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.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
  3. package/bin/src/engine/agent/computerUseLoop.js +413 -0
  4. package/bin/src/engine/agent/index.d.ts +2 -0
  5. package/bin/src/engine/agent/index.js +2 -0
  6. package/bin/src/engine/agent/recovery/index.d.ts +4 -0
  7. package/bin/src/engine/agent/recovery/index.js +4 -0
  8. package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
  9. package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
  10. package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
  11. package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
  12. package/bin/src/engine/agent/recovery/types.d.ts +48 -0
  13. package/bin/src/engine/agent/recovery/types.js +4 -0
  14. package/bin/src/engine/agent/verification/index.d.ts +3 -0
  15. package/bin/src/engine/agent/verification/index.js +3 -0
  16. package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
  17. package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
  18. package/bin/src/engine/agent/verification/types.d.ts +28 -0
  19. package/bin/src/engine/agent/verification/types.js +4 -0
  20. package/bin/src/engine/agentEngine.d.ts +3 -1
  21. package/bin/src/engine/agentEngine.js +370 -56
  22. package/bin/src/engine/agentState.d.ts +41 -1
  23. package/bin/src/engine/agentState.js +45 -0
  24. package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
  25. package/bin/src/engine/browser/actions/actionEngine.js +707 -0
  26. package/bin/src/engine/browser/actions/index.d.ts +4 -0
  27. package/bin/src/engine/browser/actions/index.js +4 -0
  28. package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
  29. package/bin/src/engine/browser/actions/reliability.js +170 -0
  30. package/bin/src/engine/browser/actions/types.d.ts +50 -0
  31. package/bin/src/engine/browser/actions/types.js +2 -0
  32. package/bin/src/engine/browser/browserController.d.ts +18 -0
  33. package/bin/src/engine/browser/browserController.js +44 -12
  34. package/bin/src/engine/browser/index.d.ts +2 -0
  35. package/bin/src/engine/browser/index.js +2 -0
  36. package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
  37. package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
  38. package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
  39. package/bin/src/engine/browser/observer/browserObserver.js +204 -0
  40. package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
  41. package/bin/src/engine/browser/observer/domExtractor.js +407 -0
  42. package/bin/src/engine/browser/observer/index.d.ts +5 -0
  43. package/bin/src/engine/browser/observer/index.js +5 -0
  44. package/bin/src/engine/browser/observer/types.d.ts +163 -0
  45. package/bin/src/engine/browser/observer/types.js +8 -0
  46. package/bin/src/engine/computer/computerController.d.ts +45 -2
  47. package/bin/src/engine/computer/computerController.js +178 -38
  48. package/bin/src/engine/computer/mockComputer.d.ts +7 -2
  49. package/bin/src/engine/computer/mockComputer.js +59 -1
  50. package/bin/src/engine/computer/scoutDriver.cs +310 -63
  51. package/bin/src/engine/llm.js +35 -15
  52. package/bin/src/engine/models/harpProvider.d.ts +32 -0
  53. package/bin/src/engine/models/harpProvider.js +172 -0
  54. package/bin/src/engine/models/index.d.ts +6 -0
  55. package/bin/src/engine/models/index.js +6 -0
  56. package/bin/src/engine/models/localModelProvider.d.ts +11 -0
  57. package/bin/src/engine/models/localModelProvider.js +48 -0
  58. package/bin/src/engine/models/openaiProvider.d.ts +11 -0
  59. package/bin/src/engine/models/openaiProvider.js +50 -0
  60. package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
  61. package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
  62. package/bin/src/engine/models/types.d.ts +63 -0
  63. package/bin/src/engine/models/types.js +2 -0
  64. package/bin/src/engine/production/index.d.ts +3 -0
  65. package/bin/src/engine/production/index.js +3 -0
  66. package/bin/src/engine/production/taskReplay.d.ts +37 -0
  67. package/bin/src/engine/production/taskReplay.js +81 -0
  68. package/bin/src/engine/production/telemetry.d.ts +43 -0
  69. package/bin/src/engine/production/telemetry.js +68 -0
  70. package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
  71. package/bin/src/engine/runtime/agentRuntime.js +33 -7
  72. package/bin/src/engine/safety/index.d.ts +3 -0
  73. package/bin/src/engine/safety/index.js +3 -0
  74. package/bin/src/engine/safety/policyEngine.d.ts +40 -0
  75. package/bin/src/engine/safety/policyEngine.js +282 -0
  76. package/bin/src/engine/safety/types.d.ts +24 -0
  77. package/bin/src/engine/safety/types.js +2 -0
  78. package/bin/src/engine/safety.d.ts +1 -0
  79. package/bin/src/engine/safety.js +1 -0
  80. package/bin/src/engine/toolRegistry.d.ts +4 -0
  81. package/bin/src/engine/toolRegistry.js +9 -0
  82. package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
  83. package/bin/src/engine/tools/domainHandlers.js +495 -0
  84. package/bin/src/engine/tools/index.d.ts +4 -0
  85. package/bin/src/engine/tools/index.js +4 -0
  86. package/bin/src/engine/tools/types.d.ts +56 -0
  87. package/bin/src/engine/tools/types.js +2 -0
  88. package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
  89. package/bin/src/engine/tools/unifiedRouter.js +426 -0
  90. package/bin/src/engine/workspace/agentWorkspace.js +4 -2
  91. package/bin/src/index.js +4 -4
  92. package/bin/src/mcp/client.js +1 -1
  93. package/bin/src/server/server.js +57 -18
  94. package/bin/src/utils/branding.js +1 -1
  95. package/bin/src/utils/claudeUI.d.ts +10 -1
  96. package/bin/src/utils/claudeUI.js +136 -6
  97. package/bin/src/utils/qrBridge.js +1 -1
  98. package/bin/src/utils/support.js +1 -1
  99. package/package.json +2 -2
