@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.
- package/README.md +26 -24
- package/dist/npm/canonical-project.d.ts +12 -1
- package/dist/npm/canonical-project.js +10 -4
- package/dist/npm/canonical-source.d.ts +14 -2
- package/dist/npm/canonical-source.js +46 -14
- package/dist/npm/catalog-snapshot.d.ts +32 -26
- package/dist/npm/catalog-snapshot.js +11 -4
- package/dist/npm/cli.js +5 -2
- package/dist/npm/commands.d.ts +6 -0
- package/dist/npm/commands.js +33 -8
- package/dist/npm/flow.js +52 -18
- package/dist/npm/git-catalog.d.ts +33 -32
- package/dist/npm/git-catalog.js +49 -17
- package/dist/npm/index.d.ts +0 -1
- package/dist/npm/index.js +13 -3
- package/dist/npm/installer-primitives.d.ts +3 -3
- package/dist/npm/predefined-packages/expo.js +5 -1
- package/dist/npm/predefined-packages/index.d.ts +1 -0
- package/dist/npm/predefined-packages/index.js +44 -3
- package/dist/npm/predefined-packages/install.js +3 -2
- package/dist/npm/predefined-packages/supabase.js +271 -20
- package/dist/npm/predefined-packages/types.d.ts +7 -0
- package/dist/npm/predefined-packages/vite.js +5 -1
- package/dist/npm/project-check.d.ts +8 -0
- package/dist/npm/project-check.js +38 -7
- package/dist/npm/project-context.d.ts +14 -4
- package/dist/npm/project-context.js +32 -18
- package/dist/npm/project-rules.d.ts +4 -1
- package/dist/npm/project-rules.js +15 -6
- package/dist/npm/project-runtime.d.ts +4 -1
- package/dist/npm/project-runtime.js +19 -5
- package/dist/npm/project-status.js +17 -3
- package/dist/npm/project-sync.js +13 -5
- package/dist/npm/remote-installer.d.ts +35 -4
- package/dist/npm/remote-installer.js +75 -36
- package/dist/npm/rule-id-migrations.d.ts +6 -0
- package/dist/npm/rule-id-migrations.js +19 -0
- package/dist/npm/schemas.d.ts +64 -0
- package/dist/npm/schemas.js +194 -0
- package/dist/npm/slack.d.ts +16 -0
- package/dist/npm/slack.js +131 -0
- package/dist/npm/state.js +71 -22
- package/dist/npm/supabase-local.d.ts +2 -0
- package/dist/npm/supabase-local.js +62 -0
- package/package.json +10 -7
- package/dist/npm/fuzz.d.ts +0 -138
- package/dist/npm/fuzz.js +0 -327
|
@@ -14,14 +14,28 @@ export async function loadCanonicalProjectContext(projectRoot, source, options =
|
|
|
14
14
|
let canonicalCheckRoot = null;
|
|
15
15
|
let checkerRuntimeRoot = null;
|
|
16
16
|
if (options.withCheckers && canonicalCheck) {
|
|
17
|
-
if (!options.offline ||
|
|
18
|
-
|
|
17
|
+
if (!options.offline ||
|
|
18
|
+
(await source.hasModule(canonicalCheck.id, canonicalCheck.version, canonicalCheck.contentHash))) {
|
|
19
|
+
canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version, {
|
|
20
|
+
contentHash: canonicalCheck.contentHash,
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
if (options.withCheckers && checkerRuntime) {
|
|
22
|
-
if (!options.offline ||
|
|
23
|
-
|
|
25
|
+
if (!options.offline ||
|
|
26
|
+
(await source.hasModule(checkerRuntime.id, checkerRuntime.version, checkerRuntime.contentHash))) {
|
|
27
|
+
checkerRuntimeRoot = await source.module(checkerRuntime.id, checkerRuntime.version, {
|
|
28
|
+
contentHash: checkerRuntime.contentHash,
|
|
29
|
+
});
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
catalog,
|
|
34
|
+
stack,
|
|
35
|
+
projectType,
|
|
36
|
+
profile,
|
|
37
|
+
applicable,
|
|
38
|
+
canonicalCheckRoot,
|
|
39
|
+
checkerRuntimeRoot,
|
|
40
|
+
};
|
|
27
41
|
}
|
|
@@ -10,14 +10,28 @@ export async function canonicalStatus(projectRoot, source, options = {}) {
|
|
|
10
10
|
const rows = applicable.map((entry) => {
|
|
11
11
|
const found = installed[entry.id];
|
|
12
12
|
const state = !found ? 'missing' : found.version === entry.version ? 'current' : 'outdated';
|
|
13
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
id: entry.id,
|
|
15
|
+
canonicalVersion: entry.version,
|
|
16
|
+
installedVersion: found?.version ?? null,
|
|
17
|
+
state,
|
|
18
|
+
};
|
|
14
19
|
});
|
|
15
20
|
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
16
21
|
const packages = Object.entries(installed)
|
|
17
22
|
.filter(([, value]) => value?.kind === 'package')
|
|
18
|
-
.map(([id, value]) => ({
|
|
23
|
+
.map(([id, value]) => ({
|
|
24
|
+
id,
|
|
25
|
+
recipeVersion: value.recipeVersion ?? null,
|
|
26
|
+
detectedVersion: value.detectedVersion ?? value.version ?? null,
|
|
27
|
+
role: value.role ?? null,
|
|
28
|
+
source: value.source ?? null,
|
|
29
|
+
resolvedVariant: value.resolvedVariant ?? null,
|
|
30
|
+
}))
|
|
19
31
|
.sort((a, b) => a.id.localeCompare(b.id));
|
|
20
|
-
const installedNonApplicable = Object.keys(installed)
|
|
32
|
+
const installedNonApplicable = Object.keys(installed)
|
|
33
|
+
.filter((id) => !applicableIds.has(id) && installed[id]?.kind !== 'package')
|
|
34
|
+
.sort();
|
|
21
35
|
return {
|
|
22
36
|
stack,
|
|
23
37
|
projectType,
|
package/dist/npm/project-sync.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { access, readdir, rm, rmdir } from 'node:fs/promises';
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
|
-
import { installRule, syncRule } from
|
|
3
|
+
import { installRule, syncRule } from "./remote-installer.js";
|
|
4
4
|
import { assertPredefinedPackageState } from "./predefined-packages/health.js";
|
|
5
5
|
import { loadCanonicalProjectContext, prepareCanonicalManifest } from "./project-runtime.js";
|
|
6
|
-
import { readChecksState, readInstalledState, writeChecksState, writeInstalledState } from "./state.js";
|
|
6
|
+
import { readChecksState, readInstalledState, writeChecksState, writeInstalledState, } from "./state.js";
|
|
7
7
|
async function fileExists(path) {
|
|
8
8
|
try {
|
|
9
9
|
await access(path);
|
|
@@ -110,16 +110,24 @@ export async function canonicalSync(projectRoot, source) {
|
|
|
110
110
|
}
|
|
111
111
|
const installed = current.installed[entry.id];
|
|
112
112
|
if (!installed) {
|
|
113
|
-
await installRule({
|
|
113
|
+
await installRule({
|
|
114
|
+
projectRoot,
|
|
115
|
+
payloadRoot: source.cachedModulePath(entry.id, entry.version),
|
|
116
|
+
manifest: prepared.manifest,
|
|
117
|
+
});
|
|
114
118
|
changed.push({ id: entry.id, action: 'installed', version: entry.version });
|
|
115
119
|
}
|
|
116
120
|
else {
|
|
117
121
|
const requiresContentSync = installed.version !== entry.version ||
|
|
118
122
|
installed.contentHash !== entry.contentHash ||
|
|
119
123
|
(prepared.checkerPath && installed.check?.command?.[0] !== 'specdest-cache') ||
|
|
120
|
-
await missingProjectScaffold(projectRoot, prepared.manifest.copies);
|
|
124
|
+
(await missingProjectScaffold(projectRoot, prepared.manifest.copies));
|
|
121
125
|
if (requiresContentSync) {
|
|
122
|
-
await syncRule({
|
|
126
|
+
await syncRule({
|
|
127
|
+
projectRoot,
|
|
128
|
+
payloadRoot: source.cachedModulePath(entry.id, entry.version),
|
|
129
|
+
manifest: prepared.manifest,
|
|
130
|
+
});
|
|
123
131
|
changed.push({ id: entry.id, action: 'updated', version: entry.version });
|
|
124
132
|
}
|
|
125
133
|
else if (installed.revision !== entry.revision) {
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type CanonicalManifest } from './schemas.ts';
|
|
2
|
+
type ManagedFileOperation = {
|
|
3
|
+
type: 'copy_file';
|
|
4
|
+
path: string;
|
|
5
|
+
source: string;
|
|
6
|
+
};
|
|
7
|
+
type ScaffoldOperation = {
|
|
8
|
+
type: 'scaffold_file';
|
|
9
|
+
path: string;
|
|
10
|
+
source: string;
|
|
11
|
+
};
|
|
12
|
+
type ManagedSectionOperation = {
|
|
13
|
+
type: 'managed_section';
|
|
14
|
+
path: string;
|
|
15
|
+
heading: string;
|
|
16
|
+
content?: unknown;
|
|
17
|
+
};
|
|
18
|
+
type Operation = ManagedFileOperation | ScaffoldOperation | ManagedSectionOperation;
|
|
19
|
+
type RemoteManifest = CanonicalManifest & {
|
|
20
|
+
operations: Operation[];
|
|
21
|
+
kind?: string;
|
|
22
|
+
revision?: string;
|
|
23
|
+
contentHash?: string;
|
|
24
|
+
check?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
type ReconcileOptions = {
|
|
27
|
+
projectRoot: string;
|
|
28
|
+
payloadRoot: string;
|
|
29
|
+
manifest: unknown;
|
|
30
|
+
};
|
|
31
|
+
export declare function validateRemoteManifest(input: unknown): RemoteManifest;
|
|
32
|
+
export declare function installRule(options: ReconcileOptions): Promise<any>;
|
|
33
|
+
export declare function syncRule(options: ReconcileOptions): Promise<any>;
|
|
34
|
+
export declare function removeRule(options: ReconcileOptions): Promise<any>;
|
|
35
|
+
export {};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { mkdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, isAbsolute, resolve, sep } from 'node:path';
|
|
4
|
-
import { removeMarkdownSection, resolveProjectPath, upsertMarkdownSection } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
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');
|
|
9
16
|
function payloadPath(payloadRoot, relativePath) {
|
|
10
17
|
if (!relativePath || isAbsolute(relativePath))
|
|
11
18
|
throw new Error(`Source must be payload-relative: ${relativePath}`);
|
|
@@ -35,44 +42,61 @@ const checkerSkillIds = new Map([
|
|
|
35
42
|
function checkerSkillId(implementation) {
|
|
36
43
|
return checkerSkillIds.get(implementation) ?? implementation;
|
|
37
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
|
+
}
|
|
38
64
|
function normalizeManifest(manifest) {
|
|
39
|
-
const operations =
|
|
40
|
-
const checkerImplementation = String(manifest
|
|
41
|
-
const check = manifest
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 ?? []) {
|
|
45
72
|
if (copy.type === 'directory' || copy.directory === true) {
|
|
46
|
-
throw new Error(`Directory copies are not supported: ${copy.source}`);
|
|
73
|
+
throw new Error(`Directory copies are not supported: ${String(copy.source ?? '')}`);
|
|
47
74
|
}
|
|
48
75
|
operations.push({
|
|
49
76
|
type: copy.mode === 'scaffold' || copy.mode === 'create-only' ? 'scaffold_file' : 'copy_file',
|
|
50
|
-
source: copy.source,
|
|
51
|
-
path: copy.target ?? copy.path,
|
|
77
|
+
source: String(copy.source ?? ''),
|
|
78
|
+
path: String(copy.target ?? copy.path ?? ''),
|
|
52
79
|
});
|
|
53
80
|
}
|
|
54
|
-
for (const section of manifest
|
|
81
|
+
for (const section of manifest.markdownSections ?? []) {
|
|
55
82
|
operations.push({
|
|
56
83
|
type: 'managed_section',
|
|
57
|
-
path: section.path,
|
|
58
|
-
heading: section.heading,
|
|
84
|
+
path: String(section.path ?? ''),
|
|
85
|
+
heading: String(section.heading ?? ''),
|
|
59
86
|
content: section.body ?? section.content ?? '',
|
|
60
87
|
});
|
|
61
88
|
}
|
|
62
89
|
return { ...manifest, operations, ...(check ? { check } : {}) };
|
|
63
90
|
}
|
|
64
91
|
export function validateRemoteManifest(input) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const manifest = normalizeManifest(input);
|
|
92
|
+
const parsed = parseWithSchema(CanonicalManifestSchema, input, 'canonical manifest');
|
|
93
|
+
const manifest = normalizeManifest(parsed);
|
|
68
94
|
for (const operation of manifest.operations) {
|
|
69
|
-
if (!SUPPORTED_OPERATIONS.has(operation?.type))
|
|
70
|
-
throw new Error(`Unsupported manifest operation: ${operation?.type}`);
|
|
71
95
|
resolveProjectPath('/__specdest_project__', operation.path);
|
|
72
|
-
if (operation.type !== 'managed_section' && !
|
|
96
|
+
if (operation.type !== 'managed_section' && !operation.source.trim()) {
|
|
73
97
|
throw new Error(`Manifest operation source is required: ${operation.type}`);
|
|
74
98
|
}
|
|
75
|
-
if (operation.type === 'managed_section' && !
|
|
99
|
+
if (operation.type === 'managed_section' && !operation.heading.trim()) {
|
|
76
100
|
throw new Error('Managed section heading is required');
|
|
77
101
|
}
|
|
78
102
|
}
|
|
@@ -127,7 +151,9 @@ function legacyMarkdownSection(text, heading) {
|
|
|
127
151
|
}
|
|
128
152
|
offset += line.length;
|
|
129
153
|
}
|
|
130
|
-
return start < 0
|
|
154
|
+
return start < 0
|
|
155
|
+
? { exists: false, value: '' }
|
|
156
|
+
: { exists: true, value: text.slice(start, end).trimEnd() };
|
|
131
157
|
}
|
|
132
158
|
async function migrateLegacyMarkdownOwnership(projectRoot, prior) {
|
|
133
159
|
for (const [key, record] of Object.entries(prior)) {
|
|
@@ -261,9 +287,15 @@ async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManife
|
|
|
261
287
|
throw new Error(`${manifest.id} is already installed`);
|
|
262
288
|
if (kind !== 'install' && !installed)
|
|
263
289
|
throw new Error(`${manifest.id} is not installed`);
|
|
264
|
-
const prior = clone(runtimeState.ownership[manifest.id] ?? {});
|
|
290
|
+
const prior = clone((runtimeState.ownership[manifest.id] ?? {}));
|
|
265
291
|
await migrateLegacyMarkdownOwnership(projectRoot, prior);
|
|
266
|
-
const context = {
|
|
292
|
+
const context = {
|
|
293
|
+
projectRoot,
|
|
294
|
+
payloadRoot,
|
|
295
|
+
prior,
|
|
296
|
+
next: clone(prior),
|
|
297
|
+
touched: new Set(),
|
|
298
|
+
};
|
|
267
299
|
if (kind === 'remove') {
|
|
268
300
|
for (const record of Object.values(prior))
|
|
269
301
|
await restoreOwnership(projectRoot, record);
|
|
@@ -286,12 +318,13 @@ async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManife
|
|
|
286
318
|
delete runtimeState.results[manifest.id];
|
|
287
319
|
}
|
|
288
320
|
else {
|
|
289
|
-
const contentHash = String(manifest.contentHash ??
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}));
|
|
295
328
|
const revision = String(manifest.revision ?? contentHash);
|
|
296
329
|
installedState.installed[manifest.id] = {
|
|
297
330
|
kind: manifest.kind ?? 'rule',
|
|
@@ -307,6 +340,12 @@ async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManife
|
|
|
307
340
|
await writeChecksState(projectRoot, { ...runtimeState, schemaVersion: 2 });
|
|
308
341
|
return installedState.installed[manifest.id] ?? null;
|
|
309
342
|
}
|
|
310
|
-
export async function installRule(options) {
|
|
311
|
-
|
|
312
|
-
|
|
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 {};
|