Skip to content

cli: did-you-mean suggestions in output, and flashtex check --fix [--dry-run] with symlink-safe atomic writes - #362

Merged
GoKubar merged 15 commits into
mainfrom
agent/daniel-parent/cli-fix
Sep 15, 2026
Merged

GoKubar merged 15 commits into
mainfrom
agent/daniel-parent/cli-fix

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

daniel-parent (claim GH-277-cli-fix, Cursor Grok lane, reviewed by daniel-parent plus an independent read-only Codex review). This was a draft stacked on #303 and #354. Both merged, and #444 answered its design question, so it's now CLI-only and ready.

What changes

  • Suggestions in CLI output:
    • Full style prints a rustc-style = help: did you mean \alpha? with the suggested line and a + gutter.
    • Short style appends (did you mean \alpha?).
    • --json includes suggestion only when present; the key is absent otherwise.
    • Main's existing report output (carets, excerpts, cli: a missing \input is reported once, not twice #313 dedup, per-font folding) is unchanged.
  • flashtex check --fix [--dry-run] applies each diagnostic's suggestion to its source span.
    • Edits apply back to front, and overlapping edits are skipped and reported.
    • A file whose bytes changed since compile is refused. The SHA-256 is taken over the same bytes the compiler read.
    • It never writes outside the project root (.. and absolute paths are refused). It never writes through a symlink: every path component is checked with lstat, the leaf included.
    • An edit whose span isn't on a UTF-8 character boundary is refused.
    • Writes are atomic (temp file plus rename) and keep the file mode. CRLF bytes outside the span are preserved.
    • --dry-run prints a unified diff and creates no files at all.
    • After applying, it re-checks and prints what remains.
  • Ambiguity: --fix has no ambiguity policy of its own. Per compiler: only a unique closest match becomes an applicable fix (#277) #444, the compiler emits an applicable suggestion only for a unique closest match.

Review round

The independent review found writes through a symlinked parent directory: with link -> src, fixing link/main.tex modified src/main.tex. It also found that the safety matrix was untested. Both are fixed, test first:

  • 83211e88 adds the tests; there a_symlinked_parent_directory_is_refused FAILED, because it wrote through link/, and so did the UTF-8 boundary test.
  • f26143dc fixes both.

The matrix now covers:

  • symlinked parent and leaf;
  • .. and absolute paths;
  • CRLF;
  • UTF-8 boundary;
  • multiple back-to-front edits;
  • overlaps;
  • a dry-run directory listing unchanged;
  • JSON without a suggestion.

Tests

cargo test --manifest-path crates/flashtex-cli/Cargo.toml at 9d8a3be9, merged with main:

Overlap check

Not done

  • --fix for help.replacement beyond suggestion, once v2 structured fields exist.
  • An interactive per-fix confirmation.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 and others added 7 commits September 13, 2026 21:26
…art 2)

`flashtex check`/`build`/`watch` print each diagnostic as a header, a
`--> file:line:col` pointer, the source line(s) under a line-number
gutter, carets under the byte span and a wrapped `= recovery:` line.

- `--diagnostics=full|short|json`: full is the new form; short is the
  unchanged one-line `line_text`; json is `--json`. The default is full
  when stderr is a terminal and short otherwise, so piped output and
  scripts see exactly what they did before.
- `--color=auto|always|never`; auto is on for a terminal unless NO_COLOR.
- Uses only the fields a diagnostic already has (code, message, span,
  recovery). Structured labels/help from #277 part (1) can be added to
  the renderer without changing this path.
- Spans: tabs expanded so carets line up, multi-byte text, empty spans
  and spans past the end of the text get one caret, spans longer than
  four lines show the first two and the last.

Tests: 7 renderer unit tests, one end-to-end test for the flags. The
pre-existing multi_file_project_resolves_inputs_from_the_project_root
failure reproduces on unmodified main 9bd4b02 and is not touched here.

Implementation-Agent: daniel-parent (mac-m5pro-dq222)
Commit-Executor: git, direct
Co-authored-by: d-q222 <[email protected]>
Add display::Diagnostic.suggestion (None at every constructor) and tests
that expect unknown_command/\alpha and unsupported_feature. from_compiler
still hardcodes code "compiler" and does not copy suggestion.

Ran: CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-diagfwd cargo test --manifest-path crates/render-pipeline/Cargo.toml --lib from_compiler_forwards
Result: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 89 filtered out
  display::tests::from_compiler_forwards_code_and_suggestion: left "compiler" right "unknown_command"

Next: forward compiler code (explicit, else default_code, else "compiler")
and suggestion; emit suggestion only in runtime-v1 JSON; extend corpus
owner_for; keep v2 diagnostics without a suggestion key.

Open questions: none in-scope. vendor/, apps, protocol schema untouched.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
from_compiler copies the compiler's code (explicit, else default_code(message),
else "compiler") and suggestion. runtime-v1 JSON emits suggestion only when
set; display-list-v2 diagnostics are unchanged except the code value.
owner_for accepts the compiler code set; tikz_pipeline rejects those codes
too so a forwarded unknown_command cannot slip through as "not compiler".

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-diagfwd):
- --lib from_compiler_forwards -- writer_matches_value_tree: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 88 filtered out
- --lib write_json_matches_the_value_tree: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out
- --test compiler_diagnostic_forward: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test tikz_pipeline: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- python3 -m unittest tools.real-world-corpus.test_run: Ran 6 tests in 0.008s OK

Next: full cargo test --manifest-path crates/render-pipeline/Cargo.toml control-vs-after.

Open questions: no in-scope golden embeds "code":"compiler" for a compiler
diagnostic (vendor/pdf fixture and apps/mac display-list fixture are out of
lane). docs/user/compiler.md still shows the old example.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
…g-forward' into agent/daniel-parent/cli-fix

