Fix: save_block_content now writes draft file + writer must update status
Two issues that caused QA agent to fail: 1. save_block_content saved to DB only — now also rebuilds drafts/decision.md 2. legal-writer.md now has explicit mandatory step: case_update(status="drafted") Without these, workflow_status reports has_draft=false and QA can't run. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -685,7 +685,10 @@ async def get_block_context(case_id: UUID, block_id: str, instructions: str = ""
|
||||
|
||||
|
||||
async def save_block_content(case_id: UUID, block_id: str, content: str) -> dict:
|
||||
"""Save block content written by Claude Code (or any external writer)."""
|
||||
"""Save block content written by Claude Code (or any external writer).
|
||||
|
||||
Saves to DB and also writes/updates the draft file on disk.
|
||||
"""
|
||||
if block_id not in BLOCK_CONFIG:
|
||||
raise ValueError(f"Unknown block: {block_id}")
|
||||
|
||||
@@ -699,9 +702,37 @@ async def save_block_content(case_id: UUID, block_id: str, content: str) -> dict
|
||||
result["model_used"] = "claude-code"
|
||||
|
||||
await store_block(UUID(decision["id"]), result)
|
||||
|
||||
# Also write/update the draft file on disk
|
||||
await _update_draft_file(case_id, UUID(decision["id"]))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
async def _update_draft_file(case_id: UUID, decision_id: UUID) -> None:
|
||||
"""Rebuild drafts/decision.md from all blocks in DB."""
|
||||
from pathlib import Path
|
||||
|
||||
case = await db.get_case(case_id)
|
||||
if not case:
|
||||
return
|
||||
|
||||
case_dir = config.find_case_dir(case["case_number"])
|
||||
draft_dir = case_dir / "drafts"
|
||||
draft_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
pool = await db.get_pool()
|
||||
async with pool.acquire() as conn:
|
||||
rows = await conn.fetch(
|
||||
"SELECT content FROM decision_blocks WHERE decision_id = $1 AND content != '' ORDER BY block_index",
|
||||
decision_id,
|
||||
)
|
||||
|
||||
draft_path = draft_dir / "decision.md"
|
||||
draft_path.write_text("\n\n".join(row["content"] for row in rows if row["content"]), encoding="utf-8")
|
||||
logger.info("Draft file updated: %s (%d blocks)", draft_path, len(rows))
|
||||
|
||||
|
||||
# ── Renumbering ───────────────────────────────────────────────────
|
||||
|
||||
async def renumber_all_blocks(decision_id: UUID) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user