check / check (push) Canceled after 0s
The owner (2026-10-23): "We should probably just delete the stdio path altogether. THere's no point in that. And it sitting there unused will just lead to bitrot. Nuke it?" Books are served only by the books server (`wanderbooks server`), reached by agents through the bridge (`wanderbooks mcp --book ID`), which stays. Removed: `wanderbooks dev-stdio`, the `ledger-mcp` binary, and `ledger_mcp::run` (stdio and `--http` over a bare data dir), with all that only that mode had: - files the books make coming back inline: `HandedFile.content_base64` is gone, and `download` and `expires_at` are always there; - books with no access log or backups: `books.access_log`, `books.backup` and `books.back_up_now` are always offered, by scope; - the settings file read and reloaded (`legacy_files`), the vault key named by a file or `--vault-key-file`, and the books dir's key-inside-the-books and git checks (with `paths.rs`); - `wire.rs` (the bridge frames an agent's lines itself); - `books.settings`' file fields and `books.start`'s `settings_source`. `BooksServer` is built one way, from `Served` (a book as the books server serves it), in production and in the unit tests. An unknown tool is now a protocol error (mcp-tools.md). Inline file input is unchanged. Then the owner's three decisions (2026-10-23, the question tool): (a) `books.import_settings` is removed entirely (118 tools): old books come in whole by `wanderbooks books adopt`, which reads their settings file once; ledger-config keeps its settings-file parsing only as far as adoption uses it (`load` and the path-reading `effective_receipt_policy` are gone), and `books.chart_template` gives its settings as `books.set_setting` changes. (b) The viewer's loose-books-folder mode is removed (`--data-dir`, `--books-toml`, `--vault-key-file`, the settings file and config.json followed): it opens only books of the data root, reading settings from the journal and the vault from the book's own `vault/` and `keys/`. (c) `wanderbooks dev-stdio` has no stub: it is an unknown command like any other word. Also: an upload's expiry past the calendar is an error, never an empty string. Tests: every suite that drove the stdio server moved to crates/ledger-cli/tests/ and drives a real `wanderbooks server` on a data root of its own (tests/common), handed files by their download; mcp_stdio.rs is mcp_journeys.rs. Tests of what is gone are deleted and listed in docs/testing.md. Docs: plan D-44 (D-18 superseded), STATUS, testing, rules, mcp-interface, the handbook, README; justfile recipes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
159 lines
5.5 KiB
Rust
159 lines
5.5 KiB
Rust
//! The server's settings: the books' own (journaled, ledger_core::
|
|
//! settings), the defaults until the first is set.
|
|
//!
|
|
//! ```text
|
|
//! GOAL: every request sees the settings in force, one version for the
|
|
//! whole request, and they are only ever the books' own.
|
|
//! SOURCE: plan/served.md I-3 (the journal holds all books state; the
|
|
//! server never reads a settings file), 3.4 (a book in the data
|
|
//! root keeps its own settings), D-44 (one way to serve books: no
|
|
//! settings file is read by any of them).
|
|
//! INVARIANTS:
|
|
//! 1. The settings in force are the books' own: the defaults until
|
|
//! their journal holds any settings.set, then those; sync takes them
|
|
//! whenever the journal's last settings.set changes, and only then.
|
|
//! 2. No settings file is ever read.
|
|
//! ```
|
|
|
|
use crate::policy::ReceiptPolicy;
|
|
use ledger_config::Company;
|
|
use std::sync::Arc;
|
|
|
|
/// `[books]` account roles for the cash flow statement, used when a call
|
|
/// doesn't pass its own: cash, financing, and investing account codes.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct CashRoles {
|
|
/// `books.cash_accounts`.
|
|
pub cash: Vec<String>,
|
|
/// `books.financing_accounts`.
|
|
pub financing: Vec<String>,
|
|
/// `books.investing_accounts`.
|
|
pub investing: Vec<String>,
|
|
}
|
|
|
|
/// The settings in force, as the server uses them.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct Settings {
|
|
/// Which entries need a receipt.
|
|
pub policy: ReceiptPolicy,
|
|
/// The company (`company.*`).
|
|
pub company: Company,
|
|
/// The cash flow roles.
|
|
pub roles: CashRoles,
|
|
/// The prefix of generated asset tags (`books.asset_tag_prefix`, or
|
|
/// the company's initials).
|
|
pub asset_tag_prefix: String,
|
|
/// `policy.parties`: suggest, require, or never mention each entry's
|
|
/// counterparty.
|
|
pub parties: ledger_config::PartyPolicy,
|
|
/// The company's time zone (an IANA name), if set: what "today" means.
|
|
pub timezone: Option<String>,
|
|
}
|
|
|
|
impl Settings {
|
|
/// The settings the books keep (`ledger_core::settings`), as the
|
|
/// server uses them.
|
|
pub fn from_books(books: &ledger_core::settings::Settings, currency: &str) -> Self {
|
|
let b = ledger_config::codec::books_settings(books, currency);
|
|
Settings {
|
|
policy: ledger_config::codec::receipt_policy(books),
|
|
asset_tag_prefix: b.asset_tag_prefix(),
|
|
parties: b.parties,
|
|
timezone: b.timezone.clone(),
|
|
roles: CashRoles {
|
|
cash: b.cash_accounts,
|
|
financing: b.financing_accounts,
|
|
investing: b.investing_accounts,
|
|
},
|
|
company: b.company,
|
|
}
|
|
}
|
|
|
|
/// The prefix for generated asset tags ("FA" when none is set).
|
|
pub fn tag_prefix(&self) -> &str {
|
|
if self.asset_tag_prefix.is_empty() {
|
|
"FA"
|
|
} else {
|
|
&self.asset_tag_prefix
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The settings in force, and the books' settings.set they came from.
|
|
#[derive(Debug)]
|
|
pub struct Live {
|
|
current: Arc<Settings>,
|
|
/// The seq of the books' last settings.set taken (INVARIANT 1).
|
|
journal_seq: Option<u64>,
|
|
}
|
|
|
|
impl Live {
|
|
/// For a book (INVARIANT 1): the defaults; `sync` brings the books'
|
|
/// settings in once they hold any.
|
|
pub fn own() -> Self {
|
|
Self {
|
|
current: Arc::new(Settings::default()),
|
|
journal_seq: None,
|
|
}
|
|
}
|
|
|
|
/// Take the books' own settings when they hold any and they changed
|
|
/// since the last look (INVARIANT 1). The server calls this whenever
|
|
/// it holds the books.
|
|
pub fn sync(&mut self, books: &ledger_core::settings::Settings, currency: &str) {
|
|
if !books.is_journaled() || books.last_seq() == self.journal_seq {
|
|
return;
|
|
}
|
|
self.current = Arc::new(Settings::from_books(books, currency));
|
|
self.journal_seq = books.last_seq();
|
|
}
|
|
|
|
/// The settings in force.
|
|
pub fn current(&self) -> Arc<Settings> {
|
|
self.current.clone()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
/// INVARIANT 1: books that hold no settings keep the defaults; their
|
|
/// settings come in once per change, and an unchanged journal leaves
|
|
/// the settings in force as they are.
|
|
#[test]
|
|
fn books_take_their_own_settings_once_per_change() {
|
|
let mut live = Live::own();
|
|
assert_eq!(live.current().company.name, Company::default().name);
|
|
let mut books = ledger_core::settings::Settings::default();
|
|
let before = live.current();
|
|
live.sync(&books, "USD");
|
|
assert!(
|
|
Arc::ptr_eq(&before, &live.current()),
|
|
"books without settings"
|
|
);
|
|
let src = ledger_core::settings::Source {
|
|
decided_by: "Owner".into(),
|
|
decided_on: chrono::NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
|
|
citation: None,
|
|
note: None,
|
|
};
|
|
let change = |name: &str| ledger_core::settings::Change {
|
|
key: "company.name".into(),
|
|
value: Some(serde_json::json!(name)),
|
|
};
|
|
books.apply(&[change("Kept Co")], &src, 7).unwrap();
|
|
live.sync(&books, "USD");
|
|
assert_eq!(live.current().company.name, "Kept Co");
|
|
let taken = live.current();
|
|
live.sync(&books, "USD");
|
|
assert!(
|
|
Arc::ptr_eq(&taken, &live.current()),
|
|
"unchanged: not taken again"
|
|
);
|
|
books.apply(&[change("Kept Co 2")], &src, 9).unwrap();
|
|
live.sync(&books, "USD");
|
|
assert_eq!(live.current().company.name, "Kept Co 2");
|
|
}
|
|
}
|