{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/cli\/doc2vector.php",
"oldString": " $docId = (int) $positional[0];\n $chunking = new ChunkingService();\n $result = $chunking->chunkDocument($docId);",
"newString": " $docId = (int) $positional[0];\n $chunking = $container->get(ChunkingService::class);\n $result = $chunking->chunkDocument($docId);",
"originalFile": "<?php\n\n\/**\n * Doc2Vector CLI - Documentation Processing Pipeline\n *\n * Usage:\n * php cli\/doc2vector.php <command> [options]\n *\n * Commands:\n * full Run full pipeline (chunk, analyze, sync)\n * incremental Process only pending chunks\n * stats Show pipeline statistics\n * search Search documentation\n * chunk Re-chunk a specific document\n * analyze Analyze pending chunks (with limit)\n * sync Sync pending chunks to Qdrant\n *\n * Examples:\n * php cli\/doc2vector.php full\n * php cli\/doc2vector.php stats\n * php cli\/doc2vector.php search \"SSH Konfiguration\"\n * php cli\/doc2vector.php search \"Backup\" --category=Server\n * php cli\/doc2vector.php analyze --limit=50\n *\/\n\ndeclare(strict_types=1);\n\n\/\/ Bootstrap the application (loads autoloader, env, container)\nrequire_once __DIR__ . '\/..\/vendor\/autoload.php';\n$dotenv = Dotenv\\Dotenv::createImmutable(__DIR__ . '\/..');\n$dotenv->load();\nrequire_once __DIR__ . '\/..\/config\/config.php';\nrequire_once __DIR__ . '\/..\/config\/database.php';\nrequire_once __DIR__ . '\/..\/config\/autoload.php';\n\nuse Domain\\Service\\SearchServiceInterface;\nuse Infrastructure\\Docs\\Doc2VectorPipeline;\nuse Infrastructure\\Docs\\ChunkingService;\nuse Infrastructure\\Docs\\ChunkAnalysisService;\nuse Infrastructure\\Docs\\ChunkSyncService;\n\n\/\/ Initialize DI Container\n$app = new Framework\\App();\n$container = $app->container();\n\n$command = $argv[1] ?? 'help';\n$args = array_slice($argv, 2);\n\n\/\/ Parse named arguments\n$options = [];\n$positional = [];\nforeach ($args as $arg) {\n if (str_starts_with($arg, '--')) {\n $parts = explode('=', substr($arg, 2), 2);\n $options[$parts[0]] = $parts[1] ?? true;\n } else {\n $positional[] = $arg;\n }\n}\n\ntry {\n switch ($command) {\n case 'full':\n $pipeline = $container->get(Doc2VectorPipeline::class);\n $result = $pipeline->runFull();\n break;\n\n case 'incremental':\n $pipeline = $container->get(Doc2VectorPipeline::class);\n $result = $pipeline->runIncremental();\n break;\n\n case 'stats':\n $pipeline = $container->get(Doc2VectorPipeline::class);\n $stats = $pipeline->getStats();\n\n echo \"=== Doc2Vector Statistics ===\" . PHP_EOL . PHP_EOL;\n\n echo \"Chunks:\" . PHP_EOL;\n echo sprintf(\" Total: %d\" . PHP_EOL, $stats['chunks']['total_chunks']);\n echo sprintf(\" Tokens: %d\" . PHP_EOL, $stats['chunks']['total_tokens']);\n echo sprintf(\" Pending Analysis: %d\" . PHP_EOL, $stats['chunks']['pending_analysis']);\n echo sprintf(\" Completed Analysis: %d\" . PHP_EOL, $stats['chunks']['completed_analysis']);\n\n echo PHP_EOL . \"Analysis:\" . PHP_EOL;\n echo sprintf(\" Pending: %d\" . PHP_EOL, $stats['analysis']['pending']);\n echo sprintf(\" Completed: %d\" . PHP_EOL, $stats['analysis']['completed']);\n echo sprintf(\" Failed: %d\" . PHP_EOL, $stats['analysis']['failed']);\n\n echo PHP_EOL . \"Qdrant:\" . PHP_EOL;\n if ($stats['qdrant']) {\n echo sprintf(\" Points: %d\" . PHP_EOL, $stats['qdrant']['points_count']);\n echo sprintf(\" Status: %s\" . PHP_EOL, $stats['qdrant']['status']);\n } else {\n echo \" Not available\" . PHP_EOL;\n }\n\n echo PHP_EOL . \"Taxonomy Categories:\" . PHP_EOL;\n foreach ($stats['taxonomy_categories'] as $cat) {\n echo sprintf(\" - %s (%d)\" . PHP_EOL, $cat['category'], $cat['count']);\n }\n break;\n\n case 'search':\n if (empty($positional)) {\n echo \"Usage: php cli\/doc2vector.php search \\\"query\\\" [--category=X] [--limit=N]\" . PHP_EOL;\n exit(1);\n }\n\n $query = $positional[0];\n $filters = [];\n if (isset($options['category'])) {\n $filters['taxonomy_category'] = $options['category'];\n }\n if (isset($options['entity'])) {\n $filters['entity_name'] = $options['entity'];\n }\n $limit = isset($options['limit']) ? (int) $options['limit'] : 5;\n\n $search = $container->get(SearchServiceInterface::class);\n $results = $search->search($query, $filters, $limit);\n\n echo sprintf(\"=== Search: \\\"%s\\\" ===\" . PHP_EOL . PHP_EOL, $query);\n\n if (empty($results)) {\n echo \"No results found.\" . PHP_EOL;\n } else {\n foreach ($results as $i => $r) {\n echo sprintf(\"%d. [%.2f] %s\" . PHP_EOL, $i + 1, $r['relevance_score'], $r['path']);\n echo sprintf(\" Title: %s\" . PHP_EOL, $r['title']);\n echo sprintf(\" Taxonomy: %s\" . PHP_EOL, implode(' > ', $r['taxonomy']));\n echo sprintf(\" Keywords: %s\" . PHP_EOL, implode(', ', $r['keywords']));\n echo sprintf(\" Content: %s...\" . PHP_EOL, substr($r['content'], 0, 100));\n echo PHP_EOL;\n }\n\n echo \"Suggested searches: \" . implode(', ', $search->suggestRelatedSearches($results)) . PHP_EOL;\n }\n break;\n\n case 'chunk':\n if (empty($positional)) {\n echo \"Usage: php cli\/doc2vector.php chunk <doc_id>\" . PHP_EOL;\n exit(1);\n }\n\n $docId = (int) $positional[0];\n $chunking = new ChunkingService();\n $result = $chunking->chunkDocument($docId);\n\n echo sprintf(\n \"Document #%d chunked: %d chunks, %d tokens\" . PHP_EOL,\n $docId,\n $result['chunks_created'],\n $result['tokens_total']\n );\n break;\n\n case 'analyze':\n $limit = isset($options['limit']) ? (int) $options['limit'] : 50;\n\n $analysis = new ChunkAnalysisService();\n echo sprintf(\"Analyzing up to %d chunks...\" . PHP_EOL, $limit);\n $result = $analysis->analyzeAllPending($limit);\n\n echo sprintf(\n \"Completed: %d analyzed, %d failed\" . PHP_EOL,\n $result['analyzed'],\n $result['failed']\n );\n\n if (!empty($result['errors'])) {\n echo \"Errors:\" . PHP_EOL;\n foreach (array_slice($result['errors'], 0, 5) as $e) {\n echo \" - \" . $e . PHP_EOL;\n }\n }\n break;\n\n case 'sync':\n $limit = isset($options['limit']) ? (int) $options['limit'] : 100;\n\n $sync = new ChunkSyncService();\n echo sprintf(\"Syncing up to %d chunks...\" . PHP_EOL, $limit);\n $result = $sync->syncAllPending($limit);\n\n echo sprintf(\n \"Completed: %d synced, %d failed\" . PHP_EOL,\n $result['synced'],\n $result['failed']\n );\n break;\n\n case 'categories':\n $search = new HybridSearchService();\n $categories = $search->getTaxonomyCategories();\n\n echo \"=== Taxonomy Categories ===\" . PHP_EOL;\n foreach ($categories as $cat) {\n echo sprintf(\" %s: %d chunks\" . PHP_EOL, $cat['category'], $cat['count']);\n }\n break;\n\n case 'entities':\n $search = new HybridSearchService();\n $entities = $search->getEntitiesByType();\n\n echo \"=== Entities by Type ===\" . PHP_EOL;\n foreach ($entities as $type => $names) {\n echo sprintf(\"%s:\" . PHP_EOL, $type);\n foreach ($names as $name) {\n echo sprintf(\" - %s\" . PHP_EOL, $name);\n }\n }\n break;\n\n case 'help':\n default:\n echo <<<HELP\n Doc2Vector CLI - Documentation Processing Pipeline\n\n Usage:\n php cli\/doc2vector.php <command> [options]\n\n Commands:\n full Run full pipeline (chunk, analyze, sync)\n incremental Process only pending chunks\n stats Show pipeline statistics\n search <query> Search documentation\n chunk <doc_id> Re-chunk a specific document\n analyze Analyze pending chunks\n sync Sync pending chunks to Qdrant\n categories List taxonomy categories\n entities List entities by type\n help Show this help\n\n Options:\n --limit=N Limit number of items to process\n --category=X Filter search by taxonomy category\n --entity=X Filter search by entity name\n\n Examples:\n php cli\/doc2vector.php full\n php cli\/doc2vector.php stats\n php cli\/doc2vector.php search \"SSH Konfiguration\"\n php cli\/doc2vector.php search \"Backup\" --category=Server\n php cli\/doc2vector.php analyze --limit=50\n\n HELP;\n break;\n }\n} catch (Exception $e) {\n echo \"Error: \" . $e->getMessage() . PHP_EOL;\n exit(1);\n}\n",
"structuredPatch": [
{
"oldStart": 145,
"oldLines": 7,
"newStart": 145,
"newLines": 7,
"lines": [
" }",
" ",
" $docId = (int) $positional[0];",
"- $chunking = new ChunkingService();",
"+ $chunking = $container->get(ChunkingService::class);",
" $result = $chunking->chunkDocument($docId);",
" ",
" echo sprintf("
]
}
],
"userModified": false,
"replaceAll": false
}
}