@specdest/devkit 0.2.0 → 0.2.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 ADDED
@@ -0,0 +1,28 @@
1
+ # Specdest Devkit
2
+
3
+ Canonical engineering standards, reusable modules, installers, migrations, checkers, and CLI for Specdest projects.
4
+
5
+ ## CLI
6
+
7
+ The publishable package is `@specdest/devkit` and exposes the `specdest` binary.
8
+
9
+ ```sh
10
+ specdest install <rule-or-module>
11
+ specdest status
12
+ specdest sync
13
+ specdest check
14
+ ```
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.
17
+
18
+ ## Workspace
19
+
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.
@@ -39,8 +39,7 @@ Rules:
39
39
  - DAL and provider adapters need focused boundary/contract tests.
40
40
  - Public Convex functions need boundary tests executed through `convex-test` for accepted args, rejected invalid args, and validated returns. Export-only smoke tests do not satisfy this rule.
41
41
  - Public-output mappers must explicitly construct their DTO; identity mappers are forbidden because structural typing can otherwise leak persistence-only fields.
42
- - Existing boundary-test migration debt is tracked in `boundary-test-baseline.json`; the baseline may only shrink and new weak boundary tests are rejected.
43
- - Architecture enforcement has no inline suppression mechanism. Existing migration debt, when unavoidable, is tracked only in the explicit architecture baseline and new debt is rejected.
42
+ - Architecture enforcement has no suppression or baseline mechanism. Existing project debt must be fixed or explicitly tracked outside the checker; new violations always fail.
44
43
  - `nps lint.convexArchitecture` is mandatory in the normal lint gate.
45
44
  - `nps typecheck.convex` must typecheck the Convex backend independently.
46
45
  - Oxc must lint frontend, backend, architecture rules, tests, and scripts.
@@ -196,77 +196,10 @@ for (const path of forbiddenBaseMcpPaths) {
196
196
  add(path, "Base MCP must be hosted only at Convex /mcp; duplicate local MCP path is forbidden");
197
197
  }
198
198
 
199
- const boundaryDebtPath = ".agents/skills/convex-multi-presentation/boundary-test-baseline.json";
200
- const boundaryDebtCeiling = 44;
201
- let boundaryDebt = new Set<string>();
202
- let boundaryDebtHasDuplicates = false;
203
- if (await exists(boundaryDebtPath)) {
204
- const parsed = JSON.parse(decoder.decode(await runtime.readFile(boundaryDebtPath))) as {
205
- readonly findings?: readonly string[];
206
- };
207
- const debtFindings = parsed.findings ?? [];
208
- boundaryDebt = new Set(debtFindings);
209
- boundaryDebtHasDuplicates = boundaryDebt.size !== debtFindings.length;
210
- }
211
-
212
- const baselinePath = ".agents/skills/convex-multi-presentation/legacy-baseline.json";
213
- const strict = runtime.args.includes("--strict");
214
- const legacyBaselineCeiling = 87;
215
- let baseline = new Set<string>();
216
- let baselineHasDuplicates = false;
217
- if (!strict && (await exists(baselinePath))) {
218
- const parsed = JSON.parse(decoder.decode(await runtime.readFile(baselinePath))) as {
219
- readonly findings?: readonly string[];
220
- };
221
- const baselineFindings = parsed.findings ?? [];
222
- baseline = new Set(baselineFindings);
223
- baselineHasDuplicates = baseline.size !== baselineFindings.length;
224
- }
225
-
226
199
  const uniqueFindings = [...new Set(findings)].toSorted();
