@causyne/agent 1.20.42 → 1.20.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/tui/codeStreamRenderer.js +20 -35
- package/src/tui/codeStreamRenderer.ts +25 -32
- package/src/tui/completion.js +18 -19
- package/src/tui/keys.js +18 -0
- package/src/tui/messageInteraction.js +15 -8
- package/src/tui/messageInteraction.ts +14 -8
- package/src/tui/prompt.js +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChatRenderer } from './chatRenderer.js';
|
|
2
2
|
import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress } from './codeProgress.js';
|
|
3
3
|
import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
|
|
4
|
+
import { markerAt } from './messageInteraction.js';
|
|
4
5
|
function lastStart(event) {
|
|
5
6
|
return Math.max(0, codePreviewLineCount(event) - CODE_PANEL_LINES);
|
|
6
7
|
}
|
|
@@ -12,34 +13,27 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
12
13
|
codePanels = new WeakMap();
|
|
13
14
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
14
15
|
scrollCodePanel(key, surface) {
|
|
15
|
-
const wheel = key
|
|
16
|
-
if (key
|
|
16
|
+
const wheel = key?.wheel;
|
|
17
|
+
if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
|
|
17
18
|
return false;
|
|
18
|
-
const transcript = this.transcript;
|
|
19
|
-
if (!transcript
|
|
20
|
-
return false;
|
|
21
|
-
const viewport = surface.viewport;
|
|
22
|
-
const screenTop = surface.out.rows - surface.stage.height;
|
|
23
|
-
const localY = wheel.y - screenTop;
|
|
24
|
-
if (localY < 0 || localY >= viewport.viewHeight || wheel.x < 0 || wheel.x >= Math.min(viewport.viewWidth, this.measure()))
|
|
19
|
+
const transcript = (this.transcript || surface.transcript);
|
|
20
|
+
if (!transcript)
|
|
25
21
|
return false;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
if (markerIndex < 0)
|
|
22
|
+
if (!surface.transcript)
|
|
23
|
+
surface.transcript = transcript;
|
|
24
|
+
const marker = markerAt(surface, { x: wheel.x, y: wheel.y });
|
|
25
|
+
if (!marker)
|
|
31
26
|
return false;
|
|
32
|
-
const marker = markers[markerIndex];
|
|
33
27
|
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
34
28
|
const state = frame && this.codePanels.get(frame);
|
|
35
|
-
if (!frame || !state
|
|
29
|
+
if (!frame || !state)
|
|
36
30
|
return false;
|
|
37
31
|
const limit = lastStart(state.event);
|
|
38
32
|
if (limit === 0)
|
|
39
33
|
return false;
|
|
40
34
|
const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -3 : 3)));
|
|
41
35
|
if (next === state.start)
|
|
42
|
-
return
|
|
36
|
+
return true;
|
|
43
37
|
state.start = next;
|
|
44
38
|
state.followTail = next === limit;
|
|
45
39
|
frame.rows = null;
|
|
@@ -51,31 +45,22 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
51
45
|
}
|
|
52
46
|
/** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
|
|
53
47
|
scrollThinkingPanel(key, surface) {
|
|
54
|
-
const wheel = key
|
|
55
|
-
if (key
|
|
48
|
+
const wheel = key?.wheel;
|
|
49
|
+
if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
|
|
56
50
|
return false;
|
|
57
|
-
const transcript = this.transcript;
|
|
58
|
-
if (!transcript
|
|
59
|
-
return false;
|
|
60
|
-
const viewport = surface.viewport;
|
|
61
|
-
const screenTop = surface.out.rows - surface.stage.height;
|
|
62
|
-
const localY = wheel.y - screenTop;
|
|
63
|
-
if (localY < 0 || localY >= viewport.viewHeight || wheel.x < 0 || wheel.x >= Math.min(viewport.viewWidth, this.measure()))
|
|
51
|
+
const transcript = (this.transcript || surface.transcript);
|
|
52
|
+
if (!transcript)
|
|
64
53
|
return false;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
if (markerIndex < 0)
|
|
54
|
+
if (!surface.transcript)
|
|
55
|
+
surface.transcript = transcript;
|
|
56
|
+
const marker = markerAt(surface, { x: wheel.x, y: wheel.y });
|
|
57
|
+
if (!marker || marker.kind !== 'reasoning')
|
|
70
58
|
return false;
|
|
71
|
-
const marker = markers[markerIndex];
|
|
72
59
|
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
73
60
|
if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed)
|
|
74
61
|
return false;
|
|
75
|
-
if (absoluteY >= marker.row + (frame.rows?.length || 0))
|
|
76
|
-
return false;
|
|
77
62
|
const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
|
|
78
|
-
const totalLines = calculateThinkingLineCount(content,
|
|
63
|
+
const totalLines = calculateThinkingLineCount(content, this.measure());
|
|
79
64
|
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
80
65
|
if (limit === 0)
|
|
81
66
|
return false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChatRenderer } from './chatRenderer.js';
|
|
2
2
|
import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress, type CodeProgressEvent } from './codeProgress.js';
|
|
3
3
|
import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
|
|
4
|
+
import { markerAt } from './messageInteraction.js';
|
|
4
5
|
|
|
5
6
|
type RendererEvent = { type: string; [key: string]: unknown };
|
|
6
7
|
type CodePanelState = { event: CodeProgressEvent; modelNote: string; start: number; followTail: boolean };
|
|
@@ -32,27 +33,25 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
32
33
|
|
|
33
34
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
34
35
|
scrollCodePanel(key: CodeWheel, surface: CodeSurface | null): boolean {
|
|
35
|
-
const wheel = key
|
|
36
|
-
if (key
|
|
37
|
-
const transcript = this.transcript as unknown as CodeTranscript | null;
|
|
38
|
-
if (!transcript
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
const absoluteY = viewport.scrollTop + localY;
|
|
45
|
-
const markerIndex = markers.findIndex((marker, index) => marker.row <= absoluteY
|
|
46
|
-
&& (index + 1 === markers.length || absoluteY < markers[index + 1]!.row));
|
|
47
|
-
if (markerIndex < 0) return false;
|
|
48
|
-
const marker = markers[markerIndex]!;
|
|
36
|
+
const wheel = key?.wheel;
|
|
37
|
+
if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
|
|
38
|
+
const transcript = (this.transcript || (surface as any).transcript) as unknown as CodeTranscript | null;
|
|
39
|
+
if (!transcript) return false;
|
|
40
|
+
if (!(surface as any).transcript) (surface as any).transcript = transcript;
|
|
41
|
+
|
|
42
|
+
const marker = markerAt(surface as any, { x: wheel.x, y: wheel.y });
|
|
43
|
+
if (!marker) return false;
|
|
44
|
+
|
|
49
45
|
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
50
46
|
const state = frame && this.codePanels.get(frame);
|
|
51
|
-
if (!frame || !state
|
|
47
|
+
if (!frame || !state) return false;
|
|
48
|
+
|
|
52
49
|
const limit = lastStart(state.event);
|
|
53
50
|
if (limit === 0) return false;
|
|
51
|
+
|
|
54
52
|
const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -3 : 3)));
|
|
55
|
-
if (next === state.start) return
|
|
53
|
+
if (next === state.start) return true;
|
|
54
|
+
|
|
56
55
|
state.start = next;
|
|
57
56
|
state.followTail = next === limit;
|
|
58
57
|
frame.rows = null;
|
|
@@ -65,26 +64,20 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
65
64
|
|
|
66
65
|
/** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
|
|
67
66
|
override scrollThinkingPanel(key: CodeWheel, surface: CodeSurface | null): boolean {
|
|
68
|
-
const wheel = key
|
|
69
|
-
if (key
|
|
70
|
-
const transcript = this.transcript as unknown as CodeTranscript | null;
|
|
71
|
-
if (!transcript
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
const absoluteY = viewport.scrollTop + localY;
|
|
78
|
-
const markerIndex = markers.findIndex((marker, index) => marker.row <= absoluteY
|
|
79
|
-
&& (index + 1 === markers.length || absoluteY < markers[index + 1]!.row));
|
|
80
|
-
if (markerIndex < 0) return false;
|
|
81
|
-
const marker = markers[markerIndex]!;
|
|
67
|
+
const wheel = key?.wheel;
|
|
68
|
+
if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
|
|
69
|
+
const transcript = (this.transcript || (surface as any).transcript) as unknown as CodeTranscript | null;
|
|
70
|
+
if (!transcript) return false;
|
|
71
|
+
if (!(surface as any).transcript) (surface as any).transcript = transcript;
|
|
72
|
+
|
|
73
|
+
const marker = markerAt(surface as any, { x: wheel.x, y: wheel.y });
|
|
74
|
+
if (!marker || marker.kind !== 'reasoning') return false;
|
|
75
|
+
|
|
82
76
|
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
83
77
|
if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed) return false;
|
|
84
|
-
if (absoluteY >= marker.row + (frame.rows?.length || 0)) return false;
|
|
85
78
|
|
|
86
79
|
const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
|
|
87
|
-
const totalLines = calculateThinkingLineCount(content,
|
|
80
|
+
const totalLines = calculateThinkingLineCount(content, this.measure());
|
|
88
81
|
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
89
82
|
if (limit === 0) return false;
|
|
90
83
|
|
package/src/tui/completion.js
CHANGED
|
@@ -93,11 +93,26 @@ function rank(items, query, limit = 50, focusDir = null) {
|
|
|
93
93
|
for (const item of items) {
|
|
94
94
|
const val = item.match !== undefined ? item.match : item.value;
|
|
95
95
|
let value = score(val, query);
|
|
96
|
+
let matchedAlias = null;
|
|
97
|
+
|
|
98
|
+
if (Array.isArray(item.aliases) && query) {
|
|
99
|
+
for (const alias of item.aliases) {
|
|
100
|
+
const aliasScore = score(alias, query);
|
|
101
|
+
if (aliasScore > value) {
|
|
102
|
+
value = aliasScore;
|
|
103
|
+
matchedAlias = alias;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
if (value >= 0) {
|
|
97
109
|
if (focusPrefix && val.toLowerCase().startsWith(focusPrefix)) {
|
|
98
110
|
value += 3000;
|
|
99
111
|
}
|
|
100
|
-
|
|
112
|
+
const resultItem = matchedAlias
|
|
113
|
+
? { ...item, description: `(alias: /${matchedAlias}) ${item.description}` }
|
|
114
|
+
: item;
|
|
115
|
+
scored.push({ item: resultItem, value });
|
|
101
116
|
}
|
|
102
117
|
}
|
|
103
118
|
scored.sort((a, b) => b.value - a.value);
|
|
@@ -140,27 +155,11 @@ function commandItems() {
|
|
|
140
155
|
commands.push({
|
|
141
156
|
value: primaryLabel,
|
|
142
157
|
match: command.name,
|
|
158
|
+
aliases: Array.isArray(command.aliases) ? command.aliases.filter(isTerminalSafe) : [],
|
|
143
159
|
label: primaryLabel,
|
|
144
160
|
description: sanitize(command.description || '')
|
|
145
161
|
});
|
|
146
162
|
}
|
|
147
|
-
|
|
148
|
-
// Include aliases (e.g. /models, /session, /reset) so they match cleanly and resolve to canonical command
|
|
149
|
-
if (Array.isArray(command.aliases)) {
|
|
150
|
-
for (const alias of command.aliases) {
|
|
151
|
-
if (!isTerminalSafe(alias)) continue;
|
|
152
|
-
const aliasLabel = '/' + alias;
|
|
153
|
-
if (!seenLabels.has(aliasLabel)) {
|
|
154
|
-
seenLabels.add(aliasLabel);
|
|
155
|
-
commands.push({
|
|
156
|
-
value: primaryLabel,
|
|
157
|
-
match: alias,
|
|
158
|
-
label: aliasLabel,
|
|
159
|
-
description: sanitize(command.description || '')
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
// Skills answer to the slash menu directly, the way claude-code surfaces a
|
|
@@ -188,7 +187,7 @@ function commandItems() {
|
|
|
188
187
|
*/
|
|
189
188
|
function argumentItems(name) {
|
|
190
189
|
const command = listCommands('terminal')
|
|
191
|
-
.find((candidate) => candidate.name === name && isTerminalSafe(candidate.name));
|
|
190
|
+
.find((candidate) => (candidate.name === name || (Array.isArray(candidate.aliases) && candidate.aliases.includes(name))) && isTerminalSafe(candidate.name));
|
|
192
191
|
if (!command || typeof command.complete !== 'function') return [];
|
|
193
192
|
|
|
194
193
|
let produced;
|
package/src/tui/keys.js
CHANGED
|
@@ -113,6 +113,24 @@ export class KeyDecoder {
|
|
|
113
113
|
|
|
114
114
|
if (byte === 0x1b) return this.stepEscape(buffer, offset, events);
|
|
115
115
|
|
|
116
|
+
// Orphaned SGR mouse sequence: [ < b ; x ; y M|m
|
|
117
|
+
// Occurs when \x1b is consumed on a chunk boundary or dropped over PTY.
|
|
118
|
+
// Intercepting here prevents raw sequence strings like `[<64;119;43M` from
|
|
119
|
+
// leaking into the prompt input box as literal character keystrokes.
|
|
120
|
+
if (byte === 0x5b && buffer.length - offset >= 3 && buffer[offset + 1] === 0x3c) {
|
|
121
|
+
const text = buffer.toString('utf8', offset);
|
|
122
|
+
if (!/[Mm]/.test(text)) return 0; // Incomplete sequence; wait for subsequent bytes in this.pending
|
|
123
|
+
const match = /^\[<(\d+);(\d+);(\d+)([Mm])/.exec(text);
|
|
124
|
+
if (match) {
|
|
125
|
+
const code = parseInt(match[1], 10);
|
|
126
|
+
const col = parseInt(match[2], 10);
|
|
127
|
+
const row = parseInt(match[3], 10);
|
|
128
|
+
const pressed = match[4] === 'M';
|
|
129
|
+
this.emitMouse([code, col, row], pressed, match[0], events);
|
|
130
|
+
return match[0].length;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
116
134
|
if (byte === 0x0d || byte === 0x0a) {
|
|
117
135
|
events.push(makeKey('enter', { sequence: String.fromCharCode(byte) }));
|
|
118
136
|
return 1;
|
|
@@ -150,19 +150,26 @@ const isMessage = (marker) => (marker.kind === 'user' || marker.kind === 'assist
|
|
|
150
150
|
&& typeof marker.meta?.messageText === 'string';
|
|
151
151
|
/** Resolve screen coordinates against the painted viewport to find any frame marker. */
|
|
152
152
|
export function markerAt(surface, point) {
|
|
153
|
-
if (!surface?.
|
|
153
|
+
if (!surface || surface.stage?.reserved === false || !Number.isFinite(point.x) || !Number.isFinite(point.y))
|
|
154
154
|
return null;
|
|
155
|
-
const
|
|
155
|
+
const surfWidth = surface.width || surface.viewport?.viewWidth || surface.viewport?.width || 80;
|
|
156
|
+
const mainWidth = sidebarVisible(surfWidth) ? sessionMainWidth(surfWidth) : surfWidth;
|
|
156
157
|
const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
|
|
157
|
-
|
|
158
|
+
const viewWidth = surface.viewport?.viewWidth || surface.viewport?.width || surfWidth;
|
|
159
|
+
if (point.x < leftGutter || point.x >= Math.min(mainWidth, viewWidth + leftGutter))
|
|
158
160
|
return null;
|
|
159
|
-
const
|
|
161
|
+
const stageHeight = surface.stage?.height ?? 24;
|
|
162
|
+
const top = Math.max(0, (surface.out?.rows || stageHeight) - stageHeight);
|
|
160
163
|
const viewRow = point.y - top;
|
|
161
|
-
|
|
164
|
+
const viewHeight = surface.viewport?.viewHeight || surface.viewport?.height || stageHeight;
|
|
165
|
+
if (viewRow < 0 || viewRow >= viewHeight)
|
|
162
166
|
return null;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
const transcript = surface.transcript || surface.renderer?.transcript;
|
|
168
|
+
if (!transcript)
|
|
169
|
+
return null;
|
|
170
|
+
const flat = transcript.flatten(viewWidth);
|
|
171
|
+
const visible = Math.max(0, Math.min(viewHeight, flat.rows.length - surface.viewport.scrollTop));
|
|
172
|
+
const padding = viewHeight - visible;
|
|
166
173
|
if (viewRow < padding)
|
|
167
174
|
return null;
|
|
168
175
|
const row = surface.viewport.scrollTop + viewRow - padding;
|
|
@@ -239,16 +239,22 @@ const isMessage = (marker: MessageMarker): boolean =>
|
|
|
239
239
|
|
|
240
240
|
/** Resolve screen coordinates against the painted viewport to find any frame marker. */
|
|
241
241
|
export function markerAt(surface: MessageSurface | null, point: MousePoint): MessageMarker | null {
|
|
242
|
-
if (!surface?.
|
|
243
|
-
const
|
|
242
|
+
if (!surface || surface.stage?.reserved === false || !Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
|
|
243
|
+
const surfWidth = surface.width || (surface.viewport as any)?.viewWidth || surface.viewport?.width || 80;
|
|
244
|
+
const mainWidth = sidebarVisible(surfWidth) ? sessionMainWidth(surfWidth) : surfWidth;
|
|
244
245
|
const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
const viewWidth = (surface.viewport as any)?.viewWidth || surface.viewport?.width || surfWidth;
|
|
247
|
+
if (point.x < leftGutter || point.x >= Math.min(mainWidth, viewWidth + leftGutter)) return null;
|
|
248
|
+
const stageHeight = surface.stage?.height ?? 24;
|
|
249
|
+
const top = Math.max(0, ((surface.out?.rows as number) || stageHeight) - stageHeight);
|
|
247
250
|
const viewRow = point.y - top;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
251
|
+
const viewHeight = (surface.viewport as any)?.viewHeight || surface.viewport?.height || stageHeight;
|
|
252
|
+
if (viewRow < 0 || viewRow >= viewHeight) return null;
|
|
253
|
+
const transcript = surface.transcript || (surface as any).renderer?.transcript;
|
|
254
|
+
if (!transcript) return null;
|
|
255
|
+
const flat = transcript.flatten(viewWidth);
|
|
256
|
+
const visible = Math.max(0, Math.min(viewHeight, flat.rows.length - surface.viewport.scrollTop));
|
|
257
|
+
const padding = viewHeight - visible;
|
|
252
258
|
if (viewRow < padding) return null;
|
|
253
259
|
const row = surface.viewport.scrollTop + viewRow - padding;
|
|
254
260
|
for (let i = flat.markers.length - 1; i >= 0; i--) {
|
package/src/tui/prompt.js
CHANGED
|
@@ -919,8 +919,14 @@ export class ChatPrompt {
|
|
|
919
919
|
}
|
|
920
920
|
if (key.name === 'wheel') {
|
|
921
921
|
if (!viewport || !key.wheel) return true;
|
|
922
|
-
if (this.renderer?.scrollCodePanel?.(key, this.surface))
|
|
923
|
-
|
|
922
|
+
if (this.renderer?.scrollCodePanel?.(key, this.surface)) {
|
|
923
|
+
this.draw();
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
if (this.renderer?.scrollThinkingPanel?.(key, this.surface)) {
|
|
927
|
+
this.draw();
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
924
930
|
|
|
925
931
|
return handleViewportWheel(key, viewport, this.surface, this);
|
|
926
932
|
}
|