refactor!: files only by handle: uploads in, downloads out (D-46)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The owner (2026-10-23, via the question tool): "Uploads only"; and before it: "What we would DEFINITELY want to avoid is passing a bunch of BLOBs through AI context windows. That's just a pure waste." No file passes through an agent's context, in either direction. In: the inline arguments are gone with the 256 KiB limit (INLINE_MAX, take_file's inline branch): content_base64 and its sha256 on books.attach_receipt and books.file_document, w9_content_base64 and w9_sha256 on books.set_w9, csv_text on the two CSV imports. A file comes only by books.begin_upload and `wanderbooks upload`, named by its upload_id; existing_attachment_id still names bytes stored already. The five filing tools deny unknown fields, and any inline argument to any tool is refused before it runs as an unknown argument pointing to books.begin_upload (access log: refused inline_file). Out: books.export (every format), books.asset_labels and books.get_receipt view bytes hand the file over (HandedFile: download command and expiry, D-29), as the CPA package and the W-9 do. Resource reads stay text. A token keeps up to 64 handed files (was 16). The access log's digest no longer exempts file bytes. Docs: handbook files-in-out and parties-and-tins, mcp-interface.md, rules.md, receipt-store.md, parties-and-attachments.md, plan/served.md (D-46; the inline decisions marked superseded), STATUS.md, testing.md (D-46: tests migrated to uploads and downloads, rewritten, removed, added). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
This commit is contained in:
38 files changed
+1702
-1172
No files matched your search
@@ -15,25 +15,15 @@ mod common;
|
||||
const CLIENTS: usize = 6;
|
||||
const ENTRIES: usize = 12;
|
||||
|
||||
fn b64(bytes: &[u8]) -> String {
|
||||
const T: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
let mut out = String::new();
|
||||
for c in bytes.chunks(3) {
|
||||
let n = (u32::from(c[0]) << 16)
|
||||
| (u32::from(*c.get(1).unwrap_or(&0)) << 8)
|
||||
| u32::from(*c.get(2).unwrap_or(&0));
|
||||
for (i, shift) in [18, 12, 6, 0].iter().enumerate() {
|
||||
if i <= c.len() {
|
||||
out.push(T[((n >> shift) & 63) as usize] as char);
|
||||
} else {
|
||||
out.push('=');
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
async fn draft(c: &Client, tag: &str, cents: u64, with_receipt: bool) -> u64 {
|
||||
/// Draft a `cents` entry tagged `tag` on `c` (a session with `token`, of
|
||||
/// the server whose `run/` folder is `run`), with a receipt uploaded for
|
||||
/// it as an agent uploads one, if `with_receipt`.
|
||||
async fn draft(
|
||||
(c, run, token): (&Client, &std::path::Path, &str),
|
||||
tag: &str,
|
||||
cents: u64,
|
||||
with_receipt: bool,
|
||||
) -> u64 {
|
||||
let e = call(
|
||||
c,
|
||||
"books.draft_entry",
|
||||
@@ -53,12 +43,19 @@ async fn draft(c: &Client, tag: &str, cents: u64, with_receipt: bool) -> u64 {
|
||||
.unwrap();
|
||||
}
|
||||
if with_receipt {
|
||||
let upload = common::upload_on(
|
||||
c,
|
||||
run,
|
||||
common::BOOK,
|
||||
token,
|
||||
tag.as_bytes(),
|
||||
(&format!("{tag}.pdf"), "application/pdf", "receipt"),
|
||||
)
|
||||
.await;
|
||||
call(
|
||||
c,
|
||||
"books.attach_receipt",
|
||||
json!({"entry_id": id, "file_name": format!("{tag}.pdf"),
|
||||
"mime_type": "application/pdf", "content_base64": b64(tag.as_bytes()),
|
||||
"sha256": ledger_store::journal::sha256_hex(tag.as_bytes())}),
|
||||
json!({"entry_id": id, "upload_id": upload}),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -102,7 +99,15 @@ async fn agents_posting_at_once_leave_whole_books() {
|
||||
// Drafts every client will race to post.
|
||||
let mut contested = Vec::new();
|
||||
for k in 0..ENTRIES {
|
||||
contested.push(draft(&setup, &format!("contested {k}"), 100 + k as u64, true).await);
|
||||
contested.push(
|
||||
draft(
|
||||
(&setup, &run, &token),
|
||||
&format!("contested {k}"),
|
||||
100 + k as u64,
|
||||
true,
|
||||
)
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
let mut tasks = Vec::new();
|
||||
@@ -110,13 +115,13 @@ async fn agents_posting_at_once_leave_whole_books() {
|
||||
let (run, token) = (run.clone(), token.clone());
|
||||
let contested = contested.clone();
|
||||
tasks.push(tokio::spawn(async move {
|
||||
let c = connect(run, token).await;
|
||||
let c = connect(run.clone(), token.clone()).await;
|
||||
let (mut posted, mut refused, mut won) = (0usize, 0usize, 0usize);
|
||||
for (k, &race) in contested.iter().enumerate() {
|
||||
// A receipted entry posts; a bare one is refused.
|
||||
let receipted = k % 3 != 0;
|
||||
let id = draft(
|
||||
&c,
|
||||
(&c, &run, &token),
|
||||
&format!("c{n} e{k}"),
|
||||
(n * 1000 + k + 1) as u64,
|
||||
receipted,
|
||||
|
||||
Reference in new issue
Block a user