Context
PipelineState<Reconciled> carries confidence, issues: Vec<Issue>, and meta: MetaCtx { accumulated_confidence, stage_trace, flags }. After PRD-7 Phase 0, it also carries legal verification results in issues and constraint evaluations in meta.flags. None of this reaches the workbook — the _audit sheet in crates/ledger-core/src/workbook.rs is a placeholder.
This is the CPA-visible payoff. Without it, the accountant sees no evidence of the verification layer.
Audit Row Schema
One row per committed transaction. Columns:
| Column |
Source |
Type |
entry_id |
Blake3 of document_id + source_ref |
String |
constraint_score |
ConstraintEvaluation::to_confidence().0 |
f32 |
legal_result |
first legal_violation issue code or "ok" |
String |
disposition |
worst Disposition across all issues |
String |
accumulated_confidence |
meta.accumulated_confidence |
f32 |
stage_trace_json |
serde_json::to_string(&meta.stage_trace) |
String |
flags |
comma-joined MetaFlag display strings |
String |
invoice_arithmetic_ok |
InvoiceVerification::arithmetic_ok if present |
bool |
commit_gate |
CommitGate variant name |
String |
Implementation Notes
- Add
AuditRow struct to crates/ledger-core/src/workbook.rs mirroring the schema above.
workbook.rs already uses rust_xlsxwriter (0.94.0). The _audit sheet is written after the transactions sheet in the same Workbook write pass.
stage_trace_json column should be narrow (hidden by default via column width = 0 or a note in the write call) so it doesn't clutter the CPA view.
flags display: implement std::fmt::Display for MetaFlag in validation.rs.
commit_gate column: pass the gate into the row builder; derive the variant name via match (no strum needed since the column is write-only).
Acceptance Criteria
workbook.rs writes an _audit sheet with the nine columns above.
- For a committed transaction with one
Z3Result::Violated issue, legal_result column = "legal_violation".
- For a transaction with
CommitGate::Approved { confidence: 0.95 }, commit_gate = "Approved".
stage_trace_json is valid JSON parseable by serde_json.
- Existing
workbook tests still pass.
Files
crates/ledger-core/src/workbook.rs — primary change site
crates/ledger-core/src/validation.rs — add Display for MetaFlag
Dependencies
Logically follows #55 (TransactionFacts population) so legal_result column has real data. Can be implemented against test-fabricated states first.
Context
PipelineState<Reconciled>carriesconfidence,issues: Vec<Issue>, andmeta: MetaCtx { accumulated_confidence, stage_trace, flags }. After PRD-7 Phase 0, it also carries legal verification results inissuesand constraint evaluations inmeta.flags. None of this reaches the workbook — the_auditsheet incrates/ledger-core/src/workbook.rsis a placeholder.This is the CPA-visible payoff. Without it, the accountant sees no evidence of the verification layer.
Audit Row Schema
One row per committed transaction. Columns:
entry_iddocument_id + source_refStringconstraint_scoreConstraintEvaluation::to_confidence().0f32legal_resultlegal_violationissue code or"ok"StringdispositionDispositionacross all issuesStringaccumulated_confidencemeta.accumulated_confidencef32stage_trace_jsonserde_json::to_string(&meta.stage_trace)StringflagsMetaFlagdisplay stringsStringinvoice_arithmetic_okInvoiceVerification::arithmetic_okif presentboolcommit_gateCommitGatevariant nameStringImplementation Notes
AuditRowstruct tocrates/ledger-core/src/workbook.rsmirroring the schema above.workbook.rsalready usesrust_xlsxwriter(0.94.0). The_auditsheet is written after the transactions sheet in the sameWorkbookwrite pass.stage_trace_jsoncolumn should be narrow (hidden by default via column width = 0 or a note in the write call) so it doesn't clutter the CPA view.flagsdisplay: implementstd::fmt::DisplayforMetaFlaginvalidation.rs.commit_gatecolumn: pass the gate into the row builder; derive the variant name viamatch(nostrumneeded since the column is write-only).Acceptance Criteria
workbook.rswrites an_auditsheet with the nine columns above.Z3Result::Violatedissue,legal_resultcolumn ="legal_violation".CommitGate::Approved { confidence: 0.95 },commit_gate="Approved".stage_trace_jsonis valid JSON parseable byserde_json.workbooktests still pass.Files
crates/ledger-core/src/workbook.rs— primary change sitecrates/ledger-core/src/validation.rs— addDisplayforMetaFlagDependencies
Logically follows #55 (TransactionFacts population) so
legal_resultcolumn has real data. Can be implemented against test-fabricated states first.