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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carrick",
3
- "version": "0.3.153",
3
+ "version": "0.3.155",
4
4
  "carrickCache": {
5
5
  "cache_version": 22,
6
6
  "intent_cache_version": 2
@@ -115,11 +115,11 @@
115
115
  "zod": "^3.23.0"
116
116
  },
117
117
  "optionalDependencies": {
118
- "@carrick-tools/cli-darwin-arm64": "0.3.153",
119
- "@carrick-tools/cli-darwin-x64": "0.3.153",
120
- "@carrick-tools/cli-linux-arm64": "0.3.153",
121
- "@carrick-tools/cli-linux-x64": "0.3.153",
122
- "@carrick-tools/cli-win32-x64": "0.3.153"
118
+ "@carrick-tools/cli-darwin-arm64": "0.3.155",
119
+ "@carrick-tools/cli-darwin-x64": "0.3.155",
120
+ "@carrick-tools/cli-linux-arm64": "0.3.155",
121
+ "@carrick-tools/cli-linux-x64": "0.3.155",
122
+ "@carrick-tools/cli-win32-x64": "0.3.155"
123
123
  },
124
124
  "devDependencies": {
125
125
  "@types/node": "^24.13.3"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "carrick",
3
3
  "description": "Claude Code plugin for Carrick, which indexes TypeScript codebases across service and repository boundaries. After each edit it adds the file's routes, calls, and cross-service type mismatches to the session, and it registers Carrick's language server. It pairs with the Carrick MCP server, which lets agents search functions by intent rather than name.",
4
- "version": "0.3.153",
4
+ "version": "0.3.155",
5
5
  "author": {
6
6
  "name": "Carrick",
7
7
  "email": "hello@carrick.tools"
@@ -20,6 +20,26 @@
20
20
  "timeout": 5
21
21
  }
22
22
  ]
23
+ },
24
+ {
25
+ "matcher": "Bash",
26
+ "hooks": [
27
+ {
28
+ "type": "command",
29
+ "command": "carrick hook post-bash",
30
+ "timeout": 15
31
+ }
32
+ ]
33
+ },
34
+ {
35
+ "matcher": "Grep|Glob|mcp__.*",
36
+ "hooks": [
37
+ {
38
+ "type": "command",
39
+ "command": "carrick hook post-search",
40
+ "timeout": 5
41
+ }
42
+ ]
23
43
  }
24
44
  ],
