Skip to content

CLI: agentmetry detections <correlation_id> #8

Closed

Description

@blitzcrieg1

You can query a session's detections over HTTP, but there is no CLI shortcut. A one-liner would be handy for incident triage.

Task

Add a detections subcommand that calls GET /api/v1/audit/detections/{correlation_id} and prints the results as a readable table (rule, severity, summary).

File: apps/orchestrator/agentmetry/cli/__init__.py

Model it on cmd_stats, not cmd_replay. cmd_stats is the one that reads over HTTP and handles the server-not-running case. cmd_replay reads the outbox directly and is the wrong pattern here.

The endpoint

audit_detections in apps/orchestrator/agentmetry/api/routes/audit.py returns:

{
  "detections": [ ... ],
  "correlation_id": "...",
  "count": 0,
  "untriaged": 0,
  "enabled": true
}

Each detection carries rule_id, severity, title, summary, event_ids, tactic_ids, technique_ids, and disposition (null when untriaged). When audit export is disabled the endpoint returns enabled: false with an empty list, which is a different message from "no detections".

untriaged is worth surfacing. An untriaged critical is what turns a dogfood week red, so it is the number an operator acts on.

Acceptance criteria

  • agentmetry detections <id> prints ranked detections, or "no detections" cleanly
  • Distinguishes "no detections" from "audit export disabled"
  • Handles server-not-running with a clear message, the way cmd_stats does
  • Severity ordering is critical, high, medium, low. SEVERITY_RANK in core/audit/detection/models.py already defines it, so use that rather than a new list
  • A test in apps/orchestrator/tests/, mocking the HTTP call the way the existing CLI tests do

Notes

Related to but separate from #100, which adds a disposition command for closing a detection. This issue is read-only. #100 is unassigned if you want both later, but they are independently useful and this one stands alone.

One known wrinkle, not yours to fix: the endpoint is behind require_api_key, which currently returns early when AGENTMETRY_API_KEY is unset. So it works locally with no key. cmd_stats does not send a key either, so match it and do not solve auth here.

Activity

  1. added
    enhancement
    good first issue
    on Jul 14, 2026
  2. hossainzarif23 commented on Aug 30, 2026

    @hossainzarif23
    Contributor

    I would like to work on this one.

  3. blitzcrieg1 commented on Aug 30, 2026

    @blitzcrieg1
    OwnerAuthor

    Assigned, it is yours.

    I checked the issue against the code before handing it over and found two things in it that would have cost you your first hour, so I have corrected the body.

    The file path was wrong. It said apps/orchestrator/cli/__init__.py. The CLI actually lives at apps/orchestrator/agentmetry/cli/__init__.py.

    The suggested model was wrong. It said to mirror how replay reads from the API. cmd_replay does not read from the API at all; it reads the outbox directly. cmd_stats is the one to copy, including its server-not-running handling.

    I also added the endpoint's actual response shape, since you would otherwise have had to go read the route to find out that it returns count, untriaged and an enabled flag alongside the detections.

    Two things worth knowing that are not obvious from the issue:

    untriaged is the number an operator actually acts on. An untriaged critical is what turns a dogfood week red, so surfacing it is worth more than a raw count.

    Severity ordering already exists as SEVERITY_RANK in core/audit/detection/models.py. Use it rather than writing a new list, because a second ordering is a second thing to drift.

    No deadline from me. Ask here if anything is unclear, and if you hit something that turns out to be wrong in the codebase rather than in your change, say so. That has been the more common outcome this week.

  4. hossainzarif23 commented on Aug 31, 2026

    @hossainzarif23
    Contributor

    Can you please check the PR? The jobs aren't running for some reason even after the CLA signature.

  5. added a commit that references this issue on Sep 1, 2026
    9e7c379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions