ft-scout 9.5.5 → 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/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 +2 -1
- 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 +43 -0
- package/bin/src/engine/computer/computerController.js +111 -0
- package/bin/src/engine/computer/mockComputer.d.ts +6 -1
- package/bin/src/engine/computer/mockComputer.js +58 -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/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/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 +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 +4 -4
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/support.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BrowserActionEngine, type ActionResult } from '../browser/actions/index.js';
|
|
2
|
+
import { type BrowserState } from '../browser/observer/types.js';
|
|
3
|
+
import { TaskStateManager, type TaskState } 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
|
+
export interface ComputerUseTaskResult {
|
|
8
|
+
success: boolean;
|
|
9
|
+
objective: string;
|
|
10
|
+
status: 'completed' | 'failed' | 'timeout';
|
|
11
|
+
stepsExecuted: number;
|
|
12
|
+
completedSteps: number[];
|
|
13
|
+
taskState: TaskState;
|
|
14
|
+
summary: string;
|
|
15
|
+
structuredResult?: Record<string, any> | undefined;
|
|
16
|
+
durationMs: number;
|
|
17
|
+
toolHistory: Array<{
|
|
18
|
+
step: number;
|
|
19
|
+
tool: string;
|
|
20
|
+
args: Record<string, any>;
|
|
21
|
+
resultSummary?: string | undefined;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface UnderstandingInsight {
|
|
26
|
+
currentUrl: string;
|
|
27
|
+
pageTitle: string;
|
|
28
|
+
pageCategory: 'initial' | 'repo_index' | 'actions_dashboard' | 'workflow_run' | 'job_log' | 'form' | 'unknown';
|
|
29
|
+
failingWorkflows: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
target: string;
|
|
32
|
+
status: string;
|
|
33
|
+
}>;
|
|
34
|
+
logContent?: string | undefined;
|
|
35
|
+
hasBlockingModal: boolean;
|
|
36
|
+
isObjectiveMet: boolean;
|
|
37
|
+
conclusion?: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface PlannedAction {
|
|
40
|
+
stepId: number;
|
|
41
|
+
description: string;
|
|
42
|
+
actionType: 'navigate' | 'click' | 'type' | 'select' | 'read' | 'complete';
|
|
43
|
+
tool: string;
|
|
44
|
+
args: Record<string, any>;
|
|
45
|
+
expectedOutcome: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ComputerUseAgentLoop: Connects perception (OBSERVE) and actions (ACT)
|
|
49
|
+
* to reasoning (UNDERSTAND -> PLAN -> VERIFY) around an explicit TaskState.
|
|
50
|
+
*
|
|
51
|
+
* Core Cycle:
|
|
52
|
+
* OBSERVE -> UNDERSTAND -> PLAN -> ACT -> VERIFY -> OBSERVE
|
|
53
|
+
*/
|
|
54
|
+
export declare class ComputerUseAgentLoop {
|
|
55
|
+
private actionEngine;
|
|
56
|
+
private stateManager;
|
|
57
|
+
private stateVerifier;
|
|
58
|
+
private recoveryManager;
|
|
59
|
+
private loopDetector;
|
|
60
|
+
private maxSteps;
|
|
61
|
+
private maxRetries;
|
|
62
|
+
private taskTimeoutMs;
|
|
63
|
+
private workspaceDir;
|
|
64
|
+
constructor(options?: {
|
|
65
|
+
actionEngine?: BrowserActionEngine | undefined;
|
|
66
|
+
stateManager?: TaskStateManager | undefined;
|
|
67
|
+
stateVerifier?: StateChangeVerifier | undefined;
|
|
68
|
+
recoveryManager?: RecoveryManager | undefined;
|
|
69
|
+
loopDetector?: LoopDetector | undefined;
|
|
70
|
+
maxSteps?: number | undefined;
|
|
71
|
+
maxRetries?: number | undefined;
|
|
72
|
+
taskTimeoutMs?: number | undefined;
|
|
73
|
+
workspaceDir?: string | undefined;
|
|
74
|
+
});
|
|
75
|
+
getActionEngine(): BrowserActionEngine;
|
|
76
|
+
getStateManager(): TaskStateManager;
|
|
77
|
+
getStateVerifier(): StateChangeVerifier;
|
|
78
|
+
getRecoveryManager(): RecoveryManager;
|
|
79
|
+
getLoopDetector(): LoopDetector;
|
|
80
|
+
getTaskState(): TaskState;
|
|
81
|
+
/**
|
|
82
|
+
* Executes an autonomous multi-step computer-use browser task.
|
|
83
|
+
*/
|
|
84
|
+
runGoal(objective: string): Promise<ComputerUseTaskResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Stage 1: OBSERVE
|
|
87
|
+
*/
|
|
88
|
+
stage_observe(): Promise<BrowserState>;
|
|
89
|
+
/**
|
|
90
|
+
* Stage 2: UNDERSTAND
|
|
91
|
+
*/
|
|
92
|
+
stage_understand(state: BrowserState, objective: string): Promise<UnderstandingInsight>;
|
|
93
|
+
/**
|
|
94
|
+
* Stage 3: PLAN
|
|
95
|
+
*/
|
|
96
|
+
stage_plan(understanding: UnderstandingInsight, objective: string, step: number): Promise<PlannedAction>;
|
|
97
|
+
/**
|
|
98
|
+
* Stage 4: ACT
|
|
99
|
+
*/
|
|
100
|
+
stage_act(planned: PlannedAction): Promise<ActionResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Stage 5: VERIFY
|
|
103
|
+
* Verifies that the expected state change occurred using the dedicated StateChangeVerifier.
|
|
104
|
+
*/
|
|
105
|
+
stage_verify(actionResult: ActionResult, planned: PlannedAction, beforeState?: BrowserState | undefined, afterState?: BrowserState | undefined): Promise<boolean>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=computerUseLoop.d.ts.map
|
|
@@ -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
|