Community程式設計與開發github.com

node-inspect-debugger

使用 node inspect、--inspect、中斷點、CDP、堆積與 CPU 分析來除錯 Node.js。

node-inspect-debugger 是什麼?

Node Inspect Debugger 是一個專為 Node.js 開發者設計的除錯技能,提供從基本偵錯到進階 Chrome DevTools Protocol(CDP)操作的全面支援。它能處理隱藏區域變數、非同步懸掛、不穩定測試、子程序、啟動競態、記憶體增長與 CPU 熱點等複雜情境。此技能支援多種平台,包括 `node inspect` 指令、`--inspect-brk` 啟動參數、PID 附加偵錯、以及程式化 CDP 驅動。使用方式涵蓋快速暫停、中斷點管理、REPL 互動式評估,並提供堆積快照與 CPU 分析檔案的生成與審視方法。此外,它還包含 OpenClaw 的實用提示、CDP 最小驅動程式範例,以及常見陷阱說明,幫助開發者有效排除問題。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/skills/node-inspect-debugger

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Node Inspect 除錯器

用於需要檢查器存取的 Node.js 除錯:隱藏區域變數、非同步懸掛、不穩定測試、子程序、啟動競態、記憶體增長或 CPU 熱點。

預設優先使用 node inspect。僅在需要腳本式中斷點、自動化狀態擷取、堆積快照或 CPU 分析時,才使用 Chrome DevTools Protocol。

快速入門

  • 進程時暫停:node inspect path/to/script.js
  • TypeScript:node --inspect-brk --import tsx path/to/script.ts
  • 現有 PID:kill -SIGUSR1 <pid> 然後 node inspect -p <pid>
  • 檢查目標列表:curl -s http://127.0.0.1:9229/json/list | jq
  • OpenClaw CLI 路徑:node --inspect-brk openclaw.mjs ...
  • OpenClaw 測試路徑:OPENCLAW_VITEST_MAX_WORKERS=1 node --inspect-brk scripts/run-vitest.mjs <file>

除錯器 REPL

  • 繼續/單步:cont、next、step、out、pause
  • 中斷點:sb('file.js', 42)、sb(42)、sb('functionName')、breakpoints、cb('file.js', 42)
  • 檢查:bt、list(8)、watch('expr')、exec expr
  • 目前作用域:repl,然後直接評估區域變數;Ctrl+C 退出 repl 模式。
  • 安全退出:如果進程應繼續,請在退出前使用 cont;否則使用 kill。

OpenClaw 提示

  • 偏好 127.0.0.1 檢查器綁定。除非網路已隔離,否則不要暴露 --inspect=0.0.0.0。
  • 對於 Vitest,使用一個工作程序除錯一個檔案。單步執行時避免使用工作程序池。
  • 對於 TypeScript 原始碼中斷點,必要時使用 --enable-source-maps;node inspect 仍可能顯示編譯後的路徑。
  • 對於子程序,NODE_OPTIONS=--inspect-brk 可以傳播檢查器,但每個子程序需要自己的連接埠。
  • 對於長時間執行的閘道或開發進程,在透過 /json/list 確認目標後,使用 PID 附加。

程式化 CDP

除非專案已依賴,否則在儲存庫外安裝工具:

mkdir -p /tmp/cdp-tools
npm --prefix /tmp/cdp-tools i chrome-remote-interface
NODE_PATH=/tmp/cdp-tools/node_modules node /tmp/cdp-debug.cjs

最小驅動程式:

const CDP = require("chrome-remote-interface");

(async () => {
  const client = await CDP({ port: 9229 });
  const { Debugger, Runtime } = client;

  Debugger.paused(async ({ callFrames, reason }) => {
    const top = callFrames[0];
    console.log("paused", reason, top.url, top.location.lineNumber + 1);
    const { result } = await Debugger.evaluateOnCallFrame({
      callFrameId: top.callFrameId,
      expression: "JSON.stringify({ pid: process.pid })",
    });
    console.log(result.value ?? result.description);
    await Debugger.resume();
  });

  await Runtime.enable();
  await Debugger.enable();
  await Debugger.setBreakpointByUrl({ urlRegex: ".*target\\.js$", lineNumber: 41 });
  await Runtime.runIfWaitingForDebugger();
})();

分析

  • CPU:啟用 Profiler、start、等待、stop、寫入 /tmp/profile.cpuprofile,在 Chrome DevTools 中開啟。
  • 堆積:啟用 HeapProfiler、收集 addHeapSnapshotChunk、呼叫 takeHeapSnapshot、寫入 /tmp/heap.heapsnapshot。

常見陷阱

  • --inspect 不會暫停;設定必須在程式碼執行前完成時,請使用 --inspect-brk。
  • 預設連接埠為 9229;對於平行目標,請使用 --inspect=0 或一個唯一的連接埠。
  • 如果中斷點未命中,請確認檔案路徑、原始碼對應行為,以及執行是否已通過該行。
  • 如果進程在分離後看起來凍結,它可能仍暫停在除錯器中。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Grok Build, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills and agent Templates when requested; add Templates; install, verify, update, uninstall, publish, or sync skills.

相關技能