@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@causyne/agent",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.118",
|
|
4
4
|
"description": "Agentic AI for software, tools, and computer workflows",
|
|
5
5
|
"main": "bin/causyne.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,12 @@
|
|
|
32
32
|
"typecheck": "tsc -p tsconfig.json",
|
|
33
33
|
"typecheck:ts": "tsc -p tsconfig.strict.json",
|
|
34
34
|
"typecheck:js-ratchet": "tsc -p tsconfig.js-ratchet.json",
|
|
35
|
-
"typecheck:strict": "npm run typecheck:ts && npm run typecheck:js-ratchet"
|
|
35
|
+
"typecheck:strict": "npm run typecheck:ts && npm run typecheck:js-ratchet",
|
|
36
|
+
"verify:features": "node scripts/verify-features.mjs",
|
|
37
|
+
"verify:ui": "node scripts/verify-ui.mjs",
|
|
38
|
+
"verify:properties": "node --test --import ./tests/helpers/isolateState.js tests/boundedExplorer.test.ts tests/verificationPropertyProbe.test.ts",
|
|
39
|
+
"verify:statechart": "node scripts/verify-statechart.mjs",
|
|
40
|
+
"verify:tla": "node scripts/verify-tla.mjs"
|
|
36
41
|
},
|
|
37
42
|
"engines": {
|
|
38
43
|
"node": ">=24.0.0"
|
package/src/cliMode.js
CHANGED
|
@@ -66,6 +66,9 @@ export class LocalCLIConnection {
|
|
|
66
66
|
|
|
67
67
|
try {
|
|
68
68
|
this.renderer.handle(msg);
|
|
69
|
+
if (msg.type === 'usage_update' && typeof this.onUsageUpdate === 'function') {
|
|
70
|
+
this.onUsageUpdate(msg);
|
|
71
|
+
}
|
|
69
72
|
} catch (e) {
|
|
70
73
|
// This used to be `catch(e) {}` around the whole method, so a render bug
|
|
71
74
|
// silently ate the frame and the transcript just went quiet. Report it
|
|
@@ -377,12 +380,24 @@ export async function chatMode({ home = false } = {}) {
|
|
|
377
380
|
messageActionLoop: loop,
|
|
378
381
|
onInterrupt: () => loop.abort(),
|
|
379
382
|
getMode: () => loop.config?.autonomyMode || config.autonomyMode || 'B',
|
|
380
|
-
onOpenMode: () =>
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
onOpenMode: async () => {
|
|
384
|
+
await openModeControl(prompt, loop);
|
|
385
|
+
prompt?.refreshPinnedPanels?.(loop);
|
|
386
|
+
},
|
|
387
|
+
onOpenModel: async () => {
|
|
388
|
+
await runInteractiveModelPicker(prompt, { loadConfig, saveConfig }, { loop });
|
|
389
|
+
prompt?.refreshPinnedPanels?.(loop);
|
|
390
|
+
},
|
|
391
|
+
onOpenVariant: async () => {
|
|
392
|
+
await openVariantControl(prompt);
|
|
393
|
+
prompt?.refreshPinnedPanels?.(loop);
|
|
394
|
+
},
|
|
383
395
|
onExit: () => { if (prompt) prompt.stop(); process.exit(0); },
|
|
384
396
|
onExpand: () => conn.renderer.expandLastOutput()
|
|
385
397
|
});
|
|
398
|
+
conn.onUsageUpdate = () => {
|
|
399
|
+
if (prompt && typeof prompt.refreshPinnedPanels === 'function') prompt.refreshPinnedPanels(loop);
|
|
400
|
+
};
|
|
386
401
|
if (surface) prompt.attachSurface(surface);
|
|
387
402
|
prompt.attach(conn.renderer);
|
|
388
403
|
prompt.start();
|
|
@@ -631,6 +646,7 @@ export async function chatMode({ home = false } = {}) {
|
|
|
631
646
|
if (commandResult.output && (commandResult.output.includes('Now using') || commandResult.output.includes('Active model switched') || commandResult.output.includes('Saved API key'))) {
|
|
632
647
|
conn.renderer.write(homeStatusLine({ config: loadConfig() }) + '\n');
|
|
633
648
|
}
|
|
649
|
+
if (prompt && typeof prompt.refreshPinnedPanels === 'function') prompt.refreshPinnedPanels(loop);
|
|
634
650
|
if (commandResult.effect === 'exit') { finish(); break; }
|
|
635
651
|
continue;
|
|
636
652
|
}
|
package/src/commands.js
CHANGED
|
@@ -2055,7 +2055,13 @@ export const COMMANDS = [
|
|
|
2055
2055
|
description: 'Show the current provider, autonomy mode and workspace scope',
|
|
2056
2056
|
dialogTitle: 'Status',
|
|
2057
2057
|
// One builder, shared with `causyne status`, so status output cannot drift.
|
|
2058
|
-
run: (argv, ctx) =>
|
|
2058
|
+
run: (argv, ctx = {}) => {
|
|
2059
|
+
if (ctx.prompt && typeof ctx.prompt.toggleStatusCard === 'function') {
|
|
2060
|
+
ctx.prompt.toggleStatusCard(ctx.loop);
|
|
2061
|
+
return ok('', { effect: 'silent' });
|
|
2062
|
+
}
|
|
2063
|
+
return ok(buildStatusText({ loop: ctx.loop || null }));
|
|
2064
|
+
}
|
|
2059
2065
|
},
|
|
2060
2066
|
|
|
2061
2067
|
{
|
|
@@ -304,6 +304,80 @@ export function createPlugin({ name, description, toolName, toolDescription, par
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
|
|
308
|
+
export function createSkillPlugin({
|
|
309
|
+
name, description, skillId, skillName, skillDescription, skillContent, licenseText
|
|
310
|
+
} = {}) {
|
|
311
|
+
if (!NAME.test(name || '')) return { ok: false, error: 'Invalid plugin name' };
|
|
312
|
+
if (!NAME.test(skillId || '')) return { ok: false, error: 'Invalid skill id' };
|
|
313
|
+
if (typeof description !== 'string' || !description.trim() || description.length > 1000) {
|
|
314
|
+
return { ok: false, error: 'Plugin description must be 1..1000 characters' };
|
|
315
|
+
}
|
|
316
|
+
if (typeof skillName !== 'string' || !skillName.trim() || skillName.length > 120) {
|
|
317
|
+
return { ok: false, error: 'Skill name must be 1..120 characters' };
|
|
318
|
+
}
|
|
319
|
+
if (typeof skillDescription !== 'string' || !skillDescription.trim()
|
|
320
|
+
|| skillDescription.length > 400) {
|
|
321
|
+
return { ok: false, error: 'Skill description must be 1..400 characters' };
|
|
322
|
+
}
|
|
323
|
+
if (typeof skillContent !== 'string' || !skillContent.trim()
|
|
324
|
+
|| Buffer.byteLength(skillContent, 'utf8') > 32 * 1024) {
|
|
325
|
+
return { ok: false, error: 'Skill content must be nonempty and at most 32 KB' };
|
|
326
|
+
}
|
|
327
|
+
if (typeof licenseText !== 'string' || licenseText.length > 32 * 1024) {
|
|
328
|
+
return { ok: false, error: 'Full third-party license text is required' };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const isMit = /^MIT License\s*$/mi.test(licenseText)
|
|
332
|
+
&& /Permission is hereby granted, free of charge/i.test(licenseText)
|
|
333
|
+
&& /above copyright notice/i.test(licenseText);
|
|
334
|
+
const isApache = /Apache License\s*Version 2\.0/i.test(licenseText)
|
|
335
|
+
&& /TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION/i.test(licenseText);
|
|
336
|
+
if (!isMit && !isApache) {
|
|
337
|
+
return { ok: false, error: 'Only reviewed MIT or Apache-2.0 license text is accepted' };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const manifest = {
|
|
341
|
+
schemaVersion: 1, name, version: '0.1.0', description: description.trim(),
|
|
342
|
+
capabilities: [], tools: [],
|
|
343
|
+
skills: [{
|
|
344
|
+
id: skillId, name: skillName.trim(),
|
|
345
|
+
description: skillDescription.trim(), file: 'SKILL.md'
|
|
346
|
+
}]
|
|
347
|
+
};
|
|
348
|
+
ensureRoot();
|
|
349
|
+
const directory = path.join(PLUGIN_ROOT, name);
|
|
350
|
+
if (fs.existsSync(directory)) return { ok: false, error: 'Plugin already exists' };
|
|
351
|
+
let created = false;
|
|
352
|
+
try {
|
|
353
|
+
fs.mkdirSync(directory, { mode: 0o700 });
|
|
354
|
+
created = true;
|
|
355
|
+
fs.writeFileSync(path.join(directory, 'SKILL.md'), skillContent, {
|
|
356
|
+
mode: 0o600, flag: 'wx'
|
|
357
|
+
});
|
|
358
|
+
fs.writeFileSync(path.join(directory, 'LICENSE'), licenseText, {
|
|
359
|
+
mode: 0o600, flag: 'wx'
|
|
360
|
+
});
|
|
361
|
+
fs.writeFileSync(path.join(directory, 'plugin.json'),
|
|
362
|
+
JSON.stringify(manifest, null, 2) + '\n', {
|
|
363
|
+
mode: 0o600, flag: 'wx'
|
|
364
|
+
});
|
|
365
|
+
const reviewed = readPlugin(directory);
|
|
366
|
+
return {
|
|
367
|
+
ok: true, name, enabled: false, tools: [],
|
|
368
|
+
skills: reviewed.skills.map(entry => entry.domain + '/' + entry.id),
|
|
369
|
+
license: isMit ? 'MIT' : 'Apache-2.0',
|
|
370
|
+
digest: reviewed.digest, path: directory,
|
|
371
|
+
message: 'Skill packaged disabled. Review its instructions and license before explicit enablement.'
|
|
372
|
+
};
|
|
373
|
+
} catch (error) {
|
|
374
|
+
if (created) {
|
|
375
|
+
try { fs.rmSync(directory, { recursive: true, force: true }); } catch {}
|
|
376
|
+
}
|
|
377
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
307
381
|
function enabledTools() {
|
|
308
382
|
const state = readState();
|
|
309
383
|
const tools = [];
|
package/src/reporting.js
CHANGED
|
@@ -339,20 +339,28 @@ export function formatUptime(ms) {
|
|
|
339
339
|
*/
|
|
340
340
|
export function buildStatusText({ loop = null } = {}) {
|
|
341
341
|
const config = loadConfig();
|
|
342
|
+
const liveConfig = loop?.config || {};
|
|
343
|
+
const provider = liveConfig.provider || config.provider || 'default';
|
|
344
|
+
const model = liveConfig.model || config.model || 'default';
|
|
345
|
+
const autonomyMode = liveConfig.autonomyMode || config.autonomyMode || 'C';
|
|
346
|
+
const tier = liveConfig.tier || config.tier || 'premium';
|
|
342
347
|
const lines = ['Status'];
|
|
343
348
|
|
|
344
349
|
lines.push(' Runtime : local desktop');
|
|
345
350
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
351
|
+
if (loop?.memoryManager?.sessionId) {
|
|
352
|
+
lines.push(` Session : ${loop.memoryManager.sessionId}`);
|
|
353
|
+
}
|
|
354
|
+
lines.push(` Provider / model : ${provider} / ${model}`);
|
|
355
|
+
lines.push(` Autonomy mode : ${autonomyMode}`);
|
|
356
|
+
lines.push(` Tier : ${tier}`);
|
|
349
357
|
|
|
350
358
|
if (loop && loop.sandbox) {
|
|
351
359
|
const sandbox = loop.sandbox;
|
|
352
360
|
lines.push(` Workspace scope : ${sandbox.grantAllAccess ? 'ALL ACCESS' : (sandbox.workspacePaths || []).join(', ')}`);
|
|
353
361
|
}
|
|
354
362
|
|
|
355
|
-
if (!
|
|
363
|
+
if (!liveConfig.apiKey && !config.apiKey && provider !== 'ollama' && !isAcpProvider(provider) && !isAntigravityProvider(provider)) {
|
|
356
364
|
lines.push('');
|
|
357
365
|
lines.push(' No API key is set. Run `causyne config`.');
|
|
358
366
|
}
|
package/src/skillsManager.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { COMPILED_SKILLS } from './compiledSkills.js';
|
|
4
|
+
import { VERIFICATION_SKILLS } from './verification/skillCatalog.js';
|
|
4
5
|
import { loadUserSkills } from './userSkills.js';
|
|
5
6
|
import { getPluginSkills } from './plugins/pluginManager.js';
|
|
6
|
-
const compiledSkillsCatalog = COMPILED_SKILLS;
|
|
7
|
+
const compiledSkillsCatalog = { ...COMPILED_SKILLS, verification: VERIFICATION_SKILLS };
|
|
7
8
|
// User skills are read from disk, and the disk is slow relative to how often
|
|
8
9
|
// these functions are called (every completion keystroke asks for the
|
|
9
10
|
// catalogue). Cache for a moment so typing stays instant, but keep the window
|
|
@@ -80,7 +81,7 @@ const DOMAIN_INDICATORS = {
|
|
|
80
81
|
// Design and security are not properties of a file layout — an agent writing a
|
|
81
82
|
// UI needs the anti-slop direction whether or not a tailwind config exists, and
|
|
82
83
|
// input validation matters whether or not the repository has a SECURITY.md.
|
|
83
|
-
const UNIVERSAL_DOMAINS = ['design', 'security'];
|
|
84
|
+
const UNIVERSAL_DOMAINS = ['design', 'security', 'verification'];
|
|
84
85
|
// Ceiling on how many skill descriptions may enter the system prompt.
|
|
85
86
|
//
|
|
86
87
|
// With 100 skills, injecting every description of every detected domain would
|
package/src/skillsManager.ts
CHANGED
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { COMPILED_SKILLS } from './compiledSkills.js';
|
|
5
|
+
import { VERIFICATION_SKILLS } from './verification/skillCatalog.js';
|
|
5
6
|
import { loadUserSkills, type UserSkill } from './userSkills.js';
|
|
6
7
|
import { getPluginSkills } from './plugins/pluginManager.js';
|
|
7
8
|
|
|
@@ -19,7 +20,7 @@ interface CompiledSkillItem {
|
|
|
19
20
|
content: string;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const compiledSkillsCatalog = COMPILED_SKILLS as unknown as Record<string, Record<string, CompiledSkillItem>>;
|
|
23
|
+
const compiledSkillsCatalog = { ...COMPILED_SKILLS, verification: VERIFICATION_SKILLS } as unknown as Record<string, Record<string, CompiledSkillItem>>;
|
|
23
24
|
|
|
24
25
|
// User skills are read from disk, and the disk is slow relative to how often
|
|
25
26
|
// these functions are called (every completion keystroke asks for the
|
|
@@ -100,7 +101,7 @@ const DOMAIN_INDICATORS: Record<string, string[]> = {
|
|
|
100
101
|
// Design and security are not properties of a file layout — an agent writing a
|
|
101
102
|
// UI needs the anti-slop direction whether or not a tailwind config exists, and
|
|
102
103
|
// input validation matters whether or not the repository has a SECURITY.md.
|
|
103
|
-
const UNIVERSAL_DOMAINS = ['design', 'security'];
|
|
104
|
+
const UNIVERSAL_DOMAINS = ['design', 'security', 'verification'];
|
|
104
105
|
|
|
105
106
|
// Ceiling on how many skill descriptions may enter the system prompt.
|
|
106
107
|
//
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPlugin,
|
|
3
|
+
createSkillPlugin,
|
|
3
4
|
disablePlugin,
|
|
4
5
|
enablePlugin,
|
|
5
6
|
listPlugins
|
|
@@ -8,17 +9,22 @@ import {
|
|
|
8
9
|
export const pluginManagerTool = {
|
|
9
10
|
schema: {
|
|
10
11
|
name: 'plugin.manager',
|
|
11
|
-
description: 'Create and manage local Causyne plugins.
|
|
12
|
+
description: 'Create and manage local Causyne plugins. create-skill-plugin packages reviewed MIT/Apache skill text as a disabled, non-executable plugin and retains its license; enable trusts the current directory digest.',
|
|
12
13
|
parameters: {
|
|
13
14
|
type: 'object',
|
|
14
15
|
properties: {
|
|
15
|
-
action: { type: 'string', enum: ['list', 'create', 'enable', 'disable'] },
|
|
16
|
+
action: { type: 'string', enum: ['list', 'create', 'create-skill-plugin', 'enable', 'disable'] },
|
|
16
17
|
name: { type: 'string', description: 'Lowercase plugin name using letters, digits, and hyphens.' },
|
|
17
18
|
description: { type: 'string' },
|
|
18
19
|
toolName: { type: 'string' },
|
|
19
20
|
toolDescription: { type: 'string' },
|
|
20
21
|
parametersSchema: { type: 'string', description: 'JSON object schema for the custom tool arguments.' },
|
|
21
22
|
javascriptCode: { type: 'string', description: 'Body of async execute(args, context), or a complete module exporting execute.' },
|
|
23
|
+
skillId: { type: 'string' },
|
|
24
|
+
skillName: { type: 'string' },
|
|
25
|
+
skillDescription: { type: 'string' },
|
|
26
|
+
skillContent: { type: 'string', description: 'Reviewed SKILL.md source, not executed as code.' },
|
|
27
|
+
licenseText: { type: 'string', description: 'Complete original MIT or Apache-2.0 license notice.' },
|
|
22
28
|
capabilities: {
|
|
23
29
|
type: 'array',
|
|
24
30
|
items: { type: 'string', enum: ['workspace:read', 'workspace:write', 'network', 'subprocess'] }
|
|
@@ -38,6 +44,15 @@ export const pluginManagerTool = {
|
|
|
38
44
|
const result = disablePlugin(args.name);
|
|
39
45
|
return result.ok ? { success: true, ...result } : { success: false, error: result.error };
|
|
40
46
|
}
|
|
47
|
+
if (args.action === 'create-skill-plugin') {
|
|
48
|
+
const result = createSkillPlugin({
|
|
49
|
+
name: args.name, description: args.description,
|
|
50
|
+
skillId: args.skillId, skillName: args.skillName,
|
|
51
|
+
skillDescription: args.skillDescription,
|
|
52
|
+
skillContent: args.skillContent, licenseText: args.licenseText
|
|
53
|
+
});
|
|
54
|
+
return result.ok ? { success: true, ...result } : { success: false, error: result.error };
|
|
55
|
+
}
|
|
41
56
|
if (args.action === 'create') {
|
|
42
57
|
let parameters;
|
|
43
58
|
try {
|
|
@@ -143,9 +143,22 @@ export function handlePromptEscape(prompt, formatInterruptedRow) {
|
|
|
143
143
|
prompt.scheduleDraw();
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
-
if (prompt.usageCard) {
|
|
147
|
-
prompt.
|
|
148
|
-
|
|
146
|
+
if (prompt.usageCard || prompt.usageCardLoading) {
|
|
147
|
+
if (typeof prompt.closeUsageCard === 'function')
|
|
148
|
+
prompt.closeUsageCard();
|
|
149
|
+
else {
|
|
150
|
+
prompt.usageCard = null;
|
|
151
|
+
prompt.scheduleDraw();
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (prompt.statusCard !== null && prompt.statusCard !== undefined) {
|
|
156
|
+
if (typeof prompt.closeStatusCard === 'function')
|
|
157
|
+
prompt.closeStatusCard();
|
|
158
|
+
else {
|
|
159
|
+
prompt.statusCard = null;
|
|
160
|
+
prompt.scheduleDraw();
|
|
161
|
+
}
|
|
149
162
|
return;
|
|
150
163
|
}
|
|
151
164
|
if (prompt.completion) {
|
|
@@ -193,9 +193,20 @@ export function handlePromptEscape(
|
|
|
193
193
|
prompt.scheduleDraw();
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
if ((prompt as any).usageCard) {
|
|
197
|
-
(prompt as any).
|
|
198
|
-
|
|
196
|
+
if ((prompt as any).usageCard || (prompt as any).usageCardLoading) {
|
|
197
|
+
if (typeof (prompt as any).closeUsageCard === 'function') (prompt as any).closeUsageCard();
|
|
198
|
+
else {
|
|
199
|
+
(prompt as any).usageCard = null;
|
|
200
|
+
prompt.scheduleDraw();
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if ((prompt as any).statusCard !== null && (prompt as any).statusCard !== undefined) {
|
|
205
|
+
if (typeof (prompt as any).closeStatusCard === 'function') (prompt as any).closeStatusCard();
|
|
206
|
+
else {
|
|
207
|
+
(prompt as any).statusCard = null;
|
|
208
|
+
prompt.scheduleDraw();
|
|
209
|
+
}
|
|
199
210
|
return;
|
|
200
211
|
}
|
|
201
212
|
if (prompt.completion) {
|
package/src/tui/prompt.js
CHANGED
|
@@ -29,7 +29,8 @@ import { composerGeometry } from './composerGeometry.js';
|
|
|
29
29
|
import { visibleWidth, truncate, wrapBlock, shortenHome, safeDisplay, stripAnsi } from './text.js';
|
|
30
30
|
import { pickExample, fitHints } from './banner.js';
|
|
31
31
|
import { panelRows } from './overlay.js';
|
|
32
|
-
import { renderUsageCardRows, collectUsageCardData } from './usageCard.js';
|
|
32
|
+
import { renderUsageCardRows, renderStatusCardRows, collectUsageCardData } from './usageCard.js';
|
|
33
|
+
import { buildStatusText } from '../reporting.js';
|
|
33
34
|
import { commandPalette, skillPicker, ApprovalLayer, DecisionLayer, ConfirmLayer, HomeLayer, TextLayer } from './dialogs.js';
|
|
34
35
|
import { describeTool } from './toolDisplay.js';
|
|
35
36
|
import { readClipboardSync, writeClipboardSync } from './clipboardSync.js';
|
|
@@ -135,6 +136,11 @@ export class ChatPrompt {
|
|
|
135
136
|
this.exitHook = null;
|
|
136
137
|
this.drawnRows = 0;
|
|
137
138
|
this.usageCard = null;
|
|
139
|
+
this.usageCardLoading = false;
|
|
140
|
+
this.statusCard = null;
|
|
141
|
+
this.statusCardUsage = null;
|
|
142
|
+
this.infoPanelVersion = 0;
|
|
143
|
+
this.usageRefreshPending = false;
|
|
138
144
|
|
|
139
145
|
// Which row of the drawn block the caret is parked on.
|
|
140
146
|
//
|
|
@@ -542,6 +548,10 @@ export class ChatPrompt {
|
|
|
542
548
|
this.tickTimer = setInterval(() => {
|
|
543
549
|
this.tick++;
|
|
544
550
|
if (this.busy) this.scheduleDraw();
|
|
551
|
+
// Keep the pinned usage/status view current without disk reads every 125 ms.
|
|
552
|
+
if (this.busy && (this.usageCard || this.statusCard !== null) && this.tick % 32 === 0) {
|
|
553
|
+
this.refreshPinnedPanels();
|
|
554
|
+
}
|
|
545
555
|
}, 125);
|
|
546
556
|
if (this.tickTimer.unref) this.tickTimer.unref();
|
|
547
557
|
}
|
|
@@ -667,16 +677,31 @@ export class ChatPrompt {
|
|
|
667
677
|
}));
|
|
668
678
|
}
|
|
669
679
|
|
|
670
|
-
/**
|
|
680
|
+
/** Usage and Status are non-modal panels: ordinary chat must not close them. */
|
|
671
681
|
async toggleUsageCard(loop = null) {
|
|
672
|
-
if (this.usageCard) {
|
|
673
|
-
this.
|
|
682
|
+
if (this.usageCard || this.usageCardLoading) {
|
|
683
|
+
this.closeUsageCard();
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
const version = ++this.infoPanelVersion;
|
|
687
|
+
this.statusCard = null;
|
|
688
|
+
this.statusCardUsage = null;
|
|
689
|
+
this.usageCardLoading = true;
|
|
690
|
+
try {
|
|
691
|
+
const data = await collectUsageCardData(loop || this.messageActionLoop);
|
|
692
|
+
if (version !== this.infoPanelVersion || !this.usageCardLoading) return false;
|
|
693
|
+
this.usageCard = data;
|
|
694
|
+
this.usageCardLoading = false;
|
|
674
695
|
this.scheduleDraw();
|
|
696
|
+
return true;
|
|
697
|
+
} catch (error) {
|
|
698
|
+
if (version === this.infoPanelVersion) {
|
|
699
|
+
this.usageCardLoading = false;
|
|
700
|
+
this.notice = this.sanitizeSingleLine(error instanceof Error ? error.message : String(error));
|
|
701
|
+
this.scheduleDraw();
|
|
702
|
+
}
|
|
675
703
|
return false;
|
|
676
704
|
}
|
|
677
|
-
this.usageCard = await collectUsageCardData(loop || this.messageActionLoop);
|
|
678
|
-
this.scheduleDraw();
|
|
679
|
-
return true;
|
|
680
705
|
}
|
|
681
706
|
|
|
682
707
|
showUsageCard(loop = null) {
|
|
@@ -684,12 +709,84 @@ export class ChatPrompt {
|
|
|
684
709
|
}
|
|
685
710
|
|
|
686
711
|
closeUsageCard() {
|
|
687
|
-
if (this.usageCard)
|
|
688
|
-
|
|
712
|
+
if (!this.usageCard && !this.usageCardLoading) return false;
|
|
713
|
+
++this.infoPanelVersion; // Invalidate an in-flight open or refresh.
|
|
714
|
+
this.usageCard = null;
|
|
715
|
+
this.usageCardLoading = false;
|
|
716
|
+
this.scheduleDraw();
|
|
717
|
+
return true;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
async refreshUsageCard(loop = null) {
|
|
721
|
+
if (!this.usageCard || this.usageRefreshPending) return false;
|
|
722
|
+
const version = this.infoPanelVersion;
|
|
723
|
+
this.usageRefreshPending = true;
|
|
724
|
+
try {
|
|
725
|
+
const data = await collectUsageCardData(loop || this.messageActionLoop);
|
|
726
|
+
if (version !== this.infoPanelVersion || !this.usageCard) return false;
|
|
727
|
+
this.usageCard = data;
|
|
689
728
|
this.scheduleDraw();
|
|
690
729
|
return true;
|
|
730
|
+
} catch {
|
|
731
|
+
// A transient ledger read failure must not close an already visible panel.
|
|
732
|
+
return false;
|
|
733
|
+
} finally {
|
|
734
|
+
this.usageRefreshPending = false;
|
|
691
735
|
}
|
|
692
|
-
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
toggleStatusCard(loop = null) {
|
|
739
|
+
if (this.statusCard !== null) {
|
|
740
|
+
this.closeStatusCard();
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
const targetLoop = loop || this.messageActionLoop;
|
|
744
|
+
++this.infoPanelVersion; // A pending usage read must not reopen a replaced panel.
|
|
745
|
+
this.usageCard = null;
|
|
746
|
+
this.usageCardLoading = false;
|
|
747
|
+
this.statusCardUsage = null;
|
|
748
|
+
this.statusCard = buildStatusText({ loop: targetLoop });
|
|
749
|
+
this.scheduleDraw();
|
|
750
|
+
void this.refreshStatusCardMeta(targetLoop);
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
closeStatusCard() {
|
|
755
|
+
if (this.statusCard === null) return false;
|
|
756
|
+
++this.infoPanelVersion;
|
|
757
|
+
this.statusCard = null;
|
|
758
|
+
this.statusCardUsage = null;
|
|
759
|
+
this.scheduleDraw();
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
async refreshStatusCardMeta(loop = null) {
|
|
764
|
+
if (this.statusCard === null) return false;
|
|
765
|
+
const version = this.infoPanelVersion;
|
|
766
|
+
try {
|
|
767
|
+
const data = await collectUsageCardData(loop || this.messageActionLoop);
|
|
768
|
+
if (version !== this.infoPanelVersion || this.statusCard === null) return false;
|
|
769
|
+
this.statusCardUsage = data;
|
|
770
|
+
this.scheduleDraw();
|
|
771
|
+
return true;
|
|
772
|
+
} catch {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
refreshPinnedPanels(loop = null) {
|
|
778
|
+
const targetLoop = loop || this.messageActionLoop;
|
|
779
|
+
if (this.usageCard) void this.refreshUsageCard(targetLoop);
|
|
780
|
+
if (this.statusCard !== null) {
|
|
781
|
+
this.statusCard = buildStatusText({ loop: targetLoop });
|
|
782
|
+
this.scheduleDraw();
|
|
783
|
+
void this.refreshStatusCardMeta(targetLoop);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
statusCardRows(width) {
|
|
788
|
+
if (this.statusCard === null) return [];
|
|
789
|
+
return renderStatusCardRows(this.statusCard, this.statusCardUsage, width);
|
|
693
790
|
}
|
|
694
791
|
|
|
695
792
|
/**
|
|
@@ -877,6 +974,11 @@ export class ChatPrompt {
|
|
|
877
974
|
this.busy = busy;
|
|
878
975
|
resetTurnInterruptState(this, busy);
|
|
879
976
|
if (busy) this.startTick(); else this.stopTick();
|
|
977
|
+
if (!busy && this.usageCard) void this.refreshUsageCard();
|
|
978
|
+
if (this.statusCard !== null) {
|
|
979
|
+
this.statusCard = buildStatusText({ loop: this.messageActionLoop });
|
|
980
|
+
if (!busy) void this.refreshStatusCardMeta(this.messageActionLoop);
|
|
981
|
+
}
|
|
880
982
|
if (this.surface?.stage) this.surface.stage.invalidate();
|
|
881
983
|
this.draw();
|
|
882
984
|
}
|
|
@@ -897,15 +999,18 @@ export class ChatPrompt {
|
|
|
897
999
|
this.history.add(text);
|
|
898
1000
|
this.editor.clear();
|
|
899
1001
|
this.completion = null;
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
|
|
1002
|
+
// Do not dismiss a pinned information panel on any chat submission,
|
|
1003
|
+
// queued prompt, or agent run. Only Esc or the same command closes it.
|
|
904
1004
|
// Instant slash command shortcuts that operate directly on the prompt surface
|
|
905
|
-
if (text === '/usage'
|
|
1005
|
+
if ((text.trim().toLowerCase() === '/usage' || text.trim().toLowerCase() === '/cost')
|
|
1006
|
+
&& typeof this.toggleUsageCard === 'function') {
|
|
906
1007
|
void this.toggleUsageCard();
|
|
907
1008
|
return;
|
|
908
1009
|
}
|
|
1010
|
+
if (text.trim().toLowerCase() === '/status' && typeof this.toggleStatusCard === 'function') {
|
|
1011
|
+
this.toggleStatusCard();
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
909
1014
|
|
|
910
1015
|
if (text === '/observer' || text === '/observer status') {
|
|
911
1016
|
import('./observerPicker.js').then(({ runInteractiveObserverPicker }) => {
|
|
@@ -1918,7 +2023,8 @@ export class ChatPrompt {
|
|
|
1918
2023
|
punctuate: false
|
|
1919
2024
|
});
|
|
1920
2025
|
|
|
1921
|
-
const usageCardRows = this.usageCard ? renderUsageCardRows(this.usageCard,
|
|
2026
|
+
const usageCardRows = this.usageCard ? renderUsageCardRows(this.usageCard, boxWidth)
|
|
2027
|
+
: this.statusCard !== null ? this.statusCardRows(boxWidth) : [];
|
|
1922
2028
|
const planRows = this.planRows(width);
|
|
1923
2029
|
const pickerRows = this.completion ? this.pickerRows(width) : [];
|
|
1924
2030
|
this.pickerLayout = this.completion ? {
|