feat: 增加 --debug模式

This commit is contained in:
kite 2026-04-28 15:23:22 +08:00
parent 223a6ef4f9
commit a896ba5aca
5 changed files with 13 additions and 1 deletions

View file

@ -103,6 +103,7 @@ type reviewOptions struct {
outputFormat string
concurrency int
perFileTimeout int
debug bool
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.BoolVar(&opts.debug, "debug", false, "enable debug mode (write session dump to temp/)")
if err := a.Parse(args); err != nil {
return opts, fmt.Errorf("parse flags: %w", err)
@ -180,6 +182,7 @@ Flags:`)
fs.StringVar(&d.commit, "commit", "", "single commit hash or tag to review (vs its parent) (shorthand: -c)")
fs.IntVar(&d.concurrency, "concurrency", 4, "max concurrent file reviews")
fs.IntVar(&d.perFileTimeout, "timeout", 10, "per-file timeout in minutes")
fs.BoolVar(&d.debug, "debug", false, "enable debug mode (write session dump to temp/)")
fs.PrintDefaults()
}

View file

@ -100,6 +100,7 @@ func runReview(args []string) error {
CommentWorkerPool: agent.NewCommentWorkerPool(8),
MaxConcurrency: opts.concurrency,
PerFileTimeoutMinutes: opts.perFileTimeout,
Debug: opts.debug,
Model: model,
})

BIN
dist/opencodereview vendored

Binary file not shown.

View file

@ -80,6 +80,9 @@ type Args struct {
// template phases (plan/memory_compression) don't specify one.
Model string
// Debug enables debug mode which writes a session dump to temp/.
Debug bool
// Session is an optional session history instance for collecting conversation records.
// When nil, a default one is created automatically.
Session *session.SessionHistory
@ -155,6 +158,7 @@ func New(args Args) *Agent {
if args.Session == nil {
args.Session = session.New("", args.RepoDir)
}
args.Session.Debug = args.Debug
return &Agent{
args: args,
session: args.Session,

View file

@ -31,6 +31,7 @@ type SessionHistory struct {
RepoDir string
StartTime time.Time
EndTime time.Time
Debug bool
FileSessions map[string]*FileSession
}
@ -107,8 +108,11 @@ func (sh *SessionHistory) GetOrCreateFileSession(filePath string) *FileSession {
func (sh *SessionHistory) Finalize() {
sh.mu.Lock()
sh.EndTime = time.Now()
debug := sh.Debug
sh.mu.Unlock()
sh.writeDebugDump()
if debug {
sh.writeDebugDump()
}
}
// --- Debug Dump ---