thincoder 0.12.54 → 0.12.59
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 +98 -0
- package/README.md +1 -1
- package/bin/thincoder.mjs +25 -3
- package/package.json +3 -7
- package/src/acp/bridge.mjs +132 -26
- package/src/advisor/messages.mjs +38 -3
- package/src/advisor/run.mjs +91 -53
- package/src/advisor.mjs +15 -7
- package/src/agent/dispatch.mjs +156 -39
- package/src/agent/helpers.mjs +46 -4
- package/src/agent/setup.mjs +102 -19
- package/src/agent/spawn-child.mjs +28 -1
- package/src/agent-tools/advisor.mjs +43 -11
- package/src/agent-tools/consult.mjs +37 -6
- package/src/agent-tools/eng.mjs +4 -1
- package/src/agent-tools/goal.mjs +11 -1
- package/src/agent-tools/read-history.mjs +160 -0
- package/src/agent-tools/settings.mjs +162 -0
- package/src/agent-tools/skill.mjs +2 -1
- package/src/agent-tools/subagent-actions.mjs +432 -0
- package/src/agent-tools/subagent-async.mjs +427 -0
- package/src/agent-tools/subagent-scheduler.mjs +319 -0
- package/src/agent-tools/subagent.mjs +565 -128
- package/src/agent-tools/task.mjs +4 -3
- package/src/agent-tools/timer.mjs +9 -4
- package/src/agent-tools/verify.mjs +161 -49
- package/src/agent-tools.mjs +1 -0
- package/src/agent.mjs +182 -81
- package/src/auto-think.mjs +14 -0
- package/src/cli/make-agent.mjs +27 -1
- package/src/cli/memory-command.mjs +28 -7
- package/src/cli/permission.mjs +8 -1
- package/src/config.mjs +125 -8
- package/src/context.mjs +115 -34
- package/src/distill.mjs +19 -1
- package/src/escape.mjs +82 -27
- package/src/log.mjs +195 -0
- package/src/mcp/transport-http.mjs +13 -1
- package/src/mcp.mjs +52 -7
- package/src/memory/code-sync.mjs +1 -1
- package/src/memory/core.mjs +204 -10
- package/src/memory/docs.mjs +197 -62
- package/src/memory.mjs +1 -1
- package/src/model-specs.mjs +38 -1
- package/src/prompts/advisor-design.md +46 -0
- package/src/prompts/advisor-round1.md +49 -2
- package/src/prompts/advisor-round2.md +47 -0
- package/src/prompts/advisor-round3.md +47 -0
- package/src/prompts/coder.md +22 -0
- package/src/prompts/consult-base.md +13 -0
- package/src/prompts/discipline.md +25 -6
- package/src/prompts/eng-coder.md +2 -2
- package/src/prompts/engineering-sub.md +23 -1
- package/src/prompts/engineering.md +157 -50
- package/src/prompts/explore.md +1 -2
- package/src/prompts/main.md +11 -5
- package/src/prompts/methodology-template.md +14 -0
- package/src/prompts/system.md +5 -2
- package/src/provider/anthropic.mjs +7 -5
- package/src/provider/core.mjs +104 -28
- package/src/provider/google.mjs +57 -24
- package/src/provider/normalize.mjs +1 -1
- package/src/provider/rate.mjs +0 -2
- package/src/provider/responses.mjs +8 -13
- package/src/provider/sse.mjs +20 -0
- package/src/session.mjs +15 -0
- package/src/tools/apply_patch.md +5 -1
- package/src/tools/bash.md +3 -3
- package/src/tools/delete.md +1 -0
- package/src/tools/edit-batch.mjs +92 -0
- package/src/tools/edit-diff.mjs +265 -0
- package/src/tools/edit.md +11 -6
- package/src/tools/execute.md +8 -8
- package/src/tools/execute.mjs +31 -35
- package/src/tools/file.mjs +26 -114
- package/src/tools/file_ops.md +3 -2
- package/src/tools/get_current_time.md +3 -1
- package/src/tools/git.md +1 -1
- package/src/tools/git.mjs +8 -16
- package/src/tools/hashline_edit.md +2 -0
- package/src/tools/index.mjs +3 -2
- package/src/tools/insert_after.md +2 -1
- package/src/tools/lint.md +3 -1
- package/src/tools/linter.mjs +9 -37
- package/src/tools/lsp.md +4 -1
- package/src/tools/patch.mjs +84 -13
- package/src/tools/pdf-parse-text.mjs +497 -0
- package/src/tools/pdf-parse-xref.mjs +499 -0
- package/src/tools/pdf.mjs +155 -0
- package/src/tools/question.md +2 -1
- package/src/tools/read.md +1 -0
- package/src/tools/read_pdf.md +21 -0
- package/src/tools/repomap.mjs +1 -1
- package/src/tools/shared.mjs +11 -32
- package/src/tools/system.mjs +6 -21
- package/src/tools/tree.md +2 -1
- 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 +387 -24
- package/src/tui/clipboard.mjs +17 -6
- package/src/tui/cmd-config.mjs +29 -9
- package/src/tui/cmd-eng.mjs +1 -0
- package/src/tui/cmd-extract.mjs +1 -1
- package/src/tui/cmd-mcp-form.mjs +197 -0
- package/src/tui/cmd-mcp.mjs +264 -114
- package/src/tui/cmd-think.mjs +1 -1
- package/src/tui/index.mjs +49 -95
- package/src/tui/interaction.mjs +41 -3
- package/src/tui/key-handler.mjs +105 -143
- package/src/tui/key-modes.mjs +215 -0
- package/src/tui/layout.mjs +22 -1
- package/src/tui/mouse.mjs +41 -1
- package/src/tui/pickers.mjs +73 -7
- package/src/tui/render-conversation.mjs +13 -161
- package/src/tui/render-frame.mjs +45 -20
- package/src/tui/render-loop.mjs +4 -1
- package/src/tui/render-segments.mjs +165 -0
- package/src/tui/render.mjs +4 -4
- package/src/tui/startup.mjs +40 -2
- package/src/tui/subagent-blocks.mjs +404 -111
- package/src/tui/subagent-panel.mjs +88 -13
- package/src/tui/tool-args.mjs +10 -2
- package/src/tui/tool-events.mjs +172 -95
- package/src/tui/update-notice.mjs +72 -0
- package/src/tui/wizard.mjs +36 -6
- package/src/agent-tools/escalate.mjs +0 -179
- package/src/tools/exec-prelude.mjs +0 -84
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-modes.mjs — 按键模态层(2026-09-03 D-S4 自 key-handler.mjs 拆出):
|
|
3
|
+
* permission / question / interruptPrompt 三种独占模态分支。每个 handler 在模态激活时
|
|
4
|
+
* 消费全部按键(返回 true——含未匹配键,与拆出前无条件 return 语义一致),未激活返回 false。
|
|
5
|
+
* ctx: { state, agent, pushLine, render }(各 handler 按需取用)。
|
|
6
|
+
* 搜索模态另居 key-handler-search.mjs(既有拆分,本批不动)。
|
|
7
|
+
*/
|
|
8
|
+
import { C } from "./ansi.mjs"
|
|
9
|
+
import { readClipboardText, insertPastedText } from "./clipboard.mjs"
|
|
10
|
+
import { QUESTION_CUSTOM } from "./interaction.mjs"
|
|
11
|
+
|
|
12
|
+
/** permission 确认模态:y/n/a(a = approve + AUTO ON);batch(§16 D-B1):a/o/n(Esc = deny)。
|
|
13
|
+
* consume:valid 键或 Esc 走 resolve 分支;其余键静默吞掉(模态独占)。 */
|
|
14
|
+
export function handlePermissionMode(str, key, ctx) {
|
|
15
|
+
const { state, agent, pushLine, render } = ctx
|
|
16
|
+
if (!state.permission) return false
|
|
17
|
+
const answer = (str || "").toLowerCase()
|
|
18
|
+
const isContinue = state.permission.name === "continue"
|
|
19
|
+
const isBatch = Boolean(state.permission.batch)
|
|
20
|
+
const validKeys = isContinue ? ["y", "n"] : isBatch ? ["a", "o", "n"] : ["y", "n", "a"]
|
|
21
|
+
if (validKeys.includes(answer) || key.name === "escape") {
|
|
22
|
+
const { resolve, name } = state.permission
|
|
23
|
+
state.permission = null
|
|
24
|
+
state.permissionPreview = []
|
|
25
|
+
state.status = "Processing..."
|
|
26
|
+
if (isBatch) {
|
|
27
|
+
// Merged batch ask: resolve the verdict string; dispatch applies it
|
|
28
|
+
// (approveAll = batch-scope allowance only, NOT the persistent AUTO flag).
|
|
29
|
+
const verdict = answer === "a" ? "approveAll" : answer === "o" ? "oneByOne" : "deny"
|
|
30
|
+
const tone = verdict === "approveAll" ? C.dim : C.error
|
|
31
|
+
pushLine(` [${verdict === "approveAll" ? "approved" : verdict === "deny" ? "denied" : "one by one"}] ${name}`, tone)
|
|
32
|
+
resolve(verdict)
|
|
33
|
+
render()
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
if (answer === "a" && !isContinue) {
|
|
37
|
+
agent.autoApprove = true
|
|
38
|
+
agent._pendingReminders = agent._pendingReminders ?? []
|
|
39
|
+
agent._pendingReminders.push("[System reminder: AUTO mode is now ON. All tool calls are automatically approved. Use /auto to disable.]")
|
|
40
|
+
pushLine(` [auto] AUTO ON: tool calls no longer prompt for approval (/auto to disable)`, C.warn)
|
|
41
|
+
}
|
|
42
|
+
const approved = answer === "y" || (answer === "a" && !isContinue)
|
|
43
|
+
// leave trail: record approval/denial in conversation (continue prompt has its own output, don't duplicate)
|
|
44
|
+
if (!isContinue) {
|
|
45
|
+
pushLine(` [${approved ? "approved" : "denied"}] ${name}`, approved ? C.dim : C.error)
|
|
46
|
+
}
|
|
47
|
+
resolve(approved)
|
|
48
|
+
render()
|
|
49
|
+
}
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** question 工具回调模态:自由文本(type answer, Enter submit, Esc cancel)或选项
|
|
54
|
+
* (↑↓ select, Enter confirm, Esc cancel——QUESTION_CUSTOM 项切自由文本模式)。
|
|
55
|
+
* 自由文本态编辑键契约见 TUI-INPUT-BOX.md §7.2(←→/Home/End/Ctrl+U/Backspace/中段插入/
|
|
56
|
+
* Ctrl+V 落 cursor/\n→空格/Ctrl+J no-op/未列键吞——无 fall-through);Esc 语义 round2 #5:
|
|
57
|
+
* 有 options(Custom 进入)→ 回 options 态;无 options → 中止 question。
|
|
58
|
+
* consume:模态激活时全部按键独占(含未匹配键——拆出前 onKeypress 尾 return)。 */
|
|
59
|
+
export function handleQuestionMode(str, key, ctx) {
|
|
60
|
+
const { state, pushLine, render } = ctx
|
|
61
|
+
if (!state.question) return false
|
|
62
|
+
const q = state.question
|
|
63
|
+
if (q.options.length > 0) {
|
|
64
|
+
// options mode: ↑↓ select, Enter confirm, Esc cancel
|
|
65
|
+
if (key.name === "escape") {
|
|
66
|
+
q.resolve("")
|
|
67
|
+
state.question = null
|
|
68
|
+
state.status = "Processing..."
|
|
69
|
+
render()
|
|
70
|
+
} else if (key.name === "up") {
|
|
71
|
+
q.selected = Math.max(0, (q.selected ?? 0) - 1)
|
|
72
|
+
render()
|
|
73
|
+
} else if (key.name === "down") {
|
|
74
|
+
q.selected = Math.min(q.options.length - 1, (q.selected ?? 0) + 1)
|
|
75
|
+
render()
|
|
76
|
+
} else if (key.name === "return") {
|
|
77
|
+
const answer = q.options[q.selected ?? 0]
|
|
78
|
+
if (answer === QUESTION_CUSTOM) {
|
|
79
|
+
// Switch to free-text mode — the user wants to type their own answer.
|
|
80
|
+
// options 列表备份(_backOptions)——自由文本态 Esc 可回 options 态(round2 #5 逃生口);
|
|
81
|
+
// answer/cursor 按 §7.2 初始化(codepoint 数组 + cursor = answer.length)。
|
|
82
|
+
q._backOptions = { options: q.options, selected: q.selected }
|
|
83
|
+
q.options = []
|
|
84
|
+
q.selected = undefined
|
|
85
|
+
q.answer = []
|
|
86
|
+
q.cursor = 0
|
|
87
|
+
state.status = "Waiting for answer..."
|
|
88
|
+
render()
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
q.resolve(answer)
|
|
92
|
+
state.question = null
|
|
93
|
+
state.status = "Processing..."
|
|
94
|
+
pushLine(` → ${answer}`, C.tool)
|
|
95
|
+
render()
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// free text: codepoint-array answer + cursor editing (TUI-INPUT-BOX.md §7.2)
|
|
99
|
+
if (!Array.isArray(q.answer)) q.answer = q.answer ? [...q.answer] : []
|
|
100
|
+
q.cursor = Math.max(0, Math.min(q.cursor ?? q.answer.length, q.answer.length))
|
|
101
|
+
const len = q.answer.length
|
|
102
|
+
if (key.name === "escape") {
|
|
103
|
+
// round2 #5:有 options(Custom 进入)→ 回 options 态(误触 Custom 有逃生口——
|
|
104
|
+
// 选择列表与选中位恢复);无 options → 中止 question(原语义)。
|
|
105
|
+
if (q._backOptions) {
|
|
106
|
+
q.options = q._backOptions.options
|
|
107
|
+
q.selected = q._backOptions.selected
|
|
108
|
+
delete q._backOptions
|
|
109
|
+
delete q.answer
|
|
110
|
+
delete q.cursor
|
|
111
|
+
state.status = "Waiting for choice..."
|
|
112
|
+
render()
|
|
113
|
+
} else {
|
|
114
|
+
q.resolve("")
|
|
115
|
+
state.question = null
|
|
116
|
+
state.status = "Processing..."
|
|
117
|
+
render()
|
|
118
|
+
}
|
|
119
|
+
} else if (key.name === "return") {
|
|
120
|
+
if (q._pasting) return true // block Enter while paste is in flight
|
|
121
|
+
const answer = q.answer.join("").trim()
|
|
122
|
+
q.resolve(answer || "")
|
|
123
|
+
state.question = null
|
|
124
|
+
state.status = "Processing..."
|
|
125
|
+
pushLine(` → ${answer || "(empty)"}`, C.tool)
|
|
126
|
+
render()
|
|
127
|
+
} else if (key.name === "enter") {
|
|
128
|
+
// Ctrl+J(\n → name "enter")= no-op 吞——不插换行无 fall-through(round2 #2)
|
|
129
|
+
} else if (key.name === "left") {
|
|
130
|
+
q.cursor = Math.max(0, q.cursor - 1)
|
|
131
|
+
render()
|
|
132
|
+
} else if (key.name === "right") {
|
|
133
|
+
q.cursor = Math.min(len, q.cursor + 1)
|
|
134
|
+
render()
|
|
135
|
+
} else if (key.name === "home") {
|
|
136
|
+
q.cursor = 0
|
|
137
|
+
render()
|
|
138
|
+
} else if (key.name === "end") {
|
|
139
|
+
q.cursor = len
|
|
140
|
+
render()
|
|
141
|
+
} else if (key.ctrl && !key.alt && key.name === "u") {
|
|
142
|
+
q.answer = []
|
|
143
|
+
q.cursor = 0
|
|
144
|
+
render()
|
|
145
|
+
} else if (key.name === "backspace") {
|
|
146
|
+
if (q.cursor > 0) {
|
|
147
|
+
q.answer.splice(q.cursor - 1, 1) // codepoint 元素删除——emoji 不劈半(round2 #1)
|
|
148
|
+
q.cursor--
|
|
149
|
+
render()
|
|
150
|
+
}
|
|
151
|
+
} else if (key.ctrl && !key.alt && !key.meta && key.name === "v") {
|
|
152
|
+
// Ctrl+V paste: read clipboard text (fires when the terminal passes Ctrl+V through
|
|
153
|
+
// as a key event; bracketed-paste terminals are handled upstream in the stdin handler).
|
|
154
|
+
// 两路径同归 insertPastedText——落 cursor 位置、\n→空格(clipboard.mjs 单行守卫)。
|
|
155
|
+
if (q._pasting) return true
|
|
156
|
+
q._pasting = true
|
|
157
|
+
readClipboardText().then((text) => {
|
|
158
|
+
q._pasting = false
|
|
159
|
+
if (text) {
|
|
160
|
+
// activeQuestion 守卫:粘贴在途用户 Esc 中止/Enter 提交后,本回调不得把
|
|
161
|
+
// 剪贴板内容落进主输入框(审计 F1——insertPastedText 见 stale 即丢)。
|
|
162
|
+
insertPastedText(state, text, q)
|
|
163
|
+
render()
|
|
164
|
+
}
|
|
165
|
+
}).catch((e) => {
|
|
166
|
+
q._pasting = false
|
|
167
|
+
console.error(`[tui] clipboard paste failed: ${e.message}`)
|
|
168
|
+
})
|
|
169
|
+
} else if (str && !key.ctrl && !key.meta && key.name !== "tab" && key.name !== "enter") {
|
|
170
|
+
// 可打印字符插入光标位置(codepoint 拆字);\r\n 剥离 + \t→2 空格(单行不变式同主输入清洗口径)
|
|
171
|
+
const chars = [...str.replace(/[\r\n]+/g, "").replace(/\t/g, " ")]
|
|
172
|
+
if (chars.length) {
|
|
173
|
+
q.answer.splice(q.cursor, 0, ...chars)
|
|
174
|
+
q.cursor += chars.length
|
|
175
|
+
render()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// 未列键(↑↓/PgUp/PgDn/Delete/F1/…)一律消费 return——无 fall-through 到正常编辑
|
|
179
|
+
// (search 穿透教训——TUI-INPUT-BOX.md §3.2 BUG-2)
|
|
180
|
+
}
|
|
181
|
+
return true
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** interruptPrompt 模态(Ctrl+I 后输入注入消息):Enter 提交 → controller.abort
|
|
185
|
+
* { interrupt: true, message };Esc 取消;字符进 prompt;其余键静默吞(模态独占)。
|
|
186
|
+
* 返回 false 当模态未激活(key-handler 先检 state.interruptPrompt 入口再调)。 */
|
|
187
|
+
export function handleInterruptMode(str, key, ctx) {
|
|
188
|
+
const { state, pushLine, render } = ctx
|
|
189
|
+
if (!state.interruptPrompt) return false
|
|
190
|
+
if (key.name === "escape") {
|
|
191
|
+
state.interruptPrompt = null
|
|
192
|
+
render()
|
|
193
|
+
} else if (key.name === "return") {
|
|
194
|
+
const msg = (state.interruptPrompt.text ?? "").trim()
|
|
195
|
+
state.interruptPrompt = null
|
|
196
|
+
if (msg) {
|
|
197
|
+
// Guard: if the turn already finished while the user was typing, the controller
|
|
198
|
+
// may have been replaced or already aborted — don't abort a live turn by mistake.
|
|
199
|
+
if (state.processing && state.controller && !state.controller.signal.aborted) {
|
|
200
|
+
pushLine(` [inject] ${msg}`, C.warn)
|
|
201
|
+
state.controller.abort({ interrupt: true, message: msg })
|
|
202
|
+
} else {
|
|
203
|
+
pushLine(` [inject — turn ended, message queued] ${msg}`, C.dim)
|
|
204
|
+
}
|
|
205
|
+
render()
|
|
206
|
+
}
|
|
207
|
+
} else if (key.name === "backspace") {
|
|
208
|
+
state.interruptPrompt.text = state.interruptPrompt.text.slice(0, -1)
|
|
209
|
+
render()
|
|
210
|
+
} else if (str && !key.ctrl && !key.meta) {
|
|
211
|
+
state.interruptPrompt.text += str.replace(/[\r\n]+/g, "")
|
|
212
|
+
render()
|
|
213
|
+
}
|
|
214
|
+
return true
|
|
215
|
+
}
|
package/src/tui/layout.mjs
CHANGED
|
@@ -26,6 +26,14 @@ const MAX_INPUT_LINES = 5
|
|
|
26
26
|
const MAX_TASK_LINES = 5
|
|
27
27
|
const QWIN = 5
|
|
28
28
|
|
|
29
|
+
/** question 自由文本态渲染布局:与主输入框同实现(TUI-INPUT-BOX.md §7.2 round2 #1/#6)——
|
|
30
|
+
* 折行展开(`▸ ` 首行 + 续行 2 空格缩进)+ 光标行列;answer 单行不变式(无 \n 字符)由
|
|
31
|
+
* 输入侧硬守卫(Ctrl+J no-op / 粘贴 \n→空格),此处只复用 layoutInput 的折行/光标语义,
|
|
32
|
+
* cap/滚动由 computeLayout 以 MAX_INPUT_LINES + questionOffset 承担(同主输入 inputOffset)。 */
|
|
33
|
+
export function layoutAnswer(chars, cursor, width) {
|
|
34
|
+
return layoutInput(chars, cursor, width)
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
/**
|
|
30
38
|
* Computes layout. Returns panel coordinates + precomputed content (height-affecting parts).
|
|
31
39
|
* Pure function: does not modify state.
|
|
@@ -43,6 +51,11 @@ export function computeLayout(state, { cols, rows }) {
|
|
|
43
51
|
}
|
|
44
52
|
const inputLines = inputLayout.lines.slice(inputOffset, inputOffset + MAX_INPUT_LINES)
|
|
45
53
|
let boxLines = inputLines
|
|
54
|
+
// question 自由文本态(无 options):boxLines = layoutAnswer 行(同主输入 cap + offset 滚动——
|
|
55
|
+
// 光标随行;长答案不挤压会话面板到零行——TUI-INPUT-BOX.md §7.2 round2 #6)。questionLayout/
|
|
56
|
+
// questionOffset 供 render-frame 反显光标与硬件定位(hasOverlay 例外细化同 §7.2)。
|
|
57
|
+
let questionLayout = null
|
|
58
|
+
let questionOffset = 0
|
|
46
59
|
if (state.question) {
|
|
47
60
|
const q = state.question
|
|
48
61
|
if (q.options.length > 0) {
|
|
@@ -51,7 +64,13 @@ export function computeLayout(state, { cols, rows }) {
|
|
|
51
64
|
boxLines = q.options.slice(start, start + QWIN).map((opt, i) =>
|
|
52
65
|
(start + i === sel ? "▸ " : " ") + (opt === QUESTION_CUSTOM ? "✍ Custom answer…" : optText(opt)))
|
|
53
66
|
} else {
|
|
54
|
-
|
|
67
|
+
const answerChars = Array.isArray(q.answer) ? q.answer : q.answer ? [...q.answer] : []
|
|
68
|
+
const qCursor = Math.max(0, Math.min(q.cursor ?? answerChars.length, answerChars.length))
|
|
69
|
+
questionLayout = layoutAnswer(answerChars, qCursor, W - 4)
|
|
70
|
+
if (questionLayout.lines.length > MAX_INPUT_LINES) {
|
|
71
|
+
questionOffset = Math.min(questionLayout.cursorLine, questionLayout.lines.length - MAX_INPUT_LINES)
|
|
72
|
+
}
|
|
73
|
+
boxLines = questionLayout.lines.slice(questionOffset, questionOffset + MAX_INPUT_LINES)
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
76
|
const inputBoxH = boxLines.length + 2
|
|
@@ -174,6 +193,8 @@ export function computeLayout(state, { cols, rows }) {
|
|
|
174
193
|
// precomputed content (affects height, reused during render)
|
|
175
194
|
inputLayout,
|
|
176
195
|
inputOffset,
|
|
196
|
+
questionLayout,
|
|
197
|
+
questionOffset,
|
|
177
198
|
boxLines,
|
|
178
199
|
visibleTasks,
|
|
179
200
|
permPreviewLines,
|
package/src/tui/mouse.mjs
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
import { computeLayout, subagentLineIndex } from "./layout.mjs"
|
|
18
18
|
import { buildConvLines, convViewport } from "./render-conversation.mjs"
|
|
19
19
|
import { toggleFoldBlock, scrollFoldBlock, foldScrollOffset } from "./fold-block.mjs"
|
|
20
|
+
import { cancelAsyncSubagent } from "../agent-tools/subagent-async.mjs"
|
|
21
|
+
import { C } from "./ansi.mjs"
|
|
20
22
|
|
|
21
23
|
/** 2026-08-31 滚轮事件分派(用户需求"展开块能滚动阅读全文"):坐标命中展开块内容行 →
|
|
22
24
|
* 块内逐行滚动(scrollFoldBlock ±3);未命中 → 会话滚动(调用方继续处理)。
|
|
@@ -72,7 +74,7 @@ export function handleWheel(ctx, button, col, row) {
|
|
|
72
74
|
/** Extract left-click presses from a chunk. Returns [{ col, row }] (1-based). */
|
|
73
75
|
export function parseMouseClicks(text) {
|
|
74
76
|
const out = []
|
|
75
|
-
//
|
|
77
|
+
// 有意为之:控制字符协议/转义序列剥离正则(ANSI/⟦ev⟧/SGR/history 双线分隔)
|
|
76
78
|
for (const m of text.matchAll(/\x1b\[<0;(\d+);(\d+)M/g)) {
|
|
77
79
|
out.push({ col: Number(m[1]), row: Number(m[2]) })
|
|
78
80
|
}
|
|
@@ -125,6 +127,15 @@ export function handleMouseClick(ctx, col, row) {
|
|
|
125
127
|
// 评审 #4:保底截断后可见行 ≠ 前 h 行——命中映射与 render-frame 同一几何契约
|
|
126
128
|
// (subagentLineIndex:分隔线 + 末尾区块行优先)。
|
|
127
129
|
const lineEl = layout.subagentLines[subagentLineIndex(layout.subagentLines, P.subagent.h, r - P.subagent.y)]
|
|
130
|
+
// §19.5 D-M7/D-M7b ⏹ 停止标记(round1 #6 + 用户裁定 B 形态):列级命中——⏹ 列
|
|
131
|
+
// 点击 = cancel(定向该子代理——ctx.cancelSubagent 直连池 abort 路径,不经模型
|
|
132
|
+
// 回合),不触发折叠翻转;**仅 async 区块带 _stopSub 元数据**(sync 无 ⏹——
|
|
133
|
+
// 其右缘点击照常走折叠翻转——D-M7b ③);⏹ 区外点击照常走折叠/翻窗。
|
|
134
|
+
if (lineEl?._stopSub && col >= (lineEl._stopCol ?? Infinity)) {
|
|
135
|
+
ctx.cancelSubagent?.(lineEl._stopSub)
|
|
136
|
+
render()
|
|
137
|
+
return true
|
|
138
|
+
}
|
|
128
139
|
if (lineEl?._foldScrollUp || lineEl?._foldScrollDown) {
|
|
129
140
|
// ▲/▼ 控制行点击翻窗(60% 封顶保留、窗口随翻滚动,全文可达)
|
|
130
141
|
scrollFoldBlock(state, lineEl._foldScrollUp ?? lineEl._foldScrollDown,
|
|
@@ -164,3 +175,32 @@ export function handleMouseClick(ctx, col, row) {
|
|
|
164
175
|
|
|
165
176
|
return false
|
|
166
177
|
}
|
|
178
|
+
|
|
179
|
+
/** 鼠标装配簇(2026-09-03 D-S1a 自 index.mjs 迁入):index.mjs 只留装配调用。
|
|
180
|
+
* ctx: { agent, state, pushLine, render, popPicker };返回 { onMouseClick, mouseCtx }。
|
|
181
|
+
* cancelSubagent(⏹ 停止标记,§19.5 D-M7):UI 停止不经模型回合,直连池 abort——
|
|
182
|
+
* 与 action:"cancel" 同实现路径。block key "role#id" → 池条目 id。 */
|
|
183
|
+
export function createMouseDispatch({ agent, state, pushLine, render, popPicker }) {
|
|
184
|
+
const cancelSubagent = (key) => {
|
|
185
|
+
try {
|
|
186
|
+
const id = key.slice(key.lastIndexOf("#") + 1)
|
|
187
|
+
const r = cancelAsyncSubagent(agent, id)
|
|
188
|
+
if (r?.status === "error") {
|
|
189
|
+
// 池内无此条目但区块仍 live(!done)→ 阻塞型(sync)spawn 中——无池条目可定向
|
|
190
|
+
// 中止(§19.5 cancel 只针对 async 后台子代理);给出可操作指引而非神秘 unknown id
|
|
191
|
+
const liveBlock = state.subTasks?.[key] && !state.subTasks[key].done
|
|
192
|
+
pushLine(liveBlock
|
|
193
|
+
? `[subagent stop] ${key} is a blocking (sync) child mid-call — targeted stop is not available; use Ctrl+C to interrupt the turn`
|
|
194
|
+
: `[subagent stop] ${r.error}`, C.error)
|
|
195
|
+
} else {
|
|
196
|
+
pushLine(`[subagent ${key} stop requested]`, C.warn)
|
|
197
|
+
}
|
|
198
|
+
} catch (e) {
|
|
199
|
+
pushLine(`[subagent stop] ${e?.message ?? String(e)}`, C.error)
|
|
200
|
+
}
|
|
201
|
+
render()
|
|
202
|
+
}
|
|
203
|
+
const onMouseClick = (col, row) => handleMouseClick({ state, render, popPicker, cancelSubagent }, col, row)
|
|
204
|
+
const mouseCtx = () => ({ state, render })
|
|
205
|
+
return { onMouseClick, mouseCtx }
|
|
206
|
+
}
|
package/src/tui/pickers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sliceByWidth } from "./render.mjs"
|
|
2
|
-
import { PROVIDER_PRESETS as PRESETS } from "../config.mjs"
|
|
2
|
+
import { PROVIDER_PRESETS as PRESETS, providerSpec } from "../config.mjs"
|
|
3
3
|
import { computeLayout } from "./layout.mjs"
|
|
4
4
|
|
|
5
5
|
/** Generic list picker + model/provider management.
|
|
@@ -121,6 +121,14 @@ export function createPickers(ctx) {
|
|
|
121
121
|
return e.action === "switch" ? `switch:${e.provider}:${e.model}` : `action:${e.action}`
|
|
122
122
|
}
|
|
123
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
|
+
|
|
124
132
|
/** Get API key for a provider (config.json only — env vars are not a key source) */
|
|
125
133
|
function getApiKey(providerName, providerConfig) {
|
|
126
134
|
return providerConfig.apiKey
|
|
@@ -148,6 +156,8 @@ export function createPickers(ctx) {
|
|
|
148
156
|
await removeProviderFlow()
|
|
149
157
|
} else if (e.action === "key") {
|
|
150
158
|
await setKeyFlow()
|
|
159
|
+
} else if (e.action === "context") {
|
|
160
|
+
await setContextFlow()
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
}
|
|
@@ -188,9 +198,11 @@ export function createPickers(ctx) {
|
|
|
188
198
|
const marker = active ? "●" : ""
|
|
189
199
|
const note = active ? " ← current" : ""
|
|
190
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)})`
|
|
191
203
|
entries.push({
|
|
192
204
|
type: "item",
|
|
193
|
-
text: `${p.name.padEnd(12)} ${currentModel}${note}`,
|
|
205
|
+
text: `${p.name.padEnd(12)} ${currentModel}${ctxTag}${note}`,
|
|
194
206
|
action: "open-models",
|
|
195
207
|
provider: p.name,
|
|
196
208
|
marker,
|
|
@@ -201,6 +213,7 @@ export function createPickers(ctx) {
|
|
|
201
213
|
entries.push({ type: "item", text: "Add provider…", action: "add" })
|
|
202
214
|
if (agent.providers.length > 1) entries.push({ type: "item", text: "Remove provider…", action: "remove" })
|
|
203
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" })
|
|
204
217
|
return entries
|
|
205
218
|
}
|
|
206
219
|
|
|
@@ -294,7 +307,8 @@ export function createPickers(ctx) {
|
|
|
294
307
|
agent.provider = { ...target }
|
|
295
308
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
296
309
|
const { resolveCompactThreshold } = await import("../config.mjs")
|
|
297
|
-
|
|
310
|
+
// provider 对象(非 model 字符串)——阈值跟随 providers[].context 覆盖(PROVIDER.md §15 T-C2)
|
|
311
|
+
agent.config.agent.compactThreshold = resolveCompactThreshold(null, target).value
|
|
298
312
|
}
|
|
299
313
|
await persistRaw((raw) => {
|
|
300
314
|
// 落盘前剥离运行时注入的 proxyUri(由 loadConfig + injectProxy 在加载时重建)
|
|
@@ -328,10 +342,18 @@ export function createPickers(ctx) {
|
|
|
328
342
|
if (!baseURL) return
|
|
329
343
|
const model = await askQuestion("Enter model name:")
|
|
330
344
|
if (!model) return
|
|
331
|
-
|
|
345
|
+
// D-C1(TUI.md §10.6D):API format 改 picker 选择(openai/anthropic/google——默认 index=0
|
|
346
|
+
// openai)——固定枚举不再手输;Esc/取消 = 中止整个 Add Provider 流程(cfg 尚未落盘——
|
|
347
|
+
// 无半配置,与旧手输非法 abort 同语义)。与 preset 选择器同形态——零新机制。
|
|
348
|
+
const format = await showPicker("API format", [
|
|
349
|
+
{ type: "item", text: "openai", name: "openai" },
|
|
350
|
+
{ type: "item", text: "anthropic", name: "anthropic" },
|
|
351
|
+
{ type: "item", text: "google", name: "google" },
|
|
352
|
+
])
|
|
353
|
+
if (!format) return // Esc/取消 → 中止流程
|
|
332
354
|
const cfg = { name, baseURL, model }
|
|
333
|
-
if (format === "anthropic" || format === "google") cfg.format = format
|
|
334
|
-
else if (format
|
|
355
|
+
if (format.name === "anthropic" || format.name === "google") cfg.format = format.name
|
|
356
|
+
else if (format.name !== "openai") return // 防御:未知格式(理论不可达——picker 枚举)
|
|
335
357
|
agent.providers.push(cfg)
|
|
336
358
|
await persistRaw((raw) => { raw.providers = agent.providers })
|
|
337
359
|
const key = await askQuestion(`Enter API key for ${name} (skip if none):`)
|
|
@@ -382,6 +404,50 @@ export function createPickers(ctx) {
|
|
|
382
404
|
await persistRaw((raw) => { raw.providers = agent.providers })
|
|
383
405
|
}
|
|
384
406
|
|
|
407
|
+
/** /model provider 管理:context 窗口字段(K 单位,PROVIDER.md §15 D-C4/D-C5)——
|
|
408
|
+
* picker 选 provider + 表单输入(复用 syncProviderField 的落盘模式:改 agent.providers 目标项
|
|
409
|
+
* → persistRaw 全量写盘);空输入清空(回 spec 值);非法输入报错不落盘(D-C1 语义同 loadConfig)。 */
|
|
410
|
+
async function setContextFlow() {
|
|
411
|
+
const se = await showPicker("Set Context Window", [
|
|
412
|
+
{ type: "header", text: "Select provider" },
|
|
413
|
+
...agent.providers.map((p) => ({
|
|
414
|
+
type: "item",
|
|
415
|
+
text: `${p.name} (ctx ${fmtContextK(providerSpec(p).context)})`,
|
|
416
|
+
name: p.name,
|
|
417
|
+
})),
|
|
418
|
+
])
|
|
419
|
+
if (!se?.name) return // Esc
|
|
420
|
+
const target = agent.providers.find((p) => p.name === se.name)
|
|
421
|
+
if (!target) return
|
|
422
|
+
const current = Number.isInteger(target.context) && target.context > 0 ? target.context : null
|
|
423
|
+
const val = (await askQuestion(
|
|
424
|
+
`Context window for ${se.name} in K units (current: ${current ? `${current}K` : "spec default"} — e.g. 128 = 128K; empty to clear):`
|
|
425
|
+
))?.trim() ?? ""
|
|
426
|
+
if (val === "") {
|
|
427
|
+
delete target.context
|
|
428
|
+
} else {
|
|
429
|
+
const n = Number(val)
|
|
430
|
+
if (!Number.isInteger(n) || n <= 0) {
|
|
431
|
+
pushLine(`Invalid context: "${val}" — must be a positive integer in K units (e.g. 128 = 128K)`, C.error)
|
|
432
|
+
return
|
|
433
|
+
}
|
|
434
|
+
target.context = n
|
|
435
|
+
}
|
|
436
|
+
if (se.name === agent.activeProvider) {
|
|
437
|
+
// 运行时 provider 同步(同 setProviderKey 先例:只补 context,不重建对象以免丢 activeModel 覆盖)
|
|
438
|
+
if (target.context === undefined) delete agent.provider.context
|
|
439
|
+
else agent.provider.context = target.context
|
|
440
|
+
if (agent.config?.agent?.compactThresholdAuto) {
|
|
441
|
+
const { resolveCompactThreshold } = await import("../config.mjs")
|
|
442
|
+
agent.config.agent.compactThreshold = resolveCompactThreshold(null, agent.provider).value
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
await persistRaw((raw) => { raw.providers = agent.providers })
|
|
446
|
+
pushLine(target.context !== undefined
|
|
447
|
+
? `ctx = ${target.context}K (${target.context * 1024} tokens)`
|
|
448
|
+
: `context cleared — using model spec (${fmtContextK(providerSpec(target).context)})`, C.tool)
|
|
449
|
+
}
|
|
450
|
+
|
|
385
451
|
|
|
386
452
|
/** Slot-bound model picker: two-level provider → model selection that RETURNS
|
|
387
453
|
* { provider, model } instead of writing main-session state — used by /submodel
|
|
@@ -411,5 +477,5 @@ export function createPickers(ctx) {
|
|
|
411
477
|
}
|
|
412
478
|
}
|
|
413
479
|
|
|
414
|
-
return { showPicker, closePicker, popPicker, renderPickerLines, openModelPicker, selectModel, setProviderKey, pickModelForSlot }
|
|
480
|
+
return { showPicker, closePicker, popPicker, renderPickerLines, openModelPicker, selectModel, setProviderKey, setContextFlow, pickModelForSlot }
|
|
415
481
|
}
|