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