Documentation
¶
Overview ¶
Package imageextract externalizes inline base64 images from an agent's session transcript into a checkpoint asset store, replacing each with a compact, path-bearing placeholder, and re-injects them byte-exactly on restore.
The transform is per-agent because transcript formats differ: only agents that inline base64 images (Claude Code, Codex and Pi today) register a codec; every other agent resolves to nil and its transcript flows through untouched (a graceful no-op). All codecs share one extraction engine and reinjection routine and differ only in how they *find* images (their collector).
Correctness contract: for any transcript x from a supported agent, ReinjectImages(ExtractImages(x)) == x, byte-for-byte. This is achieved by only ever swapping the base64 image *value* in place (never re-marshalling the JSON) and by refusing to externalize any image whose raw bytes don't re-encode to the exact original base64 string.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DropImages ¶ added in v0.13.4
DropImages replaces every inline image in a transcript with a 1x1 image of the same type, so the stored copy holds no image content. A transcript with no images is returned unchanged.
It looks for every image shape any codec knows, whatever agent wrote the transcript, and unlike ExtractImages it has no size limit and does not require the value to be base64: an image externalization would leave inline must still not be stored.
An image is replaced in the decoded JSON, in the slot that holds it, and the JSON that held it is written back. Searching the raw bytes for the value instead would miss an image a serializer escaped differently and would rewrite unrelated text that repeats it. A line without an image keeps its bytes, a line with one comes back compact with sorted keys.
Each line's output depends only on that line, which the redaction prefix cache relies on, and dropping twice gives the same bytes as dropping once.
func HasPlaceholders ¶
HasPlaceholders reports whether a transcript carries any externalized-image placeholders — so restore knows to reinject regardless of the current config.
Types ¶
type Asset ¶
type Asset = agent.CompactedTranscriptAsset
Asset is one externalized image. It reuses the canonical agent asset model; Name is the stable asset filename (also the id used in the placeholder).
type ImageCodec ¶
type ImageCodec interface {
// ExtractImages lifts inline base64 images out, returning the rewritten
// (placeholder-bearing) transcript plus the extracted assets. A transcript
// with no externalizable images is returned unchanged with nil assets.
ExtractImages(transcript []byte) (rewritten []byte, assets []Asset, err error)
// ReinjectImages restores the original transcript by looking each placeholder's
// asset up by Name. Placeholders whose asset is missing are left in place.
ReinjectImages(transcript []byte, lookup func(name string) (Asset, bool)) ([]byte, error)
}
ImageCodec extracts/reinjects inline images for one agent's transcript format.
func CodecFor ¶
func CodecFor(t types.AgentType) ImageCodec
CodecFor returns the image codec for an agent type, or nil if the agent's transcript is not known to inline images (a no-op).