@causyne/agent 1.10.21 → 1.12.0
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/docs/THIRD_PARTY_NOTICES.md +12 -0
- package/native-skills/media/professional-document-publishing/SKILL.md +44 -0
- package/native-skills/media/screenplay-and-shotlist-forge/SKILL.md +42 -0
- package/package.json +1 -1
- package/src/acp/client.js +235 -0
- package/src/acp/client.ts +282 -0
- package/src/acp/peerProfiles.js +122 -0
- package/src/acp/peerProfiles.ts +128 -0
- package/src/acp/protocol.js +55 -0
- package/src/acp/protocol.ts +456 -0
- package/src/acp/server.js +746 -0
- package/src/acp/server.ts +822 -0
- package/src/agentLoop.d.ts +64 -0
- package/src/agentLoop.js +156 -12
- package/src/approvalGrants.js +33 -0
- package/src/approvalGrants.ts +50 -0
- package/src/commands.js +203 -0
- package/src/compiledSkills.js +10 -0
- package/src/decisionPolicy.js +2 -0
- package/src/decisionPolicy.ts +1 -0
- package/src/documentEngine/antiSlopAuditor.js +156 -0
- package/src/documentEngine/antiSlopAuditor.ts +221 -0
- package/src/documentEngine/documentForge.js +443 -0
- package/src/documentEngine/documentForge.ts +519 -0
- package/src/documentEngine/screenplayFormatter.js +336 -0
- package/src/documentEngine/screenplayFormatter.ts +407 -0
- package/src/engines/cad.js +113 -0
- package/src/engines/cad.ts +128 -0
- package/src/engines/film.js +108 -0
- package/src/engines/film.ts +104 -0
- package/src/engines/installer.js +226 -0
- package/src/engines/installer.ts +248 -0
- package/src/engines/photo.js +126 -0
- package/src/engines/photo.ts +137 -0
- package/src/engines/registry.js +186 -0
- package/src/engines/registry.ts +185 -0
- package/src/engines/sound.js +117 -0
- package/src/engines/sound.ts +130 -0
- package/src/engines/types.js +1 -0
- package/src/engines/types.ts +73 -0
- package/src/entrypoint.js +13 -0
- package/src/execSafe.js +10 -13
- package/src/execSafe.ts +25 -0
- package/src/memoryManager.js +9 -3
- package/src/modelRouter.js +56 -123
- package/src/modelRouter.ts +134 -0
- package/src/observer/advisory.js +164 -0
- package/src/observer/advisory.ts +171 -0
- package/src/observer/coldObserver.js +462 -0
- package/src/observer/coldObserver.ts +540 -0
- package/src/observer/evidence.js +435 -0
- package/src/observer/evidence.ts +499 -0
- package/src/perception.js +303 -118
- package/src/perception.ts +387 -0
- package/src/procSignal.js +15 -16
- package/src/procSignal.ts +31 -0
- package/src/promptMentions.js +170 -0
- package/src/promptMentions.ts +212 -0
- package/src/sandbox.js +9 -1
- package/src/sessionJournal.js +12 -2
- package/src/sessionJournal.ts +12 -2
- package/src/textDiff.js +117 -109
- package/src/textDiff.ts +169 -0
- package/src/toolPacks.js +19 -8
- package/src/tools/documentForge.js +215 -0
- package/src/tools/documentForge.ts +265 -0
- package/src/tools/generateMediaViaApi.js +1 -1
- package/src/tools/nativeEngine.js +464 -0
- package/src/tools/nativeEngine.ts +433 -0
- package/src/tools/openSourceToolProvisioner.js +510 -0
- package/src/tools/openSourceToolProvisioner.ts +590 -0
- package/src/tools/peerAgent.js +102 -0
- package/src/tools/peerAgent.ts +116 -0
- package/src/tools/registry.js +6 -1
- package/src/tui/completion.js +98 -42
- package/src/tui/prompt.js +17 -17
- package/src/uncertainty.js +93 -205
- package/src/uncertainty.ts +255 -0
- package/src/utils/paths.js +15 -18
- package/src/utils/paths.ts +36 -0
- package/src/vfeTracker.js +122 -181
- package/src/vfeTracker.ts +242 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface AgentLoopEvent {
|
|
2
|
+
type: string;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface AgentLoopEventSink {
|
|
7
|
+
readyState?: number;
|
|
8
|
+
send(payload: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AgentLoopConfig {
|
|
12
|
+
autonomyMode?: 'A' | 'B' | 'C' | string;
|
|
13
|
+
maxStepsPerTask?: number;
|
|
14
|
+
tokenBudget?: Record<string, unknown>;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ApprovalDecision {
|
|
19
|
+
approved: boolean;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AgentLoopApprovalScope {
|
|
24
|
+
grantAlways(toolName: unknown): void;
|
|
25
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
26
|
+
listAlwaysAllowed(): string[];
|
|
27
|
+
revokeAllAlways(): number;
|
|
28
|
+
revokeAlways(toolName: unknown): boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AgentLoopOptions {
|
|
32
|
+
workspaceRoot?: string;
|
|
33
|
+
memorySessionId?: string | null;
|
|
34
|
+
approvalScope?: AgentLoopApprovalScope;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class AgentLoop {
|
|
38
|
+
constructor(
|
|
39
|
+
eventSink: AgentLoopEventSink | null,
|
|
40
|
+
taskId: string,
|
|
41
|
+
userPrompt: string | null,
|
|
42
|
+
options?: AgentLoopOptions
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
eventSink: AgentLoopEventSink | null;
|
|
46
|
+
taskId: string;
|
|
47
|
+
userPrompt: string | null;
|
|
48
|
+
workspaceRoot: string;
|
|
49
|
+
approvalScope: AgentLoopApprovalScope;
|
|
50
|
+
autonomyOverride: string | null;
|
|
51
|
+
config: AgentLoopConfig;
|
|
52
|
+
stepsCompleted: number;
|
|
53
|
+
|
|
54
|
+
run(): Promise<void>;
|
|
55
|
+
abort(): void;
|
|
56
|
+
rearmAbortController(): void;
|
|
57
|
+
setAutonomyMode(mode: 'A' | 'B' | 'C' | string): void;
|
|
58
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
59
|
+
emitEvent(event: AgentLoopEvent): void;
|
|
60
|
+
waitForApproval(toolCallId: string): Promise<boolean>;
|
|
61
|
+
handleApprovalResponse(toolCallId: string, decision: ApprovalDecision | boolean): void;
|
|
62
|
+
waitForDecision(request: Record<string, unknown>): Promise<unknown>;
|
|
63
|
+
updateTierLimits(): void;
|
|
64
|
+
}
|
package/src/agentLoop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { processApprovalScope } from './approvalGrants.js';
|
|
3
3
|
import { pruneSessions as pruneEmbodimentSessions, describeSession } from './embodimentSession.js';
|
|
4
4
|
import { WorkspacePerception } from './perception.js';
|
|
5
5
|
import { audioFormatForMimeType } from './providers/base.js';
|
|
@@ -22,6 +22,7 @@ import { routedConfig } from './modelRouter.js';
|
|
|
22
22
|
import { assessStep, isThrashing } from './uncertainty.js';
|
|
23
23
|
import { assessDecisionRequirement, isMutatingToolCall, requiresImplementationPlan } from './decisionPolicy.js';
|
|
24
24
|
import { VFETracker } from './vfeTracker.js';
|
|
25
|
+
import { coldObserver } from './observer/coldObserver.js';
|
|
25
26
|
import {
|
|
26
27
|
routePacks,
|
|
27
28
|
packForTool,
|
|
@@ -54,6 +55,7 @@ import os from 'os';
|
|
|
54
55
|
import { analyzeFiles, formatFindings, isScannableFile } from './slopDetector.js';
|
|
55
56
|
import { suggestMovements, formatMovementBrief } from './designPalettes.js';
|
|
56
57
|
import { createProvider } from './providers/factory.js';
|
|
58
|
+
import { resolveMentionedContext } from './promptMentions.js';
|
|
57
59
|
|
|
58
60
|
const SYSTEM_PROMPT = `You are Causyne Agent, a God-Tier Autonomous AI. You operate the user's computer through a local desktop harness. You are not just a coding assistant; you are a general-purpose superintelligence.
|
|
59
61
|
|
|
@@ -317,11 +319,18 @@ export class AgentLoop {
|
|
|
317
319
|
* endpoint is reported in seconds rather than after the whole step budget.
|
|
318
320
|
*/
|
|
319
321
|
static MAX_CONSECUTIVE_FAILURES = 3;
|
|
320
|
-
constructor(eventSink, taskId, userPrompt) {
|
|
322
|
+
constructor(eventSink, taskId, userPrompt, options = {}) {
|
|
321
323
|
this.eventSink = eventSink;
|
|
322
324
|
this.taskId = taskId;
|
|
323
325
|
this.userPrompt = userPrompt;
|
|
324
|
-
|
|
326
|
+
this.workspaceRoot = typeof options.workspaceRoot === 'string' && options.workspaceRoot
|
|
327
|
+
? options.workspaceRoot
|
|
328
|
+
: process.cwd();
|
|
329
|
+
this.autonomyOverride = null;
|
|
330
|
+
this.approvalScope = options.approvalScope && typeof options.approvalScope.isAlwaysAllowed === 'function'
|
|
331
|
+
? options.approvalScope
|
|
332
|
+
: processApprovalScope;
|
|
333
|
+
|
|
325
334
|
this.config = loadConfig();
|
|
326
335
|
this.sandbox = new Sandbox();
|
|
327
336
|
|
|
@@ -342,7 +351,7 @@ export class AgentLoop {
|
|
|
342
351
|
this.tokenTracker = new TokenTracker();
|
|
343
352
|
|
|
344
353
|
this.llm = this.initializeProvider();
|
|
345
|
-
this.memoryManager = new MemoryManager();
|
|
354
|
+
this.memoryManager = new MemoryManager(this.workspaceRoot, options.memorySessionId || null);
|
|
346
355
|
this.messages = this.memoryManager.loadHistory(); // Persistent context window
|
|
347
356
|
this.stepsCompleted = 0;
|
|
348
357
|
this.consecutiveCommands = 0;
|
|
@@ -378,6 +387,7 @@ export class AgentLoop {
|
|
|
378
387
|
// prompt-cache prefix intact when a pack loads mid-task.
|
|
379
388
|
this.unlockOrder = [];
|
|
380
389
|
this.workspaceContext = null;
|
|
390
|
+
this.activeSubproject = null;
|
|
381
391
|
this.taskShape = null;
|
|
382
392
|
// Budget for the billed Tier 2 Cortex condensation pass.
|
|
383
393
|
this._cortexPassesUsed = 0;
|
|
@@ -398,6 +408,7 @@ export class AgentLoop {
|
|
|
398
408
|
// P6: rendered surfaces this task wrote, for the anti-slop gate to read back.
|
|
399
409
|
this.webArtifacts = new Set();
|
|
400
410
|
this.slopGateFired = false;
|
|
411
|
+
this.coldObserverGuardFired = false;
|
|
401
412
|
|
|
402
413
|
this.gameCascadeState = { active: true, currentStage: 1, stageHistory: [], verificationPassed: false };
|
|
403
414
|
this.gameToolStats = { godot_act: 0, game_asset_fetch: 0, game_build_html5: 0, last_godot_action: null };
|
|
@@ -416,6 +427,11 @@ export class AgentLoop {
|
|
|
416
427
|
this.toolScope = null;
|
|
417
428
|
}
|
|
418
429
|
|
|
430
|
+
/** True when this loop's own conversation scope has a standing approval. */
|
|
431
|
+
isAlwaysAllowed(toolName) {
|
|
432
|
+
return this.approvalScope.isAlwaysAllowed(toolName);
|
|
433
|
+
}
|
|
434
|
+
|
|
419
435
|
// V6: Adaptive Temperature based on task intent
|
|
420
436
|
determineTemperature(prompt) {
|
|
421
437
|
if (!prompt) return 0.1;
|
|
@@ -534,6 +550,15 @@ export class AgentLoop {
|
|
|
534
550
|
}
|
|
535
551
|
}
|
|
536
552
|
|
|
553
|
+
setAutonomyMode(mode) {
|
|
554
|
+
const normalized = String(mode || '').trim().toUpperCase();
|
|
555
|
+
if (!['A', 'B', 'C'].includes(normalized)) {
|
|
556
|
+
throw new Error('autonomy mode must be A, B, or C');
|
|
557
|
+
}
|
|
558
|
+
this.autonomyOverride = normalized;
|
|
559
|
+
this.config.autonomyMode = normalized;
|
|
560
|
+
}
|
|
561
|
+
|
|
537
562
|
/**
|
|
538
563
|
* A provider for UTILITY work — condensation, classification, filtering.
|
|
539
564
|
*
|
|
@@ -766,6 +791,7 @@ export class AgentLoop {
|
|
|
766
791
|
|
|
767
792
|
updateTierLimits() {
|
|
768
793
|
this.config = loadConfig();
|
|
794
|
+
if (this.autonomyOverride) this.config.autonomyMode = this.autonomyOverride;
|
|
769
795
|
if (typeof this.initializeProvider === 'function') {
|
|
770
796
|
this.llm = this.initializeProvider();
|
|
771
797
|
this._utilityLlm = null; // the route is derived from the model; re-derive it
|
|
@@ -817,6 +843,8 @@ export class AgentLoop {
|
|
|
817
843
|
// awareness instead of burning steps rediscovering it. The result used to be
|
|
818
844
|
// assigned to a local variable and thrown away.
|
|
819
845
|
auditLog.log({ event: 'task_start', taskId: this.taskId, request: this.userPrompt });
|
|
846
|
+
this.workspaceRoot = process.cwd();
|
|
847
|
+
coldObserver.beginTask(this.taskId);
|
|
820
848
|
this.emitEvent({ type: 'status', message: 'Analyzing workspace...' });
|
|
821
849
|
|
|
822
850
|
// P2: open the undo group for this task. This snapshots the CONVERSATION as
|
|
@@ -872,6 +900,7 @@ export class AgentLoop {
|
|
|
872
900
|
this.webGuardFired = false;
|
|
873
901
|
this.webArtifacts = new Set();
|
|
874
902
|
this.slopGateFired = false;
|
|
903
|
+
this.coldObserverGuardFired = false;
|
|
875
904
|
this.staticContext = null;
|
|
876
905
|
// Plan cache: the procedure THIS task follows, and the template (if any)
|
|
877
906
|
// that was offered to it. Both reset per task — a plan is a property of one
|
|
@@ -964,6 +993,36 @@ export class AgentLoop {
|
|
|
964
993
|
}
|
|
965
994
|
|
|
966
995
|
if (this.userPrompt) {
|
|
996
|
+
// 1b. RESOLVE @ MENTIONS FOR REFERENCED FILES, DIRECTORIES & SUBPROJECTS
|
|
997
|
+
try {
|
|
998
|
+
const subprojects = this.workspaceContext?.subprojects || [];
|
|
999
|
+
const mentionResult = await resolveMentionedContext(this.userPrompt, {
|
|
1000
|
+
cwd: process.cwd(),
|
|
1001
|
+
subprojects
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
if (mentionResult.detectedSubproject) {
|
|
1005
|
+
this.activeSubproject = mentionResult.detectedSubproject;
|
|
1006
|
+
this.notice(`Focused on subproject '${mentionResult.detectedSubproject}'`);
|
|
1007
|
+
} else if (subprojects.length > 0) {
|
|
1008
|
+
const lowerPrompt = this.userPrompt.toLowerCase();
|
|
1009
|
+
for (const sp of subprojects) {
|
|
1010
|
+
if (lowerPrompt.includes(sp.toLowerCase())) {
|
|
1011
|
+
this.activeSubproject = sp;
|
|
1012
|
+
this.notice(`Focused on subproject '${sp}'`);
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
if (mentionResult.referencedContext) {
|
|
1019
|
+
this.userPrompt += mentionResult.referencedContext;
|
|
1020
|
+
this.notice(`Loaded ${mentionResult.mentions.length} referenced @ mention(s) into context`);
|
|
1021
|
+
}
|
|
1022
|
+
} catch (mentionErr) {
|
|
1023
|
+
this.debugLog(`mention resolution error: ${mentionErr.message}`);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
967
1026
|
this.currentTaskPrompt = this.userPrompt; // Save for notification later
|
|
968
1027
|
|
|
969
1028
|
// V5: Multimodal Attachments Support
|
|
@@ -1210,12 +1269,15 @@ export class AgentLoop {
|
|
|
1210
1269
|
const ctx = this.workspaceContext;
|
|
1211
1270
|
const facts = [
|
|
1212
1271
|
ctx.cwd && `Working directory: ${ctx.cwd}`,
|
|
1272
|
+
this.activeSubproject && `Active project focus: ${this.activeSubproject}`,
|
|
1273
|
+
ctx.projectName && `Workspace project: ${ctx.projectName}`,
|
|
1213
1274
|
ctx.os && `OS: ${ctx.os}`,
|
|
1214
1275
|
ctx.framework && `Framework: ${ctx.framework}`,
|
|
1215
1276
|
ctx.projectType && `Project type: ${ctx.projectType}`,
|
|
1216
1277
|
ctx.packageManager && `Package manager: ${ctx.packageManager}`,
|
|
1217
1278
|
ctx.gitBranch && `Git branch: ${ctx.gitBranch}`,
|
|
1218
1279
|
ctx.gitStatus && `Git status: ${ctx.gitStatus}`,
|
|
1280
|
+
Array.isArray(ctx.subprojects) && ctx.subprojects.length > 0 && `Subprojects in workspace: ${ctx.subprojects.join(', ')}`,
|
|
1219
1281
|
Array.isArray(ctx.keyFiles) && ctx.keyFiles.length > 0 && `Key files: ${ctx.keyFiles.slice(0, 25).join(', ')}`
|
|
1220
1282
|
].filter(Boolean);
|
|
1221
1283
|
if (facts.length > 0) {
|
|
@@ -1640,6 +1702,32 @@ export class AgentLoop {
|
|
|
1640
1702
|
}
|
|
1641
1703
|
}
|
|
1642
1704
|
|
|
1705
|
+
// Cold Observer: Overconfidence & Loop Verification Check
|
|
1706
|
+
if (!this.coldObserverGuardFired) {
|
|
1707
|
+
try {
|
|
1708
|
+
const coldAudit = await coldObserver.auditTurnVerification({
|
|
1709
|
+
taskId: this.taskId,
|
|
1710
|
+
userPrompt: this.currentTaskPrompt || this.userPrompt || '',
|
|
1711
|
+
agentClaim: response.content || '',
|
|
1712
|
+
toolHistory: [],
|
|
1713
|
+
stepsCompleted: this.stepsCompleted
|
|
1714
|
+
});
|
|
1715
|
+
|
|
1716
|
+
if (coldAudit.overconfident) {
|
|
1717
|
+
this.coldObserverGuardFired = true;
|
|
1718
|
+
this.emitEvent({ type: 'status', message: `Cold Observer: ${coldAudit.discrepancy}` });
|
|
1719
|
+
this.messages.push({
|
|
1720
|
+
role: 'system',
|
|
1721
|
+
content: coldAudit.coldDirective
|
|
1722
|
+
});
|
|
1723
|
+
this.memoryManager.saveHistory(this.messages);
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
} catch (_err) {
|
|
1727
|
+
// Cold observer fail-open
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1643
1731
|
this.emitEvent({ type: 'status', message: 'Task completed.' });
|
|
1644
1732
|
this.memoryManager.saveHistory(this.messages); // Save final state
|
|
1645
1733
|
|
|
@@ -1716,7 +1804,7 @@ export class AgentLoop {
|
|
|
1716
1804
|
continue;
|
|
1717
1805
|
}
|
|
1718
1806
|
|
|
1719
|
-
this.emitEvent({ type: 'step_start', tool: functionName, args: args });
|
|
1807
|
+
this.emitEvent({ type: 'step_start', tool: functionName, args: args, toolCallId: toolCall.id });
|
|
1720
1808
|
this.consecutiveCommands++;
|
|
1721
1809
|
|
|
1722
1810
|
if (functionName === 'screenshot' || functionName === 'vision_inspect_ui') {
|
|
@@ -1764,7 +1852,7 @@ export class AgentLoop {
|
|
|
1764
1852
|
|
|
1765
1853
|
if ((['fs_write'].includes(functionName) && isGameFileOrDir) || isEchoingToFile || isCustomScriptBlock) {
|
|
1766
1854
|
const interceptMsg = `[SOVEREIGN CASCADE VIOLATION: You attempted to skip from Stage ${this.gameCascadeState.currentStage} to Stage 7 without completing Stages 3, 4, 5, and 6 modularly. DO NOT write monolithic 20 KB custom scripts!]`;
|
|
1767
|
-
this.emitEvent({ type: 'step_error', tool: functionName, error: '
|
|
1855
|
+
this.emitEvent({ type: 'step_error', tool: functionName, error: 'Sovereign Game Intercept: Cascade violation detected.', toolCallId: toolCall.id });
|
|
1768
1856
|
this.messages.push({
|
|
1769
1857
|
role: 'tool',
|
|
1770
1858
|
tool_call_id: toolCall.id,
|
|
@@ -1802,7 +1890,7 @@ export class AgentLoop {
|
|
|
1802
1890
|
// Hard Circuit Breaker (Transcendence Context Consciousness)
|
|
1803
1891
|
if (this.consecutiveBlockedActions >= 4) {
|
|
1804
1892
|
const fatalMsg = `FATAL ERROR: Infinite Token Drain Detected. Agent repeatedly attempted blocked/forbidden actions 4 times in a row. Forcibly aborting task to save tokens.`;
|
|
1805
|
-
this.emitEvent({ type: 'step_error', tool: functionName, error: fatalMsg });
|
|
1893
|
+
this.emitEvent({ type: 'step_error', tool: functionName, error: fatalMsg, toolCallId: toolCall.id });
|
|
1806
1894
|
auditLog.log({ event: 'task_killed_circuit_breaker', taskId: this.taskId, reason: fatalMsg });
|
|
1807
1895
|
|
|
1808
1896
|
// Save memory of failure for RLTF
|
|
@@ -1817,7 +1905,11 @@ export class AgentLoop {
|
|
|
1817
1905
|
}
|
|
1818
1906
|
|
|
1819
1907
|
auditLog.log({ event: 'tool_blocked', taskId: this.taskId, tool: functionName, args, reason: validation.reason });
|
|
1820
|
-
this.
|
|
1908
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, {
|
|
1909
|
+
success: false,
|
|
1910
|
+
error: validation.reason
|
|
1911
|
+
});
|
|
1912
|
+
this.emitEvent({ type: 'step_error', tool: functionName, error: validation.reason, toolCallId: toolCall.id });
|
|
1821
1913
|
|
|
1822
1914
|
// Feed error back to LLM with absolute command to stop repeating
|
|
1823
1915
|
this.messages.push({
|
|
@@ -1896,6 +1988,10 @@ export class AgentLoop {
|
|
|
1896
1988
|
event: 'hook_denied', taskId: this.taskId, hookEvent: 'PreToolUse',
|
|
1897
1989
|
tool: functionName, reason: preHook.reason || 'hook denied'
|
|
1898
1990
|
});
|
|
1991
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, {
|
|
1992
|
+
success: false,
|
|
1993
|
+
error: `PreToolUse hook denied "${functionName}".`
|
|
1994
|
+
});
|
|
1899
1995
|
this.messages.push({
|
|
1900
1996
|
role: 'tool',
|
|
1901
1997
|
tool_call_id: toolCall.id,
|
|
@@ -1915,6 +2011,39 @@ export class AgentLoop {
|
|
|
1915
2011
|
// downloads ran unannounced.
|
|
1916
2012
|
const isHeavyAiDownload = functionName === 'manage_local_dependencies' &&
|
|
1917
2013
|
['pipInst', 'fetchBin', 'fetchMod'].includes(args.action);
|
|
2014
|
+
|
|
2015
|
+
// Cold Observer: Assess blast radius and mutation risk
|
|
2016
|
+
try {
|
|
2017
|
+
const coldMutation = await coldObserver.evaluateMutation(functionName, args, {
|
|
2018
|
+
workspaceRoot: this.workspaceRoot
|
|
2019
|
+
});
|
|
2020
|
+
if (coldMutation.veto) {
|
|
2021
|
+
this.emitEvent({
|
|
2022
|
+
type: 'status',
|
|
2023
|
+
message: `Cold Observer Veto: Action blocked (${coldMutation.reason})`
|
|
2024
|
+
});
|
|
2025
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, {
|
|
2026
|
+
success: false,
|
|
2027
|
+
error: `[COLD OBSERVER VETO]: ${coldMutation.reason}`
|
|
2028
|
+
});
|
|
2029
|
+
this.messages.push({
|
|
2030
|
+
role: 'tool',
|
|
2031
|
+
tool_call_id: toolCall.id,
|
|
2032
|
+
name: functionName,
|
|
2033
|
+
content: JSON.stringify({
|
|
2034
|
+
success: false,
|
|
2035
|
+
error: `[COLD OBSERVER VETO]: ${coldMutation.reason}. Modify your approach to avoid project damage.`
|
|
2036
|
+
})
|
|
2037
|
+
});
|
|
2038
|
+
continue;
|
|
2039
|
+
}
|
|
2040
|
+
if (coldMutation.requiresConfirmation) {
|
|
2041
|
+
validation.risk = 'dangerous';
|
|
2042
|
+
}
|
|
2043
|
+
} catch (_err) {
|
|
2044
|
+
// Cold observer mutation assessment fail-open
|
|
2045
|
+
}
|
|
2046
|
+
|
|
1918
2047
|
// A standing approval from "Allow always" lifts the gate for this
|
|
1919
2048
|
// tool until the process restarts. It is checked HERE rather than
|
|
1920
2049
|
|
|
@@ -1924,7 +2053,7 @@ export class AgentLoop {
|
|
|
1924
2053
|
// Nothing else is bypassed: the sandbox has already run above, so a
|
|
1925
2054
|
// FORBIDDEN command is still refused and a path outside the workspace
|
|
1926
2055
|
// is still blocked. This waives the QUESTION, not the guard.
|
|
1927
|
-
const standingApproval = isAlwaysAllowed(functionName);
|
|
2056
|
+
const standingApproval = this.isAlwaysAllowed(functionName);
|
|
1928
2057
|
if (standingApproval) {
|
|
1929
2058
|
auditLog.log({
|
|
1930
2059
|
event: 'approval_auto_granted', taskId: this.taskId,
|
|
@@ -1944,6 +2073,10 @@ export class AgentLoop {
|
|
|
1944
2073
|
const approved = await this.waitForApproval(toolCall.id);
|
|
1945
2074
|
|
|
1946
2075
|
if (!approved) {
|
|
2076
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, {
|
|
2077
|
+
success: false,
|
|
2078
|
+
error: 'User denied this action'
|
|
2079
|
+
});
|
|
1947
2080
|
this.messages.push({
|
|
1948
2081
|
role: 'tool',
|
|
1949
2082
|
tool_call_id: toolCall.id,
|
|
@@ -2031,7 +2164,8 @@ export class AgentLoop {
|
|
|
2031
2164
|
this.emitEvent({
|
|
2032
2165
|
type: 'step_error',
|
|
2033
2166
|
tool: functionName,
|
|
2034
|
-
error: `${errorType}: ${toolError.message} (retry ${currentRetries + 1}/${MAX_RETRIES} in ${backoffMs/1000}s)
|
|
2167
|
+
error: `${errorType}: ${toolError.message} (retry ${currentRetries + 1}/${MAX_RETRIES} in ${backoffMs/1000}s)`,
|
|
2168
|
+
toolCallId: toolCall.id
|
|
2035
2169
|
});
|
|
2036
2170
|
|
|
2037
2171
|
auditLog.log({
|
|
@@ -2066,7 +2200,12 @@ export class AgentLoop {
|
|
|
2066
2200
|
this.emitEvent({
|
|
2067
2201
|
type: 'step_error',
|
|
2068
2202
|
tool: functionName,
|
|
2069
|
-
error: `Failed after ${MAX_RETRIES} attempts: ${toolError.message}
|
|
2203
|
+
error: `Failed after ${MAX_RETRIES} attempts: ${toolError.message}`,
|
|
2204
|
+
toolCallId: toolCall.id
|
|
2205
|
+
});
|
|
2206
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, {
|
|
2207
|
+
success: false,
|
|
2208
|
+
error: `PERMANENT FAILURE after ${MAX_RETRIES} retries: ${toolError.message}`
|
|
2070
2209
|
});
|
|
2071
2210
|
|
|
2072
2211
|
this.messages.push({
|
|
@@ -2104,6 +2243,11 @@ export class AgentLoop {
|
|
|
2104
2243
|
};
|
|
2105
2244
|
}
|
|
2106
2245
|
|
|
2246
|
+
// The journal is the observer's own record of what actually ran. It
|
|
2247
|
+
// is written only after post-hook review, so a formatter that rejects
|
|
2248
|
+
// a write is remembered as a failure rather than a success.
|
|
2249
|
+
coldObserver.recordToolOutcome(this.taskId, functionName, args, result);
|
|
2250
|
+
|
|
2107
2251
|
// PROGRESSIVE DISCLOSURE: honour unlock signals from tool_search.
|
|
2108
2252
|
// The control fields are stripped before the result reaches the LLM.
|
|
2109
2253
|
if (result && (result._unlock_tools || result._unlock_packs)) {
|
|
@@ -2121,7 +2265,7 @@ export class AgentLoop {
|
|
|
2121
2265
|
// Buffer output for disconnect resilience
|
|
2122
2266
|
await this.taskBuffer.appendOutput(this.taskId, { tool: functionName, result });
|
|
2123
2267
|
|
|
2124
|
-
this.emitEvent({ type: 'step_complete', tool: functionName, result: result._is_image_marker ? '[IMAGE DATA]' : result });
|
|
2268
|
+
this.emitEvent({ type: 'step_complete', tool: functionName, result: result._is_image_marker ? '[IMAGE DATA]' : result, toolCallId: toolCall.id });
|
|
2125
2269
|
this.stepsCompleted++;
|
|
2126
2270
|
|
|
2127
2271
|
// The procedure, as it actually ran. Tool name plus a whitelisted
|
package/src/approvalGrants.js
CHANGED
|
@@ -46,3 +46,36 @@ export function revokeAllAlways() {
|
|
|
46
46
|
export function revokeAlways(toolName) {
|
|
47
47
|
return standingApprovals.delete(normalizeToolName(toolName));
|
|
48
48
|
}
|
|
49
|
+
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
50
|
+
export function createApprovalScope() {
|
|
51
|
+
const approvals = new Set();
|
|
52
|
+
return {
|
|
53
|
+
grantAlways(toolName) {
|
|
54
|
+
const name = normalizeToolName(toolName);
|
|
55
|
+
if (name)
|
|
56
|
+
approvals.add(name);
|
|
57
|
+
},
|
|
58
|
+
isAlwaysAllowed(toolName) {
|
|
59
|
+
return approvals.has(normalizeToolName(toolName));
|
|
60
|
+
},
|
|
61
|
+
listAlwaysAllowed() {
|
|
62
|
+
return [...approvals].sort();
|
|
63
|
+
},
|
|
64
|
+
revokeAllAlways() {
|
|
65
|
+
const count = approvals.size;
|
|
66
|
+
approvals.clear();
|
|
67
|
+
return count;
|
|
68
|
+
},
|
|
69
|
+
revokeAlways(toolName) {
|
|
70
|
+
return approvals.delete(normalizeToolName(toolName));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The process-wide scope, for callers that do not create their own. */
|
|
75
|
+
export const processApprovalScope = {
|
|
76
|
+
grantAlways,
|
|
77
|
+
isAlwaysAllowed,
|
|
78
|
+
listAlwaysAllowed,
|
|
79
|
+
revokeAllAlways,
|
|
80
|
+
revokeAlways
|
|
81
|
+
};
|
package/src/approvalGrants.ts
CHANGED
|
@@ -18,6 +18,22 @@
|
|
|
18
18
|
// should be an explicit, listed, revocable config entry — not a quiet
|
|
19
19
|
// side-effect of a keypress in a modal.
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* One set of standing approvals, isolated from every other scope.
|
|
23
|
+
*
|
|
24
|
+
* The process-wide scope below is what a terminal session uses. A server-owned
|
|
25
|
+
* conversation (ACP) gets its own scope instead, so "allow always" in one
|
|
26
|
+
* conversation can never leak into another one — and never into a fork, which
|
|
27
|
+
* starts with a scope that has never been granted anything.
|
|
28
|
+
*/
|
|
29
|
+
export interface ApprovalScope {
|
|
30
|
+
grantAlways(toolName: unknown): void;
|
|
31
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
32
|
+
listAlwaysAllowed(): string[];
|
|
33
|
+
revokeAllAlways(): number;
|
|
34
|
+
revokeAlways(toolName: unknown): boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
/** Tool names approved for the rest of this process. Deliberately in memory. */
|
|
22
38
|
const standingApprovals = new Set<string>();
|
|
23
39
|
|
|
@@ -52,3 +68,37 @@ export function revokeAllAlways(): number {
|
|
|
52
68
|
export function revokeAlways(toolName: unknown): boolean {
|
|
53
69
|
return standingApprovals.delete(normalizeToolName(toolName));
|
|
54
70
|
}
|
|
71
|
+
|
|
72
|
+
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
73
|
+
export function createApprovalScope(): ApprovalScope {
|
|
74
|
+
const approvals = new Set<string>();
|
|
75
|
+
return {
|
|
76
|
+
grantAlways(toolName) {
|
|
77
|
+
const name = normalizeToolName(toolName);
|
|
78
|
+
if (name) approvals.add(name);
|
|
79
|
+
},
|
|
80
|
+
isAlwaysAllowed(toolName) {
|
|
81
|
+
return approvals.has(normalizeToolName(toolName));
|
|
82
|
+
},
|
|
83
|
+
listAlwaysAllowed() {
|
|
84
|
+
return [...approvals].sort();
|
|
85
|
+
},
|
|
86
|
+
revokeAllAlways() {
|
|
87
|
+
const count = approvals.size;
|
|
88
|
+
approvals.clear();
|
|
89
|
+
return count;
|
|
90
|
+
},
|
|
91
|
+
revokeAlways(toolName) {
|
|
92
|
+
return approvals.delete(normalizeToolName(toolName));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The process-wide scope, for callers that do not create their own. */
|
|
98
|
+
export const processApprovalScope: ApprovalScope = {
|
|
99
|
+
grantAlways,
|
|
100
|
+
isAlwaysAllowed,
|
|
101
|
+
listAlwaysAllowed,
|
|
102
|
+
revokeAllAlways,
|
|
103
|
+
revokeAlways
|
|
104
|
+
};
|