@@ -54,6 +54,7 @@ function buildCommonOptions(
5454 theme ?: string ;
5555 agentContext ?: string ;
5656 pager ?: boolean ;
57+ watch ?: boolean ;
5758 } ,
5859 argv : string [ ] ,
5960) : CommonOptions {
@@ -62,14 +63,15 @@ function buildCommonOptions(
6263 theme : options . theme ,
6364 agentContext : options . agentContext ,
6465 pager : options . pager ? true : undefined ,
66+ watch : options . watch ? true : undefined ,
6567 lineNumbers : resolveBooleanFlag ( argv , "--line-numbers" , "--no-line-numbers" ) ,
6668 wrapLines : resolveBooleanFlag ( argv , "--wrap" , "--no-wrap" ) ,
6769 hunkHeaders : resolveBooleanFlag ( argv , "--hunk-headers" , "--no-hunk-headers" ) ,
6870 agentNotes : resolveBooleanFlag ( argv , "--agent-notes" , "--no-agent-notes" ) ,
6971 } ;
7072}
7173
72- /** Attach the shared mode/theme/agent-context flags to a subcommand parser. */
74+ /** Attach the shared view flags to a subcommand parser. */
7375function applyCommonOptions ( command : Command ) {
7476 return command
7577 . option ( "--mode <mode>" , "layout mode: auto, split, stack" , parseLayoutMode )
@@ -86,6 +88,11 @@ function applyCommonOptions(command: Command) {
8688 . option ( "--no-agent-notes" , "hide agent notes by default" ) ;
8789}
8890
91+ /** Attach auto-refresh support to review commands that can reopen their source input. */
92+ function applyWatchOption ( command : Command ) {
93+ return command . option ( "--watch" , "auto-reload when the current diff input changes" ) ;
94+ }
95+
8996/** Resolve the CLI version from the nearest shipped package manifest. */
9097function resolveCliVersion ( ) {
9198 const candidatePaths = [
@@ -223,7 +230,9 @@ function resolveExplicitSessionSelector(
223230/** Parse the overloaded `hunk diff` command. */
224231async function parseDiffCommand ( tokens : string [ ] , argv : string [ ] ) : Promise < ParsedCliInput > {
225232 const { commandTokens, pathspecs } = splitPathspecArgs ( tokens ) ;
226- const command = createCommand ( "diff" , "review Git diffs or compare two concrete files" )
233+ const command = applyWatchOption (
234+ createCommand ( "diff" , "review Git diffs or compare two concrete files" ) ,
235+ )
227236 . option ( "--staged" , "show staged changes instead of the working tree" )
228237 . option ( "--cached" , "alias for --staged" )
229238 . argument ( "[targets...]" ) ;
@@ -287,7 +296,9 @@ async function parseDiffCommand(tokens: string[], argv: string[]): Promise<Parse
287296/** Parse the Git-style `hunk show` command. */
288297async function parseShowCommand ( tokens : string [ ] , argv : string [ ] ) : Promise < ParsedCliInput > {
289298 const { commandTokens, pathspecs } = splitPathspecArgs ( tokens ) ;
290- const command = createCommand ( "show" , "review the last commit or a given ref" ) . argument ( "[ref]" ) ;
299+ const command = applyWatchOption (
300+ createCommand ( "show" , "review the last commit or a given ref" ) ,
301+ ) . argument ( "[ref]" ) ;
291302
292303 let parsedRef : string | undefined ;
293304 let parsedOptions : Record < string , unknown > = { } ;
@@ -313,9 +324,8 @@ async function parseShowCommand(tokens: string[], argv: string[]): Promise<Parse
313324
314325/** Parse the patch-file / stdin patch entrypoint. */
315326async function parsePatchCommand ( tokens : string [ ] , argv : string [ ] ) : Promise < ParsedCliInput > {
316- const command = createCommand (
317- "patch" ,
318- "review a patch file, or read a patch from stdin" ,
327+ const command = applyWatchOption (
328+ createCommand ( "patch" , "review a patch file, or read a patch from stdin" ) ,
319329 ) . argument ( "[file]" ) ;
320330
321331 let parsedFile : string | undefined ;
@@ -365,7 +375,7 @@ async function parsePagerCommand(
365375
366376/** Parse Git difftool-style two-file review commands. */
367377async function parseDifftoolCommand ( tokens : string [ ] , argv : string [ ] ) : Promise < ParsedCliInput > {
368- const command = createCommand ( "difftool" , "review Git difftool file pairs" )
378+ const command = applyWatchOption ( createCommand ( "difftool" , "review Git difftool file pairs" ) )
369379 . argument ( "<left>" )
370380 . argument ( "<right>" )
371381 . argument ( "[path]" ) ;
@@ -912,9 +922,8 @@ async function parseStashCommand(tokens: string[], argv: string[]): Promise<Pars
912922 throw new Error ( "Only `hunk stash show` is supported." ) ;
913923 }
914924
915- const command = createCommand (
916- "stash show" ,
917- "review a stash entry as a full Hunk changeset" ,
925+ const command = applyWatchOption (
926+ createCommand ( "stash show" , "review a stash entry as a full Hunk changeset" ) ,
918927 ) . argument ( "[ref]" ) ;
919928
920929 let parsedRef : string | undefined ;
0 commit comments