feat(config): configurable worktree prompt branch policy#66
Open
Magentron wants to merge 2 commits intoMiniCodeMonkey:mainfrom
Open
feat(config): configurable worktree prompt branch policy#66Magentron wants to merge 2 commits intoMiniCodeMonkey:mainfrom
Magentron wants to merge 2 commits intoMiniCodeMonkey:mainfrom
Conversation
Replace the hardcoded main/master check that decided whether to prompt the user about creating a worktree with two new config fields under .chief/config.yaml: - worktree.alwaysPrompt: bool — when true, always prompt regardless of branch name. - worktree.promptBranchPattern: string (regex) — pattern matched against the current branch; when it matches, Chief prompts. Defaults preserve the prior behavior (pattern: ^(main|master)$); existing config files inherit the default on load. Invalid regex fails fast at startup with a field-named error. Save also validates so future write paths can't persist a broken pattern. Internal cleanup carried with this change: - Remove exported git.IsProtectedBranch in favor of a private isDefaultBranchName for the diff-base helper inside the git package; the TUI call site now consults the new policy method. - Rename DialogProtectedBranch to DialogWorktreePrompt; dialog title generalized so it stays accurate when triggered by regex match or alwaysPrompt on non-default branches. - NewAppWithOptions returns errors for invalid config (was os.Exit) and reliably releases the fsnotify watcher on early return. - prd.Watcher.Stop and prd.ProgressWatcher.Stop now release the underlying fsnotify watcher even when Start was never called, and are idempotent across repeated calls. - Octal literals normalized to the dominant legacy style (0755 / 0644) for repo-wide consistency. - Documentation updated with the new keys, examples, RE2 note, Markdown-escape clarification, and accurate Settings TUI scope. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add worktree.alwaysPrompt and worktree.promptBranchPattern to the Settings TUI overlay so users can edit them without leaving the app: - LoadFromConfig surfaces 5 items (was 3); the new worktree fields appear under the existing Worktree section. - ApplyToConfig copies both new keys back to Config. - ConfirmEdit now returns an error and validates regex input inline. On invalid pattern, the editor stays open with an inline "invalid regex: …" message; the previous value is preserved. Empty pattern is accepted (matches the documented opt-out semantics). - Editor app handler skips Save when ConfirmEdit returns an error, keeping the user in edit mode. DRY: extract config.ValidateBranchPattern as the single source of truth for the regex rule, used by both compilePromptRegex (load/save path) and ConfirmEdit (inline TUI validation). Includes a direct unit test covering empty / valid / invalid inputs so the contract is locked in. Docs updated: removed the "not yet exposed in the in-app Settings TUI" caveat and listed the two new editable items under the Worktree section. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
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 stringdisables matching. Ignored when
alwaysPromptis 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 withinvalid regex: …shown under the editor, theprevious value is preserved, and the editor stays open for correction.
Savevalidates the same way, so a bad regex never makes it to disk.Internal cleanup carried with this change
git.IsProtectedBranchin favour of an unexportedisDefaultBranchNameused only inside thegitpackage for diff-base detection. The TUI call site nowconsults
Config.ShouldPromptForWorktree(branch).DialogProtectedBranch→DialogWorktreePrompt(internal). Dialog title generalised to"⚠️ Worktree Recommended"so it stays accurate when the trigger is a regexmatch or
alwaysPrompt: 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.config.ValidateBranchPatternis the single source of truth for the regex rule (used by bothLoad/Saveand the Settings TUI).^(main\|master)$cell.
Test plan
go test ./...passes (internal/config≥ 90% coverage on the new code).chief/config.yaml), starting a loop onmainshows the worktree prompt; onfeature/xit does not (default-behaviour preserved).chief/config.yamlcontaining onlyworktree.setup: "...", starting a loop onmainstill shows the worktree prompt (no silent regression onupgrade)
promptBranchPattern: "^release/.*$"configured,release/v1triggers the prompt andmaindoes notalwaysPrompt: trueconfigured, every branch (includingfeature/x) shows the prompt; the dialog title reads "Worktree Recommended" without claiming the branch is"protected"
promptBranchPattern: "", no branch triggers the prompt unlessalwaysPrompt: true.chief/config.yamlwith a malformed regex (e.g."[unclosed") fails Chief startup with a clear error namingworktree.promptBranchPatternPrompt branch patternto"[bad"showsinvalid regex: …inline, editor stays open, original value preserved; editing to"^release/.*$"saves and exits the editor
Always prompt for worktreepersists to.chief/config.yaml