@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,78 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TranscriptEntry } from '../contract.js';
3
+ import { type RegisterClick } from './click.js';
4
+ import { type TurnMark, type ViewportLayout } from './scroll-model.js';
5
+ /** 一次滚轮 = 几行(终端一格滚轮不分行,三行是「一格看得出动了」的最小值)。 */
6
+ export declare const WHEEL_LINES = 3;
7
+ /** 视口对外的手柄:App 的键位与鼠标处理打这里(视口自己持有滚动状态)。 */
8
+ export interface TranscriptViewportApi {
9
+ /** 按行滚:正数往上(看更早的)。 */
10
+ scrollLines: (delta: number) => void;
11
+ /** 跳到上/下一轮。 */
12
+ jumpTurn: (direction: 'up' | 'down') => void;
13
+ /** 跳到指定轮。 */
14
+ jumpToTurn: (index: number) => void;
15
+ /** 回到底部(跟尾)。 */
16
+ toTail: () => void;
17
+ /** 翻一页的行数(一屏减一行;视口行数自己量的,调用方不必知道)。 */
18
+ page: () => number;
19
+ /** 是不是贴着最新。 */
20
+ atTail: () => boolean;
21
+ /** 当前这份布局(测试与探针读)。 */
22
+ layout: () => ViewportLayout | null;
23
+ }
24
+ export interface TranscriptViewportProps {
25
+ /** 全量条目(顺序即时间序)。 */
26
+ entries: TranscriptEntry[];
27
+ /** 没画刻度栏时可用的内容宽度(列)——调用方按帧几何扣掉边框与内边距。 */
28
+ maxWidth: number;
29
+ /**
30
+ * 视口行数。省略 = **自己量**(聊天区下面是会变高的卡片与输入区,算不出固定值):
31
+ * 先用一个宽松的默认值起排(尾锚定不受它影响,画面本来就是对的),量到真值后重排一次。
32
+ */
33
+ viewportLines?: number;
34
+ /** 终端总列数(刻度栏门槛与它自己占的列数用)。 */
35
+ columns: number;
36
+ /**
37
+ * 刻度栏**居中**用的高度(省略 = 视口行数)。视口行数会随页脚变(「回到底部」胶囊、
38
+ * 草稿行数),按它居中会让整块刻度每滚一下挪一格;调用方传一个「只在终端改变尺寸时才变」
39
+ * 的高度(聊天区是「帧高 − 状态栏」),刻度栏就静止了。
40
+ */
41
+ railCenterLines?: number;
42
+ /**
43
+ * 思考块当前是不是展开的:只影响**没量到过的**条目的行数估算(一条思考块展开态十几行、
44
+ * 折叠态只画两行)。估错了会连带「跳过段」的高度一起错,表现出来就是「滚轮前几格不动、
45
+ * 再滚一下弹回底部」。
46
+ */
47
+ expandThinking?: boolean;
48
+ /** 一条条目怎么画。 */
49
+ renderEntry: (entry: TranscriptEntry) => ReactNode;
50
+ /** 画不画右侧刻度栏(浮层画;窄屏由 `railEligible` 再判一次)。 */
51
+ showRail?: boolean;
52
+ registerClick?: RegisterClick;
53
+ /** 「是不是贴着最新」变化时回调(聊天那颗回到底部的胶囊用)。 */
54
+ onAtTailChange?: (atTail: boolean) => void;
55
+ /** 没有条目时的占位文案。 */
56
+ emptyHint?: string;
57
+ /**
58
+ * 挂在**流最顶上**的块(聊天区的启动欢迎页):随内容一起从顶上滚走,所以它是流里的
59
+ * 第一个「条目」(占行、参与行高表),不是固定表头。
60
+ */
61
+ leading?: ReactNode;
62
+ /** 视口顶部固定的内容(浮层标题行这类,不参与滚动)。 */
63
+ header?: (layout: ViewportLayout) => ReactNode;
64
+ /**
65
+ * **浮在视口第一行上**的钉住块(聊天的「当前轮题面」):零高容器 + 负 `marginTop`,压在
66
+ * 内容第一行上,而不是挤掉一行。
67
+ *
68
+ * 为什么不占一行(两条都是用户报过的):占一行会改内容坐标——同样格数滚上去再滚回来就差
69
+ * 一行到不了底;也会把右侧刻度栏整体推下去一格(「上下滑动时刻度会上下晃」)。浮上去之后
70
+ * 视口、刻度、滚动坐标全部不动,代价是**可见内容少一行**(与 dsh 挤掉一行的观感一致)。
71
+ *
72
+ * 只有滚离尾部(`top !== null`)时才给「当前轮」;第三参是正文列宽(盖满第一行用)。
73
+ */
74
+ pinned?: (active: TurnMark, layout: ViewportLayout, width: number) => ReactNode;
75
+ /** 视口底部固定的内容(提示行、回到底部胶囊)。 */
76
+ footer?: ReactNode;
77
+ }
78
+ export declare const TranscriptViewport: import("react").ForwardRefExoticComponent<TranscriptViewportProps & import("react").RefAttributes<TranscriptViewportApi>>;
@@ -0,0 +1,218 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * 转录视口:把一段条目按**行**滚动地画在定高区域里,右侧带轮数刻度栏。
4
+ *
5
+ * 结构(自上而下):
6
+ * [上占位 spacer] + [窗口内的条目] + [下占位 spacer]
7
+ * 整叠内容 `flexShrink={0}` + `marginBottom={-shift}`,装在定高、`overflowY="hidden"`、
8
+ * `justifyContent="flex-end"` 的裁剪盒里——尾锚定 + 负 margin 就是逐行滚动(ink 按行
9
+ * 裁切越界文本,见 `render-node-to-output.js` / `output.js`),折行也跟着走,不用自己算。
10
+ * spacer 让内容总高恒等于估算总行数,于是「视口顶落在第几行」就是全部滚动状态。
11
+ *
12
+ * 滚动状态是 **视口顶的内容行号 `top`**(null = 跟尾)而不是「距尾部多少行」:队友还在
13
+ * 往尾部写的时候,距尾部计数会被新内容推着走——你正读到的地方会被顶下去;钉住顶行号才
14
+ * 站得住(在顶部以上的条目已定稿、不可变,所以钉住是稳的)。
15
+ *
16
+ * 行高表:渲染前从上一帧量到的行里取真值(`measuredHeight`),没量过的用估算
17
+ * (`scroll-model.estimateLines`);内容宽度一改(刻度栏出现/消失)表就整表作废。
18
+ * settled 条目不可变,所以量到一次就永久有效;只有 live 尾每帧重测。
19
+ *
20
+ * 视口行数由调用方按帧几何算好传进来(浮层是「帧行数 − 状态栏 − 浮层框架」,聊天是
21
+ * 「帧行数 − 状态栏 − 聊天框架」),不在这里量,免得首帧拿不到数。
22
+ *
23
+ * @module dsc-tui/app/TranscriptViewport
24
+ */
25
+ import { Box, Text } from 'ink';
26
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
27
+ import { measuredHeight } from './click.js';
28
+ import { activeTurnIndex, anchorAtRow, estimateLines, HeightCache, layoutViewport, railEligible, railGeometry, RAIL_MIN_COLUMNS, RAIL_WIDTH, rowOfAnchor, turnJumpTarget, } from './scroll-model.js';
29
+ import { TimelineRail } from './TimelineRail.js';
30
+ import { GAP, INDENT, TEXT } from './theme.js';
31
+ /** 流头部(聊天区的欢迎块)在行高表里的哨兵 id——它不是真条目,但占行、要参与排版。 */
32
+ const LEADING_ID = -1_000_000;
33
+ /** 一次滚轮 = 几行(终端一格滚轮不分行,三行是「一格看得出动了」的最小值)。 */
34
+ export const WHEEL_LINES = 3;
35
+ export const TranscriptViewport = forwardRef(function TranscriptViewport({ entries, maxWidth, viewportLines, columns, railCenterLines, expandThinking, renderEntry, showRail = false, registerClick, onAtTailChange, emptyHint, leading, header, pinned, footer }, ref) {
36
+ /** 视口顶的**内容锚点**(哪一条的第几行);null = 跟尾(新内容长出来就一直跟着尾巴)。 */
37
+ const [anchor, setAnchor] = useState(null);
38
+ /** 自己量到的裁剪盒高度(`viewportLines` 省略时用;`flexGrow` 撑出来的高度量不到就先用默认)。 */
39
+ const [selfLines, setSelfLines] = useState(0);
40
+ const boxRef = useRef(null);
41
+ const lines = viewportLines ?? (selfLines > 0 ? selfLines : 30);
42
+ /** 行高表(宽度变了自动作废)。 */
43
+ const heights = useRef(new HeightCache()).current;
44
+ const nodes = useRef(new Map());
45
+ const atTail = useRef(true);
46
+ /** 本轮量到「与估算不符」的条数(>0 就要按真值重排一次)。 */
47
+ const fixups = useRef(0);
48
+ // 流头部当成一条「伪条目」参与排版:占它的行、跟着滚,但不进窗口的 renderEntry
49
+ const layoutEntries = leading === undefined
50
+ ? entries
51
+ : [{ kind: 'system', id: LEADING_ID, text: '' }, ...entries];
52
+ /** id → 条目(量到真值时查它的估算值)。 */
53
+ const byId = new Map(layoutEntries.map((entry) => [entry.id, entry]));
54
+ /** 估算口径:必须与实际渲染口径一致(思考块展开与否差十几行)。 */
55
+ const estimate = { expandThinking: expandThinking === true };
56
+ // 刻度栏先按列数定「要不要给它留位」;画不画再按轮数/内容高度复核(不画就把列还给正文)
57
+ const wantRail = showRail && columns >= RAIL_MIN_COLUMNS;
58
+ const width = Math.max(20, maxWidth - (wantRail ? RAIL_WIDTH : 0));
59
+ heights.useWidth(width);
60
+ // 渲染前先把上一帧量到的行数收进行高表:这一帧的布局就能用上真值。
61
+ // (读的是上一帧的 yoga 几何——`click.ts` 的命中判定也是这么「用的时候才量」。)
62
+ // 只有「首次量到、且与估算不符」才记一笔重排请求:纯文本条目估算本来就准,不必多排,
63
+ // 否则流式增量(每条都要新量一次)会把提交次数拖着翻倍。
64
+ for (const [id, node] of nodes.current) {
65
+ const measured = measuredHeight(node);
66
+ if (measured === null)
67
+ continue;
68
+ const known = heights.get(id);
69
+ heights.set(id, measured);
70
+ if (known !== undefined)
71
+ continue;
72
+ const entry = byId.get(id);
73
+ if (entry !== undefined && estimateLines(entry, width, estimate) !== measured)
74
+ fixups.current += 1;
75
+ }
76
+ // 布局:锚点 → 视口顶行号 → 窗口切片与滚动量。刻度栏占不占位要按「画出来没有」
77
+ // 复核,所以可能按两个宽度各排一次(`railOn` 为假时把 2 列还给正文,下一帧就正)。
78
+ const measuredLayout = layoutViewport(layoutEntries, heights, { width, viewportLines: lines, anchor, ...estimate });
79
+ const railOn = wantRail &&
80
+ railEligible({
81
+ columns,
82
+ turnCount: measuredLayout.turns.length,
83
+ viewportLines: lines,
84
+ contentLines: measuredLayout.totalLines,
85
+ });
86
+ const layout = railOn || !wantRail
87
+ ? measuredLayout
88
+ : layoutViewport(layoutEntries, heights, { width: maxWidth, viewportLines: lines, anchor, ...estimate });
89
+ const windowEntries = layoutEntries.slice(layout.start, layout.end);
90
+ const turns = layout.turns;
91
+ const activeIndex = activeTurnIndex(turns, layout.shift, layout, lines);
92
+ const viewportTop = Math.max(0, layout.totalLines - lines - layout.shift);
93
+ // 刻度栏照 dsh:块纵向居中、两头的箭头永远画(没有目标画暗色),窗口贴尾时钉在最新。
94
+ // 居中高度用调用方给的稳定值(视口行数会随页脚变化,按它居中会「滚动时刻度上下晃」)
95
+ const geometry = railOn
96
+ ? railGeometry({
97
+ turnCount: turns.length,
98
+ activeIndex,
99
+ rows: lines,
100
+ centerRows: railCenterLines,
101
+ atBottom: layout.shift === 0,
102
+ viewportTop,
103
+ maxTop: layout.maxShift,
104
+ turnTops: turns.map((turn) => turn.top),
105
+ })
106
+ : null;
107
+ // 轮数不够(<2 轮)或画不下就整列不画——右边空着,正文也不必让位
108
+ const contentWidth = railOn ? width : maxWidth;
109
+ // 浮在视口第一行上的钉住块(只在滚离尾部、且真有当前轮时给):内容坐标不动,它只是压在第一行上
110
+ const activeTurn = turns[activeIndex];
111
+ const pinnedNode = pinned === undefined || layout.top === null || activeTurn === undefined
112
+ ? null
113
+ : pinned(activeTurn, layout, contentWidth);
114
+ // 手柄与夹界都读「刚画出去的那一帧」:键位/鼠标发生在帧之后,读到的是最新值
115
+ const layoutRef = useRef(layout);
116
+ layoutRef.current = layout;
117
+ const linesRef = useRef(lines);
118
+ linesRef.current = lines;
119
+ /** 本帧参与排版的条目(含流头部伪条目):滚动手柄按行号换算锚点时要查它。 */
120
+ const layoutEntriesRef = useRef(layoutEntries);
121
+ layoutEntriesRef.current = layoutEntries;
122
+ /**
123
+ * 往上/往下滚 delta 行(正数 = 往更早的看)。
124
+ *
125
+ * 两条都踩过(用户报的「连滚不动 + 突然弹回底部」):
126
+ * - **必须用函数式更新**:终端把连续几格滚轮合并成一包是常态,一个任务里会连着调
127
+ * 好几次;若每次都读「上一次渲染时的位置」来算,几次都从同一个基准起算,最后只有
128
+ * 一格生效——五格滚轮只走三行。函数式更新拿的是累积后的最新值,几格就是几格。
129
+ * - **行号算完立刻换成锚点**:行号是估算坐标系里的坐标,跳过段一旦被量到真值就缩水,
130
+ * 同一个行号指的内容会变;钉成「哪一条的第几行」之后,跳过段怎么变视线都不动
131
+ * (见 `scroll-model.ScrollAnchor`)。
132
+ */
133
+ const scrollLines = useCallback((delta) => {
134
+ setAnchor((previous) => {
135
+ const current = layoutRef.current;
136
+ const entries = layoutEntriesRef.current;
137
+ const from = previous === null ? current.maxShift : rowOfAnchor(current.rows, entries, previous);
138
+ const next = Math.max(0, Math.min(current.maxShift, from - delta));
139
+ return anchorAtRow(current.rows, entries, next, current.maxShift);
140
+ });
141
+ }, []);
142
+ const jumpToTurn = useCallback((index) => {
143
+ const current = layoutRef.current;
144
+ const turn = current.turns[index];
145
+ if (turn === undefined)
146
+ return;
147
+ // 锚在那一条的第 0 行:跳轮之后跳过段再怎么量,题面都待在视口顶
148
+ const maxTop = Math.max(0, current.totalLines - linesRef.current);
149
+ const row = Math.min(turn.top, maxTop);
150
+ setAnchor(anchorAtRow(current.rows, layoutEntriesRef.current, row, current.maxShift));
151
+ }, []);
152
+ /** 刻度悬停读数条上的题面预览(轮下标 → 该轮题面首行;读的是上一帧的布局与条目表)。 */
153
+ const turnPreview = useCallback((turn) => {
154
+ const mark = layoutRef.current.turns[turn];
155
+ const entry = mark === undefined ? undefined : layoutEntriesRef.current[mark.index];
156
+ if (entry === undefined || entry.kind !== 'user')
157
+ return null;
158
+ return entry.text.replace(/\s+/g, ' ').trim();
159
+ }, []);
160
+ const jumpTurn = useCallback((direction) => {
161
+ const current = layoutRef.current;
162
+ const viewport = Math.max(0, current.totalLines - lines - current.shift);
163
+ // 箭头的目标与刻度栏用同一条纯函数(`[`/`]` 键与点击不会给出不同的落点)
164
+ const next = turnJumpTarget({
165
+ turnCount: current.turns.length,
166
+ activeIndex: activeTurnIndex(current.turns, current.shift, current, lines),
167
+ direction,
168
+ viewportTop: viewport,
169
+ maxTop: current.maxShift,
170
+ turnTops: current.turns.map((turn) => turn.top),
171
+ });
172
+ if (next !== null)
173
+ jumpToTurn(next);
174
+ }, [jumpToTurn, lines]);
175
+ useImperativeHandle(ref, () => ({
176
+ scrollLines,
177
+ jumpTurn,
178
+ jumpToTurn,
179
+ toTail: () => setAnchor(null),
180
+ page: () => Math.max(1, linesRef.current - 1),
181
+ atTail: () => layoutRef.current.shift === 0,
182
+ layout: () => layoutRef.current,
183
+ }), [jumpToTurn, jumpTurn, scrollLines]);
184
+ const atTailNow = layout.shift === 0;
185
+ useEffect(() => {
186
+ if (atTail.current === atTailNow)
187
+ return;
188
+ atTail.current = atTailNow;
189
+ onAtTailChange?.(atTailNow);
190
+ }, [atTailNow, onAtTailChange]);
191
+ /**
192
+ * 量到的真值要「落地一次」:首帧的位置全是估算出来的,排完这一帧才拿到真实行高——
193
+ * 不重排一次,首屏就可能停在错误的行上(试过:可视区里出现半屏空占位)。
194
+ * 签名只看「条目数 + 已量条数」,所以流式增量不会反复触发(那是同一个签名),
195
+ * 只有「新条目进来」或「又量到一批」才多排一帧,且必然收敛。
196
+ */
197
+ const [, setPass] = useState(0);
198
+ useEffect(() => {
199
+ if (viewportLines !== undefined)
200
+ return;
201
+ const measured = measuredHeight(boxRef.current);
202
+ if (measured === null || measured === selfLines)
203
+ return;
204
+ setSelfLines(measured);
205
+ });
206
+ useEffect(() => {
207
+ if (fixups.current === 0)
208
+ return;
209
+ fixups.current = 0;
210
+ setPass((current) => current + 1);
211
+ });
212
+ return (_jsxs(Box, { flexDirection: "column", flexGrow: 1, minHeight: 0, children: [header?.(layout), _jsxs(Box, { flexDirection: "row", minHeight: 0, flexGrow: 1, children: [_jsx(Box, { ref: boxRef, flexDirection: "column", width: contentWidth, ...(viewportLines === undefined ? { flexGrow: 1, minHeight: 0 } : { height: viewportLines, flexShrink: 0 }), overflowY: "hidden", justifyContent: "flex-end", children: _jsxs(Box, { flexDirection: "column", flexShrink: 0, gap: GAP.none, marginBottom: -layout.shift, children: [layout.aboveLines > 0 ? _jsx(Box, { height: layout.aboveLines, flexShrink: 0 }) : null, windowEntries.map((entry) => (_jsx(Box, { ref: (node) => {
213
+ if (node === null)
214
+ nodes.current.delete(entry.id);
215
+ else
216
+ nodes.current.set(entry.id, node);
217
+ }, flexDirection: "column", flexShrink: 0, gap: GAP.none, children: entry.id === LEADING_ID ? leading : renderEntry(entry) }, entry.id))), layout.belowLines > 0 ? _jsx(Box, { height: layout.belowLines, flexShrink: 0 }) : null, layoutEntries.length === 0 ? (_jsx(Box, { marginLeft: INDENT.detail, children: _jsx(Text, { ...TEXT.secondary, children: emptyHint ?? '(这个会话还没有条目)' }) })) : null, pinnedNode === null ? null : (_jsx(Box, { height: 0, flexShrink: 0, children: _jsx(Box, { marginTop: -(lines + layout.shift), flexDirection: "column", children: pinnedNode }) }))] }) }), geometry !== null ? (_jsx(TimelineRail, { geometry: geometry, registerClick: registerClick, onPickTurn: jumpToTurn, turnText: turnPreview })) : null] }), footer] }));
218
+ });
@@ -1,18 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * 启动欢迎块(0.6.58 对齐 dsh-TUI LogoV2 的规格):「MUSE CODE」两行 5 行点阵大字
4
- * (行色按 品牌蓝→冰蓝→浅冰 渐变)+ `✦ Pneuma vX` 词标 + model/cwd/tips 信息行 +
3
+ * 启动欢迎块(0.6.58 对齐 dsh-TUI LogoV2 的规格):「PNEUMA」5 行点阵大字
4
+ * (行色按 品牌蓝→浅冰 渐变)+ `✦ Pneuma vX` 词标 + model/cwd/tips 信息行 +
5
5
  * tagline,**挂在会话流最顶上、随内容从顶上自然滚走**(codex session header /
6
6
  * dsh LogoHeader 同构),不是独立路由。
