@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
|
@@ -0,0 +1,75 @@
|
|
|
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 ||
|
|
13
|
+
content
|
|
14
|
+
.split('\n')
|
|
15
|
+
.map((line) => line.trim())
|
|
16
|
+
.find((line) => line && !line.startsWith('#')) ||
|
|
17
|
+
entry.name ||
|
|
18
|
+
entry.id;
|
|
19
|
+
return source
|
|
20
|
+
.replace(/^\*\*Rule:\*\*\s*/u, '')
|
|
21
|
+
.replace(/\s+/gu, ' ')
|
|
22
|
+
.slice(0, 240)
|
|
23
|
+
.trim();
|
|
24
|
+
}
|
|
25
|
+
export function aiInstructionText() {
|
|
26
|
+
return [
|
|
27
|
+
'Specdest Devkit governs repository engineering rules and deterministic development flow.',
|
|
28
|
+
'Before repository work, inspect persisted Flow state with `npx @specdest/devkit flow status`. Do not infer persisted Flow state from chat history.',
|
|
29
|
+
'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.',
|
|
30
|
+
'Do not preload the full rule catalog.',
|
|
31
|
+
'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.',
|
|
32
|
+
'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.',
|
|
33
|
+
].join('\n');
|
|
34
|
+
}
|
|
35
|
+
export async function canonicalRules(projectRoot, source, options = {}) {
|
|
36
|
+
await assertPredefinedPackageState(projectRoot);
|
|
37
|
+
const { stack, profile, applicable } = await loadCanonicalProjectContext(projectRoot, source);
|
|
38
|
+
let selected = applicable;
|
|
39
|
+
let detail = false;
|
|
40
|
+
if (options.ids?.length) {
|
|
41
|
+
const wanted = new Set(options.ids);
|
|
42
|
+
selected = selected.filter((entry) => wanted.has(entry.id));
|
|
43
|
+
detail = true;
|
|
44
|
+
}
|
|
45
|
+
else if (options.categories?.length) {
|
|
46
|
+
const wanted = new Set(options.categories.map((value) => value.toLowerCase()));
|
|
47
|
+
selected = selected.filter((entry) => wanted.has(String(entry.category ?? '').toLowerCase()));
|
|
48
|
+
}
|
|
49
|
+
else if (options.failed) {
|
|
50
|
+
const state = await readChecksState(projectRoot);
|
|
51
|
+
const failed = new Set(Object.entries(state.results ?? {})
|
|
52
|
+
.filter(([, value]) => value.status === 'fail')
|
|
53
|
+
.map(([id]) => id));
|
|
54
|
+
selected = selected.filter((entry) => failed.has(entry.id));
|
|
55
|
+
detail = true;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
selected = selected.filter((entry) => aiMode(entry) === 'always');
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
stack,
|
|
62
|
+
profile,
|
|
63
|
+
detail,
|
|
64
|
+
rules: selected.map((entry) => ({
|
|
65
|
+
id: entry.id,
|
|
66
|
+
name: entry.name,
|
|
67
|
+
category: entry.category ?? null,
|
|
68
|
+
enforcement: entry.enforcement ?? 'guidance',
|
|
69
|
+
aiLoad: aiMode(entry),
|
|
70
|
+
summary: ruleSummary(entry),
|
|
71
|
+
composedOf: entry.composedOf ?? [],
|
|
72
|
+
...(detail ? { content: entry.content ?? '' } : {}),
|
|
73
|
+
})),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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: {
|
|
14
|
+
id: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
applicable: any[];
|
|
19
|
+
canonicalCheckRoot: any;
|
|
20
|
+
checkerRuntimeRoot: any;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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 ||
|
|
18
|
+
(await source.hasModule(canonicalCheck.id, canonicalCheck.version, canonicalCheck.contentHash))) {
|
|
19
|
+
canonicalCheckRoot = await source.module(canonicalCheck.id, canonicalCheck.version, {
|
|
20
|
+
contentHash: canonicalCheck.contentHash,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (options.withCheckers && checkerRuntime) {
|
|
25
|
+
if (!options.offline ||
|
|
26
|
+
(await source.hasModule(checkerRuntime.id, checkerRuntime.version, checkerRuntime.contentHash))) {
|
|
27
|
+
checkerRuntimeRoot = await source.module(checkerRuntime.id, checkerRuntime.version, {
|
|
28
|
+
contentHash: checkerRuntime.contentHash,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
catalog,
|
|
34
|
+
stack,
|
|
35
|
+
projectType,
|
|
36
|
+
profile,
|
|
37
|
+
applicable,
|
|
38
|
+
canonicalCheckRoot,
|
|
39
|
+
checkerRuntimeRoot,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -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,70 @@
|
|
|
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 {
|
|
14
|
+
id: entry.id,
|
|
15
|
+
canonicalVersion: entry.version,
|
|
16
|
+
installedVersion: found?.version ?? null,
|
|
17
|
+
state,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
21
|
+
const packages = Object.entries(installed)
|
|
22
|
+
.filter(([, value]) => value?.kind === 'package')
|
|
23
|
+
.map(([id, value]) => ({
|
|
24
|
+
id,
|
|
25
|
+
recipeVersion: value.recipeVersion ?? null,
|
|
26
|
+
detectedVersion: value.detectedVersion ?? value.version ?? null,
|
|
27
|
+
role: value.role ?? null,
|
|
28
|
+
source: value.source ?? null,
|
|
29
|
+
resolvedVariant: value.resolvedVariant ?? null,
|
|
30
|
+
}))
|
|
31
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
32
|
+
const installedNonApplicable = Object.keys(installed)
|
|
33
|
+
.filter((id) => !applicableIds.has(id) && installed[id]?.kind !== 'package')
|
|
34
|
+
.sort();
|
|
35
|
+
return {
|
|
36
|
+
stack,
|
|
37
|
+
projectType,
|
|
38
|
+
totals: {
|
|
39
|
+
applicable: rows.length,
|
|
40
|
+
current: rows.filter((row) => row.state === 'current').length,
|
|
41
|
+
missing: rows.filter((row) => row.state === 'missing').length,
|
|
42
|
+
outdated: rows.filter((row) => row.state === 'outdated').length,
|
|
43
|
+
},
|
|
44
|
+
rows,
|
|
45
|
+
packages,
|
|
46
|
+
packageIssues: packageHealth.issues,
|
|
47
|
+
installedNonApplicable,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export async function canonicalDoctor(projectRoot, source) {
|
|
51
|
+
const issues = [];
|
|
52
|
+
let stack = null;
|
|
53
|
+
try {
|
|
54
|
+
stack = await resolveProjectStack(projectRoot);
|
|
55
|
+
if (!stack)
|
|
56
|
+
issues.push('Unable to resolve a supported project stack.');
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
issues.push(error.message);
|
|
60
|
+
}
|
|
61
|
+
const packageHealth = await inspectPredefinedPackageState(projectRoot);
|
|
62
|
+
issues.push(...packageHealth.issues);
|
|
63
|
+
try {
|
|
64
|
+
await source.catalog();
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
issues.push(`Catalog unavailable: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
return { ok: issues.length === 0, stack, cacheRoot: source.cacheRoot, issues };
|
|
70
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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({
|
|
114
|
+
projectRoot,
|
|
115
|
+
payloadRoot: source.cachedModulePath(entry.id, entry.version),
|
|
116
|
+
manifest: prepared.manifest,
|
|
117
|
+
});
|
|
118
|
+
changed.push({ id: entry.id, action: 'installed', version: entry.version });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const requiresContentSync = installed.version !== entry.version ||
|
|
122
|
+
installed.contentHash !== entry.contentHash ||
|
|
123
|
+
(prepared.checkerPath && installed.check?.command?.[0] !== 'specdest-cache') ||
|
|
124
|
+
(await missingProjectScaffold(projectRoot, prepared.manifest.copies));
|
|
125
|
+
if (requiresContentSync) {
|
|
126
|
+
await syncRule({
|
|
127
|
+
projectRoot,
|
|
128
|
+
payloadRoot: source.cachedModulePath(entry.id, entry.version),
|
|
129
|
+
manifest: prepared.manifest,
|
|
130
|
+
});
|
|
131
|
+
changed.push({ id: entry.id, action: 'updated', version: entry.version });
|
|
132
|
+
}
|
|
133
|
+
else if (installed.revision !== entry.revision) {
|
|
134
|
+
await refreshInstalledRevision(projectRoot, entry.id, entry.revision);
|
|
135
|
+
changed.push({ id: entry.id, action: 'provenance-refreshed', version: entry.version });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const applicableIds = new Set(applicable.map((entry) => entry.id));
|
|
140
|
+
const removed = await cleanupCanonicalInstallState(projectRoot, catalog.entries ?? [], applicableIds);
|
|
141
|
+
await cleanupCanonicalSkillTree(projectRoot, allowedSkillFiles);
|
|
142
|
+
return { stack, projectType, applicable: applicable.length, changed, removed };
|
|
143
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type CanonicalManifest } from './schemas.ts';
|
|
2
|
+
type ManagedFileOperation = {
|
|
3
|
+
type: 'copy_file';
|
|
4
|
+
path: string;
|
|
5
|
+
source: string;
|
|
6
|
+
};
|
|
7
|
+
type ScaffoldOperation = {
|
|
8
|
+
type: 'scaffold_file';
|
|
9
|
+
path: string;
|
|
10
|
+
source: string;
|
|
11
|
+
};
|
|
12
|
+
type ManagedSectionOperation = {
|
|
13
|
+
type: 'managed_section';
|
|
14
|
+
path: string;
|
|
15
|
+
heading: string;
|
|
16
|
+
content?: unknown;
|
|
17
|
+
};
|
|
18
|
+
type Operation = ManagedFileOperation | ScaffoldOperation | ManagedSectionOperation;
|
|
19
|
+
type RemoteManifest = CanonicalManifest & {
|
|
20
|
+
operations: Operation[];
|
|
21
|
+
kind?: string;
|
|
22
|
+
revision?: string;
|
|
23
|
+
contentHash?: string;
|
|
24
|
+
check?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
type ReconcileOptions = {
|
|
27
|
+
projectRoot: string;
|
|
28
|
+
payloadRoot: string;
|
|
29
|
+
manifest: unknown;
|
|
30
|
+
};
|
|
31
|
+
export declare function validateRemoteManifest(input: unknown): RemoteManifest;
|
|
32
|
+
export declare function installRule(options: ReconcileOptions): Promise<any>;
|
|
33
|
+
export declare function syncRule(options: ReconcileOptions): Promise<any>;
|
|
34
|
+
export declare function removeRule(options: ReconcileOptions): Promise<any>;
|
|
35
|
+
export {};
|