Protokoll #24487

ID24487
Zeitstempel2025-12-27 23:21:38.312077
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,742 (Input: 108, Output: 1,634)
Dauer103 ms
Request-Zeit2025-12-27 23:21:38.312077
Response-Zeit2025-12-27 23:21:38.414772

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/UpdateChatSessionUseCase.php",
        "old_string": "        $title = mb_substr($title, 0, 100);\n        $this->sessionRepo->updateTitle($sessionId, $title);",
        "new_string": "        $title = mb_substr($title, 0, Constants::NAME_MAX_LENGTH);\n        $this->sessionRepo->updateTitle($sessionId, $title);"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/UpdateChatSessionUseCase.php",
        "oldString": "        $title = mb_substr($title, 0, 100);\n        $this->sessionRepo->updateTitle($sessionId, $title);",
        "newString": "        $title = mb_substr($title, 0, Constants::NAME_MAX_LENGTH);\n        $this->sessionRepo->updateTitle($sessionId, $title);",
        "originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Chat;\n\n\/\/ @responsibility: Updates chat session data\n\nuse Domain\\Constants;\nuse Domain\\Entity\\ChatSession;\nuse Domain\\Repository\\ChatSessionRepositoryInterface;\nuse Domain\\Repository\\CollectionRepositoryInterface;\nuse Domain\\Repository\\ContentConfigRepositoryInterface;\nuse Domain\\Service\\ModelRegistryInterface;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class UpdateChatSessionUseCase implements UpdateChatSessionUseCaseInterface\n{\n    public function __construct(\n        private ChatSessionRepositoryInterface $sessionRepo,\n        private ContentConfigRepositoryInterface $configRepo,\n        private CollectionRepositoryInterface $collectionRepo,\n        private CollectionValidator $collectionValidator,\n        private ModelRegistryInterface $modelRegistry,\n        private \\PDO $pdoDev\n    ) {\n    }\n\n    public function updateTitle(int $sessionId, string $title): string\n    {\n        $title = trim($title);\n\n        if ($title === '') {\n            $title = 'Neuer Chat';\n        }\n\n        $title = mb_substr($title, 0, 100);\n        $this->sessionRepo->updateTitle($sessionId, $title);\n\n        return $title;\n    }\n\n    public function updateSettings(\n        int $sessionId,\n        string $model,\n        array $collections,\n        int $contextLimit,\n        int $authorProfileId,\n        float $temperature,\n        int $maxTokens\n    ): void {\n        $model = $this->modelRegistry->isValid($model) ? $model : $this->modelRegistry->getDefaultChatModel();\n        $collections = $this->validateCollections($collections);\n        $contextLimit = $this->validateContextLimit($contextLimit);\n        $authorProfileId = $this->validateAuthorProfileId($authorProfileId);\n        $temperature = $this->validateTemperature($temperature);\n        $maxTokens = $this->validateMaxTokens($maxTokens);\n\n        $this->sessionRepo->updateSettings(\n            $sessionId,\n            $model,\n            $collections,\n            $contextLimit,\n            $authorProfileId > 0 ? $authorProfileId : null,\n            $temperature,\n            $maxTokens\n        );\n    }\n\n    public function updateSystemPrompt(int $sessionId, string $systemPrompt): ChatSessionResult\n    {\n        $maxLength = 2000;\n        $wasTruncated = mb_strlen($systemPrompt) > $maxLength;\n        $systemPrompt = trim(mb_substr($systemPrompt, 0, $maxLength));\n\n        $this->logSystemPromptChange($systemPrompt, $wasTruncated);\n        $this->sessionRepo->updateSystemPrompt($sessionId, $systemPrompt);\n\n        return ChatSessionResult::success('System-Prompt gespeichert.');\n    }\n\n    public function settingsHaveChanged(\n        ChatSession $session,\n        string $model,\n        array $collections,\n        int $contextLimit,\n        int $authorProfileId,\n        float $temperature,\n        int $maxTokens\n    ): bool {\n        return $model !== $session->getModel()\n            || $collections !== $session->getCollections()\n            || $contextLimit !== $session->getContextLimit()\n            || $authorProfileId !== ($session->getAuthorProfileId() ?? 0)\n            || $temperature !== $session->getTemperature()\n            || $maxTokens !== $session->getMaxTokens();\n    }\n\n    public function validateCollectionCompatibility(array $collectionIds): array\n    {\n        if (empty($collectionIds)) {\n            return ['valid' => true, 'error' => null];\n        }\n\n        $result = $this->collectionValidator->validateSelection($collectionIds);\n\n        return [\n            'valid' => $result->isValid(),\n            'error' => $result->getError(),\n        ];\n    }\n\n    private function validateCollections(array|string $collections): array\n    {\n        $availableIds = array_column($this->collectionRepo->getSearchable(), 'collection_id');\n\n        if (is_string($collections)) {\n            $collections = [$collections];\n        }\n\n        $valid = array_filter($collections, fn ($c) => in_array($c, $availableIds, true));\n\n        return array_values($valid);\n    }\n\n    private function validateContextLimit(int $limit): int\n    {\n        $allowedLimits = [3, 5, 10, 15];\n\n        return in_array($limit, $allowedLimits, true) ? $limit : 5;\n    }\n\n    private function validateAuthorProfileId(int $profileId): int\n    {\n        if ($profileId === 0) {\n            return 0;\n        }\n\n        $profile = $this->configRepo->getAuthorProfile($profileId);\n\n        return $profile !== null ? $profileId : 0;\n    }\n\n    private function validateTemperature(float $temperature): float\n    {\n        return max(0.0, min(1.0, $temperature));\n    }\n\n    private function validateMaxTokens(int $maxTokens): int\n    {\n        $allowedValues = [1024, 2048, 4096, 8192];\n\n        return in_array($maxTokens, $allowedValues, true) ? $maxTokens : 4096;\n    }\n\n    private function logSystemPromptChange(string $prompt, bool $wasTruncated): void\n    {\n        $logData = [\n            'prompt_length' => mb_strlen($prompt),\n            'truncated' => $wasTruncated,\n            'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',\n            'timestamp' => date('c'),\n        ];\n\n        try {\n            $stmt = $this->pdoDev->prepare(\n                \"INSERT INTO mcp_log (tool, operation, parameters, result, logged_at)\n                 VALUES ('chat', 'system_prompt_change', :params, 'logged', NOW())\"\n            );\n            $stmt->execute(['params' => json_encode($logData)]);\n        } catch (\\Exception $e) {\n            \/\/ Silently fail\n        }\n    }\n}\n",
        "structuredPatch": [
            {
                "oldStart": 34,
                "oldLines": 7,
                "newStart": 34,
                "newLines": 7,
                "lines": [
                    "             $title = 'Neuer Chat';",
                    "         }",
                    " ",
                    "-        $title = mb_substr($title, 0, 100);",
                    "+        $title = mb_substr($title, 0, Constants::NAME_MAX_LENGTH);",
                    "         $this->sessionRepo->updateTitle($sessionId, $title);",
                    " ",
                    "         return $title;"
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →