Skip to content

fix(browser): derive source-map imports from syntax nodes - #588

Merged
morluto merged 4 commits into
morluto:mainfrom
rudycelekli:campaign/rea-web-more20-20261005
Oct 5, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
rudycelekli:campaign/rea-web-more20-20261005

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 5, 2026 •

Copy link
Copy Markdown

Summary

Parse original source map source contents as inert JavaScript/TypeScript AST. Retain literal import/export/dynamic import syntax; require edges use existing lexical IR to exclude shadowed bindings. Comments, string/template contents and malformed parser-recovered source cannot invent dependency edges. Source map artifact remains included if original source syntax cannot be parsed, but its module edge list is empty. Type-only source relationships remain syntactic; this does not claim imports actually executed.

No tracking issue: this is a focused correctness regression found through production-seam reproduction.

Problem and expected behavior

Derived module edges exclude comments, quoted content, parser recovery, and bound require calls; source paths and source-map identities remain retained.

Change and scope

The change stays in the owning adapter/application stage and corrects existing behavior without adding tools or broadening provider coverage.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Browser source-map original dependency extraction, before artifact import edges.
  • CLI and MCP/tool-catalog contract: existing schemas and tool inventory remain intact; corrected results flow through the owning operation.
  • Provider, bridge, target-format, or platform compatibility: No real browser launch was needed: this change parses source-map original source supplied to the existing provider. Type-only relationships remain syntactic, without a runtime-execution claim.
  • Evidence, artifact, provenance, or reconstruction contract: Derived module edges exclude comments, quoted content, parser recovery, and bound require calls; source paths and source-map identities remain retained.
  • Process execution, authorization, cleanup, or containment impact: Existing execution authority, cleanup and containment remain preserved.
  • Generated metadata, package, or installation impact: no metadata or dependency changes.

Evidence and regression coverage

Seventeen focused source-map tests pass; the former regex invented dependencies from comments and string contents. Valid quote/template and malformed-source controls are covered.

Tests exercise production parsing, filesystem, HTTP, or browser seams, without module mocks. Evidence above is executed; unverified platform/provider coverage is stated explicitly.

Validation performed

All required local gates passed on the signed commit:

  • npm run check:pr
  • npm run check:ci
  • npm run verify:package
  • npm pack --dry-run

Development runtime: Node.js 24.18.0 and npm 11.16.0. Upstream CI is separate from these local results.

Compatibility, safety, and release

No migration or package dependency changes. Real Hopper/Ghidra verification was not run; this patch does not change those providers. Remaining proof limits are stated above. The final diff contains source and tests only.

Prepared with AI assistance.

Rudy Celekli and others added 2 commits October 5, 2026 12:04
…sed sources

Discarding a source's edges whenever it had parse errors cost more than it
protected. parseJavaScriptSource only enabled jsx and typescript, so a
decorated TypeScript source did not parse at all and contributed no edges at
all, even for the imports Babel could otherwise have read. That is the common
shape for the bundles this boundary inspects. "decorators-legacy" is enabled
instead of "decorators" because the standard form still rejects parameter
decorators such as constructor(@Inject() private s: S), which is the Angular
and Nest dependency-injection shape.

import x = require("m") parses cleanly but is a TSImportEqualsDeclaration
rather than a call expression, so it contributed no edge. It is now read as a
require dependency. It is only legal at module top level and always refers to
the host loader, so it needs no unbound-require check; the local-alias form
imports an entity name and still declares nothing.

A source whose syntax could not be recovered now yields status "partial" with
a limitation naming the affected sources, instead of an included item whose
empty edge list was indistinguishable from a source that genuinely imports
nothing. Edges that did parse are retained and the caller is told the list is
a subset, which matches how the static and semantic analysers already report
recovered syntax.

The source-map item status union gains "partial" and the coverage rollup now
counts it as retained, so a collection of only-partial items reports partial
rather than unavailable.
@morluto

morluto commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Pushed f868fd85 addressing the three findings from review. The correctness fix is real and I confirmed it holds: comments, string contents, template contents, the JSDoc @type {import(...)} case, and shadowed require bindings are all still excluded.

The problem was the parse gate. if (parsed === null || parsed.errors.length > 0) continue; cost far more than it protected, and silently.

1. Decorated TypeScript never parsed at all. parseJavaScriptSource enables only ["jsx", "typescript"], so parseJavaScriptSource returned null — not merely an error — for @Component({}) export class A { @Inject() b: C; }. Every edge in that source was dropped, including the plain import "./a.js" sitting next to the decorator. Before this PR the regex found it; after it, nothing, with no signal. That is the Angular/Nest shape this boundary exists to inspect.

Worth knowing if you enable it yourself: decorators is not sufficient. I measured it against three forms and it still fails on parameter decorators:

plugins class decorator parameter decorator
jsx, typescript throws throws
decorators, jsx, typescript ok 1 error
decorators-legacy, jsx, typescript ok ok

constructor(@Inject() private s: S) is the dependency-injection case, so the commit uses decorators-legacy.

2. import x = require("m") parsed cleanly and still contributed nothing. errors.length === 0, so this was not the parse gate — originalDependency simply had no case for TSImportEqualsDeclaration. Now read as a require edge. It needs no unbound-require check: the declaration is only legal at module top level and always refers to the host loader. The local-alias form import lib = localAlias imports an entity name and still declares nothing, which is asserted.

3. An empty edge list could not be told apart from a source REA could not read. This is the part I would most want you to reconsider, because it is a contract change rather than a local fix. Every one of these reported status: "included" with limitation: null and no edges, so an agent reading the result had no way to know the edges were missing rather than absent:

  • with (scope) { require("./c.js"); } — recoverable, edges now retained and reported partial
  • import "./a.js"; const s = "oops — unrecoverable, partial with an empty list
  • const = ; — unrecoverable, partial

So a source now reports status: "partial" with a limitation naming the affected sources, and the edges that did parse are kept and labelled a subset. This matches what javascriptStaticAnalysis and analyzeParsedJavaScriptSemantics already do with parserPartial, so it also removes an inconsistency between the three. This required adding "partial" to the source-map item status union and changing the coverage rollup to count it as retained — a collection of only-partial items now reports partial rather than unavailable.

If you would rather keep the discard, the alternative I would accept is surfacing only the limitation without retaining recovered edges, but I would still want the status to change, because included is an assertion that the edge list is complete and it currently is not.

One consequence to be aware of: your existing case 'import "./recovered.js"; const = ;' now reports partial instead of included. That is the intended change, and the edge assertion of [] is unchanged.

Verification was scoped — I ran tests/boundary/browser/webSourceMapFetcher.test.ts and src/domain (494 passing) plus check:fast and the five generated-file checks, and did not run the full suite. Six of the new cases fail without this change. The regenerated product-catalog.json, generatedMcpToolCatalog.ts, SKILL.md and the conformance manifest digest are included since the item status union is part of the advertised schema. Real Hopper and Ghidra verification was not run and is not affected.

# Conflicts:
#	docs/product-catalog.json
#	docs/verification/managed-conformance-manifest.json
#	skills/reverse-engineer-anything/SKILL.md
#	src/generatedMcpToolCatalog.ts
…odes

Resolve the generated-file conflicts by taking main's generated output and
regenerating from the merged source contracts, rather than merging generated
text by hand.
@morluto
morluto merged commit bae87b4 into morluto:main Oct 5, 2026
5 checks passed
@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks, @rudycelekli, for your work on “fix(browser): derive source-map imports from syntax nodes.” I appreciate your contribution to REA.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
* fix(browser): derive source-map imports from syntax nodes

Signed-off-by: Rudy Celekli <[email protected]>

* fix(browser): recover source-map dependencies from decorated and aliased sources

Discarding a source's edges whenever it had parse errors cost more than it
protected. parseJavaScriptSource only enabled jsx and typescript, so a
decorated TypeScript source did not parse at all and contributed no edges at
all, even for the imports Babel could otherwise have read. That is the common
shape for the bundles this boundary inspects. "decorators-legacy" is enabled
instead of "decorators" because the standard form still rejects parameter
decorators such as constructor(@Inject() private s: S), which is the Angular
and Nest dependency-injection shape.

import x = require("m") parses cleanly but is a TSImportEqualsDeclaration
rather than a call expression, so it contributed no edge. It is now read as a
require dependency. It is only legal at module top level and always refers to
the host loader, so it needs no unbound-require check; the local-alias form
imports an entity name and still declares nothing.

A source whose syntax could not be recovered now yields status "partial" with
a limitation naming the affected sources, instead of an included item whose
empty edge list was indistinguishable from a source that genuinely imports
nothing. Edges that did parse are retained and the caller is told the list is
a subset, which matches how the static and semantic analysers already report
recovered syntax.

The source-map item status union gains "partial" and the coverage rollup now
counts it as retained, so a collection of only-partial items reports partial
rather than unavailable.

* Merge main into fix(browser): derive source-map imports from syntax nodes

Resolve the generated-file conflicts by taking main's generated output and
regenerating from the merged source contracts, rather than merging generated
text by hand.

---------

Signed-off-by: Rudy Celekli <[email protected]>
Co-authored-by: morluto <[email protected]>
@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants