@causyne/agent 1.20.20 → 1.20.22

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.
@@ -1,5 +1,15 @@
1
1
  import { formatToolContracts, toolContractUpdate, contractFingerprint } from './toolContracts.js';
2
- import { noncachedTokens, turnTokenLimitFor } from './budgetEnforcer.js';
2
+ export function noncachedTokens(usage) {
3
+ if (!usage)
4
+ return 0;
5
+ const finite = (value) => Number.isFinite(value) ? Math.max(0, value ?? 0) : 0;
6
+ const input = usage.uncachedPromptTokens !== undefined
7
+ ? finite(usage.uncachedPromptTokens)
8
+ : finite(usage.cachedPromptTokens) > finite(usage.promptTokens)
9
+ ? finite(usage.promptTokens)
10
+ : Math.max(0, finite(usage.promptTokens) - finite(usage.cachedPromptTokens));
11
+ return input + finite(usage.completionTokens);
12
+ }
3
13
  import { determineToolScope } from '../smartToolsUse.js';
4
14
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
5
15
  import { spawn } from 'node:child_process';
@@ -966,9 +976,9 @@ export class AntigravityProvider extends LLMProvider {
966
976
  }
967
977
  };
968
978
  const configuredActions = Number(options.maxNativeActions);
969
- const isAutonomous = options.hardBudget === false || (!desktopTask && options.hardBudget !== true);
979
+ const isAutonomous = options.hardBudget === false;
970
980
  let maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
971
- ? configuredActions : desktopTask ? 12 : 35;
981
+ ? configuredActions : desktopTask ? 12 : isAutonomous ? Infinity : 35;
972
982
  let nativeActionStarts = 0;
973
983
  let lastMutationActionIndex = 0;
974
984
  let progressiveActionsCount = 0;
@@ -995,7 +1005,7 @@ export class AntigravityProvider extends LLMProvider {
995
1005
  const hasExplicitLimit = (Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0)
996
1006
  || (Number.isFinite(rawTokenLimit) && rawTokenLimit > 0);
997
1007
  const countReportedTotal = options.tokenBudgetBasis !== 'noncached';
998
- const defaultTokenLimit = turnTokenLimitFor(taskArchetype);
1008
+ const defaultTokenLimit = 100_000;
999
1009
  const tokenLimit = Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0
1000
1010
  ? remainingTaskBudget
1001
1011
  : (Number.isFinite(rawTokenLimit) && rawTokenLimit > 0
@@ -1203,19 +1213,9 @@ export class AntigravityProvider extends LLMProvider {
1203
1213
  }
1204
1214
  }
1205
1215
  }
