feat: assignee-driven pickup + repro proof on TDD PRs
- Issues are picked up by assigning them to the bot (tink-bot style) instead of by label; labels now only influence workflow routing - TDD: capture the failing 'go test' output after the repro stage (parking if it unexpectedly passes) and post it on the PR as a code block — evidence the bug was reproduced before the fix - TDD fix stage now write-protects *_test.go via agentloop.ProtectPaths (environmental enforcement, replacing the advisory prompt rule) - OpenPR extracted so stages can act after the PR exists in the same stage (the engine stops at the first stage with an outcome)
This commit is contained in:
1 parent
5465442cb3
commit
94a58e11b6
6 files changed
+74
-22
No files matched your search
@@ -87,7 +87,7 @@ func (d *Daemon) Cycle(ctx context.Context) {
|
||||
|
||||
func (d *Daemon) poll(ctx context.Context) {
|
||||
for _, repo := range d.Cfg.Repos {
|
||||
issues, err := d.Forge.LabelledIssues(ctx, repo.Owner, repo.Name, d.Cfg.Label)
|
||||
issues, err := d.Forge.AssignedIssues(ctx, repo.Owner, repo.Name, d.Cfg.BotUser)
|
||||
if err != nil {
|
||||
d.Log.Error("poll failed", "repo", repo.FullName(), "err", err)
|
||||
continue
|
||||
|
||||
@@ -38,12 +38,14 @@ func (c *Client) AcceptInvitations(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LabelledIssues returns open issues carrying the label, excluding PRs.
|
||||
func (c *Client) LabelledIssues(ctx context.Context, owner, repo, label string) ([]*github.Issue, error) {
|
||||
// AssignedIssues returns open issues assigned to the given user,
|
||||
// excluding PRs. Assigning an issue to the bot is how work is handed to
|
||||
// archie (tink-bot style); labels only influence workflow routing.
|
||||
func (c *Client) AssignedIssues(ctx context.Context, owner, repo, assignee string) ([]*github.Issue, error) {
|
||||
var out []*github.Issue
|
||||
opts := &github.IssueListByRepoOptions{
|
||||
State: "open",
|
||||
Labels: []string{label},
|
||||
Assignee: assignee,
|
||||
ListOptions: github.ListOptions{PerPage: 50},
|
||||
}
|
||||
for {
|
||||
|
||||
@@ -30,6 +30,10 @@ type AgentStage struct {
|
||||
// MaxSteps overrides the configured step budget when > 0 (planner
|
||||
// stages are cheaper than builder stages).
|
||||
MaxSteps int
|
||||
// ProtectPaths blocks write/edit on matching paths for this stage —
|
||||
// an environmental constraint, not a prompt rule (TDD's fix stage
|
||||
// protects the committed repro tests).
|
||||
ProtectPaths func(path string) bool
|
||||
// OnResult consumes a successful (passed) result. Parked and idle
|
||||
// results park the workflow before OnResult is called.
|
||||
OnResult func(*TaskContext, agentloop.Result) error
|
||||
@@ -74,9 +78,10 @@ func (a AgentStage) Stage() Stage {
|
||||
Preflight: []agentloop.GateCommand{
|
||||
{Name: "go-version", Argv: []string{"go", "version"}},
|
||||
},
|
||||
Budget: budget,
|
||||
ReadOnly: a.ReadOnly,
|
||||
Logger: tc.Log.With("stage", a.Name, "model", modelRef),
|
||||
Budget: budget,
|
||||
ReadOnly: a.ReadOnly,
|
||||
ProtectPaths: a.ProtectPaths,
|
||||
Logger: tc.Log.With("stage", a.Name, "model", modelRef),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent run: %w", err)
|
||||
|
||||
@@ -73,18 +73,26 @@ func StageDiffCap() Stage {
|
||||
}}
|
||||
}
|
||||
|
||||
// OpenPR opens the task's pull request, records its number, and sets
|
||||
// the terminal pr_open outcome. Stages that need to act after the PR
|
||||
// exists (e.g. posting evidence comments) call this and then do so in
|
||||
// the same stage — the engine stops at the first stage with an outcome.
|
||||
func OpenPR(ctx context.Context, tc *TaskContext, body string) error {
|
||||
t := tc.Task
|
||||
title := fmt.Sprintf("%s (archie)", t.Title)
|
||||
num, err := tc.Forge.CreatePR(ctx, t.Owner, t.Repo, title, tc.Branch, tc.Repo.BaseBranch(), body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.PRNumber = num
|
||||
tc.Outcome = Outcome{Status: store.StatusPROpen, Detail: fmt.Sprintf("PR #%d", num)}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StageOpenPR opens the pull request with the given body and records it.
|
||||
func StageOpenPR(body func(*TaskContext) string) Stage {
|
||||
return Stage{Name: "open-pr", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
t := tc.Task
|
||||
title := fmt.Sprintf("%s (archie)", t.Title)
|
||||
num, err := tc.Forge.CreatePR(ctx, t.Owner, t.Repo, title, tc.Branch, tc.Repo.BaseBranch(), body(tc))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.PRNumber = num
|
||||
tc.Outcome = Outcome{Status: store.StatusPROpen, Detail: fmt.Sprintf("PR #%d", num)}
|
||||
return nil
|
||||
return OpenPR(ctx, tc, body(tc))
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/ai-sdk/agentloop"
|
||||
)
|
||||
@@ -67,6 +70,19 @@ func TDD() Workflow {
|
||||
},
|
||||
}.Stage(),
|
||||
|
||||
// Capture the failing test run — the proof the repro
|
||||
// reproduces the bug, posted on the PR later.
|
||||
{Name: "capture-proof", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
cmd := exec.CommandContext(ctx, "go", "test", "./...", "-count=1")
|
||||
cmd.Dir = tc.Dir
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
return fmt.Errorf("repro tests unexpectedly pass after commit — the bug is not captured")
|
||||
}
|
||||
tc.ReproProof = clip(string(out), 4000)
|
||||
return nil
|
||||
}},
|
||||
|
||||
StageCommit("commit-repro", func(tc *TaskContext) string {
|
||||
return fmt.Sprintf("test: failing repro for #%d", tc.Task.IssueNumber)
|
||||
}),
|
||||
@@ -77,8 +93,13 @@ func TDD() Workflow {
|
||||
Gate: func(tc *TaskContext) agentloop.GateConfig {
|
||||
return GateFromRepo(tc.Repo, tc.Cfg.Budgets)
|
||||
},
|
||||
// Environmental, not advisory: the fix stage cannot touch
|
||||
// test files at all — the committed repro is the spec.
|
||||
ProtectPaths: func(path string) bool {
|
||||
return strings.HasSuffix(path, "_test.go")
|
||||
},
|
||||
ExtraRules: "The repro tests written in the previous stage are the bug's specification. " +
|
||||
"Never weaken, skip, or delete them — make them pass by fixing the code they exercise.",
|
||||
"Test files are write-protected in this stage — make them pass by fixing the code they exercise.",
|
||||
Mission: func(tc *TaskContext) string {
|
||||
return fmt.Sprintf(
|
||||
"Fix the bug in the repository %s. Failing repro tests are already committed; make them pass.\n\n"+
|
||||
@@ -99,10 +120,23 @@ func TDD() Workflow {
|
||||
return fmt.Sprintf("fix: %s (archie)\n\nFixes #%d", tc.Task.Title, tc.Task.IssueNumber)
|
||||
}),
|
||||
StageDiffCap(),
|
||||
StageOpenPR(func(tc *TaskContext) string {
|
||||
return fmt.Sprintf("%s\n\n---\n*workflow: tdd (failing repro committed first) · %d iterations · %d tokens*\n\nCloses #%d",
|
||||
|
||||
// Open the PR, then post the captured failing-test output as
|
||||
// evidence the bug was reproduced before the fix.
|
||||
{Name: "open-pr", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
body := fmt.Sprintf("%s\n\n---\n*workflow: tdd (failing repro committed first) · %d iterations · %d tokens*\n\nCloses #%d",
|
||||
tc.BuildSummary, tc.Task.Iterations, tc.Task.TokensUsed, tc.Task.IssueNumber)
|
||||
}),
|
||||
if err := OpenPR(ctx, tc, body); err != nil {
|
||||
return err
|
||||
}
|
||||
if tc.ReproProof != "" {
|
||||
proof := fmt.Sprintf("**Proof the repro tests failed before the fix** (commit 1 of this PR):\n\n```\n%s\n```", tc.ReproProof)
|
||||
if err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, proof); err != nil {
|
||||
tc.Log.Warn("failed to post repro proof", "err", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,9 @@ type TaskContext struct {
|
||||
Branch string
|
||||
// BuildSummary is the builder agent's finish summary — the PR body.
|
||||
BuildSummary string
|
||||
// ReproProof is the captured failing-test output from a TDD repro
|
||||
// stage, posted on the PR as evidence the bug was reproduced.
|
||||
ReproProof string
|
||||
// Outcome describes where the task ended up; the engine applies it.
|
||||
Outcome Outcome
|
||||
}
|
||||
@@ -140,8 +143,8 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
t.ParkReason = reason
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = tc.Store.Transition(ctx, t.ID, store.StatusRunning, store.StatusParked, reason)
|
||||
body := fmt.Sprintf("**archie parked this task.**\n\n```\n%s\n```\n\nThe worktree is kept for inspection. Re-add the `%s` label after addressing this to retry.",
|
||||
clip(reason, 3000), tc.Cfg.Label)
|
||||
body := fmt.Sprintf("**archie parked this task.**\n\n```\n%s\n```\n\nThe worktree is kept for inspection.",
|
||||
clip(reason, 3000))
|
||||
if err := tc.Forge.Comment(ctx, t.Owner, t.Repo, t.IssueNumber, body); err != nil {
|
||||
tc.Log.Error("failed to post park comment", "err", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user