#!/usr/bin/env node /** * Generates `src/cli/src/config/prime-agent-extension.ts`, which embeds the * prime-agent `/mcpctl` switcher as a string constant — the same arrangement * the pi and opencode extensions use. * * The switcher used to live *only* as that string literal, with no source file * behind it, so nothing typechecked or linted it. Now `src/prime-agent-ext/` * holds the real source and this script produces the embed, so the file the CLI * writes into ~/.prime/agent/extensions/ is always exactly what was checked. * * Regenerate after editing the extension source: * npx tsx scripts/generate-prime-agent-extension.ts */ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'; import { dirname, join } from 'node:path'; const scriptsDir = import.meta.dirname; const root = join(scriptsDir, '..'); const extDir = join(root, 'src', 'prime-agent-ext'); const SOURCE = readFileSync(join(extDir, 'mcpctl-switch.ts'), 'utf-8'); const out = `/** * The source of the \`/mcpctl\` project-switcher extension, exported as a string * so \`mcpctl config prime-agent\` can install it into prime-agent's auto- * discovered extensions directory (\`~/.prime/agent/extensions/\`). * * DO NOT EDIT BY HAND. Generated by * \`npx tsx scripts/generate-prime-agent-extension.ts\` from * \`src/prime-agent-ext/mcpctl-switch.ts\` — edit that instead, so the change is * typechecked before it ships. The installed file is this exact source * (verbatim), so the extension the CLI writes is always the one that ran. */ export const MCPCTL_SWITCH_EXTENSION_FILENAME = 'mcpctl-switch.ts'; export const MCPCTL_SWITCH_EXTENSION = ${JSON.stringify(SOURCE)}; `; mkdirSync(dirname(join(root, 'src', 'cli', 'src', 'config')), { recursive: true }); writeFileSync(join(root, 'src', 'cli', 'src', 'config', 'prime-agent-extension.ts'), out); console.log('wrote src/cli/src/config/prime-agent-extension.ts');