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

+4 -3
View File
@@ -24,6 +24,7 @@ import (
"github.com/samcharles93/archie-core/internal/eventbus"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/memory"
"github.com/samcharles93/archie-core/internal/plugin"
@@ -1004,8 +1005,8 @@ func (d *Daemon) acquireTaskContainer(
}
// containerEnv returns the environment variables passed to agent containers.
// runViaAgent publishes a full-task handoff to archie-agent over
// archie.taskrun.<id> and waits for its completion report. Every durable
// runViaAgent publishes a full-task handoff to archie-agent over the
// infrastructure-owned task subject and waits for its completion report. Every durable
// side effect (Store transitions, Forge calls, git push) happens inside
// archie-agent's workflow.Run, proxied back to this daemon over
// storerpc/forgerpc/worktreerpc -- those RPC servers are the sole place a
@@ -1084,7 +1085,7 @@ func (d *Daemon) taskRunRetryBackoff() time.Duration {
// that's already done, etc.) is returned immediately without retrying,
// since those don't mean "not ready yet".
func (d *Daemon) requestTaskRun(ctx context.Context, taskID int64, data []byte) ([]byte, error) {
subject := taskrun.SubjectForTask(taskID)
subject := agentnats.SubjectForTask(taskID)
deadline := time.Now().Add(d.taskRunReadyTimeout())
backoff := d.taskRunRetryBackoff()
for {
+4 -3
View File
@@ -18,6 +18,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/forge"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
arnats "github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/secret"
@@ -455,7 +456,7 @@ func TestRunViaAgentRetriesUntilResponderAppears(t *testing.T) {
t.Errorf("CoreConn: %v", connErr)
return
}
sub, err := coreConn.Subscribe(taskrun.SubjectForTask(task.ID), func(msg *natsio.Msg) {
sub, err := coreConn.Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
data, _ := json.Marshal(taskrun.Response{Status: store.StatusPROpen})
_ = msg.Respond(data)
})
@@ -516,7 +517,7 @@ func TestRunViaAgentParksOnRunError(t *testing.T) {
t.Fatalf("claim: (%v, %v)", task, err)
}
sub, err := mustCoreConn(t, busClient).Subscribe(taskrun.SubjectForTask(task.ID), func(msg *natsio.Msg) {
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
data, _ := json.Marshal(taskrun.Response{Error: "registry build failed"})
_ = msg.Respond(data)
})
@@ -552,7 +553,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
}
received := make(chan taskrun.Request, 1)
sub, err := mustCoreConn(t, busClient).Subscribe(taskrun.SubjectForTask(task.ID), func(msg *natsio.Msg) {
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
var req taskrun.Request
_ = json.Unmarshal(msg.Data, &req)
received <- req