@thincoder/core 0.9.4 → 0.10.1

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.
Files changed (221) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +1 -1
  3. package/abort-provenance.mjs +10 -10
  4. package/advisor/citations.mjs +5 -5
  5. package/advisor/compaction.mjs +16 -15
  6. package/advisor/loop.mjs +14 -14
  7. package/advisor/messages.mjs +6 -6
  8. package/advisor/project-context.mjs +5 -5
  9. package/advisor/repos.mjs +3 -3
  10. package/advisor/run.mjs +23 -13
  11. package/advisor.mjs +4 -4
  12. package/agent/assemble.mjs +111 -0
  13. package/agent/chat-call.mjs +68 -0
  14. package/agent/child-marks.mjs +2 -2
  15. package/agent/completion.mjs +9 -2
  16. package/agent/continue-decision.mjs +25 -0
  17. package/agent/dispatch-gates.mjs +140 -0
  18. package/agent/dispatch-run.mjs +167 -0
  19. package/agent/dispatch.mjs +55 -294
  20. package/agent/family-tools.mjs +11 -11
  21. package/agent/helpers.mjs +63 -3
  22. package/agent/live-beat.mjs +49 -0
  23. package/agent/post-turn.mjs +4 -8
  24. package/agent/record-results.mjs +23 -20
  25. package/agent/relay-prefix.mjs +2 -2
  26. package/agent/run-stages.mjs +19 -15
  27. package/agent/run-start.mjs +111 -0
  28. package/agent/setup-reminders.mjs +9 -9
  29. package/agent/setup.mjs +32 -4
  30. package/agent/spawn-child.mjs +9 -9
  31. package/agent/suspension.mjs +90 -30
  32. package/agent/timers.mjs +113 -0
  33. package/agent/turn-loop.mjs +244 -0
  34. package/agent/write-gate.mjs +103 -6
  35. package/agent-tools/advisor-async.mjs +11 -11
  36. package/agent-tools/advisor-settle.mjs +17 -17
  37. package/agent-tools/advisor.mjs +38 -43
  38. package/agent-tools/async-discard.mjs +44 -1
  39. package/agent-tools/async-settle.mjs +23 -20
  40. package/agent-tools/audit-block.mjs +7 -7
  41. package/agent-tools/bash-async.mjs +281 -0
  42. package/agent-tools/batch-lifecycle.mjs +65 -34
  43. package/agent-tools/batch-paths.mjs +186 -0
  44. package/agent-tools/batch-skeleton.mjs +19 -1
  45. package/agent-tools/batch.mjs +22 -119
  46. package/agent-tools/checkpoint.mjs +121 -0
  47. package/agent-tools/child-permission.mjs +5 -3
  48. package/agent-tools/consult.mjs +58 -58
  49. package/agent-tools/context.mjs +4 -20
  50. package/agent-tools/design-token.mjs +3 -3
  51. package/agent-tools/digest-budget.mjs +1 -1
  52. package/agent-tools/eng.mjs +5 -5
  53. package/agent-tools/escalate-async.mjs +18 -13
  54. package/agent-tools/goal.mjs +3 -10
  55. package/agent-tools/panel-blocks.mjs +3 -3
  56. package/agent-tools/parent-channel.mjs +3 -13
  57. package/agent-tools/plan.mjs +3 -4
  58. package/agent-tools/read-history.mjs +12 -28
  59. package/agent-tools/recent-changes.mjs +4 -5
  60. package/agent-tools/review-facts.mjs +1 -1
  61. package/agent-tools/settings.mjs +47 -20
  62. package/agent-tools/skill.mjs +3 -5
  63. package/agent-tools/spawn-gates.mjs +3 -3
  64. package/agent-tools/subagent-actions-query.mjs +270 -0
  65. package/agent-tools/subagent-actions.mjs +29 -273
  66. package/agent-tools/subagent-async.mjs +36 -31
  67. package/agent-tools/subagent-panel.mjs +38 -9
  68. package/agent-tools/subagent-run.mjs +44 -29
  69. package/agent-tools/subagent-scheduler.mjs +29 -28
  70. package/agent-tools/subagent-spawn.mjs +57 -25
  71. package/agent-tools/subagent.mjs +46 -66
  72. package/agent-tools/task.mjs +3 -9
  73. package/agent-tools/timer.mjs +12 -12
  74. package/agent-tools/verify.mjs +14 -13
  75. package/agent-tools.mjs +0 -1
  76. package/agent.mjs +20 -351
  77. package/attachments.mjs +125 -0
  78. package/auto-think.mjs +1 -1
  79. package/config-presets.mjs +12 -7
  80. package/config-watch.mjs +83 -0
  81. package/config.mjs +17 -4
  82. package/context-degrade.mjs +81 -0
  83. package/context-echo.mjs +88 -0
  84. package/context-push.mjs +51 -0
  85. package/context.mjs +8 -187
  86. package/conventions.mjs +110 -161
  87. package/declaration.mjs +194 -0
  88. package/embedding.mjs +3 -1
  89. package/env-ref.mjs +81 -0
  90. package/explore-distill.mjs +2 -3
  91. package/file-links.mjs +53 -0
  92. package/file-refs.mjs +103 -0
  93. package/generate-title.mjs +28 -4
  94. package/git/checkpoint.mjs +4 -8
  95. package/history-window.mjs +17 -2
  96. package/i18n.mjs +2 -0
  97. package/index-discover.mjs +7 -7
  98. package/ledger-cmd.mjs +34 -126
  99. package/ledger-db.mjs +35 -7
  100. package/ledger-migrate.mjs +299 -0
  101. package/ledger-tools.mjs +188 -0
  102. package/ledger.mjs +11 -5
  103. package/log.mjs +12 -7
  104. package/manifest-discovery.mjs +131 -0
  105. package/manifest-schema.mjs +166 -0
  106. package/manifest.mjs +18 -217
  107. package/mcp.mjs +4 -1
  108. package/memory/code-search.mjs +149 -0
  109. package/memory/code-sync.mjs +89 -230
  110. package/memory/core.mjs +47 -32
  111. package/memory/docs.mjs +63 -262
  112. package/memory/file-list.mjs +89 -0
  113. package/memory/file-walk.mjs +7 -4
  114. package/memory/memory-tool.mjs +229 -0
  115. package/memory/schema.mjs +18 -3
  116. package/memory/sweep.mjs +289 -0
  117. package/memory/sync-tail.mjs +81 -0
  118. package/memory-status.mjs +69 -0
  119. package/memory.mjs +3 -0
  120. package/model-specs.mjs +131 -66
  121. package/notify-policy.mjs +51 -0
  122. package/package.json +1 -1
  123. package/peer-claims.mjs +263 -0
  124. package/peer-domains.mjs +100 -71
  125. package/peer-instances.mjs +9 -10
  126. package/process-probe-exec.mjs +187 -0
  127. package/process-probe.mjs +27 -175
  128. package/prompt-overlays.mjs +11 -10
  129. package/prompts/advisor-design.md +2 -2
  130. package/prompts/advisor-round2.md +1 -1
  131. package/prompts/advisor-round3.md +1 -1
  132. package/prompts/common.md +19 -7
  133. package/prompts/discipline-engineering.md +57 -16
  134. package/prompts/discipline-normal.md +6 -3
  135. package/prompts/persona-coder.md +0 -1
  136. package/prompts/persona-eng-coder.md +1 -5
  137. package/prompts/persona-eng-designer.md +1 -2
  138. package/prompts/persona-engineering.md +41 -11
  139. package/prompts/persona-explore.md +0 -1
  140. package/prompts/persona-normal.md +10 -1
  141. package/prompts/persona-plan.md +3 -4
  142. package/prompts/subagent-base.md +14 -0
  143. package/provider/core.mjs +11 -48
  144. package/provider/list-models.mjs +3 -0
  145. package/provider/responses-request.mjs +237 -0
  146. package/provider/responses.mjs +6 -228
  147. package/provider-flows.mjs +248 -0
  148. package/queued.mjs +90 -0
  149. package/rules.mjs +209 -2
  150. package/session-gc.mjs +67 -6
  151. package/session-guard.mjs +27 -7
  152. package/session-lifecycle.mjs +90 -18
  153. package/session-rename.mjs +5 -1
  154. package/session-slot-claims.mjs +230 -0
  155. package/session-slot-scan.mjs +299 -0
  156. package/session-slot-verify.mjs +304 -0
  157. package/session-slot-write.mjs +74 -8
  158. package/session-slots-manifest.mjs +163 -236
  159. package/session-slots.mjs +99 -71
  160. package/session.mjs +30 -10
  161. package/shell-candidates.mjs +78 -0
  162. package/text-budget.mjs +2 -2
  163. package/think-off.mjs +49 -0
  164. package/token-ttl.mjs +15 -4
  165. package/tool-args.mjs +73 -0
  166. package/tool-docs/advisor.md +9 -0
  167. package/tool-docs/batch.md +1 -0
  168. package/tool-docs/code_search.md +1 -0
  169. package/tool-docs/consult_start.md +5 -0
  170. package/tool-docs/consult_stop.md +3 -0
  171. package/tool-docs/context.md +7 -0
  172. package/tool-docs/doc_search.md +1 -0
  173. package/tool-docs/edit.md +2 -13
  174. package/tool-docs/eng.md +1 -0
  175. package/tool-docs/execute.md +1 -9
  176. package/tool-docs/git.md +25 -51
  177. package/tool-docs/goal.md +6 -0
  178. package/tool-docs/ledger_add.md +1 -0
  179. package/tool-docs/ledger_close.md +1 -0
  180. package/tool-docs/ledger_count.md +1 -0
  181. package/tool-docs/ledger_query.md +1 -0
  182. package/tool-docs/ledger_update.md +1 -0
  183. package/tool-docs/main_history.md +1 -0
  184. package/tool-docs/memory.md +10 -0
  185. package/tool-docs/notify_parent.md +9 -0
  186. package/tool-docs/peer_instances.md +1 -0
  187. package/tool-docs/plan.md +5 -0
  188. package/tool-docs/process.md +7 -3
  189. package/tool-docs/question.md +1 -0
  190. package/tool-docs/read_history.md +7 -0
  191. package/tool-docs/recent_changes.md +1 -0
  192. package/tool-docs/repo_outline.md +1 -0
  193. package/tool-docs/settings.md +6 -0
  194. package/tool-docs/skill.md +5 -0
  195. package/tool-docs/subagent.md +31 -0
  196. package/tool-docs/task.md +7 -0
  197. package/tool-docs/timer.md +6 -0
  198. package/tool-docs/verify.md +1 -0
  199. package/tool-docs/wait_for.md +2 -1
  200. package/tools/bash.mjs +28 -4
  201. package/tools/edit-batch.mjs +10 -11
  202. package/tools/edit-diff.mjs +33 -25
  203. package/tools/exec-run.mjs +102 -4
  204. package/tools/execute.mjs +5 -2
  205. package/tools/file.mjs +11 -12
  206. package/tools/git-run.mjs +1 -1
  207. package/tools/git.mjs +0 -24
  208. package/tools/glob-dialect.mjs +3 -3
  209. package/tools/index.mjs +2 -1
  210. package/tools/linter.mjs +2 -1
  211. package/tools/node-child.mjs +21 -0
  212. package/tools/ops.mjs +50 -13
  213. package/tools/patch.mjs +4 -2
  214. package/tools/repomap.mjs +20 -9
  215. package/tools/search.mjs +2 -2
  216. package/tools/shared.mjs +9 -7
  217. package/tools/web.mjs +5 -2
  218. package/tools/write-path.mjs +1 -1
  219. package/traces/trace-store.mjs +17 -14
  220. package/vision-reader.mjs +76 -0
  221. package/agent-tools/batch-segment.mjs +0 -18
