@waq666/pneuma 0.7.0 → 0.7.1

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.
Files changed (41) hide show
  1. package/README.md +206 -145
  2. package/lib/app/App.d.ts +3 -1
  3. package/lib/app/App.js +324 -172
  4. package/lib/app/App.js.nv-backup +1650 -0
  5. package/lib/app/ChatView.d.ts +40 -9
  6. package/lib/app/ChatView.js +150 -38
  7. package/lib/app/StatusBar.js +21 -92
  8. package/lib/app/TimelineRail.d.ts +22 -0
  9. package/lib/app/TimelineRail.js +160 -0
  10. package/lib/app/TimelineRail.js.negbak +98 -0
  11. package/lib/app/TimelineRail.js.nv-backup +160 -0
  12. package/lib/app/ToolCard.d.ts +7 -1
  13. package/lib/app/ToolCard.js +30 -6
  14. package/lib/app/ToolCard.js.nv-backup +64 -0
  15. package/lib/app/TranscriptOverlay.d.ts +23 -8
  16. package/lib/app/TranscriptOverlay.js +29 -10
  17. package/lib/app/TranscriptViewport.d.ts +78 -0
  18. package/lib/app/TranscriptViewport.js +218 -0
  19. package/lib/app/Welcome.js +13 -8
  20. package/lib/app/click.d.ts +15 -2
  21. package/lib/app/click.js +20 -6
  22. package/lib/app/keymap.d.ts +56 -0
  23. package/lib/app/keymap.js +56 -0
  24. package/lib/app/mouse.d.ts +33 -0
  25. package/lib/app/mouse.js +35 -0
  26. package/lib/app/pointer.d.ts +16 -0
  27. package/lib/app/pointer.js +60 -0
  28. package/lib/app/scroll-model.d.ts +240 -0
  29. package/lib/app/scroll-model.js +347 -0
  30. package/lib/app/snapshot-subscribe.d.ts +34 -0
  31. package/lib/app/snapshot-subscribe.js +110 -0
  32. package/lib/app/theme.d.ts +29 -1
  33. package/lib/app/theme.js +46 -1
  34. package/lib/app/ticker.d.ts +7 -0
  35. package/lib/app/ticker.js +53 -0
  36. package/lib/core/llm.d.ts +11 -0
  37. package/lib/core/llm.js +19 -2
  38. package/lib/plugins/subagent.js +36 -2
  39. package/lib/plugins/tool-search.js +11 -2
  40. package/lib/plugins/tool-search.js.nv-backup +434 -0
  41. package/package.json +1 -1
@@ -1,32 +1,63 @@
1
- import type { JSX, ReactNode } from 'react';
1
+ import type { JSX, ReactNode, Ref } from 'react';
2
2
  import type { TranscriptEntry } from '../contract.js';
3
3
  import { type RegisterClick } from './click.js';
