thincoder 0.12.59 → 0.12.61
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 +62 -4
- package/README.md +10 -8
- package/bin/thincoder.mjs +99 -133
- package/package.json +6 -4
- package/src/abort-provenance.mjs +116 -0
- package/src/acp/bridge.mjs +45 -21
- package/src/acp.mjs +6 -1
- package/src/advisor/citations.mjs +83 -21
- package/src/advisor/compaction.mjs +174 -0
- package/src/advisor/loop.mjs +293 -0
- package/src/advisor/messages.mjs +59 -137
- package/src/advisor/project-context.mjs +194 -0
- package/src/advisor/repos.mjs +17 -40
- package/src/advisor/run.mjs +156 -359
- package/src/advisor/truncate.mjs +57 -0
- package/src/advisor.mjs +27 -7
- package/src/agent/completion.mjs +17 -11
- package/src/agent/dispatch.mjs +145 -27
- package/src/agent/helpers.mjs +107 -13
- package/src/agent/record-results.mjs +55 -11
- package/src/agent/relay-prefix.mjs +39 -0
- package/src/agent/run-stages.mjs +242 -0
- package/src/agent/setup-reminders.mjs +69 -0
- package/src/agent/setup.mjs +107 -127
- package/src/agent/spawn-child.mjs +55 -13
- package/src/agent-tools/advisor-async.mjs +346 -0
- package/src/agent-tools/advisor-settle.mjs +231 -0
- package/src/agent-tools/advisor.mjs +167 -116
- package/src/agent-tools/async-settle.mjs +191 -0
- package/src/agent-tools/batch-segment.mjs +195 -0
- package/src/agent-tools/consult.mjs +139 -107
- package/src/agent-tools/design-token.mjs +117 -0
- package/src/agent-tools/digest-budget.mjs +76 -0
- package/src/agent-tools/eng.mjs +24 -29
- package/src/agent-tools/escalate-async.mjs +289 -0
- package/src/agent-tools/read-history.mjs +166 -32
- package/src/agent-tools/recent-changes.mjs +2 -1
- package/src/agent-tools/review-streak.mjs +93 -0
- package/src/agent-tools/settings.mjs +137 -34
- package/src/agent-tools/subagent-actions.mjs +180 -133
- package/src/agent-tools/subagent-async.mjs +184 -177
- package/src/agent-tools/subagent-panel.mjs +160 -0
- package/src/agent-tools/subagent-run.mjs +205 -0
- package/src/agent-tools/subagent-scheduler.mjs +100 -27
- package/src/agent-tools/subagent-spawn.mjs +453 -0
- package/src/agent-tools/subagent.mjs +256 -578
- package/src/agent-tools/verify.mjs +119 -292
- package/src/agent-tools.mjs +1 -0
- package/src/agent.mjs +89 -205
- package/src/cli/distill-command.mjs +12 -6
- package/src/cli/make-agent.mjs +26 -8
- package/src/cli/memory-command.mjs +4 -3
- package/src/cli/permission.mjs +2 -2
- package/src/cli/setup-wizard.mjs +42 -17
- package/src/completions.mjs +114 -0
- package/src/config-migrate.mjs +70 -0
- package/src/config.mjs +180 -63
- package/src/context.mjs +5 -147
- package/src/conventions.mjs +223 -0
- package/src/crash-reports.mjs +128 -0
- package/src/distill.mjs +11 -11
- package/src/expand-home.mjs +16 -0
- package/src/explore-distill.mjs +155 -0
- package/src/generate-title.mjs +1 -1
- package/src/hooks.mjs +7 -3
- package/src/memory/code-index.mjs +9 -3
- package/src/memory/code-sync.mjs +72 -32
- package/src/memory/core.mjs +6 -193
- package/src/memory/delete.mjs +236 -0
- package/src/memory/docs.mjs +68 -54
- package/src/memory/file-walk.mjs +109 -0
- package/src/memory/schema.mjs +15 -3
- package/src/memory.mjs +3 -1
- package/src/model-ref.mjs +66 -0
- package/src/model-specs.mjs +42 -8
- package/src/peer-domains.mjs +265 -0
- package/src/peer-instances.mjs +231 -0
- package/src/prompt-overlays.mjs +82 -0
- package/src/prompts/advisor-design.md +18 -75
- package/src/prompts/advisor-round1.md +14 -67
- package/src/prompts/advisor-round2.md +15 -51
- package/src/prompts/advisor-round3.md +15 -51
- package/src/prompts/common.md +115 -0
- package/src/prompts/consult-base.md +5 -23
- package/src/prompts/discipline-engineering.md +217 -0
- package/src/prompts/discipline-normal.md +179 -0
- package/src/prompts/persona-coder.md +21 -0
- package/src/prompts/persona-eng-coder.md +37 -0
- package/src/prompts/persona-eng-designer.md +55 -0
- package/src/prompts/persona-engineering.md +54 -0
- package/src/prompts/persona-explore.md +15 -0
- package/src/prompts/persona-normal.md +27 -0
- package/src/prompts/persona-plan.md +26 -0
- package/src/provider/anthropic.mjs +4 -4
- package/src/provider/core.mjs +18 -98
- package/src/provider/errors.mjs +101 -0
- package/src/provider/google.mjs +5 -6
- package/src/provider/index.mjs +2 -1
- package/src/provider/list-models.mjs +93 -0
- package/src/provider/rate.mjs +2 -1
- package/src/provider/responses.mjs +5 -3
- package/src/provider/retry.mjs +8 -45
- package/src/provider/sse.mjs +3 -4
- package/src/proxy.mjs +9 -14
- 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 +188 -60
- package/src/session.mjs +104 -124
- package/src/token-ttl.mjs +274 -0
- package/src/tools/{system.mjs → bash.mjs} +19 -221
- 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 +41 -16
- package/src/tools/git.md +1 -1
- package/src/tools/git.mjs +23 -34
- 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 +9 -8
- package/src/tools/ops.mjs +188 -3
- package/src/tools/patch.mjs +3 -3
- package/src/tools/question.md +4 -0
- package/src/tools/question.mjs +26 -0
- package/src/tools/read.md +1 -2
- package/src/tools/read_image.md +1 -1
- package/src/tools/search.mjs +236 -0
- package/src/tools/shared.mjs +14 -13
- package/src/tools/wait_for.md +22 -0
- package/src/tui/agent-turn.mjs +36 -228
- package/src/tui/ansi.mjs +2 -0
- package/src/tui/clipboard.mjs +7 -1
- package/src/tui/cmd-advisor.mjs +3 -2
- package/src/tui/cmd-config.mjs +142 -30
- package/src/tui/cmd-eng.mjs +28 -40
- package/src/tui/cmd-exit.mjs +6 -8
- package/src/tui/cmd-mcp.mjs +8 -2
- package/src/tui/cmd-model.mjs +14 -12
- package/src/tui/cmd-new.mjs +3 -2
- package/src/tui/cmd-reindex.mjs +7 -0
- package/src/tui/cmd-session.mjs +19 -4
- package/src/tui/cmd-submodel.mjs +8 -5
- package/src/tui/cmd-think.mjs +10 -10
- package/src/tui/cmd-undo.mjs +4 -3
- 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 +40 -38
- package/src/tui/interaction.mjs +3 -3
- package/src/tui/key-handler.mjs +61 -17
- package/src/tui/key-modes.mjs +86 -8
- package/src/tui/layout.mjs +18 -10
- package/src/tui/model-catalog.mjs +89 -0
- package/src/tui/model-picker.mjs +498 -0
- package/src/tui/mouse.mjs +52 -9
- package/src/tui/pickers.mjs +28 -392
- package/src/tui/render-frame.mjs +32 -16
- package/src/tui/render-loop.mjs +2 -0
- package/src/tui/render-segments.mjs +12 -9
- package/src/tui/render.mjs +37 -5
- package/src/tui/slash-commands.mjs +2 -2
- package/src/tui/startup.mjs +4 -0
- package/src/tui/subagent-blocks.mjs +106 -295
- package/src/tui/subagent-children.mjs +162 -0
- package/src/tui/subagent-freeze.mjs +169 -0
- package/src/tui/subagent-panel.mjs +24 -31
- package/src/tui/suspension-drive.mjs +297 -0
- package/src/tui/tool-args.mjs +7 -5
- package/src/tui/tool-display.mjs +143 -0
- package/src/tui/tool-events.mjs +56 -185
- package/src/tui/tui-lifecycle.mjs +46 -4
- package/src/tui/update-notice.mjs +4 -0
- package/src/tui/wizard.mjs +61 -21
- package/src/tui/wrapped-spawn.mjs +38 -0
- package/src/prompts/coder.md +0 -56
- package/src/prompts/discipline.md +0 -102
- package/src/prompts/eng-coder.md +0 -44
- package/src/prompts/engineering-sub.md +0 -34
- package/src/prompts/engineering.md +0 -340
- package/src/prompts/explore.md +0 -21
- package/src/prompts/main.md +0 -56
- package/src/prompts/methodology-template.md +0 -58
- package/src/prompts/plan.md +0 -16
- package/src/prompts/system.md +0 -63
- 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
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* suspension-drive.mjs — §17 挂起会话驱动器(2026-09-05 module-split:agent-turn.mjs
|
|
3
|
+
* 535 > 500 硬限——poolCounts + §17 挂起会话段 verbatim 迁入,语义零变;agent-turn.mjs
|
|
4
|
+
* re-import(runAgentTurn ↔ suspensionSession 函数级静态环——模块求值期无顶层调用,
|
|
5
|
+
* 环安全——session-slots ↔ session.mjs 同款先例)。
|
|
6
|
+
*
|
|
7
|
+
* §17(2026-09-02,AGENT-LOOP.md §9 D-S1..S9):回合尾后台池非空 → 不阻塞等待,
|
|
8
|
+
* 进入挂起态——挂起空闲输入开放(Enter = 新回合填单槽 + 唤醒)、busy(processing 含
|
|
9
|
+
* digest)输入禁用(INPUT-LOCK-ASYNC C'——提交吞——2026-09-09)、settle 事件驱动
|
|
10
|
+
* auto-turn 消化(手动档 organize-only / AUTO 档全语义)、池空 + 无待处理输入 → 补发
|
|
11
|
+
* done 冻结自然退出。状态机行表见 AGENT-LOOP.md §9.2。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// 函数级静态环(2026-09-05):drive 的 digestTurn/用户回合经 runAgentTurn 递归进入
|
|
15
|
+
// agent-turn;agent-turn 的回合尾经 suspensionSession 进入本文件——互相 import。
|
|
16
|
+
import { runAgentTurn } from "./agent-turn.mjs"
|
|
17
|
+
import { freezeAllSubTasks, freezeReclaimDigestedBlocks } from "./subagent-blocks.mjs"
|
|
18
|
+
import { sweepToolBlocks } from "./tool-events.mjs"
|
|
19
|
+
import { logEvent } from "../log.mjs"
|
|
20
|
+
import { C } from "./ansi.mjs"
|
|
21
|
+
// ASYNC-RESULT-CONTAINER.md D1/D2:池 accessor(双池 absorb)+ pending 单容器停靠
|
|
22
|
+
import { getAsyncPool, parkAsyncPending } from "../agent-tools/async-settle.mjs"
|
|
23
|
+
|
|
24
|
+
// INPUT-LOCK-ASYNC(C'——2026-09-09,本档 INPUT-LOCK-ASYNC.md):R15 排队
|
|
25
|
+
// 用户指令合并(§11.3 D-24c——攒批计划/合并文案/上限常量)整批废弃
|
|
26
|
+
// ——busy 提交吞 + pendingInput 单槽化(至多一条待交接——单消息逐发不攒批)。
|
|
27
|
+
// 废弃记录见 AGENT-LOOP.md §11.3。
|
|
28
|
+
|
|
29
|
+
/** 后台池计数(LOGGING susp/digest 事件字段——pendingN/poolN)。
|
|
30
|
+
* poolN = _asyncSubagents + _asyncAdvisors(§11.2 D-24b advisor 池同面板计数——queued
|
|
31
|
+
* 条目同样在 map 内——2026-09-03 code review #2:不再 +queue.length 双计)。
|
|
32
|
+
* R17(§25 D-R17a/b):pendingN = pending 单容器 `_pendingAsyncResults` 条数(
|
|
33
|
+
* ASYNC-RESULT-CONTAINER.md D2——四族统一停靠——digest 驱动判据同单容器)。 */
|
|
34
|
+
export function poolCounts(agent) {
|
|
35
|
+
const map = agent?._asyncSubagents
|
|
36
|
+
const adv = agent?._asyncAdvisors
|
|
37
|
+
const running = (map ? [...map.values()].filter((e) => e.status === "running").length : 0)
|
|
38
|
+
+ (adv ? [...adv.values()].filter((e) => e.status === "running").length : 0)
|
|
39
|
+
+ consultRunningChildren(agent)
|
|
40
|
+
return {
|
|
41
|
+
poolN: (map?.size ?? 0) + (adv?.size ?? 0),
|
|
42
|
+
pendingN: pendingFamilyCount(agent),
|
|
43
|
+
runningN: running,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 运行中 consult children(会诊会话已跨回合——挂起判据/状态行计数同源)。 */
|
|
48
|
+
function consultRunningChildren(agent) {
|
|
49
|
+
let n = 0
|
|
50
|
+
for (const s of agent?._consultSessions?.values() ?? []) {
|
|
51
|
+
if (!s.stopped) n += Math.max(0, s.pending ?? 0)
|
|
52
|
+
}
|
|
53
|
+
return n
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** pending 单容器条数(§25 D-R17a 消费驱动判据——T-R17j——ASYNC-RESULT-CONTAINER.md
|
|
57
|
+
* D2:四族统一 `_pendingAsyncResults` +role,不再分族三容器)。 */
|
|
58
|
+
export function pendingFamilyCount(agent) {
|
|
59
|
+
return agent?._pendingAsyncResults?.length ?? 0
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** pending 单容器非空(digest 触发判据——D-S2/D-S9——§25 D-R17a)。 */
|
|
63
|
+
export function pendingFamiliesNonEmpty(agent) {
|
|
64
|
+
return pendingFamilyCount(agent) > 0
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** pending 单容器条目(freezeReclaimDigestedBlocks 的归属比对表——四族同容器)。 */
|
|
68
|
+
export function allPendingEntries(agent) {
|
|
69
|
+
return [...(agent?._pendingAsyncResults ?? [])]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ─── §17 挂起会话(AGENT-LOOP.md §17 D-S2/D-S9 状态机行表)────────────────
|
|
73
|
+
|
|
74
|
+
/** 后台池存活判据(D-S2/F5 口径):running/queued 子代理或后台评审,或已 settle 未注入结果
|
|
75
|
+
* (pending 单容器非空 = D-S3 "未注入"),或 running consult 会话(会诊跨回合——
|
|
76
|
+
* §25 D-R17a 挂起活度钩子——consult 启动回合尾即入挂起态)。回合尾与每次轮末都用它
|
|
77
|
+
* 评估退出。§11.2 D-24b:_asyncAdvisors(后台评审池)与子代理池同判——评审飞行中挂起
|
|
78
|
+
* 会话必须存活。 */
|
|
79
|
+
export function poolLive(agent) {
|
|
80
|
+
const map = agent._asyncSubagents
|
|
81
|
+
const adv = agent._asyncAdvisors
|
|
82
|
+
return (map && map.size > 0) || (adv && adv.size > 0)
|
|
83
|
+
|| pendingFamilyCount(agent) > 0
|
|
84
|
+
|| consultRunningChildren(agent) > 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** D-S3 ③ 记账清扫:回合边界竞态落下的已 settle 项(settle 回调未及移交——发生在
|
|
88
|
+
* 回合刚结束、_suspended 尚未置位的窗口)补入 pending。幂等:回调已移交的条目已从
|
|
89
|
+
* map 删除并带 _inPending 标记,不会重复入列。
|
|
90
|
+
* ASYNC-RESULT-CONTAINER.md D2:pending 单容器(parkAsyncPending——四族统一停靠
|
|
91
|
+
* +role;escalate 不再走独立流)。 */
|
|
92
|
+
function sweepSettledToPending(agent) {
|
|
93
|
+
const maps = [getAsyncPool(agent, "subagent"), getAsyncPool(agent, "advisor")].filter((m) => m instanceof Map && m.size > 0)
|
|
94
|
+
if (maps.length === 0) return
|
|
95
|
+
for (const map of maps) {
|
|
96
|
+
for (const e of [...map.values()]) {
|
|
97
|
+
if (e.done && !e._inPending) {
|
|
98
|
+
parkAsyncPending(agent, e)
|
|
99
|
+
map.delete(String(e.id))
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 等待下一次 settle(running 子代理 promise 完成)或用户唤醒(Enter 入队 / Ctrl+C /
|
|
106
|
+
* 会话 abort)。唤醒器经 state._suspWake 单槽注入;abort 监听兜底。 */
|
|
107
|
+
function waitForSettleOrWake(agent, state) {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
let finished = false
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
state._suspWake = null
|
|
112
|
+
const i = (agent._asyncWaiters ?? []).indexOf(w)
|
|
113
|
+
if (i >= 0) agent._asyncWaiters.splice(i, 1)
|
|
114
|
+
agent._sessionAbort?.signal.removeEventListener("abort", onAbort)
|
|
115
|
+
}
|
|
116
|
+
const finish = (why) => {
|
|
117
|
+
if (finished) return
|
|
118
|
+
finished = true
|
|
119
|
+
cleanup()
|
|
120
|
+
resolve(why)
|
|
121
|
+
}
|
|
122
|
+
const w = () => finish("settle")
|
|
123
|
+
const wake = () => finish("wake")
|
|
124
|
+
const onAbort = () => finish("aborted")
|
|
125
|
+
;(agent._asyncWaiters ??= []).push(w)
|
|
126
|
+
state._suspWake = wake
|
|
127
|
+
if (agent._sessionAbort?.signal.aborted) { onAbort(); return }
|
|
128
|
+
agent._sessionAbort?.signal.addEventListener("abort", onAbort, { once: true })
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 后台模式状态行文本(D-S8;17.5.4 #6 顺手对齐):"后台 N 子代理运行中 · M 完成待消化"
|
|
133
|
+
* ——"运行中" = running + queued(含后台评审——§11.2 D-24b 同面板计数)+ running consult
|
|
134
|
+
* children(R17——会诊跨回合);"完成待消化" = pending 任一族移交项 + §17.5 回合尾留池
|
|
135
|
+
* 的 settled 未消费项(挂起会话 sweep 前的可见窗口)。 */
|
|
136
|
+
function backgroundStatusText(agent) {
|
|
137
|
+
const map = agent._asyncSubagents
|
|
138
|
+
const adv = agent._asyncAdvisors
|
|
139
|
+
const running = (map ? [...map.values()].filter((e) => e.status === "running").length : 0)
|
|
140
|
+
+ (adv ? [...adv.values()].filter((e) => e.status === "running").length : 0)
|
|
141
|
+
+ consultRunningChildren(agent)
|
|
142
|
+
const queued = agent._asyncQueue?.length ?? 0
|
|
143
|
+
const pending = pendingFamilyCount(agent)
|
|
144
|
+
const doneInPool = (map ? [...map.values()].filter((e) => e.done).length : 0)
|
|
145
|
+
+ (adv ? [...adv.values()].filter((e) => e.done).length : 0) // §17.5 留池未消费
|
|
146
|
+
const awaiting = pending + doneInPool
|
|
147
|
+
const active = running + queued
|
|
148
|
+
return active > 0 || awaiting > 0
|
|
149
|
+
? `后台 ${active} 子代理运行中${awaiting ? ` · ${awaiting} 完成待消化` : ""}`
|
|
150
|
+
: "后台子代理收尾…"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 消化轮:系统驱动的 auto-turn(D-S6)。手动档不传权限/问答 handler(D-S7 装配
|
|
154
|
+
* 契约——denied 不弹面板、不悬挂);AUTO 档沿用普通回调(autoApprove 短路自动
|
|
155
|
+
* 执行)。_suspended 保持 true:消化中 settle 延迟冻结 + 移交 pending。R17:pending
|
|
156
|
+
* 计数/消化触发 = 任一 pending 族(T-R17j——consult/escalate 空闲 settle 也触发消化轮)。 */
|
|
157
|
+
async function digestTurn(ctx) {
|
|
158
|
+
const { agent, pushLine } = ctx
|
|
159
|
+
const manual = !agent.autoApprove
|
|
160
|
+
pushLine(manual
|
|
161
|
+
? "[auto-turn: digesting finished subagent reports…]"
|
|
162
|
+
: "[auto-turn: continuing background work…]", C.dim)
|
|
163
|
+
const digestCtx = manual
|
|
164
|
+
? { ...ctx, askPermission: null, askBatchPermission: null, askQuestion: null }
|
|
165
|
+
: ctx
|
|
166
|
+
// LOGGING:digest:* 事件(D-S9 消化轮边界——LOGGING.md F-L4 挂起态覆盖)
|
|
167
|
+
const d0 = Date.now()
|
|
168
|
+
const pend0 = pendingFamilyCount(agent)
|
|
169
|
+
logEvent("digest:start", { pendingN: pend0 })
|
|
170
|
+
await runAgentTurn(digestCtx, "", { autoTurn: true, skipSession: true })
|
|
171
|
+
logEvent("digest:end", { pendingN: pendingFamilyCount(agent), ms: Date.now() - d0 })
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* §17 挂起会话驱动(D-S9 行表;由 runAgentTurn 回合尾进入,池空自然退出):
|
|
176
|
+
* - suspension:池项 settle → 入 pending → 开 auto-turn(合并消化近邻 settle);
|
|
177
|
+
* 挂起空闲用户 Enter → pendingInput 单槽(busy 含 digest 提交吞——INPUT-LOCK-ASYNC)
|
|
178
|
+
* ——用户输入优先于 digest;
|
|
179
|
+
* - auto-turn:消化中 settle 不并发开新轮(单 runAgent 循环),轮末按 pending/池态
|
|
180
|
+
* 续开合并消化轮或回挂起;pendingInput 非空 → 以该消息开新回合(不触发新 digest);
|
|
181
|
+
* - §17.5.5:每次消化/会话内用户回合消费 pending 后 → freezeReclaimDigestedBlocks
|
|
182
|
+
* 逐条冻结回收(消化完成块不滞留面板——不等池空;settle 锚点 splice——digest 总览
|
|
183
|
+
* 文本之前——round1 #1 裁定);
|
|
184
|
+
* - 退出:池空 + pending 空 + 无待处理输入 → freezeAllSubTasks 补发冻结(仅兜底
|
|
185
|
+
* 未消化残项——17.5.5 块回收与池空解耦)→ idle。
|
|
186
|
+
* _suspended 翻转:会话期 true(settle 回调据此延迟冻结 + 移交 pending);会话内
|
|
187
|
+
* 用户回合执行期翻 false(普通回合语义:settle 即冻结 + 回合尾直注入 ①)。
|
|
188
|
+
*/
|
|
189
|
+
export async function suspensionSession(ctx) {
|
|
190
|
+
const { agent, state, render, pushLine } = ctx
|
|
191
|
+
state.pendingInput ??= []
|
|
192
|
+
state._suspAborted = false
|
|
193
|
+
agent._suspended = true
|
|
194
|
+
agent._sessionSignal = agent._sessionAbort.signal // 会话内 spawn 的 children 共享(subagent.mjs)
|
|
195
|
+
state.suspended = true
|
|
196
|
+
state._suspPending = false // 偏差 #1:进入真正挂起态——标志只在释放窗口期有效(此后由 state.suspended 分流)
|
|
197
|
+
const suspTick = setInterval(() => {
|
|
198
|
+
if (state.suspended && !state.processing) {
|
|
199
|
+
state.status = backgroundStatusText(agent)
|
|
200
|
+
render()
|
|
201
|
+
}
|
|
202
|
+
}, 1000)
|
|
203
|
+
state.status = backgroundStatusText(agent)
|
|
204
|
+
render()
|
|
205
|
+
// LOGGING:susp:* 事件(挂起态进入/退出——F-L4;挂起期输入事件 v1 不记——refinement #1)
|
|
206
|
+
const s0 = Date.now()
|
|
207
|
+
logEvent("susp:enter", poolCounts(agent))
|
|
208
|
+
try {
|
|
209
|
+
while (!state._suspAborted && !agent._sessionAbort.signal.aborted) {
|
|
210
|
+
sweepSettledToPending(agent)
|
|
211
|
+
// 1. 用户输入优先(D-S5):pendingInput 单槽(INPUT-LOCK-ASYNC C'——busy(processing
|
|
212
|
+
// 含 digest)提交吞——Enter 只可能落在挂起空闲/释放窗口——至多一条待交接——driver
|
|
213
|
+
// 消费清槽即开新回合)。R15 攒批/queue 双源已随排队机制废弃收敛(2026-09-09——
|
|
214
|
+
// 单消息交接——无合并无 /cmd 分流——key-handler 只收非斜杠文本——单消息逐发)。
|
|
215
|
+
if ((state.pendingInput?.length ?? 0) > 0) {
|
|
216
|
+
const head = String(state.pendingInput.shift())
|
|
217
|
+
agent._suspended = false // 用户回合 = 普通回合语义(① 直注入 + settle 即冻结)
|
|
218
|
+
await runAgentTurn(ctx, head, { skipSession: true })
|
|
219
|
+
agent._suspended = true
|
|
220
|
+
// §17.5.5:该回合消化完 pending(run 首行注入)→ 逐条冻结回收驻留块
|
|
221
|
+
// (不等池空——settle 锚点 splice——digest 总览文本之前;与 digest 回收同规则)
|
|
222
|
+
// R17:回收比对 = pending 单容器(四族统一——ASYNC-RESULT-CONTAINER.md D2)
|
|
223
|
+
freezeReclaimDigestedBlocks(state, allPendingEntries(agent))
|
|
224
|
+
state.status = backgroundStatusText(agent)
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
// 2. pending 任一族非空 → 合并消化轮(注入由 runAgent 首行统一完成——D-S3 单注入点;
|
|
228
|
+
// R17 判据推广——consult/escalate 族同样触发——T-R17j)
|
|
229
|
+
if (pendingFamiliesNonEmpty(agent)) {
|
|
230
|
+
await digestTurn(ctx)
|
|
231
|
+
// §17.5.5 实测修订(2026-09-03):digest 消化完成(pending 条目已注入)→ 逐条补发
|
|
232
|
+
// done 冻结回收——不等池空——块从面板移除进流(settle 锚点 splice 落位——digest
|
|
233
|
+
// 总览文本之前——round1 #1 裁定);池空 freeze-out 仅兜底未消化残项(挂起会话
|
|
234
|
+
// 结束统一清场)——块回收与池空解耦(T-H7/AC-H5)。
|
|
235
|
+
// 归属不变式:会话内任何 run 开始前 pinned 块(awaitingDigest)的条目必在 pending
|
|
236
|
+
// 任一族——run 消费后不在 pending 的 pinned 块即本 run 消化者(无需快照即精确归属)。
|
|
237
|
+
freezeReclaimDigestedBlocks(state, allPendingEntries(agent))
|
|
238
|
+
state.status = backgroundStatusText(agent)
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
// 3. 池空(无 running/queued/未注入)→ 自然退出回 idle(补发冻结在 finally)
|
|
242
|
+
if (!poolLive(agent)) break
|
|
243
|
+
// 4. 等下一 settle / 用户唤醒(Enter 入队、Ctrl+C)
|
|
244
|
+
await waitForSettleOrWake(agent, state)
|
|
245
|
+
}
|
|
246
|
+
} finally {
|
|
247
|
+
clearInterval(suspTick)
|
|
248
|
+
const aborted = state._suspAborted || agent._sessionAbort.signal.aborted
|
|
249
|
+
if (aborted && (agent._asyncSubagents?.size ?? 0) > 0) logEvent("ev:stopped", { poolN: agent._asyncSubagents?.size ?? 0, where: "suspension-abort" })
|
|
250
|
+
logEvent("susp:exit", { ...poolCounts(agent), ms: Date.now() - s0, reason: aborted ? "aborted" : "idle" })
|
|
251
|
+
agent._suspended = false
|
|
252
|
+
agent._sessionSignal = null
|
|
253
|
+
agent._sessionAbort = null
|
|
254
|
+
agent._sessionAbortAll = null // 偏差 #3:会话期 controller 集合随句柄一并释放
|
|
255
|
+
state.suspended = false
|
|
256
|
+
state._suspWake = null
|
|
257
|
+
state.suspAbortArmed = false // round2 偏差 #4:会话退出即解除挂起中止武装(防跨会话粘滞)
|
|
258
|
+
if (aborted) {
|
|
259
|
+
// §15 abort 语义:清池不注入(用户显式停——不注入陈旧错误)
|
|
260
|
+
agent._asyncSubagents?.clear()
|
|
261
|
+
agent._asyncAdvisors?.clear()
|
|
262
|
+
agent._asyncQueue = []
|
|
263
|
+
// ASYNC-RESULT-CONTAINER.md D2:pending 单容器——中止清容器不注入陈旧结果(四族
|
|
264
|
+
// 统一一处清;consult 会话标记 stopped——settle 不入 digest 流——T-R17c)+
|
|
265
|
+
// children abort。
|
|
266
|
+
agent._pendingAsyncResults = []
|
|
267
|
+
const { cleanupConsultSessions } = await import("../agent-tools/consult.mjs")
|
|
268
|
+
cleanupConsultSessions(agent)
|
|
269
|
+
// §17 round2 偏差 #2-CLI(code review round2 #2-CLI)+ INPUT-LOCK 单槽化:中止时
|
|
270
|
+
// 不静默丢弃挂起期输入——Enter 已清空输入框并入 pendingInput(用户视为已发送)——
|
|
271
|
+
// 单槽语义下残余至多一条——转回 state.queue({text} 单条目,下个普通回合的队列
|
|
272
|
+
// 循环续发——零丢失)+ 提示行明示去向(不静默丢)。
|
|
273
|
+
if ((state.pendingInput?.length ?? 0) > 0) {
|
|
274
|
+
state.queue.push({ text: String(state.pendingInput.shift()) })
|
|
275
|
+
pushLine(`[background work stopped — the message you entered will run as a normal turn]`, C.warn)
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
// D-S3 ③ 兜底:退出前残余(极端竞态)直注入再退——结果零丢失(AC-S2;
|
|
279
|
+
// ASYNC-RESULT-CONTAINER.md D2:pending 单容器一处清——注入器按 role 分发
|
|
280
|
+
// (consult → injectConsultResult;其余 → injectAsyncResult——四族同容器)。
|
|
281
|
+
const { injectAsyncResult } = await import("../agent-tools/subagent.mjs")
|
|
282
|
+
const { injectConsultResult } = await import("../agent-tools/consult.mjs")
|
|
283
|
+
const residual = agent._pendingAsyncResults
|
|
284
|
+
if (residual?.length) {
|
|
285
|
+
for (const e of residual.splice(0)) {
|
|
286
|
+
if (e.role === "consult") await injectConsultResult(agent, e)
|
|
287
|
+
else await injectAsyncResult(agent, e)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// 补发 done 冻结:驻留面板的 awaiting-digest 块随池空冻结进流(T-S14)
|
|
292
|
+
freezeAllSubTasks(state)
|
|
293
|
+
sweepToolBlocks(state)
|
|
294
|
+
state.status = "Ready"
|
|
295
|
+
render()
|
|
296
|
+
}
|
|
297
|
+
}
|
package/src/tui/tool-args.mjs
CHANGED
|
@@ -41,9 +41,11 @@ export function describeToolArgs(name, args) {
|
|
|
41
41
|
return a.filter ? `${p} (filter: ${String(a.filter)})` : p
|
|
42
42
|
}
|
|
43
43
|
case "websearch": return String(a.query ?? "")
|
|
44
|
-
case "subagent": case "coder": case "explore": case "plan": case "eng-coder": {
|
|
44
|
+
case "subagent": case "coder": case "explore": case "plan": case "eng-coder": case "eng-designer": {
|
|
45
45
|
const task = String(a.task ?? "").replace(/\s+/g, " ").trim()
|
|
46
|
-
|
|
46
|
+
if (task) return task.slice(0, 60) + (task.length > 60 ? "…" : "")
|
|
47
|
+
// action-only 调用(status/observe/send/cancel/escalate/consume-design…)无 task——action 兜底(2.4 批)
|
|
48
|
+
return a.action ? `(${String(a.action)})` : ""
|
|
47
49
|
}
|
|
48
50
|
case "advisor": return String(a.type ?? "review")
|
|
49
51
|
case "read_image": return String(a.path ?? "")
|
|
@@ -53,9 +55,9 @@ export function describeToolArgs(name, args) {
|
|
|
53
55
|
const action = String(a.action ?? "")
|
|
54
56
|
if (action === "put") return String(a.title ?? "")
|
|
55
57
|
if (action === "search") return String(a.query ?? "")
|
|
56
|
-
if (action === "list") return [a.
|
|
57
|
-
if (action === "delete") return a.id ? `id ${a.id} (${a.
|
|
58
|
-
if (action === "clear") return `clear ${a.
|
|
58
|
+
if (action === "list") return [a.layer && `layer ${a.layer}`, a.type && `type ${a.type}`, a.keyword && `kw ${a.keyword}`].filter(Boolean).join(" ")
|
|
59
|
+
if (action === "delete") return a.id ? `id ${a.id}${a.layer ? ` (layer ${a.layer})` : ""}` : `batch ${a.layer ?? ""} ${a.type ? `type ${a.type} ` : ""}${a.keyword ? `kw ${a.keyword}` : ""}`.trim()
|
|
60
|
+
if (action === "clear") return `clear ${a.layer ?? ""}`
|
|
59
61
|
return action || JSON.stringify(a)
|
|
60
62
|
}
|
|
61
63
|
case "lsp": return [a.subcommand, a.uri].filter(Boolean).map(String).join(" ")
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tool-display.mjs — 工具块显示/计时/清扫 helper 族(2026-09-05 module-split:
|
|
3
|
+
* tool-events.mjs 537 > 500 硬限——28-162 区(ticks/subActions maps、sweep/slim/
|
|
4
|
+
* settle/async 探测/find)verbatim 迁入,语义零变;tool-events.mjs import 回
|
|
5
|
+
* (buildToolCallbacks 调用点零改)+ re-export sweepToolBlocks(agent-turn 消费面)。
|
|
6
|
+
* 注意:_subActions/_subActionQ/_toolTicks 为模块级**可变对象**导出——ESM 只读绑定
|
|
7
|
+
* 不禁内容变更(.set/.delete/.push),调用方行为与同模块时代一致。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Tool execution start timestamps (performance.now ms). Keyed by tool_call id
|
|
11
|
+
// when available (parallel same-name tools each get their own tick — the
|
|
12
|
+
// P0-3 fix, 2026-08-30), falling back to a per-name FIFO queue for callers
|
|
13
|
+
// without ids (subagent relay). FIFO shift assumes near-call-order completion;
|
|
14
|
+
// a parallel same-name batch finishing out of order swaps durations between
|
|
15
|
+
// siblings — same magnitude, both keep an elapsed (display-level, acceptable).
|
|
16
|
+
|
|
17
|
+
// Named caps (consult P2, 2026-08-30): inline 200/3/5 were magic numbers.
|
|
18
|
+
// CLI-ACTIVITY-DEBLOAT F-1 (2026-09-10): the report preview constants (former named caps)
|
|
19
|
+
// deleted with the conversation-stream preview (tool-events onToolResult) — the
|
|
20
|
+
// frozen block is the ONLY carrier of a child's report.
|
|
21
|
+
export const TOOL_OUTPUT_LINE_CAP = 200 // per-call streaming output ring buffer
|
|
22
|
+
export const REMINDER_CAP = 3 // max pending reminders shown on turn end
|
|
23
|
+
export const REMINDER_PERSIST_TURNS = 5 // persist reminders every N turns
|
|
24
|
+
|
|
25
|
+
export const _toolTicks = new Map()
|
|
26
|
+
// §19 action registry: tool_call id → subagent action (non-spawn only — spawn is
|
|
27
|
+
// the default when no record exists). onToolCall sees the args, onToolResult only
|
|
28
|
+
// the name; without the record every subagent result would route as a spawn.
|
|
29
|
+
export const _subActions = new Map()
|
|
30
|
+
export const _subActionQ = [] // FIFO for subagent calls without a tool id (same fallback as tick queue)
|
|
31
|
+
|
|
32
|
+
export function tickStart(name, toolId) {
|
|
33
|
+
const key = toolId ?? name
|
|
34
|
+
if (toolId) { _toolTicks.set(key, performance.now()); return }
|
|
35
|
+
const q = _toolTicks.get(key) ?? []
|
|
36
|
+
q.push(performance.now())
|
|
37
|
+
_toolTicks.set(key, q)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Settle one pending tick: by tool_call id, or per-name FIFO. Returns start or null. */
|
|
41
|
+
export function tickTake(name, toolId) {
|
|
42
|
+
const key = toolId ?? name
|
|
43
|
+
const v = _toolTicks.get(key)
|
|
44
|
+
if (v === undefined) return null
|
|
45
|
+
if (toolId) { _toolTicks.delete(key); return v }
|
|
46
|
+
if (v.length === 0) { _toolTicks.delete(key); return null }
|
|
47
|
+
const started = v.shift()
|
|
48
|
+
if (v.length === 0) _toolTicks.delete(key)
|
|
49
|
+
return started
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** P0-2 sweep (2026-08-30 consult): an interrupted turn (Ctrl+C / error) leaves
|
|
53
|
+
* running tool-block carriers without an onToolResult — their header would say
|
|
54
|
+
* "running" forever. runAgentTurn's finally calls this: mark them done with an
|
|
55
|
+
* "(interrupted)" status and clear the tick table so no stale start time leaks
|
|
56
|
+
* into the next turn. Mirrors freezeAllSubTasks for the tool-block family. */
|
|
57
|
+
export function sweepToolBlocks(state) {
|
|
58
|
+
for (const l of state.lines ?? []) {
|
|
59
|
+
const b = l._toolBlock
|
|
60
|
+
if (b && !b.done) {
|
|
61
|
+
b.done = true
|
|
62
|
+
b.summary = "(interrupted)"
|
|
63
|
+
b.interrupted = true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
_toolTicks.clear()
|
|
67
|
+
_subActions.clear()
|
|
68
|
+
_subActionQ.length = 0
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Shared display guard for tool results — LIVE and RESTORE use the same
|
|
72
|
+
* function (P1, 2026-08-30 consult: restore lacked the live path's guards).
|
|
73
|
+
* 1) Multimodal results (read_image) embed FULL base64 images in the JSON —
|
|
74
|
+
* the human needs only the text part (model gets images via the multimodal
|
|
75
|
+
* channel); 2) results beyond maxRows are truncated in the block (full
|
|
76
|
+
* text always lives in history for the model). Returns row array. */
|
|
77
|
+
export function slimToolResultForDisplay(result, maxRows = 400) {
|
|
78
|
+
let displayResult = result
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(result)
|
|
81
|
+
if (parsed?.images?.length) displayResult = parsed.text ?? result
|
|
82
|
+
} catch { /* not JSON — show as-is */ }
|
|
83
|
+
const rows = String(displayResult).split("\n").filter((l) => l.trim())
|
|
84
|
+
return rows.length > maxRows
|
|
85
|
+
? [...rows.slice(0, maxRows), `… (result truncated at ${maxRows} rows — full text in history)`]
|
|
86
|
+
: rows
|
|
87
|
+
}
|
|
88
|
+
/** Mark the dispatch-level tool carrier done when its result is consumed by a
|
|
89
|
+
* dedicated branch (subagent/escalate/advisor blocks) — without this the turn
|
|
90
|
+
* sweep mislabels successful calls as "(interrupted)" (consult P1, 2026-08-30). */
|
|
91
|
+
export function settleToolBlock(state, name, toolId, summary) {
|
|
92
|
+
const block = findToolBlock(state, name, toolId)
|
|
93
|
+
if (block) {
|
|
94
|
+
block.done = true
|
|
95
|
+
block.summary = summary
|
|
96
|
+
const started = tickTake(name, toolId)
|
|
97
|
+
block.elapsed = started !== null ? Math.round(performance.now() - started) : null
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Async spawn detection (§15 D-A1): the subagent tool's async:true result is a
|
|
102
|
+
* status JSON ({id, role, status: running|queued}), NOT a report — the child
|
|
103
|
+
* keeps running, so its activity block must not be frozen at spawn time (it
|
|
104
|
+
* freezes via the ⟦ev⟧done event at settle — §15 D-A3). */
|
|
105
|
+
export function isAsyncSpawnResult(result) {
|
|
106
|
+
try {
|
|
107
|
+
const o = JSON.parse(result)
|
|
108
|
+
return Boolean(o && typeof o === "object" && typeof o.id !== "undefined" && (o.status === "running" || o.status === "queued"))
|
|
109
|
+
} catch {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** §7.2.3 spawn 门拒错误探测(T-F5):subagent spawn 的机械拒绝以 {status:"error"}
|
|
115
|
+
* JSON 返回(例:manual auto-turn digest spawn 门——digest 语义 organize-only)——
|
|
116
|
+
* 错误路径不得触发完成冻结(round1 #1——错误路径不冻结任何 running 块)。该形态只
|
|
117
|
+
* 出现在无 subKey 的拒绝路径(成功路径恒带 dispatch 传的 ctx._subagentKey)。 */
|
|
118
|
+
export function isSpawnErrorResult(result) {
|
|
119
|
+
try {
|
|
120
|
+
const o = JSON.parse(result)
|
|
121
|
+
return Boolean(o && typeof o === "object" && o.status === "error")
|
|
122
|
+
} catch {
|
|
123
|
+
return false
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Find the live tool-block carrier for a tool event: exact id match when the
|
|
128
|
+
* callback carries one (P0-3 — parallel same-name tools route to their own
|
|
129
|
+
* block); falls back to the last unfinished block of that name. */
|
|
130
|
+
export function findToolBlock(state, name, toolId) {
|
|
131
|
+
const lines = state.lines ?? []
|
|
132
|
+
if (toolId !== undefined && toolId !== null) {
|
|
133
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
134
|
+
if (lines[i]._toolBlock?.id === toolId) return lines[i]._toolBlock
|
|
135
|
+
}
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
138
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
139
|
+
const b = lines[i]._toolBlock
|
|
140
|
+
if (b && b.name === name && !b.done) return b
|
|
141
|
+
}
|
|
142
|
+
return null
|
|
143
|
+
}
|