thincoder 0.12.58 → 0.12.60
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 +78 -2
- package/README.md +3 -3
- package/bin/thincoder.mjs +88 -19
- package/package.json +4 -3
- package/src/acp/bridge.mjs +135 -26
- package/src/advisor/messages.mjs +57 -4
- package/src/advisor/run.mjs +119 -79
- package/src/advisor.mjs +34 -7
- package/src/agent/completion.mjs +17 -11
- package/src/agent/dispatch.mjs +182 -22
- package/src/agent/helpers.mjs +71 -4
- package/src/agent/record-results.mjs +46 -10
- package/src/agent/run-stages.mjs +227 -0
- package/src/agent/setup-reminders.mjs +62 -0
- package/src/agent/setup.mjs +107 -20
- package/src/agent/spawn-child.mjs +54 -4
- package/src/agent-tools/advisor-async.mjs +456 -0
- package/src/agent-tools/advisor.mjs +133 -109
- package/src/agent-tools/async-settle.mjs +191 -0
- package/src/agent-tools/consult.mjs +154 -104
- package/src/agent-tools/design-token.mjs +104 -0
- package/src/agent-tools/eng.mjs +26 -30
- package/src/agent-tools/escalate-async.mjs +286 -0
- package/src/agent-tools/goal.mjs +11 -1
- package/src/agent-tools/read-history.mjs +284 -0
- package/src/agent-tools/recent-changes.mjs +2 -1
- package/src/agent-tools/settings.mjs +152 -0
- package/src/agent-tools/skill.mjs +2 -1
- package/src/agent-tools/subagent-actions.mjs +470 -0
- package/src/agent-tools/subagent-async.mjs +382 -0
- package/src/agent-tools/subagent-panel.mjs +153 -0
- package/src/agent-tools/subagent-run.mjs +202 -0
- package/src/agent-tools/subagent-scheduler.mjs +343 -0
- package/src/agent-tools/subagent-spawn.mjs +406 -0
- package/src/agent-tools/subagent.mjs +203 -377
- package/src/agent-tools/task.mjs +4 -3
- package/src/agent-tools/timer.mjs +9 -4
- package/src/agent-tools/verify.mjs +198 -238
- package/src/agent-tools.mjs +1 -0
- package/src/agent.mjs +145 -242
- package/src/auto-think.mjs +14 -0
- package/src/cli/distill-command.mjs +10 -4
- package/src/cli/make-agent.mjs +4 -1
- package/src/cli/memory-command.mjs +2 -1
- package/src/cli/permission.mjs +8 -1
- package/src/cli/setup-wizard.mjs +17 -12
- package/src/config.mjs +61 -8
- package/src/context.mjs +81 -163
- package/src/crash-reports.mjs +123 -0
- package/src/distill.mjs +30 -12
- package/src/escape.mjs +6 -4
- package/src/explore-distill.mjs +155 -0
- package/src/log.mjs +195 -0
- package/src/memory/code-sync.mjs +2 -1
- package/src/memory/core.mjs +11 -72
- package/src/memory/delete.mjs +234 -0
- package/src/memory/docs.mjs +206 -87
- package/src/memory.mjs +3 -1
- package/src/model-specs.mjs +15 -1
- package/src/peer-domains.mjs +265 -0
- package/src/peer-instances.mjs +231 -0
- package/src/prompt-overlays.mjs +25 -0
- package/src/prompts/advisor-design.md +18 -39
- package/src/prompts/advisor-round1.md +20 -32
- package/src/prompts/advisor-round2.md +16 -16
- package/src/prompts/advisor-round3.md +16 -16
- package/src/prompts/coder.md +7 -28
- package/src/prompts/consult-base.md +4 -11
- package/src/prompts/discipline.md +31 -44
- package/src/prompts/eng-coder.md +9 -34
- package/src/prompts/engineering-sub.md +10 -8
- package/src/prompts/engineering.md +61 -264
- package/src/prompts/explore.md +4 -14
- package/src/prompts/main.md +18 -35
- package/src/prompts/methodology-template.md +32 -38
- package/src/prompts/plan.md +2 -9
- package/src/prompts/system.md +18 -35
- package/src/provider/core.mjs +62 -69
- package/src/provider/errors.mjs +76 -0
- package/src/provider/retry.mjs +8 -45
- package/src/session-gc.mjs +214 -0
- package/src/session-guard.mjs +47 -0
- package/src/session-rename.mjs +38 -0
- package/src/session-slots.mjs +181 -58
- package/src/session.mjs +48 -89
- package/src/token-ttl.mjs +273 -0
- package/src/tools/apply_patch.md +3 -1
- package/src/tools/bash.md +1 -1
- package/src/tools/checklist-sync.mjs +181 -0
- package/src/tools/checklist.mjs +52 -39
- package/src/tools/delete.md +1 -0
- package/src/tools/edit-batch.mjs +131 -44
- package/src/tools/edit-diff.mjs +348 -0
- package/src/tools/edit.md +20 -13
- package/src/tools/execute.md +7 -7
- package/src/tools/execute.mjs +55 -24
- package/src/tools/file.mjs +25 -70
- package/src/tools/file_ops.md +2 -1
- package/src/tools/get_current_time.md +3 -1
- package/src/tools/git.mjs +14 -6
- package/src/tools/glob-dialect.mjs +130 -0
- package/src/tools/glob.md +3 -3
- package/src/tools/grep.md +1 -1
- package/src/tools/hashline_edit.md +2 -0
- package/src/tools/index.mjs +3 -3
- package/src/tools/insert_after.md +2 -1
- package/src/tools/lint.md +2 -0
- package/src/tools/lsp.md +4 -1
- package/src/tools/ops.mjs +175 -3
- package/src/tools/patch.mjs +84 -13
- package/src/tools/question.md +5 -1
- package/src/tools/repomap.mjs +1 -1
- package/src/tools/shared.mjs +18 -25
- package/src/tools/system.mjs +50 -30
- package/src/tools/tree.md +2 -1
- package/src/tools/wait_for.md +22 -0
- package/src/tools/web.mjs +5 -3
- package/src/tools/websearch.md +2 -1
- package/src/tools/write.md +2 -0
- package/src/traces/trace-store.mjs +224 -0
- package/src/tui/agent-turn.mjs +179 -27
- package/src/tui/clipboard.mjs +15 -4
- package/src/tui/cmd-config.mjs +77 -16
- package/src/tui/cmd-eng.mjs +20 -16
- package/src/tui/cmd-extract.mjs +1 -1
- package/src/tui/cmd-mcp.mjs +17 -2
- package/src/tui/cmd-new.mjs +3 -2
- package/src/tui/cmd-session.mjs +19 -4
- package/src/tui/cmd-think.mjs +11 -11
- package/src/tui/cmd-upgrade.mjs +19 -4
- package/src/tui/config-helpers.mjs +28 -16
- package/src/tui/distill-cmd.mjs +1 -1
- package/src/tui/index.mjs +31 -96
- package/src/tui/interaction.mjs +13 -2
- package/src/tui/key-handler.mjs +105 -155
- package/src/tui/key-modes.mjs +215 -0
- package/src/tui/layout.mjs +22 -1
- package/src/tui/mouse.mjs +46 -0
- package/src/tui/pickers.mjs +51 -25
- package/src/tui/render-conversation.mjs +13 -161
- package/src/tui/render-frame.mjs +27 -10
- package/src/tui/render-loop.mjs +4 -1
- package/src/tui/render-segments.mjs +182 -0
- package/src/tui/startup.mjs +40 -0
- package/src/tui/subagent-blocks.mjs +272 -262
- package/src/tui/subagent-children.mjs +176 -0
- package/src/tui/subagent-freeze.mjs +172 -0
- package/src/tui/subagent-panel.mjs +125 -12
- package/src/tui/suspension-drive.mjs +351 -0
- package/src/tui/tool-args.mjs +10 -2
- package/src/tui/tool-display.mjs +142 -0
- package/src/tui/tool-events.mjs +127 -231
- package/src/tui/tui-lifecycle.mjs +29 -0
- package/src/tui/update-notice.mjs +76 -0
- package/src/tui/wizard.mjs +48 -12
- package/src/agent-tools/escalate.mjs +0 -179
- package/src/agent-tools/subagent-check.mjs +0 -107
- package/src/tools/exec-prelude.mjs +0 -84
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
renderMathAndMarkdown, foldCapRows, renderFoldedHead, foldTailLines,
|
|
17
17
|
} from "./fold-block.mjs"
|
|
18
18
|
import { ADVISOR_THINKING_PLACEHOLDER } from "../advisor/run.mjs"
|
|
19
|
+
import { frozenSubSeg, toolSeg, frozenAdvSeg } from "./render-segments.mjs"
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
// Test seam (mirrors the _-prefixed seams in run.mjs) — moved to fold-block.mjs.
|
|
@@ -27,7 +28,9 @@ let _convCache = { key: "", cols: 0, lines: [] }
|
|
|
27
28
|
/** 2026-08-31 懒加载卡顿优化②:段级行体缓存(行对象→conv 行数组)。
|
|
28
29
|
* 与行级 wrapRowsCached 分层:wrap 缓存只省 markdown/换行重算(streaming 行 text 变失效),
|
|
29
30
|
* 段缓存省**整个行体的折叠/展开/窗口化组装**——loadOlder unshift 后尾部 987 行段全命中,
|
|
30
|
-
* rebuild 从 25.7ms → ~8ms 量级。签名由 lineSegSig 集中计算(该段输出的所有决定因素)。
|
|
31
|
+
* rebuild 从 25.7ms → ~8ms 量级。签名由 lineSegSig 集中计算(该段输出的所有决定因素)。
|
|
32
|
+
* 2026-09-03 D-S2:tool/frozenSub/frozenAdvisor 三段缓存随段实现迁至 render-segments.mjs
|
|
33
|
+
* (各段独立 WeakMap——行对象载体系互斥——此处只剩普通源行段缓存)。 */
|
|
31
34
|
const _lineSegCache = new WeakMap()
|
|
32
35
|
|
|
33
36
|
/** 段签名:段输出的所有决定因素(漏一项 → 缓存失效不全 → 显示 stale)。
|
|
@@ -94,61 +97,6 @@ function buildLineSeg(state, l, i, cols, maxRows) {
|
|
|
94
97
|
return out
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
/** 工具块段(2026-08-31 段缓存抽出——真实会话 106 个工具块每帧全量 wrap 32ms 的根治)。
|
|
98
|
-
* 返回 conv 行数组(工具块的折叠头+尾/展开窗口+控制行),逻辑与原 L221-258 逐字同构。 */
|
|
99
|
-
function buildToolBlockSeg(state, l, i, cols, maxRows) {
|
|
100
|
-
const b = l._toolBlock
|
|
101
|
-
const foldKey = `tool-${l._lineId ?? i}`
|
|
102
|
-
const out = []
|
|
103
|
-
const status = !b.done
|
|
104
|
-
? "running"
|
|
105
|
-
: `${b.elapsed !== null ? b.elapsed + "ms" : ""}${b.summary ? (b.elapsed !== null ? " · " : "") + sliceByWidth(b.summary, 50) : ""}`.trim() || "done"
|
|
106
|
-
if (isExpanded(state, foldKey)) {
|
|
107
|
-
const body = []
|
|
108
|
-
const pushWrapped = (raw, color) => {
|
|
109
|
-
for (const w of wrapText(raw, cols - 4)) body.push({ text: " " + w, color, _skipDimFold: true })
|
|
110
|
-
}
|
|
111
|
-
for (const jl of b.argsJson) pushWrapped(jl, C.dim)
|
|
112
|
-
for (const ol of b.output) pushWrapped(ol, C.tool)
|
|
113
|
-
if (b.result) for (const rl of b.result) pushWrapped(rl, C.dim)
|
|
114
|
-
out.push(...renderExpandedBlock({ body, foldKey, state, maxRows, cols, label: `${b.name}${b.roundTag || ""} ${b.argsSummary}`.trim() }))
|
|
115
|
-
} else {
|
|
116
|
-
const headText = sliceByWidth(
|
|
117
|
-
`❯ ${b.name}${b.roundTag || ""}${b.argsSummary ? " " + b.argsSummary : ""} · ${status}`,
|
|
118
|
-
Math.max(20, cols - 2),
|
|
119
|
-
)
|
|
120
|
-
const body = []
|
|
121
|
-
for (const jl of b.argsJson) for (const w of wrapText(jl, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
122
|
-
for (const ol of b.output.slice(-3)) for (const w of wrapText(ol, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
123
|
-
if (b.result) for (const rl of b.result) for (const w of wrapText(rl, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
124
|
-
out.push(...renderFoldedHead({ header: { text: headText, color: C.tool, _foldToggle: foldKey }, body, cols }))
|
|
125
|
-
}
|
|
126
|
-
return out
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** frozenAdvisor 段(2026-08-31 段缓存抽出)——foldKey 升级为 _lineId 派生(同 long-N 判例)。 */
|
|
130
|
-
function buildFrozenAdvSeg(state, l, i, cols, maxRows) {
|
|
131
|
-
const frozenAdvKey = `advisor-done-${l._lineId ?? i}`
|
|
132
|
-
const out = []
|
|
133
|
-
if (isExpanded(state, frozenAdvKey)) {
|
|
134
|
-
const body = []
|
|
135
|
-
const rendered = renderMathAndMarkdown(sanitizeDisplay(l._frozenAdvisor))
|
|
136
|
-
for (const line of formatTables(rendered, cols - 1)) {
|
|
137
|
-
for (const wrapped of wrapText(line, cols - 1)) {
|
|
138
|
-
body.push({ text: wrapped, color: C.reason, _skipDimFold: true })
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
out.push(...renderExpandedBlock({ body, foldKey: frozenAdvKey, state, maxRows, cols, label: "[advisor · review done]" }))
|
|
142
|
-
} else {
|
|
143
|
-
out.push({
|
|
144
|
-
text: `▶ [advisor · review done] … click to expand`,
|
|
145
|
-
color: C.fold,
|
|
146
|
-
_foldToggle: frozenAdvKey,
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
return out
|
|
150
|
-
}
|
|
151
|
-
|
|
152
100
|
|
|
153
101
|
/** 2026-08-31 懒加载卡顿根因修复:行级 wrap/markdown 渲染缓存。
|
|
154
102
|
* buildConvLines 全量重建 O(总行数)——真实 200 条历史 → 987 conv 行 94ms、loadOlder 后
|
|
@@ -219,9 +167,6 @@ export function convCacheKey(state, maxRows) {
|
|
|
219
167
|
return `${state.lines.length}|${lastLine?.text.length ?? 0}|${state.streaming.length}|${state.reasoning.length}|${blocksSig}|${frozenSig}|${toolSig}|${colorSig}|${state.foldEnabled !== false ? "f" : "u"}|${exp}|${capPart}|${searchPart}|${foldScrollSig}`
|
|
220
168
|
}
|
|
221
169
|
|
|
222
|
-
/** Fold marker line: bold-cyan icon + "click to …" phrase underlined (clickable affordance).
|
|
223
|
-
* No indent — flush with the content below it; the caller adds a blank line BEFORE it
|
|
224
|
-
* so the control line stands apart from unrelated content (reported UX). */
|
|
225
170
|
|
|
226
171
|
function highlightSearchMatches(text, query, matchesInLine, globalCurrentIndex, allMatches, lineIndex) {
|
|
227
172
|
if (!matchesInLine || matchesInLine.length === 0 || !query) return text
|
|
@@ -247,45 +192,6 @@ function highlightSearchMatches(text, query, matchesInLine, globalCurrentIndex,
|
|
|
247
192
|
return result
|
|
248
193
|
}
|
|
249
194
|
|
|
250
|
-
/** Render a FROZEN child activity block carried on a state.lines entry
|
|
251
|
-
* (subagent-blocks.mjs freezeSubTaskLines pushes {_frozenSubTask: sub}). The
|
|
252
|
-
* running form renders in the fixed bottom panel (§7.2.1 subagent-panel.mjs);
|
|
253
|
-
* the frozen form stays in the stream with the same interaction: folded =
|
|
254
|
-
* `[✓ coder#1 · glm-5.3 · done 45s · turn 12/100] … click to expand` header +
|
|
255
|
-
* tail 3 block lines; expanded = blank + ▼ control + full timeline (60% screen
|
|
256
|
-
* cap via the shared component — capped view ends in a reachable collapse
|
|
257
|
-
* control). Toggle key `sub-${key}` — the SAME key the panel section uses, so
|
|
258
|
-
* fold state carries across the freeze boundary seamlessly (user ruled
|
|
259
|
-
* 2026-08-30: frozen stays clickable — full design interaction, not a
|
|
260
|
-
* dim-lines fallback). */
|
|
261
|
-
function frozenSubTaskLines(state, sub, cols, maxRows) {
|
|
262
|
-
const foldKey = `sub-${sub.key}`
|
|
263
|
-
const elapsed = Math.floor(((sub.doneAt ?? Date.now()) - sub.started) / 1000)
|
|
264
|
-
const modelPart = sub.model ? ` · ${sub.model}` : ""
|
|
265
|
-
const turnPart = sub.maxTurns > 0 ? ` · turn ${sub.turn}/${sub.maxTurns}` : ""
|
|
266
|
-
const errPart = sub.lastError ? ` — ${sub.lastError}` : ""
|
|
267
|
-
const icon = sub.approval ? "⏸" : "✓"
|
|
268
|
-
const header = `[${icon} ${sub.key}${modelPart} · done ${elapsed}s${turnPart}${errPart}]`
|
|
269
|
-
const out = []
|
|
270
|
-
if (isExpanded(state, foldKey)) {
|
|
271
|
-
// Expanded: shared component renders blank + ▼ control + full timeline,
|
|
272
|
-
// capped at 60% of the screen with a bottom collapse control.
|
|
273
|
-
const body = renderBlockTimeline(sub.blocks, cols)
|
|
274
|
-
out.push(...renderExpandedBlock({ body, foldKey, state, maxRows, cols, label: "subagent activity" }))
|
|
275
|
-
} else {
|
|
276
|
-
// Folded: the header line itself is the control (▶ affordance), then tail 3.
|
|
277
|
-
out.push({
|
|
278
|
-
text: `▶ ${header} … subagent activity — click to expand`,
|
|
279
|
-
color: C.dim,
|
|
280
|
-
_foldToggle: foldKey,
|
|
281
|
-
})
|
|
282
|
-
for (const line of foldTailLines(sub.blocks)) {
|
|
283
|
-
out.push({ text: `│ ${sliceByWidth(line, cols - 4)}`, color: C.dim, _skipDimFold: true })
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return out
|
|
287
|
-
}
|
|
288
|
-
|
|
289
195
|
/**
|
|
290
196
|
* Build the conversation lines for the given state.
|
|
291
197
|
* maxRows: terminal rows for the 60% expansion cap (undefined → uncapped —
|
|
@@ -329,77 +235,23 @@ function buildConvLines(state, cols, maxRows) {
|
|
|
329
235
|
if (!prevMain) pushBlank()
|
|
330
236
|
blankAfter = !nextMain
|
|
331
237
|
}
|
|
332
|
-
// Frozen subagent activity block (§7.2 D4, 2026-08-30):
|
|
333
|
-
//
|
|
334
|
-
// §7.2.1 — the frozen form keeps the same clickable interaction).
|
|
238
|
+
// Frozen subagent activity block (§7.2 D4, 2026-08-30): frozen form keeps the
|
|
239
|
+
// same clickable interaction as the running panel (impl in render-segments.mjs).
|
|
335
240
|
if (l._frozenSubTask) {
|
|
336
|
-
|
|
337
|
-
const fKey = `sub-${l._frozenSubTask.key}`
|
|
338
|
-
const fSig = [
|
|
339
|
-
cols, maxRows ?? 0, l._frozenSubTask.key, l._frozenSubTask.blocks?.length ?? 0,
|
|
340
|
-
l._frozenSubTask.done ? 1 : 0, state.foldEnabled === false ? 0 : 1,
|
|
341
|
-
state.expandedBlocks?.has(fKey) ? 1 : 0, state._foldScroll?.get(fKey) ?? 0,
|
|
342
|
-
].join("|")
|
|
343
|
-
const fHit = _lineSegCache.get(l)
|
|
344
|
-
if (fHit && fHit.textRef === l._frozenSubTask && fHit.sig === fSig) {
|
|
345
|
-
convLines.push(...fHit.rows)
|
|
346
|
-
} else {
|
|
347
|
-
const rows = frozenSubTaskLines(state, l._frozenSubTask, cols, maxRows)
|
|
348
|
-
_lineSegCache.set(l, { textRef: l._frozenSubTask, sig: fSig, rows })
|
|
349
|
-
convLines.push(...rows)
|
|
350
|
-
}
|
|
241
|
+
convLines.push(...frozenSubSeg(state, l, i, cols, maxRows))
|
|
351
242
|
continue
|
|
352
243
|
}
|
|
353
|
-
// ONE BLOCK PER TOOL CALL (2026-08-30 user ruling)
|
|
354
|
-
// live status, body = args JSON + streaming output + result. Folded =
|
|
355
|
-
// ▶ name args · status/summary; expanded = 60%-capped body (shared component).
|
|
244
|
+
// ONE BLOCK PER TOOL CALL (2026-08-30 user ruling) — impl in render-segments.mjs.
|
|
356
245
|
if (l._toolBlock) {
|
|
357
|
-
|
|
358
|
-
// 流式 append 使 output.length 变 → 失效;real 会话 106 个工具块每帧全量 wrap 实测
|
|
359
|
-
// 32ms(rebuild 40ms 的大头),入缓存后命中只算签名拼接。
|
|
360
|
-
const b = l._toolBlock
|
|
361
|
-
const toolFoldKey = `tool-${l._lineId ?? i}`
|
|
362
|
-
const tSig = [
|
|
363
|
-
cols, maxRows ?? 0, b.argsJson?.length ?? 0, b.output?.length ?? 0, b.result?.length ?? 0,
|
|
364
|
-
b.done ? 1 : 0, b.elapsed ?? "", b.summary ?? "", b.name ?? "", b.roundTag ?? "",
|
|
365
|
-
l._lineId ?? "", state.foldEnabled === false ? 0 : 1,
|
|
366
|
-
state.expandedBlocks?.has(toolFoldKey) ? 1 : 0, state._foldScroll?.get(toolFoldKey) ?? 0,
|
|
367
|
-
].join("|")
|
|
368
|
-
const tHit = _lineSegCache.get(l)
|
|
369
|
-
if (tHit && tHit.textRef === b && tHit.sig === tSig) {
|
|
370
|
-
convLines.push(...tHit.rows)
|
|
371
|
-
} else {
|
|
372
|
-
const rows = buildToolBlockSeg(state, l, i, cols, maxRows)
|
|
373
|
-
_lineSegCache.set(l, { textRef: b, sig: tSig, rows })
|
|
374
|
-
convLines.push(...rows)
|
|
375
|
-
}
|
|
246
|
+
convLines.push(...toolSeg(state, l, i, cols, maxRows))
|
|
376
247
|
continue
|
|
377
248
|
}
|
|
378
|
-
// Frozen advisor review (2026-08-30): same collapsible-box treatment —
|
|
379
|
-
//
|
|
380
|
-
// rendered, no gutter — review history convention kept from the flat era),
|
|
381
|
-
// 60% cap via the shared component.
|
|
249
|
+
// Frozen advisor review (2026-08-30): same collapsible-box treatment — impl
|
|
250
|
+
// in render-segments.mjs.
|
|
382
251
|
if (l._frozenAdvisor) {
|
|
383
|
-
|
|
384
|
-
// 注:foldKey 由 advisor-done-${i}(位置键)升级为 advisor-done-${_lineId ?? i}
|
|
385
|
-
// (同 long-N 判例——loadOlder unshift 后不重绑)
|
|
386
|
-
const frozenAdvKey = `advisor-done-${l._lineId ?? i}`
|
|
387
|
-
const aSig = [
|
|
388
|
-
cols, maxRows ?? 0, (l._frozenAdvisor ?? "").length,
|
|
389
|
-
state.foldEnabled === false ? 0 : 1,
|
|
390
|
-
state.expandedBlocks?.has(frozenAdvKey) ? 1 : 0, state._foldScroll?.get(frozenAdvKey) ?? 0,
|
|
391
|
-
].join("|")
|
|
392
|
-
const aHit = _lineSegCache.get(l)
|
|
393
|
-
if (aHit && aHit.textRef === l._frozenAdvisor && aHit.sig === aSig) {
|
|
394
|
-
convLines.push(...aHit.rows)
|
|
395
|
-
} else {
|
|
396
|
-
const rows = buildFrozenAdvSeg(state, l, i, cols, maxRows)
|
|
397
|
-
_lineSegCache.set(l, { textRef: l._frozenAdvisor, sig: aSig, rows })
|
|
398
|
-
convLines.push(...rows)
|
|
399
|
-
}
|
|
252
|
+
convLines.push(...frozenAdvSeg(state, l, i, cols, maxRows))
|
|
400
253
|
continue
|
|
401
254
|
}
|
|
402
|
-
|
|
403
255
|
// ── 普通源行段(2026-08-31 懒加载卡顿优化②:段级缓存——行体 WeakMap 按行对象
|
|
404
256
|
// 缓存,签名含该段所有决定因素;unshift/loadOlder 后尾部段全命中,只算新增行。
|
|
405
257
|
// toggle/翻窗/收起只失效该块段,其它段照样命中。行为不变性是硬约束。
|
|
@@ -425,7 +277,7 @@ function buildConvLines(state, cols, maxRows) {
|
|
|
425
277
|
// buildConvLines no longer renders running children: on completion
|
|
426
278
|
// onToolResult freezes the block into state.lines (subagent-blocks.mjs
|
|
427
279
|
// freezeSubTaskLines) and it scrolls away with the conversation (D4 现状).
|
|
428
|
-
// Frozen blocks render above via the _frozenSubTask branch (
|
|
280
|
+
// Frozen blocks render above via the _frozenSubTask branch (render-segments.mjs).
|
|
429
281
|
|
|
430
282
|
if (state.reasoning) {
|
|
431
283
|
// Live thinking streams INSIDE the unified box (user ruling 2026-08-30:
|
package/src/tui/render-frame.mjs
CHANGED
|
@@ -132,11 +132,19 @@ export function renderInputBox(state, W, boxLines, cols, inputLayout, inputOffse
|
|
|
132
132
|
if (title === " Input " || title === " Question " || title === " Inject Message " || title === " Processing... ") {
|
|
133
133
|
const parts = []
|
|
134
134
|
if (title === " Input " || title === " Processing... ") parts.push(" Ctrl+U clear ")
|
|
135
|
-
if (title === " Question ")
|
|
135
|
+
if (title === " Question ") {
|
|
136
|
+
// question 两形态各自真实按键提示(TUI-INPUT-BOX.md §7.2——自由文本态单行不变式:
|
|
137
|
+
// 无换行键——Shift+Enter/Ctrl+J 不插行,提示不沿用主输入框那组)。
|
|
138
|
+
parts.push((state.question?.options?.length ?? 0) > 0
|
|
139
|
+
? " ↑↓ select │ Enter confirm │ Esc: cancel "
|
|
140
|
+
: " Enter submit │ Esc: cancel │ Ctrl+U clear │ Ctrl+V paste ")
|
|
141
|
+
}
|
|
136
142
|
if (title === " Inject Message ") parts.push(" Enter send, Esc cancel ")
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
if (title !== " Question ") {
|
|
144
|
+
parts.push(" Shift+Enter / Ctrl+J newline ")
|
|
145
|
+
parts.push(" Ctrl+V paste ")
|
|
146
|
+
parts.push(" Ctrl+I inject ")
|
|
147
|
+
}
|
|
140
148
|
const hint = parts.join("")
|
|
141
149
|
topBorder = `╭─${title}${"─".repeat(Math.max(0, W - 4 - stringWidth(title) - stringWidth(hint)))}${hint}─╮`
|
|
142
150
|
} else {
|
|
@@ -144,8 +152,11 @@ export function renderInputBox(state, W, boxLines, cols, inputLayout, inputOffse
|
|
|
144
152
|
}
|
|
145
153
|
const out = [`${borderColor}${topBorder}${ansi.reset}`]
|
|
146
154
|
|
|
147
|
-
// Visual cursor position in the input box (hardware cursor stays hidden)
|
|
148
|
-
|
|
155
|
+
// Visual cursor position in the input box (hardware cursor stays hidden).
|
|
156
|
+
// hasOverlay 例外细化(TUI-INPUT-BOX.md §7.2):question 自由文本态(无 options)保留
|
|
157
|
+
// 反显光标(与主输入框同路径);options/permission/picker/wizard-provider 态无光标。
|
|
158
|
+
const qOptionsOnly = Boolean(state.question && state.question.options.length > 0)
|
|
159
|
+
const hasOverlay = state.permission || qOptionsOnly || state.picker || state.wizard?.step === "provider"
|
|
149
160
|
const curLine = (!hasOverlay && inputLayout) ? inputLayout.cursorLine - (inputOffset ?? 0) : -1
|
|
150
161
|
const curCol = (!hasOverlay && inputLayout) ? inputLayout.cursorCol : -1
|
|
151
162
|
|
|
@@ -256,13 +267,19 @@ export function renderRows(state, agent, opts) {
|
|
|
256
267
|
if (panels.picker) put(panels.picker.y, renderPicker(state, cols, panels.picker, overlay))
|
|
257
268
|
if (panels.permission) put(panels.permission.y, renderPermission(permPreviewLines))
|
|
258
269
|
if (panels.queue) put(panels.queue.y, [renderQueue(state, W)])
|
|
259
|
-
|
|
270
|
+
// question 自由文本态:box 内容是 layoutAnswer 行——光标布局/滚动随 box 内容走
|
|
271
|
+
// (questionLayout/questionOffset);主输入 inputLayout 此时无意义(被 question 行替换)。
|
|
272
|
+
const qFree = Boolean(state.question && state.question.options.length === 0)
|
|
273
|
+
const qOptionsOnly = Boolean(state.question && state.question.options.length > 0)
|
|
274
|
+
const boxLayout = qFree ? (layout.questionLayout ?? layout.inputLayout) : layout.inputLayout
|
|
275
|
+
const boxOffset = qFree ? (layout.questionOffset ?? 0) : layout.inputOffset
|
|
276
|
+
put(panels.inputBox.y, renderInputBox(state, W, boxLines, cols, boxLayout, boxOffset))
|
|
260
277
|
put(panels.status.y, [renderStatus(state, agent, cols, slashCommands)])
|
|
261
278
|
|
|
262
279
|
let cursorRow = 0, cursorCol = 0
|
|
263
|
-
if (!state.permission && !state.
|
|
264
|
-
cursorRow = panels.inputBox.y + 1 + (
|
|
265
|
-
cursorCol = 3 +
|
|
280
|
+
if (!state.permission && !state.picker && state.wizard?.step !== "provider" && !qOptionsOnly) {
|
|
281
|
+
cursorRow = panels.inputBox.y + 1 + (boxLayout.cursorLine - boxOffset) + 1
|
|
282
|
+
cursorCol = 3 + boxLayout.cursorCol
|
|
266
283
|
}
|
|
267
284
|
|
|
268
285
|
return { rows: screen, cursorRow, cursorCol, layout }
|
package/src/tui/render-loop.mjs
CHANGED
|
@@ -111,7 +111,10 @@ export function createRenderLoop(state, agent, ctx, pushLine, write = (s) => pro
|
|
|
111
111
|
}
|
|
112
112
|
prevRows = rows
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
// hasOverlay 例外细化(TUI-INPUT-BOX.md §7.2):question 自由文本态(无 options)
|
|
115
|
+
// 保留硬件定位(cursorSuffix 正常发——与主输入框同路径);options 态无光标。
|
|
116
|
+
const qOptionsOnly = Boolean(state.question && state.question.options.length > 0)
|
|
117
|
+
const hasOverlay = state.permission || qOptionsOnly || state.picker || state.wizard?.step === "provider"
|
|
115
118
|
const cursorSuffix = hasOverlay ? "" : `\x1b[${cursorRow};${cursorCol}H${ansi.hideCursor}`
|
|
116
119
|
|
|
117
120
|
if (out.length || cursorSuffix) write(ansi.wrapOff + ansi.syncUpdateStart + out.join("") + ansi.syncUpdateEnd + cursorSuffix + ansi.wrapOn)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* render-segments.mjs — 对话行三类特殊段渲染(2026-09-03 D-S2 自 render-conversation.mjs 拆出):
|
|
3
|
+
* tool 块 / frozenSubTask 冻结子agent 块 / frozenAdvisor 冻结评审块。各段自带独立 WeakMap
|
|
4
|
+
* 段级缓存(行对象载体系互斥——_toolBlock/_frozenSubTask/_frozenAdvisor 三型不共存于一行,
|
|
5
|
+
* 分支互斥 if——与共享缓存行为等价);签名由各段集中计算(该段输出的所有决定因素,漏一项
|
|
6
|
+
* → 缓存失效不全 → 显示 stale)。buildConvLines 主循环只留三分支 ~3 行调用。
|
|
7
|
+
*/
|
|
8
|
+
import { C } from "./ansi.mjs"
|
|
9
|
+
import { formatTables, sanitizeDisplay, sliceByWidth, wrapText } from "./render.mjs"
|
|
10
|
+
import {
|
|
11
|
+
foldTailLines, isExpanded, renderBlockTimeline, renderExpandedBlock, renderFoldedHead, renderMathAndMarkdown,
|
|
12
|
+
} from "./fold-block.mjs"
|
|
13
|
+
import { renderSubChildSections, subChildFoldKey } from "./subagent-panel.mjs"
|
|
14
|
+
import { SUBAGENT_ROLES } from "./subagent-blocks.mjs"
|
|
15
|
+
|
|
16
|
+
const _toolSegCache = new WeakMap()
|
|
17
|
+
const _frozenSubCache = new WeakMap()
|
|
18
|
+
const _frozenAdvCache = new WeakMap()
|
|
19
|
+
|
|
20
|
+
/** 工具块段(2026-08-31 段缓存抽出——真实会话 106 个工具块每帧全量 wrap 32ms 的根治)。
|
|
21
|
+
* 返回 conv 行数组(工具块的折叠头+尾/展开窗口+控制行),逻辑与原 L221-258 逐字同构。 */
|
|
22
|
+
function buildToolBlockSeg(state, l, i, cols, maxRows) {
|
|
23
|
+
const b = l._toolBlock
|
|
24
|
+
const foldKey = `tool-${l._lineId ?? i}`
|
|
25
|
+
const out = []
|
|
26
|
+
const status = !b.done
|
|
27
|
+
? "running"
|
|
28
|
+
: `${b.elapsed !== null ? b.elapsed + "ms" : ""}${b.summary ? (b.elapsed !== null ? " · " : "") + sliceByWidth(b.summary, 50) : ""}`.trim() || "done"
|
|
29
|
+
if (isExpanded(state, foldKey)) {
|
|
30
|
+
const body = []
|
|
31
|
+
const pushWrapped = (raw, color) => {
|
|
32
|
+
for (const w of wrapText(raw, cols - 4)) body.push({ text: " " + w, color, _skipDimFold: true })
|
|
33
|
+
}
|
|
34
|
+
for (const jl of b.argsJson) pushWrapped(jl, C.dim)
|
|
35
|
+
for (const ol of b.output) pushWrapped(ol, C.tool)
|
|
36
|
+
if (b.result) for (const rl of b.result) pushWrapped(rl, C.dim)
|
|
37
|
+
out.push(...renderExpandedBlock({ body, foldKey, state, maxRows, cols, label: `${b.name}${b.roundTag || ""} ${b.argsSummary}`.trim() }))
|
|
38
|
+
} else {
|
|
39
|
+
const headText = sliceByWidth(
|
|
40
|
+
`❯ ${b.name}${b.roundTag || ""}${b.argsSummary ? " " + b.argsSummary : ""} · ${status}`,
|
|
41
|
+
Math.max(20, cols - 2),
|
|
42
|
+
)
|
|
43
|
+
const body = []
|
|
44
|
+
for (const jl of b.argsJson) for (const w of wrapText(jl, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
45
|
+
for (const ol of b.output.slice(-3)) for (const w of wrapText(ol, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
46
|
+
if (b.result) for (const rl of b.result) for (const w of wrapText(rl, cols - 4)) body.push({ text: w, color: C.dim, _skipDimFold: true })
|
|
47
|
+
out.push(...renderFoldedHead({ header: { text: headText, color: C.tool, _foldToggle: foldKey }, body, cols }))
|
|
48
|
+
}
|
|
49
|
+
return out
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 工具块段入口(2026-08-31 段缓存:工具块签名含三缓冲长度+done/elapsed/summary+该块展开态——
|
|
53
|
+
* 流式 append 使 output.length 变 → 失效;real 会话 106 个工具块每帧全量 wrap 实测
|
|
54
|
+
* 32ms(rebuild 40ms 的大头),入缓存后命中只算签名拼接)。 */
|
|
55
|
+
export function toolSeg(state, l, i, cols, maxRows) {
|
|
56
|
+
const b = l._toolBlock
|
|
57
|
+
const toolFoldKey = `tool-${l._lineId ?? i}`
|
|
58
|
+
const tSig = [
|
|
59
|
+
cols, maxRows ?? 0, b.argsJson?.length ?? 0, b.output?.length ?? 0, b.result?.length ?? 0,
|
|
60
|
+
b.done ? 1 : 0, b.elapsed ?? "", b.summary ?? "", b.name ?? "", b.roundTag ?? "",
|
|
61
|
+
l._lineId ?? "", state.foldEnabled === false ? 0 : 1,
|
|
62
|
+
state.expandedBlocks?.has(toolFoldKey) ? 1 : 0, state._foldScroll?.get(toolFoldKey) ?? 0,
|
|
63
|
+
].join("|")
|
|
64
|
+
const hit = _toolSegCache.get(l)
|
|
65
|
+
if (hit && hit.textRef === b && hit.sig === tSig) return hit.rows
|
|
66
|
+
const rows = buildToolBlockSeg(state, l, i, cols, maxRows)
|
|
67
|
+
_toolSegCache.set(l, { textRef: b, sig: tSig, rows })
|
|
68
|
+
return rows
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 冻结子agent 活动块渲染(§7.2 D4):state.lines 载体 {_frozenSubTask: sub}(subagent-blocks.mjs
|
|
72
|
+
* freezeSubTaskLines 推入)。折叠 = 身份头 + tail 3;展开 = 共享组件(60% 屏幕封顶 + 底部可达
|
|
73
|
+
* 折叠控制)。折叠键 `sub-${key}`——与运行中面板区块同键,折叠态跨冻结边界无缝延续。
|
|
74
|
+
* §27 R23:子块段(renderSubChildSections)随冻结载体渲染(冻结含子块——T-R23d.1)。 */
|
|
75
|
+
function frozenSubTaskLines(state, sub, cols, maxRows) {
|
|
76
|
+
const foldKey = `sub-${sub.key}`
|
|
77
|
+
const elapsed = Math.floor(((sub.doneAt ?? Date.now()) - sub.started) / 1000)
|
|
78
|
+
// §19.5 D-M7b ②: 冻结头保留 sync/async 标识(done 头含历史语义——与 model 标识
|
|
79
|
+
// 同生命周期);仅真实 subagent 角色(compress 冻结等无语义)。整行 dim——
|
|
80
|
+
// 无需 ANSI 注入(running 面板头则套 dim + 恢复行色——subagent-panel.mjs)。
|
|
81
|
+
const isSubRole = SUBAGENT_ROLES.includes(sub.role)
|
|
82
|
+
// §20:冻结的 queued 块(中止清场兜底——interrupted)标 waiting——不误标 sync
|
|
83
|
+
const modePart = isSubRole
|
|
84
|
+
? ` · ${sub.queued ? "waiting" : (sub.async === true ? "async" : "sync")}`
|
|
85
|
+
: ""
|
|
86
|
+
const modelPart = sub.model ? ` · ${sub.model}` : ""
|
|
87
|
+
const turnPart = sub.maxTurns > 0 ? ` · turn ${sub.turn}/${sub.maxTurns}` : ""
|
|
88
|
+
const errPart = sub.lastError ? ` — ${sub.lastError}` : ""
|
|
89
|
+
const icon = sub.approval ? "⏸" : "✓"
|
|
90
|
+
const verb = sub.stopped ? "stopped" : "done" // §19.5: cancel 冻结标题 "stopped"
|
|
91
|
+
const header = `[${icon} ${sub.key}${modePart}${modelPart} · ${verb} ${elapsed}s${turnPart}${errPart}]`
|
|
92
|
+
const out = []
|
|
93
|
+
if (isExpanded(state, foldKey)) {
|
|
94
|
+
// Expanded: shared component renders blank + ▼ control + full timeline,
|
|
95
|
+
// capped at 60% of the screen with a bottom collapse control.
|
|
96
|
+
const body = renderBlockTimeline(sub.blocks, cols)
|
|
97
|
+
out.push(...renderExpandedBlock({ body, foldKey, state, maxRows, cols, label: "subagent activity" }))
|
|
98
|
+
} else {
|
|
99
|
+
// Folded: the header line itself is the control (▶ affordance), then tail 3.
|
|
100
|
+
out.push({
|
|
101
|
+
text: `▶ ${header} … subagent activity — click to expand`,
|
|
102
|
+
color: C.dim,
|
|
103
|
+
_foldToggle: foldKey,
|
|
104
|
+
})
|
|
105
|
+
for (const line of foldTailLines(sub.blocks)) {
|
|
106
|
+
out.push({ text: `│ ${sliceByWidth(line, cols - 4)}`, color: C.dim, _skipDimFold: true })
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// §27 R23:子块段随冻结载体(折叠/展开两态都渲染——子块自身折叠键独立控制)。
|
|
110
|
+
out.push(...renderSubChildSections(state, sub, cols, maxRows))
|
|
111
|
+
return out
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 冻结子agent 段入口(2026-08-31 段缓存:冻结后内容不变——签名含 sub.key + blocks 计数 +
|
|
115
|
+
* 子块树签名(R23——children 折叠态/滚动/行数参与——toggle 子块/翻窗必须失效);注:
|
|
116
|
+
* foldKey 由位置键升级为 sub.key(loadOlder unshift 后不重绑——sub 自身携带 key)。 */
|
|
117
|
+
export function frozenSubSeg(state, l, i, cols, maxRows) {
|
|
118
|
+
const fKey = `sub-${l._frozenSubTask.key}`
|
|
119
|
+
// §27 R23:子块树渲染输入签名(key/done/stopped/blocks 数/折叠态/窗口偏移——递归)
|
|
120
|
+
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
|
+
const fSig = [
|
|
132
|
+
cols, maxRows ?? 0, sub.key, sub.blocks?.length ?? 0,
|
|
133
|
+
sub.done ? 1 : 0, state.foldEnabled === false ? 0 : 1,
|
|
134
|
+
state.expandedBlocks?.has(fKey) ? 1 : 0, state._foldScroll?.get(fKey) ?? 0,
|
|
135
|
+
childSig,
|
|
136
|
+
].join("|")
|
|
137
|
+
const hit = _frozenSubCache.get(l)
|
|
138
|
+
if (hit && hit.textRef === sub && hit.sig === fSig) return hit.rows
|
|
139
|
+
const rows = frozenSubTaskLines(state, sub, cols, maxRows)
|
|
140
|
+
_frozenSubCache.set(l, { textRef: sub, sig: fSig, rows })
|
|
141
|
+
return rows
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** frozenAdvisor 段渲染——冻结后文本不变(markdown 渲染、无 gutter——review 历史惯例);
|
|
145
|
+
* foldKey 由 advisor-done-${i}(位置键)升级为 advisor-done-${_lineId ?? i}(同 long-N
|
|
146
|
+
* 判例——loadOlder unshift 后不重绑)。 */
|
|
147
|
+
function buildFrozenAdvSeg(state, l, i, cols, maxRows) {
|
|
148
|
+
const frozenAdvKey = `advisor-done-${l._lineId ?? i}`
|
|
149
|
+
const out = []
|
|
150
|
+
if (isExpanded(state, frozenAdvKey)) {
|
|
151
|
+
const body = []
|
|
152
|
+
const rendered = renderMathAndMarkdown(sanitizeDisplay(l._frozenAdvisor))
|
|
153
|
+
for (const line of formatTables(rendered, cols - 1)) {
|
|
154
|
+
for (const wrapped of wrapText(line, cols - 1)) {
|
|
155
|
+
body.push({ text: wrapped, color: C.reason, _skipDimFold: true })
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
out.push(...renderExpandedBlock({ body, foldKey: frozenAdvKey, state, maxRows, cols, label: "[advisor · review done]" }))
|
|
159
|
+
} else {
|
|
160
|
+
out.push({
|
|
161
|
+
text: `▶ [advisor · review done] … click to expand`,
|
|
162
|
+
color: C.fold,
|
|
163
|
+
_foldToggle: frozenAdvKey,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
return out
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** frozenAdvisor 段入口(2026-08-31 段缓存:frozenAdvisor 文本冻结不变——签名含文本长度 + 展开态)。 */
|
|
170
|
+
export function frozenAdvSeg(state, l, i, cols, maxRows) {
|
|
171
|
+
const frozenAdvKey = `advisor-done-${l._lineId ?? i}`
|
|
172
|
+
const aSig = [
|
|
173
|
+
cols, maxRows ?? 0, (l._frozenAdvisor ?? "").length,
|
|
174
|
+
state.foldEnabled === false ? 0 : 1,
|
|
175
|
+
state.expandedBlocks?.has(frozenAdvKey) ? 1 : 0, state._foldScroll?.get(frozenAdvKey) ?? 0,
|
|
176
|
+
].join("|")
|
|
177
|
+
const hit = _frozenAdvCache.get(l)
|
|
178
|
+
if (hit && hit.textRef === l._frozenAdvisor && hit.sig === aSig) return hit.rows
|
|
179
|
+
const rows = buildFrozenAdvSeg(state, l, i, cols, maxRows)
|
|
180
|
+
_frozenAdvCache.set(l, { textRef: l._frozenAdvisor, sig: aSig, rows })
|
|
181
|
+
return rows
|
|
182
|
+
}
|
package/src/tui/startup.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { listSlots } from "../session.mjs"
|
|
|
2
2
|
import { ansi, C } from "./ansi.mjs"
|
|
3
3
|
import { describeToolArgs, toolArgsLines } from "./tool-args.mjs"
|
|
4
4
|
import { slimToolResultForDisplay } from "./tool-events.mjs"
|
|
5
|
+
import { countConvLines } from "./render-conversation.mjs"
|
|
5
6
|
|
|
6
7
|
/** Lazy history window (parity with VS Code HISTORY_PAGE_SIZE): first paint loads
|
|
7
8
|
* the latest INITIAL_HISTORY_MESSAGES, then PgUp-at-top loads HISTORY_PAGE_MESSAGES
|
|
@@ -133,6 +134,41 @@ export function restoreLines(state, history) {
|
|
|
133
134
|
state.lines.unshift({ text: `… ${start} more earlier messages (PgUp at top to load)`, color: C.dim })
|
|
134
135
|
}
|
|
135
136
|
}
|
|
137
|
+
/** 懒加载更早历史(2026-08-31 用户约定:"滚动到头自动加载"——滚轮/PgUp 到顶皆触发;
|
|
138
|
+
* 2026-08-31 前只挂 PgUp 键 = 违约,滚轮到头无反应)。加载后滚动补偿保持锚定。
|
|
139
|
+
* 2026-09-03 D-S1b 自 index.mjs 迁入(startup 职责本含懒加载历史窗口——TUI.md §1 归属修复):
|
|
140
|
+
* 调用方(index.mjs)= stdin data 滚轮分支 + createKeyHandler ctx(PgUp 分支)。
|
|
141
|
+
* ctx: { agent, state, render } */
|
|
142
|
+
export function createLoadOlder({ agent, state, render }) {
|
|
143
|
+
return () => {
|
|
144
|
+
if (!state._hasOlder) return
|
|
145
|
+
const full = agent._fullHistory ?? []
|
|
146
|
+
const loaded = state._historyLoaded
|
|
147
|
+
const start = Math.max(0, full.length - loaded - HISTORY_PAGE_MESSAGES)
|
|
148
|
+
const end = full.length - loaded
|
|
149
|
+
if (start >= end) return
|
|
150
|
+
|
|
151
|
+
const d = state.dims ? state.dims.get() : {}
|
|
152
|
+
const cols = d.cols ?? ((state.dims?.get() ?? {}).cols ?? (process.stdout.columns || 80))
|
|
153
|
+
const before = countConvLines(state, cols, d.rows ?? (process.stdout.rows || 24))
|
|
154
|
+
|
|
155
|
+
if (state.lines[0]?.text?.startsWith("… ")) state.lines.shift()
|
|
156
|
+
state._lineIdCounter = state._lineIdCounter ?? 0
|
|
157
|
+
const older = historyToLines(full, start, end)
|
|
158
|
+
for (const l of older) l._lineId = ++state._lineIdCounter
|
|
159
|
+
state.lines.unshift(...older)
|
|
160
|
+
state._historyLoaded += end - start
|
|
161
|
+
state._hasOlder = start > 0
|
|
162
|
+
if (state._hasOlder) {
|
|
163
|
+
state.lines.unshift({ text: `… ${start} more earlier messages (scroll to top to load)`, color: C.dim })
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const after = countConvLines(state, cols, (state.dims?.get() ?? {}).rows ?? (process.stdout.rows || 24))
|
|
167
|
+
state.scroll += Math.max(0, after - before)
|
|
168
|
+
render()
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
136
172
|
/** Startup screen + session recovery + background indexing.
|
|
137
173
|
* Extracted from index.mjs.
|
|
138
174
|
* ctx: { agent, state, opts, pushLine, pushLabel, render, startWizard } */
|
|
@@ -151,6 +187,10 @@ export function showStartup(ctx) {
|
|
|
151
187
|
}
|
|
152
188
|
pushLine(`Tools: ${agent.tools.map((t) => t.name).join(", ")}`, C.dim)
|
|
153
189
|
|
|
190
|
+
// R25(F-R25c):上次运行异常终止提示——bin 入口扫描 crash-reports(24h 窗)经
|
|
191
|
+
// startTUI opts.crashNotice 传入——无匹配为 undefined → 不提示(负例)
|
|
192
|
+
if (opts.crashNotice) pushLine(opts.crashNotice, C.warn)
|
|
193
|
+
|
|
154
194
|
// Recover previous session: rebuild from history (lazy — display snapshot is
|
|
155
195
|
// deprecated; it drifted out of sync with history on VS Code writes).
|
|
156
196
|
if (opts.restored?.history?.length) {
|