@@ -148,16 +148,22 @@ function segmentGuard(
148148// notice can name the operative reason: a force flag, or a destination the
149149// containment authority did not approve. Returns undefined for anything else.
150150// Display-only refinement — the guard decision itself is unchanged.
151- function worktreeMismatchKind (
152- segment : string ,
153- ) : "force" | "destination" | "worktree" | undefined {
151+ type WorktreeMismatch =
152+ | { kind : "force" ; flag : string }
153+ | { kind : "destination" }
154+ | { kind : "worktree" } ;
155+
156+ function worktreeMismatchKind ( segment : string ) : WorktreeMismatch | undefined {
154157 const tokens = tokenize ( segment ) ;
155158 if ( tokens [ 0 ] !== "git" || tokens [ 1 ] !== "worktree" ) return undefined ;
156159 if ( tokens [ 2 ] !== "add" && tokens [ 2 ] !== "remove" ) return undefined ;
157- if ( tokens . slice ( 3 ) . some ( isWorktreeForceFlag ) ) return "force" ;
160+ const flag = tokens . slice ( 3 ) . find ( isWorktreeForceFlag ) ;
161+ if ( flag !== undefined ) return { kind : "force" , flag } ;
158162 // `add` takes a destination for the new worktree; `remove` names an
159163 // existing worktree, so only `add` gets the destination noun.
160- return tokens [ 2 ] === "remove" ? "worktree" : "destination" ;
164+ return tokens [ 2 ] === "remove"
165+ ? { kind : "worktree" }
166+ : { kind : "destination" } ;
161167}
162168
163169// Explains a grant mismatch: a standing grant covers the segment, but the
@@ -171,13 +177,13 @@ function grantMismatchNotice(
171177 return "A standing grant matches this command, but it references a sensitive path, so it still needs approval." ;
172178 }
173179 const worktreeKind = worktreeMismatchKind ( segment ) ;
174- if ( worktreeKind === "force" ) {
175- return " A standing grant matches this command, but it uses --force , so it still needs approval." ;
180+ if ( worktreeKind ?. kind === "force" ) {
181+ return ` A standing grant matches this command, but it uses ${ worktreeKind . flag } , so it still needs approval.` ;
176182 }
177- if ( worktreeKind === "destination" ) {
183+ if ( worktreeKind ?. kind === "destination" ) {
178184 return "A standing grant matches this command, but the worktree destination is outside the approved locations, so it still needs approval." ;
179185 }
180- if ( worktreeKind === "worktree" ) {
186+ if ( worktreeKind ?. kind === "worktree" ) {
181187 return "A standing grant matches this command, but the worktree is outside the approved locations, so it still needs approval." ;
182188 }
183189 return "A standing grant matches this command, but it targets a path outside the workspace, so it still needs approval." ;
0 commit comments