@specdest/devkit 0.4.8 → 0.4.10
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/client-only-boundary.d.ts +1 -0
- package/dist/npm/client-only-boundary.js +29 -0
- 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 +297 -26
- 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 +52 -7
- package/dist/npm/project-context.d.ts +14 -4
- package/dist/npm/project-context.js +37 -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 +9 -7
- package/dist/npm/fuzz.d.ts +0 -138
- package/dist/npm/fuzz.js +0 -327
package/dist/npm/flow.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join, normalize } from 'node:path';
|
|
5
|
+
import { PackageJsonSchema, parseWithSchema } from "./schemas.js";
|
|
5
6
|
export const FLOW_WORKFLOWS = Object.freeze({
|
|
6
7
|
feature: Object.freeze(['plan', 'implement', 'verify', 'complete']),
|
|
7
8
|
fix: Object.freeze(['plan', 'implement', 'verify', 'complete']),
|
|
@@ -23,8 +24,12 @@ function execute(command, args, cwd) {
|
|
|
23
24
|
let stderr = '';
|
|
24
25
|
child.stdout.setEncoding('utf8');
|
|
25
26
|
child.stderr.setEncoding('utf8');
|
|
26
|
-
child.stdout.on('data', (chunk) => {
|
|
27
|
-
|
|
27
|
+
child.stdout.on('data', (chunk) => {
|
|
28
|
+
stdout += chunk;
|
|
29
|
+
});
|
|
30
|
+
child.stderr.on('data', (chunk) => {
|
|
31
|
+
stderr += chunk;
|
|
32
|
+
});
|
|
28
33
|
child.on('error', reject);
|
|
29
34
|
child.on('close', (code) => resolve({
|
|
30
35
|
exitCode: code ?? 1,
|
|
@@ -57,17 +62,21 @@ function validateTaskId(value) {
|
|
|
57
62
|
return value;
|
|
58
63
|
}
|
|
59
64
|
function slugify(value) {
|
|
60
|
-
return value
|
|
65
|
+
return (value
|
|
66
|
+
.toLowerCase()
|
|
61
67
|
.replace(/[^a-z0-9]+/gu, '-')
|
|
62
68
|
.replace(/^-|-$/gu, '')
|
|
63
69
|
.slice(0, 64)
|
|
64
|
-
.replace(/-$/u, '') || 'task';
|
|
70
|
+
.replace(/-$/u, '') || 'task');
|
|
65
71
|
}
|
|
66
72
|
function validateContextFile(value) {
|
|
67
73
|
if (!value)
|
|
68
74
|
return null;
|
|
69
75
|
const path = normalize(value).replaceAll('\\', '/');
|
|
70
|
-
if (path === '..' ||
|
|
76
|
+
if (path === '..' ||
|
|
77
|
+
path.startsWith('../') ||
|
|
78
|
+
path.startsWith('/') ||
|
|
79
|
+
!path.startsWith('flow-notes/')) {
|
|
71
80
|
throw new Error('Context file must be relative to .spd/flow-notes/.');
|
|
72
81
|
}
|
|
73
82
|
return path;
|
|
@@ -123,7 +132,9 @@ async function writeFlowState(projectRoot, state) {
|
|
|
123
132
|
async function ensureFlowIgnored(projectRoot) {
|
|
124
133
|
const gitPath = await execute('git', ['rev-parse', '--git-path', 'info/exclude'], projectRoot);
|
|
125
134
|
const excludePath = gitPath.exitCode === 0
|
|
126
|
-
?
|
|
135
|
+
? gitPath.stdout.trim().startsWith('/')
|
|
136
|
+
? gitPath.stdout.trim()
|
|
137
|
+
: join(projectRoot, gitPath.stdout.trim())
|
|
127
138
|
: join(projectRoot, '.git', 'info', 'exclude');
|
|
128
139
|
await mkdir(dirname(excludePath), { recursive: true });
|
|
129
140
|
let content = '';
|
|
@@ -134,10 +145,13 @@ async function ensureFlowIgnored(projectRoot) {
|
|
|
134
145
|
if (error.code !== 'ENOENT')
|
|
135
146
|
throw error;
|
|
136
147
|
}
|
|
137
|
-
|
|
148
|
+
const required = ['/.spd/flow.json', '/.spd/flow-notes/'];
|
|
149
|
+
const lines = new Set(content.split(/\r?\n/u));
|
|
150
|
+
const missing = required.filter((entry) => !lines.has(entry));
|
|
151
|
+
if (!missing.length)
|
|
138
152
|
return;
|
|
139
153
|
const separator = content && !content.endsWith('\n') ? '\n' : '';
|
|
140
|
-
await writeFile(excludePath, `${content}${separator}
|
|
154
|
+
await writeFile(excludePath, `${content}${separator}${missing.join('\n')}\n`, 'utf8');
|
|
141
155
|
}
|
|
142
156
|
function parseOptions(args, allowed) {
|
|
143
157
|
const result = {};
|
|
@@ -152,13 +166,17 @@ function parseOptions(args, allowed) {
|
|
|
152
166
|
const value = args[++index];
|
|
153
167
|
if (!value || value.startsWith('--'))
|
|
154
168
|
throw new Error(`Missing value for ${argument}`);
|
|
155
|
-
const key = argument
|
|
169
|
+
const key = argument
|
|
170
|
+
.slice(2)
|
|
171
|
+
.replace(/-([a-z])/gu, (_, letter) => letter.toUpperCase());
|
|
156
172
|
result[key] = value;
|
|
157
173
|
}
|
|
158
174
|
return result;
|
|
159
175
|
}
|
|
160
176
|
function selectTask(state, requestedTaskId) {
|
|
161
|
-
const taskId = requestedTaskId ||
|
|
177
|
+
const taskId = requestedTaskId ||
|
|
178
|
+
state.selectedTaskId ||
|
|
179
|
+
(state.tasks.length === 1 ? state.tasks[0]?.id : null);
|
|
162
180
|
if (!taskId)
|
|
163
181
|
throw new Error('Multiple tasks exist; select one with --task <id>.');
|
|
164
182
|
const task = state.tasks.find((candidate) => candidate.id === taskId);
|
|
@@ -243,7 +261,8 @@ async function projectPackageManager(projectRoot, packageJson) {
|
|
|
243
261
|
return 'pnpm';
|
|
244
262
|
if (await exists(join(projectRoot, 'yarn.lock')))
|
|
245
263
|
return 'yarn';
|
|
246
|
-
if (await exists(join(projectRoot, 'bun.lockb')) ||
|
|
264
|
+
if ((await exists(join(projectRoot, 'bun.lockb'))) ||
|
|
265
|
+
(await exists(join(projectRoot, 'bun.lock'))))
|
|
247
266
|
return 'bun';
|
|
248
267
|
return 'npm';
|
|
249
268
|
}
|
|
@@ -253,16 +272,26 @@ export async function runConfiguredVerification(projectRoot) {
|
|
|
253
272
|
return await execute('sh', [prePush], projectRoot);
|
|
254
273
|
let packageJson;
|
|
255
274
|
try {
|
|
256
|
-
packageJson = JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8'));
|
|
275
|
+
packageJson = parseWithSchema(PackageJsonSchema, JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8')), `package.json at ${projectRoot}`);
|
|
257
276
|
}
|
|
258
277
|
catch (error) {
|
|
259
278
|
if (error.code === 'ENOENT') {
|
|
260
|
-
return {
|
|
279
|
+
return {
|
|
280
|
+
exitCode: 1,
|
|
281
|
+
stdout: '',
|
|
282
|
+
stderr: 'No .husky/pre-push or package.json verification gate found.\n',
|
|
283
|
+
summary: 'missing verification gate',
|
|
284
|
+
};
|
|
261
285
|
}
|
|
262
286
|
throw error;
|
|
263
287
|
}
|
|
264
288
|
if (!packageJson.scripts?.check) {
|
|
265
|
-
return {
|
|
289
|
+
return {
|
|
290
|
+
exitCode: 1,
|
|
291
|
+
stdout: '',
|
|
292
|
+
stderr: 'No .husky/pre-push or package.json check script found.\n',
|
|
293
|
+
summary: 'missing verification gate',
|
|
294
|
+
};
|
|
266
295
|
}
|
|
267
296
|
const manager = await projectPackageManager(projectRoot, packageJson);
|
|
268
297
|
const commandArgs = manager === 'yarn' ? ['check'] : ['run', 'check'];
|
|
@@ -280,7 +309,8 @@ export async function repositoryFingerprint(projectRoot) {
|
|
|
280
309
|
const hash = createHash('sha256');
|
|
281
310
|
hash.update(head.stdout);
|
|
282
311
|
hash.update(diff.stdout);
|
|
283
|
-
const entries = status.stdout
|
|
312
|
+
const entries = status.stdout
|
|
313
|
+
.split('\0')
|
|
284
314
|
.filter(Boolean)
|
|
285
315
|
.filter((entry) => !entry.slice(3).startsWith('.spd/'));
|
|
286
316
|
hash.update(entries.join('\0'));
|
|
@@ -324,7 +354,10 @@ async function verifyFlow(projectRoot, args, io, dependencies) {
|
|
|
324
354
|
io.stderr.write(`Verification failed for ${task.id} via ${result.summary}.\n`);
|
|
325
355
|
return 1;
|
|
326
356
|
}
|
|
327
|
-
task.verification = {
|
|
357
|
+
task.verification = {
|
|
358
|
+
status: 'passed',
|
|
359
|
+
fingerprint: await dependencies.fingerprint(projectRoot),
|
|
360
|
+
};
|
|
328
361
|
await writeFlowState(projectRoot, state);
|
|
329
362
|
io.stdout.write(`Verification passed for ${task.id} via ${result.summary}.\n`);
|
|
330
363
|
return 0;
|
|
@@ -335,7 +368,8 @@ async function cleanupTask(projectRoot, state, task) {
|
|
|
335
368
|
state.tasks = state.tasks.filter((candidate) => candidate.id !== task.id);
|
|
336
369
|
state.selectedTaskId = state.tasks[0]?.id ?? null;
|
|
337
370
|
if (!state.tasks.length) {
|
|
338
|
-
await rm(join(projectRoot,
|
|
371
|
+
await rm(join(projectRoot, FLOW_STATE_PATH), { force: true });
|
|
372
|
+
await rm(join(projectRoot, '.spd', 'flow-notes'), { recursive: true, force: true });
|
|
339
373
|
return;
|
|
340
374
|
}
|
|
341
375
|
await writeFlowState(projectRoot, state);
|
|
@@ -354,7 +388,7 @@ async function completeFlow(projectRoot, args, io, dependencies) {
|
|
|
354
388
|
io.stderr.write(`Cannot complete ${task.id}: verification has not passed.\n`);
|
|
355
389
|
return 1;
|
|
356
390
|
}
|
|
357
|
-
if (await dependencies.fingerprint(projectRoot) !== task.verification.fingerprint) {
|
|
391
|
+
if ((await dependencies.fingerprint(projectRoot)) !== task.verification.fingerprint) {
|
|
358
392
|
io.stderr.write(`Cannot complete ${task.id}: verification is stale; rerun flow verify.\n`);
|
|
359
393
|
return 1;
|
|
360
394
|
}
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type ProjectProfiles = Record<string, {
|
|
2
|
+
ruleIds: string[];
|
|
3
|
+
}>;
|
|
4
|
+
type GitCatalogEntry = {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: 'rule' | 'module';
|
|
7
|
+
version: string;
|
|
8
|
+
name: string;
|
|
9
|
+
content: string;
|
|
10
|
+
order: number;
|
|
11
|
+
source: string;
|
|
12
|
+
revision: string;
|
|
13
|
+
contentHash: string;
|
|
14
|
+
summary?: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
scope?: string;
|
|
17
|
+
labels?: string[];
|
|
18
|
+
enforcement?: string;
|
|
19
|
+
legacyInstalledIds?: string[];
|
|
20
|
+
applicableStacks?: string[];
|
|
21
|
+
requiredPackages?: string[];
|
|
22
|
+
requiredCapabilities?: string[];
|
|
23
|
+
composedOf?: string[];
|
|
24
|
+
notApplicableRuleIds?: string[];
|
|
25
|
+
projectProfiles?: ProjectProfiles;
|
|
26
|
+
ai?: unknown;
|
|
27
|
+
verification?: unknown;
|
|
28
|
+
};
|
|
29
|
+
export declare function buildGitCatalog({ modulesRoot, repositoryRevision, }: {
|
|
30
|
+
modulesRoot: string;
|
|
31
|
+
repositoryRevision?: string;
|
|
4
32
|
}): Promise<{
|
|
5
33
|
schemaVersion: number;
|
|
6
34
|
package: {
|
|
7
35
|
name: string;
|
|
8
36
|
version: string;
|
|
9
37
|
};
|
|
10
|
-
entries:
|
|
11
|
-
projectProfiles?: {
|
|
12
|
-
[k: string]: {
|
|
13
|
-
ruleIds: any[];
|
|
14
|
-
};
|
|
15
|
-
} | undefined;
|
|
16
|
-
notApplicableRuleIds?: any[] | undefined;
|
|
17
|
-
composedOf?: string[] | undefined;
|
|
18
|
-
verification?: any;
|
|
19
|
-
ai?: any;
|
|
20
|
-
requiredCapabilities?: string[] | undefined;
|
|
21
|
-
requiredPackages?: string[] | undefined;
|
|
22
|
-
applicableStacks?: any[] | undefined;
|
|
23
|
-
enforcement?: string | undefined;
|
|
24
|
-
legacyInstalledIds?: any[] | undefined;
|
|
25
|
-
order: number;
|
|
26
|
-
source: string;
|
|
27
|
-
revision: string;
|
|
28
|
-
contentHash: string;
|
|
29
|
-
labels?: string[] | undefined;
|
|
30
|
-
scope?: string | undefined;
|
|
31
|
-
category?: string | undefined;
|
|
32
|
-
summary?: any;
|
|
33
|
-
id: any;
|
|
34
|
-
kind: any;
|
|
35
|
-
version: string;
|
|
36
|
-
name: any;
|
|
37
|
-
content: any;
|
|
38
|
-
}[];
|
|
38
|
+
entries: GitCatalogEntry[];
|
|
39
39
|
}>;
|
|
40
|
+
export {};
|
package/dist/npm/git-catalog.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readdir, readFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { CanonicalManifestSchema, parseWithSchema } from "./schemas.js";
|
|
4
5
|
const sha256 = (value) => createHash('sha256').update(value).digest('hex');
|
|
5
6
|
const legacyImplementationFamilies = new Map([
|
|
6
7
|
['abac-permissions-supabase', ['abac-permissions-convex', 'abac-permissions-supabase']],
|
|
7
|
-
[
|
|
8
|
+
[
|
|
9
|
+
'layers-and-contracts',
|
|
10
|
+
['layers-and-contracts', 'layers-and-contracts-convex', 'layers-and-contracts-supabase'],
|
|
11
|
+
],
|
|
8
12
|
['unit-test-rules', ['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase']],
|
|
9
|
-
[
|
|
13
|
+
[
|
|
14
|
+
'unit-test-rules-supabase',
|
|
15
|
+
['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase'],
|
|
16
|
+
],
|
|
10
17
|
]);
|
|
11
18
|
function legacyImplementationIds(manifest) {
|
|
12
19
|
const implementation = manifest.checker?.implementation;
|
|
@@ -34,10 +41,12 @@ function title(content, id) {
|
|
|
34
41
|
function summary(content, fallback) {
|
|
35
42
|
const normalized = String(content ?? '').replace(/\r\n?/gu, '\n');
|
|
36
43
|
const intent = normalized.match(/(?:^|\n)## Intent\s*\n+([^#][\s\S]*?)(?=\n## |$)/u)?.[1]?.trim();
|
|
37
|
-
const source = intent ||
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const source = intent ||
|
|
45
|
+
normalized
|
|
46
|
+
.split('\n')
|
|
47
|
+
.map((line) => line.trim())
|
|
48
|
+
.find((line) => line && !line.startsWith('#')) ||
|
|
49
|
+
fallback;
|
|
41
50
|
return source
|
|
42
51
|
.replace(/^\*\*Rule:\*\*\s*/u, '')
|
|
43
52
|
.replace(/\s+/gu, ' ')
|
|
@@ -68,7 +77,9 @@ function projectProfiles(manifest) {
|
|
|
68
77
|
if (typeof manifest.projectProfiles !== 'object' || Array.isArray(manifest.projectProfiles)) {
|
|
69
78
|
throw new Error(`Invalid projectProfiles: ${manifest.id}`);
|
|
70
79
|
}
|
|
71
|
-
return Object.fromEntries(Object.entries(manifest.projectProfiles)
|
|
80
|
+
return Object.fromEntries(Object.entries(manifest.projectProfiles)
|
|
81
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
82
|
+
.map(([name, definition]) => {
|
|
72
83
|
if (!definition || !Array.isArray(definition.ruleIds) || definition.ruleIds.length === 0) {
|
|
73
84
|
throw new Error(`Invalid project profile: ${manifest.id}:${name}`);
|
|
74
85
|
}
|
|
@@ -78,7 +89,12 @@ function projectProfiles(manifest) {
|
|
|
78
89
|
function stringList(value) {
|
|
79
90
|
if (!Array.isArray(value) || value.length === 0)
|
|
80
91
|
return undefined;
|
|
81
|
-
return [
|
|
92
|
+
return [
|
|
93
|
+
...new Set(value
|
|
94
|
+
.map(String)
|
|
95
|
+
.map((item) => item.trim())
|
|
96
|
+
.filter(Boolean)),
|
|
97
|
+
].sort();
|
|
82
98
|
}
|
|
83
99
|
function applicableStacks(manifest) {
|
|
84
100
|
if (!Array.isArray(manifest.applicableStacks) || manifest.applicableStacks.length === 0)
|
|
@@ -95,7 +111,7 @@ function validateRuleApplicability(manifest) {
|
|
|
95
111
|
throw new Error(`Stack-specific rule requires applicableStacks or requiredPackages: ${manifest.id}`);
|
|
96
112
|
}
|
|
97
113
|
}
|
|
98
|
-
export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'working-tree' }) {
|
|
114
|
+
export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'working-tree', }) {
|
|
99
115
|
const directories = (await readdir(modulesRoot, { withFileTypes: true }))
|
|
100
116
|
.filter((entry) => entry.isDirectory())
|
|
101
117
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -106,7 +122,7 @@ export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'worki
|
|
|
106
122
|
const manifestFile = files.find((file) => file.path === 'manifest.json');
|
|
107
123
|
if (!manifestFile)
|
|
108
124
|
throw new Error(`Missing manifest.json: ${directory.name}`);
|
|
109
|
-
const manifest = JSON.parse(manifestFile.content);
|
|
125
|
+
const manifest = parseWithSchema(CanonicalManifestSchema, JSON.parse(manifestFile.content), `canonical manifest ${directory.name}`);
|
|
110
126
|
if (manifest.id !== directory.name)
|
|
111
127
|
throw new Error(`Module id/path mismatch: ${directory.name}`);
|
|
112
128
|
modules.push({ files, manifest, ownContentHash: sha256(JSON.stringify(files)) });
|
|
@@ -130,19 +146,29 @@ export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'worki
|
|
|
130
146
|
...(kind === 'rule' ? { summary: summary(guidance, manifest.name ?? manifest.id) } : {}),
|
|
131
147
|
...(kind === 'rule' && manifest.category ? { category: String(manifest.category) } : {}),
|
|
132
148
|
...(kind === 'rule' && manifest.scope ? { scope: String(manifest.scope) } : {}),
|
|
133
|
-
...(kind === 'rule' && stringList(manifest.labels)
|
|
149
|
+
...(kind === 'rule' && stringList(manifest.labels)
|
|
150
|
+
? { labels: stringList(manifest.labels) }
|
|
151
|
+
: {}),
|
|
134
152
|
order: entries.length + 1,
|
|
135
153
|
source: 'private-devkit-git',
|
|
136
154
|
revision: repositoryRevision,
|
|
137
155
|
contentHash,
|
|
138
156
|
...(kind === 'rule' ? { legacyInstalledIds: legacyImplementationIds(manifest) } : {}),
|
|
139
157
|
...(kind === 'rule' ? { enforcement: String(manifest.enforcement ?? 'guidance') } : {}),
|
|
140
|
-
...(kind === 'rule' && applicableStacks(manifest)
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
...(kind === 'rule' && applicableStacks(manifest)
|
|
159
|
+
? { applicableStacks: applicableStacks(manifest) }
|
|
160
|
+
: {}),
|
|
161
|
+
...(kind === 'rule' && requiredPackages(manifest)
|
|
162
|
+
? { requiredPackages: requiredPackages(manifest) }
|
|
163
|
+
: {}),
|
|
164
|
+
...(kind === 'rule' && stringList(manifest.requiredCapabilities)
|
|
165
|
+
? { requiredCapabilities: stringList(manifest.requiredCapabilities) }
|
|
166
|
+
: {}),
|
|
143
167
|
...(kind === 'rule' && manifest.ai ? { ai: manifest.ai } : {}),
|
|
144
168
|
...(kind === 'rule' && manifest.verification ? { verification: manifest.verification } : {}),
|
|
145
|
-
...(kind === 'rule' && stringList(manifest.composedOf)
|
|
169
|
+
...(kind === 'rule' && stringList(manifest.composedOf)
|
|
170
|
+
? { composedOf: stringList(manifest.composedOf) }
|
|
171
|
+
: {}),
|
|
146
172
|
...(kind === 'module' && notApplicableRuleIds(manifest)
|
|
147
173
|
? { notApplicableRuleIds: notApplicableRuleIds(manifest) }
|
|
148
174
|
: {}),
|
|
@@ -170,7 +196,9 @@ export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'worki
|
|
|
170
196
|
throw new Error(`Rule cannot compose itself: ${entry.id}`);
|
|
171
197
|
}
|
|
172
198
|
}
|
|
173
|
-
const composition = new Map(entries
|
|
199
|
+
const composition = new Map(entries
|
|
200
|
+
.filter((entry) => entry.kind === 'rule')
|
|
201
|
+
.map((entry) => [entry.id, entry.composedOf ?? []]));
|
|
174
202
|
const visiting = new Set();
|
|
175
203
|
const visited = new Set();
|
|
176
204
|
const visit = (id) => {
|
|
@@ -186,5 +214,9 @@ export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'worki
|
|
|
186
214
|
};
|
|
187
215
|
for (const id of composition.keys())
|
|
188
216
|
visit(id);
|
|
189
|
-
return {
|
|
217
|
+
return {
|
|
218
|
+
schemaVersion: 1,
|
|
219
|
+
package: { name: '@specdest/devkit', version: repositoryRevision },
|
|
220
|
+
entries,
|
|
221
|
+
};
|
|
190
222
|
}
|
package/dist/npm/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { createCanonicalSource } from './canonical-source.ts';
|
|
2
2
|
export { createFlowCommandHandler } from './flow.ts';
|
|
3
|
-
export { createFuzzCommandHandler } from './fuzz.js';
|
|
4
3
|
export declare const COMMAND_NAMES: string[];
|
|
5
4
|
export declare function runCli(argv: any, io?: any, handlers?: any): Promise<any>;
|
package/dist/npm/index.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
export { createCanonicalSource } from "./canonical-source.js";
|
|
2
2
|
export { createFlowCommandHandler } from "./flow.js";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const COMMAND_NAMES = [
|
|
4
|
+
'status',
|
|
5
|
+
'add',
|
|
6
|
+
'sync',
|
|
7
|
+
'check',
|
|
8
|
+
'rules',
|
|
9
|
+
'ai-instruction',
|
|
10
|
+
'doctor',
|
|
11
|
+
'flow',
|
|
12
|
+
'supabase',
|
|
13
|
+
'slack',
|
|
14
|
+
];
|
|
15
|
+
const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n add <package> Adopt/install a predefined package\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] [--json] [--details] [--staged | --files <path...>] Run canonical checks, optionally targeted\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n flow <command> Manage local resumable development flow state\n supabase <status|start|stop> Local Supabase through restricted Controller\n slack send <files...> Upload files to configured Slack channel\n`;
|
|
6
16
|
export async function runCli(argv, io = process, handlers = {}) {
|
|
7
17
|
const [command, ...args] = argv;
|
|
8
18
|
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function resolveProjectPath(projectRoot:
|
|
2
|
-
export function upsertMarkdownSection(existing:
|
|
3
|
-
export function removeMarkdownSection(existing:
|
|
1
|
+
export declare function resolveProjectPath(projectRoot: string, relativePath: string): string;
|
|
2
|
+
export declare function upsertMarkdownSection(existing: string, heading: string, body: string): string;
|
|
3
|
+
export declare function removeMarkdownSection(existing: string, heading: string): string;
|
|
@@ -66,8 +66,12 @@ export default function App() {
|
|
|
66
66
|
}
|
|
67
67
|
export const expoRecipe = {
|
|
68
68
|
id: 'expo',
|
|
69
|
-
recipeVersion: '1.
|
|
69
|
+
recipeVersion: '1.2.0',
|
|
70
70
|
role: 'frontend',
|
|
71
|
+
setupRequirements: [
|
|
72
|
+
{ kind: 'package', packageId: 'oxlint', required: true },
|
|
73
|
+
{ kind: 'package', packageId: 'husky', required: true, when: 'git' },
|
|
74
|
+
],
|
|
71
75
|
conflicts: ['vite'],
|
|
72
76
|
async detect(projectRoot) {
|
|
73
77
|
return await detectDependency(projectRoot, 'expo', 'Expo');
|
|
@@ -2,6 +2,7 @@ import { type PackageCommandRunner } from './install.ts';
|
|
|
2
2
|
export declare function addPredefinedPackage(projectRoot: string, id: string, options?: {
|
|
3
3
|
runCommand?: PackageCommandRunner;
|
|
4
4
|
}): Promise<{
|
|
5
|
+
setupPackages?: string[] | undefined;
|
|
5
6
|
id: string;
|
|
6
7
|
recipeVersion: string;
|
|
7
8
|
detectedVersion: string | null;
|
|
@@ -2,7 +2,43 @@ import { getPackageRecipe, listPackageRecipes } from "./registry.js";
|
|
|
2
2
|
import { runPackageCommand } from "./install.js";
|
|
3
3
|
import { installedPackageIds, resolvePackageAddition } from "./resolver.js";
|
|
4
4
|
import { readInstalledState, writeInstalledState } from "../state.js";
|
|
5
|
-
|
|
5
|
+
import { resolveProjectStack, STACK_PACKAGES } from "../project-context.js";
|
|
6
|
+
import { pathExists } from "./project-signals.js";
|
|
7
|
+
async function requiredSetupPackageIds(projectRoot, stack) {
|
|
8
|
+
const result = new Set();
|
|
9
|
+
const hasGit = await pathExists(projectRoot, '.git');
|
|
10
|
+
for (const foundationId of STACK_PACKAGES[stack] ?? []) {
|
|
11
|
+
const foundation = getPackageRecipe(foundationId);
|
|
12
|
+
for (const requirement of foundation.setupRequirements ?? []) {
|
|
13
|
+
if (requirement.kind !== 'package' || !requirement.required)
|
|
14
|
+
continue;
|
|
15
|
+
if (requirement.when === 'git' && !hasGit)
|
|
16
|
+
continue;
|
|
17
|
+
result.add(requirement.packageId);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [...result].sort();
|
|
21
|
+
}
|
|
22
|
+
async function ensureResolvedStackSetup(projectRoot, options) {
|
|
23
|
+
const stack = await resolveProjectStack(projectRoot);
|
|
24
|
+
if (!stack)
|
|
25
|
+
return [];
|
|
26
|
+
const state = await readInstalledState(projectRoot);
|
|
27
|
+
const foundations = STACK_PACKAGES[stack] ?? [];
|
|
28
|
+
const createdByDevkit = foundations.every((foundationId) => state.installed[foundationId]?.kind === 'package' &&
|
|
29
|
+
state.installed[foundationId]?.source === 'installed');
|
|
30
|
+
if (!createdByDevkit)
|
|
31
|
+
return [];
|
|
32
|
+
const setupPackages = await requiredSetupPackageIds(projectRoot, stack);
|
|
33
|
+
for (const packageId of setupPackages) {
|
|
34
|
+
await addPredefinedPackageInternal(projectRoot, packageId, {
|
|
35
|
+
...options,
|
|
36
|
+
ensureStackSetup: false,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return setupPackages;
|
|
40
|
+
}
|
|
41
|
+
async function addPredefinedPackageInternal(projectRoot, id, options = {}) {
|
|
6
42
|
const recipe = getPackageRecipe(id);
|
|
7
43
|
const state = await readInstalledState(projectRoot);
|
|
8
44
|
const recipes = listPackageRecipes();
|
|
@@ -28,15 +64,15 @@ export async function addPredefinedPackage(projectRoot, id, options = {}) {
|
|
|
28
64
|
if (!currentDetection.present || !currentDetection.compatible) {
|
|
29
65
|
throw new Error(currentDetection.reason ?? `${id} install did not produce a compatible package state`);
|
|
30
66
|
}
|
|
67
|
+
const existingEntry = state.installed[id];
|
|
31
68
|
const entry = {
|
|
32
69
|
kind: 'package',
|
|
33
70
|
recipeVersion: recipe.recipeVersion,
|
|
34
71
|
detectedVersion: currentDetection.detectedVersion,
|
|
35
72
|
role: recipe.role,
|
|
36
|
-
source: applied.source,
|
|
73
|
+
source: existingEntry?.source ?? applied.source,
|
|
37
74
|
...(resolution.variant ? { resolvedVariant: resolution.variant } : {}),
|
|
38
75
|
};
|
|
39
|
-
const existingEntry = state.installed[id];
|
|
40
76
|
const unchanged = existingEntry && JSON.stringify(existingEntry) === JSON.stringify(entry);
|
|
41
77
|
if (!unchanged) {
|
|
42
78
|
state.installed[id] = entry;
|
|
@@ -45,6 +81,7 @@ export async function addPredefinedPackage(projectRoot, id, options = {}) {
|
|
|
45
81
|
state.requested.sort();
|
|
46
82
|
await writeInstalledState(projectRoot, state);
|
|
47
83
|
}
|
|
84
|
+
const setupPackages = options.ensureStackSetup === false ? [] : await ensureResolvedStackSetup(projectRoot, options);
|
|
48
85
|
return {
|
|
49
86
|
id,
|
|
50
87
|
recipeVersion: recipe.recipeVersion,
|
|
@@ -52,5 +89,9 @@ export async function addPredefinedPackage(projectRoot, id, options = {}) {
|
|
|
52
89
|
source: applied.source,
|
|
53
90
|
resolvedVariant: resolution.variant,
|
|
54
91
|
changed: !unchanged,
|
|
92
|
+
...(setupPackages.length ? { setupPackages } : {}),
|
|
55
93
|
};
|
|
56
94
|
}
|
|
95
|
+
export async function addPredefinedPackage(projectRoot, id, options = {}) {
|
|
96
|
+
return await addPredefinedPackageInternal(projectRoot, id, options);
|
|
97
|
+
}
|
|
@@ -2,6 +2,7 @@ import { execFile } from 'node:child_process';
|
|
|
2
2
|
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
|
+
import { PackageJsonSchema, parseWithSchema } from "../schemas.js";
|
|
5
6
|
const execFileAsync = promisify(execFile);
|
|
6
7
|
export async function runPackageCommand(command, args, options) {
|
|
7
8
|
try {
|
|
@@ -11,14 +12,14 @@ export async function runPackageCommand(command, args, options) {
|
|
|
11
12
|
const detail = [error?.stderr, error?.stdout, error?.message]
|
|
12
13
|
.map((value) => String(value ?? '').trim())
|
|
13
14
|
.find(Boolean);
|
|
14
|
-
throw new Error(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}
|
|
15
|
+
throw new Error(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`, { cause: error });
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
export async function updatePackageJson(projectRoot, update) {
|
|
18
19
|
const path = join(projectRoot, 'package.json');
|
|
19
20
|
let pkg = {};
|
|
20
21
|
try {
|
|
21
|
-
pkg = JSON.parse(await readFile(path, 'utf8'));
|
|
22
|
+
pkg = parseWithSchema(PackageJsonSchema, JSON.parse(await readFile(path, 'utf8')), `package.json at ${path}`);
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
25
|
if (error?.code !== 'ENOENT')
|