Commit Graph
78 Commits
Author SHA1 Message Date
lhl 0a498e4f7a fix(writer): 无锚点子章归并父章生成 + 注入后裸重复子节去重
- template_mapper: 按 design §6.5 仅 Heading level<=1 起章,H2/H3 归入
  父章 sub_headings(此前每个 heading 独立成章,无 {{section:id}} 锚点的
  6 个子章生成后被静默丢弃)
- models: ChapterSpec.sub_headings 字段;to_vars 暴露 sub_headings 变量
- writer_agent: prompt 新增【小节约束】(有子节时按小节顺序以 level=2
  heading 组织,不得遗漏或新增)
- docx_injector: 注入后删除同章内与已生成标题同名且完全无内容的模板裸
  H2/H3(保守策略:带内容的模板子节保留)
- 真实试运行验证:7 章 / 无静默丢弃告警 / 14 个 H2 无重复
2026-08-24 12:23:35 +08:00
lhl 80ccc324fc fix(writer): 章节级数据注入 + 修复 prompt 从未渲染的关键缺陷
- models: CHAPTER_SHEET_TYPES/CHAPTER_IMPACT_ELEMENT 章节→数据映射(design §6.8 ①)
- models: _format_chapter_data 按章定向渲染 ExcelTable 为 Markdown;GENERIC 自由記述作通用背景
- models: _format_impact 支持按 ElementType 过滤(章节级影响上下文)
- writer_agent: {{source}}(全量repr) → {{data}}(章节数据);新增【主题约束】
- writer_agent: 关键修复——真实 PromptRegistry.get 返回模板字符串,
  引擎对 str 不做变量渲染,LLM 实际收到的是 {{占位符}} 原文;
  _resolve_prompt 统一包装为 Prompt 对象保证渲染
- 真实试运行验证:13 章主题全部正确、引用影响调查数据、语言漂移消除
2026-08-24 11:50:59 +08:00
lhl 6372bb17b9 feat(run): 试运行脚本 + 运行说明(真实 LLM 默认 / --fake 离线)
- scripts/run_trial.py:库级端到端驱动(argparse 默认指向 samples/ 股票追加改修+sunOnly+真实模板)
  - --fake 离线 FakeEngine(无 key)/ 默认 build_inference_engine 真实 LLM(读 .env)
  - SourceParser → WriteOrchestrator 门控自动影响调查 → output/output.docx + impact-report.json
  - 暴露 main(argv) 供测试
- tests/test_run_trial.py(fake 模式断言 13 章 + summary 16/5/8/3/50/0 + 文件产出 + docx 注入)
- .gitignore 新增 output/(试运行产物不入库)
- 新建 README.md(安装 / .env 配置 / 离线与真实试运行 / 输出 / 测试)
- 全量 364 passed / 99.28%;fake 试运行 PASS(13 章、summary 与 MVP 基线一致)
2026-08-24 11:05:45 +08:00
lhl 61ac47c7af refactor(impact): CodeParser 多语言就绪——语言适配器注册表(仅 Java,行为不变)
- BaseLanguageParser 抽象基类 + JavaLanguageParser(迁移全部 Java 正则,输出逐字节一致)
- LANGUAGE_PARSERS 注册表 + register_language_parser 扩展点(新增语言=加适配器类并注册,下游零改动)
- CodeParser 分发器:parse(root, language=None) 自动按扩展名探测 / 显式语言覆盖 / 多语言合并(language 逗号连接)/ 无源码或语言不支持抛 CodeParseError
- source_aggregator 新增 existing_system_language 透传;config.py 探测扩展名补 .py/.ts/.go/.cs
- 删除自动探测下不可达死分支;全量 362 passed / 99.28%(基线 351/99.27%)
- 门禁复跑 PASS:summary 与 MVP 基线一致(16/5/8/3/50/0),概要设计书 13 章
2026-08-23 18:49:34 +08:00
lhl 2e11720a2d feat(impact): Impact Agent MVP —— 变更点定位 + 影响调查书(追加改修场景)
- 门控:用户提供 existing_system 路径 → 进入影响调查;未提供 → 原流程不变
- CodeParser 解析 Java(@RestController/@Service/@Entity/@TableName)+ ExistingSystemExplorer 组装
- ImpactAgent 变更点定位(变更区分×既存対応 确定性比对,无 LLM)→ ImpactReport(JSON 可下载)
- 影响调查结果作为 Writer 生成概要设计书的主上下文({{impact}},无专用影响章)
- source_aggregator 解除 existing_system=None 硬编码
- 既有系统样本 sunOnly/stock-trade-system(无 LICENSE,仅测试输入,保留来源标注)
- 新造股票交易域追加改修样本 要件定義_追加改修_股票.xlsx(对齐 sunOnly 真实类名)
- 全量 351 passed / 99.27% 覆盖;门禁 PASS(16 要素:新规5/変更8/削除3/未受影响50)
2026-08-23 17:59:08 +08:00
lhl da33df92e1 fix(writer): 防静默丢章告警 + 占位符正则宽容化(大小写/全角冒号) 2026-08-23 14:47:14 +08:00
lhl 48a9624723 fix(writer): 正文语言须与章节标题一致(模板日文则输出日文) 2026-08-14 00:12:51 +08:00
lhl 752fd2df6d fix(writer): 透传底层 LLM 错误详情(401 等)便于门禁定位 2026-08-13 23:55:38 +08:00
lhl 24b9511d43 test(writer/qa): 覆盖 engine=None 委托工厂的真实门禁路径 2026-08-13 23:13:58 +08:00
lhl 958e2602cc feat(inference): 接通真实 LLM 引擎工厂(P5-T10 门禁接线)
- 新增 inference/factory.build_inference_engine:读 GENESIS_INFERENCE__* / 裸
  DEEPSEEK_API_KEY·LLM_BASE_URL 环境变量与 .env,构造 HttpLLMClient + InferenceEngine
- orchestrator/qa_loop 的 engine=None 分支改用工厂,真正接通真实 LLM 路径
- 脚本注入校验改为通用(非空段落数 + 残留占位符),适配真实模式
- 补工厂测试(缺密钥/前缀变量/裸变量/默认值/.env 解析),覆盖率 99.04%
2026-08-13 23:11:31 +08:00
lhl e4f533799d chore: cleanup unused imports + design.md Phase5 notes 2026-08-13 11:49:58 +08:00
lhl 2770c76ba0 test(writer): cover async engine path in WriterAgent/orchestrator 2026-08-13 11:49:44 +08:00
lhl 64c271a22c test(qa): add headless Phase5 e2e (FakeLLM pipeline) 2026-08-13 11:23:00 +08:00
lhl 24d3aa3b85 feat(qa): add QALoop (closed loop, regenerate only failed chapters) 2026-08-13 11:12:22 +08:00
lhl b318c9fd41 feat(qa): add QAReport + QAValidator.validate_doc 2026-08-13 11:05:01 +08:00
lhl 48024a40db feat(qa): add QAValidator (validate_chapter + validate_document) 2026-08-13 10:56:33 +08:00
lhl d29cb78167 feat(eval): populate EvalReport.per_chapter + failed_chapters in score() 2026-08-13 10:44:35 +08:00
lhl 08e311b0a1 feat(writer): add WriteOrchestrator.generate (vertical slice, real DocxInjector.inject) 2026-08-13 10:32:35 +08:00
lhl f175203a23 feat(writer): add build_contexts (template+rules -> GenerationContext list) 2026-08-13 10:14:03 +08:00
lhl 1c40262401 feat(writer): add renderer (ChapterContent -> DocxInjector.Block) 2026-08-13 10:08:41 +08:00
lhl 0a2dd17b0b feat(writer): add WriterState (cross-chapter regeneration tracking) 2026-08-13 09:46:38 +08:00
lhl d237201407 fix(writer): map_template consumes real ParsedTemplate sections (positional section ids) 2026-08-13 09:38:14 +08:00
lhl c1fbcff088 feat(writer): add template_mapper (ParsedTemplate -> ChapterSpec) 2026-08-13 09:31:28 +08:00
lhl 8db9cbfdf7 fix(services): make RagService protocol sync + fix no-op isinstance assertion 2026-08-13 09:27:16 +08:00
lhl ce64f2536f feat(services): add RagService protocol + CannedRagService stub 2026-08-13 09:20:43 +08:00
lhl 22ba32c34f feat(writer): add WriterGenerationError 2026-08-13 09:11:58 +08:00
lhl 6540698bf6 feat(writer): add Phase5 data models (ContentBlock/ChapterContent/GenerationContext/ChapterSpec) 2026-08-13 09:08:08 +08:00
lhl 0b704fb07e feat: QA 护栏 + fallback 路由(T15 架构审查整改收官,OV6)
- src/genesis/qa/guardrails.py: resolve_qa_model() 强制 QA 走 fallback 模型(防
  DeepSeek 校验 DeepSeek 自校验盲区);QALoopController(max_rounds=3) 约束
  「QA→Writer修正→重校验」循环边界防无限
