thincoder 0.12.81 → 0.12.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -74
- package/README.md +3 -3
- package/package.json +2 -2
- package/src/acp/bridge.mjs +15 -109
- package/src/acp/buffered-edit.mjs +217 -0
- package/src/acp/handlers-session.mjs +34 -3
- package/src/acp/handlers-slots.mjs +8 -7
- package/src/cli/make-agent.mjs +2 -2
- package/src/tui/agent-turn.mjs +6 -1
- package/src/tui/cmd-advisor.mjs +1 -1
- package/src/tui/cmd-config.mjs +27 -4
- package/src/tui/cmd-eng.mjs +48 -83
- package/src/tui/cmd-new.mjs +7 -1
- package/src/tui/cmd-session.mjs +2 -2
- package/src/tui/cmd-timers.mjs +2 -2
- package/src/tui/index.mjs +31 -2
- package/src/tui/model-picker.mjs +27 -37
- package/src/tui/provider-admin.mjs +3 -2
- package/src/tui/provider-entries.mjs +92 -0
- package/src/tui/render-loop.mjs +12 -6
- package/src/tui/slash-commands.mjs +6 -2
- package/src/tui/status-line.mjs +19 -7
- package/src/tui/timer-watch.mjs +61 -0
package/src/tui/status-line.mjs
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { ansi, C } from "./ansi.mjs"
|
|
12
12
|
import { sliceByWidth, stringWidth } from "./render.mjs"
|
|
13
13
|
import { t } from "@thincoder/core/i18n.mjs" // 停滞轻显形(TUI.md §7.7):句式键 status.quiet——词面单源(CLI 直取)
|
|
14
|
+
import { resolveWorkMode } from "@thincoder/core/config.mjs" // 档名读取口归一单源(CONFIG §5.4——旧值 minimal 读成 tiny)
|
|
14
15
|
import { isRealUserMsg } from "@thincoder/core/history-window.mjs" // B6 回退链:首条真实 user 消息谓词(纯件单源)
|
|
15
16
|
import { isYesNoModal } from "./interaction.mjs" // X8 跟进①:y/n-only 族判据单源
|
|
16
17
|
|
|
@@ -52,7 +53,8 @@ export function renderStatus(state, agent, cols, slashCommands) {
|
|
|
52
53
|
const planBanner = agent.planMode ? `${C.tool} PLAN${ansi.reset}${ansi.dim}│` : ""
|
|
53
54
|
const advisorBanner = agent.config?.advisor?.guard === true ? `${C.advisor} ADVISOR${ansi.reset}${ansi.dim}│` : ""
|
|
54
55
|
const engBanner = agent.config?.agent?.engineering ? `${C.advisor} ENG${ansi.reset}${ansi.dim}│` : ""
|
|
55
|
-
const
|
|
56
|
+
const tinyBanner = resolveWorkMode(agent.config?.agent) === "tiny" ? `${C.tool} TINY${ansi.reset}${ansi.dim}│` : ""
|
|
57
|
+
const bannerPrefix = (agent.planMode ? " PLAN│ " : "") + (agent.autoApprove ? " AUTO│ " : "") + (agent.config?.advisor?.guard === true ? " ADVISOR│ " : "") + (agent.config?.agent?.engineering ? " ENG│ " : "") + (resolveWorkMode(agent.config?.agent) === "tiny" ? " TINY│ " : "")
|
|
56
58
|
// 第 33 批(TUI §14.3(b)/(c)):attention 态 = chip 行首 + 整行注意力色对包裹(blocked >
|
|
57
59
|
// awaiting;blocked 内 permission > question——与按键分发优先级同序);平态零注入。
|
|
58
60
|
const kind = attentionKind(state)
|
|
@@ -61,7 +63,7 @@ export function renderStatus(state, agent, cols, slashCommands) {
|
|
|
61
63
|
const attentionPad = chip ? `${chip} │ ` : ""
|
|
62
64
|
// 宽度预算(N9④):chip 占位计入——整行仍 ≤ cols − 1(既有口径)。
|
|
63
65
|
const statusMax = cols - 1 - (bannerPrefix ? stringWidth(bannerPrefix) : 0) - (attentionPad ? stringWidth(attentionPad) : 0)
|
|
64
|
-
const inner = `${ansi.dim}${planBanner}${autoBanner}${advisorBanner}${engBanner}${sliceByWidth(statusLine, Math.max(10, statusMax))}`
|
|
66
|
+
const inner = `${ansi.dim}${planBanner}${autoBanner}${advisorBanner}${engBanner}${tinyBanner}${sliceByWidth(statusLine, Math.max(10, statusMax))}`
|
|
65
67
|
// 负向锁(§14.3):attention 为 null ⇒ 半态路径逐字节等价(不经包裹 / 零字节注入)。
|
|
66
68
|
if (!chip) return `${inner}${ansi.reset}`
|
|
67
69
|
// 底色存活(§14.3):既有内容含内部 ansi.reset(banner / ctx 警示段)——每次内部复位后
|
|
@@ -142,11 +144,16 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
142
144
|
const statusText = state.processing ? `${state.status}${toolHint}${elapsed}${quietHint}` : state.status
|
|
143
145
|
// 2026-09-02 Q1(SESSION.md §6.8):provider 可为 null —— 核 `providerSpec(null)` 保守 128K 不抛错。
|
|
144
146
|
// 2026-09-02 §15 ∥ context-percent-parity:窗口 / 校准比 / 两值全在核 `historyReading` 内解析(`ctxCacheOf` 缓出)——
|
|
145
|
-
//
|
|
147
|
+
// 本段零自算式,只格式化核读数的返回值;零值不显示门 `ctxPct > 0` 留在端侧(空历史口径已登记)。
|
|
148
|
+
// CONTEXT-COMPACTION.md §2.5「显示与判定同基准」:分母 = `limit`(用户实际可填的量);告警判据 = `tokens >= threshold`
|
|
149
|
+
// (同一次读数带出的压缩线),不再用魔数 `ctxPct >= 80`——判定与显示读同一个数,端侧不各发明一档阈值。
|
|
146
150
|
const ctxPct = state.ctxCache.pct
|
|
147
|
-
const
|
|
151
|
+
const ctxTokens = state.ctxCache.tokens
|
|
152
|
+
const ctxTokensHint = ctxTokens > 0 ? ` ${fmtK(ctxTokens)}` : ""
|
|
153
|
+
const threshold = state.ctxCache.threshold
|
|
154
|
+
const ctxWarn = Number.isFinite(threshold) && ctxTokens >= threshold
|
|
148
155
|
const ctxHint = ctxPct > 0
|
|
149
|
-
?
|
|
156
|
+
? ctxWarn ? ` │ ${ansi.reset}${C.warn}context ${ctxPct}%${ctxTokensHint}${ansi.reset}${ansi.dim}` : ` │ context ${ctxPct}%${ctxTokensHint}` : ""
|
|
150
157
|
// INPUT-LOCK-ASYNC(C'——F-3):busy(processing 含 digest)状态栏提示——取代旧排队提示
|
|
151
158
|
// (F-7 已删);F16(TUI.md §7.5)**四态分流**(queue-visible 批 2026-09-24):队列非空 ⇒
|
|
152
159
|
// 条数段(dim 段样式 · 零注意力色对——F13 豁免 · 消费即消失);队空 ⇒ 按 busy 面分排队句
|
|
@@ -171,7 +178,12 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
171
178
|
// titleHint 前)——取值 = `agent._pendingTimers` 活读(每帧 recompute / 零缓存副本 / 不显倒计时);
|
|
172
179
|
// 零在途 ⇒ 零注入(负向锁——半态逐字节等价);到期态(任一在途项已过期未送达)⇒ 同段警示色。
|
|
173
180
|
const timers = agent._pendingTimers ?? []
|
|
174
|
-
const timerHint = timers.length === 0 ? "" : ` │ ${timers.some((t) => t.expiresAt <= Date.now()) ? `${ansi.reset}${C.warn}
|
|
181
|
+
const timerHint = timers.length === 0 ? "" : ` │ ${timers.some((t) => t.expiresAt <= Date.now()) ? `${ansi.reset}${C.warn}timer ${timers.length}${ansi.reset}${ansi.dim}` : `timer ${timers.length}`}`
|
|
182
|
+
// 跨实例待取提示(跨实例取件闩·等待期提示 —— `docs/cli/design/TUI.md`「4. 状态栏与活动」):本端有一轮在飞且
|
|
183
|
+
// inbox 里有未取消息 ⇒ 状态段出一段待取条数(沿「已排队 N 条消息」一脉,同段样式);归零即摘除(负向锁——
|
|
184
|
+
// 零条 ∥ 非在飞 ⇒ 零注入,整行逐字节等价)。值 = `onPending` 每拍交来的读数(`index.mjs` 写 `state.inboxPending`)。
|
|
185
|
+
const inboxN = state.inboxPending ?? 0
|
|
186
|
+
const inboxPendingHint = state.processing && inboxN > 0 ? ` │ 待取 ${inboxN} 条消息` : ""
|
|
175
187
|
// D8(2026-09-21 块标题行对齐批——会话标题常显 · `docs/cli/design/TUI.md` §7.4):状态段簇尾
|
|
176
188
|
// (ledgerHint 后、键位组前);取值 = `agent.title` 活读(每帧 recompute)· 40 列截断。
|
|
177
189
|
// B6 消(#677):空白 ⇒ 回退链值(对位 VSC 顶栏——生成前 ∕ 失败期两端同值;值逐字,行级超宽走 statusMax)。
|
|
@@ -180,7 +192,7 @@ function buildStatusLine(state, agent, { cols, slashCommands }) {
|
|
|
180
192
|
const titleHint = ` │ ${titleShown}`
|
|
181
193
|
// 团队登录态段(登录面补全批 · `docs/cli/design/TUI.md` §7.8):簇尾末位(titleHint 后、`│ <enterHint>` 前)
|
|
182
194
|
const teamHint = teamSegmentHint(state.team)
|
|
183
|
-
return ` ${statusText}${taskHint}${turnHint}${tokenHint}${ctxHint}${scrollHint}${ledgerHint}${timerHint}${titleHint}${teamHint} │ ${enterHint} │ /: commands │ wheel/PgUp/PgDn: scroll │ Ctrl+I: inject │ Ctrl+C: exit (×2)`
|
|
195
|
+
return ` ${statusText}${taskHint}${turnHint}${tokenHint}${ctxHint}${scrollHint}${ledgerHint}${timerHint}${inboxPendingHint}${titleHint}${teamHint} │ ${enterHint} │ /: commands │ wheel/PgUp/PgDn: scroll │ Ctrl+I: inject │ Ctrl+C: exit (×2)`
|
|
184
196
|
}
|
|
185
197
|
|
|
186
198
|
/** 团队状态段(TUI.md §7.8——三态闭集):未登录 ⇒ `""`(**负控:零注入——整行逐字节等价**);
|
package/src/tui/timer-watch.mjs
CHANGED
|
@@ -12,10 +12,14 @@ import {
|
|
|
12
12
|
fireTimerWake as coreFireTimerWake,
|
|
13
13
|
timerWakeEnabled,
|
|
14
14
|
} from "@thincoder/core/agent/timers.mjs"
|
|
15
|
+
// 跨实例投递面(MULTI-INSTANCE-COLLAB「取件闩」「消息落法」):取件闩 + 消息形态 + 名册——核转口(本档零自持闩)。
|
|
16
|
+
import { createInboxWatch as coreCreateInboxWatch, crossMessageText, inboxTakeLostLine, inboxBlockedLine } from "@thincoder/core/instance-inbox-watch.mjs"
|
|
17
|
+
import { registerInstance, unregisterInstance } from "@thincoder/core/instance-registry.mjs"
|
|
15
18
|
import { C } from "./ansi.mjs"
|
|
16
19
|
import { REMINDER_CAP } from "./tool-display.mjs"
|
|
17
20
|
|
|
18
21
|
export { timerWakeEnabled } // 判据单源转口(§6.30.3 门三件③ D-TW5):默认开——只有显式 `false` 才关(键 `agent.timerWake`)
|
|
22
|
+
export { registerInstance, unregisterInstance, crossMessageText, inboxTakeLostLine, inboxBlockedLine }
|
|
19
23
|
|
|
20
24
|
/** 「唤醒会武装」判据(`docs/cli/design/TUI.md` §7.1 awaiting 行除外 / §7.2 置位谓词):主 agent 在途 timer
|
|
21
25
|
* 非空 ∧ 开关开 ⇒ 自动续跑在途(不计 attention / 闩会在回合链尾武装)。 */
|
|
@@ -49,6 +53,63 @@ export function modalOpen(state) {
|
|
|
49
53
|
return state?.picker != null || state?.wizard != null || state?.teamAsk != null
|
|
50
54
|
}
|
|
51
55
|
|
|
56
|
+
/** 跨实例取件闩(MULTI-INSTANCE-COLLAB「取件闩」· D-MI28 ∥ D-MI31 ∥ D-MI34):核 `createInboxWatch` 转口。
|
|
57
|
+
*
|
|
58
|
+
* **两个谓词各答一件事**:
|
|
59
|
+
* ① `isBusy` = **已有一轮在飞**,只认 `state.processing`。挂起窗(`state.suspended` ∥ `state._suspPending`)不算——
|
|
60
|
+
* 窗口在跑不等于回合在跑,把窗口算忙就是「有子代理在跑就永远收不到消息」。窗口在场时取件走 `onTake` 的入窗
|
|
61
|
+
* 一支(见 `createInboxTake`),不在这里拦。
|
|
62
|
+
* ② `ready` = 这一端此刻能不能开一轮 = **无用户自发模态在场**(`modalOpen` 为假)。面板在场不是「忙」,是
|
|
63
|
+
* 「此刻别插一轮」——混成一个就分不出该等什么。受阻因由因此从 `busy` 变 `carrier`(受阻行文案不变)。
|
|
64
|
+
* 载体(回合面)与会话同建同毁 ⇒ 除面板外无假侧(设计「取件闩」的两端落点:CLI 的 ready 只由 `modalOpen` 闸住,
|
|
65
|
+
* 「CLI 恒真」指的是载体恒有,不是 ready 恒真)。
|
|
66
|
+
*
|
|
67
|
+
* `onTake` = 取件后开轮面(普通用户回合:`autoTurn` 缺省 false——手动态照常走审批面),**返回 promise**
|
|
68
|
+
* (resolve = 有着落;reject = 开轮没成——失败单源,见核档交接契约);**不收 agent**——载体住本档闭包捕获
|
|
69
|
+
* (D-MI34:核闩不从端壳对象上推载体)。体 = `createInboxTake`(两条去路)。
|
|
70
|
+
* `onBlocked(ms, pending)` = 受阻跨阈可见行 ∥ `onPending(n)` = 待取条数常驻面(接线 = `index.mjs`)。 */
|
|
71
|
+
export function createInboxWatch({ state, onTake, onBlocked = null, onPending = null, timer = setTimeout, clear = clearTimeout } = {}) {
|
|
72
|
+
return coreCreateInboxWatch({
|
|
73
|
+
ready: () => !modalOpen(state), // 面板在场 = 此刻别插一轮(不是「忙」)
|
|
74
|
+
isBusy: () => Boolean(state?.processing), // 只认在飞回合:挂起窗不算忙
|
|
75
|
+
onTake,
|
|
76
|
+
onBlocked,
|
|
77
|
+
onPending,
|
|
78
|
+
timer,
|
|
79
|
+
clear,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 取件后开轮面(`onTake` 的体 · CLI 落点):两条去路——**有活挂起窗 ⇒ 入窗队列 + 唤醒**(窗在步边界起轮,
|
|
84
|
+
* 宿主 `turn` 零调用),否则开**普通用户回合**(`autoTurn` 缺省 false——手动态照常走审批面)。
|
|
85
|
+
* 返回 promise:resolve = 消息有着落(这一轮已登记为在飞 ∥ 已进活窗口的输入队列——窗口先退出则残项由挂起会话
|
|
86
|
+
* 出窗回填 `state.pendingInput`,宿主队列本就由回合尾兜底与步边界取批消费);reject = 没有去路(开轮没成)。
|
|
87
|
+
* **恒不带 `resume`**:走 resume 时那一串不落成 user 消息,而消息取件时已离盘 ⇒ 静默丢。
|
|
88
|
+
* @param {{ state: object, turn: Function, pushLine: Function }} p */
|
|
89
|
+
export function createInboxTake({ state, turn, pushLine }) {
|
|
90
|
+
return (messages) => {
|
|
91
|
+
const text = crossMessageText(messages)
|
|
92
|
+
// ① 已开的挂起窗 ∥ 打开在即的释放窗口(与 `key-handler-busy.mjs` ∥ `key-handler-edit.mjs` 的入队判据同形):
|
|
93
|
+
// 进窗输入队列 + 唤醒核句柄(与 Enter 入队同数组、同唤醒面)。`_suspPending` = 上一轮尾部仍在跑
|
|
94
|
+
// (标题生成 ∥ 蒸馏 flush ∥ 落盘)、挂起会话尚未启动的窗口——那一拍若开顶层回合,就是两个 runAgent 循环同时写
|
|
95
|
+
// 同一份 history(`_suspPending` 本就是为挡这个而设的)。此时 `_suspWake` 可能仍为 null(会话未起)⇒ 可选调用;
|
|
96
|
+
// 消息留在队列,会话启动后按输入优先消费(兜底径同在:池空时回合尾直接取)。
|
|
97
|
+
if (state?.suspended === true || state?._suspPending === true) {
|
|
98
|
+
state.pendingInput ??= []
|
|
99
|
+
state.pendingInput.push(text)
|
|
100
|
+
state._suspWake?.()
|
|
101
|
+
return Promise.resolve()
|
|
102
|
+
}
|
|
103
|
+
// ② 无窗:开普通用户回合(`turn()` 的同步前缀已置 `state.processing` ⇒ 返回时即可读)
|
|
104
|
+
const run = turn(text, {})
|
|
105
|
+
// 回合内错误照旧可见(不是「开轮没成」——processing 已置 ⇒ 这一轮真的开了)
|
|
106
|
+
void run.catch((e) => pushLine(`[error] ${e?.message ?? e}`, C.error))
|
|
107
|
+
if (state.processing === true) return Promise.resolve()
|
|
108
|
+
pushLine(inboxTakeLostLine(messages), C.warn) // D-MI32:消息已离盘 ⇒ 只能当场明说
|
|
109
|
+
return Promise.reject(new Error("inbox-watch: turn did not start"))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
52
113
|
/**
|
|
53
114
|
* 空闲闩触发(§6.30.3 开轮两处① = 核策略 + 端两缝——B3 改指 §6.30.16):**非空闲零动作**(processing ∥
|
|
54
115
|
* suspended ∥ `_suspPending` ∥ `modalOpen`——在途表零触碰,链尾重同步再武装);**模态期抑制**(#448① KD-6):
|