Repository navigation
feat(lk): lk analytics session list --agent-id filters by cloud agent - #1144
JackNDwyer wants to merge 1 commit into
Conversation
The Public API's ListProjectSessions already filters by the cloud agent that served a session (filter.agentId), but the CLI didn't send it, so a coding agent asked for one agent's sessions had to list every session and guess. --agent-id takes a CA_ ID, as lk agent list shows it, and requires --user-auth like the other filters. A value that isn't a CA_ ID fails before any request, since the API filters by ID, not agent name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| Statuses: cmd.StringSlice("status"), | ||
| RoomPrefix: cmd.String("room"), | ||
| Tags: cmd.StringSlice("tag"), | ||
| AgentID: cmd.String("agent-id"), |
There was a problem hiding this comment.
🟡 Empty agent flag returns unfiltered sessions
With --agent-id="", sessionListOptions accepts an empty ID. listProjectSessionsParams omits the agent filter, so results can include sessions from other agents.
Learn more
The public client uses an empty AgentID to represent an omitted filter, which is appropriate for its zero-value options. The CLI can distinguish an omitted flag from an explicitly empty flag via cmd.IsSet, as the auth mode validator already does. It currently passes the parsed string alone, so both cases reach listProjectSessionsParams as an absent filter.
Example: An automation script runs lk --user-auth analytics session list --agent-id "$AGENT_ID" --json with an empty AGENT_ID. The command succeeds and returns the project’s session page without restricting it to an agent.
Recommended fix: In sessionListOptions, reject an explicitly set but empty --agent-id before constructing the options. Keep an omitted flag valid and add a command options test for --agent-id=.
Was this helpful? React with 👍 or 👎 to provide feedback.
The Public API's
ListProjectSessionsalready filters by the cloud agent that served a session (filter.agentId), butlk analytics session listdidn't expose it. A coding agent asked "show me this agent's sessions" had to list everything and filter by guesswork.--agent-id CA_…sendsfilter.agentId. Like--roomand--tag, it requires--user-authand stays hidden until a user signs in.CA_ID fails before any request, with a pointer tolk agent list. The API filters by cloud agent ID, not name, so a name would otherwise return an empty list that looks like "no sessions."Not in this PR: filtering by agent name. A self-hosted agent has no
CA_ID and the sessions API can't filter by name, so that needs upstream work. Oncelk agent listworks under--user-auth(#1138), a follow-up could take a name and look up its ID.Tested with
go test ./cmd/lk/ ./pkg/public/, plus new cases for the query param, the flag, the bad-ID error, and the API-key-mode refusal.🤖 Generated with Claude Code