@causyne/agent 1.20.60 → 1.20.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +1 -1
  4. package/src/acp/agentCatalog.ts +1 -1
  5. package/src/acp/client.js +48 -0
  6. package/src/acp/client.ts +44 -0
  7. package/src/acp/peerProfiles.js +3 -3
  8. package/src/acp/peerProfiles.ts +3 -3
  9. package/src/agentLoop.js +239 -33
  10. package/src/agentLoop.ts +248 -36
  11. package/src/checkpoints.js +23 -5
  12. package/src/cliMode.js +13 -2
  13. package/src/commands.js +534 -78
  14. package/src/contextManager.d.ts +3 -0
  15. package/src/contextManager.js +78 -5
  16. package/src/cortex/autoCondenser.js +105 -145
  17. package/src/cortex/autoCondenser.ts +185 -0
  18. package/src/cortex/cortexEngine.js +179 -0
  19. package/src/cortex/cortexEngine.ts +209 -0
  20. package/src/cortex/provisioner.js +12 -14
  21. package/src/cortex/provisioner.ts +29 -0
  22. package/src/cortex/vectorDb.js +307 -386
  23. package/src/cortex/vectorDb.ts +473 -0
  24. package/src/decisionPolicy.js +18 -1
  25. package/src/decisionPolicy.ts +18 -1
  26. package/src/implementationPlan.js +26 -0
  27. package/src/implementationPlan.ts +25 -0
  28. package/src/observer/coldObserver.js +6 -1
  29. package/src/observer/coldObserver.ts +6 -1
  30. package/src/observer.js +24 -2
  31. package/src/observer.ts +24 -2
  32. package/src/providers/acp.js +2 -8
  33. package/src/providers/acp.ts +2 -8
  34. package/src/providers/antigravity.js +7 -10
  35. package/src/providers/antigravity.ts +7 -10
  36. package/src/reporting.js +30 -7
  37. package/src/sessionJournal.js +13 -0
  38. package/src/sessionJournal.ts +13 -0
  39. package/src/smartToolsUse.js +1 -1
  40. package/src/smartToolsUse.ts +1 -1
  41. package/src/tokenTracker.js +22 -0
  42. package/src/tokenTracker.ts +28 -0
  43. package/src/toolPacks.js +1 -1
  44. package/src/toolPacks.ts +1 -1
  45. package/src/tools/toolSelfRepair.js +51 -8
  46. package/src/tools/toolSelfRepair.ts +42 -9
  47. package/src/tui/CausyneRotor.js +234 -0
  48. package/src/tui/CausyneRotor.ts +280 -0
  49. package/src/tui/activityLayout.js +1 -1
  50. package/src/tui/activityLayout.ts +1 -1
  51. package/src/tui/chatRenderer.js +62 -9
  52. package/src/tui/chatboxClipboard.js +96 -10
  53. package/src/tui/chatboxClipboard.ts +121 -11
  54. package/src/tui/clipboardImage.js +308 -0
  55. package/src/tui/clipboardImage.ts +320 -0
  56. package/src/tui/codeStreamRenderer.js +89 -1
  57. package/src/tui/codeStreamRenderer.ts +109 -1
  58. package/src/tui/completion.js +34 -15
  59. package/src/tui/composerControls.js +5 -0
  60. package/src/tui/composerControls.ts +5 -0
  61. package/src/tui/dialogs.js +5 -2
  62. package/src/tui/engineSpinner.js +20 -0
  63. package/src/tui/engineSpinner.ts +46 -0
  64. package/src/tui/layout.js +1 -1
  65. package/src/tui/layout.ts +1 -1
  66. package/src/tui/lineEditor.js +44 -12
  67. package/src/tui/messageInteraction.js +16 -5
  68. package/src/tui/messageInteraction.ts +14 -5
  69. package/src/tui/observerPicker.js +319 -0
  70. package/src/tui/observerPicker.ts +382 -0
  71. package/src/tui/prompt.js +247 -55
  72. package/src/tui/runningLight.js +213 -0
  73. package/src/tui/runningLight.ts +271 -0
  74. package/src/tui/sessionSidebar.js +7 -1
  75. package/src/tui/sessionSidebar.ts +7 -1
  76. package/src/tui/stage.js +4 -4
  77. package/src/tui/stageSurface.js +27 -10
  78. package/src/tui/statusLine.js +27 -4
  79. package/src/tui/statusLine.ts +27 -4
  80. package/src/tui/theme.js +5 -2
  81. package/src/tui/thinkingBox.js +41 -10
  82. package/src/tui/thinkingBox.ts +43 -10
  83. package/src/tui/turnRail.js +155 -24
  84. package/src/tui/turnRail.ts +170 -22
  85. package/src/tui/usageCard.js +178 -0
  86. package/src/tui/usageCard.ts +240 -0
  87. package/src/utils/paths.js +30 -1
  88. package/src/utils/paths.ts +32 -1
  89. package/src/cortex/autoCondenser.d.ts +0 -2
  90. package/src/cortex/vectorDb.d.ts +0 -1
package/src/observer.js CHANGED
@@ -3,6 +3,22 @@ import path from 'node:path';
3
3
  import http from 'node:http';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { coldObserver } from './observer/coldObserver.js';
6
+ export function extractClaimedLocalUrls(text) {
7
+ if (!text)
8
+ return [];
9
+ const matches = text.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):\d+(?:\/[^\s)>'"`\]]*)?/gi) || [];
10
+ const unique = new Set();
11
+ for (const raw of matches) {
12
+ let end = raw.length;
13
+ while (end > 0 && '.,;:!?'.includes(raw[end - 1])) {
14
+ end--;
15
+ }
16
+ const cleaned = raw.slice(0, end);
17
+ if (cleaned)
18
+ unique.add(cleaned);
19
+ }
20
+ return [...unique];
21
+ }
6
22
  export class CausyneObserver {
7
23
  /**
8
24
  * Evaluates the current state of a task after a tool outcome or at a step boundary.
@@ -64,11 +80,14 @@ export class CausyneObserver {
64
80
  // Check if the agent claims completion
65
81
  if (context.agentClaim && context.agentClaim.trim()) {
66
82
  const claim = context.agentClaim.toLowerCase();
67
- const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b/i.test(claim);
83
+ const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b|\b(?:is\s+(?:running|live|available|listening|served)\s+(?:at|on)|application\s+is\s+running)\b/i.test(claim);
68
84
  if (claimsCompletion) {
69
85
  // Run deterministic verification checks based on domain
70
86
  const hasMutations = outcomes.some(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool));
71
- const hasPassingVerification = outcomes.some(o => o.success && o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command));
87
+ const hasPassingVerification = outcomes.some(o => o.success && (o.rendered === true ||
88
+ o.tool === 'browser_act' ||
89
+ o.tool === 'verify_local_web' ||
90
+ (o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))));
72
91
  if (hasMutations && !hasPassingVerification) {
73
92
  return {
74
93
  status: 'ready-to-verify',
@@ -166,11 +185,14 @@ export class CausyneObserver {
166
185
  return;
167
186
  }
168
187
  const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
188
+ res.resume();
169
189
  const expected = req.expectedStatus ?? 200;
170
190
  const ok = res.statusCode === expected || (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);
171
191
  const result = { verified: Boolean(ok) };
172
192
  if (typeof res.statusCode === 'number')
173
193
  result.statusCode = res.statusCode;
194
+ if (!ok)
195
+ result.error = `HTTP ${res.statusCode ?? 'unknown'}`;
174
196
  resolve(result);
175
197
  });
176
198
  clientReq.on('error', (err) => {
package/src/observer.ts CHANGED
@@ -61,6 +61,21 @@ export interface TaskObservationContext {
61
61
  toolHistory: readonly ToolOutcome[];
62
62
  }
63
63
 
64
+ export function extractClaimedLocalUrls(text: string): string[] {
65
+ if (!text) return [];
66
+ const matches = text.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):\d+(?:\/[^\s)>'"`\]]*)?/gi) || [];
67
+ const unique = new Set<string>();
68
+ for (const raw of matches) {
69
+ let end = raw.length;
70
+ while (end > 0 && '.,;:!?'.includes(raw[end - 1]!)) {
71
+ end--;
72
+ }
73
+ const cleaned = raw.slice(0, end);
74
+ if (cleaned) unique.add(cleaned);
75
+ }
76
+ return [...unique];
77
+ }
78
+
64
79
  export class CausyneObserver {
65
80
  /**
66
81
  * Evaluates the current state of a task after a tool outcome or at a step boundary.
@@ -127,7 +142,7 @@ export class CausyneObserver {
127
142
  // Check if the agent claims completion
128
143
  if (context.agentClaim && context.agentClaim.trim()) {
129
144
  const claim = context.agentClaim.toLowerCase();
130
- const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b/i.test(claim);
145
+ const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b|\b(?:is\s+(?:running|live|available|listening|served)\s+(?:at|on)|application\s+is\s+running)\b/i.test(claim);
131
146
 
132
147
  if (claimsCompletion) {
133
148
  // Run deterministic verification checks based on domain
@@ -135,7 +150,12 @@ export class CausyneObserver {
135
150
  ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)
136
151
  );
137
152
  const hasPassingVerification = outcomes.some(o =>
138
- o.success && o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command)
153
+ o.success && (
154
+ o.rendered === true ||
155
+ o.tool === 'browser_act' ||
156
+ o.tool === 'verify_local_web' ||
157
+ (o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))
158
+ )
139
159
  );
140
160
 
141
161
  if (hasMutations && !hasPassingVerification) {
@@ -248,10 +268,12 @@ export class CausyneObserver {
248
268
  }
249
269
 
250
270
  const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
271
+ res.resume();
251
272
  const expected = req.expectedStatus ?? 200;
252
273
  const ok = res.statusCode === expected || (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);
253
274
  const result: { verified: boolean; statusCode?: number; error?: string } = { verified: Boolean(ok) };
254
275
  if (typeof res.statusCode === 'number') result.statusCode = res.statusCode;
276
+ if (!ok) result.error = `HTTP ${res.statusCode ?? 'unknown'}`;
255
277
  resolve(result);
256
278
  });
257
279
 
@@ -9,7 +9,7 @@ import { BUILTIN_PEER_PRESETS } from '../acp/agentCatalog.js';
9
9
  import { createHash } from 'node:crypto';
10
10
  import path from 'node:path';
11
11
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
12
- import { extractToolCallJsonObjects, stripToolCallMarkup } from '../implementationPlan.js';
12
+ import { extractToolCallJsonObjects, stripToolCallMarkup, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
13
13
  function fingerprint(value) {
14
14
  return createHash('sha256').update(JSON.stringify(value)).digest('hex');
15
15
  }
@@ -250,13 +250,7 @@ export class AcpProvider extends LLMProvider {
250
250
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
251
251
  if (!name)
252
252
  continue;
253
- const rawArgs = parsed.arguments !== undefined
254
- ? parsed.arguments
255
- : parsed.parameters !== undefined
256
- ? parsed.parameters
257
- : parsed.input !== undefined
258
- ? parsed.input
259
- : (fnObj?.arguments ?? {});
253
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
260
254
  calls.push({
261
255
  id: `acp_call_${Date.now()}_${index++}`,
262
256
  type: 'function',
@@ -10,7 +10,7 @@ import type { RequestPermissionRequest, SessionUpdate, ToolKind } from '../acp/p
10
10
  import { createHash } from 'node:crypto';
11
11
  import path from 'node:path';
12
12
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
13
- import { extractToolCallJsonObjects, stripToolCallMarkup } from '../implementationPlan.js';
13
+ import { extractToolCallJsonObjects, stripToolCallMarkup, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
14
14
 
15
15
  interface AcpTransportSnapshot {
16
16
  conversationId: string;
@@ -271,13 +271,7 @@ export class AcpProvider extends LLMProvider {
271
271
  : null;
272
272
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
273
273
  if (!name) continue;
274
- const rawArgs = parsed.arguments !== undefined
275
- ? parsed.arguments
276
- : parsed.parameters !== undefined
277
- ? parsed.parameters
278
- : parsed.input !== undefined
279
- ? parsed.input
280
- : (fnObj?.arguments ?? {});
274
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
281
275
  calls.push({
282
276
  id: `acp_call_${Date.now()}_${index++}`,
283
277
  type: 'function',
@@ -17,7 +17,7 @@ import fs from 'node:fs';
17
17
  import path from 'node:path';
18
18
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
19
19
  import { LLMProvider } from './base.js';
20
- import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks } from '../implementationPlan.js';
20
+ import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
21
21
  /**
22
22
  * Baseline fallback models for instant offline availability.
23
23
  * Live models are autodetected dynamically from `agy models`
@@ -848,13 +848,7 @@ export class AntigravityProvider extends LLMProvider {
848
848
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
849
849
  if (!name)
850
850
  continue;
851
- const rawArgs = parsed.arguments !== undefined
852
- ? parsed.arguments
853
- : parsed.parameters !== undefined
854
- ? parsed.parameters
855
- : parsed.input !== undefined
856
- ? parsed.input
857
- : (fnObj?.arguments ?? {});
851
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
858
852
  calls.push({
859
853
  id: `agy_call_${Date.now()}_${index++}`,
860
854
  type: 'function',
@@ -944,7 +938,8 @@ export class AntigravityProvider extends LLMProvider {
944
938
  'Causyne provides native host tools for browser verification: `browser_act` (preview and snapshot) and `screenshot`/`vision_inspect_ui`. ' +
945
939
  'DO NOT write custom Node.js/Python headless Chrome or CDP WebSocket scripts to inspect console logs or take screenshots. ' +
946
940
  'Causyne automatically captures browser console errors and renders WebGL/Canvas with hardware acceleration. ' +
947
- 'Use <tool_call>{"name": "browser_act", "arguments": {"action": "preview", "filePath": "index.html"}}</tool_call> to verify rendered output directly.\n\n' + promptText;
941
+ 'Use <tool_call>{"name": "browser_act", "arguments": {"actions": [{"type": "preview", "filePath": "index.html"}, {"type": "snapshot"}]}}</tool_call> to verify rendered output directly. ' +
942
+ 'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
948
943
  }
949
944
  const modelSlug = resolveAgyModelId(this.model);
950
945
  const effort = resolveAgyEffort(this.model);
@@ -1306,7 +1301,9 @@ export class AntigravityProvider extends LLMProvider {
1306
1301
  ...(detail ? { detail } : {})
1307
1302
  };
1308
1303
  if (status !== 'running') {
1309
- const existing = nativeActions.find(a => a.name === action.name && a.detail === action.detail);
1304
+ const existing = nativeActions.find(a => action.id
1305
+ ? a.id === action.id
1306
+ : a.name === action.name && a.detail === action.detail);
1310
1307
  if (existing)
1311
1308
  existing.status = status;
1312
1309
  else
@@ -16,7 +16,7 @@ import fs from 'node:fs';
16
16
  import path from 'node:path';
17
17
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
18
18
  import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall, type ChatResponseUsage } from './base.js';
19
- import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks } from '../implementationPlan.js';
19
+ import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
20
20
 
21
21
  /**
22
22
  * Baseline fallback models for instant offline availability.
@@ -875,13 +875,7 @@ export class AntigravityProvider extends LLMProvider {
875
875
  : null;
876
876
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
877
877
  if (!name) continue;
878
- const rawArgs = parsed.arguments !== undefined
879
- ? parsed.arguments
880
- : parsed.parameters !== undefined
881
- ? parsed.parameters
882
- : parsed.input !== undefined
883
- ? parsed.input
884
- : (fnObj?.arguments ?? {});
878
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
885
879
  calls.push({
886
880
  id: `agy_call_${Date.now()}_${index++}`,
887
881
  type: 'function',
@@ -975,7 +969,8 @@ export class AntigravityProvider extends LLMProvider {
975
969
  'Causyne provides native host tools for browser verification: `browser_act` (preview and snapshot) and `screenshot`/`vision_inspect_ui`. ' +
976
970
  'DO NOT write custom Node.js/Python headless Chrome or CDP WebSocket scripts to inspect console logs or take screenshots. ' +
977
971
  'Causyne automatically captures browser console errors and renders WebGL/Canvas with hardware acceleration. ' +
978
- 'Use <tool_call>{"name": "browser_act", "arguments": {"action": "preview", "filePath": "index.html"}}</tool_call> to verify rendered output directly.\n\n' + promptText;
972
+ 'Use <tool_call>{"name": "browser_act", "arguments": {"actions": [{"type": "preview", "filePath": "index.html"}, {"type": "snapshot"}]}}</tool_call> to verify rendered output directly. ' +
973
+ 'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
979
974
  }
980
975
 
981
976
  const modelSlug = resolveAgyModelId(this.model);
@@ -1363,7 +1358,9 @@ export class AntigravityProvider extends LLMProvider {
1363
1358
  ...(detail ? { detail } : {})
1364
1359
  };
1365
1360
  if (status !== 'running') {
1366
- const existing = nativeActions.find(a => a.name === action.name && a.detail === action.detail);
1361
+ const existing = nativeActions.find(a => action.id
1362
+ ? a.id === action.id
1363
+ : a.name === action.name && a.detail === action.detail);
1367
1364
  if (existing) existing.status = status;
1368
1365
  else nativeActions.push(action);
1369
1366
  }
package/src/reporting.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { TOOL_DEFINITIONS } from './tools/registry.js';
4
4
  import { CORE_TOOLS, PACKS, PACK_PLAYBOOKS } from './toolPacks.js';
5
- import { resolveCharPool } from './contextManager.js';
5
+ import { resolveCharPool, resolveModelContextTokens } from './contextManager.js';
6
6
  import { TokenTracker } from './tokenTracker.js';
7
7
  import { loadConfig } from './config.js';
8
8
  import { listSpills, getOutputDir } from './outputStore.js';
@@ -53,7 +53,23 @@ function schemaTokens(names) {
53
53
  export function buildContextReport() {
54
54
  const config = loadConfig();
55
55
  const tier = config.tier || 'premium';
56
- const charPool = resolveCharPool(tier, config.contextCharPool);
56
+ const provider = config.provider || 'default';
57
+ const model = config.model || 'default';
58
+ const charPool = resolveCharPool(tier, config.contextCharPool, {
59
+ provider,
60
+ model,
61
+ overrideTokens: config.contextTokens || config.maxContextTokens
62
+ });
63
+
64
+ const modelTokens = resolveModelContextTokens({
65
+ provider,
66
+ model,
67
+ overrideTokens: config.contextTokens || config.maxContextTokens
68
+ });
69
+
70
+ const approxTokenPool = modelTokens > 0
71
+ ? modelTokens
72
+ : Math.round(charPool / APPROX_CHARS_PER_TOKEN);
57
73
 
58
74
  const packs = Object.entries(PACKS).map(([name, tools]) => ({
59
75
  name,
@@ -66,10 +82,10 @@ export function buildContextReport() {
66
82
 
67
83
  return {
68
84
  tier,
69
- provider: config.provider || 'default',
70
- model: config.model || 'default',
85
+ provider,
86
+ model,
71
87
  charPool,
72
- approxTokenPool: Math.round(charPool / APPROX_CHARS_PER_TOKEN),
88
+ approxTokenPool,
73
89
  core: { tools: CORE_TOOLS.length, tokens: schemaTokens(CORE_TOOLS) },
74
90
  packs,
75
91
  allTools: TOOL_DEFINITIONS.length,
@@ -124,7 +140,14 @@ export async function buildUsageText() {
124
140
  const budget = config.tokenBudget || {};
125
141
  const lines = [];
126
142
 
127
- lines.push('Token usage (BYOK — billed by your provider, not by Causyne)');
143
+ const provider = config.provider || 'default';
144
+ const isAgy = isAntigravityProvider(provider);
145
+ const isAcp = isAcpProvider(provider);
146
+ const billingNote = (isAgy || isAcp)
147
+ ? '(Local CLI / ACP peer)'
148
+ : '(BYOK — billed by your provider, not by Causyne)';
149
+
150
+ lines.push(`Token usage ${billingNote}`);
128
151
  lines.push(` Provider / model : ${config.provider || 'default'} / ${config.model || 'default'}`);
129
152
  lines.push(` This task : ${formatNumber(usage.taskTokens)} tokens $${Number(usage.taskCostUsd || 0).toFixed(4)}`);
130
153
  lines.push(` Today : ${formatNumber(usage.dailyTokens)} tokens $${Number(usage.costUsd || 0).toFixed(4)}`);
@@ -215,7 +238,7 @@ export function printCheckpoints(limit = 15) {
215
238
  * here, in one place, and each surface renders the single result it is given.
216
239
  */
217
240
  function runUndo(taskId, options = {}) {
218
- const opts = { dryRun: options.dryRun, full: options.full };
241
+ const opts = { dryRun: options.dryRun, full: options.full, workspaceRoot: options.workspaceRoot };
219
242
  return options.step
220
243
  ? undoStep({ dryRun: options.dryRun })
221
244
  : (taskId ? undoTask(taskId, opts) : undoLast(opts));
@@ -489,6 +489,19 @@ export function restoreSessionFromSnapshot(file, snapshot) {
489
489
  return false;
490
490
  }
491
491
  }
492
+ export function renameSession(id, newTitle) {
493
+ const session = readSession(id);
494
+ const cleanTitle = String(newTitle ?? '').trim();
495
+ if (!session || !cleanTitle)
496
+ return false;
497
+ return appendEvent(sessionTranscriptFile(session.id), {
498
+ version: 1,
499
+ type: 'messages.replaced',
500
+ at: Date.now(),
501
+ messages: session.messages,
502
+ title: cleanTitle
503
+ });
504
+ }
492
505
  export function deleteSession(id) {
493
506
  const safe = safeSessionId(id);
494
507
  if (!safe)
@@ -537,6 +537,19 @@ export function restoreSessionFromSnapshot(file: string, snapshot: Buffer): bool
537
537
  }
538
538
  }
539
539
 
540
+ export function renameSession(id: unknown, newTitle: string): boolean {
541
+ const session = readSession(id);
542
+ const cleanTitle = String(newTitle ?? '').trim();
543
+ if (!session || !cleanTitle) return false;
544
+ return appendEvent(sessionTranscriptFile(session.id), {
545
+ version: 1,
546
+ type: 'messages.replaced',
547
+ at: Date.now(),
548
+ messages: session.messages,
549
+ title: cleanTitle
550
+ });
551
+ }
552
+
540
553
  export function deleteSession(id: unknown): boolean {
541
554
  const safe = safeSessionId(id);
542
555
  if (!safe) return false;
@@ -131,7 +131,7 @@ const SIMPLE_FILE_OP_PATTERN = /\b(list (the )?files|show files|count files|rena
131
131
  // Media generation intent (explicit creation of 3D, video, audio, or synthesized speech)
132
132
  const EXPLICIT_MEDIA_GENERATION_PATTERN = /\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b|\.(blend\d*|psd|prproj|aep|ai|indd|ccx)\b/i;
133
133
  // Explicit web engineering intent
134
- const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|thre\.?js|3js|webgl|canvas)\b/i;
134
+ const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*(?:\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|webgl|canvas|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:threejs|three\.js|thre\.?js|3js|babylon\.?js|pixi\.js|d3\.js|p5\.js|chart\.js)\b)/i;
135
135
  // Explicit game development intent
