Skill Tracer
Skills › gstack › browse › project-slug.ts

project-slug.ts

36 lines · browse/src/project-slug.ts at 3f79d81

1/**
2 * Project slug resolution for the browse daemon.
3 *
4 * Used by domain-skills (per-project storage) and sidebar prompt-context
5 * injection. Cached after first call — slug is derived from the daemon's
6 * git remote (or env override) and doesn't change between commands.
7 */
8
9import * as path from 'path';
10import * as os from 'os';
11import { execSync } from 'child_process';
13let cachedSlug: string | null = null;
15export function getCurrentProjectSlug(): string {
16 if (cachedSlug) return cachedSlug;
17 const explicit = process.env.GSTACK_PROJECT_SLUG;
18 if (explicit) {
19 cachedSlug = explicit;
20 return explicit;
21 }
22 try {
23 const slugBin = path.join(os.homedir(), '.claude/skills/gstack/bin/gstack-slug');
24 const out = execSync(slugBin, { encoding: 'utf8', timeout: 2000, windowsHide: true }).trim();
25 const m = out.match(/SLUG="?([^"\n]+)"?/);
26 cachedSlug = m ? m[1]! : (out || 'unknown');
27 } catch {
28 cachedSlug = 'unknown';
29 }
30 return cachedSlug;
33/** Reset cache; for tests only. */
34export function _resetProjectSlugCache(): void {
35 cachedSlug = null;