-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtracker_interviewer.go
More file actions
98 lines (92 loc) · 3.49 KB
/
Copy pathtracker_interviewer.go
File metadata and controls
98 lines (92 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// ABOUTME: Interviewer resolution — selects the human-gate handler from Config.
// ABOUTME: Split out of tracker.go so the root file stays focused on the API surface (#450).
package tracker
import (
"fmt"
"github.com/2389-research/tracker/agent"
"github.com/2389-research/tracker/internal/diag"
"github.com/2389-research/tracker/llm"
"github.com/2389-research/tracker/pipeline/handlers"
)
// resolveInterviewer selects an interviewer based on Config.
// Returns nil if no automation is configured (interactive/default mode).
// Priority: Interviewer > AutoApprove > WebhookGate > Autopilot.
// When Backend is "claude-code", prefers ClaudeCodeAutopilotInterviewer.
//
// The return type is the base handlers.Interviewer: an injected Config.Interviewer
// may implement only Ask, and the human handler upgrades to the freeform/interview
// modes via type assertion. The automated interviewers below all satisfy the
// richer interfaces regardless.
func resolveInterviewer(cfg Config, client *llm.Client, completer agent.Completer) (handlers.Interviewer, error) {
if cfg.Interviewer != nil {
return cfg.Interviewer, nil
}
if cfg.AutoApprove {
return &handlers.AutoApproveFreeformInterviewer{}, nil
}
if cfg.WebhookGate != nil {
return resolveWebhookInterviewer(cfg.WebhookGate)
}
if cfg.Autopilot == "" {
return nil, nil
}
return resolveAutopilot(cfg, client, completer)
}
// resolveWebhookInterviewer creates a WebhookInterviewer from a WebhookGateConfig.
// Returns an error if WebhookURL is not set.
func resolveWebhookInterviewer(wgc *WebhookGateConfig) (handlers.FreeformInterviewer, error) {
if wgc.WebhookURL == "" {
return nil, fmt.Errorf("WebhookGate.WebhookURL is required")
}
addr := wgc.CallbackAddr
if addr == "" {
// Default to an OS-assigned ephemeral port so concurrent library-driven
// runs (e.g. a service running many pipelines) never collide on a fixed
// port. The actual bound address is advertised to the external service
// via each gate payload's callback_url, so a random port is transparent.
addr = ":0"
}
wi := handlers.NewWebhookInterviewer(wgc.WebhookURL, addr)
if wgc.Timeout > 0 {
wi.Timeout = wgc.Timeout
}
if wgc.TimeoutAction != "" {
wi.DefaultAction = wgc.TimeoutAction
}
if wgc.AuthHeader != "" {
wi.AuthHeader = wgc.AuthHeader
}
if wgc.RunID != "" {
wi.RunID = wgc.RunID
}
return wi, nil
}
// resolveAutopilot builds an autopilot interviewer for the given persona and backend.
func resolveAutopilot(cfg Config, client *llm.Client, completer agent.Completer) (handlers.FreeformInterviewer, error) {
persona, err := handlers.ParsePersona(cfg.Autopilot)
if err != nil {
return nil, fmt.Errorf("invalid autopilot persona %q: %w", cfg.Autopilot, err)
}
if cfg.Backend == "claude-code" {
if iv, ccErr := handlers.NewClaudeCodeAutopilotInterviewer(persona); ccErr == nil {
return iv, nil
}
diag.Infof("[tracker] claude-code autopilot init failed, trying native")
}
client = resolveAutopilotClient(client, completer)
if client == nil {
return nil, fmt.Errorf("autopilot %q requires an LLM client (set Config.LLMClient or configure API keys)", cfg.Autopilot)
}
return handlers.NewAutopilotInterviewer(client, persona), nil
}
// resolveAutopilotClient returns the LLM client for native autopilot,
// trying a type assertion on completer if client is nil.
func resolveAutopilotClient(client *llm.Client, completer agent.Completer) *llm.Client {
if client != nil {
return client
}
if lc, ok := completer.(*llm.Client); ok {
return lc
}
return nil
}