fix(computer): match launch paths to the running file and word background launch as an attempt

This commit is contained in:
Kelvin Amoaba
2026-11-14 01:57:00 +00:00
parent 5a7fd6f494
commit daf2673bfb
6 changed files with 34 additions and 26 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ App names work when unambiguous (`--app Spotify`). Use `--app pid:<number>` only
orca computer launch-app TextEdit --json
```
It starts the app in the background on macOS and Windows and leaves an app that's already running alone. The result's `delivery` says whether the app ended up in front. `--activate` brings it forward instead. Linux doesn't support it yet.
It asks macOS and Windows to start the app in the background and leaves an app that's already running alone. Some apps still come forward on their own, so the result's `delivery` says whether the app ended up in front. `--activate` brings it forward instead. Linux doesn't support it yet.
## Available actions
+13 -9
View File
@@ -1614,11 +1614,13 @@ function New-OrcaLaunchResult($Process, [bool]$Launched) {
[pscustomobject]@{ ok = $true; app = New-OrcaAppRecord $Process; launched = $Launched; delivery = $delivery }
}
function Find-OrcaRunningLaunchTarget([string]$ProcessName) {
function Find-OrcaRunningLaunchTarget([string]$ProcessName, [string]$ExecutablePath = "") {
# Why: starting a running app again usually opens a second window over the user's work; tray-only apps count too.
$session = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
$running = @(Get-Process -Name ([WildcardPattern]::Escape($ProcessName)) -ErrorAction SilentlyContinue | Where-Object { $_.SessionId -eq $session }) |
Sort-Object { $_.MainWindowHandle -eq 0 } | Select-Object -First 1
$running = @(Get-Process -Name ([WildcardPattern]::Escape($ProcessName)) -ErrorAction SilentlyContinue | Where-Object {
# A resolved executable must be that file, not another copy with the same name.
$_.SessionId -eq $session -and ([string]::IsNullOrEmpty($ExecutablePath) -or [string]$_.Path -ieq $ExecutablePath)
}) | Sort-Object { $_.MainWindowHandle -eq 0 } | Select-Object -First 1
if ($null -ne $running) { Assert-OrcaProcessAllowed $running }
$running
}
@@ -1626,14 +1628,16 @@ function Find-OrcaRunningLaunchTarget([string]$ProcessName) {
function Invoke-OrcaLaunchApp($Operation) {
$query = ([string]$Operation.app).Trim()
if ([string]::IsNullOrWhiteSpace($query)) { throw 'appNotFound("")' }
$queryName = if ([System.IO.Path]::IsPathRooted($query)) { [System.IO.Path]::GetFileName($query) } else { $query }
if ($queryName.EndsWith(".exe", [System.StringComparison]::OrdinalIgnoreCase)) { $queryName = $queryName.Substring(0, $queryName.Length - 4) }
$running = Find-OrcaRunningLaunchTarget $queryName
if ($null -ne $running) { return New-OrcaLaunchResult $running $false }
# A bare name means any running copy; a path means that file, checked once it resolves.
if (-not [System.IO.Path]::IsPathRooted($query)) {
$queryName = if ($query.EndsWith(".exe", [System.StringComparison]::OrdinalIgnoreCase)) { $query.Substring(0, $query.Length - 4) } else { $query }
$running = Find-OrcaRunningLaunchTarget $queryName
if ($null -ne $running) { return New-OrcaLaunchResult $running $false }
}
$executable = Resolve-OrcaLaunchExecutable $query
$executable = [System.IO.Path]::GetFullPath((Resolve-OrcaLaunchExecutable $query))
# Why: an App Paths alias can name a differently named executable.
$running = Find-OrcaRunningLaunchTarget ([System.IO.Path]::GetFileNameWithoutExtension($executable))
$running = Find-OrcaRunningLaunchTarget ([System.IO.Path]::GetFileNameWithoutExtension($executable)) $executable
if ($null -ne $running) { return New-OrcaLaunchResult $running $false }
$name = [System.IO.Path]::GetFileNameWithoutExtension($executable).ToLowerInvariant().Replace(" ", "")
foreach ($fragment in $BlockedAppFragments) {
+1 -1
View File
@@ -162,7 +162,7 @@ On Windows, these actions go through UI Automation when the control supports the
## Starting Apps
Start a closed app with `ORCA computer launch-app <app>`, not `open -a` or `Start-Process`: those bring the app to the front and take the user's keyboard. `launch-app` starts it in the background on macOS and Windows, leaves an app that is already running alone, and reports `delivery` as measured: some apps, such as many Electron apps, still bring their own window forward when they open. Pass `--activate` only when the user asked for the app to come forward. On Linux it fails with `unsupported_capability`, because a newly started app usually comes to the front there; ask the user before starting one another way.
Start a closed app with `ORCA computer launch-app <app>`, not `open -a` or `Start-Process`: those bring the app to the front and take the user's keyboard. `launch-app` asks macOS and Windows to start it in the background and leaves an app that is already running alone. Some apps, such as many Electron apps, still bring their own window forward when they open, so read `delivery`: if it says `foreground`, tell the user the app came to the front. Pass `--activate` only when the user asked for the app to come forward. On Linux it fails with `unsupported_capability`, because a newly started app usually comes to the front there; ask the user before starting one another way.
## Screenshots
+1 -1
View File
@@ -1183,7 +1183,7 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"",
"## Starting Apps",
"",
"Start a closed app with `ORCA computer launch-app <app>`, not `open -a` or `Start-Process`: those bring the app to the front and take the user's keyboard. `launch-app` starts it in the background on macOS and Windows, leaves an app that is already running alone, and reports `delivery` as measured: some apps, such as many Electron apps, still bring their own window forward when they open. Pass `--activate` only when the user asked for the app to come forward. On Linux it fails with `unsupported_capability`, because a newly started app usually comes to the front there; ask the user before starting one another way.",
"Start a closed app with `ORCA computer launch-app <app>`, not `open -a` or `Start-Process`: those bring the app to the front and take the user's keyboard. `launch-app` asks macOS and Windows to start it in the background and leaves an app that is already running alone. Some apps, such as many Electron apps, still bring their own window forward when they open, so read `delivery`: if it says `foreground`, tell the user the app came to the front. Pass `--activate` only when the user asked for the app to come forward. On Linux it fails with `unsupported_capability`, because a newly started app usually comes to the front there; ask the user before starting one another way.",
"",
"## Screenshots",
"",
+1 -1
View File
@@ -14,7 +14,7 @@ export function computerUseErrorRecoveryData(
case 'app_not_found':
return recoverWith(
'Run `orca computer list-apps --json` and retry with the exact app name or bundle ID.',
'If the app is not running, start it with `orca computer launch-app <app>` (macOS and Windows), which leaves the user in the app they are using; on Linux ask the user to.',
'If the app is not running, start it with `orca computer launch-app <app>` (macOS and Windows), which tries to leave the user in the app they are using (check its `delivery`); on Linux ask the user to.',
'If the target is a website or web app such as Gmail, choose the desktop browser app/window that contains it; `orca computer` app selectors refer to desktop apps, not website names.',
'Do not retry the same `orca computer ... --app <web app>` command unchanged.',
'If the desired browser is not listed, start it with `orca computer launch-app <browser>` so it opens in the background (macOS and Windows); on Linux ask the user to start it. Then retry `orca computer list-apps --json` and `orca computer list-windows --app <browser> --json`.'
+17 -13
View File
@@ -271,17 +271,21 @@ describe.skipIf(!isWindows || !e2eOptIn || process.env.CI !== 'true')(
)
async function foregroundWindowOwnerPid(): Promise<number> {
const { stdout } = await promisify(execFile)('powershell.exe', [
'-NoProfile',
'-NonInteractive',
'-Command',
const { stdout } = await promisify(execFile)(
'powershell.exe',
[
'Add-Type -Name Foreground -Namespace OrcaE2E -MemberDefinition \'[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);\'',
'$owner = [uint32]0',
'[void][OrcaE2E.Foreground]::GetWindowThreadProcessId([OrcaE2E.Foreground]::GetForegroundWindow(), [ref]$owner)',
'$owner'
].join('; ')
])
'-NoProfile',
'-NonInteractive',
'-Command',
[
'Add-Type -Name Foreground -Namespace OrcaE2E -MemberDefinition \'[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);\'',
'$owner = [uint32]0',
'[void][OrcaE2E.Foreground]::GetWindowThreadProcessId([OrcaE2E.Foreground]::GetForegroundWindow(), [ref]$owner)',
'$owner'
].join('; ')
],
{ windowsHide: true }
)
return Number.parseInt(stdout.trim(), 10)
}
@@ -297,9 +301,9 @@ describe.skipIf(!isWindows || !e2eOptIn || process.env.CI !== 'true')(
afterAll(async () => {
if (launchedPid !== null) {
await promisify(execFile)('taskkill.exe', ['/PID', String(launchedPid), '/F']).catch(
() => {}
)
await promisify(execFile)('taskkill.exe', ['/PID', String(launchedPid), '/F'], {
windowsHide: true
}).catch(() => {})
}
await stopOrcaRuntime()
})