Repository navigation
cli: did-you-mean suggestions in output, and flashtex check --fix [--dry-run] with symlink-safe atomic writes - #362
Conversation
…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
|
daniel-parent: unblocking. #444 answers this PR's design question: the compiler will only emit an applicable suggestion for a unique closest match, so |
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
flashtex check --fix [--dry-run] applies them (#277)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
|
daniel-muse-lead (shepherding, no feature changes): merged main at Was Generated artefacts regenerated via
|
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
= help: did you mean \alpha?with the suggested line and a+gutter.(did you mean \alpha?).--jsonincludessuggestiononly when present; the key is absent otherwise.flashtex check --fix [--dry-run]applies each diagnostic'ssuggestionto its source span...and absolute paths are refused). It never writes through a symlink: every path component is checked withlstat, the leaf included.--dry-runprints a unified diff and creates no files at all.--fixhas no ambiguity policy of its own. Per compiler: only a unique closest match becomes an applicable fix (#277) #444, the compiler emits an applicablesuggestiononly for a unique closest match.Review round
The independent review found writes through a symlinked parent directory: with
link -> src, fixinglink/main.texmodifiedsrc/main.tex. It also found that the safety matrix was untested. Both are fixed, test first:83211e88adds the tests; therea_symlinked_parent_directory_is_refusedFAILED, because it wrote throughlink/, and so did the UTF-8 boundary test.f26143dcfixes both.The matrix now covers:
..and absolute paths;Tests
cargo test --manifest-path crates/flashtex-cli/Cargo.tomlat9d8a3be9, merged with main:test result: ok. 31 passed; 0 failed; 0 ignored(unit, including the safety matrix)test result: ok. 20 passed; 0 failed; 1 ignored(tests/cli.rs)check_fix_skips_an_ambiguous_typo_and_still_fixes_alpah, the compiler: only a unique closest match becomes an applicable fix (#277) #444 end-to-end contract (\iglgets no suggestion and isn't rewritten). The CLI linksvendor/compiler, which predates compiler: only a unique closest match becomes an applicable fix (#277) #444; even vendor: re-pin render-pipeline's compiler mirror to main faa7d484, and catch the pipeline up to it #451'sfaa7d484pin does. Un-ignore it after the next re-pin past compiler: only a unique closest match becomes an applicable fix (#277) #444.Overlap check
tests/cli.rs. This lane's tests are appended at the end, so the conflict, if any, is additive.crates/flashtex-cli.Not done
--fixforhelp.replacementbeyondsuggestion, once v2 structured fields exist.🤖 Generated with Claude Code
https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz