@specdest/devkit 0.4.1 → 0.4.2

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
@@ -10,6 +10,8 @@ The npm package contains only the CLI/core runtime. Canonical rules stay in the
10
10
  npx @specdest/devkit status
11
11
  npx @specdest/devkit sync
12
12
  npx @specdest/devkit check [--refresh]
13
+ npx @specdest/devkit check --staged
14
+ npx @specdest/devkit check --files src/path/file.ts
13
15
  npx @specdest/devkit rules
14
16
  npx @specdest/devkit doctor
15
17
  npx @specdest/devkit fuzz
@@ -17,7 +19,7 @@ npx @specdest/devkit fuzz
17
19
 
18
20
  - `status` reads the cached canonical catalog and reports applicable/current/missing/outdated rules. Use `--refresh` to refresh the catalog from GitHub and `--json` for machine-readable output.
19
21
  - `sync` refreshes the canonical catalog, downloads only missing rule-cache entries, installs missing applicable rules, and updates outdated ones.
20
- - `check` executes each distinct canonical checker implementation once from the local Devkit cache, projects that result onto every rule backed by that checker, and updates `.specdest/state.json`. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files.
22
+ - `check` executes each distinct canonical checker implementation once from the local Devkit cache and projects that result onto every rule backed by that checker. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files. `--staged` resolves target paths/content from the Git index; `--files` supplies explicit project-relative paths. Repository-scoped checkers still run globally. Targeted checks are ephemeral and do not update `.specdest/state.json`; only a full check records canonical project status.
21
23
  - `rules` loads AI-facing guidance without dumping the whole catalog. Use `--id <rule>`, `--category <category>`, `--failed`, or `--json`; with no selector it returns only rules marked `ai.load = "always"`.
22
24
  - `doctor` reports project-stack/cache setup problems.
23
25
  - `fuzz` dynamically exercises Zod boundary contracts with `fast-check` plus Specdest semantic amplifiers for nullish, blank-string, numeric/boolean, and array edge cases. It is separate from static `check` and from Stryker mutation testing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "src/cli.js"
@@ -40,6 +40,34 @@ function flags(args) {
40
40
  return { refresh: args.includes('--refresh'), json: args.includes('--json') };
41
41
  }
42
42
 
