@causyne/agent 1.20.9 → 1.20.10

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 (47) hide show
  1. package/package.json +2 -1
  2. package/src/agentLoop.js +127 -72
  3. package/src/agentLoop.ts +137 -75
  4. package/src/browser/causyneBrowser.js +36 -0
  5. package/src/browser/causyneBrowser.ts +36 -1
  6. package/src/commands.js +25 -0
  7. package/src/contextManager.js +16 -0
  8. package/src/providers/antigravity.js +74 -11
  9. package/src/providers/antigravity.ts +77 -12
  10. package/src/provisioning/capabilityProvisioner.js +2 -7
  11. package/src/provisioning/npmInstall.js +19 -0
  12. package/src/provisioning/npmInstall.ts +19 -0
  13. package/src/smartToolsUse.js +20 -0
  14. package/src/smartToolsUse.ts +21 -0
  15. package/src/stallGuard.js +356 -0
  16. package/src/stallGuard.ts +432 -0
  17. package/src/tools/browserAutomator.js +3 -3
  18. package/src/tools/browserAutomator.ts +3 -3
  19. package/src/tools/fsRead.js +91 -80
  20. package/src/tools/fsRead.ts +125 -0
  21. package/src/tools/peerAgent.js +1 -1
  22. package/src/tools/peerAgent.ts +1 -1
  23. package/src/tools/screenshot.js +5 -1
  24. package/src/tools/screenshot.ts +5 -1
  25. package/src/tools/toolScanner.js +19 -0
  26. package/src/tools/toolScanner.ts +17 -0
  27. package/src/tools/toolSelfRepair.js +63 -1
  28. package/src/tools/toolSelfRepair.ts +61 -1
  29. package/src/tools/visionInspector.js +80 -142
  30. package/src/tools/visionInspector.ts +110 -0
  31. package/src/tui/chatboxClipboard.js +152 -0
  32. package/src/tui/chatboxClipboard.ts +201 -0
  33. package/src/tui/clipboardSync.js +38 -7
  34. package/src/tui/clipboardSync.ts +39 -7
  35. package/src/tui/codeProgress.js +89 -18
  36. package/src/tui/codeProgress.ts +102 -17
  37. package/src/tui/codeStreamRenderer.js +7 -2
  38. package/src/tui/codeStreamRenderer.ts +7 -2
  39. package/src/tui/composerControls.js +9 -0
  40. package/src/tui/composerControls.ts +9 -0
  41. package/src/tui/dialogs.js +8 -3
  42. package/src/tui/diff.d.ts +1 -0
  43. package/src/tui/lineEditor.js +166 -14
  44. package/src/tui/mouseHover.js +6 -2
  45. package/src/tui/mouseHover.ts +7 -2
  46. package/src/tui/prompt.js +96 -19
  47. package/src/tui/stageSurface.js +3 -1
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
5
+ import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
6
  import { LLMProvider } from './base.js';
