@specdest/devkit 0.4.18 → 0.4.20
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 +107 -28
- package/dist/npm/cli.js +16 -24
- package/dist/npm/index.js +5 -1
- package/dist/npm/native/specdest-darwin-arm64 +0 -0
- package/dist/npm/native/specdest-darwin-x64 +0 -0
- package/dist/npm/native/specdest-linux-arm64 +0 -0
- package/dist/npm/native/specdest-linux-x64 +0 -0
- package/package.json +8 -5
- package/dist/npm/automation-policy.d.ts +0 -2
- package/dist/npm/automation-policy.js +0 -30
- package/dist/npm/canonical-project-operations.d.ts +0 -5
- package/dist/npm/canonical-project-operations.js +0 -5
- package/dist/npm/canonical-project.d.ts +0 -21
- package/dist/npm/canonical-project.js +0 -115
- package/dist/npm/catalog-snapshot.d.ts +0 -53
- package/dist/npm/catalog-snapshot.js +0 -35
- package/dist/npm/client-only-boundary.d.ts +0 -1
- package/dist/npm/client-only-boundary.js +0 -29
- package/dist/npm/commands.d.ts +0 -15
- package/dist/npm/commands.js +0 -188
- package/dist/npm/git-catalog.d.ts +0 -40
- package/dist/npm/git-catalog.js +0 -222
- package/dist/npm/host-automation.d.ts +0 -9
- package/dist/npm/host-automation.js +0 -66
- package/dist/npm/installer-primitives.d.ts +0 -3
- package/dist/npm/installer-primitives.js +0 -50
- package/dist/npm/predefined-packages/abac.d.ts +0 -2
- package/dist/npm/predefined-packages/abac.js +0 -22
- package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +0 -46
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +0 -49
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +0 -15
- package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +0 -17
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +0 -16
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +0 -18
- package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +0 -22
- package/dist/npm/predefined-packages/admin-ui.d.ts +0 -2
- package/dist/npm/predefined-packages/admin-ui.js +0 -79
- package/dist/npm/predefined-packages/auth.d.ts +0 -2
- package/dist/npm/predefined-packages/auth.js +0 -21
- package/dist/npm/predefined-packages/convex.d.ts +0 -2
- package/dist/npm/predefined-packages/convex.js +0 -53
- package/dist/npm/predefined-packages/expo.d.ts +0 -2
- package/dist/npm/predefined-packages/expo.js +0 -88
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +0 -2
- package/dist/npm/predefined-packages/firebase-hosting.js +0 -24
- package/dist/npm/predefined-packages/health.d.ts +0 -10
- package/dist/npm/predefined-packages/health.js +0 -52
- package/dist/npm/predefined-packages/husky.d.ts +0 -2
- package/dist/npm/predefined-packages/husky.js +0 -57
- package/dist/npm/predefined-packages/index.d.ts +0 -12
- package/dist/npm/predefined-packages/index.js +0 -97
- package/dist/npm/predefined-packages/install.d.ts +0 -19
- package/dist/npm/predefined-packages/install.js +0 -86
- package/dist/npm/predefined-packages/local-logging.d.ts +0 -2
- package/dist/npm/predefined-packages/local-logging.js +0 -17
- package/dist/npm/predefined-packages/logging.d.ts +0 -2
- package/dist/npm/predefined-packages/logging.js +0 -21
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +0 -2
- package/dist/npm/predefined-packages/multi-tenancy.js +0 -21
- package/dist/npm/predefined-packages/nps.d.ts +0 -2
- package/dist/npm/predefined-packages/nps.js +0 -32
- package/dist/npm/predefined-packages/oxfmt.d.ts +0 -2
- package/dist/npm/predefined-packages/oxfmt.js +0 -22
- package/dist/npm/predefined-packages/oxlint.d.ts +0 -2
- package/dist/npm/predefined-packages/oxlint.js +0 -35
- package/dist/npm/predefined-packages/package-json.d.ts +0 -3
- package/dist/npm/predefined-packages/package-json.js +0 -61
- package/dist/npm/predefined-packages/payments.d.ts +0 -2
- package/dist/npm/predefined-packages/payments.js +0 -31
- package/dist/npm/predefined-packages/playwright.d.ts +0 -2
- package/dist/npm/predefined-packages/playwright.js +0 -35
- package/dist/npm/predefined-packages/project-signals.d.ts +0 -4
- package/dist/npm/predefined-packages/project-signals.js +0 -39
- package/dist/npm/predefined-packages/registry.d.ts +0 -3
- package/dist/npm/predefined-packages/registry.js +0 -65
- package/dist/npm/predefined-packages/resolver.d.ts +0 -8
- package/dist/npm/predefined-packages/resolver.js +0 -35
- package/dist/npm/predefined-packages/sentry.d.ts +0 -2
- package/dist/npm/predefined-packages/sentry.js +0 -29
- package/dist/npm/predefined-packages/shadcn.d.ts +0 -2
- package/dist/npm/predefined-packages/shadcn.js +0 -23
- package/dist/npm/predefined-packages/storybook.d.ts +0 -2
- package/dist/npm/predefined-packages/storybook.js +0 -25
- package/dist/npm/predefined-packages/stryker.d.ts +0 -2
- package/dist/npm/predefined-packages/stryker.js +0 -48
- package/dist/npm/predefined-packages/supabase.d.ts +0 -2
- package/dist/npm/predefined-packages/supabase.js +0 -355
- package/dist/npm/predefined-packages/tailwind.d.ts +0 -2
- package/dist/npm/predefined-packages/tailwind.js +0 -18
- package/dist/npm/predefined-packages/tanstack-form.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-form.js +0 -19
- package/dist/npm/predefined-packages/tanstack-query.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-query.js +0 -15
- package/dist/npm/predefined-packages/tanstack-router.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-router.js +0 -18
- package/dist/npm/predefined-packages/types.d.ts +0 -38
- package/dist/npm/predefined-packages/types.js +0 -1
- package/dist/npm/predefined-packages/vite.d.ts +0 -2
- package/dist/npm/predefined-packages/vite.js +0 -127
- package/dist/npm/predefined-packages/vitest.d.ts +0 -2
- package/dist/npm/predefined-packages/vitest.js +0 -20
- package/dist/npm/predefined-packages/zod.d.ts +0 -2
- package/dist/npm/predefined-packages/zod.js +0 -18
- package/dist/npm/project-check.d.ts +0 -25
- package/dist/npm/project-check.js +0 -178
- package/dist/npm/project-context.d.ts +0 -52
- package/dist/npm/project-context.js +0 -211
- package/dist/npm/project-install-guard.d.ts +0 -2
- package/dist/npm/project-install-guard.js +0 -51
- package/dist/npm/project-rules.d.ts +0 -25
- package/dist/npm/project-rules.js +0 -106
- package/dist/npm/project-runtime.d.ts +0 -21
- package/dist/npm/project-runtime.js +0 -41
- package/dist/npm/project-status.d.ts +0 -32
- package/dist/npm/project-status.js +0 -70
- package/dist/npm/project-sync.d.ts +0 -7
- package/dist/npm/project-sync.js +0 -143
- package/dist/npm/remote-installer.d.ts +0 -35
- package/dist/npm/remote-installer.js +0 -351
- package/dist/npm/rule-id-migrations.d.ts +0 -6
- package/dist/npm/rule-id-migrations.js +0 -19
- package/dist/npm/slack.d.ts +0 -16
- package/dist/npm/slack.js +0 -135
- package/dist/npm/snapshot/config.d.ts +0 -10
- package/dist/npm/snapshot/config.js +0 -24
- package/dist/npm/snapshot/policy.d.ts +0 -1
- package/dist/npm/snapshot/policy.js +0 -64
- package/dist/npm/snapshot/restore.d.ts +0 -10
- package/dist/npm/snapshot/restore.js +0 -19
- package/dist/npm/snapshot/sql.d.ts +0 -2
- package/dist/npm/snapshot/sql.js +0 -113
- package/dist/npm/snapshot/storage.d.ts +0 -8
- package/dist/npm/snapshot/storage.js +0 -70
- package/dist/npm/snapshot/verify.d.ts +0 -11
- package/dist/npm/snapshot/verify.js +0 -13
- package/dist/npm/snapshot-cli.d.ts +0 -6
- package/dist/npm/snapshot-cli.js +0 -45
- package/dist/npm/state.d.ts +0 -14
- package/dist/npm/state.js +0 -269
- package/dist/npm/supabase-local.d.ts +0 -2
- package/dist/npm/supabase-local.js +0 -62
package/dist/npm/project-sync.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { mkdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, isAbsolute, resolve, sep } from 'node:path';
|
|
4
|
-
import { removeMarkdownSection, resolveProjectPath, upsertMarkdownSection, } from "./installer-primitives.js";
|
|
5
|
-
import { CanonicalManifestSchema, parseWithSchema } from "./schemas.js";
|
|
6
|
-
import { readChecksState, readInstalledState, writeChecksState, writeInstalledState, } from "./state.js";
|
|
7
|
-
const SUPPORTED_OPERATIONS = new Set([
|
|
8
|
-
'copy_file',
|
|
9
|
-
'scaffold_file',
|
|
10
|
-
'managed_section',
|
|
11
|
-
]);
|
|
12
|
-
const clone = (value) => value === undefined ? value : JSON.parse(JSON.stringify(value));
|
|
13
|
-
const hash = (value) => createHash('sha256')
|
|
14
|
-
.update(typeof value === 'string' ? value : JSON.stringify(value))
|
|
15
|
-
.digest('hex');
|
|
16
|
-
function payloadPath(payloadRoot, relativePath) {
|
|
17
|
-
if (!relativePath || isAbsolute(relativePath))
|
|
18
|
-
throw new Error(`Source must be payload-relative: ${relativePath}`);
|
|
19
|
-
const root = resolve(payloadRoot);
|
|
20
|
-
const target = resolve(root, relativePath);
|
|
21
|
-
if (target !== root && !target.startsWith(`${root}${sep}`))
|
|
22
|
-
throw new Error(`Source escapes payload: ${relativePath}`);
|
|
23
|
-
return target;
|
|
24
|
-
}
|
|
25
|
-
async function exists(path) {
|
|
26
|
-
try {
|
|
27
|
-
await stat(path);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (error?.code === 'ENOENT')
|
|
32
|
-
return false;
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const checkerSkillIds = new Map([
|
|
37
|
-
['abac-permissions-convex', 'abac-permissions'],
|
|
38
|
-
['abac-permissions-supabase', 'abac-permissions'],
|
|
39
|
-
['unit-test-rules-convex', 'unit-test-rules'],
|
|
40
|
-
['unit-test-rules-supabase', 'unit-test-rules'],
|
|
41
|
-
]);
|
|
42
|
-
function checkerSkillId(implementation) {
|
|
43
|
-
return checkerSkillIds.get(implementation) ?? implementation;
|
|
44
|
-
}
|
|
45
|
-
function normalizeOperation(raw) {
|
|
46
|
-
const type = String(raw.type ?? '');
|
|
47
|
-
if (!SUPPORTED_OPERATIONS.has(type)) {
|
|
48
|
-
throw new Error(`Unsupported manifest operation: ${type || 'undefined'}`);
|
|
49
|
-
}
|
|
50
|
-
if (type === 'managed_section') {
|
|
51
|
-
return {
|
|
52
|
-
type,
|
|
53
|
-
path: String(raw.path ?? ''),
|
|
54
|
-
heading: String(raw.heading ?? ''),
|
|
55
|
-
content: raw.content,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
type: type,
|
|
60
|
-
path: String(raw.path ?? ''),
|
|
61
|
-
source: String(raw.source ?? ''),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function normalizeManifest(manifest) {
|
|
65
|
-
const operations = (manifest.operations ?? []).map(normalizeOperation);
|
|
66
|
-
const checkerImplementation = String(manifest.checker?.implementation ?? '').trim();
|
|
67
|
-
const check = manifest.check ??
|
|
68
|
-
(checkerImplementation
|
|
69
|
-
? { command: ['node', `.agents/skills/${checkerSkillId(checkerImplementation)}/check.ts`] }
|
|
70
|
-
: undefined);
|
|
71
|
-
for (const copy of manifest.copies ?? []) {
|
|
72
|
-
if (copy.type === 'directory' || copy.directory === true) {
|
|
73
|
-
throw new Error(`Directory copies are not supported: ${String(copy.source ?? '')}`);
|
|
74
|
-
}
|
|
75
|
-
operations.push({
|
|
76
|
-
type: copy.mode === 'scaffold' || copy.mode === 'create-only' ? 'scaffold_file' : 'copy_file',
|
|
77
|
-
source: String(copy.source ?? ''),
|
|
78
|
-
path: String(copy.target ?? copy.path ?? ''),
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
for (const section of manifest.markdownSections ?? []) {
|
|
82
|
-
operations.push({
|
|
83
|
-
type: 'managed_section',
|
|
84
|
-
path: String(section.path ?? ''),
|
|
85
|
-
heading: String(section.heading ?? ''),
|
|
86
|
-
content: section.body ?? section.content ?? '',
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return { ...manifest, operations, ...(check ? { check } : {}) };
|
|
90
|
-
}
|
|
91
|
-
export function validateRemoteManifest(input) {
|
|
92
|
-
const parsed = parseWithSchema(CanonicalManifestSchema, input, 'canonical manifest');
|
|
93
|
-
const manifest = normalizeManifest(parsed);
|
|
94
|
-
for (const operation of manifest.operations) {
|
|
95
|
-
resolveProjectPath('/__specdest_project__', operation.path);
|
|
96
|
-
if (operation.type !== 'managed_section' && !operation.source.trim()) {
|
|
97
|
-
throw new Error(`Manifest operation source is required: ${operation.type}`);
|
|
98
|
-
}
|
|
99
|
-
if (operation.type === 'managed_section' && !operation.heading.trim()) {
|
|
100
|
-
throw new Error('Managed section heading is required');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return manifest;
|
|
104
|
-
}
|
|
105
|
-
function ownershipKey(operation) {
|
|
106
|
-
return operation.type === 'managed_section'
|
|
107
|
-
? `section:${operation.path}:${operation.heading}`
|
|
108
|
-
: `file:${operation.path}`;
|
|
109
|
-
}
|
|
110
|
-
async function readProjectFile(projectRoot, relativePath) {
|
|
111
|
-
const target = resolveProjectPath(projectRoot, relativePath);
|
|
112
|
-
if (!(await exists(target)))
|
|
113
|
-
return { exists: false, value: '' };
|
|
114
|
-
return { exists: true, value: await readFile(target, 'utf8') };
|
|
115
|
-
}
|
|
116
|
-
async function writeProjectFile(projectRoot, relativePath, content) {
|
|
117
|
-
const target = resolveProjectPath(projectRoot, relativePath);
|
|
118
|
-
await mkdir(dirname(target), { recursive: true });
|
|
119
|
-
await writeFile(target, content, 'utf8');
|
|
120
|
-
}
|
|
121
|
-
function sectionBody(text, heading) {
|
|
122
|
-
const trimmed = heading.trim();
|
|
123
|
-
const level = trimmed.match(/^(#{1,6})\s+/)?.[1].length ?? 2;
|
|
124
|
-
const lines = text.split(/(?<=\n)/u);
|
|
125
|
-
let found = false;
|
|
126
|
-
const body = [];
|
|
127
|
-
for (const line of lines) {
|
|
128
|
-
if (!found) {
|
|
129
|
-
if (line.trim() === trimmed)
|
|
130
|
-
found = true;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (new RegExp(`^#{1,${level}}\\s+`, 'u').test(line.trim()))
|
|
134
|
-
break;
|
|
135
|
-
body.push(line);
|
|
136
|
-
}
|
|
137
|
-
return found ? body.join('').trim() : null;
|
|
138
|
-
}
|
|
139
|
-
function legacyMarkdownSection(text, heading) {
|
|
140
|
-
const lines = text.split(/(?<=\n)/u);
|
|
141
|
-
const level = heading.trim().match(/^(#{1,6})\s/u)?.[1].length ?? 2;
|
|
142
|
-
let start = -1;
|
|
143
|
-
let end = text.length;
|
|
144
|
-
let offset = 0;
|
|
145
|
-
for (const line of lines) {
|
|
146
|
-
if (start < 0 && line.trim() === heading.trim())
|
|
147
|
-
start = offset;
|
|
148
|
-
else if (start >= 0 && new RegExp(`^#{1,${level}}\\s+`, 'u').test(line.trim())) {
|
|
149
|
-
end = offset;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
offset += line.length;
|
|
153
|
-
}
|
|
154
|
-
return start < 0
|
|
155
|
-
? { exists: false, value: '' }
|
|
156
|
-
: { exists: true, value: text.slice(start, end).trimEnd() };
|
|
157
|
-
}
|
|
158
|
-
async function migrateLegacyMarkdownOwnership(projectRoot, prior) {
|
|
159
|
-
for (const [key, record] of Object.entries(prior)) {
|
|
160
|
-
if (record?.type !== 'markdown')
|
|
161
|
-
continue;
|
|
162
|
-
const file = await readProjectFile(projectRoot, record.path);
|
|
163
|
-
const legacyCurrent = file.exists
|
|
164
|
-
? legacyMarkdownSection(file.value, record.heading)
|
|
165
|
-
: { exists: false, value: '' };
|
|
166
|
-
if (record.appliedHash !== fingerprint(legacyCurrent)) {
|
|
167
|
-
throw new Error(`Conflict: managed content changed: ${record.path}`);
|
|
168
|
-
}
|
|
169
|
-
const currentBody = file.exists ? sectionBody(file.value, record.heading) : null;
|
|
170
|
-
const nextKey = `section:${record.path}:${record.heading}`;
|
|
171
|
-
if (prior[nextKey])
|
|
172
|
-
throw new Error(`Conflicting ownership records: ${record.path}`);
|
|
173
|
-
const previousBody = record.previousExists
|
|
174
|
-
? sectionBody(String(record.previousValue ?? ''), record.heading)
|
|
175
|
-
: null;
|
|
176
|
-
prior[nextKey] = {
|
|
177
|
-
type: 'section',
|
|
178
|
-
path: record.path,
|
|
179
|
-
heading: record.heading,
|
|
180
|
-
previousExists: Boolean(record.previousExists),
|
|
181
|
-
previousValue: previousBody ?? '',
|
|
182
|
-
appliedHash: fingerprint({ exists: currentBody !== null, value: currentBody ?? '' }),
|
|
183
|
-
};
|
|
184
|
-
delete prior[key];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async function currentOwnership(projectRoot, record) {
|
|
188
|
-
const file = await readProjectFile(projectRoot, record.path);
|
|
189
|
-
if (record.type === 'file')
|
|
190
|
-
return file;
|
|
191
|
-
const body = file.exists ? sectionBody(file.value, record.heading) : null;
|
|
192
|
-
return { exists: body !== null, value: body ?? '' };
|
|
193
|
-
}
|
|
194
|
-
function fingerprint(value) {
|
|
195
|
-
return hash({ exists: value.exists, value: value.value });
|
|
196
|
-
}
|
|
197
|
-
function assertOwned(record, current) {
|
|
198
|
-
if (record.appliedHash !== fingerprint(current))
|
|
199
|
-
throw new Error(`Conflict: managed content changed: ${record.path}`);
|
|
200
|
-
}
|
|
201
|
-
async function restoreOwnership(projectRoot, record) {
|
|
202
|
-
const current = await currentOwnership(projectRoot, record);
|
|
203
|
-
assertOwned(record, current);
|
|
204
|
-
if (record.type === 'file') {
|
|
205
|
-
const target = resolveProjectPath(projectRoot, record.path);
|
|
206
|
-
if (record.previousExists)
|
|
207
|
-
await writeProjectFile(projectRoot, record.path, record.previousValue);
|
|
208
|
-
else if (await exists(target))
|
|
209
|
-
await unlink(target);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const file = await readProjectFile(projectRoot, record.path);
|
|
213
|
-
const updated = record.previousExists
|
|
214
|
-
? upsertMarkdownSection(file.value, record.heading, record.previousValue)
|
|
215
|
-
: removeMarkdownSection(file.value, record.heading);
|
|
216
|
-
await writeProjectFile(projectRoot, record.path, updated);
|
|
217
|
-
}
|
|
218
|
-
async function applyManagedFile(operation, context) {
|
|
219
|
-
const key = ownershipKey(operation);
|
|
220
|
-
const current = await readProjectFile(context.projectRoot, operation.path);
|
|
221
|
-
const prior = context.prior[key];
|
|
222
|
-
if (prior)
|
|
223
|
-
assertOwned(prior, current);
|
|
224
|
-
const source = await readFile(payloadPath(context.payloadRoot, operation.source), 'utf8');
|
|
225
|
-
await writeProjectFile(context.projectRoot, operation.path, source);
|
|
226
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
227
|
-
context.next[key] = {
|
|
228
|
-
type: 'file',
|
|
229
|
-
path: operation.path,
|
|
230
|
-
previousExists: original.previousExists,
|
|
231
|
-
previousValue: original.previousValue,
|
|
232
|
-
appliedHash: fingerprint({ exists: true, value: source }),
|
|
233
|
-
};
|
|
234
|
-
context.touched.add(key);
|
|
235
|
-
}
|
|
236
|
-
async function applyScaffold(operation, context) {
|
|
237
|
-
const key = ownershipKey(operation);
|
|
238
|
-
const prior = context.prior[key];
|
|
239
|
-
if (prior) {
|
|
240
|
-
delete context.next[key];
|
|
241
|
-
context.touched.add(key);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const target = resolveProjectPath(context.projectRoot, operation.path);
|
|
245
|
-
if (await exists(target))
|
|
246
|
-
return;
|
|
247
|
-
const source = await readFile(payloadPath(context.payloadRoot, operation.source), 'utf8');
|
|
248
|
-
await writeProjectFile(context.projectRoot, operation.path, source);
|
|
249
|
-
}
|
|
250
|
-
async function applyManagedSection(operation, context) {
|
|
251
|
-
const key = ownershipKey(operation);
|
|
252
|
-
const file = await readProjectFile(context.projectRoot, operation.path);
|
|
253
|
-
const body = file.exists ? sectionBody(file.value, operation.heading) : null;
|
|
254
|
-
const current = { exists: body !== null, value: body ?? '' };
|
|
255
|
-
const prior = context.prior[key];
|
|
256
|
-
if (prior)
|
|
257
|
-
assertOwned(prior, current);
|
|
258
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
259
|
-
const updated = upsertMarkdownSection(file.value, operation.heading, String(operation.content ?? ''));
|
|
260
|
-
await writeProjectFile(context.projectRoot, operation.path, updated);
|
|
261
|
-
const appliedBody = sectionBody(updated, operation.heading) ?? '';
|
|
262
|
-
context.next[key] = {
|
|
263
|
-
type: 'section',
|
|
264
|
-
path: operation.path,
|
|
265
|
-
heading: operation.heading,
|
|
266
|
-
previousExists: original.previousExists,
|
|
267
|
-
previousValue: original.previousValue,
|
|
268
|
-
appliedHash: fingerprint({ exists: true, value: appliedBody }),
|
|
269
|
-
};
|
|
270
|
-
context.touched.add(key);
|
|
271
|
-
}
|
|
272
|
-
async function applyOperation(operation, context) {
|
|
273
|
-
if (operation.type === 'copy_file')
|
|
274
|
-
return applyManagedFile(operation, context);
|
|
275
|
-
if (operation.type === 'scaffold_file')
|
|
276
|
-
return applyScaffold(operation, context);
|
|
277
|
-
return applyManagedSection(operation, context);
|
|
278
|
-
}
|
|
279
|
-
async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManifest }) {
|
|
280
|
-
const manifest = validateRemoteManifest(inputManifest);
|
|
281
|
-
const installedState = await readInstalledState(projectRoot);
|
|
282
|
-
const runtimeState = await readChecksState(projectRoot);
|
|
283
|
-
runtimeState.results ??= {};
|
|
284
|
-
runtimeState.ownership ??= {};
|
|
285
|
-
const installed = installedState.installed[manifest.id];
|
|
286
|
-
if (kind === 'install' && installed)
|
|
287
|
-
throw new Error(`${manifest.id} is already installed`);
|
|
288
|
-
if (kind !== 'install' && !installed)
|
|
289
|
-
throw new Error(`${manifest.id} is not installed`);
|
|
290
|
-
const prior = clone((runtimeState.ownership[manifest.id] ?? {}));
|
|
291
|
-
await migrateLegacyMarkdownOwnership(projectRoot, prior);
|
|
292
|
-
const context = {
|
|
293
|
-
projectRoot,
|
|
294
|
-
payloadRoot,
|
|
295
|
-
prior,
|
|
296
|
-
next: clone(prior),
|
|
297
|
-
touched: new Set(),
|
|
298
|
-
};
|
|
299
|
-
if (kind === 'remove') {
|
|
300
|
-
for (const record of Object.values(prior))
|
|
301
|
-
await restoreOwnership(projectRoot, record);
|
|
302
|
-
context.next = {};
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
for (const operation of manifest.operations)
|
|
306
|
-
await applyOperation(operation, context);
|
|
307
|
-
for (const [key, record] of Object.entries(prior)) {
|
|
308
|
-
if (!context.touched.has(key) && context.next[key]) {
|
|
309
|
-
await restoreOwnership(projectRoot, record);
|
|
310
|
-
delete context.next[key];
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (kind === 'remove') {
|
|
315
|
-
delete installedState.installed[manifest.id];
|
|
316
|
-
installedState.requested = installedState.requested.filter((id) => id !== manifest.id);
|
|
317
|
-
delete runtimeState.ownership[manifest.id];
|
|
318
|
-
delete runtimeState.results[manifest.id];
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
const contentHash = String(manifest.contentHash ??
|
|
322
|
-
hash({
|
|
323
|
-
id: manifest.id,
|
|
324
|
-
revision: manifest.revision ?? null,
|
|
325
|
-
operations: manifest.operations,
|
|
326
|
-
check: manifest.check ?? null,
|
|
327
|
-
}));
|
|
328
|
-
const revision = String(manifest.revision ?? contentHash);
|
|
329
|
-
installedState.installed[manifest.id] = {
|
|
330
|
-
kind: manifest.kind ?? 'rule',
|
|
331
|
-
version: String(manifest.version ?? contentHash),
|
|
332
|
-
revision,
|
|
333
|
-
contentHash,
|
|
334
|
-
...(manifest.check ? { check: clone(manifest.check) } : {}),
|
|
335
|
-
};
|
|
336
|
-
installedState.requested = [...new Set([...installedState.requested, manifest.id])].sort();
|
|
337
|
-
runtimeState.ownership[manifest.id] = context.next;
|
|
338
|
-
}
|
|
339
|
-
await writeInstalledState(projectRoot, { ...installedState, schemaVersion: 2 });
|
|
340
|
-
await writeChecksState(projectRoot, { ...runtimeState, schemaVersion: 2 });
|
|
341
|
-
return installedState.installed[manifest.id] ?? null;
|
|
342
|
-
}
|
|
343
|
-
export async function installRule(options) {
|
|
344
|
-
return reconcile('install', options);
|
|
345
|
-
}
|
|
346
|
-
export async function syncRule(options) {
|
|
347
|
-
return reconcile('sync', options);
|
|
348
|
-
}
|
|
349
|
-
export async function removeRule(options) {
|
|
350
|
-
return reconcile('remove', options);
|
|
351
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const RULE_ID_MIGRATIONS: Readonly<{
|
|
2
|
-
readonly 'db-local-validation': "db-schema-static-validation";
|
|
3
|
-
}>;
|
|
4
|
-
export declare function migrateRuleId(id: string): string;
|
|
5
|
-
export declare function migrateRuleIdList(ids: string[]): string[];
|
|
6
|
-
export declare function migrateRuleIdMap<T>(values: Record<string, T>): Record<string, T>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const RULE_ID_MIGRATIONS = Object.freeze({
|
|
2
|
-
'db-local-validation': 'db-schema-static-validation',
|
|
3
|
-
});
|
|
4
|
-
export function migrateRuleId(id) {
|
|
5
|
-
return RULE_ID_MIGRATIONS[id] ?? id;
|
|
6
|
-
}
|
|
7
|
-
export function migrateRuleIdList(ids) {
|
|
8
|
-
return [...new Set(ids.map(migrateRuleId))].sort();
|
|
9
|
-
}
|
|
10
|
-
export function migrateRuleIdMap(values) {
|
|
11
|
-
const migrated = {};
|
|
12
|
-
for (const [id, value] of Object.entries(values)) {
|
|
13
|
-
const nextId = migrateRuleId(id);
|
|
14
|
-
if (nextId in migrated && id !== nextId)
|
|
15
|
-
continue;
|
|
16
|
-
migrated[nextId] = value;
|
|
17
|
-
}
|
|
18
|
-
return migrated;
|
|
19
|
-
}
|
package/dist/npm/slack.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type SlackTransport = typeof fetch;
|
|
2
|
-
type Io = {
|
|
3
|
-
stdout: {
|
|
4
|
-
write: (s: string) => void;
|
|
5
|
-
};
|
|
6
|
-
stderr: {
|
|
7
|
-
write: (s: string) => void;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare function sendSlackFiles(args: string[], io?: Io, options?: {
|
|
11
|
-
cwd?: string;
|
|
12
|
-
home?: string;
|
|
13
|
-
env?: NodeJS.ProcessEnv;
|
|
14
|
-
transport?: SlackTransport;
|
|
15
|
-
}): Promise<number>;
|
|
16
|
-
export {};
|