reading-stone 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +11 -0
  3. package/README.md +274 -2
  4. package/dist/analysis.d.ts +341 -0
  5. package/dist/analysis.js +392 -0
  6. package/dist/cognitive.d.ts +163 -0
  7. package/dist/cognitive.js +380 -0
  8. package/dist/complexity.d.ts +102 -0
  9. package/dist/complexity.js +163 -0
  10. package/dist/coverage.d.ts +78 -0
  11. package/dist/coverage.js +635 -0
  12. package/dist/detector.d.ts +41 -0
  13. package/dist/detector.js +2134 -0
  14. package/dist/discovery.d.ts +330 -0
  15. package/dist/discovery.js +930 -0
  16. package/dist/doc-coverage.d.ts +155 -0
  17. package/dist/doc-coverage.js +543 -0
  18. package/dist/extract.d.ts +209 -0
  19. package/dist/extract.js +498 -0
  20. package/dist/index.d.ts +64 -0
  21. package/dist/index.js +54 -0
  22. package/dist/internal.d.ts +75 -0
  23. package/dist/internal.js +63 -0
  24. package/dist/main.d.ts +8 -0
  25. package/dist/main.js +39 -0
  26. package/dist/models.d.ts +185 -0
  27. package/dist/models.js +170 -0
  28. package/dist/program.d.ts +207 -0
  29. package/dist/program.js +662 -0
  30. package/dist/protocol.d.ts +88 -0
  31. package/dist/protocol.js +74 -0
  32. package/dist/quality/assertions.d.ts +81 -0
  33. package/dist/quality/assertions.js +425 -0
  34. package/dist/quality/collect.d.ts +66 -0
  35. package/dist/quality/collect.js +412 -0
  36. package/dist/quality/inference.d.ts +86 -0
  37. package/dist/quality/inference.js +603 -0
  38. package/dist/quality/matchers.d.ts +129 -0
  39. package/dist/quality/matchers.js +220 -0
  40. package/dist/quality/pairing.d.ts +133 -0
  41. package/dist/quality/pairing.js +770 -0
  42. package/dist/quality/pipeline.d.ts +59 -0
  43. package/dist/quality/pipeline.js +202 -0
  44. package/dist/quality/types.d.ts +127 -0
  45. package/dist/quality/types.js +92 -0
  46. package/dist/safeio.d.ts +107 -0
  47. package/dist/safeio.js +314 -0
  48. package/dist/server.d.ts +19 -0
  49. package/dist/server.js +451 -0
  50. package/dist/signals/adapter.d.ts +103 -0
  51. package/dist/signals/adapter.js +323 -0
  52. package/dist/signals/caller-index.d.ts +117 -0
  53. package/dist/signals/caller-index.js +147 -0
  54. package/dist/signals/caller.d.ts +76 -0
  55. package/dist/signals/caller.js +108 -0
  56. package/dist/signals/evidence.d.ts +233 -0
  57. package/dist/signals/evidence.js +578 -0
  58. package/dist/signals/interface.d.ts +68 -0
  59. package/dist/signals/interface.js +87 -0
  60. package/dist/signals/jsdoc.d.ts +27 -0
  61. package/dist/signals/jsdoc.js +233 -0
  62. package/dist/signals/naming.d.ts +26 -0
  63. package/dist/signals/naming.js +160 -0
  64. package/dist/signals/routing.d.ts +163 -0
  65. package/dist/signals/routing.js +416 -0
  66. package/dist/signals/types.d.ts +146 -0
  67. package/dist/signals/types.js +99 -0
  68. package/dist/signals/visibility.d.ts +23 -0
  69. package/dist/signals/visibility.js +82 -0
  70. package/dist/taxonomy.d.ts +89 -0
  71. package/dist/taxonomy.js +217 -0
  72. package/package.json +61 -4
