[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EJHAXMSCHCBJ1ZH9ZQJGE6":3,"skill-same:01M7EJHAXMSCHCBJ1ZH9ZQJGE6":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7EJHAXMSCHCBJ1ZH9ZQJGE6","opencode-dev",null,"Use when interactively running, debugging, or verifying opencode's own CLI\u002FTUI or server during development in this repo — starting the dev TUI, driving it with termctrl, hitting the server\u002FAPI directly, reading log files, or attaching Bun's inspector.","cutfac\u002Fcutfac","cutfac","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F349630401?v=4","01M7EJGEWWTC6AWDH6F7Q0B97K","01M7EJGEXCV7T9ZWHNQ3B7GKFM",17,"AGPL-3.0","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002F.opencode\u002Fskills\u002Fopencode-dev\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: opencode-dev\ndescription: Use when interactively running, debugging, or verifying opencode's own CLI\u002FTUI or server during development in this repo — starting the dev TUI, driving it with termctrl, hitting the server\u002FAPI directly, reading log files, or attaching Bun's inspector.\n---\n\n# Debugging opencode itself\n\nWorkflow for interactively exercising the CLI\u002FTUI and server while developing in this repo. All commands below run from `packages\u002Fcli` unless noted otherwise.\n\n## Server\u002Fclient model\n\nopencode is a client\u002Fserver system, not a single monolithic process:\n\n- **Server process** runs the Effect HTTP API (`packages\u002Fserver`) and owns all domain state: sessions, database, plugins, permissions, Location services. It's started by the `serve` command (`packages\u002Fcli\u002Fsrc\u002Fcommands\u002Fhandlers\u002Fserve.ts`).\n- **TUI process** is a separate process that runs no application logic itself — it's an HTTP\u002FSSE client of the server via `@opencode\u002Fclient` (`OpenCode.make`).\n- **Discovery**: CLI processes find the shared server through a JSON registration file at `~\u002F.local\u002Fstate\u002Fopencode\u002Fservice.json` (or `service-local.json` for the local\u002Fdev channel) containing `{id, version, url, pid, password}`; the password is used for HTTP Basic auth. Before reusing a registration, the client calls `GET \u002Fapi\u002Finfo` to confirm the server is alive, is the registered PID, and is version-compatible. `opencode service status` prints the registered URL.\n- **Sharing**: because of this registration\u002Fhealth-check dance, many concurrent `opencode`\u002FTUI 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.\n- **`bun dev service start|status|stop|restart`** manages 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.\n- **Standalone mode** (`--standalone`) opts a single invocation out of the shared daemon: it spawns a private one-off `serve --stdio --port 0` child tied to that invocation's lifetime, with its own random password. Use this to isolate a debugging session from your other running opencode sessions.\n- Every log line is tagged `role=server` or `role=cli` and a per-process `run=\u003Cid>`, 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.\n\n## Starting the dev TUI\n\n- `packages\u002Fcli` is the CLI and TUI entrypoint. `bun dev` from `packages\u002Fcli` and the repository-root `bun dev` both run `packages\u002Fcli\u002Fsrc\u002Findex.ts`.\n- `bun dev` connects to the shared local-channel background service (`service-local.json`), starting it if needed. Every worktree on the machine shares that service. Add `--standalone` for a private server tied to this one process.\n- Use `bun run dev:live` from the repository root to run this worktree's TUI against the installed `opencode` background server and your real sessions.\n\n## Interactive debugging with termctrl\n\n- Use `termctrl` for 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.\n- Use a dedicated session name and do not reuse or kill an unrelated session.\n\n```bash\ntermctrl start opencode-dev --host opentui --cols 112 --rows 34 -- bun dev\ntermctrl wait opencode-dev \"Ask anything\" --timeout 20000\ntermctrl show opencode-dev\n```\n\n- Wait for visible text before interacting instead of relying on fixed sleeps. Use the text expected from the screen under test, such as `Ask anything` or `Connect a provider`.\n- Drive the running TUI with `termctrl send`. Prefix typed input with `text:` and send control keys separately so the interaction matches real terminal input.\n\n```bash\ntermctrl send opencode-dev 'text:example prompt' enter\ntermctrl send opencode-dev ctrl-c\n```\n\n- Use `termctrl show` after each meaningful interaction and inspect the full visible screen for rendering errors, stale state, error toasts, and unexpected exits.\n- 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.\n\n```bash\ntermctrl save opencode-dev --format png --out \u002Ftmp\u002Fopencode\u002Ftui.png\n```\n\n- For resize-sensitive changes, resize the viewport, wait for the expected content, and capture the screen again:\n\n```bash\ntermctrl resize opencode-dev --cols 100 --rows 30\ntermctrl show opencode-dev\n```\n\n- Source changes may require restarting the process. Use `termctrl restart opencode-dev` rather than assuming the running TUI reloaded the change. Restarting the TUI does not restart the shared background service, so run `bun dev service restart` after server-side changes, or use `--standalone`.\n- To exercise background-service behavior, use `bun dev service start`, `bun dev service status`, and `bun dev service stop`.\n- Always clean up the Terminal Control session when the check is complete:\n\n```bash\ntermctrl stop opencode-dev\n```\n\n## Server\u002FAPI debugging\n\n- Use `bun dev api --help` from `packages\u002Fcli` to inspect the API debugging command. It sends one request to the server using the same daemon discovery\u002Fauth path as the CLI.\n- Use `bun dev api` to 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.\n- `bun dev api` accepts either an OpenAPI operation ID or a raw HTTP method plus path:\n\n```bash\nbun dev api get \u002Fapi\u002Finfo\nbun dev api get \u002Fopenapi.json\nbun dev api \u003CoperationId> --param key=value\n```\n\n- Pass JSON request bodies with `--data`\u002F`-d`; the command sets `content-type: application\u002Fjson` automatically unless you provide a header. Add extra headers with `--header`\u002F`-H name:value`.\n- If no compatible background server is registered, `bun dev api` starts one through the daemon service. Use `bun dev service status`, `bun dev service restart`, and `bun dev service stop` when you need explicit lifecycle control.\n- Prefer raw method\u002Fpath calls for quick server debugging and operation IDs when exercising documented OpenAPI routes with path or query parameters.\n\n## Auditing installed `opencode` sessions\n\nInstalled (released) sessions use `~\u002F.local\u002Fshare\u002Fopencode\u002Fopencode.db` and `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log`. A local\u002Fdev checkout uses `opencode-local.db` and `opencode-local.log` instead, and `OPENCODE_DB` overrides the database. Run `opencode service status` before `opencode api`, because `opencode api` starts a server when none is healthy.\n\nFor a supplied `ses_...` ID, compare three sources:\n\n- `opencode api get \u002Fapi\u002Fsession\u002Factive` and the Session\u002Fmessage endpoints for live server state.\n- The database's ordered `event` rows for durable history.\n- `packages\u002Ftui\u002Fsrc\u002Fcontext\u002Fdata.tsx` and the relevant route for client projection and rendering.\n\nLocate an uncertain database without modifying it:\n\n```bash\nSESSION=ses_...\nfor db in ~\u002F.local\u002Fshare\u002Fopencode\u002F*.db; do\n  sqlite3 \"file:$db?mode=ro\" \"select 1 from session where id='$SESSION' limit 1\" 2>\u002Fdev\u002Fnull | grep -q 1 && printf '%s\\n' \"$db\"\ndone\n```\n\n## Logs\n\n- Log files live under `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002F`. In a local\u002Fdev checkout the active file is `opencode-local.log`; `opencode.log` is used for non-local (released) channel installs. Both are append-only, shared across every CLI and server process on the machine.\n- Each line is structured `key=value` text: `timestamp`, `level`, `run=\u003Cid>` (per-process run ID), `message`, and a `role=cli` or `role=server` tag. Use `run=` to isolate one process's activity and `role=` to separate client-side from server-side log lines, since a shared daemon interleaves many processes' output in one file.\n- Tail the live file while reproducing an issue instead of guessing from stale output:\n\n```bash\ntail -f ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\n```\n\n- Filter to one run or role when the file is noisy:\n\n```bash\ngrep 'run=8fc3b1d5' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\ngrep 'role=server' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\n```\n\n- `OPENCODE_LOG_LEVEL` controls verbosity (default `INFO`); set it before starting `bun dev` or `serve` to get `DEBUG` output for a specific repro.\n- `OPENCODE_PRINT_LOGS=1` additionally tees log output to stderr of the process that emitted it, which is useful when a process fails before you'd think to check the shared log file.\n- `termctrl logs \u003Csession>` surfaces stdout\u002Fstderr for a Terminal Control session specifically (e.g. inspector output or startup failures before the TUI renderer starts) — use the log file above for anything emitted by a separate server\u002Fdaemon process instead.\n\n## Heap snapshots\n\nOn every platform, including Windows, capture the running background server without restarting it or attaching an inspector:\n\n```bash\nopencode debug heap-dump\n```\n\nIt discovers the already-running service (never starts or replaces one), calls `POST \u002Fapi\u002Fdebug\u002Fheap-dump`, waits until the file is complete, and prints its server-local path. Pass `--server \u003Curl>` (with `OPENCODE_PASSWORD`) for a server started with `serve`, and `--directory \u003Cdir>` to write somewhere other than the server's log directory (the server creates it; a server that predates the option ignores it and the CLI warns). A 404 means the running server predates the endpoint.\n\nFor desktop memory, run **Capture heap snapshots** from the desktop command palette (`packages\u002Fgui-extensions\u002Fsrc\u002Fdebug\u002Fmain.ts`). It writes `~\u002FDownloads\u002Fopencode-heap-\u003Ctime>\u002F` with the desktop's own (local) server, which writes straight into the folder, every app window renderer, and the Electron main process. Heap snapshots only hold GC-managed objects, so it also records Chromium's memory-infra dump (`memory-infra.json`, open in Perfetto) and summarizes it per process and allocator in `memory.json` (MiB: `malloc`, `partition_alloc`, `cc\u002Ftile_memory`, `gpu`, `v8`, …), next to each window's DOM size and decoded images and the server's `process.memoryUsage()`. `manifest.json` (PIDs, `app.getAppMetrics()` before and after) is written last. Start with `memory.json` when a process is larger than its heap snapshot. In a dev desktop build you can drive it over CDP (`OPENCODE_DESKTOP_REMOTE_DEBUGGING_PORT`, default 9222): press `Control+Shift+P`, type `heap snapshots`, press Enter.\n\nThe Unix `SIGUSR1` listener in `packages\u002Fcli\u002Fsrc\u002Fheap.ts` shares the same writer (`packages\u002Futil\u002Fsrc\u002Fheap-snapshot.ts`) and is still useful for a process that is not an HTTP server, such as a TUI client:\n\n1. Find the processes and inspect their roles and memory:\n\n```bash\npgrep -af opencode\nps -o pid,ppid,rss,vsz,lstart,etime,cmd -p \u003Cpid>,\u003Cpid>\n```\n\n2. Signal the process whose heap needs investigation. For shared-service memory, target the `opencode serve --service` process, not a TUI process:\n\n```bash\nkill -USR1 \u003Cserver-pid>\n```\n\n3. Wait for `heap snapshot written` in the channel's log before opening the file. Snapshots are written to the same log directory as `heap-\u003Cpid>-\u003Ctimestamp>.heapsnapshot`; writing a large heap can take several seconds and the file is incomplete until the completion message appears:\n\n```bash\ngrep 'heap snapshot' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log | tail\nfind ~\u002F.local\u002Fshare\u002Fopencode\u002Flog -maxdepth 1 -name 'heap-\u003Cserver-pid>-*.heapsnapshot' -printf '%T@ %s %p\\n' | sort -nr | head\n```\n\nUse `opencode-local.log` instead for a local\u002Fdev channel process. The log's `path=` field is authoritative.\n\n4. Analyze the snapshot with Chrome DevTools, a V8 heap snapshot parser, or a temporary tool installed outside the repository. Start with the largest retained objects, dominators, object counts grouped by constructor\u002Fname, and retainer paths back to GC roots. Relate suspicious names and paths back to the source tree rather than treating large shallow allocations as leaks.\n\nFor command-line analysis, install tooling under `\u002Ftmp\u002Fopencode`, not in the repository. For example, MemLab can rank dominators and trace a reported heap object ID back to a GC root:\n\n```bash\nnpm install --prefix \u002Ftmp\u002Fopencode\u002Fheap-analysis @memlab\u002Fcli\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab analyze object-size --snapshot \u003Csnapshot>\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab analyze shape --snapshot \u003Csnapshot>\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab trace --snapshot \u003Csnapshot> --node-id=\u003Cid>\n```\n\nA single snapshot explains what retains memory at one point in time, but does not by itself prove a leak. For leak confirmation, capture a baseline, perform a controlled repeated workload, allow idle cleanup\u002FGC when possible, capture another snapshot, and compare growth and retainer paths. Also compare snapshot heap size with process RSS: a large difference can indicate native allocations, database mappings, allocator fragmentation, or other memory outside the JavaScript heap.\n\n```bash\ncat \u002Fproc\u002F\u003Cpid>\u002Fsmaps_rollup\npmap -x \u003Cpid> | sort -k3 -nr | head -25\n```\n\nHeap serialization itself can temporarily increase RSS and allocator high-water marks, so record `ps`\u002F`smaps_rollup` both before and after capture. Large anonymous mappings with a comparatively small live heap require native-allocation or allocator investigation; they cannot be explained from JavaScript retainer paths alone.\n\n## CPU profiles\n\nThe CLI installs a `SIGPROF` listener on non-Windows processes in `packages\u002Fcli\u002Fsrc\u002Fcpu-profile.ts`. One signal starts a ten-second CPU profile and stops it automatically; additional signals are ignored while a profile is active. There is no CPU profile CLI flag or environment variable.\n\n1. Get the PID from the info endpoint. For shared-service performance, target the server PID returned here rather than a TUI process:\n\n```bash\nopencode api get \u002Fapi\u002Finfo\n```\n\nUse `bun dev api get \u002Fapi\u002Finfo` instead when targeting the local\u002Fdev channel.\n\n2. Start the capture:\n\n```bash\nkill -PROF \u003Cserver-pid>\n```\n\n3. Wait for `CPU profile written` in the channel's log before opening the file. Profiles are written to the same log directory as `cpu-\u003Cpid>-\u003Ctimestamp>.cpuprofile`; the log's `path=` field is authoritative:\n\n```bash\ngrep 'CPU profile' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log | tail\nfind ~\u002F.local\u002Fshare\u002Fopencode\u002Flog -maxdepth 1 -name 'cpu-\u003Cserver-pid>-*.cpuprofile' -printf '%T@ %s %p\\n' | sort -nr | head\n```\n\nUse `opencode-local.log` for a local\u002Fdev process. Load the completed `.cpuprofile` in Chrome DevTools or another V8 CPU profile viewer and inspect the hottest functions, call stacks, and self time during the controlled workload.\n\n## Debugger\n\n- To debug the CLI or TUI with Bun's inspector, launch the CLI entrypoint through Terminal Control with an inspector URL, then attach a debugger to that URL:\n\n```bash\ntermctrl start opencode-debug --host opentui --cols 112 --rows 34 -- \\\n  bun run --inspect=ws:\u002F\u002Flocalhost:6499\u002F src\u002Findex.ts\n```\n\n- Use `--inspect-wait` or `--inspect-brk` when execution must pause until a debugger attaches.\n- Use `termctrl logs opencode-debug` for inspector output or startup failures emitted before the TUI renderer starts. Use `termctrl show` for the visible full-screen TUI.\n\n## Verification\n\n- Run `bun typecheck` from `packages\u002Fcli` after CLI adapter changes.\n- Run `bun typecheck` and `bun test` from `packages\u002Ftui` after shared TUI changes. Do not run tests from the repository root.\n- Treat automated checks and Terminal Control smoke tests as complementary. For user-visible changes, verify initial render, the changed interaction, Ctrl-C exit behavior, and save a screenshot of the corrected state.\n","# Debugging opencode itself\n\nWorkflow for interactively exercising the CLI\u002FTUI and server while developing in this repo. All commands below run from `packages\u002Fcli` unless noted otherwise.\n\n## Server\u002Fclient model\n\nopencode is a client\u002Fserver system, not a single monolithic process:\n\n- **Server process** runs the Effect HTTP API (`packages\u002Fserver`) and owns all domain state: sessions, database, plugins, permissions, Location services. It's started by the `serve` command (`packages\u002Fcli\u002Fsrc\u002Fcommands\u002Fhandlers\u002Fserve.ts`).\n- **TUI process** is a separate process that runs no application logic itself — it's an HTTP\u002FSSE client of the server via `@opencode\u002Fclient` (`OpenCode.make`).\n- **Discovery**: CLI processes find the shared server through a JSON registration file at `~\u002F.local\u002Fstate\u002Fopencode\u002Fservice.json` (or `service-local.json` for the local\u002Fdev channel) containing `{id, version, url, pid, password}`; the password is used for HTTP Basic auth. Before reusing a registration, the client calls `GET \u002Fapi\u002Finfo` to confirm the server is alive, is the registered PID, and is version-compatible. `opencode service status` prints the registered URL.\n- **Sharing**: because of this registration\u002Fhealth-check dance, many concurrent `opencode`\u002FTUI 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.\n- **`bun dev service start|status|stop|restart`** manages 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.\n- **Standalone mode** (`--standalone`) opts a single invocation out of the shared daemon: it spawns a private one-off `serve --stdio --port 0` child tied to that invocation's lifetime, with its own random password. Use this to isolate a debugging session from your other running opencode sessions.\n- Every log line is tagged `role=server` or `role=cli` and a per-process `run=\u003Cid>`, 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.\n\n## Starting the dev TUI\n\n- `packages\u002Fcli` is the CLI and TUI entrypoint. `bun dev` from `packages\u002Fcli` and the repository-root `bun dev` both run `packages\u002Fcli\u002Fsrc\u002Findex.ts`.\n- `bun dev` connects to the shared local-channel background service (`service-local.json`), starting it if needed. Every worktree on the machine shares that service. Add `--standalone` for a private server tied to this one process.\n- Use `bun run dev:live` from the repository root to run this worktree's TUI against the installed `opencode` background server and your real sessions.\n\n## Interactive debugging with termctrl\n\n- Use `termctrl` for 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.\n- Use a dedicated session name and do not reuse or kill an unrelated session.\n\n```bash\ntermctrl start opencode-dev --host opentui --cols 112 --rows 34 -- bun dev\ntermctrl wait opencode-dev \"Ask anything\" --timeout 20000\ntermctrl show opencode-dev\n```\n\n- Wait for visible text before interacting instead of relying on fixed sleeps. Use the text expected from the screen under test, such as `Ask anything` or `Connect a provider`.\n- Drive the running TUI with `termctrl send`. Prefix typed input with `text:` and send control keys separately so the interaction matches real terminal input.\n\n```bash\ntermctrl send opencode-dev 'text:example prompt' enter\ntermctrl send opencode-dev ctrl-c\n```\n\n- Use `termctrl show` after each meaningful interaction and inspect the full visible screen for rendering errors, stale state, error toasts, and unexpected exits.\n- 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.\n\n```bash\ntermctrl save opencode-dev --format png --out \u002Ftmp\u002Fopencode\u002Ftui.png\n```\n\n- For resize-sensitive changes, resize the viewport, wait for the expected content, and capture the screen again:\n\n```bash\ntermctrl resize opencode-dev --cols 100 --rows 30\ntermctrl show opencode-dev\n```\n\n- Source changes may require restarting the process. Use `termctrl restart opencode-dev` rather than assuming the running TUI reloaded the change. Restarting the TUI does not restart the shared background service, so run `bun dev service restart` after server-side changes, or use `--standalone`.\n- To exercise background-service behavior, use `bun dev service start`, `bun dev service status`, and `bun dev service stop`.\n- Always clean up the Terminal Control session when the check is complete:\n\n```bash\ntermctrl stop opencode-dev\n```\n\n## Server\u002FAPI debugging\n\n- Use `bun dev api --help` from `packages\u002Fcli` to inspect the API debugging command. It sends one request to the server using the same daemon discovery\u002Fauth path as the CLI.\n- Use `bun dev api` to 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.\n- `bun dev api` accepts either an OpenAPI operation ID or a raw HTTP method plus path:\n\n```bash\nbun dev api get \u002Fapi\u002Finfo\nbun dev api get \u002Fopenapi.json\nbun dev api \u003CoperationId> --param key=value\n```\n\n- Pass JSON request bodies with `--data`\u002F`-d`; the command sets `content-type: application\u002Fjson` automatically unless you provide a header. Add extra headers with `--header`\u002F`-H name:value`.\n- If no compatible background server is registered, `bun dev api` starts one through the daemon service. Use `bun dev service status`, `bun dev service restart`, and `bun dev service stop` when you need explicit lifecycle control.\n- Prefer raw method\u002Fpath calls for quick server debugging and operation IDs when exercising documented OpenAPI routes with path or query parameters.\n\n## Auditing installed `opencode` sessions\n\nInstalled (released) sessions use `~\u002F.local\u002Fshare\u002Fopencode\u002Fopencode.db` and `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log`. A local\u002Fdev checkout uses `opencode-local.db` and `opencode-local.log` instead, and `OPENCODE_DB` overrides the database. Run `opencode service status` before `opencode api`, because `opencode api` starts a server when none is healthy.\n\nFor a supplied `ses_...` ID, compare three sources:\n\n- `opencode api get \u002Fapi\u002Fsession\u002Factive` and the Session\u002Fmessage endpoints for live server state.\n- The database's ordered `event` rows for durable history.\n- `packages\u002Ftui\u002Fsrc\u002Fcontext\u002Fdata.tsx` and the relevant route for client projection and rendering.\n\nLocate an uncertain database without modifying it:\n\n```bash\nSESSION=ses_...\nfor db in ~\u002F.local\u002Fshare\u002Fopencode\u002F*.db; do\n  sqlite3 \"file:$db?mode=ro\" \"select 1 from session where id='$SESSION' limit 1\" 2>\u002Fdev\u002Fnull | grep -q 1 && printf '%s\\n' \"$db\"\ndone\n```\n\n## Logs\n\n- Log files live under `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002F`. In a local\u002Fdev checkout the active file is `opencode-local.log`; `opencode.log` is used for non-local (released) channel installs. Both are append-only, shared across every CLI and server process on the machine.\n- Each line is structured `key=value` text: `timestamp`, `level`, `run=\u003Cid>` (per-process run ID), `message`, and a `role=cli` or `role=server` tag. Use `run=` to isolate one process's activity and `role=` to separate client-side from server-side log lines, since a shared daemon interleaves many processes' output in one file.\n- Tail the live file while reproducing an issue instead of guessing from stale output:\n\n```bash\ntail -f ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\n```\n\n- Filter to one run or role when the file is noisy:\n\n```bash\ngrep 'run=8fc3b1d5' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\ngrep 'role=server' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode-local.log\n```\n\n- `OPENCODE_LOG_LEVEL` controls verbosity (default `INFO`); set it before starting `bun dev` or `serve` to get `DEBUG` output for a specific repro.\n- `OPENCODE_PRINT_LOGS=1` additionally tees log output to stderr of the process that emitted it, which is useful when a process fails before you'd think to check the shared log file.\n- `termctrl logs \u003Csession>` surfaces stdout\u002Fstderr for a Terminal Control session specifically (e.g. inspector output or startup failures before the TUI renderer starts) — use the log file above for anything emitted by a separate server\u002Fdaemon process instead.\n\n## Heap snapshots\n\nOn every platform, including Windows, capture the running background server without restarting it or attaching an inspector:\n\n```bash\nopencode debug heap-dump\n```\n\nIt discovers the already-running service (never starts or replaces one), calls `POST \u002Fapi\u002Fdebug\u002Fheap-dump`, waits until the file is complete, and prints its server-local path. Pass `--server \u003Curl>` (with `OPENCODE_PASSWORD`) for a server started with `serve`, and `--directory \u003Cdir>` to write somewhere other than the server's log directory (the server creates it; a server that predates the option ignores it and the CLI warns). A 404 means the running server predates the endpoint.\n\nFor desktop memory, run **Capture heap snapshots** from the desktop command palette (`packages\u002Fgui-extensions\u002Fsrc\u002Fdebug\u002Fmain.ts`). It writes `~\u002FDownloads\u002Fopencode-heap-\u003Ctime>\u002F` with the desktop's own (local) server, which writes straight into the folder, every app window renderer, and the Electron main process. Heap snapshots only hold GC-managed objects, so it also records Chromium's memory-infra dump (`memory-infra.json`, open in Perfetto) and summarizes it per process and allocator in `memory.json` (MiB: `malloc`, `partition_alloc`, `cc\u002Ftile_memory`, `gpu`, `v8`, …), next to each window's DOM size and decoded images and the server's `process.memoryUsage()`. `manifest.json` (PIDs, `app.getAppMetrics()` before and after) is written last. Start with `memory.json` when a process is larger than its heap snapshot. In a dev desktop build you can drive it over CDP (`OPENCODE_DESKTOP_REMOTE_DEBUGGING_PORT`, default 9222): press `Control+Shift+P`, type `heap snapshots`, press Enter.\n\nThe Unix `SIGUSR1` listener in `packages\u002Fcli\u002Fsrc\u002Fheap.ts` shares the same writer (`packages\u002Futil\u002Fsrc\u002Fheap-snapshot.ts`) and is still useful for a process that is not an HTTP server, such as a TUI client:\n\n1. Find the processes and inspect their roles and memory:\n\n```bash\npgrep -af opencode\nps -o pid,ppid,rss,vsz,lstart,etime,cmd -p \u003Cpid>,\u003Cpid>\n```\n\n2. Signal the process whose heap needs investigation. For shared-service memory, target the `opencode serve --service` process, not a TUI process:\n\n```bash\nkill -USR1 \u003Cserver-pid>\n```\n\n3. Wait for `heap snapshot written` in the channel's log before opening the file. Snapshots are written to the same log directory as `heap-\u003Cpid>-\u003Ctimestamp>.heapsnapshot`; writing a large heap can take several seconds and the file is incomplete until the completion message appears:\n\n```bash\ngrep 'heap snapshot' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log | tail\nfind ~\u002F.local\u002Fshare\u002Fopencode\u002Flog -maxdepth 1 -name 'heap-\u003Cserver-pid>-*.heapsnapshot' -printf '%T@ %s %p\\n' | sort -nr | head\n```\n\nUse `opencode-local.log` instead for a local\u002Fdev channel process. The log's `path=` field is authoritative.\n\n4. Analyze the snapshot with Chrome DevTools, a V8 heap snapshot parser, or a temporary tool installed outside the repository. Start with the largest retained objects, dominators, object counts grouped by constructor\u002Fname, and retainer paths back to GC roots. Relate suspicious names and paths back to the source tree rather than treating large shallow allocations as leaks.\n\nFor command-line analysis, install tooling under `\u002Ftmp\u002Fopencode`, not in the repository. For example, MemLab can rank dominators and trace a reported heap object ID back to a GC root:\n\n```bash\nnpm install --prefix \u002Ftmp\u002Fopencode\u002Fheap-analysis @memlab\u002Fcli\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab analyze object-size --snapshot \u003Csnapshot>\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab analyze shape --snapshot \u003Csnapshot>\n\u002Ftmp\u002Fopencode\u002Fheap-analysis\u002Fnode_modules\u002F.bin\u002Fmemlab trace --snapshot \u003Csnapshot> --node-id=\u003Cid>\n```\n\nA single snapshot explains what retains memory at one point in time, but does not by itself prove a leak. For leak confirmation, capture a baseline, perform a controlled repeated workload, allow idle cleanup\u002FGC when possible, capture another snapshot, and compare growth and retainer paths. Also compare snapshot heap size with process RSS: a large difference can indicate native allocations, database mappings, allocator fragmentation, or other memory outside the JavaScript heap.\n\n```bash\ncat \u002Fproc\u002F\u003Cpid>\u002Fsmaps_rollup\npmap -x \u003Cpid> | sort -k3 -nr | head -25\n```\n\nHeap serialization itself can temporarily increase RSS and allocator high-water marks, so record `ps`\u002F`smaps_rollup` both before and after capture. Large anonymous mappings with a comparatively small live heap require native-allocation or allocator investigation; they cannot be explained from JavaScript retainer paths alone.\n\n## CPU profiles\n\nThe CLI installs a `SIGPROF` listener on non-Windows processes in `packages\u002Fcli\u002Fsrc\u002Fcpu-profile.ts`. One signal starts a ten-second CPU profile and stops it automatically; additional signals are ignored while a profile is active. There is no CPU profile CLI flag or environment variable.\n\n1. Get the PID from the info endpoint. For shared-service performance, target the server PID returned here rather than a TUI process:\n\n```bash\nopencode api get \u002Fapi\u002Finfo\n```\n\nUse `bun dev api get \u002Fapi\u002Finfo` instead when targeting the local\u002Fdev channel.\n\n2. Start the capture:\n\n```bash\nkill -PROF \u003Cserver-pid>\n```\n\n3. Wait for `CPU profile written` in the channel's log before opening the file. Profiles are written to the same log directory as `cpu-\u003Cpid>-\u003Ctimestamp>.cpuprofile`; the log's `path=` field is authoritative:\n\n```bash\ngrep 'CPU profile' ~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log | tail\nfind ~\u002F.local\u002Fshare\u002Fopencode\u002Flog -maxdepth 1 -name 'cpu-\u003Cserver-pid>-*.cpuprofile' -printf '%T@ %s %p\\n' | sort -nr | head\n```\n\nUse `opencode-local.log` for a local\u002Fdev process. Load the completed `.cpuprofile` in Chrome DevTools or another V8 CPU profile viewer and inspect the hottest functions, call stacks, and self time during the controlled workload.\n\n## Debugger\n\n- To debug the CLI or TUI with Bun's inspector, launch the CLI entrypoint through Terminal Control with an inspector URL, then attach a debugger to that URL:\n\n```bash\ntermctrl start opencode-debug --host opentui --cols 112 --rows 34 -- \\\n  bun run --inspect=ws:\u002F\u002Flocalhost:6499\u002F src\u002Findex.ts\n```\n\n- Use `--inspect-wait` or `--inspect-brk` when execution must pause until a debugger attaches.\n- Use `termctrl logs opencode-debug` for inspector output or startup failures emitted before the TUI renderer starts. Use `termctrl show` for the visible full-screen TUI.\n\n## Verification\n\n- Run `bun typecheck` from `packages\u002Fcli` after CLI adapter changes.\n- Run `bun typecheck` and `bun test` from `packages\u002Ftui` after shared TUI changes. Do not run tests from the repository root.\n- Treat automated checks and Terminal Control smoke tests as complementary. For user-visible changes, verify initial render, the changed interaction, Ctrl-C exit behavior, and save a screenshot of the corrected state.\n",{"name":5,"description":7},"main","ac94c98de2181a59e1add4ca960ad1ce8b9f1362","reference-repos\u002Fopencode\u002F.opencode\u002Fskills\u002Fopencode-dev",1,"https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac","https:\u002F\u002Fcutfac.com","https:\u002F\u002Fgithub.com\u002Fcutfac","2026-10-31 03:56:38",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add cutfac\u002Fcutfac --skill opencode-dev",{"tool":37,"command":38},"bunx","bunx skills add cutfac\u002Fcutfac --skill opencode-dev",{"tool":40,"command":41},"pnpm","pnpm dlx skills add cutfac\u002Fcutfac --skill opencode-dev","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002F.opencode\u002Fskills\u002Fopencode-dev\u002FSKILL.md",true,[],[46,52,59,66,73,80],{"skillNo":47,"name":9,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M7EJMBKEH5HZR04HXY8AC9RY","Work inside a Cutfac workspace — learn the user's product and the short-form videos they like, turn them into reusable formats, produce short-form items (9:16 video, carousels) that market the user's app, handle review feedback from the web board, and verify uploads. Use whenever the user mentions learning, references, formats, items, the board, feedback, or short-form content for their app.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Fskills\u002Fcutfac\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M7EJM3Q5238C6D223PGYH7TK","figma-use","**MANDATORY prerequisite** — you MUST invoke this skill BEFORE every `use_figma` tool call. NEVER call `use_figma` directly without loading this skill first. Skipping it causes common, hard-to-debug failures. Trigger whenever the user wants to perform a write action or a unique read action that requires JavaScript execution in the Figma file context — e.g. create\u002Fedit\u002Fdelete nodes, set up variables or tokens, build components and variants, modify auto-layout or fills, bind variables to properties, or inspect file structure programmatically.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M7EJKZAMVSG0297D5804ECXK","figma-use-slides","This skill helps agents use Figma's use_figma MCP tool in the Slides context. Can be used alongside figma-use which has foundational context for using the use_figma tool.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-slides\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M7EJKW1WV245VCGWBQ7ZZG6P","figma-use-motion","Motion \u002F animation context for the `use_figma` MCP tool — animating Figma nodes via manual keyframes, animation styles, easing, and timeline duration. Load alongside figma-use whenever a task involves adding, editing, or inspecting animation on a node.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-motion\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M7EJKS02H39GN9RKVJ9DXWDQ","figma-use-figjam","This skill helps agents use Figma's use_figma MCP tool in the FigJam context. Can be used alongside figma-use which has foundational context for using the use_figma tool.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-use-figjam\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M7EJKKQBPBBS8BNNJR5PYS6S","figma-swiftui","SwiftUI ↔ Figma translation. Use whenever the user mentions Swift, SwiftUI, iOS, iPhone, or iPad — in EITHER direction — translating a Figma design into SwiftUI (design → code), or pushing SwiftUI views \u002F screens \u002F tokens back into a Figma file (code → design). Triggers on phrases like 'implement this Figma design in SwiftUI', 'build this screen in Swift', 'push this SwiftUI view to Figma', 'mirror my Swift code in a Figma file', or whenever a Figma URL appears alongside `.swift` files \u002F an `.xcodeproj`. Routes to a direction-specific reference doc; loads alongside `figma-use` for the code → design path.","https:\u002F\u002Fgithub.com\u002Fcutfac\u002Fcutfac\u002Fblob\u002Fmain\u002Freference-repos\u002Fopencode\u002Fpackages\u002Fplugins\u002Ffigma\u002Fskills\u002Ffigma-swiftui\u002FSKILL.md",[],[]]