@specdest/devkit 0.4.6 → 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 -438
- 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
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { access, readdir, readFile, rm, rmdir } from 'node:fs/promises';
|
|
3
|
-
import { join, relative } from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { createCanonicalSource, detectProjectStack } from './canonical-source.js';
|
|
6
|
-
import { applicableCatalogEntries, prepareCachedManifest } from './canonical-project.js';
|
|
7
|
-
import { installRule, syncRule } from './remote-installer.js';
|
|
8
|
-
import { assertKnownRuleOverrides, readRuleProfile } from './rule-profile.js';
|
|
9
|
-
import { resolveProjectType } from './project-targeting.js';
|
|
10
|
-
import { readChecksState, readInstalledState, writeChecksState, writeInstalledState } from './sync-core.js';
|
|
11
|
-
|
|
12
|
-
function execute(command, args, cwd) {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
15
|
-
let stdout = ''; let stderr = '';
|
|
16
|
-
child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8');
|
|
17
|
-
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
18
|
-
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
19
|
-
child.on('error', reject);
|
|
20
|
-
child.on('close', (code) => resolve({ exitCode: code ?? 1, stdout, stderr }));
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function fileExists(path) {
|
|
25
|
-
try { await access(path); return true; } catch (error) { if (error?.code === 'ENOENT') return false; throw error; }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function missingProjectScaffold(projectRoot, copies) {
|
|
29
|
-
for (const copy of copies ?? []) {
|
|
30
|
-
if (copy.mode !== 'scaffold' && copy.mode !== 'create-only') continue;
|
|
31
|
-
const target = String(copy.target ?? copy.path ?? '');
|
|
32
|
-
if (target && !(await fileExists(join(projectRoot, target)))) return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function flags(args) {
|
|
38
|
-
const known = new Set(['--refresh', '--json']);
|
|
39
|
-
for (const arg of args) if (!known.has(arg)) throw new Error(`Unknown option: ${arg}`);
|
|
40
|
-
return { refresh: args.includes('--refresh'), json: args.includes('--json') };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function checkFlags(args) {
|
|
44
|
-
const result = { refresh: false, mode: 'full', files: null };
|
|
45
|
-
const remaining = [];
|
|
46
|
-
for (const arg of args) {
|
|
47
|
-
if (arg === '--refresh') result.refresh = true;
|
|
48
|
-
else remaining.push(arg);
|
|
49
|
-
}
|
|
50
|
-
if (remaining.includes('--staged') && remaining.includes('--files')) {
|
|
51
|
-
throw new Error('Use either --staged or --files, not both');
|
|
52
|
-
}
|
|
53
|
-
if (remaining.includes('--staged')) {
|
|
54
|
-
if (remaining.length !== 1) throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
|
|
55
|
-
result.mode = 'staged';
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
const filesIndex = remaining.indexOf('--files');
|
|
59
|
-
if (filesIndex >= 0) {
|
|
60
|
-
if (filesIndex !== 0 || remaining.length < 2) {
|
|
61
|
-
throw new Error('Usage: specdest check [--refresh] [--staged | --files <path...>]');
|
|
62
|
-
}
|
|
63
|
-
result.mode = 'files';
|
|
64
|
-
result.files = remaining.slice(1);
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
if (remaining.length) throw new Error(`Unknown option: ${remaining[0]}`);
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot, { offline = false } = {}) {
|
|
72
|
-
if (offline && !(await source.hasModule(entry.id, entry.version, entry.contentHash))) return null;
|
|
73
|
-
const root = await source.module(entry.id, entry.version, { contentHash: entry.contentHash });
|
|
74
|
-
return await prepareCachedManifest(entry, root, canonicalCheckRoot, checkerRuntimeRoot);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function resolveCanonicalStack(projectRoot) {
|
|
78
|
-
const detectedStack = await detectProjectStack(projectRoot);
|
|
79
|
-
if (detectedStack) return detectedStack;
|
|
80
|
-
const installedState = await readInstalledState(projectRoot);
|
|
81
|
-
const requestedStacks = (installedState.requested ?? []).filter((id) => id.startsWith('stack-'));
|
|
82
|
-
return requestedStacks.length === 1 ? requestedStacks[0] : null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function canonicalContext(projectRoot, source, options = {}) {
|
|
86
|
-
const catalog = await source.catalog({ refresh: options.refresh ?? false });
|
|
87
|
-
const stack = await resolveCanonicalStack(projectRoot);
|
|
88
|
-
const profile = await readRuleProfile(projectRoot);
|
|
89
|
-
assertKnownRuleOverrides(catalog.entries ?? [], profile);
|
|
90
|
-
const projectType = resolveProjectType(stack, profile);
|
|
91
|
-
const applicable = applicableCatalogEntries(catalog.entries ?? [], stack, profile);
|
|
92
|
-
const canonicalCheck = (catalog.entries ?? []).find((entry) => entry.id === 'canonical-check');
|
|
93
|
-
const checkerRuntime = (catalog.entries ?? []).find((entry) => entry.id === 'checker-runtime');
|
|
94
|
-
let canonicalCheckRoot = null;
|
|
95
|
-
let checkerRuntimeRoot = null;
|
|
96
|
-
if (options.withCheckers && canonicalCheck) {
|
|
97
|
-
if (!options.offline || await source.hasModule(canonicalCheck.id, canonicalCheck.version, canonicalCheck.contentHash)) {
|
|
98
|
-
canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version, { contentHash: canonicalCheck.contentHash });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (options.withCheckers && checkerRuntime) {
|
|
102
|
-
if (!options.offline || await source.hasModule(checkerRuntime.id, checkerRuntime.version, checkerRuntime.contentHash)) {
|
|
103
|
-
checkerRuntimeRoot = await source.module(checkerRuntime.id, checkerRuntime.version, { contentHash: checkerRuntime.contentHash });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return { catalog, stack, projectType, profile, applicable, canonicalCheckRoot, checkerRuntimeRoot };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function canonicalStatus(projectRoot, source, options = {}) {
|
|
110
|
-
const current = await readInstalledState(projectRoot);
|
|
111
|
-
const { stack, projectType, applicable } = await canonicalContext(projectRoot, source, options);
|
|
112
|
-
const installed = current.installed;
|
|
113
|
-
const rows = applicable.map((entry) => {
|
|
114
|
-
const found = installed[entry.id];
|
|
115
|
-
const state = !found ? 'missing' : found.version === entry.version ? 'current' : 'outdated';
|
|
116
|
-
return { id: entry.id, canonicalVersion: entry.version, installedVersion: found?.version ?? null, state };
|
|
117
|
-
});
|
|
118
|
-
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
119
|
-
const installedNonApplicable = Object.keys(installed).filter((id) => !applicableIds.has(id)).sort();
|
|
120
|
-
return {
|
|
121
|
-
stack,
|
|
122
|
-
projectType,
|
|
123
|
-
totals: {
|
|
124
|
-
applicable: rows.length,
|
|
125
|
-
current: rows.filter((row) => row.state === 'current').length,
|
|
126
|
-
missing: rows.filter((row) => row.state === 'missing').length,
|
|
127
|
-
outdated: rows.filter((row) => row.state === 'outdated').length,
|
|
128
|
-
},
|
|
129
|
-
rows,
|
|
130
|
-
installedNonApplicable,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function refreshInstalledRevision(projectRoot, id, revision) {
|
|
135
|
-
const state = await readInstalledState(projectRoot);
|
|
136
|
-
if (!state.installed[id]) throw new Error(`Installed rule missing during provenance refresh: ${id}`);
|
|
137
|
-
state.installed[id] = { ...state.installed[id], revision };
|
|
138
|
-
await writeInstalledState(projectRoot, state);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function cleanupCanonicalInstallState(projectRoot, catalogEntries, applicableIds) {
|
|
142
|
-
const installedState = await readInstalledState(projectRoot);
|
|
143
|
-
const catalogRules = new Set(
|
|
144
|
-
(catalogEntries ?? []).filter((entry) => entry.kind === 'rule').map((entry) => entry.id),
|
|
145
|
-
);
|
|
146
|
-
const requestedStacks = new Set(
|
|
147
|
-
installedState.requested.filter((id) => id.startsWith('stack-')),
|
|
148
|
-
);
|
|
149
|
-
const removed = [];
|
|
150
|
-
for (const id of Object.keys(installedState.installed)) {
|
|
151
|
-
if (requestedStacks.has(id)) continue;
|
|
152
|
-
if (catalogRules.has(id) && applicableIds.has(id)) continue;
|
|
153
|
-
delete installedState.installed[id];
|
|
154
|
-
removed.push(id);
|
|
155
|
-
}
|
|
156
|
-
const nextRequested = installedState.requested.filter(
|
|
157
|
-
(id) => id.startsWith('stack-') && Boolean(installedState.installed[id]),
|
|
158
|
-
);
|
|
159
|
-
const requestedChanged = JSON.stringify(nextRequested) !== JSON.stringify(installedState.requested);
|
|
160
|
-
installedState.requested = nextRequested;
|
|
161
|
-
if (!removed.length && !requestedChanged) return [];
|
|
162
|
-
await writeInstalledState(projectRoot, installedState);
|
|
163
|
-
|
|
164
|
-
const runtimeState = await readChecksState(projectRoot);
|
|
165
|
-
for (const id of removed) {
|
|
166
|
-
delete runtimeState.results[id];
|
|
167
|
-
if (runtimeState.ownership) delete runtimeState.ownership[id];
|
|
168
|
-
}
|
|
169
|
-
await writeChecksState(projectRoot, runtimeState);
|
|
170
|
-
return removed.sort();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function cleanupCanonicalSkillTree(projectRoot, allowedFiles) {
|
|
174
|
-
const root = join(projectRoot, '.agents', 'skills');
|
|
175
|
-
async function walk(directory) {
|
|
176
|
-
let entries;
|
|
177
|
-
try { entries = await readdir(directory, { withFileTypes: true }); }
|
|
178
|
-
catch (error) { if (error?.code === 'ENOENT') return; throw error; }
|
|
179
|
-
for (const entry of entries) {
|
|
180
|
-
const path = join(directory, entry.name);
|
|
181
|
-
if (entry.isDirectory()) {
|
|
182
|
-
await walk(path);
|
|
183
|
-
try { await rmdir(path); } catch (error) { if (error?.code !== 'ENOTEMPTY' && error?.code !== 'ENOENT') throw error; }
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const projectPath = relative(projectRoot, path).split('\\').join('/');
|
|
187
|
-
if (!allowedFiles.has(projectPath)) await rm(path, { force: true });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
await walk(root);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export async function canonicalSync(projectRoot, source) {
|
|
194
|
-
const current = await readInstalledState(projectRoot);
|
|
195
|
-
const { catalog, stack, projectType, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, { refresh: true, withCheckers: true });
|
|
196
|
-
const changed = [];
|
|
197
|
-
const allowedSkillFiles = new Set();
|
|
198
|
-
for (const entry of applicable) {
|
|
199
|
-
const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
|
|
200
|
-
for (const copy of prepared.manifest.copies ?? []) {
|
|
201
|
-
const target = String(copy.target ?? copy.path ?? '');
|
|
202
|
-
if (target.startsWith('.agents/skills/')) allowedSkillFiles.add(target);
|
|
203
|
-
}
|
|
204
|
-
const installed = current.installed[entry.id];
|
|
205
|
-
if (!installed) {
|
|
206
|
-
await installRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
|
|
207
|
-
changed.push({ id: entry.id, action: 'installed', version: entry.version });
|
|
208
|
-
} else {
|
|
209
|
-
const requiresContentSync =
|
|
210
|
-
installed.version !== entry.version ||
|
|
211
|
-
installed.contentHash !== entry.contentHash ||
|
|
212
|
-
(prepared.checkerPath && installed.check?.command?.[0] !== 'specdest-cache') ||
|
|
213
|
-
await missingProjectScaffold(projectRoot, prepared.manifest.copies);
|
|
214
|
-
if (requiresContentSync) {
|
|
215
|
-
await syncRule({ projectRoot, payloadRoot: source.cachedModulePath(entry.id, entry.version), manifest: prepared.manifest });
|
|
216
|
-
changed.push({ id: entry.id, action: 'updated', version: entry.version });
|
|
217
|
-
} else if (installed.revision !== entry.revision) {
|
|
218
|
-
await refreshInstalledRevision(projectRoot, entry.id, entry.revision);
|
|
219
|
-
changed.push({ id: entry.id, action: 'provenance-refreshed', version: entry.version });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
224
|
-
const removed = await cleanupCanonicalInstallState(projectRoot, catalog.entries ?? [], applicableIds);
|
|
225
|
-
await cleanupCanonicalSkillTree(projectRoot, allowedSkillFiles);
|
|
226
|
-
return { stack, projectType, applicable: applicable.length, changed, removed };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export async function canonicalCheck(projectRoot, source, options = {}) {
|
|
230
|
-
const current = await readInstalledState(projectRoot);
|
|
231
|
-
const { catalog, applicable, canonicalCheckRoot, checkerRuntimeRoot } = await canonicalContext(projectRoot, source, {
|
|
232
|
-
offline: false,
|
|
233
|
-
withCheckers: true,
|
|
234
|
-
refresh: options.refresh ?? false,
|
|
235
|
-
});
|
|
236
|
-
const byId = new Map(applicable.map((entry) => [entry.id, entry]));
|
|
237
|
-
const results = {};
|
|
238
|
-
const groups = new Map();
|
|
239
|
-
const executor = options.executor ?? execute;
|
|
240
|
-
const targetMode = options.mode ?? 'full';
|
|
241
|
-
let targetFiles = options.files ?? null;
|
|
242
|
-
if (targetMode === 'staged' && targetFiles === null) {
|
|
243
|
-
const staged = await executor('git', ['diff', '--cached', '--name-only', '-z', '--diff-filter=ACMR'], projectRoot);
|
|
244
|
-
if (staged.exitCode !== 0) throw new Error(staged.stderr || 'Unable to read staged files');
|
|
245
|
-
targetFiles = staged.stdout.split('\0').filter(Boolean);
|
|
246
|
-
}
|
|
247
|
-
const normalizedTargetFiles = (targetFiles ?? []).map((file) => String(file).replaceAll('\\', '/'));
|
|
248
|
-
let exitCode = 0;
|
|
249
|
-
for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
|
|
250
|
-
const entry = byId.get(id);
|
|
251
|
-
if (!entry || installed.kind !== 'rule') continue;
|
|
252
|
-
const prepared = await cachedManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
|
|
253
|
-
if (!prepared?.checkerPath) {
|
|
254
|
-
if ((entry.enforcement ?? 'guidance') === 'guidance') continue;
|
|
255
|
-
results[id] = { status: 'fail', exitCode: 1, stderr: 'Canonical checker unavailable for enforced installed rule.' };
|
|
256
|
-
exitCode = 1;
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
if (prepared.execution === 'manual') continue;
|
|
260
|
-
const baseKey = prepared.checkerKey ?? `path:${prepared.checkerPath}:${JSON.stringify(prepared.checkerArgs ?? [])}`;
|
|
261
|
-
const key = `${baseKey}:targeting:${prepared.targeting?.scope ?? 'repository'}:execution:${prepared.execution ?? 'automatic'}`;
|
|
262
|
-
const group = groups.get(key) ?? {
|
|
263
|
-
checkerPath: prepared.checkerPath,
|
|
264
|
-
checkerArgs: prepared.checkerArgs ?? [],
|
|
265
|
-
targeting: prepared.targeting ?? { scope: 'repository' },
|
|
266
|
-
ids: [],
|
|
267
|
-
};
|
|
268
|
-
group.ids.push(id);
|
|
269
|
-
groups.set(key, group);
|
|
270
|
-
}
|
|
271
|
-
const groupExecutions = await Promise.all(
|
|
272
|
-
[...groups.values()].map(async (group) => {
|
|
273
|
-
const args = [group.checkerPath, ...group.checkerArgs];
|
|
274
|
-
if (targetMode !== 'full' && group.targeting.scope !== 'repository') {
|
|
275
|
-
args.push('--target-mode', targetMode);
|
|
276
|
-
for (const file of normalizedTargetFiles) args.push('--target-file', file);
|
|
277
|
-
}
|
|
278
|
-
const execution = await executor('node', args, projectRoot);
|
|
279
|
-
return { group, execution };
|
|
280
|
-
}),
|
|
281
|
-
);
|
|
282
|
-
for (const { group, execution } of groupExecutions) {
|
|
283
|
-
const result = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
|
|
284
|
-
for (const id of group.ids) results[id] = result;
|
|
285
|
-
if (execution.exitCode !== 0) exitCode = 1;
|
|
286
|
-
}
|
|
287
|
-
const orderedResults = Object.fromEntries(
|
|
288
|
-
Object.entries(results).sort(([a], [b]) => a.localeCompare(b)),
|
|
289
|
-
);
|
|
290
|
-
if (targetMode === 'full') {
|
|
291
|
-
await writeChecksState(projectRoot, {
|
|
292
|
-
schemaVersion: 2,
|
|
293
|
-
checkedAt: new Date().toISOString(),
|
|
294
|
-
results: Object.fromEntries(Object.entries(orderedResults).map(([id, result]) => [id, { status: result.status }])),
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
return { exitCode, results: orderedResults };
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
function rulesFlags(args) {
|
|
302
|
-
const result = { json: false, ids: [], categories: [], failed: false };
|
|
303
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
304
|
-
const arg = args[index];
|
|
305
|
-
if (arg === '--json') result.json = true;
|
|
306
|
-
else if (arg === '--failed') result.failed = true;
|
|
307
|
-
else if (arg === '--id' && args[index + 1]) result.ids.push(args[++index]);
|
|
308
|
-
else if (arg === '--category' && args[index + 1]) result.categories.push(args[++index]);
|
|
309
|
-
else throw new Error(`Unknown option: ${arg}`);
|
|
310
|
-
}
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function aiMode(entry) {
|
|
315
|
-
if (entry.ai?.load) return entry.ai.load;
|
|
316
|
-
return 'failure-only';
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function ruleSummary(entry) {
|
|
320
|
-
if (entry.summary) return String(entry.summary).trim();
|
|
321
|
-
const content = String(entry.content ?? '').replace(/\r\n?/gu, '\n');
|
|
322
|
-
const intent = content.match(/(?:^|\n)## Intent\s*\n+([^#][\s\S]*?)(?=\n## |$)/u)?.[1]?.trim();
|
|
323
|
-
const source = intent || content
|
|
324
|
-
.split('\n')
|
|
325
|
-
.map((line) => line.trim())
|
|
326
|
-
.find((line) => line && !line.startsWith('#')) || entry.name || entry.id;
|
|
327
|
-
return source
|
|
328
|
-
.replace(/^\*\*Rule:\*\*\s*/u, '')
|
|
329
|
-
.replace(/\s+/gu, ' ')
|
|
330
|
-
.slice(0, 240)
|
|
331
|
-
.trim();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export function aiInstructionText() {
|
|
335
|
-
return [
|
|
336
|
-
'Specdest Devkit governs repository engineering rules.',
|
|
337
|
-
'Do not preload the full rule catalog.',
|
|
338
|
-
'Before changing code, use `specdest rules --category <category>` to discover compact relevant summaries, then `specdest rules --id <rule>` only for rules whose full guidance is needed.',
|
|
339
|
-
'Run the repository completion checks normally. If Devkit checks fail, use `specdest rules --failed` to load full guidance only for failed rules and fix the violation without weakening the rule.',
|
|
340
|
-
].join('\n');
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export async function canonicalRules(projectRoot, source, options = {}) {
|
|
344
|
-
const { stack, profile, applicable } = await canonicalContext(projectRoot, source);
|
|
345
|
-
let selected = applicable;
|
|
346
|
-
let detail = false;
|
|
347
|
-
if (options.ids?.length) {
|
|
348
|
-
const wanted = new Set(options.ids);
|
|
349
|
-
selected = selected.filter((entry) => wanted.has(entry.id));
|
|
350
|
-
detail = true;
|
|
351
|
-
} else if (options.categories?.length) {
|
|
352
|
-
const wanted = new Set(options.categories.map((value) => value.toLowerCase()));
|
|
353
|
-
selected = selected.filter((entry) => wanted.has(String(entry.category ?? '').toLowerCase()));
|
|
354
|
-
} else if (options.failed) {
|
|
355
|
-
const state = await readChecksState(projectRoot);
|
|
356
|
-
const failed = new Set(Object.entries(state.results ?? {}).filter(([, value]) => value.status === 'fail').map(([id]) => id));
|
|
357
|
-
selected = selected.filter((entry) => failed.has(entry.id));
|
|
358
|
-
detail = true;
|
|
359
|
-
} else {
|
|
360
|
-
selected = selected.filter((entry) => aiMode(entry) === 'always');
|
|
361
|
-
}
|
|
362
|
-
return {
|
|
363
|
-
stack,
|
|
364
|
-
profile,
|
|
365
|
-
detail,
|
|
366
|
-
rules: selected.map((entry) => ({
|
|
367
|
-
id: entry.id,
|
|
368
|
-
name: entry.name,
|
|
369
|
-
category: entry.category ?? null,
|
|
370
|
-
enforcement: entry.enforcement ?? 'guidance',
|
|
371
|
-
aiLoad: aiMode(entry),
|
|
372
|
-
summary: ruleSummary(entry),
|
|
373
|
-
composedOf: entry.composedOf ?? [],
|
|
374
|
-
...(detail ? { content: entry.content ?? '' } : {}),
|
|
375
|
-
})),
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export async function canonicalDoctor(projectRoot, source) {
|
|
380
|
-
const issues = [];
|
|
381
|
-
const stack = await resolveCanonicalStack(projectRoot);
|
|
382
|
-
if (!stack) issues.push('Unable to resolve a supported project stack.');
|
|
383
|
-
try { await source.catalog(); } catch (error) { issues.push(`Catalog unavailable: ${error.message}`); }
|
|
384
|
-
return { ok: issues.length === 0, stack, cacheRoot: source.cacheRoot, issues };
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
export function createCanonicalCommandHandlers(projectRoot = process.cwd(), options = {}) {
|
|
388
|
-
const source = options.source ?? createCanonicalSource(options);
|
|
389
|
-
return {
|
|
390
|
-
status: async (args, io) => {
|
|
391
|
-
const parsed = flags(args);
|
|
392
|
-
const result = await canonicalStatus(projectRoot, source, { refresh: parsed.refresh });
|
|
393
|
-
if (parsed.json) io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
394
|
-
else io.stdout.write(`Stack: ${result.stack ?? 'unknown'}\nApplicable: ${result.totals.applicable} Current: ${result.totals.current} Missing: ${result.totals.missing} Outdated: ${result.totals.outdated}\n`);
|
|
395
|
-
return result.totals.missing || result.totals.outdated ? 1 : 0;
|
|
396
|
-
},
|
|
397
|
-
sync: async (args, io) => {
|
|
398
|
-
if (args.length) { io.stderr.write('Usage: specdest sync\n'); return 2; }
|
|
399
|
-
const result = await canonicalSync(projectRoot, source);
|
|
400
|
-
io.stdout.write(`Synced ${result.applicable} applicable rules; ${result.changed.length} changed.\n`);
|
|
401
|
-
for (const item of result.changed) io.stdout.write(`${item.action.toUpperCase()} ${item.id}@${item.version}\n`);
|
|
402
|
-
return 0;
|
|
403
|
-
},
|
|
404
|
-
check: async (args, io) => {
|
|
405
|
-
let parsed;
|
|
406
|
-
try { parsed = checkFlags(args); }
|
|
407
|
-
catch (error) { io.stderr.write(`${error.message}\n`); return 2; }
|
|
408
|
-
const result = await canonicalCheck(projectRoot, source, parsed);
|
|
409
|
-
for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
|
|
410
|
-
return result.exitCode;
|
|
411
|
-
},
|
|
412
|
-
rules: async (args, io) => {
|
|
413
|
-
const parsed = rulesFlags(args);
|
|
414
|
-
const result = await canonicalRules(projectRoot, source, parsed);
|
|
415
|
-
if (parsed.json) io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
416
|
-
else {
|
|
417
|
-
for (const rule of result.rules) {
|
|
418
|
-
const body = result.detail ? rule.content.trim() : rule.summary;
|
|
419
|
-
const composition = rule.composedOf.length ? `\nComposed of: ${rule.composedOf.join(', ')}` : '';
|
|
420
|
-
io.stdout.write(`## ${rule.id} — ${rule.name}\n${body}${composition}\n\n`);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return 0;
|
|
424
|
-
},
|
|
425
|
-
'ai-instruction': async (args, io) => {
|
|
426
|
-
if (args.length) { io.stderr.write('Usage: specdest ai-instruction\n'); return 2; }
|
|
427
|
-
io.stdout.write(`${aiInstructionText()}\n`);
|
|
428
|
-
return 0;
|
|
429
|
-
},
|
|
430
|
-
doctor: async (args, io) => {
|
|
431
|
-
if (args.length) { io.stderr.write('Usage: specdest doctor\n'); return 2; }
|
|
432
|
-
const result = await canonicalDoctor(projectRoot, source);
|
|
433
|
-
io.stdout.write(`Cache: ${result.cacheRoot}\nStack: ${result.stack ?? 'unknown'}\n`);
|
|
434
|
-
for (const issue of result.issues) io.stderr.write(`FAIL ${issue}\n`);
|
|
435
|
-
return result.ok ? 0 : 1;
|
|
436
|
-
},
|
|
437
|
-
};
|
|
438
|
-
}
|
package/src/canonical-project.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { cp, mkdir, readFile, rm } from 'node:fs/promises';
|
|
2
|
-
import { basename, dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
function isSkillTarget(copy) {
|
|
5
|
-
return String(copy?.target ?? copy?.path ?? '').startsWith('.agents/skills/');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function isProjectScaffold(copy) {
|
|
9
|
-
return copy?.mode === 'scaffold' || copy?.mode === 'create-only';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function keepProjectCopy(copy) {
|
|
13
|
-
return !isSkillTarget(copy) || isProjectScaffold(copy);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function materializeCopies(manifest, sourceRoot, runtimeRoot) {
|
|
17
|
-
for (const copy of manifest?.copies ?? []) {
|
|
18
|
-
if (!isSkillTarget(copy) || isProjectScaffold(copy)) continue;
|
|
19
|
-
const source = join(sourceRoot, String(copy.source ?? ''));
|
|
20
|
-
const target = join(runtimeRoot, String(copy.target ?? copy.path ?? ''));
|
|
21
|
-
await mkdir(dirname(target), { recursive: true });
|
|
22
|
-
await cp(source, target, { recursive: copy.type === 'directory' || copy.directory === true, force: true });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function readManifest(root) {
|
|
27
|
-
return JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8'));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function cacheProjectCopies(copies, sourceRoot, ruleRoot, label) {
|
|
31
|
-
const result = [];
|
|
32
|
-
for (const copy of copies.filter(keepProjectCopy)) {
|
|
33
|
-
if (sourceRoot === ruleRoot) {
|
|
34
|
-
result.push(copy);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const source = String(copy.source ?? '');
|
|
38
|
-
const cachedSource = join('.project-scaffolds', label, source);
|
|
39
|
-
const target = join(ruleRoot, cachedSource);
|
|
40
|
-
await mkdir(dirname(target), { recursive: true });
|
|
41
|
-
await cp(join(sourceRoot, source), target, {
|
|
42
|
-
recursive: copy.type === 'directory' || copy.directory === true,
|
|
43
|
-
force: true,
|
|
44
|
-
});
|
|
45
|
-
result.push({ ...copy, source: cachedSource });
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function checkerPolicy(manifest) {
|
|
51
|
-
const scope = manifest?.targeting?.scope ?? 'repository';
|
|
52
|
-
if (!['file', 'related', 'repository'].includes(scope)) {
|
|
53
|
-
throw new Error(`Invalid checker targeting scope: ${scope}`);
|
|
54
|
-
}
|
|
55
|
-
const execution = manifest?.execution ?? 'automatic';
|
|
56
|
-
if (!['automatic', 'manual'].includes(execution)) {
|
|
57
|
-
throw new Error(`Invalid checker execution class: ${execution}`);
|
|
58
|
-
}
|
|
59
|
-
return { targeting: { scope }, execution };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function runtimeChecker(manifest, runtimeRoot) {
|
|
63
|
-
if (manifest?.check?.command?.[0] !== 'node') return null;
|
|
64
|
-
const target = String(manifest.check.command[1] ?? '');
|
|
65
|
-
if (!target.startsWith('.agents/skills/')) return null;
|
|
66
|
-
return {
|
|
67
|
-
path: join(runtimeRoot, target),
|
|
68
|
-
args: manifest.check.command.slice(2).map(String),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
import { projectRuleApplies } from './project-targeting.js';
|
|
73
|
-
|
|
74
|
-
export function applicableCatalogEntries(entries, stack, profile) {
|
|
75
|
-
return entries
|
|
76
|
-
.filter((entry) => entry.kind === 'rule')
|
|
77
|
-
.filter((entry) => projectRuleApplies(entry, stack, profile, entries))
|
|
78
|
-
.sort((a, b) => a.id.localeCompare(b.id));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function prepareCachedManifest(entry, ruleRoot, canonicalCheckRoot, checkerRuntimeRoot = null) {
|
|
82
|
-
const raw = await readManifest(ruleRoot);
|
|
83
|
-
const checkerKey = raw.checker?.path
|
|
84
|
-
? `canonical:${String(raw.checker.path)}`
|
|
85
|
-
: raw.check?.command
|
|
86
|
-
? `command:${JSON.stringify(raw.check.command)}`
|
|
87
|
-
: null;
|
|
88
|
-
const runtimeRoot = join(ruleRoot, '.runtime');
|
|
89
|
-
await rm(runtimeRoot, { recursive: true, force: true });
|
|
90
|
-
await mkdir(runtimeRoot, { recursive: true });
|
|
91
|
-
|
|
92
|
-
if (checkerRuntimeRoot) {
|
|
93
|
-
await materializeCopies(await readManifest(checkerRuntimeRoot), checkerRuntimeRoot, runtimeRoot);
|
|
94
|
-
}
|
|
95
|
-
await materializeCopies(raw, ruleRoot, runtimeRoot);
|
|
96
|
-
|
|
97
|
-
const copies = await cacheProjectCopies(raw.copies ?? [], ruleRoot, ruleRoot, entry.id);
|
|
98
|
-
let checker = runtimeChecker(raw, runtimeRoot);
|
|
99
|
-
let { targeting, execution } = checkerPolicy(raw);
|
|
100
|
-
if (!checker && raw.checker?.path && canonicalCheckRoot) {
|
|
101
|
-
const relative = String(raw.checker.path).replace(/^canonical-check\//u, '');
|
|
102
|
-
const implementationRoot = dirname(join(canonicalCheckRoot, relative));
|
|
103
|
-
const implementationManifest = await readManifest(implementationRoot);
|
|
104
|
-
({ targeting, execution } = checkerPolicy(implementationManifest));
|
|
105
|
-
await materializeCopies(implementationManifest, implementationRoot, runtimeRoot);
|
|
106
|
-
copies.push(...await cacheProjectCopies(
|
|
107
|
-
implementationManifest.copies ?? [],
|
|
108
|
-
implementationRoot,
|
|
109
|
-
ruleRoot,
|
|
110
|
-
basename(implementationRoot),
|
|
111
|
-
));
|
|
112
|
-
checker = runtimeChecker(implementationManifest, runtimeRoot);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const markdownSections = (raw.markdownSections ?? []).filter(
|
|
116
|
-
(section) => !String(section?.body ?? section?.content ?? '').includes('.agents/skills/'),
|
|
117
|
-
);
|
|
118
|
-
const manifest = {
|
|
119
|
-
...raw,
|
|
120
|
-
kind: raw.kind ?? entry.kind ?? 'rule',
|
|
121
|
-
version: entry.version ?? raw.version,
|
|
122
|
-
...(entry.contentHash ? { contentHash: entry.contentHash } : {}),
|
|
123
|
-
...(entry.revision ? { revision: entry.revision } : {}),
|
|
124
|
-
copies: [...new Map(copies.map((copy) => [String(copy.target ?? copy.path ?? copy.source), copy])).values()],
|
|
125
|
-
markdownSections,
|
|
126
|
-
...(checker ? { check: { command: ['specdest-cache', entry.id] } } : {}),
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
manifest,
|
|
130
|
-
checkerPath: checker?.path ?? null,
|
|
131
|
-
checkerArgs: checker?.args ?? [],
|
|
132
|
-
checkerKey,
|
|
133
|
-
targeting,
|
|
134
|
-
execution,
|
|
135
|
-
};
|
|
136
|
-
}
|