diff --git a/scripts/gen-skill-docs.ts b/scripts/gen-skill-docs.ts index 8ad828824..0be3ca9a1 100644 --- a/scripts/gen-skill-docs.ts +++ b/scripts/gen-skill-docs.ts @@ -158,15 +158,17 @@ const EXPLAIN_LEVEL: 'default' | 'terse' = (() => { // Conductor workspace — byte-compat pinned by gen-skill-docs-out-dir tests) // and the former TREE_MUTATING tests, which render into a mkdtemp instead // of mutating the live tree. Default (unset) = in-place, unchanged. -const OUT_DIR_ARG = process.argv.find(a => a.startsWith('--out-dir')); -const OUT_DIR: string | null = (() => { - if (!OUT_DIR_ARG) return null; - const val = OUT_DIR_ARG.includes('=') - ? OUT_DIR_ARG.split('=')[1] - : process.argv[process.argv.indexOf(OUT_DIR_ARG) + 1]; - if (!val) throw new Error('--out-dir requires a directory path'); +/** Parse `--flag ` / `--flag=` into an absolute path, or null when absent. */ +function parsePathFlag(flag: string): string | null { + const arg = process.argv.find(a => a.startsWith(flag)); + if (!arg) return null; + const val = arg.includes('=') + ? arg.split('=')[1] + : process.argv[process.argv.indexOf(arg) + 1]; + if (!val) throw new Error(`${flag} requires a directory path`); return path.resolve(val); -})(); +} +const OUT_DIR: string | null = parsePathFlag('--out-dir'); // #2692: callers that render into a TMP dir and atomically swap it into place // (bin/gstack-config gbrain-refresh, setup — the #2569 pattern) must pass the @@ -175,22 +177,15 @@ const OUT_DIR: string | null = (() => { // Read dies after the swap. Defaults to OUT_DIR for direct-render callers // (bin/dev-setup, scripts/dev-skill.ts, mkdtemp tests), where out-dir IS the // serving path. -const LINK_ROOT_ARG = process.argv.find(a => a.startsWith('--link-root')); -const LINK_ROOT: string | null = (() => { - if (!LINK_ROOT_ARG) return OUT_DIR; - const val = LINK_ROOT_ARG.includes('=') - ? LINK_ROOT_ARG.split('=')[1] - : process.argv[process.argv.indexOf(LINK_ROOT_ARG) + 1]; - if (!val) throw new Error('--link-root requires a directory path'); - return path.resolve(val); -})(); +const LINK_ROOT: string | null = parsePathFlag('--link-root') ?? OUT_DIR; /** * When rendering to an out-dir, repoint the literal section-base path at the - * out-dir so section Reads resolve to the rendered copy, not the global install. + * link root (--link-root, defaulting to --out-dir) so section Reads resolve + * to the SERVED copy, not the global install. * Surgical: ONLY paths containing `/sections/` are rewritten — bin/, browse/, * docs/ references keep pointing at `~/.claude/skills/gstack` (the global - * install, which still works). No-op when --out-dir is unset. + * install, which still works). No-op when neither flag is set. */ function rewriteSectionBase(content: string): string { if (!LINK_ROOT) return content;