Expand description
Session export — produces Markdown, HTML, or JSON representations of a
parsed timeline. Used by the --export md|html|json flag.
All three writers take the same inputs (steps + totals + no_cost flag)
and return String — callers print to stdout or redirect to a file.
No I/O happens inside this module.
Schema stability: the JSON exporter’s output is the reserved programmatic interface between agx and downstream consumers (Phase 7 library mode). Field renames or removals count as breaking changes.
Functions§
- apply_
redactions - Apply literal-substring redactions to a string. Every entry in
patternsgets replaced with[REDACTED]wherever it appears. Order preserves the caller’s list; each pattern is applied in turn so later redactions operate on the already-redacted text. - html
- Render a session as self-contained HTML with inline CSS, no JS, no
external assets. Color palette mirrors the TUI — cyan/user,
green/assistant, yellow/tool_use, magenta/tool_result. When
annotationsis provided, steps with a note render the text in a magenta-bordered<div class="note">below the meta line. - json
- Serialize a session to stable-schema JSON. Pretty-printed for readability;
callers that want compact output can
jq -c. WhenannotationsisSomeand non-empty, adds anannotationsarray at the top level; omits the field entirely when there are no notes. - markdown
- Render a session as a Markdown transcript. One H2 section per step, with
metadata listed under the header and detail inside a code fence. Totals
live in a short front-matter block at the top. When
annotationsis provided, a blockquote with the note text is emitted below the meta line for any step that has one. - redacted_
steps - Apply
--redactpatterns to a borrowed step slice, returning a redacted clone. Every exporter accepts an already-redacted&[Step]slice rather than the patterns themselves, so masking lives in one place and the format-specific code stays simple. Returns the original slice unchanged (via clone) whenpatternsis empty so the common case allocates nothing extra for unused features. - trajectory_
openai - Render a session as one-line OpenAI fine-tuning JSONL. Emits a
single JSON object per session (caller typically redirects to a
.jsonlfile). Each timeline step maps to one message: