@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.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';
|
|
@@ -76,7 +89,7 @@ import { buildToolsList, renderToolsList, omittedCustomCount } from './toolsList
|
|
|
76
89
|
import type { ToolListEntry } from './toolsList.js';
|
|
77
90
|
import { assessVerification } from './verificationPlan.js';
|
|
78
91
|
import { SmartTools } from './SmartTools.js';
|
|
79
|
-
import { decideTools
|
|
92
|
+
import { decideTools } from './decideTools.js';
|
|
80
93
|
import type { DecideToolsInput } from './decideTools.js';
|
|
81
94
|
import { SavedTools, readSavedTools, writeSavedTools } from './saveTools.js';
|
|
82
95
|
import type { AdmissionResult } from './saveTools.js';
|
|
@@ -176,40 +189,21 @@ export interface AgentLoopOptions {
|
|
|
176
189
|
workspaceRoot?: string;
|
|
177
190
|
memorySessionId?: string | null;
|
|
178
191
|
approvalScope?: AgentLoopApprovalScope;
|
|
192
|
+
provider?: string;
|
|
193
|
+
model?: string;
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
export
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function isGenericHandoffResponse(text: string): boolean {
|
|
194
|
-
const answer = (text || '').trim();
|
|
195
|
-
if (!answer || answer.length > 500) return false;
|
|
196
|
-
const lower = answer.toLowerCase();
|
|
197
|
-
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);
|
|
198
|
-
const verifiedOutcome = /\b(completed|changed|set the (desktop|wallpaper)|saved|created|installed|verified|downloaded|finished)\b/i.test(lower);
|
|
199
|
-
return handoff && !verifiedOutcome;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function isDesktopWallpaperChangePrompt(text: string): boolean {
|
|
203
|
-
const t = (text || '').trim();
|
|
204
|
-
if (!t) return false;
|
|
205
|
-
// Explanatory questions or prompts that explicitly forbid execution are never wallpaper mutation requests
|
|
206
|
-
if (isNoExecutionPrompt(t) || isReadOnlyOrExplanatoryPrompt(t)) return false;
|
|
207
|
-
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;
|
|
208
|
-
if (/\b(?:why|how)\s+does\b/i.test(t)) return false;
|
|
209
|
-
// Debugging wallpaper-related source or regexes is not a request to mutate macOS.
|
|
210
|
-
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;
|
|
211
|
-
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);
|
|
212
|
-
}
|
|
196
|
+
export {
|
|
197
|
+
isActionableTaskPrompt,
|
|
198
|
+
isGenericHandoffResponse,
|
|
199
|
+
isDesktopWallpaperChangePrompt,
|
|
200
|
+
isExecutionOrLaunchTaskPrompt,
|
|
201
|
+
isCodeAuthoringTaskPrompt,
|
|
202
|
+
extractSkillIdFromPrompt,
|
|
203
|
+
isDirectGameTask,
|
|
204
|
+
isProviderPlanOrQuotaRefusal,
|
|
205
|
+
isMidTaskProgressText
|
|
206
|
+
};
|
|
213
207
|
|
|
214
208
|
function readMacDesktopPictures(): string | null {
|
|
215
209
|
try {
|
|
@@ -221,169 +215,6 @@ function readMacDesktopPictures(): string | null {
|
|
|
221
215
|
}
|
|
222
216
|
}
|
|
223
217
|
|
|
224
|
-
export function isExecutionOrLaunchTaskPrompt(text: string): boolean {
|
|
225
|
-
const t = (text || '').trim();
|
|
226
|
-
if (!t) return false;
|
|
227
|
-
return /\b(open|launch|start|run|play|serve|preview)\b/i.test(t)
|
|
228
|
-
&& !/\b(create|build|make|write|code|implement|generate|refactor)\b/i.test(t);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export function isCodeAuthoringTaskPrompt(text: string): boolean {
|
|
232
|
-
const t = (text || '').trim();
|
|
233
|
-
if (!t) return false;
|
|
234
|
-
if (isExecutionOrLaunchTaskPrompt(t)) return false;
|
|
235
|
-
return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function extractSkillIdFromPrompt(prompt: string): string {
|
|
239
|
-
const text = String(prompt || '').trim();
|
|
240
|
-
if (!text) return '';
|
|
241
|
-
const stopWords = new Set([
|
|
242
|
-
'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
|
|
243
|
-
'using', 'for', 'to', 'by', 'and', 'or', 'of'
|
|
244
|
-
]);
|
|
245
|
-
const leadingTrim = new Set(['`', '"', "'", '(', '[']);
|
|
246
|
-
const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
|
|
247
|
-
const cleanCandidate = (raw: string): string => {
|
|
248
|
-
const trimmed = raw.trim();
|
|
249
|
-
let start = 0;
|
|
250
|
-
let end = trimmed.length;
|
|
251
|
-
while (start < end && leadingTrim.has(trimmed[start]!)) start++;
|
|
252
|
-
while (end > start && trailingTrim.has(trimmed[end - 1]!)) end--;
|
|
253
|
-
const stripped = trimmed.slice(start, end);
|
|
254
|
-
if (!stripped || stopWords.has(stripped.toLowerCase())) return '';
|
|
255
|
-
if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
|
|
256
|
-
return '';
|
|
257
|
-
}
|
|
258
|
-
return stripped;
|
|
259
|
-
};
|
|
260
|
-
const isFileExt = (candidate: string): boolean =>
|
|
261
|
-
/\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
|
|
262
|
-
|
|
263
|
-
const cuedSlashMatch = text.match(
|
|
264
|
-
/(?:\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
|
|
265
|
-
);
|
|
266
|
-
if (cuedSlashMatch?.[1]) {
|
|
267
|
-
const candidate = cleanCandidate(cuedSlashMatch[1]);
|
|
268
|
-
if (candidate && !isFileExt(candidate)) {
|
|
269
|
-
return candidate;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
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)) {
|
|
273
|
-
const candidate = cleanCandidate(m[1] || '');
|
|
274
|
-
if (candidate && !isFileExt(candidate)) {
|
|
275
|
-
return candidate;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
const explicitQuotedMatch = text.match(
|
|
279
|
-
/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i
|
|
280
|
-
);
|
|
281
|
-
if (explicitQuotedMatch?.[1]) {
|
|
282
|
-
const candidate = cleanCandidate(explicitQuotedMatch[1]);
|
|
283
|
-
if (candidate) return candidate;
|
|
284
|
-
}
|
|
285
|
-
const bareMatch = text.match(
|
|
286
|
-
/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i
|
|
287
|
-
);
|
|
288
|
-
if (bareMatch?.[1]) {
|
|
289
|
-
const candidate = cleanCandidate(bareMatch[1]);
|
|
290
|
-
if (candidate) return candidate;
|
|
291
|
-
}
|
|
292
|
-
return '';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export function isDirectGameTask(text: string): boolean {
|
|
296
|
-
return isDirectGameTaskDecision(text);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function isProviderPlanOrQuotaRefusal(text: string): boolean {
|
|
300
|
-
if (!text || typeof text !== 'string') return false;
|
|
301
|
-
const trimmed = text.trim();
|
|
302
|
-
if (!trimmed || trimmed.length > 320) return false;
|
|
303
|
-
if (/^upgrade your plan to continue\.?$/i.test(trimmed)) return true;
|
|
304
|
-
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);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Detects when an agent response is an intermediate mid-task progress note or
|
|
309
|
-
* transition announcement (e.g. "Real assets verified. Writing the Tesla-style
|
|
310
|
-
* redesign now." or "Let me look at the newer assets... Pulling their real
|
|
311
|
-
* stills and confirming embeddability.") rather than a finished answer.
|
|
312
|
-
*/
|
|
313
|
-
export function isMidTaskProgressText(text: string): boolean {
|
|
314
|
-
if (!text || typeof text !== 'string') return false;
|
|
315
|
-
const trimmed = text.trim();
|
|
316
|
-
if (!trimmed || trimmed.length > 480) return false;
|
|
317
|
-
|
|
318
|
-
const lower = trimmed.toLowerCase();
|
|
319
|
-
if (
|
|
320
|
-
lower.includes('?') ||
|
|
321
|
-
lower.includes('let me know') ||
|
|
322
|
-
lower.includes('how can i help') ||
|
|
323
|
-
lower.includes('how may i help') ||
|
|
324
|
-
lower.includes('how can i assist') ||
|
|
325
|
-
lower.includes('what would you like') ||
|
|
326
|
-
lower.includes('what can i help') ||
|
|
327
|
-
lower.includes('feel free to')
|
|
328
|
-
) {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (trimmed.includes('```')) return false;
|
|
333
|
-
|
|
334
|
-
const sentences = trimmed
|
|
335
|
-
.split(/(?:(?<=[.!])\s+|\n+)/)
|
|
336
|
-
.map(s => s.trim())
|
|
337
|
-
.filter(Boolean);
|
|
338
|
-
const lastSentence = (sentences[sentences.length - 1] || trimmed).trim();
|
|
339
|
-
const lastLower = lastSentence.toLowerCase();
|
|
340
|
-
|
|
341
|
-
if (trimmed.length <= 280 && (trimmed.endsWith(':') || trimmed.endsWith('...') || trimmed.endsWith('…'))) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const intentPrefixes = [
|
|
346
|
-
'let me ',
|
|
347
|
-
"i'll ",
|
|
348
|
-
'i will ',
|
|
349
|
-
'now i ',
|
|
350
|
-
'now let me ',
|
|
351
|
-
"now i'll ",
|
|
352
|
-
'now i will ',
|
|
353
|
-
'next, i ',
|
|
354
|
-
'next i ',
|
|
355
|
-
"next, i'll ",
|
|
356
|
-
"next i'll ",
|
|
357
|
-
'first, i ',
|
|
358
|
-
'first i ',
|
|
359
|
-
'let us ',
|
|
360
|
-
"let's ",
|
|
361
|
-
'i shall ',
|
|
362
|
-
'we will ',
|
|
363
|
-
"we'll ",
|
|
364
|
-
'i am going to ',
|
|
365
|
-
"i'm going to ",
|
|
366
|
-
'going to '
|
|
367
|
-
];
|
|
368
|
-
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
|
|
369
|
-
if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
|
|
370
|
-
return true;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
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;
|
|
375
|
-
if (gerundStart.test(lastSentence) && lastSentence.length <= 220) {
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
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;
|
|
380
|
-
if (actionNowSuffix.test(lastSentence)) {
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
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.
|
|
388
219
|
|
|
389
220
|
${PEER_COLLABORATION_POLICY}
|
|
@@ -708,11 +539,19 @@ export class AgentLoop {
|
|
|
708
539
|
? options.workspaceRoot
|
|
709
540
|
: process.cwd();
|
|
710
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;
|
|
711
548
|
this.approvalScope = options.approvalScope && typeof options.approvalScope.isAlwaysAllowed === 'function'
|
|
712
549
|
? options.approvalScope
|
|
713
550
|
: processApprovalScope;
|
|
714
551
|
|
|
715
552
|
this.config = loadConfig();
|
|
553
|
+
if (this.providerOverride) this.config.provider = this.providerOverride;
|
|
554
|
+
if (this.modelOverride) this.config.model = this.modelOverride;
|
|
716
555
|
this.sandbox = new Sandbox({ workspaceRoot: this.workspaceRoot });
|
|
717
556
|
|
|
718
557
|
// Retire spilled tool outputs past their retention window. Fire-and-forget
|
|
@@ -853,6 +692,9 @@ export class AgentLoop {
|
|
|
853
692
|
this.approvalScope = createApprovalScope();
|
|
854
693
|
this.autonomyOverride = null;
|
|
855
694
|
this.circuitBreakerUnlocked = false;
|
|
695
|
+
for (const toolCallId of [...this.pendingApprovals.keys()]) {
|
|
696
|
+
this.handleApprovalResponse(toolCallId, false);
|
|
697
|
+
}
|
|
856
698
|
this.pendingApprovals.clear();
|
|
857
699
|
}
|
|
858
700
|
|
|
@@ -1721,6 +1563,8 @@ export class AgentLoop {
|
|
|
1721
1563
|
updateTierLimits() {
|
|
1722
1564
|
this.config = loadConfig();
|
|
1723
1565
|
if (this.autonomyOverride) this.config.autonomyMode = this.autonomyOverride;
|
|
1566
|
+
if (this.providerOverride) this.config.provider = this.providerOverride;
|
|
1567
|
+
if (this.modelOverride) this.config.model = this.modelOverride;
|
|
1724
1568
|
if (typeof this.initializeProvider === 'function') {
|
|
1725
1569
|
const nextProvider = this.initializeProvider();
|
|
1726
1570
|
if (nextProvider) {
|
|
@@ -4780,7 +4624,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
4780
4624
|
|
|
4781
4625
|
// Active Inference: Record step prediction error into VFE rolling tracker
|
|
4782
4626
|
if (this.vfeTracker) {
|
|
4783
|
-
const isThrash = isThrashing((this._planSteps || []).map((s) => s.tool)
|
|
4627
|
+
const isThrash = isThrashing((this._planSteps || []).map((s) => s.tool));
|
|
4784
4628
|
const vfeOutcome = this.vfeTracker.recordStep({
|
|
4785
4629
|
tool: functionName,
|
|
4786
4630
|
success: stepSuccess,
|
|
@@ -5053,16 +4897,19 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5053
4897
|
// wall-clock limits, before deciding whether recovery is possible.
|
|
5054
4898
|
if (e?.partialUsage) {
|
|
5055
4899
|
const usage = e.partialUsage;
|
|
5056
|
-
|
|
4900
|
+
const promptTokens = Number.isFinite(Number(usage.promptTokens)) ? Math.max(0, Number(usage.promptTokens)) : 0;
|
|
4901
|
+
const completionTokens = Number.isFinite(Number(usage.completionTokens)) ? Math.max(0, Number(usage.completionTokens)) : 0;
|
|
4902
|
+
const cachedPromptTokens = Number.isFinite(Number(usage.cachedPromptTokens)) ? Math.max(0, Number(usage.cachedPromptTokens)) : 0;
|
|
4903
|
+
if (promptTokens + completionTokens > 0) {
|
|
5057
4904
|
await this.tokenTracker.trackUsage(
|
|
5058
|
-
|
|
4905
|
+
promptTokens, completionTokens,
|
|
5059
4906
|
(message: string) => this.emitEvent({ type: 'budget_warning', message }), usage
|
|
5060
4907
|
);
|
|
5061
4908
|
auditLog.log({
|
|
5062
4909
|
event: 'model_usage', scope: 'agent_loop_primary', taskId: this.taskId,
|
|
5063
4910
|
step: this.stepsCompleted, provider: this.config.provider || 'unknown',
|
|
5064
|
-
promptTokens
|
|
5065
|
-
cachedPromptTokens
|
|
4911
|
+
promptTokens, completionTokens,
|
|
4912
|
+
cachedPromptTokens,
|
|
5066
4913
|
measurement: 'provider_reported_partial', costBasis: 'external_subscription_unavailable'
|
|
5067
4914
|
});
|
|
5068
4915
|
}
|
|
@@ -5274,69 +5121,12 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5274
5121
|
|
|
5275
5122
|
// V5: Classify errors for intelligent retry decisions
|
|
5276
5123
|
classifyError(error: any) {
|
|
5277
|
-
|
|
5278
|
-
if (error?.code === 'AGY_NATIVE_ACTION_DENIED'
|
|
5279
|
-
|| error?.code === 'AGY_NATIVE_ACTION_BUDGET'
|
|
5280
|
-
|| error?.code === 'AGY_DESKTOP_TASK_LIMIT') return 'fatal';
|
|
5281
|
-
// A provider may have charged for completed steps before the turn failed.
|
|
5282
|
-
// Replaying that turn can repeat actions and spend the same tokens again.
|
|
5283
|
-
const spent = Number(error?.partialUsage?.promptTokens || 0)
|
|
5284
|
-
+ Number(error?.partialUsage?.completionTokens || 0);
|
|
5285
|
-
if (spent > 0) return 'fatal';
|
|
5286
|
-
const msg = (typeof error === 'string' ? error : error?.message || '').toLowerCase();
|
|
5287
|
-
|
|
5288
|
-
if (error?.name === 'OpenRouterPrivacyConstraintError'
|
|
5289
|
-
|| msg.includes('matching the privacy policy')
|
|
5290
|
-
|| msg.includes('data_collection=')) {
|
|
5291
|
-
return 'fatal';
|
|
5292
|
-
}
|
|
5293
|
-
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')) {
|
|
5294
|
-
return 'fatal';
|
|
5295
|
-
}
|
|
5296
|
-
if (msg.includes('syntax') || msg.includes('unexpected token') || msg.includes('invalid json')) {
|
|
5297
|
-
return 'syntax_error';
|
|
5298
|
-
}
|
|
5299
|
-
if (msg.includes('enoent') || msg.includes('no such file') || msg.includes('not found') || msg.includes('does not exist')) {
|
|
5300
|
-
return 'path_not_found';
|
|
5301
|
-
}
|
|
5302
|
-
if (msg.includes('econnrefused') || msg.includes('econnreset') || msg.includes('etimedout') || msg.includes('fetch failed') || msg.includes('network')) {
|
|
5303
|
-
return "network_error";
|
|
5304
|
-
}
|
|
5305
|
-
if (msg.includes('rate limit') || msg.includes('429') || msg.includes('too many requests') || msg.includes('quota')) {
|
|
5306
|
-
return 'rate_limit';
|
|
5307
|
-
}
|
|
5308
|
-
if (msg.includes('eacces') || msg.includes('permission denied') || msg.includes('eperm')) {
|
|
5309
|
-
return 'permission_denied';
|
|
5310
|
-
}
|
|
5311
|
-
if (msg.includes('401') || msg.includes('403') || msg.includes('unauthorized') || msg.includes('api key')) {
|
|
5312
|
-
return 'auth_error';
|
|
5313
|
-
}
|
|
5314
|
-
if (msg.includes('400') || msg.includes('invalid_parameter') || msg.includes('invalid_request') || msg.includes('required property') || msg.includes('bad request')) {
|
|
5315
|
-
return 'invalid_request_error';
|
|
5316
|
-
}
|
|
5317
|
-
if (msg.includes('kill') || msg.includes('abort') || msg.includes('signal') || msg.includes('fatal')) {
|
|
5318
|
-
return 'fatal';
|
|
5319
|
-
}
|
|
5320
|
-
if (error instanceof TypeError || error instanceof ReferenceError || error instanceof RangeError) {
|
|
5321
|
-
return 'fatal';
|
|
5322
|
-
}
|
|
5323
|
-
|
|
5324
|
-
return 'unknown_error';
|
|
5124
|
+
return classifyAgentError(error);
|
|
5325
5125
|
}
|
|
5326
5126
|
|
|
5327
5127
|
// V5: Provide actionable retry hints per error type
|
|
5328
5128
|
getRetryHint(errorType: string) {
|
|
5329
|
-
|
|
5330
|
-
'syntax_error': 'Check your command syntax or JSON structure. Ensure quotes are balanced.',
|
|
5331
|
-
'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.',
|
|
5332
|
-
["network_error"]: "Network connectivity issue. Wait a moment and retry. If persistent, check if the URL is correct.",
|
|
5333
|
-
'rate_limit': 'API rate limit hit. Wait 5-10 seconds before retrying.',
|
|
5334
|
-
'permission_denied': 'Permission denied. Check if the path is within allowed workspace paths. Try a different directory.',
|
|
5335
|
-
'auth_error': 'Authentication failed. Do NOT retry — the API key may be invalid.',
|
|
5336
|
-
'invalid_request_error': 'API request format error (400 Bad Request). Do NOT retry — check model parameter compliance.',
|
|
5337
|
-
'unknown_error': 'An unexpected error occurred. Try a different approach entirely.'
|
|
5338
|
-
};
|
|
5339
|
-
return hints[errorType] || hints['unknown_error'];
|
|
5129
|
+
return getRetryHintForError(errorType);
|
|
5340
5130
|
}
|
|
5341
5131
|
|
|
5342
5132
|
async runPreToolUse(toolName: string, args: any, toolCallId: string) {
|
|
@@ -5364,98 +5154,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
5364
5154
|
}
|
|
5365
5155
|
|
|
5366
5156
|
// V5: Validate tool call arguments before execution
|
|
5367
|
-
|
|
5368
5157
|
validateToolArgs(toolName: string, args: any) {
|
|
5369
|
-
|
|
5370
|
-
return 'Tool arguments must be a JSON object';
|
|
5371
|
-
}
|
|
5372
|
-
|
|
5373
|
-
const baseDir = this.workspaceRoot || process.cwd();
|
|
5374
|
-
const resolveOne = (raw: string): string | null => {
|
|
5375
|
-
const val = raw.trim();
|
|
5376
|
-
if (!val || /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val)) {
|
|
5377
|
-
return null;
|
|
5378
|
-
}
|
|
5379
|
-
if (val === '~' || val.startsWith('~/') || val.startsWith('~\\')) {
|
|
5380
|
-
return val.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
5381
|
-
}
|
|
5382
|
-
if (!path.isAbsolute(val)) {
|
|
5383
|
-
return path.resolve(baseDir, val);
|
|
5384
|
-
}
|
|
5385
|
-
return val;
|
|
5386
|
-
};
|
|
5387
|
-
|
|
5388
|
-
// 1. File operations must have absolute paths (fs_read_skill uses skill-relative file_path)
|
|
5389
|
-
const nonPathTargetTools = new Set(['vision_inspect_ui', 'astryx_oracle', 'desktop_act']);
|
|
5390
|
-
if (toolName !== 'fs_read_skill') {
|
|
5391
|
-
const pathFields = [
|
|
5392
|
-
'path', 'searchPath', 'cwd', 'directory',
|
|
5393
|
-
'source', 'destination', 'file_path', 'filePath', 'filepath',
|
|
5394
|
-
'targetFile', 'outputFile', 'outputPath',
|
|
5395
|
-
...(nonPathTargetTools.has(toolName) ? [] : ['target'])
|
|
5396
|
-
];
|
|
5397
|
-
for (const field of pathFields) {
|
|
5398
|
-
if (args[field] && typeof args[field] === 'string') {
|
|
5399
|
-
const resolved = resolveOne(args[field]);
|
|
5400
|
-
if (resolved !== null) {
|
|
5401
|
-
args[field] = resolved;
|
|
5402
|
-
}
|
|
5403
|
-
}
|
|
5404
|
-
}
|
|
5405
|
-
if (Array.isArray(args.target_directories)) {
|
|
5406
|
-
args.target_directories = args.target_directories.map((entry: unknown) => {
|
|
5407
|
-
if (typeof entry !== 'string') return entry;
|
|
5408
|
-
return resolveOne(entry) ?? entry;
|
|
5409
|
-
});
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5412
|
-
|
|
5413
|
-
// 2. Terminal commands must have a command string
|
|
5414
|
-
if ((toolName === 'sysRun' || toolName === 'sysRunBg') && !args.command) {
|
|
5415
|
-
return 'Missing required "command" argument';
|
|
5416
|
-
}
|
|
5417
|
-
|
|
5418
|
-
// 3. File write must have a path AND content.
|
|
5419
|
-
//
|
|
5420
|
-
// These branches were dead: canonicalToolName() (called on every tool name
|
|
5421
|
-
// before this runs) normalises '.'→'_', so `toolName` is 'fs_write', never
|
|
5422
|
-
// 'fs.write'. The old 'fs.write' / 'codebase.search' / 'web.search' literals
|
|
5423
|
-
// could never match, so the model's missing-argument mistakes reached the
|
|
5424
|
-
// tool as runtime exceptions instead of a corrective message. Matched on the
|
|
5425
|
-
// canonical names now, and fs_write's `content` is actually checked (the old
|
|
5426
|
-
// comment said "must have content" but the code only looked at `path`).
|
|
5427
|
-
if (toolName === 'fs_write' && !args.path) {
|
|
5428
|
-
return 'Missing required "path" argument';
|
|
5429
|
-
}
|
|
5430
|
-
if (toolName === 'fs_write' && args.content === undefined) {
|
|
5431
|
-
return 'Missing required "content" argument';
|
|
5432
|
-
}
|
|
5433
|
-
|
|
5434
|
-
// 4. Search must have a query
|
|
5435
|
-
if ((toolName === 'codebase_search' || toolName === 'web_search') && !args.query) {
|
|
5436
|
-
return 'Missing required "query" argument';
|
|
5437
|
-
}
|
|
5438
|
-
|
|
5439
|
-
// 5. Tool search must have a query, pack, or names array
|
|
5440
|
-
if (toolName === 'tool_search') {
|
|
5441
|
-
const q = typeof args.query === 'string'
|
|
5442
|
-
? args.query.trim()
|
|
5443
|
-
: (Array.isArray(args.query) ? args.query.map(String).join(' ').trim() : '');
|
|
5444
|
-
const p = typeof args.pack === 'string' ? args.pack.trim() : '';
|
|
5445
|
-
const n = Array.isArray(args.names) && args.names.length > 0;
|
|
5446
|
-
if (!q && !p && !n) {
|
|
5447
|
-
return 'Missing required "query" or "pack" argument';
|
|
5448
|
-
}
|
|
5449
|
-
}
|
|
5450
|
-
|
|
5451
|
-
// 6. Skill reader must have a non-empty skill_id
|
|
5452
|
-
if (toolName === 'fs_read_skill') {
|
|
5453
|
-
const sid = typeof args.skill_id === 'string' ? args.skill_id.trim() : '';
|
|
5454
|
-
if (!sid) {
|
|
5455
|
-
return 'Missing required "skill_id" argument';
|
|
5456
|
-
}
|
|
5457
|
-
}
|
|
5458
|
-
|
|
5459
|
-
return null; // No validation errors
|
|
5158
|
+
return validateAndNormalizeToolArgs(toolName, args, this.workspaceRoot || process.cwd());
|
|
5460
5159
|
}
|
|
5461
5160
|
}
|
package/src/approvalGrants.js
CHANGED
|
@@ -19,18 +19,26 @@
|
|
|
19
19
|
// side-effect of a keypress in a modal.
|
|
20
20
|
/** Tool names approved for the rest of this process. Deliberately in memory. */
|
|
21
21
|
const standingApprovals = new Set();
|
|
22
|
+
const MAX_STANDING_APPROVALS = 256;
|
|
22
23
|
function normalizeToolName(toolName) {
|
|
23
|
-
|
|
24
|
+
if (typeof toolName !== 'string')
|
|
25
|
+
return '';
|
|
26
|
+
const trimmed = toolName.trim();
|
|
27
|
+
if (!trimmed || trimmed === '*' || trimmed.length > 128 || /[\r\n\0]/.test(trimmed))
|
|
28
|
+
return '';
|
|
29
|
+
return trimmed.replace(/\./g, '_');
|
|
24
30
|
}
|
|
25
31
|
/** Record a standing approval for one canonical tool name. */
|
|
26
32
|
export function grantAlways(toolName) {
|
|
27
33
|
const name = normalizeToolName(toolName);
|
|
28
|
-
if (name)
|
|
34
|
+
if (name && (standingApprovals.has(name) || standingApprovals.size < MAX_STANDING_APPROVALS)) {
|
|
29
35
|
standingApprovals.add(name);
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
/** True when this tool may run without asking again. */
|
|
32
39
|
export function isAlwaysAllowed(toolName) {
|
|
33
|
-
|
|
40
|
+
const name = normalizeToolName(toolName);
|
|
41
|
+
return name.length > 0 && standingApprovals.has(name);
|
|
34
42
|
}
|
|
35
43
|
/** Every standing approval, for `/approvals` and for the audit trail. */
|
|
36
44
|
export function listAlwaysAllowed() {
|
|
@@ -44,7 +52,8 @@ export function revokeAllAlways() {
|
|
|
44
52
|
}
|
|
45
53
|
/** Revoke one standing approval. */
|
|
46
54
|
export function revokeAlways(toolName) {
|
|
47
|
-
|
|
55
|
+
const name = normalizeToolName(toolName);
|
|
56
|
+
return name.length > 0 && standingApprovals.delete(name);
|
|
48
57
|
}
|
|
49
58
|
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
50
59
|
export function createApprovalScope() {
|
|
@@ -52,11 +61,13 @@ export function createApprovalScope() {
|
|
|
52
61
|
return {
|
|
53
62
|
grantAlways(toolName) {
|
|
54
63
|
const name = normalizeToolName(toolName);
|
|
55
|
-
if (name)
|
|
64
|
+
if (name && (approvals.has(name) || approvals.size < MAX_STANDING_APPROVALS)) {
|
|
56
65
|
approvals.add(name);
|
|
66
|
+
}
|
|
57
67
|
},
|
|
58
68
|
isAlwaysAllowed(toolName) {
|
|
59
|
-
|
|
69
|
+
const name = normalizeToolName(toolName);
|
|
70
|
+
return name.length > 0 && approvals.has(name);
|
|
60
71
|
},
|
|
61
72
|
listAlwaysAllowed() {
|
|
62
73
|
return [...approvals].sort();
|
|
@@ -67,7 +78,8 @@ export function createApprovalScope() {
|
|
|
67
78
|
return count;
|
|
68
79
|
},
|
|
69
80
|
revokeAlways(toolName) {
|
|
70
|
-
|
|
81
|
+
const name = normalizeToolName(toolName);
|
|
82
|
+
return name.length > 0 && approvals.delete(name);
|
|
71
83
|
}
|
|
72
84
|
};
|
|
73
85
|
}
|
package/src/approvalGrants.ts
CHANGED
|
@@ -37,19 +37,27 @@ export interface ApprovalScope {
|
|
|
37
37
|
/** Tool names approved for the rest of this process. Deliberately in memory. */
|
|
38
38
|
const standingApprovals = new Set<string>();
|
|
39
39
|
|
|
40
|
+
const MAX_STANDING_APPROVALS = 256;
|
|
41
|
+
|
|
40
42
|
function normalizeToolName(toolName: unknown): string {
|
|
41
|
-
|
|
43
|
+
if (typeof toolName !== 'string') return '';
|
|
44
|
+
const trimmed = toolName.trim();
|
|
45
|
+
if (!trimmed || trimmed === '*' || trimmed.length > 128 || /[\r\n\0]/.test(trimmed)) return '';
|
|
46
|
+
return trimmed.replace(/\./g, '_');
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
/** Record a standing approval for one canonical tool name. */
|
|
45
50
|
export function grantAlways(toolName: unknown): void {
|
|
46
51
|
const name = normalizeToolName(toolName);
|
|
47
|
-
if (name
|
|
52
|
+
if (name && (standingApprovals.has(name) || standingApprovals.size < MAX_STANDING_APPROVALS)) {
|
|
53
|
+
standingApprovals.add(name);
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/** True when this tool may run without asking again. */
|
|
51
58
|
export function isAlwaysAllowed(toolName: unknown): boolean {
|
|
52
|
-
|
|
59
|
+
const name = normalizeToolName(toolName);
|
|
60
|
+
return name.length > 0 && standingApprovals.has(name);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
/** Every standing approval, for `/approvals` and for the audit trail. */
|
|
@@ -66,7 +74,8 @@ export function revokeAllAlways(): number {
|
|
|
66
74
|
|
|
67
75
|
/** Revoke one standing approval. */
|
|
68
76
|
export function revokeAlways(toolName: unknown): boolean {
|
|
69
|
-
|
|
77
|
+
const name = normalizeToolName(toolName);
|
|
78
|
+
return name.length > 0 && standingApprovals.delete(name);
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
@@ -75,10 +84,13 @@ export function createApprovalScope(): ApprovalScope {
|
|
|
75
84
|
return {
|
|
76
85
|
grantAlways(toolName) {
|
|
77
86
|
const name = normalizeToolName(toolName);
|
|
78
|
-
if (name
|
|
87
|
+
if (name && (approvals.has(name) || approvals.size < MAX_STANDING_APPROVALS)) {
|
|
88
|
+
approvals.add(name);
|
|
89
|
+
}
|
|
79
90
|
},
|
|
80
91
|
isAlwaysAllowed(toolName) {
|
|
81
|
-
|
|
92
|
+
const name = normalizeToolName(toolName);
|
|
93
|
+
return name.length > 0 && approvals.has(name);
|
|
82
94
|
},
|
|
83
95
|
listAlwaysAllowed() {
|
|
84
96
|
return [...approvals].sort();
|
|
@@ -89,7 +101,8 @@ export function createApprovalScope(): ApprovalScope {
|
|
|
89
101
|
return count;
|
|
90
102
|
},
|
|
91
103
|
revokeAlways(toolName) {
|
|
92
|
-
|
|
104
|
+
const name = normalizeToolName(toolName);
|
|
105
|
+
return name.length > 0 && approvals.delete(name);
|
|
93
106
|
}
|
|
94
107
|
};
|
|
95
108
|
}
|