7
7
  *
8
- * 阶梯降级(对齐 dsh splashLayout):终端行数 ≥ 30 且列数 ≥ 40 → 全块;行数 ≥ 12 →
9
- * 只留词标+信息行;其余一行式。resume 长会话(条目 ≥ 30)直接不画——再画只是把
10
- * 历史往下顶。纯展示,信息行的暗淡档让位给正文。
8
+ * 阶梯降级(对齐 dsh splashLayout):终端行数 ≥ 30 且列数 ≥ 40 → 全块(大字
9
+ * 35 列宽,故列数门槛 40);行数 ≥ 12 → 只留词标+信息行;其余一行式。resume
10
+ * 长会话(条目 ≥ 30)直接不画——再画只是把历史往下顶。纯展示,信息行的暗淡档
11
+ * 让位给正文。
11
12
  *
12
13
  * @module dsc-tui/app/Welcome
13
14
  */
14
15
  import { Box, Text, useStdout } from 'ink';
15
16
  import { DSC_VERSION } from '../core/version.js';
17
+ import { KEYS } from './keymap.js';
16
18
  import { GAP, PALETTE, TEXT } from './theme.js';
17
19
  /** 5 行 × 5 列点阵字形(方块字,参照 dsh splashFonts 的 bold 款)。 */