1206
- if (newNativeAction && ++nativeActionStarts > maxNativeActions) {
1207
- // In autonomous mode, if the agent has made genuine progress recently
1208
- // (e.g. edits/mutations or productive steps within last 25 actions),
1209
- // dynamically expand the autonomous runway so serious tasks are not interrupted!
1210
- const hasRecentProgress = (nativeActionStarts - lastMutationActionIndex) <= 25 || progressiveActionsCount > 0;
1211
- if (isAutonomous && hasRecentProgress && maxNativeActions < 500) {
1212
- const extension = 50;
1213
- maxNativeActions += extension;
1214
- if (process.env.CAUSYNE_DEBUG === '1') {
1215
- console.log(`[AUTONOMY] Dynamically extended native action runway (+${extension} -> ${maxNativeActions} actions) due to active progress.`);
1216
- }
1217
- }
1218
- else {
1216
+ if (newNativeAction) {
1217
+ nativeActionStarts++;
1218
+ if (!isAutonomous && Number.isFinite(maxNativeActions) && nativeActionStarts > maxNativeActions) {
1219
1219
  const error = new Error(`Antigravity reached the ${maxNativeActions} native-action turn checkpoint. Work remains unfinished; continue from the saved session.`);
1220
1220
  error.code = 'AGY_NATIVE_ACTION_BUDGET';
1221
1221
  safeReject(error);
@@ -1,5 +1,14 @@
1
1
  import { formatToolContracts, toolContractUpdate, contractFingerprint } from './toolContracts.js';
2
- import { noncachedTokens, turnTokenLimitFor } from './budgetEnforcer.js';
2
+ export function noncachedTokens(usage: { promptTokens?: number | undefined; completionTokens?: number | undefined; uncachedPromptTokens?: number | undefined; cachedPromptTokens?: number | undefined } | null | undefined): number {
3
+ if (!usage) return 0;
4
+ const finite = (value: number | undefined): number => Number.isFinite(value) ? Math.max(0, value ?? 0) : 0;
5
+ const input = usage.uncachedPromptTokens !== undefined
6
+ ? finite(usage.uncachedPromptTokens)
7
+ : finite(usage.cachedPromptTokens) > finite(usage.promptTokens)
8
+ ? finite(usage.promptTokens)
9
+ : Math.max(0, finite(usage.promptTokens) - finite(usage.cachedPromptTokens));
10
+ return input + finite(usage.completionTokens);
11
+ }
3
12
  import { determineToolScope } from '../smartToolsUse.js';
4
13
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
5
14
  import { spawn } from 'node:child_process';
@@ -1008,9 +1017,9 @@ export class AntigravityProvider extends LLMProvider {
1008
1017
  }
1009
1018
  };
1010
1019
  const configuredActions = Number(options.maxNativeActions);
1011
- const isAutonomous = (options as any).hardBudget === false || (!desktopTask && (options as any).hardBudget !== true);
1020
+ const isAutonomous = (options as any).hardBudget === false;
1012
1021
  let maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
1013
- ? configuredActions : desktopTask ? 12 : 35;
1022
+ ? configuredActions : desktopTask ? 12 : isAutonomous ? Infinity : 35;
1014
1023
  let nativeActionStarts = 0;
1015
1024
  let lastMutationActionIndex = 0;
1016
1025
  let progressiveActionsCount = 0;
@@ -1037,7 +1046,7 @@ export class AntigravityProvider extends LLMProvider {
1037
1046
  const hasExplicitLimit = (Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0)
1038
1047
  || (Number.isFinite(rawTokenLimit) && rawTokenLimit > 0);
1039
1048
  const countReportedTotal = options.tokenBudgetBasis !== 'noncached';
1040
- const defaultTokenLimit = turnTokenLimitFor(taskArchetype);
1049
+ const defaultTokenLimit = 100_000;
1041
1050
  const tokenLimit = Number.isFinite(remainingTaskBudget) && remainingTaskBudget > 0
1042
1051
  ? remainingTaskBudget
1043
1052
  : (Number.isFinite(rawTokenLimit) && rawTokenLimit > 0
@@ -1258,18 +1267,9 @@ export class AntigravityProvider extends LLMProvider {
1258
1267
  }
1259
1268
  }
1260
1269
 
1261
- if (newNativeAction && ++nativeActionStarts > maxNativeActions) {
1262
- // In autonomous mode, if the agent has made genuine progress recently
1263
- // (e.g. edits/mutations or productive steps within last 25 actions),
1264
- // dynamically expand the autonomous runway so serious tasks are not interrupted!
1265
- const hasRecentProgress = (nativeActionStarts - lastMutationActionIndex) <= 25 || progressiveActionsCount > 0;
1266
- if (isAutonomous && hasRecentProgress && maxNativeActions < 500) {
1267
- const extension = 50;
1268
- maxNativeActions += extension;
1269
- if (process.env.CAUSYNE_DEBUG === '1') {
1270
- console.log(`[AUTONOMY] Dynamically extended native action runway (+${extension} -> ${maxNativeActions} actions) due to active progress.`);
1271
- }
1272
- } else {
1270
+ if (newNativeAction) {
1271
+ nativeActionStarts++;
1272
+ if (!isAutonomous && Number.isFinite(maxNativeActions) && nativeActionStarts > maxNativeActions) {
1273
1273
  const error = new Error(`Antigravity reached the ${maxNativeActions} native-action turn checkpoint. Work remains unfinished; continue from the saved session.`) as Error & { code: string };
1274
1274
  error.code = 'AGY_NATIVE_ACTION_BUDGET';
1275
1275
  safeReject(error);
@@ -130,8 +130,10 @@ const EXPLICIT_MEDIA_GENERATION_PATTERN = /\b(blender|3d model|render 3d|render
130
130
  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;
131
131
  // Explicit game development intent
132
132
  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;
133
- // Explicit software and systems engineering intent (backend, APIs, refactoring, algorithms, testing, architecture, CLI tools)
134
- const EXPLICIT_SOFTWARE_ENGINEERING_PATTERN = /(?:\b(?:build|create|code|program|develop|refactor|debug|fix|implement|test|optimize|write|add|modify|migrate|architect|engineer|benchmark|profile|audit)\b[\s\S]*\b(?:api|backend|service|microservice|server|database|schema|endpoint|controller|auth|test|spec|algorithm|function|module|class|feature|script|pipeline|codebase|repo|repository|bug|issue|engine|tool|cli|library|sdk|migration|handler|worker|queue|stream)\b|\b(?:python|rust|golang|c\+\+|cpp|java|typescript|javascript|ruby|php|sql|bash|shell|docker|k8s|kubernetes)\b)/i;
133
+ // Explicit reverse engineering and binary analysis intent
134
+ const EXPLICIT_REVERSE_ENGINEERING_PATTERN = /\b(reverse[-_ ]?engineering|decompile|disassemble|disasm|apk|aab|dex|radare|rizin|ghidra|jadx|apktool|mach-o|elf binary|portable executable|\.apk\b|\.aab\b|\.dex\b|\.so\b|\.dylib\b|\.wasm\b|\.asar\b)\b/i;
135
+ // Explicit software and systems engineering intent (backend, APIs, refactoring, algorithms, testing, architecture, CLI tools, Android/mobile)
136
+ const EXPLICIT_SOFTWARE_ENGINEERING_PATTERN = /(?:\b(?:build|create|code|program|develop|refactor|debug|fix|implement|test|optimize|write|add|modify|migrate|architect|architecture|engineer|benchmark|profile|audit|scaffold)\b[\s\S]*\b(?:api|backend|service|microservice|server|database|schema|endpoint|controller|auth|test|spec|algorithm|function|module|class|feature|script|pipeline|codebase|repo|repository|bug|issue|engine|tool|cli|library|sdk|migration|handler|worker|queue|stream|app|application|compose|jetpack|android|gradle|package)\b|\b(?:python|rust|golang|c\+\+|cpp|java|kotlin|swift|csharp|typescript|javascript|ruby|php|sql|bash|shell|docker|k8s|kubernetes|gradle|compose|android)\b)/i;
135
137
  /**
136
138
  * Select tools to preload based on prompt intent. This is never an allowlist:
137
139
  * tool_search can add capabilities as the task develops.
@@ -141,7 +143,28 @@ export function determineToolScope(prompt, _taskShape) {
141
143
  if (!text) {
142
144
  return { toolScope: null, archetype: 'empty', suppressedPacks: [] };
143
145
  }
144
- // 1. Desktop personalization (e.g. wallpaper / desktop background)
146
+ // 1. Reverse engineering & binary analysis intent
147
+ if (EXPLICIT_REVERSE_ENGINEERING_PATTERN.test(text)) {
148
+ const tools = new Set([
149
+ 'reverse_engineering',
150
+ 'fs_read',
151
+ 'fs_write',
152
+ 'fs_edit',
153
+ 'fs_list',
154
+ 'fs_search',
155
+ 'sysRun',
156
+ 'view_image',
157
+ 'update_plan',
158
+ 'tool_search'
159
+ ]);
160
+ return {
161
+ toolScope: tools,
162
+ archetype: 'reverse_engineering',
163
+ suppressedPacks: ['media', 'game', 'web'],
164
+ reason: 'Reverse engineering intent prioritizes binary triage, decompilation, filesystem exploration, and terminal verification; suppresses creative packs.'
165
+ };
166
+ }
167
+ // 2. Desktop personalization (e.g. wallpaper / desktop background)
145
168
  if (DESKTOP_PERSONALIZATION_PATTERN.test(text)) {
146
169
  const tools = new Set([
147
170
  'sysRun',
@@ -176,9 +176,13 @@ const EXPLICIT_WEB_ENGINEERING_PATTERN =
176
176
  const EXPLICIT_GAME_DEV_PATTERN =
177
177
  /(?:\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;
178
178
 
179
- // Explicit software and systems engineering intent (backend, APIs, refactoring, algorithms, testing, architecture, CLI tools)
179
+ // Explicit reverse engineering and binary analysis intent
180
+ const EXPLICIT_REVERSE_ENGINEERING_PATTERN =
181
+ /\b(reverse[-_ ]?engineering|decompile|disassemble|disasm|apk|aab|dex|radare|rizin|ghidra|jadx|apktool|mach-o|elf binary|portable executable|\.apk\b|\.aab\b|\.dex\b|\.so\b|\.dylib\b|\.wasm\b|\.asar\b)\b/i;
182
+
183
+ // Explicit software and systems engineering intent (backend, APIs, refactoring, algorithms, testing, architecture, CLI tools, Android/mobile)
180
184
  const EXPLICIT_SOFTWARE_ENGINEERING_PATTERN =
181
- /(?:\b(?:build|create|code|program|develop|refactor|debug|fix|implement|test|optimize|write|add|modify|migrate|architect|engineer|benchmark|profile|audit)\b[\s\S]*\b(?:api|backend|service|microservice|server|database|schema|endpoint|controller|auth|test|spec|algorithm|function|module|class|feature|script|pipeline|codebase|repo|repository|bug|issue|engine|tool|cli|library|sdk|migration|handler|worker|queue|stream)\b|\b(?:python|rust|golang|c\+\+|cpp|java|typescript|javascript|ruby|php|sql|bash|shell|docker|k8s|kubernetes)\b)/i;
185
+ /(?:\b(?:build|create|code|program|develop|refactor|debug|fix|implement|test|optimize|write|add|modify|migrate|architect|architecture|engineer|benchmark|profile|audit|scaffold)\b[\s\S]*\b(?:api|backend|service|microservice|server|database|schema|endpoint|controller|auth|test|spec|algorithm|function|module|class|feature|script|pipeline|codebase|repo|repository|bug|issue|engine|tool|cli|library|sdk|migration|handler|worker|queue|stream|app|application|compose|jetpack|android|gradle|package)\b|\b(?:python|rust|golang|c\+\+|cpp|java|kotlin|swift|csharp|typescript|javascript|ruby|php|sql|bash|shell|docker|k8s|kubernetes|gradle|compose|android)\b)/i;
182
186
 
183
187
  /**
184
188
  * Select tools to preload based on prompt intent. This is never an allowlist:
@@ -193,7 +197,29 @@ export function determineToolScope(
193
197
  return { toolScope: null, archetype: 'empty', suppressedPacks: [] };
194
198
  }
195
199
 
196
- // 1. Desktop personalization (e.g. wallpaper / desktop background)
200
+ // 1. Reverse engineering & binary analysis intent
201
+ if (EXPLICIT_REVERSE_ENGINEERING_PATTERN.test(text)) {
202
+ const tools = new Set([
203
+ 'reverse_engineering',
204
+ 'fs_read',
205
+ 'fs_write',
206
+ 'fs_edit',
207
+ 'fs_list',
208
+ 'fs_search',
209
+ 'sysRun',
210
+ 'view_image',
211
+ 'update_plan',
212
+ 'tool_search'
213
+ ]);
214
+ return {
215
+ toolScope: tools,
216
+ archetype: 'reverse_engineering',
217
+ suppressedPacks: ['media', 'game', 'web'],
218
+ reason: 'Reverse engineering intent prioritizes binary triage, decompilation, filesystem exploration, and terminal verification; suppresses creative packs.'
219
+ };
220
+ }
221
+
222
+ // 2. Desktop personalization (e.g. wallpaper / desktop background)
197
223
  if (DESKTOP_PERSONALIZATION_PATTERN.test(text)) {
198
224
  const tools = new Set([
199
225
  'sysRun',