Skip to content

workspaces: create local workspaces as APFS copy-on-write clones - #99

Merged
vaayne merged 7 commits into
mainfrom
cow-clone-workspaces
Jul 23, 2026
Merged

vaayne merged 7 commits into
mainfrom
cow-clone-workspaces

Conversation

@vaayne

@vaayne vaayne commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

Local workspace creation now clones the whole project directory via a single clonefile(2) syscall (~1.7s for a 4 GB repo, measured) instead of git worktree add, so node_modules, .build, and other untracked artifacts are available instantly in the new workspace. Also works for non-git projects.

  • Fallback chain: clonefile(2) → per-file copyfile(COPYFILE_CLONE) walk (with volume pre-check so it never silently degrades to a physical copy) → git worktree add (git repos) / plain copy (non-git). SSH projects keep the existing worktree path untouched.
  • Instant sidebar feedback: the new row appears immediately with a transient Creating… status (new WorktreeStatus.creating, never persisted), promoted to active on success, rolled back on failure.
  • Safe deletion: clones are removed via direct file deletion gated by path guardrails (must be under the managed workspace dir, never repo root / home / shallow paths), and the confirm dialog escalates when the clone holds unpushed commits — unlike a worktree, a clone's branch dies with its files.
  • Auto-discovery: clones/plain dirs under the workspace base dir are imported at launch, on project add, and via the existing manual import. A per-project dismissed-paths list prevents resurrecting workspaces the user removed while keeping files (also fixes manual import resurrecting previously removed git worktrees).
  • Settings: "Prefer copy-on-write clones for new workspaces" toggle (on by default) next to the worktree base path.
  • Sidebar: the + New workspace row is gone; + and … are now hover-revealed icons in the project header next to the collapse chevron (always visible for projects with no workspaces).

Notes

  • COPYFILE_CLONE_FORCE is incompatible with COPYFILE_RECURSIVE on directory trees (interior dirs are mkdir'd) — the volume pre-check provides the no-silent-physical-copy guarantee instead.
  • Worktree.kind is persisted as a hint only; destructive operations re-verify the on-disk shape (.git dir = clone, .git file = linked worktree).
  • Clone refs don't follow the main repo's fetches (unlike a shared-ref worktree); agents fetch themselves.
  • MoriGit tests were not wired into mise run test — fixed here (test:git).

Verification

  • mise run test — six packages, 1369 assertions, all green (new CowCloner suite covers clone content/symlinks, dest-exists, temp cleanup, on-disk classification, and real-git fixup).
  • Release builds of both products pass; manually tested by @vaayne (create, instant sidebar row, clone speed).

vaayne added 7 commits July 23, 2026 09:34
clonefile via copyfile(COPYFILE_CLONE) with a pre-flight volume check
(CLONE_FORCE is incompatible with RECURSIVE directory trees), a status
callback that skips sockets/FIFOs like .git/fsmonitor--daemon.ipc, temp
path + rename materialization, on-disk kind classification, and the
post-clone git fixup (drop inherited .git/worktrees, checkout -f).
Also adds GitBackend.commitsAhead for unpushed-work probes.
Worktree.kind (hint only; destructive ops re-verify on disk),
ToolSettings.preferCowClones (default on), and
Project.dismissedWorktreePaths so auto-discovery cannot resurrect
workspaces the user removed while keeping files.
Local creation clones the project dir (untracked files — node_modules,
.build — carry over instantly), falling back to git worktree (repos) or
a plain copy (non-git) on non-APFS/cross-volume. Deletion branches on
on-disk truth with path guardrails and an escalated warning when a
clone holds unpushed commits (they exist only in the clone). Discovery
scans the worktree base dir at launch/import, gated by the per-project
dismissed-paths list. Settings toggle to prefer clones, on by default.
Hover-revealed [+] and [...] icons next to the collapse chevron replace
the dedicated '+ New workspace' row, saving a row per section. Opacity
(not conditional insertion) keeps the chevron from shifting; projects
with no workspaces show the accessories permanently so the create entry
point stays discoverable. The overflow menu's New Workspace item drops
its expanded-only gate since the header works while collapsed too.
copyfile(RECURSIVE) walks per file (~30s for repos with node_modules);
clonefile(2) on the root directory clones the entire tree in one syscall
(measured 1.7s on a 4 GB repo) and handles sockets natively. The
per-file walk stays as fallback when clonefile refuses.
Insert an in-memory placeholder row with a new .creating status before
materialization, promote to .active and persist on success, roll back
on failure. Creating rows are non-interactive, show a 'Creating…'
status line, and are skipped by git status polling since their path may
not exist yet. Never persisted, so a crash mid-create leaves no stale
record.
@vaayne
vaayne merged commit 57d4c94 into main Jul 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant