feat(provider-utils): add readFile and writeFile plus convenience wrappers to Experimental_Sandbox abstraction#15345
Conversation
…Sandbox abstraction
| /** | ||
| * 1-based inclusive start line. Defaults to 1. | ||
| */ | ||
| startLine?: number; |
There was a problem hiding this comment.
what do we consider a linebreak? presumably \n but we may want an optional linebreak field that allows setting \r or \n or \r\n
There was a problem hiding this comment.
Good point, though I think an option feels a bit too low-level. I implemented a helper in provider-utils instead for extracting lines which detects the line break format used in a file and maintains it.
If this shows to be problematic, we can still considering adding an option.
| * No-op stubs for the file methods on `Experimental_Sandbox`, intended to be | ||
| * spread into test fixtures that only care about `runCommand`. | ||
| */ | ||
| export const mockSandboxFileStubs: Pick< |
There was a problem hiding this comment.
wonder if it's worth moving to provider-utils so providers can use this for testing
There was a problem hiding this comment.
Unsure about this. Do we have other test-only helpers in provider-utils? Either way, we could add this later if there's value.
Background
Experimental_Sandbox(previous: #14949, #15253, #15301) only exposeddescriptionandrunCommand, so tools that needed file I/O had to wrap every read/write in a shell command (cat,tee,echo > …). That is fragile for binary content and impossible to type properly.Summary
Experimental_Sandbox: streamingreadFile/writeFileas the foundation, plusreadBinaryFile/readTextFileandwriteBinaryFile/writeTextFileas convenience wrappers.readTextFile,writeTextFile, etc. This can take inspiration from (or continue with) provider sandbox #15311.LocalSandbox,JustBashSandbox, bothVercelSandboxcopies) to implement the new methods, using streamingreadFile/writeFileas the foundation that the binary and text variants delegate to.Checklist
pnpm changesetin the project root)Future Work
See above: We'll need to add that reduced abstraction surface so that only essential methods have to be implemented by the provider. We can provide a helper function to fill in the convenience wrappers automatically.