@playcraft/build 0.1.89 → 0.1.90

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.
Files changed (113) hide show
  1. package/dist/audio-source-files.d.ts +5 -0
  2. package/dist/audio-source-files.js +135 -0
  3. package/dist/base-builder.js +41 -2
  4. package/dist/delivery/agent-build-runner.d.ts +44 -0
  5. package/dist/delivery/agent-build-runner.js +365 -0
  6. package/dist/delivery/agent-build-source.d.ts +8 -0
  7. package/dist/delivery/agent-build-source.js +25 -0
  8. package/dist/delivery/artifact-descriptor.d.ts +31 -0
  9. package/dist/delivery/artifact-descriptor.js +237 -0
  10. package/dist/delivery/artifact-package.d.ts +43 -0
  11. package/dist/delivery/artifact-package.js +283 -0
  12. package/dist/delivery/build-plan.d.ts +4 -0
  13. package/dist/delivery/build-plan.js +189 -0
  14. package/dist/delivery/build-plan.types.d.ts +51 -0
  15. package/dist/delivery/build-plan.types.js +1 -0
  16. package/dist/delivery/command-isolation.d.ts +7 -0
  17. package/dist/delivery/command-isolation.js +252 -0
  18. package/dist/delivery/commands.d.ts +5 -0
  19. package/dist/delivery/commands.js +137 -0
  20. package/dist/delivery/files.d.ts +9 -0
  21. package/dist/delivery/files.js +144 -0
  22. package/dist/delivery/git-source-fingerprint.d.ts +2 -0
  23. package/dist/delivery/git-source-fingerprint.js +58 -0
  24. package/dist/delivery/isolated-source.d.ts +5 -0
  25. package/dist/delivery/isolated-source.js +126 -0
  26. package/dist/delivery/output-publication.d.ts +21 -0
  27. package/dist/delivery/output-publication.js +444 -0
  28. package/dist/delivery/project-delivery.d.ts +6 -0
  29. package/dist/delivery/project-delivery.js +287 -0
  30. package/dist/delivery/recipe-build-plan.d.ts +4 -0
  31. package/dist/delivery/recipe-build-plan.js +53 -0
  32. package/dist/delivery/recipe.d.ts +20 -0
  33. package/dist/delivery/recipe.js +211 -0
  34. package/dist/delivery/safe-path.d.ts +2 -0
  35. package/dist/delivery/safe-path.js +18 -0
  36. package/dist/delivery/types.d.ts +76 -0
  37. package/dist/delivery/types.js +1 -0
  38. package/dist/engines/engine-detector.js +4 -0
  39. package/dist/engines/generic-adapter.js +14 -19
  40. package/dist/index.d.ts +19 -4
  41. package/dist/index.js +11 -2
  42. package/dist/platforms/adikteev.js +1 -0
  43. package/dist/platforms/applovin.js +1 -0
  44. package/dist/platforms/base.js +2 -2
  45. package/dist/platforms/bigo.js +1 -0
  46. package/dist/platforms/facebook.js +1 -0
  47. package/dist/platforms/google.js +1 -0
  48. package/dist/platforms/inmobi.js +1 -0
  49. package/dist/platforms/ironsource.js +1 -0
  50. package/dist/platforms/liftoff.js +1 -0
  51. package/dist/platforms/mintegral.js +1 -0
  52. package/dist/platforms/moloco.js +1 -0
  53. package/dist/platforms/playcraft.js +1 -0
  54. package/dist/platforms/remerge.js +1 -0
  55. package/dist/platforms/snapchat.js +1 -0
  56. package/dist/platforms/tiktok.js +1 -0
  57. package/dist/platforms/unity.js +1 -0
  58. package/dist/production-animation-presence.d.ts +2 -0
  59. package/dist/production-animation-presence.js +146 -0
  60. package/dist/production-inputs.d.ts +30 -0
  61. package/dist/production-inputs.js +262 -0
  62. package/dist/production-source-paths.d.ts +5 -0
  63. package/dist/production-source-paths.js +27 -0
  64. package/dist/types.d.ts +5 -0
  65. package/dist/validation/artifact-qa.d.ts +44 -0
  66. package/dist/validation/artifact-qa.js +170 -0
  67. package/dist/validation/artifact-rules.d.ts +28 -0
  68. package/dist/validation/artifact-rules.js +440 -0
  69. package/dist/validation/artifact.d.ts +14 -0
  70. package/dist/validation/artifact.js +188 -0
  71. package/dist/validation/html-validator.d.ts +5 -0
  72. package/dist/validation/html-validator.js +19 -17
  73. package/dist/validation/index.d.ts +4 -0
  74. package/dist/validation/index.js +4 -0
  75. package/dist/validation/package-validator.d.ts +2 -0
  76. package/dist/validation/package-validator.js +25 -64
  77. package/dist/validation/profiles.d.ts +13 -1
  78. package/dist/validation/profiles.js +27 -0
  79. package/dist/validation/runtime-load.d.ts +89 -0
  80. package/dist/validation/runtime-load.js +654 -0
  81. package/dist/validation/source-scanner.d.ts +11 -0
  82. package/dist/validation/source-scanner.js +32 -2
  83. package/dist/validation/types.d.ts +155 -2
  84. package/dist/validation/types.js +1 -1
  85. package/dist/validation/validation-runner.d.ts +22 -2
  86. package/dist/validation/validation-runner.js +68 -3
  87. package/dist/validation/zip-reader.d.ts +7 -0
  88. package/dist/validation/zip-reader.js +159 -26
  89. package/dist/vite/config-builder-generic.d.ts +3 -1
  90. package/dist/vite/config-builder-generic.js +9 -7
  91. package/dist/vite/config-builder.js +1 -1
  92. package/dist/vite/plugin-platform.js +30 -54
  93. package/dist/vite/plugin-source-builder.d.ts +2 -14
  94. package/dist/vite/plugin-source-builder.js +61 -997
  95. package/dist/vite/source-builder-asset-paths.d.ts +25 -0
  96. package/dist/vite/source-builder-asset-paths.js +154 -0
  97. package/dist/vite/source-builder-esm.d.ts +7 -0
  98. package/dist/vite/source-builder-esm.js +877 -0
  99. package/dist/vite/source-builder-types.d.ts +14 -0
  100. package/dist/vite/source-builder-types.js +1 -0
  101. package/dist/vite/workspace.d.ts +6 -0
  102. package/dist/vite/workspace.js +41 -0
  103. package/dist/vite-builder.d.ts +4 -5
  104. package/dist/vite-builder.js +33 -34
  105. package/dist/workspace-css-imports.d.ts +2 -0
  106. package/dist/workspace-css-imports.js +139 -0
  107. package/dist/workspace-model-source.d.ts +14 -0
  108. package/dist/workspace-model-source.js +184 -0
  109. package/dist/workspace-public-imports.d.ts +11 -0
  110. package/dist/workspace-public-imports.js +232 -0
  111. package/dist/workspace-public-source.d.ts +15 -0
  112. package/dist/workspace-public-source.js +564 -0
  113. package/package.json +15 -3
@@ -0,0 +1,144 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { lstat, readFile, readdir, realpath } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { unzipSync } from 'fflate';
5
+ import { ProjectDeliveryError } from './recipe.js';
6
+ import { readProductionSourceSnapshot, ProductionSourceError } from '../production-inputs.js';
7
+ import { deliveryGitSourceFingerprint } from './git-source-fingerprint.js';
8
+ export function inside(root, target) {
9
+ const relative = path.relative(root, target);
10
+ return (relative === '' ||
11
+ (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative)));
12
+ }
13
+ export async function safeExistingPath(root, relative) {
14
+ const base = await realpath(root);
15
+ const target = await realpath(path.resolve(root, relative)).catch(() => {
16
+ throw new ProjectDeliveryError('delivery_path_missing', `Required delivery path is missing: ${relative}`, relative);
17
+ });
18
+ if (!inside(base, target))
19
+ throw new ProjectDeliveryError('delivery_path_outside_project', 'Delivery paths must stay inside the project', relative);
20
+ return target;
21
+ }
22
+ export async function checkOutputDirectory(root, directory) {
23
+ const base = await realpath(root);
24
+ let candidate = path.resolve(root, directory);
25
+ while (candidate !== path.dirname(candidate)) {
26
+ try {
27
+ const resolved = await realpath(candidate);
28
+ if (!inside(base, resolved))
29
+ throw new ProjectDeliveryError('delivery_path_outside_project', 'Delivery output must stay inside the project', directory);
30
+ return;
31
+ }
32
+ catch (error) {
33
+ if (error.code !== 'ENOENT')
34
+ throw error;
35
+ candidate = path.dirname(candidate);
36
+ }
37
+ }
38
+ }
39
+ async function validateEntry(output, primary) {
40
+ const content = await readFile(primary);
41
+ if (path.extname(primary).toLowerCase() === '.zip') {
42
+ try {
43
+ let totalBytes = 0;
44
+ const files = unzipSync(content, {
45
+ filter(file) {
46
+ totalBytes += file.originalSize;
47
+ if (totalBytes > 128 * 1024 * 1024 ||
48
+ file.name.startsWith('/') ||
49
+ file.name.includes('\\') ||
50
+ file.name.split('/').includes('..'))
51
+ throw new Error('Invalid delivery ZIP entries');
52
+ return true;
53
+ },
54
+ });
55
+ if (!Object.keys(files).some((name) => name.endsWith('.html')))
56
+ throw new Error('Delivery ZIP has no HTML entry');
57
+ }
58
+ catch {
59
+ throw new ProjectDeliveryError('delivery_package_invalid', 'The declared ZIP must be a valid Web package', path.basename(primary));
60
+ }
61
+ return;
62
+ }
63
+ const html = content.toString('utf8');
64
+ if (!/<(?:!doctype\s+html|html|body|script|canvas)\b/i.test(html))
65
+ throw new ProjectDeliveryError('delivery_html_invalid', 'The declared HTML entry is not a Web document', path.basename(primary));
66
+ for (const tag of html.match(/<(?:script|link|img|source|audio|video)\b[^>]*>/gi) ?? []) {
67
+ const attribute = /\b(?:src|href)\s*=\s*['"]([^'"]+)['"]/i.exec(tag)?.[1];
68
+ if (!attribute || /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i.test(attribute))
69
+ continue;
70
+ let relative;
71
+ try {
72
+ relative = decodeURIComponent(attribute.split(/[?#]/)[0]);
73
+ }
74
+ catch {
75
+ throw new ProjectDeliveryError('delivery_resource_missing', 'A delivery resource URL is invalid', attribute);
76
+ }
77
+ const target = relative.startsWith('/')
78
+ ? path.join(output, relative)
79
+ : path.resolve(path.dirname(primary), relative);
80
+ const resolved = await realpath(target).catch(() => undefined);
81
+ if (!resolved || !inside(output, resolved))
82
+ throw new ProjectDeliveryError('delivery_resource_missing', 'A referenced delivery resource is missing or outside the output directory', attribute);
83
+ }
84
+ }
85
+ /** Hash content and relative names, never mtime or Git HEAD, so receipts survive a clean clone. */
86
+ export async function deliverySourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories = []) {
87
+ const production = await deliveryProductionSourceSnapshot(root, outputDirectory, receiptPath, generatedDirectories);
88
+ if (production)
89
+ return production.fingerprint;
90
+ return deliveryGitSourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories);
91
+ }
92
+ /** Versioned projects use the same exact source set as save, batch capture and a clean Worker checkout. */
93
+ export async function deliveryProductionSourceSnapshot(root, outputDirectory, receiptPath, generatedDirectories = []) {
94
+ const pattern = new RegExp(`^${path.posix.normalize(outputDirectory).replace(/[.*+?^$()|[\]\\]/g, '\\$&')
95
+ .replace(/\{channel\}/g, '[a-z][a-z0-9-]{0,63}').replace(/\{format\}/g, '(?:html|zip)')}(?:/|$)`);
96
+ try {
97
+ return await readProductionSourceSnapshot(root, { excludedDirectories: generatedDirectories,
98
+ excludedPath: name => pattern.test(name) || Boolean(receiptPath && path.resolve(root, name) === path.resolve(receiptPath)) });
99
+ }
100
+ catch (error) {
101
+ if (error instanceof ProductionSourceError)
102
+ throw new ProjectDeliveryError(error.code, error.message, error.file);
103
+ throw error;
104
+ }
105
+ }
106
+ export async function outputFingerprint(root, directory, entry) {
107
+ const output = await safeExistingPath(root, directory);
108
+ const primary = await safeExistingPath(root, path.posix.join(directory, entry));
109
+ if (!inside(output, primary) ||
110
+ !(await lstat(primary)).isFile() ||
111
+ (await lstat(primary)).size < 1) {
112
+ throw new ProjectDeliveryError('delivery_output_invalid', 'The declared delivery entry must be a nonempty file', entry);
113
+ }
114
+ await validateEntry(output, primary);
115
+ const hash = createHash('sha256');
116
+ const visit = async (current) => {
117
+ for (const child of (await readdir(current, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'en'))) {
118
+ const absolute = path.join(current, child.name);
119
+ if (child.isSymbolicLink())
120
+ throw new ProjectDeliveryError('delivery_output_symlink', 'Delivery outputs must contain files instead of symlinks', path.relative(output, absolute));
121
+ if (child.isDirectory())
122
+ await visit(absolute);
123
+ else if (child.isFile()) {
124
+ const content = await readFile(absolute);
125
+ hash
126
+ .update(path.relative(output, absolute).split(path.sep).join('/'))
127
+ .update('\0')
128
+ .update(content)
129
+ .update('\0');
130
+ }
131
+ }
132
+ };
133
+ await visit(output);
134
+ return hash.digest('hex');
135
+ }
136
+ export async function entryRevision(root, directory, entry) {
137
+ try {
138
+ const info = await lstat(path.join(root, directory, entry), { bigint: true });
139
+ return [info.ino, info.size, info.mtimeNs, info.ctimeNs].join(':');
140
+ }
141
+ catch {
142
+ return undefined;
143
+ }
144
+ }
@@ -0,0 +1,2 @@
1
+ /** The clean-Git fallback has no production audio or native package dependencies. */
2
+ export declare function deliveryGitSourceFingerprint(root: string, outputDirectory: string, receiptPath?: string, generatedDirectories?: readonly string[]): Promise<string>;
@@ -0,0 +1,58 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readdir, readFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { ProjectDeliveryError } from './recipe.js';
5
+ const SOURCE_IGNORED = new Set([
6
+ '.git',
7
+ 'node_modules',
8
+ 'dist',
9
+ '.cache',
10
+ '.turbo',
11
+ '.next',
12
+ '.vite',
13
+ '.parcel-cache',
14
+ '.pnpm-store',
15
+ '.eslintcache',
16
+ '.DS_Store',
17
+ '.playcraft',
18
+ '.playcraft-temp',
19
+ '.tmp',
20
+ '.agents',
21
+ '.claude',
22
+ '.codex',
23
+ '.playcraft.json',
24
+ ]);
25
+ /** The clean-Git fallback has no production audio or native package dependencies. */
26
+ export async function deliveryGitSourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories = []) {
27
+ const hash = createHash('sha256');
28
+ const outputPattern = new RegExp(`^${path.posix
29
+ .normalize(outputDirectory)
30
+ .replace(/[.*+?^$()|[\]\\]/g, '\\$&')
31
+ .replace(/\{channel\}/g, '[a-z][a-z0-9-]{0,63}')
32
+ .replace(/\{format\}/g, '(?:html|zip)')}(?:/|$)`);
33
+ const receipt = receiptPath ? path.resolve(receiptPath) : undefined;
34
+ const visit = async (directory) => {
35
+ const entries = (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'en'));
36
+ for (const entry of entries) {
37
+ const absolute = path.join(directory, entry.name);
38
+ const relative = path.relative(root, absolute).split(path.sep).join('/');
39
+ if (SOURCE_IGNORED.has(entry.name) ||
40
+ /^\.env(?:\..*)?$/.test(entry.name) ||
41
+ absolute === receipt ||
42
+ generatedDirectories.some((directory) => relative === directory || relative.startsWith(`${directory}/`)) ||
43
+ outputPattern.test(relative))
44
+ continue;
45
+ if (entry.isDirectory())
46
+ await visit(absolute);
47
+ else if (entry.isSymbolicLink()) {
48
+ throw new ProjectDeliveryError('delivery_source_symlink', 'Source symlinks require a reproducible project build input', relative);
49
+ }
50
+ else if (entry.isFile()) {
51
+ const content = await readFile(absolute);
52
+ hash.update(`${relative.length}:${relative}:${content.length}:`).update(content);
53
+ }
54
+ }
55
+ };
56
+ await visit(root);
57
+ return hash.digest('hex');
58
+ }
@@ -0,0 +1,5 @@
1
+ import { type ProductionSourceSnapshot } from '../production-inputs.js';
2
+ import type { ProjectDeliveryOptions, ProjectDeliveryRecipe } from './types.js';
3
+ import type { DeliveryCommandIsolation } from './commands.js';
4
+ /** A clean source directory contains only the versioned production snapshot and controlled dependencies. */
5
+ export declare function buildIsolatedDelivery(root: string, snapshot: ProductionSourceSnapshot, recipe: ProjectDeliveryRecipe, options: ProjectDeliveryOptions, build: (isolated: string, isolation: DeliveryCommandIsolation) => Promise<string>): Promise<string>;
@@ -0,0 +1,126 @@
1
+ import { chown, chmod, cp, lstat, mkdir, mkdtemp, realpath, rm, symlink, writeFile } from 'node:fs/promises';
2
+ import { randomUUID } from 'node:crypto';
3
+ import path from 'node:path';
4
+ import { readProductionSourceSnapshot } from '../production-inputs.js';
5
+ import { ProjectDeliveryError, deliveryContext, recipeDigest, readProjectDeliveryRecipe } from './recipe.js';
6
+ import { outputFingerprint } from './files.js';
7
+ import { publishDeliveryOutput, recoverDeliveryOutputPublication } from './output-publication.js';
8
+ /** A clean source directory contains only the versioned production snapshot and controlled dependencies. */
9
+ export async function buildIsolatedDelivery(root, snapshot, recipe, options, build) {
10
+ root = await realpath(root);
11
+ const context = deliveryContext(recipe, options);
12
+ const outputDirectory = path.posix.normalize(context.outputDirectory).replace(/\/+$/, '');
13
+ if (!outputDirectory.startsWith('dist/'))
14
+ throw new ProjectDeliveryError('delivery_output_overlaps_artifacts', 'Use a dedicated output directory below dist; original artifacts must be preserved');
15
+ await assertOutputPath(root, outputDirectory);
16
+ const publication = { root, outputDirectory, entry: context.entry,
17
+ sourceFingerprint: snapshot.fingerprint, recipeDigest: recipeDigest(recipe), key: context.key,
18
+ ...(options.receiptDirectory || options.receiptPath ? {
19
+ receiptDirectory: options.receiptDirectory ?? path.dirname(options.receiptPath),
20
+ } : {}) };
21
+ if (await recoverDeliveryOutputPublication(publication) === 'published')
22
+ return outputFingerprint(root, outputDirectory, context.entry);
23
+ const group = (await lstat(root)).gid;
24
+ const shared = async (target, directory, executable = false) => {
25
+ if (process.platform !== 'win32') {
26
+ await chown(target, process.getuid(), group);
27
+ await chmod(target, directory ? 0o2770 : executable ? 0o770 : 0o660);
28
+ }
29
+ };
30
+ const temporary = path.join(root, '.playcraft-temp');
31
+ const existing = await lstat(temporary).catch((error) => { if (error.code === 'ENOENT')
32
+ return undefined; throw error; });
33
+ if (existing && (!existing.isDirectory() || existing.isSymbolicLink()))
34
+ throw new ProjectDeliveryError('delivery_path_outside_project', 'Unsafe delivery staging directory');
35
+ if (!existing) {
36
+ await mkdir(temporary, { mode: 0o2770 });
37
+ await shared(temporary, true);
38
+ }
39
+ const scratch = await mkdtemp(path.join(temporary, 'delivery-source-'));
40
+ await shared(scratch, true);
41
+ const directories = new Set([scratch]);
42
+ const parent = async (relative) => {
43
+ let directory = scratch;
44
+ for (const segment of relative.split('/').slice(0, -1)) {
45
+ directory = path.join(directory, segment);
46
+ if (!directories.has(directory)) {
47
+ await mkdir(directory);
48
+ await shared(directory, true);
49
+ directories.add(directory);
50
+ }
51
+ }
52
+ };
53
+ // On failure retain only this bounded staging directory. A managed process may still be
54
+ // reconciling its original identity; deleting its cwd is not a stop acknowledgement.
55
+ for (const [name, file] of snapshot.files) {
56
+ await parent(name);
57
+ const target = path.join(scratch, name);
58
+ await writeFile(target, file.body, { flag: 'wx', mode: 0o660 });
59
+ await shared(target, false, file.mode === '100755');
60
+ }
61
+ const projection = path.join(scratch, 'playcraft.config.json');
62
+ await writeFile(projection, `${JSON.stringify({ build: { delivery: recipe } }, null, 2)}\n`, { flag: 'wx', mode: 0o660 });
63
+ await shared(projection, false);
64
+ const modules = await lstat(path.join(root, 'node_modules')).catch(() => undefined);
65
+ if (modules) {
66
+ if (!modules.isDirectory() || modules.isSymbolicLink())
67
+ throw new ProjectDeliveryError('delivery_dependency_path_unsafe', 'Installed dependencies must be a directory');
68
+ await symlink(path.join(root, 'node_modules'), path.join(scratch, 'node_modules'), 'dir');
69
+ }
70
+ await build(scratch, { projectRoot: root, isolatedRoot: scratch,
71
+ dependencyRoots: modules ? [path.join(root, 'node_modules')] : [] });
72
+ const current = await readProductionSourceSnapshot(root, { excludedDirectories: recipe.generatedDirectories,
73
+ excludedPath: name => name === context.outputDirectory || name.startsWith(`${context.outputDirectory}/`) });
74
+ if (!current || current.fingerprint !== snapshot.fingerprint)
75
+ throw new ProjectDeliveryError('delivery_source_changed', 'Production source changed while preparing delivery');
76
+ const currentRecipe = await readProjectDeliveryRecipe(root);
77
+ if (!currentRecipe || recipeDigest(currentRecipe) !== publication.recipeDigest)
78
+ throw new ProjectDeliveryError('delivery_source_changed', 'The delivery recipe changed while preparing delivery');
79
+ await assertOutputPath(scratch, outputDirectory, true);
80
+ await assertOutputPath(root, outputDirectory);
81
+ const source = path.join(scratch, outputDirectory);
82
+ const expectedNewFingerprint = await outputFingerprint(scratch, context.outputDirectory, context.entry);
83
+ // Publish only the declared output subtree. Never clean the root dist/ or other artifacts.
84
+ const staged = path.join(temporary, `delivery-output-${randomUUID()}`);
85
+ await cp(source, staged, { recursive: true, force: false, dereference: false });
86
+ await assertOutputPath(root, outputDirectory, false, shared);
87
+ const fingerprint = await publishDeliveryOutput({ ...publication, stagePath: staged, expectedNewFingerprint });
88
+ await rm(scratch, { recursive: true, force: true });
89
+ return fingerprint;
90
+ }
91
+ /** Neither an output root nor any parent may alias source files or another directory. */
92
+ async function assertOutputPath(root, relative, required = false, create) {
93
+ const segments = relative.split('/');
94
+ let current = root;
95
+ for (let index = 0; index < segments.length; index++) {
96
+ current = path.join(current, segments[index]);
97
+ let info = await lstat(current).catch((error) => {
98
+ if (error.code === 'ENOENT')
99
+ return undefined;
100
+ throw error;
101
+ });
102
+ if (!info && create && index < segments.length - 1) {
103
+ let created = false;
104
+ try {
105
+ await mkdir(current, { mode: 0o2770 });
106
+ created = true;
107
+ }
108
+ catch (error) {
109
+ if (error.code !== 'EEXIST')
110
+ throw error;
111
+ }
112
+ if (created)
113
+ await create(current, true);
114
+ info = await lstat(current);
115
+ }
116
+ if (!info) {
117
+ if (required)
118
+ throw new ProjectDeliveryError('delivery_output_invalid', 'The output directory is missing');
119
+ return;
120
+ }
121
+ if (info.isSymbolicLink())
122
+ throw new ProjectDeliveryError('delivery_output_symlink', 'Delivery output paths must not contain symlinks');
123
+ if (!info.isDirectory())
124
+ throw new ProjectDeliveryError('delivery_output_invalid', 'Delivery output paths must be directories');
125
+ }
126
+ }
@@ -0,0 +1,21 @@
1
+ export type DeliveryOutputPublicationScope = {
2
+ root: string;
3
+ outputDirectory: string;
4
+ entry: string;
5
+ sourceFingerprint: string;
6
+ recipeDigest: string;
7
+ receiptDirectory?: string;
8
+ key: string;
9
+ };
10
+ export type DeliveryOutputPublicationInput = DeliveryOutputPublicationScope & {
11
+ stagePath: string;
12
+ expectedNewFingerprint: string;
13
+ /** Controller-only fault injection; never part of a recipe or model tool schema. */
14
+ checkpoint?: (phase: 'intent-durable' | 'old-moved' | 'new-published' | 'committed' | 'backup-removed') => Promise<void>;
15
+ };
16
+ /** Read-only: a pending or corrupt publication makes inspection stale; it never restores files. */
17
+ export declare function hasPendingDeliveryOutputPublication(scope: DeliveryOutputPublicationScope): Promise<boolean>;
18
+ /** Call only after the existing preparation/execution owner has exclusive directory access. */
19
+ export declare function recoverDeliveryOutputPublication(scope: DeliveryOutputPublicationScope): Promise<'none' | 'published' | 'restored'>;
20
+ /** A durable, conditional publication of a pre-copied output tree; unknown values are never removed. */
21
+ export declare function publishDeliveryOutput(input: DeliveryOutputPublicationInput): Promise<string>;