@kirill.konshin/lint 0.8.8 → 0.8.10

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/lib.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { ToggleOptions } from "./config.js";
1
+ import { LintConfig, ToggleOptions } from "./config.js";
2
2
  //#region src/lib.d.ts
3
3
  type NormalizedOptions<T extends ToggleOptions> = Omit<T, 'enabled'>;
4
4
  type ToolGateSpec<T extends ToggleOptions> = {
5
5
  tool: string;
6
+ /** Is the tool in use (the workspace-root probe)? Usually `packageName` resolvable, `nx.json` for Nx. */
6
7
  has: boolean;
8
+ /** The strict probe from cwd, when it is not `packageName` resolvable from cwd. */
7
9
  strictHas?: boolean;
10
+ /** The package the integration needs at lint time - checked on its own, whatever `has` probes. */
8
11
  packageName?: string;
9
12
  requirePackage?: boolean;
10
13
  absolutizeOptions?: (options: NormalizedOptions<T>) => string[];
@@ -23,10 +26,10 @@ type ToolGateResult<T extends ToggleOptions> = {
23
26
  };
24
27
  export declare const GLOBAL_IGNORES: string[];
25
28
  /**
26
- * Capability gate: is a package resolvable from the workspace root - the scope the ESLint plugins
27
- * themselves resolve from at lint time?
29
+ * Capability gate: is a package resolvable from `scope` - by default the workspace root, the scope the ESLint plugins
30
+ * themselves resolve from at lint time; strict detection probes from cwd (see {@link toolGate}).
28
31
  */
29
- export declare function isPackageResolvable(packageName: string): boolean;
32
+ export declare function isPackageResolvable(packageName: string, scope?: string): boolean;
30
33
  /**
31
34
  * Workspace root of the consumer project - the anchor for every config-file scan (Tailwind entry,
32
35
  * `next.config.*`) and root-file detection (`nx.json`): `process.cwd()` alone is unreliable
@@ -53,7 +56,7 @@ export declare function findWorkspaceRoot(cwd?: string): string;
53
56
  export declare function workspaceDependsOn(packageName: string, root?: string): boolean;
54
57
  /**
55
58
  * The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
56
- * workspace package dirs (see {@link findWorkspacePackages}), NOT by walking to the nearest
59
+ * workspace package dirs (see {@link workspaceOf}), NOT by walking to the nearest
57
60
  * package.json: a directory that is not a declared workspace member belongs to the root. Returns
58
61
  * the workspace root when no package contains `file`.
59
62
  *
@@ -61,7 +64,7 @@ export declare function workspaceDependsOn(packageName: string, root?: string):
61
64
  export declare function packageDirOf(file: string): string;
62
65
  /**
63
66
  * Glob for config-file candidates across the workspace: the root directory plus every workspace
64
- * package (the real `workspaces` globs via {@link findWorkspacePackages}, not a depth heuristic),
67
+ * package (the real `workspaces` globs via {@link workspaceOf}, not a depth heuristic),
65
68
  * skipping dot dirs, build outputs, the given ignore patterns and everything in the root
66
69
  * `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
67
70
  *
@@ -88,14 +91,14 @@ export declare function scanWorkspace(fileGlob: string, ignores?: string[], { do
88
91
  * block, so the Vite+ config detects Next.js without loading `eslint-config-next`.
89
92
  */
90
93
  export declare function findNextRoots(ignores: string[]): string[];
91
- export declare const hasNext: boolean;
92
- export declare const hasStorybook: boolean;
93
- export declare const hasVite: boolean;
94
- export declare const hasJest: boolean;
95
- export declare const hasVitest: boolean;
96
- export declare const hasTurbo: boolean;
97
- export declare const hasNx: boolean;
98
- export declare const hasTailwind: boolean;
94
+ export declare const hasNext: () => boolean;
95
+ export declare const hasStorybook: () => boolean;
96
+ export declare const hasVite: () => boolean;
97
+ export declare const hasJest: () => boolean;
98
+ export declare const hasVitest: () => boolean;
99
+ export declare const hasTurbo: () => boolean;
100
+ export declare const hasNx: () => boolean;
101
+ export declare const hasTailwind: () => boolean;
99
102
  /**
100
103
  * Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
101
104
  * - `true` / `false` → `{ enabled: true | false }`
@@ -108,6 +111,19 @@ export declare const hasTailwind: boolean;
108
111
  export declare function asOptions<T extends ToggleOptions>(option: boolean | T | null | undefined): NormalizedOptions<T> & {
109
112
  enabled?: boolean;
110
113
  };
114
+ /** A tool option with the `detection` setting applied: see {@link detectionOf}. */
115
+ type DetectionFlag = <T>(option: T | undefined) => T | false | undefined;
116
+ /**
117
+ * The `detection` setting of `lint.config.ts`, read the same way by the ESLint config, the Vite+ config and
118
+ * `lint-prepare` (same toggle notation as the tools): `detect` - tools are ON unless said otherwise (default true);
119
+ * `strict` - same-scope probes from cwd only, no workspace evidence scans (default false; for per-package monorepo
120
+ * configs); `flag` - with detection off, a tool not mentioned explicitly is OFF instead of auto-detected.
121
+ */
122
+ export declare function detectionOf(config: LintConfig): {
123
+ detect: boolean;
124
+ strict: boolean;
125
+ flag: DetectionFlag;
126
+ };
111
127
  /**
112
128
  * Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
113
129
  * vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
@@ -116,16 +132,16 @@ export declare function asOptions<T extends ToggleOptions>(option: boolean | T |
116
132
  *
117
133
  * Decision flow:
118
134
  * - `enabled: false` → off, always.
119
- * - strict (defineLintConfig `detection.strict`): the same-scope probe gates (`strictHas`,
120
- * defaulting to `has`); `scan` never runs, but `absolutizeOptions` evidence still counts. A tool
121
- * that is ON while its package is unresolvable (`requirePackage`) or its mandatory evidence is
122
- * missing (`needs`) throws instead of producing a config that crashes at lint time.
135
+ * - strict (defineLintConfig `detection.strict`): every probe runs from cwd - `packageName` resolvable from
136
+ * cwd, or the tool's own `strictHas` (e.g. `nx.json` at cwd), else `has`; `scan` never runs, but
137
+ * `absolutizeOptions` evidence still counts. A tool that is ON while its package is unresolvable from cwd
138
+ * (`requirePackage`) or its mandatory evidence is missing (`needs`) throws instead of producing a config that
139
+ * crashes at lint time.
123
140
  * - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
124
141
  * auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
125
142
  * makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
126
- * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip, no
127
- * symlink bridging - the plugins resolve from the root scope, so only hoisting actually fixes
128
- * them; the user or their AI agent picks it up from the error).
143
+ * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip - the
144
+ * plugins resolve from the root scope, so only hoisting fixes them).
129
145
  *
130
146
  */
131
147
  export declare function toolGate<T extends ToggleOptions>(option: boolean | T | undefined, strict: boolean, spec: ToolGateSpec<T>): ToolGateResult<T>;
package/dist/lib.js CHANGED
@@ -15,6 +15,7 @@ const GLOBAL_IGNORES = [
15
15
  "**/.nx",
16
16
  "**/.turbo",
17
17
  "**/.yarn",
18
+ "**/graphify-out",
18
19
  "**/skills/spec-tools/scripts/cli.js"
19
20
  ];
20
21
  const LINT_DEBUG = Boolean(process.env.LINT_DEBUG);
@@ -27,20 +28,23 @@ function debug(message, ...args) {
27
28
  console.log(`[@kirill.konshin/lint] ${message}`, ...args);
28
29
  }
29
30
  /**
30
- * Capability gate: is a package resolvable from the workspace root - the scope the ESLint plugins
31
- * themselves resolve from at lint time?
31
+ * Capability gate: is a package resolvable from `scope` - by default the workspace root, the scope the ESLint plugins
32
+ * themselves resolve from at lint time; strict detection probes from cwd (see {@link toolGate}).
32
33
  */
33
- function isPackageResolvable(packageName) {
34
- return isPackageExists(packageName, { paths: [findWorkspaceRoot()] });
34
+ function isPackageResolvable(packageName, scope = findWorkspaceRoot()) {
35
+ return isPackageExists(packageName, { paths: [scope] });
35
36
  }
37
+ /** Is `path` `dir` itself or inside it? */
38
+ const isInside = (dir, path) => {
39
+ const rel = relative(dir, path);
40
+ return !rel.startsWith("..") && !isAbsolute(rel);
41
+ };
36
42
  /**
37
43
  * An env-supplied root candidate is only plausible when it is an absolute existing directory that
38
44
  * contains (or is) `cwd` - guards against stale env leaking in from an unrelated checkout.
39
45
  */
40
46
  function isRootOf(root, cwd) {
41
- if (!root || !isAbsolute(root) || !existsSync(root)) return false;
42
- const rel = relative(root, cwd);
43
- return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
47
+ return Boolean(root && isAbsolute(root) && existsSync(root) && isInside(root, cwd));
44
48
  }
45
49
  const workspaceRoots = /* @__PURE__ */ new Map();
46
50
  /**
@@ -73,52 +77,50 @@ function findWorkspaceRoot(cwd = process.cwd()) {
73
77
  workspaceRoots.set(cwd, root);
74
78
  return root;
75
79
  }
76
- const workspacePackageDirs = /* @__PURE__ */ new Map();
80
+ const workspaces = /* @__PURE__ */ new Map();
77
81
  /**
78
- * Absolute directories of all workspace packages - the real `workspaces` / `pnpm-workspace.yaml`
79
- * globs expanded by `@manypkg/get-packages`, NOT a scan heuristic. Single-package repos yield the
80
- * root itself; no package.json at all yields an empty list (degenerate sandboxes, tests).
82
+ * The workspace of `root`, read once per process: the absolute directories of its packages - the real `workspaces` /
83
+ * `pnpm-workspace.yaml` globs expanded by `@manypkg/get-packages`, NOT a scan heuristic; a single-package repo yields
84
+ * the root itself - and the manifests of the root and every package. No package.json at all yields nothing
85
+ * (degenerate sandboxes, tests).
81
86
  */
82
- function findWorkspacePackages() {
83
- const root = findWorkspaceRoot();
84
- const cached = workspacePackageDirs.get(root);
87
+ function workspaceOf(root = findWorkspaceRoot()) {
88
+ const cached = workspaces.get(root);
85
89
  if (cached) return cached;
86
- let dirs = [];
90
+ let workspace = {
91
+ dirs: [],
92
+ manifests: []
93
+ };
87
94
  try {
88
- dirs = getPackagesSync(root).packages.map((pkg) => pkg.dir);
95
+ const { rootPackage, packages } = getPackagesSync(root);
96
+ workspace = {
97
+ dirs: packages.map((pkg) => pkg.dir),
98
+ manifests: [rootPackage, ...packages].flatMap((pkg) => pkg ? [pkg.packageJson] : [])
99
+ };
89
100
  } catch {}
90
- workspacePackageDirs.set(root, dirs);
91
- return dirs;
101
+ workspaces.set(root, workspace);
102
+ return workspace;
92
103
  }
104
+ /** Does this manifest declare `packageName`? Peer/optional declarations mark libraries, not users - ignored. */
105
+ const declares = ({ dependencies, devDependencies }, packageName) => Boolean(dependencies?.[packageName] ?? devDependencies?.[packageName]);
93
106
  /**
94
107
  * Does the root or a workspace package of `root` declare `packageName` in `dependencies` or `devDependencies`?
95
108
  * Peer/optional declarations are ignored, as in {@link dependsOnNext}. Reads the manifests the workspace globs name
96
109
  * (`@manypkg/get-packages`), no scan; false without a `package.json`.
97
110
  */
98
111
  function workspaceDependsOn(packageName, root = findWorkspaceRoot()) {
99
- try {
100
- const { rootPackage, packages } = getPackagesSync(root);
101
- return [rootPackage, ...packages].some((pkg) => {
102
- const { dependencies, devDependencies } = pkg?.packageJson ?? {};
103
- return Boolean(dependencies?.[packageName] ?? devDependencies?.[packageName]);
104
- });
105
- } catch {
106
- return false;
107
- }
112
+ return workspaceOf(root).manifests.some((manifest) => declares(manifest, packageName));
108
113
  }
109
114
  /**
110
115
  * The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
111
- * workspace package dirs (see {@link findWorkspacePackages}), NOT by walking to the nearest
116
+ * workspace package dirs (see {@link workspaceOf}), NOT by walking to the nearest
112
117
  * package.json: a directory that is not a declared workspace member belongs to the root. Returns
113
118
  * the workspace root when no package contains `file`.
114
119
  *
115
120
  */
116
121
  function packageDirOf(file) {
117
122
  const root = findWorkspaceRoot();
118
- return findWorkspacePackages().filter((dir) => dir !== root).sort((a, b) => b.length - a.length).find((dir) => {
119
- const rel = relative(dir, file);
120
- return !rel.startsWith("..") && !isAbsolute(rel);
121
- }) ?? root;
123
+ return workspaceOf(root).dirs.filter((dir) => dir !== root).sort((a, b) => b.length - a.length).find((dir) => isInside(dir, file)) ?? root;
122
124
  }
123
125
  const SCAN_IGNORES = [
124
126
  "**/node_modules",
@@ -132,6 +134,7 @@ const SCAN_IGNORES = [
132
134
  "**/.git"
133
135
  ];
134
136
  const scurries = /* @__PURE__ */ new Map();
137
+ const gitignores = /* @__PURE__ */ new Map();
135
138
  /**
136
139
  * Filesystem cache of a scanned directory, shared by every {@link scanWorkspace} call: the detection scans all walk
137
140
  * the same trees, so each directory is read once instead of once per scan. Cached per process, like the workspace
@@ -145,8 +148,22 @@ function scurryOf(dir) {
145
148
  return scurry;
146
149
  }
147
150
  /**
151
+ * The root `.gitignore` as glob ignore patterns, read once per root. Reuses ESLint's gitignore->minimatch conversion;
152
+ * glob's `ignore` speaks the same language. Negations dropped: glob's ignore cannot un-ignore.
153
+ */
154
+ function gitignoredOf(root) {
155
+ const cached = gitignores.get(root);
156
+ if (cached) return cached;
157
+ let patterns = [];
158
+ try {
159
+ patterns = (includeIgnoreFile(resolve(root, ".gitignore")).ignores ?? []).filter((p) => !p.startsWith("!"));
160
+ } catch {}
161
+ gitignores.set(root, patterns);
162
+ return patterns;
163
+ }
164
+ /**
148
165
  * Glob for config-file candidates across the workspace: the root directory plus every workspace
149
- * package (the real `workspaces` globs via {@link findWorkspacePackages}, not a depth heuristic),
166
+ * package (the real `workspaces` globs via {@link workspaceOf}, not a depth heuristic),
150
167
  * skipping dot dirs, build outputs, the given ignore patterns and everything in the root
151
168
  * `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
152
169
  *
@@ -156,15 +173,11 @@ function scurryOf(dir) {
156
173
  */
157
174
  function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
158
175
  const root = findWorkspaceRoot();
159
- const packages = findWorkspacePackages().filter((dir) => dir !== root);
160
- let gitignored = [];
161
- try {
162
- gitignored = (includeIgnoreFile(resolve(root, ".gitignore")).ignores ?? []).filter((pattern) => !pattern.startsWith("!"));
163
- } catch {}
176
+ const packages = workspaceOf(root).dirs.filter((dir) => dir !== root);
164
177
  const ignore = [
165
178
  ...ignores,
166
179
  ...SCAN_IGNORES,
167
- ...gitignored
180
+ ...gitignoredOf(root)
168
181
  ].flatMap((pattern) => [pattern, pattern.endsWith("/") ? `${pattern}**` : `${pattern}/**`]);
169
182
  const rootIgnore = [...ignore, ...packages.flatMap((dir) => {
170
183
  const rel = relative(root, dir).replaceAll("\\", "/");
@@ -190,8 +203,7 @@ function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
190
203
  */
191
204
  function dependsOnNext(file) {
192
205
  try {
193
- const { dependencies, devDependencies } = JSON.parse(readFileSync(file, "utf-8"));
194
- return Boolean(dependencies?.next ?? devDependencies?.next);
206
+ return declares(JSON.parse(readFileSync(file, "utf-8")), "next");
195
207
  } catch {
196
208
  return false;
197
209
  }
@@ -218,24 +230,30 @@ function findNextRoots(ignores) {
218
230
  ...scanWorkspace("src/{app,pages}/", ignores).map((dir) => dirname(dirname(dir)))
219
231
  ])].sort();
220
232
  }
221
- const hasNext = isPackageResolvable("next");
222
- const hasStorybook = isPackageResolvable("storybook");
223
- const hasVite = isPackageResolvable("vite");
224
- const hasJest = isPackageResolvable("jest");
225
- const hasVitest = isPackageResolvable("vitest");
226
- const hasTurbo = isPackageResolvable("turbo");
227
- const hasNx = existsSync(resolve(findWorkspaceRoot(), "nx.json"));
228
- const hasTailwind = isPackageResolvable("tailwindcss");
229
- debug("capability probes", {
230
- hasNext,
231
- hasStorybook,
232
- hasVite,
233
- hasJest,
234
- hasVitest,
235
- hasTurbo,
236
- hasNx,
237
- hasTailwind
238
- });
233
+ const probes = /* @__PURE__ */ new Map();
234
+ /** `check` of the workspace root, run once per root and only when a gate asks for it - not when a module loads. */
235
+ function probe(name, check) {
236
+ const root = findWorkspaceRoot();
237
+ const key = `${root}\0${name}`;
238
+ const cached = probes.get(key);
239
+ if (cached !== void 0) return cached;
240
+ const found = check(root);
241
+ probes.set(key, found);
242
+ debug("capability probe", {
243
+ name,
244
+ root,
245
+ found
246
+ });
247
+ return found;
248
+ }
249
+ const hasNext = () => probe("next", (root) => isPackageResolvable("next", root));
250
+ const hasStorybook = () => probe("storybook", (root) => isPackageResolvable("storybook", root));
251
+ const hasVite = () => probe("vite", (root) => isPackageResolvable("vite", root));
252
+ const hasJest = () => probe("jest", (root) => isPackageResolvable("jest", root));
253
+ const hasVitest = () => probe("vitest", (root) => isPackageResolvable("vitest", root));
254
+ const hasTurbo = () => probe("turbo", (root) => isPackageResolvable("turbo", root));
255
+ const hasNx = () => probe("nx.json", (root) => existsSync(resolve(root, "nx.json")));
256
+ const hasTailwind = () => probe("tailwindcss", (root) => isPackageResolvable("tailwindcss", root));
239
257
  /**
240
258
  * Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
241
259
  * - `true` / `false` → `{ enabled: true | false }`
@@ -254,6 +272,21 @@ function asOptions(option) {
254
272
  return {};
255
273
  }
256
274
  /**
275
+ * The `detection` setting of `lint.config.ts`, read the same way by the ESLint config, the Vite+ config and
276
+ * `lint-prepare` (same toggle notation as the tools): `detect` - tools are ON unless said otherwise (default true);
277
+ * `strict` - same-scope probes from cwd only, no workspace evidence scans (default false; for per-package monorepo
278
+ * configs); `flag` - with detection off, a tool not mentioned explicitly is OFF instead of auto-detected.
279
+ */
280
+ function detectionOf(config) {
281
+ const { enabled: detect = true, strict = false } = asOptions(config.detection);
282
+ const flag = (option) => option === void 0 && !detect ? false : option;
283
+ return {
284
+ detect,
285
+ strict,
286
+ flag
287
+ };
288
+ }
289
+ /**
257
290
  * Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
258
291
  * vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
259
292
  * actually run. The `configs/*.ts` functions keep only their tool-specific parts (which blocks to
@@ -261,16 +294,16 @@ function asOptions(option) {
261
294
  *
262
295
  * Decision flow:
263
296
  * - `enabled: false` → off, always.
264
- * - strict (defineLintConfig `detection.strict`): the same-scope probe gates (`strictHas`,
265
- * defaulting to `has`); `scan` never runs, but `absolutizeOptions` evidence still counts. A tool
266
- * that is ON while its package is unresolvable (`requirePackage`) or its mandatory evidence is
267
- * missing (`needs`) throws instead of producing a config that crashes at lint time.
297
+ * - strict (defineLintConfig `detection.strict`): every probe runs from cwd - `packageName` resolvable from
298
+ * cwd, or the tool's own `strictHas` (e.g. `nx.json` at cwd), else `has`; `scan` never runs, but
299
+ * `absolutizeOptions` evidence still counts. A tool that is ON while its package is unresolvable from cwd
300
+ * (`requirePackage`) or its mandatory evidence is missing (`needs`) throws instead of producing a config that
301
+ * crashes at lint time.
268
302
  * - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
269
303
  * auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
270
304
  * makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
271
- * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip, no
272
- * symlink bridging - the plugins resolve from the root scope, so only hoisting actually fixes
273
- * them; the user or their AI agent picks it up from the error).
305
+ * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip - the
306
+ * plugins resolve from the root scope, so only hoisting fixes them).
274
307
  *
275
308
  */
276
309
  function toolGate(option, strict, spec) {
@@ -297,7 +330,7 @@ function toolGate(option, strict, spec) {
297
330
  files: []
298
331
  };
299
332
  if (enabled === false) return trace(off, "disabled explicitly");
300
- const { tool, has, strictHas = has, packageName, requirePackage = Boolean(packageName), absolutizeOptions, scan, allowMultiple = true, needs } = spec;
333
+ const { tool, has, strictHas, packageName, requirePackage = Boolean(packageName), absolutizeOptions, scan, allowMultiple = true, needs } = spec;
301
334
  const prefix = `[@kirill.konshin/lint] \`${tool}\``;
302
335
  const usable = (candidates) => {
303
336
  if (!allowMultiple && candidates.length > 1) {
@@ -307,8 +340,9 @@ function toolGate(option, strict, spec) {
307
340
  return candidates;
308
341
  };
309
342
  if (strict) {
310
- if (!(enabled ?? strictHas)) return trace(off, "strict probe negative");
311
- if (requirePackage && !has) throw new Error(`${prefix} is on under strict detection, but the \`${packageName}\` package is not resolvable at this scope - install it here or set \`${tool}: false\`.`);
343
+ const here = packageName ? isPackageResolvable(packageName, process.cwd()) : has;
344
+ if (!(enabled ?? strictHas ?? here)) return trace(off, "strict probe negative");
345
+ if (requirePackage && !here) throw new Error(`${prefix} is on under strict detection, but the \`${packageName}\` package is not resolvable at this scope - install it here or set \`${tool}: false\`.`);
312
346
  absolutized = absolutizeOptions?.(options) ?? [];
313
347
  const files = usable(absolutized);
314
348
  if (needs && files.length === 0) throw new Error(`${prefix} is on under strict detection, which cannot scan for the ${needs.what} - pass ${needs.hint} or set \`${tool}: false\`.`);
@@ -326,7 +360,7 @@ function toolGate(option, strict, spec) {
326
360
  return trace(off, `no ${needs.what} found`);
327
361
  }
328
362
  if (!(enabled ?? (has || files.length > 0))) return trace(off, "not detected");
329
- if (requirePackage && packageName && !has) {
363
+ if (requirePackage && packageName && !isPackageResolvable(packageName)) {
330
364
  const leaf = files.map((file) => dirname(file)).find((dir) => isPackageExists(packageName, { paths: [dir] }));
331
365
  throw new Error(`${prefix} is in use, but the \`${packageName}\` package is not resolvable from the workspace root` + (leaf ? ` (it is installed near \`${leaf}\`)` : "") + ` - hoist it: keep the package manager's default hoisting (no \`installConfig.hoistingLimits\` / \`nohoist\`), on pnpm add \`public-hoist-pattern[]=${packageName}\` to .npmrc, or add \`${packageName}\` to the root devDependencies. Set \`${tool}: false\` to turn the tool off. Run eslint with LINT_DEBUG=1 to trace detection.`);
332
366
  }
@@ -337,4 +371,4 @@ function toolGate(option, strict, spec) {
337
371
  }, enabled ? "forced on" : "detected");
338
372
  }
339
373
  //#endregion
340
- export { GLOBAL_IGNORES, asOptions, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn };
374
+ export { GLOBAL_IGNORES, asOptions, detectionOf, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn };
@@ -1,5 +1,5 @@
1
1
  import { LintConfig, SkillsConfig } from "./config.js";
2
- import { SpawnSyncOptions } from "node:child_process";
2
+ import { RunCommand } from "./runCommand.js";
3
3
  //#region src/lintPrepare.d.ts
4
4
  /**
5
5
  * A rule file. `paths` scopes it: Claude Code loads it only for matching files.
@@ -20,11 +20,14 @@ type ExistingFile = {
20
20
  customSection: string | null;
21
21
  };
22
22
  /**
23
- * The part of `spawnSync` runSkillsSync() uses.
23
+ * A marked section of AGENTS.md another tool owns: its anchors - lines of their own - and what `lint-prepare` writes
24
+ * after them (`tail`).
24
25
  */
25
- export type RunCommand = (command: string, args: string[], options: SpawnSyncOptions) => {
26
- status: number | null;
27
- error?: Error;
26
+ export type ToolSection = {
27
+ tool: string;
28
+ start: string;
29
+ end: string;
30
+ tail?: string;
28
31
  };
29
32
  /**
30
33
  * Read all markdown files from the package rules directory.
@@ -97,8 +100,8 @@ export declare function syncRemoteSkills(cwd: string, remote: RemoteSkills[], ru
97
100
  /** Package rules the `rules` map of `lint.config.ts` keeps. */
98
101
  export declare function enabledRules(rules: Rule[], config: LintConfig): Rule[];
99
102
  /**
100
- * List the skills the `skills` CLI installed in the `.gitignore` of every agent `skills` dir: they stay out of git, and
101
- * the links this tool placed keep their own list.
103
+ * List the skills the `skills` CLI and graphify installed in the `.gitignore` of every agent `skills` dir: they stay out
104
+ * of git, and the links this tool placed keep their own list.
102
105
  */
103
106
  export declare function recordSyncedSkills(cwd: string): void;
104
107
  /**
@@ -138,9 +141,9 @@ export declare function symlinkClaudeMd(cwd: string): void;
138
141
  *
139
142
  * The links are plain, never `@path` imports: Claude Code loads `.claude/rules` itself (syncAgentDirs() links them
140
143
  * there) and honours each rule's `paths`, while an `@` import would load every rule into every session, scoped or not.
141
- * Codex, which expands no `@`, reads this index.
144
+ * Codex, which expands no `@`, reads this index. `toolSections` follow the sections of {@link TOOL_SECTIONS}.
142
145
  */
143
- export declare function generateAgentsFile(rules: Rule[], customSection: string | null, previous?: string): string;
146
+ export declare function generateAgentsFile(rules: Rule[], customSection: string | null, previous?: string, toolSections?: ToolSection[]): string;
144
147
  /**
145
148
  * Check if AGENTS.md exists and was generated by this tool. When it was, also return
146
149
  * whatever follows the marker (the user's custom section) so it can be carried forward -
@@ -153,4 +156,4 @@ export declare function checkExisting(targetPath: string): ExistingFile;
153
156
  */
154
157
  export declare function main(): Promise<void>;
155
158
  //#endregion
156
- export {};
159
+ export type { RunCommand };