carrick 0.3.153 → 0.3.155

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 (159) hide show
  1. package/bin/carrick.mjs +26 -4
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.js +1 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/contract.d.ts +37 -3
  6. package/dist/contract.js +8 -0
  7. package/dist/contract.js.map +1 -1
  8. package/dist/facts/diff.d.ts +27 -0
  9. package/dist/facts/diff.js +134 -0
  10. package/dist/facts/diff.js.map +1 -0
  11. package/dist/facts/enabled.d.ts +2 -0
  12. package/dist/facts/enabled.js +9 -0
  13. package/dist/facts/enabled.js.map +1 -0
  14. package/dist/facts/fetch.d.ts +48 -0
  15. package/dist/facts/fetch.js +235 -0
  16. package/dist/facts/fetch.js.map +1 -0
  17. package/dist/facts/files.d.ts +21 -0
  18. package/dist/facts/files.js +58 -0
  19. package/dist/facts/files.js.map +1 -0
  20. package/dist/facts/lines.d.ts +70 -0
  21. package/dist/facts/lines.js +335 -0
  22. package/dist/facts/lines.js.map +1 -0
  23. package/dist/facts/match.d.ts +91 -0
  24. package/dist/facts/match.js +1122 -0
  25. package/dist/facts/match.js.map +1 -0
  26. package/dist/facts/peers.d.ts +48 -0
  27. package/dist/facts/peers.js +143 -0
  28. package/dist/facts/peers.js.map +1 -0
  29. package/dist/facts/refresh-run.d.ts +2 -0
  30. package/dist/facts/refresh-run.js +18 -0
  31. package/dist/facts/refresh-run.js.map +1 -0
  32. package/dist/facts/rules/packages.d.ts +16 -0
  33. package/dist/facts/rules/packages.js +157 -0
  34. package/dist/facts/rules/packages.js.map +1 -0
  35. package/dist/facts/rules/same-name.d.ts +28 -0
  36. package/dist/facts/rules/same-name.js +131 -0
  37. package/dist/facts/rules/same-name.js.map +1 -0
  38. package/dist/facts/store.d.ts +119 -0
  39. package/dist/facts/store.js +341 -0
  40. package/dist/facts/store.js.map +1 -0
  41. package/dist/git-remote.d.ts +6 -0
  42. package/dist/git-remote.js +37 -0
  43. package/dist/git-remote.js.map +1 -0
  44. package/dist/hook/apply-patch.d.ts +23 -0
  45. package/dist/hook/apply-patch.js +92 -0
  46. package/dist/hook/apply-patch.js.map +1 -1
  47. package/dist/hook/bash-targets.d.ts +8 -0
  48. package/dist/hook/bash-targets.js +23 -11
  49. package/dist/hook/bash-targets.js.map +1 -1
  50. package/dist/hook/edit-flow.d.ts +29 -2
  51. package/dist/hook/edit-flow.js +80 -29
  52. package/dist/hook/edit-flow.js.map +1 -1
  53. package/dist/hook/late.d.ts +29 -0
  54. package/dist/hook/late.js +121 -26
  55. package/dist/hook/late.js.map +1 -1
  56. package/dist/hook/post-bash.js +45 -22
  57. package/dist/hook/post-bash.js.map +1 -1
  58. package/dist/hook/post-edit.d.ts +16 -1
  59. package/dist/hook/post-edit.js +177 -13
  60. package/dist/hook/post-edit.js.map +1 -1
  61. package/dist/hook/post-read.js +8 -12
  62. package/dist/hook/post-read.js.map +1 -1
  63. package/dist/hook/post-search.d.ts +2 -0
  64. package/dist/hook/post-search.js +25 -0
  65. package/dist/hook/post-search.js.map +1 -0
  66. package/dist/hook/probe.d.ts +18 -3
  67. package/dist/hook/probe.js +30 -6
  68. package/dist/hook/probe.js.map +1 -1
  69. package/dist/hook/rechecks.d.ts +66 -11
  70. package/dist/hook/rechecks.js +115 -29
  71. package/dist/hook/rechecks.js.map +1 -1
  72. package/dist/hook/refresh.d.ts +9 -0
  73. package/dist/hook/refresh.js +10 -0
  74. package/dist/hook/refresh.js.map +1 -1
  75. package/dist/hook/reuse.d.ts +16 -2
  76. package/dist/hook/reuse.js +49 -6
  77. package/dist/hook/reuse.js.map +1 -1
  78. package/dist/hook/session-key.d.ts +12 -0
  79. package/dist/hook/session-key.js +30 -0
  80. package/dist/hook/session-key.js.map +1 -0
  81. package/dist/hook/session-start.js +14 -7
  82. package/dist/hook/session-start.js.map +1 -1
  83. package/dist/hook/stop-wait.d.ts +2 -9
  84. package/dist/hook/stop-wait.js +96 -113
  85. package/dist/hook/stop-wait.js.map +1 -1
  86. package/dist/hook/stop.js +13 -8
  87. package/dist/hook/stop.js.map +1 -1
  88. package/dist/hook/subagent-stop.d.ts +2 -0
  89. package/dist/hook/subagent-stop.js +45 -0
  90. package/dist/hook/subagent-stop.js.map +1 -0
  91. package/dist/hook/timings.d.ts +72 -0
  92. package/dist/hook/timings.js +175 -0
  93. package/dist/hook/timings.js.map +1 -0
  94. package/dist/hook/user-prompt.js +17 -13
  95. package/dist/hook/user-prompt.js.map +1 -1
  96. package/dist/hook/worktree.d.ts +11 -0
  97. package/dist/hook/worktree.js +27 -1
  98. package/dist/hook/worktree.js.map +1 -1
  99. package/dist/init/repo-copies.d.ts +6 -0
  100. package/dist/init/repo-copies.js +7 -3
  101. package/dist/init/repo-copies.js.map +1 -1
  102. package/dist/init/repos.d.ts +2 -2
  103. package/dist/init/repos.js +1 -34
  104. package/dist/init/repos.js.map +1 -1
  105. package/dist/init/settings.js +25 -13
  106. package/dist/init/settings.js.map +1 -1
  107. package/dist/render.d.ts +8 -33
  108. package/dist/render.js +42 -120
  109. package/dist/render.js.map +1 -1
  110. package/package.json +6 -6
  111. package/plugin/.claude-plugin/plugin.json +1 -1
  112. package/plugin/hooks/hooks.json +44 -3
  113. package/scripts/install-scanned-deps.sh +25 -2
  114. package/sidecar/dist/src/capture/anchors.d.ts +12 -1
  115. package/sidecar/dist/src/capture/anchors.js +28 -47
  116. package/sidecar/dist/src/capture/api.d.ts +41 -1
  117. package/sidecar/dist/src/capture/augmentations.d.ts +2 -0
  118. package/sidecar/dist/src/capture/augmentations.js +1 -1
  119. package/sidecar/dist/src/capture/check-classify.d.ts +12 -1
  120. package/sidecar/dist/src/capture/check-classify.js +43 -0
  121. package/sidecar/dist/src/capture/check-deep.d.ts +44 -1
  122. package/sidecar/dist/src/capture/check-deep.js +161 -2
  123. package/sidecar/dist/src/capture/check.js +23 -2
  124. package/sidecar/dist/src/capture/checkout.d.ts +9 -3
  125. package/sidecar/dist/src/capture/checkout.js +12 -5
  126. package/sidecar/dist/src/capture/deep-walk.d.ts +25 -0
  127. package/sidecar/dist/src/capture/deep-walk.js +41 -0
  128. package/sidecar/dist/src/capture/deno-project.d.ts +22 -0
  129. package/sidecar/dist/src/capture/deno-project.js +48 -1
  130. package/sidecar/dist/src/capture/index.d.ts +3 -1
  131. package/sidecar/dist/src/capture/index.js +14 -4
  132. package/sidecar/dist/src/capture/machinery.d.ts +8 -53
  133. package/sidecar/dist/src/capture/machinery.js +10 -157
  134. package/sidecar/dist/src/capture/node-builder.d.ts +6 -0
  135. package/sidecar/dist/src/capture/self-check.d.ts +7 -0
  136. package/sidecar/dist/src/capture/self-check.js +44 -1
  137. package/sidecar/dist/src/capture/site-node.d.ts +166 -0
  138. package/sidecar/dist/src/capture/site-node.js +570 -0
  139. package/sidecar/dist/src/capture/tool-env.d.ts +12 -0
  140. package/sidecar/dist/src/capture/tool-env.js +26 -0
  141. package/sidecar/dist/src/default-library.d.ts +39 -0
  142. package/sidecar/dist/src/default-library.js +132 -0
  143. package/sidecar/dist/src/definition-resolver.js +2 -0
  144. package/sidecar/dist/src/index.js +1 -1
  145. package/sidecar/dist/src/library-claims.d.ts +2 -0
  146. package/sidecar/dist/src/library-claims.js +387 -37
  147. package/sidecar/dist/src/node-index.d.ts +2 -0
  148. package/sidecar/dist/src/node-index.js +5 -1
  149. package/sidecar/dist/src/position-rows.d.ts +78 -7
  150. package/sidecar/dist/src/position-rows.js +343 -18
  151. package/sidecar/dist/src/project-loader.d.ts +3 -3
  152. package/sidecar/dist/src/project-loader.js +18 -9
  153. package/sidecar/dist/src/retype.d.ts +13 -0
  154. package/sidecar/dist/src/retype.js +126 -0
  155. package/sidecar/dist/src/type-inferrer.d.ts +47 -145
  156. package/sidecar/dist/src/type-inferrer.js +102 -529
  157. package/sidecar/dist/src/types.d.ts +64 -2
  158. package/sidecar/dist/src/validators.d.ts +806 -142
  159. package/sidecar/dist/src/validators.js +12 -1
