ft-scout 9.5.5 → 9.5.7
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 +1 -1
- package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
- package/bin/src/engine/agent/computerUseLoop.js +413 -0
- package/bin/src/engine/agent/index.d.ts +2 -0
- package/bin/src/engine/agent/index.js +2 -0
- package/bin/src/engine/agent/recovery/index.d.ts +4 -0
- package/bin/src/engine/agent/recovery/index.js +4 -0
- package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
- package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
- package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
- package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
- package/bin/src/engine/agent/recovery/types.d.ts +48 -0
- package/bin/src/engine/agent/recovery/types.js +4 -0
- package/bin/src/engine/agent/verification/index.d.ts +3 -0
- package/bin/src/engine/agent/verification/index.js +3 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
- package/bin/src/engine/agent/verification/types.d.ts +28 -0
- package/bin/src/engine/agent/verification/types.js +4 -0
- package/bin/src/engine/agentEngine.d.ts +3 -1
- package/bin/src/engine/agentEngine.js +370 -56
- package/bin/src/engine/agentState.d.ts +41 -1
- package/bin/src/engine/agentState.js +45 -0
- package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
- package/bin/src/engine/browser/actions/actionEngine.js +707 -0
- package/bin/src/engine/browser/actions/index.d.ts +4 -0
- package/bin/src/engine/browser/actions/index.js +4 -0
- package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
- package/bin/src/engine/browser/actions/reliability.js +170 -0
- package/bin/src/engine/browser/actions/types.d.ts +50 -0
- package/bin/src/engine/browser/actions/types.js +2 -0
- package/bin/src/engine/browser/browserController.d.ts +18 -0
- package/bin/src/engine/browser/browserController.js +44 -12
- package/bin/src/engine/browser/index.d.ts +2 -0
- package/bin/src/engine/browser/index.js +2 -0
- package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
- package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
- package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
- package/bin/src/engine/browser/observer/browserObserver.js +204 -0
- package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
- package/bin/src/engine/browser/observer/domExtractor.js +407 -0
- package/bin/src/engine/browser/observer/index.d.ts +5 -0
- package/bin/src/engine/browser/observer/index.js +5 -0
- package/bin/src/engine/browser/observer/types.d.ts +163 -0
- package/bin/src/engine/browser/observer/types.js +8 -0
- package/bin/src/engine/computer/computerController.d.ts +45 -2
- package/bin/src/engine/computer/computerController.js +178 -38
- package/bin/src/engine/computer/mockComputer.d.ts +7 -2
- package/bin/src/engine/computer/mockComputer.js +59 -1
- package/bin/src/engine/computer/scoutDriver.cs +310 -63
- package/bin/src/engine/llm.js +35 -15
- package/bin/src/engine/models/harpProvider.d.ts +32 -0
- package/bin/src/engine/models/harpProvider.js +172 -0
- package/bin/src/engine/models/index.d.ts +6 -0
- package/bin/src/engine/models/index.js +6 -0
- package/bin/src/engine/models/localModelProvider.d.ts +11 -0
- package/bin/src/engine/models/localModelProvider.js +48 -0
- package/bin/src/engine/models/openaiProvider.d.ts +11 -0
- package/bin/src/engine/models/openaiProvider.js +50 -0
- package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
- package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
- package/bin/src/engine/models/types.d.ts +63 -0
- package/bin/src/engine/models/types.js +2 -0
- package/bin/src/engine/production/index.d.ts +3 -0
- package/bin/src/engine/production/index.js +3 -0
- package/bin/src/engine/production/taskReplay.d.ts +37 -0
- package/bin/src/engine/production/taskReplay.js +81 -0
- package/bin/src/engine/production/telemetry.d.ts +43 -0
- package/bin/src/engine/production/telemetry.js +68 -0
- package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
- package/bin/src/engine/runtime/agentRuntime.js +33 -7
- package/bin/src/engine/safety/index.d.ts +3 -0
- package/bin/src/engine/safety/index.js +3 -0
- package/bin/src/engine/safety/policyEngine.d.ts +40 -0
- package/bin/src/engine/safety/policyEngine.js +282 -0
- package/bin/src/engine/safety/types.d.ts +24 -0
- package/bin/src/engine/safety/types.js +2 -0
- package/bin/src/engine/safety.d.ts +1 -0
- package/bin/src/engine/safety.js +1 -0
- package/bin/src/engine/toolRegistry.d.ts +4 -0
- package/bin/src/engine/toolRegistry.js +9 -0
- package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
- package/bin/src/engine/tools/domainHandlers.js +495 -0
- package/bin/src/engine/tools/index.d.ts +4 -0
- package/bin/src/engine/tools/index.js +4 -0
- package/bin/src/engine/tools/types.d.ts +56 -0
- package/bin/src/engine/tools/types.js +2 -0
- package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
- package/bin/src/engine/tools/unifiedRouter.js +426 -0
- package/bin/src/engine/workspace/agentWorkspace.js +4 -2
- package/bin/src/index.js +4 -4
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/server/server.js +57 -18
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/claudeUI.d.ts +10 -1
- package/bin/src/utils/claudeUI.js +136 -6
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/support.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class TelemetryTracker {
|
|
2
|
+
events = [];
|
|
3
|
+
limits;
|
|
4
|
+
constructor(customLimits) {
|
|
5
|
+
this.limits = {
|
|
6
|
+
maxSteps: customLimits?.maxSteps ?? 50,
|
|
7
|
+
maxDurationMs: customLimits?.maxDurationMs ?? 300000, // 5 minutes default
|
|
8
|
+
maxTokenBudget: customLimits?.maxTokenBudget ?? 100000,
|
|
9
|
+
maxRetriesPerStep: customLimits?.maxRetriesPerStep ?? 3,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
recordEvent(event) {
|
|
13
|
+
const fullEvent = {
|
|
14
|
+
...event,
|
|
15
|
+
timestamp: new Date().toISOString(),
|
|
16
|
+
};
|
|
17
|
+
this.events.push(fullEvent);
|
|
18
|
+
return fullEvent;
|
|
19
|
+
}
|
|
20
|
+
getEvents(taskId) {
|
|
21
|
+
if (!taskId)
|
|
22
|
+
return [...this.events];
|
|
23
|
+
return this.events.filter(e => e.taskId === taskId);
|
|
24
|
+
}
|
|
25
|
+
checkResourceLimits(taskId, currentStep, startTimeMs, totalTokensUsed = 0) {
|
|
26
|
+
if (currentStep > this.limits.maxSteps) {
|
|
27
|
+
return { exceeded: true, reason: `Exceeded maximum step budget (${currentStep}/${this.limits.maxSteps})` };
|
|
28
|
+
}
|
|
29
|
+
const elapsedMs = Date.now() - startTimeMs;
|
|
30
|
+
if (elapsedMs > this.limits.maxDurationMs) {
|
|
31
|
+
return { exceeded: true, reason: `Exceeded task timeout limit (${elapsedMs}ms > ${this.limits.maxDurationMs}ms)` };
|
|
32
|
+
}
|
|
33
|
+
if (this.limits.maxTokenBudget && totalTokensUsed > this.limits.maxTokenBudget) {
|
|
34
|
+
return { exceeded: true, reason: `Exceeded token budget (${totalTokensUsed}/${this.limits.maxTokenBudget})` };
|
|
35
|
+
}
|
|
36
|
+
return { exceeded: false };
|
|
37
|
+
}
|
|
38
|
+
getLatencySummary(taskId) {
|
|
39
|
+
const targetEvents = this.getEvents(taskId);
|
|
40
|
+
const modelEvents = targetEvents.filter(e => e.eventType === 'model_call');
|
|
41
|
+
const toolEvents = targetEvents.filter(e => e.eventType === 'tool_execution');
|
|
42
|
+
const avgModelLatency = modelEvents.length > 0
|
|
43
|
+
? modelEvents.reduce((acc, e) => acc + e.latencyMs, 0) / modelEvents.length
|
|
44
|
+
: 0;
|
|
45
|
+
const avgToolLatency = toolEvents.length > 0
|
|
46
|
+
? toolEvents.reduce((acc, e) => acc + e.latencyMs, 0) / toolEvents.length
|
|
47
|
+
: 0;
|
|
48
|
+
const totalTokens = targetEvents.reduce((acc, e) => acc + (e.tokensUsed || 0), 0);
|
|
49
|
+
const errorCount = targetEvents.filter(e => !e.success || Boolean(e.error)).length;
|
|
50
|
+
return {
|
|
51
|
+
totalEvents: targetEvents.length,
|
|
52
|
+
avgModelLatencyMs: Math.round(avgModelLatency),
|
|
53
|
+
avgToolLatencyMs: Math.round(avgToolLatency),
|
|
54
|
+
totalTokens,
|
|
55
|
+
errorCount,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
generateFailureTrace(taskId) {
|
|
59
|
+
const errors = this.getEvents(taskId).filter(e => !e.success || Boolean(e.error));
|
|
60
|
+
if (errors.length === 0)
|
|
61
|
+
return 'No failures recorded for task ' + taskId;
|
|
62
|
+
return errors.map(e => `[Step ${e.stepIndex}][${e.eventType}][${e.tool || e.model || 'system'}]: ${e.error || 'Execution failed'} (latency: ${e.latencyMs}ms)`).join('\n');
|
|
63
|
+
}
|
|
64
|
+
clear() {
|
|
65
|
+
this.events = [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -72,7 +72,7 @@ export declare class AgentRuntime {
|
|
|
72
72
|
modifiedFilesCount: number;
|
|
73
73
|
elapsedMs: number;
|
|
74
74
|
taskId: string;
|
|
75
|
-
status: "cancelled" | "completed" | "executing" | "failed" | "paused" | "planning" | "recovering" | "running" | "waiting_approval";
|
|
75
|
+
status: "cancelled" | "completed" | "executing" | "failed" | "paused" | "planning" | "recovering" | "running" | "timeout" | "waiting_approval";
|
|
76
76
|
};
|
|
77
77
|
resetContext(): void;
|
|
78
78
|
private buildSystemPrompt;
|
|
@@ -20,7 +20,7 @@ import { robustSnippetReplace, buildDirectoryTree } from '../agentEngine.js';
|
|
|
20
20
|
import { loadAuthConfig, isProOrHigher } from '../../utils/auth.js';
|
|
21
21
|
import { getMCPManager } from '../../mcp/index.js';
|
|
22
22
|
import { compress, LEVEL_FAST } from 'codrop';
|
|
23
|
-
import { renderStepHeader, renderThoughtBox, renderToolCall, renderToolResult, renderTaskCompletedCard, } from '../../utils/claudeUI.js';
|
|
23
|
+
import { renderStepHeader, renderThoughtBox, renderToolCall, renderToolResult, renderTaskCompletedCard, getActionFriendlyDescription, } from '../../utils/claudeUI.js';
|
|
24
24
|
import { loadWorkspaceRules } from '../../utils/rules.js';
|
|
25
25
|
import { InterruptManager } from '../../utils/interruptHandler.js';
|
|
26
26
|
export class AgentRuntime {
|
|
@@ -492,9 +492,21 @@ Action Rules:
|
|
|
492
492
|
}
|
|
493
493
|
const msg = sanitizeMessage(choice.message);
|
|
494
494
|
this.historyMessages.push(msg);
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
let fallbackDesc;
|
|
496
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
497
|
+
const firstTc = msg.tool_calls[0];
|
|
498
|
+
if (firstTc?.function?.name) {
|
|
499
|
+
let callArgs = {};
|
|
500
|
+
try {
|
|
501
|
+
callArgs = JSON.parse(firstTc.function.arguments || '{}');
|
|
502
|
+
}
|
|
503
|
+
catch { }
|
|
504
|
+
fallbackDesc = getActionFriendlyDescription(firstTc.function.name, callArgs);
|
|
505
|
+
}
|
|
497
506
|
}
|
|
507
|
+
const rawReasoning = choice.message?.reasoning_content || choice.message?.thinking || choice.message?.thought || '';
|
|
508
|
+
const combinedReasoning = rawReasoning ? `${rawReasoning}\n${msg.content || ''}` : (msg.content || '');
|
|
509
|
+
renderThoughtBox(combinedReasoning, step, fallbackDesc);
|
|
498
510
|
let toolCallsToExecute = [];
|
|
499
511
|
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
500
512
|
for (const tc of msg.tool_calls) {
|
|
@@ -1331,12 +1343,20 @@ Action Rules:
|
|
|
1331
1343
|
return { result: `Successfully wrote file "${targetPath}".` };
|
|
1332
1344
|
}
|
|
1333
1345
|
case 'edit_file': {
|
|
1334
|
-
const targetPath = String(args.path || '').trim();
|
|
1346
|
+
const targetPath = String(args.path || args.filePath || args.file || '').trim();
|
|
1347
|
+
let target = String(args.target ?? args.old_string ?? args.old_str ?? args.oldText ?? args.find ?? args.search ?? '');
|
|
1348
|
+
let replacement = String(args.replacement ?? args.new_string ?? args.new_str ?? args.newText ?? args.replace ?? '');
|
|
1349
|
+
if (replacement.includes('\\n') && !replacement.includes('\n')) {
|
|
1350
|
+
replacement = replacement.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
1351
|
+
}
|
|
1352
|
+
if (target.includes('\\n') && !target.includes('\n')) {
|
|
1353
|
+
target = target.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
1354
|
+
}
|
|
1335
1355
|
const fullPath = path.isAbsolute(targetPath) ? targetPath : path.resolve(this.cwd, targetPath);
|
|
1336
1356
|
if (!fs.existsSync(fullPath))
|
|
1337
1357
|
return { result: `Error: File "${targetPath}" does not exist.` };
|
|
1338
1358
|
const currentContent = fs.readFileSync(fullPath, 'utf-8');
|
|
1339
|
-
const replaceRes = robustSnippetReplace(currentContent,
|
|
1359
|
+
const replaceRes = robustSnippetReplace(currentContent, target, replacement);
|
|
1340
1360
|
if (!replaceRes.success) {
|
|
1341
1361
|
return { result: `Error: ${replaceRes.error}` };
|
|
1342
1362
|
}
|
|
@@ -1405,7 +1425,7 @@ Action Rules:
|
|
|
1405
1425
|
};
|
|
1406
1426
|
}
|
|
1407
1427
|
case 'multi_edit_file': {
|
|
1408
|
-
const targetPath = String(args.path || '').trim();
|
|
1428
|
+
const targetPath = String(args.path || args.filePath || args.file || '').trim();
|
|
1409
1429
|
const edits = Array.isArray(args.edits) ? args.edits : [];
|
|
1410
1430
|
const fullPath = path.isAbsolute(targetPath) ? targetPath : path.resolve(this.cwd, targetPath);
|
|
1411
1431
|
if (!fs.existsSync(fullPath))
|
|
@@ -1413,7 +1433,13 @@ Action Rules:
|
|
|
1413
1433
|
let content = fs.readFileSync(fullPath, 'utf-8');
|
|
1414
1434
|
let count = 0;
|
|
1415
1435
|
for (const ed of edits) {
|
|
1416
|
-
|
|
1436
|
+
let target = String(ed.target ?? ed.old_string ?? ed.old_str ?? ed.oldText ?? ed.find ?? ed.search ?? '');
|
|
1437
|
+
let replacement = String(ed.replacement ?? ed.new_string ?? ed.new_str ?? ed.newText ?? ed.replace ?? '');
|
|
1438
|
+
if (target.includes('\\n') && !target.includes('\n'))
|
|
1439
|
+
target = target.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
1440
|
+
if (replacement.includes('\\n') && !replacement.includes('\n'))
|
|
1441
|
+
replacement = replacement.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
1442
|
+
const res = robustSnippetReplace(content, target, replacement);
|
|
1417
1443
|
if (res.success) {
|
|
1418
1444
|
content = res.updatedContent;
|
|
1419
1445
|
count++;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type PolicyRiskLevel, type PolicyMode, type PolicyDecision, type ActionPolicyConfig } from './types.js';
|
|
2
|
+
export declare class ActionPolicyEngine {
|
|
3
|
+
private mode;
|
|
4
|
+
private autoApproveLevel1;
|
|
5
|
+
private approvalTimeoutMs;
|
|
6
|
+
private destructivePatterns;
|
|
7
|
+
private financialOrAuthKeywords;
|
|
8
|
+
constructor(config?: ActionPolicyConfig | undefined);
|
|
9
|
+
setMode(mode: PolicyMode): void;
|
|
10
|
+
getMode(): PolicyMode;
|
|
11
|
+
setAutoApproveLevel1(enabled: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Evaluates a tool action and determines its risk level, allowance, and approval requirements.
|
|
14
|
+
*/
|
|
15
|
+
evaluate(tool: string, args?: Record<string, any>, context?: Record<string, any> | undefined): PolicyDecision;
|
|
16
|
+
/**
|
|
17
|
+
* Formats the exact Just-In-Time UX prompt required by Phase 7:
|
|
18
|
+
*
|
|
19
|
+
* Scout wants to:
|
|
20
|
+
*
|
|
21
|
+
* [Action Description]
|
|
22
|
+
* "...."
|
|
23
|
+
*
|
|
24
|
+
* To:
|
|
25
|
+
* [Target]
|
|
26
|
+
*
|
|
27
|
+
* [Approve] [Reject]
|
|
28
|
+
*/
|
|
29
|
+
renderJitPrompt(decision: PolicyDecision, tool: string, args: Record<string, any>): string;
|
|
30
|
+
/**
|
|
31
|
+
* Authorizes an action immediately prior to execution (Just-in-Time).
|
|
32
|
+
*/
|
|
33
|
+
authorizeAction(tool: string, args?: Record<string, any>, context?: Record<string, any> | undefined, userApprover?: ((promptText: string) => Promise<boolean>) | undefined): Promise<{
|
|
34
|
+
authorized: boolean;
|
|
35
|
+
riskLevel: PolicyRiskLevel;
|
|
36
|
+
reason: string;
|
|
37
|
+
}>;
|
|
38
|
+
private createDecision;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=policyEngine.d.ts.map
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
export class ActionPolicyEngine {
|
|
3
|
+
mode;
|
|
4
|
+
autoApproveLevel1;
|
|
5
|
+
approvalTimeoutMs;
|
|
6
|
+
destructivePatterns = [
|
|
7
|
+
/\brm\s+-rf\b/i,
|
|
8
|
+
/\bformat\b/i,
|
|
9
|
+
/\bdrop\s+table\b/i,
|
|
10
|
+
/\bdrop\s+database\b/i,
|
|
11
|
+
/\btruncate\b/i,
|
|
12
|
+
/\bdel\s+\/f\s+\/s\s+\/q\b/i,
|
|
13
|
+
/\bRemove-Item\s+.*-Recurse\s+-Force\b/i,
|
|
14
|
+
/\bgit\s+reset\s+--hard\b/i,
|
|
15
|
+
/\bgit\s+clean\s+-fdx\b/i,
|
|
16
|
+
];
|
|
17
|
+
financialOrAuthKeywords = [
|
|
18
|
+
'password', 'secret', 'token', 'apikey', 'credential',
|
|
19
|
+
'credit_card', 'card_number', 'cvv', 'pay', 'purchase',
|
|
20
|
+
'checkout', 'transfer', 'wire', 'invoice_pay', 'buy',
|
|
21
|
+
'delete account', 'confirm purchase', 'pay now', 'buy now'
|
|
22
|
+
];
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.mode = config?.mode ?? 'balanced';
|
|
25
|
+
this.autoApproveLevel1 = config?.autoApproveLevel1 ?? (this.mode === 'permissive' || this.mode === 'balanced');
|
|
26
|
+
this.approvalTimeoutMs = config?.approvalTimeoutMs ?? 30000;
|
|
27
|
+
}
|
|
28
|
+
setMode(mode) {
|
|
29
|
+
this.mode = mode;
|
|
30
|
+
if (mode === 'permissive') {
|
|
31
|
+
this.autoApproveLevel1 = true;
|
|
32
|
+
}
|
|
33
|
+
else if (mode === 'strict' || mode === 'readonly') {
|
|
34
|
+
this.autoApproveLevel1 = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getMode() {
|
|
38
|
+
return this.mode;
|
|
39
|
+
}
|
|
40
|
+
setAutoApproveLevel1(enabled) {
|
|
41
|
+
this.autoApproveLevel1 = enabled;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Evaluates a tool action and determines its risk level, allowance, and approval requirements.
|
|
45
|
+
*/
|
|
46
|
+
evaluate(tool, args = {}, context) {
|
|
47
|
+
const toolLower = (tool || '').toLowerCase().trim();
|
|
48
|
+
// ---------------------------------------------------------------------
|
|
49
|
+
// 1. LEVEL 3: High-Impact Operations
|
|
50
|
+
// Purchases, financial actions, account/security changes, irreversible deletion
|
|
51
|
+
// ---------------------------------------------------------------------
|
|
52
|
+
// Irreversible deletion commands
|
|
53
|
+
if (toolLower === 'run_command') {
|
|
54
|
+
const cmd = String(args.command || args.cmd || '');
|
|
55
|
+
for (const pattern of this.destructivePatterns) {
|
|
56
|
+
if (pattern.test(cmd)) {
|
|
57
|
+
return this.createDecision(3, 'LEVEL_3_HIGH_IMPACT', false, true, `Destructive command with potential irreversible data loss: "${cmd}"`, {
|
|
58
|
+
actionTitle: 'Execute Destructive Command',
|
|
59
|
+
actionDescription: cmd,
|
|
60
|
+
target: args.cwd || 'workspace disk',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Credential and secret file modifications
|
|
66
|
+
if (toolLower === 'write_file' || toolLower === 'edit_file' || toolLower === 'multi_edit_file') {
|
|
67
|
+
const p = String(args.path || args.filePath || '').toLowerCase();
|
|
68
|
+
if (p.includes('.env') || p.includes('id_rsa') || p.includes('credentials') || p.includes('secret') || p.includes('auth.json')) {
|
|
69
|
+
return this.createDecision(3, 'LEVEL_3_HIGH_IMPACT', false, true, `Modification of sensitive credential or security file: "${args.path}"`, {
|
|
70
|
+
actionTitle: 'Modify Security File',
|
|
71
|
+
actionDescription: `Writing changes to ${args.path}`,
|
|
72
|
+
target: args.path,
|
|
73
|
+
payloadPreview: typeof args.content === 'string' ? args.content.slice(0, 100) : undefined,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Financial or account deletion actions via browser or desktop
|
|
78
|
+
if (toolLower === 'browser_click' || toolLower === 'computer_click' || toolLower === 'computer') {
|
|
79
|
+
const targetDesc = String(args.selectorOrText || args.target || args.ref || args.element || '').toLowerCase();
|
|
80
|
+
for (const kw of this.financialOrAuthKeywords) {
|
|
81
|
+
if (targetDesc.includes(kw)) {
|
|
82
|
+
return this.createDecision(3, 'LEVEL_3_HIGH_IMPACT', false, true, `Financial or account action involving: "${targetDesc}"`, {
|
|
83
|
+
actionTitle: 'Authorize High-Impact Action',
|
|
84
|
+
actionDescription: `Clicking sensitive control "${targetDesc}"`,
|
|
85
|
+
target: context?.activeUrl || context?.activeWindow || 'Desktop UI',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Sensitive typing (passwords, tokens, financial inputs)
|
|
91
|
+
if (toolLower === 'browser_type' || toolLower === 'computer_type' || (toolLower === 'computer' && args.action === 'type')) {
|
|
92
|
+
const typedText = String(args.text || '').toLowerCase();
|
|
93
|
+
for (const kw of this.financialOrAuthKeywords) {
|
|
94
|
+
if (typedText.includes(kw)) {
|
|
95
|
+
return this.createDecision(3, 'LEVEL_3_HIGH_IMPACT', false, true, `Typing sensitive credentials or payment token`, {
|
|
96
|
+
actionTitle: 'Input Sensitive Data',
|
|
97
|
+
actionDescription: 'Typing sensitive credentials or payment tokens into UI input',
|
|
98
|
+
target: args.selectorOrText || context?.activeWindow || 'active window',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// ---------------------------------------------------------------------
|
|
104
|
+
// 2. LEVEL 2: External Side Effects
|
|
105
|
+
// Sending messages, submitting forms, publishing, deleting non-critical data, launching apps
|
|
106
|
+
// ---------------------------------------------------------------------
|
|
107
|
+
if (toolLower === 'run_command') {
|
|
108
|
+
const cmd = String(args.command || args.cmd || '');
|
|
109
|
+
if (/\bgit\s+push\b/i.test(cmd) || /\bnpm\s+publish\b/i.test(cmd) || /\bdeploy\b/i.test(cmd) || /\bcurl\s+-X\s+(POST|DELETE|PUT)\b/i.test(cmd)) {
|
|
110
|
+
return this.createDecision(2, 'LEVEL_2_SIDE_EFFECTS', false, true, `External publication or remote repository push: "${cmd}"`, {
|
|
111
|
+
actionTitle: 'Push or Publish to Remote',
|
|
112
|
+
actionDescription: cmd,
|
|
113
|
+
target: 'remote server / repository',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (toolLower === 'git_pr') {
|
|
118
|
+
return this.createDecision(2, 'LEVEL_2_SIDE_EFFECTS', false, true, `Creating external pull request on remote repository`, {
|
|
119
|
+
actionTitle: 'Create Pull Request',
|
|
120
|
+
actionDescription: `Create PR: "${args.title || 'Automated PR'}"`,
|
|
121
|
+
target: 'remote Git origin',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (toolLower === 'browser_click') {
|
|
125
|
+
const targetDesc = String(args.selectorOrText || args.target || '').toLowerCase();
|
|
126
|
+
if (targetDesc.includes('submit') || targetDesc.includes('send') || targetDesc.includes('publish') || targetDesc.includes('post') || targetDesc.includes('order')) {
|
|
127
|
+
return this.createDecision(2, 'LEVEL_2_SIDE_EFFECTS', false, true, `External web side effect: clicking "${targetDesc}"`, {
|
|
128
|
+
actionTitle: 'Submit Web Form / Send Message',
|
|
129
|
+
actionDescription: `Clicking button: "${args.selectorOrText || args.target}"`,
|
|
130
|
+
target: context?.activeUrl || 'active web page',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (toolLower === 'browser_upload') {
|
|
135
|
+
return this.createDecision(2, 'LEVEL_2_SIDE_EFFECTS', false, true, `Uploading local file to external web service: "${args.filePath}"`, {
|
|
136
|
+
actionTitle: 'Upload Local File',
|
|
137
|
+
actionDescription: `Upload file ${args.filePath}`,
|
|
138
|
+
target: context?.activeUrl || 'external server',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (toolLower === 'computer_open_app' || toolLower === 'computer_close_app' || (toolLower === 'computer' && (args.action === 'open_app' || args.action === 'close_app'))) {
|
|
142
|
+
const app = args.appName || args.app || args.windowTitleOrApp || 'desktop application';
|
|
143
|
+
return this.createDecision(2, 'LEVEL_2_SIDE_EFFECTS', false, true, `Desktop process control: ${args.action || toolLower} for "${app}"`, {
|
|
144
|
+
actionTitle: 'Launch or Terminate Desktop Application',
|
|
145
|
+
actionDescription: `${toolLower === 'computer_close_app' || args.action === 'close_app' ? 'Closing' : 'Launching'} ${app}`,
|
|
146
|
+
target: String(app),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// ---------------------------------------------------------------------
|
|
150
|
+
// 3. LEVEL 1: Reversible Modifications
|
|
151
|
+
// Editing workspace files, changing code, installing dev dependencies, git commit/branch
|
|
152
|
+
// ---------------------------------------------------------------------
|
|
153
|
+
if (toolLower === 'write_file' || toolLower === 'edit_file' || toolLower === 'multi_edit_file') {
|
|
154
|
+
const allows = this.mode !== 'readonly' && this.autoApproveLevel1;
|
|
155
|
+
return this.createDecision(1, 'LEVEL_1_REVERSIBLE', allows, !allows, `Reversible workspace file modification: "${args.path}"`, {
|
|
156
|
+
actionTitle: 'Edit Workspace File',
|
|
157
|
+
actionDescription: `Updating ${args.path}`,
|
|
158
|
+
target: args.path,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (toolLower === 'git_commit' || toolLower === 'git_branch') {
|
|
162
|
+
const allows = this.mode !== 'readonly' && this.autoApproveLevel1;
|
|
163
|
+
return this.createDecision(1, 'LEVEL_1_REVERSIBLE', allows, !allows, `Local git change: ${toolLower}`, {
|
|
164
|
+
actionTitle: 'Local Git Commit or Branch',
|
|
165
|
+
actionDescription: `Executing ${toolLower}`,
|
|
166
|
+
target: 'local git workspace',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (toolLower === 'run_command') {
|
|
170
|
+
const cmd = String(args.command || args.cmd || '');
|
|
171
|
+
const allows = this.mode !== 'readonly' && (this.autoApproveLevel1 || /\b(?:npm\s+test|vitest|jest|mocha|echo|pwd|dir|ls)\b/i.test(cmd));
|
|
172
|
+
return this.createDecision(1, 'LEVEL_1_REVERSIBLE', allows, !allows, `Executing local shell command: "${cmd.slice(0, 50)}"`, {
|
|
173
|
+
actionTitle: 'Run Shell Command',
|
|
174
|
+
actionDescription: cmd,
|
|
175
|
+
target: args.cwd || 'local terminal',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (toolLower === 'computer_click' ||
|
|
179
|
+
toolLower === 'computer_type' ||
|
|
180
|
+
toolLower === 'computer_key_press' ||
|
|
181
|
+
toolLower === 'computer_hotkey' ||
|
|
182
|
+
toolLower === 'computer_drag' ||
|
|
183
|
+
toolLower === 'computer_switch_window' ||
|
|
184
|
+
toolLower === 'computer_switch_to_app' ||
|
|
185
|
+
(toolLower === 'computer' && ['click', 'type', 'key_press', 'hotkey', 'drag', 'switch_window'].includes(args.action))) {
|
|
186
|
+
const allows = this.mode !== 'readonly' && this.autoApproveLevel1;
|
|
187
|
+
return this.createDecision(1, 'LEVEL_1_REVERSIBLE', allows, !allows, `Operating desktop application UI controls`, {
|
|
188
|
+
actionTitle: 'Desktop UI Interaction',
|
|
189
|
+
actionDescription: `Executing ${toolLower} with action ${args.action || 'input'}`,
|
|
190
|
+
target: context?.activeWindow || 'desktop',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (toolLower === 'browser_type' || toolLower === 'browser_click' || toolLower === 'browser_select' || toolLower === 'browser_scroll' || toolLower === 'browser_hover') {
|
|
194
|
+
const allows = this.mode !== 'readonly' && this.autoApproveLevel1;
|
|
195
|
+
return this.createDecision(1, 'LEVEL_1_REVERSIBLE', allows, !allows, `Standard web interaction: ${toolLower}`, {
|
|
196
|
+
actionTitle: 'Web Interaction',
|
|
197
|
+
actionDescription: `Interacting with web element`,
|
|
198
|
+
target: context?.activeUrl || 'browser',
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
// ---------------------------------------------------------------------
|
|
202
|
+
// 4. LEVEL 0: Read-Only Operations
|
|
203
|
+
// Browsing, searching, inspecting code, reading logs, screenshots
|
|
204
|
+
// Automatically allowed across all modes except if completely blocked
|
|
205
|
+
// ---------------------------------------------------------------------
|
|
206
|
+
return this.createDecision(0, 'LEVEL_0_READ_ONLY', true, false, `Read-only inspection operation: ${toolLower}`, {
|
|
207
|
+
actionTitle: 'Read-Only Inspection',
|
|
208
|
+
actionDescription: `Inspecting ${toolLower}`,
|
|
209
|
+
target: args.path || args.url || context?.activeUrl || 'workspace',
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Formats the exact Just-In-Time UX prompt required by Phase 7:
|
|
214
|
+
*
|
|
215
|
+
* Scout wants to:
|
|
216
|
+
*
|
|
217
|
+
* [Action Description]
|
|
218
|
+
* "...."
|
|
219
|
+
*
|
|
220
|
+
* To:
|
|
221
|
+
* [Target]
|
|
222
|
+
*
|
|
223
|
+
* [Approve] [Reject]
|
|
224
|
+
*/
|
|
225
|
+
renderJitPrompt(decision, tool, args) {
|
|
226
|
+
const details = decision.promptDetails;
|
|
227
|
+
const actionDesc = details?.actionDescription || `Execute ${tool}`;
|
|
228
|
+
const target = details?.target || 'target system';
|
|
229
|
+
const payload = details?.payloadPreview ? `\n"${details.payloadPreview}"\n` : '';
|
|
230
|
+
return [
|
|
231
|
+
`Scout wants to:`,
|
|
232
|
+
``,
|
|
233
|
+
`${actionDesc}${payload ? '\n' + payload : ''}`,
|
|
234
|
+
``,
|
|
235
|
+
`To:`,
|
|
236
|
+
`${target}`,
|
|
237
|
+
``,
|
|
238
|
+
`[Approve] [Reject]`,
|
|
239
|
+
].join('\n');
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Authorizes an action immediately prior to execution (Just-in-Time).
|
|
243
|
+
*/
|
|
244
|
+
async authorizeAction(tool, args = {}, context, userApprover) {
|
|
245
|
+
const decision = this.evaluate(tool, args, context);
|
|
246
|
+
// Level 0: Auto-approved
|
|
247
|
+
if (decision.riskLevel === 0) {
|
|
248
|
+
return { authorized: true, riskLevel: 0, reason: decision.reason };
|
|
249
|
+
}
|
|
250
|
+
// Level 1: Approved if autoApproveLevel1 is enabled
|
|
251
|
+
if (decision.riskLevel === 1 && decision.allowed && !decision.requiresApproval) {
|
|
252
|
+
return { authorized: true, riskLevel: 1, reason: decision.reason };
|
|
253
|
+
}
|
|
254
|
+
// Level 2 & 3 (or Level 1 in strict mode): Require immediate Just-in-Time approval
|
|
255
|
+
const promptText = this.renderJitPrompt(decision, tool, args);
|
|
256
|
+
if (userApprover) {
|
|
257
|
+
const approved = await userApprover(promptText);
|
|
258
|
+
return {
|
|
259
|
+
authorized: approved,
|
|
260
|
+
riskLevel: decision.riskLevel,
|
|
261
|
+
reason: approved ? 'Authorized by user decision.' : 'Denied by user.',
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
// In headless or test environments where no approver is injected
|
|
265
|
+
return {
|
|
266
|
+
authorized: false,
|
|
267
|
+
riskLevel: decision.riskLevel,
|
|
268
|
+
reason: `Action requires user confirmation (Risk Level ${decision.riskLevel}). No interactive approver provided.`,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
createDecision(riskLevel, riskName, allowed, requiresApproval, reason, promptDetails) {
|
|
272
|
+
return {
|
|
273
|
+
allowed,
|
|
274
|
+
requiresApproval,
|
|
275
|
+
riskLevel,
|
|
276
|
+
riskName,
|
|
277
|
+
reason,
|
|
278
|
+
promptDetails,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=policyEngine.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type PolicyRiskLevel = 0 | 1 | 2 | 3;
|
|
2
|
+
export type RiskLevelName = 'LEVEL_0_READ_ONLY' | 'LEVEL_1_REVERSIBLE' | 'LEVEL_2_SIDE_EFFECTS' | 'LEVEL_3_HIGH_IMPACT';
|
|
3
|
+
export type PolicyMode = 'permissive' | 'balanced' | 'strict' | 'readonly';
|
|
4
|
+
export interface ActionPromptDetails {
|
|
5
|
+
actionTitle: string;
|
|
6
|
+
actionDescription: string;
|
|
7
|
+
target?: string | undefined;
|
|
8
|
+
payloadPreview?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface PolicyDecision {
|
|
11
|
+
allowed: boolean;
|
|
12
|
+
requiresApproval: boolean;
|
|
13
|
+
riskLevel: PolicyRiskLevel;
|
|
14
|
+
riskName: RiskLevelName;
|
|
15
|
+
reason: string;
|
|
16
|
+
promptDetails?: ActionPromptDetails | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface ActionPolicyConfig {
|
|
19
|
+
mode?: PolicyMode | undefined;
|
|
20
|
+
autoApproveLevel1?: boolean | undefined;
|
|
21
|
+
allowedDomains?: string[] | undefined;
|
|
22
|
+
approvalTimeoutMs?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
package/bin/src/engine/safety.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ToolDefinition } from './agentEngine.js';
|
|
2
|
+
import { UnifiedToolRouter, type RouteIntent, type ToolRouterContext } from './tools/index.js';
|
|
2
3
|
export interface ToolSelectionStrategyResult {
|
|
3
4
|
selectedTool: string;
|
|
4
5
|
level: 'api' | 'dom' | 'computer';
|
|
@@ -9,6 +10,7 @@ export declare const COMPUTER_USE_TOOLS: ToolDefinition[];
|
|
|
9
10
|
export declare const SCRATCHPAD_TOOLS: ToolDefinition[];
|
|
10
11
|
export declare class UnifiedToolRegistry {
|
|
11
12
|
private toolsMap;
|
|
13
|
+
private router;
|
|
12
14
|
constructor();
|
|
13
15
|
getTool(name: string): ToolDefinition | undefined;
|
|
14
16
|
getAllTools(): ToolDefinition[];
|
|
@@ -34,5 +36,7 @@ export declare class UnifiedToolRegistry {
|
|
|
34
36
|
hasDesktopApp?: boolean;
|
|
35
37
|
[key: string]: any;
|
|
36
38
|
}): string;
|
|
39
|
+
getRouter(): UnifiedToolRouter;
|
|
40
|
+
routeIntent(goal: string, context?: ToolRouterContext): RouteIntent;
|
|
37
41
|
}
|
|
38
42
|
//# sourceMappingURL=toolRegistry.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AGENT_TOOLS } from './agentEngine.js';
|
|
2
|
+
import { UnifiedToolRouter } from './tools/index.js';
|
|
2
3
|
export const BROWSER_AUTOMATION_TOOLS = [
|
|
3
4
|
{
|
|
4
5
|
name: 'browser_navigate',
|
|
@@ -390,7 +391,9 @@ export const SCRATCHPAD_TOOLS = [
|
|
|
390
391
|
];
|
|
391
392
|
export class UnifiedToolRegistry {
|
|
392
393
|
toolsMap = new Map();
|
|
394
|
+
router;
|
|
393
395
|
constructor() {
|
|
396
|
+
this.router = new UnifiedToolRouter();
|
|
394
397
|
// Register all baseline tools (15 tools)
|
|
395
398
|
for (const tool of AGENT_TOOLS) {
|
|
396
399
|
this.toolsMap.set(tool.name, tool);
|
|
@@ -518,5 +521,11 @@ export class UnifiedToolRegistry {
|
|
|
518
521
|
}
|
|
519
522
|
return 'run_command';
|
|
520
523
|
}
|
|
524
|
+
getRouter() {
|
|
525
|
+
return this.router;
|
|
526
|
+
}
|
|
527
|
+
routeIntent(goal, context) {
|
|
528
|
+
return this.router.route(goal, context);
|
|
529
|
+
}
|
|
521
530
|
}
|
|
522
531
|
//# sourceMappingURL=toolRegistry.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type IToolHandler, type ToolDomain, type ToolRouterContext } from './types.js';
|
|
2
|
+
import { type IBrowserActionEngine } from '../browser/actions/types.js';
|
|
3
|
+
import { type BrowserObserver } from '../browser/observer/browserObserver.js';
|
|
4
|
+
import { type IComputerController } from '../computer/computerController.js';
|
|
5
|
+
export declare class BrowserHandler implements IToolHandler {
|
|
6
|
+
readonly domain: ToolDomain;
|
|
7
|
+
readonly supportedTools: string[];
|
|
8
|
+
private actionEngine?;
|
|
9
|
+
private observer?;
|
|
10
|
+
constructor(actionEngine?: IBrowserActionEngine | undefined, observer?: BrowserObserver | undefined);
|
|
11
|
+
canHandle(toolName: string): boolean;
|
|
12
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ComputerHandler implements IToolHandler {
|
|
15
|
+
readonly domain: ToolDomain;
|
|
16
|
+
readonly supportedTools: string[];
|
|
17
|
+
private computerController?;
|
|
18
|
+
constructor(computerController?: IComputerController | undefined);
|
|
19
|
+
canHandle(toolName: string): boolean;
|
|
20
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
export type CommandExecutor = (command: string, cwd?: string | undefined) => Promise<{
|
|
23
|
+
stdout: string;
|
|
24
|
+
stderr: string;
|
|
25
|
+
exitCode: number;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class TerminalHandler implements IToolHandler {
|
|
28
|
+
readonly domain: ToolDomain;
|
|
29
|
+
readonly supportedTools: string[];
|
|
30
|
+
private customExecutor?;
|
|
31
|
+
constructor(customExecutor?: CommandExecutor | undefined);
|
|
32
|
+
canHandle(toolName: string): boolean;
|
|
33
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
34
|
+
}
|
|
35
|
+
export declare class FilesystemHandler implements IToolHandler {
|
|
36
|
+
readonly domain: ToolDomain;
|
|
37
|
+
readonly supportedTools: string[];
|
|
38
|
+
canHandle(toolName: string): boolean;
|
|
39
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
40
|
+
}
|
|
41
|
+
export declare class GitHandler implements IToolHandler {
|
|
42
|
+
readonly domain: ToolDomain;
|
|
43
|
+
readonly supportedTools: string[];
|
|
44
|
+
private customGitRunner?;
|
|
45
|
+
constructor(customGitRunner?: ((cmd: string, args?: string[]) => Promise<any>) | undefined);
|
|
46
|
+
canHandle(toolName: string): boolean;
|
|
47
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
48
|
+
}
|
|
49
|
+
export declare class SearchHandler implements IToolHandler {
|
|
50
|
+
readonly domain: ToolDomain;
|
|
51
|
+
readonly supportedTools: string[];
|
|
52
|
+
canHandle(toolName: string): boolean;
|
|
53
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
export declare class ApiHandler implements IToolHandler {
|
|
56
|
+
readonly domain: ToolDomain;
|
|
57
|
+
readonly supportedTools: string[];
|
|
58
|
+
canHandle(toolName: string): boolean;
|
|
59
|
+
execute(toolName: string, args: Record<string, any>, context?: ToolRouterContext | undefined): Promise<any>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=domainHandlers.d.ts.map
|