Protokoll #4544

ID4544
Zeitstempel2025-12-22 10:13:37.354698
Clientroot
IP145.224.96.190
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,933 (Input: 38, Output: 1,895)
Dauer81 ms
Request-Zeit2025-12-22 10:13:37.354698
Response-Zeit2025-12-22 10:13:37.436171

Request

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

Response

{
    "tool_response": {
        "type": "text",
        "file": {
            "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
            "content": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass PromptsController extends Controller\n{\n    private \\PDO $db;\n\n    private const PROMPT_TYPES = [\n        'critic' => 'Critic-Prompt',\n        'generate' => 'Generierungs-Prompt',\n        'revise' => 'Revisions-Prompt',\n        'system' => 'System-Prompt',\n        'other' => 'Sonstiges',\n    ];\n\n    public function __construct()\n    {\n        $this->db = DatabaseFactory::content();\n    }\n\n    \/**\n     * GET \/prompts\n     *\/\n    public function index(): void\n    {\n        $stmt = $this->db->query('\n            SELECT p.*,\n                   (SELECT COUNT(*) FROM critics c WHERE c.prompt_id = p.id) as critic_count\n            FROM prompts p\n            ORDER BY p.name\n        ');\n        $prompts = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n        $stats = $this->getStatistics();\n\n        $this->view('prompts.index', [\n            'title' => 'Prompts verwalten',\n            'prompts' => $prompts,\n            'stats' => $stats,\n            'promptTypes' => self::PROMPT_TYPES,\n        ]);\n    }\n\n    \/**\n     * GET \/prompts\/new\n     *\/\n    public function promptsNew(): void\n    {\n        $this->view('prompts.form', [\n            'title' => 'Neuer Prompt',\n            'prompt' => null,\n            'promptTypes' => self::PROMPT_TYPES,\n            'isEdit' => false,\n        ]);\n    }\n\n    \/**\n     * POST \/prompts\n     *\/\n    public function store(): void\n    {\n        $this->requireCsrf();\n\n        $name = trim($_POST['name'] ?? '');\n        $version = trim($_POST['version'] ?? '1.0');\n        $content = $_POST['content'] ?? '';\n        $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n        if ($name === '' || $content === '') {\n            $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n            header('Location: \/prompts\/new');\n            exit;\n        }\n\n        $stmt = $this->db->prepare('\n            INSERT INTO prompts (name, version, content, is_active)\n            VALUES (?, ?, ?, ?)\n        ');\n        $stmt->execute([$name, $version, $content, $isActive]);\n        $id = $this->db->lastInsertId();\n\n        $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n        header('Location: \/prompts\/' . $id);\n        exit;\n    }\n\n    \/**\n     * GET \/prompts\/{id}\n     *\/\n    public function show(string $id): void\n    {\n        $prompt = $this->findById((int) $id);\n\n        if ($prompt === null) {\n            $this->notFound('Prompt nicht gefunden');\n        }\n\n        \/\/ Verknüpfte Critics laden\n        $stmt = $this->db->prepare('SELECT * FROM critics WHERE prompt_id = ? ORDER BY name');\n        $stmt->execute([$id]);\n        $linkedCritics = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n\n        $this->view('prompts.show', [\n            'title' => $prompt['name'],\n            'prompt' => $prompt,\n            'linkedCritics' => $linkedCritics,\n            'promptTypes' => self::PROMPT_TYPES,\n        ]);\n    }\n\n    \/**\n     * GET \/prompts\/{id}\/edit\n     *\/\n    public function edit(string $id): void\n    {\n        $prompt = $this->findById((int) $id);\n\n        if ($prompt === null) {\n            $this->notFound('Prompt nicht gefunden');\n        }\n\n        $this->view('prompts.form', [\n            'title' => 'Bearbeiten: ' . $prompt['name'],\n            'prompt' => $prompt,\n            'promptTypes' => self::PROMPT_TYPES,\n            'isEdit' => true,\n        ]);\n    }\n\n    \/**\n     * POST \/prompts\/{id}\n     *\/\n    public function update(string $id): void\n    {\n        $this->requireCsrf();\n\n        $prompt = $this->findById((int) $id);\n\n        if ($prompt === null) {\n            $this->notFound('Prompt nicht gefunden');\n        }\n\n        $name = trim($_POST['name'] ?? '');\n        $version = trim($_POST['version'] ?? $prompt['version']);\n        $content = $_POST['content'] ?? '';\n        $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n        if ($name === '' || $content === '') {\n            $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n            header('Location: \/prompts\/' . $id . '\/edit');\n            exit;\n        }\n\n        $stmt = $this->db->prepare('\n            UPDATE prompts\n            SET name = ?, version = ?, content = ?, is_active = ?\n            WHERE id = ?\n        ');\n        $stmt->execute([$name, $version, $content, $isActive, $id]);\n\n        $_SESSION['success'] = 'Prompt aktualisiert.';\n        header('Location: \/prompts\/' . $id);\n        exit;\n    }\n\n    \/**\n     * POST \/prompts\/{id}\/delete\n     *\/\n    public function delete(string $id): void\n    {\n        $this->requireCsrf();\n\n        $prompt = $this->findById((int) $id);\n\n        if ($prompt === null) {\n            $this->notFound('Prompt nicht gefunden');\n        }\n\n        \/\/ Prüfen ob Critics verknüpft sind\n        $stmt = $this->db->prepare('SELECT COUNT(*) FROM critics WHERE prompt_id = ?');\n        $stmt->execute([$id]);\n        $criticCount = (int) $stmt->fetchColumn();\n\n        if ($criticCount > 0) {\n            $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n            header('Location: \/prompts\/' . $id);\n            exit;\n        }\n\n        $stmt = $this->db->prepare('DELETE FROM prompts WHERE id = ?');\n        $stmt->execute([$id]);\n\n        $_SESSION['success'] = 'Prompt gelöscht.';\n        header('Location: \/prompts');\n        exit;\n    }\n\n    \/**\n     * POST \/prompts\/{id}\/duplicate\n     *\/\n    public function duplicate(string $id): void\n    {\n        $this->requireCsrf();\n\n        $prompt = $this->findById((int) $id);\n\n        if ($prompt === null) {\n            $this->notFound('Prompt nicht gefunden');\n        }\n\n        $newName = $prompt['name'] . ' (Kopie)';\n        $newVersion = '1.0';\n\n        $stmt = $this->db->prepare('\n            INSERT INTO prompts (name, version, content, is_active)\n            VALUES (?, ?, ?, 0)\n        ');\n        $stmt->execute([$newName, $newVersion, $prompt['content']]);\n        $newId = $this->db->lastInsertId();\n\n        $_SESSION['success'] = 'Prompt dupliziert.';\n        header('Location: \/prompts\/' . $newId . '\/edit');\n        exit;\n    }\n\n    \/\/ ========== Private Helpers ==========\n\n    private function findById(int $id): ?array\n    {\n        $stmt = $this->db->prepare('SELECT * FROM prompts WHERE id = ?');\n        $stmt->execute([$id]);\n        $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n        return $result !== false ? $result : null;\n    }\n\n    private function getStatistics(): array\n    {\n        $stats = ['total' => 0, 'active' => 0, 'inactive' => 0, 'linked_to_critics' => 0];\n\n        $stmt = $this->db->query('SELECT COUNT(*) as cnt, SUM(is_active) as active FROM prompts');\n        $row = $stmt->fetch(\\PDO::FETCH_ASSOC);\n        $stats['total'] = (int) $row['cnt'];\n        $stats['active'] = (int) $row['active'];\n        $stats['inactive'] = $stats['total'] - $stats['active'];\n\n        $stmt = $this->db->query('SELECT COUNT(DISTINCT prompt_id) FROM critics WHERE prompt_id IS NOT NULL');\n        $stats['linked_to_critics'] = (int) $stmt->fetchColumn();\n\n        return $stats;\n    }\n}\n",
            "numLines": 257,
            "startLine": 1,
            "totalLines": 257
        }
    }
}
← Vorheriger Zur Liste Nächster →