Files
archie/internal/domain/workflow/agent_run.go
T
sam d320a1a01a feat(eda): workflow inputs, optional repository and agent profiles
Workflow definitions declare inputs, repository (none, optional or
required; default required) and profile. A binding assigns each input
from a mapped parameter or a constant and may take its repository from a
parameter, which must name a configured repo; both are checked when the
binding is saved and again at dispatch. Inputs travel as structured task
data (tasks.inputs, the task brief, and a JSON block in the agent's
mission), never as body text.

A task with no repository runs in a per-task scratch workspace with no
clone and no publication grant. The agent.run step runs one mission
without a repository and finishes the task in the new completed status.

Agent profiles live under [containers.profiles.<name>]: an image and an
allowlist over the tools archie adds (MCP, scripts, plugins).
[containers].image is the default profile; an unconfigured profile parks
the task. The workflow is now pinned before the container starts so the
profile can choose its image.

Also stop two archied tests writing embedded NATS state into the package
directory, refuse an empty state_dir for embedded NATS, and drop the NATS
store files an earlier lane commit tracked.
2026-09-24 20:29:33 +10:00

84 lines
2.6 KiB
Go

package workflow
import (
"context"
"encoding/json"
"fmt"
"strings"
"gopkg.in/yaml.v3"
"github.com/samcharles93/archie-core/internal/agentexec"
)
// AgentRunStepName is the step type that runs one agent mission and finishes
// the workflow with its summary. It needs no repository: the agent works in
// whatever workspace the task has, a worktree or a scratch directory.
const AgentRunStepName = "agent.run"
// agentRunSettings are the agent.run step's settings.
type agentRunSettings struct {
// Mission is what the agent is asked to do. The workflow's inputs are
// appended to it as structured data.
Mission string `yaml:"mission"`
// Role selects the model (cfg.Models[Role]); empty means builder.
Role string `yaml:"role"`
// ReadOnly restricts the agent to read-only tools.
ReadOnly bool `yaml:"read_only"`
}
// AgentRunStepType contributes the agent.run step type.
func AgentRunStepType() StepType {
return StepType{Name: AgentRunStepName, Factory: newAgentRunStage}
}
func newAgentRunStage(settings yaml.Node) (Stage, error) {
var s agentRunSettings
if settings.Kind == 0 {
return Stage{}, fmt.Errorf("%s: settings.mission is required", AgentRunStepName)
}
if err := settings.Decode(&s); err != nil {
return Stage{}, fmt.Errorf("%s: %w", AgentRunStepName, err)
}
if strings.TrimSpace(s.Mission) == "" {
return Stage{}, fmt.Errorf("%s: settings.mission is required", AgentRunStepName)
}
role := s.Role
if role == "" {
role = "builder"
}
agent := AgentStage{
Name: AgentRunStepName,
Role: role,
ReadOnly: s.ReadOnly,
Mission: func(*TaskContext) string { return s.Mission },
OnResult: func(tc *TaskContext, res agentexec.Result) error {
tc.Outcome = Outcome{Status: StatusCompleted, Detail: res.Summary}
return nil
},
}.Stage()
return Stage{Name: AgentRunStepName, Run: func(ctx context.Context, tc *TaskContext) error {
if tc.Dir == "" {
dir, branch, err := tc.Trees.Prepare(ctx, tc.Task.Owner, tc.Task.Repo, tc.Repo.BaseBranch(), tc.Task.IssueNumber, tc.Task.Title, tc.Task.Body, tc.Task.Labels)
if err != nil {
return fmt.Errorf("%s: workspace: %w", AgentRunStepName, err)
}
tc.Dir, tc.Branch = dir, branch
}
return agent.Run(ctx, tc)
}}, nil
}
// missionWithInputs appends the task's workflow inputs to a mission as a JSON
// block, so the agent reads them as structured data rather than prose.
func missionWithInputs(t *Task, mission string) string {
if t == nil || len(t.Inputs) == 0 {
return mission
}
data, err := json.MarshalIndent(t.Inputs, "", " ")
if err != nil {
return mission
}
return mission + "\n\nWorkflow inputs (JSON):\n```json\n" + string(data) + "\n```"
}