feat: debug mode — hypothesis-driven debugging (Cursor-style)#45
feat: debug mode — hypothesis-driven debugging (Cursor-style)#45kienbui1995 merged 4 commits intomainfrom
Conversation
- New 'debug' tool with 4 phases: hypothesize, instrument, analyze, fix - Guides agent through evidence-based debugging workflow - TUI '/debug' template activates debug mode in conversation - Agent generates hypotheses → adds logging → analyzes evidence → targeted fix - 30 tools total, 192 tests pass, 0 warnings
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new synchronous "debug" tool: spec, core handler ( Changes
Sequence DiagramsequenceDiagram
participant User as User/TUI
participant Runtime as Runtime
participant Registry as Tool Registry
participant Debug as execute_debug
User->>Runtime: invoke tool "debug" with input (action + params)
Runtime->>Registry: identify tool "debug" (sequential)
Registry->>Runtime: confirm dispatch
Runtime->>Debug: call execute_debug(input)
alt action = "hypothesize"
Debug->>Debug: read `bug_description`
Debug->>User: return hypothesis message, is_error=false
else action = "instrument"
Debug->>Debug: validate `file` and optional `hypotheses`
alt missing required fields
Debug->>User: return error message, is_error=true
else
Debug->>User: return instrumentation message, is_error=false
end
else action = "analyze"
Debug->>Debug: validate `evidence`
alt evidence missing
Debug->>User: return error message, is_error=true
else
Debug->>User: return analysis message, is_error=false
end
else action = "fix"
Debug->>Debug: read `root_cause` and `file`
Debug->>User: return fix message, is_error=false
else unknown action
Debug->>User: return "Unknown debug action" error, is_error=true
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
/review |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mc/crates/mc-tui/src/commands.rs (1)
383-396:⚠️ Potential issue | 🟡 MinorExpose
debugin the/templatehelp list.
/templatenow supportsdebug(Line 396), but the list shown when no args are provided still omits it (Line 384), so users won’t discover it.💡 Proposed fix
- app.push("Templates: review, refactor, test, explain, document, optimize, security"); + app.push("Templates: review, refactor, test, explain, document, optimize, security, debug");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mc/crates/mc-tui/src/commands.rs` around lines 383 - 396, The templates help list omits the new "debug" template when arg.is_empty() is true; update the string pushed to the UI (the first app.push call that currently lists "Templates: review, refactor, test, explain, document, optimize, security") to include "debug" (e.g., append ", debug" or insert at desired position) so the /template help output exposes the Debug Mode entry; keep the Usage line as-is and ensure the change is made near the arg.is_empty() branch in commands.rs where app.push is called.
🧹 Nitpick comments (2)
mc/crates/mc-core/src/runtime.rs (1)
1704-1719: Validatefixinputs like other debug phases.
fixaccepts emptyroot_causeandfile, which weakens the workflow and can cause extra loops. Consider enforcing non-empty values (similar toinstrumentandanalyze).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mc/crates/mc-core/src/runtime.rs` around lines 1704 - 1719, The "fix" debug branch currently allows empty root_cause and file (variables root_cause and file in the "fix" match arm), so update runtime.rs to validate them the same way as the instrument/analyze phases: extract with input.get(...).and_then(|v| v.as_str()).filter(|s| !s.is_empty()) and if either is missing/empty return or propagate an error (or produce a validation prompt) instead of defaulting to ""; ensure the match arm for "fix" fails fast on missing values and logs/returns a clear validation error so the prompt is only built when both root_cause and file are non-empty.mc/crates/mc-tools/src/spec.rs (1)
391-405: Tightendebugschema with action-specific required fields.Right now only
actionis required, but runtime rejects missingfileforinstrumentand missingevidenceforanalyze. Encoding that in schema (oneOf/if-then) would reduce avoidable tool-call failures.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mc/crates/mc-tools/src/spec.rs` around lines 391 - 405, The debug ToolSpec's input_schema currently only requires "action", causing runtime failures when action-specific fields are missing; update the ToolSpec with an action-specific schema (use JSON Schema oneOf or if/then branches) inside the input_schema for the ToolSpec named "debug" so that: when action == "hypothesize" require "bug_description"; when action == "instrument" require "file" (and optionally "hypotheses"); when action == "analyze" require "evidence"; when action == "fix" require "root_cause" (and "file" if fixes target a file). Modify the input_schema definition in the ToolSpec block to include these conditional/oneOf subschemas so the runtime validates required fields per action.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@mc/crates/mc-core/src/runtime.rs`:
- Around line 1208-1209: The "debug" tool is registered in runtime
(execute_debug) but run_turn currently doesn't classify "debug" as a sequential
tool, so calls go through the parallel path (ToolRegistry::execute) where no
debug handler exists; update the classification in run_turn to treat "debug" as
sequential (or alternatively add a debug branch in ToolRegistry::execute) so
that execute_debug is reached when name == "debug" and Debug Mode no longer
returns NotFound; reference run_turn and execute_debug (or ToolRegistry::execute
if you choose the alternate fix) when making the change.
---
Outside diff comments:
In `@mc/crates/mc-tui/src/commands.rs`:
- Around line 383-396: The templates help list omits the new "debug" template
when arg.is_empty() is true; update the string pushed to the UI (the first
app.push call that currently lists "Templates: review, refactor, test, explain,
document, optimize, security") to include "debug" (e.g., append ", debug" or
insert at desired position) so the /template help output exposes the Debug Mode
entry; keep the Usage line as-is and ensure the change is made near the
arg.is_empty() branch in commands.rs where app.push is called.
---
Nitpick comments:
In `@mc/crates/mc-core/src/runtime.rs`:
- Around line 1704-1719: The "fix" debug branch currently allows empty
root_cause and file (variables root_cause and file in the "fix" match arm), so
update runtime.rs to validate them the same way as the instrument/analyze
phases: extract with input.get(...).and_then(|v| v.as_str()).filter(|s|
!s.is_empty()) and if either is missing/empty return or propagate an error (or
produce a validation prompt) instead of defaulting to ""; ensure the match arm
for "fix" fails fast on missing values and logs/returns a clear validation error
so the prompt is only built when both root_cause and file are non-empty.
In `@mc/crates/mc-tools/src/spec.rs`:
- Around line 391-405: The debug ToolSpec's input_schema currently only requires
"action", causing runtime failures when action-specific fields are missing;
update the ToolSpec with an action-specific schema (use JSON Schema oneOf or
if/then branches) inside the input_schema for the ToolSpec named "debug" so
that: when action == "hypothesize" require "bug_description"; when action ==
"instrument" require "file" (and optionally "hypotheses"); when action ==
"analyze" require "evidence"; when action == "fix" require "root_cause" (and
"file" if fixes target a file). Modify the input_schema definition in the
ToolSpec block to include these conditional/oneOf subschemas so the runtime
validates required fields per action.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 092baf62-5463-4577-80ac-f7077a6341ab
📒 Files selected for processing (4)
mc/crates/mc-core/src/runtime.rsmc/crates/mc-tools/src/registry.rsmc/crates/mc-tools/src/spec.rsmc/crates/mc-tui/src/commands.rs
1. Add 'debug' and 'browser' to sequential tool list (was going through parallel path where no handler exists — critical bug) 2. Add 'debug' to /template help list 3. Validate root_cause and file in debug 'fix' action 192 tests, 0 warnings.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mc/crates/mc-core/src/runtime.rs (1)
1640-1732: Consider moving Debug Mode into its ownmc-coremodule.This handler is already feature-sized, and
runtime.rsis doing a lot of orchestration work already. Extractingexecute_debuginto something likemc-core/src/debug.rswould keep dispatch here thin and make the new workflow easier to evolve and test.Based on learnings: When adding a new core feature: create module in
mc-core/src/{feature}.rs, integrate into ConversationRuntime in runtime.rs, export frommc-core/src/lib.rs, add to config if needed, add slash command in TUI🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mc/crates/mc-core/src/runtime.rs` around lines 1640 - 1732, The execute_debug handler is large and should be extracted into its own module named debug: create a new module debug that exposes a pub fn execute_debug(input: &serde_json::Value) -> (String, bool) (migrating the entire match body), then replace the inline implementation in runtime.rs with a thin dispatch that calls debug::execute_debug; update the crate root to pub mod debug / pub use debug::execute_debug so the function is exported, wire the ConversationRuntime dispatch to call the new function, and update any config/TUI slash-command registration and tests that referenced the old inline handler to point to the new module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@mc/crates/mc-core/src/runtime.rs`:
- Around line 1661-1717: The runtime's execute_debug branches ("instrument",
"analyze", "fix") enforce required fields (file, hypotheses/evidence/root_cause)
but the registered debug ToolSpec still only marks action as required; update
the ToolSpec registration for the "debug" tool in mc/crates/mc-tools/src/spec.rs
(ToolSpec for debug) to reflect per-action required parameters: require "file"
for action="instrument" and action="fix", require "hypotheses" (or mark its
expected type) for "instrument", require "evidence" for action="analyze", and
require "root_cause" for action="fix" so the schema matches execute_debug's
validations and prevents the model from invoking the tool without those fields.
---
Nitpick comments:
In `@mc/crates/mc-core/src/runtime.rs`:
- Around line 1640-1732: The execute_debug handler is large and should be
extracted into its own module named debug: create a new module debug that
exposes a pub fn execute_debug(input: &serde_json::Value) -> (String, bool)
(migrating the entire match body), then replace the inline implementation in
runtime.rs with a thin dispatch that calls debug::execute_debug; update the
crate root to pub mod debug / pub use debug::execute_debug so the function is
exported, wire the ConversationRuntime dispatch to call the new function, and
update any config/TUI slash-command registration and tests that referenced the
old inline handler to point to the new module.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cddb14c3-4e6a-4cdc-ae01-22fbebe50265
📒 Files selected for processing (2)
mc/crates/mc-core/src/runtime.rsmc/crates/mc-tui/src/commands.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- mc/crates/mc-tui/src/commands.rs
1. Extract execute_debug to mc-core/src/debug.rs (was inline in runtime.rs) 2. Add 4 unit tests for debug module 3. Tighten ToolSpec schema with per-action required fields (allOf/if-then) 4. Export debug module from mc-core/src/lib.rs 196 tests (4 new), 0 warnings.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mc/crates/mc-core/src/debug.rs (1)
1-2: Markexecute_debugas#[must_use].This is a public function returning a value, so it should carry the repo-required annotation.
Based on learnings: "Add `#[must_use]` attribute on all public functions returning values"♻️ Proposed fix
/// Structured debug mode — guides agent through hypothesis-driven debugging. +#[must_use] pub fn execute_debug(input: &serde_json::Value) -> (String, bool) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mc/crates/mc-core/src/debug.rs` around lines 1 - 2, The public function execute_debug returns a value but lacks the required must_use annotation; add the #[must_use] attribute directly above the pub fn execute_debug(...) declaration so callers get a compiler warning if the returned (String, bool) tuple is ignored, preserving the function signature and visibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@mc/crates/mc-core/src/debug.rs`:
- Around line 6-9: The code currently sets bug to "unknown bug" when
input.get("bug_description") is missing; instead, make the "bug_description"
required by checking input.get("bug_description").and_then(|v| v.as_str()) and
returning an error (or propagating a failure) if it's None rather than using
unwrap_or; update the branch that sets the variable named bug in
mc/crates/mc-core/src/debug.rs so the "hypothesize" path fails fast when
bug_description is absent and include a clear error message referencing the
missing "bug_description".
---
Nitpick comments:
In `@mc/crates/mc-core/src/debug.rs`:
- Around line 1-2: The public function execute_debug returns a value but lacks
the required must_use annotation; add the #[must_use] attribute directly above
the pub fn execute_debug(...) declaration so callers get a compiler warning if
the returned (String, bool) tuple is ignored, preserving the function signature
and visibility.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cd0310ea-f7b4-464e-8e00-4f59c66f340b
📒 Files selected for processing (4)
mc/crates/mc-core/src/debug.rsmc/crates/mc-core/src/lib.rsmc/crates/mc-core/src/runtime.rsmc/crates/mc-tools/src/spec.rs
✅ Files skipped from review due to trivial changes (2)
- mc/crates/mc-core/src/lib.rs
- mc/crates/mc-tools/src/spec.rs
- Add #[must_use] to execute_debug - Require bug_description for hypothesize (was defaulting to 'unknown bug') - Add test for missing bug_description 197 tests, 0 warnings.
Debug Mode
Structured debugging workflow inspired by Cursor's Debug Mode:
4 phases:
hypothesize— generate 3-5 hypotheses about root causeinstrument— add targeted logging/assertions to verify each hypothesisanalyze— compare evidence against hypotheses, identify root causefix— apply targeted fix, remove instrumentation, add regression testUsage:
/debugin TUI or agent callsdebugtool directlyWhy: Standard agent debugging = guess and fix. Debug Mode = evidence-based, systematic, fewer iterations.
30 tools, 192 tests, 0 warnings.
Summary by CodeRabbit
/template debugcommand to generate step-by-step debug prompts.