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

+23 -9
View File
@@ -583,6 +583,7 @@ impl BooksServer {
+ Self::payouts_router()
+ Self::tax_router()
+ Self::write_offs_router()
+ Self::drafts_router()
}
/// The settings in force for this request: the books' own, taken from
@@ -1010,14 +1011,10 @@ impl BooksServer {
if entry.status() != ledger_core::EntryStatus::Posted || entry.reversal_of().is_some() {
return Ok(());
}
let split_group = self
.settings()
.policy
let split_group = ledger_core::evidence::Policy::from_settings(store.ledger().settings())
.split_group(store.ledger(), entry_id, entry);
if !self
.settings()
.policy
.receipt_required(store.ledger(), entry)
if !ledger_core::evidence::requirement(store.ledger(), entry, store.ledger().settings())
.is_required()
&& split_group.is_empty()
{
return Ok(());
@@ -1328,6 +1325,10 @@ thread_local! {
/// (set at its start from the settings in force: one version per
/// request), so every "today" in it agrees.
static TIMEZONE: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) };
/// The arguments the request running on this thread was called with,
/// as the caller sent them: what the preview digest (plan P4 step 4,
/// D-50) is taken over, so a changed argument is a changed preview.
static ARGS: std::cell::RefCell<Option<serde_json::Map<String, serde_json::Value>>> = const { std::cell::RefCell::new(None) };
}
/// Poll `fut` with "today" in the request's zone on this thread, each
@@ -1415,6 +1416,8 @@ mod attachments;
mod chart;
#[path = "tools/documents.rs"]
mod documents;
#[path = "tools/drafts.rs"]
mod drafts;
#[path = "tools/entries.rs"]
mod entries;
#[path = "tools/evidence.rs"]
@@ -1503,7 +1506,10 @@ impl BooksServer {
}
"books://reports/balance-sheet" => {
let Json(out) = self
.balance_sheet(Parameters(BalanceSheetParams { as_of: None }))
.balance_sheet(Parameters(BalanceSheetParams {
as_of: None,
strict: None,
}))
.await?;
json(&out)
}
@@ -1513,13 +1519,20 @@ impl BooksServer {
start: None,
end: None,
class: None,
strict: None,
}))
.await?;
json(&out)
}
"books://digest" => {
let since = digest_since(query, today());
let Json(out) = self.digest(Parameters(DigestParams { since })).await?;
let Json(out) = self
.digest(Parameters(DigestParams {
since: Some(since),
since_seq: None,
as_of: None,
}))
.await?;
json(&out)
}
handbook::URI => {
@@ -1694,6 +1707,7 @@ impl ServerHandler for BooksServer {
let result = run_blocking(&self.store, move || {
Box::pin(async move {
WROTE.with(|w| w.borrow_mut().take());
ARGS.with(|a| *a.borrow_mut() = request.arguments.clone());
let caller = running_call
.caller()
.map(|c| (c.token.id.clone(), c.token.name.clone()));