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.
- package/CHANGELOG.md +104 -74
- package/README.md +3 -3
- package/package.json +2 -2
- package/src/acp/bridge.mjs +15 -109
- 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/cli/make-agent.mjs +2 -2
- package/src/tui/agent-turn.mjs +6 -1
- package/src/tui/cmd-advisor.mjs +1 -1
- package/src/tui/cmd-config.mjs +27 -4
- package/src/tui/cmd-eng.mjs +48 -83
- 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/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 +12 -6
- package/src/tui/slash-commands.mjs +6 -2
- package/src/tui/status-line.mjs +19 -7
- package/src/tui/timer-watch.mjs +61 -0
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
|
-
// #41 先判后翻(MANIFEST.md §2.8 F2/F3 · KD-M1-21):**ON 方向**先走入口决策树单源
|
|
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) {
|
|
19
|
+
// Preserve the existing engineering entry gate: refusal leaves mode, tokens, PLAN and slot intact.
|
|
20
|
+
let engineeringManifest
|
|
21
|
+
if (enteringEngineering) {
|
|
45
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-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
|
|
package/src/tui/model-picker.mjs
CHANGED
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
* closePicker, renderPickerLines, confirmDelete }(后四者为 pickers.mjs 通用 picker 绑定——闭包入参,环安全)。
|
|
21
21
|
*/
|
|
22
22
|
import { sliceByWidth } from "./render.mjs"
|
|
23
|
-
import { providerSpec, specMatch, resolveCompactThreshold, formatContextK } from "@thincoder/core/config.mjs"
|
|
23
|
+
import { providerSpec, specMatch, resolveCompactThreshold, resolveWorkMode, formatContextK, reloadProviders, configPath } from "@thincoder/core/config.mjs"
|
|
24
24
|
import { saveSession, loadSlotFile } from "@thincoder/core/session.mjs"
|
|
25
25
|
import { carryoverDefaultModel } from "./config-helpers.mjs"
|
|
26
26
|
import { getProviderModels, modelListFailureText, dedupeModels } from "./model-catalog.mjs"
|
|
27
27
|
import { createProviderAdmin, isDerivedProviderHidden, declaredContextText } from "./provider-admin.mjs"
|
|
28
|
+
// L1 列表行构建(崩溃点所在——从本档闭包搬出成可 import 的纯函数;`docs/core/design/PROVIDER.md` §6.29)
|
|
29
|
+
import { buildProviderEntries } from "./provider-entries.mjs"
|
|
28
30
|
|
|
29
31
|
/** createModelPicker(ctx) → { openModelPicker, selectModel, setProviderKey, setModelContextFlow, pickModelForSlot } */
|
|
30
32
|
export function createModelPicker(ctx) {
|
|
@@ -53,10 +55,25 @@ export function createModelPicker(ctx) {
|
|
|
53
55
|
pk.index = restored >= 0 ? restored : Math.min(pk.index, Math.max(0, itemRows.length - 1))
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
/** Level 1: provider list(/model 入口——session 复合两级面)。
|
|
58
|
+
/** Level 1: provider list(/model 入口——session 复合两级面)。
|
|
59
|
+
* 打开即重读盘上渠道(`docs/core/design/PROVIDER.md` §6.30):列表是盘上现况,不是启动时那份——
|
|
60
|
+
* 盘上改完的渠道不必重启就能看见。读失败 ⇒ 出一行错误且**不打开列表**:拿旧表当现况正是
|
|
61
|
+
* 「盘上改了不生效」的形状,开一张盘上不存在的表只是换了个错。 */
|
|
57
62
|
async function openModelPicker() {
|
|
63
|
+
const reload = reloadProviders(agent)
|
|
64
|
+
if (reload.ok !== true) {
|
|
65
|
+
pushLine(`[model] cannot re-read config: ${reload.error} (file: ${configPath})`, C.error)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
58
68
|
for (;;) {
|
|
59
|
-
const entries = buildProviderEntries(
|
|
69
|
+
const entries = buildProviderEntries({
|
|
70
|
+
providers: agent.providers,
|
|
71
|
+
activeProvider: agent.activeProvider,
|
|
72
|
+
activeModel: agent.activeModel,
|
|
73
|
+
dropped: agent.config?.providersDropped,
|
|
74
|
+
isHidden: isDerivedProviderHidden,
|
|
75
|
+
ctxText: declaredContextText,
|
|
76
|
+
})
|
|
60
77
|
const items = entries.filter((e) => e.type === "item")
|
|
61
78
|
const current = items.findIndex(
|
|
62
79
|
(e) => e.action === "open-models" && e.provider === agent.activeProvider)
|
|
@@ -105,39 +122,11 @@ export function createModelPicker(ctx) {
|
|
|
105
122
|
return false
|
|
106
123
|
}
|
|
107
124
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const providers = agent.providers.filter((p) => !isDerivedProviderHidden(p)) // 派生无 key ⇒ 隐藏(TEAM.md §2.4——模型候选面)
|
|
114
|
-
for (const p of providers) {
|
|
115
|
-
const active = p.name === agent.activeProvider
|
|
116
|
-
const shown = active && agent.activeModel ? ` ${agent.activeModel}` : ""
|
|
117
|
-
const marker = active ? "●" : ""
|
|
118
|
-
// A1(第 20 批 §12.5):渠道警示((no key) / (不可用))上移 text——与既有状态标
|
|
119
|
-
// ((ctx …) / ← session)同簇(先例 = provider-admin.mjs setKeyFlow / wizard 的 (added, no key)):
|
|
120
|
-
// 警示不再位于最先牺牲段。note 收窄为 baseURL(补充信息——超宽随行右截断可接受)。
|
|
121
|
-
const sessionNote = active ? " ← session" : ""
|
|
122
|
-
const keyStatus = p.apiKey ? "" : " (no key)"
|
|
123
|
-
const unavailable = p._unavailable ? " (不可用)" : ""
|
|
124
|
-
const ctxTag = ` (ctx ${declaredContextText(p)})`
|
|
125
|
-
entries.push({
|
|
126
|
-
type: "item",
|
|
127
|
-
text: `${p.name.padEnd(12)}${shown}${ctxTag}${keyStatus}${unavailable}${sessionNote}`,
|
|
128
|
-
action: "open-models",
|
|
129
|
-
provider: p.name,
|
|
130
|
-
marker,
|
|
131
|
-
note: p.baseURL,
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
entries.push({ type: "header", text: "Management" })
|
|
135
|
-
entries.push({ type: "item", text: "Add provider…", action: "add" })
|
|
136
|
-
if (providers.length > 1) entries.push({ type: "item", text: "Remove provider…", action: "remove" })
|
|
137
|
-
entries.push({ type: "item", text: "Set / change API key…", action: "key" })
|
|
138
|
-
entries.push({ type: "item", text: "Set context window (K)…", action: "model-context" })
|
|
139
|
-
return entries
|
|
140
|
-
}
|
|
125
|
+
// L1 列表行构建已迁 `thincoder-cli/src/tui/provider-entries.mjs` 的 `buildProviderEntries`
|
|
126
|
+
// (`docs/core/design/PROVIDER.md` §6.29「可见面」)——搬出闭包的唯一目的是让崩溃点
|
|
127
|
+
// `${p.name.padEnd(12)}` 可被用例 import 直测;L1 与用例共用同一个函数。
|
|
128
|
+
// 2026-10-09 清除批:渠道条目不携模型——模型段只显**会话槽**值(仅当前会话渠道),
|
|
129
|
+
// 其余显示回退 = 行 note 的 `baseURL`。
|
|
141
130
|
|
|
142
131
|
/** Level 2 entries(/model 会话面——候选运行期拉取):当前会话行 + 候选区(拉取填充)。
|
|
143
132
|
* 占位行必须存在:showPicker 对 0 item **立即 resolve(null)**(picker 不打开、entries 不可达)——
|
|
@@ -237,8 +226,9 @@ export function createModelPicker(ctx) {
|
|
|
237
226
|
agent.provider = { ...target }
|
|
238
227
|
agent.provider.model = item.model
|
|
239
228
|
// §6.17:auto 派生线随模型跟手——只刷新显示面 compactThresholdResolved,显式键 agent.compactThreshold 永不被改写
|
|
229
|
+
// (档位取本会话当前档:切模型不换模式,但阈值要按当前档的有效窗口算,否则显示面与实际压缩线分家)
|
|
240
230
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
241
|
-
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
|
|
231
|
+
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider, resolveWorkMode(agent.config?.agent)).value
|
|
242
232
|
}
|
|
243
233
|
// 写会话槽(saveSession——槽双字段恒非空)——写回单点在其后(槽先配置后)
|
|
244
234
|
saveSession(agent)
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* (本端不再写旧键);同批替代 = `setModelContextFlow`——按模型写 `providers[].modelContext`,
|
|
18
18
|
* 单位仍是 K(输入 ∥ 存储 ∥ 提示 ∥ 回显四处同口径;端侧零 ×1024——唯一乘点在核)。
|
|
19
19
|
*/
|
|
20
|
-
import { PROVIDER_PRESETS as PRESETS, resolveCompactThreshold } from "@thincoder/core/config.mjs"
|
|
20
|
+
import { PROVIDER_PRESETS as PRESETS, resolveCompactThreshold, resolveWorkMode } from "@thincoder/core/config.mjs"
|
|
21
21
|
import { hasKey } from "@thincoder/core/model-ref.mjs"
|
|
22
22
|
import { normalizeModelKey, positiveInt } from "@thincoder/core/model-context.mjs"
|
|
23
23
|
import { formatDeclaredContextK } from "@thincoder/core/model-specs.mjs"
|
|
@@ -302,8 +302,9 @@ export function createProviderAdmin(ctx) {
|
|
|
302
302
|
if (target.modelContext === undefined) delete agent.provider.modelContext
|
|
303
303
|
else agent.provider.modelContext = target.modelContext
|
|
304
304
|
// §6.17:窗口覆盖后 auto 派生线跟手——只刷新显示面 compactThresholdResolved,显式键永不被改写
|
|
305
|
+
// (按当前档的有效窗口算:tiny 档下窗口覆盖后压缩线仍以 262144 封顶)
|
|
305
306
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
306
|
-
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
|
|
307
|
+
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider, resolveWorkMode(agent.config?.agent)).value
|
|
307
308
|
}
|
|
308
309
|
}
|
|
309
310
|
// 回显串 = 核出词(`128K` / `1M`)——不同时给 token 数(两个数并排又把人绕回单位问题)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provider-entries.mjs — `/model` L1 列表行的构建纯函数(`docs/core/design/PROVIDER.md` §6.29「可见面」)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独成档:崩溃点就在这个函数体里——`${p.name.padEnd(12)}`。装载层漏进一条无 `name` 的
|
|
5
|
+
* 条目(`{ ...null }` 得 `{}`)时,`undefined.padEnd` 抛
|
|
6
|
+
* `Cannot read properties of undefined (reading 'padEnd')`,一条空条目让整条渠道列表不可用。
|
|
7
|
+
* 验收不落在崩溃那一层等于没验那个 bug,所以它从 `model-picker.mjs` 的闭包搬出来,让用例能
|
|
8
|
+
* import 直接喂参数——L1 与用例共用同一个函数,测试不复制实现。
|
|
9
|
+
*
|
|
10
|
+
* 零 TUI 运行时依赖:`isHidden` ∥ `ctxText` 由参数进来(实现住 `provider-admin.mjs`),本档不
|
|
11
|
+
* import `render.mjs` ∥ picker 绑定 ⇒ 用例无需终端。
|
|
12
|
+
*
|
|
13
|
+
* 渲染层不加 `?? ""` 之类的防御:防御留在渲染处会把坏条目重新藏起来——准入过滤是全仓唯一入口
|
|
14
|
+
* (`thincoder-core/config.mjs` 的装载过滤 ∥ `reloadProviders`)。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** 告警行文案(逐字,`docs/core/design/PROVIDER.md` §6.29「新名与文案」):列表首行,指向要改的那一处。 */
|
|
18
|
+
function droppedHeaderText(count) {
|
|
19
|
+
return count === 1
|
|
20
|
+
? '⚠ 1 provider entry skipped — no "name" (fix providers[] in config.json)'
|
|
21
|
+
: `⚠ ${count} provider entries skipped — no "name" (fix providers[] in config.json)`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* buildProviderEntries({ providers, activeProvider, activeModel, dropped, isHidden, ctxText }) → entries[]
|
|
26
|
+
*
|
|
27
|
+
* 参数契约:
|
|
28
|
+
* - 六个键调用方必须写全,不得省略任一键;**真必填只有三项**——`providers`(数组)·
|
|
29
|
+
* `isHidden`(函数 `(provider) => boolean`)· `ctxText`(函数 `(provider) => string`,取该渠道
|
|
30
|
+
* 已声明的上下文回显)。缺一项或类型不符 ⇒ 抛 `TypeError` 点名该参数。
|
|
31
|
+
* - 另三项的「无」是合法值域,不抛:`activeProvider` = `string | null`、`activeModel` =
|
|
32
|
+
* `string | null`(会话槽无值即 `null`),函数内按 `?? null` 归一;`dropped` = `string[] |
|
|
33
|
+
* undefined`(载体只在有丢弃时才存在,缺即无丢弃、与 `[]` 同义),按 `?? []` 归一。
|
|
34
|
+
*
|
|
35
|
+
* 返回:L1 的 `entries[]`。`dropped` 非空 ⇒ **首行**一条 `type:"header"` 告警,其后渠道行与
|
|
36
|
+
* `Management` 管理项;`dropped` 为空 ⇒ 首行即渠道行。
|
|
37
|
+
*
|
|
38
|
+
* 渠道行形状与搬迁前逐键一致(`type` / `text` / `action` / `provider` / `marker` / `note`)——
|
|
39
|
+
* 有 name 的条目一个字节不动;无名条目不进表(装载层已滤掉),也绝不在这里补一个名字。
|
|
40
|
+
*/
|
|
41
|
+
export function buildProviderEntries({
|
|
42
|
+
providers: rawProviders,
|
|
43
|
+
activeProvider: rawActiveProvider,
|
|
44
|
+
activeModel: rawActiveModel,
|
|
45
|
+
dropped: rawDropped,
|
|
46
|
+
isHidden,
|
|
47
|
+
ctxText,
|
|
48
|
+
} = {}) {
|
|
49
|
+
if (!Array.isArray(rawProviders)) {
|
|
50
|
+
throw new TypeError(`buildProviderEntries: "providers" must be an array (got ${rawProviders === null ? "null" : typeof rawProviders})`)
|
|
51
|
+
}
|
|
52
|
+
if (typeof isHidden !== "function") {
|
|
53
|
+
throw new TypeError(`buildProviderEntries: "isHidden" must be a function (provider) => boolean (got ${typeof isHidden})`)
|
|
54
|
+
}
|
|
55
|
+
if (typeof ctxText !== "function") {
|
|
56
|
+
throw new TypeError(`buildProviderEntries: "ctxText" must be a function (provider) => string (got ${typeof ctxText})`)
|
|
57
|
+
}
|
|
58
|
+
const activeProvider = rawActiveProvider ?? null
|
|
59
|
+
const activeModel = rawActiveModel ?? null
|
|
60
|
+
const dropped = rawDropped ?? []
|
|
61
|
+
|
|
62
|
+
const entries = []
|
|
63
|
+
if (dropped.length) entries.push({ type: "header", text: droppedHeaderText(dropped.length) })
|
|
64
|
+
|
|
65
|
+
const providers = rawProviders.filter((p) => !isHidden(p)) // 派生无 key ⇒ 隐藏(TEAM.md §2.4——模型候选面)
|
|
66
|
+
for (const p of providers) {
|
|
67
|
+
const active = p.name === activeProvider
|
|
68
|
+
const shown = active && activeModel ? ` ${activeModel}` : ""
|
|
69
|
+
const marker = active ? "●" : ""
|
|
70
|
+
// A1(第 20 批 §12.5):渠道警示((no key) / (不可用))在 text 里,与既有状态标
|
|
71
|
+
// ((ctx …) / ← session)同簇;note 收窄为 baseURL(补充信息——超宽随行右截断可接受)。
|
|
72
|
+
const sessionNote = active ? " ← session" : ""
|
|
73
|
+
const keyStatus = p.apiKey ? "" : " (no key)"
|
|
74
|
+
const unavailable = p._unavailable ? " (不可用)" : ""
|
|
75
|
+
const ctxTag = ` (ctx ${ctxText(p)})`
|
|
76
|
+
entries.push({
|
|
77
|
+
type: "item",
|
|
78
|
+
text: `${p.name.padEnd(12)}${shown}${ctxTag}${keyStatus}${unavailable}${sessionNote}`,
|
|
79
|
+
action: "open-models",
|
|
80
|
+
provider: p.name,
|
|
81
|
+
marker,
|
|
82
|
+
note: p.baseURL,
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
entries.push({ type: "header", text: "Management" })
|
|
87
|
+
entries.push({ type: "item", text: "Add provider…", action: "add" })
|
|
88
|
+
if (providers.length > 1) entries.push({ type: "item", text: "Remove provider…", action: "remove" })
|
|
89
|
+
entries.push({ type: "item", text: "Set / change API key…", action: "key" })
|
|
90
|
+
entries.push({ type: "item", text: "Set context window (K)…", action: "model-context" })
|
|
91
|
+
return entries
|
|
92
|
+
}
|
package/src/tui/render-loop.mjs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { countConvLines, renderRows } from "./render-frame.mjs"
|
|
17
17
|
import { historyReading, tokenRatioOf } from "@thincoder/core/token-window.mjs"
|
|
18
|
-
import {
|
|
18
|
+
import { resolveWorkMode, effectiveWindow } from "@thincoder/core/config.mjs"
|
|
19
19
|
import { ansi, C } from "./ansi.mjs"
|
|
20
20
|
import { isTuiActive } from "./tui-lifecycle.mjs" // F-2 渲染抑制守卫(RESIZE-MOUSE-LEAK-FIX)
|
|
21
21
|
|
|
@@ -23,8 +23,10 @@ const MIN_RENDER_INTERVAL_MS = 16
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* 上下文读数缓存(CONTEXT-COMPACTION.md §6.16.4 单源):值全部来自核 `historyReading`,本档零自算式。
|
|
26
|
-
* 失效键三项 = `history.length` · `ratio` ·
|
|
27
|
-
* (槽样本恢复 / 口径版本切换),窗口可在切模型 ∥
|
|
26
|
+
* 失效键三项 = `history.length` · `ratio` · **有效窗口**——只按长度会留陈旧读数:校准比可在长度不变时变
|
|
27
|
+
* (槽样本恢复 / 口径版本切换),窗口可在切模型 ∥ 改人工声明时变,**且切档位也变**(tiny 上限——
|
|
28
|
+
* `CONTEXT-COMPACTION.md` §2.1)。键取模型窗口就会在切档后继续命中旧缓存:1M 模型切进 tiny 模型窗口不变,
|
|
29
|
+
* `pct` 于是沿用旧分母,「切出即解除」在状态行这一格上不成立。三项全等 ⇒ **原引用**(零重算);
|
|
28
30
|
* 否则重取核读数。为何不每帧调核:`estimateTokens` 是全史线性扫描,每帧跑一次是渲染热路径的净开销。
|
|
29
31
|
* **三项覆盖不到的一类变化(登记)**:内容变而长度不变——`pruneStaleToolOutputs` 原位换掉 tool 内容
|
|
30
32
|
* (`thincoder-core/context-degrade.mjs:30`-35:数组长度不变、估算骤降)与 `applySession` 整体换机读线
|
|
@@ -36,10 +38,14 @@ const MIN_RENDER_INTERVAL_MS = 16
|
|
|
36
38
|
export function ctxCacheOf(agent, prev) {
|
|
37
39
|
const history = agent?.history ?? []
|
|
38
40
|
const ratio = tokenRatioOf(agent)
|
|
39
|
-
|
|
41
|
+
// 档位自 agent 现取(§2.3);窗口用**有效窗口**——它是失效键的第三项(也是预算的输入)。
|
|
42
|
+
const workMode = resolveWorkMode(agent?.config?.agent)
|
|
43
|
+
const window = effectiveWindow(agent?.provider, workMode)
|
|
40
44
|
if (prev && prev.len === history.length && prev.ratio === ratio && prev.window === window) return prev
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
// 一次核读数出四个值(§2.5):分母是 `limit`(用户实际可填的量),`threshold` 随读带出供告警判据用——
|
|
46
|
+
// 状态行不再拿窗口当分母、也不再自造 `ctxPct >= 80` 这一档。
|
|
47
|
+
const { tokens, pct, limit, threshold } = historyReading(history, agent?.provider, ratio, workMode)
|
|
48
|
+
return { len: history.length, ratio, window, tokens, pct, limit, threshold }
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
/**
|
|
@@ -35,7 +35,7 @@ import { handleHelpCommand } from "./cmd-help.mjs"
|
|
|
35
35
|
import { handleUpgradeCommand } from "./cmd-upgrade.mjs"
|
|
36
36
|
import { handleFoldCommand } from "./cmd-fold.mjs"
|
|
37
37
|
import { handleUndoCommand } from "./cmd-undo.mjs"
|
|
38
|
-
import { handleEngCommand } from "./cmd-eng.mjs"
|
|
38
|
+
import { handleEngCommand, handleTinyCommand, handleNormalCommand } from "./cmd-eng.mjs"
|
|
39
39
|
import { handleTeamCommand } from "./cmd-team.mjs" // 团队登录(登录面补全批——/team login ∥ logout ∥ status)
|
|
40
40
|
// 派生条目隐藏判据单源(TEAM.md §2.4——#1223:/model·/submodel Tab 补全面过滤)
|
|
41
41
|
import { isDerivedProviderHidden } from "./provider-admin.mjs"
|
|
@@ -43,7 +43,9 @@ import { isDerivedProviderHidden } from "./provider-admin.mjs"
|
|
|
43
43
|
export const SLASH_COMMANDS = [
|
|
44
44
|
{ name: "/plan", group: "Agent", desc: "toggle plan mode (design first, then implement)" },
|
|
45
45
|
{ name: "/auto", group: "Agent", desc: "toggle auto-approve" },
|
|
46
|
-
{ name: "/eng", group: "Agent", desc: "toggle engineering
|
|
46
|
+
{ name: "/eng", group: "Agent", desc: "toggle engineering ↔ normal work mode" },
|
|
47
|
+
{ name: "/tiny", group: "Agent", desc: "toggle tiny ↔ normal work mode" },
|
|
48
|
+
{ name: "/normal", group: "Agent", desc: "select normal work mode" },
|
|
47
49
|
{ name: "/advisor", group: "Agent", desc: "advisor settings (model, thinking, review gate)" },
|
|
48
50
|
{ name: "/model", group: "Agent", desc: "select model & manage providers" },
|
|
49
51
|
{ name: "/submodel", group: "Agent", desc: "subagent model per type (explore/plan/coder/eng-coder/eng-designer)" },
|
|
@@ -102,6 +104,8 @@ export const HANDLERS = {
|
|
|
102
104
|
"/fold": handleFoldCommand,
|
|
103
105
|
"/undo": handleUndoCommand,
|
|
104
106
|
"/eng": handleEngCommand,
|
|
107
|
+
"/tiny": handleTinyCommand,
|
|
108
|
+
"/normal": handleNormalCommand,
|
|
105
109
|
"/extract": handleExtractCommand,
|
|
106
110
|
"/help": handleHelpCommand,
|
|
107
111
|
}
|