@trans-ai/trans-code 0.10.4 → 0.11.0
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/README.md +6 -0
- package/docs/superpowers/plans/2026-11-22-static-render.md +93 -0
- package/docs/superpowers/specs/2026-11-22-static-render-design.md +42 -0
- package/package.json +1 -1
- package/src/main.tsx +14 -26
- package/src/screens/REPL.tsx +196 -90
- package/src/screens/live-view.test.ts +47 -0
- package/src/screens/live-view.ts +52 -0
- package/src/screens/turn-summary.test.ts +15 -17
- package/src/screens/turn-summary.ts +9 -8
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -240,6 +240,12 @@ ACP 默认权限模式是 `ask`:写文件、改文件、执行命令前会向
|
|
|
240
240
|
|
|
241
241
|
注入预算 12k 字符,超预算整条省略最低优先级(user > feedback > project > reference)并在提示中注明。记忆目录文件是事实源,`MEMORY.md` 删除后会自动重建。测试与隔离用环境变量 `TRANSCODE_USER_DIR` 覆盖根目录。
|
|
242
242
|
|
|
243
|
+
## 渲染与交互
|
|
244
|
+
|
|
245
|
+
- **静态历史架构**:历史每条只打印一次(Ink `<Static>`),流式输出与输入在底部活动区小面积重绘——打字、生成、长会话都不闪烁;回合进行中活动区只显示流式输出的**尾部窗口**(超出部分顶部注明 `… +N lines`),回合结束完整内容落入历史
|
|
246
|
+
- **`ctrl+o` 展开明细**:多工具回合折叠为一行摘要(`… +N lines (ctrl+o 展开明细)`),按 ctrl+o 将最近一个折叠回合的工具明细展开打印;连按依次展开更早的回合
|
|
247
|
+
- **`/clear` 语义**:已打印的历史无法"收回"——/clear 在下方开始新对话,旧内容保留在终端滚动缓冲中(可自行清屏)
|
|
248
|
+
|
|
243
249
|
## 联网工具
|
|
244
250
|
|
|
245
251
|
- **`web_fetch`**:零配置开箱即用。抓 URL 返回可读文本(HTML 剥离为文本 + 标题,text/json 原样,二进制给类型/大小提示);支持 gbk/gb2312 页面解码,512KB / 20k 字符上限,15s 超时
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Static 渲染架构迁移 Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** 历史区迁入 Ink `<Static>`(只印一次),活动区(输入/队列/流式尾部窗口)小面积重绘——全场景消闪烁。
|
|
6
|
+
|
|
7
|
+
**Architecture:** 回合内一切输出写入 `liveOutput`(经既有 32ms 节流),活动区只渲染其**尾部窗口**(rows-10 行 + `… +M lines` 指示);回合结束**单次提交**落地 Static 条目并清空 liveOutput。`history`+`liveOutput` 合并为单一 state(legacy reconciler 下两次提交会闪一帧重复尾巴,spec 裁定 #6)。
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** TypeScript + Bun test;Ink 5 `<Static>`(已装,零新依赖)。
|
|
10
|
+
|
|
11
|
+
**Spec:** `docs/superpowers/specs/2026-11-22-static-render-design.md`(含 6 条审查裁定,均为约束)
|
|
12
|
+
|
|
13
|
+
## Global Constraints
|
|
14
|
+
|
|
15
|
+
- Static 语义(Ink 5.2 实测):纯按 `items.length` 增量打印;**条目推入后不可变**(等长变更不重印,可利用——ctrl+o 清 hiddenLines);同批 `setItems([])`+append 会吞条
|
|
16
|
+
- 活动区高度必须 < 终端行数(否则触发 clearTerminal+整史重画):liveOutput 尾部窗口 `rows - 10`,`… +M lines` 指示行
|
|
17
|
+
- 回合落地 = **单次提交**(合并 state);liveOutput 带 ref 镜像(节流 flush 同步读)
|
|
18
|
+
- /clear:清空与确认条目**分批提交**(setTimeout 0);语义 = 下方开新对话(滚动缓冲保留)
|
|
19
|
+
- Banner = 首条 Static 条目(不留在交互帧)
|
|
20
|
+
- ctrl+o = 动作:展开最近含 hiddenLines 的条目(连按回走),展开后清该条 hiddenLines
|
|
21
|
+
- 每任务收尾:`bun test` 全绿 + `bun run typecheck` 通过
|
|
22
|
+
|
|
23
|
+
## Review Focus
|
|
24
|
+
|
|
25
|
+
1. **长回复超终端高度** → 尾部窗口使活动区恒 < rows,不触发整史重画(Task 1/2)
|
|
26
|
+
2. **/clear 同批吞条** → 确认条目分批提交(Task 3)
|
|
27
|
+
3. **回合落地重复尾巴帧** → 合并 state 单提交(Task 2)
|
|
28
|
+
4. **压缩失败** → 半截摘要 + ⚠ 合并一条落史,liveOutput 清零不渗下回合(Task 2)
|
|
29
|
+
5. **ctrl+o 连按** → 逐条回走,已展开条目不再重复(Task 3)
|
|
30
|
+
6. **resume 重建** → 全量 append 打印;压缩摘要走 liveOutput 后落条目(Task 2/3)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### Task 1: 纯函数层(turn-summary 改造 + 尾部窗口)
|
|
35
|
+
|
|
36
|
+
**Files:**
|
|
37
|
+
- Modify: `src/screens/turn-summary.ts`(`renderTurnLog` → `renderCollapsed`;新增 `renderExpansion`)
|
|
38
|
+
- Create: `src/screens/live-view.ts`(`sliceLiveTail`)
|
|
39
|
+
- Test: `src/screens/turn-summary.test.ts`(改造)、`src/screens/live-view.test.ts`
|
|
40
|
+
|
|
41
|
+
**Interfaces:**
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// turn-summary.ts
|
|
45
|
+
export function renderCollapsed(summary: string, hiddenLines: string[]): string;
|
|
46
|
+
// summary + '\n… +N lines (ctrl+o 展开明细)'(hiddenLines 空则原样)
|
|
47
|
+
export function renderExpansion(entry: { output: string; hiddenLines: string[] }): string;
|
|
48
|
+
// '⚙ 展开明细:' + hiddenLines 全量(无 collapse 提示)
|
|
49
|
+
// live-view.ts
|
|
50
|
+
export function sliceLiveTail(text: string, maxLines: number): { visible: string; hidden: number };
|
|
51
|
+
// 末 maxLines 行;hidden = 被截行数(按非空行计?——按真实行数 split('\n') 计,含空行)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- [ ] **Step 1: 写失败测试**(`renderCollapsed`/`renderExpansion`/`sliceLiveTail` 各行为:计数、边界 maxLines≥总行、空文本),同时改造 turn-summary.test.ts 里 `renderTurnLog` 的三个用例为新 API
|
|
55
|
+
- [ ] **Step 2: 跑测试确认失败**(新 API 不存在)
|
|
56
|
+
- [ ] **Step 3: 实现**;`renderTurnLog` 删除(verbose 开关语义废弃)
|
|
57
|
+
- [ ] **Step 4: 跑测试确认通过 + 全量回归**(REPL 尚未用新 API——先改 turn-summary 会破 REPL 编译?不会:REPL 引用 renderTurnLog,删除即破——**本任务同步把 REPL 内 renderTurnLog 调用点改为 renderCollapsed(折叠行创建时)**,渲染仍走旧 history.map,行为等价)
|
|
58
|
+
- [ ] **Step 5: 提交** `feat: collapsed-line and live-tail pure helpers for static render`
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Task 2: 核心迁移(liveOutput + Static + 回合生命周期 + 压缩流)
|
|
63
|
+
|
|
64
|
+
**Files:**
|
|
65
|
+
- Modify: `src/screens/REPL.tsx`(state 合并、事件路由、Static 渲染、runChat/runCompaction 生命周期)
|
|
66
|
+
- Test: 全量回归 + typecheck(纯逻辑在 Task 1;本任务为架构接线)
|
|
67
|
+
|
|
68
|
+
**Interfaces:**
|
|
69
|
+
- Consumes: Task 1 全部;`createStreamThrottler`(既有)
|
|
70
|
+
- Produces: REPL 内部 `chat` 合并 state 与 helpers(`addHistory`/`appendLive`/`landTurn`,签名不变处沿用旧名)
|
|
71
|
+
|
|
72
|
+
- [ ] **Step 1: 合并 state**:`{ history, liveOutput }` 单 useState + `liveOutputRef` 镜像;`streamAppend` 节流目标从 appendChatOutput 改为 appendLive(写 liveOutput)
|
|
73
|
+
- [ ] **Step 2: 回合生命周期**:runChat 开头不再建宿主条目(输入头进活动区);结束在 finally 单次提交落地 `addHistory({input: display, output: liveOutputRef.current(+hiddenLines/摘要), hiddenLines})` 并清 liveOutput;取消/报错文案同入 liveOutput(既有 streamAppend 路径);压缩摘要流(runCompaction)走 liveOutput,成功/失败(合并 ⚠)各自落一条并清零
|
|
74
|
+
- [ ] **Step 3: 渲染**:`<Static items={history>` 为首子(条目渲染 = input 头 + output 纯文本,折叠提示已烙进 output);活动区:`> 输入头(busy 时)` + `sliceLiveTail(liveOutput, rows-10)` + `… +M lines` + liveTool + 队列 + 输入框 + 弹窗;删除旧 history.map 与 verboseTools
|
|
75
|
+
- [ ] **Step 4: resume 压缩摘要同走 liveOutput**;`applyResume` 的末条追加模式改为 liveOutput 承载 + 落条目
|
|
76
|
+
- [ ] **Step 5: 全量回归 + typecheck + 提交** `feat: static history with live-region streaming and tail window`
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### Task 3: 边缘语义(Banner/clear/ctrl+o)+ README
|
|
81
|
+
|
|
82
|
+
**Files:**
|
|
83
|
+
- Modify: `src/main.tsx`(Banner 移出树,文本经 prop)、`src/screens/REPL.tsx`(seed 首条、/clear 分批、ctrl+o 动作)、`README.md`(ctrl+o 与 /clear 新语义)
|
|
84
|
+
- Test: `src/screens/turn-summary.test.ts` 或新增小测试(ctrl+o 选择的纯函数若有);其余全量回归
|
|
85
|
+
|
|
86
|
+
**Interfaces:**
|
|
87
|
+
- Consumes: Task 1 `renderExpansion`
|
|
88
|
+
- Produces: REPL prop `banner: string`(main.tsx 传入,REPL 初始化 history[0] = banner 条目)
|
|
89
|
+
|
|
90
|
+
- [ ] **Step 1: Banner 入 Static**:main.tsx 去掉 `<Banner>` 包裹,banner 文本作 prop;REPL 初始 history seed 该条目(仅挂载时)
|
|
91
|
+
- [ ] **Step 2: /clear**:setChat 清空后,确认条目 `setTimeout(0)` 分批提交;README 更新语义(滚动缓冲保留)
|
|
92
|
+
- [ ] **Step 3: ctrl+o**:handler 找最后含 hiddenLines 条目 → land 展开条目(renderExpansion)→ 同提交内清该条 hiddenLines(等长变更);README 更新
|
|
93
|
+
- [ ] **Step 4: 全量回归 + typecheck + 提交** `feat: banner-in-static, deferred /clear confirmation, ctrl+o expand action`
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Static 渲染架构(全场景消闪烁)— 设计
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
打字、流式输出、长会话全场景消闪烁。根源:历史区与活动区同帧渲染,任何 setState(每敲一个字符、每个 delta)都整屏清除重画。修法:历史区搬进 Ink `<Static>`(每条只印一次,永不重绘),按键与流式只重绘小面积活动区——这正是 Claude Code 的架构。
|
|
6
|
+
|
|
7
|
+
## 设计
|
|
8
|
+
|
|
9
|
+
**Static 历史区**:`history` 数组渲染进 `<Static items>`;条目 **append-only,推入后不可变**(现架构里 appendChatOutput 对末条追加的写法是唯一的变形点,本设计移除它)。
|
|
10
|
+
|
|
11
|
+
**活动区 `liveOutput`**(新 string state):回合内一切输出——文本 delta、工具结果/diff、折叠摘要行、取消/报错提示——经既有 `streamAppend`(32ms 节流)写入 `liveOutput`;活动区自上而下渲染:`> 输入头` + liveOutput + liveTool 指示 + 队列 + 输入框 + 弹窗。
|
|
12
|
+
|
|
13
|
+
**回合结束**:`addHistory({ input, output: liveOutput, hiddenLines })` 一次性落入 Static,清空 liveOutput。空输出(立即取消)也落条目(含 `(cancelled)`)。
|
|
14
|
+
|
|
15
|
+
**压缩摘要流**(runCompaction 与 resume 压缩):摘要 delta 同样走 liveOutput(前缀"正在提炼前情提要…"),完成后作为一条独立历史条目落入。`applyResume` 现"确认条目先建、摘要流进末条"的模式改为:压缩期间 liveOutput 承载,完成后与确认信息合并落条目。
|
|
16
|
+
|
|
17
|
+
**回合外直写不变**:命令输出、`/search` 流程提示、模式切换横幅、updateNotice 等一次性条目仍直接 `addHistory`(无流变,Static 安全)。
|
|
18
|
+
|
|
19
|
+
**ctrl+o 从开关变动作**:Static 条目印后不可改,"切换展开已打印历史"不可行——改为按下时找**最近一条**含 `hiddenLines` 的历史,补打印展开条目(`addHistory({ input: '', output: renderExpansion(entry) })`);折叠行提示改为 `(ctrl+o 展开明细)`;`verboseTools` state 删除。`renderTurnLog` 收窄为折叠行渲染;新增 `renderExpansion(entry)`。
|
|
20
|
+
|
|
21
|
+
**/clear、/resume 重建**:setHistory 替换/清空后 Static 按新 items 全量打印(append-only 语义不变),无需特判。
|
|
22
|
+
|
|
23
|
+
## 非目标
|
|
24
|
+
|
|
25
|
+
- fork Ink / 单元格级双缓冲 diff(CCB 路线,重)
|
|
26
|
+
- liveOutput 跨会话保留;队列/补全弹窗变化(本就在活动区)
|
|
27
|
+
- 展开块的再折叠(打印即定稿)
|
|
28
|
+
|
|
29
|
+
## 备选(已否)
|
|
30
|
+
|
|
31
|
+
- 输入行 setState 节流:打字频率本就低于帧率,闪烁源于单次重绘面积而非频率 — 治不了
|
|
32
|
+
- 维持整帧渲染 + 仅流式节流:0.10.4 已证不彻底(打字仍闪)
|
|
33
|
+
- ctrl+o 保留开关语义、仅对未来回合生效:违背"展开已折叠明细"的使用动机
|
|
34
|
+
|
|
35
|
+
## 审查后裁定(builder check,实测 Ink 5.2.1 源码后)
|
|
36
|
+
|
|
37
|
+
1. **活动区尾部窗口(必做)**:回合中 liveOutput 只渲染最后 `终端行数 - 固定件(~10)` 行,顶上加 `… +M lines` 指示行;全文存 ref,回合结束完整落 Static——否则长回复每 32ms 触发 clearTerminal + 整史重画,闪烁以更糟形式回归。
|
|
38
|
+
2. **/clear 语义变更**:Static 印出内容无法收回(无 fullStaticOutput 重置 API)——/clear = 下方开新对话、滚动缓冲保留旧内容;清空与后续条目分属不同提交批次(同批 setHistory([])+addHistory 会静默吞条,实测确认)。
|
|
39
|
+
3. **Banner 迁入 Static**:留交互帧会被逐键重绘且钉在历史与输入框之间(实测)——改为首条 Static 条目。
|
|
40
|
+
4. **ctrl+o 逐条回走**:展开后清除该条 hiddenLines(等长变更,不触发重印);连按依次展开更早折叠回合;折叠行提示字样不可抹,接受。
|
|
41
|
+
5. **压缩失败**:liveOutput 半截摘要与 ⚠ 提示合并为一条落史,并清空 liveOutput(防渗入下回合)。
|
|
42
|
+
6. 实现注意:liveOutput 需 ref 镜像(节流 flush 同步读 state 会读到旧值);回合落地与 liveOutput 清空合并为单次提交(legacy reconciler 下两次提交会闪一帧重复尾巴)。
|
package/package.json
CHANGED
package/src/main.tsx
CHANGED
|
@@ -9,32 +9,19 @@ import { autoUpdateNotice } from './upgrade.js';
|
|
|
9
9
|
import { VERSION } from './version.js';
|
|
10
10
|
const DEFAULT_MODEL: string = preferredModelId() ?? 'opus';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/** Startup banner as plain text: printed once as the first Static entry. */
|
|
13
|
+
function bannerText(modelId: string, cwd: string, envLabel?: string): string {
|
|
13
14
|
const models = getAvailableModels();
|
|
14
15
|
const current = models.find(m => m.id === modelId);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
</Box>
|
|
25
|
-
<Box>
|
|
26
|
-
<Text color="yellow">Model: </Text>
|
|
27
|
-
<Text>{envLabel ?? current?.name ?? modelId}</Text>
|
|
28
|
-
</Box>
|
|
29
|
-
<Box>
|
|
30
|
-
<Text color="blue">Dir: </Text>
|
|
31
|
-
<Text>{cwd}</Text>
|
|
32
|
-
</Box>
|
|
33
|
-
<Box marginTop={1}>
|
|
34
|
-
<Text dimColor>Type "help" for available commands, "exit" to quit.</Text>
|
|
35
|
-
</Box>
|
|
36
|
-
</Box>
|
|
37
|
-
);
|
|
16
|
+
return [
|
|
17
|
+
bannerLines('T R A N S C O D E · Multi-Model Agent'),
|
|
18
|
+
'',
|
|
19
|
+
`Trans Code v${VERSION}`,
|
|
20
|
+
`Model: ${envLabel ?? current?.name ?? modelId}`,
|
|
21
|
+
`Dir: ${cwd}`,
|
|
22
|
+
'',
|
|
23
|
+
'Type "help" for available commands, "exit" to quit.',
|
|
24
|
+
].join('\n');
|
|
38
25
|
}
|
|
39
26
|
|
|
40
27
|
function App() {
|
|
@@ -50,8 +37,9 @@ function App() {
|
|
|
50
37
|
return (
|
|
51
38
|
<Box flexDirection="column">
|
|
52
39
|
{/* A saved model choice (from the models flow) wins over the env label */}
|
|
53
|
-
|
|
54
|
-
<REPL
|
|
40
|
+
|
|
41
|
+
<REPL
|
|
42
|
+
banner={bannerText(modelId, cwd, preferredModelId() ? undefined : envModelLabel())} ctx={ctx} updateNotice={autoUpdateNotice()} />
|
|
55
43
|
</Box>
|
|
56
44
|
);
|
|
57
45
|
}
|
package/src/screens/REPL.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Box, Text, useInput, useApp, useStdout } from 'ink';
|
|
1
|
+
import { Box, Static, Text, useInput, useApp, useStdout } from 'ink';
|
|
2
2
|
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { executeCommand, findCommand, getCommands, type CommandContext } from '../commands.js';
|
|
@@ -52,7 +52,8 @@ import { reduceQueue, shouldResumeQueue, type QueueAction } from './input-queue.
|
|
|
52
52
|
import { createStreamThrottler } from './stream-throttle.js';
|
|
53
53
|
import { historyRule } from './history-rule.js';
|
|
54
54
|
import { renderDiff } from './diff-render.js';
|
|
55
|
-
import { createTurnStats, recordCall,
|
|
55
|
+
import { createTurnStats, recordCall, renderCollapsed, renderExpansion, shouldCollapse, summaryLine } from './turn-summary.js';
|
|
56
|
+
import { sliceLiveTail } from './live-view.js';
|
|
56
57
|
import { buildSystemPrompt, INIT_PROMPT, loadProjectContext } from '../agent/system-prompt.js';
|
|
57
58
|
import { HumanMessage, SystemMessage, type BaseMessage } from '@langchain/core/messages';
|
|
58
59
|
|
|
@@ -83,11 +84,13 @@ const SEARCH_PROVIDERS: WebSearchConfig['provider'][] = ['tavily', 'brave'];
|
|
|
83
84
|
|
|
84
85
|
interface REPLProps {
|
|
85
86
|
ctx: CommandContext;
|
|
87
|
+
/** Startup banner text; printed once as the first Static entry. */
|
|
88
|
+
banner?: string;
|
|
86
89
|
/** Background auto-update outcome; a non-null message shows as a banner. */
|
|
87
90
|
updateNotice?: Promise<string | null>;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
93
|
+
export default function REPL({ ctx, banner, updateNotice }: REPLProps) {
|
|
91
94
|
const { exit } = useApp();
|
|
92
95
|
const { stdout } = useStdout();
|
|
93
96
|
const [input, setInput] = useState('');
|
|
@@ -100,7 +103,23 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
100
103
|
inputRef.current = next;
|
|
101
104
|
setInput(next);
|
|
102
105
|
}, []);
|
|
103
|
-
|
|
106
|
+
// Single commit for history + live stream: the legacy reconciler paints
|
|
107
|
+
// per commit, so landing a turn and clearing the live region in two
|
|
108
|
+
// commits flashes one duplicated tail frame (spec ruling #6).
|
|
109
|
+
interface ChatView {
|
|
110
|
+
history: HistoryEntry[];
|
|
111
|
+
liveOutput: string;
|
|
112
|
+
/** Input echo shown at the top of the live region while a turn runs. */
|
|
113
|
+
turnInput: string;
|
|
114
|
+
}
|
|
115
|
+
const [chat, setChat] = useState<ChatView>(() => ({
|
|
116
|
+
// Banner prints once as the first static item (spec ruling #3).
|
|
117
|
+
history: banner ? [{ input: '', output: banner }] : [],
|
|
118
|
+
liveOutput: '',
|
|
119
|
+
turnInput: '',
|
|
120
|
+
}));
|
|
121
|
+
const liveOutputRef = useRef('');
|
|
122
|
+
const turnDisplayRef = useRef('');
|
|
104
123
|
const [historyIndex, setHistoryIndex] = useState(-1);
|
|
105
124
|
const [savedInput, setSavedInput] = useState('');
|
|
106
125
|
const [phase, setPhase] = useState<PromptPhase>('idle');
|
|
@@ -150,23 +169,13 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
150
169
|
}, []);
|
|
151
170
|
|
|
152
171
|
const addHistory = useCallback((entry: HistoryEntry) => {
|
|
153
|
-
|
|
172
|
+
setChat(prev => ({ ...prev, history: [...prev.history, entry] }));
|
|
154
173
|
}, []);
|
|
155
174
|
|
|
156
|
-
/**
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
setHistory(prev => {
|
|
161
|
-
if (prev.length === 0 || lines.length === 0) return prev;
|
|
162
|
-
const next = [...prev];
|
|
163
|
-
const last = next[next.length - 1];
|
|
164
|
-
next[next.length - 1] = {
|
|
165
|
-
...last,
|
|
166
|
-
hiddenLines: [...(last.hiddenLines ?? []), ...lines],
|
|
167
|
-
};
|
|
168
|
-
return next;
|
|
169
|
-
});
|
|
175
|
+
/** Turn-time streaming target: the live region (never mutates history). */
|
|
176
|
+
const appendLive = useCallback((chunk: string) => {
|
|
177
|
+
liveOutputRef.current += chunk;
|
|
178
|
+
setChat(prev => ({ ...prev, liveOutput: prev.liveOutput + chunk }));
|
|
170
179
|
}, []);
|
|
171
180
|
|
|
172
181
|
// Busy-input queue: prompts typed while the agent works. Natural turn end
|
|
@@ -203,18 +212,16 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
203
212
|
const sessionPickerRef = useRef<SessionRecord[]>([]);
|
|
204
213
|
/** Load a record into the live conversation; shared by /resume arg and picker paths. */
|
|
205
214
|
const applyResume = useCallback(
|
|
206
|
-
(record: SessionRecord,
|
|
215
|
+
(record: SessionRecord, _inputLine: string) => {
|
|
207
216
|
conversationRef.current = { id: record.id, createdAt: record.createdAt, titled: true };
|
|
208
217
|
conversationTitleRef.current = record.title;
|
|
209
218
|
summaryRef.current = record.summary ?? null;
|
|
210
219
|
messagesRef.current = record.messages;
|
|
211
220
|
toolSessionRef.current = createToolSession(process.cwd());
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
output: `已恢复「${record.title}」(${record.messages.length} 条消息,${record.model}),继续对话。`,
|
|
215
|
-
});
|
|
221
|
+
// The confirmation line now lands WITH the streamed digest in
|
|
222
|
+
// resumeWith (live region hosts the digest while compacting).
|
|
216
223
|
},
|
|
217
|
-
[
|
|
224
|
+
[],
|
|
218
225
|
);
|
|
219
226
|
|
|
220
227
|
// @-mention file completion: lazy file list, active query, dismissed flag.
|
|
@@ -307,8 +314,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
307
314
|
/** Shared resume flow: auto-compact over-long sessions, then load + render. */
|
|
308
315
|
const resumeWith = async (record: SessionRecord, inputLine: string, keepTurns = DEFAULT_KEEP_TURNS) => {
|
|
309
316
|
const { turns } = splitTurns(record.messages);
|
|
310
|
-
// Load first so the confirmation entry hosts the streamed digest.
|
|
311
317
|
applyResume(record, inputLine);
|
|
318
|
+
const confirm = `已恢复「${record.title}」(${record.messages.length} 条消息,${record.model}),继续对话。`;
|
|
312
319
|
let oldTurns = 0;
|
|
313
320
|
if (turns.length > keepTurns && process.env.TRANSCODE_MOCK !== '1') {
|
|
314
321
|
setBusyBoth(true);
|
|
@@ -322,14 +329,26 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
322
329
|
// Manual success heals the auto-compact breaker too.
|
|
323
330
|
autoCompactFailuresRef.current = 0;
|
|
324
331
|
autoCompactWarnedRef.current = false;
|
|
332
|
+
landLive({ input: inputLine, prefix: confirm });
|
|
325
333
|
} else {
|
|
326
|
-
|
|
334
|
+
// Failure: partial digest + warning merged as ONE entry (ruling #5).
|
|
335
|
+
landLive({
|
|
336
|
+
input: inputLine,
|
|
337
|
+
prefix: confirm,
|
|
338
|
+
suffix: `\n⚠ 提炼失败(${outcome.error ?? '未知'}),已恢复完整对话。`,
|
|
339
|
+
});
|
|
327
340
|
}
|
|
328
341
|
} catch {
|
|
329
|
-
|
|
342
|
+
landLive({
|
|
343
|
+
input: inputLine,
|
|
344
|
+
prefix: confirm,
|
|
345
|
+
suffix: '\n⚠ 提炼失败,已恢复完整对话。',
|
|
346
|
+
});
|
|
330
347
|
} finally {
|
|
331
348
|
setBusyBoth(false);
|
|
332
349
|
}
|
|
350
|
+
} else {
|
|
351
|
+
addHistory({ input: inputLine, output: confirm });
|
|
333
352
|
}
|
|
334
353
|
// Restore in the original conversation form: each message becomes a
|
|
335
354
|
// history entry (rule-framed questions, full-length replies).
|
|
@@ -339,16 +358,6 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
339
358
|
dragFlush();
|
|
340
359
|
};
|
|
341
360
|
|
|
342
|
-
const appendChatOutput = useCallback((chunk: string) => {
|
|
343
|
-
setHistory(prev => {
|
|
344
|
-
if (prev.length === 0) return prev;
|
|
345
|
-
const next = [...prev];
|
|
346
|
-
const last = next[next.length - 1];
|
|
347
|
-
next[next.length - 1] = { ...last, output: last.output + chunk };
|
|
348
|
-
return next;
|
|
349
|
-
});
|
|
350
|
-
}, []);
|
|
351
|
-
|
|
352
361
|
/**
|
|
353
362
|
* Frame-level coalescing for streaming output. Stock Ink re-renders
|
|
354
363
|
* synchronously per setState, so per-delta appends rewrite the whole
|
|
@@ -358,12 +367,45 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
358
367
|
*/
|
|
359
368
|
const streamAppendRef = useRef<ReturnType<typeof createStreamThrottler> | null>(null);
|
|
360
369
|
if (streamAppendRef.current === null) {
|
|
361
|
-
streamAppendRef.current = createStreamThrottler(
|
|
370
|
+
streamAppendRef.current = createStreamThrottler(appendLive, 32);
|
|
362
371
|
}
|
|
363
372
|
const streamAppend = (chunk: string): void => {
|
|
364
373
|
streamAppendRef.current?.push(chunk);
|
|
365
374
|
};
|
|
366
375
|
|
|
376
|
+
/** Show the input echo at the top of the live region while a turn runs. */
|
|
377
|
+
const beginTurnLive = useCallback((display: string) => {
|
|
378
|
+
turnDisplayRef.current = display;
|
|
379
|
+
setChat(prev => ({ ...prev, turnInput: display }));
|
|
380
|
+
}, []);
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Land the streamed live output as one static history entry and clear the
|
|
384
|
+
* live region in a single commit. Flushes the throttler first and builds
|
|
385
|
+
* output = prefix + live + suffix AFTER the flush — never pre-capture the
|
|
386
|
+
* live text at the call site (the tail may sit in the throttler). Ruling #6.
|
|
387
|
+
*/
|
|
388
|
+
const landLive = useCallback(
|
|
389
|
+
(entry: {
|
|
390
|
+
input: string;
|
|
391
|
+
prefix?: string;
|
|
392
|
+
suffix?: string;
|
|
393
|
+
output?: string;
|
|
394
|
+
hiddenLines?: string[];
|
|
395
|
+
}) => {
|
|
396
|
+
streamAppendRef.current?.flush();
|
|
397
|
+
const output =
|
|
398
|
+
entry.output ?? `${entry.prefix ?? ''}${liveOutputRef.current}${entry.suffix ?? ''}`;
|
|
399
|
+
liveOutputRef.current = '';
|
|
400
|
+
setChat(prev => ({
|
|
401
|
+
history: [...prev.history, { input: entry.input, output, hiddenLines: entry.hiddenLines }],
|
|
402
|
+
liveOutput: '',
|
|
403
|
+
turnInput: '',
|
|
404
|
+
}));
|
|
405
|
+
},
|
|
406
|
+
[],
|
|
407
|
+
);
|
|
408
|
+
|
|
367
409
|
/**
|
|
368
410
|
* One shared compaction run for /resume and /compact: fast-model routing
|
|
369
411
|
* (routing.compact → fallback current model) with the digest streamed
|
|
@@ -373,7 +415,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
373
415
|
record: SessionRecord,
|
|
374
416
|
keepTurns: number,
|
|
375
417
|
): Promise<{ compressed: boolean; record: SessionRecord; error?: string }> => {
|
|
376
|
-
|
|
418
|
+
streamAppend('\n正在提炼前情提要…\n');
|
|
377
419
|
try {
|
|
378
420
|
const outcome = await compressSession(
|
|
379
421
|
record,
|
|
@@ -381,12 +423,10 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
381
423
|
keepTurns,
|
|
382
424
|
(delta) => streamAppend(delta),
|
|
383
425
|
);
|
|
384
|
-
|
|
385
|
-
appendChatOutput('\n\n');
|
|
426
|
+
streamAppend('\n\n');
|
|
386
427
|
return outcome;
|
|
387
428
|
} catch (error) {
|
|
388
|
-
|
|
389
|
-
appendChatOutput('\n\n');
|
|
429
|
+
streamAppend('\n\n');
|
|
390
430
|
return {
|
|
391
431
|
compressed: false,
|
|
392
432
|
record,
|
|
@@ -426,9 +466,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
426
466
|
if (autoCompactFailuresRef.current >= 3) return;
|
|
427
467
|
if (!shouldAutoCompact(messagesRef.current, cfg)) return;
|
|
428
468
|
try {
|
|
429
|
-
//
|
|
430
|
-
//
|
|
431
|
-
addHistory({ input: '', output: '' });
|
|
469
|
+
// Digest streams into the live region; it lands as its own entry here
|
|
470
|
+
// (before the turn's echo) and never mixes into the turn entry.
|
|
432
471
|
const record = buildSessionRecord({
|
|
433
472
|
id: conversationRef.current.id,
|
|
434
473
|
title: conversationTitleRef.current,
|
|
@@ -442,8 +481,9 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
442
481
|
if (!outcome.compressed) {
|
|
443
482
|
// Without an error it is a no-op (≤ keepTurns turns — e.g. one giant
|
|
444
483
|
// turn over threshold): nothing compressible, skip without touching
|
|
445
|
-
// the breaker.
|
|
484
|
+
// the breaker. The streamed banner still lands as a stub entry.
|
|
446
485
|
if (outcome.error) throw new Error(outcome.error);
|
|
486
|
+
landLive({ input: '' });
|
|
447
487
|
return;
|
|
448
488
|
}
|
|
449
489
|
summaryRef.current = outcome.record.summary ?? null;
|
|
@@ -451,6 +491,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
451
491
|
saveSession(outcome.record);
|
|
452
492
|
autoCompactFailuresRef.current = 0;
|
|
453
493
|
autoCompactWarnedRef.current = false;
|
|
494
|
+
landLive({ input: '' });
|
|
454
495
|
for (const entry of transcriptEntries(summaryRef.current, messagesRef.current)) {
|
|
455
496
|
addHistory(entry);
|
|
456
497
|
}
|
|
@@ -458,13 +499,15 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
458
499
|
autoCompactFailuresRef.current += 1;
|
|
459
500
|
const reason = error instanceof Error ? error.message : String(error);
|
|
460
501
|
if (autoCompactFailuresRef.current >= 3) {
|
|
461
|
-
|
|
502
|
+
landLive({
|
|
462
503
|
input: '',
|
|
463
|
-
|
|
504
|
+
suffix: `\n⚠ 自动压缩已暂停(连续 3 次失败,最后原因:${reason})。可 /compact 手动压缩或检查 routing.compact 配置。`,
|
|
464
505
|
});
|
|
465
506
|
} else if (!autoCompactWarnedRef.current) {
|
|
466
507
|
autoCompactWarnedRef.current = true;
|
|
467
|
-
|
|
508
|
+
landLive({ input: '', suffix: `\n⚠ 自动压缩失败(${reason}),本轮继续。` });
|
|
509
|
+
} else {
|
|
510
|
+
landLive({ input: '' });
|
|
468
511
|
}
|
|
469
512
|
}
|
|
470
513
|
};
|
|
@@ -475,12 +518,15 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
475
518
|
const controller = new AbortController();
|
|
476
519
|
abortRef.current = controller;
|
|
477
520
|
await autoCompactIfNeeded();
|
|
478
|
-
|
|
521
|
+
// No host entry: the input echo lives in the live region and the whole
|
|
522
|
+
// turn lands in <Static> as one immutable entry when it ends.
|
|
523
|
+
beginTurnLive(display ?? text);
|
|
479
524
|
if (options?.planMode) {
|
|
480
|
-
|
|
525
|
+
streamAppend('[plan 模式:只读探索,产出方案,PLAN READY 后可让我执行]\n');
|
|
481
526
|
}
|
|
482
527
|
|
|
483
528
|
let endedNaturally = false;
|
|
529
|
+
let turnHiddenLines: string[] | undefined;
|
|
484
530
|
try {
|
|
485
531
|
const provider =
|
|
486
532
|
process.env.TRANSCODE_MOCK === '1'
|
|
@@ -567,8 +613,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
567
613
|
// Collapsed detail is kept (hiddenLines) so ctrl+o can reveal it.
|
|
568
614
|
if (shouldCollapse(stats)) {
|
|
569
615
|
const line = summaryLine(stats);
|
|
570
|
-
if (line) streamAppend(`\n${line}`);
|
|
571
|
-
|
|
616
|
+
if (line) streamAppend(`\n${renderCollapsed(line, bufferedLines)}`);
|
|
617
|
+
turnHiddenLines = bufferedLines;
|
|
572
618
|
} else {
|
|
573
619
|
for (const line of bufferedLines) streamAppend(line);
|
|
574
620
|
}
|
|
@@ -633,8 +679,12 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
633
679
|
streamAppend(`\n(run "models" to switch model + set key, or export its env var)`);
|
|
634
680
|
}
|
|
635
681
|
} finally {
|
|
636
|
-
//
|
|
637
|
-
|
|
682
|
+
// Land the whole turn as one immutable static entry and clear the
|
|
683
|
+
// live region in a single commit, then let the queue continue.
|
|
684
|
+
landLive({
|
|
685
|
+
input: turnDisplayRef.current,
|
|
686
|
+
hiddenLines: turnHiddenLines,
|
|
687
|
+
});
|
|
638
688
|
setBusyBoth(false);
|
|
639
689
|
abortRef.current = undefined;
|
|
640
690
|
setLiveTool(null);
|
|
@@ -649,7 +699,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
649
699
|
}
|
|
650
700
|
}
|
|
651
701
|
},
|
|
652
|
-
[ctx.modelId, addHistory,
|
|
702
|
+
[ctx.modelId, addHistory, askInTerminal, setBusyBoth, dragFlush, applyQueue, beginTurnLive, landLive],
|
|
653
703
|
);
|
|
654
704
|
|
|
655
705
|
const enterModelSelect = useCallback(() => {
|
|
@@ -987,9 +1037,6 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
987
1037
|
messages: messagesRef.current,
|
|
988
1038
|
summary: summaryRef.current,
|
|
989
1039
|
});
|
|
990
|
-
// Host entry first so the streamed digest renders inside this
|
|
991
|
-
// command's own frame (same contract as the resume path).
|
|
992
|
-
addHistory({ input: trimmed, output: '' });
|
|
993
1040
|
const outcome = process.env.TRANSCODE_MOCK === '1'
|
|
994
1041
|
? { compressed: false as const, record, error: 'mock 模式无模型' }
|
|
995
1042
|
: await runCompaction(record, keepN);
|
|
@@ -1000,15 +1047,21 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1000
1047
|
// Manual success heals the auto-compact breaker too.
|
|
1001
1048
|
autoCompactFailuresRef.current = 0;
|
|
1002
1049
|
autoCompactWarnedRef.current = false;
|
|
1003
|
-
|
|
1050
|
+
landLive({
|
|
1051
|
+
input: trimmed,
|
|
1052
|
+
suffix: `已压缩:旧 ${turns.length - keepN} 轮提炼为前情提要,保留最近 ${keepN} 轮。`,
|
|
1053
|
+
});
|
|
1004
1054
|
for (const entry of transcriptEntries(summaryRef.current, messagesRef.current)) {
|
|
1005
1055
|
addHistory(entry);
|
|
1006
1056
|
}
|
|
1007
1057
|
} else {
|
|
1008
|
-
|
|
1058
|
+
landLive({
|
|
1059
|
+
input: trimmed,
|
|
1060
|
+
suffix: `\n⚠ 压缩失败(${outcome.error ?? '未知'}),会话保持原样。`,
|
|
1061
|
+
});
|
|
1009
1062
|
}
|
|
1010
1063
|
} catch {
|
|
1011
|
-
|
|
1064
|
+
landLive({ input: trimmed, suffix: '\n⚠ 压缩失败,会话保持原样。' });
|
|
1012
1065
|
} finally {
|
|
1013
1066
|
setBusyBoth(false);
|
|
1014
1067
|
}
|
|
@@ -1051,7 +1104,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1051
1104
|
|
|
1052
1105
|
if (cmdName === 'clear') {
|
|
1053
1106
|
ctx.clearHistory();
|
|
1054
|
-
|
|
1107
|
+
setChat(prev => ({ ...prev, history: [] }));
|
|
1108
|
+
// Static output cannot be un-printed: /clear starts a fresh
|
|
1109
|
+
// transcript below (scrollback keeps the old one). The confirmation
|
|
1110
|
+
// lands in a SEPARATE commit — same-batch clear+append gets
|
|
1111
|
+
// swallowed by Static's length-based diff (probe-verified).
|
|
1112
|
+
setTimeout(() => {
|
|
1113
|
+
addHistory({ input: '', output: '已开始新对话。(旧内容保留在终端滚动缓冲中)' });
|
|
1114
|
+
}, 0);
|
|
1055
1115
|
} else if (result.output) {
|
|
1056
1116
|
addHistory({ input: trimmed, output: result.output });
|
|
1057
1117
|
}
|
|
@@ -1080,9 +1140,25 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1080
1140
|
// eslint-disable-next-line no-console
|
|
1081
1141
|
console.error(`CB ${JSON.stringify(ch)} ret=${key.return} esc=${key.escape}`);
|
|
1082
1142
|
}
|
|
1083
|
-
// ctrl+o:
|
|
1143
|
+
// ctrl+o: expand the most recent folded turn (repeat presses walk
|
|
1144
|
+
// backwards). Printed static entries never re-render, so expansion
|
|
1145
|
+
// lands as a NEW entry and the source entry drops its hiddenLines
|
|
1146
|
+
// (same-length mutation — Static-safe).
|
|
1084
1147
|
if (key.ctrl && (ch === 'o' || ch === 'O')) {
|
|
1085
|
-
|
|
1148
|
+
const history = chat.history;
|
|
1149
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
1150
|
+
const entry = history[i];
|
|
1151
|
+
if (entry?.hiddenLines?.length) {
|
|
1152
|
+
const expansion = renderExpansion({ output: entry.output, hiddenLines: entry.hiddenLines });
|
|
1153
|
+
const index = i;
|
|
1154
|
+
setChat(prev => {
|
|
1155
|
+
const next = [...prev.history];
|
|
1156
|
+
next[index] = { ...next[index]!, hiddenLines: undefined };
|
|
1157
|
+
return { ...prev, history: [...next, { input: '', output: expansion }] };
|
|
1158
|
+
});
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1086
1162
|
return;
|
|
1087
1163
|
}
|
|
1088
1164
|
// @-mention popup: Esc dismisses it instead of exiting the app.
|
|
@@ -1359,7 +1435,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1359
1435
|
}
|
|
1360
1436
|
|
|
1361
1437
|
if (phase === 'idle' && key.upArrow) {
|
|
1362
|
-
const inputs = history.map(h => h.input);
|
|
1438
|
+
const inputs = chat.history.map(h => h.input);
|
|
1363
1439
|
if (inputs.length === 0) return;
|
|
1364
1440
|
|
|
1365
1441
|
if (historyIndex === -1) {
|
|
@@ -1378,7 +1454,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1378
1454
|
if (phase === 'idle' && key.downArrow) {
|
|
1379
1455
|
if (historyIndex === -1) return;
|
|
1380
1456
|
|
|
1381
|
-
const inputs = history.map(h => h.input);
|
|
1457
|
+
const inputs = chat.history.map(h => h.input);
|
|
1382
1458
|
const newIndex = historyIndex + 1;
|
|
1383
1459
|
|
|
1384
1460
|
if (newIndex >= inputs.length) {
|
|
@@ -1396,6 +1472,17 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1396
1472
|
}
|
|
1397
1473
|
});
|
|
1398
1474
|
|
|
1475
|
+
// Live-region tail window: keep the interactive frame shorter than the
|
|
1476
|
+
// terminal or Ink falls back to clearing + repainting everything.
|
|
1477
|
+
// Wrapped-row budget (review finding: Ink counts folded screen rows, so
|
|
1478
|
+
// logical-line budgets blow on long CJK/diff lines): rows-12 with wide
|
|
1479
|
+
// chars measured at 2 columns, columns-2 for paddingX.
|
|
1480
|
+
const liveTail = sliceLiveTail(
|
|
1481
|
+
chat.liveOutput,
|
|
1482
|
+
(stdout?.rows ?? 24) - 12,
|
|
1483
|
+
(stdout?.columns ?? 80) - 2,
|
|
1484
|
+
);
|
|
1485
|
+
|
|
1399
1486
|
const promptLabel = phase === 'model_select'
|
|
1400
1487
|
? 'vendor> '
|
|
1401
1488
|
: phase === 'model_pick'
|
|
@@ -1416,29 +1503,48 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
1416
1503
|
|
|
1417
1504
|
return (
|
|
1418
1505
|
<Box flexDirection="column" paddingX={1}>
|
|
1419
|
-
{history
|
|
1420
|
-
|
|
1421
|
-
{
|
|
1422
|
-
|
|
1423
|
-
<
|
|
1424
|
-
|
|
1425
|
-
<
|
|
1426
|
-
|
|
1506
|
+
<Static items={chat.history}>
|
|
1507
|
+
{(entry, i) => (
|
|
1508
|
+
<Box key={i} flexDirection="column">
|
|
1509
|
+
{entry.input && (
|
|
1510
|
+
<Box flexDirection="column">
|
|
1511
|
+
<Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
|
|
1512
|
+
<Box>
|
|
1513
|
+
<Text color="green" bold>> </Text>
|
|
1514
|
+
<Text color="cyan" bold>{entry.input}</Text>
|
|
1515
|
+
</Box>
|
|
1516
|
+
<Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
|
|
1427
1517
|
</Box>
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1518
|
+
)}
|
|
1519
|
+
{entry.output && (
|
|
1520
|
+
<Box marginLeft={2}>
|
|
1521
|
+
<Text>{entry.output}</Text>
|
|
1522
|
+
</Box>
|
|
1523
|
+
)}
|
|
1524
|
+
</Box>
|
|
1525
|
+
)}
|
|
1526
|
+
</Static>
|
|
1527
|
+
|
|
1528
|
+
{busy && chat.turnInput && (
|
|
1529
|
+
<Box flexDirection="column">
|
|
1530
|
+
<Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
|
|
1531
|
+
<Box>
|
|
1532
|
+
<Text color="green" bold>> </Text>
|
|
1533
|
+
<Text color="cyan" bold>{chat.turnInput}</Text>
|
|
1534
|
+
</Box>
|
|
1535
|
+
<Text color="gray" dimColor>{historyRule(stdout?.columns ?? 80)}</Text>
|
|
1536
|
+
</Box>
|
|
1537
|
+
)}
|
|
1538
|
+
{liveTail.hidden > 0 && (
|
|
1539
|
+
<Box marginLeft={2}>
|
|
1540
|
+
<Text color="gray" dimColor>… +{liveTail.hidden} lines</Text>
|
|
1541
|
+
</Box>
|
|
1542
|
+
)}
|
|
1543
|
+
{liveTail.visible && (
|
|
1544
|
+
<Box marginLeft={2}>
|
|
1545
|
+
<Text>{liveTail.visible}</Text>
|
|
1440
1546
|
</Box>
|
|
1441
|
-
)
|
|
1547
|
+
)}
|
|
1442
1548
|
|
|
1443
1549
|
{phase === 'permission' && pendingPermissionRef.current && (
|
|
1444
1550
|
<Box marginLeft={2}>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { displayWidth, sliceLiveTail } from './live-view.js';
|
|
3
|
+
|
|
4
|
+
describe('displayWidth', () => {
|
|
5
|
+
test('宽字符(CJK)按 2 列计,ASCII 按 1 列', () => {
|
|
6
|
+
expect(displayWidth('abc')).toBe(3);
|
|
7
|
+
expect(displayWidth('中文')).toBe(4);
|
|
8
|
+
expect(displayWidth('a中b')).toBe(4);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('sliceLiveTail (wrapped-row aware)', () => {
|
|
13
|
+
test('超窗截尾:visible 为最后若干逻辑行,hidden 为被截逻辑行数', () => {
|
|
14
|
+
const text = Array.from({ length: 12 }, (_, i) => `line-${i}`).join('\n');
|
|
15
|
+
const { visible, hidden } = sliceLiveTail(text, 5, 80);
|
|
16
|
+
expect(visible).toBe('line-7\nline-8\nline-9\nline-10\nline-11');
|
|
17
|
+
expect(hidden).toBe(7);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('折行计入预算:尾部装最新行,装不下的大段被截(按屏幕行计)', () => {
|
|
21
|
+
const longCjk = '中'.repeat(200); // 80 列下 ≈ 5 屏幕行(400 列宽)
|
|
22
|
+
const text = `${longCjk}\nshort\nanother`;
|
|
23
|
+
const { visible, hidden } = sliceLiveTail(text, 6, 80);
|
|
24
|
+
// 尾窗保最新:another(1)+short(1)=2 行;longCjk 占 5 行装不下 → 截
|
|
25
|
+
expect(visible).toBe('short\nanother');
|
|
26
|
+
expect(hidden).toBe(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('未超窗原样返回 hidden=0;空文本安全', () => {
|
|
30
|
+
expect(sliceLiveTail('a\nb\nc', 5, 80)).toEqual({ visible: 'a\nb\nc', hidden: 0 });
|
|
31
|
+
expect(sliceLiveTail('', 5, 80)).toEqual({ visible: '', hidden: 0 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('单逻辑行超预算也至少保留该行(不整行丢弃)', () => {
|
|
35
|
+
const longCjk = '中'.repeat(400); // ≈ 10 屏幕行
|
|
36
|
+
const { visible, hidden } = sliceLiveTail(longCjk, 3, 80);
|
|
37
|
+
expect(visible).toBe(longCjk);
|
|
38
|
+
expect(hidden).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('maxLines 钳制下限 1:退化终端不产生空 visible 与虚高 hidden', () => {
|
|
42
|
+
const text = 'a\nb\nc';
|
|
43
|
+
const { visible, hidden } = sliceLiveTail(text, 0, 80);
|
|
44
|
+
expect(visible).toBe('c');
|
|
45
|
+
expect(hidden).toBe(2);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-region tail windowing. The interactive frame must stay SHORTER than
|
|
3
|
+
* the terminal: once it reaches stdout rows, Ink falls back to
|
|
4
|
+
* clearTerminal + full-history repaint on every render (the flicker this
|
|
5
|
+
* rework kills). During a turn only the tail of the streamed output is
|
|
6
|
+
* shown; the full text lives in a ref and lands in <Static> at turn end.
|
|
7
|
+
*
|
|
8
|
+
* Budgeting counts WRAPPED screen rows (Ink's overflow check uses Yoga
|
|
9
|
+
* layout rows, where wide chars take two columns) — not logical lines.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface LiveTail {
|
|
13
|
+
visible: string;
|
|
14
|
+
hidden: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Approximate terminal columns taken by a string: CJK/fullwidth count 2. */
|
|
18
|
+
export function displayWidth(text: string): number {
|
|
19
|
+
let width = 0;
|
|
20
|
+
for (const ch of text) {
|
|
21
|
+
width += /[ᄀ-ᅟ⺀-가-힣豈-︰--⦆¢-₩]/.test(ch)
|
|
22
|
+
? 2
|
|
23
|
+
: 1;
|
|
24
|
+
}
|
|
25
|
+
return width;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function screenRows(line: string, columns: number): number {
|
|
29
|
+
const width = displayWidth(line);
|
|
30
|
+
return Math.max(1, Math.ceil(width / columns));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function sliceLiveTail(text: string, maxLines: number, columns: number): LiveTail {
|
|
34
|
+
if (!text) return { visible: '', hidden: 0 };
|
|
35
|
+
const budget = Math.max(1, maxLines);
|
|
36
|
+
const cols = Math.max(20, columns);
|
|
37
|
+
const lines = text.split('\n');
|
|
38
|
+
|
|
39
|
+
// Walk from the end, accumulating wrapped screen rows until the budget
|
|
40
|
+
// is exhausted. A single line that alone exceeds the budget is still
|
|
41
|
+
// kept (never drop content entirely — the constant margin absorbs it).
|
|
42
|
+
let used = 0;
|
|
43
|
+
let cut = lines.length; // index of first visible line
|
|
44
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
45
|
+
const rows = screenRows(lines[i]!, cols);
|
|
46
|
+
if (used + rows > budget && i !== lines.length - 1) break;
|
|
47
|
+
used += rows;
|
|
48
|
+
cut = i;
|
|
49
|
+
}
|
|
50
|
+
if (cut === 0) return { visible: text, hidden: 0 };
|
|
51
|
+
return { visible: lines.slice(cut).join('\n'), hidden: cut };
|
|
52
|
+
}
|
|
@@ -40,25 +40,23 @@ describe('turn summary', () => {
|
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
describe('renderTurnLog', () => {
|
|
44
|
-
test('折叠:summary + "… +N lines (ctrl+o to expand)",N 数实际行数', async () => {
|
|
45
|
-
const { renderTurnLog } = await import('./turn-summary.js');
|
|
46
|
-
const hidden = ['\n⚙ read_file a.ts ✓', '\n⚙ bash npm test ✓\nextra line', '\n⚙ grep foo ✓'];
|
|
47
|
-
expect(renderTurnLog('⚙ 3 tool calls · …', hidden, false)).toBe(
|
|
48
|
-
'⚙ 3 tool calls · …\n… +4 lines (ctrl+o to expand)',
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
expect(out).toContain('
|
|
44
|
+
describe('static render helpers', () => {
|
|
45
|
+
test('renderCollapsed:summary + "(ctrl+o 展开明细)" 提示;hiddenLines 空则原样', async () => {
|
|
46
|
+
const { renderCollapsed } = await import('./turn-summary.js');
|
|
47
|
+
const hidden = ['\n⚙ read_file a ✓', '\n⚙ bash t ✓', 'extra\nline'];
|
|
48
|
+
const out = renderCollapsed('⚙ 3 tool calls · …', hidden);
|
|
49
|
+
expect(out).toContain('⚙ 3 tool calls · …');
|
|
50
|
+
expect(out).toContain('… +4 lines (ctrl+o 展开明细)');
|
|
51
|
+
expect(renderCollapsed('S', [])).toBe('S');
|
|
58
52
|
});
|
|
59
53
|
|
|
60
|
-
test('
|
|
61
|
-
const {
|
|
62
|
-
|
|
54
|
+
test('renderExpansion:全量明细 + 头,无 collapse 提示', async () => {
|
|
55
|
+
const { renderExpansion } = await import('./turn-summary.js');
|
|
56
|
+
const out = renderExpansion({ output: '⚙ 2 tool calls · …', hiddenLines: ['\n⚙ read_file a ✓', '\n⚙ bash t ✓'] });
|
|
57
|
+
expect(out).toContain('展开明细');
|
|
58
|
+
expect(out).toContain('read_file a ✓');
|
|
59
|
+
expect(out).toContain('bash t ✓');
|
|
60
|
+
expect(out).not.toContain('collapse');
|
|
63
61
|
});
|
|
64
62
|
});
|
|
@@ -34,17 +34,18 @@ export function summaryLine(stats: TurnStats): string {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* detail lines become visible so nothing is permanently unreachable.
|
|
37
|
+
* Collapsed turn line, stamped at creation time (static entries print once
|
|
38
|
+
* and never re-render): summary plus the expand affordance.
|
|
40
39
|
*/
|
|
41
|
-
export function
|
|
40
|
+
export function renderCollapsed(summary: string, hiddenLines: string[]): string {
|
|
42
41
|
if (hiddenLines.length === 0) return summary;
|
|
43
|
-
if (verbose) {
|
|
44
|
-
return `${summary}\n(ctrl+o to collapse)${hiddenLines.join('')}`;
|
|
45
|
-
}
|
|
46
42
|
const count = hiddenLines
|
|
47
43
|
.flatMap((line) => line.split('\n'))
|
|
48
44
|
.filter((line) => line.trim().length > 0).length;
|
|
49
|
-
return `${summary}\n… +${count} lines (ctrl+o
|
|
45
|
+
return `${summary}\n… +${count} lines (ctrl+o 展开明细)`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** ctrl+o action: full detail of a folded turn, printed as a new entry. */
|
|
49
|
+
export function renderExpansion(entry: { output: string; hiddenLines: string[] }): string {
|
|
50
|
+
return `⚙ 展开明细:${entry.hiddenLines.join('')}`;
|
|
50
51
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated from package.json by scripts/sync-version.ts (npm version hook)
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.11.0';
|