From 19223a8e9d01da0e197884183f53c290fde7ab37 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 13 Oct 2026 16:14:38 -0700 Subject: [PATCH] feat(workspaces): verify settlement captures before abandoned-work cleanup Clover chose the working JJ change at settlement as the abandonment identity. Capture it immediately for each chat settlement, retain the same capture on repeated events, clear it on resume, and report abandonment only for that exact settlement. Thread IDs live in the per-thread record path; change, commit, and repository operation identities have one home in that capture. A known captured commit with no visible version is eligible only when the current working change is empty and its ancestry has no nonempty commits introduced since the historical visible repository view. This preserves rebases and later work hidden beneath an empty tip. Unknown source/history fails closed. Collection removes capture records with the directory. Atomic settle/unsettle/completion commands bypass the preparation lock so T3 settlement reactions and GC probes cannot deadlock. Verified real JJ rebase, abandonment, new nonempty work, new-work then empty-tip abandonment, idempotence, timestamp mismatch, resume, unknown source, and capture cleanup in the isolated V2/JJ/APFS lifecycle; lock tests and Nix syntax pass. Assisted-by: gpt-6.1-sol --- users/clover/packages/workspaces/README.md | 10 ++- users/clover/packages/workspaces/default.nix | 8 +- .../clover/packages/workspaces/workspaces.mjs | 76 +++++++++++++++++++ .../packages/workspaces/workspaces.test.mjs | 61 +++++++++++++++ 4 files changed, 151 insertions(+), 4 deletions(-) diff --git a/users/clover/packages/workspaces/README.md b/users/clover/packages/workspaces/README.md index d62c27fb7e5528982fde5f9f721c8367b7377993..c84286b29d3d8c50f8c99e8e2ea7974a28fa4756 100644 --- a/users/clover/packages/workspaces/README.md +++ b/users/clover/packages/workspaces/README.md @@ -51,7 +51,15 @@ Settling a chat keeps its workspace directory. Cleanup begins only after every chat using the directory is archived or deleted and no work is running. Archival releases the directory for cleanup; settling does not. Automatic archival uses T3 Code's guarded merge check and retains chats with open, closed, or missing PRs. -An unavailable merge check pauses cleanup. `ws gc --dry-run` never archives chats. +An unavailable completion check pauses cleanup. `ws gc --dry-run` never archives chats. + +When a chat settles, T3 captures that workspace's current JJ change with +`ws settle`; resuming clears its capture with `ws unsettle`. `ws completion` +reports abandonment only for that same settlement, when its captured change has +no visible version, the current working change is empty, and its ancestry has +no nonempty work introduced since the captured repository operation. Rebased +changes, missing captures, and later work—even beneath an empty tip—retain the directory. These atomic +per-thread records bypass the preparation lock and are removed with the workspace. Only registered workspaces under `~/workspaces` are collected. JJ retains snapshotted changes; ignored files are deleted with the directory. Closing T3 diff --git a/users/clover/packages/workspaces/default.nix b/users/clover/packages/workspaces/default.nix index 9b146d3caf1e16f35d57316c4914a3b22c0df9e8..81041db8ffdc3cfc7c41111c66b65d2c47064768 100644 --- a/users/clover/packages/workspaces/default.nix +++ b/users/clover/packages/workspaces/default.nix @@ -14,9 +14,11 @@ pkgs.writeShellApplication { native ]; text = '' - if [[ "''${1-}" == ready-hook ]]; then - exec node ${./workspaces.mjs} "$@" - fi + case "''${1-}" in + ready-hook|settle|unsettle|completion) + exec node ${./workspaces.mjs} "$@" + ;; + esac mkdir -p "$HOME/.local/state/workspaces" workspace_lock="$HOME/.local/state/workspaces/lock" if [[ "''${1-}" == new ]]; then diff --git a/users/clover/packages/workspaces/workspaces.mjs b/users/clover/packages/workspaces/workspaces.mjs index 4f26b979134bca930af356f39a4fa8ebd015c3a7..8a890d35e6a62f7424481b51d46aa83ca06a4bd9 100644 --- a/users/clover/packages/workspaces/workspaces.mjs +++ b/users/clover/packages/workspaces/workspaces.mjs @@ -683,6 +683,81 @@ export async function main(args) { (!fs.existsSync(records) || !fs.readdirSync(records).length) ) return; const config = JSON.parse(fs.readFileSync(configFile)); + if (["settle", "unsettle", "completion"].includes(command)) { + const expectedLength = command === "unsettle" ? 2 : command === "completion" ? 5 : 4; + if ( + !argument || rest.length !== expectedLength || rest[0] !== "--thread-id" || + (command !== "unsettle" && rest[2] !== "--settled-at") || + (command === "completion" && rest[4] !== "--json") + ) { + throw new Error(`Run ws ${command} --thread-id ${ + command === "unsettle" ? "" : " --settled-at