Skip to content

Start a task from an existing task-less worktree#3528

Merged
trunk-io[bot] merged 7 commits into
mainfrom
posthog-code/start-task-from-worktree
Jul 17, 2026
Merged

Start a task from an existing task-less worktree#3528
trunk-io[bot] merged 7 commits into
mainfrom
posthog-code/start-task-from-worktree

Conversation

@haacked

@haacked haacked commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

A workflow some of us use: have the agent spin up several worktrees, kick off work in them, and later pick each one up as a first-class task. PostHog Code can create a task from an existing worktree branch today, but only by going through the full task-creation form — and worktrees that no task owns are invisible in the sidebar, so there's no quick way to jump back into one.

Screenshot 2026-07-16 at 2 51 02 PM Screenshot 2026-07-16 at 2 52 09 PM

Changes

  • Per-repo "Worktrees" dropdown in the sidebar. Each repo group can list its linked worktrees that no task uses (any location on disk, including hand-made ones; detached-HEAD worktrees and the hidden local-stash worktree are excluded). Clicking one:
    1. creates a task named after the branch — with no prompt, so the agent session starts idle rather than auto-running on a synthesized prompt,
    2. adopts the existing worktree via the existing reuseExistingWorktree flow (including its occupancy race re-check),
    3. opens the task's Chat + Terminal cwd'd to that worktree. The worktree then leaves the list.
  • Opt-in via settings. Off by default to keep the sidebar uncluttered; enable with Settings → Worktrees → "Show worktrees in sidebar". When off, the section never mounts and its queries never fire.
  • Backend: new workspace.listAdoptableWorktrees tRPC query (single-pass occupancy/registered-folder filtering).
  • Core: buildWorktreeAdoptionInput helper; createTask validation now accepts content OR taskDescription instead of enumerating per-flow flags.
  • UI: GroupWorktreesSection + useAdoptableWorktrees / useStartTaskFromWorktree hooks; SidebarSection gained a depth prop for nesting.

How did you test this?

  • Unit tests added: orphan-worktree filtering (workspace-server), adoption saga flow asserting no initial prompt and reuseExistingWorktree passthrough, adoption input builder, and the createTask validation gate.
  • Full suites pass locally: workspace-server (748), core (2440), ui (1715); pnpm typecheck and Biome clean.
  • Manually tested in the dev app: enabled the setting, verified the dropdown lists task-less worktrees under the right repo, one-click created a task named after the branch with idle chat + shell in the worktree, and verified the worktree disappears from the list afterwards and the section hides when the setting is off.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

haacked added 4 commits July 16, 2026 12:29
Each repo group in the sidebar gets a nested "Worktrees (N)" dropdown
listing linked worktrees no task uses. Clicking one creates a promptless
task named after the branch, adopts the worktree via the existing
reuseExistingWorktree flow, and opens the task's chat + shell with an
idle agent session.

- workspace-server: listAdoptableWorktrees filters linked worktrees to
  branch-bearing, task-less ones, excluding registered folders and the
  local-backgrounding stash worktree
- core: buildWorktreeAdoptionInput + worktreeAdoption input flag so a
  synthesized taskDescription passes createTask validation without
  content (no initial agent prompt)
- ui: GroupWorktreesSection nested under each repo group, with
  useAdoptableWorktrees / useStartTaskFromWorktree hooks

Generated-By: PostHog Code
Task-Id: 24032eac-82cc-4c5f-a7e9-30ed9278a6e1
Settings → Worktrees gains a "Show worktrees in sidebar" toggle (on by
default) that hides the per-repo worktrees dropdown and skips its
queries entirely. The dropdown also starts collapsed: expansion is
tracked as the exception in a new expandedWorktreeSections set, since
collapsedSections defaults sections to expanded.

Generated-By: PostHog Code
Task-Id: 24032eac-82cc-4c5f-a7e9-30ed9278a6e1
- Validation in createTask now accepts content OR taskDescription
  instead of enumerating per-flow flags; the worktreeAdoption input
  flag existed only to gate that check, so it's gone
- listAdoptableWorktrees builds occupied-path and registered-folder
  sets in one pass instead of re-querying workspace tables per
  worktree candidate
- SidebarSection reuses the INDENT_SIZE constant from SidebarItem
  instead of a third copy of the indent unit

Generated-By: PostHog Code
Task-Id: 24032eac-82cc-4c5f-a7e9-30ed9278a6e1
With the section hidden until the user enables it in Settings →
Worktrees, expanded-by-default is the right behavior for those who
opted in. That removes the need for expandedWorktreeSections — the
inverse-polarity twin of collapsedSections — so the section now uses
the shared collapsedSections/toggleSection mechanism like every other
sidebar section.

Generated-By: PostHog Code
Task-Id: 24032eac-82cc-4c5f-a7e9-30ed9278a6e1
@trunk-io

trunk-io Bot commented Jul 16, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 8cadeab.

@haacked
haacked marked this pull request as ready for review July 16, 2026 23:56
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Make sidebar worktrees opt-in and drop t..." | Re-trigger Greptile

- Add showSidebarWorktrees to settings rehydration test
- Clarify padding calculation comment in SidebarSection
- Use AdoptableWorktree named type instead of inline object type
Comment thread packages/workspace-server/src/services/workspace/workspace.ts
@haacked haacked added the Stamphog This will request an autostamp by stamphog on small changes label Jul 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No showstoppers. The opt-in sidebar worktree adoption feature follows established service patterns correctly. The greptile bot's path-aliasing concern is on an older commit and describes a pre-existing, documented design choice (verbatim git-path comparison, explicitly noted at line 1422–1424 of workspace.ts) — the new code mirrors the same pattern as getWorktreeTasks. The validation broadening in taskService.ts is intentional and has clear test coverage.

@haacked
haacked enabled auto-merge (squash) July 17, 2026 03:39
@haacked

haacked commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

4 similar comments
@haacked

haacked commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@haacked

haacked commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@haacked

haacked commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@haacked

haacked commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@trunk-io
trunk-io Bot merged commit 13f7ab6 into main Jul 17, 2026
32 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/start-task-from-worktree branch July 17, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants