@causyne/agent 1.20.62 → 1.20.65

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 (65) 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/approvalPolicy.js +19 -0
  8. package/src/approvalPolicy.ts +18 -0
  9. package/src/browser/causyneBrowser.js +34 -4
  10. package/src/browser/causyneBrowser.ts +32 -4
  11. package/src/cliMode.js +12 -28
  12. package/src/commands.js +33 -0
  13. package/src/decisionPolicy.js +18 -1
  14. package/src/decisionPolicy.ts +18 -1
  15. package/src/implementationPlan.js +26 -0
  16. package/src/implementationPlan.ts +25 -0
  17. package/src/observer/coldObserver.js +6 -1
  18. package/src/observer/coldObserver.ts +6 -1
  19. package/src/observer.js +24 -2
  20. package/src/observer.ts +24 -2
  21. package/src/providers/acp.js +2 -8
  22. package/src/providers/acp.ts +2 -8
  23. package/src/providers/antigravity.js +7 -10
  24. package/src/providers/antigravity.ts +7 -10
  25. package/src/smartToolsUse.js +1 -1
  26. package/src/smartToolsUse.ts +1 -1
  27. package/src/toolPacks.js +1 -1
  28. package/src/toolPacks.ts +1 -1
  29. package/src/tools/toolSelfRepair.js +51 -8
  30. package/src/tools/toolSelfRepair.ts +42 -9
  31. package/src/tui/CausyneRotor.js +234 -0
  32. package/src/tui/CausyneRotor.ts +280 -0
  33. package/src/tui/activityLayout.js +1 -1
  34. package/src/tui/activityLayout.ts +1 -1
  35. package/src/tui/chatRenderer.js +56 -7
  36. package/src/tui/chatboxClipboard.js +96 -10
  37. package/src/tui/chatboxClipboard.ts +121 -11
  38. package/src/tui/clipboardImage.js +308 -0
  39. package/src/tui/clipboardImage.ts +320 -0
  40. package/src/tui/codeStreamRenderer.js +89 -1
  41. package/src/tui/codeStreamRenderer.ts +109 -1
  42. package/src/tui/composerControls.js +2 -0
  43. package/src/tui/composerControls.ts +2 -0
  44. package/src/tui/dialogs.js +41 -6
  45. package/src/tui/engineSpinner.js +20 -0
  46. package/src/tui/engineSpinner.ts +46 -0
  47. package/src/tui/lineEditor.js +44 -12
  48. package/src/tui/messageInteraction.js +16 -5
  49. package/src/tui/messageInteraction.ts +14 -5
  50. package/src/tui/observerPicker.js +4 -8
  51. package/src/tui/observerPicker.ts +4 -8
  52. package/src/tui/prompt.js +80 -43
  53. package/src/tui/runningLight.js +213 -0
  54. package/src/tui/runningLight.ts +271 -0
  55. package/src/tui/sessionSidebar.js +7 -1
  56. package/src/tui/sessionSidebar.ts +7 -1
  57. package/src/tui/stage.js +4 -4
  58. package/src/tui/stageSurface.js +21 -14
  59. package/src/tui/statusLine.js +27 -4
  60. package/src/tui/statusLine.ts +27 -4
  61. package/src/tui/theme.js +5 -2
  62. package/src/tui/thinkingBox.js +41 -10
  63. package/src/tui/thinkingBox.ts +43 -10
  64. package/src/tui/turnRail.js +155 -24
  65. package/src/tui/turnRail.ts +170 -22
