CLI for numbered jj workspaces side by side: each starts on the megamerge and opens in its own Rex session
Files
README.md

jj-ws #

ws keeps numbered jj workspaces of one repo side by side in a root folder, next to the main workspace, and opens each one in its own Rex session.

~/code/myapp/          root, named after the repo; holds .ws.toml and README.md
├── app.default/       main workspace (the clone), named default in jj
├── app.1/             ws new
└── app.2-fix-login/   ws new -n "fix login"

It is opinionated:

  • jj with the megamerge workflow. main ← empty megamerge commit ← your work. ws init creates the megamerge bookmark if it is missing; every ws new workspace starts on top of it.
  • Rex. ws new creates a Rex session named after the workspace and refuses to run outside Rex. ws rm closes the session, from inside Rex or any other terminal while the Rex server runs.
  • mise, if installed. ws init adds the root to mise's trusted_config_paths. This also allows the workspaces to inherit mise.toml and mise.local.toml from the root.

Requirements #

  • jj 0.32 or newer. Homebrew installs it; the cargo and mise installs don't.
  • Rex 0.1.0-preview.14 or newer, with rex on PATH, for ws new and ws workon. For them to switch the app to the session, turn on Remote Control in Rex's settings; without it they still open the session and say they couldn't switch.

ws checks both before it changes anything and says which one is missing or too old.

Install #

Homebrew (macOS and Linux):

brew tap kloevaa.dk/jj-ws https://tangled.org/kloevaa.dk/jj-ws
brew install kloevaa.dk/jj-ws/jj-ws

mise (prebuilt binary through cargo-binstall):

mise use -g cargo-binstall cargo:jj-ws

mise's cargo backend runs cargo-binstall when it is installed, and cargo-binstall downloads the archive attached to the release tag, so Rust isn't needed; mise's warning that cargo may be required is harmless then. Without cargo-binstall, or for a target with no archive, mise builds with cargo install and needs Rust (mise use -g rust).

cargo-binstall:

cargo binstall jj-ws

From source:

cargo install jj-ws

Shell completions #

Homebrew installs them. Otherwise add one line to your shell's startup file:

# fish: ~/.config/fish/config.fish
COMPLETE=fish ws | source
# bash: ~/.bashrc
source <(COMPLETE=bash ws)
# zsh: ~/.zshrc, after compinit
source <(COMPLETE=zsh ws)

Completions list registered prefixes and removable workspaces. Inside a root they also offer its workspaces without the prefix, so ws rm 1<Tab> lists 1-fix-login, 10 and 11.

Use #

cd ~/code
ws init app https://tangled.org/me/myapp   # clone into ~/code/myapp/app.default, set up megamerge
cd myapp
ws new             # app.1 on megamerge, in a new Rex session
ws new -n "ADLC-55 some important feature"   # app.2-adlc-55-some-important-feature
ws workon default  # open a workspace in Rex, or switch to its session; also N or app.N
ws ls              # workspaces, their Rex session and working-copy change
ws ls --all        # every registered root; also what ws ls shows outside any root
ws rm              # remove the workspace you are in (folder, jj workspace, Rex session)
ws rm app.2        # or name one, from anywhere; app.2-adlc-55-some-important-feature works too

ws new -n NAME appends NAME after the number in lowercase kebab case: each run of characters other than letters and digits becomes one -. NAME is cut to 100 characters, after the last whole word that fits. The number alone still identifies the workspace, so ws workon 2 and ws rm app.2 find app.2-adlc-55-some-important-feature; the Rex session gets the full name.

ws init works out what to do from where you run it:

Run Where Result
ws init P URL [DIR] anywhere Clones URL into DIR/P.default; DIR defaults to the repo's name, as with git clone
ws init P a root folder holding P.default Sets up that root, or does nothing if it already is one
ws init anywhere inside a root The same, with the prefix from the root's .ws.toml
ws init P the top folder of a jj repo Moves the repo to P.default of a root at the repo's old path; cd P.default afterwards to follow it

It refuses to move a repo that has other jj workspaces or git worktrees (they'd lose their links to it), a git repo without jj (run jj git init --colocate first), and anything inside another root. P.default's working copy must be empty so megamerge can go under it; megamerge goes on the local main bookmark, or on trunk() when there is no local main.

Prefixes are unique across registered roots, so PREFIX.default and PREFIX.N name one workspace, and one Rex session, everywhere. Inside a root, commands find the root by walking up from the current folder; elsewhere, pass the prefix.

ws rm snapshots every file in the workspace that isn't ignored into its commit before forgetting it, including new files over jj's size limit, so that work stays in the repo. Ignored files (node_modules, .env) are deleted. ws rm never removes PREFIX.default or any folder holding the repo, and refuses a PREFIX.N folder that isn't a workspace of the repo.

A workspace goes stale when another workspace rewrites its commit, as rebasing megamerge can. ws rm brings a stale workspace up to date before snapshotting it; edits jj hadn't seen yet stay in the repo as a divergent copy of its commit. jj can't add a workspace while PREFIX.default is stale, so ws new first runs jj workspace update-stale there, which updates its files.

Configuration #

<root>/.ws.toml:

prefix = "myapp"
# Typed into the new workspace's shell by ws new, so any syntax your shell takes works.
on_new = "pnpm install"

~/.config/ws/config.toml (or $XDG_CONFIG_HOME/ws/config.toml) lists the roots; ws init adds to it.

Release #

See RELEASING.md.