thincoder 0.12.59 → 0.12.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -3
- package/README.md +2 -2
- package/bin/thincoder.mjs +80 -19
- package/package.json +4 -3
- package/src/acp/bridge.mjs +7 -4
- package/src/advisor/messages.mjs +24 -4
- package/src/advisor/run.mjs +35 -33
- package/src/advisor.mjs +25 -6
- package/src/agent/completion.mjs +17 -11
- package/src/agent/dispatch.mjs +102 -19
- package/src/agent/helpers.mjs +36 -0
- package/src/agent/record-results.mjs +46 -10
- package/src/agent/run-stages.mjs +227 -0
- package/src/agent/setup-reminders.mjs +62 -0
- package/src/agent/setup.mjs +18 -2
- package/src/agent/spawn-child.mjs +29 -4
- package/src/agent-tools/advisor-async.mjs +456 -0
- package/src/agent-tools/advisor.mjs +110 -108
- package/src/agent-tools/async-settle.mjs +191 -0
- package/src/agent-tools/consult.mjs +121 -102
- package/src/agent-tools/design-token.mjs +104 -0
- package/src/agent-tools/eng.mjs +24 -29
- package/src/agent-tools/escalate-async.mjs +286 -0
- package/src/agent-tools/read-history.mjs +155 -31
- package/src/agent-tools/recent-changes.mjs +2 -1
- package/src/agent-tools/settings.mjs +7 -17
- package/src/agent-tools/subagent-actions.mjs +168 -130
- package/src/agent-tools/subagent-async.mjs +129 -174
- package/src/agent-tools/subagent-panel.mjs +153 -0
- package/src/agent-tools/subagent-run.mjs +202 -0
- package/src/agent-tools/subagent-scheduler.mjs +45 -21
- package/src/agent-tools/subagent-spawn.mjs +406 -0
- package/src/agent-tools/subagent.mjs +107 -555
- package/src/agent-tools/verify.mjs +118 -270
- package/src/agent.mjs +57 -190
- package/src/cli/distill-command.mjs +10 -4
- package/src/cli/make-agent.mjs +3 -1
- package/src/cli/memory-command.mjs +2 -1
- package/src/cli/permission.mjs +2 -2
- package/src/cli/setup-wizard.mjs +17 -12
- package/src/config.mjs +56 -8
- package/src/context.mjs +5 -147
- package/src/crash-reports.mjs +123 -0
- package/src/distill.mjs +11 -11
- package/src/explore-distill.mjs +155 -0
- package/src/memory/code-sync.mjs +2 -1
- package/src/memory/core.mjs +6 -193
- package/src/memory/delete.mjs +234 -0
- package/src/memory/docs.mjs +58 -48
- package/src/memory.mjs +3 -1
- package/src/peer-domains.mjs +265 -0
- package/src/peer-instances.mjs +231 -0
- package/src/prompt-overlays.mjs +25 -0
- package/src/prompts/advisor-design.md +9 -76
- package/src/prompts/advisor-round1.md +9 -68
- package/src/prompts/advisor-round2.md +7 -54
- package/src/prompts/advisor-round3.md +7 -54
- package/src/prompts/coder.md +7 -50
- package/src/prompts/consult-base.md +4 -24
- package/src/prompts/discipline.md +26 -44
- package/src/prompts/eng-coder.md +7 -32
- package/src/prompts/engineering-sub.md +3 -23
- package/src/prompts/engineering.md +53 -306
- package/src/prompts/explore.md +3 -12
- package/src/prompts/main.md +10 -32
- package/src/prompts/methodology-template.md +28 -48
- package/src/prompts/plan.md +2 -9
- package/src/prompts/system.md +16 -35
- package/src/provider/core.mjs +6 -67
- package/src/provider/errors.mjs +76 -0
- package/src/provider/retry.mjs +8 -45
- package/src/session-gc.mjs +214 -0
- package/src/session-guard.mjs +47 -0
- package/src/session-rename.mjs +38 -0
- package/src/session-slots.mjs +181 -58
- package/src/session.mjs +48 -89
- package/src/token-ttl.mjs +273 -0
- package/src/tools/checklist-sync.mjs +181 -0
- package/src/tools/checklist.mjs +52 -39
- package/src/tools/edit-batch.mjs +109 -10
- package/src/tools/edit-diff.mjs +110 -27
- package/src/tools/edit.md +17 -12
- package/src/tools/execute.mjs +31 -4
- package/src/tools/file.mjs +11 -6
- package/src/tools/git.mjs +14 -6
- package/src/tools/glob-dialect.mjs +130 -0
- package/src/tools/glob.md +3 -3
- package/src/tools/grep.md +1 -1
- package/src/tools/index.mjs +5 -6
- package/src/tools/ops.mjs +175 -3
- package/src/tools/patch.mjs +3 -3
- package/src/tools/question.md +3 -0
- package/src/tools/read.md +0 -1
- package/src/tools/shared.mjs +14 -13
- package/src/tools/system.mjs +44 -9
- package/src/tools/wait_for.md +22 -0
- package/src/tui/agent-turn.mjs +17 -228
- package/src/tui/cmd-config.mjs +48 -7
- package/src/tui/cmd-eng.mjs +20 -16
- package/src/tui/cmd-mcp.mjs +8 -2
- package/src/tui/cmd-new.mjs +3 -2
- package/src/tui/cmd-session.mjs +19 -4
- package/src/tui/cmd-think.mjs +10 -10
- package/src/tui/cmd-upgrade.mjs +19 -4
- package/src/tui/config-helpers.mjs +28 -16
- package/src/tui/distill-cmd.mjs +1 -1
- package/src/tui/index.mjs +3 -2
- package/src/tui/interaction.mjs +3 -3
- package/src/tui/mouse.mjs +7 -1
- package/src/tui/pickers.mjs +40 -22
- package/src/tui/render-segments.mjs +27 -10
- package/src/tui/startup.mjs +4 -0
- package/src/tui/subagent-blocks.mjs +95 -263
- package/src/tui/subagent-children.mjs +176 -0
- package/src/tui/subagent-freeze.mjs +172 -0
- package/src/tui/subagent-panel.mjs +61 -23
- package/src/tui/suspension-drive.mjs +351 -0
- package/src/tui/tool-args.mjs +3 -3
- package/src/tui/tool-display.mjs +142 -0
- package/src/tui/tool-events.mjs +37 -173
- package/src/tui/tui-lifecycle.mjs +29 -0
- package/src/tui/update-notice.mjs +4 -0
- package/src/tui/wizard.mjs +12 -6
- package/src/tools/pdf-parse-text.mjs +0 -497
- package/src/tools/pdf-parse-xref.mjs +0 -499
- package/src/tools/pdf.mjs +0 -155
- package/src/tools/read_pdf.md +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
|
+
## [0.12.60] — 2026-09-08
|
|
2
|
+
|
|
3
|
+
> 0.12.59 → 0.12.60(§4.5 连续号——发布时定号)
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **R17 会诊/飞刀完全异步化(AGENT-LOOP.md §25——2026-09-06/07)**:consult_check 退役(digest 自动注入闭环);escalate 入 other 池异步化(async:false 保留);三族 pending 注入/驱动推广;T-R17a..r 全绿(CLI L2 1626/1626 + VS 1301/1301)
|
|
8
|
+
- **记账路径 join→resolve 双前缀修复(R-bug——2026-09-07——AGENT-LOOP.md §24 尾修复注)**:record-results.mjs ×2 + agent.mjs ×1 `join(agent.cwd, p)` → `resolve(agent.cwd, p)`(绝对路径 p 双前缀——touchedFiles/记账错路径——修复前先验失败实拍——guards.test +12 断言)
|
|
9
|
+
- **R18 长测试输出先落盘纪律条款(AGENT-LOOP.md §26——2026-09-06 快车道)**:`src/prompts/system.md` Rules 工具纪律区插逐字条款("长输出命令先落盘"——全量/长测试(≥60s)先重定向日志再查——汇总读尾部/失败 grep——禁过滤管道直跑长命令——镜像锚逐字稿照抄 AGENT-LOOP §26.2——各端独立断言)+ 日志位置执行细则(OS 临时/~/.thincoder 类非工作区——查毕删除——防 git 工作区 untracked 污染——条款逐字不改)。锚测试 T-R18.1/T-R18.2(fail-when-unchanged)。双端各自落端(VS Code 侧并行照抄)。
|
|
10
|
+
- **R19 跨会话历史检索 + 检索族消歧(SESSION.md §13——2026-09-06)**:`read_history` 加 `path` 参数(可选——缺省 = 本会话零行为变化)——path = 会话文件路径 → 跨会话单槽深查(同 filter 面 role/keyword/tool/since/until/limit/direction 应用 + limit clamp);path = "cwd:xxx" → 发现面(列该 cwd 全部槽——每槽摘要行含槽号 + 完整文件路径 + title/消息数/updatedAt——不做死槽过滤——时间序);行扫护栏 READ_HISTORY_SCAN_MAX = 200,000 行——超限返回定稿文案 `{"error":"session too large — refine keyword or since/until"}`(不再读全文);read_history 描述尾段插族表总纲(D-R19b 逐字——checkpoint cat/versions 经核验保留——git 动作面含 versions);recent_changes/memory/doc_search/code_search 描述补互指句。测试 T-R19.1..7(含 3b/3c/3d 错误/边界子行 + 描述锚)。压缩刀锋 fixture 随 schema 增重校准(session-compaction T3b 15500 → 17000——沿革注更新)。
|
|
11
|
+
|
|
12
|
+
- **legacy v1 扩展删除集(SESSION.md §12.7——2026-09-06)**:`session gc` 冷 cwd 整前缀删除集补裸 `{hash}.json`(v1 死数据——§12.6 裁决代码同步);三处同源单集合(dry-run 报告/confirm 警告/删除共用);自动残留 GC 面零触碰。测试 T-V1a..d(含 v1 报告/删除/--all/活跃拒绝)。父侧 L2 1543/1543 全绿。
|
|
13
|
+
|
|
14
|
+
- **测试分层 Phase 3:存量清理 + 红线收窄(TESTING.md §1 D-T4/D-T5——2026-09-06——用户逐项批准删除清单)**:删除一次性迁移零残留锁 11 组 + 防回潮元测试 4 案 + 同锚多断 3 组(1492→1486,差额 -6 全对账);"断言数不减"红线收窄为拆分轮专用(system.md Module Split Policy + 双 METHODOLOGY.md 拆后两验注——清理轮改删除清单制)。测试 T-T5 收窄锚断言。**五杠杆批全链收口——总目标 AC-T4 ✓:链测试墙钟 ~4.5-5.5min → ~1.6min(降 ~70%)**。
|
|
15
|
+
|
|
16
|
+
- **测试分层 Phase 2:eng-coder 首次实现降 L0+(TESTING.md §1 D-T3——2026-09-06——supersede §18.7 D-TS1 首次实现全量 L1 口径)**:`engineering-sub.md` 验证粒度段修订——首次实现 = L0+(语法检查 + §18.12 定向相关测试,秒级),L1 收窄为显式升级档(兜底语义保留),修正轮 L0 与父侧 L2 不变;交付报告义务锚句("not full-suite verified — the parent-side L2 run is the only full-suite point."——双端逐字镜像)。AGENT-LOOP §18.7 原位 supersede 注。测试 T-T4 锚断言(fail-when-unchanged + 旧句零残留)。实测快层 18.5s 全绿 1492 用例。
|
|
17
|
+
|
|
18
|
+
- **测试分层 Phase 1:slow 门防漏拦截 + 快层归册(TESTING.md §1——2026-09-06——用户"测试已成包袱"五杠杆批之零冲突先行段)**:`test/slow-gate.mjs`(reporter 收集叶子用例耗时——未标 slow 超 800ms 拦截阈值即报错红,防快层腐化——env `THINCODER_SLOW_GATE_MS` 可覆盖)+ `test/run-fast.mjs`(npm test 新入口——spec 直通 + gate 判定非零退出 + `--test-concurrency=6`);60 条重 IO 用例归册(只加 slow() 标记,零删除零本体改动);机制自验 `test/slow-gate.test.mjs` 红/绿双证。**实测:快层 38.0s → 19.2-19.7s(≤20s 达标),test:full 1491/1491 全绿**。
|
|
19
|
+
|
|
20
|
+
- **拆分判据修辞防博弈加固(METHODOLOGY.md 2026-09-06 变更条——快车道——用户实测模型引用"才 500 多行、没 2300 行大"拒绝拆分)**:文件档升同级判定表(>500 = 必须拆——硬限、无例外、无相对比较通道——原"兜底红线"定性退役);函数档改定位 = 早期预警线、文件档 = 不可协商底线;新增"相对大小永远不是豁免"封堵句(中英镜像)+ 动机节封口句 + 反例档案新行(相对大小打折硬限实测反例);**AGENTS.md / .thincoder/advisor.md 测试文件+生成代码豁免说辞全删(用户裁定"不允许豁免"——工作区根两文件同删)**——存量 26 个 >500 测试文件登记 TODO 拆分轮。测试 T-S1/S2/S3/S5 锚断言(prompts.test.mjs——含旧修辞零残留负向断言)。
|
|
21
|
+
|
|
22
|
+
- **question 工具使用抑制(AGENT-LOOP.md §22——2026-09-06 快车道——用户实测过度提问/大段文字/一条多问)**:工具描述 Notes 补三条逐字锚(一次一问不塞子问题 / 问题文本要短、背景走正文回复 / 例行确认门走普通文本回复、question 仅留真实决策场景);提示词三文件锚(engineering.md Questioning Style 两条 + system.md 确认门形式句 + discipline.md 工具表反模式扩展);questionTool execute 机械上限(git.mjs 寄生段——question >100 字符 / options >4 条返回错误串、不弹卡不调 onQuestion——用户裁定值——guard 仅 `Array.isArray(options) && length > 4` 触发、非数组透传)。测试 T-Q1/T-Q3/T-Q4/T-Q5/T-Q6/T-Q7(git.test + prompts.test——锚 fail-when-unchanged + 超限拒绝/边界透传)。
|
|
23
|
+
|
|
24
|
+
- **async spawn 收尾引导(AGENT-LOOP.md §19.7——2026-09-06)**:subagent 工具描述 Async spawn 段尾部补收尾引导锚句("After an async spawn the turn winds down normally — nothing expects you to wait for it…"——逐字定稿于设计文档 §19.7 D-A2)——模型 async spawn 后回合自然收尾、unchecked 结果自动到达(下轮注入/挂起态 digest)、无需自发 status/check 轮询等待;锚句内容断言 fail-when-unchanged(设计锚 + 两端各自断言——防描述再漂移——D-A4)。测试 T-D-A2。
|
|
25
|
+
- **subagent check 动作删除 + 锚句收紧(AGENT-LOOP.md §19.8——2026-09-06 用户裁定"check 是冗余 API")**:工具面六动作 → 五动作(spawn/status/escalate/cancel/panel)——删 `action:"check"` + `n` 参数 + `executeCheckAction`/`MAX_ASYNC_CHECKS`/`_asyncCheckLastN` 全链路;async 子代理结果仅自动通道送达(回合尾 collect/挂起 digest——§17.5 机制零改动——consumed 终态墓碑保留——dependsOn 语义不变);Async spawn 段描述替换为 D-CH2 锚句逐字("…do not poll or wait for the result…use a synchronous spawn instead—pass `async:false`…"——fail-when-unchanged 断言);main.md/discipline.md/工具描述 check 引导句改自动送达口径;停滞检测(P-SL2)check 守卫路径删除——F-SL2 语义面迁至 status 视图(可显示停滞标记不变)。测试:check 域用例删 8 条(逐条见交付报告)+ 2 条在位改自动通道形态(T-SD14/T-H3)+ T-M16 改 status 形态 + D-A2 断言在位改 D-CH2。
|
|
26
|
+
- **工程模式 token 防伪层删除(ENGINEERING-MODE.md 2026-09-06 段——用户裁定"过度工程给我删了")**:advisor.mjs 删 DEFAULT_TOKEN_SECRET / USING_DEFAULT_SECRET / TOKEN_SECRET / warnIfDefaultSecret + 启动警告与 HMAC 签名/验签——token 回归**无签名流程凭证**(格式 uuid:expiresAt——TTL 检查 fail-closed + designId 槽位精确匹配不变);存量 3 段 token 格式判错 fail-closed 拒绝(不迁移——重评一次);NFR3/§2.3/§2.7/§2.6 文档同步。
|
|
27
|
+
- **会话"当前槽位"按端分离(R4——2026-09-05——SESSION.md §10)**:CLI 与 VS Code 各自 end marker(`{manifest}.cli|.vscode`,本端单写者)记录"本端最后使用的槽位"——恢复决策 resumeSlot(本端记录 → 无记录一次性继承 active 死主槽 → 全新分配)替代共享 manifest.active 作为恢复依据——双端同开时退出 CLI 重进不再进错会话/空白新槽;启动即钉 _slot 闭合"load→首保存"迁移窗口;/session 列表高亮按本端记录(含被删守卫)。双端同批镜像(L2:CLI 1485/1437+48skip/0 + VS Code 1196/1196 全绿)。
|
|
28
|
+
- **git 工具 add/rm/commit 多路径(2026-09-05 发版后——git add 单路径被迫 N 次调用)**:`path` 空格分隔多路径(`git add a b c`——ref 多值先例同法——split(/\s+/));path 描述尾追加注(保既有原子串断言);双端同改(CLI git.test + VS Code git.test 镜像用例——add/rm/commit 三动作多路径覆盖)。
|
|
29
|
+
- **release:check 一键发版门禁(scripts/release-check.mjs——2026-09-05 0.12.59 发版教训)**:lint + test:full 合并一键;全量输出捕获不刷屏(只打摘要);失败自动提取 failing tests 详情段(此前为看错误详情跑 3 次全量);RELEASE.md §1 发布前检查合并 + 修复迭代局部重跑纪律 + prepublishOnly 双保险注。
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- fix: 子代理块 done 后定格修复批(2026-09-07 id:14)——CLI trimSubTree done 豁免 + route* done 守卫(迟到 chunk 丢弃)
|
|
34
|
+
- fix: prompts.test 折行断言折叠化收口(2026-09-07 id:3)——双侧 \s+ 归一匹配——负守卫保持负向——锚整块/落位序断言加固
|
|
35
|
+
|
|
1
36
|
## [0.12.59] — 2026-09-05
|
|
2
37
|
|
|
3
|
-
> 0.12.58 → 0.12.59(§
|
|
38
|
+
> 0.12.58 → 0.12.59(§4.5 连续号——发布时定号)
|
|
4
39
|
|
|
5
40
|
### Added
|
|
6
41
|
|
|
@@ -16,7 +51,7 @@
|
|
|
16
51
|
- **普通模式两段式(AGENT-LOOP.md §21 F-N1.5——2026-09-05 用户"把 coder 用起来……解决自查问题")**:规模实现批次默认委托 coder 子代理(async——设计书为 task book)——执行/检查心智分离(隔离上下文破自查盲区);小改动/探索留内联;复核走 F-N1.4(偏差退回 coder ≤2 轮)。测试 T-N1.9 双端。
|
|
17
52
|
- **委托操作标准(AGENT-LOOP.md §21 扩展注 4——F-N1.6——2026-09-05 用户"spawn coder 干活现在并没有明确的标准是吗")**:规模判据可操作化(≥2 文件/单文件 >30 行逻辑/模块边界/双端镜像 → 委托;≤30 行/文档同步/探索 → 内联);任务书七字段标准(目标/已知事实/设计+禁止/约束/硬验收/报告格式/调度元数据——缺字段=委托缺陷);委托模式判据(async 默认/sync 仅依赖链/并行仅文件域互斥);通用验收基线。测试 T-N1.10 双端。
|
|
18
53
|
- **/config 交互修复(2026-09-05)**:改配置项保存后回主菜单(不再退到输入框)——每轮刷新 ac/tc 配置引用(reloadConfig 换对象后显示新值);view 浏览态同回菜单。
|
|
19
|
-
- **版本号连续性规则(RELEASE.md §
|
|
54
|
+
- **版本号连续性规则(RELEASE.md §4.2/§4.3——2026-09-05 用户裁定"不要跳号")**:号在发布时定、开发期不预占(CHANGELOG 挂 [Unreleased]);待发号 = registry 最高 + 1;缺口不补。
|
|
20
55
|
|
|
21
56
|
### Fixed
|
|
22
57
|
|
|
@@ -80,7 +115,7 @@
|
|
|
80
115
|
|
|
81
116
|
### Added
|
|
82
117
|
|
|
83
|
-
- **`/mcp` edit/add 统一字段 picker 表单(v2)+ agent 代配闭环**(docs/design/MCP.md §5,CLI-only):① **edit = 字段选择表单**——picker 列可编辑字段行(`HTTP URL https://…` / `Token
|
|
118
|
+
- **`/mcp` edit/add 统一字段 picker 表单(v2)+ agent 代配闭环**(docs/design/MCP.md §5,CLI-only):① **edit = 字段选择表单**——picker 列可编辑字段行(`HTTP URL https://…` / `Token ••••…` 打码 / `Headers 2 items`;stdio `Command/Args/Env`;name 不可改无行)+ 末行 `✓ Save & test`;选中字段只输入该字段新值(提示 `(current: …)`——空=不变、`-`=删可选字段、`k=`=删 header/env 项、required 字段拒绝 `-`)→ 回 picker 循环连改多字段(中间 Esc 回 picker 不丢已改值);**废除逐字段预填重问**(改 token 不再被迫路过 URL/headers);② **add 复用同一表单**——空 entry 起、必填字段 `(required)` 标注、Save 校验必填非空(未满足提示并停留表单不落盘)、headers/env 不选即跳过、add 的 name 可编辑(重复名检查);③ **保存前预览 + 探活 + 字段级重试合一**——`showPreview`(token 遮蔽)→ `probeMcpServer` 零副作用探活(`✓ N tools, Xms` / `✗ 错误`)→ `Save? (Y/n)`;探活失败 → `Save anyway? (y/N)` 显式 y,否则**回同一字段表单**只重输失败字段复 probe(**独立 retry 路径废除**,不重启流程;save-anyway 显式 y 保留);④ **表单文件拆分**——新增 `src/tui/cmd-mcp-form.mjs`(fieldPicker 机制独立文件;`cmd-mcp.mjs` 499→382 行,脱离 500 硬限压线);⑤ **列表即菜单**——主菜单 = server 行(●/○ 连接态 + tool 数)+ `+ Add server` + `↻ Refresh` + 顶部 agent 代配提示行;选中行 → per-server 子菜单(Edit/Test/Reconnect/Remove),"先选操作再选 server"双弹层与 View list 废除;⑥ **磁盘重读**——`config.mjs` 新增 `reloadMcpFromDisk()`(菜单打开边界 + Refresh):磁盘→内存仅替换 mcp 段;畸形 config.json 回退内存态 + `⚠ disk config unreadable` 提示行;disk 删除/变更的已连接 server 连接不断 + 行尾 `⚠ disk changed` 对账标记(persistRaw 落盘后重读幂等防环);⑦ AI 生成降 transport picker 末位(生成的 entry 同走预览+探活确认环,失败回表单补齐/修正);`/mcp edit|test|remove|connect <name>` 直达参数路径零改动
|
|
84
119
|
- **MCP Streamable POST 误判修复 + `/mcp edit`/`/mcp test` + token 一等字段**(docs/design/MCP.md §4,两端落地):① `httpTransport` 增 postOnly 标记——GET SSE 405 降级后的纯 POST 模式 `isAlive()` 不再因 `eventSource == null` 误判死(glm-websearch "reconnect failed after 4 attempts" 根因:降级后 isAlive 恒 false → ensureAlive 触发无意义重连循环;legacy SSE 流断仍正常 fireDead 重连不回归);② `/mcp edit [name]`:逐字段预填重问(空输入保留 / `-` 删除可选字段 / `k=` 删除单个 header 项),persistRaw 原位替换保数组序,保存后自动重连(config 指纹含 token,变更自动关旧连接);③ `/mcp test [name]`:probeMcpServer 一次性探活(initialize + tools/list 计时 → `OK — N tools, Xms` / 错误透传),零副作用(不进 session 表、不动 agent.tools、探完即关);④ token 一等字段:config 增 `token` 字段,connect 链自动合成 `Authorization: Bearer <token>`(显式 headers 优先,不写回 config);⑤ parseHeaders 改逗号分隔(`Authorization=Bearer abc, X-Foo=bar`——修复空格截断把 Bearer token 截成 "Bearer" 的缺陷);⑥ VS Code 同构:http transport 同款修复 + probeMcpServer 镜像 + 面板 [Edit]/[Test] 按钮(同一表单编辑预填,token 字段 + 逗号分隔 headers 提示)+ **面板 [Reconnect] 死按钮修复**(webview 发的 `reconnectMcp` 消息在路由拆分时丢失 case,按钮此前无效)
|
|
85
120
|
- **memory_delete 工具**(跨端):三层记忆条目删除——personal 行级删(embedding/FTS 随行)、project/team 文件级删;scope 与 id 前缀匹配校验,非法 scope 明确报错
|
|
86
121
|
|
package/README.md
CHANGED
|
@@ -15,13 +15,13 @@ Design philosophy (the entire meaning of the name): if the Node standard library
|
|
|
15
15
|
- **Fix-verify loop**: file changes without `verify` get pushed back — syntax check + tests must pass before the agent can claim completion (auto-repair up to 3 rounds)
|
|
16
16
|
- **Checkpoint system**: auto-snapshot before every user task, `list`/`create`/`rewind` tools for the model, single-file restore — rewinding itself is reversible (pre-rewind state auto-saved)
|
|
17
17
|
- **Codebase understanding** ⭐0.5.0: `repo_outline` (dependency outline, auto-injected at startup), `code_search` (source FTS5 + vectors + JSDoc extraction), `doc_search` (docs chunked by ## headings) — background indexing, auto-incremental updates on file writes, three tools guided by "structure → intent → details"
|
|
18
|
-
- **Model adaptation** ⭐: top-tier only, latest only. Built-in flagship models from
|
|
18
|
+
- **Model adaptation** ⭐: top-tier only, latest only. Built-in flagship models from twenty providers — DeepSeek / Kimi / Kimi For Coding / GLM / GLM Coding Plan (智谱 Coding) / Qwen / Qwen Token Plan / MiMo (小米) / MiMo Token Plan (小米套餐) / MiniMax / OpenAI / Claude / Gemini / Grok / Mistral / Volcengine Ark (豆包) / Hunyuan (腾讯混元) / SiliconFlow (硅基流动) / OpenRouter / Groq. No legacy model compatibility. Auto-matched context windows, truncation-resume protocols (prefix/partial), thinking-mode APIs (thinking.type / reasoning_effort), reasoning_content echo strategies (reasoningEcho), output limits, temperature range clamping — all deeply adapted.
|
|
19
19
|
- **Toolset**: `read` / `write` / `edit` / `bash` / `glob` (supports `**`) / `grep` / `websearch` / `ls` / `fetch` + `read_image` (image/video paste) + three retrieval tools + MCP — all zero-dependency, file tools confined to the working directory
|
|
20
20
|
- **Memory system**: three layers (personal/project/team), FTS5 + vector RRF hybrid retrieval, git-friendly markdown format
|
|
21
21
|
- **Two-phase tool scheduling**: permission prompts serialized, read-only tools parallelized, side-effect tools serialized
|
|
22
22
|
- **Session persistence** ⭐0.5.0: unlimited archive slots, `/session` to switch anytime, tool results visible after restore. Process-level isolation — multiple instances in the same directory each get their own session slot
|
|
23
23
|
- **Concurrent subagents**: three roles — `explore`/`plan`/`coder` — dispatched in parallel, streaming output visible, reports land in the conversation; per-subagent model override (`subagent` tool `model` arg or `agent.subagentModel` config — e.g. discuss with `glm-5.2`, let `deepseek-v4-flash` implement)
|
|
24
|
-
- **Multi-model consultation 会诊 + 飞刀 (escalate)** ⭐0.12.30: `consult_start`/`
|
|
24
|
+
- **Multi-model consultation 会诊 + 飞刀 (escalate)** ⭐0.12.30: `consult_start`/`consult_stop` run several configured models in parallel as independent read-only consultants (each with its own TUI activity card, `main_history` access to the failure trail); when every model settles, the full verdict digest is delivered automatically (R17 — consult_check retired). `escalate` flies in a stronger model for a single expert implementation run with full write access (default-async since R17 — the post-op report arrives automatically with its mutations merged). Candidate pool = `agent.consultModels` ([{ provider, model, effort? }], up to 5); budgets via `agent.consultTurns` / `agent.consultTimeoutMs`
|
|
25
25
|
- **Plan Mode**: read-only exploration + design, implement after user approval
|
|
26
26
|
- **AUTO mode**: `/auto` full authorization, no confirmations on long tasks
|
|
27
27
|
- **Task tracking**: `task` tool breaks down multi-step work, status bar ✓n/m live progress, auto-filters completed items
|
package/bin/thincoder.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* thincoder memory <sub> Memory management: list / search / put / remove
|
|
8
8
|
* thincoder upgrade Update to the latest version from npm
|
|
9
9
|
* thincoder completion <sh> Shell completion: bash / zsh / fish
|
|
10
|
+
* thincoder session gc Session dir GC: --dry-run report / --confirm delete cold projects (SESSION.md §12)
|
|
10
11
|
* thincoder acp Agent Client Protocol server (stdio, for Zed/JetBrains/Paseo)
|
|
11
12
|
* thincoder -v Print version
|
|
12
13
|
* thincoder --help Print help
|
|
@@ -23,19 +24,56 @@ import { memoryCommand } from "../src/cli/memory-command.mjs"
|
|
|
23
24
|
import { setupWizard } from "../src/cli/setup-wizard.mjs"
|
|
24
25
|
import { summarize, askPermission } from "../src/cli/permission.mjs"
|
|
25
26
|
import { distillCommand } from "../src/cli/distill-command.mjs"
|
|
27
|
+
import { prepareCrashReporting, recentCrashHint, writeCrashRecord } from "../src/crash-reports.mjs"
|
|
28
|
+
import { setTuiActive, restoreTerminalAfterCrash } from "../src/tui/tui-lifecycle.mjs"
|
|
26
29
|
|
|
27
30
|
const [command, ...args] = process.argv.slice(2)
|
|
28
31
|
const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version
|
|
29
32
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// R25(F-R25b):crash-reports 预建 + process.report 启用——入口最前(一切重活前——缩编程
|
|
34
|
+
// 期窗口)——V8 OOM/原生 fatal 自动写 report.*.json(实现批实测:目录缺失时 Node 静默不写
|
|
35
|
+
// ——预建为必要动作)。失败不阻断启动(尽力面)。
|
|
36
|
+
prepareCrashReporting()
|
|
37
|
+
|
|
38
|
+
// R25(F-R25a)异常钩子升级:原"只 console.error 一行(TUI 全屏下不可见)"→ ① 落盘
|
|
39
|
+
// crash-{ts}-{pid}.json ② TUI 活动态终端恢复 ③ console.error(恢复后打印才可见)
|
|
40
|
+
// ④ exit 非 0。执行序列定死(评审 #5 + 复审 #2):一次性 guard(防再入递归)→ 同步写 →
|
|
41
|
+
// 终端恢复 → console.error → exit 非 0——各步独立 try/catch(写失败/恢复失败不阻断后续步)。
|
|
42
|
+
let crashHandled = false
|
|
43
|
+
function handleFatal(type, error) {
|
|
44
|
+
if (crashHandled) {
|
|
45
|
+
// 再入(本序列内又抛异常)→ 直接退出,不再递归
|
|
46
|
+
process.exit(1)
|
|
47
|
+
}
|
|
48
|
+
crashHandled = true
|
|
49
|
+
try {
|
|
50
|
+
// ① 同步写诊断记录(设计字段集:时间/类型/消息+堆栈/uptime/argv/cwd/内存/node+版本)
|
|
51
|
+
writeCrashRecord({ type, error })
|
|
52
|
+
} catch { /* 写失败不阻断后续步 */ }
|
|
53
|
+
try {
|
|
54
|
+
// ② TUI 终端恢复:仅 TUI 活动态执行(writeCleanupSequence 同源——chat 模式 stdout
|
|
55
|
+
// 管道不得收 ANSI——误判即污染输出)
|
|
56
|
+
restoreTerminalAfterCrash()
|
|
57
|
+
} catch { /* 恢复失败不阻断后续步 */ }
|
|
58
|
+
try {
|
|
59
|
+
// ③ 原 console.error 行保留(非 TUI 模式可见——恢复后打印才可见)
|
|
60
|
+
console.error(`[error] ${error?.message ?? error}`)
|
|
61
|
+
} catch { /* 打印失败不阻断 exit */ }
|
|
62
|
+
// ④ exit 非 0 恒达(exitSoon——Windows/Node 24 上 fetch 后立即 exit 触发 libuv 断言先例)
|
|
37
63
|
exitSoon(1)
|
|
38
|
-
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Top-level safety net: print one-line error and exit cleanly, no stack traces to the user
|
|
67
|
+
process.on("uncaughtException", (error) => handleFatal("uncaughtException", error))
|
|
68
|
+
process.on("unhandledRejection", (error) => handleFatal("unhandledRejection", error))
|
|
69
|
+
|
|
70
|
+
// R25 测试门(T-R25a.1/a.2——子进程 env 注入——生产零路径):THINCODER_TEST_CRASH=1 抛
|
|
71
|
+
// 未捕获异常走完整崩溃序列;THINCODER_TEST_TUI_ACTIVE=1 模拟 TUI 活动态(同一 setter——
|
|
72
|
+
// 测试缝同源);THINCODER_TEST_CLEANUP_OUT 指向文件时恢复序列写入该文件(tui-lifecycle 读)。
|
|
73
|
+
if (process.env.THINCODER_TEST_CRASH === "1") {
|
|
74
|
+
if (process.env.THINCODER_TEST_TUI_ACTIVE === "1") setTuiActive(true)
|
|
75
|
+
throw new Error("R25 test crash (THINCODER_TEST_CRASH)")
|
|
76
|
+
}
|
|
39
77
|
|
|
40
78
|
const USAGE = `thincoder - thin coding agent
|
|
41
79
|
|
|
@@ -49,9 +87,11 @@ Usage:
|
|
|
49
87
|
thincoder memory remove <id> Remove an entry
|
|
50
88
|
thincoder sync Sync team memory repo (pull --rebase + reindex)
|
|
51
89
|
thincoder reindex Rebuild the local index from markdown sources
|
|
52
|
-
thincoder distill <file> [--yes] [--
|
|
90
|
+
thincoder distill <file> [--yes] [--layer=<s>]
|
|
53
91
|
Extract knowledge candidates from a session
|
|
54
92
|
transcript file; confirm each before saving
|
|
93
|
+
thincoder session gc --dry-run | --confirm <hash|--all>
|
|
94
|
+
Session dir GC: report/delete cold project data (cold = manifest idle >90d, no live slots)
|
|
55
95
|
thincoder upgrade Update to the latest version from npm
|
|
56
96
|
thincoder completion <sh> Generate shell completion script (bash / zsh / fish)
|
|
57
97
|
thincoder -v, --version Print version
|
|
@@ -86,6 +126,10 @@ switch (command) {
|
|
|
86
126
|
break
|
|
87
127
|
}
|
|
88
128
|
|
|
129
|
+
// R25(F-R25c):非交互/chat 模式——上次异常终止提示写 stderr 一行(无匹配不提示)
|
|
130
|
+
const crashNotice = recentCrashHint()
|
|
131
|
+
if (crashNotice) console.error(crashNotice)
|
|
132
|
+
|
|
89
133
|
const agent = await assembleAgent()
|
|
90
134
|
// SESSION.md §8 D-S4(F4):headless 无 TUI —— 可读错误 + 退出码 1,不弹 UI、不崩溃
|
|
91
135
|
if (agent._providerInvalid) {
|
|
@@ -239,10 +283,12 @@ switch (command) {
|
|
|
239
283
|
if (agent._providerInvalid) agent.provider = null
|
|
240
284
|
const config = loadConfig()
|
|
241
285
|
// 恢复上次的会话(同一项目目录);provider 按保存的名字切回(用户上次可能换过模型)
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
286
|
+
// 2026-09-05 §10(R4):恢复决策按本端记录 resumeSlot(D-2 ①②③)——manifest active
|
|
287
|
+
// 只作"无记录端"的一次性继承源,不再作本端恢复第一依据(D-6)。
|
|
288
|
+
const { resumeSlot, applySession } = await import("../src/session.mjs")
|
|
289
|
+
const { slot, data } = resumeSlot(process.cwd())
|
|
290
|
+
if (data) {
|
|
291
|
+
const switched = applySession(agent, data)
|
|
246
292
|
if (switched && agent.config?.agent?.compactThresholdAuto) {
|
|
247
293
|
// 压缩阈值跟模型走(与 TUI 切换 provider 时的处理一致);传 provider 对象——
|
|
248
294
|
// providers[].context 覆盖生效(PROVIDER.md §15 T-C2)
|
|
@@ -250,6 +296,10 @@ switch (command) {
|
|
|
250
296
|
agent.config.agent.compactThreshold = resolveCompactThreshold(null, agent.provider).value
|
|
251
297
|
}
|
|
252
298
|
}
|
|
299
|
+
// D-3 钉槽:applySession 清 _slot 后立即钉回恢复槽——首保存必落恢复槽(消除
|
|
300
|
+
// "load → 首回合保存"窗口内并发方翻 active 导致的静默迁移);/new 经 resetSessionState
|
|
301
|
+
// 清 _slot(newSession 已认领 + 写记录,语义保留)
|
|
302
|
+
agent._slot = slot
|
|
253
303
|
// D-S3 优先级补全:applySession 可能已用会话中的有效 provider 修复(config 无效 + 会话有效)——
|
|
254
304
|
// 修复后复验清除标记,仅当两者都无效才弹重选(validateProvider 幂等)
|
|
255
305
|
if (agent._providerInvalid) validateProvider(agent)
|
|
@@ -268,7 +318,9 @@ switch (command) {
|
|
|
268
318
|
projectDir: config.memory.projectDir ? join(process.cwd(), config.memory.projectDir) : null,
|
|
269
319
|
team: teamConfig(config),
|
|
270
320
|
author: gitAuthor(),
|
|
271
|
-
restored,
|
|
321
|
+
restored: data,
|
|
322
|
+
// R25(F-R25c):TUI 启动显示一行"上次运行异常终止"提示(showStartup 渲染——无匹配不传)
|
|
323
|
+
crashNotice: recentCrashHint() ?? undefined,
|
|
272
324
|
})
|
|
273
325
|
} catch (error) {
|
|
274
326
|
console.error(`[error] ${error.message}`)
|
|
@@ -298,10 +350,10 @@ switch (command) {
|
|
|
298
350
|
list) COMPREPLY=( \\$(compgen -W "--type=rule --type=knowledge --type=decision --type=pattern" -- "\\$cur") ) ;;
|
|
299
351
|
put) COMPREPLY=( \\$(compgen -W "--type= --title= --content= --tags=" -- "\\$cur") ) ;;
|
|
300
352
|
esac ;;
|
|
301
|
-
distill) COMPREPLY=( \\$(compgen -W "--yes --
|
|
353
|
+
distill) COMPREPLY=( \\$(compgen -W "--yes --layer=" -- "\\$cur") ) ;;
|
|
302
354
|
completion) COMPREPLY=( \\$(compgen -W "bash zsh fish" -- "\\$cur") ) ;;
|
|
303
355
|
*)
|
|
304
|
-
COMPREPLY=( \\$(compgen -W "chat acp memory sync reindex distill upgrade completion -v --version -h --help" -- "\\$cur") ) ;;
|
|
356
|
+
COMPREPLY=( \\$(compgen -W "chat acp memory sync reindex distill upgrade completion session -v --version -h --help" -- "\\$cur") ) ;;
|
|
305
357
|
esac
|
|
306
358
|
}
|
|
307
359
|
complete -F _thincoder thincoder
|
|
@@ -326,7 +378,8 @@ _thincoder() {
|
|
|
326
378
|
'reindex[Rebuild local index from markdown]' \\
|
|
327
379
|
'distill[Extract knowledge from session transcript]' \\
|
|
328
380
|
'upgrade[Update to latest version from npm]' \\
|
|
329
|
-
'completion[Generate shell completion script]'
|
|
381
|
+
'completion[Generate shell completion script]' \\
|
|
382
|
+
'session[Session dir GC: session gc --dry-run|--confirm]'
|
|
330
383
|
;;
|
|
331
384
|
args)
|
|
332
385
|
case "\\$words[1]" in
|
|
@@ -336,7 +389,7 @@ _thincoder() {
|
|
|
336
389
|
list) _arguments '--type=[Filter by type]' ;;
|
|
337
390
|
put) _arguments '--type=[Entry type]' '--title=[Title]' '--content=[Content]' '--tags=[Space-separated tags]' ;;
|
|
338
391
|
esac ;;
|
|
339
|
-
distill) _arguments '--yes[Skip confirmation]' '--
|
|
392
|
+
distill) _arguments '--yes[Skip confirmation]' '--layer=[Layer filter]' ;;
|
|
340
393
|
completion) _values 'shell' 'bash' 'zsh' 'fish' ;;
|
|
341
394
|
esac ;;
|
|
342
395
|
esac
|
|
@@ -355,6 +408,7 @@ complete -c thincoder -a reindex -d 'Rebuild local index from markdown'
|
|
|
355
408
|
complete -c thincoder -a distill -d 'Extract knowledge from session'
|
|
356
409
|
complete -c thincoder -a upgrade -d 'Update to latest version'
|
|
357
410
|
complete -c thincoder -a completion -d 'Shell completion'
|
|
411
|
+
complete -c thincoder -a session -d 'Session dir GC (session gc --dry-run|--confirm)'
|
|
358
412
|
complete -c thincoder -a acp -d 'Agent Client Protocol server for IDEs'
|
|
359
413
|
|
|
360
414
|
# Flags
|
|
@@ -381,7 +435,7 @@ complete -c thincoder -n '__fish_seen_subcommand_from memory; and __fish_seen_su
|
|
|
381
435
|
|
|
382
436
|
# distill flags
|
|
383
437
|
complete -c thincoder -n '__fish_seen_subcommand_from distill' -l yes -d 'Skip confirmation'
|
|
384
|
-
complete -c thincoder -n '__fish_seen_subcommand_from distill' -l
|
|
438
|
+
complete -c thincoder -n '__fish_seen_subcommand_from distill' -l layer -d 'Layer filter'
|
|
385
439
|
|
|
386
440
|
# completion shells
|
|
387
441
|
complete -c thincoder -n '__fish_seen_subcommand_from completion' -a bash -d 'Bash completions'
|
|
@@ -419,6 +473,13 @@ complete -c thincoder -n '__fish_seen_subcommand_from completion' -a fish -d 'Fi
|
|
|
419
473
|
break
|
|
420
474
|
}
|
|
421
475
|
|
|
476
|
+
case "session": {
|
|
477
|
+
// SESSION.md §12:会话目录 GC 手动面(F2 冷 cwd 报告/删除——VS Code 端无 shell 通道,仅 CLI)
|
|
478
|
+
const { runSessionGc } = await import("../src/session-gc.mjs")
|
|
479
|
+
process.exitCode = runSessionGc(args)
|
|
480
|
+
break
|
|
481
|
+
}
|
|
482
|
+
|
|
422
483
|
case "--help":
|
|
423
484
|
case "-h": {
|
|
424
485
|
process.stdout.write(USAGE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thincoder",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.60",
|
|
4
4
|
"description": "Thin coding agent - zero dependencies, no build step, Node.js native. Sharp code, zero bloat.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
"url": "git+https://github.com/xinbo-tech/thincoder.git"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"test": "node
|
|
35
|
-
"prepublishOnly": "npm run
|
|
34
|
+
"test": "node test/run-fast.mjs",
|
|
35
|
+
"prepublishOnly": "npm run release:check",
|
|
36
36
|
"lint": "node scripts/check-syntax.mjs",
|
|
37
|
+
"release:check": "node scripts/release-check.mjs",
|
|
37
38
|
"test:full": "node test/run-full.mjs"
|
|
38
39
|
},
|
|
39
40
|
"author": "liwei <liwei@51marine.com> (上海新舶)",
|
package/src/acp/bridge.mjs
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* `{ stopReason: "end_turn" }` (kimi session.ts parity).
|
|
21
21
|
*/
|
|
22
22
|
import { detectDanger, normalizeEOL, joinWithEol } from "../tools/shared.mjs"
|
|
23
|
-
import { computeEditEntry, validateEditEntry, assertEditArgsExclusive } from "../tools/edit-diff.mjs"
|
|
23
|
+
import { computeEditEntry, validateEditEntry, assertEditArgsExclusive, hasLineParams } from "../tools/edit-diff.mjs"
|
|
24
24
|
|
|
25
25
|
/** ACP ToolKind inference (schema v1 enum) — best-effort, clients render by kind. */
|
|
26
26
|
function inferToolKind(name) {
|
|
@@ -92,7 +92,7 @@ export function buildAcpCallbacks({ sessionId, notify, request, log = () => {} }
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// §15.1(TOOLS.md)D15.7 委派:edit 判定/应用单一权威 = 本地 computeEditEntry
|
|
95
|
-
// (edit-diff.mjs——校验→判定序→应用:行级 LCS
|
|
95
|
+
// (edit-diff.mjs——校验→判定序→应用:行级 LCS、零重叠→替换即删、replace_all 字面替换全部)。
|
|
96
96
|
// 桥只留「读 IDE 缓冲 → computeEditEntry → 写回 IDE 缓冲」——错误文本经抛错原样透传
|
|
97
97
|
// ——与本地通道逐字一致(NF15.6b / AC15.10:not found / occurrences / 空 old / 空 new)。
|
|
98
98
|
const EDIT_ABORT_PREFIX = "edit aborted (atomic — no files written): "
|
|
@@ -130,7 +130,7 @@ export function buildAcpCallbacks({ sessionId, notify, request, log = () => {} }
|
|
|
130
130
|
const editBatch = async (args) => {
|
|
131
131
|
const edits = args.edits
|
|
132
132
|
if (!Array.isArray(edits) || edits.length === 0) {
|
|
133
|
-
throw new Error("edits must be a non-empty array of {path, old_string, new_string}")
|
|
133
|
+
throw new Error("edits must be a non-empty array of {path, old_string | line/startLine+endLine, new_string}")
|
|
134
134
|
}
|
|
135
135
|
assertEditArgsExclusive(args)
|
|
136
136
|
const groups = new Map() // path → { path, raw, content, edits }
|
|
@@ -269,7 +269,10 @@ export function buildAcpCallbacks({ sessionId, notify, request, log = () => {} }
|
|
|
269
269
|
return { handled: true, result: `Error: fs/write_text_file failed: ${e.message}` }
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
// 2026-09-08 D1:单形态按行号改(path + line/startLine/endLine + new_string——无
|
|
273
|
+
// old_string)同样走 IDE 缓冲通道(hasLineParams 判定)——否则回落本地写盘会与
|
|
274
|
+
// IDE 缓冲脱敏;editSingle → computeEditEntry 行号语义自动继承。
|
|
275
|
+
if (base === "edit" && (Array.isArray(args?.edits) || (path && typeof args?.new_string === "string" && (typeof args?.old_string === "string" || hasLineParams(args))))) {
|
|
273
276
|
try {
|
|
274
277
|
const text = Array.isArray(args?.edits) ? await editBatch(args) : await editSingle(path, args)
|
|
275
278
|
return { handled: true, result: text }
|
package/src/advisor/messages.mjs
CHANGED
|
@@ -129,6 +129,25 @@ export function buildObjectDeclarationBlock(object = null) {
|
|
|
129
129
|
].join("\n")
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Approval-signal block for design reviews (round 1 and round 2+ — §24 D-24b:
|
|
134
|
+
* an async fix-round continuation must be able to re-approve, so the token is
|
|
135
|
+
* injected into EVERY design round; the reviewer echoes it only on a clean pass).
|
|
136
|
+
* §29.1 F2a (2026-09-07): BOTH values are injected — the token AND the designId
|
|
137
|
+
* (anchor sentence verbatim — Copy BOTH values). designId null (legacy direct
|
|
138
|
+
* callers without a resolved instance) degrades to the token-only form.
|
|
139
|
+
*/
|
|
140
|
+
export function buildDesignApprovalBlock(designToken, designId) {
|
|
141
|
+
const echo = designId
|
|
142
|
+
? `If — and ONLY if — your review finds NO 🔴 (Critical) issues, end your reply with this exact token: [DESIGN-TOKEN:${designToken}] and this exact designId: ${designId}. Copy BOTH values verbatim.`
|
|
143
|
+
: `If — and ONLY if — your review finds NO 🔴 (Critical) issues, end your reply with this exact token: [DESIGN-TOKEN:${designToken}]`
|
|
144
|
+
return [
|
|
145
|
+
"## Approval Signal",
|
|
146
|
+
echo,
|
|
147
|
+
"🟡 (Advisory) and 🔵 (Note) findings do NOT block approval — list them if present, but still include the token. If there are any 🔴 issues, do NOT include the token.",
|
|
148
|
+
].join("\n")
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
/**
|
|
133
152
|
* Build the user message for an advisor review session.
|
|
134
153
|
* @param {Object} agent — the parent agent
|
|
@@ -142,9 +161,12 @@ export function buildObjectDeclarationBlock(object = null) {
|
|
|
142
161
|
* @param {Object|null} [object] — review-object declaration (§18.8 D-OA1/D-OA3):
|
|
143
162
|
* { type, target, status, reason, exclude } — mechanically injected at the
|
|
144
163
|
* start of the user message; absent → no injection (legacy calls unchanged).
|
|
164
|
+
* @param {string|null} [designId] — §29.1 F2a: injected next to the token in the
|
|
165
|
+
* Approval Signal (both values — the reviewer copies both verbatim); null →
|
|
166
|
+
* token-only degradation (legacy direct callers).
|
|
145
167
|
* @returns {string} the user message
|
|
146
168
|
*/
|
|
147
|
-
export function buildAdvisorUserMessage(agent, prior, reviewType, designToken = null, documents = null, paths = null, object = null) {
|
|
169
|
+
export function buildAdvisorUserMessage(agent, prior, reviewType, designToken = null, documents = null, paths = null, object = null, designId = null) {
|
|
148
170
|
// prior = the full prior review output (string) when a convergence round is
|
|
149
171
|
// being built (decision 2026-08-08 — verbatim injection, model understands it).
|
|
150
172
|
// Deterministic: only _advisorRound > 0 with stored output counts.
|
|
@@ -246,9 +268,7 @@ export function buildAdvisorUserMessage(agent, prior, reviewType, designToken =
|
|
|
246
268
|
parts.push("5. If you find issues, produce your review table with the format: | # | Category | Severity | Issue | Suggestion |. If the design passes, no table is needed.")
|
|
247
269
|
if (designToken) {
|
|
248
270
|
parts.push("")
|
|
249
|
-
parts.push(
|
|
250
|
-
parts.push(`If — and ONLY if — your review finds NO 🔴 (Critical) issues, end your reply with this exact token: [DESIGN-TOKEN:${designToken}]`)
|
|
251
|
-
parts.push("🟡 (Advisory) and 🔵 (Note) findings do NOT block approval — list them if present, but still include the token. If there are any 🔴 issues, do NOT include the token.")
|
|
271
|
+
parts.push(buildDesignApprovalBlock(designToken, designId))
|
|
252
272
|
}
|
|
253
273
|
return parts.join("\n")
|
|
254
274
|
}
|
package/src/advisor/run.mjs
CHANGED
|
@@ -10,11 +10,10 @@ import { appendCitationReport } from "./citations.mjs"
|
|
|
10
10
|
import { describeToolArgs } from "../tui/tool-args.mjs"
|
|
11
11
|
|
|
12
12
|
const MAX_ADVISOR_TURNS = 100
|
|
13
|
-
// Mechanical convergence cap:
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// _advisorRound in agent.mjs; the cap no longer exempts design).
|
|
13
|
+
// Mechanical convergence cap: up to 5 rounds suffice; a 6th call means the model
|
|
14
|
+
// is looping — refuse it instead of burning tokens. §24 D-24b (2026-09-06): PER
|
|
15
|
+
// REVIEW INSTANCE (agent._advisorRuns); CODE REVIEWS ONLY (2026-09-07 §8 ruling)
|
|
16
|
+
// — design reviews are EXEMPT: their rounds keep advancing, the cap never refuses.
|
|
18
17
|
export const MAX_ADVISOR_ROUNDS = 5
|
|
19
18
|
|
|
20
19
|
// NOTE: prompts/advisor-round{1,2,3}.md encourage the model to finish within
|
|
@@ -221,7 +220,7 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
|
|
|
221
220
|
// already streamed into the timeline via onText; fall back to
|
|
222
221
|
// response.content only if nothing was recorded.
|
|
223
222
|
if (!response.toolCalls?.length) {
|
|
224
|
-
if (!response.content?.trim()) return renderTimeline(timeline) || "Advisor:
|
|
223
|
+
if (!response.content?.trim()) return renderTimeline(timeline) || "Advisor: empty response — review was inconclusive"
|
|
225
224
|
return renderTimeline(timeline) || response.content.trim()
|
|
226
225
|
}
|
|
227
226
|
|
|
@@ -388,17 +387,35 @@ function extractUnfixedIssues(priorText) {
|
|
|
388
387
|
.filter(Boolean)
|
|
389
388
|
.slice(0, MAX_UNFIXED_DISPLAY)
|
|
390
389
|
}
|
|
390
|
+
/** Review-looking guard (async settle parity): a markdown table row or ≥200 chars of prose counts as a prior. */
|
|
391
|
+
export function looksLikeReviewOutput(text) {
|
|
392
|
+
const trimmed = String(text ?? "").trim()
|
|
393
|
+
return /\|.*\|.*\|/.test(trimmed) || trimmed.length >= 200
|
|
394
|
+
}
|
|
395
|
+
/** Cap message (shared by runAdvisorReview and the async pre-check — per-review refusal). */
|
|
396
|
+
export function buildCapMessage(agent) {
|
|
397
|
+
const prior = agent._lastAdvisorOutput
|
|
398
|
+
const unfixed = prior ? extractUnfixedIssues(prior) : []
|
|
399
|
+
let message = `Advisor: convergence cap reached after ${MAX_ADVISOR_ROUNDS} rounds.\n`
|
|
400
|
+
if (unfixed.length > 0) {
|
|
401
|
+
message += `\nUnresolved issues from prior rounds:\n${unfixed.map((i) => `- ${i}`).join("\n")}\n`
|
|
402
|
+
} else {
|
|
403
|
+
message += "\nAll prior issues appear resolved.\n"
|
|
404
|
+
}
|
|
405
|
+
message += "\nOptions:\n1. Accept current state and proceed\n2. Manually review specific concerns with read/grep\n3. Start a new session (/new) to reset the advisor"
|
|
406
|
+
return message
|
|
407
|
+
}
|
|
391
408
|
|
|
392
409
|
/**
|
|
393
410
|
* Run an advisor review. reviewType: "code" (default) or "design". Returns review text or null when skipped.
|
|
394
411
|
* @param {string|null} [designToken] — injected into the design-review prompt; the advisor echoes it only on approval.
|
|
395
412
|
* @param {string[]|null} [documents] — design review only: explicit list of doc paths to review; passed through to the message builder.
|
|
396
413
|
* @param {string[]|null} [paths] — code review only: explicit list of file/dir paths to review.
|
|
397
|
-
* @param {Object|null} [object] — review-object declaration (§18.8 D-OA1/D-OA3):
|
|
398
|
-
*
|
|
399
|
-
*
|
|
414
|
+
* @param {Object|null} [object] — review-object declaration (§18.8 D-OA1/D-OA3): { type, target, status, reason, exclude }; absent → legacy behavior (no injection).
|
|
415
|
+
* @param {string|null} [designId] — §29.1 F2a: injected next to the design token in
|
|
416
|
+
* the Approval Signal (passed through to the message builders).
|
|
400
417
|
*/
|
|
401
|
-
export async function runAdvisorReview(agent, reviewType, callbacks, designToken = null, documents = null, paths = null, object = null) {
|
|
418
|
+
export async function runAdvisorReview(agent, reviewType, callbacks, designToken = null, documents = null, paths = null, object = null, designId = null) {
|
|
402
419
|
const onOutput = callbacks?.onOutput
|
|
403
420
|
const signal = callbacks?.signal
|
|
404
421
|
const startTime = Date.now()
|
|
@@ -407,33 +424,19 @@ export async function runAdvisorReview(agent, reviewType, callbacks, designToken
|
|
|
407
424
|
// former advisor.enabled gate is removed — review capability has no off
|
|
408
425
|
// switch; only the guard (completion pushback) is opt-in via advisor.guard.
|
|
409
426
|
|
|
410
|
-
// Mechanical convergence cap —
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// Summarize unresolved items from the last review output for guidance
|
|
417
|
-
// (line-level status-word scan — no table-header parsing, decision 2026-08-08).
|
|
418
|
-
const prior = agent._lastAdvisorOutput
|
|
419
|
-
const unfixed = prior ? extractUnfixedIssues(prior) : []
|
|
420
|
-
|
|
421
|
-
let message = `Advisor: convergence cap reached after ${MAX_ADVISOR_ROUNDS} rounds.\n`
|
|
422
|
-
if (unfixed.length > 0) {
|
|
423
|
-
message += `\nUnresolved issues from prior rounds:\n${unfixed.map((i) => `- ${i}`).join("\n")}\n`
|
|
424
|
-
} else {
|
|
425
|
-
message += "\nAll prior issues appear resolved.\n"
|
|
426
|
-
}
|
|
427
|
-
message += "\nOptions:\n1. Accept current state and proceed\n2. Manually review specific concerns with read/grep\n3. Start a new session (/new) to reset the advisor"
|
|
428
|
-
|
|
429
|
-
return message
|
|
427
|
+
// Mechanical convergence cap — CODE REVIEWS ONLY (2026-09-07 §8 ruling: design
|
|
428
|
+
// reviews are exempt). _advisorRound is scoped to the current review instance
|
|
429
|
+
// (§24 D-24b ③), so >= MAX_ADVISOR_ROUNDS blocks the next call of THIS instance.
|
|
430
|
+
// 5 rounds max; after that the review is never pushed back.
|
|
431
|
+
if (reviewType !== "design" && (agent._advisorRound || 0) >= MAX_ADVISOR_ROUNDS) {
|
|
432
|
+
return buildCapMessage(agent)
|
|
430
433
|
}
|
|
431
434
|
|
|
432
435
|
const provider = resolveAdvisorProvider(agent)
|
|
433
436
|
// Advisor always works in the agent's cwd — scope is defined by paths/documents.
|
|
434
437
|
const advisorCwd = agent.cwd
|
|
435
438
|
|
|
436
|
-
const messages = prepareAdvisorMessages(agent, reviewType, designToken, documents, paths, null, object)
|
|
439
|
+
const messages = prepareAdvisorMessages(agent, reviewType, designToken, documents, paths, null, object, designId)
|
|
437
440
|
|
|
438
441
|
try {
|
|
439
442
|
const result = await runAdvisorToolLoop(provider, messages, onOutput, signal, agent, advisorCwd)
|
|
@@ -454,8 +457,7 @@ export async function runAdvisorReview(agent, reviewType, callbacks, designToken
|
|
|
454
457
|
// table row (`| a | b | c |`) or substantial prose (>200 chars). An
|
|
455
458
|
// empty or tool-progress-only reply must not become the "prior review"
|
|
456
459
|
// of round 2+.
|
|
457
|
-
const
|
|
458
|
-
const looksLikeReview = /\|.*\|.*\|/.test(trimmed) || trimmed.length >= 200
|
|
460
|
+
const looksLikeReview = looksLikeReviewOutput(final)
|
|
459
461
|
if (looksLikeReview) {
|
|
460
462
|
agent._lastAdvisorOutput = final
|
|
461
463
|
}
|
package/src/advisor.mjs
CHANGED
|
@@ -45,13 +45,13 @@ import { readFileSync } from "node:fs"
|
|
|
45
45
|
import { join, dirname } from "node:path"
|
|
46
46
|
import { fileURLToPath } from "node:url"
|
|
47
47
|
import { extractAgentResponseTable } from "./advisor/history.mjs"
|
|
48
|
-
import { buildAdvisorUserMessage, resolveScopeFiles, buildObjectDeclarationBlock } from "./advisor/messages.mjs"
|
|
48
|
+
import { buildAdvisorUserMessage, resolveScopeFiles, buildObjectDeclarationBlock, buildDesignApprovalBlock } from "./advisor/messages.mjs"
|
|
49
49
|
import { buildConvergenceBody } from "./advisor/convergence.mjs"
|
|
50
50
|
import { escapeLiteralEscapes } from "./escape.mjs"
|
|
51
51
|
// Re-export for run.mjs and tests (keeps their imports from "../advisor.mjs" stable)
|
|
52
52
|
export { ADVISOR_MD_PATH, extractAgentResponseTable, extractConversationBackground } from "./advisor/history.mjs"
|
|
53
53
|
export { buildAdvisorUserMessage } from "./advisor/messages.mjs"
|
|
54
|
-
export { buildObjectDeclarationBlock } from "./advisor/messages.mjs"
|
|
54
|
+
export { buildObjectDeclarationBlock, buildDesignApprovalBlock } from "./advisor/messages.mjs"
|
|
55
55
|
|
|
56
56
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
57
57
|
|
|
@@ -195,8 +195,10 @@ export { escapeLiteralEscapes }
|
|
|
195
195
|
* @param {Object|null} [object] — review-object declaration (§18.8 D-OA1): passed through
|
|
196
196
|
* to the user-message builders; mechanically injected at the start of every review
|
|
197
197
|
* round (round 1 design/code + round 2+ follow-up). Absent → legacy behavior.
|
|
198
|
+
* @param {string|null} [designId] — §29.1 F2a: injected next to the design token in
|
|
199
|
+
* the Approval Signal (round 1 + round 2+ — both values, verbatim anchor).
|
|
198
200
|
*/
|
|
199
|
-
export function prepareAdvisorMessages(agent, reviewType, designToken = null, documents = null, paths = null, priorParam = null, object = null) {
|
|
201
|
+
export function prepareAdvisorMessages(agent, reviewType, designToken = null, documents = null, paths = null, priorParam = null, object = null, designId = null) {
|
|
200
202
|
// Deterministic convergence state (decision 2026-08-08): round 2+ requires
|
|
201
203
|
// _advisorRound > 0 AND a stored prior review output. No history parsing.
|
|
202
204
|
// priorParam (direct callers) wins over the stored output — same derivation
|
|
@@ -209,7 +211,7 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
209
211
|
if (reviewType === "design" && (agent._advisorRound || 0) === 0) {
|
|
210
212
|
return [
|
|
211
213
|
{ role: "system", content: withTime(buildAdvisorSystemPrompt(agent, prior, reviewType)) },
|
|
212
|
-
{ role: "user", content: escapeLiteralEscapes(buildAdvisorUserMessage(agent, prior, reviewType, designToken, documents, paths, object)) },
|
|
214
|
+
{ role: "user", content: escapeLiteralEscapes(buildAdvisorUserMessage(agent, prior, reviewType, designToken, documents, paths, object, designId)) },
|
|
213
215
|
]
|
|
214
216
|
}
|
|
215
217
|
|
|
@@ -234,7 +236,7 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
234
236
|
agent._advisorRound = 0
|
|
235
237
|
}
|
|
236
238
|
// Mutations exist → KEEP the round (cap keeps advancing through retries).
|
|
237
|
-
const user = buildAdvisorUserMessage(agent, prior, reviewType, designToken, documents, paths, object)
|
|
239
|
+
const user = buildAdvisorUserMessage(agent, prior, reviewType, designToken, documents, paths, object, designId)
|
|
238
240
|
return [
|
|
239
241
|
{ role: "system", content: withTime(buildAdvisorSystemPrompt(agent, prior, reviewType)) },
|
|
240
242
|
{
|
|
@@ -263,8 +265,25 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
263
265
|
// scopeFiles gives the fallback (agent gave no response table) a concrete
|
|
264
266
|
// review surface.
|
|
265
267
|
const scopeFiles = resolveScopeFiles(agent, paths)
|
|
268
|
+
const followUp = buildAdvisorFollowUp(agent, prior, scopeFiles, object)
|
|
269
|
+
// §24 D-24b (design round 2+ — async fix-round continuations must be able to
|
|
270
|
+
// re-approve): re-anchor the review scope (the convergence follow-up carries no
|
|
271
|
+
// document list) and inject the round's design token with the approval signal.
|
|
272
|
+
if (reviewType === "design") {
|
|
273
|
+
const docList = Array.isArray(documents)
|
|
274
|
+
? documents.filter((d) => typeof d === "string" && d.trim())
|
|
275
|
+
: []
|
|
276
|
+
const scopeBlock = docList.length > 0
|
|
277
|
+
? `\n\n## Documents to Review\nThe documents below are the review scope. Review ONLY these files — do not scan git diff or read any other files.\n${docList.map((d) => `- ${d} — Read this file in full`).join("\n")}`
|
|
278
|
+
: ""
|
|
279
|
+
const tokenBlock = designToken ? `\n\n${buildDesignApprovalBlock(designToken, designId)}` : ""
|
|
280
|
+
return [
|
|
281
|
+
{ role: "system", content: withTime(buildAdvisorSystemPrompt(agent, prior, reviewType)) },
|
|
282
|
+
{ role: "user", content: escapeLiteralEscapes(followUp + scopeBlock + tokenBlock) },
|
|
283
|
+
]
|
|
284
|
+
}
|
|
266
285
|
return [
|
|
267
286
|
{ role: "system", content: withTime(buildAdvisorSystemPrompt(agent, prior, reviewType)) },
|
|
268
|
-
{ role: "user", content: escapeLiteralEscapes(
|
|
287
|
+
{ role: "user", content: escapeLiteralEscapes(followUp) },
|
|
269
288
|
]
|
|
270
289
|
}
|