@causyne/agent 1.20.111 → 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/statusLine.js
CHANGED
|
@@ -24,13 +24,24 @@ import { contextMeter } from './block.js';
|
|
|
24
24
|
import { CHARS_PER_TOKEN } from '../contextManager.js';
|
|
25
25
|
import { formatAnimatedStatus } from './engineSpinner.js';
|
|
26
26
|
import { renderRunningLight } from './runningLight.js';
|
|
27
|
+
function nonNegativeFinite(value) {
|
|
28
|
+
const n = Number(value);
|
|
29
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
30
|
+
}
|
|
31
|
+
function oneLineDisplay(value) {
|
|
32
|
+
return safeDisplay(value).replace(/[\r\n]+/g, ' ');
|
|
33
|
+
}
|
|
27
34
|
/** 1234 -> "1.2k", 1234567 -> "1.2M". Token counts are read, not summed. */
|
|
28
35
|
export function compactCount(value) {
|
|
29
|
-
const n =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
const n = nonNegativeFinite(value);
|
|
37
|
+
const rounded = Math.round(n);
|
|
38
|
+
if (rounded < 1000)
|
|
39
|
+
return String(rounded);
|
|
40
|
+
if (n < 9950)
|
|
41
|
+
return `${(n / 1000).toFixed(1)}k`;
|
|
42
|
+
const thousands = Math.round(n / 1000);
|
|
43
|
+
if (thousands < 1000)
|
|
44
|
+
return `${thousands}k`;
|
|
34
45
|
return `${(n / 1000000).toFixed(1)}M`;
|
|
35
46
|
}
|
|
36
47
|
/**
|
|
@@ -40,7 +51,7 @@ export function compactCount(value) {
|
|
|
40
51
|
* to look at the cost at all.
|
|
41
52
|
*/
|
|
42
53
|
export function formatCost(value) {
|
|
43
|
-
const n =
|
|
54
|
+
const n = nonNegativeFinite(value);
|
|
44
55
|
if (n <= 0)
|
|
45
56
|
return '$0';
|
|
46
57
|
if (n < 0.01)
|
|
@@ -50,9 +61,10 @@ export function formatCost(value) {
|
|
|
50
61
|
return `$${n.toFixed(2)}`;
|
|
51
62
|
}
|
|
52
63
|
export function formatElapsed(ms) {
|
|
53
|
-
const
|
|
64
|
+
const safeMs = nonNegativeFinite(ms);
|
|
65
|
+
const total = Math.round(safeMs / 1000);
|
|
54
66
|
if (total < 60)
|
|
55
|
-
return `${(
|
|
67
|
+
return `${(safeMs / 1000).toFixed(1)}s`;
|
|
56
68
|
const minutes = Math.floor(total / 60);
|
|
57
69
|
const seconds = total % 60;
|
|
58
70
|
if (minutes < 60)
|
|
@@ -61,8 +73,12 @@ export function formatElapsed(ms) {
|
|
|
61
73
|
}
|
|
62
74
|
/** Strip a provider prefix so "anthropic/claude-opus-5" reads as the model. */
|
|
63
75
|
function shortModel(model) {
|
|
64
|
-
const name =
|
|
65
|
-
return name
|
|
76
|
+
const name = oneLineDisplay(model || '').split('/').pop() || '';
|
|
77
|
+
return visibleWidth(name) > 22 ? truncate(name, 22, GLYPHS.ellipsis) : name;
|
|
78
|
+
}
|
|
79
|
+
function finiteWidth(width) {
|
|
80
|
+
const numeric = Number(width ?? 80);
|
|
81
|
+
return Number.isFinite(numeric) ? Math.max(2, Math.floor(numeric)) : 80;
|
|
66
82
|
}
|
|
67
83
|
export class StatusLine {
|
|
68
84
|
model = '';
|
|
@@ -79,20 +95,27 @@ export class StatusLine {
|
|
|
79
95
|
constructor() {
|
|
80
96
|
this.reset();
|
|
81
97
|
}
|
|
98
|
+
applyContextWindow(chars, limit) {
|
|
99
|
+
const safeChars = nonNegativeFinite(chars);
|
|
100
|
+
if (safeChars > 0 || chars === 0)
|
|
101
|
+
this.contextChars = safeChars;
|
|
102
|
+
const safeLimit = nonNegativeFinite(limit);
|
|
103
|
+
if (safeLimit > 0 || limit === 0)
|
|
104
|
+
this.contextLimit = safeLimit;
|
|
105
|
+
}
|
|
82
106
|
/** Session-lifetime facts, set once from the same info as the header. */
|
|
83
107
|
setSession(info = {}) {
|
|
108
|
+
if (!info || typeof info !== 'object')
|
|
109
|
+
return this;
|
|
84
110
|
if (info.model !== undefined)
|
|
85
111
|
this.model = shortModel(info.model);
|
|
86
112
|
if (info.provider !== undefined)
|
|
87
|
-
this.provider = info.provider ?
|
|
113
|
+
this.provider = info.provider ? oneLineDisplay(info.provider) : '';
|
|
88
114
|
if (info.tier !== undefined)
|
|
89
|
-
this.tier = info.tier ?
|
|
115
|
+
this.tier = info.tier ? oneLineDisplay(info.tier) : '';
|
|
90
116
|
if (info.cwd !== undefined)
|
|
91
|
-
this.cwd = info.cwd ?
|
|
92
|
-
|
|
93
|
-
this.contextLimit = Number(info.contextLimit);
|
|
94
|
-
if (Number(info.contextChars) > 0)
|
|
95
|
-
this.contextChars = Number(info.contextChars);
|
|
117
|
+
this.cwd = info.cwd ? oneLineDisplay(info.cwd) : '';
|
|
118
|
+
this.applyContextWindow(info.contextChars, info.contextLimit);
|
|
96
119
|
return this;
|
|
97
120
|
}
|
|
98
121
|
/** Per-turn counters. */
|
|
@@ -107,14 +130,17 @@ export class StatusLine {
|
|
|
107
130
|
/**
|
|
108
131
|
* The idle footer: where you are, and how much context is left.
|
|
109
132
|
*/
|
|
110
|
-
renderIdle(
|
|
111
|
-
const
|
|
133
|
+
renderIdle(options = {}) {
|
|
134
|
+
const { width = 80, hint = '' } = options || {};
|
|
135
|
+
const safeWidth = finiteWidth(width);
|
|
136
|
+
const budget = Math.max(1, safeWidth - 1);
|
|
112
137
|
const meter = contextMeter(Math.round(this.contextChars / CHARS_PER_TOKEN), Math.round(this.contextLimit / CHARS_PER_TOKEN));
|
|
113
138
|
const segments = [];
|
|
114
139
|
if (meter)
|
|
115
140
|
segments.push(meter);
|
|
116
|
-
|
|
117
|
-
|
|
141
|
+
const cleanHint = hint ? oneLineDisplay(hint) : '';
|
|
142
|
+
if (cleanHint)
|
|
143
|
+
segments.push(cleanHint);
|
|
118
144
|
const separator = ` ${GLYPHS.dot} `;
|
|
119
145
|
const kept = segments.slice();
|
|
120
146
|
let tail = kept.join(separator);
|
|
@@ -125,43 +151,48 @@ export class StatusLine {
|
|
|
125
151
|
if (visibleWidth(tail) > budget)
|
|
126
152
|
tail = '';
|
|
127
153
|
const room = tail ? Math.max(0, budget - visibleWidth(tail) - visibleWidth(separator)) : budget;
|
|
128
|
-
const where = this.cwd ? truncate(shortenHome(this.cwd), room, GLYPHS.ellipsis) : '';
|
|
154
|
+
const where = this.cwd && room > 0 ? truncate(shortenHome(oneLineDisplay(this.cwd)), room, GLYPHS.ellipsis) : '';
|
|
129
155
|
const left = dim(where);
|
|
130
156
|
if (!tail)
|
|
131
157
|
return left;
|
|
132
|
-
|
|
158
|
+
if (!where)
|
|
159
|
+
return dim(tail);
|
|
160
|
+
const gap = Math.max(visibleWidth(separator), safeWidth - 1 - visibleWidth(left) - visibleWidth(tail));
|
|
133
161
|
return `${left}${' '.repeat(gap)}${dim(tail)}`;
|
|
134
162
|
}
|
|
135
163
|
/**
|
|
136
164
|
* Consume a `usage_update` frame.
|
|
137
165
|
*/
|
|
138
166
|
onUsage(msg = {}) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const responseCost = Number(msg.costUsd) || 0;
|
|
145
|
-
const taskCost = Number(msg.taskCostUsd) || 0;
|
|
167
|
+
const usage = msg && typeof msg === 'object' ? msg : {};
|
|
168
|
+
this.turnTokens = nonNegativeFinite(usage.taskTokens) || nonNegativeFinite(usage.usedTokens) || this.turnTokens;
|
|
169
|
+
this.applyContextWindow(usage.contextChars, usage.contextLimitChars);
|
|
170
|
+
const responseCost = nonNegativeFinite(usage.costUsd);
|
|
171
|
+
const taskCost = nonNegativeFinite(usage.taskCostUsd);
|
|
146
172
|
this.turnCost = taskCost > 0 ? taskCost : this.turnCost + responseCost;
|
|
147
|
-
this.cachedTokens =
|
|
173
|
+
this.cachedTokens = nonNegativeFinite(usage.cachedTokens);
|
|
148
174
|
return this;
|
|
149
175
|
}
|
|
150
176
|
/**
|
|
151
177
|
* Build the line.
|
|
152
178
|
*/
|
|
153
|
-
render(
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
179
|
+
render(options = {}) {
|
|
180
|
+
const { message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '', tick } = options || {};
|
|
181
|
+
const safeWidth = finiteWidth(width);
|
|
182
|
+
const safeElapsedMs = nonNegativeFinite(elapsedMs);
|
|
183
|
+
const safeSteps = Math.floor(nonNegativeFinite(steps));
|
|
184
|
+
const safeTick = tick !== undefined && Number.isFinite(tick) ? Math.floor(tick) : undefined;
|
|
185
|
+
const maxTotal = Math.max(1, safeWidth - 1);
|
|
186
|
+
// Even a precolored frame may be supplied by a tool; render only
|
|
187
|
+
// sanitized glyphs so it cannot move the cursor or clear the screen.
|
|
188
|
+
const rawHead = spinnerFrame ? `${paint('accent', oneLineDisplay(spinnerFrame))} ` : '';
|
|
189
|
+
const head = visibleWidth(rawHead) < maxTotal ? rawHead : '';
|
|
190
|
+
const budget = Math.max(1, maxTotal - visibleWidth(head));
|
|
160
191
|
const segments = [];
|
|
161
|
-
if (
|
|
162
|
-
segments.push(formatElapsed(
|
|
163
|
-
if (
|
|
164
|
-
segments.push(`step ${
|
|
192
|
+
if (safeElapsedMs > 0)
|
|
193
|
+
segments.push(formatElapsed(safeElapsedMs));
|
|
194
|
+
if (safeSteps > 0)
|
|
195
|
+
segments.push(`step ${safeSteps}`);
|
|
165
196
|
if (this.turnTokens > 0)
|
|
166
197
|
segments.push(`${compactCount(this.turnTokens)} tok`);
|
|
167
198
|
if (this.turnCost > 0)
|
|
@@ -171,28 +202,29 @@ export class StatusLine {
|
|
|
171
202
|
if (this.model)
|
|
172
203
|
segments.push(this.model);
|
|
173
204
|
const separator = ` ${GLYPHS.dot} `;
|
|
174
|
-
const
|
|
175
|
-
|
|
205
|
+
const sepWidth = visibleWidth(separator);
|
|
206
|
+
const rawMessage = safeTick !== undefined
|
|
207
|
+
? formatAnimatedStatus(message || 'working', safeTick)
|
|
176
208
|
: (message || (spinnerFrame ? 'working' : ''));
|
|
177
|
-
const text =
|
|
209
|
+
const text = oneLineDisplay(rawMessage);
|
|
178
210
|
const kept = segments.slice();
|
|
179
211
|
const wanted = Math.min(visibleWidth(text), Math.max(18, Math.floor(budget / 2)));
|
|
180
212
|
while (kept.length > 0) {
|
|
181
213
|
const tail = kept.join(separator);
|
|
182
|
-
if (visibleWidth(tail) +
|
|
214
|
+
if (visibleWidth(tail) + sepWidth + wanted <= budget)
|
|
183
215
|
break;
|
|
184
216
|
kept.pop();
|
|
185
217
|
}
|
|
186
218
|
const tail = kept.length > 0 ? kept.join(separator) : '';
|
|
187
219
|
const messageBudget = tail
|
|
188
|
-
? Math.max(1, budget - visibleWidth(tail) -
|
|
220
|
+
? Math.max(1, budget - visibleWidth(tail) - sepWidth)
|
|
189
221
|
: budget;
|
|
190
222
|
const body = truncate(text, messageBudget, GLYPHS.ellipsis);
|
|
191
|
-
const isAnimating =
|
|
192
|
-
const shimmerNowMs =
|
|
223
|
+
const isAnimating = safeTick !== undefined || safeElapsedMs > 0 || Boolean(spinnerFrame);
|
|
224
|
+
const shimmerNowMs = safeElapsedMs > 0 ? safeElapsedMs : (safeTick !== undefined ? Math.max(0, safeTick) * 80 : 320);
|
|
193
225
|
if (isAnimating && this.onTick) {
|
|
194
226
|
try {
|
|
195
|
-
this.onTick(shimmerNowMs,
|
|
227
|
+
this.onTick(shimmerNowMs, safeTick);
|
|
196
228
|
}
|
|
197
229
|
catch {
|
|
198
230
|
// Never allow a tick observer to disrupt status rendering
|
|
@@ -204,16 +236,16 @@ export class StatusLine {
|
|
|
204
236
|
const left = `${head}${styledBody}`;
|
|
205
237
|
if (!tail)
|
|
206
238
|
return left;
|
|
207
|
-
const gap = Math.max(visibleWidth(separator),
|
|
239
|
+
const gap = Math.max(visibleWidth(separator), safeWidth - 1 - visibleWidth(left) - visibleWidth(tail));
|
|
208
240
|
return `${left}${' '.repeat(gap)}${dim(tail)}`;
|
|
209
241
|
}
|
|
210
242
|
/**
|
|
211
243
|
* The non-TTY form: no spinner, no elapsed clock, printed once.
|
|
212
244
|
*/
|
|
213
245
|
renderStatic(message, width = 80) {
|
|
214
|
-
const parts = [
|
|
246
|
+
const parts = [oneLineDisplay(message)];
|
|
215
247
|
if (this.model)
|
|
216
248
|
parts.push(this.model);
|
|
217
|
-
return truncate(`${GLYPHS.dot} ${parts.join(` ${GLYPHS.dot} `)}`, width, GLYPHS.ellipsis);
|
|
249
|
+
return truncate(`${GLYPHS.dot} ${parts.join(` ${GLYPHS.dot} `)}`, finiteWidth(width), GLYPHS.ellipsis);
|
|
218
250
|
}
|
|
219
251
|
}
|
package/src/tui/statusLine.ts
CHANGED
|
@@ -26,11 +26,23 @@ import { CHARS_PER_TOKEN } from '../contextManager.js';
|
|
|
26
26
|
import { formatAnimatedStatus } from './engineSpinner.js';
|
|
27
27
|
import { renderRunningLight } from './runningLight.js';
|
|
28
28
|
|
|
29
|
+
function nonNegativeFinite(value: unknown): number {
|
|
30
|
+
const n = Number(value);
|
|
31
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function oneLineDisplay(value: unknown): string {
|
|
35
|
+
return safeDisplay(value).replace(/[\r\n]+/g, ' ');
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
/** 1234 -> "1.2k", 1234567 -> "1.2M". Token counts are read, not summed. */
|
|
30
39
|
export function compactCount(value: unknown): string {
|
|
31
|
-
const n =
|
|
32
|
-
|
|
33
|
-
if (
|
|
40
|
+
const n = nonNegativeFinite(value);
|
|
41
|
+
const rounded = Math.round(n);
|
|
42
|
+
if (rounded < 1000) return String(rounded);
|
|
43
|
+
if (n < 9950) return `${(n / 1000).toFixed(1)}k`;
|
|
44
|
+
const thousands = Math.round(n / 1000);
|
|
45
|
+
if (thousands < 1000) return `${thousands}k`;
|
|
34
46
|
return `${(n / 1000000).toFixed(1)}M`;
|
|
35
47
|
}
|
|
36
48
|
|
|
@@ -41,7 +53,7 @@ export function compactCount(value: unknown): string {
|
|
|
41
53
|
* to look at the cost at all.
|
|
42
54
|
*/
|
|
43
55
|
export function formatCost(value: unknown): string {
|
|
44
|
-
const n =
|
|
56
|
+
const n = nonNegativeFinite(value);
|
|
45
57
|
if (n <= 0) return '$0';
|
|
46
58
|
if (n < 0.01) return `$${n.toFixed(4)}`;
|
|
47
59
|
if (n < 1) return `$${n.toFixed(3)}`;
|
|
@@ -49,8 +61,9 @@ export function formatCost(value: unknown): string {
|
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
export function formatElapsed(ms: number): string {
|
|
52
|
-
const
|
|
53
|
-
|
|
64
|
+
const safeMs = nonNegativeFinite(ms);
|
|
65
|
+
const total = Math.round(safeMs / 1000);
|
|
66
|
+
if (total < 60) return `${(safeMs / 1000).toFixed(1)}s`;
|
|
54
67
|
const minutes = Math.floor(total / 60);
|
|
55
68
|
const seconds = total % 60;
|
|
56
69
|
if (minutes < 60) return `${minutes}m${String(seconds).padStart(2, '0')}s`;
|
|
@@ -59,8 +72,8 @@ export function formatElapsed(ms: number): string {
|
|
|
59
72
|
|
|
60
73
|
/** Strip a provider prefix so "anthropic/claude-opus-5" reads as the model. */
|
|
61
74
|
function shortModel(model: unknown): string {
|
|
62
|
-
const name =
|
|
63
|
-
return name
|
|
75
|
+
const name = oneLineDisplay(model || '').split('/').pop() || '';
|
|
76
|
+
return visibleWidth(name) > 22 ? truncate(name, 22, GLYPHS.ellipsis) : name;
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
export interface StatusLineSessionInfo {
|
|
@@ -86,6 +99,11 @@ export interface StatusLineIdleOptions {
|
|
|
86
99
|
hint?: string | undefined;
|
|
87
100
|
}
|
|
88
101
|
|
|
102
|
+
function finiteWidth(width: number | undefined): number {
|
|
103
|
+
const numeric = Number(width ?? 80);
|
|
104
|
+
return Number.isFinite(numeric) ? Math.max(2, Math.floor(numeric)) : 80;
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
export class StatusLine {
|
|
90
108
|
model = '';
|
|
91
109
|
provider = '';
|
|
@@ -104,14 +122,21 @@ export class StatusLine {
|
|
|
104
122
|
this.reset();
|
|
105
123
|
}
|
|
106
124
|
|
|
125
|
+
private applyContextWindow(chars: unknown, limit: unknown): void {
|
|
126
|
+
const safeChars = nonNegativeFinite(chars);
|
|
127
|
+
if (safeChars > 0 || chars === 0) this.contextChars = safeChars;
|
|
128
|
+
const safeLimit = nonNegativeFinite(limit);
|
|
129
|
+
if (safeLimit > 0 || limit === 0) this.contextLimit = safeLimit;
|
|
130
|
+
}
|
|
131
|
+
|
|
107
132
|
/** Session-lifetime facts, set once from the same info as the header. */
|
|
108
|
-
setSession(info: StatusLineSessionInfo = {}): this {
|
|
133
|
+
setSession(info: StatusLineSessionInfo | null = {}): this {
|
|
134
|
+
if (!info || typeof info !== 'object') return this;
|
|
109
135
|
if (info.model !== undefined) this.model = shortModel(info.model);
|
|
110
|
-
if (info.provider !== undefined) this.provider = info.provider ?
|
|
111
|
-
if (info.tier !== undefined) this.tier = info.tier ?
|
|
112
|
-
if (info.cwd !== undefined) this.cwd = info.cwd ?
|
|
113
|
-
|
|
114
|
-
if (Number(info.contextChars) > 0) this.contextChars = Number(info.contextChars);
|
|
136
|
+
if (info.provider !== undefined) this.provider = info.provider ? oneLineDisplay(info.provider) : '';
|
|
137
|
+
if (info.tier !== undefined) this.tier = info.tier ? oneLineDisplay(info.tier) : '';
|
|
138
|
+
if (info.cwd !== undefined) this.cwd = info.cwd ? oneLineDisplay(info.cwd) : '';
|
|
139
|
+
this.applyContextWindow(info.contextChars, info.contextLimit);
|
|
115
140
|
return this;
|
|
116
141
|
}
|
|
117
142
|
|
|
@@ -128,15 +153,18 @@ export class StatusLine {
|
|
|
128
153
|
/**
|
|
129
154
|
* The idle footer: where you are, and how much context is left.
|
|
130
155
|
*/
|
|
131
|
-
renderIdle(
|
|
132
|
-
const
|
|
156
|
+
renderIdle(options: StatusLineIdleOptions | null = {}): string {
|
|
157
|
+
const { width = 80, hint = '' } = options || {};
|
|
158
|
+
const safeWidth = finiteWidth(width);
|
|
159
|
+
const budget = Math.max(1, safeWidth - 1);
|
|
133
160
|
const meter = contextMeter(
|
|
134
161
|
Math.round(this.contextChars / CHARS_PER_TOKEN),
|
|
135
162
|
Math.round(this.contextLimit / CHARS_PER_TOKEN)
|
|
136
163
|
);
|
|
137
164
|
const segments: string[] = [];
|
|
138
165
|
if (meter) segments.push(meter);
|
|
139
|
-
|
|
166
|
+
const cleanHint = hint ? oneLineDisplay(hint) : '';
|
|
167
|
+
if (cleanHint) segments.push(cleanHint);
|
|
140
168
|
|
|
141
169
|
const separator = ` ${GLYPHS.dot} `;
|
|
142
170
|
const kept = segments.slice();
|
|
@@ -148,13 +176,14 @@ export class StatusLine {
|
|
|
148
176
|
if (visibleWidth(tail) > budget) tail = '';
|
|
149
177
|
|
|
150
178
|
const room = tail ? Math.max(0, budget - visibleWidth(tail) - visibleWidth(separator)) : budget;
|
|
151
|
-
const where = this.cwd ? truncate(shortenHome(this.cwd), room, GLYPHS.ellipsis) : '';
|
|
179
|
+
const where = this.cwd && room > 0 ? truncate(shortenHome(oneLineDisplay(this.cwd)), room, GLYPHS.ellipsis) : '';
|
|
152
180
|
const left = dim(where);
|
|
153
181
|
if (!tail) return left;
|
|
182
|
+
if (!where) return dim(tail);
|
|
154
183
|
|
|
155
184
|
const gap = Math.max(
|
|
156
185
|
visibleWidth(separator),
|
|
157
|
-
|
|
186
|
+
safeWidth - 1 - visibleWidth(left) - visibleWidth(tail)
|
|
158
187
|
);
|
|
159
188
|
return `${left}${' '.repeat(gap)}${dim(tail)}`;
|
|
160
189
|
}
|
|
@@ -162,61 +191,68 @@ export class StatusLine {
|
|
|
162
191
|
/**
|
|
163
192
|
* Consume a `usage_update` frame.
|
|
164
193
|
*/
|
|
165
|
-
onUsage(msg: Record<string, unknown> = {}): this {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const responseCost =
|
|
170
|
-
const taskCost =
|
|
194
|
+
onUsage(msg: Record<string, unknown> | null = {}): this {
|
|
195
|
+
const usage = msg && typeof msg === 'object' ? msg : {};
|
|
196
|
+
this.turnTokens = nonNegativeFinite(usage.taskTokens) || nonNegativeFinite(usage.usedTokens) || this.turnTokens;
|
|
197
|
+
this.applyContextWindow(usage.contextChars, usage.contextLimitChars);
|
|
198
|
+
const responseCost = nonNegativeFinite(usage.costUsd);
|
|
199
|
+
const taskCost = nonNegativeFinite(usage.taskCostUsd);
|
|
171
200
|
this.turnCost = taskCost > 0 ? taskCost : this.turnCost + responseCost;
|
|
172
|
-
this.cachedTokens =
|
|
201
|
+
this.cachedTokens = nonNegativeFinite(usage.cachedTokens);
|
|
173
202
|
return this;
|
|
174
203
|
}
|
|
175
204
|
|
|
176
205
|
/**
|
|
177
206
|
* Build the line.
|
|
178
207
|
*/
|
|
179
|
-
render(
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
208
|
+
render(options: StatusLineRenderOptions | null = {}): string {
|
|
209
|
+
const { message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '', tick } = options || {};
|
|
210
|
+
const safeWidth = finiteWidth(width);
|
|
211
|
+
const safeElapsedMs = nonNegativeFinite(elapsedMs);
|
|
212
|
+
const safeSteps = Math.floor(nonNegativeFinite(steps));
|
|
213
|
+
const safeTick = tick !== undefined && Number.isFinite(tick) ? Math.floor(tick) : undefined;
|
|
214
|
+
|
|
215
|
+
const maxTotal = Math.max(1, safeWidth - 1);
|
|
216
|
+
// Even a precolored frame may be supplied by a tool; render only
|
|
217
|
+
// sanitized glyphs so it cannot move the cursor or clear the screen.
|
|
218
|
+
const rawHead = spinnerFrame ? `${paint('accent', oneLineDisplay(spinnerFrame))} ` : '';
|
|
219
|
+
const head = visibleWidth(rawHead) < maxTotal ? rawHead : '';
|
|
220
|
+
const budget = Math.max(1, maxTotal - visibleWidth(head));
|
|
186
221
|
|
|
187
222
|
const segments: string[] = [];
|
|
188
|
-
if (
|
|
189
|
-
if (
|
|
223
|
+
if (safeElapsedMs > 0) segments.push(formatElapsed(safeElapsedMs));
|
|
224
|
+
if (safeSteps > 0) segments.push(`step ${safeSteps}`);
|
|
190
225
|
if (this.turnTokens > 0) segments.push(`${compactCount(this.turnTokens)} tok`);
|
|
191
226
|
if (this.turnCost > 0) segments.push(formatCost(this.turnCost));
|
|
192
227
|
if (this.cachedTokens > 0) segments.push(`${compactCount(this.cachedTokens)} cached`);
|
|
193
228
|
if (this.model) segments.push(this.model);
|
|
194
229
|
|
|
195
230
|
const separator = ` ${GLYPHS.dot} `;
|
|
196
|
-
const
|
|
197
|
-
|
|
231
|
+
const sepWidth = visibleWidth(separator);
|
|
232
|
+
const rawMessage = safeTick !== undefined
|
|
233
|
+
? formatAnimatedStatus(message || 'working', safeTick)
|
|
198
234
|
: (message || (spinnerFrame ? 'working' : ''));
|
|
199
|
-
const text =
|
|
235
|
+
const text = oneLineDisplay(rawMessage);
|
|
200
236
|
|
|
201
237
|
const kept = segments.slice();
|
|
202
238
|
const wanted = Math.min(visibleWidth(text), Math.max(18, Math.floor(budget / 2)));
|
|
203
239
|
while (kept.length > 0) {
|
|
204
240
|
const tail = kept.join(separator);
|
|
205
|
-
if (visibleWidth(tail) +
|
|
241
|
+
if (visibleWidth(tail) + sepWidth + wanted <= budget) break;
|
|
206
242
|
kept.pop();
|
|
207
243
|
}
|
|
208
244
|
|
|
209
245
|
const tail = kept.length > 0 ? kept.join(separator) : '';
|
|
210
246
|
const messageBudget = tail
|
|
211
|
-
? Math.max(1, budget - visibleWidth(tail) -
|
|
247
|
+
? Math.max(1, budget - visibleWidth(tail) - sepWidth)
|
|
212
248
|
: budget;
|
|
213
249
|
const body = truncate(text, messageBudget, GLYPHS.ellipsis);
|
|
214
250
|
|
|
215
|
-
const isAnimating =
|
|
216
|
-
const shimmerNowMs =
|
|
251
|
+
const isAnimating = safeTick !== undefined || safeElapsedMs > 0 || Boolean(spinnerFrame);
|
|
252
|
+
const shimmerNowMs = safeElapsedMs > 0 ? safeElapsedMs : (safeTick !== undefined ? Math.max(0, safeTick) * 80 : 320);
|
|
217
253
|
if (isAnimating && this.onTick) {
|
|
218
254
|
try {
|
|
219
|
-
this.onTick(shimmerNowMs,
|
|
255
|
+
this.onTick(shimmerNowMs, safeTick);
|
|
220
256
|
} catch {
|
|
221
257
|
// Never allow a tick observer to disrupt status rendering
|
|
222
258
|
}
|
|
@@ -229,7 +265,7 @@ export class StatusLine {
|
|
|
229
265
|
|
|
230
266
|
const gap = Math.max(
|
|
231
267
|
visibleWidth(separator),
|
|
232
|
-
|
|
268
|
+
safeWidth - 1 - visibleWidth(left) - visibleWidth(tail)
|
|
233
269
|
);
|
|
234
270
|
return `${left}${' '.repeat(gap)}${dim(tail)}`;
|
|
235
271
|
}
|
|
@@ -238,8 +274,8 @@ export class StatusLine {
|
|
|
238
274
|
* The non-TTY form: no spinner, no elapsed clock, printed once.
|
|
239
275
|
*/
|
|
240
276
|
renderStatic(message: string, width = 80): string {
|
|
241
|
-
const parts = [
|
|
277
|
+
const parts = [oneLineDisplay(message)];
|
|
242
278
|
if (this.model) parts.push(this.model);
|
|
243
|
-
return truncate(`${GLYPHS.dot} ${parts.join(` ${GLYPHS.dot} `)}`, width, GLYPHS.ellipsis);
|
|
279
|
+
return truncate(`${GLYPHS.dot} ${parts.join(` ${GLYPHS.dot} `)}`, finiteWidth(width), GLYPHS.ellipsis);
|
|
244
280
|
}
|
|
245
281
|
}
|
|
@@ -22,6 +22,7 @@ export class TerminalInputFramer {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
push(input) {
|
|
25
|
+
if (input == null) return [];
|
|
25
26
|
const incoming = Buffer.isBuffer(input) ? input : Buffer.from(String(input), 'utf8');
|
|
26
27
|
if (incoming.length === 0) return [];
|
|
27
28
|
const bytes = this.pending.length ? Buffer.concat([this.pending, incoming]) : incoming;
|
|
@@ -66,6 +67,7 @@ const SGR = /\x1b\[[0-9;]*m/g;
|
|
|
66
67
|
* regression test expects to arrive as a single multiline editor insertion.
|
|
67
68
|
*/
|
|
68
69
|
export function shouldTreatAsAtomicPaste(raw, decoder) {
|
|
70
|
+
if (raw == null) return false;
|
|
69
71
|
let text;
|
|
70
72
|
if (typeof raw === 'string') text = raw;
|
|
71
73
|
else {
|
|
@@ -91,8 +93,9 @@ export function shouldTreatAsAtomicPaste(raw, decoder) {
|
|
|
91
93
|
|
|
92
94
|
/** Display a short, non-sensitive paste notification (not the pasted content). */
|
|
93
95
|
export function pasteSummary(text) {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
+
const normalized = String(text == null ? '' : text).replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
97
|
+
const lines = 1 + (normalized.match(/\n/g)?.length ?? 0);
|
|
98
|
+
const size = Buffer.byteLength(normalized, 'utf8');
|
|
96
99
|
const sizeLabel = size >= 1024 ? `${Math.round(size / 1024)} KiB` : `${size} B`;
|
|
97
100
|
return `pasted ${lines} ${lines === 1 ? 'line' : 'lines'} · ${sizeLabel}`;
|
|
98
101
|
}
|