A systematic debugging capability that automates evidence collection via dynamic instrumentation. Use when manual tracing is tedious or environment is restricted.
Core Philosophy: Don't guess. Instrument, measure, and let the data reveal the root cause.
This skill empowers you to debug complex issues by systematically injecting lightweight probes (fetch calls) into the codebase. These probes stream real-time execution data (function entries, variable states, errors) to a local debug server, allowing you to reconstruct the exact execution flow without relying on scattered console logs or interactive debuggers.
Follow this 4-phase loop to resolve issues efficiently.
Don't rush to code. First, define what you need to capture.
bootstrap.js is running (node .agent/skills/automated-instrumented-debugging/scripts/bootstrap.js).#region DEBUG blocks (Entry, Exit, Error, State).Inject probes using the standard templates. Always use the #region DEBUG wrapper for easy cleanup.
try-catch blocks in critical paths.(See "Instrumentation Templates" below for code patterns)
Run the reproduction case and let the data speak.
curl http://localhost:9876/logs/{session}.Fix the root cause and restore the codebase.
#region DEBUG blocks using the cleanup script:node .agent/skills/automated-instrumented-debugging/scripts/cleanup.js
// #region DEBUG - {SESSION}
fetch('http://localhost:9876/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
session: '{SESSION}',
type: 'enter',
fn: '{FUNC}',
file: '{FILE_PATH}', // Use absolute path or relative to project root
data: { arg1, arg2 }, // Snapshot arguments
}),
}).catch(() => {});
// #endregion
// #region DEBUG - {SESSION}
fetch('http://localhost:9876/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
session: '{SESSION}',
type: 'var',
fn: '{FUNC}',
file: '{FILE_PATH}',
data: { varName: value },
}),
}).catch(() => {});
// #endregion
// #region DEBUG - {SESSION}
fetch('http://localhost:9876/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
session: '{SESSION}',
type: 'exit',
fn: '{FUNC}',
data: { result },
}),
}).catch(() => {});
// #endregion
// #region DEBUG - {SESSION}
fetch('http://localhost:9876/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
session: '{SESSION}',
type: 'error',
fn: '{FUNC}',
data: { error: err.message, stack: err.stack },
}),
}).catch(() => {});
// #endregion
β Sync Fetch Trap: Using fetch without considering execution order in critical paths.
-> Fix: Always use .catch(() => {}) and place probes after variable definitions.
β Committing Probes: Forgetting to run cleanup.js.
-> Fix: Add cleanup as a mandatory step in your "Resolution & Cleanup" workflow.