carrick 0.3.135 → 0.3.137

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carrick",
3
- "version": "0.3.135",
3
+ "version": "0.3.137",
4
4
  "carrickCache": {
5
5
  "cache_version": 22,
6
6
  "intent_cache_version": 2
@@ -114,11 +114,11 @@
114
114
  "zod": "^3.23.0"
115
115
  },
116
116
  "optionalDependencies": {
117
- "@carrick-tools/cli-darwin-arm64": "0.3.135",
118
- "@carrick-tools/cli-darwin-x64": "0.3.135",
119
- "@carrick-tools/cli-linux-arm64": "0.3.135",
120
- "@carrick-tools/cli-linux-x64": "0.3.135",
121
- "@carrick-tools/cli-win32-x64": "0.3.135"
117
+ "@carrick-tools/cli-darwin-arm64": "0.3.137",
118
+ "@carrick-tools/cli-darwin-x64": "0.3.137",
119
+ "@carrick-tools/cli-linux-arm64": "0.3.137",
120
+ "@carrick-tools/cli-linux-x64": "0.3.137",
121
+ "@carrick-tools/cli-win32-x64": "0.3.137"
122
122
  },
123
123
  "devDependencies": {
124
124
  "@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.135",
4
+ "version": "0.3.137",
5
5
  "author": {
6
6
  "name": "Carrick",
7
7
  "email": "hello@carrick.tools"
@@ -75,6 +75,21 @@
75
75
  # Unset, the script behaves as it always has: on a developer's own CI the
76
76
  # tree is theirs. `action.yml` leaves it unset.
77
77
  #
78
+ # CARRICK_INSTALL_LOCKFILE_RETRY=1 is the hosted runner's lane policy (carrick#3069),
79
+ # separate from the posture above. Unset, nothing here changes. Set, a strict
80
+ # install that fails with anything but a timeout (124, 137) is retried once, with
81
+ # lifecycle scripts still disabled, the same time limit and every untrusted guard:
82
+ # npm npm ci -> npm install --ignore-scripts --no-audit --no-fund --no-save
83
+ # pnpm install --frozen-lockfile -> install --no-frozen-lockfile --ignore-scripts [--ignore-pnpmfile]
84
+ # yarn classic as above -> yarn install --pure-lockfile --ignore-scripts
85
+ # bun as above -> bun install --ignore-scripts --no-save
86
+ # Not retried: Yarn Berry (no install mode that reads the lockfile without writing
87
+ # it; zero-install repos commit what a mutable install writes) and Deno (the
88
+ # pre-flight asks only when `nodeModulesDir` is set, and no failing frozen
89
+ # install has been seen). The tree stays the commit: the lockfile, package.json
90
+ # and pnpm-workspace.yaml are restored byte for byte after the retry, and a root
91
+ # that ends uninstalled keeps no node_modules directory the attempts created.
92
+ #
78
93
  # CARRICK_CLI names the Carrick to ask for the services. `action.yml` writes a
79
94
  # wrapper for whichever copy the run resolved, npm package or release asset.
80
95
  # Deliberately NOT `CARRICK_BIN`: that variable names a scanner BINARY to the
@@ -88,6 +103,9 @@ INSTALL_TIMEOUT_SECONDS="${CARRICK_INSTALL_TIMEOUT:-300}"
88
103
  # Set by a machine that scans repositories it does not own; see the header.
89
104
  UNTRUSTED="${CARRICK_INSTALL_UNTRUSTED:-}"
90
105
 
106
+ # Set by the hosted runner; see the header. A lane policy, separate from UNTRUSTED.
107
+ LOCKFILE_RETRY="${CARRICK_INSTALL_LOCKFILE_RETRY:-}"
108
+
91
109
  # The delimiter for the one multi-line step output this script writes. A
92
110
  # workflow reads `cache_dirs` as the `path:` of actions/cache, which takes one
93
111
  # directory per line, and a plain `key=value` line cannot carry that.
@@ -393,13 +411,70 @@ yarn_untrusted_refusal() {
393
411
  echo "$answer"
394
412
  }
395
413
 
414
+ # A failed attempt's log: the first 30 lines (npm puts the cause of a refusal
415
+ # there and follows it with usage text), a marker only when lines were cut,
416
+ # then the last 20. A log of 50 lines or fewer prints whole.
417
+ print_failed_log() {
418
+ local log="$1" total
419
+ [ -f "$log" ] || return 0
420
+ total=$(wc -l <"$log" | tr -d ' ')
421
+ if [ "$total" -le 50 ]; then
422
+ cat "$log"
423
+ else
424
+ head -n 30 "$log"
425
+ echo "... ($((total - 50)) lines omitted) ..."
426
+ tail -n 20 "$log"
427
+ fi
428
+ }
429
+
430
+ # The files a lockfile-tolerant retry may rewrite, per manager.
431
+ retry_guarded_files() {
432
+ case "$1" in
433
+ npm) echo "package-lock.json package.json" ;;
434
+ pnpm) echo "pnpm-lock.yaml package.json pnpm-workspace.yaml" ;;
435
+ yarn) echo "yarn.lock package.json" ;;
436
+ bun) echo "bun.lock bun.lockb package.json" ;;
437
+ esac
438
+ }
439
+
440
+ # Every `node_modules` directory under a root, one per line, sorted; `.git` and
441
+ # the `node_modules` found are not descended into.
442
+ node_modules_dirs() {
443
+ find "$1" -name .git -prune -o -name node_modules -type d -prune -print 2>/dev/null | sort
444
+ }
445
+
446
+ # The retry command for a manager, run through `run_install` like the strict
447
+ # one, with every untrusted-mode guard the strict install has.
448
+ run_retry_install() {
449
+ local root="$1" log="$2" manager="$3"
450
+ case "$manager" in
451
+ npm)
452
+ if [ -n "$UNTRUSTED" ]; then
453
+ npm_trusted_tools
454
+ run_install "$root" "$log" env "${NPM_TRUSTED_TOOLS[@]}" npm install --ignore-scripts --no-audit --no-fund --no-save
455
+ else
456
+ run_install "$root" "$log" npm install --ignore-scripts --no-audit --no-fund --no-save
457
+ fi
458
+ ;;
459
+ pnpm)
460
+ if [ -n "$UNTRUSTED" ]; then
461
+ run_install "$root" "$log" corepack pnpm install --no-frozen-lockfile --ignore-scripts --ignore-pnpmfile
462
+ else
463
+ run_install "$root" "$log" corepack pnpm install --no-frozen-lockfile --ignore-scripts
464
+ fi
465
+ ;;
466
+ yarn) run_install "$root" "$log" yarn install --pure-lockfile --ignore-scripts ;;
467
+ bun) run_install "$root" "$log" bun install --ignore-scripts --no-save ;;
468
+ esac
469
+ }
470
+
396
471
  # Yarn Berry's lockfile opens with a `__metadata` block; classic's does not.
