Skip to content

Add worktree auto-layout (worktree.created event)#24

Merged
cloudmanic merged 3 commits into
mainfrom
worktree-auto-layout-plugin
Jun 16, 2026
Merged

Add worktree auto-layout (worktree.created event)#24
cloudmanic merged 3 commits into
mainfrom
worktree-auto-layout-plugin

Conversation

@cloudmanic

Copy link
Copy Markdown
Owner

Lays a project-style tab layout into a git worktree the moment herdr creates it. When you run herdr worktree create, herdr makes a fresh workspace and fires a worktree.created event; herdr-plus catches it, finds a layout matching the worktree's repo, and opens that layout's tabs/panes in the new workspace — every command running — with no keypress. This is the original pre-rewrite feature (09f448e) ported forward onto the current plugin architecture.

Per-layout on/off switch

The toggle lives in the layout file, not a separate global config:

repo = "options-cafe"
enabled = false      # keep the file, but don't deploy — worktree opens plain

[[tabs]]
name = "claude"
command = "claude"
  • No layout file → nothing deploys (unchanged worktree behavior).
  • enabled = false → that layout is skipped; a plain workspace is created.
  • enabled omitted (or true) → deploys (on by default).

enabled is a *bool so an omitted key is distinguishable from an explicit false. A disabled layout is still validated (a typo can't hide behind it) and never suppresses another matching enabled layout. When a worktree opens plain because its layout was switched off, the plugin log says so explicitly.

How it's wired

  • worktree.goWorktreeLayout config (repo + optional branch, the enabled toggle, reusing the ProjectTab model), loader for ~/.config/herdr-plus/worktrees/, event-payload parsing, layout matching, and the handler.
  • herdr-plugin.toml[[events]] entry on worktree.created.
  • main.go — dispatches the hidden on-worktree-created subcommand (herdr runs it; never invoked by hand).
  • project.go — extracted the shared validateTabs helper (used by both projects and worktree layouts). Reuses the existing layoutTabs (projects.go) and firstNonEmpty (util.go).
  • Docs — README section, new worktrees.md page, plus configuration/examples/index/troubleshooting updates.

Tests

worktree_test.go parses a real captured herdr 0.7.0 worktree.created payload and covers matching (branch-specific beats repo-only, case-insensitive, repo-root basename fallback), validation, loading, and the new enabled toggle.

go build, go test -race ./..., and go vet ./... all pass. Not yet exercised live against a running herdr instance — same event wiring as the originally validated implementation.

Port the worktree auto-layout feature forward onto the plugin architecture.
When herdr creates a git worktree it makes a workspace and fires a
worktree.created event; herdr-plus subscribes to it and lays a matching
layout's tabs/panes into the new workspace automatically — extending Projects
with event-driven automation.

Each layout carries its own on/off switch: omit `enabled` (or set it true) to
deploy, set `enabled = false` to keep the file on disk but stop it firing, so the
worktree opens as a plain workspace. With no layout file at all, the feature is
inert.

- worktree.go: WorktreeLayout config (repo + optional branch matcher, plus the
  enabled *bool toggle, reusing the ProjectTab model), loader for
  ~/.config/herdr-plus/worktrees/, event-payload parsing, layout matching
  (branch-specific beats repo-only; disabled layouts skipped and never
  suppress an enabled match), and the handler.
- herdr-plugin.toml: add an [[events]] entry on worktree.created.
- main.go: dispatch the hidden on-worktree-created subcommand.
- project.go: extract validateTabs, shared by Project and WorktreeLayout.
- worktree_test.go: parse a real captured worktree.created payload; cover
  matching, validation, loading, and the enabled toggle.
- Docs: README section, new www/ worktrees page, configuration, examples,
  index, and troubleshooting updates.
The per-layout on/off switch was `enabled`, which doesn't say what it gates. A
worktree layout only ever does one thing — open when herdr fires
worktree.created — so name the key after that event. Renames the TOML key, the
struct field (OnWorktreeCreated), the appliesOnCreate predicate, the
switchedOffMatch helper, the plugin-log message, and every doc reference.
A worktree layout is on simply by existing in worktrees/; to turn one off, delete
the file. That removes the need for a separate on/off key to keep in sync, so the
on_worktree_created field is gone along with its predicate, the switched-off log
path, and the tests/docs that covered it.
@cloudmanic cloudmanic merged commit 7debe85 into main Jun 16, 2026
2 checks passed
@cloudmanic cloudmanic deleted the worktree-auto-layout-plugin branch June 16, 2026 17:00
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