feat(mcp): books.start v2 and the agent's self-report (P5)

Agent reason: the first call of a session should say who is asking, what is
waiting and what to do, in under 8 KiB, from the same lists the viewer
draws. books.start now carries book.id and book.url (the book's path on the
server, never a path on a disk), you {principal, kind, scopes, client_id},
drafts {building, awaiting_evidence}, reconciliation {tracked,
never_reconciled, behind}, backup {last_at, through_seq, stale}, the
prompts, and needs_attention (the twelve most urgent items, problems first,
with every item counted by kind), beside next_steps now in the envelope's
shape (tool or prompt, why, required; attention problems are required). A
new book is told to run the onboard prompt first, then to record the
company's facts and set up the chart; an active one is offered a draft
entry. The tool carries _meta anthropic/alwaysLoad, so a client that defers
tools loads it up front. The size fit shortens attention items and waiting
drafts after the convention summaries and before the lists, as before.

agent {model, reasoning_effort, harness} is accepted and written to the
call's access record (the access log shows it as agent), self-reported and
never checked, and used for nothing else: not in the answer, not in any
decision. Who asked is the request's alone: it is cleared when the request
ends, so a later resource read on the same thread cannot see it.

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 15:48:27 -06:00
1 parent 996c5f40f4
commit 453abb62ea
7 files changed
+459 -25

No files matched your search

+26 -1
View File
@@ -1381,6 +1381,13 @@ thread_local! {
/// The journal's head after the last write made by the request
/// running on this thread (StoreGuard's drop), for its access record.
static WROTE: std::cell::RefCell<Option<(u64, String)>> = const { std::cell::RefCell::new(None) };
/// Who the request running on this thread is, as `books.start` shows
/// it: `{principal, kind, scopes, client_id}`. The token's own facts
/// and the client's name; set at the start of the request.
static YOU: std::cell::RefCell<Option<serde_json::Value>> = const { std::cell::RefCell::new(None) };
/// What the agent said about itself in a `books.start` this request is
/// running (`agent`), for the call's access record.
static AGENT_NOTE: std::cell::RefCell<Option<ledger_store::access::Agent>> = const { std::cell::RefCell::new(None) };
/// The company's time zone for the request running on this thread
/// (set at its start from the settings in force: one version per
/// request), so every "today" in it agrees.
@@ -1832,6 +1839,17 @@ impl ServerHandler for BooksServer {
.caller()
.map(|c| (c.token.id.clone(), c.token.name.clone()));
CALLER.with(|c| *c.borrow_mut() = caller);
AGENT_NOTE.with(|a| a.borrow_mut().take());
YOU.with(|y| {
*y.borrow_mut() = running_call.caller().map(|c| {
serde_json::json!({
"principal": c.token.name,
"kind": "agent",
"scopes": c.token.scopes.iter().map(|s| s.as_str()).collect::<Vec<_>>(),
"client_id": running_call.client_name(),
})
})
});
// Counted as running by now (run_blocking): hashed here.
let digest = Call::digest_of(request.arguments.as_ref());
let tcc =
@@ -1862,8 +1880,12 @@ impl ServerHandler for BooksServer {
};
// The result envelope (next_steps.rs INVARIANT 1).
let out = next_steps::apply(&server, &tool_name, envelope_args.as_ref(), out);
// Who asked is the request's alone: a later request on this
// thread (a resource read) must not see it.
YOU.with(|y| y.borrow_mut().take());
let mut c = running_call;
c.digested(digest);
c.with_agent(AGENT_NOTE.with(|a| a.borrow_mut().take()));
let recorded = c.record_blocking(outcome_of(&out), wrote);
(out, recorded)
})
@@ -2074,7 +2096,10 @@ impl BooksServer {
let server = self.clone();
let at = uri.clone();
let body = run_blocking(&self.store, move || {
Box::pin(async move { in_timezone_async(timezone, server.resource_body(&at)).await })
Box::pin(async move {
YOU.with(|y| y.borrow_mut().take());
in_timezone_async(timezone, server.resource_body(&at)).await
})
})
.await?;
// A refusal quotes the URI it was given: masked like a tool's.