{
"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",
"permission_mode": "default",
"hook_event_name": "PostToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/scripts\/pipeline\/detect.py"
},
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/scripts\/pipeline\/detect.py",
"content": "\"\"\"\nFile detection for KI-System Pipeline\nMonitors Nextcloud folder for new\/changed documents.\n\"\"\"\n\nimport hashlib\nimport os\nfrom pathlib import Path\n\nfrom config import NEXTCLOUD_PATH, SUPPORTED_EXTENSIONS\nfrom db import db\n\n\ndef calculate_file_hash(file_path):\n \"\"\"Calculate SHA-256 hash of file.\"\"\"\n sha256 = hashlib.sha256()\n with open(file_path, \"rb\") as f:\n for chunk in iter(lambda: f.read(8192), b\"\"):\n sha256.update(chunk)\n return sha256.hexdigest()\n\n\ndef scan_directory(path=None):\n \"\"\"\n Scan directory for supported documents.\n Returns list of files to process.\n \"\"\"\n path = path or NEXTCLOUD_PATH\n files_to_process = []\n\n if not os.path.exists(path):\n db.log(\"ERROR\", f\"Source path does not exist: {path}\")\n return files_to_process\n\n for root, dirs, files in os.walk(path):\n # Skip hidden directories\n dirs[:] = [d for d in dirs if not d.startswith(\".\")]\n\n for filename in files:\n # Skip hidden files\n if filename.startswith(\".\"):\n continue\n\n file_path = os.path.join(root, filename)\n ext = Path(filename).suffix.lower()\n\n if ext not in SUPPORTED_EXTENSIONS:\n continue\n\n file_stat = os.stat(file_path)\n file_hash = calculate_file_hash(file_path)\n\n # Check if file exists in database\n existing_id = db.document_exists(file_path)\n\n if existing_id:\n # Check if file changed (by hash)\n cursor = db.execute(\"SELECT file_hash FROM documents WHERE id = %s\", (existing_id,))\n result = cursor.fetchone()\n cursor.close()\n\n if result and result[\"file_hash\"] != file_hash:\n files_to_process.append(\n {\n \"path\": file_path,\n \"name\": filename,\n \"ext\": ext,\n \"size\": file_stat.st_size,\n \"hash\": file_hash,\n \"action\": \"update\",\n \"existing_id\": existing_id,\n }\n )\n else:\n files_to_process.append(\n {\n \"path\": file_path,\n \"name\": filename,\n \"ext\": ext,\n \"size\": file_stat.st_size,\n \"hash\": file_hash,\n \"action\": \"new\",\n }\n )\n\n return files_to_process\n\n\ndef queue_files(files):\n \"\"\"Add detected files to processing queue.\"\"\"\n queued = 0\n for file_info in files:\n queue_id = db.add_to_queue(file_info[\"path\"], file_info[\"action\"])\n db.log(\"INFO\", f\"Queued: {file_info['name']}\", f\"queue_id={queue_id}\")\n queued += 1\n return queued\n\n\ndef run():\n \"\"\"Main detection routine.\"\"\"\n db.connect()\n db.log(\"INFO\", \"Starting file detection scan\")\n\n try:\n files = scan_directory()\n db.log(\"INFO\", f\"Found {len(files)} files to process\")\n\n if files:\n queued = queue_files(files)\n db.log(\"INFO\", f\"Queued {queued} files\")\n\n return files\n\n except Exception as e:\n db.log(\"ERROR\", f\"Detection error: {str(e)}\")\n raise\n finally:\n db.disconnect()\n\n\nif __name__ == \"__main__\":\n files = run()\n for f in files:\n print(f\"[{f['action']}] {f['name']} ({f['size']} bytes)\")\n",
"numLines": 125,
"startLine": 1,
"totalLines": 125
}
},
"tool_use_id": "toolu_012uJwxUGfmn95dpEPHFJb9Z"
}
}