@causyne/agent 1.20.120 → 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 +22 -339
- package/src/agentLoop.ts +40 -347
- package/src/autoUpdate.js +111 -8
- package/src/autoUpdate.ts +144 -8
- package/src/cliMode.js +16 -2
- package/src/commands.js +10 -9
- 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/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/osKeychain.js +209 -0
- package/src/osKeychain.ts +245 -0
- package/src/providers/anthropic.js +28 -11
- 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 +34 -25
- package/src/providers/deepseek.js +31 -22
- package/src/providers/gemini.js +40 -13
- package/src/providers/moonshot.js +31 -22
- package/src/providers/muse.js +10 -10
- package/src/providers/ollama.js +25 -10
- package/src/providers/openai-compatible.js +46 -14
- package/src/providers/openrouter.js +63 -29
- package/src/providers/openrouter.ts +73 -29
- package/src/providers/qwen-byok.js +33 -16
- package/src/providers/xai.js +31 -22
- 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/osSandbox.js +473 -0
- package/src/tools/osSandbox.ts +554 -0
- package/src/tools/persistentShell.js +8 -3
- 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/agentLoop.js
CHANGED
|
@@ -6,6 +6,9 @@ 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 { isActionableTaskPrompt, isGenericHandoffResponse, isDesktopWallpaperChangePrompt, isExecutionOrLaunchTaskPrompt, isCodeAuthoringTaskPrompt, extractSkillIdFromPrompt, isDirectGameTask, isProviderPlanOrQuotaRefusal, isMidTaskProgressText } from './agent/promptIntent.js';
|
|
11
|
+
import { validateAndNormalizeToolArgs } from './agent/toolArgValidator.js';
|
|
9
12
|
import { resolveTaskTokenCeiling, peerCallTokenCeiling, isAntigravityPeer, isTerminalBudgetFailure, desktopDeadline, remainingDesktopTime, DEFAULT_AGY_TASK_TOKENS } from './budget/budgetPolicy.js';
|
|
10
13
|
import { PEER_COLLABORATION_POLICY } from './providers/collaborationPolicy.js';
|
|
11
14
|
import { createHash, randomUUID } from 'crypto';
|
|
@@ -49,7 +52,7 @@ import { determineToolScope, resolveLazyPlaybooks, refineToolDecision, SmartTool
|
|
|
49
52
|
import { buildToolsList, renderToolsList, omittedCustomCount } from './toolsList.js';
|
|
50
53
|
import { assessVerification } from './verificationPlan.js';
|
|
51
54
|
import { SmartTools } from './SmartTools.js';
|
|
52
|
-
import { decideTools
|
|
55
|
+
import { decideTools } from './decideTools.js';
|
|
53
56
|
import { SavedTools, readSavedTools, writeSavedTools } from './saveTools.js';
|
|
54
57
|
import { CHARS_PER_TOKEN, resolveCharPool, measureMessages, resultCapFor, decayToolResults, buildWindow, compactInPlace, describeDroppedMessages, sanitizeSequences, applyProgressiveCompaction, snipOversizedToolOutputs } from './contextManager.js';
|
|
55
58
|
// Provider imports
|
|
@@ -98,46 +101,7 @@ function spillErrorField(result) {
|
|
|
98
101
|
const error = nonEmptyErrorText(result);
|
|
99
102
|
return error !== undefined ? { error: error.slice(0, 500) } : {};
|
|
100
103
|
}
|
|
101
|
-
export
|
|
102
|
-
const t = (text || '').trim();
|
|
103
|
-
if (!t)
|
|
104
|
-
return false;
|
|
105
|
-
// A no-execution request can be satisfied by analysis without mandatory tool calls.
|
|
106
|
-
if (isNoExecutionPrompt(t))
|
|
107
|
-
return false;
|
|
108
|
-
const pureGreeting = /^(hi|hello|hey|yo|halo|hai|p|assalamu['a]?[l]?aikum|good\s+(morning|afternoon|evening))[.!?, ]*$/i.test(t);
|
|
109
|
-
if (pureGreeting)
|
|
110
|
-
return false;
|
|
111
|
-
const actionKeywords = /\b(continue|resume|proceed|lanjut\w*|create|build|make|write|code|implement|fix|optimize|refactor|generate|add|setup|install|run|open|launch|start|play|serve|preview|deploy|delete|remove|update|change|test|review|inspect|search|find|download|buat\w*|bikin\w*|perbaik\w*|tambah\w*|ubah\w*|hapus\w*|jalan\w*|pasang\w*|analis\w*|cek\w*|rancang\w*|desain\w*|kerjakan\w*|tolong\w*|bantu\w*|ganti\w*|tulis\w*|kembangkan\w*)\b/i;
|
|
112
|
-
if (actionKeywords.test(t))
|
|
113
|
-
return true;
|
|
114
|
-
return false; // Length alone does not turn an information question into an execution order.
|
|
115
|
-
}
|
|
116
|
-
export function isGenericHandoffResponse(text) {
|
|
117
|
-
const answer = (text || '').trim();
|
|
118
|
-
if (!answer || answer.length > 500)
|
|
119
|
-
return false;
|
|
120
|
-
const lower = answer.toLowerCase();
|
|
121
|
-
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);
|
|
122
|
-
const verifiedOutcome = /\b(completed|changed|set the (desktop|wallpaper)|saved|created|installed|verified|downloaded|finished)\b/i.test(lower);
|
|
123
|
-
return handoff && !verifiedOutcome;
|
|
124
|
-
}
|
|
125
|
-
export function isDesktopWallpaperChangePrompt(text) {
|
|
126
|
-
const t = (text || '').trim();
|
|
127
|
-
if (!t)
|
|
128
|
-
return false;
|
|
129
|
-
// Explanatory questions or prompts that explicitly forbid execution are never wallpaper mutation requests
|
|
130
|
-
if (isNoExecutionPrompt(t) || isReadOnlyOrExplanatoryPrompt(t))
|
|
131
|
-
return false;
|
|
132
|
-
if (/^(?:why|how|what|does|can\s+you\s+explain|explain|tell\s+me|show\s+me\s+how)\b/i.test(t))
|
|
133
|
-
return false;
|
|
134
|
-
if (/\b(?:why|how)\s+does\b/i.test(t))
|
|
135
|
-
return false;
|
|
136
|
-
// Debugging wallpaper-related source or regexes is not a request to mutate macOS.
|
|
137
|
-
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))
|
|
138
|
-
return false;
|
|
139
|
-
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);
|
|
140
|
-
}
|
|
104
|
+
export { isActionableTaskPrompt, isGenericHandoffResponse, isDesktopWallpaperChangePrompt, isExecutionOrLaunchTaskPrompt, isCodeAuthoringTaskPrompt, extractSkillIdFromPrompt, isDirectGameTask, isProviderPlanOrQuotaRefusal, isMidTaskProgressText };
|
|
141
105
|
function readMacDesktopPictures() {
|
|
142
106
|
try {
|
|
143
107
|
return execFileSync('osascript', ['-e', 'tell application "System Events" to get picture of every desktop'], {
|
|
@@ -148,160 +112,6 @@ function readMacDesktopPictures() {
|
|
|
148
112
|
return null;
|
|
149
113
|
}
|
|
150
114
|
}
|
|
151
|
-
export function isExecutionOrLaunchTaskPrompt(text) {
|
|
152
|
-
const t = (text || '').trim();
|
|
153
|
-
if (!t)
|
|
154
|
-
return false;
|
|
155
|
-
return /\b(open|launch|start|run|play|serve|preview)\b/i.test(t)
|
|
156
|
-
&& !/\b(create|build|make|write|code|implement|generate|refactor)\b/i.test(t);
|
|
157
|
-
}
|
|
158
|
-
export function isCodeAuthoringTaskPrompt(text) {
|
|
159
|
-
const t = (text || '').trim();
|
|
160
|
-
if (!t)
|
|
161
|
-
return false;
|
|
162
|
-
if (isExecutionOrLaunchTaskPrompt(t))
|
|
163
|
-
return false;
|
|
164
|
-
return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
|
|
165
|
-
}
|
|
166
|
-
export function extractSkillIdFromPrompt(prompt) {
|
|
167
|
-
const text = String(prompt || '').trim();
|
|
168
|
-
if (!text)
|
|
169
|
-
return '';
|
|
170
|
-
const stopWords = new Set([
|
|
171
|
-
'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
|
|
172
|
-
'using', 'for', 'to', 'by', 'and', 'or', 'of'
|
|
173
|
-
]);
|
|
174
|
-
const leadingTrim = new Set(['`', '"', "'", '(', '[']);
|
|
175
|
-
const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
|
|
176
|
-
const cleanCandidate = (raw) => {
|
|
177
|
-
const trimmed = raw.trim();
|
|
178
|
-
let start = 0;
|
|
179
|
-
let end = trimmed.length;
|
|
180
|
-
while (start < end && leadingTrim.has(trimmed[start]))
|
|
181
|
-
start++;
|
|
182
|
-
while (end > start && trailingTrim.has(trimmed[end - 1]))
|
|
183
|
-
end--;
|
|
184
|
-
const stripped = trimmed.slice(start, end);
|
|
185
|
-
if (!stripped || stopWords.has(stripped.toLowerCase()))
|
|
186
|
-
return '';
|
|
187
|
-
if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
|
|
188
|
-
return '';
|
|
189
|
-
}
|
|
190
|
-
return stripped;
|
|
191
|
-
};
|
|
192
|
-
const isFileExt = (candidate) => /\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
|
|
193
|
-
const cuedSlashMatch = text.match(/(?:\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);
|
|
194
|
-
if (cuedSlashMatch?.[1]) {
|
|
195
|
-
const candidate = cleanCandidate(cuedSlashMatch[1]);
|
|
196
|
-
if (candidate && !isFileExt(candidate)) {
|
|
197
|
-
return candidate;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
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)) {
|
|
201
|
-
const candidate = cleanCandidate(m[1] || '');
|
|
202
|
-
if (candidate && !isFileExt(candidate)) {
|
|
203
|
-
return candidate;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
const explicitQuotedMatch = text.match(/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i);
|
|
207
|
-
if (explicitQuotedMatch?.[1]) {
|
|
208
|
-
const candidate = cleanCandidate(explicitQuotedMatch[1]);
|
|
209
|
-
if (candidate)
|
|
210
|
-
return candidate;
|
|
211
|
-
}
|
|
212
|
-
const bareMatch = text.match(/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i);
|
|
213
|
-
if (bareMatch?.[1]) {
|
|
214
|
-
const candidate = cleanCandidate(bareMatch[1]);
|
|
215
|
-
if (candidate)
|
|
216
|
-
return candidate;
|
|
217
|
-
}
|
|
218
|
-
return '';
|
|
219
|
-
}
|
|
220
|
-
export function isDirectGameTask(text) {
|
|
221
|
-
return isDirectGameTaskDecision(text);
|
|
222
|
-
}
|
|
223
|
-
export function isProviderPlanOrQuotaRefusal(text) {
|
|
224
|
-
if (!text || typeof text !== 'string')
|
|
225
|
-
return false;
|
|
226
|
-
const trimmed = text.trim();
|
|
227
|
-
if (!trimmed || trimmed.length > 320)
|
|
228
|
-
return false;
|
|
229
|
-
if (/^upgrade your plan to continue\.?$/i.test(trimmed))
|
|
230
|
-
return true;
|
|
231
|
-
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);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Detects when an agent response is an intermediate mid-task progress note or
|
|
235
|
-
* transition announcement (e.g. "Real assets verified. Writing the Tesla-style
|
|
236
|
-
* redesign now." or "Let me look at the newer assets... Pulling their real
|
|
237
|
-
* stills and confirming embeddability.") rather than a finished answer.
|
|
238
|
-
*/
|
|
239
|
-
export function isMidTaskProgressText(text) {
|
|
240
|
-
if (!text || typeof text !== 'string')
|
|
241
|
-
return false;
|
|
242
|
-
const trimmed = text.trim();
|
|
243
|
-
if (!trimmed || trimmed.length > 480)
|
|
244
|
-
return false;
|
|
245
|
-
const lower = trimmed.toLowerCase();
|
|
246
|
-
if (lower.includes('?') ||
|
|
247
|
-
lower.includes('let me know') ||
|
|
248
|
-
lower.includes('how can i help') ||
|
|
249
|
-
lower.includes('how may i help') ||
|
|
250
|
-
lower.includes('how can i assist') ||
|
|
251
|
-
lower.includes('what would you like') ||
|
|
252
|
-
lower.includes('what can i help') ||
|
|
253
|
-
lower.includes('feel free to')) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
if (trimmed.includes('```'))
|
|
257
|
-
return false;
|
|
258
|
-
const sentences = trimmed
|
|
259
|
-
.split(/(?:(?<=[.!])\s+|\n+)/)
|
|
260
|
-
.map(s => s.trim())
|
|
261
|
-
.filter(Boolean);
|
|
262
|
-
const lastSentence = (sentences[sentences.length - 1] || trimmed).trim();
|
|
263
|
-
const lastLower = lastSentence.toLowerCase();
|
|
264
|
-
if (trimmed.length <= 280 && (trimmed.endsWith(':') || trimmed.endsWith('...') || trimmed.endsWith('…'))) {
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
267
|
-
const intentPrefixes = [
|
|
268
|
-
'let me ',
|
|
269
|
-
"i'll ",
|
|
270
|
-
'i will ',
|
|
271
|
-
'now i ',
|
|
272
|
-
'now let me ',
|
|
273
|
-
"now i'll ",
|
|
274
|
-
'now i will ',
|
|
275
|
-
'next, i ',
|
|
276
|
-
'next i ',
|
|
277
|
-
"next, i'll ",
|
|
278
|
-
"next i'll ",
|
|
279
|
-
'first, i ',
|
|
280
|
-
'first i ',
|
|
281
|
-
'let us ',
|
|
282
|
-
"let's ",
|
|
283
|
-
'i shall ',
|
|
284
|
-
'we will ',
|
|
285
|
-
"we'll ",
|
|
286
|
-
'i am going to ',
|
|
287
|
-
"i'm going to ",
|
|
288
|
-
'going to '
|
|
289
|
-
];
|
|
290
|
-
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
|
|
291
|
-
if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
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;
|
|
296
|
-
if (gerundStart.test(lastSentence) && lastSentence.length <= 220) {
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
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;
|
|
300
|
-
if (actionNowSuffix.test(lastSentence)) {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
115
|
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.
|
|
306
116
|
|
|
307
117
|
${PEER_COLLABORATION_POLICY}
|
|
@@ -603,10 +413,20 @@ export class AgentLoop {
|
|
|
603
413
|
? options.workspaceRoot
|
|
604
414
|
: process.cwd();
|
|
605
415
|
this.autonomyOverride = null;
|
|
416
|
+
this.providerOverride = typeof options.provider === 'string' && options.provider.trim()
|
|
417
|
+
? options.provider.trim()
|
|
418
|
+
: null;
|
|
419
|
+
this.modelOverride = typeof options.model === 'string' && options.model.trim()
|
|
420
|
+
? options.model.trim()
|
|
421
|
+
: null;
|
|
606
422
|
this.approvalScope = options.approvalScope && typeof options.approvalScope.isAlwaysAllowed === 'function'
|
|
607
423
|
? options.approvalScope
|
|
608
424
|
: processApprovalScope;
|
|
609
425
|
this.config = loadConfig();
|
|
426
|
+
if (this.providerOverride)
|
|
427
|
+
this.config.provider = this.providerOverride;
|
|
428
|
+
if (this.modelOverride)
|
|
429
|
+
this.config.model = this.modelOverride;
|
|
610
430
|
this.sandbox = new Sandbox({ workspaceRoot: this.workspaceRoot });
|
|
611
431
|
// Retire spilled tool outputs past their retention window. Fire-and-forget
|
|
612
432
|
// at task start rather than on a timer: nothing may run in the background
|
|
@@ -1658,6 +1478,10 @@ export class AgentLoop {
|
|
|
1658
1478
|
this.config = loadConfig();
|
|
1659
1479
|
if (this.autonomyOverride)
|
|
1660
1480
|
this.config.autonomyMode = this.autonomyOverride;
|
|
1481
|
+
if (this.providerOverride)
|
|
1482
|
+
this.config.provider = this.providerOverride;
|
|
1483
|
+
if (this.modelOverride)
|
|
1484
|
+
this.config.model = this.modelOverride;
|
|
1661
1485
|
if (typeof this.initializeProvider === 'function') {
|
|
1662
1486
|
const nextProvider = this.initializeProvider();
|
|
1663
1487
|
if (nextProvider) {
|
|
@@ -5025,69 +4849,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5025
4849
|
}
|
|
5026
4850
|
// V5: Classify errors for intelligent retry decisions
|
|
5027
4851
|
classifyError(error) {
|
|
5028
|
-
|
|
5029
|
-
return 'fatal';
|
|
5030
|
-
if (error?.code === 'AGY_NATIVE_ACTION_DENIED'
|
|
5031
|
-
|| error?.code === 'AGY_NATIVE_ACTION_BUDGET'
|
|
5032
|
-
|| error?.code === 'AGY_DESKTOP_TASK_LIMIT')
|
|
5033
|
-
return 'fatal';
|
|
5034
|
-
// A provider may have charged for completed steps before the turn failed.
|
|
5035
|
-
// Replaying that turn can repeat actions and spend the same tokens again.
|
|
5036
|
-
const spent = Number(error?.partialUsage?.promptTokens || 0)
|
|
5037
|
-
+ Number(error?.partialUsage?.completionTokens || 0);
|
|
5038
|
-
if (spent > 0)
|
|
5039
|
-
return 'fatal';
|
|
5040
|
-
const msg = (typeof error === 'string' ? error : error?.message || '').toLowerCase();
|
|
5041
|
-
if (error?.name === 'OpenRouterPrivacyConstraintError'
|
|
5042
|
-
|| msg.includes('matching the privacy policy')
|
|
5043
|
-
|| msg.includes('data_collection=')) {
|
|
5044
|
-
return 'fatal';
|
|
5045
|
-
}
|
|
5046
|
-
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')) {
|
|
5047
|
-
return 'fatal';
|
|
5048
|
-
}
|
|
5049
|
-
if (msg.includes('syntax') || msg.includes('unexpected token') || msg.includes('invalid json')) {
|
|
5050
|
-
return 'syntax_error';
|
|
5051
|
-
}
|
|
5052
|
-
if (msg.includes('enoent') || msg.includes('no such file') || msg.includes('not found') || msg.includes('does not exist')) {
|
|
5053
|
-
return 'path_not_found';
|
|
5054
|
-
}
|
|
5055
|
-
if (msg.includes('econnrefused') || msg.includes('econnreset') || msg.includes('etimedout') || msg.includes('fetch failed') || msg.includes('network')) {
|
|
5056
|
-
return "network_error";
|
|
5057
|
-
}
|
|
5058
|
-
if (msg.includes('rate limit') || msg.includes('429') || msg.includes('too many requests') || msg.includes('quota')) {
|
|
5059
|
-
return 'rate_limit';
|
|
5060
|
-
}
|
|
5061
|
-
if (msg.includes('eacces') || msg.includes('permission denied') || msg.includes('eperm')) {
|
|
5062
|
-
return 'permission_denied';
|
|
5063
|
-
}
|
|
5064
|
-
if (msg.includes('401') || msg.includes('403') || msg.includes('unauthorized') || msg.includes('api key')) {
|
|
5065
|
-
return 'auth_error';
|
|
5066
|
-
}
|
|
5067
|
-
if (msg.includes('400') || msg.includes('invalid_parameter') || msg.includes('invalid_request') || msg.includes('required property') || msg.includes('bad request')) {
|
|
5068
|
-
return 'invalid_request_error';
|
|
5069
|
-
}
|
|
5070
|
-
if (msg.includes('kill') || msg.includes('abort') || msg.includes('signal') || msg.includes('fatal')) {
|
|
5071
|
-
return 'fatal';
|
|
5072
|
-
}
|
|
5073
|
-
if (error instanceof TypeError || error instanceof ReferenceError || error instanceof RangeError) {
|
|
5074
|
-
return 'fatal';
|
|
5075
|
-
}
|
|
5076
|
-
return 'unknown_error';
|
|
4852
|
+
return classifyAgentError(error);
|
|
5077
4853
|
}
|
|
5078
4854
|
// V5: Provide actionable retry hints per error type
|
|
5079
4855
|
getRetryHint(errorType) {
|
|
5080
|
-
|
|
5081
|
-
'syntax_error': 'Check your command syntax or JSON structure. Ensure quotes are balanced.',
|
|
5082
|
-
'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.',
|
|
5083
|
-
["network_error"]: "Network connectivity issue. Wait a moment and retry. If persistent, check if the URL is correct.",
|
|
5084
|
-
'rate_limit': 'API rate limit hit. Wait 5-10 seconds before retrying.',
|
|
5085
|
-
'permission_denied': 'Permission denied. Check if the path is within allowed workspace paths. Try a different directory.',
|
|
5086
|
-
'auth_error': 'Authentication failed. Do NOT retry — the API key may be invalid.',
|
|
5087
|
-
'invalid_request_error': 'API request format error (400 Bad Request). Do NOT retry — check model parameter compliance.',
|
|
5088
|
-
'unknown_error': 'An unexpected error occurred. Try a different approach entirely.'
|
|
5089
|
-
};
|
|
5090
|
-
return hints[errorType] || hints['unknown_error'];
|
|
4856
|
+
return getRetryHintForError(errorType);
|
|
5091
4857
|
}
|
|
5092
4858
|
async runPreToolUse(toolName, args, toolCallId) {
|
|
5093
4859
|
return runConfiguredHooks({
|
|
@@ -5113,89 +4879,6 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5113
4879
|
}
|
|
5114
4880
|
// V5: Validate tool call arguments before execution
|
|
5115
4881
|
validateToolArgs(toolName, args) {
|
|
5116
|
-
|
|
5117
|
-
return 'Tool arguments must be a JSON object';
|
|
5118
|
-
}
|
|
5119
|
-
const baseDir = this.workspaceRoot || process.cwd();
|
|
5120
|
-
const resolveOne = (raw) => {
|
|
5121
|
-
const val = raw.trim();
|
|
5122
|
-
if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
|
|
5123
|
-
return null;
|
|
5124
|
-
}
|
|
5125
|
-
if (val === '~' || val.startsWith('~/') || val.startsWith('~\\')) {
|
|
5126
|
-
return val.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
5127
|
-
}
|
|
5128
|
-
if (!path.isAbsolute(val)) {
|
|
5129
|
-
return path.resolve(baseDir, val);
|
|
5130
|
-
}
|
|
5131
|
-
return val;
|
|
5132
|
-
};
|
|
5133
|
-
// 1. File operations must have absolute paths (fs_read_skill uses skill-relative file_path)
|
|
5134
|
-
const nonPathTargetTools = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
|
|
5135
|
-
if (toolName !== 'fs_read_skill') {
|
|
5136
|
-
const pathFields = [
|
|
5137
|
-
'path', 'searchPath', 'cwd', 'directory',
|
|
5138
|
-
'source', 'destination', 'file_path', 'filePath', 'filepath',
|
|
5139
|
-
'targetFile', 'outputFile', 'outputPath',
|
|
5140
|
-
...(nonPathTargetTools.has(toolName) ? [] : ['target'])
|
|
5141
|
-
];
|
|
5142
|
-
for (const field of pathFields) {
|
|
5143
|
-
if (args[field] && typeof args[field] === 'string') {
|
|
5144
|
-
const resolved = resolveOne(args[field]);
|
|
5145
|
-
if (resolved !== null) {
|
|
5146
|
-
args[field] = resolved;
|
|
5147
|
-
}
|
|
5148
|
-
}
|
|
5149
|
-
}
|
|
5150
|
-
if (Array.isArray(args.target_directories)) {
|
|
5151
|
-
args.target_directories = args.target_directories.map((entry) => {
|
|
5152
|
-
if (typeof entry !== 'string')
|
|
5153
|
-
return entry;
|
|
5154
|
-
return resolveOne(entry) ?? entry;
|
|
5155
|
-
});
|
|
5156
|
-
}
|
|
5157
|
-
}
|
|
5158
|
-
// 2. Terminal commands must have a command string
|
|
5159
|
-
if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !args.command) {
|
|
5160
|
-
return 'Missing required "command" argument';
|
|
5161
|
-
}
|
|
5162
|
-
// 3. File write must have a path AND content.
|
|
5163
|
-
//
|
|
5164
|
-
// These branches were dead: canonicalToolName() (called on every tool name
|
|
5165
|
-
// before this runs) normalises '.'→'_', so `toolName` is 'fs_write', never
|
|
5166
|
-
// 'fs.write'. The old 'fs.write' / 'codebase.search' / 'web.search' literals
|
|
5167
|
-
// could never match, so the model's missing-argument mistakes reached the
|
|
5168
|
-
// tool as runtime exceptions instead of a corrective message. Matched on the
|
|
5169
|
-
// canonical names now, and fs_write's `content` is actually checked (the old
|
|
5170
|
-
// comment said "must have content" but the code only looked at `path`).
|
|
5171
|
-
if (toolName === 'fs_write' && !args.path) {
|
|
5172
|
-
return 'Missing required "path" argument';
|
|
5173
|
-
}
|
|
5174
|
-
if (toolName === 'fs_write' && args.content === undefined) {
|
|
5175
|
-
return 'Missing required "content" argument';
|
|
5176
|
-
}
|
|
5177
|
-
// 4. Search must have a query
|
|
5178
|
-
if ((toolName === 'codebase_search' || toolName === 'web_search') && !args.query) {
|
|
5179
|
-
return 'Missing required "query" argument';
|
|
5180
|
-
}
|
|
5181
|
-
// 5. Tool search must have a query, pack, or names array
|
|
5182
|
-
if (toolName === 'tool_search') {
|
|
5183
|
-
const q = typeof args.query === 'string'
|
|
5184
|
-
? args.query.trim()
|
|
5185
|
-
: (Array.isArray(args.query) ? args.query.map(String).join(' ').trim() : '');
|
|
5186
|
-
const p = typeof args.pack === 'string' ? args.pack.trim() : '';
|
|
5187
|
-
const n = Array.isArray(args.names) && args.names.length > 0;
|
|
5188
|
-
if (!q && !p && !n) {
|
|
5189
|
-
return 'Missing required "query" or "pack" argument';
|
|
5190
|
-
}
|
|
5191
|
-
}
|
|
5192
|
-
// 6. Skill reader must have a non-empty skill_id
|
|
5193
|
-
if (toolName === 'fs_read_skill') {
|
|
5194
|
-
const sid = typeof args.skill_id === 'string' ? args.skill_id.trim() : '';
|
|
5195
|
-
if (!sid) {
|
|
5196
|
-
return 'Missing required "skill_id" argument';
|
|
5197
|
-
}
|
|
5198
|
-
}
|
|
5199
|
-
return null; // No validation errors
|
|
4882
|
+
return validateAndNormalizeToolArgs(toolName, args, this.workspaceRoot || process.cwd());
|
|
5200
4883
|
}
|
|
5201
4884
|
}
|