@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
@@ -94,6 +94,11 @@ function renderMarkdown(text, width) {
94
94
  continue;
95
95
  }
96
96
 
97
+ if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
98
+ lines.push(dim(GLYPHS.hLine.repeat(Math.max(4, Math.min(width, 40)))));
99
+ continue;
100
+ }
101
+
97
102
  const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
98
103
  if (bullet) {
99
104
  const indent = bullet[1] + ' ';
@@ -104,6 +109,39 @@ function renderMarkdown(text, width) {
104
109
  continue;
105
110
  }
106
111
 
112
+ const numbered = line.match(/^(\s*)(\d+\.)\s+(.*)$/);
113
+ if (numbered) {
114
+ const prefix = `${numbered[1]}${bold(numbered[2])} `;
115
+ const indent = ' '.repeat(visibleWidth(`${numbered[1]}${numbered[2]} `));
116
+ const wrapped = wrap(inline(numbered[3]), width - indent.length);
117
+ wrapped.forEach((part, index) => {
118
+ lines.push(index === 0 ? `${prefix}${part}` : `${indent}${part}`);
119
+ });
120
+ continue;
121
+ }
122
+
123
+ const quote = line.match(/^(\s*)>\s?(.*)$/);
124
+ if (quote) {
125
+ const indent = quote[1] + paint('muted', '│ ');
126
+ const wrapped = wrap(inline(quote[2]), width - visibleWidth(indent));
127
+ wrapped.forEach((part) => {
128
+ lines.push(`${indent}${part}`);
129
+ });
130
+ continue;
131
+ }
132
+
133
+ if (/^\s*\|?(\s*:?-+:?\s*\|)+\s*$/.test(line)) {
134
+ lines.push(dim(' ' + GLYPHS.hLine.repeat(Math.max(4, Math.min(width - 4, 48)))));
135
+ continue;
136
+ }
137
+
138
+ const tableRow = line.match(/^\s*\|(.+)\|\s*$/);
139
+ if (tableRow) {
140
+ const cells = tableRow[1].split('|').map(c => inline(c.trim()));
141
+ lines.push(' ' + cells.join(paint('muted', ' │ ')));
142
+ continue;
143
+ }
144
+
107
145
  const trimmed = line.trim();
108
146
  if (trimmed === '') { lines.push(''); continue; }
109
147
  if (trimmed === '[' || trimmed === ']') continue;
@@ -206,8 +244,18 @@ function inline(text) {
206
244
  out = out.replace(/`([^`]+)`/g, (_m, code) => stash(HAS_COLOR ? paint('accent', code) : code));
207
245
  out = formatMarkdownMath(out);
208
246
  out = HAS_COLOR
209
- ? out.replace(/\*\*([^*]+)\*\*/g, (m, strong) => bold(strong))
247
+ ? out.replace(/\*\*\*([^*]+)\*\*\*/g, (_m, strong) => bold(paint('accent', strong)))
248
+ : out.replace(/\*\*\*([^*]+)\*\*\*/g, '$1');
249
+ out = HAS_COLOR
250
+ ? out.replace(/\*\*([^*]+)\*\*/g, (_m, strong) => bold(strong))
210
251
  : out.replace(/\*\*([^*]+)\*\*/g, '$1');
252
+ out = HAS_COLOR
253
+ ? out.replace(/(?<=^|[\s(])\*([^*\s](?:[^*]*[^*\s])?)\*(?=[\s).,!?]|$)/g, (_m, italic) => `\x1b[3m${italic}\x1b[23m`)
254
+ : out.replace(/(?<=^|[\s(])\*([^*\s](?:[^*]*[^*\s])?)\*(?=[\s).,!?]|$)/g, '$1');
255
+ out = HAS_COLOR
256
+ ? out.replace(/(?<=^|[\s(])_([^\s_](?:[^_]*[^\s_])?)_(?=[\s).,!?]|$)/g, (_m, italic) => `\x1b[3m${italic}\x1b[23m`)
257
+ : out.replace(/(?<=^|[\s(])_([^\s_](?:[^_]*[^\s_])?)_(?=[\s).,!?]|$)/g, '$1');
258
+ out = out.replace(/~~([^~]+)~~/g, HAS_COLOR ? '\x1b[9m$1\x1b[29m' : '$1');
211
259
 
212
260
  if (stashed.length > 0) {
213
261
  out = out.replace(/\u0000(\d+)\u0000/g, (m, index) => stashed[Number(index)] || '');
@@ -324,7 +372,11 @@ export class ChatRenderer {
324
372
  this.rowSink = previousSink;
325
373
  this.forcedWidth = previousWidth;
326
374
  }
327
- return sessionRows(sink, width).rows;
375
+ const maxAvailable = this.transcript?.surface?.composeAvailableWidth
376
+ ? this.transcript.surface.composeAvailableWidth()
377
+ : width;
378
+ const availableWidth = Math.min(width, maxAvailable);
379
+ return sessionRows(sink, availableWidth).rows;
328
380
  }
329
381
 
330
382
  /**
@@ -468,11 +520,12 @@ export class ChatRenderer {
468
520
  elapsedMs: Date.now() - since,
469
521
  steps: this.stepCount,
470
522
  width: this.width() - 1,
471
- spinnerFrame: frame
523
+ spinnerFrame: frame,
524
+ tick: this.spinnerIndex
472
525
  }));
473
526
  readline.clearLine(this.out, 1);
474
527
  this.spinnerIndex++;
475
- }, 90);
528
+ }, 125);
476
529
  }
477
530
 
478
531
  stopSpinner() {
@@ -509,7 +562,7 @@ export class ChatRenderer {
509
562
  const blockWidth = Math.max(8, width);
510
563
  const innerWidth = Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - 1);
511
564
  const rows = barBlock(
512
- wrapBlock(safeDisplay(text), innerWidth),
565
+ wrapBlock(safeDisplay(text), innerWidth, { hang: 0 }),
513
566
  { width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
514
567
  );
515
568
  this.write();
@@ -948,7 +1001,7 @@ export class ChatRenderer {
948
1001
  this.frame('approval', () => {
949
1002
  this.write();
950
1003
  this.write(`${paint('accent', GLYPHS.arrow)} ${bold(safeDisplay(request.header || 'decision required'))}`);
951
- for (const row of wrapBlock(safeDisplay(request.question || ''), Math.max(20, this.width() - 4))) this.write(` ${row}`);
1004
+ for (const row of wrapBlock(safeDisplay(request.question || ''), Math.max(20, this.width() - 4), { hang: 0 })) this.write(` ${row}`);
952
1005
  this.write();
953
1006
  }, { kind: request.kind || 'other' });
954
1007
  }
@@ -1170,7 +1223,7 @@ export class ChatRenderer {
1170
1223
  const head = label ? `${label} ${detail}` : detail;
1171
1224
 
1172
1225
  this.frame('error', () => {
1173
- const rows = wrapBlock(head, Math.max(20, this.width() - 7));
1226
+ const rows = wrapBlock(head, Math.max(20, this.width() - 7), { hang: 0 });
1174
1227
  this.write(` ${paint('danger', GLYPHS.cross)} ${paint('danger', rows[0] || '')}`);
1175
1228
  for (const row of rows.slice(1)) this.write(` ${dim(row)}`);
1176
1229
  }, { tool: msg.tool });
@@ -1311,7 +1364,7 @@ export class ChatRenderer {
1311
1364
  this.write();
1312
1365
  this.write(truncate(head, width - 1, GLYPHS.ellipsis));
1313
1366
  if (instruction) {
1314
- for (const line of wrapBlock(safeDisplay(instruction), width - 4)) {
1367
+ for (const line of wrapBlock(safeDisplay(instruction), width - 4, { hang: 0 })) {
1315
1368
  this.write(dim(` ${line}`));
1316
1369
  }
1317
1370
  }
@@ -1336,7 +1389,7 @@ export class ChatRenderer {
1336
1389
  this.frame('notice', () => {
1337
1390
  const width = this.measure();
1338
1391
  const marker = paint(tone === 'muted' ? 'rule' : tone, GLYPHS.vLine);
1339
- for (const line of wrapBlock(message, width - 2)) {
1392
+ for (const line of wrapBlock(message, width - 2, { hang: 0 })) {
1340
1393
  this.write(`${marker} ${dim(line)}`);
1341
1394
  }
1342
1395
  }, { tone });
@@ -1,6 +1,8 @@
1
1
  // Chatbox Clipboard Manager: surgical operations for copy, paste, and CRLF normalization.
2
2
  // Supports native terminal mouse selection, readline kill/yank, Alt+C/Alt+W/Alt+V, and /copy /paste commands.
3
3
  import { readClipboardSync, writeClipboardSync, emitOsc52Copy } from './clipboardSync.js';
4
+ import { readClipboardImageSync, formatByteSize, loadLocalImageAttachment, extractPastedFilePath, isLocalImageFile } from './clipboardImage.js';
5
+ export { loadLocalImageAttachment, extractPastedFilePath, isLocalImageFile };
4
6
  /**
5
7
  * Clean up text copied or pasted: normalize Windows CRLF and classic Mac CR to LF,
6
8
  * remove null bytes and non-printable control characters while preserving valid newlines and tabs.
@@ -42,22 +44,103 @@ export function copyChatboxInput(prompt) {
42
44
  }
43
45
  /**
44
46
  * Paste clipboard content into the chatbox prompt editor.
47
+ * Seamlessly supports both text and screenshot images from system clipboard,
48
+ * as well as drag-and-dropped local image file paths and empty bracketed pastes.
45
49
  */
46
50
  export function pasteIntoChatbox(prompt, fallbackText) {
47
- const raw = fallbackText ?? readClipboardSync();
48
- const text = normalizeClipboardText(raw);
49
- if (!text) {
50
- prompt.notice = 'clipboard is empty';
51
+ const clean = normalizeClipboardText(fallbackText);
52
+ // 1. If fallbackText was provided (e.g. drag & drop or file paste), check if it's a local image file
53
+ if (clean) {
54
+ const filePath = extractPastedFilePath(clean);
55
+ const localImg = loadLocalImageAttachment(filePath);
56
+ if (localImg) {
57
+ if (!Array.isArray(prompt.pendingAttachments)) {
58
+ prompt.pendingAttachments = [];
59
+ }
60
+ prompt.pendingAttachments.push(localImg);
61
+ const index = prompt.pendingAttachments.length;
62
+ const tag = `[Image ${index}] `;
63
+ prompt.editor.insert(tag);
64
+ if (typeof prompt.refreshCompletion === 'function') {
65
+ prompt.refreshCompletion();
66
+ }
67
+ prompt.notice = `attached image ${index} (${formatByteSize(localImg.size)})`;
68
+ prompt.scheduleDraw();
69
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
70
+ }
71
+ }
72
+ // 2. If fallbackText was empty (empty bracketed paste from Cmd+V in terminal when an image is copied)
73
+ // OR no fallbackText was passed (user pressed Ctrl+V, Alt+V, or typed /paste):
74
+ // Probe system clipboard for screenshot / image FIRST!
75
+ if (!clean) {
76
+ const img = readClipboardImageSync();
77
+ if (img) {
78
+ if (!Array.isArray(prompt.pendingAttachments)) {
79
+ prompt.pendingAttachments = [];
80
+ }
81
+ prompt.pendingAttachments.push(img);
82
+ const index = prompt.pendingAttachments.length;
83
+ const tag = `[Image ${index}] `;
84
+ prompt.editor.insert(tag);
85
+ if (typeof prompt.refreshCompletion === 'function') {
86
+ prompt.refreshCompletion();
87
+ }
88
+ prompt.notice = `attached clipboard image ${index} (${formatByteSize(img.size)})`;
89
+ prompt.scheduleDraw();
90
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
91
+ }
92
+ }
93
+ // 3. If fallbackText had non-image text: insert it into the editor
94
+ if (clean) {
95
+ prompt.editor.insert(clean);
96
+ if (typeof prompt.refreshCompletion === 'function') {
97
+ prompt.refreshCompletion();
98
+ }
99
+ prompt.notice = 'pasted from clipboard';
51
100
  prompt.scheduleDraw();
52
- return { success: false, notice: prompt.notice, text: '' };
101
+ return { success: true, notice: prompt.notice, text: clean, isImage: false };
53
102
  }
54
- prompt.editor.insert(text);
55
- if (typeof prompt.refreshCompletion === 'function') {
56
- prompt.refreshCompletion();
103
+ // 4. No fallbackText provided and no clipboard image: read text from clipboard
104
+ const clipText = normalizeClipboardText(readClipboardSync());
105
+ if (clipText) {
106
+ const filePath = extractPastedFilePath(clipText);
107
+ const localImg = loadLocalImageAttachment(filePath);
108
+ if (localImg) {
109
+ if (!Array.isArray(prompt.pendingAttachments)) {
110
+ prompt.pendingAttachments = [];
111
+ }
112
+ prompt.pendingAttachments.push(localImg);
113
+ const index = prompt.pendingAttachments.length;
114
+ const tag = `[Image ${index}] `;
115
+ prompt.editor.insert(tag);
116
+ if (typeof prompt.refreshCompletion === 'function') {
117
+ prompt.refreshCompletion();
118
+ }
119
+ prompt.notice = `attached image ${index} (${formatByteSize(localImg.size)})`;
120
+ prompt.scheduleDraw();
121
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
122
+ }
123
+ prompt.editor.insert(clipText);
124
+ if (typeof prompt.refreshCompletion === 'function') {
125
+ prompt.refreshCompletion();
126
+ }
127
+ prompt.notice = 'pasted from clipboard';
128
+ prompt.scheduleDraw();
129
+ return { success: true, notice: prompt.notice, text: clipText, isImage: false };
57
130
  }
58
- prompt.notice = 'pasted from clipboard';
131
+ // 5. Fallback to editor killRing
132
+ if (prompt.editor.killRing) {
133
+ prompt.editor.insert(prompt.editor.killRing);
134
+ if (typeof prompt.refreshCompletion === 'function') {
135
+ prompt.refreshCompletion();
136
+ }
137
+ prompt.notice = 'yanked from kill ring';
138
+ prompt.scheduleDraw();
139
+ return { success: true, notice: prompt.notice, text: prompt.editor.killRing, isImage: false };
140
+ }
141
+ prompt.notice = 'clipboard is empty';
59
142
  prompt.scheduleDraw();
60
- return { success: true, notice: prompt.notice, text };
143
+ return { success: false, notice: prompt.notice, text: '' };
61
144
  }
62
145
  /**
63
146
  * Extract the content of the last assistant turn from the conversation.
@@ -148,5 +231,8 @@ export function runPasteCommand(argv, ctx) {
148
231
  if (!result.success) {
149
232
  return { ok: false, output: 'Clipboard is empty or unavailable.' };
150
233
  }
234
+ if (result.isImage) {
235
+ return { ok: true, output: `Attached screenshot from clipboard (${result.text.trim()}).` };
236
+ }
151
237
  return { ok: true, output: `Pasted ${result.text.length} characters into chatbox input.` };
152
238
  }
@@ -2,6 +2,21 @@
2
2
  // Supports native terminal mouse selection, readline kill/yank, Alt+C/Alt+W/Alt+V, and /copy /paste commands.
3
3
 
4
4
  import { readClipboardSync, writeClipboardSync, emitOsc52Copy } from './clipboardSync.js';
5
+ import {
6
+ readClipboardImageSync,
7
+ formatByteSize,
8
+ loadLocalImageAttachment,
9
+ extractPastedFilePath,
10
+ isLocalImageFile,
11
+ type ClipboardImageAttachment
12
+ } from './clipboardImage.js';
13
+
14
+ export {
15
+ loadLocalImageAttachment,
16
+ extractPastedFilePath,
17
+ isLocalImageFile,
18
+ type ClipboardImageAttachment
19
+ };
5
20
 
6
21
  export interface ChatboxEditor {
7
22
  lines: string[][];
@@ -20,6 +35,7 @@ export interface ChatboxPrompt {
20
35
  notice: string;
21
36
  scheduleDraw(): void;
22
37
  refreshCompletion?: (() => void) | undefined;
38
+ pendingAttachments?: ClipboardImageAttachment[] | undefined;
23
39
  }
24
40
 
25
41
  export interface ConversationMessage {
@@ -79,22 +95,113 @@ export function copyChatboxInput(prompt: ChatboxPrompt): { success: boolean; not
79
95
 
80
96
  /**
81
97
  * Paste clipboard content into the chatbox prompt editor.
98
+ * Seamlessly supports both text and screenshot images from system clipboard,
99
+ * as well as drag-and-dropped local image file paths and empty bracketed pastes.
82
100
  */
83
- export function pasteIntoChatbox(prompt: ChatboxPrompt, fallbackText?: string): { success: boolean; notice: string; text: string } {
84
- const raw = fallbackText ?? readClipboardSync();
85
- const text = normalizeClipboardText(raw);
86
- if (!text) {
87
- prompt.notice = 'clipboard is empty';
101
+ export function pasteIntoChatbox(
102
+ prompt: ChatboxPrompt,
103
+ fallbackText?: string
104
+ ): { success: boolean; notice: string; text: string; isImage?: boolean } {
105
+ const clean = normalizeClipboardText(fallbackText);
106
+
107
+ // 1. If fallbackText was provided (e.g. drag & drop or file paste), check if it's a local image file
108
+ if (clean) {
109
+ const filePath = extractPastedFilePath(clean);
110
+ const localImg = loadLocalImageAttachment(filePath);
111
+ if (localImg) {
112
+ if (!Array.isArray(prompt.pendingAttachments)) {
113
+ prompt.pendingAttachments = [];
114
+ }
115
+ prompt.pendingAttachments.push(localImg);
116
+ const index = prompt.pendingAttachments.length;
117
+ const tag = `[Image ${index}] `;
118
+ prompt.editor.insert(tag);
119
+ if (typeof prompt.refreshCompletion === 'function') {
120
+ prompt.refreshCompletion();
121
+ }
122
+ prompt.notice = `attached image ${index} (${formatByteSize(localImg.size)})`;
123
+ prompt.scheduleDraw();
124
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
125
+ }
126
+ }
127
+
128
+ // 2. If fallbackText was empty (empty bracketed paste from Cmd+V in terminal when an image is copied)
129
+ // OR no fallbackText was passed (user pressed Ctrl+V, Alt+V, or typed /paste):
130
+ // Probe system clipboard for screenshot / image FIRST!
131
+ if (!clean) {
132
+ const img = readClipboardImageSync();
133
+ if (img) {
134
+ if (!Array.isArray(prompt.pendingAttachments)) {
135
+ prompt.pendingAttachments = [];
136
+ }
137
+ prompt.pendingAttachments.push(img);
138
+ const index = prompt.pendingAttachments.length;
139
+ const tag = `[Image ${index}] `;
140
+ prompt.editor.insert(tag);
141
+ if (typeof prompt.refreshCompletion === 'function') {
142
+ prompt.refreshCompletion();
143
+ }
144
+ prompt.notice = `attached clipboard image ${index} (${formatByteSize(img.size)})`;
145
+ prompt.scheduleDraw();
146
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
147
+ }
148
+ }
149
+
150
+ // 3. If fallbackText had non-image text: insert it into the editor
151
+ if (clean) {
152
+ prompt.editor.insert(clean);
153
+ if (typeof prompt.refreshCompletion === 'function') {
154
+ prompt.refreshCompletion();
155
+ }
156
+ prompt.notice = 'pasted from clipboard';
88
157
  prompt.scheduleDraw();
89
- return { success: false, notice: prompt.notice, text: '' };
158
+ return { success: true, notice: prompt.notice, text: clean, isImage: false };
90
159
  }
91
- prompt.editor.insert(text);
92
- if (typeof prompt.refreshCompletion === 'function') {
93
- prompt.refreshCompletion();
160
+
161
+ // 4. No fallbackText provided and no clipboard image: read text from clipboard
162
+ const clipText = normalizeClipboardText(readClipboardSync());
163
+ if (clipText) {
164
+ const filePath = extractPastedFilePath(clipText);
165
+ const localImg = loadLocalImageAttachment(filePath);
166
+ if (localImg) {
167
+ if (!Array.isArray(prompt.pendingAttachments)) {
168
+ prompt.pendingAttachments = [];
169
+ }
170
+ prompt.pendingAttachments.push(localImg);
171
+ const index = prompt.pendingAttachments.length;
172
+ const tag = `[Image ${index}] `;
173
+ prompt.editor.insert(tag);
174
+ if (typeof prompt.refreshCompletion === 'function') {
175
+ prompt.refreshCompletion();
176
+ }
177
+ prompt.notice = `attached image ${index} (${formatByteSize(localImg.size)})`;
178
+ prompt.scheduleDraw();
179
+ return { success: true, notice: prompt.notice, text: tag, isImage: true };
180
+ }
181
+
182
+ prompt.editor.insert(clipText);
183
+ if (typeof prompt.refreshCompletion === 'function') {
184
+ prompt.refreshCompletion();
185
+ }
186
+ prompt.notice = 'pasted from clipboard';
187
+ prompt.scheduleDraw();
188
+ return { success: true, notice: prompt.notice, text: clipText, isImage: false };
94
189
  }
95
- prompt.notice = 'pasted from clipboard';
190
+
191
+ // 5. Fallback to editor killRing
192
+ if (prompt.editor.killRing) {
193
+ prompt.editor.insert(prompt.editor.killRing);
194
+ if (typeof prompt.refreshCompletion === 'function') {
195
+ prompt.refreshCompletion();
196
+ }
197
+ prompt.notice = 'yanked from kill ring';
198
+ prompt.scheduleDraw();
199
+ return { success: true, notice: prompt.notice, text: prompt.editor.killRing, isImage: false };
200
+ }
201
+
202
+ prompt.notice = 'clipboard is empty';
96
203
  prompt.scheduleDraw();
97
- return { success: true, notice: prompt.notice, text };
204
+ return { success: false, notice: prompt.notice, text: '' };
98
205
  }
99
206
 
100
207
  /**
@@ -197,5 +304,8 @@ export function runPasteCommand(
197
304
  if (!result.success) {
198
305
  return { ok: false, output: 'Clipboard is empty or unavailable.' };
199
306
  }
307
+ if (result.isImage) {
308
+ return { ok: true, output: `Attached screenshot from clipboard (${result.text.trim()}).` };
309
+ }
200
310
  return { ok: true, output: `Pasted ${result.text.length} characters into chatbox input.` };
201
311
  }