Skip to content

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 pointBest forOutput 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 ​

bash
# 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 to stdout without ANSI chrome; tool activity and progress messages stay on stderr.
  • stream-json (--json, --output-format stream-json|json|jsonl): emits one self-contained JSON object per line to stdout with monotonically increasing seq numbers; diagnostic output stays on stderr.
  • --output-last-message <file>: writes only the final assistant response text to <file> while still streaming to stdout.

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:

bash
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-json

Supported 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 ​

json
{"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 ​

typeKey fieldsWhen emitted
sessionsession_id, model, cwd, optional rag, memory, workflowOnce at start with effective non-secret session metadata
backendsession_id, agent, process_idPassthrough runs when the external CLI subprocess starts
titlesession_id, titleWhen Kompile generates a title for a new session
thinkingtextDisplay-only reasoning delta (never concatenated into the final narration)
texttextStreamed assistant narration delta
tool_startcall_id, name, optional input, detailWhen an Elthoria MCP tool or Kompile tool call begins
tool_outputcall_id, name, detailBounded live snapshot while a long-running tool is still executing
toolcall_id, name, ok, ms, optional detailWhen a tool call finishes (with duration and pass/fail status)
usageinput_tokens, output_tokens, cache_read_tokens, cache_creation_tokensProvider-reported token counts
sources / statssources / statsGrounding sources or summary metrics when produced
resulttext, session_id, tools, exitTerminal event on completion (includes full final text and total tool count)
errormessage, exitTerminal event on fatal error
detachedsession_id, messageWhen 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) ​

bash
elthoria exec --json "/elthoria-recap" \
  | jq -r --unbuffered 'select(.type == "text") | .text' -j

Audit every Elthoria MCP tool call and its latency ​

bash
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 ​

bash
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 codeMeaning
0Turn completed cleanly
1Runtime, provider, or missing-session failure
2Invalid CLI flags, missing prompt, or managed-option conflict
124Run exceeded --timeout <seconds> and was cancelled

6. Choosing the Right Streaming Protocol for Your Integration ​

Integration goalRecommended Elthoria interface
Shell scripts, CI smoke tests, cron recaps, Discord/Slack botselthoria exec --output-format stream-json (or elthoria chat --prompt ... --output-format stream-json)
Foundry VTT, Owlbear Rodeo, Roll20, or custom browser VTTselthoria 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 Panelselthoria web --web-port 9181 --open-browser (drives Kompile's Web Harness SSE + live web-json/stream-json control loop automatically)

Built on the upstream Kompile harness. Released under the MIT License.