Protokoll #15727

ID15727
Zeitstempel2025-12-25 16:56:27.833259
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuspending
Tokens2,359 (Input: 2,359, Output: 0)
Dauer-
Request-Zeit2025-12-25 16:56:27.833259
Response-Zeit-

Request

{
    "event": "PostToolUse",
    "raw_data": {
        "session_id": "f0f145c4-ac1d-417a-b15b-271983ae648b",
        "transcript_path": "\/root\/.claude\/projects\/-var-www\/f0f145c4-ac1d-417a-b15b-271983ae648b.jsonl",
        "cwd": "\/var\/www\/dev.campus.systemische-tools.de",
        "permission_mode": "acceptEdits",
        "hook_event_name": "PostToolUse",
        "tool_name": "Read",
        "tool_input": {
            "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/ManageChatSessionsUseCase.php"
        },
        "tool_response": {
            "type": "text",
            "file": {
                "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/ManageChatSessionsUseCase.php",
                "content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Chat;\n\n\/\/ @responsibility: Verwaltet Chat-Sessions (CRUD, Einstellungen, Collections)\n\nuse Domain\\Entity\\ChatMessage;\nuse Domain\\Entity\\ChatSession;\nuse Domain\\Repository\\ChatMessageRepositoryInterface;\nuse Domain\\Repository\\ChatSessionRepositoryInterface;\nuse Domain\\Repository\\CollectionRepositoryInterface;\nuse Infrastructure\\AI\\ModelRegistry;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase\n{\n    private ?array $collectionsCache = null;\n\n    public function __construct(\n        private ChatSessionRepositoryInterface $sessionRepo,\n        private ChatMessageRepositoryInterface $messageRepo,\n        private ContentConfigRepository $configRepo,\n        private CollectionRepositoryInterface $collectionRepo,\n        private CollectionValidator $collectionValidator,\n        private \\PDO $pdoDev,\n        private ModelRegistry $modelRegistry\n    ) {\n    }\n\n    public function createSession(): string\n    {\n        $uuid = $this->sessionRepo->generateUuid();\n        $this->sessionRepo->create($uuid, 'claude-opus-4-5-20251101', '[\"documents\"]', 5);\n\n        return $uuid;\n    }\n\n    public function getSession(string $uuid): ?ChatSession\n    {\n        return $this->sessionRepo->findByUuid($uuid);\n    }\n\n    \/**\n     * Get all sessions as entities.\n     *\n     * @return array<int, ChatSession>\n     *\/\n    public function getAllSessions(int $limit = 50): array\n    {\n        return $this->sessionRepo->findAll($limit);\n    }\n\n    \/**\n     * Get all sessions with stats as arrays (for list views).\n     *\n     * @return array<int, array<string, mixed>>\n     *\/\n    public function getAllSessionsWithStats(int $limit = 50): array\n    {\n        return $this->sessionRepo->findAllWithStats($limit);\n    }\n\n    \/**\n     * Get messages for a session.\n     *\n     * @return array<int, ChatMessage>\n     *\/\n    public function getMessages(int $sessionId): array\n    {\n        return $this->messageRepo->findBySessionId($sessionId);\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 deleteSession(int $sessionId): void\n    {\n        $this->sessionRepo->delete($sessionId);\n    }\n\n    public function getAuthorProfiles(): array\n    {\n        return $this->configRepo->getAuthorProfiles();\n    }\n\n    public function getSystemPrompts(): array\n    {\n        return $this->configRepo->getSystemPrompts();\n    }\n\n    public function getOutputStructures(): array\n    {\n        return $this->configRepo->getStructures();\n    }\n\n    public function getStructure(int $id): ?array\n    {\n        return $this->configRepo->getStructure($id);\n    }\n\n    public function getAvailableCollections(): array\n    {\n        if ($this->collectionsCache === null) {\n            $this->collectionsCache = $this->collectionRepo->getSearchable();\n\n            if ($this->collectionsCache === []) {\n                $this->collectionsCache = [\n                    ['collection_id' => 'documents', 'display_name' => 'Dokumente', 'points_count' => 0, 'vector_size' => 1024],\n                ];\n            }\n        }\n\n        return $this->collectionsCache;\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    public function getDefaultSystemPrompt(): string\n    {\n        return <<<'PROMPT'\n            Du bist ein hilfreicher Assistent für Fragen zu systemischem Teamcoaching und Teamentwicklung.\n\n            Beantworte die Frage des Nutzers basierend auf dem bereitgestellten Kontext.\n            - Antworte auf Deutsch\n            - Sei präzise und hilfreich\n            - Wenn der Kontext die Frage nicht beantwortet, sage das ehrlich\n            - Verweise auf die Quellen wenn passend\n            PROMPT;\n    }\n\n    \/**\n     * Check if settings have changed.\n     *\n     * @param array<string> $collections\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    private function validateCollections(array|string $collections): array\n    {\n        $availableIds = array_column($this->getAvailableCollections(), '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",
                "numLines": 281,
                "startLine": 1,
                "totalLines": 281
            }
        },
        "tool_use_id": "toolu_01A9dPAtd4ahfsE1Dq5R9Qa8"
    }
}

Response

-
← Vorheriger Zur Liste Nächster →