The loop runner hooks every model call and tool call and reports ordered,
redacted, clipped entries. Each is persisted as an agent_transcript task
event through InsertEvent, left out of the timeline read, and served per
attempt at /api/tasks/{id}/transcript. The step run view shows it with Trace.
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package agentexec
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
|
)
|
|
|
|
// copilotHarnessOutput reads GitHub Copilot CLI's `--output-format json`.
|
|
// The stream carries no token counts, so a Copilot run reports no usage and
|
|
// its budget is wall clock.
|
|
type copilotHarnessOutput struct {
|
|
sessionID string
|
|
pending map[string]string
|
|
}
|
|
|
|
func newCopilotHarnessOutput() *copilotHarnessOutput {
|
|
return &copilotHarnessOutput{pending: make(map[string]string)}
|
|
}
|
|
|
|
func (o *copilotHarnessOutput) Line(line []byte, report agentrun.Reporter) {
|
|
var event struct {
|
|
Type string `json:"type"`
|
|
SessionID string `json:"sessionId"`
|
|
Data struct {
|
|
ToolCallID string `json:"toolCallId"`
|
|
ToolName string `json:"toolName"`
|
|
MCPToolName string `json:"mcpToolName"`
|
|
Success bool `json:"success"`
|
|
Result struct {
|
|
Content string `json:"content"`
|
|
} `json:"result"`
|
|
} `json:"data"`
|
|
}
|
|
if json.Unmarshal(line, &event) != nil {
|
|
return
|
|
}
|
|
switch event.Type {
|
|
case "result":
|
|
o.sessionID = event.SessionID
|
|
case "tool.execution_start":
|
|
name := event.Data.MCPToolName
|
|
if name == "" {
|
|
name = event.Data.ToolName
|
|
}
|
|
if event.Data.ToolCallID != "" && name != "" {
|
|
o.pending[event.Data.ToolCallID] = name
|
|
}
|
|
case "tool.execution_complete":
|
|
tool, ok := o.pending[event.Data.ToolCallID]
|
|
if !ok {
|
|
return
|
|
}
|
|
delete(o.pending, event.Data.ToolCallID)
|
|
report.ReportToolCall(agentrun.ToolCallReport{Tool: tool, Detail: ClipToolCallDetail(event.Data.Result.Content), Failed: !event.Data.Success})
|
|
}
|
|
}
|
|
|
|
func (o *copilotHarnessOutput) SessionID() string { return o.sessionID }
|
|
func (o *copilotHarnessOutput) Usage() agentrun.Usage { return agentrun.Usage{} }
|