eslint-plugin-kerfjs 5.0.0-beta.115 → 5.0.0-beta.116
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/docs/rules/ai-assistant-configs.md +10 -0
- package/index.js +1 -1
- package/lib/rules/ai-assistant-configs.js +114 -8
- package/package.json +1 -1
|
@@ -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.
|
|
18
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.116' },
|
|
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 {
|
|
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,
|
|
189
|
-
|
|
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
|
|
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())
|
|
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(
|
|
386
|
+
applyFix(
|
|
387
|
+
file,
|
|
388
|
+
checked.bundleDir,
|
|
389
|
+
checked.guidanceRoot,
|
|
390
|
+
result.appendZone,
|
|
391
|
+
);
|
|
286
392
|
}
|
|
287
393
|
return null;
|
|
288
394
|
},
|
package/package.json
CHANGED