Skip to content

feat(worktrees): list worktrees git already has - #294

Merged
nixuuu merged 1 commit into
devfrom
feat/external-worktrees
Nov 6, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/external-worktrees

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026

Copy link
Copy Markdown
Member

Change

Projects with worktrees created outside Canopy now show those directories in the new-thread workspace picker on web and mobile. The list merges the worker's real Git inventory with Canopy's registry, keeps Current checkout once, and shows branch or detached HEAD, directory, provenance, and unavailable states. Settings also lists external worktrees with read-only controls.

Discovery and adoption

  • The worker reads git worktree list --porcelain -z, with a 2-second bounded cache and a 3-second discovery deadline. Opening the picker refreshes it; selecting an entry bypasses the cache.
  • The gateway accepts an owned workspace and opaque worktree id, never a client path. The worker validates canonical checkout roots and the repository's common Git directory. Locked, prunable, missing, and substituted directories cannot be selected.
  • Discovery does not write to the registry. First use registers external = true with fixed branch naming. Existing live HEAD tracking then follows branch changes. Cleanup, removal, movement, and generated branch naming never manage external directories; migration 0092 protects their provenance and removal state.
  • Linked workspaces use the existing home-gateway routes and the worker holding the checkout. Settings aggregates reachable homes.

Compatibility

Protobuf additions include generated code. WORKER_LINK_PROTOCOL remains 1: the additive git_worktree_discovery capability enables discovery, while older workers retain their registry list. Previously adopted external entries require an updated worker. Linked gateways negotiate remote_worktrees; a home without it refuses placement instead of silently using Current checkout.

Verification

  • Passed: bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check, the web build, and bun run --filter @canopy/mobile lint (Expo lint).
  • Full bun run check:tmp: 1,549 passed, 158 skipped, 0 failed (1,707 tests across 277 files), with no test temporary directories left. Temporary data stayed under the worktree; GIT_CEILING_DIRECTORIES isolates non-repository fixtures from the enclosing checkout.
  • Focused check:tmp run: 9 tests passed, 45 assertions, no temporary directories left. Real Git + worker/gateway/Postgres integration covers normal, detached, locked and prunable worktrees; fresh selection; actual thread cwd; live branch changes; cleanup/removal/renaming protections; owner/repository scoping; symlinked managed roots; and linked gateways including capability skew.
  • Manually inspected web picker and settings in light/dark at desktop and phone widths, with short and long paths/branches. Inspected the Android emulator picker and read-only settings in light/dark, including disabled states and long text. No permanent web UI tests or native builds were added. iOS and opt-in live model tests were not run.

Copy audit

Before After Reason
Previous worktrees Managed by Canopy / Created outside Canopy State provenance explicitly.
Created [relative time] Shortened directory path Distinguish entries even when branches match.
No managed worktrees in this scope. No worktrees in this scope. Include external entries in the empty state.
No availability cue Locked worktree / Prunable worktree / Directory missing Explain disabled entries with text.

Checked all ten items in docs/copy.md §8: sentence case, glossary, action verbs, actionable discovery errors, concise empty states, no repeated provenance, explicit compatibility action, no added personality copy, short/long text at both widths, and textual state cues. Expanded the worktree glossary to include externally created worktrees.

Discover repository worktrees on their worker and register external entries only when a thread uses them. Keep external directories read-only in lifecycle operations and expose the merged list on web, mobile and linked computers.
@nixuuu
nixuuu merged commit 3f94f6e into dev Nov 6, 2026
9 checks passed
@nixuuu
nixuuu deleted the feat/external-worktrees branch November 6, 2026 19:59
nixuuu added a commit that referenced this pull request Nov 6, 2026
## Root cause

A shared project (#168) is one overview row with every linked computer's
workspaces. The routed overview merged them only in `GetOverview` and in
updates **from the partner**. When this computer republished its **own**
row of a shared project, the overview stream sent it with local
workspaces only. Triggers include `coreBroadcastWorkers` on any worker
change, renames, `projectsChanged` after a config sync and origin
refreshes. Web and mobile upsert by id, so the merged row lost the
partner's workspaces. A project that lives only on a linked computer
then had `workspaces: []`, and the new-thread picker showed "No worker"
and "… is not on any worker yet".

I reproduced it with two linked gateways. A's `WatchOverview` emitted
the shared project with `workspaces: []` right after A republished it.

## Fix

- `apps/gateway/src/api/routed-overview.ts`: every update of a shared
project goes out with all computers' workspaces, whether it came from
this computer or a partner. A burst (for example, a worker change
republishing every project) reads the overview once, 50 ms coalescing.
If that read fails, the local row still goes out. Mobile is fixed by the
same change.
- `WorkerPicker.svelte`:
- linked workers stay listed until the gateway capabilities load
(before, they were briefly hidden);
- workers on an unreachable computer are greyed out and disabled, with
the presence reason, as on mobile;
- the empty state says "<project>'s workers are not connected." when the
project has workspaces. "not on any worker yet" now appears only when it
is true.
- `docs/linked-computers.md`: notes the merged stream updates.

## Verification

- New `tests/integration/linked-new-thread.test.ts` (two linked
gateways, separate databases):
- A's overview stream keeps B's workspace after A republishes the shared
project. This test fails without the fix.
  - B's worker is in A's overview and online.
  - A thread created from A on B's worker lives on B, in B's project.
- Passed, each file run on its own: `linked-projects`,
`config-sync-projects`, `worktrees`, `worktree-automation` and the db
schema test.
- Clean: `bun install`, `gen:check`, `typecheck`, `lint`, `format:check`
and the web build.
- `check:tmp`: 1517 pass, 3 fail. All 3 failures are in files `dev`
(#294) changed while the run was in progress; all 3 pass when rerun on
the rebased branch.
- Browser, against three linked test gateways and a vite dev BFF:
- wrk-ai only on "Mac-Studio-of-the-team": the picker shows that worker
and the composer is ready (light, desktop);
- pinpoint on two computers: grouped "This computer" /
"Mac-Studio-of-the-team";
- an offline "Mac mini": its worker is greyed out and disabled with
"Offline since …" (dark, iPhone 12 Pro width).

## Not in scope

New worktrees on a linked computer's checkout stay refused on purpose
(docs/worktrees.md, "Połączone komputery", stage 1). Supporting them
needs gateway capability negotiation and is a separate feature.

## Copy audit (docs/copy.md §8)

- New: "{project}'s workers are not connected." It is short and factual,
and it replaces a false claim. No other text changed.

Fixes: #168
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