thincoder 0.12.75 → 0.12.76
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 +8 -0
- package/README.md +2 -0
- package/package.json +2 -2
- package/src/acp/read-data.mjs +19 -3
- package/src/command-interactive.mjs +2 -1
- package/src/tui/cmd-config-menus.mjs +245 -0
- package/src/tui/cmd-config.mjs +45 -252
- package/src/tui/config-helpers.mjs +54 -4
- package/src/tui/index.mjs +2 -1
- package/src/tui/model-picker.mjs +3 -3
- package/src/tui/provider-admin.mjs +3 -3
- package/src/tui/secret-prompt.mjs +12 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.12.76] — 2026-10-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **网络工具接入 DeepSeek 后端**:`websearch` / `fetch` 自动复用 `providers[]` 中 `api.deepseek.com` 渠道的 key(零新增配置)——搜索得结构化结果(date ∥ authority ∥ rerank + 长摘要),抓取得 Markdown 正文;后端失败软着陆(401/402/403/404 熔断 ∥ 408/429/5xx 退避一次 ∥ 工具永不失败);新增逃生口键 `websearch.backend` ∥ `fetch.backend`(∈ auto/local,缺省 auto;无该渠道的用户行为逐字不变)。
|
|
8
|
+
|
|
1
9
|
## [0.12.75] — 2026-10-16
|
|
2
10
|
|
|
3
11
|
> 0.12.74 → 0.12.75(连续号——发布时定号)
|
package/README.md
CHANGED
|
@@ -178,7 +178,9 @@ may hold a `${env:VAR}` reference, resolved at use time — the value is then ta
|
|
|
178
178
|
// optional: Tavily structured search (stable JSON API, no HTML scraping).
|
|
179
179
|
// Empty apiKey → silently falls back to Bing HTML extraction (zero-config).
|
|
180
180
|
"apiKey": "tvly-...", // https://tavily.com — has a free monthly tier
|
|
181
|
+
"backend": "auto", // "auto" = DeepSeek when a DeepSeek provider is configured; "local" = skip DeepSeek
|
|
181
182
|
},
|
|
183
|
+
"fetch": { "backend": "auto" }, // same values — "local" = fetch locally (skip DeepSeek)
|
|
182
184
|
}
|
|
183
185
|
```
|
|
184
186
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thincoder",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.76",
|
|
4
4
|
"description": "Thin coding agent - zero third-party dependencies, no build step, Node.js native. Sharp code, zero bloat.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node": ">=24"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@thincoder/core": "^0.10.
|
|
23
|
+
"@thincoder/core": "^0.10.9"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"bin/",
|
package/src/acp/read-data.mjs
CHANGED
|
@@ -73,7 +73,8 @@ export function createReadDataHandlers(ctx, { intervalMs = WATCH_INTERVAL_MS } =
|
|
|
73
73
|
const c = resolveCwd(params, ctx)
|
|
74
74
|
if (c.error) return c.error
|
|
75
75
|
const { ledgerCmd } = await core()
|
|
76
|
-
|
|
76
|
+
// `ledgerCount` 出参 = 对象形 `{ count, overdue, evidenceOversize }`(设计档 §7.1)——直传核对象,零包装
|
|
77
|
+
try { return ledgerCmd.ledgerCount({ cwd: c.cwd }) } catch (e) { return badParams(e?.message ?? String(e)) }
|
|
77
78
|
},
|
|
78
79
|
|
|
79
80
|
"batch/list": async (params) => {
|
|
@@ -90,6 +91,7 @@ export function createReadDataHandlers(ctx, { intervalMs = WATCH_INTERVAL_MS } =
|
|
|
90
91
|
let last = null
|
|
91
92
|
let timer = null
|
|
92
93
|
let inflight = false // 重叠防衛(先例 = 核 ledger-surface.mjs):上一拍未落定 ⇒ 跳过本拍
|
|
94
|
+
let lastError = null // 上次失败比较键(同因连续 ⇒ 不重复;`check()` resolve 当拍复位)
|
|
93
95
|
|
|
94
96
|
async function check() {
|
|
95
97
|
if (inflight) return []
|
|
@@ -112,11 +114,25 @@ export function createReadDataHandlers(ctx, { intervalMs = WATCH_INTERVAL_MS } =
|
|
|
112
114
|
} finally { inflight = false }
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
/** 拍包装(失败可见——同因不刷屏):`check()` reject ⇒ 比较键(`code` 优先、无则 `message`、再无则 `String(e)`);
|
|
118
|
+
* 与上次同键 ⇒ 不重复,异键 ⇒ 记键 + `ctx.log` 一行(`acp.mjs` 注入口 = stderr——协议面零触);resolve ⇒ 复位。 */
|
|
119
|
+
function runCheck() {
|
|
120
|
+
return check().then(
|
|
121
|
+
() => { lastError = null },
|
|
122
|
+
(e) => {
|
|
123
|
+
const key = String(e?.code ?? e?.message ?? e)
|
|
124
|
+
if (key === lastError) return
|
|
125
|
+
lastError = key
|
|
126
|
+
ctx.log?.("[acp] read-data watcher check failed:", key)
|
|
127
|
+
},
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
115
131
|
/** 启动:立即首查(立基线——静默)+ 周期轮询;unref 定时器(不阻塞进程退出)。 */
|
|
116
132
|
function start() {
|
|
117
133
|
if (timer) return
|
|
118
|
-
void
|
|
119
|
-
timer = setInterval(() => { void
|
|
134
|
+
void runCheck()
|
|
135
|
+
timer = setInterval(() => { void runCheck() }, intervalMs)
|
|
120
136
|
timer.unref?.()
|
|
121
137
|
}
|
|
122
138
|
|
|
@@ -136,7 +136,8 @@ export async function tuiCommand(ctx) {
|
|
|
136
136
|
if (agent.config?.providerState === "invalid") agent.provider = null
|
|
137
137
|
const config = loadConfig()
|
|
138
138
|
if (data) {
|
|
139
|
-
// applySession
|
|
139
|
+
// applySession 内部已按槽复合刷新显示面 compactThresholdResolved(auto 时)——判定阈值由
|
|
140
|
+
// setup.mjs 每 run 现算(§6.17),此处不再需要 switched 分支
|
|
140
141
|
// TUI-OOM-ROOTCAUSE(SESSION.md §6.14):传 slot → 绑定记录存储(身份核验 + 对账)
|
|
141
142
|
// ——人读线 = 尾窗(磁盘为准);未传 = 模式 F(全量数组)
|
|
142
143
|
applySession(agent, data, { slot })
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cmd-config-menus.mjs — the four `/config` sub-menus: proxy ∥ consult/escalate pool ∥ async
|
|
3
|
+
* pools ∥ default model. Split out of cmd-config.mjs (CONTEXT-COMPACTION.md §6.16.9 — C2):
|
|
4
|
+
* the entry file keeps the command spine (embedding key / save + reload / main menu / numeric
|
|
5
|
+
* items), this file only renders sub-menus.
|
|
6
|
+
*
|
|
7
|
+
* Factory form (design-pinned): `create<Name>Menu(ctx)` with
|
|
8
|
+
* ctx = { agent, DEFAULTS, showPicker, askQuestion, pushLine, pushLabel, saveProxy, pickModelForSlot }
|
|
9
|
+
* cmd-config.mjs builds `saveProxy` first, then constructs the four menus once and reuses them —
|
|
10
|
+
* behaviour is unchanged (same entries, same wording, same save path).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { ansi, C } from "./ansi.mjs"
|
|
14
|
+
import { probeChannelModels, dedupeModels } from "./model-catalog.mjs"
|
|
15
|
+
// 派生条目隐藏判据单源(TEAM.md §2.4——#1223:/config 渠道读面过滤)
|
|
16
|
+
import { isDerivedProviderHidden } from "./provider-admin.mjs"
|
|
17
|
+
import { probeTargetOf } from "@thincoder/core/provider-flows.mjs"
|
|
18
|
+
import { effortMenuLevels, poolCur } from "./config-helpers.mjs"
|
|
19
|
+
|
|
20
|
+
/** ── 代理子菜单:URI ∥ Web 工具开关 ∥ 连通性自测 ∥ 清除。
|
|
21
|
+
* 每轮重建 entries 显示最新状态,defaultIndex 记住上次位置。 */
|
|
22
|
+
export function createProxyMenu(ctx) {
|
|
23
|
+
const { agent, showPicker, askQuestion, pushLine, pushLabel, saveProxy } = ctx
|
|
24
|
+
return async function proxyMenu() {
|
|
25
|
+
let proxyIdx = 0
|
|
26
|
+
for (;;) {
|
|
27
|
+
const pc = agent.config?.proxy // 已归一化 { uri, web } | undefined
|
|
28
|
+
const entries = [
|
|
29
|
+
{ type: "header", text: `Proxy: ${pc?.uri || "(not set)"}` },
|
|
30
|
+
{ type: "item", text: "Set proxy URI…", action: "seturi" },
|
|
31
|
+
{ type: "item", text: `Web tools (fetch/websearch): ${!pc || pc.web ? "ON" : "OFF"}`, action: "toggleweb" },
|
|
32
|
+
{ type: "item", text: "Test connection", action: "test" },
|
|
33
|
+
{ type: "item", text: "Clear proxy", action: "clear" },
|
|
34
|
+
]
|
|
35
|
+
const c = await showPicker("Proxy", entries, { defaultIndex: proxyIdx })
|
|
36
|
+
if (!c) return // Esc 返回主菜单
|
|
37
|
+
proxyIdx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
if (c.action === "seturi") {
|
|
41
|
+
const newUri = await askQuestion("Proxy URI (e.g. http://127.0.0.1:7890):")
|
|
42
|
+
if (!newUri) continue // 空输入不改动
|
|
43
|
+
// 写即归一:两键重建 `{ uri, web }`——旧 string 形态 ∥ 盘上退役残键(如 `model`)读后即清;
|
|
44
|
+
// `web` 不显式 OFF 即 true(沿现值显示口径 `!pc || pc.web`——改 URI 不动 web 开合)。
|
|
45
|
+
await saveProxy((raw) => {
|
|
46
|
+
raw.proxy = { uri: newUri, web: !pc || pc.web !== false }
|
|
47
|
+
})
|
|
48
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
49
|
+
pushLine(`proxy.uri = ${newUri}`, C.tool)
|
|
50
|
+
} else if (c.action === "toggleweb") {
|
|
51
|
+
if (!pc) { pushLine("Proxy URI not set — use Set proxy URI… first", C.error); continue }
|
|
52
|
+
await saveProxy((raw) => { raw.proxy = { ...pc, web: !pc.web } })
|
|
53
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
54
|
+
pushLine(`proxy.web = ${!pc.web ? "on" : "off"}`, C.tool)
|
|
55
|
+
} else if (c.action === "test") {
|
|
56
|
+
const { proxyFetch, resolveWebProxy } = await import("@thincoder/core/proxy.mjs")
|
|
57
|
+
const { UA } = await import("@thincoder/core/tools/web.mjs")
|
|
58
|
+
const uri = resolveWebProxy({ agent })
|
|
59
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
60
|
+
pushLine(`Testing ${uri ? `via proxy ${uri}` : "direct (no proxy)"}...`, C.dim)
|
|
61
|
+
try {
|
|
62
|
+
const res = await Promise.race([
|
|
63
|
+
proxyFetch("https://www.gstatic.com/generate_204", { headers: { "User-Agent": UA } }, uri),
|
|
64
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout after 5s")), 5000)),
|
|
65
|
+
])
|
|
66
|
+
if (res.ok) pushLine(`✓ OK (HTTP ${res.status})`, C.tool)
|
|
67
|
+
else pushLine(`✗ HTTP ${res.status}`, C.error)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
pushLine(`✗ ${error.message}`, C.error)
|
|
70
|
+
}
|
|
71
|
+
} else if (c.action === "clear") {
|
|
72
|
+
await saveProxy((raw) => { delete raw.proxy })
|
|
73
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
74
|
+
pushLine("Proxy cleared", C.tool)
|
|
75
|
+
}
|
|
76
|
+
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Reasoning-effort 取档(会诊条目用):显示该模型真实枚举——枚举跨渠道异构(deepseek:
|
|
82
|
+
* low/high/max;qwen3.8-max: xhigh/medium/low;kimi: 7 级),固定 min/low/medium/high/max
|
|
83
|
+
* 会让用户选出运行期静默丢弃的档(2026-08-17 审计)。 */
|
|
84
|
+
async function pickEffort(ctx, current, model) {
|
|
85
|
+
const { showPicker } = ctx
|
|
86
|
+
const { specForModel } = await import("@thincoder/core/config.mjs")
|
|
87
|
+
const enumList = model ? specForModel(model).reasoningEffortEnum : null
|
|
88
|
+
if (!enumList || enumList.length === 0) return null // model has no effort — skip
|
|
89
|
+
const levels = effortMenuLevels(enumList) // "none" = clear the effort(自带去重——#16)
|
|
90
|
+
const entries = levels.map((l) => ({ type: "item", text: l === current ? `${l} ← current` : l, action: l }))
|
|
91
|
+
const c = await showPicker("Reasoning effort", entries, { defaultIndex: Math.max(0, levels.indexOf(current ?? "none")) })
|
|
92
|
+
return c ? c.action : null // Esc → null (keep unchanged)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** ── 会诊/飞刀候选池子菜单:列出 / 添加 / 编辑 effort / 删除 consultModels 条目。 */
|
|
96
|
+
export function createConsultMenu(ctx) {
|
|
97
|
+
const { agent, showPicker, pushLine, pushLabel, saveProxy, pickModelForSlot } = ctx
|
|
98
|
+
return async function consultMenu() {
|
|
99
|
+
let idx = 0
|
|
100
|
+
for (;;) {
|
|
101
|
+
const cm = agent.config?.agent?.consultModels ?? []
|
|
102
|
+
const entries = [
|
|
103
|
+
{ type: "header", text: `Consult/escalate pool: ${cm.length} model(s) (max 5)` },
|
|
104
|
+
...cm.map((m, i) => ({ type: "item", text: `${m.provider}:${m.model}${m.effort ? ` (${m.effort})` : ""}`, action: "edit", index: i })),
|
|
105
|
+
{ type: "item", text: cm.length ? "+ Add model" : "+ Add model (none yet)", action: "add" },
|
|
106
|
+
]
|
|
107
|
+
const c = await showPicker("Consult models", entries, { defaultIndex: idx })
|
|
108
|
+
if (!c) return // Esc → 返回主菜单
|
|
109
|
+
if (c.action === "add") {
|
|
110
|
+
if (cm.length >= 5) { pushLine("At most 5 consult models", C.error); continue }
|
|
111
|
+
// BOTH provider and model are pickers (discipline: options, never free-text) —
|
|
112
|
+
// pickModelForSlot reuses /model's provider list + async-fetched model list.
|
|
113
|
+
const picked = await pickModelForSlot()
|
|
114
|
+
if (!picked) continue
|
|
115
|
+
const effort = await pickEffort(ctx, null, picked.model)
|
|
116
|
+
const entry = { provider: picked.provider, model: picked.model }
|
|
117
|
+
if (effort && effort !== "none") entry.effort = effort
|
|
118
|
+
const next = [...cm, entry]
|
|
119
|
+
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
120
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
121
|
+
pushLine(`Added ${entry.provider}:${entry.model}${entry.effort ? ` (${entry.effort})` : ""}`, C.tool)
|
|
122
|
+
idx = 0
|
|
123
|
+
} else if (c.action === "edit") {
|
|
124
|
+
// Per-model sub-menu: change effort or remove.
|
|
125
|
+
const m = cm[c.index]
|
|
126
|
+
const tag = `${m.provider}:${m.model}`
|
|
127
|
+
const subEntries = [
|
|
128
|
+
{ type: "header", text: `${tag} — effort: ${m.effort ?? "(none)"}` },
|
|
129
|
+
{ type: "item", text: `Change effort (current: ${m.effort ?? "none"})`, action: "effort" },
|
|
130
|
+
{ type: "item", text: "Remove", action: "remove" },
|
|
131
|
+
]
|
|
132
|
+
const s = await showPicker(tag, subEntries, {})
|
|
133
|
+
if (!s) continue
|
|
134
|
+
if (s.action === "remove") {
|
|
135
|
+
const next = cm.filter((_, i) => i !== c.index)
|
|
136
|
+
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
137
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
138
|
+
pushLine(`Removed ${tag}`, C.tool)
|
|
139
|
+
} else if (s.action === "effort") {
|
|
140
|
+
const effort = await pickEffort(ctx, m.effort, m.model)
|
|
141
|
+
if (effort === null) { continue } // Esc 保持
|
|
142
|
+
const next = cm.map((x, i) => {
|
|
143
|
+
if (i !== c.index) return x
|
|
144
|
+
if (effort === "none") { const { effort, ...rest } = x; return rest }
|
|
145
|
+
return { ...x, effort }
|
|
146
|
+
})
|
|
147
|
+
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
148
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
149
|
+
const after = next[c.index]
|
|
150
|
+
pushLine(`${tag} effort = ${after?.effort ?? "none"}`, C.tool)
|
|
151
|
+
}
|
|
152
|
+
idx = 0
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** ── 并发池子菜单(agent.poolLimits——读/改三域;保存经 saveProxy
|
|
159
|
+
* 落盘 + reloadConfig 热应用——下个 spawn 生效)── */
|
|
160
|
+
export function createPoolMenu(ctx) {
|
|
161
|
+
const { agent, DEFAULTS, showPicker, askQuestion, pushLine, pushLabel, saveProxy } = ctx
|
|
162
|
+
return async function poolMenu() {
|
|
163
|
+
let poolIdx = 0
|
|
164
|
+
for (;;) {
|
|
165
|
+
const pl = agent.config?.agent?.poolLimits ?? {}
|
|
166
|
+
// 显示回退与默认同源(DEFAULTS.agent.poolLimits——配置 DEFAULTS 与运行时回退常量
|
|
167
|
+
// ASYNC_POOL_LIMITS/ADVISOR_POOL_LIMIT 的耦合由 T-24a4 锚定断言锁住——防默认值单侧漂移)
|
|
168
|
+
const cur = poolCur(pl, DEFAULTS)
|
|
169
|
+
const entries = [
|
|
170
|
+
{ type: "header", text: `Async pools: eng-coder ${cur("engCoder")} / other ${cur("other")} / advisor ${cur("advisor")}(默认 4/4/4——分域互不阻塞——subagent 超限排队/advisor 超限即拒)` },
|
|
171
|
+
{ type: "item", text: `eng-coder 池上限 = ${cur("engCoder")}`, action: "engCoder" },
|
|
172
|
+
{ type: "item", text: `其他角色池上限 = ${cur("other")}`, action: "other" },
|
|
173
|
+
{ type: "item", text: `advisor 评审池上限 = ${cur("advisor")}`, action: "advisor" },
|
|
174
|
+
]
|
|
175
|
+
const c = await showPicker("并发池(agent.poolLimits)", entries, { defaultIndex: poolIdx })
|
|
176
|
+
if (!c) return // Esc 返回主菜单
|
|
177
|
+
poolIdx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
178
|
+
const val = await askQuestion(`${c.action} pool limit (current: ${cur(c.action)} — positive integer ≥1):`)
|
|
179
|
+
if (!val) continue // 空输入不改动
|
|
180
|
+
const num = Number(val)
|
|
181
|
+
if (!Number.isInteger(num) || num < 1) { pushLine("Pool limit must be a positive integer (≥1)", C.error); continue }
|
|
182
|
+
// 写盘全对象(三键——未触碰的键带当前值重写——全非法/空输入不改动)
|
|
183
|
+
const next = { engCoder: cur("engCoder"), other: cur("other"), advisor: cur("advisor"), [c.action]: num }
|
|
184
|
+
try {
|
|
185
|
+
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.poolLimits = { engCoder: next.engCoder, other: next.other, advisor: next.advisor } })
|
|
186
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
187
|
+
pushLine(`agent.poolLimits = { engCoder: ${next.engCoder}, other: ${next.other}, advisor: ${next.advisor} }(下个 spawn 生效——分域互不阻塞)`, C.tool)
|
|
188
|
+
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** ── 默认模型子菜单(F-5:config.defaultModel 专用入口——L1 provider → L2 **运行期拉取**候选 →
|
|
194
|
+
* 写 config.defaultModel——saveProxy/writeConfigAtomic 通道——不落会话槽;不加手输行——O1 已裁)── */
|
|
195
|
+
export function createDefaultModelMenu(ctx) {
|
|
196
|
+
const { agent, showPicker, pushLine, pushLabel, saveProxy } = ctx
|
|
197
|
+
return async function defaultModelMenu() {
|
|
198
|
+
let idx = 0
|
|
199
|
+
// M9 配置阶段准入:进本子菜单探一次各渠道 `/models`(复用 M1 + 会话缓存)。
|
|
200
|
+
// 探通 → 渠道可用 + 候选直接可用;探不通 → 不缓存不阻断(标「不可用」且不入可选来源)。
|
|
201
|
+
// #1223(TEAM.md §2.4 六消费面):派生无 key 条目隐藏——探针 ∥ 条目录入两面同过滤。
|
|
202
|
+
const probes = new Map()
|
|
203
|
+
pushLine("Fetching channel model lists (GET /models)…", C.dim)
|
|
204
|
+
await Promise.all(agent.providers.filter((p) => !isDerivedProviderHidden(p)).map(async (p) => {
|
|
205
|
+
const r = await probeChannelModels(probeTargetOf(p)) // 探针目标构造收敛核判据(③′——逐渠旗 ∧ `uri` 在案;执行体零改)
|
|
206
|
+
probes.set(p.name, r)
|
|
207
|
+
if (r.ok) delete p._unavailable
|
|
208
|
+
else p._unavailable = true
|
|
209
|
+
}))
|
|
210
|
+
for (;;) {
|
|
211
|
+
const dm = agent.config?.defaultModel ?? null
|
|
212
|
+
const entries = [
|
|
213
|
+
{ type: "header", text: `config.defaultModel = ${dm ?? "(not set — 新会话起点未配置)"}` },
|
|
214
|
+
...agent.providers.filter((p) => !isDerivedProviderHidden(p)).map((p) => {
|
|
215
|
+
const r = probes.get(p.name)
|
|
216
|
+
if (!r?.ok) return { type: "item", text: `${p.name.padEnd(10)} 不可用`, action: "provider", provider: p.name, unavailable: true }
|
|
217
|
+
const n = r.list.length
|
|
218
|
+
// M3③:渠道行显示回退 = `baseURL`(渠道条目不携模型——2026-10-09 清除批)+ 探得候选数
|
|
219
|
+
return { type: "item", text: `${p.name.padEnd(10)} ${p.baseURL} (${n} model${n === 1 ? "" : "s"})`, action: "provider", provider: p.name }
|
|
220
|
+
}),
|
|
221
|
+
]
|
|
222
|
+
const c = await showPicker("Default Model (新会话起点)", entries, { defaultIndex: idx })
|
|
223
|
+
if (!c) return // Esc → 返回主菜单
|
|
224
|
+
idx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
225
|
+
if (c.action !== "provider") continue
|
|
226
|
+
const r = probes.get(c.provider)
|
|
227
|
+
if (!r?.ok) {
|
|
228
|
+
// 准入判据:探不通的渠道不作为默认模型的可选来源——明示原因(M8 长句),不阻断菜单
|
|
229
|
+
pushLine(r?.message ?? `${c.provider} 不可用`, C.error)
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
if (r.list.length === 0) { pushLine(`${c.provider}: /models 未返回任何模型`, C.error); continue }
|
|
233
|
+
const me = await showPicker(`${c.provider} models`, [
|
|
234
|
+
{ type: "header", text: "选为 config.defaultModel(新会话起点——当前会话槽不受影响)" },
|
|
235
|
+
...dedupeModels(r.list).map((m) => ({ type: "item", text: m, action: "model", model: m })),
|
|
236
|
+
])
|
|
237
|
+
if (!me) continue // Esc → 回默认模型菜单
|
|
238
|
+
try {
|
|
239
|
+
await saveProxy((raw) => { raw.defaultModel = `${c.provider}:${me.model}` })
|
|
240
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
241
|
+
pushLine(`config.defaultModel = ${c.provider}:${me.model}(新会话起点;会话模型不受影响)`, C.tool)
|
|
242
|
+
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
package/src/tui/cmd-config.mjs
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
1
|
import { ansi, C } from "./ansi.mjs"
|
|
2
|
-
import {
|
|
3
|
-
//
|
|
4
|
-
import {
|
|
5
|
-
import { probeTargetOf } from "@thincoder/core/provider-flows.mjs"
|
|
6
|
-
/** Merge an embedding-key save into the raw config, backfilling baseURL/model from defaults.
|
|
7
|
-
* Keeps existing custom values (Ollama/local embedding); defaults are the single source
|
|
8
|
-
* (TUI.md §9.3D — NF1). Exported for unit tests. */
|
|
9
|
-
export function embeddingPatch(raw, embKey, defaults) {
|
|
10
|
-
const prev = raw?.embedding ?? {}
|
|
11
|
-
return {
|
|
12
|
-
...prev,
|
|
13
|
-
apiKey: embKey,
|
|
14
|
-
baseURL: prev.baseURL ?? defaults.baseURL,
|
|
15
|
-
model: prev.model ?? defaults.model,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** 并发池三键当前值读取(POOL-CONFIG-UNIFIED F-3——2026-09-09):配置值合法(≥1 整数)
|
|
20
|
-
* 读配置——非法/缺省回退 DEFAULTS(agent.poolLimits 三键——/config 并发池子菜单/
|
|
21
|
-
* 主菜单/view 三面共用同一读取——config-pool.test.mjs 单元测试)。 */
|
|
22
|
-
export function poolCur(pl, defaults) {
|
|
23
|
-
return (k) => (Number.isInteger(pl?.[k]) && pl[k] >= 1 ? pl[k] : defaults.agent.poolLimits[k])
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Effort 菜单档位构造(#16 双 `none` 去重——枚举自带 `none` 的族如 qwen3.8-flash 时原来出两行):
|
|
27
|
-
* `none` 恒为首项且唯一,其余档序保持(`filter` 保序)。语义面零改——`none` = 清档,
|
|
28
|
-
* 消费点(`consultMenu` 两支)只认 `=== "none"`;空枚举在 `pickEffort` 处已早退 null、不经本函数。
|
|
29
|
-
* Exported for unit tests (`cmd-config-effort.test.mjs`). */
|
|
30
|
-
export function effortMenuLevels(enumList) {
|
|
31
|
-
return ["none", ...(enumList ?? []).filter((l) => l !== "none")]
|
|
32
|
-
}
|
|
2
|
+
import { embeddingPatch, poolCur, compactThresholdSuffix, compactThresholdHint } from "./config-helpers.mjs"
|
|
3
|
+
// 四子菜单(代理 ∥ 会诊池 ∥ 并发池 ∥ 默认模型)已迁 `cmd-config-menus.mjs`(§6.16.9 —— C2)
|
|
4
|
+
import { createProxyMenu, createConsultMenu, createPoolMenu, createDefaultModelMenu } from "./cmd-config-menus.mjs"
|
|
33
5
|
|
|
34
6
|
/** /config command: view and set agent/embedding/proxy config. */
|
|
35
7
|
export async function handleConfigCommand(ctx, args = []) {
|
|
@@ -94,9 +66,11 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
94
66
|
}
|
|
95
67
|
// 运行时重建后同步注入结果(cfg.provider 系 loadConfig 内建——injectProxy 后建)
|
|
96
68
|
agent.provider.proxyUri = cfg.providersList.find((p) => p.name === agent.activeProvider)?.proxyUri
|
|
69
|
+
// §6.17:auto 派生值永不回写 agent.compactThreshold——只刷新显示面 compactThresholdResolved
|
|
70
|
+
// (每 run 的判定阈值由 setup.mjs 现算,本处只管 /config 显示面与显式键隔离)
|
|
97
71
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
98
72
|
const { resolveCompactThreshold } = await import("@thincoder/core/config.mjs")
|
|
99
|
-
agent.config.agent.
|
|
73
|
+
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
|
|
100
74
|
}
|
|
101
75
|
}
|
|
102
76
|
|
|
@@ -113,62 +87,13 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
113
87
|
if (failure) throw failure
|
|
114
88
|
}
|
|
115
89
|
|
|
116
|
-
// ──
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
{ type: "item", text: "Set proxy URI…", action: "seturi" },
|
|
124
|
-
{ type: "item", text: `Web tools (fetch/websearch): ${!pc || pc.web ? "ON" : "OFF"}`, action: "toggleweb" },
|
|
125
|
-
{ type: "item", text: "Test connection", action: "test" },
|
|
126
|
-
{ type: "item", text: "Clear proxy", action: "clear" },
|
|
127
|
-
]
|
|
128
|
-
const c = await showPicker("Proxy", entries, { defaultIndex: proxyIdx })
|
|
129
|
-
if (!c) return // Esc 返回主菜单
|
|
130
|
-
proxyIdx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
if (c.action === "seturi") {
|
|
134
|
-
const newUri = await askQuestion("Proxy URI (e.g. http://127.0.0.1:7890):")
|
|
135
|
-
if (!newUri) continue // 空输入不改动
|
|
136
|
-
// 写即归一:两键重建 `{ uri, web }`——旧 string 形态 ∥ 盘上退役残键(如 `model`)读后即清;
|
|
137
|
-
// `web` 不显式 OFF 即 true(沿现值显示口径 `!pc || pc.web`——改 URI 不动 web 开合)。
|
|
138
|
-
await saveProxy((raw) => {
|
|
139
|
-
raw.proxy = { uri: newUri, web: !pc || pc.web !== false }
|
|
140
|
-
})
|
|
141
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
142
|
-
pushLine(`proxy.uri = ${newUri}`, C.tool)
|
|
143
|
-
} else if (c.action === "toggleweb") {
|
|
144
|
-
if (!pc) { pushLine("Proxy URI not set — use Set proxy URI… first", C.error); continue }
|
|
145
|
-
await saveProxy((raw) => { raw.proxy = { ...pc, web: !pc.web } })
|
|
146
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
147
|
-
pushLine(`proxy.web = ${!pc.web ? "on" : "off"}`, C.tool)
|
|
148
|
-
} else if (c.action === "test") {
|
|
149
|
-
const { proxyFetch, resolveWebProxy } = await import("@thincoder/core/proxy.mjs")
|
|
150
|
-
const { UA } = await import("@thincoder/core/tools/web.mjs")
|
|
151
|
-
const uri = resolveWebProxy({ agent })
|
|
152
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
153
|
-
pushLine(`Testing ${uri ? `via proxy ${uri}` : "direct (no proxy)"}...`, C.dim)
|
|
154
|
-
try {
|
|
155
|
-
const res = await Promise.race([
|
|
156
|
-
proxyFetch("https://www.gstatic.com/generate_204", { headers: { "User-Agent": UA } }, uri),
|
|
157
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout after 5s")), 5000)),
|
|
158
|
-
])
|
|
159
|
-
if (res.ok) pushLine(`✓ OK (HTTP ${res.status})`, C.tool)
|
|
160
|
-
else pushLine(`✗ HTTP ${res.status}`, C.error)
|
|
161
|
-
} catch (error) {
|
|
162
|
-
pushLine(`✗ ${error.message}`, C.error)
|
|
163
|
-
}
|
|
164
|
-
} else if (c.action === "clear") {
|
|
165
|
-
await saveProxy((raw) => { delete raw.proxy })
|
|
166
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
167
|
-
pushLine("Proxy cleared", C.tool)
|
|
168
|
-
}
|
|
169
|
-
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
170
|
-
}
|
|
171
|
-
}
|
|
90
|
+
// ── 四子菜单(代理 ∥ 会诊池 ∥ 并发池 ∥ 默认模型)已迁 `cmd-config-menus.mjs`(§6.16.9 —— C2):
|
|
91
|
+
// 工厂形接收 ctx 袋——saveProxy 在本处已建好,四个菜单各建一次、主循环复用(行为零变)──
|
|
92
|
+
const menuCtx = { agent, DEFAULTS, showPicker, askQuestion, pushLine, pushLabel, saveProxy, pickModelForSlot }
|
|
93
|
+
const proxyMenu = createProxyMenu(menuCtx)
|
|
94
|
+
const consultMenu = createConsultMenu(menuCtx)
|
|
95
|
+
const poolMenu = createPoolMenu(menuCtx)
|
|
96
|
+
const defaultModelMenu = createDefaultModelMenu(menuCtx)
|
|
172
97
|
|
|
173
98
|
// Direct args: /config embedkey
|
|
174
99
|
const sub = args[0]?.toLowerCase()
|
|
@@ -178,164 +103,6 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
178
103
|
}
|
|
179
104
|
if (sub) { pushLine("Usage: /config [embedkey]", C.error); return }
|
|
180
105
|
|
|
181
|
-
/** 会诊/飞刀候选池子菜单:列出 / 添加 / 编辑 effort / 删除 consultModels 条目。 */
|
|
182
|
-
async function pickEffort(current, model) {
|
|
183
|
-
const { specForModel } = await import("@thincoder/core/config.mjs")
|
|
184
|
-
const enumList = model ? specForModel(model).reasoningEffortEnum : null
|
|
185
|
-
// The model's reasoning-effort enum is HETEROGENEOUS across providers (deepseek:
|
|
186
|
-
// low/high/max; qwen3.8-max: xhigh/medium/low; kimi: 7 levels). A fixed
|
|
187
|
-
// min/low/medium/high/max list made the user pick values that the runtime then
|
|
188
|
-
// silently dropped as out-of-enum (2026-08-17 audit). Show the model's real enum.
|
|
189
|
-
if (!enumList || enumList.length === 0) return null // model has no effort — skip
|
|
190
|
-
const levels = effortMenuLevels(enumList) // "none" = clear the effort(自带去重——#16)
|
|
191
|
-
const entries = levels.map((l) => ({ type: "item", text: l === current ? `${l} ← current` : l, action: l }))
|
|
192
|
-
const c = await showPicker("Reasoning effort", entries, { defaultIndex: Math.max(0, levels.indexOf(current ?? "none")) })
|
|
193
|
-
return c ? c.action : null // Esc → null (keep unchanged)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function consultMenu() {
|
|
197
|
-
let idx = 0
|
|
198
|
-
for (;;) {
|
|
199
|
-
const cm = agent.config?.agent?.consultModels ?? []
|
|
200
|
-
const entries = [
|
|
201
|
-
{ type: "header", text: `Consult/escalate pool: ${cm.length} model(s) (max 5)` },
|
|
202
|
-
...cm.map((m, i) => ({ type: "item", text: `${m.provider}:${m.model}${m.effort ? ` (${m.effort})` : ""}`, action: "edit", index: i })),
|
|
203
|
-
{ type: "item", text: cm.length ? "+ Add model" : "+ Add model (none yet)", action: "add" },
|
|
204
|
-
]
|
|
205
|
-
const c = await showPicker("Consult models", entries, { defaultIndex: idx })
|
|
206
|
-
if (!c) return // Esc → 返回主菜单
|
|
207
|
-
if (c.action === "add") {
|
|
208
|
-
if (cm.length >= 5) { pushLine("At most 5 consult models", C.error); continue }
|
|
209
|
-
// BOTH provider and model are pickers (discipline: options, never free-text) —
|
|
210
|
-
// pickModelForSlot reuses /model's provider list + async-fetched model list.
|
|
211
|
-
const picked = await pickModelForSlot()
|
|
212
|
-
if (!picked) continue
|
|
213
|
-
const effort = await pickEffort(null, picked.model)
|
|
214
|
-
const entry = { provider: picked.provider, model: picked.model }
|
|
215
|
-
if (effort && effort !== "none") entry.effort = effort
|
|
216
|
-
const next = [...cm, entry]
|
|
217
|
-
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
218
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
219
|
-
pushLine(`Added ${entry.provider}:${entry.model}${entry.effort ? ` (${entry.effort})` : ""}`, C.tool)
|
|
220
|
-
idx = 0
|
|
221
|
-
} else if (c.action === "edit") {
|
|
222
|
-
// Per-model sub-menu: change effort or remove.
|
|
223
|
-
const m = cm[c.index]
|
|
224
|
-
const tag = `${m.provider}:${m.model}`
|
|
225
|
-
const subEntries = [
|
|
226
|
-
{ type: "header", text: `${tag} — effort: ${m.effort ?? "(none)"}` },
|
|
227
|
-
{ type: "item", text: `Change effort (current: ${m.effort ?? "none"})`, action: "effort" },
|
|
228
|
-
{ type: "item", text: "Remove", action: "remove" },
|
|
229
|
-
]
|
|
230
|
-
const s = await showPicker(tag, subEntries, {})
|
|
231
|
-
if (!s) continue
|
|
232
|
-
if (s.action === "remove") {
|
|
233
|
-
const next = cm.filter((_, i) => i !== c.index)
|
|
234
|
-
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
235
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
236
|
-
pushLine(`Removed ${tag}`, C.tool)
|
|
237
|
-
} else if (s.action === "effort") {
|
|
238
|
-
const effort = await pickEffort(m.effort, m.model)
|
|
239
|
-
if (effort === null) { continue } // Esc 保持
|
|
240
|
-
const next = cm.map((x, i) => {
|
|
241
|
-
if (i !== c.index) return x
|
|
242
|
-
if (effort === "none") { const { effort, ...rest } = x; return rest }
|
|
243
|
-
return { ...x, effort }
|
|
244
|
-
})
|
|
245
|
-
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.consultModels = next })
|
|
246
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
247
|
-
const after = next[c.index]
|
|
248
|
-
pushLine(`${tag} effort = ${after?.effort ?? "none"}`, C.tool)
|
|
249
|
-
}
|
|
250
|
-
idx = 0
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// ── 并发池子菜单(agent.poolLimits——读/改三域;保存经 saveProxy
|
|
256
|
-
// 落盘 + reloadConfig 热应用——下个 spawn 生效)──
|
|
257
|
-
async function poolMenu() {
|
|
258
|
-
let poolIdx = 0
|
|
259
|
-
for (;;) {
|
|
260
|
-
const pl = agent.config?.agent?.poolLimits ?? {}
|
|
261
|
-
// 显示回退与默认同源(DEFAULTS.agent.poolLimits——配置 DEFAULTS 与运行时回退常量
|
|
262
|
-
// ASYNC_POOL_LIMITS/ADVISOR_POOL_LIMIT 的耦合由 T-24a4 锚定断言(config-pool.test.mjs)
|
|
263
|
-
// 锁住——防默认值单侧漂移)
|
|
264
|
-
const cur = poolCur(pl, DEFAULTS)
|
|
265
|
-
const entries = [
|
|
266
|
-
{ type: "header", text: `Async pools: eng-coder ${cur("engCoder")} / other ${cur("other")} / advisor ${cur("advisor")}(默认 4/4/4——分域互不阻塞——subagent 超限排队/advisor 超限即拒)` },
|
|
267
|
-
{ type: "item", text: `eng-coder 池上限 = ${cur("engCoder")}`, action: "engCoder" },
|
|
268
|
-
{ type: "item", text: `其他角色池上限 = ${cur("other")}`, action: "other" },
|
|
269
|
-
{ type: "item", text: `advisor 评审池上限 = ${cur("advisor")}`, action: "advisor" },
|
|
270
|
-
]
|
|
271
|
-
const c = await showPicker("并发池(agent.poolLimits)", entries, { defaultIndex: poolIdx })
|
|
272
|
-
if (!c) return // Esc 返回主菜单
|
|
273
|
-
poolIdx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
274
|
-
const val = await askQuestion(`${c.action} pool limit (current: ${cur(c.action)} — positive integer ≥1):`)
|
|
275
|
-
if (!val) continue // 空输入不改动
|
|
276
|
-
const num = Number(val)
|
|
277
|
-
if (!Number.isInteger(num) || num < 1) { pushLine("Pool limit must be a positive integer (≥1)", C.error); continue }
|
|
278
|
-
// 写盘全对象(三键——未触碰的键带当前值重写——全非法/空输入不改动)
|
|
279
|
-
const next = { engCoder: cur("engCoder"), other: cur("other"), advisor: cur("advisor"), [c.action]: num }
|
|
280
|
-
try {
|
|
281
|
-
await saveProxy((raw) => { raw.agent ??= {}; raw.agent.poolLimits = { engCoder: next.engCoder, other: next.other, advisor: next.advisor } })
|
|
282
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
283
|
-
pushLine(`agent.poolLimits = { engCoder: ${next.engCoder}, other: ${next.other}, advisor: ${next.advisor} }(下个 spawn 生效——分域互不阻塞)`, C.tool)
|
|
284
|
-
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// ── 默认模型子菜单(F-5:config.defaultModel 专用入口——L1 provider → L2 **运行期拉取**候选 →
|
|
289
|
-
// 写 config.defaultModel——saveProxy/writeConfigAtomic 通道——不落会话槽;不加手输行——O1 已裁)──
|
|
290
|
-
async function defaultModelMenu() {
|
|
291
|
-
let idx = 0
|
|
292
|
-
// M9 配置阶段准入:进本子菜单探一次各渠道 `/models`(复用 M1 + 会话缓存)。
|
|
293
|
-
// 探通 → 渠道可用 + 候选直接可用;探不通 → 不缓存不阻断(标「不可用」且不入可选来源)。
|
|
294
|
-
// #1223(TEAM.md §2.4 六消费面):派生无 key 条目隐藏——探针 ∥ 条目录入两面同过滤。
|
|
295
|
-
const probes = new Map()
|
|
296
|
-
pushLine("Fetching channel model lists (GET /models)…", C.dim)
|
|
297
|
-
await Promise.all(agent.providers.filter((p) => !isDerivedProviderHidden(p)).map(async (p) => {
|
|
298
|
-
const r = await probeChannelModels(probeTargetOf(p)) // 探针目标构造收敛核判据(③′——逐渠旗 ∧ `uri` 在案;执行体零改)
|
|
299
|
-
probes.set(p.name, r)
|
|
300
|
-
if (r.ok) delete p._unavailable
|
|
301
|
-
else p._unavailable = true
|
|
302
|
-
}))
|
|
303
|
-
for (;;) {
|
|
304
|
-
const dm = agent.config?.defaultModel ?? null
|
|
305
|
-
const entries = [
|
|
306
|
-
{ type: "header", text: `config.defaultModel = ${dm ?? "(not set — 新会话起点未配置)"}` },
|
|
307
|
-
...agent.providers.filter((p) => !isDerivedProviderHidden(p)).map((p) => {
|
|
308
|
-
const r = probes.get(p.name)
|
|
309
|
-
if (!r?.ok) return { type: "item", text: `${p.name.padEnd(10)} 不可用`, action: "provider", provider: p.name, unavailable: true }
|
|
310
|
-
const n = r.list.length
|
|
311
|
-
// M3③:渠道行显示回退 = `baseURL`(渠道条目不携模型——2026-10-09 清除批)+ 探得候选数
|
|
312
|
-
return { type: "item", text: `${p.name.padEnd(10)} ${p.baseURL} (${n} model${n === 1 ? "" : "s"})`, action: "provider", provider: p.name }
|
|
313
|
-
}),
|
|
314
|
-
]
|
|
315
|
-
const c = await showPicker("Default Model (新会话起点)", entries, { defaultIndex: idx })
|
|
316
|
-
if (!c) return // Esc → 返回主菜单
|
|
317
|
-
idx = Math.max(0, entries.filter((e) => e.type === "item").indexOf(c))
|
|
318
|
-
if (c.action !== "provider") continue
|
|
319
|
-
const r = probes.get(c.provider)
|
|
320
|
-
if (!r?.ok) {
|
|
321
|
-
// 准入判据:探不通的渠道不作为默认模型的可选来源——明示原因(M8 长句),不阻断菜单
|
|
322
|
-
pushLine(r?.message ?? `${c.provider} 不可用`, C.error)
|
|
323
|
-
continue
|
|
324
|
-
}
|
|
325
|
-
if (r.list.length === 0) { pushLine(`${c.provider}: /models 未返回任何模型`, C.error); continue }
|
|
326
|
-
const me = await showPicker(`${c.provider} models`, [
|
|
327
|
-
{ type: "header", text: "选为 config.defaultModel(新会话起点——当前会话槽不受影响)" },
|
|
328
|
-
...dedupeModels(r.list).map((m) => ({ type: "item", text: m, action: "model", model: m })),
|
|
329
|
-
])
|
|
330
|
-
if (!me) continue // Esc → 回默认模型菜单
|
|
331
|
-
try {
|
|
332
|
-
await saveProxy((raw) => { raw.defaultModel = `${c.provider}:${me.model}` })
|
|
333
|
-
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
334
|
-
pushLine(`config.defaultModel = ${c.provider}:${me.model}(新会话起点;会话模型不受影响)`, C.tool)
|
|
335
|
-
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
106
|
// ── Main config loop ──
|
|
340
107
|
let running = true
|
|
341
108
|
let mainIdx = 0 // 记住上次选中位置,改完一项回主菜单时恢复
|
|
@@ -348,12 +115,18 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
348
115
|
const consultCount = (ac.consultModels ?? []).length
|
|
349
116
|
const pl = ac.poolLimits ?? {}
|
|
350
117
|
const cur = poolCur(pl, DEFAULTS)
|
|
118
|
+
// §6.17 显示面(一处助手,四处共用):数值 = compactThresholdResolved(缺场 ⇒ `(unavailable)`——
|
|
119
|
+
// 链尾不产数、不回落任何默认数——回落 100000 会造一条 10% 假线;该支不可达,纯护栏);
|
|
120
|
+
// auto 旗 ⇒ 缀 ` (auto)`。写入数值 = 固定为显式阈值(保存回显明示)。
|
|
121
|
+
const ctResolved = ac.compactThresholdResolved
|
|
122
|
+
const ctDisplay = ctResolved === undefined ? "(unavailable)" : String(ctResolved)
|
|
123
|
+
const ctSuffix = compactThresholdSuffix(ac.compactThresholdAuto)
|
|
351
124
|
const mainEntries = [
|
|
352
|
-
{ type: "header", text: `proxy=${proxySummary()} | maxTurns=${ac.maxTurns ?? 200} | compactThreshold=${
|
|
125
|
+
{ type: "header", text: `proxy=${proxySummary()} | maxTurns=${ac.maxTurns ?? 200} | compactThreshold=${ctDisplay}${ctSuffix} | verifyGuard=${ac.verifyGuard === true ? "on" : "off"} | consult=${consultCount} model(s) | embedding=${agent.memory?.embedder ? "on" : "off"} | traces=${tc.enabled === false ? "off" : "on"}` },
|
|
353
126
|
{ type: "item", text: `agent.maxTurns = ${ac.maxTurns ?? 200}`, action: "agent.maxTurns" },
|
|
354
127
|
{ type: "item", text: `agent.subagentTurns = ${ac.subagentTurns ?? 100}`, action: "agent.subagentTurns" },
|
|
355
128
|
{ type: "item", text: `并发池 agent.poolLimits = engCoder ${cur("engCoder")} / other ${cur("other")} / advisor ${cur("advisor")}(async 分域上限)`, action: "pool" },
|
|
356
|
-
{ type: "item", text: `agent.compactThreshold = ${
|
|
129
|
+
{ type: "item", text: `agent.compactThreshold = ${ctDisplay}${ctSuffix}`, action: "agent.compactThreshold" },
|
|
357
130
|
{ type: "item", text: `config.defaultModel = ${agent.config?.defaultModel ?? "(未设置 — 新会话起点)"}`, action: "defaultModel" },
|
|
358
131
|
{ type: "item", text: `agent.verifyGuard = ${ac.verifyGuard === true ? "on" : "off"}`, action: "agent.verifyGuard" },
|
|
359
132
|
{ type: "item", text: `traces.enabled = ${tc.enabled === false ? "off" : "on"}(轨迹存档——发布默认关——隐私)`, action: "traces.enabled" },
|
|
@@ -381,7 +154,7 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
381
154
|
pushLine(`Key: ${maskKey(agent.provider.apiKey)}`, C.dim)
|
|
382
155
|
pushLine(`agent.maxTurns: ${ac.maxTurns ?? 200}`, C.dim)
|
|
383
156
|
pushLine(`agent.subagentTurns: ${ac.subagentTurns ?? 100}`, C.dim)
|
|
384
|
-
pushLine(`agent.compactThreshold: ${
|
|
157
|
+
pushLine(`agent.compactThreshold: ${ctDisplay}${ctSuffix}`, C.dim)
|
|
385
158
|
pushLine(`agent.verifyGuard: ${ac.verifyGuard === true ? "on" : "off"}`, C.dim)
|
|
386
159
|
pushLine(`traces.enabled: ${tc.enabled === false ? "off" : "on"}(默认 off——发布隐私——本地分析可开)`, C.dim)
|
|
387
160
|
pushLine(`traces.retentionHours: ${tc.retentionHours ?? 24}(超期文件启动清理——D-TR10)`, C.dim)
|
|
@@ -483,18 +256,37 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
483
256
|
// Numeric config items
|
|
484
257
|
const label = choice.action
|
|
485
258
|
const isTimeout = label === "agent.consultTimeoutMs"
|
|
259
|
+
const isCompact = label === "agent.compactThreshold"
|
|
486
260
|
const current = label === "agent.maxTurns" ? (ac.maxTurns ?? 200)
|
|
487
261
|
: label === "agent.subagentTurns" ? (ac.subagentTurns ?? 100)
|
|
488
|
-
|
|
262
|
+
// §6.17 编辑初值 = 同一数值(resolved 缺场 ⇒ 留空——不预填任何默认数)
|
|
263
|
+
: label === "agent.compactThreshold" ? (ctResolved ?? "")
|
|
489
264
|
: label === "agent.consultTurns" ? (ac.consultTurns ?? 40)
|
|
490
265
|
: label === "traces.retentionHours" ? (tc.retentionHours ?? 24)
|
|
491
266
|
: isTimeout ? Math.round((ac.consultTimeoutMs ?? 600000) / 60000)
|
|
492
267
|
: ""
|
|
493
|
-
|
|
268
|
+
// §6.17 提问行后缀(两档互斥文案):compact 项按 auto 旗二选一,非 compact 项传 null ⇒ 空串
|
|
269
|
+
// (台账 `#1679`——auto 档学「数值会锁死派生线」、显式档学「怎么回 auto」)。
|
|
270
|
+
const hint = compactThresholdHint(isCompact ? ac.compactThresholdAuto === true : null)
|
|
271
|
+
const val = await askQuestion(`${label} (current: ${current}${isTimeout ? " min" : ""}${hint}):`)
|
|
494
272
|
if (!val) continue
|
|
273
|
+
// §6.17 写回面:输入 auto(大小写不敏感、去首尾空白)⇒ 删键回 auto(仅 `agent.compactThreshold`
|
|
274
|
+
// 认该形;其余数值项照旧走数值判,空输入仍 = 取消)。
|
|
275
|
+
if (isCompact && String(val).trim().toLowerCase() === "auto") {
|
|
276
|
+
try {
|
|
277
|
+
await saveProxy((raw) => { if (raw.agent) delete raw.agent.compactThreshold })
|
|
278
|
+
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
279
|
+
pushLine("agent.compactThreshold = (auto)(键已删除——压缩线按在用模型的窗口每轮现算)", C.tool)
|
|
280
|
+
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
281
|
+
continue
|
|
282
|
+
}
|
|
495
283
|
try {
|
|
496
284
|
const num = Number(val)
|
|
497
|
-
if (isNaN(num)) {
|
|
285
|
+
if (isNaN(num)) {
|
|
286
|
+
// 报错行射程:`auto` 子句仅 `agent.compactThreshold` 一项,其余数值项文案不变(R13)
|
|
287
|
+
pushLine(isCompact ? `Value must be a number (or "auto" to clear the explicit override)` : "Value must be a number", C.error)
|
|
288
|
+
continue
|
|
289
|
+
}
|
|
498
290
|
const stored = isTimeout ? Math.round(num * 60000) : num
|
|
499
291
|
await saveProxy((raw) => {
|
|
500
292
|
const keys = label.split(".")
|
|
@@ -504,6 +296,7 @@ export async function handleConfigCommand(ctx, args = []) {
|
|
|
504
296
|
})
|
|
505
297
|
pushLabel("❯ Config", ansi.bold + C.tool)
|
|
506
298
|
pushLine(`${label} = ${isTimeout ? `${val} min (${stored} ms)` : val}`, C.tool)
|
|
299
|
+
if (isCompact) pushLine("显式阈值——auto 派生线不再生效(压缩线改按该显式值判定)", C.dim)
|
|
507
300
|
pushLine("(restart to apply)", C.dim)
|
|
508
301
|
} catch (error) { pushLine(`Save failed: ${error.message}`, C.error) }
|
|
509
302
|
// 回主菜单(Esc 退出)——数值输入 Enter 空值也已 continue 于此
|
|
@@ -1,11 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* createConfigHelpers
|
|
4
|
-
*
|
|
1
|
+
/** config-helpers.mjs — `/config` value/display helpers.
|
|
2
|
+
* Two groups:
|
|
3
|
+
* ① createConfigHelpers / carryoverDefaultModel / maskKey — config read/write helpers
|
|
4
|
+
* (extracted from index.mjs for shared use by slash-commands, wizard, and pickers;
|
|
5
|
+
* carryoverDefaultModel = the session-selection write-back single point — SESSION.md §6.21).
|
|
6
|
+
* Disk writes go through the core's single write executor `writeConfigAtomic` (mtime-gated);
|
|
7
|
+
* this module never writes a second way.
|
|
8
|
+
* ② embeddingPatch / poolCur / effortMenuLevels / compactThresholdSuffix / compactThresholdHint
|
|
9
|
+
* — pure config-value and display-string helpers (zero ctx, zero I/O), moved here from
|
|
10
|
+
* cmd-config.mjs (CONTEXT-COMPACTION.md §6.16.9 — C2 split: value helpers ∥ sub-menu
|
|
11
|
+
* rendering ∥ command spine).
|
|
5
12
|
* R10 F5(D-F5b):persistRaw 全链(磁盘新鲜读→mutate→写)收口进 config.mjs
|
|
6
13
|
* writeConfigAtomic——mtime 门控 + .bak + 冲突放弃(见 MULTI-INSTANCE-COLLAB.md §2a.2)。
|
|
7
14
|
* createConfigHelpers(agent, opts):opts.configPath 为测试注入缝(默认 configPath——
|
|
8
15
|
* 生产 index.mjs 单参调用零变化)。 */
|
|
16
|
+
|
|
17
|
+
/** Merge an embedding-key save into the raw config, backfilling baseURL/model from defaults.
|
|
18
|
+
* Keeps existing custom values (Ollama/local embedding); defaults are the single source
|
|
19
|
+
* (TUI.md §9.3D — NF1). Exported for unit tests. */
|
|
20
|
+
export function embeddingPatch(raw, embKey, defaults) {
|
|
21
|
+
const prev = raw?.embedding ?? {}
|
|
22
|
+
return {
|
|
23
|
+
...prev,
|
|
24
|
+
apiKey: embKey,
|
|
25
|
+
baseURL: prev.baseURL ?? defaults.baseURL,
|
|
26
|
+
model: prev.model ?? defaults.model,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 并发池三键当前值读取(POOL-CONFIG-UNIFIED F-3——2026-09-09):配置值合法(≥1 整数)
|
|
31
|
+
* 读配置——非法/缺省回退 DEFAULTS(agent.poolLimits 三键——/config 并发池子菜单/
|
|
32
|
+
* 主菜单/view 三面共用同一读取)。 */
|
|
33
|
+
export function poolCur(pl, defaults) {
|
|
34
|
+
return (k) => (Number.isInteger(pl?.[k]) && pl[k] >= 1 ? pl[k] : defaults.agent.poolLimits[k])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Effort 菜单档位构造(#16 双 `none` 去重——枚举自带 `none` 的族如 qwen3.8-flash 时原来出两行):
|
|
38
|
+
* `none` 恒为首项且唯一,其余档序保持(`filter` 保序)。语义面零改——`none` = 清档,
|
|
39
|
+
* 消费点(会诊子菜单两支)只认 `=== "none"`;空枚举在取档处已早退 null、不经本函数。 */
|
|
40
|
+
export function effortMenuLevels(enumList) {
|
|
41
|
+
return ["none", ...(enumList ?? []).filter((l) => l !== "none")]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `/config` 压缩阈值显示后缀(§6.17 显示面):auto 派生 ⇒ `" (auto)"`;显式 ⇒ `""`。
|
|
45
|
+
* 三处显示路径(header / 主菜单项 / View full config)共用本函数——后缀文案单源。 */
|
|
46
|
+
export function compactThresholdSuffix(auto) {
|
|
47
|
+
return auto ? " (auto)" : ""
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `/config` 压缩阈值提问行后缀(§6.17 写回面——台账 `#1679`):按 `compactThresholdAuto` 二选一。
|
|
51
|
+
* 两档要的指令相反——auto 档「输数值会锁死派生线」、显式档「怎么回 auto」——只给其中一档,
|
|
52
|
+
* 另一档的人就看不到自己该看的那半句;逐字恒发两句则其中一句必为空操作。
|
|
53
|
+
* 非 compact 数值项传 `null` ⇒ 空串(= 该项无后缀)。分隔符自带(空格 + `—` + 空格)。 */
|
|
54
|
+
export function compactThresholdHint(auto) {
|
|
55
|
+
if (auto == null) return ""
|
|
56
|
+
return auto ? " — 输入数值即固定为显式阈值" : " — 输入 auto 回到自动派生(删键)"
|
|
57
|
+
}
|
|
58
|
+
|
|
9
59
|
export function createConfigHelpers(agent, opts = {}) {
|
|
10
60
|
const cfgPath = opts.configPath ?? null // null → 默认 configPath(动态 import 解)
|
|
11
61
|
|
package/src/tui/index.mjs
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* pickers.mjs — generic list picker + model picker
|
|
12
12
|
* wizard.mjs — first-launch config wizard
|
|
13
13
|
* slash-commands.mjs — slash command dispatch
|
|
14
|
-
* config-helpers.mjs — persistRaw / syncProviderField / maskKey
|
|
14
|
+
* config-helpers.mjs — persistRaw / syncProviderField / maskKey + /config value & display helpers
|
|
15
|
+
* cmd-config.mjs — /config command spine;cmd-config-menus.mjs — its four sub-menus
|
|
15
16
|
* clipboard.mjs — clipboard image paste
|
|
16
17
|
* distill-cmd.mjs — /distill command
|
|
17
18
|
* mouse.mjs — SGR mouse parsing + dispatch assembly (createMouseDispatch)
|
package/src/tui/model-picker.mjs
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* closePicker, renderPickerLines, confirmDelete }(后四者为 pickers.mjs 通用 picker 绑定——闭包入参,环安全)。
|
|
17
17
|
*/
|
|
18
18
|
import { sliceByWidth } from "./render.mjs"
|
|
19
|
-
import { providerSpec, specMatch } from "@thincoder/core/config.mjs"
|
|
19
|
+
import { providerSpec, specMatch, resolveCompactThreshold } from "@thincoder/core/config.mjs"
|
|
20
20
|
import { saveSession, loadSlotFile } from "@thincoder/core/session.mjs"
|
|
21
21
|
import { carryoverDefaultModel } from "./config-helpers.mjs"
|
|
22
22
|
import { getProviderModels, modelListFailureText, dedupeModels } from "./model-catalog.mjs"
|
|
@@ -238,9 +238,9 @@ export function createModelPicker(ctx) {
|
|
|
238
238
|
agent.activeModel = item.model
|
|
239
239
|
agent.provider = { ...target }
|
|
240
240
|
agent.provider.model = item.model
|
|
241
|
+
// §6.17:auto 派生线随模型跟手——只刷新显示面 compactThresholdResolved,显式键 agent.compactThreshold 永不被改写
|
|
241
242
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
242
|
-
|
|
243
|
-
agent.config.agent.compactThreshold = resolveCompactThreshold(null, agent.provider).value
|
|
243
|
+
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
|
|
244
244
|
}
|
|
245
245
|
// 写会话槽(saveSession——槽双字段恒非空)——写回单点在其后(槽先配置后)
|
|
246
246
|
saveSession(agent)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* 2026-10-07 三端对齐批(#1027):添加流两支 +走 proxy 问句(写同一键 `providers[].proxy`);
|
|
16
16
|
* 三端探针目标构造收敛核 `probeTargetOf`(③′)。
|
|
17
17
|
*/
|
|
18
|
-
import { PROVIDER_PRESETS as PRESETS, providerSpec } from "@thincoder/core/config.mjs"
|
|
18
|
+
import { PROVIDER_PRESETS as PRESETS, providerSpec, resolveCompactThreshold } from "@thincoder/core/config.mjs"
|
|
19
19
|
import { hasKey } from "@thincoder/core/model-ref.mjs"
|
|
20
20
|
import { probeTargetOf } from "@thincoder/core/provider-flows.mjs"
|
|
21
21
|
import { probeChannelModels } from "./model-catalog.mjs"
|
|
@@ -209,9 +209,9 @@ export function createProviderAdmin(ctx) {
|
|
|
209
209
|
if (se.name === agent.activeProvider) {
|
|
210
210
|
if (newCtx === undefined) delete agent.provider.context
|
|
211
211
|
else agent.provider.context = newCtx
|
|
212
|
+
// §6.17:窗口覆盖后 auto 派生线跟手——只刷新显示面 compactThresholdResolved,显式键永不被改写
|
|
212
213
|
if (agent.config?.agent?.compactThresholdAuto) {
|
|
213
|
-
|
|
214
|
-
agent.config.agent.compactThreshold = resolveCompactThreshold(null, agent.provider).value
|
|
214
|
+
agent.config.agent.compactThresholdResolved = resolveCompactThreshold(null, agent.provider).value
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
pushLine(target.context !== undefined
|
|
@@ -79,25 +79,31 @@ export function secretPromptFaceLines(face) {
|
|
|
79
79
|
if (typeof v === "string" && v !== "") lines.push({ text: ` ${fieldWord(f.name)}: ${v}`, color: C.dim })
|
|
80
80
|
}
|
|
81
81
|
const field = secretCurrentField(face)
|
|
82
|
-
if (field)
|
|
82
|
+
if (field) {
|
|
83
|
+
// 勾选字段(`save`):`(y/N)` 尾缀——Enter = 不勾(缺省不勾,§6.22 ⑪)
|
|
84
|
+
const suffix = field.checkbox === true ? " (y/N)" : ""
|
|
85
|
+
lines.push({ text: ` \u276f ${fieldWord(field.name)}${suffix}:`, color: ansi.bold + C.text })
|
|
86
|
+
}
|
|
83
87
|
lines.push({ text: " (type in input box below)", color: C.dim })
|
|
84
88
|
return lines
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
/** 步入场:当前字段行 +
|
|
91
|
+
/** 步入场:当前字段行 + 输入框预填(**仅非掩码非勾选字段**——密码零预填(设计 ⑨);掩码步恒空;
|
|
92
|
+
* 勾选步 = y/n 输入,Enter = 不勾)。 */
|
|
88
93
|
function enterSecretField(ctx, face, index) {
|
|
89
94
|
const { state } = ctx
|
|
90
95
|
const field = face.fields[index]
|
|
91
96
|
face.index = index
|
|
92
97
|
face.lines = secretPromptFaceLines(face)
|
|
93
|
-
const prefill = field?.masked === true ? "" : String(field?.prefill ?? "")
|
|
98
|
+
const prefill = field?.masked === true || field?.checkbox === true ? "" : String(field?.prefill ?? "")
|
|
94
99
|
state.input = [...prefill]
|
|
95
100
|
state.cursor = state.input.length
|
|
96
101
|
ctx.render()
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
/** Enter(键面转口):当前字段决议。必填且空 ⇒ 驻留(零推进零提交——零新文案);取值口径同
|
|
100
|
-
* `/team login`:掩码字段原样(密码零裁剪)∥ 非掩码字段 trim(账号 /
|
|
105
|
+
* `/team login`:掩码字段原样(密码零裁剪)∥ 非掩码字段 trim(账号 / 地址同族)∥ **勾选字段 = 布尔**
|
|
106
|
+
* (`y` / `yes` ⇒ true;空 Enter ∥ 其他 ⇒ false——缺省不勾,§6.22 ⑪)。 */
|
|
101
107
|
export function secretPromptSubmit(ctx) {
|
|
102
108
|
const { state } = ctx
|
|
103
109
|
const face = state.secretPrompt
|
|
@@ -105,7 +111,7 @@ export function secretPromptSubmit(ctx) {
|
|
|
105
111
|
const resolve = face?._resolveField
|
|
106
112
|
if (field == null || typeof resolve !== "function") return
|
|
107
113
|
const raw = state.input.join("")
|
|
108
|
-
const value = field.masked === true ? raw : raw.trim()
|
|
114
|
+
const value = field.checkbox === true ? /^(y|yes|true)$/i.test(raw.trim()) : field.masked === true ? raw : raw.trim()
|
|
109
115
|
if (field.required === true && value === "") return
|
|
110
116
|
face._resolveField = null
|
|
111
117
|
resolve(value)
|
|
@@ -173,6 +179,7 @@ function normalizeSecretFields(payload) {
|
|
|
173
179
|
name: f.name,
|
|
174
180
|
masked: f.masked === true,
|
|
175
181
|
required: f.required === true,
|
|
182
|
+
checkbox: f.checkbox === true,
|
|
176
183
|
prefill: typeof f.prefill === "string" ? f.prefill : "",
|
|
177
184
|
}))
|
|
178
185
|
}
|