@causyne/agent 1.20.16 → 1.20.18

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.
@@ -357,17 +357,60 @@ function nativeInspectionTarget(name, parameters) {
357
357
  }
358
358
  return null;
359
359
  }
360
- function isNativeMutation(name, parameters) {
360
+ export function isNativeMutation(name, parameters = {}) {
361
+ if (!name || typeof name !== 'string')
362
+ return false;
361
363
  const action = name.toLowerCase().replace(/[_\s-]/g, '');
362
- if (/^(writefile|editfile|deletefile|applypatch|createfile|replaceinfile)$/.test(action))
364
+ if (/^(writefile|writetofile|editfile|replacefilecontent|multireplacefilecontent|deletefile|applypatch|createfile|replaceinfile|fswrite|fsedit|generatemedia|generateimage)$/.test(action)) {
363
365
  return true;
366
+ }
364
367
  if (!/^(runcommand|command|sysrun|terminal|bash|shell)$/.test(action))
365
368
  return false;
366
369
  const command = cleanCommandString(parameters.CommandLine ?? parameters.command ?? parameters.cmd ?? '');
367
370
  if (!command)
368
371
  return false;
369
372
  return /\b(?:save_as_mainfile|save_mainfile|write_text|write_bytes|tee)\b/.test(command)
370
- || /(?:^|[;&|]\s*)(?:cp|mv|rm|install|patch)\s/.test(command);
373
+ || /(?:^|[;&|]\s*)(?:cp|mv|rm|install|patch|touch|mkdir|chmod|sed)\s/.test(command)
374
+ || /(?:>|>>)/.test(command)
375
+ || /\b(?:npm|yarn|pnpm|cargo|gradle|gradlew|mvn|dotnet|pip|pip3|pytest|vitest|jest|tsc|make|docker|git\s+(?:add|commit|checkout|merge|rebase|stash|pull|push))\b/i.test(command);
376
+ }
377
+ export function nativeToolSignature(name, parameters = {}) {
378
+ const normName = name.toLowerCase().replace(/[_\s-]/g, '');
379
+ const sortedKeys = Object.keys(parameters).sort();
380
+ const sortedObj = {};
381
+ for (const k of sortedKeys) {
382
+ const val = parameters[k];
383
+ if (val !== undefined && typeof val !== 'function') {
384
+ sortedObj[k] = val;
385
+ }
386
+ }
387
+ return `${normName}:${JSON.stringify(sortedObj)}`;
388
+ }
389
+ export function detectNativeCycle(signatures) {
390
+ for (let period = 2; period <= 4; period++) {
391
+ if (signatures.length < period * 3)
392
+ continue;
393
+ let laps = 1;
394
+ while (true) {
395
+ const base = signatures.length - period * (laps + 1);
396
+ if (base < 0)
397
+ break;
398
+ let lapEqual = true;
399
+ for (let i = 0; i < period; i++) {
400
+ if (signatures[base + i] !== signatures[signatures.length - period + i]) {
401
+ lapEqual = false;
402
+ break;
403
+ }
404
+ }
405
+ if (!lapEqual)
406
+ break;
407
+ laps++;
408
+ }
409
+ if (laps >= 3) {
410
+ return { period, laps };
411
+ }
412
+ }
413
+ return null;
371
414
  }
372
415
  export function mapNativeToolToCausyne(name, rawParams, index) {
373
416
  if (!name || typeof name !== 'string')
@@ -923,9 +966,16 @@ export class AntigravityProvider extends LLMProvider {
923
966
  }
924
967
  };
925
968
  const configuredActions = Number(options.maxNativeActions);
926
- const maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
969
+ const isAutonomous = options.hardBudget === false || (!desktopTask && options.hardBudget !== true);
970
+ let maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
927
971
  ? configuredActions : desktopTask ? 12 : 35;
928
972
  let nativeActionStarts = 0;
973
+ let lastMutationActionIndex = 0;
974
+ let progressiveActionsCount = 0;
975
+ let consecutiveIdenticalCount = 0;
976
+ let consecutiveInspections = 0;
977
+ let lastToolSignature = '';
978
+ const recentSignatures = [];
929
979
  const seenNativeActionSteps = new Set();
930
980
  const mediaInspectionCounts = new Map();
931
981
  const pendingMediaMutations = new Set();
@@ -1098,13 +1148,6 @@ export class AntigravityProvider extends LLMProvider {
1098
1148
  && (!Number.isFinite(stepIndex) || !seenNativeActionSteps.has(stepIndex));
1099
1149
  if (newNativeAction && Number.isFinite(stepIndex))
1100
1150
  seenNativeActionSteps.add(stepIndex);
1101
- if (newNativeAction && ++nativeActionStarts > maxNativeActions) {
1102
- const error = new Error(`Antigravity reached the ${maxNativeActions} native-action turn checkpoint. Work remains unfinished; continue from the saved session.`);
1103
- error.code = 'AGY_NATIVE_ACTION_BUDGET';
1104
- safeReject(error);
1105
- terminateChild();
1106
- return;
1107
- }
1108
1151
  const toolInfo = stepUpdate?.tool_info || {};
1109
1152
  const name = stepUpdate?.tool_name || toolInfo?.name;
1110
1153
  const status = state === 'DONE' || state === 'ERROR'
@@ -1114,6 +1157,72 @@ export class AntigravityProvider extends LLMProvider {
1114
1157
  (stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
1115
1158
  (toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
1116
1159
  {};
1160
+ if (name && newNativeAction) {
1161
+ const mutating = isNativeMutation(name, rawParams);
1162
+ if (mutating) {
1163
+ lastMutationActionIndex = nativeActionStarts + 1;
1164
+ progressiveActionsCount++;
1165
+ consecutiveIdenticalCount = 0;
1166
+ consecutiveInspections = 0;
1167
+ lastToolSignature = '';
1168
+ }
1169
+ else if (!desktopTask && options.taskArchetype !== 'media_3d_generation') {
1170
+ consecutiveInspections++;
1171
+ const sig = nativeToolSignature(name, rawParams);
1172
+ if (sig === lastToolSignature) {
1173
+ consecutiveIdenticalCount++;
1174
+ }
1175
+ else {
1176
+ consecutiveIdenticalCount = 1;
1177
+ lastToolSignature = sig;
1178
+ }
1179
+ recentSignatures.push(sig);
1180
+ if (recentSignatures.length > 24)
1181
+ recentSignatures.shift();
1182
+ // 1. Aimless identical streak detection: 4 identical consecutive non-mutating calls
1183
+ if (consecutiveIdenticalCount >= 4) {
1184
+ const error = Object.assign(new Error(`Antigravity repeated identical call to '${name}' ${consecutiveIdenticalCount} times without progress. Halting circular loop.`), { code: 'AGY_EXPLORATION_LOOP', toolName: name, count: consecutiveIdenticalCount });
1185
+ safeReject(error);
1186
+ terminateChild();
1187
+ return;
1188
+ }
1189
+ // 2. Aimless circular cycle detection: period 2-4 repeating 3 laps without mutation
1190
+ const cycle = detectNativeCycle(recentSignatures);
1191
+ if (cycle && (nativeActionStarts - lastMutationActionIndex) > (cycle.period * 2)) {
1192
+ const error = Object.assign(new Error(`Antigravity repeated circular cycle of ${cycle.period} tool calls without forward progress. Halting circular loop.`), { code: 'AGY_EXPLORATION_LOOP', period: cycle.period, laps: cycle.laps });
1193
+ safeReject(error);
1194
+ terminateChild();
1195
+ return;
1196
+ }
1197
+ // 3. Stagnant read-only inspection runaway without mutations on an editing task
1198
+ if (consecutiveInspections >= 30 && options.taskArchetype !== 'web_research_only') {
1199
+ const error = Object.assign(new Error(`Antigravity performed ${consecutiveInspections} consecutive read-only inspections without writing or modifying code. Halting exploration loop.`), { code: 'AGY_EXPLORATION_LOOP', inspectionCount: consecutiveInspections });
1200
+ safeReject(error);
1201
+ terminateChild();
1202
+ return;
1203
+ }
1204
+ }
1205
+ }
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 {
1219
+ const error = new Error(`Antigravity reached the ${maxNativeActions} native-action turn checkpoint. Work remains unfinished; continue from the saved session.`);
1220
+ error.code = 'AGY_NATIVE_ACTION_BUDGET';
1221
+ safeReject(error);
1222
+ terminateChild();
1223
+ return;
1224
+ }
1225
+ }
1117
1226
  if (options.taskArchetype === 'media_3d_generation' && name) {
1118
1227
  if (newNativeAction) {
1119
1228
  const target = isReadOnlyNativeInspection(name, rawParams)
@@ -364,14 +364,56 @@ function nativeInspectionTarget(name: string, parameters: Record<string, unknown
364
364
  return null;
365
365
  }
366
366
 
367
- function isNativeMutation(name: string, parameters: Record<string, unknown>): boolean {
367
+ export function isNativeMutation(name: string, parameters: Record<string, unknown> = {}): boolean {
368
+ if (!name || typeof name !== 'string') return false;
368
369
  const action = name.toLowerCase().replace(/[_\s-]/g, '');
369
- if (/^(writefile|editfile|deletefile|applypatch|createfile|replaceinfile)$/.test(action)) return true;
370
+ if (/^(writefile|writetofile|editfile|replacefilecontent|multireplacefilecontent|deletefile|applypatch|createfile|replaceinfile|fswrite|fsedit|generatemedia|generateimage)$/.test(action)) {
371
+ return true;
372
+ }
370
373
  if (!/^(runcommand|command|sysrun|terminal|bash|shell)$/.test(action)) return false;
371
374
  const command = cleanCommandString(parameters.CommandLine ?? parameters.command ?? parameters.cmd ?? '');
372
375
  if (!command) return false;
373
376
  return /\b(?:save_as_mainfile|save_mainfile|write_text|write_bytes|tee)\b/.test(command)
374
- || /(?:^|[;&|]\s*)(?:cp|mv|rm|install|patch)\s/.test(command);
377
+ || /(?:^|[;&|]\s*)(?:cp|mv|rm|install|patch|touch|mkdir|chmod|sed)\s/.test(command)
378
+ || /(?:>|>>)/.test(command)
379
+ || /\b(?:npm|yarn|pnpm|cargo|gradle|gradlew|mvn|dotnet|pip|pip3|pytest|vitest|jest|tsc|make|docker|git\s+(?:add|commit|checkout|merge|rebase|stash|pull|push))\b/i.test(command);
380
+ }
381
+
382
+ export function nativeToolSignature(name: string, parameters: Record<string, unknown> = {}): string {
383
+ const normName = name.toLowerCase().replace(/[_\s-]/g, '');
384
+ const sortedKeys = Object.keys(parameters).sort();
385
+ const sortedObj: Record<string, unknown> = {};
386
+ for (const k of sortedKeys) {
387
+ const val = parameters[k];
388
+ if (val !== undefined && typeof val !== 'function') {
389
+ sortedObj[k] = val;
390
+ }
391
+ }
392
+ return `${normName}:${JSON.stringify(sortedObj)}`;
393
+ }
394
+
395
+ export function detectNativeCycle(signatures: string[]): { period: number; laps: number } | null {
396
+ for (let period = 2; period <= 4; period++) {
397
+ if (signatures.length < period * 3) continue;
398
+ let laps = 1;
399
+ while (true) {
400
+ const base = signatures.length - period * (laps + 1);
401
+ if (base < 0) break;
402
+ let lapEqual = true;
403
+ for (let i = 0; i < period; i++) {
404
+ if (signatures[base + i] !== signatures[signatures.length - period + i]) {
405
+ lapEqual = false;
406
+ break;
407
+ }
408
+ }
409
+ if (!lapEqual) break;
410
+ laps++;
411
+ }
412
+ if (laps >= 3) {
413
+ return { period, laps };
414
+ }
415
+ }
416
+ return null;
375
417
  }
376
418
 
377
419
  export function mapNativeToolToCausyne(
@@ -966,9 +1008,16 @@ export class AntigravityProvider extends LLMProvider {
966
1008
  }
967
1009
  };
968
1010
  const configuredActions = Number(options.maxNativeActions);
969
- const maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
1011
+ const isAutonomous = (options as any).hardBudget === false || (!desktopTask && (options as any).hardBudget !== true);
1012
+ let maxNativeActions = Number.isSafeInteger(configuredActions) && configuredActions >= 0
970
1013
  ? configuredActions : desktopTask ? 12 : 35;
971
1014
  let nativeActionStarts = 0;
1015
+ let lastMutationActionIndex = 0;
1016
+ let progressiveActionsCount = 0;
1017
+ let consecutiveIdenticalCount = 0;
1018
+ let consecutiveInspections = 0;
1019
+ let lastToolSignature = '';
1020
+ const recentSignatures: string[] = [];
972
1021
  const seenNativeActionSteps = new Set<number>();
973
1022
  const mediaInspectionCounts = new Map<string, number>();
974
1023
  const pendingMediaMutations = new Set<number>();
@@ -1142,13 +1191,7 @@ export class AntigravityProvider extends LLMProvider {
1142
1191
  const newNativeAction = (state === 'ACTIVE' || (state === 'DONE' && Number.isFinite(stepIndex)))
1143
1192
  && (!Number.isFinite(stepIndex) || !seenNativeActionSteps.has(stepIndex));
1144
1193
  if (newNativeAction && Number.isFinite(stepIndex)) seenNativeActionSteps.add(stepIndex);
1145
- if (newNativeAction && ++nativeActionStarts > maxNativeActions) {
1146
- const error = new Error(`Antigravity reached the ${maxNativeActions} native-action turn checkpoint. Work remains unfinished; continue from the saved session.`) as Error & { code: string };
1147
- error.code = 'AGY_NATIVE_ACTION_BUDGET';
1148
- safeReject(error);
1149
- terminateChild();
1150
- return;
1151
- }
1194
+
1152
1195
  const toolInfo = stepUpdate?.tool_info || {};
1153
1196
  const name = stepUpdate?.tool_name || toolInfo?.name;
1154
1197
  const status = state === 'DONE' || state === 'ERROR'
@@ -1159,6 +1202,82 @@ export class AntigravityProvider extends LLMProvider {
1159
1202
  (toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
1160
1203
  {};
1161
1204
 
1205
+ if (name && newNativeAction) {
1206
+ const mutating = isNativeMutation(name, rawParams);
1207
+ if (mutating) {
1208
+ lastMutationActionIndex = nativeActionStarts + 1;
1209
+ progressiveActionsCount++;
1210
+ consecutiveIdenticalCount = 0;
1211
+ consecutiveInspections = 0;
1212
+ lastToolSignature = '';
1213
+ } else if (!desktopTask && (options as any).taskArchetype !== 'media_3d_generation') {
1214
+ consecutiveInspections++;
1215
+ const sig = nativeToolSignature(name, rawParams);
1216
+ if (sig === lastToolSignature) {
1217
+ consecutiveIdenticalCount++;
1218
+ } else {
1219
+ consecutiveIdenticalCount = 1;
1220
+ lastToolSignature = sig;
1221
+ }
1222
+ recentSignatures.push(sig);
1223
+ if (recentSignatures.length > 24) recentSignatures.shift();
1224
+
1225
+ // 1. Aimless identical streak detection: 4 identical consecutive non-mutating calls
1226
+ if (consecutiveIdenticalCount >= 4) {
1227
+ const error = Object.assign(
1228
+ new Error(`Antigravity repeated identical call to '${name}' ${consecutiveIdenticalCount} times without progress. Halting circular loop.`),
1229
+ { code: 'AGY_EXPLORATION_LOOP', toolName: name, count: consecutiveIdenticalCount }
1230
+ );
1231
+ safeReject(error);
1232
+ terminateChild();
1233
+ return;
1234
+ }
1235
+
1236
+ // 2. Aimless circular cycle detection: period 2-4 repeating 3 laps without mutation
1237
+ const cycle = detectNativeCycle(recentSignatures);
1238
+ if (cycle && (nativeActionStarts - lastMutationActionIndex) > (cycle.period * 2)) {
1239
+ const error = Object.assign(
1240
+ new Error(`Antigravity repeated circular cycle of ${cycle.period} tool calls without forward progress. Halting circular loop.`),
1241
+ { code: 'AGY_EXPLORATION_LOOP', period: cycle.period, laps: cycle.laps }
1242
+ );
1243
+ safeReject(error);
1244
+ terminateChild();
1245
+ return;
1246
+ }
1247
+
1248
+ // 3. Stagnant read-only inspection runaway without mutations on an editing task
1249
+ if (consecutiveInspections >= 30 && (options as any).taskArchetype !== 'web_research_only') {
1250
+ const error = Object.assign(
1251
+ new Error(`Antigravity performed ${consecutiveInspections} consecutive read-only inspections without writing or modifying code. Halting exploration loop.`),
1252
+ { code: 'AGY_EXPLORATION_LOOP', inspectionCount: consecutiveInspections }
1253
+ );
1254
+ safeReject(error);
1255
+ terminateChild();
1256
+ return;
1257
+ }
1258
+ }
1259
+ }
1260
+
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 {
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
+ error.code = 'AGY_NATIVE_ACTION_BUDGET';
1275
+ safeReject(error);
1276
+ terminateChild();
1277
+ return;
1278
+ }
1279
+ }
1280
+
1162
1281
  if ((options as any).taskArchetype === 'media_3d_generation' && name) {
1163
1282
  if (newNativeAction) {
1164
1283
  const target = isReadOnlyNativeInspection(name, rawParams)