4
- /** 单条条目的渲染(回看浮层复用同一份,直播光标由 streaming 控制)。 */
5
- export declare function Entry({ entry, streaming, expandThinking, onPreviewImages, onOpenAgent, registerClick, }: {
4
+ import { type TranscriptViewportApi } from './TranscriptViewport.js';
5
+ /**
6
+ * 单条条目的渲染(回看浮层复用同一份,直播光标由 streaming 控制)。
7
+ *
8
+ * `memo` 是救命的:定稿条目在 `transcript.entries` 里是**同一个对象引用**,而快照
9
+ * 每次重建都会换掉直播尾——没有 memo 时每个增量都要把窗口里 80 条全部重渲染一遍。
10
+ * 前提是 props 里没有每帧新建的值(回调在 App 侧已 `useCallback`,见 handleOpenAgent)。
11
+ */
12
+ export declare const Entry: import("react").NamedExoticComponent<{
6
13
  entry: TranscriptEntry;
7
14
  streaming: boolean;
8
15
  expandThinking: boolean;
16
+ /** 已经展开的工具卡(点一行工具卡切换;状态由 App 持有)。 */
17
+ expandedTools?: ReadonlySet<number>;
18
+ /** 点工具卡的回调(省略 = 工具卡不可点)。 */
19
+ onToggleTool?: (id: number) => void;
9
20
  /** 用户消息图片行的点击回调(省略 = 图片行不可点)。 */
10
21
  onPreviewImages?: (images: string[]) => void;
11
22
  /** 子代理卡的点击回调(省略 = 卡片不可点):打开队友的只读转录浮层。 */
12
23
  onOpenAgent?: (file: string) => void;
13
24
  registerClick?: RegisterClick;
14
- }): JSX.Element | null;
15
- export declare function ChatView({ entries, turnState, expandThinking, empty, header, onPreviewImages, onOpenAgent, registerClick, }: {
16
- /** 可见窗口切片(App 按「帧底对齐 + 顶部裁剪」算好传入)。 */
25
+ }>;
26
+ export declare function ChatView({ entries, turnState, expandThinking, empty, welcome, maxWidth, columns, railCenterLines, expandedTools, onToggleTool, onPreviewImages, onOpenAgent, onPickTurn, registerClick, viewportRef, onAtTailChange, }: {
27
+ /** 全量条目(窗口切片、行偏移、刻度几何都在 TranscriptViewport 里按行算)。 */
17
28
  entries: TranscriptEntry[];
18
29
  turnState: 'idle' | 'thinking' | 'working' | 'awaiting-approval';
19
30
  expandThinking: boolean;
20
31
  /** 全会话一条都没有(和「窗口恰好翻空」区分开,只有前者画开场提示)。 */
21
32
  empty: boolean;
22
33
  /**
23
- * 挂在会话流最顶上的头部(启动欢迎页):随内容一起从顶上滚走(对齐 codex 的
24
- * session header / dsh 的 LogoHeader——不独占屏幕,也不永久占位)。
34
+ * 挂在会话流最顶上的头部(启动欢迎页):**随内容一起从顶上滚走**(对齐 codex 的
35
+ * session header / dsh 的 LogoHeader——不独占屏幕,也不永久占位),所以它是流里的
36
+ * 第一个「条目」,不是固定表头。
25
37
  */
26
- header?: ReactNode;
38
+ welcome?: ReactNode;
39
+ /** 没画刻度栏时可用的内容宽度(列)。 */
40
+ maxWidth: number;
41
+ /** 终端总列数(刻度栏门槛)。 */
42
+ columns: number;
43
+ /**
44
+ * 刻度栏**居中**用的高度(省略 = 视口行数)。聊天区可用高度会随「回到底部」胶囊、
45
+ * 草稿行数变化,按它居中会让整块刻度每滚一下上下挪一行,所以调用方传「帧高 − 状态栏」。
46
+ */
47
+ railCenterLines?: number;
48
+ /** 已展开的工具卡(点一行工具卡切换)。 */
49
+ expandedTools?: ReadonlySet<number>;
50
+ /** 点工具卡的回调(省略 = 工具卡不可点)。 */
51
+ onToggleTool?: (id: number) => void;
27
52
  /** 用户消息图片行的点击预览回调(省略 = 图片行不可点)。 */
28
53
  onPreviewImages?: (images: string[]) => void;
29
54
  /** 子代理卡点击回调(省略 = 卡片不可点):打开队友的只读转录浮层。 */
30
55
  onOpenAgent?: (file: string) => void;
56
+ /** 顶部钉住的轮头被点击(参数是轮下标):跳回那一轮的题面。 */
57
+ onPickTurn?: (turn: number) => void;
31
58
  registerClick?: RegisterClick;
59
+ /** 视口手柄(App 的键位与鼠标打这里)。 */
60
+ viewportRef?: Ref<TranscriptViewportApi>;
61
+ /** 「是不是贴着最新」变化时回调(回到底部的那颗胶囊用)。 */
62
+ onAtTailChange?: (atTail: boolean) => void;
32
63
  }): JSX.Element;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * 会话流:把 TranscriptEntry 序列渲染成终端块。只渲染 App 算好的「可见窗口」切片
4
4
  * (整屏视口:根盒恒定高度、底对齐、老条目从顶上裁掉;回看走 Ctrl+O 浮层)。
@@ -13,23 +13,40 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  *
14
14
  * @module dsc-tui/app/ChatView
15
15
  */
16
- import { useEffect, useRef, useState } from 'react';
16
+ import { memo, useRef } from 'react';
17
17
  import { Box, Text, useStdout } from 'ink';
18
18
  import { MarkdownView } from './MarkdownView.js';
19
19
  import { ToolCard } from './ToolCard.js';
20
20
  import { displayWidth } from './markdown.js';
21
- import { useClickRegion } from './click.js';
22
- import { ACCENT, DIFF_COLOR, GAP, INDENT, PAD, PALETTE, STATUS_COLOR, TEXT } from './theme.js';
21
+ import { measuredSpan, useClickRegion } from './click.js';
22
+ import { HINT } from './keymap.js';
23
+ import { useTick } from './ticker.js';
24
+ import { TranscriptViewport } from './TranscriptViewport.js';
25
+ import { ACCENT, DIFF_COLOR, GAP, INDENT, PAD, PALETTE, STATUS_COLOR, TEXT, mixHex } from './theme.js';
23
26
  /** 流式思考的盲文 spinner 帧(dsh 同款字符,80-120ms 一拍)。 */
24
27
  const BRAILLE = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
25
- /** 盲文 spinner:本地帧状态只重渲染自己,不动会话流的 reconcile。 */
26
- function BrailleSpinner() {
27
- const [frame, setFrame] = useState(0);
28
- useEffect(() => {
29
- const timer = setInterval(() => setFrame((current) => (current + 1) % BRAILLE.length), 120);
30
- return () => clearInterval(timer);
31
- }, []);
32
- return _jsx(Text, { color: PALETTE.accent, children: BRAILLE[frame] });
28
+ /**
29
+ * 用户消息之前留一行空:一句话(尤其金色的 `❯` 行)紧贴在上一轮的工具输出下面是糊的
30
+ * ——看不出「这一轮从哪开始」。dsh 的做法是「一轮的第一条消息 marginTop=1」(
31
+ * MessageList 的 `marginTopOnTurn`),这里同款。列表第一条也留:它上面要么是欢迎块、
32
+ * 要么是开场提示,留一行反而把题面从引导文字里分出来。
33
+ */
34
+ const USER_TOP_GAP = 1;
35
+ /** spinner 节拍:所有 spinner 共用这一个周期(见 ticker.ts)。 */
36
+ const BRAILLE_MS = 120;
37
+ /** 耗时读数节拍:同上,1 秒一格。 */
38
+ const SECONDS_MS = 1000;
39
+ /**
40
+ * 盲文 spinner:走共享节拍(同周期全局一个计时器),帧状态只重渲染自己。
41
+ *
42
+ * `pulse` = **呼吸色**(照 dsh 的 Kimi Code 蓝脉冲):字形颜色沿「品牌蓝 → 冰蓝」按正弦
43
+ * 来回,一个来回约 0.55 秒(`sin(frame * 0.9)`,与 dsh 同一个系数)。只给「思考中」用——
44
+ * 画面上同时呼吸的东西一多就是噪音,工具卡/队友卡上的 spinner 保持恒定强调色。
45
+ */
46
+ function BrailleSpinner({ pulse = false }) {
47
+ const frame = useTick(BRAILLE_MS);
48
+ const color = pulse === true ? mixHex(PALETTE.brand, PALETTE.ice, (Math.sin(frame * 0.9) + 1) / 2) : PALETTE.accent;
49
+ return _jsx(Text, { color: color, children: BRAILLE[frame % BRAILLE.length] });
33
50
  }
34
51
  const oneLine = (text, limit) => {
35
52
  const flat = text.replace(/\s+/g, ' ').trim();
@@ -50,6 +67,9 @@ const fmtTokens = (value) => {
50
67
  return `${(value / 1000).toFixed(1)}k`;
51
68
  return String(value);
52
69
  };
70
+ /** 瀑布窗口恒定 3 行(Kimi Code 视觉语言,dsh 同款):高度不随输出抖动。子代理卡与
71
+ * 思考块共用(`scroll-model.estimateLines` 里同口径)。 */
72
+ const WATERFALL_ROWS = 3;
53
73
  /**
54
74
  * 按显示宽度硬截单行:折行会破坏瀑布的恒定 3 行窗口(dsh clipLine 同款)。
55
75
  * 逐码点走,CJK/emoji 宽字符永远不会被劈成两半。
@@ -71,6 +91,61 @@ const clipLine = (text, maxWidth) => {
71
91
  };
72
92
  /** 文件路径的末段(显示用)。 */
73
93
  const baseName = (path) => path.split(/[\\/]/).pop() ?? path;
94
+ /**
95
+ * 从**尾部**硬截单行(`clipLine` 的镜像):`…` + 尽量多的后缀。
96
+ *
97
+ * 为什么要留尾:瀑布的末行是「刚吐出来的那几个字」长在行尾,留头截尾的话永远看不见
98
+ * 最新内容(dsh 的 `truncate-start` 同义)。
99
+ */
100
+ const clipLineStart = (text, maxWidth) => {
101
+ if (maxWidth <= 1)
102
+ return '';
103
+ const chars = [...text];
104
+ let width = 0;
105
+ let index = chars.length;
106
+ while (index > 0) {
107
+ const charWidth = displayWidth(chars[index - 1]);
108
+ if (width + charWidth > maxWidth - 1)
109
+ break;
110
+ width += charWidth;
111
+ index -= 1;
112
+ }
113
+ return index === 0 ? text : `…${chars.slice(index).join('')}`;
114
+ };
115
+ /**
116
+ * 思考块的**恒定 3 行瀑布窗口**(照 dsh 的 preview ticker):取正文最后 3 行——流式时
117
+ * 最新的话就在底部——每行硬截到框宽、**不折行**,所以块高与「流到哪一句 / 框多宽」都无关,
118
+ * 加字不会让整块跳一下。上面还有内容时首行前缀 `…`;末行从尾部截(新词长在行尾)。
119
+ *
120
+ * @param text - 思考正文。
121
+ * @param width - 正文可用列数(不含 `│ ` 引导)。
122
+ */
123
+ const thinkingRows = (text, width) => {
124
+ const lines = text.split('\n');
125
+ const visible = lines.slice(-WATERFALL_ROWS);
126
+ const clipped = lines.length > visible.length;
127
+ return Array.from({ length: WATERFALL_ROWS }, (_, index) => {
128
+ const raw = visible[index] ?? '';
129
+ const moreAbove = index === 0 && clipped;
130
+ const room = moreAbove ? Math.max(1, width - 1) : width;
131
+ const body = raw === '' ? '' : index === WATERFALL_ROWS - 1 ? clipLineStart(raw, room) : clipLine(raw, room);
132
+ // 引导符永远在:空行也画 `│ `,否则空字符串的 Text 高度是 0,瀑布会缺行
133
+ return `│ ${moreAbove ? '…' : ''}${body}`;
134
+ });
135
+ };
136
+ /** 瀑布正文的可用列数(页边距与缩进之外再扣掉 `│ ` 两列)。 */
137
+ const thinkingWidth = (columns) => Math.max(8, columns - PAD.page * 2 - INDENT.detail - 2);
138
+ /**
139
+ * 思考正文:展开态给全文,折叠态给恒定 3 行瀑布(宽度自己量,`Entry` 不必为此接 props)。
140
+ */
141
+ function ThinkingBody({ text, expanded }) {
142
+ const { stdout } = useStdout();
143
+ if (expanded)
144
+ return _jsx(Text, { ...TEXT.secondary, children: text });
145
+ if (text === '')
146
+ return null;
147
+ return (_jsx(_Fragment, { children: thinkingRows(text, thinkingWidth(stdout?.columns ?? 100)).map((row, index) => (_jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: row }, index))) }));
148
+ }
74
149
  /** 子代理卡的运行状态词与颜色(对照 dsh SubagentMessage 的 status())。 */
75
150
  const SUBAGENT_STATUS = {
76
151
  working: { glyph: '◐', label: '运行中', color: STATUS_COLOR.pending },
@@ -78,10 +153,7 @@ const SUBAGENT_STATUS = {
78
153
  failed: { glyph: '✗', label: '失败', color: STATUS_COLOR.failed },
79
154
  stopped: { glyph: '×', label: '已停止', color: STATUS_COLOR.failed },
80
155
  };
81
- /** 瀑布窗口恒定 3 行(Kimi Code 视觉语言,dsh 同款):高度不随输出抖动。 */
82
- const WATERFALL_ROWS = 3;
83
- /**
84
- * 子代理内联卡:跑动时 = 头行(状态点 + bold 任务 + 模型/轮数/工具数/耗时/token)
156
+ /** 子代理卡:跑动时 = 头行(状态点 + bold 任务 + 模型/轮数/工具数/耗时/token)
85
157
  * + 当前工具行 + 恒定 3 行输出瀑布(dim、`│` 引导);收工折成头行一行(失败保留
86
158
  * 一条错误行)。整卡可点,点了开队友的只读转录浮层。
87
159
  */
@@ -89,20 +161,19 @@ function SubagentCard({ sub, onOpen, registerClick, }) {
89
161
  const { stdout } = useStdout();
90
162
  const ref = useRef(null);
91
163
  const settled = sub.state !== 'working';
92
- // 跑动时头部耗时每秒跳一格(本地 setState 只重渲染这张卡);收工停表
93
- const [, setTick] = useState(0);
94
- useEffect(() => {
95
- if (settled || sub.startedAt === undefined)
96
- return;
97
- const timer = setInterval(() => setTick((current) => current + 1), 1000);
98
- return () => clearInterval(timer);
99
- }, [settled, sub.startedAt]);
164
+ // 跑动时头部耗时每秒跳一格(共享 1s 节拍;收工停表,不停着一张卡一个计时器)
165
+ useTick(SECONDS_MS, !settled && sub.startedAt !== undefined);
100
166
  const info = SUBAGENT_STATUS[sub.state];
101
167
  const clickable = onOpen !== undefined && sub.file !== undefined;
102
168
  useClickRegion(ref, clickable ? registerClick : undefined, clickable
103
169
  ? (col, row, top, height) => {
104
170
  if (row < top || row >= top + height)
105
171
  return false;
172
+ // 行对列也要对:卡片右边与刻度栏同屏时,点在刻度栏上应归刻度栏(跳轮),
173
+ // 点卡片正文才开队友转录
174
+ const span = measuredSpan(ref.current);
175
+ if (span === null || col < span.left || col >= span.left + span.width)
176
+ return false;
106
177
  onOpen(sub.file);
107
178
  return true;
108
179
  }
@@ -121,6 +192,32 @@ function SubagentCard({ sub, onOpen, registerClick, }) {
121
192
  function CompactionRule({ count }) {
122
193
  return (_jsxs(Text, { ...TEXT.label, color: ACCENT, children: ["\u23AF \u5DF2\u538B\u7F29\u5386\u53F2 \u00B7 \u7B2C ", count, " \u6B21 \u23AF"] }));
123
194
  }
195
+ /**
196
+ * 滚离尾部时**浮在视口第一行**上的那一行(照 dsh 的 `PinnedTurnHeader`):**当前轮的题面**。
197
+ *
198
+ * 往上读的时候,屏幕上永远有一行告诉你「现在读的是哪一轮」——长会话里最贵的认知负担
199
+ * 就是这个;点它跳回本轮题面(dsh 同语义)。
200
+ *
201
+ * 硬性只占一行、**且不挤掉内容行**(它由 TranscriptViewport 用零高容器 + 负 margin 浮上去,
202
+ * 见那边 `pinned` 的注释):挤掉一行会改内容坐标(同样格数滚回来差一行到不了底)与刻度栏
203
+ * 位置。所以这里把文本**补齐到满宽**——浮层要盖住下面那一行,只画 `❯ …` 几个字符的话
204
+ * 后半行会露出底下的正文。
205
+ */
206
+ function PinnedTurn({ text, turn, width, onPick, registerClick, }) {
207
+ const ref = useRef(null);
208
+ useClickRegion(ref, registerClick, (col, row, top, height) => {
209
+ if (row < top || row >= top + height)
210
+ return false;
211
+ // 行对列也要对(钉住行只占正文那几列):点在右侧刻度栏上不该被它吃掉
212
+ const span = measuredSpan(ref.current);
213
+ if (span === null || col < span.left || col >= span.left + span.width)
214
+ return false;
215
+ onPick(turn);
216
+ return true;
217
+ });
218
+ const label = clipLine(`❯ ${text}`, width);
219
+ return (_jsx(Box, { ref: ref, height: 1, flexShrink: 0, overflow: "hidden", children: _jsx(Text, { color: PALETTE.userPrompt, bold: true, wrap: "truncate-end", children: label.padEnd(Math.max(0, width), ' ') }) }));
220
+ }
124
221
  /** 用户消息的图片行:整行可点,点了开半块真彩预览(没有回调时退化为纯说明)。 */
125
222
  function ImageLine({ count, onPreview, registerClick, }) {
126
223
  const ref = useRef(null);
@@ -134,8 +231,14 @@ function ImageLine({ count, onPreview, registerClick, }) {
134
231
  });
135
232
  return (_jsx(Box, { ref: ref, marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, color: onPreview === undefined ? undefined : ACCENT, children: ["\uD83D\uDDBC ", count, " \u5F20\u56FE\u7247", onPreview === undefined ? '' : ' · 点击预览'] }) }));
136
233
  }
137
- /** 单条条目的渲染(回看浮层复用同一份,直播光标由 streaming 控制)。 */
138
- export function Entry({ entry, streaming, expandThinking, onPreviewImages, onOpenAgent, registerClick, }) {
234
+ /**
235
+ * 单条条目的渲染(回看浮层复用同一份,直播光标由 streaming 控制)。
236
+ *
237
+ * `memo` 是救命的:定稿条目在 `transcript.entries` 里是**同一个对象引用**,而快照
238
+ * 每次重建都会换掉直播尾——没有 memo 时每个增量都要把窗口里 80 条全部重渲染一遍。
239
+ * 前提是 props 里没有每帧新建的值(回调在 App 侧已 `useCallback`,见 handleOpenAgent)。
240
+ */
241
+ export const Entry = memo(function Entry({ entry, streaming, expandThinking, expandedTools, onToggleTool, onPreviewImages, onOpenAgent, registerClick, }) {
139
242
  switch (entry.kind) {
140
243
  case 'user':
141
244
  // 运行时投进来的消息(队友干完活的 <teammate-report> 汇报):不是人打的字,
@@ -144,17 +247,18 @@ export function Entry({ entry, streaming, expandThinking, onPreviewImages, onOpe
144
247
  if (entry.internal === true) {
145
248
  return _jsx(Text, { ...TEXT.secondary, children: "\u2338 \u5B50\u4EFB\u52A1\u72B6\u6001\u66F4\u65B0" });
146
249
  }
147
- return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, children: [entry.compaction !== undefined ? _jsx(CompactionRule, { count: entry.compaction.count }) : null, _jsxs(Box, { children: [_jsxs(Text, { color: PALETTE.userPrompt, bold: true, children: ["\u276F", entry.steering === true ? ' ↩' : '', ' '] }), _jsx(Text, { color: PALETTE.userPrompt, bold: true, children: entry.text })] }), entry.images !== undefined && entry.images.length > 0 ? (_jsx(ImageLine, { count: entry.images.length, onPreview: onPreviewImages === undefined ? undefined : () => onPreviewImages(entry.images ?? []), registerClick: registerClick })) : null] }));
250
+ return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, marginTop: USER_TOP_GAP, children: [entry.compaction !== undefined ? _jsx(CompactionRule, { count: entry.compaction.count }) : null, _jsxs(Box, { children: [_jsxs(Text, { color: PALETTE.userPrompt, bold: true, children: ["\u276F", entry.steering === true ? ' ↩' : '', ' '] }), _jsx(Text, { color: PALETTE.userPrompt, bold: true, children: entry.text })] }), entry.images !== undefined && entry.images.length > 0 ? (_jsx(ImageLine, { count: entry.images.length, onPreview: onPreviewImages === undefined ? undefined : () => onPreviewImages(entry.images ?? []), registerClick: registerClick })) : null] }));
148
251
  case 'thinking': {
149
- // 标签与内容分行(0.6.57);0.6.59 对齐 dsh:⚓ + 整行斜体,流式时盲文 spinner;
150
- // 0.6.60 补时长(≥1s 才显示 · Ns,重放老日志没有这一项就自然不显示)。
252
+ // 标签与内容分行(0.6.57);0.6.59 对齐 dsh:⚓ + 斜体标签,流式时盲文 spinner;
253
+ // 0.6.60 补时长(≥1s 才显示 · Ns,重放老日志没有这一项就自然不显示);
254
+ // 本批把折叠态从「压成一行的 100 字预览」换成 dsh 的**恒定 3 行瀑布**(见 thinkingRows)。
151
255
  const seconds = entry.durationMs === undefined ? '' : fmtSeconds(entry.durationMs);
152
- return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, children: [_jsxs(Text, { italic: true, ...TEXT.secondary, children: [streaming ? _jsx(BrailleSpinner, {}) : _jsx(Text, { color: STATUS_COLOR.pending, children: "\u2693" }), ' ', streaming ? '思考中' : '思考', seconds === '' ? '' : ` · ${seconds}`, expandThinking ? '' : '(ctrl+t 展开)'] }), _jsx(Box, { marginLeft: INDENT.detail, children: _jsx(Text, { ...TEXT.secondary, italic: true, children: expandThinking ? entry.text : oneLine(entry.text, 100) }) })] }));
256
+ return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, children: [_jsxs(Text, { italic: true, ...TEXT.secondary, children: [streaming ? _jsx(BrailleSpinner, { pulse: true }) : _jsx(Text, { color: STATUS_COLOR.pending, children: "\u2693" }), ' ', streaming ? '思考中' : '思考', seconds === '' ? '' : ` · ${seconds}`, expandThinking ? '' : HINT.thinkingExpand] }), _jsx(Box, { marginLeft: INDENT.detail, flexDirection: "column", children: _jsx(ThinkingBody, { text: entry.text, expanded: expandThinking }) })] }));
153
257
  }
