[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F1CBV0MGB2EBPRABQ1QCF0":3,"skill-same:01M7F1CBV0MGB2EBPRABQ1QCF0":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M7F1CBV0MGB2EBPRABQ1QCF0","opencode-dev",null,"Use when interactively running, debugging, or verifying opencode's own V2 CLI\u002FTUI or server during development in this repo — starting the dev TUI, driving it with termctrl, comparing V2 against the legacy TUI, hitting the V2 server\u002FAPI directly, reading log files, or attaching Bun's inspector.","monti212\u002FCode-agent","monti212","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F111462978?v=4","01M7F1C5MT9PHA2YW0VYZ1SAHR","Monti","01M7F1C5NJZYQE6DJPPXY87WPM",0,"MIT","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002F.opencode\u002Fskills\u002Fopencode-dev\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: opencode-dev\ndescription: Use when interactively running, debugging, or verifying opencode's own V2 CLI\u002FTUI or server during development in this repo — starting the dev TUI, driving it with termctrl, comparing V2 against the legacy TUI, hitting the V2 server\u002FAPI directly, reading log files, or attaching Bun's inspector.\n---\n\n# Debugging opencode itself\n\nWorkflow for interactively exercising the V2 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 V2 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 the generated SDK (`createOpencodeClient` \u002F `sdk.client.v2`).\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}`. A separate password file under `~\u002F.config\u002Fopencode\u002Fservice.json` provides HTTP Basic auth. Before reusing a registration, the client calls `GET \u002Fhealth` to confirm the server is alive, authenticated, and version-compatible.\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- This package is the V2 CLI adapter. Run its `dev` script when testing the TUI; do not use the repository-root `bun dev`, which launches the legacy `packages\u002Fopencode` CLI.\n- Run commands from `packages\u002Fcli`. Use `bun dev` for most debugging so the TUI starts with a private V2 server.\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-v2-dev --host opentui --cols 112 --rows 34 -- bun dev\ntermctrl wait opencode-v2-dev \"Ask anything\" --timeout 20000\ntermctrl show opencode-v2-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-v2-dev 'text:example prompt' enter\ntermctrl send opencode-v2-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-v2-dev --format png --out \u002Ftmp\u002Fopencode\u002Fv2-tui.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-v2-dev --cols 100 --rows 30\ntermctrl show opencode-v2-dev\n```\n\n- Source changes may require restarting the process. Use `termctrl restart opencode-v2-dev` rather than assuming the running TUI reloaded the change.\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-v2-dev\n```\n\n## Comparing V2 against the legacy TUI\n\nRun both versions in separate Terminal Control sessions and save PNG-only captures at equivalent states:\n\n```bash\n# From packages\u002Fcli: local V2 TUI\ntermctrl start opencode-v2-dev --host opentui --cols 112 --rows 34 -- bun dev\n\n# Released legacy TUI behavior reference\ntermctrl start opencode-legacy --host opentui --cols 112 --rows 34 -- bunx opencode-ai@latest\n\ntermctrl save opencode-v2-dev --format png --out \u002Ftmp\u002Fopencode\u002Fv2.png\ntermctrl save opencode-legacy --format png --out \u002Ftmp\u002Fopencode\u002Flegacy.png\n```\n\n- Use the same viewport and send equivalent inputs to both sessions before comparing screenshots. The released CLI is a behavioral reference, not a source of V2 API design; keep the local implementation on V2 endpoints.\n- Stop both sessions after comparison: `termctrl stop opencode-v2-dev` and `termctrl stop opencode-legacy`.\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 V2 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 \u002Fhealth\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 `opencode2` sessions\n\nInstalled next-channel sessions normally use `~\u002F.local\u002Fshare\u002Fopencode\u002Fopencode-next.db` and `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log`; `OPENCODE_DB` can override the database. Before calling `opencode2 api`, inspect `~\u002F.local\u002Fstate\u002Fopencode\u002Fservice.json` because the command may start a daemon when none is healthy.\n\nFor a supplied `ses_...` ID, compare three sources:\n\n- `opencode2 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\nThe CLI installs a `SIGUSR1` listener on non-Windows processes in `packages\u002Fcli\u002Fsrc\u002Fheap.ts`. Use it to capture the installed `opencode2` server without restarting it or attaching an inspector.\n\n1. Find the processes and inspect their roles and memory:\n\n```bash\npgrep -a -f 'opencode2\\.exe|opencode2'\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 `opencode2.exe serve --service` child, not the short wrapper\u002FTUI 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 health endpoint. For shared-service performance, target the server PID returned here rather than the short wrapper or TUI process:\n\n```bash\nopencode2 api get \u002Fapi\u002Fhealth\n```\n\nUse `bun dev api get \u002Fapi\u002Fhealth` 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 V2 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-v2-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-v2-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 V2 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 V2 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 the generated SDK (`createOpencodeClient` \u002F `sdk.client.v2`).\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}`. A separate password file under `~\u002F.config\u002Fopencode\u002Fservice.json` provides HTTP Basic auth. Before reusing a registration, the client calls `GET \u002Fhealth` to confirm the server is alive, authenticated, and version-compatible.\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- This package is the V2 CLI adapter. Run its `dev` script when testing the TUI; do not use the repository-root `bun dev`, which launches the legacy `packages\u002Fopencode` CLI.\n- Run commands from `packages\u002Fcli`. Use `bun dev` for most debugging so the TUI starts with a private V2 server.\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-v2-dev --host opentui --cols 112 --rows 34 -- bun dev\ntermctrl wait opencode-v2-dev \"Ask anything\" --timeout 20000\ntermctrl show opencode-v2-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-v2-dev 'text:example prompt' enter\ntermctrl send opencode-v2-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-v2-dev --format png --out \u002Ftmp\u002Fopencode\u002Fv2-tui.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-v2-dev --cols 100 --rows 30\ntermctrl show opencode-v2-dev\n```\n\n- Source changes may require restarting the process. Use `termctrl restart opencode-v2-dev` rather than assuming the running TUI reloaded the change.\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-v2-dev\n```\n\n## Comparing V2 against the legacy TUI\n\nRun both versions in separate Terminal Control sessions and save PNG-only captures at equivalent states:\n\n```bash\n# From packages\u002Fcli: local V2 TUI\ntermctrl start opencode-v2-dev --host opentui --cols 112 --rows 34 -- bun dev\n\n# Released legacy TUI behavior reference\ntermctrl start opencode-legacy --host opentui --cols 112 --rows 34 -- bunx opencode-ai@latest\n\ntermctrl save opencode-v2-dev --format png --out \u002Ftmp\u002Fopencode\u002Fv2.png\ntermctrl save opencode-legacy --format png --out \u002Ftmp\u002Fopencode\u002Flegacy.png\n```\n\n- Use the same viewport and send equivalent inputs to both sessions before comparing screenshots. The released CLI is a behavioral reference, not a source of V2 API design; keep the local implementation on V2 endpoints.\n- Stop both sessions after comparison: `termctrl stop opencode-v2-dev` and `termctrl stop opencode-legacy`.\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 V2 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 \u002Fhealth\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 `opencode2` sessions\n\nInstalled next-channel sessions normally use `~\u002F.local\u002Fshare\u002Fopencode\u002Fopencode-next.db` and `~\u002F.local\u002Fshare\u002Fopencode\u002Flog\u002Fopencode.log`; `OPENCODE_DB` can override the database. Before calling `opencode2 api`, inspect `~\u002F.local\u002Fstate\u002Fopencode\u002Fservice.json` because the command may start a daemon when none is healthy.\n\nFor a supplied `ses_...` ID, compare three sources:\n\n- `opencode2 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\nThe CLI installs a `SIGUSR1` listener on non-Windows processes in `packages\u002Fcli\u002Fsrc\u002Fheap.ts`. Use it to capture the installed `opencode2` server without restarting it or attaching an inspector.\n\n1. Find the processes and inspect their roles and memory:\n\n```bash\npgrep -a -f 'opencode2\\.exe|opencode2'\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 `opencode2.exe serve --service` child, not the short wrapper\u002FTUI 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 health endpoint. For shared-service performance, target the server PID returned here rather than the short wrapper or TUI process:\n\n```bash\nopencode2 api get \u002Fapi\u002Fhealth\n```\n\nUse `bun dev api get \u002Fapi\u002Fhealth` 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 V2 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-v2-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-v2-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},"acp-command-lifecycle","c6cc98b9798b8156c2a38101c05552d5fb2398bf",".opencode\u002Fskills\u002Fopencode-dev","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent","https:\u002F\u002Fgithub.com\u002Fmonti212","2026-10-31 08:52:44",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add monti212\u002FCode-agent --skill opencode-dev",{"tool":36,"command":37},"bunx","bunx skills add monti212\u002FCode-agent --skill opencode-dev",{"tool":39,"command":40},"pnpm","pnpm dlx skills add monti212\u002FCode-agent --skill opencode-dev","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002F.opencode\u002Fskills\u002Fopencode-dev\u002FSKILL.md",true,[],[45,52,59,66,73],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":19},"01M7F1CQ9A6A1FBEZDZCJXC0QC","second","Second skill","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002Fpackages\u002Fcore\u002Ftest\u002Fconfig\u002Ffixture\u002Fskills\u002Fsecond-source\u002Fsecond\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M7F1CP6ZV2CHGTCD220776S4","first","First skill","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002Fpackages\u002Fcore\u002Ftest\u002Fconfig\u002Ffixture\u002Fskills\u002Ffirst-source\u002Ffirst\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7F1CKJ0ECK40J785KHE9T1E","sample-skill","Use when the user says sample skill, skill demo, or asks how an opencode SKILL.md should be structured; demonstrates a tiny project-local skill with practical assistant workflow guidance.","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002F.opencode\u002Fskills\u002Fsample-skill\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7F1CGFPDJ7RGXW2C57XRK0M","rtl-aware-development","OpenCode Desktop should be RTL-aware. Use when implementing or reviewing RTL\u002FLTR behavior in the web app, desktop app, CSS, menus, scrolling, resizing, icons, mixed-direction text, or Electron title bars.","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002F.opencode\u002Fskills\u002Frtl-aware-development\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7F1CA4DNANA1YRN8BRZB9EY","effect","Work with Effect v4 TypeScript code in this repo","https:\u002F\u002Fgithub.com\u002Fmonti212\u002FCode-agent\u002Fblob\u002Facp-command-lifecycle\u002F.opencode\u002Fskills\u002Feffect\u002FSKILL.md",[],[]]