6
7
  /**
7
8
  * Baseline fallback models for instant offline availability.
@@ -272,6 +273,21 @@ function describeNativeAction(toolInfo) {
272
273
  }
273
274
  return undefined;
274
275
  }
276
+ export function isReadOnlyNativeInspection(name, parameters) {
277
+ const action = name.toLowerCase().replace(/[_\s-]/g, '');
278
+ if (/^(readfile|listdirectory|listfiles|search|searchweb|grep|findfiles)$/.test(action))
279
+ return true;
280
+ if (!/^(runcommand|command|sysrun|terminal|bash|shell)$/.test(action))
281
+ return false;
282
+ const command = String(parameters.CommandLine ?? parameters.command ?? parameters.cmd ?? '').trim();
283
+ // A compound shell command can inspect and then mutate; do not count it as
284
+ // read-only merely because its first command is a probe.
285
+ if (!/[;&|]/.test(command) && /^(?:ls|rg|grep|head|tail|cat|ps|pgrep|which|file|sips|mdls)\b/.test(command))
286
+ return true;
287
+ return /\bblender\b.*--python-expr\b/is.test(command)
288
+ && /\bprint\s*\(/.test(command)
289
+ && !/\b(?:save_as_mainfile|save|render|write|unlink|remove|delete)\b/.test(command);
290
+ }
275
291
  export function mapNativeToolToCausyne(name, rawParams, index) {
276
292
  if (!name || typeof name !== 'string')
277
293
  return null;
@@ -498,7 +514,10 @@ export class AntigravityProvider extends LLMProvider {
498
514
  this.printTimeout = typeof config.printTimeout === 'string' && config.printTimeout.trim()
499
515
  ? config.printTimeout.trim()
500
516
  : '1800s';
501
- this.visionModels = ['*'];
517
+ // This ACP bridge currently sends text-only stream-json messages. Image
518
+ // blocks are reduced to labels in formatDelta/formatConversation, so do
519
+ // not advertise vision or ask for desktop capture as proof of inspection.
520
+ this.visionModels = [];
502
521
  this.audioModels = [];
503
522
  }
504
523
  formatDelta(messages) {
@@ -561,16 +580,21 @@ export class AntigravityProvider extends LLMProvider {
561
580
  ' - Immediately open the URL or project in the user\'s browser using desktop.open with {"target": "http://localhost:<port>"} or run the native open command.\n' +
562
581
  ' - Confirm the application is accessible only after a readiness check succeeds.\n' +
563
582
  '3. NEVER reply with conversational pleasantries, canned greetings (e.g. "How can I help you today?"), or ask what the user wants when an instruction has already been provided.\n' +
564
- '4. Create or edit files only when the current user request authorizes it.\n\n' +
583
+ '4. Create or edit files only when the current user request authorizes it.\n' +
584
+ '5. TOKEN CONSERVATION & MEDIA DIRECTIVE:\n' +
585
+ ' - NEVER attempt to read binary or media files (.png, .jpg, .blend, .glb, .wasm, .zip, etc.) using text reading tools like read_file or cat. This blows up the token context.\n' +
586
+ ' - For 3D modeling, Blender, or media tasks: write a single self-contained generator script and execute it in one batch. Avoid dozens of speculative CLI exploration commands.\n' +
587
+ ' - Use a model-readable image channel for visual verification when available. This text-only bridge does not deliver screenshot pixels to you; a saved image or file metadata proves the file exists, not how it looks. Report visual verification as unavailable when no image channel is present.\n\n' +
565
588
  '[Environment State & Idempotency Directive]\n' +
566
589
  'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
567
590
  '[Language & Communication Directive]\n' +
568
591
  'Dynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language. Never send conversational pleasantries or canned greetings.');
569
592
  if (tools && tools.length > 0) {
570
- const toolSummaries = tools.map(t => {
571
- const name = t.name || t.function?.name || 'unknown';
572
- const desc = t.description || t.function?.description || '';
573
- const params = t.parameters || t.input_schema || t.function?.parameters || {};
593
+ const scanReport = scanAndAdaptToolsForProvider(tools, 'antigravity');
594
+ const toolSummaries = scanReport.adaptedTools.map((t) => {
595
+ const name = t.name || 'unknown';
596
+ const desc = t.description || '';
597
+ const params = t.parameters || {};
574
598
  const paramKeys = Object.keys(params.properties || {}).join(', ');
575
599
  return `- ${name}(${paramKeys}): ${desc}`;
576
600
  }).join('\n');
@@ -843,6 +867,7 @@ export class AntigravityProvider extends LLMProvider {
843
867
  };
844
868
  const maxNativeActions = desktopTask ? 12 : Infinity;
845
869
  let nativeActionStarts = 0;
870
+ let consecutiveInspections = 0;
846
871
  const seenNativeActionSteps = new Set();
847
872
  // Antigravity's result usage is cumulative across the conversation, but
848
873
  // DONE step updates carry usage for that step. Keep a turn-local subtotal
@@ -852,8 +877,15 @@ export class AntigravityProvider extends LLMProvider {
852
877
  promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0,
853
878
  thinkingTokens: 0, measurement: 'provider_reported', cacheMeasurement: 'provider_reported'
854
879
  };
855
- const tokenLimit = Number(options.maxTokensThisCall);
856
- const enforceTokenLimit = Number.isFinite(tokenLimit) && tokenLimit > 0;
880
+ // A headless peer can run many paid model steps before chat() returns.
881
+ // Keep a finite per-call ceiling even when the optional task budget is
882
+ // disabled. Users can set a lower task budget through the existing UI.
883
+ const remainingTaskBudget = Number(options.maxTokensThisCall);
884
+ const tokenLimit = Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0
885
+ ? remainingTaskBudget
886
+ : (typeof options.tokenLimit === 'number' && options.tokenLimit > 0
887
+ ? options.tokenLimit
888
+ : 100_000);
857
889
  const wallTimer = desktopTask ? setTimeout(() => {
858
890
  const error = new Error('Antigravity exceeded the 180-second desktop task limit. Outcome is unverified.');
859
891
  error.code = 'AGY_DESKTOP_TASK_LIMIT';
@@ -872,6 +904,24 @@ export class AntigravityProvider extends LLMProvider {
872
904
  if (isSettled)
873
905
  return;
874
906
  isSettled = true;
907
+ // Failed native turns can have already consumed several model steps.
908
+ // Preserve their reported usage for the outer task ledger and prevent
909
+ // the provider from silently replaying a paid turn.
910
+ if (partialUsage.promptTokens + partialUsage.completionTokens > 0) {
911
+ Object.assign(err, { partialUsage: { ...partialUsage } });
912
+ if ((err.code === 'AGY_EXPLORATION_LOOP'
913
+ || err.code === 'AGY_TOKEN_BUDGET') && this.currentConversationId) {
914
+ const prior = resumedConversationId === this.lastCumulativeUsage?.conversationId
915
+ ? this.lastCumulativeUsage : null;
916
+ this.lastCumulativeUsage = {
917
+ conversationId: this.currentConversationId,
918
+ input: (prior?.input || 0) + partialUsage.promptTokens,
919
+ output: (prior?.output || 0) + partialUsage.completionTokens,
920
+ thinking: (prior?.thinking || 0) + (partialUsage.thinkingTokens || 0),
921
+ cacheRead: (prior?.cacheRead || 0) + (partialUsage.cachedPromptTokens || 0)
922
+ };
923
+ }
924
+ }
875
925
  cleanup();
876
926
  reject(err);
877
927
  };
@@ -938,9 +988,9 @@ export class AntigravityProvider extends LLMProvider {
938
988
  + (Number(usage.cache_read_tokens) || 0);
939
989
  partialUsage.thinkingTokens = (partialUsage.thinkingTokens || 0)
940
990
  + (Number(usage.thinking_tokens) || 0);
941
- if (enforceTokenLimit && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
942
- this.currentConversationId = null;
943
- const error = Object.assign(new Error(`Antigravity token budget reached during this turn: at least ${partialUsage.promptTokens + partialUsage.completionTokens} tokens reported for a ${tokenLimit}-token remaining budget. The task outcome is unverified.`), { code: 'AGY_TOKEN_BUDGET', partialUsage: { ...partialUsage } });
991
+ if (Number.isFinite(tokenLimit) && tokenLimit > 0
992
+ && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
993
+ const error = Object.assign(new Error(`Antigravity reported at least ${partialUsage.promptTokens + partialUsage.completionTokens} noncached tokens against a ${tokenLimit}-token per-call ceiling. This turn stopped and its outcome is unverified.`), { code: 'AGY_TOKEN_BUDGET', tokenLimit, partialUsage: { ...partialUsage } });
944
994
  safeReject(error);
945
995
  terminateChild();
946
996
  return;
@@ -972,6 +1022,16 @@ export class AntigravityProvider extends LLMProvider {
972
1022
  (stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
973
1023
  (toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
974
1024
  {};
1025
+ if (options.taskArchetype === 'media_3d_generation' && newNativeAction && name) {
1026
+ consecutiveInspections = isReadOnlyNativeInspection(String(name), rawParams)
1027
+ ? consecutiveInspections + 1 : 0;
1028
+ if (consecutiveInspections >= 10) {
1029
+ const error = Object.assign(new Error('Antigravity made 10 consecutive read-only media inspections without a change. Pausing to redirect the task before further token use.'), { code: 'AGY_EXPLORATION_LOOP', inspectionCount: consecutiveInspections });
1030
+ safeReject(error);
1031
+ terminateChild();
1032
+ return;
1033
+ }
1034
+ }
975
1035
  if (name) {
976
1036
  const existingAttempt = attemptedNativeTools.find(a => a.name === name && a.status === 'running');
977
1037
  if (existingAttempt) {
@@ -1233,6 +1293,9 @@ export class AntigravityProvider extends LLMProvider {
1233
1293
  if (options.signal?.aborted || err?.name === 'AbortError') {
1234
1294
  throw err;
1235
1295
  }
1296
+ if (err?.partialUsage?.promptTokens + err?.partialUsage?.completionTokens > 0) {
1297
+ throw err;
1298
+ }
1236
1299
  const canRetryResetConversation = hadConversation && !this.currentConversationId
1237
1300
  && err?.code !== 'AGY_NATIVE_ACTION_DENIED'
1238
1301
  && err?.code !== 'AGY_TOKEN_BUDGET';
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
5
+ import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
6
  import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall, type ChatResponseUsage } from './base.js';
6
7
 
7
8
  /**
@@ -275,6 +276,19 @@ function describeNativeAction(toolInfo: any): string | undefined {
275
276
  return undefined;
276
277
  }
277
278
 
279
+ export function isReadOnlyNativeInspection(name: string, parameters: Record<string, unknown>): boolean {
280
+ const action = name.toLowerCase().replace(/[_\s-]/g, '');
281
+ if (/^(readfile|listdirectory|listfiles|search|searchweb|grep|findfiles)$/.test(action)) return true;
282
+ if (!/^(runcommand|command|sysrun|terminal|bash|shell)$/.test(action)) return false;
283
+ const command = String(parameters.CommandLine ?? parameters.command ?? parameters.cmd ?? '').trim();
284
+ // A compound shell command can inspect and then mutate; do not count it as
285
+ // read-only merely because its first command is a probe.
286
+ if (!/[;&|]/.test(command) && /^(?:ls|rg|grep|head|tail|cat|ps|pgrep|which|file|sips|mdls)\b/.test(command)) return true;
287
+ return /\bblender\b.*--python-expr\b/is.test(command)
288
+ && /\bprint\s*\(/.test(command)
289
+ && !/\b(?:save_as_mainfile|save|render|write|unlink|remove|delete)\b/.test(command);
290
+ }
291
+
278
292
  export function mapNativeToolToCausyne(
279
293
  name: string,
280
294
  rawParams: Record<string, any>,
@@ -516,7 +530,10 @@ export class AntigravityProvider extends LLMProvider {
516
530
  this.printTimeout = typeof config.printTimeout === 'string' && config.printTimeout.trim()
517
531
  ? config.printTimeout.trim()
518
532
  : '1800s';
519
- this.visionModels = ['*'];
533
+ // This ACP bridge currently sends text-only stream-json messages. Image
534
+ // blocks are reduced to labels in formatDelta/formatConversation, so do
535
+ // not advertise vision or ask for desktop capture as proof of inspection.
536
+ this.visionModels = [];
520
537
  this.audioModels = [];
521
538
  }
522
539
 
@@ -583,7 +600,11 @@ export class AntigravityProvider extends LLMProvider {
583
600
  ' - Immediately open the URL or project in the user\'s browser using desktop.open with {"target": "http://localhost:<port>"} or run the native open command.\n' +
584
601
  ' - Confirm the application is accessible only after a readiness check succeeds.\n' +
585
602
  '3. NEVER reply with conversational pleasantries, canned greetings (e.g. "How can I help you today?"), or ask what the user wants when an instruction has already been provided.\n' +
586
- '4. Create or edit files only when the current user request authorizes it.\n\n' +
603
+ '4. Create or edit files only when the current user request authorizes it.\n' +
604
+ '5. TOKEN CONSERVATION & MEDIA DIRECTIVE:\n' +
605
+ ' - NEVER attempt to read binary or media files (.png, .jpg, .blend, .glb, .wasm, .zip, etc.) using text reading tools like read_file or cat. This blows up the token context.\n' +
606
+ ' - For 3D modeling, Blender, or media tasks: write a single self-contained generator script and execute it in one batch. Avoid dozens of speculative CLI exploration commands.\n' +
607
+ ' - Use a model-readable image channel for visual verification when available. This text-only bridge does not deliver screenshot pixels to you; a saved image or file metadata proves the file exists, not how it looks. Report visual verification as unavailable when no image channel is present.\n\n' +
587
608
  '[Environment State & Idempotency Directive]\n' +
588
609
  'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
589
610
  '[Language & Communication Directive]\n' +
@@ -591,10 +612,11 @@ export class AntigravityProvider extends LLMProvider {
591
612
  );
592
613
 
593
614
  if (tools && tools.length > 0) {
594
- const toolSummaries = tools.map(t => {
595
- const name = t.name || t.function?.name || 'unknown';
596
- const desc = t.description || t.function?.description || '';
597
- const params = t.parameters || t.input_schema || t.function?.parameters || {};
615
+ const scanReport = scanAndAdaptToolsForProvider(tools, 'antigravity');
616
+ const toolSummaries = scanReport.adaptedTools.map((t: any) => {
617
+ const name = t.name || 'unknown';
618
+ const desc = t.description || '';
619
+ const params = t.parameters || {};
598
620
  const paramKeys = Object.keys(params.properties || {}).join(', ');
599
621
  return `- ${name}(${paramKeys}): ${desc}`;
600
622
  }).join('\n');
@@ -883,6 +905,7 @@ export class AntigravityProvider extends LLMProvider {
883
905
  };
884
906
  const maxNativeActions = desktopTask ? 12 : Infinity;
885
907
  let nativeActionStarts = 0;
908
+ let consecutiveInspections = 0;
886
909
  const seenNativeActionSteps = new Set<number>();
887
910
  // Antigravity's result usage is cumulative across the conversation, but
888
911
  // DONE step updates carry usage for that step. Keep a turn-local subtotal
@@ -892,8 +915,15 @@ export class AntigravityProvider extends LLMProvider {
892
915
  promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0,
893
916
  thinkingTokens: 0, measurement: 'provider_reported', cacheMeasurement: 'provider_reported'
894
917
  };
895
- const tokenLimit = Number(options.maxTokensThisCall);
896
- const enforceTokenLimit = Number.isFinite(tokenLimit) && tokenLimit > 0;
918
+ // A headless peer can run many paid model steps before chat() returns.
919
+ // Keep a finite per-call ceiling even when the optional task budget is
920
+ // disabled. Users can set a lower task budget through the existing UI.
921
+ const remainingTaskBudget = Number(options.maxTokensThisCall);
922
+ const tokenLimit = Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0
923
+ ? remainingTaskBudget
924
+ : (typeof (options as any).tokenLimit === 'number' && (options as any).tokenLimit > 0
925
+ ? (options as any).tokenLimit
926
+ : 100_000);
897
927
  const wallTimer = desktopTask ? setTimeout(() => {
898
928
  const error = new Error('Antigravity exceeded the 180-second desktop task limit. Outcome is unverified.') as Error & { code: string };
899
929
  error.code = 'AGY_DESKTOP_TASK_LIMIT';
@@ -912,6 +942,24 @@ export class AntigravityProvider extends LLMProvider {
912
942
  const safeReject = (err: Error) => {
913
943
  if (isSettled) return;
914
944
  isSettled = true;
945
+ // Failed native turns can have already consumed several model steps.
946
+ // Preserve their reported usage for the outer task ledger and prevent
947
+ // the provider from silently replaying a paid turn.
948
+ if (partialUsage.promptTokens + partialUsage.completionTokens > 0) {
949
+ Object.assign(err, { partialUsage: { ...partialUsage } });
950
+ if (((err as Error & { code?: string }).code === 'AGY_EXPLORATION_LOOP'
951
+ || (err as Error & { code?: string }).code === 'AGY_TOKEN_BUDGET') && this.currentConversationId) {
952
+ const prior = resumedConversationId === this.lastCumulativeUsage?.conversationId
953
+ ? this.lastCumulativeUsage : null;
954
+ this.lastCumulativeUsage = {
955
+ conversationId: this.currentConversationId,
956
+ input: (prior?.input || 0) + partialUsage.promptTokens,
957
+ output: (prior?.output || 0) + partialUsage.completionTokens,
958
+ thinking: (prior?.thinking || 0) + (partialUsage.thinkingTokens || 0),
959
+ cacheRead: (prior?.cacheRead || 0) + (partialUsage.cachedPromptTokens || 0)
960
+ };
961
+ }
962
+ }
915
963
  cleanup();
916
964
  reject(err);
917
965
  };
@@ -981,11 +1029,11 @@ export class AntigravityProvider extends LLMProvider {
981
1029
  + (Number(usage.cache_read_tokens) || 0);
982
1030
  partialUsage.thinkingTokens = (partialUsage.thinkingTokens || 0)
983
1031
  + (Number(usage.thinking_tokens) || 0);
984
- if (enforceTokenLimit && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
985
- this.currentConversationId = null;
1032
+ if (Number.isFinite(tokenLimit) && tokenLimit > 0
1033
+ && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
986
1034
  const error = Object.assign(
987
- new Error(`Antigravity token budget reached during this turn: at least ${partialUsage.promptTokens + partialUsage.completionTokens} tokens reported for a ${tokenLimit}-token remaining budget. The task outcome is unverified.`),
988
- { code: 'AGY_TOKEN_BUDGET', partialUsage: { ...partialUsage } }
1035
+ new Error(`Antigravity reported at least ${partialUsage.promptTokens + partialUsage.completionTokens} noncached tokens against a ${tokenLimit}-token per-call ceiling. This turn stopped and its outcome is unverified.`),
1036
+ { code: 'AGY_TOKEN_BUDGET', tokenLimit, partialUsage: { ...partialUsage } }
989
1037
  );
990
1038
  safeReject(error);
991
1039
  terminateChild();
@@ -1018,6 +1066,20 @@ export class AntigravityProvider extends LLMProvider {
1018
1066
  (toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
1019
1067
  {};
1020
1068
 
1069
+ if ((options as any).taskArchetype === 'media_3d_generation' && newNativeAction && name) {
1070
+ consecutiveInspections = isReadOnlyNativeInspection(String(name), rawParams)
1071
+ ? consecutiveInspections + 1 : 0;
1072
+ if (consecutiveInspections >= 10) {
1073
+ const error = Object.assign(
1074
+ new Error('Antigravity made 10 consecutive read-only media inspections without a change. Pausing to redirect the task before further token use.'),
1075
+ { code: 'AGY_EXPLORATION_LOOP', inspectionCount: consecutiveInspections }
1076
+ );
1077
+ safeReject(error);
1078
+ terminateChild();
1079
+ return;
1080
+ }
1081
+ }
1082
+
1021
1083
  if (name) {
1022
1084
  const existingAttempt = attemptedNativeTools.find(a => a.name === name && a.status === 'running');
1023
1085
  if (existingAttempt) {
@@ -1291,6 +1353,9 @@ export class AntigravityProvider extends LLMProvider {
1291
1353
  if (options.signal?.aborted || err?.name === 'AbortError') {
1292
1354
  throw err;
1293
1355
  }
1356
+ if (err?.partialUsage?.promptTokens + err?.partialUsage?.completionTokens > 0) {
1357
+ throw err;
1358
+ }
1294
1359
  const canRetryResetConversation =
1295
1360
  hadConversation && !this.currentConversationId
1296
1361
  && (err as any)?.code !== 'AGY_NATIVE_ACTION_DENIED'
@@ -3,7 +3,7 @@
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import { createRequire } from 'module';
6
- import { execFileSync } from 'node:child_process';
6
+ import { installCapabilityManifest } from './npmInstall.js';
7
7
  import { pathToFileURL } from 'url';
8
8
  import { loadConfig, saveConfig } from '../config.js';
9
9
  import { isGroupGranted, isGroupDeclined } from './capabilityConsent.js';
@@ -169,12 +169,7 @@ export async function provisionCapabilities(groups = []) {
169
169
 
170
170
  if (!needsInstall) return { installed: target, skipped: true };
171
171
 
172
- const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
173
- execFileSync(
174
- npm,
175
- ['install', '--ignore-scripts', '--no-fund'],
176
- { cwd: CAPABILITY_DIR, stdio: 'inherit' }
177
- );
172
+ installCapabilityManifest(CAPABILITY_DIR);
178
173
  return { installed: target, skipped: false };
179
174
  }
180
175
 
@@ -0,0 +1,19 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ /** Install optional capabilities without writing over the active terminal UI. */
3
+ export function installCapabilityManifest(directory) {
4
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
5
+ try {
6
+ execFileSync(npm, ['install', '--ignore-scripts', '--no-fund'], {
7
+ cwd: directory,
8
+ stdio: 'pipe',
9
+ encoding: 'utf8',
10
+ maxBuffer: 2 * 1024 * 1024,
11
+ timeout: 120_000,
12
+ windowsHide: true
13
+ });
14
+ }
15
+ catch (error) {
16
+ const reason = error instanceof Error ? error.message : String(error);
17
+ throw new Error(`Capability installation failed: ${reason.slice(0, 600)}`, { cause: error });
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import { execFileSync } from 'node:child_process';
2
+
3
+ /** Install optional capabilities without writing over the active terminal UI. */
4
+ export function installCapabilityManifest(directory: string): void {
5
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
6
+ try {
7
+ execFileSync(npm, ['install', '--ignore-scripts', '--no-fund'], {
8
+ cwd: directory,
9
+ stdio: 'pipe',
10
+ encoding: 'utf8',
11
+ maxBuffer: 2 * 1024 * 1024,
12
+ timeout: 120_000,
13
+ windowsHide: true
14
+ });
15
+ } catch (error: unknown) {
16
+ const reason = error instanceof Error ? error.message : String(error);
17
+ throw new Error(`Capability installation failed: ${reason.slice(0, 600)}`, { cause: error });
18
+ }
19
+ }
@@ -110,6 +110,26 @@ export function determineToolScope(prompt, _taskShape) {
110
110
  reason: 'Simple filesystem operation; suppresses external domain packs.'
111
111
  };
112
112
  }
113
+ // 5. Media / 3D generation & creative audio intent
114
+ if (EXPLICIT_MEDIA_GENERATION_PATTERN.test(text)) {
115
+ const tools = new Set([
116
+ 'blender_act',
117
+ 'creative_apps',
118
+ 'execute_procedural_media',
119
+ 'fs_read',
120
+ 'fs_write',
121
+ 'sysRun',
122
+ 'view_image',
123
+ 'update_plan',
124
+ 'tool_search'
125
+ ]);
126
+ return {
127
+ toolScope: tools,
128
+ archetype: 'media_3d_generation',
129
+ suppressedPacks: ['web', 'game', 'advanced', 'system'],
130
+ reason: 'Media generation intent prioritizes 3D studio, procedural media, and image inspection; suppresses web and game packs.'
131
+ };
132
+ }
113
133
  // Default: unconstrained (standard progressive disclosure and packs apply)
114
134
  return {
115
135
  toolScope: null,
@@ -151,6 +151,27 @@ export function determineToolScope(
151
151
  };
152
152
  }
153
153
 
154
+ // 5. Media / 3D generation & creative audio intent
155
+ if (EXPLICIT_MEDIA_GENERATION_PATTERN.test(text)) {
156
+ const tools = new Set([
157
+ 'blender_act',
158
+ 'creative_apps',
159
+ 'execute_procedural_media',
160
+ 'fs_read',
161
+ 'fs_write',
162
+ 'sysRun',
163
+ 'view_image',
164
+ 'update_plan',
165
+ 'tool_search'
166
+ ]);
167
+ return {
168
+ toolScope: tools,
169
+ archetype: 'media_3d_generation',
170
+ suppressedPacks: ['web', 'game', 'advanced', 'system'],
171
+ reason: 'Media generation intent prioritizes 3D studio, procedural media, and image inspection; suppresses web and game packs.'
172
+ };
173
+ }
174
+
154
175
  // Default: unconstrained (standard progressive disclosure and packs apply)
155
176
  return {
156
177
  toolScope: null,