154
258
  case 'text':
155
259
  return (_jsx(Box, { children: _jsx(MarkdownView, { source: entry.text, cursor: streaming }) }));
156
260
  case 'tool':
157
- return _jsx(ToolCard, { call: entry.call });
261
+ return (_jsx(ToolCard, { call: entry.call, expanded: expandedTools?.has(entry.id) === true, ...(onToggleTool === undefined ? {} : { onToggle: () => onToggleTool(entry.id) }), registerClick: registerClick }));
158
262
  case 'subagent':
159
263
  return _jsx(SubagentCard, { sub: entry.sub, onOpen: onOpenAgent, registerClick: registerClick });
160
264
  case 'plan': {
@@ -187,12 +291,20 @@ export function Entry({ entry, streaming, expandThinking, onPreviewImages, onOpe
187
291
  default:
188
292
  return null;
189
293
  }
190
- }
191
- export function ChatView({ entries, turnState, expandThinking, empty, header, onPreviewImages, onOpenAgent, registerClick, }) {
192
- const tail = entries;
294
+ });
295
+ export function ChatView({ entries, turnState, expandThinking, empty, welcome, maxWidth, columns, railCenterLines, expandedTools, onToggleTool, onPreviewImages, onOpenAgent, onPickTurn, registerClick, viewportRef, onAtTailChange, }) {
193
296
  // 直播尾(负 id)与最后定稿 text 条目才带光标闪烁位。
194
- const lastId = tail[tail.length - 1]?.id;
195
- return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, gap: GAP.tight, children: [header, tail.map((entry) => (_jsx(Entry, { entry: entry, streaming: entry.id === lastId &&
196
- entry.id < 0 &&
197
- (turnState === 'thinking' || turnState === 'working'), expandThinking: expandThinking, onPreviewImages: onPreviewImages, onOpenAgent: onOpenAgent, registerClick: registerClick }, entry.id))), empty ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsx(Text, { ...TEXT.secondary, children: "\u8F93\u5165\u6D88\u606F\u5F00\u59CB\u5BF9\u8BDD\uFF1B/help \u67E5\u770B\u547D\u4EE4\uFF0CEsc \u6253\u65AD\u56DE\u5408\uFF0CCtrl+O \u56DE\u770B\u5168\u6587\u3002" }) })) : null] }));
297
+ const lastId = entries[entries.length - 1]?.id;
298
+ // 流头部(欢迎页 + 一句开场提示)当流里的第一块,跟着内容一起滚
299
+ const leading = welcome === undefined && !empty ? undefined : (_jsxs(_Fragment, { children: [welcome, empty ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsx(Text, { ...TEXT.secondary, children: HINT.empty }) })) : null] }));
300
+ return (_jsx(TranscriptViewport, { ref: viewportRef, entries: entries, maxWidth: maxWidth, columns: columns, ...(railCenterLines === undefined ? {} : { railCenterLines }), showRail: true, expandThinking: expandThinking, registerClick: registerClick, onAtTailChange: onAtTailChange, emptyHint: HINT.empty,
301
+ // 滚离尾部时浮住当前轮的题面(视口把「当前轮」与正文列宽算好给进来,见 TranscriptViewport 的 `pinned`)
302
+ pinned: (active, _layout, width) => {
303
+ if (onPickTurn === undefined)
304
+ return null;
305
+ const source = entries.find((item) => item.id === active.id);
306
+ if (source === undefined || source.kind !== 'user')
307
+ return null;
308
+ return (_jsx(PinnedTurn, { text: oneLine(source.text, 240), turn: active.index, width: width, onPick: onPickTurn, registerClick: registerClick }));
309
+ }, renderEntry: (entry) => (_jsx(Entry, { entry: entry, streaming: entry.id === lastId && entry.id < 0 && (turnState === 'thinking' || turnState === 'working'), expandThinking: expandThinking, expandedTools: expandedTools, onToggleTool: onToggleTool, onPreviewImages: onPreviewImages, onOpenAgent: onOpenAgent, registerClick: registerClick })), ...(leading === undefined ? {} : { leading }) }));
198
310
  }