Stacking base for an overnight daniel-parent lane (#277); announced on #2.

Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
Add six cli.rs tests that pin GH-277 acceptance: rustc-style help for
\alpah, JSON suggestion, check --fix rewrite, --dry-run diff, suggestion
in an \input file, and --help mentioning --fix/--dry-run. Overlap and
hash-changed refusal will land with the apply module (need synthetic
edits; the compiler does not emit overlapping spans for \alpah).

Control (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix, base 5b7a88b):
- unittests: test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test cli: test result: FAILED. 12 passed; 1 failed (multi_file_project_resolves_inputs_from_the_project_root, fixture-dependent / PR #308)

New tests (same target dir):
- typo_alpah_full_output_has_a_help_block: FAILED (no "= help: did you mean `\alpha`?")
- typo_alpah_json_includes_suggestion: FAILED (suggestion key absent, left None)
- check_fix_rewrites_alpah_to_alpha / dry_run / input file: FAILED (exit 2, unknown option "--fix")
- check_help_mentions_fix_and_dry_run: FAILED (--help has no --fix)

Next: copy suggestion onto the CLI Diagnostic next to code.clone(), then
render the help block / short parenthetical / JSON key, then check --fix.

Open questions: none in-scope. Overlap/hash/symlink tests belong in the
apply module; they cannot be driven from the compiler's \alpah diagnostic.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
CLI Diagnostic copies pipeline suggestion next to code.clone(). Full
renderer prints `= help: did you mean \`\\alpha\`?` plus a `+` gutter over
the replaced line; short appends `(did you mean \alpha?)`; JSON emits
`suggestion` only when set. `check --fix [--dry-run]` applies non-
overlapping back-to-front byte edits, refuses changed files (SHA-256),
symlinks and paths outside the project root, writes atomically with mode
preserved, then re-checks. Overlap/hash/symlink/mode covered by fix.rs
unit tests (the compiler does not emit overlapping \alpah spans).

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix):
- --bin flashtex: test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- full cargo test --manifest-path crates/flashtex-cli/Cargo.toml:
  unittests ok. 21 passed; --test cli FAILED. 18 passed; 1 failed
  (multi_file_project_resolves_inputs_from_the_project_root — same
  pre-existing control failure; all six new GH-277 tests passed)

Next: no in-scope follow-up; lane is ready for daniel-parent review (no PR).

Open questions: none. Known #308 fixture failure left untouched.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
…g it

Review fix on the GH-277-cli-fix lane: collect_edits used
`end_byte.unwrap_or(start)`, so a diagnostic with a start but no end (or an
empty span) became an insertion at `start`. A compiler suggestion replaces
its span, so both ends are now required and the span must be non-empty.

cargo test -p flashtex-cli: bin 22/0 (+1: a_suggestion_without_a_full_span_is_not_turned_into_an_insertion);
tests/cli 18 passed, 1 failed: multi_file_project_resolves_inputs_from_the_project_root,
the same fixture-dependent failure as on the base 5b7a88b (replaced by #308).

Implementation-Agent: Claude Code (daniel-parent, mac-m5pro-dq222)
Commit-Executor: Claude Code (daniel-parent)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent: unblocking. #444 answers this PR's design question: the compiler will only emit an applicable suggestion for a unique closest match, so --fix needs no ambiguity handling of its own. Both stacked bases (#303, #354) are merged. A merge with main is in progress for the main.rs, report.rs and display.rs conflicts; I'll mark this ready after it's re-tested.

d-q222 and others added 6 commits September 14, 2026 12:09
Merged origin/main (2cf635b). #303 and #354 are on main; this lane no
longer needs its stacked pipeline-diag-forward display.rs code.

Conflict resolution:
- crates/flashtex-cli/src/main.rs: kept --fix/--dry-run and main's
  version_string (#420), collapse_repeats, and watch screen-clear. The
  post-fix re-check also uses collapse_repeats.
- crates/flashtex-cli/src/report.rs (add/add): kept main's structure
  (collapse_repeats) and ported this lane's `= help:` / `+` gutter
  suggestion rendering. Fold equality also compares suggestion.
- crates/render-pipeline/src/display.rs: took main's file. #354 already
  forwards compiler `code` exactly and runtime-v1 `suggestion`. This
  lane's default_code re-derivation was dropped (CLI reads suggestion
  from the pipeline Diagnostic; it does not need that re-derivation).

--fix still has no ambiguity policy. None existed; PR #444 is the
unique-closest-match rule, so the CLI applies whatever suggestion the
compiler emitted.

compile.rs auto-merged: suggestion copy plus main's missing-include
dedup. Tests in tests/cli.rs stayed at the end of the file.

Ran:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix cargo test --manifest-path crates/flashtex-cli/Cargo.toml
  unittests: test result: ok. 24 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  tests/cli.rs: test result: ok. 20 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  (multi_file_project_resolves_inputs_from_the_project_root now passes; #308 landed on main)
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --lib
  test result: ok. 110 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: push this merge to origin/agent/daniel-parent/cli-fix.

Open questions: none in-scope. Ambiguous suggestions are compiler-side (#444, still open).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Adds the --fix safety matrix. Two tests fail on 6abfbec, as intended:

- a_symlinked_parent_directory_is_refused: with root/link -> root/src
  and diagnostic path link/main.tex, apply reports issues=1, skipped=[],
  and rewrites src/main.tex. resolve_writable only lstats the leaf and
  canonicalises the parent, so the temp+rename follows the directory
  symlink.
- a_span_on_a_utf8_multibyte_boundary_is_refused: start=1,end=3 on
  éé (c3 a9 c3 a9) with an empty replacement leaves a valid é;
  from_utf8 accepts it and the file is written.

The rest of the matrix already passes: leaf symlink, ../ and absolute
paths, CRLF preservation, back-to-front non-overlapping edits,
overlapping skips, dry-run directory listing, JSON omitting the
suggestion key (extracted diagnostic_json so the assertion is
unconditional).

Ran:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix cargo test --manifest-path crates/flashtex-cli/Cargo.toml --bin flashtex -- a_symlinked_parent_directory_is_refused a_span_on_a_utf8_multibyte_boundary_is_refused
  test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 29 filtered out
- same binary filter for the other new tests
  test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 24 filtered out

Next: walk every path component with symlink_metadata and refuse
non-char-boundary spans before splicing.

Open questions: none.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
resolve_writable walked only the leaf and canonicalised the parent, so a
directory symlink (root/link -> root/src, diagnostic link/main.tex) still
took the temp+rename to src/main.tex. It now lstats every component from
the project root to the file and returns Skip::Symlink if any is a
symlink. `..` and absolute paths are still rejected before the walk.
The atomic temp+rename stays in that verified real directory.

apply_edits_back_to_front also refuses a span whose start or end is not
a UTF-8 char boundary, even when the spliced bytes happen to be valid
UTF-8.

Ran:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix cargo test --manifest-path crates/flashtex-cli/Cargo.toml --bin flashtex -- a_symlinked_parent_directory_is_refused a_span_on_a_utf8_multibyte_boundary_is_refused a_symlink_target a_parent_escape crlf_bytes non_overlapping overlapping dry_run_creates json_omits a_file_changed
  test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 21 filtered out

The two tests that failed on 83211e8 now pass.

Next: git fetch origin && git merge origin/main, then an end-to-end
test that an ambiguous typo (#444: igl/lph/igm) gets no suggestion and
--fix writes nothing, while \\alpah is still fixed.

Open questions: CLI links render-pipeline/vendor/compiler, not
crates/compiler. If origin/main's #444 did not re-pin the vendor, the
e2e test is a vendor-re-pin (out of scope) and will be reported.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Adds check_fix_skips_an_ambiguous_typo_and_still_fixes_alpah using #444's
inputs: `\igl` (tie between `\Bigl` and `\bigl`) must have no suggestion
key and `--fix` must leave the file bytes unchanged; `\alpah` still
rewrites to `\alpha`.

This test FAILS on the current CLI: flashtex-cli links
render-pipeline/vendor/compiler (PIN e44d591), which still uses
list-order suggest_command. Observed JSON for `\igl`:
"suggestion":"\\Bigl". crates/compiler on origin/main has #444
(closest_commands / unique match only), but a vendor re-pin is out of
this lane's scope. Not done.

Ran:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix cargo test --manifest-path crates/flashtex-cli/Cargo.toml
  unittests: test result: ok. 31 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  tests/cli.rs: test result: FAILED. 20 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
  (the one failure is check_fix_skips_an_ambiguous_typo_and_still_fixes_alpah)

Next: stop. A vendor re-pin of compiler onto #444 is required before
this e2e can pass; this lane must not do that re-pin.

Open questions: who owns the vendor/compiler re-pin so `--fix` sees
#444's unique-closest-match rule?

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
…#444

The CLI links vendor/compiler, which still picks list-order suggestions, so
\\igl keeps a suggestion. The test is the contract for after the re-pin
(#451 pins faa7d48, which predates #444).

What was run: cargo test --manifest-path crates/flashtex-cli/Cargo.toml
test result: ok. 31 passed; 0 failed; 0 ignored
test result: ok. 20 passed; 0 failed; 1 ignored

Implementation-Agent: daniel-parent (Claude Code, mac-m5pro-dq222)
Commit-Executor: daniel-parent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222 d-q222 changed the title cli: show did-you-mean suggestions as help, and flashtex check --fix [--dry-run] applies them (#277) cli: did-you-mean suggestions in output, and flashtex check --fix [--dry-run] with symlink-safe atomic writes Sep 14, 2026
@d-q222
d-q222 marked this pull request as ready for review September 14, 2026 19:31
Conflict in crates/flashtex-cli/tests/cli.rs was additive on both sides
(the --fix test helpers/tests from this branch vs. the restored
diagnostics_short_is_one_line_per_diagnostic and color precedence tests
from #431/#459 on main); resolved by keeping both blocks intact. Generated
artefacts (supported-latex.json, coverage.md, docs/user/compiler.md, the
Mac bundled copy) regenerated via the project scripts, not hand-merged --
confirmed byte-identical to git's own auto-merge, so no drift.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Lane-Owner: daniel-parent
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead (shepherding, no feature changes): merged main at ce807082.

Was CONFLICTING; the only real conflict was in crates/flashtex-cli/tests/cli.rs, additive on both sides (this branch's --fix/did-you-mean tests vs. #431/#459's restored diagnostics_short_is_one_line_per_diagnostic/color-precedence tests on main) — resolved by keeping both blocks intact.

Generated artefacts regenerated via crates/compiler/scripts/render_supported_latex.sh (not hand-merged) — confirmed byte-identical to git's own auto-merge, so no drift.

cargo test --manifest-path crates/flashtex-cli/Cargo.toml
test result: ok. 31 passed; 0 failed; 0 ignored   (unit)
test result: ok. 26 passed; 0 failed; 1 ignored   (tests/cli.rs, same 1 ignored as before — #444 re-pin dependency, unaffected by this merge)
cargo test --test supported_latex (crates/compiler)
test result: ok. 8 passed; 0 failed   (generated_artifacts_are_current passes)

muse-precheck.sh 362: no hard-rule violations, mergeable=MERGEABLE, no forbidden-path touches. Two informational notes, not fixed since they're outside shepherding scope: no active coord.py claim names this branch (your claim, not mine to re-register), and docs/user/compiler.md shows as touched by many other open PRs — expected for this shared generated file, not a real overlap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants