Skip to content

fix(cli): advertise the source-location path and URL constraints - #9281

Merged
morluto merged 3 commits into
morluto:mainfrom
Shelden-Hao:fix/cli-source-location-input-constraints
Nov 9, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
Shelden-Hao:fix/cli-source-location-input-constraints

Conversation

@Shelden-Hao

@Shelden-Hao Shelden-Hao commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #9201.

rea trace-web-source-location declared three of its positionals as bare strings, so --schema --json advertised manifestPath, sourceMapPath and sourceMapUrl with no minLength and no absolute-path pattern. A caller reading the advertised contract could not discover the constraint that the command actually enforces one parse later.

Problem and expected behavior

Smallest trigger, on main at 2e2f981:

node scripts/rea.mjs trace-web-source-location --schema --json

Before this change, the advertised args were:

"manifestPath": { "type": "string", "description": "Absolute export_web_scripts manifest path" },
"sourceMapPath": { "type": "string", "description": "Absolute local source-map path" },
"sourceMapUrl": { "type": "string", "description": "Absolute source-map URL context; no fetch" }

Passing a relative manifest then failed one stage later, from service.trace, not from the CLI argument parser:

{"code":"invalid_request","category":"invalid_input","details":{"operation":"trace_web_source_location","issues":[
  {"path":["manifest_path"],"reason":"invalid_format","message":"must be an absolute local filesystem path"},
  {"path":["source_map","path"],"reason":"invalid_format","message":"must be an absolute local filesystem path"}]}}

The violated invariant is that the advertised CLI input schema and the parsed domain input agree on the constraints of a selected local path. trace-web-module-imports already satisfies it by reusing webModuleTraceInputSchema fields, and tests/boundary/cli/cliInputSchemaRequired.test.ts already checks that sibling.

Change and scope

src/cli/webSourceLocationCommands.ts now binds the three positionals to their owning domain fields instead of restating them:

  • manifestPath → webSourceLocationInputSchema.shape.manifest_path
  • sourceMapPath / sourceMapUrl → webSourceLocationInputSchema.shape.source_map.shape.{path,url}

This follows the rule already recorded on cliDecimalField: the domain field owns bounds, defaults, nullability and help. It also corrects two descriptions that disagreed with the contract — sourceMapPath gained the "no fetch" statement that the MCP schema carries, and sourceMapUrl no longer claims to be absolute, which the domain never required.

The integer positionals (scriptIndex, line, column) keep cliIntegerArgument, because those need the CLI decimal-token parsing that the domain field does not provide; their advertised minimum/maximum already match the domain bounds.

A draft PR may leave the scope decision pending. This is a contract-consistency fix inside an existing capability: no new provider, no target execution, injection, memory mutation or protection recovery, so no maintainer scope decision is required.

I intentionally did not change other registrations that still declare bare path strings. Inspection of the sibling web-script workflow showed trace-web-module-imports is already correct; the remaining sites are in unrelated command families and each needs its own contract check, so they do not belong in this diff.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/webSourceLocation.ts stays the owner of the parsed facts. Only its consumer, the CLI registration, stops re-declaring them. No superseded code path remains; the duplicated literal descriptions are removed rather than kept in parallel.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: the CLI now advertises minLength: 1, the NUL-free pattern and the absolute-path pattern for both paths, and minLength: 1 for the URL, matching the trace_web_source_location MCP contract. The alias→domain mapping in run is unchanged, so the MCP surface is untouched.
  • Provider, bridge, target-format, or platform compatibility: the absolute-path pattern is the platform-specific one already used by every other command on the host running REA; no behavior change on either platform.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • 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; no generated file was edited.

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: a web source location CLI advertised input schema block in tests/boundary/cli/cliInputSchemaRequired.test.ts, next to the existing web module CLI advertised input schema case. It compiles the advertised args schema with Ajv2020 and asserts an absolute manifest and map are accepted, while an empty value, a relative value, a NUL-bearing value and an empty URL are rejected. The NUL cases carry a NUL inside an otherwise absolute path, for both manifestPath and sourceMapPath, so they pin the NUL pattern rather than being rejected by the absolute-path check alone.
  • Base reproduction or other evidence: I ran the negative control by reverting only src/cli/webSourceLocationCommands.ts and re-running the same test file. The new case fails on the base source and passes with the change, so it pins this defect rather than the surrounding behavior.
  • User-visible CLI/MCP output (if applicable):

After the change, trace-web-source-location --schema --json advertises:

"manifestPath": { "type": "string", "minLength": 1, "allOf": [
  {"pattern": "^[^\\x00]*$"}, {"pattern": "^(?:[\\x5C\\x2F]|[A-Za-z]:[\\x5C\\x2F])"}],
  "description": "Absolute export_web_scripts manifest path" },
"sourceMapPath": { "type": "string", "minLength": 1, "allOf": [
  {"pattern": "^[^\\x00]*$"}, {"pattern": "^(?:[\\x5C\\x2F]|[A-Za-z]:[\\x5C\\x2F])"}],
  "description": "Absolute local source-map path; no fetch" },
"sourceMapUrl": { "type": "string", "minLength": 1,
  "description": "Explicit source-map URL context used to resolve original source names" }

(A Windows host was used, so the advertised absolute pattern is the Windows one; the POSIX host advertises its own.)

and a relative manifest now fails at the CLI boundary with a field-level message instead of a service-level invalid_request:

{"code":"VALIDATION_ERROR","message":"REA could not read the command arguments. Check the named argument and its expected type, then try again.","fieldErrors":[
  {"code":"invalid_format","path":"manifestPath","message":"must be an absolute local filesystem path"},
  {"code":"invalid_format","path":"sourceMapPath","message":"must be an absolute local filesystem path"}]}
  • Remaining proof gaps: I did not run a successful end-to-end trace of a real source map on this host (that needs a retained export_web_scripts manifest plus its map). The change touches input advertisement and boundary rejection only, and the accepted-value path is unchanged: run still forwards the same three values under the same domain keys.

For boundary fixes, identify the applicable boundary regressions and lifecycle regressions covered by the evidence above, and explain relevant gaps. This is an input-contract boundary; no lifecycle stage is involved.

Validation performed

  • npm run compile — succeeded, produced dist.
  • node scripts/run-typescript.mjs --noEmit — no diagnostics.
  • node scripts/ci/static-check-report.mjs lint — 6626 files, 0 errors, 3332 warnings (all pre-existing categories).
  • node node_modules/vitest/vitest.mjs run tests/boundary/cli/cliInputSchemaRequired.test.ts — 24 passed, including the new case.
  • node scripts/run-typescript.mjs --noEmit and node scripts/ci/static-check-report.mjs lint were re-run after strengthening the NUL cases — no diagnostics, 6626 files with 0 errors.
  • Same test file with src/cli/webSourceLocationCommands.ts reverted — the new case fails, confirming the regression is pinned.
  • node scripts/rea.mjs trace-web-source-location --schema --json — output shown above.
  • node scripts/rea.mjs trace-web-source-location manifest.json 0 map.json http://x 1 0 --json — VALIDATION_ERROR naming manifestPath and sourceMapPath.
  • npm run test:focused -- tests/boundary/cli/cliInputSchemaRequired.test.ts — could not run in my checkout: node_modules/.package-lock.json is missing after an interrupted npm ci. I ran the same file directly with vitest, as recorded above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none in the domain or MCP contract. A CLI caller that passed an empty or relative path was already rejected one stage later; it now fails earlier, with the field named. A caller that passed an empty --source-map-url was already rejected by the domain min(1), so no previously successful invocation changes outcome.
  • Real Hopper/Ghidra, browser, or OS coverage: no provider was involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the change only narrows what the CLI advertises and accepts; no new file, process or network surface.

Author readiness

Human owner: @Shelden-Hao

  • 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.

@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The PR appears safe to merge, with a non-blocking correction needed to preserve the absolute-URL guidance.

Findings

  1. P2 URL help drops a requirement ▶
Fix with agent prompt
### Issue 1
src/cli/webSourceLocationCommands.ts:31
Reusing `sourceMapSelection.shape.url` removes “Absolute” from the CLI help, but `admitContext` still requires an absolute URL through `URL.canParse` without a base. A value such as `app.js.map` passes the advertised nonempty-string check, then fails in the service.

Restore the absolute-URL requirement in the shared field’s description so callers can discover it before running the command.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The CLI now reuses the domain fields for the manifest path, map path, and map URL.

  • The source-location CLI now checks its path and URL rules up front.

Reviews (5) · Last reviewed commit: "style(test): wrap input schema assertion..." · Reviewed by Greptile

trace-web-source-location declared manifestPath, sourceMapPath and sourceMapUrl
as bare strings, so `--schema --json` advertised them with no minLength and no
absolute-path pattern. The service then refused a relative manifest or map with
a post-parse invalid_request naming manifest_path and source_map.path, while
trace-web-module-imports already advertises those constraints from its domain
fields.

Bind the three positionals to webSourceLocationInputSchema so the domain field
owns the bounds, format and help, matching the rule in cliDecimalField that the
domain field owns bounds, defaults, nullability and help. The CLI now refuses a
relative or NUL-bearing value at its own boundary with a field-level message
instead of surfacing a service-level failure.

Add a boundary test that compiles the advertised args schema and asserts the
shared path and non-empty URL constraints, next to the existing sibling case.
The boundary case for trace-web-source-location used "manifest\0.json", which is
also a relative path. The absolute-path constraint alone rejects it, so the case
would still pass if schema conversion dropped the NUL pattern. Use an absolute
path with an embedded NUL instead, and add the same case for sourceMapPath.
The two unknown-byte cases exceeded the line width and tripped
format:check in CI. No assertion changes.
@Shelden-Hao
Shelden-Hao force-pushed the fix/cli-source-location-input-constraints branch from 4d431d8 to f67737f Compare November 8, 2026 14:12
.string()
.describe("Absolute source-map URL context; no fetch"),
sourceMapPath: sourceMapSelection.shape.path,
sourceMapUrl: sourceMapSelection.shape.url,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 URL help drops a requirement

Reusing sourceMapSelection.shape.url removes “Absolute” from the CLI help, but admitContext still requires an absolute URL through URL.canParse without a base. A value such as app.js.map passes the advertised nonempty-string check, then fails in the service.

Restore the absolute-URL requirement in the shared field’s description so callers can discover it before running the command.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/webSourceLocationCommands.ts
Line: 31

Comment:
**URL help drops a requirement**

Reusing `sourceMapSelection.shape.url` removes “Absolute” from the CLI help, but `admitContext` still requires an absolute URL through `URL.canParse` without a base. A value such as `app.js.map` passes the advertised nonempty-string check, then fails in the service.

Restore the absolute-URL requirement in the shared field’s description so callers can discover it before running the command.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@morluto
morluto merged commit 875f729 into morluto:main Nov 9, 2026
45 checks passed
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] trace-web-source-location CLI schema omits enforced path and URL constraints

2 participants