eslint-plugin-kerfjs 5.0.0-beta.115 → 5.0.0-beta.117

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/README.md CHANGED
@@ -79,6 +79,8 @@ settings: {
79
79
 
80
80
  For deterministic generated configs, the same settings accept parsed `catalog`, `selectionCatalog`, and `profile` objects. File-based precedence is package defaults, then workspace profile, then root-to-leaf directory profiles. The rules load `application-ui-profile-sync.cjs` from the installed `@kerfjs/ui` package by default because ESLint rule creation is synchronous; `profileContractPath` is only needed when artifacts are vendored, and then its directory must also hold `application-ui-diagnostic-ids-v1.json` and `component-class-owners.cjs` (the class-to-component rule `KUI-L103` shares with `@kerfjs/ui`'s generated component pages) from the same `@kerfjs/ui` release. Every raw layer is schema- and catalog-reference-validated before merge, so a child cannot hide malformed or stale parent policy. Exceptions use exact `KUI-L*` diagnostic ids and repository-relative file or directory targets.
81
81
 
82
+ When linting a nested workspace package, set `workspaceRoot` to the repository root. Installed `@kerfjs/ui` assets still resolve from ESLint's package `cwd`, while profile discovery and exception targets use the workspace root.
83
+
82
84
  `ui-css-values` consumes each catalog entry's property-specific grammar and
83
85
  emits `KUI-L013`–`KUI-L016` with a preferred shorthand or helper. It covers JSX,
84
86
  direct component calls, nested catalog paths, and explicitly configured
@@ -17,6 +17,16 @@ The rule resolves `kerfjs/ai/manifest.json` from the consumer's installed `kerfj
17
17
 
18
18
  A triggered file is then classified into one of three reported states (a fourth, "up-to-date," is silent):
19
19
 
20
+ With `--guidance-source AGENTS.md`, setup writes an import-only Claude skill.
21
+ The rule accepts its generated form and checks that the import resolves within
22
+ the workspace to a readable document containing Kerf and a project check command
23
+ instructions. A missing, malformed, or ineffective source is reported as
24
+ forked. This authored guidance mode does not compare the source to the bundled
25
+ skill version; review its Kerf instructions during upgrades.
26
+ When lint runs inside a workspace package, the rule finds setup state in a
27
+ parent directory and checks the workspace-root guidance. `eslint --fix`
28
+ restores the import-only skill when that mode is recorded in setup state.
29
+
20
30
  - **Missing** — the consumer's `dest` doesn't exist.
21
31
  - **Stale** — exists, parses cleanly, its `kerf-skill-version` line is older than the bundle's, and its canonical-section hash matches that version in the manifest's history.
22
32
  - **Forked** — the consumer's file no longer matches the canonical layout: marker is missing, marker appears more than once, `kerf-skill-version` line is missing, or the content above the marker has been edited.
package/index.js CHANGED
@@ -15,7 +15,7 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
15
15
  import uiWiring from './lib/rules/ui-wiring.js';
16
16
 
17
17
  const plugin = {
18
- meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.115' },
18
+ meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.117' },
19
19
  rules: {
20
20
  'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
21
21
  'no-raw-with-dynamic-arg': noRawWithDynamicArg,
@@ -14,13 +14,55 @@
14
14
  * flag.
15
15
  */
16
16
  import { createHash } from 'node:crypto';
17
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
+ import {
18
+ existsSync,
19
+ mkdirSync,
20
+ readFileSync,
21
+ realpathSync,
22
+ writeFileSync,
23
+ } from 'node:fs';
18
24
  import { createRequire } from 'node:module';
19
- import { dirname, join } from 'node:path';
25
+ import { dirname, join, resolve, relative } from 'node:path';
20
26
 
21
27
  const MARKER = '<!-- KERF-APP-CANONICAL-END · your customizations below -->';
22
28
  const VERSION_RE = /kerf-skill-version:\s*(\d+\.\d+\.\d+(?:-[\w.]+)?)/;
23
29
  const VERSION_SCAN_BYTES = 512;
30
+ const SHARED_SKILL_PREFIX =
31
+ '---\nname: kerf-app\ndescription: Use the shared workspace guidance for Kerf application work.\n---\n\n@';
32
+
33
+ function sharedGuidanceSource(cwd) {
34
+ try {
35
+ const state = JSON.parse(
36
+ readFileSync(join(cwd, '.kerf-ai-setup.json'), 'utf8'),
37
+ );
38
+ const sources = new Set(
39
+ Object.values(state.packages ?? {})
40
+ .map((entry) => entry.guidanceSource)
41
+ .filter(Boolean),
42
+ );
43
+ return sources.size === 1 ? [...sources][0] : null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ function guidanceRoot(cwd) {
50
+ let current = cwd;
51
+ while (true) {
52
+ if (existsSync(join(current, '.kerf-ai-setup.json'))) return current;
53
+ const parent = dirname(current);
54
+ if (parent === current) return cwd;
55
+ current = parent;
56
+ }
57
+ }
58
+
59
+ function sharedSkill(file, cwd, source) {
60
+ const importPath = relative(
61
+ dirname(join(cwd, file.dest)),
62
+ join(cwd, source),
63
+ ).replaceAll('\\', '/');
64
+ return `${SHARED_SKILL_PREFIX}${importPath}\n`;
65
+ }
24
66
 
25
67
  // Module-level once-per-lint-run guard. ESLint instantiates the rule
26
68
  // per-file; we do the project-level filesystem check the first time the
@@ -105,6 +147,50 @@ export function classifyFile(file, bundleDir, cwd) {
105
147
  return { state: 'missing' };
106
148
  }
107
149
 
150
+ if (
151
+ file.name === 'skill' &&
152
+ /^---\nname: kerf-app\n/.test(consumer) &&
153
+ /\n@[^\n]+\n$/.test(consumer)
154
+ ) {
155
+ const match = consumer.match(
156
+ /^---\nname: kerf-app\ndescription: Use the shared workspace guidance for Kerf application work\.\n---\n\n@([^\n]+)\n$/,
157
+ );
158
+ if (!match)
159
+ return { state: 'forked', reason: 'malformed shared guidance import' };
160
+ const sourcePath = resolve(dirname(destAbs), match[1]);
161
+ const sourceRelative = relative(cwd, sourcePath);
162
+ if (sourceRelative === '..' || sourceRelative.startsWith('../'))
163
+ return {
164
+ state: 'forked',
165
+ reason: 'shared guidance import escapes the workspace',
166
+ };
167
+ let source;
168
+ try {
169
+ const actualRelative = relative(
170
+ realpathSync(cwd),
171
+ realpathSync(sourcePath),
172
+ );
173
+ if (actualRelative === '..' || actualRelative.startsWith('../'))
174
+ return {
175
+ state: 'forked',
176
+ reason: 'shared guidance import escapes the workspace',
177
+ };
178
+ source = readFileSync(sourcePath, 'utf8');
179
+ } catch {
180
+ return { state: 'forked', reason: 'shared guidance source is missing' };
181
+ }
182
+ if (
183
+ !/\bkerf(?:js)?\b/i.test(source) ||
184
+ !/(?:kerf:check|npm run check)/i.test(source)
185
+ )
186
+ return {
187
+ state: 'forked',
188
+ reason:
189
+ 'shared guidance source lacks Kerf or project check instructions',
190
+ };
191
+ return { state: 'ok' };
192
+ }
193
+
108
194
  const markerIdx = findMarkerIndex(consumer);
109
195
  if (markerIdx === -1)
110
196
  return { state: 'forked', reason: 'no canonical-end marker' };
@@ -183,12 +269,23 @@ function isTriggered(name, cwd) {
183
269
  export function runCheck(cwd) {
184
270
  const bundle = loadBundle(cwd);
185
271
  if (!bundle) return null;
272
+ const root = guidanceRoot(cwd);
186
273
  const results = [];
274
+ const sharedSource = sharedGuidanceSource(root);
187
275
  for (const file of bundle.manifest.files) {
188
- if (!isTriggered(file.name, cwd)) continue;
189
- results.push({ file, result: classifyFile(file, bundle.bundleDir, cwd) });
276
+ if (!isTriggered(file.name, root)) continue;
277
+ let result = classifyFile(file, bundle.bundleDir, root);
278
+ if (file.name === 'skill' && sharedSource && result.state === 'ok') {
279
+ const actual = readFileSync(join(root, file.dest), 'utf8');
280
+ if (actual !== sharedSkill(file, root, sharedSource))
281
+ result = {
282
+ state: 'forked',
283
+ reason: 'expected the configured shared guidance import',
284
+ };
285
+ }
286
+ results.push({ file, result });
190
287
  }
191
- return { results, bundleDir: bundle.bundleDir };
288
+ return { results, bundleDir: bundle.bundleDir, guidanceRoot: root };
192
289
  }
193
290
 
194
291
  /**
@@ -198,7 +295,10 @@ export function runCheck(cwd) {
198
295
  */
199
296
  export function applyFix(file, bundleDir, cwd, appendZone) {
200
297
  const bundlePath = join(bundleDir, file.bundle.replace(/^ai\//, ''));
201
- const canonical = readFileSync(bundlePath, 'utf8');
298
+ const sharedSource = file.name === 'skill' && sharedGuidanceSource(cwd);
299
+ const canonical = sharedSource
300
+ ? sharedSkill(file, cwd, sharedSource)
301
+ : readFileSync(bundlePath, 'utf8');
202
302
  const dest = join(cwd, file.dest);
203
303
  mkdirSync(dirname(dest), { recursive: true });
204
304
  writeFileSync(dest, canonical + (appendZone || ''));
@@ -267,7 +367,8 @@ function create(context) {
267
367
  messageId: 'missing',
268
368
  data,
269
369
  fix() {
270
- if (isFixCliRun()) applyFix(file, checked.bundleDir, cwd, '');
370
+ if (isFixCliRun())
371
+ applyFix(file, checked.bundleDir, checked.guidanceRoot, '');
271
372
  return null;
272
373
  },
273
374
  });
@@ -282,7 +383,12 @@ function create(context) {
282
383
  },
283
384
  fix() {
284
385
  if (isFixCliRun()) {
285
- applyFix(file, checked.bundleDir, cwd, result.appendZone);
386
+ applyFix(
387
+ file,
388
+ checked.bundleDir,
389
+ checked.guidanceRoot,
390
+ result.appendZone,
391
+ );
286
392
  }
287
393
  return null;
288
394
  },
@@ -145,7 +145,8 @@ function loadClassOwnership(profileContractPath) {
145
145
 
146
146
  export function loadUiContract(context) {
147
147
  const settings = context.settings?.kerfjs?.ui ?? {};
148
- const cwd = settings.workspaceRoot ?? context.cwd ?? process.cwd();
148
+ const packageCwd = context.cwd ?? process.cwd();
149
+ const cwd = resolve(settings.workspaceRoot ?? packageCwd);
149
150
  const filename = context.filename ?? context.getFilename();
150
151
  const key = JSON.stringify([cwd, filename, settings]);
151
152
  if (cache.has(key)) return cache.get(key);
@@ -153,13 +154,14 @@ export function loadUiContract(context) {
153
154
  const catalog =
154
155
  settings.catalog ??
155
156
  readJson(
156
- settings.catalogPath ?? packageAsset(cwd, 'component-composition.json'),
157
+ settings.catalogPath ??
158
+ packageAsset(packageCwd, 'component-composition.json'),
157
159
  );
158
160
  const selection =
159
161
  settings.selectionCatalog ??
160
162
  readJson(
161
163
  settings.selectionCatalogPath ??
162
- packageAsset(cwd, 'component-catalog.json'),
164
+ packageAsset(packageCwd, 'component-catalog.json'),
163
165
  );
164
166
  const profiles = settings.profilePath
165
167
  ? [
@@ -168,10 +170,10 @@ export function loadUiContract(context) {
168
170
  profile: readJson(settings.profilePath),
169
171
  },
170
172
  ]
171
- : discoveredProfiles(cwd, filename, settings);
173
+ : discoveredProfiles(packageCwd, filename, settings);
172
174
  const profileContractPath =
173
175
  settings.profileContractPath ??
174
- packageAsset(cwd, 'application-ui-profile-sync.cjs');
176
+ packageAsset(packageCwd, 'application-ui-profile-sync.cjs');
175
177
  if (!profileContractPath)
176
178
  throw new Error(
177
179
  'Cannot resolve @kerfjs/ui/ai/application-ui-profile-sync.cjs; install @kerfjs/ui or set kerfjs.ui.profileContractPath.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-kerfjs",
3
- "version": "5.0.0-beta.115",
3
+ "version": "5.0.0-beta.117",
4
4
  "description": "ESLint rules that enforce kerf's hard rules — catches AI-shaped bugs at edit time.",
5
5
  "type": "module",
6
6
  "license": "MIT",