Some checks failed
CI/CD / lint (pull_request) Successful in 1m10s
CI/CD / test (pull_request) Successful in 1m22s
CI/CD / typecheck (pull_request) Successful in 3m8s
CI/CD / smoke (pull_request) Failing after 1m55s
CI/CD / build (pull_request) Successful in 2m8s
CI/CD / publish (pull_request) Has been skipped
Implement mcpctl as an opencode addon mirroring the pi/prime-agent integrations. Mounts the active project's MCP gateway through opencode's own live MCP API, so switching projects needs no restart and opencode.json is never touched (the bearer token stays in a 0600 state file). - server plugin (plugin/mcpctl.ts): headless mount under a stable 'mcpctl' name, re-asserted on first contact + before each turn; skips re-registering an unchanged mount so a gated project's begin_session state survives. - TUI plugin (mcpctl/mcpctl-tui.tsx): /mcpctl filterable picker (live switch), /mcpctl-status, /mcpctl-skills, and a mcpctl:<project> footer indicator right of the model name, directly above the token counter. - mcpctl config opencode: mint/reuse project mcptoken, install + register plugins, write 0600 state, write marker, sync skills. - skills sync --agent opencode: new shared-tree target (XDG-aware). - shared credential plumbing lifted from config prime-agent and parameterised by agent so both hosts share mint/reuse/retire logic. - embedded-source generator + freshness test; typechecked against the real @opencode-ai/plugin types (1.18.15); unit tests for settings, order, embed. typecheck (incl. opencode-ext) and the full cli suite (619 tests) pass.
56 lines
2.2 KiB
JavaScript
56 lines
2.2 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/
|
|
* so an installed binary with no source tree can still provision a working
|
|
* opencode integration.
|
|
*/
|
|
|
|
/** 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');
|