fix(writer): 无子节章剔除 LLM 自造 heading 块

- writer_agent: prompt【小节约束】明确空结构时不得输出 heading 块
- writer_agent: generate_chapter 程序化强制——template_marker.sub_headings
  为空的章,剔除生成结果中全部 type=heading 的内容块(LLM 遵循度不完美,
  以模板结构为准做确定性兜底)
- 真实试运行验证:自造与章同名 H2 清零、H2 总数 14→6(仅模板定义子节)、
  内容引用不受影响
This commit is contained in:
lhl
2026-08-24 13:19:11 +08:00
parent 0a498e4f7a
commit 5091125fbc
3 changed files with 55 additions and 1 deletions
+1
View File
@@ -116,3 +116,4 @@
| 2026-08-24 | Agent 实现 | 试运行脚本与运行说明:新增 scripts/run_trial.py(库级端到端驱动——argparse 默认指向 samples/ 股票追加改修+sunOnly+真实模板;--fake 离线 FakeEngine / 默认 build_inference_engine 真实 LLM 读 .env keySourceParser→WriteOrchestrator 门控自动影响调查→output/output.docx + impact-report.json;暴露 main(argv) 供测试);新增 tests/test_run_trial.pyfake 模式断言 13 章 + summary 16/5/8/3/50/0 + 文件产出 + docx 注入);.gitignore 新增 output/(试运行产物不入库);新建 README.md(安装/配置 .env/离线与真实试运行命令/输出/测试);TDD REDModuleNotFoundError)→ GREEN2 passed)→ 全量 364 passed / 99.28%fake 试运行 PASS13 章、summary 与 MVP 基线一致、output.docx 含注入文本);真实 LLM 试运行待用户配置 .env API Key | scripts/run_trial.py; tests/test_run_trial.py; .gitignore; README.md; _AI_USAGE_LOG.md | deepseek-v4-flash |
| 2026-08-24 11:50 | Agent 实现 | Writer 章节级数据注入(design §6.8 ①落地):CHAPTER_SHEET_TYPES/CHAPTER_IMPACT_ELEMENT 映射、_format_chapter_data 按章定向注入 ExcelTable、_format_impact 按要素类型过滤;修复关键缺陷——真实 PromptRegistry.get 返回模板字符串导致引擎从不渲染变量(LLM 收到 {{占位符}} 原文),_resolve_prompt 统一包装为 Prompt 对象;prompt 增加【主题约束】。真实试运行验证:13 章主题全部正确(機能/画面/帳票/DB/IF/バッチ各写其义)、引用 F001-F004/TB001-004 影响数据、语言漂移顺带消除 | src/genesis/writer/models.py, src/genesis/writer/writer_agent.py, tests/test_phase5_models.py, tests/test_phase5_writer_agent.py, tests/test_phase5_context_builder.py | x-preview-f-free (opencode) |
| 2026-08-24 12:23 | Agent 实现 | 遗留项修复——无锚点子章静默丢弃:template_mapper 按 design §6.5 仅 H1 起章、H2/H3 归并父章 sub_headingsto_vars 注入小节结构 + prompt【小节约束】按小节组织内容;DocxInjector 新增裸重复子节标题去重(模板空 H2/H3 与生成同名且无内容时删除)。真实试运行:13→7 章、无静默丢弃告警、14 个 H2 无重复 | src/genesis/writer/template_mapper.py, src/genesis/writer/models.py, src/genesis/writer/writer_agent.py, src/genesis/writer/docx_injector.py, tests/test_phase5_template_mapper.py, tests/test_phase5_models.py, tests/test_phase5_writer_agent.py, tests/test_docx_injector.py, tests/test_run_trial.py | x-preview-f-free (opencode) |
| 2026-08-24 13:18 | Agent 实现 | 修复无子节章 LLM 自造标题:prompt【小节约束】禁止空结构时输出 heading 块(尽力约束)+ WriterAgent.generate_chapter 程序化强制(sub_headings 为空的章剔除生成结果中的 heading 块,模板结构为准)。真实试运行验证:自造同名 H2 清零、H2 总数 14→6(仅模板定义的子节)、无子节章正文全为段落 | src/genesis/writer/writer_agent.py, tests/test_phase5_writer_agent.py | x-preview-f-free (opencode) |