[PR #7092] fix(cli): parse environment-serve --port and --host like rea mcp --http #7635

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7092
Author: @Adolanium
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: fix/environment-serve-port-text


📝 Commits (2)

  • 53337a1 fix(cli): parse environment-serve --port and --host like rea mcp --http
  • d22d6d4 refactor(cli): reuse the shared MCP listener port and host schemas

📊 Changes

3 files changed (+39 additions, -6 deletions)

View changed files

📝 src/cli/environmentCommands.ts (+5 -5)
📝 src/config/mcpHttpEndpoint.ts (+2 -1)
📝 tests/boundary/cli/environmentServeCli.test.ts (+32 -0)

📄 Description

Summary

Fixes #7093.

rea environment-serve --port= (for example --port "$PORT" with PORT unset) binds an ephemeral port and serves, instead of failing. --port 0x1F90 and --port 1e3 are reinterpreted as 8080 and 1000, and --host " " is accepted. docs/cli.md says these flags resolve like rea mcp --http, which accepts only decimal port text and a non-empty host. They now use the same rules and are refused before anything binds.

Problem and expected behavior

The environment-serve options declared port with the numeric mcpHttpListenerPortSchema, so incur converted the flag text with Number(): "" became 0, "0x1F90" became 8080, "1e3" became 1000. host was z.string().min(1) without trimming. rea mcp --http parses --port as decimal text (mcpHttpPortSchema, also used for MCP_PORT) and refuses a blank --host.

Expected: those values are refused with a validation error, and no listener starts.

Change and scope

  • src/cli/environmentCommands.ts: --port uses mcpHttpPortSchema and --host uses mcpHttpHostSchema, the owners already used for MCP_PORT, MCP_HOST and rea mcp --http. The parsed values reach parseMcpHttpEndpoint unchanged, so the environment fallback is unchanged. The unused mcpHttpListenerPortSchema import is removed.
  • src/config/mcpHttpEndpoint.ts: mcpHttpHostSchema is exported; its rule is unchanged.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contribution scope: not applicable. This is a fix inside the existing environment-serve command.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the environment-serve option schema, where the flags are parsed.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: --port and --host refuse the values above with a validation error; valid values behave as before.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): no listener is bound for a refused value.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/environmentServeCli.test.ts, "refuses listener flag %s like rea mcp --http, before binding", for --port=, --port=0x1F90, --port=1e3 and --host= : each exits 1 with VALIDATION_ERROR naming the field, and stderr has no "MCP transport listening" line.
  • Base reproduction or other evidence: with environmentCommands.ts from upstream/main 80673b22a, rebuilt, all four cases fail. --port= and --port=0x1F90 time out after 30 s because the command starts serving on a port.
  • User-visible CLI/MCP output (if applicable): the validation error for these flags.
  • Remaining proof gaps: none beyond the CLI boundary test.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

On Linux (WSL Ubuntu, Node 24.22.1) at 53337a187 (on upstream/main 80673b22a), after npm ci and npm run build:cached:

  • npx tsc -p . --noEmit passed.
  • npx oxfmt --check on the changed files: clean. node scripts/ci/static-check-report.mjs lint: 0 errors.
  • npx vitest run tests/boundary/cli/environmentServeCli.test.ts and the other environment CLI tests: 35 passed, in two runs (first commit); environmentServeCli.test.ts: 8 passed, in two runs, at the shared-schema commit.
  • The negative check above (source reverted and rebuilt) failed the four new cases.

Compatibility, safety, and release

  • Breaking changes or migration steps: scripts that passed a non-decimal or empty --port now get an error instead of a different port.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: a misconfigured port no longer opens a listener on an unexpected port.

Author readiness

