@causyne/agent 1.20.60 → 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 (90) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +1 -1
  4. package/src/acp/agentCatalog.ts +1 -1
  5. package/src/acp/client.js +48 -0
  6. package/src/acp/client.ts +44 -0
  7. package/src/acp/peerProfiles.js +3 -3
  8. package/src/acp/peerProfiles.ts +3 -3
  9. package/src/agentLoop.js +239 -33
  10. package/src/agentLoop.ts +248 -36
  11. package/src/checkpoints.js +23 -5
  12. package/src/cliMode.js +13 -2
  13. package/src/commands.js +534 -78
  14. package/src/contextManager.d.ts +3 -0
  15. package/src/contextManager.js +78 -5
  16. package/src/cortex/autoCondenser.js +105 -145
  17. package/src/cortex/autoCondenser.ts +185 -0
  18. package/src/cortex/cortexEngine.js +179 -0
  19. package/src/cortex/cortexEngine.ts +209 -0
  20. package/src/cortex/provisioner.js +12 -14
  21. package/src/cortex/provisioner.ts +29 -0
  22. package/src/cortex/vectorDb.js +307 -386
  23. package/src/cortex/vectorDb.ts +473 -0
  24. package/src/decisionPolicy.js +18 -1
  25. package/src/decisionPolicy.ts +18 -1
  26. package/src/implementationPlan.js +26 -0
  27. package/src/implementationPlan.ts +25 -0
  28. package/src/observer/coldObserver.js +6 -1
  29. package/src/observer/coldObserver.ts +6 -1
  30. package/src/observer.js +24 -2
  31. package/src/observer.ts +24 -2
  32. package/src/providers/acp.js +2 -8
  33. package/src/providers/acp.ts +2 -8
  34. package/src/providers/antigravity.js +7 -10
  35. package/src/providers/antigravity.ts +7 -10
  36. package/src/reporting.js +30 -7
  37. package/src/sessionJournal.js +13 -0
  38. package/src/sessionJournal.ts +13 -0
  39. package/src/smartToolsUse.js +1 -1
  40. package/src/smartToolsUse.ts +1 -1
  41. package/src/tokenTracker.js +22 -0
  42. package/src/tokenTracker.ts +28 -0
  43. package/src/toolPacks.js +1 -1
  44. package/src/toolPacks.ts +1 -1
  45. package/src/tools/toolSelfRepair.js +51 -8
  46. package/src/tools/toolSelfRepair.ts +42 -9
  47. package/src/tui/CausyneRotor.js +234 -0
  48. package/src/tui/CausyneRotor.ts +280 -0
  49. package/src/tui/activityLayout.js +1 -1
  50. package/src/tui/activityLayout.ts +1 -1
  51. package/src/tui/chatRenderer.js +62 -9
  52. package/src/tui/chatboxClipboard.js +96 -10
  53. package/src/tui/chatboxClipboard.ts +121 -11
  54. package/src/tui/clipboardImage.js +308 -0
  55. package/src/tui/clipboardImage.ts +320 -0
  56. package/src/tui/codeStreamRenderer.js +89 -1
  57. package/src/tui/codeStreamRenderer.ts +109 -1
  58. package/src/tui/completion.js +34 -15
  59. package/src/tui/composerControls.js +5 -0
  60. package/src/tui/composerControls.ts +5 -0
  61. package/src/tui/dialogs.js +5 -2
  62. package/src/tui/engineSpinner.js +20 -0
  63. package/src/tui/engineSpinner.ts +46 -0
  64. package/src/tui/layout.js +1 -1
  65. package/src/tui/layout.ts +1 -1
  66. package/src/tui/lineEditor.js +44 -12
  67. package/src/tui/messageInteraction.js +16 -5
  68. package/src/tui/messageInteraction.ts +14 -5
  69. package/src/tui/observerPicker.js +319 -0
  70. package/src/tui/observerPicker.ts +382 -0
  71. package/src/tui/prompt.js +247 -55
  72. package/src/tui/runningLight.js +213 -0
  73. package/src/tui/runningLight.ts +271 -0
  74. package/src/tui/sessionSidebar.js +7 -1
  75. package/src/tui/sessionSidebar.ts +7 -1
  76. package/src/tui/stage.js +4 -4
  77. package/src/tui/stageSurface.js +27 -10
  78. package/src/tui/statusLine.js +27 -4
  79. package/src/tui/statusLine.ts +27 -4
  80. package/src/tui/theme.js +5 -2
  81. package/src/tui/thinkingBox.js +41 -10
  82. package/src/tui/thinkingBox.ts +43 -10
  83. package/src/tui/turnRail.js +155 -24
  84. package/src/tui/turnRail.ts +170 -22
  85. package/src/tui/usageCard.js +178 -0
  86. package/src/tui/usageCard.ts +240 -0
  87. package/src/utils/paths.js +30 -1
  88. package/src/utils/paths.ts +32 -1
  89. package/src/cortex/autoCondenser.d.ts +0 -2
  90. package/src/cortex/vectorDb.d.ts +0 -1
