Skip to main content
← Back to list
01Issue
BugShippedSwamp CLI
Assigneesstack72

Relationships

#430 --json output is polluted by non-JSON content, breaking machine parsing

Opened by keeb · 5/24/2026· Shipped 5/25/2026

Description

--json mode is supposed to make stdout a single, parseable JSON document. It isn't — non-JSON text reaches stdout from three independent sources, so json.load / JSON.parse chokes on real output.

1. In-process extensions write directly to stdout (primary cause)

RawExecutionDriver (the default driver) runs model methods directly in the host Deno process:

// src/domain/drivers/raw_execution_driver.ts:180
const result = await this.executor.execute(this.definition, this.method, this.contextWithWriters);

There is no console isolation around that call. Extensions don't use LogTape — they console.log(...) for progress/debugging — and that lands straight on swamp's stdout, interleaved with the renderer's JSON. swamp's own logging is correctly muted in JSON mode (root logger gets no sinks in src/infrastructure/logging/logger.ts:88), so the leak is extension code bypassing the logging pipeline, not swamp's logs. command/shell doesn't leak because it explicitly captures subprocess stdout into a data artifact; an in-process TS extension has nothing capturing it.

2. Group commands print ANSI help to stdout in JSON mode

swamp --json, swamp doctor --json, etc. fall through to this.showHelp() (src/cli/mod.ts:1212 plus ~28 other call sites), which dumps colorized help text to stdout regardless of --json.

3. Extension-load warnings go to stderr

src/infrastructure/logging/extension_load_warnings.ts:77 uses console.error — only corrupts output when stderr is merged via 2>&1.

Steps to Reproduce

  1. Run a model method whose extension calls console.log under the default (raw) driver with --json, e.g. swamp model method run <m> <method> --json.
  2. Observe extension stdout interleaved with the JSON document.
  3. swamp doctor --json — observe ANSI help text instead of JSON.

Environment

swamp dev build (sha 93c9a4fd), Deno, Linux.

Suggested Fix

In JSON mode, reserve stdout for exactly one JSON document; route everything else to stderr or the run log. Concretely: install a console guard around the in-process execution boundary that funnels extension console.* into the run's log sink, and make showHelp() JSON-aware.

02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED+ 7 MORETRIAGE+ 10 MOREREVIEW+ 7 MOREPR_LINKED+ 1 MORENOTIFICATION_SKIPPED

Shipped

5/25/2026, 6:16:55 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
stack72 assigned stack725/24/2026, 10:23:44 PM

Sign in to post a ripple.