|
| 1 | +# Runtime Debug Toolkit |
| 2 | + |
| 3 | +Two agent workflows backed by one local loopback log server. |
| 4 | + |
| 5 | +| Skill | Workflow outcome | |
| 6 | +| --- | --- | |
| 7 | +| `$trace-mode` | Add temporary structured logs, analyze one runtime trace, and locate the responsible code boundary. | |
| 8 | +| `$debug-mode` | Use the same trace evidence to confirm a cause, fix the bug, verify it, and clean up. | |
| 9 | + |
| 10 | +`debug-mode` depends on the sibling `trace-mode` skill. The server, runtime |
| 11 | +helpers, event protocol, and NDJSON summarizer have one implementation under |
| 12 | +`skills/trace-mode/`. |
| 13 | + |
| 14 | +## Workflows |
| 15 | + |
| 16 | +Trace Mode stops after evidence-backed code location: |
| 17 | + |
| 18 | +```text |
| 19 | +analyze code -> plan events -> arm server -> instrument -> trigger -> analyze logs -> locate code -> clean |
| 20 | +``` |
| 21 | + |
| 22 | +Cursor-like Debug Mode continues from the same trace into a verified fix: |
| 23 | + |
| 24 | +```text |
| 25 | +analyze code -> hypothesize -> trace with trace-mode -> prove -> fix -> verify -> clean |
| 26 | +``` |
| 27 | + |
| 28 | +Use `$trace-mode` when the goal is understanding runtime behavior or locating |
| 29 | +the code that handles an event. It changes only temporary instrumentation. |
| 30 | + |
| 31 | +Use `$debug-mode` when the goal includes modifying product code. Starting it is |
| 32 | +explicit. An active session resumes automatically across later turns until |
| 33 | +cleanup or explicit abandonment. |
| 34 | + |
| 35 | +## Shared Log Server |
| 36 | + |
| 37 | +The loopback server accepts one JSON object at `POST /log` and appends one |
| 38 | +NDJSON record. `GET /health` reports service state. Each session writes to a |
| 39 | +separate file and queue. |
| 40 | + |
| 41 | +Agents start or reuse it with: |
| 42 | + |
| 43 | +```bash |
| 44 | +node <trace-mode-skill-dir>/scripts/start-collector.mjs --session <id> |
| 45 | +``` |
| 46 | + |
| 47 | +The command prints: |
| 48 | + |
| 49 | +```text |
| 50 | +LOG_SERVER_URL=<loopback origin> |
| 51 | +SESSION_ID=<id> |
| 52 | +LOG_DIR=<temporary log directory> |
| 53 | +LOG_FILE=<session NDJSON path> |
| 54 | +HEALTH_URL=<loopback health URL> |
| 55 | +``` |
| 56 | + |
| 57 | +The wrapper fixes host to `127.0.0.1` and port to `0`. It reuses one healthy |
| 58 | +server across concurrent sessions. State and evidence stay in the operating |
| 59 | +system temporary directory. |
| 60 | + |
| 61 | +## Usage |
| 62 | + |
| 63 | +### Agent Skills clients |
| 64 | + |
| 65 | +Locate a runtime path without fixing product code: |
| 66 | + |
| 67 | +```text |
| 68 | +$trace-mode trace which handler persists this setting after Save |
| 69 | +``` |
| 70 | + |
| 71 | +Diagnose and fix a reproducible runtime bug: |
| 72 | + |
| 73 | +```text |
| 74 | +$debug-mode the setting resets after Save and reload |
| 75 | +``` |
| 76 | + |
| 77 | +At debug checkpoints, Codex uses native phase-specific choices when available. |
| 78 | +Pi uses the bundled A/B/C chooser. Other clients use the text fallback. |
| 79 | + |
| 80 | +### Pi package command |
| 81 | + |
| 82 | +The short command starts Cursor-like Debug Mode: |
| 83 | + |
| 84 | +```text |
| 85 | +/cursor-like-debug-mode <problem description> |
| 86 | +``` |
| 87 | + |
| 88 | +Pi also exposes both native skill commands: |
| 89 | + |
| 90 | +```text |
| 91 | +/skill:trace-mode <runtime question> |
| 92 | +/skill:debug-mode <problem description> |
| 93 | +``` |
| 94 | + |
| 95 | +## Install |
| 96 | + |
| 97 | +### Codex plugin |
| 98 | + |
| 99 | +Add this repository as a marketplace and install the plugin: |
| 100 | + |
| 101 | +```bash |
| 102 | +codex plugin marketplace add https://github.com/wangnan0916/runtime-debug-toolkit.git --ref main |
| 103 | +codex plugin add runtime-debug-toolkit@runtime-debug-toolkit |
| 104 | +``` |
| 105 | + |
| 106 | +The plugin packages both skills. It does not load the Pi extension, an MCP |
| 107 | +server, or an external service. |
| 108 | + |
| 109 | +### Pi |
| 110 | + |
| 111 | +Install the package to load both skills, the short command, and the chooser: |
| 112 | + |
| 113 | +```bash |
| 114 | +pi install git:github.com/wangnan0916/runtime-debug-toolkit |
| 115 | +``` |
| 116 | + |
| 117 | +### Other agents |
| 118 | + |
| 119 | +Use the open Agent Skills CLI and select both skills when installing |
| 120 | +`debug-mode`: |
| 121 | + |
| 122 | +```bash |
| 123 | +npx skills add wangnan0916/runtime-debug-toolkit |
| 124 | +npx skills add wangnan0916/runtime-debug-toolkit -g |
| 125 | +npx skills add wangnan0916/runtime-debug-toolkit -a codex |
| 126 | +npx skills add wangnan0916/runtime-debug-toolkit --list |
| 127 | +``` |
| 128 | + |
| 129 | +`trace-mode` can be installed independently. `debug-mode` requires both sibling |
| 130 | +skill directories because its workflow reuses the shared resources. |
| 131 | + |
| 132 | +## Layout |
| 133 | + |
| 134 | +```text |
| 135 | +.codex-plugin/ |
| 136 | + plugin.json |
| 137 | +
|
| 138 | +.agents/plugins/ |
| 139 | + marketplace.json |
| 140 | +
|
| 141 | +extensions/ |
| 142 | + cursor-like-debug-mode.ts |
| 143 | + cursor-like-debug-mode-choice.mjs |
| 144 | +
|
| 145 | +skills/trace-mode/ |
| 146 | + SKILL.md # trace and code-location workflow |
| 147 | + agents/openai.yaml |
| 148 | + assets/ |
| 149 | + browser-log-helper.js # generic browser event sender |
| 150 | + node-log-helper.js # generic Node.js event sender |
| 151 | + references/ |
| 152 | + checkpoint.md # manual trace capture gate |
| 153 | + collector.md # lifecycle and authorization contract |
| 154 | + probes.md # event design, privacy, and markers |
| 155 | + protocol.md # HTTP and NDJSON contract |
| 156 | + troubleshooting.md |
| 157 | + scripts/ |
| 158 | + log-server.mjs # shared loopback server |
| 159 | + start-collector.mjs # safe reusable entrypoint |
| 160 | + summarize-log.mjs # shared evidence summarizer |
| 161 | +
|
| 162 | +skills/debug-mode/ |
| 163 | + SKILL.md # hypothesis, fix, verify, clean workflow |
| 164 | + agents/openai.yaml |
| 165 | + references/ |
| 166 | + checkpoints.md # pre-fix and post-fix gates |
| 167 | + probes.md # debug fields layered on generic events |
| 168 | + troubleshooting.md |
| 169 | +
|
| 170 | +tests/ |
| 171 | +``` |
| 172 | + |
| 173 | +## Safety |
| 174 | + |
| 175 | +- The server binds only to `127.0.0.1`, `localhost`, or `::1`. |
| 176 | +- The safe wrapper always uses `127.0.0.1` with an available port. |
| 177 | +- The server makes no external network calls. |
| 178 | +- Event payloads exclude secrets, credentials, and unrelated personal data. |
| 179 | +- Temporary instrumentation uses `LOG_SERVER_PROBE <session_id>` markers. |
| 180 | +- Runtime logs stay outside the repository and should not be committed. |
| 181 | + |
| 182 | +## Development |
| 183 | + |
| 184 | +Requires Node.js 24 or later. Tests use only Node.js built-ins. |
| 185 | + |
| 186 | +```bash |
| 187 | +npm run check |
| 188 | +npm test |
| 189 | +``` |
| 190 | + |
| 191 | +## License |
| 192 | + |
| 193 | +MIT. See [LICENSE](LICENSE). |
0 commit comments