@causyne/agent 1.20.19 → 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.
- package/bin/causyne.js +7 -1
- package/package.json +1 -1
- package/src/agentLoop.js +36 -100
- package/src/agentLoop.ts +35 -101
- package/src/autoUpdate.js +251 -183
- package/src/autoUpdate.ts +360 -0
- package/src/engines/reverseHarness.js +25 -3
- package/src/engines/reverseHarness.ts +30 -3
- package/src/providers/antigravity.js +17 -17
- package/src/providers/antigravity.ts +16 -16
- package/src/smartToolsUse.js +26 -3
- package/src/smartToolsUse.ts +29 -3
- package/src/tools/reverseEngineering.js +464 -24
- package/src/tools/reverseEngineering.ts +473 -25
- package/src/utils/cli_ui.d.ts +19 -0
- package/src/providers/budgetEnforcer.js +0 -136
- package/src/providers/budgetEnforcer.ts +0 -143
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Causyne package updates.
|
|
2
|
+
//
|
|
3
|
+
// Updates are intentionally limited to installations managed by npm or by the
|
|
4
|
+
// causyne.com installer. A source checkout is never rewritten. Commands are
|
|
5
|
+
// passed as argv arrays with shell disabled, and the only accepted package is
|
|
6
|
+
// the public @causyne/agent package from the npm registry.
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
|
|
12
|
+
|
|
13
|
+
import { UI } from './utils/cli_ui.js';
|
|
14
|
+
import { causyneHome } from './utils/paths.js';
|
|
15
|
+
import { getPackageVersion } from './version.js';
|
|
16
|
+
|
|
17
|
+
const PACKAGE_NAME = '@causyne/agent';
|
|
18
|
+
const REGISTRY_LATEST = 'https://registry.npmjs.org/@causyne%2fagent/latest';
|
|
19
|
+
const DEFAULT_CHECK_INTERVAL_MS = 60 * 60 * 1000; // 1 hour for active developer agility
|
|
20
|
+
const ERROR_RETRY_INTERVAL_MS = 2 * 60 * 1000; // 2 minutes retry on network error
|
|
21
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
22
|
+
|
|
23
|
+
export interface VersionParts {
|
|
24
|
+
numbers: [number, number, number];
|
|
25
|
+
prerelease: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface InstallationInfo {
|
|
29
|
+
managed: boolean;
|
|
30
|
+
type: 'causyne.com installer' | 'global npm' | 'source checkout';
|
|
31
|
+
prefix: string | null;
|
|
32
|
+
packageRoot: string;
|
|
33
|
+
npmCommand: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface UpdateState {
|
|
37
|
+
checkedAt?: number;
|
|
38
|
+
latest?: string;
|
|
39
|
+
installedAt?: number;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CheckUpdateOptions {
|
|
44
|
+
currentVersion?: string;
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SelfUpdateOptions extends CheckUpdateOptions {
|
|
52
|
+
force?: boolean;
|
|
53
|
+
stateFile?: string;
|
|
54
|
+
packageRoot?: string;
|
|
55
|
+
spawnSyncImpl?: (command: string, args: readonly string[], options: Record<string, unknown>) => SpawnSyncReturns<string | Buffer>;
|
|
56
|
+
verbose?: boolean;
|
|
57
|
+
version?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CheckResult {
|
|
61
|
+
current: string;
|
|
62
|
+
latest: string;
|
|
63
|
+
available: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface UpdateResult extends InstallationInfo {
|
|
67
|
+
current?: string | undefined;
|
|
68
|
+
latest?: string | undefined;
|
|
69
|
+
available?: boolean | undefined;
|
|
70
|
+
updated: boolean;
|
|
71
|
+
reason?: 'disabled' | 'source-checkout' | 'recently-checked' | 'current' | 'failed' | undefined;
|
|
72
|
+
error?: string | undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface DiagnosisResult extends InstallationInfo {
|
|
76
|
+
current?: string | undefined;
|
|
77
|
+
latest?: string | null | undefined;
|
|
78
|
+
available?: boolean | undefined;
|
|
79
|
+
autoUpdates: boolean;
|
|
80
|
+
error?: string | undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function updateStateFile(options: { stateFile?: string; env?: NodeJS.ProcessEnv } = {}): string {
|
|
84
|
+
if (options.stateFile) return path.resolve(options.stateFile);
|
|
85
|
+
const env = options.env || process.env;
|
|
86
|
+
const root = env.CAUSYNE_HOME && String(env.CAUSYNE_HOME).trim()
|
|
87
|
+
? path.resolve(String(env.CAUSYNE_HOME).trim())
|
|
88
|
+
: causyneHome();
|
|
89
|
+
return path.join(root, 'update-state.json');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function versionParts(version: string | undefined): VersionParts | null {
|
|
93
|
+
const match = String(version || '').trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/);
|
|
94
|
+
if (!match) return null;
|
|
95
|
+
const num1 = Number(match[1]);
|
|
96
|
+
const num2 = Number(match[2]);
|
|
97
|
+
const num3 = Number(match[3]);
|
|
98
|
+
return { numbers: [num1, num2, num3], prerelease: match[4] || '' };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function compareVersions(left: string | undefined, right: string | undefined): number {
|
|
102
|
+
const a = versionParts(left);
|
|
103
|
+
const b = versionParts(right);
|
|
104
|
+
if (!a || !b) return 0;
|
|
105
|
+
for (let index = 0; index < 3; index++) {
|
|
106
|
+
const aNum = a.numbers[index] ?? 0;
|
|
107
|
+
const bNum = b.numbers[index] ?? 0;
|
|
108
|
+
if (aNum !== bNum) return aNum > bNum ? 1 : -1;
|
|
109
|
+
}
|
|
110
|
+
if (a.prerelease === b.prerelease) return 0;
|
|
111
|
+
if (!a.prerelease) return 1;
|
|
112
|
+
if (!b.prerelease) return -1;
|
|
113
|
+
const aParts = a.prerelease.split('.');
|
|
114
|
+
const bParts = b.prerelease.split('.');
|
|
115
|
+
const length = Math.max(aParts.length, bParts.length);
|
|
116
|
+
for (let index = 0; index < length; index++) {
|
|
117
|
+
const aPart = aParts[index];
|
|
118
|
+
const bPart = bParts[index];
|
|
119
|
+
if (aPart === undefined) return -1;
|
|
120
|
+
if (bPart === undefined) return 1;
|
|
121
|
+
if (aPart === bPart) continue;
|
|
122
|
+
const aNumeric = /^\d+$/.test(aPart);
|
|
123
|
+
const bNumeric = /^\d+$/.test(bPart);
|
|
124
|
+
if (aNumeric && bNumeric) return Number(aPart) > Number(bPart) ? 1 : -1;
|
|
125
|
+
if (aNumeric !== bNumeric) return aNumeric ? -1 : 1;
|
|
126
|
+
return aPart.localeCompare(bPart);
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function managedPrefix(packageRoot: string = PACKAGE_ROOT, env: NodeJS.ProcessEnv = process.env): string | null {
|
|
132
|
+
if (env.CAUSYNE_INSTALL_ROOT) return path.resolve(env.CAUSYNE_INSTALL_ROOT);
|
|
133
|
+
|
|
134
|
+
const markers = [
|
|
135
|
+
path.join('lib', 'node_modules', '@causyne', 'agent'),
|
|
136
|
+
path.join('node_modules', '@causyne', 'agent')
|
|
137
|
+
];
|
|
138
|
+
for (const marker of markers) {
|
|
139
|
+
const index = packageRoot.lastIndexOf(marker);
|
|
140
|
+
if (index >= 0 && index + marker.length === packageRoot.length) {
|
|
141
|
+
return packageRoot.slice(0, index).replace(/[\\/]$/, '');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function resolveNpmExecutable(env: NodeJS.ProcessEnv = process.env): string {
|
|
148
|
+
if (env.CAUSYNE_NPM_COMMAND && String(env.CAUSYNE_NPM_COMMAND).trim()) {
|
|
149
|
+
return String(env.CAUSYNE_NPM_COMMAND).trim();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const isWin = process.platform === 'win32';
|
|
153
|
+
const npmName = isWin ? 'npm.cmd' : 'npm';
|
|
154
|
+
|
|
155
|
+
// 1. Sibling of running node binary (most reliable across all Node version managers: nvm, fnm, volta, mise)
|
|
156
|
+
if (process.execPath) {
|
|
157
|
+
const sibling = path.join(path.dirname(process.execPath), npmName);
|
|
158
|
+
if (fs.existsSync(sibling)) {
|
|
159
|
+
return sibling;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 2. Private Causyne runtime if provisioned
|
|
164
|
+
const privateNpm = path.join(causyneHome(), 'runtime', 'node', isWin ? '' : 'bin', npmName);
|
|
165
|
+
if (fs.existsSync(privateNpm)) {
|
|
166
|
+
return privateNpm;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 3. Default fallback to system PATH
|
|
170
|
+
return npmName;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function installationInfo(options: { env?: NodeJS.ProcessEnv; packageRoot?: string } = {}): InstallationInfo {
|
|
174
|
+
const env = options.env || process.env;
|
|
175
|
+
const packageRoot = options.packageRoot || PACKAGE_ROOT;
|
|
176
|
+
const prefix = managedPrefix(packageRoot, env);
|
|
177
|
+
const npmCommand = resolveNpmExecutable(env);
|
|
178
|
+
return {
|
|
179
|
+
managed: Boolean(prefix),
|
|
180
|
+
type: env.CAUSYNE_INSTALL_ROOT ? 'causyne.com installer' : (prefix ? 'global npm' : 'source checkout'),
|
|
181
|
+
prefix,
|
|
182
|
+
packageRoot,
|
|
183
|
+
npmCommand
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function readState(options: { stateFile?: string; env?: NodeJS.ProcessEnv } = {}): UpdateState {
|
|
188
|
+
try {
|
|
189
|
+
return JSON.parse(fs.readFileSync(updateStateFile(options), 'utf8')) as UpdateState;
|
|
190
|
+
} catch {
|
|
191
|
+
return {};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function writeState(state: UpdateState, options: { stateFile?: string; env?: NodeJS.ProcessEnv } = {}): void {
|
|
196
|
+
try {
|
|
197
|
+
const stateFile = updateStateFile(options);
|
|
198
|
+
fs.mkdirSync(path.dirname(stateFile), { recursive: true, mode: 0o700 });
|
|
199
|
+
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), { mode: 0o600 });
|
|
200
|
+
} catch {
|
|
201
|
+
// Update state is an optimisation. Failure must never stop the CLI.
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function latestPackageVersion(options: CheckUpdateOptions = {}): Promise<string> {
|
|
206
|
+
const fetchImpl = options.fetchImpl || globalThis.fetch;
|
|
207
|
+
if (typeof fetchImpl !== 'function') throw new Error('This Node.js runtime has no fetch implementation.');
|
|
208
|
+
const timeoutMs = options.timeoutMs || 3500;
|
|
209
|
+
const signal = options.signal || AbortSignal.timeout(timeoutMs);
|
|
210
|
+
const response = await fetchImpl(REGISTRY_LATEST, {
|
|
211
|
+
headers: { accept: 'application/json', 'user-agent': `causyne/${getPackageVersion()}` },
|
|
212
|
+
signal
|
|
213
|
+
});
|
|
214
|
+
if (!response.ok) throw new Error(`npm registry returned HTTP ${response.status}`);
|
|
215
|
+
const metadata = (await response.json()) as { name?: string; version?: string };
|
|
216
|
+
if (metadata.name !== PACKAGE_NAME || !versionParts(metadata.version)) {
|
|
217
|
+
throw new Error('npm registry returned invalid package metadata');
|
|
218
|
+
}
|
|
219
|
+
return metadata.version as string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function installLatest(info: InstallationInfo, options: SelfUpdateOptions = {}): void {
|
|
223
|
+
if (!info.prefix) {
|
|
224
|
+
throw new Error('Cannot install package: prefix is not defined for this installation.');
|
|
225
|
+
}
|
|
226
|
+
const runner = options.spawnSyncImpl || spawnSync;
|
|
227
|
+
const targetVersion = options.version;
|
|
228
|
+
if (!targetVersion) {
|
|
229
|
+
throw new Error('Target version must be specified for installation.');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const args = [
|
|
233
|
+
'install', '--global', '--prefix', info.prefix,
|
|
234
|
+
`${PACKAGE_NAME}@${targetVersion}`, '--ignore-scripts', '--no-audit', '--no-fund'
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
// Prepend the directory containing node and npm to PATH so child npm executes smoothly
|
|
238
|
+
const env = { ...(options.env || process.env) };
|
|
239
|
+
const extraPaths = [path.dirname(process.execPath)];
|
|
240
|
+
if (info.npmCommand.includes('/') || info.npmCommand.includes('\\')) {
|
|
241
|
+
extraPaths.push(path.dirname(info.npmCommand));
|
|
242
|
+
}
|
|
243
|
+
const delimiter = process.platform === 'win32' ? ';' : ':';
|
|
244
|
+
const currentPath = env.PATH || env.Path || '';
|
|
245
|
+
env.PATH = [...extraPaths, currentPath].filter(Boolean).join(delimiter);
|
|
246
|
+
|
|
247
|
+
const result = runner(info.npmCommand, args, {
|
|
248
|
+
shell: false,
|
|
249
|
+
stdio: options.verbose ? 'inherit' : 'pipe',
|
|
250
|
+
encoding: 'utf8',
|
|
251
|
+
env
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
if (result.error) throw result.error;
|
|
255
|
+
if (result.status !== 0) {
|
|
256
|
+
const detail = String(result.stderr || result.stdout || '').trim();
|
|
257
|
+
throw new Error(detail || `npm exited with status ${result.status}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function checkForUpdate(options: CheckUpdateOptions = {}): Promise<CheckResult> {
|
|
262
|
+
const current = options.currentVersion || getPackageVersion();
|
|
263
|
+
const latest = await latestPackageVersion(options);
|
|
264
|
+
return { current, latest, available: compareVersions(latest, current) > 0 };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export async function runSelfUpdate(verbose: boolean = false, options: SelfUpdateOptions = {}): Promise<UpdateResult> {
|
|
268
|
+
const info = installationInfo(options);
|
|
269
|
+
if (!info.managed) {
|
|
270
|
+
if (verbose) UI.printInfo('This is a source checkout. Update it with Git; Causyne will not rewrite developer source.');
|
|
271
|
+
return { updated: false, reason: 'source-checkout', ...info };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
const status = await checkForUpdate(options);
|
|
276
|
+
if (!status.available) {
|
|
277
|
+
writeState({ checkedAt: Date.now(), latest: status.latest }, options);
|
|
278
|
+
if (verbose) UI.printSuccess(`Causyne ${status.current} is up to date.`);
|
|
279
|
+
return { updated: false, reason: 'current', ...status, ...info };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (verbose) UI.printInfo(`Updating Causyne ${status.current} → ${status.latest}...`);
|
|
283
|
+
installLatest(info, { ...options, version: status.latest, verbose });
|
|
284
|
+
writeState({ checkedAt: Date.now(), latest: status.latest, installedAt: Date.now() }, options);
|
|
285
|
+
if (verbose) UI.printSuccess(`Updated to Causyne ${status.latest}.`);
|
|
286
|
+
return { updated: true, ...status, ...info };
|
|
287
|
+
} catch (error) {
|
|
288
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
+
writeState({ checkedAt: Date.now(), error: message }, options);
|
|
290
|
+
if (verbose) UI.printError(`Update failed: ${message}`);
|
|
291
|
+
return { updated: false, reason: 'failed', error: message, ...info };
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Check on launch, defaulting to at most once per hour with fast retry on error. */
|
|
296
|
+
export async function startUpdateChecker(options: SelfUpdateOptions = {}): Promise<UpdateResult> {
|
|
297
|
+
const env = options.env || process.env;
|
|
298
|
+
if (env.CAUSYNE_DISABLE_AUTOUPDATE === '1' || env.CAUSYNE_DISABLE_AUTOUPDATE === 'true') {
|
|
299
|
+
return {
|
|
300
|
+
updated: false,
|
|
301
|
+
reason: 'disabled',
|
|
302
|
+
managed: false,
|
|
303
|
+
type: 'source checkout',
|
|
304
|
+
prefix: null,
|
|
305
|
+
packageRoot: PACKAGE_ROOT,
|
|
306
|
+
npmCommand: resolveNpmExecutable(env)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const info = installationInfo(options);
|
|
311
|
+
if (!info.managed) return { updated: false, reason: 'source-checkout', ...info };
|
|
312
|
+
|
|
313
|
+
const customInterval = Number(env.CAUSYNE_UPDATE_INTERVAL_MS);
|
|
314
|
+
const checkInterval = Number.isFinite(customInterval) && customInterval > 0
|
|
315
|
+
? customInterval
|
|
316
|
+
: DEFAULT_CHECK_INTERVAL_MS;
|
|
317
|
+
|
|
318
|
+
const state = readState(options);
|
|
319
|
+
if (!options.force && Number.isFinite(state.checkedAt)) {
|
|
320
|
+
const elapsed = Date.now() - (state.checkedAt as number);
|
|
321
|
+
const intervalToUse = state.error ? ERROR_RETRY_INTERVAL_MS : checkInterval;
|
|
322
|
+
if (elapsed < intervalToUse) {
|
|
323
|
+
return { updated: false, reason: 'recently-checked', latest: state.latest, ...info };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return runSelfUpdate(false, options);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export async function diagnoseInstallation(options: CheckUpdateOptions = {}): Promise<DiagnosisResult> {
|
|
331
|
+
const info = installationInfo(options);
|
|
332
|
+
let update: CheckResult | { current: string; latest: null; available: false; error: string };
|
|
333
|
+
try {
|
|
334
|
+
update = await checkForUpdate(options);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
337
|
+
update = { current: getPackageVersion(), latest: null, available: false, error: message };
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
...info,
|
|
341
|
+
...update,
|
|
342
|
+
autoUpdates: !['1', 'true'].includes(String((options.env || process.env).CAUSYNE_DISABLE_AUTOUPDATE || '').toLowerCase())
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function formatDoctorReport(status: DiagnosisResult, runtime: typeof process = process): string {
|
|
347
|
+
const rows = [
|
|
348
|
+
`Version : ${status.current || 'unknown'}`,
|
|
349
|
+
`Latest : ${status.latest || `unavailable (${status.error || 'unknown error'})`}`,
|
|
350
|
+
`Installation : ${status.type}`,
|
|
351
|
+
`Package root : ${status.packageRoot}`,
|
|
352
|
+
`NPM command : ${status.npmCommand}`,
|
|
353
|
+
`Node.js : ${runtime.version}`,
|
|
354
|
+
`Platform : ${runtime.platform} ${runtime.arch}`,
|
|
355
|
+
`Auto updates : ${status.autoUpdates ? 'enabled' : 'disabled'}`,
|
|
356
|
+
`Workspace : ${runtime.cwd()}`
|
|
357
|
+
];
|
|
358
|
+
if (status.available) rows.push('Update : available — run `causyne update`');
|
|
359
|
+
return rows.join('\n');
|
|
360
|
+
}
|
|
@@ -63,10 +63,24 @@ export class SovereignReverseHarness {
|
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
const nodeDir = path.dirname(process.execPath);
|
|
67
|
+
const homeDir = process.env.HOME || '';
|
|
68
|
+
const buildToolsDirs = [
|
|
69
|
+
path.join(homeDir, 'Library/Android/sdk/build-tools/36.1.0'),
|
|
70
|
+
path.join(homeDir, 'Library/Android/sdk/build-tools/35.0.0'),
|
|
71
|
+
path.join(homeDir, 'Library/Android/sdk/platform-tools'),
|
|
72
|
+
'/opt/homebrew/bin',
|
|
73
|
+
'/usr/local/bin'
|
|
74
|
+
].filter(d => fs.existsSync(d));
|
|
75
|
+
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].join(':');
|
|
66
76
|
const mcpClient = new McpClient({
|
|
67
77
|
name: 'causyne_reverse_engineering',
|
|
68
78
|
command,
|
|
69
79
|
args,
|
|
80
|
+
env: {
|
|
81
|
+
...process.env,
|
|
82
|
+
PATH: augmentedPath
|
|
83
|
+
},
|
|
70
84
|
timeoutMs: 60_000
|
|
71
85
|
});
|
|
72
86
|
await mcpClient.connect();
|
|
@@ -163,15 +177,23 @@ export class SovereignReverseHarness {
|
|
|
163
177
|
const ext = path.extname(resolved).toLowerCase();
|
|
164
178
|
if (ext === '.apk' || ext === '.aab') {
|
|
165
179
|
const pkg = await this.callEngineTool('inspect_android_package', { path: resolved }, signal);
|
|
166
|
-
if (pkg.success)
|
|
180
|
+
if (pkg.success && pkg.output && !pkg.output.includes('capability_unavailable') && !pkg.output.includes('REA_JADX_MCP_JAR')) {
|
|
167
181
|
return pkg;
|
|
182
|
+
}
|
|
168
183
|
const dec = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
169
|
-
if (dec.success)
|
|
184
|
+
if (dec.success && dec.output && !dec.output.includes('capability_unavailable') && !dec.output.includes('apktool launcher was not found')) {
|
|
170
185
|
return dec;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
toolName: 'inspect_android_package',
|
|
190
|
+
error: 'Engine APK tools unavailable; delegating to sovereign native inspector.',
|
|
191
|
+
source: 'fallback'
|
|
192
|
+
};
|
|
171
193
|
}
|
|
172
194
|
// Try primary session / overview tools
|
|
173
195
|
const open = await this.callEngineTool('open_binary', { path: resolved }, signal);
|
|
174
|
-
if (open.success)
|
|
196
|
+
if (open.success && open.output && !open.output.includes('"architecture":null'))
|
|
175
197
|
return open;
|
|
176
198
|
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
177
199
|
if (layout.success)
|
|
@@ -80,10 +80,26 @@ export class SovereignReverseHarness {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
const nodeDir = path.dirname(process.execPath);
|
|
84
|
+
const homeDir = process.env.HOME || '';
|
|
85
|
+
const buildToolsDirs = [
|
|
86
|
+
path.join(homeDir, 'Library/Android/sdk/build-tools/36.1.0'),
|
|
87
|
+
path.join(homeDir, 'Library/Android/sdk/build-tools/35.0.0'),
|
|
88
|
+
path.join(homeDir, 'Library/Android/sdk/platform-tools'),
|
|
89
|
+
'/opt/homebrew/bin',
|
|
90
|
+
'/usr/local/bin'
|
|
91
|
+
].filter(d => fs.existsSync(d));
|
|
92
|
+
|
|
93
|
+
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].join(':');
|
|
94
|
+
|
|
83
95
|
const mcpClient = new McpClient({
|
|
84
96
|
name: 'causyne_reverse_engineering',
|
|
85
97
|
command,
|
|
86
98
|
args,
|
|
99
|
+
env: {
|
|
100
|
+
...process.env,
|
|
101
|
+
PATH: augmentedPath
|
|
102
|
+
},
|
|
87
103
|
timeoutMs: 60_000
|
|
88
104
|
});
|
|
89
105
|
|
|
@@ -186,15 +202,26 @@ export class SovereignReverseHarness {
|
|
|
186
202
|
const ext = path.extname(resolved).toLowerCase();
|
|
187
203
|
if (ext === '.apk' || ext === '.aab') {
|
|
188
204
|
const pkg = await this.callEngineTool('inspect_android_package', { path: resolved }, signal);
|
|
189
|
-
if (pkg.success)
|
|
205
|
+
if (pkg.success && pkg.output && !pkg.output.includes('capability_unavailable') && !pkg.output.includes('REA_JADX_MCP_JAR')) {
|
|
206
|
+
return pkg;
|
|
207
|
+
}
|
|
190
208
|
|
|
191
209
|
const dec = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
192
|
-
if (dec.success)
|
|
210
|
+
if (dec.success && dec.output && !dec.output.includes('capability_unavailable') && !dec.output.includes('apktool launcher was not found')) {
|
|
211
|
+
return dec;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
success: false,
|
|
216
|
+
toolName: 'inspect_android_package',
|
|
217
|
+
error: 'Engine APK tools unavailable; delegating to sovereign native inspector.',
|
|
218
|
+
source: 'fallback'
|
|
219
|
+
};
|
|
193
220
|
}
|
|
194
221
|
|
|
195
222
|
// Try primary session / overview tools
|
|
196
223
|
const open = await this.callEngineTool('open_binary', { path: resolved }, signal);
|
|
197
|
-
if (open.success) return open;
|
|
224
|
+
if (open.success && open.output && !open.output.includes('"architecture":null')) return open;
|
|
198
225
|
|
|
199
226
|
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
200
227
|
if (layout.success) return layout;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { formatToolContracts, toolContractUpdate, contractFingerprint } from './toolContracts.js';
|
|
2
|
-
|
|
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
|
|
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 =
|
|
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
|
|
1207
|
-
|
|
1208
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
|
1262
|
-
|
|
1263
|
-
|
|
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);
|
package/src/smartToolsUse.js
CHANGED
|
@@ -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
|
|
134
|
-
const
|
|
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.
|
|
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',
|