thincoder 0.12.81 → 0.12.82

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.
@@ -23,11 +23,14 @@
23
23
  * End-of-turn is NOT a notification: `session/prompt` resolves with
24
24
  * `{ stopReason: "end_turn" }` (kimi session.ts parity).
25
25
  */
26
- import { detectDanger, normalizeEOL, joinWithEol, resolveInCwd } from "@thincoder/core/tools/shared.mjs"
27
- import { computeEditEntry, validateEditEntry, assertEditArgsExclusive, assertEditsContainer, assertEditEntries, hasLineParams, planEditEntries, applyPlannedEntries, deleteTarget, EDIT_ENTRY_NO_PATH, editEntryLabel } from "@thincoder/core/tools/edit-diff.mjs"
28
- // 行号锚护栏(EDIT-HELPERS §7):桥不经 writeThroughPath ⇒ 判据与记账都得在桥面接(§7.4)。
29
- // 判据 / 拒文 = 核单源;记账 = 写缓冲成功后桥自 recordWrite,键 = resolveInCwd 后的绝对路径。
30
- import { recordWrite, lineAnchorVerdict, lineAnchorRefusal } from "@thincoder/core/tools/write-path.mjs"
26
+ import { detectDanger } from "@thincoder/core/tools/shared.mjs"
27
+ import { hasLineParams } from "@thincoder/core/tools/edit-diff.mjs"
28
+ // 行号锚护栏(EDIT-HELPERS §3):桥不经 writeThroughPath ⇒ 判据与记账都得在桥面接(§4)。
29
+ // 判据 / 拒文 = 核单源(住 `buffered-edit.mjs`);记账 = 写缓冲成功后 recordWrite,键 = resolveInCwd 后的绝对路径。
30
+ import { recordWrite } from "@thincoder/core/tools/write-path.mjs"
31
+ // IDE 缓冲编辑面(2026-11-05 拆档族):`absOf` ∥ `editSingle` ∥ `editBatch` 三件住同目录兄弟档,
32
+ // 本档按工厂造一次、把四个 IO 缝递进去——判据 ∥ 回执零变。
33
+ import { makeBufferedEditFace } from "./buffered-edit.mjs"
31
34
  // 第 27 批 §12.3①/③:relay 前缀文法单一权威(模块直连——不自持正则副本)。
32
35
  import { parseRelayPath } from "@thincoder/core/agent/relay-prefix.mjs"
33
36
  // 批 1 CORE-DEFECT-FIXES B3:onWait 相位值域 + 文案单源(本面仅日志——PROVIDER.md §6.20)
