Skip to content

Commit eca2ece

Browse files
committed
fix: cleanup dead code + extend diff to all nodes
- Remove unused validate_chat_article_markdown() from validators.py - Remove _sync_chat_to_state residual comment block - Add 'writer' to _node_official_artifact_path() mapping - Extend /runs/{run_id}/diff endpoint with ?node= param for all nodes - Save .prev files for all artifact nodes in review chat (not just writer) - Delegate api.py _node_session_key to nodes.py (single source of truth)
1 parent f6f0017 commit eca2ece

2 files changed

Lines changed: 29 additions & 56 deletions

File tree

scripts/validators.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -338,46 +338,6 @@ def validate_writer_markdown(text: str, min_chars: int = 1200) -> ValidationResu
338338
return ValidationResult(ok=True, parsed=raw, normalized_text=raw + "\n")
339339

340340

341-
def validate_chat_article_markdown(text: str, min_chars: int = 800) -> ValidationResult:
342-
raw = _strip_code_fence(text).strip()
343-
details: list[str] = []
344-
bad_markers = [
345-
"微信文章无法直接提取",
346-
"基于",
347-
"我直接修改",
348-
"根据你的要求",
349-
"下面是修改后的",
350-
"以下是修改后的",
351-
"我会按这个风格",
352-
"已按",
353-
"我已经根据",
354-
"让我根据",
355-
"已重写",
356-
"主要调整",
357-
"风格特点是",
358-
]
359-
360-
if len(raw) < min_chars:
361-
details.append(f"content too short: {len(raw)} chars (< {min_chars})")
362-
363-
head = raw[:500]
364-
for marker in bad_markers:
365-
if marker in head:
366-
details.append(f"meta marker near opening: {marker}")
367-
368-
paragraphs = [p.strip() for p in re.split(r"\n\s*\n", raw) if p.strip()]
369-
if len(paragraphs) < 4:
370-
details.append(f"too few paragraphs: {len(paragraphs)}")
371-
372-
heading_count = sum(1 for line in raw.splitlines() if line.strip().startswith("## "))
373-
if heading_count < 2:
374-
details.append(f"too few section headings: {heading_count}")
375-
376-
if details:
377-
return ValidationResult(ok=False, message="chat article failed quality checks", details=details)
378-
return ValidationResult(ok=True, parsed=raw, normalized_text=raw + "\n")
379-
380-
381341
def validate_de_ai_markdown(text: str, original_text: str) -> ValidationResult:
382342
raw = _strip_code_fence(text).strip()
383343
details: list[str] = []

scripts/web/routes/api.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _node_official_artifact_path(run_id: str, node_id: str) -> Path | None:
5454
mapping = {
5555
"scout": run_dir / "topic.yaml",
5656
"researcher": run_dir / "research.yaml",
57+
"writer": run_dir / "article_edited.md",
5758
"director": run_dir / "visual_plan.json",
5859
"formatter": run_dir / "formatted.html",
5960
}
@@ -486,27 +487,45 @@ async def api_save_article(run_id: str, body: dict):
486487

487488

488489
@router.get("/runs/{run_id}/diff")
489-
async def api_get_diff(run_id: str):
490-
"""获取文章改动 diff(当前 vs 上一版本)"""
490+
async def api_get_diff(run_id: str, node: str | None = None):
491+
"""获取节点改动 diff(当前 vs 上一版本)。
492+
493+
?node=scout → topic.yaml diff
494+
?node=writer → article_edited.md diff (default)
495+
?node=researcher → research.yaml diff
496+
?node=director → visual_plan.json diff
497+
?node=formatter → formatted.html diff
498+
"""
491499
import difflib
492500

493501
run_dir = Path(__file__).parent.parent.parent.parent / "output" / "runs" / run_id
494-
current_path = run_dir / "article_edited.md"
495-
prev_path = run_dir / "article_edited.md.prev"
496-
draft_path = run_dir / "article_draft.md"
502+
503+
# 确定要 diff 的文件
504+
if node and node != "writer":
505+
artifact_path = _node_official_artifact_path(run_id, node)
506+
if not artifact_path:
507+
return JSONResponse({"error": f"未知节点: {node}"}, status_code=400)
508+
current_path = artifact_path
509+
prev_path = run_dir / f"{artifact_path.name}.prev"
510+
draft_path = None
511+
else:
512+
# 默认: writer article
513+
current_path = run_dir / "article_edited.md"
514+
prev_path = run_dir / "article_edited.md.prev"
515+
draft_path = run_dir / "article_draft.md"
497516

498517
if not current_path.exists():
499-
return JSONResponse({"error": "当前文章不存在"}, status_code=404)
518+
return JSONResponse({"error": f"当前产物不存在: {current_path.name}"}, status_code=404)
500519

501-
# 优先用 .prev(上一次审核改稿前的版本),fallback 用 article_draft.md(初稿
520+
# 优先用 .prev,fallback 用 draft(仅 writer
502521
if prev_path.exists():
503522
base_path = prev_path
504523
from_label = "上一版本"
505-
elif draft_path.exists():
524+
elif draft_path and draft_path.exists():
506525
base_path = draft_path
507526
from_label = "初稿"
508527
else:
509-
return JSONResponse({"diff": None, "message": "暂无历史版本"})
528+
return JSONResponse({"diff": None, "has_diff": False, "message": "暂无历史版本"})
510529

511530
current = current_path.read_text(encoding="utf-8").splitlines(keepends=True)
512531
previous = base_path.read_text(encoding="utf-8").splitlines(keepends=True)
@@ -518,7 +537,7 @@ async def api_get_diff(run_id: str):
518537
lineterm=""
519538
)
520539
diff_text = "\n".join(diff)
521-
return {"diff": diff_text}
540+
return {"diff": diff_text, "has_diff": bool(diff_text.strip())}
522541

523542

524543
# ── 节点数据 ──────────────────────────────────────────────────
@@ -1276,12 +1295,6 @@ async def api_update_settings_form(request: Request):
12761295
)
12771296

12781297

1279-
# ── 审核对话同步 ──────────────────────────────────────────────
1280-
1281-
# 旧的 _sync_chat_to_state 链路已退役:
1282-
# 审核聊天现在直接由节点主 session 修改正式产物,再由 Python 读回并提交。
1283-
1284-
12851298
# ── 内部函数 ──────────────────────────────────────────────────
12861299

12871300
async def _execute_pipeline(run_id: str):

0 commit comments

Comments
 (0)