ft-scout 9.5.6 → 9.5.8
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/benchmark.d.ts +1 -1
- package/bin/src/commands/benchmark.js +4 -1
- package/bin/src/commands/replay.d.ts +6 -0
- package/bin/src/commands/replay.js +64 -0
- package/bin/src/engine/agentEngine.d.ts +2 -0
- package/bin/src/engine/agentEngine.js +409 -55
- package/bin/src/engine/browser/actions/actionEngine.js +1 -1
- package/bin/src/engine/browser/observer/browserObserver.js +1 -1
- package/bin/src/engine/checkpoints/checkpointManager.js +9 -0
- package/bin/src/engine/computer/computerController.d.ts +8 -2
- package/bin/src/engine/computer/computerController.js +172 -38
- package/bin/src/engine/computer/mockComputer.d.ts +1 -1
- package/bin/src/engine/computer/mockComputer.js +1 -1
- package/bin/src/engine/computer/scoutDriver.cs +310 -63
- package/bin/src/engine/llm.js +37 -17
- package/bin/src/engine/models/harpProvider.js +48 -0
- package/bin/src/engine/production/taskReplay.d.ts +24 -5
- package/bin/src/engine/production/taskReplay.js +158 -11
- package/bin/src/engine/runtime/agentRuntime.js +35 -7
- package/bin/src/engine/tools/domainHandlers.js +44 -7
- package/bin/src/engine/workspace/agentWorkspace.js +11 -2
- package/bin/src/index.js +17 -6
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/server/server.js +57 -18
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/claudeUI.d.ts +10 -1
- package/bin/src/utils/claudeUI.js +136 -6
- package/bin/src/utils/config.d.ts +9 -0
- package/bin/src/utils/config.js +39 -1
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/support.js +1 -1
- package/package.json +1 -1
|
@@ -24,19 +24,65 @@ import { getMCPManager } from '../mcp/index.js';
|
|
|
24
24
|
import { writeTelemetry } from '../utils/qrBridge.js';
|
|
25
25
|
import { compress, LEVEL_FAST } from 'codrop';
|
|
26
26
|
import { CheckpointManager } from './checkpoints/checkpointManager.js';
|
|
27
|
-
import {
|
|
27
|
+
import { defaultTaskReplayManager } from './production/index.js';
|
|
28
|
+
import { renderStepHeader, renderThoughtBox, renderToolCall, renderToolResult, renderTaskCompletedCard, ensureCompleteSentence, getActionFriendlyDescription, } from '../utils/claudeUI.js';
|
|
28
29
|
import { loadWorkspaceRules } from '../utils/rules.js';
|
|
29
30
|
import { InterruptManager } from '../utils/interruptHandler.js';
|
|
30
31
|
import { ComputerUseAgentLoop } from './agent/index.js';
|
|
31
32
|
export { AgentRuntime, AgentWorkspace, inferExecutionIntent, resolveDesktopPath, SystemComputerController, MockComputerController, ComputerUseAgentLoop };
|
|
32
33
|
const execAsync = promisify(exec);
|
|
34
|
+
function computeSimilarity(s1, s2) {
|
|
35
|
+
if (s1 === s2)
|
|
36
|
+
return 1.0;
|
|
37
|
+
if (!s1 || !s2)
|
|
38
|
+
return 0.0;
|
|
39
|
+
const longer = s1.length > s2.length ? s1 : s2;
|
|
40
|
+
const shorter = s1.length > s2.length ? s2 : s1;
|
|
41
|
+
if (longer.length === 0)
|
|
42
|
+
return 1.0;
|
|
43
|
+
const costs = [];
|
|
44
|
+
for (let i = 0; i <= shorter.length; i++)
|
|
45
|
+
costs[i] = i;
|
|
46
|
+
for (let i = 1; i <= longer.length; i++) {
|
|
47
|
+
costs[0] = i;
|
|
48
|
+
let nw = i - 1;
|
|
49
|
+
for (let j = 1; j <= shorter.length; j++) {
|
|
50
|
+
const cj = Math.min(1 + Math.min(costs[j], costs[j - 1]), longer[i - 1] === shorter[j - 1] ? nw : nw + 1);
|
|
51
|
+
nw = costs[j];
|
|
52
|
+
costs[j] = cj;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return (longer.length - costs[shorter.length]) / longer.length;
|
|
56
|
+
}
|
|
57
|
+
function adjustIndentation(replacement, matchedOrigBlock, matchedTargetLines) {
|
|
58
|
+
if (matchedOrigBlock.length === 0)
|
|
59
|
+
return replacement;
|
|
60
|
+
const origFirstIndent = matchedOrigBlock[0].match(/^(\s*)/)?.[1] || '';
|
|
61
|
+
const targetFirstIndent = matchedTargetLines[0]?.match(/^(\s*)/)?.[1] || '';
|
|
62
|
+
if (origFirstIndent !== targetFirstIndent) {
|
|
63
|
+
const replLines = replacement.split('\n');
|
|
64
|
+
return replLines.map((line) => {
|
|
65
|
+
if (!line.trim())
|
|
66
|
+
return line;
|
|
67
|
+
if (targetFirstIndent && line.startsWith(targetFirstIndent)) {
|
|
68
|
+
return origFirstIndent + line.slice(targetFirstIndent.length);
|
|
69
|
+
}
|
|
70
|
+
return origFirstIndent + line;
|
|
71
|
+
}).join('\n');
|
|
72
|
+
}
|
|
73
|
+
return replacement;
|
|
74
|
+
}
|
|
33
75
|
export function robustSnippetReplace(origContent, target, replacement) {
|
|
34
76
|
if (!origContent || !target) {
|
|
35
77
|
return { success: false, updatedContent: origContent, error: 'Target snippet or original content is empty.' };
|
|
36
78
|
}
|
|
79
|
+
const isCRLF = origContent.includes('\r\n');
|
|
37
80
|
const normOrig = origContent.replace(/\r\n/g, '\n');
|
|
38
81
|
const normTarget = target.replace(/\r\n/g, '\n');
|
|
39
82
|
const normReplacement = replacement.replace(/\r\n/g, '\n');
|
|
83
|
+
const finalize = (content) => {
|
|
84
|
+
return { success: true, updatedContent: isCRLF ? content.replace(/\n/g, '\r\n') : content };
|
|
85
|
+
};
|
|
40
86
|
// 1. Direct exact match
|
|
41
87
|
if (normOrig.includes(normTarget)) {
|
|
42
88
|
const occurrences = normOrig.split(normTarget).length - 1;
|
|
@@ -47,12 +93,20 @@ export function robustSnippetReplace(origContent, target, replacement) {
|
|
|
47
93
|
error: `Target snippet occurs ${occurrences} times. Please include more surrounding code lines in target to make it unique.`
|
|
48
94
|
};
|
|
49
95
|
}
|
|
50
|
-
return
|
|
96
|
+
return finalize(normOrig.replace(normTarget, () => normReplacement));
|
|
97
|
+
}
|
|
98
|
+
// 2. Trimmed leading/trailing newlines in target
|
|
99
|
+
const trimmedTarget = normTarget.replace(/^\n+|\n+$/g, '');
|
|
100
|
+
if (trimmedTarget && trimmedTarget !== normTarget && normOrig.includes(trimmedTarget)) {
|
|
101
|
+
const occurrences = normOrig.split(trimmedTarget).length - 1;
|
|
102
|
+
if (occurrences === 1) {
|
|
103
|
+
return finalize(normOrig.replace(trimmedTarget, () => normReplacement.replace(/^\n+|\n+$/g, '')));
|
|
104
|
+
}
|
|
51
105
|
}
|
|
52
|
-
// 2. Trailing whitespace normalized match
|
|
53
106
|
const origLines = normOrig.split('\n');
|
|
54
107
|
const targetLines = normTarget.split('\n');
|
|
55
108
|
const targetLen = targetLines.length;
|
|
109
|
+
// 3. Trailing whitespace normalized match
|
|
56
110
|
const strippedTarget = targetLines.map((l) => l.trimEnd()).join('\n');
|
|
57
111
|
const matches = [];
|
|
58
112
|
for (let i = 0; i <= origLines.length - targetLen; i++) {
|
|
@@ -66,7 +120,7 @@ export function robustSnippetReplace(origContent, target, replacement) {
|
|
|
66
120
|
const before = origLines.slice(0, idx);
|
|
67
121
|
const after = origLines.slice(idx + targetLen);
|
|
68
122
|
const updatedContent = [...before, normReplacement, ...after].join('\n');
|
|
69
|
-
return
|
|
123
|
+
return finalize(updatedContent);
|
|
70
124
|
}
|
|
71
125
|
if (matches.length > 1) {
|
|
72
126
|
return {
|
|
@@ -75,34 +129,37 @@ export function robustSnippetReplace(origContent, target, replacement) {
|
|
|
75
129
|
error: `Target snippet matched ${matches.length} locations when ignoring trailing spaces. Please provide more surrounding code lines in target.`
|
|
76
130
|
};
|
|
77
131
|
}
|
|
78
|
-
//
|
|
79
|
-
const trimmedTargetLines = targetLines.map((l) => l.trim())
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (windowLines.join('\n') === trimmedTargetStr) {
|
|
86
|
-
trimMatches.push(i);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (trimMatches.length === 1) {
|
|
90
|
-
const idx = trimMatches[0];
|
|
91
|
-
const before = origLines.slice(0, idx);
|
|
92
|
-
const after = origLines.slice(idx + targetLen);
|
|
93
|
-
const updatedContent = [...before, normReplacement, ...after].join('\n');
|
|
94
|
-
return { success: true, updatedContent };
|
|
132
|
+
// 4. Fully trimmed lines match with indentation adjustment (handles indentation differences)
|
|
133
|
+
const trimmedTargetLines = targetLines.map((l) => l.trim());
|
|
134
|
+
const trimMatches = [];
|
|
135
|
+
for (let i = 0; i <= origLines.length - targetLen; i++) {
|
|
136
|
+
const windowLines = origLines.slice(i, i + targetLen).map((l) => l.trim());
|
|
137
|
+
if (windowLines.join('\n') === trimmedTargetLines.join('\n')) {
|
|
138
|
+
trimMatches.push(i);
|
|
95
139
|
}
|
|
96
140
|
}
|
|
97
|
-
|
|
98
|
-
|
|
141
|
+
if (trimMatches.length === 1) {
|
|
142
|
+
const idx = trimMatches[0];
|
|
143
|
+
const before = origLines.slice(0, idx);
|
|
144
|
+
const after = origLines.slice(idx + targetLen);
|
|
145
|
+
const matchedOrigBlock = origLines.slice(idx, idx + targetLen);
|
|
146
|
+
const adjustedRepl = adjustIndentation(normReplacement, matchedOrigBlock, targetLines);
|
|
147
|
+
const updatedContent = [...before, adjustedRepl, ...after].join('\n');
|
|
148
|
+
return finalize(updatedContent);
|
|
149
|
+
}
|
|
150
|
+
// 5. Non-blank lines window match (handles variable blank lines in target snippet)
|
|
151
|
+
const nonBlankTargetLines = targetLines.filter((l) => l.trim().length > 0).map((l) => l.trim());
|
|
99
152
|
if (nonBlankTargetLines.length > 0) {
|
|
100
|
-
const nonBlankTargetStr = nonBlankTargetLines.
|
|
153
|
+
const nonBlankTargetStr = nonBlankTargetLines.join('\n');
|
|
101
154
|
const fuzzyMatches = [];
|
|
102
155
|
for (let i = 0; i < origLines.length; i++) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
156
|
+
if (origLines[i].trim().length === 0)
|
|
157
|
+
continue;
|
|
158
|
+
for (let j = i + 1; j <= Math.min(origLines.length, i + targetLen + 8); j++) {
|
|
159
|
+
if (origLines[j - 1].trim().length === 0)
|
|
160
|
+
continue;
|
|
161
|
+
const windowLines = origLines.slice(i, j).filter((l) => l.trim().length > 0).map((l) => l.trim());
|
|
162
|
+
if (windowLines.join('\n') === nonBlankTargetStr) {
|
|
106
163
|
fuzzyMatches.push({ startIdx: i, endIdx: j });
|
|
107
164
|
break;
|
|
108
165
|
}
|
|
@@ -112,14 +169,99 @@ export function robustSnippetReplace(origContent, target, replacement) {
|
|
|
112
169
|
const { startIdx, endIdx } = fuzzyMatches[0];
|
|
113
170
|
const before = origLines.slice(0, startIdx);
|
|
114
171
|
const after = origLines.slice(endIdx);
|
|
115
|
-
const
|
|
116
|
-
|
|
172
|
+
const matchedOrigBlock = origLines.slice(startIdx, endIdx);
|
|
173
|
+
const adjustedRepl = adjustIndentation(normReplacement, matchedOrigBlock, targetLines);
|
|
174
|
+
const updatedContent = [...before, adjustedRepl, ...after].join('\n');
|
|
175
|
+
return finalize(updatedContent);
|
|
117
176
|
}
|
|
118
177
|
}
|
|
178
|
+
// 6. Single-line substring or line-level match
|
|
179
|
+
if (targetLen === 1) {
|
|
180
|
+
const trimmedSingleTarget = normTarget.trim();
|
|
181
|
+
const singleLineExactMatches = [];
|
|
182
|
+
for (let i = 0; i < origLines.length; i++) {
|
|
183
|
+
if (origLines[i].trim() === trimmedSingleTarget) {
|
|
184
|
+
singleLineExactMatches.push(i);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (singleLineExactMatches.length === 1) {
|
|
188
|
+
const idx = singleLineExactMatches[0];
|
|
189
|
+
const origIndent = origLines[idx].match(/^(\s*)/)?.[1] || '';
|
|
190
|
+
const replLines = normReplacement.split('\n').map((l) => (l.trim() ? origIndent + l.trim() : l)).join('\n');
|
|
191
|
+
const before = origLines.slice(0, idx);
|
|
192
|
+
const after = origLines.slice(idx + 1);
|
|
193
|
+
return finalize([...before, replLines, ...after].join('\n'));
|
|
194
|
+
}
|
|
195
|
+
// Substring inside a single line
|
|
196
|
+
const lineContainsMatches = [];
|
|
197
|
+
for (let i = 0; i < origLines.length; i++) {
|
|
198
|
+
if (origLines[i].includes(trimmedSingleTarget)) {
|
|
199
|
+
lineContainsMatches.push(i);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (lineContainsMatches.length === 1) {
|
|
203
|
+
const idx = lineContainsMatches[0];
|
|
204
|
+
const updatedLine = origLines[idx].replace(trimmedSingleTarget, normReplacement.trim());
|
|
205
|
+
const before = origLines.slice(0, idx);
|
|
206
|
+
const after = origLines.slice(idx + 1);
|
|
207
|
+
return finalize([...before, updatedLine, ...after].join('\n'));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 7. Quote & punctuation relaxed matching
|
|
211
|
+
const normalizePunctuation = (str) => str.replace(/['"`]/g, '"').replace(/[;,]$/gm, '').trim();
|
|
212
|
+
const relaxedTarget = normalizePunctuation(normTarget);
|
|
213
|
+
if (relaxedTarget) {
|
|
214
|
+
const relaxedMatches = [];
|
|
215
|
+
for (let i = 0; i <= origLines.length - targetLen; i++) {
|
|
216
|
+
const windowStr = normalizePunctuation(origLines.slice(i, i + targetLen).join('\n'));
|
|
217
|
+
if (windowStr === relaxedTarget) {
|
|
218
|
+
relaxedMatches.push({ startIdx: i, endIdx: i + targetLen });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (relaxedMatches.length === 1) {
|
|
222
|
+
const { startIdx, endIdx } = relaxedMatches[0];
|
|
223
|
+
const before = origLines.slice(0, startIdx);
|
|
224
|
+
const after = origLines.slice(endIdx);
|
|
225
|
+
const matchedOrigBlock = origLines.slice(startIdx, endIdx);
|
|
226
|
+
const adjustedRepl = adjustIndentation(normReplacement, matchedOrigBlock, targetLines);
|
|
227
|
+
return finalize([...before, adjustedRepl, ...after].join('\n'));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// 8. High-confidence fuzzy similarity matching (>= 88% similarity)
|
|
231
|
+
let bestSim = 0;
|
|
232
|
+
let bestRange = null;
|
|
233
|
+
let secondBestSim = 0;
|
|
234
|
+
const targetClean = targetLines.map((l) => l.trim()).filter(Boolean).join('\n');
|
|
235
|
+
for (let i = 0; i <= origLines.length - Math.max(1, targetLen - 2); i++) {
|
|
236
|
+
for (let len = Math.max(1, targetLen - 2); len <= Math.min(origLines.length - i, targetLen + 2); len++) {
|
|
237
|
+
const windowClean = origLines.slice(i, i + len).map((l) => l.trim()).filter(Boolean).join('\n');
|
|
238
|
+
const sim = computeSimilarity(windowClean, targetClean);
|
|
239
|
+
if (sim > bestSim) {
|
|
240
|
+
secondBestSim = bestSim;
|
|
241
|
+
bestSim = sim;
|
|
242
|
+
bestRange = { startIdx: i, endIdx: i + len };
|
|
243
|
+
}
|
|
244
|
+
else if (sim > secondBestSim) {
|
|
245
|
+
secondBestSim = sim;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (bestSim >= 0.88 && secondBestSim < 0.70 && bestRange) {
|
|
250
|
+
const before = origLines.slice(0, bestRange.startIdx);
|
|
251
|
+
const after = origLines.slice(bestRange.endIdx);
|
|
252
|
+
const matchedOrigBlock = origLines.slice(bestRange.startIdx, bestRange.endIdx);
|
|
253
|
+
const adjustedRepl = adjustIndentation(normReplacement, matchedOrigBlock, targetLines);
|
|
254
|
+
return finalize([...before, adjustedRepl, ...after].join('\n'));
|
|
255
|
+
}
|
|
256
|
+
// 9. Informative error message with closest line indicator
|
|
257
|
+
let closestMsg = '';
|
|
258
|
+
if (bestRange && bestSim >= 0.40) {
|
|
259
|
+
closestMsg = ` (Closest match found near line ${bestRange.startIdx + 1} with ${(bestSim * 100).toFixed(0)}% similarity).`;
|
|
260
|
+
}
|
|
119
261
|
return {
|
|
120
262
|
success: false,
|
|
121
263
|
updatedContent: origContent,
|
|
122
|
-
error: `Target snippet not found in file
|
|
264
|
+
error: `Target snippet not found in file${closestMsg} Hint: Use read_file to view current lines and copy the exact snippet, or use write_file with complete file content.`
|
|
123
265
|
};
|
|
124
266
|
}
|
|
125
267
|
export const AGENT_TOOLS = [
|
|
@@ -681,7 +823,7 @@ CORE ARCHITECTURAL PRINCIPLES:
|
|
|
681
823
|
NEVER output a vacuous meta-summary like "Task completed" or "Looked up account" without providing the actual information the user asked for!
|
|
682
824
|
- For coding/modification tasks: Detail what was changed, created, and tested.
|
|
683
825
|
- CONVERSATIONAL CO-PILOT TONE: In your 'summary' parameter for task_completed, speak directly and warmly to the developer like an elite human co-pilot (e.g. "Here are your GitHub account details: your username is ..."). Never output dry mechanical robot logs or third-person phrases like "Objective achieved with 1 tool call". Talk directly to the user!
|
|
684
|
-
10. THOUGHT TRANSPARENCY PROTOCOL: In EVERY step before calling any tools or ending a turn, you MUST provide a clear 1-2 sentence explanation in your text response describing your current reasoning, what
|
|
826
|
+
10. THOUGHT TRANSPARENCY PROTOCOL: In EVERY step before calling any tools or ending a turn, you MUST provide a clear, grammatically complete 1-2 sentence explanation in your text response describing your current reasoning, what specific action you are taking, and why. Always finish every sentence completely with proper terminal punctuation (period, question mark, or exclamation mark) before outputting tool calls. NEVER leave a sentence half-written, hanging, or ending on a preposition or conjunction like "to", "and", "by", or "using".
|
|
685
827
|
11. APPLICATION LAUNCH & SIMPLE ACTION TERMINATION: When the user's objective is simply to open, launch, close, or focus an application (e.g. "Open Chrome", "Launch Notepad", "Open Calculator"): Immediately after calling computer_open_app or computer_close_app, your goal is 100% complete! You MUST call task_completed on the very next step with your friendly conversational summary. NEVER explore the repository or call list_dir, read_file, grep_search, or edit_file for app launching tasks!
|
|
686
828
|
12. STRICT ACTIVE GOAL ISOLATION & ACCURACY:
|
|
687
829
|
- You must strictly execute ONLY the current active goal provided in the user prompt.
|
|
@@ -703,6 +845,11 @@ CORE ARCHITECTURAL PRINCIPLES:
|
|
|
703
845
|
* Primitives: bpy.ops.mesh.primitive_uv_sphere_add, primitive_cylinder_add, primitive_cube_add
|
|
704
846
|
- Apply cel-shading or toon materials with vibrant anime colors matching the request (e.g. Genshin Impact aesthetic).
|
|
705
847
|
- Position camera and lighting. Immediately after your Blender script creates the 3D model (or after a single quick verification step), you MUST call task_completed with a complete description of the created 3D character and mesh hierarchy. Do NOT run unnecessary repeated polling turns.
|
|
848
|
+
15. DO NOT CLOSE USER APPLICATIONS UNLESS EXPLICITLY COMMANDED:
|
|
849
|
+
When the user asks to open, create, write, or interact with an application (e.g. "open notepad and write X", "launch Chrome and search Y"):
|
|
850
|
+
NEVER close or kill the application!
|
|
851
|
+
Keep the application open on the user's screen so they can review, edit, or save the document.
|
|
852
|
+
ONLY call computer_close_app if the user explicitly commanded "close <app>", "exit <app>", or "kill <app>".
|
|
706
853
|
|
|
707
854
|
When returning tool calls, use standard OpenAI function calling format or JSON tool call payload format:
|
|
708
855
|
\`\`\`json
|
|
@@ -719,6 +866,8 @@ When returning tool calls, use standard OpenAI function calling format or JSON t
|
|
|
719
866
|
this.taskStateManager.createTaskState(userGoal);
|
|
720
867
|
this.executionIntent = inferExecutionIntent(userGoal);
|
|
721
868
|
this.taskStateManager.setObjective(userGoal);
|
|
869
|
+
const activeTaskId = this.taskStateManager.getCurrentState().taskId;
|
|
870
|
+
defaultTaskReplayManager.startTrace(activeTaskId, userGoal, { cwd: this.cwd, tier: this.userTier });
|
|
722
871
|
this.syncTelemetry('running', `scout: autonomous execution started for "${userGoal.slice(0, 55)}"`);
|
|
723
872
|
if (this.computerController.setExpectedApplication && this.executionIntent.requiredApplications.length > 0) {
|
|
724
873
|
this.computerController.setExpectedApplication(this.executionIntent.requiredApplications[0] ?? null);
|
|
@@ -1039,6 +1188,16 @@ When returning tool calls, use standard OpenAI function calling format or JSON t
|
|
|
1039
1188
|
}
|
|
1040
1189
|
}
|
|
1041
1190
|
}
|
|
1191
|
+
if (needsBrowser) {
|
|
1192
|
+
const browserTools = this.toolRegistry.getAllTools().filter((t) => t.name.startsWith('browser_'));
|
|
1193
|
+
const existingNames = new Set(baseTools.map((t) => t.name));
|
|
1194
|
+
for (const bt of browserTools) {
|
|
1195
|
+
if (!existingNames.has(bt.name)) {
|
|
1196
|
+
baseTools.push(bt);
|
|
1197
|
+
existingNames.add(bt.name);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1042
1201
|
if (mcpRouting.tools.length > 0 && !needsBrowser && !needsComputer) {
|
|
1043
1202
|
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']);
|
|
1044
1203
|
baseTools = baseTools.filter((t) => ESSENTIAL_BASE_TOOLS.has(t.name));
|
|
@@ -1090,6 +1249,7 @@ When returning tool calls, use standard OpenAI function calling format or JSON t
|
|
|
1090
1249
|
temperature: 0.1,
|
|
1091
1250
|
presence_penalty: 0.1,
|
|
1092
1251
|
frequency_penalty: 0.1,
|
|
1252
|
+
max_tokens: 4096,
|
|
1093
1253
|
});
|
|
1094
1254
|
});
|
|
1095
1255
|
}
|
|
@@ -1116,6 +1276,7 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1116
1276
|
temperature: 0.1,
|
|
1117
1277
|
presence_penalty: 0.1,
|
|
1118
1278
|
frequency_penalty: 0.1,
|
|
1279
|
+
max_tokens: 4096,
|
|
1119
1280
|
});
|
|
1120
1281
|
});
|
|
1121
1282
|
}
|
|
@@ -1135,8 +1296,27 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1135
1296
|
this.historyMessages.push(msg);
|
|
1136
1297
|
// Render assistant's thought reasoning text if provided on this turn
|
|
1137
1298
|
const textContent = msg.content || '';
|
|
1138
|
-
|
|
1139
|
-
|
|
1299
|
+
const inferredToolCall = !msg.tool_calls || msg.tool_calls.length === 0 ? this.extractJsonToolCall(textContent) : null;
|
|
1300
|
+
const toolCallsList = (msg.tool_calls && msg.tool_calls.length > 0)
|
|
1301
|
+
? msg.tool_calls
|
|
1302
|
+
: (inferredToolCall ? [{ tool: inferredToolCall.tool, args: inferredToolCall.args }] : []);
|
|
1303
|
+
const cleanReasoning = this.extractCleanReasoning(msg, choice, toolCallsList);
|
|
1304
|
+
if (cleanReasoning.trim()) {
|
|
1305
|
+
let fallbackDesc;
|
|
1306
|
+
const firstTc = msg.tool_calls?.[0];
|
|
1307
|
+
if (firstTc?.function?.name) {
|
|
1308
|
+
try {
|
|
1309
|
+
const parsedArgs = JSON.parse(firstTc.function.arguments || '{}');
|
|
1310
|
+
fallbackDesc = getActionFriendlyDescription(firstTc.function.name, parsedArgs);
|
|
1311
|
+
}
|
|
1312
|
+
catch {
|
|
1313
|
+
fallbackDesc = getActionFriendlyDescription(firstTc.function.name, {});
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
else if (inferredToolCall?.tool) {
|
|
1317
|
+
fallbackDesc = getActionFriendlyDescription(inferredToolCall.tool, inferredToolCall.args || {});
|
|
1318
|
+
}
|
|
1319
|
+
renderThoughtBox(cleanReasoning, step, fallbackDesc);
|
|
1140
1320
|
}
|
|
1141
1321
|
// Check native tool calls
|
|
1142
1322
|
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
@@ -1316,13 +1496,6 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1316
1496
|
continue;
|
|
1317
1497
|
}
|
|
1318
1498
|
if (textContent.trim()) {
|
|
1319
|
-
let cleanedThought = textContent
|
|
1320
|
-
.replace(/[\u0600-\u06FF\u0750-\u077F\uAC00-\uD7AF\u3040-\u30FF\u4E00-\u9FFF\u0D80-\u0DFF]+/g, '')
|
|
1321
|
-
.trim();
|
|
1322
|
-
if (!cleanedThought || cleanedThought.length < 5) {
|
|
1323
|
-
cleanedThought = 'Analyzing codebase files and executing next tool operation...';
|
|
1324
|
-
}
|
|
1325
|
-
safeNote(renderMarkdown(cleanedThought), ` Scout Agent Thought (Step ${step})`);
|
|
1326
1499
|
const lowerText = textContent.toLowerCase().trim();
|
|
1327
1500
|
const isExplicitCompletion = lowerText.includes('task is complete') ||
|
|
1328
1501
|
lowerText.includes('task complete') ||
|
|
@@ -1398,6 +1571,12 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1398
1571
|
}
|
|
1399
1572
|
finally {
|
|
1400
1573
|
interruptManager.detach();
|
|
1574
|
+
try {
|
|
1575
|
+
const currentStatus = this.taskStateManager.getCurrentState().status;
|
|
1576
|
+
const activeTaskId = this.taskStateManager.getCurrentState().taskId;
|
|
1577
|
+
defaultTaskReplayManager.finalizeTrace(activeTaskId, currentStatus === 'completed' ? 'completed' : 'failed');
|
|
1578
|
+
}
|
|
1579
|
+
catch { }
|
|
1401
1580
|
}
|
|
1402
1581
|
}
|
|
1403
1582
|
extractJsonToolCall(content) {
|
|
@@ -1448,7 +1627,70 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1448
1627
|
}
|
|
1449
1628
|
return null;
|
|
1450
1629
|
}
|
|
1630
|
+
extractCleanReasoning(msg, rawChoice, toolCalls) {
|
|
1631
|
+
const rawMsg = rawChoice?.message || msg || {};
|
|
1632
|
+
const rawReasoning = rawMsg.reasoning_content || rawMsg.thinking || rawMsg.thought || msg?.reasoning_content || '';
|
|
1633
|
+
let candidate = '';
|
|
1634
|
+
// Check for <think>...</think> blocks in msg.content or rawReasoning
|
|
1635
|
+
const combined = `${rawReasoning}\n${msg?.content || ''}`.trim();
|
|
1636
|
+
const thinkMatch = combined.match(/<think>([\s\S]*?)<\/think>/i);
|
|
1637
|
+
if (thinkMatch && thinkMatch[1] && thinkMatch[1].trim().length > 0) {
|
|
1638
|
+
candidate = thinkMatch[1].trim();
|
|
1639
|
+
}
|
|
1640
|
+
else if (rawReasoning && typeof rawReasoning === 'string' && rawReasoning.trim().length > 0) {
|
|
1641
|
+
candidate = rawReasoning.trim();
|
|
1642
|
+
}
|
|
1643
|
+
else if (typeof msg?.content === 'string' && msg.content.trim().length > 0) {
|
|
1644
|
+
candidate = msg.content.trim();
|
|
1645
|
+
}
|
|
1646
|
+
const firstCall = (toolCalls && toolCalls.length > 0) ? toolCalls[0] : null;
|
|
1647
|
+
let fallbackDesc;
|
|
1648
|
+
if (firstCall) {
|
|
1649
|
+
const fnName = firstCall.function?.name || firstCall.tool || '';
|
|
1650
|
+
let callArgs = {};
|
|
1651
|
+
try {
|
|
1652
|
+
callArgs = typeof firstCall.function?.arguments === 'string'
|
|
1653
|
+
? JSON.parse(firstCall.function.arguments)
|
|
1654
|
+
: (firstCall.args || {});
|
|
1655
|
+
}
|
|
1656
|
+
catch { }
|
|
1657
|
+
fallbackDesc = getActionFriendlyDescription(fnName, callArgs);
|
|
1658
|
+
}
|
|
1659
|
+
return ensureCompleteSentence(candidate, fallbackDesc);
|
|
1660
|
+
}
|
|
1451
1661
|
async dispatchToolCall(name, args) {
|
|
1662
|
+
const toolStartTime = Date.now();
|
|
1663
|
+
const taskId = this.taskStateManager.getCurrentState().taskId;
|
|
1664
|
+
try {
|
|
1665
|
+
const res = await this.executeToolCallInternal(name, args);
|
|
1666
|
+
const durationMs = Date.now() - toolStartTime;
|
|
1667
|
+
defaultTaskReplayManager.recordStep(taskId, {
|
|
1668
|
+
stepIndex: this.currentStep,
|
|
1669
|
+
action: name,
|
|
1670
|
+
tool: name,
|
|
1671
|
+
args,
|
|
1672
|
+
result: res.result,
|
|
1673
|
+
success: !res.result.startsWith('Error:'),
|
|
1674
|
+
durationMs,
|
|
1675
|
+
});
|
|
1676
|
+
return res;
|
|
1677
|
+
}
|
|
1678
|
+
catch (err) {
|
|
1679
|
+
const durationMs = Date.now() - toolStartTime;
|
|
1680
|
+
defaultTaskReplayManager.recordStep(taskId, {
|
|
1681
|
+
stepIndex: this.currentStep,
|
|
1682
|
+
action: name,
|
|
1683
|
+
tool: name,
|
|
1684
|
+
args,
|
|
1685
|
+
result: null,
|
|
1686
|
+
error: err?.message || String(err),
|
|
1687
|
+
success: false,
|
|
1688
|
+
durationMs,
|
|
1689
|
+
});
|
|
1690
|
+
throw err;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
async executeToolCallInternal(name, args) {
|
|
1452
1694
|
this.totalToolCalls++;
|
|
1453
1695
|
let actionDesc = '';
|
|
1454
1696
|
if (name === 'read_file')
|
|
@@ -1562,9 +1804,25 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1562
1804
|
return { result: currentScratch ? `Scratchpad Contents:\n${currentScratch}` : `Scratchpad is currently empty.` };
|
|
1563
1805
|
}
|
|
1564
1806
|
}
|
|
1807
|
+
const isBasicWindowTool = [
|
|
1808
|
+
'computer_open_app',
|
|
1809
|
+
'computer_close_app',
|
|
1810
|
+
'computer_screenshot',
|
|
1811
|
+
'computer_inspect_ui',
|
|
1812
|
+
'computer_switch_window',
|
|
1813
|
+
'computer_type',
|
|
1814
|
+
'computer_click',
|
|
1815
|
+
'computer_double_click',
|
|
1816
|
+
'computer_right_click',
|
|
1817
|
+
'computer_key_press',
|
|
1818
|
+
'computer_hotkey',
|
|
1819
|
+
'computer_wait',
|
|
1820
|
+
'browser_screenshot',
|
|
1821
|
+
'browser_inspect',
|
|
1822
|
+
].includes(name);
|
|
1565
1823
|
// 2. Autonomous Computer & Browser Automation Gating (Pro & Enterprise only)
|
|
1566
1824
|
if (name === 'computer' || name.startsWith('computer_') || name.startsWith('browser_')) {
|
|
1567
|
-
if (!isPaid) {
|
|
1825
|
+
if (!isPaid && !isBasicWindowTool) {
|
|
1568
1826
|
const blockedMsg = `[PLAN RESTRICTION: PRO / ENTERPRISE ONLY] Autonomous Computer-Use & Browser Automation features are exclusive to Pro and Enterprise tiers. Free tier developers can perform basic code editing (edit_file), creating files and folders (write_file), and running commands (run_command) in the workspace. Upgrade to Pro at https://scout.frontterrain.com/plans or run 'scout dashboard'.`;
|
|
1569
1827
|
console.log(chalk.red.bold(`\n⛔ ${blockedMsg}`));
|
|
1570
1828
|
this.taskStateManager.addObservation(name, blockedMsg, false);
|
|
@@ -1689,12 +1947,12 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1689
1947
|
}
|
|
1690
1948
|
// Tier Gating Enforcement
|
|
1691
1949
|
if (!isPaid) {
|
|
1692
|
-
if (name.startsWith('computer_') || name === 'computer') {
|
|
1950
|
+
if ((name.startsWith('computer_') || name === 'computer') && !isBasicWindowTool) {
|
|
1693
1951
|
const upgradeMsg = `[PLAN RESTRICTION]: Autonomous Computer Control tools (${name}) are exclusively available to Pro and Enterprise plan developers. Free tier developers can perform code editing, creating files/folders, and running terminal commands. Upgrade to Pro at https://scout.frontterrain.com to unlock autonomous computer & app control.`;
|
|
1694
1952
|
this.taskStateManager.addObservation(name, upgradeMsg, false);
|
|
1695
1953
|
return { result: upgradeMsg };
|
|
1696
1954
|
}
|
|
1697
|
-
if (name.startsWith('browser_')) {
|
|
1955
|
+
if (name.startsWith('browser_') && !isBasicWindowTool) {
|
|
1698
1956
|
const upgradeMsg = `[PLAN RESTRICTION]: Autonomous Browser Control tools (${name}) are exclusively available to Pro and Enterprise plan developers. Free tier developers can perform code editing, creating files/folders, and running terminal commands. Upgrade to Pro at https://scout.frontterrain.com to unlock browser automation.`;
|
|
1699
1957
|
this.taskStateManager.addObservation(name, upgradeMsg, false);
|
|
1700
1958
|
return { result: upgradeMsg };
|
|
@@ -1716,7 +1974,9 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1716
1974
|
const fullPath = path.isAbsolute(targetPath) ? targetPath : path.resolve(this.cwd, targetPath);
|
|
1717
1975
|
const relPath = path.relative(this.cwd, fullPath).replace(/\\/g, '/');
|
|
1718
1976
|
const normKey = relPath.toLowerCase();
|
|
1719
|
-
|
|
1977
|
+
const isRangeRead = Boolean(args.startLine || args.endLine);
|
|
1978
|
+
const wasModified = this.modifiedFiles.has(targetPath) || this.modifiedFiles.has(relPath) || this.modifiedFiles.has(normKey);
|
|
1979
|
+
if (!isRangeRead && !wasModified && (this.readFilesHistory.has(normKey) || this.readFilesHistory.has(targetPath.toLowerCase()))) {
|
|
1720
1980
|
const readSpin = spinner();
|
|
1721
1981
|
readSpin.stop(chalk.yellow(` Skipped duplicate read for ${targetPath} (already in context)`));
|
|
1722
1982
|
return {
|
|
@@ -1774,6 +2034,9 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1774
2034
|
catch { }
|
|
1775
2035
|
fs.writeFileSync(fullPath, content, 'utf-8');
|
|
1776
2036
|
this.modifiedFiles.add(targetPath);
|
|
2037
|
+
const relPWrite = path.relative(this.cwd, fullPath).replace(/\\/g, '/').toLowerCase();
|
|
2038
|
+
this.readFilesHistory.delete(relPWrite);
|
|
2039
|
+
this.readFilesHistory.delete(targetPath.toLowerCase());
|
|
1777
2040
|
const oldLineCount = origContent !== '__FT_WAS_NEW__' ? origContent.split('\n').length : 0;
|
|
1778
2041
|
const newLineCount = content.split('\n').length;
|
|
1779
2042
|
const numberOfLinesChanged = origContent === '__FT_WAS_NEW__' ? newLineCount : Math.abs(newLineCount - oldLineCount) || newLineCount;
|
|
@@ -1803,9 +2066,9 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1803
2066
|
return { result: `Successfully wrote ${content.length} characters (${numberOfLinesChanged} lines changed) to "${targetPath}". Rationale: ${reason}. Syntax check passed cleanly.` };
|
|
1804
2067
|
}
|
|
1805
2068
|
case 'edit_file': {
|
|
1806
|
-
const targetPath = String(args.path || '').trim();
|
|
1807
|
-
let target = String(args.target
|
|
1808
|
-
let replacement = String(args.replacement
|
|
2069
|
+
const targetPath = String(args.path || args.filePath || args.file || '').trim();
|
|
2070
|
+
let target = String(args.target ?? args.old_string ?? args.old_str ?? args.oldText ?? args.find ?? args.search ?? '');
|
|
2071
|
+
let replacement = String(args.replacement ?? args.new_string ?? args.new_str ?? args.newText ?? args.replace ?? '');
|
|
1809
2072
|
const reason = String(args.reason || args.why || args.description || 'Replaced target code snippet with updated implementation.');
|
|
1810
2073
|
if (replacement.includes('\\n') && !replacement.includes('\n')) {
|
|
1811
2074
|
replacement = replacement.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
@@ -1833,6 +2096,9 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1833
2096
|
catch { }
|
|
1834
2097
|
fs.writeFileSync(fullPath, replaceRes.updatedContent, 'utf-8');
|
|
1835
2098
|
this.modifiedFiles.add(targetPath);
|
|
2099
|
+
const relPEdit = path.relative(this.cwd, fullPath).replace(/\\/g, '/').toLowerCase();
|
|
2100
|
+
this.readFilesHistory.delete(relPEdit);
|
|
2101
|
+
this.readFilesHistory.delete(targetPath.toLowerCase());
|
|
1836
2102
|
const targetLines = target.split('\n').length;
|
|
1837
2103
|
const replacementLines = replacement.split('\n').length;
|
|
1838
2104
|
const numberOfLinesChanged = Math.max(targetLines, replacementLines);
|
|
@@ -1978,7 +2244,7 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1978
2244
|
};
|
|
1979
2245
|
}
|
|
1980
2246
|
case 'multi_edit_file': {
|
|
1981
|
-
const targetPath = String(args.path || '').trim();
|
|
2247
|
+
const targetPath = String(args.path || args.filePath || args.file || '').trim();
|
|
1982
2248
|
const edits = Array.isArray(args.edits) ? args.edits : [];
|
|
1983
2249
|
const reason = String(args.reason || args.description || 'Applied multiple code snippet edits.');
|
|
1984
2250
|
if (edits.length === 0) {
|
|
@@ -1994,8 +2260,8 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
1994
2260
|
const errors = [];
|
|
1995
2261
|
for (let i = 0; i < edits.length; i++) {
|
|
1996
2262
|
const ed = edits[i];
|
|
1997
|
-
let target = String(ed.target
|
|
1998
|
-
let replacement = String(ed.replacement
|
|
2263
|
+
let target = String(ed.target ?? ed.old_string ?? ed.old_str ?? ed.oldText ?? ed.find ?? ed.search ?? '');
|
|
2264
|
+
let replacement = String(ed.replacement ?? ed.new_string ?? ed.new_str ?? ed.newText ?? ed.replace ?? '');
|
|
1999
2265
|
if (target.includes('\\n') && !target.includes('\n'))
|
|
2000
2266
|
target = target.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
|
2001
2267
|
if (replacement.includes('\\n') && !replacement.includes('\n'))
|
|
@@ -2015,6 +2281,9 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2015
2281
|
this.backups.push({ filePath: targetPath, originalContent: origContent });
|
|
2016
2282
|
fs.writeFileSync(fullPath, currentContent, 'utf-8');
|
|
2017
2283
|
this.modifiedFiles.add(targetPath);
|
|
2284
|
+
const relPMulti = path.relative(this.cwd, fullPath).replace(/\\/g, '/').toLowerCase();
|
|
2285
|
+
this.readFilesHistory.delete(relPMulti);
|
|
2286
|
+
this.readFilesHistory.delete(targetPath.toLowerCase());
|
|
2018
2287
|
safeNote(` • File: ${chalk.bold.cyan(targetPath)}\n` +
|
|
2019
2288
|
` • Multi-edits applied: ${chalk.bold.green(appliedCount + '/' + edits.length)}\n` +
|
|
2020
2289
|
` • Why: ${reason}`, ` Applied ${appliedCount} edits to ${targetPath}`);
|
|
@@ -2101,6 +2370,22 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2101
2370
|
return { result: res.output };
|
|
2102
2371
|
}
|
|
2103
2372
|
case 'browser_inspect': {
|
|
2373
|
+
const ui = await this.computerController.inspectUI();
|
|
2374
|
+
const hasDesktopBrowser = ui.windows.some(w => /chrome|edge|brave|firefox/i.test(w)) ||
|
|
2375
|
+
(ui.activeWindow && /chrome|edge|brave|firefox/i.test(ui.activeWindow));
|
|
2376
|
+
if (hasDesktopBrowser) {
|
|
2377
|
+
const activeWin = ui.activeWindow || ui.windows.find(w => /chrome|edge|brave|firefox/i.test(w)) || 'Web Browser';
|
|
2378
|
+
const pageTitle = activeWin.replace(/\s*[-—·]\s*(?:Google Chrome|Microsoft Edge|Brave|Mozilla Firefox)\s*$/i, '').trim();
|
|
2379
|
+
const summary = [
|
|
2380
|
+
`[BROWSER WINDOW INSPECTION]:`,
|
|
2381
|
+
`• Active Desktop Browser: "${activeWin}"`,
|
|
2382
|
+
`• Current Page / Tab Title: "${pageTitle}"`,
|
|
2383
|
+
`• Visible Windows: ${ui.windows.map(w => `"${w}"`).join(', ')}`,
|
|
2384
|
+
`• State: Desktop browser is active and responsive. You can interact directly using computer_click, computer_type, computer_hotkey, or computer_screenshot.`
|
|
2385
|
+
].join('\n');
|
|
2386
|
+
this.taskStateManager.addObservation('browser_inspect', summary, true, activeWin);
|
|
2387
|
+
return { result: summary };
|
|
2388
|
+
}
|
|
2104
2389
|
const res = await this.browserController.inspect_page();
|
|
2105
2390
|
this.taskStateManager.addObservation('browser_inspect', res.summary, res.success, res.url);
|
|
2106
2391
|
return { result: res.summary };
|
|
@@ -2144,6 +2429,24 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2144
2429
|
return { result: res.output };
|
|
2145
2430
|
}
|
|
2146
2431
|
case 'browser_screenshot': {
|
|
2432
|
+
const ui = await this.computerController.inspectUI();
|
|
2433
|
+
const hasDesktopBrowser = ui.windows.some(w => /chrome|edge|brave|firefox/i.test(w)) ||
|
|
2434
|
+
(ui.activeWindow && /chrome|edge|brave|firefox/i.test(ui.activeWindow));
|
|
2435
|
+
if (hasDesktopBrowser) {
|
|
2436
|
+
const res = await this.computerController.screenshot();
|
|
2437
|
+
const activeWin = res.activeWindow || ui.activeWindow || 'Web Browser';
|
|
2438
|
+
const pageTitle = activeWin.replace(/\s*[-—·]\s*(?:Google Chrome|Microsoft Edge|Brave|Mozilla Firefox)\s*$/i, '').trim();
|
|
2439
|
+
const output = [
|
|
2440
|
+
`[BROWSER SCREEN OBSERVATION]:`,
|
|
2441
|
+
`• Active Browser Window: "${activeWin}"`,
|
|
2442
|
+
`• Current Webpage Title: "${pageTitle}"`,
|
|
2443
|
+
`• Viewport Resolution: ${res.width}x${res.height}`,
|
|
2444
|
+
`• Visual State: Web page is rendered on screen and visible. Address bar and interactive content viewport are active.`,
|
|
2445
|
+
`• Screenshot File: ${res.path || 'captured'}`
|
|
2446
|
+
].join('\n');
|
|
2447
|
+
this.taskStateManager.addObservation('browser_screenshot', output, true, activeWin);
|
|
2448
|
+
return { result: output };
|
|
2449
|
+
}
|
|
2147
2450
|
const res = await this.browserController.screenshot();
|
|
2148
2451
|
this.taskStateManager.addObservation('browser_screenshot', res.output, res.success, res.url);
|
|
2149
2452
|
return { result: res.output };
|
|
@@ -2173,10 +2476,56 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2173
2476
|
application: res.activeWindow || 'Desktop',
|
|
2174
2477
|
});
|
|
2175
2478
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2479
|
+
const ui = await this.computerController.inspectUI();
|
|
2480
|
+
const activeWin = res.activeWindow || ui.activeWindow || 'Desktop';
|
|
2481
|
+
if (activeWin) {
|
|
2482
|
+
this.taskStateManager.setActiveWindow(activeWin);
|
|
2483
|
+
}
|
|
2484
|
+
let boundsInfo = '';
|
|
2485
|
+
if (activeWin && activeWin !== 'Desktop' && typeof this.computerController.getWindowBounds === 'function') {
|
|
2486
|
+
try {
|
|
2487
|
+
const bounds = await this.computerController.getWindowBounds(activeWin);
|
|
2488
|
+
if (bounds) {
|
|
2489
|
+
boundsInfo = `Position: (${bounds.x}, ${bounds.y}), Size: ${bounds.width}x${bounds.height}`;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
catch { }
|
|
2493
|
+
}
|
|
2494
|
+
const activeLower = activeWin.toLowerCase();
|
|
2495
|
+
let appType = 'desktop_application';
|
|
2496
|
+
let visualStatus = '';
|
|
2497
|
+
if (activeLower.includes('chrome') || activeLower.includes('edge') || activeLower.includes('brave') || activeLower.includes('firefox')) {
|
|
2498
|
+
appType = 'web_browser';
|
|
2499
|
+
const pageTitle = activeWin.replace(/\s*[-—·]\s*(?:Google Chrome|Microsoft Edge|Brave|Mozilla Firefox)\s*$/i, '').trim();
|
|
2500
|
+
visualStatus = `Web Browser is active displaying page: "${pageTitle}". Browser address bar, tab bar, and web viewport are visible. Ready for typing URL/search (computer_type), navigation hotkeys (e.g. ["Control", "l"] to focus address bar), or clicking links.`;
|
|
2501
|
+
}
|
|
2502
|
+
else if (activeLower.includes('notepad')) {
|
|
2503
|
+
appType = 'text_editor';
|
|
2504
|
+
visualStatus = `Notepad text editor active. Document text editing canvas is visible and focused. Ready for typing content (computer_type) or saving (["Control", "s"]).`;
|
|
2505
|
+
}
|
|
2506
|
+
else if (activeLower.includes('code') || activeLower.includes('visual studio')) {
|
|
2507
|
+
appType = 'code_editor';
|
|
2508
|
+
visualStatus = `Visual Studio Code active. Editor tabs, sidebar, and coding canvas are visible.`;
|
|
2509
|
+
}
|
|
2510
|
+
else if (activeLower.includes('terminal') || activeLower.includes('powershell') || activeLower.includes('cmd') || activeLower.includes('wt')) {
|
|
2511
|
+
appType = 'terminal';
|
|
2512
|
+
visualStatus = `Terminal console active and ready for shell command input.`;
|
|
2178
2513
|
}
|
|
2179
|
-
|
|
2514
|
+
else if (activeWin === 'Desktop') {
|
|
2515
|
+
visualStatus = `Windows desktop visible with taskbar and wallpaper. No single application window is currently foreground-focused.`;
|
|
2516
|
+
}
|
|
2517
|
+
else {
|
|
2518
|
+
visualStatus = `Application "${activeWin}" is foreground-focused and active on screen.`;
|
|
2519
|
+
}
|
|
2520
|
+
const visibleList = ui.windows.filter(w => w && w !== 'Desktop');
|
|
2521
|
+
const summary = [
|
|
2522
|
+
`[VISUAL SCREEN OBSERVATION & LAYOUT]:`,
|
|
2523
|
+
`• Primary Display Resolution: ${res.width}x${res.height}`,
|
|
2524
|
+
`• Active Foreground Window: "${activeWin}" [Type: ${appType}]${boundsInfo ? ` (${boundsInfo})` : ''}`,
|
|
2525
|
+
`• Visible Open Windows: ${visibleList.length > 0 ? visibleList.map(w => `"${w}"`).join(', ') : '["' + activeWin + '"]'}`,
|
|
2526
|
+
`• Visual Perception State: ${visualStatus}`,
|
|
2527
|
+
`• Screenshot Image: ${res.path ? res.path : 'Captured in memory'}`
|
|
2528
|
+
].join('\n');
|
|
2180
2529
|
this.taskStateManager.addObservation('computer_screenshot', summary, true);
|
|
2181
2530
|
return { result: summary };
|
|
2182
2531
|
}
|
|
@@ -2267,7 +2616,8 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2267
2616
|
}
|
|
2268
2617
|
case 'computer_type': {
|
|
2269
2618
|
const textVal = String(args.text || '');
|
|
2270
|
-
const
|
|
2619
|
+
const targetApp = args.targetApp || args.app || args.appName || undefined;
|
|
2620
|
+
const res = await this.computerController.type(textVal, targetApp);
|
|
2271
2621
|
this.taskStateManager.addObservation('computer_type', res.output, res.success);
|
|
2272
2622
|
const structuredRes = {
|
|
2273
2623
|
success: res.success,
|
|
@@ -2382,9 +2732,13 @@ You MUST output exactly ONE JSON code block per tool call. Do NOT describe what
|
|
|
2382
2732
|
}
|
|
2383
2733
|
case 'computer_close_app': {
|
|
2384
2734
|
const appName = String(args.appName || args.app || '');
|
|
2735
|
+
const currentObj = this.taskStateManager.getState()?.objective || '';
|
|
2736
|
+
const isExplicitClose = /\b(close|exit|quit|kill|terminate|shut|band\s+kar|hatao|band)\b/i.test(currentObj);
|
|
2737
|
+
if (!isExplicitClose) {
|
|
2738
|
+
return { result: `[ACTION BLOCKED]: The user asked to interact with or use "${appName}", NOT close it. Keep "${appName}" open on their screen so they can see and use the results. Call task_completed now if your work is done.` };
|
|
2739
|
+
}
|
|
2385
2740
|
const res = await this.computerController.closeApplication(appName);
|
|
2386
2741
|
this.taskStateManager.addObservation('computer_close_app', res.output, res.success);
|
|
2387
|
-
const currentObj = this.taskStateManager.getState()?.objective || '';
|
|
2388
2742
|
const simpleCheck = checkSimpleAppAction(currentObj);
|
|
2389
2743
|
const isOnlyClosing = simpleCheck.isSimple && simpleCheck.action === 'close';
|
|
2390
2744
|
if (isOnlyClosing && res.success) {
|