carrick 0.3.156 → 0.3.158

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 (166) hide show
  1. package/dist/cli.d.ts +7 -0
  2. package/dist/cli.js +4 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/contract.d.ts +8 -1
  5. package/dist/contract.js.map +1 -1
  6. package/dist/engine-ask.d.ts +21 -0
  7. package/dist/engine-ask.js +50 -0
  8. package/dist/engine-ask.js.map +1 -0
  9. package/dist/facts/diff.d.ts +14 -1
  10. package/dist/facts/diff.js +21 -8
  11. package/dist/facts/diff.js.map +1 -1
  12. package/dist/facts/enabled.d.ts +6 -0
  13. package/dist/facts/enabled.js +8 -0
  14. package/dist/facts/enabled.js.map +1 -1
  15. package/dist/facts/fetch.d.ts +7 -0
  16. package/dist/facts/fetch.js +24 -2
  17. package/dist/facts/fetch.js.map +1 -1
  18. package/dist/facts/lines.d.ts +22 -4
  19. package/dist/facts/lines.js +31 -9
  20. package/dist/facts/lines.js.map +1 -1
  21. package/dist/facts/peers.d.ts +13 -4
  22. package/dist/facts/peers.js +17 -15
  23. package/dist/facts/peers.js.map +1 -1
  24. package/dist/facts/rules/packages.js +3 -1
  25. package/dist/facts/rules/packages.js.map +1 -1
  26. package/dist/facts/rules/same-name.js +1 -1
  27. package/dist/facts/rules/same-name.js.map +1 -1
  28. package/dist/facts/store.d.ts +15 -0
  29. package/dist/facts/store.js +30 -0
  30. package/dist/facts/store.js.map +1 -1
  31. package/dist/held/backoff.d.ts +8 -0
  32. package/dist/held/backoff.js +43 -0
  33. package/dist/held/backoff.js.map +1 -0
  34. package/dist/held/build.d.ts +17 -0
  35. package/dist/held/build.js +62 -0
  36. package/dist/held/build.js.map +1 -0
  37. package/dist/held/client.d.ts +43 -0
  38. package/dist/held/client.js +200 -0
  39. package/dist/held/client.js.map +1 -0
  40. package/dist/held/daemon.d.ts +151 -0
  41. package/dist/held/daemon.js +399 -0
  42. package/dist/held/daemon.js.map +1 -0
  43. package/dist/held/early.d.ts +28 -0
  44. package/dist/held/early.js +115 -0
  45. package/dist/held/early.js.map +1 -0
  46. package/dist/held/engine.d.ts +50 -0
  47. package/dist/held/engine.js +166 -0
  48. package/dist/held/engine.js.map +1 -0
  49. package/dist/held/paths.d.ts +15 -0
  50. package/dist/held/paths.js +44 -0
  51. package/dist/held/paths.js.map +1 -0
  52. package/dist/held/place.d.ts +130 -0
  53. package/dist/held/place.js +236 -0
  54. package/dist/held/place.js.map +1 -0
  55. package/dist/held/registry.d.ts +22 -0
  56. package/dist/held/registry.js +72 -0
  57. package/dist/held/registry.js.map +1 -0
  58. package/dist/held/run.d.ts +2 -0
  59. package/dist/held/run.js +78 -0
  60. package/dist/held/run.js.map +1 -0
  61. package/dist/held/runtime.d.ts +22 -0
  62. package/dist/held/runtime.js +612 -0
  63. package/dist/held/runtime.js.map +1 -0
  64. package/dist/held/shadow.d.ts +33 -0
  65. package/dist/held/shadow.js +68 -0
  66. package/dist/held/shadow.js.map +1 -0
  67. package/dist/held/steps.d.ts +11 -0
  68. package/dist/held/steps.js +29 -0
  69. package/dist/held/steps.js.map +1 -0
  70. package/dist/hook/bash-targets.d.ts +7 -2
  71. package/dist/hook/bash-targets.js +82 -27
  72. package/dist/hook/bash-targets.js.map +1 -1
  73. package/dist/hook/confirm.d.ts +79 -0
  74. package/dist/hook/confirm.js +220 -0
  75. package/dist/hook/confirm.js.map +1 -0
  76. package/dist/hook/edit-flow.d.ts +14 -3
  77. package/dist/hook/edit-flow.js +113 -33
  78. package/dist/hook/edit-flow.js.map +1 -1
  79. package/dist/hook/generation.d.ts +19 -0
  80. package/dist/hook/generation.js +75 -0
  81. package/dist/hook/generation.js.map +1 -0
  82. package/dist/hook/late.d.ts +50 -9
  83. package/dist/hook/late.js +104 -24
  84. package/dist/hook/late.js.map +1 -1
  85. package/dist/hook/lock.d.ts +26 -0
  86. package/dist/hook/lock.js +122 -0
  87. package/dist/hook/lock.js.map +1 -0
  88. package/dist/hook/post-bash.js +17 -8
  89. package/dist/hook/post-bash.js.map +1 -1
  90. package/dist/hook/post-edit.js +2 -2
  91. package/dist/hook/post-edit.js.map +1 -1
  92. package/dist/hook/post-read.js +25 -3
  93. package/dist/hook/post-read.js.map +1 -1
  94. package/dist/hook/post-search.js +1 -1
  95. package/dist/hook/post-search.js.map +1 -1
  96. package/dist/hook/probe.js +1 -0
  97. package/dist/hook/probe.js.map +1 -1
  98. package/dist/hook/read-answer.d.ts +5 -0
  99. package/dist/hook/read-answer.js +8 -4
  100. package/dist/hook/read-answer.js.map +1 -1
  101. package/dist/hook/rechecks.d.ts +59 -2
  102. package/dist/hook/rechecks.js +129 -119
  103. package/dist/hook/rechecks.js.map +1 -1
  104. package/dist/hook/session-start.d.ts +1 -1
  105. package/dist/hook/session-start.js +19 -5
  106. package/dist/hook/session-start.js.map +1 -1
  107. package/dist/hook/similar.d.ts +1 -1
  108. package/dist/hook/similar.js +21 -8
  109. package/dist/hook/similar.js.map +1 -1
  110. package/dist/hook/stop-wait.js +35 -16
  111. package/dist/hook/stop-wait.js.map +1 -1
  112. package/dist/hook/timings.d.ts +30 -2
  113. package/dist/hook/timings.js +8 -2
  114. package/dist/hook/timings.js.map +1 -1
  115. package/dist/hook/user-prompt.js +2 -2
  116. package/dist/hook/user-prompt.js.map +1 -1
  117. package/dist/hosted-snapshot.d.ts +27 -0
  118. package/dist/hosted-snapshot.js +32 -0
  119. package/dist/hosted-snapshot.js.map +1 -1
  120. package/dist/init/hosted.js +2 -9
  121. package/dist/init/hosted.js.map +1 -1
  122. package/dist/lsp-frame.d.ts +20 -0
  123. package/dist/lsp-frame.js +47 -0
  124. package/dist/lsp-frame.js.map +1 -0
  125. package/dist/render.d.ts +15 -1
  126. package/dist/render.js +50 -4
  127. package/dist/render.js.map +1 -1
  128. package/dist/server.js +5 -29
  129. package/dist/server.js.map +1 -1
  130. package/package.json +6 -6
  131. package/plugin/.claude-plugin/plugin.json +1 -1
  132. package/sidecar/dist/src/capture/anchors.d.ts +8 -0
  133. package/sidecar/dist/src/capture/anchors.js +3 -2
  134. package/sidecar/dist/src/capture/api.d.ts +98 -1
  135. package/sidecar/dist/src/capture/check-classify.d.ts +7 -0
  136. package/sidecar/dist/src/capture/check-classify.js +24 -0
  137. package/sidecar/dist/src/capture/check-probe.d.ts +86 -11
  138. package/sidecar/dist/src/capture/check-probe.js +175 -22
  139. package/sidecar/dist/src/capture/check.js +13 -1
  140. package/sidecar/dist/src/capture/graphql-leaves.d.ts +46 -0
  141. package/sidecar/dist/src/capture/graphql-leaves.js +142 -0
  142. package/sidecar/dist/src/capture/index.d.ts +12 -3
  143. package/sidecar/dist/src/capture/index.js +11 -2
  144. package/sidecar/dist/src/capture/result-label.js +3 -1
  145. package/sidecar/dist/src/capture/type-reasons.json +78 -0
  146. package/sidecar/dist/src/definition-resolver.d.ts +6 -5
  147. package/sidecar/dist/src/definition-resolver.js +20 -15
  148. package/sidecar/dist/src/engine-stamp.json +1 -0
  149. package/sidecar/dist/src/held-shadow.d.ts +70 -0
  150. package/sidecar/dist/src/held-shadow.js +222 -0
  151. package/sidecar/dist/src/index.js +65 -2
  152. package/sidecar/dist/src/library-claims.d.ts +3 -1
  153. package/sidecar/dist/src/library-claims.js +105 -6
  154. package/sidecar/dist/src/retype.d.ts +47 -0
  155. package/sidecar/dist/src/retype.js +274 -18
  156. package/sidecar/dist/src/site-find.d.ts +27 -0
  157. package/sidecar/dist/src/site-find.js +109 -0
  158. package/sidecar/dist/src/type-home.d.ts +12 -0
  159. package/sidecar/dist/src/type-home.js +41 -1
  160. package/sidecar/dist/src/type-inferrer.d.ts +13 -3
  161. package/sidecar/dist/src/type-inferrer.js +44 -22
  162. package/sidecar/dist/src/type-structural-expander.d.ts +11 -11
  163. package/sidecar/dist/src/type-structural-expander.js +73 -4
  164. package/sidecar/dist/src/types.d.ts +91 -5
  165. package/sidecar/dist/src/validators.d.ts +621 -254
  166. package/sidecar/dist/src/validators.js +37 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * The shadow tree a held-open compiler reads: a copy of one service's program
3
+ * that lives outside the checkout and loads on TypeScript 7.
4
+ *
5
+ * The scan's loader builds the program on TypeScript 6 (repo tsconfig, Deno
6
+ * graph, workspace links). TypeScript 7's command line refuses options the
7
+ * repo may set (`baseUrl`, `moduleResolution: node`, `target: es5`,
8
+ * `esModuleInterop: false`), and a config outside the repo cannot govern files
9
+ * inside it, so the held compiler never reads the repo's own config or files.
10
+ * It reads this tree instead:
11
+ *
12
+ * - `w/<repo-relative path>`: byte copies of the service's own files;
13
+ * - `v/<absolute path>`: every other program file (installed packages,
14
+ * runtime types), with each import, export, import type, augmentation and
15
+ * `types` reference pinned to the copy of the file TypeScript 6 resolved it
16
+ * to, so one package name that resolves to two versions stays two files;
17
+ * - `w/tsconfig.json`: generated, `moduleResolution: bundler`, exact `paths`
18
+ * for the bare specifiers the own files use, every non-library program file
19
+ * named in `files` (so `@types` the loader included on its own are
20
+ * explicit), and the library files TypeScript 6 loaded named in `lib`.
21
+ *
22
+ * Own = under the scanned repo, not under a `node_modules` segment, not under
23
+ * `.carrick/`. A bare import added later is not in `paths` (it needs a new
24
+ * shadow).
25
+ */
26
+ import * as fs from 'node:fs';
27
+ import * as path from 'node:path';
28
+ import { ts } from 'ts-morph';
29
+ import { WriteGuard, judgeTscPath, jsonWireDeclarations, jsonWireRule, judgeTolerances } from './capture/index.js';
30
+ /** The platform package's executable, `@typescript/typescript-<platform>-<arch>/lib/tsc`. */
31
+ const NATIVE_TSC = /[\\/]@typescript[\\/]typescript-[^\\/]+[\\/]lib[\\/]tsc(\.exe)?$/;
32
+ /** `judgeTscPath()` when it is the native executable, else null (no held compiler). */
33
+ export function nativeTscPath(tscPath = judgeTscPath()) {
34
+ return NATIVE_TSC.test(tscPath) ? tscPath : null;
35
+ }
36
+ const MISSING = (spec) => `__held_unresolved__/${spec.replace(/[^A-Za-z0-9@/._-]/g, '_')}`;
37
+ /** A `/// <reference types>` or import target written for a vendored file: relative, JS-spelled for declaration files. */
38
+ function relativeSpecifier(fromFile, toFile) {
39
+ let rel = path.relative(path.dirname(fromFile), toFile).split(path.sep).join('/');
40
+ if (!rel.startsWith('.'))
41
+ rel = `./${rel}`;
42
+ return rel.replace(/\.d\.ts$/, '.js').replace(/\.d\.mts$/, '.mjs').replace(/\.d\.cts$/, '.cjs');
43
+ }
44
+ function isLibraryFile(program, fileName) {
45
+ const sf = program.getSourceFile(fileName);
46
+ if (sf && program.isSourceFileDefaultLibrary(sf))
47
+ return true;
48
+ return (/[\\/]typescript[\\/]lib[\\/]lib\.[^/\\]*\.d\.ts$/.test(fileName) ||
49
+ /[\\/]@ts-morph[\\/]common[\\/].*lib\.[^/\\]*\.d\.ts$/.test(fileName));
50
+ }
51
+ /**
52
+ * Write the shadow tree of the loader's default program under `outDir` (which
53
+ * must be outside the scan root). Reads the program; changes nothing in the
54
+ * checkout.
55
+ */
56
+ export function writeShadow(loader, outDir) {
57
+ const scanRoot = loader.getScanRoot();
58
+ const program = loader.getProject().getProgram().compilerObject;
59
+ const internal = program;
60
+ const roots = [scanRoot, safeRealpath(scanRoot)].filter((r, i, all) => all.indexOf(r) === i);
61
+ const underRoot = (file) => roots.find((r) => file.startsWith(r + path.sep));
62
+ const isOwn = (file) => {
63
+ const root = underRoot(file);
64
+ if (root === undefined)
65
+ return false;
66
+ const segments = file.slice(root.length + 1).split(path.sep);
67
+ return !segments.includes('node_modules') && segments[0] !== '.carrick';
68
+ };
69
+ const ownRelative = (file) => path.relative(underRoot(file) ?? scanRoot, file);
70
+ const guard = WriteGuard.of({ dirs: [outDir], protect: [scanRoot, loader.getRepoRoot()] });
71
+ const own = path.join(outDir, 'w');
72
+ const vendoredRoot = path.join(outDir, 'v');
73
+ const shadowPath = (file) => isOwn(file) ? path.join(own, ownRelative(file)) : path.join(vendoredRoot, file);
74
+ const inProgram = new Set(program.getSourceFiles().map((sf) => sf.fileName));
75
+ const paths = {};
76
+ const pathConflicts = [];
77
+ const ownFiles = [];
78
+ let vendored = 0;
79
+ let rewritten = 0;
80
+ let unresolved = 0;
81
+ for (const sf of program.getSourceFiles()) {
82
+ const file = sf.fileName;
83
+ if (isLibraryFile(program, file))
84
+ continue;
85
+ const literals = [];
86
+ const { imports = [], moduleAugmentations = [] } = sf;
87
+ for (const node of [...imports, ...moduleAugmentations]) {
88
+ if (!ts.isStringLiteralLike(node))
89
+ continue;
90
+ const augmentation = moduleAugmentations.includes(node);
91
+ if (augmentation && !ts.isExternalModule(sf))
92
+ continue; // an ambient declaration, not a resolution
93
+ const mode = program.getModeForUsageLocation(sf, node);
94
+ const resolved = internal.getResolvedModule(sf, node.text, mode)?.resolvedModule;
95
+ literals.push({
96
+ node,
97
+ text: node.text,
98
+ to: resolved?.resolvedFileName,
99
+ augmentation,
100
+ synthesized: node.pos < 0 || node.end < 0 || !node.parent,
101
+ });
102
+ }
103
+ if (isOwn(file)) {
104
+ ownFiles.push(ownRelative(file));
105
+ const out = shadowPath(file);
106
+ guard.mkdir(path.dirname(out));
107
+ guard.copyFile(file, out);
108
+ for (const lit of literals) {
109
+ if (lit.text.startsWith('.') || path.isAbsolute(lit.text))
110
+ continue;
111
+ if (!lit.to || !inProgram.has(lit.to))
112
+ continue; // unresolved stays unresolved: no `paths` entry
113
+ const target = shadowPath(lit.to);
114
+ const known = paths[lit.text];
115
+ if (known && known[0] !== target)
116
+ pathConflicts.push({ spec: lit.text, a: known[0], b: target, from: ownRelative(file) });
117
+ else
118
+ paths[lit.text] = [target];
119
+ }
120
+ continue;
121
+ }
122
+ // A vendored copy: every specifier pinned to the copy TypeScript 6 chose.
123
+ let text = sf.text;
124
+ const edits = [];
125
+ for (const lit of literals) {
126
+ if (lit.synthesized)
127
+ continue;
128
+ let spec;
129
+ if (lit.to && inProgram.has(lit.to))
130
+ spec = relativeSpecifier(shadowPath(file), shadowPath(lit.to));
131
+ else {
132
+ spec = MISSING(lit.text);
133
+ unresolved++;
134
+ }
135
+ edits.push({ start: lit.node.getStart(sf) + 1, end: lit.node.end - 1, text: spec });
136
+ }
137
+ for (const ref of sf.typeReferenceDirectives ?? []) {
138
+ const mode = ref.resolutionMode ?? internal.getDefaultResolutionModeForFile(sf);
139
+ const target = internal.getResolvedTypeReferenceDirective?.(sf, ref.fileName, mode)?.resolvedTypeReferenceDirective?.resolvedFileName;
140
+ // The whole `/// <reference types="..." />` line becomes a path reference to the copy.
141
+ const lineStart = text.lastIndexOf('\n', ref.pos) + 1;
142
+ const newline = text.indexOf('\n', ref.end);
143
+ const lineEnd = newline === -1 ? text.length : newline;
144
+ const replacement = target && inProgram.has(target)
145
+ ? `/// <reference path="${relativeSpecifier(shadowPath(file), shadowPath(target)).replace(/\.js$/, '.d.ts').replace(/\.mjs$/, '.d.mts').replace(/\.cjs$/, '.d.cts')}" />`
146
+ : `// held: unresolved types reference ${ref.fileName}`;
147
+ edits.push({ start: lineStart, end: lineEnd, text: replacement });
148
+ }
149
+ edits.sort((a, b) => b.start - a.start);
150
+ for (const edit of edits)
151
+ text = text.slice(0, edit.start) + edit.text + text.slice(edit.end);
152
+ rewritten += edits.length;
153
+ const out = shadowPath(file);
154
+ guard.mkdir(path.dirname(out));
155
+ guard.writeFile(out, text);
156
+ vendored++;
157
+ }
158
+ const options = program.getCompilerOptions();
159
+ // A repo that sets no `lib` gets the default library files for its target (DOM, es2022, ...). `lib: []`
160
+ // would leave only what `@types/node` references, so the files TypeScript 6 loaded are named. `*.full`
161
+ // is a file, not a `--lib` name, and TypeScript 7 refuses it; its parts are listed.
162
+ const libraryNames = program
163
+ .getSourceFiles()
164
+ .map((sf) => sf.fileName)
165
+ .filter((f) => isLibraryFile(program, f))
166
+ .map((f) => path.basename(f).replace(/^lib\./, '').replace(/\.d\.ts$/, ''))
167
+ .filter((name) => !name.endsWith('.full'));
168
+ const lib = options.lib ? options.lib.map((l) => l.replace(/^lib\./, '').replace(/\.d\.ts$/, '')) : libraryNames;
169
+ // Every non-library program file is a root, so `@types` the loader included on its own and the
170
+ // synthesised JSX runtime import's target stay in the program.
171
+ const files = program.getSourceFiles().filter((sf) => !isLibraryFile(program, sf.fileName)).map((sf) => shadowPath(sf.fileName));
172
+ const jsx = { 1: 'preserve', 2: 'react', 3: 'react-native', 4: 'react-jsx', 5: 'react-jsxdev' }[options.jsx ?? 0];
173
+ const passed = [
174
+ 'noImplicitAny', 'strictNullChecks', 'noUnusedLocals', 'noUnusedParameters', 'exactOptionalPropertyTypes',
175
+ 'noImplicitOverride', 'noImplicitReturns', 'noFallthroughCasesInSwitch', 'noUncheckedIndexedAccess',
176
+ 'useUnknownInCatchVariables', 'verbatimModuleSyntax', 'isolatedModules', 'experimentalDecorators',
177
+ 'emitDecoratorMetadata', 'useDefineForClassFields', 'noPropertyAccessFromIndexSignature',
178
+ ];
179
+ const compilerOptions = {
180
+ // Options TypeScript 7 removed (baseUrl, node10 resolution, es5, esModuleInterop: false) are never carried.
181
+ target: 'esnext', module: 'esnext', moduleResolution: 'bundler', strict: options.strict ?? false,
182
+ allowJs: !!options.allowJs, checkJs: !!options.checkJs, skipLibCheck: !!options.skipLibCheck,
183
+ resolveJsonModule: !!options.resolveJsonModule,
184
+ ...(jsx ? { jsx } : {}), ...(options.jsxImportSource ? { jsxImportSource: options.jsxImportSource } : {}),
185
+ lib, allowImportingTsExtensions: true, noEmit: true,
186
+ // `false` (the loader's reading of `esModuleInterop: false`) is refused by TypeScript 7 (TS5108); the default is true.
187
+ ...(options.allowSyntheticDefaultImports === false ? {} : { allowSyntheticDefaultImports: true }),
188
+ types: options.types ?? [], noUncheckedSideEffectImports: options.noUncheckedSideEffectImports ?? false,
189
+ ...Object.fromEntries(passed.filter((k) => options[k] !== undefined).map((k) => [k, options[k]])),
190
+ paths,
191
+ };
192
+ const tsconfig = path.join(own, 'tsconfig.json');
193
+ guard.mkdir(own);
194
+ guard.writeFile(tsconfig, JSON.stringify({ compilerOptions, files, include: [] }, null, 1));
195
+ return {
196
+ tsconfig,
197
+ own_files: ownFiles.sort(),
198
+ vendored,
199
+ rewritten,
200
+ unresolved,
201
+ path_conflicts: pathConflicts,
202
+ bare_specifiers: Object.keys(paths).sort(),
203
+ wire: heldWire(),
204
+ tolerances: judgeTolerances('__carrick_'),
205
+ native_tsc: nativeTscPath(),
206
+ };
207
+ }
208
+ /** The wire declarations and the one rule type a held check appends (prefix `__carrick_`). */
209
+ export function heldWire() {
210
+ return [
211
+ ...jsonWireDeclarations('__carrick_'),
212
+ `type __carrick_Wire<S, E> = ${jsonWireRule('S', 'E', '__carrick_')};`,
213
+ ];
214
+ }
215
+ function safeRealpath(p) {
216
+ try {
217
+ return fs.realpathSync(p);
218
+ }
219
+ catch {
220
+ return p;
221
+ }
222
+ }
@@ -16,6 +16,7 @@
16
16
  * that goes silent past its deadline; a long handler stays alive by writing
