Policy, approval and retention commands

Part of the NovaFabric CLI reference. Both nova and novafabric run the same binary.

Policy and governance (v0.8)

When opa is not installed. OPA is optional in local mode. With no opa on PATH and no NOVAFABRIC_POLICY_BUNDLE_PATH, the built-in policy gates (promote, evidence_export, replay_mutating) are disabled with a warning and allow — except the gates that require an explicit allow (promote direct into production, protected labels). Two cases now fail closed instead, because a policy was asked for:

nova policy test

Run the Rego unit test suite on the built-in policy bundle (requires opa installed).

nova policy test
nova policy test --bundle /path/to/custom-bundle

Options:

Returns exit code 0 if all tests pass, 1 if any test fails or opa is not found.

opa runs sandboxed, as everywhere in NovaFabric: it inherits no environment variable except a fixed PATH, and the Rego cannot call opa.runtime, http.send or net.lookup_ip_addr (they are removed from the capabilities opa runs with, and network access is denied). A test that relies on one of them fails to compile. An opa too old to report its capabilities (opa capabilities --current) is refused with exit code 1.

The built-in bundle ships reference gates including promote_gate.rego, regression_gate.rego (v0.9), and budget_gate.rego — the cost/energy budget gate (ADR-0136, experimental).

Budget gate (budget_gate.rego, experimental). Denies promotion when the capsule's already-recorded cost/energy/token rollup exceeds declared ceilings — a promotion gate over sealed evidence, never a live spend alert. The rollup is assembled with novafabric.policy.budget_block_from_capsule(capsule_dir) (reads nova.cost from model-calls.jsonl, measured_joules from energy-receipts.jsonl, and gen_ai.usage.* token counts) and passed as input.resource.budget; ceilings go in input.context.budget_ceilings (total_cost / cost_per_run / energy_kwh / tokens). Missing evidence is never treated as zero: absent ceilings or absent data pass with an explicit "no data" reason (skip_unmeasured, the default), while input.context.missing_evidence: "require_measured" fail-closes on a declared ceiling with no recorded evidence. Spec: design/spec/budget-gate-v0.md (private). The nova policy budget set|list|show authoring commands and the budget-gate verdict record are future design (ADR-0136 P2/P3) — not yet implemented.

Environment-conditioned gates (experimental, ADR-0126 P3). The evidence-export gate's input carries the capsule's recorded deployment environment as input.resource.deployment_environment (the value of nova capture --environment / NOVAFABRIC_ENVIRONMENT, verbatim; null when none was recorded — never inferred), so a custom policy can apply production-only requirements:

allow if {
    input.resource.deployment_environment == "production"
    input.resource.redaction_proof_present == true
    input.resource.unsafe_skips == 0
}

Asset-scoped gates (promotion, protected labels) carry null. The mutating-replay gate does not yet populate the field (planned); no built-in gate conditions on it.


nova policy explain <decision-id>

Replay a past policy decision from the audit log, showing the event type, actor, resource, and details.

nova policy explain 3f8a1b2c-...

The dashboard Policy Explain panel auto-completes decision IDs via GET /api/policy/recent-decisions?limit=50 (serve REST API), which returns up to 50 recent IDs from ~/.novafabric/dashboard-audit.jsonl in most-recent-first order.


nova policy list

List Rego policy files in the built-in bundle and any signed promotion policies stored in the PolicyStore.

nova policy list
nova policy list --namespace staging
nova policy list --bundle /path/to/custom-bundle
nova policy list --db ~/.local/share/novafabric/merkle.db   # a store signed before the default changed

Options:

Output has two sections:

  1. Rego Bundle — table of .rego files with file name (relative to bundle root) and size.
  2. Signed Promotion Policies — table of stored policy versions with version number, namespace, and creation timestamp. If no DB exists yet, a note is printed and the command exits cleanly.

nova approve <name@version>

Approve an asset that is in the pending_approval lifecycle state, recording the approver and note in the audit log.

nova approve my-model@v2
nova approve my-model@v2 --approver alice --note "Reviewed eval results"

Options:

Exits with code 1 if the asset is not found or not in pending_approval state.


nova hold create <registry>

Place a legal hold on a registry, suspending all capsule deletion (ADR-0031).

nova hold create my-registry --reason "SEC examination 2026-Q2"
nova hold create my-registry --reason "SEC examination 2026-Q2" --duration-days 365

Options:

