chore: add cmux config that delegates worktree creation to worktrunk - #5053
chore: add cmux config that delegates worktree creation to worktrunk#5053adaam2 wants to merge 4 commits into
Conversation
|
There was a problem hiding this comment.
3 issues found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".cmux/import-worktrees.sh">
<violation number="1" location=".cmux/import-worktrees.sh:30">
P2: Worktrees located under paths containing spaces are truncated during import, so `git -C "$wt"` fails and the script skips that worktree. Extract everything after the `worktree ` prefix instead of using the second whitespace-delimited field.</violation>
<violation number="2" location=".cmux/import-worktrees.sh:37">
P2: Under `set -euo pipefail`, any single failing iteration inside the `while read` loop aborts the entire import. `git -C "$wt" rev-parse --abbrev-ref HEAD` or `cmux new-workspace --cwd "$wt"` will fail (nonzero) if a worktree was removed concurrently, points at an invalid path, or the cmux socket/control mode rejects the call — and with `set -e` that tears down the whole loop, silently leaving every remaining worktree un-imported with no indication of which path failed or why. Since this is designed as a re-runnable/idempotent sync, per-worktree failures should be tolerated and reported rather than aborting the batch. Wrap the per-worktree body so a failure is logged and the loop continues.</violation>
<violation number="3" location=".cmux/import-worktrees.sh:38">
P2: The script identifies the workspace it just created by grabbing the *last* entry of `cmux list-workspaces --json` (`[-1]`) instead of the id that `cmux new-workspace` returns. This only works if the CLI appends new workspaces and never reorders or sorts them, and if creation is synchronously visible in the very next call. If cmux returns workspaces in any other order (e.g. name-sorted) or the create is still propagating, `rename-workspace` will rename an existing, unrelated workspace and the new one is left with its default name — silently corrupting workspace labels. Prefer capturing the id directly from the `new-workspace` output payload (most CLIs print the created object) and renaming right from that value.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
| print(ws.get("cwd") or "") | ||
| ') | ||
|
|
||
| git -C "$repo" worktree list --porcelain | awk '/^worktree /{print $2}' | |
There was a problem hiding this comment.
P2: Worktrees located under paths containing spaces are truncated during import, so git -C "$wt" fails and the script skips that worktree. Extract everything after the worktree prefix instead of using the second whitespace-delimited field.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cmux/import-worktrees.sh, line 30:
<comment>Worktrees located under paths containing spaces are truncated during import, so `git -C "$wt"` fails and the script skips that worktree. Extract everything after the `worktree ` prefix instead of using the second whitespace-delimited field.</comment>
<file context>
@@ -0,0 +1,44 @@
+ print(ws.get("cwd") or "")
+')
+
+git -C "$repo" worktree list --porcelain | awk '/^worktree /{print $2}' |
+while read -r wt; do
+ if printf "%s\n" "$existing" | grep -Fxq "$wt"; then
</file context>
| continue | ||
| fi | ||
| branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD) | ||
| cmux new-workspace --cwd "$wt" |
There was a problem hiding this comment.
P2: Under set -euo pipefail, any single failing iteration inside the while read loop aborts the entire import. git -C "$wt" rev-parse --abbrev-ref HEAD or cmux new-workspace --cwd "$wt" will fail (nonzero) if a worktree was removed concurrently, points at an invalid path, or the cmux socket/control mode rejects the call — and with set -e that tears down the whole loop, silently leaving every remaining worktree un-imported with no indication of which path failed or why. Since this is designed as a re-runnable/idempotent sync, per-worktree failures should be tolerated and reported rather than aborting the batch. Wrap the per-worktree body so a failure is logged and the loop continues.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cmux/import-worktrees.sh, line 37:
<comment>Under `set -euo pipefail`, any single failing iteration inside the `while read` loop aborts the entire import. `git -C "$wt" rev-parse --abbrev-ref HEAD` or `cmux new-workspace --cwd "$wt"` will fail (nonzero) if a worktree was removed concurrently, points at an invalid path, or the cmux socket/control mode rejects the call — and with `set -e` that tears down the whole loop, silently leaving every remaining worktree un-imported with no indication of which path failed or why. Since this is designed as a re-runnable/idempotent sync, per-worktree failures should be tolerated and reported rather than aborting the batch. Wrap the per-worktree body so a failure is logged and the loop continues.</comment>
<file context>
@@ -0,0 +1,44 @@
+ continue
+ fi
+ branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD)
+ cmux new-workspace --cwd "$wt"
+ id=$(cmux list-workspaces --json | python3 -c '
+import json, sys
</file context>
| fi | ||
| branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD) | ||
| cmux new-workspace --cwd "$wt" | ||
| id=$(cmux list-workspaces --json | python3 -c ' |
There was a problem hiding this comment.
P2: The script identifies the workspace it just created by grabbing the last entry of cmux list-workspaces --json ([-1]) instead of the id that cmux new-workspace returns. This only works if the CLI appends new workspaces and never reorders or sorts them, and if creation is synchronously visible in the very next call. If cmux returns workspaces in any other order (e.g. name-sorted) or the create is still propagating, rename-workspace will rename an existing, unrelated workspace and the new one is left with its default name — silently corrupting workspace labels. Prefer capturing the id directly from the new-workspace output payload (most CLIs print the created object) and renaming right from that value.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cmux/import-worktrees.sh, line 38:
<comment>The script identifies the workspace it just created by grabbing the *last* entry of `cmux list-workspaces --json` (`[-1]`) instead of the id that `cmux new-workspace` returns. This only works if the CLI appends new workspaces and never reorders or sorts them, and if creation is synchronously visible in the very next call. If cmux returns workspaces in any other order (e.g. name-sorted) or the create is still propagating, `rename-workspace` will rename an existing, unrelated workspace and the new one is left with its default name — silently corrupting workspace labels. Prefer capturing the id directly from the `new-workspace` output payload (most CLIs print the created object) and renaming right from that value.</comment>
<file context>
@@ -0,0 +1,44 @@
+ fi
+ branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD)
+ cmux new-workspace --cwd "$wt"
+ id=$(cmux list-workspaces --json | python3 -c '
+import json, sys
+print(json.load(sys.stdin)[-1]["id"])
</file context>
What
Adds
.cmux/cmux.json, a project config for cmux that plugs its workspace creation into our existing worktrunk flow instead of rawgit worktree add.Two workspace commands, wired to the "+" button and command palette:
--no-boot/--base <ref>passthrough), runswt switch --create, so the.config/wt.tomlhooks fire as usual:git:workinitport remap and the backgroundgit:workbootstack boot. Echoes the worktree's dashboard URL.wt switchfor an existing branch; supports wt shortcuts (^,-,pr:123) and the interactive picker on empty input.Each workspace opens two panes: a shell left in the worktree, and a Claude agent pane that waits for the worktree path (via a state file keyed on
CMUX_WORKSPACE_ID), cds in, and starts.Notes
--no-bootis translated toGRAM_WT_NO_BOOT=1, matching thegit:workboothook contract.wt removestill does that (and thepre-removenuke hook tears the stack down).Summary by cubic
Add
cmuxproject config to create/open worktrees viaworktrunk(wt), plus a palette action to import existing git worktrees. The import script resolves the bundledcmuxCLI and relies on socket auto-discovery (>=0.64).New Features
.cmux/cmux.jsonto route workspace creation/opening throughwt.wt switch --create, supports--base,--no-boot) and Open Branch (wt switch, supports^,-,pr:123, or picker); layout opens a terminal plus aclaudepane that waits onCMUX_WORKSPACE_ID..cmux/import-worktrees.sh: one workspace per git worktree; resolves the bundledcmuxCLI; socket auto-discovered (override withCMUX_SOCKET_PATH).--no-bootsetsGRAM_WT_NO_BOOT=1; prints the dashboard URL if a port is found.Migration
worktrunkshell integration.defaults write com.cmuxterm.app socketControlMode automation.cmuxworkspace does not remove the worktree; runwt remove.Written for commit 6a8af9c. Summary will update on new commits.