@causyne/agent 1.20.50 → 1.20.54
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/agentLoop.js +35 -4
- package/src/agentLoop.ts +32 -4
- package/src/tui/block.js +56 -100
- package/src/tui/block.ts +139 -0
- package/src/tui/chatRenderer.d.ts +2 -2
- package/src/tui/chatRenderer.js +38 -8
- package/src/tui/codeStreamRenderer.js +73 -5
- package/src/tui/codeStreamRenderer.ts +80 -6
- package/src/tui/prompt.js +9 -6
- package/src/tui/scrollInteraction.js +93 -5
- package/src/tui/scrollInteraction.ts +113 -5
- package/src/tui/stageSurface.js +27 -6
- package/src/tui/theme.js +3 -4
- package/src/tui/thinkingBox.js +67 -5
- package/src/tui/thinkingBox.ts +59 -5
- package/src/tui/turnRail.js +9 -0
- package/src/tui/turnRail.ts +10 -0
- package/src/tui/viewport.js +6 -0
- package/src/tui/viewport.ts +7 -0
- package/src/tui/block.d.ts +0 -1
|
@@ -2,6 +2,7 @@ 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
4
|
import { markerAt } from './messageInteraction.js';
|
|
5
|
+
import { AdaptiveWheelDampener } from './scrollInteraction.js';
|
|
5
6
|
function lastStart(event) {
|
|
6
7
|
return Math.max(0, codePreviewLineCount(event) - CODE_PANEL_LINES);
|
|
7
8
|
}
|
|
@@ -10,6 +11,7 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
10
11
|
activeCode = null;
|
|
11
12
|
modelNote = '';
|
|
12
13
|
lastReasoning = '';
|
|
14
|
+
currentActivity = 'thinking';
|
|
13
15
|
codePanels = new WeakMap();
|
|
14
16
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
15
17
|
scrollCodePanel(key, surface) {
|
|
@@ -31,7 +33,13 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
31
33
|
const limit = lastStart(state.event);
|
|
32
34
|
if (limit === 0)
|
|
33
35
|
return false;
|
|
34
|
-
|
|
36
|
+
if (!state.dampener) {
|
|
37
|
+
state.dampener = new AdaptiveWheelDampener();
|
|
38
|
+
}
|
|
39
|
+
const delta = state.dampener.stepRows(wheel.direction, 3);
|
|
40
|
+
if (delta === 0)
|
|
41
|
+
return true;
|
|
42
|
+
const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -delta : delta)));
|
|
35
43
|
if (next === state.start)
|
|
36
44
|
return true;
|
|
37
45
|
state.start = next;
|
|
@@ -64,8 +72,15 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
64
72
|
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
65
73
|
if (limit === 0)
|
|
66
74
|
return false;
|
|
75
|
+
if (!frame.meta._dampener) {
|
|
76
|
+
frame.meta._dampener = new AdaptiveWheelDampener();
|
|
77
|
+
}
|
|
78
|
+
const dampener = frame.meta._dampener;
|
|
79
|
+
const delta = dampener.stepRows(wheel.direction, 3);
|
|
80
|
+
if (delta === 0)
|
|
81
|
+
return true;
|
|
67
82
|
const currentStart = Number(frame.meta.scrollStart) || 0;
|
|
68
|
-
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -
|
|
83
|
+
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -delta : delta)));
|
|
69
84
|
if (next === currentStart)
|
|
70
85
|
return true;
|
|
71
86
|
frame.meta.scrollStart = next;
|
|
@@ -113,8 +128,53 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
130
|
handle(message) {
|
|
131
|
+
if (message?.type === 'agent_activity') {
|
|
132
|
+
const rawActivity = String(message.activity || message.message || '').trim();
|
|
133
|
+
if (rawActivity) {
|
|
134
|
+
this.currentActivity = rawActivity.replace(/…|\.\.\.$/, '').trim();
|
|
135
|
+
if (this._activeReasoning && this.lastReasoning) {
|
|
136
|
+
super.onAgentReasoning({
|
|
137
|
+
content: this.lastReasoning,
|
|
138
|
+
streaming: true,
|
|
139
|
+
activity: this.currentActivity,
|
|
140
|
+
title: rawActivity
|
|
141
|
+
});
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
116
146
|
if (message?.type === 'notice' && message.nativeStep === true) {
|
|
117
147
|
this.stepCount = (this.stepCount || 0) + 1;
|
|
148
|
+
const stepLine = String(message.message || '').trim();
|
|
149
|
+
if (stepLine) {
|
|
150
|
+
const actionName = String(message.actionName || stepLine).toLowerCase();
|
|
151
|
+
let activity = this.currentActivity || 'processing';
|
|
152
|
+
if (['read_file', 'fs_read', 'view_file', 'cat', 'grep', 'find', 'ls'].some(k => actionName.includes(k))) {
|
|
153
|
+
activity = 'analyzing';
|
|
154
|
+
}
|
|
155
|
+
else if (['run_command', 'sysrun', 'bash', 'terminal', 'sh', 'exec'].some(k => actionName.includes(k))) {
|
|
156
|
+
activity = 'executing';
|
|
157
|
+
}
|
|
158
|
+
else if (['write_file', 'edit_file', 'multiedit', 'replace_file_content', 'fs_write'].some(k => actionName.includes(k))) {
|
|
159
|
+
activity = 'editing';
|
|
160
|
+
}
|
|
161
|
+
else if (['web_search', 'web_fetch', 'browse'].some(k => actionName.includes(k))) {
|
|
162
|
+
activity = 'researching';
|
|
163
|
+
}
|
|
164
|
+
else if (['plan', 'todo'].some(k => actionName.includes(k))) {
|
|
165
|
+
activity = 'planning';
|
|
166
|
+
}
|
|
167
|
+
this.currentActivity = activity;
|
|
168
|
+
const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
|
|
169
|
+
this.lastReasoning = currentContent;
|
|
170
|
+
super.onAgentReasoning({
|
|
171
|
+
content: currentContent,
|
|
172
|
+
streaming: true,
|
|
173
|
+
activity,
|
|
174
|
+
title: `${activity}…`
|
|
175
|
+
});
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
118
178
|
}
|
|
119
179
|
if (message?.type === 'code_progress') {
|
|
120
180
|
this.onCodeProgress(message);
|
|
@@ -138,15 +198,23 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
138
198
|
}
|
|
139
199
|
return true;
|
|
140
200
|
}
|
|
141
|
-
const handled = super.handle(
|
|
201
|
+
const handled = super.handle({
|
|
202
|
+
...message,
|
|
203
|
+
activity: message.activity || this.currentActivity
|
|
204
|
+
});
|
|
142
205
|
if (message.streaming === false) {
|
|
143
206
|
this.lastReasoning = '';
|
|
144
207
|
}
|
|
145
208
|
return handled;
|
|
146
209
|
}
|
|
147
|
-
if (['agent_message', '
|
|
210
|
+
if (['agent_message', 'budget_warning', 'step_start', 'task_complete', 'error', 'agent_plan'].includes(message?.type || '')
|
|
211
|
+
|| (message?.type === 'notice' && !message.nativeStep)) {
|
|
148
212
|
if (this._activeReasoning && this.lastReasoning) {
|
|
149
|
-
super.onAgentReasoning({
|
|
213
|
+
super.onAgentReasoning({
|
|
214
|
+
content: this.lastReasoning,
|
|
215
|
+
streaming: false,
|
|
216
|
+
activity: this.currentActivity
|
|
217
|
+
});
|
|
150
218
|
}
|
|
151
219
|
this._activeReasoning = false;
|
|
152
220
|
this.lastReasoning = '';
|
|
@@ -2,9 +2,16 @@ 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
4
|
import { markerAt } from './messageInteraction.js';
|
|
5
|
+
import { AdaptiveWheelDampener } from './scrollInteraction.js';
|
|
5
6
|
|
|
6
7
|
type RendererEvent = { type: string; [key: string]: unknown };
|
|
7
|
-
type CodePanelState = {
|
|
8
|
+
type CodePanelState = {
|
|
9
|
+
event: CodeProgressEvent;
|
|
10
|
+
modelNote: string;
|
|
11
|
+
start: number;
|
|
12
|
+
followTail: boolean;
|
|
13
|
+
dampener?: AdaptiveWheelDampener;
|
|
14
|
+
};
|
|
8
15
|
type CodeFrame = { id: number; meta?: Record<string, unknown> | null; rows?: string[] | null; renderedWidth?: number; produce?: (width: number) => string[] };
|
|
9
16
|
type CodeTranscript = {
|
|
10
17
|
frames: CodeFrame[];
|
|
@@ -29,6 +36,7 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
29
36
|
private activeCode: CodeProgressEvent | null = null;
|
|
30
37
|
private modelNote = '';
|
|
31
38
|
private lastReasoning = '';
|
|
39
|
+
private currentActivity = 'thinking';
|
|
32
40
|
private readonly codePanels = new WeakMap<CodeFrame, CodePanelState>();
|
|
33
41
|
|
|
34
42
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
@@ -49,7 +57,13 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
49
57
|
const limit = lastStart(state.event);
|
|
50
58
|
if (limit === 0) return false;
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
if (!state.dampener) {
|
|
61
|
+
state.dampener = new AdaptiveWheelDampener();
|
|
62
|
+
}
|
|
63
|
+
const delta = state.dampener.stepRows(wheel.direction as 'up' | 'down', 3);
|
|
64
|
+
if (delta === 0) return true;
|
|
65
|
+
|
|
66
|
+
const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -delta : delta)));
|
|
53
67
|
if (next === state.start) return true;
|
|
54
68
|
|
|
55
69
|
state.start = next;
|
|
@@ -81,8 +95,15 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
81
95
|
const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
|
|
82
96
|
if (limit === 0) return false;
|
|
83
97
|
|
|
98
|
+
if (!frame.meta._dampener) {
|
|
99
|
+
frame.meta._dampener = new AdaptiveWheelDampener();
|
|
100
|
+
}
|
|
101
|
+
const dampener = frame.meta._dampener as AdaptiveWheelDampener;
|
|
102
|
+
const delta = dampener.stepRows(wheel.direction as 'up' | 'down', 3);
|
|
103
|
+
if (delta === 0) return true;
|
|
104
|
+
|
|
84
105
|
const currentStart = Number(frame.meta.scrollStart) || 0;
|
|
85
|
-
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -
|
|
106
|
+
const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -delta : delta)));
|
|
86
107
|
if (next === currentStart) return true;
|
|
87
108
|
|
|
88
109
|
frame.meta.scrollStart = next;
|
|
@@ -133,9 +154,54 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
133
154
|
}
|
|
134
155
|
|
|
135
156
|
override handle(message: RendererEvent): boolean {
|
|
157
|
+
if (message?.type === 'agent_activity') {
|
|
158
|
+
const rawActivity = String((message as any).activity || (message as any).message || '').trim();
|
|
159
|
+
if (rawActivity) {
|
|
160
|
+
this.currentActivity = rawActivity.replace(/…|\.\.\.$/, '').trim();
|
|
161
|
+
if (this._activeReasoning && this.lastReasoning) {
|
|
162
|
+
super.onAgentReasoning({
|
|
163
|
+
content: this.lastReasoning,
|
|
164
|
+
streaming: true,
|
|
165
|
+
activity: this.currentActivity,
|
|
166
|
+
title: rawActivity
|
|
167
|
+
});
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
136
173
|
if (message?.type === 'notice' && message.nativeStep === true) {
|
|
137
174
|
this.stepCount = (this.stepCount || 0) + 1;
|
|
175
|
+
const stepLine = String(message.message || '').trim();
|
|
176
|
+
if (stepLine) {
|
|
177
|
+
const actionName = String((message as any).actionName || stepLine).toLowerCase();
|
|
178
|
+
let activity = this.currentActivity || 'processing';
|
|
179
|
+
if (['read_file', 'fs_read', 'view_file', 'cat', 'grep', 'find', 'ls'].some(k => actionName.includes(k))) {
|
|
180
|
+
activity = 'analyzing';
|
|
181
|
+
} else if (['run_command', 'sysrun', 'bash', 'terminal', 'sh', 'exec'].some(k => actionName.includes(k))) {
|
|
182
|
+
activity = 'executing';
|
|
183
|
+
} else if (['write_file', 'edit_file', 'multiedit', 'replace_file_content', 'fs_write'].some(k => actionName.includes(k))) {
|
|
184
|
+
activity = 'editing';
|
|
185
|
+
} else if (['web_search', 'web_fetch', 'browse'].some(k => actionName.includes(k))) {
|
|
186
|
+
activity = 'researching';
|
|
187
|
+
} else if (['plan', 'todo'].some(k => actionName.includes(k))) {
|
|
188
|
+
activity = 'planning';
|
|
189
|
+
}
|
|
190
|
+
this.currentActivity = activity;
|
|
191
|
+
|
|
192
|
+
const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
|
|
193
|
+
this.lastReasoning = currentContent;
|
|
194
|
+
|
|
195
|
+
super.onAgentReasoning({
|
|
196
|
+
content: currentContent,
|
|
197
|
+
streaming: true,
|
|
198
|
+
activity,
|
|
199
|
+
title: `${activity}…`
|
|
200
|
+
});
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
138
203
|
}
|
|
204
|
+
|
|
139
205
|
if (message?.type === 'code_progress') {
|
|
140
206
|
this.onCodeProgress(message as unknown as CodeProgressEvent);
|
|
141
207
|
return true;
|
|
@@ -157,15 +223,23 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
157
223
|
}
|
|
158
224
|
return true;
|
|
159
225
|
}
|
|
160
|
-
const handled = super.handle(
|
|
226
|
+
const handled = super.handle({
|
|
227
|
+
...message,
|
|
228
|
+
activity: (message as any).activity || this.currentActivity
|
|
229
|
+
});
|
|
161
230
|
if (message.streaming === false) {
|
|
162
231
|
this.lastReasoning = '';
|
|
163
232
|
}
|
|
164
233
|
return handled;
|
|
165
234
|
}
|
|
166
|
-
if (['agent_message', '
|
|
235
|
+
if (['agent_message', 'budget_warning', 'step_start', 'task_complete', 'error', 'agent_plan'].includes(message?.type || '')
|
|
236
|
+
|| (message?.type === 'notice' && !message.nativeStep)) {
|
|
167
237
|
if (this._activeReasoning && this.lastReasoning) {
|
|
168
|
-
super.onAgentReasoning({
|
|
238
|
+
super.onAgentReasoning({
|
|
239
|
+
content: this.lastReasoning,
|
|
240
|
+
streaming: false,
|
|
241
|
+
activity: this.currentActivity
|
|
242
|
+
});
|
|
169
243
|
}
|
|
170
244
|
this._activeReasoning = false;
|
|
171
245
|
this.lastReasoning = '';
|
package/src/tui/prompt.js
CHANGED
|
@@ -667,9 +667,9 @@ export class ChatPrompt {
|
|
|
667
667
|
if (this.surface?.homeInfo) this.surface.leaveHome();
|
|
668
668
|
if (this.renderer?.renderUserMessage) this.renderer.renderUserMessage(text);
|
|
669
669
|
else this.commit('user', (width) => {
|
|
670
|
-
const blockWidth = Math.max(8, width
|
|
670
|
+
const blockWidth = Math.max(8, width);
|
|
671
671
|
return barBlock(
|
|
672
|
-
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.bar) - GUTTER)),
|
|
672
|
+
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - GUTTER)),
|
|
673
673
|
{ width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
|
|
674
674
|
);
|
|
675
675
|
});
|
|
@@ -920,11 +920,11 @@ 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)) {
|
|
923
|
-
this.draw();
|
|
923
|
+
if (typeof this.scheduleDraw === 'function') this.scheduleDraw(); else this.draw();
|
|
924
924
|
return true;
|
|
925
925
|
}
|
|
926
926
|
if (this.renderer?.scrollThinkingPanel?.(key, this.surface)) {
|
|
927
|
-
this.draw();
|
|
927
|
+
if (typeof this.scheduleDraw === 'function') this.scheduleDraw(); else this.draw();
|
|
928
928
|
return true;
|
|
929
929
|
}
|
|
930
930
|
|
|
@@ -1389,7 +1389,7 @@ export class ChatPrompt {
|
|
|
1389
1389
|
role: this.busy ? 'accent' : 'user',
|
|
1390
1390
|
filled: true,
|
|
1391
1391
|
surface: 'surface',
|
|
1392
|
-
punctuate:
|
|
1392
|
+
punctuate: false
|
|
1393
1393
|
});
|
|
1394
1394
|
|
|
1395
1395
|
const planRows = this.planRows(width);
|
|
@@ -1414,8 +1414,11 @@ export class ChatPrompt {
|
|
|
1414
1414
|
if (this.pickerLayout) this.pickerLayout.totalPromptRows = all.length;
|
|
1415
1415
|
|
|
1416
1416
|
// Park the cursor where the user is typing, not at the end of the picker.
|
|
1417
|
+
const availableWidth = this.surface?.composeAvailableWidth
|
|
1418
|
+
? this.surface.composeAvailableWidth()
|
|
1419
|
+
: sessionMainWidth(this.surface?.width || terminalWidth());
|
|
1417
1420
|
const positioned = this.surface
|
|
1418
|
-
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all,
|
|
1421
|
+
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all, availableWidth))
|
|
1419
1422
|
: { rows: all, inset: 0 };
|
|
1420
1423
|
this.present(positioned.rows, planRows.length + caretRow + padTop, layout.cursorCol + inset + positioned.inset);
|
|
1421
1424
|
}
|
|
@@ -7,13 +7,95 @@
|
|
|
7
7
|
// preventing terminal scrollback desync and UI freezes.
|
|
8
8
|
// 4. Scrollbar (rail) mouse interactions clamp cleanly even if clicked above or
|
|
9
9
|
// below the chat box bounds.
|
|
10
|
+
/**
|
|
11
|
+
* Adaptive Wheel Dampener & Momentum Controller.
|
|
12
|
+
*
|
|
13
|
+
* Distinguishes single mechanical mouse wheel notches (e.g. 1 notch every 100ms+)
|
|
14
|
+
* from high-frequency macOS trackpad / Magic Mouse continuous event streams (10-100Hz).
|
|
15
|
+
*
|
|
16
|
+
* For single notches, full discrete step is preserved.
|
|
17
|
+
* For continuous trackpad streams, velocity is smoothly damped via sub-line accumulation
|
|
18
|
+
* so a natural finger swipe advances smoothly without exploding into runaway flight.
|
|
19
|
+
* Direction reversals provide instant braking to prevent momentum drift.
|
|
20
|
+
*/
|
|
21
|
+
export class AdaptiveWheelDampener {
|
|
22
|
+
minDamping;
|
|
23
|
+
thresholdMs;
|
|
24
|
+
minTickInterval;
|
|
25
|
+
burstWindowMs;
|
|
26
|
+
maxBurstNotches;
|
|
27
|
+
lastTick = 0;
|
|
28
|
+
lastDirection = null;
|
|
29
|
+
rowAccumulator = 0;
|
|
30
|
+
recentBursts = [];
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.minDamping = options.minDamping ?? 0.28;
|
|
33
|
+
this.thresholdMs = options.thresholdMs ?? 85;
|
|
34
|
+
this.minTickInterval = options.minTickInterval ?? 6;
|
|
35
|
+
this.burstWindowMs = options.burstWindowMs ?? 120;
|
|
36
|
+
this.maxBurstNotches = options.maxBurstNotches ?? 5.0;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Compute adaptive fractional notch multiplier for viewports that possess
|
|
40
|
+
* their own sub-row accumulator (e.g. Viewport).
|
|
41
|
+
*/
|
|
42
|
+
computeNotches(direction, now = Date.now()) {
|
|
43
|
+
if (this.lastDirection && this.lastDirection !== direction) {
|
|
44
|
+
this.recentBursts = [];
|
|
45
|
+
this.lastTick = 0;
|
|
46
|
+
this.rowAccumulator = 0;
|
|
47
|
+
}
|
|
48
|
+
this.lastDirection = direction;
|
|
49
|
+
const gap = this.lastTick ? Math.max(0, now - this.lastTick) : Infinity;
|
|
50
|
+
this.lastTick = now;
|
|
51
|
+
if (gap === Infinity || gap > 150) {
|
|
52
|
+
this.recentBursts = [];
|
|
53
|
+
return 1.0;
|
|
54
|
+
}
|
|
55
|
+
if (gap < this.minTickInterval) {
|
|
56
|
+
return 1.0;
|
|
57
|
+
}
|
|
58
|
+
let damping = Math.max(this.minDamping, Math.min(1.0, gap / this.thresholdMs));
|
|
59
|
+
const windowStart = now - this.burstWindowMs;
|
|
60
|
+
this.recentBursts = this.recentBursts.filter(b => b.time >= windowStart);
|
|
61
|
+
const windowNotches = this.recentBursts.reduce((sum, b) => sum + b.notches, 0);
|
|
62
|
+
if (windowNotches >= this.maxBurstNotches) {
|
|
63
|
+
damping = Math.min(damping, 0.15);
|
|
64
|
+
}
|
|
65
|
+
this.recentBursts.push({ time: now, notches: damping });
|
|
66
|
+
return damping;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Compute whole integer row steps for widgets without internal sub-row accumulators
|
|
70
|
+
* (e.g. Code panel and Thinking box previews).
|
|
71
|
+
*/
|
|
72
|
+
stepRows(direction, baseSpeed = 3, now = Date.now()) {
|
|
73
|
+
const notch = this.computeNotches(direction, now);
|
|
74
|
+
this.rowAccumulator += baseSpeed * notch;
|
|
75
|
+
const whole = Math.trunc(this.rowAccumulator);
|
|
76
|
+
if (whole !== 0) {
|
|
77
|
+
this.rowAccumulator -= whole;
|
|
78
|
+
return whole;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
reset() {
|
|
83
|
+
this.lastTick = 0;
|
|
84
|
+
this.lastDirection = null;
|
|
85
|
+
this.rowAccumulator = 0;
|
|
86
|
+
this.recentBursts = [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export const defaultViewportDampener = new AdaptiveWheelDampener();
|
|
10
90
|
/**
|
|
11
91
|
* Handle mouse wheel scrolling with full viewport containment.
|
|
12
92
|
* Replaces the buggy overscroll release with clean boundary saturation.
|
|
13
93
|
*/
|
|
14
|
-
export function handleViewportWheel(key, viewport, surface, host) {
|
|
94
|
+
export function handleViewportWheel(key, viewport, surface, host, now = Date.now()) {
|
|
15
95
|
if (!viewport || !key.wheel)
|
|
16
96
|
return true;
|
|
97
|
+
if (key.wheel.direction !== 'up' && key.wheel.direction !== 'down')
|
|
98
|
+
return true;
|
|
17
99
|
// Auto-heal: If the surface was ever detached, immediately re-capture mouse
|
|
18
100
|
// so the session stays responsive and never freezes.
|
|
19
101
|
if (surface && typeof surface.captureMouse === 'function' && surface.detached) {
|
|
@@ -26,10 +108,16 @@ export function handleViewportWheel(key, viewport, surface, host) {
|
|
|
26
108
|
if (surface) {
|
|
27
109
|
surface.activeTurnIndex = null;
|
|
28
110
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
111
|
+
const dir = key.wheel.direction === 'down' ? 'down' : 'up';
|
|
112
|
+
const notches = defaultViewportDampener.computeNotches(dir, now);
|
|
113
|
+
viewport.wheel(dir, notches, now);
|
|
114
|
+
// Coalesce redraws to prevent terminal buffer flooding and latency pileup
|
|
115
|
+
if (typeof host.scheduleDraw === 'function') {
|
|
116
|
+
host.scheduleDraw();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
host.draw();
|
|
120
|
+
}
|
|
33
121
|
return true;
|
|
34
122
|
}
|
|
35
123
|
/**
|
|
@@ -79,6 +79,107 @@ export interface PromptScrollHost {
|
|
|
79
79
|
} | null;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
export interface WheelDampenerOptions {
|
|
83
|
+
minDamping?: number;
|
|
84
|
+
thresholdMs?: number;
|
|
85
|
+
minTickInterval?: number;
|
|
86
|
+
burstWindowMs?: number;
|
|
87
|
+
maxBurstNotches?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Adaptive Wheel Dampener & Momentum Controller.
|
|
92
|
+
*
|
|
93
|
+
* Distinguishes single mechanical mouse wheel notches (e.g. 1 notch every 100ms+)
|
|
94
|
+
* from high-frequency macOS trackpad / Magic Mouse continuous event streams (10-100Hz).
|
|
95
|
+
*
|
|
96
|
+
* For single notches, full discrete step is preserved.
|
|
97
|
+
* For continuous trackpad streams, velocity is smoothly damped via sub-line accumulation
|
|
98
|
+
* so a natural finger swipe advances smoothly without exploding into runaway flight.
|
|
99
|
+
* Direction reversals provide instant braking to prevent momentum drift.
|
|
100
|
+
*/
|
|
101
|
+
export class AdaptiveWheelDampener {
|
|
102
|
+
readonly minDamping: number;
|
|
103
|
+
readonly thresholdMs: number;
|
|
104
|
+
readonly minTickInterval: number;
|
|
105
|
+
readonly burstWindowMs: number;
|
|
106
|
+
readonly maxBurstNotches: number;
|
|
107
|
+
private lastTick = 0;
|
|
108
|
+
private lastDirection: 'up' | 'down' | null = null;
|
|
109
|
+
private rowAccumulator = 0;
|
|
110
|
+
private recentBursts: Array<{ time: number; notches: number }> = [];
|
|
111
|
+
|
|
112
|
+
constructor(options: WheelDampenerOptions = {}) {
|
|
113
|
+
this.minDamping = options.minDamping ?? 0.28;
|
|
114
|
+
this.thresholdMs = options.thresholdMs ?? 85;
|
|
115
|
+
this.minTickInterval = options.minTickInterval ?? 6;
|
|
116
|
+
this.burstWindowMs = options.burstWindowMs ?? 120;
|
|
117
|
+
this.maxBurstNotches = options.maxBurstNotches ?? 5.0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Compute adaptive fractional notch multiplier for viewports that possess
|
|
122
|
+
* their own sub-row accumulator (e.g. Viewport).
|
|
123
|
+
*/
|
|
124
|
+
computeNotches(direction: 'up' | 'down', now: number = Date.now()): number {
|
|
125
|
+
if (this.lastDirection && this.lastDirection !== direction) {
|
|
126
|
+
this.recentBursts = [];
|
|
127
|
+
this.lastTick = 0;
|
|
128
|
+
this.rowAccumulator = 0;
|
|
129
|
+
}
|
|
130
|
+
this.lastDirection = direction;
|
|
131
|
+
|
|
132
|
+
const gap = this.lastTick ? Math.max(0, now - this.lastTick) : Infinity;
|
|
133
|
+
this.lastTick = now;
|
|
134
|
+
|
|
135
|
+
if (gap === Infinity || gap > 150) {
|
|
136
|
+
this.recentBursts = [];
|
|
137
|
+
return 1.0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (gap < this.minTickInterval) {
|
|
141
|
+
return 1.0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let damping = Math.max(this.minDamping, Math.min(1.0, gap / this.thresholdMs));
|
|
145
|
+
|
|
146
|
+
const windowStart = now - this.burstWindowMs;
|
|
147
|
+
this.recentBursts = this.recentBursts.filter(b => b.time >= windowStart);
|
|
148
|
+
const windowNotches = this.recentBursts.reduce((sum, b) => sum + b.notches, 0);
|
|
149
|
+
|
|
150
|
+
if (windowNotches >= this.maxBurstNotches) {
|
|
151
|
+
damping = Math.min(damping, 0.15);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.recentBursts.push({ time: now, notches: damping });
|
|
155
|
+
return damping;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Compute whole integer row steps for widgets without internal sub-row accumulators
|
|
160
|
+
* (e.g. Code panel and Thinking box previews).
|
|
161
|
+
*/
|
|
162
|
+
stepRows(direction: 'up' | 'down', baseSpeed: number = 3, now: number = Date.now()): number {
|
|
163
|
+
const notch = this.computeNotches(direction, now);
|
|
164
|
+
this.rowAccumulator += baseSpeed * notch;
|
|
165
|
+
const whole = Math.trunc(this.rowAccumulator);
|
|
166
|
+
if (whole !== 0) {
|
|
167
|
+
this.rowAccumulator -= whole;
|
|
168
|
+
return whole;
|
|
169
|
+
}
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
reset(): void {
|
|
174
|
+
this.lastTick = 0;
|
|
175
|
+
this.lastDirection = null;
|
|
176
|
+
this.rowAccumulator = 0;
|
|
177
|
+
this.recentBursts = [];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const defaultViewportDampener = new AdaptiveWheelDampener();
|
|
182
|
+
|
|
82
183
|
/**
|
|
83
184
|
* Handle mouse wheel scrolling with full viewport containment.
|
|
84
185
|
* Replaces the buggy overscroll release with clean boundary saturation.
|
|
@@ -87,9 +188,11 @@ export function handleViewportWheel(
|
|
|
87
188
|
key: KeyEvent,
|
|
88
189
|
viewport: ViewportContract | null | undefined,
|
|
89
190
|
surface: SurfaceContract | null | undefined,
|
|
90
|
-
host: PromptScrollHost
|
|
191
|
+
host: PromptScrollHost,
|
|
192
|
+
now: number = Date.now()
|
|
91
193
|
): boolean {
|
|
92
194
|
if (!viewport || !key.wheel) return true;
|
|
195
|
+
if (key.wheel.direction !== 'up' && key.wheel.direction !== 'down') return true;
|
|
93
196
|
|
|
94
197
|
// Auto-heal: If the surface was ever detached, immediately re-capture mouse
|
|
95
198
|
// so the session stays responsive and never freezes.
|
|
@@ -105,11 +208,16 @@ export function handleViewportWheel(
|
|
|
105
208
|
(surface as any).activeTurnIndex = null;
|
|
106
209
|
}
|
|
107
210
|
|
|
108
|
-
|
|
109
|
-
|
|
211
|
+
const dir: 'up' | 'down' = key.wheel.direction === 'down' ? 'down' : 'up';
|
|
212
|
+
const notches = defaultViewportDampener.computeNotches(dir, now);
|
|
213
|
+
viewport.wheel(dir, notches, now);
|
|
110
214
|
|
|
111
|
-
//
|
|
112
|
-
host.
|
|
215
|
+
// Coalesce redraws to prevent terminal buffer flooding and latency pileup
|
|
216
|
+
if (typeof host.scheduleDraw === 'function') {
|
|
217
|
+
host.scheduleDraw();
|
|
218
|
+
} else {
|
|
219
|
+
host.draw();
|
|
220
|
+
}
|
|
113
221
|
return true;
|
|
114
222
|
}
|
|
115
223
|
|
package/src/tui/stageSurface.js
CHANGED
|
@@ -34,7 +34,7 @@ import { composerWidth } from './layout.js';
|
|
|
34
34
|
import { placeHome, placeDialog } from './homeView.js';
|
|
35
35
|
import { sidebarVisible, sessionMainWidth, sessionComposerWidth, sessionSidebarRows, joinSessionSidebar } from './sessionSidebar.js';
|
|
36
36
|
import { sessionStageHeight, alignTranscriptRows } from './sessionLayout.js';
|
|
37
|
-
import { collectSessionTurns, buildTurnRailCells, renderTurnPreviewCard, overlayTurnPreviewCard, resolveActiveTurnIndex } from './turnRail.js';
|
|
37
|
+
import { hasSessionTurns, collectSessionTurns, buildTurnRailCells, renderTurnPreviewCard, overlayTurnPreviewCard, resolveActiveTurnIndex } from './turnRail.js';
|
|
38
38
|
|
|
39
39
|
// Rows of evicted transcript held for the exit log. Eviction only happens after
|
|
40
40
|
// MAX_FRAMES, so this is a bound on a pathological session, not a working limit.
|
|
@@ -199,11 +199,25 @@ export class StageSurface {
|
|
|
199
199
|
return this.stage.width();
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
composeAvailableWidth() {
|
|
203
|
+
if (this.homeInfo) return this.width;
|
|
204
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
205
|
+
const rail = this.railEnabled(mainWidth);
|
|
206
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
207
|
+
const turnRailBudget = (rail && hasTurns) ? 3 : 0;
|
|
208
|
+
return rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
209
|
+
}
|
|
210
|
+
|
|
202
211
|
/** Home is compact; a session uses its full conversation column. */
|
|
203
212
|
composeWidth() {
|
|
204
|
-
return this.
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
if (this.homeInfo) return composerWidth(this.width);
|
|
214
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
215
|
+
const rail = this.railEnabled(mainWidth);
|
|
216
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
217
|
+
if (!hasTurns) return sessionComposerWidth(mainWidth);
|
|
218
|
+
const turnRailBudget = rail ? 3 : 0;
|
|
219
|
+
const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
220
|
+
return sessionComposerWidth(contentWidth);
|
|
207
221
|
}
|
|
208
222
|
|
|
209
223
|
/** Keep Home distinct from a selected or newly started conversation. */
|
|
@@ -395,12 +409,19 @@ export class StageSurface {
|
|
|
395
409
|
const sidebar = sidebarVisible(width);
|
|
396
410
|
const mainWidth = sessionMainWidth(width);
|
|
397
411
|
const rail = this.railEnabled(mainWidth);
|
|
398
|
-
const hasTurns =
|
|
412
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
399
413
|
const turnRailBudget = (rail && hasTurns) ? 3 : 0;
|
|
400
414
|
const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
401
415
|
|
|
402
416
|
let block = promptRows;
|
|
403
417
|
let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
|
|
418
|
+
let caretCol = caret ? caret.col : 0;
|
|
419
|
+
|
|
420
|
+
if (turnRailBudget > 0) {
|
|
421
|
+
const railGutter = ' '.repeat(turnRailBudget);
|
|
422
|
+
block = block.map(row => (row ? railGutter + row : row));
|
|
423
|
+
caretCol += turnRailBudget;
|
|
424
|
+
}
|
|
404
425
|
|
|
405
426
|
// Grow the band to what there is to show, before deciding anything else.
|
|
406
427
|
//
|
|
@@ -485,7 +506,7 @@ export class StageSurface {
|
|
|
485
506
|
const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
|
|
486
507
|
return this.stage.paint(painted, {
|
|
487
508
|
row: rows.length + caretRow,
|
|
488
|
-
col:
|
|
509
|
+
col: caretCol
|
|
489
510
|
});
|
|
490
511
|
}
|
|
491
512
|
|
package/src/tui/theme.js
CHANGED
|
@@ -250,10 +250,9 @@ export const GLYPHS = HAS_UNICODE
|
|
|
250
250
|
arrow: '▸', check: '✓', cross: '✕', dot: '·', bullet: '•',
|
|
251
251
|
spinner: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
252
252
|
hLine: '─', vLine: '│', corner: '└', tee: '├', ellipsis: '…',
|
|
253
|
-
// The left accent bar of a block.
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
bar: '▌', step: '▪',
|
|
253
|
+
// The left accent bar of a block. Uses box-drawing heavy vertical ('┃')
|
|
254
|
+
// so it joins seamlessly from row to row without font line-height leading gaps.
|
|
255
|
+
bar: '┃', step: '▪',
|
|
257
256
|
// The permission marker. opencode shows a warning triangle and NO risk
|
|
258
257
|
// word — the level is internal plumbing, and printing 'DANGEROUS' at
|
|
259
258
|
// someone just makes them numb to it. Colour still carries the tier.
|