@specdest/devkit 0.4.8 → 0.4.9

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 (47) hide show
  1. package/README.md +26 -24
  2. package/dist/npm/canonical-project.d.ts +12 -1
  3. package/dist/npm/canonical-project.js +10 -4
  4. package/dist/npm/canonical-source.d.ts +14 -2
  5. package/dist/npm/canonical-source.js +46 -14
  6. package/dist/npm/catalog-snapshot.d.ts +32 -26
  7. package/dist/npm/catalog-snapshot.js +11 -4
  8. package/dist/npm/cli.js +5 -2
  9. package/dist/npm/commands.d.ts +6 -0
  10. package/dist/npm/commands.js +33 -8
  11. package/dist/npm/flow.js +52 -18
  12. package/dist/npm/git-catalog.d.ts +33 -32
  13. package/dist/npm/git-catalog.js +49 -17
  14. package/dist/npm/index.d.ts +0 -1
  15. package/dist/npm/index.js +13 -3
  16. package/dist/npm/installer-primitives.d.ts +3 -3
  17. package/dist/npm/predefined-packages/expo.js +5 -1
  18. package/dist/npm/predefined-packages/index.d.ts +1 -0
  19. package/dist/npm/predefined-packages/index.js +44 -3
  20. package/dist/npm/predefined-packages/install.js +3 -2
  21. package/dist/npm/predefined-packages/supabase.js +271 -20
  22. package/dist/npm/predefined-packages/types.d.ts +7 -0
  23. package/dist/npm/predefined-packages/vite.js +5 -1
  24. package/dist/npm/project-check.d.ts +8 -0
  25. package/dist/npm/project-check.js +38 -7
  26. package/dist/npm/project-context.d.ts +14 -4
  27. package/dist/npm/project-context.js +32 -18
  28. package/dist/npm/project-rules.d.ts +4 -1
  29. package/dist/npm/project-rules.js +15 -6
  30. package/dist/npm/project-runtime.d.ts +4 -1
  31. package/dist/npm/project-runtime.js +19 -5
  32. package/dist/npm/project-status.js +17 -3
  33. package/dist/npm/project-sync.js +13 -5
  34. package/dist/npm/remote-installer.d.ts +35 -4
  35. package/dist/npm/remote-installer.js +75 -36
  36. package/dist/npm/rule-id-migrations.d.ts +6 -0
  37. package/dist/npm/rule-id-migrations.js +19 -0
  38. package/dist/npm/schemas.d.ts +64 -0
  39. package/dist/npm/schemas.js +194 -0
  40. package/dist/npm/slack.d.ts +16 -0
  41. package/dist/npm/slack.js +131 -0
  42. package/dist/npm/state.js +71 -22
  43. package/dist/npm/supabase-local.d.ts +2 -0
  44. package/dist/npm/supabase-local.js +62 -0
  45. package/package.json +10 -7
  46. package/dist/npm/fuzz.d.ts +0 -138
  47. package/dist/npm/fuzz.js +0 -327
package/README.md CHANGED
@@ -6,7 +6,7 @@ The CLI/core source is strict TypeScript. Development uses Node 24 directly; npm
6
6
 
7
7
  The npm package contains only the CLI/core runtime. Canonical rules stay in the private Devkit GitHub repository and are fetched with normal Git/SSH transport into a local machine cache when needed. Rule changes therefore do not require an npm release.
8
8
 
9
- The root package API is intentionally small: `runCli`, `COMMAND_NAMES`, `createCanonicalSource`, `createFlowCommandHandler`, and `createFuzzCommandHandler`. Installer, state, sync, and canonical orchestration modules are internal implementation details.
9
+ The root package API is intentionally small: `runCli`, `COMMAND_NAMES`, `createCanonicalSource`, `createFlowCommandHandler`. Installer, state, sync, and canonical orchestration modules are internal implementation details.
10
10
 
11
11
  `modules/**` is the canonical rule/module source. `catalog/**` is compatibility/test fixture data only; production CLI and release catalog generation do not read it.
12
12
 
@@ -16,13 +16,12 @@ The root package API is intentionally small: `runCli`, `COMMAND_NAMES`, `createC
16
16
  npx @specdest/devkit status
17
17
  npx @specdest/devkit add vite
18
18
  npx @specdest/devkit sync
19
- npx @specdest/devkit check [--refresh]
19
+ npx @specdest/devkit check [--refresh] [--json]
20
20
  npx @specdest/devkit check --staged
21
21
  npx @specdest/devkit check --files src/path/file.ts
22
22
  npx @specdest/devkit rules
23
23
  npx @specdest/devkit ai-instruction
24
24
  npx @specdest/devkit doctor
25
- npx @specdest/devkit fuzz
26
25
  npx @specdest/devkit flow status
27
26
  npx @specdest/devkit flow start --mode feature --goal "Add password reset" --task auth-reset
28
27
  npx @specdest/devkit flow checkpoint --phase implement
@@ -31,12 +30,11 @@ npx @specdest/devkit flow complete
31
30
  ```
32
31
 
33
32
  - `status` reads the cached canonical catalog and reports applicable/current/missing/outdated rules plus registered predefined packages. Use `--refresh` to refresh the catalog from GitHub and `--json` for machine-readable output.
34
- - `add <package>` applies or adopts a predefined package recipe. Package recipes use only three relationship primitives: `requires`, `conflicts`, and environment-selected `variants`. `requires` is evaluated against packages registered in Devkit state; conflicts and variant selection also consider packages physically detected in the project. Status/doctor report stale package state, while sync/check/rules refuse to run against invalid package metadata. The supported foundational packages are `vite`, `expo`, `supabase`, and `convex`. Additional predefined packages are `auth`, `multi-tenancy`, `abac`, `sentry`, `logging`, `payments`, `shadcn`, `tanstack-router`, `tanstack-query`, `tanstack-form`, `storybook`, `playwright`, `vitest`, `local-logging`, `firebase-hosting`, `zod`, `tailwind`, `husky`, `nps`, `oxlint`, `oxfmt`, and `stryker`. Create-or-adopt recipes include the foundations (`vite`, `expo`, `supabase`, `convex`) and deterministic self-contained tooling (`zod`, `vitest`, `oxlint`, `oxfmt`, `husky`, `nps`, `tanstack-form`, `playwright`, `stryker`). They create minimal local dependencies/configuration when absent, then run `pnpm install`; when an integration already exists they adopt it without rewriting project-owned application files. Runtime-wired or product-specific recipes remain adoption-only until Devkit has a deterministic, product-neutral installation contract. Recipes record the recipe version separately from any detected dependency version in `.spd/installed.json`; Devkit does not invent product-specific auth, tenancy, authorization, logging, or payment architecture. Generated/adopted application code remains project-owned. Package lifecycle is deliberately fire-and-forget: there is no package `remove` or `upgrade` command. Developers remove packages manually; to update a recipe, re-run `add <package>`. Re-adding applies only the current recipe and does not remove files/settings that existed only in an older recipe. See [`docs/package-model.md`](docs/package-model.md).
33
+ - `add <package>` applies or adopts a predefined package recipe. Package recipes use only three relationship primitives: `requires`, `conflicts`, and environment-selected `variants`. `requires` is evaluated against packages registered in Devkit state; conflicts and variant selection also consider packages physically detected in the project. Status/doctor report stale package state, while sync/check/rules refuse to run against invalid package metadata. The supported foundational packages are `vite`, `expo`, `supabase`, and `convex`. Additional predefined packages are `auth`, `multi-tenancy`, `abac`, `sentry`, `logging`, `payments`, `shadcn`, `tanstack-router`, `tanstack-query`, `tanstack-form`, `storybook`, `playwright`, `vitest`, `local-logging`, `firebase-hosting`, `zod`, `tailwind`, `husky`, `nps`, `oxlint`, `oxfmt`, and `stryker`. Create-or-adopt recipes include the foundations (`vite`, `expo`, `supabase`, `convex`) and deterministic self-contained tooling (`zod`, `vitest`, `oxlint`, `oxfmt`, `husky`, `nps`, `tanstack-form`, `playwright`, `stryker`). They create minimal local dependencies/configuration when absent, then run `pnpm install`; when an integration already exists they adopt it without rewriting project-owned application files. Runtime-wired or product-specific recipes remain adoption-only until Devkit has a deterministic, product-neutral installation contract. Recipes record the recipe version separately from any detected dependency version in `.spd/installed.json`; Devkit does not invent product-specific auth, tenancy, authorization, logging, or payment architecture. Generated/adopted application code remains project-owned. Package lifecycle is deliberately fire-and-forget: there is no package `remove` or `upgrade` command. Developers remove packages manually; to update a recipe, re-run `add <package>`. Re-adding applies only the current recipe and does not remove files/settings that existed only in an older recipe. See [`docs/package-model.md`](docs/package-model.md). Supabase creation also scaffolds the canonical guarded declarative production-release workflow; registering Supabase activates the corresponding database rule/checker for ongoing enforcement. When Devkit-created foundation packages resolve a supported stack, required canonical setup packages are installed automatically (for example Oxlint/Husky for React stack gates and NPS for Supabase database commands); adopted stacks remain non-invasive and report missing setup through canonical checks.
35
34
  - `sync` refreshes the canonical catalog, downloads only missing rule-cache entries, installs missing applicable rules, and updates outdated ones.
