feat(config): configurable worktree prompt branch policy
Summary
Replaces the hardcoded "is this main or master?" check that decides whether to prompt the user about creating a git worktree. Two new fields under worktree: in
.chief/config.yaml:
worktree.alwaysPrompt(bool, defaultfalse) — when true, Chief always shows the worktree prompt before starting a loop, regardless of branch name.worktree.promptBranchPattern(string, default"^(main|master)$") — RE2 regex matched against the current branch. When it matches, Chief prompts. Empty string disables matching. Ignored whenalwaysPromptis true. Invalid regex causes a clean startup failure naming the offending field.
Defaults preserve the prior behaviour. Existing config files without the new keys inherit the default pattern on load — the protected-branch safety isn't silently dropped on
upgrade. An explicit promptBranchPattern: "" is the documented opt-out.
Both fields are also editable in the Settings TUI (,). The regex field validates inline: invalid input is rejected with invalid regex: … shown under the editor, the
previous value is preserved, and the editor stays open for correction. Save validates the same way, so a bad regex never makes it to disk.
Internal cleanup carried with this change
- Removed the exported
git.IsProtectedBranchin favour of an unexportedisDefaultBranchNameused only inside thegitpackage for diff-base detection. The TUI call site now consultsConfig.ShouldPromptForWorktree(branch). - Renamed
DialogProtectedBranch→DialogWorktreePrompt(internal). Dialog title generalised to"⚠️ Worktree Recommended"so it stays accurate when the trigger is a regex match oralwaysPrompt: trueon a non-default branch. NewAppWithOptionsnow returns errors for invalid config (wasos.Exit) and reliably releases the fsnotify watcher on early-return paths.prd.Watcher.Stopandprd.ProgressWatcher.Stopnow release the underlying fsnotify watcher even whenStartwas never called, and are idempotent across repeated calls.- Save validates before writing, so future code paths can't persist a malformed pattern.
config.ValidateBranchPatternis the single source of truth for the regex rule (used by bothLoad/Saveand the Settings TUI).- Documentation updated with the new keys, examples (regex pattern, alwaysPrompt), an RE2 syntax note, and the markdown-escape clarification for the default
^(main\|master)$cell.
Test plan
- [ ]
go test ./...passes (internal/config≥ 90% coverage on the new code) - [ ] On a fresh project (no
.chief/config.yaml), starting a loop onmainshows the worktree prompt; onfeature/xit does not (default-behaviour preserved) - [ ] On a project with a legacy
.chief/config.yamlcontaining onlyworktree.setup: "...", starting a loop onmainstill shows the worktree prompt (no silent regression on upgrade) - [ ] With
promptBranchPattern: "^release/.*$"configured,release/v1triggers the prompt andmaindoes not - [ ] With
alwaysPrompt: trueconfigured, every branch (includingfeature/x) shows the prompt; the dialog title reads "Worktree Recommended" without claiming the branch is "protected" - [ ] With an explicitly empty
promptBranchPattern: "", no branch triggers the prompt unlessalwaysPrompt: true - [ ] Hand-editing
.chief/config.yamlwith a malformed regex (e.g."[unclosed") fails Chief startup with a clear error namingworktree.promptBranchPattern - [ ] In the Settings TUI: editing
Prompt branch patternto"[bad"showsinvalid regex: …inline, editor stays open, original value preserved; editing to"^release/.*$"saves and exits the editor - [ ] In the Settings TUI: toggling
Always prompt for worktreepersists to.chief/config.yaml