18
20
  const GLYPHS = {
@@ -23,6 +25,9 @@ const GLYPHS = {
23
25
  C: ['█████', '█ ', '█ ', '█ ', '█████'],
24
26
  O: ['█████', '█ █', '█ █', '█ █', '█████'],
25
27
  D: ['████ ', '█ █', '█ █', '█ █', '████ '],
28
+ P: ['█████', '█ █', '█████', '█ ', '█ '],
29
+ N: ['█ █', '██ █', '█ █ █', '█ ██', '█ █'],
30
+ A: ['█████', '█ █', '█████', '█ █', '█ █'],
26
31
  ' ': [' ', ' ', ' ', ' ', ' '],
27
32
  };
28
33
  /** 一个词的 5 行点阵(字形间 1 列空隙)。 */
@@ -57,10 +62,10 @@ export function Welcome({ model, effort, cwd, }) {
57
62
  const { stdout } = useStdout();
58
63
  const columns = stdout?.columns ?? 100;
59
64
  const rows = stdout?.rows ?? 24;
60
- const info = (_jsxs(_Fragment, { children: [_jsxs(Text, { ...TEXT.secondary, wrap: "truncate-end", children: [cwd !== undefined && cwd !== '' ? `${shortCwd(cwd)} · ` : '', "\u6A21\u578B ", model, " \u00B7 effort ", effort] }), _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: "/help \u770B\u547D\u4EE4 \u00B7 \u53CC\u51FB Esc \u64A4\u56DE\u4E0A\u4E00\u8F6E \u00B7 Ctrl+O \u56DE\u770B\u5168\u6587 \u00B7 Ctrl+T \u5C55\u5F00\u601D\u8003 \u00B7 Ctrl+V \u8D34\u56FE" }), _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: "\u6709\u6D3B\u76F4\u63A5\u8BF4\uFF1B@ \u63D0\u6587\u4EF6\uFF0C/ \u6216 @ \u5524\u51FA\u8865\u5168\uFF0CShift+Enter \u6362\u884C\u3002" })] }));
61
- // 阶梯降级:矮终端/窄终端退到词标版(块体 ~17 行要 ≥30 行才放得下)
65
+ const info = (_jsxs(_Fragment, { children: [_jsxs(Text, { ...TEXT.secondary, wrap: "truncate-end", children: [cwd !== undefined && cwd !== '' ? `${shortCwd(cwd)} · ` : '', "\u6A21\u578B ", model, " \u00B7 effort ", effort] }), _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: `/help 看命令 · 双击 ${KEYS.escape} 撤回上一轮 · ${KEYS.transcript} 回看全文 · ${KEYS.thinking} 展开思考 · ${KEYS.paste} 贴图` }), _jsx(Text, { ...TEXT.secondary, wrap: "truncate-end", children: "\u6709\u6D3B\u76F4\u63A5\u8BF4\uFF1B@ \u63D0\u6587\u4EF6\uFF0C/ \u6216 @ \u5524\u51FA\u8865\u5168\uFF0CShift+Enter \u6362\u884C\u3002" })] }));
66
+ // 阶梯降级:矮终端/窄终端退到词标版(大字体 35 列宽,故列数门槛 40)
62
67
  if (rows >= 30 && columns >= 40) {
63
- return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, marginBottom: GAP.tight, children: [_jsxs(Text, { children: [_jsx(Text, { color: PALETTE.accent, children: "\u2726 " }), _jsx(Text, { bold: true, children: "Pneuma" }), _jsxs(Text, { ...TEXT.secondary, children: [" v", DSC_VERSION] })] }), _jsx(BigWord, { rows: wordRows('MUSE'), from: PALETTE.brand, to: PALETTE.ice }), _jsx(Text, { children: " " }), _jsx(BigWord, { rows: wordRows('CODE'), from: PALETTE.ice, to: PALETTE.pale }), _jsx(Text, { color: PALETTE.accent, children: "\u2726 \u628A\u60F3\u6CD5\u53D8\u6210\u4EE3\u7801" }), info] }));
68
+ return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, marginBottom: GAP.tight, children: [_jsxs(Text, { children: [_jsx(Text, { color: PALETTE.accent, children: "\u2726 " }), _jsx(Text, { bold: true, children: "Pneuma" }), _jsxs(Text, { ...TEXT.secondary, children: [" v", DSC_VERSION] })] }), _jsx(BigWord, { rows: wordRows('PNEUMA'), from: PALETTE.brand, to: PALETTE.pale }), _jsx(Text, { color: PALETTE.accent, children: "\u2726 \u628A\u60F3\u6CD5\u53D8\u6210\u4EE3\u7801" }), info] }));
64
69
  }
