Files
Codeman/src/utils/antigravity-cli-resolver.ts
T

61 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-08-04 12:59:40 +02:00
/**
* @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';
2026-08-04 12:59:40 +02:00
import { homedir } from 'node:os';
import {
createCliExecutableResolver,
formatCliNotFoundMessage,
type CliResolverHost,
} from './cli-executable-resolver.js';
2026-08-04 12:59:40 +02:00
/** 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'),
2026-08-04 12:59:40 +02:00
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();
2026-08-04 12:59:40 +02:00
/**
* 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;
2026-08-04 12:59:40 +02:00
}
/**
* 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());
}