ft-scout 9.5.4 → 9.5.6
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/commands/agent.d.ts +5 -0
- package/bin/src/commands/agent.js +45 -3
- package/bin/src/commands/support.d.ts +9 -0
- package/bin/src/commands/support.js +227 -0
- 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 +2 -1
- package/bin/src/engine/agentEngine.js +98 -7
- 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 +49 -0
- package/bin/src/engine/computer/computerController.js +249 -104
- package/bin/src/engine/computer/mockComputer.d.ts +6 -1
- package/bin/src/engine/computer/mockComputer.js +58 -0
- package/bin/src/engine/computer/scoutDriver.cs +84 -2
- package/bin/src/engine/llm.js +16 -0
- package/bin/src/engine/models/harpProvider.d.ts +32 -0
- package/bin/src/engine/models/harpProvider.js +124 -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/planner.js +64 -34
- 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 +99 -0
- 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/subagents/subagentManager.js +2 -2
- 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 +458 -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/index.js +26 -6
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/server/server.js +136 -0
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/session.d.ts +5 -1
- package/bin/src/utils/session.js +36 -3
- package/bin/src/utils/support.d.ts +63 -0
- package/bin/src/utils/support.js +182 -0
- package/package.json +2 -2
|
@@ -17,59 +17,89 @@ export function checkSimpleAppAction(objective) {
|
|
|
17
17
|
if (hasSecondaryWork) {
|
|
18
18
|
return { isSimple: false };
|
|
19
19
|
}
|
|
20
|
-
// Known apps dictionary
|
|
20
|
+
// Known apps dictionary with common aliases
|
|
21
21
|
const knownApps = [
|
|
22
22
|
'google chrome', 'chrome', 'notepad', 'calculator', 'calc',
|
|
23
|
-
'excel', 'word', 'paint', 'terminal', 'powershell', 'cmd',
|
|
24
|
-
'command prompt', 'browser', 'vs code', 'vscode', 'edge',
|
|
25
|
-
'firefox', 'spotify', 'slack', 'discord', 'file explorer', 'explorer'
|
|
23
|
+
'excel', 'word', 'paint', 'mspaint', 'terminal', 'powershell', 'cmd',
|
|
24
|
+
'command prompt', 'browser', 'vs code', 'vscode', 'code', 'edge',
|
|
25
|
+
'firefox', 'spotify', 'slack', 'discord', 'file explorer', 'explorer',
|
|
26
|
+
'blender', 'brave'
|
|
26
27
|
];
|
|
28
|
+
const cleanAppCandidate = (str) => {
|
|
29
|
+
return str
|
|
30
|
+
.replace(/^(the|a|an)\s+/i, '')
|
|
31
|
+
.replace(/\s+(app|application|browser)$/i, '')
|
|
32
|
+
.trim();
|
|
33
|
+
};
|
|
27
34
|
const isExactAppMatch = (target, app) => {
|
|
28
|
-
|
|
35
|
+
const cleaned = cleanAppCandidate(target);
|
|
36
|
+
return cleaned === app || target === app || target === `${app} browser` || target === `${app} app` || target === `${app} application`;
|
|
37
|
+
};
|
|
38
|
+
const resolveMatchedApp = (rawTarget) => {
|
|
39
|
+
const cleaned = cleanAppCandidate(rawTarget);
|
|
40
|
+
const match = knownApps.find(app => isExactAppMatch(cleaned, app) || isExactAppMatch(rawTarget, app));
|
|
41
|
+
if (match)
|
|
42
|
+
return match;
|
|
43
|
+
// If it's a clean 1-2 word identifier without special punctuation, treat as valid desktop app
|
|
44
|
+
if (/^[a-zA-Z0-9_\-\s]{2,30}$/.test(cleaned) && !/\b(something|anything|everything|nothing|task|job|work)\b/i.test(cleaned)) {
|
|
45
|
+
return cleaned;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
29
48
|
};
|
|
30
|
-
// English patterns: (open|launch|start|run) [the] [app]
|
|
49
|
+
// 1. English patterns: (open|launch|start|run) [the] [app]
|
|
31
50
|
const openMatch = clean.match(/^(open|launch|start|run)\s+(?:the\s+)?(.+)$/i);
|
|
32
51
|
if (openMatch && openMatch[2]) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return { isSimple: true, action: 'open', appName: matchedApp };
|
|
52
|
+
const resolved = resolveMatchedApp(openMatch[2]);
|
|
53
|
+
if (resolved) {
|
|
54
|
+
return { isSimple: true, action: 'open', appName: resolved };
|
|
37
55
|
}
|
|
38
56
|
}
|
|
39
|
-
// English close patterns: (close|kill|exit|quit|stop) [the] [app]
|
|
57
|
+
// 2. English close patterns: (close|kill|exit|quit|stop) [the] [app]
|
|
40
58
|
const closeMatch = clean.match(/^(close|kill|exit|quit|stop)\s+(?:the\s+)?(.+)$/i);
|
|
41
59
|
if (closeMatch && closeMatch[2]) {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { isSimple: true, action: 'close', appName: matchedApp };
|
|
60
|
+
const resolved = resolveMatchedApp(closeMatch[2]);
|
|
61
|
+
if (resolved) {
|
|
62
|
+
return { isSimple: true, action: 'close', appName: resolved };
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
|
-
// English switch/focus patterns: (switch to|focus|bring up) [the] [app]
|
|
65
|
+
// 3. English switch/focus patterns: (switch to|focus|bring up) [the] [app]
|
|
49
66
|
const switchMatch = clean.match(/^(switch\s+to|focus|bring\s+up)\s+(?:the\s+)?(.+)$/i);
|
|
50
67
|
if (switchMatch && switchMatch[2]) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
const resolved = resolveMatchedApp(switchMatch[2]);
|
|
69
|
+
if (resolved) {
|
|
70
|
+
return { isSimple: true, action: 'switch', appName: resolved };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// 4. Hinglish Verb-First Open: (khol do|kholo|khol|chala do|chalao|chala|open karo|launch karo|start karo) [app]
|
|
74
|
+
const hinglishVerbOpenMatch = clean.match(/^(khol\s+do|kholo|khol|chala\s+do|chalao|chala|open\s+karo|launch\s+karo|start\s+karo)\s+(?:the\s+)?(.+)$/i);
|
|
75
|
+
if (hinglishVerbOpenMatch && hinglishVerbOpenMatch[2]) {
|
|
76
|
+
const resolved = resolveMatchedApp(hinglishVerbOpenMatch[2]);
|
|
77
|
+
if (resolved) {
|
|
78
|
+
return { isSimple: true, action: 'open', appName: resolved };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// 5. Hinglish App-First Open: [app] (open|khol|kholo|chala|chalao|launch|start) (karo|kar do|kar|do|karna|dena)?
|
|
82
|
+
const hinglishAppOpenMatch = clean.match(/^(.+?)\s+(open|khol|kholo|chala|chalao|launch|start)\s*(karo|kar do|kar|do|karna|dena)?$/i);
|
|
83
|
+
if (hinglishAppOpenMatch && hinglishAppOpenMatch[1]) {
|
|
84
|
+
const resolved = resolveMatchedApp(hinglishAppOpenMatch[1]);
|
|
85
|
+
if (resolved) {
|
|
86
|
+
return { isSimple: true, action: 'open', appName: resolved };
|
|
55
87
|
}
|
|
56
88
|
}
|
|
57
|
-
// Hinglish
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return { isSimple: true, action: 'open', appName: matchedApp };
|
|
89
|
+
// 6. Hinglish Verb-First Close: (band kar do|band karo|band kar|close karo|kill karo) [app]
|
|
90
|
+
const hinglishVerbCloseMatch = clean.match(/^(band\s+kar\s+do|band\s+karo|band\s+kar|close\s+karo|kill\s+karo)\s+(?:the\s+)?(.+)$/i);
|
|
91
|
+
if (hinglishVerbCloseMatch && hinglishVerbCloseMatch[2]) {
|
|
92
|
+
const resolved = resolveMatchedApp(hinglishVerbCloseMatch[2]);
|
|
93
|
+
if (resolved) {
|
|
94
|
+
return { isSimple: true, action: 'close', appName: resolved };
|
|
64
95
|
}
|
|
65
96
|
}
|
|
66
|
-
// Hinglish
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return { isSimple: true, action: 'close', appName: matchedApp };
|
|
97
|
+
// 7. Hinglish App-First Close: [app] (close|band|kill) (karo|kar do|kar|do|karna|dena)?
|
|
98
|
+
const hinglishAppCloseMatch = clean.match(/^(.+?)\s+(close|band|kill)\s*(karo|kar do|kar|do|karna|dena)?$/i);
|
|
99
|
+
if (hinglishAppCloseMatch && hinglishAppCloseMatch[1]) {
|
|
100
|
+
const resolved = resolveMatchedApp(hinglishAppCloseMatch[1]);
|
|
101
|
+
if (resolved) {
|
|
102
|
+
return { isSimple: true, action: 'close', appName: resolved };
|
|
73
103
|
}
|
|
74
104
|
}
|
|
75
105
|
return { isSimple: false };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ReplayStep {
|
|
2
|
+
stepIndex: number;
|
|
3
|
+
action: string;
|
|
4
|
+
tool?: string | undefined;
|
|
5
|
+
args: Record<string, any>;
|
|
6
|
+
observationBefore?: any | undefined;
|
|
7
|
+
observationAfter?: any | undefined;
|
|
8
|
+
result: any;
|
|
9
|
+
success: boolean;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
timestamp: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TaskReplayTrace {
|
|
14
|
+
taskId: string;
|
|
15
|
+
objective: string;
|
|
16
|
+
startTime: string;
|
|
17
|
+
endTime?: string | undefined;
|
|
18
|
+
steps: ReplayStep[];
|
|
19
|
+
finalStatus: 'completed' | 'failed' | 'timeout' | 'interrupted';
|
|
20
|
+
totalDurationMs: number;
|
|
21
|
+
metadata?: Record<string, any> | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare class TaskReplayManager {
|
|
24
|
+
private traces;
|
|
25
|
+
startTrace(taskId: string, objective: string, metadata?: Record<string, any> | undefined): TaskReplayTrace;
|
|
26
|
+
recordStep(taskId: string, step: Omit<ReplayStep, 'timestamp'>): void;
|
|
27
|
+
finalizeTrace(taskId: string, status: TaskReplayTrace['finalStatus']): TaskReplayTrace | undefined;
|
|
28
|
+
getTrace(taskId: string): TaskReplayTrace | undefined;
|
|
29
|
+
exportTraceJson(taskId: string): string;
|
|
30
|
+
importTraceJson(jsonContent: string): TaskReplayTrace;
|
|
31
|
+
replay(taskId: string, stepExecutor?: (step: ReplayStep) => Promise<boolean>): Promise<{
|
|
32
|
+
totalReplayed: number;
|
|
33
|
+
matches: number;
|
|
34
|
+
failures: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=taskReplay.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export class TaskReplayManager {
|
|
2
|
+
traces = new Map();
|
|
3
|
+
startTrace(taskId, objective, metadata) {
|
|
4
|
+
const trace = {
|
|
5
|
+
taskId,
|
|
6
|
+
objective,
|
|
7
|
+
startTime: new Date().toISOString(),
|
|
8
|
+
steps: [],
|
|
9
|
+
finalStatus: 'completed',
|
|
10
|
+
totalDurationMs: 0,
|
|
11
|
+
metadata,
|
|
12
|
+
};
|
|
13
|
+
this.traces.set(taskId, trace);
|
|
14
|
+
return trace;
|
|
15
|
+
}
|
|
16
|
+
recordStep(taskId, step) {
|
|
17
|
+
const trace = this.traces.get(taskId);
|
|
18
|
+
if (!trace)
|
|
19
|
+
return;
|
|
20
|
+
trace.steps.push({
|
|
21
|
+
...step,
|
|
22
|
+
timestamp: new Date().toISOString(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
finalizeTrace(taskId, status) {
|
|
26
|
+
const trace = this.traces.get(taskId);
|
|
27
|
+
if (!trace)
|
|
28
|
+
return undefined;
|
|
29
|
+
trace.endTime = new Date().toISOString();
|
|
30
|
+
trace.finalStatus = status;
|
|
31
|
+
trace.totalDurationMs = Date.now() - new Date(trace.startTime).getTime();
|
|
32
|
+
return trace;
|
|
33
|
+
}
|
|
34
|
+
getTrace(taskId) {
|
|
35
|
+
return this.traces.get(taskId);
|
|
36
|
+
}
|
|
37
|
+
exportTraceJson(taskId) {
|
|
38
|
+
const trace = this.traces.get(taskId);
|
|
39
|
+
if (!trace)
|
|
40
|
+
throw new Error(`Trace not found for task ${taskId}`);
|
|
41
|
+
return JSON.stringify(trace, null, 2);
|
|
42
|
+
}
|
|
43
|
+
importTraceJson(jsonContent) {
|
|
44
|
+
const trace = JSON.parse(jsonContent);
|
|
45
|
+
this.traces.set(trace.taskId, trace);
|
|
46
|
+
return trace;
|
|
47
|
+
}
|
|
48
|
+
async replay(taskId, stepExecutor) {
|
|
49
|
+
const trace = this.traces.get(taskId);
|
|
50
|
+
if (!trace)
|
|
51
|
+
throw new Error(`Trace not found for task ${taskId}`);
|
|
52
|
+
let matches = 0;
|
|
53
|
+
let failures = 0;
|
|
54
|
+
for (const step of trace.steps) {
|
|
55
|
+
if (stepExecutor) {
|
|
56
|
+
const ok = await stepExecutor(step);
|
|
57
|
+
if (ok) {
|
|
58
|
+
matches++;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
failures++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Deterministic verification against recorded success
|
|
66
|
+
if (step.success) {
|
|
67
|
+
matches++;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
failures++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
totalReplayed: trace.steps.length,
|
|
76
|
+
matches,
|
|
77
|
+
failures,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=taskReplay.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface TelemetryEvent {
|
|
2
|
+
timestamp: string;
|
|
3
|
+
taskId: string;
|
|
4
|
+
stepIndex: number;
|
|
5
|
+
eventType: 'model_call' | 'tool_execution' | 'state_change' | 'recovery' | 'safety_check' | 'error';
|
|
6
|
+
provider?: string | undefined;
|
|
7
|
+
model?: string | undefined;
|
|
8
|
+
tool?: string | undefined;
|
|
9
|
+
latencyMs: number;
|
|
10
|
+
tokensUsed?: number | undefined;
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: string | undefined;
|
|
13
|
+
riskLevel?: number | undefined;
|
|
14
|
+
metadata?: Record<string, any> | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface ResourceLimits {
|
|
17
|
+
maxSteps: number;
|
|
18
|
+
maxDurationMs: number;
|
|
19
|
+
maxTokenBudget?: number | undefined;
|
|
20
|
+
maxRetriesPerStep: number;
|
|
21
|
+
}
|
|
22
|
+
export interface LatencySummary {
|
|
23
|
+
totalEvents: number;
|
|
24
|
+
avgModelLatencyMs: number;
|
|
25
|
+
avgToolLatencyMs: number;
|
|
26
|
+
totalTokens: number;
|
|
27
|
+
errorCount: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class TelemetryTracker {
|
|
30
|
+
private events;
|
|
31
|
+
private limits;
|
|
32
|
+
constructor(customLimits?: Partial<ResourceLimits> | undefined);
|
|
33
|
+
recordEvent(event: Omit<TelemetryEvent, 'timestamp'>): TelemetryEvent;
|
|
34
|
+
getEvents(taskId?: string | undefined): TelemetryEvent[];
|
|
35
|
+
checkResourceLimits(taskId: string, currentStep: number, startTimeMs: number, totalTokensUsed?: number): {
|
|
36
|
+
exceeded: boolean;
|
|
37
|
+
reason?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
getLatencySummary(taskId?: string | undefined): LatencySummary;
|
|
40
|
+
generateFailureTrace(taskId: string): string;
|
|
41
|
+
clear(): void;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -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;
|
|
@@ -221,6 +221,74 @@ Action Rules:
|
|
|
221
221
|
status: 'completed',
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
+
const simpleAppCheck = checkSimpleAppAction(userGoal);
|
|
225
|
+
if (simpleAppCheck.isSimple && simpleAppCheck.appName) {
|
|
226
|
+
const app = simpleAppCheck.appName;
|
|
227
|
+
const action = simpleAppCheck.action || 'open';
|
|
228
|
+
this.workspace.startStep(1);
|
|
229
|
+
let res;
|
|
230
|
+
const toolName = action === 'close' ? 'computer_close_app' : (action === 'switch' ? 'computer_switch_window' : 'computer_open_app');
|
|
231
|
+
const toolArgs = action === 'switch' ? { windowTitleOrApp: app } : { appName: app };
|
|
232
|
+
renderStepHeader({
|
|
233
|
+
step: 1,
|
|
234
|
+
maxSteps: this.maxSteps,
|
|
235
|
+
startTimeMs: this.startTime,
|
|
236
|
+
tokensConsumed: 0,
|
|
237
|
+
userTier: this.userTier,
|
|
238
|
+
});
|
|
239
|
+
renderToolCall({
|
|
240
|
+
name: toolName,
|
|
241
|
+
args: toolArgs,
|
|
242
|
+
step: 1,
|
|
243
|
+
});
|
|
244
|
+
const actionStartTime = Date.now();
|
|
245
|
+
if (action === 'close') {
|
|
246
|
+
res = await this.computerController.closeApplication(app);
|
|
247
|
+
}
|
|
248
|
+
else if (action === 'switch') {
|
|
249
|
+
res = await this.computerController.switchWindow(app);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
res = await this.computerController.openApplication(app);
|
|
253
|
+
}
|
|
254
|
+
renderToolResult({
|
|
255
|
+
name: toolName,
|
|
256
|
+
args: toolArgs,
|
|
257
|
+
result: JSON.stringify(res, null, 2),
|
|
258
|
+
durationMs: Date.now() - actionStartTime,
|
|
259
|
+
success: res && res.success !== false,
|
|
260
|
+
});
|
|
261
|
+
const actionVerb = action === 'close' ? 'closed' : (action === 'switch' ? 'focused' : 'launched');
|
|
262
|
+
const summary = res && res.success !== false
|
|
263
|
+
? `I've ${actionVerb} ${app} for you. It's ready on your screen!`
|
|
264
|
+
: `Attempted to ${action} ${app}: ${res?.output || res?.error || 'Failed to execute application action'}`;
|
|
265
|
+
this.workspace.completeStep(1, summary);
|
|
266
|
+
this.workspace.setStatus(res && res.success !== false ? 'completed' : 'failed');
|
|
267
|
+
renderTaskCompletedCard({
|
|
268
|
+
objective: userGoal,
|
|
269
|
+
summary,
|
|
270
|
+
modifiedFiles: [],
|
|
271
|
+
steps: 1,
|
|
272
|
+
maxSteps: this.maxSteps,
|
|
273
|
+
totalTokens: 0,
|
|
274
|
+
totalToolCalls: 1,
|
|
275
|
+
elapsedSecs: Math.max(0.1, (Date.now() - this.startTime) / 1000),
|
|
276
|
+
userTier: this.userTier,
|
|
277
|
+
});
|
|
278
|
+
saveAgentSession({
|
|
279
|
+
goal: userGoal,
|
|
280
|
+
summary,
|
|
281
|
+
modifiedFiles: [],
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
success: res && res.success !== false,
|
|
285
|
+
summary,
|
|
286
|
+
taskId,
|
|
287
|
+
stepsTaken: 1,
|
|
288
|
+
modifiedFiles: [],
|
|
289
|
+
status: res && res.success !== false ? 'completed' : 'failed',
|
|
290
|
+
};
|
|
291
|
+
}
|
|
224
292
|
this.historyMessages.push({ role: 'system', content: this.buildSystemPrompt() });
|
|
225
293
|
// Memory persistence
|
|
226
294
|
const recentMemory = getRecentSessionsSummary(1);
|
|
@@ -312,9 +380,40 @@ Action Rules:
|
|
|
312
380
|
goalLower.includes('calc') ||
|
|
313
381
|
goalLower.includes('paint') ||
|
|
314
382
|
goalLower.includes('type') ||
|
|
383
|
+
goalLower.includes('chrome') ||
|
|
384
|
+
goalLower.includes('browser') ||
|
|
385
|
+
goalLower.includes('vscode') ||
|
|
386
|
+
goalLower.includes('vs code') ||
|
|
387
|
+
goalLower.includes('code') ||
|
|
388
|
+
goalLower.includes('terminal') ||
|
|
389
|
+
goalLower.includes('powershell') ||
|
|
390
|
+
goalLower.includes('cmd') ||
|
|
391
|
+
goalLower.includes('explorer') ||
|
|
392
|
+
goalLower.includes('spotify') ||
|
|
393
|
+
goalLower.includes('slack') ||
|
|
394
|
+
goalLower.includes('discord') ||
|
|
395
|
+
goalLower.includes('edge') ||
|
|
396
|
+
goalLower.includes('firefox') ||
|
|
397
|
+
goalLower.includes('excel') ||
|
|
398
|
+
goalLower.includes('word') ||
|
|
399
|
+
goalLower.includes('blender') ||
|
|
400
|
+
goalLower.includes('open') ||
|
|
401
|
+
goalLower.includes('launch') ||
|
|
402
|
+
goalLower.includes('window') ||
|
|
403
|
+
simpleAppCheck.isSimple ||
|
|
315
404
|
this.workspace?.getExecutionIntent()?.requiredInteraction === 'computer' ||
|
|
316
405
|
((this.workspace?.getExecutionIntent()?.requiredApplications?.length ?? 0) > 0);
|
|
317
406
|
let baseTools = this.toolRegistry.getToolsForTier(this.userTier);
|
|
407
|
+
if (needsComputer) {
|
|
408
|
+
const computerTools = this.toolRegistry.getAllTools().filter((t) => t.name.startsWith('computer_'));
|
|
409
|
+
const existingNames = new Set(baseTools.map((t) => t.name));
|
|
410
|
+
for (const ct of computerTools) {
|
|
411
|
+
if (!existingNames.has(ct.name)) {
|
|
412
|
+
baseTools.push(ct);
|
|
413
|
+
existingNames.add(ct.name);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
318
417
|
if (mcpRouting.tools.length > 0 && !needsBrowser && !needsComputer) {
|
|
319
418
|
const ESSENTIAL_BASE_TOOLS = new Set(['read_file', 'write_file', 'edit_file', 'run_command', 'list_dir', 'grep_search', 'task_completed', 'ask_user', 'speak_text', 'scratchpad', 'computer_open_app']);
|
|
320
419
|
baseTools = baseTools.filter((t) => ESSENTIAL_BASE_TOOLS.has(t.name));
|
|
@@ -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
|