25
45
  "SessionStart": [
@@ -38,9 +58,30 @@
38
58
  "hooks": [
39
59
  {
40
60
  "type": "command",
41
- "command": "carrick hook stop --wait-s 200",
42
- "timeout": 210,
43
- "statusMessage": "Carrick: waiting for the re-check of your last edit"
61
+ "command": "carrick hook stop",
62
+ "timeout": 10
63
+ }
64
+ ]
65
+ }
66
+ ],
67
+ "SubagentStop": [
68
+ {
69
+ "hooks": [
70
+ {
71
+ "type": "command",
72
+ "command": "carrick hook subagent-stop",
73
+ "timeout": 5
74
+ }
75
+ ]
76
+ }
77
+ ],
78
+ "UserPromptSubmit": [
79
+ {
80
+ "hooks": [
81
+ {
82
+ "type": "command",
83
+ "command": "carrick hook user-prompt",
84
+ "timeout": 5
44
85
  }
45
86
  ]
46
87
  }
@@ -427,6 +427,26 @@ print_failed_log() {
427
427
  fi
428
428
  }
429
429
 
430
+ # npm's first error line in a failed attempt's log, on one line for the
431
+ # warning: the root's path made relative, URL credentials and npm token forms
432
+ # (`_authToken=`, `_auth=`, `Authorization: Bearer|token`) redacted, capped.
433
+ # Prints nothing when the log has none (another manager, or a timeout).
434
+ first_npm_error() {
435
+ local log="$1" root="$2" line literal_root delim
436
+ [ -f "$log" ] || return 0
437
+ # The root matches as text: a `.` or `+` in the path is not a pattern. The
438
+ # expression's delimiter is a control byte, which no path carries.
439
+ literal_root=$(printf '%s' "$root" | sed -e 's/[][\.*^$|+?(){}]/\\&/g')
440
+ delim=$(printf '\001')
441
+ line=$(grep -m1 -E '^npm (error|ERR!)' "$log" | tr -d '\000-\037' | sed -E \
442
+ -e "s${delim}${literal_root}${delim}.${delim}g" \
443
+ -e 's|//[^/@ ]*@|//|g' \
444
+ -e 's|(_authToken=)[^[:space:]]+|\1<redacted>|g' \
445
+ -e 's|(_auth=)[^[:space:]]+|\1<redacted>|g' \
446
+ -e 's#([Aa]uthorization: *([Bb]earer|[Tt]oken) +)[^[:space:]]+#\1<redacted>#g')
447
+ printf '%.200s' "$line"
448
+ }
449
+
430
450
  # The files a lockfile-tolerant retry may rewrite, per manager.
431
451
  retry_guarded_files() {
432
452
  case "$1" in
@@ -474,7 +494,7 @@ yarn_is_berry() {
474
494
  }
475
495
 
476
496
  cmd_install_one() {
477
- local root="$1" manager="$2" log status refusal strict_cmd="" no_retry="" snap="" before=""
497
+ local root="$1" manager="$2" log status refusal strict_cmd="" no_retry="" snap="" before="" npm_error="" retry_error=""
478
498
  if [ "$manager" != "deno" ] && { [ -f "$root/deno.json" ] || [ -f "$root/deno.jsonc" ]; }; then
479
499
  # Mixed roots need the global Deno cache AND the Node compiler's local
480
500
  # install. Neither preparation executes authorized project lifecycle code.
@@ -581,6 +601,7 @@ cmd_install_one() {
581
601
  fi
582
602
 
583
603
  print_failed_log "$log"
604
+ npm_error=$(first_npm_error "$log" "$root")
584
605
 
585
606
  # One lockfile-tolerant retry (CARRICK_INSTALL_LOCKFILE_RETRY=1). A timeout
586
607
  # is not retried: a second attempt would only spend the limit again.
@@ -611,6 +632,8 @@ cmd_install_one() {
611
632
  return 0
612
633
  fi
613
634
  print_failed_log "$log"
635
+ retry_error=$(first_npm_error "$log" "$root")
636
+ [ -n "$retry_error" ] && npm_error="$retry_error"
614
637
  fi
615
638
 
616
639
  # A root that ends uninstalled keeps no node_modules the attempts created:
@@ -625,7 +648,7 @@ cmd_install_one() {
625
648
  if [ $status -eq 124 ] || [ $status -eq 137 ]; then
626
649
  warn "Carrick's dependency install ($manager) in $root hit the ${INSTALL_TIMEOUT_SECONDS}s limit; the scan will refuse that service rather than index \`any\` through its packages."
627
650
  else
628
- warn "Carrick's dependency install ($manager) in $root failed (exit $status); the scan will refuse that service rather than index \`any\` through its packages."
651
+ warn "Carrick's dependency install ($manager) in $root failed (exit $status)${npm_error:+: $npm_error}; the scan will refuse that service rather than index \`any\` through its packages."
629
652
  fi
630
653
  return 0
631
654
  }
@@ -5,7 +5,7 @@
5
5
  * or a recorded demotion -- never a silently wrong line.
6
6
  */
7
7
  import ts from 'typescript';
8
- import type { CaptureAnchorRequest, InferAnchorRequest } from './api.js';
8
+ import type { CaptureAnchorRequest, InferAnchorRequest, TypeProvenanceReason } from './api.js';
9
9
  import type { UnresolvedAtAnchor } from './deep-walk.js';
10
10
  export interface ResolvedAnchor {
11
11
  request: CaptureAnchorRequest;
@@ -55,6 +55,17 @@ export interface ResolvedAnchor {
55
55
  * record states for a literal anchor, whose text is what the index serves.
56
56
  */
57
57
  namesUnemittedModule?: true;
58
+ /**
59
+ * carrick#3995: why the alias is untyped, decided here: `machinery_envelope`
60
+ * for a demotion off framework machinery, `site_unreadable` for every other
61
+ * demotion, `not_located` for an abstain because the anchor named no
62
+ * payload, `no_success_payload` for a response table with no success row.
63
+ * Absent on a typed alias and on an abstain decided from the code whose
64
+ * reason is stated elsewhere. A located bare `any`/`unknown` with no cause
65
+ * here is stamped `declared` by the self-check (carrick#4046). Recorded as the record's `unread_cause`,
66
+ * which only the index reads: never a verdict input, never in `surface_hash`.
67
+ */
68
+ unreadCause?: TypeProvenanceReason;
58
69
  }
59
70
  /**
60
71
  * Repo-root-relative source file -> the specifier the surface entry imports
@@ -8,6 +8,7 @@ import ts from 'typescript';
8
8
  import * as path from 'node:path';
9
9
  import { printTypeForDestination, substituteUndeclaredNames, undeclaredNamesIn, } from './node-builder.js';
10
10
  import { typeIsOrContainsMachinery } from './machinery.js';
11
+ import { firstExactLocatorMatch } from './site-node.js';
11
12
  import { readResultLabel } from './result-label.js';
12
13
  import { installedPackageSpecifier } from './installed-package.js';
13
14
  import { realPath } from './service-config.js';
@@ -64,16 +65,17 @@ export function moduleExport(checker, sourceFile, name) {
64
65
  */
65
66
  export function resolveAnchor(program, request, args) {
66
67
  const checker = program.getTypeChecker();
67
- const demote = (reason) => ({
68
+ const demote = (reason, cause) => ({
68
69
  request,
69
70
  aliasText: 'unknown',
70
71
  serialization: 'structural_fallback',
71
72
  failureReason: reason,
73
+ unreadCause: cause,
72
74
  });
73
75
  if (request.kind === 'literal') {
74
76
  const text = request.type_text.trim();
75
77
  if (!text) {
76
- return demote('empty literal type text');
78
+ return demote('empty literal type text', 'site_unreadable');
77
79
  }
78
80
  const bareIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(text);
79
81
  const siblingSpec = bareIdentifier
@@ -126,13 +128,13 @@ export function resolveAnchor(program, request, args) {
126
128
  const sourceAbs = resolveSourceFile(args.repoRoot, request.source_file);
127
129
  const sourceFile = program.getSourceFile(sourceAbs);
128
130
  if (!sourceFile) {
129
- return demote(`source file not in program: ${request.source_file}`);
131
+ return demote(`source file not in program: ${request.source_file}`, 'site_unreadable');
130
132
  }
131
133
  const spec = entryRelativeSpecifier(args.entryDir, args.repoRoot, request.source_file, args.resolveFromEntry);
132
134
  if (request.kind === 'symbol') {
133
135
  const exported = moduleExport(checker, sourceFile, request.symbol_name);
134
136
  if (!exported) {
135
- return demote(`'${request.symbol_name}' is not an export of ${request.source_file}`);
137
+ return demote(`'${request.symbol_name}' is not an export of ${request.source_file}`, 'site_unreadable');
136
138
  }
137
139
  // The anchor is the ELEMENT symbol; array_depth restores the use-site's
138
140
  // `[]` levels (#248/#306) so an array-vs-scalar mismatch stays visible.
@@ -162,7 +164,7 @@ export function resolveAnchor(program, request, args) {
162
164
  // emitting a surface line that references a value in type position.
163
165
  return demote(`'${request.symbol_name}' is a value export with no type-space meaning, ` +
164
166
  `and no sibling type alias derives from it (e.g. \`typeof ${request.symbol_name}\`); ` +
165
- 'demoted so the surface line stays valid');
167
+ 'demoted so the surface line stays valid', 'site_unreadable');
166
168
  }
167
169
  const arrayDepth = Math.max(0, request.array_depth ?? 0);
168
170
  const declared = checker.getDeclaredTypeOfSymbol(resolvedExport);
@@ -181,6 +183,8 @@ export function resolveAnchor(program, request, args) {
181
183
  serialization: 'structural_fallback',
182
184
  abstainReason: `'${request.symbol_name}' is a response table keyed by status code with no ` +
183
185
  'success row that states a body, so this consumer states no response contract',
186
+ // carrick#4046: no success body is the reason, not a declared `unknown`.
187
+ unreadCause: 'no_success_payload',
184
188
  };
185
189
  }
186
190
  if (table?.kind === 'body') {
@@ -212,21 +216,21 @@ export function resolveAnchor(program, request, args) {
212
216
  // Design-doc Capture step 1 guards, all three verified failure modes.
213
217
  const exported = moduleExport(checker, sourceFile, request.symbol_name);
214
218
  if (!exported) {
215
- return demote(`handler '${request.symbol_name}' is not an export of ${request.source_file}`);
219
+ return demote(`handler '${request.symbol_name}' is not an export of ${request.source_file}`, 'site_unreadable');
216
220
  }
217
221
  const declaration = exported.valueDeclaration ?? exported.declarations?.[0];
218
222
  const handlerType = checker.getTypeOfSymbolAtLocation(exported, declaration ?? sourceFile);
219
223
  const callSignatures = handlerType.getCallSignatures();
220
224
  if (callSignatures.length === 0) {
221
- return demote(`handler '${request.symbol_name}' has no call signatures`);
225
+ return demote(`handler '${request.symbol_name}' has no call signatures`, 'site_unreadable');
222
226
  }
223
227
  if (callSignatures.length > 1) {
224
228
  // ReturnType<> silently resolves the LAST overload only.
225
- return demote(`handler '${request.symbol_name}' is an overload set (${callSignatures.length} signatures)`);
229
+ return demote(`handler '${request.symbol_name}' is an overload set (${callSignatures.length} signatures)`, 'site_unreadable');
226
230
  }
227
231
  if ((callSignatures[0].getTypeParameters() ?? []).length > 0) {
228
232
  // Type parameters erase to their constraint/unknown under ReturnType<>.
229
- return demote(`handler '${request.symbol_name}' is generic`);
233
+ return demote(`handler '${request.symbol_name}' is generic`, 'site_unreadable');
230
234
  }
231
235
  const returned = callSignatures[0].getReturnType();
232
236
  const unresolved = unresolvedAtAnchor(program, sourceFile, checker.getAwaitedType(returned) ?? returned, declaration ?? sourceFile);
@@ -248,13 +252,13 @@ export function resolveAnchor(program, request, args) {
248
252
  const param = locateHandlerParam(sourceFile, request, request.param_name);
249
253
  if (!param) {
250
254
  return demote(`no handler parameter '${request.param_name}' resolved in ` +
251
- `${request.source_file} (${paramLocatorHints(request)})`);
255
+ `${request.source_file} (${paramLocatorHints(request)})`, 'site_unreadable');
252
256
  }
253
257
  return finishInferAnchor(program, sourceFile, request, param, args.placeholder, undefined, args.repoRoot);
254
258
  }
255
259
  const found = locate(sourceFile, request);
256
260
  if (!found) {
257
- return demote(locatorFailureReason(request));
261
+ return demote(locatorFailureReason(request), 'site_unreadable');
258
262
  }
259
263
  // carrick#1785: the line fallback takes the first expression on the line,
260
264
  // and a declaration's NAME is an expression to `ts.isExpression`. On a line
@@ -275,6 +279,7 @@ export function resolveAnchor(program, request, args) {
275
279
  `${describeNode(sourceFile, request.source_file, declaration)}; a ` +
276
280
  `declaration's name is not a payload, so the anchor abstains rather ` +
277
281
  `than publish the declared entity's own type`,
282
+ unreadCause: 'not_located',
278
283
  };
279
284
  }
280
285
  }
@@ -292,7 +297,7 @@ export function resolveAnchor(program, request, args) {
292
297
  let reaimNote;
293
298
  const builderReaim = reaimBuilderChainPayload(checker, located);
294
299
  if (builderReaim.kind === 'demote') {
295
- return demote(builderReaim.reason);
300
+ return demote(builderReaim.reason, 'site_unreadable');
296
301
  }
297
302
  if (builderReaim.kind === 'reaim') {
298
303
  located = builderReaim.node;
@@ -308,11 +313,12 @@ export function resolveAnchor(program, request, args) {
308
313
  */
309
314
  function finishInferAnchor(program, sourceFile, request, located, placeholder, reaimNote, repoRoot) {
310
315
  const checker = program.getTypeChecker();
311
- const demote = (reason) => ({
316
+ const demote = (reason, cause) => ({
312
317
  request,
313
318
  aliasText: 'unknown',
314
319
  serialization: 'structural_fallback',
315
320
  failureReason: reason,
321
+ unreadCause: cause,
316
322
  });
317
323
  const rawType = checker.getTypeAtLocation(located);
318
324
  let type = rawType;
@@ -387,6 +393,7 @@ function finishInferAnchor(program, sourceFile, request, located, placeholder, r
387
393
  `bare top type ('${checker.typeToString(type)}'); the anchor names no ` +
388
394
  `payload span, expression or parameter, so it abstains rather than ` +
389
395
  `publish a top type as a contract`,
396
+ unreadCause: 'not_located',
390
397
  };
391
398
  }
392
399
  // carrick#371 fail-closed guard: a producer anchor whose resolved type IS or
@@ -400,16 +407,16 @@ function finishInferAnchor(program, sourceFile, request, located, placeholder, r
400
407
  // type. No source locator points at a distinct clean payload here (the payload
401
408
  // lives inside the wrapper's response builder), so degrade to `unknown` —
402
409
  // abstain, never a concrete verdict off the machinery.
403
- if (typeIsOrContainsMachinery(program, type, located, repoRoot)) {
410
+ if (typeIsOrContainsMachinery(program, type, repoRoot)) {
404
411
  return demote('resolved type is or contains framework machinery (Response/Request-shaped); ' +
405
- 'degraded to unknown rather than emit a wrapper envelope as a response contract');
412
+ 'degraded to unknown rather than emit a wrapper envelope as a response contract', 'machinery_envelope');
406
413
  }
407
414
  if (!placeholder) {
408
- return demote('internal: no placeholder destination for infer anchor');
415
+ return demote('internal: no placeholder destination for infer anchor', 'site_unreadable');
409
416
  }
410
417
  const printed = printTypeForDestination(program, type, placeholder);
411
418
  if (!printed.text) {
412
- return demote(printed.failure ?? 'node builder print failed');
419
+ return demote(printed.failure ?? 'node builder print failed', 'site_unreadable');
413
420
  }
414
421
  const atAnchor = unresolvedAtAnchor(program, sourceFile, type, located);
415
422
  // carrick#1377: a member the print named undeclared and this rewrote to
@@ -1241,38 +1248,12 @@ function tightestCoveringNode(sourceFile, start, end) {
1241
1248
  return best;
1242
1249
  }
1243
1250
  /**
1244
- * Locator text with insignificant whitespace removed: runs collapse to one
1245
- * space, and a member chain broken before its dot (`client\n .list(…)`) reads
1246
- * as `client.list(…)` (carrick#1162), the same rule the v1 inferrer applies.
1251
+ * The node a locator's text names: the first exact match on or after the line
1252
+ * among the nodes a value type can be read at (`firstExactLocatorMatch`,
1253
+ * carrick#3500).
1247
1254
  */
1248
- function normalizeLocatorText(text) {
1249
- return text
1250
- .replace(/\s+/g, ' ')
1251
- .replace(/\s*(\?\.|\.)\s*/g, '$1')
1252
- .trim();
1253
- }
1254
1255
  function nodeByExpressionText(sourceFile, text, fromLine) {
1255
- const wanted = normalizeLocatorText(text);
1256
- let best;
1257
- const visit = (node) => {
1258
- if (best)
1259
- return;
1260
- if (isPreferredTarget(node)) {
1261
- const nodeText = normalizeLocatorText(node.getText(sourceFile));
1262
- if (nodeText === wanted) {
1263
- // On or after the line, or COVERING it: a chain broken before its dot
1264
- // starts a line above the line the analyzer reports for the call.
1265
- const endLine = sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1;
1266
- if (fromLine === undefined || endLine >= fromLine) {
1267
- best = node;
1268
- return;
1269
- }
1270
- }
1271
- }
1272
- node.forEachChild(visit);
1273
- };
1274
- visit(sourceFile);
1275
- return best;
1256
+ return firstExactLocatorMatch(sourceFile, text, fromLine, isPreferredTarget);
1276
1257
  }
1277
1258
  function firstExpressionOnLine(sourceFile, line) {
1278
1259
  let best;
@@ -102,6 +102,11 @@ export interface LiteralAnchorRequest {
102
102
  * reads it.
103
103
  */
104
104
  absent_body_tolerated?: true;
105
+ /**
106
+ * carrick#3995: why the text is a placeholder, when the driver knows.
107
+ * Copied onto the alias's record; no verdict reads it.
108
+ */
109
+ unread_cause?: TypeProvenanceReason;
105
110
  }
106
111
  /**
107
112
  * The declaration a bare name in printed type text meant (carrick#1836).
@@ -241,10 +246,17 @@ export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal
241
246
  * name) that builds a new value from it, and nothing in the chain states
242
247
  * the body, so the value the chain ends in is not the response the call
243
248
  * receives and no contract is published (carrick#3004).
249
+ * - `not_located`: the scan found no value in the code for this payload, so
250
+ * no type was read for it: no request located one, or the only locator was
251
+ * a line (carrick#3995).
252
+ * - `site_unreadable`: the scan located the site, but the compiler could not
253
+ * read a type at it (carrick#3995).
254
+ * - `unplaced_top_type`: the printed shape holds a top type at a member no
255
+ * layer placed (carrick#3995). Stamped at the entry's root.
244
256
  * - `not_recorded`: the position carries a top type and this layer has no
245
257
  * cause for it.
246
258
  */
247
- export type TypeProvenanceReason = 'declared' | 'unresolved_import' | 'budget_exhausted' | 'no_payload_evidence' | 'machinery_envelope' | 'coerced_input' | 'no_success_payload' | 'no_request_body' | 'projected_value_only' | 'serialised_body_unread' | 'body_built_by_callee' | 'reshaped_by_callback' | 'result_member_missing' | 'not_recorded';
259
+ export type TypeProvenanceReason = 'declared' | 'unresolved_import' | 'budget_exhausted' | 'no_payload_evidence' | 'machinery_envelope' | 'coerced_input' | 'no_success_payload' | 'no_request_body' | 'projected_value_only' | 'serialised_body_unread' | 'body_built_by_callee' | 'reshaped_by_callback' | 'result_member_missing' | 'not_located' | 'site_unreadable' | 'unplaced_top_type' | 'not_recorded';
248
260
  /**
249
261
  * One `any`/`unknown` finding inside a captured or inferred type, with its
250
262
  * position and its cause. Sorted by `path` wherever a list is emitted, so the
@@ -358,6 +370,14 @@ export interface CaptureAliasRecord {
358
370
  * type alone.
359
371
  */
360
372
  absent_body_tolerated?: true;
373
+ /**
374
+ * carrick#3995: why the alias is untyped. A literal anchor's own
375
+ * `unread_cause` when the driver sent one, otherwise the cause the capture
376
+ * decided at the anchor (`machinery_envelope`, `site_unreadable`,
377
+ * `not_located`). Read only to say why the entry is untyped: never a
378
+ * verdict input, never in `surface_hash`.
379
+ */
380
+ unread_cause?: TypeProvenanceReason;
361
381
  /**
362
382
  * carrick#3135: lowercase hex SHA-256 of everything the judge reads for
363
383
  * this alias from its own stub: the alias's `export type` statement, every
@@ -582,6 +602,13 @@ export interface CheckVerdict {
582
602
  * observation as a verdict.
583
603
  */
584
604
  notes: string[];
605
+ /**
606
+ * On a `foreign:<side>` verdict only (carrick#1047 J1-1): why that side
607
+ * could not be judged. `hit`: its type reads another service's
608
+ * declaration. `budget`: the walk ran out of budget before it could rule
609
+ * one out. `no_program`: no program could be built to walk it in.
610
+ */
611
+ foreign_kind?: 'hit' | 'budget' | 'no_program';
585
612
  }
586
613
  /**
587
614
  * A service degraded SERVICE-WIDE: install failure, or a stub-tree diagnostic
@@ -617,6 +644,19 @@ export interface CheckResult {
617
644
  * signal, or a non-zero exit with no parseable diagnostics): every pair is then
618
645
  * unverifiable, and this says whether it died of memory (carrick#2209). */
619
646
  compiler_end?: CompilerEnd;
647
+ /** Wall time of each phase of a check that ran to its end, in whole
648
+ * milliseconds. For the scanner's log only: no verdict reads it. Absent on
649
+ * every early return (carrick#1047). */
650
+ phase_ms?: CheckPhaseMs;
651
+ }
652
+ /** Where a check's time went (carrick#1047). */
653
+ export interface CheckPhaseMs {
654
+ assemble: number;
655
+ probes: number;
656
+ install: number;
657
+ tsc: number;
658
+ probe_program: number;
659
+ classify: number;
620
660
  }
621
661
  /** How the check's compiler process ended. */
622
662
  export interface CompilerEnd {
@@ -12,6 +12,8 @@
12
12
  * one silently corrupts the closure. Cheap syntactic prefilter first, real
13
13
  * parse only on candidates.
14
14
  */
15
+ import ts from 'typescript';
16
+ export declare function declaresAugmentation(sourceFile: ts.SourceFile): boolean;
15
17
  /**
16
18
  * Absolute paths of files in `fileNames` that declare global or module
17
19
  * augmentations. Files that fail to read/parse are skipped (they will fail
@@ -15,7 +15,7 @@
15
15
  import ts from 'typescript';
16
16
  import * as fs from 'node:fs';
17
17
  const PREFILTER = /declare\s+(?:global|module)\b/;
18
- function declaresAugmentation(sourceFile) {
18
+ export function declaresAugmentation(sourceFile) {
19
19
  // Augmentations only have their augmentation semantics inside a module;
20
20
  // in a script file `declare module "x"` is an ambient module declaration,
21
21
  // which the closure treatment still wants shipped when present.
@@ -7,6 +7,8 @@
7
7
  * classifying by diagnostic code + file + line (never by line position alone):
8
8
  *
9
9
  * poison (stub-file diagnostic) -> unverifiable [highest precedence]
10
+ * a side reads another service's -> unverifiable (foreign:<side>,
11
+ * declaration (or could not rule it out) carrick#1047)
10
12
  * surface import error (probe lines 1-2)-> unverifiable
11
13
  * IsAny gate fired (TS2344) -> gate_caught_baked_any
12
14
  * IsUnknown/IsNever gate fired (TS2344) -> unverifiable
@@ -34,7 +36,7 @@
34
36
  import type { CheckVerdict } from './api.js';
35
37
  import { type ProbePlan, type Side } from './check-probe.js';
36
38
  import { type ScrubContext } from './check-scrub.js';
37
- import type { PairDeepFindings } from './check-deep.js';
39
+ import type { PairDeepFindings, PairForeignFindings } from './check-deep.js';
38
40
  import type { DispatchUnion } from './check-union.js';
39
41
  import { type PairFieldReport } from './check-fields.js';
40
42
  export interface RawDiagnostic {
@@ -88,6 +90,11 @@ export interface ClassifyInput {
88
90
  * JSON body that is a string.
89
91
  */
90
92
  rawTextSide?: Side;
93
+ /**
94
+ * What each side reads of another service's declarations (carrick#1047
95
+ * J1-1). Absent when neither side can reach one.
96
+ */
97
+ foreign?: PairForeignFindings;
91
98
  }
92
99
  /** Classify one pair into exactly one bucket, honouring the precedence order. */
93
100
  export declare function classifyPair(input: ClassifyInput): CheckVerdict;
@@ -98,3 +105,7 @@ export declare function classifyPair(input: ClassifyInput): CheckVerdict;
98
105
  export declare const CONSUMER_WIDER_NOTE: string;
99
106
  /** The note on a pair whose consumer reads no response body (carrick#1162). */
100
107
  export declare const CONSUMER_READS_NO_BODY_NOTE = "the consumer reads no response body (its expected response is void), so the producer response is not compared with a read";
108
+ /** carrick#1047 J1-1: a side's type reads a declaration `other` declares. */
109
+ export declare function foreignHitReason(side: Side, other: string): string;
110
+ /** carrick#1047 J1-1: no program could be built to rule that out. */
111
+ export declare function foreignUnwalkedReason(side: Side): string;
@@ -7,6 +7,8 @@
7
7
  * classifying by diagnostic code + file + line (never by line position alone):
8
8
  *
9
9
  * poison (stub-file diagnostic) -> unverifiable [highest precedence]
10
+ * a side reads another service's -> unverifiable (foreign:<side>,
11
+ * declaration (or could not rule it out) carrick#1047)
10
12
  * surface import error (probe lines 1-2)-> unverifiable
11
13
  * IsAny gate fired (TS2344) -> gate_caught_baked_any
12
14
  * IsUnknown/IsNever gate fired (TS2344) -> unverifiable
@@ -119,6 +121,34 @@ export function classifyPair(input) {
119
121
  };
120
122
  }
121
123
  }
124
+ // 1b. A side whose type reads a declaration only another service declares
125
+ // (carrick#1047 J1-1): a global merged in from a stub loaded beside it.
126
+ // Each service compiles alone, so neither compiles that type, and the
127
+ // verdict would hang on which other pairs this run probed. A walk that
128
+ // could not rule it out fails closed. The producer is named first, as
129
+ // poison names it.
130
+ for (const side of ['producer', 'consumer']) {
131
+ const found = input.foreign?.[side];
132
+ if (!found)
133
+ continue;
134
+ const service = plan.spec[side].service_name;
135
+ const [kind, reason] = found === 'unwalked'
136
+ ? ['no_program', foreignUnwalkedReason(side)]
137
+ : 'exhaustedAt' in found
138
+ ? [
139
+ 'budget',
140
+ `the ${side} type is too deep or wide to verify at ${found.exhaustedAt === '<root>' ? 'its root' : `'${found.exhaustedAt}'`}`,
141
+ ]
142
+ : ['hit', foreignHitReason(side, found.service)];
143
+ return {
144
+ ...base,
145
+ bucket: 'unverifiable',
146
+ gate: `foreign:${side}`,
147
+ diagnostic: foreignDiagnostic(service, typeof found !== 'string' && 'service' in found ? found.service : undefined),
148
+ ...notAFact(reason, side),
149
+ foreign_kind: kind,
150
+ };
151
+ }
122
152
  // 2. Surface import error (missing/renamed export): probe import lines.
123
153
  const importDiag = probeDiags.find((d) => plan.importLines.includes(d.line));
124
154
  if (importDiag) {
@@ -481,3 +511,16 @@ function factness(input, strict = false) {
481
511
  }
482
512
  return { resolved: true };
483
513
  }
514
+ /** carrick#1047 J1-1: a side's type reads a declaration `other` declares. */
515
+ export function foreignHitReason(side, other) {
516
+ return `the ${side} type uses declarations from '${other}'`;
517
+ }
518
+ /** carrick#1047 J1-1: no program could be built to rule that out. */
519
+ export function foreignUnwalkedReason(side) {
520
+ return `the ${side} type may use declarations from another service`;
521
+ }
522
+ function foreignDiagnostic(service, other) {
523
+ return other === undefined
524
+ ? `the type for '${service}' may use declarations from another service that '${service}' never compiles with; compatibility cannot be verified.`
525
+ : `the type for '${service}' uses declarations from '${other}', which '${service}' never compiles with; compatibility cannot be verified.`;
526
+ }
@@ -22,7 +22,8 @@
22
22
  */
23
23
  import ts from 'typescript';
24
24
  import type { TypeProvenance } from './api.js';
25
- import { type ProbePlan } from './check-probe.js';
25
+ import { type ProbePlan, type Side } from './check-probe.js';
26
+ import type { AssembledWorkspace } from './check-workspace.js';
26
27
  /** Deep findings for one pair, per probe side. */
27
28
  export interface PairDeepFindings {
28
29
  sent: TypeProvenance[];
@@ -52,3 +53,45 @@ export declare function openProbeProgram(probesDir: string, plans: ProbePlan[]):
52
53
  * as unresolved rather than resolved.
53
54
  */
54
55
  export declare function probeDeepFindings(opened: ProbeProgram | undefined, plans: ProbePlan[]): Map<string, PairDeepFindings>;
56
+ /**
57
+ * What one side of a pair reads of another service's declarations
58
+ * (carrick#1047 J1-1): the first position and the service that declares it,
59
+ * where the walk ran out of budget before it could rule one out, or
60
+ * `unwalked` when no program could be built to walk it in.
61
+ */
62
+ export type SideForeign = {
63
+ service: string;
64
+ path: string;
65
+ } | {
66
+ exhaustedAt: string;
67
+ } | 'unwalked';
68
+ /** Per side of a pair; a side absent here reads only its own service. */
69
+ export type PairForeignFindings = Partial<Record<Side, SideForeign>>;
70
+ /**
71
+ * Which probed sides read a declaration that only another service declares
72
+ * (carrick#1047 J1-1).
73
+ *
74
+ * Each service compiles alone. The judge loads every probed stub into one
75
+ * program, so a global-scope file of one stub (a script, a `declare global`, a
76
+ * module augmentation) can merge into a name another stub's type reads, and
77
+ * that type is then one neither service compiles. A side can only read
78
+ * another stub's declaration through such a file: a stub that names a sibling
79
+ * by its package name does not resolve in this workspace (carrick#2970). So a
80
+ * side is walked only when the program holds a global-scope file of another
81
+ * stub, and otherwise costs nothing.
82
+ *
83
+ * A declaration in another stub's tree is not foreign when its text equals a
84
+ * declaration of the same symbol in the side's own tree: a typing file two
85
+ * services both carry says the same thing in each.
86
+ *
87
+ * Nor is one that merges into a built-in global, one TypeScript's default
88
+ * library declares (`interface Array<T>`, `Date`, `Promise`), unless it lies
89
+ * in the tree of the pair's other side. Both sides read the same built-in in
90
+ * the judge's program, so a third service's augmentation of it cannot move
91
+ * the verdict; the other side's can, as that side's own compile has it and
92
+ * this side's does not.
93
+ *
94
+ * Fails closed. A walk out of budget is `exhaustedAt`; a run with no program
95
+ * whose workspace holds another stub's global-scope file is `unwalked`.
96
+ */
97
+ export declare function pairForeignFindings(opened: ProbeProgram | undefined, plans: ProbePlan[], ws: AssembledWorkspace): Map<string, PairForeignFindings>;