Repository navigation
fix(install): preserve line endings of CLAUDE.md, AGENTS.md and siblings (#4360) - #4372
nothariharan wants to merge 1 commit into
Conversation
…ngs (Graphify-Labs#4360) Graphify-Labs#3741 stopped the always-on and Gemini writers from translating line endings on write (newline=""), but every one of these paths still READ through Path.read_text, which opens in universal-newline mode and folds CRLF to LF before the block is merged. A later write then re-emitted the platform default, so a read-modify-write normalised the WHOLE file: on Windows an LF file gained CRLF on every line, on Linux a CRLF file lost its CR. Install and uninstall now go through one shared read/write pair (_read_keep_newline / _write_keep_newline): the file's own dominant ending is detected on read, the section helpers keep working on bare-LF text, and the ending is restored on write with newline="". A file with no prior convention is written LF, matching the other writers. This covers claude_install, _agents_install, codebuddy_install, gemini_install/_uninstall, vscode_install/_uninstall, _strip_graphify_md_section, _agents_uninstall, codebuddy_uninstall and _remove_claude_skill_registration, plus the two Graphify-Labs#3741 paths so the read side can no longer drift from the write side. Adds a round-trip test per writer: an LF file and a CRLF file in, same endings out, and install-then-uninstall returns the exact original bytes.
|
Thanks for the pull request, @nothariharan. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; no formal proof of the changed code.
Graphify review — findings
Preserves each instruction file's own line endings when graphify installs or uninstalls its section in CLAUDE.md, GEMINI.md, AGENTS.md and copilot-instructions.md, so the rest of the file is never re-encoded. _read_keep_newline reads raw bytes, records whether the file uses CRLF or LF, and hands the section helpers bare-\n text. _write_keep_newline restores that ending with no further translation, so LF files no longer become CRLF on Windows and CRLF files no longer flatten to LF elsewhere; new files are written as plain LF.
Worth a look
- _read_keep_newline treats any CRLF as the file convention instead of the dominant ending —
graphify/install.py:801· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 594 functions depend on the 182 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
codebuddy_install()— 22 callers, 7 callees - worse:
claude_install()— 20 callers, 6 callees - worse:
gemini_install()— 12 callers, 9 callees - worse:
codebuddy_uninstall()— 15 callers, 6 callees - worse:
claude_uninstall()— 18 callers, 4 callees - worse:
_agents_install()— 7 callers, 8 callees - worse:
gemini_uninstall()— 9 callers, 6 callees - worse:
vscode_install()— 5 callers, 10 callees - …and 4 more — each is listed as a finding
Verification — 594 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 405 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
40 of 391 test file(s) selected (10%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_agents_platform.py— impacttests/test_atomic_version_stamp.py— impacttests/test_claude_md.py— impacttests/test_codebuddy.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_detect.py— impacttests/test_devin.py— impacttests/test_explain_cli.py— impacttests/test_explain_same_file_tie.py— impacttests/test_extract_cli.py— impacttests/test_gemini_hook.py— impacttests/test_global_add_tag_inference.py— impacttests/test_god_nodes_cli.py— impacttests/test_hollow_chunks_arm_shrink_guard.py— impacttests/test_home_sandbox.py— impacttests/test_hook_strict.py— impacttests/test_incomplete_build_guard.py— impacttests/test_install.py— impacttests/test_install_line_endings.py— impact, changed-testtests/test_install_references.py— impacttests/test_install_strings.py— impacttests/test_install_version_warning.py— impacttests/test_lookup_exit_codes.py— impacttests/test_merge_chunks_validation.py— impacttests/test_multigraph_diagnostics.py— impacttests/test_no_dedup_flag.py— impacttests/test_opencode_plugin_refresh.py— impacttests/test_path_cli.py— impacttests/test_query_cli.py— impacttests/test_query_induced_edges.py— impacttests/test_read_hook.py— impacttests/test_replace_or_append_section.py— impacttests/test_search_hook.py— impacttests/test_skill_auto_refresh.py— impacttests/test_skill_version_warning.py— impacttests/test_truncation_full_answer.py— impacttests/test_uninstall_purge_safety.py— impacttests/test_uninstall_scope.py— impacttests/test_unverified_semantic_shrink.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
· 12 more finding(s) on lines outside this diff (see the check run).
|
Shipped in v0.9.88, just released to PyPI as |
What this fixes
Closes #4360.
#3741stopped two writers from translating line endings on write (newline=""), but every install/uninstall path in the issue still reads throughPath.read_text, which opens in universal-newline mode and folds\r\nto\nbefore graphify's block is merged. The later write then re-emitted the platform default, so a read-modify-write normalised the whole file:\r.For
CLAUDE.md/AGENTS.md, which are shared and reviewed, that buries the real one-block change in an every-line diff and can trip line-ending checks.Confirmed real on
v8(0.9.87)The issue's minimal repro, run end-to-end through the real CLI:
Function-level check on Windows showed
CLAUDE.md,AGENTS.md,GEMINI.md,CODEBUDDY.mdand.github/copilot-instructions.mdall flipping LF → CRLF after install, and staying CRLF after uninstall.The fix
One shared read/write pair, used by every listed writer so the read and write sides can no longer drift apart:
_read_keep_newline(path) -> (text, newline)— reads bytes (bypassing universal-newline translation), detects the file's dominant ending (\r\nor\n), and returns bare-\ntext so the existing_replace_or_append_section/_remove_marker_sectionhelpers keep working unchanged._write_keep_newline(path, text, newline)— converts bare\nto the detected ending and writes withnewline="", so nothing is translated on the way out. A fresh file (no prior convention) is written LF, matching what the other writers already emit.Writers updated
CLAUDE.mdclaude_install_strip_graphify_md_sectionAGENTS.md_agents_install_agents_uninstallGEMINI.mdgemini_install*gemini_uninstallCODEBUDDY.mdcodebuddy_installcodebuddy_uninstall.github/copilot-instructions.mdvscode_install(new-file branch too)vscode_uninstall# graphifyH1 registration_register_always_on_block*_remove_claude_skill_registration* the two
#3741paths are included: they had the write side fixed but still read throughread_text, so a CRLF file was still normalised to LF on any host. Fixing the read side closes that gap.As a small simplification, the installers now reuse the already-read
contentfor the "already configured (no change)" comparison instead of re-reading the file.Tests
New
tests/test_install_line_endings.py:_strip_graphify_md_section): the file is seeded with an LF body and again with a CRLF body; after install only the graphify block changed and every line keeps the original ending; after uninstall the bytes equal the original exactly._read_keep_newline/_write_keep_newline.The bug is observable in the file bytes on any host OS (LF input fails on Windows, CRLF input fails on Linux), so the tests are not platform-gated.
Verification:
17 passed.11cases — confirming the tests pin the bug.253 passed, 3 skipped; the wider 5-file run has byte-identical pass/fail sets before and after the change.ruff checkclean.Scope
Only the read-modify-write writers listed in the issue (plus the
#3741read side). Graphify-owned rule files that aren't shared/reviewed (kiro,antigravity,cursor,devin) and the JSON settings writers are unchanged.