refactor(agent): move worker runtime into application layer

cmd/archie-agent used to own worker construction, NATS lifecycle, task execution, MCP setup, and workflow wiring. It now owns process input only and invokes internal/app/agentworker, while transport-specific NATS, boot-brief, and git-safety mechanics live under infrastructure.
This commit is contained in:
sam committed 2026-08-15 00:43:12 +10:00
1 parent 0243c13d37
commit 45345cdfb6
35 files changed
+2901 -689

No files matched your search

+13 -5
View File
@@ -7,6 +7,7 @@
package taskrun
import (
"errors"
"fmt"
"github.com/samcharles93/archie-core/internal/agentexec"
@@ -14,11 +15,6 @@ import (
"github.com/samcharles93/archie-core/internal/store"
)
// SubjectForTask returns the per-task NATS subject for a full-task handoff.
func SubjectForTask(taskID int64) string {
return fmt.Sprintf("archie.taskrun.%d", taskID)
}
// Request carries everything archie-agent needs to run a task's entire
// workflow itself: the task row (already claimed by archied), the repo's
// gate/ecosystem config, a non-secret config snapshot, and LLM provider
@@ -35,6 +31,18 @@ type Request struct {
MCPServers []config.MCPServer `json:"mcp_servers,omitempty"`
}
// Validate rejects a full-task request that cannot be correlated to a real
// task. Transport-specific subject correlation is enforced by the adapter.
func (r Request) Validate() error {
if r.Task == nil {
return errors.New("task is required")
}
if r.Task.ID <= 0 {
return fmt.Errorf("task ID must be positive, got %d", r.Task.ID)
}
return nil
}
// Response reports the task's final state after archie-agent runs its
// workflow. Task carries the last-known field values for logging; the
// authoritative state already landed in archied's store via storerpc
+20 -6
View File
@@ -50,6 +50,26 @@ func TestRequestJSONRoundTrip(t *testing.T) {
}
}
func TestRequestValidateRequiresPositiveTaskID(t *testing.T) {
for _, test := range []struct {
name string
request Request
wantErr bool
}{
{name: "missing task", wantErr: true},
{name: "zero ID", request: Request{Task: &store.Task{}}, wantErr: true},
{name: "negative ID", request: Request{Task: &store.Task{ID: -1}}, wantErr: true},
{name: "positive ID", request: Request{Task: &store.Task{ID: 1}}},
} {
t.Run(test.name, func(t *testing.T) {
err := test.request.Validate()
if (err != nil) != test.wantErr {
t.Fatalf("Validate() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
func TestResponseJSONRoundTrip(t *testing.T) {
resp := Response{
Task: &store.Task{ID: 1, Status: store.StatusPROpen},
@@ -67,9 +87,3 @@ func TestResponseJSONRoundTrip(t *testing.T) {
t.Fatalf("Response did not round-trip: %+v", got)
}
}
func TestSubjectForTask(t *testing.T) {
if got := SubjectForTask(42); got != "archie.taskrun.42" {
t.Fatalf("SubjectForTask(42) = %q", got)
}
}