refactor(agentexec): own the capture file format in agentexec, not the app layer

This commit is contained in:
sam committed 2026-09-26 03:30:19 +10:00
1 parent 928d7041e6
commit ca8c0179ec
2 files changed
+23 -20

No files matched your search

+20
View File
@@ -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)
}
+3 -20
View File
@@ -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{})
}