Skip to content

agentgate-verify: add a --format json output option #13

Description

@shreyanshjain7174

What

Add a --format json flag to cmd/agentgate-verify that emits the verification result as a single machine-readable JSON object on stdout, instead of (or as an alternative to) the current human-readable text lines.

Why

Today agentgate-verify's output (PASS: %d receipts verified, head seq=%d hash=%x, completeness: ..., range: ..., or FAIL: seq=%d reason=%s (...)) is designed to be read by a person, not parsed by a script or CI pipeline. A --format json option lets an auditor's tooling consume the result programmatically without scraping text.

Files to touch

  • cmd/agentgate-verify/main.go — add a --format flag (text default, json alternative) to the run() function's flag set; when json is selected, marshal a small result struct instead of the current fmt.Fprintf calls.
  • cmd/agentgate-verify/main_test.go — add test coverage for the new flag.

Suggested JSON shape

Something close to:

{
  "ok": true,
  "verified_count": 5,
  "head_seq": 5,
  "head_entry_hash": "a1b2c3...",
  "complete": true,
  "reason": "",
  "range": "full"
}

For a failure:

{
  "ok": false,
  "failed_at_seq": 3,
  "reason": "entry_hash_mismatch",
  "verified_count": 2,
  "total_receipts": 5
}

Match the existing receipt.VerifyResult struct's fields (internal/receipt/verifier.go) rather than inventing new field names where one already exists.

Exit codes must not change: 0 pass, 1 chain/signature mismatch, 2 I/O or config error — the same rule applies whether --format text or --format json is selected.

Acceptance checks

  • agentgate-verify --format json (with a valid, passing chain) exits 0 and prints one valid JSON object with "ok": true.
  • agentgate-verify --format json against a tampered chain exits 1 and prints one valid JSON object with "ok": false and the correct "reason".
  • The default (no --format flag, or --format text) behavior is byte-for-byte unchanged from today.
  • --format with an unrecognized value exits 2 with a clear stderr message, matching the existing pattern for other flag validation errors in run().

Test path (no secrets needed)

go test ./cmd/agentgate-verify/... -race -count=1 -v

The existing test helpers (buildTestChain, writeJSONLFile) already build real signed receipt chains in a temp SQLite database — no live AgentGate instance, network access, or secrets are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions