Community编程与开发github.com

Node Inspect 调试器

使用 node inspect、--inspect、断点、CDP、堆和 CPU 性能分析来调试 Node.js。

Node Inspect 调试器 是什么?

Node Inspect 调试器是一项 AI 代理技能,专注于使用 Node.js 内置的检查器功能进行深度调试。它适用于处理隐藏局部变量、异步挂起、不稳定测试、子进程、启动竞态、内存增长或 CPU 热点路径等场景。该技能支持 node inspect 命令行工具和 Chrome DevTools 协议 (CDP),并提供了快速启动指南、调试器 REPL 命令、OpenClaw 调试提示、程序化 CDP 示例代码以及 CPU 和堆性能分析的操作步骤。它兼容常见的 AI 代理平台(如 Claude Code、Cursor、Codex),并提供了在调试过程中避免常见陷阱的最佳实践。

兼容平台~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 协议。

快速开始

  • 在入口暂停: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 或一个唯一的端口。
  • 如果断点未命中,请确认文件路径、source map 行为以及执行是否已经过该行。
  • 如果分离后进程似乎冻结了,它可能仍然暂停在调试器中。

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.

相关技能