diff --git a/internal/agentexec/harness_output_claude.go b/internal/agentexec/harness_output_claude.go new file mode 100644 index 000000000..82bd96f56 --- /dev/null +++ b/internal/agentexec/harness_output_claude.go @@ -0,0 +1,176 @@ +package agentexec + +import ( + "bytes" + "encoding/json" + "strings" +) + +// claudeCodeHarnessOutput reads Claude Code's newline-delimited stream-json +// output. It keeps tool-use IDs until the corresponding user tool_result +// arrives and retains assistant usage as a fallback for interrupted runs. +type claudeCodeHarnessOutput struct { + sessionID string + pending map[string]string + + messageUsage Usage + seenMessages map[string]struct{} + hasResult bool + resultUsage Usage +} + +func newClaudeCodeHarnessOutput() *claudeCodeHarnessOutput { + return &claudeCodeHarnessOutput{ + pending: make(map[string]string), + seenMessages: make(map[string]struct{}), + } +} + +func (o *claudeCodeHarnessOutput) Line(line []byte, report ToolCallReporter) { + var event struct { + Type string `json:"type"` + SessionID string `json:"session_id"` + Message json.RawMessage `json:"message"` + Usage json.RawMessage `json:"usage"` + } + if json.Unmarshal(line, &event) != nil { + return + } + if event.SessionID != "" { + o.sessionID = event.SessionID + } + + switch event.Type { + case "assistant": + o.assistant(event.Message, report) + case "user": + o.user(event.Message, report) + case "result": + if usage, ok := decodeClaudeUsage(event.Usage); ok { + o.resultUsage = usage + o.hasResult = true + } + } +} + +func (o *claudeCodeHarnessOutput) assistant(raw json.RawMessage, _ ToolCallReporter) { + var message struct { + ID string `json:"id"` + Usage *struct { + InputTokens int `json:"input_tokens"` + OutputTokens int `json:"output_tokens"` + CacheReadInputTokens int `json:"cache_read_input_tokens"` + CacheCreationInputTokens int `json:"cache_creation_input_tokens"` + } `json:"usage"` + Content []struct { + Type string `json:"type"` + ID string `json:"id"` + Name string `json:"name"` + Input any `json:"input"` + } `json:"content"` + } + if json.Unmarshal(raw, &message) != nil { + return + } + if message.Usage != nil && (message.ID == "" || o.markMessage(message.ID)) { + o.messageUsage = addUsage(o.messageUsage, usageFromFields( + message.Usage.InputTokens, + message.Usage.OutputTokens, + message.Usage.CacheReadInputTokens, + message.Usage.CacheCreationInputTokens, + )) + } + for _, block := range message.Content { + if block.Type == "tool_use" && block.ID != "" && block.Name != "" { + o.pending[block.ID] = block.Name + } + } +} + +func (o *claudeCodeHarnessOutput) user(raw json.RawMessage, report ToolCallReporter) { + var message struct { + Content []struct { + Type string `json:"type"` + ToolUseID string `json:"tool_use_id"` + Content json.RawMessage `json:"content"` + IsError bool `json:"is_error"` + } `json:"content"` + } + if json.Unmarshal(raw, &message) != nil { + return + } + for _, block := range message.Content { + if block.Type != "tool_result" || block.ToolUseID == "" { + continue + } + tool, ok := o.pending[block.ToolUseID] + if !ok { + continue + } + delete(o.pending, block.ToolUseID) + if report != nil { + report(ToolCallReport{ + Tool: tool, Detail: clipToolCallDetail(claudeResultContent(block.Content)), + Failed: block.IsError, + }) + } + } +} + +func (o *claudeCodeHarnessOutput) markMessage(id string) bool { + if _, seen := o.seenMessages[id]; seen { + return false + } + o.seenMessages[id] = struct{}{} + return true +} + +func (o *claudeCodeHarnessOutput) SessionID() string { return o.sessionID } + +func (o *claudeCodeHarnessOutput) Usage() Usage { + if o.hasResult { + return o.resultUsage + } + return o.messageUsage +} + +func decodeClaudeUsage(raw json.RawMessage) (Usage, bool) { + var fields struct { + InputTokens int `json:"input_tokens"` + OutputTokens int `json:"output_tokens"` + CacheReadInputTokens int `json:"cache_read_input_tokens"` + CacheCreationInputTokens int `json:"cache_creation_input_tokens"` + } + if len(raw) == 0 || bytes.Equal(bytes.TrimSpace(raw), []byte("null")) || json.Unmarshal(raw, &fields) != nil { + return Usage{}, false + } + return usageFromFields(fields.InputTokens, fields.OutputTokens, fields.CacheReadInputTokens, fields.CacheCreationInputTokens), true +} + +func usageFromFields(input, output, cacheRead, cacheCreation int) Usage { + return Usage{ + PromptTokens: input, CompletionTokens: output, TotalTokens: input + output, + CachedTokens: cacheRead, CacheCreationTokens: cacheCreation, + } +} + +func claudeResultContent(raw json.RawMessage) string { + var content string + if json.Unmarshal(raw, &content) == nil { + return content + } + var blocks []struct { + Type string `json:"type"` + Text string `json:"text"` + } + if json.Unmarshal(raw, &blocks) != nil { + return "" + } + texts := make([]string, 0, len(blocks)) + for _, block := range blocks { + if block.Type == "text" { + texts = append(texts, block.Text) + } + } + return strings.Join(texts, "\n") +} diff --git a/internal/agentexec/harness_output_claude_test.go b/internal/agentexec/harness_output_claude_test.go new file mode 100644 index 000000000..c5a1f0051 --- /dev/null +++ b/internal/agentexec/harness_output_claude_test.go @@ -0,0 +1,148 @@ +package agentexec + +import ( + "bufio" + "encoding/json" + "os" + "reflect" + "strings" + "testing" +) + +func TestClaudeCodeHarnessOutputFixtures(t *testing.T) { + errorDetail := "Exit code 1\ncat: /nonexistent-file: No such file or directory" + cases := []struct { + name string + wantCalls []ToolCallReport + wantUsage Usage + wantSession string + }{ + { + name: "run.jsonl", + wantCalls: []ToolCallReport{ + {Tool: "Bash", Detail: "hello"}, + {Tool: "Bash", Detail: errorDetail, Failed: true}, + }, + wantUsage: Usage{PromptTokens: 6, CompletionTokens: 248, TotalTokens: 254, CachedTokens: 78105, CacheCreationTokens: 24309}, + wantSession: "9c22c15c-80ef-42c6-a503-8d087ec47d92", + }, + { + name: "killed-before-result.jsonl", + wantCalls: []ToolCallReport{ + {Tool: "Bash", Detail: "hello"}, + {Tool: "Bash", Detail: errorDetail, Failed: true}, + }, + wantUsage: Usage{PromptTokens: 6, CompletionTokens: 121, TotalTokens: 127, CachedTokens: 78105, CacheCreationTokens: 24309}, + wantSession: "9c22c15c-80ef-42c6-a503-8d087ec47d92", + }, + { + name: "malformed-line.jsonl", + wantCalls: []ToolCallReport{ + {Tool: "Bash", Detail: "hello"}, + {Tool: "Bash", Detail: errorDetail, Failed: true}, + }, + wantUsage: Usage{PromptTokens: 6, CompletionTokens: 248, TotalTokens: 254, CachedTokens: 78105, CacheCreationTokens: 24309}, + wantSession: "9c22c15c-80ef-42c6-a503-8d087ec47d92", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + stream, err := os.Open("testdata/claude/" + tc.name) + if err != nil { + t.Fatal(err) + } + defer stream.Close() + + output := newClaudeCodeHarnessOutput() + var calls []ToolCallReport + scanner := bufio.NewScanner(stream) + for scanner.Scan() { + output.Line(scanner.Bytes(), func(call ToolCallReport) { calls = append(calls, call) }) + } + if err := scanner.Err(); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(calls, tc.wantCalls) { + t.Errorf("tool calls = %#v, want %#v", calls, tc.wantCalls) + } + if got := output.SessionID(); got != tc.wantSession { + t.Errorf("session ID = %q, want %q", got, tc.wantSession) + } + if got := output.Usage(); got != tc.wantUsage { + t.Errorf("usage = %#v, want %#v", got, tc.wantUsage) + } + }) + } +} + +func TestClaudeCodeHarnessOutputToolResultContent(t *testing.T) { + long := strings.Repeat("x", toolCallDetailBytes+25) + cases := []struct { + name string + content any + wantDetail string + }{ + {name: "string", content: "plain result", wantDetail: "plain result"}, + {name: "text blocks", content: []map[string]string{{"type": "text", "text": "first"}, {"type": "text", "text": "second"}}, wantDetail: "first\nsecond"}, + {name: "clipped", content: long, wantDetail: strings.Repeat("x", toolCallDetailBytes) + "…"}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + output := newClaudeCodeHarnessOutput() + var calls []ToolCallReport + report := func(call ToolCallReport) { calls = append(calls, call) } + sendClaudeEvent(t, output, report, map[string]any{ + "type": "assistant", "session_id": "old-session", + "message": map[string]any{ + "id": "same-message", "usage": claudeUsageFixture(2, 3, 5, 7), + "content": []any{map[string]any{"type": "tool_use", "id": "call-1", "name": "Read", "input": map[string]any{}}}, + }, + }) + sendClaudeEvent(t, output, report, map[string]any{ + "type": "assistant", "session_id": "newer-session", + "message": map[string]any{ + "id": "same-message", "usage": claudeUsageFixture(2, 3, 5, 7), + "content": []any{map[string]any{"type": "tool_use", "id": "call-2", "name": "Write", "input": map[string]any{}}}, + }, + }) + sendClaudeEvent(t, output, report, map[string]any{ + "type": "user", "session_id": "latest-session", + "message": map[string]any{"content": []any{map[string]any{"type": "tool_result", "tool_use_id": "call-1", "content": tc.content, "is_error": false}}}, + }) + sendClaudeEvent(t, output, report, map[string]any{ + "type": "user", "session_id": "", + "message": map[string]any{"content": []any{map[string]any{"type": "tool_result", "tool_use_id": "call-2", "content": "done", "is_error": false}}}, + }) + + wantCalls := []ToolCallReport{{Tool: "Read", Detail: tc.wantDetail}, {Tool: "Write", Detail: "done"}} + if !reflect.DeepEqual(calls, wantCalls) { + t.Errorf("tool calls = %#v, want %#v", calls, wantCalls) + } + wantUsage := Usage{PromptTokens: 2, CompletionTokens: 3, TotalTokens: 5, CachedTokens: 5, CacheCreationTokens: 7} + if got := output.Usage(); got != wantUsage { + t.Errorf("usage = %#v, want %#v", got, wantUsage) + } + if got := output.SessionID(); got != "latest-session" { + t.Errorf("session ID = %q, want latest non-empty event value", got) + } + }) + } +} + +func sendClaudeEvent(t *testing.T, output HarnessOutput, report ToolCallReporter, event map[string]any) { + t.Helper() + line, err := json.Marshal(event) + if err != nil { + t.Fatal(err) + } + output.Line(line, report) +} + +func claudeUsageFixture(input, output, cacheRead, cacheCreate int) map[string]any { + return map[string]any{ + "input_tokens": input, "output_tokens": output, + "cache_read_input_tokens": cacheRead, "cache_creation_input_tokens": cacheCreate, + } +} diff --git a/internal/agentexec/testdata/claude/killed-before-result.jsonl b/internal/agentexec/testdata/claude/killed-before-result.jsonl new file mode 100644 index 000000000..7c9ae5e90 --- /dev/null +++ b/internal/agentexec/testdata/claude/killed-before-result.jsonl @@ -0,0 +1,15 @@ +{"type": "system", "subtype": "hook_started", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "959d5b3d-d376-4416-9abb-71e0b8a36047", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "1f5ed274-0baa-4558-b00f-36ef98d28ebc", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "5aa154a9-9315-4a6c-8de0-750cb35139cf", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "ef74547a-736e-4bb9-bd68-16cc1592b2a3", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "398b087e-942b-4d67-904c-1778d3b20063", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "ecbfdcf2-446c-4386-a89f-eeaf43e48b46", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "c10b3042-e990-49db-8937-954b6fe11570", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "3a3327f8-ad24-46d7-a194-e0ce68f9f871", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "init", "cwd": "/workspace", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "tools": ["Task", "Bash", "CronCreate", "CronDelete", "CronList", "DesignSync", "Edit", "EnterWorktree", "ExitWorktree", "ListAgents", "ListMcpResourcesTool", "LSP", "Monitor", "NotebookEdit", "PushNotification", "Read", "ReadMcpResourceDirTool", "ReadMcpResourceTool", "RemoteTrigger", "ReportFindings", "ScheduleWakeup", "SendMessage", "Skill", "TaskStop", "ToolSearch", "WebFetch", "WebSearch", "Workflow", "Write", "mcp__claude_ai_Claude_Docs__batch", "mcp__claude_ai_Claude_Docs__create", "mcp__claude_ai_Claude_Docs__delete", "mcp__claude_ai_Claude_Docs__export", "mcp__claude_ai_Claude_Docs__guide", "mcp__claude_ai_Claude_Docs__query", "mcp__claude_ai_Claude_Docs__read", "mcp__claude_ai_Claude_Docs__update", "mcp__claude_ai_Context7__query-docs", "mcp__claude_ai_Context7__resolve-library-id", "mcp__claude_ai_Excalidraw__create_view", "mcp__claude_ai_Excalidraw__read_me", "mcp__claude_ai_Gmail__apply_sensitive_message_label", "mcp__claude_ai_Gmail__apply_sensitive_thread_label", "mcp__claude_ai_Gmail__create_draft", "mcp__claude_ai_Gmail__create_label", "mcp__claude_ai_Gmail__delete_draft", "mcp__claude_ai_Gmail__delete_label", "mcp__claude_ai_Gmail__forward", "mcp__claude_ai_Gmail__get_draft", "mcp__claude_ai_Gmail__get_message", "mcp__claude_ai_Gmail__get_thread", "mcp__claude_ai_Gmail__label_message", "mcp__claude_ai_Gmail__label_thread", "mcp__claude_ai_Gmail__list_drafts", "mcp__claude_ai_Gmail__list_labels", "mcp__claude_ai_Gmail__mark_message_spam", "mcp__claude_ai_Gmail__mark_thread_spam", "mcp__claude_ai_Gmail__reply", "mcp__claude_ai_Gmail__search_threads", "mcp__claude_ai_Gmail__send_message", "mcp__claude_ai_Gmail__trash_message", "mcp__claude_ai_Gmail__trash_thread", "mcp__claude_ai_Gmail__unlabel_message", "mcp__claude_ai_Gmail__unlabel_thread", "mcp__claude_ai_Gmail__unmark_message_spam", "mcp__claude_ai_Gmail__unmark_thread_spam", "mcp__claude_ai_Gmail__untrash_message", "mcp__claude_ai_Gmail__untrash_thread", "mcp__claude_ai_Gmail__update_draft", "mcp__claude_ai_Gmail__update_label", "mcp__claude_ai_Gmail__update_message_labels", "mcp__claude_ai_Google_Calendar__create_event", "mcp__claude_ai_Google_Calendar__delete_event", "mcp__claude_ai_Google_Calendar__get_event", "mcp__claude_ai_Google_Calendar__list_calendars", "mcp__claude_ai_Google_Calendar__list_events", "mcp__claude_ai_Google_Calendar__respond_to_event", "mcp__claude_ai_Google_Calendar__search_events", "mcp__claude_ai_Google_Calendar__suggest_time", "mcp__claude_ai_Google_Calendar__update_event", "mcp__claude_ai_Microsoft_365__chat_message_search", "mcp__claude_ai_Microsoft_365__find_meeting_availability", "mcp__claude_ai_Microsoft_365__get_granted_scopes", "mcp__claude_ai_Microsoft_365__get_me", "mcp__claude_ai_Microsoft_365__outlook_batch_delete_messages", "mcp__claude_ai_Microsoft_365__outlook_batch_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_calendar_search", "mcp__claude_ai_Microsoft_365__outlook_create_draft", "mcp__claude_ai_Microsoft_365__outlook_create_event", "mcp__claude_ai_Microsoft_365__outlook_create_filter", "mcp__claude_ai_Microsoft_365__outlook_create_label", "mcp__claude_ai_Microsoft_365__outlook_create_reply_all_draft", "mcp__claude_ai_Microsoft_365__outlook_create_reply_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_event", "mcp__claude_ai_Microsoft_365__outlook_delete_filter", "mcp__claude_ai_Microsoft_365__outlook_delete_label", "mcp__claude_ai_Microsoft_365__outlook_email_search", "mcp__claude_ai_Microsoft_365__outlook_find_available_time", "mcp__claude_ai_Microsoft_365__outlook_forward_mail", "mcp__claude_ai_Microsoft_365__outlook_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_modify_thread_labels", "mcp__claude_ai_Microsoft_365__outlook_respond_to_event", "mcp__claude_ai_Microsoft_365__outlook_send_draft", "mcp__claude_ai_Microsoft_365__outlook_send_mail", "mcp__claude_ai_Microsoft_365__outlook_set_vacation", "mcp__claude_ai_Microsoft_365__outlook_trash_thread", "mcp__claude_ai_Microsoft_365__outlook_untrash_thread", "mcp__claude_ai_Microsoft_365__outlook_update_draft", "mcp__claude_ai_Microsoft_365__outlook_update_event", "mcp__claude_ai_Microsoft_365__outlook_update_label", "mcp__claude_ai_Microsoft_365__read_resource", "mcp__claude_ai_Microsoft_365__search_people", "mcp__claude_ai_Microsoft_365__sharepoint_copy_item", "mcp__claude_ai_Microsoft_365__sharepoint_create_folder", "mcp__claude_ai_Microsoft_365__sharepoint_delete_item", "mcp__claude_ai_Microsoft_365__sharepoint_folder_search", "mcp__claude_ai_Microsoft_365__sharepoint_move_item", "mcp__claude_ai_Microsoft_365__sharepoint_rename_item", "mcp__claude_ai_Microsoft_365__sharepoint_search", "mcp__claude_ai_Microsoft_365__sharepoint_update_file", "mcp__claude_ai_Microsoft_365__sharepoint_upload_file", "mcp__claude_ai_Microsoft_365__teams_create_chat", "mcp__claude_ai_Microsoft_365__teams_list_channel_messages", "mcp__claude_ai_Microsoft_365__teams_list_channels", "mcp__claude_ai_Microsoft_365__teams_list_chats", "mcp__claude_ai_Microsoft_365__teams_list_teams", "mcp__claude_ai_Microsoft_365__teams_reply_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_chat_message", "mcp__claude_ai_Slack__slack_add_reaction", "mcp__claude_ai_Slack__slack_create_canvas", "mcp__claude_ai_Slack__slack_create_conversation", "mcp__claude_ai_Slack__slack_get_reactions", "mcp__claude_ai_Slack__slack_list_channel_members", "mcp__claude_ai_Slack__slack_read_canvas", "mcp__claude_ai_Slack__slack_read_channel", "mcp__claude_ai_Slack__slack_read_file", "mcp__claude_ai_Slack__slack_read_thread", "mcp__claude_ai_Slack__slack_read_user_profile", "mcp__claude_ai_Slack__slack_schedule_message", "mcp__claude_ai_Slack__slack_search_channels", "mcp__claude_ai_Slack__slack_search_emojis", "mcp__claude_ai_Slack__slack_search_public", "mcp__claude_ai_Slack__slack_search_public_and_private", "mcp__claude_ai_Slack__slack_search_users", "mcp__claude_ai_Slack__slack_send_message", "mcp__claude_ai_Slack__slack_send_message_draft", "mcp__claude_ai_Slack__slack_update_canvas", "mcp__plugin_context7_context7__query-docs", "mcp__plugin_context7_context7__resolve-library-id", "mcp__techlead-hosted__post", "mcp__techlead-hosted__propose_case", "mcp__techlead-hosted__review", "mcp__techlead-hosted__signals"], "mcp_servers": [], "model": "claude-opus-5-5", "permissionMode": "bypassPermissions", "slash_commands": [], "terminal_slash_commands": [], "apiKeySource": "none", "claude_code_version": "2.1.282", "output_style": "default", "agents": [], "skills": [], "plugins": [], "capabilities": ["interrupt_receipt_v1", "interrupt_cancel_queued_v1", "msg_lifecycle_v1", "mcp_read_resource_v1", "mcp_tool_ui_meta_v1"], "analytics_disabled": false, "product_feedback_disabled": false, "uuid": "0ad7c54e-a817-406b-af22-8f647b4e0021", "memory_paths": {}, "messaging_socket_path": "", "fast_mode_state": "off", "fast_mode_disabled_reason": "sdk_opt_in_required", "per_turn_effort_active": true, "view_mode": "default"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZ2iQ3sZ59vJ9CCae9", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "name": "Bash", "input": {"command": "echo hello", "description": "Print hello"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 23584, "cache_read_input_tokens": 10119, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 23584}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "b4c3b51e-0a58-4b28-8c5a-20a2ff2aaadb", "timestamp": "2026-09-25T17:22:54.134Z", "request_id": "req_011CfQYZ2Ddp5YubZj8vB9Fb", "wire_tool_inputs": {"toolu_01P8qrSZwqH1jjZXfrZETjKz": {"command": "echo hello", "description": "Print hello"}}} +{"type": "rate_limit_event", "rate_limit_info": {"status": "allowed_warning", "resetsAt": 1790377200, "rateLimitType": "seven_day", "utilization": 0.98, "isUsingOverage": false, "surpassedThreshold": 0.75, "unifiedWindows": {"five_hour": {"utilization": 0.76, "resetsAt": 1790366400}, "seven_day": {"utilization": 0.98, "resetsAt": 1790377200}}}, "uuid": "a91b2340-329e-4c73-8e1a-307860859743", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "type": "tool_result", "content": "hello", "is_error": false}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "6beae671-52a0-499a-b72b-f9321c1d9e14", "timestamp": "2026-09-25T17:22:54.460Z", "tool_use_result": {"stdout": "hello", "stderr": "", "interrupted": false, "isImage": false, "noOutputExpected": false}} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZHW9AJ164FSYj39uG", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01YNNETbc61jN44ATXrmHdEC", "name": "Bash", "input": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 580, "cache_read_input_tokens": 33703, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 580}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "3b14941d-c8eb-45f4-b555-829e06119f19", "timestamp": "2026-09-25T17:22:56.420Z", "request_id": "req_011CfQYZH18nwJgBYNZs8XGq", "wire_tool_inputs": {"toolu_01YNNETbc61jN44ATXrmHdEC": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}}} +{"type": "user", "message": {"role": "user", "content": [{"type": "tool_result", "content": "Exit code 1\ncat: /nonexistent-file: No such file or directory", "is_error": true, "tool_use_id": "toolu_01YNNETbc61jN44ATXrmHdEC"}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "395dc93d-0e4f-40b5-854b-77a128aa0990", "timestamp": "2026-09-25T17:22:56.442Z", "tool_use_result": "Error: Exit code 1\ncat: /nonexistent-file: No such file or directory"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZRy8qPUaVcnVs9CQD", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "done\n\nThe first command printed `hello`. The second failed with \"No such file or directory\".\n\nGoogle Drive, exa and intercom still need authorizing. Google Drive is set up in its claude.ai connector settings. For exa and intercom, run `/mcp` in an interactive session."}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 145, "cache_read_input_tokens": 34283, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 145}, "output_tokens": 89, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "8f97a329-c76c-4b90-b154-bda9468b969d", "timestamp": "2026-09-25T17:22:58.580Z", "request_id": "req_011CfQYZRSdq9mNMbE7n8okT"} diff --git a/internal/agentexec/testdata/claude/malformed-line.jsonl b/internal/agentexec/testdata/claude/malformed-line.jsonl new file mode 100644 index 000000000..643fb9954 --- /dev/null +++ b/internal/agentexec/testdata/claude/malformed-line.jsonl @@ -0,0 +1,17 @@ +{"type": "system", "subtype": "hook_started", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "959d5b3d-d376-4416-9abb-71e0b8a36047", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "1f5ed274-0baa-4558-b00f-36ef98d28ebc", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "5aa154a9-9315-4a6c-8de0-750cb35139cf", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "ef74547a-736e-4bb9-bd68-16cc1592b2a3", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "398b087e-942b-4d67-904c-1778d3b20063", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "ecbfdcf2-446c-4386-a89f-eeaf43e48b46", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "c10b3042-e990-49db-8937-954b6fe11570", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "3a3327f8-ad24-46d7-a194-e0ce68f9f871", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "init", "cwd": "/workspace", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "tools": ["Task", "Bash", "CronCreate", "CronDelete", "CronList", "DesignSync", "Edit", "EnterWorktree", "ExitWorktree", "ListAgents", "ListMcpResourcesTool", "LSP", "Monitor", "NotebookEdit", "PushNotification", "Read", "ReadMcpResourceDirTool", "ReadMcpResourceTool", "RemoteTrigger", "ReportFindings", "ScheduleWakeup", "SendMessage", "Skill", "TaskStop", "ToolSearch", "WebFetch", "WebSearch", "Workflow", "Write", "mcp__claude_ai_Claude_Docs__batch", "mcp__claude_ai_Claude_Docs__create", "mcp__claude_ai_Claude_Docs__delete", "mcp__claude_ai_Claude_Docs__export", "mcp__claude_ai_Claude_Docs__guide", "mcp__claude_ai_Claude_Docs__query", "mcp__claude_ai_Claude_Docs__read", "mcp__claude_ai_Claude_Docs__update", "mcp__claude_ai_Context7__query-docs", "mcp__claude_ai_Context7__resolve-library-id", "mcp__claude_ai_Excalidraw__create_view", "mcp__claude_ai_Excalidraw__read_me", "mcp__claude_ai_Gmail__apply_sensitive_message_label", "mcp__claude_ai_Gmail__apply_sensitive_thread_label", "mcp__claude_ai_Gmail__create_draft", "mcp__claude_ai_Gmail__create_label", "mcp__claude_ai_Gmail__delete_draft", "mcp__claude_ai_Gmail__delete_label", "mcp__claude_ai_Gmail__forward", "mcp__claude_ai_Gmail__get_draft", "mcp__claude_ai_Gmail__get_message", "mcp__claude_ai_Gmail__get_thread", "mcp__claude_ai_Gmail__label_message", "mcp__claude_ai_Gmail__label_thread", "mcp__claude_ai_Gmail__list_drafts", "mcp__claude_ai_Gmail__list_labels", "mcp__claude_ai_Gmail__mark_message_spam", "mcp__claude_ai_Gmail__mark_thread_spam", "mcp__claude_ai_Gmail__reply", "mcp__claude_ai_Gmail__search_threads", "mcp__claude_ai_Gmail__send_message", "mcp__claude_ai_Gmail__trash_message", "mcp__claude_ai_Gmail__trash_thread", "mcp__claude_ai_Gmail__unlabel_message", "mcp__claude_ai_Gmail__unlabel_thread", "mcp__claude_ai_Gmail__unmark_message_spam", "mcp__claude_ai_Gmail__unmark_thread_spam", "mcp__claude_ai_Gmail__untrash_message", "mcp__claude_ai_Gmail__untrash_thread", "mcp__claude_ai_Gmail__update_draft", "mcp__claude_ai_Gmail__update_label", "mcp__claude_ai_Gmail__update_message_labels", "mcp__claude_ai_Google_Calendar__create_event", "mcp__claude_ai_Google_Calendar__delete_event", "mcp__claude_ai_Google_Calendar__get_event", "mcp__claude_ai_Google_Calendar__list_calendars", "mcp__claude_ai_Google_Calendar__list_events", "mcp__claude_ai_Google_Calendar__respond_to_event", "mcp__claude_ai_Google_Calendar__search_events", "mcp__claude_ai_Google_Calendar__suggest_time", "mcp__claude_ai_Google_Calendar__update_event", "mcp__claude_ai_Microsoft_365__chat_message_search", "mcp__claude_ai_Microsoft_365__find_meeting_availability", "mcp__claude_ai_Microsoft_365__get_granted_scopes", "mcp__claude_ai_Microsoft_365__get_me", "mcp__claude_ai_Microsoft_365__outlook_batch_delete_messages", "mcp__claude_ai_Microsoft_365__outlook_batch_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_calendar_search", "mcp__claude_ai_Microsoft_365__outlook_create_draft", "mcp__claude_ai_Microsoft_365__outlook_create_event", "mcp__claude_ai_Microsoft_365__outlook_create_filter", "mcp__claude_ai_Microsoft_365__outlook_create_label", "mcp__claude_ai_Microsoft_365__outlook_create_reply_all_draft", "mcp__claude_ai_Microsoft_365__outlook_create_reply_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_event", "mcp__claude_ai_Microsoft_365__outlook_delete_filter", "mcp__claude_ai_Microsoft_365__outlook_delete_label", "mcp__claude_ai_Microsoft_365__outlook_email_search", "mcp__claude_ai_Microsoft_365__outlook_find_available_time", "mcp__claude_ai_Microsoft_365__outlook_forward_mail", "mcp__claude_ai_Microsoft_365__outlook_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_modify_thread_labels", "mcp__claude_ai_Microsoft_365__outlook_respond_to_event", "mcp__claude_ai_Microsoft_365__outlook_send_draft", "mcp__claude_ai_Microsoft_365__outlook_send_mail", "mcp__claude_ai_Microsoft_365__outlook_set_vacation", "mcp__claude_ai_Microsoft_365__outlook_trash_thread", "mcp__claude_ai_Microsoft_365__outlook_untrash_thread", "mcp__claude_ai_Microsoft_365__outlook_update_draft", "mcp__claude_ai_Microsoft_365__outlook_update_event", "mcp__claude_ai_Microsoft_365__outlook_update_label", "mcp__claude_ai_Microsoft_365__read_resource", "mcp__claude_ai_Microsoft_365__search_people", "mcp__claude_ai_Microsoft_365__sharepoint_copy_item", "mcp__claude_ai_Microsoft_365__sharepoint_create_folder", "mcp__claude_ai_Microsoft_365__sharepoint_delete_item", "mcp__claude_ai_Microsoft_365__sharepoint_folder_search", "mcp__claude_ai_Microsoft_365__sharepoint_move_item", "mcp__claude_ai_Microsoft_365__sharepoint_rename_item", "mcp__claude_ai_Microsoft_365__sharepoint_search", "mcp__claude_ai_Microsoft_365__sharepoint_update_file", "mcp__claude_ai_Microsoft_365__sharepoint_upload_file", "mcp__claude_ai_Microsoft_365__teams_create_chat", "mcp__claude_ai_Microsoft_365__teams_list_channel_messages", "mcp__claude_ai_Microsoft_365__teams_list_channels", "mcp__claude_ai_Microsoft_365__teams_list_chats", "mcp__claude_ai_Microsoft_365__teams_list_teams", "mcp__claude_ai_Microsoft_365__teams_reply_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_chat_message", "mcp__claude_ai_Slack__slack_add_reaction", "mcp__claude_ai_Slack__slack_create_canvas", "mcp__claude_ai_Slack__slack_create_conversation", "mcp__claude_ai_Slack__slack_get_reactions", "mcp__claude_ai_Slack__slack_list_channel_members", "mcp__claude_ai_Slack__slack_read_canvas", "mcp__claude_ai_Slack__slack_read_channel", "mcp__claude_ai_Slack__slack_read_file", "mcp__claude_ai_Slack__slack_read_thread", "mcp__claude_ai_Slack__slack_read_user_profile", "mcp__claude_ai_Slack__slack_schedule_message", "mcp__claude_ai_Slack__slack_search_channels", "mcp__claude_ai_Slack__slack_search_emojis", "mcp__claude_ai_Slack__slack_search_public", "mcp__claude_ai_Slack__slack_search_public_and_private", "mcp__claude_ai_Slack__slack_search_users", "mcp__claude_ai_Slack__slack_send_message", "mcp__claude_ai_Slack__slack_send_message_draft", "mcp__claude_ai_Slack__slack_update_canvas", "mcp__plugin_context7_context7__query-docs", "mcp__plugin_context7_context7__resolve-library-id", "mcp__techlead-hosted__post", "mcp__techlead-hosted__propose_case", "mcp__techlead-hosted__review", "mcp__techlead-hosted__signals"], "mcp_servers": [], "model": "claude-opus-5-5", "permissionMode": "bypassPermissions", "slash_commands": [], "terminal_slash_commands": [], "apiKeySource": "none", "claude_code_version": "2.1.282", "output_style": "default", "agents": [], "skills": [], "plugins": [], "capabilities": ["interrupt_receipt_v1", "interrupt_cancel_queued_v1", "msg_lifecycle_v1", "mcp_read_resource_v1", "mcp_tool_ui_meta_v1"], "analytics_disabled": false, "product_feedback_disabled": false, "uuid": "0ad7c54e-a817-406b-af22-8f647b4e0021", "memory_paths": {}, "messaging_socket_path": "", "fast_mode_state": "off", "fast_mode_disabled_reason": "sdk_opt_in_required", "per_turn_effort_active": true, "view_mode": "default"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZ2iQ3sZ59vJ9CCae9", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "name": "Bash", "input": {"command": "echo hello", "description": "Print hello"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 23584, "cache_read_input_tokens": 10119, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 23584}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "b4c3b51e-0a58-4b28-8c5a-20a2ff2aaadb", "timestamp": "2026-09-25T17:22:54.134Z", "request_id": "req_011CfQYZ2Ddp5YubZj8vB9Fb", "wire_tool_inputs": {"toolu_01P8qrSZwqH1jjZXfrZETjKz": {"command": "echo hello", "description": "Print hello"}}} +{"type":"assistant","message":{"content":[{"type":"tool_use" +{"type": "rate_limit_event", "rate_limit_info": {"status": "allowed_warning", "resetsAt": 1790377200, "rateLimitType": "seven_day", "utilization": 0.98, "isUsingOverage": false, "surpassedThreshold": 0.75, "unifiedWindows": {"five_hour": {"utilization": 0.76, "resetsAt": 1790366400}, "seven_day": {"utilization": 0.98, "resetsAt": 1790377200}}}, "uuid": "a91b2340-329e-4c73-8e1a-307860859743", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "type": "tool_result", "content": "hello", "is_error": false}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "6beae671-52a0-499a-b72b-f9321c1d9e14", "timestamp": "2026-09-25T17:22:54.460Z", "tool_use_result": {"stdout": "hello", "stderr": "", "interrupted": false, "isImage": false, "noOutputExpected": false}} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZHW9AJ164FSYj39uG", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01YNNETbc61jN44ATXrmHdEC", "name": "Bash", "input": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 580, "cache_read_input_tokens": 33703, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 580}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "3b14941d-c8eb-45f4-b555-829e06119f19", "timestamp": "2026-09-25T17:22:56.420Z", "request_id": "req_011CfQYZH18nwJgBYNZs8XGq", "wire_tool_inputs": {"toolu_01YNNETbc61jN44ATXrmHdEC": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}}} +{"type": "user", "message": {"role": "user", "content": [{"type": "tool_result", "content": "Exit code 1\ncat: /nonexistent-file: No such file or directory", "is_error": true, "tool_use_id": "toolu_01YNNETbc61jN44ATXrmHdEC"}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "395dc93d-0e4f-40b5-854b-77a128aa0990", "timestamp": "2026-09-25T17:22:56.442Z", "tool_use_result": "Error: Exit code 1\ncat: /nonexistent-file: No such file or directory"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZRy8qPUaVcnVs9CQD", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "done\n\nThe first command printed `hello`. The second failed with \"No such file or directory\".\n\nGoogle Drive, exa and intercom still need authorizing. Google Drive is set up in its claude.ai connector settings. For exa and intercom, run `/mcp` in an interactive session."}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 145, "cache_read_input_tokens": 34283, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 145}, "output_tokens": 89, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "8f97a329-c76c-4b90-b154-bda9468b969d", "timestamp": "2026-09-25T17:22:58.580Z", "request_id": "req_011CfQYZRSdq9mNMbE7n8okT"} +{"duration_api_ms": 7263, "stop_reason": "end_turn", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "total_cost_usd": 0.21507700000000002, "usage": {"input_tokens": 6, "cache_creation_input_tokens": 24309, "cache_read_input_tokens": 78105, "output_tokens": 248, "output_tokens_details": {"thinking_tokens": 0}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 24309, "ephemeral_5m_input_tokens": 0}, "inference_geo": "not_available", "iterations": [{"input_tokens": 2, "output_tokens": 89, "cache_read_input_tokens": 34283, "cache_creation_input_tokens": 145, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 145}, "type": "message"}], "speed": "standard"}, "modelUsage": {"claude-opus-5-5": {"inputTokens": 6, "outputTokens": 248, "cacheReadInputTokens": 78105, "cacheCreationInputTokens": 24309, "webSearchRequests": 0, "costUSD": 0.21507700000000002, "contextWindow": 1000000, "maxOutputTokens": 128000, "thinkingTokens": 0, "canonicalModel": "claude-opus-5-5", "provider": "firstParty", "costBasis": "list"}}, "permission_denials": [], "terminal_reason": "completed", "fast_mode_state": "off", "fast_mode_disabled_reason": "sdk_opt_in_required", "subagent_stats": {"spawned": 0, "requested": {"background": 0, "foreground": 0, "unset": 0}, "started_in_background": 0, "max_depth": 0, "spawned_by_subagents": 0, "completed": 0, "failed": 0, "killed": {"parent": 0, "user": 0, "system": 0}, "refused": {"depth_limit": 0, "concurrency_limit": 0, "budget": 0}, "by_type": {}}, "is_error": false, "num_turns": 3, "subtype": "success", "api_error_status": null, "result": "done\n\nThe first command printed `hello`. The second failed with \"No such file or directory\".\n\nGoogle Drive, exa and intercom still need authorizing. Google Drive is set up in its claude.ai connector settings. For exa and intercom, run `/mcp` in an interactive session.", "ttft_ms": 3229, "type": "result", "duration_ms": 7717, "uuid": "d0b46ba2-f8ff-49eb-b35e-b4eb6b9b272b", "ttft_stream_ms": 2833, "time_to_request_ms": 102, "first_content_frame_ms": 2834, "queued_turn_count": 0, "result_index": 0} diff --git a/internal/agentexec/testdata/claude/run.jsonl b/internal/agentexec/testdata/claude/run.jsonl new file mode 100644 index 000000000..790a3514e --- /dev/null +++ b/internal/agentexec/testdata/claude/run.jsonl @@ -0,0 +1,16 @@ +{"type": "system", "subtype": "hook_started", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "959d5b3d-d376-4416-9abb-71e0b8a36047", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "1f5ed274-0baa-4558-b00f-36ef98d28ebc", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "5aa154a9-9315-4a6c-8de0-750cb35139cf", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_started", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "uuid": "ef74547a-736e-4bb9-bd68-16cc1592b2a3", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "3364ed13-2659-4abb-bda4-58243f1eb065", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "398b087e-942b-4d67-904c-1778d3b20063", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "04acf4c4-0c8d-4dd5-9d3a-a7a6df371224", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "ecbfdcf2-446c-4386-a89f-eeaf43e48b46", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "4c58406e-b5f0-49d7-af88-483c14212e0d", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "c10b3042-e990-49db-8937-954b6fe11570", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "hook_response", "hook_id": "a0cb320b-0bdd-45b5-90b5-451add28d1ed", "hook_name": "SessionStart:startup", "hook_event": "SessionStart", "output": "", "stdout": "", "stderr": "", "exit_code": 0, "outcome": "success", "uuid": "3a3327f8-ad24-46d7-a194-e0ce68f9f871", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "system", "subtype": "init", "cwd": "/workspace", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "tools": ["Task", "Bash", "CronCreate", "CronDelete", "CronList", "DesignSync", "Edit", "EnterWorktree", "ExitWorktree", "ListAgents", "ListMcpResourcesTool", "LSP", "Monitor", "NotebookEdit", "PushNotification", "Read", "ReadMcpResourceDirTool", "ReadMcpResourceTool", "RemoteTrigger", "ReportFindings", "ScheduleWakeup", "SendMessage", "Skill", "TaskStop", "ToolSearch", "WebFetch", "WebSearch", "Workflow", "Write", "mcp__claude_ai_Claude_Docs__batch", "mcp__claude_ai_Claude_Docs__create", "mcp__claude_ai_Claude_Docs__delete", "mcp__claude_ai_Claude_Docs__export", "mcp__claude_ai_Claude_Docs__guide", "mcp__claude_ai_Claude_Docs__query", "mcp__claude_ai_Claude_Docs__read", "mcp__claude_ai_Claude_Docs__update", "mcp__claude_ai_Context7__query-docs", "mcp__claude_ai_Context7__resolve-library-id", "mcp__claude_ai_Excalidraw__create_view", "mcp__claude_ai_Excalidraw__read_me", "mcp__claude_ai_Gmail__apply_sensitive_message_label", "mcp__claude_ai_Gmail__apply_sensitive_thread_label", "mcp__claude_ai_Gmail__create_draft", "mcp__claude_ai_Gmail__create_label", "mcp__claude_ai_Gmail__delete_draft", "mcp__claude_ai_Gmail__delete_label", "mcp__claude_ai_Gmail__forward", "mcp__claude_ai_Gmail__get_draft", "mcp__claude_ai_Gmail__get_message", "mcp__claude_ai_Gmail__get_thread", "mcp__claude_ai_Gmail__label_message", "mcp__claude_ai_Gmail__label_thread", "mcp__claude_ai_Gmail__list_drafts", "mcp__claude_ai_Gmail__list_labels", "mcp__claude_ai_Gmail__mark_message_spam", "mcp__claude_ai_Gmail__mark_thread_spam", "mcp__claude_ai_Gmail__reply", "mcp__claude_ai_Gmail__search_threads", "mcp__claude_ai_Gmail__send_message", "mcp__claude_ai_Gmail__trash_message", "mcp__claude_ai_Gmail__trash_thread", "mcp__claude_ai_Gmail__unlabel_message", "mcp__claude_ai_Gmail__unlabel_thread", "mcp__claude_ai_Gmail__unmark_message_spam", "mcp__claude_ai_Gmail__unmark_thread_spam", "mcp__claude_ai_Gmail__untrash_message", "mcp__claude_ai_Gmail__untrash_thread", "mcp__claude_ai_Gmail__update_draft", "mcp__claude_ai_Gmail__update_label", "mcp__claude_ai_Gmail__update_message_labels", "mcp__claude_ai_Google_Calendar__create_event", "mcp__claude_ai_Google_Calendar__delete_event", "mcp__claude_ai_Google_Calendar__get_event", "mcp__claude_ai_Google_Calendar__list_calendars", "mcp__claude_ai_Google_Calendar__list_events", "mcp__claude_ai_Google_Calendar__respond_to_event", "mcp__claude_ai_Google_Calendar__search_events", "mcp__claude_ai_Google_Calendar__suggest_time", "mcp__claude_ai_Google_Calendar__update_event", "mcp__claude_ai_Microsoft_365__chat_message_search", "mcp__claude_ai_Microsoft_365__find_meeting_availability", "mcp__claude_ai_Microsoft_365__get_granted_scopes", "mcp__claude_ai_Microsoft_365__get_me", "mcp__claude_ai_Microsoft_365__outlook_batch_delete_messages", "mcp__claude_ai_Microsoft_365__outlook_batch_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_calendar_search", "mcp__claude_ai_Microsoft_365__outlook_create_draft", "mcp__claude_ai_Microsoft_365__outlook_create_event", "mcp__claude_ai_Microsoft_365__outlook_create_filter", "mcp__claude_ai_Microsoft_365__outlook_create_label", "mcp__claude_ai_Microsoft_365__outlook_create_reply_all_draft", "mcp__claude_ai_Microsoft_365__outlook_create_reply_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_draft", "mcp__claude_ai_Microsoft_365__outlook_delete_event", "mcp__claude_ai_Microsoft_365__outlook_delete_filter", "mcp__claude_ai_Microsoft_365__outlook_delete_label", "mcp__claude_ai_Microsoft_365__outlook_email_search", "mcp__claude_ai_Microsoft_365__outlook_find_available_time", "mcp__claude_ai_Microsoft_365__outlook_forward_mail", "mcp__claude_ai_Microsoft_365__outlook_modify_labels", "mcp__claude_ai_Microsoft_365__outlook_modify_thread_labels", "mcp__claude_ai_Microsoft_365__outlook_respond_to_event", "mcp__claude_ai_Microsoft_365__outlook_send_draft", "mcp__claude_ai_Microsoft_365__outlook_send_mail", "mcp__claude_ai_Microsoft_365__outlook_set_vacation", "mcp__claude_ai_Microsoft_365__outlook_trash_thread", "mcp__claude_ai_Microsoft_365__outlook_untrash_thread", "mcp__claude_ai_Microsoft_365__outlook_update_draft", "mcp__claude_ai_Microsoft_365__outlook_update_event", "mcp__claude_ai_Microsoft_365__outlook_update_label", "mcp__claude_ai_Microsoft_365__read_resource", "mcp__claude_ai_Microsoft_365__search_people", "mcp__claude_ai_Microsoft_365__sharepoint_copy_item", "mcp__claude_ai_Microsoft_365__sharepoint_create_folder", "mcp__claude_ai_Microsoft_365__sharepoint_delete_item", "mcp__claude_ai_Microsoft_365__sharepoint_folder_search", "mcp__claude_ai_Microsoft_365__sharepoint_move_item", "mcp__claude_ai_Microsoft_365__sharepoint_rename_item", "mcp__claude_ai_Microsoft_365__sharepoint_search", "mcp__claude_ai_Microsoft_365__sharepoint_update_file", "mcp__claude_ai_Microsoft_365__sharepoint_upload_file", "mcp__claude_ai_Microsoft_365__teams_create_chat", "mcp__claude_ai_Microsoft_365__teams_list_channel_messages", "mcp__claude_ai_Microsoft_365__teams_list_channels", "mcp__claude_ai_Microsoft_365__teams_list_chats", "mcp__claude_ai_Microsoft_365__teams_list_teams", "mcp__claude_ai_Microsoft_365__teams_reply_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_channel_message", "mcp__claude_ai_Microsoft_365__teams_send_chat_message", "mcp__claude_ai_Slack__slack_add_reaction", "mcp__claude_ai_Slack__slack_create_canvas", "mcp__claude_ai_Slack__slack_create_conversation", "mcp__claude_ai_Slack__slack_get_reactions", "mcp__claude_ai_Slack__slack_list_channel_members", "mcp__claude_ai_Slack__slack_read_canvas", "mcp__claude_ai_Slack__slack_read_channel", "mcp__claude_ai_Slack__slack_read_file", "mcp__claude_ai_Slack__slack_read_thread", "mcp__claude_ai_Slack__slack_read_user_profile", "mcp__claude_ai_Slack__slack_schedule_message", "mcp__claude_ai_Slack__slack_search_channels", "mcp__claude_ai_Slack__slack_search_emojis", "mcp__claude_ai_Slack__slack_search_public", "mcp__claude_ai_Slack__slack_search_public_and_private", "mcp__claude_ai_Slack__slack_search_users", "mcp__claude_ai_Slack__slack_send_message", "mcp__claude_ai_Slack__slack_send_message_draft", "mcp__claude_ai_Slack__slack_update_canvas", "mcp__plugin_context7_context7__query-docs", "mcp__plugin_context7_context7__resolve-library-id", "mcp__techlead-hosted__post", "mcp__techlead-hosted__propose_case", "mcp__techlead-hosted__review", "mcp__techlead-hosted__signals"], "mcp_servers": [], "model": "claude-opus-5-5", "permissionMode": "bypassPermissions", "slash_commands": [], "terminal_slash_commands": [], "apiKeySource": "none", "claude_code_version": "2.1.282", "output_style": "default", "agents": [], "skills": [], "plugins": [], "capabilities": ["interrupt_receipt_v1", "interrupt_cancel_queued_v1", "msg_lifecycle_v1", "mcp_read_resource_v1", "mcp_tool_ui_meta_v1"], "analytics_disabled": false, "product_feedback_disabled": false, "uuid": "0ad7c54e-a817-406b-af22-8f647b4e0021", "memory_paths": {}, "messaging_socket_path": "", "fast_mode_state": "off", "fast_mode_disabled_reason": "sdk_opt_in_required", "per_turn_effort_active": true, "view_mode": "default"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZ2iQ3sZ59vJ9CCae9", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "name": "Bash", "input": {"command": "echo hello", "description": "Print hello"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 23584, "cache_read_input_tokens": 10119, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 23584}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "b4c3b51e-0a58-4b28-8c5a-20a2ff2aaadb", "timestamp": "2026-09-25T17:22:54.134Z", "request_id": "req_011CfQYZ2Ddp5YubZj8vB9Fb", "wire_tool_inputs": {"toolu_01P8qrSZwqH1jjZXfrZETjKz": {"command": "echo hello", "description": "Print hello"}}} +{"type": "rate_limit_event", "rate_limit_info": {"status": "allowed_warning", "resetsAt": 1790377200, "rateLimitType": "seven_day", "utilization": 0.98, "isUsingOverage": false, "surpassedThreshold": 0.75, "unifiedWindows": {"five_hour": {"utilization": 0.76, "resetsAt": 1790366400}, "seven_day": {"utilization": 0.98, "resetsAt": 1790377200}}}, "uuid": "a91b2340-329e-4c73-8e1a-307860859743", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92"} +{"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_01P8qrSZwqH1jjZXfrZETjKz", "type": "tool_result", "content": "hello", "is_error": false}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "6beae671-52a0-499a-b72b-f9321c1d9e14", "timestamp": "2026-09-25T17:22:54.460Z", "tool_use_result": {"stdout": "hello", "stderr": "", "interrupted": false, "isImage": false, "noOutputExpected": false}} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZHW9AJ164FSYj39uG", "type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01YNNETbc61jN44ATXrmHdEC", "name": "Bash", "input": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}, "caller": {"type": "direct"}}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 580, "cache_read_input_tokens": 33703, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 580}, "output_tokens": 16, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "3b14941d-c8eb-45f4-b555-829e06119f19", "timestamp": "2026-09-25T17:22:56.420Z", "request_id": "req_011CfQYZH18nwJgBYNZs8XGq", "wire_tool_inputs": {"toolu_01YNNETbc61jN44ATXrmHdEC": {"command": "cat /nonexistent-file", "description": "Read a nonexistent file"}}} +{"type": "user", "message": {"role": "user", "content": [{"type": "tool_result", "content": "Exit code 1\ncat: /nonexistent-file: No such file or directory", "is_error": true, "tool_use_id": "toolu_01YNNETbc61jN44ATXrmHdEC"}]}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "395dc93d-0e4f-40b5-854b-77a128aa0990", "timestamp": "2026-09-25T17:22:56.442Z", "tool_use_result": "Error: Exit code 1\ncat: /nonexistent-file: No such file or directory"} +{"type": "assistant", "message": {"model": "claude-opus-5-5", "id": "msg_011CfQYZRy8qPUaVcnVs9CQD", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "done\n\nThe first command printed `hello`. The second failed with \"No such file or directory\".\n\nGoogle Drive, exa and intercom still need authorizing. Google Drive is set up in its claude.ai connector settings. For exa and intercom, run `/mcp` in an interactive session."}], "container": null, "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 2, "cache_creation_input_tokens": 145, "cache_read_input_tokens": 34283, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 145}, "output_tokens": 89, "service_tier": "standard", "inference_geo": "not_available"}, "input_transformations": [], "diagnostics": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "uuid": "8f97a329-c76c-4b90-b154-bda9468b969d", "timestamp": "2026-09-25T17:22:58.580Z", "request_id": "req_011CfQYZRSdq9mNMbE7n8okT"} +{"duration_api_ms": 7263, "stop_reason": "end_turn", "session_id": "9c22c15c-80ef-42c6-a503-8d087ec47d92", "total_cost_usd": 0.21507700000000002, "usage": {"input_tokens": 6, "cache_creation_input_tokens": 24309, "cache_read_input_tokens": 78105, "output_tokens": 248, "output_tokens_details": {"thinking_tokens": 0}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 24309, "ephemeral_5m_input_tokens": 0}, "inference_geo": "not_available", "iterations": [{"input_tokens": 2, "output_tokens": 89, "cache_read_input_tokens": 34283, "cache_creation_input_tokens": 145, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 145}, "type": "message"}], "speed": "standard"}, "modelUsage": {"claude-opus-5-5": {"inputTokens": 6, "outputTokens": 248, "cacheReadInputTokens": 78105, "cacheCreationInputTokens": 24309, "webSearchRequests": 0, "costUSD": 0.21507700000000002, "contextWindow": 1000000, "maxOutputTokens": 128000, "thinkingTokens": 0, "canonicalModel": "claude-opus-5-5", "provider": "firstParty", "costBasis": "list"}}, "permission_denials": [], "terminal_reason": "completed", "fast_mode_state": "off", "fast_mode_disabled_reason": "sdk_opt_in_required", "subagent_stats": {"spawned": 0, "requested": {"background": 0, "foreground": 0, "unset": 0}, "started_in_background": 0, "max_depth": 0, "spawned_by_subagents": 0, "completed": 0, "failed": 0, "killed": {"parent": 0, "user": 0, "system": 0}, "refused": {"depth_limit": 0, "concurrency_limit": 0, "budget": 0}, "by_type": {}}, "is_error": false, "num_turns": 3, "subtype": "success", "api_error_status": null, "result": "done\n\nThe first command printed `hello`. The second failed with \"No such file or directory\".\n\nGoogle Drive, exa and intercom still need authorizing. Google Drive is set up in its claude.ai connector settings. For exa and intercom, run `/mcp` in an interactive session.", "ttft_ms": 3229, "type": "result", "duration_ms": 7717, "uuid": "d0b46ba2-f8ff-49eb-b35e-b4eb6b9b272b", "ttft_stream_ms": 2833, "time_to_request_ms": 102, "first_content_frame_ms": 2834, "queued_turn_count": 0, "result_index": 0}