Skip to main content

Diff-Based Analysis

Codeward focuses every policy and output on what a change introduces or alters— not historic backlog. A pull request (or feature branch) is compared to main and each record is classified so governance targets only net-new or modified risk.

See also: Glossary for term definitions and the Policy System for how actions are applied.

How It Works

  1. Scan baseline repository (mounted at /main).
  2. Scan change workspace (mounted at /branch) when CI_EVENT=pr; otherwise single-path (main) scan.
  3. Classify each record into one diff category (canonical order below).
  4. Apply policy actions per category (only keys you define matter).
  5. Render each output restricted to its changes filter.

Change Categories (Authoritative)

CategoryDefinitionTypical Action PatternGovernance Rationale
newPresent only in branchblock / warnNet-new risk entering codebase (highest leverage gate)
changedPresent in both but key attributes differ (e.g., version)warnPossible upgrade/downgrade or license/severity shift requiring review
removedPresent only in main (eliminated by branch)infoIndicates remediation / improvement; never block
existingPresent in both unchangedinfo / warnBacklog context; avoid blocking velocity until ready to escalate

(Glossary entries: new · changed · removed · existing)

(Always express keys in the canonical order: new, changed, removed, existing for tables, examples, and action maps when ordering is shown.)

Output Scoping with changes

Use the per-output "changes": [ ... ] array to minimize reviewer noise:

  • PR comment: ["new","changed"] (focus only on what to act on now).
  • Backlog / issue: ["existing"] (track inherited debt separately).
  • Progress reporting: ["removed"] (celebrate remediation).
  • Full audit artifact: all four categories.

Example Policy (Severity Gate)

{
"vulnerability": [
{
"name": "critical-and-high-vulns",
"actions": {"new": "block", "changed": "warn", "removed": "info", "existing": "warn"},
"rules": [
{"field": "Severity", "type": "eq", "value": "CRITICAL"},
{"field": "Severity", "type": "eq", "value": "HIGH"}
],
"outputs": [
{"format": "markdown", "template": "table", "destination": "git:pr", "fields": ["VulnerabilityID","PkgName","Severity","FixedVersion"], "changes": ["new","changed"], "collapse": true},
{"format": "json", "destination": "file:/results/vuln-changes.json", "changes": ["new","changed","removed" ]}
]
}
]
}

Best Practices

GoalPractice
Reduce PR noiseExclude existing from PR destinations
Encourage remediationSeparate removed section or output
Highlight risky deltasAlways include changed for packages / licenses where version or classification can shift risk
Deterministic automationEmit JSON with explicit changes filters; combine via Combining & Grouping
Safe rolloutStart blocking only on new critical risk, later expand

Common Misconfigurations

SymptomCauseFix
Everything marked newBaseline not mounted at /main or missing CI_EVENT=prMount both /main & /branch; set CI_EVENT=pr
No changed items appearActual record attributes identicalExpected; verify version or metadata truly changed
Existing overwhelms reviewPR output omitted changes filterAdd "changes": ["new","changed"] to PR outputs

Next: define rules & actions in the Policy System.