@@ -0,0 +1,207 @@
1
+ import type { Writable } from "node:stream";
2
+ import { type SourceFile } from "typescript/unstable/ast";
3
+ import { type Checker, type Symbol as CompilerSymbol, type Program } from "typescript/unstable/sync";
4
+ /**
5
+ * The bootstrapped TypeScript analysis context — the foundation the
6
+ * detector and complexity engine build on (FR-003 through FR-006; research
7
+ * R1, R2, R3, R15; data-model.md ProgramContext; Constitution Principles
8
+ * III and V). `buildProgramContext` turns the analysis pipeline's pre-read
9
+ * in-scope sources into one of two contexts — mode `"program"` (a compiler
10
+ * program plus its live type checker, built from the project's own
11
+ * tsconfig) or mode `"parse-only"` (one parsed source per in-scope file).
12
+ * The union is internal: it never appears on the wire.
13
+ *
14
+ * API-surface design record (typescript 7.0.2, the native compiler): the
15
+ * classic API named in research R1/R2 (`ts.createProgram`,
16
+ * `ts.createSourceFile`, a wrapped `CompilerHost`) does not exist in the
17
+ * promoted runtime dependency — its main export carries only version
18
+ * metadata. The equivalent verified surface is:
19
+ *
20
+ * - `typescript/unstable/sync` — the `API` client, spawned with filesystem
21
+ * delegation callbacks (`new API({ cwd, fs })`). Those callbacks are the
22
+ * bounded-compiler-host equivalent: every compiler read funnels through
23
+ * them, so the hermetic views below bound what the compiler can touch.
24
+ * - `API.updateSnapshot({ openFiles })` — the parse-only route: with no
25
+ * tsconfig visible, the compiler loads every opened file into its
26
+ * inferred project and answers a parsed `SourceFile` per path.
27
+ * - `API.updateSnapshot({ openProjects })` — the program-mode route: the
28
+ * native server builds a configured project for a config path served
29
+ * through the fs callbacks, so a synthesized config IS the classic
30
+ * `ts.createProgram(rootNames, options, host)` statement.
31
+ * - `Program`/`Checker` — the program-mode arm's types: `Program` answers
32
+ * `getCompilerOptions`/`getSourceFile`/`getSourceFileNames`/
33
+ * `getConfigFileParsingDiagnostics`, `Checker` the type queries.
34
+ * - `typescript/unstable/ast` — `SourceFile` and `ScriptKind`: the parsed
35
+ * sources this module returns and the enum the extension map enforces.
36
+ *
37
+ * The program-mode contract (FR-003, FR-005; research R1, R3), as the
38
+ * classic vocabulary maps onto that surface:
39
+ *
40
+ * 1. **The extender config is the rootNames override.** The host serves a
41
+ * virtual config — `<root>/.reading-stone-tsconfig.json`, a path that
42
+ * never touches disk — that `extends` the project's own tsconfig,
43
+ * lists exactly the in-scope roots in `files`, and empties `include`
44
+ * and `references`. tsconfig extends replaces top-level fields rather
45
+ * than merging them (verified against 7.0.2), so the project's own
46
+ * include/files/references can never widen or narrow the root set:
47
+ * FR-003's every-in-scope-file-covered holds regardless of the
48
+ * project's include/exclude patterns. The virtual path is a sibling
49
+ * of the real tsconfig (not nested in a subdirectory) so the
50
+ * `extends` target and every base-relative path resolve against the
51
+ * same directory the project's own config lives in.
52
+ * 2. **Forced options ride the extends merge.** The extender's
53
+ * `compilerOptions` — `noEmit: true`, `incremental: false`,
54
+ * `composite: false`, `skipLibCheck: true`, `allowJs: true`,
55
+ * `checkJs: false` — win over the project's own values; everything
56
+ * else (paths, baseUrl, strict, target, module resolution) flows
57
+ * verbatim through the extends chain, which the compiler parses
58
+ * natively — comments included, so real-world JSONC configs keep their
59
+ * type information instead of degrading to parse-only under an
60
+ * analyzer-side JSON re-parse. The classic `tsBuildInfoFile:
61
+ * undefined` adjustment has no JSON spelling ("unset" cannot be
62
+ * expressed through extends), so the bootstrap clears it on the
63
+ * parsed options object after the build — inert either way, with emit
64
+ * and incremental state force-disabled in the server's merged options
65
+ * too.
66
+ * 3. **The bounded compiler host** (Constitution V) routes every compiler
67
+ * read: the two config texts and the in-scope pre-read texts come from
68
+ * memory; reads under the typescript package's own platform lib
69
+ * directory are bounded but exempt from root containment (the
70
+ * analyzer's dependency, not analyzed-tree content); any other in-root
71
+ * path is probed with lstat — never followed — and, when present,
72
+ * read through `readBoundedSync`, so skipped transitive files resolve
73
+ * as absent modules → `any` types → FR-017 ambiguity: graceful
74
+ * degradation, never a crash; every other compiler-resolved path
75
+ * outside the analysis root does not exist, with one diagnostic.
76
+ * Out-of-root existence probes answer false, so module resolution
77
+ * cannot walk past the analyzed tree.
78
+ * 4. **The config-error boundary** (research R3): the extends chain
79
+ * propagates the project config's parse errors into the extender
80
+ * project's config diagnostics (verified) — that is where the
81
+ * fallback decision reads them. The no-inputs family — TS18002 (the
82
+ * files list is empty) and TS18003 (include matched nothing) — cannot
83
+ * affect a bootstrap whose root set is its own, so it never triggers
84
+ * fallback; every other error-category diagnostic does. Semantic and
85
+ * syntactic diagnostics are never a gate (FR-005): type errors
86
+ * surface as error types the ambiguity rules handle.
87
+ * 5. **Resource closure and disposal**: parse-only sources are
88
+ * self-contained client-side binary views — lazy node materialization
89
+ * reads only the decoded buffer, never the compiler client — so that
90
+ * path closes the API client (and the native server behind it) before
91
+ * returning. Program mode cannot: `Checker`/`Program` calls
92
+ * round-trip to the live server, so the program arm carries
93
+ * `dispose()` — the consumer that drops the context closes the
94
+ * subprocess, and an idempotent guard makes double disposal safe. No
95
+ * native server outlives its consumer.
96
+ *
97
+ * The parse-only path's contract (research R2):
98
+ *
99
+ * 1. **Hermetic compiler view**: the filesystem callbacks expose ONLY the
100
+ * pre-read in-scope sources — every other path (including any on-disk
101
+ * tsconfig) does not exist. Unknown paths answer `null`/`false`, never
102
+ * `undefined`: `undefined` is the fall-back-to-the-real-filesystem
103
+ * signal, and falling back would hand the compiler unbounded reads of
104
+ * untrusted tree content (Constitution V). The view is also why this
105
+ * path needs no tsconfig logic of its own: with nothing visible, every
106
+ * opened file lands in the compiler's single inferred project.
107
+ * 2. **Explicit extension map**: `.ts`→TS, `.tsx`→TSX, `.js`/`.mjs`/`.cjs`
108
+ * →JS, `.jsx`→JSX — the same six extensions discovery walks,
109
+ * case-sensitively. The map is enforced, not advisory: a parsed source
110
+ * whose script kind does not match the mapped kind is skipped with one
111
+ * diagnostic. A silently different kind would mis-shape every
112
+ * downstream rule that keys off script-kind semantics, and a diagnosed
113
+ * skip is Principle II's acknowledged-uncertainty pattern; the
114
+ * enforcement never fires on typescript 7.0.2 (verified) and exists to
115
+ * catch compiler drift loudly instead.
116
+ * 3. **Skip semantics** mirror safeio's: a `null` pre-read text excludes
117
+ * the file (its diagnostic was already written by `readBounded`); a
118
+ * `RangeError` escaping source-file fetch/decode on pathological
119
+ * nesting is caught and treated as the same skip-with-one-diagnostic
120
+ * (research R15); parse diagnostics are ignored — the parser is
121
+ * error-tolerant and a file is never dropped for failing to parse.
122
+ */
123
+ /**
124
+ * One in-scope source as the analysis pipeline pre-read it: the
125
+ * root-relative POSIX path and the `readBounded` result verbatim. `text` is
126
+ * `null` exactly when the bounded read skipped the file — its diagnostic
127
+ * was already written, so `null` excludes the file from the bootstrap
128
+ * silently (never a second diagnostic for one skip).
129
+ */
130
+ export type PreReadSource = readonly [relPath: string, text: string | null];
131
+ /**
132
+ * The analysis context `buildProgramContext` produces (data-model.md
133
+ * ProgramContext; internal — not protocol-visible).
134
+ *
135
+ * - `"program"`: a compiler program built from a usable root tsconfig plus
136
+ * its live type checker. `Program`/`Checker` calls round-trip to the
137
+ * native compiler server, so the arm carries `dispose()`: the consumer
138
+ * that drops the context closes that server — no subprocess outlives its
139
+ * consumer (the analysis methods that own a context's lifetime are the
140
+ * Phase 4/5 pipeline entry points).
141
+ * - `"parse-only"`: one parsed source per in-scope file, keyed by
142
+ * root-relative POSIX path, for trees with no usable tsconfig. The
143
+ * fallback is never an error and is invisible on the wire. The sources
144
+ * are self-contained client-side binary views, so this arm owns nothing
145
+ * to dispose.
146
+ */
147
+ export type ProgramContext = {
148
+ mode: "program";
149
+ program: Program;
150
+ checker: Checker;
151
+ /**
152
+ * Closes the native compiler server behind the program and checker
153
+ * (idempotent); the context is unusable afterwards.
154
+ */
155
+ dispose(): void;
156
+ } | {
157
+ mode: "parse-only";
158
+ sources: ReadonlyMap<string, SourceFile>;
159
+ };
160
+ /**
161
+ * Resolves a checker-returned symbol to the symbol its references name,
162
+ * following import and re-export aliases to the declaring symbol — the
163
+ * shared checker-safety primitive for declaration matching (spec 004's
164
+ * pairing strategies; Constitution Principle III's price on the unstable
165
+ * surface).
166
+ *
167
+ * `Checker.getAliasedSymbol` PANICS the native compiler server when handed
168
+ * a non-alias argument ("Should only get alias here", verified against
169
+ * 7.0.2 — the src/signals/evidence.ts module header records the same
170
+ * hazard for its single-hop heritage route), so the Alias-flag gate below
171
+ * is a safety requirement, not a stylistic choice. Alias chains (a barrel
172
+ * re-exporting another barrel) resolve hop by hop, bounded by
173
+ * `ALIAS_HOP_LIMIT` — beyond the bound the symbol is treated as unresolved
174
+ * (absence of evidence, never an error). The checker's unknown symbol (an
175
+ * alias whose target cannot be resolved — a name imported from a missing
176
+ * module) identifies nothing and returns null the same way.
177
+ *
178
+ * @param checker The live program-mode type checker.
179
+ * @param symbol The symbol a reference or import specifier resolved to, or
180
+ * undefined when it resolved nowhere.
181
+ * @returns The referenced symbol with aliases followed, or null when
182
+ * nothing resolvable backs the reference.
183
+ */
184
+ export declare function resolveSymbolAliases(checker: Checker, symbol: CompilerSymbol | undefined): CompilerSymbol | null;
185
+ /**
186
+ * Bootstraps the analysis context from the analyzed tree's own pre-read
187
+ * sources (FR-003 through FR-006; research R1, R2, R3).
188
+ *
189
+ * Mode selection: a usable root `tsconfig.json` drives the program arm —
190
+ * the extender-config route and bounded compiler host documented in the
191
+ * module header. Anything else — no tsconfig, an unreadable one, or a
192
+ * config error beyond the no-inputs family (research R3) — falls back to
193
+ * the parse-only arm: one parsed source per in-scope file, keyed by
194
+ * root-relative path, with the absolute `fileName` and pre-read `text`
195
+ * preserved. A tree with no usable in-scope sources bootstraps an empty
196
+ * parse-only context without spawning the compiler at all.
197
+ *
198
+ * @param realRoot Realpath-resolved absolute analysis root (discovery's
199
+ * `resolveRoot` output); in-scope paths join beneath it.
200
+ * @param sourceFiles The in-scope `(relPath, text)` pairs the pipeline
201
+ * pre-read through the async `readBounded` (16 MiB budget — a JSON-free
202
+ * whole-file read). A `null` text excludes its file.
203
+ * @param stderr Injected diagnostic sink for per-file skips; stdout is
204
+ * never touched (it is reserved for JSON-RPC responses).
205
+ * @returns The bootstrapped `ProgramContext` in either mode.
206
+ */
207
+ export declare function buildProgramContext(realRoot: string, sourceFiles: ReadonlyArray<PreReadSource>, stderr: Writable): ProgramContext;