@@ -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
@@ -0,0 +1,271 @@
1
+ import {} from '../../browser/observer/types.js';
2
+ import {} from '../../browser/actions/index.js';
3
+ import {} from './types.js';
4
+ export class RecoveryManager {
5
+ defaultMaxRetries;
6
+ baseBackoffMs;
7
+ maxBackoffMs;
8
+ constructor(options) {
9
+ this.defaultMaxRetries = options?.defaultMaxRetries || 3;
10
+ this.baseBackoffMs = options?.baseBackoffMs || 150;
11
+ this.maxBackoffMs = options?.maxBackoffMs || 2500;
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) {
18
+ const maxRetries = ctx.maxRetries || this.defaultMaxRetries;
19
+ const errLower = (ctx.error || '').toLowerCase();
20
+ const backoffDelayMs = this.computeBackoff(ctx.attempt);
21
+ // 1. Loop Breaking: If a loop is detected, break out of RETRY/RE_LOCATE immediately
22
+ if (ctx.loopDetection?.isLoop) {
23
+ const alternative = ctx.currentState
24
+ ? this.findSemanticAlternative(ctx.target || ctx.tool, ctx.currentState)
25
+ : undefined;
26
+ if (alternative) {
27
+ return {
28
+ strategy: 'SEMANTIC_ALTERNATIVE',
29
+ attempt: ctx.attempt,
30
+ maxRetriesExceeded: false,
31
+ reason: `Loop detected (${ctx.loopDetection.message}). Breaking loop by switching to semantic alternative: "${alternative}".`,
32
+ backoffDelayMs,
33
+ suggestedAlternativeTarget: alternative,
34
+ shouldHalt: false,
35
+ };
36
+ }
37
+ return {
38
+ strategy: 'REPORT_FAILURE',
39
+ attempt: ctx.attempt,
40
+ maxRetriesExceeded: true,
41
+ reason: `Halted: Action loop detected (${ctx.loopDetection.message}) and no semantic alternatives remain.`,
42
+ backoffDelayMs: 0,
43
+ shouldHalt: true,
44
+ };
45
+ }
46
+ // 2. Max Retries Exceeded: Escalate to REPORT_FAILURE
47
+ if (ctx.attempt >= maxRetries) {
48
+ return {
49
+ strategy: 'REPORT_FAILURE',
50
+ attempt: ctx.attempt,
51
+ maxRetriesExceeded: true,
52
+ reason: `Exceeded maximum retry limit (${ctx.attempt}/${maxRetries}) for action "${ctx.tool}". Halting task step.`,
53
+ backoffDelayMs: 0,
54
+ shouldHalt: true,
55
+ };
56
+ }
57
+ // 3. Browser Disconnected / Crash Detected
58
+ if (errLower.includes('disconnected') || errLower.includes('crash') || errLower.includes('closed target')) {
59
+ return {
60
+ strategy: 'RE_OBSERVE',
61
+ attempt: ctx.attempt,
62
+ maxRetriesExceeded: false,
63
+ reason: 'Browser session disconnected or unresponsive. Attempting session recovery and fresh observation.',
64
+ backoffDelayMs: Math.max(backoffDelayMs, 500),
65
+ shouldHalt: false,
66
+ };
67
+ }
68
+ // 4. Verification signaled strategy recommendation
69
+ if (ctx.verificationResult?.recommendedStrategy) {
70
+ const recommended = ctx.verificationResult.recommendedStrategy;
71
+ if (recommended === 'SEMANTIC_ALTERNATIVE') {
72
+ const alt = ctx.currentState && ctx.target
73
+ ? this.findSemanticAlternative(ctx.target, ctx.currentState)
74
+ : undefined;
75
+ return {
76
+ strategy: 'SEMANTIC_ALTERNATIVE',
77
+ attempt: ctx.attempt,
78
+ maxRetriesExceeded: false,
79
+ reason: `Verification flagged: ${ctx.verificationResult.details}. Trying semantic alternative.`,
80
+ backoffDelayMs,
81
+ suggestedAlternativeTarget: alt,
82
+ shouldHalt: false,
83
+ };
84
+ }
85
+ if (recommended === 'RE_LOCATE') {
86
+ return {
87
+ strategy: 'RE_LOCATE',
88
+ attempt: ctx.attempt,
89
+ maxRetriesExceeded: false,
90
+ reason: `Verification indicated element not found or stale: ${ctx.verificationResult.details}.`,
91
+ backoffDelayMs,
92
+ shouldHalt: false,
93
+ };
94
+ }
95
+ }
96
+ // 5. Strict Hierarchy Escalation by Attempt Count
97
+ // Attempt 1: RETRY (if transient) or RE_OBSERVE
98
+ if (ctx.attempt === 1) {
99
+ const isTransient = /timeout|network|busy|loading|pending|econnreset/i.test(errLower);
100
+ if (isTransient) {
101
+ return {
102
+ strategy: 'RETRY',
103
+ attempt: ctx.attempt,
104
+ maxRetriesExceeded: false,
105
+ reason: `Transient error encountered: "${ctx.error || 'timeout'}". Retrying with backoff.`,
106
+ backoffDelayMs,
107
+ shouldHalt: false,
108
+ };
109
+ }
110
+ return {
111
+ strategy: 'RE_OBSERVE',
112
+ attempt: ctx.attempt,
113
+ maxRetriesExceeded: false,
114
+ reason: `Initial attempt failed (${ctx.error || 'unverified state'}). Re-observing current DOM/accessibility tree.`,
115
+ backoffDelayMs,
116
+ shouldHalt: false,
117
+ };
118
+ }
119
+ // Attempt 2: RE_LOCATE
120
+ if (ctx.attempt === 2) {
121
+ return {
122
+ strategy: 'RE_LOCATE',
123
+ attempt: ctx.attempt,
124
+ maxRetriesExceeded: false,
125
+ reason: `Target element "${ctx.target || ctx.tool}" stale or not found. Re-locating target using semantic attributes.`,
126
+ backoffDelayMs,
127
+ shouldHalt: false,
128
+ };
129
+ }
130
+ // Attempt 3: SEMANTIC_ALTERNATIVE
131
+ if (ctx.attempt === 3) {
132
+ const alt = ctx.currentState && ctx.target
133
+ ? this.findSemanticAlternative(ctx.target, ctx.currentState)
134
+ : undefined;
135
+ return {
136
+ strategy: 'SEMANTIC_ALTERNATIVE',
137
+ attempt: ctx.attempt,
138
+ maxRetriesExceeded: false,
139
+ reason: `Direct action failed. Seeking semantic alternative control on page.`,
140
+ backoffDelayMs,
141
+ suggestedAlternativeTarget: alt,
142
+ shouldHalt: false,
143
+ };
144
+ }
145
+ // Attempt 4: VISUAL_FALLBACK
146
+ if (ctx.attempt === 4) {
147
+ return {
148
+ strategy: 'VISUAL_FALLBACK',
149
+ attempt: ctx.attempt,
150
+ maxRetriesExceeded: false,
151
+ reason: `Semantic resolution unsuccessful. Falling back to visual bounding box coordinates.`,
152
+ backoffDelayMs,
153
+ shouldHalt: false,
154
+ };
155
+ }
156
+ // Fallback default
157
+ return {
158
+ strategy: 'REPORT_FAILURE',
159
+ attempt: ctx.attempt,
160
+ maxRetriesExceeded: true,
161
+ reason: `Recovery hierarchy exhausted without successful state change: "${ctx.error}".`,
162
+ backoffDelayMs: 0,
163
+ shouldHalt: true,
164
+ };
165
+ }
166
+ /**
167
+ * Calculates exponential backoff with randomized jitter to prevent thundering herds.
168
+ */
169
+ computeBackoff(attempt, baseMs = this.baseBackoffMs, maxMs = this.maxBackoffMs) {
170
+ const raw = Math.min(baseMs * Math.pow(2, Math.max(0, attempt - 1)), maxMs);
171
+ const jitterMultiplier = 0.85 + Math.random() * 0.3; // 85% to 115%
172
+ return Math.floor(raw * jitterMultiplier);
173
+ }
174
+ /**
175
+ * Checks if task has exceeded maximum allotted execution time.
176
+ */
177
+ isTaskTimedOut(startTime, timeoutMs = 60000) {
178
+ return (Date.now() - startTime) >= timeoutMs;
179
+ }
180
+ /**
181
+ * Returns remaining task execution time in milliseconds.
182
+ */
183
+ getRemainingTimeMs(startTime, timeoutMs = 60000) {
184
+ return Math.max(0, timeoutMs - (Date.now() - startTime));
185
+ }
186
+ /**
187
+ * Recovers from browser session crashes or lost connections.
188
+ */
189
+ async handleBrowserCrash(actionEngine, lastKnownUrl) {
190
+ try {
191
+ const fallbackUrl = lastKnownUrl || 'https://github.com';
192
+ const activeTab = actionEngine.getActiveTab();
193
+ const targetUrl = (activeTab && activeTab.url && activeTab.url !== 'about:blank')
194
+ ? activeTab.url
195
+ : fallbackUrl;
196
+ if (!activeTab) {
197
+ // Respawn tab
198
+ await actionEngine.open_tab(targetUrl, '<html><head><title>Restored</title></head><body><h1>Restored</h1></body></html>');
199
+ return {
200
+ recovered: true,
201
+ message: `Browser crash recovered: New active tab created and restored to "${targetUrl}".`,
202
+ recoveredUrl: targetUrl,
203
+ };
204
+ }
205
+ // Tab exists; reload and restore to target URL
206
+ await actionEngine.navigate(targetUrl, '<html><head><title>Restored</title></head><body><h1>Restored</h1></body></html>');
207
+ return {
208
+ recovered: true,
209
+ message: `Browser session re-established at "${targetUrl}".`,
210
+ recoveredUrl: targetUrl,
211
+ };
212
+ }
213
+ catch (err) {
214
+ return {
215
+ recovered: false,
216
+ message: `Failed to recover browser session: ${err.message}`,
217
+ recoveredUrl: 'about:blank',
218
+ };
219
+ }
220
+ }
221
+ /**
222
+ * Finds semantic alternative elements when a target element is missing or fails.
223
+ */
224
+ findSemanticAlternative(target, state) {
225
+ const targetLower = target.toLowerCase();
226
+ // Synonym mappings for common UI intentions
227
+ const synonymGroups = [
228
+ ['submit', 'save', 'confirm', 'continue', 'proceed', 'next', 'ok', 'apply'],
229
+ ['actions', 'ci', 'workflows', 'runs', 'checks', 'builds'],
230
+ ['login', 'sign in', 'authenticate', 'continue with', 'log in'],
231
+ ['close', 'dismiss', 'cancel', 'exit', 'x'],
232
+ ['logs', 'view logs', 'details', 'raw log', 'console'],
233
+ ['search', 'find', 'filter', 'query'],
234
+ ];
235
+ let matchedGroup;
236
+ for (const group of synonymGroups) {
237
+ if (group.some(word => targetLower.includes(word))) {
238
+ matchedGroup = group;
239
+ break;
240
+ }
241
+ }
242
+ if (matchedGroup) {
243
+ for (const synonym of matchedGroup) {
244
+ if (targetLower.includes(synonym))
245
+ continue; // skip identical
246
+ const found = state.elements.find(el => {
247
+ const text = (el.text || '').toLowerCase();
248
+ const aria = (el.attributes['aria-label'] || '').toLowerCase();
249
+ return text.includes(synonym) || aria.includes(synonym);
250
+ });
251
+ if (found) {
252
+ return found.selector;
253
+ }
254
+ }
255
+ }
256
+ // Generic fallback: Look for actionable element sharing token
257
+ const tokens = targetLower.replace(/[^a-z0-9]/g, ' ').split(/\s+/).filter(t => t.length > 3);
258
+ for (const token of tokens) {
259
+ const found = state.elements.find(el => {
260
+ const text = (el.text || '').toLowerCase();
261
+ const isActionable = !el.state.disabled && (el.role === 'button' || el.role === 'link' || el.tagName === 'a' || el.tagName === 'button');
262
+ return text.includes(token) && isActionable;
263
+ });
264
+ if (found) {
265
+ return found.selector;
266
+ }
267
+ }
268
+ return undefined;
269
+ }
270
+ }
271
+ //# sourceMappingURL=recoveryManager.js.map
@@ -0,0 +1,48 @@
1
+ import { type BrowserState } from '../../browser/observer/types.js';
2
+ import { type StateChangeVerificationResult } from '../verification/types.js';
3
+ export type RecoveryStrategyStep = 'RETRY' | 'RE_OBSERVE' | 'RE_LOCATE' | 'SEMANTIC_ALTERNATIVE' | 'VISUAL_FALLBACK' | 'REPORT_FAILURE';
4
+ export type LoopType = 'repeated_action' | 'ping_pong' | 'cycle';
5
+ export interface LoopDetectionResult {
6
+ isLoop: boolean;
7
+ loopType?: LoopType | undefined;
8
+ repeatedCount?: number | undefined;
9
+ cycleLength?: number | undefined;
10
+ patternSummary?: string | undefined;
11
+ message?: string | undefined;
12
+ }
13
+ export interface ActionHistoryRecord {
14
+ step: number;
15
+ tool: string;
16
+ actionType: string;
17
+ args: Record<string, any>;
18
+ target?: string | undefined;
19
+ success: boolean;
20
+ url: string;
21
+ pageFingerprint?: string | undefined;
22
+ timestamp: number;
23
+ }
24
+ export interface RecoveryDecision {
25
+ strategy: RecoveryStrategyStep;
26
+ attempt: number;
27
+ maxRetriesExceeded: boolean;
28
+ reason: string;
29
+ backoffDelayMs: number;
30
+ suggestedAlternativeTarget?: string | undefined;
31
+ suggestedActionOverride?: {
32
+ tool: string;
33
+ args: Record<string, any>;
34
+ } | undefined;
35
+ shouldHalt: boolean;
36
+ }
37
+ export interface RecoveryContext {
38
+ tool: string;
39
+ actionType?: string | undefined;
40
+ target?: string | undefined;
41
+ error?: string | undefined;
42
+ attempt: number;
43
+ maxRetries?: number | undefined;
44
+ loopDetection?: LoopDetectionResult | undefined;
45
+ verificationResult?: StateChangeVerificationResult | undefined;
46
+ currentState?: BrowserState | undefined;
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,4 @@
1
+ import {} from '../../browser/observer/types.js';
2
+ import {} from '../computerUseLoop.js';
3
+ import {} from '../verification/types.js';
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './stateChangeVerifier.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './stateChangeVerifier.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ import { type BrowserState } from '../../browser/observer/types.js';
2
+ import { type ActionResult } from '../../browser/actions/types.js';
3
+ import { type PlannedAction } from '../computerUseLoop.js';
4
+ import { type StateChangeVerificationResult, type ExpectedStateChange } from './types.js';
5
+ export declare class StateChangeVerifier {
6
+ /**
7
+ * Verifies whether an expected state change occurred following an action.
8
+ * Core question: "Did the expected state change occur?"
9
+ */
10
+ verifyStateChange(params: {
11
+ actionResult: ActionResult;
12
+ plannedAction: PlannedAction;
13
+ beforeState?: BrowserState | Partial<BrowserState> | undefined;
14
+ afterState?: BrowserState | Partial<BrowserState> | undefined;
15
+ expected?: ExpectedStateChange | undefined;
16
+ }): StateChangeVerificationResult;
17
+ private extractErrorStrings;
18
+ private checkButtonActionOccurred;
19
+ private analyzeFormState;
20
+ private isSubmissionAction;
21
+ }
22
+ //# sourceMappingURL=stateChangeVerifier.d.ts.map