@causyne/agent 1.20.41 → 1.20.42
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/chatRenderer.d.ts +2 -1
- package/src/tui/chatRenderer.js +21 -8
- package/src/tui/codeStreamRenderer.js +43 -0
- package/src/tui/codeStreamRenderer.ts +39 -0
- package/src/tui/prompt.js +1 -0
- package/src/tui/thinkingBox.js +28 -5
- package/src/tui/thinkingBox.ts +31 -5
package/package.json
CHANGED
|
@@ -15,7 +15,8 @@ export class ChatRenderer {
|
|
|
15
15
|
handle(message: { type: string; [key: string]: unknown }): boolean;
|
|
16
16
|
resetTurn(): void;
|
|
17
17
|
onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
|
|
18
|
-
renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean }): void;
|
|
18
|
+
renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean; startLine?: number }): void;
|
|
19
|
+
scrollThinkingPanel?(key: unknown, surface: unknown): boolean;
|
|
19
20
|
stopSpinner(): void;
|
|
20
21
|
frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|
|
21
22
|
updateTailFrame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|
package/src/tui/chatRenderer.js
CHANGED
|
@@ -753,12 +753,14 @@ export class ChatRenderer {
|
|
|
753
753
|
collapsed: false,
|
|
754
754
|
streaming: true,
|
|
755
755
|
durationText,
|
|
756
|
-
content
|
|
756
|
+
content,
|
|
757
|
+
scrollStart: 0
|
|
757
758
|
};
|
|
758
759
|
this.frame('reasoning', () => this.renderReasoning(meta.content, {
|
|
759
760
|
streaming: true,
|
|
760
761
|
durationText: meta.durationText,
|
|
761
|
-
collapsed: Boolean(meta.collapsed)
|
|
762
|
+
collapsed: Boolean(meta.collapsed),
|
|
763
|
+
startLine: Number(meta.scrollStart) || 0
|
|
762
764
|
}), meta);
|
|
763
765
|
} else {
|
|
764
766
|
const meta = tailFrame?.meta || { reasoning: true };
|
|
@@ -766,10 +768,12 @@ export class ChatRenderer {
|
|
|
766
768
|
meta.durationText = durationText;
|
|
767
769
|
meta.content = content;
|
|
768
770
|
if (meta.collapsed === undefined) meta.collapsed = false;
|
|
771
|
+
if (meta.scrollStart === undefined) meta.scrollStart = 0;
|
|
769
772
|
this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
|
|
770
773
|
streaming: true,
|
|
771
774
|
durationText: meta.durationText,
|
|
772
|
-
collapsed: Boolean(meta.collapsed)
|
|
775
|
+
collapsed: Boolean(meta.collapsed),
|
|
776
|
+
startLine: Number(meta.scrollStart) || 0
|
|
773
777
|
}), meta);
|
|
774
778
|
}
|
|
775
779
|
return;
|
|
@@ -783,10 +787,12 @@ export class ChatRenderer {
|
|
|
783
787
|
meta.durationText = durationText;
|
|
784
788
|
meta.content = content;
|
|
785
789
|
if (meta.collapsed === undefined) meta.collapsed = false;
|
|
790
|
+
if (meta.scrollStart === undefined) meta.scrollStart = 0;
|
|
786
791
|
this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
|
|
787
792
|
streaming: false,
|
|
788
793
|
durationText: meta.durationText,
|
|
789
|
-
collapsed: Boolean(meta.collapsed)
|
|
794
|
+
collapsed: Boolean(meta.collapsed),
|
|
795
|
+
startLine: Number(meta.scrollStart) || 0
|
|
790
796
|
}), meta);
|
|
791
797
|
} else if (content.trim()) {
|
|
792
798
|
const meta = {
|
|
@@ -795,23 +801,26 @@ export class ChatRenderer {
|
|
|
795
801
|
streaming: false,
|
|
796
802
|
durationText,
|
|
797
803
|
content,
|
|
798
|
-
collapsed: false
|
|
804
|
+
collapsed: false,
|
|
805
|
+
scrollStart: 0
|
|
799
806
|
};
|
|
800
807
|
this.frame('reasoning', () => this.renderReasoning(meta.content, {
|
|
801
808
|
streaming: false,
|
|
802
809
|
durationText: meta.durationText,
|
|
803
|
-
collapsed: Boolean(meta.collapsed)
|
|
810
|
+
collapsed: Boolean(meta.collapsed),
|
|
811
|
+
startLine: Number(meta.scrollStart) || 0
|
|
804
812
|
}), meta);
|
|
805
813
|
}
|
|
806
814
|
}
|
|
807
815
|
|
|
808
|
-
renderReasoning(content, { streaming = false, durationText = '', collapsed = false } = {}) {
|
|
816
|
+
renderReasoning(content, { streaming = false, durationText = '', collapsed = false, startLine = 0 } = {}) {
|
|
809
817
|
const width = this.measure();
|
|
810
818
|
const rows = renderThinkingFrame(content, {
|
|
811
819
|
width,
|
|
812
820
|
streaming,
|
|
813
821
|
durationText,
|
|
814
|
-
collapsed
|
|
822
|
+
collapsed,
|
|
823
|
+
startLine: Number(startLine) || 0
|
|
815
824
|
});
|
|
816
825
|
|
|
817
826
|
if (rows.length === 0) return;
|
|
@@ -823,6 +832,10 @@ export class ChatRenderer {
|
|
|
823
832
|
this.write();
|
|
824
833
|
}
|
|
825
834
|
|
|
835
|
+
scrollThinkingPanel(key, surface) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
|
|
826
839
|
onAgentActivity(msg) {
|
|
827
840
|
const text = String(msg.activity || msg.message || '').trim();
|
|
828
841
|
if (!text) return;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChatRenderer } from './chatRenderer.js';
|
|
2
2
|
import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress } from './codeProgress.js';
|
|
3
|
+
import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
|
|
3
4
|
function lastStart(event) {
|
|
4
5
|
return Math.max(0, codePreviewLineCount(event) - CODE_PANEL_LINES);
|
|
5
6
|
}
|
|
@@ -48,6 +49,48 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
48
49
|
transcript.changed();
|
|
49
50
|
return true;
|
|
50
51
|
}
|
|
52
|
+
/** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
|
|
53
|
+
scrollThinkingPanel(key, surface) {
|
|
54
|
+
const wheel = key.wheel;
|
|
55
|
+
if (key.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
|
|
56
|
+
return false;
|
|
57
|
+
const transcript = this.transcript;
|
|
58
|
+
if (!transcript || !Number.isFinite(surface.out.rows) || !Number.isFinite(wheel.x) || !Number.isFinite(wheel.y))
|
|
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()))
|
|
64
|
+
return false;
|
|
65
|
+
const { markers } = transcript.flatten(viewport.viewWidth);
|
|
66
|
+
const absoluteY = viewport.scrollTop + localY;
|
|
67
|
+
const markerIndex = markers.findIndex((marker, index) => marker.row <= absoluteY
|
|
68
|
+
&& (index + 1 === markers.length || absoluteY < markers[index + 1].row));
|
|
69
|
+
if (markerIndex < 0)
|
|
70
|
+
return false;
|
|
71
|
+
const marker = markers[markerIndex];
|
|
72
|
+
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
73
|
+
if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed)
|
|
74
|
+
return false;
|
|
75
|
+
if (absoluteY >= marker.row + (frame.rows?.length || 0))
|
|
76
|
+
return false;
|
|
77
|
+
const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
|
|
78
|
+
const totalLines = calculateThinkingLineCount(content, viewport.viewWidth);
|
|
79
|
+
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
80
|
+
if (limit === 0)
|
|
81
|
+
return false;
|
|
82
|
+
const currentStart = Number(frame.meta.scrollStart) || 0;
|
|
83
|
+
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -3 : 3)));
|
|
84
|
+
if (next === currentStart)
|
|
85
|
+
return true;
|
|
86
|
+
frame.meta.scrollStart = next;
|
|
87
|
+
frame.rows = null;
|
|
88
|
+
frame.renderedWidth = -1;
|
|
89
|
+
transcript.cache = null;
|
|
90
|
+
transcript.revision++;
|
|
91
|
+
transcript.changed();
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
51
94
|
resetTurn() {
|
|
52
95
|
this._activeReasoning = false;
|
|
53
96
|
this.activeCode = null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChatRenderer } from './chatRenderer.js';
|
|
2
2
|
import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress, type CodeProgressEvent } from './codeProgress.js';
|
|
3
|
+
import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
|
|
3
4
|
|
|
4
5
|
type RendererEvent = { type: string; [key: string]: unknown };
|
|
5
6
|
type CodePanelState = { event: CodeProgressEvent; modelNote: string; start: number; followTail: boolean };
|
|
@@ -62,6 +63,44 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
/** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
|
|
67
|
+
override scrollThinkingPanel(key: CodeWheel, surface: CodeSurface | null): boolean {
|
|
68
|
+
const wheel = key.wheel;
|
|
69
|
+
if (key.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
|
|
70
|
+
const transcript = this.transcript as unknown as CodeTranscript | null;
|
|
71
|
+
if (!transcript || !Number.isFinite(surface.out.rows) || !Number.isFinite(wheel.x) || !Number.isFinite(wheel.y)) return false;
|
|
72
|
+
const viewport = surface.viewport;
|
|
73
|
+
const screenTop = (surface.out.rows as number) - surface.stage.height;
|
|
74
|
+
const localY = wheel.y - screenTop;
|
|
75
|
+
if (localY < 0 || localY >= viewport.viewHeight || wheel.x < 0 || wheel.x >= Math.min(viewport.viewWidth, this.measure())) return false;
|
|
76
|
+
const { markers } = transcript.flatten(viewport.viewWidth);
|
|
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]!;
|
|
82
|
+
const frame = transcript.frames.find(item => item.id === marker.id);
|
|
83
|
+
if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed) return false;
|
|
84
|
+
if (absoluteY >= marker.row + (frame.rows?.length || 0)) return false;
|
|
85
|
+
|
|
86
|
+
const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
|
|
87
|
+
const totalLines = calculateThinkingLineCount(content, viewport.viewWidth);
|
|
88
|
+
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
89
|
+
if (limit === 0) return false;
|
|
90
|
+
|
|
91
|
+
const currentStart = Number(frame.meta.scrollStart) || 0;
|
|
92
|
+
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -3 : 3)));
|
|
93
|
+
if (next === currentStart) return true;
|
|
94
|
+
|
|
95
|
+
frame.meta.scrollStart = next;
|
|
96
|
+
frame.rows = null;
|
|
97
|
+
frame.renderedWidth = -1;
|
|
98
|
+
transcript.cache = null;
|
|
99
|
+
transcript.revision++;
|
|
100
|
+
transcript.changed();
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
65
104
|
override resetTurn(): void {
|
|
66
105
|
this._activeReasoning = false;
|
|
67
106
|
this.activeCode = null;
|
package/src/tui/prompt.js
CHANGED
|
@@ -920,6 +920,7 @@ export class ChatPrompt {
|
|
|
920
920
|
if (key.name === 'wheel') {
|
|
921
921
|
if (!viewport || !key.wheel) return true;
|
|
922
922
|
if (this.renderer?.scrollCodePanel?.(key, this.surface)) return true;
|
|
923
|
+
if (this.renderer?.scrollThinkingPanel?.(key, this.surface)) return true;
|
|
923
924
|
|
|
924
925
|
return handleViewportWheel(key, viewport, this.surface, this);
|
|
925
926
|
}
|
package/src/tui/thinkingBox.js
CHANGED
|
@@ -10,6 +10,17 @@ import { paint, bold, dim, GLYPHS, HAS_UNICODE } from './theme.js';
|
|
|
10
10
|
import { padEnd, truncate, visibleWidth, wrapBlock } from './text.js';
|
|
11
11
|
export const DEFAULT_MAX_STREAMING_LINES = 8;
|
|
12
12
|
export const DEFAULT_MAX_EXPANDED_LINES = 12;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates total wrapped lines for reasoning content under the thinking box budget.
|
|
15
|
+
*/
|
|
16
|
+
export function calculateThinkingLineCount(content, width) {
|
|
17
|
+
const text = String(content ?? '').trim();
|
|
18
|
+
if (!text)
|
|
19
|
+
return 0;
|
|
20
|
+
const safeWidth = Math.max(20, Math.floor(width));
|
|
21
|
+
const contentBudget = Math.max(10, safeWidth - 4);
|
|
22
|
+
return wrapBlock(text, contentBudget).length;
|
|
23
|
+
}
|
|
13
24
|
/**
|
|
14
25
|
* Single-line compact badge for collapsed reasoning frames.
|
|
15
26
|
*/
|
|
@@ -123,13 +134,25 @@ export function renderThinkingFrame(content, options = {}) {
|
|
|
123
134
|
const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, collapseHint, width, 'rule');
|
|
124
135
|
const rows = [top];
|
|
125
136
|
if (totalLines > maxLines) {
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
137
|
+
const limit = Math.max(0, totalLines - maxLines);
|
|
138
|
+
const start = Math.max(0, Math.min(limit, Math.floor(options.startLine ?? 0)));
|
|
139
|
+
const visible = allRows.slice(start, start + maxLines);
|
|
140
|
+
for (const row of visible) {
|
|
129
141
|
rows.push(wrapRow(dim(row)));
|
|
130
142
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
143
|
+
const hiddenBelow = totalLines - (start + visible.length);
|
|
144
|
+
if (hiddenBelow > 0) {
|
|
145
|
+
const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenBelow} more line${hiddenBelow === 1 ? '' : 's'} of reasoning`;
|
|
146
|
+
rows.push(wrapRow(dim(moreNotice)));
|
|
147
|
+
}
|
|
148
|
+
else if (start > 0) {
|
|
149
|
+
const earlierNotice = `${HAS_UNICODE ? '↑' : '^'} ${start} earlier line${start === 1 ? '' : 's'} scrolled above`;
|
|
150
|
+
rows.push(wrapRow(dim(earlierNotice)));
|
|
151
|
+
}
|
|
152
|
+
const upArrow = start > 0 ? (HAS_UNICODE ? '↑ ' : '^ ') : '';
|
|
153
|
+
const downArrow = start + visible.length < totalLines ? (HAS_UNICODE ? ' ↓' : ' v') : '';
|
|
154
|
+
const scrollInfo = `${upArrow}lines ${start + 1}–${start + visible.length} of ${totalLines}${downArrow} · scroll over thinking`;
|
|
155
|
+
rows.push(wrapRow(dim(scrollInfo)));
|
|
133
156
|
}
|
|
134
157
|
else {
|
|
135
158
|
for (const row of allRows) {
|
package/src/tui/thinkingBox.ts
CHANGED
|
@@ -17,11 +17,23 @@ export interface ThinkingFrameOptions {
|
|
|
17
17
|
collapsed?: boolean;
|
|
18
18
|
maxVisibleLines?: number;
|
|
19
19
|
role?: string;
|
|
20
|
+
startLine?: number;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export const DEFAULT_MAX_STREAMING_LINES = 8;
|
|
23
24
|
export const DEFAULT_MAX_EXPANDED_LINES = 12;
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Calculates total wrapped lines for reasoning content under the thinking box budget.
|
|
28
|
+
*/
|
|
29
|
+
export function calculateThinkingLineCount(content: string, width: number): number {
|
|
30
|
+
const text = String(content ?? '').trim();
|
|
31
|
+
if (!text) return 0;
|
|
32
|
+
const safeWidth = Math.max(20, Math.floor(width));
|
|
33
|
+
const contentBudget = Math.max(10, safeWidth - 4);
|
|
34
|
+
return wrapBlock(text, contentBudget).length;
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
/**
|
|
26
38
|
* Single-line compact badge for collapsed reasoning frames.
|
|
27
39
|
*/
|
|
@@ -172,13 +184,27 @@ export function renderThinkingFrame(
|
|
|
172
184
|
const rows: string[] = [top];
|
|
173
185
|
|
|
174
186
|
if (totalLines > maxLines) {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
187
|
+
const limit = Math.max(0, totalLines - maxLines);
|
|
188
|
+
const start = Math.max(0, Math.min(limit, Math.floor(options.startLine ?? 0)));
|
|
189
|
+
const visible = allRows.slice(start, start + maxLines);
|
|
190
|
+
|
|
191
|
+
for (const row of visible) {
|
|
178
192
|
rows.push(wrapRow(dim(row)));
|
|
179
193
|
}
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
|
|
195
|
+
const hiddenBelow = totalLines - (start + visible.length);
|
|
196
|
+
if (hiddenBelow > 0) {
|
|
197
|
+
const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenBelow} more line${hiddenBelow === 1 ? '' : 's'} of reasoning`;
|
|
198
|
+
rows.push(wrapRow(dim(moreNotice)));
|
|
199
|
+
} else if (start > 0) {
|
|
200
|
+
const earlierNotice = `${HAS_UNICODE ? '↑' : '^'} ${start} earlier line${start === 1 ? '' : 's'} scrolled above`;
|
|
201
|
+
rows.push(wrapRow(dim(earlierNotice)));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const upArrow = start > 0 ? (HAS_UNICODE ? '↑ ' : '^ ') : '';
|
|
205
|
+
const downArrow = start + visible.length < totalLines ? (HAS_UNICODE ? ' ↓' : ' v') : '';
|
|
206
|
+
const scrollInfo = `${upArrow}lines ${start + 1}–${start + visible.length} of ${totalLines}${downArrow} · scroll over thinking`;
|
|
207
|
+
rows.push(wrapRow(dim(scrollInfo)));
|
|
182
208
|
} else {
|
|
183
209
|
for (const row of allRows) {
|
|
184
210
|
rows.push(wrapRow(dim(row)));
|