Documentation

Docs / Reference

ADR 0070 - TypeScript, TSX and JavaScript structural claim contract: files, declarations, imports

Status: Accepted (delegated review, 2026-11-18)

Context

T020 (ADR 0066) labels a language's structural scope (files, declarations, imports) precise only through a rule-table row whose evidence includes a claim contract with a 1:1 test, goldens, corpus checks, an oracle where cheap and an independent review. The T020 investigation (the T020 task record (internal)) inventoried every TypeScript, TSX and JavaScript form the extractor (internal/lang/typescript) emits and compared it with an oracle built on the TypeScript compiler API (scripts/oracle/ts_structure/oracle.cjs, typescript@6.0.3) on sixteen corpora and the self-index.

Declarations agreed on 99.0 % of the compared facts, but main stated wrong facts in ten classes (precision stops PS-S3-1..PS-S3-10): default.* nodes and exported flags propagated through export default <expr> (D-1, 186 rows), methods read from type literals (D-2), the tree-sitter misparse of => tag<T>...`` (D-3), declarations recovered in files tree-sitter rejects (D-4, 355 wrong and 775 missing), decorators lost across a comment (D-6) and variables named by a binding pattern (D-7). Imports were worse: main's resolver was a best-effort order of its own (ADR 0014), so 812 imports edges named a file the compiler does not resolve: paths of a configuration that does not govern the file (I-3, 152), a src/index guess for unbuilt workspace entries (I-2, 642), every named package.json taken as a workspace package (I-4), implementations where the compiler takes a declaration file (I-1, 14), ESM-mode relative specifiers (I-5), and 262 externals whose name is no npm package (I-8).

Options considered

  1. Patch main's resolver at each stop: keep ADR 0014's order and add the governing configuration, members only, and refusals. Every class of the inventory is a place where main's order is not the compiler's; the next corpus would find the next one.
  2. Transcribe the compiler's resolution (configuration reading, program membership, moduleNameResolver.ts for node10, node16, nodenext and bundler) in Go over the scanned inventory, refuse what it does not model, and let the compiler oracle check it. Chosen.
  3. Run the compiler (Node and typescript) as an external indexer. Precise, but a runtime dependency the indexer does not have; it remains the oracle only.

Decision

Option 2, with the developer's decisions on the open points (2026-11-17, before S3B): O-S3-1 (a), O-S3-2 (c), O-S3-3 (refuse, except the compiler's own output mapping proven by the member's tsconfig), O-S3-4 (a), O-S3-5 (a), O-S3-6 (a), O-S3-7 (a), O-S3-8 (a). The contract is docs/lang/typescript-structure.md, rows TS-C1..TS-C3, TS-F1..TS-F3, TS-D1..TS-D12, TS-I1..TS-I7 and the default branch D, mirrored by structureRows (internal/lang/typescript/structure.go).

No rule-table row is added and no label changes: PL-L3 follows the independent review.

What the oracle shares with the extractor

The oracle parses with the compiler, resolves with ts.resolveModuleName, reads configurations with getParsedCommandLineOfConfigFile and computes outputs with ts.getOutputFileNames, over the raw bytes and the filesystem; it uses no Graphvein code. It still shares, by definition of the contract:

What it does not compare: calls, export bindings, routes, model facts; require() and dynamic import() targets; the default-branch counts; packages under a real node_modules (none on disk); symlinked directories (the scanner skips them; the compiler would follow them).

Consequences

Known gaps

Review fixes (S3R)

The independent review (the T020 task record (internal), head 5fc1fb3) found one class A and five class B findings. Each is fixed as a class rule; the contract table, structureRows and TestTypeScriptStructureContract stay 1:1, and every fix has a fixture case or test that fails when the fix is reverted (mutation-checked). The extractor version stays extractors-41 (2026-11-17 assigns 41 to TypeScript, 40 to Python, 42 to Rust).

Results