43
+ function checkFlags(args) {
44
+ const result = { refresh: false, mode: 'full', files: null };
45
+ const remaining = [];
46
+ for (const arg of args) {
47
+ if (arg === '--refresh') result.refresh = true;
48
+ else remaining.push(arg);
49
+ }
50
+ if (remaining.includes('--staged') && remaining.includes('--files')) {
51
+ throw new Error('Use either --staged or --files, not both');
52
+ }
53
+ if (remaining.includes('--staged')) {
54
+ if (remaining.length !== 1) throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
55
+ result.mode = 'staged';
56
+ return result;
57
+ }
58
+ const filesIndex = remaining.indexOf('--files');
59
+ if (filesIndex >= 0) {
60
+ if (filesIndex !== 0 || remaining.length < 2) {
61
+ throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
62
+ }
63
+ result.mode = 'files';
64
+ result.files = remaining.slice(1);
65
+ return result;
66
+ }
67
+ if (remaining.length) throw new Error(`Unknown option: ${remaining[0]}`);
68
+ return result;
69
+ }
70
+
43
71
  async function cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline = false } = {}) {
44
72
  if (offline && !(await source.hasModule(entry.id, entry.version, entry.contentHash))) return null;
45
73
  const root = await source.module(entry.id, entry.version, { contentHash: entry.contentHash });
@@ -219,6 +247,14 @@ export async function canonicalCheck(projectRoot, source, options = {}) {
219
247
  const results = {};
220
248
  const groups = new Map();
221
249
  const executor = options.executor ?? execute;
250
+ const targetMode = options.mode ?? 'full';
251
+ let targetFiles = options.files ?? null;
252
+ if (targetMode === 'staged' && targetFiles === null) {
253
+ const staged = await executor('git', ['diff', '--cached', '--name-only', '-z', '--diff-filter=ACMR'], projectRoot);
254
+ if (staged.exitCode !== 0) throw new Error(staged.stderr || 'Unable to read staged files');
255
+ targetFiles = staged.stdout.split('\0').filter(Boolean);
256
+ }
257
+ const normalizedTargetFiles = (targetFiles ?? []).map((file) => String(file).replaceAll('\\', '/'));
222
258
  let exitCode = 0;
223
259
  for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
224
260
  const entry = byId.get(id);
@@ -230,17 +266,25 @@ export async function canonicalCheck(projectRoot, source, options = {}) {
230
266
  exitCode = 1;
231
267
  continue;
232
268
  }
233
- const key = prepared.checkerKey ?? `path:${prepared.checkerPath}:${JSON.stringify(prepared.checkerArgs ?? [])}`;
269
+ if (prepared.execution === 'manual') continue;
270
+ const baseKey = prepared.checkerKey ?? `path:${prepared.checkerPath}:${JSON.stringify(prepared.checkerArgs ?? [])}`;
271
+ const key = `${baseKey}:targeting:${prepared.targeting?.scope ?? 'repository'}:execution:${prepared.execution ?? 'automatic'}`;
234
272
  const group = groups.get(key) ?? {
235
273
  checkerPath: prepared.checkerPath,
236
274
  checkerArgs: prepared.checkerArgs ?? [],
275
+ targeting: prepared.targeting ?? { scope: 'repository' },
237
276
  ids: [],
238
277
  };
239
278
  group.ids.push(id);
240
279
  groups.set(key, group);
241
280
  }
242
281
  for (const group of groups.values()) {
243
- const execution = await executor('node', [group.checkerPath, ...group.checkerArgs], projectRoot);
282
+ const args = [group.checkerPath, ...group.checkerArgs];
283
+ if (targetMode !== 'full' && group.targeting.scope !== 'repository') {
284
+ args.push('--target-mode', targetMode);
285
+ for (const file of normalizedTargetFiles) args.push('--target-file', file);
286
+ }
287
+ const execution = await executor('node', args, projectRoot);
244
288
  const result = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
245
289
  for (const id of group.ids) results[id] = result;
246
290
  if (execution.exitCode !== 0) exitCode = 1;
@@ -248,11 +292,13 @@ export async function canonicalCheck(projectRoot, source, options = {}) {
248
292
  const orderedResults = Object.fromEntries(
249
293
  Object.entries(results).sort(([a], [b]) => a.localeCompare(b)),
250
294
  );
251
- await writeChecksState(projectRoot, {
252
- schemaVersion: 2,
253
- checkedAt: new Date().toISOString(),
254
- results: Object.fromEntries(Object.entries(orderedResults).map(([id, result]) => [id, { status: result.status }])),
255
- });
295
+ if (targetMode === 'full') {
296
+ await writeChecksState(projectRoot, {
297
+ schemaVersion: 2,
298
+ checkedAt: new Date().toISOString(),
299
+ results: Object.fromEntries(Object.entries(orderedResults).map(([id, result]) => [id, { status: result.status }])),
300
+ });
301
+ }
256
302
  return { exitCode, results: orderedResults };
257
303
  }
258
304
 
@@ -361,9 +407,10 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
361
407
  return 0;
362
408
  },
363
409
  check: async (args, io) => {
364
- const refresh = args.length === 1 && args[0] === '--refresh';
365
- if (args.length && !refresh) { io.stderr.write('Usage: specdest check [--refresh]\n'); return 2; }
366
- const result = await canonicalCheck(projectRoot, source, { refresh });
410
+ let parsed;
411
+ try { parsed = checkFlags(args); }
412
+ catch (error) { io.stderr.write(`${error.message}\n`); return 2; }
413
+ const result = await canonicalCheck(projectRoot, source, parsed);
367
414
  for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
368
415
  return result.exitCode;
369
416
  },
@@ -47,6 +47,18 @@ async function cacheProjectCopies(copies, sourceRoot, ruleRoot, label) {
47
47
  return result;
48
48
  }
49
49
 
50
+ function checkerPolicy(manifest) {
51
+ const scope = manifest?.targeting?.scope ?? 'repository';
52
+ if (!['file', 'related', 'repository'].includes(scope)) {
53
+ throw new Error(`Invalid checker targeting scope: ${scope}`);
54
+ }
55
+ const execution = manifest?.execution ?? 'automatic';
56
+ if (!['automatic', 'manual'].includes(execution)) {
57
+ throw new Error(`Invalid checker execution class: ${execution}`);
58
+ }
59
+ return { targeting: { scope }, execution };
60
+ }
61
+
50
62
  function runtimeChecker(manifest, runtimeRoot) {
51
63
  if (manifest?.check?.command?.[0] !== 'node') return null;
52
64
  const target = String(manifest.check.command[1] ?? '');
@@ -84,10 +96,12 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
84
96
 
85
97
  const copies = await cacheProjectCopies(raw.copies ?? [], ruleRoot, ruleRoot, entry.id);
86
98
  let checker = runtimeChecker(raw, runtimeRoot);
99
+ let { targeting, execution } = checkerPolicy(raw);
87
100
  if (!checker && raw.checker?.path && canonicalCheckRoot) {
88
101
  const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
89
102
  const implementationRoot = dirname(join(canonicalCheckRoot, relative));
90
103
  const implementationManifest = await readManifest(implementationRoot);
104
+ ({ targeting, execution } = checkerPolicy(implementationManifest));
91
105
  await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
92
106
  copies.push(...await cacheProjectCopies(
93
107
  implementationManifest.copies ?? [],
@@ -116,5 +130,7 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
116
130
  checkerPath: checker?.path ?? null,
117
131
  checkerArgs: checker?.args ?? [],
118
132
  checkerKey,
133
+ targeting,
134
+ execution,
119
135
  };
120
136
  }
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ export * from './fuzz.js';
13
13
 
14
14
  export const COMMAND_NAMES = ['status', 'sync', 'check', 'rules', 'ai-instruction', 'doctor', 'fuzz'];
15
15
 
16
- const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] Run installed rule checks; optionally refresh canonical cache first\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n fuzz Dynamically fuzz Zod contract semantics\n`;
16
+ const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] [--staged | --files <path...>] Run canonical checks, optionally targeted\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n fuzz Dynamically fuzz Zod contract semantics\n`;
17
17
 
18
18
  export async function runCli(argv, io = process, handlers = {}) {
19
19
  const [command, ...args] = argv;