@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
@@ -0,0 +1,160 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * 右侧那一列:**轮数刻度**(照 dsh-TUI 的 TimelineRail)。
4
+ *
5
+ * - 一轮一格,当前视口所在的那一轮画 `━━`、其余画 ` ─`,▲ + 刻度 + ▼ 这一块在列里
6
+ * **纵向居中**,两头箭头永远画(没有目标就暗色——位置固定,视线不用每帧重找)。
7
+ * 照 dsh 的门槛:窄于 60 列、不到两轮、一屏装得下都不画。
8
+ *
9
+ * 整列**一次命中判定**(`row - top` 换算成列内行号),不在每行挂命中区;空档一律用
10
+ * **固定高度的 spacer**——拿只含空格的 `Text` 当空行会被 yoga 压扁,整列跟着错位
11
+ * (实测 16 行的列只画出 9 行、箭头落到中段)。颜色走既有调色板,不硬编码。
12
+ *
13
+ * **悬停**(对齐 dsh):指针停在刻度列上时该行提亮一档;停住约 250ms 弹出
14
+ * 一枚单行读数条(`第 N 轮 · 题面`),点下去跳哪儿与读数完全一致。三条实现约束:
15
+ *
16
+ * 1. 读数条是 `position="absolute"` 的子节点:**不占布局**(不弹出来就不影响任何行高),
17
+ * ink 6.8 的 Box 没有 `top`/`right`,绝对子节点落在**父节点的原点**上,所以它挂在
18
+ * 悬停那一行的行盒里,再用**负 `marginLeft`** 顶到刻度列左边(实测:负 margin 认,
19
+ * 但绝对子节点**不认**父节点的流式位置——放在列容器里会跑到列首,这也是它必须挂在
20
+ * 行盒里的原因)。
21
+ * 2. 指针位置只走 `pointer` 那个小 store,且**值没变不通知**(列判定在 store 里做)——
22
+ * 鼠标划过屏幕其余地方,这个组件一次都不会重渲染。
23
+ * 3. 拖动 = 「从刻度列上按住左键划过」:拖动会话由 App 在**按下**时开在这个区上
24
+ * (见 `App.dispatchMouseDrag`),划过是一条连续 scrub,与点击同一条映射(dsh 同款)。
25
+ *
26
+ * @module dsc-tui/app/TimelineRail
27
+ */
28
+ import { Box, Text } from 'ink';
29
+ import { useEffect, useRef, useState } from 'react';
30
+ import { absoluteTop, displayWidth, measuredSpan, useClickRegion } from './click.js';
31
+ import { useGutterPointer } from './pointer.js';
32
+ import { railHitRow, RAIL_GLYPH, RAIL_WIDTH, } from './scroll-model.js';
33
+ import { PALETTE, RAIL_COLOR } from './theme.js';
34
+ /** 悬停多久弹读数条(对齐 dsh 的 dwell 闸:扫过不弹,停住才弹)。 */
35
+ const CHIP_DWELL_MS = 250;
36
+ /** 把「逐行有/无内容」压成段序列:空档给固定高度,渲染时一行字符 = 几何里的一行。 */
37
+ export function segments(rows) {
38
+ const output = [];
39
+ for (let row = 0; row < rows.length; row += 1) {
40
+ const value = rows[row];
41
+ if (value === null || value === undefined) {
42
+ const last = output[output.length - 1];
43
+ if (last !== undefined && last.kind === 'gap')
44
+ last.rows += 1;
45
+ else
46
+ output.push({ kind: 'gap', rows: 1 });
47
+ continue;
48
+ }
49
+ output.push({ kind: 'row', row });
50
+ }
51
+ return output;
52
+ }
53
+ /** 按显示宽度硬截(读数条宽度要自己算:绝对子节点的盒宽不能靠 yoga 量)。 */
54
+ function clip(text, maxWidth) {
55
+ let width = 0;
56
+ let index = 0;
57
+ while (index < text.length) {
58
+ const char = String.fromCodePoint(text.codePointAt(index) ?? 0);
59
+ const next = width + displayWidth(char);
60
+ if (next > maxWidth)
61
+ return `${text.slice(0, index)}…`;
62
+ width = next;
63
+ index += char.length;
64
+ }
65
+ return text;
66
+ }
67
+ /** 刻度栏某一行画什么字符。 */
68
+ function glyphOf(entry) {
69
+ if (entry.kind === 'up')
70
+ return RAIL_GLYPH.up;
71
+ if (entry.kind === 'down')
72
+ return RAIL_GLYPH.down;
73
+ return entry.active ? RAIL_GLYPH.active : RAIL_GLYPH.idle;
74
+ }
75
+ /** 刻度栏某一行什么颜色(箭头分「有目标可点 / 没目标」两档)。 */
76
+ function colorOf(entry, hovered) {
77
+ if (entry.kind === 'up' || entry.kind === 'down') {
78
+ return entry.enabled ? RAIL_COLOR.arrow : RAIL_COLOR.arrowOff;
79
+ }
80
+ if (hovered)
81
+ return RAIL_COLOR.active;
82
+ return entry.active ? RAIL_COLOR.active : RAIL_COLOR.idle;
83
+ }
84
+ /**
85
+ * 悬浮读数条:单行、暗底、宽度自己算,用负 `marginLeft` 从行盒(= 刻度列)向左顶出去。
86
+ * 绝对定位 → 不占布局;行盒只有两列宽,所以宽度必须是显式的(否则文字会按 2 列折行)。
87
+ */
88
+ function HoverChip({ label }) {
89
+ const width = displayWidth(label) + 2;
90
+ return (_jsx(Box, { position: "absolute", height: 1, width: width, marginLeft: -(width + 1), backgroundColor: PALETTE.surface, children: _jsx(Text, { color: PALETTE.surfaceText, wrap: "truncate-end", children: ` ${label} ` }) }));
91
+ }
92
+ /** 指针在刻度列上的第几行(列内 0 基);不在列上/量不到几何 = null。 */
93
+ function useHoverRow(ref, rows) {
94
+ const pointerRow = useGutterPointer();
95
+ const top = absoluteTop(ref.current);
96
+ if (pointerRow === null || top === null)
97
+ return null;
98
+ const local = pointerRow - 1 - top;
99
+ return local >= 0 && local < rows ? local : null;
100
+ }
101
+ /** 停住才弹、弹出来就跟着走(原样照 dsh 的 dwell 语义)。 */
102
+ function useChipRow(hovered) {
103
+ const [chipRow, setChipRow] = useState(null);
104
+ useEffect(() => {
105
+ if (hovered === null) {
106
+ setChipRow(null);
107
+ return;
108
+ }
109
+ if (chipRow === hovered)
110
+ return;
111
+ if (chipRow !== null) {
112
+ setChipRow(hovered);
113
+ return;
114
+ }
115
+ const timer = setTimeout(() => setChipRow(hovered), CHIP_DWELL_MS);
116
+ return () => clearTimeout(timer);
117
+ }, [hovered, chipRow]);
118
+ return chipRow;
119
+ }
120
+ /** 一行的行盒:`height={1}` + 不收缩——读数条按行盒的原点定位,压扁一行整块就错位。 */
121
+ function RailLine({ children, color, chip }) {
122
+ return (_jsxs(Box, { height: 1, flexShrink: 0, children: [_jsx(Text, { color: color, children: children }), chip] }));
123
+ }
124
+ export function TimelineRail({ geometry, registerClick, onPickTurn, turnText, }) {
125
+ const ref = useRef(null);
126
+ const hovered = useHoverRow(ref, geometry.rows.length);
127
+ const chipRow = useChipRow(hovered);
128
+ useClickRegion(ref, registerClick, (col, row, top, height) => {
129
+ if (row < top || row >= top + height)
130
+ return false;
131
+ // 列也要对得上:整块只占最右两列(页边距之内)。上一版只判行,于是正文里点一下
132
+ // 也会跳到某一轮(用户报障:「左键点任意位置都被当成点滚动条」)。
133
+ const span = measuredSpan(ref.current);
134
+ if (span === null || col < span.left || col >= span.left + span.width)
135
+ return false;
136
+ const hit = railHitRow(geometry, row - top);
137
+ if (hit === null)
138
+ return false;
139
+ if (hit === 'up' || hit === 'down') {
140
+ // 暗箭头(没有目标)点了什么也不做——「画得出 = 点得中,暗 = 保证的空操作」
141
+ const target = hit === 'up' ? geometry.up : geometry.down;
142
+ if (target !== null)
143
+ onPickTurn(target);
144
+ return true;
145
+ }
146
+ onPickTurn(hit);
147
+ return true;
148
+ },
149
+ // 认拖动:按住左键划过刻度列 = 一路跳(scrub),与点击同一条映射
150
+ { drag: true });
151
+ return (_jsx(Box, { ref: ref, width: RAIL_WIDTH, flexShrink: 0, flexDirection: "column", children: segments(geometry.rows).map((segment, index) => segment.kind === 'gap' ? (_jsx(Box, { height: segment.rows, flexShrink: 0 }, `gap-${index}`)) : (_jsx(RailLine, { color: colorOf(geometry.rows[segment.row], hovered === segment.row), chip: chipRow === segment.row ? _jsx(HoverChip, { label: tickLabel(geometry.rows[segment.row], turnText) }) : null, children: glyphOf(geometry.rows[segment.row]) }, `row-${segment.row}`))) }));
152
+ }
153
+ /** 刻度那行的读数条文案:`第 N 轮 · 题面预览`(没有预览就只报轮号)。 */
154
+ function tickLabel(entry, turnText) {
155
+ if (entry.kind !== 'tick')
156
+ return '';
157
+ const head = `第 ${entry.turn + 1} 轮`;
158
+ const text = turnText?.(entry.turn) ?? null;
159
+ return text === null || text === '' ? head : `${head} · ${clip(text, 24)}`;
160
+ }
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * 右侧那一列(照 dsh-TUI 的 gutter):**轮数刻度**为主,轮数不够时退成**比例滚动条**。
4
+ *
5
+ * - `TimelineRail`:一轮一格,当前视口所在的那一轮画 `━━`、其余 ` ─`,▲ + 刻度 + ▼ 这一
6
+ * 块在列里**纵向居中**,两头箭头永远画(没有目标就暗色——位置固定,视线不用每帧重找)。
7
+ * 照 dsh 的门槛:窄于 60 列、不到两轮、一屏装得下都不画。
8
+ * - `ScrollbarGutter`:轮数不够(agent 团队的会话经常是「一条长任务 + 一堆队友汇报」,
9
+ * 真人消息只有一条)但内容装不下时画比例滑块——至少「我在哪儿、还有多少」看得见,
10
+ * 点轨道任意一行直接跳到那儿(用户报障:那种会话右边空空如也)。只画滑块不画轨道。
11
+ *
12
+ * 两处都**整列一次命中判定**(`row - top` 换算成列内行号),不在每行挂命中区;空档一律用
13
+ * **固定高度的 spacer**——拿只含空格的 `Text` 当空行会被 yoga 压扁,整列跟着错位
14
+ * (实测 16 行的列只画出 9 行、箭头落到中段)。颜色走既有调色板,不硬编码。
15
+ *
16
+ * @module dsc-tui/app/TimelineRail
17
+ */
18
+ import { Box, Text } from 'ink';
19
+ import { useRef } from 'react';
20
+ import { useClickRegion } from './click.js';
21
+ import { railHitRow, RAIL_GLYPH, RAIL_WIDTH } from './scroll-model.js';
22
+ import { RAIL_COLOR } from './theme.js';
23
+ /** 把「逐行有/无内容」压成段序列:空档给固定高度,渲染时一行字符 = 几何里的一行。 */
24
+ export function segments(rows) {
25
+ const output = [];
26
+ for (let row = 0; row < rows.length; row += 1) {
27
+ const value = rows[row];
28
+ if (value === null || value === undefined) {
29
+ const last = output[output.length - 1];
30
+ if (last !== undefined && last.kind === 'gap')
31
+ last.rows += 1;
32
+ else
33
+ output.push({ kind: 'gap', rows: 1 });
34
+ continue;
35
+ }
36
+ output.push({ kind: 'row', row });
37
+ }
38
+ return output;
39
+ }
40
+ /** 刻度栏某一行画什么字符。 */
41
+ function glyphOf(entry) {
42
+ if (entry.kind === 'up')
43
+ return RAIL_GLYPH.up;
44
+ if (entry.kind === 'down')
45
+ return RAIL_GLYPH.down;
46
+ return entry.active ? RAIL_GLYPH.active : RAIL_GLYPH.idle;
47
+ }
48
+ /** 刻度栏某一行什么颜色(箭头分「有目标可点 / 没目标」两档)。 */
49
+ function colorOf(entry) {
50
+ if (entry.kind === 'up' || entry.kind === 'down') {
51
+ return entry.enabled ? RAIL_COLOR.arrow : RAIL_COLOR.arrowOff;
52
+ }
53
+ return entry.active ? RAIL_COLOR.active : RAIL_COLOR.idle;
54
+ }
55
+ /**
56
+ * 一行字形:`height={1}` + 不收缩——刻度栏的「第几行」必须与几何逐行对齐,压扁一行整块
57
+ * 就错位(空档用 spacer,同理)。
58
+ */
59
+ function RailLine({ children, color }) {
60
+ return (_jsx(Box, { height: 1, flexShrink: 0, children: _jsx(Text, { color: color, children: children }) }));
61
+ }
62
+ export function TimelineRail({ geometry, registerClick, onPickTurn, }) {
63
+ const ref = useRef(null);
64
+ useClickRegion(ref, registerClick, (col, row, top, height) => {
65
+ if (row < top || row >= top + height)
66
+ return false;
67
+ const hit = railHitRow(geometry, row - top);
68
+ if (hit === null)
69
+ return false;
70
+ if (hit === 'up' || hit === 'down') {
71
+ // 暗箭头(没有目标)点了什么也不做——「画得出 = 点得中,暗 = 保证的空操作」
72
+ const target = hit === 'up' ? geometry.up : geometry.down;
73
+ if (target !== null)
74
+ onPickTurn(target);
75
+ return true;
76
+ }
77
+ onPickTurn(hit);
78
+ return true;
79
+ });
80
+ return (_jsx(Box, { ref: ref, width: RAIL_WIDTH, flexShrink: 0, flexDirection: "column", children: segments(geometry.rows).map((segment, index) => segment.kind === 'gap' ? (_jsx(Box, { height: segment.rows, flexShrink: 0 }, `gap-${index}`)) : (_jsx(RailLine, { color: colorOf(geometry.rows[segment.row]), children: glyphOf(geometry.rows[segment.row]) }, `row-${segment.row}`))) }));
81
+ }
82
+ /**
83
+ * 比例滚动条(轮数不够画刻度时的兜底):滑块按「可见比例」定长、位置按滚动比例。
84
+ * 用途只有一个——**让「我在哪儿、还有多少」在右边看得见**;点轨道上任意一行直接跳
85
+ * 到那个比例处。
86
+ *
87
+ * 只画滑块、不画轨道(对齐 dsh):没滑块的地方整列留空,正文右侧不会多一条竖线抢注意力。
88
+ */
89
+ export function ScrollbarGutter({ marks, registerClick, onPickRow, }) {
90
+ const ref = useRef(null);
91
+ useClickRegion(ref, registerClick, (col, row, top, height) => {
92
+ if (row < top || row >= top + height)
93
+ return false;
94
+ onPickRow(row - top);
95
+ return true;
96
+ });
97
+ return (_jsx(Box, { ref: ref, width: RAIL_WIDTH, flexShrink: 0, flexDirection: "column", children: segments(marks.map((mark) => (mark ? true : null))).map((segment, index) => segment.kind === 'gap' ? (_jsx(Box, { height: segment.rows, flexShrink: 0 }, `gap-${index}`)) : (_jsx(RailLine, { color: RAIL_COLOR.arrow, children: RAIL_GLYPH.thumb }, `row-${segment.row}`))) }));
98
+ }
@@ -0,0 +1,160 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * 右侧那一列:**轮数刻度**(照 dsh-TUI 的 TimelineRail)。
4
+ *
5
+ * - 一轮一格,当前视口所在的那一轮画 `━━`、其余画 ` ─`,▲ + 刻度 + ▼ 这一块在列里
6
+ * **纵向居中**,两头箭头永远画(没有目标就暗色——位置固定,视线不用每帧重找)。
7
+ * 照 dsh 的门槛:窄于 60 列、不到两轮、一屏装得下都不画。
8
+ *
9
+ * 整列**一次命中判定**(`row - top` 换算成列内行号),不在每行挂命中区;空档一律用
10
+ * **固定高度的 spacer**——拿只含空格的 `Text` 当空行会被 yoga 压扁,整列跟着错位
11
+ * (实测 16 行的列只画出 9 行、箭头落到中段)。颜色走既有调色板,不硬编码。
12
+ *
13
+ * **悬停**(对齐 dsh):指针停在刻度列上时该行提亮一档;停住约 250ms 弹出
14
+ * 一枚单行读数条(`第 N 轮 · 题面`),点下去跳哪儿与读数完全一致。三条实现约束:
15
+ *
16
+ * 1. 读数条是 `position="absolute"` 的子节点:**不占布局**(不弹出来就不影响任何行高),
17
+ * ink 6.8 的 Box 没有 `top`/`right`,绝对子节点落在**父节点的原点**上,所以它挂在
18
+ * 悬停那一行的行盒里,再用**负 `marginLeft`** 顶到刻度列左边(实测:负 margin 认,
19
+ * 但绝对子节点**不认**父节点的流式位置——放在列容器里会跑到列首,这也是它必须挂在
20
+ * 行盒里的原因)。
21
+ * 2. 指针位置只走 `pointer` 那个小 store,且**值没变不通知**(列判定在 store 里做)——
22
+ * 鼠标划过屏幕其余地方,这个组件一次都不会重渲染。
23
+ * 3. 拖动 = 「从刻度列上按住左键划过」:拖动会话由 App 在**按下**时开在这个区上
24
+ * (见 `App.dispatchMouseDrag`),划过是一条连续 scrub,与点击同一条映射(dsh 同款)。
25
+ *
26
+ * @module dsc-tui/app/TimelineRail
27
+ */
28
+ import { Box, Text } from 'ink';
29
+ import { useEffect, useRef, useState } from 'react';
30
+ import { absoluteTop, displayWidth, measuredSpan, useClickRegion } from './click.js';
31
+ import { useGutterPointer } from './pointer.js';
32
+ import { railHitRow, RAIL_GLYPH, RAIL_WIDTH, } from './scroll-model.js';
33
+ import { PALETTE, RAIL_COLOR } from './theme.js';
34
+ /** 悬停多久弹读数条(对齐 dsh 的 dwell 闸:扫过不弹,停住才弹)。 */
35
+ const CHIP_DWELL_MS = 250;
36
+ /** 把「逐行有/无内容」压成段序列:空档给固定高度,渲染时一行字符 = 几何里的一行。 */
37
+ export function segments(rows) {
38
+ const output = [];
39
+ for (let row = 0; row < rows.length; row += 1) {
40
+ const value = rows[row];
41
+ if (value === null || value === undefined) {
42
+ const last = output[output.length - 1];
43
+ if (last !== undefined && last.kind === 'gap')
44
+ last.rows += 1;
45
+ else
46
+ output.push({ kind: 'gap', rows: 1 });
47
+ continue;
48
+ }
49
+ output.push({ kind: 'row', row });
50
+ }
51
+ return output;
52
+ }
53
+ /** 按显示宽度硬截(读数条宽度要自己算:绝对子节点的盒宽不能靠 yoga 量)。 */
54
+ function clip(text, maxWidth) {
55
+ let width = 0;
56
+ let index = 0;
57
+ while (index < text.length) {
58
+ const char = String.fromCodePoint(text.codePointAt(index) ?? 0);
59
+ const next = width + displayWidth(char);
60
+ if (next > maxWidth)
61
+ return `${text.slice(0, index)}…`;
62
+ width = next;
63
+ index += char.length;
64
+ }
65
+ return text;
66
+ }
67
+ /** 刻度栏某一行画什么字符。 */
68
+ function glyphOf(entry) {
69
+ if (entry.kind === 'up')
70
+ return RAIL_GLYPH.up;
71
+ if (entry.kind === 'down')
72
+ return RAIL_GLYPH.down;
73
+ return entry.active ? RAIL_GLYPH.active : RAIL_GLYPH.idle;
74
+ }
75
+ /** 刻度栏某一行什么颜色(箭头分「有目标可点 / 没目标」两档)。 */
76
+ function colorOf(entry, hovered) {
77
+ if (entry.kind === 'up' || entry.kind === 'down') {
78
+ return entry.enabled ? RAIL_COLOR.arrow : RAIL_COLOR.arrowOff;
79
+ }
80
+ if (hovered)
81
+ return RAIL_COLOR.active;
82
+ return entry.active ? RAIL_COLOR.active : RAIL_COLOR.idle;
83
+ }
84
+ /**
85
+ * 悬浮读数条:单行、暗底、宽度自己算,用负 `marginLeft` 从行盒(= 刻度列)向左顶出去。
86
+ * 绝对定位 → 不占布局;行盒只有两列宽,所以宽度必须是显式的(否则文字会按 2 列折行)。
87
+ */
88
+ function HoverChip({ label }) {
89
+ const width = displayWidth(label) + 2;
90
+ return (_jsx(Box, { position: "absolute", height: 1, width: width, marginLeft: -(width + 1), backgroundColor: PALETTE.surface, children: _jsx(Text, { color: PALETTE.surfaceText, wrap: "truncate-end", children: ` ${label} ` }) }));
91
+ }
92
+ /** 指针在刻度列上的第几行(列内 0 基);不在列上/量不到几何 = null。 */
93
+ function useHoverRow(ref, rows) {
94
+ const pointerRow = useGutterPointer();
95
+ const top = absoluteTop(ref.current);
96
+ if (pointerRow === null || top === null)
97
+ return null;
98
+ const local = pointerRow - 1 - top;
99
+ return local >= 0 && local < rows ? local : null;
100
+ }
101
+ /** 停住才弹、弹出来就跟着走(原样照 dsh 的 dwell 语义)。 */
102
+ function useChipRow(hovered) {
103
+ const [chipRow, setChipRow] = useState(null);
104
+ useEffect(() => {
105
+ if (hovered === null) {
106
+ setChipRow(null);
107
+ return;
108
+ }
109
+ if (chipRow === hovered)
110
+ return;
111
+ if (chipRow !== null) {
112
+ setChipRow(hovered);
113
+ return;
114
+ }
115
+ const timer = setTimeout(() => setChipRow(hovered), CHIP_DWELL_MS);
116
+ return () => clearTimeout(timer);
117
+ }, [hovered, chipRow]);
118
+ return chipRow;
119
+ }
120
+ /** 一行的行盒:`height={1}` + 不收缩——读数条按行盒的原点定位,压扁一行整块就错位。 */
121
+ function RailLine({ children, color, chip }) {
122
+ return (_jsxs(Box, { height: 1, flexShrink: 0, children: [_jsx(Text, { color: color, children: children }), chip] }));
123
+ }
124
+ export function TimelineRail({ geometry, registerClick, onPickTurn, turnText, }) {
125
+ const ref = useRef(null);
126
+ const hovered = useHoverRow(ref, geometry.rows.length);
127
+ const chipRow = useChipRow(hovered);
128
+ useClickRegion(ref, registerClick, (col, row, top, height) => {
129
+ if (row < top || row >= top + height)
130
+ return false;
131
+ // 列也要对得上:整块只占最右两列(页边距之内)。上一版只判行,于是正文里点一下
132
+ // 也会跳到某一轮(用户报障:「左键点任意位置都被当成点滚动条」)。
133
+ const span = measuredSpan(ref.current);
134
+ if (span === null || col < span.left || col >= span.left + span.width)
135
+ return false;
136
+ const hit = railHitRow(geometry, row - top);
137
+ if (hit === null)
138
+ return false;
139
+ if (hit === 'up' || hit === 'down') {
140
+ // 暗箭头(没有目标)点了什么也不做——「画得出 = 点得中,暗 = 保证的空操作」
141
+ const target = hit === 'up' ? geometry.up : geometry.down;
142
+ if (target !== null)
143
+ onPickTurn(target);
144
+ return true;
145
+ }
146
+ onPickTurn(hit);
147
+ return true;
148
+ },
149
+ // 认拖动:按住左键划过刻度列 = 一路跳(scrub),与点击同一条映射
150
+ { drag: true });
151
+ return (_jsx(Box, { ref: ref, width: RAIL_WIDTH, flexShrink: 0, flexDirection: "column", children: segments(geometry.rows).map((segment, index) => segment.kind === 'gap' ? (_jsx(Box, { height: segment.rows, flexShrink: 0 }, `gap-${index}`)) : (_jsx(RailLine, { color: colorOf(geometry.rows[segment.row], hovered === segment.row), chip: chipRow === segment.row ? _jsx(HoverChip, { label: tickLabel(geometry.rows[segment.row], turnText) }) : null, children: glyphOf(geometry.rows[segment.row]) }, `row-${segment.row}`))) }));
152
+ }
153
+ /** 刻度那行的读数条文案:`第 N 轮 · 题面预览`(没有预览就只报轮号)。 */
154
+ function tickLabel(entry, turnText) {
155
+ if (entry.kind !== 'tick')
156
+ return '';
157
+ const head = `第 ${entry.turn + 1} 轮`;
158
+ const text = turnText?.(entry.turn) ?? null;
159
+ return text === null || text === '' ? head : `${head} · ${clip(text, 24)}`;
160
+ }
@@ -1,5 +1,11 @@
1
1
  import type { JSX } from 'react';
