@causyne/agent 1.20.62 → 1.20.63

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 (59) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/acp/client.js +48 -0
  4. package/src/acp/client.ts +44 -0
  5. package/src/agentLoop.js +181 -11
  6. package/src/agentLoop.ts +184 -11
  7. package/src/cliMode.js +9 -0
  8. package/src/commands.js +31 -0
  9. package/src/decisionPolicy.js +18 -1
  10. package/src/decisionPolicy.ts +18 -1
  11. package/src/implementationPlan.js +26 -0
  12. package/src/implementationPlan.ts +25 -0
  13. package/src/observer/coldObserver.js +6 -1
  14. package/src/observer/coldObserver.ts +6 -1
  15. package/src/observer.js +24 -2
  16. package/src/observer.ts +24 -2
  17. package/src/providers/acp.js +2 -8
  18. package/src/providers/acp.ts +2 -8
  19. package/src/providers/antigravity.js +7 -10
  20. package/src/providers/antigravity.ts +7 -10
  21. package/src/smartToolsUse.js +1 -1
  22. package/src/smartToolsUse.ts +1 -1
  23. package/src/toolPacks.js +1 -1
  24. package/src/toolPacks.ts +1 -1
  25. package/src/tools/toolSelfRepair.js +51 -8
  26. package/src/tools/toolSelfRepair.ts +42 -9
  27. package/src/tui/CausyneRotor.js +234 -0
  28. package/src/tui/CausyneRotor.ts +280 -0
  29. package/src/tui/activityLayout.js +1 -1
  30. package/src/tui/activityLayout.ts +1 -1
  31. package/src/tui/chatRenderer.js +56 -7
  32. package/src/tui/chatboxClipboard.js +96 -10
  33. package/src/tui/chatboxClipboard.ts +121 -11
  34. package/src/tui/clipboardImage.js +308 -0
  35. package/src/tui/clipboardImage.ts +320 -0
  36. package/src/tui/codeStreamRenderer.js +89 -1
  37. package/src/tui/codeStreamRenderer.ts +109 -1
  38. package/src/tui/dialogs.js +5 -2
  39. package/src/tui/engineSpinner.js +20 -0
  40. package/src/tui/engineSpinner.ts +46 -0
  41. package/src/tui/lineEditor.js +44 -12
  42. package/src/tui/messageInteraction.js +16 -5
  43. package/src/tui/messageInteraction.ts +14 -5
  44. package/src/tui/observerPicker.js +4 -8
  45. package/src/tui/observerPicker.ts +4 -8
  46. package/src/tui/prompt.js +70 -40
  47. package/src/tui/runningLight.js +213 -0
  48. package/src/tui/runningLight.ts +271 -0
  49. package/src/tui/sessionSidebar.js +7 -1
  50. package/src/tui/sessionSidebar.ts +7 -1
  51. package/src/tui/stage.js +4 -4
  52. package/src/tui/stageSurface.js +21 -14
  53. package/src/tui/statusLine.js +27 -4
  54. package/src/tui/statusLine.ts +27 -4
  55. package/src/tui/theme.js +5 -2
  56. package/src/tui/thinkingBox.js +41 -10
  57. package/src/tui/thinkingBox.ts +43 -10
  58. package/src/tui/turnRail.js +155 -24
  59. package/src/tui/turnRail.ts +170 -22
