[PR #7040] [MERGED] feat(cli): accept stdin for structured JSON request documents (#5486) #7597

Closed
opened 2026-11-03 13:39:00 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7040
Author: @ahmed-husssain
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @morluto

Base: main ← Head: feat/cli-stdin-request-documents


📝 Commits (2)

  • 50a8422 feat(cli): accept stdin for structured JSON request documents (#5486)
  • 9a191e2 fix(cli): preserve cancellation and admission for JSON stdin

📊 Changes

8 files changed (+539 additions, -10 deletions)

View changed files

📝 src/application/Utf8JsonInput.ts (+1 -0)
📝 src/cli/electronCommands.ts (+1 -0)
📝 src/cli/wasmCommands.ts (+1 -0)
📝 src/cliBrowserScenarioCommands.ts (+5 -1)
📝 src/cliJsonInput.ts (+147 -9)
➕ tests/boundary/cli/cliJsonStdinCli.test.ts (+168 -0)
📝 tests/boundary/filesystem/cliJsonInput.test.ts (+210 -0)
➕ tests/fixtures/cliJsonStdinProbe.mjs (+6 -0)

📄 Description

Summary

Fixes #5486. Structured JSON request arguments now accept - to read stdin, enabling piped CLI workflows.

The shared boundary caps stdin at 8 MiB, checks live V8 heap headroom using the existing native-parser expansion estimate (including snapshot bookkeeping), and preserves strict UTF-8 handling and input_path: "-". Invalid syntax produces a structured error without echoing parser payload snippets; BOM and invalid UTF-8 retain explicit safe diagnostics.

Idle reads are interrupted by caller cancellation, with abort listeners disposed after reading. Stdin uses the same tagged error/cancellation projection as files, including cancellation during snapshot sealing. Browser scenario capture, Electron scenario capture, and WASM interface comparison forward their existing cancellation signals into JSON parsing.

Scope

CLI input parsing and signal forwarding only; provider execution, target authority, MCP contracts and generated catalog semantics are unchanged. Inline JSON and file-path inputs remain supported. A single stdin document is consumed through EOF. The 8 MiB byte cap and live-headroom refusal both return resource_constraint with input_reason: "too-large".

Validation performed

Node.js 24.22.1 / npm 11.16.0, macOS:

  • npm run test:focused -- tests/boundary/filesystem/cliJsonInput.test.ts tests/boundary/cli/cliJsonStdinCli.test.ts — 52 passed.
  • Public built CLI: SIGINT and SIGTERM with a held-open stdin pipe for all three signal-forwarding commands; exit codes 130/143 and code: "cancelled".
  • Public built CLI under --max-old-space-size=256: compact JSON below the stdin cap returns a measured heap-headroom refusal, both with and without snapshot sealing.
  • Regression comparison against the original parser: both idle-read cases timed out, three UTF-8 diagnostic cases failed, and sealing cancellation rejected instead of returning cancellation (6 failures). The fixed boundary passes all six.
  • npm run check:fast — typecheck and lint passed.
  • npm run docs:check — passed, including 9 README consistency tests.

Representative output: piping a leading UTF-8 BOM into rea compare-wasm-interfaces - --json returns code: "invalid_request", input_path: "-", input_reason: "invalid-json" and the UTF-8 BOM repair message.

Coverage limitations: real provider execution and Windows signal delivery were not exercised locally. POSIX signal cases skip on Windows. Linux CI results are tracked below by GitHub checks.

Parser cost sample

Local source-boundary sample: one 1,197,490-byte JSON document with a 1 MiB string and 10,000 objects, 64 KiB chunks, snapshot enabled. One first invocation and five warm invocations per fresh process; imports excluded, no child processes. This is a small noisy sample, not an optimization claim.

Measurement Original Fixed
First parse elapsed / CPU 11.71 / 33.66 ms 11.64 / 31.51 ms
Warm mean elapsed / CPU 5.67 / 10.52 ms 5.06 / 8.30 ms
Peak process-family RSS 129.55 MiB 132.63 MiB

Agent token usage and end-to-end analysis costs were not measured.

Author readiness

Human owner: @ahmed-husssain

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/7040 **Author:** [@ahmed-husssain](https://github.com/ahmed-husssain) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `feat/cli-stdin-request-documents` --- ### 📝 Commits (2) - [`50a8422`](https://github.com/morluto/rea/commit/50a8422a8b8c1545a1db90038be7d35d81a754d4) feat(cli): accept stdin for structured JSON request documents (#5486) - [`9a191e2`](https://github.com/morluto/rea/commit/9a191e2665699745e13fc943f489a1bd2828bee8) fix(cli): preserve cancellation and admission for JSON stdin ### 📊 Changes **8 files changed** (+539 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/application/Utf8JsonInput.ts` (+1 -0) 📝 `src/cli/electronCommands.ts` (+1 -0) 📝 `src/cli/wasmCommands.ts` (+1 -0) 📝 `src/cliBrowserScenarioCommands.ts` (+5 -1) 📝 `src/cliJsonInput.ts` (+147 -9) ➕ `tests/boundary/cli/cliJsonStdinCli.test.ts` (+168 -0) 📝 `tests/boundary/filesystem/cliJsonInput.test.ts` (+210 -0) ➕ `tests/fixtures/cliJsonStdinProbe.mjs` (+6 -0) </details> ### 📄 Description ## Summary Fixes #5486. Structured JSON request arguments now accept `-` to read stdin, enabling piped CLI workflows. The shared boundary caps stdin at 8 MiB, checks live V8 heap headroom using the existing native-parser expansion estimate (including snapshot bookkeeping), and preserves strict UTF-8 handling and `input_path: "-"`. Invalid syntax produces a structured error without echoing parser payload snippets; BOM and invalid UTF-8 retain explicit safe diagnostics. Idle reads are interrupted by caller cancellation, with abort listeners disposed after reading. Stdin uses the same tagged error/cancellation projection as files, including cancellation during snapshot sealing. Browser scenario capture, Electron scenario capture, and WASM interface comparison forward their existing cancellation signals into JSON parsing. ## Scope CLI input parsing and signal forwarding only; provider execution, target authority, MCP contracts and generated catalog semantics are unchanged. Inline JSON and file-path inputs remain supported. A single stdin document is consumed through EOF. The 8 MiB byte cap and live-headroom refusal both return `resource_constraint` with `input_reason: "too-large"`. ## Validation performed Node.js 24.22.1 / npm 11.16.0, macOS: - `npm run test:focused -- tests/boundary/filesystem/cliJsonInput.test.ts tests/boundary/cli/cliJsonStdinCli.test.ts` — 52 passed. - Public built CLI: SIGINT and SIGTERM with a held-open stdin pipe for all three signal-forwarding commands; exit codes 130/143 and `code: "cancelled"`. - Public built CLI under `--max-old-space-size=256`: compact JSON below the stdin cap returns a measured heap-headroom refusal, both with and without snapshot sealing. - Regression comparison against the original parser: both idle-read cases timed out, three UTF-8 diagnostic cases failed, and sealing cancellation rejected instead of returning cancellation (6 failures). The fixed boundary passes all six. - `npm run check:fast` — typecheck and lint passed. - `npm run docs:check` — passed, including 9 README consistency tests. Representative output: piping a leading UTF-8 BOM into `rea compare-wasm-interfaces - --json` returns `code: "invalid_request"`, `input_path: "-"`, `input_reason: "invalid-json"` and the UTF-8 BOM repair message. Coverage limitations: real provider execution and Windows signal delivery were not exercised locally. POSIX signal cases skip on Windows. Linux CI results are tracked below by GitHub checks. <details> <summary>Parser cost sample</summary> Local source-boundary sample: one 1,197,490-byte JSON document with a 1 MiB string and 10,000 objects, 64 KiB chunks, snapshot enabled. One first invocation and five warm invocations per fresh process; imports excluded, no child processes. This is a small noisy sample, not an optimization claim. | Measurement | Original | Fixed | | --- | ---: | ---: | | First parse elapsed / CPU | 11.71 / 33.66 ms | 11.64 / 31.51 ms | | Warm mean elapsed / CPU | 5.67 / 10.52 ms | 5.06 / 8.30 ms | | Peak process-family RSS | 129.55 MiB | 132.63 MiB | Agent token usage and end-to-end analysis costs were not measured. </details> ## Author readiness Human owner: @ahmed-husssain - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 13:39:00 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7597
No description provided.