diff --git a/internal/agentexec/nats.go b/internal/agentexec/nats.go index 1fef95da5..2cefd4df8 100644 --- a/internal/agentexec/nats.go +++ b/internal/agentexec/nats.go @@ -14,20 +14,26 @@ import ( ) // AgentRequestMessage is the NATS payload for an agent stage execution request. +// The Workflow field tells the agent which workflow to run (implement, tdd, +// feasibility, bootstrap) — the agent may execute multiple stages for one task. type AgentRequestMessage struct { TaskID int64 `json:"task_id"` Attempt int `json:"attempt"` Stage string `json:"stage"` + Workflow string `json:"workflow,omitempty"` Workspace string `json:"workspace"` Request Request `json:"request"` Providers map[string]Provider `json:"providers,omitempty"` } // AgentResponseEnvelope is the response payload published to the reply inbox. +// Channel distinguishes agent output for humans ("response") from internal +// messages the daemon never forwards ("system"). PRD §2. type AgentResponseEnvelope struct { Version int `json:"version"` Result Result `json:"result"` Error string `json:"error,omitempty"` + Channel string `json:"channel,omitempty"` // "response" (default) or "system" } const defaultAgentTimeout = 30 * time.Minute @@ -65,6 +71,7 @@ func (r *NATSRunner) Run(ctx context.Context, workspace string, req Request) (Re TaskID: req.TaskID, Attempt: req.Attempt, Stage: req.Stage, + Workflow: req.Workflow, Workspace: workspace, Request: req, Providers: r.Providers, diff --git a/internal/agentexec/protocol.go b/internal/agentexec/protocol.go index 7277d8e05..4cdee9fc4 100644 --- a/internal/agentexec/protocol.go +++ b/internal/agentexec/protocol.go @@ -61,6 +61,7 @@ type Request struct { TaskID int64 `json:"task_id"` Attempt int `json:"attempt"` Stage string `json:"stage"` + Workflow string `json:"workflow,omitempty"` Model string `json:"model"` Mission string `json:"mission"` ExtraRules string `json:"extra_rules,omitempty"` diff --git a/internal/nats/subjects.go b/internal/nats/subjects.go index 50bff5116..9106231cd 100644 --- a/internal/nats/subjects.go +++ b/internal/nats/subjects.go @@ -54,6 +54,20 @@ func SubjectForAgentRequest(taskID int64) string { return fmt.Sprintf("archie.agent.%d.request", taskID) } +// SubjectForAgentResponse returns the subject for agent output destined +// for human channels. The daemon reviews messages on this subject before +// forwarding to issue comments, labels, or PRs. PRD §2. +func SubjectForAgentResponse(taskID int64) string { + return fmt.Sprintf("archie.agent.%d.response", taskID) +} + +// SubjectForAgentSystem returns the subject for internal agent messages +// (log dumps, health, PII warnings). The daemon reads these for +// observability and never forwards them. PRD §2. +func SubjectForAgentSystem(taskID int64) string { + return fmt.Sprintf("archie.agent.%d.system", taskID) +} + // ReplyHeader is the custom NATS header carrying the daemon's reply inbox. // JetStream's PublishMsg consumes the Reply field internally for PubAck, so // the reply address is carried via this header instead. diff --git a/internal/workflow/agent.go b/internal/workflow/agent.go index f941a9edf..d21569c5d 100644 --- a/internal/workflow/agent.go +++ b/internal/workflow/agent.go @@ -42,6 +42,12 @@ type AgentStage struct { // OnResult consumes a successful (passed) result. Parked and idle // results park the workflow before OnResult is called. OnResult func(*TaskContext, agentexec.Result) error + // ReviewResult gates agent output before OnResult forwards it to + // human channels. The daemon calls this hook to review stage output + // (issue comments, PR bodies) before human delivery. Return an + // error to block the stage. Nil means pass-through — no review. + // PRD §1: daemon reviews agent responses before forwarding. + ReviewResult func(*TaskContext, agentexec.Result) error } // Stage adapts the AgentStage to the engine. @@ -103,6 +109,7 @@ func (a AgentStage) Stage() Stage { TaskID: tc.Task.ID, Attempt: tc.Task.Attempt, Stage: a.Name, + Workflow: tc.Task.Workflow, Model: modelRef, Mission: missionWithSkill(tc, a.Mission(tc)), ExtraRules: a.ExtraRules, @@ -147,6 +154,12 @@ func (a AgentStage) Stage() Stage { } return fmt.Errorf("agent %s (%s): %s", res.Status, res.StopReason, clip(detail, 2000)) } + // Gatekeeping: the daemon reviews agent output before human delivery. + if a.ReviewResult != nil { + if err := a.ReviewResult(tc, res); err != nil { + return fmt.Errorf("review: %w", err) + } + } if a.OnResult != nil { return a.OnResult(tc, res) }