36
35
  - `check` executes each distinct canonical checker implementation once from the local Devkit cache and projects that result onto every rule backed by that checker. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files. `--staged` resolves target paths/content from the Git index; `--files` supplies explicit project-relative paths. Repository-scoped checkers still run globally. Targeted checks are ephemeral and do not update `.spd/state.json`; only a full check records canonical project status.
37
36
  - `rules` loads AI-facing guidance without dumping the whole catalog. Use `--id <rule>`, `--category <category>`, `--failed`, or `--json`; with no selector it returns only rules marked `ai.load = "always"`.
38
37
  - `doctor` reports project-stack/cache setup problems.
39
- - `fuzz` dynamically exercises Zod boundary contracts with `fast-check` plus Specdest semantic amplifiers for nullish, blank-string, numeric/boolean, and array edge cases. It is separate from static `check` and from Stryker mutation testing.
40
38
  - `flow` manages local, resumable development state under `.spd/`. Canonical workflows are fixed: Feature/Fix use `plan → implement → verify → complete`; Inspect uses `plan → complete`. Use `--task <id>` when multiple tasks exist and `--context-file flow-notes/<task>.md` only when rich working context is needed. `flow verify` runs the repository's existing `.husky/pre-push` gate when present, otherwise its package `check` script; completion requires a successful, still-current verification. Runtime state is local-only and removed on completion.
41
39
 
42
40
  ## AI usage
@@ -49,25 +47,6 @@ The CLI resolves a project stack from supported Expo/Vite + Convex/Supabase pack
49
47
 
50
48
  See [`docs/operations.md`](docs/operations.md) for cache, dashboard, CI, and release behavior.
51
49
 
52
- ## Contract fuzzing
53
-
54
- `npx @specdest/devkit fuzz` runs against the current repository. By default it discovers the boundary filenames already used by the canonical architecture rules: `*.input.schema.ts`, `*.output.schema.ts`, `*.form.schema.ts`, and `*.callbackInput.schema.ts` under `src/` and `supabase/functions/`. It loads the project's own Zod schemas; Devkit does not require or bundle a second runtime Zod instance.
55
-
56
- The v1 adapter supports Zod objects, strings, numbers, booleans, arrays, enums, optional, nullable/nullish wrappers, and practical min/max boundaries. It amplifies values such as `null`, `undefined`, omitted properties, empty/whitespace strings, `0`, `false`, `NaN`, empty arrays, nullish array items, duplicates, reordering, and item removal. Accepted empty/whitespace strings are reported as semantic failures because they are commonly indistinguishable from absent user input at Specdest boundaries. Failures include the fast-check seed/path when applicable.
57
-
58
- If default discovery is not appropriate, add `.spd/fuzz.json`:
59
-
60
- ```json
61
- {
62
- "schemaVersion": 1,
63
- "targets": [
64
- { "module": "src/application/user/update.input.schema.ts", "exports": ["userUpdateInputSchema"] }
65
- ]
66
- }
67
- ```
68
-
69
- Current module loading supports Node 24 TypeScript, extensionless relative imports, and the Specdest `@/* -> src/*` alias convention. Unsupported schema constructs or unloadable modules are reported explicitly as `SKIP`; they are never silently interpreted.
70
-
71
50
  ## Canonical cache runtime
72
51
 
73
52
  Canonical authoring lives under `modules/**`. The CLI refreshes a single-branch bare Git source and hydrates required modules from the same catalog revision 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.
@@ -80,3 +59,26 @@ Project operations are split by behavior: `project-status.ts`, `project-sync.ts`
80
59
  The canonical installer intentionally supports only managed file copies, create-once scaffold files, and managed Markdown sections. Canonical manifests must not rely on generic JSON/YAML/env mutation, directory-copy, delete, or lifecycle-script operations.
81
60
 
82
61
  The legacy generic sync planner (`sync-core.js`), shared-file mutation runtime, and setup-requirement evaluator have been removed from the shipped CLI. Compatibility catalog validation for those historical manifest shapes lives only under `test/support`.