65
70
  return (_jsxs(Box, { flexDirection: "column", gap: GAP.none, marginBottom: GAP.tight, children: [_jsxs(Text, { children: [_jsx(Text, { color: PALETTE.accent, children: "\u2726 " }), _jsx(Text, { bold: true, children: "Pneuma" }), _jsxs(Text, { ...TEXT.secondary, children: [" v", DSC_VERSION] })] }), info] }));
66
71
  }
@@ -20,8 +20,21 @@ export interface ClickEntry {
20
20
  node: RefObject<DOMElement | null>;
21
21
  /** (col, row, top, height) 均为 0 基帧内坐标。 */
22
22
  hit: (col: number, row: number, top: number, height: number) => boolean;
23
+ /**
24
+ * 够不够格当**拖动目标**(按住左键划过,SGR 1002):只有刻度列认拖动
25
+ * (拖 = 一连串跳到该行),其余区一律不派发拖动——划过去误触比「拖不动」讨厌。
26
+ */
27
+ drag?: boolean;
23
28
  }
24
29
  /** App 侧的注册表:组件渲染后登记,卸载/重渲染时自动注销。 */
25
30
  export type RegisterClick = (entry: ClickEntry) => () => void;
26
- /** 组件登记命中判定(每帧重登记;hit 闭包拿着当次渲染的 props)。 */
27
- export declare function useClickRegion(ref: RefObject<DOMElement | null>, register: RegisterClick | undefined, hit: ClickEntry['hit'] | undefined): void;
31
+ /**
32
+ * 组件登记命中判定。
33
+ *
34
+ * `hit` 走 ref、**只在挂载/卸载时登记一次**:原先没有依赖数组,每次重渲染都要把
35
+ * 帧内 80+ 个命中区退订再登记一遍(Set 的增删落在渲染提交路径上)。判定闭包拿的
36
+ * 仍是最新 props——ref 每次渲染都刷新,判定时刻读到的是当次渲染的闭包。
37
+ */
38
+ export declare function useClickRegion(ref: RefObject<DOMElement | null>, register: RegisterClick | undefined, hit: ClickEntry['hit'] | undefined, options?: {
39
+ drag?: boolean;
40
+ }): void;
package/lib/app/click.js CHANGED
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @module dsc-tui/app/click
18
18
  */
