Headless & Streaming Mode (elthoria exec & stream-json)
Because elthoria runs on top of the upstream Kompile Harness, Elthoria inherits Kompile's full non-interactive headless and stream-json streaming mode by proxy — automatically preloaded with the elthoria-gm role, your Elthoria MCP tools, your persistent H2 campaign database, and your folder-local bookshelf.
Use streaming mode for Discord/Slack bots, custom VTT integrations, scripted campaign recaps, automated regression tests, or any shell pipeline that wants real-time narration and structured tool-call telemetry.
TIP
Upstream specification: See Kompile Headless & Streaming Mode (kompile exec & stream-json) ↗ for the full underlying engine reference.
How Elthoria proxies streaming mode
Both elthoria exec and elthoria chat delegate directly to kompile chat --working-dir "$ELTHORIA_HARNESS_DIR" --role elthoria-gm "$@":
| Entry point | Best for | Output modes |
|---|---|---|
elthoria exec [OPTIONS] PROMPT... | One-shot GM turns, scripted recaps, and shell pipelines (validates that a prompt is supplied) | Default text, --json / --output-format stream-json, --output-last-message <file> |
elthoria chat --prompt ... (or stdin -) | Full headless overrides (attachments, stdin piping, or passthrough streaming over claude, codex, opencode, agy, gemini, qwen, pi) | Default text, --json, --output-format <text|stream-json|json|jsonl> |
NOTE
Elthoria-managed identity flags: Because Elthoria owns the GM workspace, role, and single-owner H2 database, --working-dir, --role, --product-profile, and --web-session-worker are managed by the launcher and rejected if overridden manually.
1. Quick Start: Streaming GM Turns & Recaps
# 1. Stream raw GM narration to stdout (tool & progress activity goes to stderr)
elthoria exec "/elthoria-recap"
# 2. Stream ordered JSONL (NDJSON) events — text deltas, tool calls, token usage, final result
elthoria exec --output-format stream-json \
"/elthoria-turn Rowan inspects the darkened South Beacon shutter — roll Perception"
# Short alias (--json is equivalent to --output-format stream-json):
elthoria exec --json "/elthoria-recap"
# 3. Stream JSONL while also writing the clean final narration to a Markdown file
elthoria exec --json --output-last-message session-recap.md "/elthoria-recap"
# 4. Override provider, auth route, model, or reasoning effort for a single streaming turn
elthoria exec \
--provider openrouter --model anthropic/claude-sonnet-4-5 \
--output-format stream-json \
"Advance Greywater Reach by one week and summarize public harbor news"
# 5. Resume a multi-turn scripted session (even across a different vendor)
SID="greywater-bot-$(date +%s)"
elthoria exec --session-id "$SID" --json "/elthoria-play load Lanterns at Greywater"
elthoria exec --resume "$SID" --provider openai --auth oauth --model gpt-5.6-sol --json \
"/elthoria-turn Rowan confronts Harbor Master Pell"
# 6. Pipe stdin notes directly into a headless streaming turn
cat session-notes.md | elthoria chat --output-format stream-json -Clean stdout / stderr separation
text(default): raw assistant text deltas stream directly tostdoutwithout ANSI chrome; tool activity and progress messages stay onstderr.stream-json(--json,--output-format stream-json|json|jsonl): emits one self-contained JSON object per line tostdoutwith monotonically increasingseqnumbers; diagnostic output stays onstderr.--output-last-message <file>: writes only the final assistant response text to<file>while still streaming tostdout.
2. Unified stream-json Across External Agent CLIs (Passthrough)
Through elthoria chat --mode passthrough, you can drive managed external vendor CLIs headlessly behind the exact same stream-json JSONL envelope while still injecting Elthoria's MCP server, campaign tools, and workspace memory:
elthoria chat --mode passthrough --agent claude --prompt "/elthoria-recap" --output-format stream-json
elthoria chat --mode passthrough --agent codex --prompt "/elthoria-recap" --output-format stream-json
elthoria chat --mode passthrough --agent opencode --prompt "/elthoria-recap" --output-format stream-json
elthoria chat --mode passthrough --agent agy --prompt "/elthoria-recap" --output-format stream-jsonSupported headless passthrough agents: claude, codex, gemini, qwen, opencode, pi, and agy (antigravity).
3. The stream-json JSONL Event Protocol
With --json or --output-format stream-json, every line written to stdout is a single JSON object containing a monotonically increasing seq integer (keeping interleaved token deltas and Elthoria MCP tool events strictly ordered) and a type discriminator.
Sample Elthoria tabletop stream
{"seq":1,"type":"session","session_id":"exec-7a4c2d10","model":"claude-sonnet-4-5","cwd":"/home/gm/.elthoria/kompile-harness"}
{"seq":2,"type":"tool_start","call_id":"call_1","name":"mcp__elthoria__get_play_dashboard"}
{"seq":3,"type":"tool","call_id":"call_1","name":"mcp__elthoria__get_play_dashboard","ok":true,"ms":28}
{"seq":4,"type":"tool_start","call_id":"call_2","name":"mcp__elthoria__roll_skill_check","input":"Perception"}
{"seq":5,"type":"tool","call_id":"call_2","name":"mcp__elthoria__roll_skill_check","ok":true,"ms":19}
{"seq":6,"type":"text","text":"Rowan squints through the salt mist. "}
{"seq":7,"type":"text","text":"Fresh wax seals glint on the brass padlock of the South Beacon shutter."}
{"seq":8,"type":"usage","input_tokens":3420,"output_tokens":145,"cache_read_tokens":2100,"cache_creation_tokens":0}
{"seq":9,"type":"result","text":"Rowan squints through the salt mist. Fresh wax seals glint on the brass padlock of the South Beacon shutter.","session_id":"exec-7a4c2d10","tools":2,"exit":0}Event reference
type | Key fields | When emitted |
|---|---|---|
session | session_id, model, cwd, optional rag, memory, workflow | Once at start with effective non-secret session metadata |
backend | session_id, agent, process_id | Passthrough runs when the external CLI subprocess starts |
title | session_id, title | When Kompile generates a title for a new session |
thinking | text | Display-only reasoning delta (never concatenated into the final narration) |
text | text | Streamed assistant narration delta |
tool_start | call_id, name, optional input, detail | When an Elthoria MCP tool or Kompile tool call begins |
tool_output | call_id, name, detail | Bounded live snapshot while a long-running tool is still executing |
tool | call_id, name, ok, ms, optional detail | When a tool call finishes (with duration and pass/fail status) |
usage | input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens | Provider-reported token counts |
sources / stats | sources / stats | Grounding sources or summary metrics when produced |
result | text, session_id, tools, exit | Terminal event on completion (includes full final text and total tool count) |
error | message, exit | Terminal event on fatal error |
detached | session_id, message | When a run detaches cleanly while background work continues |
4. Practical Shell & Bot Recipes (jq)
Stream live narration text cleanly (ideal for a Discord/VTT bot)
elthoria exec --json "/elthoria-recap" \
| jq -r --unbuffered 'select(.type == "text") | .text' -jAudit every Elthoria MCP tool call and its latency
elthoria exec --json "/elthoria-turn Rowan attacks the Tide-Stalker Smuggler" \
| jq -r --unbuffered 'select(.type == "tool") | "\(.name)\tok=\(.ok)\t\(.ms)ms"'Capture final narration, session ID, and tool count in a script
OUT=$(mktemp)
elthoria exec --json --timeout 300 --output-last-message recap.md "/elthoria-recap" > "$OUT"
STATUS=$?
SESSION_ID=$(jq -r 'select(.type == "result") | .session_id' "$OUT")
TOOLS_USED=$(jq -r 'select(.type == "result") | .tools' "$OUT")
echo "Exit=$STATUS Session=$SESSION_ID Tools=$TOOLS_USED"5. Exit Codes
| Exit code | Meaning |
|---|---|
0 | Turn completed cleanly |
1 | Runtime, provider, or missing-session failure |
2 | Invalid CLI flags, missing prompt, or managed-option conflict |
124 | Run exceeded --timeout <seconds> and was cancelled |
6. Choosing the Right Streaming Protocol for Your Integration
| Integration goal | Recommended Elthoria interface |
|---|---|
| Shell scripts, CI smoke tests, cron recaps, Discord/Slack bots | elthoria exec --output-format stream-json (or elthoria chat --prompt ... --output-format stream-json) |
| Foundry VTT, Owlbear Rodeo, Roll20, or custom browser VTTs | elthoria acp --ws --port 9188 (ACP v1 JSON-RPC 2.0 over localhost WebSocket with streaming session/update chunks & GM permission dialogs — see Connecting Foundry VTT & Other VTTs) |
| Desktop ACP editors (Zed, JetBrains, Neovim) | elthoria acp (ACP v1 over stdio) |
| Built-in browser GM table + Play Panels | elthoria web --web-port 9181 --open-browser (drives Kompile's Web Harness SSE + live web-json/stream-json control loop automatically) |