refactor(agentexec): own the capture file format in agentexec, not the app layer
This commit is contained in:
1 parent
928d7041e6
commit
ca8c0179ec
2 files changed
+23
-20
No files matched your search
@@ -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)
|
||||
}
|
||||
@@ -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{})
|
||||
}
|
||||
Reference in new issue
Block a user