Add support for .patch files as a recognized code format - #164
Merged
Conversation
A `.patch` is a build input in its own right -- pnpm `patchedDependencies`, patch-package, a podspec or build script that shells out to `git apply` -- but it had no format: capturing one meant declaring `patch` in `resources` and storing it as an opaque blob. It now classifies as `patch` and rides the text path, so the payload is raw UTF-8, `stasis diff` shows a changed patch as a text diff, and `extract` writes it back byte-for-byte. - `patch` joins KNOWN_FORMATS as its own family: a UTF-8 text build input, no language's source, and not the byte blob `resource` would make it. Recorded wherever the name-based classifier runs -- `stasis add`, an `fs.readFileSync` capture under `--fs`, and the Metro native capture / `bundle --metro` walk. The JS-graph bundler plugins are unchanged: a `.patch` pulled in as a bundler asset is still a `resource`, like a `.sh` or a `.plist`. - A patch whose hunks copy raw bytes out of a non-UTF-8 file can't be the UTF-8 string the format implies -- exactly the hazard `isBinaryPlist` was added for, so generalize it to `isBinaryTextInput` over both extensions. Such a file is NOT code: it falls through to the resource path (base64 when `patch` is allowlisted, refused otherwise) instead of aborting the capture. - `patch` is not a Node loader format, so the loader refuses to execute one, with its own message rather than the tampered-or-newer-stasis fallback. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoTa1QbaGEnmYs79TPuARq
Drop the isBinaryPlist -> isBinaryTextInput generalization: a non-UTF-8 `.patch` now fails closed on the ordinary source UTF-8 check like any other text format, instead of demoting to the resource path. Rare enough (a patch of a non-UTF-8 file) not to earn the machinery, and it keeps the plist special case scoped to the one format that legitimately ships binary. Also fold the standalone doc section into the `formats` bullet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoTa1QbaGEnmYs79TPuARq
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.
Summary
This PR adds support for
.patchfiles (unified diffs) as a first-class code format in stasis, alongside existing formats likexml,shell, etc. Patch files are build inputs used by tools like pnpm'spatchedDependencies,patch-package, and build scripts that apply patches during the build process.Key Changes
patch: AddedpatchtoKNOWN_FORMATSandCODE_EXT_FORMATSmapping.patchextension to thepatchformatisBinaryPlist()→isBinaryTextInput()to handle both binary plists and non-UTF-8 patches, since both are formats that should be stored as UTF-8 text but can legitimately contain binary bytesisBinaryTextInput()function now checks for both.plistand.patchextensions, treating non-UTF-8 content in these formats as resources rather than coderefineNativeCapture(): Modified to use the renamed function and dynamically check the file extension's allowlist statusfile-formats.mdexplaining patch files, their UTF-8 storage, and behavior when containing non-UTF-8 byteshooks.jswhen attempting to execute a patch file via Node loaderadd.test.jsandfs.test.js, covering both UTF-8 and non-UTF-8 patch scenariosImplementation Details
stasis diffshows text diffs andstasis extractwrites them back byte-for-bytepatchin theresourcesallowliststasis add,--fsfilesystem captures, and Metro native walksresourceformat (unchanged behavior)https://claude.ai/code/session_01KoTa1QbaGEnmYs79TPuARq