Skip to main content

Module export

Module export 

Source
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 patterns gets 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 annotations is 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. When annotations is Some and non-empty, adds an annotations array 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 annotations is provided, a blockquote with the note text is emitted below the meta line for any step that has one.
redacted_steps
Apply --redact patterns 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) when patterns is 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 .jsonl file). Each timeline step maps to one message: