@specdest/devkit 0.4.6 → 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 (131) hide show
  1. package/README.md +52 -20
  2. package/dist/npm/canonical-project-operations.d.ts +5 -0
  3. package/dist/npm/canonical-project-operations.js +5 -0
  4. package/dist/npm/canonical-project.d.ts +21 -0
  5. package/dist/npm/canonical-project.js +115 -0
  6. package/dist/npm/canonical-source.d.ts +26 -0
  7. package/dist/npm/canonical-source.js +248 -0
  8. package/dist/npm/catalog-snapshot.d.ts +53 -0
  9. package/dist/npm/catalog-snapshot.js +35 -0
  10. package/dist/npm/cli.d.ts +2 -0
  11. package/dist/npm/cli.js +18 -0
  12. package/dist/npm/commands.d.ts +15 -0
  13. package/dist/npm/commands.js +182 -0
  14. package/dist/npm/flow.d.ts +48 -0
  15. package/dist/npm/flow.js +430 -0
  16. package/dist/npm/git-catalog.d.ts +40 -0
  17. package/dist/npm/git-catalog.js +222 -0
  18. package/dist/npm/index.d.ts +4 -0
  19. package/dist/npm/index.js +32 -0
  20. package/dist/npm/installer-primitives.d.ts +3 -0
  21. package/dist/npm/installer-primitives.js +50 -0
  22. package/dist/npm/predefined-packages/abac.d.ts +2 -0
  23. package/dist/npm/predefined-packages/abac.js +22 -0
  24. package/dist/npm/predefined-packages/auth.d.ts +2 -0
  25. package/dist/npm/predefined-packages/auth.js +21 -0
  26. package/dist/npm/predefined-packages/convex.d.ts +2 -0
  27. package/dist/npm/predefined-packages/convex.js +53 -0
  28. package/dist/npm/predefined-packages/expo.d.ts +2 -0
  29. package/dist/npm/predefined-packages/expo.js +88 -0
  30. package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
  31. package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
  32. package/dist/npm/predefined-packages/health.d.ts +10 -0
  33. package/dist/npm/predefined-packages/health.js +52 -0
  34. package/dist/npm/predefined-packages/husky.d.ts +2 -0
  35. package/dist/npm/predefined-packages/husky.js +57 -0
  36. package/dist/npm/predefined-packages/index.d.ts +12 -0
  37. package/dist/npm/predefined-packages/index.js +97 -0
  38. package/dist/npm/predefined-packages/install.d.ts +19 -0
  39. package/dist/npm/predefined-packages/install.js +86 -0
  40. package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
  41. package/dist/npm/predefined-packages/local-logging.js +17 -0
  42. package/dist/npm/predefined-packages/logging.d.ts +2 -0
  43. package/dist/npm/predefined-packages/logging.js +21 -0
  44. package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
  45. package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
  46. package/dist/npm/predefined-packages/nps.d.ts +2 -0
  47. package/dist/npm/predefined-packages/nps.js +32 -0
  48. package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
  49. package/dist/npm/predefined-packages/oxfmt.js +22 -0
  50. package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
  51. package/dist/npm/predefined-packages/oxlint.js +35 -0
  52. package/dist/npm/predefined-packages/package-json.d.ts +3 -0
  53. package/dist/npm/predefined-packages/package-json.js +61 -0
  54. package/dist/npm/predefined-packages/payments.d.ts +2 -0
  55. package/dist/npm/predefined-packages/payments.js +31 -0
  56. package/dist/npm/predefined-packages/playwright.d.ts +2 -0
  57. package/dist/npm/predefined-packages/playwright.js +35 -0
  58. package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
  59. package/dist/npm/predefined-packages/project-signals.js +39 -0
  60. package/dist/npm/predefined-packages/registry.d.ts +3 -0
  61. package/dist/npm/predefined-packages/registry.js +63 -0
  62. package/dist/npm/predefined-packages/resolver.d.ts +8 -0
  63. package/dist/npm/predefined-packages/resolver.js +35 -0
  64. package/dist/npm/predefined-packages/sentry.d.ts +2 -0
  65. package/dist/npm/predefined-packages/sentry.js +29 -0
  66. package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
  67. package/dist/npm/predefined-packages/shadcn.js +23 -0
  68. package/dist/npm/predefined-packages/storybook.d.ts +2 -0
  69. package/dist/npm/predefined-packages/storybook.js +25 -0
  70. package/dist/npm/predefined-packages/stryker.d.ts +2 -0
  71. package/dist/npm/predefined-packages/stryker.js +48 -0
  72. package/dist/npm/predefined-packages/supabase.d.ts +2 -0
  73. package/dist/npm/predefined-packages/supabase.js +335 -0
  74. package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
  75. package/dist/npm/predefined-packages/tailwind.js +18 -0
  76. package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
  77. package/dist/npm/predefined-packages/tanstack-form.js +19 -0
  78. package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
  79. package/dist/npm/predefined-packages/tanstack-query.js +15 -0
  80. package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
  81. package/dist/npm/predefined-packages/tanstack-router.js +18 -0
  82. package/dist/npm/predefined-packages/types.d.ts +38 -0
  83. package/dist/npm/predefined-packages/types.js +1 -0
  84. package/dist/npm/predefined-packages/vite.d.ts +2 -0
  85. package/dist/npm/predefined-packages/vite.js +127 -0
  86. package/dist/npm/predefined-packages/vitest.d.ts +2 -0
  87. package/dist/npm/predefined-packages/vitest.js +20 -0
  88. package/dist/npm/predefined-packages/zod.d.ts +2 -0
  89. package/dist/npm/predefined-packages/zod.js +18 -0
  90. package/dist/npm/project-check.d.ts +14 -0
  91. package/dist/npm/project-check.js +118 -0
  92. package/dist/npm/project-context.d.ts +52 -0
  93. package/dist/npm/project-context.js +206 -0
  94. package/dist/npm/project-rules.d.ts +25 -0
  95. package/dist/npm/project-rules.js +75 -0
  96. package/dist/npm/project-runtime.d.ts +21 -0
  97. package/dist/npm/project-runtime.js +41 -0
  98. package/dist/npm/project-status.d.ts +32 -0
  99. package/dist/npm/project-status.js +70 -0
  100. package/dist/npm/project-sync.d.ts +7 -0
  101. package/dist/npm/project-sync.js +143 -0
  102. package/dist/npm/remote-installer.d.ts +35 -0
  103. package/dist/npm/remote-installer.js +351 -0
  104. package/dist/npm/rule-id-migrations.d.ts +6 -0
  105. package/dist/npm/rule-id-migrations.js +19 -0
  106. package/dist/npm/schemas.d.ts +64 -0
  107. package/dist/npm/schemas.js +194 -0
  108. package/dist/npm/slack.d.ts +16 -0
  109. package/dist/npm/slack.js +131 -0
  110. package/dist/npm/state.d.ts +14 -0
  111. package/dist/npm/state.js +231 -0
  112. package/dist/npm/supabase-local.d.ts +2 -0
  113. package/dist/npm/supabase-local.js +62 -0
  114. package/package.json +18 -12
  115. package/src/canonical-project-operations.js +0 -438
  116. package/src/canonical-project.js +0 -136
  117. package/src/canonical-source.js +0 -250
  118. package/src/catalog-snapshot.js +0 -39
  119. package/src/catalog.js +0 -117
  120. package/src/cli.js +0 -14
  121. package/src/fuzz.js +0 -291
  122. package/src/git-catalog.js +0 -177
  123. package/src/index.js +0 -36
  124. package/src/installer-primitives.js +0 -198
  125. package/src/project-operations.js +0 -189
  126. package/src/project-targeting.js +0 -48
  127. package/src/remote-installer.js +0 -479
  128. package/src/rule-profile.js +0 -61
  129. package/src/setup-requirements.js +0 -82
  130. package/src/shared-file.js +0 -131
  131. package/src/sync-core.js +0 -390
@@ -0,0 +1,351 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
3
+ import { dirname, isAbsolute, resolve, sep } from 'node:path';
4
+ import { removeMarkdownSection, resolveProjectPath, upsertMarkdownSection, } from "./installer-primitives.js";
5
+ import { CanonicalManifestSchema, parseWithSchema } from "./schemas.js";
6
+ import { readChecksState, readInstalledState, writeChecksState, writeInstalledState, } from "./state.js";
7
+ const SUPPORTED_OPERATIONS = new Set([
8
+ 'copy_file',
9
+ 'scaffold_file',
10
+ 'managed_section',
11
+ ]);
12
+ const clone = (value) => value === undefined ? value : JSON.parse(JSON.stringify(value));
13
+ const hash = (value) => createHash('sha256')
14
+ .update(typeof value === 'string' ? value : JSON.stringify(value))
15
+ .digest('hex');
16
+ function payloadPath(payloadRoot, relativePath) {
17
+ if (!relativePath || isAbsolute(relativePath))
18
+ throw new Error(`Source must be payload-relative: ${relativePath}`);
19
+ const root = resolve(payloadRoot);
20
+ const target = resolve(root, relativePath);
21
+ if (target !== root && !target.startsWith(`${root}${sep}`))
22
+ throw new Error(`Source escapes payload: ${relativePath}`);
23
+ return target;
24
+ }
25
+ async function exists(path) {
26
+ try {
27
+ await stat(path);
28
+ return true;
29
+ }
30
+ catch (error) {
31
+ if (error?.code === 'ENOENT')
32
+ return false;
33
+ throw error;
34
+ }
35
+ }
36
+ const checkerSkillIds = new Map([
37
+ ['abac-permissions-convex', 'abac-permissions'],
38
+ ['abac-permissions-supabase', 'abac-permissions'],
39
+ ['unit-test-rules-convex', 'unit-test-rules'],
40
+ ['unit-test-rules-supabase', 'unit-test-rules'],
41
+ ]);
42
+ function checkerSkillId(implementation) {
43
+ return checkerSkillIds.get(implementation) ?? implementation;
44
+ }
45
+ function normalizeOperation(raw) {
46
+ const type = String(raw.type ?? '');
47
+ if (!SUPPORTED_OPERATIONS.has(type)) {
48
+ throw new Error(`Unsupported manifest operation: ${type || 'undefined'}`);
49
+ }
50
+ if (type === 'managed_section') {
51
+ return {
52
+ type,
53
+ path: String(raw.path ?? ''),
54
+ heading: String(raw.heading ?? ''),
55
+ content: raw.content,
56
+ };
57
+ }
58
+ return {
59
+ type: type,
60
+ path: String(raw.path ?? ''),
61
+ source: String(raw.source ?? ''),
62
+ };
63
+ }
64
+ function normalizeManifest(manifest) {
65
+ const operations = (manifest.operations ?? []).map(normalizeOperation);
66
+ const checkerImplementation = String(manifest.checker?.implementation ?? '').trim();
67
+ const check = manifest.check ??
68
+ (checkerImplementation
69
+ ? { command: ['node', `.agents/skills/${checkerSkillId(checkerImplementation)}/check.ts`] }
70
+ : undefined);
71
+ for (const copy of manifest.copies ?? []) {
72
+ if (copy.type === 'directory' || copy.directory === true) {
73
+ throw new Error(`Directory copies are not supported: ${String(copy.source ?? '')}`);
74
+ }
75
+ operations.push({
76
+ type: copy.mode === 'scaffold' || copy.mode === 'create-only' ? 'scaffold_file' : 'copy_file',
77
+ source: String(copy.source ?? ''),
78
+ path: String(copy.target ?? copy.path ?? ''),
79
+ });
80
+ }
81
+ for (const section of manifest.markdownSections ?? []) {
82
+ operations.push({
83
+ type: 'managed_section',
84
+ path: String(section.path ?? ''),
85
+ heading: String(section.heading ?? ''),
86
+ content: section.body ?? section.content ?? '',
87
+ });
88
+ }
89
+ return { ...manifest, operations, ...(check ? { check } : {}) };
90
+ }
91
+ export function validateRemoteManifest(input) {
92
+ const parsed = parseWithSchema(CanonicalManifestSchema, input, 'canonical manifest');
93
+ const manifest = normalizeManifest(parsed);
94
+ for (const operation of manifest.operations) {
95
+ resolveProjectPath('/__specdest_project__', operation.path);
96
+ if (operation.type !== 'managed_section' && !operation.source.trim()) {
97
+ throw new Error(`Manifest operation source is required: ${operation.type}`);
98
+ }
99
+ if (operation.type === 'managed_section' && !operation.heading.trim()) {
100
+ throw new Error('Managed section heading is required');
101
+ }
102
+ }
103
+ return manifest;
104
+ }
105
+ function ownershipKey(operation) {
106
+ return operation.type === 'managed_section'
107
+ ? `section:${operation.path}:${operation.heading}`
108
+ : `file:${operation.path}`;
109
+ }
110
+ async function readProjectFile(projectRoot, relativePath) {
111
+ const target = resolveProjectPath(projectRoot, relativePath);
112
+ if (!(await exists(target)))
113
+ return { exists: false, value: '' };
114
+ return { exists: true, value: await readFile(target, 'utf8') };
115
+ }
116
+ async function writeProjectFile(projectRoot, relativePath, content) {
117
+ const target = resolveProjectPath(projectRoot, relativePath);
118
+ await mkdir(dirname(target), { recursive: true });
119
+ await writeFile(target, content, 'utf8');
120
+ }
121
+ function sectionBody(text, heading) {
122
+ const trimmed = heading.trim();
123
+ const level = trimmed.match(/^(#{1,6})\s+/)?.[1].length ?? 2;
124
+ const lines = text.split(/(?<=\n)/u);
125
+ let found = false;
126
+ const body = [];
127
+ for (const line of lines) {
128
+ if (!found) {
129
+ if (line.trim() === trimmed)
130
+ found = true;
131
+ continue;
132
+ }
133
+ if (new RegExp(`^#{1,${level}}\\s+`, 'u').test(line.trim()))
134
+ break;
135
+ body.push(line);
136
+ }
137
+ return found ? body.join('').trim() : null;
138
+ }
139
+ function legacyMarkdownSection(text, heading) {
140
+ const lines = text.split(/(?<=\n)/u);
141
+ const level = heading.trim().match(/^(#{1,6})\s/u)?.[1].length ?? 2;
142
+ let start = -1;
143
+ let end = text.length;
144
+ let offset = 0;
145
+ for (const line of lines) {
146
+ if (start < 0 && line.trim() === heading.trim())
147
+ start = offset;
148
+ else if (start >= 0 && new RegExp(`^#{1,${level}}\\s+`, 'u').test(line.trim())) {
149
+ end = offset;
150
+ break;
151
+ }
152
+ offset += line.length;
153
+ }
154
+ return start < 0
155
+ ? { exists: false, value: '' }
156
+ : { exists: true, value: text.slice(start, end).trimEnd() };
157
+ }
158
+ async function migrateLegacyMarkdownOwnership(projectRoot, prior) {
159
+ for (const [key, record] of Object.entries(prior)) {
160
+ if (record?.type !== 'markdown')
161
+ continue;
162
+ const file = await readProjectFile(projectRoot, record.path);
163
+ const legacyCurrent = file.exists
164
+ ? legacyMarkdownSection(file.value, record.heading)
165
+ : { exists: false, value: '' };
166
+ if (record.appliedHash !== fingerprint(legacyCurrent)) {
167
+ throw new Error(`Conflict: managed content changed: ${record.path}`);
168
+ }
169
+ const currentBody = file.exists ? sectionBody(file.value, record.heading) : null;
170
+ const nextKey = `section:${record.path}:${record.heading}`;
171
+ if (prior[nextKey])
172
+ throw new Error(`Conflicting ownership records: ${record.path}`);
173
+ const previousBody = record.previousExists
174
+ ? sectionBody(String(record.previousValue ?? ''), record.heading)
175
+ : null;
176
+ prior[nextKey] = {
177
+ type: 'section',
178
+ path: record.path,
179
+ heading: record.heading,
180
+ previousExists: Boolean(record.previousExists),
181
+ previousValue: previousBody ?? '',
182
+ appliedHash: fingerprint({ exists: currentBody !== null, value: currentBody ?? '' }),
183
+ };
184
+ delete prior[key];
185
+ }
186
+ }
187
+ async function currentOwnership(projectRoot, record) {
188
+ const file = await readProjectFile(projectRoot, record.path);
189
+ if (record.type === 'file')
190
+ return file;
191
+ const body = file.exists ? sectionBody(file.value, record.heading) : null;
192
+ return { exists: body !== null, value: body ?? '' };
193
+ }
194
+ function fingerprint(value) {
195
+ return hash({ exists: value.exists, value: value.value });
196
+ }
197
+ function assertOwned(record, current) {
198
+ if (record.appliedHash !== fingerprint(current))
199
+ throw new Error(`Conflict: managed content changed: ${record.path}`);
200
+ }
201
+ async function restoreOwnership(projectRoot, record) {
202
+ const current = await currentOwnership(projectRoot, record);
203
+ assertOwned(record, current);
204
+ if (record.type === 'file') {
205
+ const target = resolveProjectPath(projectRoot, record.path);
206
+ if (record.previousExists)
207
+ await writeProjectFile(projectRoot, record.path, record.previousValue);
208
+ else if (await exists(target))
209
+ await unlink(target);
210
+ return;
211
+ }
212
+ const file = await readProjectFile(projectRoot, record.path);
213
+ const updated = record.previousExists
214
+ ? upsertMarkdownSection(file.value, record.heading, record.previousValue)
215
+ : removeMarkdownSection(file.value, record.heading);
216
+ await writeProjectFile(projectRoot, record.path, updated);
217
+ }
218
+ async function applyManagedFile(operation, context) {
219
+ const key = ownershipKey(operation);
220
+ const current = await readProjectFile(context.projectRoot, operation.path);
221
+ const prior = context.prior[key];
222
+ if (prior)
223
+ assertOwned(prior, current);
224
+ const source = await readFile(payloadPath(context.payloadRoot, operation.source), 'utf8');
225
+ await writeProjectFile(context.projectRoot, operation.path, source);
226
+ const original = prior ?? { previousExists: current.exists, previousValue: current.value };
227
+ context.next[key] = {
228
+ type: 'file',
229
+ path: operation.path,
230
+ previousExists: original.previousExists,
231
+ previousValue: original.previousValue,
232
+ appliedHash: fingerprint({ exists: true, value: source }),
233
+ };
234
+ context.touched.add(key);
235
+ }
236
+ async function applyScaffold(operation, context) {
237
+ const key = ownershipKey(operation);
238
+ const prior = context.prior[key];
239
+ if (prior) {
240
+ delete context.next[key];
241
+ context.touched.add(key);
242
+ return;
243
+ }
244
+ const target = resolveProjectPath(context.projectRoot, operation.path);
245
+ if (await exists(target))
246
+ return;
247
+ const source = await readFile(payloadPath(context.payloadRoot, operation.source), 'utf8');
248
+ await writeProjectFile(context.projectRoot, operation.path, source);
249
+ }
250
+ async function applyManagedSection(operation, context) {
251
+ const key = ownershipKey(operation);
252
+ const file = await readProjectFile(context.projectRoot, operation.path);
253
+ const body = file.exists ? sectionBody(file.value, operation.heading) : null;
254
+ const current = { exists: body !== null, value: body ?? '' };
255
+ const prior = context.prior[key];
256
+ if (prior)
257
+ assertOwned(prior, current);
258
+ const original = prior ?? { previousExists: current.exists, previousValue: current.value };
259
+ const updated = upsertMarkdownSection(file.value, operation.heading, String(operation.content ?? ''));
260
+ await writeProjectFile(context.projectRoot, operation.path, updated);
261
+ const appliedBody = sectionBody(updated, operation.heading) ?? '';
262
+ context.next[key] = {
263
+ type: 'section',
264
+ path: operation.path,
265
+ heading: operation.heading,
266
+ previousExists: original.previousExists,
267
+ previousValue: original.previousValue,
268
+ appliedHash: fingerprint({ exists: true, value: appliedBody }),
269
+ };
270
+ context.touched.add(key);
271
+ }
272
+ async function applyOperation(operation, context) {
273
+ if (operation.type === 'copy_file')
274
+ return applyManagedFile(operation, context);
275
+ if (operation.type === 'scaffold_file')
276
+ return applyScaffold(operation, context);
277
+ return applyManagedSection(operation, context);
278
+ }
279
+ async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManifest }) {
280
+ const manifest = validateRemoteManifest(inputManifest);
281
+ const installedState = await readInstalledState(projectRoot);
282
+ const runtimeState = await readChecksState(projectRoot);
283
+ runtimeState.results ??= {};
284
+ runtimeState.ownership ??= {};
285
+ const installed = installedState.installed[manifest.id];
286
+ if (kind === 'install' && installed)
287
+ throw new Error(`${manifest.id} is already installed`);
288
+ if (kind !== 'install' && !installed)
289
+ throw new Error(`${manifest.id} is not installed`);
290
+ const prior = clone((runtimeState.ownership[manifest.id] ?? {}));
291
+ await migrateLegacyMarkdownOwnership(projectRoot, prior);
292
+ const context = {
293
+ projectRoot,
294
+ payloadRoot,
295
+ prior,
296
+ next: clone(prior),
297
+ touched: new Set(),
298
+ };
299
+ if (kind === 'remove') {
300
+ for (const record of Object.values(prior))
301
+ await restoreOwnership(projectRoot, record);
302
+ context.next = {};
303
+ }
304
+ else {
305
+ for (const operation of manifest.operations)
306
+ await applyOperation(operation, context);
307
+ for (const [key, record] of Object.entries(prior)) {
308
+ if (!context.touched.has(key) && context.next[key]) {
309
+ await restoreOwnership(projectRoot, record);
310
+ delete context.next[key];
311
+ }
312
+ }
313
+ }
314
+ if (kind === 'remove') {
315
+ delete installedState.installed[manifest.id];
316
+ installedState.requested = installedState.requested.filter((id) => id !== manifest.id);
317
+ delete runtimeState.ownership[manifest.id];
318
+ delete runtimeState.results[manifest.id];
319
+ }
320
+ else {
321
+ const contentHash = String(manifest.contentHash ??
322
+ hash({
323
+ id: manifest.id,
324
+ revision: manifest.revision ?? null,
325
+ operations: manifest.operations,
326
+ check: manifest.check ?? null,
327
+ }));
328
+ const revision = String(manifest.revision ?? contentHash);
329
+ installedState.installed[manifest.id] = {
330
+ kind: manifest.kind ?? 'rule',
331
+ version: String(manifest.version ?? contentHash),
332
+ revision,
333
+ contentHash,
334
+ ...(manifest.check ? { check: clone(manifest.check) } : {}),
335
+ };
336
+ installedState.requested = [...new Set([...installedState.requested, manifest.id])].sort();
337
+ runtimeState.ownership[manifest.id] = context.next;
338
+ }
339
+ await writeInstalledState(projectRoot, { ...installedState, schemaVersion: 2 });
340
+ await writeChecksState(projectRoot, { ...runtimeState, schemaVersion: 2 });
341
+ return installedState.installed[manifest.id] ?? null;
342
+ }
343
+ export async function installRule(options) {
344
+ return reconcile('install', options);
345
+ }
346
+ export async function syncRule(options) {
347
+ return reconcile('sync', options);
348
+ }
349
+ export async function removeRule(options) {
350
+ return reconcile('remove', options);
351
+ }
@@ -0,0 +1,6 @@
1
+ export declare const RULE_ID_MIGRATIONS: Readonly<{
2
+ readonly 'db-local-validation': "db-schema-static-validation";
3
+ }>;
4
+ export declare function migrateRuleId(id: string): string;
5
+ export declare function migrateRuleIdList(ids: string[]): string[];
6
+ export declare function migrateRuleIdMap<T>(values: Record<string, T>): Record<string, T>;
@@ -0,0 +1,19 @@
1
+ export const RULE_ID_MIGRATIONS = Object.freeze({
2
+ 'db-local-validation': 'db-schema-static-validation',
3
+ });
4
+ export function migrateRuleId(id) {
5
+ return RULE_ID_MIGRATIONS[id] ?? id;
6
+ }
7
+ export function migrateRuleIdList(ids) {
8
+ return [...new Set(ids.map(migrateRuleId))].sort();
9
+ }
10
+ export function migrateRuleIdMap(values) {
11
+ const migrated = {};
12
+ for (const [id, value] of Object.entries(values)) {
13
+ const nextId = migrateRuleId(id);
14
+ if (nextId in migrated && id !== nextId)
15
+ continue;
16
+ migrated[nextId] = value;
17
+ }
18
+ return migrated;
19
+ }
@@ -0,0 +1,64 @@
1
+ export type JsonRecord = Record<string, unknown>;
2
+ export type PackageJson = JsonRecord & {
3
+ name?: string;
4
+ version?: string;
5
+ packageManager?: string;
6
+ scripts?: Record<string, string>;
7
+ dependencies?: Record<string, string>;
8
+ devDependencies?: Record<string, string>;
9
+ };
10
+ export type InstalledEntry = JsonRecord & {
11
+ kind?: string;
12
+ };
13
+ export type InstalledState = JsonRecord & {
14
+ schemaVersion: 1 | 2;
15
+ requested?: string[];
16
+ installed: Record<string, InstalledEntry>;
17
+ };
18
+ export type ChecksState = JsonRecord & {
19
+ schemaVersion: 1 | 2;
20
+ checkedAt?: string | null;
21
+ results: Record<string, JsonRecord>;
22
+ ownership?: Record<string, JsonRecord>;
23
+ };
24
+ export type RuleProfile = JsonRecord & {
25
+ schemaVersion: 1;
26
+ projectType?: string | null;
27
+ capabilities?: string[];
28
+ include?: string[];
29
+ exclude?: JsonRecord[];
30
+ };
31
+ export type CatalogEntry = JsonRecord & {
32
+ id: string;
33
+ kind?: 'rule' | 'module';
34
+ version: string;
35
+ contentHash?: string;
36
+ revision?: string;
37
+ };
38
+ export type Catalog = JsonRecord & {
39
+ schemaVersion?: number;
40
+ package?: JsonRecord;
41
+ entries: CatalogEntry[];
42
+ predefinedPackages?: JsonRecord[];
43
+ };
44
+ export type CanonicalManifest = JsonRecord & {
45
+ id: string;
46
+ version?: string;
47
+ kind?: string;
48
+ operations?: JsonRecord[];
49
+ copies?: JsonRecord[];
50
+ markdownSections?: JsonRecord[];
51
+ checker?: JsonRecord;
52
+ check?: JsonRecord;
53
+ };
54
+ export type RuntimeSchema<T> = {
55
+ parse(value: unknown): T;
56
+ };
57
+ export declare const PackageJsonSchema: RuntimeSchema<PackageJson>;
58
+ export declare const InstalledStateSchema: RuntimeSchema<InstalledState>;
59
+ export declare const ChecksStateSchema: RuntimeSchema<ChecksState>;
60
+ export declare const RuleProfileSchema: RuntimeSchema<RuleProfile>;
61
+ export declare const CatalogSchema: RuntimeSchema<Catalog>;
62
+ export declare const CanonicalManifestSchema: RuntimeSchema<CanonicalManifest>;
63
+ export declare function parseWithSchema<T>(schema: RuntimeSchema<T>, value: unknown, label: string): T;
64
+ export declare function parseJsonWithSchema<T>(schema: RuntimeSchema<T>, text: string, label: string): T;
@@ -0,0 +1,194 @@
1
+ function record(value, path) {
2
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
3
+ throw new Error(`${path} must be an object`);
4
+ }
5
+ return value;
6
+ }
7
+ function optionalString(value, path) {
8
+ if (value === undefined)
9
+ return undefined;
10
+ if (typeof value !== 'string')
11
+ throw new Error(`${path} must be a string`);
12
+ return value;
13
+ }
14
+ function stringArray(value, path) {
15
+ if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
16
+ throw new Error(`${path} must be an array of strings`);
17
+ }
18
+ return value;
19
+ }
20
+ function stringMap(value, path) {
21
+ const object = record(value, path);
22
+ for (const [key, item] of Object.entries(object)) {
23
+ if (typeof item !== 'string')
24
+ throw new Error(`${path}.${key} must be a string`);
25
+ }
26
+ return object;
27
+ }
28
+ function recordArray(value, path) {
29
+ if (!Array.isArray(value))
30
+ throw new Error(`${path} must be an array`);
31
+ return value.map((item, index) => record(item, `${path}.${index}`));
32
+ }
33
+ function optionalRecordArray(value, path) {
34
+ return value === undefined ? undefined : recordArray(value, path);
35
+ }
36
+ export const PackageJsonSchema = {
37
+ parse(value) {
38
+ const object = record(value, 'package.json');
39
+ for (const key of ['name', 'version', 'packageManager']) {
40
+ optionalString(object[key], `package.json.${key}`);
41
+ }
42
+ for (const key of ['scripts', 'dependencies', 'devDependencies']) {
43
+ if (object[key] !== undefined)
44
+ stringMap(object[key], `package.json.${key}`);
45
+ }
46
+ return object;
47
+ },
48
+ };
49
+ export const InstalledStateSchema = {
50
+ parse(value) {
51
+ const object = record(value, 'installed state');
52
+ if (object.schemaVersion !== 1 && object.schemaVersion !== 2) {
53
+ throw new Error('installed state schemaVersion must be 1 or 2');
54
+ }
55
+ if (object.requested !== undefined)
56
+ stringArray(object.requested, 'installed state.requested');
57
+ const installed = record(object.installed, 'installed state.installed');
58
+ for (const [id, item] of Object.entries(installed)) {
59
+ const entry = record(item, `installed state.installed.${id}`);
60
+ optionalString(entry.kind, `installed state.installed.${id}.kind`);
61
+ }
62
+ return object;
63
+ },
64
+ };
65
+ function validateOwnership(value, path) {
66
+ const ownership = record(value, path);
67
+ for (const [key, raw] of Object.entries(ownership)) {
68
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
69
+ continue;
70
+ const item = raw;
71
+ if (!['file', 'section', 'markdown'].includes(String(item.type)))
72
+ continue;
73
+ if (typeof item.path !== 'string')
74
+ throw new Error(`${path}.${key}.path must be a string`);
75
+ if (item.type !== 'file' && typeof item.heading !== 'string') {
76
+ throw new Error(`${path}.${key}.heading must be a string`);
77
+ }
78
+ if (typeof item.previousExists !== 'boolean') {
79
+ throw new Error(`${path}.${key}.previousExists must be a boolean`);
80
+ }
81
+ if (typeof item.previousValue !== 'string' || typeof item.appliedHash !== 'string') {
82
+ throw new Error(`${path}.${key} ownership values must be strings`);
83
+ }
84
+ }
85
+ }
86
+ export const ChecksStateSchema = {
87
+ parse(value) {
88
+ const object = record(value, 'checks state');
89
+ if (object.schemaVersion !== 1 && object.schemaVersion !== 2) {
90
+ throw new Error('checks state schemaVersion must be 1 or 2');
91
+ }
92
+ if (object.checkedAt !== undefined &&
93
+ object.checkedAt !== null &&
94
+ typeof object.checkedAt !== 'string') {
95
+ throw new Error('checks state.checkedAt must be a string or null');
96
+ }
97
+ const results = record(object.results, 'checks state.results');
98
+ for (const [id, result] of Object.entries(results))
99
+ record(result, `checks state.results.${id}`);
100
+ if (object.ownership !== undefined) {
101
+ const ownership = record(object.ownership, 'checks state.ownership');
102
+ for (const [id, records] of Object.entries(ownership)) {
103
+ validateOwnership(records, `checks state.ownership.${id}`);
104
+ }
105
+ }
106
+ return object;
107
+ },
108
+ };
109
+ export const RuleProfileSchema = {
110
+ parse(value) {
111
+ const object = record(value, 'rule profile');
112
+ if (object.schemaVersion !== 1)
113
+ throw new Error('rule profile schemaVersion must be 1');
114
+ if (object.projectType !== undefined &&
115
+ object.projectType !== null &&
116
+ typeof object.projectType !== 'string') {
117
+ throw new Error('rule profile.projectType must be a string or null');
118
+ }
119
+ for (const key of ['capabilities', 'include']) {
120
+ if (object[key] !== undefined)
121
+ stringArray(object[key], `rule profile.${key}`);
122
+ }
123
+ if (object.exclude !== undefined)
124
+ recordArray(object.exclude, 'rule profile.exclude');
125
+ return object;
126
+ },
127
+ };
128
+ function parseCatalogEntry(value, path) {
129
+ const object = record(value, path);
130
+ if (typeof object.id !== 'string' || !object.id)
131
+ throw new Error(`${path}.id is required`);
132
+ if (typeof object.version !== 'string' || !object.version)
133
+ throw new Error(`${path}.version is required`);
134
+ if (object.kind !== undefined && object.kind !== 'rule' && object.kind !== 'module') {
135
+ throw new Error(`${path}.kind must be rule or module`);
136
+ }
137
+ optionalString(object.contentHash, `${path}.contentHash`);
138
+ optionalString(object.revision, `${path}.revision`);
139
+ return object;
140
+ }
141
+ export const CatalogSchema = {
142
+ parse(value) {
143
+ const object = record(value, 'catalog');
144
+ if (!Array.isArray(object.entries))
145
+ throw new Error('catalog.entries must be an array');
146
+ object.entries.forEach((entry, index) => parseCatalogEntry(entry, `catalog.entries.${index}`));
147
+ if (object.package !== undefined)
148
+ record(object.package, 'catalog.package');
149
+ if (object.predefinedPackages !== undefined) {
150
+ recordArray(object.predefinedPackages, 'catalog.predefinedPackages');
151
+ }
152
+ return object;
153
+ },
154
+ };
155
+ export const CanonicalManifestSchema = {
156
+ parse(value) {
157
+ const object = record(value, 'canonical manifest');
158
+ if (typeof object.id !== 'string' || !object.id.trim()) {
159
+ throw new Error('canonical manifest.id is required');
160
+ }
161
+ optionalString(object.version, 'canonical manifest.version');
162
+ optionalString(object.kind, 'canonical manifest.kind');
163
+ for (const key of ['operations', 'copies', 'markdownSections']) {
164
+ optionalRecordArray(object[key], `canonical manifest.${key}`);
165
+ }
166
+ if (object.checker !== undefined)
167
+ record(object.checker, 'canonical manifest.checker');
168
+ if (object.check !== undefined)
169
+ record(object.check, 'canonical manifest.check');
170
+ return object;
171
+ },
172
+ };
173
+ export function parseWithSchema(schema, value, label) {
174
+ try {
175
+ return schema.parse(value);
176
+ }
177
+ catch (error) {
178
+ throw new Error(`Invalid ${label}: ${error instanceof Error ? error.message : String(error)}`, {
179
+ cause: error,
180
+ });
181
+ }
182
+ }
183
+ export function parseJsonWithSchema(schema, text, label) {
184
+ let value;
185
+ try {
186
+ value = JSON.parse(text);
187
+ }
188
+ catch (error) {
189
+ throw new Error(`Invalid ${label}: ${error instanceof Error ? error.message : String(error)}`, {
190
+ cause: error,
191
+ });
192
+ }
193
+ return parseWithSchema(schema, value, label);
194
+ }
@@ -0,0 +1,16 @@
1
+ export type SlackTransport = typeof fetch;
2
+ type Io = {
3
+ stdout: {
4
+ write: (s: string) => void;
5
+ };
6
+ stderr: {
7
+ write: (s: string) => void;
8
+ };
9
+ };
10
+ export declare function sendSlackFiles(args: string[], io?: Io, options?: {
11
+ cwd?: string;
12
+ home?: string;
13
+ env?: NodeJS.ProcessEnv;
14
+ transport?: SlackTransport;
15
+ }): Promise<number>;
16
+ export {};