Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 1 addition & 55 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ jobs:
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
- name: Verify runner architecture and release version
- name: Verify runner architecture
shell: bash
run: |
case "${{ matrix.platform }}" in
Expand All @@ -37,10 +34,6 @@ jobs:
if [[ "${{ matrix.platform }}" == linux-x64 ]]; then
printf '2.42.0\n%s\n' "$(git version | cut -d' ' -f3)" | sort -V -C
fi
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
version="$(node -p 'require("./package.json").version')"
test "$GITHUB_REF_NAME" = "v$version"
fi
- name: Install verified JJ 0.46.0
shell: bash
run: |
Expand Down Expand Up @@ -94,13 +87,6 @@ jobs:
echo 'Malformed JSON was accepted' >&2
exit 1
fi
- name: Smoke npm artifact without publishing
if: matrix.platform == 'macos-arm64'
shell: bash
run: |
set -euo pipefail
GITHUB_REF_NAME="v$(node -p 'require("./package.json").version')" npm pack --ignore-scripts --json > pack.json
GITHUB_REF_NAME="v$(node -p 'require("./package.json").version')" node scripts/publish-npm.mjs --dry-run
- name: Pack platform release
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
Expand All @@ -122,46 +108,6 @@ jobs:
if-no-files-found: error
retention-days: 7

publish-npm:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: check
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
concurrency:
group: npm-release
cancel-in-progress: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: macos-arm64-release
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: npm install --global npm@11.21.0 --ignore-scripts --registry=https://registry.npmjs.org
- name: Pack the verified macOS executable
shell: bash
run: |
set -euo pipefail
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
test "$GITHUB_REF_NAME" = "v$(node -p 'require("./package.json").version')"
sha256sum -c rex-worktrees-macos-arm64.sha256
mkdir -p npm-package/dist
tar -xzf rex-worktrees-macos-arm64.tar.gz -C npm-package
mv npm-package/rex-worktrees npm-package/dist/
cp package.json npm-package/
cd npm-package
npm pack --ignore-scripts --json > pack.json
- name: Publish with OIDC and verify registry integrity
working-directory: npm-package
run: node ../scripts/publish-npm.mjs

publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: check
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build check test clean

LUA_PATH := $(CURDIR)/src/?.lua;$(CURDIR)/.build/modules/?.lua;$(CURDIR)/.build/modules/?/init.lua;$(CURDIR)/.build/src/terminal/src/?.lua;$(CURDIR)/.build/src/terminal/src/?/init.lua;;
LUA_PATH := $(CURDIR)/src/?.lua;$(CURDIR)/.build/modules/?.lua;$(CURDIR)/.build/modules/?/init.lua;;
LUA_CPATH := $(CURDIR)/.build/lib/?.so;;
export LUA_PATH LUA_CPATH

Expand Down
55 changes: 17 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

