Skip to content

fix(javascript): preserve TypeScript resolution modes and native type erasure - #2060

Closed
xu91102 wants to merge 48 commits into
morluto:mainfrom
xu91102:fix/cts-static-module-lookup
Closed

xu91102 wants to merge 48 commits into
morluto:mainfrom
xu91102:fix/cts-static-module-lookup

Conversation

@xu91102

@xu91102 xu91102 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

TypeScript and checked-JavaScript erased module requests could disappear, select the wrong loader, or appear as runtime native exports. Preserve parser-owned requests, loader choice, source provenance and uncertainty through the owned worker and existing CLI/stdio MCP workflows.

Fixes #2056

  • Retain CTS/MTS import-equals, type re-exports, inline import types and JSDoc requests, including declaration erasure, explicit/omitted/unknown modes, original ranges/digests/member selections and origin modes. Only explicit type_only:false creates runtime native nodes, relationships and totals; erased and legacy-unclassified facts stay on their source asset.
  • Integrate main 7d1e4d0e2bfb77bd47203b4f962e4f034678dc75 and resolve four real source conflicts. Static consumers use upstream's one definitions pass before ambient writes; loader mode moves to the remaining third parameter. Explicit JavaScript extensions use JavaScript grammar, while detached JSDoc requests keep their TypeScript parser and separate metadata. Preserve upstream IPC deduplication and prior CommonJS lifetime/configuration-uncertainty fixes. No parallel compiled workflow, provider/schema/authority/deadline change or related cleanup deferred.
  • Tilde-fenced @import exclusion follows this PR's Markdown-example contract; TypeScript7 itself can process the directive and emit TS2307. Static syntax does not verify native binary exports.

Final head: bb04220.

Final-byte macOS arm64 / Node24.18 / npm11.16 validation:

  • Fresh170 relevant files /2914 tests PASS, no skips. The initial160-file selection omitted the complete module-lookup/owned-worker and core mode suites; all10 missing files /353 tests then ran and passed on the same frozen bytes. Includes existing real TS7/Node controls, compiled CLI/stdio MCP, owned workers, cancellation and failure controls. No old test evidence substitutes for these runs.
  • Six static-check tasks plus module/architecture guards PASS (0 errors/1433 warnings); six documentation tasks plus5 conformance tests PASS; discovery1300 files exactlyonce PASS. Fresh independent Standards and Spec PASS.
  • Three extension scenarios combining conditional-arrow JavaScript, comparison syntax, JSDoc type aliases matching a runtime receiver and native/IPC facts pass through both actual CLI and stdio MCP, with source SHA/ranges and complete adapter parity. Node --check confirms syntax; this probe does not execute native dependencies. SDK closes are awaited, without proving OS process-family quiescence.
  • Four fresh completed CLI cost observations retain the same two immutable inputs/lock and business reads as four historical 090d observations. Full normalized output equality failed because accepted upstream owners replace container-dependent module metadata with source SHA and add boundary field; all such deltas are documented, with remaining payload values unchanged. Median elapsed1.117/1.143s, CPU1.31/1.375s; sampled family peaks505120–507344/503824–514000KiB. Historical timing, uncontrolled cache/load, estimated RSS and unmeasured tokens prevent isolated-cost or speedup claims. Entry-file hashes do not establish full runtime-tree equality.

Normal hooks, commit/push and frozen-byte checks: PASS; final contribution/integration patches and all3850 raw tracked inputs match the reviewed freeze byte for byte. CI for bb04220: CI38668257089 completed SUCCESS. Its complete 2,297,295-byte log and all30 final jobs were read:16 success/14 conditional skips. Portable aggregate15062 PASS/129 skips combines source and shards; it is not an extra independent suite. GitHub tested synthetic83fae2685717231a26799efd25bae78b75367a36, with parents main d69acc3 and this final PR head. Windows controls build passed; the Windows execution lane was skipped, so this is not actual Windows runtime verification. Previous 090d CI38625304403 is historical SUCCESS and does not establish new-head CI. Local full Windows/Linux, actual native engines and installed Electron were NOT RUN. Local review, remote automated review, CI and human readiness remain separate.

