diff --git a/config.example.toml b/config.example.toml index 1546ff086..539703aae 100644 --- a/config.example.toml +++ b/config.example.toml @@ -36,7 +36,9 @@ gate_max_failures = 5 owner = "samcharles93" name = "todo" base = "main" +protect = ["_templ.go"] gate = [ + ["templ", "generate", "./components/"], ["go", "vet", "./..."], ["go", "build", "./..."], ["golangci-lint", "run"], diff --git a/internal/config/config.go b/internal/config/config.go index e1309f862..0b27d9d91 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "time" "github.com/BurntSushi/toml" @@ -36,6 +37,20 @@ type Repo struct { // [["go","vet","./..."], ["task","check"]]. Workflow stages may // extend or override it (a TDD repro stage inverts the test command). Gate [][]string `toml:"gate"` + // Protect lists path suffixes agents must never write directly — + // generated files (e.g. "_templ.go") whose sources they should edit + // instead. Enforced environmentally via agentloop.ProtectPaths. + Protect []string `toml:"protect"` +} + +// Protected reports whether path matches a protected suffix. +func (r Repo) Protected(path string) bool { + for _, suf := range r.Protect { + if strings.HasSuffix(path, suf) { + return true + } + } + return false } func (r Repo) FullName() string { return r.Owner + "/" + r.Name } diff --git a/internal/store/store.go b/internal/store/store.go index 1ef7bd33e..95726882f 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -200,17 +200,20 @@ func (s *Store) WaitingTasks(ctx context.Context) ([]Task, error) { return out, rows.Err() } -// Requeue puts a task back on the queue under a specific workflow — -// the waiting_human → approved → implement handoff. +// Requeue puts a task back on the queue. A non-empty workflow forces it +// (the waiting_human → approved → implement handoff); empty keeps the +// task's current workflow (retrying a parked task). func (s *Store) Requeue(ctx context.Context, taskID int64, fromStatus, workflow string) error { if _, err := s.db.ExecContext(ctx, ` - UPDATE tasks SET status='queued', workflow=?, stage='', updated_at=datetime('now') - WHERE id=?`, workflow, taskID); err != nil { + UPDATE tasks SET status='queued', + workflow=CASE WHEN ?='' THEN workflow ELSE ? END, + stage='', park_reason='', updated_at=datetime('now') + WHERE id=?`, workflow, workflow, taskID); err != nil { return err } _, err := s.db.ExecContext(ctx, `INSERT INTO transitions (task_id, from_status, to_status, detail) VALUES (?, ?, 'queued', ?)`, - taskID, fromStatus, "requeued as "+workflow) + taskID, fromStatus, "requeued "+workflow) return err } diff --git a/internal/workflow/agent.go b/internal/workflow/agent.go index a32d8cc0a..dc4929043 100644 --- a/internal/workflow/agent.go +++ b/internal/workflow/agent.go @@ -33,8 +33,10 @@ type AgentStage struct { 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 + // protects the committed repro tests; every builder stage protects + // the repo's generated files). The returned matcher is combined + // with the repo's configured protected suffixes. + ProtectPaths func(*TaskContext) func(path string) bool // Extra adds stage-specific tools to the agent's toolset (e.g. // feasibility's decide tool). Extra func(*TaskContext) core.ToolSet @@ -75,6 +77,22 @@ func (a AgentStage) Stage() Stage { extra = a.Extra(tc) } + // Repo-configured protected suffixes (generated files) apply to + // every writing stage; stage-specific matchers stack on top. + var stageProtect func(string) bool + if a.ProtectPaths != nil { + stageProtect = a.ProtectPaths(tc) + } + protect := func(path string) bool { + if tc.Repo.Protected(path) { + return true + } + return stageProtect != nil && stageProtect(path) + } + if a.ReadOnly { + protect = nil // nothing to protect from read-only tools + } + res, err := agentloop.Run(ctx, agentloop.Config{ Runtime: tc.Runtime, ModelRef: modelRef, @@ -88,7 +106,7 @@ func (a AgentStage) Stage() Stage { }, Budget: budget, ReadOnly: a.ReadOnly, - ProtectPaths: a.ProtectPaths, + ProtectPaths: protect, Extra: extra, Logger: tc.Log.With("stage", a.Name, "model", modelRef), }) diff --git a/internal/workflow/implement.go b/internal/workflow/implement.go index aad81bdf0..d923b4c4c 100644 --- a/internal/workflow/implement.go +++ b/internal/workflow/implement.go @@ -77,6 +77,8 @@ func Implement() Workflow { Gate: func(tc *TaskContext) agentloop.GateConfig { return GateFromRepo(tc.Repo, tc.Cfg.Budgets) }, + ExtraRules: "Files matching the repository's protected suffixes (e.g. generated code) are " + + "write-blocked — edit their sources instead; the gate regenerates them.", Mission: func(tc *TaskContext) string { return fmt.Sprintf( "Implement this GitHub issue on the repository %s, following the plan below.\n\n"+ diff --git a/internal/workflow/tdd.go b/internal/workflow/tdd.go index de11b3e82..fff6f6f3a 100644 --- a/internal/workflow/tdd.go +++ b/internal/workflow/tdd.go @@ -95,8 +95,8 @@ func TDD() Workflow { }, // 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") + ProtectPaths: func(*TaskContext) func(string) bool { + return func(path string) bool { return strings.HasSuffix(path, "_test.go") } }, ExtraRules: "The repro tests written in the previous stage are the bug's specification. " + "Test files are write-protected in this stage — make them pass by fixing the code they exercise.",