397
472
  yarn_is_berry() {
398
473
  [ -f "$1/.yarnrc.yml" ] || grep -q '^__metadata:' "$1/yarn.lock" 2>/dev/null
399
474
  }
400
475
 
401
476
  cmd_install_one() {
402
- local root="$1" manager="$2" log status refusal
477
+ local root="$1" manager="$2" log status refusal strict_cmd="" no_retry="" snap="" before=""
403
478
  if [ "$manager" != "deno" ] && { [ -f "$root/deno.json" ] || [ -f "$root/deno.jsonc" ]; }; then
404
479
  # Mixed roots need the global Deno cache AND the Node compiler's local
405
480
  # install. Neither preparation executes authorized project lifecycle code.
@@ -411,8 +486,19 @@ cmd_install_one() {
411
486
  # reach the version the repo pins in `packageManager`.
412
487
  corepack enable >/dev/null 2>&1 || true
413
488
 
489
+ # Taken before the first attempt, so a retry that fails can remove what the
490
+ # attempts created and nothing else.
491
+ if [ -n "$LOCKFILE_RETRY" ]; then
492
+ before=$(mktemp "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/carrick-node-modules.XXXXXX") || before=""
493
+ [ -n "$before" ] && node_modules_dirs "$root" >"$before"
494
+ fi
495
+
414
496
  case "$manager" in
415
497
  deno)
498
+ # No retry: the pre-flight asks about a Deno service only when its config
499
+ # sets `nodeModulesDir`, and no failing `deno install --frozen` has been seen.
500
+ no_retry=1
501
+ strict_cmd="deno install --frozen"
416
502
  # A project can authorize lifecycle scripts through allowScripts in its
417
503
  # config. Deno has no --ignore-scripts: disabling node_modules is what
418
504
  # prevents those scripts from running, even for an authorizing config.
@@ -421,6 +507,7 @@ cmd_install_one() {
421
507
  status=$?
422
508
  ;;
423
509
  npm)
510
+ strict_cmd="npm ci"
424
511
  if [ -n "$UNTRUSTED" ]; then
425
512
  npm_trusted_tools
426
513
  run_install "$root" "$log" env "${NPM_TRUSTED_TOOLS[@]}" npm ci --ignore-scripts
@@ -430,6 +517,7 @@ cmd_install_one() {
430
517
  status=$?
431
518
  ;;
432
519
  pnpm)
520
+ strict_cmd="pnpm install --frozen-lockfile"
433
521
  if [ -n "$UNTRUSTED" ]; then
434
522
  # pnpm loads the tree's `.pnpmfile.cjs` on install unless told not to.
435
523
  run_install "$root" "$log" corepack pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfile
@@ -448,11 +536,19 @@ cmd_install_one() {
448
536
  # so the two lines are told apart by what the tree says they are,
449
537
  # never by which command happens to exit 0.
450
538
  if yarn_is_berry "$root"; then
539
+ # No retry: Berry has no install mode that reads the lockfile without
540
+ # writing it, a mutable install can write `.pnp.cjs` and `.yarn/cache`
541
+ # that zero-install repos commit, and lifting
542
+ # YARN_ENABLE_IMMUTABLE_INSTALLS undoes the guard from #2246/#2251.
543
+ no_retry=1
544
+ strict_cmd="yarn install --mode=skip-build"
451
545
  run_install "$root" "$log" yarn install --mode=skip-build
452
546
  elif [ -n "$UNTRUSTED" ]; then
453
547
  # Frozen, or classic rewrites yarn.lock.
548
+ strict_cmd="yarn install --frozen-lockfile"
454
549
  run_install "$root" "$log" yarn install --frozen-lockfile --ignore-scripts
455
550
  else
551
+ strict_cmd="yarn install"
456
552
  run_install "$root" "$log" yarn install --ignore-scripts
457
553
  fi
458
554
  status=$?
@@ -463,8 +559,10 @@ cmd_install_one() {
463
559
  return 0
464
560
  fi
465
561
  if [ -n "$UNTRUSTED" ]; then
562
+ strict_cmd="bun install --frozen-lockfile"
466
563
  run_install "$root" "$log" bun install --ignore-scripts --frozen-lockfile
467
564
  else
565
+ strict_cmd="bun install"
468
566
  run_install "$root" "$log" bun install --ignore-scripts
469
567
  fi
470
568
  status=$?
@@ -478,10 +576,52 @@ cmd_install_one() {
478
576
  if [ $status -eq 0 ]; then
479
577
  echo "Installed $root dependencies with $manager (lifecycle scripts disabled)."
480
578
  [ -f "$log" ] && tail -n 3 "$log"
579
+ [ -n "$before" ] && rm -f "$before"
481
580
  return 0
482
581
  fi
483
582
 
484
- [ -f "$log" ] && tail -n 20 "$log"
583
+ print_failed_log "$log"
584
+
585
+ # One lockfile-tolerant retry (CARRICK_INSTALL_LOCKFILE_RETRY=1). A timeout
586
+ # is not retried: a second attempt would only spend the limit again.
587
+ if [ -n "$LOCKFILE_RETRY" ] && [ -z "$no_retry" ] && [ $status -ne 124 ] && [ $status -ne 137 ]; then
588
+ echo "Carrick's lockfile install ($strict_cmd) in $root failed (exit $status); retrying once without the frozen lockfile, lifecycle scripts still disabled."
589
+ snap=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/carrick-retry-snapshot.XXXXXX") || snap=""
590
+ if [ -z "$snap" ]; then
591
+ warn "Carrick could not snapshot $root before retrying its install; the scan will refuse that service rather than index \`any\` through its packages."
592
+ [ -n "$before" ] && rm -f "$before"
593
+ return 0
594
+ fi
595
+ # The tree stays the commit: put the lockfile and manifests back byte for
596
+ # byte afterwards, whatever the retry did (pnpm rewrites its lockfile).
597
+ local file
598
+ for file in $(retry_guarded_files "$manager"); do
599
+ if [ -e "$root/$file" ]; then cp -p "$root/$file" "$snap/$file"; else : >"$snap/absent.$file"; fi
600
+ done
601
+ run_retry_install "$root" "$log" "$manager"
602
+ status=$?
603
+ for file in $(retry_guarded_files "$manager"); do
604
+ if [ -e "$snap/$file" ]; then cp -p "$snap/$file" "$root/$file"; else rm -f "$root/$file"; fi
605
+ done
606
+ rm -rf "$snap"
607
+ if [ $status -eq 0 ]; then
608
+ echo "Installed $root dependencies with $manager after its lockfile install failed; the lockfile and package.json in the tree are unchanged (lifecycle scripts disabled)."
609
+ [ -f "$log" ] && tail -n 3 "$log"
610
+ [ -n "$before" ] && rm -f "$before"
611
+ return 0
612
+ fi
613
+ print_failed_log "$log"
614
+ fi
615
+
616
+ # A root that ends uninstalled keeps no node_modules the attempts created:
617
+ # the pre-flight reads one as prepared, and the scan would read `any` silently.
618
+ if [ -n "$before" ]; then
619
+ local created
620
+ while IFS= read -r created; do
621
+ [ -n "$created" ] && rm -rf "$created"
622
+ done < <(node_modules_dirs "$root" | comm -13 "$before" -)
623
+ rm -f "$before"
624
+ fi
485
625
  if [ $status -eq 124 ] || [ $status -eq 137 ]; then
486
626
  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."
487
627
  else
@@ -236,10 +236,15 @@ export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal
236
236
  * into a function that builds the request body from it, and the body that
237
237
  * function builds cannot be typed, so the argument is not the body and no
238
238
  * contract is published (carrick#2628).
239
+ * - `reshaped_by_callback`: a consumer call's untyped result is handed
240
+ * unread to a callback in its chain (`.mapOk`, `.then`, `.andThen`, any
241
+ * name) that builds a new value from it, and nothing in the chain states
242
+ * the body, so the value the chain ends in is not the response the call
243
+ * receives and no contract is published (carrick#3004).
239
244
  * - `not_recorded`: the position carries a top type and this layer has no
240
245
  * cause for it.
241
246
  */
242
- 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' | 'result_member_missing' | 'not_recorded';
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';
243
248
  /**
244
249
  * One `any`/`unknown` finding inside a captured or inferred type, with its
245
250
  * position and its cause. Sorted by `path` wherever a list is emitted, so the
@@ -382,8 +387,12 @@ export interface CaptureStubResult {
382
387
  /** Number of emitted specifiers rewritten by the post-emit pass
383
388
  * (tsconfig-paths mappings and absolute internal import types). */
384
389
  specifier_rewrites: number;
385
- /** True when the source repo had no node_modules at capture time. */
390
+ /** True when the source repo had no node_modules at capture time, or a
391
+ * dependency its package.json declares does not resolve from the service
392
+ * root (carrick#2999). */
386
393
  bare_checkout: boolean;
394
+ /** The first few declared dependencies that did not resolve, sorted. */
395
+ unresolved_dependencies: string[];
387
396
  ts_version: string;
388
397
  errors: string[];
389
398
  }
@@ -601,6 +610,13 @@ export interface CheckOptions {
601
610
  * 7's native tsc (`judgeTscPath`). Tests inject a stand-in to pin the
602
611
  * abnormal-termination path. */
603
612
  tscPath?: string;
613
+ /** Total time cap for the workspace install, in ms (default 1800000, or
614
+ * `CARRICK_CHECK_INSTALL_TIMEOUT_MS`). Past it the install is killed and
615
+ * every pair reads unverifiable with gate `install:timeout` (carrick#3021). */
616
+ installTimeoutMs?: number;
617
+ /** Silence limit for the workspace install, in ms (default 120000): an
618
+ * install that prints nothing for this long is killed the same way. */
619
+ installIdleTimeoutMs?: number;
604
620
  /** Delete the scratch workspace before returning (default true). Tests that
605
621
  * inspect the assembled tree pass false. */
606
622
  cleanup?: boolean;
@@ -17,6 +17,38 @@
17
17
  import type { CheckOptions, CheckProgressPhase, CheckResult } from './api.js';
18
18
  import { type RawDiagnostic } from './check-classify.js';
19
19
  export type CheckProgress = (phase: CheckProgressPhase, message: string) => void;
20
+ interface SpawnResult {
21
+ code: number | null;
22
+ /** The signal that ended the process, when one did. */
23
+ signal: NodeJS.Signals | null;
24
+ stdout: string;
25
+ stderr: string;
26
+ /** Which time limit killed the process, when one did. */
27
+ timedOut: false | 'total' | 'idle';
28
+ }
29
+ /**
30
+ * The check install's limits (carrick#3021). A healthy install prints
31
+ * progress about once a second (longest gap measured: 1 s), so silence is the
32
+ * sign of a hang: the install is killed after `DEFAULT_INSTALL_IDLE_MS` with
33
+ * no output, and a total cap bounds one that keeps printing. Both are far
34
+ * above the slowest healthy run measured (54 s, install plus judge).
35
+ * `CARRICK_CHECK_INSTALL_TIMEOUT_MS` replaces the total cap.
36
+ */
37
+ export declare const DEFAULT_INSTALL_IDLE_MS = 120000;
38
+ export declare const DEFAULT_INSTALL_TIMEOUT_MS = 1800000;
39
+ /** The total cap: the option, else the environment, else the default. */
40
+ export declare function installTotalLimitMs(opt: number | undefined, env?: NodeJS.ProcessEnv): number;
41
+ /**
42
+ * Why the check install did not finish, as a gate and a sentence the verdicts
43
+ * carry. A hang and a refused connection are named apart from a plain failure.
44
+ */
45
+ export declare function installFailure(install: Pick<SpawnResult, 'timedOut' | 'stderr' | 'stdout'>, limits: {
46
+ idleMs: number;
47
+ totalMs: number;
48
+ }): {
49
+ gate: string;
50
+ reason: string;
51
+ };
20
52
  /**
21
53
  * Whether a process's stderr carries V8's fatal heap-exhaustion line
22
54
  * (`Reached heap limit`, `Ineffective mark-compacts near heap limit`, and the
@@ -113,3 +145,4 @@ export declare function judgeLabel(tscPath: string): string;
113
145
  /** Run the deterministic check phase. Async: install + tsc run off the event
114
146
  * loop so the sidecar stays responsive and can emit keepalive frames. */
115
147
  export declare function runCheck(opts: CheckOptions, onProgress?: CheckProgress): Promise<CheckResult>;
148
+ export {};
@@ -28,17 +28,104 @@ import { openProbeProgram, probeDeepFindings } from './check-deep.js';
28
28
  import { onlyDeclaredOpenAny } from './deep-walk.js';
29
29
  import { pairFieldReports } from './check-fields.js';
30
30
  import { pairDispatchUnions } from './check-union.js';
31
- function runProcess(command, args, cwd, env) {
31
+ function runProcess(command, args, cwd, env, limits) {
32
32
  return new Promise((resolve, reject) => {
33
- const child = spawn(command, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
33
+ const limited = limits?.totalMs !== undefined || limits?.idleMs !== undefined;
34
+ // With a limit the child leads its own process group, so the kill takes
35
+ // the package manager's workers with it and `close` can fire.
36
+ const child = spawn(command, args, {
37
+ cwd,
38
+ env,
39
+ stdio: ['ignore', 'pipe', 'pipe'],
40
+ detached: limited,
41
+ });
34
42
  let stdout = '';
35
43
  let stderr = '';
36
- child.stdout.on('data', (d) => (stdout += d.toString()));
37
- child.stderr.on('data', (d) => (stderr += d.toString()));
38
- child.on('error', reject);
39
- child.on('close', (code, signal) => resolve({ code, signal, stdout, stderr }));
44
+ let timedOut = false;
45
+ const kill = (kind) => {
46
+ timedOut = kind;
47
+ try {
48
+ process.kill(-child.pid, 'SIGKILL');
49
+ }
50
+ catch {
51
+ child.kill('SIGKILL');
52
+ }
53
+ };
54
+ const totalTimer = limits?.totalMs === undefined ? undefined : setTimeout(() => kill('total'), limits.totalMs);
55
+ let idleTimer;
56
+ const armIdle = () => {
57
+ if (limits?.idleMs === undefined)
58
+ return;
59
+ if (idleTimer)
60
+ clearTimeout(idleTimer);
61
+ idleTimer = setTimeout(() => kill('idle'), limits.idleMs);
62
+ };
63
+ const clearTimers = () => {
64
+ if (totalTimer)
65
+ clearTimeout(totalTimer);
66
+ if (idleTimer)
67
+ clearTimeout(idleTimer);
68
+ };
69
+ armIdle();
70
+ child.stdout.on('data', (d) => {
71
+ stdout += d.toString();
72
+ armIdle();
73
+ });
74
+ child.stderr.on('data', (d) => {
75
+ stderr += d.toString();
76
+ armIdle();
77
+ });
78
+ child.on('error', (e) => {
79
+ clearTimers();
80
+ reject(e);
81
+ });
82
+ child.on('close', (code, signal) => {
83
+ clearTimers();
84
+ resolve({ code, signal, stdout, stderr, timedOut });
85
+ });
40
86
  });
41
87
  }
88
+ /**
89
+ * The check install's limits (carrick#3021). A healthy install prints
90
+ * progress about once a second (longest gap measured: 1 s), so silence is the
91
+ * sign of a hang: the install is killed after `DEFAULT_INSTALL_IDLE_MS` with
92
+ * no output, and a total cap bounds one that keeps printing. Both are far
93
+ * above the slowest healthy run measured (54 s, install plus judge).
94
+ * `CARRICK_CHECK_INSTALL_TIMEOUT_MS` replaces the total cap.
95
+ */
96
+ export const DEFAULT_INSTALL_IDLE_MS = 120_000;
97
+ export const DEFAULT_INSTALL_TIMEOUT_MS = 1_800_000;
98
+ /** The total cap: the option, else the environment, else the default. */
99
+ export function installTotalLimitMs(opt, env = process.env) {
100
+ if (opt !== undefined)
101
+ return opt;
102
+ const fromEnv = Number(env.CARRICK_CHECK_INSTALL_TIMEOUT_MS);
103
+ return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : DEFAULT_INSTALL_TIMEOUT_MS;
104
+ }
105
+ /** What the package manager prints when it cannot reach the registry. */
106
+ const REGISTRY_UNREACHABLE = /ERR_PNPM_META_FETCH_FAIL|ERR_PNPM_FETCH_|ENOTFOUND|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENETUNREACH/;
107
+ /**
108
+ * Why the check install did not finish, as a gate and a sentence the verdicts
109
+ * carry. A hang and a refused connection are named apart from a plain failure.
110
+ */
111
+ export function installFailure(install, limits) {
112
+ if (install.timedOut) {
113
+ const idle = install.timedOut === 'idle';
114
+ return {
115
+ gate: 'install:timeout',
116
+ reason: idle
117
+ ? `workspace dependency install printed nothing for ${Math.round(limits.idleMs / 1000)}s and was stopped (registry unreachable or stuck)`
118
+ : `workspace dependency install did not finish within ${Math.round(limits.totalMs / 1000)}s (registry unreachable or too slow)`,
119
+ };
120
+ }
121
+ if (REGISTRY_UNREACHABLE.test(`${install.stderr}\n${install.stdout}`)) {
122
+ return {
123
+ gate: 'install:registry-unreachable',
124
+ reason: 'workspace dependency install failed: the package registry could not be reached',
125
+ };
126
+ }
127
+ return { gate: 'install:failed', reason: 'workspace dependency install failed' };
128
+ }
42
129
  /** The tail V8 prints on every fatal heap-exhaustion line. */
43
130
  const HEAP_OUT_OF_MEMORY = 'JavaScript heap out of memory';
44
131
  /**
@@ -309,18 +396,23 @@ export async function runCheck(opts, onProgress) {
309
396
  const degraded = [];
310
397
  // ---- Install (async, off the event loop) --------------------------------
311
398
  progress('installing', 'installing pinned dependencies');
312
- const install = await runProcess(pnpmPath, ['install'], ws.workspaceDir);
313
- if (install.code !== 0) {
399
+ const installLimits = {
400
+ idleMs: opts.installIdleTimeoutMs ?? DEFAULT_INSTALL_IDLE_MS,
401
+ totalMs: installTotalLimitMs(opts.installTimeoutMs),
402
+ };
403
+ const install = await runProcess(pnpmPath, ['install'], ws.workspaceDir, undefined, installLimits);
404
+ if (install.code !== 0 || install.timedOut) {
405
+ const failure = installFailure(install, installLimits);
314
406
  const installError = scrubPaths((install.stderr || install.stdout).trim().slice(0, 2000), scrubCtx);
315
407
  // `errors` says why the run failed (carrick#1821); each pair the install
316
408
  // stopped says it too, because the client reads every pair's own verdict
317
409
  // on a failed check (carrick#1833).
318
- errors.push(`workspace dependency install failed${installError ? `: ${installError}` : ''}`);
410
+ errors.push(`${failure.reason}${installError && failure.gate !== 'install:timeout' ? `: ${installError}` : ''}`);
319
411
  for (const s of opts.stubs) {
320
412
  degraded.push({ service_name: s.service_name, reason: 'workspace install failed' });
321
413
  }
322
414
  const verdicts = sortVerdicts([
323
- ...unverifiableAll(probing, 'install:failed', 'workspace dependency install failed; compatibility cannot be verified.' +
415
+ ...unverifiableAll(probing, failure.gate, `${failure.reason}; compatibility cannot be verified.` +
324
416
  (installError ? ` Installer output: ${installError}` : '')),
325
417
  // Capture-decay verdicts stand regardless of the install outcome.
326
418
  ...preGated,
@@ -108,6 +108,7 @@ function fail(stubDir, packageName, errors) {
108
108
  augmentation_files: [],
109
109
  specifier_rewrites: 0,
110
110
  bare_checkout: false,
111
+ unresolved_dependencies: [],
111
112
  ts_version: ts.version,
112
113
  errors,
113
114
  };
@@ -518,7 +519,20 @@ export function captureStub(opts) {
518
519
  console.error(`[sidecar] capture ${packageName}: ${edgeCount} dependency edge(s) recorded from the installed tree, ` +
519
520
  `${resolution.unrecorded} left to the registry`);
520
521
  const dependencyRoot = deno?.config.workspaceRoot ?? repoRoot;
521
- const bareCheckout = !deno && !fs.existsSync(path.join(dependencyRoot, 'node_modules'));
522
+ const nodeModulesPresent = fs.existsSync(path.join(dependencyRoot, 'node_modules'));
523
+ const declared = deno || !nodeModulesPresent
524
+ ? { unresolved: [], runtimeDeclared: 0, runtimeResolved: 0 }
525
+ : declaredDependencyResolution(dependencyRoot);
526
+ const unresolvedDependencies = declared.unresolved;
527
+ // Bare: no node_modules, or every declared runtime dependency dangles (a
528
+ // missing pnpm store). One missing package, or missing devDependencies,
529
+ // leaves the installed ones usable (carrick#2999).
530
+ const bareCheckout = !deno &&
531
+ (!nodeModulesPresent || (declared.runtimeDeclared > 0 && declared.runtimeResolved === 0));
532
+ if (unresolvedDependencies.length > 0) {
533
+ console.error(`[sidecar] capture ${packageName}: declared dependencies do not resolve` +
534
+ `${bareCheckout ? ' (bare checkout)' : ''}: ${unresolvedDependencies.join(', ')}`);
535
+ }
522
536
  stubGuard.writeFile(path.join(stubDir, 'package.json'), JSON.stringify({
523
537
  name: packageName,
524
538
  version: '0.0.0-carrick',
@@ -568,10 +582,66 @@ export function captureStub(opts) {
568
582
  augmentation_files: augmentationFiles.sort(),
569
583
  specifier_rewrites: specifierRewrites,
570
584
  bare_checkout: bareCheckout,
585
+ unresolved_dependencies: unresolvedDependencies,
571
586
  ts_version: ts.version,
572
587
  errors,
573
588
  };
574
589
  }
590
+ /** How many unresolved packages a capture result names. */
591
+ const UNRESOLVED_DEPENDENCIES_NAMED = 5;
592
+ /**
593
+ * How `root/package.json` dependencies resolve from `root`: no
594
+ * `node_modules/<name>` in `root` or any parent directory means unresolved.
595
+ * `existsSync` follows links, so a pnpm link into a missing store reads as
596
+ * unresolved (carrick#2999). `unresolved` is the first few names across
597
+ * dependencies and devDependencies, sorted; the runtime counts cover
598
+ * `dependencies` only. Declared names only, one stat per ancestor.
599
+ */
600
+ function declaredDependencyResolution(root) {
601
+ const none = { unresolved: [], runtimeDeclared: 0, runtimeResolved: 0 };
602
+ let manifest;
603
+ try {
604
+ manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
605
+ }
606
+ catch {
607
+ return none;
608
+ }
609
+ if (manifest === null || typeof manifest !== 'object')
610
+ return none;
611
+ const names = (field) => {
612
+ const group = manifest[field];
613
+ return group !== null && typeof group === 'object' ? Object.keys(group) : [];
614
+ };
615
+ const resolves = (name) => {
616
+ let dir = path.resolve(root);
617
+ for (;;) {
618
+ if (fs.existsSync(path.join(dir, 'node_modules', name)))
619
+ return true;
620
+ const parent = path.dirname(dir);
621
+ if (parent === dir)
622
+ return false;
623
+ dir = parent;
624
+ }
625
+ };
626
+ const runtime = new Set(names('dependencies'));
627
+ const all = new Set([...runtime, ...names('devDependencies')]);
628
+ let runtimeResolved = 0;
629
+ const unresolved = [];
630
+ for (const name of [...all].sort()) {
631
+ if (resolves(name)) {
632
+ if (runtime.has(name))
633
+ runtimeResolved++;
634
+ }
635
+ else {
636
+ unresolved.push(name);
637
+ }
638
+ }
639
+ return {
640
+ unresolved: unresolved.slice(0, UNRESOLVED_DEPENDENCIES_NAMED),
641
+ runtimeDeclared: runtime.size,
642
+ runtimeResolved,
643
+ };
644
+ }
575
645
  /**
576
646
  * Phase B: build the program of the final entry and emit its declarations.
577
647
  *
@@ -61,16 +61,16 @@ function initializedLoader() {
61
61
  return projectLoader;
62
62
  }
63
63
  /**
64
- * carrick#2100: the unwidened reading's budget in milliseconds, when
65
- * `CARRICK_UNWIDENED_BUDGET_MS` sets one. A switch for tests that drive the
66
- * scanner's binary: it forces the budget to run out on any machine. Unset or
67
- * not a whole number of milliseconds, the inferrer's default stands.
64
+ * carrick#2629: the most readings one batch's unwidened reading may make,
65
+ * when `CARRICK_UNWIDENED_READINGS_CAP` sets it. A switch for tests that
66
+ * drive the scanner's binary: 0 forces every reading past the cap, on any
67
+ * machine. Unset or not a whole number, the inferrer's default stands.
68
68
  */
69
- function unwidenedBudgetFromEnv() {
70
- const value = process.env.CARRICK_UNWIDENED_BUDGET_MS;
69
+ function unwidenedLimitsFromEnv() {
70
+ const value = process.env.CARRICK_UNWIDENED_READINGS_CAP;
71
71
  if (value === undefined || !/^\d+$/.test(value.trim()))
72
72
  return undefined;
73
- return Number(value.trim());
73
+ return { readings: Number(value.trim()) };
74
74
  }
75
75
  /**
76
76
  * Get the project-backed components, building the project if this is the
@@ -94,7 +94,7 @@ function projectComponents(key = '') {
94
94
  project,
95
95
  repoRoot,
96
96
  packageOf: (filePath) => loader.packageOf(filePath),
97
- unwidenedBudgetMs: unwidenedBudgetFromEnv(),
97
+ unwidenedLimits: unwidenedLimitsFromEnv(),
98
98
  });
99
99
  built = {
100
100
  typeBundler: new TypeBundler({ project, repoRoot }),
@@ -351,13 +351,19 @@ function handleInfer(request) {
351
351
  }
352
352
  // One count for the request, whichever programs its items span.
353
353
  let done = 0;
354
- const report = atMostEvery(PROGRESS_INTERVAL_MS, () => writeProgress(request.request_id, 'infer', `${done} of ${request.requests.length}`));
354
+ let readingSteps = 0;
355
+ const report = atMostEvery(PROGRESS_INTERVAL_MS, () => writeProgress(request.request_id, 'infer', readingSteps === 0
356
+ ? `${done} of ${request.requests.length}`
357
+ : `${done} of ${request.requests.length}, unwidened reading step ${readingSteps}`));
355
358
  const results = [...groups].map(([key, items]) => {
356
359
  const built = projectComponents(key);
357
360
  return built.typeInferrer.infer(items, request.extraction_config, () => {
358
361
  done += 1;
359
362
  report();
360
- }, request.model_symbols, labelledMembersFor(built, key, items, request.server_claims));
363
+ }, request.model_symbols, labelledMembersFor(built, key, items, request.server_claims), () => {
364
+ readingSteps += 1;
365
+ report();
366
+ });
361
367
  });
362
368
  const result = results.length === 1
363
369
  ? results[0]
@@ -637,7 +643,7 @@ function handleListLibrarySurface(request) {
637
643
  const { claimsVerifier } = projectComponents();
638
644
  const fromDir = path.resolve(projectLoader.getRepoRoot(), request.from_dir);
639
645
  log(`Listing the declared surface of ${request.packages.length} specifier(s) from ${fromDir}`);
640
- const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, resultCandidates: request.result_candidates });
646
+ const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, types: request.types, resultCandidates: request.result_candidates, maxHandlerMembers: request.max_handler_members });
641
647
  return { request_id: request.request_id, status: 'success', surfaces, surface_sha256 };
642
648
  }
643
649
  catch (err) {