Evidence-driven debugging
Evidence-driven debugging mode activated. Follow the workflow below:
Generate multiple hypotheses based on the problem described by the user.
Insert narrow, hypothesis-specific instrumentation for each hypothesis.
Provide reproduction steps and ask the user to reproduce the issue.
Read the captured runtime data and identify the confirmed root cause.
Implement fix based on the confirmed root cause.
If the user confirms the issue has been resolved, clean up all inserted log
statements; otherwise, add more logs or generate new hypotheses
IMPORTANT: Do not implement a fix until it is supported by runtime evidence.
IMPORTANT: Do not clean up instrumentation until the user confirms the issue
has been fixed.
Rules
Before reading debug-agent.log, check its size and approximate entry count.
Do not read a large log end-to-end in one pass; filter by hypothesis ID,
location, time range, or other relevant keywords, and write a small analysis
script when aggregation or correlation is needed.
Before each new request for the user to reproduce the issue, clear the
existing debug-agent.log so that the next capture is attributable to that
reproduction. If the historical entries may be needed, create a separate
backup first (for example, with a timestamp or reproduction-batch suffix),
then clear the active log.
Separate diagnosis from repair selection. Assess whether the confirmed cause
calls for a root-cause fix, a smaller mitigation, or both. A mitigation that
merely masks the symptom must not be presented as the root-cause fix.
If there are multiple viable fixes, or the root-cause fix has a materially
larger change surface, present the options, trade-offs, and verification
implications to the user and ask them to choose before editing production
code. If one proportionate root-cause fix is clearly preferred, explain why
and proceed only after the runtime evidence supports it.
How to Write to Log Files
All logs must be written to {project_root}/debug-agent.log. Note: absolute paths must be used.
Inserted log statements should be wrapped with appropriate comment statements for location and cleanup
Log content should include: hypothesis ID (A/B/C/...), log location (e.g., api-get_weather), and specific information
Backend: write via file IO
// #region agent log
{
use std::io::Write;
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(r"absolute\path\to\debug-agent.log") {
let _ = writeln!(f, "log_content");
}
}
// #endregion
- Frontend: start the bundled receiver script, then write via
fetch.
node <this-skill-directory>/scripts/debug-log-server.mjs --root <project-root>
This uses the default local port (7469) and writes to debug-agent.log in the
project root. Run the script with --help to see options for a different
project root, port, log path, or startup behavior.
Inserted frontend logs should use this pattern:
// #region agent log
void fetch('http://127.0.0.1:7469/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 'A',
loc: 'ComponentName.eventName',
msg: 'specific observation',
data: { value },
}),
}).catch(() => {});
// #endregion
The receiver exposes:
POST /clear to clear the log file
GET /health to confirm the server and log path
Keep frontend instrumentation project-agnostic: avoid importing app-specific debug utilities unless the project already has a logging adapter that can POST to this receiver cleanly.
1---2name: debug3description: Use this skill to locate a runtime bug. Add targeted instrumentation, collect reproduction evidence, and confirm the root cause before changing code.4---56# Evidence-driven debugging78Evidence-driven debugging mode activated. Follow the workflow below:9101. Generate multiple hypotheses based on the problem described by the user.11122. Insert narrow, hypothesis-specific instrumentation for each hypothesis.13143. Provide reproduction steps and ask the user to reproduce the issue.15164. Read the captured runtime data and identify the confirmed root cause.17185. Implement fix based on the confirmed root cause.19206. If the user confirms the issue has been resolved, clean up all inserted log 21 statements; otherwise, add more logs or generate new hypotheses2223IMPORTANT: Do not implement a fix until it is supported by runtime evidence.24IMPORTANT: Do not clean up instrumentation until the user confirms the issue25has been fixed.2627## Rules2829- Before reading `debug-agent.log`, check its size and approximate entry count.30 Do not read a large log end-to-end in one pass; filter by hypothesis ID,31 location, time range, or other relevant keywords, and write a small analysis32 script when aggregation or correlation is needed.3334- Before each new request for the user to reproduce the issue, clear the35 existing `debug-agent.log` so that the next capture is attributable to that36 reproduction. If the historical entries may be needed, create a separate37 backup first (for example, with a timestamp or reproduction-batch suffix),38 then clear the active log.3940- Separate diagnosis from repair selection. Assess whether the confirmed cause41 calls for a root-cause fix, a smaller mitigation, or both. A mitigation that42 merely masks the symptom must not be presented as the root-cause fix.4344- If there are multiple viable fixes, or the root-cause fix has a materially45 larger change surface, present the options, trade-offs, and verification46 implications to the user and ask them to choose before editing production47 code. If one proportionate root-cause fix is clearly preferred, explain why48 and proceed only after the runtime evidence supports it.4950## How to Write to Log Files51521. All logs must be written to `{project_root}/debug-agent.log`. Note: absolute paths must be used.53542. Inserted log statements should be wrapped with appropriate comment statements for location and cleanup55563. Log content should include: hypothesis ID (A/B/C/...), log location (e.g., api-get_weather), and specific information57584. Backend: write via file IO59```rust60// #region agent log61{62 use std::io::Write;63 if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(r"absolute\path\to\debug-agent.log") {64 let _ = writeln!(f, "log_content");65 }66}67// #endregion68```69705. Frontend: start the bundled receiver script, then write via `fetch`.7172```bash73node <this-skill-directory>/scripts/debug-log-server.mjs --root <project-root>74```7576This uses the default local port (7469) and writes to `debug-agent.log` in the77project root. Run the script with `--help` to see options for a different78project root, port, log path, or startup behavior.7980Inserted frontend logs should use this pattern:8182```ts83// #region agent log84void fetch('http://127.0.0.1:7469/log', {85 method: 'POST',86 headers: { 'Content-Type': 'application/json' },87 body: JSON.stringify({88 id: 'A',89 loc: 'ComponentName.eventName',90 msg: 'specific observation',91 data: { value },92 }),93}).catch(() => {});94// #endregion95```9697The receiver exposes:98- `POST /clear` to clear the log file99- `GET /health` to confirm the server and log path100101Keep frontend instrumentation project-agnostic: avoid importing app-specific debug utilities unless the project already has a logging adapter that can POST to this receiver cleanly.