@causyne/agent 1.20.112 → 1.20.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/tui/chatRenderer.js
CHANGED
|
@@ -57,9 +57,11 @@ const REASONING_LINES = 12;
|
|
|
57
57
|
const STATUS_GUTTER = 10;
|
|
58
58
|
|
|
59
59
|
function formatDuration(ms) {
|
|
60
|
-
if (ms
|
|
60
|
+
if (!Number.isFinite(ms) || ms <= 0) return '0ms';
|
|
61
|
+
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
61
62
|
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
|
|
62
|
-
|
|
63
|
+
const totalSeconds = Math.round(ms / 1000);
|
|
64
|
+
return `${Math.floor(totalSeconds / 60)}m ${totalSeconds % 60}s`;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/**
|
|
@@ -70,7 +72,14 @@ function formatDuration(ms) {
|
|
|
70
72
|
* inline code, fenced blocks and list bullets. Anything fancier belongs in a
|
|
71
73
|
* pager, not a chat transcript.
|
|
72
74
|
*/
|
|
75
|
+
function clampMarkdownIndent(raw, markerCols, targetWidth) {
|
|
76
|
+
const maxLead = Math.max(0, Math.min(Math.floor(targetWidth / 3), targetWidth - markerCols - 8));
|
|
77
|
+
const rawCols = visibleWidth(String(raw || '').replace(/\t/g, ' '));
|
|
78
|
+
return ' '.repeat(Math.min(rawCols, maxLead));
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
function renderMarkdown(text, width) {
|
|
82
|
+
const safeWidth = Number.isFinite(width) && width > 0 ? Math.max(12, Math.floor(width)) : 80;
|
|
74
83
|
const lines = [];
|
|
75
84
|
let inFence = false;
|
|
76
85
|
|
|
@@ -80,11 +89,14 @@ function renderMarkdown(text, width) {
|
|
|
80
89
|
if (/^\s*```/.test(line)) {
|
|
81
90
|
inFence = !inFence;
|
|
82
91
|
const language = line.replace(/^\s*```/, '').trim();
|
|
83
|
-
|
|
92
|
+
const maxLabel = Math.max(0, safeWidth - 8);
|
|
93
|
+
const safeLang = language.length > maxLabel ? language.slice(0, maxLabel) : language;
|
|
94
|
+
const trail = Math.max(0, safeWidth - 3 - (safeLang ? safeLang.length + 2 : 1));
|
|
95
|
+
lines.push(dim(`${GLYPHS.hLine.repeat(3)}${safeLang ? ' ' + safeLang + ' ' : ' '}${GLYPHS.hLine.repeat(trail)}`));
|
|
84
96
|
continue;
|
|
85
97
|
}
|
|
86
98
|
if (inFence) {
|
|
87
|
-
for (const codeRow of wrapBlock(' ' + line, Math.max(8,
|
|
99
|
+
for (const codeRow of wrapBlock(' ' + line, Math.max(8, safeWidth), { hang: 0 })) {
|
|
88
100
|
lines.push(paint('accent', codeRow));
|
|
89
101
|
}
|
|
90
102
|
continue;
|
|
@@ -93,21 +105,21 @@ function renderMarkdown(text, width) {
|
|
|
93
105
|
const heading = line.match(/^(#{1,6})\s+(.*)$/);
|
|
94
106
|
if (heading) {
|
|
95
107
|
lines.push('');
|
|
96
|
-
for (const headingRow of wrap(heading[2], Math.max(8,
|
|
108
|
+
for (const headingRow of wrap(heading[2], Math.max(8, safeWidth))) {
|
|
97
109
|
lines.push(bold(paint('ink', headingRow)));
|
|
98
110
|
}
|
|
99
111
|
continue;
|
|
100
112
|
}
|
|
101
113
|
|
|
102
114
|
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
103
|
-
lines.push(dim(GLYPHS.hLine.repeat(Math.max(4, Math.min(
|
|
115
|
+
lines.push(dim(GLYPHS.hLine.repeat(Math.max(4, Math.min(safeWidth, 40)))));
|
|
104
116
|
continue;
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
108
120
|
if (bullet) {
|
|
109
|
-
const indent = bullet[1] + ' ';
|
|
110
|
-
const wrapped = wrap(inline(bullet[2]),
|
|
121
|
+
const indent = clampMarkdownIndent(bullet[1], 4, safeWidth) + ' ';
|
|
122
|
+
const wrapped = wrap(inline(bullet[2]), Math.max(8, safeWidth - indent.length - 2));
|
|
111
123
|
wrapped.forEach((part, index) => {
|
|
112
124
|
lines.push(index === 0 ? `${indent}${paint('muted', GLYPHS.bullet)} ${part}` : `${indent} ${part}`);
|
|
113
125
|
});
|
|
@@ -116,9 +128,12 @@ function renderMarkdown(text, width) {
|
|
|
116
128
|
|
|
117
129
|
const numbered = line.match(/^(\s*)(\d+\.)\s+(.*)$/);
|
|
118
130
|
if (numbered) {
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const
|
|
131
|
+
const markerCols = visibleWidth(numbered[2]) + 1;
|
|
132
|
+
const lead = clampMarkdownIndent(numbered[1], markerCols, safeWidth);
|
|
133
|
+
const prefix = `${lead}${bold(numbered[2])} `;
|
|
134
|
+
const indentCols = visibleWidth(lead) + markerCols;
|
|
135
|
+
const indent = ' '.repeat(indentCols);
|
|
136
|
+
const wrapped = wrap(inline(numbered[3]), Math.max(8, safeWidth - indentCols));
|
|
122
137
|
wrapped.forEach((part, index) => {
|
|
123
138
|
lines.push(index === 0 ? `${prefix}${part}` : `${indent}${part}`);
|
|
124
139
|
});
|
|
@@ -127,8 +142,9 @@ function renderMarkdown(text, width) {
|
|
|
127
142
|
|
|
128
143
|
const quote = line.match(/^(\s*)>\s?(.*)$/);
|
|
129
144
|
if (quote) {
|
|
130
|
-
const
|
|
131
|
-
const
|
|
145
|
+
const lead = clampMarkdownIndent(quote[1], 2, safeWidth);
|
|
146
|
+
const indent = lead + paint('muted', '│ ');
|
|
147
|
+
const wrapped = wrap(inline(quote[2]), Math.max(8, safeWidth - visibleWidth(lead) - 2));
|
|
132
148
|
wrapped.forEach((part) => {
|
|
133
149
|
lines.push(`${indent}${part}`);
|
|
134
150
|
});
|
|
@@ -136,14 +152,14 @@ function renderMarkdown(text, width) {
|
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
if (/^\s*\|?(\s*:?-+:?\s*\|)+\s*$/.test(line)) {
|
|
139
|
-
lines.push(dim(' ' + GLYPHS.hLine.repeat(Math.max(4, Math.min(
|
|
155
|
+
lines.push(dim(' ' + GLYPHS.hLine.repeat(Math.max(4, Math.min(safeWidth - 4, 48)))));
|
|
140
156
|
continue;
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
const tableRow = line.match(/^\s*\|(.+)\|\s*$/);
|
|
144
160
|
if (tableRow) {
|
|
145
161
|
const cells = tableRow[1].split('|').map(c => c.trim());
|
|
146
|
-
for (const tableLine of wrapBlock(' ' + cells.join(' │ '), Math.max(8,
|
|
162
|
+
for (const tableLine of wrapBlock(' ' + cells.join(' │ '), Math.max(8, safeWidth), { hang: 0 })) {
|
|
147
163
|
lines.push(inline(tableLine));
|
|
148
164
|
}
|
|
149
165
|
continue;
|
|
@@ -152,7 +168,7 @@ function renderMarkdown(text, width) {
|
|
|
152
168
|
const trimmed = line.trim();
|
|
153
169
|
if (trimmed === '') { lines.push(''); continue; }
|
|
154
170
|
if (trimmed === '[' || trimmed === ']') continue;
|
|
155
|
-
for (const part of wrap(inline(line),
|
|
171
|
+
for (const part of wrap(inline(line), safeWidth)) lines.push(part);
|
|
156
172
|
}
|
|
157
173
|
|
|
158
174
|
// A fence that never closed.
|
|
@@ -470,7 +486,7 @@ export class ChatRenderer {
|
|
|
470
486
|
|
|
471
487
|
this.frame('turn', () => {
|
|
472
488
|
const parts = [];
|
|
473
|
-
if (model) parts.push(paint('ink', model));
|
|
489
|
+
if (model) parts.push(paint('ink', safeDisplay(model)));
|
|
474
490
|
parts.push(`${steps} step${steps === 1 ? '' : 's'}`);
|
|
475
491
|
if (durationMs > 0) parts.push(formatDuration(durationMs));
|
|
476
492
|
|
|
@@ -486,6 +502,7 @@ export class ChatRenderer {
|
|
|
486
502
|
this.stepCount = 0;
|
|
487
503
|
this.stepStartedAt = null;
|
|
488
504
|
this.turnStartedAt = Date.now();
|
|
505
|
+
this._activeAssistant = false;
|
|
489
506
|
this._activeReasoning = false;
|
|
490
507
|
this.status.reset();
|
|
491
508
|
}
|
|
@@ -563,10 +580,17 @@ export class ChatRenderer {
|
|
|
563
580
|
if (!text.trim()) return;
|
|
564
581
|
|
|
565
582
|
this.frame('user', () => {
|
|
566
|
-
const
|
|
567
|
-
|
|
583
|
+
const measured = this.width();
|
|
584
|
+
const maxCaptureWidth = Math.max(8, Math.min(
|
|
585
|
+
measured,
|
|
586
|
+
this.transcript?.surface?.composeAvailableWidth?.() ?? measured
|
|
587
|
+
) - 4);
|
|
588
|
+
const preferred = this.transcript
|
|
589
|
+
? (this.transcript.surface?.composeWidth?.() ?? sessionComposerWidth(measured))
|
|
568
590
|
: composerWidth(this.measure());
|
|
569
|
-
const blockWidth =
|
|
591
|
+
const blockWidth = this.transcript
|
|
592
|
+
? Math.max(8, Math.min(preferred, maxCaptureWidth))
|
|
593
|
+
: Math.max(8, preferred);
|
|
570
594
|
const innerWidth = Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - 1);
|
|
571
595
|
const rows = barBlock(
|
|
572
596
|
wrapBlock(safeDisplay(text), innerWidth, { hang: 0 }),
|
|
@@ -594,19 +618,26 @@ export class ChatRenderer {
|
|
|
594
618
|
renderSessionDivider(info = {}) {
|
|
595
619
|
this.transcript?.surface?.setSessionInfo?.(info);
|
|
596
620
|
this.frame('session', () => {
|
|
597
|
-
const width = this.measure();
|
|
598
|
-
const
|
|
599
|
-
const count = info.messagesCount ?? 0;
|
|
600
|
-
const
|
|
621
|
+
const width = Math.max(12, this.measure());
|
|
622
|
+
const rawTitle = safeDisplay((info && info.title) || 'Session');
|
|
623
|
+
const count = (info && info.messagesCount) ?? 0;
|
|
624
|
+
const rawCount = count > 0 ? ` (${count} message${count === 1 ? '' : 's'})` : '';
|
|
625
|
+
const countText = visibleWidth(rawCount) <= Math.max(0, width - 10) ? rawCount : '';
|
|
626
|
+
const title = truncate(rawTitle, Math.max(4, width - visibleWidth(countText) - 6), GLYPHS.ellipsis);
|
|
601
627
|
const badgeText = `${title}${countText}`;
|
|
602
|
-
const
|
|
628
|
+
const remaining = Math.max(2, width - visibleWidth(badgeText) - 2);
|
|
629
|
+
const leftRule = Math.max(1, Math.floor(remaining / 2));
|
|
630
|
+
const rightRule = Math.max(1, remaining - leftRule);
|
|
603
631
|
this.write();
|
|
604
|
-
this.write(`${paint('rule', GLYPHS.hLine.repeat(
|
|
632
|
+
this.write(`${paint('rule', GLYPHS.hLine.repeat(leftRule))} ${bold(paint('accent', title))}${dim(countText)} ${paint('rule', GLYPHS.hLine.repeat(rightRule))}`);
|
|
605
633
|
this.write();
|
|
606
634
|
});
|
|
607
635
|
}
|
|
608
636
|
|
|
609
637
|
clearTranscript() {
|
|
638
|
+
this._activeAssistant = false;
|
|
639
|
+
this._activeReasoning = false;
|
|
640
|
+
this.lastOutput = null;
|
|
610
641
|
if (this.transcript && typeof this.transcript.clear === 'function') {
|
|
611
642
|
this.transcript.clear();
|
|
612
643
|
}
|
|
@@ -617,6 +648,7 @@ export class ChatRenderer {
|
|
|
617
648
|
* Mirrors OpenCode's session conversation loader so prior turns are visible in viewport.
|
|
618
649
|
*/
|
|
619
650
|
renderSessionHistory(messages = [], sessionInfo = null) {
|
|
651
|
+
const safeMessages = Array.isArray(messages) ? messages : [];
|
|
620
652
|
const renderContent = () => {
|
|
621
653
|
this.transcript?.surface?.leaveHome?.(true);
|
|
622
654
|
this.clearTranscript();
|
|
@@ -625,32 +657,31 @@ export class ChatRenderer {
|
|
|
625
657
|
this.resetTurn();
|
|
626
658
|
|
|
627
659
|
const info = sessionInfo ? { ...sessionInfo } : {};
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
660
|
+
if (info.messagesCount === undefined || info.messagesCount === null) {
|
|
661
|
+
info.messagesCount = safeMessages.filter(m => m && m.role !== 'system').length;
|
|
662
|
+
}
|
|
663
|
+
const measuredChars = measureMessages(safeMessages);
|
|
664
|
+
// Loading an empty session must clear usage from the previous chat.
|
|
633
665
|
this.status.contextChars = measuredChars;
|
|
634
666
|
info.contextChars = measuredChars;
|
|
635
|
-
}
|
|
636
667
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
668
|
+
if (info.title || info.id) {
|
|
669
|
+
this.renderSessionDivider(info);
|
|
670
|
+
}
|
|
640
671
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
672
|
+
// Index tool results by tool_call_id to pair them with assistant tool_calls
|
|
673
|
+
const toolResultsById = new Map();
|
|
674
|
+
for (const m of safeMessages) {
|
|
675
|
+
if (m && m.role === 'tool' && m.tool_call_id) {
|
|
676
|
+
toolResultsById.set(m.tool_call_id, m);
|
|
677
|
+
}
|
|
646
678
|
}
|
|
647
|
-
}
|
|
648
679
|
|
|
649
|
-
|
|
680
|
+
const renderedToolMessages = new Set();
|
|
650
681
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
682
|
+
for (let i = 0; i < safeMessages.length; i++) {
|
|
683
|
+
const msg = safeMessages[i];
|
|
684
|
+
if (!msg) continue;
|
|
654
685
|
const role = String(msg.role || '').toLowerCase();
|
|
655
686
|
|
|
656
687
|
if (role === 'user') {
|
|
@@ -693,6 +724,7 @@ export class ChatRenderer {
|
|
|
693
724
|
// 3. If assistant invoked tool calls, render each tool step and pair with its result
|
|
694
725
|
if (Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0) {
|
|
695
726
|
for (const call of msg.tool_calls) {
|
|
727
|
+
if (!call || typeof call !== 'object') continue;
|
|
696
728
|
const toolName = call.function?.name || call.name || 'tool';
|
|
697
729
|
let args = {};
|
|
698
730
|
try {
|
|
@@ -706,7 +738,7 @@ export class ChatRenderer {
|
|
|
706
738
|
// Restore active implementation plan if update_plan was called
|
|
707
739
|
if (toolName === 'update_plan' && args && Array.isArray(args.plan)) {
|
|
708
740
|
this.onAgentPlan({
|
|
709
|
-
plan: args.plan.map(item => ({
|
|
741
|
+
plan: args.plan.filter(Boolean).map(item => ({
|
|
710
742
|
...item,
|
|
711
743
|
text: item.text || item.step || item.content || ''
|
|
712
744
|
}))
|
|
@@ -724,7 +756,7 @@ export class ChatRenderer {
|
|
|
724
756
|
}
|
|
725
757
|
if (toolName === 'update_plan' && Array.isArray(normalized.plan)) {
|
|
726
758
|
this.onAgentPlan({
|
|
727
|
-
plan: normalized.plan.map(item => ({
|
|
759
|
+
plan: normalized.plan.filter(Boolean).map(item => ({
|
|
728
760
|
...item,
|
|
729
761
|
text: item.text || item.step || item.content || ''
|
|
730
762
|
}))
|
|
@@ -743,7 +775,7 @@ export class ChatRenderer {
|
|
|
743
775
|
? msg.content
|
|
744
776
|
: (Array.isArray(msg.content)
|
|
745
777
|
? msg.content.map(p => (typeof p === 'string' ? p : (p && p.text) || '')).filter(Boolean).join('\n')
|
|
746
|
-
:
|
|
778
|
+
: (msg.content == null ? '' : String(msg.content)));
|
|
747
779
|
// The agent loop stores a protocol placeholder when a peer emits no
|
|
748
780
|
// final reply. Restoring it as a Causyne message falsely implies an
|
|
749
781
|
// answer was given. Older histories have the literal but no marker.
|
|
@@ -751,7 +783,7 @@ export class ChatRenderer {
|
|
|
751
783
|
|| (text.trim() === 'No final response was provided.'
|
|
752
784
|
&& (!Array.isArray(msg.tool_calls) || msg.tool_calls.length === 0));
|
|
753
785
|
if (syntheticNoFinal) {
|
|
754
|
-
const isLatestTurn = !
|
|
786
|
+
const isLatestTurn = !safeMessages.slice(i + 1).some(next =>
|
|
755
787
|
next && (next.role === 'assistant' || next.role === 'user'));
|
|
756
788
|
if (isLatestTurn) {
|
|
757
789
|
this.frame('notice', () => {
|
|
@@ -785,7 +817,7 @@ export class ChatRenderer {
|
|
|
785
817
|
}
|
|
786
818
|
}
|
|
787
819
|
|
|
788
|
-
const finalMeasured = measureMessages(
|
|
820
|
+
const finalMeasured = measureMessages(safeMessages);
|
|
789
821
|
if (finalMeasured > 0) {
|
|
790
822
|
this.status.contextChars = finalMeasured;
|
|
791
823
|
}
|
|
@@ -1005,20 +1037,24 @@ export class ChatRenderer {
|
|
|
1005
1037
|
}
|
|
1006
1038
|
|
|
1007
1039
|
onAgentActivity(msg) {
|
|
1040
|
+
if (!msg || typeof msg !== 'object') return;
|
|
1008
1041
|
const text = String(msg.activity || msg.message || '').trim();
|
|
1009
1042
|
if (!text) return;
|
|
1010
1043
|
this.frame('notice', () => {
|
|
1011
1044
|
const prefix = `${GLYPHS.arrow || '▸'} `;
|
|
1012
1045
|
for (const [index, row] of activityRows(text, this.width(), prefix).entries()) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1046
|
+
if (index === 0) {
|
|
1047
|
+
const body = row.startsWith(prefix) ? row.slice(prefix.length) : row;
|
|
1048
|
+
this.write(`${paint('accent', GLYPHS.arrow || '▸')} ${dim(body)}`);
|
|
1049
|
+
} else {
|
|
1050
|
+
this.write(dim(row));
|
|
1051
|
+
}
|
|
1016
1052
|
}
|
|
1017
1053
|
}, { activity: true });
|
|
1018
1054
|
}
|
|
1019
1055
|
|
|
1020
1056
|
onAgentPlan(msg) {
|
|
1021
|
-
if (!Array.isArray(msg.plan) || msg.plan.length === 0) return;
|
|
1057
|
+
if (!msg || !Array.isArray(msg.plan) || msg.plan.length === 0) return;
|
|
1022
1058
|
const plan = msg.plan.slice();
|
|
1023
1059
|
this.latestPlan = plan;
|
|
1024
1060
|
const placement = this.onPlanChange?.(plan);
|
|
@@ -1028,7 +1064,7 @@ export class ChatRenderer {
|
|
|
1028
1064
|
|
|
1029
1065
|
onDecisionRequest(msg) {
|
|
1030
1066
|
if (this.dialogWillAsk) return;
|
|
1031
|
-
const request = msg.request || {};
|
|
1067
|
+
const request = (msg && msg.request) || {};
|
|
1032
1068
|
this.frame('approval', () => {
|
|
1033
1069
|
this.write();
|
|
1034
1070
|
this.write(`${paint('accent', GLYPHS.arrow)} ${bold(safeDisplay(request.header || 'decision required'))}`);
|
|
@@ -1038,8 +1074,8 @@ export class ChatRenderer {
|
|
|
1038
1074
|
}
|
|
1039
1075
|
|
|
1040
1076
|
onDecisionResult(msg) {
|
|
1041
|
-
const request = msg.request || {};
|
|
1042
|
-
const answer = msg.answer;
|
|
1077
|
+
const request = (msg && msg.request) || {};
|
|
1078
|
+
const answer = msg && msg.answer;
|
|
1043
1079
|
this.frame('approval', () => {
|
|
1044
1080
|
if (!answer) {
|
|
1045
1081
|
this.write(` ${paint('muted', 'decision dismissed')} ${safeDisplay(request.header || '')}`);
|
|
@@ -1050,10 +1086,12 @@ export class ChatRenderer {
|
|
|
1050
1086
|
}
|
|
1051
1087
|
|
|
1052
1088
|
renderPlan(plan) {
|
|
1089
|
+
if (!Array.isArray(plan) || plan.length === 0) return;
|
|
1053
1090
|
const width = this.width();
|
|
1054
1091
|
this.write();
|
|
1055
1092
|
this.write(paint('muted', 'plan'));
|
|
1056
1093
|
for (const item of plan) {
|
|
1094
|
+
if (!item || typeof item !== 'object') continue;
|
|
1057
1095
|
const done = item.status === 'completed';
|
|
1058
1096
|
const active = item.status === 'in_progress';
|
|
1059
1097
|
const mark = done ? paint('success', GLYPHS.check)
|
|
@@ -1061,35 +1099,39 @@ export class ChatRenderer {
|
|
|
1061
1099
|
: paint('muted', GLYPHS.dot);
|
|
1062
1100
|
const text = item.text || item.step || item.content || '';
|
|
1063
1101
|
const label = done ? dim(safeDisplay(text)) : paint('ink', safeDisplay(text));
|
|
1064
|
-
this.write(` ${mark} ${truncate(label, width - 5, GLYPHS.ellipsis)}`);
|
|
1102
|
+
this.write(` ${mark} ${truncate(label, Math.max(8, width - 5), GLYPHS.ellipsis)}`);
|
|
1065
1103
|
}
|
|
1066
1104
|
this.write();
|
|
1067
1105
|
}
|
|
1068
1106
|
|
|
1069
1107
|
onStepStart(msg) {
|
|
1108
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1070
1109
|
this.stepStartedAt = Date.now();
|
|
1071
1110
|
this.stepCount++;
|
|
1072
1111
|
|
|
1073
|
-
const
|
|
1112
|
+
const toolLabel = safeDisplay(safeMsg.tool || 'tool') || 'tool';
|
|
1113
|
+
const { verb, detail } = describeTool(safeMsg.tool, safeMsg.args);
|
|
1074
1114
|
const step = this.stepCount;
|
|
1075
1115
|
|
|
1076
1116
|
this.frame('step', () => {
|
|
1077
1117
|
const width = this.width();
|
|
1078
1118
|
const index = paint('muted', String(step).padStart(2, '0'));
|
|
1079
|
-
const
|
|
1119
|
+
const displayVerb = verb || toolLabel;
|
|
1120
|
+
const name = paint('accent', padEnd(displayVerb, STATUS_GUTTER));
|
|
1080
1121
|
|
|
1081
|
-
const used = 2 + 2 + 1 + Math.max(visibleWidth(
|
|
1122
|
+
const used = 2 + 2 + 1 + Math.max(visibleWidth(displayVerb), STATUS_GUTTER) + 1;
|
|
1082
1123
|
const detailText = detail ? paint('ink', truncate(detail, Math.max(10, width - used - 12), GLYPHS.ellipsis)) : '';
|
|
1083
1124
|
|
|
1084
1125
|
this.write(`${paint('muted', GLYPHS.arrow)} ${index} ${name} ${detailText}`);
|
|
1085
|
-
}, { step, tool:
|
|
1126
|
+
}, { step, tool: safeMsg.tool, verb: verb || toolLabel, detail });
|
|
1086
1127
|
}
|
|
1087
1128
|
|
|
1088
1129
|
onStepComplete(msg) {
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1130
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1131
|
+
const elapsed = typeof safeMsg.elapsed === 'string'
|
|
1132
|
+
? safeMsg.elapsed
|
|
1091
1133
|
: (this.stepStartedAt ? formatDuration(Date.now() - this.stepStartedAt) : '');
|
|
1092
|
-
const result =
|
|
1134
|
+
const result = safeMsg.result || {};
|
|
1093
1135
|
|
|
1094
1136
|
// Kept so Ctrl+O can show the whole thing, and set here rather than inside
|
|
1095
1137
|
// the closure — a reflow must not re-point "the last output" at a tool
|
|
@@ -1147,14 +1189,14 @@ export class ChatRenderer {
|
|
|
1147
1189
|
// leave two frames showing two different outputs, not one shown twice.
|
|
1148
1190
|
const output = this.lastOutput;
|
|
1149
1191
|
this.frame('result', () => {
|
|
1150
|
-
const width = this.width() - 7;
|
|
1192
|
+
const width = Math.max(8, this.width() - 7);
|
|
1151
1193
|
this.write('');
|
|
1152
1194
|
for (const line of String(output.text).split('\n')) {
|
|
1153
1195
|
for (const part of wrap(safeDisplay(line), width)) {
|
|
1154
1196
|
this.write(` ${paint('rule', GLYPHS.vLine)} ${dim(part)}`);
|
|
1155
1197
|
}
|
|
1156
1198
|
}
|
|
1157
|
-
|
|
1199
|
+
if (output.spillPath) {
|
|
1158
1200
|
this.write(this.clipHint(output.spillPath));
|
|
1159
1201
|
}
|
|
1160
1202
|
this.write('');
|
|
@@ -1166,7 +1208,8 @@ export class ChatRenderer {
|
|
|
1166
1208
|
* Remember the payload Ctrl+O expands. Separate from rendering it, because
|
|
1167
1209
|
* rendering runs again on every reflow and this must not.
|
|
1168
1210
|
*/
|
|
1169
|
-
captureLastOutput(result
|
|
1211
|
+
captureLastOutput(result) {
|
|
1212
|
+
if (!result || typeof result !== 'object') return;
|
|
1170
1213
|
const payload = typeof result.output === 'string' ? result.output
|
|
1171
1214
|
: typeof result.log === 'string' ? result.log
|
|
1172
1215
|
: '';
|
|
@@ -1175,6 +1218,7 @@ export class ChatRenderer {
|
|
|
1175
1218
|
}
|
|
1176
1219
|
|
|
1177
1220
|
renderOutputPreview(result, toolName = '') {
|
|
1221
|
+
if (!result || typeof result !== 'object') return;
|
|
1178
1222
|
const rawPayload = typeof result.output === 'string' ? result.output
|
|
1179
1223
|
: typeof result.log === 'string' ? result.log
|
|
1180
1224
|
: '';
|
|
@@ -1186,7 +1230,7 @@ export class ChatRenderer {
|
|
|
1186
1230
|
: payload;
|
|
1187
1231
|
if (!source.trim()) return;
|
|
1188
1232
|
|
|
1189
|
-
const width = this.width() - 7;
|
|
1233
|
+
const width = Math.max(8, this.width() - 7);
|
|
1190
1234
|
const cleaned = safeDisplay(source).replace(/\n{3,}/g, '\n\n').trim();
|
|
1191
1235
|
|
|
1192
1236
|
// Wrap first, THEN cut — bounding by source newlines lets a single long
|
|
@@ -1252,7 +1296,8 @@ export class ChatRenderer {
|
|
|
1252
1296
|
* loudly as the work trains the user to read neither.
|
|
1253
1297
|
*/
|
|
1254
1298
|
onCheckpoint(msg) {
|
|
1255
|
-
|
|
1299
|
+
if (!msg || typeof msg !== 'object') return;
|
|
1300
|
+
const where = typeof msg.path === 'string' ? safeDisplay(shortenHome(msg.path)) : '';
|
|
1256
1301
|
const count = Number(msg.count) || 1;
|
|
1257
1302
|
this.frame('checkpoint', () => {
|
|
1258
1303
|
const label = where
|
|
@@ -1263,14 +1308,15 @@ export class ChatRenderer {
|
|
|
1263
1308
|
}
|
|
1264
1309
|
|
|
1265
1310
|
onStepError(msg) {
|
|
1311
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1266
1312
|
// Wrapped and hanging-indented, not written as one long string.
|
|
1267
1313
|
//
|
|
1268
1314
|
// Loop-level failures now carry a real explanation across several lines —
|
|
1269
1315
|
// what could not be reached, why, and what to check. Emitting that as a
|
|
1270
1316
|
// single write put the continuation lines at column 0, under a marker
|
|
1271
1317
|
// indented five columns, so the whole block read as unrelated fragments.
|
|
1272
|
-
const label = `${
|
|
1273
|
-
const rawError =
|
|
1318
|
+
const label = safeDisplay(`${safeMsg.tool || ''}`.trim());
|
|
1319
|
+
const rawError = safeMsg.error || (safeMsg.result && (safeMsg.result.error || safeMsg.result.message)) || '';
|
|
1274
1320
|
const detail = safeDisplay(`${rawError}`.trim());
|
|
1275
1321
|
const head = label && detail ? `${label} ${detail}` : (detail || label || 'failed');
|
|
1276
1322
|
|
|
@@ -1278,7 +1324,7 @@ export class ChatRenderer {
|
|
|
1278
1324
|
const rows = wrapBlock(head, Math.max(20, this.width() - 7), { hang: 0 });
|
|
1279
1325
|
this.write(` ${paint('danger', GLYPHS.cross)} ${paint('danger', rows[0] || '')}`);
|
|
1280
1326
|
for (const row of rows.slice(1)) this.write(` ${dim(row)}`);
|
|
1281
|
-
}, { tool:
|
|
1327
|
+
}, { tool: safeMsg.tool });
|
|
1282
1328
|
}
|
|
1283
1329
|
|
|
1284
1330
|
/**
|
|
@@ -1286,7 +1332,8 @@ export class ChatRenderer {
|
|
|
1286
1332
|
* L6 in the local-path audit: a bare "Proceed?" is not human-in-the-loop.
|
|
1287
1333
|
*/
|
|
1288
1334
|
onApprovalRequest(msg) {
|
|
1289
|
-
|
|
1335
|
+
if (!msg || typeof msg !== 'object') return;
|
|
1336
|
+
if (msg.toolCallId) this.pendingApprovals.set(msg.toolCallId, msg);
|
|
1290
1337
|
|
|
1291
1338
|
// When an interactive dialog will ask the question, DO NOT also print the
|
|
1292
1339
|
// whole request into the transcript. It shipped doing both: the same risk
|
|
@@ -1315,6 +1362,7 @@ export class ChatRenderer {
|
|
|
1315
1362
|
}
|
|
1316
1363
|
|
|
1317
1364
|
renderApprovalRequest(msg, diff = undefined) {
|
|
1365
|
+
if (!msg || typeof msg !== 'object') return;
|
|
1318
1366
|
// Colour carries the tier; the word never reaches the user. See the note
|
|
1319
1367
|
// in dialogs.js ApprovalLayer — 'DANGEROUS' printed at somebody installing a
|
|
1320
1368
|
// package teaches them to stop reading these.
|
|
@@ -1325,7 +1373,7 @@ export class ChatRenderer {
|
|
|
1325
1373
|
this.write();
|
|
1326
1374
|
this.write(`${paint(role, GLYPHS.warnMark)} ${paint('ink', 'permission required')} ${bold(safeDisplay(msg.tool || ''))}${verb ? dim(` ${verb}`) : ''}`);
|
|
1327
1375
|
if (detail) {
|
|
1328
|
-
this.write(` ${paint('ink', truncate(detail, this.width() - 4, GLYPHS.ellipsis))}`);
|
|
1376
|
+
this.write(` ${paint('ink', truncate(detail, Math.max(8, this.width() - 4), GLYPHS.ellipsis))}`);
|
|
1329
1377
|
}
|
|
1330
1378
|
|
|
1331
1379
|
// What the user is actually consenting to. Without this the approval gate
|
|
@@ -1379,7 +1427,8 @@ export class ChatRenderer {
|
|
|
1379
1427
|
}
|
|
1380
1428
|
|
|
1381
1429
|
onError(msg) {
|
|
1382
|
-
const
|
|
1430
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1431
|
+
const message = safeDisplay(safeMsg.message || '');
|
|
1383
1432
|
this.frame('error', () => {
|
|
1384
1433
|
this.write();
|
|
1385
1434
|
for (const row of wrappedChatRows(message, this.width(), `${badge('danger', 'ERROR')} `, 'danger')) this.write(row);
|
|
@@ -1388,14 +1437,16 @@ export class ChatRenderer {
|
|
|
1388
1437
|
}
|
|
1389
1438
|
|
|
1390
1439
|
onBudgetWarning(msg) {
|
|
1391
|
-
const
|
|
1440
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1441
|
+
const message = safeDisplay(safeMsg.message || '');
|
|
1392
1442
|
this.frame('notice', () => {
|
|
1393
1443
|
for (const row of wrappedChatRows(message, this.width(), `${badge('warn', 'BUDGET')} `, 'warn')) this.write(row);
|
|
1394
1444
|
}, { tone: 'warn' });
|
|
1395
1445
|
}
|
|
1396
1446
|
|
|
1397
1447
|
onStatus(msg) {
|
|
1398
|
-
|
|
1448
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1449
|
+
this.startSpinner(safeMsg.message || '');
|
|
1399
1450
|
}
|
|
1400
1451
|
|
|
1401
1452
|
/**
|
|
@@ -1414,9 +1465,9 @@ export class ChatRenderer {
|
|
|
1414
1465
|
const head = `${paint('accent', GLYPHS.step)} ${bold(paint('ink', 'skill'))}`
|
|
1415
1466
|
+ `${dim(` ${GLYPHS.dot} `)}${paint('agent', safeDisplay(id))}`;
|
|
1416
1467
|
this.write();
|
|
1417
|
-
this.write(truncate(head, width - 1, GLYPHS.ellipsis));
|
|
1468
|
+
this.write(truncate(head, Math.max(8, width - 1), GLYPHS.ellipsis));
|
|
1418
1469
|
if (instruction) {
|
|
1419
|
-
for (const line of wrapBlock(safeDisplay(instruction), width - 4, { hang: 0 })) {
|
|
1470
|
+
for (const line of wrapBlock(safeDisplay(instruction), Math.max(8, width - 4), { hang: 0 })) {
|
|
1420
1471
|
this.write(dim(` ${line}`));
|
|
1421
1472
|
}
|
|
1422
1473
|
}
|
|
@@ -1436,12 +1487,13 @@ export class ChatRenderer {
|
|
|
1436
1487
|
* as loudly as the agent's answer trains the user to stop reading both.
|
|
1437
1488
|
*/
|
|
1438
1489
|
onNotice(msg) {
|
|
1439
|
-
const
|
|
1440
|
-
const
|
|
1490
|
+
const safeMsg = msg && typeof msg === 'object' ? msg : {};
|
|
1491
|
+
const tone = ['accent', 'success', 'warn', 'muted'].includes(safeMsg.tone) ? safeMsg.tone : 'muted';
|
|
1492
|
+
const message = safeDisplay(safeMsg.message || '');
|
|
1441
1493
|
this.frame('notice', () => {
|
|
1442
1494
|
const width = this.measure();
|
|
1443
1495
|
const marker = paint(tone === 'muted' ? 'rule' : tone, GLYPHS.vLine);
|
|
1444
|
-
for (const line of wrapBlock(message, width - 2, { hang: 0 })) {
|
|
1496
|
+
for (const line of wrapBlock(message, Math.max(8, width - 2), { hang: 0 })) {
|
|
1445
1497
|
this.write(`${marker} ${dim(line)}`);
|
|
1446
1498
|
}
|
|
1447
1499
|
}, { tone });
|
|
@@ -24,7 +24,6 @@ export function normalizeClipboardText(raw) {
|
|
|
24
24
|
export function copyToClipboard(text) {
|
|
25
25
|
if (typeof text !== 'string' || text.length === 0)
|
|
26
26
|
return false;
|
|
27
|
-
emitOsc52Copy(text);
|
|
28
27
|
return writeClipboardSync(text);
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
@@ -167,10 +166,13 @@ export function extractLastAssistantTurn(loop) {
|
|
|
167
166
|
for (let i = loop.messages.length - 1; i >= 0; i--) {
|
|
168
167
|
const msg = loop.messages[i];
|
|
169
168
|
if (msg && msg.role === 'assistant') {
|
|
170
|
-
if (typeof msg.content === 'string')
|
|
171
|
-
|
|
169
|
+
if (typeof msg.content === 'string') {
|
|
170
|
+
if (msg.content.trim())
|
|
171
|
+
return msg.content;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
172
174
|
if (Array.isArray(msg.content)) {
|
|
173
|
-
|
|
175
|
+
const joined = msg.content
|
|
174
176
|
.map((part) => {
|
|
175
177
|
if (typeof part === 'string')
|
|
176
178
|
return part;
|
|
@@ -181,6 +183,8 @@ export function extractLastAssistantTurn(loop) {
|
|
|
181
183
|
})
|
|
182
184
|
.filter(Boolean)
|
|
183
185
|
.join('\n');
|
|
186
|
+
if (joined.trim())
|
|
187
|
+
return joined;
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
}
|
|
@@ -208,7 +212,10 @@ export function runCopyCommand(argv, ctx) {
|
|
|
208
212
|
return { ok: false, output: 'Chatbox input is currently empty.' };
|
|
209
213
|
}
|
|
210
214
|
const res = copyChatboxInput(ctx.prompt);
|
|
211
|
-
return {
|
|
215
|
+
return {
|
|
216
|
+
ok: res.success,
|
|
217
|
+
output: res.success ? 'Copied chatbox input to clipboard.' : 'Chatbox input is currently empty.'
|
|
218
|
+
};
|
|
212
219
|
}
|
|
213
220
|
if (argv.length > 0) {
|
|
214
221
|
const customText = argv.join(' ');
|
|
@@ -73,7 +73,6 @@ export function normalizeClipboardText(raw: unknown): string {
|
|
|
73
73
|
*/
|
|
74
74
|
export function copyToClipboard(text: string): boolean {
|
|
75
75
|
if (typeof text !== 'string' || text.length === 0) return false;
|
|
76
|
-
emitOsc52Copy(text);
|
|
77
76
|
return writeClipboardSync(text);
|
|
78
77
|
}
|
|
79
78
|
|
|
@@ -225,9 +224,12 @@ export function extractLastAssistantTurn(loop?: ChatboxLoop): string {
|
|
|
225
224
|
for (let i = loop.messages.length - 1; i >= 0; i--) {
|
|
226
225
|
const msg = loop.messages[i];
|
|
227
226
|
if (msg && msg.role === 'assistant') {
|
|
228
|
-
if (typeof msg.content === 'string')
|
|
227
|
+
if (typeof msg.content === 'string') {
|
|
228
|
+
if (msg.content.trim()) return msg.content;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
229
231
|
if (Array.isArray(msg.content)) {
|
|
230
|
-
|
|
232
|
+
const joined = msg.content
|
|
231
233
|
.map((part: unknown) => {
|
|
232
234
|
if (typeof part === 'string') return part;
|
|
233
235
|
if (part && typeof part === 'object' && 'text' in part && typeof (part as { text: unknown }).text === 'string') {
|
|
@@ -237,6 +239,7 @@ export function extractLastAssistantTurn(loop?: ChatboxLoop): string {
|
|
|
237
239
|
})
|
|
238
240
|
.filter(Boolean)
|
|
239
241
|
.join('\n');
|
|
242
|
+
if (joined.trim()) return joined;
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
245
|
}
|
|
@@ -270,7 +273,10 @@ export function runCopyCommand(
|
|
|
270
273
|
return { ok: false, output: 'Chatbox input is currently empty.' };
|
|
271
274
|
}
|
|
272
275
|
const res = copyChatboxInput(ctx.prompt);
|
|
273
|
-
return {
|
|
276
|
+
return {
|
|
277
|
+
ok: res.success,
|
|
278
|
+
output: res.success ? 'Copied chatbox input to clipboard.' : 'Chatbox input is currently empty.'
|
|
279
|
+
};
|
|
274
280
|
}
|
|
275
281
|
|
|
276
282
|
if (argv.length > 0) {
|