{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
"old_string": " public function store(): void\n {\n $this->requireCsrf();\n\n $command = CreatePromptCommand::fromRequest($_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/new');\n }\n\n $result = $this->promptsUseCase->create(\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/new');\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id);\n }",
"new_string": " public function store(): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n $command = CreatePromptCommand::fromRequest($_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n if ($isHtmx) {\n $this->htmxError(implode(' ', $errors));\n\n return;\n }\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/new');\n }\n\n $result = $this->promptsUseCase->create(\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n if ($isHtmx) {\n $this->htmxError($result->message);\n\n return;\n }\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/new');\n }\n\n if ($isHtmx) {\n $this->htmxRedirect('\/prompts\/' . $result->id);\n\n return;\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id);\n }"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
"oldString": " public function store(): void\n {\n $this->requireCsrf();\n\n $command = CreatePromptCommand::fromRequest($_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/new');\n }\n\n $result = $this->promptsUseCase->create(\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/new');\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id);\n }",
"newString": " public function store(): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n $command = CreatePromptCommand::fromRequest($_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n if ($isHtmx) {\n $this->htmxError(implode(' ', $errors));\n\n return;\n }\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/new');\n }\n\n $result = $this->promptsUseCase->create(\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n if ($isHtmx) {\n $this->htmxError($result->message);\n\n return;\n }\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/new');\n }\n\n if ($isHtmx) {\n $this->htmxRedirect('\/prompts\/' . $result->id);\n\n return;\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id);\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für Prompt-Verwaltung (CRUD, Duplizieren)\n\nuse Framework\\Controller;\nuse UseCases\\Command\\CreatePromptCommand;\nuse UseCases\\Command\\UpdatePromptCommand;\nuse UseCases\\Prompts\\ManagePromptsUseCase;\n\nclass PromptsController extends Controller\n{\n private ManagePromptsUseCase $promptsUseCase;\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(ManagePromptsUseCase $promptsUseCase)\n {\n $this->promptsUseCase = $promptsUseCase;\n }\n\n public function index(): void\n {\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => array_map(fn ($dto) => $dto->toArray(), $this->promptsUseCase->getAll()),\n 'stats' => $this->promptsUseCase->getStatistics(),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\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 public function store(): void\n {\n $this->requireCsrf();\n\n $command = CreatePromptCommand::fromRequest($_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/new');\n }\n\n $result = $this->promptsUseCase->create(\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/new');\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id);\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsUseCase->getById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt->name,\n 'prompt' => $prompt->toArray(),\n 'linkedCritics' => $this->promptsUseCase->getLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsUseCase->getById((int) $id);\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->toArray(),\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $command = UpdatePromptCommand::fromRequest((int) $id, $_POST);\n $errors = $command->validate();\n\n if ($errors !== []) {\n $_SESSION['error'] = implode(' ', $errors);\n $this->redirect('\/prompts\/' . $id . '\/edit');\n }\n\n $result = $this->promptsUseCase->update(\n id: $command->id,\n name: $command->name,\n version: $command->version,\n content: $command->content,\n isActive: $command->isActive\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/' . $id . '\/edit');\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $id);\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->delete((int) $id);\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/' . $id);\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts');\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->duplicate((int) $id);\n\n \/\/ HTMX request handling\n if ($this->isHtmxRequest()) {\n if (!$result->success) {\n $this->htmxError($result->message);\n\n return;\n }\n $this->htmxRedirect('\/prompts\/' . $result->id . '\/edit');\n\n return;\n }\n\n \/\/ Traditional form fallback\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n $this->redirect('\/prompts\/' . $id);\n }\n\n $_SESSION['success'] = $result->message;\n $this->redirect('\/prompts\/' . $result->id . '\/edit');\n }\n}\n",
"structuredPatch": [
{
"oldStart": 52,
"oldLines": 10,
"newStart": 52,
"newLines": 16,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"+ $isHtmx = $this->isHtmxRequest();",
" $command = CreatePromptCommand::fromRequest($_POST);",
" $errors = $command->validate();",
" ",
" if ($errors !== []) {",
"+ if ($isHtmx) {",
"+ $this->htmxError(implode(' ', $errors));",
"+",
"+ return;",
"+ }",
" $_SESSION['error'] = implode(' ', $errors);",
" $this->redirect('\/prompts\/new');",
" }"
]
},
{
"oldStart": 68,
"oldLines": 10,
"newStart": 74,
"newLines": 21,
"lines": [
" );",
" ",
" if (!$result->success) {",
"+ if ($isHtmx) {",
"+ $this->htmxError($result->message);",
"+",
"+ return;",
"+ }",
" $_SESSION['error'] = $result->message;",
" $this->redirect('\/prompts\/new');",
" }",
" ",
"+ if ($isHtmx) {",
"+ $this->htmxRedirect('\/prompts\/' . $result->id);",
"+",
"+ return;",
"+ }",
"+",
" $_SESSION['success'] = $result->message;",
" $this->redirect('\/prompts\/' . $result->id);",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}