mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-02 11:45:20 +02:00
4a1a70c2c7
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>
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
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;
|
|
localSkillRoot: string;
|
|
binDir: string;
|
|
browseDir: string;
|
|
designDir: string;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
tmplPath: string;
|
|
benefitsFrom?: string[];
|
|
host: Host;
|
|
paths: HostPaths;
|
|
preambleTier?: number; // 1-4, controls which preamble sections are included
|
|
}
|
|
|
|
/** Resolver function signature. args is populated for parameterized placeholders like {{INVOKE_SKILL:name}}. */
|
|
export type ResolverFn = (ctx: TemplateContext, args?: string[]) => string;
|