an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix: add Windows fallback discovery for Antigravity CLI (#592)
Hsien Weib7f2566d7dbd
diff --git a/src/main/pty.ts b/src/main/pty.tsindex 075d35e9..5c1a03a0 100644--- a/src/main/pty.ts+++ b/src/main/pty.ts@@ -6,7 +6,12 @@ import { spawnSync } from 'node:child_process';import { ensureKilled, hardKillTree } from './procKill';import { expandTilde } from './fs';import { buildPtyEnv } from './ptyEnv';-import { captureFromLoginShell, isSafeCommandName, userShellPath } from './shellEnv';+import {+ captureFromLoginShell,+ isSafeCommandName,+ userShellPath,+ windowsFallbackCandidates+} from './shellEnv';/** APPEND the hive's bundled-node dir (`<HIVE_ROOT>/bin/runtime`, which holds a* shim literally named `node`) to a child's PATH.@@ -462,16 +467,7 @@ export class PtyManager {if (exe) return { path: exe, found: true };} catch { /* fall through */ }// Common Windows install locations (npm global = %APPDATA%\npm\<cmd>.cmd).- const appData = process.env.APPDATA ?? '';- const localAppData = process.env.LOCALAPPDATA ?? '';- const home = process.env.USERPROFILE ?? process.env.HOME ?? '';- const winCandidates = [- `${appData}\\npm\\${command}.cmd`,- `${appData}\\npm\\${command}`,- `${localAppData}\\Programs\\claude\\${command}.exe`,- `${home}\\.claude\\local\\${command}.cmd`,- `${home}\\.claude\\local\\${command}`- ];+ const winCandidates = windowsFallbackCandidates(command);for (const c of winCandidates) if (existsSync(c)) return { path: c, found: true };// Last resort — let node-pty try; will fail with ENOENT if missing.return { path: command, found: false };diff --git a/src/main/shellEnv.ts b/src/main/shellEnv.tsindex 64c29d7c..9a4177ed 100644--- a/src/main/shellEnv.ts+++ b/src/main/shellEnv.ts@@ -1,5 +1,6 @@import { existsSync } from 'node:fs';import { spawnSync } from 'node:child_process';+import { win32 } from 'node:path';// These helpers mirror the resolution logic in pty.ts. They exist separately so// headless child processes can launch `claude` with the same PATH the user's@@ -83,6 +84,61 @@ export function isSafeCommandName(command: string): boolean {return /^[A-Za-z0-9._+-]+$/.test(command);}+interface WindowsFallbackLocation {+ commands: readonly string[];+ root: 'LOCALAPPDATA';+ segments: readonly string[];+}++/** Known provider-specific Windows locations, checked after the established+ * npm/Claude fallbacks. Keep filesystem knowledge here so another verified+ * installer location can be added without branching either resolver. */+const WINDOWS_FALLBACK_LOCATIONS: readonly WindowsFallbackLocation[] = [+ {+ commands: ['agy'],+ root: 'LOCALAPPDATA',+ segments: ['agy', 'bin', 'agy.exe']+ }+];++function isAbsoluteWindowsPathWithVolume(path: string): boolean {+ if (!win32.isAbsolute(path)) return false;+ const root = win32.parse(path).root;+ // win32.isAbsolute also accepts `\foo` and `/c/foo`, which are rooted only+ // relative to the current drive (or are MSYS syntax), not stable env roots.+ return root !== '\\' && root !== '/';+}++/** Build Windows fallback candidates only; callers retain their own PATH lookup,+ * existence checks, caching, and spawn semantics. */+export function windowsFallbackCandidates(+ command: string,+ env: NodeJS.ProcessEnv = process.env+): string[] {+ const appData = env.APPDATA ?? '';+ const localAppData = env.LOCALAPPDATA ?? '';+ const home = env.USERPROFILE ?? env.HOME ?? '';+ const candidates = [+ `${appData}\\npm\\${command}.cmd`,+ `${appData}\\npm\\${command}`,+ `${localAppData}\\Programs\\claude\\${command}.exe`,+ `${home}\\.claude\\local\\${command}.cmd`,+ `${home}\\.claude\\local\\${command}`+ ];+ const normalizedCommand = command.replace(/\.exe$/i, '').toLowerCase();++ for (const location of WINDOWS_FALLBACK_LOCATIONS) {+ if (!location.commands.includes(normalizedCommand)) continue;+ const root = env[location.root];+ // Provider-specific additions fail closed: an absent, relative, or POSIX+ // root must not turn into a plausible-looking Windows path.+ if (!root || !isAbsoluteWindowsPathWithVolume(root)) continue;+ candidates.push(win32.join(root, ...location.segments));+ }++ return candidates;+}+export function resolveCommand(command: string): string {// Already an absolute/relative path (Unix `/` or Windows `\`) — pass through.if (command.includes('/') || command.includes('\\')) return command;@@ -98,16 +154,7 @@ export function resolveCommand(command: string): string {const path = (res.stdout ?? '').trim().split(/\r?\n/)[0];if (path && existsSync(path)) return path;} catch { /* fall through */ }- const appData = process.env.APPDATA ?? '';- const localAppData = process.env.LOCALAPPDATA ?? '';- const home = process.env.USERPROFILE ?? process.env.HOME ?? '';- const winCandidates = [- `${appData}\\npm\\${command}.cmd`,- `${appData}\\npm\\${command}`,- `${localAppData}\\Programs\\claude\\${command}.exe`,- `${home}\\.claude\\local\\${command}.cmd`,- `${home}\\.claude\\local\\${command}`- ];+ const winCandidates = windowsFallbackCandidates(command);for (const c of winCandidates) if (existsSync(c)) return c;return command;}diff --git a/test/windows-command-fallback.test.cjs b/test/windows-command-fallback.test.cjsnew file mode 100644index 00000000..116c03fb--- /dev/null+++ b/test/windows-command-fallback.test.cjs@@ -0,0 +1,106 @@+'use strict';++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const os = require('node:os');+const path = require('node:path');+const loadTs = require('./load-ts.cjs');++const { resolveCommand, windowsFallbackCandidates } = loadTs('src/main/shellEnv.ts');+const { PtyManager } = loadTs('src/main/pty.ts');++const WINDOWS_ENV = {+ APPDATA: 'C:\\Users\\Tester\\AppData\\Roaming',+ LOCALAPPDATA: 'C:\\Users\\Tester\\AppData\\Local',+ USERPROFILE: 'C:\\Users\\Tester'+};++function genericCandidates(command, env = WINDOWS_ENV) {+ const appData = env.APPDATA ?? '';+ const localAppData = env.LOCALAPPDATA ?? '';+ const home = env.USERPROFILE ?? env.HOME ?? '';+ return [+ `${appData}\\npm\\${command}.cmd`,+ `${appData}\\npm\\${command}`,+ `${localAppData}\\Programs\\claude\\${command}.exe`,+ `${home}\\.claude\\local\\${command}.cmd`,+ `${home}\\.claude\\local\\${command}`+ ];+}++test('agy adds its official LOCALAPPDATA location after existing fallbacks', () => {+ assert.deepEqual(windowsFallbackCandidates('agy', WINDOWS_ENV), [+ ...genericCandidates('agy'),+ 'C:\\Users\\Tester\\AppData\\Local\\agy\\bin\\agy.exe'+ ]);+});++test('Antigravity fallback lookup normalizes command case and an exe suffix', () => {+ for (const command of ['AGY', 'agy.exe', 'AGY.EXE']) {+ assert.equal(+ windowsFallbackCandidates(command, WINDOWS_ENV).at(-1),+ 'C:\\Users\\Tester\\AppData\\Local\\agy\\bin\\agy.exe',+ command+ );+ }+});++test('fallbacks do not map agy to the unverified antigravity.cmd launcher', () => {+ assert.ok(+ windowsFallbackCandidates('agy', WINDOWS_ENV).every((candidate) => !candidate.endsWith('antigravity.cmd'))+ );+});++test('Codex, OpenCode, and Claude retain the existing generic fallback order', () => {+ for (const command of ['codex', 'opencode', 'claude']) {+ assert.deepEqual(windowsFallbackCandidates(command, WINDOWS_ENV), genericCandidates(command));+ }+});++test('missing or invalid LOCALAPPDATA does not add an Antigravity candidate', () => {+ for (const localAppData of [+ undefined,+ '',+ 'relative-path',+ '\\Users\\Tester\\AppData\\Local',+ '/c/Users/Tester/AppData/Local'+ ]) {+ const env = { ...WINDOWS_ENV, LOCALAPPDATA: localAppData };+ assert.deepEqual(windowsFallbackCandidates('agy', env), genericCandidates('agy', env));+ }+});++test('Antigravity fallback preserves spaces and Unicode in LOCALAPPDATA', () => {+ for (const localAppData of [+ 'C:\\Users\\Test User\\AppData\\Local',+ 'C:\\使用者\\測試\\AppData\\Local',+ '\\\\server\\share\\Profile'+ ]) {+ const candidates = windowsFallbackCandidates('agy', { ...WINDOWS_ENV, LOCALAPPDATA: localAppData });+ assert.equal(candidates.at(-1), path.win32.join(localAppData, 'agy', 'bin', 'agy.exe'));+ }+});++test('resolveCommand finds agy in its Windows LOCALAPPDATA install location', { skip: process.platform !== 'win32' }, (t) => {+ const localAppData = fs.mkdtempSync(path.join(os.tmpdir(), 'munder-agy-'));+ const executable = path.join(localAppData, 'agy', 'bin', 'agy.exe');+ const previousLocalAppData = process.env.LOCALAPPDATA;+ const previousPath = process.env.PATH;++ t.after(() => {+ if (previousLocalAppData === undefined) delete process.env.LOCALAPPDATA;+ else process.env.LOCALAPPDATA = previousLocalAppData;+ if (previousPath === undefined) delete process.env.PATH;+ else process.env.PATH = previousPath;+ fs.rmSync(localAppData, { recursive: true, force: true });+ });++ fs.mkdirSync(path.dirname(executable), { recursive: true });+ fs.writeFileSync(executable, '');+ process.env.LOCALAPPDATA = localAppData;+ process.env.PATH = path.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32');++ assert.equal(resolveCommand('agy'), executable);+ assert.equal(new PtyManager().commandPath('agy'), executable);+});