@@ -1,62 +1,17 @@
1
1
  /**
2
- * Framework-machinery detection for the v2 capture path (carrick#371).
2
+ * The capture's origin gate for the machinery test (carrick#371).
3
3
  *
4
- * A producer response anchor whose resolved type IS or CONTAINS HTTP transport
5
- * machinery — a fetch/DOM `Response`/`Request`, a Node `http.ServerResponse`, a
6
- * wrapper envelope `{ response: Response; error?: undefined } | { ...; error }`,
7
- * or a wrapper function `(req: Request) => Promise<Response>` — must never be
8
- * emitted as a comparable contract. Comparing it against the consumer's real
9
- * payload manufactures a false compat mismatch (the bug this module fixes).
10
- *
11
- * This is the raw-`ts` seam mirror of `type-inferrer.ts`'s
12
- * `typeIsOrContainsResponseMachinery` (ts-morph): the capture/ seam forbids
13
- * importing a module from outside it, so the canonical indicator set and the
14
- * detection shape are duplicated here in lockstep — the same pattern by which
15
- * `BUILTIN_ANCHOR_SYMBOLS` mirrors `socket_io.rs`. Detection is STRUCTURAL and
16
- * framework-agnostic: no framework NAME appears, only the shared HTTP-message
17
- * member surface, gated by a lib / installed-dependency declaration origin so a
18
- * user payload that merely shares a member name can never trip it.
4
+ * The test itself is `typeIsOrContainsMachinery` in `site-node.ts`, the one
5
+ * the inferrer runs too (carrick#3500). What the capture hands it is where a
6
+ * declaration comes from, read off the program alone: the capture builds each
7
+ * program once and never edits it.
19
8
  */