@@ -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,16 +393,14 @@ 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;
400
400
  const sidebar = sidebarVisible(width);
401
401
  const mainWidth = sessionMainWidth(width);
402
402
  const rail = this.railEnabled(mainWidth);
403
- const hasTurns = hasSessionTurns(this.transcript);
404
- const turnRailBudget = (rail && hasTurns) ? 3 : 0;
405
- const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
403
+ const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
406
404
 
407
405
  let block = promptRows;
408
406
  let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
@@ -448,7 +446,19 @@ export class StageSurface {
448
446
  const card = renderTurnPreviewCard(hoveredTurn, 52);
449
447
  const anchorY = this.hoveredTurnAnchorY ?? Math.floor(rows.length / 2);
450
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
+ }
451
459
  }
460
+ } else if (this.turnRailLayout) {
461
+ this.turnRailLayout.cardRect = null;
452
462
  }
453
463
  if (this.messageActionOverlay) {
454
464
  const overlay = this.messageActionOverlay;
@@ -491,7 +501,8 @@ export class StageSurface {
491
501
  const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
492
502
  return this.stage.paint(painted, {
493
503
  row: rows.length + caretRow,
494
- col: caretCol
504
+ col: caretCol,
505
+ hideCursor: caret?.hideCursor
495
506
  });
496
507
  }
497
508
 
@@ -646,13 +657,13 @@ export class StageSurface {
646
657
  */
647
658
  attachRail(rows, contentWidth) {
648
659
  const turns = collectSessionTurns(this.transcript, contentWidth);
660
+ const hasTurns = turns.length > 0;
649
661
  const isAtBottom = typeof this.viewport?.atBottom === 'function' ? this.viewport.atBottom() : false;
650
662
  const activeTurn = this.activeTurnIndex || resolveActiveTurnIndex(turns, this.viewport.state().scrollTop, rows.length, isAtBottom);
651
- const railResult = turns.length > 0
663
+ const railResult = hasTurns
652
664
  ? buildTurnRailCells(turns, rows.length, activeTurn, this.hoveredTurnIndex)
653
665
  : null;
654
666
 
655
- const hasTurns = turns.length > 0;
656
667
  this.turnRailLayout = {
657
668
  railX: hasTurns ? 1 : contentWidth + 1,
658
669
  stageTop: (this.out.rows || this.stage.height) - this.stage.height,
@@ -665,12 +676,18 @@ export class StageSurface {
665
676
  const rail = this.buildRail(rows.length, contentWidth);
666
677
  for (let i = 0; i < rows.length; i++) {
667
678
  const rightCell = rail[i] || ' ';
679
+ let row = rows[i] || '';
668
680
  if (hasTurns && railResult) {
669
681
  const leftCell = railResult.cells[i] || ' ';
670
- rows[i] = ` ${leftCell} ${padEnd(rows[i], contentWidth)} ${rightCell}`;
671
- } else {
672
- rows[i] = `${padEnd(rows[i], contentWidth)} ${rightCell}`;
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}`;
688
+ }
673
689
  }
690
+ rows[i] = `${padEnd(row, contentWidth)} ${rightCell}`;
674
691
  }
675
692
  return rows;
676
693
  }