@smthrs/std 0.0.0-stage → 1.0.0-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +148 -0
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/dist/cjs/ApplyPatch.d.ts +174 -0
- package/dist/cjs/ApplyPatch.d.ts.map +1 -0
- package/dist/cjs/ApplyPatch.js +309 -0
- package/dist/cjs/ApplyPatch.js.map +7 -0
- package/dist/cjs/Bash.d.ts +390 -0
- package/dist/cjs/Bash.d.ts.map +1 -0
- package/dist/cjs/Bash.js +333 -0
- package/dist/cjs/Bash.js.map +7 -0
- package/dist/cjs/Checkpoints.d.ts +322 -0
- package/dist/cjs/Checkpoints.d.ts.map +1 -0
- package/dist/cjs/Checkpoints.js +233 -0
- package/dist/cjs/Checkpoints.js.map +7 -0
- package/dist/cjs/Container.d.ts +132 -0
- package/dist/cjs/Container.d.ts.map +1 -0
- package/dist/cjs/Container.js +113 -0
- package/dist/cjs/Container.js.map +7 -0
- package/dist/cjs/Edit.d.ts +203 -0
- package/dist/cjs/Edit.d.ts.map +1 -0
- package/dist/cjs/Edit.js +258 -0
- package/dist/cjs/Edit.js.map +7 -0
- package/dist/cjs/ExaWebSearch.d.ts +22 -0
- package/dist/cjs/ExaWebSearch.d.ts.map +1 -0
- package/dist/cjs/ExaWebSearch.js +138 -0
- package/dist/cjs/ExaWebSearch.js.map +7 -0
- package/dist/cjs/Explore.d.ts +328 -0
- package/dist/cjs/Explore.d.ts.map +1 -0
- package/dist/cjs/Explore.js +90 -0
- package/dist/cjs/Explore.js.map +7 -0
- package/dist/cjs/Fetch.d.ts +130 -0
- package/dist/cjs/Fetch.d.ts.map +1 -0
- package/dist/cjs/Fetch.js +64 -0
- package/dist/cjs/Fetch.js.map +7 -0
- package/dist/cjs/Glob.d.ts +204 -0
- package/dist/cjs/Glob.d.ts.map +1 -0
- package/dist/cjs/Glob.js +94 -0
- package/dist/cjs/Glob.js.map +7 -0
- package/dist/cjs/Grep.d.ts +347 -0
- package/dist/cjs/Grep.d.ts.map +1 -0
- package/dist/cjs/Grep.js +181 -0
- package/dist/cjs/Grep.js.map +7 -0
- package/dist/cjs/HttpPost.d.ts +130 -0
- package/dist/cjs/HttpPost.d.ts.map +1 -0
- package/dist/cjs/HttpPost.js +72 -0
- package/dist/cjs/HttpPost.js.map +7 -0
- package/dist/cjs/LanguageServer.d.ts +90 -0
- package/dist/cjs/LanguageServer.d.ts.map +1 -0
- package/dist/cjs/LanguageServer.js +60 -0
- package/dist/cjs/LanguageServer.js.map +7 -0
- package/dist/cjs/Ls.d.ts +164 -0
- package/dist/cjs/Ls.d.ts.map +1 -0
- package/dist/cjs/Ls.js +136 -0
- package/dist/cjs/Ls.js.map +7 -0
- package/dist/cjs/Lsp.d.ts +125 -0
- package/dist/cjs/Lsp.d.ts.map +1 -0
- package/dist/cjs/Lsp.js +137 -0
- package/dist/cjs/Lsp.js.map +7 -0
- package/dist/cjs/Manifest.d.ts +918 -0
- package/dist/cjs/Manifest.d.ts.map +1 -0
- package/dist/cjs/Manifest.js +144 -0
- package/dist/cjs/Manifest.js.map +7 -0
- package/dist/cjs/NativeSearch.d.ts +38 -0
- package/dist/cjs/NativeSearch.d.ts.map +1 -0
- package/dist/cjs/NativeSearch.js +326 -0
- package/dist/cjs/NativeSearch.js.map +7 -0
- package/dist/cjs/NodeLanguageServer.d.ts +128 -0
- package/dist/cjs/NodeLanguageServer.d.ts.map +1 -0
- package/dist/cjs/NodeLanguageServer.js +796 -0
- package/dist/cjs/NodeLanguageServer.js.map +7 -0
- package/dist/cjs/PortableSearch.d.ts +36 -0
- package/dist/cjs/PortableSearch.d.ts.map +1 -0
- package/dist/cjs/PortableSearch.js +240 -0
- package/dist/cjs/PortableSearch.js.map +7 -0
- package/dist/cjs/Probe.d.ts +193 -0
- package/dist/cjs/Probe.d.ts.map +1 -0
- package/dist/cjs/Probe.js +134 -0
- package/dist/cjs/Probe.js.map +7 -0
- package/dist/cjs/Read.d.ts +189 -0
- package/dist/cjs/Read.d.ts.map +1 -0
- package/dist/cjs/Read.js +223 -0
- package/dist/cjs/Read.js.map +7 -0
- package/dist/cjs/Relocate.d.ts +73 -0
- package/dist/cjs/Relocate.d.ts.map +1 -0
- package/dist/cjs/Relocate.js +72 -0
- package/dist/cjs/Relocate.js.map +7 -0
- package/dist/cjs/RemoteSearch.d.ts +54 -0
- package/dist/cjs/RemoteSearch.d.ts.map +1 -0
- package/dist/cjs/RemoteSearch.js +134 -0
- package/dist/cjs/RemoteSearch.js.map +7 -0
- package/dist/cjs/Search.d.ts +163 -0
- package/dist/cjs/Search.d.ts.map +1 -0
- package/dist/cjs/Search.js +51 -0
- package/dist/cjs/Search.js.map +7 -0
- package/dist/cjs/SearchConformance.d.ts +115 -0
- package/dist/cjs/SearchConformance.d.ts.map +1 -0
- package/dist/cjs/SearchConformance.js +172 -0
- package/dist/cjs/SearchConformance.js.map +7 -0
- package/dist/cjs/SearchContract.d.ts +114 -0
- package/dist/cjs/SearchContract.d.ts.map +1 -0
- package/dist/cjs/SearchContract.js +339 -0
- package/dist/cjs/SearchContract.js.map +7 -0
- package/dist/cjs/ShellCommand.d.ts +164 -0
- package/dist/cjs/ShellCommand.d.ts.map +1 -0
- package/dist/cjs/ShellCommand.js +102 -0
- package/dist/cjs/ShellCommand.js.map +7 -0
- package/dist/cjs/StdError.d.ts +55 -0
- package/dist/cjs/StdError.d.ts.map +1 -0
- package/dist/cjs/StdError.js +74 -0
- package/dist/cjs/StdError.js.map +7 -0
- package/dist/cjs/TestRun.d.ts +311 -0
- package/dist/cjs/TestRun.d.ts.map +1 -0
- package/dist/cjs/TestRun.js +228 -0
- package/dist/cjs/TestRun.js.map +7 -0
- package/dist/cjs/TestRunner.d.ts +102 -0
- package/dist/cjs/TestRunner.d.ts.map +1 -0
- package/dist/cjs/TestRunner.js +54 -0
- package/dist/cjs/TestRunner.js.map +7 -0
- package/dist/cjs/TreeFingerprint.d.ts +140 -0
- package/dist/cjs/TreeFingerprint.d.ts.map +1 -0
- package/dist/cjs/TreeFingerprint.js +87 -0
- package/dist/cjs/TreeFingerprint.js.map +7 -0
- package/dist/cjs/UpdatePlan.d.ts +152 -0
- package/dist/cjs/UpdatePlan.d.ts.map +1 -0
- package/dist/cjs/UpdatePlan.js +87 -0
- package/dist/cjs/UpdatePlan.js.map +7 -0
- package/dist/cjs/WebFetch.d.ts +134 -0
- package/dist/cjs/WebFetch.d.ts.map +1 -0
- package/dist/cjs/WebFetch.js +140 -0
- package/dist/cjs/WebFetch.js.map +7 -0
- package/dist/cjs/WebSearch.d.ts +181 -0
- package/dist/cjs/WebSearch.d.ts.map +1 -0
- package/dist/cjs/WebSearch.js +86 -0
- package/dist/cjs/WebSearch.js.map +7 -0
- package/dist/cjs/Write.d.ts +147 -0
- package/dist/cjs/Write.d.ts.map +1 -0
- package/dist/cjs/Write.js +122 -0
- package/dist/cjs/Write.js.map +7 -0
- package/dist/cjs/index.d.ts +129 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +101 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/ApplyPatch.d.ts +145 -0
- package/dist/cjs/internal/ApplyPatch.d.ts.map +1 -0
- package/dist/cjs/internal/ApplyPatch.js +462 -0
- package/dist/cjs/internal/ApplyPatch.js.map +7 -0
- package/dist/cjs/internal/CodexText.d.ts +73 -0
- package/dist/cjs/internal/CodexText.d.ts.map +1 -0
- package/dist/cjs/internal/CodexText.js +108 -0
- package/dist/cjs/internal/CodexText.js.map +7 -0
- package/dist/cjs/internal/Declaration.d.ts +49 -0
- package/dist/cjs/internal/Declaration.d.ts.map +1 -0
- package/dist/cjs/internal/Declaration.js +46 -0
- package/dist/cjs/internal/Declaration.js.map +7 -0
- package/dist/cjs/internal/Diagnostics.d.ts +77 -0
- package/dist/cjs/internal/Diagnostics.d.ts.map +1 -0
- package/dist/cjs/internal/Diagnostics.js +89 -0
- package/dist/cjs/internal/Diagnostics.js.map +7 -0
- package/dist/cjs/internal/EnvelopePrecheck.d.ts +69 -0
- package/dist/cjs/internal/EnvelopePrecheck.d.ts.map +1 -0
- package/dist/cjs/internal/EnvelopePrecheck.js +323 -0
- package/dist/cjs/internal/EnvelopePrecheck.js.map +7 -0
- package/dist/cjs/internal/Exec.d.ts +151 -0
- package/dist/cjs/internal/Exec.d.ts.map +1 -0
- package/dist/cjs/internal/Exec.js +207 -0
- package/dist/cjs/internal/Exec.js.map +7 -0
- package/dist/cjs/internal/FileMutation.d.ts +109 -0
- package/dist/cjs/internal/FileMutation.d.ts.map +1 -0
- package/dist/cjs/internal/FileMutation.js +116 -0
- package/dist/cjs/internal/FileMutation.js.map +7 -0
- package/dist/cjs/internal/FsFailure.d.ts +38 -0
- package/dist/cjs/internal/FsFailure.d.ts.map +1 -0
- package/dist/cjs/internal/FsFailure.js +40 -0
- package/dist/cjs/internal/FsFailure.js.map +7 -0
- package/dist/cjs/internal/GitWorktree.d.ts +108 -0
- package/dist/cjs/internal/GitWorktree.d.ts.map +1 -0
- package/dist/cjs/internal/GitWorktree.js +276 -0
- package/dist/cjs/internal/GitWorktree.js.map +7 -0
- package/dist/cjs/internal/Grouping.d.ts +51 -0
- package/dist/cjs/internal/Grouping.d.ts.map +1 -0
- package/dist/cjs/internal/Grouping.js +83 -0
- package/dist/cjs/internal/Grouping.js.map +7 -0
- package/dist/cjs/internal/Html.d.ts +20 -0
- package/dist/cjs/internal/Html.d.ts.map +1 -0
- package/dist/cjs/internal/Html.js +81 -0
- package/dist/cjs/internal/Html.js.map +7 -0
- package/dist/cjs/internal/Http.d.ts +95 -0
- package/dist/cjs/internal/Http.d.ts.map +1 -0
- package/dist/cjs/internal/Http.js +153 -0
- package/dist/cjs/internal/Http.js.map +7 -0
- package/dist/cjs/internal/HttpNetwork.d.ts +27 -0
- package/dist/cjs/internal/HttpNetwork.d.ts.map +1 -0
- package/dist/cjs/internal/HttpNetwork.js +146 -0
- package/dist/cjs/internal/HttpNetwork.js.map +7 -0
- package/dist/cjs/internal/Ignore.d.ts +37 -0
- package/dist/cjs/internal/Ignore.d.ts.map +1 -0
- package/dist/cjs/internal/Ignore.js +100 -0
- package/dist/cjs/internal/Ignore.js.map +7 -0
- package/dist/cjs/internal/LinearRegex.d.ts +19 -0
- package/dist/cjs/internal/LinearRegex.d.ts.map +1 -0
- package/dist/cjs/internal/LinearRegex.js +166 -0
- package/dist/cjs/internal/LinearRegex.js.map +7 -0
- package/dist/cjs/internal/Match.d.ts +85 -0
- package/dist/cjs/internal/Match.d.ts.map +1 -0
- package/dist/cjs/internal/Match.js +99 -0
- package/dist/cjs/internal/Match.js.map +7 -0
- package/dist/cjs/internal/Paths.d.ts +23 -0
- package/dist/cjs/internal/Paths.d.ts.map +1 -0
- package/dist/cjs/internal/Paths.js +52 -0
- package/dist/cjs/internal/Paths.js.map +7 -0
- package/dist/cjs/internal/Preserve.d.ts +25 -0
- package/dist/cjs/internal/Preserve.d.ts.map +1 -0
- package/dist/cjs/internal/Preserve.js +88 -0
- package/dist/cjs/internal/Preserve.js.map +7 -0
- package/dist/cjs/internal/Prune.d.ts +35 -0
- package/dist/cjs/internal/Prune.d.ts.map +1 -0
- package/dist/cjs/internal/Prune.js +54 -0
- package/dist/cjs/internal/Prune.js.map +7 -0
- package/dist/cjs/internal/RemoteTree.d.ts +60 -0
- package/dist/cjs/internal/RemoteTree.d.ts.map +1 -0
- package/dist/cjs/internal/RemoteTree.js +123 -0
- package/dist/cjs/internal/RemoteTree.js.map +7 -0
- package/dist/cjs/internal/SearchContract.d.ts +63 -0
- package/dist/cjs/internal/SearchContract.d.ts.map +1 -0
- package/dist/cjs/internal/SearchContract.js +46 -0
- package/dist/cjs/internal/SearchContract.js.map +7 -0
- package/dist/cjs/internal/Symbols.d.ts +39 -0
- package/dist/cjs/internal/Symbols.d.ts.map +1 -0
- package/dist/cjs/internal/Symbols.js +59 -0
- package/dist/cjs/internal/Symbols.js.map +7 -0
- package/dist/cjs/internal/Tar.d.ts +23 -0
- package/dist/cjs/internal/Tar.d.ts.map +1 -0
- package/dist/cjs/internal/Tar.js +86 -0
- package/dist/cjs/internal/Tar.js.map +7 -0
- package/dist/cjs/internal/TestReport.d.ts +52 -0
- package/dist/cjs/internal/TestReport.d.ts.map +1 -0
- package/dist/cjs/internal/TestReport.js +131 -0
- package/dist/cjs/internal/TestReport.js.map +7 -0
- package/dist/cjs/internal/Text.d.ts +125 -0
- package/dist/cjs/internal/Text.d.ts.map +1 -0
- package/dist/cjs/internal/Text.js +85 -0
- package/dist/cjs/internal/Text.js.map +7 -0
- package/dist/cjs/internal/Url.d.ts +13 -0
- package/dist/cjs/internal/Url.d.ts.map +1 -0
- package/dist/cjs/internal/Url.js +35 -0
- package/dist/cjs/internal/Url.js.map +7 -0
- package/dist/cjs/internal/Walk.d.ts +72 -0
- package/dist/cjs/internal/Walk.d.ts.map +1 -0
- package/dist/cjs/internal/Walk.js +108 -0
- package/dist/cjs/internal/Walk.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/ApplyPatch.d.ts +174 -0
- package/dist/esm/ApplyPatch.d.ts.map +1 -0
- package/dist/esm/ApplyPatch.js +346 -0
- package/dist/esm/ApplyPatch.js.map +1 -0
- package/dist/esm/Bash.d.ts +390 -0
- package/dist/esm/Bash.d.ts.map +1 -0
- package/dist/esm/Bash.js +514 -0
- package/dist/esm/Bash.js.map +1 -0
- package/dist/esm/Checkpoints.d.ts +322 -0
- package/dist/esm/Checkpoints.d.ts.map +1 -0
- package/dist/esm/Checkpoints.js +396 -0
- package/dist/esm/Checkpoints.js.map +1 -0
- package/dist/esm/Container.d.ts +132 -0
- package/dist/esm/Container.d.ts.map +1 -0
- package/dist/esm/Container.js +151 -0
- package/dist/esm/Container.js.map +1 -0
- package/dist/esm/Edit.d.ts +203 -0
- package/dist/esm/Edit.d.ts.map +1 -0
- package/dist/esm/Edit.js +296 -0
- package/dist/esm/Edit.js.map +1 -0
- package/dist/esm/ExaWebSearch.d.ts +22 -0
- package/dist/esm/ExaWebSearch.d.ts.map +1 -0
- package/dist/esm/ExaWebSearch.js +107 -0
- package/dist/esm/ExaWebSearch.js.map +1 -0
- package/dist/esm/Explore.d.ts +328 -0
- package/dist/esm/Explore.d.ts.map +1 -0
- package/dist/esm/Explore.js +106 -0
- package/dist/esm/Explore.js.map +1 -0
- package/dist/esm/Fetch.d.ts +130 -0
- package/dist/esm/Fetch.d.ts.map +1 -0
- package/dist/esm/Fetch.js +91 -0
- package/dist/esm/Fetch.js.map +1 -0
- package/dist/esm/Glob.d.ts +204 -0
- package/dist/esm/Glob.d.ts.map +1 -0
- package/dist/esm/Glob.js +177 -0
- package/dist/esm/Glob.js.map +1 -0
- package/dist/esm/Grep.d.ts +347 -0
- package/dist/esm/Grep.d.ts.map +1 -0
- package/dist/esm/Grep.js +289 -0
- package/dist/esm/Grep.js.map +1 -0
- package/dist/esm/HttpPost.d.ts +130 -0
- package/dist/esm/HttpPost.d.ts.map +1 -0
- package/dist/esm/HttpPost.js +89 -0
- package/dist/esm/HttpPost.js.map +1 -0
- package/dist/esm/LanguageServer.d.ts +90 -0
- package/dist/esm/LanguageServer.d.ts.map +1 -0
- package/dist/esm/LanguageServer.js +57 -0
- package/dist/esm/LanguageServer.js.map +1 -0
- package/dist/esm/Ls.d.ts +164 -0
- package/dist/esm/Ls.d.ts.map +1 -0
- package/dist/esm/Ls.js +178 -0
- package/dist/esm/Ls.js.map +1 -0
- package/dist/esm/Lsp.d.ts +125 -0
- package/dist/esm/Lsp.d.ts.map +1 -0
- package/dist/esm/Lsp.js +165 -0
- package/dist/esm/Lsp.js.map +1 -0
- package/dist/esm/Manifest.d.ts +918 -0
- package/dist/esm/Manifest.d.ts.map +1 -0
- package/dist/esm/Manifest.js +153 -0
- package/dist/esm/Manifest.js.map +1 -0
- package/dist/esm/NativeSearch.d.ts +38 -0
- package/dist/esm/NativeSearch.d.ts.map +1 -0
- package/dist/esm/NativeSearch.js +378 -0
- package/dist/esm/NativeSearch.js.map +1 -0
- package/dist/esm/NodeLanguageServer.d.ts +128 -0
- package/dist/esm/NodeLanguageServer.d.ts.map +1 -0
- package/dist/esm/NodeLanguageServer.js +843 -0
- package/dist/esm/NodeLanguageServer.js.map +1 -0
- package/dist/esm/PortableSearch.d.ts +36 -0
- package/dist/esm/PortableSearch.d.ts.map +1 -0
- package/dist/esm/PortableSearch.js +256 -0
- package/dist/esm/PortableSearch.js.map +1 -0
- package/dist/esm/Probe.d.ts +193 -0
- package/dist/esm/Probe.d.ts.map +1 -0
- package/dist/esm/Probe.js +225 -0
- package/dist/esm/Probe.js.map +1 -0
- package/dist/esm/Read.d.ts +189 -0
- package/dist/esm/Read.d.ts.map +1 -0
- package/dist/esm/Read.js +300 -0
- package/dist/esm/Read.js.map +1 -0
- package/dist/esm/Relocate.d.ts +73 -0
- package/dist/esm/Relocate.d.ts.map +1 -0
- package/dist/esm/Relocate.js +153 -0
- package/dist/esm/Relocate.js.map +1 -0
- package/dist/esm/RemoteSearch.d.ts +54 -0
- package/dist/esm/RemoteSearch.d.ts.map +1 -0
- package/dist/esm/RemoteSearch.js +162 -0
- package/dist/esm/RemoteSearch.js.map +1 -0
- package/dist/esm/Search.d.ts +163 -0
- package/dist/esm/Search.d.ts.map +1 -0
- package/dist/esm/Search.js +47 -0
- package/dist/esm/Search.js.map +1 -0
- package/dist/esm/SearchConformance.d.ts +115 -0
- package/dist/esm/SearchConformance.d.ts.map +1 -0
- package/dist/esm/SearchConformance.js +193 -0
- package/dist/esm/SearchConformance.js.map +1 -0
- package/dist/esm/SearchContract.d.ts +114 -0
- package/dist/esm/SearchContract.d.ts.map +1 -0
- package/dist/esm/SearchContract.js +461 -0
- package/dist/esm/SearchContract.js.map +1 -0
- package/dist/esm/ShellCommand.d.ts +164 -0
- package/dist/esm/ShellCommand.d.ts.map +1 -0
- package/dist/esm/ShellCommand.js +159 -0
- package/dist/esm/ShellCommand.js.map +1 -0
- package/dist/esm/StdError.d.ts +55 -0
- package/dist/esm/StdError.d.ts.map +1 -0
- package/dist/esm/StdError.js +71 -0
- package/dist/esm/StdError.js.map +1 -0
- package/dist/esm/TestRun.d.ts +311 -0
- package/dist/esm/TestRun.d.ts.map +1 -0
- package/dist/esm/TestRun.js +316 -0
- package/dist/esm/TestRun.js.map +1 -0
- package/dist/esm/TestRunner.d.ts +102 -0
- package/dist/esm/TestRunner.d.ts.map +1 -0
- package/dist/esm/TestRunner.js +68 -0
- package/dist/esm/TestRunner.js.map +1 -0
- package/dist/esm/TreeFingerprint.d.ts +140 -0
- package/dist/esm/TreeFingerprint.d.ts.map +1 -0
- package/dist/esm/TreeFingerprint.js +170 -0
- package/dist/esm/TreeFingerprint.js.map +1 -0
- package/dist/esm/UpdatePlan.d.ts +152 -0
- package/dist/esm/UpdatePlan.d.ts.map +1 -0
- package/dist/esm/UpdatePlan.js +129 -0
- package/dist/esm/UpdatePlan.js.map +1 -0
- package/dist/esm/WebFetch.d.ts +134 -0
- package/dist/esm/WebFetch.d.ts.map +1 -0
- package/dist/esm/WebFetch.js +151 -0
- package/dist/esm/WebFetch.js.map +1 -0
- package/dist/esm/WebSearch.d.ts +181 -0
- package/dist/esm/WebSearch.d.ts.map +1 -0
- package/dist/esm/WebSearch.js +134 -0
- package/dist/esm/WebSearch.js.map +1 -0
- package/dist/esm/Write.d.ts +147 -0
- package/dist/esm/Write.d.ts.map +1 -0
- package/dist/esm/Write.js +144 -0
- package/dist/esm/Write.js.map +1 -0
- package/dist/esm/index.d.ts +129 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +129 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/ApplyPatch.d.ts +145 -0
- package/dist/esm/internal/ApplyPatch.d.ts.map +1 -0
- package/dist/esm/internal/ApplyPatch.js +489 -0
- package/dist/esm/internal/ApplyPatch.js.map +1 -0
- package/dist/esm/internal/CodexText.d.ts +73 -0
- package/dist/esm/internal/CodexText.d.ts.map +1 -0
- package/dist/esm/internal/CodexText.js +156 -0
- package/dist/esm/internal/CodexText.js.map +1 -0
- package/dist/esm/internal/Declaration.d.ts +49 -0
- package/dist/esm/internal/Declaration.d.ts.map +1 -0
- package/dist/esm/internal/Declaration.js +42 -0
- package/dist/esm/internal/Declaration.js.map +1 -0
- package/dist/esm/internal/Diagnostics.d.ts +77 -0
- package/dist/esm/internal/Diagnostics.d.ts.map +1 -0
- package/dist/esm/internal/Diagnostics.js +99 -0
- package/dist/esm/internal/Diagnostics.js.map +1 -0
- package/dist/esm/internal/EnvelopePrecheck.d.ts +69 -0
- package/dist/esm/internal/EnvelopePrecheck.d.ts.map +1 -0
- package/dist/esm/internal/EnvelopePrecheck.js +426 -0
- package/dist/esm/internal/EnvelopePrecheck.js.map +1 -0
- package/dist/esm/internal/Exec.d.ts +151 -0
- package/dist/esm/internal/Exec.d.ts.map +1 -0
- package/dist/esm/internal/Exec.js +285 -0
- package/dist/esm/internal/Exec.js.map +1 -0
- package/dist/esm/internal/FileMutation.d.ts +109 -0
- package/dist/esm/internal/FileMutation.d.ts.map +1 -0
- package/dist/esm/internal/FileMutation.js +123 -0
- package/dist/esm/internal/FileMutation.js.map +1 -0
- package/dist/esm/internal/FsFailure.d.ts +38 -0
- package/dist/esm/internal/FsFailure.d.ts.map +1 -0
- package/dist/esm/internal/FsFailure.js +39 -0
- package/dist/esm/internal/FsFailure.js.map +1 -0
- package/dist/esm/internal/GitWorktree.d.ts +108 -0
- package/dist/esm/internal/GitWorktree.d.ts.map +1 -0
- package/dist/esm/internal/GitWorktree.js +352 -0
- package/dist/esm/internal/GitWorktree.js.map +1 -0
- package/dist/esm/internal/Grouping.d.ts +51 -0
- package/dist/esm/internal/Grouping.d.ts.map +1 -0
- package/dist/esm/internal/Grouping.js +99 -0
- package/dist/esm/internal/Grouping.js.map +1 -0
- package/dist/esm/internal/Html.d.ts +20 -0
- package/dist/esm/internal/Html.d.ts.map +1 -0
- package/dist/esm/internal/Html.js +70 -0
- package/dist/esm/internal/Html.js.map +1 -0
- package/dist/esm/internal/Http.d.ts +95 -0
- package/dist/esm/internal/Http.d.ts.map +1 -0
- package/dist/esm/internal/Http.js +154 -0
- package/dist/esm/internal/Http.js.map +1 -0
- package/dist/esm/internal/HttpNetwork.d.ts +27 -0
- package/dist/esm/internal/HttpNetwork.d.ts.map +1 -0
- package/dist/esm/internal/HttpNetwork.js +114 -0
- package/dist/esm/internal/HttpNetwork.js.map +1 -0
- package/dist/esm/internal/Ignore.d.ts +37 -0
- package/dist/esm/internal/Ignore.d.ts.map +1 -0
- package/dist/esm/internal/Ignore.js +128 -0
- package/dist/esm/internal/Ignore.js.map +1 -0
- package/dist/esm/internal/LinearRegex.d.ts +19 -0
- package/dist/esm/internal/LinearRegex.d.ts.map +1 -0
- package/dist/esm/internal/LinearRegex.js +176 -0
- package/dist/esm/internal/LinearRegex.js.map +1 -0
- package/dist/esm/internal/Match.d.ts +85 -0
- package/dist/esm/internal/Match.d.ts.map +1 -0
- package/dist/esm/internal/Match.js +142 -0
- package/dist/esm/internal/Match.js.map +1 -0
- package/dist/esm/internal/Paths.d.ts +23 -0
- package/dist/esm/internal/Paths.d.ts.map +1 -0
- package/dist/esm/internal/Paths.js +40 -0
- package/dist/esm/internal/Paths.js.map +1 -0
- package/dist/esm/internal/Preserve.d.ts +25 -0
- package/dist/esm/internal/Preserve.d.ts.map +1 -0
- package/dist/esm/internal/Preserve.js +70 -0
- package/dist/esm/internal/Preserve.js.map +1 -0
- package/dist/esm/internal/Prune.d.ts +35 -0
- package/dist/esm/internal/Prune.d.ts.map +1 -0
- package/dist/esm/internal/Prune.js +60 -0
- package/dist/esm/internal/Prune.js.map +1 -0
- package/dist/esm/internal/RemoteTree.d.ts +60 -0
- package/dist/esm/internal/RemoteTree.d.ts.map +1 -0
- package/dist/esm/internal/RemoteTree.js +132 -0
- package/dist/esm/internal/RemoteTree.js.map +1 -0
- package/dist/esm/internal/SearchContract.d.ts +63 -0
- package/dist/esm/internal/SearchContract.d.ts.map +1 -0
- package/dist/esm/internal/SearchContract.js +66 -0
- package/dist/esm/internal/SearchContract.js.map +1 -0
- package/dist/esm/internal/Symbols.d.ts +39 -0
- package/dist/esm/internal/Symbols.d.ts.map +1 -0
- package/dist/esm/internal/Symbols.js +79 -0
- package/dist/esm/internal/Symbols.js.map +1 -0
- package/dist/esm/internal/Tar.d.ts +23 -0
- package/dist/esm/internal/Tar.d.ts.map +1 -0
- package/dist/esm/internal/Tar.js +97 -0
- package/dist/esm/internal/Tar.js.map +1 -0
- package/dist/esm/internal/TestReport.d.ts +52 -0
- package/dist/esm/internal/TestReport.d.ts.map +1 -0
- package/dist/esm/internal/TestReport.js +172 -0
- package/dist/esm/internal/TestReport.js.map +1 -0
- package/dist/esm/internal/Text.d.ts +125 -0
- package/dist/esm/internal/Text.d.ts.map +1 -0
- package/dist/esm/internal/Text.js +141 -0
- package/dist/esm/internal/Text.js.map +1 -0
- package/dist/esm/internal/Url.d.ts +13 -0
- package/dist/esm/internal/Url.d.ts.map +1 -0
- package/dist/esm/internal/Url.js +27 -0
- package/dist/esm/internal/Url.js.map +1 -0
- package/dist/esm/internal/Walk.d.ts +72 -0
- package/dist/esm/internal/Walk.d.ts.map +1 -0
- package/dist/esm/internal/Walk.js +126 -0
- package/dist/esm/internal/Walk.js.map +1 -0
- package/docs/README.md +119 -0
- package/docs/api.md +499 -0
- package/docs/concepts/effects-and-capabilities.md +138 -0
- package/docs/concepts/flows-and-handlers.md +115 -0
- package/docs/concepts/limits-and-disclosure.md +105 -0
- package/docs/concepts/search-contract.md +182 -0
- package/docs/guides/bind-the-standard-flows.md +116 -0
- package/docs/guides/implement-a-search-peer.md +133 -0
- package/docs/guides/pin-a-checkpoint.md +161 -0
- package/docs/guides/query-a-language-server.md +257 -0
- package/docs/guides/reach-the-network.md +141 -0
- package/docs/guides/read-and-edit-a-file.md +240 -0
- package/docs/guides/run-a-shell-command.md +236 -0
- package/docs/guides/run-the-test-suite.md +154 -0
- package/docs/guides/search-a-workspace.md +148 -0
- package/docs/installation.md +115 -0
- package/docs/quickstart.md +125 -0
- package/docs/reference/flows.md +556 -0
- package/docs/troubleshooting.md +347 -0
- package/package.json +449 -3
- package/src/ApplyPatch.ts +458 -0
- package/src/Bash.ts +619 -0
- package/src/Checkpoints.ts +589 -0
- package/src/Container.ts +212 -0
- package/src/Edit.ts +366 -0
- package/src/ExaWebSearch.ts +145 -0
- package/src/Explore.ts +139 -0
- package/src/Fetch.ts +117 -0
- package/src/Glob.ts +200 -0
- package/src/Grep.ts +320 -0
- package/src/HttpPost.ts +120 -0
- package/src/LanguageServer.ts +110 -0
- package/src/Ls.ts +228 -0
- package/src/Lsp.ts +184 -0
- package/src/Manifest.ts +162 -0
- package/src/NativeSearch.ts +457 -0
- package/src/NodeLanguageServer.ts +1148 -0
- package/src/PortableSearch.ts +284 -0
- package/src/Probe.ts +284 -0
- package/src/Read.ts +359 -0
- package/src/Relocate.ts +166 -0
- package/src/RemoteSearch.ts +199 -0
- package/src/Search.ts +185 -0
- package/src/SearchConformance.ts +288 -0
- package/src/SearchContract.ts +489 -0
- package/src/ShellCommand.ts +201 -0
- package/src/StdError.ts +80 -0
- package/src/TestRun.ts +401 -0
- package/src/TestRunner.ts +119 -0
- package/src/TreeFingerprint.ts +200 -0
- package/src/UpdatePlan.ts +171 -0
- package/src/WebFetch.ts +194 -0
- package/src/WebSearch.ts +165 -0
- package/src/Write.ts +195 -0
- package/src/index.ts +157 -0
- package/src/internal/ApplyPatch.ts +601 -0
- package/src/internal/CodexText.ts +182 -0
- package/src/internal/Declaration.ts +60 -0
- package/src/internal/Diagnostics.ts +134 -0
- package/src/internal/EnvelopePrecheck.ts +489 -0
- package/src/internal/Exec.ts +427 -0
- package/src/internal/FileMutation.ts +231 -0
- package/src/internal/FsFailure.ts +51 -0
- package/src/internal/GitWorktree.ts +491 -0
- package/src/internal/Grouping.ts +106 -0
- package/src/internal/Html.ts +87 -0
- package/src/internal/Http.ts +209 -0
- package/src/internal/HttpNetwork.ts +153 -0
- package/src/internal/Ignore.ts +135 -0
- package/src/internal/LinearRegex.ts +173 -0
- package/src/internal/Match.ts +172 -0
- package/src/internal/Paths.ts +42 -0
- package/src/internal/Preserve.ts +108 -0
- package/src/internal/Prune.ts +62 -0
- package/src/internal/RemoteTree.ts +159 -0
- package/src/internal/SearchContract.ts +77 -0
- package/src/internal/Symbols.ts +88 -0
- package/src/internal/Tar.ts +95 -0
- package/src/internal/TestReport.ts +194 -0
- package/src/internal/Text.ts +185 -0
- package/src/internal/Url.ts +23 -0
- package/src/internal/Walk.ts +176 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* apply_patch flow declaration and portable handler.
|
|
3
|
+
*
|
|
4
|
+
* A Codex CLI clone: the V4A patch grammar (`*** Begin Patch` /
|
|
5
|
+
* `*** Add File:` / `*** Update File:` / `*** Delete File:` /
|
|
6
|
+
* `*** End Patch`), the fuzzy context-matching applier, and Codex's error
|
|
7
|
+
* and summary text, expressed as a flow over the kernel filesystem.
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import * as Path from "@smthrs/kernel/Path";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as FileSystem from "effect/FileSystem";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import * as ApplyPatchText from "./internal/ApplyPatch.js";
|
|
16
|
+
import { capability, envelope } from "./internal/Declaration.js";
|
|
17
|
+
import * as Diagnostics from "./internal/Diagnostics.js";
|
|
18
|
+
import * as FileMutation from "./internal/FileMutation.js";
|
|
19
|
+
import * as FsFailure from "./internal/FsFailure.js";
|
|
20
|
+
import * as Preserve from "./internal/Preserve.js";
|
|
21
|
+
import * as StdError from "./StdError.js";
|
|
22
|
+
/**
|
|
23
|
+
* Registry name for the apply_patch flow. Matches the Codex CLI tool name.
|
|
24
|
+
*
|
|
25
|
+
* @category identifiers
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export const name = "apply_patch";
|
|
29
|
+
/**
|
|
30
|
+
* Model-facing description of the apply_patch flow. Matches the Codex CLI
|
|
31
|
+
* freeform tool description.
|
|
32
|
+
*
|
|
33
|
+
* @category descriptions
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export const description = "The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.";
|
|
37
|
+
/**
|
|
38
|
+
* Input schema for the apply_patch flow.
|
|
39
|
+
*
|
|
40
|
+
* Codex delivers the patch as freeform text; the JSON function fallback uses
|
|
41
|
+
* a single `input` field, which is the shape cloned here.
|
|
42
|
+
*
|
|
43
|
+
* @category schemas
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
*/
|
|
46
|
+
export const Input = Schema.Struct({
|
|
47
|
+
input: Schema.String.annotate({ description: "The entire contents of the apply_patch command" })
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Output schema for the apply_patch flow.
|
|
51
|
+
*
|
|
52
|
+
* @category schemas
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
export const Output = Schema.Struct({
|
|
56
|
+
output: Schema.String.annotate({
|
|
57
|
+
description: "Codex-style summary: 'Success. Updated the following files:' with A/M/D lines"
|
|
58
|
+
}),
|
|
59
|
+
added: Schema.Array(Schema.String).annotate({ description: "Paths of files created by the patch" }),
|
|
60
|
+
modified: Schema.Array(Schema.String).annotate({ description: "Paths of files updated by the patch" }),
|
|
61
|
+
deleted: Schema.Array(Schema.String).annotate({ description: "Paths of files deleted by the patch" })
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Static conservative effect envelope for the apply_patch flow.
|
|
65
|
+
*
|
|
66
|
+
* @category effects
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
export const effects = envelope({ tier: "compensable", mode: "hermetic", reads: ["/**"], writes: ["/**"] });
|
|
70
|
+
/**
|
|
71
|
+
* Narrows the effect envelope for a decoded invocation.
|
|
72
|
+
*
|
|
73
|
+
* A patch names its files inside its own text rather than in a decoded field,
|
|
74
|
+
* and the parse that finds them is the same parse that can fail, so there is
|
|
75
|
+
* nothing here to narrow before the handler runs: the static envelope is the
|
|
76
|
+
* honest answer.
|
|
77
|
+
*
|
|
78
|
+
* @category effects
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
*/
|
|
81
|
+
export const effectsFor = (_input) => effects;
|
|
82
|
+
/**
|
|
83
|
+
* Capabilities required by the apply_patch flow.
|
|
84
|
+
*
|
|
85
|
+
* @category capabilities
|
|
86
|
+
* @since 1.0.0
|
|
87
|
+
*/
|
|
88
|
+
export const capabilities = [capability("fs:read", "/**"), capability("fs:write", "/**")];
|
|
89
|
+
/**
|
|
90
|
+
* Declaration-only apply_patch flow.
|
|
91
|
+
*
|
|
92
|
+
* @category flows
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
export const flow = { name, description, input: Input, output: Output, capabilities, effects };
|
|
96
|
+
/**
|
|
97
|
+
* What a call to this flow does, for a reader of a run.
|
|
98
|
+
*
|
|
99
|
+
* Display metadata only. `@smthrs/registry` `Descriptor.FlowActivity` is the
|
|
100
|
+
* governing vocabulary and `StandardFlows` binds this value onto the flow's
|
|
101
|
+
* descriptor, where the binding site checks it. `declarationDigest` excludes
|
|
102
|
+
* it, so declaring it cannot invalidate a call identity or a cached prompt.
|
|
103
|
+
*
|
|
104
|
+
* @category presentation
|
|
105
|
+
* @since 1.0.0-rc.0
|
|
106
|
+
*/
|
|
107
|
+
export const activity = "writes";
|
|
108
|
+
/**
|
|
109
|
+
* How one recorded call to this flow reads: the verb for each settlement, the
|
|
110
|
+
* input field that is its subject, and the measured output fields a one-line
|
|
111
|
+
* summary may count.
|
|
112
|
+
*
|
|
113
|
+
* Display metadata only, governed by `@smthrs/registry`
|
|
114
|
+
* `Descriptor.CallPresentation` and checked where `StandardFlows` binds it.
|
|
115
|
+
*
|
|
116
|
+
* @category presentation
|
|
117
|
+
* @since 1.0.0-rc.0
|
|
118
|
+
*/
|
|
119
|
+
export const presentation = {
|
|
120
|
+
verb: { pending: "patching", success: "patched", failure: "failed to patch" },
|
|
121
|
+
subject: "patch",
|
|
122
|
+
result: "patch"
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Every path a patch writes, in the order it names them, including a move's
|
|
126
|
+
* destination. The patch is read by the parser {@link run} uses, so a header
|
|
127
|
+
* `run` accepts is never missed.
|
|
128
|
+
*
|
|
129
|
+
* Returns `undefined` when `run` would refuse the patch. A caller asking
|
|
130
|
+
* permission for the call then asks for everything the flow declares.
|
|
131
|
+
*
|
|
132
|
+
* @category parsing
|
|
133
|
+
* @since 1.0.0-rc.1
|
|
134
|
+
*/
|
|
135
|
+
export const paths = (patch) => {
|
|
136
|
+
let parsed;
|
|
137
|
+
try {
|
|
138
|
+
parsed = ApplyPatchText.parsePatch(patch);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
return [
|
|
144
|
+
...new Set(parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]))
|
|
145
|
+
];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The one sentence a model sees for a failure this handler did not design.
|
|
149
|
+
* The raw failure goes to the log, never into the tool result.
|
|
150
|
+
*/
|
|
151
|
+
const unknownFailureSentence = "Something went wrong on our side. Not your fault.";
|
|
152
|
+
const unknownFailure = (error, path) => Effect.logError("apply_patch failed unexpectedly", error).pipe(Effect.andThen(Effect.fail(new StdError.StdError(path === undefined
|
|
153
|
+
? { code: "command_failed", message: unknownFailureSentence }
|
|
154
|
+
: { code: "command_failed", message: unknownFailureSentence, path }))));
|
|
155
|
+
const encoder = new TextEncoder();
|
|
156
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
157
|
+
/**
|
|
158
|
+
* Parses and applies a V4A patch through the permission-aware kernel
|
|
159
|
+
* filesystem, preserving Codex error text.
|
|
160
|
+
*
|
|
161
|
+
* @category handlers
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
*/
|
|
164
|
+
export const run = Effect.fn("ApplyPatch.run")(function* (input) {
|
|
165
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
166
|
+
const path = yield* Path.Path;
|
|
167
|
+
let parsed;
|
|
168
|
+
try {
|
|
169
|
+
parsed = ApplyPatchText.parsePatch(input.input);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (error instanceof ApplyPatchText.ParseError) {
|
|
173
|
+
return yield* Effect.fail(new StdError.StdError({ code: "invalid_input", message: error.message }));
|
|
174
|
+
}
|
|
175
|
+
return yield* unknownFailure(error);
|
|
176
|
+
}
|
|
177
|
+
// Every update hunk is derived from the file as it is on disk, so two
|
|
178
|
+
// sections naming one path both start from the same original and the second
|
|
179
|
+
// write erases the first — while the summary reports two modifications.
|
|
180
|
+
// The preflight cannot honestly validate the second section against a file
|
|
181
|
+
// the first has not written yet, so the patch is refused whole rather than
|
|
182
|
+
// applied by halves. A file needing several edits carries several `@@`
|
|
183
|
+
// chunks inside one section, which is the shape the parser already accepts.
|
|
184
|
+
// Resolve against the injected workspace, then follow existing filesystem
|
|
185
|
+
// aliases. For a new file, resolve its parent (which may be a symlink).
|
|
186
|
+
const identity = (value) => {
|
|
187
|
+
const resolved = path.resolve(value);
|
|
188
|
+
return fileSystem.realPath(resolved).pipe(Effect.catch((error) => error.reason._tag === "NotFound"
|
|
189
|
+
? fileSystem.realPath(path.dirname(resolved)).pipe(Effect.map((parent) => path.resolve(parent, path.basename(resolved))), Effect.catch((parentError) => parentError.reason._tag === "NotFound"
|
|
190
|
+
? Effect.succeed(resolved)
|
|
191
|
+
: Effect.fail(parentError)))
|
|
192
|
+
: Effect.fail(error)), Effect.mapError(FsFailure.denied(value, () => new StdError.StdError({
|
|
193
|
+
code: "command_failed",
|
|
194
|
+
message: `Failed to resolve patch path ${value}`,
|
|
195
|
+
path: value
|
|
196
|
+
}))));
|
|
197
|
+
};
|
|
198
|
+
const touched = new Set();
|
|
199
|
+
for (const hunk of parsed.hunks) {
|
|
200
|
+
const source = yield* identity(hunk.path);
|
|
201
|
+
const destination = hunk.kind === "update" && hunk.movePath !== undefined
|
|
202
|
+
? yield* identity(hunk.movePath)
|
|
203
|
+
: undefined;
|
|
204
|
+
const claims = [[hunk.path, source]];
|
|
205
|
+
if (hunk.kind === "update" && hunk.movePath !== undefined && destination !== source) {
|
|
206
|
+
claims.push([hunk.movePath, destination]);
|
|
207
|
+
}
|
|
208
|
+
for (const [claimed, key] of claims) {
|
|
209
|
+
if (touched.has(key)) {
|
|
210
|
+
return yield* Effect.fail(new StdError.StdError({
|
|
211
|
+
code: "invalid_input",
|
|
212
|
+
message: `The patch names ${claimed} in more than one section; give one section per path`,
|
|
213
|
+
path: claimed
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
touched.add(key);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
yield* FileMutation.validate(fileSystem, parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]));
|
|
220
|
+
// Create only parents the patch already intends to create, before taking
|
|
221
|
+
// stable sibling locks for new destinations as well as existing sources.
|
|
222
|
+
for (const hunk of parsed.hunks) {
|
|
223
|
+
const destination = hunk.kind === "add" ? hunk.path : hunk.kind === "update" ? hunk.movePath : undefined;
|
|
224
|
+
if (destination !== undefined && !FileMutation.isVersioned(fileSystem)) {
|
|
225
|
+
yield* fileSystem.makeDirectory(path.dirname(destination), { recursive: true }).pipe(Effect.mapError(FsFailure.denied(destination, () => new StdError.StdError({
|
|
226
|
+
code: "command_failed",
|
|
227
|
+
message: `Failed to create parent directories for ${destination}`,
|
|
228
|
+
path: destination
|
|
229
|
+
}))));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return yield* Effect.scoped(Effect.gen(function* () {
|
|
233
|
+
const mutation = yield* FileMutation.acquire(fileSystem, parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]), path);
|
|
234
|
+
const added = [];
|
|
235
|
+
const modified = [];
|
|
236
|
+
const deleted = [];
|
|
237
|
+
const prepared = new Map();
|
|
238
|
+
for (const hunk of parsed.hunks) {
|
|
239
|
+
if (hunk.kind !== "update")
|
|
240
|
+
continue;
|
|
241
|
+
const bytes = yield* mutation.read(hunk.path, fileSystem.readFile(hunk.path).pipe(Effect.mapError(FsFailure.reading(hunk.path, `Failed to read file to update ${hunk.path}`))));
|
|
242
|
+
if (bytes.includes(0)) {
|
|
243
|
+
return yield* Effect.fail(new StdError.StdError({
|
|
244
|
+
code: "binary_file",
|
|
245
|
+
message: `Cannot read binary file: ${hunk.path}`,
|
|
246
|
+
path: hunk.path
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
const original = yield* Effect.try({
|
|
250
|
+
try: () => decoder.decode(bytes),
|
|
251
|
+
catch: () => new StdError.StdError({
|
|
252
|
+
code: "binary_file",
|
|
253
|
+
message: `File is not valid UTF-8: ${hunk.path}`,
|
|
254
|
+
path: hunk.path
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
let contents;
|
|
258
|
+
try {
|
|
259
|
+
contents = ApplyPatchText.deriveNewContents(original, hunk.path, hunk.chunks);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (error instanceof ApplyPatchText.ComputeReplacementsError) {
|
|
263
|
+
return yield* Effect.fail(new StdError.StdError({ code: "no_match", message: error.message, path: hunk.path }));
|
|
264
|
+
}
|
|
265
|
+
return yield* unknownFailure(error, hunk.path);
|
|
266
|
+
}
|
|
267
|
+
prepared.set(hunk, contents);
|
|
268
|
+
}
|
|
269
|
+
// Prepare one complete provider request before touching any file. A move
|
|
270
|
+
// carries both its destination write and source removal in the same commit.
|
|
271
|
+
const changes = [];
|
|
272
|
+
const moves = new Set();
|
|
273
|
+
for (const hunk of parsed.hunks) {
|
|
274
|
+
if (hunk.kind === "delete") {
|
|
275
|
+
changes.push({ path: hunk.path, content: null });
|
|
276
|
+
}
|
|
277
|
+
else if (hunk.kind === "add") {
|
|
278
|
+
changes.push({ path: hunk.path, content: encoder.encode(hunk.contents) });
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
changes.push({
|
|
282
|
+
path: hunk.movePath ?? hunk.path,
|
|
283
|
+
content: encoder.encode(prepared.get(hunk))
|
|
284
|
+
});
|
|
285
|
+
if (hunk.movePath !== undefined && (yield* identity(hunk.movePath)) !== (yield* identity(hunk.path))) {
|
|
286
|
+
moves.add(hunk);
|
|
287
|
+
changes.push({ path: hunk.path, content: null });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// A denial names itself, so the model does not retry a write the host refuses.
|
|
292
|
+
const mutationFailure = (code, message, offendingPath) => (error) => error.reason._tag === "PermissionDenied"
|
|
293
|
+
? mutationError("permission_denied", `Permission denied: ${offendingPath}`, offendingPath)
|
|
294
|
+
: mutationError(code, message, offendingPath);
|
|
295
|
+
const mutationError = (code, message, offendingPath) => new StdError.StdError({
|
|
296
|
+
code,
|
|
297
|
+
message: `${message}; applied before failure: added=${JSON.stringify(added)}, modified=${JSON.stringify(modified)}, deleted=${JSON.stringify(deleted)}`,
|
|
298
|
+
path: offendingPath
|
|
299
|
+
});
|
|
300
|
+
yield* mutation.commit(changes, Effect.gen(function* () {
|
|
301
|
+
for (const hunk of parsed.hunks) {
|
|
302
|
+
switch (hunk.kind) {
|
|
303
|
+
case "add": {
|
|
304
|
+
yield* fileSystem.writeFile(hunk.path, encoder.encode(hunk.contents)).pipe(Effect.mapError(mutationFailure("command_failed", `Failed to write file ${hunk.path}`, hunk.path)));
|
|
305
|
+
added.push(hunk.path);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "delete": {
|
|
309
|
+
yield* fileSystem.remove(hunk.path).pipe(Effect.mapError(mutationFailure("not_found", `Failed to delete file ${hunk.path}`, hunk.path)));
|
|
310
|
+
deleted.push(hunk.path);
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case "update": {
|
|
314
|
+
const contents = prepared.get(hunk);
|
|
315
|
+
const destination = hunk.movePath ?? hunk.path;
|
|
316
|
+
yield* Preserve.writeFile(fileSystem, destination, encoder.encode(contents)).pipe(Effect.mapError((error) => error.reason.method === "chmod"
|
|
317
|
+
? mutationError("command_failed", `Could not preserve the mode of ${destination} before replacement by chmod`, destination)
|
|
318
|
+
: mutationFailure("command_failed", `Failed to write file ${destination}`, destination)(error)));
|
|
319
|
+
modified.push(destination);
|
|
320
|
+
if (moves.has(hunk)) {
|
|
321
|
+
yield* fileSystem.remove(hunk.path).pipe(Effect.mapError(mutationFailure("command_failed", `Failed to remove original ${hunk.path}`, hunk.path)));
|
|
322
|
+
}
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}));
|
|
328
|
+
// Publish diagnostics only after the whole provider operation succeeds.
|
|
329
|
+
for (const change of changes) {
|
|
330
|
+
if (change.content === null)
|
|
331
|
+
yield* Diagnostics.close(path.resolve(change.path));
|
|
332
|
+
else
|
|
333
|
+
yield* Diagnostics.sync(path.resolve(change.path), decoder.decode(change.content));
|
|
334
|
+
}
|
|
335
|
+
const summary = {
|
|
336
|
+
added: parsed.hunks.filter((hunk) => hunk.kind === "add").map((hunk) => hunk.path),
|
|
337
|
+
deleted: parsed.hunks.filter((hunk) => hunk.kind === "delete").map((hunk) => hunk.path),
|
|
338
|
+
modified: parsed.hunks.filter((hunk) => hunk.kind === "update").map((hunk) => hunk.movePath ?? hunk.path)
|
|
339
|
+
};
|
|
340
|
+
return {
|
|
341
|
+
output: ApplyPatchText.printSummary(summary),
|
|
342
|
+
...summary
|
|
343
|
+
};
|
|
344
|
+
}));
|
|
345
|
+
});
|
|
346
|
+
//# sourceMapping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,IAAI,CAAC;YACvF,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC;SAC1G,CAAA;QAED,OAAO;YACL,MAAM,EAAE,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5C,GAAG,OAAO;SACX,CAAA;IACH,CAAC,CAAC,CAAC,CAAA;AACL,CAAC,CAAC,CAAA","sourcesContent":["/**\n * apply_patch flow declaration and portable handler.\n *\n * A Codex CLI clone: the V4A patch grammar (`*** Begin Patch` /\n * `*** Add File:` / `*** Update File:` / `*** Delete File:` /\n * `*** End Patch`), the fuzzy context-matching applier, and Codex's error\n * and summary text, expressed as a flow over the kernel filesystem.\n *\n * @since 1.0.0\n */\n\nimport * as Path from \"@smthrs/kernel/Path\"\nimport * as Effect from \"effect/Effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport type * as PlatformError from \"effect/PlatformError\"\nimport * as Schema from \"effect/Schema\"\nimport * as ApplyPatchText from \"./internal/ApplyPatch.ts\"\nimport { capability, envelope } from \"./internal/Declaration.ts\"\nimport * as Diagnostics from \"./internal/Diagnostics.ts\"\nimport * as FileMutation from \"./internal/FileMutation.ts\"\nimport * as FsFailure from \"./internal/FsFailure.ts\"\nimport * as Preserve from \"./internal/Preserve.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * Registry name for the apply_patch flow. Matches the Codex CLI tool name.\n *\n * @category identifiers\n * @since 1.0.0\n */\nexport const name = \"apply_patch\"\n\n/**\n * Model-facing description of the apply_patch flow. Matches the Codex CLI\n * freeform tool description.\n *\n * @category descriptions\n * @since 1.0.0\n */\nexport const description =\n \"The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.\"\n\n/**\n * Input schema for the apply_patch flow.\n *\n * Codex delivers the patch as freeform text; the JSON function fallback uses\n * a single `input` field, which is the shape cloned here.\n *\n * @category schemas\n * @since 1.0.0\n */\nexport const Input = Schema.Struct({\n input: Schema.String.annotate({ description: \"The entire contents of the apply_patch command\" })\n})\n\n/**\n * Decoded input accepted by the `apply_patch` flow.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Input = typeof Input.Type\n\n/**\n * Output schema for the apply_patch flow.\n *\n * @category schemas\n * @since 1.0.0\n */\nexport const Output = Schema.Struct({\n output: Schema.String.annotate({\n description: \"Codex-style summary: 'Success. Updated the following files:' with A/M/D lines\"\n }),\n added: Schema.Array(Schema.String).annotate({ description: \"Paths of files created by the patch\" }),\n modified: Schema.Array(Schema.String).annotate({ description: \"Paths of files updated by the patch\" }),\n deleted: Schema.Array(Schema.String).annotate({ description: \"Paths of files deleted by the patch\" })\n})\n\n/**\n * Decoded output returned by the `apply_patch` flow.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Output = typeof Output.Type\n\n/**\n * Static conservative effect envelope for the apply_patch flow.\n *\n * @category effects\n * @since 1.0.0\n */\nexport const effects = envelope({ tier: \"compensable\", mode: \"hermetic\", reads: [\"/**\"], writes: [\"/**\"] })\n\n/**\n * Narrows the effect envelope for a decoded invocation.\n *\n * A patch names its files inside its own text rather than in a decoded field,\n * and the parse that finds them is the same parse that can fail, so there is\n * nothing here to narrow before the handler runs: the static envelope is the\n * honest answer.\n *\n * @category effects\n * @since 1.0.0\n */\nexport const effectsFor = (_input: typeof Input.Type) => effects\n\n/**\n * Capabilities required by the apply_patch flow.\n *\n * @category capabilities\n * @since 1.0.0\n */\nexport const capabilities = [capability(\"fs:read\", \"/**\"), capability(\"fs:write\", \"/**\")]\n\n/**\n * Declaration-only apply_patch flow.\n *\n * @category flows\n * @since 1.0.0\n */\nexport const flow = { name, description, input: Input, output: Output, capabilities, effects } as const\n\n/**\n * What a call to this flow does, for a reader of a run.\n *\n * Display metadata only. `@smthrs/registry` `Descriptor.FlowActivity` is the\n * governing vocabulary and `StandardFlows` binds this value onto the flow's\n * descriptor, where the binding site checks it. `declarationDigest` excludes\n * it, so declaring it cannot invalidate a call identity or a cached prompt.\n *\n * @category presentation\n * @since 1.0.0-rc.0\n */\nexport const activity = \"writes\" as const\n\n/**\n * How one recorded call to this flow reads: the verb for each settlement, the\n * input field that is its subject, and the measured output fields a one-line\n * summary may count.\n *\n * Display metadata only, governed by `@smthrs/registry`\n * `Descriptor.CallPresentation` and checked where `StandardFlows` binds it.\n *\n * @category presentation\n * @since 1.0.0-rc.0\n */\nexport const presentation = {\n verb: { pending: \"patching\", success: \"patched\", failure: \"failed to patch\" },\n subject: \"patch\",\n result: \"patch\"\n} as const\n\n/**\n * Every path a patch writes, in the order it names them, including a move's\n * destination. The patch is read by the parser {@link run} uses, so a header\n * `run` accepts is never missed.\n *\n * Returns `undefined` when `run` would refuse the patch. A caller asking\n * permission for the call then asks for everything the flow declares.\n *\n * @category parsing\n * @since 1.0.0-rc.1\n */\nexport const paths = (patch: string): ReadonlyArray<string> | undefined => {\n let parsed: ApplyPatchText.ParsedPatch\n try {\n parsed = ApplyPatchText.parsePatch(patch)\n } catch {\n return undefined\n }\n return [\n ...new Set(\n parsed.hunks.flatMap((hunk) =>\n hunk.kind === \"update\" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]\n )\n )\n ]\n}\n\n/**\n * The one sentence a model sees for a failure this handler did not design.\n * The raw failure goes to the log, never into the tool result.\n */\nconst unknownFailureSentence = \"Something went wrong on our side. Not your fault.\"\n\nconst unknownFailure = (error: unknown, path?: string): Effect.Effect<never, StdError.StdError> =>\n Effect.logError(\"apply_patch failed unexpectedly\", error).pipe(\n Effect.andThen(Effect.fail(\n new StdError.StdError(\n path === undefined\n ? { code: \"command_failed\", message: unknownFailureSentence }\n : { code: \"command_failed\", message: unknownFailureSentence, path }\n )\n ))\n )\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true })\n\n/**\n * Parses and applies a V4A patch through the permission-aware kernel\n * filesystem, preserving Codex error text.\n *\n * @category handlers\n * @since 1.0.0\n */\nexport const run = Effect.fn(\"ApplyPatch.run\")(function*(\n input: typeof Input.Type\n): Effect.fn.Return<typeof Output.Type, StdError.StdError, FileSystem.FileSystem | Path.Path> {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n\n let parsed: ApplyPatchText.ParsedPatch\n try {\n parsed = ApplyPatchText.parsePatch(input.input)\n } catch (error) {\n if (error instanceof ApplyPatchText.ParseError) {\n return yield* Effect.fail(new StdError.StdError({ code: \"invalid_input\", message: error.message }))\n }\n return yield* unknownFailure(error)\n }\n\n // Every update hunk is derived from the file as it is on disk, so two\n // sections naming one path both start from the same original and the second\n // write erases the first — while the summary reports two modifications.\n // The preflight cannot honestly validate the second section against a file\n // the first has not written yet, so the patch is refused whole rather than\n // applied by halves. A file needing several edits carries several `@@`\n // chunks inside one section, which is the shape the parser already accepts.\n // Resolve against the injected workspace, then follow existing filesystem\n // aliases. For a new file, resolve its parent (which may be a symlink).\n const identity = (value: string) => {\n const resolved = path.resolve(value)\n return fileSystem.realPath(resolved).pipe(\n Effect.catch((error) =>\n error.reason._tag === \"NotFound\"\n ? fileSystem.realPath(path.dirname(resolved)).pipe(\n Effect.map((parent) => path.resolve(parent, path.basename(resolved))),\n Effect.catch((parentError) =>\n parentError.reason._tag === \"NotFound\"\n ? Effect.succeed(resolved)\n : Effect.fail(parentError)\n )\n )\n : Effect.fail(error)\n ),\n Effect.mapError(FsFailure.denied(value, () =>\n new StdError.StdError({\n code: \"command_failed\",\n message: `Failed to resolve patch path ${value}`,\n path: value\n })))\n )\n }\n const touched = new Set<string>()\n for (const hunk of parsed.hunks) {\n const source = yield* identity(hunk.path)\n const destination = hunk.kind === \"update\" && hunk.movePath !== undefined\n ? yield* identity(hunk.movePath)\n : undefined\n const claims: Array<[string, string]> = [[hunk.path, source]]\n if (hunk.kind === \"update\" && hunk.movePath !== undefined && destination !== source) {\n claims.push([hunk.movePath, destination!])\n }\n for (const [claimed, key] of claims) {\n if (touched.has(key)) {\n return yield* Effect.fail(\n new StdError.StdError({\n code: \"invalid_input\",\n message: `The patch names ${claimed} in more than one section; give one section per path`,\n path: claimed\n })\n )\n }\n touched.add(key)\n }\n }\n\n yield* FileMutation.validate(\n fileSystem,\n parsed.hunks.flatMap((hunk) =>\n hunk.kind === \"update\" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]\n )\n )\n\n // Create only parents the patch already intends to create, before taking\n // stable sibling locks for new destinations as well as existing sources.\n for (const hunk of parsed.hunks) {\n const destination = hunk.kind === \"add\" ? hunk.path : hunk.kind === \"update\" ? hunk.movePath : undefined\n if (destination !== undefined && !FileMutation.isVersioned(fileSystem)) {\n yield* fileSystem.makeDirectory(path.dirname(destination), { recursive: true }).pipe(\n Effect.mapError(\n FsFailure.denied(destination, () =>\n new StdError.StdError({\n code: \"command_failed\",\n message: `Failed to create parent directories for ${destination}`,\n path: destination\n }))\n )\n )\n }\n }\n return yield* Effect.scoped(Effect.gen(function*() {\n const mutation = yield* FileMutation.acquire(\n fileSystem,\n parsed.hunks.flatMap((hunk) =>\n hunk.kind === \"update\" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]\n ),\n path\n )\n const added: Array<string> = []\n const modified: Array<string> = []\n const deleted: Array<string> = []\n const prepared = new Map<ApplyPatchText.Hunk, string>()\n\n for (const hunk of parsed.hunks) {\n if (hunk.kind !== \"update\") continue\n const bytes = yield* mutation.read(\n hunk.path,\n fileSystem.readFile(hunk.path).pipe(\n Effect.mapError(FsFailure.reading(hunk.path, `Failed to read file to update ${hunk.path}`))\n )\n )\n if (bytes.includes(0)) {\n return yield* Effect.fail(\n new StdError.StdError({\n code: \"binary_file\",\n message: `Cannot read binary file: ${hunk.path}`,\n path: hunk.path\n })\n )\n }\n const original = yield* Effect.try({\n try: () => decoder.decode(bytes),\n catch: () =>\n new StdError.StdError({\n code: \"binary_file\",\n message: `File is not valid UTF-8: ${hunk.path}`,\n path: hunk.path\n })\n })\n let contents: string\n try {\n contents = ApplyPatchText.deriveNewContents(original, hunk.path, hunk.chunks)\n } catch (error) {\n if (error instanceof ApplyPatchText.ComputeReplacementsError) {\n return yield* Effect.fail(\n new StdError.StdError({ code: \"no_match\", message: error.message, path: hunk.path })\n )\n }\n return yield* unknownFailure(error, hunk.path)\n }\n prepared.set(hunk, contents)\n }\n\n // Prepare one complete provider request before touching any file. A move\n // carries both its destination write and source removal in the same commit.\n const changes: Array<FileMutation.Change> = []\n const moves = new Set<ApplyPatchText.Hunk>()\n for (const hunk of parsed.hunks) {\n if (hunk.kind === \"delete\") {\n changes.push({ path: hunk.path, content: null })\n } else if (hunk.kind === \"add\") {\n changes.push({ path: hunk.path, content: encoder.encode(hunk.contents) })\n } else {\n changes.push({\n path: hunk.movePath ?? hunk.path,\n content: encoder.encode(prepared.get(hunk))\n })\n if (hunk.movePath !== undefined && (yield* identity(hunk.movePath)) !== (yield* identity(hunk.path))) {\n moves.add(hunk)\n changes.push({ path: hunk.path, content: null })\n }\n }\n }\n\n // A denial names itself, so the model does not retry a write the host refuses.\n const mutationFailure =\n (code: StdError.Code, message: string, offendingPath: string) =>\n (error: PlatformError.PlatformError): StdError.StdError =>\n error.reason._tag === \"PermissionDenied\"\n ? mutationError(\"permission_denied\", `Permission denied: ${offendingPath}`, offendingPath)\n : mutationError(code, message, offendingPath)\n const mutationError = (code: StdError.Code, message: string, offendingPath: string): StdError.StdError =>\n new StdError.StdError({\n code,\n message: `${message}; applied before failure: added=${JSON.stringify(added)}, modified=${\n JSON.stringify(modified)\n }, deleted=${JSON.stringify(deleted)}`,\n path: offendingPath\n })\n\n yield* mutation.commit(\n changes,\n Effect.gen(function*() {\n for (const hunk of parsed.hunks) {\n switch (hunk.kind) {\n case \"add\": {\n yield* fileSystem.writeFile(hunk.path, encoder.encode(hunk.contents)).pipe(\n Effect.mapError(mutationFailure(\"command_failed\", `Failed to write file ${hunk.path}`, hunk.path))\n )\n added.push(hunk.path)\n break\n }\n case \"delete\": {\n yield* fileSystem.remove(hunk.path).pipe(\n Effect.mapError(mutationFailure(\"not_found\", `Failed to delete file ${hunk.path}`, hunk.path))\n )\n deleted.push(hunk.path)\n break\n }\n case \"update\": {\n const contents = prepared.get(hunk)!\n const destination = hunk.movePath ?? hunk.path\n yield* Preserve.writeFile(fileSystem, destination, encoder.encode(contents)).pipe(\n Effect.mapError((error) =>\n error.reason.method === \"chmod\"\n ? mutationError(\n \"command_failed\",\n `Could not preserve the mode of ${destination} before replacement by chmod`,\n destination\n )\n : mutationFailure(\"command_failed\", `Failed to write file ${destination}`, destination)(error)\n )\n )\n modified.push(destination)\n if (moves.has(hunk)) {\n yield* fileSystem.remove(hunk.path).pipe(\n Effect.mapError(\n mutationFailure(\"command_failed\", `Failed to remove original ${hunk.path}`, hunk.path)\n )\n )\n }\n break\n }\n }\n }\n })\n )\n\n // Publish diagnostics only after the whole provider operation succeeds.\n for (const change of changes) {\n if (change.content === null) yield* Diagnostics.close(path.resolve(change.path))\n else yield* Diagnostics.sync(path.resolve(change.path), decoder.decode(change.content))\n }\n const summary = {\n added: parsed.hunks.filter((hunk) => hunk.kind === \"add\").map((hunk) => hunk.path),\n deleted: parsed.hunks.filter((hunk) => hunk.kind === \"delete\").map((hunk) => hunk.path),\n modified: parsed.hunks.filter((hunk) => hunk.kind === \"update\").map((hunk) => hunk.movePath ?? hunk.path)\n }\n\n return {\n output: ApplyPatchText.printSummary(summary),\n ...summary\n }\n }))\n})\n"]}
|