19
- import { useEffect } from 'react';
19
+ import { useEffect, useRef } from 'react';
20
20
  /** 与终端一致的显示宽度:CJK/全角/emoji 记 2 列,其余记 1 列。 */
21
21
  export function displayWidth(text) {
22
22
  let width = 0;
@@ -79,11 +79,25 @@ export function measuredWidth(node) {
79
79
  const width = node?.yogaNode?.getComputedWidth();
80
80
  return typeof width === 'number' ? width : null;
81
81
  }
82
- /** 组件登记命中判定(每帧重登记;hit 闭包拿着当次渲染的 props)。 */
83
- export function useClickRegion(ref, register, hit) {
82
+ /**
83
+ * 组件登记命中判定。
84
+ *
85
+ * `hit` 走 ref、**只在挂载/卸载时登记一次**:原先没有依赖数组,每次重渲染都要把
86
+ * 帧内 80+ 个命中区退订再登记一遍(Set 的增删落在渲染提交路径上)。判定闭包拿的
87
+ * 仍是最新 props——ref 每次渲染都刷新,判定时刻读到的是当次渲染的闭包。
88
+ */
89
+ export function useClickRegion(ref, register, hit, options) {
90
+ const hitRef = useRef(hit);
91
+ hitRef.current = hit;
92
+ const drag = options?.drag === true;
93
+ const active = register !== undefined && hit !== undefined;
84
94
  useEffect(() => {
85
- if (register === undefined || hit === undefined)
95
+ if (!active)
86
96
  return;
87
- return register({ node: ref, hit });
88
- });
97
+ return register({
98
+ node: ref,
99
+ hit: (col, row, top, height) => hitRef.current?.(col, row, top, height) ?? false,
100
+ ...(drag ? { drag: true } : {}),
101
+ });
102
+ }, [active, register, ref, drag]);
89
103
  }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 键位的单一来源:**界面上写出来的键名**都在这里,提示语由它拼。
3
+ *
4
+ * 为什么要有这一层:提示语与实际绑定漂移过一次又一次(胶囊上写 Enter/End、回看浮层写
5
+ * `[ ] 跳轮`、欢迎页写 Ctrl+T——同一批键名散在六个文件里各写一遍,改一处忘一处)。现在
6
+ * 键名只在本文件出现,组件拼句子时插值引用。
7
+ *
8
+ * 边界要说清楚(别把它当成 dsh 的组合键表):dsh 那套是**注册表**——combo 语法解析、
9
+ * 用户可改键位、输入层按 combo 匹配。我们这里只有一个「显示名」表,输入层仍是 App 里
10
+ * 逐条 `if (key.ctrl && input === 'o')` 的判断。做成可改键位得把输入层一起重写,不在这批里。
11
+ *
12
+ * @module dsc-tui/app/keymap
13
+ */
14
+ /** 界面文案里出现的键名(改这里 = 全部提示一起改)。 */
15
+ export declare const KEYS: {
16
+ /** 回看全文浮层。 */
17
+ readonly transcript: "Ctrl+O";
18
+ /** 思考块展开/折叠。 */
19
+ readonly thinking: "Ctrl+T";
20
+ /** 回到底部(输入框为空时)。 */
21
+ readonly bottom: "Enter/End";
22
+ /** 逐行滚动。 */
23
+ readonly lines: "↑↓/j·k";
24
+ /** 翻页。 */
25
+ readonly page: "PgUp/PgDn";
26
+ /** 滚轮(与逐行/翻页同义)。 */
27
+ readonly wheel: "滚轮";
28
+ /** 上一轮 / 下一轮。 */
29
+ readonly turnUp: "[";
30
+ readonly turnDown: "]";
31
+ /** 关闭浮层。 */
32
+ readonly close: "q/Esc";
33
+ /** 关闭浮层(含回看浮层自己的开关)。 */
34
+ readonly closeTranscript: "q/Esc/Ctrl+O";
35
+ readonly enter: "Enter";
36
+ readonly escape: "Esc";
37
+ readonly tab: "Tab";
38
+ readonly space: "空格";
39
+ /** 列表里的上下选择。 */
40
+ readonly pick: "↑↓";
41
+ /** 剪贴板贴图。 */
42
+ readonly paste: "Ctrl+V";
43
+ };
44
+ /** 拼好的提示语(键名一律从这里取,不再各写一遍)。 */
45
+ export declare const HINT: {
46
+ /** 回看浮层的提示行。 */
47
+ readonly transcript: "↑↓/j·k 逐行 · PgUp/PgDn 翻页 · 滚轮 同义 · [ ] 跳轮 · 点刻度也能跳 · q/Esc 关闭";
48
+ /** 子代理只读转录的提示行(同一个视口,只多「只读」与多一个关闭键)。 */
49
+ readonly peek: "只读 · ↑↓/j·k 逐行 · PgUp/PgDn 翻页 · 滚轮 同义 · [ ] 跳轮 · q/Esc/Ctrl+O 关闭";
50
+ /** 「已离开最新」胶囊(浮在转录区最后一行上)。 */
51
+ readonly backToBottom: " ↓ 回到底部(Enter/End)";
52
+ /** 思考块的折叠提示(跟在标签后面)。 */
53
+ readonly thinkingExpand: "(Ctrl+T 展开)";
54
+ /** 空会话/欢迎页那一行开场提示。 */
55
+ readonly empty: "输入消息开始对话;/help 查看命令,Esc 打断回合,Ctrl+O 回看全文。";
56
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 键位的单一来源:**界面上写出来的键名**都在这里,提示语由它拼。
3
+ *
4
+ * 为什么要有这一层:提示语与实际绑定漂移过一次又一次(胶囊上写 Enter/End、回看浮层写
5
+ * `[ ] 跳轮`、欢迎页写 Ctrl+T——同一批键名散在六个文件里各写一遍,改一处忘一处)。现在
6
+ * 键名只在本文件出现,组件拼句子时插值引用。
7
+ *
8
+ * 边界要说清楚(别把它当成 dsh 的组合键表):dsh 那套是**注册表**——combo 语法解析、
9
+ * 用户可改键位、输入层按 combo 匹配。我们这里只有一个「显示名」表,输入层仍是 App 里
10
+ * 逐条 `if (key.ctrl && input === 'o')` 的判断。做成可改键位得把输入层一起重写,不在这批里。
11
+ *
12
+ * @module dsc-tui/app/keymap
13
+ */
14
+ /** 界面文案里出现的键名(改这里 = 全部提示一起改)。 */
15
+ export const KEYS = {
16
+ /** 回看全文浮层。 */
17
+ transcript: 'Ctrl+O',
18
+ /** 思考块展开/折叠。 */
19
+ thinking: 'Ctrl+T',
20
+ /** 回到底部(输入框为空时)。 */
21
+ bottom: 'Enter/End',
22
+ /** 逐行滚动。 */
23
+ lines: '↑↓/j·k',
24
+ /** 翻页。 */
25
+ page: 'PgUp/PgDn',
26
+ /** 滚轮(与逐行/翻页同义)。 */
27
+ wheel: '滚轮',
28
+ /** 上一轮 / 下一轮。 */
29
+ turnUp: '[',
30
+ turnDown: ']',
31
+ /** 关闭浮层。 */
32
+ close: 'q/Esc',
33
+ /** 关闭浮层(含回看浮层自己的开关)。 */
34
+ closeTranscript: 'q/Esc/Ctrl+O',
35
+ enter: 'Enter',
36
+ escape: 'Esc',
37
+ tab: 'Tab',
38
+ space: '空格',
39
+ /** 列表里的上下选择。 */
40
+ pick: '↑↓',
41
+ /** 剪贴板贴图。 */
42
+ paste: 'Ctrl+V',
43
+ };
44
+ /** 拼好的提示语(键名一律从这里取,不再各写一遍)。 */
45
+ export const HINT = {
46
+ /** 回看浮层的提示行。 */
47
+ transcript: `${KEYS.lines} 逐行 · ${KEYS.page} 翻页 · ${KEYS.wheel} 同义 · ${KEYS.turnUp} ${KEYS.turnDown} 跳轮 · 点刻度也能跳 · ${KEYS.close} 关闭`,
48
+ /** 子代理只读转录的提示行(同一个视口,只多「只读」与多一个关闭键)。 */
49
+ peek: `只读 · ${KEYS.lines} 逐行 · ${KEYS.page} 翻页 · ${KEYS.wheel} 同义 · ${KEYS.turnUp} ${KEYS.turnDown} 跳轮 · ${KEYS.closeTranscript} 关闭`,
50
+ /** 「已离开最新」胶囊(浮在转录区最后一行上)。 */
51
+ backToBottom: ` ↓ 回到底部(${KEYS.bottom})`,
52
+ /** 思考块的折叠提示(跟在标签后面)。 */
53
+ thinkingExpand: `(${KEYS.thinking} 展开)`,
54
+ /** 空会话/欢迎页那一行开场提示。 */
55
+ empty: `输入消息开始对话;/help 查看命令,${KEYS.escape} 打断回合,${KEYS.transcript} 回看全文。`,
56
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * SGR 鼠标事件的分包解析(`\x1b[<b;x;yM` / `\x1b[<b;x;ym`)。
3
+ *
4
+ * 为什么要能解析「一包多条」:ink 的 `useInput` 把**一次 stdin 读取**当成一条 keypress
5
+ * 交给回调(`input` = 整包去掉首个 ESC 的原文)。终端会把连着发生的事件攒在一起发——
6
+ * 快速连点、划过刻度列的运动事件(1003)尤其如此。旧写法(锚定单条的 `/^\[<…$/`)碰上
7
+ * 一包两条就整包匹配失败,于是鼠标事件掉进普通键盘路径:轻则丢事件,重则被读成 Esc
8
+ * (「再按一次 Quit」/「打断回合」)。这里一次取出全部事件,且**只在整包确实都是鼠标
9
+ * 序列时**才认(残留任何别的字符就交回键盘路径,粘贴文本里恰好带 `[<1;2;3M` 也不会被吞)。
10
+ *
11
+ * @module dsc-tui/app/mouse
12
+ */
13
+ /** 一条 SGR 鼠标事件。 */
14
+ export interface MouseEventBit {
15
+ /**
16
+ * SGR 的 button 原始号(**未拆位**):
17
+ * 0 左键、1 中键、2 右键、32+n 「按住键 n 拖动」、35 纯移动(1003)、
18
+ * 64/65 纵向滚轮上/下、66/67 横向滚轮。
19
+ */
20
+ button: number;
21
+ /** 终端列(1 基,SGR 原样)。 */
22
+ col: number;
23
+ /** 终端行(1 基,SGR 原样)。 */
24
+ row: number;
25
+ /** `M` = 按下/移动,`m` = 松开。 */
26
+ press: boolean;
27
+ }
28
+ /**
29
+ * 把一次输入解析成鼠标事件表;不是「纯鼠标包」返回 null。
30
+ *
31
+ * @param input - `useInput` 给的原文(可能含前导 ESC 或一包多条)。
32
+ */
33
+ export declare function parseMouse(input: string): MouseEventBit[] | null;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * SGR 鼠标事件的分包解析(`\x1b[<b;x;yM` / `\x1b[<b;x;ym`)。
3
+ *
4
+ * 为什么要能解析「一包多条」:ink 的 `useInput` 把**一次 stdin 读取**当成一条 keypress
5
+ * 交给回调(`input` = 整包去掉首个 ESC 的原文)。终端会把连着发生的事件攒在一起发——
6
+ * 快速连点、划过刻度列的运动事件(1003)尤其如此。旧写法(锚定单条的 `/^\[<…$/`)碰上
7
+ * 一包两条就整包匹配失败,于是鼠标事件掉进普通键盘路径:轻则丢事件,重则被读成 Esc
8
+ * (「再按一次 Quit」/「打断回合」)。这里一次取出全部事件,且**只在整包确实都是鼠标
9
+ * 序列时**才认(残留任何别的字符就交回键盘路径,粘贴文本里恰好带 `[<1;2;3M` 也不会被吞)。
10
+ *
11
+ * @module dsc-tui/app/mouse
12
+ */
13
+ /** 一条 SGR 鼠标序列(不含前导 ESC,ink 已经剥掉第一个)。 */
14
+ const PATTERN = '\\[<(\\d+);(\\d+);(\\d+)([Mm])';
15
+ /**
16
+ * 把一次输入解析成鼠标事件表;不是「纯鼠标包」返回 null。
17
+ *
18
+ * @param input - `useInput` 给的原文(可能含前导 ESC 或一包多条)。
19
+ */
20
+ export function parseMouse(input) {
21
+ const events = [];
22
+ for (const match of input.matchAll(new RegExp(PATTERN, 'g'))) {
23
+ events.push({
24
+ button: Number(match[1]),
25
+ col: Number(match[2]),
26
+ row: Number(match[3]),
27
+ press: match[4] === 'M',
28
+ });
29
+ }
30
+ if (events.length === 0)
31
+ return null;
32
+ // 残留检查:剔掉鼠标序列与游离的 ESC,还剩字符就不认(例如粘贴进来的一整段文本)。
33
+ const residue = input.replace(new RegExp(PATTERN, 'g'), '').replace(/\x1b/g, '');
34
+ return residue === '' ? events : null;
35
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 指针是不是落在右侧刻度列上。
3
+ *
4
+ * 列要算准:帧有 `PAD.page` 列页边距,刻度列是**内容列的最后 RAIL_WIDTH 列**——直接拿
5
+ * 终端右缘(`columns - RAIL_WIDTH`)判会整体偏两列,指针压在刻度上也不认(第一次实现
6
+ * 就是这么错的,走查里点不亮)。
7
+ */
8
+ export declare function onGutter(col: number, columns: number): boolean;
9
+ /** 记一次指针位置(运动事件每来一条调一次)。 */
10
+ export declare function publishPointer(col: number, row: number, columns: number): void;
11
+ /** 清掉指针(失焦/退出这类没有 leave 事件的场合由调用方兜底)。 */
12
+ export declare function clearPointer(): void;
13
+ /** 指针在刻度列上时的终端行号(1 基);不在 = null。 */
14
+ export declare function useGutterPointer(): number | null;
15
+ /** 测试注入口:直接读当前值(探针不挂 React 也能验通知语义)。 */
16
+ export declare function readPointer(): number | null;