~cytrogen/gstack

ref: c8c2cbba33ac7037d9196d545be8effed8bba9db gstack/browse/src/find-browse.ts -rw-r--r-- 1.6 KiB
c8c2cbba — Garry Tan docs: add /design-consultation skill to README (#127) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * find-browse — locate the gstack browse binary.
 *
 * Compiled to browse/dist/find-browse (standalone binary, no bun runtime needed).
 * Outputs the absolute path to the browse binary on stdout, or exits 1 if not found.
 */

import { existsSync } from 'fs';
import { join } from 'path';
import { homedir } from 'os';

// ─── Binary Discovery ───────────────────────────────────────────

function getGitRoot(): string | null {
  try {
    const proc = Bun.spawnSync(['git', 'rev-parse', '--show-toplevel'], {
      stdout: 'pipe',
      stderr: 'pipe',
    });
    if (proc.exitCode !== 0) return null;
    return proc.stdout.toString().trim();
  } catch {
    return null;
  }
}

export function locateBinary(): string | null {
  const root = getGitRoot();
  const home = homedir();

  // Workspace-local takes priority (for development)
  if (root) {
    const local = join(root, '.claude', 'skills', 'gstack', 'browse', 'dist', 'browse');
    if (existsSync(local)) return local;
  }

  // Global fallback
  const global = join(home, '.claude', 'skills', 'gstack', 'browse', 'dist', 'browse');
  if (existsSync(global)) return global;

  return null;
}

// ─── Main ───────────────────────────────────────────────────────

function main() {
  const bin = locateBinary();
  if (!bin) {
    process.stderr.write('ERROR: browse binary not found. Run: cd <skill-dir> && ./setup\n');
    process.exit(1);
  }

  console.log(bin);
}

main();