@@ -0,0 +1,213 @@
1
+ // Travelling running-light shimmer animation for Causyne Agent TUI.
2
+ //
3
+ // Implements a width-stable, multi-stop chromatic highlight wave that sweeps
4
+ // across active status labels ("working...", "Analyzing & planning…") and
5
+ // live streaming reasoning lines ("thinking…", "analyzing…", and active tail
6
+ // thoughts).
7
+ //
8
+ // Mathematical model:
9
+ // - Window width W = min(L, 5), where L is the code-point length.
10
+ // - Short strings (L < 25): unidirectional left-to-right sweep at 80ms/step
11
+ // with a 3-step lead-in and 3-step lead-out dead-zone.
12
+ // - Long strings (L >= 25): bidirectional ping-pong sweep at 40ms/step
13
+ // with smooth lead-in/lead-out turnarounds.
14
+ //
15
+ // Invariant:
16
+ // - Strictly preserves character sequence and terminal column width:
17
+ // stripAnsi(renderRunningLight(s)) === stripAnsi(s)
18
+ // visibleWidth(renderRunningLight(s)) === visibleWidth(s)
19
+ //
20
+ // Pure TypeScript under strict mode.
21
+ // @ts-expect-error theme.js has no TypeScript declaration yet.
22
+ import { paint, bold, dim, HAS_COLOR, COLOR_DEPTH, IS_LIGHT } from './theme.js';
23
+ import { stripAnsi } from './text.js';
24
+ const DARK_TRUECOLOR_STOPS = [
25
+ '\x1b[38;2;154;186;104m', // 0: outer shoulder (#9aba68)
26
+ '\x1b[38;2;182;224;111m', // 1: Signal Lime (#b6e06f)
27
+ '\x1b[1m\x1b[38;2;232;248;204m', // 2: luminous specular crest (#e8f8cc)
28
+ '\x1b[38;2;182;224;111m', // 3: Signal Lime (#b6e06f)
29
+ '\x1b[38;2;154;186;104m', // 4: outer shoulder (#9aba68)
30
+ ];
31
+ const LIGHT_TRUECOLOR_STOPS = [
32
+ '\x1b[38;2;92;124;42m', // 0: outer shoulder (#5c7c2a)
33
+ '\x1b[38;2;78;112;24m', // 1: deep Signal Lime (#4e7018)
34
+ '\x1b[1m\x1b[38;2;38;64;4m', // 2: high-contrast crest (#264004)
35
+ '\x1b[38;2;78;112;24m', // 3: deep Signal Lime (#4e7018)
36
+ '\x1b[38;2;92;124;42m', // 4: outer shoulder (#5c7c2a)
37
+ ];
38
+ const DARK_256_STOPS = [
39
+ '\x1b[38;5;107m',
40
+ '\x1b[38;5;149m',
41
+ '\x1b[1m\x1b[38;5;193m',
42
+ '\x1b[38;5;149m',
43
+ '\x1b[38;5;107m',
44
+ ];
45
+ const LIGHT_256_STOPS = [
46
+ '\x1b[38;5;64m',
47
+ '\x1b[38;5;28m',
48
+ '\x1b[1m\x1b[38;5;22m',
49
+ '\x1b[38;5;28m',
50
+ '\x1b[38;5;64m',
51
+ ];
52
+ const RESET = '\x1b[0m';
53
+ /**
54
+ * Resolves the step duration in milliseconds for short (< 25 chars) and
55
+ * long (>= 25 chars) strings.
56
+ */
57
+ export function resolveRunningLightSpeed(speed = 'medium') {
58
+ switch (speed) {
59
+ case 'off':
60
+ return { shortStepMs: 0, longStepMs: 0 };
61
+ case 'slow':
62
+ return { shortStepMs: 200, longStepMs: 100 };
63
+ case 'fast':
64
+ return { shortStepMs: 20, longStepMs: 10 };
65
+ case 'medium':
66
+ default:
67
+ return { shortStepMs: 80, longStepMs: 40 };
68
+ }
69
+ }
70
+ /**
71
+ * Computes the active highlight window [start, start + width) at timestamp `nowMs`.
72
+ *
73
+ * - For `runesLen < 25`: unidirectional left-to-right sweep at `shortStepMs`.
74
+ * - For `runesLen >= 25`: bidirectional ping-pong sweep at `longStepMs`.
75
+ */
76
+ export function runningLightWindow(runesLen, nowMs, speed = 'medium') {
77
+ const len = Math.max(0, Math.floor(runesLen));
78
+ const { shortStepMs, longStepMs } = resolveRunningLightSpeed(speed);
79
+ if (len <= 0 || shortStepMs <= 0 || longStepMs <= 0) {
80
+ return { start: 0, width: 0, active: false };
81
+ }
82
+ const t = Math.max(0, Math.floor(Number.isFinite(nowMs) ? nowMs : 0));
83
+ const windowWidth = Math.min(len, 5);
84
+ const span = len + windowWidth;
85
+ const limit = span + 6;
86
+ if (len < 25) {
87
+ const step = Math.floor(t / shortStepMs);
88
+ const phase = ((step % limit) + limit) % limit;
89
+ const pos = phase - windowWidth;
90
+ const start = pos - 3;
91
+ return { start, width: windowWidth, active: true };
92
+ }
93
+ const halfPeriod = span + 5;
94
+ const fullPeriod = halfPeriod * 2;
95
+ const step = Math.floor(t / longStepMs);
96
+ const phase = ((step % fullPeriod) + fullPeriod) % fullPeriod;
97
+ const folded = phase < limit ? phase : fullPeriod - phase;
98
+ const pos = folded - windowWidth;
99
+ const start = pos - 3;
100
+ return { start, width: windowWidth, active: true };
101
+ }
102
+ /**
103
+ * Maps a character offset [0 .. windowWidth - 1] inside the highlight window
104
+ * to one of the 5 chromatic gradient stops [0 .. 4].
105
+ */
106
+ function mapWindowOffsetToStop(offset, windowWidth) {
107
+ if (windowWidth <= 1)
108
+ return 2;
109
+ if (windowWidth >= 5) {
110
+ const clamped = Math.max(0, Math.min(4, offset));
111
+ return clamped;
112
+ }
113
+ const scaled = Math.floor((offset * 5) / windowWidth);
114
+ const clamped = Math.max(0, Math.min(4, scaled));
115
+ return clamped;
116
+ }
117
+ function paintBaseSegment(segment, baseRole, boldActive) {
118
+ if (!segment)
119
+ return '';
120
+ if (baseRole === 'dim')
121
+ return dim(segment);
122
+ const painted = paint(baseRole, segment);
123
+ return boldActive && baseRole === 'warn' ? bold(painted) : painted;
124
+ }
125
+ function paintStopSegment(segment, stop, boldActive) {
126
+ if (!segment)
127
+ return '';
128
+ if (!HAS_COLOR || COLOR_DEPTH <= 1)
129
+ return segment;
130
+ if (COLOR_DEPTH >= 16777216) {
131
+ const palette = IS_LIGHT ? LIGHT_TRUECOLOR_STOPS : DARK_TRUECOLOR_STOPS;
132
+ const prefix = palette[stop];
133
+ const boldPrefix = boldActive && stop !== 2 ? '\x1b[1m' : '';
134
+ return `${boldPrefix}${prefix}${segment}${RESET}`;
135
+ }
136
+ if (COLOR_DEPTH >= 256) {
137
+ const palette = IS_LIGHT ? LIGHT_256_STOPS : DARK_256_STOPS;
138
+ const prefix = palette[stop];
139
+ const boldPrefix = boldActive && stop !== 2 ? '\x1b[1m' : '';
140
+ return `${boldPrefix}${prefix}${segment}${RESET}`;
141
+ }
142
+ // 16-color fallback
143
+ if (stop === 2) {
144
+ return bold(paint('ink', segment));
145
+ }
146
+ return boldActive || stop === 1 || stop === 3
147
+ ? bold(paint('accent', segment))
148
+ : paint('accent', segment);
149
+ }
150
+ /**
151
+ * Renders `text` with a travelling running-light shimmer highlight at the
152
+ * current timestamp or tick.
153
+ *
154
+ * Strictly width-stable: never adds or removes characters.
155
+ */
156
+ export function renderRunningLight(text, options = {}) {
157
+ const plain = stripAnsi(String(text ?? ''));
158
+ if (!plain)
159
+ return '';
160
+ const baseRole = options.baseRole ?? 'muted';
161
+ const boldActive = Boolean(options.boldActive);
162
+ const speed = options.speed ?? 'medium';
163
+ if (!HAS_COLOR || COLOR_DEPTH <= 1 || speed === 'off') {
164
+ return HAS_COLOR ? paintBaseSegment(plain, baseRole, boldActive) : plain;
165
+ }
166
+ const chars = Array.from(plain);
167
+ const len = chars.length;
168
+ const nowMs = options.nowMs !== undefined
169
+ ? options.nowMs
170
+ : options.tick !== undefined
171
+ ? options.tick * 80
172
+ : 0;
173
+ const win = runningLightWindow(len, nowMs, speed);
174
+ if (!win.active || win.width <= 0) {
175
+ return paintBaseSegment(plain, baseRole, boldActive);
176
+ }
177
+ const windowEnd = win.start + win.width;
178
+ // Fast path: when the highlight window is completely in the lead-in or
179
+ // lead-out dead-zone outside [0, len), paint the entire string in one pass.
180
+ if (windowEnd <= 0 || win.start >= len) {
181
+ return paintBaseSegment(plain, baseRole, boldActive);
182
+ }
183
+ // Coalesce consecutive characters with the same style index (-1 = base, 0..4 = stop)
184
+ let out = '';
185
+ let currentStyle = -2;
186
+ let currentRun = '';
187
+ const flushRun = (style, run) => {
188
+ if (!run)
189
+ return;
190
+ if (style < 0) {
191
+ out += paintBaseSegment(run, baseRole, boldActive);
192
+ }
193
+ else {
194
+ out += paintStopSegment(run, style, boldActive);
195
+ }
196
+ };
197
+ for (let i = 0; i < len; i++) {
198
+ const ch = chars[i];
199
+ const style = (i >= win.start && i < windowEnd)
200
+ ? mapWindowOffsetToStop(i - win.start, win.width)
201
+ : -1;
202
+ if (style !== currentStyle) {
203
+ flushRun(currentStyle, currentRun);
204
+ currentStyle = style;
205
+ currentRun = ch;
206
+ }
207
+ else {
208
+ currentRun += ch;
209
+ }
210
+ }
211
+ flushRun(currentStyle, currentRun);
212
+ return out;
213
+ }
@@ -0,0 +1,271 @@
1
+ // Travelling running-light shimmer animation for Causyne Agent TUI.
2
+ //
3
+ // Implements a width-stable, multi-stop chromatic highlight wave that sweeps
4
+ // across active status labels ("working...", "Analyzing & planning…") and
5
+ // live streaming reasoning lines ("thinking…", "analyzing…", and active tail
6
+ // thoughts).
7
+ //
8
+ // Mathematical model:
9
+ // - Window width W = min(L, 5), where L is the code-point length.
10
+ // - Short strings (L < 25): unidirectional left-to-right sweep at 80ms/step
11
+ // with a 3-step lead-in and 3-step lead-out dead-zone.
12
+ // - Long strings (L >= 25): bidirectional ping-pong sweep at 40ms/step
13
+ // with smooth lead-in/lead-out turnarounds.
14
+ //
15
+ // Invariant:
16
+ // - Strictly preserves character sequence and terminal column width:
17
+ // stripAnsi(renderRunningLight(s)) === stripAnsi(s)
18
+ // visibleWidth(renderRunningLight(s)) === visibleWidth(s)
19
+ //
20
+ // Pure TypeScript under strict mode.
21
+
22
+ // @ts-expect-error theme.js has no TypeScript declaration yet.
23
+ import { paint, bold, dim, HAS_COLOR, COLOR_DEPTH, IS_LIGHT } from './theme.js';
24
+ import { stripAnsi } from './text.js';
25
+
26
+ export type RunningLightSpeed = 'off' | 'slow' | 'medium' | 'fast';
27
+ export type RunningLightBaseRole = 'muted' | 'warn' | 'accent' | 'ink' | 'dim';
28
+
29
+ export interface RunningLightWindow {
30
+ start: number;
31
+ width: number;
32
+ active: boolean;
33
+ }
34
+
35
+ export interface RunningLightOptions {
36
+ /** Monotonic or turn-elapsed timestamp in milliseconds. */
37
+ nowMs?: number | undefined;
38
+ /** Optional frame tick counter (fallback when nowMs is not provided). */
39
+ tick?: number | undefined;
40
+ /** Sweep speed preset. Defaults to 'medium' (80ms short / 40ms long). */
41
+ speed?: RunningLightSpeed | undefined;
42
+ /** Base theme role for characters outside the active highlight window. */
43
+ baseRole?: RunningLightBaseRole | undefined;
44
+ /** Whether to apply bold emphasis across the active highlight window. */
45
+ boldActive?: boolean | undefined;
46
+ }
47
+
48
+ const DARK_TRUECOLOR_STOPS: readonly [string, string, string, string, string] = [
49
+ '\x1b[38;2;154;186;104m', // 0: outer shoulder (#9aba68)
50
+ '\x1b[38;2;182;224;111m', // 1: Signal Lime (#b6e06f)
51
+ '\x1b[1m\x1b[38;2;232;248;204m', // 2: luminous specular crest (#e8f8cc)
52
+ '\x1b[38;2;182;224;111m', // 3: Signal Lime (#b6e06f)
53
+ '\x1b[38;2;154;186;104m', // 4: outer shoulder (#9aba68)
54
+ ];
55
+
56
+ const LIGHT_TRUECOLOR_STOPS: readonly [string, string, string, string, string] = [
57
+ '\x1b[38;2;92;124;42m', // 0: outer shoulder (#5c7c2a)
58
+ '\x1b[38;2;78;112;24m', // 1: deep Signal Lime (#4e7018)
59
+ '\x1b[1m\x1b[38;2;38;64;4m', // 2: high-contrast crest (#264004)
60
+ '\x1b[38;2;78;112;24m', // 3: deep Signal Lime (#4e7018)
61
+ '\x1b[38;2;92;124;42m', // 4: outer shoulder (#5c7c2a)
62
+ ];
63
+
64
+ const DARK_256_STOPS: readonly [string, string, string, string, string] = [
65
+ '\x1b[38;5;107m',
66
+ '\x1b[38;5;149m',
67
+ '\x1b[1m\x1b[38;5;193m',
68
+ '\x1b[38;5;149m',
69
+ '\x1b[38;5;107m',
70
+ ];
71
+
72
+ const LIGHT_256_STOPS: readonly [string, string, string, string, string] = [
73
+ '\x1b[38;5;64m',
74
+ '\x1b[38;5;28m',
75
+ '\x1b[1m\x1b[38;5;22m',
76
+ '\x1b[38;5;28m',
77
+ '\x1b[38;5;64m',
78
+ ];
79
+
80
+ const RESET = '\x1b[0m';
81
+
82
+ /**
83
+ * Resolves the step duration in milliseconds for short (< 25 chars) and
84
+ * long (>= 25 chars) strings.
85
+ */
86
+ export function resolveRunningLightSpeed(
87
+ speed: RunningLightSpeed = 'medium'
88
+ ): { shortStepMs: number; longStepMs: number } {
89
+ switch (speed) {
90
+ case 'off':
91
+ return { shortStepMs: 0, longStepMs: 0 };
92
+ case 'slow':
93
+ return { shortStepMs: 200, longStepMs: 100 };
94
+ case 'fast':
95
+ return { shortStepMs: 20, longStepMs: 10 };
96
+ case 'medium':
97
+ default:
98
+ return { shortStepMs: 80, longStepMs: 40 };
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Computes the active highlight window [start, start + width) at timestamp `nowMs`.
104
+ *
105
+ * - For `runesLen < 25`: unidirectional left-to-right sweep at `shortStepMs`.
106
+ * - For `runesLen >= 25`: bidirectional ping-pong sweep at `longStepMs`.
107
+ */
108
+ export function runningLightWindow(
109
+ runesLen: number,
110
+ nowMs: number,
111
+ speed: RunningLightSpeed = 'medium'
112
+ ): RunningLightWindow {
113
+ const len = Math.max(0, Math.floor(runesLen));
114
+ const { shortStepMs, longStepMs } = resolveRunningLightSpeed(speed);
115
+ if (len <= 0 || shortStepMs <= 0 || longStepMs <= 0) {
116
+ return { start: 0, width: 0, active: false };
117
+ }
118
+
119
+ const t = Math.max(0, Math.floor(Number.isFinite(nowMs) ? nowMs : 0));
120
+ const windowWidth = Math.min(len, 5);
121
+ const span = len + windowWidth;
122
+ const limit = span + 6;
123
+
124
+ if (len < 25) {
125
+ const step = Math.floor(t / shortStepMs);
126
+ const phase = ((step % limit) + limit) % limit;
127
+ const pos = phase - windowWidth;
128
+ const start = pos - 3;
129
+ return { start, width: windowWidth, active: true };
130
+ }
131
+
132
+ const halfPeriod = span + 5;
133
+ const fullPeriod = halfPeriod * 2;
134
+ const step = Math.floor(t / longStepMs);
135
+ const phase = ((step % fullPeriod) + fullPeriod) % fullPeriod;
136
+ const folded = phase < limit ? phase : fullPeriod - phase;
137
+ const pos = folded - windowWidth;
138
+ const start = pos - 3;
139
+ return { start, width: windowWidth, active: true };
140
+ }
141
+
142
+ /**
143
+ * Maps a character offset [0 .. windowWidth - 1] inside the highlight window
144
+ * to one of the 5 chromatic gradient stops [0 .. 4].
145
+ */
146
+ function mapWindowOffsetToStop(offset: number, windowWidth: number): 0 | 1 | 2 | 3 | 4 {
147
+ if (windowWidth <= 1) return 2;
148
+ if (windowWidth >= 5) {
149
+ const clamped = Math.max(0, Math.min(4, offset));
150
+ return clamped as 0 | 1 | 2 | 3 | 4;
151
+ }
152
+ const scaled = Math.floor((offset * 5) / windowWidth);
153
+ const clamped = Math.max(0, Math.min(4, scaled));
154
+ return clamped as 0 | 1 | 2 | 3 | 4;
155
+ }
156
+
157
+ function paintBaseSegment(
158
+ segment: string,
159
+ baseRole: RunningLightBaseRole,
160
+ boldActive: boolean
161
+ ): string {
162
+ if (!segment) return '';
163
+ if (baseRole === 'dim') return dim(segment);
164
+ const painted = paint(baseRole, segment);
165
+ return boldActive && baseRole === 'warn' ? bold(painted) : painted;
166
+ }
167
+
168
+ function paintStopSegment(
169
+ segment: string,
170
+ stop: 0 | 1 | 2 | 3 | 4,
171
+ boldActive: boolean
172
+ ): string {
173
+ if (!segment) return '';
174
+ if (!HAS_COLOR || COLOR_DEPTH <= 1) return segment;
175
+
176
+ if (COLOR_DEPTH >= 16777216) {
177
+ const palette = IS_LIGHT ? LIGHT_TRUECOLOR_STOPS : DARK_TRUECOLOR_STOPS;
178
+ const prefix = palette[stop];
179
+ const boldPrefix = boldActive && stop !== 2 ? '\x1b[1m' : '';
180
+ return `${boldPrefix}${prefix}${segment}${RESET}`;
181
+ }
182
+
183
+ if (COLOR_DEPTH >= 256) {
184
+ const palette = IS_LIGHT ? LIGHT_256_STOPS : DARK_256_STOPS;
185
+ const prefix = palette[stop];
186
+ const boldPrefix = boldActive && stop !== 2 ? '\x1b[1m' : '';
187
+ return `${boldPrefix}${prefix}${segment}${RESET}`;
188
+ }
189
+
190
+ // 16-color fallback
191
+ if (stop === 2) {
192
+ return bold(paint('ink', segment));
193
+ }
194
+ return boldActive || stop === 1 || stop === 3
195
+ ? bold(paint('accent', segment))
196
+ : paint('accent', segment);
197
+ }
198
+
199
+ /**
200
+ * Renders `text` with a travelling running-light shimmer highlight at the
201
+ * current timestamp or tick.
202
+ *
203
+ * Strictly width-stable: never adds or removes characters.
204
+ */
205
+ export function renderRunningLight(
206
+ text: string,
207
+ options: RunningLightOptions = {}
208
+ ): string {
209
+ const plain = stripAnsi(String(text ?? ''));
210
+ if (!plain) return '';
211
+
212
+ const baseRole: RunningLightBaseRole = options.baseRole ?? 'muted';
213
+ const boldActive = Boolean(options.boldActive);
214
+ const speed: RunningLightSpeed = options.speed ?? 'medium';
215
+
216
+ if (!HAS_COLOR || COLOR_DEPTH <= 1 || speed === 'off') {
217
+ return HAS_COLOR ? paintBaseSegment(plain, baseRole, boldActive) : plain;
218
+ }
219
+
220
+ const chars = Array.from(plain);
221
+ const len = chars.length;
222
+ const nowMs = options.nowMs !== undefined
223
+ ? options.nowMs
224
+ : options.tick !== undefined
225
+ ? options.tick * 80
226
+ : 0;
227
+
228
+ const win = runningLightWindow(len, nowMs, speed);
229
+ if (!win.active || win.width <= 0) {
230
+ return paintBaseSegment(plain, baseRole, boldActive);
231
+ }
232
+
233
+ const windowEnd = win.start + win.width;
234
+ // Fast path: when the highlight window is completely in the lead-in or
235
+ // lead-out dead-zone outside [0, len), paint the entire string in one pass.
236
+ if (windowEnd <= 0 || win.start >= len) {
237
+ return paintBaseSegment(plain, baseRole, boldActive);
238
+ }
239
+
240
+ // Coalesce consecutive characters with the same style index (-1 = base, 0..4 = stop)
241
+ let out = '';
242
+ let currentStyle = -2;
243
+ let currentRun = '';
244
+
245
+ const flushRun = (style: number, run: string): void => {
246
+ if (!run) return;
247
+ if (style < 0) {
248
+ out += paintBaseSegment(run, baseRole, boldActive);
249
+ } else {
250
+ out += paintStopSegment(run, style as 0 | 1 | 2 | 3 | 4, boldActive);
251
+ }
252
+ };
253
+
254
+ for (let i = 0; i < len; i++) {
255
+ const ch = chars[i]!;
256
+ const style = (i >= win.start && i < windowEnd)
257
+ ? mapWindowOffsetToStop(i - win.start, win.width)
258
+ : -1;
259
+
260
+ if (style !== currentStyle) {
261
+ flushRun(currentStyle, currentRun);
262
+ currentStyle = style;
263
+ currentRun = ch;
264
+ } else {
265
+ currentRun += ch;
266
+ }
267
+ }
268
+ flushRun(currentStyle, currentRun);
269
+
270
+ return out;
271
+ }
@@ -20,7 +20,13 @@ export function sessionMainWidth(columns, home = false) {
20
20
  }
21
21
  /** The session input uses the available conversation column, with a small inset. */
22
22
  export function sessionComposerWidth(columns) {
23
- return Number.isFinite(columns) ? Math.max(20, Math.floor(columns) - 3) : 77;
23
+ const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
24
+ if (available <= 112) {
25
+ return Math.max(20, available - 3);
26
+ }
27
+ // Dynamic readable measure scaling on wide terminals:
28
+ const readableMeasure = Math.round(109 + 20 * Math.log2(available / 112));
29
+ return Math.min(available - 3, Math.max(20, readableMeasure));
24
30
  }
25
31
  /** Render only facts the runtime can actually report. */
26
32
  export function sessionSidebarRows(facts, height) {
@@ -34,7 +34,13 @@ export function sessionMainWidth(columns: number, home = false): number {
34
34
 
35
35
  /** The session input uses the available conversation column, with a small inset. */
36
36
  export function sessionComposerWidth(columns: number): number {
37
- return Number.isFinite(columns) ? Math.max(20, Math.floor(columns) - 3) : 77;
37
+ const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
38
+ if (available <= 112) {
39
+ return Math.max(20, available - 3);
40
+ }
41
+ // Dynamic readable measure scaling on wide terminals:
42
+ const readableMeasure = Math.round(109 + 20 * Math.log2(available / 112));
43
+ return Math.min(available - 3, Math.max(20, readableMeasure));
38
44
  }
39
45
 
40
46
  /** Render only facts the runtime can actually report. */
package/src/tui/stage.js CHANGED
@@ -225,15 +225,15 @@ export class Stage {
225
225
 
226
226
  const next = this.normalize(rows);
227
227
  const target = caret && Number.isFinite(caret.row)
228
- ? { row: Math.max(0, Math.min(Math.floor(caret.row), this.height - 1)), col: Math.max(0, Math.floor(caret.col) || 0) }
229
- : { row: this.height - 1, col: 0 };
228
+ ? { row: Math.max(0, Math.min(Math.floor(caret.row), this.height - 1)), col: Math.max(0, Math.floor(caret.col) || 0), hideCursor: Boolean(caret.hideCursor) }
229
+ : { row: this.height - 1, col: 0, hideCursor: Boolean(caret?.hideCursor) };
230
230
 
231
231
  const changed = [];
232
232
  for (let i = 0; i < this.height; i++) {
233
233
  if (next[i] !== this.prev[i]) changed.push(i);
234
234
  }
235
235
 
236
- const caretMoved = target.row !== this.caret.row || target.col !== this.caret.col;
236
+ const caretMoved = target.row !== this.caret.row || target.col !== this.caret.col || target.hideCursor !== this.caret.hideCursor;
237
237
  // A frame with nothing to say emits zero bytes. opencode's renderer makes
238
238
  // the same bet and calls it out as its main anti-flicker mechanism.
239
239
  if (changed.length === 0 && !caretMoved) return 0;
@@ -246,7 +246,7 @@ export class Stage {
246
246
  this.moveTo(target.row);
247
247
  this.write('\r');
248
248
  if (target.col > 0) this.write(`\x1b[${target.col}C`);
249
- this.write(SHOW_CURSOR + '\x1b[6 q' + SYNC_OFF);
249
+ this.write((target.hideCursor ? HIDE_CURSOR : SHOW_CURSOR) + '\x1b[6 q' + SYNC_OFF);
250
250
 
251
251
  this.prev = next;
252
252
  this.caret = target;
@@ -393,7 +393,7 @@ export class StageSurface {
393
393
  const view = caret?.modal
394
394
  ? placeDialog(promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0)
395
395
  : placeHome(this.homeInfo, promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0);
396
- return this.stage.paint(view.rows, { row: view.caretRow, col: view.caretCol });
396
+ return this.stage.paint(view.rows, { row: view.caretRow, col: view.caretCol, hideCursor: caret?.hideCursor });
397
397
  }
398
398
 
399
399
  const width = this.width;
@@ -446,7 +446,19 @@ export class StageSurface {
446
446
  const card = renderTurnPreviewCard(hoveredTurn, 52);
447
447
  const anchorY = this.hoveredTurnAnchorY ?? Math.floor(rows.length / 2);
448
448
  rows = overlayTurnPreviewCard(rows, card, anchorY, this.turnRailLayout?.railX ?? 1, mainWidth);
449
+ if (this.turnRailLayout) {
450
+ const cardWidth = 52;
451
+ const railX = this.turnRailLayout.railX ?? 1;
452
+ let cardX = railX - cardWidth - 1;
453
+ if (cardX < 0 || (railX <= 4 && railX + 2 + cardWidth <= mainWidth)) {
454
+ cardX = Math.max(0, Math.min(mainWidth - cardWidth - 1, railX + 2));
455
+ }
456
+ const startY = Math.max(0, Math.min(rows.length - card.length, anchorY - Math.floor(card.length / 2)));
457
+ this.turnRailLayout.cardRect = { x: cardX, y: startY, width: cardWidth, height: card.length, turnIndex: hoveredTurn.turnIndex };
458
+ }
449
459
  }
460
+ } else if (this.turnRailLayout) {
461
+ this.turnRailLayout.cardRect = null;
450
462
  }
451
463
  if (this.messageActionOverlay) {
452
464
  const overlay = this.messageActionOverlay;
@@ -489,7 +501,8 @@ export class StageSurface {
489
501
  const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
490
502
  return this.stage.paint(painted, {
491
503
  row: rows.length + caretRow,
492
- col: caretCol
504
+ col: caretCol,
505
+ hideCursor: caret?.hideCursor
493
506
  });
494
507
  }
495
508
 
@@ -666,18 +679,12 @@ export class StageSurface {
666
679
  let row = rows[i] || '';
667
680
  if (hasTurns && railResult) {
668
681
  const leftCell = railResult.cells[i] || ' ';
669
- if (leftCell !== ' ') {
670
- if (row.startsWith(' ')) {
671
- row = ` ${leftCell} ${row.slice(3)}`;
672
- } else if (row.startsWith(' ')) {
673
- row = ` ${leftCell}${row.slice(2)}`;
674
- } else if (row.startsWith(' ')) {
675
- row = ` ${leftCell}${row.slice(1)}`;
676
- } else if (row.length > 0) {
677
- row = ` ${leftCell} ${row}`;
678
- } else {
679
- row = ` ${leftCell} `;
680
- }
682
+ if (row.startsWith(' ')) {
683
+ row = ` ${leftCell} ${row.slice(3)}`;
684
+ } else if (row.length === 0) {
685
+ row = leftCell !== ' ' ? ` ${leftCell} ` : '';
686
+ } else {
687
+ row = ` ${leftCell} ${row}`;
681
688
  }
682
689
  }
683
690
  rows[i] = `${padEnd(row, contentWidth)} ${rightCell}`;
@@ -22,6 +22,8 @@ import { paint, dim, GLYPHS } from './theme.js';
22
22
  import { truncate, visibleWidth, safeDisplay, shortenHome } from './text.js';
23
23
  import { contextMeter } from './block.js';
24
24
  import { CHARS_PER_TOKEN } from '../contextManager.js';
25
+ import { formatAnimatedStatus } from './engineSpinner.js';
26
+ import { renderRunningLight } from './runningLight.js';
25
27
  /** 1234 -> "1.2k", 1234567 -> "1.2M". Token counts are read, not summed. */
26
28
  export function compactCount(value) {
27
29
  const n = Number(value) || 0;
@@ -73,6 +75,7 @@ export class StatusLine {
73
75
  turnTokens = 0;
74
76
  turnCost = 0;
75
77
  cachedTokens = 0;
78
+ onTick = null;
76
79
  constructor() {
77
80
  this.reset();
78
81
  }
@@ -147,8 +150,12 @@ export class StatusLine {
147
150
  /**
148
151
  * Build the line.
149
152
  */
150
- render({ message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '' } = {}) {
151
- const head = spinnerFrame ? `${paint('accent', spinnerFrame)} ` : '';
153
+ render({ message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '', tick } = {}) {
154
+ const head = spinnerFrame
155
+ ? (typeof spinnerFrame === 'string' && spinnerFrame.includes('\x1b')
156
+ ? `${spinnerFrame} `
157
+ : `${paint('accent', spinnerFrame)} `)
158
+ : '';
152
159
  const budget = Math.max(10, width - visibleWidth(head) - 1);
153
160
  const segments = [];
154
161
  if (elapsedMs > 0)
@@ -164,7 +171,10 @@ export class StatusLine {
164
171
  if (this.model)
165
172
  segments.push(this.model);
166
173
  const separator = ` ${GLYPHS.dot} `;
167
- const text = safeDisplay(message);
174
+ const rawMessage = tick !== undefined
175
+ ? formatAnimatedStatus(message || 'working', tick)
176
+ : (message || (spinnerFrame ? 'working' : ''));
177
+ const text = safeDisplay(rawMessage);
168
178
  const kept = segments.slice();
169
179
  const wanted = Math.min(visibleWidth(text), Math.max(18, Math.floor(budget / 2)));
170
180
  while (kept.length > 0) {
@@ -178,7 +188,20 @@ export class StatusLine {
178
188
  ? Math.max(1, budget - visibleWidth(tail) - separator.length)
179
189
  : budget;
180
190
  const body = truncate(text, messageBudget, GLYPHS.ellipsis);
181
- const left = `${head}${paint('muted', body)}`;
191
+ const isAnimating = tick !== undefined || elapsedMs > 0 || Boolean(spinnerFrame);
192
+ const shimmerNowMs = elapsedMs > 0 ? elapsedMs : (tick !== undefined ? tick * 80 : 320);
193
+ if (isAnimating && this.onTick) {
194
+ try {
195
+ this.onTick(shimmerNowMs, tick);
196
+ }
197
+ catch {
198
+ // Never allow a tick observer to disrupt status rendering
199
+ }
200
+ }
201
+ const styledBody = isAnimating
202
+ ? renderRunningLight(body, { nowMs: shimmerNowMs, baseRole: 'muted' })
203
+ : paint('muted', body);
204
+ const left = `${head}${styledBody}`;
182
205
  if (!tail)
183
206
  return left;
184
207
  const gap = Math.max(visibleWidth(separator), width - 1 - visibleWidth(left) - visibleWidth(tail));