@@ -1,6 +1,6 @@
1
1
  /**
2
- * subagent-panel.mjs — subagent action:"panel" 执行器(§19.6——2026-09-08 自
3
- * subagent-actions.mjs 拆分——Module Split Policy:601 > 500 硬限跨档,§19.6 面板段
2
+ * subagent-panel.mjs — subagent action:"panel" 执行器(AGENT-LOOP-SUBAGENT.md §6.7.2——2026-09-08 自
3
+ * subagent-actions.mjs 拆分——Module Split Policy:601 > 500 硬限跨档,AGENT-LOOP-SUBAGENT.md §6.7.2 面板段
4
4
  * verbatim 迁入 + ASYNC-RESULT-CONTAINER.md D1/D2 落地(池 accessor getAsyncPool +
5
5
  * pending 单容器 _pendingAsyncResults 四族统一——escalate/consult 独立族退役))。
6
6
  * 内容:executePanelAction(D-P2——readonly 视图面 + 门控 freeze)+ panelFreezeGate
@@ -20,14 +20,36 @@ function blockKeyIn(container, key) {
20
20
  return entries.some((e) => `${e.role}#${e.id}` === key)
21
21
  }
22
22
 
23
+ /** consult 子块键形态(#748):`consult#<N>`(N = 子块 relay 号——会话条目 `childIds` 表元素同形)。 */
24
+ function consultChildKey(key) {
25
+ const k = String(key ?? "")
26
+ return k.startsWith("consult#") && !k.includes("/") && k.length > "consult#".length
27
+ }
28
+
29
+ /** consult 子块消费判读(#748——与回收 ∥ 补发判据同源):会话在跑(`_consultSessions` 内未 stopped
30
+ * 会话携该 relay 号)∥ 会话条目在 pending(`childIds` 携该号)⇒ **未消化**(报告未达模型——
31
+ * 冻结 ∥ 回收即破坏消化顺序)。非 consult 子块键 ⇒ 恒 false。 */
32
+ function consultChildUndigested(agent, key) {
33
+ if (!consultChildKey(key)) return false
34
+ const id = String(key).slice("consult#".length)
35
+ for (const s of agent?._consultSessions?.values() ?? []) {
36
+ if (s.stopped !== true && (s.childIds ?? []).includes(id)) return true
37
+ }
38
+ for (const e of agent?._pendingAsyncResults ?? []) {
39
+ if (e?.role === "consult" && (e.childIds ?? []).includes(id)) return true
40
+ }
41
+ return false
42
+ }
43
+
23
44
  /**
24
- * §19.6 D-P3 冻结门控(安全):仅允许冻结 awaitingDigest 且池(_asyncSubagents/
45
+ * AGENT-LOOP-SUBAGENT.md §6.7.2 D-P3 冻结门控(安全):仅允许冻结 awaitingDigest 且池(_asyncSubagents/
25
46
  * _asyncAdvisors——经 getAsyncPool accessor——D1)无对应运行条目 + pending 单容器
26
47
  * (_pendingAsyncResults——D2)无对应条目的块(= 已消化驻留块——报告已入模型上下文
27
48
  * ——pending 已消费——状态滞后——补发冻结不破坏任何顺序)。
28
49
  * - pending 仍有对应(报告未达模型)→ 拒绝(提前回收破坏消化顺序——T-P3)
29
50
  * - 不存在的 key / 仍 running / done 的块 → 拒绝(T-P4——running 块 settle 时自冻)
30
51
  * - 无面板(现算返 null)→ 拒绝(headless/VS Code——freeze 不可用——T-P5)
52
+ * - consult 子块(#748):会话在跑 ∥ 会话条目在 pending(`childIds` 携该号)→ 拒绝(同判据——与回收 ∥ 补发同源)
31
53
  * 错误信息明确(模型可解释 + 自助修正)。返回 { ok:true } 或 { err }。
32
54
  */