17
17
  * `progress` frames as it finishes units of work (writeProgress).
18
18
  */
19
+ import * as fs from 'node:fs';
19
20
  import * as path from 'node:path';
20
21
  import * as readline from 'node:readline';
21
22
  import { parseRequest } from './validators.js';
@@ -30,6 +31,8 @@ import { readServerLabels } from './server-labels.js';
30
31
  import { PROGRESS_INTERVAL_MS, atMostEvery } from './progress.js';
31
32
  import { mergeInferTimings } from './infer-timing.js';
32
33
  import { addProgramFiles, listProgramFiles } from './program-files.js';
34
+ import { writeShadow } from './held-shadow.js';
35
+ import { findSite } from './site-find.js';
33
36
  import { changedSource, inferCacheDir, keepable, programDifference, programRecord, readEntry, requestDigest, writeEntry, } from './infer-cache.js';
34
37
  import { writePositionRows } from './position-rows.js';
35
38
  import { findImplementations } from './implementations.js';
@@ -630,6 +633,25 @@ function handleVerifyClientSemantics(request) {
630
633
  return { request_id: request.request_id, status: 'error', errors: [error] };
631
634
  }
632
635
  }
636
+ /**
637
+ * A verifier over a program built from another service's tsconfig: its
638
+ * compiler options, none of its files (the `scripts` build kind), so the probe
639
+ * file is the only root. Nothing keeps the program; it is garbage once the
640
+ * request that asked for it has answered. Module resolution still goes through
641
+ * this process's loader, as the default program's does.
642
+ *
643
+ * @throws if the tsconfig cannot be read
644
+ */
645
+ function probeOnlyVerifier(tsconfigPath) {
646
+ const loader = initializedLoader();
647
+ const configPath = path.resolve(loader.getRepoRoot(), tsconfigPath);
648
+ if (!fs.existsSync(configPath))
649
+ throw new Error(`tsconfig_path ${configPath} does not exist`);
650
+ return new LibraryClaimsVerifier(loader.scriptProjectFor(configPath), {
651
+ packageDirectoryOf: (file) => loader.packageDirectoryOf(file),
652
+ resolveModule: (name, from, options) => loader.resolveThroughGraph(name, from, options),
653
+ });
654
+ }
633
655
  /**
634
656
  * Handle the 'verify_library_claims' action - check library claims of every
635
657
  * role against each package's own declarations (carrick#1616). One verdict
@@ -638,7 +660,10 @@ function handleVerifyClientSemantics(request) {
638
660
  function handleVerifyLibraryClaims(request) {
639
661
  const started = performance.now();
640
662
  try {
641
- const { claimsVerifier } = projectComponents();
663
+ // A named tsconfig is judged in a probe-only program of its own options,
664
+ // built for this request and dropped with it (carrick#4472); the service's
665
+ // own program is not built for it.
666
+ const claimsVerifier = request.tsconfig_path === undefined ? projectComponents().claimsVerifier : probeOnlyVerifier(request.tsconfig_path);
642
667
  // The verifier's budget starts now, and so does the scanner's wait.
643
668
  writeProgress(request.request_id, 'verify_library_claims', 'program ready');
644
669
  const fromDir = path.resolve(projectLoader.getRepoRoot(), request.from_dir);
@@ -687,7 +712,7 @@ function handleListLibrarySurface(request) {
687
712
  function handleResolveDefinitions(request) {
688
713
  try {
689
714
  log(`Resolving ${request.aliases.length} type alias(es) from ${request.stub_dir}`);
690
- const results = definitionResolver.resolveFromStub(request.stub_dir, request.aliases);
715
+ const results = definitionResolver.resolveFromStub(request.stub_dir, request.aliases, request.graphql_types);
691
716
  return {
692
717
  request_id: request.request_id,
693
718
  status: 'success',
@@ -730,6 +755,40 @@ function handleListProgramFiles(request) {
730
755
  return { request_id: request.request_id, status: 'error', errors: [error] };
731
756
  }
732
757
  }
758
+ /**
759
+ * Handle the 'write_shadow' action: write the service's program as the shadow
760
+ * tree a held-open compiler reads (held-shadow.ts). Builds the default
761
+ * project if the process has not, reads it, and changes nothing in the
762
+ * checkout.
763
+ */
764
+ function handleWriteShadow(request) {
765
+ try {
766
+ const loader = initializedLoader();
767
+ const startTime = performance.now();
768
+ const result = writeShadow(loader, request.out_dir);
769
+ log(`Wrote the shadow of ${result.own_files.length} own file(s) in ${Math.round(performance.now() - startTime)}ms`);
770
+ return { request_id: request.request_id, status: 'success', ...result };
771
+ }
772
+ catch (err) {
773
+ const error = err instanceof Error ? err.message : String(err);
774
+ logError(`Writing the shadow failed: ${error}`);
775
+ return { request_id: request.request_id, status: 'error', errors: [error] };
776
+ }
777
+ }
778
+ /**
779
+ * Handle the 'find_site' action: the capture's own site finder over the
780
+ * caller's two texts (site-find.ts). Reads no program and no disk.
781
+ */
782
+ function handleFindSite(request) {
783
+ try {
784
+ return { request_id: request.request_id, status: 'success', ...findSite(request) };
785
+ }
786
+ catch (err) {
787
+ const error = err instanceof Error ? err.message : String(err);
788
+ logError(`Finding the site failed: ${error}`);
789
+ return { request_id: request.request_id, status: 'error', errors: [error] };
790
+ }
791
+ }
733
792
  /**
734
793
  * Handle the 'reach_graph' action - the import graph of every program the
735
794
  * process has built, the default one and each owning project's (carrick#3100).
@@ -913,6 +972,10 @@ function handleRequest(request) {
913
972
  return handleListLibrarySurface(request);
914
973
  case 'list_program_files':
915
974
  return handleListProgramFiles(request);
975
+ case 'write_shadow':
976
+ return handleWriteShadow(request);
977
+ case 'find_site':
978
+ return handleFindSite(request);
916
979
  case 'reach_graph':
917
980
  return handleReachGraph(request);
918
981
  case 'reach':
@@ -31,7 +31,9 @@
31
31
  *
32
32
  * The export's type is read the way the service's own code would read it: a
33
33
  * probe file in `from_dir` imports it, inside the service's program, under the
34
- * service's compiler options. The declarations must be the installed
34
+ * service's compiler options. A request that names another service's tsconfig
35
+ * (`tsconfig_path`, carrick#4472) reads it in a probe-only program under that
36
+ * tsconfig's options instead. The declarations must be the installed
35
37
  * package's: a `paths` alias or a `declare module` block the service writes
36
38
  * for itself is not evidence about the library.
37
39
  */
@@ -31,7 +31,9 @@
31
31
  *
32
32
  * The export's type is read the way the service's own code would read it: a
33
33
  * probe file in `from_dir` imports it, inside the service's program, under the
34
- * service's compiler options. The declarations must be the installed
34
+ * service's compiler options. A request that names another service's tsconfig
35
+ * (`tsconfig_path`, carrick#4472) reads it in a probe-only program under that
36
+ * tsconfig's options instead. The declarations must be the installed
35
37
  * package's: a `paths` alias or a `declare module` block the service writes
36
38
  * for itself is not evidence about the library.
37
39
  */
@@ -627,6 +629,9 @@ export class LibraryClaimsVerifier {
627
629
  const made = other.claim;
628
630
  if ((made.kind !== 'make' && made.kind !== 'scope') || made.name === undefined)
629
631
  return;
632
+ // An `of`-make names the object its member returns, not an instance of this export (rule 7).
633
+ if (made.kind === 'make' && made.of !== undefined)
634
+ return;
630
635
  const judgement = judge(i);
631
636
  if (judgement.outcome.verdict !== 'verified' || !judgement.holding)
632
637
  return;
@@ -699,6 +704,8 @@ export class LibraryClaimsVerifier {
699
704
  };
700
705
  const judgeCheck = (index) => {
701
706
  const check = checks[index];
707
+ if (check.claim.kind === 'make' && ofMakeInvalid(check.claim))
708
+ return { outcome: unchecked('claim_invalid') };
702
709
  const makeProtocol = makeProtocolRefusal(check);
703
710
  if (makeProtocol !== undefined)
704
711
  return { outcome: unchecked(makeProtocol) };
@@ -718,6 +725,8 @@ export class LibraryClaimsVerifier {
718
725
  }
719
726
  if (unbuiltPart(check.claim) !== undefined)
720
727
  return { outcome: unchecked('part_unbuilt') };
728
+ if (rules.http && check.claim.kind === 'make' && check.claim.of !== undefined)
729
+ return { outcome: unchecked('role_unsupported') };
721
730
  if (rules.http && !HTTP_RECEIVER.test(check.receiver))
722
731
  return { outcome: unchecked('receiver_invalid') };
723
732
  if (rules.message && !fitsReceiver(check))
@@ -1149,13 +1158,15 @@ export function fullSurfaceSha256(surfaces) {
1149
1158
  // A member's `handlers` (carrick#2674), a signature's `result_candidates`
1150
1159
  // (carrick#2817) and a member's `scope_receiver` (carrick#2774) are out of
1151
1160
  // the hash at every depth, and so is a member's `runtime_events`
1152
- // (carrick#3032), and a receiver's `properties` (carrick#3696), so a
1153
- // package's key does not change when the lister learns to list them.
1161
+ // (carrick#3032), a receiver's `properties` (carrick#3696) and a construct
1162
+ // signature's `abstract` (L2, R5), so a package's key does not change when
1163
+ // the lister learns to list them.
1154
1164
  const text = JSON.stringify(listed, (key, value) => key === 'handlers' ||
1155
1165
  key === 'result_candidates' ||
1156
1166
  key === 'scope_receiver' ||
1157
1167
  key === 'runtime_events' ||
1158
- key === 'properties'
1168
+ key === 'properties' ||
1169
+ key === 'abstract'
1159
1170
  ? undefined
1160
1171
  : value);
1161
1172
  return crypto.createHash('sha256').update(text).digest('hex');
@@ -1283,13 +1294,33 @@ function unbuiltPart(claim) {
1283
1294
  * maker's instances" is two elements, not one.
1284
1295
  */
1285
1296
  function placementInvalid(claim) {
1286
- if (claim.kind === 'make' || claim.of === undefined)
1297
+ if (claim.kind === 'make')
1298
+ return ofMakeInvalid(claim);
1299
+ if (claim.of === undefined)
1287
1300
  return false;
1288
1301
  if (claim.on !== undefined)
1289
1302
  return true;
1290
1303
  const of = parseReceiver(claim.of);
1291
1304
  return of === undefined || (of.maker === undefined && of.scope === undefined && of.type === undefined);
1292
1305
  }
1306
+ /**
1307
+ * Rules 1-3 of amendment 12: a make's `of` is a maker receiver id (never the
1308
+ * export, a scope or a type), the make is a `call` on a named member, and it
1309
+ * takes a `name` at an argument with only `key_labels`, `name_scope` and
1310
+ * `picker` beside it. Rule 4 is read on the member's declared return.
1311
+ */
1312
+ function ofMakeInvalid(claim) {
1313
+ if (claim.of === undefined)
1314
+ return false;
1315
+ const of = parseReceiver(claim.of);
1316
+ if (of?.maker === undefined || of.scope !== undefined)
1317
+ return true;
1318
+ if (claim.form !== 'call' || claim.member === null)
1319
+ return true;
1320
+ if (claim.name === undefined || !('arg' in claim.name))
1321
+ return true;
1322
+ return [claim.base, claim.prefix, claim.handler, claim.runs, claim.protocol, claim.result].some(part => part !== undefined);
1323
+ }
1293
1324
  /** The slots a claim's name sits at: one slot, or each of its parts. */
1294
1325
  function nameSlots(claim) {
1295
1326
  const name = claim.name;
@@ -1376,7 +1407,7 @@ function fitsReceiver(check) {
1376
1407
  if (receiver.type)
1377
1408
  return claim.kind !== 'make' && claim.of === check.receiver;
1378
1409
  if (claim.kind === 'make')
1379
- return check.receiver === 'export';
1410
+ return claim.of === undefined ? check.receiver === 'export' : check.receiver === claim.of;
1380
1411
  if (claim.of !== undefined)
1381
1412
  return check.receiver === claim.of;
1382
1413
  if (claim.on === undefined)
@@ -1398,6 +1429,9 @@ function fitsReceiver(check) {
1398
1429
  function builtReceiver(check) {
1399
1430
  const claim = check.claim;
1400
1431
  if (claim.kind === 'make') {
1432
+ // An `of`-make opens no receiver id on its own export (amendment 12, rule 7).
1433
+ if (claim.of !== undefined)
1434
+ return undefined;
1401
1435
  if (claim.member === null)
1402
1436
  return claim.form === 'call' ? 'instance:()' : 'instance:new';
1403
1437
  return claim.form === 'call' ? `instance:${claim.member}` : `instance:new:${claim.member}`;
@@ -2264,6 +2298,8 @@ class DeclarationReader {
2264
2298
  * (`runsCollectionOutcome`). With no such scope this arm never runs.
2265
2299
  */
2266
2300
  judgeMake(receiver, claim, built, collections) {
2301
+ if (claim.of !== undefined)
2302
+ return this.judgeOfMake(receiver, claim);
2267
2303
  const layout = this.layout({
2268
2304
  base: claim.base,
2269
2305
  prefix: claim.prefix,
@@ -2302,6 +2338,48 @@ class DeclarationReader {
2302
2338
  return { outcome: VERIFIED, holding };
2303
2339
  return { outcome: best.outcome };
2304
2340
  }
2341
+ /**
2342
+ * An `of`-make (amendment 12): `member` is a home-declared call on the
2343
+ * receiver `of` names, whose name slot takes the name at `name`, and whose
2344
+ * declared return is an object type: not the receiver's own (a fluent
2345
+ * `this`), not a Promise (`claim_invalid`). It opens no receiver, so it
2346
+ * holds no overloads; its verdict carries the member's declarations.
2347
+ */
2348
+ judgeOfMake(receiver, claim) {
2349
+ const layout = this.layout({ name: claim.name });
2350
+ if ('failure' in layout)
2351
+ return { outcome: layout.failure };
2352
+ const callee = this.ownCallee(receiver, [], claim.member, 'call');
2353
+ if ('failure' in callee)
2354
+ return { outcome: callee.failure };
2355
+ const labels = claim.key_labels ?? {};
2356
+ const holding = [];
2357
+ let best;
2358
+ for (const signature of callee.signatures) {
2359
+ let result = this.messageSignatureOutcome(signature, layout.value, labels);
2360
+ if (result.rank === Infinity && !this.makesAnObject(this.checker.getReturnTypeOfSignature(signature), receiver.type)) {
2361
+ result = { rank: 6, outcome: unchecked('claim_invalid') };
2362
+ }
2363
+ if (result.rank === Infinity)
2364
+ holding.push(signature);
2365
+ else
2366
+ best = furthest(best, result.rank, result.outcome);
2367
+ }
2368
+ if (holding.length === 0)
2369
+ return { outcome: best.outcome };
2370
+ const declarations = this.declarationsOf({ signatures: holding, named: callee.named });
2371
+ return { outcome: declarations.length > 0 ? { verdict: 'verified', declarations } : VERIFIED };
2372
+ }
2373
+ /** An `of`-make's return (rule 4): an object type that is neither the receiver's own nor a thenable. */
2374
+ makesAnObject(returned, receiver) {
2375
+ if (returned.flags & ts.TypeFlags.TypeParameter && returned.isThisType)
2376
+ return false;
2377
+ if (returned === receiver || sameDeclared(this.checker, returned, receiver))
2378
+ return false;
2379
+ if (this.checker.getAwaitedType(returned) !== returned)
2380
+ return false;
2381
+ return this.isObjectType(returned);
2382
+ }
2305
2383
  /**
2306
2384
  * `member` (after `path`) is a home-declared callable member whose name
2307
2385
  * slot accepts a string, under the name-slot rules, and returns a type that
@@ -5443,6 +5521,25 @@ class DeclarationReader {
5443
5521
  this.handlerMembers.set(type, listed);
5444
5522
  return listed;
5445
5523
  }
5524
+ /**
5525
+ * A construct signature of an abstract class: `new` on it is a type error.
5526
+ * Read from the class declaration, which the written constructor sits in or
5527
+ * the instance type names when the class writes none. A call signature, or
5528
+ * a construct signature written in an interface, is never abstract.
5529
+ */
5530
+ isAbstractConstruct(signature) {
5531
+ const declaration = signature.getDeclaration();
5532
+ const abstractClass = (node) => node !== undefined &&
5533
+ ts.isClassLike(node) &&
5534
+ (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Abstract) !== 0;
5535
+ if (declaration !== undefined && ts.isConstructorDeclaration(declaration))
5536
+ return abstractClass(declaration.parent);
5537
+ if (declaration !== undefined && ts.isClassLike(declaration))
5538
+ return abstractClass(declaration);
5539
+ if (declaration !== undefined)
5540
+ return false;
5541
+ return (this.checker.getReturnTypeOfSignature(signature).symbol?.declarations ?? []).some(abstractClass);
5542
+ }
5446
5543
  listSignatures(signatures, holder, take) {
5447
5544
  const listed = [];
5448
5545
  for (const signature of signatures) {
@@ -5484,6 +5581,8 @@ class DeclarationReader {
5484
5581
  const candidates = this.listResultCandidates ? resultCandidatesOf(this.checker, signature) : undefined;
5485
5582
  if (candidates !== undefined)
5486
5583
  entry.result_candidates = candidates;
5584
+ if (this.isAbstractConstruct(signature))
5585
+ entry.abstract = true;
5487
5586
  listed.push(entry);
5488
5587
  }
5489
5588
  return listed;
@@ -129,6 +129,53 @@ export declare class Retyper {
129
129
  * than the budget allows; the compiler's diagnostics stand.
130
130
  */
131
131
  private unresolvedMembers;
132
+ /**
133
+ * The JSON wire transform's declarations and the `${WIRE}<P>` alias that
134
+ * states a type in its wire form, as appended to a file that names them.
135
+ */
136
+ private wireDeclarations;
137
+ /**
138
+ * The procedure form (carrick#937): judge a procedure call by the
139
+ * consumer's own code against the call's own type.
140
+ *
141
+ * A procedure call's type IS the producer's router type, read by the
142
+ * consumer's compiler, so stating the producer's output at the call would
143
+ * compare one type with itself. What breaks is the consumer's use of it.
144
+ * The file is type-checked as it is and again with only the call's result
145
+ * erased (`(<call> as any)`): a diagnostic present as-is and gone when
146
+ * erased is a place the consumer uses what the procedure does not return.
147
+ *
148
+ * A guard runs first: the call's result (or one member of it, for a hook's
149
+ * envelope such as `{ data }`) must be the producer's published output, as
150
+ * declared or in its JSON wire form. A call whose result is something else
151
+ * (an options builder's `{ key }`), or a router on disk that no longer
152
+ * returns what the producer published, is not compared: erasing it would
153
+ * agree about nothing.
154
+ */
155
+ private runProcedure;
156
+ /**
157
+ * The one call to the procedure `procedurePath` names that starts on the
158
+ * item's line: a call whose callee is `R.s1.….sk.m`, with `s1..sk` the key
159
+ * path's segments, `m` any name (the client's operation) and `R` any
160
+ * expression (the client). Or why there is not exactly one.
161
+ */
162
+ private locateProcedureCall;
163
+ /**
164
+ * The `any` members of the call's awaited result, which can only hide a
165
+ * diagnostic and so decide only an empty diff, or why the result cannot be
166
+ * compared at all (`any`/`unknown` as a whole, `unknown` at a member). The
167
+ * walk's budget sentinel is dropped, as {@link unresolvedMembers} drops it.
168
+ */
169
+ private procedureTopTypes;
170
+ /**
171
+ * Guard (carrick#937): what carries the producer's published output,
172
+ * declared or in its JSON wire form (each way assignable to the other),
173
+ * read in the consumer's own program: the call's awaited result as a whole
174
+ * (`member` unset), or for an object result the string-named member that
175
+ * does once `null`/`undefined` are removed. Else why the call is not
176
+ * compared.
177
+ */
178
+ private carriesProducerOutput;
132
179
  /**
133
180
  * The stated type argument must be what the call RETURNS (or a type
134
181
  * argument or member of it): the rewrite is only a statement about the