Reporting remediation and monitoring
AgentShield turns scan findings into outputs that people and tools can use, then keeps those findings useful after the first scan. It provides human reports, machine reports, portable evidence packs, safe fix actions, and change alerts so teams can review risk, hand off work, and detect regressions over time. See Runtime and operations for the wider operating model and Runtime and MiniClaw services for runtime enforcement services.
Reporting outputs
The reporting layer presents one scored SecurityReport through several interfaces. The scan command selects the primary format and can write it to a file, while CI can add SARIF and job-summary output around the same result. Human-facing reports can include an optional product message, but machine-facing JSON and SARIF stay free of that text.
Terminal reports
The terminal report is the main interactive view for an engineer at a shell. It gives the target, timestamp, grade, score breakdown, finding counts, severity groups, evidence, and suggested fixes in a compact colored layout. It also lists recognized defenses as context without treating them as score deductions. Optional harness and skill-health data appears when the scan supplies it. An opt-in CTA can appear at the end and can be suppressed for CI or scripted use.
References: src/…/terminal.ts• L14-30 src/…/terminal.ts• L31-127 src/…/terminal.ts• L544-600 src/…/cta.ts• L39-62
JSON reports
The JSON report preserves the scored report as structured data. It is suited to scripts and later processing because it keeps the findings, score, summary, recognized defenses, evidence, confidence, and fix fields instead of reducing them to display text. Its companion Markdown report can show an opt-in CTA for human review, while JSON stays clean. JSON and SARIF use standard output behavior when no output file is selected, so auxiliary status text does not corrupt the machine report on standard output.
References: src/…/json.ts• L29-39 src/…/json.ts• L50-64 src/…/json.ts• L120-133 src/…/cta.ts• L54-62 src/types.ts• L100-110 src/index.ts• L389-410
SARIF reports
SARIF is the interchange format for code-scanning systems such as GitHub code scanning. AgentShield maps findings to SARIF rules and results, carries file locations and severity, and can add organization-policy violations as separate results. Runtime confidence affects the reported precision, which helps downstream reviewers judge how directly a finding relates to an active runtime.
References: src/…/sarif.ts• L19-29 src/…/sarif.ts• L31-93 src/…/sarif.ts• L96-209 src/action.ts• L374-386
HTML reports
The HTML report is a self-contained review page for people who need a broad view of risk. It combines the grade and score with an executive posture, priority findings, category exposure, severity distribution, runtime confidence, finding evidence, and before/after fix views. It also shows counts for auto-fixable findings and recognized defenses. Inline styles make the file portable without external assets.
References: src/…/html.ts• L10-15 src/…/html.ts• L20-130 src/…/html.ts• L141-179 src/…/html.ts• L432-467
Recognized defenses
Recognized defenses are protective settings found during the same scan. They give reviewers evidence of controls such as permission gates, sandboxes, deny hooks, or narrow tool lists, but they do not raise or lower the security score. This keeps a visible control separate from a finding about attack surface.
References: src/…/defenses.ts• L11-18 src/…/defenses.ts• L43-77 src/…/score.ts• L27-53 src/…/terminal.ts• L546-559
Score signals
The score summarizes finding risk across secrets, permissions, hooks, MCP servers, and agents. It keeps lower-confidence examples and optional configuration from having the same weight as active runtime findings, while informational findings and recognized defenses do not create deductions. The result includes both an overall grade and a per-category breakdown so a report can show where attention is needed.
References: src/…/score.ts• L27-53 src/…/score.ts• L59-74 src/…/score.ts• L97-149 src/…/score.ts• L152-207
The report path from a scan to a consumer is shown below.
flowchart LR
A[Scan target] --> B[Scored security report]
B --> C[Terminal view]
B --> D[JSON data]
B --> E[SARIF findings]
B --> F[Self-contained HTML]
E --> G[Code-scanning system]
D --> H[Scripts and evidence pack]
Evidence packs
An evidence pack is a portable bundle that joins the scan result with the context needed for review and promotion. It records the main reports plus policy, baseline, supply-chain, CI, and remediation data so a later consumer can inspect one verified unit rather than reconstructing a scan from separate logs.
Bundle contents
The pack has a manifest and human guide around a fixed set of artifacts. Optional checks are represented by explicit not-run markers when they were not requested, which distinguishes an absent check from a passing check.
| Artifact group | Purpose |
|---|---|
| JSON, HTML, SARIF | Human review, automation, and code-scanning integration |
| Policy and baseline | Organization rule status and drift from the accepted state |
| Supply chain and CI context | Package risk plus workflow, commit, and runner provenance |
| Remediation plan | Stable work queue for automatic and manual actions |
| Manifest and README | Artifact inventory, bundle digest, and reading guide |
References: src/…/index.ts• L281-342 src/…/index.ts• L353-418 src/…/index.ts• L1249-1300
Pack integrity and privacy
Evidence packs are redacted by default before they leave the scan environment. Redaction replaces local target paths, home paths, user names, email addresses, and common token-shaped strings. Each artifact has a content hash and the bundle has a digest, so verification can detect missing or changed files before a pack is trusted.
References: src/…/index.ts• L353-407 src/…/index.ts• L421-508 src/…/index.ts• L1302-1386
Pack inspection and fleet routing
Inspection verifies the pack and returns a compact summary for downstream consumers. Fleet inspection applies the same model to many packs and routes each one to ready, security-blocker, policy-review, baseline-regression, supply-chain-review, or invalid. Non-ready packs produce owners, evidence paths, approval IDs, reversible actions, and ticket text so a review can move to the right queue.
References: src/…/index.ts• L510-620 src/…/index.ts• L622-703 src/…/index.ts• L705-855 src/…/index.ts• L958-1017 src/index.ts• L680-839
The evidence-pack lifecycle connects scan evidence to a promotion decision.
flowchart TD
A[Scan and score] --> B[Write reports and context]
B --> C[Create manifest and digests]
C --> D{Verify pack}
D -->|Invalid| E[Regenerate before promotion]
D -->|Valid| F[Inspect one or many packs]
F --> G{Route result}
G -->|Ready| H[Keep in promotion set]
G -->|Review route| I[Assign owner and approval]
G -->|Security blocker| J[Fix or explicitly approve]
Remediation workflow
Remediation separates changes that the tool can apply safely from changes that need maintainer judgment. A remediation plan gives every finding a stable fingerprint, an action type, a suggested command, and an ordered workflow that ends with a clean verification scan.
Remediation plans
The plan groups work into three possible phases: apply safe auto-fixes, resolve manual findings, and verify the updated scan. Auto-fix work is non-blocking in the plan, manual review is blocking, and verification is blocking whenever findings exist. The plan is also included in each evidence pack for CI handoff and ticket work.
References: src/…/index.ts• L20-71 src/…/index.ts• L89-114 src/…/index.ts• L133-213 src/…/index.ts• L375-391
Automated fix transforms
The fix engine acts only on findings marked fix.auto. It groups fixes by file, applies the finding's before/after change in memory, writes a file only when at least one change succeeds, and reports both applied and skipped work. Secret findings use a secret replacement transform, permission findings use a wildcard-tightening transform, and other auto-fixable findings use a generic replacement.
References: src/…/index.ts• L39-49 src/…/index.ts• L72-147 src/…/transforms.ts• L11-37 src/…/transforms.ts• L39-67 src/…/transforms.ts• L69-113
Remediation verification
Fixes do not prove that the system is safe by themselves. The verified fix path snapshots files, applies only marked safe changes, rescans the target, and rolls back written files when the score drops or a new high or critical finding appears. A successful run reports resolved and introduced findings plus a tamper-evident attestation that binds the result to the score change. A missing file or missing before-pattern produces a skipped fix instead of a silent write, so the engineer can decide whether the finding changed or the proposed transform no longer matches.
References: src/…/index.ts• L174-210 src/…/index.ts• L89-139 src/…/index.ts• L161-192 src/…/index.ts• L226-340
Watch alerts and diff monitoring
Watch mode turns repeated scans into a change signal for configuration directories. It takes an initial scan as the baseline, waits for a quiet debounce period after file events, rescans the target, and compares the new result with the previous baseline before sending an alert.
Baseline diffing
The diff uses a finding fingerprint made from the rule ID, file, and a short hash of the evidence. This keeps a finding recognizable across scans without placing full evidence in the identity. A drift result reports new findings, resolved findings, score movement, regression state, and whether a new critical finding appeared.
References: src/fingerprint.ts• L4-20 src/…/diff.ts• L7-20 src/…/diff.ts• L23-58 src/…/types.ts• L16-34
File watch cycle
The watcher monitors configured directories and supports recursive watching with a per-directory fallback on platforms that do not support recursive mode. It filters findings by the selected minimum severity for both the initial baseline and later scans. After each completed change scan, the new result becomes the next baseline.
References: src/…/watcher.ts• L24-79 src/…/watcher.ts• L104-165 src/…/watcher.ts• L168-231 src/…/types.ts• L3-14
Alert delivery
Alerts are sent only when a rescan finds new or resolved findings. Terminal alerts show score movement and the changed findings, with a clear critical warning when a new critical finding appears. Webhook alerts use the agentshield.drift JSON event and include the prior and current score plus compact new and resolved finding records. Delivery can target the terminal, a webhook, or both.
References: src/…/alerts.ts• L4-19 src/…/alerts.ts• L21-61 src/…/alerts.ts• L63-118 src/index.ts• L901-997
The watch loop turns a file change into a review signal as follows.
sequenceDiagram
participant F as Config file
participant W as Watch mode
participant S as Scanner
participant D as Baseline diff
participant A as Alert target
F->>W: Change event
W->>W: Wait for debounce period
W->>S: Scan target
S-->>W: Filtered findings and score
W->>D: Compare with prior baseline
D-->>W: New, resolved, and score changes
alt New or resolved findings
W->>A: Terminal and/or webhook alert
end
W->>W: Store new baseline
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the report shape, score summary, finding fields, recognized-defense fields, and SARIF rule/result mapping aligned when finding or score data changes.
- Keep human-only CTA text out of JSON and SARIF, and preserve the opt-in and hard-suppress behavior when report footers change.
- Keep evidence-pack artifact names, manifest entries, digest rules, README guidance, inspection summaries, and fleet routing aligned when a pack artifact changes.
- Preserve redaction across JSON, HTML, SARIF, remediation, CI context, and policy outputs when a new field can carry a path, identity, or secret.
- Keep remediation fingerprints and watch fingerprints compatible when finding identity fields or evidence formatting changes.
- Recheck machine-output behavior when adding scan status text, because JSON and SARIF may be written to standard output for automation.
- Recheck the action outputs and evidence-pack verification gate when changing CI report or pack behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An evidence-pack artifact is missing or changed | Verification fails and fleet routing marks the pack invalid | Run evidence-pack verification before promotion |
| Evidence redaction is disabled | Local paths, user data, emails, or token-shaped strings can remain in review artifacts | Keep redaction enabled unless the destination is trusted |
| A fix target file cannot be read or its before-pattern is absent | The fix is skipped and the source file is not changed for that finding | Review the skipped-fix reason and rerun the scan after the source changes |
| A verified fix lowers the score or adds a high or critical finding | Written files are rolled back and the attestation is marked unverified | Review the introduced finding and keep the reverted state until the fix is corrected |
| A new finding or score drop changes the baseline | The drift is marked as a regression; a new critical finding sets the critical flag | Review the diff and use the baseline gate where promotion must stop |
| A webhook endpoint rejects or does not answer within the timeout | The alert is logged as failed; the scan does not gain a delivered webhook | Use terminal or both alert modes and monitor webhook delivery |
| The initial watch scan cannot establish a baseline | Later changes have no prior result to compare against | Fix the path or scan error before relying on watch alerts |
Key files
| File | Why to read it |
|---|---|
| src/index.ts | Shows how scan formats, fix mode, evidence packs, baselines, gates, and watch mode connect at the CLI boundary |
| src/…/index.ts | Shows the public reporting surface for scores, defenses, and terminal, Markdown, JSON, HTML, and SARIF outputs |
| src/…/terminal.ts | Shows the human-facing terminal report and the fields it makes actionable |
| src/…/json.ts | Shows the structured report and Markdown summary used by automation and CI summaries |
| src/…/sarif.ts | Shows the code-scanning contract and policy result mapping |
| src/…/html.ts | Shows the self-contained executive review report |
| src/…/cta.ts | Shows how optional human-facing product text stays separate from machine output |
| src/…/defenses.ts and src/…/score.ts | Explain how protective controls are reported without becoming score deductions, and how risk signals shape the grade |
| src/…/index.ts | Defines the evidence bundle, integrity checks, inspection, and fleet routing model |
| src/…/index.ts | Defines stable remediation work items and the apply-review-verify workflow |
| src/…/index.ts and src/…/transforms.ts | Define which safe changes can be applied, how verification can roll them back, and how skipped work is reported |
| src/…/watcher.ts and src/…/diff.ts | Define the rescan cycle, baseline comparison, and regression signal |
| src/…/alerts.ts | Defines terminal and webhook alert behavior |
| src/action.ts | Shows how reports, SARIF, evidence packs, verification, and CI outputs are exposed in GitHub Actions |