feat(opencode): native opencode addon — bottom-row project indicator + in-TUI switcher
Some checks failed
CI/CD / lint (pull_request) Successful in 1m10s
CI/CD / test (pull_request) Successful in 1m23s
CI/CD / typecheck (pull_request) Successful in 2m58s
CI/CD / smoke (pull_request) Failing after 1m55s
CI/CD / build (pull_request) Successful in 4m56s
CI/CD / publish (pull_request) Has been skipped
Some checks failed
CI/CD / lint (pull_request) Successful in 1m10s
CI/CD / test (pull_request) Successful in 1m23s
CI/CD / typecheck (pull_request) Successful in 2m58s
CI/CD / smoke (pull_request) Failing after 1m55s
CI/CD / build (pull_request) Successful in 4m56s
CI/CD / publish (pull_request) Has been skipped
Adds an opencode integration mirroring the existing pi and prime-agent addons.
The addon is a TUI plugin (`src/opencode-ext/open-mcpctl.tsx`) that:
- renders the active mcpctl project into opencode's `app_bottom` slot — the
status row that also carries the token counter / model info,
- registers a `mcpctl.switch_project` command bound to `<leader>m` that opens a
searchable `DialogSelect` project picker,
- switches live by re-pointing opencode's `mcpctl` MCP server at the new
project's mcplocal endpoint via the SDK client (native MCP, no JSON-RPC code),
- persists state in `~/.mcpctl/opencode-state.json` (+ `.mcpctl-project` marker).
Pure helpers (`filterProjects`, `toolChangeAnnouncement`) live in
`projects.ts` so they are unit-tested.
`mcpctl config opencode --project X` provisions it: writes the plugin into
`~/.config/opencode/plugin/`, registers the `.tsx` in opencode.json's plugin
array (auto-discovery only matches {ts,js}), best-effort installs the TUI peer
deps (`@opentui/*`), and syncs skills into `~/.config/opencode/skill`.
`mcpctl skills sync --agent opencode` is added as a fourth shared-tree target.
Closes typecheck gap with `typecheck:opencode-ext` against the real
`@opencode-ai/plugin` + `@opentui/solid` types.
Tests: embed freshness, opencode-settings, projects helpers, skills agent
root. Full `pnpm run typecheck` + cli tests pass; completions regenerated.
This commit is contained in:
50
scripts/generate-opencode-extension.ts
Normal file
50
scripts/generate-opencode-extension.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Generates `src/cli/src/config/opencode-extension.ts` which embeds the opencode
|
||||
* plugin source (`open-mcpctl.tsx` + `projects.ts`) as string constants,
|
||||
* mirroring how the pi and prime-agent extensions 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 source:
|
||||
* 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 opencodeExtDir = join(root, 'src', 'opencode-ext');
|
||||
|
||||
const MAIN = readFileSync(join(opencodeExtDir, 'open-mcpctl.tsx'), 'utf-8');
|
||||
const PROJECTS = readFileSync(join(opencodeExtDir, 'projects.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 opencode plugin — DO NOT EDIT BY HAND.
|
||||
* Generated by \`npx tsx scripts/generate-opencode-extension.ts\` from
|
||||
* \`src/opencode-ext/open-mcpctl.tsx\` + \`src/opencode-ext/projects.ts\`.
|
||||
*
|
||||
* \`mcpctl config opencode\` writes these verbatim into
|
||||
* ~/.config/opencode/plugin/ and registers \`open-mcpctl.tsx\` in opencode.json's
|
||||
* plugin array, so an installed binary with no source tree can still provision
|
||||
* a working opencode integration.
|
||||
*/
|
||||
export const OPENCODE_EXTENSION_FILENAMES = ['open-mcpctl.tsx', 'projects.ts'] as const;
|
||||
|
||||
export const OPENCODE_EXTENSION_FILES: Record<string, string> = {
|
||||
'open-mcpctl.tsx': ${embed(MAIN)},
|
||||
'projects.ts': ${embed(PROJECTS)},
|
||||
};
|
||||
`;
|
||||
|
||||
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');
|
||||
Reference in New Issue
Block a user