Communityコーディング&開発github.com

Node インスペクトデバッガー

node inspect、--inspect、ブレークポイント、CDP、ヒープ、CPUプロファイルを使ってNode.jsをデバッグします。

Node インスペクトデバッガー とは?

このスキルは、Node.jsのデバッグにインスペクタアクセスが必要な場面で使用します。隠れたローカル変数、非同期ハング、不安定なテスト、子プロセス、起動時の競合、メモリ増大、CPUのホットパスなどが対象です。 まず`node inspect`をデフォルトとして推奨し、スクリプトによるブレークポイントの設定や自動状態取得、ヒープスナップショット、CPUプロファイルが必要な場合にのみChrome DevTools Protocol (CDP)を使います。 クイックスタートからデバッガREPLの使い方、TypeScriptのデバッグ、子プロセスやOpenClaw固有の注意点まで詳しくカバー。特にVitestと併用する際のシングルワーカー制限や、127.0.0.1へのバインド推奨など実践的なアドバイスを提供します。 また、プログラムでCDPを利用する最小限のJavaScriptドライバー例や、CPU/ヒーププロファイル取得の手順も含んでいます。ブレークポイントが効かない場合のトラブルシューティングやデフォルトポートの競合回避など、よくある落とし穴についても言及しており、本番環境でも安全に使えるよう設計されています。

対応~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に質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Node インスペクトデバッガー は何をしますか?

Node.jsのデバッグでインスペクタアクセスが必要な場合に使用します。隠れたローカル変数、非同期ハング、不安定なテスト、子プロセス、起動時の競合、メモリ増大、CPUのホットパスなどが対象です。

まずは node inspect をデフォルトとして使用してください。スクリプトによるブレークポイントの設定、自動状態取得、ヒープスナップショット、CPUプロファイルが必要な場合にのみChrome DevTools Protocol (CDP) を使用します。

クイックスタート

  • エントリで一時停止: 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では、1つのファイルを1つのワーカーでデバッグします。ステップ実行中はワーカープールを避けてください。
  • TSソースのブレークポイントには、必要に応じて --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 when explicitly requested; install, verify, update, uninstall, publish, or sync skills.

関連スキル