@causyne/agent 1.20.120 → 1.20.122
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/README.md +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +117 -0
- package/src/agent/errorClassifier.ts +165 -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 +33 -344
- package/src/agentLoop.ts +51 -352
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +116 -10
- package/src/autoUpdate.ts +149 -10
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/cliMode.js +16 -2
- package/src/commands.js +10 -9
- package/src/config.js +288 -272
- package/src/config.ts +342 -0
- package/src/configVault.js +271 -0
- package/src/configVault.ts +273 -0
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +305 -0
- package/src/headlessCli.ts +381 -0
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- 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/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +263 -0
- package/src/osKeychain.ts +287 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +328 -385
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +397 -0
- package/src/providers/byokHttp.ts +497 -0
- package/src/providers/byokStream.js +748 -0
- package/src/providers/byokStream.ts +863 -0
- package/src/providers/dashscope-byok.js +98 -81
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +74 -64
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +229 -253
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +71 -64
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +116 -93
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +114 -65
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +194 -98
- package/src/providers/openrouter.ts +202 -97
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +97 -71
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +74 -64
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +486 -530
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +1287 -0
- package/src/sandboxPolicy.ts +1381 -0
- package/src/sessionJournal.js +55 -3
- package/src/sessionJournal.ts +58 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +513 -0
- package/src/tools/osSandbox.ts +588 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +108 -35
- package/src/tools/sysRun.ts +119 -31
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
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
|
|
@@ -746,6 +566,9 @@ export class AgentLoop {
|
|
|
746
566
|
this.approvalScope = createApprovalScope();
|
|
747
567
|
this.autonomyOverride = null;
|
|
748
568
|
this.circuitBreakerUnlocked = false;
|
|
569
|
+
for (const toolCallId of [...this.pendingApprovals.keys()]) {
|
|
570
|
+
this.handleApprovalResponse(toolCallId, false);
|
|
571
|
+
}
|
|
749
572
|
this.pendingApprovals.clear();
|
|
750
573
|
}
|
|
751
574
|
// V6: Adaptive Temperature based on task intent
|
|
@@ -1658,6 +1481,10 @@ export class AgentLoop {
|
|
|
1658
1481
|
this.config = loadConfig();
|
|
1659
1482
|
if (this.autonomyOverride)
|
|
1660
1483
|
this.config.autonomyMode = this.autonomyOverride;
|
|
1484
|
+
if (this.providerOverride)
|
|
1485
|
+
this.config.provider = this.providerOverride;
|
|
1486
|
+
if (this.modelOverride)
|
|
1487
|
+
this.config.model = this.modelOverride;
|
|
1661
1488
|
if (typeof this.initializeProvider === 'function') {
|
|
1662
1489
|
const nextProvider = this.initializeProvider();
|
|
1663
1490
|
if (nextProvider) {
|
|
@@ -4555,7 +4382,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4555
4382
|
this._lastToolResult = observedResult;
|
|
4556
4383
|
// Active Inference: Record step prediction error into VFE rolling tracker
|
|
4557
4384
|
if (this.vfeTracker) {
|
|
4558
|
-
const isThrash = isThrashing((this._planSteps || []).map((s) => s.tool)
|
|
4385
|
+
const isThrash = isThrashing((this._planSteps || []).map((s) => s.tool));
|
|
4559
4386
|
const vfeOutcome = this.vfeTracker.recordStep({
|
|
4560
4387
|
tool: functionName,
|
|
4561
4388
|
success: stepSuccess,
|
|
@@ -4819,13 +4646,16 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4819
4646
|
// wall-clock limits, before deciding whether recovery is possible.
|
|
4820
4647
|
if (e?.partialUsage) {
|
|
4821
4648
|
const usage = e.partialUsage;
|
|
4822
|
-
|
|
4823
|
-
|
|
4649
|
+
const promptTokens = Number.isFinite(Number(usage.promptTokens)) ? Math.max(0, Number(usage.promptTokens)) : 0;
|
|
4650
|
+
const completionTokens = Number.isFinite(Number(usage.completionTokens)) ? Math.max(0, Number(usage.completionTokens)) : 0;
|
|
4651
|
+
const cachedPromptTokens = Number.isFinite(Number(usage.cachedPromptTokens)) ? Math.max(0, Number(usage.cachedPromptTokens)) : 0;
|
|
4652
|
+
if (promptTokens + completionTokens > 0) {
|
|
4653
|
+
await this.tokenTracker.trackUsage(promptTokens, completionTokens, (message) => this.emitEvent({ type: 'budget_warning', message }), usage);
|
|
4824
4654
|
auditLog.log({
|
|
4825
4655
|
event: 'model_usage', scope: 'agent_loop_primary', taskId: this.taskId,
|
|
4826
4656
|
step: this.stepsCompleted, provider: this.config.provider || 'unknown',
|
|
4827
|
-
promptTokens
|
|
4828
|
-
cachedPromptTokens
|
|
4657
|
+
promptTokens, completionTokens,
|
|
4658
|
+
cachedPromptTokens,
|
|
4829
4659
|
measurement: 'provider_reported_partial', costBasis: 'external_subscription_unavailable'
|
|
4830
4660
|
});
|
|
4831
4661
|
}
|
|
@@ -5025,69 +4855,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5025
4855
|
}
|
|
5026
4856
|
// V5: Classify errors for intelligent retry decisions
|
|
5027
4857
|
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';
|
|
4858
|
+
return classifyAgentError(error);
|
|
5077
4859
|
}
|
|
5078
4860
|
// V5: Provide actionable retry hints per error type
|
|
5079
4861
|
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'];
|
|
4862
|
+
return getRetryHintForError(errorType);
|
|
5091
4863
|
}
|
|
5092
4864
|
async runPreToolUse(toolName, args, toolCallId) {
|
|
5093
4865
|
return runConfiguredHooks({
|
|
@@ -5113,89 +4885,6 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5113
4885
|
}
|
|
5114
4886
|
// V5: Validate tool call arguments before execution
|
|
5115
4887
|
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
|
|
4888
|
+
return validateAndNormalizeToolArgs(toolName, args, this.workspaceRoot || process.cwd());
|
|
5200
4889
|
}
|
|
5201
4890
|
}
|