@specdest/devkit 0.4.5 → 0.4.8
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 +34 -4
- package/dist/npm/canonical-project-operations.d.ts +5 -0
- package/dist/npm/canonical-project-operations.js +5 -0
- package/dist/npm/canonical-project.d.ts +10 -0
- package/dist/npm/canonical-project.js +109 -0
- package/dist/npm/canonical-source.d.ts +14 -0
- package/dist/npm/canonical-source.js +216 -0
- package/dist/npm/catalog-snapshot.d.ts +47 -0
- package/dist/npm/catalog-snapshot.js +28 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +15 -0
- package/dist/npm/commands.d.ts +9 -0
- package/dist/npm/commands.js +157 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +396 -0
- package/dist/npm/fuzz.d.ts +138 -0
- package/dist/npm/fuzz.js +327 -0
- package/dist/npm/git-catalog.d.ts +39 -0
- package/dist/npm/git-catalog.js +190 -0
- package/dist/npm/index.d.ts +5 -0
- package/dist/npm/index.js +22 -0
- package/dist/npm/installer-primitives.d.ts +3 -0
- package/dist/npm/installer-primitives.js +50 -0
- package/dist/npm/predefined-packages/abac.d.ts +2 -0
- package/dist/npm/predefined-packages/abac.js +22 -0
- package/dist/npm/predefined-packages/auth.d.ts +2 -0
- package/dist/npm/predefined-packages/auth.js +21 -0
- package/dist/npm/predefined-packages/convex.d.ts +2 -0
- package/dist/npm/predefined-packages/convex.js +53 -0
- package/dist/npm/predefined-packages/expo.d.ts +2 -0
- package/dist/npm/predefined-packages/expo.js +84 -0
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
- package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
- package/dist/npm/predefined-packages/health.d.ts +10 -0
- package/dist/npm/predefined-packages/health.js +52 -0
- package/dist/npm/predefined-packages/husky.d.ts +2 -0
- package/dist/npm/predefined-packages/husky.js +57 -0
- package/dist/npm/predefined-packages/index.d.ts +11 -0
- package/dist/npm/predefined-packages/index.js +56 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +85 -0
- package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
- package/dist/npm/predefined-packages/local-logging.js +17 -0
- package/dist/npm/predefined-packages/logging.d.ts +2 -0
- package/dist/npm/predefined-packages/logging.js +21 -0
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
- package/dist/npm/predefined-packages/nps.d.ts +2 -0
- package/dist/npm/predefined-packages/nps.js +32 -0
- package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
- package/dist/npm/predefined-packages/oxfmt.js +22 -0
- package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
- package/dist/npm/predefined-packages/oxlint.js +35 -0
- package/dist/npm/predefined-packages/package-json.d.ts +3 -0
- package/dist/npm/predefined-packages/package-json.js +61 -0
- package/dist/npm/predefined-packages/payments.d.ts +2 -0
- package/dist/npm/predefined-packages/payments.js +31 -0
- package/dist/npm/predefined-packages/playwright.d.ts +2 -0
- package/dist/npm/predefined-packages/playwright.js +35 -0
- package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
- package/dist/npm/predefined-packages/project-signals.js +39 -0
- package/dist/npm/predefined-packages/registry.d.ts +3 -0
- package/dist/npm/predefined-packages/registry.js +63 -0
- package/dist/npm/predefined-packages/resolver.d.ts +8 -0
- package/dist/npm/predefined-packages/resolver.js +35 -0
- package/dist/npm/predefined-packages/sentry.d.ts +2 -0
- package/dist/npm/predefined-packages/sentry.js +29 -0
- package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
- package/dist/npm/predefined-packages/shadcn.js +23 -0
- package/dist/npm/predefined-packages/storybook.d.ts +2 -0
- package/dist/npm/predefined-packages/storybook.js +25 -0
- package/dist/npm/predefined-packages/stryker.d.ts +2 -0
- package/dist/npm/predefined-packages/stryker.js +48 -0
- package/dist/npm/predefined-packages/supabase.d.ts +2 -0
- package/dist/npm/predefined-packages/supabase.js +84 -0
- package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
- package/dist/npm/predefined-packages/tailwind.js +18 -0
- package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-form.js +19 -0
- package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-query.js +15 -0
- package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-router.js +18 -0
- package/dist/npm/predefined-packages/types.d.ts +31 -0
- package/dist/npm/predefined-packages/types.js +1 -0
- package/dist/npm/predefined-packages/vite.d.ts +2 -0
- package/dist/npm/predefined-packages/vite.js +123 -0
- package/dist/npm/predefined-packages/vitest.d.ts +2 -0
- package/dist/npm/predefined-packages/vitest.js +20 -0
- package/dist/npm/predefined-packages/zod.d.ts +2 -0
- package/dist/npm/predefined-packages/zod.js +18 -0
- package/dist/npm/project-check.d.ts +6 -0
- package/dist/npm/project-check.js +87 -0
- package/dist/npm/project-context.d.ts +42 -0
- package/dist/npm/project-context.js +192 -0
- package/dist/npm/project-rules.d.ts +22 -0
- package/dist/npm/project-rules.js +66 -0
- package/dist/npm/project-runtime.d.ts +18 -0
- package/dist/npm/project-runtime.js +27 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +56 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +135 -0
- package/dist/npm/remote-installer.d.ts +4 -0
- package/dist/npm/remote-installer.js +312 -0
- package/dist/npm/state.d.ts +14 -0
- package/dist/npm/state.js +182 -0
- package/package.json +10 -7
- package/src/canonical-project-operations.js +0 -433
- package/src/canonical-project.js +0 -136
- package/src/canonical-source.js +0 -250
- package/src/catalog-snapshot.js +0 -39
- package/src/catalog.js +0 -117
- package/src/cli.js +0 -14
- package/src/fuzz.js +0 -291
- package/src/git-catalog.js +0 -177
- package/src/index.js +0 -36
- package/src/installer-primitives.js +0 -198
- package/src/project-operations.js +0 -189
- package/src/project-targeting.js +0 -48
- package/src/remote-installer.js +0 -479
- package/src/rule-profile.js +0 -61
- package/src/setup-requirements.js +0 -82
- package/src/shared-file.js +0 -131
- package/src/sync-core.js +0 -390
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const RULE_PROFILE_RELATIVE_PATH = ".spd/rules.json";
|
|
2
|
+
export declare const PROJECT_TYPES: readonly string[];
|
|
3
|
+
export declare const EMPTY_RULE_PROFILE: Readonly<{
|
|
4
|
+
schemaVersion: 1;
|
|
5
|
+
projectType: null;
|
|
6
|
+
capabilities: never[];
|
|
7
|
+
include: never[];
|
|
8
|
+
exclude: never[];
|
|
9
|
+
}>;
|
|
10
|
+
export declare function validateRuleProfile(profile: any): {
|
|
11
|
+
schemaVersion: number;
|
|
12
|
+
projectType: string | null;
|
|
13
|
+
capabilities: unknown[];
|
|
14
|
+
include: unknown[];
|
|
15
|
+
exclude: any;
|
|
16
|
+
};
|
|
17
|
+
export declare function readRuleProfile(projectRoot: string): Promise<{
|
|
18
|
+
schemaVersion: number;
|
|
19
|
+
projectType: string | null;
|
|
20
|
+
capabilities: unknown[];
|
|
21
|
+
include: unknown[];
|
|
22
|
+
exclude: any;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function assertKnownRuleOverrides(entries: any[], profile: any): void;
|
|
25
|
+
export declare function resolveProjectType(stack: string | null, profile?: any): any;
|
|
26
|
+
export declare function ruleApplies(entry: any, stack: string | null, profile?: any, packageIds?: Iterable<string>): boolean;
|
|
27
|
+
export declare function projectRuleApplies(entry: any, stack: string | null, profile?: any, entries?: any[], packageIds?: Iterable<string>): any;
|
|
28
|
+
export declare function applicableCatalogEntries(entries: any[], stack: string | null, profile?: any, packageIds?: Iterable<string>): any[];
|
|
29
|
+
export declare function detectProjectStack(projectRoot: string): Promise<string | null>;
|
|
30
|
+
export declare function resolveProjectStack(projectRoot: string): Promise<any>;
|
|
31
|
+
export declare function loadProjectContext(projectRoot: string, entries: any[]): Promise<{
|
|
32
|
+
stack: any;
|
|
33
|
+
profile: {
|
|
34
|
+
schemaVersion: number;
|
|
35
|
+
projectType: string | null;
|
|
36
|
+
capabilities: unknown[];
|
|
37
|
+
include: unknown[];
|
|
38
|
+
exclude: any;
|
|
39
|
+
};
|
|
40
|
+
projectType: any;
|
|
41
|
+
applicable: any[];
|
|
42
|
+
}>;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { ensureMetadataNamespace, readInstalledState } from "./state.js";
|
|
4
|
+
export const RULE_PROFILE_RELATIVE_PATH = '.spd/rules.json';
|
|
5
|
+
export const PROJECT_TYPES = Object.freeze(['product', 'static-site', 'tooling', 'backend', 'monorepo', 'generic']);
|
|
6
|
+
export const EMPTY_RULE_PROFILE = Object.freeze({
|
|
7
|
+
schemaVersion: 1,
|
|
8
|
+
projectType: null,
|
|
9
|
+
capabilities: [],
|
|
10
|
+
include: [],
|
|
11
|
+
exclude: [],
|
|
12
|
+
});
|
|
13
|
+
function uniqueStrings(values, label) {
|
|
14
|
+
if (!Array.isArray(values ?? []))
|
|
15
|
+
throw new Error(`Invalid ${label}`);
|
|
16
|
+
return [...new Set((values ?? []).map(String).map((value) => value.trim()).filter(Boolean))].sort();
|
|
17
|
+
}
|
|
18
|
+
export function validateRuleProfile(profile) {
|
|
19
|
+
if (!profile || typeof profile !== 'object' || Array.isArray(profile) || profile.schemaVersion !== 1) {
|
|
20
|
+
throw new Error('Invalid .spd/rules.json profile');
|
|
21
|
+
}
|
|
22
|
+
const projectType = profile.projectType == null ? null : String(profile.projectType).trim();
|
|
23
|
+
if (profile.projectType != null && !projectType)
|
|
24
|
+
throw new Error('Invalid rule profile projectType');
|
|
25
|
+
const capabilities = uniqueStrings(profile.capabilities, 'rule profile capabilities');
|
|
26
|
+
const include = uniqueStrings(profile.include, 'rule profile include');
|
|
27
|
+
if (!Array.isArray(profile.exclude ?? []))
|
|
28
|
+
throw new Error('Invalid rule profile exclude');
|
|
29
|
+
const exclude = (profile.exclude ?? []).map((item) => {
|
|
30
|
+
if (!item || typeof item !== 'object' || !String(item.id ?? '').trim() || !String(item.reason ?? '').trim()) {
|
|
31
|
+
throw new Error('Rule exclusions require both id and non-empty reason');
|
|
32
|
+
}
|
|
33
|
+
return { id: String(item.id).trim(), reason: String(item.reason).trim() };
|
|
34
|
+
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
35
|
+
return { schemaVersion: 1, projectType, capabilities, include, exclude };
|
|
36
|
+
}
|
|
37
|
+
export async function readRuleProfile(projectRoot) {
|
|
38
|
+
await ensureMetadataNamespace(projectRoot);
|
|
39
|
+
try {
|
|
40
|
+
return validateRuleProfile(JSON.parse(await readFile(join(projectRoot, RULE_PROFILE_RELATIVE_PATH), 'utf8')));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error?.code === 'ENOENT')
|
|
44
|
+
return { ...EMPTY_RULE_PROFILE, capabilities: [], include: [], exclude: [] };
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function assertKnownRuleOverrides(entries, profile) {
|
|
49
|
+
const ids = new Set(entries.filter((entry) => entry.kind === 'rule').map((entry) => entry.id));
|
|
50
|
+
for (const id of profile.include ?? [])
|
|
51
|
+
if (!ids.has(id))
|
|
52
|
+
throw new Error(`Unknown included rule: ${id}`);
|
|
53
|
+
for (const item of profile.exclude ?? [])
|
|
54
|
+
if (!ids.has(item.id))
|
|
55
|
+
throw new Error(`Unknown excluded rule: ${item.id}`);
|
|
56
|
+
}
|
|
57
|
+
export function resolveProjectType(stack, profile = EMPTY_RULE_PROFILE) {
|
|
58
|
+
return profile.projectType ?? (stack ? 'product' : 'generic');
|
|
59
|
+
}
|
|
60
|
+
const STACK_PACKAGES = {
|
|
61
|
+
'stack-vite-supabase': ['vite', 'supabase'],
|
|
62
|
+
'stack-vite-convex': ['vite', 'convex'],
|
|
63
|
+
'stack-expo-supabase': ['expo', 'supabase'],
|
|
64
|
+
'stack-expo-convex': ['expo', 'convex'],
|
|
65
|
+
};
|
|
66
|
+
function effectivePackages(stack, packageIds = []) {
|
|
67
|
+
return new Set([...(stack ? STACK_PACKAGES[stack] ?? [] : []), ...packageIds]);
|
|
68
|
+
}
|
|
69
|
+
export function ruleApplies(entry, stack, profile = EMPTY_RULE_PROFILE, packageIds = []) {
|
|
70
|
+
const included = new Set(profile.include ?? []);
|
|
71
|
+
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
72
|
+
if (excluded.has(entry.id))
|
|
73
|
+
return false;
|
|
74
|
+
if (included.has(entry.id))
|
|
75
|
+
return true;
|
|
76
|
+
if (entry.applicableStacks?.length && (!stack || !entry.applicableStacks.includes(stack)))
|
|
77
|
+
return false;
|
|
78
|
+
const packages = effectivePackages(stack, packageIds);
|
|
79
|
+
if (entry.requiredPackages?.some((id) => !packages.has(id)))
|
|
80
|
+
return false;
|
|
81
|
+
return capabilitySatisfied(entry, profile);
|
|
82
|
+
}
|
|
83
|
+
function profileDefinition(entries, projectType) {
|
|
84
|
+
if (projectType === 'product')
|
|
85
|
+
return null;
|
|
86
|
+
const module = entries.find((entry) => entry.kind === 'module' && entry.id === 'project-profiles');
|
|
87
|
+
const definition = module?.projectProfiles?.[projectType];
|
|
88
|
+
if (!definition)
|
|
89
|
+
throw new Error(`Canonical project profile not found: ${projectType}`);
|
|
90
|
+
return definition;
|
|
91
|
+
}
|
|
92
|
+
function capabilitySatisfied(entry, profile) {
|
|
93
|
+
const capabilities = new Set(profile.capabilities ?? []);
|
|
94
|
+
return !entry.requiredCapabilities?.some((capability) => !capabilities.has(capability));
|
|
95
|
+
}
|
|
96
|
+
export function projectRuleApplies(entry, stack, profile = EMPTY_RULE_PROFILE, entries = [], packageIds = []) {
|
|
97
|
+
const included = new Set(profile.include ?? []);
|
|
98
|
+
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
99
|
+
if (excluded.has(entry.id))
|
|
100
|
+
return false;
|
|
101
|
+
if (included.has(entry.id))
|
|
102
|
+
return true;
|
|
103
|
+
const projectType = resolveProjectType(stack, profile);
|
|
104
|
+
if (projectType === 'product')
|
|
105
|
+
return ruleApplies(entry, stack, profile, packageIds);
|
|
106
|
+
const definition = profileDefinition(entries, projectType);
|
|
107
|
+
return definition.ruleIds.includes(entry.id) && capabilitySatisfied(entry, profile);
|
|
108
|
+
}
|
|
109
|
+
export function applicableCatalogEntries(entries, stack, profile = EMPTY_RULE_PROFILE, packageIds = []) {
|
|
110
|
+
return entries
|
|
111
|
+
.filter((entry) => entry.kind === 'rule')
|
|
112
|
+
.filter((entry) => projectRuleApplies(entry, stack, profile, entries, packageIds))
|
|
113
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
114
|
+
}
|
|
115
|
+
function stackFromDependencies(deps) {
|
|
116
|
+
const frontends = [
|
|
117
|
+
deps.expo ? 'expo' : null,
|
|
118
|
+
(deps.vite || deps['@vitejs/plugin-react']) ? 'vite' : null,
|
|
119
|
+
].filter(Boolean);
|
|
120
|
+
const backends = [
|
|
121
|
+
deps.convex ? 'convex' : null,
|
|
122
|
+
deps['@supabase/supabase-js'] ? 'supabase' : null,
|
|
123
|
+
].filter(Boolean);
|
|
124
|
+
if (frontends.length > 1)
|
|
125
|
+
throw new Error(`Conflicting frontend packages detected: ${frontends.sort().join(', ')}`);
|
|
126
|
+
if (backends.length > 1)
|
|
127
|
+
throw new Error(`Conflicting backend packages detected: ${backends.sort().join(', ')}`);
|
|
128
|
+
if (frontends.length !== 1 || backends.length !== 1)
|
|
129
|
+
return null;
|
|
130
|
+
return `stack-${frontends[0]}-${backends[0]}`;
|
|
131
|
+
}
|
|
132
|
+
async function readPackageDependencies(path) {
|
|
133
|
+
try {
|
|
134
|
+
const pkg = JSON.parse(await readFile(path, 'utf8'));
|
|
135
|
+
return { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error?.code === 'ENOENT')
|
|
139
|
+
return null;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export async function detectProjectStack(projectRoot) {
|
|
144
|
+
const dependencySets = [];
|
|
145
|
+
const rootDeps = await readPackageDependencies(join(projectRoot, 'package.json'));
|
|
146
|
+
if (rootDeps)
|
|
147
|
+
dependencySets.push(rootDeps);
|
|
148
|
+
for (const group of ['apps', 'packages']) {
|
|
149
|
+
let children = [];
|
|
150
|
+
try {
|
|
151
|
+
children = await readdir(join(projectRoot, group), { withFileTypes: true });
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error?.code !== 'ENOENT')
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
for (const child of children.filter((entry) => entry.isDirectory())) {
|
|
158
|
+
const deps = await readPackageDependencies(join(projectRoot, group, child.name, 'package.json'));
|
|
159
|
+
if (deps)
|
|
160
|
+
dependencySets.push(deps);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const detected = new Set(dependencySets.map(stackFromDependencies).filter(Boolean));
|
|
164
|
+
if (detected.size === 1)
|
|
165
|
+
return [...detected][0];
|
|
166
|
+
if (detected.size > 1)
|
|
167
|
+
throw new Error(`Multiple canonical stacks detected: ${[...detected].sort().join(', ')}`);
|
|
168
|
+
return stackFromDependencies(Object.assign({}, ...dependencySets));
|
|
169
|
+
}
|
|
170
|
+
export async function resolveProjectStack(projectRoot) {
|
|
171
|
+
const detectedStack = await detectProjectStack(projectRoot);
|
|
172
|
+
if (detectedStack)
|
|
173
|
+
return detectedStack;
|
|
174
|
+
const installedState = await readInstalledState(projectRoot);
|
|
175
|
+
const requestedStacks = (installedState.requested ?? []).filter((id) => id.startsWith('stack-'));
|
|
176
|
+
return requestedStacks.length === 1 ? requestedStacks[0] : null;
|
|
177
|
+
}
|
|
178
|
+
export async function loadProjectContext(projectRoot, entries) {
|
|
179
|
+
const stack = await resolveProjectStack(projectRoot);
|
|
180
|
+
const installedState = await readInstalledState(projectRoot);
|
|
181
|
+
const packageIds = Object.entries(installedState.installed ?? {})
|
|
182
|
+
.filter(([, value]) => value?.kind === 'package')
|
|
183
|
+
.map(([id]) => id);
|
|
184
|
+
const profile = await readRuleProfile(projectRoot);
|
|
185
|
+
assertKnownRuleOverrides(entries, profile);
|
|
186
|
+
return {
|
|
187
|
+
stack,
|
|
188
|
+
profile,
|
|
189
|
+
projectType: resolveProjectType(stack, profile),
|
|
190
|
+
applicable: applicableCatalogEntries(entries, stack, profile, packageIds),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function aiInstructionText(): string;
|
|
2
|
+
export declare function canonicalRules(projectRoot: string, source: any, options?: any): Promise<{
|
|
3
|
+
stack: any;
|
|
4
|
+
profile: {
|
|
5
|
+
schemaVersion: number;
|
|
6
|
+
projectType: string | null;
|
|
7
|
+
capabilities: unknown[];
|
|
8
|
+
include: unknown[];
|
|
9
|
+
exclude: any;
|
|
10
|
+
};
|
|
11
|
+
detail: boolean;
|
|
12
|
+
rules: {
|
|
13
|
+
content?: any;
|
|
14
|
+
id: any;
|
|
15
|
+
name: any;
|
|
16
|
+
category: any;
|
|
17
|
+
enforcement: any;
|
|
18
|
+
aiLoad: any;
|
|
19
|
+
summary: any;
|
|
20
|
+
composedOf: any;
|
|
21
|
+
}[];
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { loadCanonicalProjectContext } from "./project-runtime.js";
|
|
2
|
+
import { assertPredefinedPackageState } from "./predefined-packages/health.js";
|
|
3
|
+
import { readChecksState } from "./state.js";
|
|
4
|
+
function aiMode(entry) {
|
|
5
|
+
return entry.ai?.load ?? 'failure-only';
|
|
6
|
+
}
|
|
7
|
+
function ruleSummary(entry) {
|
|
8
|
+
if (entry.summary)
|
|
9
|
+
return String(entry.summary).trim();
|
|
10
|
+
const content = String(entry.content ?? '').replace(/\r\n?/gu, '\n');
|
|
11
|
+
const intent = content.match(/(?:^|\n)## Intent\s*\n+([^#][\s\S]*?)(?=\n## |$)/u)?.[1]?.trim();
|
|
12
|
+
const source = intent || content
|
|
13
|
+
.split('\n')
|
|
14
|
+
.map((line) => line.trim())
|
|
15
|
+
.find((line) => line && !line.startsWith('#')) || entry.name || entry.id;
|
|
16
|
+
return source.replace(/^\*\*Rule:\*\*\s*/u, '').replace(/\s+/gu, ' ').slice(0, 240).trim();
|
|
17
|
+
}
|
|
18
|
+
export function aiInstructionText() {
|
|
19
|
+
return [
|
|
20
|
+
'Specdest Devkit governs repository engineering rules and deterministic development flow.',
|
|
21
|
+
'Before repository work, inspect persisted Flow state with `npx @specdest/devkit flow status`. Do not infer persisted Flow state from chat history.',
|
|
22
|
+
'Use the agent development policy to classify the work and choose the appropriate worktree. Devkit Flow owns persisted task state, phase transitions, verification, and completion.',
|
|
23
|
+
'Do not preload the full rule catalog.',
|
|
24
|
+
'Before changing code, use `npx @specdest/devkit rules --category <category>` to discover compact relevant summaries, then `npx @specdest/devkit rules --id <rule>` only for rules whose full guidance is needed.',
|
|
25
|
+
'Run the repository completion checks normally. If Devkit checks fail, use `npx @specdest/devkit rules --failed` to load full guidance only for failed rules and fix the violation without weakening the rule.',
|
|
26
|
+
].join('\n');
|
|
27
|
+
}
|
|
28
|
+
export async function canonicalRules(projectRoot, source, options = {}) {
|
|
29
|
+
await assertPredefinedPackageState(projectRoot);
|
|
30
|
+
const { stack, profile, applicable } = await loadCanonicalProjectContext(projectRoot, source);
|
|
31
|
+
let selected = applicable;
|
|
32
|
+
let detail = false;
|
|
33
|
+
if (options.ids?.length) {
|
|
34
|
+
const wanted = new Set(options.ids);
|
|
35
|
+
selected = selected.filter((entry) => wanted.has(entry.id));
|
|
36
|
+
detail = true;
|
|
37
|
+
}
|
|
38
|
+
else if (options.categories?.length) {
|
|
39
|
+
const wanted = new Set(options.categories.map((value) => value.toLowerCase()));
|
|
40
|
+
selected = selected.filter((entry) => wanted.has(String(entry.category ?? '').toLowerCase()));
|
|
41
|
+
}
|
|
42
|
+
else if (options.failed) {
|
|
43
|
+
const state = await readChecksState(projectRoot);
|
|
44
|
+
const failed = new Set(Object.entries(state.results ?? {}).filter(([, value]) => value.status === 'fail').map(([id]) => id));
|
|
45
|
+
selected = selected.filter((entry) => failed.has(entry.id));
|
|
46
|
+
detail = true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
selected = selected.filter((entry) => aiMode(entry) === 'always');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
stack,
|
|
53
|
+
profile,
|
|
54
|
+
detail,
|
|
55
|
+
rules: selected.map((entry) => ({
|
|
56
|
+
id: entry.id,
|
|
57
|
+
name: entry.name,
|
|
58
|
+
category: entry.category ?? null,
|
|
59
|
+
enforcement: entry.enforcement ?? 'guidance',
|
|
60
|
+
aiLoad: aiMode(entry),
|
|
61
|
+
summary: ruleSummary(entry),
|
|
62
|
+
composedOf: entry.composedOf ?? [],
|
|
63
|
+
...(detail ? { content: entry.content ?? '' } : {}),
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function prepareCanonicalManifest(source: any, entry: any, canonicalCheckRoot: string | null, checkerRuntimeRoot: string | null, { offline }?: {
|
|
2
|
+
offline?: boolean;
|
|
3
|
+
}): Promise<any>;
|
|
4
|
+
export declare function loadCanonicalProjectContext(projectRoot: string, source: any, options?: any): Promise<{
|
|
5
|
+
catalog: any;
|
|
6
|
+
stack: any;
|
|
7
|
+
projectType: any;
|
|
8
|
+
profile: {
|
|
9
|
+
schemaVersion: number;
|
|
10
|
+
projectType: string | null;
|
|
11
|
+
capabilities: unknown[];
|
|
12
|
+
include: unknown[];
|
|
13
|
+
exclude: any;
|
|
14
|
+
};
|
|
15
|
+
applicable: any[];
|
|
16
|
+
canonicalCheckRoot: any;
|
|
17
|
+
checkerRuntimeRoot: any;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { prepareCachedManifest } from "./canonical-project.js";
|
|
2
|
+
import { loadProjectContext } from "./project-context.js";
|
|
3
|
+
export async function prepareCanonicalManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline = false } = {}) {
|
|
4
|
+
if (offline && !(await source.hasModule(entry.id, entry.version, entry.contentHash)))
|
|
5
|
+
return null;
|
|
6
|
+
const root = await source.module(entry.id, entry.version, { contentHash: entry.contentHash });
|
|
7
|
+
return await prepareCachedManifest(entry, root, canonicalCheckRoot, checkerRuntimeRoot);
|
|
8
|
+
}
|
|
9
|
+
export async function loadCanonicalProjectContext(projectRoot, source, options = {}) {
|
|
10
|
+
const catalog = await source.catalog({ refresh: options.refresh ?? false });
|
|
11
|
+
const { stack, profile, projectType, applicable } = await loadProjectContext(projectRoot, catalog.entries ?? []);
|
|
12
|
+
const canonicalCheck = (catalog.entries ?? []).find((entry) => entry.id === 'canonical-check');
|
|
13
|
+
const checkerRuntime = (catalog.entries ?? []).find((entry) => entry.id === 'checker-runtime');
|
|
14
|
+
let canonicalCheckRoot = null;
|
|
15
|
+
let checkerRuntimeRoot = null;
|
|
16
|
+
if (options.withCheckers && canonicalCheck) {
|
|
17
|
+
if (!options.offline || await source.hasModule(canonicalCheck.id, canonicalCheck.version, canonicalCheck.contentHash)) {
|
|
18
|
+
canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version, { contentHash: canonicalCheck.contentHash });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (options.withCheckers && checkerRuntime) {
|
|
22
|
+
if (!options.offline || await source.hasModule(checkerRuntime.id, checkerRuntime.version, checkerRuntime.contentHash)) {
|
|
23
|
+
checkerRuntimeRoot = await source.module(checkerRuntime.id, checkerRuntime.version, { contentHash: checkerRuntime.contentHash });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { catalog, stack, projectType, profile, applicable, canonicalCheckRoot, checkerRuntimeRoot };
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function canonicalStatus(projectRoot: string, source: any, options?: any): Promise<{
|
|
2
|
+
stack: any;
|
|
3
|
+
projectType: any;
|
|
4
|
+
totals: {
|
|
5
|
+
applicable: number;
|
|
6
|
+
current: number;
|
|
7
|
+
missing: number;
|
|
8
|
+
outdated: number;
|
|
9
|
+
};
|
|
10
|
+
rows: {
|
|
11
|
+
id: any;
|
|
12
|
+
canonicalVersion: any;
|
|
13
|
+
installedVersion: any;
|
|
14
|
+
state: string;
|
|
15
|
+
}[];
|
|
16
|
+
packages: {
|
|
17
|
+
id: string;
|
|
18
|
+
recipeVersion: any;
|
|
19
|
+
detectedVersion: any;
|
|
20
|
+
role: any;
|
|
21
|
+
source: any;
|
|
22
|
+
resolvedVariant: any;
|
|
23
|
+
}[];
|
|
24
|
+
packageIssues: string[];
|
|
25
|
+
installedNonApplicable: string[];
|
|
26
|
+
}>;
|
|
27
|
+
export declare function canonicalDoctor(projectRoot: string, source: any): Promise<{
|
|
28
|
+
ok: boolean;
|
|
29
|
+
stack: string | null;
|
|
30
|
+
cacheRoot: any;
|
|
31
|
+
issues: string[];
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { resolveProjectStack } from "./project-context.js";
|
|
2
|
+
import { inspectPredefinedPackageState } from "./predefined-packages/health.js";
|
|
3
|
+
import { loadCanonicalProjectContext } from "./project-runtime.js";
|
|
4
|
+
import { readInstalledState } from "./state.js";
|
|
5
|
+
export async function canonicalStatus(projectRoot, source, options = {}) {
|
|
6
|
+
const current = await readInstalledState(projectRoot);
|
|
7
|
+
const packageHealth = await inspectPredefinedPackageState(projectRoot, current);
|
|
8
|
+
const { stack, projectType, applicable } = await loadCanonicalProjectContext(projectRoot, source, options);
|
|
9
|
+
const installed = current.installed;
|
|
10
|
+
const rows = applicable.map((entry) => {
|
|
11
|
+
const found = installed[entry.id];
|
|
12
|
+
const state = !found ? 'missing' : found.version === entry.version ? 'current' : 'outdated';
|
|
13
|
+
return { id: entry.id, canonicalVersion: entry.version, installedVersion: found?.version ?? null, state };
|
|
14
|
+
});
|
|
15
|
+
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
16
|
+
const packages = Object.entries(installed)
|
|
17
|
+
.filter(([, value]) => value?.kind === 'package')
|
|
18
|
+
.map(([id, value]) => ({ id, recipeVersion: value.recipeVersion ?? null, detectedVersion: value.detectedVersion ?? value.version ?? null, role: value.role ?? null, source: value.source ?? null, resolvedVariant: value.resolvedVariant ?? null }))
|
|
19
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
20
|
+
const installedNonApplicable = Object.keys(installed).filter((id) => !applicableIds.has(id) && installed[id]?.kind !== 'package').sort();
|
|
21
|
+
return {
|
|
22
|
+
stack,
|
|
23
|
+
projectType,
|
|
24
|
+
totals: {
|
|
25
|
+
applicable: rows.length,
|
|
26
|
+
current: rows.filter((row) => row.state === 'current').length,
|
|
27
|
+
missing: rows.filter((row) => row.state === 'missing').length,
|
|
28
|
+
outdated: rows.filter((row) => row.state === 'outdated').length,
|
|
29
|
+
},
|
|
30
|
+
rows,
|
|
31
|
+
packages,
|
|
32
|
+
packageIssues: packageHealth.issues,
|
|
33
|
+
installedNonApplicable,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export async function canonicalDoctor(projectRoot, source) {
|
|
37
|
+
const issues = [];
|
|
38
|
+
let stack = null;
|
|
39
|
+
try {
|
|
40
|
+
stack = await resolveProjectStack(projectRoot);
|
|
41
|
+
if (!stack)
|
|
42
|
+
issues.push('Unable to resolve a supported project stack.');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
issues.push(error.message);
|
|
46
|
+
}
|
|
47
|
+
const packageHealth = await inspectPredefinedPackageState(projectRoot);
|
|
48
|
+
issues.push(...packageHealth.issues);
|
|
49
|
+
try {
|
|
50
|
+
await source.catalog();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
issues.push(`Catalog unavailable: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
return { ok: issues.length === 0, stack, cacheRoot: source.cacheRoot, issues };
|
|
56
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { access, readdir, rm, rmdir } from 'node:fs/promises';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
3
|
+
import { installRule, syncRule } from './remote-installer.js';
|
|
4
|
+
import { assertPredefinedPackageState } from "./predefined-packages/health.js";
|
|
5
|
+
import { loadCanonicalProjectContext, prepareCanonicalManifest } from "./project-runtime.js";
|
|
6
|
+
import { readChecksState, readInstalledState, writeChecksState, writeInstalledState } from "./state.js";
|
|
7
|
+
async function fileExists(path) {
|
|
8
|
+
try {
|
|
9
|
+
await access(path);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error?.code === 'ENOENT')
|
|
14
|
+
return false;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function missingProjectScaffold(projectRoot, copies) {
|
|
19
|
+
for (const copy of copies ?? []) {
|
|
20
|
+
if (copy.mode !== 'scaffold' && copy.mode !== 'create-only')
|
|
21
|
+
continue;
|
|
22
|
+
const target = String(copy.target ?? copy.path ?? '');
|
|
23
|
+
if (target && !(await fileExists(join(projectRoot, target))))
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
async function refreshInstalledRevision(projectRoot, id, revision) {
|
|
29
|
+
const state = await readInstalledState(projectRoot);
|
|
30
|
+
if (!state.installed[id])
|
|
31
|
+
throw new Error(`Installed rule missing during provenance refresh: ${id}`);
|
|
32
|
+
state.installed[id] = { ...state.installed[id], revision };
|
|
33
|
+
await writeInstalledState(projectRoot, state);
|
|
34
|
+
}
|
|
35
|
+
async function cleanupCanonicalInstallState(projectRoot, catalogEntries, applicableIds) {
|
|
36
|
+
const installedState = await readInstalledState(projectRoot);
|
|
37
|
+
const catalogRules = new Set((catalogEntries ?? []).filter((entry) => entry.kind === 'rule').map((entry) => entry.id));
|
|
38
|
+
const requestedRoots = new Set(installedState.requested.filter((id) => {
|
|
39
|
+
const installed = installedState.installed[id];
|
|
40
|
+
return id.startsWith('stack-') || installed?.kind === 'package';
|
|
41
|
+
}));
|
|
42
|
+
const removed = [];
|
|
43
|
+
for (const id of Object.keys(installedState.installed)) {
|
|
44
|
+
if (requestedRoots.has(id))
|
|
45
|
+
continue;
|
|
46
|
+
if (catalogRules.has(id) && applicableIds.has(id))
|
|
47
|
+
continue;
|
|
48
|
+
delete installedState.installed[id];
|
|
49
|
+
removed.push(id);
|
|
50
|
+
}
|
|
51
|
+
const nextRequested = installedState.requested.filter((id) => requestedRoots.has(id) && Boolean(installedState.installed[id]));
|
|
52
|
+
const requestedChanged = JSON.stringify(nextRequested) !== JSON.stringify(installedState.requested);
|
|
53
|
+
installedState.requested = nextRequested;
|
|
54
|
+
if (!removed.length && !requestedChanged)
|
|
55
|
+
return [];
|
|
56
|
+
await writeInstalledState(projectRoot, installedState);
|
|
57
|
+
const runtimeState = await readChecksState(projectRoot);
|
|
58
|
+
for (const id of removed) {
|
|
59
|
+
delete runtimeState.results[id];
|
|
60
|
+
if (runtimeState.ownership)
|
|
61
|
+
delete runtimeState.ownership[id];
|
|
62
|
+
}
|
|
63
|
+
await writeChecksState(projectRoot, runtimeState);
|
|
64
|
+
return removed.sort();
|
|
65
|
+
}
|
|
66
|
+
async function cleanupCanonicalSkillTree(projectRoot, allowedFiles) {
|
|
67
|
+
const root = join(projectRoot, '.agents', 'skills');
|
|
68
|
+
async function walk(directory) {
|
|
69
|
+
let entries;
|
|
70
|
+
try {
|
|
71
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error?.code === 'ENOENT')
|
|
75
|
+
return;
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const path = join(directory, entry.name);
|
|
80
|
+
if (entry.isDirectory()) {
|
|
81
|
+
await walk(path);
|
|
82
|
+
try {
|
|
83
|
+
await rmdir(path);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error?.code !== 'ENOTEMPTY' && error?.code !== 'ENOENT')
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const projectPath = relative(projectRoot, path).split('\\').join('/');
|
|
92
|
+
if (!allowedFiles.has(projectPath))
|
|
93
|
+
await rm(path, { force: true });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await walk(root);
|
|
97
|
+
}
|
|
98
|
+
export async function canonicalSync(projectRoot, source) {
|
|
99
|
+
await assertPredefinedPackageState(projectRoot);
|
|
100
|
+
const current = await readInstalledState(projectRoot);
|
|
101
|
+
const { catalog, stack, projectType, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await loadCanonicalProjectContext(projectRoot, source, { refresh: true, withCheckers: true });
|
|
102
|
+
const changed = [];
|
|
103
|
+
const allowedSkillFiles = new Set();
|
|
104
|
+
for (const entry of applicable) {
|
|
105
|
+
const prepared = await prepareCanonicalManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
|
|
106
|
+
for (const copy of prepared.manifest.copies ?? []) {
|
|
107
|
+
const target = String(copy.target ?? copy.path ?? '');
|
|
108
|
+
if (target.startsWith('.agents/skills/'))
|
|
109
|
+
allowedSkillFiles.add(target);
|
|
110
|
+
}
|
|
111
|
+
const installed = current.installed[entry.id];
|
|
112
|
+
if (!installed) {
|
|
113
|
+
await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
|
|
114
|
+
changed.push({ id: entry.id, action: 'installed', version: entry.version });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const requiresContentSync = installed.version !== entry.version ||
|
|
118
|
+
installed.contentHash !== entry.contentHash ||
|
|
119
|
+
(prepared.checkerPath && installed.check?.command?.[0] !== 'specdest-cache') ||
|
|
120
|
+
await missingProjectScaffold(projectRoot, prepared.manifest.copies);
|
|
121
|
+
if (requiresContentSync) {
|
|
122
|
+
await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
|
|
123
|
+
changed.push({ id: entry.id, action: 'updated', version: entry.version });
|
|
124
|
+
}
|
|
125
|
+
else if (installed.revision !== entry.revision) {
|
|
126
|
+
await refreshInstalledRevision(projectRoot, entry.id, entry.revision);
|
|
127
|
+
changed.push({ id: entry.id, action: 'provenance-refreshed', version: entry.version });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
132
|
+
const removed = await cleanupCanonicalInstallState(projectRoot, catalog.entries ?? [], applicableIds);
|
|
133
|
+
await cleanupCanonicalSkillTree(projectRoot, allowedSkillFiles);
|
|
134
|
+
return { stack, projectType, applicable: applicable.length, changed, removed };
|
|
135
|
+
}
|