diff --git a/cmd/agentop/README.md b/cmd/agentop/README.md index 76fac1538..48dae05f0 100644 --- a/cmd/agentop/README.md +++ b/cmd/agentop/README.md @@ -1920,10 +1920,13 @@ section: `↵` on it opens it. In it: them, and each image or document as `[image image/png 34.1kB]`. - `forwarded` says whether a plugin rewrote the body, and `forwardedBody` is what went upstream when one did. -- `headers` and `query` are the request's, without credentials. -- In the RESPONSE section, `response` has the status, the headers, the body (a - compressed one as `[gzip body 12.0kB]`) and `truncated` or `incomplete` when - either applies. +- `query` is the request's. +- In the RESPONSE section, `response` has the status, the body (a compressed one as + `[gzip body 12.0kB]`) and `truncated` or `incomplete` when either applies. + +The captured headers are in a closed `headers` node beside `raw`, not in it, so `↵` +opens them without the bodies. A request's headers are without credentials. A search +opens `headers` when it matches there. Each section has its own `raw`. Its capture comes with the fetch of that half, and agentop keeps it. A section has no `raw` when the archive has no capture for its diff --git a/cmd/agentop/tui/detail_pane.go b/cmd/agentop/tui/detail_pane.go index ad1330764..6df6fd45c 100644 --- a/cmd/agentop/tui/detail_pane.go +++ b/cmd/agentop/tui/detail_pane.go @@ -717,7 +717,8 @@ var sharedWithRequest = []string{"client", "direction", "host", "httpMethod", "h // dropShared leaves out of resp each sharedWithRequest field whose value equals req's. A field // that differs stays — a redirected response's host is news. at always stays: it is the // response's own time. Both inputs are filterForDetail's output, so equal values are equal -// bytes. Any decode failure returns resp as it was. +// bytes. Each plugin record in "plugins" that equals the request's goes too: a request-side +// plugin's record repeats on its response. Any decode failure returns resp as it was. func dropShared(resp, req []byte) []byte { var a, b map[string]json.RawMessage if json.Unmarshal(resp, &a) != nil || json.Unmarshal(req, &b) != nil { @@ -728,6 +729,19 @@ func dropShared(resp, req []byte) []byte { delete(a, k) } } + var pa, pb map[string]json.RawMessage + if json.Unmarshal(a["plugins"], &pa) == nil && json.Unmarshal(b["plugins"], &pb) == nil && len(pa) > 0 { + for k, v := range pa { + if bytes.Equal(v, pb[k]) { + delete(pa, k) + } + } + if len(pa) == 0 { + delete(a, "plugins") + } else if out, err := json.Marshal(pa); err == nil { + a["plugins"] = out + } + } out, err := json.Marshal(a) if err != nil { return resp diff --git a/cmd/agentop/tui/detail_raw.go b/cmd/agentop/tui/detail_raw.go index bb097a0f7..2aed1d1e7 100644 --- a/cmd/agentop/tui/detail_raw.go +++ b/cmd/agentop/tui/detail_raw.go @@ -13,7 +13,8 @@ import ( // and searches as one more node of the tree. The bodies are decoded into JSON where they are // JSON, which puts thinking blocks in place among the messages, and every image or document // becomes "[type size]" rather than its base64. An imported event e has no capture, so its -// "raw" node says so. +// "raw" node says so. The headers go beside "raw", not in it, so a reader sees them without +// opening the bodies. func withRaw(data []byte, raw *pipeline.RawCapture, e *pipeline.SessionEvent) []byte { if raw == nil && !e.Imported() { return data @@ -34,7 +35,7 @@ func withRaw(data []byte, raw *pipeline.RawCapture, e *pipeline.SessionEvent) [] p := raw.Response resp := map[string]any{"status": p.Status} if len(p.Headers) > 0 { - resp["headers"] = flatHeaders(p.Headers) + m["headers"] = flatHeaders(p.Headers) } if p.Truncated { resp["truncated"] = true @@ -69,7 +70,7 @@ func withRaw(data []byte, raw *pipeline.RawCapture, e *pipeline.SessionEvent) [] r["forwarded"] = "forwarded as sent" } if len(raw.RequestHeaders) > 0 { - r["headers"] = flatHeaders(raw.RequestHeaders) + m["headers"] = flatHeaders(raw.RequestHeaders) } if raw.Query != "" { r["query"] = raw.Query diff --git a/cmd/agentop/tui/detail_raw_test.go b/cmd/agentop/tui/detail_raw_test.go index ba3118a35..badd54e24 100644 --- a/cmd/agentop/tui/detail_raw_test.go +++ b/cmd/agentop/tui/detail_raw_test.go @@ -92,6 +92,27 @@ func TestDetailRaw_StartsClosedAndOpensWithEnter(t *testing.T) { } } +// The headers are beside raw, not in it: closed, but a reader opens them without the bodies. +func TestDetailRaw_HeadersBesideRaw(t *testing.T) { + ev := &pipeline.SessionEvent{Seq: 3, Phase: pipeline.SessionRequest, Direction: pipeline.Outbound, Host: "h", + Inference: &pipeline.InferenceExtension{Model: "m"}} + m := detailModel(t, "s1", ev) + m.applyDetailEvent(detailEventLoadedMsg{sessionID: "s1", seq: 3, event: ev, raw: &pipeline.RawCapture{Request: rawRequest, + RequestHeaders: map[string][]string{"X-App": {"cli"}}}}) + if out := stripANSI(strings.Join(lineTexts(m.detailLines), "\n")); strings.Contains(out, "X-App") { + t.Fatalf("headers start open:\n%s", out) + } + cursorTo(t, m, "headers") + press(m, tea.KeyEnter) + out := stripANSI(strings.Join(lineTexts(m.detailLines), "\n")) + if !strings.Contains(out, `"X-App": "cli"`) { + t.Fatalf("Enter did not open the headers:\n%s", out) + } + if strings.Contains(out, "read it whole") { + t.Fatalf("opening the headers opened the body:\n%s", out) + } +} + // A response's capture shows its status and flags, and a compressed body as its size. func TestDetailRaw_Response(t *testing.T) { ev := &pipeline.SessionEvent{Seq: 4, Phase: pipeline.SessionResponse, Direction: pipeline.Outbound, Host: "h", diff --git a/cmd/agentop/tui/detail_sections_test.go b/cmd/agentop/tui/detail_sections_test.go index e293bf9f0..3832c9818 100644 --- a/cmd/agentop/tui/detail_sections_test.go +++ b/cmd/agentop/tui/detail_sections_test.go @@ -96,4 +96,13 @@ func TestDropShared(t *testing.T) { if got, want := string(dropShared(resp, req)), `{"at":"2","host":"b","statusCode":200}`; got != want { t.Errorf("dropShared = %s, want %s: equal fields go, a different host and at stay", got, want) } + // A plugin record equal to the request's goes; one of the response's own stays. + req = []byte(`{"plugins":{"tool-prune":{"bytesRemoved":9},"cost":{"usd":1}}}`) + resp = []byte(`{"plugins":{"tool-prune":{"bytesRemoved":9},"cost":{"usd":2}}}`) + if got, want := string(dropShared(resp, req)), `{"plugins":{"cost":{"usd":2}}}`; got != want { + t.Errorf("dropShared = %s, want %s", got, want) + } + if got, want := string(dropShared(req, req)), `{}`; got != want { + t.Errorf("dropShared = %s, want %s: no record left drops plugins", got, want) + } } diff --git a/cmd/agentop/tui/detail_tree.go b/cmd/agentop/tui/detail_tree.go index abd4d2863..0c0c74c8a 100644 --- a/cmd/agentop/tui/detail_tree.go +++ b/cmd/agentop/tui/detail_tree.go @@ -231,6 +231,10 @@ func foldDefaults(root *node) { if raw := root.child("raw"); raw != nil && raw.fold { raw.defOpen, raw.noQueryOpen = false, true } + // The captured headers: 20 to 30 lines on real traffic. A search opens them. + if h := root.child("headers"); h != nil && h.fold { + h.defOpen = false + } // Every plugin's invocation, skips included, was half of a short request (#1681). The // section title names the plugins that acted, so the full list starts closed. if inv := root.child("invocations"); inv != nil && inv.fold { diff --git a/core/sessionapi/detail_keys.go b/core/sessionapi/detail_keys.go index 128b8ffbd..2add28b00 100644 --- a/core/sessionapi/detail_keys.go +++ b/core/sessionapi/detail_keys.go @@ -11,7 +11,9 @@ import "slices" var detailKeys = map[string][2][]string{ "inference": { {"model", "requestedModel", "messages", "temperature", "maxTokens", "topP", - "stream", "tools", "toolChoice", "toolResults", "historyToolCalls"}, + "stream", "tools", "toolChoice", "toolResults", "historyToolCalls", + // How the agent asked the model to think. A change of effort breaks the prompt cache. + "effort", "thinkingType", "anthropicBeta", "agentRole", "historyThinking"}, // reasoningTokens is a SUBSET of completionTokens, not a sibling: it is the share // of the generated tokens the model spent reasoning, billed at the output rate. // Adding the two double-counts every one of them. diff --git a/core/sessionapi/detail_keys_test.go b/core/sessionapi/detail_keys_test.go index 51fa7c226..561019de9 100644 --- a/core/sessionapi/detail_keys_test.go +++ b/core/sessionapi/detail_keys_test.go @@ -14,7 +14,7 @@ func TestDetailKeys(t *testing.T) { has []string hasNot []string }{ - {"inference", false, []string{"messages", "tools", "toolResults", "historyToolCalls"}, []string{"completion", "toolCalls"}}, + {"inference", false, []string{"messages", "tools", "toolResults", "historyToolCalls", "effort", "thinkingType"}, []string{"completion", "toolCalls"}}, {"inference", true, []string{"completion", "toolCalls", "reasoningTokens"}, []string{"messages", "tools"}}, {"mcp", false, []string{"params"}, []string{"result"}}, {"mcp", true, []string{"result", "error"}, []string{"params"}}, diff --git a/docs/assets/cortex-demo.svg b/docs/assets/cortex-demo.svg index 1a9feddb7..18dfdc4d8 100644 --- a/docs/assets/cortex-demo.svg +++ b/docs/assets/cortex-demo.svg @@ -5172,45 +5172,45 @@ clipPath rect{width:100000px} ▾ "inference": { -▾ "messages": [ +"agentRole": "main", -▸ 8 earlier messages · 1.4kB +▾ "messages": [ -▾ { +▸ 8 earlier messages · 1.4kB -"content": "Running the tests to confirm the change holds.", +▾ { -"role": "assistant", +"content": "Running the tests to confirm the change holds.", -"toolCallNames": "Bash", +"role": "assistant", -▾ "toolCalls": [ +"toolCallNames": "Bash", -▌▾ { +▾ "toolCalls": [ -"arguments": "{\"command\":\"npm test -- Settings\"}", +▌▾ { -"id": "toolu_web_04", +"arguments": "{\"command\":\"npm test -- Settings\"}", -"name": "Bash" +"id": "toolu_web_04", -} +"name": "Bash" -] +} -}, +] -▾ { +}, [↑↓] move [↵] fold [tab] response [y] yank request [u] usage [/] search [esc] back [?] keys [q] quit -"host": "api.anthropic.com", +"httpMethod": "POST", -"httpMethod": "POST", +"httpPath": "/v1/messages", -"httpPath": "/v1/messages", +▾ "inference": { -▾ "inference": { +"agentRole": "main", ▾ "messages": [