iomgaa
b929a5db6c
fix(harness): Codex functional review 修复 — 命名/集成测试/delta_min/promote 消息
...
- _apply_env_overrides → _apply_env_var_overrides,docstring 明确从 os.environ 读取
- 新增 TestLoadConfigRealYaml:用真实 config/default.yaml 验证嵌套 harness 解析
- 新增 test_delta_min_negative_rejected:覆盖 gate_delta_min >= 0 校验
- 恢复 promote 模式独立错误消息(从合并分支分离回 TRM4 原始提示)
- 77 个单元测试全部通过,radon 全部 Grade B 或更好
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 12:23:27 -04:00
iomgaa
ce43871828
fix(harness): 补充 train 模式 run_id 校验 + 拆分函数保持 radon Grade B
...
- _validate_mode_deps: 恢复 train 非 resume/fresh 时必须提供 run_id 校验
- 提取 _validate_train_run_id 用 early return 展平条件,避免 radon Grade C
- 合并 promote run_id 检查到 diagnose/evolve/promote 统一检查
- 新增 4 个测试:train+run_id / train+resume / train+fresh / train+baseline
- radon cc -n C 无输出(全部 Grade B 或更好)
- 74 个单元测试全部通过
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 12:14:28 -04:00
iomgaa
09a385addc
feat(harness): RunConfig frozen dataclass + 四层校验 + YAML/CLI/.env 三层加载
...
- RunConfig: 46 字段 frozen dataclass,从 TRM4 core/harness/config.py 迁移
- 四层校验链:_validate → _validate_edit_budget + _validate_minibatch + _validate_gate
- 新增 .env 覆盖层:工程配置(workspace_dir, store_dir)可通过 HARNESS_* 环境变量注入
- 合并优先级:CLI > .env > YAML(CLAUDE.md §4.5)
- load_config 支持嵌套 harness 段和扁平 YAML 两种格式
- run_id 改为默认空字符串(CLI-only 字段,YAML 不提供)
- resume/fresh 互斥校验不在 config 层(移至 runner.py)
- 70 个单元测试全部通过
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 11:57:35 -04:00
iomgaa
4634414606
feat(evolution): evolve.py per-target evolution — skill/system/tool ( #9 )
2026-07-07 10:26:58 -04:00
iomgaa
6072ee7d0b
feat(evolution): evolve.py validation + helpers ( #9 )
2026-07-07 10:12:15 -04:00
iomgaa
dc091361c3
feat(evolution): diagnose.py aggregation + case packs + run_diagnosis ( #8 )
2026-07-07 10:04:48 -04:00
iomgaa
49d6fe8f51
feat(evolution): diagnose.py metrics + attribution (Stage 1, #8 )
2026-07-07 09:55:22 -04:00
iomgaa
f7193551dd
feat(evolution): validate.py — pure block validation decision functions ( #7 )
2026-07-07 09:47:45 -04:00
iomgaa
3005f24577
feat(evolution): patch.py — 补丁引擎移植(算法 #9),51 测试全通过
...
从 TRM4 core/harness/patch.py (427 行) 零修改移植到 core/evolution/patch.py。
包含:
- 7 个常量(APPENDIX/MOMENTUM marker + MAX_CHARS + HEADING)
- appendix 区:追加/提取/替换/边界检测,损坏态 ValueError
- momentum 区:替换/提取/边界检测,注入防护
- apply_patch_with_report:4 种 op(append/insert_after/replace/delete)
- 冻结区坐标判定(每条 edit 重算)、report 1-based index
- 51 个单元测试覆盖全部公共 API 及边缘场景
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 09:44:05 -04:00
iomgaa
4eefbfdd74
feat(evolution): gate.py — CE-Gate e-process 纯函数 ( #5 算法保真)
...
从 TRM4 core/harness/eprocess.py 逐行迁移,零逻辑变更:
- compute_e_value: 截断 Beta 混合 e 值(log 空间 + betainc 对称性)
- gate_decision: 四出口优先级链(confirmed→directional→futility→exhaustion→continue)
- probation_verdict: 试用期非对称双向结算
- 常量保真: _WALD_WIN=ln1.4, _WALD_LOSS=ln0.6, _SHRINK_PSEUDO=4
仅变更: import 路径 + GateParams/GateVerdict 移至 types.py + 中文 docstring
14 tests 覆盖: e 值数学、边界校验、四出口路径、试用期三分支
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 09:38:21 -04:00
iomgaa
9d4d52dac5
feat(core/evolution): protocols.py + types.py 基础层 — 18 个 dataclass + 3 个 Protocol
...
TRM4 诊断/进化/门控数据类型迁移至 TRM5 Clean Architecture 内核。
逐字段比对 TRM4 的 eprocess.py、diagnose.py、evolve.py 保真迁移。
types.py (18 个 dataclass):
- Gate: GateParams, GateVerdict (frozen, 原样迁移)
- 诊断: SpanMetrics, SkillStepAdherence, QuestionMetrics,
ErrorAttribution, CaseSample, SkillCasePack, SystemCasePack,
ToolCasePack, DiagnosisResult (全部 frozen=True)
- 进化: EvolutionRecord (mutable), RejectedEdit (frozen),
EvolutionResult (frozen, 移除 skills_version/prompts_version)
- 新增: PairResult, QuadrantClassification (块验证纯决策输出)
- 新增: DiagnosePrompts, EvolvePrompts (模板束, frozen)
protocols.py (3 个只读 Protocol):
- SkillStore, PromptStore (同步文件读取)
- RunLog (异步日志查询, 隔离 SQL)
变更理由:
- QuestionMetrics 由 TRM4 mutable 改为 frozen (一次性构造)
- ErrorAttribution 由 TRM4 mutable 改为 frozen (构造时填入全部字段)
- EvolutionResult 移除版本管理字段 (app/ 职责)
涉及算法: #5(CE-Gate), #8(诊断瀑布), #9(进化引擎)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 09:34:04 -04:00
iomgaa
499c5b8043
feat(search): __init__.py 公开 API + 修复 OCR 测试 asyncio 兼容性
2026-07-07 06:13:25 -04:00
iomgaa
4baf92c93f
feat(search): PromptManager — 搜索 Agent 提示词加载与组装
...
从 TRM4 core/search/prompt.py 迁移。有意变更:
- 工具描述从 app.search.tools.get_tool_descriptions 获取
- format_user_prompt 参数显式化(question/options/l1_node_ids/task_type)
16 个单元测试覆盖 __init__、build_inference_prompt(auto/manual/none
三种 skill_mode)、format_user_prompt、load。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 06:11:13 -04:00
iomgaa
f4f92b0938
feat(search): 实现 SearchToolDispatcher 工具调度器 (Task 7)
...
- 新增 app/search/tools.py:
- get_tool_descriptions() 工具描述文本(与 TRM4 一致)
- SearchToolDispatcher 类实现 ToolDispatcher Protocol
- dispatch() 按工具名路由: view_node / search_similar /
observe_frame / submit_answer / read_skill
- ValueError(未知工具)上抛,KeyError/FileNotFoundError 捕获返回错误文本
- view_node: env.get_node_text + summarize_node + get_children_info + summarize_children
- search_similar: env.search_similar + summarize_nodes_batch
- observe_frame: env.resolve_frame_paths + get_subtitle + observe_frame + 字幕前置
- 修复 app/tree/environment.py get_children_info():
- 原实现返回 _format_time_range (str) 导致 summarize_children 解包失败
- 改为返回原始数值元组 via 新增 _node_time_range_raw 静态方法
- 新增 tests/unit/test_search_tools.py (14 tests):
- get_tool_descriptions 含/不含 read_skill
- 五种工具 dispatch 路由验证
- 未知工具 ValueError + 节点不存在错误文本
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 06:07:27 -04:00
iomgaa
ba7fdaddf6
style: format vision.py
2026-07-07 05:53:33 -04:00
iomgaa
3ae3d5ab50
feat(search): app/search/vision.py — 两轮 VLM 帧观察模块
...
从 TRM4 core/tree/vision.py 迁移 observe_frame,关键变更:
- VLM 调用走 VLMProvider.chat_with_images Protocol(images 传 Path)
- OCR 调用走 OCRProvider.transcribe_frames 异步 Protocol
- 遥测字段 session_id / parent_call_id 透传
- 帧文件存在性前置校验
12 个单元测试覆盖:两轮正常、仅提取、OCR 注入/失败降级/None、
VLM 提取失败、VLM 验证失败降级、帧缺失、stats 完整性、
分歧/弃权标记、遥测透传。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 05:52:54 -04:00
iomgaa
86b19d1e07
feat(adapters): OCRProvider Protocol + MonkeyOCRClient 异步适配器
...
- app/ports.py: 新增 OCRProvider Protocol(runtime_checkable,与
EmbeddingProvider 同级),定义 async transcribe_frames 端口
- adapters/ocr.py: 从 TRM4 core/tree/ocr.py 保真迁移 MonkeyOCRClient
- assert → ValueError(P5 防御性校验)
- 公开方法改 async(asyncio.to_thread 包装同步 HTTP)
- 内部逻辑不变:多端点轮询、线程安全 Session、单帧降级、行去重
- tests/unit/test_ocr_adapter.py: 17 个测试覆盖 Protocol 合规、
构造校验、健康检查、转录、降级、去重、轮询
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 05:47:55 -04:00
iomgaa
60e737e2fc
feat(search): app/search/skills.py — 技能注册表与 frontmatter 解析
...
从 TRM4 core/search/skills.py 保真迁移。提供 parse_frontmatter、
strip_frontmatter、SkillRegistry、discover_skills 四个公共 API。
逻辑完全一致,仅调整导入路径并添加中文 docstring。
17 个单元测试全部通过,覆盖正常/异常/边界场景。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 05:46:25 -04:00
iomgaa
44ee62867d
feat(tree): add get_node_text + get_children_info to TreeEnvironment
...
- get_node_text(node_id, anchor=False): returns raw text + optional
anchor_map dict by parsing [cN]/[sN] prefixes from anchored text
- get_children_info(node_id): returns structured child list with
id/time_range/summary (description truncated to 120 chars)
- Both methods reuse existing internal helpers (_node_full_text,
_node_anchored_text, _get_children, _node_description,
_format_time_range)
- 9 new test cases across TestGetNodeText and TestGetChildrenInfo
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 05:45:48 -04:00
iomgaa
d8a903fb54
feat(question_gen): QuestionGenerator Protocol + 模块公开 API
...
app/ports.py 追加 QuestionGenerator Protocol(预留 LLM 出题接口)。
app/question_gen/__init__.py re-export load_benchmark 和 stratified_sample。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 04:48:21 -04:00
iomgaa
8d515ff01f
feat(question_gen): stratified_sample — 分层采样 + 题型保底
...
算法 100% 保真 TRM4: task_types 过滤、correctness.get(id, False) 语义、
对题在前返回顺序、min_per_class 遍历 pool 全部题型(含稀疏类)。
所有参数显式传入,无默认值。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 04:45:19 -04:00
iomgaa
dea8a7d3f6
feat(question_gen): load_benchmark — benchmark JSON 加载
...
从 JSON 目录 glob *.json 加载题目,stem 作 video_id。
legacy schema 无 difficulty 字段时赋 _LEGACY_DEFAULT_DIFFICULTY 常量。
options/source_nodes 转 tuple 配合 frozen dataclass。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 04:41:25 -04:00
iomgaa
eea3bcba3f
feat(core): 追加 GeneratedQuestion frozen dataclass
...
跨层共享类型,被 core/evolution/ 和 app/harness/、app/question_gen/ 使用。
frozen=True + tuple 字段确保不可变。无默认值(显式传入)。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 04:36:56 -04:00
iomgaa
4686adf266
feat(tree/repair): 检测器扩展 — visible_entities/ongoing_actions/spatial_layout 为空也触发修复
2026-07-07 03:15:42 -04:00
iomgaa
73b240cc84
test(tree): 建树模块端到端集成测试
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 02:44:28 -04:00
iomgaa
18971a794b
feat(tree/repair): Q&A 反向补全 — 从 TRM4 supplement 迁移
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 02:37:50 -04:00
iomgaa
edaa0d8290
feat(tree): VideoTreeBuilder 保真 #1 #2 #3 + 复杂度重构
...
- 从 reference/video_tree_trm/video_tree_builder.py (994行) 迁移
- 保真算法 #1 : L2 轴心建树策略 (asyncio.gather 链式并发)
- 保真算法 #2 : VLM 批量帧描述 + JSON fallback (_L3_BATCH_SIZE=5)
- 保真算法 #3 : 断点续跑 (progress.json + L1 中间 JSON)
- 新增: VLMProvider/LLMProvider Protocol 替代 LLMClient
- 新增: 结构化 JSON 输出 → L1Card/L2Card/L3Card
- 新增: L2 代表帧复用 L3 帧 (_sample_representative_frames)
- 新增: 字幕注入 + Voronoi 分配
- 重构: 提取 _load_resume_state/_assemble_roots 降低 _build_async 复杂度 D(21)→C(14)
- 44 个单元测试全部通过
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 02:17:50 -04:00
iomgaa
12f20493c1
feat(tree): 质量校验 — 交叉验证 entities/visible_text
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 01:57:32 -04:00
iomgaa
fb6f9964d8
feat(tree): 字幕模块 — SRT 解析 + 完整性检查 + Voronoi 分配
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 01:54:09 -04:00
iomgaa
e3b027ce34
feat(adapters): GovernedVLMClient — VLMProvider 最小可用实现
...
- 包装 GovernedLLMClient,注入 base64 图片到 OpenAI Vision API 格式
- 复用 LLM 治理栈全部能力(熔断、缓存、重试、遥测)
- 8 项单元测试覆盖协议满足、图片编码、注入逻辑、不可变性
2026-07-07 01:49:55 -04:00
iomgaa
c1680447c0
feat(adapters): EmbeddingProvider Protocol + local/remote 双后端实现
...
- app/ports.py: 添加 EmbeddingProvider Protocol(runtime_checkable,dim 属性 + embed 方法)
- adapters/embedding.py: 从参考代码迁移,拆分为 LocalEmbeddingProvider 和 RemoteEmbeddingProvider
- Local: sentence-transformers 冻结推理,维度校验
- Remote: OpenAI 兼容 API,L2 归一化,按 index 排序
- 两者均提供 embed() 和 embed_tensor() 统一接口
- tests/unit/test_embedding_adapter.py: Protocol 满足性、形状校验、导入测试
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 01:45:09 -04:00
iomgaa
22ad014973
feat(tree): TreeIndex 数据结构 — Card 体系 + 节点 + 序列化
...
- 新增三级 frozen Card dataclass: L3Card(6字段), L2Card(7字段), L1Card(7字段)
- 节点重构: L3Node/L2Node/L1Node 使用 Card 替代原始字符串字段
- 添加 @property 兼容层: description/summary 代理到 Card 字段
- L3Node 新增 subtitle 字段(字幕集成预留)
- JSON 序列化/反序列化支持 Card 结构 + embedding base64 编解码
- load_json 新增 ID 唯一性校验(重复 ID 抛 ValueError)
- 移除 pickle 序列化(仅保留 JSON)
- 日志从 log_msg 迁移到 loguru
- 17 个单元测试全部通过
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-07 01:35:10 -04:00
iomgaa
dc6f8e047e
test: AgentLoop + GovernedLLMClient 集成测试
...
验证 core/agent/ 通过 LLMProvider Protocol 与 adapters/ 端到端协作。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 23:13:59 -04:00
iomgaa
ee90fb8e88
fix(adapters): 修复 GovernedLLMClient 流式消费和规格偏差
...
- _stream_request + _consume_stream 合并为 _call_streaming,
在 async with self._http.stream() 内直接消费流,
确保看门狗作用于真实 HTTP 流而非内存列表(Critical 1)
- breaker 检查移到 call_id 生成之前(Critical 2)
- cache/ttft_timeout_s/inter_token_timeout_s 支持 None(Important 1)
- 重试失败路径遥测使用统一 call_id(Important 2)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 23:08:52 -04:00
iomgaa
f1a0414be8
feat(adapters): 实现 GovernedLLMClient 四层治理栈
...
流式 SSE + 三层看门狗 + 重试退避 + 熔断 + Redis 缓存 + 遥测。
provider 差异处理(DeepSeek reasoning_content vs Qwen think 标签)。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 23:00:22 -04:00
iomgaa
9ca9035190
feat(core/agent): 实现 AgentLoop 推理循环引擎
...
保真 TRM4 算法 #11 : json_repair 兜底、submit_answer 终止、
pluggy hook 生命周期、无效工具不计步。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:43:22 -04:00
iomgaa
c2ff2855b7
feat(adapters): 实现三层流式看门狗
...
TTFT / inter_token / total 超时保护。
参考 CHSAnalyzer2 streaming.py。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:43:01 -04:00
iomgaa
82f065e4ef
feat(adapters): 实现 SQLiteTelemetryRecorder
...
asyncio.to_thread 桥接 SQLite,字段与 TelemetryRecorder Protocol 一一对应。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:40:15 -04:00
iomgaa
14bb60e918
feat(adapters): 实现 CircuitBreaker 内存级熔断器
...
注入 now 纯确定性,force_open 支持 401/403 直接熔断。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:39:57 -04:00
iomgaa
9dae7dda98
feat(adapters): 实现 RedisResponseCache
...
content-addressed sha256 缓存键,Redis 不可用时静默降级。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:39:42 -04:00
iomgaa
d79d67b1d3
feat(core/agent): 添加 ToolDispatcher Protocol 和 AgentLoopSpec hookspec
...
ToolDispatcher async + context 参数。AgentLoopSpec 四个 async 生命周期 hook。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:36:31 -04:00
iomgaa
112111408e
feat(core): 添加共享 Protocol 端口
...
LLMProvider / VLMProvider / TelemetryRecorder,全部 runtime_checkable。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:36:23 -04:00
iomgaa
70320d7cfa
feat(core): 添加 LLMResponse frozen dataclass
...
含 content/thinking/ttft_ms/max_inter_token_ms/call_id 等 11 个字段。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:33:48 -04:00
iomgaa
9340c5e0f8
feat(core/agent): 添加 Step 和 LoopResult 数据类
...
保真 TRM4 算法 #11,Step 新增 call_id 字段。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 22:32:59 -04:00
iomgaa
e60823de1a
build: add README, pyproject.toml, package skeletons and smoke test
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-06 11:37:59 -04:00