@causyne/agent 1.20.117 → 1.20.118
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/package.json +7 -2
- package/src/cliMode.js +19 -3
- package/src/commands.js +7 -1
- package/src/plugins/pluginManager.js +74 -0
- package/src/reporting.js +12 -4
- package/src/skillsManager.js +3 -2
- package/src/skillsManager.ts +3 -2
- package/src/tools/pluginManager.js +17 -2
- package/src/tui/composerControls.js +16 -3
- package/src/tui/composerControls.ts +14 -3
- package/src/tui/prompt.js +122 -16
- package/src/tui/usageCard.js +119 -47
- package/src/tui/usageCard.ts +133 -49
- package/src/tui/workspaceSwitch.js +2 -0
- package/src/tui/workspaceSwitch.ts +1 -0
- package/src/verification/boundedExplorer.js +119 -0
- package/src/verification/cliProbe.js +116 -0
- package/src/verification/featureMap.js +78 -0
- package/src/verification/interactivePty.js +188 -0
- package/src/verification/propertyProbe.js +121 -0
- package/src/verification/ptyProbe.js +125 -0
- package/src/verification/skillCatalog.d.ts +1 -0
- package/src/verification/skillCatalog.js +60 -0
- package/src/verification/statechart.js +143 -0
- package/src/verification/uiRuntime.js +57 -0
- package/src/verificationPlan.js +1 -1
- package/src/verificationPlan.ts +1 -1
package/src/tui/usageCard.js
CHANGED
|
@@ -168,67 +168,139 @@ export async function collectUsageCardData(loop) {
|
|
|
168
168
|
usageProvenance: 'Local tracker: provider reports, ACP text estimates and media equivalents can be mixed'
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
* Render the usage card as an array of styled terminal rows, exactly matching `width`.
|
|
173
|
-
*/
|
|
174
|
-
export function renderUsageCardRows(data, width) {
|
|
171
|
+
function buildFramedCardRows(width, options, populate) {
|
|
175
172
|
const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 80;
|
|
176
173
|
const frameWidth = safeWidth; // Never paint outside the terminal's actual columns.
|
|
177
174
|
const innerWidth = Math.max(0, frameWidth - 4);
|
|
178
175
|
const edge = paint('accent', FRAME.v);
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
const cleanTitle = oneLineText(options.title);
|
|
177
|
+
const title = frameWidth >= 32 ? ` ${bold(paint('accent', cleanTitle))} `
|
|
178
|
+
: frameWidth >= 13 ? ` ${cleanTitle.split(/\s+/)[0] || cleanTitle} ` : '';
|
|
179
|
+
const footerText = oneLineText(options.footer || 'esc close');
|
|
180
|
+
const hint = frameWidth >= 43 && footerText ? ` ${dim(footerText)} ` : '';
|
|
182
181
|
const lineRoom = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(hint));
|
|
183
182
|
const top = paint('accent', FRAME.tl + FRAME.h)
|
|
184
183
|
+ title + paint('accent', FRAME.h.repeat(lineRoom)) + hint + paint('accent', FRAME.tr);
|
|
185
184
|
const rows = [fill('surface', top)];
|
|
186
|
-
const labelWidth = innerWidth >= 60 ? 16 : 13;
|
|
187
|
-
const
|
|
188
|
-
const name = dim(String(label).padEnd(labelWidth));
|
|
189
|
-
const text = name + value;
|
|
185
|
+
const labelWidth = options.labelWidth ?? (innerWidth >= 60 ? 16 : 13);
|
|
186
|
+
const pushInnerRow = (text) => {
|
|
190
187
|
const clipped = visibleWidth(text) > innerWidth
|
|
191
188
|
? truncate(text, innerWidth, GLYPHS.ellipsis) : text;
|
|
192
189
|
const padding = ' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)));
|
|
193
190
|
rows.push(fill('surface', `${edge} ${clipped}${padding} ${edge}`));
|
|
194
191
|
};
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
|
|
201
|
-
addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
|
|
202
|
-
const pool = Number.isFinite(data.contextPoolTokens) && data.contextPoolTokens > 0
|
|
203
|
-
? data.contextPoolTokens : 0;
|
|
204
|
-
const estimatedUsed = formatNumber(data.contextUsedTokens);
|
|
205
|
-
if (pool > 0) {
|
|
206
|
-
const percent = Number.isFinite(data.contextPercentLeft)
|
|
207
|
-
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
|
|
208
|
-
const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
|
|
209
|
-
addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
|
|
213
|
-
}
|
|
214
|
-
addRow('This Session', data.sessionMetricsAvailable === false
|
|
215
|
-
? dim('unavailable (no live tracker)')
|
|
216
|
-
: `${bold(formatNumber(data.sessionTokens))} tracked tokens ${dim('(current process only)')}`);
|
|
217
|
-
addRow('Today (local)', `${bold(formatNumber(data.dailyTokens))} tracked tokens ${dim('(calendar day)')}`);
|
|
218
|
-
addRow('All-Time', `${bold(formatNumber(data.lifetimeTokens))} tracked tokens ${dim(`(${formatNumber(data.lifetimeCalls)} recorded events)`)}`);
|
|
219
|
-
const totalEstimate = formatCostEstimate(data.lifetimeCostUsd).trim();
|
|
220
|
-
const dailyEstimate = formatCostEstimate(data.dailyCostUsd).trim();
|
|
221
|
-
addRow('Cost (estimate)', totalEstimate
|
|
222
|
-
? `${totalEstimate} all-time${dailyEstimate ? ` · ${dailyEstimate} today` : ''}`
|
|
223
|
-
: dim('no positive local estimate recorded'));
|
|
224
|
-
addRow('Data source', dim('Local tracker; not provider billing or exact token telemetry'));
|
|
225
|
-
if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
|
|
226
|
-
const pct = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
|
|
227
|
-
? Math.max(0, Math.round(data.budgetPercentUsed)) : 0;
|
|
228
|
-
addRow('Daily budget', `${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tracked (${pct}% used)`);
|
|
229
|
-
}
|
|
192
|
+
const addRow = (label, value) => {
|
|
193
|
+
const name = dim(String(label).padEnd(labelWidth));
|
|
194
|
+
pushInnerRow(name + value);
|
|
195
|
+
};
|
|
196
|
+
populate(addRow, pushInnerRow, { innerWidth, labelWidth });
|
|
230
197
|
const bottom = paint('accent', FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
|
|
231
198
|
rows.push(fill('surface', bottom));
|
|
232
|
-
rows.push(''); // Keep the composer visually separate from the
|
|
199
|
+
rows.push(''); // Keep the composer visually separate from the pinned panel.
|
|
233
200
|
return rows;
|
|
234
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Render the usage card as an array of styled terminal rows, exactly matching `width`.
|
|
204
|
+
*/
|
|
205
|
+
export function renderUsageCardRows(data, width) {
|
|
206
|
+
return buildFramedCardRows(width, { title: 'Usage & Context', footer: 'esc close' }, (addRow, _addLine, { innerWidth, labelWidth }) => {
|
|
207
|
+
const session = oneLineText(data.sessionId || 'unknown') || 'unknown';
|
|
208
|
+
const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
|
|
209
|
+
addRow('Session/Chat', `${paint('ink', sessionName)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
|
|
210
|
+
// Model and provider occupy separate rows, rather than squeezing two long
|
|
211
|
+
// identifiers into a single line where neither is readable.
|
|
212
|
+
addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
|
|
213
|
+
addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
|
|
214
|
+
const pool = Number.isFinite(data.contextPoolTokens) && data.contextPoolTokens > 0
|
|
215
|
+
? data.contextPoolTokens : 0;
|
|
216
|
+
const estimatedUsed = formatNumber(data.contextUsedTokens);
|
|
217
|
+
if (pool > 0) {
|
|
218
|
+
const percent = Number.isFinite(data.contextPercentLeft)
|
|
219
|
+
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
|
|
220
|
+
const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
|
|
221
|
+
addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
|
|
222
|
+
const barRoom = Math.max(0, innerWidth - labelWidth - 13);
|
|
223
|
+
if (barRoom >= 8) {
|
|
224
|
+
const barWidth = Math.min(28, barRoom);
|
|
225
|
+
const bar = renderProgressBar(percent, barWidth, false);
|
|
226
|
+
addRow('Window left', `[${bar}] ${String(percent).padStart(3)}% left`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
|
|
231
|
+
}
|
|
232
|
+
addRow('This Session', data.sessionMetricsAvailable === false
|
|
233
|
+
? dim('unavailable (no live tracker)')
|
|
234
|
+
: `${bold(formatNumber(data.sessionTokens))} tracked tokens ${dim('(current process only)')}`);
|
|
235
|
+
addRow('Today (local)', `${bold(formatNumber(data.dailyTokens))} tracked tokens ${dim('(calendar day)')}`);
|
|
236
|
+
addRow('All-Time', `${bold(formatNumber(data.lifetimeTokens))} tracked tokens ${dim(`(${formatNumber(data.lifetimeCalls)} recorded events)`)}`);
|
|
237
|
+
const totalEstimate = formatCostEstimate(data.lifetimeCostUsd).trim();
|
|
238
|
+
const dailyEstimate = formatCostEstimate(data.dailyCostUsd).trim();
|
|
239
|
+
addRow('Cost (estimate)', totalEstimate
|
|
240
|
+
? `${totalEstimate} all-time${dailyEstimate ? ` · ${dailyEstimate} today` : ''}`
|
|
241
|
+
: dim('no positive local estimate recorded'));
|
|
242
|
+
addRow('Data source', dim('Local tracker; not provider billing or exact token telemetry'));
|
|
243
|
+
if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
|
|
244
|
+
const pct = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
|
|
245
|
+
? Math.max(0, Math.round(data.budgetPercentUsed)) : 0;
|
|
246
|
+
addRow('Daily budget', `${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tracked (${pct}% used)`);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Render the pinned `/status` card matching the Usage card styling, plus live session/context meters when available.
|
|
252
|
+
*/
|
|
253
|
+
export function renderStatusCardRows(statusText, usageData, width) {
|
|
254
|
+
return buildFramedCardRows(width, { title: 'Status', footer: 'esc close' }, (addRow, addLine, { innerWidth, labelWidth }) => {
|
|
255
|
+
const rawLines = String(statusText || '').split(/\r?\n/);
|
|
256
|
+
if (rawLines[0]?.trim() === 'Status')
|
|
257
|
+
rawLines.shift();
|
|
258
|
+
let hasSessionLine = false;
|
|
259
|
+
for (const rawLine of rawLines) {
|
|
260
|
+
const trimmed = oneLineText(rawLine);
|
|
261
|
+
if (!trimmed)
|
|
262
|
+
continue;
|
|
263
|
+
const sepIdx = trimmed.indexOf(':');
|
|
264
|
+
if (sepIdx > 0 && sepIdx <= 20) {
|
|
265
|
+
const key = trimmed.slice(0, sepIdx).trim();
|
|
266
|
+
const val = trimmed.slice(sepIdx + 1).trim();
|
|
267
|
+
if (key.toLowerCase() === 'session')
|
|
268
|
+
hasSessionLine = true;
|
|
269
|
+
const coloredVal = key.toLowerCase().includes('provider')
|
|
270
|
+
? paint('accent', val)
|
|
271
|
+
: paint('ink', val);
|
|
272
|
+
addRow(key, coloredVal);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
addLine(dim(trimmed));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (usageData) {
|
|
279
|
+
if (!hasSessionLine) {
|
|
280
|
+
const session = oneLineText(usageData.sessionId || 'unknown') || 'unknown';
|
|
281
|
+
const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
|
|
282
|
+
addRow('Session', `${paint('ink', sessionName)} ${dim(`(${formatNumber(usageData.sessionTurns)} messages)`)}`);
|
|
283
|
+
}
|
|
284
|
+
const pool = Number.isFinite(usageData.contextPoolTokens) && usageData.contextPoolTokens > 0
|
|
285
|
+
? usageData.contextPoolTokens : 0;
|
|
286
|
+
const used = formatNumber(usageData.contextUsedTokens);
|
|
287
|
+
if (pool > 0) {
|
|
288
|
+
const percent = Number.isFinite(usageData.contextPercentLeft)
|
|
289
|
+
? Math.max(0, Math.min(100, Math.round(usageData.contextPercentLeft))) : 0;
|
|
290
|
+
const barRoom = Math.max(0, innerWidth - labelWidth - 13);
|
|
291
|
+
if (barRoom >= 8) {
|
|
292
|
+
const barWidth = Math.min(26, barRoom);
|
|
293
|
+
const bar = renderProgressBar(percent, barWidth, false);
|
|
294
|
+
addRow('Context left', `[${bar}] ${String(percent).padStart(3)}% left`);
|
|
295
|
+
}
|
|
296
|
+
addRow('Context tokens', `~${used} / ~${formatNumber(pool)} tokens`);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
addRow('Context tokens', `~${used} tokens; model limit unknown`);
|
|
300
|
+
}
|
|
301
|
+
if (usageData.sessionMetricsAvailable !== false) {
|
|
302
|
+
addRow('Tracked tokens', `${bold(formatNumber(usageData.sessionTokens))} session · ${bold(formatNumber(usageData.dailyTokens))} today`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
package/src/tui/usageCard.ts
CHANGED
|
@@ -210,73 +210,157 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
interface FramedCardOptions {
|
|
214
|
+
title: string;
|
|
215
|
+
footer?: string;
|
|
216
|
+
labelWidth?: number;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function buildFramedCardRows(
|
|
220
|
+
width: number,
|
|
221
|
+
options: FramedCardOptions,
|
|
222
|
+
populate: (addRow: (label: string, value: string) => void, addLine: (line: string) => void, ctx: { innerWidth: number; labelWidth: number }) => void
|
|
223
|
+
): string[] {
|
|
217
224
|
const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 80;
|
|
218
225
|
const frameWidth = safeWidth; // Never paint outside the terminal's actual columns.
|
|
219
226
|
const innerWidth = Math.max(0, frameWidth - 4);
|
|
220
227
|
const edge = paint('accent', FRAME.v);
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
const cleanTitle = oneLineText(options.title);
|
|
229
|
+
const title = frameWidth >= 32 ? ` ${bold(paint('accent', cleanTitle))} `
|
|
230
|
+
: frameWidth >= 13 ? ` ${cleanTitle.split(/\s+/)[0] || cleanTitle} ` : '';
|
|
231
|
+
const footerText = oneLineText(options.footer || 'esc close');
|
|
232
|
+
const hint = frameWidth >= 43 && footerText ? ` ${dim(footerText)} ` : '';
|
|
224
233
|
const lineRoom = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(hint));
|
|
225
234
|
const top = paint('accent', FRAME.tl + FRAME.h)
|
|
226
235
|
+ title + paint('accent', FRAME.h.repeat(lineRoom)) + hint + paint('accent', FRAME.tr);
|
|
227
236
|
const rows = [fill('surface', top)];
|
|
228
237
|
|
|
229
|
-
const labelWidth = innerWidth >= 60 ? 16 : 13;
|
|
230
|
-
const
|
|
231
|
-
const name = dim(String(label).padEnd(labelWidth));
|
|
232
|
-
const text = name + value;
|
|
238
|
+
const labelWidth = options.labelWidth ?? (innerWidth >= 60 ? 16 : 13);
|
|
239
|
+
const pushInnerRow = (text: string): void => {
|
|
233
240
|
const clipped = visibleWidth(text) > innerWidth
|
|
234
241
|
? truncate(text, innerWidth, GLYPHS.ellipsis) : text;
|
|
235
242
|
const padding = ' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)));
|
|
236
243
|
rows.push(fill('surface', `${edge} ${clipped}${padding} ${edge}`));
|
|
237
244
|
};
|
|
245
|
+
const addRow = (label: string, value: string): void => {
|
|
246
|
+
const name = dim(String(label).padEnd(labelWidth));
|
|
247
|
+
pushInnerRow(name + value);
|
|
248
|
+
};
|
|
238
249
|
|
|
239
|
-
|
|
240
|
-
const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
|
|
241
|
-
addRow('Session/Chat', `${paint('ink', sessionName)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
|
|
242
|
-
// Model and provider occupy separate rows, rather than squeezing two long
|
|
243
|
-
// identifiers into a single line where neither is readable.
|
|
244
|
-
addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
|
|
245
|
-
addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
|
|
250
|
+
populate(addRow, pushInnerRow, { innerWidth, labelWidth });
|
|
246
251
|
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
|
|
253
|
-
const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
|
|
254
|
-
addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
|
|
255
|
-
} else {
|
|
256
|
-
addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
|
|
257
|
-
}
|
|
252
|
+
const bottom = paint('accent', FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
|
|
253
|
+
rows.push(fill('surface', bottom));
|
|
254
|
+
rows.push(''); // Keep the composer visually separate from the pinned panel.
|
|
255
|
+
return rows;
|
|
256
|
+
}
|
|
258
257
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Render the usage card as an array of styled terminal rows, exactly matching `width`.
|
|
260
|
+
*/
|
|
261
|
+
export function renderUsageCardRows(data: UsageCardData, width: number): string[] {
|
|
262
|
+
return buildFramedCardRows(width, { title: 'Usage & Context', footer: 'esc close' }, (addRow, _addLine, { innerWidth, labelWidth }) => {
|
|
263
|
+
const session = oneLineText(data.sessionId || 'unknown') || 'unknown';
|
|
264
|
+
const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
|
|
265
|
+
addRow('Session/Chat', `${paint('ink', sessionName)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
|
|
266
|
+
// Model and provider occupy separate rows, rather than squeezing two long
|
|
267
|
+
// identifiers into a single line where neither is readable.
|
|
268
|
+
addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
|
|
269
|
+
addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
|
|
264
270
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
const pool = Number.isFinite(data.contextPoolTokens) && data.contextPoolTokens > 0
|
|
272
|
+
? data.contextPoolTokens : 0;
|
|
273
|
+
const estimatedUsed = formatNumber(data.contextUsedTokens);
|
|
274
|
+
if (pool > 0) {
|
|
275
|
+
const percent = Number.isFinite(data.contextPercentLeft)
|
|
276
|
+
? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
|
|
277
|
+
const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
|
|
278
|
+
addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
|
|
279
|
+
const barRoom = Math.max(0, innerWidth - labelWidth - 13);
|
|
280
|
+
if (barRoom >= 8) {
|
|
281
|
+
const barWidth = Math.min(28, barRoom);
|
|
282
|
+
const bar = renderProgressBar(percent, barWidth, false);
|
|
283
|
+
addRow('Window left', `[${bar}] ${String(percent).padStart(3)}% left`);
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
|
|
287
|
+
}
|
|
270
288
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
addRow('
|
|
276
|
-
}
|
|
289
|
+
addRow('This Session', data.sessionMetricsAvailable === false
|
|
290
|
+
? dim('unavailable (no live tracker)')
|
|
291
|
+
: `${bold(formatNumber(data.sessionTokens))} tracked tokens ${dim('(current process only)')}`);
|
|
292
|
+
addRow('Today (local)', `${bold(formatNumber(data.dailyTokens))} tracked tokens ${dim('(calendar day)')}`);
|
|
293
|
+
addRow('All-Time', `${bold(formatNumber(data.lifetimeTokens))} tracked tokens ${dim(`(${formatNumber(data.lifetimeCalls)} recorded events)`)}`);
|
|
277
294
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
295
|
+
const totalEstimate = formatCostEstimate(data.lifetimeCostUsd).trim();
|
|
296
|
+
const dailyEstimate = formatCostEstimate(data.dailyCostUsd).trim();
|
|
297
|
+
addRow('Cost (estimate)', totalEstimate
|
|
298
|
+
? `${totalEstimate} all-time${dailyEstimate ? ` · ${dailyEstimate} today` : ''}`
|
|
299
|
+
: dim('no positive local estimate recorded'));
|
|
300
|
+
|
|
301
|
+
addRow('Data source', dim('Local tracker; not provider billing or exact token telemetry'));
|
|
302
|
+
if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
|
|
303
|
+
const pct = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
|
|
304
|
+
? Math.max(0, Math.round(data.budgetPercentUsed)) : 0;
|
|
305
|
+
addRow('Daily budget', `${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tracked (${pct}% used)`);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Render the pinned `/status` card matching the Usage card styling, plus live session/context meters when available.
|
|
312
|
+
*/
|
|
313
|
+
export function renderStatusCardRows(
|
|
314
|
+
statusText: string,
|
|
315
|
+
usageData: UsageCardData | null | undefined,
|
|
316
|
+
width: number
|
|
317
|
+
): string[] {
|
|
318
|
+
return buildFramedCardRows(width, { title: 'Status', footer: 'esc close' }, (addRow, addLine, { innerWidth, labelWidth }) => {
|
|
319
|
+
const rawLines = String(statusText || '').split(/\r?\n/);
|
|
320
|
+
if (rawLines[0]?.trim() === 'Status') rawLines.shift();
|
|
321
|
+
let hasSessionLine = false;
|
|
322
|
+
for (const rawLine of rawLines) {
|
|
323
|
+
const trimmed = oneLineText(rawLine);
|
|
324
|
+
if (!trimmed) continue;
|
|
325
|
+
const sepIdx = trimmed.indexOf(':');
|
|
326
|
+
if (sepIdx > 0 && sepIdx <= 20) {
|
|
327
|
+
const key = trimmed.slice(0, sepIdx).trim();
|
|
328
|
+
const val = trimmed.slice(sepIdx + 1).trim();
|
|
329
|
+
if (key.toLowerCase() === 'session') hasSessionLine = true;
|
|
330
|
+
const coloredVal = key.toLowerCase().includes('provider')
|
|
331
|
+
? paint('accent', val)
|
|
332
|
+
: paint('ink', val);
|
|
333
|
+
addRow(key, coloredVal);
|
|
334
|
+
} else {
|
|
335
|
+
addLine(dim(trimmed));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (usageData) {
|
|
340
|
+
if (!hasSessionLine) {
|
|
341
|
+
const session = oneLineText(usageData.sessionId || 'unknown') || 'unknown';
|
|
342
|
+
const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
|
|
343
|
+
addRow('Session', `${paint('ink', sessionName)} ${dim(`(${formatNumber(usageData.sessionTurns)} messages)`)}`);
|
|
344
|
+
}
|
|
345
|
+
const pool = Number.isFinite(usageData.contextPoolTokens) && usageData.contextPoolTokens > 0
|
|
346
|
+
? usageData.contextPoolTokens : 0;
|
|
347
|
+
const used = formatNumber(usageData.contextUsedTokens);
|
|
348
|
+
if (pool > 0) {
|
|
349
|
+
const percent = Number.isFinite(usageData.contextPercentLeft)
|
|
350
|
+
? Math.max(0, Math.min(100, Math.round(usageData.contextPercentLeft))) : 0;
|
|
351
|
+
const barRoom = Math.max(0, innerWidth - labelWidth - 13);
|
|
352
|
+
if (barRoom >= 8) {
|
|
353
|
+
const barWidth = Math.min(26, barRoom);
|
|
354
|
+
const bar = renderProgressBar(percent, barWidth, false);
|
|
355
|
+
addRow('Context left', `[${bar}] ${String(percent).padStart(3)}% left`);
|
|
356
|
+
}
|
|
357
|
+
addRow('Context tokens', `~${used} / ~${formatNumber(pool)} tokens`);
|
|
358
|
+
} else {
|
|
359
|
+
addRow('Context tokens', `~${used} tokens; model limit unknown`);
|
|
360
|
+
}
|
|
361
|
+
if (usageData.sessionMetricsAvailable !== false) {
|
|
362
|
+
addRow('Tracked tokens', `${bold(formatNumber(usageData.sessionTokens))} session · ${bold(formatNumber(usageData.dailyTokens))} today`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
282
366
|
}
|
|
@@ -33,6 +33,8 @@ export function switchChatWorkspace({ workspaceRoot, createLoop, prompt = null,
|
|
|
33
33
|
// queued attachments or active skills from the previous workspace.
|
|
34
34
|
prompt.pendingAttachments = [];
|
|
35
35
|
prompt.completion = null;
|
|
36
|
+
if (typeof prompt.refreshPinnedPanels === 'function')
|
|
37
|
+
prompt.refreshPinnedPanels(replacement);
|
|
36
38
|
if (typeof prompt.scheduleDraw === 'function')
|
|
37
39
|
prompt.scheduleDraw();
|
|
38
40
|
}
|
|
@@ -60,6 +60,7 @@ export function switchChatWorkspace<TLoop extends {
|
|
|
60
60
|
// queued attachments or active skills from the previous workspace.
|
|
61
61
|
prompt.pendingAttachments = [];
|
|
62
62
|
prompt.completion = null;
|
|
63
|
+
if (typeof prompt.refreshPinnedPanels === 'function') prompt.refreshPinnedPanels(replacement);
|
|
63
64
|
if (typeof prompt.scheduleDraw === 'function') prompt.scheduleDraw();
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const DEFAULT_DEPTH = 6;
|
|
2
|
+
const DEFAULT_STATES = 10_000;
|
|
3
|
+
|
|
4
|
+
function boundedInteger(value, fallback, maximum) {
|
|
5
|
+
if (value === undefined) return fallback;
|
|
6
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) {
|
|
7
|
+
throw new RangeError('Invalid exploration bound');
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function exploreStateMachine(options) {
|
|
13
|
+
const { initial, actions, transition, invariant } = options || {};
|
|
14
|
+
if (!Array.isArray(actions) || actions.length === 0) throw new TypeError('actions must be nonempty');
|
|
15
|
+
if (actions.length > 10000) throw new RangeError('Too many actions to explore safely');
|
|
16
|
+
if (typeof transition !== 'function') throw new TypeError('transition must be a function');
|
|
17
|
+
if (typeof invariant !== 'function') throw new TypeError('invariant must be a function');
|
|
18
|
+
|
|
19
|
+
if (initial && typeof initial.then === 'function') {
|
|
20
|
+
throw new TypeError('Async initial state is not supported by synchronous model exploration');
|
|
21
|
+
}
|
|
22
|
+
const maxDepth = boundedInteger(options.maxDepth, DEFAULT_DEPTH, 32);
|
|
23
|
+
const maxStates = boundedInteger(options.maxStates, DEFAULT_STATES, 100_000);
|
|
24
|
+
if (maxStates === 0) throw new RangeError('maxStates must be positive');
|
|
25
|
+
const key = options.stateKey || JSON.stringify;
|
|
26
|
+
if (typeof key !== 'function') throw new TypeError('stateKey must be a function');
|
|
27
|
+
|
|
28
|
+
const checkedState = value => {
|
|
29
|
+
try { return structuredClone(value); }
|
|
30
|
+
catch { throw new TypeError('State must be structured-cloneable for sound bounded exploration'); }
|
|
31
|
+
};
|
|
32
|
+
const checkedAction = value => {
|
|
33
|
+
try { return structuredClone(value); }
|
|
34
|
+
catch { throw new TypeError('Actions must be structured-cloneable for sound bounded exploration'); }
|
|
35
|
+
};
|
|
36
|
+
const stableActions = actions.map(checkedAction);
|
|
37
|
+
const startState = checkedState(initial);
|
|
38
|
+
const startKey = key(checkedState(startState));
|
|
39
|
+
if (startKey && typeof startKey.then === 'function') {
|
|
40
|
+
throw new TypeError('Async stateKey is not supported');
|
|
41
|
+
}
|
|
42
|
+
if (typeof startKey !== 'string') throw new TypeError('stateKey must produce a string');
|
|
43
|
+
let nodesVisited = 1;
|
|
44
|
+
let transitions = 0;
|
|
45
|
+
let deepest = 0;
|
|
46
|
+
const root = { state: startState, trace: [] };
|
|
47
|
+
const queue = [root];
|
|
48
|
+
const seen = new Set([startKey]);
|
|
49
|
+
|
|
50
|
+
function failed(node) {
|
|
51
|
+
const result = invariant(checkedState(node.state));
|
|
52
|
+
if (result && typeof result.then === 'function') {
|
|
53
|
+
throw new TypeError('Async invariants are not supported');
|
|
54
|
+
}
|
|
55
|
+
if (result === true) return null;
|
|
56
|
+
return {
|
|
57
|
+
status: 'counterexample',
|
|
58
|
+
depthLimit: maxDepth,
|
|
59
|
+
statesExplored: nodesVisited,
|
|
60
|
+
transitionsExplored: transitions,
|
|
61
|
+
exploredDepth: node.trace.length,
|
|
62
|
+
trace: node.trace,
|
|
63
|
+
state: node.state,
|
|
64
|
+
reason: typeof result === 'string' ? result : 'Invariant returned false'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const initialFailure = failed(root);
|
|
69
|
+
if (initialFailure) return initialFailure;
|
|
70
|
+
for (let head = 0; head < queue.length; head++) {
|
|
71
|
+
const current = queue[head];
|
|
72
|
+
deepest = Math.max(deepest, current.trace.length);
|
|
73
|
+
if (current.trace.length >= maxDepth) continue;
|
|
74
|
+
for (const action of stableActions) {
|
|
75
|
+
// Each branch must start from the same immutable snapshot. A mutating
|
|
76
|
+
// transition otherwise poisons later siblings and can produce false proofs.
|
|
77
|
+
const isolated = checkedState(current.state);
|
|
78
|
+
const next = transition(isolated, checkedAction(action));
|
|
79
|
+
if (next && typeof next.then === 'function') {
|
|
80
|
+
throw new TypeError('Async transitions are not supported');
|
|
81
|
+
}
|
|
82
|
+
transitions++;
|
|
83
|
+
if (next === null || next === undefined) continue;
|
|
84
|
+
const trace = current.trace.concat(action);
|
|
85
|
+
const nextNode = { state: next, trace };
|
|
86
|
+
const failure = failed(nextNode);
|
|
87
|
+
if (failure) return failure;
|
|
88
|
+
const identity = key(checkedState(next));
|
|
89
|
+
if (identity && typeof identity.then === 'function') {
|
|
90
|
+
throw new TypeError('Async stateKey is not supported');
|
|
91
|
+
}
|
|
92
|
+
if (typeof identity !== 'string') throw new TypeError('stateKey must produce a string');
|
|
93
|
+
if (seen.has(identity)) continue;
|
|
94
|
+
if (nodesVisited >= maxStates) {
|
|
95
|
+
return {
|
|
96
|
+
status: 'incomplete',
|
|
97
|
+
depthLimit: maxDepth,
|
|
98
|
+
statesExplored: nodesVisited,
|
|
99
|
+
transitionsExplored: transitions,
|
|
100
|
+
exploredDepth: trace.length,
|
|
101
|
+
trace: [],
|
|
102
|
+
reason: 'Exploration reached maxStates before completing the bound'
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
seen.add(identity);
|
|
106
|
+
nodesVisited++;
|
|
107
|
+
queue.push(nextNode);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
status: 'bounded-pass',
|
|
112
|
+
depthLimit: maxDepth,
|
|
113
|
+
statesExplored: nodesVisited,
|
|
114
|
+
transitionsExplored: transitions,
|
|
115
|
+
exploredDepth: deepest,
|
|
116
|
+
trace: [],
|
|
117
|
+
reason: 'Invariant holds for reachable states within the stated bound; not an unbounded proof'
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { realpathSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
function inside(root, candidate) {
|
|
6
|
+
const lexicalRoot = path.resolve(root);
|
|
7
|
+
const base = realpathSync(root);
|
|
8
|
+
const lexical = path.relative(lexicalRoot, path.resolve(candidate));
|
|
9
|
+
if (lexical === '..' || lexical.startsWith('..' + path.sep) || path.isAbsolute(lexical)) return false;
|
|
10
|
+
let target;
|
|
11
|
+
try {
|
|
12
|
+
target = realpathSync(candidate);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error?.code === 'ENOENT') return true;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
const relative = path.relative(base, target);
|
|
18
|
+
return relative === '' || (relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function runCliProbe(options) {
|
|
22
|
+
const { workspace, program, args = [], timeoutMs = 8_000, outputLimit = 32_768,
|
|
23
|
+
expectedExitCode = 0, contains = null } = options || {};
|
|
24
|
+
if (typeof workspace !== 'string' || typeof program !== 'string'
|
|
25
|
+
|| !Array.isArray(args) || !args.every(a => typeof a === 'string')) {
|
|
26
|
+
throw new TypeError('workspace, program, and string argv are required');
|
|
27
|
+
}
|
|
28
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 10 || timeoutMs > 60_000) {
|
|
29
|
+
throw new RangeError('timeoutMs must be between 10 and 60000');
|
|
30
|
+
}
|
|
31
|
+
if (!Number.isSafeInteger(outputLimit) || outputLimit < 64 || outputLimit > 1_048_576) {
|
|
32
|
+
throw new RangeError('outputLimit must be between 64 and 1048576');
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isInteger(expectedExitCode) || expectedExitCode < 0 || expectedExitCode > 255) {
|
|
35
|
+
throw new RangeError('invalid expectedExitCode');
|
|
36
|
+
}
|
|
37
|
+
if (contains !== null && (typeof contains !== 'string' || contains.length > 1000)) {
|
|
38
|
+
throw new TypeError('contains must be a bounded string');
|
|
39
|
+
}
|
|
40
|
+
const cwd = path.resolve(workspace);
|
|
41
|
+
if (program !== 'node' && !path.isAbsolute(program)
|
|
42
|
+
&& !program.includes('/') && !program.includes('\\')) {
|
|
43
|
+
throw new Error('Executable must be an explicit workspace path or node');
|
|
44
|
+
}
|
|
45
|
+
const executable = program === 'node' ? process.execPath : program;
|
|
46
|
+
const resolvedProgram = path.isAbsolute(executable) ? executable
|
|
47
|
+
: executable.includes('/') || executable.includes('\\') ? path.resolve(cwd, executable) : executable;
|
|
48
|
+
if (!inside(cwd, cwd)) throw new Error('Invalid workspace');
|
|
49
|
+
if ((executable.includes('/') || executable.includes('\\')) && !inside(cwd, resolvedProgram)
|
|
50
|
+
&& resolvedProgram !== process.execPath) {
|
|
51
|
+
throw new Error('Executable must remain inside workspace');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
return new Promise(resolve => {
|
|
56
|
+
let stdout = '';
|
|
57
|
+
let stderr = '';
|
|
58
|
+
let usedBytes = 0;
|
|
59
|
+
let truncated = false;
|
|
60
|
+
let timedOut = false;
|
|
61
|
+
let exitCode = null;
|
|
62
|
+
let signal = null;
|
|
63
|
+
let spawnError = null;
|
|
64
|
+
let settled = false;
|
|
65
|
+
let child;
|
|
66
|
+
let timer;
|
|
67
|
+
const finish = () => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true;
|
|
70
|
+
if (timer) clearTimeout(timer);
|
|
71
|
+
const success = !timedOut && !spawnError && exitCode === expectedExitCode
|
|
72
|
+
&& !truncated && (contains === null || (stdout + stderr).includes(contains));
|
|
73
|
+
resolve({
|
|
74
|
+
status: success ? 'observed-pass' : 'observed-fail',
|
|
75
|
+
success, command: { program, args, workspace: cwd },
|
|
76
|
+
exitCode, signal, timedOut, truncated, stdout, stderr,
|
|
77
|
+
error: spawnError, durationMs: Math.max(0, Date.now() - started),
|
|
78
|
+
surface: 'cli-pipe',
|
|
79
|
+
limitation: 'A pipe subprocess does not verify terminal rendering, mouse events, or desktop UI behavior'
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const collect = (field, chunk) => {
|
|
83
|
+
const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
84
|
+
const available = Math.max(0, outputLimit - usedBytes);
|
|
85
|
+
if (data.length > available) truncated = true;
|
|
86
|
+
if (available) {
|
|
87
|
+
const safe = data.subarray(0, available).toString('utf8');
|
|
88
|
+
if (field === 'stdout') stdout += safe;
|
|
89
|
+
else stderr += safe;
|
|
90
|
+
usedBytes += Math.min(available, data.length);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
child = spawn(resolvedProgram, args, {
|
|
95
|
+
cwd, shell: false, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true,
|
|
96
|
+
env: { ...process.env, CAUSYNE_VERIFY_PROBE: '1' }
|
|
97
|
+
});
|
|
98
|
+
child.stdout?.on('data', chunk => collect('stdout', chunk));
|
|
99
|
+
child.stderr?.on('data', chunk => collect('stderr', chunk));
|
|
100
|
+
child.on('error', error => { spawnError = String(error.message || error); finish(); });
|
|
101
|
+
child.on('close', (code, sig) => {
|
|
102
|
+
exitCode = code;
|
|
103
|
+
signal = sig;
|
|
104
|
+
finish();
|
|
105
|
+
});
|
|
106
|
+
timer = setTimeout(() => {
|
|
107
|
+
timedOut = true;
|
|
108
|
+
child.kill('SIGKILL');
|
|
109
|
+
}, timeoutMs);
|
|
110
|
+
timer.unref?.();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
spawnError = String(error?.message || error);
|
|
113
|
+
finish();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|