Skip to content

feat(audit): rivet audit — AI-session/commit traceability gate (#127 P2)#297

Open
avrabe wants to merge 1 commit into
mainfrom
feat/127-rivet-audit
Open

feat(audit): rivet audit — AI-session/commit traceability gate (#127 P2)#297
avrabe wants to merge 1 commit into
mainfrom
feat/127-rivet-audit

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 17, 2026

Summary

Closes the AI-provenance loop opened by v0.10.0 (#127 Phase 1 shipped the `ai-session` schema only; this PR ships the gate that enforces it).

What ships

New top-level read-only subcommand `rivet audit` with two gates:

Gate 1 — every AI-authored commit needs an `ai-session` artifact whose `commit-sha` matches. AI-authored is detected via `Co-Authored-By: ...noreply@anthropic.com` or `Generated-With:`/`Created-By:` trailer matching `^(ai|ai-assisted)`.

Gate 2 — every `ai-session.commit-sha` must point at a commit that exists AND is reachable from HEAD. Catches drift after rebase/force-push and fabricated sessions pointing at vanished commits.

```
rivet audit [--since ] [--until ] [--format text|json] [--strict]
```

  • `--since` defaults to `git merge-base origin/main HEAD` (fallback HEAD~50).
  • `--strict` exits non-zero on violations (CI mode).
  • JSON envelope: `command`, `passed`, `since`, `until`, `ai_commits_scanned`, `ai_sessions_in_project`, `violations.*`, `summary.total_violations`.

Read-only, shells out to git (no new deps). Composes with `rivet check ai-defects-open` (PR #295) — together they cover the two operational TD1 loops the dossier §3 layer 5 names.

Out of scope (deferred)

Test plan

  • `cargo test -p rivet-cli --test cli_commands audit_` — 4 pass.
  • `cargo test --workspace --lib` — 994 pass.
  • `cargo build --workspace` — clean.
  • `cargo fmt -p rivet-cli --check` — clean.

Composes with

This PR can rebase cleanly onto either or both once they merge.

🤖 Generated with Claude Code

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 142172f Previous: 2932166 Ratio
store_insert/10000 15941393 ns/iter (± 1509982) 11958794 ns/iter (± 1062766) 1.33
validate/10000 16813458 ns/iter (± 2566668) 12511533 ns/iter (± 1331396) 1.34

This comment was automatically generated by workflow using github-action-benchmark.

Closes the loop opened by v0.10.0's ai-session schema (#127 Phase 1).
New top-level read-only subcommand `rivet audit` walks the current
branch's git history and enforces two gates:

**Gate 1 — AI-authored commit needs a session.**
For every commit detected as AI-authored (`Co-Authored-By:` containing
`noreply@anthropic.com`, OR `Generated-With:`/`Created-By:` trailer
matching `^(ai|ai-assisted)`), require an `ai-session` artifact in the
project with `fields.commit-sha` matching the commit SHA (prefix
match either direction, ≥7 chars).

**Gate 2 — session must point at a real reachable commit.**
For every `ai-session` artifact with `commit-sha` set, verify the
commit exists (`git cat-file -e`) AND is reachable from `--until`
(`git merge-base --is-ancestor`). Catches drift after rebase / force-
push as well as fabricated sessions pointing at vanished commits.

CLI: `rivet audit [--since <ref>] [--until <ref>] [--format text|json] [--strict]`
- `--since` defaults to `git merge-base origin/main HEAD`, falling
  back to `HEAD~50`.
- `--strict` exits non-zero on violations (CI mode).
- JSON envelope per spec: `command`, `passed`, `since`, `until`,
  `ai_commits_scanned`, `ai_sessions_in_project`,
  `violations.{ai_commits_without_session,sessions_with_missing_commit}`,
  `summary.total_violations`.

Read-only. Shells out to `git` (no new deps). Composes with
`rivet check ai-defects-open` (PR #295) — together they cover the
two operational TD1 loops the dossier §3 layer 5 names.

Tests (4 integration tests, all green):
- audit_passes_when_ai_commits_have_matching_sessions
- audit_fails_when_ai_commit_has_no_session
- audit_fails_when_session_points_at_missing_commit
- audit_json_envelope_shape_on_failure

Docs: new `audit` topic in `rivet-cli/src/docs.rs` (~105 lines).

OUT OF SCOPE (deferred):
- Auto-stamping sessions from `~/.claude/projects/*.jsonl` (Phase 2.5).
- session-hash verification (Phase 2.5).
- pre-commit / commit-msg hook installation (Phase 3).
- DPIA-link enforcement on `invoker`-bearing sessions.

Implements: REQ-002, REQ-007
Refs: FEAT-001, #127

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@avrabe avrabe force-pushed the feat/127-rivet-audit branch from 142172f to df2f6fb Compare May 17, 2026 06:35
@github-actions
Copy link
Copy Markdown

📐 Rivet artifact delta

No artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant