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
|
@@ -140,7 +140,18 @@ export function digestTraceLines(rec, startN = null) {
|
|
|
140
140
|
export function synthSubTask(rec) {
|
|
141
141
|
const meta = rec?.meta ?? {}
|
|
142
142
|
const rows = Array.isArray(rec?.rows) ? rec.rows : []
|
|
143
|
-
|
|
143
|
+
// 行首子标(跨端恢复——承接细则 = `docs/cli/design/TUI-SESSION-VIEW.md` §6「行首子标」条):
|
|
144
|
+
// 条目带 `sub` ⇒ 行文 = `<sub> · <正文>`(与 VSC ∥ 桌面 `span.advisor-sub` 同一串:同字面 ∥ 同位置 ∥ 同分隔符);
|
|
145
|
+
// 不带 ⇒ 原样(存量记录的子标烙在 `text` 内,逐字不变)。子标在此合成——本端渲染面逐字消费 `b.text`,零改。
|
|
146
|
+
// 空正文行 = 两端同判丢弃:跳过判据 = `text` 为空,与 `sub` 在场无关(与 VSC 派生面 `rowsOf` 同一谓词)。
|
|
147
|
+
const blocks = []
|
|
148
|
+
for (const r of rows) {
|
|
149
|
+
const text = String(r?.text ?? "")
|
|
150
|
+
if (text === "") continue
|
|
151
|
+
const kind = typeof r?.kind === "string" ? r.kind : "text"
|
|
152
|
+
const sub = typeof r?.sub === "string" && r.sub ? r.sub : null
|
|
153
|
+
blocks.push({ kind, text: sub === null ? text : `${sub} · ${text}` })
|
|
154
|
+
}
|
|
144
155
|
const doneAt = Number.isFinite(meta.doneAt) ? meta.doneAt : null
|
|
145
156
|
const started = Number.isFinite(meta.startedAt) ? meta.startedAt : (doneAt ?? 0)
|
|
146
157
|
return {
|
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
|
@@ -14,12 +14,40 @@
|
|
|
14
14
|
* so recomputing the frame each paint is cheap.
|
|
15
15
|
*/
|
|
16
16
|
import { countConvLines, renderRows } from "./render-frame.mjs"
|
|
17
|
-
import {
|
|
17
|
+
import { historyReading, tokenRatioOf } from "@thincoder/core/token-window.mjs"
|
|
18
|
+
import { resolveWorkMode, effectiveWindow } from "@thincoder/core/config.mjs"
|
|
18
19
|
import { ansi, C } from "./ansi.mjs"
|
|
19
20
|
import { isTuiActive } from "./tui-lifecycle.mjs" // F-2 渲染抑制守卫(RESIZE-MOUSE-LEAK-FIX)
|
|
20
21
|
|
|
21
22
|
const MIN_RENDER_INTERVAL_MS = 16
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* 上下文读数缓存(CONTEXT-COMPACTION.md §6.16.4 单源):值全部来自核 `historyReading`,本档零自算式。
|
|
26
|
+
* 失效键三项 = `history.length` · `ratio` · **有效窗口**——只按长度会留陈旧读数:校准比可在长度不变时变
|
|
27
|
+
* (槽样本恢复 / 口径版本切换),窗口可在切模型 ∥ 改人工声明时变,**且切档位也变**(tiny 上限——
|
|
28
|
+
* `CONTEXT-COMPACTION.md` §2.1)。键取模型窗口就会在切档后继续命中旧缓存:1M 模型切进 tiny 模型窗口不变,
|
|
29
|
+
* `pct` 于是沿用旧分母,「切出即解除」在状态行这一格上不成立。三项全等 ⇒ **原引用**(零重算);
|
|
30
|
+
* 否则重取核读数。为何不每帧调核:`estimateTokens` 是全史线性扫描,每帧跑一次是渲染热路径的净开销。
|
|
31
|
+
* **三项覆盖不到的一类变化(登记)**:内容变而长度不变——`pruneStaleToolOutputs` 原位换掉 tool 内容
|
|
32
|
+
* (`thincoder-core/context-degrade.mjs:30`-35:数组长度不变、估算骤降)与 `applySession` 整体换机读线
|
|
33
|
+
* (`thincoder-core/session-lifecycle.mjs:119`:长度可与前一会话巧合相等)。这两时刻状态行沿用变化前的
|
|
34
|
+
* 百分比,直到下一次追回消息使 `len` 变;闭这项需要第四个内容版本键(机制变更,不自取)。
|
|
35
|
+
* 首帧:`state.ctxCache` 初值 `{ len: -1, tokens: 0 }`(`tui-state.mjs`)长度恒不等 ⇒ 必落重算支,
|
|
36
|
+
* 由此补齐 `ratio` / `window` / `pct`;未补齐前 `pct` = `undefined` ⇒ 状态行显示门(`ctxPct > 0`)为假,该段不显。
|
|
37
|
+
*/
|
|
38
|
+
export function ctxCacheOf(agent, prev) {
|
|
39
|
+
const history = agent?.history ?? []
|
|
40
|
+
const ratio = tokenRatioOf(agent)
|
|
41
|
+
// 档位自 agent 现取(§2.3);窗口用**有效窗口**——它是失效键的第三项(也是预算的输入)。
|
|
42
|
+
const workMode = resolveWorkMode(agent?.config?.agent)
|
|
43
|
+
const window = effectiveWindow(agent?.provider, workMode)
|
|
44
|
+
if (prev && prev.len === history.length && prev.ratio === ratio && prev.window === window) return prev
|
|
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 }
|
|
49
|
+
}
|
|
50
|
+
|
|
23
51
|
/**
|
|
24
52
|
* Create the render loop closure. Returns { render, scheduleRender }.
|
|
25
53
|
*
|
|
@@ -86,9 +114,7 @@ export function createRenderLoop(state, agent, ctx, pushLine, write = (s) => pro
|
|
|
86
114
|
// Clamp scroll (bookkeeping for the status-bar hint; renderConversation clamps internally too)
|
|
87
115
|
state.scroll = Math.min(state.scroll, Math.max(0, countConvLines(state, dims.cols, dims.rows) - layout.panels.conversation.h))
|
|
88
116
|
|
|
89
|
-
|
|
90
|
-
state.ctxCache = { len: agent.history.length, tokens: estimateTokens(agent.history) }
|
|
91
|
-
}
|
|
117
|
+
state.ctxCache = ctxCacheOf(agent, state.ctxCache)
|
|
92
118
|
|
|
93
119
|
// Deferred upgrade notice — pop when no overlay is active
|
|
94
120
|
if (ctx.pendingNoticeReady(state)) {
|
|
@@ -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
|
}
|
package/src/tui/status-line.mjs
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { ansi, C } from "./ansi.mjs"
|
|
12
12
|
import { sliceByWidth, stringWidth } from "./render.mjs"
|
|
13
|
-
import { providerSpec } from "@thincoder/core/config.mjs"
|
|
14
13
|
import { t } from "@thincoder/core/i18n.mjs" // 停滞轻显形(TUI.md §7.7):句式键 status.quiet——词面单源(CLI 直取)
|
|
14
|
+
import { resolveWorkMode } from "@thincoder/core/config.mjs" // 档名读取口归一单源(CONFIG §5.4——旧值 minimal 读成 tiny)
|
|
15
15
|
import { isRealUserMsg } from "@thincoder/core/history-window.mjs" // B6 回退链:首条真实 user 消息谓词(纯件单源)
|
|
16
16
|
import { isYesNoModal } from "./interaction.mjs" // X8 跟进①:y/n-only 族判据单源
|
|
17
17
|
|
|
@@ -53,7 +53,8 @@ export function renderStatus(state, agent, cols, slashCommands) {
|
|
|
53
53
|
const planBanner = agent.planMode ? `${C.tool} PLAN${ansi.reset}${ansi.dim}│` : ""
|
|
54
54
|
const advisorBanner = agent.config?.advisor?.guard === true ? `${C.advisor} ADVISOR${ansi.reset}${ansi.dim}│` : ""
|
|
55
55
|
const engBanner = agent.config?.agent?.engineering ? `${C.advisor} ENG${ansi.reset}${ansi.dim}│` : ""
|
|
56
|
-
const
|
|
56
|
+
const tinyBanner = resolveWorkMode(agent.config?.agent) === "tiny" ? `${C.tool} TINY${ansi.reset}${ansi.dim}│` : ""
|
|
57
|
+
const bannerPrefix = (agent.planMode ? " PLAN│ " : "") + (agent.autoApprove ? " AUTO│ " : "") + (agent.config?.advisor?.guard === true ? " ADVISOR│ " : "") + (agent.config?.agent?.engineering ? " ENG│ " : "") + (resolveWorkMode(agent.config?.agent) === "tiny" ? " TINY│ " : "")
|
|
57
58
|
// 第 33 批(TUI §14.3(b)/(c)):attention 态 = chip 行首 + 整行注意力色对包裹(blocked >
|
|
58
59
|
// awaiting;blocked 内 permission > question——与按键分发优先级同序);平态零注入。
|
|
59
60
|
const kind = attentionKind(state)
|
|
@@ -62,7 +63,7 @@ export function renderStatus(state, agent, cols, slashCommands) {
|
|
|
62
63
|
const attentionPad = chip ? `${chip} │ ` : ""
|
|
63
64
|
// 宽度预算(N9④):chip 占位计入——整行仍 ≤ cols − 1(既有口径)。
|
|
64
65
|
const statusMax = cols - 1 - (bannerPrefix ? stringWidth(bannerPrefix) : 0) - (attentionPad ? stringWidth(attentionPad) : 0)
|
|
65
|
-
const inner = `${ansi.dim}${planBanner}${autoBanner}${advisorBanner}${engBanner}${sliceByWidth(statusLine, Math.max(10, statusMax))}`
|
|
66
|
+
const inner = `${ansi.dim}${planBanner}${autoBanner}${advisorBanner}${engBanner}${tinyBanner}${sliceByWidth(statusLine, Math.max(10, statusMax))}`
|
|
66
67
|
// 负向锁(§14.3):attention 为 null ⇒ 半态路径逐字节等价(不经包裹 / 零字节注入)。
|
|
67
68
|
if (!chip) return `${inner}${ansi.reset}`
|
|
68
69
|
// 底色存活(§14.3):既有内容含内部 ansi.reset(banner / ctx 警示段)——每次内部复位后
|
|
@@ -141,13 +142,18 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
141
142
|
? ` ${t("status.quiet", { s: Math.floor((Date.now() - lastOut) / 1000) })}`
|
|
142
143
|
: ""
|
|
143
144
|
const statusText = state.processing ? `${state.status}${toolHint}${elapsed}${quietHint}` : state.status
|
|
144
|
-
// 2026-09-02 Q1(SESSION.md §6.8):provider 可为 null —— providerSpec(null) 保守 128K
|
|
145
|
-
// 2026-09-02 §15
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
// 2026-09-02 Q1(SESSION.md §6.8):provider 可为 null —— 核 `providerSpec(null)` 保守 128K 不抛错。
|
|
146
|
+
// 2026-09-02 §15 ∥ context-percent-parity:窗口 / 校准比 / 两值全在核 `historyReading` 内解析(`ctxCacheOf` 缓出)——
|
|
147
|
+
// 本段零自算式,只格式化核读数的返回值;零值不显示门 `ctxPct > 0` 留在端侧(空历史口径已登记)。
|
|
148
|
+
// CONTEXT-COMPACTION.md §2.5「显示与判定同基准」:分母 = `limit`(用户实际可填的量);告警判据 = `tokens >= threshold`
|
|
149
|
+
// (同一次读数带出的压缩线),不再用魔数 `ctxPct >= 80`——判定与显示读同一个数,端侧不各发明一档阈值。
|
|
150
|
+
const ctxPct = state.ctxCache.pct
|
|
151
|
+
const ctxTokens = state.ctxCache.tokens
|
|
152
|
+
const ctxTokensHint = ctxTokens > 0 ? ` ${fmtK(ctxTokens)}` : ""
|
|
153
|
+
const threshold = state.ctxCache.threshold
|
|
154
|
+
const ctxWarn = Number.isFinite(threshold) && ctxTokens >= threshold
|
|
149
155
|
const ctxHint = ctxPct > 0
|
|
150
|
-
?
|
|
156
|
+
? ctxWarn ? ` │ ${ansi.reset}${C.warn}context ${ctxPct}%${ctxTokensHint}${ansi.reset}${ansi.dim}` : ` │ context ${ctxPct}%${ctxTokensHint}` : ""
|
|
151
157
|
// INPUT-LOCK-ASYNC(C'——F-3):busy(processing 含 digest)状态栏提示——取代旧排队提示
|
|
152
158
|
// (F-7 已删);F16(TUI.md §7.5)**四态分流**(queue-visible 批 2026-09-24):队列非空 ⇒
|
|
153
159
|
// 条数段(dim 段样式 · 零注意力色对——F13 豁免 · 消费即消失);队空 ⇒ 按 busy 面分排队句
|
|
@@ -172,7 +178,12 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
172
178
|
// titleHint 前)——取值 = `agent._pendingTimers` 活读(每帧 recompute / 零缓存副本 / 不显倒计时);
|
|
173
179
|
// 零在途 ⇒ 零注入(负向锁——半态逐字节等价);到期态(任一在途项已过期未送达)⇒ 同段警示色。
|
|
174
180
|
const timers = agent._pendingTimers ?? []
|
|
175
|
-
const timerHint = timers.length === 0 ? "" : ` │ ${timers.some((t) => t.expiresAt <= Date.now()) ? `${ansi.reset}${C.warn}
|
|
181
|
+
const timerHint = timers.length === 0 ? "" : ` │ ${timers.some((t) => t.expiresAt <= Date.now()) ? `${ansi.reset}${C.warn}timer ${timers.length}${ansi.reset}${ansi.dim}` : `timer ${timers.length}`}`
|
|
182
|
+
// 跨实例待取提示(跨实例取件闩·等待期提示 —— `docs/cli/design/TUI.md`「4. 状态栏与活动」):本端有一轮在飞且
|
|
183
|
+
// inbox 里有未取消息 ⇒ 状态段出一段待取条数(沿「已排队 N 条消息」一脉,同段样式);归零即摘除(负向锁——
|
|
184
|
+
// 零条 ∥ 非在飞 ⇒ 零注入,整行逐字节等价)。值 = `onPending` 每拍交来的读数(`index.mjs` 写 `state.inboxPending`)。
|
|
185
|
+
const inboxN = state.inboxPending ?? 0
|
|
186
|
+
const inboxPendingHint = state.processing && inboxN > 0 ? ` │ 待取 ${inboxN} 条消息` : ""
|
|
176
187
|
// D8(2026-09-21 块标题行对齐批——会话标题常显 · `docs/cli/design/TUI.md` §7.4):状态段簇尾
|
|
177
188
|
// (ledgerHint 后、键位组前);取值 = `agent.title` 活读(每帧 recompute)· 40 列截断。
|
|
178
189
|
// B6 消(#677):空白 ⇒ 回退链值(对位 VSC 顶栏——生成前 ∕ 失败期两端同值;值逐字,行级超宽走 statusMax)。
|
|
@@ -181,7 +192,7 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
181
192
|
const titleHint = ` │ ${titleShown}`
|
|
182
193
|
// 团队登录态段(登录面补全批 · `docs/cli/design/TUI.md` §7.8):簇尾末位(titleHint 后、`│ <enterHint>` 前)
|
|
183
194
|
const teamHint = teamSegmentHint(state.team)
|
|
184
|
-
return ` ${statusText}${taskHint}${turnHint}${tokenHint}${ctxHint}${scrollHint}${ledgerHint}${timerHint}${titleHint}${teamHint} │ ${enterHint} │ /: commands │ wheel/PgUp/PgDn: scroll │ Ctrl+I: inject │ Ctrl+C: exit (×2)`
|
|
195
|
+
return ` ${statusText}${taskHint}${turnHint}${tokenHint}${ctxHint}${scrollHint}${ledgerHint}${timerHint}${inboxPendingHint}${titleHint}${teamHint} │ ${enterHint} │ /: commands │ wheel/PgUp/PgDn: scroll │ Ctrl+I: inject │ Ctrl+C: exit (×2)`
|
|
185
196
|
}
|
|
186
197
|
|
|
187
198
|
/** 团队状态段(TUI.md §7.8——三态闭集):未登录 ⇒ `""`(**负控:零注入——整行逐字节等价**);
|
package/src/tui/timer-watch.mjs
CHANGED
|
@@ -12,10 +12,14 @@ import {
|
|
|
12
12
|
fireTimerWake as coreFireTimerWake,
|
|
13
13
|
timerWakeEnabled,
|
|
14
14
|
} from "@thincoder/core/agent/timers.mjs"
|
|
15
|
+
// 跨实例投递面(MULTI-INSTANCE-COLLAB「取件闩」「消息落法」):取件闩 + 消息形态 + 名册——核转口(本档零自持闩)。
|
|
16
|
+
import { createInboxWatch as coreCreateInboxWatch, crossMessageText, inboxTakeLostLine, inboxBlockedLine } from "@thincoder/core/instance-inbox-watch.mjs"
|
|
17
|
+
import { registerInstance, unregisterInstance } from "@thincoder/core/instance-registry.mjs"
|
|
15
18
|
import { C } from "./ansi.mjs"
|
|
16
19
|
import { REMINDER_CAP } from "./tool-display.mjs"
|
|
17
20
|
|
|
18
21
|
export { timerWakeEnabled } // 判据单源转口(§6.30.3 门三件③ D-TW5):默认开——只有显式 `false` 才关(键 `agent.timerWake`)
|
|
22
|
+
export { registerInstance, unregisterInstance, crossMessageText, inboxTakeLostLine, inboxBlockedLine }
|
|
19
23
|
|
|
20
24
|
/** 「唤醒会武装」判据(`docs/cli/design/TUI.md` §7.1 awaiting 行除外 / §7.2 置位谓词):主 agent 在途 timer
|
|
21
25
|
* 非空 ∧ 开关开 ⇒ 自动续跑在途(不计 attention / 闩会在回合链尾武装)。 */
|
|
@@ -49,6 +53,63 @@ export function modalOpen(state) {
|
|
|
49
53
|
return state?.picker != null || state?.wizard != null || state?.teamAsk != null
|
|
50
54
|
}
|
|
51
55
|
|
|
56
|
+
/** 跨实例取件闩(MULTI-INSTANCE-COLLAB「取件闩」· D-MI28 ∥ D-MI31 ∥ D-MI34):核 `createInboxWatch` 转口。
|
|
57
|
+
*
|
|
58
|
+
* **两个谓词各答一件事**:
|
|
59
|
+
* ① `isBusy` = **已有一轮在飞**,只认 `state.processing`。挂起窗(`state.suspended` ∥ `state._suspPending`)不算——
|
|
60
|
+
* 窗口在跑不等于回合在跑,把窗口算忙就是「有子代理在跑就永远收不到消息」。窗口在场时取件走 `onTake` 的入窗
|
|
61
|
+
* 一支(见 `createInboxTake`),不在这里拦。
|
|
62
|
+
* ② `ready` = 这一端此刻能不能开一轮 = **无用户自发模态在场**(`modalOpen` 为假)。面板在场不是「忙」,是
|
|
63
|
+
* 「此刻别插一轮」——混成一个就分不出该等什么。受阻因由因此从 `busy` 变 `carrier`(受阻行文案不变)。
|
|
64
|
+
* 载体(回合面)与会话同建同毁 ⇒ 除面板外无假侧(设计「取件闩」的两端落点:CLI 的 ready 只由 `modalOpen` 闸住,
|
|
65
|
+
* 「CLI 恒真」指的是载体恒有,不是 ready 恒真)。
|
|
66
|
+
*
|
|
67
|
+
* `onTake` = 取件后开轮面(普通用户回合:`autoTurn` 缺省 false——手动态照常走审批面),**返回 promise**
|
|
68
|
+
* (resolve = 有着落;reject = 开轮没成——失败单源,见核档交接契约);**不收 agent**——载体住本档闭包捕获
|
|
69
|
+
* (D-MI34:核闩不从端壳对象上推载体)。体 = `createInboxTake`(两条去路)。
|
|
70
|
+
* `onBlocked(ms, pending)` = 受阻跨阈可见行 ∥ `onPending(n)` = 待取条数常驻面(接线 = `index.mjs`)。 */
|
|
71
|
+
export function createInboxWatch({ state, onTake, onBlocked = null, onPending = null, timer = setTimeout, clear = clearTimeout } = {}) {
|
|
72
|
+
return coreCreateInboxWatch({
|
|
73
|
+
ready: () => !modalOpen(state), // 面板在场 = 此刻别插一轮(不是「忙」)
|
|
74
|
+
isBusy: () => Boolean(state?.processing), // 只认在飞回合:挂起窗不算忙
|
|
75
|
+
onTake,
|
|
76
|
+
onBlocked,
|
|
77
|
+
onPending,
|
|
78
|
+
timer,
|
|
79
|
+
clear,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 取件后开轮面(`onTake` 的体 · CLI 落点):两条去路——**有活挂起窗 ⇒ 入窗队列 + 唤醒**(窗在步边界起轮,
|
|
84
|
+
* 宿主 `turn` 零调用),否则开**普通用户回合**(`autoTurn` 缺省 false——手动态照常走审批面)。
|
|
85
|
+
* 返回 promise:resolve = 消息有着落(这一轮已登记为在飞 ∥ 已进活窗口的输入队列——窗口先退出则残项由挂起会话
|
|
86
|
+
* 出窗回填 `state.pendingInput`,宿主队列本就由回合尾兜底与步边界取批消费);reject = 没有去路(开轮没成)。
|
|
87
|
+
* **恒不带 `resume`**:走 resume 时那一串不落成 user 消息,而消息取件时已离盘 ⇒ 静默丢。
|
|
88
|
+
* @param {{ state: object, turn: Function, pushLine: Function }} p */
|
|
89
|
+
export function createInboxTake({ state, turn, pushLine }) {
|
|
90
|
+
return (messages) => {
|
|
91
|
+
const text = crossMessageText(messages)
|
|
92
|
+
// ① 已开的挂起窗 ∥ 打开在即的释放窗口(与 `key-handler-busy.mjs` ∥ `key-handler-edit.mjs` 的入队判据同形):
|
|
93
|
+
// 进窗输入队列 + 唤醒核句柄(与 Enter 入队同数组、同唤醒面)。`_suspPending` = 上一轮尾部仍在跑
|
|
94
|
+
// (标题生成 ∥ 蒸馏 flush ∥ 落盘)、挂起会话尚未启动的窗口——那一拍若开顶层回合,就是两个 runAgent 循环同时写
|
|
95
|
+
// 同一份 history(`_suspPending` 本就是为挡这个而设的)。此时 `_suspWake` 可能仍为 null(会话未起)⇒ 可选调用;
|
|
96
|
+
// 消息留在队列,会话启动后按输入优先消费(兜底径同在:池空时回合尾直接取)。
|
|
97
|
+
if (state?.suspended === true || state?._suspPending === true) {
|
|
98
|
+
state.pendingInput ??= []
|
|
99
|
+
state.pendingInput.push(text)
|
|
100
|
+
state._suspWake?.()
|
|
101
|
+
return Promise.resolve()
|
|
102
|
+
}
|
|
103
|
+
// ② 无窗:开普通用户回合(`turn()` 的同步前缀已置 `state.processing` ⇒ 返回时即可读)
|
|
104
|
+
const run = turn(text, {})
|
|
105
|
+
// 回合内错误照旧可见(不是「开轮没成」——processing 已置 ⇒ 这一轮真的开了)
|
|
106
|
+
void run.catch((e) => pushLine(`[error] ${e?.message ?? e}`, C.error))
|
|
107
|
+
if (state.processing === true) return Promise.resolve()
|
|
108
|
+
pushLine(inboxTakeLostLine(messages), C.warn) // D-MI32:消息已离盘 ⇒ 只能当场明说
|
|
109
|
+
return Promise.reject(new Error("inbox-watch: turn did not start"))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
52
113
|
/**
|
|
53
114
|
* 空闲闩触发(§6.30.3 开轮两处① = 核策略 + 端两缝——B3 改指 §6.30.16):**非空闲零动作**(processing ∥
|
|
54
115
|
* suspended ∥ `_suspPending` ∥ `modalOpen`——在途表零触碰,链尾重同步再武装);**模态期抑制**(#448① KD-6):
|
package/src/tui/tui-state.mjs
CHANGED
|
@@ -36,7 +36,7 @@ export function createTuiState({ cols, rows, agent }) {
|
|
|
36
36
|
tasks: agent.tasks ?? [], // task list from task tool (progress shown in status bar); carried over on session restore, auto-collapsed when all done
|
|
37
37
|
dims: makeDimsState({ cols: startupCols, rows: startupRows }), // terminal dims single source (Windows ConPTY instability, 2026-08-30) — seeded pre-raw-mode, re-sampled by event hooks only (startup retry / resize / idle watchdog)
|
|
38
38
|
tokens: { prompt: 0, completion: 0, cacheHit: 0, cacheMiss: 0, reasoningTokens: 0 }, // cumulative token usage (shown in status bar)
|
|
39
|
-
ctxCache: { len: -1, tokens: 0 }, // context
|
|
39
|
+
ctxCache: { len: -1, tokens: 0 }, // context reading cache (core `historyReading`; estimateTokens is O(n)). Invalidation keys = len · ratio · window (`ctxCacheOf`, render-loop.mjs); `len: -1` never matches ⇒ the first frame fills ratio / window / pct
|
|
40
40
|
reasoning: "", // thinking stream buffer (dimmed display)
|
|
41
41
|
completion: null, // Tab completion state { candidates, index }
|
|
42
42
|
|