fix(config pi): embed extension sources so installed binary is self-contained
- add scripts/generate-pi-extension.ts to embed src/pi-ext sources as string constants (mirrors prime-agent's embedded switcher pattern). - config pi now writes the embedded sources by default, so it works from an /usr/bin install with no source tree (--extension-dir overrides for dev). Verified installed binary writes files byte-identical to source. - add installEmbeddedExtension test.
This commit is contained in:
48
scripts/generate-pi-extension.ts
Normal file
48
scripts/generate-pi-extension.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Generates `src/cli/src/config/pi-extension.ts` which embeds the pi extension
|
||||
* sources (`mcpctl-pi.ts` + `mcp-http.ts`) as string constants, mirroring how
|
||||
* prime-agent's `/mcpctl` switcher is embedded (`prime-agent-extension.ts`).
|
||||
*
|
||||
* Embedding matters: `mcpctl config pi` must work from an installed binary
|
||||
* that has no access to the source tree. The installed extension files are this
|
||||
* exact embedded source, so what the CLI ships is always what pi runs.
|
||||
*
|
||||
* Regenerate after editing the extension sources:
|
||||
* npx tsx scripts/generate-pi-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 piExtDir = join(root, 'src', 'pi-ext');
|
||||
|
||||
const MAIN = readFileSync(join(piExtDir, 'mcpctl-pi.ts'), 'utf-8');
|
||||
const HTTP = readFileSync(join(piExtDir, 'mcp-http.ts'), 'utf-8');
|
||||
|
||||
function embed(src) {
|
||||
// JSON.stringify yields a quoted string literal we can inline directly.
|
||||
return JSON.stringify(src);
|
||||
}
|
||||
|
||||
const out = `/**
|
||||
* Embedded source of the mcpctl pi extension — DO NOT EDIT BY HAND.
|
||||
* Generated by \`npx tsx scripts/generate-pi-extension.ts\` from
|
||||
* \`src/pi-ext/mcpctl-pi.ts\` and \`src/pi-ext/mcp-http.ts\`.
|
||||
*
|
||||
* \`mcpctl config pi\` writes these verbatim into ~/.pi/agent/extensions/mcpctl/
|
||||
* (and registers them), so an installed binary with no source tree can still
|
||||
* provision a working pi integration.
|
||||
*/
|
||||
export const PI_EXTENSION_FILENAMES = ['mcpctl-pi.ts', 'mcp-http.ts'] as const;
|
||||
|
||||
export const PI_EXTENSION_FILES: Record<string, string> = {
|
||||
'mcpctl-pi.ts': ${embed(MAIN)},
|
||||
'mcp-http.ts': ${embed(HTTP)},
|
||||
};
|
||||
`;
|
||||
|
||||
mkdirSync(dirname(join(root, 'src', 'cli', 'src', 'config')), { recursive: true });
|
||||
writeFileSync(join(root, 'src', 'cli', 'src', 'config', 'pi-extension.ts'), out);
|
||||
console.log('wrote src/cli/src/config/pi-extension.ts');
|
||||
Reference in New Issue
Block a user