thincoder 0.12.60 → 0.12.62
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 +49 -2
- package/README.md +8 -6
- package/bin/thincoder.mjs +38 -124
- package/package.json +3 -2
- package/src/abort-provenance.mjs +116 -0
- package/src/acp/bridge.mjs +38 -17
- package/src/acp.mjs +19 -6
- package/src/advisor/citations.mjs +83 -21
- package/src/advisor/compaction.mjs +174 -0
- package/src/advisor/loop.mjs +293 -0
- package/src/advisor/messages.mjs +36 -134
- package/src/advisor/project-context.mjs +194 -0
- package/src/advisor/repos.mjs +17 -40
- package/src/advisor/run.mjs +124 -329
- package/src/advisor/truncate.mjs +57 -0
- package/src/advisor.mjs +3 -2
- package/src/agent/completion.mjs +1 -1
- package/src/agent/dispatch.mjs +47 -12
- package/src/agent/helpers.mjs +71 -13
- package/src/agent/record-results.mjs +13 -5
- package/src/agent/relay-prefix.mjs +39 -0
- package/src/agent/run-stages.mjs +24 -7
- package/src/agent/setup-reminders.mjs +16 -9
- package/src/agent/setup.mjs +92 -128
- package/src/agent/spawn-child.mjs +43 -11
- package/src/agent-tools/advisor-async.mjs +70 -180
- package/src/agent-tools/advisor-settle.mjs +231 -0
- package/src/agent-tools/advisor.mjs +69 -20
- package/src/agent-tools/async-settle.mjs +13 -0
- package/src/agent-tools/batch-segment.mjs +195 -0
- package/src/agent-tools/consult.mjs +28 -10
- package/src/agent-tools/design-token.mjs +14 -1
- package/src/agent-tools/digest-budget.mjs +76 -0
- package/src/agent-tools/eng.mjs +3 -3
- package/src/agent-tools/escalate-async.mjs +22 -13
- package/src/agent-tools/read-history.mjs +31 -6
- package/src/agent-tools/review-streak.mjs +93 -0
- package/src/agent-tools/settings.mjs +130 -17
- package/src/agent-tools/subagent-actions.mjs +18 -6
- package/src/agent-tools/subagent-async.mjs +66 -14
- package/src/agent-tools/subagent-panel.mjs +22 -15
- package/src/agent-tools/subagent-run.mjs +10 -7
- package/src/agent-tools/subagent-scheduler.mjs +57 -8
- package/src/agent-tools/subagent-spawn.mjs +69 -16
- package/src/agent-tools/subagent.mjs +175 -49
- package/src/agent-tools/verify.mjs +13 -34
- package/src/agent-tools.mjs +1 -0
- package/src/agent.mjs +42 -21
- package/src/cli/distill-command.mjs +2 -2
- package/src/cli/make-agent.mjs +23 -7
- package/src/cli/memory-command.mjs +2 -2
- package/src/cli/setup-wizard.mjs +29 -9
- package/src/completions.mjs +114 -0
- package/src/config-migrate.mjs +70 -0
- package/src/config.mjs +132 -63
- package/src/context.mjs +12 -1
- package/src/conventions.mjs +223 -0
- package/src/crash-reports.mjs +35 -8
- package/src/expand-home.mjs +16 -0
- package/src/generate-title.mjs +9 -4
- package/src/heap-watch.mjs +88 -0
- package/src/hooks.mjs +7 -3
- package/src/ledger.mjs +227 -0
- package/src/memory/code-index.mjs +9 -3
- package/src/memory/code-sync.mjs +77 -36
- package/src/memory/core.mjs +8 -9
- package/src/memory/delete.mjs +2 -0
- package/src/memory/docs.mjs +17 -11
- package/src/memory/file-walk.mjs +109 -0
- package/src/memory/scan.mjs +95 -0
- package/src/memory/schema.mjs +15 -3
- package/src/model-ref.mjs +66 -0
- package/src/model-specs.mjs +42 -8
- package/src/prompt-overlays.mjs +73 -16
- package/src/prompts/advisor-design.md +19 -9
- package/src/prompts/advisor-round1.md +8 -2
- package/src/prompts/advisor-round2.md +14 -3
- package/src/prompts/advisor-round3.md +14 -3
- package/src/prompts/common.md +115 -0
- package/src/prompts/consult-base.md +2 -0
- package/src/prompts/discipline-engineering.md +258 -0
- package/src/prompts/discipline-normal.md +185 -0
- package/src/prompts/persona-coder.md +21 -0
- package/src/prompts/persona-eng-coder.md +37 -0
- package/src/prompts/persona-eng-designer.md +60 -0
- package/src/prompts/persona-engineering.md +55 -0
- package/src/prompts/persona-explore.md +15 -0
- package/src/prompts/persona-normal.md +27 -0
- package/src/prompts/persona-plan.md +26 -0
- package/src/provider/anthropic.mjs +4 -4
- package/src/provider/core.mjs +13 -32
- package/src/provider/errors.mjs +26 -1
- package/src/provider/google.mjs +5 -6
- package/src/provider/index.mjs +2 -1
- package/src/provider/list-models.mjs +93 -0
- package/src/provider/rate.mjs +2 -1
- package/src/provider/responses.mjs +5 -3
- package/src/provider/sse.mjs +3 -4
- package/src/proxy.mjs +9 -14
- package/src/session-gc.mjs +9 -2
- package/src/session-guard.mjs +12 -0
- package/src/session-segments.mjs +100 -0
- package/src/session-slots.mjs +10 -2
- package/src/session-store.mjs +441 -0
- package/src/session.mjs +137 -99
- package/src/text-budget.mjs +46 -0
- package/src/token-ttl.mjs +2 -1
- package/src/tools/{system.mjs → bash.mjs} +6 -243
- package/src/tools/file.mjs +30 -10
- package/src/tools/git.md +1 -1
- package/src/tools/git.mjs +15 -34
- package/src/tools/index.mjs +4 -2
- package/src/tools/ops.mjs +20 -7
- package/src/tools/question.md +1 -0
- package/src/tools/question.mjs +26 -0
- package/src/tools/read.md +1 -1
- package/src/tools/read_image.md +1 -1
- package/src/tools/search.mjs +236 -0
- package/src/traces/trace-store.mjs +195 -64
- package/src/tui/agent-turn.mjs +32 -13
- package/src/tui/ansi.mjs +2 -0
- package/src/tui/clipboard.mjs +7 -1
- package/src/tui/cmd-advisor.mjs +3 -2
- package/src/tui/cmd-clear.mjs +2 -0
- package/src/tui/cmd-config.mjs +108 -37
- package/src/tui/cmd-eng.mjs +11 -27
- package/src/tui/cmd-exit.mjs +6 -8
- package/src/tui/cmd-model.mjs +14 -12
- package/src/tui/cmd-new.mjs +5 -1
- package/src/tui/cmd-reindex.mjs +7 -0
- package/src/tui/cmd-session.mjs +8 -4
- package/src/tui/cmd-submodel.mjs +8 -5
- package/src/tui/cmd-undo.mjs +4 -3
- package/src/tui/display-budget.mjs +184 -0
- package/src/tui/index.mjs +69 -40
- package/src/tui/key-handler-search.mjs +9 -1
- package/src/tui/key-handler.mjs +61 -17
- package/src/tui/key-modes.mjs +86 -8
- package/src/tui/layout.mjs +18 -10
- package/src/tui/ledger-surface.mjs +69 -0
- package/src/tui/model-catalog.mjs +89 -0
- package/src/tui/model-picker.mjs +498 -0
- package/src/tui/mouse.mjs +47 -10
- package/src/tui/pickers.mjs +28 -410
- package/src/tui/render-frame.mjs +38 -16
- package/src/tui/render-loop.mjs +2 -0
- package/src/tui/render-segments.mjs +5 -19
- package/src/tui/render.mjs +37 -5
- package/src/tui/slash-commands.mjs +2 -2
- package/src/tui/startup.mjs +45 -13
- package/src/tui/subagent-blocks.mjs +70 -90
- package/src/tui/subagent-children.mjs +125 -67
- package/src/tui/subagent-freeze.mjs +48 -45
- package/src/tui/subagent-panel.mjs +21 -66
- package/src/tui/suspension-drive.mjs +31 -83
- package/src/tui/tool-args.mjs +9 -4
- package/src/tui/tool-display.mjs +20 -5
- package/src/tui/tool-events.mjs +76 -30
- package/src/tui/tui-lifecycle.mjs +27 -7
- package/src/tui/wizard.mjs +52 -18
- package/src/tui/wrapped-spawn.mjs +54 -0
- package/src/prompts/coder.md +0 -13
- package/src/prompts/discipline.md +0 -84
- package/src/prompts/eng-coder.md +0 -19
- package/src/prompts/engineering-sub.md +0 -14
- package/src/prompts/engineering.md +0 -87
- package/src/prompts/explore.md +0 -12
- package/src/prompts/main.md +0 -34
- package/src/prompts/methodology-template.md +0 -38
- package/src/prompts/plan.md +0 -9
- package/src/prompts/system.md +0 -44
package/src/tui/pickers.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { sliceByWidth } from "./render.mjs"
|
|
2
|
-
import { PROVIDER_PRESETS as PRESETS, providerSpec } from "../config.mjs"
|
|
3
1
|
import { computeLayout } from "./layout.mjs"
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { createModelPicker } from "./model-picker.mjs"
|
|
3
|
+
|
|
4
|
+
/** Generic list picker plumbing + /model two-level surface delegation.
|
|
5
|
+
* MODEL-MERGE-SESSION 拆分(评审 #9):/model 两级面(L1 provider → L2 模型行——
|
|
6
|
+
* 2026-09-10 MODEL-SELECTION v2 起 L2 行 = 运行期拉取候选)+ 渠道
|
|
7
|
+
* 管理流 + selectModel + pickModelForSlot 迁 model-picker.mjs——本文件只留通用 picker
|
|
8
|
+
* 栈(showPicker/closePicker/popPicker/rebuildLines)——createModelPicker 以 ctx 接收
|
|
9
|
+
* 通用绑定(showPicker/closePicker/renderPickerLines)再行装配——index.mjs 消费面不变。
|
|
6
10
|
* 单一 Promise API:showPicker(title, entries, { defaultIndex }) → Promise<entry|null>。
|
|
7
11
|
* picker 栈:state.pickerStack,state.picker 始终指向栈顶(layout/render/key-handler 都只读 state.picker)。
|
|
8
12
|
* 选中即关闭(Enter = resolve + pop);Esc = pop 当前层并 resolve(null)。菜单循环由调用方 while 重开。 */
|
|
@@ -37,6 +41,12 @@ export function createPickers(ctx) {
|
|
|
37
41
|
* 互斥保护:入栈前把现有挂起 picker 全部 resolve(null),消除 Promise 悬挂。
|
|
38
42
|
* (正常嵌套是先 await 上一层返回再开新的,栈深通常为 1。) */
|
|
39
43
|
function showPicker(title, entries, { defaultIndex = 0 } = {}) {
|
|
44
|
+
if (!Array.isArray(entries)) {
|
|
45
|
+
const got = entries && typeof entries.then === "function"
|
|
46
|
+
? "a Promise (missing `await`?)"
|
|
47
|
+
: `a ${entries === null ? "null" : typeof entries}`
|
|
48
|
+
throw new TypeError(`showPicker("${title}"): entries must be an array — got ${got}`)
|
|
49
|
+
}
|
|
40
50
|
closePicker()
|
|
41
51
|
return new Promise((resolve) => {
|
|
42
52
|
const itemCount = entries.filter((e) => e.type === "item").length
|
|
@@ -65,7 +75,12 @@ export function createPickers(ctx) {
|
|
|
65
75
|
const sel = row === p.index
|
|
66
76
|
if (sel) selLine = lines.length
|
|
67
77
|
const marker = e.marker ? ` ${e.marker}` : ""
|
|
68
|
-
|
|
78
|
+
// A1(第 20 批 §12.5——D-SS7):item 附注消费——渲染形态 {prefix}{text}{marker}{note};
|
|
79
|
+
// header 分支既有消费同形态,无 note 零追加(不产生尾随空格)。宽度预算 =
|
|
80
|
+
// renderPicker 既有 8 格余量 + 右截断——保序 prefix→text→marker→note,截断从行尾
|
|
81
|
+
// 开始 = note 段最先牺牲。
|
|
82
|
+
const note = e.note ? ` ${e.note}` : ""
|
|
83
|
+
lines.push({ text: `${sel ? " ▸ " : " "}${e.text}${marker}${note}`, color: sel ? ansi.bold + C.text : C.dim, _row: row })
|
|
69
84
|
row++
|
|
70
85
|
}
|
|
71
86
|
}
|
|
@@ -90,410 +105,13 @@ export function createPickers(ctx) {
|
|
|
90
105
|
|
|
91
106
|
function renderPickerLines() { rebuildLines() }
|
|
92
107
|
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.replace(/-\d{4}-\d{2}-\d{2}$/, "") // date suffix like -2024-09-19
|
|
101
|
-
.replace(/-\d{8}$/, "") // date suffix like -20240919
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Dedupe model list: group by series, keep shortest name per group.
|
|
105
|
-
* Reduces "qwen-max, qwen-max-latest, qwen-max-2024-09-19" to just "qwen-max". */
|
|
106
|
-
function dedupeModels(models) {
|
|
107
|
-
const groups = new Map()
|
|
108
|
-
for (const m of models) {
|
|
109
|
-
const series = modelSeries(m)
|
|
110
|
-
const existing = groups.get(series)
|
|
111
|
-
if (!existing || m.length < existing.length) {
|
|
112
|
-
groups.set(series, m)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return [...groups.values()].sort()
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** entry 唯一标识:异步更新 entries 后按它恢复选中项 */
|
|
119
|
-
function entryKey(e) {
|
|
120
|
-
if (!e) return null
|
|
121
|
-
return e.action === "switch" ? `switch:${e.provider}:${e.model}` : `action:${e.action}`
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** 模型信息显示的 context 窗口(PROVIDER.md §15 D-C5):K 单位形态跟随覆盖值
|
|
125
|
-
* (config K 是二进制 K:128 → 128×1024 = 131072 → 显示 "128K");≥1M tokens 用 M 形态
|
|
126
|
-
* (1_000_000 → "1M"),与 spec 值的大窗口惯例一致。 */
|
|
127
|
-
function fmtContextK(tokens) {
|
|
128
|
-
if (tokens >= 1_000_000) return `${Math.round(tokens / 1_048_576)}M`
|
|
129
|
-
return `${Math.round(tokens / 1024)}K`
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Get API key for a provider (config.json only — env vars are not a key source) */
|
|
133
|
-
function getApiKey(providerName, providerConfig) {
|
|
134
|
-
return providerConfig.apiKey
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Level 1: Show provider list. Selecting a provider opens Level 2 (model list). */
|
|
138
|
-
async function openModelPicker() {
|
|
139
|
-
// 菜单循环:选中即关闭,子流程结束后重开主菜单;Esc 退出
|
|
140
|
-
for (;;) {
|
|
141
|
-
const entries = buildProviderEntries()
|
|
142
|
-
const items = entries.filter((e) => e.type === "item")
|
|
143
|
-
const current = items.findIndex(
|
|
144
|
-
(e) => e.action === "open-models" && e.provider === agent.activeProvider)
|
|
145
|
-
const picked = showPicker("Models & Providers", entries, { defaultIndex: Math.max(0, current) })
|
|
146
|
-
const e = await picked
|
|
147
|
-
if (!e) return
|
|
148
|
-
if (e.action === "open-models") {
|
|
149
|
-
// Level 2: open model list for this provider
|
|
150
|
-
const modelSelected = await openModelListForProvider(e.provider)
|
|
151
|
-
if (modelSelected) return // model selected, close picker
|
|
152
|
-
// Esc from model list → return to provider list
|
|
153
|
-
} else if (e.action === "add") {
|
|
154
|
-
await addProviderFlow()
|
|
155
|
-
} else if (e.action === "remove") {
|
|
156
|
-
await removeProviderFlow()
|
|
157
|
-
} else if (e.action === "key") {
|
|
158
|
-
await setKeyFlow()
|
|
159
|
-
} else if (e.action === "context") {
|
|
160
|
-
await setContextFlow()
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Level 2: Show model list for a specific provider. Returns true if a model was selected. */
|
|
166
|
-
async function openModelListForProvider(providerName) {
|
|
167
|
-
const providerConfig = agent.providers.find((p) => p.name === providerName)
|
|
168
|
-
if (!providerConfig) return false
|
|
169
|
-
|
|
170
|
-
const entries = buildModelEntriesForProvider(providerName, providerConfig)
|
|
171
|
-
const items = entries.filter((e) => e.type === "item")
|
|
172
|
-
const currentModel = providerName === agent.activeProvider
|
|
173
|
-
? (agent.activeModel || providerConfig.model)
|
|
174
|
-
: providerConfig.model
|
|
175
|
-
const current = items.findIndex((e) => e.model === currentModel)
|
|
176
|
-
const picked = showPicker(`${providerName} models`, entries, { defaultIndex: Math.max(0, current) })
|
|
177
|
-
|
|
178
|
-
// Async fetch models in background
|
|
179
|
-
fetchModelsForProvider(providerName, entries).catch((err) => {
|
|
180
|
-
pushLine(`[model] fetch models failed: ${err.message}`, C.error)
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
const e = await picked
|
|
184
|
-
if (!e) return false // Esc → back to provider list
|
|
185
|
-
if (e.action === "switch") {
|
|
186
|
-
await selectModel(e).catch((err) => pushLine(`[error] ${err.message}`, C.error))
|
|
187
|
-
return true
|
|
188
|
-
}
|
|
189
|
-
return false
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** Build entries for Level 1: provider list */
|
|
193
|
-
function buildProviderEntries() {
|
|
194
|
-
const entries = []
|
|
195
|
-
for (const p of agent.providers) {
|
|
196
|
-
const active = p.name === agent.activeProvider
|
|
197
|
-
const currentModel = active ? (agent.activeModel || p.model) : p.model
|
|
198
|
-
const marker = active ? "●" : ""
|
|
199
|
-
const note = active ? " ← current" : ""
|
|
200
|
-
const keyStatus = p.apiKey ? "" : " (no key)"
|
|
201
|
-
// context 窗口显示(PROVIDER.md §15 D-C5/T-C6):跟随 providers[].context 覆盖
|
|
202
|
-
const ctxTag = ` (ctx ${fmtContextK(providerSpec(p).context)})`
|
|
203
|
-
entries.push({
|
|
204
|
-
type: "item",
|
|
205
|
-
text: `${p.name.padEnd(12)} ${currentModel}${ctxTag}${note}`,
|
|
206
|
-
action: "open-models",
|
|
207
|
-
provider: p.name,
|
|
208
|
-
marker,
|
|
209
|
-
note: `${p.baseURL}${keyStatus}`,
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
entries.push({ type: "header", text: "Management" })
|
|
213
|
-
entries.push({ type: "item", text: "Add provider…", action: "add" })
|
|
214
|
-
if (agent.providers.length > 1) entries.push({ type: "item", text: "Remove provider…", action: "remove" })
|
|
215
|
-
entries.push({ type: "item", text: "Set / change API key…", action: "key" })
|
|
216
|
-
entries.push({ type: "item", text: "Set context window (K units)…", action: "context" })
|
|
217
|
-
return entries
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Build entries for Level 2: model list for a specific provider */
|
|
221
|
-
function buildModelEntriesForProvider(providerName, providerConfig) {
|
|
222
|
-
const entries = []
|
|
223
|
-
const active = providerName === agent.activeProvider
|
|
224
|
-
const currentModel = active ? (agent.activeModel || providerConfig.model) : providerConfig.model
|
|
225
|
-
const isDefaultModel = currentModel === providerConfig.model
|
|
226
|
-
|
|
227
|
-
entries.push({ type: "header", text: "Current model" })
|
|
228
|
-
entries.push({
|
|
229
|
-
type: "item",
|
|
230
|
-
text: currentModel,
|
|
231
|
-
action: "switch",
|
|
232
|
-
provider: providerName,
|
|
233
|
-
model: currentModel,
|
|
234
|
-
marker: active && isDefaultModel ? "●" : "",
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
entries.push({ type: "header", text: "Available models (loading…)" })
|
|
238
|
-
return entries
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** Async fetch and splice models for a specific provider */
|
|
242
|
-
async function fetchModelsForProvider(providerName, entries) {
|
|
243
|
-
const { listModels } = await import("../provider/index.mjs")
|
|
244
|
-
const providerConfig = agent.providers.find((p) => p.name === providerName)
|
|
245
|
-
if (!providerConfig) return
|
|
246
|
-
|
|
247
|
-
let selKey = null
|
|
248
|
-
try {
|
|
249
|
-
const apiKey = getApiKey(providerName, providerConfig)
|
|
250
|
-
const models = await listModels(
|
|
251
|
-
{ baseURL: providerConfig.baseURL, apiKey: apiKey ?? "" },
|
|
252
|
-
{ signal: AbortSignal.timeout(10000) }
|
|
253
|
-
)
|
|
254
|
-
if (state.picker?.entries !== entries) return // picker closed or changed
|
|
255
|
-
selKey = entryKey(pickerItems(state.picker)[state.picker.index])
|
|
256
|
-
|
|
257
|
-
// Dedupe and filter
|
|
258
|
-
const deduped = dedupeModels(models)
|
|
259
|
-
const currentModel = providerName === agent.activeProvider
|
|
260
|
-
? (agent.activeModel || providerConfig.model)
|
|
261
|
-
: providerConfig.model
|
|
262
|
-
|
|
263
|
-
// Find the "Available models" header and splice after it
|
|
264
|
-
const headerIdx = entries.findIndex((e) => e.type === "header" && e.text.startsWith("Available models"))
|
|
265
|
-
if (headerIdx >= 0) {
|
|
266
|
-
// Update header with count info
|
|
267
|
-
const hint = deduped.length < models.length
|
|
268
|
-
? ` (${models.length} total, ${deduped.length} shown — type to filter)`
|
|
269
|
-
: ` (${deduped.length})`
|
|
270
|
-
entries[headerIdx].text = `Available models${hint}`
|
|
271
|
-
|
|
272
|
-
// Splice models after header (skip current model)
|
|
273
|
-
const newModels = deduped.filter((m) => m !== currentModel)
|
|
274
|
-
entries.splice(headerIdx + 1, 0, ...newModels.map((m) => ({
|
|
275
|
-
type: "item",
|
|
276
|
-
text: m,
|
|
277
|
-
action: "switch",
|
|
278
|
-
provider: providerName,
|
|
279
|
-
model: m,
|
|
280
|
-
})))
|
|
281
|
-
}
|
|
282
|
-
} catch (error) {
|
|
283
|
-
if (state.picker?.entries !== entries) return
|
|
284
|
-
const headerIdx = entries.findIndex((e) => e.type === "header" && e.text.startsWith("Available models"))
|
|
285
|
-
if (headerIdx >= 0) {
|
|
286
|
-
entries[headerIdx].text = `Available models (fetch failed: ${sliceByWidth(error.message, 30)})`
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// Restore selection
|
|
291
|
-
const pk = state.picker
|
|
292
|
-
const items = pickerItems(pk)
|
|
293
|
-
const restored = selKey ? items.findIndex((e) => entryKey(e) === selKey) : -1
|
|
294
|
-
pk.index = restored >= 0 ? restored : Math.min(pk.index, Math.max(0, items.length - 1))
|
|
295
|
-
rebuildLines()
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async function selectModel(item) {
|
|
299
|
-
closePicker()
|
|
300
|
-
const target = agent.providers.find((pp) => pp.name === item.provider)
|
|
301
|
-
if (!target) return
|
|
302
|
-
const providerDefault = target.model
|
|
303
|
-
const nextActiveModel = item.model !== providerDefault ? item.model : null // default model → clear activeModel
|
|
304
|
-
// D-F5a(selectModel——清单外同型写回补正)先盘后存:磁盘 fresh raw 单操作(model + active 指针)——冲突放弃不留 ghost
|
|
305
|
-
await persistRaw((raw) => {
|
|
306
|
-
raw.providers ??= []
|
|
307
|
-
const t = raw.providers.find((p) => p?.name === item.provider)
|
|
308
|
-
if (t) t.model = item.model
|
|
309
|
-
raw.activeProvider = item.provider
|
|
310
|
-
raw.activeModel = nextActiveModel || undefined // null → omit from config
|
|
311
|
-
})
|
|
312
|
-
target.model = item.model
|
|
313
|
-
agent.activeProvider = item.provider
|
|
314
|
-
agent.activeModel = nextActiveModel
|
|
315
|
-
agent.provider = { ...target }
|
|
316
|
-
if (agent.config?.agent?.compactThresholdAuto) {
|
|
317
|
-
const { resolveCompactThreshold } = await import("../config.mjs")
|
|
318
|
-
// provider 对象(非 model 字符串)——阈值跟随 providers[].context 覆盖(PROVIDER.md §15 T-C2)
|
|
319
|
-
agent.config.agent.compactThreshold = resolveCompactThreshold(null, target).value
|
|
320
|
-
}
|
|
321
|
-
agent.config.activeProvider = item.provider
|
|
322
|
-
agent.config.activeModel = agent.activeModel
|
|
323
|
-
if (!agent.provider.apiKey) {
|
|
324
|
-
const selKey = await askQuestion(`Enter API key for ${item.provider} (leave empty to skip):`)
|
|
325
|
-
if (selKey) await setProviderKey(item.provider, selKey)
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async function addProviderFlow() {
|
|
330
|
-
const entries = [
|
|
331
|
-
{ type: "header", text: "Select a preset provider" },
|
|
332
|
-
...Object.entries(PRESETS).filter(([name]) => !agent.providers.some((p) => p.name === name))
|
|
333
|
-
.map(([name, p]) => ({ type: "item", text: `${name.padEnd(10)} ${p.desc ?? ""} (${p.model})`, name, kind: "preset" })),
|
|
334
|
-
{ type: "header", text: "Other" },
|
|
335
|
-
{ type: "item", text: "Custom (manual config)", name: "__custom__", kind: "custom" },
|
|
336
|
-
]
|
|
337
|
-
const se = await showPicker("Add Provider", entries)
|
|
338
|
-
if (!se) return // Esc → 返回上级(openModelPicker 循环会重开主菜单)
|
|
339
|
-
if (se.kind === "custom") {
|
|
340
|
-
const name = await askQuestion("Enter provider name:")
|
|
341
|
-
if (!name) return
|
|
342
|
-
if (agent.providers.some((p) => p.name === name)) return
|
|
343
|
-
const baseURL = (await askQuestion("Enter baseURL:")).replace(/\/+$/, "")
|
|
344
|
-
if (!baseURL) return
|
|
345
|
-
const model = await askQuestion("Enter model name:")
|
|
346
|
-
if (!model) return
|
|
347
|
-
// D-C1(TUI.md §10.6D):API format 改 picker 选择(openai/anthropic/google——默认 index=0
|
|
348
|
-
// openai)——固定枚举不再手输;Esc/取消 = 中止整个 Add Provider 流程(cfg 尚未落盘——
|
|
349
|
-
// 无半配置,与旧手输非法 abort 同语义)。与 preset 选择器同形态——零新机制。
|
|
350
|
-
const format = await showPicker("API format", [
|
|
351
|
-
{ type: "item", text: "openai", name: "openai" },
|
|
352
|
-
{ type: "item", text: "anthropic", name: "anthropic" },
|
|
353
|
-
{ type: "item", text: "google", name: "google" },
|
|
354
|
-
])
|
|
355
|
-
if (!format) return // Esc/取消 → 中止流程
|
|
356
|
-
const cfg = { name, baseURL, model }
|
|
357
|
-
if (format.name === "anthropic" || format.name === "google") cfg.format = format.name
|
|
358
|
-
else if (format.name !== "openai") return // 防御:未知格式(理论不可达——picker 枚举)
|
|
359
|
-
await persistRaw((raw) => { raw.providers ??= []; raw.providers.push(cfg) }) // D-F5a(#3)先盘后存
|
|
360
|
-
agent.providers.push(cfg)
|
|
361
|
-
const key = await askQuestion(`Enter API key for ${name} (skip if none):`)
|
|
362
|
-
if (key) await setProviderKey(name, key)
|
|
363
|
-
return
|
|
364
|
-
}
|
|
365
|
-
const preset = PRESETS[se.name]
|
|
366
|
-
if (!preset || agent.providers.some((p) => p.name === se.name)) return
|
|
367
|
-
const cfg = { name: se.name, baseURL: preset.baseURL, model: preset.model }
|
|
368
|
-
if (preset.thinking) cfg.thinking = preset.thinking
|
|
369
|
-
if (preset.reasoningEffort) cfg.reasoningEffort = preset.reasoningEffort
|
|
370
|
-
if (preset.maxTokens) cfg.maxTokens = preset.maxTokens
|
|
371
|
-
if (preset.chatPath) cfg.chatPath = preset.chatPath
|
|
372
|
-
if (preset.format) cfg.format = preset.format
|
|
373
|
-
await persistRaw((raw) => { raw.providers ??= []; raw.providers.push(cfg) }) // D-F5a(#2)先盘后存
|
|
374
|
-
agent.providers.push(cfg)
|
|
375
|
-
const key = await askQuestion(`Enter API key for ${se.name} (skip if none):`)
|
|
376
|
-
if (key) await setProviderKey(se.name, key)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
async function removeProviderFlow() {
|
|
380
|
-
const candidates = agent.providers.filter((p) => p.name !== agent.activeProvider)
|
|
381
|
-
if (!candidates.length) return
|
|
382
|
-
const se = await showPicker("Remove Provider", [
|
|
383
|
-
{ type: "header", text: "Select provider to remove" },
|
|
384
|
-
...candidates.map((p) => ({ type: "item", text: `${p.name} (${p.model})`, name: p.name })),
|
|
385
|
-
])
|
|
386
|
-
if (!se) return
|
|
387
|
-
// D-F5a(#4)先盘后存:磁盘 fresh raw 上 splice;冲突放弃不留下内存 ghost
|
|
388
|
-
await persistRaw((raw) => {
|
|
389
|
-
raw.providers ??= []
|
|
390
|
-
const idx = raw.providers.findIndex((p) => p?.name === se.name)
|
|
391
|
-
if (idx !== -1) raw.providers.splice(idx, 1)
|
|
392
|
-
})
|
|
393
|
-
agent.providers.splice(agent.providers.findIndex((p) => p.name === se.name), 1)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
async function setKeyFlow() {
|
|
397
|
-
const se = await showPicker("Configure API Key", [
|
|
398
|
-
{ type: "header", text: "Select provider" },
|
|
399
|
-
...agent.providers.map((p) => ({ type: "item", text: `${p.name} ${p.apiKey ? `(has key: ${maskKey(p.apiKey)})` : "(no key)"}`, name: p.name })),
|
|
400
|
-
])
|
|
401
|
-
if (!se) return
|
|
402
|
-
const key = await askQuestion(`Enter API key for ${se.name}:`)
|
|
403
|
-
if (key) await setProviderKey(se.name, key)
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
async function setProviderKey(name, key) {
|
|
407
|
-
const target = agent.providers.find((p) => p.name === name)
|
|
408
|
-
if (!target) return
|
|
409
|
-
// D-F5a(#5)先盘后存:磁盘 fresh raw 上改目标项 apiKey;冲突放弃不留下内存 ghost
|
|
410
|
-
await persistRaw((raw) => {
|
|
411
|
-
raw.providers ??= []
|
|
412
|
-
const t = raw.providers.find((p) => p?.name === name)
|
|
413
|
-
if (t) t.apiKey = key
|
|
414
|
-
})
|
|
415
|
-
target.apiKey = key
|
|
416
|
-
if (name === agent.activeProvider) agent.provider.apiKey = key
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/** /model provider 管理:context 窗口字段(K 单位,PROVIDER.md §15 D-C4/D-C5)——picker 选
|
|
420
|
-
* provider + 表单输入;空清空/非法不落盘(D-C1);落盘 = D-F5a(#6)fresh 单字段补丁——先盘后存。 */
|
|
421
|
-
async function setContextFlow() {
|
|
422
|
-
const se = await showPicker("Set Context Window", [
|
|
423
|
-
{ type: "header", text: "Select provider" },
|
|
424
|
-
...agent.providers.map((p) => ({
|
|
425
|
-
type: "item",
|
|
426
|
-
text: `${p.name} (ctx ${fmtContextK(providerSpec(p).context)})`,
|
|
427
|
-
name: p.name,
|
|
428
|
-
})),
|
|
429
|
-
])
|
|
430
|
-
if (!se?.name) return // Esc
|
|
431
|
-
const target = agent.providers.find((p) => p.name === se.name)
|
|
432
|
-
if (!target) return
|
|
433
|
-
const current = Number.isInteger(target.context) && target.context > 0 ? target.context : null
|
|
434
|
-
const val = (await askQuestion(
|
|
435
|
-
`Context window for ${se.name} in K units (current: ${current ? `${current}K` : "spec default"} — e.g. 128 = 128K; empty to clear):`
|
|
436
|
-
))?.trim() ?? ""
|
|
437
|
-
let newCtx // undefined = 清空(回 spec 值)
|
|
438
|
-
if (val !== "") {
|
|
439
|
-
const n = Number(val)
|
|
440
|
-
if (!Number.isInteger(n) || n <= 0) {
|
|
441
|
-
pushLine(`Invalid context: "${val}" — must be a positive integer in K units (e.g. 128 = 128K)`, C.error)
|
|
442
|
-
return
|
|
443
|
-
}
|
|
444
|
-
newCtx = n
|
|
445
|
-
}
|
|
446
|
-
await persistRaw((raw) => {
|
|
447
|
-
raw.providers ??= []
|
|
448
|
-
const t = raw.providers.find((p) => p?.name === se.name)
|
|
449
|
-
if (!t) return
|
|
450
|
-
if (newCtx === undefined) delete t.context
|
|
451
|
-
else t.context = newCtx
|
|
452
|
-
})
|
|
453
|
-
if (newCtx === undefined) delete target.context
|
|
454
|
-
else target.context = newCtx
|
|
455
|
-
if (se.name === agent.activeProvider) {
|
|
456
|
-
// 运行时 provider 同步(同 setProviderKey 先例:只补 context,不重建对象以免丢 activeModel 覆盖)
|
|
457
|
-
if (newCtx === undefined) delete agent.provider.context
|
|
458
|
-
else agent.provider.context = newCtx
|
|
459
|
-
if (agent.config?.agent?.compactThresholdAuto) {
|
|
460
|
-
const { resolveCompactThreshold } = await import("../config.mjs")
|
|
461
|
-
agent.config.agent.compactThreshold = resolveCompactThreshold(null, agent.provider).value
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
pushLine(target.context !== undefined
|
|
465
|
-
? `ctx = ${target.context}K (${target.context * 1024} tokens)`
|
|
466
|
-
: `context cleared — using model spec (${fmtContextK(providerSpec(target).context)})`, C.tool)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
/** Slot-bound model picker: two-level provider → model selection that RETURNS
|
|
471
|
-
* { provider, model } instead of writing main-session state — used by /submodel
|
|
472
|
-
* to write into a subagent slot (global or per-role). Esc from the model list
|
|
473
|
-
* returns to the provider list (openModelPicker parity); Esc from the provider
|
|
474
|
-
* list exits → null. */
|
|
475
|
-
async function pickModelForSlot() {
|
|
476
|
-
for (;;) {
|
|
477
|
-
const providers = agent.providers
|
|
478
|
-
if (!providers.length) return null
|
|
479
|
-
const e = await showPicker("Select provider", providers.map((p) => ({
|
|
480
|
-
type: "item",
|
|
481
|
-
text: `${p.name.padEnd(12)} ${p.model}`,
|
|
482
|
-
action: "open-models",
|
|
483
|
-
provider: p.name,
|
|
484
|
-
})))
|
|
485
|
-
if (!e?.provider) return null
|
|
486
|
-
const providerConfig = providers.find((p) => p.name === e.provider)
|
|
487
|
-
if (!providerConfig) return null
|
|
488
|
-
const entries = buildModelEntriesForProvider(e.provider, providerConfig)
|
|
489
|
-
fetchModelsForProvider(e.provider, entries).catch((err) => {
|
|
490
|
-
pushLine(`[model] fetch models failed: ${err.message}`, C.error)
|
|
491
|
-
})
|
|
492
|
-
const me = await showPicker(`${e.provider} models`, entries)
|
|
493
|
-
if (!me?.model) continue // Esc from model list → back to provider list
|
|
494
|
-
return { provider: e.provider, model: me.model }
|
|
495
|
-
}
|
|
496
|
-
}
|
|
108
|
+
// /model 两级面 + selectModel + 渠道管理 + pickModelForSlot —— 迁 model-picker.mjs
|
|
109
|
+
// (MODEL-MERGE-SESSION——pick 后本文件 ≤450)。createModelPicker 返回同名单函数,
|
|
110
|
+
// 经本层原样转发(index.mjs/wizard/slash-commands 消费面零变化)。
|
|
111
|
+
const modelPicker = createModelPicker({
|
|
112
|
+
agent, state, render, ansi, C, pushLine, persistRaw, askQuestion, maskKey,
|
|
113
|
+
showPicker, closePicker, renderPickerLines,
|
|
114
|
+
})
|
|
497
115
|
|
|
498
|
-
return { showPicker, closePicker, popPicker, renderPickerLines,
|
|
116
|
+
return { showPicker, closePicker, popPicker, renderPickerLines, ...modelPicker }
|
|
499
117
|
}
|
package/src/tui/render-frame.mjs
CHANGED
|
@@ -72,13 +72,6 @@ export function renderPermission(permPreviewLines) {
|
|
|
72
72
|
return [`${ansi.bold}${C.warn}❯ Permission Request${ansi.reset}`, ...permPreviewLines.map((w) => `${C.warn}${w}${ansi.reset}`)]
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/** Queue preview (1 line when queue has items during processing). */
|
|
76
|
-
export function renderQueue(state, W) {
|
|
77
|
-
if (state.queue.length === 0 || !state.processing) return ""
|
|
78
|
-
const preview = sliceByWidth(state.queue[0].text, W - 20)
|
|
79
|
-
return `${C.dim}❯ Queue: ${state.queue.length} pending${state.queue.length > 1 ? ` (next: ${preview}…)` : ` (next: ${preview})`} — Ctrl+D delete │ Ctrl+I inject${ansi.reset}`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
75
|
/** Picker/wizard overlay panel. Returns empty when no overlay. */
|
|
83
76
|
export function renderPicker(state, cols, panel, overlay) {
|
|
84
77
|
if (!panel || !overlay) return []
|
|
@@ -139,8 +132,8 @@ export function renderInputBox(state, W, boxLines, cols, inputLayout, inputOffse
|
|
|
139
132
|
? " ↑↓ select │ Enter confirm │ Esc: cancel "
|
|
140
133
|
: " Enter submit │ Esc: cancel │ Ctrl+U clear │ Ctrl+V paste ")
|
|
141
134
|
}
|
|
142
|
-
if (title === " Inject Message ") parts.push(" Enter send, Esc cancel ")
|
|
143
|
-
if (title
|
|
135
|
+
if (title === " Inject Message ") parts.push(" Enter send, Esc cancel │ ←→↑↓ Home/End move │ Ctrl+V paste ")
|
|
136
|
+
if (title === " Input " || title === " Processing... ") {
|
|
144
137
|
parts.push(" Shift+Enter / Ctrl+J newline ")
|
|
145
138
|
parts.push(" Ctrl+V paste ")
|
|
146
139
|
parts.push(" Ctrl+I inject ")
|
|
@@ -160,8 +153,8 @@ export function renderInputBox(state, W, boxLines, cols, inputLayout, inputOffse
|
|
|
160
153
|
const curLine = (!hasOverlay && inputLayout) ? inputLayout.cursorLine - (inputOffset ?? 0) : -1
|
|
161
154
|
const curCol = (!hasOverlay && inputLayout) ? inputLayout.cursorCol : -1
|
|
162
155
|
|
|
163
|
-
// Interrupt prompt
|
|
164
|
-
const isInterruptEmpty = state.interruptPrompt &&
|
|
156
|
+
// Interrupt prompt 空文本占位符:灰色提示用户该做什么(第 31 批:chars 数组判空——§8)
|
|
157
|
+
const isInterruptEmpty = state.interruptPrompt && state.interruptPrompt.chars.length === 0
|
|
165
158
|
const interruptPlaceholder = "Type message to inject (Enter send, Esc cancel)"
|
|
166
159
|
|
|
167
160
|
for (let li = 0; li < boxLines.length; li++) {
|
|
@@ -212,6 +205,15 @@ export function renderInputBox(state, W, boxLines, cols, inputLayout, inputOffse
|
|
|
212
205
|
return out
|
|
213
206
|
}
|
|
214
207
|
|
|
208
|
+
/** 第 33 批(TUI §14.3(a)——纯函数派生,无副作用):blocked = 审批/提问卡挂起(实时派生,
|
|
209
|
+
* 提示消解即消失);awaiting = 回合结束等待输入(链尾置位——processing / 挂起两态期间不派生)。
|
|
210
|
+
* @returns {"blocked"|"awaiting"|null} */
|
|
211
|
+
export function attentionKind(state) {
|
|
212
|
+
if (state.permission || state.question) return "blocked"
|
|
213
|
+
if (state.attentionAwaiting && !state.processing && !state.suspended && !state._suspPending) return "awaiting"
|
|
214
|
+
return null
|
|
215
|
+
}
|
|
216
|
+
|
|
215
217
|
/** Status bar (always 1 line). */
|
|
216
218
|
export function renderStatus(state, agent, cols, slashCommands) {
|
|
217
219
|
const statusLine = buildStatusLine(state, agent, { cols, slashCommands })
|
|
@@ -220,8 +222,20 @@ export function renderStatus(state, agent, cols, slashCommands) {
|
|
|
220
222
|
const advisorBanner = agent.config?.advisor?.guard === true ? `${C.advisor} ADVISOR${ansi.reset}${ansi.dim}│` : ""
|
|
221
223
|
const engBanner = agent.config?.agent?.engineering ? `${C.advisor} ENG${ansi.reset}${ansi.dim}│` : ""
|
|
222
224
|
const bannerPrefix = (agent.planMode ? " PLAN│ " : "") + (agent.autoApprove ? " AUTO│ " : "") + (agent.config?.advisor?.guard === true ? " ADVISOR│ " : "") + (agent.config?.agent?.engineering ? " ENG│ " : "")
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
// 第 33 批(TUI §14.3(b)/(c)):attention 态 = chip 行首 + 整行注意力色对包裹(blocked >
|
|
226
|
+
// awaiting;blocked 内 permission > question——与按键分发优先级同序);平态零注入。
|
|
227
|
+
const kind = attentionKind(state)
|
|
228
|
+
const chip = kind === "blocked" ? (state.permission ? "⚠ 等待你的审批" : "⚠ 等待你的回答")
|
|
229
|
+
: kind === "awaiting" ? "⚠ 等待你的输入" : ""
|
|
230
|
+
const attentionPad = chip ? `${chip} │ ` : ""
|
|
231
|
+
// 宽度预算(N9④):chip 占位计入——整行仍 ≤ cols − 1(既有口径)。
|
|
232
|
+
const statusMax = cols - 1 - (bannerPrefix ? stringWidth(bannerPrefix) : 0) - (attentionPad ? stringWidth(attentionPad) : 0)
|
|
233
|
+
const inner = `${ansi.dim}${planBanner}${autoBanner}${advisorBanner}${engBanner}${sliceByWidth(statusLine, Math.max(10, statusMax))}`
|
|
234
|
+
// 负向锁(§14.3):attention 为 null ⇒ 半态路径逐字节等价(不经包裹 / 零字节注入)。
|
|
235
|
+
if (!chip) return `${inner}${ansi.reset}`
|
|
236
|
+
// 底色存活(§14.3):既有内容含内部 ansi.reset(banner / ctx 警示段)——每次内部复位后
|
|
237
|
+
// 重施加注意力色对,再整体包裹(内容零省略)。
|
|
238
|
+
return `${C.attention}${(chip + " │ " + inner).replaceAll(ansi.reset, ansi.reset + C.attention)}${ansi.reset}`
|
|
225
239
|
}
|
|
226
240
|
|
|
227
241
|
// ====================================================================
|
|
@@ -266,7 +280,7 @@ export function renderRows(state, agent, opts) {
|
|
|
266
280
|
if (panels.todo) put(panels.todo.y, renderTodo(visibleTasks, cols))
|
|
267
281
|
if (panels.picker) put(panels.picker.y, renderPicker(state, cols, panels.picker, overlay))
|
|
268
282
|
if (panels.permission) put(panels.permission.y, renderPermission(permPreviewLines))
|
|
269
|
-
|
|
283
|
+
// 排队面板提示已撤(INPUT-LOCK-ASYNC F-7——2026-09-09——busy 提交吞——无排队展示)
|
|
270
284
|
// question 自由文本态:box 内容是 layoutAnswer 行——光标布局/滚动随 box 内容走
|
|
271
285
|
// (questionLayout/questionOffset);主输入 inputLayout 此时无意义(被 question 行替换)。
|
|
272
286
|
const qFree = Boolean(state.question && state.question.options.length === 0)
|
|
@@ -376,6 +390,14 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
376
390
|
const ctxTokensHint = state.ctxCache.tokens > 0 ? ` ${fmtK(state.ctxCache.tokens)}` : ""
|
|
377
391
|
const ctxHint = ctxPct > 0
|
|
378
392
|
? ctxPct >= 80 ? ` │ ${ansi.reset}${C.warn}context ${ctxPct}%${ctxTokensHint}${ansi.reset}${ansi.dim}` : ` │ context ${ctxPct}%${ctxTokensHint}` : ""
|
|
379
|
-
|
|
380
|
-
|
|
393
|
+
// INPUT-LOCK-ASYNC(C'——F-3):busy(processing 含 digest)状态栏提示——取代旧
|
|
394
|
+
// 排队提示(F-7 已删)——“主会话处理中——Enter 提交禁用”
|
|
395
|
+
const enterHint = state.processing ? `主会话处理中 — Enter 提交禁用(字符可输入,回合结束请重按 Enter)` : "Enter: send"
|
|
396
|
+
// LEDGER-SURFACE(§2.30.3.3/§2.30.3.4):L1 常驻标记——状态段簇尾(scrollHint 后、键位组前);
|
|
397
|
+
// 空标记零注入(半态逐字节等价——同 :233-238 纪律);warn = 当前项目老化 > 0(警示色段包裹)
|
|
398
|
+
const lg = state.ledger
|
|
399
|
+
const ledgerHint = lg?.marker
|
|
400
|
+
? ` │ ${lg.warn ? `${ansi.reset}${C.warn}${lg.marker}${ansi.reset}${ansi.dim}` : lg.marker}`
|
|
401
|
+
: ""
|
|
402
|
+
return ` ${statusText}${taskHint}${turnHint}${tokenHint}${ctxHint}${scrollHint}${ledgerHint} │ ${enterHint} │ /: commands │ wheel/PgUp/PgDn: scroll │ Ctrl+I: inject │ Ctrl+C: exit (×2)`
|
|
381
403
|
}
|
package/src/tui/render-loop.mjs
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { countConvLines, renderRows } from "./render-frame.mjs"
|
|
17
17
|
import { estimateTokens } from "../context.mjs"
|
|
18
18
|
import { ansi, C } from "./ansi.mjs"
|
|
19
|
+
import { isTuiActive } from "./tui-lifecycle.mjs" // F-2 渲染抑制守卫(RESIZE-MOUSE-LEAK-FIX)
|
|
19
20
|
|
|
20
21
|
const MIN_RENDER_INTERVAL_MS = 16
|
|
21
22
|
|
|
@@ -55,6 +56,7 @@ export function createRenderLoop(state, agent, ctx, pushLine, write = (s) => pro
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function doRender() {
|
|
59
|
+
if (!isTuiActive()) return // F-2 渲染抑制(RESIZE-MOUSE-LEAK-FIX):cleanup 已清活动态——退出期不再把 TUI 帧重绘到已恢复的主屏
|
|
58
60
|
try {
|
|
59
61
|
// Single source (Windows ConPTY instability, 2026-08-30). CACHE ONLY —
|
|
60
62
|
// no per-frame refresh: during heavy streaming output ConPTY reports a
|
|
@@ -10,7 +10,6 @@ import { formatTables, sanitizeDisplay, sliceByWidth, wrapText } from "./render.
|
|
|
10
10
|
import {
|
|
11
11
|
foldTailLines, isExpanded, renderBlockTimeline, renderExpandedBlock, renderFoldedHead, renderMathAndMarkdown,
|
|
12
12
|
} from "./fold-block.mjs"
|
|
13
|
-
import { renderSubChildSections, subChildFoldKey } from "./subagent-panel.mjs"
|
|
14
13
|
import { SUBAGENT_ROLES } from "./subagent-blocks.mjs"
|
|
15
14
|
|
|
16
15
|
const _toolSegCache = new WeakMap()
|
|
@@ -71,7 +70,8 @@ export function toolSeg(state, l, i, cols, maxRows) {
|
|
|
71
70
|
/** 冻结子agent 活动块渲染(§7.2 D4):state.lines 载体 {_frozenSubTask: sub}(subagent-blocks.mjs
|
|
72
71
|
* freezeSubTaskLines 推入)。折叠 = 身份头 + tail 3;展开 = 共享组件(60% 屏幕封顶 + 底部可达
|
|
73
72
|
* 折叠控制)。折叠键 `sub-${key}`——与运行中面板区块同键,折叠态跨冻结边界无缝延续。
|
|
74
|
-
*
|
|
73
|
+
* SUBAGENT-TAIL:内层内容已并入 sub.blocks(数据层——取代小节;docs/design/TUI.md §6)
|
|
74
|
+
* ——本段只渲染单流(无子块段/无子块头)。 */
|
|
75
75
|
function frozenSubTaskLines(state, sub, cols, maxRows) {
|
|
76
76
|
const foldKey = `sub-${sub.key}`
|
|
77
77
|
const elapsed = Math.floor(((sub.doneAt ?? Date.now()) - sub.started) / 1000)
|
|
@@ -106,33 +106,19 @@ function frozenSubTaskLines(state, sub, cols, maxRows) {
|
|
|
106
106
|
out.push({ text: `│ ${sliceByWidth(line, cols - 4)}`, color: C.dim, _skipDimFold: true })
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
// §27 R23:子块段随冻结载体(折叠/展开两态都渲染——子块自身折叠键独立控制)。
|
|
110
|
-
out.push(...renderSubChildSections(state, sub, cols, maxRows))
|
|
111
109
|
return out
|
|
112
110
|
}
|
|
113
111
|
|
|
114
|
-
/** 冻结子agent 段入口(2026-08-31 段缓存:冻结后内容不变——签名含 sub.key + blocks
|
|
115
|
-
*
|
|
116
|
-
*
|
|
112
|
+
/** 冻结子agent 段入口(2026-08-31 段缓存:冻结后内容不变——签名含 sub.key + blocks 计数;
|
|
113
|
+
* 注:foldKey 由位置键升级为 sub.key(loadOlder unshift 后不重绑——sub 自身携带 key)。
|
|
114
|
+
* SUBAGENT-TAIL:子块树签名退役(子块无内容行、无独立折叠键——渲染零读 children)。 */
|
|
117
115
|
export function frozenSubSeg(state, l, i, cols, maxRows) {
|
|
118
116
|
const fKey = `sub-${l._frozenSubTask.key}`
|
|
119
|
-
// §27 R23:子块树渲染输入签名(key/done/stopped/blocks 数/折叠态/窗口偏移——递归)
|
|
120
117
|
const sub = l._frozenSubTask
|
|
121
|
-
let childSig = ""
|
|
122
|
-
const walk = (carrier, path) => {
|
|
123
|
-
for (const c of carrier.children ?? []) {
|
|
124
|
-
const innerPath = path ? `${path}/${c.key}` : c.key
|
|
125
|
-
const fk = subChildFoldKey(sub.key, innerPath)
|
|
126
|
-
childSig += `${innerPath}:${c.done ? 1 : 0}:${c.stopped ? 1 : 0}:${c.blocks?.length ?? 0}:${state.expandedBlocks?.has(fk) ? 1 : 0}:${state._foldScroll?.get(fk) ?? 0};`
|
|
127
|
-
walk(c, innerPath)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
walk(sub, "")
|
|
131
118
|
const fSig = [
|
|
132
119
|
cols, maxRows ?? 0, sub.key, sub.blocks?.length ?? 0,
|
|
133
120
|
sub.done ? 1 : 0, state.foldEnabled === false ? 0 : 1,
|
|
134
121
|
state.expandedBlocks?.has(fKey) ? 1 : 0, state._foldScroll?.get(fKey) ?? 0,
|
|
135
|
-
childSig,
|
|
136
122
|
].join("|")
|
|
137
123
|
const hit = _frozenSubCache.get(l)
|
|
138
124
|
if (hit && hit.textRef === sub && hit.sig === fSig) return hit.rows
|