@@ -1,19 +1,18 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  /**
3
- * 底部状态栏(0.6.59 对齐 dsh StatusLine 的规格,0.6.60 分段条与费用):固定两行、无框。
3
+ * 底部状态栏(0.6.59 对齐 dsh StatusLine 的规格):**一行**、无框。
4
4
  *
5
- * 第一行是 **context 分段进度条**——占用段按内容类型着色(system/prompt/assistant/
6
- * thinking/tools,dsh 蓝系谱;估算分段,见 core/token-estimate),空闲段右侧读数
7
- * `10k/1.0M 1.0%`。读数的分子是**最近一次请求的 prompt_tokens**(权威占用;usage
8
- * 累计是多轮计费和,会把滚出窗口的内容也算进去),≥80% 琥珀、≥95% 红。
5
+ * 段间 ` · ` 暗淡分隔(theme 的 SEP.dot),左右两组 space-between;后台芯片可点,
6
+ * 直达转录。段显隐走 prefs.ui.statusBar(设置 → 终端界面 → 状态栏,0.6.62),
7
+ * 开关与数据双条件、缺一整段缺席;总宽超出预算时按 priority **整段丢弃**(对齐 dsh
8
+ * 的「段缺席优于段截断」——旧版全靠 ink 的 flex 等比压缩,宽终端一挤就段段变
9
+ * `xxx...`),可丢的全丢光仍放不下才让 cwd/model 收缩截断。≈¥ 只在 DeepSeek 官方
10
+ * 端点且模型有价目时出现(峰谷按北京时段分桶估算)。行数恒定是选择器几何的组成部分。
9
11
  *
10
- * 第二行是状态字段行:段间 ` · ` 暗淡分隔(theme 的 SEP.dot),左右两组
11
- * space-between;后台芯片可点,直达转录。段显隐走 prefs.ui.statusBar(设置 →
12
- * 终端界面 → 状态栏,0.6.62),开关与数据双条件、缺一整段缺席;总宽超出预算时
13
- * 按 priority **整段丢弃**(对齐 dsh 的「段缺席优于段截断」——旧版全靠 ink 的
14
- * flex 等比压缩,宽终端一挤就段段变 `xxx...`),可丢的全丢光仍放不下才让
15
- * cwd/model 收缩截断。≈¥ 只在 DeepSeek 官方端点且模型有价目时出现(峰谷按
16
- * 北京时段分桶估算)。行数恒定是选择器几何的组成部分。
12
+ * 曾经还有第二行「context 分段进度条」(整幅蓝条 + `25k/512k 4.9%` 读数):那一条
13
+ * 每帧占一行、横跨整幅,把本来就紧的正文又压掉一行,而它给的信息在 `ctx 4.9%` 这个
14
+ * 字段里已经有了——用户明确要求去掉。压力提示没丢:占用 ≥80% 琥珀、≥95% 红,染在
15
+ * `ctx` 这个字段上(见下面 `right` 的装配)。
17
16
  *
18
17
  * @module dsc-tui/app/StatusBar
19
18
  */
