Skip to main content

Module memory_delivery

Module memory_delivery 

Source
Expand description

An agent’s memory, delivered through Claude Code’s SessionStart hook (docs/specs/SPEC_GLOBAL_MEMORY_DELIVERY_2026_09_27.md §7 P2).

The hook’s additionalContext reaches the model without showing as a conversation turn — but, measured against the CLI AgentMux bundles (2.1.280), only up to about 10,000 characters per hook command: past that the CLI swaps it for a saved file plus a 2 KB preview, which the model can’t reliably read. Several hook commands’ contexts are all delivered, each under its own cap, in the order the hooks finish (they run in parallel). So the memory is split into MAX_PART_CHARS parts, each labelled “part N of M”, and HOOK_PARTS hook commands each ask for one.

This module is pure: composition, splitting and the source rules. The per-session cache, the acknowledgements and the notice live in the server handlers.

Structs§

Composed
A composed delivery and where each item sits in it.
Entry
One memory entry: a Global Memory section as the startup file carries it, or one Personal Memory file.
ItemSpan
Where one item sits in a composed delivery, in characters (SPEC_CONTEXT_DELIVERY_2026_09_30 §3.4 step 3).
Tracked 🔒
A string being built, with its length in characters kept alongside.

Enums§

Delivered
How much of one item a delivery carried.
FallbackReason
Why the frontend’s fallback re-delivers memory (memory-reinjection.ts’s ReinjectionReason).
Reason
Why memory is being delivered — the SessionStart hook’s source, for the sources that get a delivery.
Tier
Whether an entry is Global Memory (Operator Config included) or the agent’s own Personal Memory.

Constants§

HOOK_PARTS
How many hook commands are installed, so the most a delivery can carry is HOOK_PARTS * MAX_PART_CHARS characters. A memory larger than that is cut at the end, and the last part says so.
MAX_PART_CHARS
The most characters one part carries. The measured per-hook cap is about 10,000; the margin covers the part label and any counting difference.
REINJECTION_SIGNATURE
The sentence every hidden memory re-delivery opens with, whatever the reason: what is_hidden_reinjection_text (srv) and isMemoryReinjectionMessage (frontend) recognise it by.

Functions§

compose_fallback
The fallback’s hidden message, composed on srv (SPEC_CONTEXT_DELIVERY_2026_09_30.md §3.4 step 2, CD2b). Its wire format is the frontend’s composeReinjectionMessage, unchanged: the <system-reminder> envelope and REINJECTION_SIGNATURE are how srv’s digest, the continuation packet and replay recognise a hidden turn. No part cap: the fallback is one message. None when there is no memory. A compaction’s running summary is not here: srv’s input handler appends it (continuity_state::with_state_after_compaction).
compose_items_with
[compose_items], saying so when the Global Memory was left out because the agent’s startup file already carries it (a new Claude session that loaded AGENTMUX_MEMORY.md or an AgentMux-owned CLAUDE.md; SPEC_LAUNCH_CONTEXT_WORKSPACE_RULE_AND_STARTUP_FILES_2026_09_30.md §4.4).
push_sections 🔒
# Global Memory (n entries) and # Personal Memory (…), each item’s text whole, sections separated by a blank line; empty sections left out. The frontend’s composeReinjectionMessage writes the same, so a re-delivery carries the startup block’s sections byte for byte. Returns whether anything was written.
split_into_parts_counted
[split_into_parts], plus how many of text’s characters the parts carry: all of them unless the text was cut.