Oracle (oracle.cjs with the S3F expectation for TS-I5, TypeScript 6.0.3) on the branch binary, what was compared as in S3B; "undeclared / paths" are the sites the new TS-I5 refusals take:

corpus TS/JS files declarations agree / claimed import sites claims agree no claim undeclared / paths claimed disagreements
fixture 71 111 / 111 63 39 24 4 / 2 0
hoppscotch 1179 6550 / 6550 5849 5244 605 43 / 129 0
aqualink-app 787 2639 / 2639 4498 4452 46 2 / 0 0
kaneo 4562 11770 / 11770 20508 19649 859 162 / 0 0
opencollective-api 2187 7082 / 7082 11513 11485 28 4 / 0 0
react 73 184 / 184 240 198 42 0 / 42 0
umami 1393 3713 / 3713 6078 6034 44 0 / 31 0
dokploy 1124 4800 / 4800 8347 8333 14 0 / 0 0
self 869 3657 / 3657 2175 2083 92 37 / 15 0

The review's A1 cases: hoppscotch's 39 npm:src edges (baseUrl into the git-ignored src/generated/), 4 npm:@app/api, 2 npm:@helpers/backend and 1 npm:unfonts.css, and aqualink-app's npm:sites and npm:regions are gone (refused); the oracle now expects the refusal from its own reading. The other 9 corpora of the review were not re-run.

Snapshot diff against S3B (what the fixes changed): A1 removes externals (hoppscotch 47 imports edges, kaneo 159, aqualink-app 2, opencollective-api 4); B3 restores the family facts S3B lost: opencollective-api the PaymentMethod table (27 columns), its 131 foreign_key edges and the complete state and claims of the 47 other tables (column foreign_keys 697, nullable 245): table, column and edge records identical to main; kaneo 100 reads_table/writes_table edges (identical to main except 39 that main sourced from declarations of rejected files, now 22 file-owned edges, merged per table); hoppscotch 3 ipc_call nodes (file-owned). B4 restores react's 27 client_call nodes and 27 calls_operation edges (identical to main).

Snapshot diff against main (extractors-39), per class, beyond S3B's table above: no model, table, column, foreign_key, calls_operation, client_call or Angular record differs on these corpora except the re-anchoring of B3 (hoppscotch 12 client_call and 3 ipc_call contains edges from the file node instead of a withheld function; kaneo the 39 table edges above) and on self the Angular proofs of files that import @angular/core without a declaring package.json (spike/parsing/samples, the shadow fixture: angular_decorator_unproven 1 to 8, one uses_template edge less). Externals removed by A1 against main: hoppscotch 116 imports edges (10 nodes), kaneo 559 (26; the config_unread sites of S3B included), umami 37, dokploy 60, react 27, aqualink-app 7, opencollective-api 13, self 45.

Corpus results

Oracle (oracle.cjs, TypeScript 6.0.3, branch binary extractors-41): what was compared is file nodes (span, hash), every declaration Graphvein emits (kind, identity, name, qualified name, span, hash, exported, default_export, decorators, contains edge) against the compiler AST under the contract's naming and span rules, and every import site (statement span; edge target or external against the contract's expected outcome from ts.resolveModuleName). "No claim" sites are those where Graphvein claims nothing (refused or unresolved).

corpus TS/JS files declarations agree / claimed compiler-only declarations import sites claims agree no claim claimed disagreements
fixture 66 108 / 108 1 (misparse) 52 33 19 0
hoppscotch 1179 6550 / 6550 0 5849 5291 558 0
maintainerr 900 5261 / 5261 0 4510 4510 0 0
kaneo 4562 11770 / 11770 0 20508 19811 697 0
dokploy 1124 4800 / 4800 0 8347 8333 14 0
umami 1393 3708 / 3708 0 6078 6034 44 0
seerr 637 2304 / 2304 0 4392 4385 7 0
opencollective-api 2187 7082 / 7082 19 (misparse) 11513 11489 24 0
gladys 3671 5561 / 5561 0 1238 1238 0 0

(Declarations and sites of files tree-sitter rejects are not counted above: the oracle expects nothing there.)

Cost of TS-F2 (files tree-sitter rejects, declarations the compiler reads in them): hoppscotch 4 files / 113, maintainerr 4 / 12, kaneo 55 / 165, dokploy 23 / 71, umami 3 / 0, seerr 0, opencollective-api 4 / 16, gladys 640 / 1964 (its Preact front end: class= attributes). Known gap pointer: ADR 0074 (Proposed, T020-TSG) patches the JavaScript, TypeScript and TSX grammars for keyword JSX attribute names, a bare & in JSX and export type *, recovering 659 of these files; the forms it does not cover stay TS-F2 (the T020 task record (internal)).

Under-claims worth a follow-up: kaneo's apps/mobile extends expo/tsconfig.base (not in the repository), so 690 sites go to config_unread; hoppscotch's @hoppscotch/data and @hoppscotch/kernel are built by vite with declarations from a tsconfig.decl.json, so 289 sites are workspace_entry_missing; aliases such as ~icons and @/generated (hoppscotch 227, umami 31) are not_a_package.

Snapshot diff against main (extractors-39), per class:

corpus declarations removed (TS-F2 / other classes) declaration facts changed (flags, span, decorators) imports edges removed (TS-F2 / refused / other) edges added or retargeted
hoppscotch 127 / 48 (PS-S3-1 17, PS-S3-2 12, namespace members 19) 72 (71 exported/default_export PS-S3-1, 1 decorators PS-S3-10) + 1 span (D-5 convention unchanged, ambient) 18 / 516 (workspace_entry_missing 289, not_a_package 227, of which 101 were I-3 edges) / 4 (declare module sites) 0
maintainerr 12 / 7 (PS-S3-2 5, PS-S3-1 1, namespace 1) 0 35 / 0 / 0 0
kaneo 165 / 26 (PS-S3-1 15, namespace 8, PS-S3-2 3) 0 369 / 690 (config_unread: apps/mobile extends expo/tsconfig.base) / 1 12 (I-3: the compiler's governing configuration)
dokploy 71 / 5 (PS-S3-9 2, namespace 2, PS-S3-1 1) 0 131 / 1 / 0 0
umami 0 / 12 (namespace 9, PS-S3-1 2, PS-S3-2 1) 4 (PS-S3-1) 15 / 41 (not_a_package 31, workspace_entry_missing 10) / 0 0
seerr 0 / 7 (namespace) 1 (PS-S3-1) 0 / 6 (config_unread) / 0 0
opencollective-api 16 / 43 (PS-S3-1 36, misparse 7) 23 (PS-S3-1) + 9 renamed owners (PS-S3-1) 36 / 0 / 0 1 (config now the npm external the compiler takes)
gladys 1510 / 1 (PS-S3-1) 0 3888 / 0 / 0 0
self 39 / 13 (namespace 8, PS-S3-2 2, PS-S3-9 2, PS-S3-1 1) 3 (PS-S3-1 2, PS-S3-10 1) 24 / 33 (fixture refusals: not_a_package, declaration_or_implementation, workspace_entry_missing, unlinked_package, ESM-mode) / 1 5 (fixture cases the compiler resolves: paths through references, an exports pattern, pkg-b's root index.ts)

Every changed class is an intended one: no claim remains that the oracle does not confirm. calls edges and route handlers that bound through a refused import, and the new ts_structure_unread diagnostics, change with them (not tabulated).

Review notes

Corpus and oracle results. What oracle.cjs (TypeScript 6.0.3 compiler API over the raw bytes) compares is described under "Corpus results ": file nodes, every declaration Graphvein emits and every import site against the contract's expected outcome; sites where Graphvein claims nothing are counted, not compared. It does not compare calls edges (row D) or the family facts (models, table access, clients, routes, Angular, Tauri), which have their own contracts and oracles.

corpus TS/JS files declarations agree / claimed import sites claims agree files precise / best_effort (TS-F2, TS-F3)
seerr 637 2304 / 2304 4392 4385 637 / 0
nest-admin 242 990 / 990 1210 1192 242 / 0
opencollective-api 2187 7082 / 7082 11513 11485 2183 / 4
gladys 3671 5561 / 5561 1238 1236 3031 / 640
umami 1393 3713 / 3713 6078 6034 1390 / 3
dokploy 1124 4800 / 4800 8347 8333 1101 / 23
kaneo 4562 11770 / 11770 20508 19649 4507 / 55
react 73 184 / 184 240 198 73 / 0
hoppscotch 1179 6550 / 6550 5849 5244 1175 / 4
angular 50 126 / 126 270 255 50 / 0
angular-ngmodule 67 161 / 161 244 243 67 / 0
kftray 180 601 / 601 855 854 179 / 1
express 357 742 / 742 888 886 357 / 0
realworld 26 63 / 63 76 50 26 / 0
maintainerr 900 5261 / 5261 4510 4491 895 / 5
aqualink-app 787 2639 / 2639 4498 4452 785 / 2
localsend 0 0 / 0 0 0 0 / 0
self 869 3657 / 3657 2175 2083 861 / 8

Unread options (S3F open point 1, decided (b) in S3L): a file whose governing tsconfig.json extends a package outside the checkout keeps its bare imports refused (config_unread, no imports edge); family consumers (TypeORM, Sequelize, Drizzle, and every consumer of the export bindings: clients, routes, Angular, Tauri, table access) read such a specifier as the package exactly when rule (ii) of TS-I5 holds for its package name and no workspace link or scanned package.json name carries it (ModuleResolution.DeclaredPackage, Package). Node built-ins are not included. Tests TestUnreadDeclaredPackages, TypeORM TestDiscoverCompilerFlags ("package extends" restored), Sequelize TestDiscoverUnreadConfig.

Review notes (S3R, pending acceptance)

Independent review (the T020 task record (internal), on 5fc1fb3). Verdict, verbatim: "The PL-L3 flip is blocked by one class A finding (A1). Row TS-I5 claims "the file imports an npm package of this name that is not in the repository" for every bare specifier the compiler does not resolve over the scanned inventory whose first segment looks like an npm name." The review found every other claim confirmed by its own probes and corpus runs (60 generated projects, 17 corpora).

Fixes (c98a29b), verbatim from "Review fixes" above: "The independent review [...] found one class A and five class B findings. Each is fixed as a class rule; the contract table, structureRows and TestTypeScriptStructureContract stay 1:1, and every fix has a fixture case or test that fails when the fix is reverted (mutation-checked)." A1 (TS-I5's declared-package rule, applied to the resolution itself, with the oracle no longer sharing it), B1-B5 as listed there. No class A finding is open. The class C items are known gaps above.

Flip (extractors-41): row PL-L3 of docs/extract/precision.md labels TypeScript, TSX and JavaScript files precise (declaration and test files included); calls stay row D (code_calls). A file whose structure claims nothing (tree-sitter rejects it, TS-F2; not parsed or not extracted, TS-F3; or dropped by validation) is stored best_effort, served with reason structure_refused. The oracle TestTypeScriptStructureOracle is opt-in (it skips without GRAPHVEIN_TS_ORACLE_DIR), so it does not run in CI. This section stays pending until the developer accepts the review record; Status stays Proposed.

Review notes (acceptance, 2026-11-18)

Accepted after delegated review (2026-11-17). Steps: the investigation (the T020 task record (internal)), S3B implementation, one independent review (the T020 task record (internal): one class A, five class B, class C items), S3F fixes (A1 and B1-B5 fixed as class rules and mutation-checked; class C items are known gaps above), S3L (config_unread declared-package rule for family consumers, row PL-L3, label flip), S3I (merge with the Python structure stack).

Report a problem with this pageSource: docs/adr/0070-typescript-structure-contract.md