@specdest/devkit 0.4.6 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -20
- 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 +21 -0
- package/dist/npm/canonical-project.js +115 -0
- package/dist/npm/canonical-source.d.ts +26 -0
- package/dist/npm/canonical-source.js +248 -0
- package/dist/npm/catalog-snapshot.d.ts +53 -0
- package/dist/npm/catalog-snapshot.js +35 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +18 -0
- package/dist/npm/commands.d.ts +15 -0
- package/dist/npm/commands.js +182 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +430 -0
- package/dist/npm/git-catalog.d.ts +40 -0
- package/dist/npm/git-catalog.js +222 -0
- package/dist/npm/index.d.ts +4 -0
- package/dist/npm/index.js +32 -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 +88 -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 +12 -0
- package/dist/npm/predefined-packages/index.js +97 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +86 -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 +335 -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 +38 -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 +127 -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 +14 -0
- package/dist/npm/project-check.js +118 -0
- package/dist/npm/project-context.d.ts +52 -0
- package/dist/npm/project-context.js +206 -0
- package/dist/npm/project-rules.d.ts +25 -0
- package/dist/npm/project-rules.js +75 -0
- package/dist/npm/project-runtime.d.ts +21 -0
- package/dist/npm/project-runtime.js +41 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +70 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +143 -0
- package/dist/npm/remote-installer.d.ts +35 -0
- package/dist/npm/remote-installer.js +351 -0
- 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.d.ts +14 -0
- package/dist/npm/state.js +231 -0
- package/dist/npm/supabase-local.d.ts +2 -0
- package/dist/npm/supabase-local.js +62 -0
- package/package.json +18 -12
- 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,198 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname, isAbsolute, resolve, sep } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function resolveProjectPath(projectRoot, relativePath) {
|
|
5
|
-
if (!relativePath || isAbsolute(relativePath)) {
|
|
6
|
-
throw new Error(`Path must be project-relative: ${relativePath}`);
|
|
7
|
-
}
|
|
8
|
-
const root = resolve(projectRoot);
|
|
9
|
-
const target = resolve(root, relativePath);
|
|
10
|
-
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
11
|
-
throw new Error(`Path escapes project: ${relativePath}`);
|
|
12
|
-
}
|
|
13
|
-
return target;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function renderTemplate(value, parameters = {}) {
|
|
17
|
-
let result = String(value);
|
|
18
|
-
for (const [name, replacement] of Object.entries(parameters)) {
|
|
19
|
-
result = result.replaceAll(`{{${name}}}`, String(replacement ?? ''));
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function validateParameters(definitions = [], parameters = {}) {
|
|
25
|
-
const allowed = new Set(definitions.map((item) => String(item?.name ?? '')).filter(Boolean));
|
|
26
|
-
const unknown = Object.keys(parameters).filter((name) => !allowed.has(name)).sort();
|
|
27
|
-
if (unknown.length) throw new Error(`Unknown parameters: ${unknown.join(', ')}`);
|
|
28
|
-
|
|
29
|
-
const missing = definitions
|
|
30
|
-
.filter((item) => item?.required === true)
|
|
31
|
-
.map((item) => String(item.name))
|
|
32
|
-
.filter((name) => !String(parameters[name] ?? '').trim());
|
|
33
|
-
if (missing.length) throw new Error(`Missing parameters: ${missing.join(', ')}`);
|
|
34
|
-
return { ...parameters };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function readText(filePath) {
|
|
38
|
-
try {
|
|
39
|
-
return await readFile(filePath, 'utf8');
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (error?.code === 'ENOENT') return '';
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function fileExists(filePath) {
|
|
47
|
-
try {
|
|
48
|
-
await stat(filePath);
|
|
49
|
-
return true;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (error?.code === 'ENOENT') return false;
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function changeAction(exists, existing, updated) {
|
|
57
|
-
if (exists && existing === updated) return 'unchanged';
|
|
58
|
-
return exists ? 'update' : 'create';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function planFileContent(projectRoot, relativePath, replacement, options = {}) {
|
|
62
|
-
const target = resolveProjectPath(projectRoot, relativePath);
|
|
63
|
-
const exists = await fileExists(target);
|
|
64
|
-
const existing = exists ? await readText(target) : '';
|
|
65
|
-
if (exists && options.createOnly) {
|
|
66
|
-
return {
|
|
67
|
-
relativePath,
|
|
68
|
-
target,
|
|
69
|
-
action: 'unchanged',
|
|
70
|
-
replacement: existing,
|
|
71
|
-
reason: 'preserve-project-owned',
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
relativePath,
|
|
76
|
-
target,
|
|
77
|
-
action: changeAction(exists, existing, replacement),
|
|
78
|
-
replacement,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function applyFileOperation(operation) {
|
|
83
|
-
if (operation.action === 'unchanged') return;
|
|
84
|
-
if (!['create', 'update'].includes(operation.action)) {
|
|
85
|
-
throw new Error(`Unsupported file operation: ${operation.action}`);
|
|
86
|
-
}
|
|
87
|
-
await mkdir(dirname(operation.target), { recursive: true });
|
|
88
|
-
await writeFile(operation.target, operation.replacement, 'utf8');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function markdownSectionBounds(existing, heading) {
|
|
92
|
-
const trimmed = heading.trim();
|
|
93
|
-
const level = trimmed.match(/^(#{1,6})\s+/)?.[1].length ?? 2;
|
|
94
|
-
const lines = existing.split(/(?<=\n)/);
|
|
95
|
-
let offset = 0;
|
|
96
|
-
let start = -1;
|
|
97
|
-
let end = existing.length;
|
|
98
|
-
for (const line of lines) {
|
|
99
|
-
if (start < 0 && line.trim() === trimmed) start = offset;
|
|
100
|
-
else if (start >= 0 && new RegExp(`^#{1,${level}}\\s+`).test(line.trim())) {
|
|
101
|
-
end = offset;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
offset += line.length;
|
|
105
|
-
}
|
|
106
|
-
return start >= 0 ? [start, end] : null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function upsertMarkdownSection(existing, heading, body) {
|
|
110
|
-
const block = `${heading.trim()}\n\n${body.trim()}\n`;
|
|
111
|
-
const bounds = markdownSectionBounds(existing, heading);
|
|
112
|
-
if (!bounds) return `${existing.trimEnd()}${existing.trim() ? '\n\n' : ''}${block}`;
|
|
113
|
-
const [start, end] = bounds;
|
|
114
|
-
const before = existing.slice(0, start).trimEnd();
|
|
115
|
-
const after = existing.slice(end).trim();
|
|
116
|
-
return `${[before, block.trimEnd(), after].filter(Boolean).join('\n\n')}\n`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function normalizeTextLines(text) {
|
|
120
|
-
return text.replace(/\r\n/g, '\n').split('\n');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function finishLineFile(lines) {
|
|
124
|
-
const trimmed = [...lines];
|
|
125
|
-
while (trimmed.length && !trimmed[trimmed.length - 1]?.trim()) trimmed.pop();
|
|
126
|
-
return trimmed.length ? `${trimmed.join('\n')}\n` : '';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function upsertExactLines(existing, lines) {
|
|
130
|
-
const entries = lines.map((line) => String(line).trim()).filter(Boolean);
|
|
131
|
-
const existingLines = normalizeTextLines(existing);
|
|
132
|
-
if (
|
|
133
|
-
entries.every(
|
|
134
|
-
(entry) => existingLines.filter((line) => line.trim() === entry).length === 1,
|
|
135
|
-
)
|
|
136
|
-
) {
|
|
137
|
-
return existing;
|
|
138
|
-
}
|
|
139
|
-
const remove = new Set(entries);
|
|
140
|
-
const kept = existingLines.filter((line) => !remove.has(line.trim()));
|
|
141
|
-
while (kept.length && !kept[kept.length - 1]?.trim()) kept.pop();
|
|
142
|
-
if (kept.length && entries.length) kept.push('');
|
|
143
|
-
kept.push(...entries);
|
|
144
|
-
return finishLineFile(kept);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function removeExactLines(existing, lines) {
|
|
148
|
-
const remove = new Set(lines.map((line) => String(line).trim()).filter(Boolean));
|
|
149
|
-
return finishLineFile(normalizeTextLines(existing).filter((line) => !remove.has(line.trim())));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function upsertKeyValueLines(existing, entries, separator = '=') {
|
|
153
|
-
const keys = new Set(Object.keys(entries));
|
|
154
|
-
const existingLines = normalizeTextLines(existing);
|
|
155
|
-
const exact = [...keys].every((key) => {
|
|
156
|
-
const matches = existingLines.filter((line) => {
|
|
157
|
-
const trimmed = line.trim();
|
|
158
|
-
if (!trimmed || trimmed.startsWith('#')) return false;
|
|
159
|
-
const index = trimmed.indexOf(separator);
|
|
160
|
-
return index >= 0 && trimmed.slice(0, index).trim() === key;
|
|
161
|
-
});
|
|
162
|
-
return matches.length === 1 && matches[0].trim() === `${key}${separator}${String(entries[key] ?? '')}`;
|
|
163
|
-
});
|
|
164
|
-
if (exact) return existing;
|
|
165
|
-
const kept = existingLines.filter((line) => {
|
|
166
|
-
const trimmed = line.trim();
|
|
167
|
-
if (!trimmed || trimmed.startsWith('#')) return true;
|
|
168
|
-
const index = trimmed.indexOf(separator);
|
|
169
|
-
return index < 0 || !keys.has(trimmed.slice(0, index).trim());
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
while (kept.length && !kept[kept.length - 1]?.trim()) kept.pop();
|
|
173
|
-
if (kept.length && keys.size) kept.push('');
|
|
174
|
-
for (const [key, value] of Object.entries(entries)) {
|
|
175
|
-
kept.push(`${key}${separator}${value}`);
|
|
176
|
-
}
|
|
177
|
-
return finishLineFile(kept);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function removeMarkdownSection(existing, heading) {
|
|
181
|
-
const bounds = markdownSectionBounds(existing, heading);
|
|
182
|
-
if (!bounds) return existing;
|
|
183
|
-
const [start, end] = bounds;
|
|
184
|
-
const updated = `${existing.slice(0, start).trimEnd()}\n\n${existing.slice(end).trimStart()}`
|
|
185
|
-
.replace(/\n{3,}/g, '\n\n')
|
|
186
|
-
.trimEnd();
|
|
187
|
-
return updated ? `${updated}\n` : '';
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function removeKeyValueLines(existing, keys, separator = '=') {
|
|
191
|
-
const remove = new Set(keys.map((key) => String(key).trim()).filter(Boolean));
|
|
192
|
-
return finishLineFile(normalizeTextLines(existing).filter((line) => {
|
|
193
|
-
const trimmed = line.trim();
|
|
194
|
-
if (!trimmed || trimmed.startsWith('#')) return true;
|
|
195
|
-
const index = trimmed.indexOf(separator);
|
|
196
|
-
return index < 0 || !remove.has(trimmed.slice(0, index).trim());
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { readdir } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { listCatalogEntries, loadCatalogEntry, resolveCatalogSelection } from './catalog.js';
|
|
6
|
-
import { evaluateSetupRequirements } from './setup-requirements.js';
|
|
7
|
-
import {
|
|
8
|
-
applySyncPlan,
|
|
9
|
-
previewSync,
|
|
10
|
-
inferRequestedRoots,
|
|
11
|
-
readInstalledState,
|
|
12
|
-
writeChecksState,
|
|
13
|
-
} from './sync-core.js';
|
|
14
|
-
|
|
15
|
-
function defaultExecutor({ command, args, cwd }) {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
18
|
-
let stdout = '';
|
|
19
|
-
let stderr = '';
|
|
20
|
-
child.stdout.setEncoding('utf8');
|
|
21
|
-
child.stderr.setEncoding('utf8');
|
|
22
|
-
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
23
|
-
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
24
|
-
child.on('error', reject);
|
|
25
|
-
child.on('close', (code) => resolve({ exitCode: code ?? 1, stdout, stderr }));
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function hydrateInstalledCheckMetadata(installed, options = {}) {
|
|
30
|
-
const catalogIds = new Set((await listCatalogEntries(options)).map((entry) => entry.id));
|
|
31
|
-
const hydrated = {};
|
|
32
|
-
for (const [id, entry] of Object.entries(installed)) {
|
|
33
|
-
if (entry.check || !catalogIds.has(id)) {
|
|
34
|
-
hydrated[id] = entry;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const catalogEntry = await loadCatalogEntry(id, options);
|
|
38
|
-
hydrated[id] = catalogEntry.check ? { ...entry, check: catalogEntry.check } : entry;
|
|
39
|
-
}
|
|
40
|
-
return hydrated;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function auditSkillOwnership(projectRoot, installed) {
|
|
44
|
-
const allowedDirectories = new Set();
|
|
45
|
-
if (installed['checker-runtime']) allowedDirectories.add('shared');
|
|
46
|
-
|
|
47
|
-
for (const [id, entry] of Object.entries(installed)) {
|
|
48
|
-
allowedDirectories.add(id);
|
|
49
|
-
for (const suffix of ['-supabase', '-convex', '-expo']) {
|
|
50
|
-
if (id.endsWith(suffix)) allowedDirectories.add(id.slice(0, -suffix.length));
|
|
51
|
-
}
|
|
52
|
-
for (const value of entry.check?.command ?? []) {
|
|
53
|
-
const match = String(value).match(/^\.agents\/skills\/([^/]+)\//u);
|
|
54
|
-
if (match?.[1]) allowedDirectories.add(match[1]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let entries;
|
|
59
|
-
try {
|
|
60
|
-
entries = await readdir(join(projectRoot, '.agents', 'skills'), { withFileTypes: true });
|
|
61
|
-
} catch (error) {
|
|
62
|
-
if (error?.code === 'ENOENT') return { unownedSkillDirectories: [] };
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
const actualDirectories = entries
|
|
66
|
-
.filter((entry) => entry.isDirectory())
|
|
67
|
-
.map((entry) => entry.name)
|
|
68
|
-
.sort();
|
|
69
|
-
return {
|
|
70
|
-
unownedSkillDirectories: actualDirectories.filter(
|
|
71
|
-
(directory) => !allowedDirectories.has(directory),
|
|
72
|
-
),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export async function installCatalogEntry(projectRoot, id, options = {}) {
|
|
77
|
-
const current = await readInstalledState(projectRoot);
|
|
78
|
-
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
79
|
-
const currentRequested = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
80
|
-
if (currentRequested.includes(id)) throw new Error(`${id} is already requested; use specdest sync`);
|
|
81
|
-
const requestedIds = [...new Set([...currentRequested, id])].sort();
|
|
82
|
-
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
83
|
-
const desiredIds = entries.map((entry) => entry.id);
|
|
84
|
-
const desiredSet = new Set(desiredIds);
|
|
85
|
-
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
86
|
-
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
87
|
-
await applySyncPlan(plan);
|
|
88
|
-
return plan;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function syncInstalledCatalog(projectRoot, options = {}) {
|
|
92
|
-
const current = await readInstalledState(projectRoot);
|
|
93
|
-
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
94
|
-
const requestedIds = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
95
|
-
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
96
|
-
const desiredIds = entries.map((entry) => entry.id);
|
|
97
|
-
const desiredSet = new Set(desiredIds);
|
|
98
|
-
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
99
|
-
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
100
|
-
await applySyncPlan(plan);
|
|
101
|
-
return plan;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function getProjectStatus(projectRoot, options = {}) {
|
|
105
|
-
const current = await readInstalledState(projectRoot);
|
|
106
|
-
const entries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
107
|
-
return {
|
|
108
|
-
...current,
|
|
109
|
-
setup: await evaluateSetupRequirements(projectRoot, entries, options),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function runInstalledChecks(projectRoot, options = {}) {
|
|
114
|
-
const current = await readInstalledState(projectRoot);
|
|
115
|
-
const installed = await hydrateInstalledCheckMetadata(current.installed, options);
|
|
116
|
-
const executor = options.executor ?? defaultExecutor;
|
|
117
|
-
const results = {};
|
|
118
|
-
const integrity = await auditSkillOwnership(projectRoot, installed);
|
|
119
|
-
let exitCode = integrity.unownedSkillDirectories.length ? 1 : 0;
|
|
120
|
-
|
|
121
|
-
const installedEntries = Object.entries(installed).sort(([left], [right]) =>
|
|
122
|
-
left.localeCompare(right),
|
|
123
|
-
);
|
|
124
|
-
for (const [id, entry] of installedEntries) {
|
|
125
|
-
if (entry.kind !== 'rule' || !entry.check) continue;
|
|
126
|
-
const [command, ...args] = entry.check.command;
|
|
127
|
-
const execution = await executor({ command, args, cwd: projectRoot });
|
|
128
|
-
const status = execution.exitCode === 0 ? 'pass' : 'fail';
|
|
129
|
-
if (execution.exitCode !== 0) exitCode = 1;
|
|
130
|
-
results[id] = {
|
|
131
|
-
status,
|
|
132
|
-
exitCode: execution.exitCode,
|
|
133
|
-
stdout: execution.stdout ?? '',
|
|
134
|
-
stderr: execution.stderr ?? '',
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const persistedResults = Object.fromEntries(
|
|
139
|
-
Object.entries(results).map(([id, result]) => [id, { status: result.status }]),
|
|
140
|
-
);
|
|
141
|
-
await writeChecksState(projectRoot, { schemaVersion: 2, results: persistedResults });
|
|
142
|
-
return { exitCode, results, integrity };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function createProjectCommandHandlers(projectRoot = process.cwd()) {
|
|
146
|
-
return {
|
|
147
|
-
install: async (args, io) => {
|
|
148
|
-
if (args.length !== 1) {
|
|
149
|
-
io.stderr.write('Usage: specdest install <rule-or-module>\n');
|
|
150
|
-
return 2;
|
|
151
|
-
}
|
|
152
|
-
const plan = await installCatalogEntry(projectRoot, args[0]);
|
|
153
|
-
io.stdout.write(`Installed ${args[0]} (${plan.operations.filter((op) => op.action !== 'unchanged').length} changes).\n`);
|
|
154
|
-
return 0;
|
|
155
|
-
},
|
|
156
|
-
status: async (args, io) => {
|
|
157
|
-
if (args.length) {
|
|
158
|
-
io.stderr.write('Usage: specdest status\n');
|
|
159
|
-
return 2;
|
|
160
|
-
}
|
|
161
|
-
io.stdout.write(`${JSON.stringify(await getProjectStatus(projectRoot), null, 2)}\n`);
|
|
162
|
-
return 0;
|
|
163
|
-
},
|
|
164
|
-
sync: async (args, io) => {
|
|
165
|
-
if (args.length) {
|
|
166
|
-
io.stderr.write('Usage: specdest sync\n');
|
|
167
|
-
return 2;
|
|
168
|
-
}
|
|
169
|
-
const plan = await syncInstalledCatalog(projectRoot);
|
|
170
|
-
io.stdout.write(`Synced ${Object.keys(plan.nextState.installed).length} installed items.\n`);
|
|
171
|
-
return 0;
|
|
172
|
-
},
|
|
173
|
-
check: async (args, io) => {
|
|
174
|
-
if (args.length) {
|
|
175
|
-
io.stderr.write('Usage: specdest check\n');
|
|
176
|
-
return 2;
|
|
177
|
-
}
|
|
178
|
-
const result = await runInstalledChecks(projectRoot);
|
|
179
|
-
for (const [id, check] of Object.entries(result.results)) io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
|
|
180
|
-
if (result.integrity.unownedSkillDirectories.length) {
|
|
181
|
-
io.stderr.write('FAIL devkit-skill-ownership: unowned directories found under .agents/skills; move project-only enforcement to .agents/project-skills\n');
|
|
182
|
-
for (const directory of result.integrity.unownedSkillDirectories) {
|
|
183
|
-
io.stderr.write(`- .agents/skills/${directory}\n`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return result.exitCode;
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
}
|
package/src/project-targeting.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { EMPTY_RULE_PROFILE } from './rule-profile.js';
|
|
2
|
-
|
|
3
|
-
export const PROJECT_TYPES = Object.freeze([
|
|
4
|
-
'product',
|
|
5
|
-
'static-site',
|
|
6
|
-
'tooling',
|
|
7
|
-
'backend',
|
|
8
|
-
'monorepo',
|
|
9
|
-
'generic',
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
|
-
export function resolveProjectType(stack, profile = EMPTY_RULE_PROFILE) {
|
|
13
|
-
return profile.projectType ?? (stack ? 'product' : 'generic');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function profileDefinition(entries, projectType) {
|
|
17
|
-
if (projectType === 'product') return null;
|
|
18
|
-
const module = entries.find(
|
|
19
|
-
(entry) => entry.kind === 'module' && entry.id === 'project-profiles',
|
|
20
|
-
);
|
|
21
|
-
const definition = module?.projectProfiles?.[projectType];
|
|
22
|
-
if (!definition) throw new Error(`Canonical project profile not found: ${projectType}`);
|
|
23
|
-
return definition;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function capabilitySatisfied(entry, profile) {
|
|
27
|
-
const capabilities = new Set(profile.capabilities ?? []);
|
|
28
|
-
return !entry.requiredCapabilities?.some((capability) => !capabilities.has(capability));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function projectRuleApplies(entry, stack, profile = EMPTY_RULE_PROFILE, entries = []) {
|
|
32
|
-
const included = new Set(profile.include ?? []);
|
|
33
|
-
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
34
|
-
if (excluded.has(entry.id)) return false;
|
|
35
|
-
if (included.has(entry.id)) return true;
|
|
36
|
-
|
|
37
|
-
const projectType = resolveProjectType(stack, profile);
|
|
38
|
-
if (projectType === 'product') {
|
|
39
|
-
if (entry.applicableStacks?.length && (!stack || !entry.applicableStacks.includes(stack))) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
return capabilitySatisfied(entry, profile);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const definition = profileDefinition(entries, projectType);
|
|
46
|
-
if (!definition.ruleIds.includes(entry.id)) return false;
|
|
47
|
-
return capabilitySatisfied(entry, profile);
|
|
48
|
-
}
|