Skip to content

Commit f348f7a

Browse files
committed
Let the shell change the run's files through the Host
A script can write, append, make a directory, remove, move, and copy: `RunFiles` sends each of these six changes to the Host as a `FileRequest`, and `READ_ONLY` is removed. What the contract has no function for, `RunFiles` answers itself, with no state kept: a fixed mode, a time that is not kept, and no link or named pipe. The tool is marked with `changes_files()`, so the Host runs the `Shell` calls of one reply in the order the reply lists them. - `write_path` refuses a write or an append to a path under `/dev/` with `NO_DEVICE`, on every platform, and sends no request to the Host. The comment beside the refusal cites the bashkit fault on Windows that is its reason: everruns/bashkit#2933 - The refusal covers `write_file` and `append_file` alone. A `mkdir`, a `rename`, or a `copy` to a path under `/dev/` goes to the Host. - `write_path` also refuses more than `RV_MAX_WRITE` bytes, with a sentence that names the limit. The shell does not split a write. - `mkdir` with `recursive` follows a failure for a path that is taken with a `Stat` request, and it succeeds when the path names a directory, because bashkit takes such a request as done. - `chmod` asks the Host what the path names. It succeeds for the mode the shell reports, 644 for a file and 755 for a directory, and it fails with `FIXED_MODE` for another mode. - `io_error` gives `AlreadyExists` and `NotEmpty` cases of their own, with the words `File exists` and `Directory not empty`. - `shell.json` says that the Shell calls of one reply run in order. It also says that no file has an execute bit and that a script runs with `bash script.sh`. - A write makes each absent directory on the way to its file, because the Host does. A real shell fails that write. - `mktemp` makes `/tmp` among the run's files when that directory is absent. - A change whose job was killed before the request went to the Host does not happen. A change of a job that the script kills in the step that sends the request still happens, because bashkit lets go of a killed job when it next polls its jobs. - A script that bashkit stops at its time limit keeps its `&` jobs, and the call ends after the changes of those jobs that are in progress. - No test covers a `cp`, a `mv`, or a `mkdir` to a path under `/dev/`. - No test makes the Host refuse the write of `sed -i` alone. The test of a failed write of `sed -i` uses a file under `/dev/`. - `a_script_that_ended_waits_for_its_changes_in_progress` sleeps 300 ms so that the time limit passes. A limit that fires late lets the writes happen while the script sleeps, so the test cannot fail from timing. Plan: runvil-harness/plan/2026-11-16-1-tool-file-effects.plan.md
1 parent 1c26d04 commit f348f7a

10 files changed

Lines changed: 886 additions & 180 deletions

File tree

‎AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Anything else gets a qualified lowercase name, such as Rust's built-in test harn
2727
- Behavior changes ship with tests in the same change. Preserve behavior tests during refactors.
2828
- The Plugin crate depends on `runvil-plugin-sdk` and outside libraries alone, and writes no `unsafe`. The SDK owns the C boundary.
2929
- The tool's description and parameter schema come from `crates/plugin-bashkit/schemas/shell.json`. `EDITS.md` beside it records every difference from Cursor's definition, and a change to the JSON file changes `EDITS.md` with it.
30-
- The shell reaches files only through `RunFiles` (`crates/plugin-bashkit/src/files.rs`), which hands each read to the tool call that is running, so every read goes through the Host and the run's policy applies to it. No layer of bashkit's sits over it, and bashkit's features that reach the network, the real file system, or another language's interpreter stay off.
31-
- The shell cannot change files in this build: `RunFiles` passes no change on to the Host. A change fails with one fixed reason, and nothing is built around the failure.
30+
- The shell reaches files only through `RunFiles` (`crates/plugin-bashkit/src/files.rs`), which hands each read and each change to the tool call that is running, so every file operation goes through the Host and the run's policy applies to it. No layer of bashkit's sits over it, and bashkit's features that reach the network, the real file system, or another language's interpreter stay off.
31+
- The shell changes files with the six changes the contract has a function for, and the `Shell` tool says that it changes files, so the Host runs the calls of one reply in the order the reply lists them. What bashkit asks beyond the contract, `RunFiles` answers itself and keeps no state to do so: a file has one fixed mode and a directory another, a time is taken and not kept, and no link or named pipe is made.
32+
- A write to a path under `/dev/` is refused on every platform, before it reaches the Host. The reason is a fault in bashkit on Windows, and the comment beside the refusal in `files.rs` cites the issue.
3233
- Each call gets a shell of its own, which the call builds and drops when it ends. A Pack instance holds no shell, so nothing that a call leaves in its shell reaches a later call: a working directory, a variable, or a function. The reason is replay, which answers each call from the record and runs no tool: a run that goes on live after a replay would find none of the state that earlier calls left in a shell.
3334
- bashkit starts a tokio timer for its time limit and for each `sleep`, so its futures are polled only inside the context of the Plugin's tokio runtime. The Plugin instance owns that runtime, whose one thread runs the timers, and dropping the instance joins the thread.
3435
- A Plugin shares its process with the Host, so nothing here installs process-global state, such as a panic hook (`clippy.toml` bans `std::panic::set_hook`), and nothing starts a thread that outlives the Plugin's unload. What every run shares lives in the Plugin instance and never in a `static`, so an unload frees it.

‎crates/plugin-bashkit/schemas/EDITS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
- Removed `IMPORTANT: Use this tool for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files, sleeping) - use the specialized tools for this instead.` The shell runs no external program, so a model told otherwise would call `git` and get an error. In its place a paragraph says what the shell is: a bash interpreter inside the run, with every command built in and no network.
1010
- Removed the bullet that names `Grep`, `Glob`, `Read`, and `rg`, because another Pack offers those tools, and a run may hold this Pack without it.
1111
- Removed the bullet about `head`, `tail`, `sed -n`, and the terminal file, because no output is saved to a file.
12-
- Removed `Run independent commands as parallel Shell calls.`, because the Pack cannot promise that two calls run at the same time: the Host decides when the steps of each call run. `Chain dependent commands with &&.` became `Chain dependent commands with && in one call.`, because each call starts a new shell, so a command finds what another left only when both are in one call.
12+
- Removed `Run independent commands as parallel Shell calls.`, because the Shell calls of one reply do not run in parallel: the tool says that it changes files, so the Host runs each of them by itself, in the order the reply lists them. `Chain dependent commands with &&.` became `Chain dependent commands with && in one call.`, because each call starts a new shell, so a command finds the directory, the variables, and the functions another left only when both are in one call.
1313
- Removed the bullet about the `gh` command, which the shell does not have.
14-
- Added three bullets that state what the shell does: each call starts a new shell at the root of the run's files, and a `cd`, a variable, or a function lasts for that call alone; the shell reads the run's files and cannot change them yet; and output past `{output_cap}` characters is cut in the middle. The placeholder is filled when the definition is built, from the constant the code enforces, so the text and the limit cannot drift apart.
14+
- Added four bullets that state what the shell does: each call starts a new shell at the root of the run's files, and a `cd`, a variable, or a function lasts for that call alone; the Shell calls of one reply run one after another, in the order listed; the shell reads and changes the run's files, and no file has an execute bit, so a script runs with `bash script.sh`; and output past `{output_cap}` characters is cut in the middle. The placeholder is filled when the definition is built, from the constant the code enforces, so the text and the limit cannot drift apart.
1515
- `block_until_ms` is an `integer` of at least 1, where Cursor's is a `number`, because a count of milliseconds is whole and 0 has no meaning here. Cursor's text is `How long to block and wait for the command to complete before moving it to background (in milliseconds). Defaults to 30000ms (30 seconds). Set to 0 to immediately run the command in the background. The timer includes the shell startup time.` This one says the command is stopped at the limit, that the default is `{timeout_ms}`ms, and that a larger value is lowered to that. The placeholder is filled from the constant the code enforces.
1616
- Removed the parameters `notify_on_output`, `request_smart_mode_approval`, and `smart_mode_block_reason`, which belong to Cursor's output monitoring and its approval flow.
1717
- In `working_directory`, `(defaults to current directory)` became `(defaults to the root of the run's files)`, because each call's shell starts at that root, and no earlier call's `cd` moves it.

‎crates/plugin-bashkit/schemas/shell.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"wire_name": "Shell",
3-
"description": "Executes a given command in a bash shell with an optional time limit.\n\nThe shell is a bash interpreter that runs inside the run. Its commands are built in: there are no external programs such as git, npm, or docker, and no network.\n\n- Each call starts a new shell at the root of the run's files. A `cd`, a variable, or a function lasts for that call alone.\n- Chain dependent commands with `&&` in one call.\n- The shell reads the run's files. It cannot change them yet: a command that writes, deletes, or renames a file fails.\n- Output past {output_cap} characters is cut in the middle: the result keeps the start and the end and says so.",
3+
"description": "Executes a given command in a bash shell with an optional time limit.\n\nThe shell is a bash interpreter that runs inside the run. Its commands are built in: there are no external programs such as git, npm, or docker, and no network.\n\n- Each call starts a new shell at the root of the run's files. A `cd`, a variable, or a function lasts for that call alone.\n- Chain dependent commands with `&&` in one call.\n- The Shell calls of one reply run one after another, in the order listed.\n- The shell reads and changes the run's files. No file has an execute bit: run a script with `bash script.sh`.\n- Output past {output_cap} characters is cut in the middle: the result keeps the start and the end and says so.",
44
"parameters": {
55
"type": "object",
66
"properties": {

0 commit comments

Comments
 (0)