From ca8c0179ec1b93fec6fd8c1fadb275dd3deac205 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 26 Sep 2026 03:30:19 +1000 Subject: [PATCH] refactor(agentexec): own the capture file format in agentexec, not the app layer --- internal/agentexec/capture_mcp.go | 20 ++++++++++++++++++++ internal/app/agentworker/mcp.go | 23 +++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/internal/agentexec/capture_mcp.go b/internal/agentexec/capture_mcp.go index 0217be646..3a0077356 100644 --- a/internal/agentexec/capture_mcp.go +++ b/internal/agentexec/capture_mcp.go @@ -110,3 +110,23 @@ func readCaptures(path string, specs []CaptureTool) (map[string][]json.RawMessag } return captures, scanner.Err() } + +// ServeCaptureFiles serves the capture tools listed in specPath, appending +// accepted calls to capturesPath. The files are the ones prepareCaptures +// writes, so this package owns their format end to end. +func ServeCaptureFiles(ctx context.Context, specPath, capturesPath string, t mcp.Transport) error { + raw, err := os.ReadFile(specPath) + if err != nil { + return err + } + var specs []CaptureTool + if err := json.Unmarshal(raw, &specs); err != nil { + return fmt.Errorf("capture tool spec: %w", err) + } + sink, err := os.OpenFile(capturesPath, os.O_WRONLY|os.O_APPEND, 0) + if err != nil { + return err + } + defer sink.Close() + return ServeCaptureMCP(ctx, specs, sink, t) +} diff --git a/internal/app/agentworker/mcp.go b/internal/app/agentworker/mcp.go index 3e1f1753d..0fcd86f00 100644 --- a/internal/app/agentworker/mcp.go +++ b/internal/app/agentworker/mcp.go @@ -2,31 +2,14 @@ package agentworker import ( "context" - "encoding/json" - "fmt" - "os" "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/samcharles93/archie-core/internal/agentexec" ) -// RunCaptureMCP serves the capture tools listed in specPath over stdio, -// appending accepted calls to capturesPath, until the harness closes the -// connection or ctx is cancelled. +// RunCaptureMCP serves a stage's capture tools to its harness over stdio +// until the harness closes the connection or ctx is cancelled. func RunCaptureMCP(ctx context.Context, specPath, capturesPath string) error { - raw, err := os.ReadFile(specPath) - if err != nil { - return err - } - var specs []agentexec.CaptureTool - if err := json.Unmarshal(raw, &specs); err != nil { - return fmt.Errorf("capture tool spec: %w", err) - } - sink, err := os.OpenFile(capturesPath, os.O_WRONLY|os.O_APPEND, 0) - if err != nil { - return err - } - defer sink.Close() - return agentexec.ServeCaptureMCP(ctx, specs, sink, &mcp.StdioTransport{}) + return agentexec.ServeCaptureFiles(ctx, specPath, capturesPath, &mcp.StdioTransport{}) }