Skip to content

fix_plan: structured edit previews on diagnostics (Zero-style, ILO-48 MVP)#621

Merged
danieljohnmorris merged 10 commits into
mainfrom
feature/fix-plans-mvp
May 22, 2026
Merged

fix_plan: structured edit previews on diagnostics (Zero-style, ILO-48 MVP)#621
danieljohnmorris merged 10 commits into
mainfrom
feature/fix-plans-mvp

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Adds FixPlan { path, edits: Vec<FixEdit { line_start, line_end, before, after } } to the Diagnostic struct, matching the Zero PR build: collapse internal whitespace in compact spec #137 schema
  • fix_plan is serialized as an optional field in --json NDJSON output (absent when no mechanical fix is known)
  • Diagnostic::derive_fix_plan() computes the plan from code + span + source — called in check_cmd via an enrich() closure
  • Four diagnostic codes wired (MVP scope):
    • ILO-T004 — undefined variable with "did you mean 'X'?" hint → rename span to X
    • ILO-T003 — undefined type, same hint pattern
    • ILO-T032 — bare fmt/fmt2 result discarded → prepend prnt before the call
    • ILO-L002 — underscore identifier → hyphenated form (extracted from suggestion backtick)
  • path is populated from the file path when checking a file; absent for inline code
  • JSON_OUTPUT.md updated with full diagnostic shape and fix_plan table
  • ai.txt ERROR DIAGNOSTICS section updated with [fix_plan] note

Test plan

  • cargo test --lib diagnostic::tests::derive_fix_plan — 7 unit tests covering all four derivation paths, guard cases, JSON shape, path field
  • cargo test --test json_output_contracts check_json — 4 integration tests running the full ilo check --json pipeline
  • cargo test --lib — 3338 lib tests, 0 failures
  • cargo test --test json_output_contracts — 15 tests, 0 failures

Deferred follow-ups (not in this PR)

  • AOT / serv integration (fix_plans in non-check pipelines)
  • Multi-file edits
  • More diagnostic codes (T008 return-type mismatch, T013 builtin-type mismatch, P011 reserved keyword, T041 nil-coalesce on Result)
  • ilo apply subcommand to consume a fix_plan JSON and rewrite the file
  • IDE protocol bridge

🤖 Generated with Claude Code

Daniel Morris and others added 4 commits May 22, 2026 00:38
Add FixPlan { path, edits: Vec<FixEdit> } and FixEdit { line_start,
line_end, before, after } matching the Zero PR #137 schema. Wire
fix_plan serialization into --json output. No diagnostics emit plans yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add Diagnostic::derive_fix_plan() which pattern-matches on code and
builds a structured FixPlan from the primary span + source text:

- ILO-T004 / ILO-T003: parse "did you mean 'X'?" from hint, replace span
- ILO-T032: bare fmt/fmt2 → prepend "prnt " before the call
- ILO-L002: underscore ident → hyphenated form from suggestion backticks

Wire enrich() closure in check_cmd to call derive_fix_plan() after
attaching source and diag_path (file-only; absent for inline code).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Unit tests in diagnostic::tests::derive_fix_plan_* cover:
- T004 typo rename, T003 type rename, T032 fmt prefix, L002 hyphen
- absent-without-hint and absent-without-source guard cases
- JSON shape (line_range array, before/after keys, path field)

Integration tests in json_output_contracts exercise the full
check --json → NDJSON stderr pipeline for each wired diagnostic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JSON_OUTPUT.md: expand ilo check section with diagnostic NDJSON shape,
optional fix_plan schema (Zero PR#137 style), and table of codes that
emit structured edits.

ai.txt: add [fix_plan] note in ERROR DIAGNOSTICS section describing the
field and which codes populate it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 95.18072% with 20 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/diagnostic/mod.rs 94.75% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

Extends derive_fix_plan() with three new code handlers:

- ILO-T008 (return type mismatch): wraps the offending return expression
  with `str`/`num` when the hint identifies a cast; no-ops for non-cast types
- ILO-P011 (reserved keyword as identifier): renames the span token to
  `<name>2` (safe mechanical rename with no semantic ambiguity)
- ILO-T041 (nil-coalesce on Result): rewrites `expr ?? default` to
  `?expr{~v:v;^_:default}` by splitting on the ` ?? ` operator

Adds 5 unit tests in src/diagnostic/mod.rs and 4 integration tests in
tests/json_output_contracts.rs exercising the live binary via ilo check --json.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danieljohnmorris danieljohnmorris merged commit 4266a80 into main May 22, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/fix-plans-mvp branch May 22, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant