Skip to content

fix(reference): report sloppy scripts, PHP, C# and enclosing Git facts - #1770

Merged
baron merged 5 commits into
morluto:mainfrom
flitzrrr:fix/reference-source-import-facts
Oct 12, 2026
Merged

baron merged 5 commits into
morluto:mainfrom
flitzrrr:fix/reference-source-import-facts

Conversation

@flitzrrr

@flitzrrr flitzrrr commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

import-reference-source records wrong or missing facts for an ordinary legacy subtree:

  • A valid sloppy-mode script is reported as a parse failure.
  • .php and .cs files have no language.
  • A directory inside a Git checkout is reported as having no version control.
  • importer_version is null.

This PR corrects all four at their owning boundaries. They are kept together because they are all facts of one import result.

I did not open a separate issue because the PR carries the full reproduction below.

Problem and expected behavior

Reproduction: a Git repository whose committed source/ directory contains legacy.js (var messages = {};\ndelete messages;\n), index.php and Program.cs. Then run rea import-reference-source <repo>/source --format json --filter-output languages,parse_failures,vcs,provenance.

Before (062723e):

{"languages":["JavaScript"],"parse_failures":[{"path":"legacy.js","parser":"babel","reason":"Deleting local variable in strict mode. (2:0)"}],"vcs":{"kind":"none","head":null,"dirty":null},"provenance":{"importer":"rea-agents","importer_version":null,"caller":"rea-cli"}}

After:

{"languages":["C#","JavaScript","PHP"],"parse_failures":[],"vcs":{"kind":"git","head":"45763e758c7b0d62b7b7382650afffd515563b90","dirty":null},"provenance":{"importer":"rea-agents","importer_version":"6.4.0","caller":"rea-cli"}}

Causes:

  1. Babel's sourceType: "unambiguous" parses as a module first. With errorRecovery, it keeps those strict-mode errors after falling back to program.sourceType === "script".
  2. LANGUAGE_BY_EXTENSION had no php or cs entry.
  3. ReferenceSourceVcsAdapter only checked <root>/.git. A missing entry there was reported as kind: "none", a wrong absence claim for a subtree of a checkout.
  4. The CLI passed importerVersion: null although PRODUCT_IDENTITY.packageVersion is known.

Change and scope

  1. parseRecoveredJavaScript in javascriptSourceParser.ts parses reference sources by extension: .mjs/.mts as modules, .cjs as scripts. Other sources fall back to a script when Babel settles on one, and errors only the module parse reports become an entry limitation. The application pipeline (parseJavaScriptSource) is unchanged.
  2. php maps to PHP and cs to C#. This is detection only: neither language is parsed for imports.
  3. The VCS adapter walks up to the nearest ancestor with a .git entry, as Git does for a subdirectory, and reads HEAD through the existing reader. It reports none only when no ancestor has one, and unknown on any other lookup error. dirty stays null, so whether the subtree matches HEAD remains unknown. docs/cli.md documents this.
  4. The CLI records the package version as importer_version.

Not included:

  • .gitignore files above the selected root are still not applied to exclusions.
  • csproj and sln are not classified as manifests.
  • webBundleAnalyzerInspection keeps its own parse, because it does not report parser errors.

Contract and boundary impact

  • Semantic owner and earliest changed stage:
    • JavaScript parser boundary (src/domain/javascript/javascriptSourceParser.ts)
    • reference-source classification (src/domain/referenceSourceClassification.ts)
    • VCS adapter (src/application/ReferenceSourceVcsAdapter.ts)
    • CLI composition (src/cli/utilityCommands.ts)
  • CLI and MCP/tool-catalog contract: no schema changes; languages, parse_failures, vcs and provenance.importer_version values change as shown.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: fewer false parse failures and false parser-recovered semantic coverage. VCS identity is now reported for subtrees of a checkout.
  • Process execution, authorization, cleanup, or containment impact: VCS discovery now checks ancestor directories for .git and may read the enclosing repository's HEAD and refs outside the selected root, through the existing read path without a subprocess. This is documented in docs/cli.md.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/cli/referenceSourceLegacyFacts.test.ts: the compiled CLI on the reproduction above, asserting all four facts.
  • Base reproduction: the CLI test fails on 062723e at parse_failures and passes with this change.
  • User-visible CLI/MCP output: shown above.
  • Remaining proof gaps: Git ceiling directories and filesystem-boundary discovery rules are not modelled; discovery stops at the first ancestor with a .git entry. No Windows run (the import is unsupported on native Windows).

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 macOS (Darwin 27.0, Apple Silicon), Node 24.18.0:

  • npm run test:fast — 375 files, 4270 passed, 7 skipped
  • npm run test:focused -- tests/boundary/filesystem/referenceSource*.test.ts tests/boundary/cli/referenceSource*.test.ts — 19 files, 69 passed, 2 skipped
  • npm run check — passed
  • npm run docs:check — passed
  • npm run verify:test-discovery — 814 test files discovered exactly once
  • npm run build:cached and the CLI run above — passed

Review follow-up

  • 641732e: .mjs/.mts parse as modules through one parser-owned rule; .cs/.php are classified as source.
  • d4169d8 / 6598d42 / a4ff51b: unmarked sources (everything except .mjs/.mts/.cjs) keep an unknown mode and are not forced to script; module-only strict errors become an entry limitation. .cjs parses as a script. Package-scope resolution was tried and removed again, because it kept pulling in more of Node's lookup rules; this matches the require-binding analysis, which also treats unmarked paths as unknown. The application pipeline parses as on main.
  • The CLI test covers explicit modules, .cjs, unknown mode and classification; it fails on the previous head.
  • npm run test:fast — 4270 passed; reference-source boundary — 69 passed; npm run check:fast — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Consumers that treated vcs.kind: "none" as authoritative for subdirectories now receive the enclosing repository's HEAD.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; macOS only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the only new file access is read-only Git metadata of the nearest enclosing repository, as described above.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

🤖 Generated with Claude Code

Importing the source/ subtree of a legacy PHP and C# checkout produced
four wrong or missing facts:

- Babel's unambiguous mode parses a module first and keeps its
  strict-mode recovery errors after falling back to a script, so a valid
  sloppy-mode `delete messages;` was reported as a parse failure and the
  semantic IR marked the file as parser-recovered. Parsing now goes
  through one owner that re-parses such a script as a script.
- .php and .cs files had no language; they are now detected as PHP and
  C# (detection only, no parsing).
- A root without its own .git was reported as having no version
  control even inside a checkout. The adapter now resolves the nearest
  enclosing repository, as Git does, and reports `none` only when no
  ancestor has one.
- The CLI recorded importer_version as null although the package
  version is known.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4b639c2e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T10:35:04.123408Z a4ff51b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Review follow-up. `.mjs` and `.mts` files are modules by extension, but
the script fallback re-parsed them in sloppy mode and erased real
strict-mode errors. The parser boundary now owns the extension rule,
parses explicit modules as modules and applies the fallback only when
the mode is ambiguous; the require-binding analysis uses the same rule.

`.cs` and `.php` received a language but stayed classified as unknown,
so source-to-bundle comparison dropped them. Both are now source
extensions, like the other detected languages.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 641732e58b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ct errors

Review follow-up. A `.js` file under a package.json with `"type":
"module"` is an ES module, but it went through the script fallback that
erases strict-mode errors. The import now reads each in-inventory
package.json and parses `.js` files in a module scope as modules. Other
`.js` and `.ts` sources keep an unknown mode, because bundlers treat them
as modules without that field: they are no longer forced to script, and
errors that only the module parse reports are kept as an entry limitation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4169d85ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…hanged

Review follow-up.
- `.cjs` files parse as scripts, so module-only strict errors no longer
  become limitations on CommonJS trees. `.cts` keeps an unknown mode
  because TypeScript compiles ES import syntax there.
- An unreadable or linked package.json now bounds the module scope with
  an unknown type instead of letting an outer `"type": "module"` apply.
- The application pipeline parses as on main again. Its module-only
  strict errors keep a source partial; package-mode handling stays in the
  reference importer.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6598d42f5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…solving package scope

Review follow-up. Resolving Node package scope for `.js` kept pulling in
more of Node's lookup semantics (require bindings, excluded or
directory-named manifests). Only extensions now select a mode: `.mjs`
and `.mts` parse as modules and `.cjs` as scripts. Every other source
keeps an unknown mode, so module-only strict errors stay visible as an
entry limitation instead of being dropped or asserted. This matches the
require-binding analysis, which also treats unmarked paths as unknown.

@baron baron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head a4ff51b against current main, including parsed-owner/consumer boundaries and directly related cleanup. No confirmed source blocker.

The parser preserves explicit module strictness and unknown runtime mode instead of treating recovered sloppy syntax as proved runtime configuration. PHP/C# classification and nearest-enclosing Git facts preserve source values and unknown dirty state. CLI provenance carries the package version. No further structural repair or test pruning was justified.

Pinned Node 24.18.0/npm 11.16.0 current-main integration: 9 focused files passed (41 tests passed, 2 Windows-only skips), 8 direct producer/parser witnesses passed, and uncached check:fast passed. The compiled public import workflow was exercised on inert source; source was not executed. Exact-head hosted CI is green; final object-only merge is clean. No real provider operations were performed or claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants