Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

resolve-executable.ts

25 lines1018 Bytes

1import type { SandboxHandle } from '@tanstack/ai-sandbox'
2​
3/** Prefer the path the official installer writes; fall back to PATH. */
4const GROK_PROBE =
5 'sh -lc \'if test -x "$HOME/.grok/bin/grok"; then printf "%s" "$HOME/.grok/bin/grok"; elif command -v grok >/dev/null 2>&1; then command -v grok; fi\''
6​
7/**
8 * Resolve the `grok` executable path inside a sandbox.
9 *
10 * Sandboxed providers often install the CLI under `$HOME/.grok/bin` without a
11 * global PATH entry (non-root images cannot write `/usr/local/bin`). Probe the
12 * sandbox before spawning the harness.
13 */
14export async function resolveGrokExecutable(
15 sandbox: SandboxHandle,
16 preferred?: string,
17): Promise<string> {
18 if (preferred !== undefined && preferred !== 'grok') return preferred
19 if (sandbox.provider === 'local-process') return preferred ?? 'grok'
20​
21 const probe = await sandbox.process.exec(GROK_PROBE)
22 const resolved = probe.stdout.trim()
23 if (probe.exitCode === 0 && resolved !== '') return resolved
24 return preferred ?? 'grok'