Skip to content

feat(storage): add agentId filter to aggregation queries#1081

Merged
jpleva91 merged 1 commit intomainfrom
feat/agentid-aggregation-filter
Mar 27, 2026
Merged

feat(storage): add agentId filter to aggregation queries#1081
jpleva91 merged 1 commit intomainfrom
feat/agentid-aggregation-filter

Conversation

@jpleva91
Copy link
Copy Markdown
Collaborator

Closes #1029

Implementation Summary

What changed:

  • Added migration v5 to sessions table: new agent_id TEXT column with index (idx_sessions_agent_id), backfilled from RunStarted event JSON data
  • Added agentId?: string to SessionStartData and agent_id to SessionRow — sessions can now be stamped with an agent identity at creation time
  • Added agentId?: string to AggregationTimeFilter interface
  • Wired agentId into buildTimeConditions() — filters events/decisions to runs owned by the specified agent via sessions.agent_id
  • Refactored agentSummaries() to prefer sessions.agent_id (indexed) over json_extract() on RunStarted event data via COALESCE(s.agent_id, json_extract(...))
  • Updated migration test expectations for v5 (counts, version numbers, index checks)
  • Added 7 new tests: agentId filtering on agentSummaries, countEventsByKind, countDecisionsByOutcome, teamReport, empty results for non-existent agent, and sessions.agent_id precedence over event JSON

How to verify:

  1. pnpm build --filter=@red-codes/storage — builds clean
  2. pnpm test --filter=@red-codes/storage — all 206 tests pass
  3. pnpm lint --filter=@red-codes/storage — no lint errors

Tier C scope check:

  • Files changed: 5 (limit: 5)
  • Lines changed: ~219 (limit: 300)
  • Breaking changes: None — new optional field on existing interface, additive migration

Tier C implementation by copilot-cli — AgentGuard three-tier governance

- Add migration v5: agent_id column + index on sessions table with
  backfill from RunStarted event data
- Add agentId to SessionStartData and SessionRow interfaces
- Populate agent_id when inserting sessions
- Add agentId?: string to AggregationTimeFilter interface
- Wire agentId into buildTimeConditions() to join/filter via sessions
- Refactor agentSummaries() to prefer sessions.agent_id over
  json_extract() for faster indexed lookups
- Update migration test expectations for v5
- Add 7 new tests for agentId filtering across agentSummaries,
  countEventsByKind, countDecisionsByOutcome, and teamReport

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jpleva91 jpleva91 merged commit e6d14eb into main Mar 27, 2026
3 of 5 checks passed
jpleva91 pushed a commit that referenced this pull request Mar 27, 2026
…urity 6→5, risk 8→7

- Add 4 new shipped items to Current State table:
  - Credential file write detection via shell commands (PR #1032, closes #618)
  - Agent identity in agentguard inspect output (PR #1078, closes #1030)
  - agentId filter in storage aggregation queries (PR #1081, closes #1029)
  - Site user capture funnel hero/CTA/early access (PR #1076, closes #938)
- Update v3.0 capture funnel: mark site CTA done, list remaining CLI items with #1084
- Add #1086 tracking to Go Kernel Phase 1
- swarm-state.json: risk 8→7, security bypass count 6→5 (#618 removed),
  triaged new issues #1086/#1085/#1084/#1073/#1072/#1027/#1026

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add agentId filter to aggregation queries

1 participant