Skip to content
Merged
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* text=auto eol=lf
*.png binary
*.jpg binary
*.gif binary
*.ico binary
*.webp binary
2 changes: 2 additions & 0 deletions docs/studio/behaviour/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The data folder was `~/Library/Application Support/dev.falinks.studio/` before p

The hooks are async, so Claude Code never waits for them, and they append whether the app runs or not. Two events that fire within a few milliseconds can land in either order.

`events.lock` beside the log is the log's lock (#811). Every writer of `events.jsonl` holds `events.lock` while it writes: the hook, the answer hook, and the app's own lines (`StudioRename`, `StudioDelete`, `StudioPromptName`, a `SessionEnd` with reason `process_gone`). It takes the lock before it opens the log, and writes its lines in one write, so two writers never interleave their lines. A prune swaps the new log in only while holding it, so a writer always opens the log the last prune left. Readers take no lock, and nothing locks `events.jsonl` itself. A hook waits up to 5 seconds for the lock (a Codex or Cursor line 1 second) and otherwise drops its event to `drops.txt` beside the log; the app and a prune wait up to 60 seconds. The lock file is made on first use, so a data folder from before it needs no step, and its bytes mean nothing: it is never written, read, truncated, replaced or deleted.

The log holds tool inputs and results: commands and their output, errors, exit codes, the text an edit replaced and its hunks, and a written file's content. It leaves out two fields no reader takes (danielrispler/plotkeeper#132): an Edit's or Write's `originalFile`, the whole file before the change, and a Read's file `content`.

