feat(drafts): the drafts tools, the preview digest on every confirm, the digest tool (P4)

Accounting reason: a confirm must act on the thing that was previewed.
Every tool with confirmed (post_entry, reverse_entry, run_schedules,
dispose_asset, reconcile, close_period, create_invoice, create_bill,
write_off_invoice, purge_tin, consolidate_duplicates, and the S6
settlement tools receive_payment and pay_bill, which gain confirmed and
preview on a clone of the ledger) returns preview (SHA-256 of the
canonical preview) and refuses a confirm whose preview is missing or
stale (stale_preview, before anything is written). A draft's digest is
its own state and the settings seq; an operation's is the tool, its
arguments as sent, the settings seq and the journal head seq, so another
session's write forces a re-preview (D-50).

New tools books.list_drafts, books.set_draft_state, books.discard_draft,
books.preview_entry; reports carry as_of_status (drafts open on or before
their end, unreconciled accounts, settings problems) and take strict; the
CPA package is refused while a draft dated in it is open unless
allow_open_drafts gives a reason, journaled as a decision;
books.digest takes since_seq (what was posted since a journal line,
backdated entries included: defect 6) and lists zero_net_accounts,
drafts_by_state and the reconciliation split. Needs attention gains
'draft awaiting receipt' beside 'draft not posted'; the drafts handbook
is rewritten. Every over-the-wire harness confirms the way an agent does.

Docs: mcp-interface, rules B-43, parity, testing (with the For-P12
paragraph), architecture, and the unit's As-built block.

Tests: drafts.rs (a_draft_waits_for_its_receipt_and_posts,
the_gate_moved_and_the_mcp_error_is_unchanged,
a_reversal_needs_no_receipt_of_its_own, discard_unblocks_the_close_over_the_wire,
report_warns_on_draft_before_as_of, cpa_package_refuses_open_draft,
stale_preview_refused, every_confirm_tool_takes_a_preview,
digest_since_seq_is_posting_time, legacy_reversed_replays_identically,
gui_and_server_gate_agree), attention_parity.rs, format_upgrade.rs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
swaitsandClaude Fable 5.1 committed 2026-10-29 13:55:38 -06:00
1 parent 7299cf90f2
commit 6a66a2855b
49 files changed
+2526 -202

No files matched your search

+43 -3
View File
@@ -296,6 +296,7 @@ fn payment_out(
_ => (None, None),
};
Ok(Json(PaymentOut {
preview: None,
entry_id,
documents,
deposited: money(deposited),
@@ -305,6 +306,20 @@ fn payment_out(
}))
}
/// A payment's preview: the figures the settled documents would show
/// (entry 0: nothing is posted), with the digest to confirm it by.
fn payment_preview(
probe: &Ledger,
settle: &ledger_core::SettleParams,
warnings: Vec<String>,
digest: String,
) -> Result<Json<PaymentOut>, String> {
let mut out = payment_out(probe, 0, settle)?.0;
out.warnings = warnings;
out.preview = Some(digest);
Ok(Json(out))
}
#[tool_router(router = settlements_router, vis = "pub(super)")]
impl BooksServer {
#[tool(
@@ -324,9 +339,25 @@ impl BooksServer {
let p = params.0;
let mut store = self.lock()?;
let (settle, warnings) = settlement(&store, &p, true)?;
let entry_id = store.settle(settle.clone()).map_err(|e| e.to_string())?;
let confirmed = p.confirmed.unwrap_or(false);
let digest = self.preview_of(
&store,
"books.receive_payment",
confirmed,
p.preview.as_deref(),
)?;
let entry_id = if confirmed {
store.settle(settle.clone()).map_err(|e| e.to_string())?
} else {
// The engine on a clone: every refusal the post would give,
// and the figures it would leave. Nothing is written.
let mut probe = store.ledger().clone();
probe.settle(settle.clone()).map_err(|e| e.to_string())?;
return payment_preview(&probe, &settle, warnings, digest);
};
let mut out = payment_out(store.ledger(), entry_id, &settle)?.0;
out.warnings = warnings;
out.preview = Some(digest);
Ok(Json(out))
}
@@ -346,9 +377,18 @@ impl BooksServer {
) -> Result<Json<PaymentOut>, String> {
let p = params.0;
let mut store = self.lock()?;
let (settle, _) = settlement(&store, &p, false)?;
let (settle, warnings) = settlement(&store, &p, false)?;
let confirmed = p.confirmed.unwrap_or(false);
let digest = self.preview_of(&store, "books.pay_bill", confirmed, p.preview.as_deref())?;
if !confirmed {
let mut probe = store.ledger().clone();
probe.settle(settle.clone()).map_err(|e| e.to_string())?;
return payment_preview(&probe, &settle, warnings, digest);
}
let entry_id = store.settle(settle.clone()).map_err(|e| e.to_string())?;
payment_out(store.ledger(), entry_id, &settle)
let mut out = payment_out(store.ledger(), entry_id, &settle)?.0;
out.preview = Some(digest);
Ok(Json(out))
}
#[tool(