Load tui plugin via direct src/tui.tsx file spec instead of repo root

This commit is contained in:
nhat.nguyenhong 2026-09-24 07:53:03 +00:00
parent cc7b9fc600
commit a1fe7c7a87
3 changed files with 29 additions and 12 deletions

View File

@ -130,9 +130,14 @@ These are load-bearing. Breaking one causes silent failures in opencode.
`provider.commandcode.models` in `opencode.json` and never asks a custom `file://` provider to `provider.commandcode.models` in `opencode.json` and never asks a custom `file://` provider to
discover models (only internal providers can register `discoverModels`). Refresh the map with discover models (only internal providers can register `discoverModels`). Refresh the map with
`npm run sync-models`; do not expect a discovery hook in `src/` to populate it. `npm run sync-models`; do not expect a discovery hook in `src/` to populate it.
13. **The TUI plugin lives outside the provider entrypoint.** `src/tui.tsx` is loaded from 13. **The TUI plugin lives outside the provider entrypoint.** `src/tui.tsx` is loaded from
**source** (not `dist/`) via `opencode plugin <path>`, which writes a `tui.json` `plugin` **source** (not `dist/`) via a `tui.json` `plugin` entry that must be a **direct `file://` URL
entry; it is exposed as `./tui` in `package.json`. opencode compiles the `.tsx` at load with to `src/tui.tsx`** (global `~/.config/opencode/tui.json` or project `.opencode/tui.json`),
wired by hand: `opencode plugin <path>` cannot install a bare `.tsx` (it needs a `package.json`
manifest next to the target), and the spec must never point at the **repo root** — a directory
spec is also picked up as a server plugin via `package.json` `main` → `dist/index.js` (the
provider, not a plugin). Do not re-add a `./tui` export for this; it is deliberately removed.
opencode compiles the `.tsx` at load with
its Bun/Solid transform and maps `solid-js` / `@opentui/solid` to its internal modules, so the its Bun/Solid transform and maps `solid-js` / `@opentui/solid` to its internal modules, so the
package stays dependency-free — do not add a build step or real imports of those packages. package stays dependency-free — do not add a build step or real imports of those packages.
`src/tui-shims.d.ts` is the only local stand-in for types; keep it in sync with what the file `src/tui-shims.d.ts` is the only local stand-in for types; keep it in sync with what the file

View File

@ -48,7 +48,7 @@ npm run build
"provider": { "provider": {
"commandcode": { "commandcode": {
"name": "Command Code", "name": "Command Code",
"npm": "file:///C:/DevTools/pienv/ccprovider/dist/index.js", "npm": "file:///C:/dev/opencode-commandcode-provider/dist/index.js",
"options": { "options": {
"apiKey": "{env:COMMANDCODE_API_KEY}" "apiKey": "{env:COMMANDCODE_API_KEY}"
}, },
@ -188,14 +188,28 @@ the current state. The file is `~/.config/opencode/commandcode-toggles.json` (ov
These commands come from a small TUI plugin shipped in this package (`src/tui.tsx`). It is loaded These commands come from a small TUI plugin shipped in this package (`src/tui.tsx`). It is loaded
from **source** — opencode compiles the TSX and provides the Solid runtime itself — so there is no from **source** — opencode compiles the TSX and provides the Solid runtime itself — so there is no
build step and no runtime dependency for it. Register it once: build step and no runtime dependency for it. Register it once by adding the plugin file's absolute
`file://` URL to the `plugin` list in `tui.json` (global `~/.config/opencode/tui.json`, or
project-local `.opencode/tui.json`):
```powershell ```jsonc
opencode plugin file:///C:/DevTools/pienv/ccprovider/src/tui.tsx // tui.json
{
"plugin": ["file:///C:/dev/opencode-commandcode-provider/src/tui.tsx"]
}
``` ```
That writes a `tui.json` `plugin` entry (project-local `.opencode/tui.json`, or global with Use an absolute path with forward slashes (`file:///C:/...` on Windows, `file:///home/...` on
`--global`). Restart opencode after installing; then type `/cc-` for autocomplete. The plugin also Linux/macOS). Two rules for the entry:
- It must point at **`src/tui.tsx` itself**. `opencode plugin <module>` cannot install this form:
the CLI requires a `package.json` manifest next to the target, so a bare `.tsx` must be wired in
by hand as above.
- Never point `plugin` at the **repo root**. A directory spec makes opencode also treat the package
as a server plugin (via `package.json` `main` → `dist/index.js`), which is the AI SDK provider,
not a plugin — it loads as dead weight into every session.
Restart opencode after registering the plugin; then type `/cc-` for autocomplete. The plugin also
renders a **CommandCode panel in the session sidebar** (`zdr` / `debug`, plus live quota, above the renders a **CommandCode panel in the session sidebar** (`zdr` / `debug`, plus live quota, above the
built-in panels) that updates live as you toggle. Note that in opencode 1.x the slash menu and the built-in panels) that updates live as you toggle. Note that in opencode 1.x the slash menu and the
`Ctrl+P` palette read the same command registry, so these entries appear in both. If you run opencode `Ctrl+P` palette read the same command registry, so these entries appear in both. If you run opencode
@ -363,6 +377,7 @@ opencode run "Use the glob tool to list *.mjs and report the filenames." -m comm
| Need to see what the provider sends/receives | Set `COMMANDCODE_DEBUG=1` and read the appended log file (see [Debug tracing](#debug-tracing)). | | Need to see what the provider sends/receives | Set `COMMANDCODE_DEBUG=1` and read the appended log file (see [Debug tracing](#debug-tracing)). |
| `tool_choice` seemingly ignored | Expected for `required`; upstream cannot force a call. `none` and named-tool are emulated via the tool list. | | `tool_choice` seemingly ignored | Expected for `required`; upstream cannot force a call. `none` and named-tool are emulated via the tool list. |
| Config change had no effect | opencode reads config once at startup. Restart it. | | Config change had no effect | opencode reads config once at startup. Restart it. |
| `/cc-*` commands and the sidebar panel are missing | TUI plugin not registered: add a direct `file://` URL to `src/tui.tsx` in `tui.json` (see [Runtime toggles](#runtime-toggles)). A repo-root or `src/tui.tsx`-less entry does not load. |
## Security ## Security

View File

@ -9,9 +9,6 @@
".": { ".": {
"import": "./dist/index.js", "import": "./dist/index.js",
"types": "./dist/index.d.ts" "types": "./dist/index.d.ts"
},
"./tui": {
"import": "./src/tui.tsx"
} }
}, },
"files": [ "files": [