thincoder 0.12.80 → 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.
- package/CHANGELOG.md +115 -74
- package/README.md +90 -39
- package/package.json +2 -2
- package/src/acp/bridge.mjs +19 -61
- package/src/acp/buffered-edit.mjs +217 -0
- package/src/acp/handlers-session.mjs +34 -3
- package/src/acp/handlers-slots.mjs +8 -7
- package/src/acp/read-data.mjs +4 -4
- package/src/acp/resource-link.mjs +1 -1
- package/src/cli/make-agent.mjs +3 -3
- package/src/command-interactive.mjs +3 -1
- package/src/tui/agent-turn.mjs +14 -3
- package/src/tui/cmd-advisor.mjs +1 -1
- package/src/tui/cmd-config.mjs +27 -4
- package/src/tui/cmd-eng.mjs +49 -84
- package/src/tui/cmd-mcp.mjs +1 -1
- package/src/tui/cmd-new.mjs +7 -1
- package/src/tui/cmd-session.mjs +2 -2
- package/src/tui/cmd-timers.mjs +2 -2
- package/src/tui/index.mjs +31 -2
- package/src/tui/lifecycle-records.mjs +12 -1
- package/src/tui/model-picker.mjs +27 -37
- package/src/tui/provider-admin.mjs +3 -2
- package/src/tui/provider-entries.mjs +92 -0
- package/src/tui/render-loop.mjs +30 -4
- package/src/tui/slash-commands.mjs +6 -2
- package/src/tui/status-line.mjs +22 -11
- package/src/tui/timer-watch.mjs +61 -0
- package/src/tui/tui-state.mjs +1 -1
|
@@ -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
|
-
|
|
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) =>
|
|
28
|
-
|
|
29
|
-
|
|
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 {}
|
package/src/acp/read-data.mjs
CHANGED
|
@@ -73,8 +73,8 @@ export function createReadDataHandlers(ctx, { intervalMs = WATCH_INTERVAL_MS } =
|
|
|
73
73
|
const c = resolveCwd(params, ctx)
|
|
74
74
|
if (c.error) return c.error
|
|
75
75
|
const { ledgerCmd } = await core()
|
|
76
|
-
// `ledgerCount` 出参 = 对象形 `{ count, overdue,
|
|
77
|
-
try { return ledgerCmd.ledgerCount({ cwd: c.cwd }) } catch (e) { return badParams(e?.message ?? String(e)) }
|
|
76
|
+
// `ledgerCount` 出参 = 对象形 `{ count, overdue, evidenceTooLong }`(设计档 §7.1)——直传核对象,零包装
|
|
77
|
+
try { return ledgerCmd.ledgerCount({ cwd: c.cwd, boundary: c.cwd }) } catch (e) { return badParams(e?.message ?? String(e)) } // 界 = 调用方指名的 cwd(同 :66;见 docs/core/design/LEDGER.md §3.8「三面三界」)
|
|
78
78
|
},
|
|
79
79
|
|
|
80
80
|
"batch/list": async (params) => {
|
|
@@ -101,8 +101,8 @@ export function createReadDataHandlers(ctx, { intervalMs = WATCH_INTERVAL_MS } =
|
|
|
101
101
|
const { ledgerDb, batchRead } = await core()
|
|
102
102
|
// 观察域根 = 判据单源 `resolveLedgerRoot`(与写入面同源):根 ⇒ 其键控库指纹;无根 ⇒ 该域无台账库、
|
|
103
103
|
// 指纹恒 "0"(观察域照常上报——键控库在盘 / 变动即报 `ledger/changed`)。
|
|
104
|
-
const root = ledgerDb.resolveLedgerRoot(cwd)?.root
|
|
105
|
-
const ledgerSig = root ? fileSig(ledgerDb.ledgerDbPath(root)) : "0"
|
|
104
|
+
const root = ledgerDb.resolveLedgerRoot(cwd, cwd)?.root
|
|
105
|
+
const ledgerSig = root ? fileSig(ledgerDb.ledgerDbPath(root, root)) : "0"
|
|
106
106
|
const batchSig = batchRead.listBatchRecords({ cwd }).batches.map((b) => `${b.path}:${fileSig(b.path)}`).join("|")
|
|
107
107
|
if (!last || last.cwd !== cwd) { last = { cwd, ledgerSig, batchSig }; return [] } // 首查 / 观察域切换 ⇒ 立基线(静默)
|
|
108
108
|
const fired = []
|
|
@@ -60,7 +60,7 @@ export async function resolveResourceLink(block, { cwd } = {}) {
|
|
|
60
60
|
} else {
|
|
61
61
|
try { path = decodeURIComponent(raw) } catch { return marker(raw, "invalid percent-encoding") }
|
|
62
62
|
}
|
|
63
|
-
path = resolvePath(cwd
|
|
63
|
+
path = resolvePath(cwd, path) // 相对路径按 cwd;已在盘面形则归一平台原生分隔符
|
|
64
64
|
|
|
65
65
|
// ③ 选区解析(仅 url.hash;非选区哈希 = 锚点 ⇒ 整文)
|
|
66
66
|
let sel = null
|
package/src/cli/make-agent.mjs
CHANGED
|
@@ -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 }
|
|
@@ -124,9 +125,8 @@ async function finalizeTools(baseTools, { cwd, config, excludeTools, warnings })
|
|
|
124
125
|
* @param {{cwd?: string, slotData?: object|null}} [opts]
|
|
125
126
|
* @returns {object|null} 附着后的 manifest / 非 ok 态与普通会话 null
|
|
126
127
|
*/
|
|
127
|
-
export function attachManifest(agent, { cwd =
|
|
128
|
-
const
|
|
129
|
-
const engineering = slotEng !== undefined ? slotEng === true : agent.config?.agent?.engineering === true
|
|
128
|
+
export function attachManifest(agent, { cwd = agent.cwd, slotData } = {}) {
|
|
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
|
|
@@ -108,7 +108,9 @@ export async function chatCommand(args, ctx) {
|
|
|
108
108
|
} catch (error) {
|
|
109
109
|
// 用 name 判断而非 instanceof:不依赖"与 runAgent 同一个模块实例"这一隐式约定
|
|
110
110
|
if (error.name === "ContinueError") {
|
|
111
|
-
|
|
111
|
+
// 两个数(TURN-CAP-CONTINUE.md §6.1 / §6.3 · D-TC10):本段轮数 + 链内累计(直读 `agent._turnSeq`,
|
|
112
|
+
// 不加兜底——缺值印 0 会把「未跟踪」读作「零消耗」);上限不印(§6.2 撞帽点两个上限均 ≡ 已示轮数)。
|
|
113
|
+
console.error(`\n[paused] Agent stopped after ${error.turn} turns — ${agent._turnSeq} turns total. Run in TUI to continue.`)
|
|
112
114
|
exitSoon(0)
|
|
113
115
|
} else {
|
|
114
116
|
console.error(`\n[error] ${error.message}`)
|
package/src/tui/agent-turn.mjs
CHANGED
|
@@ -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
|
|
|
@@ -238,8 +243,14 @@ async function runAgentTurnBody(ctx, text, opts) {
|
|
|
238
243
|
break
|
|
239
244
|
}
|
|
240
245
|
if (decision === "ask") {
|
|
246
|
+
// TURN-CAP-CONTINUE.md §6.1 ∕ §6.4(D-TC10):撞帽提示给两个数——
|
|
247
|
+
// seg = 本段轮数(`ContinueError.turn`,撞帽点 ≡ 本段预算)、total = 链内累计(`_turnSeq` 计数器本身)。
|
|
248
|
+
// 直读 `agent._turnSeq`,不加 `?? 0`:缺值印 0 会把「未跟踪」读作「零消耗」(§6.1)。
|
|
249
|
+
// 上限不印(§6.2):撞帽点本段上限 ≡ 本段轮数、累计上限 ≡ 累计轮数,印出来只有重复。
|
|
250
|
+
const seg = error.turn
|
|
251
|
+
const total = agent._turnSeq
|
|
241
252
|
pushLabel(`❯ Continue`, ansi.bold + C.warn)
|
|
242
|
-
pushLine(`Ran ${
|
|
253
|
+
pushLine(`Ran ${seg} turns — ${total} turns total. Continue?`, C.warn)
|
|
243
254
|
// Pause to ask: reuse permission mechanism
|
|
244
255
|
const willContinue = await new Promise((resolve) => {
|
|
245
256
|
state.permission = {
|
|
@@ -247,7 +258,7 @@ async function runAgentTurnBody(ctx, text, opts) {
|
|
|
247
258
|
args: { turns: error.turn },
|
|
248
259
|
resolve,
|
|
249
260
|
}
|
|
250
|
-
state.status = `Continue after ${
|
|
261
|
+
state.status = `Continue after ${seg} turns (${total} total)?`
|
|
251
262
|
render()
|
|
252
263
|
})
|
|
253
264
|
state.permission = null
|
package/src/tui/cmd-advisor.mjs
CHANGED
|
@@ -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 "
|
|
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
|
package/src/tui/cmd-config.mjs
CHANGED
|
@@ -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
|
|
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 {
|
package/src/tui/cmd-eng.mjs
CHANGED
|
@@ -1,107 +1,72 @@
|
|
|
1
|
-
/** /eng
|
|
2
|
-
*
|
|
3
|
-
* no methodology file, no docs tree. **可拒面 = 仅「档非法」一格**(工作区 `workspace` 放行):
|
|
4
|
-
* 该格上 ON = 拒翻 + 明示原因、模式保持 OFF(#41 —
|
|
5
|
-
* `docs/core/design/MANIFEST.md` §2.8 F2/F3;判定面 = 入口决策树单源)。
|
|
6
|
-
* ctx: { agent, pushLine, pushLabel } */
|
|
7
|
-
import { readFileSync, writeFileSync, mkdirSync, renameSync, unlinkSync } from "node:fs"
|
|
8
|
-
import { dirname } from "node:path"
|
|
1
|
+
/** Session work-mode commands. /eng toggles engineering↔normal; /tiny toggles
|
|
2
|
+
* tiny↔normal; /normal always selects normal. All three write the same slot field. */
|
|
9
3
|
import { ansi, C } from "./ansi.mjs"
|
|
10
|
-
import { activeSlot
|
|
4
|
+
import { activeSlot } from "@thincoder/core/session.mjs"
|
|
5
|
+
import { setSlotMode } from "@thincoder/core/session-slot-write.mjs"
|
|
11
6
|
import { purgeExpiredDesignTokens } from "@thincoder/core/token-ttl.mjs"
|
|
12
7
|
import { resolveEngineeringManifest } from "@thincoder/core/manifest.mjs"
|
|
13
|
-
|
|
8
|
+
import { resolveWorkMode, setConfigWorkMode } from "@thincoder/core/config.mjs"
|
|
14
9
|
import { ENG_OFF_REMINDER } from "@thincoder/core/agent.mjs"
|
|
15
10
|
import { clearPlanMode } from "@thincoder/core/agent-tools/plan.mjs"
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
* private-import; cmd-advisor's guard toggle shares this helper). */
|
|
19
|
-
export function writeSessionFile(p, data) {
|
|
20
|
-
mkdirSync(dirname(p), { recursive: true })
|
|
21
|
-
const tmp = `${p}.tmp`
|
|
22
|
-
writeFileSync(tmp, JSON.stringify(data), "utf8")
|
|
23
|
-
try {
|
|
24
|
-
renameSync(tmp, p)
|
|
25
|
-
} catch {
|
|
26
|
-
try { unlinkSync(p) } catch {}
|
|
27
|
-
try { renameSync(tmp, p) } catch { writeFileSync(p, readFileSync(tmp, "utf8"), "utf8") }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function handleEngCommand(ctx) {
|
|
12
|
+
async function selectWorkMode(ctx, target, command) {
|
|
32
13
|
const { agent, pushLine, pushLabel } = ctx
|
|
33
14
|
agent.config.agent ??= {}
|
|
15
|
+
const previous = resolveWorkMode(agent.config.agent)
|
|
16
|
+
const enteringEngineering = target === "engineering" && previous !== "engineering"
|
|
17
|
+
const leavingEngineering = previous === "engineering" && target !== "engineering"
|
|
34
18
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// (resolveEngineeringManifest——KD-M1-20),判据通过才写态;OFF 方向零改(F2 表 OFF 行)。
|
|
40
|
-
// **可拒面 = 仅「档非法」格**(工作区 `workspace` ⇒ 放行——放行 ⇒ **零附着**,模式照开)。
|
|
41
|
-
// 拒 ⇒ warn 行 + **零标签**(标签 = 成功回显——拒时零标签防假成功)+ 零副作用
|
|
42
|
-
// (模式未翻 / token 未清 / `_advisorRuns` 未重置 / 提醒未入列 / 槽未写)。
|
|
43
|
-
// 准 ⇒ 缺档格就地建档(writer:'main')+ `agent.manifest` ← 结果(相位行当回合起活)。
|
|
44
|
-
if (!agent.config.agent.engineering) {
|
|
45
|
-
const r = resolveEngineeringManifest(agent.cwd ?? process.cwd(), { writer: "main" })
|
|
19
|
+
// Preserve the existing engineering entry gate: refusal leaves mode, tokens, PLAN and slot intact.
|
|
20
|
+
let engineeringManifest
|
|
21
|
+
if (enteringEngineering) {
|
|
22
|
+
const r = resolveEngineeringManifest(agent.cwd, { writer: "main" })
|
|
46
23
|
if (!r.ok && r.code !== "workspace") {
|
|
47
24
|
pushLine(`Engineering mode not enabled — ${r.message} (mode unchanged)`, C.warn)
|
|
48
25
|
return
|
|
49
26
|
}
|
|
50
|
-
|
|
51
|
-
else agent.manifest = null // 工作区放行 ⇒ 零附着(显式置 null——§2.8 F2 放行行)
|
|
27
|
+
engineeringManifest = r.ok ? r.manifest : null
|
|
52
28
|
}
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
agent.
|
|
29
|
+
|
|
30
|
+
// Persist first: a rejected write leaves the current in-memory mode unchanged and reports failure.
|
|
31
|
+
const slot = agent._slot ?? activeSlot(agent.cwd)
|
|
32
|
+
if (!setSlotMode(agent.cwd, slot, target)) {
|
|
33
|
+
pushLine(`Work mode unchanged — could not write session slot ${slot}`, C.error)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
if (enteringEngineering) agent.manifest = engineeringManifest
|
|
37
|
+
setConfigWorkMode(agent.config, target)
|
|
38
|
+
const planReset = target === "engineering" ? clearPlanMode(agent) : false
|
|
39
|
+
if (previous !== target && (enteringEngineering || leavingEngineering)) agent._advisorRuns = new Map()
|
|
40
|
+
if (leavingEngineering) {
|
|
41
|
+
agent._advisorRound = 0
|
|
42
|
+
agent._touchedFiles = []
|
|
43
|
+
agent._pendingReminders ??= []
|
|
67
44
|
agent._pendingReminders.push(ENG_OFF_REMINDER)
|
|
68
45
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
pushLine(
|
|
77
|
-
if (planReset) {
|
|
78
|
-
pushLine(` → plan mode reset (engineering mode excludes plan mode)`, C.dim)
|
|
79
|
-
}
|
|
46
|
+
const clearedExpired = enteringEngineering ? purgeExpiredDesignTokens(agent) : 0
|
|
47
|
+
agent._lastEngState = target === "engineering"
|
|
48
|
+
|
|
49
|
+
pushLabel(`❯ ${command}`, ansi.bold + C.tool)
|
|
50
|
+
pushLine(`Work mode: ${target} (session; next run)`, C.tool)
|
|
51
|
+
if (target === "engineering") {
|
|
52
|
+
pushLine(" → design-before-code enforced (design review + user approval before code)", C.dim)
|
|
53
|
+
if (planReset) pushLine(" → plan mode reset (engineering mode excludes plan mode)", C.dim)
|
|
80
54
|
if (clearedExpired > 0) {
|
|
81
55
|
pushLine(` → cleared ${clearedExpired} expired design token${clearedExpired === 1 ? "" : "s"}; valid tokens from prior reviews stay usable`, C.dim)
|
|
82
56
|
}
|
|
83
57
|
}
|
|
84
58
|
}
|
|
85
59
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const p = slotPath(agent.cwd, slot)
|
|
100
|
-
const data = JSON.parse(readFileSync(p, "utf8"))
|
|
101
|
-
if (data && typeof data === "object" && Array.isArray(data.history)) {
|
|
102
|
-
data.engineering = agent.config.agent.engineering
|
|
103
|
-
if (agent.config.agent.engineering) data.planMode = false
|
|
104
|
-
writeSessionFile(p, data)
|
|
105
|
-
}
|
|
106
|
-
} catch { /* slot missing/unreadable — in-memory flag already flipped; saveSession persists at turn end */ }
|
|
60
|
+
export async function handleEngCommand(ctx) {
|
|
61
|
+
const current = resolveWorkMode(ctx.agent.config?.agent)
|
|
62
|
+
await selectWorkMode(ctx, current === "engineering" ? "normal" : "engineering", "/eng")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function handleTinyCommand(ctx) {
|
|
66
|
+
const current = resolveWorkMode(ctx.agent.config?.agent)
|
|
67
|
+
await selectWorkMode(ctx, current === "tiny" ? "normal" : "tiny", "/tiny")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function handleNormalCommand(ctx) {
|
|
71
|
+
await selectWorkMode(ctx, "normal", "/normal")
|
|
107
72
|
}
|
package/src/tui/cmd-mcp.mjs
CHANGED
|
@@ -187,7 +187,7 @@ Return ONLY the JSON object:`,
|
|
|
187
187
|
logCtx: {
|
|
188
188
|
stage: "mcp", kind: "mcp",
|
|
189
189
|
role: agent?._role ?? null,
|
|
190
|
-
session: agent?._sessionStart ?? null, cwd: agent?.cwd
|
|
190
|
+
session: agent?._sessionStart ?? null, cwd: agent?.cwd,
|
|
191
191
|
traces: agent?.config?.traces?.enabled !== false,
|
|
192
192
|
},
|
|
193
193
|
})
|
package/src/tui/cmd-new.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { newSession, resetSessionState, bindRecordStore, slotPath } from "@thincoder/core/session.mjs"
|
|
2
2
|
import { C } from "./ansi.mjs"
|
|
3
|
+
import { loadConfig, setConfigWorkMode } from "@thincoder/core/config.mjs"
|
|
4
|
+
import { attachManifest } from "../cli/make-agent.mjs"
|
|
3
5
|
|
|
4
6
|
/** /new command: start a new session in a fresh slot.
|
|
5
7
|
* ctx: { agent, state, pushLine, showPicker, render } */
|
|
@@ -8,12 +10,16 @@ export async function handleNewCommand(ctx) {
|
|
|
8
10
|
|
|
9
11
|
// F-MI7:newSession = async(探测束)——doNewSession 随之为 async,调用点 await
|
|
10
12
|
const doNewSession = async () => {
|
|
11
|
-
const
|
|
13
|
+
const initialMode = loadConfig().agent.mode
|
|
14
|
+
const slot = await newSession(agent.cwd, { releaseStale: true, mode: initialMode }) // F-CR1:/new 释放本进程残留认领(保留集 = {新槽});ACP 四点不传(F-CR3)
|
|
12
15
|
// 2026-08-31 会诊 F3:resetSessionState 清全量会话态(_fullHistory/title/_sessionStart/
|
|
13
16
|
// 多槽设计凭证(_engDesignTokens——单值镜像 _engDesignToken 已退役 D3)/压缩与验证计数
|
|
14
17
|
// 等)——原实现只清 agent.history,新会话首次落盘把旧会话完整人类线 + 旧标题写进新
|
|
15
18
|
// slot(实锤 .19/.3 双副本)。_slot 更新为粘性新槽位。
|
|
16
19
|
const { droppedDesignTokens } = resetSessionState(agent)
|
|
20
|
+
// A new session starts from the persisted default, not from the previous slot's mode.
|
|
21
|
+
setConfigWorkMode(agent.config, initialMode)
|
|
22
|
+
attachManifest(agent, { cwd: agent.cwd })
|
|
17
23
|
agent._slot = slot
|
|
18
24
|
// SESSION.md §6.14:/new 绑定新槽记录存储(baseHistory 空——identity 此时为 null = 待固化;
|
|
19
25
|
// 首次保存/首条追加时补写现场身份)
|
package/src/tui/cmd-session.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listSlots, switchToSlot, applySession, renameSlot, activeSlot, slotOccupancy, readEndMarker, sessionDescriptor, loadSlotFile, ledgerHealth } from "@thincoder/core/session.mjs"
|
|
2
2
|
import { resolveEngineeringManifest } from "@thincoder/core/manifest.mjs"
|
|
3
|
+
import { resolveSessionWorkMode } from "@thincoder/core/config.mjs"
|
|
3
4
|
import { ansi, C } from "./ansi.mjs"
|
|
4
5
|
import { restoreLines } from "./startup.mjs"
|
|
5
6
|
import { stringWidth, sliceByWidth } from "./render.mjs"
|
|
@@ -100,8 +101,7 @@ export async function handleSessionCommand(ctx) {
|
|
|
100
101
|
// `workspace` ⇒ 放行——放行 ⇒ **零附着**)。拒 ⇒ 切槽整体不发生(switchToSlot /
|
|
101
102
|
// applySession 均不调——零副作用)+ 原因行;准 ⇒ 既有切换 + applySession 之后一行附着。
|
|
102
103
|
const preview = loadSlotFile(agent.cwd, e.slot)
|
|
103
|
-
const
|
|
104
|
-
const targetEng = preview != null && (slotEng !== undefined ? slotEng === true : agent.config?.agent?.engineering === true)
|
|
104
|
+
const targetEng = preview != null && resolveSessionWorkMode(preview, agent.config?.agent) === "engineering"
|
|
105
105
|
let manifestAfterSwitch = null
|
|
106
106
|
if (targetEng) {
|
|
107
107
|
const r = resolveEngineeringManifest(agent.cwd, { writer: "main" })
|
package/src/tui/cmd-timers.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* cmd-timers.mjs — `/timers`:在途 timer 只读列表(最薄)。
|
|
3
3
|
*
|
|
4
4
|
* 机制单源 = `docs/core/design/AGENT-LOOP-ASYNC-POOL.md` §6.30;显示形态单源 = `docs/cli/design/TUI.md`
|
|
5
|
-
* §7.6(逐条 dim 行
|
|
5
|
+
* §7.6(逐条 dim 行 `timer <i> · <kind> · 剩余 <dur> · <message 首行(截断)>`;零在途 ⇒ 一行 `无在途 timer`)。
|
|
6
6
|
* **取消 = 模型工具 `timer` 的 `cancel` 动作**(§6.30.18——四端同得;`/timers` 保持只读;停轮 = Ctrl+C,
|
|
7
7
|
* 停机制 = `agent.timerWake` 关);不设端专属取消 UI。
|
|
8
8
|
* 取值 = `agent._pendingTimers` 活读(每次调用现算——零缓存);剩余按 `expiresAt - now` 现算。
|
|
@@ -65,6 +65,6 @@ export async function handleTimersCommand(ctx) {
|
|
|
65
65
|
const now = ctx.now ?? Date.now() // 时钟缝单点(§6.30.18)——生产 ctx 不携 now ⇒ 缺省回落 = 现行为零变
|
|
66
66
|
timers.forEach((t, i) => {
|
|
67
67
|
const kind = kindText(t)
|
|
68
|
-
pushLine(
|
|
68
|
+
pushLine(`timer ${i + 1}${kind === null ? "" : ` · ${kind}`} · 剩余 ${remainText(t.expiresAt, now)} · ${headText(t.message)}`, C.dim)
|
|
69
69
|
})
|
|
70
70
|
}
|
package/src/tui/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ import { createTuiState } from "./tui-state.mjs"
|
|
|
43
43
|
import { createInputFace } from "./input-face.mjs"
|
|
44
44
|
import { createConversationWriter } from "./conversation-writer.mjs"
|
|
45
45
|
import { createTurnFace } from "./turn-face.mjs"
|
|
46
|
-
import { createTimerWatch, fireTimerWake } from "./timer-watch.mjs"
|
|
46
|
+
import { createTimerWatch, fireTimerWake, createInboxWatch, createInboxTake, inboxBlockedLine, registerInstance, unregisterInstance } from "./timer-watch.mjs"
|
|
47
47
|
import { initTeamState, teamAskCancel, teamAskSubmit } from "./cmd-team.mjs"
|
|
48
48
|
|
|
49
49
|
export { upgradeFailureText, pendingNoticeReady } from "./update-notice.mjs"
|
|
@@ -179,7 +179,36 @@ export async function startTUI(agent, opts = {}) {
|
|
|
179
179
|
// #448①「关闭后补评估」(KD-6):用户自发模态(picker ∕ wizard)全部退场 ⇒ 闩重武装——模态期被
|
|
180
180
|
// 抑制的到期件即达(无在途 / 开关关 ⇒ `sync()` 自判零注册——幂等)。两关闭点(picker 栈空 ∕
|
|
181
181
|
// wizard 退场)同注本回调;抑制本体 = `timer-watch.mjs` `fireTimerWake` 模态门(同谓词 `modalOpen`)。
|
|
182
|
-
|
|
182
|
+
// 跨实例取件闩同点补一次(幂等 —— 自续闩存活不靠它;它换的是「模态关后 ≤ 1 ms 取件」而非「≤ 1 s」)。
|
|
183
|
+
const reevalTimerWake = () => { turnCtx.timerWatch?.sync(); turnCtx.inboxWatch?.sync() }
|
|
184
|
+
|
|
185
|
+
// 跨实例投递面取件闩(MULTI-INSTANCE-COLLAB「取件闩」「消息落法」· D-MI28 · D-MI31 · D-MI34):**会话起点**武装 + 登记名册;
|
|
186
|
+
// 闩**自续**(先重臂再试取件)⇒ 回合起点不撤、回合链尾与模态关闭两处 `sync()` 只是幂等补位;
|
|
187
|
+
// 退出删名册条目。两个谓词各答一件事(住本档转口 `timer-watch.mjs`:`isBusy` = `state.processing`,`ready` =
|
|
188
|
+
// 无面板在场);取件后的开轮面 = `createInboxTake` 的两条去路:**有活挂起窗 ⇒ 入窗队列 + 唤醒**,否则开
|
|
189
|
+
// **普通用户回合**(`autoTurn` 缺省 false——手动态照常走审批面;**恒不带 `resume`**——走 resume 时那一串
|
|
190
|
+
// 不落成 user 消息而消息已离盘 = 静默丢)。
|
|
191
|
+
// `onTake` 的 promise 契约(交接:失败单源 = reject):开轮侧读到 `state.processing` 为真 = 已登记为在飞
|
|
192
|
+
// (resolve);入窗侧消息已进活窗口输入队列(resolve);两者皆否 = 开轮没成(reject)⇒ 核记
|
|
193
|
+
// `ev:inbox-watch-take-lost` + 丢失单源、端壳出逐字丢失行。**拿 `isBusy()` 的一次读数判死是禁止形**
|
|
194
|
+
// (短轮 / 审批悬挂会被误报成丢失)。
|
|
195
|
+
// `onPending(n)` = 待取条数常驻面:本端有一轮在飞且 inbox 有未取消息 ⇒ 状态栏出一段条数(`status-line.mjs`),
|
|
196
|
+
// 归零即摘除;与 `onBlocked` 那条一次性受阻行不是一件事(后者仍由核拼串)。
|
|
197
|
+
turnCtx.inboxWatch = createInboxWatch({
|
|
198
|
+
state,
|
|
199
|
+
onTake: createInboxTake({ state, turn, pushLine }),
|
|
200
|
+
onBlocked: (ms, pending) => pushLine(inboxBlockedLine(ms, pending), C.warn), // D-MI33:门开不了要出声
|
|
201
|
+
onPending: (n) => { // 待取条数→状态面;值未变不重绘(零注入:没变化就不打扰)
|
|
202
|
+
if (state.inboxPending === n) return
|
|
203
|
+
state.inboxPending = n
|
|
204
|
+
render()
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
registerInstance({ cwd: process.cwd() })
|
|
208
|
+
turnCtx.inboxWatch.sync()
|
|
209
|
+
// 正常退出撤闩 + 删名册条目(D-MI28 · 设计「取件闩」CLI 行):退出途多路(/exit · Ctrl+C×2 · 关终端),
|
|
210
|
+
// `exit` 钩子一处全覆盖且恒达(闩是一次性 `unref` 定时器——进程走它也走;此处是本点的字面形态)。
|
|
211
|
+
process.on("exit", () => { turnCtx.inboxWatch?.disarm(); unregisterInstance() })
|
|
183
212
|
|
|
184
213
|
// ---------------------------------------------------------- Slash Commands
|
|
185
214
|
|