feat(mcp): every result carries the envelope (P5)
Agent reason: an agent should never have to guess what follows a call. One place (call_tool, after the tool answers) now gives every tool result the same four fields: next_steps (what to do next, each with why and whether it is required), guards (the named refusal and the tool that remedies it), warnings, and, on any tool that is not read-only, head (where the journal ends after the call's last write). A tool's own field of the same name is kept, never overwritten; the text block says what the structured content says. Next steps come from the tool's own result (a preview gets its confirm step with the digest; a post is followed by showing the entry and, only if it was in error, its reversal; a draft by its lines; a statement by marking its lines and reconciling; a period list by the close) and, after a change to an entry or an invoice, from the viewer's own Needs-attention items about that subject, so the agent and the human read one list. guards.rs is the registry of refusals (stale_preview, format_upgrade_pending, receipt_required, approval_required, party_shares, party_required, open_drafts, untagged_control_line, duplicate_vendor_ref, first_number_locked), each naming a tool that exists. A refusal whose text carries a guard gets it as structuredContent.guards; its text is unchanged. Tests: every_mutating_result_has_head_and_next_steps (the whole router), the_envelope_keeps_what_a_tool_said_and_carries_a_refusal_guard, every_guard_names_an_existing_tool, a_refusal_becomes_its_guard, every_step_a_tool_names_exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
1 parent
169b914e1f
commit
cf73d0bda5
5 files changed
+803
No files matched your search
@@ -1391,6 +1391,10 @@ enum ShownDates {
|
||||
// Tools
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[path = "guards.rs"]
|
||||
mod guards;
|
||||
#[path = "next_steps.rs"]
|
||||
mod next_steps;
|
||||
#[path = "tools/access.rs"]
|
||||
mod access_tools;
|
||||
#[path = "tools/backup.rs"]
|
||||
@@ -1704,6 +1708,8 @@ impl ServerHandler for BooksServer {
|
||||
let running_call = call.clone();
|
||||
// Kept for the record of a call the server stopped before running.
|
||||
let request_args = request.arguments.clone();
|
||||
let tool_name = request.name.to_string();
|
||||
let envelope_args = request.arguments.clone();
|
||||
let result = run_blocking(&self.store, move || {
|
||||
Box::pin(async move {
|
||||
WROTE.with(|w| w.borrow_mut().take());
|
||||
@@ -1740,6 +1746,8 @@ impl ServerHandler for BooksServer {
|
||||
std::panic::resume_unwind(panic)
|
||||
}
|
||||
};
|
||||
// The result envelope (next_steps.rs INVARIANT 1).
|
||||
let out = next_steps::apply(&server, &tool_name, envelope_args.as_ref(), out);
|
||||
let mut c = running_call;
|
||||
c.digested(digest);
|
||||
let recorded = c.record_blocking(outcome_of(&out), wrote);
|
||||
|
||||
Reference in new issue
Block a user