react-doctor 0.5.6-dev.f45cb29 → 0.5.7-dev.0b4f4f4

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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="bb93aaad-ea85-5f1d-b2db-584f48671f66")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6a2c86b6-c3a8-5e50-8e7b-daef840df200")}catch(e){}}();
3
3
  import { createRequire } from "node:module";
4
4
  import * as NodeChildProcess from "node:child_process";
5
5
  import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
@@ -9,12 +9,12 @@ import * as NFS from "node:fs";
9
9
  import fs, { mkdtempSync, rmSync } from "node:fs";
10
10
  import process$1 from "node:process";
11
11
  import * as ts from "typescript";
12
- import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, REACT_DOCTOR_RULES, classifySecurityScanFile, shouldReadSecurityScanContent } from "oxlint-plugin-react-doctor";
12
+ import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, CROSS_FILE_RULE_IDS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, REACT_DOCTOR_RULES, classifySecurityScanFile, shouldReadSecurityScanContent } from "oxlint-plugin-react-doctor";
13
13
  import * as OS from "node:os";
14
14
  import os, { tmpdir } from "node:os";
15
15
  import { parseJSON5 } from "confbox";
16
16
  import * as NodeUrl from "node:url";
17
- import { fileURLToPath } from "node:url";
17
+ import { fileURLToPath, pathToFileURL } from "node:url";
18
18
  import { createJiti } from "jiti";
19
19
  import * as Crypto from "node:crypto";
20
20
  import crypto, { createHash, randomUUID } from "node:crypto";
@@ -10277,7 +10277,7 @@ const provideContext$1 = /* @__PURE__ */ dual(2, (self, context) => {
10277
10277
  return updateContext$1(self, merge$3(context));
10278
10278
  });
10279
10279
  /** @internal */
10280
- const provideService$1 = function() {
10280
+ const provideService$3 = function() {
10281
10281
  if (arguments.length === 1) return dual(2, (self, impl) => provideServiceImpl(self, arguments[0], impl));
10282
10282
  return dual(3, (self, service, impl) => provideServiceImpl(self, service, impl)).apply(this, arguments);
10283
10283
  };
@@ -10508,7 +10508,7 @@ const constScopeEmpty = { _tag: "Empty" };
10508
10508
  /** @internal */
10509
10509
  const scope = scopeTag;
10510
10510
  /** @internal */
10511
- const provideScope = /* @__PURE__ */ provideService$1(scopeTag);
10511
+ const provideScope = /* @__PURE__ */ provideService$3(scopeTag);
10512
10512
  /** @internal */
10513
10513
  const scoped$1 = (self) => withFiber$1((fiber) => {
10514
10514
  const prev = fiber.context;
@@ -10949,9 +10949,9 @@ const makeLatchUnsafe = (open) => new Latch(open ?? false);
10949
10949
  /** @internal */
10950
10950
  const makeLatch = (open) => sync$2(() => makeLatchUnsafe(open));
10951
10951
  /** @internal */
10952
- const withTracer$1 = /* @__PURE__ */ dual(2, (effect, tracer) => provideService$1(effect, Tracer, tracer));
10952
+ const withTracer$1 = /* @__PURE__ */ dual(2, (effect, tracer) => provideService$3(effect, Tracer, tracer));
10953
10953
  /** @internal */
10954
- const withTracerEnabled$1 = /* @__PURE__ */ provideService$1(TracerEnabled);
10954
+ const withTracerEnabled$1 = /* @__PURE__ */ provideService$3(TracerEnabled);
10955
10955
  const bigint0 = /* @__PURE__ */ BigInt(0);
10956
10956
  const NoopSpanProto = {
10957
10957
  _tag: "Span",
@@ -11032,7 +11032,7 @@ const useSpan$1 = (name, ...args) => {
11032
11032
  }));
11033
11033
  });
11034
11034
  };
11035
- const provideParentSpan = /* @__PURE__ */ provideService$1(ParentSpan);
11035
+ const provideParentSpan = /* @__PURE__ */ provideService$3(ParentSpan);
11036
11036
  /** @internal */
11037
11037
  const withParentSpan$1 = function() {
11038
11038
  const dataFirst = isEffect$1(arguments[0]);
@@ -12599,7 +12599,7 @@ var CurrentMemoMap = class extends Service()("effect/Layer/CurrentMemoMap") {
12599
12599
  * @category memo map
12600
12600
  * @since 2.0.0
12601
12601
  */
12602
- const buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope) => provideService$1(map$4(self.build(memoMap, scope), add(CurrentMemoMap, memoMap)), CurrentMemoMap, memoMap));
12602
+ const buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope) => provideService$3(map$4(self.build(memoMap, scope), add(CurrentMemoMap, memoMap)), CurrentMemoMap, memoMap));
12603
12603
  /**
12604
12604
  * Builds a layer into an `Effect` value. Any resources associated with this
12605
12605
  * layer will be released when the specified scope is closed unless their scope
@@ -13952,7 +13952,7 @@ const provide$1 = /* @__PURE__ */ dual((args) => isEffect$1(args[0]), (self, sou
13952
13952
  /** @internal */
13953
13953
  const repeatOrElse = /* @__PURE__ */ dual(3, (self, schedule, orElse) => flatMap$4(toStepWithMetadata(schedule), (step) => {
13954
13954
  let meta = CurrentMetadata.defaultValue();
13955
- return catch_$2(forever$2(tap$2(flatMap$4(suspend$3(() => provideService$1(self, CurrentMetadata, meta)), step), (meta_) => sync$2(() => {
13955
+ return catch_$2(forever$2(tap$2(flatMap$4(suspend$3(() => provideService$3(self, CurrentMetadata, meta)), step), (meta_) => sync$2(() => {
13956
13956
  meta = meta_;
13957
13957
  })), { disableYield: true }), (error) => isDone$2(error) ? succeed$5(error.value) : orElse(error, meta.attempt === 0 ? none() : some(meta)));
13958
13958
  }));
@@ -13960,7 +13960,7 @@ const repeatOrElse = /* @__PURE__ */ dual(3, (self, schedule, orElse) => flatMap
13960
13960
  const retryOrElse = /* @__PURE__ */ dual(3, (self, policy, orElse) => flatMap$4(toStepWithMetadata(policy), (step) => {
13961
13961
  let meta = CurrentMetadata.defaultValue();
13962
13962
  let lastError;
13963
- const loop = catch_$2(suspend$3(() => provideService$1(self, CurrentMetadata, meta)), (error) => {
13963
+ const loop = catch_$2(suspend$3(() => provideService$3(self, CurrentMetadata, meta)), (error) => {
13964
13964
  lastError = error;
13965
13965
  return flatMap$4(step(error), (meta_) => {
13966
13966
  meta = meta_;
@@ -16076,7 +16076,7 @@ const updateContext = updateContext$1;
16076
16076
  * @category Context
16077
16077
  * @since 2.0.0
16078
16078
  */
16079
- const provideService = provideService$1;
16079
+ const provideService$2 = provideService$3;
16080
16080
  /**
16081
16081
  * Scopes all resources used in this workflow to the lifetime of the workflow,
16082
16082
  * ensuring that their finalizers are run as soon as this workflow completes
@@ -21091,6 +21091,20 @@ function decodeUnknownOption$1(schema, options) {
21091
21091
  return asOption(decodeUnknownEffect(schema, options));
21092
21092
  }
21093
21093
  /**
21094
+ * Creates a synchronous decoder for `unknown` input.
21095
+ *
21096
+ * **Details**
21097
+ *
21098
+ * The returned function returns the decoded `Type` on success and throws an
21099
+ * `Error` with the `SchemaIssue.Issue` in its `cause` on decoding failure.
21100
+ *
21101
+ * @category decoding
21102
+ * @since 3.10.0
21103
+ */
21104
+ function decodeUnknownSync$1(schema, options) {
21105
+ return asSync(decodeUnknownEffect(schema, options));
21106
+ }
21107
+ /**
21094
21108
  * Creates an effectful encoder for `unknown` input.
21095
21109
  *
21096
21110
  * **Details**
@@ -21392,6 +21406,40 @@ function isSchemaError(u) {
21392
21406
  */
21393
21407
  const decodeUnknownOption = decodeUnknownOption$1;
21394
21408
  /**
21409
+ * Decodes an `unknown` input against a schema synchronously, returning the
21410
+ * decoded value or throwing an `Error` whose cause contains the schema issue.
21411
+ * Use this when you want to validate data at a boundary and treat a schema
21412
+ * mismatch as an exception. For typed input use `decodeSync`.
21413
+ *
21414
+ * **Details**
21415
+ *
21416
+ * Only service-free schemas can be decoded synchronously. For non-throwing
21417
+ * alternatives see `decodeUnknownOption`, `decodeUnknownExit`, or
21418
+ * `decodeUnknownEffect`. Options may be provided either when creating the
21419
+ * decoder or when applying it; application options override creation options.
21420
+ *
21421
+ * **Example** (Decoding with a transformation schema)
21422
+ *
21423
+ * ```ts
21424
+ * import { Schema } from "effect"
21425
+ *
21426
+ * const NumberFromString = Schema.NumberFromString
21427
+ *
21428
+ * console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
21429
+ * // Output: 42
21430
+ *
21431
+ * Schema.decodeUnknownSync(NumberFromString)("not a number")
21432
+ * // throws SchemaError: NumberFromString
21433
+ * // └─ Encoded side transformation failure
21434
+ * // └─ NumberFromString
21435
+ * // └─ Expected a numeric string, actual "not a number"
21436
+ * ```
21437
+ *
21438
+ * @category decoding
21439
+ * @since 4.0.0
21440
+ */
21441
+ const decodeUnknownSync = decodeUnknownSync$1;
21442
+ /**
21395
21443
  * Encodes an `unknown` input against a schema synchronously, throwing a
21396
21444
  * {@link SchemaError} on failure. Use this when you want to serialize data at a
21397
21445
  * boundary and treat a schema mismatch as an unrecoverable error. For
@@ -22358,7 +22406,8 @@ var Diagnostic = class extends Class("Diagnostic")({
22358
22406
  category: String$1,
22359
22407
  fileContext: optional(Literals(["test", "story"])),
22360
22408
  suppressionHint: optional(String$1),
22361
- relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
22409
+ relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation)),
22410
+ fixGroupId: optional(String$1)
22362
22411
  }) {};
22363
22412
  const JsonReportMode = Literals([
22364
22413
  "full",
@@ -22400,6 +22449,7 @@ var JsonReportProjectEntry = class extends Class("JsonReportProjectEntry")({
22400
22449
  score: Unknown,
22401
22450
  skippedChecks: ArraySchema(String$1),
22402
22451
  skippedCheckReasons: optional(Record$1(String$1, String$1)),
22452
+ scannedFileCount: optional(Number$1),
22403
22453
  elapsedMilliseconds: Number$1
22404
22454
  }) {};
22405
22455
  /**
@@ -28269,6 +28319,14 @@ const runWith = (self, f, onHalt) => suspend$2(() => {
28269
28319
  return catchDone(flatMap$2(toTransform(self)(done$1(), scope), f), onHalt ? onHalt : succeed$2).pipe(onExit$2((exit) => close(scope, exit)));
28270
28320
  });
28271
28321
  /**
28322
+ * Provides a concrete service for a context key, removing that service
28323
+ * requirement from the returned channel.
28324
+ *
28325
+ * @category services
28326
+ * @since 2.0.0
28327
+ */
28328
+ const provideService$1 = /* @__PURE__ */ dual(3, (self, key, service) => fromTransform$1((upstream, scope) => map$3(provideService$2(toTransform(self)(upstream, scope), key, service), provideService$2(key, service))));
28329
+ /**
28272
28330
  * Runs a channel and applies an effect to each output element.
28273
28331
  *
28274
28332
  * **Example** (Running effects for each output)
@@ -29657,6 +29715,44 @@ const splitLines = (self) => self.channel.pipe(pipeTo(splitLines$1()), fromChann
29657
29715
  */
29658
29716
  const ensuring = /* @__PURE__ */ dual(2, (self, finalizer) => fromChannel(ensuring$1(self.channel, finalizer)));
29659
29717
  /**
29718
+ * Provides the stream with a single required service, eliminating that
29719
+ * requirement from its environment.
29720
+ *
29721
+ * **Example** (Providing a stream service)
29722
+ *
29723
+ * ```ts
29724
+ * import { Console, Context, Effect, Stream } from "effect"
29725
+ *
29726
+ * class Greeter extends Context.Service<Greeter, {
29727
+ * greet: (name: string) => string
29728
+ * }>()("Greeter") {}
29729
+ *
29730
+ * const stream = Stream.fromEffect(
29731
+ * Effect.service(Greeter).pipe(
29732
+ * Effect.map((greeter) => greeter.greet("Ada"))
29733
+ * )
29734
+ * )
29735
+ *
29736
+ * const program = Effect.gen(function*() {
29737
+ * const collected = yield* Stream.runCollect(
29738
+ * stream.pipe(
29739
+ * Stream.provideService(Greeter, {
29740
+ * greet: (name) => `Hello, ${name}`
29741
+ * })
29742
+ * )
29743
+ * )
29744
+ * yield* Console.log(collected)
29745
+ * })
29746
+ *
29747
+ * Effect.runPromise(program)
29748
+ * //=> ["Hello, Ada"]
29749
+ * ```
29750
+ *
29751
+ * @category services
29752
+ * @since 2.0.0
29753
+ */
29754
+ const provideService = /* @__PURE__ */ dual(3, (self, key, service) => fromChannel(provideService$1(self.channel, key, service)));
29755
+ /**
29660
29756
  * Runs a stream with a sink and returns the sink result.
29661
29757
  *
29662
29758
  * **Example** (Running a stream with a sink)
@@ -33086,7 +33182,7 @@ const make$8 = /* @__PURE__ */ fnUntraced(function* (options) {
33086
33182
  const runFork = runForkWith(services);
33087
33183
  const exportInterval = max(fromInputUnsafe(options.exportInterval), zero);
33088
33184
  let disabledUntil = void 0;
33089
- const client = filterStatusOk(get$4(services, HttpClient)).pipe(transformResponse(provideService(TracerPropagationEnabled, false)), retryTransient({
33185
+ const client = filterStatusOk(get$4(services, HttpClient)).pipe(transformResponse(provideService$2(TracerPropagationEnabled, false)), retryTransient({
33090
33186
  schedule: policy,
33091
33187
  times: 3
33092
33188
  }));
@@ -35883,16 +35979,23 @@ const isMinifiedSource = (absolutePath) => {
35883
35979
  if (fileDescriptor !== void 0) NFS.closeSync(fileDescriptor);
35884
35980
  }
35885
35981
  };
35886
- const isLargeMinifiedFile = (absolutePath) => {
35887
- let sizeBytes;
35982
+ const cachedIsLargeMinifiedByPath = /* @__PURE__ */ new Map();
35983
+ const statSourceFileSize = (absolutePath) => {
35888
35984
  try {
35889
- sizeBytes = NFS.statSync(absolutePath).size;
35985
+ return NFS.statSync(absolutePath).size;
35890
35986
  } catch {
35891
- return false;
35987
+ return null;
35892
35988
  }
35893
- if (sizeBytes < 2e4) return false;
35894
- return isMinifiedSource(absolutePath);
35895
35989
  };
35990
+ const isLargeMinifiedFile = (absolutePath, knownSizeBytes) => {
35991
+ const cached = cachedIsLargeMinifiedByPath.get(absolutePath);
35992
+ if (cached !== void 0) return cached;
35993
+ const sizeBytes = knownSizeBytes === void 0 ? statSourceFileSize(absolutePath) : knownSizeBytes;
35994
+ const result = sizeBytes !== null && sizeBytes >= 2e4 && isMinifiedSource(absolutePath);
35995
+ cachedIsLargeMinifiedByPath.set(absolutePath, result);
35996
+ return result;
35997
+ };
35998
+ const isErrnoException = (error) => error instanceof Error && "code" in error;
35896
35999
  const IGNORABLE_READDIR_ERROR_CODES = new Set([
35897
36000
  "EACCES",
35898
36001
  "EPERM",
@@ -35902,11 +36005,7 @@ const IGNORABLE_READDIR_ERROR_CODES = new Set([
35902
36005
  "ELOOP",
35903
36006
  "ENAMETOOLONG"
35904
36007
  ]);
35905
- const isIgnorableReaddirError = (error) => {
35906
- if (typeof error !== "object" || error === null) return false;
35907
- const errorCode = error.code;
35908
- return typeof errorCode === "string" && IGNORABLE_READDIR_ERROR_CODES.has(errorCode);
35909
- };
36008
+ const isIgnorableReaddirError = (error) => isErrnoException(error) && typeof error.code === "string" && IGNORABLE_READDIR_ERROR_CODES.has(error.code);
35910
36009
  const readDirectoryEntries = (directoryPath) => {
35911
36010
  try {
35912
36011
  return NFS.readdirSync(directoryPath, { withFileTypes: true });
@@ -35953,7 +36052,7 @@ const readPackageJsonUncached = (packageJsonPath) => {
35953
36052
  return JSON.parse(NFS.readFileSync(packageJsonPath, "utf-8"));
35954
36053
  } catch (error) {
35955
36054
  if (error instanceof SyntaxError) return {};
35956
- if (error instanceof Error && "code" in error) {
36055
+ if (isErrnoException(error)) {
35957
36056
  const { code } = error;
35958
36057
  if (code === "EISDIR" || code === "EACCES" || code === "EPERM" || code === "ENOENT") return {};
35959
36058
  }
@@ -36678,17 +36777,13 @@ const isPackageJsonReactNativeAware = (packageJson) => {
36678
36777
  return false;
36679
36778
  };
36680
36779
  const hasReactNativeWorkspaceAnywhere = (rootDirectory, rootPackageJson) => someWorkspacePackageJson(rootDirectory, rootPackageJson, isPackageJsonReactNativeAware);
36681
- const getExpoDependencySpec = (packageJson) => {
36682
- const spec = packageJson.dependencies?.expo ?? packageJson.devDependencies?.expo ?? packageJson.peerDependencies?.expo ?? packageJson.optionalDependencies?.expo;
36780
+ const getDependencySpec = (packageJson, packageName) => {
36781
+ const spec = packageJson.dependencies?.[packageName] ?? packageJson.devDependencies?.[packageName] ?? packageJson.peerDependencies?.[packageName] ?? packageJson.optionalDependencies?.[packageName];
36683
36782
  return typeof spec === "string" ? spec : null;
36684
36783
  };
36685
- const findExpoVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getExpoDependencySpec);
36784
+ const findExpoVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, (packageJson) => getDependencySpec(packageJson, "expo"));
36686
36785
  const SHOPIFY_FLASH_LIST_PACKAGE_NAME = "@shopify/flash-list";
36687
- const getShopifyFlashListDependencySpec = (packageJson) => {
36688
- const spec = packageJson.dependencies?.["@shopify/flash-list"] ?? packageJson.devDependencies?.["@shopify/flash-list"] ?? packageJson.peerDependencies?.["@shopify/flash-list"] ?? packageJson.optionalDependencies?.["@shopify/flash-list"];
36689
- return typeof spec === "string" ? spec : null;
36690
- };
36691
- const findShopifyFlashListVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getShopifyFlashListDependencySpec);
36786
+ const findShopifyFlashListVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, (packageJson) => getDependencySpec(packageJson, SHOPIFY_FLASH_LIST_PACKAGE_NAME));
36692
36787
  const resolveCatalogBackedDependencyVersion = ({ rootDirectory, rootPackageJson, packageName, version }) => {
36693
36788
  if (version === null || !isCatalogReference(version)) return version;
36694
36789
  const catalogName = extractCatalogName(version);
@@ -36700,11 +36795,7 @@ const resolveCatalogBackedDependencyVersion = ({ rootDirectory, rootPackageJson,
36700
36795
  if (!isFile(monorepoPackageJsonPath)) return version;
36701
36796
  return resolveCatalogVersion(readPackageJson$1(monorepoPackageJsonPath), packageName, monorepoRoot, catalogName) ?? version;
36702
36797
  };
36703
- const getNextjsDependencySpec = (packageJson) => {
36704
- const spec = packageJson.dependencies?.next ?? packageJson.devDependencies?.next ?? packageJson.peerDependencies?.next ?? packageJson.optionalDependencies?.next;
36705
- return typeof spec === "string" ? spec : null;
36706
- };
36707
- const findNextjsVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getNextjsDependencySpec);
36798
+ const findNextjsVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, (packageJson) => getDependencySpec(packageJson, "next"));
36708
36799
  const getPreactVersion = (packageJson) => {
36709
36800
  return {
36710
36801
  ...packageJson.peerDependencies,
@@ -36771,6 +36862,7 @@ const DOCS_URL = "https://react.doctor/docs";
36771
36862
  const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
36772
36863
  const FETCH_TIMEOUT_MS = 1e4;
36773
36864
  const GITHUB_VIEWER_PERMISSION_TIMEOUT_MS = 2e3;
36865
+ const PER_WORKER_MEM_BUDGET_BYTES = 1024 * 1024 * 1024;
36774
36866
  const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
36775
36867
  const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
36776
36868
  const OXLINT_NODE_REQUIREMENT = "^20.19.0 || >=22.12.0";
@@ -36793,6 +36885,11 @@ const ES_TARGET_YEAR_BY_NAME = {
36793
36885
  esnext: 9999
36794
36886
  };
36795
36887
  /**
36888
+ * tsconfig filenames probed when resolving a project's TypeScript
36889
+ * compiler options — the root config first, then a monorepo base config.
36890
+ */
36891
+ const TSCONFIG_FILENAMES = ["tsconfig.json", "tsconfig.base.json"];
36892
+ /**
36796
36893
  * Project-config files that `StagedFiles.materialize` copies into
36797
36894
  * the temp directory alongside staged sources so oxlint resolves
36798
36895
  * `tsconfig` / `package.json` / lint configs the same way it would
@@ -36842,7 +36939,16 @@ const CANONICAL_DISCORD_URL = "https://react.doctor/discord";
36842
36939
  const SKILL_NAME = "react-doctor";
36843
36940
  const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
36844
36941
  const OXLINT_SPAWN_TIMEOUT_MS = 6e4;
36942
+ const NODE_COMPILE_CACHE_DIR_NAME = "node-compile-cache";
36943
+ const DEAD_CODE_WORKER_TIMEOUT_MS = 12e4;
36944
+ const OXLINT_SPLIT_TOTAL_BUDGET_MS = 18e4;
36945
+ const DEAD_CODE_PHASE_TIMEOUT_MS = 15e4;
36946
+ const LINT_PHASE_TIMEOUT_MS = 3e5;
36947
+ const SCAN_TOTAL_DEADLINE_MS = 9e5;
36845
36948
  const DEAD_CODE_WORKER_MAX_OLD_SPACE_MB = 8192;
36949
+ const DEAD_CODE_TIMEOUT_CEILING_MS = 6e5;
36950
+ const DEAD_CODE_PHASE_TIMEOUT_OVER_WORKER_MS = 3e4;
36951
+ const DEAD_CODE_OVERLAP_PARSE_SHARE = .4;
36846
36952
  const RECOMMENDED_PNPM_MINIMUM_RELEASE_AGE_MINUTES = 10080;
36847
36953
  const REACT_SERVER_DOM_PACKAGES = [
36848
36954
  "react-server-dom-webpack",
@@ -36865,14 +36971,25 @@ const APP_ONLY_RULE_KEYS = new Set([
36865
36971
  ]);
36866
36972
  const COMPILER_CLEANUP_BUCKET = "compiler-cleanup";
36867
36973
  const COMPILER_CLEANUP_RULE_KEYS = new Set(["react-doctor/react-compiler-no-manual-memoization"]);
36974
+ const ROOT_CAUSE_GROUPABLE_RULE_KEYS = new Set([
36975
+ "react-doctor/no-derived-state",
36976
+ "react-doctor/no-derived-state-effect",
36977
+ "react-doctor/no-derived-useState",
36978
+ "react-doctor/no-adjust-state-on-prop-change",
36979
+ "react-doctor/no-reset-all-state-on-prop-change"
36980
+ ]);
36868
36981
  const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
36869
36982
  const CONFIG_CACHE_TTL_MS = 300 * 1e3;
36870
36983
  const SOCKET_FREE_PURL_API_BASE = "https://firewall-api.socket.dev/purl";
36871
36984
  const SOCKET_PACKAGE_PAGE_BASE = "https://socket.dev/npm/package";
36872
36985
  const SOCKET_FREE_USER_AGENT = "react-doctor-supply-chain";
36986
+ const FILE_LINT_CACHE_FILENAME = "file-lint-cache.json";
36987
+ const FILE_LINT_CACHE_MAX_FILE_COUNT = 5e4;
36873
36988
  const SUPPLY_CHAIN_PLUGIN = "socket";
36874
36989
  const SUPPLY_CHAIN_RULE = "low-supply-chain-score";
36875
36990
  const SUPPLY_CHAIN_CATEGORY = "Security";
36991
+ const SUPPLY_CHAIN_OVERLAP_TIMEOUT_MS = 9e4;
36992
+ const SUPPLY_CHAIN_CACHE_SUBDIR = "supply-chain";
36876
36993
  const SUPPLY_CHAIN_IGNORED_PACKAGES = new Set(["next"]);
36877
36994
  const TSCONFIG_FILENAME = "tsconfig.json";
36878
36995
  const isRelativeExtendsValue = (extendsValue) => extendsValue.startsWith("./") || extendsValue.startsWith("../") || Path.isAbsolute(extendsValue);
@@ -37314,6 +37431,7 @@ const isTailwindAtLeast = (detected, required) => {
37314
37431
  if (detected.major !== required.major) return detected.major > required.major;
37315
37432
  return detected.minor >= required.minor;
37316
37433
  };
37434
+ const messageFromUnknown = (error) => error instanceof Error ? error.message : String(error);
37317
37435
  var InvalidGlobPatternError = class extends Error {
37318
37436
  pattern;
37319
37437
  reason;
@@ -37342,7 +37460,7 @@ const compileGlobPattern = (rawPattern) => {
37342
37460
  try {
37343
37461
  return import_picomatch.default.makeRe(normalizeGlobPattern(rawPattern), PICOMATCH_OPTIONS);
37344
37462
  } catch (caughtError) {
37345
- throw new InvalidGlobPatternError(rawPattern, caughtError instanceof Error ? caughtError.message : String(caughtError));
37463
+ throw new InvalidGlobPatternError(rawPattern, messageFromUnknown(caughtError));
37346
37464
  }
37347
37465
  };
37348
37466
  const compileGlobPatternsLenient = (patterns, onInvalid) => {
@@ -37438,115 +37556,6 @@ const buildRuleSeverityControls = (config) => {
37438
37556
  ...config.buckets !== void 0 ? { buckets: config.buckets } : {}
37439
37557
  };
37440
37558
  };
37441
- const JSX_OPENER_TAG_PATTERN = /<[A-Za-z][\w.]*/g;
37442
- const JSX_TAG_NAME_FOLLOW = /[A-Za-z]/;
37443
- const isOpenerMatchInsideLineComment = (line, openerCharIndex) => {
37444
- let stringDelimiter = null;
37445
- for (let charIndex = 0; charIndex < openerCharIndex; charIndex++) {
37446
- const character = line[charIndex];
37447
- if (stringDelimiter !== null) {
37448
- if (character === "\\") {
37449
- charIndex++;
37450
- continue;
37451
- }
37452
- if (character === stringDelimiter) stringDelimiter = null;
37453
- continue;
37454
- }
37455
- if (character === "\"" || character === "'" || character === "`") {
37456
- stringDelimiter = character;
37457
- continue;
37458
- }
37459
- if (character === "/" && line[charIndex + 1] === "/") return true;
37460
- }
37461
- return false;
37462
- };
37463
- const findOpenerTagOnLine = (line) => {
37464
- for (const match of line.matchAll(JSX_OPENER_TAG_PATTERN)) {
37465
- if (match.index === void 0) continue;
37466
- if (!isOpenerMatchInsideLineComment(line, match.index)) return { startCharIndex: match.index + match[0].length };
37467
- }
37468
- return null;
37469
- };
37470
- const findJsxOpenerSpan = (lines, openerLineIndex) => {
37471
- const openerLine = lines[openerLineIndex];
37472
- if (openerLine === void 0) return null;
37473
- const opener = findOpenerTagOnLine(openerLine);
37474
- if (!opener) return null;
37475
- const lookaheadLimit = Math.min(lines.length, openerLineIndex + 32);
37476
- let braceDepth = 0;
37477
- let innerAngleDepth = 0;
37478
- let stringDelimiter = null;
37479
- for (let lineIndex = openerLineIndex; lineIndex < lookaheadLimit; lineIndex++) {
37480
- const currentLine = lines[lineIndex];
37481
- const startCharForLine = lineIndex === openerLineIndex ? opener.startCharIndex : 0;
37482
- for (let charIndex = startCharForLine; charIndex < currentLine.length; charIndex++) {
37483
- const character = currentLine[charIndex];
37484
- if (stringDelimiter !== null) {
37485
- if (character === "\\") {
37486
- charIndex++;
37487
- continue;
37488
- }
37489
- if (character === stringDelimiter) stringDelimiter = null;
37490
- continue;
37491
- }
37492
- if (character === "\"" || character === "'" || character === "`") {
37493
- stringDelimiter = character;
37494
- continue;
37495
- }
37496
- if (character === "{") {
37497
- braceDepth++;
37498
- continue;
37499
- }
37500
- if (character === "}") {
37501
- braceDepth--;
37502
- continue;
37503
- }
37504
- if (braceDepth !== 0) continue;
37505
- if (character === "<") {
37506
- const followCharacter = currentLine[charIndex + 1];
37507
- if (followCharacter !== void 0 && JSX_TAG_NAME_FOLLOW.test(followCharacter)) innerAngleDepth++;
37508
- continue;
37509
- }
37510
- if (character !== ">") continue;
37511
- const previousCharacter = currentLine[charIndex - 1];
37512
- const nextCharacter = currentLine[charIndex + 1];
37513
- if (previousCharacter === "=" || nextCharacter === "=") continue;
37514
- if (innerAngleDepth > 0) {
37515
- innerAngleDepth--;
37516
- continue;
37517
- }
37518
- return lineIndex;
37519
- }
37520
- }
37521
- return null;
37522
- };
37523
- const findEnclosingMultilineJsxOpenerStart = (lines, diagnosticLineIndex) => {
37524
- for (let candidateIndex = diagnosticLineIndex - 1; candidateIndex >= 0 && diagnosticLineIndex - candidateIndex <= 32; candidateIndex--) {
37525
- const openerCloseIndex = findJsxOpenerSpan(lines, candidateIndex);
37526
- if (openerCloseIndex !== null && openerCloseIndex >= diagnosticLineIndex) return candidateIndex;
37527
- }
37528
- return null;
37529
- };
37530
- const DISABLE_NEXT_LINE_PATTERN = /(?:\/\/|\/\*)\s*react-doctor-disable-next-line\b(?:\s+([^\r\n]*?))?\s*(?:\*\/)?\s*\}?\s*$/;
37531
- const findStackedDisableCommentsAbove = (lines, anchorIndex) => {
37532
- const collected = [];
37533
- let isStillInChain = true;
37534
- for (let candidateIndex = anchorIndex - 1; candidateIndex >= 0 && anchorIndex - candidateIndex <= 10; candidateIndex--) {
37535
- const candidateLine = lines[candidateIndex];
37536
- if (candidateLine === void 0) break;
37537
- const match = candidateLine.match(DISABLE_NEXT_LINE_PATTERN);
37538
- if (match) {
37539
- collected.push({
37540
- commentLineIndex: candidateIndex,
37541
- ruleList: match[1],
37542
- isInChain: isStillInChain
37543
- });
37544
- continue;
37545
- }
37546
- isStillInChain = false;
37547
- }
37548
- return collected;
37549
- };
37550
37559
  const LEGACY_RULE_KEY_TO_NATIVE_RULE_KEY = {
37551
37560
  "effect/no-adjust-state-on-prop-change": "react-doctor/no-adjust-state-on-prop-change",
37552
37561
  "effect/no-chain-state-updates": "react-doctor/no-chain-state-updates",
@@ -37671,7 +37680,13 @@ for (const [legacyRuleKey, nativeRuleKey] of Object.entries(LEGACY_RULE_KEY_TO_N
37671
37680
  }
37672
37681
  const getLegacyRuleKeysForNative = (ruleKey) => NATIVE_RULE_KEY_TO_LEGACY_RULE_KEYS.get(ruleKey) ?? [];
37673
37682
  const canonicalizeRuleKey = (ruleKey) => LEGACY_RULE_KEY_TO_NATIVE_RULE_KEY[ruleKey] ?? ruleKey;
37674
- const isSameRuleKey = (candidateRuleKey, targetRuleKey) => canonicalizeRuleKey(candidateRuleKey) === canonicalizeRuleKey(targetRuleKey);
37683
+ const isReactDoctorShortIdOf = (bareRuleKey, qualifiedRuleKey) => !bareRuleKey.includes("/") && qualifiedRuleKey === `react-doctor/${bareRuleKey}`;
37684
+ const isSameRuleKey = (candidateRuleKey, targetRuleKey) => {
37685
+ const canonicalCandidate = canonicalizeRuleKey(candidateRuleKey);
37686
+ const canonicalTarget = canonicalizeRuleKey(targetRuleKey);
37687
+ if (canonicalCandidate === canonicalTarget) return true;
37688
+ return isReactDoctorShortIdOf(canonicalCandidate, canonicalTarget) || isReactDoctorShortIdOf(canonicalTarget, canonicalCandidate);
37689
+ };
37675
37690
  const getEquivalentRuleKeys = (ruleKey) => {
37676
37691
  const nativeRuleKey = canonicalizeRuleKey(ruleKey);
37677
37692
  return [nativeRuleKey, ...getLegacyRuleKeysForNative(nativeRuleKey)];
@@ -37681,12 +37696,182 @@ const stripDescriptionTail = (ruleList) => {
37681
37696
  if (!descriptionMatch || descriptionMatch.index === void 0) return ruleList;
37682
37697
  return ruleList.slice(0, descriptionMatch.index);
37683
37698
  };
37684
- const isRuleListedInComment = (ruleList, ruleId) => {
37699
+ const tokenizeRuleList = (ruleList) => {
37685
37700
  const trimmed = ruleList?.trim();
37686
- if (!trimmed) return true;
37701
+ if (!trimmed) return [];
37687
37702
  const ruleSection = stripDescriptionTail(trimmed).trim();
37688
- if (!ruleSection) return true;
37689
- return ruleSection.split(/[,\s]+/).some((token) => isSameRuleKey(token.trim(), ruleId));
37703
+ if (!ruleSection) return [];
37704
+ return ruleSection.split(/[,\s]+/).map((token) => token.trim()).filter(Boolean);
37705
+ };
37706
+ const FOREIGN_INLINE_DISABLE_PATTERN = /(?:\/\/|\/\*)[ \t]*(eslint|oxlint)-disable-(next-line|line)(?![\w-])([^\r\n]*)/;
37707
+ const FOREIGN_BLOCK_DISABLE_PATTERN = /\/\*[ \t]*(eslint|oxlint)-disable(?![\w-])([^*\r\n]*)/;
37708
+ const FOREIGN_BLOCK_ENABLE_PATTERN = /\/\*[ \t]*(?:eslint|oxlint)-enable(?![\w-])([^*\r\n]*)/;
37709
+ const buildHint = (tool, token, ruleId) => `oxlint matches plugin rules only by their full name, so \`${token}\` in your ${tool}-disable comment does not silence \`${ruleId}\` — change it to \`${ruleId}\`.`;
37710
+ const tokenMisnamesRule = (token, ruleId) => token !== ruleId && isSameRuleKey(token, ruleId);
37711
+ const detectInlineNearMiss = (lines, diagnosticLineIndex, ruleId) => {
37712
+ const candidates = [{
37713
+ line: lines[diagnosticLineIndex],
37714
+ requiredScope: "line"
37715
+ }, {
37716
+ line: lines[diagnosticLineIndex - 1],
37717
+ requiredScope: "next-line"
37718
+ }];
37719
+ for (const { line, requiredScope } of candidates) {
37720
+ const match = line?.match(FOREIGN_INLINE_DISABLE_PATTERN);
37721
+ if (!match) continue;
37722
+ const [, tool, scope, ruleList] = match;
37723
+ if (scope !== requiredScope) continue;
37724
+ const tokens = tokenizeRuleList(ruleList);
37725
+ if (tokens.includes(ruleId)) continue;
37726
+ for (const token of tokens) if (tokenMisnamesRule(token, ruleId)) return buildHint(tool, token, ruleId);
37727
+ }
37728
+ return null;
37729
+ };
37730
+ const detectBlockNearMiss = (lines, diagnosticLineIndex, ruleId) => {
37731
+ let openMisname = null;
37732
+ const lastLineIndex = Math.min(diagnosticLineIndex, lines.length - 1);
37733
+ for (let lineIndex = 0; lineIndex <= lastLineIndex; lineIndex++) {
37734
+ const line = lines[lineIndex];
37735
+ if (line === void 0 || !line.includes("-disable") && !line.includes("-enable")) continue;
37736
+ const disableMatch = line.match(FOREIGN_BLOCK_DISABLE_PATTERN);
37737
+ if (disableMatch) {
37738
+ const [, tool, ruleList] = disableMatch;
37739
+ const tokens = tokenizeRuleList(ruleList);
37740
+ if (tokens.includes(ruleId)) openMisname = null;
37741
+ else {
37742
+ const misnamed = tokens.find((token) => tokenMisnamesRule(token, ruleId));
37743
+ if (misnamed) openMisname = {
37744
+ tool,
37745
+ token: misnamed
37746
+ };
37747
+ }
37748
+ continue;
37749
+ }
37750
+ const enableMatch = line.match(FOREIGN_BLOCK_ENABLE_PATTERN);
37751
+ if (enableMatch) {
37752
+ const enabledRules = tokenizeRuleList(enableMatch[1]);
37753
+ if (enabledRules.length === 0 || enabledRules.some((rule) => isSameRuleKey(rule, ruleId))) openMisname = null;
37754
+ }
37755
+ }
37756
+ return openMisname ? buildHint(openMisname.tool, openMisname.token, ruleId) : null;
37757
+ };
37758
+ const detectForeignDisableNearMiss = (lines, diagnosticLineIndex, ruleId) => {
37759
+ if (!ruleId.startsWith("react-doctor/")) return null;
37760
+ return detectInlineNearMiss(lines, diagnosticLineIndex, ruleId) ?? detectBlockNearMiss(lines, diagnosticLineIndex, ruleId);
37761
+ };
37762
+ const JSX_OPENER_TAG_PATTERN = /<[A-Za-z][\w.]*/g;
37763
+ const JSX_TAG_NAME_FOLLOW = /[A-Za-z]/;
37764
+ const isOpenerMatchInsideLineComment = (line, openerCharIndex) => {
37765
+ let stringDelimiter = null;
37766
+ for (let charIndex = 0; charIndex < openerCharIndex; charIndex++) {
37767
+ const character = line[charIndex];
37768
+ if (stringDelimiter !== null) {
37769
+ if (character === "\\") {
37770
+ charIndex++;
37771
+ continue;
37772
+ }
37773
+ if (character === stringDelimiter) stringDelimiter = null;
37774
+ continue;
37775
+ }
37776
+ if (character === "\"" || character === "'" || character === "`") {
37777
+ stringDelimiter = character;
37778
+ continue;
37779
+ }
37780
+ if (character === "/" && line[charIndex + 1] === "/") return true;
37781
+ }
37782
+ return false;
37783
+ };
37784
+ const findOpenerTagOnLine = (line) => {
37785
+ for (const match of line.matchAll(JSX_OPENER_TAG_PATTERN)) {
37786
+ if (match.index === void 0) continue;
37787
+ if (!isOpenerMatchInsideLineComment(line, match.index)) return { startCharIndex: match.index + match[0].length };
37788
+ }
37789
+ return null;
37790
+ };
37791
+ const findJsxOpenerSpan = (lines, openerLineIndex) => {
37792
+ const openerLine = lines[openerLineIndex];
37793
+ if (openerLine === void 0) return null;
37794
+ const opener = findOpenerTagOnLine(openerLine);
37795
+ if (!opener) return null;
37796
+ const lookaheadLimit = Math.min(lines.length, openerLineIndex + 32);
37797
+ let braceDepth = 0;
37798
+ let innerAngleDepth = 0;
37799
+ let stringDelimiter = null;
37800
+ for (let lineIndex = openerLineIndex; lineIndex < lookaheadLimit; lineIndex++) {
37801
+ const currentLine = lines[lineIndex];
37802
+ const startCharForLine = lineIndex === openerLineIndex ? opener.startCharIndex : 0;
37803
+ for (let charIndex = startCharForLine; charIndex < currentLine.length; charIndex++) {
37804
+ const character = currentLine[charIndex];
37805
+ if (stringDelimiter !== null) {
37806
+ if (character === "\\") {
37807
+ charIndex++;
37808
+ continue;
37809
+ }
37810
+ if (character === stringDelimiter) stringDelimiter = null;
37811
+ continue;
37812
+ }
37813
+ if (character === "\"" || character === "'" || character === "`") {
37814
+ stringDelimiter = character;
37815
+ continue;
37816
+ }
37817
+ if (character === "{") {
37818
+ braceDepth++;
37819
+ continue;
37820
+ }
37821
+ if (character === "}") {
37822
+ braceDepth--;
37823
+ continue;
37824
+ }
37825
+ if (braceDepth !== 0) continue;
37826
+ if (character === "<") {
37827
+ const followCharacter = currentLine[charIndex + 1];
37828
+ if (followCharacter !== void 0 && JSX_TAG_NAME_FOLLOW.test(followCharacter)) innerAngleDepth++;
37829
+ continue;
37830
+ }
37831
+ if (character !== ">") continue;
37832
+ const previousCharacter = currentLine[charIndex - 1];
37833
+ const nextCharacter = currentLine[charIndex + 1];
37834
+ if (previousCharacter === "=" || nextCharacter === "=") continue;
37835
+ if (innerAngleDepth > 0) {
37836
+ innerAngleDepth--;
37837
+ continue;
37838
+ }
37839
+ return lineIndex;
37840
+ }
37841
+ }
37842
+ return null;
37843
+ };
37844
+ const findEnclosingMultilineJsxOpenerStart = (lines, diagnosticLineIndex) => {
37845
+ for (let candidateIndex = diagnosticLineIndex - 1; candidateIndex >= 0 && diagnosticLineIndex - candidateIndex <= 32; candidateIndex--) {
37846
+ const openerCloseIndex = findJsxOpenerSpan(lines, candidateIndex);
37847
+ if (openerCloseIndex !== null && openerCloseIndex >= diagnosticLineIndex) return candidateIndex;
37848
+ }
37849
+ return null;
37850
+ };
37851
+ const DISABLE_NEXT_LINE_PATTERN = /(?:\/\/|\/\*)\s*react-doctor-disable-next-line\b(?:\s+([^\r\n]*?))?\s*(?:\*\/)?\s*\}?\s*$/;
37852
+ const findStackedDisableCommentsAbove = (lines, anchorIndex) => {
37853
+ const collected = [];
37854
+ let isStillInChain = true;
37855
+ for (let candidateIndex = anchorIndex - 1; candidateIndex >= 0 && anchorIndex - candidateIndex <= 10; candidateIndex--) {
37856
+ const candidateLine = lines[candidateIndex];
37857
+ if (candidateLine === void 0) break;
37858
+ const match = candidateLine.match(DISABLE_NEXT_LINE_PATTERN);
37859
+ if (match) {
37860
+ collected.push({
37861
+ commentLineIndex: candidateIndex,
37862
+ ruleList: match[1],
37863
+ isInChain: isStillInChain
37864
+ });
37865
+ continue;
37866
+ }
37867
+ isStillInChain = false;
37868
+ }
37869
+ return collected;
37870
+ };
37871
+ const isRuleListedInComment = (ruleList, ruleId) => {
37872
+ const tokens = tokenizeRuleList(ruleList);
37873
+ if (tokens.length === 0) return true;
37874
+ return tokens.some((token) => isSameRuleKey(token, ruleId));
37690
37875
  };
37691
37876
  const DISABLE_LINE_PATTERN = /(?:\/\/|\/\*)\s*react-doctor-disable-line\b(?:\s+([^\r\n]*?))?\s*(?:\*\/)?\s*\}?\s*$/;
37692
37877
  const formatLineGap = (gapLineCount) => `${gapLineCount} line${gapLineCount === 1 ? "" : "s"}`;
@@ -37730,7 +37915,7 @@ const evaluateSuppression = (lines, diagnosticLineIndex, ruleId) => {
37730
37915
  };
37731
37916
  return {
37732
37917
  isSuppressed: false,
37733
- nearMissHint: classifyFromComments([directComments, openerComments], diagnosticLineIndex, ruleId)
37918
+ nearMissHint: classifyFromComments([directComments, openerComments], diagnosticLineIndex, ruleId) ?? detectForeignDisableNearMiss(lines, diagnosticLineIndex, ruleId)
37734
37919
  };
37735
37920
  };
37736
37921
  /**
@@ -38156,6 +38341,11 @@ var OxlintBatchExceeded = class extends TaggedErrorClass()("OxlintBatchExceeded"
38156
38341
  }
38157
38342
  }
38158
38343
  };
38344
+ var ScanDeadlineExceeded = class extends TaggedErrorClass()("ScanDeadlineExceeded", { detail: String$1 }) {
38345
+ get message() {
38346
+ return `Scan exceeded its overall time budget: ${this.detail}`;
38347
+ }
38348
+ };
38159
38349
  var OxlintSpawnFailed = class extends TaggedErrorClass()("OxlintSpawnFailed", { cause: Unknown }) {
38160
38350
  get message() {
38161
38351
  return `Failed to run oxlint: ${pretty(fail$6(this.cause))}`;
@@ -38219,6 +38409,7 @@ var GitBaseBranchInvalid = class extends TaggedErrorClass()("GitBaseBranchInvali
38219
38409
  const ReactDoctorErrorReason = Union([
38220
38410
  OxlintUnavailable,
38221
38411
  OxlintBatchExceeded,
38412
+ ScanDeadlineExceeded,
38222
38413
  OxlintSpawnFailed,
38223
38414
  OxlintOutputUnparseable,
38224
38415
  ConfigParseFailed,
@@ -38291,15 +38482,105 @@ const layerOtlp = unwrap$3(gen(function* () {
38291
38482
  }).pipe(provide$2(layer$9));
38292
38483
  }).pipe(orDie));
38293
38484
  /**
38294
- * Resolves a requested lint worker count to a clamped integer within
38295
- * `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`. `"auto"` uses the
38296
- * machine's CPU cores; out-of-range or non-finite requests degrade to
38485
+ * Read a positive-millisecond timeout from an env var, falling back to
38486
+ * `defaultMs` when the var is unset, non-finite, or not strictly positive.
38487
+ */
38488
+ const readPositiveEnvMs = (envVarName, defaultMs) => {
38489
+ const rawValue = process.env[envVarName];
38490
+ if (rawValue === void 0) return defaultMs;
38491
+ const parsedValue = Number(rawValue);
38492
+ if (!Number.isFinite(parsedValue) || parsedValue <= 0) return defaultMs;
38493
+ return parsedValue;
38494
+ };
38495
+ const CGROUP_V2_MEMORY_MAX_PATH = "/sys/fs/cgroup/memory.max";
38496
+ const CGROUP_V1_MEMORY_LIMIT_PATH = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
38497
+ const CGROUP_UNLIMITED_SENTINEL_BYTES = Number.MAX_SAFE_INTEGER;
38498
+ /**
38499
+ * Parses one raw cgroup memory-limit file value into a positive byte count, or
38500
+ * `undefined` when it represents "no limit" (the v2 `"max"` literal, an empty
38501
+ * read, a non-positive / non-finite value, or v1's near-2^63 unlimited
38502
+ * sentinel). Pure and exported so the classification is unit-testable without
38503
+ * touching the filesystem.
38504
+ */
38505
+ const parseCgroupMemoryLimitBytes = (raw) => {
38506
+ if (raw === void 0) return void 0;
38507
+ const trimmed = raw.trim();
38508
+ if (trimmed === "" || trimmed === "max") return void 0;
38509
+ const parsed = Number(trimmed);
38510
+ if (!Number.isFinite(parsed) || parsed <= 0 || parsed >= CGROUP_UNLIMITED_SENTINEL_BYTES) return;
38511
+ return parsed;
38512
+ };
38513
+ const CGROUP_MEMORY_LIMIT_PATHS = [CGROUP_V2_MEMORY_MAX_PATH, CGROUP_V1_MEMORY_LIMIT_PATH];
38514
+ /**
38515
+ * Reads this process's cgroup memory limit in bytes from the first candidate
38516
+ * path that yields a real limit, or `undefined` when none does — no cgroup, no
38517
+ * limit, or the files are unreadable (e.g. macOS / Windows dev machines).
38518
+ * `os.totalmem()` reports the HOST total and ignores cgroup memory limits, so a
38519
+ * memory-constrained container over-reports total memory; `resolveAutoScan-
38520
+ * Concurrency` takes `min(totalmem, this)` to honor the limit.
38521
+ *
38522
+ * The cgroup v2 read is the mount-root `memory.max`, which IS the container's
38523
+ * limit under the standard cgroup-namespace setup CI runners use (the
38524
+ * container's own cgroup is the root of its namespaced view). A process in a
38525
+ * non-namespaced nested/delegated cgroup whose root reads `"max"` is not
38526
+ * detected here and falls back to the host total; the EAGAIN/ENOMEM serial
38527
+ * replay in `spawnLintBatches` remains the runtime backstop for that case.
38528
+ *
38529
+ * `candidatePaths` is injectable so tests exercise the v2-wins-over-v1
38530
+ * precedence, the skip-unreadable fallback, and the all-missing case without a
38531
+ * real `/sys/fs/cgroup`.
38532
+ */
38533
+ const readCgroupMemoryLimitBytes = (candidatePaths = CGROUP_MEMORY_LIMIT_PATHS) => {
38534
+ for (const limitPath of candidatePaths) {
38535
+ let raw;
38536
+ try {
38537
+ raw = fs.readFileSync(limitPath, "utf8");
38538
+ } catch {
38539
+ continue;
38540
+ }
38541
+ const limitBytes = parseCgroupMemoryLimitBytes(raw);
38542
+ if (limitBytes !== void 0) return limitBytes;
38543
+ }
38544
+ };
38545
+ /**
38546
+ * Clamps a requested lint worker count to `[MIN_SCAN_CONCURRENCY,
38547
+ * HARD_MAX_SCAN_CONCURRENCY]` as a finite integer. This is the explicit-pin and
38548
+ * spawn-boundary clamp — the memory-and-core-budgeted auto count comes from
38549
+ * `resolveAutoScanConcurrency`. Out-of-range or non-finite requests degrade to
38297
38550
  * `MIN_SCAN_CONCURRENCY` rather than oversubscribing or running zero workers.
38298
38551
  */
38299
38552
  const resolveScanConcurrency = (requested) => {
38300
- const desired = requested === "auto" ? os.availableParallelism() : requested;
38301
- if (!Number.isFinite(desired) || desired < 1) return 1;
38302
- return Math.max(1, Math.min(Math.floor(desired), 16));
38553
+ if (!Number.isFinite(requested) || requested < 1) return 1;
38554
+ return Math.min(Math.floor(requested), 32);
38555
+ };
38556
+ const readSystemFacts = () => ({
38557
+ availableCores: os.availableParallelism(),
38558
+ totalMemoryBytes: os.totalmem(),
38559
+ cgroupMemoryLimitBytes: readCgroupMemoryLimitBytes()
38560
+ });
38561
+ /**
38562
+ * Auto lint-worker count: the smaller of the (cgroup-CPU-aware) core count and
38563
+ * the number of `PER_WORKER_MEM_BUDGET_BYTES` workers that fit in available
38564
+ * memory, then clamped to `[MIN, HARD_MAX]` by `resolveScanConcurrency`.
38565
+ *
38566
+ * `os.availableParallelism()` already respects cgroup CPU quotas, so the core
38567
+ * term needs no help. Available memory is `os.totalmem()` floored by the cgroup
38568
+ * memory limit — `os.freemem()` is deliberately NOT used: it excludes
38569
+ * reclaimable page cache and reads near-zero on macOS / cache-heavy Linux, which
38570
+ * would collapse the auto path to a single worker. `os.totalmem()` reports the
38571
+ * host total even inside a container, so the cgroup limit (read directly,
38572
+ * because Node doesn't fold it into `totalmem()`) is the real ceiling there.
38573
+ *
38574
+ * `facts` is injectable so tests exercise core-bound, memory-bound, cgroup-
38575
+ * limited, and ceiling cases without mocking `os` or the filesystem.
38576
+ */
38577
+ const resolveAutoScanConcurrency = (facts = readSystemFacts()) => {
38578
+ const availableMemoryBytes = Math.min(facts.totalMemoryBytes, facts.cgroupMemoryLimitBytes ?? Number.POSITIVE_INFINITY);
38579
+ const memoryBoundedWorkers = Math.floor(availableMemoryBytes / PER_WORKER_MEM_BUDGET_BYTES);
38580
+ return resolveScanConcurrency(Math.min(facts.availableCores, memoryBoundedWorkers));
38581
+ };
38582
+ const resolveLintBatchOrdering = () => {
38583
+ return process.env["REACT_DOCTOR_LINT_BATCH_ORDERING"]?.trim().toLowerCase() === "cost" ? "cost" : "arrival";
38303
38584
  };
38304
38585
  /**
38305
38586
  * Per-batch oxlint wall-clock budget. Reads from the env var on
@@ -38307,11 +38588,38 @@ const resolveScanConcurrency = (requested) => {
38307
38588
  * microVMs without recompiling react-doctor. Tests override via
38308
38589
  * `Layer.succeed(OxlintSpawnTimeoutMs, ...)`.
38309
38590
  */
38310
- var OxlintSpawnTimeoutMs = class extends Reference("react-doctor/OxlintSpawnTimeoutMs", { defaultValue: () => {
38311
- const raw = process.env["REACT_DOCTOR_OXLINT_SPAWN_TIMEOUT_MS"];
38312
- if (raw === void 0) return OXLINT_SPAWN_TIMEOUT_MS;
38591
+ var OxlintSpawnTimeoutMs = class extends Reference("react-doctor/OxlintSpawnTimeoutMs", { defaultValue: () => readPositiveEnvMs("REACT_DOCTOR_OXLINT_SPAWN_TIMEOUT_MS", OXLINT_SPAWN_TIMEOUT_MS) }) {};
38592
+ /**
38593
+ * Effect-side cap on the lint phase. The env var lets CI / eval runners
38594
+ * raise the phase budget for slow large repos without recompiling.
38595
+ * Tests override via `Layer.succeed(LintPhaseTimeoutMs, ...)`.
38596
+ */
38597
+ var LintPhaseTimeoutMs = class extends Reference("react-doctor/LintPhaseTimeoutMs", { defaultValue: () => readPositiveEnvMs("REACT_DOCTOR_LINT_PHASE_TIMEOUT_MS", LINT_PHASE_TIMEOUT_MS) }) {};
38598
+ /**
38599
+ * Effect-side cap on the dead-code phase, sitting above the in-worker
38600
+ * timeout as a runtime-independent backstop. The env var raises it for
38601
+ * type-heavy projects; tests override via
38602
+ * `Layer.succeed(DeadCodePhaseTimeoutMs, ...)`.
38603
+ */
38604
+ var DeadCodePhaseTimeoutMs = class extends Reference("react-doctor/DeadCodePhaseTimeoutMs", { defaultValue: () => readPositiveEnvMs("REACT_DOCTOR_DEAD_CODE_PHASE_TIMEOUT_MS", DEAD_CODE_PHASE_TIMEOUT_MS) }) {};
38605
+ /**
38606
+ * Overall scan deadline backstop, bounding everything the per-phase
38607
+ * timeouts don't (wedged git / IO). The env var raises it for very
38608
+ * large repos; tests override via `Layer.succeed(ScanDeadlineMs, ...)`.
38609
+ */
38610
+ var ScanDeadlineMs = class extends Reference("react-doctor/ScanDeadlineMs", { defaultValue: () => readPositiveEnvMs("REACT_DOCTOR_SCAN_DEADLINE_MS", SCAN_TOTAL_DEADLINE_MS) }) {};
38611
+ /**
38612
+ * Wall-clock budget for the supply-chain check when it runs on a background
38613
+ * fiber overlapping the lint pass. Reads from the env var on startup so the
38614
+ * eval harness can raise the budget under sandbox microVMs (slower network)
38615
+ * without recompiling react-doctor. Tests override via
38616
+ * `Layer.succeed(SupplyChainOverlapTimeoutMs, ...)`.
38617
+ */
38618
+ var SupplyChainOverlapTimeoutMs = class extends Reference("react-doctor/SupplyChainOverlapTimeoutMs", { defaultValue: () => {
38619
+ const raw = process.env["REACT_DOCTOR_SUPPLY_CHAIN_TIMEOUT_MS"];
38620
+ if (raw === void 0) return SUPPLY_CHAIN_OVERLAP_TIMEOUT_MS;
38313
38621
  const parsed = Number(raw);
38314
- if (!Number.isFinite(parsed) || parsed <= 0) return OXLINT_SPAWN_TIMEOUT_MS;
38622
+ if (!Number.isFinite(parsed) || parsed <= 0) return SUPPLY_CHAIN_OVERLAP_TIMEOUT_MS;
38315
38623
  return parsed;
38316
38624
  } }) {};
38317
38625
  /**
@@ -38322,31 +38630,93 @@ var OxlintSpawnTimeoutMs = class extends Reference("react-doctor/OxlintSpawnTime
38322
38630
  */
38323
38631
  var OxlintOutputMaxBytes = class extends Reference("react-doctor/OxlintOutputMaxBytes", { defaultValue: () => OXLINT_OUTPUT_MAX_BYTES }) {};
38324
38632
  /**
38325
- * Number of oxlint subprocesses the lint pass runs in parallel. Defaults
38326
- * to auto-detected CPU cores (parallel) so large repos scan fast out of
38327
- * the box; `spawnLintBatches` transparently falls back to a single worker
38328
- * if a parallel run exhausts system resources. The CLI's `--no-parallel`
38329
- * flag forces serial via `Layer.succeed`; the `REACT_DOCTOR_PARALLEL` env
38330
- * var seeds the default for programmatic / CI callers that never touch the
38331
- * flag parallelism is opt-OUT, so only the explicit serial values pin
38332
- * one worker:
38333
- *
38334
- * - unset / `auto` / `true` / `on` → available CPU cores (clamped)
38633
+ * Number of oxlint subprocesses the lint pass runs in parallel. Defaults to a
38634
+ * memory-and-core-budgeted auto count (`resolveAutoScanConcurrency`) so large
38635
+ * repos scan fast out of the box without OOMing the native binding on a
38636
+ * high-core / low-memory box; `spawnLintBatches` transparently falls back to a
38637
+ * single worker if a parallel run still exhausts system resources. The CLI's
38638
+ * `--no-parallel` flag forces serial via `Layer.succeed`; the
38639
+ * `REACT_DOCTOR_PARALLEL` env var seeds the default for programmatic / CI
38640
+ * callers that never touch the flag — parallelism is opt-OUT, so only the
38641
+ * explicit serial values pin one worker:
38642
+ *
38643
+ * - unset / `auto` / `true` / `on` → memory-and-core-budgeted auto count
38335
38644
  * - `0` / `false` / `off` → `1` (serial)
38336
38645
  * - a positive integer → that many workers (clamped)
38337
- * - any other value → available CPU cores (clamped)
38646
+ * - any other value → memory-and-core-budgeted auto count
38338
38647
  *
38339
38648
  * The resolved value is always within
38340
- * `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`.
38649
+ * `[MIN_SCAN_CONCURRENCY, HARD_MAX_SCAN_CONCURRENCY]`.
38341
38650
  */
38342
38651
  var OxlintConcurrency = class extends Reference("react-doctor/OxlintConcurrency", { defaultValue: () => {
38343
38652
  const raw = process.env["REACT_DOCTOR_PARALLEL"];
38344
- if (raw === void 0) return resolveScanConcurrency("auto");
38653
+ if (raw === void 0) return resolveAutoScanConcurrency();
38345
38654
  const normalized = raw.trim().toLowerCase();
38346
38655
  if (normalized === "0" || normalized === "false" || normalized === "off") return 1;
38347
38656
  const parsed = Number.parseInt(normalized, 10);
38348
38657
  if (Number.isInteger(parsed) && parsed > 0) return resolveScanConcurrency(parsed);
38349
- return resolveScanConcurrency("auto");
38658
+ return resolveAutoScanConcurrency();
38659
+ } }) {};
38660
+ /**
38661
+ * Three-state control for overlapping the dead-code pass with the lint pass —
38662
+ * forking dead-code as a child fiber that runs DURING lint instead of strictly
38663
+ * after it.
38664
+ *
38665
+ * - `"auto"` (default) / `"off"` → strictly SEQUENTIAL: dead-code runs after
38666
+ * lint with the full core budget. Both deslop's parse pool and the oxlint
38667
+ * pool are CPU-bound and each size themselves to all cores, so overlapping
38668
+ * them only oversubscribes (~2x the cores) and starves the parse pass past
38669
+ * its timeout — for no wall-clock win, since there are no spare cores to
38670
+ * absorb the second pass. Sequential is both faster per-phase and safe.
38671
+ * - `"on"` → force the overlap anyway. The orchestrator then SPLITS the core
38672
+ * budget (`DEAD_CODE_OVERLAP_PARSE_SHARE`): deslop's parse pool is capped
38673
+ * and lint shrinks to the remainder, so the two sum to the cores instead of
38674
+ * doubling them, and the dead-code timeout scales up for the reduced share.
38675
+ *
38676
+ * Seeded from `REACT_DOCTOR_DEAD_CODE_OVERLAP` so operators get a redeploy-free
38677
+ * switch; tests pin it via `Layer.succeed(DeadCodeOverlap, ...)`.
38678
+ */
38679
+ var DeadCodeOverlap = class extends Reference("react-doctor/DeadCodeOverlap", { defaultValue: () => {
38680
+ const raw = process.env["REACT_DOCTOR_DEAD_CODE_OVERLAP"]?.trim().toLowerCase();
38681
+ if (raw === "on" || raw === "true" || raw === "1") return "on";
38682
+ if (raw === "off" || raw === "false" || raw === "0") return "off";
38683
+ return "auto";
38684
+ } }) {};
38685
+ /**
38686
+ * How the full-scan lint pass orders its file batches. `"arrival"` (the
38687
+ * default) keeps `git ls-files` discovery order. `"cost"` opts into LPT (feed
38688
+ * the largest files first); set `REACT_DOCTOR_LINT_BATCH_ORDERING=cost`. NOTE:
38689
+ * `cost` is OFF by default because the current sort-desc-then-chunk-100 packs
38690
+ * the heaviest files into one wave-1 batch — on size-skewed repos that mega-
38691
+ * batch is a straggler (and can trip the per-batch timeout + split), measurably
38692
+ * regressing the common full-scan case. LPT needs the heavy files SPREAD across
38693
+ * batches before `cost` earns the default. Tests override via
38694
+ * `Layer.succeed(LintBatchOrdering, ...)`. Diff / staged scans never reach this
38695
+ * — they pass user-scoped `includePaths` that skip discovery and stay in
38696
+ * arrival order; only the full-scan branch reads it.
38697
+ */
38698
+ var LintBatchOrdering = class extends Reference("react-doctor/LintBatchOrdering", { defaultValue: resolveLintBatchOrdering }) {};
38699
+ const CACHE_DISABLED_VALUES$1 = new Set(["1", "true"]);
38700
+ /**
38701
+ * Whether the per-file lint cache (`runners/oxlint/file-lint-cache.ts`) is
38702
+ * active. Defaults ON — repeat scans re-lint only the files whose content
38703
+ * changed, and correctness is guaranteed byte-identical to a cold scan by the
38704
+ * always-fresh cross-file sidecar. Opt-OUT, two knobs (matching the whole-repo
38705
+ * scan cache's `REACT_DOCTOR_NO_CACHE`):
38706
+ *
38707
+ * - `REACT_DOCTOR_NO_CACHE` — the global off-switch; disables BOTH the
38708
+ * whole-repo scan cache and this per-file cache.
38709
+ * - `REACT_DOCTOR_NO_FILE_CACHE` — granular: bust only the per-file cache
38710
+ * while keeping the whole-repo short-circuit.
38711
+ *
38712
+ * Tests override via `Layer.succeed(PerFileLintCacheEnabled, false)`.
38713
+ */
38714
+ var PerFileLintCacheEnabled = class extends Reference("react-doctor/PerFileLintCacheEnabled", { defaultValue: () => {
38715
+ const noCache = process.env["REACT_DOCTOR_NO_CACHE"]?.toLowerCase() ?? "";
38716
+ const noFileCache = process.env["REACT_DOCTOR_NO_FILE_CACHE"]?.toLowerCase() ?? "";
38717
+ if (CACHE_DISABLED_VALUES$1.has(noCache)) return false;
38718
+ if (CACHE_DISABLED_VALUES$1.has(noFileCache)) return false;
38719
+ return true;
38350
38720
  } }) {};
38351
38721
  const DIAGNOSTIC_SURFACES = [
38352
38722
  "cli",
@@ -38520,7 +38890,6 @@ const PACKAGE_JSON_FILENAME = "package.json";
38520
38890
  const PACKAGE_JSON_CONFIG_KEY$1 = "reactDoctor";
38521
38891
  const LEGACY_CONFIG_FILENAME = "react-doctor.config.json";
38522
38892
  const jiti = createJiti(import.meta.url);
38523
- const formatError = (error) => error instanceof Error ? error.message : String(error);
38524
38893
  const importDefaultExport = async (jitiInstance, filePath) => {
38525
38894
  const imported = await jitiInstance.import(filePath);
38526
38895
  return imported?.default ?? imported;
@@ -38552,7 +38921,7 @@ const loadModuleConfig = async (filePath) => {
38552
38921
  try {
38553
38922
  return await importDefaultExport(aliasJiti, filePath);
38554
38923
  } catch (retryError) {
38555
- throw new Error(`${formatError(error)} (retry with ${SELF_PACKAGE_IMPORT_SPECIFIER} aliased to the running react-doctor package also failed: ${formatError(retryError)})`, { cause: retryError });
38924
+ throw new Error(`${messageFromUnknown(error)} (retry with ${SELF_PACKAGE_IMPORT_SPECIFIER} aliased to the running react-doctor package also failed: ${messageFromUnknown(retryError)})`, { cause: retryError });
38556
38925
  }
38557
38926
  }
38558
38927
  };
@@ -38601,7 +38970,7 @@ const loadLegacyConfig = (directory) => {
38601
38970
  }
38602
38971
  warn(`${LEGACY_CONFIG_FILENAME} must contain an object, ignoring.`);
38603
38972
  } catch (error) {
38604
- warn(`Failed to load ${LEGACY_CONFIG_FILENAME}: ${formatError(error)}`);
38973
+ warn(`Failed to load ${LEGACY_CONFIG_FILENAME}: ${messageFromUnknown(error)}`);
38605
38974
  }
38606
38975
  return {
38607
38976
  status: "invalid",
@@ -38628,7 +38997,7 @@ const loadConfigFromDirectory = async (directory) => {
38628
38997
  warn(`${CONFIG_BASENAME}.${extension} must export an object, ignoring.`);
38629
38998
  sawBrokenConfigFile = true;
38630
38999
  } catch (error) {
38631
- warn(`Failed to load ${CONFIG_BASENAME}.${extension}: ${formatError(error)}`);
39000
+ warn(`Failed to load ${CONFIG_BASENAME}.${extension}: ${messageFromUnknown(error)}`);
38632
39001
  sawBrokenConfigFile = true;
38633
39002
  }
38634
39003
  }
@@ -38758,6 +39127,31 @@ const resolveScanTarget = async (requestedDirectory, options = {}) => {
38758
39127
  didRedirectViaRootDir: redirectedDirectory !== null
38759
39128
  };
38760
39129
  };
39130
+ const buildFixGroupId = (diagnostic) => createHash("sha1").update(JSON.stringify([
39131
+ diagnostic.filePath,
39132
+ `${diagnostic.plugin}/${diagnostic.rule}`,
39133
+ diagnostic.message
39134
+ ])).digest("hex").slice(0, 16);
39135
+ const isGroupableRule = (diagnostic) => ROOT_CAUSE_GROUPABLE_RULE_KEYS.has(`${diagnostic.plugin}/${diagnostic.rule}`);
39136
+ const assignFixGroups = (diagnostics) => {
39137
+ const siteCountByGroupId = /* @__PURE__ */ new Map();
39138
+ for (const diagnostic of diagnostics) {
39139
+ if (!isGroupableRule(diagnostic)) continue;
39140
+ const groupId = buildFixGroupId(diagnostic);
39141
+ siteCountByGroupId.set(groupId, (siteCountByGroupId.get(groupId) ?? 0) + 1);
39142
+ }
39143
+ return diagnostics.map((diagnostic) => {
39144
+ if (!isGroupableRule(diagnostic)) return diagnostic;
39145
+ const groupId = buildFixGroupId(diagnostic);
39146
+ if ((siteCountByGroupId.get(groupId) ?? 0) < 2) return diagnostic;
39147
+ return {
39148
+ ...diagnostic,
39149
+ fixGroupId: groupId
39150
+ };
39151
+ });
39152
+ };
39153
+ const compareStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
39154
+ const sortDiagnosticsStable = (diagnostics) => [...diagnostics].sort((left, right) => compareStrings(left.filePath, right.filePath) || left.line - right.line || left.column - right.column || compareStrings(left.plugin, right.plugin) || compareStrings(left.rule, right.rule) || compareStrings(left.severity, right.severity) || compareStrings(left.message, right.message));
38761
39155
  const getDirectDependencyNames = (packageJson) => new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.devDependencies ?? {})]);
38762
39156
  const buildExpoCheckContext = (rootDirectory, expoVersion) => {
38763
39157
  const packageJson = readPackageJson$1(Path.join(rootDirectory, "package.json"));
@@ -39264,10 +39658,15 @@ const buildHardeningDiagnostic = (input) => ({
39264
39658
  column: input.column ?? 0,
39265
39659
  category: "Security"
39266
39660
  });
39267
- const checkPnpmHardening = (rootDirectory) => {
39268
- if (!isPnpmManagedProject(rootDirectory)) return [];
39269
- const workspacePath = Path.join(rootDirectory, PNPM_WORKSPACE_FILE);
39270
- const settings = parseHardeningSettings(isFile(workspacePath) ? NFS.readFileSync(workspacePath, "utf-8") : "");
39661
+ const checkPnpmHardening = (scanDirectory) => {
39662
+ if (!isPnpmManagedProject(scanDirectory)) return [];
39663
+ const workspacePath = Path.join(scanDirectory, PNPM_WORKSPACE_FILE);
39664
+ const hasWorkspaceFile = isFile(workspacePath);
39665
+ if (!hasWorkspaceFile) {
39666
+ const monorepoRoot = findMonorepoRoot(scanDirectory);
39667
+ if (monorepoRoot !== null && isFile(Path.join(monorepoRoot, PNPM_WORKSPACE_FILE))) return [];
39668
+ }
39669
+ const settings = parseHardeningSettings(hasWorkspaceFile ? NFS.readFileSync(workspacePath, "utf-8") : "");
39271
39670
  const diagnostics = [];
39272
39671
  if (settings.minimumReleaseAge === null) diagnostics.push(buildHardeningDiagnostic({
39273
39672
  message: "pnpm-workspace.yaml is missing `minimumReleaseAge` — newly published versions can ship malware that gets caught and unpublished within hours",
@@ -39903,7 +40302,7 @@ const readIgnoreFile = (filePath) => {
39903
40302
  try {
39904
40303
  content = NFS.readFileSync(filePath, "utf-8");
39905
40304
  } catch (error) {
39906
- const errnoCode = error?.code;
40305
+ const errnoCode = isErrnoException(error) ? error.code : void 0;
39907
40306
  if (errnoCode && errnoCode !== "ENOENT") runSync(warn$1(`Could not read ignore file ${filePath}: ${errnoCode}`));
39908
40307
  return [];
39909
40308
  }
@@ -39941,8 +40340,8 @@ const collectIgnorePatterns = (rootDirectory) => {
39941
40340
  cachedPatternsByRoot.set(rootDirectory, patterns);
39942
40341
  return patterns;
39943
40342
  };
40343
+ const isRecord$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
39944
40344
  const KNIP_JSON_FILENAME = "knip.json";
39945
- const isRecord$1$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
39946
40345
  const readJsonFileSafe = (filePath) => {
39947
40346
  let rawContents;
39948
40347
  try {
@@ -39958,10 +40357,10 @@ const readJsonFileSafe = (filePath) => {
39958
40357
  };
39959
40358
  const readKnipConfig = (rootDirectory) => {
39960
40359
  const knipJson = readJsonFileSafe(path.join(rootDirectory, KNIP_JSON_FILENAME));
39961
- if (isRecord$1$1(knipJson)) return knipJson;
40360
+ if (isRecord$2(knipJson)) return knipJson;
39962
40361
  const packageJson = readJsonFileSafe(path.join(rootDirectory, "package.json"));
39963
- const packageKnipConfig = isRecord$1$1(packageJson) ? packageJson.knip : null;
39964
- return isRecord$1$1(packageKnipConfig) ? packageKnipConfig : null;
40362
+ const packageKnipConfig = isRecord$2(packageJson) ? packageJson.knip : null;
40363
+ return isRecord$2(packageKnipConfig) ? packageKnipConfig : null;
39965
40364
  };
39966
40365
  const normalizePatternList = (value) => {
39967
40366
  if (typeof value === "string" && value.length > 0) return [value];
@@ -39973,10 +40372,10 @@ const prefixWorkspacePatterns = (workspacePattern, patterns) => {
39973
40372
  return patterns.map((pattern) => pattern.startsWith("!") ? `!${normalizedWorkspacePattern}/${pattern.slice(1)}` : `${normalizedWorkspacePattern}/${pattern}`);
39974
40373
  };
39975
40374
  const collectKnipWorkspacePatterns = (workspaces, settingName) => {
39976
- if (!isRecord$1$1(workspaces)) return [];
40375
+ if (!isRecord$2(workspaces)) return [];
39977
40376
  const patterns = [];
39978
40377
  for (const [workspacePattern, workspaceConfig] of Object.entries(workspaces)) {
39979
- if (!isRecord$1$1(workspaceConfig)) continue;
40378
+ if (!isRecord$2(workspaceConfig)) continue;
39980
40379
  patterns.push(...prefixWorkspacePatterns(workspacePattern, normalizePatternList(workspaceConfig[settingName])));
39981
40380
  }
39982
40381
  return patterns;
@@ -40021,8 +40420,6 @@ const toCanonicalPath = (filePath) => {
40021
40420
  };
40022
40421
  const DEAD_CODE_PLUGIN = "deslop";
40023
40422
  const DEAD_CODE_CATEGORY = "Maintainability";
40024
- const TSCONFIG_FILENAMES$1 = ["tsconfig.json", "tsconfig.base.json"];
40025
- const isRecord$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
40026
40423
  const DEAD_CODE_WORKER_SCRIPT = `
40027
40424
  const inputChunks = [];
40028
40425
  process.stdin.on("data", (chunk) => inputChunks.push(chunk));
@@ -40070,6 +40467,22 @@ process.stdin.on("end", () => {
40070
40467
  ...(workerInput.ignorePatterns.length > 0
40071
40468
  ? { ignorePatterns: workerInput.ignorePatterns }
40072
40469
  : {}),
40470
+ // We consume only deslop's GRAPH-based findings (unusedFiles, unusedExports,
40471
+ // unusedDependencies, circularDependencies). Everything else deslop can compute
40472
+ // is pure wasted work for us, and it's the bulk of the runtime:
40473
+ // - semantic: a full TS Program for unusedTypes/enum/class-members/
40474
+ // misclassifiedDependencies (~37-45% of the phase).
40475
+ // - reportCodeQuality: the duplicate-block, complexity, feature-flag,
40476
+ // TypeScript-smell, private-type-leak and re-export-cycle detectors. These
40477
+ // are the single most expensive pass — duplicate-block detection alone was
40478
+ // ~83s of a ~130s Sentry scan — so skipping them is an ~8.5x dead-code
40479
+ // speedup on a large repo.
40480
+ // Both are provably safe: the consumed graph findings are computed by their own
40481
+ // detectors, independent of these passes (confirmed byte-identical on
40482
+ // excalidraw + mui-material + sentry). tsConfigPath stays — the module resolver
40483
+ // needs it for path-alias resolution in the import graph.
40484
+ semantic: { enabled: false },
40485
+ reportCodeQuality: false,
40073
40486
  };
40074
40487
  const result = await analyze(defineConfig(config));
40075
40488
  emit({ ok: true, result: normalizeResult(result) });
@@ -40080,7 +40493,7 @@ process.stdin.on("end", () => {
40080
40493
  });
40081
40494
  `;
40082
40495
  const resolveTsConfigPath = (rootDirectory) => {
40083
- for (const filename of TSCONFIG_FILENAMES$1) {
40496
+ for (const filename of TSCONFIG_FILENAMES) {
40084
40497
  const candidate = Path.join(rootDirectory, filename);
40085
40498
  if (NFS.existsSync(candidate)) return candidate;
40086
40499
  }
@@ -40199,7 +40612,11 @@ const createDeadCodeWorker = (input) => {
40199
40612
  "pipe",
40200
40613
  "pipe"
40201
40614
  ],
40202
- windowsHide: true
40615
+ windowsHide: true,
40616
+ env: input.parseConcurrency === void 0 ? process.env : {
40617
+ ...process.env,
40618
+ DESLOP_PARSE_CONCURRENCY: String(input.parseConcurrency)
40619
+ }
40203
40620
  });
40204
40621
  const stdoutChunks = [];
40205
40622
  const stderrChunks = [];
@@ -40244,28 +40661,25 @@ const createDeadCodeWorker = (input) => {
40244
40661
  }
40245
40662
  };
40246
40663
  };
40247
- const runDeadCodeWorkerWithTimeout = (handle, timeoutMs) => new Promise((resolve, reject) => {
40664
+ const runDeadCodeWorkerWithTimeout = (handle, timeoutMs, abortSignal) => new Promise((resolve, reject) => {
40248
40665
  let didSettle = false;
40249
- const timeoutHandle = setTimeout(() => {
40250
- if (didSettle) return;
40251
- didSettle = true;
40252
- handle.terminate?.();
40253
- reject(/* @__PURE__ */ new Error(`Dead-code worker timed out after ${timeoutMs / MILLISECONDS_PER_SECOND}s.`));
40254
- }, timeoutMs);
40255
- timeoutHandle.unref?.();
40256
- handle.result.then((value) => {
40666
+ const settle = (finish) => {
40257
40667
  if (didSettle) return;
40258
40668
  didSettle = true;
40259
40669
  clearTimeout(timeoutHandle);
40670
+ abortSignal?.removeEventListener("abort", onAbort);
40260
40671
  handle.terminate?.();
40261
- resolve(value);
40262
- }, (error) => {
40263
- if (didSettle) return;
40264
- didSettle = true;
40265
- clearTimeout(timeoutHandle);
40266
- handle.terminate?.();
40267
- reject(error);
40268
- });
40672
+ finish();
40673
+ };
40674
+ const onAbort = () => settle(() => reject(/* @__PURE__ */ new Error("Dead-code worker aborted.")));
40675
+ const timeoutHandle = setTimeout(() => settle(() => reject(/* @__PURE__ */ new Error(`Dead-code worker timed out after ${timeoutMs / MILLISECONDS_PER_SECOND}s.`))), timeoutMs);
40676
+ timeoutHandle.unref?.();
40677
+ if (abortSignal?.aborted) {
40678
+ onAbort();
40679
+ return;
40680
+ }
40681
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
40682
+ handle.result.then((value) => settle(() => resolve(value)), (error) => settle(() => reject(error)));
40269
40683
  });
40270
40684
  const checkDeadCode = async (options) => {
40271
40685
  const rootDirectory = toCanonicalPath(options.rootDirectory);
@@ -40277,8 +40691,9 @@ const checkDeadCode = async (options) => {
40277
40691
  entryPatterns,
40278
40692
  tsConfigPath: resolveTsConfigPath(rootDirectory),
40279
40693
  ignorePatterns,
40280
- deslopJsModuleSpecifier: options.deslopJsModuleSpecifier ?? import.meta.resolve("deslop-js")
40281
- }), options.workerTimeoutMs ?? 12e4));
40694
+ deslopJsModuleSpecifier: options.deslopJsModuleSpecifier ?? import.meta.resolve("deslop-js"),
40695
+ parseConcurrency: options.parseConcurrency
40696
+ }), options.workerTimeoutMs ?? 12e4, options.abortSignal));
40282
40697
  const toRelative = (filePath) => toRelativeFilePath(rootDirectory, filePath);
40283
40698
  const diagnostics = [];
40284
40699
  for (const unusedFile of result.unusedFiles) diagnostics.push({
@@ -40376,7 +40791,37 @@ const isDiagnosticOnSurface = (diagnostic, surface, config) => {
40376
40791
  return true;
40377
40792
  };
40378
40793
  const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
40379
- const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(Path.resolve(rootDirectory, relativePath)));
40794
+ /**
40795
+ * Budget for the dead-code phase, scaled to the work. deslop's graph build is
40796
+ * CPU-bound and roughly linear in file count, so a fixed 120s cap is too tight
40797
+ * for a large repo (where the pass legitimately runs that long) and is then
40798
+ * tipped over by any concurrent load — silently dropping every dead-code
40799
+ * finding. Scaling the budget with file count (and inversely with the core
40800
+ * share when overlapped) lets the pass complete, while the ceiling still
40801
+ * reclaims a genuinely wedged worker. Returns the in-worker SIGKILL deadline
40802
+ * and the Effect-side phase backstop that sits a margin above it.
40803
+ */
40804
+ const resolveDeadCodeTimeout = (input) => {
40805
+ const coreShareFactor = Math.max(1, input.fullConcurrency / Math.max(1, input.deadCodeConcurrency));
40806
+ const workerTimeoutMs = Math.min(DEAD_CODE_TIMEOUT_CEILING_MS, Math.max(DEAD_CODE_WORKER_TIMEOUT_MS, Math.ceil(input.sourceFileCount * 30 * coreShareFactor)));
40807
+ return {
40808
+ workerTimeoutMs,
40809
+ phaseTimeoutMs: workerTimeoutMs + DEAD_CODE_PHASE_TIMEOUT_OVER_WORKER_MS
40810
+ };
40811
+ };
40812
+ const collectSizedSourceFiles = (rootDirectory, relativePaths) => {
40813
+ const entries = [];
40814
+ for (const relativePath of relativePaths) {
40815
+ const absolutePath = Path.resolve(rootDirectory, relativePath);
40816
+ const sizeBytes = statSourceFileSize(absolutePath);
40817
+ if (isLargeMinifiedFile(absolutePath, sizeBytes)) continue;
40818
+ entries.push({
40819
+ path: relativePath,
40820
+ sizeBytes: sizeBytes ?? 0
40821
+ });
40822
+ }
40823
+ return entries;
40824
+ };
40380
40825
  const listSourceFilesViaGit = (rootDirectory) => {
40381
40826
  const result = spawnSync("git", [
40382
40827
  "ls-files",
@@ -40409,7 +40854,8 @@ const listSourceFilesViaFilesystem = (rootDirectory) => {
40409
40854
  }
40410
40855
  return filePaths;
40411
40856
  };
40412
- const listSourceFiles = (rootDirectory) => excludeMinifiedFiles(rootDirectory, listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory));
40857
+ const listSourceFilesWithSize = (rootDirectory) => collectSizedSourceFiles(rootDirectory, listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory));
40858
+ const listSourceFiles = (rootDirectory) => listSourceFilesWithSize(rootDirectory).map((entry) => entry.path);
40413
40859
  const resolveLintIncludePaths = (rootDirectory, userConfig, project) => {
40414
40860
  if (!Array.isArray(userConfig?.ignore?.files) || userConfig.ignore.files.length === 0) return;
40415
40861
  const ignoredPatterns = compileIgnoredFilePatterns(userConfig);
@@ -40452,24 +40898,25 @@ var Config = class Config extends Service()("react-doctor/Config") {
40452
40898
  var DeadCode = class DeadCode extends Service()("react-doctor/DeadCode") {
40453
40899
  static layerNode = succeed$3(DeadCode, DeadCode.of({ run: (input) => unwrap(fn("DeadCode.run")(function* () {
40454
40900
  return yield* tryPromise({
40455
- try: () => checkDeadCode({
40901
+ try: (signal) => checkDeadCode({
40456
40902
  rootDirectory: input.rootDirectory,
40457
- userConfig: input.userConfig
40903
+ userConfig: input.userConfig,
40904
+ parseConcurrency: input.parseConcurrency,
40905
+ workerTimeoutMs: input.workerTimeoutMs,
40906
+ abortSignal: signal
40458
40907
  }),
40459
40908
  catch: (cause) => new ReactDoctorError({ reason: new DeadCodeAnalysisFailed({ cause }) })
40460
40909
  }).pipe(map$3((diagnostics) => fromIterable$1(diagnostics)));
40461
40910
  })()) }));
40462
40911
  static layerOf = (diagnostics) => succeed$3(DeadCode, DeadCode.of({ run: () => fromIterable$1(diagnostics) }));
40463
40912
  };
40464
- const createNodeReadFileLinesSync = (rootDirectory) => {
40465
- return (filePath) => {
40466
- const absolutePath = Path.isAbsolute(filePath) ? filePath : Path.join(rootDirectory, filePath);
40467
- try {
40468
- return NFS.readFileSync(absolutePath, "utf-8").split("\n");
40469
- } catch {
40470
- return null;
40471
- }
40472
- };
40913
+ const createNodeReadFileLinesSync = (rootDirectory) => (filePath) => {
40914
+ const absolutePath = Path.isAbsolute(filePath) ? filePath : Path.join(rootDirectory, filePath);
40915
+ try {
40916
+ return NFS.readFileSync(absolutePath, "utf-8").split("\n");
40917
+ } catch {
40918
+ return null;
40919
+ }
40473
40920
  };
40474
40921
  var Files = class Files extends Service()("react-doctor/Files") {
40475
40922
  static layerNode = succeed$3(Files, Files.of({
@@ -40680,7 +41127,10 @@ var Git = class Git extends Service()("react-doctor/Git") {
40680
41127
  directory: input.directory,
40681
41128
  cause
40682
41129
  }) });
40683
- }));
41130
+ }), withSpan("git.exec", { attributes: {
41131
+ "git.command": input.command,
41132
+ "git.subcommand": input.args[0] ?? ""
41133
+ } }));
40684
41134
  const runGit = (directory, args) => runCommand({
40685
41135
  command: "git",
40686
41136
  args,
@@ -40708,7 +41158,7 @@ var Git = class Git extends Service()("react-doctor/Git") {
40708
41158
  ]);
40709
41159
  if (candidates.status !== 0) return null;
40710
41160
  return trimOrNull(candidates.stdout.split("\n")[0] ?? "");
40711
- });
41161
+ }).pipe(withSpan("Git.defaultBranch"));
40712
41162
  const branchExists = (directory, branch) => runGit(directory, [
40713
41163
  "rev-parse",
40714
41164
  "--verify",
@@ -40755,7 +41205,7 @@ var Git = class Git extends Service()("react-doctor/Git") {
40755
41205
  const result = resultOption.value;
40756
41206
  if (result.status !== 0) return null;
40757
41207
  return parseGithubViewerPermission(result.stdout);
40758
- }).pipe(catch_$1(() => succeed$2(null)));
41208
+ }).pipe(catch_$1(() => succeed$2(null)), withSpan("Git.githubViewerPermission"));
40759
41209
  /**
40760
41210
  * Resolves a `--diff A..B` / `A...B` commit range into a changed-file
40761
41211
  * selection. Each endpoint is validated with `isSafeGitRevision`
@@ -40869,7 +41319,7 @@ var Git = class Git extends Service()("react-doctor/Git") {
40869
41319
  changedFiles: splitNullSeparated(diff.stdout),
40870
41320
  isCurrentChanges: false
40871
41321
  };
40872
- }),
41322
+ }).pipe(withSpan("Git.diffSelection")),
40873
41323
  stagedFilePaths: (directory) => runGit(directory, [
40874
41324
  "diff",
40875
41325
  "--cached",
@@ -40911,7 +41361,7 @@ var Git = class Git extends Service()("react-doctor/Git") {
40911
41361
  status: result.status,
40912
41362
  stdout: result.stdout
40913
41363
  };
40914
- }),
41364
+ }).pipe(withSpan("Git.grep")),
40915
41365
  changedLineRanges: ({ directory, baseRef, cached, files }) => gen(function* () {
40916
41366
  if (files.length === 0) return [];
40917
41367
  if (baseRef !== void 0 && !isSafeGitRevision(baseRef)) return null;
@@ -40927,7 +41377,7 @@ var Git = class Git extends Service()("react-doctor/Git") {
40927
41377
  ]);
40928
41378
  if (result.status !== 0) return null;
40929
41379
  return parseChangedLineRanges(result.stdout);
40930
- })
41380
+ }).pipe(withSpan("Git.changedLineRanges"))
40931
41381
  });
40932
41382
  })).pipe(provide$2(layer$3.pipe(provide$2(mergeAll$1(layer$2, layer$1)))));
40933
41383
  /**
@@ -41142,7 +41592,7 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
41142
41592
  for (const [absolutePath, originalContent] of originalContents) try {
41143
41593
  NFS.writeFileSync(absolutePath, originalContent);
41144
41594
  } catch (error) {
41145
- process.stderr.write(`[react-doctor] Failed to restore inline disable directives in ${absolutePath}: ${error instanceof Error ? error.message : String(error)}\n[react-doctor] Run: git checkout -- ${absolutePath}\n`);
41595
+ process.stderr.write(`[react-doctor] Failed to restore inline disable directives in ${absolutePath}: ${messageFromUnknown(error)}\n[react-doctor] Run: git checkout -- ${absolutePath}\n`);
41146
41596
  }
41147
41597
  };
41148
41598
  const onExit = () => restore();
@@ -41166,6 +41616,14 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
41166
41616
  process.removeListener("exit", onExit);
41167
41617
  };
41168
41618
  };
41619
+ const ROOT_DIRECTORY_PLACEHOLDER = "<root>";
41620
+ const normalizeConfigForHash = (config) => {
41621
+ const clone = JSON.parse(JSON.stringify(config));
41622
+ if (clone?.settings?.["react-doctor"]) clone.settings["react-doctor"].rootDirectory = ROOT_DIRECTORY_PLACEHOLDER;
41623
+ if (Array.isArray(clone?.jsPlugins)) clone.jsPlugins = clone.jsPlugins.map((_, index) => `<plugin:${index}>`);
41624
+ return clone;
41625
+ };
41626
+ const computeRulesetHash = (input) => crypto.createHash("sha1").update(JSON.stringify(normalizeConfigForHash(input.config))).update("\0").update([...input.toolchainVersions].join("\0")).update("\0").update([...input.ignorePatterns].join("\n")).update(" ").update(input.tsconfigContent ?? "").digest("hex");
41169
41627
  /**
41170
41628
  * Loads a plugin module via the local require resolver and extracts
41171
41629
  * `(name, ruleNames)` from either `module.exports.meta + rules` or
@@ -41248,7 +41706,7 @@ const resolveUserPlugin = (spec, configSourceDirectory) => {
41248
41706
  try {
41249
41707
  resolvedSpecifier = isRelative ? Path.resolve(configSourceDirectory, spec) : candidateRequire.resolve(spec);
41250
41708
  } catch (error) {
41251
- warnConfigIssue(`config.plugins entry "${spec}" could not be resolved from ${configSourceDirectory}: ${error instanceof Error ? error.message : String(error)}`);
41709
+ warnConfigIssue(`config.plugins entry "${spec}" could not be resolved from ${configSourceDirectory}: ${messageFromUnknown(error)}`);
41252
41710
  return null;
41253
41711
  }
41254
41712
  const { name, ruleNames } = readPluginShape(resolvedSpecifier, (target) => candidateRequire(target));
@@ -41320,8 +41778,8 @@ const buildUserPluginRules = (userPlugin, severityControls) => {
41320
41778
  }
41321
41779
  return enabled;
41322
41780
  };
41323
- const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames, severityControls, userPlugins = [] }) => {
41324
- const reactHooksJsPlugin = resolveReactHooksJsPlugin(project.hasReactCompiler, customRulesOnly);
41781
+ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), serverAuthFunctionNames, severityControls, userPlugins = [], disableReactHooksJsPlugin = false, ruleSelection }) => {
41782
+ const reactHooksJsPlugin = disableReactHooksJsPlugin || ruleSelection === "sidecar" ? null : resolveReactHooksJsPlugin(project.hasReactCompiler, customRulesOnly);
41325
41783
  const reactCompilerRules = reactHooksJsPlugin ? applyRuleSeverityControls(filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames), severityControls) : {};
41326
41784
  const jsPlugins = [];
41327
41785
  if (reactHooksJsPlugin) jsPlugins.push(reactHooksJsPlugin.entry);
@@ -41330,6 +41788,8 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
41330
41788
  for (const registryEntry of REACT_DOCTOR_RULES) {
41331
41789
  const rule = reactDoctorPlugin.rules[registryEntry.id];
41332
41790
  if (!rule) continue;
41791
+ if (ruleSelection === "cacheable" && CROSS_FILE_RULE_IDS.has(registryEntry.id)) continue;
41792
+ if (ruleSelection === "sidecar" && !CROSS_FILE_RULE_IDS.has(registryEntry.id)) continue;
41333
41793
  if (rule.scan !== void 0) continue;
41334
41794
  if (customRulesOnly && registryEntry.originallyExternal) continue;
41335
41795
  if (rule.framework !== "global" && !rule.requires) continue;
@@ -41344,7 +41804,7 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
41344
41804
  enabledReactDoctorRules[registryEntry.key] = severity;
41345
41805
  }
41346
41806
  const userPluginRules = {};
41347
- for (const userPlugin of userPlugins) {
41807
+ if (ruleSelection !== "sidecar") for (const userPlugin of userPlugins) {
41348
41808
  Object.assign(userPluginRules, buildUserPluginRules(userPlugin, severityControls));
41349
41809
  jsPlugins.push(userPlugin.entry);
41350
41810
  }
@@ -41374,6 +41834,100 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
41374
41834
  }
41375
41835
  };
41376
41836
  };
41837
+ const atomicWriteJson = (filePath, value) => {
41838
+ try {
41839
+ NFS.mkdirSync(Path.dirname(filePath), { recursive: true });
41840
+ const temporaryPath = `${filePath}.${process.pid}.tmp`;
41841
+ NFS.writeFileSync(temporaryPath, JSON.stringify(value));
41842
+ NFS.renameSync(temporaryPath, filePath);
41843
+ } catch {
41844
+ return;
41845
+ }
41846
+ };
41847
+ const failOpenReadJson = (filePath, fallback) => {
41848
+ try {
41849
+ return JSON.parse(NFS.readFileSync(filePath, "utf8"));
41850
+ } catch {
41851
+ return fallback;
41852
+ }
41853
+ };
41854
+ const validateDiagnostic = decodeUnknownSync(Diagnostic);
41855
+ const decodeFileDiagnostics = (raw) => {
41856
+ if (!Array.isArray(raw)) return null;
41857
+ try {
41858
+ for (const entry of raw) validateDiagnostic(entry);
41859
+ return raw;
41860
+ } catch {
41861
+ return null;
41862
+ }
41863
+ };
41864
+ const emptyCache = () => ({
41865
+ version: 1,
41866
+ rulesets: {}
41867
+ });
41868
+ const loadRulesetEntries = (cacheFilePath, rulesetHash) => {
41869
+ const entries = /* @__PURE__ */ new Map();
41870
+ const persisted = failOpenReadJson(cacheFilePath, emptyCache());
41871
+ if (persisted.version !== 1 || !isRecord$2(persisted.rulesets)) return entries;
41872
+ const bucket = persisted.rulesets[rulesetHash];
41873
+ if (!isRecord$2(bucket) || !isRecord$2(bucket.files)) return entries;
41874
+ for (const [fileKey, rawDiagnostics] of Object.entries(bucket.files)) {
41875
+ const decoded = decodeFileDiagnostics(rawDiagnostics);
41876
+ if (decoded !== null) entries.set(fileKey, decoded);
41877
+ }
41878
+ return entries;
41879
+ };
41880
+ const createFileLintCache = (cacheDirectory, rulesetHash) => {
41881
+ const cacheFilePath = Path.join(cacheDirectory, FILE_LINT_CACHE_FILENAME);
41882
+ const entries = loadRulesetEntries(cacheFilePath, rulesetHash);
41883
+ return {
41884
+ lookup: (fileKey) => entries.get(fileKey) ?? null,
41885
+ store: (fileKey, diagnostics) => {
41886
+ entries.delete(fileKey);
41887
+ entries.set(fileKey, diagnostics);
41888
+ },
41889
+ persist: () => {
41890
+ const onDisk = failOpenReadJson(cacheFilePath, emptyCache());
41891
+ const rulesets = onDisk.version === 1 && isRecord$2(onDisk.rulesets) ? { ...onDisk.rulesets } : {};
41892
+ const existingBucket = rulesets[rulesetHash];
41893
+ const existingFiles = isRecord$2(existingBucket) && isRecord$2(existingBucket.files) ? existingBucket.files : {};
41894
+ const ourFiles = {};
41895
+ for (const [fileKey, diagnostics] of entries) ourFiles[fileKey] = diagnostics;
41896
+ const cappedEntries = Object.entries({
41897
+ ...existingFiles,
41898
+ ...ourFiles
41899
+ }).slice(-FILE_LINT_CACHE_MAX_FILE_COUNT);
41900
+ rulesets[rulesetHash] = {
41901
+ updatedAtMs: Date.now(),
41902
+ files: Object.fromEntries(cappedEntries)
41903
+ };
41904
+ const keptHashes = Object.entries(rulesets).sort(([, first], [, second]) => second.updatedAtMs - first.updatedAtMs).slice(0, 8).map(([hash]) => hash);
41905
+ const prunedRulesets = {};
41906
+ for (const hash of keptHashes) prunedRulesets[hash] = rulesets[hash];
41907
+ atomicWriteJson(cacheFilePath, {
41908
+ version: 1,
41909
+ rulesets: prunedRulesets
41910
+ });
41911
+ }
41912
+ };
41913
+ };
41914
+ const bundledRequire$2 = createRequire(import.meta.url);
41915
+ const TOOLCHAIN_PACKAGE_SPECIFIERS$1 = [
41916
+ "oxlint/package.json",
41917
+ "oxlint-plugin-react-doctor/package.json",
41918
+ "eslint-plugin-react-hooks/package.json"
41919
+ ];
41920
+ const resolveOxlintToolchainVersions = () => {
41921
+ const versions = [`node=${process.version}`];
41922
+ for (const specifier of TOOLCHAIN_PACKAGE_SPECIFIERS$1) try {
41923
+ const packageJson = bundledRequire$2(specifier);
41924
+ const version = typeof packageJson.version === "string" ? packageJson.version : "unknown";
41925
+ versions.push(`${specifier}=${version}`);
41926
+ } catch {
41927
+ versions.push(`${specifier}=missing`);
41928
+ }
41929
+ return versions;
41930
+ };
41377
41931
  const esmRequire = createRequire(import.meta.url);
41378
41932
  const resolveOxlintBinary = () => {
41379
41933
  const oxlintMainPath = esmRequire.resolve("oxlint");
@@ -41381,7 +41935,6 @@ const resolveOxlintBinary = () => {
41381
41935
  return Path.join(oxlintPackageDirectory, "bin", "oxlint");
41382
41936
  };
41383
41937
  const resolvePluginPath = () => esmRequire.resolve("oxlint-plugin-react-doctor");
41384
- const TSCONFIG_FILENAMES = ["tsconfig.json", "tsconfig.base.json"];
41385
41938
  const resolveTsConfigRelativePath = (rootDirectory) => {
41386
41939
  for (const filename of TSCONFIG_FILENAMES) if (NFS.existsSync(Path.join(rootDirectory, filename))) return `./${filename}`;
41387
41940
  return null;
@@ -41753,7 +42306,7 @@ const scopeContainsNonImportBinding = (node, scopeNode, identifierName) => {
41753
42306
  const isIdentifierShadowedByLocalBinding = (identifier, sourceFile) => {
41754
42307
  let currentNode = identifier.parent;
41755
42308
  while (currentNode) {
41756
- if (isScopeNode(currentNode)) {
42309
+ if (isScopeBoundary(currentNode)) {
41757
42310
  if (scopeContainsNonImportBinding(currentNode, currentNode, identifier.text)) return true;
41758
42311
  }
41759
42312
  if (currentNode === sourceFile) return false;
@@ -41844,11 +42397,10 @@ const findResolutionInScope = (scopeNode, identifierName, reactImportBindings, s
41844
42397
  });
41845
42398
  return resolution;
41846
42399
  };
41847
- const isScopeNode = isScopeBoundary;
41848
42400
  const resolveIdentifierBinding = (identifier, reactImportBindings, sourceFile, visitedDeclarations = /* @__PURE__ */ new Set()) => {
41849
42401
  let currentNode = identifier.parent;
41850
42402
  while (currentNode) {
41851
- if (isScopeNode(currentNode)) {
42403
+ if (isScopeBoundary(currentNode)) {
41852
42404
  const resolution = findResolutionInScope(currentNode, identifier.text, reactImportBindings, sourceFile, visitedDeclarations);
41853
42405
  if (resolution) return resolution;
41854
42406
  }
@@ -42018,9 +42570,9 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
42018
42570
  try {
42019
42571
  parsed = JSON.parse(sanitizedStdout);
42020
42572
  } catch {
42021
- throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
42573
+ throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 600) }) });
42022
42574
  }
42023
- if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
42575
+ if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 600) }) });
42024
42576
  const minifiedFileCache = /* @__PURE__ */ new Map();
42025
42577
  const isMinifiedDiagnosticFile = (filename) => {
42026
42578
  const absolutePath = Path.isAbsolute(filename) ? filename : Path.resolve(rootDirectory || ".", filename);
@@ -42057,15 +42609,19 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
42057
42609
  };
42058
42610
  });
42059
42611
  };
42060
- const SANITIZED_ENV = (() => {
42061
- const sanitized = {};
42062
- for (const [name, value] of Object.entries(process.env)) {
42612
+ const buildOxlintChildEnv = (sourceEnv) => {
42613
+ const childEnv = {};
42614
+ for (const [name, value] of Object.entries(sourceEnv)) {
42063
42615
  if (name === "NODE_OPTIONS" || name === "NODE_DEBUG") continue;
42064
42616
  if (name.startsWith("npm_config_")) continue;
42065
- sanitized[name] = value;
42617
+ childEnv[name] = value;
42066
42618
  }
42067
- return sanitized;
42068
- })();
42619
+ const isCompileCacheDisabled = Boolean(sourceEnv.NODE_DISABLE_COMPILE_CACHE);
42620
+ const isCompileCacheAlreadySet = childEnv.NODE_COMPILE_CACHE !== void 0;
42621
+ if (!isCompileCacheDisabled && !isCompileCacheAlreadySet) childEnv.NODE_COMPILE_CACHE = Path.join(os.tmpdir(), NODE_COMPILE_CACHE_DIR_NAME);
42622
+ return childEnv;
42623
+ };
42624
+ const SANITIZED_ENV = buildOxlintChildEnv(process.env);
42069
42625
  /**
42070
42626
  * Spawn one oxlint subprocess with hard ceilings on wall time and
42071
42627
  * output size. Returns stdout on success; raises a tagged
@@ -42082,7 +42638,11 @@ const SANITIZED_ENV = (() => {
42082
42638
  * The first three are splittable (the caller's binary-split retry
42083
42639
  * shrinks the batch and re-spawns); the fourth isn't.
42084
42640
  */
42085
- const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLINT_SPAWN_TIMEOUT_MS, outputMaxBytes = OXLINT_OUTPUT_MAX_BYTES) => new Promise((resolve, reject) => {
42641
+ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLINT_SPAWN_TIMEOUT_MS, outputMaxBytes = OXLINT_OUTPUT_MAX_BYTES, abortSignal) => new Promise((resolve, reject) => {
42642
+ if (abortSignal?.aborted) {
42643
+ reject(new ReactDoctorError({ reason: new OxlintSpawnFailed({ cause: "lint phase aborted" }) }));
42644
+ return;
42645
+ }
42086
42646
  const child = spawn(nodeBinaryPath, args, {
42087
42647
  cwd: rootDirectory,
42088
42648
  env: SANITIZED_ENV,
@@ -42092,11 +42652,18 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
42092
42652
  "pipe"
42093
42653
  ]
42094
42654
  });
42655
+ const onAbort = () => {
42656
+ child.kill("SIGKILL");
42657
+ reject(new ReactDoctorError({ reason: new OxlintSpawnFailed({ cause: "lint phase aborted" }) }));
42658
+ };
42659
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
42660
+ const clearAbortListener = () => abortSignal?.removeEventListener("abort", onAbort);
42095
42661
  const timeoutHandle = setTimeout(() => {
42662
+ clearAbortListener();
42096
42663
  child.kill("SIGKILL");
42097
42664
  reject(new ReactDoctorError({ reason: new OxlintBatchExceeded({
42098
42665
  kind: "timeout",
42099
- detail: `${spawnTimeoutMs / 1e3}s budget exceeded`
42666
+ detail: `${spawnTimeoutMs / MILLISECONDS_PER_SECOND}s budget exceeded`
42100
42667
  }) }));
42101
42668
  }, spawnTimeoutMs);
42102
42669
  timeoutHandle.unref?.();
@@ -42127,10 +42694,12 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
42127
42694
  });
42128
42695
  child.on("error", (error) => {
42129
42696
  clearTimeout(timeoutHandle);
42697
+ clearAbortListener();
42130
42698
  reject(new ReactDoctorError({ reason: new OxlintSpawnFailed({ cause: error }) }));
42131
42699
  });
42132
42700
  child.on("close", (_code, signal) => {
42133
42701
  clearTimeout(timeoutHandle);
42702
+ clearAbortListener();
42134
42703
  if (didKillForSize) {
42135
42704
  reject(new ReactDoctorError({ reason: new OxlintBatchExceeded({
42136
42705
  kind: "output-too-large",
@@ -42197,26 +42766,28 @@ const isParallelismRelatedSpawnError = (error) => {
42197
42766
  * loop with a slimmer config in that case.
42198
42767
  */
42199
42768
  const spawnLintBatches = async (input) => {
42200
- const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes } = input;
42769
+ const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes, splitTotalBudgetMs = OXLINT_SPLIT_TOTAL_BUDGET_MS, splitMaxDepth = 8, signal } = input;
42201
42770
  const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
42202
42771
  const totalFileCount = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
42203
42772
  const runBatchPass = async (concurrency) => {
42204
42773
  const allDiagnostics = [];
42205
42774
  const droppedFiles = [];
42206
42775
  let firstDropReason = null;
42207
- const spawnLintBatch = async (batch) => {
42776
+ const splitDeadlineMs = Date.now() + splitTotalBudgetMs;
42777
+ const spawnLintBatch = async (batch, depth) => {
42208
42778
  const batchArgs = [...baseArgs, ...batch];
42209
42779
  try {
42210
- return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
42780
+ return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes, signal), project, rootDirectory);
42211
42781
  } catch (error) {
42212
42782
  if (!isSplittableReactDoctorError(error)) throw error;
42213
- if (batch.length <= 1) {
42783
+ const splitBudgetExhausted = Date.now() >= splitDeadlineMs || depth >= splitMaxDepth;
42784
+ if (batch.length <= 1 || splitBudgetExhausted) {
42214
42785
  droppedFiles.push(...batch);
42215
- if (firstDropReason === null) firstDropReason = error.message;
42786
+ if (firstDropReason === null) firstDropReason = splitBudgetExhausted && batch.length > 1 ? `${error.message} (split budget exhausted after ${splitMaxDepth} levels / ${splitTotalBudgetMs / MILLISECONDS_PER_SECOND}s)` : error.message;
42216
42787
  return [];
42217
42788
  }
42218
42789
  const splitIndex = Math.ceil(batch.length / 2);
42219
- return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
42790
+ return [...await spawnLintBatch(batch.slice(0, splitIndex), depth + 1), ...await spawnLintBatch(batch.slice(splitIndex), depth + 1)];
42220
42791
  }
42221
42792
  };
42222
42793
  let startedFileCount = 0;
@@ -42233,7 +42804,7 @@ const spawnLintBatches = async (input) => {
42233
42804
  try {
42234
42805
  const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
42235
42806
  startedFileCount += batch.length;
42236
- const batchDiagnostics = await spawnLintBatch(batch);
42807
+ const batchDiagnostics = await spawnLintBatch(batch, 0);
42237
42808
  scannedFileCount += batch.length;
42238
42809
  if (onFileProgress) {
42239
42810
  displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
@@ -42294,6 +42865,22 @@ const validateRuleRegistration = () => {
42294
42865
  ].filter((entry) => entry !== null).join("; ");
42295
42866
  console.warn(`[react-doctor] rule-registration drift: ${detail}`);
42296
42867
  };
42868
+ const hashFileContents = (filePath) => {
42869
+ try {
42870
+ return crypto.createHash("sha1").update(NFS.readFileSync(filePath)).digest("hex");
42871
+ } catch {
42872
+ return null;
42873
+ }
42874
+ };
42875
+ const projectCacheSubdir = (projectDirectory) => crypto.createHash("sha256").update(projectDirectory).digest("hex").slice(0, 16);
42876
+ const resolveReactDoctorCacheDir = (projectDirectory) => {
42877
+ const cacheDirOverride = process.env["REACT_DOCTOR_CACHE_DIR"]?.trim();
42878
+ if (cacheDirOverride) return Path.join(cacheDirOverride, projectCacheSubdir(projectDirectory));
42879
+ const nodeModulesDirectory = Path.join(projectDirectory, "node_modules");
42880
+ if (NFS.existsSync(nodeModulesDirectory)) return Path.join(nodeModulesDirectory, ".cache", "react-doctor");
42881
+ return Path.join(os.tmpdir(), "react-doctor-cache", projectCacheSubdir(projectDirectory));
42882
+ };
42883
+ const sortSourceFilesByCost = (entries) => [...entries].sort((left, right) => right.sizeBytes - left.sizeBytes).map((entry) => entry.path);
42297
42884
  /**
42298
42885
  * Atomically (re)writes the generated oxlintrc.json. Used twice in
42299
42886
  * the runner: once for the primary scan, once for the
@@ -42311,6 +42898,28 @@ const writeOxlintConfig = (configPath, configToWrite) => {
42311
42898
  NFS.closeSync(fileHandle);
42312
42899
  }
42313
42900
  };
42901
+ const REACT_HOOKS_JS_DROP_PREFIX = "React Compiler rules (react-hooks-js/*) skipped — eslint-plugin-react-hooks failed to load in this environment";
42902
+ /**
42903
+ * Detects an oxlint config-load crash caused by the optional
42904
+ * `react-hooks-js` (eslint-plugin-react-hooks) React Compiler plugin and
42905
+ * builds the partial-failure note for it; returns `null` when the failure
42906
+ * was anything else.
42907
+ *
42908
+ * oxlint prints a framed error to stdout (not stderr) and exits non-zero
42909
+ * when a `jsPlugins` entry can't be imported; that non-JSON stdout
42910
+ * surfaces as `OxlintOutputUnparseable`. Because oxlint fails the WHOLE
42911
+ * config load on it, leaving the plugin in would drop every curated
42912
+ * react-doctor diagnostic too — so the caller retries with the plugin
42913
+ * stripped (issue #833). Both markers sit at the start of oxlint's
42914
+ * message, so they survive the `preview` slice even for deep pnpm paths.
42915
+ */
42916
+ const reactHooksJsPluginDropNote = (error) => {
42917
+ if (!(error instanceof ReactDoctorError) || error.reason._tag !== "OxlintOutputUnparseable") return null;
42918
+ const { preview } = error.reason;
42919
+ if (!preview.includes("Failed to load JS plugin") || !preview.includes("eslint-plugin-react-hooks")) return null;
42920
+ const underlyingReason = preview.match(/Error:[^\n]*/)?.[0]?.trim();
42921
+ return `${REACT_HOOKS_JS_DROP_PREFIX}${underlyingReason ? `: ${underlyingReason}` : ""}. Other rules ran normally.`;
42922
+ };
42314
42923
  /**
42315
42924
  * The oxlint runner. Composed of three pieces in `runners/oxlint/`:
42316
42925
  *
@@ -42330,7 +42939,7 @@ const writeOxlintConfig = (configPath, configToWrite) => {
42330
42939
  * 6. always restore disable directives + clean up the temp dir
42331
42940
  */
42332
42941
  const runOxlint = async (options) => {
42333
- const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), userConfig, configSourceDirectory = rootDirectory, onPartialFailure, spawnTimeoutMs, outputMaxBytes } = options;
42942
+ const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), userConfig, configSourceDirectory = rootDirectory, onPartialFailure, perFileLintCacheEnabled = false, onCacheStats, spawnTimeoutMs, outputMaxBytes, lintBatchOrdering = "arrival" } = options;
42334
42943
  const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
42335
42944
  const severityControls = buildRuleSeverityControls(userConfig);
42336
42945
  validateRuleRegistration();
@@ -42338,38 +42947,165 @@ const runOxlint = async (options) => {
42338
42947
  const pluginPath = resolvePluginPath();
42339
42948
  const extendsPaths = (adoptExistingLintConfig && !customRulesOnly ? detectUserLintConfigPaths(rootDirectory) : []).filter(canOxlintExtendConfig);
42340
42949
  const userPlugins = resolveUserPlugins(userConfig?.plugins, configSourceDirectory);
42341
- const buildConfig = (extendsForThisAttempt) => createOxlintConfig({
42950
+ const buildConfig = (overrides) => createOxlintConfig({
42342
42951
  pluginPath,
42343
42952
  project,
42344
42953
  customRulesOnly,
42345
- extendsPaths: extendsForThisAttempt,
42954
+ extendsPaths: overrides.extendsPaths,
42346
42955
  ignoredTags,
42347
42956
  serverAuthFunctionNames,
42348
42957
  severityControls,
42349
- userPlugins
42958
+ userPlugins,
42959
+ disableReactHooksJsPlugin: overrides.disableReactHooksJsPlugin,
42960
+ ruleSelection: overrides.ruleSelection
42350
42961
  });
42351
42962
  const restoreDisableDirectives = respectInlineDisables ? () => {} : await neutralizeDisableDirectives(rootDirectory, includePaths);
42352
42963
  const configDirectory = NFS.mkdtempSync(Path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
42353
42964
  const configPath = Path.join(configDirectory, "oxlintrc.json");
42354
42965
  try {
42355
- const baseArgs = [
42356
- resolveOxlintBinary(),
42357
- "-c",
42358
- configPath,
42359
- "--format",
42360
- "json"
42361
- ];
42966
+ const oxlintBinary = resolveOxlintBinary();
42967
+ const sharedArgs = [];
42968
+ let tsconfigContent = null;
42362
42969
  if (project.hasTypeScript) {
42363
42970
  const tsconfigRelativePath = resolveTsConfigRelativePath(rootDirectory);
42364
- if (tsconfigRelativePath) baseArgs.push("--tsconfig", tsconfigRelativePath);
42971
+ if (tsconfigRelativePath) {
42972
+ sharedArgs.push("--tsconfig", tsconfigRelativePath);
42973
+ try {
42974
+ tsconfigContent = NFS.readFileSync(Path.resolve(rootDirectory, tsconfigRelativePath), "utf8");
42975
+ } catch {
42976
+ tsconfigContent = null;
42977
+ }
42978
+ }
42365
42979
  }
42366
42980
  const combinedPatterns = collectIgnorePatterns(rootDirectory);
42367
42981
  if (combinedPatterns.length > 0) {
42368
42982
  const combinedIgnorePath = Path.join(configDirectory, "combined.ignore");
42369
42983
  NFS.writeFileSync(combinedIgnorePath, `${combinedPatterns.join("\n")}\n`);
42370
- baseArgs.push("--ignore-path", combinedIgnorePath);
42984
+ sharedArgs.push("--ignore-path", combinedIgnorePath);
42371
42985
  }
42372
- const fileBatches = batchIncludePaths(baseArgs, includePaths !== void 0 ? includePaths : listSourceFiles(rootDirectory));
42986
+ const makeBaseArgs = (oxlintConfigPath) => [
42987
+ oxlintBinary,
42988
+ "-c",
42989
+ oxlintConfigPath,
42990
+ "--format",
42991
+ "json",
42992
+ ...sharedArgs
42993
+ ];
42994
+ const discoverScanFiles = () => lintBatchOrdering === "cost" ? sortSourceFilesByCost(listSourceFilesWithSize(rootDirectory)) : listSourceFiles(rootDirectory);
42995
+ const candidateFiles = includePaths !== void 0 ? includePaths : discoverScanFiles();
42996
+ const runConfigOverFiles = async (buildConfigForPass, configFileName, files, fileProgress) => {
42997
+ if (files.length === 0) return {
42998
+ diagnostics: [],
42999
+ didDropReactHooksJsPlugin: false,
43000
+ hadPartialFailure: false
43001
+ };
43002
+ let hadPartialFailure = false;
43003
+ const reportPartialFailure = (reason) => {
43004
+ hadPartialFailure = true;
43005
+ onPartialFailure?.(reason);
43006
+ };
43007
+ const passConfigPath = Path.join(configDirectory, configFileName);
43008
+ const passBaseArgs = makeBaseArgs(passConfigPath);
43009
+ const passFileBatches = batchIncludePaths(passBaseArgs, files);
43010
+ const spawnPass = () => spawnLintBatches({
43011
+ baseArgs: passBaseArgs,
43012
+ fileBatches: passFileBatches,
43013
+ rootDirectory,
43014
+ nodeBinaryPath,
43015
+ project,
43016
+ onPartialFailure: reportPartialFailure,
43017
+ onFileProgress: fileProgress,
43018
+ spawnTimeoutMs,
43019
+ outputMaxBytes,
43020
+ concurrency: options.concurrency,
43021
+ signal: options.signal
43022
+ });
43023
+ writeOxlintConfig(passConfigPath, buildConfigForPass({}));
43024
+ try {
43025
+ return {
43026
+ diagnostics: await spawnPass(),
43027
+ didDropReactHooksJsPlugin: false,
43028
+ hadPartialFailure
43029
+ };
43030
+ } catch (error) {
43031
+ const reactHooksJsDropNote = reactHooksJsPluginDropNote(error);
43032
+ if (reactHooksJsDropNote === null) throw error;
43033
+ writeOxlintConfig(passConfigPath, buildConfigForPass({ disableReactHooksJsPlugin: true }));
43034
+ const diagnostics = await spawnPass();
43035
+ reportPartialFailure(reactHooksJsDropNote);
43036
+ return {
43037
+ diagnostics,
43038
+ didDropReactHooksJsPlugin: true,
43039
+ hadPartialFailure
43040
+ };
43041
+ }
43042
+ };
43043
+ if (perFileLintCacheEnabled && respectInlineDisables && !project.hasReactCompiler && extendsPaths.length === 0 && userPlugins.length === 0) {
43044
+ const rulesetHash = computeRulesetHash({
43045
+ config: buildConfig({
43046
+ extendsPaths: [],
43047
+ ruleSelection: "cacheable"
43048
+ }),
43049
+ toolchainVersions: resolveOxlintToolchainVersions(),
43050
+ ignorePatterns: combinedPatterns,
43051
+ tsconfigContent
43052
+ });
43053
+ const cache = createFileLintCache(resolveReactDoctorCacheDir(rootDirectory), rulesetHash);
43054
+ const cacheKeyByFile = /* @__PURE__ */ new Map();
43055
+ const missFiles = [];
43056
+ const replayedDiagnostics = [];
43057
+ for (const candidateFile of candidateFiles) {
43058
+ const contentHash = hashFileContents(Path.resolve(rootDirectory, candidateFile));
43059
+ if (contentHash === null) {
43060
+ missFiles.push(candidateFile);
43061
+ continue;
43062
+ }
43063
+ const cacheKey = `${candidateFile.replaceAll("\\", "/")}${contentHash}`;
43064
+ cacheKeyByFile.set(candidateFile, cacheKey);
43065
+ const cachedDiagnostics = cache.lookup(cacheKey);
43066
+ if (cachedDiagnostics === null) missFiles.push(candidateFile);
43067
+ else replayedDiagnostics.push(...cachedDiagnostics);
43068
+ }
43069
+ const cacheHitFileCount = candidateFiles.length - missFiles.length;
43070
+ const cacheableResult = await runConfigOverFiles((overrides) => buildConfig({
43071
+ extendsPaths: [],
43072
+ ruleSelection: "cacheable",
43073
+ disableReactHooksJsPlugin: overrides.disableReactHooksJsPlugin
43074
+ }), "oxlintrc.cacheable.json", missFiles, void 0);
43075
+ const sidecarResult = await runConfigOverFiles(() => buildConfig({
43076
+ extendsPaths: [],
43077
+ ruleSelection: "sidecar"
43078
+ }), "oxlintrc.sidecar.json", candidateFiles, options.onFileProgress);
43079
+ onCacheStats?.(cacheHitFileCount, candidateFiles.length);
43080
+ const missFileByNormalizedPath = /* @__PURE__ */ new Map();
43081
+ for (const missFile of missFiles) missFileByNormalizedPath.set(missFile.replaceAll("\\", "/"), missFile);
43082
+ const freshDiagnosticsByFile = /* @__PURE__ */ new Map();
43083
+ let isAttributionSound = true;
43084
+ for (const diagnostic of cacheableResult.diagnostics) {
43085
+ const missFile = missFileByNormalizedPath.get(diagnostic.filePath);
43086
+ if (missFile === void 0) {
43087
+ isAttributionSound = false;
43088
+ break;
43089
+ }
43090
+ const fileDiagnostics = freshDiagnosticsByFile.get(missFile) ?? [];
43091
+ fileDiagnostics.push(diagnostic);
43092
+ freshDiagnosticsByFile.set(missFile, fileDiagnostics);
43093
+ }
43094
+ if (!cacheableResult.didDropReactHooksJsPlugin && !cacheableResult.hadPartialFailure && isAttributionSound) {
43095
+ for (const missFile of missFiles) {
43096
+ const cacheKey = cacheKeyByFile.get(missFile);
43097
+ if (cacheKey !== void 0) cache.store(cacheKey, freshDiagnosticsByFile.get(missFile) ?? []);
43098
+ }
43099
+ cache.persist();
43100
+ }
43101
+ return dedupeDiagnostics([
43102
+ ...replayedDiagnostics,
43103
+ ...cacheableResult.diagnostics,
43104
+ ...sidecarResult.diagnostics
43105
+ ]);
43106
+ }
43107
+ const baseArgs = makeBaseArgs(configPath);
43108
+ const fileBatches = batchIncludePaths(baseArgs, candidateFiles);
42373
43109
  const runBatches = () => spawnLintBatches({
42374
43110
  baseArgs,
42375
43111
  fileBatches,
@@ -42380,14 +43116,25 @@ const runOxlint = async (options) => {
42380
43116
  onFileProgress: options.onFileProgress,
42381
43117
  spawnTimeoutMs,
42382
43118
  outputMaxBytes,
42383
- concurrency: options.concurrency
43119
+ concurrency: options.concurrency,
43120
+ signal: options.signal
42384
43121
  });
42385
- writeOxlintConfig(configPath, buildConfig(extendsPaths));
43122
+ writeOxlintConfig(configPath, buildConfig({ extendsPaths }));
42386
43123
  try {
42387
43124
  return await runBatches();
42388
43125
  } catch (error) {
43126
+ const reactHooksJsDropNote = reactHooksJsPluginDropNote(error);
43127
+ if (reactHooksJsDropNote !== null) {
43128
+ writeOxlintConfig(configPath, buildConfig({
43129
+ extendsPaths,
43130
+ disableReactHooksJsPlugin: true
43131
+ }));
43132
+ const diagnostics = await runBatches();
43133
+ onPartialFailure?.(reactHooksJsDropNote);
43134
+ return diagnostics;
43135
+ }
42389
43136
  if (extendsPaths.length === 0) throw error;
42390
- writeOxlintConfig(configPath, buildConfig([]));
43137
+ writeOxlintConfig(configPath, buildConfig({ extendsPaths: [] }));
42391
43138
  return await runBatches();
42392
43139
  }
42393
43140
  } finally {
@@ -42449,9 +43196,11 @@ var Linter = class Linter extends Service()("react-doctor/Linter") {
42449
43196
  const spawnTimeoutMs = yield* OxlintSpawnTimeoutMs;
42450
43197
  const outputMaxBytes = yield* OxlintOutputMaxBytes;
42451
43198
  const concurrency = yield* OxlintConcurrency;
43199
+ const lintBatchOrdering = yield* LintBatchOrdering;
43200
+ const perFileLintCacheEnabled = yield* PerFileLintCacheEnabled;
42452
43201
  const collectedFailures = [];
42453
43202
  const diagnostics = yield* tryPromise({
42454
- try: () => runOxlint({
43203
+ try: (signal) => runOxlint({
42455
43204
  rootDirectory: input.rootDirectory,
42456
43205
  project: input.project,
42457
43206
  includePaths: input.includePaths ? [...input.includePaths] : void 0,
@@ -42466,9 +43215,13 @@ var Linter = class Linter extends Service()("react-doctor/Linter") {
42466
43215
  collectedFailures.push(reason);
42467
43216
  },
42468
43217
  onFileProgress: input.onFileProgress,
43218
+ perFileLintCacheEnabled,
43219
+ onCacheStats: input.onCacheStats,
42469
43220
  spawnTimeoutMs,
42470
43221
  outputMaxBytes,
42471
- concurrency
43222
+ concurrency,
43223
+ signal,
43224
+ lintBatchOrdering
42472
43225
  }),
42473
43226
  catch: ensureReactDoctorError
42474
43227
  });
@@ -42860,14 +43613,49 @@ const parseArtifactFromBody = (body) => {
42860
43613
  }
42861
43614
  return null;
42862
43615
  };
42863
- const fetchSocketArtifact = (dependency) => tryPromise(async (signal) => {
43616
+ const isSupplyChainCacheDisabled = () => {
43617
+ const noCache = process.env["REACT_DOCTOR_NO_CACHE"]?.toLowerCase() ?? "";
43618
+ return noCache === "1" || noCache === "true";
43619
+ };
43620
+ const supplyChainCacheFile = (cacheDirectory, dependency) => {
43621
+ const purlHash = crypto.createHash("sha256").update(toPurl(dependency)).digest("hex").slice(0, 16);
43622
+ return Path.join(cacheDirectory, SUPPLY_CHAIN_CACHE_SUBDIR, `${purlHash}.json`);
43623
+ };
43624
+ const readCachedSocketBody = (cacheFile) => {
43625
+ try {
43626
+ const entry = JSON.parse(NFS.readFileSync(cacheFile, "utf-8"));
43627
+ if (typeof entry === "object" && entry !== null && "fetchedAtMs" in entry && "body" in entry && typeof entry.fetchedAtMs === "number" && typeof entry.body === "string" && Date.now() - entry.fetchedAtMs <= 864e5) return entry.body;
43628
+ } catch {}
43629
+ return null;
43630
+ };
43631
+ const writeCachedSocketBody = (cacheFile, body) => {
43632
+ try {
43633
+ NFS.mkdirSync(Path.dirname(cacheFile), { recursive: true });
43634
+ NFS.writeFileSync(cacheFile, JSON.stringify({
43635
+ fetchedAtMs: Date.now(),
43636
+ body
43637
+ }));
43638
+ } catch {}
43639
+ };
43640
+ const fetchSocketArtifact = (dependency, cacheDirectory) => tryPromise(async (signal) => {
43641
+ const cacheFile = cacheDirectory === null ? null : supplyChainCacheFile(cacheDirectory, dependency);
43642
+ if (cacheFile !== null) {
43643
+ const cachedBody = readCachedSocketBody(cacheFile);
43644
+ if (cachedBody !== null) {
43645
+ const cachedArtifact = parseArtifactFromBody(cachedBody);
43646
+ if (cachedArtifact !== null) return cachedArtifact;
43647
+ }
43648
+ }
42864
43649
  const requestUrl = `${SOCKET_FREE_PURL_API_BASE}/${encodeURIComponent(toPurl(dependency))}`;
42865
43650
  const response = await fetch(requestUrl, {
42866
43651
  headers: { "User-Agent": SOCKET_FREE_USER_AGENT },
42867
43652
  signal
42868
43653
  });
42869
43654
  if (!response.ok) return null;
42870
- return parseArtifactFromBody(await response.text());
43655
+ const body = await response.text();
43656
+ const artifact = parseArtifactFromBody(body);
43657
+ if (artifact !== null && cacheFile !== null) writeCachedSocketBody(cacheFile, body);
43658
+ return artifact;
42871
43659
  }).pipe(timeout(FETCH_TIMEOUT_MS), orElseSucceed(() => null), tap$1((artifact) => {
42872
43660
  const scoreAttributes = {};
42873
43661
  if (artifact !== null) {
@@ -42972,7 +43760,8 @@ const checkSupplyChain = (input) => gen(function* () {
42972
43760
  const packageJsonPath = Path.join(input.rootDirectory, "package.json");
42973
43761
  const dependencies = collectDependenciesToScore(readPackageJson$1(packageJsonPath), readPackageJsonText(packageJsonPath), options.includeDevDependencies);
42974
43762
  if (dependencies.length === 0) return [];
42975
- const artifacts = yield* forEach$1(dependencies, fetchSocketArtifact, { concurrency: 8 });
43763
+ const cacheDirectory = isSupplyChainCacheDisabled() ? null : resolveReactDoctorCacheDir(input.rootDirectory);
43764
+ const artifacts = yield* forEach$1(dependencies, (dependency) => fetchSocketArtifact(dependency, cacheDirectory), { concurrency: 8 }).pipe(timeoutOption(input.totalTimeoutMs ?? 9e4), map$3((maybeArtifacts) => getOrElse$1(maybeArtifacts, () => [])));
42976
43765
  const diagnostics = [];
42977
43766
  for (let index = 0; index < dependencies.length; index += 1) {
42978
43767
  const artifact = artifacts[index];
@@ -42997,6 +43786,10 @@ const checkSupplyChain = (input) => gen(function* () {
42997
43786
  * The underlying `checkSupplyChain` Effect is total/fail-open — per-package
42998
43787
  * timeouts and network failures recover to "skip" — so the stream never
42999
43788
  * fails, mirroring `DeadCode`'s stream shape so the two compose the same way.
43789
+ * The orchestrator (`run-inspect.ts`) consumes this stream on a background
43790
+ * fiber whose network time overlaps the lint pass, joined under a generous
43791
+ * wall-clock budget; a budget expiry is the same fail-open outcome as a Socket
43792
+ * outage.
43000
43793
  */
43001
43794
  var SupplyChain = class SupplyChain extends Service()("react-doctor/SupplyChain") {
43002
43795
  static layerNode = succeed$3(SupplyChain, SupplyChain.of({ run: (input) => unwrap(checkSupplyChain(input).pipe(map$3((diagnostics) => fromIterable$1(diagnostics)), withSpan("SupplyChain.run"))) }));
@@ -43055,18 +43848,42 @@ const formatLintFailText = (reasonTag, nodeVersion) => {
43055
43848
  *
43056
43849
  * Phases:
43057
43850
  *
43058
- * 1. Config.resolve(directory) → Project.discover → Git metadata
43851
+ * 1. Config.resolve(directory) → Project.discover → Git metadata.
43852
+ * The GitHub viewer-permission lookup is forked onto a background
43853
+ * fiber here and joined late (it feeds score metadata, not
43854
+ * diagnostics).
43059
43855
  * 2. beforeLint hook (e.g. CLI renders the project-detection block)
43060
43856
  * 3. environment checks (reduced-motion + pnpm hardening +
43061
- * expo/react-native + security scan)
43062
- * 4. Linter.run + DeadCode.run forked as concurrent fibers so
43063
- * their wall-clock times overlap. Progress spinners stay
43064
- * sequential (lint first, then dead-code) for clean terminal
43065
- * output. GitHub viewer permission also runs as a background
43066
- * fiber during this phase.
43067
- * 5. afterLint hook
43068
- * 6. Reporter.finalize
43069
- * 7. Score.compute against the surface-filtered diagnostic set
43857
+ * expo/react-native + security scan), collected synchronously
43858
+ * 4. The supply-chain check (Socket.dev) is forked onto a background
43859
+ * fiber so its ~100% network-bound time overlaps the ~100%
43860
+ * CPU/subprocess-bound lint pass below, collapsing two serial
43861
+ * phases into roughly `max(supplyChain, lint)`. It is capped by
43862
+ * `SupplyChainOverlapTimeoutMs` (measured from fork) so a hung
43863
+ * socket can't drag out its join; on timeout it fails open to no
43864
+ * diagnostics — the same outcome class as a Socket outage.
43865
+ * 5. Linter.run runs; DeadCode.run runs concurrently (forked child
43866
+ * fiber) ONLY when the memory gate has headroom to run the 8 GB
43867
+ * dead-code child alongside the oxlint workers — or when overlap is
43868
+ * forced via REACT_DOCTOR_DEAD_CODE_OVERLAP. Otherwise dead-code
43869
+ * runs sequentially after lint, exactly as it did pre-overlap. The
43870
+ * fiber is joined (or interrupted, SIGKILLing its worker, on lint
43871
+ * failure) before diagnostics are concatenated. The afterLint hook
43872
+ * fires between lint and dead-code. Progress spinner labels AND the
43873
+ * final diagnostic / score order stay independent of execution
43874
+ * order, so terminal output is identical either way; supply-chain
43875
+ * rides alongside without a spinner.
43876
+ * 6. Join the supply-chain fiber, then assemble the diagnostics in a
43877
+ * FIXED order (env, supply-chain, lint, dead-code) so the output is
43878
+ * byte-identical regardless of which fiber settled first. The
43879
+ * viewer-permission fiber is joined later, during score-metadata
43880
+ * assembly (it feeds score metadata, not diagnostics). The per-element
43881
+ * `Reporter.emit` side-channel now interleaves supply-chain with lint
43882
+ * emits, so capture-order assertions must target the deterministic
43883
+ * concat below, not emit order (production `Reporter.layerNoop` makes
43884
+ * emit a no-op).
43885
+ * 7. Reporter.finalize
43886
+ * 8. Score.compute against the surface-filtered diagnostic set
43070
43887
  *
43071
43888
  * The orchestrator owns spinner lifecycle via `Progress`; callers
43072
43889
  * choose `Progress.layerOra(...)` for CLI feedback or
@@ -43124,10 +43941,21 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43124
43941
  ignoredTags: input.ignoredTags
43125
43942
  })
43126
43943
  ])));
43127
- const supplyChainCollected = !isDiffMode || (input.supplyChainManifestChanged ?? false) ? yield* runCollect(applyPerElementPipeline(supplyChainService.run({
43944
+ const shouldRunSupplyChain = !isDiffMode || (input.supplyChainManifestChanged ?? false);
43945
+ const supplyChainOverlapTimeout = yield* SupplyChainOverlapTimeoutMs;
43946
+ const supplyChainFiber = yield* forkChild(shouldRunSupplyChain ? runCollect(applyPerElementPipeline(supplyChainService.run({
43128
43947
  rootDirectory: scanDirectory,
43129
43948
  userConfig: resolvedConfig.config
43130
- }))) : [];
43949
+ }))).pipe(map$3((diagnostics) => ({
43950
+ diagnostics,
43951
+ timedOut: false
43952
+ })), timeout(supplyChainOverlapTimeout), orElseSucceed(() => ({
43953
+ diagnostics: [],
43954
+ timedOut: true
43955
+ }))) : succeed$2({
43956
+ diagnostics: [],
43957
+ timedOut: false
43958
+ }));
43131
43959
  const lintFailure = yield* make$13({
43132
43960
  didFail: false,
43133
43961
  reason: null,
@@ -43138,12 +43966,49 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43138
43966
  didFail: false,
43139
43967
  reason: null
43140
43968
  });
43141
- const scanConcurrency = yield* OxlintConcurrency;
43969
+ const scanConcurrency = resolveScanConcurrency(yield* OxlintConcurrency);
43970
+ const lintPhaseTimeoutMs = yield* LintPhaseTimeoutMs;
43971
+ const deadCodePhaseTimeoutMs = yield* DeadCodePhaseTimeoutMs;
43972
+ const resolveDeadCodePhaseTimeoutMs = (scaledPhaseTimeoutMs) => deadCodePhaseTimeoutMs === 15e4 ? scaledPhaseTimeoutMs : deadCodePhaseTimeoutMs;
43142
43973
  const workerCountSuffix = scanConcurrency > 1 ? ` ${highlighter.dim(`[~${scanConcurrency} workers]`)}` : "";
43974
+ const shouldRunDeadCode = input.runDeadCode && !isDiffMode && (showWarnings || deadCodeMaySurfaceWhenWarningsHidden(resolvedConfig.config));
43975
+ const deadCodeOverlapMode = yield* DeadCodeOverlap;
43976
+ const shouldOverlapDeadCode = shouldRunDeadCode && deadCodeOverlapMode === "on";
43977
+ const deadCodeParseConcurrency = shouldOverlapDeadCode ? Math.max(1, Math.floor(scanConcurrency * DEAD_CODE_OVERLAP_PARSE_SHARE)) : void 0;
43978
+ const lintConcurrency = deadCodeParseConcurrency === void 0 ? scanConcurrency : Math.max(1, scanConcurrency - deadCodeParseConcurrency);
43979
+ const buildCollectDeadCode = (deadCodeTimeout) => runCollect(applyPerElementPipeline(deadCodeService.run({
43980
+ rootDirectory: scanDirectory,
43981
+ userConfig: resolvedConfig.config,
43982
+ parseConcurrency: deadCodeParseConcurrency,
43983
+ workerTimeoutMs: deadCodeTimeout.workerTimeoutMs
43984
+ }).pipe(catchTag("ReactDoctorError", (error) => unwrap(gen(function* () {
43985
+ yield* set(deadCodeFailure, {
43986
+ didFail: true,
43987
+ reason: error.message
43988
+ });
43989
+ return empty$4;
43990
+ })))))).pipe(timeoutOption(deadCodeTimeout.phaseTimeoutMs), flatMap$2(match$3({
43991
+ onNone: () => set(deadCodeFailure, {
43992
+ didFail: true,
43993
+ reason: `Dead-code analysis exceeded ${Math.round(deadCodeTimeout.phaseTimeoutMs / MILLISECONDS_PER_SECOND)}s and was skipped.`
43994
+ }).pipe(as([])),
43995
+ onSome: succeed$2
43996
+ })));
43997
+ const overlapDeadCodeTimeout = resolveDeadCodeTimeout({
43998
+ sourceFileCount: project.sourceFileCount,
43999
+ deadCodeConcurrency: deadCodeParseConcurrency ?? scanConcurrency,
44000
+ fullConcurrency: scanConcurrency
44001
+ });
44002
+ const deadCodeFiber = shouldOverlapDeadCode ? yield* forkChild(buildCollectDeadCode({
44003
+ workerTimeoutMs: overlapDeadCodeTimeout.workerTimeoutMs,
44004
+ phaseTimeoutMs: resolveDeadCodePhaseTimeoutMs(overlapDeadCodeTimeout.phaseTimeoutMs)
44005
+ })) : null;
43143
44006
  const scanProgress = yield* progressService.start("Scanning...");
43144
44007
  const scanStartTime = Date.now();
43145
44008
  let lastReportedTotalFileCount = 0;
43146
- const lintCollected = yield* runCollect(applyPerElementPipeline(linterService.run({
44009
+ let lintCacheHitFileCount = null;
44010
+ let lintCacheTotalFileCount = null;
44011
+ const baseLintStream = linterService.run({
43147
44012
  rootDirectory: scanDirectory,
43148
44013
  project,
43149
44014
  includePaths: lintIncludePaths ?? void 0,
@@ -43157,6 +44022,10 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43157
44022
  onFileProgress: (scannedFileCount, totalFileCount) => {
43158
44023
  lastReportedTotalFileCount = totalFileCount;
43159
44024
  runSync(scanProgress.update(`Scanning files (${scannedFileCount}/${totalFileCount})${workerCountSuffix}...`));
44025
+ },
44026
+ onCacheStats: (cacheHitFileCount, totalConsideredFileCount) => {
44027
+ lintCacheHitFileCount = cacheHitFileCount;
44028
+ lintCacheTotalFileCount = totalConsideredFileCount;
43160
44029
  }
43161
44030
  }).pipe(catchTag("ReactDoctorError", (error) => unwrap(gen(function* () {
43162
44031
  yield* set(lintFailure, {
@@ -43166,36 +44035,54 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43166
44035
  reasonKind: error.reason._tag === "OxlintUnavailable" ? error.reason.kind : null
43167
44036
  });
43168
44037
  return empty$4;
43169
- }))))));
44038
+ }))));
44039
+ const lintCollected = yield* runCollect(applyPerElementPipeline(shouldOverlapDeadCode ? baseLintStream.pipe(provideService(OxlintConcurrency, lintConcurrency)) : baseLintStream)).pipe(timeoutOption(lintPhaseTimeoutMs), flatMap$2(match$3({
44040
+ onNone: () => set(lintFailure, {
44041
+ didFail: true,
44042
+ reason: `Lint analysis exceeded ${lintPhaseTimeoutMs / MILLISECONDS_PER_SECOND}s and was skipped.`,
44043
+ reasonTag: "OxlintBatchExceeded",
44044
+ reasonKind: null
44045
+ }).pipe(as([])),
44046
+ onSome: succeed$2
44047
+ })));
43170
44048
  const lintFailureState = yield* get$2(lintFailure);
43171
44049
  yield* afterLint(lintFailureState.didFail);
43172
44050
  if (lintFailureState.didFail) yield* scanProgress.fail(formatLintFailText(lintFailureState.reasonTag, process.version));
43173
44051
  const totalFileCount = lastReportedTotalFileCount || (lintIncludePaths?.length ?? project.sourceFileCount);
43174
44052
  const scannedFilesLabel = `${totalFileCount} ${totalFileCount === 1 ? "file" : "files"}`;
43175
- const shouldRunDeadCode = input.runDeadCode && !isDiffMode && (showWarnings || deadCodeMaySurfaceWhenWarningsHidden(resolvedConfig.config));
43176
- const deadCodeCollected = lintFailureState.didFail || !shouldRunDeadCode ? [] : yield* scanProgress.update(`Scanned ${scannedFilesLabel}, analyzing dead code...`).pipe(andThen(runCollect(applyPerElementPipeline(deadCodeService.run({
43177
- rootDirectory: scanDirectory,
43178
- userConfig: resolvedConfig.config
43179
- }).pipe(catchTag("ReactDoctorError", (error) => unwrap(gen(function* () {
43180
- yield* set(deadCodeFailure, {
43181
- didFail: true,
43182
- reason: error.message
44053
+ let deadCodeCollected = [];
44054
+ if (lintFailureState.didFail) {
44055
+ if (deadCodeFiber !== null) yield* interrupt(deadCodeFiber);
44056
+ } else if (shouldRunDeadCode) {
44057
+ yield* scanProgress.update(`Scanned ${scannedFilesLabel}, analyzing dead code...`);
44058
+ const sequentialDeadCodeTimeout = resolveDeadCodeTimeout({
44059
+ sourceFileCount: totalFileCount,
44060
+ deadCodeConcurrency: scanConcurrency,
44061
+ fullConcurrency: scanConcurrency
43183
44062
  });
43184
- return empty$4;
43185
- }))))))));
43186
- const deadCodeFailureState = yield* get$2(deadCodeFailure);
44063
+ deadCodeCollected = deadCodeFiber !== null ? yield* join(deadCodeFiber) : yield* buildCollectDeadCode({
44064
+ workerTimeoutMs: sequentialDeadCodeTimeout.workerTimeoutMs,
44065
+ phaseTimeoutMs: resolveDeadCodePhaseTimeoutMs(sequentialDeadCodeTimeout.phaseTimeoutMs)
44066
+ });
44067
+ }
44068
+ const deadCodeFailureState = lintFailureState.didFail ? {
44069
+ didFail: false,
44070
+ reason: null
44071
+ } : yield* get$2(deadCodeFailure);
43187
44072
  const scanElapsedMilliseconds = Date.now() - scanStartTime;
43188
- const scanElapsedSeconds = (scanElapsedMilliseconds / 1e3).toFixed(1);
44073
+ const scanElapsedSeconds = (scanElapsedMilliseconds / MILLISECONDS_PER_SECOND).toFixed(1);
43189
44074
  if (!lintFailureState.didFail) if (deadCodeFailureState.didFail) yield* scanProgress.fail(DEAD_CODE_FAIL_TEXT);
43190
44075
  else if (input.suppressScanSummary) yield* scanProgress.stop();
43191
44076
  else yield* scanProgress.succeed(`Scanned ${scannedFilesLabel} in ${scanElapsedSeconds}s${workerCountSuffix}`);
44077
+ const supplyChainResult = yield* join(supplyChainFiber);
44078
+ const supplyChainCollected = supplyChainResult.diagnostics;
43192
44079
  yield* reporterService.finalize;
43193
- const finalDiagnostics = [
44080
+ const finalDiagnostics = sortDiagnosticsStable(assignFixGroups([
43194
44081
  ...envCollected,
43195
44082
  ...supplyChainCollected,
43196
44083
  ...lintCollected,
43197
44084
  ...deadCodeCollected
43198
- ];
44085
+ ]));
43199
44086
  const githubViewerPermission = yield* join(githubViewerPermissionFiber);
43200
44087
  const scoreMetadata = {
43201
44088
  ...repo !== null ? { repo } : {},
@@ -43231,9 +44118,14 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43231
44118
  lintPartialFailures,
43232
44119
  didDeadCodeFail: deadCodeFailureState.didFail,
43233
44120
  deadCodeFailureReason: deadCodeFailureState.reason,
44121
+ deadCodeOverlapped: shouldOverlapDeadCode,
43234
44122
  scannedFileCount: totalFileCount,
43235
44123
  scannedFilePaths,
43236
- scanElapsedMilliseconds
44124
+ scanElapsedMilliseconds,
44125
+ scanConcurrency,
44126
+ supplyChainOverlapTimedOut: supplyChainResult.timedOut,
44127
+ lintCacheHitFileCount,
44128
+ lintCacheTotalFileCount
43237
44129
  };
43238
44130
  }).pipe(withSpan("runInspect", { attributes: {
43239
44131
  "inspect.directory": input.directory,
@@ -43241,7 +44133,7 @@ const runInspect = (input, hooks = {}) => gen(function* () {
43241
44133
  "inspect.runDeadCode": input.runDeadCode,
43242
44134
  "inspect.isCi": input.isCi,
43243
44135
  "inspect.scoreSurface": input.scoreSurface ?? "score"
43244
- } }));
44136
+ } }), (scanProgram) => flatMap$2(ScanDeadlineMs, (scanDeadlineMs) => scanProgram.pipe(timeout(scanDeadlineMs), catchTag$1("TimeoutError", () => new ReactDoctorError({ reason: new ScanDeadlineExceeded({ detail: `${scanDeadlineMs / MILLISECONDS_PER_SECOND}s elapsed` }) })))));
43245
44137
  const parseNodeVersion = (versionString) => {
43246
44138
  const [major = 0, minor = 0, patch = 0] = versionString.replace(/^v/, "").trim().split(".").map(Number);
43247
44139
  return {
@@ -43422,7 +44314,7 @@ var StagedFiles = class StagedFiles extends Service()("react-doctor/StagedFiles"
43422
44314
  static layerNode = effect(StagedFiles, gen(function* () {
43423
44315
  const git = yield* Git;
43424
44316
  return StagedFiles.of({
43425
- discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(map$3((entries) => entries.filter(isLintableSourceFile))),
44317
+ discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(map$3((entries) => entries.filter(isLintableSourceFile)), withSpan("StagedFiles.discoverSourceFiles")),
43426
44318
  materialize: ({ directory, stagedFiles, tempDirectory }) => materializeSourceTree({
43427
44319
  directory,
43428
44320
  files: stagedFiles,
@@ -43432,7 +44324,7 @@ var StagedFiles = class StagedFiles extends Service()("react-doctor/StagedFiles"
43432
44324
  tempDirectory: tree.tempDirectory,
43433
44325
  stagedFiles: tree.materializedFiles,
43434
44326
  cleanup: tree.cleanup
43435
- })))
44327
+ })), withSpan("StagedFiles.materialize"))
43436
44328
  });
43437
44329
  }));
43438
44330
  /**
@@ -43565,6 +44457,7 @@ const buildJsonReport = (input) => {
43565
44457
  score: result.score,
43566
44458
  skippedChecks: result.skippedChecks,
43567
44459
  ...result.skippedCheckReasons ? { skippedCheckReasons: result.skippedCheckReasons } : {},
44460
+ ...typeof result.scannedFileCount === "number" ? { scannedFileCount: result.scannedFileCount } : {},
43568
44461
  elapsedMilliseconds: result.elapsedMilliseconds
43569
44462
  }));
43570
44463
  const flattenedDiagnostics = projects.flatMap((entry) => entry.diagnostics);
@@ -43839,7 +44732,7 @@ const FALSY_CI_FLAG_VALUES = new Set([
43839
44732
  "false"
43840
44733
  ]);
43841
44734
  const isCiFlagSet = (value) => value !== void 0 && !FALSY_CI_FLAG_VALUES.has(value.toLowerCase());
43842
- const isCiEnvironment = () => CI_ENVIRONMENT_VARIABLES.some((environmentVariable) => Boolean(process.env[environmentVariable])) || isCiFlagSet(process.env.CI);
44735
+ const isCiEnvironment = (env = process.env) => CI_ENVIRONMENT_VARIABLES.some((environmentVariable) => Boolean(env[environmentVariable])) || isCiFlagSet(env.CI);
43843
44736
  const detectCiProvider = () => {
43844
44737
  for (const [environmentVariable, provider] of CI_PROVIDER_BY_ENVIRONMENT_VARIABLE) if (process.env[environmentVariable]) return provider;
43845
44738
  return isCiFlagSet(process.env.CI) ? "unknown" : null;
@@ -43864,6 +44757,53 @@ const detectCodingAgent = () => {
43864
44757
  const isCodingAgentEnvironment = () => detectCodingAgent() !== null;
43865
44758
  const isCiOrCodingAgentEnvironment = () => isCiEnvironment() || isCodingAgentEnvironment();
43866
44759
  //#endregion
44760
+ //#region src/cli/utils/detect-terminal-kind.ts
44761
+ const TERMINAL_BY_TERM_PROGRAM = [
44762
+ ["vscode", "vscode"],
44763
+ ["iTerm.app", "iterm"],
44764
+ ["Apple_Terminal", "apple-terminal"],
44765
+ ["WezTerm", "wezterm"],
44766
+ ["ghostty", "ghostty"],
44767
+ ["Hyper", "hyper"],
44768
+ ["Tabby", "tabby"],
44769
+ ["rio", "rio"]
44770
+ ];
44771
+ /**
44772
+ * Best-effort label for the terminal emulator / editor hosting the CLI,
44773
+ * derived from terminal-identity env vars. Recorded as the `terminalKind` run
44774
+ * tag so we can see where React Doctor is actually run (nvim, VS Code, iTerm,
44775
+ * …) — the split Sentry can't otherwise see. Low-cardinality and free of any
44776
+ * username/path/secret, so it's safe as a tag. Editor terminals (nvim/vim)
44777
+ * win over the outer emulator because that's the surface a user is reading in;
44778
+ * "ci" marks a run with no interactive terminal; "unknown" when nothing matches.
44779
+ */
44780
+ const detectTerminalKind = (env = process.env) => {
44781
+ if (env.NVIM) return "neovim";
44782
+ if (env.VIM_TERMINAL) return "vim";
44783
+ const termProgram = env.TERM_PROGRAM;
44784
+ if (termProgram) {
44785
+ for (const [marker, label] of TERMINAL_BY_TERM_PROGRAM) if (termProgram === marker) return label;
44786
+ }
44787
+ if (env.KITTY_WINDOW_ID || env.TERM === "xterm-kitty") return "kitty";
44788
+ if (env.WT_SESSION) return "windows-terminal";
44789
+ if (env.ALACRITTY_WINDOW_ID || env.TERM === "alacritty") return "alacritty";
44790
+ if (env.VTE_VERSION) return "vte";
44791
+ if (env.TMUX) return "tmux";
44792
+ if (isCiEnvironment(env)) return "ci";
44793
+ return "unknown";
44794
+ };
44795
+ //#endregion
44796
+ //#region src/cli/utils/is-debug-flag.ts
44797
+ /**
44798
+ * Whether the user passed `--debug` (surface the run's Sentry trace id, and
44799
+ * force performance tracing on so there's a trace to surface). Read straight
44800
+ * from argv rather than Commander's parsed flags because `initializeSentry()`
44801
+ * runs before Commander parses — the same reason `shouldEnableSentry()` reads
44802
+ * `--no-score` from argv. Sharing this one reader keeps the init-time sampling
44803
+ * override and the end-of-run print in agreement.
44804
+ */
44805
+ const isDebugFlagEnabled = (argv = process.argv) => argv.includes("--debug");
44806
+ //#endregion
43867
44807
  //#region src/cli/utils/is-git-hook-environment.ts
43868
44808
  const isGitHookEnvironment = () => Boolean(process.env.GIT_DIR);
43869
44809
  //#endregion
@@ -43886,6 +44826,7 @@ const NON_INTERACTIVE_ENVIRONMENT_VARIABLES = [
43886
44826
  const isNonInteractiveEnvironment = () => NON_INTERACTIVE_ENVIRONMENT_VARIABLES.some((envVariable) => Boolean(process.env[envVariable])) || isCodingAgentEnvironment();
43887
44827
  //#endregion
43888
44828
  //#region src/cli/utils/constants.ts
44829
+ const REACT_DOCTOR_CONFIG_PROJECT_NAME = "react-doctor";
43889
44830
  const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
43890
44831
  const BASELINE_FILES_TEMP_DIR_PREFIX = "react-doctor-baseline-";
43891
44832
  const GH_DEFAULT_BRANCH_PROBE_TIMEOUT_MS = 5e3;
@@ -43970,7 +44911,7 @@ const makeNoopConsole = () => ({
43970
44911
  });
43971
44912
  //#endregion
43972
44913
  //#region src/cli/utils/version.ts
43973
- const VERSION = "0.5.6-dev.f45cb29";
44914
+ const VERSION = "0.5.7-dev.0b4f4f4";
43974
44915
  //#endregion
43975
44916
  //#region src/cli/utils/json-mode.ts
43976
44917
  let context = null;
@@ -44120,8 +45061,11 @@ const buildRunContext = () => {
44120
45061
  viaAction: isOfficialGithubAction(),
44121
45062
  codingAgent: detectCodingAgent(),
44122
45063
  interactive: !isNonInteractiveEnvironment(),
45064
+ terminalKind: detectTerminalKind(),
44123
45065
  jsonMode: isJsonModeActive(),
44124
- invokedVia: detectInvokedVia()
45066
+ debug: isDebugFlagEnabled(),
45067
+ invokedVia: detectInvokedVia(),
45068
+ lintBatchOrdering: resolveLintBatchOrdering()
44125
45069
  };
44126
45070
  };
44127
45071
  //#endregion
@@ -44190,9 +45134,12 @@ const buildSentryScope = (runContext = buildRunContext()) => {
44190
45134
  viaAction: runContext.viaAction,
44191
45135
  codingAgent: runContext.codingAgent,
44192
45136
  interactive: runContext.interactive,
45137
+ terminalKind: runContext.terminalKind,
44193
45138
  jsonMode: runContext.jsonMode,
45139
+ debug: runContext.debug,
44194
45140
  invokedVia: runContext.invokedVia,
44195
- nodeMajor: runContext.nodeMajor
45141
+ nodeMajor: runContext.nodeMajor,
45142
+ lintBatchOrdering: runContext.lintBatchOrdering
44196
45143
  };
44197
45144
  const contexts = { run: { ...runContext } };
44198
45145
  const projectInfo = getSentryProjectInfo();
@@ -44328,13 +45275,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
44328
45275
  * uploads source-map artifacts under, so stack frames symbolicate. Honors the
44329
45276
  * standard `SENTRY_RELEASE` override.
44330
45277
  */
44331
- const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.5.6-dev.f45cb29`;
45278
+ const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.5.7-dev.0b4f4f4`;
44332
45279
  /**
44333
45280
  * Deployment environment shown in Sentry's environment filter. Defaults to
44334
45281
  * `production` for tagged releases and `development` for dev/unbuilt versions,
44335
45282
  * overridable via the standard `SENTRY_ENVIRONMENT` env var.
44336
45283
  */
44337
- const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.5.6-dev.f45cb29") ? "development" : "production");
45284
+ const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.5.7-dev.0b4f4f4") ? "development" : "production");
44338
45285
  /**
44339
45286
  * Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
44340
45287
  * (set to `0` to disable tracing) and falls back to
@@ -44398,7 +45345,7 @@ const flushSentry = async () => {
44398
45345
  const initializeSentry = () => {
44399
45346
  if (isInitialized || !shouldEnableSentry()) return;
44400
45347
  isInitialized = true;
44401
- resolvedTracesSampleRate = resolveTracesSampleRate();
45348
+ resolvedTracesSampleRate = isDebugFlagEnabled() ? 1 : resolveTracesSampleRate();
44402
45349
  const { tags, contexts } = buildSentryScope();
44403
45350
  Sentry.init({
44404
45351
  dsn: process.env.SENTRY_DSN || "https://f253d570240a59b8dbd77b7a548ef133@o4510226365743104.ingest.us.sentry.io/4511487817809920",
@@ -44537,7 +45484,7 @@ const externalSpanFrom = (sentrySpan) => {
44537
45484
  * in-memory tracer — identical to the prior default behavior.
44538
45485
  */
44539
45486
  const applyObservability = (program, rootSentrySpan) => {
44540
- if (isOtlpExportConfigured()) return (rootSentrySpan ? program.pipe(provideService(ParentSpan, externalSpanFrom(rootSentrySpan))) : program).pipe(provide(layerOtlp));
45487
+ if (isOtlpExportConfigured()) return (rootSentrySpan ? program.pipe(provideService$2(ParentSpan, externalSpanFrom(rootSentrySpan))) : program).pipe(provide(layerOtlp));
44541
45488
  if (rootSentrySpan) return program.pipe(withTracer(makeSentryTracer(rootSentrySpan)));
44542
45489
  return program.pipe(provide(layerOtlp));
44543
45490
  };
@@ -47614,6 +48561,11 @@ const setActiveRunTrace = (trace) => {
47614
48561
  activeRunTrace = trace;
47615
48562
  };
47616
48563
  const getActiveRunTrace = () => activeRunTrace;
48564
+ let lastRunTraceId = null;
48565
+ const recordRunTraceId = (traceId) => {
48566
+ lastRunTraceId = traceId;
48567
+ };
48568
+ const getLastRunTraceId = () => lastRunTraceId;
47617
48569
  //#endregion
47618
48570
  //#region src/cli/utils/to-span-attributes.ts
47619
48571
  /**
@@ -47676,14 +48628,13 @@ const withSentryRunSpan = (run, options = {}) => {
47676
48628
  op: "cli.inspect",
47677
48629
  attributes: toSpanAttributes(tags)
47678
48630
  }, (rootSpan) => {
47679
- if (options.concurrentScan !== true) {
47680
- const spanContext = rootSpan.spanContext();
47681
- setActiveRunTrace({
47682
- traceId: spanContext.traceId,
47683
- spanId: spanContext.spanId,
47684
- sampled: (spanContext.traceFlags & 1) === 1
47685
- });
47686
- }
48631
+ const spanContext = rootSpan.spanContext();
48632
+ recordRunTraceId(spanContext.traceId);
48633
+ if (options.concurrentScan !== true) setActiveRunTrace({
48634
+ traceId: spanContext.traceId,
48635
+ spanId: spanContext.spanId,
48636
+ sampled: (spanContext.traceFlags & 1) === 1
48637
+ });
47687
48638
  return run(rootSpan);
47688
48639
  });
47689
48640
  };
@@ -47823,6 +48774,42 @@ const recordScanMetrics = (input) => {
47823
48774
  });
47824
48775
  };
47825
48776
  //#endregion
48777
+ //#region src/cli/utils/diagnostic-grouping.ts
48778
+ const buildRulePriorityMap = (scores) => {
48779
+ const rulePriority = /* @__PURE__ */ new Map();
48780
+ for (const score of scores) {
48781
+ if (!score?.rules) continue;
48782
+ for (const [ruleKey, info] of Object.entries(score.rules)) if (typeof info.priority === "number") rulePriority.set(ruleKey, info.priority);
48783
+ }
48784
+ return rulePriority;
48785
+ };
48786
+ const compareByRulePriority = (ruleKeyA, ruleKeyB, rulePriority) => {
48787
+ const priorityA = rulePriority?.get(ruleKeyA);
48788
+ const priorityB = rulePriority?.get(ruleKeyB);
48789
+ if (priorityA === void 0 && priorityB === void 0) return 0;
48790
+ if (priorityA === void 0) return 1;
48791
+ if (priorityB === void 0) return -1;
48792
+ return priorityB - priorityA;
48793
+ };
48794
+ const sortRuleGroupsByImportance = (diagnosticGroups, rulePriority) => diagnosticGroups.toSorted(([ruleKeyA], [ruleKeyB]) => compareByRulePriority(ruleKeyA, ruleKeyB, rulePriority));
48795
+ const buildSortedRuleGroups = (diagnostics, rulePriority) => sortRuleGroupsByImportance([...groupBy([...diagnostics], (diagnostic) => `${diagnostic.plugin}/${diagnostic.rule}`)], rulePriority);
48796
+ const getSharedFixSiteCount = (diagnostics) => {
48797
+ if (diagnostics.length < 2) return 0;
48798
+ const firstFixGroupId = diagnostics[0]?.fixGroupId;
48799
+ if (!firstFixGroupId) return 0;
48800
+ return diagnostics.every((diagnostic) => diagnostic.fixGroupId === firstFixGroupId) ? diagnostics.length : 0;
48801
+ };
48802
+ const FIX_RECIPE_DIRECTIVE_LABEL = "Curl with no cache & follow the canonical fix and false positive check recipe before fixing";
48803
+ const formatFixRecipeLine = (diagnostic) => hasPublishedFixRecipe(diagnostic) ? `${FIX_RECIPE_DIRECTIVE_LABEL}: ${buildRuleDocsUrl(diagnostic.plugin, diagnostic.rule)}` : null;
48804
+ const formatLearnMoreLine = (diagnostic) => hasPublishedFixRecipe(diagnostic) ? `Learn more: ${buildRuleDocsUrl(diagnostic.plugin, diagnostic.rule)}` : null;
48805
+ const buildRuleBlastRadii = (diagnostics) => buildSortedRuleGroups(diagnostics).map(([ruleKey, ruleDiagnostics]) => ({
48806
+ ruleKey,
48807
+ title: ruleDiagnostics[0].title ?? ruleKey,
48808
+ siteCount: ruleDiagnostics.length,
48809
+ fileCount: new Set(ruleDiagnostics.map((diagnostic) => diagnostic.filePath)).size
48810
+ })).toSorted((left, right) => right.fileCount - left.fileCount);
48811
+ const findMigrationScaleBuckets = (diagnostics) => buildRuleBlastRadii(diagnostics).filter((bucket) => bucket.fileCount >= 40);
48812
+ //#endregion
47826
48813
  //#region src/cli/utils/cli-logger.ts
47827
48814
  /**
47828
48815
  * Thin synchronous façade over Effect's `Console` module. Used by
@@ -47939,12 +48926,17 @@ const buildOutcomeAttributes = (input) => {
47939
48926
  topRule = rule;
47940
48927
  topRuleCount = count;
47941
48928
  }
48929
+ const largestRuleBucket = buildRuleBlastRadii(result.diagnostics)[0] ?? null;
47942
48930
  let diagnosticsInTestFiles = 0;
47943
48931
  let diagnosticsInStoryFiles = 0;
48932
+ const findingsPerFixGroup = /* @__PURE__ */ new Map();
47944
48933
  for (const diagnostic of result.diagnostics) {
47945
48934
  if (diagnostic.fileContext === "test") diagnosticsInTestFiles += 1;
47946
48935
  if (diagnostic.fileContext === "story") diagnosticsInStoryFiles += 1;
48936
+ if (diagnostic.fixGroupId) findingsPerFixGroup.set(diagnostic.fixGroupId, (findingsPerFixGroup.get(diagnostic.fixGroupId) ?? 0) + 1);
47947
48937
  }
48938
+ let fixGroupedFindings = 0;
48939
+ for (const count of findingsPerFixGroup.values()) fixGroupedFindings += count;
47948
48940
  const attributes = {
47949
48941
  outcome,
47950
48942
  exitCode: wouldBlock ? 1 : 0,
@@ -47958,8 +48950,16 @@ const buildOutcomeAttributes = (input) => {
47958
48950
  diagnosticsInTestFiles,
47959
48951
  diagnosticsInStoryFiles,
47960
48952
  distinctRulesFired: countByRule.size,
48953
+ "diag.fixGroups": findingsPerFixGroup.size,
48954
+ "diag.fixGroupedFindings": fixGroupedFindings,
47961
48955
  topRule,
48956
+ "migration.largestRuleBucketFiles": largestRuleBucket ? largestRuleBucket.fileCount : null,
48957
+ "migration.largestRuleBucketSites": largestRuleBucket ? largestRuleBucket.siteCount : null,
48958
+ "migration.largestRuleBucketRule": largestRuleBucket ? largestRuleBucket.ruleKey : null,
47962
48959
  scannedFileCount: result.scannedFileCount ?? null,
48960
+ lintCacheHitFiles: result.lintCacheHitFileCount ?? null,
48961
+ lintCacheTotalFiles: result.lintCacheTotalFileCount ?? null,
48962
+ lintCacheHitRatio: result.lintCacheTotalFileCount != null && result.lintCacheTotalFileCount > 0 ? (result.lintCacheHitFileCount ?? 0) / result.lintCacheTotalFileCount : null,
47963
48963
  elapsedMs: result.elapsedMilliseconds,
47964
48964
  scanPhaseMs: result.scanElapsedMilliseconds ?? null,
47965
48965
  score: result.score ? result.score.score : null,
@@ -47969,7 +48969,10 @@ const buildOutcomeAttributes = (input) => {
47969
48969
  didLintFail: input.didLintFail ?? null,
47970
48970
  lintFailureReasonKind: input.lintFailureReasonKind ?? null,
47971
48971
  lintPartialFailureCount: input.lintPartialFailureCount ?? null,
47972
- didDeadCodeFail: input.didDeadCodeFail ?? null
48972
+ lintDroppedFileCount: input.lintDroppedFileCount ?? null,
48973
+ didDeadCodeFail: input.didDeadCodeFail ?? null,
48974
+ supplyChainOverlapTimedOut: input.supplyChainOverlapTimedOut ?? null,
48975
+ deadCodeOverlapped: input.deadCodeOverlapped ?? null
47973
48976
  };
47974
48977
  for (const [category, count] of countByCategory) attributes[`diag.category.${toCategoryKey(category)}`] = count;
47975
48978
  if (result.baselineDelta) {
@@ -48038,6 +49041,32 @@ const recordRunEvent = (rootSpan, input) => {
48038
49041
  } catch {}
48039
49042
  };
48040
49043
  //#endregion
49044
+ //#region src/cli/utils/resolve-worker-telemetry.ts
49045
+ /**
49046
+ * Projects the resolved lint worker count into the `(workerCount, parallel)`
49047
+ * telemetry pair. `resolvedWorkerCount` is the count the scan actually fanned
49048
+ * out to (`InspectOutput.scanConcurrency`); `pinnedConcurrency` is the caller's
49049
+ * `inspect({ concurrency })` pin, used as the fallback when no scan resolved a
49050
+ * count (the pre-scan failure path, or a cache entry persisted before the
49051
+ * resolved count was tracked). `parallel` is derived from the count — NOT from
49052
+ * whether a count was pinned — so the common auto path (no pin) still reports
49053
+ * parallelism correctly instead of always reading `false`.
49054
+ */
49055
+ const resolveWorkerTelemetry = (resolvedWorkerCount, pinnedConcurrency) => {
49056
+ const workerCount = resolvedWorkerCount ?? pinnedConcurrency;
49057
+ return {
49058
+ workerCount,
49059
+ parallel: workerCount !== void 0 && workerCount > 1
49060
+ };
49061
+ };
49062
+ //#endregion
49063
+ //#region src/cli/utils/count-dropped-lint-files.ts
49064
+ const DROPPED_FILES_MESSAGE_PATTERN = /^(\d+) file\(s\) failed to lint and were skipped/;
49065
+ const countDroppedLintFiles = (lintPartialFailures) => lintPartialFailures.reduce((total, message) => {
49066
+ const match = DROPPED_FILES_MESSAGE_PATTERN.exec(message);
49067
+ return match ? total + Number(match[1]) : total;
49068
+ }, 0);
49069
+ //#endregion
48041
49070
  //#region src/cli/utils/path-format.ts
48042
49071
  const toForwardSlashes = (filePath) => filePath.replaceAll("\\", "/");
48043
49072
  //#endregion
@@ -48116,9 +49145,10 @@ const AGENT_GUIDANCE_LINES = [
48116
49145
  "Investigate deeply where relevant: race conditions, security-sensitive flows, state propagation, multi-file refactors, and downstream dependency chains.",
48117
49146
  "Ignore pure style preferences, theoretical issues without real impact, missing features, and unrelated pre-existing code.",
48118
49147
  "Start with high-confidence fixes that preserve behavior. Leave low-confidence or product-dependent changes as notes.",
48119
- "Run `npx react-doctor@latest --verbose --diff` before and after changes, plus relevant tests after each focused batch.",
49148
+ "Run `npx react-doctor@latest --verbose --scope changed` before and after changes, plus relevant tests after each focused batch.",
48120
49149
  "When available, spawn subagents or isolated worktrees for independent rule families, then review and merge only the best safe fixes.",
48121
49150
  "Split unrelated, broad, or behavior-changing work into separate PRs/branches instead of one large cleanup.",
49151
+ "When one rule spans dozens of files (a migration-scale change), fix a representative sample first, confirm the recipe holds, and get the code owner's sign-off before changing the rest. Don't mass-fix a broad pattern in one unreviewed pass.",
48122
49152
  "For confirmed issues that cannot be fixed now, create GitHub issues with the rule, file/line, confidence, impact, and proposed fix.",
48123
49153
  "If a fix needs an API, UX, or architecture decision, stop and ask before editing."
48124
49154
  ];
@@ -48128,29 +49158,6 @@ const printAgentGuidance = () => gen(function* () {
48128
49158
  yield* log("");
48129
49159
  });
48130
49160
  //#endregion
48131
- //#region src/cli/utils/diagnostic-grouping.ts
48132
- const buildRulePriorityMap = (scores) => {
48133
- const rulePriority = /* @__PURE__ */ new Map();
48134
- for (const score of scores) {
48135
- if (!score?.rules) continue;
48136
- for (const [ruleKey, info] of Object.entries(score.rules)) if (typeof info.priority === "number") rulePriority.set(ruleKey, info.priority);
48137
- }
48138
- return rulePriority;
48139
- };
48140
- const compareByRulePriority = (ruleKeyA, ruleKeyB, rulePriority) => {
48141
- const priorityA = rulePriority?.get(ruleKeyA);
48142
- const priorityB = rulePriority?.get(ruleKeyB);
48143
- if (priorityA === void 0 && priorityB === void 0) return 0;
48144
- if (priorityA === void 0) return 1;
48145
- if (priorityB === void 0) return -1;
48146
- return priorityB - priorityA;
48147
- };
48148
- const sortRuleGroupsByImportance = (diagnosticGroups, rulePriority) => diagnosticGroups.toSorted(([ruleKeyA], [ruleKeyB]) => compareByRulePriority(ruleKeyA, ruleKeyB, rulePriority));
48149
- const buildSortedRuleGroups = (diagnostics, rulePriority) => sortRuleGroupsByImportance([...groupBy([...diagnostics], (diagnostic) => `${diagnostic.plugin}/${diagnostic.rule}`)], rulePriority);
48150
- const FIX_RECIPE_DIRECTIVE_LABEL = "Curl with no cache & follow the canonical fix and false positive check recipe before fixing";
48151
- const formatFixRecipeLine = (diagnostic) => hasPublishedFixRecipe(diagnostic) ? `${FIX_RECIPE_DIRECTIVE_LABEL}: ${buildRuleDocsUrl(diagnostic.plugin, diagnostic.rule)}` : null;
48152
- const formatLearnMoreLine = (diagnostic) => hasPublishedFixRecipe(diagnostic) ? `Learn more: ${buildRuleDocsUrl(diagnostic.plugin, diagnostic.rule)}` : null;
48153
- //#endregion
48154
49161
  //#region src/cli/utils/box-text.ts
48155
49162
  const ESCAPE = String.fromCharCode(27);
48156
49163
  const ANSI_ESCAPE_PATTERN = new RegExp(`${ESCAPE}\\[[0-9;]*m`, "g");
@@ -48191,6 +49198,15 @@ const boxText = (content, innerWidth) => {
48191
49198
  ].join("\n");
48192
49199
  };
48193
49200
  //#endregion
49201
+ //#region src/cli/utils/resolve-absolute-path.ts
49202
+ /**
49203
+ * Resolves a diagnostic's `filePath` (relative to its project root, or
49204
+ * already absolute) to an absolute path. Shared by the code-frame reader and
49205
+ * the terminal hyperlink builder so both turn a relative path into the same
49206
+ * on-disk location.
49207
+ */
49208
+ const resolveAbsolutePath = (filePath, rootDirectory) => Path.isAbsolute(filePath) ? filePath : Path.resolve(rootDirectory || ".", filePath);
49209
+ //#endregion
48194
49210
  //#region src/cli/utils/build-code-frame.ts
48195
49211
  /**
48196
49212
  * Renders a syntax-highlighted source excerpt around a diagnostic site
@@ -48201,7 +49217,7 @@ const boxText = (content, innerWidth) => {
48201
49217
  */
48202
49218
  const buildCodeFrame = (input) => {
48203
49219
  if (input.line <= 0) return null;
48204
- const absolutePath = Path.isAbsolute(input.filePath) ? input.filePath : Path.resolve(input.rootDirectory || ".", input.filePath);
49220
+ const absolutePath = resolveAbsolutePath(input.filePath, input.rootDirectory);
48205
49221
  let source;
48206
49222
  try {
48207
49223
  source = NFS.readFileSync(absolutePath, "utf8");
@@ -48241,6 +49257,16 @@ const resolveMeasureWidth = (reservedColumns = 0) => resolveClampedWidth({
48241
49257
  const DIVIDER_INDENT = " ";
48242
49258
  const buildSectionDivider = () => highlighter.dim(`${DIVIDER_INDENT}${"─".repeat(resolveMeasureWidth(2))}`);
48243
49259
  //#endregion
49260
+ //#region src/cli/utils/format-hyperlink.ts
49261
+ const OSC = "\x1B]";
49262
+ const ST = "\x1B\\";
49263
+ /**
49264
+ * Wraps `text` in an OSC 8 hyperlink pointing at `uri`. The visible characters
49265
+ * are exactly `text`; the link is carried in escape sequences a capable
49266
+ * terminal turns into a click target.
49267
+ */
49268
+ const formatHyperlink = (text, uri) => `${OSC}8;;${uri}${ST}${text}${OSC}8;;${ST}`;
49269
+ //#endregion
48244
49270
  //#region src/cli/utils/indent-multiline-text.ts
48245
49271
  const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
48246
49272
  //#endregion
@@ -48394,17 +49420,23 @@ const clusterNearbyDiagnostics = (diagnostics) => {
48394
49420
  }
48395
49421
  return clusters;
48396
49422
  };
48397
- const formatClusterLocation = (cluster) => {
49423
+ const formatClusterLocationText = (cluster) => {
49424
+ const { filePath } = cluster.diagnostics[0];
49425
+ if (cluster.startLine <= 0) return filePath;
49426
+ if (cluster.endLine > cluster.startLine) return `${filePath}:${cluster.startLine}-${cluster.endLine}`;
49427
+ return `${filePath}:${cluster.startLine}`;
49428
+ };
49429
+ const formatClusterLocation = (cluster, resolveSourceRoot, hyperlinks) => {
48398
49430
  const lead = cluster.diagnostics[0];
48399
49431
  const contextTag = formatFileContextTag(lead);
48400
- if (cluster.startLine <= 0) return `${lead.filePath}${contextTag}`;
48401
- if (cluster.endLine > cluster.startLine) return `${lead.filePath}:${cluster.startLine}-${cluster.endLine}${contextTag}`;
48402
- return `${lead.filePath}:${cluster.startLine}${contextTag}`;
49432
+ const location = formatClusterLocationText(cluster);
49433
+ if (!hyperlinks) return `${location}${contextTag}`;
49434
+ return `${formatHyperlink(location, pathToFileURL(resolveAbsolutePath(lead.filePath, resolveSourceRoot(lead))).href)}${contextTag}`;
48403
49435
  };
48404
- const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame) => {
49436
+ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame, hyperlinks) => {
48405
49437
  const lead = cluster.diagnostics[0];
48406
49438
  const isMultiSite = cluster.diagnostics.length > 1;
48407
- const lines = ["", highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${formatClusterLocation(cluster)}`)];
49439
+ const lines = ["", highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${formatClusterLocation(cluster, resolveSourceRoot, hyperlinks)}`)];
48408
49440
  const codeFrame = renderCodeFrame ? buildCodeFrame({
48409
49441
  filePath: lead.filePath,
48410
49442
  line: cluster.startLine,
@@ -48423,7 +49455,7 @@ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame
48423
49455
  }
48424
49456
  return lines;
48425
49457
  };
48426
- const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, renderEverySite, isAgentEnvironment) => {
49458
+ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, renderEverySite, isAgentEnvironment, hyperlinks) => {
48427
49459
  const representative = pickRepresentativeDiagnostic(ruleDiagnostics);
48428
49460
  const { severity } = representative;
48429
49461
  const trailingBadge = formatTrailingSiteBadge(ruleDiagnostics.length);
@@ -48437,13 +49469,15 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
48437
49469
  const impactMessages = isCollapsedWarningGroup ? [...new Set(ruleDiagnostics.map((diagnostic) => diagnostic.message))] : [representative.message];
48438
49470
  for (const impactMessage of impactMessages) for (const explanationLine of wrapTextToWidth(impactMessage, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(`${TOP_ERROR_DETAIL_INDENT}${explanationLine}`);
48439
49471
  if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
49472
+ const sharedFixSiteCount = getSharedFixSiteCount(ruleDiagnostics);
49473
+ if (sharedFixSiteCount > 0) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}↳ One fix clears all ${sharedFixSiteCount} findings.`));
48440
49474
  if (renderEverySite && isAgentEnvironment) {
48441
49475
  const fixRecipeLine = formatFixRecipeLine(representative);
48442
49476
  if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
48443
49477
  }
48444
49478
  const renderCodeFrame = severity === "error";
48445
49479
  const sites = renderEverySite ? ruleDiagnostics : [representative];
48446
- if (!(isCollapsedWarningGroup && representative.help.includes(representative.filePath))) for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
49480
+ if (!(isCollapsedWarningGroup && representative.help.includes(representative.filePath))) for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame, hyperlinks));
48447
49481
  return lines;
48448
49482
  };
48449
49483
  const selectErrorRuleGroups = (diagnostics, rulePriority) => buildSortedRuleGroups(diagnostics.filter((diagnostic) => diagnostic.severity === "error"), rulePriority);
@@ -48455,8 +49489,21 @@ const buildOverflowSummaryLine = (diagnostics, rulePriority) => {
48455
49489
  const command = highlighter.bold(highlighter.info("npx react-doctor@latest --verbose"));
48456
49490
  return ` ${highlighter.dim("Run")} ${command} ${highlighter.dim("to list every error and warning")}`;
48457
49491
  };
49492
+ const formatMigrationBucketLine = (bucket) => `${TOP_ERROR_DETAIL_INDENT}${bucket.title} ${highlighter.gray(`×${bucket.siteCount} across ${bucket.fileCount} files`)}`;
49493
+ const buildMigrationScaleAdvisoryLines = (diagnostics) => {
49494
+ const buckets = findMigrationScaleBuckets(diagnostics);
49495
+ if (buckets.length === 0) return [];
49496
+ const shownBuckets = buckets.slice(0, 3);
49497
+ const lines = [` ${highlighter.warn("⚠")} ${highlighter.bold("Migration-scale change")}${highlighter.dim(": sample before you sweep")}`, ...shownBuckets.map(formatMigrationBucketLine)];
49498
+ const remainingBuckets = buckets.length - shownBuckets.length;
49499
+ if (remainingBuckets > 0) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}+${remainingBuckets} more ${remainingBuckets === 1 ? "rule" : "rules"} at this scale`));
49500
+ for (const guidanceLine of wrapTextToWidth("Fixing all of them at once is hard to review and prone to subtle mistakes across the whole repo. Fix a representative few first and confirm the recipe holds. Then get the code owner's sign-off before changing the rest.", resolveMeasureWidth(4), { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${guidanceLine}`));
49501
+ const command = highlighter.info("npx react-doctor@latest <path>");
49502
+ lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.dim("Scope it down one area at a time:")} ${command}`);
49503
+ return lines;
49504
+ };
48458
49505
  const getTopErrorRuleKeys = (diagnostics, limit, rulePriority) => new Set(selectTopErrorRuleGroups(diagnostics, limit, rulePriority).map(([ruleKey]) => ruleKey));
48459
- const buildTopErrorsSection = (diagnostics, resolveSourceRoot, rulePriority) => {
49506
+ const buildTopErrorsSection = (diagnostics, resolveSourceRoot, hyperlinks, rulePriority) => {
48460
49507
  const topRuleGroups = selectErrorRuleGroups(diagnostics, rulePriority).slice(0, 3);
48461
49508
  if (topRuleGroups.length === 0) return {
48462
49509
  lines: [],
@@ -48466,7 +49513,7 @@ const buildTopErrorsSection = (diagnostics, resolveSourceRoot, rulePriority) =>
48466
49513
  const blockOffsets = [];
48467
49514
  for (const [ruleKey, ruleDiagnostics] of topRuleGroups) {
48468
49515
  blockOffsets.push(lines.length);
48469
- lines.push(...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, false, false));
49516
+ lines.push(...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, false, false, hyperlinks));
48470
49517
  lines.push("");
48471
49518
  }
48472
49519
  return {
@@ -48504,24 +49551,24 @@ const buildOverviewHeaderLines = (diagnostics) => {
48504
49551
  * single Effect.forEach over Console.log so failures or fiber
48505
49552
  * interruption produce predictable partial output.
48506
49553
  */
48507
- const printDiagnostics = (diagnostics, isVerbose, sourceRoot, rulePriority, isAgentEnvironment = false, onboarding = {}) => gen(function* () {
49554
+ const printDiagnostics = (diagnostics, isVerbose, sourceRoot, rulePriority, isAgentEnvironment = false, onboarding = {}, hyperlinks = false) => gen(function* () {
48508
49555
  const sectionPause = onboarding.sectionPause ?? void_;
48509
49556
  const animateCountUp = onboarding.animateCountUp ?? false;
48510
49557
  const resolveSourceRoot = typeof sourceRoot === "function" ? sourceRoot : () => sourceRoot;
48511
49558
  let detailLines;
48512
49559
  let topErrorBlockOffsets = [];
48513
49560
  if (!isVerbose) {
48514
- const topErrors = buildTopErrorsSection(diagnostics, resolveSourceRoot, rulePriority);
49561
+ const topErrors = buildTopErrorsSection(diagnostics, resolveSourceRoot, hyperlinks, rulePriority);
48515
49562
  detailLines = topErrors.lines;
48516
49563
  topErrorBlockOffsets = topErrors.blockOffsets;
48517
49564
  } else detailLines = buildSortedRuleGroups(diagnostics, rulePriority).flatMap(([ruleKey, ruleDiagnostics]) => {
48518
- return [...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, true, isAgentEnvironment), ""];
49565
+ return [...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, true, isAgentEnvironment, hyperlinks), ""];
48519
49566
  });
48520
49567
  const overflowLine = isVerbose ? void 0 : buildOverflowSummaryLine(diagnostics, rulePriority);
48521
49568
  const categoryTallies = buildCategoryDiagnosticGroups(diagnostics, rulePriority).map(buildCategoryTally);
48522
49569
  const categoryLines = buildCategoryTallyLines(categoryTallies);
48523
49570
  const overviewDividerLines = detailLines.length > 0 && categoryLines.length > 0 ? [buildSectionDivider()] : [];
48524
- const { lines, sectionStarts } = joinSections(detailLines, overviewDividerLines, buildOverviewHeaderLines(diagnostics), categoryLines, overflowLine ? [overflowLine] : []);
49571
+ const { lines, sectionStarts } = joinSections(detailLines, overviewDividerLines, buildOverviewHeaderLines(diagnostics), categoryLines, overflowLine ? [overflowLine] : [], buildMigrationScaleAdvisoryLines(diagnostics));
48525
49572
  const [detailStart, , , categoryStart] = sectionStarts;
48526
49573
  const pauseBeforeLineIndices = detailStart == null ? /* @__PURE__ */ new Set() : new Set(topErrorBlockOffsets.map((offset) => detailStart + offset));
48527
49574
  let lineIndex = 0;
@@ -48576,6 +49623,48 @@ const computeProjectedScore = async (topErrorSource, rescoreSource, currentScore
48576
49623
  //#endregion
48577
49624
  //#region src/cli/utils/filter-diagnostics-by-categories.ts
48578
49625
  const filterDiagnosticsByCategories = (diagnostics, categories) => categories.size === 0 ? [...diagnostics] : diagnostics.filter((diagnostic) => categories.has(diagnostic.category));
49626
+ //#endregion
49627
+ //#region src/cli/utils/supports-hyperlinks.ts
49628
+ const HYPERLINK_CAPABLE_TERM_PROGRAMS = new Set([
49629
+ "iTerm.app",
49630
+ "WezTerm",
49631
+ "vscode",
49632
+ "Hyper",
49633
+ "ghostty",
49634
+ "Tabby",
49635
+ "rio"
49636
+ ]);
49637
+ const parseVteVersion = (raw) => {
49638
+ const parsed = Number.parseInt(raw ?? "", 10);
49639
+ return Number.isNaN(parsed) ? 0 : parsed;
49640
+ };
49641
+ /**
49642
+ * Whether `stream` is a terminal that renders OSC 8 hyperlinks. Auto-detected
49643
+ * from terminal-identity env vars; the de-facto `FORCE_HYPERLINK` env var
49644
+ * overrides detection (`FORCE_HYPERLINK=0`/`false` forces off, any other value
49645
+ * forces on), mirroring how the ecosystem's terminal libraries gate the same
49646
+ * feature. Off for non-TTYs, `TERM=dumb`, and CI (whose log viewers render the
49647
+ * raw escape rather than a link). Unknown terminals default to off.
49648
+ */
49649
+ const supportsHyperlinks = (stream = process.stdout, env = process.env) => {
49650
+ const forced = env.FORCE_HYPERLINK;
49651
+ if (forced !== void 0 && forced !== "") return forced !== "0" && forced.toLowerCase() !== "false";
49652
+ if (stream.isTTY !== true) return false;
49653
+ if (env.TERM === "dumb") return false;
49654
+ if (isCiEnvironment(env)) return false;
49655
+ if (env.WT_SESSION) return true;
49656
+ if (env.KITTY_WINDOW_ID || env.TERM === "xterm-kitty") return true;
49657
+ if (parseVteVersion(env.VTE_VERSION) >= 5e3) return true;
49658
+ return Boolean(env.TERM_PROGRAM && HYPERLINK_CAPABLE_TERM_PROGRAMS.has(env.TERM_PROGRAM));
49659
+ };
49660
+ //#endregion
49661
+ //#region src/cli/utils/should-render-hyperlinks.ts
49662
+ /**
49663
+ * Whether to emit OSC 8 clickable `file:line` locations for this run: a
49664
+ * hyperlink-capable terminal AND not a coding agent (whose output parsers
49665
+ * would choke on the escape sequences).
49666
+ */
49667
+ const shouldRenderHyperlinks = (stream = process.stdout) => supportsHyperlinks(stream) && !isCodingAgentEnvironment();
48579
49668
  const FORCE_ONBOARDING_ENV_VAR = "REACT_DOCTOR_FORCE_ONBOARDING";
48580
49669
  const FALSY_FLAG_VALUES = new Set([
48581
49670
  "",
@@ -48594,26 +49683,182 @@ const canAnimateOnboarding = (stream = process.stdout) => {
48594
49683
  return !isGitHookEnvironment() && !isCiEnvironment();
48595
49684
  };
48596
49685
  //#endregion
48597
- //#region src/cli/utils/onboarding-state.ts
48598
- const GLOBAL_CONFIG_PROJECT_NAME$2 = "react-doctor";
48599
- const ONBOARDED_AT_KEY = "onboardedAt";
48600
- const getOnboardingStore = (options = {}) => new Conf({
48601
- projectName: GLOBAL_CONFIG_PROJECT_NAME$2,
48602
- cwd: options.cwd
49686
+ //#region src/cli/utils/now-iso.ts
49687
+ const nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
49688
+ const ONBOARDING_EVENT = "onboarding";
49689
+ const CI_PITCH_EVENT = "ci-pitch";
49690
+ const ACTION_UPGRADE_EVENT = "action-upgrade-v2";
49691
+ const SETUP_HINT_EVENT = "setup-hint";
49692
+ const foldLegacyDecisions = (projects, legacy, eventId) => {
49693
+ for (const [hash, record] of Object.entries(legacy ?? {})) {
49694
+ const existing = projects[hash] ?? { rootDirectory: record.rootDirectory ?? "" };
49695
+ projects[hash] = {
49696
+ ...existing,
49697
+ events: {
49698
+ ...existing.events,
49699
+ [eventId]: {
49700
+ firedAt: record.at ?? nowIso(),
49701
+ version: 1,
49702
+ ...record.outcome ? { outcome: record.outcome } : {}
49703
+ }
49704
+ }
49705
+ };
49706
+ }
49707
+ };
49708
+ const migrateCliState = (state) => {
49709
+ if (state.schemaVersion === 2) return state;
49710
+ const projects = {};
49711
+ for (const [hash, record] of Object.entries(state.projects ?? {})) {
49712
+ const carried = {
49713
+ rootDirectory: record.rootDirectory,
49714
+ ...record.events ? { events: record.events } : {},
49715
+ ...record.migrations ? { migrations: record.migrations } : {}
49716
+ };
49717
+ projects[hash] = record.setupPrompt === false ? {
49718
+ ...carried,
49719
+ events: {
49720
+ ...carried.events,
49721
+ [SETUP_HINT_EVENT]: {
49722
+ firedAt: nowIso(),
49723
+ version: 1,
49724
+ outcome: "declined"
49725
+ }
49726
+ }
49727
+ } : carried;
49728
+ }
49729
+ foldLegacyDecisions(projects, state.ciPrompts, CI_PITCH_EVENT);
49730
+ foldLegacyDecisions(projects, state.actionUpgrades, ACTION_UPGRADE_EVENT);
49731
+ return {
49732
+ schemaVersion: 2,
49733
+ global: typeof state.onboardedAt === "string" ? { events: { [ONBOARDING_EVENT]: {
49734
+ firedAt: state.onboardedAt,
49735
+ version: 1
49736
+ } } } : {},
49737
+ projects
49738
+ };
49739
+ };
49740
+ const resolveConfigDir = (options) => options.cwd ?? (process.env["REACT_DOCTOR_CONFIG_DIR"] || void 0);
49741
+ const openStore = (options = {}) => new Conf({
49742
+ projectName: REACT_DOCTOR_CONFIG_PROJECT_NAME,
49743
+ cwd: resolveConfigDir(options)
48603
49744
  });
48604
- const hasCompletedOnboarding = (options = {}) => {
49745
+ const openMigratedStore = (options) => {
49746
+ const store = openStore(options);
49747
+ if (store.store.schemaVersion !== 2) store.store = migrateCliState(store.store);
49748
+ return store;
49749
+ };
49750
+ const readCliState = (select, fallback, options = {}) => {
48605
49751
  try {
48606
- return typeof getOnboardingStore(options).get(ONBOARDED_AT_KEY) === "string";
49752
+ return select(openMigratedStore(options).store);
48607
49753
  } catch {
49754
+ return fallback;
49755
+ }
49756
+ };
49757
+ const updateCliState = (update, options = {}) => {
49758
+ try {
49759
+ const store = openMigratedStore(options);
49760
+ store.store = update(store.store);
48608
49761
  return true;
49762
+ } catch {
49763
+ return false;
48609
49764
  }
48610
49765
  };
49766
+ //#endregion
49767
+ //#region src/cli/utils/hash-project-root.ts
49768
+ const hashProjectRoot = (projectRoot) => createHash("sha256").update(Path.resolve(projectRoot)).digest("hex");
49769
+ //#endregion
49770
+ //#region src/cli/utils/cli-lifecycle.ts
49771
+ const versionOf = (item) => item.version ?? 1;
49772
+ const selectScope = (state, scoped, projectRoot) => scoped.scope === "global" ? state.global : projectRoot === void 0 ? void 0 : state.projects?.[hashProjectRoot(projectRoot)];
49773
+ const updateScope = (state, scoped, projectRoot, updateScopeState) => {
49774
+ if (scoped.scope === "global") return {
49775
+ ...state,
49776
+ global: updateScopeState(state.global ?? {})
49777
+ };
49778
+ if (projectRoot === void 0) return state;
49779
+ const projectKey = hashProjectRoot(projectRoot);
49780
+ const base = state.projects?.[projectKey] ?? { rootDirectory: Path.resolve(projectRoot) };
49781
+ return {
49782
+ ...state,
49783
+ projects: {
49784
+ ...state.projects,
49785
+ [projectKey]: {
49786
+ ...base,
49787
+ ...updateScopeState(base)
49788
+ }
49789
+ }
49790
+ };
49791
+ };
49792
+ const isGatePending = (gate, target = {}, options = {}) => {
49793
+ if (gate.scope === "project" && target.projectRoot === void 0) return false;
49794
+ return readCliState((state) => {
49795
+ const record = selectScope(state, gate, target.projectRoot)?.events?.[gate.id];
49796
+ return !record || record.version < versionOf(gate);
49797
+ }, gate.fireWhenUnknown ?? false, options);
49798
+ };
49799
+ const recordGate = (gate, target = {}, options = {}) => updateCliState((state) => updateScope(state, gate, target.projectRoot, (scope) => ({
49800
+ ...scope,
49801
+ events: {
49802
+ ...scope.events,
49803
+ [gate.id]: {
49804
+ firedAt: nowIso(),
49805
+ version: versionOf(gate),
49806
+ ...target.outcome ? { outcome: target.outcome } : {}
49807
+ }
49808
+ }
49809
+ })), options);
49810
+ const isMigrationPending = (migration, target = {}, options = {}) => {
49811
+ if (migration.scope === "project" && target.projectRoot === void 0) return false;
49812
+ return readCliState((state) => {
49813
+ const record = selectScope(state, migration, target.projectRoot)?.migrations?.[migration.id];
49814
+ return !record || record.version < versionOf(migration);
49815
+ }, false, options);
49816
+ };
49817
+ const recordMigration = (migration, projectRoot, record, options) => updateCliState((state) => updateScope(state, migration, projectRoot, (scope) => ({
49818
+ ...scope,
49819
+ migrations: {
49820
+ ...scope.migrations,
49821
+ [migration.id]: record
49822
+ }
49823
+ })), options);
49824
+ const runMigrations = async (migrations, target = {}, options = {}) => {
49825
+ const results = [];
49826
+ for (const migration of migrations) {
49827
+ if (!isMigrationPending(migration, target, options)) {
49828
+ results.push({
49829
+ id: migration.id,
49830
+ ran: false,
49831
+ applied: true
49832
+ });
49833
+ continue;
49834
+ }
49835
+ let applied = false;
49836
+ try {
49837
+ applied = await migration.run({ projectRoot: target.projectRoot });
49838
+ } catch {
49839
+ applied = false;
49840
+ }
49841
+ if (applied) recordMigration(migration, target.projectRoot, {
49842
+ ranAt: nowIso(),
49843
+ version: versionOf(migration)
49844
+ }, options);
49845
+ results.push({
49846
+ id: migration.id,
49847
+ ran: true,
49848
+ applied
49849
+ });
49850
+ }
49851
+ return results;
49852
+ };
49853
+ //#endregion
49854
+ //#region src/cli/utils/onboarding-state.ts
49855
+ const ONBOARDING_GATE = {
49856
+ id: ONBOARDING_EVENT,
49857
+ scope: "global"
49858
+ };
49859
+ const hasCompletedOnboarding = (options = {}) => !isGatePending(ONBOARDING_GATE, {}, options);
48611
49860
  const markOnboardingComplete = (options = {}) => {
48612
- try {
48613
- const store = getOnboardingStore(options);
48614
- if (typeof store.get(ONBOARDED_AT_KEY) === "string") return;
48615
- store.set(ONBOARDED_AT_KEY, (/* @__PURE__ */ new Date()).toISOString());
48616
- } catch {}
49861
+ if (isGatePending(ONBOARDING_GATE, {}, options)) recordGate(ONBOARDING_GATE, {}, options);
48617
49862
  };
48618
49863
  //#endregion
48619
49864
  //#region src/cli/utils/render-project-detection.ts
@@ -49054,6 +50299,78 @@ const resolveCliCategories = (categoryFlag) => {
49054
50299
  return resolvedCategories.length > 0 ? resolvedCategories : void 0;
49055
50300
  };
49056
50301
  //#endregion
50302
+ //#region src/cli/utils/git-hook-shared.ts
50303
+ const HOOK_FILE_NAME = "pre-commit";
50304
+ const HOOK_RELATIVE_PATH = "hooks/pre-commit";
50305
+ const LEGACY_HOOK_RUNNER_RELATIVE_PATH = ".react-doctor/hooks/pre-commit";
50306
+ const HUSKY_HOOKS_PATH = ".husky";
50307
+ const VITE_PLUS_HOOKS_PATH = ".vite-hooks";
50308
+ const LEFTHOOK_CONFIG_FILES = ["lefthook.yml", "lefthook.yaml"];
50309
+ const PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml";
50310
+ const OVERCOMMIT_CONFIG_FILE = ".overcommit.yml";
50311
+ const REACT_DOCTOR_COMMAND = "react-doctor --staged --blocking warning";
50312
+ const NON_BLOCKING_REACT_DOCTOR_COMMAND = [
50313
+ "react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\");",
50314
+ `if ${REACT_DOCTOR_COMMAND} > "$react_doctor_output" 2>&1; then`,
50315
+ "rm -f \"$react_doctor_output\";",
50316
+ "else",
50317
+ "rm -f \"$react_doctor_output\";",
50318
+ `printf "%s\\n" "React Doctor found staged regressions." "Run ${REACT_DOCTOR_COMMAND} to inspect." "Want them fixed? Ask your agent to run that command and resolve the findings." >&2;`,
50319
+ "fi"
50320
+ ].join(" ");
50321
+ const PACKAGE_JSON_FILE_NAME = "package.json";
50322
+ const runGit = (projectRoot, args) => {
50323
+ try {
50324
+ return execFileSync("git", [...args], {
50325
+ cwd: projectRoot,
50326
+ encoding: "utf8",
50327
+ stdio: [
50328
+ "ignore",
50329
+ "pipe",
50330
+ "ignore"
50331
+ ]
50332
+ }).trim();
50333
+ } catch {
50334
+ return null;
50335
+ }
50336
+ };
50337
+ const resolveGitPath = (baseDirectory, value) => Path.isAbsolute(value) ? value : Path.resolve(baseDirectory, value);
50338
+ const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
50339
+ const getPackageJsonPath = (projectRoot) => Path.join(projectRoot, PACKAGE_JSON_FILE_NAME);
50340
+ const readPackageJson = (projectRoot) => {
50341
+ try {
50342
+ return JSON.parse(NFS.readFileSync(getPackageJsonPath(projectRoot), "utf8"));
50343
+ } catch {
50344
+ return null;
50345
+ }
50346
+ };
50347
+ const writeJsonFile$1 = (filePath, value) => {
50348
+ NFS.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
50349
+ };
50350
+ const packageHasDependency = (projectRoot, dependencyName) => {
50351
+ const packageJson = readPackageJson(projectRoot);
50352
+ if (!isRecord$1(packageJson)) return false;
50353
+ return [
50354
+ "dependencies",
50355
+ "devDependencies",
50356
+ "optionalDependencies"
50357
+ ].some((fieldName) => {
50358
+ const dependencies = packageJson[fieldName];
50359
+ return isRecord$1(dependencies) && typeof dependencies[dependencyName] === "string";
50360
+ });
50361
+ };
50362
+ const packageHasRecordKey = (projectRoot, key) => {
50363
+ const packageJson = readPackageJson(projectRoot);
50364
+ return isRecord$1(packageJson) && isRecord$1(packageJson[key]);
50365
+ };
50366
+ const packageHasNestedRecordKey = (projectRoot, key, nestedKey) => {
50367
+ const packageJson = readPackageJson(projectRoot);
50368
+ if (!isRecord$1(packageJson)) return false;
50369
+ const value = packageJson[key];
50370
+ return isRecord$1(value) && isRecord$1(value[nestedKey]);
50371
+ };
50372
+ const ensureTrailingNewline = (content) => content.endsWith("\n") ? content : `${content}\n`;
50373
+ //#endregion
49057
50374
  //#region src/cli/utils/scan-result-cache.ts
49058
50375
  const CACHE_DISABLED_VALUES = new Set(["1", "true"]);
49059
50376
  const TOOLCHAIN_PACKAGE_SPECIFIERS = [
@@ -49064,7 +50381,7 @@ const TOOLCHAIN_PACKAGE_SPECIFIERS = [
49064
50381
  "eslint-plugin-react-hooks/package.json"
49065
50382
  ];
49066
50383
  const bundledRequire = createRequire(import.meta.url);
49067
- const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
50384
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
49068
50385
  const normalizeForStableJson = (value) => {
49069
50386
  if (value === null) return null;
49070
50387
  if (value === void 0) return void 0;
@@ -49093,24 +50410,9 @@ const stringifyStableJson = (value) => {
49093
50410
  }
49094
50411
  };
49095
50412
  const hashString = (value) => crypto.createHash("sha1").update(value).digest("hex");
49096
- const runGit$1 = (directory, args) => {
49097
- try {
49098
- return execFileSync("git", [...args], {
49099
- cwd: directory,
49100
- encoding: "utf8",
49101
- stdio: [
49102
- "ignore",
49103
- "pipe",
49104
- "ignore"
49105
- ]
49106
- }).trim();
49107
- } catch {
49108
- return null;
49109
- }
49110
- };
49111
- const readHeadSha = (projectDirectory) => runGit$1(projectDirectory, ["rev-parse", "HEAD"]);
50413
+ const readHeadSha = (projectDirectory) => runGit(projectDirectory, ["rev-parse", "HEAD"]);
49112
50414
  const isWorktreeClean = (projectDirectory) => {
49113
- const status = runGit$1(projectDirectory, [
50415
+ const status = runGit(projectDirectory, [
49114
50416
  "status",
49115
50417
  "--porcelain=v1",
49116
50418
  "--untracked-files=normal"
@@ -49118,7 +50420,7 @@ const isWorktreeClean = (projectDirectory) => {
49118
50420
  return status !== null && status.length === 0;
49119
50421
  };
49120
50422
  const hasHiddenTrackedFileState = (projectDirectory) => {
49121
- const output = runGit$1(projectDirectory, ["ls-files", "-v"]);
50423
+ const output = runGit(projectDirectory, ["ls-files", "-v"]);
49122
50424
  if (output === null) return true;
49123
50425
  return output.split("\n").some((line) => line.length > 0 && line[0] !== "H");
49124
50426
  };
@@ -49131,27 +50433,27 @@ const resolveCacheFilePath = (projectDirectory) => {
49131
50433
  const readPersistedCache = (cacheFilePath) => {
49132
50434
  try {
49133
50435
  const parsed = JSON.parse(fs.readFileSync(cacheFilePath, "utf8"));
49134
- if (!isRecord$1(parsed) || parsed.version !== 1) return {
49135
- version: 1,
50436
+ if (!isRecord(parsed) || parsed.version !== 2) return {
50437
+ version: 2,
49136
50438
  entries: []
49137
50439
  };
49138
50440
  if (!Array.isArray(parsed.entries)) return {
49139
- version: 1,
50441
+ version: 2,
49140
50442
  entries: []
49141
50443
  };
49142
50444
  const entries = [];
49143
50445
  for (const entry of parsed.entries) {
49144
- if (!isRecord$1(entry) || typeof entry.key !== "string" || typeof entry.createdAtMs !== "number") continue;
49145
- if (!isRecord$1(entry.payload) || !Array.isArray(entry.payload.diagnostics)) continue;
50446
+ if (!isRecord(entry) || typeof entry.key !== "string" || typeof entry.createdAtMs !== "number") continue;
50447
+ if (!isRecord(entry.payload) || !Array.isArray(entry.payload.diagnostics)) continue;
49146
50448
  entries.push(entry);
49147
50449
  }
49148
50450
  return {
49149
- version: 1,
50451
+ version: 2,
49150
50452
  entries
49151
50453
  };
49152
50454
  } catch {
49153
50455
  return {
49154
- version: 1,
50456
+ version: 2,
49155
50457
  entries: []
49156
50458
  };
49157
50459
  }
@@ -49204,7 +50506,7 @@ const buildScanResultCacheKey = (input) => {
49204
50506
  if (headSha === null) return null;
49205
50507
  if (stringifyStableJson(input.userConfig) === null) return null;
49206
50508
  const cacheKeyJson = stringifyStableJson({
49207
- schemaVersion: 1,
50509
+ schemaVersion: 2,
49208
50510
  projectIdentity: resolveProjectIdentity(input.projectDirectory),
49209
50511
  headSha,
49210
50512
  reactDoctorVersion: input.version,
@@ -49224,6 +50526,7 @@ const buildScanResultCacheKey = (input) => {
49224
50526
  adoptExistingLintConfig: input.options.adoptExistingLintConfig,
49225
50527
  ignoredTags: [...input.options.ignoredTags].sort(),
49226
50528
  concurrency: input.options.concurrency,
50529
+ lintBatchOrdering: resolveLintBatchOrdering(),
49227
50530
  baselineRef: input.options.baseline?.ref,
49228
50531
  changedLineRanges: input.options.changedLineRanges ?? void 0,
49229
50532
  noScore: input.options.noScore,
@@ -49241,7 +50544,7 @@ const createScanResultCache = (projectDirectory) => {
49241
50544
  for (const entry of persistedCache.entries) entries.set(entry.key, entry);
49242
50545
  const persist = () => {
49243
50546
  writePersistedCache(cacheFilePath, {
49244
- version: 1,
50547
+ version: 2,
49245
50548
  entries: [...entries.values()].sort((firstEntry, secondEntry) => secondEntry.createdAtMs - firstEntry.createdAtMs).slice(0, 20)
49246
50549
  });
49247
50550
  };
@@ -49257,7 +50560,7 @@ const createScanResultCache = (projectDirectory) => {
49257
50560
  }
49258
50561
  };
49259
50562
  };
49260
- const shouldStoreScanPayload = (payload) => !payload.didLintFail && !payload.didDeadCodeFail && payload.lintPartialFailures.length === 0;
50563
+ const shouldStoreScanPayload = (payload) => !payload.didLintFail && !payload.didDeadCodeFail && payload.lintPartialFailures.length === 0 && !payload.supplyChainOverlapTimedOut;
49261
50564
  //#endregion
49262
50565
  //#region src/inspect.ts
49263
50566
  const silentConsole = makeNoopConsole();
@@ -49321,21 +50624,24 @@ const deriveScope = (options) => {
49321
50624
  if (options.changedLineRanges !== null) return "lines";
49322
50625
  return options.includePaths.length > 0 ? "files" : "full";
49323
50626
  };
49324
- const buildRunEventConfig = (options, userConfig, hasCustomConfig) => ({
49325
- scope: deriveScope(options),
49326
- parallel: options.concurrency !== void 0,
49327
- workerCount: options.concurrency,
49328
- lint: options.lint,
49329
- deadCode: options.deadCode,
49330
- scoreOnly: options.scoreOnly,
49331
- noScore: options.noScore,
49332
- respectInlineDisables: options.respectInlineDisables,
49333
- showWarnings: options.warnings,
49334
- usedOutputDir: options.outputDirectory !== null,
49335
- ignoredTagCount: options.ignoredTags.size,
49336
- hasCustomConfig,
49337
- userConfig
49338
- });
50627
+ const buildRunEventConfig = (options, userConfig, hasCustomConfig, resolvedWorkerCount) => {
50628
+ const { workerCount, parallel } = resolveWorkerTelemetry(resolvedWorkerCount, options.concurrency);
50629
+ return {
50630
+ scope: deriveScope(options),
50631
+ parallel,
50632
+ workerCount,
50633
+ lint: options.lint,
50634
+ deadCode: options.deadCode,
50635
+ scoreOnly: options.scoreOnly,
50636
+ noScore: options.noScore,
50637
+ respectInlineDisables: options.respectInlineDisables,
50638
+ showWarnings: options.warnings,
50639
+ usedOutputDir: options.outputDirectory !== null,
50640
+ ignoredTagCount: options.ignoredTags.size,
50641
+ hasCustomConfig,
50642
+ userConfig
50643
+ };
50644
+ };
49339
50645
  const inspect = async (directory, inputOptions = {}) => {
49340
50646
  const startTime = performance$1.now();
49341
50647
  const isConcurrentScan = inputOptions.concurrentScan === true;
@@ -49427,7 +50733,7 @@ const runBaselineComparison = async (params) => {
49427
50733
  resolveLocalGithubViewerPermission: false,
49428
50734
  suppressScanSummary: true,
49429
50735
  supplyChainManifestChanged: params.options.supplyChainManifestChanged
49430
- }, {}).pipe(provide(baseLayers), provideService(Console, silentConsole))));
50736
+ }, {}).pipe(provide(baseLayers), provideService$2(Console, silentConsole))));
49431
50737
  if (baseOutput.didLintFail) return null;
49432
50738
  const delta = computeDiagnosticDelta({
49433
50739
  headDiagnostics: params.headDiagnostics,
@@ -49512,7 +50818,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
49512
50818
  runId: getRunId(),
49513
50819
  resolveLocalGithubViewerPermission: !options.noScore,
49514
50820
  suppressScanSummary: options.suppressRendering,
49515
- supplyChainManifestChanged: options.supplyChainManifestChanged
50821
+ supplyChainManifestChanged: options.supplyChainManifestChanged,
50822
+ concurrentScan: options.concurrentScan
49516
50823
  }, { beforeLint: (projectInfo, lintIncludePaths) => gen(function* () {
49517
50824
  recordSentryProjectContext(projectInfo, rootSentrySpan, { concurrentScan: options.concurrentScan });
49518
50825
  recordCount(METRIC.projectDetected, 1);
@@ -49526,7 +50833,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
49526
50833
  lintSourceFileCount
49527
50834
  });
49528
50835
  }) });
49529
- const output = await runPromise(restoreLegacyThrow(applyObservability(options.silent ? program.pipe(provide(layers), provideService(Console, silentConsole)) : program.pipe(provide(layers)), rootSentrySpan)));
50836
+ const output = await runPromise(restoreLegacyThrow(applyObservability(options.silent ? program.pipe(provide(layers), provideService$2(Console, silentConsole)) : program.pipe(provide(layers)), rootSentrySpan)));
49530
50837
  const didLintFail = lintBindingMissing || output.didLintFail;
49531
50838
  const lintFailureReason = lintBindingMissing ? `oxlint native binding not found for Node ${process.version}; expected one matching ${OXLINT_NODE_REQUIREMENT}` : output.lintFailureReason;
49532
50839
  if (!options.scoreOnly && !lintBindingMissing && output.didLintFail && lintFailureReason !== null) if (output.lintFailureReasonKind === "native-binding-missing") runConsole(log(highlighter.gray(` Upgrade to Node ${OXLINT_NODE_REQUIREMENT} or run: npx -p oxlint@latest react-doctor@latest`)));
@@ -49563,12 +50870,15 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
49563
50870
  lintPartialFailures: output.lintPartialFailures,
49564
50871
  didDeadCodeFail: output.didDeadCodeFail,
49565
50872
  deadCodeFailureReason: output.deadCodeFailureReason,
50873
+ deadCodeOverlapped: output.deadCodeOverlapped,
49566
50874
  directory: output.resolvedDirectory,
49567
50875
  scannedFileCount: output.scannedFileCount,
49568
50876
  scannedFilePaths: output.scannedFilePaths,
49569
50877
  scanElapsedMilliseconds: output.scanElapsedMilliseconds,
50878
+ scanConcurrency: output.scanConcurrency,
49570
50879
  baselineDelta,
49571
- lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind
50880
+ lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
50881
+ supplyChainOverlapTimedOut: output.supplyChainOverlapTimedOut
49572
50882
  };
49573
50883
  if (cacheKey !== null && scanResultCache !== null && shouldStoreScanPayload(payload)) scanResultCache.store(cacheKey, payload);
49574
50884
  const result = await renderAndRecordScan({
@@ -49579,12 +50889,14 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
49579
50889
  startTime,
49580
50890
  rootSentrySpan,
49581
50891
  scanMode: baselineDelta ? "baseline" : isDiffMode ? "diff" : "full",
49582
- baselineDegraded
50892
+ baselineDegraded,
50893
+ lintCacheHitFileCount: output.lintCacheHitFileCount,
50894
+ lintCacheTotalFileCount: output.lintCacheTotalFileCount
49583
50895
  });
49584
50896
  recordOnboardingCompletion(options);
49585
50897
  return result;
49586
50898
  };
49587
- const runMaybeSilent = (effect, silent) => silent ? effect.pipe(provideService(Console, silentConsole)) : effect;
50899
+ const runMaybeSilent = (effect, silent) => silent ? effect.pipe(provideService$2(Console, silentConsole)) : effect;
49588
50900
  const renderCachedProjectDetection = async (input) => {
49589
50901
  if (input.options.scoreOnly || input.options.suppressRendering) return;
49590
50902
  await runPromise(runMaybeSilent(printProjectDetection({
@@ -49612,14 +50924,17 @@ const renderAndRecordScan = async (input) => {
49612
50924
  scannedFileCount: input.payload.scannedFileCount,
49613
50925
  scannedFilePaths: input.payload.scannedFilePaths,
49614
50926
  scanElapsedMilliseconds: input.payload.scanElapsedMilliseconds,
50927
+ lintCacheHitFileCount: input.lintCacheHitFileCount ?? null,
50928
+ lintCacheTotalFileCount: input.lintCacheTotalFileCount ?? null,
49615
50929
  baselineDelta: input.payload.baselineDelta
49616
50930
  }), input.options.silent));
50931
+ const { workerCount: resolvedWorkerCount, parallel } = resolveWorkerTelemetry(input.payload.scanConcurrency, input.options.concurrency);
49617
50932
  recordScanMetrics({
49618
50933
  result,
49619
50934
  mode: input.scanMode,
49620
50935
  baselineDegraded: input.baselineDegraded,
49621
- parallel: input.options.concurrency !== void 0,
49622
- workerCount: input.options.concurrency,
50936
+ parallel,
50937
+ workerCount: resolvedWorkerCount,
49623
50938
  lint: input.options.lint,
49624
50939
  deadCode: input.options.deadCode,
49625
50940
  scoreOnly: input.options.scoreOnly,
@@ -49629,19 +50944,22 @@ const renderAndRecordScan = async (input) => {
49629
50944
  didDeadCodeFail: input.payload.didDeadCodeFail
49630
50945
  });
49631
50946
  recordRunEvent(input.rootSentrySpan, {
49632
- ...buildRunEventConfig(input.options, input.userConfig, input.hasCustomConfig),
50947
+ ...buildRunEventConfig(input.options, input.userConfig, input.hasCustomConfig, resolvedWorkerCount),
49633
50948
  result,
49634
50949
  mode: input.scanMode,
49635
50950
  gateExempt: input.baselineDegraded,
49636
50951
  didLintFail: input.payload.didLintFail,
49637
50952
  lintFailureReasonKind: input.payload.lintFailureReasonKind,
49638
50953
  lintPartialFailureCount: input.payload.lintPartialFailures.length,
49639
- didDeadCodeFail: input.payload.didDeadCodeFail
50954
+ lintDroppedFileCount: countDroppedLintFiles(input.payload.lintPartialFailures),
50955
+ didDeadCodeFail: input.payload.didDeadCodeFail,
50956
+ supplyChainOverlapTimedOut: input.payload.supplyChainOverlapTimedOut,
50957
+ deadCodeOverlapped: input.payload.deadCodeOverlapped
49640
50958
  });
49641
50959
  return result;
49642
50960
  };
49643
50961
  const finalizeAndRender = (input) => gen(function* () {
49644
- const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds, baselineDelta } = input;
50962
+ const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds, lintCacheHitFileCount, lintCacheTotalFileCount, baselineDelta } = input;
49645
50963
  const { skippedChecks, skippedCheckReasons } = buildSkippedChecks({
49646
50964
  didLintFail,
49647
50965
  lintFailureReason,
@@ -49661,6 +50979,10 @@ const finalizeAndRender = (input) => gen(function* () {
49661
50979
  scannedFileCount,
49662
50980
  scannedFilePaths,
49663
50981
  scanElapsedMilliseconds,
50982
+ ...lintCacheTotalFileCount !== null ? {
50983
+ lintCacheHitFileCount,
50984
+ lintCacheTotalFileCount
50985
+ } : {},
49664
50986
  ...baselineDelta ? { baselineDelta } : {}
49665
50987
  });
49666
50988
  if (options.suppressRendering) return buildResult();
@@ -49674,6 +50996,7 @@ const finalizeAndRender = (input) => gen(function* () {
49674
50996
  }
49675
50997
  const animateRender = !options.silent && !options.verbose && canAnimateOnboarding(process.stdout);
49676
50998
  const pause = onboardingSectionPause(animateRender);
50999
+ const useHyperlinks = shouldRenderHyperlinks(process.stdout);
49677
51000
  const demotedDiagnosticCount = diagnostics.length - surfaceDiagnostics.length;
49678
51001
  const lintSourceFileCount = options.includePaths.length > 0 ? options.includePaths.length : project.sourceFileCount;
49679
51002
  if (printedDiagnostics.length === 0) {
@@ -49699,7 +51022,7 @@ const finalizeAndRender = (input) => gen(function* () {
49699
51022
  yield* printDiagnostics([...printedDiagnostics], options.verbose, directory, buildRulePriorityMap([score]), isCodingAgentEnvironment(), {
49700
51023
  sectionPause: pause,
49701
51024
  animateCountUp: animateRender
49702
- });
51025
+ }, useHyperlinks);
49703
51026
  if (options.isNonInteractiveEnvironment && options.outputSurface !== "prComment") yield* printAgentGuidance();
49704
51027
  if (options.categoryFilters.size === 0 && demotedDiagnosticCount > 0) {
49705
51028
  yield* log(highlighter.gray(` ${demotedDiagnosticCount} demoted from the ${options.outputSurface} surface (e.g. design cleanup) — run \`npx react-doctor@latest .\` locally for the full list.`));
@@ -49888,24 +51211,18 @@ const isExpectedUserError = (error) => error instanceof CliInputError || isProje
49888
51211
  //#region src/cli/utils/build-handoff-payload.ts
49889
51212
  const buildHandoffPayload = (input) => {
49890
51213
  const topGroups = buildSortedRuleGroups(input.diagnostics).slice(0, 3);
51214
+ const migrationScaleBuckets = new Map(findMigrationScaleBuckets(input.diagnostics).map((bucket) => [bucket.ruleKey, bucket]));
49891
51215
  let outputDirectory = null;
49892
51216
  try {
49893
51217
  outputDirectory = writeDiagnosticsDirectory([...input.diagnostics], input.outputDirectory);
49894
51218
  } catch {}
49895
- const lines = [
49896
- "Before fixing anything, first ask me whether I'd like to add React Doctor to CI so every pull request is scanned automatically. Explain that:",
49897
- `- It's used by teams at ${CI_TRUST_COMPANIES}.`,
49898
- "- I don't have to fix everything at once; CI keeps new PRs clean while I incrementally pay down the existing issues.",
49899
- `- Setup guide: ${CI_URL}`,
49900
- "If I say yes, run `npx react-doctor install` (or add the GitHub Actions workflow). Either way, then continue with the fixes below.",
49901
- "",
49902
- `Fix the top ${topGroups.length} React Doctor ${topGroups.length === 1 ? "issue" : "issues"} in ${input.projectName} on this pass — leave the rest for a follow-up.`,
49903
- ""
49904
- ];
51219
+ const lines = [`Fix the top ${topGroups.length} React Doctor ${topGroups.length === 1 ? "issue" : "issues"} in ${input.projectName} on this pass — leave the rest for a follow-up.`, ""];
49905
51220
  topGroups.forEach(([ruleKey, ruleDiagnostics], index) => {
49906
51221
  const representative = ruleDiagnostics[0];
49907
51222
  const severityLabel = representative.severity === "error" ? "ERROR" : "WARN";
49908
- lines.push(`${index + 1}. ${severityLabel} ${representative.category}: ${representative.title ?? ruleKey} (×${ruleDiagnostics.length})`, ` ${representative.message}`);
51223
+ const sharedFixSiteCount = getSharedFixSiteCount(ruleDiagnostics);
51224
+ const countBadge = sharedFixSiteCount > 0 ? `one fix · ${sharedFixSiteCount} sites` : `×${ruleDiagnostics.length}`;
51225
+ lines.push(`${index + 1}. ${severityLabel} ${representative.category}: ${representative.title ?? ruleKey} (${countBadge})`, ` ${representative.message}`);
49909
51226
  const fixRecipeLine = formatFixRecipeLine(representative);
49910
51227
  if (fixRecipeLine) lines.push(` ${fixRecipeLine}`);
49911
51228
  const uniqueFiles = [...new Set(ruleDiagnostics.map((diagnostic) => diagnostic.filePath))];
@@ -49915,10 +51232,19 @@ const buildHandoffPayload = (input) => {
49915
51232
  }
49916
51233
  const remainingFiles = uniqueFiles.length - 3;
49917
51234
  if (remainingFiles > 0) lines.push(` - +${remainingFiles} more files`);
51235
+ const migrationBucket = migrationScaleBuckets.get(ruleKey);
51236
+ if (migrationBucket) lines.push(` Migration-scale (${migrationBucket.fileCount} files): fix a representative sample, confirm the recipe holds, and get the code owner's sign-off before changing the rest in one pass.`);
49918
51237
  });
49919
51238
  lines.push("");
49920
51239
  if (outputDirectory) lines.push(`Full results for all ${input.diagnostics.length} issues (diagnostics.json + a .txt per rule): ${outputDirectory}`, "");
49921
- lines.push("Read each file and fix the root cause — don't suppress or silence the rule.", "", "Verify against the real thing, don't assume: confirm each change matches the canonical fix recipe you fetched for that rule, then re-run `npx react-doctor@latest --verbose` and check the issue is actually gone against the real tool before moving on.", "", "Teach me as you go: for every issue you touch, explain it in plain language (no jargon) — what the problem is, why it's a problem, and how serious it is in human terms. Describe the real-world impact and severity concretely (e.g. \"this crashes the page for users on Safari\" vs. \"this is a minor cleanup with no user impact\") so I understand why it matters, not just what changed.", "", "Then work through the rest from the full results above.");
51240
+ lines.push("Read each file and fix the root cause — don't suppress or silence the rule.", "", "Findings that share a `fixGroupId` (in diagnostics.json) are one root cause — a single fix clears all of them, so treat each `fixGroupId` as ONE task, not one per site.", "", "Verify against the real thing, don't assume: confirm each change matches the canonical fix recipe you fetched for that rule, then re-run `npx react-doctor@latest --verbose` and check the issue is actually gone against the real tool before moving on.", "", "Teach me as you go: for every issue you touch, explain it in plain language (no jargon) — what the problem is, why it's a problem, and how serious it is in human terms. Describe the real-world impact and severity concretely (e.g. \"this crashes the page for users on Safari\" vs. \"this is a minor cleanup with no user impact\") so I understand why it matters, not just what changed.", "");
51241
+ const shownRuleKeys = new Set(topGroups.map(([ruleKey]) => ruleKey));
51242
+ const deferredMigrationBuckets = [...migrationScaleBuckets.values()].filter((bucket) => !shownRuleKeys.has(bucket.ruleKey));
51243
+ if (deferredMigrationBuckets.length > 0) {
51244
+ const ruleSummaries = deferredMigrationBuckets.map((bucket) => `${bucket.title} (${bucket.fileCount} files)`).join(", ");
51245
+ lines.push(`Some of the rest are migration-scale (span dozens of files): ${ruleSummaries}. For each, fix a representative sample, confirm the recipe holds, and get the code owner's sign-off before changing the rest in one pass.`, "");
51246
+ }
51247
+ lines.push("Then work through the rest from the full results above.");
49922
51248
  return lines.join("\n");
49923
51249
  };
49924
51250
  //#endregion
@@ -49962,78 +51288,6 @@ const detectAvailableAgents = async () => {
49962
51288
  return getSkillAgentTypes().filter((agent) => agent !== "universal" && detected.has(agent));
49963
51289
  };
49964
51290
  //#endregion
49965
- //#region src/cli/utils/git-hook-shared.ts
49966
- const HOOK_FILE_NAME = "pre-commit";
49967
- const HOOK_RELATIVE_PATH = "hooks/pre-commit";
49968
- const LEGACY_HOOK_RUNNER_RELATIVE_PATH = ".react-doctor/hooks/pre-commit";
49969
- const HUSKY_HOOKS_PATH = ".husky";
49970
- const VITE_PLUS_HOOKS_PATH = ".vite-hooks";
49971
- const LEFTHOOK_CONFIG_FILES = ["lefthook.yml", "lefthook.yaml"];
49972
- const PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml";
49973
- const OVERCOMMIT_CONFIG_FILE = ".overcommit.yml";
49974
- const REACT_DOCTOR_COMMAND = "react-doctor --staged --blocking warning";
49975
- const NON_BLOCKING_REACT_DOCTOR_COMMAND = [
49976
- "react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\");",
49977
- `if ${REACT_DOCTOR_COMMAND} > "$react_doctor_output" 2>&1; then`,
49978
- "rm -f \"$react_doctor_output\";",
49979
- "else",
49980
- "rm -f \"$react_doctor_output\";",
49981
- `printf "%s\\n" "React Doctor found staged regressions." "Run ${REACT_DOCTOR_COMMAND} to inspect." "Want them fixed? Ask your agent to run that command and resolve the findings." >&2;`,
49982
- "fi"
49983
- ].join(" ");
49984
- const PACKAGE_JSON_FILE_NAME = "package.json";
49985
- const runGit = (projectRoot, args) => {
49986
- try {
49987
- return execFileSync("git", [...args], {
49988
- cwd: projectRoot,
49989
- encoding: "utf8",
49990
- stdio: [
49991
- "ignore",
49992
- "pipe",
49993
- "ignore"
49994
- ]
49995
- }).trim();
49996
- } catch {
49997
- return null;
49998
- }
49999
- };
50000
- const resolveGitPath = (baseDirectory, value) => Path.isAbsolute(value) ? value : Path.resolve(baseDirectory, value);
50001
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
50002
- const getPackageJsonPath = (projectRoot) => Path.join(projectRoot, PACKAGE_JSON_FILE_NAME);
50003
- const readPackageJson = (projectRoot) => {
50004
- try {
50005
- return JSON.parse(NFS.readFileSync(getPackageJsonPath(projectRoot), "utf8"));
50006
- } catch {
50007
- return null;
50008
- }
50009
- };
50010
- const writeJsonFile$1 = (filePath, value) => {
50011
- NFS.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
50012
- };
50013
- const packageHasDependency = (projectRoot, dependencyName) => {
50014
- const packageJson = readPackageJson(projectRoot);
50015
- if (!isRecord(packageJson)) return false;
50016
- return [
50017
- "dependencies",
50018
- "devDependencies",
50019
- "optionalDependencies"
50020
- ].some((fieldName) => {
50021
- const dependencies = packageJson[fieldName];
50022
- return isRecord(dependencies) && typeof dependencies[dependencyName] === "string";
50023
- });
50024
- };
50025
- const packageHasRecordKey = (projectRoot, key) => {
50026
- const packageJson = readPackageJson(projectRoot);
50027
- return isRecord(packageJson) && isRecord(packageJson[key]);
50028
- };
50029
- const packageHasNestedRecordKey = (projectRoot, key, nestedKey) => {
50030
- const packageJson = readPackageJson(projectRoot);
50031
- if (!isRecord(packageJson)) return false;
50032
- const value = packageJson[key];
50033
- return isRecord(value) && isRecord(value[nestedKey]);
50034
- };
50035
- const ensureTrailingNewline = (content) => content.endsWith("\n") ? content : `${content}\n`;
50036
- //#endregion
50037
51291
  //#region src/cli/utils/install-doctor-script.ts
50038
51292
  const DOCTOR_SCRIPT_NAME = "doctor";
50039
51293
  const FALLBACK_DOCTOR_SCRIPT_NAME = "react-doctor";
@@ -50059,31 +51313,31 @@ const findNearestPackageDirectory = (startDirectory, stopDirectory) => {
50059
51313
  };
50060
51314
  const hasDoctorScript = (projectRoot) => {
50061
51315
  const packageJson = readPackageJson(findNearestPackageDirectory(projectRoot) ?? projectRoot);
50062
- if (!isRecord(packageJson)) return false;
51316
+ if (!isRecord$1(packageJson)) return false;
50063
51317
  const scripts = packageJson.scripts;
50064
- if (!isRecord(scripts)) return false;
51318
+ if (!isRecord$1(scripts)) return false;
50065
51319
  return isReactDoctorScriptCommand(scripts[DOCTOR_SCRIPT_NAME]) || isReactDoctorScriptCommand(scripts[FALLBACK_DOCTOR_SCRIPT_NAME]);
50066
51320
  };
50067
51321
  const hasDoctorDependency = (packageJson) => DEPENDENCY_FIELD_NAMES.some((fieldName) => {
50068
51322
  const dependencies = packageJson[fieldName];
50069
- return isRecord(dependencies) && Object.hasOwn(dependencies, "react-doctor");
51323
+ return isRecord$1(dependencies) && Object.hasOwn(dependencies, "react-doctor");
50070
51324
  });
50071
51325
  const installDoctorScript = (options) => {
50072
51326
  const packageDirectory = findNearestPackageDirectory(options.projectRoot) ?? options.projectRoot;
50073
51327
  const packageJsonPath = getPackageJsonPath(packageDirectory);
50074
51328
  const packageJson = readPackageJson(packageDirectory);
50075
- if (!isRecord(packageJson)) return {
51329
+ if (!isRecord$1(packageJson)) return {
50076
51330
  packageJsonPath,
50077
51331
  scriptStatus: "skipped",
50078
51332
  scriptReason: "missing-or-invalid-package-json"
50079
51333
  };
50080
51334
  const scripts = packageJson.scripts;
50081
51335
  const scriptTarget = (() => {
50082
- if (scripts !== void 0 && !isRecord(scripts)) return {
51336
+ if (scripts !== void 0 && !isRecord$1(scripts)) return {
50083
51337
  status: "skipped",
50084
51338
  reason: "invalid-scripts"
50085
51339
  };
50086
- const scriptRecord = isRecord(scripts) ? scripts : {};
51340
+ const scriptRecord = isRecord$1(scripts) ? scripts : {};
50087
51341
  if (isReactDoctorScriptCommand(scriptRecord[DOCTOR_SCRIPT_NAME])) return {
50088
51342
  scriptName: DOCTOR_SCRIPT_NAME,
50089
51343
  status: "existing"
@@ -50117,7 +51371,7 @@ const installDoctorScript = (options) => {
50117
51371
  if (scriptStatus === "created") writeJsonFile$1(packageJsonPath, {
50118
51372
  ...packageJson,
50119
51373
  scripts: {
50120
- ...isRecord(scripts) ? scripts : {},
51374
+ ...isRecord$1(scripts) ? scripts : {},
50121
51375
  [scriptTarget.scriptName ?? DOCTOR_SCRIPT_NAME]: DOCTOR_SCRIPT_COMMAND
50122
51376
  }
50123
51377
  });
@@ -50268,40 +51522,27 @@ const upgradeReactDoctorWorkflowInPlace = (projectRoot) => {
50268
51522
  }
50269
51523
  };
50270
51524
  //#endregion
50271
- //#region src/cli/utils/hash-project-root.ts
50272
- const hashProjectRoot = (projectRoot) => createHash("sha256").update(Path.resolve(projectRoot)).digest("hex");
50273
- //#endregion
50274
51525
  //#region src/cli/utils/action-upgrade-prompt.ts
50275
- const GLOBAL_CONFIG_PROJECT_NAME$1 = "react-doctor";
50276
- const getActionUpgradeStore = (options = {}) => new Conf({
50277
- projectName: GLOBAL_CONFIG_PROJECT_NAME$1,
50278
- cwd: options.cwd
50279
- });
50280
- const hasHandledActionUpgrade = (projectRoot, storeOptions = {}) => {
50281
- try {
50282
- const upgrades = getActionUpgradeStore(storeOptions).get("actionUpgrades", {});
50283
- return Boolean(upgrades[hashProjectRoot(projectRoot)]);
50284
- } catch {
50285
- return true;
50286
- }
50287
- };
50288
- const recordActionUpgradeDecision = (projectRoot, outcome, storeOptions = {}) => {
50289
- try {
50290
- const store = getActionUpgradeStore(storeOptions);
50291
- const upgrades = store.get("actionUpgrades", {});
50292
- store.set("actionUpgrades", {
50293
- ...upgrades,
50294
- [hashProjectRoot(projectRoot)]: {
50295
- rootDirectory: Path.resolve(projectRoot),
50296
- outcome,
50297
- at: (/* @__PURE__ */ new Date()).toISOString()
50298
- }
50299
- });
50300
- return true;
50301
- } catch {
50302
- return false;
50303
- }
50304
- };
51526
+ const ACTION_UPGRADE_GATE = {
51527
+ id: ACTION_UPGRADE_EVENT,
51528
+ scope: "project"
51529
+ };
51530
+ const hasHandledActionUpgrade = (projectRoot, options = {}) => !isGatePending(ACTION_UPGRADE_GATE, { projectRoot }, options);
51531
+ const recordActionUpgradeDecision = (projectRoot, outcome, options = {}) => recordGate(ACTION_UPGRADE_GATE, {
51532
+ projectRoot,
51533
+ outcome
51534
+ }, options);
51535
+ //#endregion
51536
+ //#region src/cli/utils/ci-prompt-decision.ts
51537
+ const CI_PITCH_GATE = {
51538
+ id: CI_PITCH_EVENT,
51539
+ scope: "project"
51540
+ };
51541
+ const hasHandledCiPrompt = (projectRoot, options = {}) => !isGatePending(CI_PITCH_GATE, { projectRoot }, options);
51542
+ const recordCiPromptDecision = (projectRoot, outcome, options = {}) => recordGate(CI_PITCH_GATE, {
51543
+ projectRoot,
51544
+ outcome
51545
+ }, options);
50305
51546
  //#endregion
50306
51547
  //#region src/cli/utils/open-url.ts
50307
51548
  const resolveOpenCommand = (url) => {
@@ -50467,39 +51708,80 @@ const DEFAULT_PR_TITLE = "Add React Doctor to GitHub Actions";
50467
51708
  const DEFAULT_PR_BODY = `Adds a [React Doctor](https://www.react.doctor) scan to every pull request and every push to the default branch. The workflow file is documented inline.
50468
51709
 
50469
51710
  Docs: https://www.react.doctor/ci`;
50470
- const findUniqueBranchName = async (cwd) => {
50471
- if (!(await runCommand("git", [
51711
+ const findUniqueBranchName = async (cwd, run) => {
51712
+ if (!(await run("git", [
50472
51713
  "rev-parse",
50473
51714
  "--verify",
50474
51715
  NEW_BRANCH_PREFIX
50475
51716
  ], cwd)).success) return NEW_BRANCH_PREFIX;
50476
51717
  return `${NEW_BRANCH_PREFIX}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 16).replace(/[-:T]/g, "")}`;
50477
51718
  };
51719
+ const findExistingSetupPullRequest = async (cwd, run) => {
51720
+ const prList = await run("gh", [
51721
+ "pr",
51722
+ "list",
51723
+ "--state",
51724
+ "open",
51725
+ "--json",
51726
+ "headRefName,url",
51727
+ "--limit",
51728
+ String(100)
51729
+ ], cwd);
51730
+ if (!prList.success) return null;
51731
+ try {
51732
+ return JSON.parse(prList.stdout).find((pullRequest) => (pullRequest.headRefName ?? "").startsWith(NEW_BRANCH_PREFIX)) ?? null;
51733
+ } catch {
51734
+ return null;
51735
+ }
51736
+ };
51737
+ const hasUnrelatedTrackedChanges = async (cwd, workflowRelative, run) => {
51738
+ const statusProbe = await run("git", [
51739
+ "status",
51740
+ "--porcelain",
51741
+ "--",
51742
+ ".",
51743
+ `:!${workflowRelative}`
51744
+ ], cwd);
51745
+ if (!statusProbe.success) return true;
51746
+ return statusProbe.stdout.split(/\r?\n/).filter(Boolean).some((statusLine) => !statusLine.startsWith("??"));
51747
+ };
50478
51748
  const openWorkflowPullRequest = async (params) => {
50479
51749
  const workflowPath = Path.resolve(params.workflowPath);
50480
51750
  const commitMessage = params.commitMessage ?? DEFAULT_COMMIT_MESSAGE;
50481
51751
  const prTitle = params.prTitle ?? DEFAULT_PR_TITLE;
50482
51752
  const prBody = params.prBody ?? DEFAULT_PR_BODY;
50483
- const repoRootProbe = await runCommand("git", ["rev-parse", "--show-toplevel"], Path.dirname(workflowPath));
51753
+ const run = params.run ?? runCommand;
51754
+ const checkCommandAvailable = params.checkCommandAvailable ?? isCommandAvailable;
51755
+ const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], Path.dirname(workflowPath));
50484
51756
  if (!repoRootProbe.success) return {
50485
51757
  status: "not-attempted",
50486
51758
  reason: "not-a-git-repo"
50487
51759
  };
50488
51760
  const cwd = repoRootProbe.stdout;
50489
- if (!isCommandAvailable("gh")) return {
51761
+ const workflowRelative = toForwardSlashes(Path.relative(cwd, workflowPath));
51762
+ if (!checkCommandAvailable("gh")) return {
50490
51763
  status: "not-attempted",
50491
51764
  reason: "gh-not-installed"
50492
51765
  };
50493
- if (!(await runCommand("gh", ["auth", "status"], cwd)).success) return {
51766
+ if (!(await run("gh", ["auth", "status"], cwd)).success) return {
50494
51767
  status: "not-attempted",
50495
51768
  reason: "gh-not-authenticated"
50496
51769
  };
50497
- const defaultBranch = params.baseBranch ?? await detectDefaultBranch(cwd);
51770
+ const existingSetupPullRequest = await findExistingSetupPullRequest(cwd, run);
51771
+ if (existingSetupPullRequest) return {
51772
+ status: "pr-exists",
51773
+ url: existingSetupPullRequest.url ?? ""
51774
+ };
51775
+ if (await hasUnrelatedTrackedChanges(cwd, workflowRelative, run)) return {
51776
+ status: "not-attempted",
51777
+ reason: "working-tree-dirty"
51778
+ };
51779
+ const defaultBranch = params.baseBranch ?? await detectDefaultBranch(cwd, run);
50498
51780
  if (!defaultBranch) return {
50499
51781
  status: "not-attempted",
50500
51782
  reason: "no-default-branch"
50501
51783
  };
50502
- const previousBranchProbe = await runCommand("git", [
51784
+ const previousBranchProbe = await run("git", [
50503
51785
  "rev-parse",
50504
51786
  "--abbrev-ref",
50505
51787
  "HEAD"
@@ -50509,13 +51791,13 @@ const openWorkflowPullRequest = async (params) => {
50509
51791
  reason: "detached-head"
50510
51792
  };
50511
51793
  const previousBranch = previousBranchProbe.stdout;
50512
- await runCommand("git", [
51794
+ await run("git", [
50513
51795
  "fetch",
50514
51796
  "origin",
50515
51797
  defaultBranch
50516
51798
  ], cwd);
50517
- const newBranch = await findUniqueBranchName(cwd);
50518
- if (!(await runCommand("git", [
51799
+ const newBranch = await findUniqueBranchName(cwd, run);
51800
+ if (!(await run("git", [
50519
51801
  "checkout",
50520
51802
  "-b",
50521
51803
  newBranch,
@@ -50525,17 +51807,17 @@ const openWorkflowPullRequest = async (params) => {
50525
51807
  reason: "checkout-failed"
50526
51808
  };
50527
51809
  const restoreToPreviousBranch = async (deleteNewBranch) => {
50528
- await runCommand("git", ["checkout", previousBranch], cwd);
50529
- if (deleteNewBranch) await runCommand("git", [
51810
+ await run("git", ["checkout", previousBranch], cwd);
51811
+ if (deleteNewBranch) await run("git", [
50530
51812
  "branch",
50531
51813
  "-D",
50532
51814
  newBranch
50533
51815
  ], cwd);
50534
51816
  };
50535
- if (!(await runCommand("git", [
51817
+ if (!(await run("git", [
50536
51818
  "add",
50537
51819
  "--",
50538
- Path.relative(cwd, workflowPath)
51820
+ workflowRelative
50539
51821
  ], cwd)).success) {
50540
51822
  await restoreToPreviousBranch(true);
50541
51823
  return {
@@ -50543,7 +51825,7 @@ const openWorkflowPullRequest = async (params) => {
50543
51825
  reason: "git-add-failed"
50544
51826
  };
50545
51827
  }
50546
- if (!(await runCommand("git", [
51828
+ if (!(await run("git", [
50547
51829
  "commit",
50548
51830
  "-m",
50549
51831
  commitMessage
@@ -50554,7 +51836,7 @@ const openWorkflowPullRequest = async (params) => {
50554
51836
  reason: "git-commit-failed"
50555
51837
  };
50556
51838
  }
50557
- if (!(await runCommand("git", [
51839
+ if (!(await run("git", [
50558
51840
  "push",
50559
51841
  "-u",
50560
51842
  "origin",
@@ -50566,7 +51848,7 @@ const openWorkflowPullRequest = async (params) => {
50566
51848
  reason: "git-push-failed"
50567
51849
  };
50568
51850
  }
50569
- const prCreate = await runCommand("gh", [
51851
+ const prCreate = await run("gh", [
50570
51852
  "pr",
50571
51853
  "create",
50572
51854
  "--title",
@@ -50590,12 +51872,13 @@ const openWorkflowPullRequest = async (params) => {
50590
51872
  };
50591
51873
  const stageWorkflowFile = async (params) => {
50592
51874
  const workflowPath = Path.resolve(params.workflowPath);
50593
- const repoRootProbe = await runCommand("git", ["rev-parse", "--show-toplevel"], Path.dirname(workflowPath));
51875
+ const run = params.run ?? runCommand;
51876
+ const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], Path.dirname(workflowPath));
50594
51877
  if (!repoRootProbe.success) return false;
50595
- return (await runCommand("git", [
51878
+ return (await run("git", [
50596
51879
  "add",
50597
51880
  "--",
50598
- Path.relative(repoRootProbe.stdout, workflowPath)
51881
+ toForwardSlashes(Path.relative(repoRootProbe.stdout, workflowPath))
50599
51882
  ], repoRootProbe.stdout)).success;
50600
51883
  };
50601
51884
  //#endregion
@@ -50636,6 +51919,7 @@ const setUpGitHubActions = async (options) => {
50636
51919
  baseBranch: defaultBranch
50637
51920
  });
50638
51921
  if (pullRequestResult.status === "pr-opened") pullRequestSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
51922
+ else if (pullRequestResult.status === "pr-exists") pullRequestSpinner.succeed(`A React Doctor setup pull request is already open: ${highlighter.info(pullRequestResult.url)}`);
50639
51923
  else if (pullRequestResult.status === "branch-pushed") pullRequestSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
50640
51924
  else {
50641
51925
  pullRequestSpinner.stop();
@@ -50758,22 +52042,22 @@ const buildAgentHookScript = () => [
50758
52042
  "",
50759
52043
  "run_react_doctor() {",
50760
52044
  " if [ -x ./node_modules/.bin/react-doctor ]; then",
50761
- " ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
52045
+ " ./node_modules/.bin/react-doctor --verbose --scope changed --blocking warning --no-score",
50762
52046
  " return",
50763
52047
  " fi",
50764
52048
  "",
50765
52049
  " if command -v react-doctor >/dev/null 2>&1; then",
50766
- " react-doctor --verbose --diff --blocking warning --no-score",
52050
+ " react-doctor --verbose --scope changed --blocking warning --no-score",
50767
52051
  " return",
50768
52052
  " fi",
50769
52053
  "",
50770
52054
  " if command -v pnpm >/dev/null 2>&1; then",
50771
- " pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
52055
+ " pnpm dlx react-doctor@latest --verbose --scope changed --blocking warning --no-score",
50772
52056
  " return",
50773
52057
  " fi",
50774
52058
  "",
50775
52059
  " if command -v npx >/dev/null 2>&1; then",
50776
- " npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
52060
+ " npx --yes react-doctor@latest --verbose --scope changed --blocking warning --no-score",
50777
52061
  " return",
50778
52062
  " fi",
50779
52063
  "",
@@ -50931,13 +52215,13 @@ const installPackageJsonHook = (options, strategy) => {
50931
52215
  const packageJsonPath = getPackageJsonPath(options.projectRoot);
50932
52216
  const didHookExist = NFS.existsSync(packageJsonPath);
50933
52217
  const packageJson = readPackageJson(options.projectRoot);
50934
- const nextPackageJson = isRecord(packageJson) ? { ...packageJson } : {};
52218
+ const nextPackageJson = isRecord$1(packageJson) ? { ...packageJson } : {};
50935
52219
  const parentKeys = strategy.path.slice(0, -1);
50936
52220
  const leafKey = strategy.path[strategy.path.length - 1];
50937
52221
  let parent = nextPackageJson;
50938
52222
  for (const key of parentKeys) {
50939
52223
  const existing = parent[key];
50940
- const cloned = isRecord(existing) ? { ...existing } : {};
52224
+ const cloned = isRecord$1(existing) ? { ...existing } : {};
50941
52225
  parent[key] = cloned;
50942
52226
  parent = cloned;
50943
52227
  }
@@ -51108,7 +52392,7 @@ const isHuskyProject = (projectRoot) => NFS.existsSync(Path.join(projectRoot, ".
51108
52392
  const isVitePlusProject = (projectRoot) => packageHasDependency(projectRoot, "vite-plus");
51109
52393
  const isSimpleGitHooksProject = (projectRoot) => {
51110
52394
  const packageJson = readPackageJson(projectRoot);
51111
- return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || NFS.existsSync(Path.join(projectRoot, ".simple-git-hooks.cjs"));
52395
+ return isRecord$1(packageJson) && isRecord$1(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || NFS.existsSync(Path.join(projectRoot, ".simple-git-hooks.cjs"));
51112
52396
  };
51113
52397
  const getLefthookConfigPath = (projectRoot) => {
51114
52398
  for (const fileName of LEFTHOOK_CONFIG_FILES) {
@@ -51274,7 +52558,7 @@ const detectPackageManager = (projectRoot) => {
51274
52558
  let currentDirectory = Path.resolve(projectRoot);
51275
52559
  while (true) {
51276
52560
  const packageJson = readPackageJson(currentDirectory);
51277
- if (isRecord(packageJson) && typeof packageJson.packageManager === "string") {
52561
+ if (isRecord$1(packageJson) && typeof packageJson.packageManager === "string") {
51278
52562
  const packageManagerName = packageJson.packageManager.split("@")[0];
51279
52563
  if (packageManagerName === "pnpm" || packageManagerName === "yarn" || packageManagerName === "bun" || packageManagerName === "npm") return packageManagerName;
51280
52564
  }
@@ -51350,12 +52634,12 @@ const isSupplyChainTrustError = (error) => {
51350
52634
  const formatInstallCommand = (input) => [input.command, ...input.args].join(" ");
51351
52635
  const installReactDoctorDependency = async (options) => {
51352
52636
  const packageJson = readPackageJson(options.projectRoot);
51353
- if (!isRecord(packageJson)) return {
52637
+ if (!isRecord$1(packageJson)) return {
51354
52638
  dependencyStatus: "skipped",
51355
52639
  dependencyReason: "missing-or-invalid-package-json"
51356
52640
  };
51357
52641
  if (hasDoctorDependency(packageJson)) return { dependencyStatus: "existing" };
51358
- if (packageJson.devDependencies !== void 0 && !isRecord(packageJson.devDependencies)) return {
52642
+ if (packageJson.devDependencies !== void 0 && !isRecord$1(packageJson.devDependencies)) return {
51359
52643
  dependencyStatus: "skipped",
51360
52644
  dependencyReason: "invalid-dev-dependencies"
51361
52645
  };
@@ -51519,10 +52803,12 @@ const runInstallReactDoctor = async (options = {}) => {
51519
52803
  const existingWorkflow = readReactDoctorWorkflow(projectRoot);
51520
52804
  const canInstallWorkflow = !NFS.existsSync(workflowTargetPath);
51521
52805
  const canUpgradeWorkflow = existingWorkflow !== null && workflowUsesV1Action(existingWorkflow.content) && !hasHandledActionUpgrade(projectRoot);
51522
- const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !skipPrompts && await askAddToGitHubActions(prompt) === "yes");
52806
+ const ciPromptOutcome = canInstallWorkflow && !options.yes && !skipPrompts && !hasHandledCiPrompt(projectRoot) ? await askAddToGitHubActions(prompt) : null;
52807
+ const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || ciPromptOutcome === "yes");
51523
52808
  const upgradePromptOutcome = canUpgradeWorkflow && !options.yes && !skipPrompts ? await askUpgradeActionVersion(prompt) : null;
51524
52809
  const shouldUpgradeWorkflow = canUpgradeWorkflow && (Boolean(options.yes) || upgradePromptOutcome === "yes");
51525
52810
  if (upgradePromptOutcome === "no" && !options.dryRun) recordActionUpgradeDecision(projectRoot, "declined");
52811
+ if ((ciPromptOutcome === "yes" || ciPromptOutcome === "no") && !options.dryRun) recordCiPromptDecision(projectRoot, ciPromptOutcome === "yes" ? "accepted" : "declined");
51526
52812
  const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
51527
52813
  type: "multiselect",
51528
52814
  name: "agents",
@@ -51734,7 +53020,12 @@ const upgradeGitHubActionsWorkflow = async (workflow) => {
51734
53020
  prBody: UPGRADE_PR_BODY
51735
53021
  });
51736
53022
  if (pullRequestResult.status === "pr-opened") upgradeSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
51737
- else if (pullRequestResult.status === "branch-pushed") upgradeSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
53023
+ else if (pullRequestResult.status === "pr-exists") {
53024
+ try {
53025
+ NFS.writeFileSync(workflow.workflowPath, workflow.content);
53026
+ } catch {}
53027
+ upgradeSpinner.succeed(`A React Doctor pull request is already open: ${highlighter.info(pullRequestResult.url)}`);
53028
+ } else if (pullRequestResult.status === "branch-pushed") upgradeSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
51738
53029
  else {
51739
53030
  upgradeSpinner.stop();
51740
53031
  try {
@@ -51769,18 +53060,24 @@ const handoffToAgent = async (input) => {
51769
53060
  if (!input.interactive || input.diagnostics.length === 0) return;
51770
53061
  cliLogger.break();
51771
53062
  const projectRootForCi = findNearestPackageDirectory(input.rootDirectory) ?? input.rootDirectory;
51772
- if (!isReactDoctorWorkflowInstalled(projectRootForCi)) {
53063
+ const isGitHubActionsConfigured = isReactDoctorWorkflowInstalled(projectRootForCi);
53064
+ if (!isGitHubActionsConfigured && !hasHandledCiPrompt(projectRootForCi)) {
51773
53065
  const ciOutcome = await askAddToGitHubActions();
51774
53066
  recordCount(METRIC.agentHandoff, 1, {
51775
53067
  outcome: `ci-${ciOutcome}`,
51776
53068
  diagnosticsCount: input.diagnostics.length
51777
53069
  });
51778
53070
  if (ciOutcome === "cancel") return;
53071
+ recordCiPromptDecision(projectRootForCi, ciOutcome === "yes" ? "accepted" : "declined");
51779
53072
  if (ciOutcome === "yes") {
51780
53073
  await setUpGitHubActions({ rootDirectory: input.rootDirectory });
51781
53074
  cliLogger.break();
51782
53075
  }
51783
- } else await maybeOfferActionUpgrade(projectRootForCi);
53076
+ } else if (isGitHubActionsConfigured) await maybeOfferActionUpgrade(projectRootForCi);
53077
+ else recordCount(METRIC.agentHandoff, 1, {
53078
+ outcome: "ci-suppressed",
53079
+ diagnosticsCount: input.diagnostics.length
53080
+ });
51784
53081
  const { handoffTarget } = await prompts({
51785
53082
  type: "select",
51786
53083
  name: "handoffTarget",
@@ -51842,6 +53139,47 @@ const handoffToAgent = async (input) => {
51842
53139
  }
51843
53140
  };
51844
53141
  //#endregion
53142
+ //#region src/cli/utils/migrate-action-pin.ts
53143
+ const WORKFLOWS_DIRECTORY = Path.join(".github", "workflows");
53144
+ const RECOMMENDED_ACTION_REF = "v2";
53145
+ const MUTABLE_ACTION_REF = /(uses:\s*[\w.-]+\/react-doctor@)(?:main|master)\b/g;
53146
+ const isWorkflowFile = (fileName) => /\.ya?ml$/.test(fileName);
53147
+ /**
53148
+ * Rewrites mutable `@main` / `@master` React Doctor GitHub Action references in
53149
+ * the repo's `.github/workflows/*.yml` to the recommended floating major
53150
+ * (`@v2`) — a supply-chain hardening (#299) that also moves the workflow onto
53151
+ * the current (install- and scan-cached) action release. Pinned tags / SHAs are
53152
+ * deliberate and left untouched. Returns the absolute paths of the workflow
53153
+ * files it rewrote — empty when there's nothing to migrate.
53154
+ */
53155
+ const migrateActionPin = (projectRoot) => {
53156
+ const workflowsDirectory = Path.join(projectRoot, WORKFLOWS_DIRECTORY);
53157
+ let entries;
53158
+ try {
53159
+ entries = NFS.readdirSync(workflowsDirectory, { withFileTypes: true });
53160
+ } catch {
53161
+ return [];
53162
+ }
53163
+ const rewrittenFiles = [];
53164
+ for (const entry of entries) {
53165
+ if (!entry.isFile() || !isWorkflowFile(entry.name)) continue;
53166
+ const workflowPath = Path.join(workflowsDirectory, entry.name);
53167
+ let contents;
53168
+ try {
53169
+ contents = NFS.readFileSync(workflowPath, "utf-8");
53170
+ } catch {
53171
+ continue;
53172
+ }
53173
+ const updated = contents.replace(MUTABLE_ACTION_REF, `$1${RECOMMENDED_ACTION_REF}`);
53174
+ if (updated === contents) continue;
53175
+ try {
53176
+ NFS.writeFileSync(workflowPath, updated);
53177
+ rewrittenFiles.push(workflowPath);
53178
+ } catch {}
53179
+ }
53180
+ return rewrittenFiles;
53181
+ };
53182
+ //#endregion
51845
53183
  //#region src/cli/utils/read-object-file.ts
51846
53184
  /**
51847
53185
  * Reads a JSON / JSONC file as a plain object, or `null` when it is missing,
@@ -51906,6 +53244,35 @@ export default ${serializeTsObjectLiteral(config)} satisfies ReactDoctorConfig;
51906
53244
  NFS.rmSync(legacy.legacyFilePath, { force: true });
51907
53245
  return targetPath;
51908
53246
  };
53247
+ const PROJECT_MIGRATIONS = [{
53248
+ id: "config-json-to-ts",
53249
+ scope: "project",
53250
+ run: ({ projectRoot }) => {
53251
+ if (projectRoot === void 0) return false;
53252
+ const legacyConfig = findLegacyConfig(projectRoot);
53253
+ if (!legacyConfig) return false;
53254
+ const migratedPath = migrateLegacyConfig(legacyConfig);
53255
+ if (!migratedPath) return false;
53256
+ cliLogger.success("Migrated react-doctor.config.json → doctor.config.ts");
53257
+ cliLogger.dim(` Your settings were preserved. Review ${toRelativePath(migratedPath, projectRoot)} and commit it.`);
53258
+ cliLogger.break();
53259
+ return true;
53260
+ }
53261
+ }, {
53262
+ id: "action-pin-main-to-v2",
53263
+ scope: "project",
53264
+ run: ({ projectRoot }) => {
53265
+ if (projectRoot === void 0) return false;
53266
+ const rewrittenFiles = migrateActionPin(projectRoot);
53267
+ if (rewrittenFiles.length === 0) return false;
53268
+ const relativeFiles = rewrittenFiles.map((file) => toRelativePath(file, projectRoot)).join(", ");
53269
+ cliLogger.success(`Pinned the React Doctor action to @v2 in ${relativeFiles}`);
53270
+ cliLogger.dim(" An unpinned @main reference runs whatever the action's HEAD points to (a supply-chain risk). Review and commit the change — or revert it if you intentionally track main.");
53271
+ cliLogger.break();
53272
+ return true;
53273
+ }
53274
+ }];
53275
+ const runProjectMigrations = (projectRoot, options = {}) => runMigrations(PROJECT_MIGRATIONS, { projectRoot }, options);
51909
53276
  //#endregion
51910
53277
  //#region src/cli/utils/print-branded-header.ts
51911
53278
  /**
@@ -52003,6 +53370,7 @@ const reportErrorToSentry = async (error) => {
52003
53370
  sampled: runTrace.sampled,
52004
53371
  sampleRand: Math.random()
52005
53372
  });
53373
+ recordRunTraceId(scope.getPropagationContext().traceId);
52006
53374
  return Sentry.captureException(error);
52007
53375
  });
52008
53376
  await Sentry.flush(SENTRY_FLUSH_TIMEOUT_MS);
@@ -52086,7 +53454,7 @@ const printMultiProjectSummary = (input) => gen(function* () {
52086
53454
  yield* log(`${highlighter.success("✔")} Scanned ${totalScannedFileCount} ${totalScannedFileCount === 1 ? "file" : "files"} in ${formatElapsedTime(totalElapsedMilliseconds)}`);
52087
53455
  if (displayDiagnostics.length > 0) {
52088
53456
  yield* log("");
52089
- yield* printDiagnostics(displayDiagnostics, verbose, resolveDiagnosticSourceRoot, buildRulePriorityMap(completedScans.map((scan) => scan.result.score)), isCodingAgentEnvironment(), { animateCountUp: animateRender });
53457
+ yield* printDiagnostics(displayDiagnostics, verbose, resolveDiagnosticSourceRoot, buildRulePriorityMap(completedScans.map((scan) => scan.result.score)), isCodingAgentEnvironment(), { animateCountUp: animateRender }, shouldRenderHyperlinks(process.stdout));
52090
53458
  }
52091
53459
  const lowestScoredScan = findLowestScoredScan(completedScans);
52092
53460
  const aggregateScore = lowestScoredScan?.result.score ?? null;
@@ -52124,19 +53492,16 @@ const printMultiProjectSummary = (input) => gen(function* () {
52124
53492
  });
52125
53493
  //#endregion
52126
53494
  //#region src/cli/utils/prompt-install-setup.ts
52127
- const GLOBAL_CONFIG_PROJECT_NAME = "react-doctor";
52128
- const getSetupPromptStore = (options = {}) => new Conf({
52129
- projectName: GLOBAL_CONFIG_PROJECT_NAME,
52130
- cwd: options.cwd
52131
- });
52132
- const getSetupPromptProjectKey = (projectRoot) => hashProjectRoot(projectRoot);
52133
- const hasDisabledSetupPrompt = (projectRoot, storeOptions = {}) => {
52134
- try {
52135
- return getSetupPromptStore(storeOptions).get("projects", {})[getSetupPromptProjectKey(projectRoot)]?.setupPrompt === false;
52136
- } catch {
52137
- return false;
52138
- }
52139
- };
53495
+ const SETUP_HINT_GATE = {
53496
+ id: SETUP_HINT_EVENT,
53497
+ scope: "project",
53498
+ fireWhenUnknown: true
53499
+ };
53500
+ const hasDisabledSetupPrompt = (projectRoot, options = {}) => !isGatePending(SETUP_HINT_GATE, { projectRoot }, options);
53501
+ const disableSetupPrompt = (projectRoot, options = {}) => recordGate(SETUP_HINT_GATE, {
53502
+ projectRoot,
53503
+ outcome: "declined"
53504
+ }, options);
52140
53505
  const resolveInstallSetupProjectRoot = (options) => {
52141
53506
  if (options.scanDirectories.length === 0) return findNearestPackageDirectory(options.scanRoot) ?? options.scanRoot;
52142
53507
  const packageDirectories = /* @__PURE__ */ new Set();
@@ -52543,6 +53908,14 @@ const runExplain = async (fileLineArgument, context) => {
52543
53908
  const colorizedRule = colorizeRuleByDiagnostic(ruleIdentifier, diagnostic.severity);
52544
53909
  const severityLabel = colorizeRuleByDiagnostic(diagnostic.severity, diagnostic.severity);
52545
53910
  cliLogger.log(`${severitySymbol} ${colorizedRule} ${highlighter.dim(`(${severityLabel})`)} — ${diagnostic.message}`);
53911
+ const codeFrame = buildCodeFrame({
53912
+ filePath: diagnostic.filePath,
53913
+ line: diagnostic.line,
53914
+ column: diagnostic.column,
53915
+ endLine: diagnostic.endLine,
53916
+ rootDirectory: targetDirectory
53917
+ });
53918
+ if (codeFrame) cliLogger.log(indentMultilineText(codeFrame, " "));
52546
53919
  if (diagnostic.category) cliLogger.dim(` Category: ${diagnostic.category}`);
52547
53920
  if (diagnostic.help) cliLogger.dim(` ${diagnostic.help}`);
52548
53921
  cliLogger.dim(` If this needs follow-up or looks like a false positive, open: ${buildDiagnosticIssueUrl({
@@ -52592,6 +53965,10 @@ const validateModeFlags = (flags) => {
52592
53965
  if (flags.staged && (flags.scope === "full" || flags.scope === "changed")) throw new CliInputError(`Cannot combine --staged with --scope ${flags.scope}; use --scope files or --scope lines, or drop --scope.`);
52593
53966
  if (flags.score && flags.json) throw new CliInputError("Cannot combine --score and --json; pick one output mode.");
52594
53967
  if (flags.score && flags.telemetry === false) throw new CliInputError("Cannot combine --score with --no-telemetry; --score prints the score that --no-telemetry disables.");
53968
+ if (flags.debug && (flags.score === false || flags.telemetry === false)) {
53969
+ const disablingFlag = flags.score === false ? "--no-score" : "--no-telemetry";
53970
+ throw new CliInputError(`Cannot combine --debug with ${disablingFlag}; ${disablingFlag} disables the Sentry reporting --debug needs to capture a trace.`);
53971
+ }
52595
53972
  };
52596
53973
  //#endregion
52597
53974
  //#region src/cli/commands/inspect.ts
@@ -52652,15 +54029,9 @@ const buildChangedFilesDiffInfo = (changedFiles) => ({
52652
54029
  * are left untouched — the loader still reads the legacy file as a deprecated
52653
54030
  * fallback and warns — so a scan never mutates the repo unattended.
52654
54031
  */
52655
- const maybeMigrateLegacyConfig = (requestedDirectory, { isQuiet, isStaged }) => {
54032
+ const maybeMigrateLegacyConfig = async (requestedDirectory, { isQuiet, isStaged }) => {
52656
54033
  if (!(!isQuiet && !isStaged && process.stdout.isTTY === true && !isCiOrCodingAgentEnvironment())) return;
52657
- const legacyConfig = findLegacyConfig(requestedDirectory);
52658
- if (!legacyConfig) return;
52659
- const migratedPath = migrateLegacyConfig(legacyConfig);
52660
- if (!migratedPath) return;
52661
- cliLogger.success("Migrated react-doctor.config.json → doctor.config.ts");
52662
- cliLogger.dim(` Your settings were preserved. Review ${toRelativePath(migratedPath, requestedDirectory)} and commit it.`);
52663
- cliLogger.break();
54034
+ await runProjectMigrations(requestedDirectory);
52664
54035
  };
52665
54036
  const inspectAction = async (directory, flags) => {
52666
54037
  const isScoreOnly = Boolean(flags.score);
@@ -52675,7 +54046,7 @@ const inspectAction = async (directory, flags) => {
52675
54046
  recordCount(METRIC.cliInvoked, 1, { command: "inspect" });
52676
54047
  try {
52677
54048
  validateModeFlags(flags);
52678
- maybeMigrateLegacyConfig(requestedDirectory, {
54049
+ await maybeMigrateLegacyConfig(requestedDirectory, {
52679
54050
  isQuiet,
52680
54051
  isStaged: Boolean(flags.staged)
52681
54052
  });
@@ -52939,11 +54310,13 @@ const inspectAction = async (directory, flags) => {
52939
54310
  })) {
52940
54311
  printAgentInstallHint();
52941
54312
  recordCount(METRIC.agentInstallHintShown, 1);
54313
+ disableSetupPrompt(setupProjectRoot);
52942
54314
  }
52943
54315
  }
52944
54316
  } catch (error) {
52945
54317
  const isUserError = isExpectedUserError(error);
52946
54318
  const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
54319
+ if (isDebugFlagEnabled()) await flushSentry();
52947
54320
  if (isJsonMode) {
52948
54321
  writeJsonErrorReport(error, sentryEventId);
52949
54322
  process.exitCode = 1;
@@ -53666,6 +55039,33 @@ const normalizeHelpInvocation = (argv, knownCommands) => {
53666
55039
  return [...nodeArguments, "--help"];
53667
55040
  };
53668
55041
  //#endregion
55042
+ //#region src/cli/utils/print-debug-trace.ts
55043
+ /**
55044
+ * The `--debug` end-of-run line, pure so it's testable without the Sentry SDK.
55045
+ * Mirrors the crash-reference phrasing in `handle-error.ts` ("mention this when
55046
+ * reporting") so users learn one habit for both paths. A `null` trace says why,
55047
+ * so `--debug` never silently does nothing.
55048
+ */
55049
+ const buildDebugTraceMessage = (traceId) => traceId === null ? "Sentry trace unavailable for this run (no trace was recorded)." : `Sentry trace (mention this when reporting): ${traceId}`;
55050
+ /**
55051
+ * Prints the run's Sentry trace id to stderr at the end of a `--debug` run, so
55052
+ * maintainers can pull the full trace from a pasted id. Runs from the process
55053
+ * `exit` handler, so it's the last line on both the success path and the error
55054
+ * funnels (which `process.exit()` before the promise chain could resume).
55055
+ *
55056
+ * Writes straight to `process.stderr` (not `Console`) for three reasons: the
55057
+ * exit handler is synchronous, JSON mode patches the global console to no-ops —
55058
+ * a diagnostic the user explicitly asked for must survive that — and stderr
55059
+ * keeps `--json` / `--score` stdout machine-clean. The write is wrapped because
55060
+ * a diagnostic must never throw out of an exit handler.
55061
+ */
55062
+ const printDebugTrace = () => {
55063
+ if (!Sentry.isInitialized()) return;
55064
+ try {
55065
+ process.stderr.write(`${highlighter.dim(buildDebugTraceMessage(getLastRunTraceId()))}\n`);
55066
+ } catch {}
55067
+ };
55068
+ //#endregion
53669
55069
  //#region src/cli/utils/removed-cli-flags.ts
53670
55070
  const REMOVED_FLAGS = new Map([
53671
55071
  ["--full", "use `--diff false` to force a full scan"],
@@ -53692,6 +55092,7 @@ const ROOT_FLAG_SPEC = {
53692
55092
  longOptionsWithoutValues: new Set([
53693
55093
  "--color",
53694
55094
  "--dead-code",
55095
+ "--debug",
53695
55096
  "--help",
53696
55097
  "--json",
53697
55098
  "--json-compact",
@@ -53859,6 +55260,9 @@ const stripUnknownCliFlags = (argv) => {
53859
55260
  initializeSentry();
53860
55261
  process.on("SIGINT", exitGracefully);
53861
55262
  process.on("SIGTERM", exitGracefully);
55263
+ process.on("exit", () => {
55264
+ if (isDebugFlagEnabled()) printDebugTrace();
55265
+ });
53862
55266
  unrefStdin();
53863
55267
  guardStdin();
53864
55268
  const formatExampleLines = (examples) => {
@@ -53870,7 +55274,7 @@ ${highlighter.dim("Examples:")}
53870
55274
  ${formatExampleLines([
53871
55275
  ["react-doctor", "scan the current project"],
53872
55276
  ["react-doctor ./apps/web", "scan a specific directory"],
53873
- ["react-doctor --diff main", "scan only files changed vs. main"],
55277
+ ["react-doctor --scope changed --base main", "scan only new issues vs. main"],
53874
55278
  ["react-doctor --project modules/a,modules/b", "score each module separately (names or paths)"],
53875
55279
  ["react-doctor --staged", "scan staged files (pre-commit hook)"],
53876
55280
  ["react-doctor --category Security", "show only one diagnostic category"],
@@ -53903,7 +55307,7 @@ ${highlighter.dim("Learn more:")}
53903
55307
  ${highlighter.info(CANONICAL_GITHUB_URL)}
53904
55308
  `;
53905
55309
  const collectCategoryOption = (value, previousValues) => [...previousValues ?? [], value];
53906
- const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--output-dir <dir>", "directory for the full diagnostics dump (default: a temp folder)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--no-parallel", "lint serially with one worker (default: parallel across CPU cores; set the worker count with REACT_DOCTOR_PARALLEL)").option("--project <name>", "select projects: workspace names or directory paths (comma-separated for multiple); overrides the `projects` config field").option("--scope <value>", "how much to scan/report: full (default), files, changed (only new issues vs base), or lines (only changed lines)").option("--base <ref>", "base git ref for files/changed/lines scope (auto-detected when omitted)").addOption(new Option("--diff [base]", "[deprecated] alias for --scope changed (pass `false` to force a full scan)").hideHelp()).addOption(new Option("--changed-files-from <file>", "scan source files listed in a newline-delimited changed-files file").hideHelp()).option("--no-score", "skip the score API, the share URL, and crash reporting").addOption(new Option("--category <category>", "only show diagnostics in a category (repeatable; e.g. Security)").argParser(collectCategoryOption)).option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--blocking <level>", "severity that fails CI: error (default), warning, or none (advisory)").addOption(new Option("--fail-on <level>", "[deprecated] alias for --blocking <level>").hideHelp()).option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
55310
+ const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--debug", "force a Sentry trace and print its id at the end (paste it into a bug report)").option("--output-dir <dir>", "directory for the full diagnostics dump (default: a temp folder)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--no-parallel", "lint serially with one worker (default: parallel across CPU cores; set the worker count with REACT_DOCTOR_PARALLEL)").option("--project <name>", "select projects: workspace names or directory paths (comma-separated for multiple); overrides the `projects` config field").option("--scope <value>", "how much to scan/report: full (default), files, changed (only new issues vs base), or lines (only changed lines)").option("--base <ref>", "base git ref for files/changed/lines scope (auto-detected when omitted)").addOption(new Option("--diff [base]", "[deprecated] alias for --scope changed (pass `false` to force a full scan)").hideHelp()).addOption(new Option("--changed-files-from <file>", "scan source files listed in a newline-delimited changed-files file").hideHelp()).option("--no-score", "skip the score API, the share URL, and crash reporting").addOption(new Option("--category <category>", "only show diagnostics in a category (repeatable; e.g. Security)").argParser(collectCategoryOption)).option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--blocking <level>", "severity that fails CI: error (default), warning, or none (advisory)").addOption(new Option("--fail-on <level>", "[deprecated] alias for --blocking <level>").hideHelp()).option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
53907
55311
  program.action(inspectAction);
53908
55312
  program.command("why <location>").description("Explain why a rule fired (or why a suppression didn't apply) at a file:line").option("--project <name>", "select projects: workspace names or directory paths (comma-separated for multiple)").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action((location, options) => whyAction(location, options));
53909
55313
  program.command("install").alias("setup").description("Install the react-doctor skill into your coding agents and optional git hook").option("-y, --yes", "skip prompts, install for all detected agents").option("--dry-run", "show what would be installed without writing files").option("--agent-hooks", "install native non-blocking agent hooks for Claude Code and Cursor").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderInstallHelpEpilog).action(installAction);
@@ -53946,4 +55350,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
53946
55350
  export {};
53947
55351
 
53948
55352
  //# sourceMappingURL=cli.js.map
53949
- //# debugId=bb93aaad-ea85-5f1d-b2db-584f48671f66
55353
+ //# debugId=6a2c86b6-c3a8-5e50-8e7b-daef840df200