Add worktree auto-layout (worktree.created event)#24
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aworktree.createdevent; 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:
enabled = false→ that layout is skipped; a plain workspace is created.enabledomitted (ortrue) → deploys (on by default).enabledis a*boolso an omitted key is distinguishable from an explicitfalse. 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.go—WorktreeLayoutconfig (repo+ optionalbranch, theenabledtoggle, reusing theProjectTabmodel), loader for~/.config/herdr-plus/worktrees/, event-payload parsing, layout matching, and the handler.herdr-plugin.toml—[[events]]entry onworktree.created.main.go— dispatches the hiddenon-worktree-createdsubcommand (herdr runs it; never invoked by hand).project.go— extracted the sharedvalidateTabshelper (used by both projects and worktree layouts). Reuses the existinglayoutTabs(projects.go) andfirstNonEmpty(util.go).worktrees.mdpage, plus configuration/examples/index/troubleshooting updates.Tests
worktree_test.goparses a real captured herdr 0.7.0worktree.createdpayload and covers matching (branch-specific beats repo-only, case-insensitive, repo-root basename fallback), validation, loading, and the newenabledtoggle.go build,go test -race ./..., andgo vet ./...all pass. Not yet exercised live against a running herdr instance — same event wiring as the originally validated implementation.