Commit 6ff239ee moved the remediate resume into daemon worktree
preparation and deleted StageResumeWorktree together with the Dir/Resume
pair it called, but nothing in the workflow replaced the binding it did:
TaskContext.Dir and Branch stayed empty for a whole run, so
remediate-build ran the builder with no workspace and
remediate-commit-push called CommitAll/Push with an empty dir and branch.
Extend the workflow-side Trees seam with the prepare target, mirroring
the daemon's mode-aware worktree.Manager.Prepare: PrepareFresh lands on
base, a non-empty target is the branch a resume continues. Remediate now
stages StagePrepareWorktreeOnBranch before any agent stage, binding the
same directory the daemon prepared and the task's PR branch, and failing
closed when the task has no branch rather than preparing base. The
container adapter returns the requested resume target verbatim.
Refs archie-core-h4tk
84 lines
2.6 KiB
Go
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, PrepareFresh)
|
|
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```"
|
|
}
|