20
9
  import ts from 'typescript';
21
10
  /**
22
- * Strongly-discriminating member names of HTTP transport machinery. Kept
23
- * identical to `MACHINERY_MEMBER_INDICATORS` in `type-inferrer.ts`. These are
24
- * the names no JSON payload carries (`ok`, `redirected`, `bodyUsed`,
25
- * `writeHead`, ...), so the origin gate + threshold never fire on real data.
26
- * Exported so a drift-guard test (`machinery-indicator-mirror.test.ts`) asserts
27
- * it stays equal to the `type-inferrer.ts` copy — nothing else enforces the
28
- * lockstep, and if the two drift one path silently stops abstaining.
29
- */
30
- export declare const MACHINERY_MEMBER_INDICATORS: Set<string>;
31
- /**
32
- * True when `type`, resolved against `node`, IS or CONTAINS framework
33
- * machinery.
34
- *
35
- * DETECTS, exactly:
36
- * 1. the type itself is machinery (`isFrameworkMachinery`);
37
- * 2. a union/intersection member is machinery (the envelope union);
38
- * 3. a DIRECT property whose type is machinery (`{ response: Response }`),
39
- * ONE level of descent only;
40
- * 4. a CALL SIGNATURE whose AWAITED return type is machinery — the wrapper
41
- * function `(req) => Promise<Response>` the Infer fallback resolves to.
42
- * (Only the call return is awaited; property types below are not.)
43
- *
44
- * DELIBERATELY NOT DETECTED — stated so this comment never overstates the
45
- * guarantee (mirrors the same list in `type-inferrer.ts`). Each is a
46
- * non-regression (pre-existing verdict unchanged, never a new wrong one), a
47
- * tracked follow-up:
48
- * - machinery nested deeper than one property level;
49
- * - a PROPERTY typed `Promise<Response>` (property types are not awaited /
50
- * Promise-unwrapped before the check — only call-signature returns are);
51
- * - an array element type: `Response[]` is not descended to its element;
52
- * - `interface X extends Response` declared in USER source — the origin gate
53
- * is lib/installed-dependency only, so a user-declared subtype reads as a real
54
- * contract.
55
- *
56
- * The depth cap + origin gate keep a legitimate payload that merely references a
57
- * machinery type far inside from over-abstaining.
11
+ * True when `type`, resolved in `program`, IS or CONTAINS framework
12
+ * machinery, its origin read for the service at `repoRoot`.
58
13
  */
59
- export declare function typeIsOrContainsMachinery(program: ts.Program, type: ts.Type, node: ts.Node, repoRoot: string): boolean;
14
+ export declare function typeIsOrContainsMachinery(program: ts.Program, type: ts.Type, repoRoot: string): boolean;
60
15
  /**
61
16
  * True when a declaration's source file is runtime/library origin rather than
62
17
  * user source. Four answers, in order:
@@ -1,139 +1,19 @@
1
1
  /**
2
- * Framework-machinery detection for the v2 capture path (carrick#371).
2
+ * The capture's origin gate for the machinery test (carrick#371).
3
3
  *
4
- * A producer response anchor whose resolved type IS or CONTAINS HTTP transport
5
- * machinery — a fetch/DOM `Response`/`Request`, a Node `http.ServerResponse`, a
6
- * wrapper envelope `{ response: Response; error?: undefined } | { ...; error }`,
7
- * or a wrapper function `(req: Request) => Promise<Response>` — must never be
8
- * emitted as a comparable contract. Comparing it against the consumer's real
9
- * payload manufactures a false compat mismatch (the bug this module fixes).
10
- *
11
- * This is the raw-`ts` seam mirror of `type-inferrer.ts`'s
12
- * `typeIsOrContainsResponseMachinery` (ts-morph): the capture/ seam forbids
13
- * importing a module from outside it, so the canonical indicator set and the
14
- * detection shape are duplicated here in lockstep — the same pattern by which
15
- * `BUILTIN_ANCHOR_SYMBOLS` mirrors `socket_io.rs`. Detection is STRUCTURAL and
16
- * framework-agnostic: no framework NAME appears, only the shared HTTP-message
17
- * member surface, gated by a lib / installed-dependency declaration origin so a
18
- * user payload that merely shares a member name can never trip it.
4
+ * The test itself is `typeIsOrContainsMachinery` in `site-node.ts`, the one
5
+ * the inferrer runs too (carrick#3500). What the capture hands it is where a
6
+ * declaration comes from, read off the program alone: the capture builds each
7
+ * program once and never edits it.
19
8
  */
