Skip to content

feat(cli): add detections command for triage - #139

Merged
blitzcrieg1 merged 2 commits into
blitzcrieg1:masterfrom
hossainzarif23:feat/cli-detections
Sep 3, 2026
Merged

blitzcrieg1 merged 2 commits into
blitzcrieg1:masterfrom
hossainzarif23:feat/cli-detections

Conversation

@hossainzarif23

Copy link
Copy Markdown
Contributor

Summary

Adds agentmetry detections <correlation_id> so a session's correlated
detections can be inspected without calling the audit API manually.

  • Calls GET /api/v1/audit/detections/{correlation_id}
  • Preserves the API's severity-ranked result order
  • Renders rule ID, severity, and summary as a readable table
  • Reports sessions with no detections cleanly and exits successfully
  • Returns a clear message and non-zero exit code when the orchestrator is unavailable

Why

The detections endpoint already supports session-level incident triage, but
CLI users currently need to construct the HTTP request themselves. This adds
the one-line workflow described in the issue while keeping ranking logic in
the detection API.

Testing

  • python -m ruff check agentmetry tests tools
  • python -m pytest -q — 1154 passed, 1 skipped
  • Manually verified a seeded session with multiple detections
  • Manually verified an unknown session returns No detections
  • Manually verified an unavailable server returns exit code 1

Scope

This is limited to the CLI command and its focused tests. It does not change
the detections API, detection rules, event schema, or dashboard.

Closes #8

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hossainzarif23

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@hossainzarif23

Copy link
Copy Markdown
Contributor Author

recheck

github-actions Bot added a commit that referenced this pull request Aug 31, 2026
@blitzcrieg1

Copy link
Copy Markdown
Owner

Thank you for this, and for the three install bugs you filed on the way to it. Finding that the project does not install on a clean Windows machine was far more valuable than the issue you were assigned, and all three are fixed and released in #141. That is the kind of contribution nobody on the inside can make, because we all have working machines.

The CLA check was red on a stale run from before you signed. I have re-run it and this is now green.

The implementation follows cmd_stats exactly as asked, the column widths are computed rather than guessed, and the tests cover the shape properly. I checked one thing rather than assuming: the engine already sorts by SEVERITY_RANK at engine.py:67, so the API hands you ranked results and your test name is accurate. No client-side sort needed.

One thing before I merge

The endpoint returns enabled: false when audit export is switched off, with an empty detections list. Right now that prints:

No detections for <id>.

Which is not true. It means nothing was ever recorded for any session, and someone reading that would go looking for a session that was never captured rather than turning export on.

Something like:

if not data.get("enabled", True):
    print("Audit export is disabled, so no sessions are recorded.")
    print("Set AGENTMETRY_AUDIT_EXPORT=1 and restart.")
    return 1

cmd_stats has the same distinction a few lines above yours, so it will look at home. A test for it would round the set out nicely.

That is the only change. Push it and I will merge.

If you want more

You clearly have a good eye for the parts that break for a first-time user, which is the part this project is weakest on and the hardest thing to see from the inside. #100 is the natural next one if you want it, though @kkkhs has a PR open for it, so #36 or #25 on benchmark corpus coverage may be better. Or anything you trip over while using it, which so far has been the richest seam.

And if you know anyone who would enjoy taking a detection tool apart, send them. The most useful thing anyone sends this project is a report that a rule fired on something legitimate, and there is a standing offer: a case that makes a rule misfire is worth more here than a case that confirms it works.

Incident triage currently requires calling the audit endpoint directly.

Expose ranked findings by correlation ID, with clean output for empty

sessions and an unavailable orchestrator.

Closes blitzcrieg1#8
@hossainzarif23

Copy link
Copy Markdown
Contributor Author

I have reproduced the exact problem actually. Now, I'm fixing this.

An empty detections list can mean export is disabled, not that the session
has no findings. Report the disabled state and return a non-zero exit code
so operators know recording must be enabled.
@blitzcrieg1
blitzcrieg1 merged commit 5f120f0 into blitzcrieg1:master Sep 3, 2026
9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: agentmetry detections <correlation_id>

2 participants