It keeps a session's events for 30 days after its last one. At each start, before the replay, the app moves the events of older sessions to `events-archive.jsonl` beside it, and drops the two fields from the lines it keeps; a prune moves lines, so it also removes `studio-state.json`, the state a replay made, which the next start saves again and later starts resume from, replaying only the log's tail. Each session in it keeps its `project`, its project folder (spec #659): the root of the first folder it got, set once and never changed by later events. It has a default, so a previous build reads the file and skips it as an unknown key; a session saved before it existed takes it from its saved folder when the file is read, a task's worktree's main checkout, so it keeps the project it showed. The app never reads the archive, and never deletes it; their turns stay in the card store.
Expand Down
4 changes: 2 additions & 2 deletions docs/studio/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
- `core/tests/blocked_commands.rs`: blocked commands replayed through the core: the command's fields, block order, a subagent's block, needs you until the session moves on (the agent's next call, Daniel's next prompt, a subagent's end, not the turn's end), which blocks count as waiting, and an older log's Allow, Decline, decision and retry.
- `hook/tests/named_roots.rs`: the hook binary in a scratch `HOME` and a temporary repository with a second worktree: the roots a Bash call names and touches, the deepest root on a path boundary, a worktree an earlier command made, a removed worktree's folder (by path or as the event's folder) touching nothing, a new folder in a listed one touching it, a known root not listed again, and a worktree made mid-turn starting from its creation commit;
- `hook/tests/harness_trees.rs`: the hook binary in a scratch `HOME` and a temporary repository fed wave 1's trial lines of a Codex and a Cursor turn and a real OpenCode turn, each recording its worktree's start and end trees, which differ by the file it changed; OpenCode turns whose hooks run at once and out of order, their appends waiting on the log's lock together, each listing their own edit once the core replays the log; a Cursor turn writing in its second workspace root listing the file, a Cursor prompt starting every workspace root but touching only its folder's, a Cursor `Shell` call touching the folder its input names, a Cursor line logged in time while `git` hangs, and a Cursor prompt's trees given up past the budget leaving the worktree's start to the turn's next touch;
- `hook/tests/agents.rs`: the agent a hook entry names stored on the line, and another harness's payload dropped by the Claude entry and recorded once by its own; `hook/tests/names.rs`: every name a user sees says plotkeeper; `hook/tests/prune.rs`: the two heavy fields left out and the ended sessions' archive, each session's lines kept together by its agent's own id;
- `hook/tests/agents.rs`: the agent a hook entry names stored on the line, and another harness's payload dropped by the Claude entry and recorded once by its own; `hook/tests/names.rs`: every name a user sees says plotkeeper; `hook/tests/prune.rs`: the two heavy fields left out and the ended sessions' archive, each session's lines kept together by its agent's own id, and the log's lock, `events.lock` (a line waiting through a swap landing in the new log, a held lock leaving the log readable and an append waiting or giving up, whole lines from threads at once, the lock file made on first use, a prune's tail copy, and no file but the log code naming the log and opening a file to write);
- `server/tests/runner.rs`: the background runner with a fake harness that is a real child process, a shell script run through the real launcher: a run's result, cost, exit and record, denials in a 0 exit, a failed run's prompt, a refused run (no harness, no `checks`), `checks` and `setup` read for each run, one run at a time per project, a run picked up after a restart, a dead run failed live and at a start, Cancel killing the group and removing the folder and refusing a process whose start time differs, Cancel of a run that ends at that moment, the pause on a login or limit failure and Resume, the time limit, the cores, an orphaned folder, a running run a start cannot read left alone, a queued run never started beside a running one, a refusal that removes nothing but a new run's folder, a finished run's stray children stopped, standard input closed and the command's removed variables, a pause told to every project, the page's two commands, and the `claude` command, sandbox block and allow list as built, never run;
- `server/tests/back_a_law.rs`: Back a law end to end against a temporary repository with a bare `origin`, a fake agent run by the real launcher, a fake `srt` that runs its command as it is and a recorded `gh`: the clone of the default branch with no remote, a well-formed run proven and kept with Daniel's repository untouched byte for byte, each rejection (no test patch, a test patch outside its scope, a plant that edits the test or breaks the build, a red run that does not name the new test, a test that fails alone, a law left on trust), Discard, the prompt's text, a missing `srt` copying the prompt, a proof with no home folder or with a settings file that cannot be written rejected before `srt` starts, Dismiss refused while the proof runs, a proof plotkeeper stopped in rejected at the next start, Open draft PR from a temporary worktree (its branch, body and ratify record), a retry after `gh` failed past the push, Daniel's other worktrees left alone, an out-of-date patch, and the new-law variant (the writer's draft, the confirmed sentence alone in the prompt, its proof and PR);
- `server/tests/micro_worlds.rs`: micro-worlds with the real launcher, a fake harness that writes the page and the fake dsh-visual (`tests/fake-dsh-visual/`): a flow's topic, a checked page stored and served with its policy first, a failing page never served, rewritten once and then falling back to the prompt to copy, no run without `microWorlds.dshVisual`, out of date and Rebuild, Dismiss refused while the host check runs, a check plotkeeper stopped in failing with why at the next start, and a folder of its own for each project;
- `server/tests/map_review.rs`: the map text review with the real launcher, a fake harness that records the real `claude` command and answers as a review, and a fake `gh`: the items a PR's map adds or changes and none it removes, a review of Daniel's own PR on the head's files with read-only tools, no `Edit` rule, no setup, no `.git` and no map text in its prompt, no start for another login's PR without the request, verdicts reused by id and hash, a new head cancelling an older head's run, and a failed answer run again on request;
- `server/tests/map_draft.rs`: First map's drafting through the real launcher, a stub `claude` that answers canned JSON and a recorded `gh`, on `studio-test-support`'s repositories: the groups landing in order and each reviewer reading its group alone, a failed group (no JSON, a reviewer that cannot start, a purpose without a verdict, one answered twice) kept apart and retried alone, Redraft this part with its flag, Discard mid-batch and a Discard refused half way, a limit pausing the queues, a restart mid-batch, Accept's Write and its refusals and replace question, Open a draft PR from a temporary worktree, muted, and pressed again after it stopped short, and the pending PR followed merged, closed or open; `server/tests/map_check.rs`: `plotkeeper map check` printing what `system-map check` prints, with its exit codes, and `map scan`;
- `server/tests/install.rs`: `plotkeeper install` and `uninstall` on a temporary home with stand-in `claude`, `agy`, `codex` and `copilot`: every file byte-identical after both, Claude Code's settings file never opened, each harness's hooks naming the data folder's `bin/`, Codex's and Cursor's hook files edited beside the user's own hooks, `~/.zshrc` with only its removed lines kept, and an uninstall that retries only its failed steps; `server/tests/hook_copies.rs`: the hook binaries' copies made, left when equal, replaced by rename when they differ, and kept when a binary is missing; `server/tests/api_key.rs`: the API keys saved, replaced and removed through a key store in memory, never reaching the page or the log; `understanding/tests/http_writer.rs`: the API-key writers against a local fake HTTP server, the request's shape and each error status's failure kind;
- `hook/tests/answer.rs`: the answer hook's contract (Seam 4), including a blocked command's denial returned at once with no decision, a payload on stdin and the studio played by the test in a scratch `HOME`: an answer's `allow` with the questions and each label, a multi-select's joined; an approved plan's `allow` with its input and a rejected one's `deny`; a permission's `allow` or `deny`; each card answer logged as `StudioAnswer`, a terminal one not; for questions, plans and permissions alike, an immediate return with no decision when nobody watches, another session is watched, the studio's pid is dead or its heartbeat old; no decision at the timeout or for "Answer in the terminal"; a wrong nonce or an answer file others may write refused;
- the unit tests of the event log's path and of the turn the shell's `StudioInterrupted` line ends, its own and never a later one (`hook`), of what `scrub` keeps (`studio-core`), of the weekly rates' dates (`understanding`), of the shell's risk-note log lines, which keep no reply and no command, and of a worker's view joining its session's risk notes and asks and of the cards key changing with a second card of a judged command (`server/src/lib.rs`) and of the settings file's reads (`server/src/settings.rs`: the writer, `briefBackfill.hours` and its older name `catchUp.hours`, `prBriefs.model`, Opus unless it says another, `prBriefs.effort`, low unless it names another claude takes or `default`, and a background run's `backgroundRuns`, `checks` and `setup`, its project's own with no default) and of the settings' write: a comment and a trailing comma beside the edited key kept byte for byte, a value replaced, a missing parent inserted, reset removing the key, a text that does not parse or a file that changed refused and left as it was, a missing file created, the file replaced whole with nothing left beside it, and a symbolic link written through and kept. and of the PR briefs (`server/src/prs.rs`: which PRs are ready from the sessions' branches and the repository's open list, a failed lookup keeping what was known; `pr_briefs.rs`: the write once per head, stale on a new head, no lock held across a write, a failed head not retried, what waits for Daniel and what a chapter lights, and which ready PRs the start writes, at most 3, the newest head first within `briefBackfill.hours`; `part_catch_ups.rs`: which fogged part gets a part catch-up and which opens its one PR's chapter, completion clearing the part's fog and completing no brief, a stored catch-up read only for the fog list it covers, and, with a fake writer, a shown map writing at most 8 fogged Core parts' catch-ups oldest fog first and none of the others, a part that is not Core written on click, the catch-up's state carrying the stage as each call starts, a new fog entry rewriting it on the next show and an unchanged one never, and two shows in a row starting one write; `ratify.rs`: the decisions file read and written back whole, what has landed; `fog.rs`: reads and the fog a push after reading files; `history.rs`: a PR's files for the drawer).
- the unit tests of the event log's path and of the turn the shell's `StudioInterrupted` line ends, its own and never a later one (`hook`), of what `scrub` keeps (`studio-core`), of the weekly rates' dates (`understanding`), of the shell's risk-note log lines, which keep no reply and no command, and of a worker's view joining its session's risk notes and asks and of the cards key changing with a second card of a judged command and of the server's own lines waiting for the log's lock, then landing whole (`server/src/lib.rs`) and of the settings file's reads (`server/src/settings.rs`: the writer, `briefBackfill.hours` and its older name `catchUp.hours`, `prBriefs.model`, Opus unless it says another, `prBriefs.effort`, low unless it names another claude takes or `default`, and a background run's `backgroundRuns`, `checks` and `setup`, its project's own with no default) and of the settings' write: a comment and a trailing comma beside the edited key kept byte for byte, a value replaced, a missing parent inserted, reset removing the key, a text that does not parse or a file that changed refused and left as it was, a missing file created, the file replaced whole with nothing left beside it, and a symbolic link written through and kept. and of the PR briefs (`server/src/prs.rs`: which PRs are ready from the sessions' branches and the repository's open list, a failed lookup keeping what was known; `pr_briefs.rs`: the write once per head, stale on a new head, no lock held across a write, a failed head not retried, what waits for Daniel and what a chapter lights, and which ready PRs the start writes, at most 3, the newest head first within `briefBackfill.hours`; `part_catch_ups.rs`: which fogged part gets a part catch-up and which opens its one PR's chapter, completion clearing the part's fog and completing no brief, a stored catch-up read only for the fog list it covers, and, with a fake writer, a shown map writing at most 8 fogged Core parts' catch-ups oldest fog first and none of the others, a part that is not Core written on click, the catch-up's state carrying the stage as each call starts, a new fog entry rewriting it on the next show and an unchanged one never, and two shows in a row starting one write; `ratify.rs`: the decisions file read and written back whole, what has landed; `fog.rs`: reads and the fog a push after reading files; `history.rs`: a PR's files for the drawer).

Each crate's integration tests are one test binary, `it`: its `Cargo.toml` sets `autotests = false`, and `tests/main.rs` declares each `tests/*.rs` file as a module, so a new test file needs a `mod` line there. Helpers the files share live in `tests/common.rs`; the git helpers that `hook`, `understanding` and `workbench` share (an isolated `git`, a one-commit repository, also in a folder the test names, a bare `origin`) and the `LauncherGuard` that `server`'s tests hold to stop the `plotkeeper-run` launchers a test leaves running live in the `studio-test-support` crate (`test-support/`), a dev-dependency that depends on no workspace crate. The fake writers of `understanding/tests` are `Scripted` in its `common.rs`. In `ui/tests/`, `dom.mjs` holds the fake document (`fakeDocument`) and the `invoke` stub (`tauri`).

Expand Down
2 changes: 1 addition & 1 deletion hook/src/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub fn answered_line(payload: &Value, answer: &Value) -> Value {
/// Appends a `StudioAnswer` line to the event log and says whether it got there; the decision stands
/// even if it cannot be logged.
pub fn log_answer(data: &Path, line: &Value) -> bool {
match crate::append(&data.join("events.jsonl"), line, crate::PATIENCE) {
match crate::append(&crate::event_log_in(data), line, crate::PATIENCE) {
Ok(true) => true,
Ok(false) => {
eprintln!("plotkeeper-answer: log the answer: the log stayed locked");
Expand Down
Loading
Loading