Protokoll #3130

ID3130
Zeitstempel2025-12-22 02:00:48.149922
Clientroot
IP145.224.96.190
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens2,686 (Input: 40, Output: 2,646)
Dauer98 ms
Request-Zeit2025-12-22 02:00:48.149922
Response-Zeit2025-12-22 02:00:48.248319

Request

{
    "event": "PreToolUse",
    "tool_name": "Read",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/SemanticExplorerController.php"
    }
}

Response

{
    "tool_response": {
        "type": "text",
        "file": {
            "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/SemanticExplorerController.php",
            "content": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\SemanticExplorerRepository;\n\n\/**\n * SemanticExplorerController - Nutzdaten Explorer\n *\n * Zeigt Dokumente und Chunks aus Nextcloud (documents, chunks Tabellen).\n * Für Endnutzer - Coaching-Materialien, PDFs, später Mails.\n *\/\nclass SemanticExplorerController extends Controller\n{\n    private SemanticExplorerRepository $repository;\n\n    public function __construct()\n    {\n        $this->repository = new SemanticExplorerRepository();\n    }\n\n    \/**\n     * GET \/semantic-explorer\n     * Dashboard mit Statistiken\n     *\/\n    public function index(): void\n    {\n        $docStats = $this->repository->getDocumentStats();\n        $chunkStats = $this->repository->getChunkStats();\n        $documents = $this->repository->getDocuments();\n        $recentChunks = $this->repository->getRecentChunks(5);\n\n        $this->view('semantic-explorer.index', [\n            'title' => 'Semantic Explorer',\n            'docStats' => $docStats,\n            'chunkStats' => $chunkStats,\n            'documents' => $documents,\n            'recentChunks' => $recentChunks,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/dokumente\n     * Liste aller Dokumente\n     *\/\n    public function dokumente(): void\n    {\n        $status = $_GET['status'] ?? '';\n        $search = $_GET['search'] ?? '';\n\n        $documents = $this->repository->getDocumentsFiltered($status, $search);\n\n        $this->view('semantic-explorer.dokumente.index', [\n            'title' => 'Dokumente',\n            'documents' => $documents,\n            'currentStatus' => $status,\n            'currentSearch' => $search,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/dokumente\/{id}\n     * Dokument-Details mit Chunks\n     *\/\n    public function dokumentShow(int $id): void\n    {\n        $document = $this->repository->getDocument($id);\n\n        if ($document === null) {\n            $this->notFound('Dokument nicht gefunden');\n        }\n\n        $chunks = $this->repository->getChunksForDocument($id);\n\n        \/\/ Heading-Paths dekodieren\n        foreach ($chunks as &$chunk) {\n            $chunk['heading_path_decoded'] = json_decode($chunk['heading_path'] ?? '[]', true) ?: [];\n            $chunk['metadata_decoded'] = json_decode($chunk['metadata'] ?? '{}', true) ?: [];\n        }\n\n        $this->view('semantic-explorer.dokumente.show', [\n            'title' => $document['filename'],\n            'document' => $document,\n            'chunks' => $chunks,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/chunks\n     * Liste aller Chunks\n     *\/\n    public function chunks(): void\n    {\n        $search = $_GET['search'] ?? '';\n        $embedded = $_GET['embedded'] ?? '';\n        $page = max(1, (int) ($_GET['page'] ?? 1));\n        $limit = 50;\n        $offset = ($page - 1) * $limit;\n\n        $totalCount = $this->repository->getChunksCount($search, $embedded);\n        $chunks = $this->repository->getChunksFiltered($search, $embedded, $limit, $offset);\n\n        $this->view('semantic-explorer.chunks.index', [\n            'title' => 'Chunks',\n            'chunks' => $chunks,\n            'currentSearch' => $search,\n            'currentEmbedded' => $embedded,\n            'currentPage' => $page,\n            'totalCount' => $totalCount,\n            'totalPages' => ceil($totalCount \/ $limit),\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/chunks\/{id}\n     * Chunk-Details\n     *\/\n    public function chunkShow(int $id): void\n    {\n        $chunk = $this->repository->getChunk($id);\n\n        if ($chunk === null) {\n            $this->notFound('Chunk nicht gefunden');\n        }\n\n        \/\/ JSON-Felder dekodieren\n        $chunk['heading_path_decoded'] = json_decode($chunk['heading_path'] ?? '[]', true) ?: [];\n        $chunk['metadata_decoded'] = json_decode($chunk['metadata'] ?? '{}', true) ?: [];\n\n        \/\/ Nachbar-Chunks\n        $prevChunk = $this->repository->getChunkByDocumentAndIndex(\n            $chunk['document_id'],\n            $chunk['chunk_index'] - 1\n        );\n        $nextChunk = $this->repository->getChunkByDocumentAndIndex(\n            $chunk['document_id'],\n            $chunk['chunk_index'] + 1\n        );\n\n        $this->view('semantic-explorer.chunks.show', [\n            'title' => 'Chunk #' . $chunk['id'],\n            'chunk' => $chunk,\n            'prevChunk' => $prevChunk,\n            'nextChunk' => $nextChunk,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/suche\n     * Semantische Suche in Nutzdaten\n     *\/\n    public function suche(): void\n    {\n        $query = $_GET['q'] ?? '';\n        $limit = min(20, max(1, (int) ($_GET['limit'] ?? 10)));\n\n        $results = [];\n\n        if ($query !== '') {\n            \/\/ Vektor-Suche via Qdrant\n            $results = $this->vectorSearch($query, $limit);\n        }\n\n        $this->view('semantic-explorer.suche', [\n            'title' => 'Semantische Suche',\n            'query' => $query,\n            'results' => $results,\n            'limit' => $limit,\n        ]);\n    }\n\n    \/**\n     * Vektor-Suche in documents Collection\n     *\/\n    private function vectorSearch(string $query, int $limit): array\n    {\n        \/\/ Embedding generieren\n        $embedding = $this->getEmbedding($query);\n        if (empty($embedding)) {\n            return [];\n        }\n\n        \/\/ Qdrant suchen\n        $response = $this->qdrantSearch($embedding, $limit);\n        if (empty($response)) {\n            return [];\n        }\n\n        \/\/ Chunk-Details aus DB laden\n        $results = [];\n        foreach ($response as $point) {\n            $chunkId = $point['payload']['chunk_id'] ?? null;\n            if ($chunkId === null) {\n                continue;\n            }\n\n            $chunk = $this->repository->getChunkById($chunkId);\n\n            if ($chunk !== null) {\n                $chunk['score'] = $point['score'];\n                $chunk['heading_path_decoded'] = json_decode($chunk['heading_path'] ?? '[]', true) ?: [];\n                $results[] = $chunk;\n            }\n        }\n\n        return $results;\n    }\n\n    \/**\n     * Embedding via Ollama\n     *\/\n    private function getEmbedding(string $text): array\n    {\n        $ch = curl_init('http:\/\/localhost:11434\/api\/embeddings');\n        curl_setopt_array($ch, [\n            CURLOPT_RETURNTRANSFER => true,\n            CURLOPT_POST => true,\n            CURLOPT_HTTPHEADER => ['Content-Type: application\/json'],\n            CURLOPT_POSTFIELDS => json_encode([\n                'model' => 'mxbai-embed-large',\n                'prompt' => $text,\n            ]),\n        ]);\n\n        $response = curl_exec($ch);\n        curl_close($ch);\n\n        $data = json_decode($response, true);\n\n        return $data['embedding'] ?? [];\n    }\n\n    \/**\n     * Qdrant-Suche\n     *\/\n    private function qdrantSearch(array $embedding, int $limit): array\n    {\n        $ch = curl_init('http:\/\/localhost:6333\/collections\/documents\/points\/search');\n        curl_setopt_array($ch, [\n            CURLOPT_RETURNTRANSFER => true,\n            CURLOPT_POST => true,\n            CURLOPT_HTTPHEADER => ['Content-Type: application\/json'],\n            CURLOPT_POSTFIELDS => json_encode([\n                'vector' => $embedding,\n                'limit' => $limit,\n                'with_payload' => true,\n            ]),\n        ]);\n\n        $response = curl_exec($ch);\n        curl_close($ch);\n\n        $data = json_decode($response, true);\n\n        return $data['result'] ?? [];\n    }\n\n    \/**\n     * GET \/semantic-explorer\/entitaeten\n     * Liste aller Entitaeten\n     *\/\n    public function entitaeten(): void\n    {\n        $type = $_GET['type'] ?? '';\n        $search = $_GET['search'] ?? '';\n\n        $entities = $this->repository->getEntitiesFiltered($type, $search);\n        $stats = $this->repository->getEntityStats();\n\n        $this->view('semantic-explorer.entitaeten.index', [\n            'title' => 'Entitaeten',\n            'entities' => $entities,\n            'stats' => $stats,\n            'currentType' => $type,\n            'currentSearch' => $search,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/entitaeten\/{id}\n     * Entitaet-Details\n     *\/\n    public function entitaetShow(int $id): void\n    {\n        $entity = $this->repository->getEntity($id);\n\n        if ($entity === null) {\n            $this->notFound('Entitaet nicht gefunden');\n        }\n\n        $synonyms = $this->repository->getEntitySynonyms($id);\n        $outgoingRelations = $this->repository->getOutgoingRelations($id);\n        $incomingRelations = $this->repository->getIncomingRelations($id);\n        $chunks = $this->repository->getChunksForEntity($id);\n        $classifications = $this->repository->getEntityClassifications($id);\n\n        $this->view('semantic-explorer.entitaeten.show', [\n            'title' => $entity['name'],\n            'entity' => $entity,\n            'synonyms' => $synonyms,\n            'outgoingRelations' => $outgoingRelations,\n            'incomingRelations' => $incomingRelations,\n            'chunks' => $chunks,\n            'classifications' => $classifications,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/relationen\n     * Beziehungen zwischen Entitaeten\n     *\/\n    public function relationen(): void\n    {\n        $type = $_GET['type'] ?? '';\n\n        $relations = $this->repository->getRelationsFiltered($type);\n        $relationTypes = $this->repository->getRelationTypes();\n        $stats = $this->repository->getRelationStats();\n\n        $this->view('semantic-explorer.relationen', [\n            'title' => 'Relationen',\n            'relations' => $relations,\n            'relationTypes' => $relationTypes,\n            'stats' => $stats,\n            'currentType' => $type,\n        ]);\n    }\n\n    \/**\n     * GET \/semantic-explorer\/taxonomie\n     * Hierarchische Kategorisierung\n     *\/\n    public function taxonomie(): void\n    {\n        $terms = $this->repository->getTaxonomyTerms();\n        $hierarchy = $this->buildTaxonomyTree($terms);\n        $stats = $this->reposito... [TRUNCATED-64850df3ed83d09d]",
            "numLines": 816,
            "startLine": 1,
            "totalLines": 816
        }
    }
}
← Vorheriger Zur Liste Nächster →