@@ -0,0 +1,320 @@
1
+ // Sovereign Cross-Platform Clipboard Image Reader & Attachment Manager.
2
+ // Captures screenshots and images pasted from system clipboard across macOS (osascript),
3
+ // Windows/WSL (PowerShell System.Windows.Forms), and Linux (wl-paste, xclip).
4
+ // Provides seamless multimodal image attachment for TUI prompt editors and slash commands.
5
+
6
+ import { spawnSync } from 'node:child_process';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import os from 'node:os';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { causyneHome, resolveUserPath } from '../utils/paths.js';
12
+
13
+ export interface ClipboardImageAttachment {
14
+ type: 'image';
15
+ mimeType: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
16
+ base64: string;
17
+ name: string;
18
+ path: string;
19
+ size: number;
20
+ }
21
+
22
+ /**
23
+ * Format bytes into readable string: '128 KB', '1.5 MB'.
24
+ */
25
+ export function formatByteSize(bytes: number): string {
26
+ if (bytes < 1024) return `${bytes} B`;
27
+ if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
28
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
29
+ }
30
+
31
+ /**
32
+ * Detect image mime type from binary magic bytes.
33
+ */
34
+ export function detectImageMimeType(buffer: Buffer): 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' | null {
35
+ if (!buffer || buffer.length < 8) return null;
36
+ // PNG: 89 50 4E 47 0D 0A 1A 0A
37
+ if (buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4e && buffer[3] === 0x47) {
38
+ return 'image/png';
39
+ }
40
+ // JPEG: FF D8 FF
41
+ if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) {
42
+ return 'image/jpeg';
43
+ }
44
+ // GIF: 47 49 46 38
45
+ if (buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46 && buffer[3] === 0x38) {
46
+ return 'image/gif';
47
+ }
48
+ // WebP: 52 49 46 46 ... 57 45 42 50
49
+ if (buffer.length >= 12 &&
50
+ buffer[0] === 0x52 && buffer[1] === 0x49 && buffer[2] === 0x46 && buffer[3] === 0x46 &&
51
+ buffer[8] === 0x57 && buffer[9] === 0x45 && buffer[10] === 0x42 && buffer[11] === 0x50) {
52
+ return 'image/webp';
53
+ }
54
+ return null;
55
+ }
56
+
57
+ /**
58
+ * Ensure the causyne attachments directory exists and return its path.
59
+ */
60
+ export function getAttachmentsDirectory(): string {
61
+ const dir = path.join(causyneHome(), 'attachments');
62
+ if (!fs.existsSync(dir)) {
63
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
64
+ }
65
+ return dir;
66
+ }
67
+
68
+ /**
69
+ * Save raw image buffer to persistent attachments directory and return attachment object.
70
+ */
71
+ export function persistImageBuffer(
72
+ buffer: Buffer,
73
+ preferredName?: string
74
+ ): ClipboardImageAttachment | null {
75
+ const mimeType = detectImageMimeType(buffer);
76
+ if (!mimeType) return null;
77
+
78
+ const ext = mimeType === 'image/jpeg' ? 'jpg'
79
+ : mimeType === 'image/webp' ? 'webp'
80
+ : mimeType === 'image/gif' ? 'gif'
81
+ : 'png';
82
+
83
+ const timestamp = Date.now();
84
+ const filename = preferredName
85
+ ? path.basename(preferredName)
86
+ : `screenshot_${timestamp}.${ext}`;
87
+
88
+ const attachmentsDir = getAttachmentsDirectory();
89
+ const filePath = path.join(attachmentsDir, filename);
90
+
91
+ fs.writeFileSync(filePath, buffer, { mode: 0o600 });
92
+
93
+ return {
94
+ type: 'image',
95
+ mimeType,
96
+ base64: buffer.toString('base64'),
97
+ name: filename,
98
+ path: filePath,
99
+ size: buffer.length
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Read screenshot or image from macOS clipboard using built-in osascript.
105
+ * Supports both PNG and JPEG image data placed on clipboard by macOS, browsers, and terminals.
106
+ */
107
+ function readDarwinClipboardImageSync(): Buffer | null {
108
+ const tempFile = path.join('/tmp', `causyne_clip_${Date.now()}_${Math.random().toString(36).slice(2, 8)}.png`);
109
+ // Script uses standard AppleScript POSIX file API with safe error handling and file descriptor close guard
110
+ const script = [
111
+ 'try',
112
+ ' set imageData to (the clipboard as "PNGf")',
113
+ ` set fileRef to open for access POSIX file "${tempFile}" with write permission`,
114
+ ' set eof fileRef to 0',
115
+ ' write imageData to fileRef',
116
+ ' close access fileRef',
117
+ ' return "ok"',
118
+ 'on error',
119
+ ' try',
120
+ ` close access (POSIX file "${tempFile}")`,
121
+ ' end try',
122
+ ' try',
123
+ ' set imageData to (the clipboard as JPEG picture)',
124
+ ` set fileRef to open for access POSIX file "${tempFile}" with write permission`,
125
+ ' set eof fileRef to 0',
126
+ ' write imageData to fileRef',
127
+ ' close access fileRef',
128
+ ' return "ok"',
129
+ ' on error',
130
+ ' try',
131
+ ` close access (POSIX file "${tempFile}")`,
132
+ ' end try',
133
+ ' return ""',
134
+ ' end try',
135
+ 'end try'
136
+ ].join('\n');
137
+
138
+ try {
139
+ const res = spawnSync('osascript', ['-e', script], {
140
+ encoding: 'utf8',
141
+ timeout: 3000,
142
+ windowsHide: true
143
+ });
144
+ if (res.status === 0 && res.stdout.trim() === 'ok' && fs.existsSync(tempFile)) {
145
+ const buf = fs.readFileSync(tempFile);
146
+ return buf.length > 0 ? buf : null;
147
+ }
148
+ } catch {
149
+ // osascript clipboard read is best-effort
150
+ } finally {
151
+ try {
152
+ if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
153
+ } catch {
154
+ // Ignore cleanup error
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+
160
+ /**
161
+ * Read screenshot or image from Windows or WSL clipboard via PowerShell.
162
+ */
163
+ function readWindowsClipboardImageSync(): Buffer | null {
164
+ const command = process.platform === 'win32' ? 'powershell.exe' : 'powershell.exe';
165
+ const psScript = 'Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }';
166
+
167
+ try {
168
+ const res = spawnSync(command, ['-NonInteractive', '-NoProfile', '-Command', psScript], {
169
+ encoding: 'utf8',
170
+ timeout: 4000,
171
+ maxBuffer: 32 * 1024 * 1024,
172
+ windowsHide: true
173
+ });
174
+ if (res.status === 0 && res.stdout) {
175
+ const b64 = res.stdout.trim();
176
+ if (b64.length > 0) {
177
+ const buf = Buffer.from(b64, 'base64');
178
+ return buf.length > 0 ? buf : null;
179
+ }
180
+ }
181
+ } catch {
182
+ // PowerShell clipboard image is best-effort
183
+ }
184
+ return null;
185
+ }
186
+
187
+ /**
188
+ * Read screenshot or image from Linux clipboard via Wayland (wl-paste) or X11 (xclip).
189
+ */
190
+ function readLinuxClipboardImageSync(): Buffer | null {
191
+ // Try Wayland first
192
+ try {
193
+ const wl = spawnSync('wl-paste', ['-t', 'image/png'], {
194
+ timeout: 2500,
195
+ maxBuffer: 32 * 1024 * 1024
196
+ });
197
+ if (wl.status === 0 && Buffer.isBuffer(wl.stdout) && wl.stdout.length > 0) {
198
+ return wl.stdout;
199
+ }
200
+ } catch {
201
+ // Fall through to X11
202
+ }
203
+
204
+ // Try X11 xclip
205
+ try {
206
+ const xc = spawnSync('xclip', ['-selection', 'clipboard', '-t', 'image/png', '-o'], {
207
+ timeout: 2500,
208
+ maxBuffer: 32 * 1024 * 1024
209
+ });
210
+ if (xc.status === 0 && Buffer.isBuffer(xc.stdout) && xc.stdout.length > 0) {
211
+ return xc.stdout;
212
+ }
213
+ } catch {
214
+ // Fall through
215
+ }
216
+
217
+ return null;
218
+ }
219
+
220
+ /**
221
+ * Synchronously read screenshot or image from the system clipboard.
222
+ * Returns ClipboardImageAttachment if an image is present, or null if none.
223
+ */
224
+ export function readClipboardImageSync(): ClipboardImageAttachment | null {
225
+ try {
226
+ let buf: Buffer | null = null;
227
+ if (process.platform === 'darwin') {
228
+ buf = readDarwinClipboardImageSync();
229
+ } else if (process.platform === 'win32' || (os.release().toLowerCase().includes('wsl'))) {
230
+ buf = readWindowsClipboardImageSync();
231
+ } else if (process.platform === 'linux') {
232
+ buf = readLinuxClipboardImageSync();
233
+ }
234
+
235
+ if (buf && buf.length > 0) {
236
+ return persistImageBuffer(buf);
237
+ }
238
+ } catch {
239
+ // Non-throwing guard
240
+ }
241
+ return null;
242
+ }
243
+
244
+ /**
245
+ * Clean up and extract a valid local file path from pasted text or drag-and-drop strings.
246
+ * Strips quotes, file:// URIs, and backslash escape sequences.
247
+ */
248
+ export function extractPastedFilePath(input: string): string {
249
+ let raw = String(input ?? '').trim();
250
+ // Strip surrounding quotes
251
+ while (raw.length >= 2 && ((raw.startsWith('"') && raw.endsWith('"')) || (raw.startsWith("'") && raw.endsWith("'")))) {
252
+ raw = raw.slice(1, -1).trim();
253
+ }
254
+ // Handle file:// URI
255
+ if (raw.startsWith('file://')) {
256
+ try {
257
+ raw = fileURLToPath(raw);
258
+ } catch {
259
+ // ignore
260
+ }
261
+ }
262
+ // Unescape backslash-escaped spaces/characters on Unix, and backslash-escaped spaces on Windows
263
+ if (process.platform !== 'win32') {
264
+ raw = raw.replace(/\\(.)/g, '$1');
265
+ } else {
266
+ raw = raw.replace(/\\ /g, ' ');
267
+ }
268
+ return raw;
269
+ }
270
+
271
+ const KNOWN_IMAGE_EXTENSIONS = new Set([
272
+ '.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp', '.tiff', '.tif'
273
+ ]);
274
+
275
+ /**
276
+ * Check if a file path corresponds to an existing local image file.
277
+ */
278
+ export function isLocalImageFile(rawPath: string): boolean {
279
+ try {
280
+ const cleaned = extractPastedFilePath(rawPath);
281
+ if (!cleaned) return false;
282
+ const resolved = resolveUserPath(cleaned);
283
+ const ext = path.extname(resolved).toLowerCase();
284
+ if (!KNOWN_IMAGE_EXTENSIONS.has(ext)) return false;
285
+ if (!fs.existsSync(resolved)) return false;
286
+ const stat = fs.statSync(resolved);
287
+ return stat.isFile() && stat.size > 0 && stat.size <= 25 * 1024 * 1024;
288
+ } catch {
289
+ return false;
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Load a local image file as an attachment (e.g. from /image or /attach command).
295
+ */
296
+ export function loadLocalImageAttachment(rawPath: string): ClipboardImageAttachment | null {
297
+ try {
298
+ const cleaned = extractPastedFilePath(rawPath);
299
+ if (!cleaned) return null;
300
+ const resolved = resolveUserPath(cleaned);
301
+ if (!fs.existsSync(resolved)) return null;
302
+ const stat = fs.statSync(resolved);
303
+ if (!stat.isFile() || stat.size > 25 * 1024 * 1024) return null; // 25 MB ceiling
304
+
305
+ const buffer = fs.readFileSync(resolved);
306
+ const mimeType = detectImageMimeType(buffer);
307
+ if (!mimeType) return null;
308
+
309
+ return {
310
+ type: 'image',
311
+ mimeType,
312
+ base64: buffer.toString('base64'),
313
+ name: path.basename(resolved),
314
+ path: resolved,
315
+ size: buffer.length
316
+ };
317
+ } catch {
318
+ return null;
319
+ }
320
+ }
@@ -1,6 +1,7 @@
1
1
  import { ChatRenderer } from './chatRenderer.js';
2
2
  import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress } from './codeProgress.js';
3
- import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
3
+ import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES, renderThinkingFrame } from './thinkingBox.js';
4
+ import { formatElapsed } from './statusLine.js';
4
5
  import { markerAt } from './messageInteraction.js';
5
6
  import { AdaptiveWheelDampener } from './scrollInteraction.js';
6
7
  function lastStart(event) {
@@ -12,7 +13,63 @@ export class CodeStreamRenderer extends ChatRenderer {
12
13
  modelNote = '';
13
14
  lastReasoning = '';
14
15
  currentActivity = 'thinking';
16
+ streamingNowMs = 320;
17
+ streamingTick = undefined;
15
18
  codePanels = new WeakMap();
19
+ constructor(options) {
20
+ super(options);
21
+ const status = this.status;
22
+ if (status) {
23
+ status.onTick = (nowMs, tick) => {
24
+ this.onStatusTick(nowMs, tick);
25
+ };
26
+ }
27
+ }
28
+ /**
29
+ * Synchronizes the active streaming thinking frame with the live status clock
30
+ * so the running-light shimmer advances smoothly across both surfaces.
31
+ */
32
+ onStatusTick(nowMs, tick) {
33
+ this.streamingNowMs = nowMs;
34
+ this.streamingTick = tick;
35
+ const transcript = this.transcript;
36
+ if (!transcript || !Array.isArray(transcript.frames))
37
+ return;
38
+ const tail = transcript.frames.at(-1);
39
+ if (tail?.meta?.reasoning === true && tail.meta.streaming === true) {
40
+ if (nowMs > 0) {
41
+ tail.meta.durationText = formatElapsed(nowMs);
42
+ }
43
+ tail.rows = null;
44
+ tail.renderedWidth = -1;
45
+ transcript.cache = null;
46
+ transcript.revision++;
47
+ }
48
+ }
49
+ renderReasoning(content, options = {}) {
50
+ const width = this.measure();
51
+ const isStreaming = Boolean(options.streaming);
52
+ const resolvedTick = options.tick ?? this.streamingTick;
53
+ const rows = renderThinkingFrame(content, {
54
+ width,
55
+ streaming: isStreaming,
56
+ durationText: options.durationText ?? '',
57
+ collapsed: Boolean(options.collapsed),
58
+ startLine: Number(options.startLine) || 0,
59
+ ...(options.activity !== undefined ? { activity: options.activity } : {}),
60
+ ...(options.title !== undefined ? { title: options.title } : {}),
61
+ ...(options.completedTitle !== undefined ? { completedTitle: options.completedTitle } : {}),
62
+ ...(isStreaming ? { nowMs: options.nowMs ?? this.streamingNowMs } : {}),
63
+ ...(isStreaming && resolvedTick !== undefined ? { tick: resolvedTick } : {})
64
+ });
65
+ if (rows.length === 0)
66
+ return;
67
+ this.write();
68
+ for (const row of rows) {
69
+ this.write(row);
70
+ }
71
+ this.write();
72
+ }
16
73
  /** Scroll only the code beneath the pointer; leave the chat viewport alone. */
17
74
  scrollCodePanel(key, surface) {
18
75
  const wheel = key?.wheel;
@@ -128,6 +185,7 @@ export class CodeStreamRenderer extends ChatRenderer {
128
185
  }
129
186
  }
130
187
  handle(message) {
188
+ const selfStatus = this;
131
189
  if (message?.type === 'agent_activity') {
132
190
  const rawActivity = String(message.activity || message.message || '').trim();
133
191
  if (rawActivity) {
@@ -139,8 +197,18 @@ export class CodeStreamRenderer extends ChatRenderer {
139
197
  activity: this.currentActivity,
140
198
  title: rawActivity
141
199
  });
200
+ if (selfStatus.quietStatus) {
201
+ selfStatus.currentStatus = rawActivity;
202
+ selfStatus.onStatusChange?.(rawActivity);
203
+ }
142
204
  return true;
143
205
  }
206
+ const handled = super.handle(message);
207
+ if (selfStatus.quietStatus) {
208
+ selfStatus.currentStatus = rawActivity;
209
+ selfStatus.onStatusChange?.(rawActivity);
210
+ }
211
+ return handled;
144
212
  }
145
213
  }
146
214
  if (message?.type === 'notice' && message.nativeStep === true) {
@@ -165,6 +233,11 @@ export class CodeStreamRenderer extends ChatRenderer {
165
233
  activity = 'planning';
166
234
  }
167
235
  this.currentActivity = activity;
236
+ if (selfStatus.quietStatus) {
237
+ const statusLabel = `${activity.charAt(0).toUpperCase() + activity.slice(1)}…`;
238
+ selfStatus.currentStatus = statusLabel;
239
+ selfStatus.onStatusChange?.(statusLabel);
240
+ }
168
241
  const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
169
242
  this.lastReasoning = currentContent;
170
243
  super.onAgentReasoning({
@@ -198,6 +271,7 @@ export class CodeStreamRenderer extends ChatRenderer {
198
271
  }
199
272
  return true;
200
273
  }
274
+ const preservedStatus = selfStatus.quietStatus ? selfStatus.currentStatus : '';
201
275
  const handled = super.handle({
202
276
  ...message,
203
277
  activity: message.activity || this.currentActivity
@@ -205,6 +279,20 @@ export class CodeStreamRenderer extends ChatRenderer {
205
279
  if (message.streaming === false) {
206
280
  this.lastReasoning = '';
207
281
  }
282
+ else if (selfStatus.quietStatus) {
283
+ const activeStatus = preservedStatus || `${this.currentActivity || 'thinking'}…`;
284
+ selfStatus.currentStatus = activeStatus;
285
+ selfStatus.onStatusChange?.(activeStatus);
286
+ }
287
+ return handled;
288
+ }
289
+ if (message?.type === 'usage_update' && selfStatus.quietStatus) {
290
+ const preservedStatus = selfStatus.currentStatus;
291
+ const handled = super.handle(message);
292
+ if (preservedStatus) {
293
+ selfStatus.currentStatus = preservedStatus;
294
+ selfStatus.onStatusChange?.(preservedStatus);
295
+ }
208
296
  return handled;
209
297
  }
210
298
  if (['agent_message', 'budget_warning', 'step_start', 'task_complete', 'error', 'agent_plan'].includes(message?.type || '')
@@ -1,6 +1,7 @@
1
1
  import { ChatRenderer } from './chatRenderer.js';
2
2
  import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress, type CodeProgressEvent } from './codeProgress.js';
3
- import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
3
+ import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES, renderThinkingFrame } from './thinkingBox.js';
4
+ import { formatElapsed, type StatusLine } from './statusLine.js';
4
5
  import { markerAt } from './messageInteraction.js';
5
6
  import { AdaptiveWheelDampener } from './scrollInteraction.js';
6
7
 
@@ -37,8 +38,80 @@ export class CodeStreamRenderer extends ChatRenderer {
37
38
  private modelNote = '';
38
39
  private lastReasoning = '';
39
40
  private currentActivity = 'thinking';
41
+ private streamingNowMs = 320;
42
+ private streamingTick: number | undefined = undefined;
40
43
  private readonly codePanels = new WeakMap<CodeFrame, CodePanelState>();
41
44
 
45
+ constructor(options?: Record<string, unknown>) {
46
+ super(options);
47
+ const status = (this as unknown as { status?: StatusLine }).status;
48
+ if (status) {
49
+ status.onTick = (nowMs: number, tick?: number) => {
50
+ this.onStatusTick(nowMs, tick);
51
+ };
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Synchronizes the active streaming thinking frame with the live status clock
57
+ * so the running-light shimmer advances smoothly across both surfaces.
58
+ */
59
+ onStatusTick(nowMs: number, tick?: number): void {
60
+ this.streamingNowMs = nowMs;
61
+ this.streamingTick = tick;
62
+ const transcript = this.transcript as unknown as CodeTranscript | null;
63
+ if (!transcript || !Array.isArray(transcript.frames)) return;
64
+ const tail = transcript.frames.at(-1);
65
+ if (tail?.meta?.reasoning === true && tail.meta.streaming === true) {
66
+ if (nowMs > 0) {
67
+ tail.meta.durationText = formatElapsed(nowMs);
68
+ }
69
+ tail.rows = null;
70
+ tail.renderedWidth = -1;
71
+ transcript.cache = null;
72
+ transcript.revision++;
73
+ }
74
+ }
75
+
76
+ override renderReasoning(
77
+ content: string,
78
+ options: {
79
+ streaming?: boolean;
80
+ durationText?: string;
81
+ collapsed?: boolean;
82
+ startLine?: number;
83
+ activity?: string;
84
+ title?: string;
85
+ completedTitle?: string;
86
+ nowMs?: number;
87
+ tick?: number;
88
+ } = {}
89
+ ): void {
90
+ const width = this.measure();
91
+ const isStreaming = Boolean(options.streaming);
92
+ const resolvedTick = options.tick ?? this.streamingTick;
93
+ const rows = renderThinkingFrame(content, {
94
+ width,
95
+ streaming: isStreaming,
96
+ durationText: options.durationText ?? '',
97
+ collapsed: Boolean(options.collapsed),
98
+ startLine: Number(options.startLine) || 0,
99
+ ...(options.activity !== undefined ? { activity: options.activity } : {}),
100
+ ...(options.title !== undefined ? { title: options.title } : {}),
101
+ ...(options.completedTitle !== undefined ? { completedTitle: options.completedTitle } : {}),
102
+ ...(isStreaming ? { nowMs: options.nowMs ?? this.streamingNowMs } : {}),
103
+ ...(isStreaming && resolvedTick !== undefined ? { tick: resolvedTick } : {})
104
+ });
105
+
106
+ if (rows.length === 0) return;
107
+
108
+ this.write();
109
+ for (const row of rows) {
110
+ this.write(row);
111
+ }
112
+ this.write();
113
+ }
114
+
42
115
  /** Scroll only the code beneath the pointer; leave the chat viewport alone. */
43
116
  scrollCodePanel(key: CodeWheel, surface: CodeSurface | null): boolean {
44
117
  const wheel = key?.wheel;
@@ -154,6 +227,12 @@ export class CodeStreamRenderer extends ChatRenderer {
154
227
  }
155
228
 
156
229
  override handle(message: RendererEvent): boolean {
230
+ const selfStatus = this as unknown as {
231
+ quietStatus?: boolean;
232
+ currentStatus?: string;
233
+ onStatusChange?: ((s: string) => void) | null;
234
+ };
235
+
157
236
  if (message?.type === 'agent_activity') {
158
237
  const rawActivity = String((message as any).activity || (message as any).message || '').trim();
159
238
  if (rawActivity) {
@@ -165,8 +244,18 @@ export class CodeStreamRenderer extends ChatRenderer {
165
244
  activity: this.currentActivity,
166
245
  title: rawActivity
167
246
  });
247
+ if (selfStatus.quietStatus) {
248
+ selfStatus.currentStatus = rawActivity;
249
+ selfStatus.onStatusChange?.(rawActivity);
250
+ }
168
251
  return true;
169
252
  }
253
+ const handled = super.handle(message);
254
+ if (selfStatus.quietStatus) {
255
+ selfStatus.currentStatus = rawActivity;
256
+ selfStatus.onStatusChange?.(rawActivity);
257
+ }
258
+ return handled;
170
259
  }
171
260
  }
172
261
 
@@ -188,6 +277,11 @@ export class CodeStreamRenderer extends ChatRenderer {
188
277
  activity = 'planning';
189
278
  }
190
279
  this.currentActivity = activity;
280
+ if (selfStatus.quietStatus) {
281
+ const statusLabel = `${activity.charAt(0).toUpperCase() + activity.slice(1)}…`;
282
+ selfStatus.currentStatus = statusLabel;
283
+ selfStatus.onStatusChange?.(statusLabel);
284
+ }
191
285
 
192
286
  const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
193
287
  this.lastReasoning = currentContent;
@@ -223,12 +317,26 @@ export class CodeStreamRenderer extends ChatRenderer {
223
317
  }
224
318
  return true;
225
319
  }
320
+ const preservedStatus = selfStatus.quietStatus ? selfStatus.currentStatus : '';
226
321
  const handled = super.handle({
227
322
  ...message,
228
323
  activity: (message as any).activity || this.currentActivity
229
324
  });
230
325
  if (message.streaming === false) {
231
326
  this.lastReasoning = '';
327
+ } else if (selfStatus.quietStatus) {
328
+ const activeStatus = preservedStatus || `${this.currentActivity || 'thinking'}…`;
329
+ selfStatus.currentStatus = activeStatus;
330
+ selfStatus.onStatusChange?.(activeStatus);
331
+ }
332
+ return handled;
333
+ }
334
+ if (message?.type === 'usage_update' && selfStatus.quietStatus) {
335
+ const preservedStatus = selfStatus.currentStatus;
336
+ const handled = super.handle(message);
337
+ if (preservedStatus) {
338
+ selfStatus.currentStatus = preservedStatus;
339
+ selfStatus.onStatusChange?.(preservedStatus);
232
340
  }
233
341
  return handled;
234
342
  }
@@ -19,6 +19,8 @@ export function openModeControl(prompt, loop) {
19
19
  config.autonomyMode = item.value;
20
20
  saveConfig(config);
21
21
  loop.setAutonomyMode(item.value);
22
+ prompt.renderer?.status?.setSession?.({ autonomyMode: item.value });
23
+ prompt.surface?.setSessionInfo?.({ autonomyMode: item.value });
22
24
  prompt.notice = `Mode ${item.value} active`;
23
25
  prompt.scheduleDraw();
24
26
  }
@@ -31,6 +31,8 @@ export function openModeControl(prompt: ControlPrompt, loop: ControlLoop): void
31
31
  config.autonomyMode = item.value;
32
32
  saveConfig(config);
33
33
  loop.setAutonomyMode(item.value);
34
+ (prompt as any).renderer?.status?.setSession?.({ autonomyMode: item.value });
35
+ (prompt as any).surface?.setSessionInfo?.({ autonomyMode: item.value });
34
36
  prompt.notice = `Mode ${item.value} active`;
35
37
  prompt.scheduleDraw();
36
38
  }