@arcadia-eternity/content-sdk 4.6.0 → 4.7.1
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 +2 -2
- package/dist/author-api.d.ts +12 -2
- package/dist/author-api.js +11 -2
- package/dist/author-git.d.ts +63 -0
- package/dist/author-git.js +324 -0
- package/dist/author-reference.d.ts +15 -1
- package/dist/author-reference.js +20 -1
- package/dist/cli.js +5 -4
- package/dist/content-query.d.ts +15 -1
- package/dist/content-query.js +53 -11
- package/dist/content-workspace.d.ts +423 -3
- package/dist/content-workspace.js +194 -51
- package/dist/debug-environments.d.ts +393 -25
- package/dist/debug-environments.js +3 -42
- package/dist/demo.js +1 -1
- package/dist/effect-declarations.d.ts +14 -0
- package/dist/effect-declarations.js +103 -0
- package/dist/environment-host-base.d.ts +175 -0
- package/dist/environment-host-base.js +86 -0
- package/dist/environment-member-transfer.d.ts +5 -0
- package/dist/environment-member-transfer.js +95 -0
- package/dist/environment-rules.d.ts +728 -3
- package/dist/environment-rules.js +158 -74
- package/dist/environment-sharing.d.ts +51 -0
- package/dist/environment-sharing.js +321 -0
- package/dist/environment.d.ts +2 -0
- package/dist/environment.js +32 -9
- package/dist/jobs.d.ts +5 -0
- package/dist/jobs.js +59 -10
- package/dist/learnsets.d.ts +47 -0
- package/dist/learnsets.js +124 -0
- package/dist/lib/content.d.ts +1 -1
- package/dist/lib/content.js +26 -2
- package/dist/lib/presentation.js +5 -11
- package/dist/managed-projects.d.ts +6 -0
- package/dist/managed-projects.js +137 -45
- package/dist/managed-sources.d.ts +17 -0
- package/dist/managed-sources.js +28 -10
- package/dist/mcp-contracts.d.ts +405 -4
- package/dist/mcp-contracts.js +3 -1
- package/dist/mcp.js +23 -1
- package/dist/pack-project.d.ts +2 -1
- package/dist/pack-project.js +40 -5
- package/dist/prepared-document.d.ts +476 -0
- package/dist/prepared-document.js +47 -0
- package/dist/preview.js +5 -5
- package/dist/project.d.ts +3 -1
- package/dist/project.js +47 -4
- package/dist/rule-composition.d.ts +290 -0
- package/dist/rule-composition.js +267 -0
- package/dist/template/.github/scripts/release-payload.mjs +91 -0
- package/dist/template/.github/scripts/release-test-npm.mjs +27 -0
- package/dist/template/.github/scripts/verify-release.mjs +138 -0
- package/dist/template/.github/workflows/release-pack.yml +77 -0
- package/dist/template/README.md +15 -2
- package/dist/template/gitignore-template +7 -0
- package/dist/template/npm-lock-template.json +2319 -0
- package/dist/template/package.json +4 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +1 -1
- package/dist/template/skills/arcadia-content-git/SKILL.md +14 -0
- package/dist/template/skills/arcadia-content-release/SKILL.md +29 -0
- package/dist/template/test/pack.test.mjs +24 -5
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +26 -7
- package/dist/workspace-cli.js +2 -2
- package/dist/workspace-materials.d.ts +4 -1
- package/dist/workspace-materials.js +8 -2
- package/dist/workspace.d.ts +11 -0
- package/dist/workspace.js +191 -31
- package/package.json +16 -4
- package/release-payload.mjs +91 -0
- package/release-test-npm.mjs +27 -0
|
@@ -1,29 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sha256Hex, skillParameterCatalogSchema, readElementCatalog, } from '@arcadia-eternity/const';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { lstat, mkdir, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { join, resolve } from 'node:path';
|
|
4
5
|
import writeFileAtomic from 'write-file-atomic';
|
|
5
6
|
import semver from 'semver';
|
|
6
7
|
import { inspectNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
7
|
-
import { normalizeEnvironmentDocument, EnvironmentDocumentV2Schema, } from './debug-environments.js';
|
|
8
|
+
import { normalizeEnvironmentDocument, EnvironmentDocumentV2Schema, EnvironmentRulesSchema, EnvironmentRuleDeclarationSchema, } from './debug-environments.js';
|
|
9
|
+
import { z } from 'zod';
|
|
8
10
|
import { withSourceLock } from './source-lock.js';
|
|
9
|
-
import { contentError, materialFiles, writeMaterials } from './workspace-materials.js';
|
|
11
|
+
import { contentError, readJson, materialFiles, writeMaterials } from './workspace-materials.js';
|
|
10
12
|
import { errorCode, isRecord } from './types.js';
|
|
13
|
+
import { compactMaterials, expandSharedMaterials, exportDependencies, } from './environment-sharing.js';
|
|
14
|
+
import { environmentShareMaterials } from './environment-host-base.js';
|
|
15
|
+
export { copyEnvironmentMember } from './environment-member-transfer.js';
|
|
16
|
+
import { parseManifestDraft, preparedDocument } from './prepared-document.js';
|
|
17
|
+
export { readInstalledEnvironmentDocument } from './prepared-document.js';
|
|
11
18
|
export { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
19
|
+
const compositionSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
rules: EnvironmentRulesSchema,
|
|
22
|
+
requiredCapabilities: z.array(z.string()).optional(),
|
|
23
|
+
fields: z.array(z.object({
|
|
24
|
+
path: z.array(z.string()),
|
|
25
|
+
value: z.unknown(),
|
|
26
|
+
sources: z.array(z.string()),
|
|
27
|
+
effectiveSources: z.array(z.string()),
|
|
28
|
+
})),
|
|
29
|
+
ruleSets: z.array(z.object({ id: z.string(), name: z.string(), rules: EnvironmentRuleDeclarationSchema })),
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
32
|
+
const contentChoices = z.array(z.object({ id: z.string(), name: z.string().optional() }));
|
|
33
|
+
const contentCatalogSchema = z.object({
|
|
34
|
+
species: contentChoices,
|
|
35
|
+
skills: contentChoices,
|
|
36
|
+
marks: contentChoices,
|
|
37
|
+
stages: contentChoices,
|
|
38
|
+
});
|
|
39
|
+
export const exportSelectionSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
revision: z.string().min(1),
|
|
42
|
+
locations: z.array(z.string().min(1)).max(50000),
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
45
|
+
function exportRevision(draft, content, dependencies) {
|
|
46
|
+
return sha256Hex(JSON.stringify([draft, content, dependencies]));
|
|
47
|
+
}
|
|
12
48
|
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
13
49
|
const envId = /^[a-z0-9][a-z0-9_-]{0,79}$/;
|
|
14
|
-
const revision = (text) => createHash('sha256').update(text).digest('hex');
|
|
15
50
|
const json = (value) => JSON.stringify(value, null, 2) + '\n';
|
|
16
51
|
const checkId = (id, pattern = uuid) => {
|
|
17
52
|
if (typeof id !== 'string' || !pattern.test(id))
|
|
18
53
|
throw contentError('RESOURCE_ID_INVALID');
|
|
19
54
|
return id;
|
|
20
55
|
};
|
|
21
|
-
async function readJson(file, limit = 4 * 1024 * 1024) {
|
|
22
|
-
const info = await lstat(file);
|
|
23
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > limit)
|
|
24
|
-
throw contentError('WORKSPACE_FILE_INVALID');
|
|
25
|
-
return JSON.parse(await readFile(file, 'utf8'));
|
|
26
|
-
}
|
|
27
56
|
async function regularDirectory(path) {
|
|
28
57
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
29
58
|
const info = await lstat(path);
|
|
@@ -55,6 +84,14 @@ async function checkedPreparation(result, document, directory) {
|
|
|
55
84
|
return {
|
|
56
85
|
contentRevision: result.contentRevision,
|
|
57
86
|
packages,
|
|
87
|
+
...(result.contentCatalog !== undefined && { contentCatalog: contentCatalogSchema.parse(result.contentCatalog) }),
|
|
88
|
+
...(result.ruleComposition !== undefined && { ruleComposition: compositionSchema.parse(result.ruleComposition) }),
|
|
89
|
+
...(result.skillParameters !== undefined && {
|
|
90
|
+
skillParameters: skillParameterCatalogSchema.parse(result.skillParameters),
|
|
91
|
+
}),
|
|
92
|
+
...(isRecord(result.elementCatalog) && {
|
|
93
|
+
elementCatalog: readElementCatalog(result.elementCatalog),
|
|
94
|
+
}),
|
|
58
95
|
members: (inspection.members ?? []),
|
|
59
96
|
};
|
|
60
97
|
}
|
|
@@ -73,8 +110,7 @@ function activeProcess(pid) {
|
|
|
73
110
|
throw error;
|
|
74
111
|
}
|
|
75
112
|
}
|
|
76
|
-
/** One owner
|
|
77
|
-
* never a selectable historical version. Runtime loaders capture their own inputs. */
|
|
113
|
+
/** One write owner publishes prepared documents alongside the locked npm materials. */
|
|
78
114
|
class ContentWorkspaceImplementation {
|
|
79
115
|
root;
|
|
80
116
|
bootId = randomUUID();
|
|
@@ -178,7 +214,7 @@ class ContentWorkspaceImplementation {
|
|
|
178
214
|
return;
|
|
179
215
|
const archive = join(this.root, 'migration-backups');
|
|
180
216
|
await regularDirectory(archive);
|
|
181
|
-
await writeFileAtomic(join(archive, `${id}-${
|
|
217
|
+
await writeFileAtomic(join(archive, `${id}-${sha256Hex(text)}.json`), text);
|
|
182
218
|
}
|
|
183
219
|
#manifest(document, previous = {}) {
|
|
184
220
|
const { packages, ...metadata } = document;
|
|
@@ -201,19 +237,10 @@ class ContentWorkspaceImplementation {
|
|
|
201
237
|
throw contentError('WORKSPACE_PATH_INVALID');
|
|
202
238
|
await readJson(join(directory, 'package.json'));
|
|
203
239
|
const text = await readFile(join(this.#directory(id), 'package.json'), 'utf8');
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
throw contentError('ENVIRONMENT_MANIFEST_INVALID');
|
|
207
|
-
const sources = manifest.arcadiaEnvironment.sources;
|
|
208
|
-
if (!Array.isArray(sources))
|
|
209
|
-
throw contentError('ENVIRONMENT_MANIFEST_INVALID');
|
|
210
|
-
const document = normalizeEnvironmentDocument({
|
|
211
|
-
...manifest.arcadiaEnvironment,
|
|
212
|
-
packages: Object.fromEntries(Object.entries(manifest.dependencies).filter(([name]) => !sources.includes(name))),
|
|
213
|
-
});
|
|
214
|
-
if (document.id !== id)
|
|
240
|
+
const draft = parseManifestDraft(text);
|
|
241
|
+
if (draft.document.id !== id)
|
|
215
242
|
throw contentError('ENVIRONMENT_ID_MISMATCH');
|
|
216
|
-
return
|
|
243
|
+
return draft;
|
|
217
244
|
}
|
|
218
245
|
listDrafts() {
|
|
219
246
|
return this.#exclusive(() => this.#listDrafts());
|
|
@@ -240,10 +267,20 @@ class ContentWorkspaceImplementation {
|
|
|
240
267
|
throw error;
|
|
241
268
|
return null;
|
|
242
269
|
});
|
|
243
|
-
if ((previous === null ? null :
|
|
270
|
+
if ((previous === null ? null : sha256Hex(previous)) !== input.expectedRevision)
|
|
244
271
|
throw contentError('REVISION_CONFLICT');
|
|
245
272
|
await regularDirectory(directory);
|
|
246
273
|
await this.#archiveRemovedDeclarations(document.id);
|
|
274
|
+
if (previous !== null) {
|
|
275
|
+
const receiptFile = join(directory, '.arcadia-prepared.json');
|
|
276
|
+
const receipt = await readJson(receiptFile).catch(error => {
|
|
277
|
+
if (errorCode(error) !== 'ENOENT')
|
|
278
|
+
throw error;
|
|
279
|
+
return undefined;
|
|
280
|
+
});
|
|
281
|
+
if (receipt && !receipt.document && receipt.draftRevision === sha256Hex(previous))
|
|
282
|
+
await writeFileAtomic(receiptFile, json({ ...receipt, document: parseManifestDraft(previous).document }));
|
|
283
|
+
}
|
|
247
284
|
await writeFileAtomic(file, json(this.#manifest(document, previous ? JSON.parse(previous) : {})));
|
|
248
285
|
return this.#draft(document.id);
|
|
249
286
|
}, true);
|
|
@@ -261,21 +298,34 @@ class ContentWorkspaceImplementation {
|
|
|
261
298
|
}
|
|
262
299
|
async #installation(id) {
|
|
263
300
|
const directory = this.#directory(id);
|
|
264
|
-
await readJson(join(directory, 'package-lock.json'), 16 * 1024 * 1024);
|
|
301
|
+
const lock = await readJson(join(directory, 'package-lock.json'), 16 * 1024 * 1024);
|
|
265
302
|
await lstat(join(directory, 'node_modules'));
|
|
266
|
-
const draft = await this.#draft(id);
|
|
267
303
|
const metadata = await readJson(join(directory, '.arcadia-prepared.json'));
|
|
268
304
|
if (metadata.format !== 'arcadia.environment-installation/1' ||
|
|
269
305
|
metadata.installationId !== id ||
|
|
270
306
|
typeof metadata.contentRevision !== 'string')
|
|
271
307
|
throw contentError('ENVIRONMENT_INSTALLATION_INVALID');
|
|
272
|
-
|
|
308
|
+
const document = preparedDocument(metadata, metadata.document === undefined ? await readFile(join(directory, 'package.json'), 'utf8') : '');
|
|
309
|
+
const locked = isRecord(lock.packages) ? lock.packages : {};
|
|
310
|
+
const members = Array.isArray(metadata.members)
|
|
311
|
+
? metadata.members.map(member => {
|
|
312
|
+
const entry = locked['node_modules/' + member.name];
|
|
313
|
+
return isRecord(entry) &&
|
|
314
|
+
typeof entry.resolved === 'string' &&
|
|
315
|
+
/^file:candidates\/[a-zA-Z0-9_.-]+\.tgz$/.test(entry.resolved) &&
|
|
316
|
+
typeof entry.integrity === 'string' &&
|
|
317
|
+
member.name !== '@arcadia-eternity/data-pack-base'
|
|
318
|
+
? { ...member, archiveIntegrity: entry.integrity }
|
|
319
|
+
: member;
|
|
320
|
+
})
|
|
321
|
+
: undefined;
|
|
273
322
|
return {
|
|
274
323
|
...metadata,
|
|
324
|
+
members,
|
|
275
325
|
installationId: id,
|
|
276
326
|
environmentId: id,
|
|
277
327
|
workspaceId: this.workspaceId,
|
|
278
|
-
document
|
|
328
|
+
document,
|
|
279
329
|
directory,
|
|
280
330
|
materialDirectory: `environments/${id}`,
|
|
281
331
|
status: 'ready',
|
|
@@ -322,6 +372,7 @@ class ContentWorkspaceImplementation {
|
|
|
322
372
|
throw contentError('ENVIRONMENT_ID_MISMATCH');
|
|
323
373
|
const source = input.projectDirectory ??
|
|
324
374
|
input.directory ??
|
|
375
|
+
input.seedDirectory ??
|
|
325
376
|
(await this.#options.resolveProject?.(input.environmentId)) ??
|
|
326
377
|
this.#directory(input.environmentId);
|
|
327
378
|
return this.#install(document, source, preparer, input);
|
|
@@ -338,10 +389,14 @@ class ContentWorkspaceImplementation {
|
|
|
338
389
|
let journaled = false;
|
|
339
390
|
try {
|
|
340
391
|
await input.onProgress?.({ stage: 'preparing' });
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
392
|
+
const limits = { ...this.#options, signal };
|
|
393
|
+
let materials = await materialFiles(source, limits);
|
|
394
|
+
if (input.importing) {
|
|
395
|
+
const restored = await environmentShareMaterials(materials, document, limits);
|
|
396
|
+
materials = restored.files;
|
|
397
|
+
document = restored.document;
|
|
398
|
+
}
|
|
399
|
+
await writeMaterials(staging, materials, limits);
|
|
345
400
|
const manifest = await readJson(join(staging, 'package.json'));
|
|
346
401
|
const base = '@arcadia-eternity/data-pack-base';
|
|
347
402
|
if (Object.hasOwn(document.packages, base) || document.sources.includes(base)) {
|
|
@@ -360,10 +415,15 @@ class ContentWorkspaceImplementation {
|
|
|
360
415
|
await writeFile(join(staging, '.arcadia-prepared.json'), json({
|
|
361
416
|
format: 'arcadia.environment-installation/1',
|
|
362
417
|
installationId: document.id,
|
|
363
|
-
|
|
418
|
+
document,
|
|
419
|
+
draftRevision: sha256Hex(text),
|
|
364
420
|
contentRevision: result.contentRevision,
|
|
365
421
|
packages: result.packages,
|
|
366
422
|
members: result.members,
|
|
423
|
+
ruleComposition: result.ruleComposition,
|
|
424
|
+
skillParameters: result.skillParameters,
|
|
425
|
+
contentCatalog: result.contentCatalog,
|
|
426
|
+
elementCatalog: result.elementCatalog,
|
|
367
427
|
createdAt: Date.now(),
|
|
368
428
|
...(input.importId ? { importId: input.importId } : {}),
|
|
369
429
|
}));
|
|
@@ -452,9 +512,6 @@ class ContentWorkspaceImplementation {
|
|
|
452
512
|
...((await this.#options.retentions?.list(id)) ?? []).map(x => ({ kind: 'retention', ...x })),
|
|
453
513
|
];
|
|
454
514
|
}
|
|
455
|
-
references(id) {
|
|
456
|
-
return this.#exclusive(() => this.#references(id));
|
|
457
|
-
}
|
|
458
515
|
clearInstallation(id) {
|
|
459
516
|
return this.#exclusive(async () => {
|
|
460
517
|
const references = await this.#references(id);
|
|
@@ -465,21 +522,78 @@ class ContentWorkspaceImplementation {
|
|
|
465
522
|
await rm(join(directory, '.arcadia-prepared.json'), { force: true });
|
|
466
523
|
}, true);
|
|
467
524
|
}
|
|
468
|
-
async #
|
|
525
|
+
async #exportVersion(id) {
|
|
469
526
|
const draft = await this.#draft(id);
|
|
470
527
|
const installation = await this.#installation(id);
|
|
471
528
|
if (installation.draftRevision !== draft.revision)
|
|
472
529
|
throw contentError('ENVIRONMENT_PREPARATION_REQUIRED', '环境已修改,请先准备环境再导出');
|
|
473
|
-
|
|
530
|
+
return { draft, installation };
|
|
531
|
+
}
|
|
532
|
+
async #shareFiles(id, document) {
|
|
533
|
+
return environmentShareMaterials(await materialFiles(this.#directory(id), this.#options), document);
|
|
534
|
+
}
|
|
535
|
+
previewEnvironmentExport(id) {
|
|
536
|
+
return this.#exclusive(async () => {
|
|
537
|
+
const { draft, installation } = await this.#exportVersion(id);
|
|
538
|
+
const lock = await readJson(join(this.#directory(id), 'package-lock.json'), 16 * 1024 * 1024);
|
|
539
|
+
const hasOnline = Object.values(lock.packages ?? {}).some(entry => isRecord(entry) && typeof entry.resolved === 'string' && entry.resolved.startsWith('https:'));
|
|
540
|
+
const dependencies = hasOnline ? exportDependencies((await this.#shareFiles(id, draft.document)).files) : [];
|
|
541
|
+
return { revision: exportRevision(draft.revision, installation.contentRevision, dependencies), dependencies };
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
missingEnvironmentArchives(probe) {
|
|
545
|
+
return this.#exclusive(async () => {
|
|
546
|
+
if (probe?.lock?.path !== 'package-lock.json' ||
|
|
547
|
+
!Array.isArray(probe.archives) ||
|
|
548
|
+
probe.archives.length > (this.#options.maxFiles ?? 50000) ||
|
|
549
|
+
probe.archives.some(ref => !ref?.external))
|
|
550
|
+
throw contentError('ENVIRONMENT_EXPORT_INVALID');
|
|
551
|
+
const missing = new Set();
|
|
552
|
+
await expandSharedMaterials([probe.lock], probe.archives, {
|
|
553
|
+
...this.#options,
|
|
554
|
+
offline: true,
|
|
555
|
+
missing,
|
|
556
|
+
signal: this.#controller.signal,
|
|
557
|
+
environments: join(this.root, 'environments'),
|
|
558
|
+
cache: this.#options.npmCache ?? join(this.root, 'npm-cache'),
|
|
559
|
+
});
|
|
560
|
+
return [...missing];
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
async #export(id, mode) {
|
|
564
|
+
const { draft, installation } = await this.#exportVersion(id);
|
|
565
|
+
const { contentRevision } = installation;
|
|
566
|
+
const shared = await this.#shareFiles(id, draft.document);
|
|
567
|
+
let files = shared.files;
|
|
568
|
+
let archives = [];
|
|
569
|
+
if (mode !== 'offline') {
|
|
570
|
+
let locations = [];
|
|
571
|
+
if (mode !== 'share') {
|
|
572
|
+
const selection = exportSelectionSchema.safeParse(mode);
|
|
573
|
+
if (!selection.success)
|
|
574
|
+
throw contentError('ENVIRONMENT_EXPORT_INVALID');
|
|
575
|
+
if (exportRevision(draft.revision, contentRevision, exportDependencies(files)) !== selection.data.revision)
|
|
576
|
+
throw contentError('REVISION_CONFLICT', '环境已修改,请重新导出');
|
|
577
|
+
locations = selection.data.locations;
|
|
578
|
+
}
|
|
579
|
+
const compact = await compactMaterials(files, this.#options, locations);
|
|
580
|
+
files = compact.materials;
|
|
581
|
+
archives = compact.archives;
|
|
582
|
+
}
|
|
474
583
|
return {
|
|
475
|
-
format:
|
|
476
|
-
|
|
477
|
-
|
|
584
|
+
format: shared.usesBase
|
|
585
|
+
? 'arcadia.environment-export/4'
|
|
586
|
+
: archives.length
|
|
587
|
+
? 'arcadia.environment-export/3'
|
|
588
|
+
: 'arcadia.environment-export/2',
|
|
589
|
+
...(archives.length || shared.usesBase ? { archives } : {}),
|
|
590
|
+
document: shared.document,
|
|
591
|
+
contentRevision,
|
|
478
592
|
files: files.map(({ path, bytes }) => ({ path, data: bytes.toString('base64') })),
|
|
479
593
|
};
|
|
480
594
|
}
|
|
481
|
-
exportEnvironment(id) {
|
|
482
|
-
return this.#exclusive(() => this.#export(id));
|
|
595
|
+
exportEnvironment(id, mode = 'share') {
|
|
596
|
+
return this.#exclusive(() => this.#export(id, mode));
|
|
483
597
|
}
|
|
484
598
|
async #snapshot() {
|
|
485
599
|
for (const name of await readdir(join(this.root, 'imports'))) {
|
|
@@ -511,7 +625,7 @@ class ContentWorkspaceImplementation {
|
|
|
511
625
|
captureSnapshot() {
|
|
512
626
|
return this.#exclusive(async () => {
|
|
513
627
|
const snapshot = await this.#snapshot();
|
|
514
|
-
this.#snapshotFingerprint =
|
|
628
|
+
this.#snapshotFingerprint = sha256Hex(json(snapshot));
|
|
515
629
|
const stamp = { workspaceId: this.workspaceId, bootId: this.bootId, generation: ++this.#snapshotGeneration };
|
|
516
630
|
return { snapshot, stamp };
|
|
517
631
|
});
|
|
@@ -525,7 +639,7 @@ class ContentWorkspaceImplementation {
|
|
|
525
639
|
return false;
|
|
526
640
|
const expected = this.#snapshotFingerprint;
|
|
527
641
|
this.#snapshotFingerprint = undefined;
|
|
528
|
-
return
|
|
642
|
+
return sha256Hex(json(await this.#snapshot())) === expected;
|
|
529
643
|
});
|
|
530
644
|
}
|
|
531
645
|
restoreSnapshot(snapshot, { mode }, preparer) {
|
|
@@ -558,7 +672,10 @@ class ContentWorkspaceImplementation {
|
|
|
558
672
|
const manifest = JSON.parse(manifestText);
|
|
559
673
|
const lock = await readJson(join(staging, 'package-lock.json'));
|
|
560
674
|
await writeFile(join(staging, 'package.json'), json({ ...manifest, dependencies: lock.packages['']?.dependencies ?? {} }));
|
|
561
|
-
const
|
|
675
|
+
const applied = normalizeEnvironmentDocument(entry.version.document);
|
|
676
|
+
if (applied.id !== id)
|
|
677
|
+
throw contentError('WORKSPACE_SNAPSHOT_INVALID');
|
|
678
|
+
const result = await preparer({ directory: staging, draft: applied });
|
|
562
679
|
await inspectNpmProject(staging);
|
|
563
680
|
await writeFile(join(staging, 'package.json'), manifestText);
|
|
564
681
|
await writeFile(join(staging, '.arcadia-prepared.json'), json({
|
|
@@ -566,6 +683,10 @@ class ContentWorkspaceImplementation {
|
|
|
566
683
|
format: 'arcadia.environment-installation/1',
|
|
567
684
|
contentRevision: result.contentRevision,
|
|
568
685
|
packages: result.packages ?? [],
|
|
686
|
+
ruleComposition: result.ruleComposition,
|
|
687
|
+
skillParameters: result.skillParameters,
|
|
688
|
+
contentCatalog: result.contentCatalog,
|
|
689
|
+
elementCatalog: result.elementCatalog,
|
|
569
690
|
}));
|
|
570
691
|
await rename(staging, this.#directory(id));
|
|
571
692
|
}
|
|
@@ -591,7 +712,7 @@ class ContentWorkspaceImplementation {
|
|
|
591
712
|
}
|
|
592
713
|
importEnvironment(bundle, input, preparer) {
|
|
593
714
|
return this.#exclusive(async () => {
|
|
594
|
-
if (
|
|
715
|
+
if (!['arcadia.environment-export/2', 'arcadia.environment-export/3', 'arcadia.environment-export/4'].includes(bundle?.format))
|
|
595
716
|
throw contentError('ENVIRONMENT_EXPORT_INVALID');
|
|
596
717
|
const document = normalizeEnvironmentDocument({
|
|
597
718
|
...bundle.document,
|
|
@@ -607,8 +728,30 @@ class ContentWorkspaceImplementation {
|
|
|
607
728
|
const staging = join(this.root, 'staging', `import-${randomUUID()}`);
|
|
608
729
|
await mkdir(staging);
|
|
609
730
|
try {
|
|
610
|
-
|
|
611
|
-
|
|
731
|
+
const files = bundle.format !== 'arcadia.environment-export/2'
|
|
732
|
+
? await expandSharedMaterials(bundle.files, bundle.archives, {
|
|
733
|
+
...this.#options,
|
|
734
|
+
signal: input.signal
|
|
735
|
+
? AbortSignal.any([input.signal, this.#controller.signal])
|
|
736
|
+
: this.#controller.signal,
|
|
737
|
+
offline: this.#options.allowShareDownloads !== true || input.allowDownload === false,
|
|
738
|
+
environments: join(this.root, 'environments'),
|
|
739
|
+
supplied: bundle.suppliedArchives,
|
|
740
|
+
cache: this.#options.npmCache ?? join(this.root, 'npm-cache'),
|
|
741
|
+
})
|
|
742
|
+
: bundle.files;
|
|
743
|
+
await writeMaterials(staging, files, { ...this.#options, signal: input.signal });
|
|
744
|
+
// The recipient owns the captured local archives, including registered ZIP sources.
|
|
745
|
+
const manifest = await readJson(join(staging, 'package.json'));
|
|
746
|
+
const dependencies = manifest.dependencies;
|
|
747
|
+
for (const name of [...document.sources]) {
|
|
748
|
+
const spec = isRecord(dependencies) ? dependencies[name] : undefined;
|
|
749
|
+
if (typeof spec === 'string' && /^file:candidates\/[a-zA-Z0-9_.-]+\.tgz$/.test(spec)) {
|
|
750
|
+
document.packages[name] = spec;
|
|
751
|
+
document.sources = document.sources.filter(source => source !== name);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
const result = await this.#install(document, staging, preparer, { ...input, importing: true });
|
|
612
755
|
return result;
|
|
613
756
|
}
|
|
614
757
|
finally {
|