@specdest/devkit 0.2.2 → 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.
Files changed (138) hide show
  1. package/README.md +17 -18
  2. package/package.json +4 -4
  3. package/src/canonical-project-operations.js +164 -0
  4. package/src/canonical-project.js +78 -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 +478 -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,27 @@
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
+ See [`docs/operations.md`](docs/operations.md) for cache, dashboard, CI, and release behavior.
23
24
 
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
+ ## Canonical cache runtime
25
26
 
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.
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.2.2",
3
+ "version": "0.3.1",
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,164 @@
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, checkerRuntimeRoot, { 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, checkerRuntimeRoot);
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
+ const checkerRuntime = (catalog.entries ?? []).find((entry) => entry.id === 'checker-runtime');
40
+ let canonicalCheckRoot = null;
41
+ let checkerRuntimeRoot = null;
42
+ if (options.withCheckers && canonicalCheck) {
43
+ if (!options.offline || await source.hasModule(canonicalCheck.id, canonicalCheck.version)) {
44
+ canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version);
45
+ }
46
+ }
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 };
53
+ }
54
+
55
+ export async function canonicalStatus(projectRoot, source, options = {}) {
56
+ const current = await readInstalledState(projectRoot);
57
+ const { stack, applicable } = await canonicalContext(projectRoot, source, options);
58
+ const installed = current.installed;
59
+ const rows = applicable.map((entry) => {
60
+ const found = installed[entry.id];
61
+ const state = !found ? 'missing' : found.version === entry.version ? 'current' : 'outdated';
62
+ return { id: entry.id, canonicalVersion: entry.version, installedVersion: found?.version ?? null, state };
63
+ });
64
+ const applicableIds = new Set(applicable.map((entry) => entry.id));
65
+ const installedNonApplicable = Object.keys(installed).filter((id) => !applicableIds.has(id)).sort();
66
+ return {
67
+ stack,
68
+ totals: {
69
+ applicable: rows.length,
70
+ current: rows.filter((row) => row.state === 'current').length,
71
+ missing: rows.filter((row) => row.state === 'missing').length,
72
+ outdated: rows.filter((row) => row.state === 'outdated').length,
73
+ },
74
+ rows,
75
+ installedNonApplicable,
76
+ };
77
+ }
78
+
79
+ export async function canonicalSync(projectRoot, source) {
80
+ const current = await readInstalledState(projectRoot);
81
+ const { stack, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
82
+ const changed = [];
83
+ for (const entry of applicable) {
84
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
85
+ const installed = current.installed[entry.id];
86
+ if (!installed) {
87
+ await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
88
+ 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') {
90
+ await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
91
+ changed.push({ id: entry.id, action: 'updated', version: entry.version });
92
+ }
93
+ }
94
+ return { stack, applicable: applicable.length, changed };
95
+ }
96
+
97
+ export async function canonicalCheck(projectRoot, source) {
98
+ const current = await readInstalledState(projectRoot);
99
+ const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { offline: true, withCheckers: true });
100
+ const byId = new Map(applicable.map((entry) => [entry.id, entry]));
101
+ const results = {};
102
+ let exitCode = 0;
103
+ for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
104
+ const entry = byId.get(id);
105
+ 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.' };
108
+ exitCode = 1;
109
+ continue;
110
+ }
111
+ const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline: true });
112
+ if (!prepared?.checkerPath) continue;
113
+ const execution = await execute('node', [prepared.checkerPath], projectRoot);
114
+ results[id] = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
115
+ if (execution.exitCode !== 0) exitCode = 1;
116
+ }
117
+ await writeChecksState(projectRoot, {
118
+ schemaVersion: 2,
119
+ checkedAt: new Date().toISOString(),
120
+ results: Object.fromEntries(Object.entries(results).map(([id, result]) => [id, { status: result.status }])),
121
+ });
122
+ return { exitCode, results };
123
+ }
124
+
125
+ export async function canonicalDoctor(projectRoot, source) {
126
+ const issues = [];
127
+ const stack = await detectProjectStack(projectRoot);
128
+ if (!stack) issues.push('Unable to detect a supported project stack.');
129
+ try { await source.catalog(); } catch (error) { issues.push(`Catalog unavailable: ${error.message}`); }
130
+ return { ok: issues.length === 0, stack, cacheRoot: source.cacheRoot, issues };
131
+ }
132
+
133
+ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), options = {}) {
134
+ const source = options.source ?? createCanonicalSource(options);
135
+ return {
136
+ status: async (args, io) => {
137
+ const parsed = flags(args);
138
+ const result = await canonicalStatus(projectRoot, source, { refresh: parsed.refresh });
139
+ if (parsed.json) io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
140
+ 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`);
141
+ return result.totals.missing || result.totals.outdated ? 1 : 0;
142
+ },
143
+ sync: async (args, io) => {
144
+ if (args.length) { io.stderr.write('Usage: specdest sync\n'); return 2; }
145
+ const result = await canonicalSync(projectRoot, source);
146
+ io.stdout.write(`Synced ${result.applicable} applicable rules; ${result.changed.length} changed.\n`);
147
+ for (const item of result.changed) io.stdout.write(`${item.action.toUpperCase()} ${item.id}@${item.version}\n`);
148
+ return 0;
149
+ },
150
+ check: async (args, io) => {
151
+ if (args.length) { io.stderr.write('Usage: specdest check\n'); return 2; }
152
+ const result = await canonicalCheck(projectRoot, source);
153
+ for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
154
+ return result.exitCode;
155
+ },
156
+ doctor: async (args, io) => {
157
+ if (args.length) { io.stderr.write('Usage: specdest doctor\n'); return 2; }
158
+ const result = await canonicalDoctor(projectRoot, source);
159
+ io.stdout.write(`Cache: ${result.cacheRoot}\nStack: ${result.stack ?? 'unknown'}\n`);
160
+ for (const issue of result.issues) io.stderr.write(`FAIL ${issue}\n`);
161
+ return result.ok ? 0 : 1;
162
+ },
163
+ };
164
+ }
@@ -0,0 +1,78 @@
1
+ import { cp, mkdir, readFile, rm } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+
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;
34
+ }
35
+
36
+ export function applicableCatalogEntries(entries, stack) {
37
+ return entries
38
+ .filter((entry) => entry.kind === 'rule')
39
+ .filter((entry) => !entry.applicableStacks?.length || (stack && entry.applicableStacks.includes(stack)))
40
+ .sort((a, b) => a.id.localeCompare(b.id));
41
+ }
42
+
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);
51
+ }
52
+ await materializeCopies(raw, ruleRoot, runtimeRoot);
53
+
54
+ let checkerPath = runtimeCheckerPath(raw, runtimeRoot);
55
+ if (!checkerPath && raw.checker?.path && canonicalCheckRoot) {
56
+ const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
57
+ const implementationRoot = dirname(join(canonicalCheckRoot, relative));
58
+ const implementationManifest = await readManifest(implementationRoot);
59
+ await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
60
+ checkerPath = runtimeCheckerPath(implementationManifest, runtimeRoot);
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
+ );
67
+ const manifest = {
68
+ ...raw,
69
+ kind: raw.kind ?? entry.kind ?? 'rule',
70
+ version: entry.version ?? raw.version,
71
+ ...(entry.contentHash ? { contentHash: entry.contentHash } : {}),
72
+ ...(entry.revision ? { revision: entry.revision } : {}),
73
+ copies,
74
+ markdownSections,
75
+ ...(checkerPath ? { check: { command: ['specdest-cache', entry.id] } } : {}),
76
+ };
77
+ return { manifest, checkerPath };
78
+ }
@@ -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;