Human owner: @Adolanium

  • 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/7092 **Author:** [@Adolanium](https://github.com/Adolanium) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/environment-serve-port-text` --- ### 📝 Commits (2) - [`53337a1`](https://github.com/morluto/rea/commit/53337a187f1535dfa7f400f4e2fe806151733f3e) fix(cli): parse environment-serve --port and --host like rea mcp --http - [`d22d6d4`](https://github.com/morluto/rea/commit/d22d6d4ede0d866ed36291e22f361e7822a0cd54) refactor(cli): reuse the shared MCP listener port and host schemas ### 📊 Changes **3 files changed** (+39 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/cli/environmentCommands.ts` (+5 -5) 📝 `src/config/mcpHttpEndpoint.ts` (+2 -1) 📝 `tests/boundary/cli/environmentServeCli.test.ts` (+32 -0) </details> ### 📄 Description ## Summary Fixes #7093. `rea environment-serve --port=` (for example `--port "$PORT"` with `PORT` unset) binds an ephemeral port and serves, instead of failing. `--port 0x1F90` and `--port 1e3` are reinterpreted as 8080 and 1000, and `--host " "` is accepted. `docs/cli.md` says these flags resolve like `rea mcp --http`, which accepts only decimal port text and a non-empty host. They now use the same rules and are refused before anything binds. ## Problem and expected behavior The `environment-serve` options declared `port` with the numeric `mcpHttpListenerPortSchema`, so incur converted the flag text with `Number()`: `""` became `0`, `"0x1F90"` became `8080`, `"1e3"` became `1000`. `host` was `z.string().min(1)` without trimming. `rea mcp --http` parses `--port` as decimal text (`mcpHttpPortSchema`, also used for `MCP_PORT`) and refuses a blank `--host`. Expected: those values are refused with a validation error, and no listener starts. ## Change and scope - `src/cli/environmentCommands.ts`: `--port` uses `mcpHttpPortSchema` and `--host` uses `mcpHttpHostSchema`, the owners already used for `MCP_PORT`, `MCP_HOST` and `rea mcp --http`. The parsed values reach `parseMcpHttpEndpoint` unchanged, so the environment fallback is unchanged. The unused `mcpHttpListenerPortSchema` import is removed. - `src/config/mcpHttpEndpoint.ts`: `mcpHttpHostSchema` is exported; its rule is unchanged. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Unresolved scope, authority, side effects, or required verification block integration. Link the required maintainer scope decision for new providers or capabilities involving target execution, injection, mutation, or protection recovery; ordinary fixes within existing boundaries may state "not applicable". Draft PRs may leave the scope decision pending and the readiness and merge checklists unchecked. Maintainers can help resolve open questions. Contribution scope: not applicable. This is a fix inside the existing environment-serve command. ## Contract and boundary impact - Semantic owner and earliest changed stage: the `environment-serve` option schema, where the flags are parsed. - Contribution scope fit and linked maintainer decision: not applicable. - CLI and MCP/tool-catalog contract: `--port` and `--host` refuse the values above with a validation error; valid values behave as before. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): no listener is bound for a refused value. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact (CI generates and validates ignored catalogs and `skills/`; edit authored instructions in `.agents/skills/reverse-engineer-anything/` and never commit build outputs): none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [ ] Read existing files or captured data. - [x] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/cli/environmentServeCli.test.ts`, "refuses listener flag %s like rea mcp --http, before binding", for `--port=`, `--port=0x1F90`, `--port=1e3` and `--host= `: each exits 1 with `VALIDATION_ERROR` naming the field, and stderr has no "MCP transport listening" line. - Base reproduction or other evidence: with `environmentCommands.ts` from upstream/main 80673b22a, rebuilt, all four cases fail. `--port=` and `--port=0x1F90` time out after 30 s because the command starts serving on a port. - User-visible CLI/MCP output (if applicable): the validation error for these flags. - Remaining proof gaps: none beyond the CLI boundary test. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed On Linux (WSL Ubuntu, Node 24.22.1) at 53337a187 (on upstream/main 80673b22a), after `npm ci` and `npm run build:cached`: - `npx tsc -p . --noEmit` passed. - `npx oxfmt --check` on the changed files: clean. `node scripts/ci/static-check-report.mjs lint`: 0 errors. - `npx vitest run tests/boundary/cli/environmentServeCli.test.ts` and the other environment CLI tests: 35 passed, in two runs (first commit); `environmentServeCli.test.ts`: 8 passed, in two runs, at the shared-schema commit. - The negative check above (source reverted and rebuilt) failed the four new cases. ## Compatibility, safety, and release - Breaking changes or migration steps: scripts that passed a non-decimal or empty `--port` now get an error instead of a different port. - Real Hopper/Ghidra, browser, or OS coverage: Linux only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: a misconfigured port no longer opens a listener on an unexpected port. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: @Adolanium - [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 <!-- Draft PRs may leave pending items unchecked. Resolve material scope and authority questions before integration. --> - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7635
No description provided.