Skip to content

Commit d2edbd0

Browse files
BunsDevCopilot
andauthored
feat(memory): add structured provenance metadata (#141)
fixes #106 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fbb7cad commit d2edbd0

11 files changed

Lines changed: 824 additions & 69 deletions

File tree

docs/configuration.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ Auto-extracted memories are approval-gated in hosted review mode. By default,
161161
hosted sessions write reviewable JSON candidates under
162162
`.coven-code/memory-candidates/` instead of appending directly to durable
163163
`.coven-code/AGENTS.md` memory. Each candidate records content, category,
164-
confidence, provenance, source trust, proposed scope, proposed visibility,
165-
status, and any rejection reason.
164+
confidence, structured provenance, source trust, proposed scope, proposed
165+
visibility, status, and any rejection reason. Auto-extracted provenance records
166+
the session id, source kind, creator, and best-effort repository and commit
167+
references; it does not store secret values.
166168

167169
Trusted deployments can opt into direct durable writes only when the source
168170
trust meets the configured threshold:
@@ -373,8 +375,9 @@ Frontmatter fields:
373375
| `scope` | Intended scope, such as `user`, `tenant`, `installation`, `repo`, `branch`, or `pr`. |
374376
| `trust` | Source trust. Hosted review enforces this against `hostedReview.memoryTrustThreshold`. Supported values include `system_policy`, `maintainer_approved`, `default_branch_code`, `model_inferred`, `contributor_input`, `fork_input`, and `unknown`. |
375377
| `visibility` | Intended review visibility: `public_review`, `private_review`, or `security_private`. Hosted public reviews exclude `security_private` memory by default. |
376-
| `source` | Provenance source kind, for example `manual`, `github_pr`, `github_pr_review`, or `session_memory_extraction`. |
378+
| `source` | Provenance source kind, for example `manual`, `github_pr`, `github_pr_review`, or `session-memory-extraction`. |
377379
| `source_ref` | Source reference such as `owner/repo#123`, a commit SHA, or another non-secret audit handle. |
380+
| `source_repo`, `source_commit`, `source_actor` | Optional structured provenance for repository slug, commit SHA, and source actor. Store references only, not secret values. |
378381
| `expires_at` | Optional expiry date in `YYYY-MM-DD` format. Expired hosted memory is ignored. |
379382
| `retention_class` | Optional lifecycle class such as `standard`, `short_lived`, `security`, or `legal_hold`. |
380383
| `redacted_at` | Marks content as redacted. Hosted review keeps the metadata visible but replaces the body with a redaction stub. |

docs/headless-contract.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coven-code Headless Execution Contract
22

3-
**Contract version: `2`** - Status: **Locked** (V2 / structured review output)
3+
**Contract version: `3`** - Status: **Locked** (V3 / memory provenance in review artifacts)
44

55
This document is the single source of truth for the interface between
66
`coven-github` (the GitHub ingress adapter) and `coven-code` (the execution
@@ -64,7 +64,7 @@ The adapter is the **producer**; the runtime is the **consumer**. The brief is
6464

6565
```json
6666
{
67-
"contract_version": "2",
67+
"contract_version": "3",
6868
"trigger": "issue_assigned",
6969
"repo": {
7070
"owner": "OpenCoven",
@@ -96,7 +96,7 @@ The adapter is the **producer**; the runtime is the **consumer**. The brief is
9696

9797
| Field | Type | Notes |
9898
|---|---|---|
99-
| `contract_version` | string | MUST be `"2"`. Consumers MUST reject a brief whose major version they do not implement. |
99+
| `contract_version` | string | MUST be `"3"`. Consumers MUST reject a brief whose major version they do not implement. |
100100
| `trigger` | string enum | `issue_assigned` \| `pr_review_comment` \| `issue_mention`. |
101101
| `repo.owner` | string | |
102102
| `repo.name` | string | |
@@ -132,7 +132,7 @@ the file MAY be absent.
132132

133133
```json
134134
{
135-
"contract_version": "2",
135+
"contract_version": "3",
136136
"status": "success",
137137
"branch": "cody/fix-issue-42",
138138
"commits": [
@@ -157,7 +157,18 @@ the file MAY be absent.
157157
"id": "mem_review_policy",
158158
"trust": "maintainer-approved",
159159
"visibility": "public_review",
160-
"scope": "managed"
160+
"scope": "managed",
161+
"source": "session-memory-extraction",
162+
"source_ref": null,
163+
"source_repo": "OpenCoven/coven-code",
164+
"source_commit": "0123456789abcdef0123456789abcdef01234567",
165+
"source_actor": "BunsDev",
166+
"session_id": "sess-artifact",
167+
"transcript_ref": "sha256:abc123",
168+
"created_by": "coven-code",
169+
"provenance": [
170+
"session:sess-artifact;source:session-memory-extraction;repo:OpenCoven/coven-code;commit:0123456"
171+
]
161172
}
162173
]
163174
}
@@ -170,7 +181,7 @@ the file MAY be absent.
170181

171182
| Field | Type | Notes |
172183
|---|---|---|
173-
| `contract_version` | string | MUST be `"2"`. Producers MUST emit it. |
184+
| `contract_version` | string | MUST be `"3"`. Producers MUST emit it. |
174185
| `status` | string enum | `success` \| `failure` \| `partial` \| `needs_input`. See [3.3](#33-status). |
175186
| `branch` | string \| null | Branch the runtime pushed. `null` when no branch was created. The adapter only opens a PR when `branch` is set **and** `commits` is non-empty. |
176187
| `commits` | array | `{ "sha": string, "message": string }`. MAY be empty. |
@@ -181,9 +192,9 @@ the file MAY be absent.
181192
| `exit_reason` | string enum \| null | `null` on success; otherwise the terminal cause. See [3.4](#34-exit_reason). |
182193

183194
> **Drift note (supersedes `COVEN-GITHUB.md`):** the prose result envelope listed
184-
> an `events` array. Progress/event streaming is **not** part of the v2 result
195+
> an `events` array. Progress/event streaming is **not** part of the v3 result
185196
> envelope — it is deferred to M2 and will travel over a separate channel. The
186-
> v2 envelope carries terminal task state only. Producers MUST NOT rely on
197+
> v3 envelope carries terminal task state only. Producers MUST NOT rely on
187198
> `events` being read.
188199
189200
### 3.2 `review`
@@ -202,7 +213,7 @@ the intended code. It is required on every result. Non-review tasks MUST set
202213
| `tests_run` | array | Commands run while reviewing, with `passed`, `failed`, `not_run`, or `unknown` status. |
203214
| `no_findings_reason` | string \| null | File-backed explanation for a clean review. MAY be `null` for degraded/partial output when `evidence_status` and `limitations` explain why a substantive clean-review conclusion was not possible. |
204215
| `limitations` | string[] | Evidence gaps, skipped checks, or other caveats. |
205-
| `memory` | object | Memory audit report: `domains_loaded` (hosted memory domains eligible for this review, e.g. `default-branch`; empty for local runs) and `entries` (every loaded memory entry with its stable `id`, effective `trust` label after hosted caps/floors, optional `visibility`, and load `scope`). Lets the consumer audit which memory inputs could have influenced findings and cross-check `memory_refs` citations. |
216+
| `memory` | object | Memory audit report: `domains_loaded` (hosted memory domains eligible for this review, e.g. `default-branch`; empty for local runs) and `entries` (every loaded memory entry with its stable `id`, effective `trust` label after hosted caps/floors, optional `visibility`, load `scope`, structured file-level provenance fields such as `source`, `source_ref`, `source_repo`, `source_commit`, `session_id`, and `created_by`, plus compact per-entry `provenance` strings found in durable memory content). Lets the consumer audit which memory inputs could have influenced findings and cross-check `memory_refs` citations. |
206217

207218
Each finding carries `severity`, `file`, optional `line`, `title`, `body`, and
208219
optional `recommendation`. Valid severities are `info`, `low`, `medium`, `high`,
@@ -259,7 +270,7 @@ A process **killed by signal**, or one that **times out** (the adapter enforces
259270

260271
## 5. Security invariants
261272

262-
These are non-negotiable for v2:
273+
These are non-negotiable for v3:
263274

264275
1. The session brief is **tokenless**. Serializing a brief MUST NOT produce an
265276
`auth` field, a `"token"` field, or a credential-bearing `clone_url`
@@ -284,11 +295,16 @@ The contract is versioned by the single `contract_version` string, which tracks
284295
the version.
285296
- A change that adds a **required** field, removes a field, renames a field,
286297
changes a type, or changes exit-code/status semantics is **breaking** and MUST
287-
bump `contract_version` to `"2"`, update both schemas and fixtures, and ship a
288-
migration note here.
298+
bump `contract_version` to the next major version, update both schemas and
299+
fixtures, and ship a migration note here.
289300
- Consumers MUST reject a payload whose major version they do not implement,
290301
rather than silently mis-parsing it.
291302

303+
Migration note for v3: `review.memory.entries[]` now includes structured
304+
file-level provenance fields and compact per-entry provenance strings alongside
305+
memory ids and effective trust labels. Consumers that validate result envelopes
306+
must accept the new required nullable provenance fields and `provenance` arrays.
307+
292308
---
293309

294310
## 7. Conformance artifacts

0 commit comments

Comments
 (0)