Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/agentop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion cmd/agentop/tui/detail_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — the len(pa) > 0 guard means a response carrying "plugins": {} keeps the empty object, while the PR body says dropShared "removes plugins when no record is left" — and the all-equal case (covered by the new dropShared(req, req) test) does remove it. Degenerate input, so just a nit, but if you want the body's claim to hold unconditionally, drop the guard and let the len(pa) == 0 branch handle it.

Suggested fix: if json.Unmarshal(...) == nil && json.Unmarshal(...) == nil { (no len(pa) > 0), keeping the existing len(pa) == 0 → delete(a, "plugins") branch.

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
Expand Down
7 changes: 4 additions & 3 deletions cmd/agentop/tui/detail_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions cmd/agentop/tui/detail_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions cmd/agentop/tui/detail_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions cmd/agentop/tui/detail_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion core/sessionapi/detail_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — the new keys are added only to the request-side list, which matches the PR body ("the proxy records" them on requests). Worth confirming that responses never carry any of these names on this proxy path: if a response ever echoes e.g. agentRole, it will now render in the response pane as an unrecognized key rather than under the inference group. The updated TestDetailKeys covers the request side; a hasNot assertion on the response-side row ({"inference", true, ...}) for effort/thinkingType would pin this down cheaply.

// How the agent asked the model to think. A change of effort breaks the prompt cache.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: two thinking fields still do not show. thinkingDisplay is the sibling of thinkingType on the request (InferenceExtension.ThinkingDisplay). responseThinking is the response-side counterpart of historyThinking: whether the model actually returned thinking blocks. If the goal is to debug thinking and cache-cost problems from the pane, consider adding thinkingDisplay here and responseThinking to the response list. Both are scalars or small structs that view=summary keeps, so the search route is unaffected, as with the five keys in this PR.

"effort", "thinkingType", "anthropicBeta", "agentRole", "historyThinking"},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: adding agentRole (and the other keys) to the request's detail view changes what the README demo renders. Go CI (README demo) › TestCommittedAssetIsCurrent now fails: docs/assets/cortex-demo.svg is stale (committed 470502 bytes, regenerated 470709 bytes). The same job passes on main at b83e6da. I reproduced it on this head, and the regenerated SVG's diff is the request pane gaining "agentRole": "main",, which pushes the following lines down. Run go -C scripts/readme-demo run . and commit docs/assets/cortex-demo.svg.

// 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.
Expand Down
2 changes: 1 addition & 1 deletion core/sessionapi/detail_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
Loading
Loading