@@ -135,8 +138,9 @@ export function buildAcpCallbacks({ sessionId, agent, notify, request, log = ()
135
138
 
136
139
  // §15.1(TOOLS.md)D15.7 委派:edit 判定/应用单一权威 = 本地 computeEditEntry
137
140
  // (edit-diff.mjs——校验→判定序→应用:行级 LCS、零重叠→替换即删、replace_all 字面替换全部)。
138
- // 桥只留「读 IDE 缓冲 → computeEditEntry → 写回 IDE 缓冲」——错误文本经抛错原样透传
139
- // ——与本地通道逐字一致(NF15.6b / AC15.10:not found / occurrences / 空 old / 空 new)。
141
+ // 编辑链本体(读缓冲 → 行号锚护栏 → 纯函数判定 → 写回 → 记账)2026-11-05 外移 `./buffered-edit.mjs`:
142
+ // 那三件原是本函数体内的闭包,改装成工厂注入四个 IO 缝(本文件的 `readBuffer` / `writeBuffer` /
143
+ // `pathOf` + `agent`)——链体逐字搬家,错误文本仍经抛错原样透传(NF15.6b / AC15.10)。
140
144
 
141
145
  // 不变量(§11.7-2):**任何** fs/* 反向 RPC 发出前必过客户端能力位——守卫住在本函数内
142
146
  // (防御面:路由分支先判,守卫兜底,漏判不发静默超时)。
@@ -157,107 +161,9 @@ export function buildAcpCallbacks({ sessionId, agent, notify, request, log = ()
157
161
  throw new Error(`fs/write_text_file failed: ${e.message}`)
158
162
  }
159
163
  }
160
- /** 记账键(§7.4):与核同一键 = `resolveInCwd` 后的绝对路径——键不一致则核与桥各记一条、
161
- * 互相看不见,护栏对另一条通道等于零。 */
162
- const absOf = (p) => resolveInCwd({ cwd: agent?.cwd ?? process.cwd() }, p)
163
- /** 单形态:读 IDE 缓冲 → 行号锚护栏判定 → computeEditEntry(rich——无 abortPrefix——同本地
164
- * runSingleEdit)→ 写回 → 记账。EOL 权威(F1):判定/应用在 normalizeEOL 后的 LF 域;写回
165
- * joinWithEol 按原文首换行恢复(LF 域判定——CRLF 域写回——与本地 edit 工具同判同恢复)。 */
166
- const editSingle = async (p, args) => {
167
- const raw = await readBuffer(p)
168
- const content = normalizeEOL(raw)
169
- const abs = absOf(p)
170
- // 行号锚护栏(§7.4):行号形才需判——内容形态是位置无关寻址,没有可漂移的锚。
171
- // 形态校验先于护栏(与核 runSingleEdit 同序):缺 endLine / 与 old_string 互斥报自己的句。
172
- if (hasLineParams(args)) {
173
- validateEditEntry(args, { rich: true })
174
- const startLine = args.line ?? args.startLine
175
- const endLine = args.line ?? args.endLine
176
- if (lineAnchorVerdict(abs, startLine, endLine)) throw new Error(lineAnchorRefusal(abs, startLine, endLine))
177
- }
178
- const out = computeEditEntry(content, args, { path: p, absPath: abs })
179
- await writeBuffer(p, joinWithEol(normalizeEOL(out.updated).split("\n"), raw))
180
- // 缓冲写回**成功之后**记账(快照对同一坐标系有效——缓冲与盘面可能不同步,行号语义跟的是缓冲)
181
- recordWrite(abs, { type: "edit", startLine: out.editStartLine, shift: out.lineShift })
182
- // 逐条回执(§7.4「单形态删行不经桥」):单形态经桥恒为确认形——路由门要求单形态的
183
- // `new_string` 是字符串,而删行只在**省略**它时成立 ⇒ 单形态删行走不到这里(落本地通道,
184
- // 回执 = 核面 `Deleted line N of <path>`),桥面的删行回执只来自 `edits` 数组形态(editBatch)。
185
- // 不留删行分支:为没出现过的输入加分支 = 加一条没人走的路,且它会让下一个读这里的人
186
- // 以为单形态删行走 IDE 缓冲(实测不走);放宽路由门是行为变更,没人要求过。
187
- return `OK: edited ${p} via IDE (${out.occurrences} occurrence(s))${out.note ? ` — ${out.note}` : ""}`
188
- }
189
- /** 数组形态(D15.7):守卫与文案单源 = 本地 edit-diff(assertEditsContainer / assertEditEntries /
190
- * validateEditEntry——EDIT.md §8 D-7:核 edit-batch 与桥同调用、桥零字面副本)→
191
- * 读全部涉及文件缓冲(按绝对路径去重——一次读)→ 用批前快照判一次 → **帧调同一对纯函数**
192
- * (planEditEntries / applyPlannedEntries,R1–R4;不另写组循环)→ 全部通过 → 逐文件写回
193
- * 一次并同记账(判失败 → 零写;写失败 → 同本地 edit-batch 既有原子语义)。 */
194
- /** ACP batch-edit 通道——与 EDIT.md:#796 汇总行体系**无关**。
195
- * 桥面 `prepared.map(...).join("\\n")` 自持逐条文字行,不经 `applyEditBatch`/`diffLines`/offload;
196
- * 距 64K offload 阈值远 + 不含 diff 结构 ⇒ 不在 offload 盲区范围。**判定:非 #796 射程(#908)**。
197
- */
198
- const editBatch = async (args) => {
199
- const edits = args.edits
200
- assertEditsContainer(edits)
201
- assertEditArgsExclusive(args)
202
- assertEditEntries(edits)
203
- const groups = new Map() // abs → { abs, path, raw, content, edits, origIdx }
204
- for (let i = 0; i < edits.length; i++) {
205
- const e = edits[i]
206
- // 2026-09-05 用户裁定(CLI parity——本地 edit-batch 同句):条目自带 path 优先;
207
- // 缺省回退顶层 path(pathOf——path/filePath 别名同单形态)
208
- const p = e.path || pathOf(args) // 同核 edit-batch 的兜底判(`||` 而非 `??`——空串也回落顶层)
209
- if (!p) throw new Error(EDIT_ENTRY_NO_PATH)
210
- validateEditEntry(e, { label: editEntryLabel(p), rich: false })
211
- const abs = absOf(p)
212
- let g = groups.get(abs)
213
- if (!g) {
214
- g = { abs, path: p, raw: "", content: "", edits: [], origIdx: [] }
215
- groups.set(abs, g)
216
- }
217
- g.edits.push(e)
218
- g.origIdx.push(i) // 条目在 `edits` 数组里的原始下标——回显按它回位(§7.3)
219
- }
220
- for (const g of groups.values()) {
221
- g.raw = await readBuffer(g.path)
222
- g.content = normalizeEOL(g.raw)
223
- }
224
- // 判定点(§7.3 同核):组循环之前用**批前快照**判一次——命中即抛、零写
225
- for (const g of groups.values()) {
226
- for (const e of g.edits) {
227
- if (!hasLineParams(e)) continue
228
- const startLine = e.line ?? e.startLine
229
- const endLine = e.line ?? e.endLine
230
- if (lineAnchorVerdict(g.abs, startLine, endLine)) throw new Error(lineAnchorRefusal(g.abs, startLine, endLine))
231
- }
232
- }
233
- // 帧单源:调 §7.3 的同一对零 IO 纯函数——桥只做「读缓冲 → 应用计划 → 写缓冲」。
234
- // 回显按调用序 = 按条目的**原始下标**回填(§7.3):跨文件交错的批若按文件分组去排会排成
235
- // A、A、B——模型按位置对号入座,顺序一变它会把结果贴到错的那一笔上。
236
- const prepared = new Array(edits.length)
237
- for (const g of groups.values()) {
238
- const plan = planEditEntries(g.edits, g.path)
239
- if (plan.rejection) throw new Error(plan.rejection)
240
- const applied = applyPlannedEntries(g.content, g.edits, plan.order, { path: g.path })
241
- g.content = applied.content
242
- g.netShift = applied.results.reduce((n, r) => n + r.lineShift, 0)
243
- // results 按组内调用序;g.origIdx 给出它在这一组里的下标对应的原始下标
244
- applied.results.forEach((r, k) => { prepared[g.origIdx[k]] = { g, ...r } })
245
- }
246
- for (const g of groups.values()) {
247
- await writeBuffer(g.path, joinWithEol(normalizeEOL(g.content).split("\n"), g.raw))
248
- // 写缓冲成功后记账:合并快照 startLine = 组内最小、shift = 组内净漂移(同核批量语义)
249
- const startLine = Math.min(...prepared.filter((p) => p.g === g).map((p) => p.editStartLine))
250
- recordWrite(g.abs, { type: "edit", startLine, shift: g.netShift })
251
- }
252
- // 逐条回执同单形态(§7.4):删行条目写 `Deleted <line N|lines N-M> of <path> via IDE`,
253
- // 行号段取同一 `deleteTarget`;替换条目保持确认形。核面的 diff / `context (L…-L…)` /
254
- // 批末汇总行桥面不写(那三样读盘面内容或起外部进程,缓冲与盘面可能不同步)。
255
- return prepared
256
- .map((o) => (o.deleted
257
- ? `Deleted ${deleteTarget(o)} of ${o.g.path} via IDE`
258
- : `OK: edited ${o.g.path} via IDE (${o.occurrences} occurrence(s))${o.note ? ` — ${o.note}` : ""}`))
259
- .join("\n")
260
- }
164
+ // 编辑面三件(`absOf` ∥ `editSingle` ∥ `editBatch`):判据与回执住 `./buffered-edit.mjs`,本处只把四个
165
+ // 常量闭包当作 IO 缝递进去(唯一调用点就在本作用域内,实参恒在)。
166
+ const { absOf, editSingle, editBatch } = makeBufferedEditFace({ agent, readBuffer, writeBuffer, pathOf })
261
167
 
262
168
  const callbacks = {
263
169
  onToken: (text) => {
@@ -400,7 +306,7 @@ export function buildAcpCallbacks({ sessionId, agent, notify, request, log = ()
400
306
  const content = args.content
401
307
  try {
402
308
  await request("fs/write_text_file", { sessionId, path, content }, { timeoutMs: 30000 })
403
- // 全文重写也是「我们写的」——与核 writeTool 同型记账(§7.1 第 3 行:之后任何行号形拒)。
309
+ // 全文重写也是「我们写的」——与核 writeTool 同型记账(§3 第 3 行:之后任何行号形拒)。
404
310
  // 不记这一格,同一份漂移就成了「本地拒、IDE 缓冲放」。
405
311
  recordWrite(absOf(path), { type: "write", startLine: 1, shift: 0 })
406
312
  return { handled: true, result: `OK: wrote ${path} via IDE` }
@@ -0,0 +1,217 @@
1
+ /**
2
+ * buffered-edit.mjs — IDE 缓冲编辑面(读缓冲 → 行号锚护栏 → 纯函数判定 → 写回 → 记账)。
3
+ *
4
+ * 2026-11-05 拆档族从 `bridge.mjs` 外移:`absOf` / `editSingle` / `editBatch` 三者原是
5
+ * `buildAcpCallbacks` 体内的闭包,依赖四个同作用域闭包(`agent` ∥ `readBuffer` ∥ `writeBuffer` ∥
6
+ * `pathOf`)——裸搬会把 `request` 与 sessionId 一并带走,故改为**工厂形注入**:IO 缝由调用方给,
7
+ * 链体逐字搬家。
8
+ *
9
+ * 判据与回执:edit 判定/应用单一权威仍是本地 `edit-diff.mjs` 的 `computeEditEntry` /
10
+ * `planEditEntries` / `applyPlannedEntries`——本档零字面副本;行号锚护栏的判据与拒文仍是核单源
11
+ * `write-path.mjs`;批级回执的两件文案单源 `edit-receipt.mjs`(与核同调、零字面副本);
12
+ * 记账键 = `resolveInCwd` 后的绝对路径(与核同一键)。
13
+ *
14
+ * **批量口径与核批面同一**(`docs/core/design/EDIT.md` §2「匹配与应用」):逐条成败、逐档一次写回、批内零回滚。
15
+ *
16
+ * 依赖单向:`本档 ← bridge.mjs`(本档不 import `bridge.mjs`)。
17
+ */
18
+ import { normalizeEOL, joinWithEol, resolveInCwd } from "@thincoder/core/tools/shared.mjs"
19
+ import { computeEditEntry, validateEditEntry, assertEditArgsExclusive, assertEditsContainer, hasLineParams, planEditEntries, applyPlannedEntries, deleteTarget, EDIT_ENTRY_NO_PATH, editEntryLabel, editsEntryError } from "@thincoder/core/tools/edit-diff.mjs"
20
+ // 行号锚护栏(`EDIT-HELPERS.md` §3「行号锚」):桥不经 writeThroughPath ⇒ 判据与记账都得在桥面接(同节)。
21
+ // 判据 / 拒文 = 核单源;记账 = 写缓冲成功后桥自 recordWrite,键 = resolveInCwd 后的绝对路径。
22
+ import { recordWrite, lineAnchorVerdict, lineAnchorRefusal } from "@thincoder/core/tools/write-path.mjs"
23
+ // 批级回执两件文案(逐条失败行 ∥ 末行汇总)单源 = edit-receipt.mjs(`EDIT-HELPERS.md` §4「批量帧」):
24
+ // 核批面与桥面同调用——两工具一副骨架,改一处就同时改到另一处。
25
+ import { editEntryFailureLine, editBatchSummary } from "@thincoder/core/tools/edit-receipt.mjs"
26
+
27
+ /**
28
+ * 造一个 IDE 缓冲编辑面。
29
+ * @param {{ agent: object, readBuffer: (p: string) => Promise<string>,
30
+ * writeBuffer: (p: string, content: string) => Promise<void>,
31
+ * pathOf: (args: object) => string|null }} deps
32
+ * `agent` = 会话的活引用(取 `cwd`);`readBuffer` / `writeBuffer` = 客户端 fs 反向 RPC 的两件闭包
33
+ * (各带自己的能力位守卫——本档只 issue);`pathOf` = `args.path ?? args.filePath` 的取值闭包
34
+ * (数组形态里条目缺 path 时回落到顶层 path 的判据靠它)。
35
+ * @returns {{ absOf: (p: string) => string, editSingle: Function, editBatch: Function }}
36
+ */
37
+ export function makeBufferedEditFace({ agent, readBuffer, writeBuffer, pathOf }) {
38
+ /** 记账键(`EDIT-HELPERS.md` §3「行号锚」):与核同一键 = `resolveInCwd` 后的绝对路径——键不一致则核与桥各记一条、
39
+ * 互相看不见,护栏对另一条通道等于零。 */
40
+ const absOf = (p) => resolveInCwd({ cwd: agent?.cwd ?? process.cwd() }, p)
41
+ /** 单形态:读 IDE 缓冲 → 行号锚护栏判定 → computeEditEntry(rich——同本地 runSingleEdit)→
42
+ * 写回 → 记账。EOL 权威(F1):判定/应用在 normalizeEOL 后的 LF 域;写回
43
+ * joinWithEol 按原文首换行恢复(LF 域判定——CRLF 域写回——与本地 edit 工具同判同恢复)。 */
44
+ const editSingle = async (p, args) => {
45
+ const raw = await readBuffer(p)
46
+ const content = normalizeEOL(raw)
47
+ const abs = absOf(p)
48
+ // 行号锚护栏(`EDIT-HELPERS.md` §3「行号锚」):行号形才需判——内容形态是位置无关寻址,没有可漂移的锚。
49
+ // 形态校验先于护栏(与核 runSingleEdit 同序):缺 endLine / 与 old_string 互斥报自己的句。
50
+ if (hasLineParams(args)) {
51
+ validateEditEntry(args, { rich: true })
52
+ const startLine = args.line ?? args.startLine
53
+ const endLine = args.line ?? args.endLine
54
+ if (lineAnchorVerdict(abs, startLine, endLine)) throw new Error(lineAnchorRefusal(abs, startLine, endLine))
55
+ }
56
+ const out = computeEditEntry(content, args, { path: p, absPath: abs })
57
+ await writeBuffer(p, joinWithEol(normalizeEOL(out.updated).split("\n"), raw))
58
+ // 缓冲写回**成功之后**记账(快照对同一坐标系有效——缓冲与盘面可能不同步,行号语义跟的是缓冲)
59
+ recordWrite(abs, { type: "edit", startLine: out.editStartLine, shift: out.lineShift })
60
+ // 单形态回执说真话(EDIT.md §3「写与桥」):路由门要求单形态的 `new_string` 是字符串,而空串也是字符串
61
+ // ⇒ 行号形 + 空串改后确实走到这里,且它的结局是一次删除——继续印 `OK: edited` 就是把删除
62
+ // 说成替换。两路同一措辞:`Deleted <line N|lines N-M> of <path>`(行号段 = 同一 `deleteTarget`)。
63
+ return out.deleted
64
+ ? `Deleted ${deleteTarget(out)} of ${p}`
65
+ : `OK: edited ${p} via IDE (${out.occurrences} occurrence(s))${out.note ? ` — ${out.note}` : ""}`
66
+ }
67
+ /** 数组形态:与核批面同一条六段流水线(EDIT.md §2「匹配与应用」)——
68
+ * ① 容器守卫整批拒 → ② 分组(非对象条目 ∥ 缺 path ∥ 条目校验不过 ⇒ 该条失败、不进组)→
69
+ * ③ 逐档读缓冲(读不到连坐该档)→ ④ 行号锚护栏逐条判(命中只废那一条)→
70
+ * ⑤ 帧排 + `onEntryError:"collect"` 累积(重叠两条互指、各得一行)→
71
+ * ⑥ 有 ≥1 条成功的档写缓冲一次并记合并快照;零成功的档不写不记账,写缓冲抛错只连坐该档。
72
+ *
73
+ * **两段结构保留、不拆**:`readBuffer` / `writeBuffer` 指 IDE 文档缓冲(传输事实),不是暂存区;
74
+ * 变的是第一段的身份——从「全过才写的闸」变成逐条判定点。桥的 IO 缝与消息契约字段零改。
75
+ *
76
+ * 回执三形(EDIT.md §2「匹配与应用」):成功行保持桥面现措辞;失败行与末行与核同一构造器;末行汇总行桥面
77
+ * 照写——它的数字(条目总数 / 成功条数 / 已写档数与路径)全在内存里,没有宿主能力依据可以挡它。
78
+ * 桥面不写的三样仍是 diff ∥ 语法检查 ∥ 写入点上下文(它们都读盘面内容或起外部进程)。
79
+ *
80
+ * ACP batch-edit 通道**不进 offload 面**:回执自持逐条文字行,不含 diff 结构。
81
+ */
82
+ const editBatch = async (args) => {
83
+ const edits = args.edits
84
+ assertEditsContainer(edits) // ① 容器成形错 = 整批拒(经 toolRouter catch 渲染 `Error: <msg>`)
85
+ assertEditArgsExclusive(args)
86
+ const total = edits.length
87
+ // 每条一个结局:{ ok:true, g, out } ∥ { ok:false, reason }。回执只在全部写回之后组装——
88
+ // 档级写失败要把该档已算成的条改判为失败(「该档写不成就整档不成」)。
89
+ const state = new Array(total)
90
+ const fail = (i, reason) => { state[i] = { ok: false, reason } }
91
+ const groups = new Map() // abs → 每档一条流水线
92
+
93
+ // ② 分组(同核批面判据):非对象条目 = **该条**成形错(文案单源 editsEntryError(i)),不进组
94
+ for (let i = 0; i < total; i++) {
95
+ const e = edits[i]
96
+ if (e === null || typeof e !== "object" || Array.isArray(e)) { fail(i, editsEntryError(i)); continue }
97
+ // 2026-09-05 用户裁定(CLI parity——本地 edit-batch 同句):条目自带 path 优先;
98
+ // 缺省回退顶层 path(pathOf——path/filePath 别名同单形态)
99
+ const p = e.path || pathOf(args) // 同核 edit-batch 的兜底判(`||` 而非 `??`——空串也回落顶层)
100
+ if (!p) { fail(i, EDIT_ENTRY_NO_PATH); continue }
101
+ try {
102
+ // 成形错 ∥ 空串 ∥ 互斥 ∥ 行号非法:都只废这一条(scope:"batch" ⇒ 文本不带写盘结论)
103
+ validateEditEntry(e, { label: editEntryLabel(p), scope: "batch" })
104
+ } catch (err) {
105
+ fail(i, err.message)
106
+ continue
107
+ }
108
+ const abs = absOf(p)
109
+ let g = groups.get(abs)
110
+ if (!g) {
111
+ g = { abs, path: p, raw: "", content: "", readError: null, entries: [], idx: [], written: false }
112
+ groups.set(abs, g)
113
+ }
114
+ g.entries.push(e)
115
+ g.idx.push(i) // 条目在 `edits` 数组里的原始下标——回显按它回位(`EDIT-HELPERS.md` §4「批量帧」)
116
+ }
117
+
118
+ // ③ 逐档读一次缓冲(读不到 ⇒ 该档所有条失败——原因取读错误原文)
119
+ for (const g of groups.values()) {
120
+ try {
121
+ g.raw = await readBuffer(g.path)
122
+ g.content = normalizeEOL(g.raw)
123
+ } catch (err) {
124
+ g.readError = err.message
125
+ for (const i of g.idx) fail(i, g.readError)
126
+ }
127
+ }
128
+
129
+ // ④ 行号锚护栏(判定点同核:批前快照逐条判——命中只废那一条,零写不是它的后果)
130
+ // 组内不逐条再判:组内漂移由 R2(降序应用)自己算得出来,逐条再判会用同一份快照判出与 R2 相反的结果。
131
+ for (const g of groups.values()) {
132
+ if (g.readError) continue
133
+ const keep = []
134
+ const keepIdx = []
135
+ g.entries.forEach((e, k) => {
136
+ if (hasLineParams(e)) {
137
+ const startLine = e.line ?? e.startLine
138
+ const endLine = e.line ?? e.endLine
139
+ if (lineAnchorVerdict(g.abs, startLine, endLine)) {
140
+ fail(g.idx[k], lineAnchorRefusal(g.abs, startLine, endLine))
141
+ return
142
+ }
143
+ }
144
+ keep.push(e)
145
+ keepIdx.push(g.idx[k])
146
+ })
147
+ g.entries = keep
148
+ g.idx = keepIdx
149
+ }
150
+
151
+ // ⑤ 帧排 + 逐条累积(帧单源 = edit-diff 的两个零 IO 纯函数;`onEntryError:"collect"` + `scope:"batch"`
152
+ // 与核批面同组实参——桥只做「读缓冲 → 应用计划 → 写缓冲」)
153
+ const planned = [] // { g, results, idx }——待写档
154
+ for (const g of groups.values()) {
155
+ if (g.readError || g.entries.length === 0) continue
156
+ const plan = planEditEntries(g.entries, g.path)
157
+ const rejected = new Set(plan.rejections.map((r) => r.index))
158
+ for (const r of plan.rejections) fail(g.idx[r.index], r.reason) // 重叠:两条互指,各得一行
159
+ const pos = new Map() // 组内下标 → 存活序下标
160
+ const liveE = []
161
+ const liveIdx = []
162
+ g.entries.forEach((e, k) => {
163
+ if (rejected.has(k)) return
164
+ pos.set(k, liveE.length)
165
+ liveE.push(e)
166
+ liveIdx.push(g.idx[k])
167
+ })
168
+ if (liveE.length === 0) continue
169
+ const order = plan.order.filter((k) => !rejected.has(k)).map((k) => pos.get(k))
170
+ const applied = applyPlannedEntries(g.content, liveE, order, { path: g.path, scope: "batch", onEntryError: "collect" })
171
+ g.content = applied.content
172
+ for (const f of applied.failures) fail(liveIdx[f.index], f.reason)
173
+ planned.push({ g, results: applied.results, idx: liveIdx })
174
+ }
175
+
176
+ // ⑥ 逐档一次写回(该档有 ≥1 条成功才写;零条成功 ⇒ 不写、也不记账)
177
+ // recordWrite 每档一条合并快照:startLine = 已应用条受影响行的最小值、shift = 已应用条净漂移之和
178
+ // (失败条没有可记的漂移)。零条成功的档不记账,否则护栏会拿一条没有对应写盘的快照放行/拒绝。
179
+ for (const { g, results, idx } of planned) {
180
+ const okPos = []
181
+ results.forEach((r, k) => { if (r) okPos.push(k) })
182
+ if (okPos.length === 0) continue
183
+ const startLine = Math.min(...okPos.map((k) => results[k].editStartLine))
184
+ const shift = okPos.reduce((n, k) => n + results[k].lineShift, 0)
185
+ try {
186
+ await writeBuffer(g.path, joinWithEol(normalizeEOL(g.content).split("\n"), g.raw))
187
+ } catch (err) {
188
+ // 写缓冲抛错只连坐该档:已有自己失败原因的条目保留自己那一句——它讲的是另一件事。
189
+ for (const k of idx) if (!state[k]) fail(k, err.message)
190
+ continue
191
+ }
192
+ // 缓冲写回**成功之后**记账:快照对同一坐标系有效(行号语义跟的是缓冲)
193
+ recordWrite(g.abs, { type: "edit", startLine, shift })
194
+ g.written = true
195
+ okPos.forEach((k) => { state[idx[k]] = { ok: true, g, out: results[k] } })
196
+ }
197
+
198
+ // ⑦ 回执:逐条一行、按调用序回原位(成 = 桥面成功形;败 = `edits[<i>] — failed: <原因原文>`)+ 末行汇总
199
+ const lines = new Array(total)
200
+ let appliedCount = 0
201
+ for (let i = 0; i < total; i++) {
202
+ const s = state[i]
203
+ if (!s) throw new Error(`editBatch: entry ${i} produced no outcome — internal invariant break, not a bad input`)
204
+ if (!s.ok) { lines[i] = editEntryFailureLine(`edits[${i}]`, s.reason); continue }
205
+ appliedCount++
206
+ // 删行条目写 `Deleted <line N|lines N-M> of <path> via IDE`,行号段取同一 `deleteTarget`;
207
+ // 替换条目写确认形。两形是模型区分「删了行」与「换了内容」的两条线索。
208
+ lines[i] = s.out.deleted
209
+ ? `Deleted ${deleteTarget(s.out)} of ${s.g.path} via IDE`
210
+ : `OK: edited ${s.g.path} via IDE (${s.out.occurrences} occurrence(s))${s.out.note ? ` — ${s.out.note}` : ""}`
211
+ }
212
+ const written = [...groups.values()].filter((g) => g.written).map((g) => g.path)
213
+ lines.push(editBatchSummary({ tool: "edit batch", applied: appliedCount, total, unit: "entries", filesWritten: written }))
214
+ return lines.join("\n")
215
+ }
216
+ return { absOf, editSingle, editBatch }
217
+ }
@@ -14,14 +14,17 @@
14
14
  * 释放该会话认领(保留集 = 本进程其余在存会话的活绑定槽,同 cwd;落盘判据三条沿用)。
15
15
  */
16
16
  import { resolve } from "node:path"
17
- import { loadManifest, normalizeCwd, bindRecordStore, deleteSlot, newSession, saveManifest, slotPath } from "@thincoder/core/session.mjs"
17
+ import { activeSlot, loadManifest, normalizeCwd, bindRecordStore, deleteSlot, newSession, saveManifest, slotPath } from "@thincoder/core/session.mjs"
18
+ import { setSlotMode } from "@thincoder/core/session-slot-write.mjs"
18
19
  // 认领释放谓词单源(SESSION.md §6.2 / §6.16——与 VSC 端壳 `releaseClaimsAll` 同源档;
19
20
  // core `session.mjs` 未 re-export 该名——直引 manifest 档,先例 = `thincoder-vscode/src/extension/session-io.mjs`)。
20
21
  import { staleClaims } from "@thincoder/core/session-slots-manifest.mjs"
21
22
  import { PLAN_ENGINEERING_REFUSED } from "@thincoder/core/agent-tools/plan.mjs"
22
23
  // #363①(off 形族单源——MODEL-SPECS.md §16.2):thinking 开关的取形引核(本档零副本)。
23
24
  import { thinkOffShape } from "@thincoder/core/think-off.mjs"
24
- import { providerSpec } from "@thincoder/core/config.mjs"
25
+ import { loadConfig, providerSpec, resolveWorkMode, setConfigWorkMode, WORK_MODES } from "@thincoder/core/config.mjs"
26
+ import { clearPlanMode } from "@thincoder/core/agent-tools/plan.mjs"
27
+ import { resolveEngineeringManifest } from "@thincoder/core/manifest.mjs"
25
28
  import { ACP_ERRORS } from "./transport.mjs"
26
29
  // §2.5(ACP-PROTOCOL-COMPLIANCE):prompt 内容块聚合(resource_link 内联 ∥ 降级标记——基线 MUST)。
27
30
  import { buildPromptText } from "./resource-link.mjs"
@@ -49,6 +52,9 @@ export function sessionConfigOptions(agent) {
49
52
  opts.push({ id: "thinking", name: "Thinking", type: "boolean", currentValue: th != null && th.type !== "disabled" })
50
53
  opts.push({ id: "mode", name: "Mode", type: "select", currentValue: agent?.planMode ? "plan" : "normal",
51
54
  options: [{ value: "normal", name: "Normal" }, { value: "plan", name: "Plan" }] })
55
+ const workMode = resolveWorkMode(agent?.config?.agent)
56
+ opts.push({ id: "workMode", name: "Work mode", type: "select", currentValue: workMode,
57
+ options: WORK_MODES.map((value) => ({ value, name: value[0].toUpperCase() + value.slice(1) })) })
52
58
  return opts
53
59
  }
54
60
 
@@ -140,6 +146,12 @@ export function applyConfigOption(agent, configId, value) {
140
146
  agent.planMode = value === "plan"
141
147
  return true
142
148
  }
149
+ case "workMode": {
150
+ if (!WORK_MODES.includes(value)) return false
151
+ setConfigWorkMode(agent.config, value)
152
+ if (value === "engineering") clearPlanMode(agent)
153
+ return true
154
+ }
143
155
  default:
144
156
  return false
145
157
  }
@@ -190,9 +202,11 @@ export function createSessionHandlers(ctx) {
190
202
  let slot = null
191
203
  let committed = false
192
204
  try {
193
- slot = await newSession(getCwd())
205
+ const initialMode = loadConfig().agent.mode
206
+ slot = await newSession(getCwd(), { mode: initialMode })
194
207
  const id = String(slot)
195
208
  const session = await createSession({ id, notify: notifyRef.current, request: requestRef.current, log })
209
+ setConfigWorkMode(session.agent.config, initialMode)
196
210
  // §11.5 装配后检查(兜底,与门互补):门拦「key 缺失 / defaultModel 不可解析」;
197
211
  // 本行拦「门放行但 provider 仍不可用」的残余(如 defaultModel 可解析而 provider 缺
198
212
  // baseURL)——显式报错而**不建半死会话**(槽已认领 ⇒ 由 finally 回滚撤除——无半态)。
@@ -305,6 +319,23 @@ export function createSessionHandlers(ctx) {
305
319
  if (configId === "mode" && value === "plan" && isEngineering(found.session.agent)) {
306
320
  return { error: { ...ACP_ERRORS.INVALID_PARAMS, message: PLAN_ENGINEERING_REFUSED } }
307
321
  }
322
+ if (configId === "workMode") {
323
+ if (!WORK_MODES.includes(value)) {
324
+ return { error: { ...ACP_ERRORS.INVALID_PARAMS, message: `workMode must be one of ${WORK_MODES.join("/")}` } }
325
+ }
326
+ const agent = found.session.agent
327
+ if (value === "engineering" && !isEngineering(agent)) {
328
+ const r = resolveEngineeringManifest(getCwd(), { writer: "main" })
329
+ if (!r.ok && r.code !== "workspace") {
330
+ return { error: { ...ACP_ERRORS.INVALID_PARAMS, message: `cannot enter engineering mode: ${r.message}` } }
331
+ }
332
+ agent.manifest = r.ok ? r.manifest : null
333
+ }
334
+ const slot = agent._slot ?? activeSlot(getCwd())
335
+ if (!setSlotMode(getCwd(), slot, value)) {
336
+ return { error: { code: ACP_ERRORS.INTERNAL.code, message: `failed to persist workMode to session slot ${slot}` } }
337
+ }
338
+ }
308
339
  const applied = applyConfigOption(found.session.agent, configId, value)
309
340
  if (!applied) {
310
341
  return { error: { ...ACP_ERRORS.INVALID_PARAMS, message: `unknown configId: ${configId}` } }
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { ACP_ERRORS } from "./transport.mjs"
13
13
  import { sessionConfigOptions } from "./handlers-session.mjs"
14
- import { loadConfig } from "@thincoder/core/config.mjs"
14
+ import { loadConfig, resolveSessionWorkMode, resolveWorkMode } from "@thincoder/core/config.mjs"
15
15
  import { resolveEngineeringManifest } from "@thincoder/core/manifest.mjs"
16
16
  import { replayHistory } from "./bridge.mjs"
17
17
  import { listSlots, applySession, deleteSlot, loadSlotFile, slotOccupancy, loadManifest, saveManifest, getSessionId, newSession } from "@thincoder/core/session.mjs"
@@ -24,9 +24,10 @@ export function createSlotsHandlers(ctx) {
24
24
  * `engineering` 字段 ? 槽值 : config 回退」。本路装配期(`applySession` 之前)无会话
25
25
  * agent ⇒ 回退源 = 盘上 config(与装配产物同源:`defaultCreateSession` → `assembleAgent`
26
26
  * → `loadConfig`)。 */
27
- const slotEngineering = (data) => data?.engineering !== undefined
28
- ? data.engineering === true
29
- : (() => { try { return loadConfig().agent?.engineering === true } catch { return false } })()
27
+ const slotEngineering = (data) => {
28
+ try { return resolveSessionWorkMode(data, loadConfig().agent) === "engineering" }
29
+ catch { return false }
30
+ }
30
31
 
31
32
  /** #41 装载后一行重估(F3 准翻列 / F4):`applySession` 已按槽订正 config ⇒ 工程模式会话
32
33
  * 就地判据(单源)+ 附着——缺档格 `writer:'main'` 建档;非工程模式零动作(零 manifest I/O)。
@@ -122,7 +123,7 @@ export function createSlotsHandlers(ctx) {
122
123
  // fork 会经 saveSession → activeSlot → ensureActive 分支1 早退(slotSessions
123
124
  // [active] === mySessionId 同进程恒真)落回同进程 active 槽 → 两会话写同一槽
124
125
  // 静默互覆盖。newSession 跳过活认领号/现存文件号,必定落到新槽。
125
- session.agent._slot = await newSession(getCwd())
126
+ session.agent._slot = await newSession(getCwd(), { mode: resolveWorkMode(session.agent.config?.agent) })
126
127
  }
127
128
  sessions.set(id, session)
128
129
  // Replay the human line (role → chunk mapping, design §4.5) so the
@@ -185,7 +186,7 @@ export function createSlotsHandlers(ctx) {
185
186
  } else {
186
187
  // 2026-09-01 advisor 🔴:同 load——显式 newSession fork(_slot=null 的 fork 会
187
188
  // 落回同进程 active 槽 → 两会话写同一槽静默互覆盖)
188
- session.agent._slot = await newSession(getCwd())
189
+ session.agent._slot = await newSession(getCwd(), { mode: resolveWorkMode(session.agent.config?.agent) })
189
190
  }
190
191
  sessions.set(id, session)
191
192
  // resume: no history replay — the client keeps its own rendering.
@@ -216,7 +217,7 @@ export function createSlotsHandlers(ctx) {
216
217
  // 互覆盖(sessionStart 均 null → F2 永不轮转)。与 load/resume 同型修复:
217
218
  // 立即 newSession 钉全新槽(跳过活认领号/现存文件号)。
218
219
  for (const s of sessions.values()) {
219
- if (s.agent?._slot === slot) s.agent._slot = await newSession(getCwd())
220
+ if (s.agent?._slot === slot) s.agent._slot = await newSession(getCwd(), { mode: resolveWorkMode(s.agent.config?.agent) })
220
221
  }
221
222
  log(`session ${slot} archive deleted`)
222
223
  return {}
@@ -11,6 +11,7 @@ import { join } from "node:path"
11
11
  // 装配序核单源(B5 装配序上提批):本档 = 核调用 + MCP 缝 + 后处理。
12
12
  import { assembleAgent as coreAssemble, DEFAULT_DEPS, gitAuthor, teamConfig, validateProvider } from "@thincoder/core/agent/assemble.mjs"
13
13
  import { resolveEngineeringManifest, projectView } from "@thincoder/core/manifest.mjs"
14
+ import { resolveSessionWorkMode } from "@thincoder/core/config.mjs"
14
15
 
15
16
  // 四名转口(核单源**恒等绑定**;调用面零改 —— 枚举见档头)。
16
17
  export { DEFAULT_DEPS, gitAuthor, teamConfig, validateProvider }
@@ -125,8 +126,7 @@ async function finalizeTools(baseTools, { cwd, config, excludeTools, warnings })
125
126
  * @returns {object|null} 附着后的 manifest / 非 ok 态与普通会话 null
126
127
  */
127
128
  export function attachManifest(agent, { cwd = agent.cwd, slotData } = {}) {
128
- const slotEng = slotData?.engineering
129
- const engineering = slotEng !== undefined ? slotEng === true : agent.config?.agent?.engineering === true
129
+ const engineering = resolveSessionWorkMode(slotData, agent.config?.agent) === "engineering"
130
130
  if (!engineering) {
131
131
  agent.manifest = null // 清残留附着(KD-M1-12)——普通会话不读 / 不拒 / 不建档
132
132
  return null
@@ -95,12 +95,17 @@ function timerRearmBlocked(state, agent) {
95
95
  /** runAgentTurn 本体(LOGGING 包装之外——见上方包装器):**链尾收口层**——正文(`runAgentTurnBody`)
96
96
  * 之后收「链尾闩重同步」(§6.30.5 载体②武装点——履行原正文内同点调用;#448②:入 `finally` ⇒
97
97
  * 异常 ∕ 中止逃逸的回合同样重武装;守卫 = `timerRearmBlocked`)。attention 仍在正文链尾原位
98
- * (谓词读 `_pendingTimers`、不读闩状态 ⇒ 与 sync 无相对序依赖)。 */
98
+ * (谓词读 `_pendingTimers`、不读闩状态 ⇒ 与 sync 无相对序依赖)。
99
+ * **跨实例取件闩**(MULTI-INSTANCE-COLLAB §5.4 · D-MI31):**回合起点不撤**(自续闩——撤闩 =
100
+ * 「要靠别人再把你叫醒」,而那个「别人」正是会漏掉叫醒的地方);链尾 `sync()` 为**幂等补位**(换的是
101
+ * 「轮尾 ≤ 1 ms 取件」而非「≤ 1 s」),**不进 `timerRearmBlocked` 守卫**——那道守卫管的是「要不要无人自动
102
+ * 开一轮」,管不着「门还能不能开」(闩哑掉不会让守卫少开一轮,只会让消息躺在盘上没人取)。 */
99
103
  async function runAgentTurnInner(ctx, text, opts) {
100
104
  try {
101
105
  await runAgentTurnBody(ctx, text, opts)
102
106
  } finally {
103
107
  if (!timerRearmBlocked(ctx?.state, ctx?.agent)) ctx?.timerWatch?.sync()
108
+ ctx?.inboxWatch?.sync() // 补位点(幂等 · 零存活职责)——守卫只管 timer 面
104
109
  }
105
110
  }
106
111
 
@@ -7,7 +7,7 @@ import { activeSlot, slotPath } from "@thincoder/core/session.mjs"
7
7
  // off 形族单源(`docs/core/design/MODEL-SPECS.md` §16.2 / §16.3 / §16.4)——取形与「有效 off 路径」
8
8
  // 判据一律自本档取,本档零副本(叶档:零 import 纯函数)。
9
9
  import { thinkOffShape, thinkOffPath } from "@thincoder/core/think-off.mjs"
10
- import { writeSessionFile } from "./cmd-eng.mjs"
10
+ import { writeSessionFile } from "@thincoder/core/session.mjs"
11
11
 
12
12
  export async function handleAdvisorCommand(ctx) {
13
13
  const { agent, showPicker, pushLine, pushLabel } = ctx
@@ -2,11 +2,13 @@ import { ansi, C } from "./ansi.mjs"
2
2
  import { embeddingPatch, poolCur, compactThresholdSuffix, compactThresholdHint } from "./config-helpers.mjs"
3
3
  // 四子菜单(代理 ∥ 会诊池 ∥ 并发池 ∥ 默认模型)已迁 `cmd-config-menus.mjs`(§6.16.9 —— C2)
4
4
  import { createProxyMenu, createConsultMenu, createPoolMenu, createDefaultModelMenu } from "./cmd-config-menus.mjs"
5
+ import { resolveWorkMode, setConfigWorkMode } from "@thincoder/core/config.mjs"
5
6
 
6
7
  /** /config command: view and set agent/embedding/proxy config. */
7
8
  export async function handleConfigCommand(ctx, args = []) {
8
9
  const { agent, pushLine, pushLabel, showPicker, askQuestion, persistRaw, maskKey, pickModelForSlot } = ctx
9
- const { configPath, DEFAULTS } = await import("@thincoder/core/config.mjs")
10
+ const { configPath, DEFAULTS, loadConfig } = await import("@thincoder/core/config.mjs")
11
+ let defaultMode = loadConfig().agent.mode
10
12
  let ac = agent.config?.agent ?? {}
11
13
  let ec = agent.config?.embedding ?? {}
12
14
  let tc = agent.config?.traces ?? {}
@@ -39,15 +41,18 @@ export async function handleConfigCommand(ctx, args = []) {
39
41
  * MODEL-MERGE-SESSION 三支改写(cfg 无 active*):运行时由「会话槽复合仍在 providers 中 →
40
42
  * 保持槽值」或「config defaultModel(新会话起点)」决定(渠道条目不携模型——2026-10-09 清除批)。 */
41
43
  async function reloadConfig() {
42
- const { loadConfig } = await import("@thincoder/core/config.mjs")
44
+ const sessionMode = resolveWorkMode(agent.config?.agent)
43
45
  const { injectProxy } = await import("@thincoder/core/proxy.mjs")
44
46
  const cfg = loadConfig()
47
+ defaultMode = cfg.agent.mode
45
48
  injectProxy(cfg.providersList, cfg)
46
49
  const sessionName = agent.activeProvider
47
50
  const sessionModel = agent.activeModel
48
51
  agent.providers = cfg.providersList
49
52
  agent.config = cfg
50
53
  agent.config.agent ??= {}
54
+ // agent.mode in config.json seeds new sessions; reloading settings must not switch this slot.
55
+ setConfigWorkMode(agent.config, sessionMode)
51
56
  const keep = sessionName ? cfg.providersList.find((p) => p.name === sessionName) : null
52
57
  if (keep) {
53
58
  // 会话 provider 仍存在 → 会话复合优先(槽值——不看 cfg 默认;模型空时落默认复合;
@@ -69,8 +74,8 @@ export async function handleConfigCommand(ctx, args = []) {
69
74
  // §6.17:auto 派生值永不回写 agent.compactThreshold——只刷新显示面 compactThresholdResolved
70
75
  // (每 run 的判定阈值由 setup.mjs 现算,本处只管 /config 显示面与显式键隔离)
71
76
  if (agent.config?.agent?.compactThresholdAuto) {
72
- const { resolveCompactThreshold } = await import("@thincoder/core/config.mjs")
73
- agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
77
+ const { resolveCompactThreshold, resolveWorkMode } = await import("@thincoder/core/config.mjs")
78
+ agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider, resolveWorkMode(agent.config?.agent)).value
74
79
  }
75
80
  }
76
81
 
@@ -128,6 +133,7 @@ export async function handleConfigCommand(ctx, args = []) {
128
133
  { type: "item", text: `并发池 agent.poolLimits = engCoder ${cur("engCoder")} / other ${cur("other")} / advisor ${cur("advisor")}(async 分域上限)`, action: "pool" },
129
134
  { type: "item", text: `agent.compactThreshold = ${ctDisplay}${ctSuffix}`, action: "agent.compactThreshold" },
130
135
  { type: "item", text: `config.defaultModel = ${agent.config?.defaultModel ?? "(未设置 — 新会话起点)"}`, action: "defaultModel" },
136
+ { type: "item", text: `agent.mode = ${defaultMode}(新会话默认工作模式;当前会话 ${ac.mode ?? "normal"})`, action: "agent.mode" },
131
137
  { type: "item", text: `agent.verifyGuard = ${ac.verifyGuard === true ? "on" : "off"}`, action: "agent.verifyGuard" },
132
138
  { type: "item", text: `traces.enabled = ${tc.enabled === false ? "off" : "on"}(轨迹存档——发布默认关——隐私)`, action: "traces.enabled" },
133
139
  { type: "item", text: `traces.retentionHours = ${tc.retentionHours ?? 24} h(超期文件启动时清理)`, action: "traces.retentionHours" },
@@ -152,6 +158,7 @@ export async function handleConfigCommand(ctx, args = []) {
152
158
  pushLine(`Session model: ${agent.activeProvider ? `${agent.activeProvider}:${agent.activeModel ?? ""}` : "(none)"}`, C.dim)
153
159
  pushLine(`defaultModel (config): ${agent.config?.defaultModel ?? "(not set — 新会话起点)"}`, C.dim)
154
160
  pushLine(`Key: ${maskKey(agent.provider.apiKey)}`, C.dim)
161
+ pushLine(`agent.mode (new-session default): ${defaultMode}`, C.dim)
155
162
  pushLine(`agent.maxTurns: ${ac.maxTurns ?? 200}`, C.dim)
156
163
  pushLine(`agent.subagentTurns: ${ac.subagentTurns ?? 100}`, C.dim)
157
164
  pushLine(`agent.compactThreshold: ${ctDisplay}${ctSuffix}`, C.dim)
@@ -197,6 +204,22 @@ export async function handleConfigCommand(ctx, args = []) {
197
204
  continue
198
205
  }
199
206
 
207
+ if (choice.action === "agent.mode") {
208
+ const selected = await showPicker("New-session work mode", [
209
+ { type: "item", text: "tiny — compact prompts with on-demand knowledge", action: "tiny" },
210
+ { type: "item", text: "normal — full normal workflow", action: "normal" },
211
+ { type: "item", text: "engineering — design-first engineering workflow", action: "engineering" },
212
+ ])
213
+ if (selected) {
214
+ try {
215
+ await saveProxy((raw) => { raw.agent ??= {}; raw.agent.mode = selected.action })
216
+ pushLabel("❯ Config", ansi.bold + C.tool)
217
+ pushLine(`agent.mode = ${selected.action}(新会话默认;当前会话不变)`, C.tool)
218
+ } catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
219
+ }
220
+ continue
221
+ }
222
+
200
223
  if (choice.action === "agent.verifyGuard") {
201
224
  const newVal = ac.verifyGuard !== true
202
225
  try {