- 集成测试验证 QA 调用实际落到 fallback 而非 primary(FakeLLMClient 记录 model)
- design.md §7.4 补 QA 护栏说明(循环边界 + 独立校验模型)
- TDD:257 passed / 100.00% 覆盖,17 项架构审查整改全部完成
2026-08-12 23:24:15 +08:00
lhl 3ae1f5f38f refactor(parsers): 提取 _validate_path helper(T7 架构审查整改,I8 DRY)
- source_aggregator.py 三处重复校验(扩展名白名单 + 存在性)提取为
  _validate_path(path, allowed_exts) -> Path,保留 ValueError/FileNotFoundError
  语义与错误信息,parse 三分支改用 helper
- 外部契约不变:未知扩展名→ValueError、不存在→FileNotFoundError
- 新增 3 用例直接测 helper
- TDD: RED(helper 不存在)→ GREEN(聚焦 13 passed)→ 全量 248 passed / 100.00%(1356 stmts/332 br)
2026-08-12 23:01:58 +08:00
lhl e3c714d5d9 feat(writer): docx 注入原型提前(T17 架构审查整改,OV8)
- T17 (OV8, P1): 新建 src/genesis/writer/ 包
  - docx_injector.py: DocxInjector 用原生 python-docx 实现 §6.6 占位符注入
    - 章节级 {{section:id}} → 内容块 docx 元素序列(heading/paragraph/table)
    - 行内 {{meta}} → 元信息填充
    - 残留检查: 未替换 {{...}} 抛 DocxInjectError
    - 格式精度: 注入 heading 继承模板 Heading 样式,原内容不被破坏
  - 新增 test_docx_injector.py(5 用例)
  - 同步 design.md §6.7 渲染链路 T17 原型说明
- TDD: RED(模块缺失)→ GREEN(聚焦 5 passed)→ 全量 245 passed / 100.00%(1361 stmts/340 br)
2026-08-12 22:47:43 +08:00
lhl d2e651bad0 feat(eval): 黄金集 + 评分器(T13 架构审查整改,OV4)
- T13 (OV4, P1): 新建 src/genesis/eval/ 包
  - golden_set.py: GoldenCase/GoldenSet(YAML 加载,samples/ 真实脱敏样本作 input_ref)
  - scorer.py: ChapterScorer 按 §7.2 指标体系打分
    - 确定性维度: traceability(resolver 验证 source_uri 可解析率)/
      placeholder_residue(无 {{...}} 残留)/chapter_completeness(章节覆盖)
    - LLM 语义维度: llm_evaluators 钩子(默认中性分,待 Phase5)
  - tests/fixtures/eval/golden_set.yaml 示例黄金集
