Skip to main content

Module memory_delivery_handlers

Module memory_delivery_handlers 

Source
Expand description

The endpoints Claude Code’s SessionStart hook calls to deliver an agent’s memory (docs/specs/SPEC_GLOBAL_MEMORY_DELIVERY_2026_09_27.md §7 P2). The composition and the part rules are backend::memory::delivery.

  • POST /api/v1/agent/memory/session-start/part — one part. Each of the HOOK_PARTS hook commands asks for its own part number. They run in parallel, so the first request for a (block, session, reason) composes the delivery and caches it, and every other part comes from that same composition.
  • POST /api/v1/agent/memory/session-start/ack — a hook wrote its part to Claude. Once every part is acknowledged the delivery is complete: the pane gets one persisted agentmux_memory_injected frame naming each entry and its size (owner decision D11). A part fetched but never acknowledged (the hook crashed or timed out) leaves the delivery incomplete, and no notice claims otherwise.

The agent comes from the request’s credential (X-Agent-Token → Caller::Agent): its Personal Memory is that agent’s. Without a token only Global Memory is delivered.

Structs§

AckRequest 🔒
ClaimResult 🔒
What a fallback’s claim found: deliver, or stand down because the hook delivered, or because the event was another block’s (foreign).
GateEntry 🔒
Removes a delivery’s compose gate when the part that took it is done.
LaunchDirs 🔒
Where a session’s CLI looked for its startup files.
PartRequest 🔒
PartResponse 🔒

Functions§

acknowledge 🔒
Marks part written. True exactly once: when this makes every part written and no notice has gone out yet.
append_notice 🔒
Appends one notice line to the block’s output and its transcript zone.
bind_to_grant 🔒
A container agent asks for its own block’s delivery only. Its block is the grant’s (an empty one is filled in); another block’s is refused, since the delivery is cached and composed per block, and a compaction summary is a block’s own conversation.
block_is_container 🔒
Whether the pane is a container agent’s: its host folders aren’t readable from inside, so an index line names the Memory tool’s form only.
card_frame 🔒
The agentmux_memory_injected frame both delivery routes write: the fields the card reads, then extra (the route’s own: the hook’s session and part count, the fallback’s delivery id).
carried_items 🔒
The card’s rows for the Global entries the startup file carried (every one that is not in newer): listed, sized 0 (the file’s row counts them).
claim_fallback 🔒
Whether the frontend’s hidden-reinjection fallback should deliver this event (true) or stand down because the SessionStart hook delivered it (false). Waits out a hook delivery still in flight for up to PENDING_WAIT, then lets the fallback deliver, so a hook that died part-way never leaves the agent without its memory. With a boundary_uuid, only the block whose CLI compacted can deliver. With event_at_ms (a fresh session’s time), the hook’s delivery for that session counts however late the claim comes.
compose_delivery 🔒
Reads the memory and composes the delivery. None when there is nothing to deliver. A new session’s delivery also lists the startup files the CLI loaded from launch (startup_items_of), ahead of the memory items.
compose_fallback_delivery 🔒
Composes the fallback’s hidden message from the same memory the hook delivers (global_entries, personal_entries), and the card that will stand for it. None when there is no memory.
delivery_items 🔒
The notice’s items, in delivery order, sized by what the parts carried.
fallback_frame 🔒
The card for a fallback re-delivery: the hook notice’s shape, under the delivery’s own id. fallback: true tells replay that the hidden message right after it is this delivery’s echo, not a second one.
finish_part 🔒
The reply for one part of a composed delivery. A delivery with nothing for the hook to carry still gets its card, on the first part asked for.
fit_and_compose 🔒
The delivery’s entries sorted by what each gets (fit::fit), composed and split the way the hooks will carry them. The character budget is only a guess at how the parts break at line ends, so when the real split still cuts (the notes at the end are what can tip it), a little more room is kept back and the fit is redone, so the reserved summary and the notes are never the part that is lost.
global_against_startup_files 🔒
Which current Global sections the CLI already got from a startup file: one AgentMux wrote that holds the section byte for byte. Returns the sections newer than the files (absent, or held in an older form, which the CLI never saw in its current form), and how much of the Global Memory the files carry. A foreign file doesn’t count, or the hook would drop current entries the agent never saw.
global_entries 🔒
Global Memory as the startup file carries it — its sections, Operator Config first (globalmemory:sections, P1).
global_left_out_item 🔒
The card’s row for a Global Memory entry left out of the delivery whole because it was full.
handle_session_start_ack 🔒
POST /api/v1/agent/memory/session-start/ack
handle_session_start_part 🔒
POST /api/v1/agent/memory/session-start/part
in_startup_file_item 🔒
A Global Memory entry that reached the agent through its startup file: listed in the card, sized 0 (the file’s own row counts it).
indexed_items 🔒
The card’s rows for the Personal files listed in the index: each sized by its index line, not “0 B”.
latest_startup_files 🔒
The startup files of the agent’s latest Claude spawn, from where its continuity segment says the CLI started: the fallback has no hook request to read them from.
modified_ms_of 🔒
When a Personal Memory file was last modified, in Unix ms: its modified frontmatter when it has one that parses, else the file’s mtime.
notice_frame 🔒
The persisted notice (D11): which memory was delivered, and each entry’s size. id is stable for the delivery, so a live frame and a replay of the same line render once.
part_response 🔒
personal_entries 🔒
The agent’s Personal Memory files from its latest spawn’s memory folder, by name, without the MEMORY.md index (the CLI’s own table of contents).
personal_entries_in 🔒
reason_for_fallback 🔒
The event a frontend reinjection reason stands for: a compaction, or a fresh session (a spawn without --resume, whose hook source is startup). None for anything else.
register_memory_delivery_handlers 🔒
Registers memorydelivery:claim_fallback — the frontend’s hidden memory reinjection asks it right before it would fire — and memorydelivery:compose, which composes what it sends.
send_partless_notice 🔒
A delivery with nothing for the hook to carry (its Global Memory is in the startup file, and there’s no Personal Memory) still has a card: written on the first part request, exactly once, since no part will be acknowledged.
session_start_ack 🔒
session_start_part 🔒
from_container: the request’s cwd and config_dir are paths inside the container, so nothing is read from the host for them. The startup files are the ones in the block’s own mounted workspace, as the CLI there read them.
startup_files 🔒
The files the CLI read by itself at session start.
startup_items_of 🔒
take_fallback_frame 🔒
The card of the fallback delivery delivery_id, taken once, when its hidden message reaches srv. None for an unknown or expired id, or one composed for another block.