opencode-dev
Use when interactively running, debugging, or verifying opencode's own CLI/TUI or server during development in this repo — starting the dev TUI, driving it with termctrl, hitting the server/API directly, reading log files, or attaching Bun's inspector.
SKILL.md 原文预览
Debugging opencode itself
Workflow for interactively exercising the CLI/TUI and server while developing in this repo. All commands below run from packages/cli unless noted otherwise.
Server/client model
opencode is a client/server system, not a single monolithic process:
- Server process runs the Effect HTTP API (
packages/server) and owns all domain state: sessions, database, plugins, permissions, Location services. It's started by theservecommand (packages/cli/src/commands/handlers/serve.ts). - TUI process is a separate process that runs no application logic itself — it's an HTTP/SSE client of the server via
@opencode/client(OpenCode.make). - Discovery: CLI processes find the shared server through a JSON registration file at
~/.local/state/opencode/service.json(orservice-local.jsonfor the local/dev channel) containing{id, version, url, pid, password}; the password is used for HTTP Basic auth. Before reusing a registration, the client callsGET /api/infoto confirm the server is alive, is the registered PID, and is version-compatible.opencode service statusprints the registered URL. - Sharing: because of this registration/health-check dance, many concurrent
opencode/TUI invocations converge on one shared background daemon rather than each spawning their own. If no compatible healthy daemon is found, a new one is spawned detached (serve --service) and registers itself. bun dev service start|status|stop|restartmanages this shared background daemon's lifecycle directly — useful when you need to force a fresh server, confirm one is running, or kill a stuck one.- Standalone mode (
--standalone) opts a single invocation out of the shared daemon: it spawns a private one-offserve --stdio --port 0child tied to that invocation's lifetime, with its own random password. Use this to isolate a debugging session from your other running opencode sessions. - Every log line is tagged
role=serverorrole=cliand a per-processrun=<id>, so you can distinguish server-side and client-side activity in one shared log file (see "Logs" below) even when both roles are interleaved from concurrent processes.
Starting the dev TUI
packages/cliis the CLI and TUI entrypoint.bun devfrompackages/cliand the repository-rootbun devboth runpackages/cli/src/index.ts.bun devconnects to the shared local-channel background service (service-local.json), starting it if needed. Every worktree on the machine shares that service. Add--standalonefor a private server tied to this one process.- Use
bun run dev:livefrom the repository root to run this worktree's TUI against the installedopencodebackground server and your real sessions.
Interactive debugging with termctrl
- Use
termctrlfor interactive checks instead of starting the TUI as a blocking foreground process. It provides a real PTY, handles OpenTUI's host handshake, and can save reviewable screenshots. - Use a dedicated session name and do not reuse or kill an unrelated session.
termctrl start opencode-dev --host opentui --cols 112 --rows 34 -- bun dev
termctrl wait opencode-dev "Ask anything" --timeout 20000
termctrl show opencode-dev- Wait for visible text before interacting instead of relying on fixed sleeps. Use the text expected from the screen under test, such as
Ask anythingorConnect a provider. - Drive the running TUI with
termctrl send. Prefix typed input withtext:and send control keys separately so the interaction matches real terminal input.
termctrl send opencode-dev 'text:example prompt' enter
termctrl send opencode-dev ctrl-c- Use
termctrl showafter each meaningful interaction and inspect the full visible screen for rendering errors, stale state, error toasts, and unexpected exits. - Save PNG evidence for every user-visible bug and fix. Do not save text captures; inspect the rendered PNG. Write temporary captures outside the repository unless the artifact is intended to be committed.
termctrl save opencode-dev --format png --out /tmp/opencode/tui.png- For resize-sensitive changes, resize the viewport, wait for the expected content, and capture the screen again:
termctrl resize opencode-dev --cols 100 --rows 30
termctrl show opencode-dev- Source changes may require restarting the process. Use
termctrl restart opencode-devrather than assuming the running TUI reloaded the change. Restarting the TUI does not restart the shared background service, so runbun dev service restartafter server-side changes, or use--standalone. - To exercise background-service behavior, use
bun dev service start,bun dev service status, andbun dev service stop. - Always clean up the Terminal Control session when the check is complete:
termctrl stop opencode-devServer/API debugging
- Use
bun dev api --helpfrompackages/clito inspect the API debugging command. It sends one request to the server using the same daemon discovery/auth path as the CLI. - Use
bun dev apito introspect the server-side data backing the TUI. This is useful when debugging UI bugs: compare what the screen renders with the raw session, message, event, agent, or health data returned by the API to determine whether the bug is in the server state, the client data layer, or the TUI rendering. bun dev apiaccepts either an OpenAPI operation ID or a raw HTTP method plus path:
bun dev api get /api/info
bun dev api get /openapi.json
bun dev api <operationId> --param key=value- Pass JSON request bodies with
--data/-d; the command setscontent-type: application/jsonau
评论