20
- import ts from 'typescript';
21
9
  import { isInsideCheckout } from './checkout.js';
10
+ import { typeIsOrContainsMachinery as siteTypeIsOrContainsMachinery } from './site-node.js';
22
11
  /**
23
- * Strongly-discriminating member names of HTTP transport machinery. Kept
24
- * identical to `MACHINERY_MEMBER_INDICATORS` in `type-inferrer.ts`. These are
25
- * the names no JSON payload carries (`ok`, `redirected`, `bodyUsed`,
26
- * `writeHead`, ...), so the origin gate + threshold never fire on real data.
27
- * Exported so a drift-guard test (`machinery-indicator-mirror.test.ts`) asserts
28
- * it stays equal to the `type-inferrer.ts` copy — nothing else enforces the
29
- * lockstep, and if the two drift one path silently stops abstaining.
30
- */
31
- export const MACHINERY_MEMBER_INDICATORS = new Set([
32
- // fetch / DOM Response & Request body-consumer surface
33
- 'ok',
34
- 'redirected',
35
- 'bodyUsed',
36
- 'arrayBuffer',
37
- 'blob',
38
- 'formData',
39
- 'clone',
40
- 'json',
41
- 'statusText',
42
- // FROZEN (old path, 2026-10-21): the reply-object half below only (the
43
- // fetch half above and the threshold stay). Deletions and safety fixes
44
- // only. Fixes for wrong or missing types go in labelled reply objects
45
- // (carrick#2472 C4) and the language library rows (carrick#2445). Delete
46
- // when a delete-and-replay on the four repos moves no row wrongly, after
47
- // carrick-cloud#2379 and carrick#2445 (carrick#2472, C6).
48
- // Node http ServerResponse / reply-object surface
49
- 'statusCode',
50
- 'statusMessage',
51
- 'setHeader',
52
- 'getHeader',
53
- 'removeHeader',
54
- 'writeHead',
55
- 'flushHeaders',
56
- ]);
57
- /** Machinery needs at least this many indicator members to be recognized. */
58
- const MACHINERY_INDICATOR_THRESHOLD = 3;
59
- /**
60
- * True when `type`, resolved against `node`, IS or CONTAINS framework
61
- * machinery.
62
- *
63
- * DETECTS, exactly:
64
- * 1. the type itself is machinery (`isFrameworkMachinery`);
65
- * 2. a union/intersection member is machinery (the envelope union);
66
- * 3. a DIRECT property whose type is machinery (`{ response: Response }`),
67
- * ONE level of descent only;
68
- * 4. a CALL SIGNATURE whose AWAITED return type is machinery — the wrapper
69
- * function `(req) => Promise<Response>` the Infer fallback resolves to.
70
- * (Only the call return is awaited; property types below are not.)
71
- *
72
- * DELIBERATELY NOT DETECTED — stated so this comment never overstates the
73
- * guarantee (mirrors the same list in `type-inferrer.ts`). Each is a
74
- * non-regression (pre-existing verdict unchanged, never a new wrong one), a
75
- * tracked follow-up:
76
- * - machinery nested deeper than one property level;
77
- * - a PROPERTY typed `Promise<Response>` (property types are not awaited /
78
- * Promise-unwrapped before the check — only call-signature returns are);
79
- * - an array element type: `Response[]` is not descended to its element;
80
- * - `interface X extends Response` declared in USER source — the origin gate
81
- * is lib/installed-dependency only, so a user-declared subtype reads as a real
82
- * contract.
83
- *
84
- * The depth cap + origin gate keep a legitimate payload that merely references a
85
- * machinery type far inside from over-abstaining.
86
- */
87
- export function typeIsOrContainsMachinery(program, type, node, repoRoot) {
88
- const scope = { program, checker: program.getTypeChecker(), repoRoot };
89
- return isOrContains(scope, type, node, 0);
90
- }
91
- function isOrContains(scope, type, node, depth) {
92
- const { checker } = scope;
93
- if (isFrameworkMachinery(scope, type)) {
94
- return true;
95
- }
96
- if (type.isUnion() || type.isIntersection()) {
97
- return type.types.some((part) => isOrContains(scope, part, node, depth));
98
- }
99
- if (depth >= 1) {
100
- return false;
101
- }
102
- // A wrapper function value: descend into its (awaited) return type.
103
- for (const sig of checker.getSignaturesOfType(type, ts.SignatureKind.Call)) {
104
- const returnType = sig.getReturnType();
105
- const awaited = checker.getAwaitedType?.(returnType) ?? returnType;
106
- if (isOrContains(scope, awaited, node, depth + 1)) {
107
- return true;
108
- }
109
- }
110
- // Direct properties: the `{ response: Response; error }` envelope shape.
111
- for (const prop of checker.getPropertiesOfType(type)) {
112
- const propType = checker.getTypeOfSymbolAtLocation(prop, node);
113
- if (isOrContains(scope, propType, node, depth + 1)) {
114
- return true;
115
- }
116
- }
117
- return false;
118
- }
119
- /**
120
- * True when `type` itself is an HTTP-machinery type: it structurally carries at
121
- * least `MACHINERY_INDICATOR_THRESHOLD` of the indicator members AND its symbol
122
- * is declared in a lib or installed-dependency origin.
12
+ * True when `type`, resolved in `program`, IS or CONTAINS framework
13
+ * machinery, its origin read for the service at `repoRoot`.
123
14
  */
