feat(sandbox): add edit_file (str_replace) tool for partial edits — scaffold - #1533
feat(sandbox): add edit_file (str_replace) tool for partial edits — scaffold#1533iroiro147 wants to merge 2 commits into
Conversation
Scaffold for vercel#1523. Adds a framework `edit_file` tool that replaces one unique substring with a new one — a lightweight partial-edit primitive that avoids the token cost of regenerating entire files via `write_file`. Behavior: - Reads file, verifies `oldString` appears exactly once, replaces, writes back. - Fails with descriptive error when `oldString` is missing, empty, or matches > 1 position. - Returns `{ path, replacements: 1 }`. Files changed: - `runtime/framework-tools/edit-file.ts` (NEW) — zod input/output schemas, executor, tool definition, unique-substring guarantee via occurrence count. - `runtime/framework-tools/index.ts` — register EDIT_FILE_TOOL_DEFINITION. - `public/tools/defaults.ts` — export `editFile` alongside existing readFile/writeFile. Notes / caveats for reviewers: - Uses only existing sandbox session primitives (`readTextFile`, `writeTextFile`) and `resolveAbsoluteFilePath` — no new deps, no new API surface. - Typecheck not run in this commit's context (no node_modules in this workspace); CI `tsc --noEmit` should be the verification gate. - This PR is a SCAFFOLD: maintainer decisions on (a) maximum diff size, (b) atomicity (read-+write within sandbox exec vs split tools), (c) telemetry/trace surface for edit_file's unique-substring failures, are intentionally deferred to design review. Related: vercel#1523 Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
|
@iroiro147 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
…r patterns Two VADE review findings on PR vercel#1533: 1. edit_file wrote without refreshing the read-file stamp, so a subsequent write_file on the same file spuriously failed with "File has been modified since it was last read". Now refreshes the stamp after a successful write, mirroring executeWriteFileOnSandbox. 2. String.replace(oldString, newString) interpreted $$, $&, $`, $', $n in newString as special replacement patterns, silently corrupting the output. Now passes a replacer function so newString is inserted literally. Signed-off-by: iroiro147 <sarthak.singh@juspay.in>
|
Both VADE findings fixed in a8919ad:
Typecheck still gated on CI (no local node_modules in this worktree). |
|
CI status note: typecheck + lint + test-integration(ubuntu) + test-scenario all green on a8919ad. test-unit and test-integration(windows) fail identically to my other open eve PRs (#1528–#1532) — consistent with fork-scoped CI credentials, not the change (which is contained to packages/eve/src/runtime/framework-tools/). DCO signoff present. Ready for design/impl review when a maintainer gets a chance. |
|
Standing-health check (re-verified against current
Ready for a maintainer shape-review whenever convenient; no action required from contributors. |
What
Scaffold PR for #1523: adds a framework
edit_filetool that performs a single unique substring replacement, avoiding the token cost of full-filewrite_fileregeneration.Changes (139 LOC, 3 files)
runtime/framework-tools/edit-file.ts(NEW, 129 LOC)executeEditFileOnSandboxexecutor with unique-substring guarantee,EDIT_FILE_TOOL_DEFINITIONdefinitionruntime/framework-tools/index.ts(+2)public/tools/defaults.ts(+12)editFilepublic tool surface matching readFile/writeFile patternBehavior
edit_file({filePath, oldString, newString}){path, replacements: 1}Design tradeoffs (intentionally deferred to maintainer review)
SandboxSessionprimitives — no new deps.Verification
npx tsc --noEmitin a dev checkout is the verification gate.Closes #1523 (design-shaped; whether this is THE implementation or a starting point is maintainer call)