Protokoll #16884

ID16884
Zeitstempel2025-12-25 20:13:42.939247
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,695 (Input: 179, Output: 1,516)
Dauer91 ms
Request-Zeit2025-12-25 20:13:42.939247
Response-Zeit2025-12-25 20:13:43.030181

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/AssignChunkTaxonomyUseCase.php",
        "old_string": "        $mapping = new ChunkTaxonomyMapping(\n            chunkId: $chunkId,\n            taxonomyTermId: $taxonomyTermId,\n            confidence: new Confidence($confidence),\n            source: MappingSource::from($source)\n        );",
        "new_string": "        $mapping = new ChunkTaxonomyMapping();\n        $mapping->setChunkId($chunkId);\n        $mapping->setTaxonomyTermId($taxonomyTermId);\n        $mapping->setConfidence(Confidence::fromFloat($confidence));\n        $mapping->setSource(MappingSource::from($source));"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/AssignChunkTaxonomyUseCase.php",
        "oldString": "        $mapping = new ChunkTaxonomyMapping(\n            chunkId: $chunkId,\n            taxonomyTermId: $taxonomyTermId,\n            confidence: new Confidence($confidence),\n            source: MappingSource::from($source)\n        );",
        "newString": "        $mapping = new ChunkTaxonomyMapping();\n        $mapping->setChunkId($chunkId);\n        $mapping->setTaxonomyTermId($taxonomyTermId);\n        $mapping->setConfidence(Confidence::fromFloat($confidence));\n        $mapping->setSource(MappingSource::from($source));",
        "originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Chunk-Taxonomie-Zuweisung\n\nuse Domain\\Entity\\ChunkTaxonomyMapping;\nuse Domain\\Repository\\ChunkExplorerRepositoryInterface;\nuse Domain\\Repository\\ChunkTaxonomyRepositoryInterface;\nuse Domain\\Repository\\TaxonomyRepositoryInterface;\nuse Domain\\ValueObject\\Confidence;\nuse Domain\\ValueObject\\MappingSource;\nuse Infrastructure\\Audit\\AuditService;\n\nfinal class AssignChunkTaxonomyUseCase\n{\n    public function __construct(\n        private ChunkTaxonomyRepositoryInterface $chunkTaxonomyRepository,\n        private ChunkExplorerRepositoryInterface $chunkRepository,\n        private TaxonomyRepositoryInterface $taxonomyRepository,\n        private AuditService $auditService\n    ) {\n    }\n\n    \/**\n     * Assign a single taxonomy term to a chunk.\n     *\n     * @throws \\InvalidArgumentException if validation fails\n     *\/\n    public function execute(\n        int $chunkId,\n        int $taxonomyTermId,\n        float $confidence,\n        string $source\n    ): int {\n        $this->validateChunk($chunkId);\n        $this->validateTaxonomyTerm($taxonomyTermId);\n        $this->validateConfidence($confidence);\n        $this->validateSource($source);\n\n        \/\/ Check if mapping already exists\n        if ($this->chunkTaxonomyRepository->exists($chunkId, $taxonomyTermId)) {\n            throw new \\InvalidArgumentException(\n                \"Mapping already exists for chunk {$chunkId} and term {$taxonomyTermId}\"\n            );\n        }\n\n        $mapping = new ChunkTaxonomyMapping(\n            chunkId: $chunkId,\n            taxonomyTermId: $taxonomyTermId,\n            confidence: new Confidence($confidence),\n            source: MappingSource::from($source)\n        );\n\n        $id = $this->chunkTaxonomyRepository->save($mapping);\n\n        $this->auditService->logCreate(\n            table: 'chunk_taxonomy',\n            id: $id,\n            data: [\n                'chunk_id' => $chunkId,\n                'taxonomy_term_id' => $taxonomyTermId,\n                'confidence' => $confidence,\n                'source' => $source,\n            ],\n            actor: 'system',\n            actorType: $source === 'auto' ? 'pipeline' : 'user'\n        );\n\n        return $id;\n    }\n\n    \/**\n     * Batch assign taxonomy terms to chunks.\n     *\n     * @param array<array{chunk_id: int, taxonomy_term_id: int, confidence: float, source: string}> $assignments\n     * @return array{success: int, errors: array<string>}\n     *\/\n    public function batchAssign(array $assignments): array\n    {\n        $successCount = 0;\n        $errors = [];\n\n        foreach ($assignments as $index => $assignment) {\n            try {\n                $this->execute(\n                    chunkId: $assignment['chunk_id'],\n                    taxonomyTermId: $assignment['taxonomy_term_id'],\n                    confidence: $assignment['confidence'],\n                    source: $assignment['source']\n                );\n                $successCount++;\n            } catch (\\Exception $e) {\n                $errors[] = \"Assignment {$index}: \" . $e->getMessage();\n            }\n        }\n\n        return [\n            'success' => $successCount,\n            'errors' => $errors,\n        ];\n    }\n\n    private function validateChunk(int $chunkId): void\n    {\n        $chunk = $this->chunkRepository->getChunk($chunkId);\n        if ($chunk === null) {\n            throw new \\InvalidArgumentException(\"Chunk {$chunkId} not found\");\n        }\n    }\n\n    private function validateTaxonomyTerm(int $termId): void\n    {\n        $term = $this->taxonomyRepository->find($termId);\n        if ($term === null) {\n            throw new \\InvalidArgumentException(\"Taxonomy term {$termId} not found\");\n        }\n    }\n\n    private function validateConfidence(float $confidence): void\n    {\n        if ($confidence < 0.0 || $confidence > 1.0) {\n            throw new \\InvalidArgumentException(\n                \"Confidence must be between 0.0 and 1.0, got {$confidence}\"\n            );\n        }\n    }\n\n    private function validateSource(string $source): void\n    {\n        $validSources = ['auto', 'manual'];\n        if (!in_array($source, $validSources, true)) {\n            throw new \\InvalidArgumentException(\n                \"Invalid source '{$source}'. Must be one of: \" . implode(', ', $validSources)\n            );\n        }\n    }\n}\n",
        "structuredPatch": [
            {
                "oldStart": 47,
                "oldLines": 12,
                "newStart": 47,
                "newLines": 11,
                "lines": [
                    "             );",
                    "         }",
                    " ",
                    "-        $mapping = new ChunkTaxonomyMapping(",
                    "-            chunkId: $chunkId,",
                    "-            taxonomyTermId: $taxonomyTermId,",
                    "-            confidence: new Confidence($confidence),",
                    "-            source: MappingSource::from($source)",
                    "-        );",
                    "+        $mapping = new ChunkTaxonomyMapping();",
                    "+        $mapping->setChunkId($chunkId);",
                    "+        $mapping->setTaxonomyTermId($taxonomyTermId);",
                    "+        $mapping->setConfidence(Confidence::fromFloat($confidence));",
                    "+        $mapping->setSource(MappingSource::from($source));",
                    " ",
                    "         $id = $this->chunkTaxonomyRepository->save($mapping);",
                    " "
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →