@specdest/devkit 0.3.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "src/cli.js"
@@ -1,6 +1,6 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { readFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
2
+ import { readdir, readFile, rm, rmdir } from 'node:fs/promises';
3
+ import { join, relative } from 'node:path';
4
4
 
5
5
  import { createCanonicalSource, detectProjectStack } from './canonical-source.js';
6
6
  import { applicableCatalogEntries, prepareCachedManifest } from './canonical-project.js';
@@ -76,40 +76,66 @@ export async function canonicalStatus(projectRoot, source, options = {}) {
76
76
  };
77
77
  }
78
78
 
79
+ async function cleanupCanonicalSkillTree(projectRoot, allowedFiles) {
80
+ const root = join(projectRoot, '.agents', 'skills');
81
+ async function walk(directory) {
82
+ let entries;
83
+ try { entries = await readdir(directory, { withFileTypes: true }); }
84
+ catch (error) { if (error?.code === 'ENOENT') return; throw error; }
85
+ for (const entry of entries) {
86
+ const path = join(directory, entry.name);
87
+ if (entry.isDirectory()) {
88
+ await walk(path);
89
+ try { await rmdir(path); } catch (error) { if (error?.code !== 'ENOTEMPTY' && error?.code !== 'ENOENT') throw error; }
90
+ continue;
91
+ }
92
+ const projectPath = relative(projectRoot, path).split('\\').join('/');
93
+ if (!allowedFiles.has(projectPath)) await rm(path, { force: true });
94
+ }
95
+ }
96
+ await walk(root);
97
+ }
98
+
79
99
  export async function canonicalSync(projectRoot, source) {
80
100
  const current = await readInstalledState(projectRoot);
81
101
  const { stack, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
82
102
  const changed = [];
103
+ const allowedSkillFiles = new Set();
83
104
  for (const entry of applicable) {
84
105
  const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
106
+ for (const copy of prepared.manifest.copies ?? []) {
107
+ const target = String(copy.target ?? copy.path ?? '');
108
+ if (target.startsWith('.agents/skills/')) allowedSkillFiles.add(target);
109
+ }
85
110
  const installed = current.installed[entry.id];
86
111
  if (!installed) {
87
112
  await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
88
113
  changed.push({ id: entry.id, action: 'installed', version: entry.version });
89
- } else if (installed.version !== entry.version || installed.contentHash !== entry.contentHash || installed.check?.command?.[0] !== 'specdest-cache') {
114
+ } else if (installed.version !== entry.version || installed.contentHash !== entry.contentHash || (prepared.checkerPath && installed.check?.command?.[0] !== 'specdest-cache')) {
90
115
  await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
91
116
  changed.push({ id: entry.id, action: 'updated', version: entry.version });
92
117
  }
93
118
  }
119
+ await cleanupCanonicalSkillTree(projectRoot, allowedSkillFiles);
94
120
  return { stack, applicable: applicable.length, changed };
95
121
  }
96
122
 
97
123
  export async function canonicalCheck(projectRoot, source) {
98
124
  const current = await readInstalledState(projectRoot);
99
- const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { offline: true, withCheckers: true });
125
+ const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { offline: false, withCheckers: true });
100
126
  const byId = new Map(applicable.map((entry) => [entry.id, entry]));
101
127
  const results = {};
102
128
  let exitCode = 0;
103
129
  for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
104
130
  const entry = byId.get(id);
105
131
  if (!entry || installed.kind !== 'rule') continue;
106
- if (!(await source.hasModule(id, entry.version))) {
107
- results[id] = { status: 'fail', exitCode: 1, stderr: 'Rule cache missing; run specdest sync first.' };
132
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
133
+ if (!prepared?.checkerPath) {
134
+ if ((entry.enforcement ?? 'guidance') === 'guidance') continue;
135
+ results[id] = { status: 'fail', exitCode: 1, stderr: 'Canonical checker unavailable for enforced installed rule.' };
108
136
  exitCode = 1;
109
137
  continue;
110
138
  }
111
- const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline: true });
112
- if (!prepared?.checkerPath) continue;
113
139
  const execution = await execute('node', [prepared.checkerPath], projectRoot);
114
140
  results[id] = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
115
141
  if (execution.exitCode !== 0) exitCode = 1;
@@ -1,5 +1,5 @@
1
1
  import { cp, mkdir, readFile, rm } from 'node:fs/promises';
2
- import { dirname, join } from 'node:path';
2
+ import { basename, dirname, join } from 'node:path';
3
3
 
4
4
  function isSkillTarget(copy) {
5
5
  return String(copy?.target ?? copy?.path ?? '').startsWith('.agents/skills/');
@@ -27,6 +27,26 @@ async function readManifest(root) {
27
27
  return JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8'));
28
28
  }
29
29
 
30
+ async function cacheProjectCopies(copies, sourceRoot, ruleRoot, label) {
31
+ const result = [];
32
+ for (const copy of copies.filter(keepProjectCopy)) {
33
+ if (sourceRoot === ruleRoot) {
34
+ result.push(copy);
35
+ continue;
36
+ }
37
+ const source = String(copy.source ?? '');
38
+ const cachedSource = join('.project-scaffolds', label, source);
39
+ const target = join(ruleRoot, cachedSource);
40
+ await mkdir(dirname(target), { recursive: true });
41
+ await cp(join(sourceRoot, source), target, {
42
+ recursive: copy.type === 'directory' || copy.directory === true,
43
+ force: true,
44
+ });
45
+ result.push({ ...copy, source: cachedSource });
46
+ }
47
+ return result;
48
+ }
49
+
30
50
  function runtimeCheckerPath(manifest, runtimeRoot) {
31
51
  if (manifest?.check?.command?.[0] !== 'node') return null;
32
52
  const target = String(manifest.check.command[1] ?? '');
@@ -51,16 +71,22 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
51
71
  }
52
72
  await materializeCopies(raw, ruleRoot, runtimeRoot);
53
73
 
74
+ const copies = await cacheProjectCopies(raw.copies ?? [], ruleRoot, ruleRoot, entry.id);
54
75
  let checkerPath = runtimeCheckerPath(raw, runtimeRoot);
55
76
  if (!checkerPath && raw.checker?.path && canonicalCheckRoot) {
56
77
  const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
57
78
  const implementationRoot = dirname(join(canonicalCheckRoot, relative));
58
79
  const implementationManifest = await readManifest(implementationRoot);
59
80
  await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
81
+ copies.push(...await cacheProjectCopies(
82
+ implementationManifest.copies ?? [],
83
+ implementationRoot,
84
+ ruleRoot,
85
+ basename(implementationRoot),
86
+ ));
60
87
  checkerPath = runtimeCheckerPath(implementationManifest, runtimeRoot);
61
88
  }
62
89
 
63
- const copies = (raw.copies ?? []).filter(keepProjectCopy);
64
90
  const markdownSections = (raw.markdownSections ?? []).filter(
65
91
  (section) => !String(section?.body ?? section?.content ?? '').includes('.agents/skills/'),
66
92
  );
@@ -70,7 +96,7 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
70
96
  version: entry.version ?? raw.version,
71
97
  ...(entry.contentHash ? { contentHash: entry.contentHash } : {}),
72
98
  ...(entry.revision ? { revision: entry.revision } : {}),
73
- copies,
99
+ copies: [...new Map(copies.map((copy) => [String(copy.target ?? copy.path ?? copy.source), copy])).values()],
74
100
  markdownSections,
75
101
  ...(checkerPath ? { check: { command: ['specdest-cache', entry.id] } } : {}),
76
102
  };