2
2
  import type { ToolCallView } from '../contract.js';
3
- export declare function ToolCard({ call }: {
3
+ import { type RegisterClick } from './click.js';
4
+ export declare function ToolCard({ call, expanded, onToggle, registerClick, }: {
4
5
  call: ToolCallView;
6
+ /** 展开态(点整卡切换;状态由调用方持有)。 */
7
+ expanded: boolean;
8
+ /** 点一下整卡的回调(省略 = 卡片不可点,只画折叠态)。 */
9
+ onToggle?: () => void;
10
+ registerClick?: RegisterClick;
5
11
  }): JSX.Element;
@@ -1,11 +1,22 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
- * 工具行:折叠态就是会话流里的一行平铺文字(名称 + 参数摘要 + 状态),
4
- * 结果摘要作为展开块缩两格、走暗淡色;不给整行套描边框,一屏能多放下几条。
3
+ * 工具行:**默认折叠成一行「⚙ 调用 xx 工具 · 状态」**,点一行才展开参数与结果
4
+ * (用户口径:工具调用默认只报「调用了什么」,细节点开才给)。展开体缩两格、走暗淡色;
5
+ * 不给整行套描边框,一屏能多放下几条。
6
+ *
7
+ * 三条实现约束:
8
+ * 1. **展开态由调用方持有**(App 的 `expandedTools`):卡片滚出窗口切片再滚回来、或换到
9
+ * 回看浮层,展开与否都还在同一份状态里。
10
+ * 2. 点击判定**行、列都量**(行在卡内、列在卡宽内):右侧那两列是刻度栏的,别抢——
11
+ * 只判行的话,点在刻度栏上会被卡片吃掉,反之亦然(用户报过「点哪都像点滚动条」)。
12
+ * 3. 图标与文字之间留**两格**:`⚙` 在多数终端按双宽字形渲染,一格会被字形吃掉,
13
+ * 看起来就是图标和文本挤在一起(用户报的「挤一块」)。
5
14
  *
6
15
  * @module dsc-tui/app/ToolCard
7
16
  */
8
17
  import { Box, Text } from 'ink';
18
+ import { useRef } from 'react';
19
+ import { measuredSpan, useClickRegion } from './click.js';
9
20
  import { GAP, INDENT, SEP, STATUS_COLOR, TEXT } from './theme.js';
10
21
  /** 状态标签:中文硬编码,配色只取 `STATUS_COLOR` 里的状态色。 */
11
22
  const STATUS_LABEL = {
@@ -17,7 +28,7 @@ const STATUS_LABEL = {
17
28
  failed: { text: '✗ 失败', color: STATUS_COLOR.failed },
18
29
  rejected: { text: '⊘ 已拒绝', color: STATUS_COLOR.failed },
19
30
  };
20
- /** 参数摘要截断宽度:留出名称与状态的位置,让一行不被挤到换行。 */
31
+ /** 参数摘要截断宽度(展开态那一行)。 */
21
32
  const ARG_PREVIEW_LIMIT = 80;
22
33
  /** 结果摘要截断宽度。 */
23
34
  const RESULT_PREVIEW_LIMIT = 200;
@@ -34,7 +45,20 @@ const oneLine = (text, limit) => {
34
45
  const flat = text.replace(/\s+/g, ' ').trim();
35
46
  return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
36
47
  };
37
- export function ToolCard({ call }) {
48
+ export function ToolCard({ call, expanded, onToggle, registerClick, }) {
38
49
  const status = STATUS_LABEL[call.status];
39
- return (_jsxs(Box, { flexDirection: "column", marginLeft: INDENT.tool, gap: GAP.none, children: [_jsxs(Box, { children: [_jsx(Box, { flexShrink: 0, children: _jsxs(Text, { ...TEXT.secondary, children: ["\u2699 ", call.name] }) }), call.argsText !== '' ? (_jsx(Box, { minWidth: 0, children: _jsxs(Text, { ...TEXT.secondary, wrap: "truncate-end", children: [SEP.dot, oneLine(call.argsText, ARG_PREVIEW_LIMIT)] }) })) : null, _jsxs(Box, { flexShrink: 0, children: [_jsxs(Text, { ...TEXT.label, color: status.color, children: [SEP.dot, status.text] }), call.durationMs !== undefined ? (_jsxs(Text, { ...TEXT.label, color: status.color, children: [' ', "\u00B7 ", fmtDuration(call.durationMs)] })) : null] })] }), call.resultText !== undefined && call.resultText !== '' ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, children: ["\u21B3 ", oneLine(call.resultText, RESULT_PREVIEW_LIMIT)] }) })) : null] }));
50
+ const ref = useRef(null);
51
+ useClickRegion(ref, onToggle === undefined ? undefined : registerClick, onToggle === undefined
52
+ ? undefined
53
+ : (col, row, top, height) => {
54
+ if (row < top || row >= top + height)
55
+ return false;
56
+ const span = measuredSpan(ref.current);
57
+ if (span === null || col < span.left || col >= span.left + span.width)
58
+ return false;
59
+ onToggle();
60
+ return true;
61
+ });
62
+ const hasResult = call.resultText !== undefined && call.resultText !== '';
63
+ return (_jsxs(Box, { ref: ref, flexDirection: "column", marginLeft: INDENT.tool, gap: GAP.none, children: [_jsxs(Box, { children: [_jsx(Box, { flexShrink: 0, children: _jsx(Text, { ...TEXT.secondary, children: `⚙ 调用 ${call.name} 工具` }) }), _jsxs(Box, { flexShrink: 0, children: [_jsxs(Text, { ...TEXT.label, color: status.color, children: [SEP.dot, status.text] }), call.durationMs !== undefined ? (_jsxs(Text, { ...TEXT.label, color: status.color, children: [' ', "\u00B7 ", fmtDuration(call.durationMs)] })) : null] })] }), expanded && call.argsText !== '' ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, wrap: "truncate-end", children: ["\u25B8 ", oneLine(call.argsText, ARG_PREVIEW_LIMIT)] }) })) : null, expanded && hasResult ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, children: ["\u21B3 ", oneLine(call.resultText ?? '', RESULT_PREVIEW_LIMIT)] }) })) : null] }));
40
64
  }
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * 工具行:**默认折叠成一行「⚙ 调用 xx 工具 · 状态」**,点一行才展开参数与结果
4
+ * (用户口径:工具调用默认只报「调用了什么」,细节点开才给)。展开体缩两格、走暗淡色;
5
+ * 不给整行套描边框,一屏能多放下几条。
6
+ *
7
+ * 三条实现约束:
8
+ * 1. **展开态由调用方持有**(App 的 `expandedTools`):卡片滚出窗口切片再滚回来、或换到
9
+ * 回看浮层,展开与否都还在同一份状态里。
10
+ * 2. 点击判定**行、列都量**(行在卡内、列在卡宽内):右侧那两列是刻度栏的,别抢——
11
+ * 只判行的话,点在刻度栏上会被卡片吃掉,反之亦然(用户报过「点哪都像点滚动条」)。
12
+ * 3. 图标与文字之间留**两格**:`⚙` 在多数终端按双宽字形渲染,一格会被字形吃掉,
13
+ * 看起来就是图标和文本挤在一起(用户报的「挤一块」)。
14
+ *
15
+ * @module dsc-tui/app/ToolCard
16
+ */
17
+ import { Box, Text } from 'ink';
18
+ import { useRef } from 'react';
19
+ import { measuredSpan, useClickRegion } from './click.js';
20
+ import { GAP, INDENT, SEP, STATUS_COLOR, TEXT } from './theme.js';
21
+ /** 状态标签:中文硬编码,配色只取 `STATUS_COLOR` 里的状态色。 */
22
+ const STATUS_LABEL = {
23
+ // 模型吐了工具名、参数还没到齐(对照 dsh 的 preparing 阶段):与「执行中」同色,
24
+ // 但它只是「接下来要干这件事」,参数与结果都还没有。
25
+ preparing: { text: '◌ 准备中', color: STATUS_COLOR.pending },
26
+ running: { text: '◐ 执行中', color: STATUS_COLOR.pending },
27
+ done: { text: '✓ 完成', color: STATUS_COLOR.done },
28
+ failed: { text: '✗ 失败', color: STATUS_COLOR.failed },
29
+ rejected: { text: '⊘ 已拒绝', color: STATUS_COLOR.failed },
30
+ };
31
+ /** 参数摘要截断宽度(展开态那一行)。 */
32
+ const ARG_PREVIEW_LIMIT = 80;
33
+ /** 结果摘要截断宽度。 */
34
+ const RESULT_PREVIEW_LIMIT = 200;
35
+ /** 耗时的人话格式:890ms / 1.2s / 1m23s。 */
36
+ const fmtDuration = (ms) => {
37
+ if (ms < 1000)
38
+ return `${Math.round(ms)}ms`;
39
+ if (ms < 60_000)
40
+ return `${(ms / 1000).toFixed(1)}s`;
41
+ return `${Math.floor(ms / 60_000)}m${Math.round((ms % 60_000) / 1000)}s`;
42
+ };
43
+ /** 单行化并截断。 */
44
+ const oneLine = (text, limit) => {
45
+ const flat = text.replace(/\s+/g, ' ').trim();
46
+ return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
47
+ };
48
+ export function ToolCard({ call, expanded, onToggle, registerClick, }) {
49
+ const status = STATUS_LABEL[call.status];
50
+ const ref = useRef(null);
51
+ useClickRegion(ref, onToggle === undefined ? undefined : registerClick, onToggle === undefined
52
+ ? undefined
53
+ : (col, row, top, height) => {
54
+ if (row < top || row >= top + height)
55
+ return false;
56
+ const span = measuredSpan(ref.current);
57
+ if (span === null || col < span.left || col >= span.left + span.width)
58
+ return false;
59
+ onToggle();
60
+ return true;
61
+ });
62
+ const hasResult = call.resultText !== undefined && call.resultText !== '';
63
+ return (_jsxs(Box, { ref: ref, flexDirection: "column", marginLeft: INDENT.tool, gap: GAP.none, children: [_jsxs(Box, { children: [_jsx(Box, { flexShrink: 0, children: _jsx(Text, { ...TEXT.secondary, children: `⚙ 调用 ${call.name} 工具` }) }), _jsxs(Box, { flexShrink: 0, children: [_jsxs(Text, { ...TEXT.label, color: status.color, children: [SEP.dot, status.text] }), call.durationMs !== undefined ? (_jsxs(Text, { ...TEXT.label, color: status.color, children: [' ', "\u00B7 ", fmtDuration(call.durationMs)] })) : null] })] }), expanded && call.argsText !== '' ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, wrap: "truncate-end", children: ["\u25B8 ", oneLine(call.argsText, ARG_PREVIEW_LIMIT)] }) })) : null, expanded && hasResult ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsxs(Text, { ...TEXT.secondary, children: ["\u21B3 ", oneLine(call.resultText ?? '', RESULT_PREVIEW_LIMIT)] }) })) : null] }));
64
+ }
@@ -1,12 +1,27 @@
1
- import type { JSX } from 'react';
2
1
  import type { TranscriptEntry } from '../contract.js';