62
+
63
+ ### Share development artifacts in Slack
64
+
65
+ Screenshot capture remains owned by each project (for example `agent-device` or
66
+ `agent-browser`). Devkit only uploads existing files:
67
+
68
+ ```sh
69
+ specdest slack send --message 'UI review' screenshots/*.png
70
+ specdest slack send --thread 1234567890.123456 screenshots/new.png
71
+ ```
72
+
73
+ When no `SLACK_CHANNEL_ID` is set in the environment or project `.env.e2e.local`, commit a channel in `.spd/config.json`:
74
+
75
+ ```json
76
+ { "slack": { "channel": "C0123456789" } }
77
+ ```
78
+
79
+ Set `SLACK_BOT_TOKEN` in the environment, project `.env.e2e.local`, or in
80
+ `~/.config/specdest/slack.env` (a machine-local file outside the project,
81
+ mode `0600` recommended). The Slack app needs `chat:write` and `files:write`
82
+ scopes and membership in the target channel. The command creates one parent
83
+ message and uploads the files as threaded attachments unless `--thread` is
84
+ provided. Missing configuration fails explicitly, with no channel prompt. See [`docs/slack-artifacts.md`](docs/slack-artifacts.md) for ownership boundaries, configuration, and retry semantics.
@@ -1,5 +1,16 @@
1
1
  export declare function prepareCachedManifest(entry: any, ruleRoot: any, canonicalCheckRoot: any, checkerRuntimeRoot?: any): Promise<{
2
- manifest: any;
2
+ manifest: {
3
+ check?: import("./schemas.ts").JsonRecord;
4
+ copies: any[];
5
+ markdownSections: import("./schemas.ts").JsonRecord[];
6
+ revision?: any;
7
+ contentHash?: any;
8
+ kind: any;
9
+ version: any;
10
+ id: string;
11
+ operations?: import("./schemas.ts").JsonRecord[];
12
+ checker?: import("./schemas.ts").JsonRecord;
13
+ };
3
14
  checkerPath: string | null;
4
15
  checkerArgs: any;
5
16
  checkerKey: string | null;
@@ -1,5 +1,6 @@
1
1
  import { cp, mkdir, readFile, rm } from 'node:fs/promises';
2
2
  import { basename, dirname, join } from 'node:path';
3
+ import { CanonicalManifestSchema, parseWithSchema } from "./schemas.js";
3
4
  function isSkillTarget(copy) {
4
5
  return String(copy?.target ?? copy?.path ?? '').startsWith('.agents/skills/');
5
6
  }
@@ -16,11 +17,14 @@ async function materializeCopies(manifest, sourceRoot, runtimeRoot) {
16
17
  const source = join(sourceRoot, String(copy.source ?? ''));
17
18
  const target = join(runtimeRoot, String(copy.target ?? copy.path ?? ''));
18
19
  await mkdir(dirname(target), { recursive: true });
19
- await cp(source, target, { recursive: copy.type === 'directory' || copy.directory === true, force: true });
20
+ await cp(source, target, {
21
+ recursive: copy.type === 'directory' || copy.directory === true,
22
+ force: true,
23
+ });
20
24
  }
21
25
  }
22
26
  async function readManifest(root) {
23
- return JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8'));
27
+ return parseWithSchema(CanonicalManifestSchema, JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8')), `canonical manifest at ${root}`);
24
28
  }
25
29
  async function cacheProjectCopies(copies, sourceRoot, ruleRoot, label) {
26
30
  const result = [];
@@ -84,7 +88,7 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
84
88
  const implementationManifest = await readManifest(implementationRoot);
85
89
  ({ targeting, execution } = checkerPolicy(implementationManifest));
86
90
  await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
87
- copies.push(...await cacheProjectCopies(implementationManifest.copies ?? [], implementationRoot, ruleRoot, basename(implementationRoot)));
91
+ copies.push(...(await cacheProjectCopies(implementationManifest.copies ?? [], implementationRoot, ruleRoot, basename(implementationRoot))));
88
92
  checker = runtimeChecker(implementationManifest, runtimeRoot);
89
93
  }
90
94
  const markdownSections = (raw.markdownSections ?? []).filter((section) => !String(section?.body ?? section?.content ?? '').includes('.agents/skills/'));
@@ -94,7 +98,9 @@ export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot,
94
98
  version: entry.version ?? raw.version,
95
99
  ...(entry.contentHash ? { contentHash: entry.contentHash } : {}),
96
100
  ...(entry.revision ? { revision: entry.revision } : {}),
97
- copies: [...new Map(copies.map((copy) => [String(copy.target ?? copy.path ?? copy.source), copy])).values()],
101
+ copies: [
102
+ ...new Map(copies.map((copy) => [String(copy.target ?? copy.path ?? copy.source), copy])).values(),
103
+ ],
98
104
  markdownSections,
99
105
  ...(checker ? { check: { command: ['specdest-cache', entry.id] } } : {}),
100
106
  };
@@ -2,10 +2,22 @@ export declare function createCanonicalSource(options?: any): {
2
2
  cacheRoot: any;
3
3
  cachedModulePath(id: any, version: any): string;
4
4
  hasModule(id: any, version: any, contentHash?: any): Promise<boolean>;
5
- catalog({ refresh }?: any): Promise<any>;
5
+ catalog({ refresh }?: any): Promise<import("./schemas.ts").Catalog | {
6
+ repositoryRevision: string;
7
+ entries: any[];
8
+ schemaVersion?: number;
9
+ package?: import("./schemas.ts").JsonRecord;
10
+ predefinedPackages?: import("./schemas.ts").JsonRecord[];
11
+ }>;
6
12
  module(id: any, version: any, { refresh, contentHash }?: any): Promise<string>;
7
13
  };
8
- export declare function fetchGitHubCatalog(options?: any): Promise<any>;
14
+ export declare function fetchGitHubCatalog(options?: any): Promise<import("./schemas.ts").Catalog | {
15
+ repositoryRevision: string;
16
+ entries: any[];
17
+ schemaVersion?: number;
18
+ package?: import("./schemas.ts").JsonRecord;
19
+ predefinedPackages?: import("./schemas.ts").JsonRecord[];
20
+ }>;
9
21
  export declare function fetchGitHubModule(id: any, options?: any): Promise<{
10
22
  files: {
11
23
  path: string;
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { homedir } from 'node:os';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
5
+ import { CatalogSchema, parseWithSchema } from "./schemas.js";
5
6
  const DEFAULT_REPOSITORY = 'specdest-org/devkit';
6
7
  const DEFAULT_REF = 'main';
7
8
  async function exists(path) {
@@ -22,7 +23,10 @@ function repositoryUrl(options = {}) {
22
23
  if (options.repositoryUrl)
23
24
  return String(options.repositoryUrl);
24
25
  const repository = String(options.repository ?? DEFAULT_REPOSITORY);
25
- if (repository.startsWith('/') || repository.startsWith('.') || repository.includes('://') || repository.startsWith('git@')) {
26
+ if (repository.startsWith('/') ||
27
+ repository.startsWith('.') ||
28
+ repository.includes('://') ||
29
+ repository.startsWith('git@')) {
26
30
  return repository;
27
31
  }
28
32
  return `git@github.com:${repository}.git`;
@@ -34,10 +38,16 @@ function run(command, args, options = {}) {
34
38
  let stderr = '';
35
39
  child.stdout.setEncoding('utf8');
36
40
  child.stderr.setEncoding('utf8');
37
- child.stdout.on('data', (chunk) => { stdout += chunk; });
38
- child.stderr.on('data', (chunk) => { stderr += chunk; });
41
+ child.stdout.on('data', (chunk) => {
42
+ stdout += chunk;
43
+ });
44
+ child.stderr.on('data', (chunk) => {
45
+ stderr += chunk;
46
+ });
39
47
  child.on('error', reject);
40
- child.on('close', (code) => code === 0 ? resolve(stdout) : reject(new Error(`${command} exited ${code}: ${stderr.trim()}`)));
48
+ child.on('close', (code) => code === 0
49
+ ? resolve(stdout)
50
+ : reject(new Error(`${command} exited ${code}: ${stderr.trim()}`)));
41
51
  });
42
52
  }
43
53
  async function ensureGitRepository(cacheRoot, options = {}) {
@@ -67,13 +77,28 @@ async function readGitFile(gitDir, revision, path) {
67
77
  }
68
78
  async function readGitModule(gitDir, revision, id) {
69
79
  const prefix = `modules/${id}/`;
70
- const listed = await run('git', ['--git-dir', gitDir, 'ls-tree', '-r', '--name-only', revision, '--', `modules/${id}`]);
71
- const paths = listed.split('\n').map((value) => value.trim()).filter((value) => value.startsWith(prefix));
80
+ const listed = await run('git', [
81
+ '--git-dir',
82
+ gitDir,
83
+ 'ls-tree',
84
+ '-r',
85
+ '--name-only',
86
+ revision,
87
+ '--',
88
+ `modules/${id}`,
89
+ ]);
90
+ const paths = listed
91
+ .split('\n')
92
+ .map((value) => value.trim())
93
+ .filter((value) => value.startsWith(prefix));
72
94
  if (!paths.length)
73
95
  throw new Error(`Canonical module directory not found: ${id}`);
74
96
  const files = [];
75
97
  for (const path of paths.sort()) {
76
- files.push({ path: path.slice(prefix.length), content: await readGitFile(gitDir, revision, path) });
98
+ files.push({
99
+ path: path.slice(prefix.length),
100
+ content: await readGitFile(gitDir, revision, path),
101
+ });
77
102
  }
78
103
  return { files };
79
104
  }
@@ -95,7 +120,10 @@ async function readMarker(path) {
95
120
  }
96
121
  }
97
122
  function markerMatches(marker, id, version, contentHash) {
98
- return Boolean(marker && marker.id === id && marker.version === version && (!contentHash || marker.contentHash === contentHash));
123
+ return Boolean(marker &&
124
+ marker.id === id &&
125
+ marker.version === version &&
126
+ (!contentHash || marker.contentHash === contentHash));
99
127
  }
100
128
  export function createCanonicalSource(options = {}) {
101
129
  const cacheRoot = options.cacheRoot ?? defaultCacheRoot(options.env);
@@ -108,25 +136,27 @@ export function createCanonicalSource(options = {}) {
108
136
  if (!(await exists(catalogPath)) || !(await exists(catalogMetaPath)))
109
137
  return null;
110
138
  const meta = JSON.parse(await readFile(catalogMetaPath, 'utf8'));
111
- if (!customFetch && (meta.repositoryUrl !== repositoryUrl(options) || meta.ref !== String(options.ref ?? DEFAULT_REF)))
139
+ if (!customFetch &&
140
+ (meta.repositoryUrl !== repositoryUrl(options) ||
141
+ meta.ref !== String(options.ref ?? DEFAULT_REF)))
112
142
  return null;
113
143
  activeRevision = meta.revision ?? null;
114
144
  if (!customFetch)
115
145
  activeGitDir = await ensureGitRepository(cacheRoot, options);
116
- return JSON.parse(await readFile(catalogPath, 'utf8'));
146
+ return parseWithSchema(CatalogSchema, JSON.parse(await readFile(catalogPath, 'utf8')), 'cached canonical catalog');
117
147
  }
118
148
  async function refreshCatalog() {
119
149
  let catalog;
120
150
  let revision;
121
151
  if (options.fetchCatalog) {
122
- catalog = await options.fetchCatalog();
152
+ catalog = parseWithSchema(CatalogSchema, await options.fetchCatalog(), 'canonical catalog');
123
153
  revision = String(catalog.repositoryRevision ?? catalog.package?.version ?? 'custom');
124
154
  }
125
155
  else {
126
156
  const fetched = await fetchGitRevision(cacheRoot, options);
127
157
  activeGitDir = fetched.gitDir;
128
158
  revision = fetched.revision;
129
- const rawCatalog = JSON.parse(await readGitFile(activeGitDir, revision, 'catalog.json'));
159
+ const rawCatalog = parseWithSchema(CatalogSchema, JSON.parse(await readGitFile(activeGitDir, revision, 'catalog.json')), 'canonical catalog');
130
160
  catalog = {
131
161
  ...rawCatalog,
132
162
  repositoryRevision: revision,
@@ -154,7 +184,9 @@ export function createCanonicalSource(options = {}) {
154
184
  }
155
185
  return {
156
186
  cacheRoot,
157
- cachedModulePath(id, version) { return join(cacheRoot, 'rules', id, version); },
187
+ cachedModulePath(id, version) {
188
+ return join(cacheRoot, 'rules', id, version);
189
+ },
158
190
  async hasModule(id, version, contentHash = null) {
159
191
  const marker = await readMarker(join(cacheRoot, 'rules', id, version, '.complete'));
160
192
  return markerMatches(marker, id, version, contentHash);
@@ -196,7 +228,7 @@ async function directoryFiles(root, prefix = '') {
196
228
  continue;
197
229
  const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
198
230
  if (entry.isDirectory())
199
- files.push(...await directoryFiles(join(root, entry.name), relative));
231
+ files.push(...(await directoryFiles(join(root, entry.name), relative)));
200
232
  else if (entry.isFile())
201
233
  files.push({ path: relative, content: await readFile(join(root, entry.name), 'utf8') });
202
234
  }
@@ -1,36 +1,36 @@
1
- export function buildCatalogSnapshot(): Promise<{
1
+ export declare function buildCatalogSnapshot(): Promise<{
2
2
  package: {
3
- name: any;
4
- version: any;
3
+ name: string | undefined;
4
+ version: string | undefined;
5
5
  };
6
6
  entries: {
7
7
  source: string;
8
- projectProfiles?: {
9
- [k: string]: {
10
- ruleIds: any[];
11
- };
12
- } | undefined;
13
- notApplicableRuleIds?: any[] | undefined;
14
- composedOf?: string[] | undefined;
15
- verification?: any;
16
- ai?: any;
17
- requiredCapabilities?: string[] | undefined;
18
- requiredPackages?: string[] | undefined;
19
- applicableStacks?: any[] | undefined;
20
- enforcement?: string | undefined;
21
- legacyInstalledIds?: any[] | undefined;
8
+ id: string;
9
+ kind: "rule" | "module";
10
+ version: string;
11
+ name: string;
12
+ content: string;
22
13
  order: number;
23
14
  revision: string;
24
15
  contentHash: string;
25
- labels?: string[] | undefined;
26
- scope?: string | undefined;
27
- category?: string | undefined;
28
- summary?: any;
29
- id: any;
30
- kind: any;
31
- version: string;
32
- name: any;
33
- content: any;
16
+ summary?: string;
17
+ category?: string;
18
+ scope?: string;
19
+ labels?: string[];
20
+ enforcement?: string;
21
+ legacyInstalledIds?: string[];
22
+ applicableStacks?: string[];
23
+ requiredPackages?: string[];
24
+ requiredCapabilities?: string[];
25
+ composedOf?: string[];
26
+ notApplicableRuleIds?: string[];
27
+ projectProfiles?: {
28
+ [x: string]: {
29
+ ruleIds: string[];
30
+ };
31
+ };
32
+ ai?: unknown;
33
+ verification?: unknown;
34
34
  }[];
35
35
  predefinedPackages: {
36
36
  id: string;
@@ -42,6 +42,12 @@ export function buildCatalogSnapshot(): Promise<{
42
42
  id: string;
43
43
  when: string[];
44
44
  }[];
45
+ setupRequirements: {
46
+ kind: "package";
47
+ packageId: string;
48
+ required: boolean;
49
+ when?: "git";
50
+ }[];
45
51
  }[];
46
52
  schemaVersion: number;
47
53
  }>;
@@ -1,17 +1,21 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { fileURLToPath } from 'node:url';
3
- import { buildGitCatalog } from './git-catalog.js';
3
+ import { buildGitCatalog } from "./git-catalog.js";
4
4
  import { listPackageRecipes } from "./predefined-packages/registry.js";
5
+ import { PackageJsonSchema, parseWithSchema } from "./schemas.js";
5
6
  const MODULES_ROOT = fileURLToPath(new URL('../modules/', import.meta.url));
6
7
  export async function buildCatalogSnapshot() {
7
- const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
8
- const catalog = await buildGitCatalog({ modulesRoot: MODULES_ROOT, repositoryRevision: packageJson.version });
8
+ const packageJson = parseWithSchema(PackageJsonSchema, JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')), 'DevKit package.json');
9
+ const catalog = await buildGitCatalog({
10
+ modulesRoot: MODULES_ROOT,
11
+ repositoryRevision: packageJson.version,
12
+ });
9
13
  return {
10
14
  ...catalog,
11
15
  package: { name: packageJson.name, version: packageJson.version },
12
16
  entries: catalog.entries
13
17
  .map((entry) => ({ ...entry, source: '@specdest/devkit' }))
14
- .sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
18
+ .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)),
15
19
  predefinedPackages: listPackageRecipes()
16
20
  .map((recipe) => ({
17
21
  id: recipe.id,
@@ -22,6 +26,9 @@ export async function buildCatalogSnapshot() {
22
26
  variants: (recipe.variants ?? [])
23
27
  .map((variant) => ({ id: variant.id, when: [...variant.when].sort() }))
24
28
  .sort((a, b) => a.id.localeCompare(b.id)),
29
+ setupRequirements: (recipe.setupRequirements ?? [])
30
+ .map((requirement) => ({ ...requirement }))
31
+ .sort((a, b) => a.packageId.localeCompare(b.packageId)),
25
32
  }))
26
33
  .sort((a, b) => a.id.localeCompare(b.id)),
27
34
  };
package/dist/npm/cli.js CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { createFlowCommandHandler, createFuzzCommandHandler, runCli } from "./index.js";
2
+ import { createFlowCommandHandler, runCli } from "./index.js";
3
3
  import { createCanonicalCommandHandlers } from "./canonical-project-operations.js";
4
+ import { runSupabaseLocal } from "./supabase-local.js";
5
+ import { sendSlackFiles } from "./slack.js";
4
6
  try {
5
7
  const exitCode = await runCli(process.argv.slice(2), process, {
6
8
  ...createCanonicalCommandHandlers(),
7
- fuzz: createFuzzCommandHandler(),
8
9
  flow: createFlowCommandHandler(),
10
+ supabase: async (args) => runSupabaseLocal(args),
11
+ slack: async (args) => sendSlackFiles(args),
9
12
  });
10
13
  process.exitCode = exitCode;
11
14
  }
@@ -1,3 +1,9 @@
1
+ export declare function checkFlags(args: string[]): {
2
+ refresh: boolean;
3
+ json: boolean;
4
+ mode: "full" | "staged" | "files";
5
+ files: string[] | null;
6
+ };
1
7
  export declare function createCanonicalCommandHandlers(projectRoot?: string, options?: any): {
2
8
  add: (args: string[], io: any) => Promise<0 | 1 | 2>;
3
9
  status: (args: string[], io: any) => Promise<0 | 1>;
@@ -11,9 +11,10 @@ function flags(args) {
11
11
  throw new Error(`Unknown option: ${arg}`);
12
12
  return { refresh: args.includes('--refresh'), json: args.includes('--json') };
13
13
  }
14
- function checkFlags(args) {
14
+ export function checkFlags(args) {
15
15
  const result = {
16
16
  refresh: false,
17
+ json: false,
17
18
  mode: 'full',
18
19
  files: null,
19
20
  };
@@ -21,6 +22,8 @@ function checkFlags(args) {
21
22
  for (const arg of args) {
22
23
  if (arg === '--refresh')
23
24
  result.refresh = true;
25
+ else if (arg === '--json')
26
+ result.json = true;
24
27
  else
25
28
  remaining.push(arg);
26
29
  }
@@ -28,14 +31,14 @@ function checkFlags(args) {
28
31
  throw new Error('Use either --staged or --files, not both');
29
32
  if (remaining.includes('--staged')) {
30
33
  if (remaining.length !== 1)
31
- throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
34
+ throw new Error('Usage: specdest check [--refresh] [--json] [--staged | --files <path...>]');
32
35
  result.mode = 'staged';
33
36
  return result;
34
37
  }
35
38
  const filesIndex = remaining.indexOf('--files');
36
39
  if (filesIndex >= 0) {
37
40
  if (filesIndex !== 0 || remaining.length < 2)
38
- throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
41
+ throw new Error('Usage: specdest check [--refresh] [--json] [--staged | --files <path...>]');
39
42
  result.mode = 'files';
40
43
  result.files = remaining.slice(1);
41
44
  return result;
@@ -45,7 +48,12 @@ function checkFlags(args) {
45
48
  return result;
46
49
  }
47
50
  function rulesFlags(args) {
48
- const result = { json: false, ids: [], categories: [], failed: false };
51
+ const result = {
52
+ json: false,
53
+ ids: [],
54
+ categories: [],
55
+ failed: false,
56
+ };
49
57
  for (let index = 0; index < args.length; index += 1) {
50
58
  const arg = args[index];
51
59
  if (arg === '--json')
@@ -71,9 +79,12 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
71
79
  }
72
80
  try {
73
81
  const result = await addPredefinedPackage(projectRoot, args[0]);
82
+ const setup = result.setupPackages?.length
83
+ ? `; ensured stack setup: ${result.setupPackages.join(', ')}`
84
+ : '';
74
85
  io.stdout.write(result.changed
75
- ? `Registered ${result.id} (recipe ${result.recipeVersion}, detected ${result.detectedVersion ?? 'unknown'}, ${result.source})\n`
76
- : `${result.id} already registered (recipe ${result.recipeVersion}, detected ${result.detectedVersion ?? 'unknown'}); no changes.\n`);
86
+ ? `Registered ${result.id} (recipe ${result.recipeVersion}, detected ${result.detectedVersion ?? 'unknown'}, ${result.source})${setup}\n`
87
+ : `${result.id} already registered (recipe ${result.recipeVersion}, detected ${result.detectedVersion ?? 'unknown'}); no changes${setup}.\n`);
77
88
  return 0;
78
89
  }
79
90
  catch (error) {
@@ -116,8 +127,20 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
116
127
  return 2;
117
128
  }
118
129
  const result = await canonicalCheck(projectRoot, source, parsed);
119
- for (const [id, check] of Object.entries(result.results))
130
+ if (parsed.json) {
131
+ io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
132
+ return result.exitCode;
133
+ }
134
+ for (const [id, check] of Object.entries(result.results)) {
120
135
  io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
136
+ }
137
+ for (const execution of result.executions.filter((item) => item.exitCode !== 0)) {
138
+ io.stderr.write(`\nChecker failure (${execution.ids.join(', ')}):\n`);
139
+ if (execution.stdout)
140
+ io.stderr.write(execution.stdout.endsWith('\n') ? execution.stdout : `${execution.stdout}\n`);
141
+ if (execution.stderr)
142
+ io.stderr.write(execution.stderr.endsWith('\n') ? execution.stderr : `${execution.stderr}\n`);
143
+ }
121
144
  return result.exitCode;
122
145
  },
123
146
  rules: async (args, io) => {
@@ -128,7 +151,9 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
128
151
  else {
129
152
  for (const rule of result.rules) {
130
153
  const body = result.detail ? rule.content.trim() : rule.summary;
131
- const composition = rule.composedOf.length ? `\nComposed of: ${rule.composedOf.join(', ')}` : '';
154
+ const composition = rule.composedOf.length
155
+ ? `\nComposed of: ${rule.composedOf.join(', ')}`
156
+ : '';
132
157
  io.stdout.write(`## ${rule.id} — ${rule.name}\n${body}${composition}\n\n`);
133
158
  }
134
159
  }