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.
- 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 +3 -1
- package/bin/src/engine/agentEngine.js +370 -56
- 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 +45 -2
- package/bin/src/engine/computer/computerController.js +178 -38
- package/bin/src/engine/computer/mockComputer.d.ts +7 -2
- package/bin/src/engine/computer/mockComputer.js +59 -1
- package/bin/src/engine/computer/scoutDriver.cs +310 -63
- package/bin/src/engine/llm.js +35 -15
- package/bin/src/engine/models/harpProvider.d.ts +32 -0
- package/bin/src/engine/models/harpProvider.js +172 -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/runtime/agentRuntime.js +33 -7
- 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 +495 -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/engine/workspace/agentWorkspace.js +4 -2
- package/bin/src/index.js +4 -4
- 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/qrBridge.js +1 -1
- package/bin/src/utils/support.js +1 -1
- package/package.json +2 -2
|
@@ -34,6 +34,37 @@ export interface UIInspectionResult {
|
|
|
34
34
|
windows: string[];
|
|
35
35
|
focusedElement?: string;
|
|
36
36
|
}
|
|
37
|
+
export type SupportedAppType = 'browser' | 'terminal' | 'editor' | 'file_manager' | 'other';
|
|
38
|
+
export interface ActiveWindowInfo {
|
|
39
|
+
title: string;
|
|
40
|
+
appName: string;
|
|
41
|
+
appType: SupportedAppType;
|
|
42
|
+
bounds?: {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
} | undefined;
|
|
48
|
+
processId?: number | undefined;
|
|
49
|
+
isResponding: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface DesktopApplicationState {
|
|
52
|
+
appName: string;
|
|
53
|
+
appType: SupportedAppType;
|
|
54
|
+
isRunning: boolean;
|
|
55
|
+
isFocused: boolean;
|
|
56
|
+
windowTitle: string;
|
|
57
|
+
bounds?: {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
} | undefined;
|
|
63
|
+
canAcceptInput: boolean;
|
|
64
|
+
}
|
|
65
|
+
export type DesktopActionRiskLevel = 0 | 1 | 2 | 3;
|
|
66
|
+
export declare function classifyAppType(windowTitleOrApp: string): SupportedAppType;
|
|
67
|
+
export declare function getDesktopActionRiskLevel(action: string): DesktopActionRiskLevel;
|
|
37
68
|
export interface IComputerController {
|
|
38
69
|
screenshot(): Promise<ScreenCaptureResult>;
|
|
39
70
|
click(x: number, y: number, options?: {
|
|
@@ -45,17 +76,20 @@ export interface IComputerController {
|
|
|
45
76
|
doubleClick(x: number, y: number): Promise<ComputerActionResult>;
|
|
46
77
|
mouseDown(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
|
|
47
78
|
mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
|
|
48
|
-
type(text: string): Promise<ComputerActionResult>;
|
|
79
|
+
type(text: string, targetApp?: string): Promise<ComputerActionResult>;
|
|
49
80
|
keyPress(key: string): Promise<ComputerActionResult>;
|
|
81
|
+
key_press(key: string): Promise<ComputerActionResult>;
|
|
50
82
|
hotkey(keys: string[]): Promise<ComputerActionResult>;
|
|
51
83
|
scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
|
|
52
84
|
mouseMove(x: number, y: number): Promise<ComputerActionResult>;
|
|
53
85
|
move(x: number, y: number): Promise<ComputerActionResult>;
|
|
86
|
+
move_mouse(x: number, y: number): Promise<ComputerActionResult>;
|
|
54
87
|
drag(fromX: number, fromY: number, toX: number, toY: number): Promise<ComputerActionResult>;
|
|
55
88
|
wait(ms: number): Promise<void>;
|
|
56
89
|
openApplication(appName: string, args?: string[]): Promise<ComputerActionResult>;
|
|
57
90
|
closeApplication(appName: string): Promise<ComputerActionResult>;
|
|
58
91
|
switchWindow(windowTitleOrApp: string): Promise<ComputerActionResult>;
|
|
92
|
+
switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
|
|
59
93
|
getWindowBounds?(windowTitleOrApp: string): Promise<{
|
|
60
94
|
x: number;
|
|
61
95
|
y: number;
|
|
@@ -63,6 +97,8 @@ export interface IComputerController {
|
|
|
63
97
|
height: number;
|
|
64
98
|
} | null>;
|
|
65
99
|
inspectUI(): Promise<UIInspectionResult>;
|
|
100
|
+
active_window(): Promise<ActiveWindowInfo>;
|
|
101
|
+
application_state(appName?: string): Promise<DesktopApplicationState[]>;
|
|
66
102
|
getMousePosition(): Promise<{
|
|
67
103
|
x: number;
|
|
68
104
|
y: number;
|
|
@@ -105,6 +141,7 @@ export declare class SystemComputerController implements IComputerController {
|
|
|
105
141
|
mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
|
|
106
142
|
mouseMove(x: number, y: number): Promise<ComputerActionResult>;
|
|
107
143
|
move(x: number, y: number): Promise<ComputerActionResult>;
|
|
144
|
+
move_mouse(x: number, y: number): Promise<ComputerActionResult>;
|
|
108
145
|
drag(startX: number, startY: number, endX: number, endY: number): Promise<ComputerActionResult>;
|
|
109
146
|
scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
|
|
110
147
|
getMousePosition(): Promise<{
|
|
@@ -112,8 +149,9 @@ export declare class SystemComputerController implements IComputerController {
|
|
|
112
149
|
y: number;
|
|
113
150
|
}>;
|
|
114
151
|
runDiagnostic(): Promise<ComputerActionResult>;
|
|
115
|
-
type(text: string): Promise<ComputerActionResult>;
|
|
152
|
+
type(text: string, targetApp?: string): Promise<ComputerActionResult>;
|
|
116
153
|
keyPress(key: string): Promise<ComputerActionResult>;
|
|
154
|
+
key_press(key: string): Promise<ComputerActionResult>;
|
|
117
155
|
hotkey(keys: string[]): Promise<ComputerActionResult>;
|
|
118
156
|
wait(ms: number): Promise<void>;
|
|
119
157
|
resolveCanonicalApp(appName: string, args?: string[]): {
|
|
@@ -132,5 +170,10 @@ export declare class SystemComputerController implements IComputerController {
|
|
|
132
170
|
height: number;
|
|
133
171
|
} | null>;
|
|
134
172
|
inspectUI(): Promise<UIInspectionResult>;
|
|
173
|
+
active_window(): Promise<ActiveWindowInfo>;
|
|
174
|
+
application_state(appName?: string): Promise<DesktopApplicationState[]>;
|
|
175
|
+
switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
|
|
135
176
|
}
|
|
177
|
+
export type ComputerController = IComputerController;
|
|
178
|
+
export declare const ComputerController: typeof SystemComputerController;
|
|
136
179
|
//# sourceMappingURL=computerController.d.ts.map
|
|
@@ -8,6 +8,39 @@ const __dirname = path.dirname(__filename);
|
|
|
8
8
|
const execAsync = promisify(exec);
|
|
9
9
|
const execFileAsync = promisify(execFile);
|
|
10
10
|
import { OperatorHud } from './operatorHud.js';
|
|
11
|
+
export function classifyAppType(windowTitleOrApp) {
|
|
12
|
+
const lower = (windowTitleOrApp || '').toLowerCase().trim();
|
|
13
|
+
if (/chrome|edge|msedge|brave|firefox|opera|browser|safari|github/i.test(lower)) {
|
|
14
|
+
return 'browser';
|
|
15
|
+
}
|
|
16
|
+
if (/terminal|wt|windows\s*terminal|powershell|pwsh|cmd|bash|wsl|command\s*prompt|zsh|git\s*bash/i.test(lower)) {
|
|
17
|
+
return 'terminal';
|
|
18
|
+
}
|
|
19
|
+
if (/code|cursor|notepad|sublime|atom|vim|neovim|ide|editor/i.test(lower)) {
|
|
20
|
+
return 'editor';
|
|
21
|
+
}
|
|
22
|
+
if (/explorer|file\s*explorer|finder|nautilus|dolphin|files/i.test(lower)) {
|
|
23
|
+
return 'file_manager';
|
|
24
|
+
}
|
|
25
|
+
return 'other';
|
|
26
|
+
}
|
|
27
|
+
export function getDesktopActionRiskLevel(action) {
|
|
28
|
+
const act = action.toLowerCase().trim();
|
|
29
|
+
// Level 0: Read-only inspection
|
|
30
|
+
if (['screenshot', 'active_window', 'activewindow', 'application_state', 'applicationstate', 'inspectui', 'getmouseposition', 'diagnostic', 'position'].includes(act)) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
// Level 1: Reversible input modification
|
|
34
|
+
if (['move', 'move_mouse', 'movemouse', 'mousemove', 'type', 'key_press', 'keypress', 'click', 'leftclick', 'rightclick', 'doubleclick', 'drag', 'scroll', 'switchwindow', 'switch_to_app', 'switchtoapp'].includes(act)) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
// Level 2: External side effects / process launching
|
|
38
|
+
if (['openapplication', 'closeapplication', 'hotkey'].includes(act)) {
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
// Level 3: High impact / destructive
|
|
42
|
+
return 3;
|
|
43
|
+
}
|
|
11
44
|
export class SystemComputerController {
|
|
12
45
|
workspaceDir;
|
|
13
46
|
screenshotsDir;
|
|
@@ -440,6 +473,9 @@ if ($act -eq "move") {
|
|
|
440
473
|
coordinates: { x, y },
|
|
441
474
|
};
|
|
442
475
|
}
|
|
476
|
+
async move_mouse(x, y) {
|
|
477
|
+
return this.move(x, y);
|
|
478
|
+
}
|
|
443
479
|
async drag(startX, startY, endX, endY) {
|
|
444
480
|
if (process.platform === 'win32') {
|
|
445
481
|
const res = await this.runDriverAction('drag', [startX, startY, endX, endY]);
|
|
@@ -512,18 +548,14 @@ if ($act -eq "move") {
|
|
|
512
548
|
activeWindow: 'Desktop',
|
|
513
549
|
};
|
|
514
550
|
}
|
|
515
|
-
async type(text) {
|
|
551
|
+
async type(text, targetApp) {
|
|
516
552
|
if (!text)
|
|
517
553
|
return { success: true, output: 'Typed empty string', action: 'type' };
|
|
518
554
|
if (process.platform === 'win32') {
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
await this.switchWindow(targetApp);
|
|
522
|
-
await this.wait(150);
|
|
523
|
-
}
|
|
524
|
-
const res = await this.runDriverAction('type', [text]);
|
|
555
|
+
const app = targetApp || this.expectedApplication || '';
|
|
556
|
+
const res = await this.runDriverAction('type', app ? [text, app] : [text]);
|
|
525
557
|
const success = Boolean(res?.success);
|
|
526
|
-
const activeWin = res?.activeWindow ||
|
|
558
|
+
const activeWin = res?.activeWindow || app || 'foreground';
|
|
527
559
|
this.activeWindow = activeWin;
|
|
528
560
|
return {
|
|
529
561
|
success,
|
|
@@ -564,6 +596,9 @@ if ($act -eq "move") {
|
|
|
564
596
|
}
|
|
565
597
|
return { success: true, output: `Simulated key press: ${key}`, action: 'key_press' };
|
|
566
598
|
}
|
|
599
|
+
async key_press(key) {
|
|
600
|
+
return this.keyPress(key);
|
|
601
|
+
}
|
|
567
602
|
async hotkey(keys) {
|
|
568
603
|
if (!keys || keys.length === 0) {
|
|
569
604
|
return { success: false, output: 'No keys provided for hotkey', action: 'hotkey', error: 'No keys provided' };
|
|
@@ -618,16 +653,20 @@ if ($act -eq "move") {
|
|
|
618
653
|
titleTerms.push('visual studio code', 'code');
|
|
619
654
|
processNames.push('Code');
|
|
620
655
|
}
|
|
621
|
-
else if (appLower === 'chrome' || appLower === 'google chrome' || appLower === 'google-chrome' || appLower === 'browser') {
|
|
622
|
-
const
|
|
656
|
+
else if (appLower === 'chrome' || appLower === 'google chrome' || appLower === 'google-chrome' || appLower === 'browser' || appLower === 'web browser' || appLower === 'default browser' || appLower === 'web' || appLower === 'internet') {
|
|
657
|
+
const browserCandidates = [
|
|
623
658
|
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
624
659
|
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
625
660
|
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'Google', 'Chrome', 'Application', 'chrome.exe') : '',
|
|
661
|
+
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
|
|
662
|
+
'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
|
|
663
|
+
'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe',
|
|
664
|
+
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe') : '',
|
|
626
665
|
].filter(Boolean);
|
|
627
|
-
const found =
|
|
666
|
+
const found = browserCandidates.find((p) => fs.existsSync(p));
|
|
628
667
|
canonicalCmd = found || 'chrome.exe';
|
|
629
|
-
titleTerms.push('chrome', 'google chrome');
|
|
630
|
-
processNames.push('chrome');
|
|
668
|
+
titleTerms.push('chrome', 'google chrome', 'edge', 'microsoft edge', 'brave', 'browser', 'new tab', 'google');
|
|
669
|
+
processNames.push('chrome', 'msedge', 'brave');
|
|
631
670
|
}
|
|
632
671
|
else if (appLower === 'edge' || appLower === 'msedge' || appLower === 'microsoft edge') {
|
|
633
672
|
const edgeCandidates = [
|
|
@@ -718,48 +757,70 @@ if ($act -eq "move") {
|
|
|
718
757
|
async openApplication(appName, args = []) {
|
|
719
758
|
const resolved = this.resolveCanonicalApp(appName, args);
|
|
720
759
|
const canonicalCmd = resolved.canonicalCmd;
|
|
721
|
-
const
|
|
760
|
+
const appLower = appName.toLowerCase().trim();
|
|
761
|
+
const isGenericBrowser = ['browser', 'web browser', 'default browser', 'web', 'internet'].includes(appLower);
|
|
762
|
+
const isBrowser = isGenericBrowser ||
|
|
763
|
+
['chrome', 'google chrome', 'edge', 'msedge', 'brave'].includes(appLower) ||
|
|
764
|
+
canonicalCmd.toLowerCase().includes('chrome') ||
|
|
765
|
+
canonicalCmd.toLowerCase().includes('msedge') ||
|
|
766
|
+
canonicalCmd.toLowerCase().includes('brave');
|
|
767
|
+
let finalArgs = resolved.args;
|
|
768
|
+
if (isBrowser && finalArgs.length === 0 && !isGenericBrowser) {
|
|
769
|
+
finalArgs = ['--new-window', 'https://www.google.com'];
|
|
770
|
+
}
|
|
722
771
|
const argsStr = finalArgs.join(' ');
|
|
723
772
|
try {
|
|
724
773
|
if (process.platform === 'win32') {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
774
|
+
// Primary: Spawn detached via Windows Shell (cmd.exe /c start) directly from Node.js.
|
|
775
|
+
// In Windows, processes launched via "start" are delegated to explorer.exe,
|
|
776
|
+
// completely independent of this console, job object, or process tree,
|
|
777
|
+
// and remain open indefinitely on the user's desktop.
|
|
778
|
+
let launched = false;
|
|
779
|
+
try {
|
|
780
|
+
const startTarget = isGenericBrowser ? 'https://www.google.com' : canonicalCmd;
|
|
781
|
+
const startArgs = isGenericBrowser ? [] : finalArgs;
|
|
782
|
+
const child = spawn('cmd.exe', ['/c', 'start', '', startTarget, ...startArgs], {
|
|
783
|
+
detached: true,
|
|
784
|
+
stdio: 'ignore',
|
|
785
|
+
});
|
|
786
|
+
child.unref();
|
|
787
|
+
launched = true;
|
|
788
|
+
}
|
|
789
|
+
catch { }
|
|
790
|
+
// Fallback to native scout_driver launch if spawn fails
|
|
791
|
+
if (!launched) {
|
|
792
|
+
await this.runDriverAction('launch', finalArgs.length > 0 ? [canonicalCmd, argsStr] : [canonicalCmd]);
|
|
739
793
|
}
|
|
740
794
|
this.expectedApplication = appName;
|
|
741
795
|
// Observation-based wait: poll inspectUI to confirm window appeared
|
|
742
|
-
const delays = [300, 600, 1000];
|
|
796
|
+
const delays = [300, 600, 1000, 1500];
|
|
797
|
+
let matchedWindow = null;
|
|
743
798
|
for (const delay of delays) {
|
|
744
799
|
await this.wait(delay);
|
|
745
800
|
const ui = await this.inspectUI();
|
|
746
|
-
const match = ui.windows.
|
|
801
|
+
const match = ui.windows.find(w => {
|
|
747
802
|
const wLower = w.toLowerCase();
|
|
748
803
|
return resolved.titleTerms.some(term => wLower.includes(term.toLowerCase()));
|
|
749
804
|
});
|
|
750
|
-
if (match
|
|
805
|
+
if (match) {
|
|
806
|
+
matchedWindow = match;
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
if (ui.activeWindow && resolved.titleTerms.some(term => ui.activeWindow.toLowerCase().includes(term.toLowerCase()))) {
|
|
810
|
+
matchedWindow = ui.activeWindow;
|
|
751
811
|
break;
|
|
752
812
|
}
|
|
753
813
|
}
|
|
754
|
-
if (
|
|
755
|
-
|
|
814
|
+
if (matchedWindow) {
|
|
815
|
+
this.expectedApplication = matchedWindow;
|
|
816
|
+
this.activeWindow = matchedWindow;
|
|
756
817
|
}
|
|
757
818
|
return {
|
|
758
819
|
success: true,
|
|
759
|
-
output: `Launched and focused application: "${this.expectedApplication || appName}"`,
|
|
820
|
+
output: `Launched and focused application: "${matchedWindow || this.expectedApplication || appName}"`,
|
|
760
821
|
action: 'open_app',
|
|
761
|
-
activeWindow: this.expectedApplication || appName,
|
|
762
|
-
expectedWindow: this.expectedApplication || appName,
|
|
822
|
+
activeWindow: matchedWindow || this.expectedApplication || appName,
|
|
823
|
+
expectedWindow: matchedWindow || this.expectedApplication || appName,
|
|
763
824
|
};
|
|
764
825
|
}
|
|
765
826
|
else if (process.platform === 'darwin') {
|
|
@@ -838,9 +899,16 @@ if ($act -eq "move") {
|
|
|
838
899
|
try {
|
|
839
900
|
const script = `
|
|
840
901
|
$wshell = New-Object -ComObject Wscript.Shell
|
|
841
|
-
$
|
|
902
|
+
$target = "${windowTitleOrApp.replace(/"/g, '`"')}"
|
|
903
|
+
$result = $wshell.AppActivate($target)
|
|
842
904
|
if (-not $result) {
|
|
843
|
-
$p = Get-Process | Where-Object { $_.MainWindowTitle -like "*$
|
|
905
|
+
$p = Get-Process | Where-Object { $_.MainWindowTitle -like "*$target*" -or $_.ProcessName -like "*$target*" } | Select-Object -First 1
|
|
906
|
+
if (-not $p) {
|
|
907
|
+
$kw = if ($target -match 'chrome|browser') { 'chrome' } elseif ($target -match 'edge') { 'msedge' } elseif ($target -match 'notepad') { 'notepad' } elseif ($target -match 'code') { 'code' } else { '' }
|
|
908
|
+
if ($kw) {
|
|
909
|
+
$p = Get-Process | Where-Object { $_.ProcessName -like "*$kw*" -or $_.MainWindowTitle -like "*$kw*" } | Select-Object -First 1
|
|
910
|
+
}
|
|
911
|
+
}
|
|
844
912
|
if ($p) {
|
|
845
913
|
$null = $wshell.AppActivate($p.Id)
|
|
846
914
|
$result = $true
|
|
@@ -910,5 +978,77 @@ if ($result) { Write-Output "OK" } else { Write-Output "NOT_FOUND" }
|
|
|
910
978
|
}
|
|
911
979
|
return { activeWindow: 'Desktop', windows: ['Desktop', 'Terminal'] };
|
|
912
980
|
}
|
|
981
|
+
async active_window() {
|
|
982
|
+
const ui = await this.inspectUI();
|
|
983
|
+
const title = ui.activeWindow || this.activeWindow || 'Desktop';
|
|
984
|
+
const appType = classifyAppType(title);
|
|
985
|
+
let bounds;
|
|
986
|
+
try {
|
|
987
|
+
const b = await this.getWindowBounds(title);
|
|
988
|
+
if (b)
|
|
989
|
+
bounds = b;
|
|
990
|
+
}
|
|
991
|
+
catch { }
|
|
992
|
+
return {
|
|
993
|
+
title,
|
|
994
|
+
appName: title.split(/[-—·]/)[0]?.trim() || title,
|
|
995
|
+
appType,
|
|
996
|
+
bounds: bounds || undefined,
|
|
997
|
+
isResponding: true,
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
async application_state(appName) {
|
|
1001
|
+
const ui = await this.inspectUI();
|
|
1002
|
+
const activeWin = ui.activeWindow || 'Desktop';
|
|
1003
|
+
const states = [];
|
|
1004
|
+
for (const win of ui.windows) {
|
|
1005
|
+
if (!win || win === 'Desktop')
|
|
1006
|
+
continue;
|
|
1007
|
+
const appType = classifyAppType(win);
|
|
1008
|
+
const isFocused = win.toLowerCase() === activeWin.toLowerCase() ||
|
|
1009
|
+
(activeWin !== 'Desktop' && win.toLowerCase().includes(activeWin.toLowerCase()));
|
|
1010
|
+
if (appName && !win.toLowerCase().includes(appName.toLowerCase())) {
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
let bounds;
|
|
1014
|
+
try {
|
|
1015
|
+
const b = await this.getWindowBounds(win);
|
|
1016
|
+
if (b)
|
|
1017
|
+
bounds = b;
|
|
1018
|
+
}
|
|
1019
|
+
catch { }
|
|
1020
|
+
states.push({
|
|
1021
|
+
appName: win.split(/[-—·]/)[0]?.trim() || win,
|
|
1022
|
+
appType,
|
|
1023
|
+
isRunning: true,
|
|
1024
|
+
isFocused,
|
|
1025
|
+
windowTitle: win,
|
|
1026
|
+
bounds: bounds || undefined,
|
|
1027
|
+
canAcceptInput: true,
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
return states;
|
|
1031
|
+
}
|
|
1032
|
+
async switch_to_app(appType) {
|
|
1033
|
+
const target = appType.toLowerCase().trim();
|
|
1034
|
+
const ui = await this.inspectUI();
|
|
1035
|
+
// 1. Check if an application of this type is already open
|
|
1036
|
+
const openMatch = ui.windows.find(w => classifyAppType(w) === target || w.toLowerCase().includes(target));
|
|
1037
|
+
if (openMatch) {
|
|
1038
|
+
return await this.switchWindow(openMatch);
|
|
1039
|
+
}
|
|
1040
|
+
// 2. Not running: Launch canonical default application for this category
|
|
1041
|
+
let defaultApp = target;
|
|
1042
|
+
if (target === 'browser')
|
|
1043
|
+
defaultApp = 'chrome';
|
|
1044
|
+
else if (target === 'terminal')
|
|
1045
|
+
defaultApp = 'wt';
|
|
1046
|
+
else if (target === 'editor')
|
|
1047
|
+
defaultApp = 'notepad';
|
|
1048
|
+
else if (target === 'file_manager')
|
|
1049
|
+
defaultApp = 'explorer';
|
|
1050
|
+
return await this.openApplication(defaultApp);
|
|
1051
|
+
}
|
|
913
1052
|
}
|
|
1053
|
+
export const ComputerController = SystemComputerController;
|
|
914
1054
|
//# sourceMappingURL=computerController.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IComputerController, ScreenCaptureResult, ComputerActionResult, UIInspectionResult } from './computerController.js';
|
|
1
|
+
import type { IComputerController, ScreenCaptureResult, ComputerActionResult, UIInspectionResult, ActiveWindowInfo, DesktopApplicationState, SupportedAppType } from './computerController.js';
|
|
2
2
|
export declare class MockComputerController implements IComputerController {
|
|
3
3
|
activeWindow: string;
|
|
4
4
|
expectedApplication: string | null;
|
|
@@ -29,12 +29,14 @@ export declare class MockComputerController implements IComputerController {
|
|
|
29
29
|
doubleClick(x: number, y: number): Promise<ComputerActionResult>;
|
|
30
30
|
mouseDown(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
|
|
31
31
|
mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
|
|
32
|
-
type(text: string): Promise<ComputerActionResult>;
|
|
32
|
+
type(text: string, targetApp?: string): Promise<ComputerActionResult>;
|
|
33
33
|
keyPress(key: string): Promise<ComputerActionResult>;
|
|
34
|
+
key_press(key: string): Promise<ComputerActionResult>;
|
|
34
35
|
hotkey(keys: string[]): Promise<ComputerActionResult>;
|
|
35
36
|
scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
|
|
36
37
|
mouseMove(x: number, y: number): Promise<ComputerActionResult>;
|
|
37
38
|
move(x: number, y: number): Promise<ComputerActionResult>;
|
|
39
|
+
move_mouse(x: number, y: number): Promise<ComputerActionResult>;
|
|
38
40
|
drag(fromX: number, fromY: number, toX: number, toY: number): Promise<ComputerActionResult>;
|
|
39
41
|
wait(ms: number): Promise<void>;
|
|
40
42
|
getMousePosition(): Promise<{
|
|
@@ -52,6 +54,9 @@ export declare class MockComputerController implements IComputerController {
|
|
|
52
54
|
height: number;
|
|
53
55
|
} | null>;
|
|
54
56
|
inspectUI(): Promise<UIInspectionResult>;
|
|
57
|
+
active_window(): Promise<ActiveWindowInfo>;
|
|
58
|
+
application_state(appName?: string): Promise<DesktopApplicationState[]>;
|
|
59
|
+
switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
|
|
55
60
|
getActionLog(): Array<{
|
|
56
61
|
action: string;
|
|
57
62
|
args: any;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { classifyAppType } from './computerController.js';
|
|
1
2
|
export class MockComputerController {
|
|
2
3
|
activeWindow = 'Desktop';
|
|
3
4
|
expectedApplication = null;
|
|
@@ -114,7 +115,7 @@ export class MockComputerController {
|
|
|
114
115
|
button: btn,
|
|
115
116
|
};
|
|
116
117
|
}
|
|
117
|
-
async type(text) {
|
|
118
|
+
async type(text, targetApp) {
|
|
118
119
|
this.log('type', { text });
|
|
119
120
|
if (this.shouldFailNext) {
|
|
120
121
|
this.shouldFailNext = false;
|
|
@@ -139,6 +140,9 @@ export class MockComputerController {
|
|
|
139
140
|
this.log('keyPress', { key });
|
|
140
141
|
return { success: true, output: `Pressed key: ${key}`, action: 'key_press' };
|
|
141
142
|
}
|
|
143
|
+
async key_press(key) {
|
|
144
|
+
return this.keyPress(key);
|
|
145
|
+
}
|
|
142
146
|
async hotkey(keys) {
|
|
143
147
|
this.log('hotkey', { keys });
|
|
144
148
|
return { success: true, output: `Executed hotkey: ${keys.join('+')}`, action: 'hotkey' };
|
|
@@ -162,6 +166,9 @@ export class MockComputerController {
|
|
|
162
166
|
activeWindow: this.activeWindow,
|
|
163
167
|
};
|
|
164
168
|
}
|
|
169
|
+
async move_mouse(x, y) {
|
|
170
|
+
return this.move(x, y);
|
|
171
|
+
}
|
|
165
172
|
async drag(fromX, fromY, toX, toY) {
|
|
166
173
|
this.currentX = toX;
|
|
167
174
|
this.currentY = toY;
|
|
@@ -250,6 +257,57 @@ export class MockComputerController {
|
|
|
250
257
|
focusedElement: 'MainView',
|
|
251
258
|
};
|
|
252
259
|
}
|
|
260
|
+
async active_window() {
|
|
261
|
+
this.log('active_window', {});
|
|
262
|
+
const appType = classifyAppType(this.activeWindow);
|
|
263
|
+
return {
|
|
264
|
+
title: this.activeWindow,
|
|
265
|
+
appName: this.activeWindow.split(/[-—·]/)[0]?.trim() || this.activeWindow,
|
|
266
|
+
appType,
|
|
267
|
+
bounds: { x: 0, y: 0, width: this.screenWidth, height: this.screenHeight },
|
|
268
|
+
isResponding: true,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async application_state(appName) {
|
|
272
|
+
this.log('application_state', { appName });
|
|
273
|
+
const states = [];
|
|
274
|
+
for (const win of this.openWindows) {
|
|
275
|
+
if (appName && !win.toLowerCase().includes(appName.toLowerCase())) {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const appType = classifyAppType(win);
|
|
279
|
+
states.push({
|
|
280
|
+
appName: win.split(/[-—·]/)[0]?.trim() || win,
|
|
281
|
+
appType,
|
|
282
|
+
isRunning: true,
|
|
283
|
+
isFocused: win === this.activeWindow,
|
|
284
|
+
windowTitle: win,
|
|
285
|
+
bounds: { x: 0, y: 0, width: this.screenWidth, height: this.screenHeight },
|
|
286
|
+
canAcceptInput: true,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return states;
|
|
290
|
+
}
|
|
291
|
+
async switch_to_app(appType) {
|
|
292
|
+
this.log('switch_to_app', { appType });
|
|
293
|
+
const target = appType.toLowerCase().trim();
|
|
294
|
+
// 1. Check if an application of this category is open
|
|
295
|
+
const openMatch = this.openWindows.find(w => classifyAppType(w) === target || w.toLowerCase().includes(target));
|
|
296
|
+
if (openMatch) {
|
|
297
|
+
return await this.switchWindow(openMatch);
|
|
298
|
+
}
|
|
299
|
+
// 2. Open default application for this category
|
|
300
|
+
let defaultName = target;
|
|
301
|
+
if (target === 'browser')
|
|
302
|
+
defaultName = 'Google Chrome';
|
|
303
|
+
else if (target === 'terminal')
|
|
304
|
+
defaultName = 'Terminal';
|
|
305
|
+
else if (target === 'editor')
|
|
306
|
+
defaultName = 'VS Code';
|
|
307
|
+
else if (target === 'file_manager')
|
|
308
|
+
defaultName = 'File Explorer';
|
|
309
|
+
return await this.openApplication(defaultName);
|
|
310
|
+
}
|
|
253
311
|
getActionLog() {
|
|
254
312
|
return [...this.actionLog];
|
|
255
313
|
}
|