124
- function isFrameworkMachinery(scope, type) {
125
- let hits = 0;
126
- for (const prop of scope.checker.getPropertiesOfType(type)) {
127
- if (MACHINERY_MEMBER_INDICATORS.has(prop.getName())) {
128
- hits += 1;
129
- if (hits >= MACHINERY_INDICATOR_THRESHOLD)
130
- break;
131
- }
132
- }
133
- if (hits < MACHINERY_INDICATOR_THRESHOLD) {
134
- return false;
135
- }
136
- return symbolIsLibOrExternalOrigin(scope, type.getSymbol() ?? type.aliasSymbol);
15
+ export function typeIsOrContainsMachinery(program, type, repoRoot) {
16
+ return siteTypeIsOrContainsMachinery(program.getTypeChecker(), type, (sourceFile) => isExternalOrigin(program, sourceFile, repoRoot));
137
17
  }
138
18
  /**
139
19
  * True when a declaration's source file is runtime/library origin rather than
@@ -176,30 +56,3 @@ export function isExternalOrigin(program, sourceFile, repoRoot) {
176
56
  }
177
57
  return program.isSourceFileFromExternalLibrary(sourceFile) && !isInsideCheckout(file, repoRoot);
178
58
  }
179
- /**
180
- * True when the symbol is declared in a runtime/library origin. Works on a bare
181
- * checkout: the DOM `Response`/`Request` resolve from the bundled
182
- * `lib.dom.d.ts` even with no installed dependencies.
183
- */
184
- function symbolIsLibOrExternalOrigin(scope, symbol) {
185
- if (!symbol) {
186
- return false;
187
- }
188
- for (const decl of symbol.getDeclarations() ?? []) {
189
- if (isExternalOrigin(scope.program, decl.getSourceFile(), scope.repoRoot)) {
190
- return true;
191
- }
192
- }
193
- if (symbol.flags & ts.SymbolFlags.Alias) {
194
- try {
195
- const aliased = scope.checker.getAliasedSymbol(symbol);
196
- if (aliased && aliased !== symbol) {
197
- return symbolIsLibOrExternalOrigin(scope, aliased);
198
- }
199
- }
200
- catch {
201
- // Ignore errors when resolving the aliased symbol.
202
- }
203
- }
204
- return false;
205
- }
@@ -48,6 +48,12 @@ export interface UndeclaredSubstitution {
48
48
  name: string;
49
49
  path: string;
50
50
  }
51
+ export interface InternalTypeChecker extends ts.TypeChecker {
52
+ isSymbolAccessible(symbol: ts.Symbol, enclosingDeclaration: ts.Node | undefined, meaning: ts.SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): {
53
+ accessibility: number;
54
+ };
55
+ typeToTypeNode(type: ts.Type, enclosingDeclaration: ts.Node | undefined, flags: ts.NodeBuilderFlags | undefined, internalFlags?: number, tracker?: unknown): ts.TypeNode | undefined;
56
+ }
51
57
  /**
52
58
  * Print `type` as a type node anchored at `destination` (a declaration inside
53
59
  * the surface entry file). Returns untrusted-failure instead of text whenever
@@ -83,3 +83,10 @@ export declare function selfCheckStub(args: SelfCheckArgs): CaptureAliasRecord[]
83
83
  * `lib.dom.d.ts` is skipped, and the judge counts any stub diagnostic.
84
84
  */
85
85
  export declare const SELF_CHECK_OPTIONS: Readonly<ts.CompilerOptions>;
86
+ /**
87
+ * Whether a stub tree file declares into global scope, so that a program
88
+ * loading it beside another stub changes what that stub's names mean
89
+ * (carrick#1047 J-R5): a script (no import or export), or a module that
90
+ * declares a global or module augmentation.
91
+ */
92
+ export declare function isGlobalScopeFile(source: ts.SourceFile): boolean;
@@ -35,7 +35,7 @@ import ts from 'typescript';
35
35
  import { createHash } from 'node:crypto';
36
36
  import * as fs from 'node:fs';
37
37
  import * as path from 'node:path';
38
- import { findAugmentationFiles } from './augmentations.js';
38
+ import { declaresAugmentation, findAugmentationFiles } from './augmentations.js';
39
39
  import { sidecarCompilerOptions } from './compiler-options.js';
40
40
  import { collectSpecifiers, declarationCandidates, isDeclarationFileName, isRelative, packageNameOf, } from './specifiers.js';
41
41
  import { repairDanglingImports } from './repair-dangling.js';
@@ -344,6 +344,18 @@ function literalMarks(request) {
344
344
  ...(request.absent_body_tolerated ? { absent_body_tolerated: true } : {}),
345
345
  };
346
346
  }
347
+ /**
348
+ * Why an untyped alias is untyped (carrick#3995), which only the index reads:
349
+ * never a verdict input, never in `surface_hash`. The driver's cause on a
350
+ * literal it sent as a placeholder wins: it knows no value was located, which
351
+ * a demotion of that placeholder does not undo. Otherwise the cause the
352
+ * capture decided at the anchor, of any kind.
353
+ */
354
+ function unreadCause(anchor) {
355
+ const cause = (anchor.request.kind === 'literal' ? anchor.request.unread_cause : undefined) ??
356
+ anchor.unreadCause;
357
+ return cause ? { unread_cause: cause } : {};
358
+ }
347
359
  /** An alias that never reached a capture-native tier: the failure reason was
348
360
  * recorded at demotion time; the surface line is `unknown` by construction. */
349
361
  function demotedRecord(anchor) {
@@ -365,6 +377,7 @@ function demotedRecord(anchor) {
365
377
  ? { unresolved_in_tree: [unemittedModuleProvenance()] }
366
378
  : {}),
367
379
  ...literalMarks(anchor.request),
380
+ ...unreadCause(anchor),
368
381
  };
369
382
  }
370
383
  function checkedRecord(anchor, ctx) {
@@ -376,6 +389,8 @@ function checkedRecord(anchor, ctx) {
376
389
  // placeholder out because the check heals a pinned external; what the index
377
390
  // publishes is this tree, so the record says where it does not resolve.
378
391
  let unresolvedPaths = [];
392
+ // The alias's own type is a genuine `any`/`unknown` (carrick#4046).
393
+ let rootStatesTopType = false;
379
394
  const seeds = [];
380
395
  let statementText;
381
396
  if (ctx.surfaceSource) {
@@ -393,6 +408,11 @@ function checkedRecord(anchor, ctx) {
393
408
  else if (isErrorPlaceholder(type)) {
394
409
  unresolvedPaths = [''];
395
410
  }
411
+ else if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
412
+ // A genuine root `any`/`unknown`, not TypeScript's unresolved-reference
413
+ // placeholder and not `never` (carrick#4046).
414
+ rootStatesTopType = true;
415
+ }
396
416
  // Seed the closure with the alias's own import-type targets.
397
417
  const visit = (node) => {
398
418
  if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument)) {
@@ -462,6 +482,9 @@ function checkedRecord(anchor, ctx) {
462
482
  // phase must pre-gate exactly these: its probe gates are whole-type only and
463
483
  // cannot see a member-level any.
464
484
  let unexplainedDeep = [];
485
+ // Located, and the type is itself a bare `any`/`unknown` nothing explains
486
+ // away: the declaration states it (carrick#4046).
487
+ let declaredTop = false;
465
488
  const deep = deepFindings[0];
466
489
  if (internalFailure) {
467
490
  outcome = 'decayed_internal';
@@ -499,6 +522,7 @@ function checkedRecord(anchor, ctx) {
499
522
  }
500
523
  else {
501
524
  // Root top type with no external explanation.
525
+ declaredTop = rootStatesTopType;
502
526
  outcome = 'decayed_internal';
503
527
  detail = 'alias resolved to a top type with no allowlisted external failure';
504
528
  }
@@ -549,6 +573,16 @@ function checkedRecord(anchor, ctx) {
549
573
  }
550
574
  : {}),
551
575
  ...literalMarks(anchor.request),
576
+ // An abstain keeps its own reason (stated, or none): its `unknown` is
577
+ // this layer's wording, not a type the source declares. So does a literal
578
+ // whose text is the driver's `unknown` placeholder.
579
+ ...(declaredTop &&
580
+ !anchor.abstainReason &&
581
+ !(anchor.request.kind === 'literal' && anchor.request.type_text.trim() === 'unknown') &&
582
+ !unreadCause(anchor).unread_cause
583
+ ? { unread_cause: 'declared' }
584
+ : {}),
585
+ ...unreadCause(anchor),
552
586
  };
553
587
  return statementText === undefined
554
588
  ? record
@@ -557,6 +591,15 @@ function checkedRecord(anchor, ctx) {
557
591
  surface_hash: surfaceHash(record, statementText, closure, ctx),
558
592
  };
559
593
  }
594
+ /**
595
+ * Whether a stub tree file declares into global scope, so that a program
596
+ * loading it beside another stub changes what that stub's names mean
597
+ * (carrick#1047 J-R5): a script (no import or export), or a module that
598
+ * declares a global or module augmentation.
599
+ */
600
+ export function isGlobalScopeFile(source) {
601
+ return !ts.isExternalModule(source) || declaresAugmentation(source);
602
+ }
560
603
  /**
561
604
  * A tree file in global scope reaches every alias the judge loads beside
562
605
  * it, closure or not: a script (no import or export), a file that declares
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Where a site is, and whether its type is framework machinery: one answer for
3
+ * the inferrer and the capture (carrick#3500).
4
+ *
5
+ * Both find the node a locator's text names near its line, then refuse to
6
+ * publish a type that is HTTP transport machinery. Each used to keep its own
7
+ * copy, and the copies disagreed (string quotes in the locator, which shapes
8
+ * of machinery were refused), so a wrong node or a transport type could be
9
+ * published by one path and refused by the other. They share the text rule
10
+ * here: the inferrer runs `nodeByLocatorText`, the capture an exact match
11
+ * alone (`firstExactLocatorMatch`). The module lives inside `capture/`
12
+ * because that bundle may import only itself and `typescript`; the inferrer
13
+ * reaches it through `capture/index.js` and hands it compiler nodes.
14
+ */
15
+ import ts from 'typescript';
16
+ /**
17
+ * Strongly-discriminating member names of HTTP transport machinery: a
18
+ * fetch/DOM `Response` & `Request`, a Node `http.ServerResponse`, a framework
19
+ * reply object. A type declared in a lib or installed-dependency origin that
20
+ * carries a subset of these is framework machinery, never a user contract: the
21
+ * PRODUCER-side structural mirror of the consumer `machineryIndicators`
22
+ * (ExtractionConfig), used to reject a wrapper envelope whose response field is
23
+ * a raw `Response` (carrick#371) instead of emitting it as a comparable type.
24
+ *
25
+ * Framework-agnostic by construction: no framework NAME appears here, only the
26
+ * shared HTTP-message surface. The names are deliberately the ones no
27
+ * JSON payload ever carries (`ok`, `redirected`, `bodyUsed`, `arrayBuffer`,
28
+ * `writeHead`, ...), so the origin gate + `MACHINERY_INDICATOR_THRESHOLD` never
29
+ * fire on real data.
30
+ */
31
+ export declare const MACHINERY_MEMBER_INDICATORS: Set<string>;
32
+ /**
33
+ * Whether a declaration's file is the runtime's or an installed package's
34
+ * rather than the user's. The caller answers it: the inferrer reads the
35
+ * resolver's record beside the program (`origin.ts`), the capture reads the
36
+ * program alone (`machinery.ts`).
37
+ */
38
+ export type DeclaredOutside = (sourceFile: ts.SourceFile) => boolean;
39
+ /**
40
+ * True when `type` itself is an HTTP-machinery type: it structurally carries
41
+ * at least `MACHINERY_INDICATOR_THRESHOLD` DISTINCT indicator members (own and
42
+ * apparent), AND its symbol is declared in a lib or installed-dependency
43
+ * origin. Both gates are required: the indicator subset alone essentially
44
+ * never matches a JSON payload, and the origin gate keeps a user's own type
45
+ * that shares those member names from reading as machinery.
46
+ */
47
+ export declare function isFrameworkMachinery(checker: ts.TypeChecker, type: ts.Type, declaredOutside: DeclaredOutside): boolean;
48
+ /**
49
+ * True when one of the symbol's declarations is outside the user's source, or
50
+ * the declaration an import alias stands for is. Works on a bare checkout:
51
+ * the DOM `Response`/`Request` resolve from the bundled `lib.dom.d.ts` even
52
+ * with no installed dependencies.
53
+ */
54
+ export declare function symbolDeclaredOutside(checker: ts.TypeChecker, symbol: ts.Symbol | undefined, declaredOutside: DeclaredOutside): boolean;
55
+ /**
56
+ * True when `type` IS or CONTAINS framework machinery: a type that resolves
57
+ * here is never a comparable contract, so a path that reads it abstains
58
+ * (honest `unknown`) rather than publish a concrete-but-false type.
59
+ *
60
+ * DETECTS, exactly:
61
+ * 1. the type itself is machinery (`isFrameworkMachinery`);
62
+ * 2. a union/intersection member is machinery (the envelope union
63
+ * `{ response: Response; error?: undefined } | { ...; error: Error }`);
64
+ * 3. a DIRECT property whose type is machinery (`{ response: Response }`),
65
+ * ONE level of descent only, including a property no declaration states
66
+ * (a mapped `Record<'response', Response>`);
67
+ * 4. a CALL SIGNATURE whose AWAITED return type is machinery: the wrapper
68
+ * function `(req) => Promise<Response>`.
69
+ *
70
+ * DELIBERATELY NOT DETECTED (carrick#447), stated so this comment never
71
+ * overstates the guarantee. Each leaves the pre-existing verdict in place:
72
+ * - machinery nested deeper than one level;
73
+ * - a PROPERTY typed `Promise<Response>` (only call-signature returns are
74
+ * awaited);
75
+ * - an array element type: `Response[]` is not descended to its element;
76
+ * - `interface X extends Response` declared in USER source: the origin gate
77
+ * is lib/installed-dependency only.
78
+ *
79
+ * The depth cap + origin gate keep a legitimate payload that merely references
80
+ * a machinery type far inside from over-abstaining.
81
+ */
82
+ export declare function typeIsOrContainsMachinery(checker: ts.TypeChecker, type: ts.Type, declaredOutside: DeclaredOutside): boolean;
83
+ /**
84
+ * Source text with every plain string literal written in double quotes:
85
+ * `'/a'`, `"/a"` and an interpolation-free `` `/a` `` are one value, so text
86
+ * that differs only in its quotes compares equal (carrick#2056).
87
+ *
88
+ * The text is read left to right, pairing quotes the way the scanner does,
89
+ * so a template's closing backtick never pairs with the next template's
90
+ * opening one. A literal holding a quote, a backslash or an interpolation is
91
+ * copied as it is, and so is an unterminated one with everything after it.
92
+ */
93
+ export declare function canonicalStringQuotes(text: string): string;
94
+ /**
95
+ * The text the capture's exact match compares: whitespace collapsed
96
+ * (`collapseLocatorWhitespace`), trimmed, and every plain string literal in
97
+ * double quotes (carrick#2056). Unlike `normalizeLocatorText` it keeps
98
+ * trailing commas and the space after an opening bracket, so a payload written
99
+ * over several lines is not matched by a compact print of it (see
100
+ * `firstExactLocatorMatch`).
101
+ */
102
+ export declare function exactLocatorText(text: string): string;
103
+ /**
104
+ * Normalize whitespace for text comparison, the inferrer's rule:
105
+ * `collapseLocatorWhitespace`, then trim.
106
+ *
107
+ * Also strips trailing commas before `}` `)` `]`: multi-line source
108
+ * literals carry them but the LLM's single-line locator print does not,
109
+ * and that one comma used to defeat exact AND containment matching for
110
+ * the payload and every enclosing node (#335). Applied symmetrically to
111
+ * node text and target, so both sides compare equal.
112
+ *
113
+ * Also strips the space left AFTER `(` `[` `{` by the collapse: a
114
+ * multi-line call whose arguments start on the next line normalizes to
115
+ * `f( x)` while the LLM's compact print is `f(x)`, and that one space
116
+ * defeated exact matching for the call and every enclosing node — the
117
+ * opening-delimiter mirror of the #335 trailing comma (#336). Symmetric
118
+ * for the same reason.
119
+ *
120
+ * A string literal reads the same in any quotes (carrick#2056).
121
+ */
122
+ export declare function normalizeLocatorText(text: string): string;
123
+ /**
124
+ * The capture's locator: the first node in pre-order that `accept`s, whose
125
+ * text equals the locator's (`exactLocatorText`), and that ends on or after
126
+ * `fromLine` (a chain broken before its dot starts a line above the line the
127
+ * analyzer reports for the call), anywhere in the file.
128
+ *
129
+ * Exact only, with no line window: the capture publishes the type of the node
130
+ * it binds, and each of `nodeByLocatorText`'s further tiers moved published
131
+ * answers when the capture ran them (carrick#3500): a body read stated at a
132
+ * handler's opening line bound the whole handler, and a compact print of a
133
+ * multi-line payload bound the payload where the call on its line was asked.
134
+ * A text with no exact match leaves the caller its line fallback.
135
+ */
136
+ export declare function firstExactLocatorMatch(sourceFile: ts.SourceFile, expressionText: string, fromLine: number | undefined, accept: (node: ts.Node) => boolean): ts.Node | undefined;
137
+ /**
138
+ * The node a locator's text names, among `nodes`, near `lineNumber`.
139
+ *
140
+ * Normalizes whitespace once per candidate, then tries an exact match, then a
141
+ * locator that elides members, then a node containing the text (preferring
142
+ * the nodes the text opens), then a node the text contains. Among several,
143
+ * the smallest node wins, then the one nearest the line. The caller chooses
144
+ * the candidates (every node, or only calls). The inferrer's locator; the
145
+ * capture runs `firstExactLocatorMatch`.
146
+ */
147
+ export declare function nodeByLocatorText<T extends ts.Node>(sourceFile: ts.SourceFile, nodes: readonly T[], expressionText: string, lineNumber?: number, searchRadius?: number): T | undefined;
148
+ /**
149
+ * What a locator's text names, read off its own parse (carrick#2056):
150
+ *
151
+ * - `texts`: the normalized text of the expression it names and of each
152
+ * wrapper it carries around it (`return`, a `const x =` binding, a label,
153
+ * `await`, parentheses, a cast, `satisfies`, `!`). A node strictly inside
154
+ * that expression is not among them;
155
+ * - `rootKind` and `rootStart`: the innermost of those, its kind, and where
156
+ * its text starts in the locator.
157
+ *
158
+ * `null` when the text does not parse as one expression or one statement:
159
+ * there is no structure to read, and the caller keeps its text rule.
160
+ * Exported for the reference walk in `infer-line-index.test.ts`.
161
+ */
162
+ export declare function locatorNames(normalizedTarget: string): {
163
+ texts: Set<string>;
164
+ rootKind: ts.SyntaxKind;
165
+ rootStart: number;
166
+ } | null;