refactor: derive Host type and HOST_PATHS from host configs

types.ts no longer hardcodes host names or paths. The Host type is
derived from ALL_HOST_CONFIGS in hosts/index.ts, and HOST_PATHS is
built dynamically from each config's globalRoot/localSkillRoot/usesEnvVars.
Adding a new host to hosts/index.ts automatically extends the type system.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-03 15:50:57 -07:00
parent ae7dd311f2
commit 4a1a70c2c7
+39 -24
View File
@@ -1,4 +1,11 @@
export type Host = 'claude' | 'codex' | 'factory';
import { ALL_HOST_CONFIGS } from '../../hosts/index';
/**
* Host type — derived from host configs in hosts/*.ts.
* Adding a new host: create hosts/myhost.ts + add to hosts/index.ts.
* Do NOT hardcode host names here.
*/
export type Host = (typeof ALL_HOST_CONFIGS)[number]['name'];
export interface HostPaths {
skillRoot: string;
@@ -8,29 +15,37 @@ export interface HostPaths {
designDir: string;
}
export const HOST_PATHS: Record<Host, HostPaths> = {
claude: {
skillRoot: '~/.claude/skills/gstack',
localSkillRoot: '.claude/skills/gstack',
binDir: '~/.claude/skills/gstack/bin',
browseDir: '~/.claude/skills/gstack/browse/dist',
designDir: '~/.claude/skills/gstack/design/dist',
},
codex: {
skillRoot: '$GSTACK_ROOT',
localSkillRoot: '.agents/skills/gstack',
binDir: '$GSTACK_BIN',
browseDir: '$GSTACK_BROWSE',
designDir: '$GSTACK_DESIGN',
},
factory: {
skillRoot: '$GSTACK_ROOT',
localSkillRoot: '.factory/skills/gstack',
binDir: '$GSTACK_BIN',
browseDir: '$GSTACK_BROWSE',
designDir: '$GSTACK_DESIGN',
},
};
/**
* HOST_PATHS — derived from host configs.
* Each config's globalRoot/localSkillRoot determines the path structure.
* Non-Claude hosts use $GSTACK_ROOT env vars (set by preamble).
*/
function buildHostPaths(): Record<string, HostPaths> {
const paths: Record<string, HostPaths> = {};
for (const config of ALL_HOST_CONFIGS) {
if (config.usesEnvVars) {
paths[config.name] = {
skillRoot: '$GSTACK_ROOT',
localSkillRoot: config.localSkillRoot,
binDir: '$GSTACK_BIN',
browseDir: '$GSTACK_BROWSE',
designDir: '$GSTACK_DESIGN',
};
} else {
const root = `~/${config.globalRoot}`;
paths[config.name] = {
skillRoot: root,
localSkillRoot: config.localSkillRoot,
binDir: `${root}/bin`,
browseDir: `${root}/browse/dist`,
designDir: `${root}/design/dist`,
};
}
}
return paths;
}
export const HOST_PATHS: Record<string, HostPaths> = buildHostPaths();
export interface TemplateContext {
skillName: string;