@causyne/agent 1.20.118 → 1.20.121
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/package.json +1 -1
- package/src/agent/errorClassifier.js +113 -0
- package/src/agent/errorClassifier.ts +161 -0
- package/src/agent/promptIntent.js +200 -0
- package/src/agent/promptIntent.ts +203 -0
- package/src/agent/toolArgValidator.js +97 -0
- package/src/agent/toolArgValidator.ts +112 -0
- package/src/agentLoop.js +51 -351
- package/src/agentLoop.ts +69 -363
- package/src/autoUpdate.js +111 -8
- package/src/autoUpdate.ts +144 -8
- package/src/browser/causyneBrowser.js +231 -136
- package/src/browser/causyneBrowser.ts +229 -140
- package/src/browser/searchProviders.js +41 -30
- package/src/browser/searchProviders.ts +24 -14
- package/src/browser/workspacePathSafety.js +50 -0
- package/src/browser/workspacePathSafety.ts +50 -0
- package/src/browser/workspacePreview.js +27 -4
- package/src/browser/workspacePreview.ts +28 -4
- package/src/cliMode.js +17 -3
- package/src/commands.js +15 -22
- package/src/config.js +42 -63
- package/src/configVault.js +204 -0
- package/src/configVault.ts +213 -0
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/creative/liveBridge.js +34 -1
- package/src/creative/liveBridge.ts +28 -1
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +304 -0
- package/src/headlessCli.ts +380 -0
- package/src/mcp/mcpClient.js +38 -11
- package/src/mcp/mcpClient.ts +44 -11
- package/src/mcp/mcpRegistry.js +2 -5
- package/src/mcp/mcpRegistry.ts +2 -5
- package/src/mcp/mcpSecurity.js +189 -0
- package/src/mcp/mcpSecurity.ts +190 -0
- package/src/observer/evidence.js +23 -0
- package/src/observer/evidence.ts +21 -0
- package/src/osKeychain.js +209 -0
- package/src/osKeychain.ts +245 -0
- package/src/providers/anthropic.js +61 -28
- package/src/providers/base.js +14 -0
- package/src/providers/byokHttp.js +354 -0
- package/src/providers/byokHttp.ts +454 -0
- package/src/providers/byokStream.js +657 -0
- package/src/providers/byokStream.ts +759 -0
- package/src/providers/dashscope-byok.js +47 -32
- package/src/providers/deepseek.js +43 -39
- package/src/providers/gemini.js +73 -38
- package/src/providers/moonshot.js +43 -33
- package/src/providers/muse.js +10 -10
- package/src/providers/ollama.js +46 -31
- package/src/providers/openai-compatible.js +57 -32
- package/src/providers/openrouter.js +77 -113
- package/src/providers/openrouter.ts +99 -118
- package/src/providers/qwen-byok.js +46 -23
- package/src/providers/toolContracts.js +9 -3
- package/src/providers/toolContracts.ts +9 -3
- package/src/providers/wireNormalizer.js +238 -0
- package/src/providers/wireNormalizer.ts +279 -0
- package/src/providers/xai.js +43 -33
- package/src/sandbox.js +77 -56
- package/src/sandboxPolicy.js +1208 -0
- package/src/sandboxPolicy.ts +1300 -0
- package/src/sessionJournal.js +47 -0
- package/src/sessionJournal.ts +49 -0
- package/src/tools/browserAutomator.js +13 -1
- package/src/tools/browserAutomator.ts +13 -0
- package/src/tools/creativeApps.js +2 -1
- package/src/tools/creativeApps.ts +2 -1
- package/src/tools/gameAssetFetcher.js +130 -26
- package/src/tools/gameAssetHarvester.js +80 -58
- package/src/tools/nativeEngine.js +1 -1
- package/src/tools/nativeEngine.ts +1 -1
- package/src/tools/osSandbox.js +473 -0
- package/src/tools/osSandbox.ts +554 -0
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/registry.js +13 -0
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +39 -6
- package/src/tools/sysRun.ts +53 -7
- package/src/tools/toolScanner.js +596 -140
- package/src/tools/toolScanner.ts +665 -147
- package/src/tools/toolSelfRepair.js +243 -114
- package/src/tools/toolSelfRepair.ts +262 -111
- package/src/tools/webFetch.js +161 -24
- package/src/tools/webFetch.ts +157 -22
- package/src/tools/webSearch.js +33 -4
- package/src/tools/webSearch.ts +27 -4
- package/src/tui/sessionPicker.js +132 -35
- package/src/tui/sessionPicker.ts +153 -32
- package/src/tui/sessionPickerView.js +277 -34
- package/src/tui/sessionPickerView.ts +328 -34
- package/src/tui/statusLine.js +3 -0
- package/src/tui/statusLine.ts +5 -0
- package/src/tui/workspaceIdentity.js +133 -0
- package/src/tui/workspaceIdentity.ts +146 -0
package/src/agentLoop.ts
CHANGED
|
@@ -6,6 +6,19 @@ import { getProcessEntitlementGate, EntitlementAccessError } from './licensing/e
|
|
|
6
6
|
import { repairUnansweredToolCalls, validateToolCallBatch } from './agent/toolTurnIntegrity.js';
|
|
7
7
|
import { waitForAbortableDelay } from './agent/abortableDelay.js';
|
|
8
8
|
import { normalizeAgentFailure } from './agent/providerFailure.js';
|
|
9
|
+
import { classifyAgentError, getRetryHintForError } from './agent/errorClassifier.js';
|
|
10
|
+
import {
|
|
11
|
+
isActionableTaskPrompt,
|
|
12
|
+
isGenericHandoffResponse,
|
|
13
|
+
isDesktopWallpaperChangePrompt,
|
|
14
|
+
isExecutionOrLaunchTaskPrompt,
|
|
15
|
+
isCodeAuthoringTaskPrompt,
|
|
16
|
+
extractSkillIdFromPrompt,
|
|
17
|
+
isDirectGameTask,
|
|
18
|
+
isProviderPlanOrQuotaRefusal,
|
|
19
|
+
isMidTaskProgressText
|
|
20
|
+
} from './agent/promptIntent.js';
|
|
21
|
+
import { validateAndNormalizeToolArgs } from './agent/toolArgValidator.js';
|
|
9
22
|
import { resolveTaskTokenCeiling, peerCallTokenCeiling, isAntigravityPeer, isTerminalBudgetFailure, desktopDeadline, remainingDesktopTime, DEFAULT_AGY_TASK_TOKENS } from './budget/budgetPolicy.js';
|
|
10
23
|
import { PEER_COLLABORATION_POLICY } from './providers/collaborationPolicy.js';
|
|
11
24
|
import type { RequestPermissionRequest, RequestPermissionResponse } from './acp/protocol.js';
|
|
@@ -17,6 +30,7 @@ import { WorkspacePerception } from './perception.js';
|
|
|
17
30
|
import { audioFormatForMimeType } from './providers/base.js';
|
|
18
31
|
import { TaskBuffer } from './taskBuffer.js';
|
|
19
32
|
import { TOOL_DEFINITIONS, getDynamicTools, getSearchableToolDefinitions, resolveTool, canonicalToolName } from './tools/registry.js';
|
|
33
|
+
import { scanAndAdaptToolsForProvider } from './tools/toolScanner.js';
|
|
20
34
|
import { selfRepairToolCall, generateSelfRepairDiagnostic } from './tools/toolSelfRepair.js';
|
|
21
35
|
import { validateToolArguments } from './tools/argumentValidation.js';
|
|
22
36
|
import { Sandbox } from './sandbox.js';
|
|
@@ -52,7 +66,7 @@ import { requiresToolApproval, withToolAutonomyMode } from './approvalPolicy.js'
|
|
|
52
66
|
import { AGENT_USER_POLICY } from './agentPolicy.js';
|
|
53
67
|
import { VFETracker } from './vfeTracker.js';
|
|
54
68
|
import { coldObserver } from './observer/coldObserver.js';
|
|
55
|
-
import { isRenderedNativeBrowserAction, isVerificationCommand } from './observer/evidence.js';
|
|
69
|
+
import { inspectBrowserToolEvidence, isRenderedNativeBrowserAction, isVerificationCommand } from './observer/evidence.js';
|
|
56
70
|
import { CausyneObserver, defaultObserver, extractClaimedLocalUrls } from './observer.js';
|
|
57
71
|
import type { Observation } from './observer.js';
|
|
58
72
|
import { TimeMachine, recoveryUserMessage, TIME_MACHINE_MAX_ATTEMPTS } from './timeMachine.js';
|
|
@@ -75,7 +89,7 @@ import { buildToolsList, renderToolsList, omittedCustomCount } from './toolsList
|
|
|
75
89
|
import type { ToolListEntry } from './toolsList.js';
|
|
76
90
|
import { assessVerification } from './verificationPlan.js';
|
|
77
91
|
import { SmartTools } from './SmartTools.js';
|
|
78
|
-
import { decideTools
|
|
92
|
+
import { decideTools } from './decideTools.js';
|
|
79
93
|
import type { DecideToolsInput } from './decideTools.js';
|
|
80
94
|
import { SavedTools, readSavedTools, writeSavedTools } from './saveTools.js';
|
|
81
95
|
import type { AdmissionResult } from './saveTools.js';
|
|
@@ -175,40 +189,21 @@ export interface AgentLoopOptions {
|
|
|
175
189
|
workspaceRoot?: string;
|
|
176
190
|
memorySessionId?: string | null;
|
|
177
191
|
approvalScope?: AgentLoopApprovalScope;
|
|
192
|
+
provider?: string;
|
|
193
|
+
model?: string;
|
|
178
194
|
}
|
|
179
195
|
|
|
180
|
-
export
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function isGenericHandoffResponse(text: string): boolean {
|
|
193
|
-
const answer = (text || '').trim();
|
|
194
|
-
if (!answer || answer.length > 500) return false;
|
|
195
|
-
const lower = answer.toLowerCase();
|
|
196
|
-
const handoff = /\b(let me know what you would like to do next|what would you like me to do next|how (can|may) i help|what can i help you with|feel free to (ask|tell me))\b/i.test(lower);
|
|
197
|
-
const verifiedOutcome = /\b(completed|changed|set the (desktop|wallpaper)|saved|created|installed|verified|downloaded|finished)\b/i.test(lower);
|
|
198
|
-
return handoff && !verifiedOutcome;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function isDesktopWallpaperChangePrompt(text: string): boolean {
|
|
202
|
-
const t = (text || '').trim();
|
|
203
|
-
if (!t) return false;
|
|
204
|
-
// Explanatory questions or prompts that explicitly forbid execution are never wallpaper mutation requests
|
|
205
|
-
if (isNoExecutionPrompt(t) || isReadOnlyOrExplanatoryPrompt(t)) return false;
|
|
206
|
-
if (/^(?:why|how|what|does|can\s+you\s+explain|explain|tell\s+me|show\s+me\s+how)\b/i.test(t)) return false;
|
|
207
|
-
if (/\b(?:why|how)\s+does\b/i.test(t)) return false;
|
|
208
|
-
// Debugging wallpaper-related source or regexes is not a request to mutate macOS.
|
|
209
|
-
if (/\b(?:test|review|audit|analy[sz]e|debug|refactor|inspect|explain|write|implement)\b[\s\S]{0,140}\b(?:regex|code|source|logic|verification|readback|function|script|test)\b/i.test(t)) return false;
|
|
210
|
-
return /\b(?:change|set|switch|replace)\s+(?:(?:my|the|this|current|desktop|mac|macos)\s+){0,4}(?:desktop picture|wallpaper|desktop background)\b/i.test(t);
|
|
211
|
-
}
|
|
196
|
+
export {
|
|
197
|
+
isActionableTaskPrompt,
|
|
198
|
+
isGenericHandoffResponse,
|
|
199
|
+
isDesktopWallpaperChangePrompt,
|
|
200
|
+
isExecutionOrLaunchTaskPrompt,
|
|
201
|
+
isCodeAuthoringTaskPrompt,
|
|
202
|
+
extractSkillIdFromPrompt,
|
|
203
|
+
isDirectGameTask,
|
|
204
|
+
isProviderPlanOrQuotaRefusal,
|
|
205
|
+
isMidTaskProgressText
|
|
206
|
+
};
|
|
212
207
|
|
|
213
208
|
function readMacDesktopPictures(): string | null {
|
|
214
209
|
try {
|
|
@@ -220,169 +215,6 @@ function readMacDesktopPictures(): string | null {
|
|
|
220
215
|
}
|
|
221
216
|
}
|
|
222
217
|
|
|
223
|
-
export function isExecutionOrLaunchTaskPrompt(text: string): boolean {
|
|
224
|
-
const t = (text || '').trim();
|
|
225
|
-
if (!t) return false;
|
|
226
|
-
return /\b(open|launch|start|run|play|serve|preview)\b/i.test(t)
|
|
227
|
-
&& !/\b(create|build|make|write|code|implement|generate|refactor)\b/i.test(t);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function isCodeAuthoringTaskPrompt(text: string): boolean {
|
|
231
|
-
const t = (text || '').trim();
|
|
232
|
-
if (!t) return false;
|
|
233
|
-
if (isExecutionOrLaunchTaskPrompt(t)) return false;
|
|
234
|
-
return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function extractSkillIdFromPrompt(prompt: string): string {
|
|
238
|
-
const text = String(prompt || '').trim();
|
|
239
|
-
if (!text) return '';
|
|
240
|
-
const stopWords = new Set([
|
|
241
|
-
'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
|
|
242
|
-
'using', 'for', 'to', 'by', 'and', 'or', 'of'
|
|
243
|
-
]);
|
|
244
|
-
const leadingTrim = new Set(['`', '"', "'", '(', '[']);
|
|
245
|
-
const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
|
|
246
|
-
const cleanCandidate = (raw: string): string => {
|
|
247
|
-
const trimmed = raw.trim();
|
|
248
|
-
let start = 0;
|
|
249
|
-
let end = trimmed.length;
|
|
250
|
-
while (start < end && leadingTrim.has(trimmed[start]!)) start++;
|
|
251
|
-
while (end > start && trailingTrim.has(trimmed[end - 1]!)) end--;
|
|
252
|
-
const stripped = trimmed.slice(start, end);
|
|
253
|
-
if (!stripped || stopWords.has(stripped.toLowerCase())) return '';
|
|
254
|
-
if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
|
|
255
|
-
return '';
|
|
256
|
-
}
|
|
257
|
-
return stripped;
|
|
258
|
-
};
|
|
259
|
-
const isFileExt = (candidate: string): boolean =>
|
|
260
|
-
/\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
|
|
261
|
-
|
|
262
|
-
const cuedSlashMatch = text.match(
|
|
263
|
-
/(?:\bskill_id|\bskill|\bfs_read_skil{1,2})(?:\s*[:=]\s*|\s+)[`"']?([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})[`"']?/i
|
|
264
|
-
);
|
|
265
|
-
if (cuedSlashMatch?.[1]) {
|
|
266
|
-
const candidate = cleanCandidate(cuedSlashMatch[1]);
|
|
267
|
-
if (candidate && !isFileExt(candidate)) {
|
|
268
|
-
return candidate;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
for (const m of text.matchAll(/\b([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})\b/g)) {
|
|
272
|
-
const candidate = cleanCandidate(m[1] || '');
|
|
273
|
-
if (candidate && !isFileExt(candidate)) {
|
|
274
|
-
return candidate;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
const explicitQuotedMatch = text.match(
|
|
278
|
-
/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i
|
|
279
|
-
);
|
|
280
|
-
if (explicitQuotedMatch?.[1]) {
|
|
281
|
-
const candidate = cleanCandidate(explicitQuotedMatch[1]);
|
|
282
|
-
if (candidate) return candidate;
|
|
283
|
-
}
|
|
284
|
-
const bareMatch = text.match(
|
|
285
|
-
/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i
|
|
286
|
-
);
|
|
287
|
-
if (bareMatch?.[1]) {
|
|
288
|
-
const candidate = cleanCandidate(bareMatch[1]);
|
|
289
|
-
if (candidate) return candidate;
|
|
290
|
-
}
|
|
291
|
-
return '';
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export function isDirectGameTask(text: string): boolean {
|
|
295
|
-
return isDirectGameTaskDecision(text);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function isProviderPlanOrQuotaRefusal(text: string): boolean {
|
|
299
|
-
if (!text || typeof text !== 'string') return false;
|
|
300
|
-
const trimmed = text.trim();
|
|
301
|
-
if (!trimmed || trimmed.length > 320) return false;
|
|
302
|
-
if (/^upgrade your plan to continue\.?$/i.test(trimmed)) return true;
|
|
303
|
-
return /\b(upgrade your plan to continue|insufficient[_ ]quota|credit balance is too low|billing hard limit|quota exceeded for|plan limit reached|subscription required to continue)\b/i.test(trimmed);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Detects when an agent response is an intermediate mid-task progress note or
|
|
308
|
-
* transition announcement (e.g. "Real assets verified. Writing the Tesla-style
|
|
309
|
-
* redesign now." or "Let me look at the newer assets... Pulling their real
|
|
310
|
-
* stills and confirming embeddability.") rather than a finished answer.
|
|
311
|
-
*/
|
|
312
|
-
export function isMidTaskProgressText(text: string): boolean {
|
|
313
|
-
if (!text || typeof text !== 'string') return false;
|
|
314
|
-
const trimmed = text.trim();
|
|
315
|
-
if (!trimmed || trimmed.length > 480) return false;
|
|
316
|
-
|
|
317
|
-
const lower = trimmed.toLowerCase();
|
|
318
|
-
if (
|
|
319
|
-
lower.includes('?') ||
|
|
320
|
-
lower.includes('let me know') ||
|
|
321
|
-
lower.includes('how can i help') ||
|
|
322
|
-
lower.includes('how may i help') ||
|
|
323
|
-
lower.includes('how can i assist') ||
|
|
324
|
-
lower.includes('what would you like') ||
|
|
325
|
-
lower.includes('what can i help') ||
|
|
326
|
-
lower.includes('feel free to')
|
|
327
|
-
) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (trimmed.includes('```')) return false;
|
|
332
|
-
|
|
333
|
-
const sentences = trimmed
|
|
334
|
-
.split(/(?:(?<=[.!])\s+|\n+)/)
|
|
335
|
-
.map(s => s.trim())
|
|
336
|
-
.filter(Boolean);
|
|
337
|
-
const lastSentence = (sentences[sentences.length - 1] || trimmed).trim();
|
|
338
|
-
const lastLower = lastSentence.toLowerCase();
|
|
339
|
-
|
|
340
|
-
if (trimmed.length <= 280 && (trimmed.endsWith(':') || trimmed.endsWith('...') || trimmed.endsWith('…'))) {
|
|
341
|
-
return true;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const intentPrefixes = [
|
|
345
|
-
'let me ',
|
|
346
|
-
"i'll ",
|
|
347
|
-
'i will ',
|
|
348
|
-
'now i ',
|
|
349
|
-
'now let me ',
|
|
350
|
-
"now i'll ",
|
|
351
|
-
'now i will ',
|
|
352
|
-
'next, i ',
|
|
353
|
-
'next i ',
|
|
354
|
-
"next, i'll ",
|
|
355
|
-
"next i'll ",
|
|
356
|
-
'first, i ',
|
|
357
|
-
'first i ',
|
|
358
|
-
'let us ',
|
|
359
|
-
"let's ",
|
|
360
|
-
'i shall ',
|
|
361
|
-
'we will ',
|
|
362
|
-
"we'll ",
|
|
363
|
-
'i am going to ',
|
|
364
|
-
"i'm going to ",
|
|
365
|
-
'going to '
|
|
366
|
-
];
|
|
367
|
-
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
|
|
368
|
-
if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const gerundStart = /^(?:now\s+|next,?\s+|currently\s+|still\s+)?(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|setting up|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting|installing|opening|switching|retrying|continuing)\b/i;
|
|
374
|
-
if (gerundStart.test(lastSentence) && lastSentence.length <= 220) {
|
|
375
|
-
return true;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const actionNowSuffix = /\b(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting)\b[^.!?\n]{1,120}\b(?:now|next)\.?$/i;
|
|
379
|
-
if (actionNowSuffix.test(lastSentence)) {
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return false;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
218
|
const SYSTEM_PROMPT = `You are Causyne Agent, an autonomous local AI agent. Your capabilities are the tools actually available in this session. Never invent a capability or claim an action occurred without evidence.
|
|
387
219
|
|
|
388
220
|
${PEER_COLLABORATION_POLICY}
|
|
@@ -485,9 +317,10 @@ You possess native reverse engineering capabilities powered by the Reverse Engin
|
|
|
485
317
|
5. **Multiple Emulators/Devices**: When multiple devices or emulators are connected, specify \`-s <serial>\` (e.g. \`adb -s emulator-5554 ...\`) or set \`export ANDROID_SERIAL=<serial>\`.
|
|
486
318
|
|
|
487
319
|
# Universal Tool Calling & Registry Discipline
|
|
488
|
-
1. **Strict Registry Adherence**:
|
|
489
|
-
2. **
|
|
490
|
-
3. **
|
|
320
|
+
1. **Strict Root Registry Adherence**: Invoke ONLY tools registered in the active Causyne catalogue (native, plugin, or MCP) or permitted connected-peer capabilities across ACP/Antigravity/Pi. Use exact canonical parameter names and required fields defined in each tool schema without inventing or renaming parameters.
|
|
321
|
+
2. **Pre-Flight Universal Schema Scan (\`toolsScan\`)**: Before dispatching schemas to any provider API, Causyne scans and compiles every tool declaration into that provider's dialect without reducing or altering underlying tool capability. When an adapted schema asks for a JSON-encoded string on an object, array, or union parameter (e.g. multi-file paths or free-form properties), pass valid JSON so the runtime buffer decodes it transparently to its native type.
|
|
322
|
+
3. **Universal Self-Repair Buffer (\`toolsSelfRepair\`)**: Every tool call is filtered through \`toolsSelfRepair\`, which heals malformed JSON, decodes adapted free-form/polymorphic values, resolves parameter aliases, coerces types recursively, and emits structured \`selfRepairGuidance\` (\`expectedParameters\`) on incomplete invocations. Always read \`expectedParameters\` and re-invoke with the corrected arguments.
|
|
323
|
+
4. **Valid JSON Formatting**: Never emit raw unescaped newlines, single-quoted keys, or trailing commas inside tool call JSON strings.
|
|
491
324
|
|
|
492
325
|
# Completion
|
|
493
326
|
Answer directly when no tool is needed. For action tasks, continue until the authorized work is done or a real blocker is evidenced; then report the verified outcome or blocker concisely.
|
|
@@ -706,11 +539,19 @@ export class AgentLoop {
|
|
|
706
539
|
? options.workspaceRoot
|
|
707
540
|
: process.cwd();
|
|
708
541
|
this.autonomyOverride = null;
|
|
542
|
+
this.providerOverride = typeof options.provider === 'string' && options.provider.trim()
|
|
543
|
+
? options.provider.trim()
|
|
544
|
+
: null;
|
|
545
|
+
this.modelOverride = typeof options.model === 'string' && options.model.trim()
|
|
546
|
+
? options.model.trim()
|
|
547
|
+
: null;
|
|
709
548
|
this.approvalScope = options.approvalScope && typeof options.approvalScope.isAlwaysAllowed === 'function'
|
|
710
549
|
? options.approvalScope
|
|
711
550
|
: processApprovalScope;
|
|
712
551
|
|
|
713
552
|
this.config = loadConfig();
|
|
553
|
+
if (this.providerOverride) this.config.provider = this.providerOverride;
|
|
554
|
+
if (this.modelOverride) this.config.model = this.modelOverride;
|
|
714
555
|
this.sandbox = new Sandbox({ workspaceRoot: this.workspaceRoot });
|
|
715
556
|
|
|
716
557
|
// Retire spilled tool outputs past their retention window. Fire-and-forget
|
|
@@ -762,6 +603,8 @@ export class AgentLoop {
|
|
|
762
603
|
this.stallGuard = new StallGuardController();
|
|
763
604
|
this.smartToolsGovernor = new SmartToolsGovernor(4);
|
|
764
605
|
this._smartToolsNudge = null;
|
|
606
|
+
this.activeFreeFormPaths = new Map<string, string[][]>();
|
|
607
|
+
this._lastToolsScanKey = '';
|
|
765
608
|
|
|
766
609
|
// Sovereign Progressive Disclosure: which capability packs have entered the
|
|
767
610
|
// context window for this task. Nothing is disabled — see src/toolPacks.js.
|
|
@@ -1717,6 +1560,8 @@ export class AgentLoop {
|
|
|
1717
1560
|
updateTierLimits() {
|
|
1718
1561
|
this.config = loadConfig();
|
|
1719
1562
|
if (this.autonomyOverride) this.config.autonomyMode = this.autonomyOverride;
|
|
1563
|
+
if (this.providerOverride) this.config.provider = this.providerOverride;
|
|
1564
|
+
if (this.modelOverride) this.config.model = this.modelOverride;
|
|
1720
1565
|
if (typeof this.initializeProvider === 'function') {
|
|
1721
1566
|
const nextProvider = this.initializeProvider();
|
|
1722
1567
|
if (nextProvider) {
|
|
@@ -2378,6 +2223,22 @@ export class AgentLoop {
|
|
|
2378
2223
|
this.config.grantAllTools === true);
|
|
2379
2224
|
const dynamicToolNames = dynamicTools.map((t: any) => t.name);
|
|
2380
2225
|
|
|
2226
|
+
// Pre-flight universal schema audit (toolsScan): verify dialect readiness and cache
|
|
2227
|
+
// adapted free-form/polymorphic paths for lossless decoding inside toolsSelfRepair.
|
|
2228
|
+
const activeProviderName = String(this.config?.provider || 'openai');
|
|
2229
|
+
const scanKey = `${activeProviderName}:${dynamicToolNames.join(',')}`;
|
|
2230
|
+
if (scanKey !== this._lastToolsScanKey) {
|
|
2231
|
+
const preflightScan = scanAndAdaptToolsForProvider(dynamicTools, activeProviderName);
|
|
2232
|
+
this.activeFreeFormPaths = preflightScan.freeFormPaths;
|
|
2233
|
+
this._lastToolsScanKey = scanKey;
|
|
2234
|
+
if (preflightScan.repairedCount > 0) {
|
|
2235
|
+
this.debugLog(`[toolsScan] Pre-flight compiled ${preflightScan.repairedCount}/${preflightScan.totalTools} schemas for '${activeProviderName}' (universalReady=${preflightScan.universalReady})`);
|
|
2236
|
+
}
|
|
2237
|
+
if (!preflightScan.universalReady) {
|
|
2238
|
+
this.debugLog(`[toolsScan] Residual compatibility issues on '${activeProviderName}': ${preflightScan.residualIssues.slice(0, 5).map((issue) => `${issue.tool}:${issue.code}`).join(', ')}`);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2381
2242
|
// Dynamically inject the absolute latest System context
|
|
2382
2243
|
const autonomyMode = this.config.autonomyMode || 'C';
|
|
2383
2244
|
const allowedPaths = this.sandbox.grantAllAccess
|
|
@@ -4090,7 +3951,8 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4090
3951
|
const tool = resolveTool(functionName);
|
|
4091
3952
|
const toolSchema = tool?.schema?.parameters || tool?.schema?.input_schema;
|
|
4092
3953
|
const repair = selfRepairToolCall(toolCall, toolSchema, {
|
|
4093
|
-
cwd: this.workspaceRoot || process.cwd()
|
|
3954
|
+
cwd: this.workspaceRoot || process.cwd(),
|
|
3955
|
+
freeFormPaths: this.activeFreeFormPaths?.get(functionName)
|
|
4094
3956
|
});
|
|
4095
3957
|
|
|
4096
3958
|
if (repair.error) {
|
|
@@ -4654,18 +4516,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4654
4516
|
if (functionName === 'browser_act' && result?.success === true) {
|
|
4655
4517
|
const hasExplicitPlanInBatch = Array.isArray(response.toolCalls)
|
|
4656
4518
|
&& response.toolCalls.some((c: any) => canonicalToolName(c?.function?.name || '') === 'update_plan');
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
}
|
|
4660
|
-
const browserResults = Array.isArray(result.data) ? result.data : [];
|
|
4661
|
-
const allRuntimeErrors = browserResults.flatMap((item: any) =>
|
|
4662
|
-
Array.isArray(item?.data?.runtimeErrors) ? item.data.runtimeErrors : []
|
|
4663
|
-
);
|
|
4664
|
-
const hasValidBrowserAction = browserResults.some((item: any) =>
|
|
4665
|
-
['preview', 'snapshot', 'scrape', 'screenshot'].includes(item?.action)
|
|
4666
|
-
);
|
|
4667
|
-
if (allRuntimeErrors.length === 0 && (hasValidBrowserAction || result.url || result.tabId)) {
|
|
4519
|
+
const { verified, runtimeErrors: allRuntimeErrors } = inspectBrowserToolEvidence(result);
|
|
4520
|
+
if (verified) {
|
|
4668
4521
|
this.webVerificationState.browserActUsed = true;
|
|
4522
|
+
if (!hasExplicitPlanInBatch) this.advanceImplementationPlanProgress('verification');
|
|
4669
4523
|
} else if (allRuntimeErrors.length > 0) {
|
|
4670
4524
|
this.webVerificationState.browserActUsed = false;
|
|
4671
4525
|
this.emitEvent({
|
|
@@ -5261,69 +5115,12 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5261
5115
|
|
|
5262
5116
|
// V5: Classify errors for intelligent retry decisions
|
|
5263
5117
|
classifyError(error: any) {
|
|
5264
|
-
|
|
5265
|
-
if (error?.code === 'AGY_NATIVE_ACTION_DENIED'
|
|
5266
|
-
|| error?.code === 'AGY_NATIVE_ACTION_BUDGET'
|
|
5267
|
-
|| error?.code === 'AGY_DESKTOP_TASK_LIMIT') return 'fatal';
|
|
5268
|
-
// A provider may have charged for completed steps before the turn failed.
|
|
5269
|
-
// Replaying that turn can repeat actions and spend the same tokens again.
|
|
5270
|
-
const spent = Number(error?.partialUsage?.promptTokens || 0)
|
|
5271
|
-
+ Number(error?.partialUsage?.completionTokens || 0);
|
|
5272
|
-
if (spent > 0) return 'fatal';
|
|
5273
|
-
const msg = (typeof error === 'string' ? error : error?.message || '').toLowerCase();
|
|
5274
|
-
|
|
5275
|
-
if (error?.name === 'OpenRouterPrivacyConstraintError'
|
|
5276
|
-
|| msg.includes('matching the privacy policy')
|
|
5277
|
-
|| msg.includes('data_collection=')) {
|
|
5278
|
-
return 'fatal';
|
|
5279
|
-
}
|
|
5280
|
-
if (msg.includes('free usage limit') || msg.includes('subscribe to opencode') || msg.includes('opencode.ai/go') || msg.includes('insufficient_quota') || msg.includes('credit balance is too low')) {
|
|
5281
|
-
return 'fatal';
|
|
5282
|
-
}
|
|
5283
|
-
if (msg.includes('syntax') || msg.includes('unexpected token') || msg.includes('invalid json')) {
|
|
5284
|
-
return 'syntax_error';
|
|
5285
|
-
}
|
|
5286
|
-
if (msg.includes('enoent') || msg.includes('no such file') || msg.includes('not found') || msg.includes('does not exist')) {
|
|
5287
|
-
return 'path_not_found';
|
|
5288
|
-
}
|
|
5289
|
-
if (msg.includes('econnrefused') || msg.includes('econnreset') || msg.includes('etimedout') || msg.includes('fetch failed') || msg.includes('network')) {
|
|
5290
|
-
return "network_error";
|
|
5291
|
-
}
|
|
5292
|
-
if (msg.includes('rate limit') || msg.includes('429') || msg.includes('too many requests') || msg.includes('quota')) {
|
|
5293
|
-
return 'rate_limit';
|
|
5294
|
-
}
|
|
5295
|
-
if (msg.includes('eacces') || msg.includes('permission denied') || msg.includes('eperm')) {
|
|
5296
|
-
return 'permission_denied';
|
|
5297
|
-
}
|
|
5298
|
-
if (msg.includes('401') || msg.includes('403') || msg.includes('unauthorized') || msg.includes('api key')) {
|
|
5299
|
-
return 'auth_error';
|
|
5300
|
-
}
|
|
5301
|
-
if (msg.includes('400') || msg.includes('invalid_parameter') || msg.includes('invalid_request') || msg.includes('required property') || msg.includes('bad request')) {
|
|
5302
|
-
return 'invalid_request_error';
|
|
5303
|
-
}
|
|
5304
|
-
if (msg.includes('kill') || msg.includes('abort') || msg.includes('signal') || msg.includes('fatal')) {
|
|
5305
|
-
return 'fatal';
|
|
5306
|
-
}
|
|
5307
|
-
if (error instanceof TypeError || error instanceof ReferenceError || error instanceof RangeError) {
|
|
5308
|
-
return 'fatal';
|
|
5309
|
-
}
|
|
5310
|
-
|
|
5311
|
-
return 'unknown_error';
|
|
5118
|
+
return classifyAgentError(error);
|
|
5312
5119
|
}
|
|
5313
5120
|
|
|
5314
5121
|
// V5: Provide actionable retry hints per error type
|
|
5315
5122
|
getRetryHint(errorType: string) {
|
|
5316
|
-
|
|
5317
|
-
'syntax_error': 'Check your command syntax or JSON structure. Ensure quotes are balanced.',
|
|
5318
|
-
'path_not_found': 'The file or directory does not exist. Use fs.list to verify the path first, or create it with fs.write/mkdir.',
|
|
5319
|
-
["network_error"]: "Network connectivity issue. Wait a moment and retry. If persistent, check if the URL is correct.",
|
|
5320
|
-
'rate_limit': 'API rate limit hit. Wait 5-10 seconds before retrying.',
|
|
5321
|
-
'permission_denied': 'Permission denied. Check if the path is within allowed workspace paths. Try a different directory.',
|
|
5322
|
-
'auth_error': 'Authentication failed. Do NOT retry — the API key may be invalid.',
|
|
5323
|
-
'invalid_request_error': 'API request format error (400 Bad Request). Do NOT retry — check model parameter compliance.',
|
|
5324
|
-
'unknown_error': 'An unexpected error occurred. Try a different approach entirely.'
|
|
5325
|
-
};
|
|
5326
|
-
return hints[errorType] || hints['unknown_error'];
|
|
5123
|
+
return getRetryHintForError(errorType);
|
|
5327
5124
|
}
|
|
5328
5125
|
|
|
5329
5126
|
async runPreToolUse(toolName: string, args: any, toolCallId: string) {
|
|
@@ -5351,98 +5148,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5351
5148
|
}
|
|
5352
5149
|
|
|
5353
5150
|
// V5: Validate tool call arguments before execution
|
|
5354
|
-
|
|
5355
5151
|
validateToolArgs(toolName: string, args: any) {
|
|
5356
|
-
|
|
5357
|
-
return 'Tool arguments must be a JSON object';
|
|
5358
|
-
}
|
|
5359
|
-
|
|
5360
|
-
const baseDir = this.workspaceRoot || process.cwd();
|
|
5361
|
-
const resolveOne = (raw: string): string | null => {
|
|
5362
|
-
const val = raw.trim();
|
|
5363
|
-
if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
|
|
5364
|
-
return null;
|
|
5365
|
-
}
|
|
5366
|
-
if (val === '~' || val.startsWith('~/') || val.startsWith('~\\')) {
|
|
5367
|
-
return val.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
5368
|
-
}
|
|
5369
|
-
if (!path.isAbsolute(val)) {
|
|
5370
|
-
return path.resolve(baseDir, val);
|
|
5371
|
-
}
|
|
5372
|
-
return val;
|
|
5373
|
-
};
|
|
5374
|
-
|
|
5375
|
-
// 1. File operations must have absolute paths (fs_read_skill uses skill-relative file_path)
|
|
5376
|
-
const nonPathTargetTools = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
|
|
5377
|
-
if (toolName !== 'fs_read_skill') {
|
|
5378
|
-
const pathFields = [
|
|
5379
|
-
'path', 'searchPath', 'cwd', 'directory',
|
|
5380
|
-
'source', 'destination', 'file_path', 'filePath', 'filepath',
|
|
5381
|
-
'targetFile', 'outputFile', 'outputPath',
|
|
5382
|
-
...(nonPathTargetTools.has(toolName) ? [] : ['target'])
|
|
5383
|
-
];
|
|
5384
|
-
for (const field of pathFields) {
|
|
5385
|
-
if (args[field] && typeof args[field] === 'string') {
|
|
5386
|
-
const resolved = resolveOne(args[field]);
|
|
5387
|
-
if (resolved !== null) {
|
|
5388
|
-
args[field] = resolved;
|
|
5389
|
-
}
|
|
5390
|
-
}
|
|
5391
|
-
}
|
|
5392
|
-
if (Array.isArray(args.target_directories)) {
|
|
5393
|
-
args.target_directories = args.target_directories.map((entry: unknown) => {
|
|
5394
|
-
if (typeof entry !== 'string') return entry;
|
|
5395
|
-
return resolveOne(entry) ?? entry;
|
|
5396
|
-
});
|
|
5397
|
-
}
|
|
5398
|
-
}
|
|
5399
|
-
|
|
5400
|
-
// 2. Terminal commands must have a command string
|
|
5401
|
-
if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !args.command) {
|
|
5402
|
-
return 'Missing required "command" argument';
|
|
5403
|
-
}
|
|
5404
|
-
|
|
5405
|
-
// 3. File write must have a path AND content.
|
|
5406
|
-
//
|
|
5407
|
-
// These branches were dead: canonicalToolName() (called on every tool name
|
|
5408
|
-
// before this runs) normalises '.'→'_', so `toolName` is 'fs_write', never
|
|
5409
|
-
// 'fs.write'. The old 'fs.write' / 'codebase.search' / 'web.search' literals
|
|
5410
|
-
// could never match, so the model's missing-argument mistakes reached the
|
|
5411
|
-
// tool as runtime exceptions instead of a corrective message. Matched on the
|
|
5412
|
-
// canonical names now, and fs_write's `content` is actually checked (the old
|
|
5413
|
-
// comment said "must have content" but the code only looked at `path`).
|
|
5414
|
-
if (toolName === 'fs_write' && !args.path) {
|
|
5415
|
-
return 'Missing required "path" argument';
|
|
5416
|
-
}
|
|
5417
|
-
if (toolName === 'fs_write' && args.content === undefined) {
|
|
5418
|
-
return 'Missing required "content" argument';
|
|
5419
|
-
}
|
|
5420
|
-
|
|
5421
|
-
// 4. Search must have a query
|
|
5422
|
-
if ((toolName === 'codebase_search' || toolName === 'web_search') && !args.query) {
|
|
5423
|
-
return 'Missing required "query" argument';
|
|
5424
|
-
}
|
|
5425
|
-
|
|
5426
|
-
// 5. Tool search must have a query, pack, or names array
|
|
5427
|
-
if (toolName === 'tool_search') {
|
|
5428
|
-
const q = typeof args.query === 'string'
|
|
5429
|
-
? args.query.trim()
|
|
5430
|
-
: (Array.isArray(args.query) ? args.query.map(String).join(' ').trim() : '');
|
|
5431
|
-
const p = typeof args.pack === 'string' ? args.pack.trim() : '';
|
|
5432
|
-
const n = Array.isArray(args.names) && args.names.length > 0;
|
|
5433
|
-
if (!q && !p && !n) {
|
|
5434
|
-
return 'Missing required "query" or "pack" argument';
|
|
5435
|
-
}
|
|
5436
|
-
}
|
|
5437
|
-
|
|
5438
|
-
// 6. Skill reader must have a non-empty skill_id
|
|
5439
|
-
if (toolName === 'fs_read_skill') {
|
|
5440
|
-
const sid = typeof args.skill_id === 'string' ? args.skill_id.trim() : '';
|
|
5441
|
-
if (!sid) {
|
|
5442
|
-
return 'Missing required "skill_id" argument';
|
|
5443
|
-
}
|
|
5444
|
-
}
|
|
5445
|
-
|
|
5446
|
-
return null; // No validation errors
|
|
5152
|
+
return validateAndNormalizeToolArgs(toolName, args, this.workspaceRoot || process.cwd());
|
|
5447
5153
|
}
|
|
5448
5154
|
}
|