Repository navigation
Description
Problem Statement
Native Windows support is coming (docs/studio/research/windows.md, "Recommended path"), but not yet. A few parts of plotkeeper get harder to change once people use it, because their shape lands on disk or in other people's checkouts. Today they are shaped for macOS and Linux only:
- The event log's lock is the log itself. Every writer opens
events.jsonlfor append and locks that file (hook/src/lib.rs:122-145at8e7faab21), and the prune checks it still holds the same file by(dev, ino)(hook/src/lib.rs:306-310). On Windows a lock on the log blocks the read loop's reads, and a lock on an append-only handle fails. The CI spike of 2026-11-28 showed both: error 33 for a reader while another process held the lock, and "lock acquisition failed" on an append-only handle (run 46141976334, probelock-blocks-reader,lock-append-only).(dev, ino)is Unix-only (std::os::unix::fs::MetadataExt). - Line endings follow the checkout's machine. The repository has no
.gitattributes. On the Windows runner Git for Windows checked out 794 files with CRLF (same run,survey), so frozen samples, fixtures and snapshot texts would differ byte for byte on a Windows checkout. - Tests fake agents with shell scripts. 38
#!/bin/shfakes across 21 files (grep -rc '#!/bin/sh' --include='*.rs' hook server understanding workbench test-support core wayfinder system-mapat8e7faab21), each made executable with Unix permission bits. None of them can run on Windows, and the number grew from 25 to 36 in three days (windows.md, "Foundational changes: now or later"). And the spike found that a barebashstarted from Rust on Windows is WSL's launcher, not Git Bash (windows.md, "CI spike results").
Daniel has no other users yet, so these are cheapest now (windows.md, "Foundational changes: now or later").
Solution
Three changes, none of which changes what plotkeeper does on macOS or Linux:
- The event log gets its own lock file,
events.lockbesideevents.jsonlin the data folder. Every writer of the log, the hook, the answer hook and the server, takes that lock, then opens the log, appends and lets go. The prune holds the same lock while it puts the new log in the old one's place. Nothing locksevents.jsonlitself any more, so a reader never meets a lock, and the same-file check by(dev, ino)goes away: a writer opens the log only after it holds the lock, so it always opens the file the last prune left. - The repository checks out with LF everywhere. A
.gitattributesmarks text files LF on every machine and the images binary. - Tests fake programs with one Rust fake from
test-support, not shell scripts. A test asks for a fake of a name (claude,agy,git, …) in a folder, with what it prints, what it exits with and what it records (its arguments, folder, stdin, environment). The fake is a real executable on every platform. New tests use it, and AGENTS.md says so. The existing fakes move over in their own time.
The research note docs/studio/research/windows.md, with its CI spike results, lands in the repository with the first ticket.
User Stories
- As Daniel, I want the event log never locked itself, so that a future Windows build's read loop can read it while hooks append.
- As Daniel, I want every writer of the log to take one lock file, so that two hooks that fire together still never interleave their lines.
- As Daniel, I want the server's own lines (
StudioRename,StudioDelete,StudioPromptName, aSessionEndwith reasonprocess_gone) to take the same lock as the hooks, so that its lines never interleave with a hook's. - As Daniel, I want the answer hook's lines to take the same lock, so that a card's answer line is written whole.
- As Daniel, I want a prune to hold the lock file while it puts the new log in the old one's place, so that a hook's line waiting for the lock lands in the new log, never in the replaced one.
- As Daniel, I want a hook that waited for the lock through a prune to append to the new log, so that no line is lost to a swap, as today.
- As Daniel, I want the hook to drop an event to
drops.txtwhen the lock never comes within its patience, as today, so that an agent never waits on plotkeeper. - As Daniel, I want Codex's and Cursor's shorter waits for the lock (1 second) kept, so that their hooks still fit inside the time their entries allow.
- As Daniel, I want OpenCode's order kept, the session's record locked until its line is in the log, so that its lines stay in the order the hook took them.
- As Daniel, I want the lock file made on first use, so that a data folder from before this change needs no step.
- As Daniel, I want an old log, archive and state to read as before, so that no history changes.
- As Daniel, I want
plotkeeper uninstallto keep treating the data folder as history, so that the lock file is left with the log like any other file there. - As Daniel, I want the storage doc to name
events.lockand say which writers take it, so that the log's contract is written where its readers look. - As Daniel, I want the lock rule to be a law on the system map with tagged tests, so that a later change that writes the log without the lock fails
npm run check. - As Daniel, I want the same-file check by device and inode gone, so that the hook crate has one Unix-only item fewer for the Windows port.
- As Daniel, I want no change in how long a hook takes in the common case, so that the agents feel the same.
- As a contributor on Windows, I want a checkout with LF line endings, so that the frozen samples and fixtures match their bytes and the tests that read them pass.
- As Daniel, I want images and other binary files marked binary, so that no line-ending rule ever touches them.
- As Daniel, I want the new
.gitattributesto change no file in the index, so that the change is one new file, listed in the system map'signored, and no churn. - As Daniel, I want the files that hold no line end (single-line JSON samples) left as they are, so that their bytes stay the same.
- As a test author, I want one call that makes a fake program of a given name in a folder, so that I stop writing shell scripts and setting permission bits by hand.
- As a test author, I want to say what the fake prints on stdout and stderr and what it exits with, so that I can fake an agent's success, its failure and its "not logged in".
- As a test author, I want the fake to record its arguments, its folder, its stdin and its environment to a file I can read, so that I can assert how the code under test called it.
- As a test author, I want to change what a fake does between two calls, so that a test can fake a first failure and a later success, as
server/tests/writer.rsdoes today. - As a test author, I want the fake to be able to wait before it exits, so that tests of deadlines and kills still have a slow program to stop.
- As a test author, I want the fake to need no shell, Python or Node, so that it runs the same on macOS, Linux and Windows.
- As a test author, I want the fake's file named as the platform expects (
claudeon Unix,claude.exeon Windows), so that the code under test finds it as it would find the real program. - As Daniel, I want AGENTS.md "Tests" to say new fakes use the Rust fake and never a
#!/bin/shscript or a barebash/sh, so that the debt stops growing while the old fakes wait for their port. - As Daniel, I want at least one existing shell fake moved to the Rust fake in this spec, so that the fake is proven against a real test before others copy it.
- As Daniel, I want the fake's own behaviour tested in
test-support, so that a test that uses it can trust what it records. - As Daniel, I want the research note and its spike results in the repository, so that this spec and the later Windows spec cite a durable source.
Implementation Decisions
The event log's lock.
- The hook crate owns the lock, as it owns the log's name and path today. Its public log API keeps its shape for callers: append a line with a patience, get the log open under the lock for a write, prune. The value it hands back for a write holds both the lock and the open log, and lets both go when dropped.
- The lock file is
events.lockin the data folder, besideevents.jsonl. It is opened for read and write and created if missing, and locked exclusively with std's file lock, the same lock call as today on a different file. The lock file is never written, read, truncated, replaced or deleted. Its bytes mean nothing. - A writer takes the lock first and opens the log for append after. Since the prune replaces the log only while it holds the lock, a writer that holds the lock always opens the current log, so the loop that re-opened a replaced log and the
(dev, ino)comparison both go. - The prune reads the log and writes
events.jsonl.nextwithout the lock, as today, then takes the lock (60 seconds of patience, as today), copies the tail hooks appended meanwhile, removes the state file, renames the new log into place, and lets the lock go. Its check that the log was not replaced during the prune, by comparing the file it read with the one it holds, becomes a check that the log's length did not shrink below the bytes it read. Only another prune can replace the log, and only one plotkeeper runs at a time (the data folder's lock,server/src/lock.rs). - The waits stay as they are: 5 seconds for a hook, 1 second for Codex and Cursor lines, 60 seconds for the server and the prune.
- OpenCode's order stays: the hook takes the session record's lock, then the log's lock, as today.
- An upgrade needs no step: the hook copies in
bin/are refreshed at each start (docs/studio/plugin.md, the start), so after a restart every writer takesevents.lock. A hook process already running from an old copy during that restart locks the old way for one event. Two such writers no longer exclude each other, but each still writes its line in onewriteto a file opened for append. The window is one restart, and Daniel is the only user (windows.md, "Foundational changes: now or later"). - The storage doc (
docs/studio/behaviour/storage.md) addsevents.lockto the data folder's files and states the rule: every writer ofevents.jsonlholdsevents.lockwhile it writes, a prune swaps the log only while holding it, and readers take no lock. - A new law on the system map,
log-writers-hold-the-log-lock,on: "hook",backing: "check": "Every line written to the event log is written whole, underevents.lock; a prune replaces the log only while holding it, and no reader takes it." The tests below carry@law: log-writers-hold-the-log-lock. Sincesystem-map checkonly sees that a tagged test exists, one of them is a source scan, asno_git_or_gh_is_built_outside_the_runner(workbench/tests/run.rs:321) is for the runner's law: it fails when a shipped Rust file other than the hook crate's log code names the event log (events.jsonlorEVENT_LOG) and opens a file to write (OpenOptions,File::create,fs::write). So a later writer that skips the lock failsnpm run check.
Line endings.
.gitattributesat the root:* text=auto eol=lf, and the image types the repository holds (*.png, plus*.jpg,*.gif,*.ico,*.webp) markedbinary. Every text file in the index is already LF (git ls-files --eolat8e7faab21: 789i/lf, 6i/-textimages, 3i/nonesingle-line files, 2 empty;git ls-files --eol | awk '{print $1}' | sort | uniq -c), so the change renormalises nothing..gitattributesjoins the root files insystem-map.json'signoredlist, orsystem-map checkfails on a file no part owns.- No per-file exceptions. A file that must keep CRLF (none today) would get its own line later.
The Rust fake.
- The fake lives in
test-support, which the tests ofhook,understanding,workbench,system-mapandserveralready use (theirCargo.tomldev-dependencies);coreandwayfinderhold no shell fake and do not take it on. A test calls one function with a folder, a name and a behaviour, and gets back the fake's path. The behaviour says what to print on stdout and stderr, the exit code, an optional wait before exiting, and whether to record the call. A test can rewrite the behaviour between calls. - The fake is the test's own executable, started under another name.
test-supportplaces a hard link to the running test binary at<folder>/<name>, with.exeon Windows, or a copy where a hard link cannot be made (another filesystem, such as atmpfstemp folder), and writes the behaviour beside it. A symbolic link will not do: on Linux the process's own path then reads as the test binary's, not the fake's. Code that runs before the test harness's ownmainchecks whether the process was started as a fake, by looking for a behaviour file beside its own path (std::env::current_exe), and if so acts out the behaviour and exits without starting the harness. This needs no shell, no second build step and no tool beyond Rust, so it runs the same on all three platforms. - What a fake records goes to a JSON file beside it, one entry per call: the arguments, the working folder, stdin, and the environment.
- The code that runs before
mainis thectorcrate's attribute, a dependency oftest-support, which is itself only ever a dev-dependency, so nothing shipped carries it. workbench/tests/run.rs'sfake(it prints its arguments, folder, environment and stdin, the richest of the existing fakes) moves to the Rust fake in this spec. Its tests check the same facts, read from the fake's record instead of its printed lines (workbench/tests/run.rs:64-71). The other 37 stay until the Windows port moves them.- AGENTS.md "Tests" gains one rule: a test that needs a fake program uses
test-support's fake, never a#!/bin/shscript, and no code or test startsshorbashby bare name (on Windows a barebashfrom Rust is WSL's launcher:windows.md, "CI spike results").
The research note. docs/studio/research/windows.md lands with the first ticket's PR (#813), as cross-platform.md landed with #712.
Made without Daniel.
- Q1: The lock is a separate file, not a lock on a byte range of the log past its end. Set aside: a range lock (
LockFileExwith an offset) needswindows-sysand has no std counterpart. Why: the spike showed a separate file works on both Windows images (lock-file-beside-log), and std's lock covers it. - Q2: An upgrade's in-flight old hook is not handled. Set aside: writers taking both locks for a release. Why: one event in one restart, a single user, and appends that are still one write.
- Q3: The prune's "replaced during the prune" check becomes a length check. Set aside: keeping
(dev, ino)on Unix only. Why: it is the Unix-only item the port must remove anyway, and only a second prune could replace the log, which the data folder's lock already prevents. - Q4: The fake is the test binary re-run under another name (
ctor). Set aside: a separate fake binary built by a nestedcargo buildat test time (slow under nextest's one process per test, and it contends for cargo's lock), and a bin in each package (four extra shipped binaries). Why: no build step, nothing new shipped. - Q5: Only one existing fake moves now. Set aside: moving all 38 (the Windows port's job, about a day:
windows.md, slice list). Why: the rule stops new ones, and one move proves the fake. - Q6: Claude Code's exec form is not in this spec. Set aside: exec form on every platform now. Why: Claude Code before 2.1.139 drops
argsand runscommandthrough a shell, and the unquoted macOS hook path holds a space, so recording would stop with no error (windows.md, "Claude Code's exec form and older versions"). Exec form goes into the Windows spec, for Windows only.
Testing Decisions
A good test here drives the public seam and checks what a user or another process sees: the lines in events.jsonl, the files in the data folder, what a fake recorded. None asserts how the lock is taken inside.
- The log's lock is tested through the hook crate's public log API, in
hook/tests/prune.rs, which already tests the prune and the wait through a swap. Cases, extending its table where it has one:- A line waiting for the lock through a prune lands in the new log (the existing
a_line_waiting_for_the_lock_lands_in_the_log_that_replaced_it,hook/tests/prune.rs:175, rewritten to holdevents.lockrather than the log). - While another holder has
events.lock, the log still opens and reads whole, and an append waits and then lands after it lets go. - Many appends from threads at once give whole lines, none interleaved, in a log that ends with a newline.
- An append with a patience shorter than the holder's hold gives
falseand writes nothing. - A data folder with no
events.lockgets one on the first append, and an existing log keeps its lines. - A prune's tail copy keeps the lines appended between its read and its swap.
- The source scan of the law (Implementation Decisions).
All carry@law: log-writers-hold-the-log-lock. Three existing tests lockevents.jsonldirectly to hold the hooks back, and move to holdingevents.lock:a_held_lock_gives_a_drops_line_and_no_log_line_once_its_patience_runs_out(hook/tests/deadline.rs:34-38), the Cursor case athook/tests/harness_trees.rs:324-327, and the prune case above. The OpenCode case athook/tests/harness_trees.rs:395, which holds the lock throughstudio_hook::locked, keeps working through the API.
- A line waiting for the lock through a prune lands in the new log (the existing
- The server's lines go through
append_to(server/src/lib.rs:586); one case in an existing server test that writes aStudio…line, holdingevents.lockfrom the test, checks it waits and lands whole. - The Rust fake is tested in
test-support's own tests: a fake prints what it was told, exits with its code, records arguments, folder, stdin and environment, waits when told, and does the second behaviour after a rewrite.workbench/tests/run.rs's tests check the same facts as before, from the record. .gitattributeshas no test. The PR showsgit ls-files --eolbefore and after: every text fileattr/text=auto eol=lf, and no file in the index changed.- No Windows CI job in this spec. These changes are tested on macOS and Linux CI as today; the Windows spec adds the Windows job.
Prior art: hook/tests/prune.rs for the log and the prune, server/tests/hook_copies.rs for the data folder on a temporary home, and test-support's LauncherGuard for a helper of its own with tests.
Out of Scope
- Any Windows build, CI job, package or code path. That is the native core v1 spec (
windows.md, "Recommended path", step 4). - Claude Code's exec-form hooks (Q6), which go to the Windows spec, for Windows only.
- Moving the other 37 shell fakes.
- The run's lock and the session records' locks in
turns/, which the Windows spec takes on with the process runner. - Any change to
plotkeeper's own npm package, itsosfield or its launcher's message on Windows. - Reserving the Windows npm names (
plotkeeper-win32-x64,plotkeeper-win32-arm64) ahead of the build. npm's policy calls a package "squatted if the package has no genuine function" and lets it remove accounts that squat (Dispute Resolution, "Squatting"), and a0.0.0placeholder publish was refused on 2026-11-28 with "Package name triggered spam detection". The names are published with the Windows build. A name taken meanwhile costs only a rename:plotkeeper's ownoptionalDependencieschoose which packages install, so a stranger's package never reaches a user. - The README's Windows and WSL2 lines; the WSL2 result from the spike goes into the README with the Windows spec.
- Versioned
bin/<version>/hook folders, set aside by the research (windows.md, "Foundational changes: now or later").
Further Notes
- Every number above was read at
8e7faab21or in the spike run of 2026-11-28; the run's logs and artifacts expire with GitHub's retention, andwindows.mdholds what they showed. - The second spike round (Codex's hook form, a Job Object killing a real grandchild) belongs to the Windows spec, not this one.
🤖 Generated with Claude Code
Activity
danielrispler commentedon Nov 28, 2026
Scope change, 2026-11-28: the npm placeholders are out of this spec.
Daniel's publish of
plotkeeper-win32-x64@0.0.0was refused:403 Forbidden - PUT https://registry.npmjs.org/plotkeeper-win32-x64 - Package name triggered spam detection. Neither name is published (npm view plotkeeper-win32-x64 versionandnpm view plotkeeper-win32-arm64 versiongive E404).npm's Dispute Resolution policy, "Squatting", rules out a retry or an appeal: "It is against npm's Terms of Use to publish a package … simply for the purposes of reserving it for future use", "Package names are considered squatted if the package has no genuine function", and "Accounts violating the name squatting policy may be removed or renamed without notice." The account at risk publishes
plotkeeperand its platform packages.Daniel's decision: drop the reservation. The Windows packages are published with the Windows build. A name taken meanwhile costs a rename only:
plotkeeper'soptionalDependencieschoose which packages install, so a stranger's package never reaches a user.Changed in the body: the Problem Statement's npm bullet, Solution item 4, user stories 31–33, Implementation Decisions "The npm names", Q7 and the Testing Decisions line are removed; Out of Scope gains the reservation with this reason. No ticket held the npm work (#811, #812 and #813 are unchanged).
docs/studio/research/windows.md, which lands with #813, says the same.Studio: the log lock's review fixes (#805)
Studio: Windows foundations — the event log's own lock file, and LF c…