@specdest/devkit 0.2.2 → 0.3.0

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.
Files changed (138) hide show
  1. package/README.md +15 -20
  2. package/package.json +4 -4
  3. package/src/canonical-project-operations.js +157 -0
  4. package/src/canonical-project.js +50 -0
  5. package/src/canonical-source.js +114 -0
  6. package/src/cli.js +2 -2
  7. package/src/git-catalog.js +105 -0
  8. package/src/index.js +6 -2
  9. package/src/project-operations.js +65 -6
  10. package/src/remote-installer.js +462 -0
  11. package/src/sync-core.js +20 -7
  12. package/catalog/README.md +0 -11
  13. package/catalog/modules/backend-convex/manifest.json +0 -14
  14. package/catalog/modules/backend-convex-expo/manifest.json +0 -11
  15. package/catalog/modules/backend-supabase/manifest.json +0 -15
  16. package/catalog/modules/backend-supabase-expo/manifest.json +0 -11
  17. package/catalog/modules/checker-runtime/config.ts +0 -25
  18. package/catalog/modules/checker-runtime/fs.ts +0 -48
  19. package/catalog/modules/checker-runtime/manifest.json +0 -29
  20. package/catalog/modules/checker-runtime/runtime.ts +0 -79
  21. package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +0 -33
  22. package/catalog/modules/devflow/.devflow.json +0 -10
  23. package/catalog/modules/devflow/manifest.json +0 -35
  24. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +0 -85
  25. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +0 -130
  26. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +0 -7
  27. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +0 -36
  28. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +0 -143
  29. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +0 -43
  30. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +0 -25
  31. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +0 -66
  32. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +0 -146
  33. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +0 -56
  34. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +0 -6
  35. package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +0 -103
  36. package/catalog/modules/e2e-playwright/manifest.json +0 -206
  37. package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +0 -39
  38. package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +0 -107
  39. package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +0 -27
  40. package/catalog/modules/local-log/AGENTS.local-log.md +0 -13
  41. package/catalog/modules/local-log/docs/features/local-logging/README.md +0 -70
  42. package/catalog/modules/local-log/manifest.json +0 -39
  43. package/catalog/modules/local-log/tmp/logs/.gitignore +0 -2
  44. package/catalog/modules/local-log/tools/local-log/README.md +0 -47
  45. package/catalog/modules/local-log/tools/local-log/local-log.mjs +0 -241
  46. package/catalog/modules/stack-common-vite/manifest.json +0 -16
  47. package/catalog/modules/stack-expo-convex/manifest.json +0 -31
  48. package/catalog/modules/stack-expo-supabase/manifest.json +0 -44
  49. package/catalog/modules/stack-vite-convex/manifest.json +0 -32
  50. package/catalog/modules/stack-vite-supabase/manifest.json +0 -45
  51. package/catalog/rules/abac-permissions-convex/SKILL.md +0 -17
  52. package/catalog/rules/abac-permissions-convex/check.ts +0 -87
  53. package/catalog/rules/abac-permissions-convex/manifest.json +0 -33
  54. package/catalog/rules/abac-permissions-supabase/SKILL.md +0 -17
  55. package/catalog/rules/abac-permissions-supabase/check.ts +0 -87
  56. package/catalog/rules/abac-permissions-supabase/manifest.json +0 -33
  57. package/catalog/rules/convex-multi-presentation/SKILL.md +0 -47
  58. package/catalog/rules/convex-multi-presentation/check.ts +0 -205
  59. package/catalog/rules/convex-multi-presentation/manifest.json +0 -47
  60. package/catalog/rules/convex-multi-presentation/policy.ts +0 -261
  61. package/catalog/rules/design-rules/SKILL.md +0 -12
  62. package/catalog/rules/design-rules/check.ts +0 -84
  63. package/catalog/rules/design-rules/config.json +0 -5
  64. package/catalog/rules/design-rules/manifest.json +0 -38
  65. package/catalog/rules/e2e-test-rules/SKILL.md +0 -46
  66. package/catalog/rules/e2e-test-rules/check.ts +0 -145
  67. package/catalog/rules/e2e-test-rules/config.json +0 -32
  68. package/catalog/rules/e2e-test-rules/manifest.json +0 -38
  69. package/catalog/rules/error-handling-rules/SKILL.md +0 -21
  70. package/catalog/rules/error-handling-rules/check.ts +0 -73
  71. package/catalog/rules/error-handling-rules/manifest.json +0 -33
  72. package/catalog/rules/layers-and-contracts/SKILL.md +0 -36
  73. package/catalog/rules/layers-and-contracts/check.ts +0 -266
  74. package/catalog/rules/layers-and-contracts/manifest.json +0 -33
  75. package/catalog/rules/layers-and-contracts-convex/SKILL.md +0 -49
  76. package/catalog/rules/layers-and-contracts-convex/check.ts +0 -289
  77. package/catalog/rules/layers-and-contracts-convex/manifest.json +0 -38
  78. package/catalog/rules/layers-and-contracts-convex/policy.ts +0 -68
  79. package/catalog/rules/layers-and-contracts-supabase/SKILL.md +0 -52
  80. package/catalog/rules/layers-and-contracts-supabase/check.ts +0 -371
  81. package/catalog/rules/layers-and-contracts-supabase/manifest.json +0 -38
  82. package/catalog/rules/layers-and-contracts-supabase/policy.ts +0 -68
  83. package/catalog/rules/module-size-rules/SKILL.md +0 -5
  84. package/catalog/rules/module-size-rules/check.ts +0 -144
  85. package/catalog/rules/module-size-rules/config.json +0 -6
  86. package/catalog/rules/module-size-rules/manifest.json +0 -38
  87. package/catalog/rules/module-size-rules-convex/SKILL.md +0 -5
  88. package/catalog/rules/module-size-rules-convex/check.ts +0 -146
  89. package/catalog/rules/module-size-rules-convex/config.json +0 -6
  90. package/catalog/rules/module-size-rules-convex/manifest.json +0 -38
  91. package/catalog/rules/module-size-rules-supabase/SKILL.md +0 -5
  92. package/catalog/rules/module-size-rules-supabase/check.ts +0 -146
  93. package/catalog/rules/module-size-rules-supabase/config.json +0 -12
  94. package/catalog/rules/module-size-rules-supabase/manifest.json +0 -38
  95. package/catalog/rules/mutation-command-rules/SKILL.md +0 -15
  96. package/catalog/rules/mutation-command-rules/check.ts +0 -30
  97. package/catalog/rules/mutation-command-rules/config.json +0 -19
  98. package/catalog/rules/mutation-command-rules/manifest.json +0 -38
  99. package/catalog/rules/nearby-contracts/SKILL.md +0 -18
  100. package/catalog/rules/nearby-contracts/check.ts +0 -138
  101. package/catalog/rules/nearby-contracts/config.json +0 -10
  102. package/catalog/rules/nearby-contracts/manifest.json +0 -38
  103. package/catalog/rules/no-raw-click-buttons/SKILL.md +0 -5
  104. package/catalog/rules/no-raw-click-buttons/check.ts +0 -37
  105. package/catalog/rules/no-raw-click-buttons/manifest.json +0 -33
  106. package/catalog/rules/public-api-export-barrels/SKILL.md +0 -45
  107. package/catalog/rules/public-api-export-barrels/check.ts +0 -73
  108. package/catalog/rules/public-api-export-barrels/config.json +0 -4
  109. package/catalog/rules/public-api-export-barrels/manifest.json +0 -38
  110. package/catalog/rules/route-tree-fresh/SKILL.md +0 -16
  111. package/catalog/rules/route-tree-fresh/check.ts +0 -66
  112. package/catalog/rules/route-tree-fresh/manifest.json +0 -33
  113. package/catalog/rules/strict-typescript/SKILL.md +0 -3
  114. package/catalog/rules/strict-typescript/check.ts +0 -119
  115. package/catalog/rules/strict-typescript/manifest.json +0 -33
  116. package/catalog/rules/supabase-contracts/SKILL.md +0 -3
  117. package/catalog/rules/supabase-contracts/check.ts +0 -172
  118. package/catalog/rules/supabase-contracts/manifest.json +0 -33
  119. package/catalog/rules/supabase-declarative-schema/SKILL.md +0 -30
  120. package/catalog/rules/supabase-declarative-schema/check.ts +0 -262
  121. package/catalog/rules/supabase-declarative-schema/config.json +0 -8
  122. package/catalog/rules/supabase-declarative-schema/manifest.json +0 -38
  123. package/catalog/rules/tanstack-form-rules/SKILL.md +0 -11
  124. package/catalog/rules/tanstack-form-rules/check.ts +0 -58
  125. package/catalog/rules/tanstack-form-rules/manifest.json +0 -33
  126. package/catalog/rules/unit-test-rules/SKILL.md +0 -55
  127. package/catalog/rules/unit-test-rules/check.ts +0 -132
  128. package/catalog/rules/unit-test-rules/config.json +0 -22
  129. package/catalog/rules/unit-test-rules/manifest.json +0 -38
  130. package/catalog/rules/unit-test-rules-convex/SKILL.md +0 -41
  131. package/catalog/rules/unit-test-rules-convex/check.ts +0 -418
  132. package/catalog/rules/unit-test-rules-convex/manifest.json +0 -33
  133. package/catalog/rules/unit-test-rules-supabase/SKILL.md +0 -40
  134. package/catalog/rules/unit-test-rules-supabase/check.ts +0 -492
  135. package/catalog/rules/unit-test-rules-supabase/manifest.json +0 -33
  136. package/catalog/rules/workstation-controller-rules/SKILL.md +0 -22
  137. package/catalog/rules/workstation-controller-rules/check.ts +0 -108
  138. package/catalog/rules/workstation-controller-rules/manifest.json +0 -33
package/README.md CHANGED
@@ -1,28 +1,23 @@
1
- # Specdest Devkit
1
+ # @specdest/devkit
2
2
 
3
- Canonical engineering standards, reusable modules, installers, migrations, checkers, and CLI for Specdest projects.
3
+ `@specdest/devkit` is the canonical Devkit CLI for Specdest repositories.
4
4
 
5
- ## CLI
5
+ The npm package contains only the CLI/core runtime. Canonical rules stay in the private Devkit GitHub repository and are fetched into a local machine cache when needed. Rule changes therefore do not require an npm release.
6
6
 
7
- The publishable package is `@specdest/devkit` and exposes the `specdest` binary.
7
+ ## Commands
8
8
 
9
- ```sh
10
- specdest install <rule-or-module>
11
- specdest status
12
- specdest sync
13
- specdest check
9
+ ```bash
10
+ npx @specdest/devkit status
11
+ npx @specdest/devkit sync
12
+ npx @specdest/devkit check
13
+ npx @specdest/devkit doctor
14
14
  ```
15
15
 
16
- The core command surface is implemented. Deferred convenience commands such as `fix` and module add/remove/list are intentionally excluded until real usage justifies them.
16
+ - `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.
17
+ - `sync` refreshes the canonical catalog, downloads only missing rule-cache entries, installs missing applicable rules, and updates outdated ones.
18
+ - `check` is local-only. It executes canonical checkers from the local Devkit cache and updates `.specdest/state.json`.
19
+ - `doctor` reports project-stack/cache setup problems.
17
20
 
18
- ## Workspace
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.
19
22
 
20
- - repository root: publishable `@specdest/devkit` package and CLI
21
- - `docs`: canonical architecture/implementation documentation
22
- - `scripts`: repository validation helpers
23
-
24
- Operational install, controller/GitHub authentication, npm Trusted Publishing, Base publication configuration, release verification, and recovery procedures are documented in [`docs/operations.md`](docs/operations.md).
25
-
26
- Releases publish one tested immutable bundle: the npm tarball, catalog snapshot, release metadata, and checksums. npm publication and Base catalog propagation are separate: a Base outage cannot turn an already-published npm version into a failed release, and propagation can be retried independently.
27
-
28
- Devkit is Node 24+ only. Rule checkers are strict TypeScript executed directly by Node; Deno and auxiliary TypeScript runtimes are intentionally not required.
23
+ See [`docs/operations.md`](docs/operations.md) for cache, dashboard, CI, and release behavior.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "src/cli.js"
@@ -10,8 +10,7 @@
10
10
  "./cli": "./src/cli.js"
11
11
  },
12
12
  "files": [
13
- "src",
14
- "catalog"
13
+ "src"
15
14
  ],
16
15
  "engines": {
17
16
  "node": ">=24.0.0",
@@ -31,7 +30,8 @@
31
30
  "typecheck": "node scripts/typecheck-checkers.mjs",
32
31
  "release:build": "node scripts/build-release-artifacts.mjs",
33
32
  "smoke:artifact": "node scripts/smoke-package-artifact.mjs",
34
- "catalog:propagate": "node scripts/propagate-catalog-release.mjs"
33
+ "runtime:build": "node scripts/build-remote-runtime.mjs",
34
+ "catalog:git": "node scripts/export-git-catalog.mjs"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^24.0.0",
@@ -0,0 +1,157 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+
5
+ import { createCanonicalSource, detectProjectStack } from './canonical-source.js';
6
+ import { applicableCatalogEntries, prepareCachedManifest } from './canonical-project.js';
7
+ import { installRule, syncRule } from './remote-installer.js';
8
+ import { readInstalledState, writeChecksState } from './sync-core.js';
9
+
10
+ function execute(command, args, cwd) {
11
+ return new Promise((resolve, reject) => {
12
+ const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
13
+ let stdout = ''; let stderr = '';
14
+ child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8');
15
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
16
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
17
+ child.on('error', reject);
18
+ child.on('close', (code) => resolve({ exitCode: code ?? 1, stdout, stderr }));
19
+ });
20
+ }
21
+
22
+ function flags(args) {
23
+ const known = new Set(['--refresh', '--json']);
24
+ for (const arg of args) if (!known.has(arg)) throw new Error(`Unknown option: ${arg}`);
25
+ return { refresh: args.includes('--refresh'), json: args.includes('--json') };
26
+ }
27
+
28
+ async function cachedManifest(source, entry, canonicalCheckRoot, { offline = false } = {}) {
29
+ if (offline && !(await source.hasModule(entry.id, entry.version))) return null;
30
+ const root = await source.module(entry.id, entry.version);
31
+ return await prepareCachedManifest(entry, root, canonicalCheckRoot);
32
+ }
33
+
34
+ async function canonicalContext(projectRoot, source, options = {}) {
35
+ const catalog = await source.catalog({ refresh: options.refresh ?? false });
36
+ const stack = await detectProjectStack(projectRoot);
37
+ const applicable = applicableCatalogEntries(catalog.entries ?? [], stack);
38
+ const canonicalCheck = (catalog.entries ?? []).find((entry) => entry.id === 'canonical-check');
39
+ let canonicalCheckRoot = null;
40
+ if (options.withCheckers && canonicalCheck) {
41
+ if (!options.offline || await source.hasModule(canonicalCheck.id, canonicalCheck.version)) {
42
+ canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version);
43
+ }
44
+ }
45
+ return { catalog, stack, applicable, canonicalCheckRoot };
46
+ }
47
+
48
+ export async function canonicalStatus(projectRoot, source, options = {}) {
49
+ const current = await readInstalledState(projectRoot);
50
+ const { stack, applicable } = await canonicalContext(projectRoot, source, options);
51
+ const installed = current.installed;
52
+ const rows = applicable.map((entry) => {
53
+ const found = installed[entry.id];
54
+ const state = !found ? 'missing' : found.version === entry.version ? 'current' : 'outdated';
55
+ return { id: entry.id, canonicalVersion: entry.version, installedVersion: found?.version ?? null, state };
56
+ });
57
+ const applicableIds = new Set(applicable.map((entry) => entry.id));
58
+ const installedNonApplicable = Object.keys(installed).filter((id) => !applicableIds.has(id)).sort();
59
+ return {
60
+ stack,
61
+ totals: {
62
+ applicable: rows.length,
63
+ current: rows.filter((row) => row.state === 'current').length,
64
+ missing: rows.filter((row) => row.state === 'missing').length,
65
+ outdated: rows.filter((row) => row.state === 'outdated').length,
66
+ },
67
+ rows,
68
+ installedNonApplicable,
69
+ };
70
+ }
71
+
72
+ export async function canonicalSync(projectRoot, source) {
73
+ const current = await readInstalledState(projectRoot);
74
+ const { stack, applicable, canonicalCheckRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
75
+ const changed = [];
76
+ for (const entry of applicable) {
77
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot);
78
+ const installed = current.installed[entry.id];
79
+ if (!installed) {
80
+ await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
81
+ changed.push({ id: entry.id, action: 'installed', version: entry.version });
82
+ } else if (installed.version !== entry.version || installed.contentHash !== entry.contentHash) {
83
+ await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
84
+ changed.push({ id: entry.id, action: 'updated', version: entry.version });
85
+ }
86
+ }
87
+ return { stack, applicable: applicable.length, changed };
88
+ }
89
+
90
+ export async function canonicalCheck(projectRoot, source) {
91
+ const current = await readInstalledState(projectRoot);
92
+ const { applicable, canonicalCheckRoot } = await canonicalContext(projectRoot, source, { offline: true, withCheckers: true });
93
+ const byId = new Map(applicable.map((entry) => [entry.id, entry]));
94
+ const results = {};
95
+ let exitCode = 0;
96
+ for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
97
+ const entry = byId.get(id);
98
+ if (!entry || installed.kind !== 'rule') continue;
99
+ if (!(await source.hasModule(id, entry.version))) {
100
+ results[id] = { status: 'fail', exitCode: 1, stderr: 'Rule cache missing; run specdest sync first.' };
101
+ exitCode = 1;
102
+ continue;
103
+ }
104
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, { offline: true });
105
+ if (!prepared?.checkerPath) continue;
106
+ const execution = await execute('node', [prepared.checkerPath], projectRoot);
107
+ results[id] = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
108
+ if (execution.exitCode !== 0) exitCode = 1;
109
+ }
110
+ await writeChecksState(projectRoot, {
111
+ schemaVersion: 2,
112
+ checkedAt: new Date().toISOString(),
113
+ results: Object.fromEntries(Object.entries(results).map(([id, result]) => [id, { status: result.status }])),
114
+ });
115
+ return { exitCode, results };
116
+ }
117
+
118
+ export async function canonicalDoctor(projectRoot, source) {
119
+ const issues = [];
120
+ const stack = await detectProjectStack(projectRoot);
121
+ if (!stack) issues.push('Unable to detect a supported project stack.');
122
+ try { await source.catalog(); } catch (error) { issues.push(`Catalog unavailable: ${error.message}`); }
123
+ return { ok: issues.length === 0, stack, cacheRoot: source.cacheRoot, issues };
124
+ }
125
+
126
+ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), options = {}) {
127
+ const source = options.source ?? createCanonicalSource(options);
128
+ return {
129
+ status: async (args, io) => {
130
+ const parsed = flags(args);
131
+ const result = await canonicalStatus(projectRoot, source, { refresh: parsed.refresh });
132
+ if (parsed.json) io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
133
+ else io.stdout.write(`Stack: ${result.stack ?? 'unknown'}\nApplicable: ${result.totals.applicable} Current: ${result.totals.current} Missing: ${result.totals.missing} Outdated: ${result.totals.outdated}\n`);
134
+ return result.totals.missing || result.totals.outdated ? 1 : 0;
135
+ },
136
+ sync: async (args, io) => {
137
+ if (args.length) { io.stderr.write('Usage: specdest sync\n'); return 2; }
138
+ const result = await canonicalSync(projectRoot, source);
139
+ io.stdout.write(`Synced ${result.applicable} applicable rules; ${result.changed.length} changed.\n`);
140
+ for (const item of result.changed) io.stdout.write(`${item.action.toUpperCase()} ${item.id}@${item.version}\n`);
141
+ return 0;
142
+ },
143
+ check: async (args, io) => {
144
+ if (args.length) { io.stderr.write('Usage: specdest check\n'); return 2; }
145
+ const result = await canonicalCheck(projectRoot, source);
146
+ for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
147
+ return result.exitCode;
148
+ },
149
+ doctor: async (args, io) => {
150
+ if (args.length) { io.stderr.write('Usage: specdest doctor\n'); return 2; }
151
+ const result = await canonicalDoctor(projectRoot, source);
152
+ io.stdout.write(`Cache: ${result.cacheRoot}\nStack: ${result.stack ?? 'unknown'}\n`);
153
+ for (const issue of result.issues) io.stderr.write(`FAIL ${issue}\n`);
154
+ return result.ok ? 0 : 1;
155
+ },
156
+ };
157
+ }
@@ -0,0 +1,50 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+
4
+ function keepCopy(copy) {
5
+ const target = String(copy?.target ?? copy?.path ?? '');
6
+ return !/(^|\/)SKILL\.md$|(^|\/)check\.ts$|(^|\/)runtime\.ts$/u.test(target);
7
+ }
8
+
9
+ export function applicableCatalogEntries(entries, stack) {
10
+ return entries
11
+ .filter((entry) => entry.kind === 'rule')
12
+ .filter((entry) => !entry.applicableStacks?.length || (stack && entry.applicableStacks.includes(stack)))
13
+ .sort((a, b) => a.id.localeCompare(b.id));
14
+ }
15
+
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
+ }
34
+ }
35
+ if (!checkerPath && raw.checker?.path && canonicalCheckRoot) {
36
+ const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
37
+ checkerPath = join(canonicalCheckRoot, relative);
38
+ }
39
+ const manifest = {
40
+ ...raw,
41
+ kind: raw.kind ?? entry.kind ?? 'rule',
42
+ version: entry.version ?? raw.version,
43
+ ...(entry.contentHash ? { contentHash: entry.contentHash } : {}),
44
+ ...(entry.revision ? { revision: entry.revision } : {}),
45
+ copies,
46
+ markdownSections,
47
+ ...(checkerPath ? { check: { command: ['specdest-cache', entry.id] } } : {}),
48
+ };
49
+ return { manifest, checkerPath };
50
+ }
@@ -0,0 +1,114 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, join } from 'node:path';
4
+ import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
5
+
6
+ const DEFAULT_REPOSITORY = 'specdest-org/devkit';
7
+ const DEFAULT_REF = 'main';
8
+
9
+ async function exists(path) {
10
+ try { await stat(path); return true; } catch (error) { if (error?.code === 'ENOENT') return false; throw error; }
11
+ }
12
+
13
+ function defaultCacheRoot(env = process.env) {
14
+ return join(env.XDG_CACHE_HOME?.trim() || join(homedir(), '.cache'), 'specdest', 'devkit');
15
+ }
16
+
17
+ function run(command, args, options = {}) {
18
+ return new Promise((resolve, reject) => {
19
+ const child = spawn(command, args, { cwd: options.cwd, stdio: ['ignore', 'pipe', 'pipe'] });
20
+ let stdout = '';
21
+ let stderr = '';
22
+ child.stdout.setEncoding('utf8');
23
+ child.stderr.setEncoding('utf8');
24
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
25
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
26
+ child.on('error', reject);
27
+ child.on('close', (code) => code === 0 ? resolve(stdout) : reject(new Error(`${command} exited ${code}: ${stderr.trim()}`)));
28
+ });
29
+ }
30
+
31
+ async function ghJson(path, repository = DEFAULT_REPOSITORY, ref = DEFAULT_REF) {
32
+ const output = await run('gh', ['api', '--method', 'GET', `repos/${repository}/contents/${path}`, '-f', `ref=${ref}`]);
33
+ return JSON.parse(output);
34
+ }
35
+
36
+ export async function fetchGitHubCatalog(options = {}) {
37
+ const response = await ghJson('catalog.json', options.repository, options.ref);
38
+ if (response.type !== 'file' || !response.content) throw new Error('Canonical Devkit catalog not found');
39
+ return JSON.parse(Buffer.from(response.content.replace(/\n/g, ''), 'base64').toString('utf8'));
40
+ }
41
+
42
+ export async function fetchGitHubModule(id, options = {}) {
43
+ const files = [];
44
+ const pending = [`modules/${id}`];
45
+ while (pending.length) {
46
+ const path = pending.pop();
47
+ const entries = await ghJson(path, options.repository, options.ref);
48
+ if (!Array.isArray(entries)) throw new Error(`Canonical module directory not found: ${id}`);
49
+ for (const entry of entries) {
50
+ if (entry.type === 'dir') pending.push(entry.path);
51
+ else if (entry.type === 'file') {
52
+ const file = await ghJson(entry.path, options.repository, options.ref);
53
+ files.push({
54
+ path: entry.path.slice(`modules/${id}/`.length),
55
+ content: Buffer.from(String(file.content ?? '').replace(/\n/g, ''), 'base64').toString('utf8'),
56
+ });
57
+ }
58
+ }
59
+ }
60
+ return { files: files.sort((a, b) => a.path.localeCompare(b.path)) };
61
+ }
62
+
63
+ async function writePayload(root, files) {
64
+ for (const file of files) {
65
+ const target = join(root, file.path);
66
+ await mkdir(dirname(target), { recursive: true });
67
+ await writeFile(target, file.content, 'utf8');
68
+ }
69
+ }
70
+
71
+ export function createCanonicalSource(options = {}) {
72
+ const cacheRoot = options.cacheRoot ?? defaultCacheRoot(options.env);
73
+ const catalogPath = join(cacheRoot, 'catalog.json');
74
+ const fetchCatalog = options.fetchCatalog ?? (() => fetchGitHubCatalog(options));
75
+ const fetchModule = options.fetchModule ?? ((id) => fetchGitHubModule(id, options));
76
+ return {
77
+ cacheRoot,
78
+ cachedModulePath(id, version) { return join(cacheRoot, 'rules', id, version); },
79
+ async hasModule(id, version) { return await exists(join(cacheRoot, 'rules', id, version, '.complete')); },
80
+ async catalog({ refresh = false } = {}) {
81
+ if (!refresh && await exists(catalogPath)) return JSON.parse(await readFile(catalogPath, 'utf8'));
82
+ const catalog = await fetchCatalog();
83
+ await mkdir(cacheRoot, { recursive: true });
84
+ await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8');
85
+ return catalog;
86
+ },
87
+ async module(id, version, { refresh = false } = {}) {
88
+ const root = join(cacheRoot, 'rules', id, version);
89
+ const marker = join(root, '.complete');
90
+ if (!refresh && await exists(marker)) return root;
91
+ if (await exists(marker)) return root;
92
+ const payload = await fetchModule(id);
93
+ await mkdir(root, { recursive: true });
94
+ await writePayload(root, payload.files ?? []);
95
+ await writeFile(marker, `${id}@${version}\n`, 'utf8');
96
+ return root;
97
+ },
98
+ };
99
+ }
100
+
101
+ export async function detectProjectStack(projectRoot) {
102
+ let pkg = {};
103
+ try { pkg = JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8')); } catch (error) { if (error?.code !== 'ENOENT') throw error; }
104
+ const deps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
105
+ const expo = Boolean(deps.expo);
106
+ const vite = Boolean(deps.vite || deps['@vitejs/plugin-react']);
107
+ const convex = Boolean(deps.convex);
108
+ const supabase = Boolean(deps['@supabase/supabase-js']);
109
+ if (expo && convex) return 'stack-expo-convex';
110
+ if (expo && supabase) return 'stack-expo-supabase';
111
+ if (vite && convex) return 'stack-vite-convex';
112
+ if (vite && supabase) return 'stack-vite-supabase';
113
+ return null;
114
+ }
package/src/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { runCli } from './index.js';
3
- import { createProjectCommandHandlers } from './project-operations.js';
3
+ import { createCanonicalCommandHandlers } from './canonical-project-operations.js';
4
4
 
5
5
  try {
6
- const exitCode = await runCli(process.argv.slice(2), process, createProjectCommandHandlers());
6
+ const exitCode = await runCli(process.argv.slice(2), process, createCanonicalCommandHandlers());
7
7
  process.exitCode = exitCode;
8
8
  } catch (error) {
9
9
  process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
@@ -0,0 +1,105 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readdir, readFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+
5
+ const sha256 = (value) => createHash('sha256').update(value).digest('hex');
6
+
7
+ const legacyImplementationFamilies = new Map([
8
+ ['abac-permissions-supabase', ['abac-permissions-convex', 'abac-permissions-supabase']],
9
+ ['layers-and-contracts', ['layers-and-contracts', 'layers-and-contracts-convex', 'layers-and-contracts-supabase']],
10
+ ['unit-test-rules', ['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase']],
11
+ ['unit-test-rules-supabase', ['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase']],
12
+ ]);
13
+
14
+ function legacyImplementationIds(manifest) {
15
+ const implementation = manifest.checker?.implementation;
16
+ if (!implementation || implementation === manifest.id) return [];
17
+ return legacyImplementationFamilies.get(implementation) ?? [implementation];
18
+ }
19
+
20
+ async function moduleFiles(root) {
21
+ const files = [];
22
+ const walk = async (dir, prefix = '') => {
23
+ for (const entry of (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
24
+ const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
25
+ if (entry.isDirectory()) await walk(join(dir, entry.name), relative);
26
+ else if (entry.isFile()) files.push({ path: relative, content: await readFile(join(dir, entry.name), 'utf8') });
27
+ }
28
+ };
29
+ await walk(root);
30
+ return files.sort((a, b) => a.path.localeCompare(b.path));
31
+ }
32
+
33
+ function title(content, id) {
34
+ return content.match(/^#\s+(.+)$/mu)?.[1]?.trim() || id;
35
+ }
36
+
37
+ function canonicalVersion(manifest) {
38
+ const version = String(manifest.version ?? '');
39
+ if (!/^\d+\.\d+\.\d+$/u.test(version)) {
40
+ throw new Error(`Canonical catalog entry requires SemVer version: ${manifest.id}`);
41
+ }
42
+ return version;
43
+ }
44
+
45
+ function catalogKind(manifest) {
46
+ const kind = manifest.kind ?? 'rule';
47
+ if (!['rule', 'module'].includes(kind)) throw new Error(`Invalid canonical kind: ${manifest.id}`);
48
+ return kind;
49
+ }
50
+
51
+ function notApplicableRuleIds(manifest) {
52
+ if (!Array.isArray(manifest.notApplicableRuleIds)) return undefined;
53
+ return [...new Set(manifest.notApplicableRuleIds.map(String))].sort();
54
+ }
55
+
56
+ function applicableStacks(manifest) {
57
+ if (manifest.scope !== 'Stack-specific') return undefined;
58
+ if (!Array.isArray(manifest.applicableStacks) || manifest.applicableStacks.length === 0) {
59
+ throw new Error(`Stack-specific rule requires applicableStacks: ${manifest.id}`);
60
+ }
61
+ return [...new Set(manifest.applicableStacks.map(String))].sort();
62
+ }
63
+
64
+ export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'working-tree' }) {
65
+ const directories = (await readdir(modulesRoot, { withFileTypes: true }))
66
+ .filter((entry) => entry.isDirectory())
67
+ .sort((a, b) => a.name.localeCompare(b.name));
68
+ const entries = [];
69
+ for (const directory of directories) {
70
+ const root = join(modulesRoot, directory.name);
71
+ const files = await moduleFiles(root);
72
+ const manifestFile = files.find((file) => file.path === 'manifest.json');
73
+ if (!manifestFile) throw new Error(`Missing manifest.json: ${directory.name}`);
74
+ const manifest = JSON.parse(manifestFile.content);
75
+ if (manifest.id !== directory.name) throw new Error(`Module id/path mismatch: ${directory.name}`);
76
+ const contentHash = sha256(JSON.stringify(files));
77
+ const guidance = files.find((file) => /(^|\/)rule\.md$/u.test(file.path) || /(^|\/)SKILL\.md$/u.test(file.path))?.content ?? '';
78
+ const kind = catalogKind(manifest);
79
+ entries.push({
80
+ id: manifest.id,
81
+ kind,
82
+ version: canonicalVersion(manifest),
83
+ name: title(guidance, manifest.id),
84
+ content: guidance,
85
+ group: kind === 'rule' ? 'Rules' : 'Modules',
86
+ order: entries.length + 1,
87
+ source: 'private-devkit-git',
88
+ revision: repositoryRevision,
89
+ contentHash,
90
+ ...(kind === 'rule' ? { legacyInstalledIds: legacyImplementationIds(manifest) } : {}),
91
+ ...(kind === 'rule' ? { enforcement: String(manifest.enforcement ?? 'guidance') } : {}),
92
+ ...(kind === 'rule' && applicableStacks(manifest) ? { applicableStacks: applicableStacks(manifest) } : {}),
93
+ ...(kind === 'module' && notApplicableRuleIds(manifest)
94
+ ? { notApplicableRuleIds: notApplicableRuleIds(manifest) }
95
+ : {}),
96
+ });
97
+ }
98
+ const ruleIds = new Set(entries.filter((entry) => entry.kind === 'rule').map((entry) => entry.id));
99
+ for (const entry of entries) {
100
+ for (const ruleId of entry.notApplicableRuleIds ?? []) {
101
+ if (!ruleIds.has(ruleId)) throw new Error(`Unknown not-applicable rule: ${entry.id}:${ruleId}`);
102
+ }
103
+ }
104
+ return { schemaVersion: 1, package: { name: '@specdest/devkit', version: repositoryRevision }, entries };
105
+ }
package/src/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  export * from './catalog.js';
2
+ export * from './canonical-source.js';
3
+ export * from './canonical-project.js';
4
+ export * from './canonical-project-operations.js';
2
5
  export * from './installer-primitives.js';
3
6
  export * from './project-operations.js';
7
+ export * from './remote-installer.js';
4
8
  export * from './setup-requirements.js';
5
9
  export * from './shared-file.js';
6
10
  export * from './sync-core.js';
7
11
 
8
- export const COMMAND_NAMES = ['install', 'status', 'sync', 'check'];
12
+ export const COMMAND_NAMES = ['status', 'sync', 'check', 'doctor'];
9
13
 
10
- const HELP = `Usage: specdest <command> [arguments]\n\nCommands:\n install <rule-or-module> Install a new rule or module\n status Show installed Specdest state\n sync Reconcile installed rules/modules\n check Run installed rule checks\n`;
14
+ 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 Run installed rule checks from the local cache\n doctor Diagnose project/cache setup\n`;
11
15
 
12
16
  export async function runCli(argv, io = process, handlers = {}) {
13
17
  const [command, ...args] = argv;
@@ -1,6 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { readdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
2
4
 
3
- import { resolveCatalogSelection } from './catalog.js';
5
+ import { listCatalogEntries, loadCatalogEntry, resolveCatalogSelection } from './catalog.js';
4
6
  import { evaluateSetupRequirements } from './setup-requirements.js';
5
7
  import {
6
8
  applySyncPlan,
@@ -24,6 +26,53 @@ function defaultExecutor({ command, args, cwd }) {
24
26
  });
25
27
  }
26
28
 
29
+ async function hydrateInstalledCheckMetadata(installed, options = {}) {
30
+ const catalogIds = new Set((await listCatalogEntries(options)).map((entry) => entry.id));
31
+ const hydrated = {};
32
+ for (const [id, entry] of Object.entries(installed)) {
33
+ if (entry.check || !catalogIds.has(id)) {
34
+ hydrated[id] = entry;
35
+ continue;
36
+ }
37
+ const catalogEntry = await loadCatalogEntry(id, options);
38
+ hydrated[id] = catalogEntry.check ? { ...entry, check: catalogEntry.check } : entry;
39
+ }
40
+ return hydrated;
41
+ }
42
+
43
+ async function auditSkillOwnership(projectRoot, installed) {
44
+ const allowedDirectories = new Set();
45
+ if (installed['checker-runtime']) allowedDirectories.add('shared');
46
+
47
+ for (const [id, entry] of Object.entries(installed)) {
48
+ allowedDirectories.add(id);
49
+ for (const suffix of ['-supabase', '-convex', '-expo']) {
50
+ if (id.endsWith(suffix)) allowedDirectories.add(id.slice(0, -suffix.length));
51
+ }
52
+ for (const value of entry.check?.command ?? []) {
53
+ const match = String(value).match(/^\.agents\/skills\/([^/]+)\//u);
54
+ if (match?.[1]) allowedDirectories.add(match[1]);
55
+ }
56
+ }
57
+
58
+ let entries;
59
+ try {
60
+ entries = await readdir(join(projectRoot, '.agents', 'skills'), { withFileTypes: true });
61
+ } catch (error) {
62
+ if (error?.code === 'ENOENT') return { unownedSkillDirectories: [] };
63
+ throw error;
64
+ }
65
+ const actualDirectories = entries
66
+ .filter((entry) => entry.isDirectory())
67
+ .map((entry) => entry.name)
68
+ .sort();
69
+ return {
70
+ unownedSkillDirectories: actualDirectories.filter(
71
+ (directory) => !allowedDirectories.has(directory),
72
+ ),
73
+ };
74
+ }
75
+
27
76
  export async function installCatalogEntry(projectRoot, id, options = {}) {
28
77
  const current = await readInstalledState(projectRoot);
29
78
  const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
@@ -63,18 +112,22 @@ export async function getProjectStatus(projectRoot, options = {}) {
63
112
 
64
113
  export async function runInstalledChecks(projectRoot, options = {}) {
65
114
  const current = await readInstalledState(projectRoot);
66
- const entries = await resolveCatalogSelection(Object.keys(current.installed), options);
115
+ const installed = await hydrateInstalledCheckMetadata(current.installed, options);
67
116
  const executor = options.executor ?? defaultExecutor;
68
117
  const results = {};
69
- let exitCode = 0;
118
+ const integrity = await auditSkillOwnership(projectRoot, installed);
119
+ let exitCode = integrity.unownedSkillDirectories.length ? 1 : 0;
70
120
 
71
- for (const entry of entries) {
121
+ const installedEntries = Object.entries(installed).sort(([left], [right]) =>
122
+ left.localeCompare(right),
123
+ );
124
+ for (const [id, entry] of installedEntries) {
72
125
  if (entry.kind !== 'rule' || !entry.check) continue;
73
126
  const [command, ...args] = entry.check.command;
74
127
  const execution = await executor({ command, args, cwd: projectRoot });
75
128
  const status = execution.exitCode === 0 ? 'pass' : 'fail';
76
129
  if (execution.exitCode !== 0) exitCode = 1;
77
- results[entry.id] = {
130
+ results[id] = {
78
131
  status,
79
132
  exitCode: execution.exitCode,
80
133
  stdout: execution.stdout ?? '',
@@ -86,7 +139,7 @@ export async function runInstalledChecks(projectRoot, options = {}) {
86
139
  Object.entries(results).map(([id, result]) => [id, { status: result.status }]),
87
140
  );
88
141
  await writeChecksState(projectRoot, { schemaVersion: 2, results: persistedResults });
89
- return { exitCode, results };
142
+ return { exitCode, results, integrity };
90
143
  }
91
144
 
92
145
  export function createProjectCommandHandlers(projectRoot = process.cwd()) {
@@ -124,6 +177,12 @@ export function createProjectCommandHandlers(projectRoot = process.cwd()) {
124
177
  }
125
178
  const result = await runInstalledChecks(projectRoot);
126
179
  for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
180
+ if (result.integrity.unownedSkillDirectories.length) {
181
+ io.stderr.write('FAIL devkit-skill-ownership: unowned directories found under .agents/skills; move project-only enforcement to .agents/project-skills\n');
182
+ for (const directory of result.integrity.unownedSkillDirectories) {
183
+ io.stderr.write(`- .agents/skills/${directory}\n`);
184
+ }
185
+ }
127
186
  return result.exitCode;
128
187
  },
129
188
  };