227
- const newFindings = strict
228
- ? uniqueFindings
229
- : uniqueFindings.filter((finding) => !baseline.has(finding) && !boundaryDebt.has(finding));
230
- const staleBaseline = strict
231
- ? []
232
- : [...baseline].filter((finding) => !uniqueFindings.includes(finding)).toSorted();
233
- const staleBoundaryDebt = strict
234
- ? []
235
- : [...boundaryDebt].filter((finding) => !uniqueFindings.includes(finding)).toSorted();
236
- const baselineGrew = !strict && baseline.size > legacyBaselineCeiling;
237
- const boundaryDebtGrew = !strict && boundaryDebt.size > boundaryDebtCeiling;
238
-
239
- if (baselineGrew)
240
- console.error(
241
- `legacy convex architecture baseline may not grow beyond ${legacyBaselineCeiling}; found ${baseline.size}`,
242
- );
243
- if (baselineHasDuplicates)
244
- console.error("legacy convex architecture baseline contains duplicate findings");
245
- if (boundaryDebtGrew)
246
- console.error(
247
- `boundary-test baseline may not grow beyond ${boundaryDebtCeiling}; found ${boundaryDebt.size}`,
248
- );
249
- if (boundaryDebtHasDuplicates) console.error("boundary-test baseline contains duplicate findings");
250
- if (staleBaseline.length)
251
- console.error(
252
- "stale convex architecture baseline entries must be removed:\n" + staleBaseline.join("\n"),
253
- );
254
- if (staleBoundaryDebt.length)
255
- console.error(
256
- "stale boundary-test baseline entries must be removed:\n" + staleBoundaryDebt.join("\n"),
257
- );
258
- if (newFindings.length) console.error(newFindings.join("\n"));
259
- if (
260
- baselineGrew ||
261
- baselineHasDuplicates ||
262
- staleBaseline.length ||
263
- staleBoundaryDebt.length ||
264
- newFindings.length
265
- )
200
+ if (uniqueFindings.length) {
201
+ console.error(uniqueFindings.join("\n"));
266
202
  runtime.exit(1);
203
+ }
267
204
 
268
- if (baseline.size)
269
- console.log(
270
- `convex-multi-presentation ok (${baseline.size} tracked legacy findings; --strict reports all)`,
271
- );
272
- else console.log("convex-multi-presentation ok");
205
+ console.log("convex-multi-presentation ok");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "convex-multi-presentation",
3
3
  "kind": "rule",
4
- "version": "1.0.4",
4
+ "version": "1.0.5",
5
5
  "requires": [
6
6
  "checker-runtime"
7
7
  ],
@@ -11,11 +11,6 @@
11
11
  "path": ".agents/skills/convex-multi-presentation/SKILL.md",
12
12
  "source": "SKILL.md"
13
13
  },
14
- {
15
- "kind": "scaffold",
16
- "path": ".agents/skills/convex-multi-presentation/boundary-test-baseline.json",
17
- "source": "boundary-test-baseline.json"
18
- },
19
14
  {
20
15
  "kind": "managed-file",
21
16
  "path": ".agents/skills/convex-multi-presentation/check.ts",
@@ -33,7 +28,16 @@
33
28
  "body": "Use `.agents/skills/convex-multi-presentation/SKILL.md` when working in this rule area. Run `node .agents/skills/convex-multi-presentation/check.ts` before handoff."
34
29
  }
35
30
  ],
36
- "obsolete": [],
31
+ "obsolete": [
32
+ {
33
+ "kind": "file",
34
+ "path": ".agents/skills/convex-multi-presentation/boundary-test-baseline.json"
35
+ },
36
+ {
37
+ "kind": "file",
38
+ "path": ".agents/skills/convex-multi-presentation/legacy-baseline.json"
39
+ }
40
+ ],
37
41
  "check": {
38
42
  "command": [
39
43
  "node",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "src/cli.js"
@@ -14,9 +14,27 @@
14
14
  "catalog"
15
15
  ],
16
16
  "engines": {
17
- "node": ">=24.0.0"
17
+ "node": ">=24.0.0",
18
+ "pnpm": ">=11.0.0"
18
19
  },
20
+ "packageManager": "pnpm@11.6.0",
19
21
  "publishConfig": {
20
22
  "access": "public"
23
+ },
24
+ "scripts": {
25
+ "test": "node --test test/*.test.js",
26
+ "lint": "node scripts/validate-js.mjs",
27
+ "check": "pnpm run lint && pnpm run typecheck && pnpm run test",
28
+ "catalog:snapshot": "node scripts/export-catalog-snapshot.mjs",
29
+ "release:preflight": "node scripts/release-preflight.mjs",
30
+ "smoke:published": "node scripts/smoke-published-package.mjs",
31
+ "typecheck": "node scripts/typecheck-checkers.mjs",
32
+ "release:build": "node scripts/build-release-artifacts.mjs",
33
+ "smoke:artifact": "node scripts/smoke-package-artifact.mjs",
34
+ "catalog:propagate": "node scripts/propagate-catalog-release.mjs"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^24.0.0",
38
+ "typescript": "^6.0.0"
21
39
  }
22
40
  }
@@ -5,17 +5,11 @@ import { evaluateSetupRequirements } from './setup-requirements.js';
5
5
  import {
6
6
  applySyncPlan,
7
7
  previewSync,
8
+ inferRequestedRoots,
8
9
  readInstalledState,
9
10
  writeChecksState,
10
11
  } from './sync-core.js';
11
12
 
12
- function checkerArgs(command, args) {
13
- if (command !== 'deno' || args.includes('--no-lock')) return args;
14
- const [subcommand, ...rest] = args;
15
- if (!subcommand) return args;
16
- return [subcommand, '--no-lock', ...rest];
17
- }
18
-
19
13
  function defaultExecutor({ command, args, cwd }) {
20
14
  return new Promise((resolve, reject) => {
21
15
  const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -32,19 +26,28 @@ function defaultExecutor({ command, args, cwd }) {
32
26
 
33
27
  export async function installCatalogEntry(projectRoot, id, options = {}) {
34
28
  const current = await readInstalledState(projectRoot);
35
- if (current.installed[id]) throw new Error(`${id} is already installed; use specdest sync`);
36
- const requested = [...Object.keys(current.installed), id];
37
- const entries = await resolveCatalogSelection(requested, options);
29
+ const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
30
+ const currentRequested = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
31
+ if (currentRequested.includes(id)) throw new Error(`${id} is already requested; use specdest sync`);
32
+ const requestedIds = [...new Set([...currentRequested, id])].sort();
33
+ const entries = await resolveCatalogSelection(requestedIds, options);
38
34
  const desiredIds = entries.map((entry) => entry.id);
39
- const plan = await previewSync(projectRoot, entries, { desiredIds });
35
+ const desiredSet = new Set(desiredIds);
36
+ const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
37
+ const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
40
38
  await applySyncPlan(plan);
41
39
  return plan;
42
40
  }
43
41
 
44
42
  export async function syncInstalledCatalog(projectRoot, options = {}) {
45
43
  const current = await readInstalledState(projectRoot);
46
- const entries = await resolveCatalogSelection(Object.keys(current.installed), options);
47
- const plan = await previewSync(projectRoot, entries, { desiredIds: entries.map((entry) => entry.id) });
44
+ const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
45
+ const requestedIds = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
46
+ const entries = await resolveCatalogSelection(requestedIds, options);
47
+ const desiredIds = entries.map((entry) => entry.id);
48
+ const desiredSet = new Set(desiredIds);
49
+ const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
50
+ const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
48
51
  await applySyncPlan(plan);
49
52
  return plan;
50
53
  }
@@ -69,7 +72,7 @@ export async function runInstalledChecks(projectRoot, options = {}) {
69
72
  for (const entry of entries) {
70
73
  if (entry.kind !== 'rule' || !entry.check) continue;
71
74
  const [command, ...args] = entry.check.command;
72
- const execution = await executor({ command, args: checkerArgs(command, args), cwd: projectRoot });
75
+ const execution = await executor({ command, args, cwd: projectRoot });
73
76
  const status = execution.exitCode === 0 ? 'pass' : 'fail';
74
77
  if (execution.exitCode !== 0) exitCode = 1;
75
78
  results[entry.id] = {
package/src/sync-core.js CHANGED
@@ -10,12 +10,13 @@ import {
10
10
  validateSharedArtifact,
11
11
  } from './shared-file.js';
12
12
 
13
- export const STATE_SCHEMA_VERSION = 1;
13
+ export const STATE_SCHEMA_VERSION = 2;
14
+ export const CHECKS_SCHEMA_VERSION = 1;
14
15
  export const INSTALLED_RELATIVE_PATH = '.specdest/installed.json';
15
16
  export const CHECKS_RELATIVE_PATH = '.specdest/checks.json';
16
17
 
17
- const EMPTY_INSTALLED = Object.freeze({ schemaVersion: 1, installed: {} });
18
- const EMPTY_CHECKS = Object.freeze({ schemaVersion: 1, checkedAt: null, results: {} });
18
+ const EMPTY_INSTALLED = Object.freeze({ schemaVersion: 2, requested: [], installed: {} });
19
+ const EMPTY_CHECKS = Object.freeze({ schemaVersion: CHECKS_SCHEMA_VERSION, checkedAt: null, results: {} });
19
20
 
20
21
  function clone(value) {
21
22
  return JSON.parse(JSON.stringify(value));
@@ -38,14 +39,19 @@ async function writeJsonAtomic(filePath, value) {
38
39
  }
39
40
 
40
41
  function validateInstalledState(state) {
41
- if (state?.schemaVersion !== STATE_SCHEMA_VERSION || !state.installed || Array.isArray(state.installed) || typeof state.installed !== 'object') {
42
+ const legacy = state?.schemaVersion === 1;
43
+ const current = state?.schemaVersion === STATE_SCHEMA_VERSION;
44
+ if ((!legacy && !current) || !state.installed || Array.isArray(state.installed) || typeof state.installed !== 'object') {
42
45
  throw new Error('Invalid .specdest/installed.json state');
43
46
  }
47
+ if (current && (!Array.isArray(state.requested) || state.requested.some((id) => !validId(id) || !state.installed[id]))) {
48
+ throw new Error('Invalid .specdest/installed.json requested roots');
49
+ }
44
50
  return state;
45
51
  }
46
52
 
47
53
  function validateChecksState(state) {
48
- if (state?.schemaVersion !== STATE_SCHEMA_VERSION || !state.results || Array.isArray(state.results) || typeof state.results !== 'object') {
54
+ if (state?.schemaVersion !== CHECKS_SCHEMA_VERSION || !state.results || Array.isArray(state.results) || typeof state.results !== 'object') {
49
55
  throw new Error('Invalid .specdest/checks.json state');
50
56
  }
51
57
  if (state.checkedAt !== null && typeof state.checkedAt !== 'string') {
@@ -59,9 +65,22 @@ export async function readInstalledState(projectRoot) {
59
65
  return validateInstalledState(state);
60
66
  }
61
67
 
68
+ function formatInstalledState(state) {
69
+ const installed = JSON.stringify(state.installed, null, 2)
70
+ .split('\n')
71
+ .map((line, index) => index === 0 ? line : ` ${line}`)
72
+ .join('\n');
73
+ return `{\n "schemaVersion": ${STATE_SCHEMA_VERSION},\n "requested": ${JSON.stringify(state.requested)},\n "installed": ${installed}\n}\n`;
74
+ }
75
+
62
76
  export async function writeInstalledState(projectRoot, state) {
63
77
  validateInstalledState(state);
64
- await writeJsonAtomic(join(projectRoot, INSTALLED_RELATIVE_PATH), state);
78
+ if (state.schemaVersion !== STATE_SCHEMA_VERSION) throw new Error('Cannot write legacy .specdest/installed.json state');
79
+ const filePath = join(projectRoot, INSTALLED_RELATIVE_PATH);
80
+ await mkdir(dirname(filePath), { recursive: true });
81
+ const temp = `${filePath}.${process.pid}.tmp`;
82
+ await writeFile(temp, formatInstalledState(state), 'utf8');
83
+ await rename(temp, filePath);
65
84
  }
66
85
 
67
86
  export async function readChecksState(projectRoot) {
@@ -154,6 +173,22 @@ function sortedInstalled(installed) {
154
173
  return Object.fromEntries(Object.entries(installed).sort(([a], [b]) => a.localeCompare(b)));
155
174
  }
156
175
 
176
+ export function inferRequestedRoots(entries) {
177
+ const ids = new Set(entries.map((entry) => entry.id));
178
+ const required = new Set();
179
+ for (const entry of entries) {
180
+ for (const id of entry.requires ?? []) if (ids.has(id)) required.add(id);
181
+ }
182
+ return [...ids].filter((id) => !required.has(id)).sort();
183
+ }
184
+
185
+ function removalArtifact(artifact) {
186
+ if (artifact.kind === 'managed-file') return { kind: 'file', path: artifact.path };
187
+ if (artifact.kind === 'scaffold') return null;
188
+ if (isSharedArtifact(artifact)) return artifact;
189
+ return null;
190
+ }
191
+
157
192
  export async function previewSync(projectRoot, manifests, options = {}) {
158
193
  const currentState = await readInstalledState(projectRoot);
159
194
  const catalog = new Map();
@@ -164,12 +199,18 @@ export async function previewSync(projectRoot, manifests, options = {}) {
164
199
  }
165
200
 
166
201
  const desiredIds = options.desiredIds ?? Object.keys(currentState.installed);
202
+ const requestedIds = options.requestedIds ?? (currentState.schemaVersion === 2 ? currentState.requested : desiredIds);
167
203
  const selected = [...new Set(desiredIds)].sort().map((id) => {
168
204
  const manifest = catalog.get(id);
169
205
  if (!manifest) throw new Error(`Desired item has no current manifest: ${id}`);
170
206
  return manifest;
171
207
  });
172
208
  buildOwnershipGraph(selected);
209
+ const activeWholePaths = new Set(
210
+ selected.flatMap((manifest) => (manifest.artifacts ?? [])
211
+ .filter((artifact) => artifact.kind === 'managed-file' || artifact.kind === 'scaffold')
212
+ .map((artifact) => artifact.path)),
213
+ );
173
214
 
174
215
  const operations = [];
175
216
  const sharedFiles = new Map();
@@ -179,6 +220,28 @@ export async function previewSync(projectRoot, manifests, options = {}) {
179
220
  sharedFiles.set(artifact.path, entry);
180
221
  };
181
222
 
223
+ for (const manifest of options.removedManifests ?? []) {
224
+ for (const artifact of manifest.artifacts ?? []) {
225
+ const obsolete = removalArtifact(artifact);
226
+ if (!obsolete) continue;
227
+ if (obsolete.kind === 'file' && activeWholePaths.has(obsolete.path)) continue;
228
+ if (isSharedArtifact(obsolete)) {
229
+ collectShared(manifest.id, obsolete, true);
230
+ continue;
231
+ }
232
+ const target = resolveProjectPath(projectRoot, obsolete.path);
233
+ const state = await fileState(target);
234
+ if (state === 'other') throw new Error(`Removed file target is not a file: ${obsolete.path}`);
235
+ operations.push({
236
+ relativePath: obsolete.path,
237
+ target,
238
+ action: state === 'file' ? 'delete' : 'unchanged',
239
+ ownerId: manifest.id,
240
+ artifactKind: 'removed-managed-file',
241
+ });
242
+ }
243
+ }
244
+
182
245
  for (const manifest of selected) {
183
246
  for (const artifact of manifest.artifacts ?? []) {
184
247
  if (isSharedArtifact(artifact)) {
@@ -235,8 +298,15 @@ export async function previewSync(projectRoot, manifests, options = {}) {
235
298
  for (const manifest of selected) {
236
299
  nextInstalled[manifest.id] = { kind: manifest.kind, version: manifest.version };
237
300
  }
238
- const nextState = { schemaVersion: STATE_SCHEMA_VERSION, installed: sortedInstalled(nextInstalled) };
239
- const normalizedCurrent = { schemaVersion: STATE_SCHEMA_VERSION, installed: sortedInstalled(currentState.installed) };
301
+ for (const id of Object.keys(nextInstalled)) if (!desiredIds.includes(id)) delete nextInstalled[id];
302
+ const nextState = {
303
+ schemaVersion: STATE_SCHEMA_VERSION,
304
+ requested: [...new Set(requestedIds)].sort(),
305
+ installed: sortedInstalled(nextInstalled),
306
+ };
307
+ const normalizedCurrent = currentState.schemaVersion === STATE_SCHEMA_VERSION
308
+ ? { schemaVersion: STATE_SCHEMA_VERSION, requested: [...currentState.requested].sort(), installed: sortedInstalled(currentState.installed) }
309
+ : { schemaVersion: 1, installed: sortedInstalled(currentState.installed) };
240
310
  return {
241
311
  projectRoot,
242
312
  operations,