@specdest/devkit 0.2.0 → 0.2.2
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 +28 -0
- package/catalog/README.md +1 -1
- package/catalog/modules/checker-runtime/manifest.json +5 -4
- package/catalog/rules/convex-multi-presentation/SKILL.md +1 -2
- package/catalog/rules/convex-multi-presentation/check.ts +4 -71
- package/catalog/rules/convex-multi-presentation/manifest.json +11 -7
- package/package.json +20 -2
- package/src/project-operations.js +22 -18
- package/src/sync-core.js +82 -9
- package/catalog/rules/convex-multi-presentation/boundary-test-baseline.json +0 -3
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Specdest Devkit
|
|
2
|
+
|
|
3
|
+
Canonical engineering standards, reusable modules, installers, migrations, checkers, and CLI for Specdest projects.
|
|
4
|
+
|
|
5
|
+
## CLI
|
|
6
|
+
|
|
7
|
+
The publishable package is `@specdest/devkit` and exposes the `specdest` binary.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
specdest install <rule-or-module>
|
|
11
|
+
specdest status
|
|
12
|
+
specdest sync
|
|
13
|
+
specdest check
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The core command surface is implemented. Deferred convenience commands such as `fix` and module add/remove/list are intentionally excluded until real usage justifies them.
|
|
17
|
+
|
|
18
|
+
## Workspace
|
|
19
|
+
|
|
20
|
+
- repository root: publishable `@specdest/devkit` package and CLI
|
|
21
|
+
- `docs`: canonical architecture/implementation documentation
|
|
22
|
+
- `scripts`: repository validation helpers
|
|
23
|
+
|
|
24
|
+
Operational install, controller/GitHub authentication, npm Trusted Publishing, Base publication configuration, release verification, and recovery procedures are documented in [`docs/operations.md`](docs/operations.md).
|
|
25
|
+
|
|
26
|
+
Releases publish one tested immutable bundle: the npm tarball, catalog snapshot, release metadata, and checksums. npm publication and Base catalog propagation are separate: a Base outage cannot turn an already-published npm version into a failed release, and propagation can be retried independently.
|
|
27
|
+
|
|
28
|
+
Devkit is Node 24+ only. Rule checkers are strict TypeScript executed directly by Node; Deno and auxiliary TypeScript runtimes are intentionally not required.
|
package/catalog/README.md
CHANGED
|
@@ -6,6 +6,6 @@ Canonical machine-readable rule/module definitions shipped with `@specdest/devki
|
|
|
6
6
|
- `modules/<id>/manifest.json` declares reusable infrastructure modules.
|
|
7
7
|
- `source` fields are package-relative catalog files hydrated into artifact `content` before install/sync.
|
|
8
8
|
- Rule skills install under `.agents/skills/<rule-id>/` and add only their owned `AGENTS.md` section.
|
|
9
|
-
- `checker-runtime` owns shared checker helpers
|
|
9
|
+
- `checker-runtime` owns shared checker helpers. `.specdest/checks.json` is committed project state and must not be ignored.
|
|
10
10
|
|
|
11
11
|
Stack-specific differences are not expressed through inheritance here; explicit stack modules are added separately.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "checker-runtime",
|
|
3
3
|
"kind": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"artifacts": [
|
|
6
6
|
{
|
|
7
7
|
"kind": "managed-file",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"kind": "managed-file",
|
|
18
18
|
"path": ".agents/skills/shared/config.ts",
|
|
19
19
|
"source": "config.ts"
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"obsolete": [
|
|
21
23
|
{
|
|
22
24
|
"kind": "shared-line",
|
|
23
25
|
"path": ".gitignore",
|
|
24
26
|
"line": ".specdest/checks.json"
|
|
25
27
|
}
|
|
26
|
-
]
|
|
27
|
-
"obsolete": []
|
|
28
|
+
]
|
|
28
29
|
}
|
|
@@ -39,8 +39,7 @@ Rules:
|
|
|
39
39
|
- DAL and provider adapters need focused boundary/contract tests.
|
|
40
40
|
- Public Convex functions need boundary tests executed through `convex-test` for accepted args, rejected invalid args, and validated returns. Export-only smoke tests do not satisfy this rule.
|
|
41
41
|
- Public-output mappers must explicitly construct their DTO; identity mappers are forbidden because structural typing can otherwise leak persistence-only fields.
|
|
42
|
-
-
|
|
43
|
-
- Architecture enforcement has no inline suppression mechanism. Existing migration debt, when unavoidable, is tracked only in the explicit architecture baseline and new debt is rejected.
|
|
42
|
+
- Architecture enforcement has no suppression or baseline mechanism. Existing project debt must be fixed or explicitly tracked outside the checker; new violations always fail.
|
|
44
43
|
- `nps lint.convexArchitecture` is mandatory in the normal lint gate.
|
|
45
44
|
- `nps typecheck.convex` must typecheck the Convex backend independently.
|
|
46
45
|
- Oxc must lint frontend, backend, architecture rules, tests, and scripts.
|
|
@@ -196,77 +196,10 @@ for (const path of forbiddenBaseMcpPaths) {
|
|
|
196
196
|
add(path, "Base MCP must be hosted only at Convex /mcp; duplicate local MCP path is forbidden");
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
const boundaryDebtPath = ".agents/skills/convex-multi-presentation/boundary-test-baseline.json";
|
|
200
|
-
const boundaryDebtCeiling = 44;
|
|
201
|
-
let boundaryDebt = new Set<string>();
|
|
202
|
-
let boundaryDebtHasDuplicates = false;
|
|
203
|
-
if (await exists(boundaryDebtPath)) {
|
|
204
|
-
const parsed = JSON.parse(decoder.decode(await runtime.readFile(boundaryDebtPath))) as {
|
|
205
|
-
readonly findings?: readonly string[];
|
|
206
|
-
};
|
|
207
|
-
const debtFindings = parsed.findings ?? [];
|
|
208
|
-
boundaryDebt = new Set(debtFindings);
|
|
209
|
-
boundaryDebtHasDuplicates = boundaryDebt.size !== debtFindings.length;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const baselinePath = ".agents/skills/convex-multi-presentation/legacy-baseline.json";
|
|
213
|
-
const strict = runtime.args.includes("--strict");
|
|
214
|
-
const legacyBaselineCeiling = 87;
|
|
215
|
-
let baseline = new Set<string>();
|
|
216
|
-
let baselineHasDuplicates = false;
|
|
217
|
-
if (!strict && (await exists(baselinePath))) {
|
|
218
|
-
const parsed = JSON.parse(decoder.decode(await runtime.readFile(baselinePath))) as {
|
|
219
|
-
readonly findings?: readonly string[];
|
|
220
|
-
};
|
|
221
|
-
const baselineFindings = parsed.findings ?? [];
|
|
222
|
-
baseline = new Set(baselineFindings);
|
|
223
|
-
baselineHasDuplicates = baseline.size !== baselineFindings.length;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
199
|
const uniqueFindings = [...new Set(findings)].toSorted();
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
: uniqueFindings.filter((finding) => !baseline.has(finding) && !boundaryDebt.has(finding));
|
|
230
|
-
const staleBaseline = strict
|
|
231
|
-
? []
|
|
232
|
-
: [...baseline].filter((finding) => !uniqueFindings.includes(finding)).toSorted();
|
|
233
|
-
const staleBoundaryDebt = strict
|
|
234
|
-
? []
|
|
235
|
-
: [...boundaryDebt].filter((finding) => !uniqueFindings.includes(finding)).toSorted();
|
|
236
|
-
const baselineGrew = !strict && baseline.size > legacyBaselineCeiling;
|
|
237
|
-
const boundaryDebtGrew = !strict && boundaryDebt.size > boundaryDebtCeiling;
|
|
238
|
-
|
|
239
|
-
if (baselineGrew)
|
|
240
|
-
console.error(
|
|
241
|
-
`legacy convex architecture baseline may not grow beyond ${legacyBaselineCeiling}; found ${baseline.size}`,
|
|
242
|
-
);
|
|
243
|
-
if (baselineHasDuplicates)
|
|
244
|
-
console.error("legacy convex architecture baseline contains duplicate findings");
|
|
245
|
-
if (boundaryDebtGrew)
|
|
246
|
-
console.error(
|
|
247
|
-
`boundary-test baseline may not grow beyond ${boundaryDebtCeiling}; found ${boundaryDebt.size}`,
|
|
248
|
-
);
|
|
249
|
-
if (boundaryDebtHasDuplicates) console.error("boundary-test baseline contains duplicate findings");
|
|
250
|
-
if (staleBaseline.length)
|
|
251
|
-
console.error(
|
|
252
|
-
"stale convex architecture baseline entries must be removed:\n" + staleBaseline.join("\n"),
|
|
253
|
-
);
|
|
254
|
-
if (staleBoundaryDebt.length)
|
|
255
|
-
console.error(
|
|
256
|
-
"stale boundary-test baseline entries must be removed:\n" + staleBoundaryDebt.join("\n"),
|
|
257
|
-
);
|
|
258
|
-
if (newFindings.length) console.error(newFindings.join("\n"));
|
|
259
|
-
if (
|
|
260
|
-
baselineGrew ||
|
|
261
|
-
baselineHasDuplicates ||
|
|
262
|
-
staleBaseline.length ||
|
|
263
|
-
staleBoundaryDebt.length ||
|
|
264
|
-
newFindings.length
|
|
265
|
-
)
|
|
200
|
+
if (uniqueFindings.length) {
|
|
201
|
+
console.error(uniqueFindings.join("\n"));
|
|
266
202
|
runtime.exit(1);
|
|
203
|
+
}
|
|
267
204
|
|
|
268
|
-
|
|
269
|
-
console.log(
|
|
270
|
-
`convex-multi-presentation ok (${baseline.size} tracked legacy findings; --strict reports all)`,
|
|
271
|
-
);
|
|
272
|
-
else console.log("convex-multi-presentation ok");
|
|
205
|
+
console.log("convex-multi-presentation ok");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "convex-multi-presentation",
|
|
3
3
|
"kind": "rule",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"requires": [
|
|
6
6
|
"checker-runtime"
|
|
7
7
|
],
|
|
@@ -11,11 +11,6 @@
|
|
|
11
11
|
"path": ".agents/skills/convex-multi-presentation/SKILL.md",
|
|
12
12
|
"source": "SKILL.md"
|
|
13
13
|
},
|
|
14
|
-
{
|
|
15
|
-
"kind": "scaffold",
|
|
16
|
-
"path": ".agents/skills/convex-multi-presentation/boundary-test-baseline.json",
|
|
17
|
-
"source": "boundary-test-baseline.json"
|
|
18
|
-
},
|
|
19
14
|
{
|
|
20
15
|
"kind": "managed-file",
|
|
21
16
|
"path": ".agents/skills/convex-multi-presentation/check.ts",
|
|
@@ -33,7 +28,16 @@
|
|
|
33
28
|
"body": "Use `.agents/skills/convex-multi-presentation/SKILL.md` when working in this rule area. Run `node .agents/skills/convex-multi-presentation/check.ts` before handoff."
|
|
34
29
|
}
|
|
35
30
|
],
|
|
36
|
-
"obsolete": [
|
|
31
|
+
"obsolete": [
|
|
32
|
+
{
|
|
33
|
+
"kind": "file",
|
|
34
|
+
"path": ".agents/skills/convex-multi-presentation/boundary-test-baseline.json"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"kind": "file",
|
|
38
|
+
"path": ".agents/skills/convex-multi-presentation/legacy-baseline.json"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
37
41
|
"check": {
|
|
38
42
|
"command": [
|
|
39
43
|
"node",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specdest/devkit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"specdest": "src/cli.js"
|
|
@@ -14,9 +14,27 @@
|
|
|
14
14
|
"catalog"
|
|
15
15
|
],
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=24.0.0"
|
|
17
|
+
"node": ">=24.0.0",
|
|
18
|
+
"pnpm": ">=11.0.0"
|
|
18
19
|
},
|
|
20
|
+
"packageManager": "pnpm@11.6.0",
|
|
19
21
|
"publishConfig": {
|
|
20
22
|
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test test/*.test.js",
|
|
26
|
+
"lint": "node scripts/validate-js.mjs",
|
|
27
|
+
"check": "pnpm run lint && pnpm run typecheck && pnpm run test",
|
|
28
|
+
"catalog:snapshot": "node scripts/export-catalog-snapshot.mjs",
|
|
29
|
+
"release:preflight": "node scripts/release-preflight.mjs",
|
|
30
|
+
"smoke:published": "node scripts/smoke-published-package.mjs",
|
|
31
|
+
"typecheck": "node scripts/typecheck-checkers.mjs",
|
|
32
|
+
"release:build": "node scripts/build-release-artifacts.mjs",
|
|
33
|
+
"smoke:artifact": "node scripts/smoke-package-artifact.mjs",
|
|
34
|
+
"catalog:propagate": "node scripts/propagate-catalog-release.mjs"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^24.0.0",
|
|
38
|
+
"typescript": "^6.0.0"
|
|
21
39
|
}
|
|
22
40
|
}
|
|
@@ -5,17 +5,11 @@ import { evaluateSetupRequirements } from './setup-requirements.js';
|
|
|
5
5
|
import {
|
|
6
6
|
applySyncPlan,
|
|
7
7
|
previewSync,
|
|
8
|
+
inferRequestedRoots,
|
|
8
9
|
readInstalledState,
|
|
9
10
|
writeChecksState,
|
|
10
11
|
} from './sync-core.js';
|
|
11
12
|
|
|
12
|
-
function checkerArgs(command, args) {
|
|
13
|
-
if (command !== 'deno' || args.includes('--no-lock')) return args;
|
|
14
|
-
const [subcommand, ...rest] = args;
|
|
15
|
-
if (!subcommand) return args;
|
|
16
|
-
return [subcommand, '--no-lock', ...rest];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
function defaultExecutor({ command, args, cwd }) {
|
|
20
14
|
return new Promise((resolve, reject) => {
|
|
21
15
|
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -32,19 +26,28 @@ function defaultExecutor({ command, args, cwd }) {
|
|
|
32
26
|
|
|
33
27
|
export async function installCatalogEntry(projectRoot, id, options = {}) {
|
|
34
28
|
const current = await readInstalledState(projectRoot);
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
29
|
+
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
30
|
+
const currentRequested = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
31
|
+
if (currentRequested.includes(id)) throw new Error(`${id} is already requested; use specdest sync`);
|
|
32
|
+
const requestedIds = [...new Set([...currentRequested, id])].sort();
|
|
33
|
+
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
38
34
|
const desiredIds = entries.map((entry) => entry.id);
|
|
39
|
-
const
|
|
35
|
+
const desiredSet = new Set(desiredIds);
|
|
36
|
+
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
37
|
+
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
40
38
|
await applySyncPlan(plan);
|
|
41
39
|
return plan;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
export async function syncInstalledCatalog(projectRoot, options = {}) {
|
|
45
43
|
const current = await readInstalledState(projectRoot);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
44
|
+
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
45
|
+
const requestedIds = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
46
|
+
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
47
|
+
const desiredIds = entries.map((entry) => entry.id);
|
|
48
|
+
const desiredSet = new Set(desiredIds);
|
|
49
|
+
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
50
|
+
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
48
51
|
await applySyncPlan(plan);
|
|
49
52
|
return plan;
|
|
50
53
|
}
|
|
@@ -62,14 +65,13 @@ export async function runInstalledChecks(projectRoot, options = {}) {
|
|
|
62
65
|
const current = await readInstalledState(projectRoot);
|
|
63
66
|
const entries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
64
67
|
const executor = options.executor ?? defaultExecutor;
|
|
65
|
-
const now = options.now ?? (() => new Date());
|
|
66
68
|
const results = {};
|
|
67
69
|
let exitCode = 0;
|
|
68
70
|
|
|
69
71
|
for (const entry of entries) {
|
|
70
72
|
if (entry.kind !== 'rule' || !entry.check) continue;
|
|
71
73
|
const [command, ...args] = entry.check.command;
|
|
72
|
-
const execution = await executor({ command, args
|
|
74
|
+
const execution = await executor({ command, args, cwd: projectRoot });
|
|
73
75
|
const status = execution.exitCode === 0 ? 'pass' : 'fail';
|
|
74
76
|
if (execution.exitCode !== 0) exitCode = 1;
|
|
75
77
|
results[entry.id] = {
|
|
@@ -80,9 +82,11 @@ export async function runInstalledChecks(projectRoot, options = {}) {
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
const persistedResults = Object.fromEntries(
|
|
86
|
+
Object.entries(results).map(([id, result]) => [id, { status: result.status }]),
|
|
87
|
+
);
|
|
88
|
+
await writeChecksState(projectRoot, { schemaVersion: 2, results: persistedResults });
|
|
89
|
+
return { exitCode, results };
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
export function createProjectCommandHandlers(projectRoot = process.cwd()) {
|
package/src/sync-core.js
CHANGED
|
@@ -10,12 +10,13 @@ import {
|
|
|
10
10
|
validateSharedArtifact,
|
|
11
11
|
} from './shared-file.js';
|
|
12
12
|
|
|
13
|
-
export const STATE_SCHEMA_VERSION =
|
|
13
|
+
export const STATE_SCHEMA_VERSION = 2;
|
|
14
|
+
export const CHECKS_SCHEMA_VERSION = 2;
|
|
14
15
|
export const INSTALLED_RELATIVE_PATH = '.specdest/installed.json';
|
|
15
16
|
export const CHECKS_RELATIVE_PATH = '.specdest/checks.json';
|
|
16
17
|
|
|
17
|
-
const EMPTY_INSTALLED = Object.freeze({ schemaVersion:
|
|
18
|
-
const EMPTY_CHECKS = Object.freeze({ schemaVersion:
|
|
18
|
+
const EMPTY_INSTALLED = Object.freeze({ schemaVersion: 2, requested: [], installed: {} });
|
|
19
|
+
const EMPTY_CHECKS = Object.freeze({ schemaVersion: CHECKS_SCHEMA_VERSION, results: {} });
|
|
19
20
|
|
|
20
21
|
function clone(value) {
|
|
21
22
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -38,17 +39,24 @@ async function writeJsonAtomic(filePath, value) {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
function validateInstalledState(state) {
|
|
41
|
-
|
|
42
|
+
const legacy = state?.schemaVersion === 1;
|
|
43
|
+
const current = state?.schemaVersion === STATE_SCHEMA_VERSION;
|
|
44
|
+
if ((!legacy && !current) || !state.installed || Array.isArray(state.installed) || typeof state.installed !== 'object') {
|
|
42
45
|
throw new Error('Invalid .specdest/installed.json state');
|
|
43
46
|
}
|
|
47
|
+
if (current && (!Array.isArray(state.requested) || state.requested.some((id) => !validId(id) || !state.installed[id]))) {
|
|
48
|
+
throw new Error('Invalid .specdest/installed.json requested roots');
|
|
49
|
+
}
|
|
44
50
|
return state;
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
function validateChecksState(state) {
|
|
48
|
-
|
|
54
|
+
const legacy = state?.schemaVersion === 1;
|
|
55
|
+
const current = state?.schemaVersion === CHECKS_SCHEMA_VERSION;
|
|
56
|
+
if ((!legacy && !current) || !state.results || Array.isArray(state.results) || typeof state.results !== 'object') {
|
|
49
57
|
throw new Error('Invalid .specdest/checks.json state');
|
|
50
58
|
}
|
|
51
|
-
if (state.checkedAt !== null && typeof state.checkedAt !== 'string') {
|
|
59
|
+
if (legacy && state.checkedAt !== null && typeof state.checkedAt !== 'string') {
|
|
52
60
|
throw new Error('Invalid .specdest/checks.json checkedAt');
|
|
53
61
|
}
|
|
54
62
|
return state;
|
|
@@ -59,9 +67,22 @@ export async function readInstalledState(projectRoot) {
|
|
|
59
67
|
return validateInstalledState(state);
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
function formatInstalledState(state) {
|
|
71
|
+
const installed = JSON.stringify(state.installed, null, 2)
|
|
72
|
+
.split('\n')
|
|
73
|
+
.map((line, index) => index === 0 ? line : ` ${line}`)
|
|
74
|
+
.join('\n');
|
|
75
|
+
return `{\n "schemaVersion": ${STATE_SCHEMA_VERSION},\n "requested": ${JSON.stringify(state.requested)},\n "installed": ${installed}\n}\n`;
|
|
76
|
+
}
|
|
77
|
+
|
|
62
78
|
export async function writeInstalledState(projectRoot, state) {
|
|
63
79
|
validateInstalledState(state);
|
|
64
|
-
|
|
80
|
+
if (state.schemaVersion !== STATE_SCHEMA_VERSION) throw new Error('Cannot write legacy .specdest/installed.json state');
|
|
81
|
+
const filePath = join(projectRoot, INSTALLED_RELATIVE_PATH);
|
|
82
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
83
|
+
const temp = `${filePath}.${process.pid}.tmp`;
|
|
84
|
+
await writeFile(temp, formatInstalledState(state), 'utf8');
|
|
85
|
+
await rename(temp, filePath);
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
export async function readChecksState(projectRoot) {
|
|
@@ -71,6 +92,7 @@ export async function readChecksState(projectRoot) {
|
|
|
71
92
|
|
|
72
93
|
export async function writeChecksState(projectRoot, state) {
|
|
73
94
|
validateChecksState(state);
|
|
95
|
+
if (state.schemaVersion !== CHECKS_SCHEMA_VERSION) throw new Error('Cannot write legacy .specdest/checks.json state');
|
|
74
96
|
await writeJsonAtomic(join(projectRoot, CHECKS_RELATIVE_PATH), state);
|
|
75
97
|
}
|
|
76
98
|
|
|
@@ -154,6 +176,22 @@ function sortedInstalled(installed) {
|
|
|
154
176
|
return Object.fromEntries(Object.entries(installed).sort(([a], [b]) => a.localeCompare(b)));
|
|
155
177
|
}
|
|
156
178
|
|
|
179
|
+
export function inferRequestedRoots(entries) {
|
|
180
|
+
const ids = new Set(entries.map((entry) => entry.id));
|
|
181
|
+
const required = new Set();
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
for (const id of entry.requires ?? []) if (ids.has(id)) required.add(id);
|
|
184
|
+
}
|
|
185
|
+
return [...ids].filter((id) => !required.has(id)).sort();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function removalArtifact(artifact) {
|
|
189
|
+
if (artifact.kind === 'managed-file') return { kind: 'file', path: artifact.path };
|
|
190
|
+
if (artifact.kind === 'scaffold') return null;
|
|
191
|
+
if (isSharedArtifact(artifact)) return artifact;
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
157
195
|
export async function previewSync(projectRoot, manifests, options = {}) {
|
|
158
196
|
const currentState = await readInstalledState(projectRoot);
|
|
159
197
|
const catalog = new Map();
|
|
@@ -164,12 +202,18 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
164
202
|
}
|
|
165
203
|
|
|
166
204
|
const desiredIds = options.desiredIds ?? Object.keys(currentState.installed);
|
|
205
|
+
const requestedIds = options.requestedIds ?? (currentState.schemaVersion === 2 ? currentState.requested : desiredIds);
|
|
167
206
|
const selected = [...new Set(desiredIds)].sort().map((id) => {
|
|
168
207
|
const manifest = catalog.get(id);
|
|
169
208
|
if (!manifest) throw new Error(`Desired item has no current manifest: ${id}`);
|
|
170
209
|
return manifest;
|
|
171
210
|
});
|
|
172
211
|
buildOwnershipGraph(selected);
|
|
212
|
+
const activeWholePaths = new Set(
|
|
213
|
+
selected.flatMap((manifest) => (manifest.artifacts ?? [])
|
|
214
|
+
.filter((artifact) => artifact.kind === 'managed-file' || artifact.kind === 'scaffold')
|
|
215
|
+
.map((artifact) => artifact.path)),
|
|
216
|
+
);
|
|
173
217
|
|
|
174
218
|
const operations = [];
|
|
175
219
|
const sharedFiles = new Map();
|
|
@@ -179,6 +223,28 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
179
223
|
sharedFiles.set(artifact.path, entry);
|
|
180
224
|
};
|
|
181
225
|
|
|
226
|
+
for (const manifest of options.removedManifests ?? []) {
|
|
227
|
+
for (const artifact of manifest.artifacts ?? []) {
|
|
228
|
+
const obsolete = removalArtifact(artifact);
|
|
229
|
+
if (!obsolete) continue;
|
|
230
|
+
if (obsolete.kind === 'file' && activeWholePaths.has(obsolete.path)) continue;
|
|
231
|
+
if (isSharedArtifact(obsolete)) {
|
|
232
|
+
collectShared(manifest.id, obsolete, true);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const target = resolveProjectPath(projectRoot, obsolete.path);
|
|
236
|
+
const state = await fileState(target);
|
|
237
|
+
if (state === 'other') throw new Error(`Removed file target is not a file: ${obsolete.path}`);
|
|
238
|
+
operations.push({
|
|
239
|
+
relativePath: obsolete.path,
|
|
240
|
+
target,
|
|
241
|
+
action: state === 'file' ? 'delete' : 'unchanged',
|
|
242
|
+
ownerId: manifest.id,
|
|
243
|
+
artifactKind: 'removed-managed-file',
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
182
248
|
for (const manifest of selected) {
|
|
183
249
|
for (const artifact of manifest.artifacts ?? []) {
|
|
184
250
|
if (isSharedArtifact(artifact)) {
|
|
@@ -235,8 +301,15 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
235
301
|
for (const manifest of selected) {
|
|
236
302
|
nextInstalled[manifest.id] = { kind: manifest.kind, version: manifest.version };
|
|
237
303
|
}
|
|
238
|
-
const
|
|
239
|
-
const
|
|
304
|
+
for (const id of Object.keys(nextInstalled)) if (!desiredIds.includes(id)) delete nextInstalled[id];
|
|
305
|
+
const nextState = {
|
|
306
|
+
schemaVersion: STATE_SCHEMA_VERSION,
|
|
307
|
+
requested: [...new Set(requestedIds)].sort(),
|
|
308
|
+
installed: sortedInstalled(nextInstalled),
|
|
309
|
+
};
|
|
310
|
+
const normalizedCurrent = currentState.schemaVersion === STATE_SCHEMA_VERSION
|
|
311
|
+
? { schemaVersion: STATE_SCHEMA_VERSION, requested: [...currentState.requested].sort(), installed: sortedInstalled(currentState.installed) }
|
|
312
|
+
: { schemaVersion: 1, installed: sortedInstalled(currentState.installed) };
|
|
240
313
|
return {
|
|
241
314
|
projectRoot,
|
|
242
315
|
operations,
|