Merge branch 't3/refuse-tax-ids-in-free-text': free text refuses a tax id's shapes; references take nine digits; bank files mask (WB-partner-15)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
e7d5e4b8cd
36 files changed
+4353
-113
No files matched your search
@@ -8,7 +8,7 @@ The receipt rule in force: {evidence_rule}
|
||||
|
||||
- books.audit { through, scope } without confirmed lists the checks and changes nothing; show it to the human. Then call it again with confirmed: true and the preview. It files the workpaper (JSON and PDF, category workpaper) and journals the run. books.workpaper { id } gives it back: the JSON, and the PDF handed over (run its download command to save it).
|
||||
- scope: month (a month-end), annual (a fiscal year), cpa_handoff (the year, for the CPA package), full (everything from the start of the books).
|
||||
- It checks the trial balance, the accounting equation, the profit and loss against equity, the cash flow's footing, the A/R and A/P control accounts, closes, schedules and depreciation, the asset register, every posted entry against the receipt rule, open drafts, tax categories, 1099 decisions and the settings; then the journal's chain, the stored files, the access log and the backups. A finding is a failure (the books are wrong or cannot be shown right), a warning (unfinished or a rule not met) or a note (listed so the workpaper is whole: a reversal rests on its original's receipt).
|
||||
- It checks the trial balance, the accounting equation, the profit and loss against equity, the cash flow's footing, the A/R and A/P control accounts, closes, schedules and depreciation, the asset register, every posted entry against the receipt rule, open drafts, tax categories, 1099 decisions and the settings; then the journal's chain, the stored files, the access log, a journal line whose text field looks like a tax id (a warning naming the line and the field, never the number; the journal is never rewritten, so correct it with a reversal and keep the tax id in the vault) and the backups. A finding is a failure (the books are wrong or cannot be shown right), a warning (unfinished or a rule not met) or a note (listed so the workpaper is whole: a reversal rests on its original's receipt).
|
||||
- Fix findings with journaled corrections (a reversal, a receipt attached, a decision recorded), never by editing: posted entries stay as they are. Then audit again.
|
||||
- The same books, day and scope give the run that exists: asking again files nothing. The books are "the same" while no entry, document, close, settings or role change has been made; filing a receipt, an audit or an attestation does not change them.
|
||||
- Books that have not declared audits refuse a confirmed audit and every attestation with format_upgrade_pending until the owner's upgrade (books.start says so). Nothing else about them changes.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
## Importing a bank CSV (books.import_bank_csv)
|
||||
|
||||
A QuickBooks-style bank or credit-card CSV: 3 columns Date, Description, Amount (payments negative), or 4 columns Date, Description, money out, money in (Intuit heads them Credit, Debit). Slash dates must settle month-first or day-first from the file itself or from date_order ("month_first" for mm/dd, "day_first" for dd/mm); ask the human when the tool says the dates read either way. It creates one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other (the longest matching rule pattern, else default_offset_code). Give the CSV as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Review with books.digest, then post. File the export too (books.file_document category import_source) and pass source_attachment_id: it is linked to the bank account, so the import traces to its source (never to the drafts: a bank export is not a receipt).
|
||||
A QuickBooks-style bank or credit-card CSV: 3 columns Date, Description, Amount (payments negative), or 4 columns Date, Description, money out, money in (Intuit heads them Credit, Debit). Slash dates must settle month-first or day-first from the file itself or from date_order ("month_first" for mm/dd, "day_first" for dd/mm); ask the human when the tool says the dates read either way. It creates one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other (the longest matching rule pattern, else default_offset_code). Give the CSV as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Review with books.digest, then post. File the export too (books.file_document category import_source) and pass source_attachment_id: it is linked to the bank account, so the import traces to its source (never to the drafts: a bank export is not a receipt). A bank's description often carries a nine-digit reference, so the file is not refused for one: a number in it that reads as a tax id is kept masked to its last four digits, and the answer says how many values were masked and on which lines (masked_count, masked, masked_note); tell the human, who can check the bank's own statement. A chart CSV (books.import_chart_csv) is refused whole if a cell looks like a tax id; the refusal names its row and column.
|
||||
|
||||
## Exporting a report (books.export)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
- Every post_entry preview says where the entry stands (party_policy, party_missing, party_suggestions): under the `[books] parties` setting "suggest" (the default), when party_missing, name the likely party to the human and tag it (or add it) before confirming; under "require", posting is refused (party_required) until the entry names a party or is marked as having none (books.set_entry_party with party null and no_party_reason, or draft_entry no_party_reason: only for an entry with truly no counterparty, like a transfer between the company's own accounts); under "off", don't raise it.
|
||||
- Record W-9 facts (books.set_w9) for contractors and landlords before paying them, and W-4 facts (books.set_w4) for employees before their first payroll; name the employee party on every books.run_payroll line.
|
||||
- Never put a full TIN or SSN anywhere in the books, only the last four digits: the engine refuses any nine-digit number in a party field. The full TIN goes only to the encrypted TIN vault, and every member's and every 1099 payee's belongs there: books.set_tin (party, tin, tin_type: ssn, ein, itin; any role, so each member's SSN for their K-1) and books.set_w9 with tin and tin_type for a payee's W-9, and the signed form with w9_upload_id (books.begin_upload purpose w9; never books.file_document or books.attach_receipt: the form shows the TIN).
|
||||
- A full TIN lives in the vault: keep it out of descriptions, notes, file names and version-history messages. books.get_w9 hands the signed form over (run its download command to save it for the human); books.purge_tin (preview, then confirmed, with a reason) deletes a TIN no longer needed.
|
||||
- A full TIN lives in the vault: keep it out of descriptions, notes, file names and version-history messages. Every tool refuses a string that looks like a tax id (nine digits standing alone, or an SSN's 3-2-4 or an EIN's 2-7 grouping), whichever field it is in, before anything is written, and says which field; a party's own fields refuse any run of nine digits. A field that is an identifier by nature (an asset's tag or serial number, a vendor's or customer's reference, a payment's reference, an account code, a file name, an instrument's label, where a W-9 is kept) takes nine digits as a number and refuses only the grouped forms. An invoice number, a phone number, a coordinate or a reference of ten digits or more is no tax id. If a bank or vendor reference is nine digits and goes into a memo or a description, write its last four. books.get_w9 hands the signed form over (run its download command to save it for the human); books.purge_tin (preview, then confirmed, with a reason) deletes a TIN no longer needed.
|
||||
- books.parties lists the directory (each party's TIN last four from its TIN or W-9 facts), books.party shows one party with the year's totals, and books.show party opens it in the viewer. Archive (books.update_party archived) parties no longer dealt with; never delete history.
|
||||
|
||||
## Tagging an entry with several parties (books.set_entry_party)
|
||||
|
||||
@@ -133,6 +133,9 @@ pub(crate) const STOPPED: &str = "stopped";
|
||||
pub(crate) const STOPPED_BY_CLOSE: &str = "stopped_by_close";
|
||||
/// A file's bytes or text came as an argument (D-46).
|
||||
pub(crate) const INLINE_FILE: &str = "inline_file";
|
||||
/// A call refused unrun because a string in it looks like a tax id
|
||||
/// (text_fields.rs).
|
||||
pub(crate) const TIN_IN_TEXT: &str = "tin_in_text";
|
||||
|
||||
/// What a refused call is told when its record couldn't be kept, or a
|
||||
/// call that ran is told instead of its answer (INVARIANT 3).
|
||||
|
||||
@@ -1588,6 +1588,8 @@ mod next_steps;
|
||||
mod projects;
|
||||
#[path = "tools/prompts.rs"]
|
||||
mod prompts;
|
||||
#[path = "text_fields.rs"]
|
||||
mod text_fields;
|
||||
pub use kept::SettingKeyOut;
|
||||
|
||||
// The tool groups: one file each (plan/served.md 8.2 U0a). A unit adds a
|
||||
@@ -1934,6 +1936,15 @@ impl ServerHandler for BooksServer {
|
||||
}
|
||||
calls::key_problem(request_key.as_ref())
|
||||
.map(|why| (calls::MISSING_KEY, Ok(tool_error(why))))
|
||||
})
|
||||
// A string that looks like a tax id isn't run, whatever it was for:
|
||||
// the vault is where one goes (text_fields.rs INVARIANT 5).
|
||||
.or_else(|| {
|
||||
if !calls::writes(&request.name) {
|
||||
return None;
|
||||
}
|
||||
text_fields::refusal(&request.name, request.arguments.as_ref())
|
||||
.map(|why| (access::TIN_IN_TEXT, Ok(tool_error(why))))
|
||||
});
|
||||
if let Some((code, answer)) = refusal {
|
||||
call.digested(refused_digest(request.arguments.clone()).await);
|
||||
|
||||
@@ -1702,3 +1702,59 @@ fn the_envelope_keeps_what_a_tool_said_and_carries_a_refusal_guard() {
|
||||
assert_eq!(g["code"], "approval_required");
|
||||
assert_eq!(g["remedy_tool"], "books.approve_entry");
|
||||
}
|
||||
|
||||
/// text_fields.rs INVARIANT 5 (WB-format-10): a call with a string that
|
||||
/// looks like a tax id is refused before it runs, in words that name the
|
||||
/// field and never repeat the number; the books are as they were and the
|
||||
/// access record says why. A reference that is no tax id goes on to the tool.
|
||||
#[test]
|
||||
fn a_call_with_a_tax_id_in_free_text_is_refused_unrun_and_writes_nothing() {
|
||||
rt().block_on(async {
|
||||
let s = session("tin-text").await;
|
||||
let (server, books) = logged("tin-text");
|
||||
let key = "key-0123456789";
|
||||
let add = |name: &str| {
|
||||
tool_call(
|
||||
"books.add_class",
|
||||
serde_json::json!({"name": name, "request_key": key}),
|
||||
)
|
||||
};
|
||||
let (refusal, text) = answer(
|
||||
server
|
||||
.call_tool(add("Rondo 000-00-0000"), context(&s.peer, Some(ALL)))
|
||||
.await,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(refusal, "{text}");
|
||||
assert!(
|
||||
text.starts_with("the name of books.add_class looks like it holds a tax id"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("books.set_tin") && text.contains("W-9"), "{text}");
|
||||
assert!(!text.contains("000"), "never the number: {text}");
|
||||
// A preview is refused too: its text would be shown to a person.
|
||||
let draft = tool_call(
|
||||
"books.draft_entry",
|
||||
serde_json::json!({"date": "2026-11-21", "description": "pay 00-0000000", "request_key": key}),
|
||||
);
|
||||
let (refusal, text) =
|
||||
answer(server.call_tool(draft, context(&s.peer, Some(ALL))).await).unwrap();
|
||||
assert!(refusal && text.contains("the description of books.draft_entry"), "{text}");
|
||||
// Nothing was made: no class, no entry.
|
||||
let projects = tool_call("books.projects", serde_json::json!({}));
|
||||
let (refusal, text) =
|
||||
answer(server.call_tool(projects, context(&s.peer, Some(ALL))).await).unwrap();
|
||||
assert!(!refusal && !text.contains("Rondo"), "{text}");
|
||||
// A reference that is no tax id is not refused for being one.
|
||||
let (_, text) = answer(
|
||||
server
|
||||
.call_tool(add("Rondo 2026-11-0042"), context(&s.peer, Some(ALL)))
|
||||
.await,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!text.contains("looks like it holds a tax id"), "{text}");
|
||||
let log = records(&books);
|
||||
assert_eq!(log[0], ("books.add_class".into(), refused("tin_in_text"), true));
|
||||
assert_eq!(log[1], ("books.draft_entry".into(), refused("tin_in_text"), true));
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -371,7 +371,7 @@ impl BooksServer {
|
||||
#[tool(
|
||||
name = "books.import_chart_csv",
|
||||
title = "Import a chart of accounts",
|
||||
description = "Import a chart of accounts from CSV (header: code,name,type,parent_code,tax_category; the last is optional), as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Types: asset, liability, equity, revenue, expense. Parents must come before children. Fails on the first bad row; nothing is half-imported. A revenue or expense row without a tax_category is listed in warnings, or, under policy.require_tax_category = refuse, refuses the file.",
|
||||
description = "Import a chart of accounts from CSV (header: code,name,type,parent_code,tax_category; the last is optional), as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Types: asset, liability, equity, revenue, expense. Parents must come before children. Fails on the first bad row, a cell that looks like a tax id included (it names the row and column); nothing is half-imported. A revenue or expense row without a tax_category is listed in warnings, or, under policy.require_tax_category = refuse, refuses the file.",
|
||||
annotations(
|
||||
read_only_hint = false,
|
||||
destructive_hint = false,
|
||||
|
||||
@@ -474,10 +474,10 @@ impl BooksServer {
|
||||
"due_date, or terms, or the customer's default terms, or invoicing.default_terms",
|
||||
)?;
|
||||
if let Some(r) = &p.customer_ref {
|
||||
ledger_core::parties::check_text("the customer reference", r)?;
|
||||
ledger_core::parties::check_reference_note("the customer reference", r)?;
|
||||
}
|
||||
if let Some(m) = &p.memo {
|
||||
ledger_core::parties::check_text("the memo", m)?;
|
||||
ledger_core::parties::check_note("the memo", m)?;
|
||||
}
|
||||
let settings = self.settings();
|
||||
let fields = arap::InvoiceFields {
|
||||
@@ -616,10 +616,10 @@ impl BooksServer {
|
||||
);
|
||||
}
|
||||
if let Some(m) = &p.memo {
|
||||
ledger_core::parties::check_text("the memo", m)?;
|
||||
ledger_core::parties::check_note("the memo", m)?;
|
||||
}
|
||||
if let Some(r) = &p.duplicate_reason {
|
||||
ledger_core::parties::check_text("the duplicate reason", r)?;
|
||||
ledger_core::parties::check_note("the duplicate reason", r)?;
|
||||
}
|
||||
// The file is taken before anything is written: an upload is used
|
||||
// up only by the call that files it (files.rs INVARIANT 1).
|
||||
|
||||
@@ -709,7 +709,7 @@ impl BooksServer {
|
||||
#[tool(
|
||||
name = "books.import_bank_csv",
|
||||
title = "Import a bank CSV as drafts",
|
||||
description = "Import a bank or card CSV (Date, Description, Amount; or Date, Description, money out, money in) as one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other. Give the CSV as upload_id (books.begin_upload purpose import; a file never passes through you). Ambiguous slash dates need date_order. Review with books.digest, then post. Also file the export (books.file_document category import_source) and pass source_attachment_id. Details in books.handbook section files-in-out.",
|
||||
description = "Import a bank or card CSV (Date, Description, Amount; or Date, Description, money out, money in) as one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other. Give the CSV as upload_id (books.begin_upload purpose import; a file never passes through you). Ambiguous slash dates need date_order. A description holding a number that reads as a tax id is kept masked to its last four digits (masked_count, masked). Review with books.digest, then post. Also file the export (books.file_document category import_source) and pass source_attachment_id. Details in books.handbook section files-in-out.",
|
||||
annotations(
|
||||
read_only_hint = false,
|
||||
destructive_hint = false,
|
||||
@@ -732,7 +732,14 @@ impl BooksServer {
|
||||
}
|
||||
};
|
||||
let (csv, claim) = self.csv_given(&p.upload_id)?;
|
||||
let txns = ledger_import::parse_bank_csv_with(&csv, order).map_err(|e| e.to_string())?;
|
||||
// A description a bank wrote is not typed by a person: a number in
|
||||
// it that reads as a tax id is kept masked to its last four digits
|
||||
// and named in the answer, never a reason to refuse the file.
|
||||
let ledger_import::MaskedBankImport {
|
||||
transactions: txns,
|
||||
masked,
|
||||
as_written,
|
||||
} = ledger_import::parse_bank_csv_masked(&csv, order).map_err(|e| e.to_string())?;
|
||||
let mut store = self.lock()?;
|
||||
let bank = store
|
||||
.ledger()
|
||||
@@ -788,8 +795,10 @@ impl BooksServer {
|
||||
// can't become a draft (a date in a closed period, say) refuses the
|
||||
// file instead of leaving the ones before it behind.
|
||||
let mut scratch = store.ledger().clone();
|
||||
for txn in &txns {
|
||||
let (offset_id, _) = offset_for(&txn.description);
|
||||
for (txn, written) in txns.iter().zip(&as_written) {
|
||||
// A rule reads the bank's own words, a nine-digit reference
|
||||
// in them included; what is kept is the masked text.
|
||||
let (offset_id, _) = offset_for(written);
|
||||
let amount = Money::new(txn.amount.abs(), base);
|
||||
let (bank_side, offset_side) = if txn.amount > Decimal::ZERO {
|
||||
(Side::Debit, Side::Credit)
|
||||
@@ -806,8 +815,8 @@ impl BooksServer {
|
||||
// Rehearsed whole: the upload is used up as the writing begins.
|
||||
files::filed(claim);
|
||||
let mut imported = Vec::new();
|
||||
for txn in txns {
|
||||
let (offset_id, offset_code) = offset_for(&txn.description);
|
||||
for (txn, written) in txns.into_iter().zip(&as_written) {
|
||||
let (offset_id, offset_code) = offset_for(written);
|
||||
let amount = Money::new(txn.amount.abs(), store.ledger().base_currency());
|
||||
let entry_id = store
|
||||
.create_entry(txn.date, &format!("Bank import — {}", txn.description))
|
||||
@@ -838,11 +847,34 @@ impl BooksServer {
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
let count = imported.len();
|
||||
let masked_count: usize = masked
|
||||
.iter()
|
||||
.fold(0, |n: usize, m| n.saturating_add(m.numbers));
|
||||
let masked_note = (masked_count > 0).then(|| {
|
||||
let lines: Vec<String> = masked.iter().map(|m| m.line.to_string()).collect();
|
||||
format!(
|
||||
"{masked_count} value{} in the Description column read as a tax id (nine digits standing alone, or an SSN's or an EIN's shape) and {} kept masked to the last four digits, on line{} {}. A bank's description is not typed by a person and often carries a nine-digit reference, so the file was not refused; a tax id is stored only with books.set_tin or a W-9 (books.set_w9)",
|
||||
if masked_count == 1 { "" } else { "s" },
|
||||
if masked_count == 1 { "was" } else { "were" },
|
||||
if lines.len() == 1 { "" } else { "s" },
|
||||
lines.join(", ")
|
||||
)
|
||||
});
|
||||
Ok(Json(ImportBankCsvOut {
|
||||
imported,
|
||||
count,
|
||||
source_attachment_id: p.source_attachment_id,
|
||||
source_linked: link_source,
|
||||
masked_count,
|
||||
masked: masked
|
||||
.into_iter()
|
||||
.map(|m| MaskedCellOut {
|
||||
row: m.line,
|
||||
column: m.column.to_string(),
|
||||
numbers: m.numbers,
|
||||
})
|
||||
.collect(),
|
||||
masked_note,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,7 +1550,7 @@ impl BooksServer {
|
||||
if r.trim().is_empty() {
|
||||
return Err("say why the entry has no counterparty".into());
|
||||
}
|
||||
ledger_core::parties::check_text("reason", r)?;
|
||||
ledger_core::parties::check_note("the reason", r)?;
|
||||
store
|
||||
.set_entry_party(p.entry_id, None)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
@@ -1368,6 +1368,29 @@ pub struct ImportBankCsvOut {
|
||||
/// True when this call linked it to the account (false when it already
|
||||
/// was, or none was given).
|
||||
pub source_linked: bool,
|
||||
/// How many descriptions held a number that reads as a tax id (nine
|
||||
/// digits standing alone, an SSN's or an EIN's shape) and were kept
|
||||
/// masked to its last four digits: a bank's description is not typed by
|
||||
/// a person and often carries a nine-digit reference, so the file is
|
||||
/// not refused for one (BS-partner-2).
|
||||
pub masked_count: usize,
|
||||
/// Which descriptions were masked, by the file's line.
|
||||
pub masked: Vec<MaskedCellOut>,
|
||||
/// What masking did, in words; present when `masked_count` is above
|
||||
/// zero.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub masked_note: Option<String>,
|
||||
}
|
||||
|
||||
/// One description of a bank file that was kept masked.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
pub struct MaskedCellOut {
|
||||
/// The file's line (the first line is 1).
|
||||
pub row: u64,
|
||||
/// The column: "Description".
|
||||
pub column: String,
|
||||
/// How many numbers in the cell were masked.
|
||||
pub numbers: usize,
|
||||
}
|
||||
|
||||
/// Parameters for `books.import_chart_csv`. No other argument is taken: a
|
||||
|
||||
Reference in new issue
Block a user