Skip to content

This tutorial reviews the current working tree without changing it. It uses Plan Mode, where writes and shell commands are denied by policy, and asks the agent for a written report.

Prerequisites ​

  • M31A installed and authenticated (see Quickstart).
  • A Git repository with uncommitted changes. To follow along with no risk, use a scratch clone:
bash
mkdir -p /tmp/m31a-review && cd /tmp/m31a-review
git init
printf 'function add(a, b) { return a - b; }\n' > math.js
git add math.js && git commit -m "initial"
printf 'function add(a, b) { return a - b; }\nfunction divide(a, b) { return a / b; }\n' > math.js

1. Confirm the diff yourself ​

Before involving the agent, see what will be reviewed:

bash
git status --short
git diff --stat
git diff > /tmp/m31a-review.diff
cat /tmp/m31a-review.diff

The example diff should show a new divide function and the unchanged buggy add implementation. Save the diff to a file because the agent will not be able to run Git itself in the next step.

2. Start in Plan Mode ​

bash
m31a --approval-mode plan

Plan Mode is read-only. The default plan.toml policy contains a catch-all deny at priority 40 and explicit read-only allows at 50, so tools such as read_file, glob, and grep_search work while shell tools are denied. A separate command guard is a backstop that rejects mutating shell commands even if another rule ever allows them. Run Git commands yourself and hand the diff to the agent.

You can also press Shift+Tab in the TUI to cycle to plan. Verify the mode in the sidebar or with /policies list.

3. Ask for a structured review ​

Enter a prompt like this in the TUI:

text
Review the diff in /tmp/m31a-review.diff. Use only read-only tools; do not run shell commands.
Steps:
1. Read /tmp/m31a-review.diff with read_file.
2. Read the full files around each changed hunk with read_file, and use glob and grep_search for context.
3. Check correctness, error handling, API compatibility, and tests.
4. Report findings ordered by severity (critical, high, medium, low).
For each finding give file:line, what is wrong, why it matters, and a fix suggestion.
If there are no findings, say so explicitly. Do not modify any files.

The model will call read_file, glob, and grep_search. Each call is checked against the Plan Mode policy before it executes.

TIP

If the agent proposes a patch, ask it to keep the plan in the conversation. Writing plan files is allowed only under the session's .m31a/tmp/.../plans/ directory, and even then through narrow policy exceptions.

4. Verify what happened ​

Check that nothing was modified:

bash
git status --short
git diff --stat

The output should be identical to step 1. If you want an artifact, exit Plan Mode and ask the agent to write a report file with explicit approval:

text
Exit Plan Mode and write the review above to REVIEW.md.

Approve the write_file or apply_patch call when prompted. Do not use this step in a repository you do not trust.

5. Headless variant ​

For a one-shot review that emits JSON:

bash
cat /tmp/m31a-review.diff | m31a --approval-mode plan \
  -p "Review this diff. Report findings as a JSON array with fields file, line, severity, and message." \
  --output-format json > review.json

Then inspect the result:

bash
node -e "const r=require('./review.json'); console.log(r.response); if (r.error) process.exit(1)"

The JSON object contains session_id, response, stats, and optionally error and warnings; see packages/core/src/output/json-formatter.ts. In a non-interactive run, any tool call that would require confirmation is denied instead of prompting, which is exactly why Plan Mode is a good fit.

6. What to do with findings ​

  • For a genuine bug, start a normal session in default or auto_edit mode and ask for a minimal fix with tests.
  • For a risky refactor, use Parallel worktrees so the change does not touch your main checkout.
  • For repeatable reviews, turn the prompt into a custom skill or a headless CI job.

Troubleshooting ​

SymptomCause and fix
git status is deniedShell tools are denied in Plan Mode; run Git yourself and pass the diff.
Tool requires confirmationYou are no longer in Plan Mode; check the sidebar and re-enter it.
Review misses a fileThe change is untracked; mention the path explicitly or stage it first.
Output is truncatedLarge files are distilled; ask the agent to read specific line ranges.

Next steps ​

Built with VitePress. Powered by NVIDIA NIM.