mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
Post-merge follow-ups for PR #329 (shared CLI executable resolution): - Negative-cache resolution misses with a doubling backoff (1min -> 5min cap, cliResolveRetryDelayMs, mirroring claudeVersionRetryDelayMs): the shared resolver cached success only, so a missing CLI re-ran the whole chain - ending in a synchronous interactive login-shell spawn bounded by the 5s EXEC_TIMEOUT_MS - on every /api/<cli>/status request and Run attempt, stalling the event loop each time, forever. Success still caches for the process lifetime, so an installed CLI is picked up within minutes without a restart. Tests drive the backoff via an injectable clock (createCliExecutableResolver `now` option, threaded through the createPiResolverForTest / createAntigravityResolverForTest wrappers). - Pass killSignal: 'SIGKILL' on the resolver's login-shell spawn and on the pi/claude --version probes: execFileSync's timeout only SENDS the kill signal and then keeps waiting for the child to exit, and interactive bash ignores SIGTERM, so a login shell stuck in a blocking .bash_profile survived the timeout and blocked the server permanently. - Restore test hermeticity (PR #329 deleted pi's VITEST guards, and one test pinned the deletion): under vitest the production resolver host now replaces un-injected IO primitives with inert stubs - no real PATH scanning, no login-shell spawns - and probePiVersion never executes a `pi` candidate again (`pi` is a generic binary name, so route tests hitting /api/pi/status executed whatever binary the machine carried). Tests opt in through the runCommand/isExecutableFile injection hooks or allowRealIoUnderVitest for real-filesystem fixtures. The deletion-pinning test is replaced by behavioral pins, including a real-executable fixture in the new test/pi-cli-resolver.test.ts that fails loudly if the pi gate is ever removed again. - Wire the six get*NotFoundMessage() exports (previously dead) into their intended call sites: the createSession throws in tmux-manager and the availability gates on POST /api/sessions and POST /api/quick-start in session-routes, replacing a third hardcoded copy of the text. A not-found error now names where resolution looked (server PATH, login shell, checked directories). npm run knip no longer reports any unused export from the resolver modules. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
/**
|
|
* @fileoverview Resolve the Antigravity CLI (`agy`) binary across common install paths.
|
|
*
|
|
* Mirrors gemini-cli-resolver.ts. Google's installer (antigravity.google/cli/install.sh)
|
|
* places the binary at ~/.local/bin/agy; the other locations cover manual installs.
|
|
*
|
|
* @module utils/antigravity-cli-resolver
|
|
*/
|
|
|
|
import { join } from 'node:path';
|
|
import { homedir } from 'node:os';
|
|
import {
|
|
createCliExecutableResolver,
|
|
formatCliNotFoundMessage,
|
|
type CliResolverHost,
|
|
} from './cli-executable-resolver.js';
|
|
|
|
/** Common directories where the Antigravity CLI binary may be installed */
|
|
const ANTIGRAVITY_SEARCH_DIRS = [
|
|
join(homedir(), '.local', 'bin'),
|
|
join(homedir(), '.antigravity', 'bin'),
|
|
'/usr/local/bin',
|
|
join(homedir(), '.bun', 'bin'),
|
|
join(homedir(), '.npm-global', 'bin'),
|
|
join(homedir(), 'bin'),
|
|
];
|
|
|
|
const ANTIGRAVITY_NOT_FOUND =
|
|
'Antigravity CLI not found. Install with: curl -fsSL https://antigravity.google/cli/install.sh | bash';
|
|
|
|
function createAntigravityResolver(host?: CliResolverHost, now?: () => number) {
|
|
return createCliExecutableResolver({ binary: 'agy', searchDirs: ANTIGRAVITY_SEARCH_DIRS, now }, host);
|
|
}
|
|
|
|
/** Creates an isolated Antigravity wrapper around an injected resolver host and clock. */
|
|
export function createAntigravityResolverForTest(host: CliResolverHost, now?: () => number) {
|
|
return createAntigravityResolver(host, now);
|
|
}
|
|
|
|
const antigravityResolver = createAntigravityResolver();
|
|
|
|
/**
|
|
* Finds the directory containing the `agy` binary.
|
|
* Checks `which agy` first, then falls back to common install locations.
|
|
*
|
|
* @returns Directory path, or null if not found
|
|
*/
|
|
export function resolveAntigravityDir(): string | null {
|
|
return antigravityResolver.resolve()?.directory ?? null;
|
|
}
|
|
|
|
/**
|
|
* Check if the Antigravity CLI is available on the system.
|
|
*/
|
|
export function isAntigravityAvailable(): boolean {
|
|
return resolveAntigravityDir() !== null;
|
|
}
|
|
|
|
export function getAntigravityNotFoundMessage(): string {
|
|
return formatCliNotFoundMessage(ANTIGRAVITY_NOT_FOUND, antigravityResolver.diagnostics());
|
|
}
|