Repository navigation
fix: keep a file's mode, final newline and encoding through repo writes - #89
Merged
Merged
Conversation
Five defects in the MCP repo write tools, found 2026-11-09 by driving the tool handlers against throwaway repos: - apply reset the file mode. The replacement is a temp file renamed into place and was created with the default mode, so an edited build.sh went from 755 to 644 and repo_stage_reviewed_paths staged the mode change; a 600 file became 644. The replacement now takes the replaced file's mode. - repo_stage_reviewed_paths passed reviewed paths to git as pathspecs. A reviewed pages/[id].tsx also staged an unreviewed pages/i.tsx; a reviewed x[0-9].txt next to a modified x1.txt failed, and the index restore wrote x1.txt's blob under x[0-9].txt; ":!draft.md" left every other change staged. git add, ls-files and rm --cached now run with --literal-pathspecs. - Writing back what repo_read_file returned dropped the final newline, since the read joins lines without one after the last. A file that ends with a newline keeps it (CRLF for a CRLF file) unless the new content is empty. - A file that is not UTF-8 was read lossily and written back with its bytes replaced (an EUC-KR line destroyed while the diff showed it unchanged); UTF-16 was re-encoded as UTF-8 without its BOM. The write path now reads strictly and the dry run refuses such a file. - The dry run checked the size limit before restoring CRLF and a BOM, so apply refused content the dry run had accepted. The limit is now also checked on the content that will be written. Verified: tests/repo-write-keep.test.ts fails 6 of 7 against main and passes here; the subagent's repro scripts no longer reproduce any of the five; npx tsc --noEmit; full suite 1870 passed, 3 skipped after npm run build (the first run failed only package-bin tests, from a worktree with no dist yet). Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
What this touches
6 file(s), 189 line(s) changed. Tests changed. Worth a look
This is an automated first pass, not a review. CI is the gate; a person decides. |
# Conflicts: # CHANGELOG.md
youdie006
added a commit
that referenced
this pull request
Nov 10, 2026
… through repo writes) to the container image Same change as main PR #89 (merge 8d4290c), released in 0.40.51, applied to src, tests and docs without changes. The CHANGELOG lines are main's with the PR noted. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problems
Found 2026-11-09 by calling the MCP repo tool handlers (
createMcpToolHandlers) against throwaway git repos:replaceVerifiedUtf8Filewrites a temp file and renames it into place. Repo writes passed no mode, so the temp file got the default (0666 & ~umask). An editedbuild.shwent 755 -> 644, andrepo_stage_reviewed_pathsstagedmode change 100755 => 100644. A 600 file became 644.pages/[id].tsxalso staged an unreviewed local edit ofpages/i.tsx, while the receipt listed one path.x[0-9].txtnext to a modifiedx1.txtfailed as "Staged content changed". The index restore then wrotex1.txt's blob underx[0-9].txt:ls-filesmatched the pattern, andupdate-index --cacheinfois literal.:!draft.mdleft every other modified and untracked file staged.repo_read_filejoins the lines it returns with no newline after the last one, so writing back what was read removed the file's final newline.Changes
src/safe-file.ts:replaceVerifiedUtf8Fileuses the replaced file's mode (& 0o777) unless a mode is given. Every other caller that writes secrets already passes a mode. NewrequireUtf8read option (isUtf8) throwsNotUtf8Error.src/repo-write.ts:git add,ls-files --stageandrm --cachedrun with--literal-pathspecs.keepFileConventionskeeps a final newline (CRLF for a CRLF file) unless the new content is empty.NotUtf8Errorto a message saying why.src/mcp.ts: therepo_write_file_dry_runtool description anddocs/http-mcp.mddescribe the kept conventions and the refusal.CHANGELOG.md: one entry per defect.Verification
tests/repo-write-keep.test.ts: 7 cases, 6 fail against main. The seventh, emptying a file, is a guard for the newline rule. All 7 pass here.tests/repo-write-line-endings.test.tsandtests/repo-utf16.test.tsstill pass.npx tsc --noEmitpasses. Full suite: 1870 passed, 3 skipped. The first run failed only the twopackage-bintests, because the fresh worktree had nodist/yet; they pass afternpm run build.:!file-name test are skipped there, and CI runs the rest.