@specdest/devkit 0.3.0 → 0.3.1

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
@@ -21,3 +21,7 @@ npx @specdest/devkit doctor
21
21
  The CLI recognizes the supported Expo/Vite + Convex/Supabase stacks from the target repository's `package.json`. `.specdest/installed.json` and `.specdest/state.json` remain the committed project status used by the Base rules matrix.
22
22
 
23
23
  See [`docs/operations.md`](docs/operations.md) for cache, dashboard, CI, and release behavior.
24
+
25
+ ## Canonical cache runtime
26
+
27
+ Canonical authoring lives under `modules/**`. The CLI downloads those modules into the local Devkit cache and materializes their `.agents/skills/**` target layout **inside the cache** so checker-relative imports keep working without copying canonical skills/checkers into project repositories. `catalog/**` is compatibility/test data, not a rule-authoring source.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "src/cli.js"
@@ -25,10 +25,10 @@ function flags(args) {
25
25
  return { refresh: args.includes('--refresh'), json: args.includes('--json') };
26
26
  }
27
27
 
28
- async function cachedManifest(source, entry, canonicalCheckRoot, { offline = false } = {}) {
28
+ async function cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline = false } = {}) {
29
29
  if (offline && !(await source.hasModule(entry.id, entry.version))) return null;
30
30
  const root = await source.module(entry.id, entry.version);
31
- return await prepareCachedManifest(entry, root, canonicalCheckRoot);
31
+ return await prepareCachedManifest(entry, root, canonicalCheckRoot, checkerRuntimeRoot);
32
32
  }
33
33
 
34
34
  async function canonicalContext(projectRoot, source, options = {}) {
@@ -36,13 +36,20 @@ async function canonicalContext(projectRoot, source, options = {}) {
36
36
  const stack = await detectProjectStack(projectRoot);
37
37
  const applicable = applicableCatalogEntries(catalog.entries ?? [], stack);
38
38
  const canonicalCheck = (catalog.entries ?? []).find((entry) => entry.id === 'canonical-check');
39
+ const checkerRuntime = (catalog.entries ?? []).find((entry) => entry.id === 'checker-runtime');
39
40
  let canonicalCheckRoot = null;
41
+ let checkerRuntimeRoot = null;
40
42
  if (options.withCheckers && canonicalCheck) {
41
43
  if (!options.offline || await source.hasModule(canonicalCheck.id, canonicalCheck.version)) {
42
44
  canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version);
43
45
  }
44
46
  }
45
- return { catalog, stack, applicable, canonicalCheckRoot };
47
+ if (options.withCheckers && checkerRuntime) {
48
+ if (!options.offline || await source.hasModule(checkerRuntime.id, checkerRuntime.version)) {
49
+ checkerRuntimeRoot = await source.module(checkerRuntime.id, checkerRuntime.version);
50
+ }
51
+ }
52
+ return { catalog, stack, applicable, canonicalCheckRoot, checkerRuntimeRoot };
46
53
  }
47
54
 
48
55
  export async function canonicalStatus(projectRoot, source, options = {}) {
@@ -71,15 +78,15 @@ export async function canonicalStatus(projectRoot, source, options = {}) {
71
78
 
72
79
  export async function canonicalSync(projectRoot, source) {
73
80
  const current = await readInstalledState(projectRoot);
74
- const { stack, applicable, canonicalCheckRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
81
+ const { stack, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
75
82
  const changed = [];
76
83
  for (const entry of applicable) {
77
- const prepared = await cachedManifest(source, entry, canonicalCheckRoot);
84
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
78
85
  const installed = current.installed[entry.id];
79
86
  if (!installed) {
80
87
  await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
81
88
  changed.push({ id: entry.id, action: 'installed', version: entry.version });
82
- } else if (installed.version !== entry.version || installed.contentHash !== entry.contentHash) {
89
+ } else if (installed.version !== entry.version || installed.contentHash !== entry.contentHash || installed.check?.command?.[0] !== 'specdest-cache') {
83
90
  await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
84
91
  changed.push({ id: entry.id, action: 'updated', version: entry.version });
85
92
  }
@@ -89,7 +96,7 @@ export async function canonicalSync(projectRoot, source) {
89
96
 
90
97
  export async function canonicalCheck(projectRoot, source) {
91
98
  const current = await readInstalledState(projectRoot);
92
- const { applicable, canonicalCheckRoot } = await canonicalContext(projectRoot, source, { offline: true, withCheckers: true });
99
+ const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { offline: true, withCheckers: true });
93
100
  const byId = new Map(applicable.map((entry) => [entry.id, entry]));
94
101
  const results = {};
95
102
  let exitCode = 0;
@@ -101,7 +108,7 @@ export async function canonicalCheck(projectRoot, source) {
101
108
  exitCode = 1;
102
109
  continue;
103
110
  }
104
- const prepared = await cachedManifest(source, entry, canonicalCheckRoot, { offline: true });
111
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline: true });
105
112
  if (!prepared?.checkerPath) continue;
106
113
  const execution = await execute('node', [prepared.checkerPath], projectRoot);
107
114
  results[id] = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
@@ -1,9 +1,36 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
1
+ import { cp, mkdir, readFile, rm } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
3
 
4
- function keepCopy(copy) {
5
- const target = String(copy?.target ?? copy?.path ?? '');
6
- return !/(^|\/)SKILL\.md$|(^|\/)check\.ts$|(^|\/)runtime\.ts$/u.test(target);
4
+ function isSkillTarget(copy) {
5
+ return String(copy?.target ?? copy?.path ?? '').startsWith('.agents/skills/');
6
+ }
7
+
8
+ function isProjectScaffold(copy) {
9
+ return copy?.mode === 'scaffold' || copy?.mode === 'create-only';
10
+ }
11
+
12
+ function keepProjectCopy(copy) {
13
+ return !isSkillTarget(copy) || isProjectScaffold(copy);
14
+ }
15
+
16
+ async function materializeCopies(manifest, sourceRoot, runtimeRoot) {
17
+ for (const copy of manifest?.copies ?? []) {
18
+ if (!isSkillTarget(copy) || isProjectScaffold(copy)) continue;
19
+ const source = join(sourceRoot, String(copy.source ?? ''));
20
+ const target = join(runtimeRoot, String(copy.target ?? copy.path ?? ''));
21
+ await mkdir(dirname(target), { recursive: true });
22
+ await cp(source, target, { recursive: copy.type === 'directory' || copy.directory === true, force: true });
23
+ }
24
+ }
25
+
26
+ async function readManifest(root) {
27
+ return JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8'));
28
+ }
29
+
30
+ function runtimeCheckerPath(manifest, runtimeRoot) {
31
+ if (manifest?.check?.command?.[0] !== 'node') return null;
32
+ const target = String(manifest.check.command[1] ?? '');
33
+ return target.startsWith('.agents/skills/') ? join(runtimeRoot, target) : null;
7
34
  }
8
35
 
9
36
  export function applicableCatalogEntries(entries, stack) {
@@ -13,29 +40,30 @@ export function applicableCatalogEntries(entries, stack) {
13
40
  .sort((a, b) => a.id.localeCompare(b.id));
14
41
  }
15
42
 
16
- export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot) {
17
- const raw = JSON.parse(await readFile(join(ruleRoot, 'manifest.json'), 'utf8'));
18
- const copies = (raw.copies ?? []).filter(keepCopy);
19
- const markdownSections = (raw.markdownSections ?? []).filter(
20
- (section) => !String(section?.body ?? section?.content ?? '').includes('.agents/skills/'),
21
- );
22
- let checkerPath = null;
23
- if (raw.check?.command?.[0] === 'node') {
24
- const local = String(raw.check.command[1] ?? '');
25
- const basename = local.split('/').at(-1);
26
- if (basename === 'check.ts') {
27
- try {
28
- checkerPath = join(ruleRoot, 'files', 'check.ts');
29
- await readFile(checkerPath, 'utf8');
30
- } catch {
31
- checkerPath = null;
32
- }
33
- }
43
+ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot, checkerRuntimeRoot = null) {
44
+ const raw = await readManifest(ruleRoot);
45
+ const runtimeRoot = join(ruleRoot, '.runtime');
46
+ await rm(runtimeRoot, { recursive: true, force: true });
47
+ await mkdir(runtimeRoot, { recursive: true });
48
+
49
+ if (checkerRuntimeRoot) {
50
+ await materializeCopies(await readManifest(checkerRuntimeRoot), checkerRuntimeRoot, runtimeRoot);
34
51
  }
52
+ await materializeCopies(raw, ruleRoot, runtimeRoot);
53
+
54
+ let checkerPath = runtimeCheckerPath(raw, runtimeRoot);
35
55
  if (!checkerPath && raw.checker?.path && canonicalCheckRoot) {
36
56
  const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
37
- checkerPath = join(canonicalCheckRoot, relative);
57
+ const implementationRoot = dirname(join(canonicalCheckRoot, relative));
58
+ const implementationManifest = await readManifest(implementationRoot);
59
+ await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
60
+ checkerPath = runtimeCheckerPath(implementationManifest, runtimeRoot);
38
61
  }
62
+
63
+ const copies = (raw.copies ?? []).filter(keepProjectCopy);
64
+ const markdownSections = (raw.markdownSections ?? []).filter(
65
+ (section) => !String(section?.body ?? section?.content ?? '').includes('.agents/skills/'),
66
+ );
39
67
  const manifest = {
40
68
  ...raw,
41
69
  kind: raw.kind ?? entry.kind ?? 'rule',
@@ -8,7 +8,7 @@ import { removeMarkdownSection, resolveProjectPath, upsertMarkdownSection } from
8
8
  const INSTALLED_PATH = '.specdest/installed.json';
9
9
  const STATE_PATH = '.specdest/state.json';
10
10
  const SCRIPT_PHASES = new Set(['pre_install', 'post_install', 'pre_sync', 'post_sync', 'pre_remove', 'post_remove']);
11
- const OP_TYPES = new Set(['copy_file', 'copy_directory', 'managed_section', 'json_set', 'json_merge', 'yaml_set', 'yaml_merge', 'env_set', 'env_remove', 'delete_owned_artifact', 'run_custom_script', 'run_script_file']);
11
+ const OP_TYPES = new Set(['copy_file', 'scaffold_file', 'copy_directory', 'managed_section', 'json_set', 'json_merge', 'yaml_set', 'yaml_merge', 'env_set', 'env_remove', 'delete_owned_artifact', 'run_custom_script', 'run_script_file']);
12
12
  const clone = (value) => value === undefined ? undefined : JSON.parse(JSON.stringify(value));
13
13
  const hash = (value) => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value)).digest('hex');
14
14
  const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
@@ -77,7 +77,7 @@ function normalizeManifest(manifest) {
77
77
  : undefined);
78
78
  for (const copy of manifest?.copies ?? []) {
79
79
  operations.push({
80
- type: copy.type === 'directory' || copy.directory === true ? 'copy_directory' : 'copy_file',
80
+ type: copy.type === 'directory' || copy.directory === true ? 'copy_directory' : copy.mode === 'scaffold' || copy.mode === 'create-only' ? 'scaffold_file' : 'copy_file',
81
81
  source: copy.source,
82
82
  path: copy.target ?? copy.path,
83
83
  mode: copy.mode,
@@ -324,6 +324,22 @@ async function claimFile(context, sourcePath, destination, touched) {
324
324
  async function applyOperation(op, context, touched) {
325
325
  const { projectRoot, payloadRoot } = context;
326
326
  if (op.type === 'copy_file') return claimFile(context, payloadPath(payloadRoot, op.source), op.path, touched);
327
+ if (op.type === 'scaffold_file') {
328
+ const target = resolveProjectPath(projectRoot, op.path);
329
+ const key = ownershipKey('file', op.path);
330
+ const prior = context.prior[key];
331
+ if (prior) {
332
+ // Reclassifying a formerly managed file as a scaffold intentionally hands
333
+ // ownership to the project. Preserve whatever the project currently has.
334
+ delete context.next[key];
335
+ touched.add(key);
336
+ return;
337
+ }
338
+ if (!(await exists(target))) {
339
+ await writeText(projectRoot, op.path, await readFile(payloadPath(payloadRoot, op.source), 'utf8'));
340
+ }
341
+ return;
342
+ }
327
343
  if (op.type === 'copy_directory') {
328
344
  const sourceRoot = payloadPath(payloadRoot, op.source);
329
345
  const walk = async (dir, prefix = '') => {