33
55
  function panelFreezeGate(ctx, key) {
@@ -55,15 +77,19 @@ function panelFreezeGate(ctx, key) {
55
77
  return { err: `block ${key} still has a live pool entry — it is NOT a digested-stuck block (freeze refused; status action shows the pool)` }
56
78
  }
57
79
  // ASYNC-RESULT-CONTAINER.md D2:pending 单容器(四族统一——原 escalate/consult
58
- // 独立族退役)。
59
- if (blockKeyIn(ctx.agent._pendingAsyncResults, key)) {
80
+ // 独立族退役)。#748:consult 子块键不经裸键比对(会话条目键 `consult#<sessionId>` 与
81
+ // 子块键可数字撞键)——改判消费判据(会话在跑 ∥ 会话条目在 pending——与回收 ∥ 补发同源)。
82
+ if (!consultChildKey(key) && blockKeyIn(ctx.agent._pendingAsyncResults, key)) {
60
83
  return { err: `block ${key} is still genuinely awaiting digestion — its report is still pending and has NOT reached the model yet; freezing now would break the digestion order (wait for the digest run, which reclaims it automatically)` }
61
84
  }
85
+ if (consultChildUndigested(ctx.agent, key)) {
86
+ return { err: `block ${key} belongs to a consultation whose digest has not been consumed — the session is still running, or its session entry is still pending (freeze refused; the block is reclaimed at the consumption window)` }
87
+ }
62
88
  return { ok: true }
63
89
  }
64
90
 
65
91
  /**
66
- * §19.6 subagent action:"panel"(D-P2——readonly 视图面 + 门控干预面——单动作双参,
92
+ * AGENT-LOOP-SUBAGENT.md §6.7.2 subagent action:"panel"(D-P2——readonly 视图面 + 门控干预面——单动作双参,
67
93
  * freeze 优先):
68
94
  * - view(缺省——返回面板块列表):ctx.state(= agent._tuiState——CLI TUI 装配)经
69
95
  * computePanelBlocks **读时现算**(F-3 单账本——与用户所见一致)。awaitingDigest 条目
@@ -72,7 +98,7 @@ function panelFreezeGate(ctx, key) {
72
98
  * = 报告已消化但块仍驻留——异常块——freeze 候选;模型可定位解释 UI 怪相)。
73
99
  * - freeze:key(D-P3 门控通过 → 发 key + "/" + ⟦ev⟧done 哨兵字面 token——
74
100
  * onToken——TUI routeSubToken 冻结回收——落位复用 sub._freezeAt settle 锚点
75
- * splice,无锚点尾推兜底——§17.5.5 同口径——round1 #2)。
101
+ * splice,无锚点尾推兜底——AGENT-LOOP-ASYNC-POOL.md §6.8 同口径——round1 #2)。
76
102
  * 无 TUI state(headless/VS Code——D-P2 round1 #1:webview 无 state.subTasks 对应物——
77
103
  * 7.2.3.2 #8 先例)→ view 恒降级池视图(双池经 getAsyncPool + pending 单容器
78
104
  * 合成)+ no panel 注;freeze 报不可用。CLI-only 完整能力(AC-P4)。
@@ -151,8 +177,11 @@ export function executePanelAction(args, ctx) {
151
177
  // 读时交叉(round1 #3):pending/池均无对应 = 报告已消化(注入即从两者移除)——
152
178
  // 块驻留 = 状态滞后——digested:true(freeze 候选——模型可定位异常块)。
153
179
  // ASYNC-RESULT-CONTAINER.md D2:pending 单容器参与比对(四族统一)。
154
- out.digested = !blockKeyIn(agent._pendingAsyncResults, b.key)
155
- && !blockKeyIn(getAsyncPool(agent, "subagent"), b.key) && !blockKeyIn(getAsyncPool(agent, "advisor"), b.key)
180
+ // #748:consult 子块按消费判据(会话在跑 ∥ 会话条目在 pending ⇒ 未消化)——与门控同源。
181
+ out.digested = consultChildKey(b.key)
182
+ ? !consultChildUndigested(agent, b.key)
183
+ : !blockKeyIn(agent._pendingAsyncResults, b.key)
184
+ && !blockKeyIn(getAsyncPool(agent, "subagent"), b.key) && !blockKeyIn(getAsyncPool(agent, "advisor"), b.key)
156
185
  }
157
186
  return out
158
187
  })
@@ -2,9 +2,11 @@
2
2
  * subagent-run.mjs — async spawn 执行器 executeAsyncSpawn(2026-09-05 module-split:
3
3
  * subagent.mjs 726 > 500 硬限——execute 的 async 分支 verbatim 迁入(闭包变量参数化:
4
4
  * parent/ctx/role/args + buildSpawnChild 产物),语义零变——subagent.mjs execute 调
5
- * 用(只此一处);§20 补位/排队刷新仍来自 subagent-scheduler.mjs。
5
+ * 用(只此一处);AGENT-LOOP-SUBAGENT.md §6.9 补位/排队刷新仍来自 subagent-scheduler.mjs。
6
6
  */
7
7
 
8
+ import { createHash } from "node:crypto"
9
+ import { basename } from "node:path"
8
10
  import { ASYNC_POOL_LIMITS, poolDomainOf, poolLimitsFor, runningPoolCount } from "./subagent-async.mjs"
9
11
  import { runChildPipeline } from "./subagent-async.mjs"
10
12
  import { logEvent } from "../log.mjs"
@@ -15,6 +17,12 @@ import {
15
17
  } from "./subagent-scheduler.mjs"
16
18
  // ASYNC-RESULT-CONTAINER.md D3/D6:settle 公共收尾单点 + child signal 构建单点
17
19
  import { bindChildController, buildChildSignal, settleAsyncEntry } from "./async-settle.mjs"
20
+ import { registerTurnCapCheckpoint } from "./checkpoint.mjs"
21
+
22
+ /** #309 任务书文本摘要(12 hex——**不留全文**,NF-L3 同族):条目自携与双点留痕的标识面。 */
23
+ function taskSeal(text) {
24
+ return createHash("sha256").update(String(text ?? "")).digest("hex").slice(0, 12)
25
+ }
18
26
 
19
27
  /**
20
28
  * SUBAGENT-OBSERVE-SEND D2:注入队列回合边界消费核心——把 entry._injected 全部消息按普通
@@ -32,12 +40,12 @@ export function drainInjectedQueue(entry, agent) {
32
40
  }
33
41
 
34
42
  /**
35
- * Async branch (AGENT-LOOP.md §15 D-A1/D-A6): spawn without waiting.
43
+ * Async branch (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1/D-A6): spawn without waiting.
36
44
  * The child runs the EXACT blocking pipeline (runChildPipeline — relay /
37
45
  * turn-cap / permission / MIN_REPORT_CHARS / mergeChildMutations all unchanged),
38
46
  * but the parent does not await it: the promise is parked in _asyncSubagents and
39
- * consumed by the auto channel (§19.8 — turn-end collection / suspension digest;
40
- * the check action is gone). Slot queue (§11.1 D-24a/R14 — 分域): the entry carries a
47
+ * consumed by the auto channel (AGENT-LOOP-SUBAGENT.md §6.7.5 — turn-end collection / suspension digest;
48
+ * the check action is gone). Slot queue (AGENT-LOOP-ASYNC-POOL.md §6.10 — D-24a/R14 分域): the entry carries a
41
49
  * pool domain (_pool = poolDomainOf(role)); running count < limit[its domain]
42
50
  * (agent.poolLimits — default engCoder 4 / other 4) → start now; ≥ → enqueue
43
51
  * (status "queued", position = queue index) — never rejected, never requiring the
@@ -57,35 +65,43 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
57
65
  consumeSubagentToken(parent, id, "async spawn", role)
58
66
  const entry = {
59
67
  id, role, relayPrefix,
60
- // §11.1 D-24a/R14:池域字段(域判定单一事实源——poolDomainOf——role 枚举见
68
+ // AGENT-LOOP-ASYNC-POOL.md §6.10 D-24a/R14:池域字段(域判定单一事实源——poolDomainOf——role 枚举见
61
69
  // subagent.mjs ROLES;未知角色归 other)——running 计数/补位按域过滤。
62
70
  _pool: poolDomainOf(role),
63
71
  status: "queued", // 下面按等待态/槽位重定(避免两处判断漂移)
64
72
  position: undefined,
65
73
  report: null, error: null, done: false, cancelled: false,
66
74
  promise: null, _settle: null, _settleSeq: 0,
67
- // §19.5 D-M5 可决策字段(status 数据装配锚点):model 在 spawn 时记录;
75
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-M5 可决策字段(status 数据装配锚点):model 在 spawn 时记录;
68
76
  // startedAt 在 ACTUAL start(queued 等待不计 elapsed);turn/maxTurns 由
69
77
  // 下方 onToken 拦截层从子代理 ⟦ev⟧turn 事件镜像(T-M18 正确性断言)。
70
78
  model: childProvider?.model ?? null,
71
79
  startedAt: null,
72
80
  turn: 0, maxTurns: 0,
73
- // §19.5 D-M6 (round2 #2):条目级 AbortController——cancel 定向 abort 本
81
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-M6 (round2 #2):条目级 AbortController——cancel 定向 abort 本
74
82
  // 条目(runAgent signal 链);Ctrl+C 全停语义不变(基信号 abort 逐链传播)。
75
83
  controller: null,
76
- // §20 D-SD2 域元数据(AGENT-LOOP.md §20):running ∪ queued 条目全带——
84
+ // D-SD2 域元数据(AGENT-LOOP-SUBAGENT.md §6.9):running ∪ queued 条目全带——
77
85
  // _files(归一化绝对路径)/ _dependsOn(字符串 id)——冲突检测与补位判据
78
86
  // 的事实源;无调度参数 spawn 两字段皆空(legacy——不参与冲突检测——零改动)。
79
87
  _files: files,
80
88
  _dependsOn: dependsOn,
89
+ // #309(AGENT-LOOP-SUBAGENT.md §6.29.2——可诊断性):条目**自携**绑定档与任务书摘要
90
+ // (启动路径按条目闭包取值——入队/补位不再有第二个取值面);`child:spawn` / `child:start`
91
+ // 双点同键面留痕(基名 + 摘要,零内容)——事后可对账「哪条任务书在哪个 id 下起跑」。
92
+ _batchDoc: child?._batchDoc ?? null,
93
+ _taskSeal: taskSeal(input),
81
94
  _lastQueuedSig: null, // ⟦ev⟧queued 去重 sig(refreshQueuedTokens)
82
95
  // SUBAGENT-OBSERVE-SEND D2:父侧 send 注入队列——父 action:'send' push 消息,子
83
96
  // 回合边界经 consumeInjected 回调消费(drain + pushReal 成 user 回合);settle 收尾
84
97
  // 时仍残留 = 未投递(消息入队后子在下一回合边界前 settle)→ 附 settle 报告提示。
85
98
  _injected: [],
86
99
  }
87
- // §20 D-SD3 准入落点:等待态(依赖未满足/域冲突/depc)→ queued(waiting-deps——
88
- // 不占槽不启动——即使槽空);纯槽满(kind slot)→ 按域计数判定(§11.1 D-24a:
100
+ // 留痕面基名(零内容——§6.29.2):绑定档绝对路径 → 基名;无绑定(非工程族)⇒ null(字段不落)。
101
+ const batchDocBase = entry._batchDoc ? basename(entry._batchDoc) : null
102
+
103
+ // AGENT-LOOP-SUBAGENT.md §6.9 D-SD3 准入落点:等待态(依赖未满足/域冲突/depc)→ queued(waiting-deps——
104
+ // 不占槽不启动——即使槽空);纯槽满(kind slot)→ 按域计数判定(§6.10 D-24a:
89
105
  // runningIn(domain) < limit(domain)——跨域互不阻塞——每次入池判定时读配置)。
90
106
  const blockers = describeBlockers(parent, entry)
91
107
  if (blockers.kind === "slot") {
@@ -97,15 +113,15 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
97
113
  }
98
114
  // The settle signal — resolves when the run chain settles (never rejects).
99
115
  entry.promise = new Promise((res) => { entry._settle = res })
100
- // §19.5 D-M6:条目 controller 链到会话/回合基信号(_sessionSignal 优先——
101
- // §17 挂起会话内 children 持会话 signal,digest 自身 Ctrl+C 不误伤)。
116
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-M6:条目 controller 链到会话/回合基信号(_sessionSignal 优先——
117
+ // AGENT-LOOP-ASYNC-POOL.md §6.8 挂起会话内 children 持会话 signal,digest 自身 Ctrl+C 不误伤)。
102
118
  // D6 buildChildSignal 单点(ASYNC-RESULT-CONTAINER.md)。
103
119
  const ctrl = new AbortController()
104
120
  entry.controller = ctrl
105
- // §20.3 站点 #10(第 24 批):hop 逐跳保 reason;#98 链结单点(interrupt 豁免面——
121
+ // AGENT-LOOP-SUBAGENT.md §6.12 站点 #10(第 24 批):hop 逐跳保 reason;#98 链结单点(interrupt 豁免面——
106
122
  // Ctrl+I 不逐链中止池内子代理)。
107
123
  bindChildController(ctrl, buildChildSignal(parent, ctx))
108
- // §19.5 D-M5:turn 镜像拦截层(callbacks 包装层——在既有
124
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-M5:turn 镜像拦截层(callbacks 包装层——在既有
109
125
  // wrapChildCallbacks 之外再包一层,只解析 ⟦ev⟧turn 更新条目,其余原样转发)。
110
126
  const trackOpts = { ...childOpts }
111
127
  const parentOnToken = trackOpts.onToken
@@ -118,7 +134,7 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
118
134
  }
119
135
  return parentOnToken(t)
120
136
  }
121
- // §27 R23 D-R23c1:嵌套 wrapper 标记随镜像层透传(wrapChildCallbacks 产物带
137
+ // docs/cli/design/TUI.md §6.8.2 R23 D-R23c1:嵌套 wrapper 标记随镜像层透传(wrapChildCallbacks 产物带
122
138
  // _relayPrefix——本层重包后丢失会让异步子代理(默认 async——depth-0)内嵌 spawn
123
139
  // 的生成侧补发射失效(emitNestedChildEvent 判据)——同步复制标记保语义)。
124
140
  trackOpts.onToken._relayPrefix = parentOnToken._relayPrefix ?? null
@@ -127,8 +143,8 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
127
143
  entry.status = "running"
128
144
  entry.position = undefined
129
145
  entry.startedAt = Date.now()
130
- // §19.5.6 D-SF1(round3 #1):绑定子代理对象引用——绑定时刻 = 实际启动时
131
- // (queued 条目 spawn-ack 时刻尚无子代理对象——§20 D-SD3b);绑定对象 = 子代理
146
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-SF1(round3 #1):绑定子代理对象引用——绑定时刻 = 实际启动时
147
+ // (queued 条目 spawn-ack 时刻尚无子代理对象——§6.9 D-SD3b);绑定对象 = 子代理
132
148
  // 对象(不是 _touchedFiles 数组引用——per-run 记账在 prepareRun 重置——数组
133
149
  // 引用会陈旧——对象引用保证 status 查询时实时读——杀前一刻最新)。
134
150
  entry.childAgent = child
@@ -139,7 +155,7 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
139
155
  // 持 entry + child;空队列 no-op(每轮尝试——零开销)。N2:不打断在跑工具——入队
140
156
  // 消息只在下一回合边界(当前工具完成后的下轮 chat 前)进上下文。
141
157
  const consumeInjected = (ag) => { drainInjectedQueue(entry, ag ?? child) }
142
- // §19.5 D-M7b ①: async 标记事件——零字段 ⟦ev⟧async token(sync 不发)。
158
+ // AGENT-LOOP-SUBAGENT.md §6.7.2 D-M7b ①: async 标记事件——零字段 ⟦ev⟧async token(sync 不发)。
143
159
  // 锚点 = 实际启动(与 [model] 同步——queued 入队不 paint,补位启动才发);
144
160
  // 先于 [model] 发出——区块创建即知 sub.async(routeSubToken 解析——
145
161
  // ⏹ 门控与头标 async 的判定源)。父级直接 emit(depth-0 专属路径——
@@ -147,19 +163,18 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
147
163
  ctx.callbacks?.onToken?.(relayPrefix + "⟦ev⟧async\x1e")
148
164
  // Deferred [model] emit: the TUI block is created at ACTUAL start.
149
165
  ctx.callbacks?.onToken?.(relayPrefix + "[model]" + (childProvider.model ?? ""))
150
- // Turn-cap on background children NEVER pops the continue panel (D-A3):
151
- // §15 D-A3 exception (2026-09-02 unified rule, AGENT-LOOP.md §2): in an
152
- // engineering && AUTO session the child auto-resumes — the user authorized
153
- // unattended runs, no one is at the panel. Every other tier auto-declines
154
- // and the partial-work report carries the cap reason. §18 D-E2 relies on
155
- // this exception as the turn-cap fallback for the default-async eng-coder
156
- // delivery (the internal protocol does not raise the 100-turn cap).
166
+ // #309 §6.29.2 双点留痕第二点(条目**实际启动点**——与 child:spawn 同键面):哪条任务书在哪个 id 下起跑。
167
+ logEvent("child:start", { role, id: `${role}#${id}`, batchDocBase, taskSeal: entry._taskSeal })
168
+ // Turn-cap on background children no longer auto-resumes (TURN-CAP-CONTINUE.md §1 #7 · 2026-09-26):
169
+ // a capped async child registers a parent-side checkpoint and stays suspended
170
+ // (no panel, no re-dispatch) until the parent answers send / cancel — AUTO included.
171
+ // The partial-work report carries TURN_CAP_MARK when the cap stopped the run.
157
172
  runChildPipeline(child, input, trackOpts, { ...childRunOpts, signal: entry.controller.signal, consumeInjected }, {
158
173
  parent, role, args,
159
- askContinue: () => Promise.resolve(Boolean(parent.config?.agent?.engineering && parent.autoApprove)),
174
+ askContinue: (e) => registerTurnCapCheckpoint(child, entry, { turn: e.turn, signal: entry.controller.signal }),
160
175
  })
161
176
  .then((report) => { entry.report = report })
162
- // §20.3 第 3 条合成器(第 24 批):原 message 前缀逐字保留 + 来源后缀
177
+ // §6.12 第 3 条合成器(第 24 批):原 message 前缀逐字保留 + 来源后缀
163
178
  .catch((err) => { entry.error = deathLine(err, entry.controller?.signal) })
164
179
  .finally(() => {
165
180
  // SUBAGENT-OBSERVE-SEND D3(send→settle 竞态):settle 收尾时 _injected 仍残留
@@ -187,11 +202,11 @@ export function executeAsyncSpawn(parent, ctx, role, args, child, input, childOp
187
202
  parent._asyncSubagents.set(String(id), entry)
188
203
  // LOGGING(LOGGING.md):child:spawn(async——注册即事件;status 记 queued/running 分流;
189
204
  // 实际启动由补位 start() 触发——运行中由子内 llm/tool 事件可见)
190
- logEvent("child:spawn", { role, id: `${role}#${id}`, kind: "async", status: entry.status, ms: 0 })
205
+ logEvent("child:spawn", { role, id: `${role}#${id}`, kind: "async", status: entry.status, ms: 0, batchDocBase, taskSeal: entry._taskSeal })
191
206
  if (entry.status === "queued") {
192
207
  parent._asyncQueue.push(entry)
193
208
  entry.position = parent._asyncQueue.length
194
- // §20 D-SD3b:排队 spawn 返回即建面板 waiting 块(⟦ev⟧queued 事件——spawn 侧
209
+ // §6.9 D-SD3b:排队 spawn 返回即建面板 waiting 块(⟦ev⟧queued 事件——spawn 侧
195
210
  // 发——TUI routeSubToken 消费建块/更新头;启动后 ⟦ev⟧async 转 running——同 key
196
211
  // 不重建)。refreshQueuedTokens 同时校正既有排队条目的位置/等待态头。
197
212
  refreshQueuedTokens(parent, ctx.callbacks?.onToken)
@@ -1,9 +1,9 @@
1
1
  /**
2
- * subagent-scheduler.mjs — §20 子 agent 任务调度器 + 文件域组(2026-09-05 自
3
- * subagent-async.mjs 拆分——Module Split Policy §20.9——纯迁移零行为变化——
4
- * AGENT-LOOP.md §20 D-SD1..SD5 + §21.1 D-SL1 环形死锁修正)。
2
+ * subagent-scheduler.mjs — 子 agent 任务调度器 + 文件域组(2026-09-05 自
3
+ * subagent-async.mjs 拆分——Module Split Policy——纯迁移零行为变化——
4
+ * AGENT-LOOP-SUBAGENT.md §6.9 D-SD1..SD5 + D-SL1 环形死锁修正)。
5
5
  * 内容:normalizeFileList / filesOverlap / effectiveFiles(SCHEDULER-DYNAMIC-DOMAIN
6
- * 动态域——声明 ∪ running touched)/ depInfo / describeBlockers / detectStall(§21.1
6
+ * 动态域——声明 ∪ running touched)/ depInfo / describeBlockers / detectStall(
7
7
  * P-SL2 停滞机械检测)/ queueRunnable / assertNoDepCycle / dependentLabels /
8
8
  * refreshQueuedTokens / maybeRefillAsync。
9
9
  * ASYNC_POOL_LIMITS/poolLimitsFor/runningPoolCount 回引自 subagent-async.mjs(主体保有——
@@ -24,7 +24,7 @@ import { poolLimitsFor, runningPoolCount, ASYNC_POOL_LIMITS } from "./subagent-a
24
24
  import { carrierField, getAsyncPool, tombstoneOf } from "./async-settle.mjs"
25
25
 
26
26
  // ═══════════════════════════════════════════════════════════════════════════
27
- // §20 子 agent 任务调度器(AGENT-LOOP.md §20——D-SD1..SD5 + 20.4 处置注)
27
+ // 子 agent 任务调度器(AGENT-LOOP-SUBAGENT.md §6.9——D-SD1..SD5)
28
28
  // 池条目域元数据(D-SD2:entry._files/_dependsOn——running ∪ queued 全带)、准入
29
29
  // (D-SD3:域冲突/依赖未满足 → queued 等位)、补位扫描(D-SD4:最早可启动——
30
30
  // 依赖全满足 + 域无冲突——waiting 越行不阻塞 slot 位)、释放规则(D-SD5——round2
@@ -35,14 +35,14 @@ import { carrierField, getAsyncPool, tombstoneOf } from "./async-settle.mjs"
35
35
 
36
36
  /** 文件域归一化(round1 #5——路径归一化再交集):相对 cwd 解析为绝对路径 + 去重;
37
37
  * 非字符串/空项静默跳过(声明错误 = false-negative 明示风险——v1 边界)。
38
- * §20.8 D-F1.1(2026-09-04):目录声明检测——fail-closed——尾斜杠形态 / 指向既有目录
38
+ * D-F1.1(2026-09-04):目录声明检测——fail-closed——尾斜杠形态 / 指向既有目录
39
39
  * → throw(含路径——错误字符串英文定稿)——目录声明静默绕过冲突检测的通道闭合;
40
40
  * 调用方(subagent.mjs spawn 入口)catch → 错误即工具结果(模型可见——无静默)。
41
- * 已知限制(§20.8 未编号段——评审 #4):不存在的目录声明(无尾斜杠 + 目录未创建)仍通过——不处理。
42
- * §28 R26 F-R26b(2026-09-07):父侧维护文件黑名单——归一化后 basename 全名匹配 +
41
+ * 已知限制(评审 #4):不存在的目录声明(无尾斜杠 + 目录未创建)仍通过——不处理。
42
+ * R26(2026-09-07):父侧维护文件黑名单——归一化后 basename 全名匹配 +
43
43
  * 大小写不敏感(todo.md/changelog.md 精确——路径任意层含 docs/、根、.thincoder/)——
44
44
  * 命中 → throw(fail-closed——先于调度器准入——无排队残留——错误即工具结果);
45
- * 提示列出全部违规条目——英文模板逐字定稿(AGENT-LOOP.md §28)。
45
+ * 提示列出全部违规条目——英文模板逐字定稿(AGENT-LOOP-SUBAGENT.md §6.9「父侧文件拦截(R26)」)。
46
46
  * M5 F6(2026-09-17):黑名单随同迁入 spawn-gates.mjs(rejectEngineeringFilePaths——族 = ledger.db / CHANGELOG + scripts/**;老台账 md 族随 M2 退役)——本函数只留调用(错误文案逐字保留)。 */
47
47
  export function normalizeFileList(files, cwd) {
48
48
  const out = []
@@ -102,7 +102,7 @@ export function effectiveFiles(e) {
102
102
  }
103
103
 
104
104
  /**
105
- * §20 依赖终态查询(单点事实——池条目 / pending(挂起期 settle 移交——注入前)/
105
+ * AGENT-LOOP-SUBAGENT.md §6.9 依赖终态查询(单点事实——池条目 / pending(挂起期 settle 移交——注入前)/
106
106
  * 终态墓碑(自动通道注入消费——consumed;取消/失败——D-SD5 分支)):
107
107
  * - ok = settle 成功(报告已产出)/ consumed(自动通道注入消费——T-SD14 视为满足)
108
108
  * - pending = running/queued 未终态(等启动/等完成)
@@ -131,7 +131,7 @@ export function depInfo(parent, id) {
131
131
  return { state: "unknown", role: null }
132
132
  }
133
133
 
134
- /** §20 等待态派生(无存储——refill/status/面板/spawn 返回同一事实源)。kind:
134
+ /** AGENT-LOOP-SUBAGENT.md §6.9 等待态派生(无存储——refill/status/面板/spawn 返回同一事实源)。kind:
135
135
  * - slot = 无阻塞(依赖全满足 + 域无冲突)——纯槽满等位(可启动——等 slot)
136
136
  * - wait = 依赖未完成 / 域冲突(running ∪ queued——D-SD3 同界——self 除外)
137
137
  * - depc = 依赖取消/失败(round2 #3——非 AUTO 锁住——需父显式处置;AUTO 视为可启动)
@@ -159,7 +159,7 @@ export function describeBlockers(parent, entry) {
159
159
  const hitDeclared = filesOverlap(myFiles, e._files ?? [])
160
160
  const hit = hitDeclared ?? filesOverlap(myFiles, effectiveFiles(e))
161
161
  if (!hit) continue
162
- // §21.1 D-SL1.2(环形死锁修正——与 queueRunnable 同界——展示一致):后入
162
+ // AGENT-LOOP-SUBAGENT.md §6.9 D-SL1.2(环形死锁修正——与 queueRunnable 同界——展示一致):后入
163
163
  // 者(spawn 序晚于我——数字 id 比较)不列——只列"会真正阻断我的"(running
164
164
  // 任意序 + 先入 queued);列后入者 = 误导"等一个其实等不到的人"。
165
165
  if (e.status === "queued" && Number(e.id) > Number(entry.id)) continue
@@ -176,7 +176,7 @@ export function describeBlockers(parent, entry) {
176
176
  return { kind: "slot", detail: "" }
177
177
  }
178
178
 
179
- /** §21.1 P-SL2(D-SL2——混合边环形等待停滞机械检测——AGENT-LOOP.md §21.1 扩展注):
179
+ /** P-SL2(D-SL2——混合边环形等待停滞机械检测——AGENT-LOOP-SUBAGENT.md §6.9):
180
180
  * 判据(收窄——零误报优先——宁可漏报不可误打断):池内 running = 0 && queued ≥ 2 &&
181
181
  * 无 dependency-cancelled 标记条目 && 每 queued 的 blocker(files 冲突者 + 未 settle
182
182
  * 依赖目标——与 describeBlockers/queueRunnable 同界——"真正会阻断我的"语义:files 只
@@ -185,13 +185,13 @@ export function describeBlockers(parent, entry) {
185
185
  * 条目一条阻塞链——沿首个 blocker 走到首个重复节点(闭环)——每节点自带"等谁 + 为何等"
186
186
  * 理由注(`X(reason) → Y` 形态——X 等 Y 因 reason);不满足 → null。
187
187
  * 不报(F-SL2.2 收窄判据):running 锚点存在(依赖链/文件串行正常排队);depc 滞留
188
- * (外部决策可解——§20 NF-SD 滞留有意——cancel 先入者即释放);单 queued;blocker
188
+ * (外部决策可解——§6.9 NF-SD 滞留有意——cancel 先入者即释放);单 queued;blocker
189
189
  * 外逃(unknown 依赖目标/池外条目);blocker 空(runnable——settle/cancel 驱动 refill
190
190
  * 会启动——非停滞)。自然流程中 wait 边恒指向先入者(依赖必须先前 spawn——unknown 拒 +
191
191
  * 文件冲突只阻断后入者——id 序)——混合环仅人工注入可构造(T-SD5 同族防御断言)——
192
192
  * 但状态既可能成环即机械可检——不依赖可达性论证。maybeRefillAsync 空转处不调用:refill
193
193
  * 嵌在 settle/cancel 链上无模型可见输出通道(抛错即破坏池操作)——status 视图(actions
194
- * 模块)即 F-SL2 的报错/标记落点(§19.8:check 守卫随 check 删除)。 */
194
+ * 模块)即 F-SL2 的报错/标记落点(AGENT-LOOP-SUBAGENT.md §6.7.5:check 守卫随 check 删除)。 */
195
195
  export const STALL_NOTE = "cancel one task in the loop (action:'cancel') to break the cycle, then re-spawn it"
196
196
 
197
197
  export function detectStall(parent) {
@@ -239,7 +239,7 @@ export function detectStall(parent) {
239
239
  }
240
240
  // 链组装:每 queued 条目一条——沿首个 blocker 走到首个重复节点(闭环)——每节点
241
241
  // 自带"我等谁 + 为何等"段(`X(reason) → Y`——本节点 blocker 理由注于本节点旁——
242
- // 读取无歧义:X 等 Y 因为 reason——dependsOn 边不误读为目标属性——§21.1 扩展注
242
+ // 读取无歧义:X 等 Y 因为 reason——dependsOn 边不误读为目标属性——§6.9 扩展注
243
243
  // 示例同信息形态——闭环以起始节点重复闭合(末节点不再注——闭合自明)。
244
244
  const chains = []
245
245
  for (const start of queued) {
@@ -271,10 +271,10 @@ export function entryTerminal(entry) {
271
271
  return entry?.cancelled === true || entry?.done === true
272
272
  }
273
273
 
274
- /** §20 D-SD4 补位判据:依赖全满足(AUTO 下 depc 放行)+ 域无冲突(running 任意序 +
275
- * queued 先入者——§21.1 D-SL1.1 序判定:同文件串行 = 先入者先启动、后入者等先入者
274
+ /** AGENT-LOOP-SUBAGENT.md §6.9 D-SD4 补位判据:依赖全满足(AUTO 下 depc 放行)+ 域无冲突(running 任意序 +
275
+ * queued 先入者——§6.9 D-SL1.1 序判定:同文件串行 = 先入者先启动、后入者等先入者
276
276
  * ——不自锁;先入者启动后以 running 身份继续挡住后入者——self 除外)。
277
- * 已知限制(§21.1 评审 #4——与 §20 NF-SD 同语义——滞留有意义不静默):先入者被
277
+ * 已知限制(§6.9 评审 #4——与 §6.9 NF-SD 同语义——滞留有意义不静默):先入者被
278
278
  * depc 锁定时(依赖取消/失败且非 AUTO——永不自动启动),后入者滞留等它——cancel
279
279
  * 先入者即释放(父显式可清;AUTO 档 depc 视为可启动——不滞留)。 */
280
280
  export function queueRunnable(parent, entry) {
@@ -292,7 +292,7 @@ export function queueRunnable(parent, entry) {
292
292
  if (e === entry) continue
293
293
  if (e.status !== "running" && e.status !== "queued") continue
294
294
  if (!filesOverlap(myFiles, effectiveFiles(e))) continue // 动态域:声明 ∪ running touched
295
- // §21.1 D-SL1.1 序判定:queued 仅"先入者"(spawn 序早于我——数字 id 比较)阻断;
295
+ // §6.9 D-SL1.1 序判定:queued 仅"先入者"(spawn 序早于我——数字 id 比较)阻断;
296
296
  // 后入者不阻断——先入者先启动——两个 queued 同文件不再互等(环形死锁修正)。
297
297
  // 防御(评审 #3——id 形态):池条目 id 为数字递增(_subAgentCounter——已核实);
298
298
  // 异常形态 Number() 得 NaN → 比较 false → 不跳过 → 保守阻断(宁可多等——
@@ -304,7 +304,7 @@ export function queueRunnable(parent, entry) {
304
304
  return true
305
305
  }
306
306
 
307
- /** §20 D-SD5 环防御(round2 #5——自然流程不可达:unknown id 拒 + spawn 序天然无环——
307
+ /** §6.9 D-SD5 环防御(round2 #5——自然流程不可达:unknown id 拒 + spawn 序天然无环——
308
308
  * 仅人工向池注入可构造——防御断言定位):从新 spawn 的依赖集出发沿池内条目
309
309
  * _dependsOn 边做路径 DFS——路径上重复访问(可达环)→ 拒绝(A→B→A 永不自启——
310
310
  * 错误明确——T-SD5)。运行/排队条目皆可成环节点;池小(≤4 槽 + 有限队列)深度有限。 */
@@ -337,7 +337,7 @@ export function dependentLabels(parent, depId) {
337
337
  return out
338
338
  }
339
339
 
340
- /** §20 D-SD3b 排队态面板刷新(⟦ev⟧queued 事件族——TUI routeSubToken 消费):对全部
340
+ /** §6.9 D-SD3b 排队态面板刷新(⟦ev⟧queued 事件族——TUI routeSubToken 消费):对全部
341
341
  * queued 条目重算等待态并发射变化(去重 sig——kind/position/detail 全变才发)——
342
342
  * 调用点 = 一切队列突变与等待态变迁(spawn 入队 / settle 后补位与依赖转移 / cancel
343
343
  * 出队 / 自动通道消费)。position = 队列序(D-A1 既有——cancel 前移同源)。
@@ -362,12 +362,11 @@ export function refreshQueuedTokens(parent, onToken) {
362
362
  }
363
363
 
364
364
  /**
365
- * Slot-queue refill (AGENT-LOOP.md §15 D-A1/D-A6 + §20 D-SD4 + §11.1 D-24a/R14 分域):
365
+ * Slot-queue refill (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1/D-A6 + §6.9 D-SD4 + AGENT-LOOP-ASYNC-POOL.md §6.10 D-24a/R14 分域):
366
366
  * start queue heads while a running slot is free — called from every settle
367
- * (completion frees a slot) and from the turn-end collection's refill loop. §20:
368
- * 队列现可混合 waiting-deps 与 slot-queued——扫描选"依赖全满足 + 域无冲突"的最早
367
+ * (completion frees a slot) and from the turn-end collection's refill loop. 队列现可混合 waiting-deps 与 slot-queued——扫描选"依赖全满足 + 域无冲突"的最早
369
368
  * 条目启动(waiting 越行不阻塞槽位;多任务同时解除按 queued 序逐个启动)。
370
- * §11.1 D-24a(R14):槽位判定按域——条目 _pool 域内 running 数 < 该域上限才启动
369
+ * D-24a/R14(分域):槽位判定按域——条目 _pool 域内 running 数 < 该域上限才启动
371
370
  * (同域仍 4——纯单域队列行为与旧 shift 完全一致;跨域总量 8——各域独立腾槽,
372
371
  * 互不阻塞)。配置每次补位时读(poolLimitsFor——变更即生效下个补位)。
373
372
  */
@@ -397,13 +396,15 @@ export function maybeRefillAsync(parent) {
397
396
  * next = max(counter ?? 0, poolMax) + 1——取号后 counter 同步(首取号初始化)。id 作用
398
397
  * 域 = 进程内(不做槽持久化——reload 后池清块消失,新进程从 1 无冲突——设计范围边界)。
399
398
  * spawn(subagent-spawn.mjs async 分支)、escalate(escalate-async.mjs)、async-advisor
400
- * 池(advisor-async.mjs——§11.2 跨池共号)共用;executeAsyncSpawn 直读 counter(分配与
399
+ * 池(advisor-async.mjs——§6.10 跨池共号)、**后台 bash 任务池**(bash-async.mjs——#9:
400
+ * `_bgTasks` 同入扫描域——VSC 形计数器不随 run 存活,缺此扫描会与在途 bg 条目撞号)共用;
401
+ * executeAsyncSpawn 直读 counter(分配与
401
402
  * 消费同步——无 await 间隙)。CLI 两池键均为字符串(set(String(id))——解析分支防御保留)。
402
403
  * @returns {number} 全池唯一的下一 id(单调——进程内)
403
404
  */
404
405
  export function nextSubagentId(parent) {
405
406
  let poolMax = 0
406
- for (const pool of [carrierField(parent, "_asyncSubagents"), carrierField(parent, "_asyncAdvisors")]) {
407
+ for (const pool of [carrierField(parent, "_asyncSubagents"), carrierField(parent, "_asyncAdvisors"), carrierField(parent, "_bgTasks")]) {
407
408
  if (!pool || pool.size === 0) continue
408
409
  for (const k of pool.keys()) {
409
410
  const n = typeof k === "number" ? k : Number.parseInt(k, 10)