3
- export declare function TranscriptOverlay({ entries, start, total, title, }: {
4
- /** 可见窗口切片(App 按滚动偏移算好传入)。 */
2
+ import type { RegisterClick } from './click.js';
3
+ import { type TranscriptViewportApi } from './TranscriptViewport.js';
4
+ /**
5
+ * 浮层固定占掉的行数:上下边框 2 + 标题 1 + 提示 1。
6
+ * 视口行数 = 帧行数 − 状态栏行数 − 它(App 按这个算)。
7
+ */
8
+ export declare const TRANSCRIPT_CHROME = 4;
9
+ export interface TranscriptOverlayProps {
10
+ /** 全量条目(视口自己切片)。 */
5
11
  entries: TranscriptEntry[];
6
- /** 窗口第一条在全量 transcript 里的下标(标题展示用)。 */
7
- start: number;
8
- /** 全量条数。 */
12
+ /** 全量条数(标题用;peek 失败时也会是 0)。 */
9
13
  total: number;
10
- /** 标题(省略 = 本会话回看;子代理转录复用同一浮层时传它的名字)。 */
14
+ /** 标题(省略 = 本会话回看;子代理转录传它的名字)。 */
11
15
  title?: string;
12
- }): JSX.Element;
16
+ /** 终端列数(浮层自身宽度与刻度栏门槛都用它算)。 */
17
+ columns: number;
18
+ /** 视口行数(= 帧行数 − 状态栏 − `TRANSCRIPT_CHROME`)。 */
19
+ viewportLines: number;
20
+ /** 子代理转录(只读 peek)与主回看的提示行不同时用。 */
21
+ hint?: string;
22
+ registerClick?: RegisterClick;
23
+ /** 已展开的工具卡与切换回调(与聊天区同一份):浮层里点工具卡也能展开。 */
24
+ expandedTools?: ReadonlySet<number>;
25
+ onToggleTool?: (id: number) => void;
26
+ }
27
+ export declare const TranscriptOverlay: import("react").ForwardRefExoticComponent<TranscriptOverlayProps & import("react").RefAttributes<TranscriptViewportApi>>;
@@ -1,17 +1,36 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /**
3
- * 回看浮层(Ctrl+O 打开):全量 transcript 的滚动窗口,摆脱「直播窗只画尾部 30 条」
4
- * 的限制。复用 ChatView 的条目渲染(streaming 恒 false);窗口切片与滚动偏移由
5
- * App 按「条」计算并路由按键(↑↓/j·k 单条、PgUp/PgDn 翻页、滚轮同义)。根盒在
6
- * 恒定帧里撑满、底对齐、溢出从顶上裁掉——只丢历史不丢最新。本组件纯展示。
3
+ * 回看浮层(Ctrl+O 打开 / 子代理只读转录复用同一块):全量 transcript 的**行滚动**视口,
4
+ * 右侧带轮数刻度栏。窗口切片、行偏移、刻度几何全在 `TranscriptViewport` 里,本组件只负责
5
+ * 「浮层这层壳」——描边、标题行、提示行,以及把每一条交给 `ChatView` 的 `Entry` 渲染。
6
+ *
7
+ * 与旧版的区别:滚动单位从「条」改成「行」(一条比一屏还高的条目因此可以逐行读完,
8
+ * 这正是「点进子代理看不到工作过程」的病根),并且条数窗口换成了「视口 ± overscan 行」
9
+ * 的窗口——会话再长,渲染量也是有界的。
7
10
  *
8
11
  * @module dsc-tui/app/TranscriptOverlay
9
12
  */
