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
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { BrowserActionEngine } from '../browser/actions/index.js';
|
|
2
|
+
import {} from '../browser/observer/types.js';
|
|
3
|
+
import { TaskStateManager } from '../agentState.js';
|
|
4
|
+
import { StateChangeVerifier } from './verification/stateChangeVerifier.js';
|
|
5
|
+
import { RecoveryManager } from './recovery/recoveryManager.js';
|
|
6
|
+
import { LoopDetector } from './recovery/loopDetector.js';
|
|
7
|
+
/**
|
|
8
|
+
* ComputerUseAgentLoop: Connects perception (OBSERVE) and actions (ACT)
|
|
9
|
+
* to reasoning (UNDERSTAND -> PLAN -> VERIFY) around an explicit TaskState.
|
|
10
|
+
*
|
|
11
|
+
* Core Cycle:
|
|
12
|
+
* OBSERVE -> UNDERSTAND -> PLAN -> ACT -> VERIFY -> OBSERVE
|
|
13
|
+
*/
|
|
14
|
+
export class ComputerUseAgentLoop {
|
|
15
|
+
actionEngine;
|
|
16
|
+
stateManager;
|
|
17
|
+
stateVerifier;
|
|
18
|
+
recoveryManager;
|
|
19
|
+
loopDetector;
|
|
20
|
+
maxSteps;
|
|
21
|
+
maxRetries;
|
|
22
|
+
taskTimeoutMs;
|
|
23
|
+
workspaceDir;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.workspaceDir = options?.workspaceDir || process.cwd();
|
|
26
|
+
this.actionEngine = options?.actionEngine || new BrowserActionEngine(this.workspaceDir);
|
|
27
|
+
this.stateManager = options?.stateManager || new TaskStateManager(undefined, '', this.workspaceDir);
|
|
28
|
+
this.stateVerifier = options?.stateVerifier || new StateChangeVerifier();
|
|
29
|
+
this.recoveryManager = options?.recoveryManager || new RecoveryManager({ defaultMaxRetries: options?.maxRetries || 3 });
|
|
30
|
+
this.loopDetector = options?.loopDetector || new LoopDetector();
|
|
31
|
+
this.maxSteps = options?.maxSteps || 25;
|
|
32
|
+
this.maxRetries = options?.maxRetries || 3;
|
|
33
|
+
this.taskTimeoutMs = options?.taskTimeoutMs || 60000;
|
|
34
|
+
}
|
|
35
|
+
getActionEngine() {
|
|
36
|
+
return this.actionEngine;
|
|
37
|
+
}
|
|
38
|
+
getStateManager() {
|
|
39
|
+
return this.stateManager;
|
|
40
|
+
}
|
|
41
|
+
getStateVerifier() {
|
|
42
|
+
return this.stateVerifier;
|
|
43
|
+
}
|
|
44
|
+
getRecoveryManager() {
|
|
45
|
+
return this.recoveryManager;
|
|
46
|
+
}
|
|
47
|
+
getLoopDetector() {
|
|
48
|
+
return this.loopDetector;
|
|
49
|
+
}
|
|
50
|
+
getTaskState() {
|
|
51
|
+
return this.stateManager.getTaskState();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Executes an autonomous multi-step computer-use browser task.
|
|
55
|
+
*/
|
|
56
|
+
async runGoal(objective) {
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
this.stateManager.createTaskState(objective);
|
|
59
|
+
this.stateManager.setStatus('running');
|
|
60
|
+
// Initial default plan steps
|
|
61
|
+
const initialPlan = [
|
|
62
|
+
{ id: 1, description: 'Inspect current state & decide where to navigate', status: 'pending' },
|
|
63
|
+
{ id: 2, description: 'Navigate to target platform / repository', status: 'pending' },
|
|
64
|
+
{ id: 3, description: 'Inspect page and locate CI / Actions workflow', status: 'pending' },
|
|
65
|
+
{ id: 4, description: 'Open the failing workflow run or build failure', status: 'pending' },
|
|
66
|
+
{ id: 5, description: 'Read and extract failure logs and root cause', status: 'pending' },
|
|
67
|
+
{ id: 6, description: 'Determine objective completion and return structured diagnosis', status: 'pending' },
|
|
68
|
+
];
|
|
69
|
+
this.stateManager.updatePlan(initialPlan);
|
|
70
|
+
let stepCount = 0;
|
|
71
|
+
let structuredResult;
|
|
72
|
+
let finalSummary = '';
|
|
73
|
+
let timedOut = false;
|
|
74
|
+
while (stepCount < this.maxSteps) {
|
|
75
|
+
// Task timeout guard
|
|
76
|
+
if (this.recoveryManager.isTaskTimedOut(startTime, this.taskTimeoutMs)) {
|
|
77
|
+
timedOut = true;
|
|
78
|
+
finalSummary = `Task timed out after ${this.taskTimeoutMs}ms (exceeded execution budget).`;
|
|
79
|
+
this.stateManager.setStatus('timeout');
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
stepCount++;
|
|
83
|
+
this.stateManager.startStep(stepCount);
|
|
84
|
+
// 1. OBSERVE: Collect current BrowserState (with crash recovery)
|
|
85
|
+
let observation;
|
|
86
|
+
try {
|
|
87
|
+
observation = await this.stage_observe();
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
const recovered = await this.recoveryManager.handleBrowserCrash(this.actionEngine);
|
|
91
|
+
if (recovered.recovered) {
|
|
92
|
+
observation = await this.stage_observe();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
finalSummary = `Browser crash unrecoverable: ${err.message}`;
|
|
96
|
+
this.stateManager.setStatus('failed');
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 2. UNDERSTAND: Interpret observation relative to objective
|
|
101
|
+
const understanding = await this.stage_understand(observation, objective);
|
|
102
|
+
// Check if objective is already completed
|
|
103
|
+
if (understanding.isObjectiveMet) {
|
|
104
|
+
structuredResult = {
|
|
105
|
+
objectiveCompleted: true,
|
|
106
|
+
conclusion: understanding.conclusion,
|
|
107
|
+
failingWorkflows: understanding.failingWorkflows,
|
|
108
|
+
logDetails: understanding.logContent,
|
|
109
|
+
url: observation.url,
|
|
110
|
+
};
|
|
111
|
+
finalSummary = understanding.conclusion || 'Objective achieved successfully.';
|
|
112
|
+
this.stateManager.setStructuredResult(structuredResult);
|
|
113
|
+
this.stateManager.completeStep(stepCount, finalSummary);
|
|
114
|
+
this.stateManager.setStatus('completed');
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
// 3. PLAN: Decide next action
|
|
118
|
+
const plannedAction = await this.stage_plan(understanding, objective, stepCount);
|
|
119
|
+
if (plannedAction.actionType === 'complete') {
|
|
120
|
+
structuredResult = plannedAction.args.result;
|
|
121
|
+
finalSummary = plannedAction.description;
|
|
122
|
+
this.stateManager.completeStep(stepCount, finalSummary);
|
|
123
|
+
this.stateManager.setStatus('completed');
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
// 4. ACT: Execute deterministic action primitive
|
|
127
|
+
const actionResult = await this.stage_act(plannedAction);
|
|
128
|
+
// Record action into LoopDetector
|
|
129
|
+
const loopCheck = this.loopDetector.recordAction({
|
|
130
|
+
step: stepCount,
|
|
131
|
+
tool: plannedAction.tool,
|
|
132
|
+
actionType: plannedAction.actionType,
|
|
133
|
+
args: plannedAction.args,
|
|
134
|
+
target: plannedAction.args.target,
|
|
135
|
+
success: actionResult.success,
|
|
136
|
+
url: observation.url,
|
|
137
|
+
timestamp: Date.now(),
|
|
138
|
+
});
|
|
139
|
+
// 5. VERIFY: Confirm expected state change occurred (Dedicated Verification System)
|
|
140
|
+
const postState = await this.stage_observe();
|
|
141
|
+
const verification = this.stateVerifier.verifyStateChange({
|
|
142
|
+
actionResult,
|
|
143
|
+
plannedAction,
|
|
144
|
+
beforeState: observation,
|
|
145
|
+
afterState: postState,
|
|
146
|
+
});
|
|
147
|
+
if (verification.verified) {
|
|
148
|
+
this.stateManager.completeStep(stepCount, verification.details);
|
|
149
|
+
this.stateManager.resetRetries();
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const retries = this.stateManager.incrementRetries();
|
|
153
|
+
const recovery = this.recoveryManager.decideRecovery({
|
|
154
|
+
tool: plannedAction.tool,
|
|
155
|
+
actionType: plannedAction.actionType,
|
|
156
|
+
target: plannedAction.args.target,
|
|
157
|
+
error: actionResult.error || verification.details,
|
|
158
|
+
attempt: retries,
|
|
159
|
+
maxRetries: this.maxRetries,
|
|
160
|
+
loopDetection: loopCheck,
|
|
161
|
+
verificationResult: verification,
|
|
162
|
+
currentState: postState,
|
|
163
|
+
});
|
|
164
|
+
this.stateManager.recordError(verification.details, plannedAction.tool, `[${recovery.strategy}] ${recovery.reason}`);
|
|
165
|
+
if (recovery.shouldHalt) {
|
|
166
|
+
finalSummary = recovery.reason;
|
|
167
|
+
this.stateManager.setStatus('failed');
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
// Exponential backoff delay
|
|
171
|
+
if (recovery.backoffDelayMs > 0) {
|
|
172
|
+
await new Promise(r => setTimeout(r, recovery.backoffDelayMs));
|
|
173
|
+
}
|
|
174
|
+
// If semantic alternative target was suggested, apply it to next planned action
|
|
175
|
+
if (recovery.suggestedAlternativeTarget) {
|
|
176
|
+
plannedAction.args.target = recovery.suggestedAlternativeTarget;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Loop continues -> Next turn re-observes (OBSERVE)
|
|
180
|
+
}
|
|
181
|
+
const isComplete = this.stateManager.getTaskState().status === 'completed';
|
|
182
|
+
const taskState = this.stateManager.getTaskState();
|
|
183
|
+
return {
|
|
184
|
+
success: isComplete,
|
|
185
|
+
objective,
|
|
186
|
+
status: isComplete ? 'completed' : (timedOut || stepCount >= this.maxSteps ? 'timeout' : 'failed'),
|
|
187
|
+
stepsExecuted: stepCount,
|
|
188
|
+
completedSteps: taskState.completed_steps,
|
|
189
|
+
taskState,
|
|
190
|
+
summary: finalSummary || (isComplete ? 'Goal fulfilled' : 'Failed to reach objective within step limit'),
|
|
191
|
+
structuredResult,
|
|
192
|
+
durationMs: Date.now() - startTime,
|
|
193
|
+
toolHistory: taskState.tool_history,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Stage 1: OBSERVE
|
|
198
|
+
*/
|
|
199
|
+
async stage_observe() {
|
|
200
|
+
const tab = this.actionEngine.getActiveTab();
|
|
201
|
+
const state = await this.actionEngine.getObserver().observe({
|
|
202
|
+
html: tab?.html || '',
|
|
203
|
+
url: tab?.url || 'about:blank',
|
|
204
|
+
title: tab?.title || '',
|
|
205
|
+
});
|
|
206
|
+
this.stateManager.setBrowserState(state);
|
|
207
|
+
this.stateManager.setActiveUrl(state.url);
|
|
208
|
+
return state;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Stage 2: UNDERSTAND
|
|
212
|
+
*/
|
|
213
|
+
async stage_understand(state, objective) {
|
|
214
|
+
const urlLower = state.url.toLowerCase();
|
|
215
|
+
const titleLower = state.title.toLowerCase();
|
|
216
|
+
const visibleText = state.visibleText.toLowerCase();
|
|
217
|
+
// 1. Classify Page Category
|
|
218
|
+
let pageCategory = 'unknown';
|
|
219
|
+
if (state.url === 'about:blank') {
|
|
220
|
+
pageCategory = 'initial';
|
|
221
|
+
}
|
|
222
|
+
else if (urlLower.includes('/actions/runs/') || visibleText.includes('run details') || (urlLower.includes('/actions') && visibleText.includes('failed in job'))) {
|
|
223
|
+
pageCategory = 'workflow_run';
|
|
224
|
+
}
|
|
225
|
+
else if (urlLower.includes('/actions') || visibleText.includes('all workflows') || titleLower.includes('actions')) {
|
|
226
|
+
pageCategory = 'actions_dashboard';
|
|
227
|
+
}
|
|
228
|
+
else if (urlLower.includes('github.com') || visibleText.includes('commit') || visibleText.includes('pull requests') || visibleText.includes('repository')) {
|
|
229
|
+
pageCategory = 'repo_index';
|
|
230
|
+
}
|
|
231
|
+
else if (visibleText.includes('syntaxerror') || visibleText.includes('failed with exit code') || visibleText.includes('stack trace')) {
|
|
232
|
+
pageCategory = 'job_log';
|
|
233
|
+
}
|
|
234
|
+
// 2. Identify Failing Workflows & CI Runs
|
|
235
|
+
const failingWorkflows = [];
|
|
236
|
+
for (const el of state.elements) {
|
|
237
|
+
const textL = el.text.toLowerCase();
|
|
238
|
+
const isFailure = /fail|failed|error|failing|broken|cancelled/i.test(textL) ||
|
|
239
|
+
el.attributes['class']?.includes('failure') ||
|
|
240
|
+
el.attributes['data-status'] === 'failure';
|
|
241
|
+
if (isFailure) {
|
|
242
|
+
failingWorkflows.push({
|
|
243
|
+
name: el.text,
|
|
244
|
+
target: el.selector,
|
|
245
|
+
status: 'failed',
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// 3. Extract Log Content
|
|
250
|
+
let logContent;
|
|
251
|
+
if (pageCategory === 'workflow_run' || pageCategory === 'job_log' || visibleText.includes('error:')) {
|
|
252
|
+
logContent = state.visibleText;
|
|
253
|
+
}
|
|
254
|
+
// 4. Modal / Dialog detection
|
|
255
|
+
const openModal = state.modals?.find(m => m.isOpen);
|
|
256
|
+
const hasBlockingModal = Boolean(openModal);
|
|
257
|
+
// 5. Objective Completion Assessment
|
|
258
|
+
const isCiGoal = /ci|build|test|failing|failure/i.test(objective);
|
|
259
|
+
let isObjectiveMet = false;
|
|
260
|
+
let conclusion;
|
|
261
|
+
if (isCiGoal && logContent && /fail|error|syntaxerror|assertionerror/i.test(logContent)) {
|
|
262
|
+
// Find root cause snippet in logs
|
|
263
|
+
const errorMatch = logContent.match(/(?:error|syntaxerror|typeerror|assertionerror)[^\n.!?]{0,100}/i);
|
|
264
|
+
const reason = errorMatch ? errorMatch[0] : 'Compilation or test suite failure';
|
|
265
|
+
isObjectiveMet = true;
|
|
266
|
+
conclusion = `CI failure root cause identified: "${reason}". Failing job logs examined successfully.`;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
currentUrl: state.url,
|
|
270
|
+
pageTitle: state.title,
|
|
271
|
+
pageCategory,
|
|
272
|
+
failingWorkflows,
|
|
273
|
+
logContent,
|
|
274
|
+
hasBlockingModal,
|
|
275
|
+
isObjectiveMet,
|
|
276
|
+
conclusion,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Stage 3: PLAN
|
|
281
|
+
*/
|
|
282
|
+
async stage_plan(understanding, objective, step) {
|
|
283
|
+
// Handle blocking modal if present
|
|
284
|
+
if (understanding.hasBlockingModal) {
|
|
285
|
+
return {
|
|
286
|
+
stepId: step,
|
|
287
|
+
description: 'Dismiss blocking popup dialog with Escape key',
|
|
288
|
+
actionType: 'click',
|
|
289
|
+
tool: 'press_key',
|
|
290
|
+
args: { key: 'Escape' },
|
|
291
|
+
expectedOutcome: 'Modal dialog dismissed',
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
// Target navigation if on initial page
|
|
295
|
+
if (understanding.pageCategory === 'initial') {
|
|
296
|
+
let targetUrl = 'https://github.com/Front-Terrain/ft-scout';
|
|
297
|
+
if (/github/i.test(objective)) {
|
|
298
|
+
targetUrl = 'https://github.com/Front-Terrain/ft-scout/actions';
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
stepId: step,
|
|
302
|
+
description: `Navigate to target URL: ${targetUrl}`,
|
|
303
|
+
actionType: 'navigate',
|
|
304
|
+
tool: 'navigate',
|
|
305
|
+
args: { url: targetUrl },
|
|
306
|
+
expectedOutcome: 'Page loads with target repository and CI workflows',
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
// If on repository index, open Actions/CI tab
|
|
310
|
+
if (understanding.pageCategory === 'repo_index') {
|
|
311
|
+
return {
|
|
312
|
+
stepId: step,
|
|
313
|
+
description: 'Open the Actions / CI tab to inspect workflow runs',
|
|
314
|
+
actionType: 'click',
|
|
315
|
+
tool: 'click',
|
|
316
|
+
args: { target: 'a:contains("Actions")' },
|
|
317
|
+
expectedOutcome: 'Navigate to Actions dashboard',
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// If on Actions dashboard, open the failing workflow run
|
|
321
|
+
if (understanding.pageCategory === 'actions_dashboard') {
|
|
322
|
+
const target = understanding.failingWorkflows[0]?.target || 'a:contains("Failed")';
|
|
323
|
+
return {
|
|
324
|
+
stepId: step,
|
|
325
|
+
description: 'Click on the failing CI run to view job execution details',
|
|
326
|
+
actionType: 'click',
|
|
327
|
+
tool: 'click',
|
|
328
|
+
args: { target },
|
|
329
|
+
expectedOutcome: 'Navigate to failing workflow run page',
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
// If on workflow run page, open failed job or view logs
|
|
333
|
+
if (understanding.pageCategory === 'workflow_run') {
|
|
334
|
+
return {
|
|
335
|
+
stepId: step,
|
|
336
|
+
description: 'Click to open and read failure logs for failing job step',
|
|
337
|
+
actionType: 'click',
|
|
338
|
+
tool: 'click',
|
|
339
|
+
args: { target: 'button:contains("Logs"), a:contains("Logs"), a:contains("Test")' },
|
|
340
|
+
expectedOutcome: 'Failure log details displayed',
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
// Fallback default
|
|
344
|
+
return {
|
|
345
|
+
stepId: step,
|
|
346
|
+
description: 'Inspect page and capture readable content',
|
|
347
|
+
actionType: 'read',
|
|
348
|
+
tool: 'wait',
|
|
349
|
+
args: { condition: 100 },
|
|
350
|
+
expectedOutcome: 'Content loaded',
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Stage 4: ACT
|
|
355
|
+
*/
|
|
356
|
+
async stage_act(planned) {
|
|
357
|
+
let result;
|
|
358
|
+
switch (planned.tool) {
|
|
359
|
+
case 'navigate': {
|
|
360
|
+
result = await this.actionEngine.navigate(planned.args.url, planned.args.htmlContent);
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
case 'click': {
|
|
364
|
+
result = await this.actionEngine.click(planned.args.target);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case 'type': {
|
|
368
|
+
result = await this.actionEngine.type(planned.args.target, planned.args.text, planned.args.options);
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case 'select': {
|
|
372
|
+
result = await this.actionEngine.select(planned.args.target, planned.args.value);
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
case 'press_key': {
|
|
376
|
+
result = await this.actionEngine.press_key(planned.args.key);
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
case 'wait': {
|
|
380
|
+
result = await this.actionEngine.wait(planned.args.condition);
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
default: {
|
|
384
|
+
result = await this.actionEngine.wait(100);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// Record to TaskState tool history
|
|
389
|
+
this.stateManager.addToolHistory({
|
|
390
|
+
step: planned.stepId,
|
|
391
|
+
tool: planned.tool,
|
|
392
|
+
args: planned.args,
|
|
393
|
+
resultSummary: result.success ? `Executed ${planned.tool} (${result.durationMs}ms)` : `Error: ${result.error}`,
|
|
394
|
+
});
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Stage 5: VERIFY
|
|
399
|
+
* Verifies that the expected state change occurred using the dedicated StateChangeVerifier.
|
|
400
|
+
*/
|
|
401
|
+
async stage_verify(actionResult, planned, beforeState, afterState) {
|
|
402
|
+
const before = beforeState || actionResult.beforeState || this.stateManager.getTaskState().browser_state;
|
|
403
|
+
const after = afterState || actionResult.afterState || (await this.stage_observe());
|
|
404
|
+
const verification = this.stateVerifier.verifyStateChange({
|
|
405
|
+
actionResult,
|
|
406
|
+
plannedAction: planned,
|
|
407
|
+
beforeState: before,
|
|
408
|
+
afterState: after,
|
|
409
|
+
});
|
|
410
|
+
return verification.verified;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=computerUseLoop.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ActionHistoryRecord, type LoopDetectionResult } from './types.js';
|
|
2
|
+
export interface LoopDetectorOptions {
|
|
3
|
+
repeatedActionThreshold?: number | undefined;
|
|
4
|
+
maxHistorySize?: number | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare class LoopDetector {
|
|
7
|
+
private history;
|
|
8
|
+
private repeatedActionThreshold;
|
|
9
|
+
private maxHistorySize;
|
|
10
|
+
constructor(options?: LoopDetectorOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Records an executed action into history and checks for loops.
|
|
13
|
+
*/
|
|
14
|
+
recordAction(record: ActionHistoryRecord): LoopDetectionResult;
|
|
15
|
+
/**
|
|
16
|
+
* Inspects current action history for repeated actions, ping-pong oscillations, or cyclical loops.
|
|
17
|
+
*/
|
|
18
|
+
detectLoop(): LoopDetectionResult;
|
|
19
|
+
getHistory(): readonly ActionHistoryRecord[];
|
|
20
|
+
reset(): void;
|
|
21
|
+
private getActionSignature;
|
|
22
|
+
private checkRepeatedActions;
|
|
23
|
+
private checkPingPongOscillation;
|
|
24
|
+
private checkCycles;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=loopDetector.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
export class LoopDetector {
|
|
3
|
+
history = [];
|
|
4
|
+
repeatedActionThreshold;
|
|
5
|
+
maxHistorySize;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.repeatedActionThreshold = options?.repeatedActionThreshold || 3;
|
|
8
|
+
this.maxHistorySize = options?.maxHistorySize || 30;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Records an executed action into history and checks for loops.
|
|
12
|
+
*/
|
|
13
|
+
recordAction(record) {
|
|
14
|
+
this.history.push(record);
|
|
15
|
+
if (this.history.length > this.maxHistorySize) {
|
|
16
|
+
this.history.shift();
|
|
17
|
+
}
|
|
18
|
+
return this.detectLoop();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Inspects current action history for repeated actions, ping-pong oscillations, or cyclical loops.
|
|
22
|
+
*/
|
|
23
|
+
detectLoop() {
|
|
24
|
+
if (this.history.length < 2) {
|
|
25
|
+
return { isLoop: false };
|
|
26
|
+
}
|
|
27
|
+
// 1. Repeated-Action Detection (same action executed N times consecutively)
|
|
28
|
+
const repeatedResult = this.checkRepeatedActions();
|
|
29
|
+
if (repeatedResult.isLoop) {
|
|
30
|
+
return repeatedResult;
|
|
31
|
+
}
|
|
32
|
+
// 2. Ping-Pong Oscillation Detection (A -> B -> A -> B)
|
|
33
|
+
const pingPongResult = this.checkPingPongOscillation();
|
|
34
|
+
if (pingPongResult.isLoop) {
|
|
35
|
+
return pingPongResult;
|
|
36
|
+
}
|
|
37
|
+
// 3. Multi-Step Cycle Detection (e.g. A -> B -> C -> A -> B -> C)
|
|
38
|
+
const cycleResult = this.checkCycles();
|
|
39
|
+
if (cycleResult.isLoop) {
|
|
40
|
+
return cycleResult;
|
|
41
|
+
}
|
|
42
|
+
return { isLoop: false };
|
|
43
|
+
}
|
|
44
|
+
getHistory() {
|
|
45
|
+
return this.history;
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
this.history = [];
|
|
49
|
+
}
|
|
50
|
+
getActionSignature(rec) {
|
|
51
|
+
const target = rec.target || rec.args.target || rec.args.url || '';
|
|
52
|
+
return `${rec.tool}:${rec.actionType}:${target}`;
|
|
53
|
+
}
|
|
54
|
+
checkRepeatedActions() {
|
|
55
|
+
const len = this.history.length;
|
|
56
|
+
if (len < this.repeatedActionThreshold) {
|
|
57
|
+
return { isLoop: false };
|
|
58
|
+
}
|
|
59
|
+
const lastSig = this.getActionSignature(this.history[len - 1]);
|
|
60
|
+
let count = 0;
|
|
61
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
62
|
+
if (this.getActionSignature(this.history[i]) === lastSig) {
|
|
63
|
+
count++;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (count >= this.repeatedActionThreshold) {
|
|
70
|
+
return {
|
|
71
|
+
isLoop: true,
|
|
72
|
+
loopType: 'repeated_action',
|
|
73
|
+
repeatedCount: count,
|
|
74
|
+
patternSummary: lastSig,
|
|
75
|
+
message: `Loop detected: Action "${lastSig}" repeated ${count} consecutive times without progress.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { isLoop: false };
|
|
79
|
+
}
|
|
80
|
+
checkPingPongOscillation() {
|
|
81
|
+
// Need at least 4 actions: A B A B
|
|
82
|
+
const len = this.history.length;
|
|
83
|
+
if (len < 4) {
|
|
84
|
+
return { isLoop: false };
|
|
85
|
+
}
|
|
86
|
+
const a1 = this.getActionSignature(this.history[len - 4]);
|
|
87
|
+
const b1 = this.getActionSignature(this.history[len - 3]);
|
|
88
|
+
const a2 = this.getActionSignature(this.history[len - 2]);
|
|
89
|
+
const b2 = this.getActionSignature(this.history[len - 1]);
|
|
90
|
+
if (a1 !== b1 && a1 === a2 && b1 === b2) {
|
|
91
|
+
return {
|
|
92
|
+
isLoop: true,
|
|
93
|
+
loopType: 'ping_pong',
|
|
94
|
+
repeatedCount: 2,
|
|
95
|
+
patternSummary: `${a1} <-> ${b1}`,
|
|
96
|
+
message: `Loop detected: Ping-pong oscillation between "${a1}" and "${b1}".`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return { isLoop: false };
|
|
100
|
+
}
|
|
101
|
+
checkCycles() {
|
|
102
|
+
// Need at least 6 actions for a 3-step cycle: A B C A B C
|
|
103
|
+
const len = this.history.length;
|
|
104
|
+
if (len < 6) {
|
|
105
|
+
return { isLoop: false };
|
|
106
|
+
}
|
|
107
|
+
const s1 = this.getActionSignature(this.history[len - 6]);
|
|
108
|
+
const s2 = this.getActionSignature(this.history[len - 5]);
|
|
109
|
+
const s3 = this.getActionSignature(this.history[len - 4]);
|
|
110
|
+
const s4 = this.getActionSignature(this.history[len - 3]);
|
|
111
|
+
const s5 = this.getActionSignature(this.history[len - 2]);
|
|
112
|
+
const s6 = this.getActionSignature(this.history[len - 1]);
|
|
113
|
+
if (s1 === s4 && s2 === s5 && s3 === s6 && (s1 !== s2 || s2 !== s3)) {
|
|
114
|
+
return {
|
|
115
|
+
isLoop: true,
|
|
116
|
+
loopType: 'cycle',
|
|
117
|
+
cycleLength: 3,
|
|
118
|
+
repeatedCount: 2,
|
|
119
|
+
patternSummary: `${s1} -> ${s2} -> ${s3}`,
|
|
120
|
+
message: `Loop detected: Cycle of 3 actions repeated ("${s1} -> ${s2} -> ${s3}").`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { isLoop: false };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=loopDetector.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type BrowserState } from '../../browser/observer/types.js';
|
|
2
|
+
import { type BrowserActionEngine } from '../../browser/actions/index.js';
|
|
3
|
+
import { type RecoveryDecision, type RecoveryContext } from './types.js';
|
|
4
|
+
export declare class RecoveryManager {
|
|
5
|
+
private defaultMaxRetries;
|
|
6
|
+
private baseBackoffMs;
|
|
7
|
+
private maxBackoffMs;
|
|
8
|
+
constructor(options?: {
|
|
9
|
+
defaultMaxRetries?: number | undefined;
|
|
10
|
+
baseBackoffMs?: number | undefined;
|
|
11
|
+
maxBackoffMs?: number | undefined;
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Decides the next recovery step following the strict hierarchy:
|
|
15
|
+
* RETRY -> RE_OBSERVE -> RE_LOCATE -> SEMANTIC_ALTERNATIVE -> VISUAL_FALLBACK -> REPORT_FAILURE
|
|
16
|
+
*/
|
|
17
|
+
decideRecovery(ctx: RecoveryContext): RecoveryDecision;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates exponential backoff with randomized jitter to prevent thundering herds.
|
|
20
|
+
*/
|
|
21
|
+
computeBackoff(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if task has exceeded maximum allotted execution time.
|
|
24
|
+
*/
|
|
25
|
+
isTaskTimedOut(startTime: number, timeoutMs?: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Returns remaining task execution time in milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
getRemainingTimeMs(startTime: number, timeoutMs?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Recovers from browser session crashes or lost connections.
|
|
32
|
+
*/
|
|
33
|
+
handleBrowserCrash(actionEngine: BrowserActionEngine, lastKnownUrl?: string): Promise<{
|
|
34
|
+
recovered: boolean;
|
|
35
|
+
message: string;
|
|
36
|
+
recoveredUrl: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Finds semantic alternative elements when a target element is missing or fails.
|
|
40
|
+
*/
|
|
41
|
+
findSemanticAlternative(target: string, state: BrowserState): string | undefined;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=recoveryManager.d.ts.map
|