feat(runtime,fs): emit FsChanged for in-shell VFS writes - #1
Open
yshaul wants to merge 1 commit into
Open
Conversation
FsChanged was only emitted by the explicit WriteFile protocol command; in-shell writes (echo > f, touch, mkdir, cp, rm, tee, redirections) ran through the executor and emitted just [Exit], despite the protocol doc promising notification when scripts touch the FS. Add a shared, ordered, de-duplicating FsChangeLog to wasmsh-fs, recorded by MemoryFs and EmscriptenFs on every mutating op (write-intent open, write_file, open_write_sink, create_dir, remove_file, remove_dir). The runtime drains it into one FsChanged(path) per distinct path at each event-batch boundary, skipping internal scratch paths (/tmp/_wasmsh_*, /tmp/_proc_subst_*). WriteFile is unified onto the same drain path. Covered E2E-first per ADR-0020: wasmsh-fs unit tests, runtime protocol tests (in-shell writes, dedup, read-only, scratch suppression), and E2E additions for standalone + pyodide-node. Design recorded in ADR-0032. Co-authored-by: Cursor <cursoragent@cursor.com>
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
FsChanged(path)was emitted only by the explicitWriteFileprotocol command. In-shell writes —echo > f,touch,mkdir,cp,rm,tee, redirections — ran through the executor and emitted just[Exit], even though the file was really written (read-back confirms). The protocol doc promised notification "when scripts touch the FS", but the standalone/Pyodide paths didn't deliver it.This adds a single chokepoint at the VFS layer:
wasmsh-fs: newFsChangeLog— anRc<RefCell<…>>-backed, insertion-ordered, de-duplicating set of mutated paths, exposed via a defaultedVfs::change_log()accessor.MemoryFsandEmscriptenFsrecord the path on every mutating op (write-intentopen,write_file,open_write_sink,create_dir,remove_file,remove_dir). TheOpfsFsstub inherits theNonedefault.wasmsh-runtime:drain_fs_change_eventsemits oneFsChanged(path)per distinct path at each event-batch boundary (poll_active_runDone + Yield,finish_idle_signal_exit), placed after I/O/diagnostics and beforeExit. Internal scratch paths (/tmp/_wasmsh_*,/tmp/_proc_subst_*) are suppressed.handle_write_file_commandis unified onto the same drain path.docs/reference/protocol.mdupdated to match; design recorded in ADR-0032 (status: Proposed).Semantics: per-path, de-duplicated per run, first-touch order. Scope note: files written by the in-process Python interpreter go through Emscripten libc directly (not the shell VFS), so they are not reported via
FsChanged.This is purely additive to the event stream — hosts already handling
FsChangedfromWriteFileneed no changes.Test plan
Per ADR-0020 (E2E-first);
FsChangedisn't expressible in the TOML differential oracle (real bash emits no such event).cargo test -p wasmsh-fs— change-log record/dedup/order/read-only unit testscargo test -p wasmsh-runtime— protocol tests: redirect, mkdir/touch/cp/rm per-path, dedup, read-only emits nothing, heredoc scratch suppressedcargo fmt --all,cargo clippy(incl.--features emscripten),cargo check --workspace --all-targetswasmsh-testkitsuite_runner) green — no regressionjust test-e2e-standalone(added cases ine2e/standalone/tests/file-ops.spec.ts) — requireswasm-packbuildjust test-e2e-pyodide-node(added case ine2e/pyodide-node/tests/protocol-parity.test.mjs) — requiresemcc/Pyodide buildMade with Cursor