{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/log_storage.py",
"offset": 95,
"limit": 50
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/log_storage.py",
"content": " \"\"\"Updated existing Request mit Response-Daten und berechnet Duration\"\"\"\n try:\n connection = pymysql.connect(**DB_CONFIG)\n with connection.cursor() as cursor:\n ct = datetime.datetime.now()\n cursor.execute(\"\"\"UPDATE protokoll SET response = %s, response_timestamp = %s, tokens_output = %s,\n tokens_total = tokens_input + %s, status = 'completed' WHERE id = %s\"\"\",\n (response_data, ct, tokens_output, tokens_output, db_id))\n cursor.execute(\"\"\"UPDATE protokoll SET duration_ms = ROUND(TIMESTAMPDIFF(MICROSECOND,\n request_timestamp, response_timestamp) \/ 1000, 3) WHERE id = %s\"\"\", (db_id,))\n connection.commit()\n except Exception as e:\n print(f\"Database update error: {e}\", file=sys.stderr)\n finally:\n if 'connection' in locals():\n connection.close()\n\n\ndef _get_pending_prompts(cursor) -> List:\n \"\"\"Holt pending UserPromptSubmit-Einträge\"\"\"\n cursor.execute(\"\"\"SELECT id, JSON_UNQUOTE(JSON_EXTRACT(request, '$.prompt')) as prompt\n FROM protokoll WHERE status = 'pending' AND JSON_EXTRACT(request, '$.event') = 'UserPromptSubmit'\n AND timestamp > DATE_SUB(NOW(), INTERVAL 1 HOUR) ORDER BY id ASC\"\"\")\n return cursor.fetchall()\n\n\ndef _find_matching_response(db_prompt: str, pairs: List[Dict[str, str]]) -> Optional[str]:\n \"\"\"Findet matching Response für einen Prompt\"\"\"\n for pair in pairs:\n if pair['prompt'].strip() == db_prompt.strip():\n return pair['response']\n return None\n\n\ndef _update_prompt_with_response(cursor, db_id: int, response: str, current_time) -> None:\n \"\"\"Updated einen pending Prompt mit seiner Response\"\"\"\n from log_parser import estimate_tokens\n tokens = estimate_tokens(response)\n resp_json = json.dumps({'assistant_response': response}, ensure_ascii=False)\n cursor.execute(\"\"\"UPDATE protokoll SET response = %s, response_timestamp = %s, tokens_output = %s,\n tokens_total = tokens_input + %s,\n duration_ms = ROUND(TIMESTAMPDIFF(MICROSECOND, request_timestamp, %s) \/ 1000, 3),\n status = 'completed' WHERE id = %s\"\"\", (resp_json, current_time, tokens, tokens, current_time, db_id))\n\n\ndef close_pending_user_prompts(session_id: str, conversation_pairs: List[Dict[str, str]]) -> None:\n \"\"\"Schließt offene UserPromptSubmit-Einträge mit ihren zugehörigen Responses\"\"\"\n if not conversation_pairs:\n return\n try:",
"numLines": 50,
"startLine": 95,
"totalLines": 160
}
}
}