Holds are stored in one store shared with the /api/holds routes: $NOVAFABRIC_HOME/registries/<registry>/holds.jsonl (append-only; release stamps released_at). A hold placed here therefore blocks nova retention, nova capsule delete, nova export-retention and the server/dashboard delete routes alike, and one placed through the dashboard or API blocks this CLI. Holds written before this store existed — at ./.novafabric/registries/<registry>/holds.jsonl under the working directory, or by nova serve beside its capsule base (<capsule-dir>/../registries/) — are still read by every deletion gate and can still be listed and released; nothing is moved. The registry name must be a single path component (no /, \ or ..; exit 1 otherwise).


nova hold list <registry>

List active (unreleased) legal holds on a registry, from every hold location (CLI- and API-placed). An unreadable ledger line is listed as an active __corrupt__:<registry> hold.

nova hold list my-registry

nova hold release <hold-id>

Release a legal hold by ID, wherever it is stored (including holds placed through the API). Records the release in the audit log.

nova hold release hold-a1b2c3d4

Exits with code 1 if the hold ID is not found or already released.


nova capsule delete <capsule-id>

Delete a capsule: removes the capsule directory and its runs-cache index rows through the same governed core as DELETE /v0/capsules/{run_id} and the dashboard delete route (ADR-0206), and reports success only once the capsule is actually gone.

nova capsule delete cap-01JXXXXX --registry my-registry
nova capsule delete cap-01JXXXXX --registry my-registry --age-days 1826
nova capsule delete cap-01JXXXXX --registry my-registry --force

Options:

Deletion is refused (exit 1, nothing reported or audited as deleted) when:

Retention policies are read from $NOVAFABRIC_HOME/registries/<registry>/retention-policy.yaml, the legacy ./.novafabric/registries/<registry>/retention-policy.yaml and the capsule store's ../registries/<registry>/retention-policy.yaml; every file found applies. A policy entry that cannot be read — malformed YAML, permission denied, a dangling symbolic link or a directory — refuses with retention_policy_unavailable (fail closed). A refusal by a hold, WORM lock, unreadable WORM state or seal is recorded as a run.index_delete_refused audit event. After the capsule is gone, a capsule.delete entry is appended to the hash-chained audit log.

WORM state (fail closed). The delete checks every worm.db of every registry in the same three locations ($NOVAFABRIC_HOME/registries/*/, ./.novafabric/registries/*/ and the capsule store's ../registries/*/), the same files nova retention reads. What happens:

On disk Result
No worm.db in any location No local WORM is configured; WORM does not block the delete
A readable worm.db with an unexpired lock for the capsule Refused, worm_hold
A worm.db entry that cannot be read: not SQLite, empty, no worm_capsules table, a locked_until that does not parse, a directory, a dangling symbolic link, permission denied, or locked by another writer for 2 s Refused, worm_state_unavailable; nothing is deleted. There is no override (--force included)

A damaged worm.db therefore blocks every delete until it is repaired or restored; see Backup & Restore — unreadable WORM or retention-policy files. The check reads worm.db read-only and never repairs it. The local WORM adapter is dev/test-only (ADR-0031): this guards against a damaged or misplaced file, not against an administrator who edits it. Before this change an unreadable worm.db was skipped with a warning, and a truncated one was silently recreated empty, so the delete went ahead.

Before this release the command printed "Deleted capsule", exited 0 and audited capsule.delete without removing anything, and --force also skipped the hold check.


Retention scheduler (ADR-0134)

Experimental. Applies the ADR-0031 retention windows over time: a WORM-aware, crypto-shred-integrated, audited sweep. Bindings live in a new optional bindings: block inside the existing $NOVAFABRIC_HOME/registries/<registry>/retention-policy.yaml (schema: schemas/retention-binding.schema.json); a registry with no bindings is swept for nothing. NovaFabric embeds no daemon — run the sweep manually or wire nova retention apply --yes into cron/systemd.

Where the per-registry files are read (works today). retention-policy.yaml and worm.db are resolved like the legal-hold store, independent of the working directory:

Releases before 2026-10-23 read both files relative to the working directory only, so a cron or container sweep started elsewhere found no bindings and no WORM database.

# retention-policy.yaml (ADR-0031 fields unchanged; bindings are additive)
include_capture_capsules: true   # optional, default false — see "Which capsules are swept"
bindings:
  - id: mifid-trade-5y
    match: {tag: trade-record, deployment_environment: production}
    window: P1825D          # ISO-8601 duration from capsule created_at, or YYYY-MM-DD
    action: purge           # expire-metadata | purge | crypto-shred
  - id: gdpr-subject-pii
    match: {age: P180D}
    window: P180D
    action: crypto-shred    # experimental — see below

Which capsules are swept. The sweep enumerates both manifest formats under the capsule directory: <run>/capsule.json (the legacy CapsuleWriter format) and <run>/capsule.yaml (what nova capture and the framework adapters write; a directory holding both is treated as capsule.json). plan, apply --dry-run, status and explain always show the capsule.yaml ("capture") capsules and what would happen to them. apply acts on capture capsules only when the policy sets include_capture_capsules: true (optional, default false). Earlier versions never enumerated capsule.yaml, so this opt-in keeps an existing cron sweep from suddenly deleting capsules it never touched before. Without it, plan and apply print how many capture capsules are excluded and how to include them, and --json output carries a capture_capsules block (included, enumerated, excluded — previewed as they would be swept — and notice). Excluded capsules are not swept, so they leave no audit entry. Holds, WORM locks and the apply-time re-check apply to capture capsules exactly as to capsule.json capsules. Any other value than true/false is refused (exit 1).

crypto-shred (experimental). It destroys the data subject's DEK (ADR-0069). The subject comes from metadata.pii_subject_id when a manifest names it, otherwise from the capsule's redaction_manifest.json: nova capture --pii-subject <id> records the subject's HMAC there (never the raw id) for every span it encrypted, and apply resolves that HMAC to a live DEK in $NOVAFABRIC_HOME/dek.db with NOVA_PII_PEPPER. So for capsules captured with --pii-subject the action is a real crypto-shred (verified end to end by tests/retention/test_crypto_shred_current_limits.py): the key is destroyed, an ErasureReceipt is written to $NOVAFABRIC_HOME/evidence/erasure/<run>.receipt.json, and readers show [erased]. Know before you enable it:

Matching reads capsule manifests under the capsule directory: metadata.tags (comma-separated), deployment_environment (metadata.deployment_environment in capsule.json; the top-level field nova capture writes in capsule.yaml), and alias (matched by the asset predicate, glob allowed). nova capture writes no tags, so bind capture capsules by age, deployment_environment or asset.

Safety invariants (fixed, not configurable): a WORM/legal hold always wins — a WORM-retained capsule is never purged or shredded before its locked_until (recorded skipped: worm_hold), and an active legal hold on the registry — placed with nova hold or through POST /api/holds, read from the shared hold store — holds every item (legal_hold_active); purge is refused under deletion_mode: prohibited; a crypto-shred inside the Art.17(3)(b) window is deferred. Every decision — including every skip — appends one hash-chained retention.action audit entry (schemas/retention-action-record.schema.json): deletion is itself evidence.

nova retention plan

Dry-run (the default posture): list what WOULD be affected. Touches nothing, writes no audit records, and uses the identical due-computation code path as apply. Capture capsules (capsule.yaml) that apply will not act on are listed in a separate table (and under capture_capsules.excluded with --json).

nova retention plan --registry my-registry
nova retention plan --registry my-registry --json

nova retention apply

Apply due retention actions. Confirm-gated: prompts unless --yes (or --dry-run). Idempotent and fail-safe — re-runs are no-ops; a per-item failure is recorded error and the sweep continues. Acts on capture capsules (capsule.yaml) only with include_capture_capsules: true in the policy; otherwise it prints how many it excluded.

Holds are re-read immediately before every action, not only while planning: a legal hold or WORM lock placed while the confirmation prompt waits, or during the sweep, still wins (recorded skipped with legal_hold_active: <ids> or worm_hold). The re-check also finds worm.db files again, so one that was emptied, replaced or became unreadable after planning skips the item as worm_state_unavailable: <path>: <reason>. If the re-check itself fails in any other way, the item is skipped (hold_check_failed). A crypto-shred that the DEK store refuses under a hold is recorded skipped (legal_hold_active), never applied, so a later nova restore does not replay it.

nova retention apply --registry my-registry --dry-run          # preview
nova retention apply --registry my-registry --yes              # cron/CI
nova retention apply -r my-registry --action crypto-shred --limit 100 --yes

Options:

nova retention status

Read-only: per binding, how many items are due now, how many are held (WORM/legal), and the next due date — counting only what apply acts on. Without include_capture_capsules: true, an excluded column (excluded_capture_capsules in --json, plus top-level include_capture_capsules and capture_capsules_enumerated) counts the capture capsules each binding matches that apply will not touch.

nova retention status --registry my-registry --json

nova retention explain <capsule-id>

Read-only: which bindings match this capsule, its computed due date, and its current hold state. --json adds manifest (capsule.json or capsule.yaml) and swept_by_apply (false for a capture capsule without the opt-in).

nova retention explain cap-01JXXXXX --registry my-registry