Assessment of auto-detecting worktrees created outside PI WEB. Worktree discovery is already derived per request with no cache and no registry, so the gap is that the browser never re-lists. Recommends the reduced scope: filter prunable worktrees, add a non-disruptive topology refresh, and call it from the existing browser-resume path. No watchers, timers, processes, or push channels. Packet is repo-only and outside the published files allowlist, so no changeset is needed.
6.6 KiB
Charter — relay "worktree-autodetect"
Relay identity
- Name:
worktree-autodetect - Root:
.pi-web/relays/worktree-autodetect/in worktree/srv/dev/pi-web-worktrees/worktree-autodetect - Branch:
feat/worktree-autodetect(based onmain)
Goal / finish line
Worktrees created or removed outside PI WEB become visible in the browser workspace list with no user action of any kind, on the next natural browser resume, on both local and remote machines.
Concretely, the relay is finished when all of the following are true:
discoverGitWorktreesno longer reports worktrees whose checkout directory is gone (prunableingit worktree list --porcelain), so worktrees deleted outside PI WEB stop appearing as selectable ghost workspaces.WorkspaceControllercan re-list the workspaces of the selected project and apply the result without disturbing the current selection, session, or scroll state when the selected workspace still exists, and without silently yanking the user out of a workspace that vanished while they were working in it.PiWebAppcalls that refresh from the existing browser-resume path (refreshAfterBrowserResume) and the existing plugin-facingrefreshAppDatapath. No new timer, no new watcher, no new process, no new WebSocket channel.- Tests cover: prunable parsing/filtering, refresh-preserves-selection, refresh-when-selected-workspace-disappeared, and the resume wiring.
npm run verifyis green, and a changeset exists describing the user-visible behavior.
Explicitly out of scope (decided in leg 0, do not re-open without the human):
- Filesystem watchers on
.git/worktreesor anywhere else. - Polling timers for worktree discovery.
- Any server→browser push channel for workspace topology.
- Instant (sub-second) detection while the browser tab already has focus.
- Auto-adopting anything into
projects.json. Worktrees are derived, never registered; nothing is being adopted, and no project registry write is part of this work.
Sizing
One leg = one vertical slice that leaves the tree green and committed.
A leg is done when its slice is implemented, its tests are written and passing, the
narrowest meaningful checks are run (npm test -- --run <file>, plus npm run typecheck
if exported types changed), and the work is committed. Do not carry uncommitted work
across a handoff.
Expected shape is three legs (see plan.md). If a leg turns out bigger than one slice,
split it and hand off the remainder rather than doing "just a bit more".
Task selection policy
- Take the explicit next leg named in
status.md. - If
status.mddoes not name one, take the next unfinished slice inplan.mdin order. - If neither is clear, or the next slice would change the design rather than implement it, stop and raise the intervention signal. Do not redesign inside a leg.
Handover protocol
Before handing off, in this order:
- Make the work durable: source + tests written, checks run, changes committed with a Conventional Commit message.
- Update
status.md: current position, last completed leg, next leg to run, next task, relevant context for the next runner, blockers. - Append a concise entry to
log.md: what you did, decisions and why, artifacts changed, exact checks run and their results, handing-off vs stopping. - Then
spawn_sessiononce, with a prompt starting:
Relay "worktree-autodetect" leg <N> begins now.
You are the next runner in this Relay method chain.
Read:
- .pi-web/relays/worktree-autodetect/charter.md
- .pi-web/relays/worktree-autodetect/status.md
Do not read log.md end-to-end. Use it only for targeted lookup if status.md or charter.md points you there.
Run one leg according to the charter. Before handing off, update status.md, append log.md, make work durable, then either spawn the next leg once or stop with a clear intervention note.
Intervention signal
Stop, do not spawn, and write a clearly marked ## BLOCKED section at the top of
status.md plus a log entry, if any of these happen:
- The next task is ambiguous, or doing it would require a design decision not in this charter.
- You are tempted to add a watcher, a timer, a new process, or a new push channel. That means the design boundary is being crossed — get the human.
- Refresh-on-resume cannot be made to preserve selection without visible UI churn (list reordering, chat scroll jump, session reload, terminal teardown). This is the main known risk; it is a stop, not a workaround.
- Filtering
prunablewould remove a workspace the user could plausibly still want (for example a temporarily unmounted network path) and you cannot bound that safely. npm run verifyfails for a reason you did not introduce.
Reading discipline
Read to orient: charter.md, then status.md, then only the files status.md names.
Do not read log.md end-to-end; use it only for targeted lookup when pointed there.
Do not read the sibling worktrees /srv/dev/pi-web-worktrees/worktree-create-ui or
/srv/dev/pi-web-worktrees/model-questions-ux — they are separate, parallel efforts. Per
the human's decision, assume they contribute nothing to this relay; this relay owns the
workspace-topology refresh seam outright.
Relevant source surface, small enough to read directly when your leg touches it:
src/server/workspaces/gitWorktreeDiscovery.ts(39 lines)src/server/workspaces/workspaceService.ts(44 lines)src/client/src/controllers/workspaceController.ts(~105 lines)src/client/src/appShell/browserResumeController.ts+ its testsrc/client/src/components/PiWebApp.ts— onlyrefreshAfterBrowserResume(~line 432) andrefreshAppData(~line 485). Do not read this 2300-line file whole.
Project conventions that apply
- Changesets: this is user-visible. Add a
.changeset/*.mdfragment (see.agents/skills/changeset-changelog/SKILL.md). Never hand-editCHANGELOG.md. - Skills: use
.agents/skills/code-quality-architecture/SKILL.mdwhen writing production code and.agents/skills/testing-guide/SKILL.mdwhen writing tests. - Session daemon: this design deliberately touches no sessiond code, no session
runtime ownership, and no daemon protocol. No manual session daemon restart is
required. Changes land on the autoreloading
pi-web-web-ui-dev.servicepath only. If a leg finds itself editingsrc/server/sessiond.ts, that is the intervention signal. - Client URL conventions: no new endpoints are added; the existing
workspacesApi.workspaces()request path is reused unchanged. - No
npm install—node_moduleshere is a symlink to the main checkout.