ft-scout 9.5.2 → 9.5.5

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.
@@ -597,16 +597,136 @@ if ($act -eq "move") {
597
597
  async wait(ms) {
598
598
  return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
599
599
  }
600
- async openApplication(appName, args = []) {
600
+ resolveCanonicalApp(appName, args = []) {
601
601
  const appLower = appName.toLowerCase().trim();
602
- const argsStr = args.join(' ');
602
+ let canonicalCmd = appName.trim();
603
+ let appArgs = [...args];
604
+ let titleTerms = [appName.trim()];
605
+ let processNames = [appName.trim().replace(/\.exe$/i, '')];
606
+ if (appLower === 'calc' || appLower === 'calculator' || appLower === 'wincalc') {
607
+ canonicalCmd = 'calc.exe';
608
+ titleTerms.push('calculator', 'calc');
609
+ processNames.push('calc', 'CalculatorApp', 'Calculator');
610
+ }
611
+ else if (appLower === 'notepad' || appLower === 'text editor' || appLower === 'editor') {
612
+ canonicalCmd = 'notepad.exe';
613
+ titleTerms.push('notepad');
614
+ processNames.push('notepad');
615
+ }
616
+ else if (appLower === 'code' || appLower === 'vscode' || appLower === 'vs code' || appLower === 'visual studio code') {
617
+ canonicalCmd = 'code';
618
+ titleTerms.push('visual studio code', 'code');
619
+ processNames.push('Code');
620
+ }
621
+ else if (appLower === 'chrome' || appLower === 'google chrome' || appLower === 'google-chrome' || appLower === 'browser') {
622
+ const chromeCandidates = [
623
+ 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
624
+ 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
625
+ process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'Google', 'Chrome', 'Application', 'chrome.exe') : '',
626
+ ].filter(Boolean);
627
+ const found = chromeCandidates.find((p) => fs.existsSync(p));
628
+ canonicalCmd = found || 'chrome.exe';
629
+ titleTerms.push('chrome', 'google chrome');
630
+ processNames.push('chrome');
631
+ }
632
+ else if (appLower === 'edge' || appLower === 'msedge' || appLower === 'microsoft edge') {
633
+ const edgeCandidates = [
634
+ 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
635
+ 'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
636
+ ];
637
+ const found = edgeCandidates.find((p) => fs.existsSync(p));
638
+ canonicalCmd = found || 'msedge.exe';
639
+ titleTerms.push('edge', 'microsoft edge');
640
+ processNames.push('msedge');
641
+ }
642
+ else if (appLower === 'brave' || appLower === 'brave browser') {
643
+ const braveCandidates = [
644
+ 'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe',
645
+ process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe') : '',
646
+ ].filter(Boolean);
647
+ const found = braveCandidates.find((p) => fs.existsSync(p));
648
+ canonicalCmd = found || 'brave.exe';
649
+ titleTerms.push('brave');
650
+ processNames.push('brave');
651
+ }
652
+ else if (appLower === 'explorer' || appLower === 'file explorer' || appLower === 'files') {
653
+ canonicalCmd = 'explorer.exe';
654
+ if (appArgs.length === 0)
655
+ appArgs.push('.');
656
+ titleTerms.push('file explorer', 'explorer');
657
+ processNames.push('explorer');
658
+ }
659
+ else if (appLower === 'terminal' || appLower === 'wt' || appLower === 'windows terminal') {
660
+ canonicalCmd = 'wt.exe';
661
+ titleTerms.push('terminal', 'windows terminal');
662
+ processNames.push('WindowsTerminal', 'wt');
663
+ }
664
+ else if (appLower === 'cmd' || appLower === 'command prompt') {
665
+ canonicalCmd = 'cmd.exe';
666
+ titleTerms.push('cmd', 'command prompt');
667
+ processNames.push('cmd');
668
+ }
669
+ else if (appLower === 'powershell' || appLower === 'pwsh') {
670
+ canonicalCmd = 'powershell.exe';
671
+ titleTerms.push('powershell');
672
+ processNames.push('powershell', 'pwsh');
673
+ }
674
+ else if (appLower === 'paint' || appLower === 'mspaint') {
675
+ canonicalCmd = 'mspaint.exe';
676
+ titleTerms.push('paint');
677
+ processNames.push('mspaint');
678
+ }
679
+ else if (appLower === 'spotify') {
680
+ const appData = process.env.APPDATA ? path.join(process.env.APPDATA, 'Spotify', 'Spotify.exe') : '';
681
+ canonicalCmd = (appData && fs.existsSync(appData)) ? appData : 'spotify.exe';
682
+ titleTerms.push('spotify');
683
+ processNames.push('Spotify');
684
+ }
685
+ else if (appLower.includes('blender')) {
686
+ const candidatePaths = [
687
+ 'C:\\Program Files\\Blender Foundation\\Blender 5.2\\blender.exe',
688
+ 'C:\\Program Files\\Blender Foundation\\Blender 5.1\\blender.exe',
689
+ 'C:\\Program Files\\Blender Foundation\\Blender 5.0\\blender.exe',
690
+ 'C:\\Program Files\\Blender Foundation\\Blender 4.3\\blender.exe',
691
+ 'C:\\Program Files\\Blender Foundation\\Blender 4.2\\blender.exe',
692
+ ];
693
+ let resolvedBlender = candidatePaths.find((p) => fs.existsSync(p));
694
+ if (!resolvedBlender) {
695
+ const bfDir = 'C:\\Program Files\\Blender Foundation';
696
+ if (fs.existsSync(bfDir)) {
697
+ try {
698
+ const subdirs = fs.readdirSync(bfDir);
699
+ for (const sub of subdirs) {
700
+ const cand = path.join(bfDir, sub, 'blender.exe');
701
+ if (fs.existsSync(cand)) {
702
+ resolvedBlender = cand;
703
+ break;
704
+ }
705
+ }
706
+ }
707
+ catch { }
708
+ }
709
+ }
710
+ if (resolvedBlender) {
711
+ canonicalCmd = resolvedBlender;
712
+ }
713
+ titleTerms.push('blender');
714
+ processNames.push('blender');
715
+ }
716
+ return { canonicalCmd, args: appArgs, titleTerms, processNames };
717
+ }
718
+ async openApplication(appName, args = []) {
719
+ const resolved = this.resolveCanonicalApp(appName, args);
720
+ const canonicalCmd = resolved.canonicalCmd;
721
+ const finalArgs = resolved.args;
722
+ const argsStr = finalArgs.join(' ');
603
723
  try {
604
724
  if (process.platform === 'win32') {
605
- const driverRes = await this.runDriverAction('launch', args.length > 0 ? [appName, argsStr] : [appName]);
725
+ const driverRes = await this.runDriverAction('launch', finalArgs.length > 0 ? [canonicalCmd, argsStr] : [canonicalCmd]);
606
726
  if (!driverRes || !driverRes.success) {
607
727
  const spawnDetached = (cmd, a = []) => {
608
728
  try {
609
- const child = spawn('cmd.exe', ['/c', 'start', '""', cmd, ...a], {
729
+ const child = spawn('cmd.exe', ['/c', 'start', '', cmd, ...a], {
610
730
  detached: true,
611
731
  stdio: 'ignore',
612
732
  windowsHide: true,
@@ -615,110 +735,19 @@ if ($act -eq "move") {
615
735
  }
616
736
  catch { }
617
737
  };
618
- if (appLower === 'code' || appLower === 'vscode') {
619
- spawnDetached('code', argsStr ? [argsStr] : []);
620
- }
621
- else if (appLower === 'explorer' || appLower === 'file explorer') {
622
- spawnDetached('explorer', [argsStr || '.']);
623
- }
624
- else if (appLower === 'notepad') {
625
- spawnDetached('notepad', argsStr ? [argsStr] : []);
626
- }
627
- else if (appLower === 'terminal' || appLower === 'cmd' || appLower === 'powershell') {
628
- spawnDetached('powershell', argsStr ? [argsStr] : []);
629
- }
630
- else if (appLower.includes('blender')) {
631
- const candidatePaths = [
632
- 'C:\\Program Files\\Blender Foundation\\Blender 5.2\\blender.exe',
633
- 'C:\\Program Files\\Blender Foundation\\Blender 5.1\\blender.exe',
634
- 'C:\\Program Files\\Blender Foundation\\Blender 5.0\\blender.exe',
635
- 'C:\\Program Files\\Blender Foundation\\Blender 4.3\\blender.exe',
636
- 'C:\\Program Files\\Blender Foundation\\Blender 4.2\\blender.exe',
637
- ];
638
- let resolvedBlender = candidatePaths.find((p) => fs.existsSync(p));
639
- if (!resolvedBlender) {
640
- const bfDir = 'C:\\Program Files\\Blender Foundation';
641
- if (fs.existsSync(bfDir)) {
642
- try {
643
- const subdirs = fs.readdirSync(bfDir);
644
- for (const sub of subdirs) {
645
- const cand = path.join(bfDir, sub, 'blender.exe');
646
- if (fs.existsSync(cand)) {
647
- resolvedBlender = cand;
648
- break;
649
- }
650
- }
651
- }
652
- catch { }
653
- }
654
- }
655
- const serverScript = path.resolve(process.cwd(), '.ft', 'scripts', 'start_blender_mcp.py');
656
- if (resolvedBlender) {
657
- const pyArg = fs.existsSync(serverScript) ? `-ArgumentList @('--python', '${serverScript.replace(/\\/g, '\\\\')}')` : '';
658
- await execAsync(`powershell -NoProfile -Command "Start-Process '${resolvedBlender}' ${pyArg} -WindowStyle Minimized"`);
659
- }
660
- else {
661
- spawnDetached(appName, argsStr ? [argsStr] : []);
662
- }
663
- }
664
- else if (appLower === 'chrome' || appLower === 'google chrome' || appLower === 'google-chrome') {
665
- const chromeCandidates = [
666
- 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
667
- 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
668
- process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'Google', 'Chrome', 'Application', 'chrome.exe') : '',
669
- ].filter(Boolean);
670
- const resolvedChrome = chromeCandidates.find((p) => fs.existsSync(p));
671
- if (resolvedChrome) {
672
- spawnDetached(resolvedChrome, argsStr ? [argsStr] : []);
673
- }
674
- else {
675
- spawnDetached('chrome', argsStr ? [argsStr] : []);
676
- }
677
- }
678
- else if (appLower === 'edge' || appLower === 'msedge' || appLower === 'microsoft edge') {
679
- const edgeCandidates = [
680
- 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
681
- 'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
682
- ];
683
- const resolvedEdge = edgeCandidates.find((p) => fs.existsSync(p));
684
- if (resolvedEdge) {
685
- spawnDetached(resolvedEdge, argsStr ? [argsStr] : []);
686
- }
687
- else {
688
- spawnDetached('msedge', argsStr ? [argsStr] : []);
689
- }
690
- }
691
- else if (appLower === 'brave' || appLower === 'brave browser') {
692
- const braveCandidates = [
693
- 'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe',
694
- process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe') : '',
695
- ].filter(Boolean);
696
- const resolvedBrave = braveCandidates.find((p) => fs.existsSync(p));
697
- if (resolvedBrave) {
698
- spawnDetached(resolvedBrave, argsStr ? [argsStr] : []);
699
- }
700
- else {
701
- spawnDetached('brave', argsStr ? [argsStr] : []);
702
- }
703
- }
704
- else if (appLower === 'calc' || appLower === 'calculator') {
705
- spawnDetached('calc');
706
- }
707
- else if (appLower === 'mspaint' || appLower === 'paint') {
708
- spawnDetached('mspaint');
709
- }
710
- else {
711
- spawnDetached(appName, argsStr ? [argsStr] : []);
712
- }
738
+ spawnDetached(canonicalCmd, finalArgs);
713
739
  }
714
740
  this.expectedApplication = appName;
715
741
  // Observation-based wait: poll inspectUI to confirm window appeared
716
- const delays = [400, 800, 1200];
742
+ const delays = [300, 600, 1000];
717
743
  for (const delay of delays) {
718
744
  await this.wait(delay);
719
745
  const ui = await this.inspectUI();
720
- const match = ui.windows.some(w => w.toLowerCase().includes(appName.toLowerCase()));
721
- if (match || (ui.activeWindow && ui.activeWindow.toLowerCase().includes(appName.toLowerCase()))) {
746
+ const match = ui.windows.some(w => {
747
+ const wLower = w.toLowerCase();
748
+ return resolved.titleTerms.some(term => wLower.includes(term.toLowerCase()));
749
+ });
750
+ if (match || (ui.activeWindow && resolved.titleTerms.some(term => ui.activeWindow.toLowerCase().includes(term.toLowerCase())))) {
722
751
  break;
723
752
  }
724
753
  }
@@ -762,10 +791,15 @@ if ($act -eq "move") {
762
791
  async closeApplication(appName) {
763
792
  try {
764
793
  if (process.platform === 'win32') {
765
- const cleanName = appName.replace(/\.exe$/i, '');
794
+ const resolved = this.resolveCanonicalApp(appName);
766
795
  const driverRes = await this.runDriverAction('close_window', [appName]);
767
796
  if (!driverRes || !driverRes.success) {
768
- await execAsync(`powershell -NoProfile -Command "Stop-Process -Name '${cleanName}' -Force -ErrorAction SilentlyContinue"`);
797
+ for (const pName of resolved.processNames) {
798
+ try {
799
+ await execAsync(`powershell -NoProfile -Command "Stop-Process -Name '${pName}' -Force -ErrorAction SilentlyContinue"`);
800
+ }
801
+ catch { }
802
+ }
769
803
  }
770
804
  }
771
805
  else {
@@ -559,9 +559,91 @@ namespace Scout.ComputerControl
559
559
  {
560
560
  string targetApp = appName.Trim();
561
561
  string targetArgs = appArgs ?? "";
562
+ string lowerApp = targetApp.ToLowerInvariant();
562
563
 
563
- // Blender candidate discovery if app is blender
564
- if (targetApp.IndexOf("blender", StringComparison.OrdinalIgnoreCase) >= 0)
564
+ if (lowerApp == "calc" || lowerApp == "calculator" || lowerApp == "wincalc")
565
+ {
566
+ targetApp = "calc.exe";
567
+ }
568
+ else if (lowerApp == "vscode" || lowerApp == "vs code" || lowerApp == "code" || lowerApp == "visual studio code")
569
+ {
570
+ targetApp = "code";
571
+ }
572
+ else if (lowerApp == "notepad" || lowerApp == "text editor" || lowerApp == "editor")
573
+ {
574
+ targetApp = "notepad.exe";
575
+ }
576
+ else if (lowerApp == "chrome" || lowerApp == "google chrome" || lowerApp == "google-chrome")
577
+ {
578
+ string localApp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
579
+ string[] chromeCandidates = new string[]
580
+ {
581
+ @"C:\Program Files\Google\Chrome\Application\chrome.exe",
582
+ @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
583
+ Path.Combine(localApp, @"Google\Chrome\Application\chrome.exe")
584
+ };
585
+ foreach (string cPath in chromeCandidates)
586
+ {
587
+ if (File.Exists(cPath)) { targetApp = cPath; break; }
588
+ }
589
+ if (targetApp.IndexOf("chrome", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "chrome.exe";
590
+ }
591
+ else if (lowerApp == "edge" || lowerApp == "msedge" || lowerApp == "microsoft edge")
592
+ {
593
+ string[] edgeCandidates = new string[]
594
+ {
595
+ @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
596
+ @"C:\Program Files\Microsoft\Edge\Application\msedge.exe"
597
+ };
598
+ foreach (string ePath in edgeCandidates)
599
+ {
600
+ if (File.Exists(ePath)) { targetApp = ePath; break; }
601
+ }
602
+ if (targetApp.IndexOf("msedge", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "msedge.exe";
603
+ }
604
+ else if (lowerApp == "brave" || lowerApp == "brave browser")
605
+ {
606
+ string localApp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
607
+ string[] braveCandidates = new string[]
608
+ {
609
+ @"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe",
610
+ Path.Combine(localApp, @"BraveSoftware\Brave-Browser\Application\brave.exe")
611
+ };
612
+ foreach (string bPath in braveCandidates)
613
+ {
614
+ if (File.Exists(bPath)) { targetApp = bPath; break; }
615
+ }
616
+ if (targetApp.IndexOf("brave", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "brave.exe";
617
+ }
618
+ else if (lowerApp == "explorer" || lowerApp == "file explorer" || lowerApp == "files")
619
+ {
620
+ targetApp = "explorer.exe";
621
+ if (string.IsNullOrEmpty(targetArgs)) targetArgs = ".";
622
+ }
623
+ else if (lowerApp == "terminal" || lowerApp == "wt" || lowerApp == "windows terminal")
624
+ {
625
+ targetApp = "wt.exe";
626
+ }
627
+ else if (lowerApp == "cmd" || lowerApp == "command prompt")
628
+ {
629
+ targetApp = "cmd.exe";
630
+ }
631
+ else if (lowerApp == "powershell" || lowerApp == "pwsh")
632
+ {
633
+ targetApp = "powershell.exe";
634
+ }
635
+ else if (lowerApp == "paint" || lowerApp == "mspaint")
636
+ {
637
+ targetApp = "mspaint.exe";
638
+ }
639
+ else if (lowerApp == "spotify")
640
+ {
641
+ string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
642
+ string sPath = Path.Combine(appData, @"Spotify\Spotify.exe");
643
+ if (File.Exists(sPath)) targetApp = sPath;
644
+ else targetApp = "spotify.exe";
645
+ }
646
+ else if (targetApp.IndexOf("blender", StringComparison.OrdinalIgnoreCase) >= 0)
565
647
  {
566
648
  string[] blenderCandidates = new string[]
567
649
  {
@@ -15,6 +15,8 @@ dotenv.config({ quiet: true });
15
15
  const openaiApiKey = process.env.OPENAI_API_KEY;
16
16
  const geminiApiKey = process.env.GEMINI_API_KEY;
17
17
  const nvidiaApiKey = process.env.NVIDIA_API_KEY || process.env.NVCF_API_KEY;
18
+ const ftApiKey = process.env.FRONTTERRAIN_API_KEY || process.env.FT_API_KEY;
19
+ const ftApiBase = process.env.FRONTTERRAIN_API_BASE || process.env.FT_API_BASE || 'https://api.frontterrain.com/v1';
18
20
  const authConfig = loadAuthConfig();
19
21
  const byokApiKey = authConfig.byokEnabled ? authConfig.customApiKey?.trim() : undefined;
20
22
  const byokProvider = authConfig.customLlmProvider?.trim().toLowerCase();
@@ -22,6 +24,7 @@ const byokDefaultBaseUrls = {
22
24
  openai: 'https://api.openai.com/v1',
23
25
  gemini: 'https://generativelanguage.googleapis.com/v1beta/openai',
24
26
  nvidia: 'https://integrate.api.nvidia.com/v1',
27
+ frontterrain: ftApiBase,
25
28
  };
26
29
  const byokBaseUrl = byokApiKey
27
30
  ? authConfig.customBaseUrl?.trim() || byokDefaultBaseUrls[byokProvider || '']
@@ -36,6 +39,15 @@ export function getClientForModel(modelName) {
36
39
  return clientCache.get('byok');
37
40
  }
38
41
  const modelLower = (modelName || '').toLowerCase();
42
+ // FrontTerrain Native Custom Models (Plug & Play when trained/hosted)
43
+ if (modelLower.startsWith('frontterrain/') || modelLower.startsWith('ft/') || modelLower.includes('frontterrain')) {
44
+ const key = ftApiKey || authConfig.customApiKey || nvidiaApiKey || 'ft-native';
45
+ const base = ftApiBase;
46
+ if (!clientCache.has('frontterrain')) {
47
+ clientCache.set('frontterrain', new OpenAI({ apiKey: key, baseURL: base, timeout: 60000 }));
48
+ }
49
+ return clientCache.get('frontterrain');
50
+ }
39
51
  if ((modelLower.startsWith('nvidia/') || modelLower.startsWith('meta/') || modelLower.includes('nemotron') || modelLower.startsWith('deepseek-ai/') || modelLower.startsWith('poolside/') || modelLower.startsWith('mistralai/')) && nvidiaApiKey) {
40
52
  if (!clientCache.has('nvidia')) {
41
53
  clientCache.set('nvidia', new OpenAI({ apiKey: nvidiaApiKey, baseURL: 'https://integrate.api.nvidia.com/v1', timeout: 60000 }));
@@ -101,6 +113,10 @@ export const openai = new Proxy({}, {
101
113
  }
102
114
  });
103
115
  export const AGENT_MODEL_FALLBACKS = [
116
+ ...(ftApiKey || byokProvider === 'frontterrain' ? [
117
+ 'frontterrain/scout-code-1',
118
+ 'frontterrain/scout-reasoner-1',
119
+ ] : []),
104
120
  ...(nvidiaApiKey || byokProvider === 'nvidia' ? [
105
121
  'nvidia/nemotron-3.5-bolt-e4b',
106
122
  'nvidia/nemotron-3.5-lightning-30b-a3b',
@@ -17,59 +17,89 @@ export function checkSimpleAppAction(objective) {
17
17
  if (hasSecondaryWork) {
18
18
  return { isSimple: false };
19
19
  }
20
- // Known apps dictionary
20
+ // Known apps dictionary with common aliases
21
21
  const knownApps = [
22
22
  'google chrome', 'chrome', 'notepad', 'calculator', 'calc',
23
- 'excel', 'word', 'paint', 'terminal', 'powershell', 'cmd',
24
- 'command prompt', 'browser', 'vs code', 'vscode', 'edge',
25
- 'firefox', 'spotify', 'slack', 'discord', 'file explorer', 'explorer'
23
+ 'excel', 'word', 'paint', 'mspaint', 'terminal', 'powershell', 'cmd',
24
+ 'command prompt', 'browser', 'vs code', 'vscode', 'code', 'edge',
25
+ 'firefox', 'spotify', 'slack', 'discord', 'file explorer', 'explorer',
26
+ 'blender', 'brave'
26
27
  ];
28
+ const cleanAppCandidate = (str) => {
29
+ return str
30
+ .replace(/^(the|a|an)\s+/i, '')
31
+ .replace(/\s+(app|application|browser)$/i, '')
32
+ .trim();
33
+ };
27
34
  const isExactAppMatch = (target, app) => {
28
- return target === app || target === `${app} browser` || target === `${app} app` || target === `${app} application`;
35
+ const cleaned = cleanAppCandidate(target);
36
+ return cleaned === app || target === app || target === `${app} browser` || target === `${app} app` || target === `${app} application`;
37
+ };
38
+ const resolveMatchedApp = (rawTarget) => {
39
+ const cleaned = cleanAppCandidate(rawTarget);
40
+ const match = knownApps.find(app => isExactAppMatch(cleaned, app) || isExactAppMatch(rawTarget, app));
41
+ if (match)
42
+ return match;
43
+ // If it's a clean 1-2 word identifier without special punctuation, treat as valid desktop app
44
+ if (/^[a-zA-Z0-9_\-\s]{2,30}$/.test(cleaned) && !/\b(something|anything|everything|nothing|task|job|work)\b/i.test(cleaned)) {
45
+ return cleaned;
46
+ }
47
+ return undefined;
29
48
  };
30
- // English patterns: (open|launch|start|run) [the] [app]
49
+ // 1. English patterns: (open|launch|start|run) [the] [app]
31
50
  const openMatch = clean.match(/^(open|launch|start|run)\s+(?:the\s+)?(.+)$/i);
32
51
  if (openMatch && openMatch[2]) {
33
- const target = openMatch[2].trim();
34
- const matchedApp = knownApps.find(app => isExactAppMatch(target, app));
35
- if (matchedApp) {
36
- return { isSimple: true, action: 'open', appName: matchedApp };
52
+ const resolved = resolveMatchedApp(openMatch[2]);
53
+ if (resolved) {
54
+ return { isSimple: true, action: 'open', appName: resolved };
37
55
  }
38
56
  }
39
- // English close patterns: (close|kill|exit|quit|stop) [the] [app]
57
+ // 2. English close patterns: (close|kill|exit|quit|stop) [the] [app]
40
58
  const closeMatch = clean.match(/^(close|kill|exit|quit|stop)\s+(?:the\s+)?(.+)$/i);
41
59
  if (closeMatch && closeMatch[2]) {
42
- const target = closeMatch[2].trim();
43
- const matchedApp = knownApps.find(app => isExactAppMatch(target, app));
44
- if (matchedApp) {
45
- return { isSimple: true, action: 'close', appName: matchedApp };
60
+ const resolved = resolveMatchedApp(closeMatch[2]);
61
+ if (resolved) {
62
+ return { isSimple: true, action: 'close', appName: resolved };
46
63
  }
47
64
  }
48
- // English switch/focus patterns: (switch to|focus|bring up) [the] [app]
65
+ // 3. English switch/focus patterns: (switch to|focus|bring up) [the] [app]
49
66
  const switchMatch = clean.match(/^(switch\s+to|focus|bring\s+up)\s+(?:the\s+)?(.+)$/i);
50
67
  if (switchMatch && switchMatch[2]) {
51
- const target = switchMatch[2].trim();
52
- const matchedApp = knownApps.find(app => isExactAppMatch(target, app));
53
- if (matchedApp) {
54
- return { isSimple: true, action: 'switch', appName: matchedApp };
68
+ const resolved = resolveMatchedApp(switchMatch[2]);
69
+ if (resolved) {
70
+ return { isSimple: true, action: 'switch', appName: resolved };
71
+ }
72
+ }
73
+ // 4. Hinglish Verb-First Open: (khol do|kholo|khol|chala do|chalao|chala|open karo|launch karo|start karo) [app]
74
+ const hinglishVerbOpenMatch = clean.match(/^(khol\s+do|kholo|khol|chala\s+do|chalao|chala|open\s+karo|launch\s+karo|start\s+karo)\s+(?:the\s+)?(.+)$/i);
75
+ if (hinglishVerbOpenMatch && hinglishVerbOpenMatch[2]) {
76
+ const resolved = resolveMatchedApp(hinglishVerbOpenMatch[2]);
77
+ if (resolved) {
78
+ return { isSimple: true, action: 'open', appName: resolved };
79
+ }
80
+ }
81
+ // 5. Hinglish App-First Open: [app] (open|khol|kholo|chala|chalao|launch|start) (karo|kar do|kar|do|karna|dena)?
82
+ const hinglishAppOpenMatch = clean.match(/^(.+?)\s+(open|khol|kholo|chala|chalao|launch|start)\s*(karo|kar do|kar|do|karna|dena)?$/i);
83
+ if (hinglishAppOpenMatch && hinglishAppOpenMatch[1]) {
84
+ const resolved = resolveMatchedApp(hinglishAppOpenMatch[1]);
85
+ if (resolved) {
86
+ return { isSimple: true, action: 'open', appName: resolved };
55
87
  }
56
88
  }
57
- // Hinglish patterns: [app] (open|khol|chala|launch) (karo|kar do|do|karna)
58
- const hinglishOpenMatch = clean.match(/^(.+?)\s+(open|khol|chala|launch)\s*(karo|kar do|do|karna|dena)?$/i);
59
- if (hinglishOpenMatch && hinglishOpenMatch[1]) {
60
- const target = hinglishOpenMatch[1].trim();
61
- const matchedApp = knownApps.find(app => target === app || target === `${app} browser` || target === `${app} app`);
62
- if (matchedApp) {
63
- return { isSimple: true, action: 'open', appName: matchedApp };
89
+ // 6. Hinglish Verb-First Close: (band kar do|band karo|band kar|close karo|kill karo) [app]
90
+ const hinglishVerbCloseMatch = clean.match(/^(band\s+kar\s+do|band\s+karo|band\s+kar|close\s+karo|kill\s+karo)\s+(?:the\s+)?(.+)$/i);
91
+ if (hinglishVerbCloseMatch && hinglishVerbCloseMatch[2]) {
92
+ const resolved = resolveMatchedApp(hinglishVerbCloseMatch[2]);
93
+ if (resolved) {
94
+ return { isSimple: true, action: 'close', appName: resolved };
64
95
  }
65
96
  }
66
- // Hinglish close patterns: [app] (close|band|kill) (karo|kar do|do|karna)
67
- const hinglishCloseMatch = clean.match(/^(.+?)\s+(close|band|kill)\s*(karo|kar do|do|karna|dena)?$/i);
68
- if (hinglishCloseMatch && hinglishCloseMatch[1]) {
69
- const target = hinglishCloseMatch[1].trim();
70
- const matchedApp = knownApps.find(app => target === app || target === `${app} browser` || target === `${app} app`);
71
- if (matchedApp) {
72
- return { isSimple: true, action: 'close', appName: matchedApp };
97
+ // 7. Hinglish App-First Close: [app] (close|band|kill) (karo|kar do|kar|do|karna|dena)?
98
+ const hinglishAppCloseMatch = clean.match(/^(.+?)\s+(close|band|kill)\s*(karo|kar do|kar|do|karna|dena)?$/i);
99
+ if (hinglishAppCloseMatch && hinglishAppCloseMatch[1]) {
100
+ const resolved = resolveMatchedApp(hinglishAppCloseMatch[1]);
101
+ if (resolved) {
102
+ return { isSimple: true, action: 'close', appName: resolved };
73
103
  }
74
104
  }
75
105
  return { isSimple: false };