[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77MJYXCNRN98SHQ3AGCVM34":3,"skill-same:01M77MJYXCNRN98SHQ3AGCVM34":53},{"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":33,"commitSha":34,"skillDirectory":35,"forksCount":13,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":38,"install":39,"resources":52},"01M77MJYXCNRN98SHQ3AGCVM34","node-inspect-debugger",null,"Debug Node.js via --inspect + Chrome DevTools Protocol CLI.","pan-hh\u002Fmateclaw-hybrid","pan-hh","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F244917262?v=4","01M77MGAQE06HNBEHKYN7180V6","01M77MGARJ7JXWZYKA9RMM968R",4,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fnode-inspect-debugger\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: node-inspect-debugger\ndescription: Debug Node.js via --inspect + Chrome DevTools Protocol CLI.\nversion: 1.1.0\ntags:\n- debugging\n- nodejs\n- node-inspect\n- cdp\n- breakpoints\n- electron\n- vite\nauthor: ported\n---\n# Node.js Inspect Debugger\n\n## Overview\n\nWhen `console.log` isn't enough, drive Node's built-in V8 inspector programmatically from the terminal. You get real breakpoints, step in\u002Fover\u002Fout, call-stack walking, local\u002Fclosure scope dumps, and arbitrary expression evaluation in the paused frame.\n\nTwo tools, pick one:\n\n- **`node inspect`** — built-in, zero install, CLI REPL. Best for quick poking.\n- **`ndb` \u002F CDP via `chrome-remote-interface`** — scriptable from Node\u002FPython; best when you want to automate many breakpoints, collect state across runs, or debug non-interactively from an agent loop.\n\n**Prefer `node inspect` first.** It's always available and the REPL is fast.\n\nIn this repo the Node.js surfaces are the front-end packages — `mateclaw-ui`, `mateclaw-webchat`, and the Electron desktop app `mateclaw-desktop`. The Spring Boot backend is a JVM process and is not a target for this skill.\n\n## When to Use\n\n- A Node-based build or packaging step (a Vite build, an `electron-builder` hook, a `scripts\u002F` helper) fails and you need to see intermediate state\n- The Electron desktop **main process** (`mateclaw-desktop`) crashes, hangs on startup, or mishandles the bundled Java backend child process\n- A Vite dev server or a build plugin behaves wrong and `console.log` can't reach the value\n- You need to inspect a value in a closure that `console.log` can't reach without patching\n- Perf: attach to a running process to capture a CPU profile or heap snapshot\n\n**Don't use for:** things `console.log` solves in under a minute. Breakpoint-driven debugging is heavier; use it when the payoff is real. The Electron **renderer** is a Chromium page, not a Node target — debug it with the window's built-in DevTools, not `node inspect`.\n\n## Quick Reference: `node inspect` REPL\n\nLaunch paused on first line:\n\n```bash\nnode inspect path\u002Fto\u002Fscript.js\n# or with tsx\nnode --inspect-brk $(which tsx) path\u002Fto\u002Fscript.ts\n```\n\nThe `debug>` prompt accepts:\n\n| Command | Action |\n|---|---|\n| `c` or `cont` | continue |\n| `n` or `next` | step over |\n| `s` or `step` | step into |\n| `o` or `out` | step out |\n| `pause` | pause running code |\n| `sb('file.js', 42)` | set breakpoint at file.js line 42 |\n| `sb(42)` | set breakpoint at line 42 of current file |\n| `sb('functionName')` | break when function is called |\n| `cb('file.js', 42)` | clear breakpoint |\n| `breakpoints` | list all breakpoints |\n| `bt` | backtrace (call stack) |\n| `list(5)` | show 5 lines of source around current position |\n| `watch('expr')` | evaluate expr on every pause |\n| `watchers` | show watched expressions |\n| `repl` | drop into REPL in current scope (Ctrl+C to exit REPL) |\n| `exec expr` | evaluate expression once |\n| `restart` | restart script |\n| `kill` | kill the script |\n| `.exit` | quit debugger |\n\n**In the `repl` sub-mode:** type any JS expression, including access to locals\u002Fclosure variables. `Ctrl+C` exits back to `debug>`.\n\n## Attaching to a Running Process\n\nWhen the process is already running (e.g. a Vite dev server, or the Electron main process):\n\n```bash\n# 1. Send SIGUSR1 to enable the inspector on an existing process\nkill -SIGUSR1 \u003Cpid>\n# Node prints: Debugger listening on ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n\n# 2. Attach the debugger CLI\nnode inspect -p \u003Cpid>\n# or by URL\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nTo start a process with the inspector from the beginning:\n\n```bash\nnode --inspect script.js           # listen on 127.0.0.1:9229, keep running\nnode --inspect-brk script.js       # listen AND pause on first line\nnode --inspect=0.0.0.0:9230 script.js   # custom host:port\n```\n\nFor TypeScript via tsx:\n\n```bash\nnode --inspect-brk --import tsx script.ts\n# or older tsx\nnode --inspect-brk -r tsx\u002Fcjs script.ts\n```\n\n## Programmatic CDP (scripting from terminal)\n\nWhen you want to automate — set many breakpoints, capture scope state, script a repro — use `chrome-remote-interface`:\n\n```bash\nnpm i -g chrome-remote-interface        # or project-local\n# Start your target:\nnode --inspect-brk=9229 target.js &\n```\n\nDriver script (save as `\u002Ftmp\u002Fcdp-debug.js`):\n\n```javascript\nconst CDP = require('chrome-remote-interface');\n\n(async () => {\n  const client = await CDP({ port: 9229 });\n  const { Debugger, Runtime } = client;\n\n  Debugger.paused(async ({ callFrames, reason }) => {\n    const top = callFrames[0];\n    console.log(`PAUSED: ${reason} @ ${top.url}:${top.location.lineNumber + 1}`);\n\n    \u002F\u002F Walk scopes for locals\n    for (const scope of top.scopeChain) {\n      if (scope.type === 'local' || scope.type === 'closure') {\n        const { result } = await Runtime.getProperties({\n          objectId: scope.object.objectId,\n          ownProperties: true,\n        });\n        for (const p of result) {\n          console.log(`  ${scope.type}.${p.name} =`, p.value?.value ?? p.value?.description);\n        }\n      }\n    }\n\n    \u002F\u002F Evaluate an expression in the paused frame\n    const { result } = await Debugger.evaluateOnCallFrame({\n      callFrameId: top.callFrameId,\n      expression: 'typeof state !== \"undefined\" ? JSON.stringify(state) : \"n\u002Fa\"',\n    });\n    console.log('state =', result.value ?? result.description);\n\n    await Debugger.resume();\n  });\n\n  await Runtime.enable();\n  await Debugger.enable();\n\n  \u002F\u002F Set a breakpoint by URL regex + line\n  await Debugger.setBreakpointByUrl({\n    urlRegex: '.*dist-electron\u002Fmain\u002Findex\\\\.js$',\n    lineNumber: 119,       \u002F\u002F 0-indexed\n    columnNumber: 0,\n  });\n\n  await Runtime.runIfWaitingForDebugger();\n})();\n```\n\nRun it:\n\n```bash\nnode \u002Ftmp\u002Fcdp-debug.js\n```\n\n`chrome-remote-interface` is not a dependency of any package in this repo. Install it to a throwaway location so you don't dirty a project's `package.json`:\n\n```bash\nmkdir -p \u002Ftmp\u002Fcdp-tools && cd \u002Ftmp\u002Fcdp-tools && npm i chrome-remote-interface\nNODE_PATH=\u002Ftmp\u002Fcdp-tools\u002Fnode_modules node \u002Ftmp\u002Fcdp-debug.js\n```\n\n## Debugging the Electron Desktop App\n\n`mateclaw-desktop` is an Electron app. The **main process** is a Node process — `electron\u002Fmain\u002Findex.ts`, compiled by Vite to `dist-electron\u002Fmain\u002Findex.js` (the `main` field in `package.json`). It spawns the Java backend as a child process. The **renderer** is a Chromium `BrowserWindow` — debug that with the window's DevTools, not this skill.\n\n### Launch the main process paused\n\nElectron forwards `--inspect` \u002F `--inspect-brk` to its main process. Build the Electron output first so there is a `dist-electron\u002F` to run:\n\n```bash\ncd mateclaw-desktop\nnpm run build                          # produces dist\u002F and dist-electron\u002F\nnpx electron --inspect-brk=9229 .      # Electron starts, paused on the main process first line\n# In another terminal:\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nThen inside `debug>`:\n\n```\nsb('dist-electron\u002Fmain\u002Findex.js', 220)   # e.g. the suspect line in window\u002Fbackend setup\ncont\n```\n\nWhen it pauses, `repl` → inspect `mainWindow`, `javaProcess`, `BACKEND_PORT`, the updater state, etc.\n\n### Attach to an already-running desktop app\n\nThe Electron main process is the one launched without a `--type=` flag (renderer\u002FGPU\u002Futility processes carry `--type=`):\n\n```bash\n# Find the main process PID (the entry without --type=)\nps aux | grep -i 'mateclaw-desktop' | grep -v -- '--type='\n\n# Enable the inspector on it\nkill -SIGUSR1 \u003Cmain-pid>\n\n# Find the WS URL and attach\ncurl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist | jq -r '.[0].webSocketDebuggerUrl'\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nThe Java backend that the main process spawns is a JVM, not a Node target — it will not appear in `\u002Fjson\u002Flist`. To debug that, use the JVM's own remote-debug flags, not this skill.\n\n## Debugging a Vite Dev Server\n\n`mateclaw-ui`, `mateclaw-webchat`, and `mateclaw-desktop` all run `vite` for `dev`. To step through Vite config or a build plugin, run Vite's binary under the inspector instead of the `pnpm dev` wrapper:\n\n```bash\ncd mateclaw-ui\nnode --inspect-brk .\u002Fnode_modules\u002Fvite\u002Fbin\u002Fvite.js\n# In another terminal: node inspect -p \u003Cpid>, then sb('vite.config.ts', N), cont\n```\n\nThis pauses inside the Node process that loads `vite.config.ts` and runs plugin hooks. The browser-side Vue code it serves is not reachable here — that runs in the browser and is debugged with browser DevTools.\n\n## Heap Snapshots & CPU Profiles (Non-interactive)\n\nFrom the CDP driver above, swap Debugger for `HeapProfiler` \u002F `Profiler`:\n\n```javascript\n\u002F\u002F CPU profile for 5 seconds\nawait client.Profiler.enable();\nawait client.Profiler.start();\nawait new Promise(r => setTimeout(r, 5000));\nconst { profile } = await client.Profiler.stop();\nrequire('fs').writeFileSync('\u002Ftmp\u002Fcpu.cpuprofile', JSON.stringify(profile));\n\u002F\u002F Open \u002Ftmp\u002Fcpu.cpuprofile in Chrome DevTools → Performance tab\n```\n\n```javascript\n\u002F\u002F Heap snapshot\nawait client.HeapProfiler.enable();\nconst chunks = [];\nclient.HeapProfiler.addHeapSnapshotChunk(({ chunk }) => chunks.push(chunk));\nawait client.HeapProfiler.takeHeapSnapshot({ reportProgress: false });\nrequire('fs').writeFileSync('\u002Ftmp\u002Fheap.heapsnapshot', chunks.join(''));\n```\n\n## Common Pitfalls\n\n1. **Wrong line numbers in TS source.** Breakpoints hit the emitted JS, not the `.ts`. Either (a) break in the built file (`dist-electron\u002Fmain\u002Findex.js`), or (b) enable sourcemaps (`node --enable-source-maps`) and use `sb('electron\u002Fmain\u002Findex.ts', N)` — but only with CDP clients that follow sourcemaps. The `node inspect` CLI does not.\n\n2. **`--inspect` vs `--inspect-brk`.** `--inspect` starts the inspector but doesn't pause; your script races past your first breakpoint if you attach too late. Use `--inspect-brk` when you need to set breakpoints before any code runs.\n\n3. **Port collisions.** Default is `9229`. If multiple Node processes are inspecting, pass `--inspect=0` (random port) and read the actual URL from `\u002Fjson\u002Flist`:\n   ```bash\n   curl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist   # lists all inspectable targets on the host\n   ```\n\n4. **Child processes.** `--inspect` on a parent does NOT inspect its children. Electron itself is multi-process, and the desktop main process additionally spawns the Java backend. Use `NODE_OPTIONS='--inspect-brk' node parent.js` to propagate to every Node child; be aware they all need unique ports (Node auto-increments when `NODE_OPTIONS='--inspect'` is inherited).\n\n5. **Background kills.** If you `Ctrl+C` out of `node inspect` while the target is paused, the target stays paused. Either `cont` first, or `kill` the target explicitly.\n\n6. **Running `node inspect` through the agent's shell tool.** The `execute_shell_command` tool is one-shot and non-interactive — it cannot drive the interactive `debug>` REPL. For interactive stepping, run `node inspect` in a real terminal yourself. For agent-driven debugging, prefer the scripted CDP driver above: it is fully non-interactive and runs fine as a single `execute_shell_command` call.\n\n7. **Security.** `--inspect=0.0.0.0:9229` exposes arbitrary code execution. Always bind to `127.0.0.1` (the default) unless you have an isolated network.\n\n## Verification Checklist\n\nAfter setting up a debug session, verify:\n\n- [ ] `curl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist` returns exactly the target you expect\n- [ ] First breakpoint actually hits (if it doesn't, you likely missed `--inspect-brk` or attached after execution completed)\n- [ ] Source listing at pause shows the right file (mismatch = sourcemap issue, see pitfall 1)\n- [ ] `exec process.pid` in `repl` returns the PID you meant to attach to\n\n## One-Shot Recipes\n\n**\"Why is this variable undefined at line X?\"**\n```bash\nnode --inspect-brk script.js &\nnode inspect -p $!\n# debug>\nsb('script.js', X)\ncont\n# paused. Now:\nrepl\n> myVariable\n> Object.keys(this)\n```\n\n**\"What's the call path into this function?\"**\n```\ndebug> sb('suspectFn')\ndebug> cont\n# paused on entry\ndebug> bt\n```\n\n**\"This async chain hangs — where?\"**\n```\n# Start with --inspect (no -brk), let it run to the hang, then:\ndebug> pause\ndebug> bt\n# Now you see the stuck frame\n```\n","# Node.js Inspect Debugger\n\n## Overview\n\nWhen `console.log` isn't enough, drive Node's built-in V8 inspector programmatically from the terminal. You get real breakpoints, step in\u002Fover\u002Fout, call-stack walking, local\u002Fclosure scope dumps, and arbitrary expression evaluation in the paused frame.\n\nTwo tools, pick one:\n\n- **`node inspect`** — built-in, zero install, CLI REPL. Best for quick poking.\n- **`ndb` \u002F CDP via `chrome-remote-interface`** — scriptable from Node\u002FPython; best when you want to automate many breakpoints, collect state across runs, or debug non-interactively from an agent loop.\n\n**Prefer `node inspect` first.** It's always available and the REPL is fast.\n\nIn this repo the Node.js surfaces are the front-end packages — `mateclaw-ui`, `mateclaw-webchat`, and the Electron desktop app `mateclaw-desktop`. The Spring Boot backend is a JVM process and is not a target for this skill.\n\n## When to Use\n\n- A Node-based build or packaging step (a Vite build, an `electron-builder` hook, a `scripts\u002F` helper) fails and you need to see intermediate state\n- The Electron desktop **main process** (`mateclaw-desktop`) crashes, hangs on startup, or mishandles the bundled Java backend child process\n- A Vite dev server or a build plugin behaves wrong and `console.log` can't reach the value\n- You need to inspect a value in a closure that `console.log` can't reach without patching\n- Perf: attach to a running process to capture a CPU profile or heap snapshot\n\n**Don't use for:** things `console.log` solves in under a minute. Breakpoint-driven debugging is heavier; use it when the payoff is real. The Electron **renderer** is a Chromium page, not a Node target — debug it with the window's built-in DevTools, not `node inspect`.\n\n## Quick Reference: `node inspect` REPL\n\nLaunch paused on first line:\n\n```bash\nnode inspect path\u002Fto\u002Fscript.js\n# or with tsx\nnode --inspect-brk $(which tsx) path\u002Fto\u002Fscript.ts\n```\n\nThe `debug>` prompt accepts:\n\n| Command | Action |\n|---|---|\n| `c` or `cont` | continue |\n| `n` or `next` | step over |\n| `s` or `step` | step into |\n| `o` or `out` | step out |\n| `pause` | pause running code |\n| `sb('file.js', 42)` | set breakpoint at file.js line 42 |\n| `sb(42)` | set breakpoint at line 42 of current file |\n| `sb('functionName')` | break when function is called |\n| `cb('file.js', 42)` | clear breakpoint |\n| `breakpoints` | list all breakpoints |\n| `bt` | backtrace (call stack) |\n| `list(5)` | show 5 lines of source around current position |\n| `watch('expr')` | evaluate expr on every pause |\n| `watchers` | show watched expressions |\n| `repl` | drop into REPL in current scope (Ctrl+C to exit REPL) |\n| `exec expr` | evaluate expression once |\n| `restart` | restart script |\n| `kill` | kill the script |\n| `.exit` | quit debugger |\n\n**In the `repl` sub-mode:** type any JS expression, including access to locals\u002Fclosure variables. `Ctrl+C` exits back to `debug>`.\n\n## Attaching to a Running Process\n\nWhen the process is already running (e.g. a Vite dev server, or the Electron main process):\n\n```bash\n# 1. Send SIGUSR1 to enable the inspector on an existing process\nkill -SIGUSR1 \u003Cpid>\n# Node prints: Debugger listening on ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n\n# 2. Attach the debugger CLI\nnode inspect -p \u003Cpid>\n# or by URL\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nTo start a process with the inspector from the beginning:\n\n```bash\nnode --inspect script.js           # listen on 127.0.0.1:9229, keep running\nnode --inspect-brk script.js       # listen AND pause on first line\nnode --inspect=0.0.0.0:9230 script.js   # custom host:port\n```\n\nFor TypeScript via tsx:\n\n```bash\nnode --inspect-brk --import tsx script.ts\n# or older tsx\nnode --inspect-brk -r tsx\u002Fcjs script.ts\n```\n\n## Programmatic CDP (scripting from terminal)\n\nWhen you want to automate — set many breakpoints, capture scope state, script a repro — use `chrome-remote-interface`:\n\n```bash\nnpm i -g chrome-remote-interface        # or project-local\n# Start your target:\nnode --inspect-brk=9229 target.js &\n```\n\nDriver script (save as `\u002Ftmp\u002Fcdp-debug.js`):\n\n```javascript\nconst CDP = require('chrome-remote-interface');\n\n(async () => {\n  const client = await CDP({ port: 9229 });\n  const { Debugger, Runtime } = client;\n\n  Debugger.paused(async ({ callFrames, reason }) => {\n    const top = callFrames[0];\n    console.log(`PAUSED: ${reason} @ ${top.url}:${top.location.lineNumber + 1}`);\n\n    \u002F\u002F Walk scopes for locals\n    for (const scope of top.scopeChain) {\n      if (scope.type === 'local' || scope.type === 'closure') {\n        const { result } = await Runtime.getProperties({\n          objectId: scope.object.objectId,\n          ownProperties: true,\n        });\n        for (const p of result) {\n          console.log(`  ${scope.type}.${p.name} =`, p.value?.value ?? p.value?.description);\n        }\n      }\n    }\n\n    \u002F\u002F Evaluate an expression in the paused frame\n    const { result } = await Debugger.evaluateOnCallFrame({\n      callFrameId: top.callFrameId,\n      expression: 'typeof state !== \"undefined\" ? JSON.stringify(state) : \"n\u002Fa\"',\n    });\n    console.log('state =', result.value ?? result.description);\n\n    await Debugger.resume();\n  });\n\n  await Runtime.enable();\n  await Debugger.enable();\n\n  \u002F\u002F Set a breakpoint by URL regex + line\n  await Debugger.setBreakpointByUrl({\n    urlRegex: '.*dist-electron\u002Fmain\u002Findex\\\\.js$',\n    lineNumber: 119,       \u002F\u002F 0-indexed\n    columnNumber: 0,\n  });\n\n  await Runtime.runIfWaitingForDebugger();\n})();\n```\n\nRun it:\n\n```bash\nnode \u002Ftmp\u002Fcdp-debug.js\n```\n\n`chrome-remote-interface` is not a dependency of any package in this repo. Install it to a throwaway location so you don't dirty a project's `package.json`:\n\n```bash\nmkdir -p \u002Ftmp\u002Fcdp-tools && cd \u002Ftmp\u002Fcdp-tools && npm i chrome-remote-interface\nNODE_PATH=\u002Ftmp\u002Fcdp-tools\u002Fnode_modules node \u002Ftmp\u002Fcdp-debug.js\n```\n\n## Debugging the Electron Desktop App\n\n`mateclaw-desktop` is an Electron app. The **main process** is a Node process — `electron\u002Fmain\u002Findex.ts`, compiled by Vite to `dist-electron\u002Fmain\u002Findex.js` (the `main` field in `package.json`). It spawns the Java backend as a child process. The **renderer** is a Chromium `BrowserWindow` — debug that with the window's DevTools, not this skill.\n\n### Launch the main process paused\n\nElectron forwards `--inspect` \u002F `--inspect-brk` to its main process. Build the Electron output first so there is a `dist-electron\u002F` to run:\n\n```bash\ncd mateclaw-desktop\nnpm run build                          # produces dist\u002F and dist-electron\u002F\nnpx electron --inspect-brk=9229 .      # Electron starts, paused on the main process first line\n# In another terminal:\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nThen inside `debug>`:\n\n```\nsb('dist-electron\u002Fmain\u002Findex.js', 220)   # e.g. the suspect line in window\u002Fbackend setup\ncont\n```\n\nWhen it pauses, `repl` → inspect `mainWindow`, `javaProcess`, `BACKEND_PORT`, the updater state, etc.\n\n### Attach to an already-running desktop app\n\nThe Electron main process is the one launched without a `--type=` flag (renderer\u002FGPU\u002Futility processes carry `--type=`):\n\n```bash\n# Find the main process PID (the entry without --type=)\nps aux | grep -i 'mateclaw-desktop' | grep -v -- '--type='\n\n# Enable the inspector on it\nkill -SIGUSR1 \u003Cmain-pid>\n\n# Find the WS URL and attach\ncurl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist | jq -r '.[0].webSocketDebuggerUrl'\nnode inspect ws:\u002F\u002F127.0.0.1:9229\u002F\u003Cuuid>\n```\n\nThe Java backend that the main process spawns is a JVM, not a Node target — it will not appear in `\u002Fjson\u002Flist`. To debug that, use the JVM's own remote-debug flags, not this skill.\n\n## Debugging a Vite Dev Server\n\n`mateclaw-ui`, `mateclaw-webchat`, and `mateclaw-desktop` all run `vite` for `dev`. To step through Vite config or a build plugin, run Vite's binary under the inspector instead of the `pnpm dev` wrapper:\n\n```bash\ncd mateclaw-ui\nnode --inspect-brk .\u002Fnode_modules\u002Fvite\u002Fbin\u002Fvite.js\n# In another terminal: node inspect -p \u003Cpid>, then sb('vite.config.ts', N), cont\n```\n\nThis pauses inside the Node process that loads `vite.config.ts` and runs plugin hooks. The browser-side Vue code it serves is not reachable here — that runs in the browser and is debugged with browser DevTools.\n\n## Heap Snapshots & CPU Profiles (Non-interactive)\n\nFrom the CDP driver above, swap Debugger for `HeapProfiler` \u002F `Profiler`:\n\n```javascript\n\u002F\u002F CPU profile for 5 seconds\nawait client.Profiler.enable();\nawait client.Profiler.start();\nawait new Promise(r => setTimeout(r, 5000));\nconst { profile } = await client.Profiler.stop();\nrequire('fs').writeFileSync('\u002Ftmp\u002Fcpu.cpuprofile', JSON.stringify(profile));\n\u002F\u002F Open \u002Ftmp\u002Fcpu.cpuprofile in Chrome DevTools → Performance tab\n```\n\n```javascript\n\u002F\u002F Heap snapshot\nawait client.HeapProfiler.enable();\nconst chunks = [];\nclient.HeapProfiler.addHeapSnapshotChunk(({ chunk }) => chunks.push(chunk));\nawait client.HeapProfiler.takeHeapSnapshot({ reportProgress: false });\nrequire('fs').writeFileSync('\u002Ftmp\u002Fheap.heapsnapshot', chunks.join(''));\n```\n\n## Common Pitfalls\n\n1. **Wrong line numbers in TS source.** Breakpoints hit the emitted JS, not the `.ts`. Either (a) break in the built file (`dist-electron\u002Fmain\u002Findex.js`), or (b) enable sourcemaps (`node --enable-source-maps`) and use `sb('electron\u002Fmain\u002Findex.ts', N)` — but only with CDP clients that follow sourcemaps. The `node inspect` CLI does not.\n\n2. **`--inspect` vs `--inspect-brk`.** `--inspect` starts the inspector but doesn't pause; your script races past your first breakpoint if you attach too late. Use `--inspect-brk` when you need to set breakpoints before any code runs.\n\n3. **Port collisions.** Default is `9229`. If multiple Node processes are inspecting, pass `--inspect=0` (random port) and read the actual URL from `\u002Fjson\u002Flist`:\n   ```bash\n   curl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist   # lists all inspectable targets on the host\n   ```\n\n4. **Child processes.** `--inspect` on a parent does NOT inspect its children. Electron itself is multi-process, and the desktop main process additionally spawns the Java backend. Use `NODE_OPTIONS='--inspect-brk' node parent.js` to propagate to every Node child; be aware they all need unique ports (Node auto-increments when `NODE_OPTIONS='--inspect'` is inherited).\n\n5. **Background kills.** If you `Ctrl+C` out of `node inspect` while the target is paused, the target stays paused. Either `cont` first, or `kill` the target explicitly.\n\n6. **Running `node inspect` through the agent's shell tool.** The `execute_shell_command` tool is one-shot and non-interactive — it cannot drive the interactive `debug>` REPL. For interactive stepping, run `node inspect` in a real terminal yourself. For agent-driven debugging, prefer the scripted CDP driver above: it is fully non-interactive and runs fine as a single `execute_shell_command` call.\n\n7. **Security.** `--inspect=0.0.0.0:9229` exposes arbitrary code execution. Always bind to `127.0.0.1` (the default) unless you have an isolated network.\n\n## Verification Checklist\n\nAfter setting up a debug session, verify:\n\n- [ ] `curl -s http:\u002F\u002F127.0.0.1:9229\u002Fjson\u002Flist` returns exactly the target you expect\n- [ ] First breakpoint actually hits (if it doesn't, you likely missed `--inspect-brk` or attached after execution completed)\n- [ ] Source listing at pause shows the right file (mismatch = sourcemap issue, see pitfall 1)\n- [ ] `exec process.pid` in `repl` returns the PID you meant to attach to\n\n## One-Shot Recipes\n\n**\"Why is this variable undefined at line X?\"**\n```bash\nnode --inspect-brk script.js &\nnode inspect -p $!\n# debug>\nsb('script.js', X)\ncont\n# paused. Now:\nrepl\n> myVariable\n> Object.keys(this)\n```\n\n**\"What's the call path into this function?\"**\n```\ndebug> sb('suspectFn')\ndebug> cont\n# paused on entry\ndebug> bt\n```\n\n**\"This async chain hangs — where?\"**\n```\n# Start with --inspect (no -brk), let it run to the hang, then:\ndebug> pause\ndebug> bt\n# Now you see the stuck frame\n```\n",{"name":5,"tags":23,"author":31,"version":32,"description":7},[24,25,26,27,28,29,30],"debugging","nodejs","node-inspect","cdp","breakpoints","electron","vite","ported","1.1.0","dev","26b960a788645da1daf5b6c1c8c7ffe1a78ab755","mateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fnode-inspect-debugger","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid","https:\u002F\u002Fgithub.com\u002Fpan-hh","2026-06-25 12:43:25",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add pan-hh\u002Fmateclaw-hybrid --skill node-inspect-debugger",{"tool":45,"command":46},"bunx","bunx skills add pan-hh\u002Fmateclaw-hybrid --skill node-inspect-debugger",{"tool":48,"command":49},"pnpm","pnpm dlx skills add pan-hh\u002Fmateclaw-hybrid --skill node-inspect-debugger","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fnode-inspect-debugger\u002FSKILL.md",true,[],[54,61,68,75,82,89],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":18},"01M77MNZW6PYRTH5KM9121RYAK","sample","Test fixture for SkillBundleMaterializer.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Ftest\u002Fresources\u002Ftest-bundles\u002Fsample\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M77MNNA8HYFP854EHAEGZ838","x_intel","Read X (Twitter) posts, search, timelines and user profiles via the official xurl CLI.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fx_intel\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":18},"01M77MNJRFN8KNSY1PXRFBV97S","writing-plans","Write implementation plans: bite-sized tasks, paths, code.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":18},"01M77MNF0PF06YCNA9TWK85PE9","webhook-subscriptions","Webhook subscriptions: event-driven agent runs.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fwebhook-subscriptions\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":18},"01M77MNATFKP03KPE7HM7W29MC","test-driven-development","TDD: enforce RED-GREEN-REFACTOR, tests before code.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Ftest-driven-development\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":18},"01M77MN78ZK5EKN7HT2ZKYDPKM","systematic-debugging","4-phase root cause debugging: understand bugs before fixing.","https:\u002F\u002Fgithub.com\u002Fpan-hh\u002Fmateclaw-hybrid\u002Fblob\u002Fdev\u002Fmateclaw-server\u002Fsrc\u002Fmain\u002Fresources\u002Fskills\u002Fsystematic-debugging\u002FSKILL.md",[],[]]