Some checks failed
CI/CD / typecheck (pull_request) Successful in 1m16s
CI/CD / test (pull_request) Successful in 1m25s
CI/CD / lint (pull_request) Successful in 2m42s
CI/CD / smoke (pull_request) Failing after 1m59s
CI/CD / build (pull_request) Successful in 4m54s
CI/CD / publish (pull_request) Has been skipped
Implements mcpctl as an opencode addon, mirroring the prime-agent UX (active-project indicator + a /mcpctl project switcher). opencode is a native MCP client, so instead of a bridge this mounts the active project's proxy MCP gateway through opencode's own live MCP API. - src/opencode-ext/mcpctl-opencode.ts — server plugin (headless runs): mounts the active project under a stable `mcpctl` name via `client.mcp.add`, re-asserting on first contact and before each turn; never throws. - src/opencode-ext/mcpctl-opencode-tui.tsx — TUI plugin: `/mcpctl`, `/mcpctl-status`, `/mcpctl-skills`, and a `mcpctl:<project>` indicator in the prompt footer (next to the model name, above the token counter); the switch delegates to the CLI then re-points the mount live. - `mcpctl config opencode` — provision/reuse the project mcptoken, install + register the plugins (tui.json), write the 0600 state file, sync skills. - `skills sync --agent opencode` — new shared-tree target (~/.config/opencode/skill). - embedded-source generator + embed test, settings/config/order tests, completions, README + docs/opencode-extension.md. Typechecked against the real @opencode-ai/plugin types (1.18.15).
63 lines
2.6 KiB
JavaScript
63 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Generates `src/cli/src/config/opencode-extension.ts`, which embeds the two
|
|
* opencode plugin sources as string constants — mirroring how the pi extension
|
|
* (`pi-extension.ts`) and prime-agent's `/mcpctl` switcher
|
|
* (`prime-agent-extension.ts`) are embedded.
|
|
*
|
|
* Embedding matters: `mcpctl config opencode` must work from an installed
|
|
* binary that has no access to the source tree. The installed plugin files are
|
|
* this exact embedded source, so what the CLI ships is always what opencode
|
|
* runs.
|
|
*
|
|
* Regenerate after editing the plugin sources:
|
|
* npx tsx scripts/generate-opencode-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', 'opencode-ext');
|
|
|
|
const SERVER = readFileSync(join(extDir, 'mcpctl-opencode.ts'), 'utf-8');
|
|
const TUI = readFileSync(join(extDir, 'mcpctl-opencode-tui.tsx'), 'utf-8');
|
|
|
|
function embed(src: string): string {
|
|
// JSON.stringify yields a quoted string literal we can inline directly.
|
|
return JSON.stringify(src);
|
|
}
|
|
|
|
const out = `/**
|
|
* Embedded source of the mcpctl opencode plugins — DO NOT EDIT BY HAND.
|
|
* Generated by \`npx tsx scripts/generate-opencode-extension.ts\` from
|
|
* \`src/opencode-ext/mcpctl-opencode.ts\` and
|
|
* \`src/opencode-ext/mcpctl-opencode-tui.tsx\`.
|
|
*
|
|
* \`mcpctl config opencode\` writes these verbatim into ~/.config/opencode/
|
|
* (and registers them), so an installed binary with no source tree can still
|
|
* provision a working opencode integration.
|
|
*
|
|
* The install file names differ from the source file names on purpose:
|
|
* - the server plugin lands in opencode's auto-discovered \`plugin/\` dir,
|
|
* where its basename is what shows up in \`opencode plugin list\`;
|
|
* - the TUI plugin lands beside it in \`mcpctl/\`, referenced by path from
|
|
* \`tui.json\`, and must keep a \`.tsx\` extension for opencode to transpile
|
|
* its JSX.
|
|
*/
|
|
|
|
/** Install name of the server plugin, relative to ~/.config/opencode/plugin/. */
|
|
export const OPENCODE_SERVER_PLUGIN_FILENAME = 'mcpctl.ts';
|
|
|
|
/** Install name of the TUI plugin, relative to ~/.config/opencode/mcpctl/. */
|
|
export const OPENCODE_TUI_PLUGIN_FILENAME = 'mcpctl-tui.tsx';
|
|
|
|
export const OPENCODE_SERVER_PLUGIN_SOURCE: string = ${embed(SERVER)};
|
|
|
|
export const OPENCODE_TUI_PLUGIN_SOURCE: string = ${embed(TUI)};
|
|
`;
|
|
|
|
mkdirSync(dirname(join(root, 'src', 'cli', 'src', 'config')), { recursive: true });
|
|
writeFileSync(join(root, 'src', 'cli', 'src', 'config', 'opencode-extension.ts'), out);
|
|
console.log('wrote src/cli/src/config/opencode-extension.ts');
|