feat(workspaces): workspaces.py makes, lists and cleans up the jj workspaces of the repositories beside it #16

Merged
HumanBean merged 1 commit from HumanBean/Tooling:feat/workspaces into main 2026-11-16 07:47:51 +00:00
Owner

Agents on a shared PC each work in a jj workspace of their own, and nothing ever removes them: on one PC there are 340 across the team's repositories, many on commits already merged and some whose folders are long gone, each with its builds. This adds a way to make, list and clean them up, safe enough for an agent to run.

What changed

scripts/workspaces.py (standard library; uses jj), for the jj repositories beside Tooling that have a remote on git.magicbean.dev, plus any folders named in ~/.config/longshot/workspaces.json:

  • new REPO NAME [-r REV]: a workspace at <checkouts>/<REPO>-<NAME> on trunk() after a fetch. It refuses a folder on a RAM file system.
  • list [--all] [--json]: for each workspace, what it holds that main lacks, how long it has been idle, and what clean would do with it.
  • clean [--auto | --dry-run], with three tiers:
    • keep: the repository's own checkout; a workspace a process runs in; one a Claude Code session of the last 24 h worked in (its cwd, a file it edited, a cd, jj -R or git -C there; a session that went through more than 8 workspaces is a sweep and doesn't count); one touched in the last 24 h.
    • safe: its folder is gone, or it holds nothing main lacks (no commits of its own, or only ones whose files now match main, as after a squash merge) and has been idle 3 days. --auto removes these and nothing else.
    • ask: its own work idle 7 days, or a folder a forgotten workspace left behind. In a terminal it asks about each one; without a terminal it removes nothing but the safe ones under --auto.
  • remove REPO:NAME ...: the ones the person named, for an agent after asking. --force is needed for one that looks in use; the repository's own checkout is never removed.
  • A removal first snapshots the workspace (so an edit jj hadn't seen goes into its commit), then forgets it, deletes the folder and prunes git's worktrees. Its commits stay in the repository; only ignored files (builds) go.
  • AGENTS.md: a Workspaces section (one of your own for every change; clean --auto any time; anything else is the person's to remove), and an Always rule: nothing big on a RAM file system (/tmp is often one). README lists the script.

On this PC, list takes about 7 s for 342 workspaces in 10 repositories: 47 are safe because they hold nothing main lacks, 15 are workspaces whose folders are gone (mostly agents' scratch folders in /tmp), and the rest are kept or recent. Nothing was removed here except the test workspaces below.

How it was tested

  • New tests/test_workspaces.py, offline:
    • each tier rule;
    • that an in-use workspace and the repository's own checkout are refused;
    • the RAM check by the longest mount;
    • a session's work told apart from a listing, a sweep and an old transcript;
    • with jj installed, a real repository in a temporary folder: a workspace made, a file written without a snapshot, the workspace removed, and the edit found in a commit that stays.
  • python -I -B tests/run_all.py: 4 of 5 files pass. The failure is test_forge_pr.py's test_create_draft_is_the_default_and_wip_is_not_doubled, which fails on main too (see #11 and #14).
  • By hand: new Tooling wstest, an unsnapshotted edit, then remove Tooling:wstest. The folder is gone, the workspace is forgotten, and the edit is in a commit (abandoned afterwards).

A companion Longshot PR (the job queue and dev_build.py) says the same about RAM file systems for builds.

🤖 Generated with Claude Code

Agents on a shared PC each work in a jj workspace of their own, and nothing ever removes them: on one PC there are 340 across the team's repositories, many on commits already merged and some whose folders are long gone, each with its builds. This adds a way to make, list and clean them up, safe enough for an agent to run. ## What changed `scripts/workspaces.py` (standard library; uses `jj`), for the jj repositories beside Tooling that have a remote on git.magicbean.dev, plus any folders named in `~/.config/longshot/workspaces.json`: - **`new REPO NAME [-r REV]`**: a workspace at `<checkouts>/<REPO>-<NAME>` on `trunk()` after a fetch. It refuses a folder on a RAM file system. - **`list [--all] [--json]`**: for each workspace, what it holds that main lacks, how long it has been idle, and what `clean` would do with it. - **`clean [--auto | --dry-run]`**, with three tiers: - **keep**: the repository's own checkout; a workspace a process runs in; one a Claude Code session of the last 24 h worked in (its cwd, a file it edited, a `cd`, `jj -R` or `git -C` there; a session that went through more than 8 workspaces is a sweep and doesn't count); one touched in the last 24 h. - **safe**: its folder is gone, or it holds nothing main lacks (no commits of its own, or only ones whose files now match main, as after a squash merge) and has been idle 3 days. `--auto` removes these and nothing else. - **ask**: its own work idle 7 days, or a folder a forgotten workspace left behind. In a terminal it asks about each one; without a terminal it removes nothing but the safe ones under `--auto`. - **`remove REPO:NAME ...`**: the ones the person named, for an agent after asking. `--force` is needed for one that looks in use; the repository's own checkout is never removed. - **A removal** first snapshots the workspace (so an edit jj hadn't seen goes into its commit), then forgets it, deletes the folder and prunes git's worktrees. Its commits stay in the repository; only ignored files (builds) go. - **AGENTS.md**: a *Workspaces* section (one of your own for every change; `clean --auto` any time; anything else is the person's to remove), and an *Always* rule: nothing big on a RAM file system (`/tmp` is often one). README lists the script. On this PC, `list` takes about 7 s for 342 workspaces in 10 repositories: 47 are safe because they hold nothing main lacks, 15 are workspaces whose folders are gone (mostly agents' scratch folders in `/tmp`), and the rest are kept or recent. Nothing was removed here except the test workspaces below. ## How it was tested - New `tests/test_workspaces.py`, offline: - each tier rule; - that an in-use workspace and the repository's own checkout are refused; - the RAM check by the longest mount; - a session's work told apart from a listing, a sweep and an old transcript; - with jj installed, a real repository in a temporary folder: a workspace made, a file written without a snapshot, the workspace removed, and the edit found in a commit that stays. - `python -I -B tests/run_all.py`: 4 of 5 files pass. The failure is `test_forge_pr.py`'s `test_create_draft_is_the_default_and_wip_is_not_doubled`, which fails on main too (see #11 and #14). - By hand: `new Tooling wstest`, an unsnapshotted edit, then `remove Tooling:wstest`. The folder is gone, the workspace is forgotten, and the edit is in a commit (abandoned afterwards). A companion Longshot PR (the job queue and `dev_build.py`) says the same about RAM file systems for builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Many agents share one PC, each in a jj workspace of its own, and nothing ever removed them: hundreds pile up beside the
checkouts, with their builds. workspaces.py new makes one on main; list says what each holds that main lacks and how
long it has been idle; clean removes the safe ones by itself (folder gone, or nothing main lacks and idle for days) and
asks about the rest; remove takes the ones the person named. A removal snapshots first, so the commits stay.

AGENTS.md: a workspace of your own for every change, and nothing big on a RAM file system (/tmp is often one).

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
HumanBean changed title from WIP: feat(workspaces): workspaces.py makes, lists and cleans up the jj workspaces of the repositories beside it to feat(workspaces): workspaces.py makes, lists and cleans up the jj workspaces of the repositories beside it 2026-11-16 07:11:58 +00:00
Author
Owner

Rebased on main after #13 (farm-run): both PRs added a row to AGENTS.md's task table and README's file table; both rows kept. tests/test_workspaces.py passes.

Rebased on main after #13 (farm-run): both PRs added a row to AGENTS.md's task table and README's file table; both rows kept. tests/test_workspaces.py passes.
HumanBean force-pushed feat/workspaces from d3e836c239 to 4366425a5d 2026-11-16 07:47:06 +00:00 Compare
HumanBean deleted branch feat/workspaces 2026-11-16 07:47:51 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Tooling!16
No description provided.