@@ -21,7 +20,7 @@ import { useRef } from 'react';
21
20
  import { Box, Text, useStdout } from 'ink';
22
21
  import { measuredSpan, useClickRegion } from './click.js';
23
22
  import { displayWidth } from './markdown.js';
24
- import { CONTEXT_SEGMENTS, GAP, PAD, PALETTE, SEP, STATUS_COLOR, TEXT } from './theme.js';
23
+ import { PAD, PALETTE, SEP, STATUS_COLOR, TEXT } from './theme.js';
25
24
  /** 回合状态词:中文硬编码,本项目不做 i18n。 */
26
25
  const TURN_LABEL = {
27
26
  idle: '空闲',
@@ -103,82 +102,6 @@ function BackgroundChip({ sessionPath, state, onOpen, registerClick, }) {
103
102
  });
104
103
  return (_jsx(Box, { ref: ref, flexShrink: 0, children: _jsxs(Text, { ...TEXT.label, color: dot.color, wrap: "truncate-end", children: [dot.mark, " ", shortId(sessionPath)] }) }));
105
104
  }
106
- /** 全零分段(快照缺字段时的兜底:老 mock / 旧版本快照没有 contextSegments 也不许炸)。 */
107
- const EMPTY_SEGMENTS = {
108
- system: 0,
109
- prompt: 0,
110
- assistant: 0,
111
- thinking: 0,
112
- tools: 0,
113
- };
114
- /**
115
- * context 分段进度条(dsh renderContextBar 的 JSX 版):占用段各一块纯色
116
- * (childless Box——渲染器按自身矩形填背景色),空闲段深底、右缘挂读数。
117
- * 列宽分配 = largest-remainder + 每个可见段至少 1 列(dsh allocateBarColumns 同款)。
118
- */
119
- function ContextBar({ status }) {
120
- const { stdout } = useStdout();
121
- const width = Math.max(10, (stdout?.columns ?? 100) - PAD.page * 2);
122
- const window = status.contextWindow;
123
- const used = window > 0 ? Math.min(status.contextUsed ?? 0, window) : 0;
124
- const ratio = window > 0 ? used / window : 0;
125
- const pctText = window > 0 ? `${(ratio * 100).toFixed(1)}%` : '--%';
126
- // 读数阶梯(dsh contextBarReadout):全形式放不下就退到只剩百分比
127
- const fullReadout = `${fmtTokens(used)}/${window > 0 ? fmtTokens(window) : '--'} ${pctText}`;
128
- const readout = width - displayWidth(fullReadout) >= 2 ? fullReadout : pctText;
129
- const readoutWidth = displayWidth(readout);
130
- // 分段列宽:空闲段 = 窗口 − 权威占用(不是分段之和——分段是估算,只管颜色组成)。
131
- // 窗口未知(0)时整条画成空闲段:状态栏行数是恒定几何,条不能塌成 0 行。
132
- const free = window > 0 ? Math.max(0, window - used) : width;
133
- const segments = status.contextSegments ?? EMPTY_SEGMENTS;
134
- const values = [...CONTEXT_SEGMENTS.map((segment) => segments[segment.key] ?? 0), free];
135
- const columns = allocateBarColumns(values, width);
136
- const nodes = [];
137
- for (const [index, segment] of CONTEXT_SEGMENTS.entries()) {
138
- const segmentWidth = columns[index] ?? 0;
139
- if (segmentWidth <= 0)
140
- continue;
141
- nodes.push(_jsx(Box, { width: segmentWidth, height: 1, flexShrink: 0, backgroundColor: segment.color }, segment.key));
142
- }
143
- const freeWidth = columns[CONTEXT_SEGMENTS.length] ?? 0;
144
- if (freeWidth > 0) {
145
- // 读数永远贴条右缘;压力阈值染读数(空闲段底色不动)
146
- const pressure = ratio >= 0.95 ? PALETTE.error : ratio >= 0.8 ? PALETTE.warning : undefined;
147
- nodes.push(_jsx(Box, { width: freeWidth, height: 1, flexShrink: 0, backgroundColor: PALETTE.surface, children: _jsxs(Text, { color: pressure ?? undefined, dimColor: pressure === undefined, wrap: "truncate-end", children: [' '.repeat(Math.max(0, freeWidth - readoutWidth)), readout] }) }, "free"));
148
- }
149
- return (_jsx(Box, { flexDirection: "row", flexShrink: 0, children: nodes }));
150
- }
151
- /** largest-remainder 列宽分配(dsh StatusMetrics 同款):可见段先各保 1 列,其余按比例分。 */
152
- function allocateBarColumns(values, width) {
153
- const allocate = (columns) => {
154
- if (columns <= 0)
155
- return values.map(() => 0);
156
- const total = values.reduce((sum, value) => sum + value, 0);
157
- if (total <= 0)
158
- return values.map(() => 0);
159
- const raw = values.map((value) => (value / total) * columns);
160
- const floored = raw.map(Math.floor);
161
- let remaining = columns - floored.reduce((sum, value) => sum + value, 0);
162
- const byRemainder = raw
163
- .map((value, index) => ({ index, remainder: value - Math.floor(value) }))
164
- .sort((left, right) => right.remainder - left.remainder);
165
- for (const slot of byRemainder) {
166
- if (remaining <= 0)
167
- break;
168
- floored[slot.index] = (floored[slot.index] ?? 0) + 1;
169
- remaining -= 1;
170
- }
171
- return floored;
172
- };
173
- const visible = values.map((value, index) => (value > 0 ? index : -1)).filter((index) => index >= 0);
174
- if (visible.length === 0 || visible.length >= width)
175
- return allocate(width);
176
- const minimum = values.map(() => 0);
177
- for (const index of visible)
178
- minimum[index] = 1;
179
- const rest = allocate(width - visible.length);
180
- return minimum.map((min, index) => min + (rest[index] ?? 0));
181
- }
182
105
  export function StatusBar({ status, surfaces, subagents, queued, config, onOpenAgent, registerClick, }) {
183
106
  const { stdout } = useStdout();
184
107
  const modeLabel = surfaces.mode.options.find((option) => option.id === surfaces.mode.current)?.label ??
@@ -192,7 +115,11 @@ export function StatusBar({ status, surfaces, subagents, queued, config, onOpenA
192
115
  const cacheHit = usage?.cacheHitTokens ?? 0;
193
116
  const cacheMiss = usage?.cacheMissTokens ?? 0;
194
117
  const cacheTotal = cacheHit + cacheMiss;
195
- const ctxPct = status.contextWindow > 0 ? `${((status.contextUsed / status.contextWindow) * 100).toFixed(1)}%` : '--%';
118
+ const ctxPct = status.contextWindow > 0 ? `${((status.contextUsed ?? 0) / status.contextWindow * 100).toFixed(1)}%` : '--%';
119
+ // 上下文压力的提醒:原来染在进度条读数上,条去掉后落到 `ctx` 这一段(≥80% 琥珀、
120
+ // ≥95% 红)。读数仍然是「最近一次请求的 prompt_tokens / 窗口」的比值。
121
+ const ctxRatio = status.contextWindow > 0 ? (status.contextUsed ?? 0) / status.contextWindow : 0;
122
+ const ctxColor = ctxRatio >= 0.95 ? PALETTE.error : ctxRatio >= 0.8 ? PALETTE.warning : undefined;
196
123
  // 段装配:开关(config)与数据(usage/cost/cwd)双条件,缺一整段缺席。
197
124
  // priority 只排「谁先被丢」,与左右组内的显示顺序无关。
198
125
  const left = [
@@ -239,7 +166,7 @@ export function StatusBar({ status, surfaces, subagents, queued, config, onOpenA
239
166
  left.push({ kind: 'text', id: 'policy', text: `权限 ${policyLabel}${reviewerSuffix}`, tone: 'secondary', priority: 7 });
240
167
  const right = [];
241
168
  if (config.ctx)
242
- right.push({ kind: 'text', id: 'ctx', text: `ctx ${ctxPct}`, tone: 'secondary', priority: 6 });
169
+ right.push({ kind: 'text', id: 'ctx', text: `ctx ${ctxPct}`, tone: 'secondary', priority: 6, ...(ctxColor === undefined ? {} : { color: ctxColor }) });
243
170
  if (config.cwd && status.cwd !== undefined && status.cwd !== '')
244
171
  right.push({ kind: 'text', id: 'cwd', text: shortCwd(status.cwd), tone: 'secondary', priority: 9 });
245
172
  if (config.session)
@@ -268,5 +195,7 @@ export function StatusBar({ status, surfaces, subagents, queued, config, onOpenA
268
195
  const flexible = (segment) => shrink && segment.kind === 'text' && (segment.id === 'cwd' || segment.id === 'model');
269
196
  /** 一组段 → 带 ` · ` 分隔的节点序列;分隔钉死不缩,可缩的只有 cwd/model。 */
270
197
  const renderGroup = (segments) => segments.map((segment, index) => (_jsxs(Box, { flexShrink: flexible(segment) ? 1 : 0, children: [index > 0 ? (_jsx(Box, { flexShrink: 0, children: _jsx(Text, { ...TEXT.secondary, children: SEP.dot }) })) : null, segment.kind === 'chip' ? (_jsx(BackgroundChip, { sessionPath: segment.sessionPath, state: segment.state, onOpen: onOpenAgent === undefined ? () => { } : onOpenAgent, registerClick: onOpenAgent === undefined ? undefined : registerClick })) : (_jsx(Text, { ...(segment.tone === 'label' ? TEXT.label : TEXT.secondary), color: segment.color, wrap: "truncate-end", children: segment.text }))] }, segment.id)));
271
- return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, children: [_jsx(ContextBar, { status: status }), _jsxs(Box, { justifyContent: "space-between", children: [_jsx(Box, { children: renderGroup(fitted.left) }), _jsx(Box, { children: renderGroup(fitted.right) })] })] }));
198
+ return (
199
+ // 一行定高:条数恒定是选择器/视口几何的组成部分(`App` 的 statusbarLines 按 1 算)
200
+ _jsxs(Box, { justifyContent: "space-between", children: [_jsx(Box, { children: renderGroup(fitted.left) }), _jsx(Box, { children: renderGroup(fitted.right) })] }));
272
201
  }
@@ -0,0 +1,22 @@
1
+ import type { JSX } from 'react';
2
+ import { type RegisterClick } from './click.js';
3
+ import { type RailGeometry } from './scroll-model.js';
4
+ /** 列里的一段:一行有字符(行号在几何里一一对应),或一段连续的空档。 */
5
+ export type RailSegment = {
6
+ kind: 'row';
7
+ row: number;
8
+ } | {
9
+ kind: 'gap';
10
+ rows: number;
11
+ };
12
+ /** 把「逐行有/无内容」压成段序列:空档给固定高度,渲染时一行字符 = 几何里的一行。 */
13
+ export declare function segments(rows: Array<unknown | null>): RailSegment[];
14
+ export declare function TimelineRail({ geometry, registerClick, onPickTurn, turnText, }: {
15
+ /** 每一行画什么(`scroll-model` 的 `railGeometry`)。 */
16
+ geometry: RailGeometry;
17
+ registerClick?: RegisterClick;
18
+ /** 点了某一轮的刻度,或点了某一头的箭头(箭头直接给几何名下那一轮)。 */
19
+ onPickTurn: (turn: number) => void;
20
+ /** 读数条上的题面预览(刻度 → 该轮题面首行;省略 = 只报轮号)。 */
21
+ turnText?: (turn: number) => string | null;
22
+ }): JSX.Element;