10
13
  import { Box, Text } from 'ink';
11
- import { ACCENT, BORDER, GAP, INDENT, PAD, TEXT } from './theme.js';
14
+ import { forwardRef } from 'react';
12
15
  import { Entry } from './ChatView.js';
13
- export function TranscriptOverlay({ entries, start, total, title, }) {
14
- return (_jsx(Box, { borderStyle: "round", borderColor: BORDER.active, paddingX: PAD.inline, flexDirection: "column", flexGrow: 1, overflowY: "hidden", justifyContent: "flex-end", gap: GAP.none, children: _jsxs(Box, { flexShrink: 0, flexDirection: "column", gap: GAP.none, children: [_jsx(Text, { ...TEXT.label, color: ACCENT, wrap: "truncate-end", children: title === undefined
15
- ? `回看全文(共 ${total} 条 · 第 ${start + 1}-${start + entries.length} 条)`
16
- : `${title} · ${total} 条` }), entries.map((entry) => (_jsx(Entry, { entry: entry, streaming: false, expandThinking: false }, entry.id))), entries.length === 0 ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsx(Text, { ...TEXT.secondary, children: "\uFF08\u8FD9\u4E2A\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u6761\u76EE\uFF09" }) })) : null, _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: "\u2191\u2193/j\u00B7k \u5355\u6761 \u00B7 PgUp/PgDn \u7FFB\u9875 \u00B7 \u6EDA\u8F6E\u540C\u4E49 \u00B7 q \u6216 Esc \u6216 Ctrl+O \u5173\u95ED" })] }) }));
16
+ import { HINT as HINT_TEXT } from './keymap.js';
17
+ import { TranscriptViewport } from './TranscriptViewport.js';
18
+ import { ACCENT, BORDER, PAD, TEXT } from './theme.js';
19
+ /**
20
+ * 浮层固定占掉的行数:上下边框 2 + 标题 1 + 提示 1。
21
+ * 视口行数 = 帧行数 − 状态栏行数 − 它(App 按这个算)。
22
+ */
23
+ export const TRANSCRIPT_CHROME = 4;
24
+ /** 浮层描边与内边距固定占掉的列数:边框 2 + 左右各 1 列内边距。 */
25
+ const OVERLAY_CHROME_COLUMNS = 4;
26
+ /** 滚动提示行(主回看与子代理转录共用;键名统一从 `keymap` 的表里拼,不再各写一遍)。 */
27
+ const HINT = HINT_TEXT.transcript;
28
+ /** 标题:主回看给「共 N 条 · 第 x-y 条」;子代理转录给「名字 · N 条」。 */
29
+ function titleText(title, total, layout) {
30
+ if (title !== undefined)
31
+ return `${title} · ${total} 条`;
32
+ return `回看全文(共 ${total} 条 · 第 ${layout.start + 1}-${layout.end} 条)`;
17
33
  }
34
+ export const TranscriptOverlay = forwardRef(function TranscriptOverlay({ entries, total, title, columns, viewportLines, hint, registerClick, expandedTools, onToggleTool }, ref) {
35
+ return (_jsx(Box, { borderStyle: "round", borderColor: BORDER.active, paddingX: PAD.inline, flexDirection: "column", flexGrow: 1, minHeight: 0, children: _jsx(TranscriptViewport, { ref: ref, entries: entries, columns: columns, maxWidth: Math.max(20, columns - PAD.page * 2 - OVERLAY_CHROME_COLUMNS), viewportLines: viewportLines, showRail: true, registerClick: registerClick, emptyHint: "\uFF08\u8FD9\u4E2A\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u6761\u76EE\uFF09", header: (layout) => (_jsx(Text, { ...TEXT.label, color: ACCENT, wrap: "truncate-end", children: titleText(title, total, layout) })), footer: _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: hint ?? HINT }), renderEntry: (entry) => (_jsx(Entry, { entry: entry, streaming: false, expandThinking: false, expandedTools: expandedTools, onToggleTool: onToggleTool, registerClick: registerClick })) }) }));
36
+ });