A keyboard-driven [Rex](https://www.superlogical.com/rex/docs) plugin for opening and creating **Git worktrees** and **Jujutsu (JJ) workspaces**. Pick a project, machine, session, and worktree; it opens a shell there. No agent or model required.

<img width="693" height="236" alt="image" src="https://github.com/user-attachments/assets/fadd8e3c-30fc-4f94-98ca-41132a23ff36" />
![Native Open Worktree picker](https://raw.githubusercontent.com/samuelho-dev/rex-worktrees/main/.github/picker.png)

## Install

Requires Rex and its CLI, a running Rex server, and Git 2.42+. JJ projects also need Jujutsu 0.46+. Standalone builds support Apple Silicon macOS 15+ and Linux x64; no separately installed Lua runtime is needed.
Requires Rex API 17 or newer, its CLI, a running Rex server, and Git 2.42+. JJ projects also need Jujutsu 0.46+. The native picker requires the standalone executable backend on each execution machine. Builds support Apple Silicon macOS 15+ and Linux x64; no separately installed Lua runtime is needed.

**Install or update on macOS (Apple Silicon):**

```sh
npx --yes rex-worktrees@latest setup && rex config reload
```

The command installs the standalone executable and registers the Lua plugin with Rex. No executable path or global npm installation is needed. Run it from a shell that can find `rex`, `git`, and optionally `jj`; unrelated Rex settings are preserved. Rerun the command to update.

**Without npm / Linux:** download your platform's archive from [GitHub Releases](https://github.com/samuelho-dev/rex-worktrees/releases/latest), verify it against `SHA256SUMS`, and extract it. From the extracted directory:
On either platform, download its archive from [GitHub Releases](https://github.com/samuelho-dev/rex-worktrees/releases/latest), verify it against `SHA256SUMS`, and extract it. From the extracted directory, with `rex`, `git`, and optionally `jj` on your PATH:

```sh
./rex-worktrees setup && rex config reload
```

Setup copies the executable to the same stable location, so the extracted directory is not needed afterward. `setup --bin /absolute/path/to/rex-worktrees` is only for keeping an executable at a custom or package-managed location.
Setup installs the executable to a stable location and registers the Lua plugin with Rex, preserving unrelated Rex settings. The extracted directory is not needed afterward. Repeat these steps to update. `setup --bin /absolute/path/to/rex-worktrees` is for keeping an executable at a custom or package-managed location.

## Use

Expand All @@ -32,35 +24,25 @@ Open **Open Worktree…** from the Rex palette, or run:
rex do worktrees_open
```

The popup detects the source terminal's project, current worktree, branch or revision, and full directory path. Git worktrees are separate checkout directories sharing one repository—not separate repositories or branch names.
The native summary picker detects the source terminal's project, current worktree, branch or revision, and full directory path. Select a field to edit it, then return to the summary. Escape returns from an editor or confirmation to the summary; Escape at the summary cancels without checkout changes. Git worktrees are separate checkout directories sharing one repository—not separate repositories or branch names.

Type a new worktree name in the summary and press Enter on **Create or clone & open** to create and open it immediately, using the selected project, machine, session, mode, and worktree directory settings. Git uses the name for its branch and starts from the selected checkout's HEAD; JJ uses it for the workspace and keeps the selected starting revision. Alternatively, enter a GitHub repository clone URL to clone its primary checkout on the selected machine and open it in the selected session. The destination is the machine's configured or remembered clone root plus the repository name; Git or JJ uses the remote default. No project needs to be selected, and Git is used when no project or clone is selected. Existing checkouts are never switched or reset. You can still filter and select a setting or use **Open worktree / Create worktree & open**. The current repository loads first; the full configured project scan runs when you open **Project**.

1. **Project:** select a discovered project or type an absolute repository path.
2. **Machine:** choose this machine or an existing Rex host.
2. **Machine:** choose a named Rex machine; **Current terminal** identifies the source server, not the machine hosting the native picker.
3. **Session:** select an existing session, or type a name to create one.
4. **Worktree / Workspace:** select an existing one, or choose **Create new worktree… / Create new workspace…**. This list contains worktrees, not branches or clone actions.
5. **Branch:** **Create new worktree…** opens the branch editor directly, without another click on the form. Select an unused existing branch or type a new branch name. JJ uses **Start from** instead; a valid `trunk()` is selected automatically.
5. **Branch:** **Create new worktree…** opens the branch editor directly. Select an unused existing branch or type a new branch name. JJ uses **Start from** instead; a valid `trunk()` is selected automatically.
6. **Directory:** new worktrees get a proposed absolute path; change it only if needed. A new JJ workspace takes its name from the directory's final component.
7. Choose **Open worktree / Create worktree & open**, or press **Ctrl+S** from the form. Accepting a field only updates the form; creation happens on submission.
7. Choose **Open worktree / Create worktree & open** in the summary. Editing fields only updates the draft; creation happens on submission. Safety warnings may require confirmation.

**Mode** reuses a matching tab by default; choose a new tab or split instead.

For an **existing worktree**, Branch (or Revision) and Directory describe the detected checkout. They remain readable and **read-only—not disabled**; Tab skips them. Select a different worktree to open another checkout. For a **new worktree**, Branch and Directory are editable.

The underlined `REX / WORKTREES` header, fields, and footer keep fixed positions. Editors and messages reuse the same details area, so only choice lists and long details scroll.
For an **existing worktree**, Branch (or Revision) and Directory describe the detected checkout and are read-only. Select a different worktree to open another checkout. For a **new worktree**, Branch and Directory are editable.

Shells and interactive Git/JJ clones stay attached to the destination terminal. The shell comes from `$SHELL`, falling back to `/bin/sh`.

Rex owns terminal placement, focus, and popup cleanup. New sessions and their first terminal are created together; checkout/clone work then runs in that terminal independently of the chooser.
Connection and review snapshots are operation-local: new sessions and forced new tabs skip reuse scans, and submission still checks fresh host and checkout state.

| Key | Action |
| ----------------- | ----------------------------------------------------------------- |
| Tab / Shift+Tab | Move between fields and buttons |
| ↑ / ↓ | Navigate fields or choices |
| Enter | Edit a field, accept its value, or activate a focused button |
| Ctrl+S | Submit the form; inside an editor, only accept that field |
| Esc | Return from an editor to the form; from the form, close the popup |
| PageUp / PageDown | Scroll long details |
Rex owns terminal placement and focus. New sessions and their first terminal are created together; checkout/clone work then runs in that terminal independently of the chooser. Submission checks fresh host and checkout state.

Optional shortcut—add outside the managed section of your Rex config, then reload:

Expand All @@ -83,9 +65,9 @@ Both settings are optional. `projects` lists repositories explicitly; `roots` di

### Other machines

Install and run setup on each execution machine, with matching plugin versions and local Git/JJ tools. Connect the host through Rex first. Paths and configuration belong to the selected machine. The helper protocol is v5; update all execution machines together.
Install and run setup on each execution machine, with matching plugin versions and local Git/JJ tools. Connect the host through Rex first. Paths and configuration belong to the selected machine. The helper protocol is v5; when a protocol upgrade requires it, upgrade both execution machines together.

If the selected machine lacks the project, the form proposes cloning it and shows the repository destination explicitly. **Directory** edits that path, and submission becomes **Clone & open**. Changing a field never starts a clone. The Worktree picker can also create a separate worktree after cloning; Directory then controls that worktree's path. Cloning opens a new tab. Only pushed history transfers—not uncommitted work, unpublished changes, or credentials. Cross-host execution and cloning are experimental; live remote Linux destinations have not been verified.
If the selected machine lacks the project, the picker proposes cloning it and shows the repository destination explicitly. **Directory** edits that path, and submission becomes **Clone & open**. Changing a field never starts a clone. The Worktree picker can also create a separate worktree after cloning; Directory then controls that worktree's path. Cloning opens a new tab. Only pushed history transfers—not uncommitted work, unpublished changes, or credentials. Cross-host execution and cloning are experimental; live remote Linux destinations have not been verified.

## Safety

Expand All @@ -96,11 +78,10 @@ If the selected machine lacks the project, the form proposes cloning it and show

## CLI and development

Run `rex-worktrees --help` for direct `open` commands and host/session options. `rex-worktrees popup` runs the chooser in the current terminal.
Run `rex-worktrees --help` for direct `open` commands and host/session options.

Source builds require a C compiler, make, curl, tar, a SHA-256 utility, and network access to download pinned dependencies. Lua and native modules are built locally; an installed Lua is not required.
Regression tests also require Git, JJ, and Python 3; Python is used only by the terminal test drivers.
Compiled popup scenarios disable `LUA_PATH` and `LUA_CPATH` to catch missing bundled modules.
Regression tests also require Git, JJ, and Python 3.

```sh
make check
Expand All @@ -112,9 +93,7 @@ rex config reload

Source-build setup installs to `~/.local/bin/rex-worktrees`. To uninstall, remove the `BEGIN rex-worktrees` / `END rex-worktrees` section and adjacent `rex-worktrees.lua` from your active Rex config (`rex config check --json`), remove the executable, and reload. Repositories are retained.

Releases publish the tested macOS archive to npm through GitHub Actions OIDC, then verify registry version and tarball integrity. The npm trusted publisher must authorize `samuelho-dev/rex-worktrees`, workflow `release.yml`, for direct publishing; no npm token is used. Tag a matching package version (`vX.Y.Z`) to release.

Registry verification allows up to 120 checks, ten seconds apart, for npm processing. Publishing is not retried; an integrity mismatch still fails the release.
Releases publish both tested platform archives and `SHA256SUMS` to GitHub. A Git version tag (`vX.Y.Z`) is the release authority.

## License

Expand Down
3 changes: 0 additions & 3 deletions licenses/THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ This executable bundles the following MIT-licensed software:
Lua 5.4.8 — https://www.lua.org/
Copyright (C) 1994–2025 Lua.org, PUC-Rio.

terminal.lua 0.1.0 — https://github.com/lunarmodules/terminal.lua
Copyright (c) 2024-2026 Thijs Schreijer

LuaSystem 0.7.1 — https://github.com/lunarmodules/luasystem
Copyright (c) 2016-2024, Oscar Lim
Copyright (c) 2024-2026, the luasystem project authors.
Expand Down
Loading
Loading