effect(patch,tool): migrate patch/index and tool/read to AppFileSystem#27155
Merged
Conversation
The patch apply path now returns Effect<...> values backed by AppFileSystem.Service. The parser, chunk replacer, and shell-argv parser remain pure helpers. deriveNewContentsFromChunks now takes the original text instead of doing its own readFileSync so callers (apply_patch tool, applyHunksToFiles) can supply the content they already have. tool/read.ts swaps its fs.createReadStream + readline helper for a Stream pipeline over AppFileSystem.Service.stream — TextDecoder + map keeps the trailing unterminated line that Stream.decodeText and Stream.runForEachWhile both drop today. Limit / offset / byte-cap behaviour is preserved.
3690488 to
ba8fba5
Compare
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
src/patch/index.ts: the apply path now returnsEffect<...>values backed byAppFileSystem.Service. The pure parser, chunk replacer, and shell-argv parser stay sync.deriveNewContentsFromChunksis now a pure function that takes the original file text as an argument — callers (apply_patchtool andapplyHunksToFiles) supply the content they already have, removing the embeddedreadFileSync.src/tool/apply_patch.ts: passes the already-read source text toderiveNewContentsFromChunksinstead of letting the parser do its own filesystem read.src/tool/read.ts: dropsfs.createReadStream+readlinein favor of aStreampipeline overAppFileSystem.Service.stream. Offset / limit / byte-cap behavior is preserved.Shape change in
patch/index.tsapplyHunksToFiles,applyPatch, andmaybeParseApplyPatchVerifiedare nowEffect.fn(...)values returningEffect<...>; they requireAppFileSystem.Service.deriveNewContentsFromChunks(filePath, chunks, originalText)now accepts the original text and is fully pure (no fs I/O).parsePatch,maybeParseApplyPatch) is unchanged.Line-streaming behavior in
tool/read.tsAppFileSystem.Service.stream+ a manualTextDecoder({ stream: true }) +Stream.splitLines+Stream.runForEach.Stream.decodeTextdrops the final unterminated line when the source ends without a flush, andStream.runForEachWhiledrops the lastsplitLineschunk. Thedoneflag in the callback replaces the originalbreakfor the byte-cap path so line counting matches the previous semantics.more/cutflags all match the previous helper.Refs
packages/opencode/specs/effect/tools.md—read.tsandpatch/index.tscleanups marked done.Test plan
bun run typecheckbun run test test/patch/patch.test.ts(20 pass)bun run test test/tool/apply_patch.test.ts(27 pass)bun run test test/tool/read.test.ts(39 pass)bun run test— 2574 pass, 0 fail