Author readiness

Human owner: @xu91102. Keep Draft; human declarations remain unchecked.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-13T23:18:43.771769Z 3123c03 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.

@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: b6621b3b5e

ℹ️ 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".

@xu91102 xu91102 changed the title fix(javascript): resolve CTS static imports with CommonJS semantics fix(javascript): retain explicit TypeScript import resolution modes Oct 12, 2026

@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: ae71496c84

ℹ️ 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 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: adf8526842

ℹ️ 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 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: 43412f2ba1

ℹ️ 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 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: 9340559a58

ℹ️ 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5 Tier: apex

[High impact] Refactors TypeScript type erasure and module resolution across the JavaScript analysis engine.

Fix the missed instance-field overwrites before merging; the documentation-example issue is non-blocking.

Findings

  1. P1 Instance-field writes disappear ▶
  2. P2 Examples become type requests ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/javascriptSemanticAmbientWrites.ts:130-132
In `let target = {}; class Patch { value = (target.URL = replacement); } target = globalThis; new Patch();`, the new `semanticReadInitializers` lookup chooses the value before the class declaration, not before the instance is created. It drops `globalThis`, so the overwrite of `URL` is missed. A later `new Worker(new URL("./worker.js", import.meta.url))` can then get a definite file target despite using a replaced `URL`.

Keep all possible alias values when the read sits inside an instance-field initializer.

### Issue 2
src/domain/javascript/javascriptSourceParser.ts:105-113
A JSDoc example fenced with `~~~js` is read as a real `@import`. Only backticks set `codeTicks`, so an `@import { NativeMode } from "./addon.node"` inside a tilde fence reaches the normal declaration consumers. CLI and MCP graphs then publish a source-owned native type observation and increase `type_relationships` for documentation code.

Track tilde fences as well as backtick fences, and add this case to the negative fixture.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

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

Summary

Preserves TypeScript loader modes and erased requests across the parser, worker, and public graphs. Adds source-owned JSDoc type requests without runtime native exports.

  • TypeScript type requests keep their loader modes and selected members.
  • JSDoc @import tags appear as erased type requests.
  • Only explicit runtime native requests create native-export graph entries.
  • Analysis keeps escaped values and small graph details intact.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  S["Source"] --> P["Shared parser"]
  P --> A["Runtime AST"]
  P --> J["Erased JSDoc declarations"]
  A --> F["Static and semantic facts"]
  J --> F
  F --> W["Strict worker transport"]
  W --> G["CLI / MCP graph"]
  G --> N{"Native finding: type_only is false?"}
  N -- Yes --> R["Native nodes, edges and totals"]
  N -- No --> O["Source-owned observations"]
Loading

Reviews (22) · Last reviewed commit: "merge: retain TypeScript source facts ac..." · Reviewed by Greptile

@xu91102 xu91102 changed the title fix(javascript): retain explicit TypeScript import resolution modes fix(javascript): preserve TypeScript resolution modes and native type erasure Oct 13, 2026

@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: e02906dac8

ℹ️ 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 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: 24c403c6d4

ℹ️ 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 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: 704b03b97a

ℹ️ 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 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: 02ae0a439d

ℹ️ 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 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: 1584dc0033

ℹ️ 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 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: 3123c0346d

ℹ️ 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@xu91102
xu91102 marked this pull request as draft October 14, 2026 08:16
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Superseded by the delivered change on main: e4532b537. Current loader/type-dependency ownership preserves .cts/.mts resolution modes and type erasure; related fixes 1b95302, c923fb0 and 86fab11 are also on main with public module-lookup coverage. Closing this earlier proposal. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281.

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @xu91102 for investigating TypeScript loader and type-erasure gaps in the JavaScript workflow. Main has the loader corrections, with the later parsing fixes owned by the shared source parser.

@krxna2005-dot krxna2005-dot 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.

Chnges

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

Labels

area: domain Domain logic, errors, and pure functions area: server Server layer and tool wiring bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] CTS static imports use ESM lookup despite NodeNext CommonJS emission

3 participants