feat: Adding the parameter distinguishes between human and agent input.

This commit is contained in:
kite 2026-05-11 11:28:56 +08:00
parent b73e05cad4
commit 5f09e5e8b6
2 changed files with 35 additions and 3 deletions

View file

@ -101,6 +101,7 @@ type reviewOptions struct {
to string
commit string
outputFormat string
audience string // --audience: "human" (default) or "agent"
concurrency int
perFileTimeout int
showHelp bool
@ -120,6 +121,7 @@ func parseReviewFlags(args []string) (reviewOptions, error) {
a.StringVarP(&opts.outputFormat, "format", "f", "text", "output format: text or json")
a.IntVar(&opts.concurrency, "concurrency", 8, "max concurrent file reviews")
a.IntVar(&opts.perFileTimeout, "timeout", 10, "per-file timeout in minutes")
a.StringVar(&opts.audience, "audience", "human", "output audience: human (show progress) or agent (summary only)")
if err := a.Parse(args); err != nil {
return opts, fmt.Errorf("parse flags: %w", err)
@ -145,6 +147,12 @@ func parseReviewFlags(args []string) (reviewOptions, error) {
return opts, fmt.Errorf("--to is required when --from is specified")
}
switch opts.audience {
case "human", "agent":
default:
return opts, fmt.Errorf("invalid --audience value %q: must be 'human' or 'agent'", opts.audience)
}
return opts, nil
}
@ -170,6 +178,9 @@ Examples:
ocr review --format json
ocr review -f json
# Agent mode (summary only, no progress lines)
ocr review --audience agent
Flags:`)
fs := flag.NewFlagSet("print", flag.ContinueOnError)
var d reviewOptions
@ -180,6 +191,7 @@ Flags:`)
fs.StringVar(&d.commit, "commit", "", "single commit hash or tag to review (vs its parent) (shorthand: -c)")
fs.IntVar(&d.concurrency, "concurrency", 8, "max concurrent file reviews")
fs.IntVar(&d.perFileTimeout, "timeout", 10, "per-file timeout in minutes")
fs.StringVar(&d.audience, "audience", "human", "output audience: human (show progress) or agent (summary only)")
fs.PrintDefaults()
}

View file

@ -109,9 +109,15 @@ func runReview(args []string) error {
Model: model,
})
// Silence progress output in JSON mode so stdout stays clean.
if opts.outputFormat == "json" {
defer stdout.Quiet()()
// Silence progress output during execution; restore before Summary in agent mode.
var unsilence func()
if opts.outputFormat == "json" || opts.audience == "agent" {
unsilence = stdout.Quiet()
defer func() {
if unsilence != nil {
unsilence()
}
}()
}
ctx, span := telemetry.StartSpan(context.Background(), "review.run")
@ -139,11 +145,25 @@ func runReview(args []string) error {
return outputJSONNoFiles()
}
// In agent mode, restore stdout so Summary reaches the terminal.
if opts.audience == "agent" && unsilence != nil {
unsilence()
unsilence = nil
}
telemetry.PrintTraceSummary(ag.FilesReviewed(), int64(len(comments)), ag.TotalInputTokens(), ag.TotalOutputTokens(), ag.TotalTokensUsed(), duration)
if opts.outputFormat == "json" {
return outputJSONWithWarnings(comments, ag.Warnings())
}
if opts.audience == "agent" {
if len(comments) == 0 {
fmt.Println("No comments generated.")
} else {
fmt.Printf("%d comment(s) generated.\n", len(comments))
}
return nil
}
outputTextWithWarnings(comments, ag.Warnings())
return nil