Debug ModeDebug mode

Debug Mode

Debug mode

The debugagent is the one built-in agent that writes code, compiles with your MCU's toolchain, flashes the board, and reads the serial line — closing the loop on real hardware instead of guessing.

When to use it

Reach for the debug agent when you describe a hardware symptom — a reset loop, panic, watchdog, brownout, hard fault, a sensor that won't read — or ask Flash to "debug/fix this on the board". It's not for read-only architecture analysis (that's the architecture agent) or a code change that doesn't need hardware (that's general).

shell
my SPI peripheral isn't responding  help me debugthe device panics on boot  use the board to find where it hangs

The loop

The agent's system prompt encodes a disciplined cycle:

1

Repro

Understand the symptom and its success criterion, and — if it can — establish a baseline (build → flash → read serial) to confirm the bug is present.
2

Locate & hypothesise

Find the code with find_symbol / component_api (both give file:line), then state one likely cause before touching anything.
3

Fix

Make a minimal edit that addresses the cause, not the symptom.
4

Build

Compile with build_firmware; if it fails, read the errors and fix before continuing — it never flashes a broken build.
5

Flash & verify

flash_firmware (gated by a confirmation), then read_serial against the success marker. If the symptom persists, loop back with what it learned.

Give it a success criterion

The more concrete the criterion, the better the loop closes. Tell it a serial pattern that must appear (e.g. DEBUG_AGENT_RECV 4) or must stop (e.g. Guru Meditation), or a window of time without resets. That's what read_serial checks for the baseline and the final verification, and it cites the result in its answer.

What you see in the TUI

Every step is reflected live — not dumped at the end:

StepWhat you see
file_editThe diff is typed in as red/green wash blocks with an intent header.
Edit permissionA permission card with an approve / deny selector.
build_firmware / flash_firmwareThe view jumps to the BUILD panel; the log streams there.
Flash confirmationA card: flash now / allow for session / skip.
read_serialThe view jumps to DEBUG; board output appears live and the capture expands in chat.

This works because the agent drives the same build and serial sessions the panels use — one owner of the serial port, so you watch in DEBUG exactly as the agent captures. Headless (flash query --agent debug) it falls back to ephemeral sessions and works the same.

Safety

  • Anti-loop guard — if a build fails twice on the same error, it stops, re-reads the whole file, and reports rather than editing blind.
  • Dry-run honesty— if results are simulated, it won't claim on-hardware verification; it says the fix is built and reasoned but verification is pending a board.
  • Shell deny-listbash runs under an unconditional deny-list (no sudo, recursive deletes, writes to block devices, curl | sh, git reset --hard, …).

Multi-target

The agent is MCU-agnostic. Per-target knowledge lives in command resolution — platformio.ini → PlatformIO, sdkconfig → ESP-IDF, west.yml → Zephyr, Arduino CLI — plus Stage 0 and the <COMMANDS> block in FLASH.md. Adding a new target doesn't touch the debug agent.

What's next