136
136
  const EXPLICIT_GAME_DEV_PATTERN = /(?:\b(?:build|create|make|design|develop|scaffold|render|animate|code|program|buat\w*|bikin\w*)[\s\S]*(?:game|simulation|simulator|simulasi|interactive|3d|three\.?js|threejs|webgl|canvas3d|babylonjs|godot|unity|unreal|platformer|rpg|arcade)\b|\b(?:game|gamedev|godot|unity|unreal|platformer|rpg|arcade|simulator|simulation|simulasi|interactive)\b|\b3d\s*(?:game|app|simulator|simulation|scene|city|world|view|body|human|anatomy|model|mesh|character|rendering|visualization|experience|space|environment)\b|\bin 3d\b|[-_]3d\b|\b3d[-_]|\b(?:threejs|three\.js|webgl|canvas3d|babylonjs)\b)/i;
137
137
  // Explicit reverse engineering and binary analysis intent
@@ -175,7 +175,7 @@ const EXPLICIT_MEDIA_GENERATION_PATTERN =
175
175
 
176
176
  // Explicit web engineering intent
177
177
  const EXPLICIT_WEB_ENGINEERING_PATTERN =
178
- /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|thre\.?js|3js|webgl|canvas)\b/i;
178
+ /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*(?:\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|webgl|canvas|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:threejs|three\.js|thre\.?js|3js|babylon\.?js|pixi\.js|d3\.js|p5\.js|chart\.js)\b)/i;
179
179
 
180
180
  // Explicit game development intent
181
181
  const EXPLICIT_GAME_DEV_PATTERN =
@@ -24,12 +24,16 @@ export class TokenTracker {
24
24
  budget;
25
25
  taskTokens;
26
26
  taskCostUsd;
27
+ sessionTokens;
28
+ sessionCostUsd;
27
29
  largestStepTokens;
28
30
  constructor() {
29
31
  this.config = loadConfig();
30
32
  this.budget = this.config.tokenBudget || { enabled: false };
31
33
  this.taskTokens = 0;
32
34
  this.taskCostUsd = 0;
35
+ this.sessionTokens = 0;
36
+ this.sessionCostUsd = 0;
33
37
  this.largestStepTokens = 0;
34
38
  this.ensureUsageDir();
35
39
  }
@@ -178,7 +182,9 @@ export class TokenTracker {
178
182
  const cost = unitPrice * (quantityUnits || 1);
179
183
  const equivalentTokens = Math.round(cost / 0.000002);
180
184
  this.taskTokens += equivalentTokens;
185
+ this.sessionTokens = (this.sessionTokens || 0) + equivalentTokens;
181
186
  this.taskCostUsd += cost;
187
+ this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
182
188
  const cumulative = await this.getCumulativeUsage();
183
189
  const daily = await this.getDailyUsage();
184
190
  daily.totalTokens += equivalentTokens;
@@ -313,9 +319,11 @@ export class TokenTracker {
313
319
  usedTokens: daily.totalTokens,
314
320
  dailyTokens: daily.totalTokens,
315
321
  taskTokens: this.taskTokens,
322
+ sessionTokens: this.sessionTokens || this.taskTokens || 0,
316
323
  lifetimeTokens: cumulative.totalTokens,
317
324
  costUsd: daily.totalCostUsd,
318
325
  taskCostUsd: this.taskCostUsd,
326
+ sessionCostUsd: this.sessionCostUsd || this.taskCostUsd || 0,
319
327
  lifetimeCostUsd: cumulative.totalCostUsd,
320
328
  isDemo: false
321
329
  };
@@ -351,12 +359,24 @@ export class TokenTracker {
351
359
  this.taskCostUsd = 0;
352
360
  this.largestStepTokens = 0;
353
361
  }
362
+ resetSession() {
363
+ this.sessionTokens = 0;
364
+ this.sessionCostUsd = 0;
365
+ this.taskTokens = 0;
366
+ this.taskCostUsd = 0;
367
+ this.largestStepTokens = 0;
368
+ }
369
+ reset() {
370
+ this.resetSession();
371
+ }
354
372
  settle(extra, daily, cumulative) {
355
373
  return {
356
374
  usedTokens: daily.totalTokens,
357
375
  dailyTokens: daily.totalTokens,
358
376
  dailyCostUsd: daily.totalCostUsd || 0,
359
377
  dailyLimit: Number(this.budget && this.budget.maxTokensPerDay) || 0,
378
+ sessionTokens: this.sessionTokens || this.taskTokens || 0,
379
+ sessionCostUsd: this.sessionCostUsd || this.taskCostUsd || 0,
360
380
  taskTokens: this.taskTokens,
361
381
  taskCostUsd: this.taskCostUsd,
362
382
  taskLimit: Number(this.budget && this.budget.maxTokensPerTask) || 0,
@@ -393,9 +413,11 @@ export class TokenTracker {
393
413
  }
394
414
  const freshStep = freshInput + cTokens;
395
415
  this.taskTokens += freshStep;
416
+ this.sessionTokens = (this.sessionTokens || 0) + freshStep;
396
417
  this.largestStepTokens = Math.max(this.largestStepTokens || 0, freshStep);
397
418
  const cost = this.calculateCost(promptTokens, completionTokens, usageDetail);
398
419
  this.taskCostUsd += cost;
420
+ this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
399
421
  const { daily, cumulative } = await withUsageLock(async () => {
400
422
  const cumulative = await this.getCumulativeUsage();
401
423
  const daily = await this.getDailyUsage();
@@ -85,6 +85,8 @@ export interface SettledUsage {
85
85
  dailyTokens: number;
86
86
  dailyCostUsd: number;
87
87
  dailyLimit: number;
88
+ sessionTokens?: number;
89
+ sessionCostUsd?: number;
88
90
  taskTokens: number;
89
91
  taskCostUsd: number;
90
92
  taskLimit: number;
@@ -102,6 +104,8 @@ export class TokenTracker {
102
104
  budget: TokenBudgetConfig;
103
105
  taskTokens: number;
104
106
  taskCostUsd: number;
107
+ sessionTokens: number;
108
+ sessionCostUsd: number;
105
109
  largestStepTokens: number;
106
110
 
107
111
  constructor() {
@@ -109,6 +113,8 @@ export class TokenTracker {
109
113
  this.budget = this.config.tokenBudget || { enabled: false };
110
114
  this.taskTokens = 0;
111
115
  this.taskCostUsd = 0;
116
+ this.sessionTokens = 0;
117
+ this.sessionCostUsd = 0;
112
118
  this.largestStepTokens = 0;
113
119
  this.ensureUsageDir();
114
120
  }
@@ -261,7 +267,9 @@ export class TokenTracker {
261
267
  const equivalentTokens = Math.round(cost / 0.000002);
262
268
 
263
269
  this.taskTokens += equivalentTokens;
270
+ this.sessionTokens = (this.sessionTokens || 0) + equivalentTokens;
264
271
  this.taskCostUsd += cost;
272
+ this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
265
273
 
266
274
  const cumulative = await this.getCumulativeUsage();
267
275
  const daily = await this.getDailyUsage();
@@ -408,9 +416,11 @@ export class TokenTracker {
408
416
  usedTokens: number;
409
417
  dailyTokens: number;
410
418
  taskTokens: number;
419
+ sessionTokens: number;
411
420
  lifetimeTokens: number;
412
421
  costUsd: number;
413
422
  taskCostUsd: number;
423
+ sessionCostUsd: number;
414
424
  lifetimeCostUsd: number;
415
425
  isDemo: boolean;
416
426
  }> {
@@ -420,9 +430,11 @@ export class TokenTracker {
420
430
  usedTokens: daily.totalTokens,
421
431
  dailyTokens: daily.totalTokens,
422
432
  taskTokens: this.taskTokens,
433
+ sessionTokens: this.sessionTokens || this.taskTokens || 0,
423
434
  lifetimeTokens: cumulative.totalTokens,
424
435
  costUsd: daily.totalCostUsd,
425
436
  taskCostUsd: this.taskCostUsd,
437
+ sessionCostUsd: this.sessionCostUsd || this.taskCostUsd || 0,
426
438
  lifetimeCostUsd: cumulative.totalCostUsd,
427
439
  isDemo: false
428
440
  };
@@ -462,12 +474,26 @@ export class TokenTracker {
462
474
  this.largestStepTokens = 0;
463
475
  }
464
476
 
477
+ resetSession(): void {
478
+ this.sessionTokens = 0;
479
+ this.sessionCostUsd = 0;
480
+ this.taskTokens = 0;
481
+ this.taskCostUsd = 0;
482
+ this.largestStepTokens = 0;
483
+ }
484
+
485
+ reset(): void {
486
+ this.resetSession();
487
+ }
488
+
465
489
  settle(extra: Record<string, unknown>, daily: DailyUsage, cumulative: CumulativeUsage): SettledUsage {
466
490
  return {
467
491
  usedTokens: daily.totalTokens,
468
492
  dailyTokens: daily.totalTokens,
469
493
  dailyCostUsd: daily.totalCostUsd || 0,
470
494
  dailyLimit: Number(this.budget && this.budget.maxTokensPerDay) || 0,
495
+ sessionTokens: this.sessionTokens || this.taskTokens || 0,
496
+ sessionCostUsd: this.sessionCostUsd || this.taskCostUsd || 0,
471
497
  taskTokens: this.taskTokens,
472
498
  taskCostUsd: this.taskCostUsd,
473
499
  taskLimit: Number(this.budget && this.budget.maxTokensPerTask) || 0,
@@ -511,10 +537,12 @@ export class TokenTracker {
511
537
  const freshStep = freshInput + cTokens;
512
538
 
513
539
  this.taskTokens += freshStep;
540
+ this.sessionTokens = (this.sessionTokens || 0) + freshStep;
514
541
  this.largestStepTokens = Math.max(this.largestStepTokens || 0, freshStep);
515
542
 
516
543
  const cost = this.calculateCost(promptTokens, completionTokens, usageDetail);
517
544
  this.taskCostUsd += cost;
545
+ this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
518
546
 
519
547
  const { daily, cumulative } = await withUsageLock(async () => {
520
548
  const cumulative = await this.getCumulativeUsage();
package/src/toolPacks.js CHANGED
@@ -331,7 +331,7 @@ When the user asks you to build, create, test, expand, or develop a game, follow
331
331
  // raw prompt only.
332
332
  // ---------------------------------------------------------------------------
333
333
  const GAME_INTENT = /\b(game|games|gamedev|godot|unity|unreal|ue5|rpg|platformer|roguelike|arcade|sprite|spritesheet|tilemap|voxel|minecraft|aetheria|voxellia|nes|snes|gameplay|player character|level design|boss fight|simulator|simulation|simulasi)\b|\.(tscn|gd|uproject|umap)\b|[-_]3d\b|\b3d[-_]/i;
334
- const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|three?\.?js|three?js|webgl|canvas|babylon)\b/i;
334
+ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|html5|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|webgl|canvas|babylon|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:three\.js|threejs|thre\.js|3js|webgl|babylon\.js|babylonjs|pixi\.js|d3\.js|p5\.js|chart\.js)\b/i;
335
335
  const MEDIA_INTENT = /\b(image|images|picture|photo|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b|\.(psd|prproj|aep|ai|indd|ccx)\b/i;
336
336
  const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|open in browser|launch app|computer use|vision grounding|desktop vision|gui agent|coordinate click|desktop control)\b/i;
337
337
  const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|plugins? factory|python bridge|mcp|mcp server|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
package/src/toolPacks.ts CHANGED
@@ -372,7 +372,7 @@ When the user asks you to build, create, test, expand, or develop a game, follow
372
372
 
373
373
  const GAME_INTENT = /\b(game|games|gamedev|godot|unity|unreal|ue5|rpg|platformer|roguelike|arcade|sprite|spritesheet|tilemap|voxel|minecraft|aetheria|voxellia|nes|snes|gameplay|player character|level design|boss fight|simulator|simulation|simulasi)\b|\.(tscn|gd|uproject|umap)\b|[-_]3d\b|\b3d[-_]/i;
374
374
 
375
- const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|three?\.?js|three?js|webgl|canvas|babylon)\b/i;
375
+ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|html5|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|webgl|canvas|babylon|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:three\.js|threejs|thre\.js|3js|webgl|babylon\.js|babylonjs|pixi\.js|d3\.js|p5\.js|chart\.js)\b/i;
376
376
 
377
377
  const MEDIA_INTENT = /\b(image|images|picture|photo|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b|\.(psd|prproj|aep|ai|indd|ccx)\b/i;
378
378