DB-Migrationen (status_history, category) + Claude CLI stdin-Übergabe

- status_history Spalte für fact_checks (Faktencheck-Verlauf als JSON)
- category Spalte für article_locations (Marker-Klassifizierung)
- Prompt-Übergabe an Claude CLI via stdin statt Argument (ARG_MAX)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dieser Commit ist enthalten in:
claude-dev
2026-03-08 13:25:21 +01:00
Ursprung bcad3e9f3c
Commit 2dd11c9db7
2 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen

Datei anzeigen

@@ -41,12 +41,14 @@ class UsageAccumulator:
async def call_claude(prompt: str, tools: str | None = "WebSearch,WebFetch", model: str | None = None) -> tuple[str, ClaudeUsage]: async def call_claude(prompt: str, tools: str | None = "WebSearch,WebFetch", model: str | None = None) -> tuple[str, ClaudeUsage]:
"""Ruft Claude CLI auf. Gibt (result_text, usage) zurück. """Ruft Claude CLI auf. Gibt (result_text, usage) zurück.
Prompt wird via stdin uebergeben um OS ARG_MAX Limits zu vermeiden.
Args: Args:
prompt: Der Prompt für Claude prompt: Der Prompt fuer Claude
tools: Kommagetrennte erlaubte Tools (None = keine Tools, --max-turns 1) tools: Kommagetrennte erlaubte Tools (None = keine Tools, --max-turns 1)
model: Optionales Modell (z.B. CLAUDE_MODEL_FAST für Haiku). None = CLI-Default (Opus). model: Optionales Modell (z.B. CLAUDE_MODEL_FAST fuer Haiku). None = CLI-Default (Opus).
""" """
cmd = [CLAUDE_PATH, "-p", prompt, "--output-format", "json"] cmd = [CLAUDE_PATH, "-p", "-", "--output-format", "json"]
if model: if model:
cmd.extend(["--model", model]) cmd.extend(["--model", model])
if tools: if tools:
@@ -56,6 +58,7 @@ async def call_claude(prompt: str, tools: str | None = "WebSearch,WebFetch", mod
process = await asyncio.create_subprocess_exec( process = await asyncio.create_subprocess_exec(
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, *cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
stdin=asyncio.subprocess.PIPE,
env={ env={
"PATH": "/usr/local/bin:/usr/bin:/bin", "PATH": "/usr/local/bin:/usr/bin:/bin",
"HOME": "/home/claude-dev", "HOME": "/home/claude-dev",
@@ -64,7 +67,9 @@ async def call_claude(prompt: str, tools: str | None = "WebSearch,WebFetch", mod
}, },
) )
try: try:
stdout, stderr = await asyncio.wait_for(process.communicate(), timeout=CLAUDE_TIMEOUT) stdout, stderr = await asyncio.wait_for(
process.communicate(input=prompt.encode("utf-8")), timeout=CLAUDE_TIMEOUT
)
except asyncio.TimeoutError: except asyncio.TimeoutError:
process.kill() process.kill()
raise TimeoutError(f"Claude CLI Timeout nach {CLAUDE_TIMEOUT}s") raise TimeoutError(f"Claude CLI Timeout nach {CLAUDE_TIMEOUT}s")

Datei anzeigen

@@ -350,6 +350,26 @@ async def init_db():
await db.execute("ALTER TABLE fact_checks ADD COLUMN tenant_id INTEGER REFERENCES organizations(id)") await db.execute("ALTER TABLE fact_checks ADD COLUMN tenant_id INTEGER REFERENCES organizations(id)")
await db.commit() await db.commit()
# Migration: status_history fuer fact_checks (Faktencheck-Verlauf)
if "status_history" not in fc_columns:
await db.execute("ALTER TABLE fact_checks ADD COLUMN status_history TEXT DEFAULT '[]'")
# Bestehende Eintraege initialisieren
cursor2 = await db.execute("SELECT id, status, checked_at FROM fact_checks")
for row2 in await cursor2.fetchall():
import json as _json
initial_history = _json.dumps([{"status": row2[1], "at": str(row2[2])}])
await db.execute("UPDATE fact_checks SET status_history = ? WHERE id = ?", (initial_history, row2[0]))
await db.commit()
logger.info("Migration: status_history zu fact_checks hinzugefuegt")
# Migration: category fuer article_locations (Marker-Klassifizierung)
cursor = await db.execute("PRAGMA table_info(article_locations)")
al_columns = [row[1] for row in await cursor.fetchall()]
if "category" not in al_columns:
await db.execute("ALTER TABLE article_locations ADD COLUMN category TEXT DEFAULT 'mentioned'")
await db.commit()
logger.info("Migration: category zu article_locations hinzugefuegt")
# Migration: tenant_id fuer incident_snapshots # Migration: tenant_id fuer incident_snapshots
cursor = await db.execute("PRAGMA table_info(incident_snapshots)") cursor = await db.execute("PRAGMA table_info(incident_snapshots)")
snap_columns2 = [row[1] for row in await cursor.fetchall()] snap_columns2 = [row[1] for row in await cursor.fetchall()]