- 新增 test_eval_scorer.py(9 用例)
- 同步 design.md §7.5 黄金集与评分器(定位 CI 质量门禁)
- TDD: RED(模块缺失)→ GREEN(聚焦 8 passed)→ 全量 240 passed / 100.00%(1279 stmts/308 br)
2026-08-12 22:44:47 +08:00
lhl 69aec7716c feat(provenance): URI 统一 + resolver + 强验证(T12 架构审查整改)
- T12 (OV3, P1): 新建 src/genesis/parsers/resolver.py
  - parse_source_uri: 解析 file.xlsx#Sheet!CellRef → SourceRef(格式非法 raise URIError)
  - provenance_to_uri: Provenance 还原 URI(与 build_source_uri 互逆)
  - resolve_source_uri: StructuredSource 内定位真实 CellValue
  - validate_source_uris: 批量强验证 → ValidationResult(resolved/unresolved)
    格式错误或源中不存在一律 unresolved(防 QA#8 编造 URI 作弊)
- URI 唯一生成入口 build_source_uri(provenance.py),无散落不一致
- 新增 test_resolver.py(13 用例);同步 design.md §9.2 + §6.8 第五步
- TDD: RED(模块缺失)→ GREEN(聚焦 10 passed)→ 全量 231 passed / 100.00%(1191 stmts/298 br)
2026-08-12 22:35:56 +08:00
lhl 6a54580ca4 feat(orchestrator): DataGate 机制化 + 任务级持久化(T14/T16 架构审查整改)
- T14 (OV5): 新建 src/genesis/orchestrator/datagate.py
  - DataGate.load(source, selector) 机制化:子集加载 + 规模保护(超 500 行
    无 selector 拒绝全量,1000 行 Excel 防上下文爆炸)+ token 预算(8000,
    复用 CJK 保守估算)+ 未知表容错
  - agent-runtime §4.2 原则→机制说明
- T16 (OV7): 新建 src/genesis/orchestrator/task_queue.py
  - TaskQueue ABC + PersistentTaskQueue(SQLite 落盘)
  - enqueue/poll/update_status/get/cancel/recover/close
  - 幂等去重(§5.3 缓存结果)+ recover 将 running→failed、pending 保留
  - api-design §5.2/5.3、agent-runtime §3.5/3.6、design §8.4.1 同步
- 新增 test_datagate.py(8 用例)+ test_task_queue.py(11 用例)
- TDD: RED(模块缺失)→ GREEN(聚焦 16 passed)→ 全量 218 passed / 100.00%(1140 stmts/278 br)
2026-08-12 15:43:10 +08:00
lhl 3decdfc31c feat(rag): v1 rerank 精排 + bge-m3 多语言切换(T6/T11 架构审查整改)
- T6 (Issue6): RerankConfig(enabled/model=BAAI/bge-reranker-v2-m3/device)
  - rag-layer-design §6.3 Rerank 精排:窗口=RRF top-10、候选≤top_k 跳过、
    故障降级 RRF 原序;原 §6.3-6.6 顺延 6.4-6.7
  - config-design §5 新增 rerank 段;design §5.5 检索策略加 rerank
- T11 (OV2): EmbeddingConfig.model 默认 bge-small-zh-v1.5 → BAAI/bge-m3(日文语料)
  - rag-layer-design 选型表/依赖表/manifest/流程图同步 + 新增 §2.3 日文样本验证
  - design.md / implementation-plan 4.3 / config-design embedding 同步
- 新增 test_rag_design_consistency.py 一致性门禁(6 用例防文档漂移)
- TDD: RED(默认模型仍旧 + rerank 字段不存在)→ GREEN → 全量 198 passed / 100.00%(996 stmts/252 br)
2026-08-12 11:32:28 +08:00
lhl c170ec2edd feat(config): 删死配置 + 同步文档(T5 架构审查整改)
- Issue5: 删除 QdrantStoreConfig / VectorStoreConfig.qdrant / task_queue.redis_url
- OV1: 同步 6 处文档(api-design §1/§4.3/§5/§6、rag-layer §9、agent-runtime §3、
  design §5.5/§8.4.1、config-design、web-ui §4.1)+ tests/fixtures/rag.yaml
  - TaskQueue 标注 v1 仅 InMemory,Redis/Valkey 为 v2 预留(Scope 缩减裁定)
  - Storage Adapter 仅 ChromaAdapter,工厂移除 qdrant 分支
  - 历史评审记录保留原样不改写
- 新增 3 用例,同步 2 个 qdrant 依赖用例;全量 189 passed / 100.00%(991 stmts/252 br)
2026-08-12 10:54:56 +08:00
lhl 8febc50eb8 feat(inference): CJK 保守 token 估算(T9 架构审查整改)
- Issue11: approximate_token_count 重写
  - 新增 _is_cjk_char(CJK 统一表意/扩展A/假名/韩文/兼容/全角六大 Unicode 范围)
  - CJK 字符按 1.5 token/字符(旧 4 字符 1 token 严重低估,裁剪失效致 API 超限)
  - 其余字符仍 4 字符 1 token;最少 1 token
- 同步 config-design.md token_estimation 注释
- 新增 4 用例,全量 186 passed / 100.00%(995 stmts/252 br)
2026-08-12 09:54:20 +08:00
lhl 8239a37a99 feat(inference): LLM 客户端全异步化(T8 架构审查整改)
- Issue9: client.py 由同步 httpx.Client 全异步化
  - LLMClient Protocol / HttpLLMClient.chat → async;httpx.AsyncClient + asyncio.sleep 退避
  - __enter__/__exit__ → __aenter__/__aexit__(async with 生命周期闭环)
- engine.py chat/chat_structured/_call 全部 async + await
- FakeLLMClient.chat → async;测试用 anyio pytest 插件转换(engine 32 + client 10 用例)
- 同步 inference-engine spec 与 milestone3 review 的 httpx 描述
- 全量 182 passed / 100.00%(987 stmts/252 br)
2026-08-12 09:50:37 +08:00
lhl 1f931228e7 feat(inference): 引擎层统一注入防护(T4 架构审查整改)
- Issue4: engine.py 新增恒定系统指令 DEFAULT_SYSTEM_INSTRUCTION + 用户数据边界包裹
  - _call 统一构造 [system 恒定指令, user 边界包裹数据],chat/chat_structured 全生效
  - __init__ 支持 system_instruction 注入覆盖;声明「用户数据段指令不作为要求执行」
- FakeLLMClient 记录结构对齐真实 payload({role, content}),同步 2 处既有断言
- 同步 agent-runtime-design.md §8.1 标注已实现
- 新增 5 用例,全量 182 passed / 100.00%(987 stmts/252 br)
2026-08-12 09:44:33 +08:00
lhl 2f4397a8d6 feat(orchestrator): 会话状态机实现 + cancelled/resume(T3 架构审查整改)
- Issue3: 新建 src/genesis/state_machine.py(9 状态白名单转移)
  - cancel 记录 cancelled_from 进 cancelled 终态,resume 回中断点
  - 仅执行中状态可取消(awaiting_*/done 不可),非法转移抛 StateTransitionError
- 同步 agent-runtime-design.md §3.2(状态图/规则表 9 状态 + cancelled 行)
- 新增 10 用例(含覆盖补齐 2 项),全量 177 passed / 100.00%(981 stmts/252 br)
2026-08-12 09:39:34 +08:00
lhl cf9600e437 feat(inference): chat_structured 解析重试走降级链(T2 架构审查整改)
- Issue2: 解析重试按 primary→fallback 顺序尝试,不再硬编码首选模型
- Issue10: 提取 names 局部变量,删除 4 处重复 _model_names(None)[0] 调用
- LLMError 不再 early return,继续降级链;全部失败按 last_was_parse_error 区分 parse_error/failed
- 新增 2 用例(解析/网络失败降级 fallback),同步更新 7 个既有用例至降级链语义
- 全量 165 passed / 100.00% 覆盖(941 stmts/242 br),fail_under=99 达标
2026-08-12 09:36:10 +08:00
lhl 25fc472d9b feat(inference): chat_structured 接入 jsonschema 真校验(T1 架构审查整改)
- pyproject.toml 新增 jsonschema>=4.23 依赖
- engine.py: json.loads 后 jsonschema.validate,校验失败按解析失败重试(带错误信息)
- 新增 3 用例:违规重试成功/耗尽 parse_error 含详情/合法一次通过
- 全量 163 passed / 100.00% 覆盖(936 stmts/238 br),fail_under=99 达标
2026-08-12 09:32:02 +08:00
lhl 31167c9314 chore: Phase3 Word 解析收尾(尾随换行/import 排序/契约注释) 2026-08-10 23:39:53 +08:00
lhl 16921ecbb4 test: 真实样本 Word 解析集成测试(模板/规则/说明书画属write) 2026-08-10 15:17:44 +08:00
lhl 7f29cc9cf3 feat: SourceParser 门面全量输入聚合 StructuredSource 2026-08-10 14:57:04 +08:00
lhl 9ab11da87d feat: RuleDocParser 规则文档 Markdown 化与分类 2026-08-10 10:14:15 +08:00
lhl 00fcbf18c3 feat: WordTemplateParser 章构成/占位符/样式名提取 2026-08-10 09:38:37 +08:00
lhl e8771aa797 test: docx 测试基建(新建/落盘/规则文档快捷构造) 2026-08-10 09:21:55 +08:00
lhl 464423b7ef chore: 一致性门禁收尾(plan 计数、尾换行、消息与注释润色) 2026-08-09 17:11:38 +08:00
lhl bb38a47445 test: api §7 与异常树错误码一致性门禁测试(防文档漂移) 2026-08-09 16:48:12 +08:00
lhl f3a30256d5 chore: 清理 error_code 收尾(删冗余死代码行、补尾换行) 2026-08-09 13:58:53 +08:00