Skip to content

feat(cli): add --json flag for machine-readable output with step traces - #64

Closed
Rasputin02 wants to merge 1 commit into
lynote-ai:mainfrom
Rasputin02:feat/json-output
Closed

Rasputin02 wants to merge 1 commit into
lynote-ai:mainfrom
Rasputin02:feat/json-output

Conversation

@Rasputin02

Copy link
Copy Markdown

What

Add a --json flag to the CLI that outputs the full pipeline result as JSON, including intermediate step outputs and timing.

Why

run_standard_pipeline() already returns a rich dict with step traces, engine names, and per-step character counts — but the CLI only prints the final text. This makes it hard to build tooling around the pipeline (e.g., a web UI showing progressive steps, or a CI check that logs which engine handled each step).

Usage

# Default (unchanged): prints final text only
python -m src.standard.pipeline --input draft.txt

# New: full JSON with step traces
python -m src.standard.pipeline --input draft.txt --json

Output:

{
  "result": "humanized text...",
  "steps": [
    {"step": 1, "engine": "DeepSeek", "direction": "Input → Chinese (中文改写)", "output": "...", "length": 1234},
    ...
  ],
  "processing_time_ms": 12345
}

When --verbose is combined with --json, step summaries go to stderr so stdout stays clean for piping.

The run_standard_pipeline() already returns step traces and timing,
but the CLI discarded everything except the final text. Add a --json
flag that dumps the full result as JSON to stdout, including all
intermediate step outputs and processing time.

Verbose step summaries go to stderr when --json is set so stdout
stays clean for piping into other tools.
molly554 added a commit that referenced this pull request Sep 16, 2026
Clean reimplementation of the ideas behind #65 and #64:

- _validate_pipeline_config() runs before any API call and reports a missing
  niutrans_api_key or an unrecognized intermediate_lang together, so a
  later-step failure no longer wastes LLM credits (resolves #62)
- --json emits the full result dict (step traces + timing) as JSON with
  ensure_ascii=False; plain and --verbose output unchanged (resolves #60)
- tests/test_pipeline_features.py — 6 cases (validation + CLI)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@molly554

Copy link
Copy Markdown
Contributor

Thanks @Rasputin02 — good idea, and it has landed on main in c3c0fd2 (from #60). I reimplemented rather than merging directly because this PR added the --json flag and the parameter but main() never used json_output (and import sys was unused), so the flag was a no-op as submitted. The shipped version emits the full result dict with step traces (ensure_ascii=False for readable CJK) and has CLI tests. Closing in favor of that commit.

@molly554 molly554 closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants