Skip to content

feat(abctl): Identity banner + token columns + plugin state helpers - #374

Merged
huang195 merged 2 commits into
rossoctl:mainfrom
huang195:feat/abctl-identity-banner
May 6, 2026
Merged

huang195 merged 2 commits into
rossoctl:mainfrom
huang195:feat/abctl-identity-banner

Conversation

@huang195

@huang195 huang195 commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

Three cohesive additions to the session-observability layer on top of the merged abctl TUI (#372).

1. IDENTITY banner on the events pane

Caller identity (subject / client / scopes) now shows once at the session level instead of repeating on every event row. Scopes truncated to 3 entries with +N more so long scope lists don't overflow. Banner only renders when inbound identity is present; table height accounts for it only when it renders.

2. TOKENS column on sessions + events panes

  • Server: new TotalTokens field on SessionSummary, aggregated in ListSessions via sumTokens().
  • Sessions pane: prefers the server total; falls back to a client-side sum over cached events for older-server compat.
  • Events pane: shows per-call TotalTokens only on inference response rows.
  • Shared formatCount helper for thousands-separator display (1,203).

3. pipeline.GetState[T] / pipeline.SetState[T] — plugin-private per-request state

type rlState struct { TokensAtStart int }

// In OnRequest:
pipeline.SetState(pctx, "rate-limiter", &rlState{TokensAtStart: 100})

// In OnResponse:
s := pipeline.GetState[rlState](pctx, "rate-limiter")

Lets new plugins stash typed state on pctx.Extensions.Custom keyed by plugin name, without extending the core Extensions struct for every new plugin. Named typed slots (MCP, A2A, Inference, …) stay reserved for telemetry-worthy extensions that flow onto the wire API; GetState/SetState covers everything internal to a single plugin.

Also

  • Drop identity from per-event detail render (banner supersedes it); yank still writes the full wire JSON.
  • Use struct key {subject, clientID} for identity dedup instead of "|"-concatenation.
  • Unit tests: sumTokens, ListSessions.TotalTokens, SetState/GetState round-trip, mutation visibility, wrong-type degradation, missing key, multi-plugin isolation.

Test plan

  • go test ./... in authlib and cmd/abctl — all green.
  • Manual: send messages via the UI, confirm TOKENS column on sessions pane populates immediately (no drill-through needed).
  • Manual: drill into a session, confirm IDENTITY banner renders above events table.
  • Manual: events table row count preserved when banner renders (no cropping).
  • yank still writes the full unfiltered event JSON to /tmp/abctl-event-*.json.

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Three cohesive additions to the session-observability layer:

1. abctl IDENTITY banner on the events pane. Caller identity (subject /
   client / scopes) now shows once at session level instead of repeating
   on every event row. Scopes are truncated to 3 entries with "+N more"
   so long scope lists don't overflow the banner. Banner only renders
   when inbound identity is present, and its height is subtracted from
   the events table height only when actually shown.

2. TOKENS column on the sessions and events panes. Server-side: add
   TotalTokens to SessionSummary, aggregated in ListSessions via a new
   sumTokens helper that walks inference response events. Client-side:
   sessions pane prefers the server total (authoritative, covers the full
   backlog) and falls back to a client-side sum over cached events when
   the server returned zero (older server compat). Events pane shows the
   per-call total only on inference response rows. Both use a shared
   formatCount helper in util.go for thousands separators.

3. pipeline.GetState[T] / pipeline.SetState[T] generic helpers for
   plugin-private per-request state. Lets a new plugin stash typed data
   on pctx.Extensions.Custom keyed by its Name() without extending the
   core Extensions struct for every new plugin. Named typed slots (MCP,
   A2A, Inference, ...) stay reserved for telemetry-worthy extensions
   that flow onto the wire API; GetState/SetState covers everything
   that's internal to a single plugin. Test file covers round-trip,
   mutation visibility, wrong-type degradation, missing key, and
   multi-plugin isolation.

Other cleanups:

- Drop "identity" from per-event detail render (banner supersedes it);
  yank still writes the full wire JSON.
- Use a struct key {subject,clientID} for identity dedup instead of
  "|"-concatenation.
- Add unit tests for sumTokens and ListSessions.TotalTokens.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
formatCount(-100) .. formatCount(-999) produced "-,100" .. "-,999"
because the leading '-' was counted as a digit in the triplet math
(len("-abc") % 3 == 1 ⇒ wrote s[:1] = "-", then the loop added a
separator + "abc"). Same band-shape break hit 6-digit and 9-digit
negatives. Token counts are non-negative so there was no runtime
impact, but the helper was documented as handling negatives and will
be reused. Strip the sign up front, group the digits, and re-apply.

Added tui/util_test.go with a table covering the previously-broken
3/6-digit negatives and the paths that already worked, locking in the
contract.

Also widen the sessions-pane TOKENS column from 8 to 10: "1,234,567"
is 9 chars, so any session crossing 1M tokens (plausible for multi-
turn agentic runs) would truncate under width 8. The events-pane
TOKENS column stays at 8 — per-call totals rarely exceed 6 digits.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clean, well-structured PR. Three cohesive additions to the session-observability layer:

  1. Identity banner — proper struct-key dedup, height accounting guards minimum table size
  2. Token columns — sumTokens correctly filters to inference response-phase events; sessions pane falls back to client-side sum for older-server compat
  3. GetState[T]/SetState[T] — nil-safe, type-safe generics with lazy map init; good separation between telemetry-worthy named slots and plugin-internal state

All CI green. Both commits DCO signed-off. Unit tests cover edge cases (negative formatCount, wrong-type degradation, multi-plugin isolation).

Assisted-By: Claude Code

@huang195
huang195 merged commit 8b55d3c into rossoctl:main May 6, 2026
17 checks passed
@huang195
huang195 deleted the feat/abctl-identity-banner branch May 6, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants