@playcraft/build 0.2.17 → 0.2.19-test-a

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 (122) 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 +42 -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 +21 -0
  17. package/dist/delivery/command-isolation.js +327 -0
  18. package/dist/delivery/commands.d.ts +5 -0
  19. package/dist/delivery/commands.js +146 -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 +148 -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 +81 -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/engines/playable-scripts-adapter.js +2 -5
  41. package/dist/index.d.ts +21 -4
  42. package/dist/index.js +12 -2
  43. package/dist/platforms/adikteev.js +1 -0
  44. package/dist/platforms/applovin.js +1 -0
  45. package/dist/platforms/base.d.ts +4 -0
  46. package/dist/platforms/base.js +25 -6
  47. package/dist/platforms/bigo.js +1 -0
  48. package/dist/platforms/facebook.js +1 -0
  49. package/dist/platforms/google.js +1 -0
  50. package/dist/platforms/inmobi.js +1 -0
  51. package/dist/platforms/ironsource.js +1 -0
  52. package/dist/platforms/liftoff.js +1 -0
  53. package/dist/platforms/mintegral.js +1 -0
  54. package/dist/platforms/moloco.js +1 -0
  55. package/dist/platforms/playcraft.js +1 -0
  56. package/dist/platforms/remerge.js +1 -0
  57. package/dist/platforms/snapchat.js +1 -0
  58. package/dist/platforms/tiktok.js +1 -0
  59. package/dist/platforms/unity.js +1 -0
  60. package/dist/production-animation-presence.d.ts +2 -0
  61. package/dist/production-animation-presence.js +146 -0
  62. package/dist/production-inputs.d.ts +30 -0
  63. package/dist/production-inputs.js +262 -0
  64. package/dist/production-source-paths.d.ts +5 -0
  65. package/dist/production-source-paths.js +27 -0
  66. package/dist/redirect-policy.d.ts +23 -0
  67. package/dist/redirect-policy.js +25 -0
  68. package/dist/types.d.ts +12 -2
  69. package/dist/validation/artifact-qa.d.ts +36 -0
  70. package/dist/validation/artifact-qa.js +263 -0
  71. package/dist/validation/artifact-rules.d.ts +39 -0
  72. package/dist/validation/artifact-rules.js +451 -0
  73. package/dist/validation/artifact.d.ts +14 -0
  74. package/dist/validation/artifact.js +188 -0
  75. package/dist/validation/html-validator.d.ts +5 -0
  76. package/dist/validation/html-validator.js +19 -17
  77. package/dist/validation/index.d.ts +5 -0
  78. package/dist/validation/index.js +5 -0
  79. package/dist/validation/package-validator.d.ts +2 -0
  80. package/dist/validation/package-validator.js +25 -64
  81. package/dist/validation/playwright-driver.d.ts +37 -0
  82. package/dist/validation/playwright-driver.js +302 -0
  83. package/dist/validation/profiles.d.ts +13 -1
  84. package/dist/validation/profiles.js +27 -0
  85. package/dist/validation/runtime-cover.d.ts +32 -0
  86. package/dist/validation/runtime-cover.js +120 -0
  87. package/dist/validation/runtime-load.d.ts +141 -0
  88. package/dist/validation/runtime-load.js +812 -0
  89. package/dist/validation/source-scanner.d.ts +11 -0
  90. package/dist/validation/source-scanner.js +32 -2
  91. package/dist/validation/types.d.ts +201 -2
  92. package/dist/validation/types.js +1 -1
  93. package/dist/validation/validation-runner.d.ts +22 -2
  94. package/dist/validation/validation-runner.js +64 -3
  95. package/dist/validation/zip-reader.d.ts +7 -0
  96. package/dist/validation/zip-reader.js +159 -26
  97. package/dist/vite/config-builder-generic.d.ts +3 -1
  98. package/dist/vite/config-builder-generic.js +9 -7
  99. package/dist/vite/config-builder.js +1 -1
  100. package/dist/vite/plugin-platform.js +16 -30
  101. package/dist/vite/plugin-source-builder.d.ts +2 -14
  102. package/dist/vite/plugin-source-builder.js +61 -997
  103. package/dist/vite/source-builder-asset-paths.d.ts +25 -0
  104. package/dist/vite/source-builder-asset-paths.js +154 -0
  105. package/dist/vite/source-builder-esm.d.ts +7 -0
  106. package/dist/vite/source-builder-esm.js +877 -0
  107. package/dist/vite/source-builder-types.d.ts +14 -0
  108. package/dist/vite/source-builder-types.js +1 -0
  109. package/dist/vite/workspace.d.ts +6 -0
  110. package/dist/vite/workspace.js +41 -0
  111. package/dist/vite-builder.d.ts +4 -5
  112. package/dist/vite-builder.js +33 -34
  113. package/dist/workspace-css-imports.d.ts +2 -0
  114. package/dist/workspace-css-imports.js +139 -0
  115. package/dist/workspace-model-source.d.ts +14 -0
  116. package/dist/workspace-model-source.js +184 -0
  117. package/dist/workspace-public-imports.d.ts +11 -0
  118. package/dist/workspace-public-imports.js +232 -0
  119. package/dist/workspace-public-source.d.ts +15 -0
  120. package/dist/workspace-public-source.js +564 -0
  121. package/package.json +30 -4
  122. package/templates/patches/playcraft-redirect-policy.js +115 -0
@@ -0,0 +1,30 @@
1
+ export { productionSourcePathAllowed } from './production-source-paths.js';
2
+ /** Legacy capability advertisement; newer builders explicitly enumerate supported rules. */
3
+ export declare const PRODUCTION_SOURCE_RULES_VERSION: 1;
4
+ export declare const SUPPORTED_PRODUCTION_SOURCE_RULES_VERSIONS: readonly [1, 2];
5
+ export type ProductionSourceFile = {
6
+ body: Buffer;
7
+ mode: '100644' | '100755';
8
+ };
9
+ export type ProductionSourceSnapshot = {
10
+ sourceRulesVersion: 1 | 2;
11
+ files: Map<string, ProductionSourceFile>;
12
+ requiredPaths: ReadonlySet<string>;
13
+ fingerprint: string;
14
+ };
15
+ export declare class ProductionSourceError extends Error {
16
+ readonly code: string;
17
+ readonly file?: string | undefined;
18
+ constructor(code: string, file?: string | undefined);
19
+ }
20
+ /** Locked engineering guidance is saved with the project, but does not masquerade as build input. */
21
+ export declare function productionAuxiliaryPathAllowed(value: string): boolean;
22
+ /** Bounded, no-link reads used for both declarations and the exact production file set. */
23
+ export declare function readProductionSourceFile(root: string, relative: string, maximum?: number): Promise<ProductionSourceFile>;
24
+ /** Undefined preserves the exact legacy fingerprint and save rules for older projects. */
25
+ export declare function readProductionSourceSnapshot(root: string, options?: {
26
+ excludedDirectories?: readonly string[];
27
+ excludedPath?: (path: string) => boolean;
28
+ }): Promise<ProductionSourceSnapshot | undefined>;
29
+ /** Check actual Git-tree bytes and executable bits before declaring save/freeze successful. */
30
+ export declare function verifyProductionSourceSnapshot(snapshot: ProductionSourceSnapshot, read: (relative: string) => Promise<ProductionSourceFile | undefined>): Promise<void>;
@@ -0,0 +1,262 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { constants } from 'node:fs';
4
+ import { lstat, open, readdir, realpath } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { promisify } from 'node:util';
7
+ import { PRODUCTION_INPUTS_MANIFEST_PATH, workspaceProductionInputsManifestSchema, computeProductionInputClosureHash, workspaceAudioBindingSchema, inspectAudioArtifactPackage, FRAME_ANIMATION_BINDINGS_PATH, frameAnimationBindingsSchema, inspectFrameAnimationBindings, assertUniqueJsonKeys, } from '@playcraft/common/cloud-workspace/runtime';
8
+ import { productionImmutableAudioPath, readProductionAudioFiles } from './audio-source-files.js';
9
+ import { hasWorkspacePublicSourceDeclaration, readWorkspacePublicSourceClosure } from './workspace-public-source.js';
10
+ import { PUBLIC_METADATA, productionSourcePathAllowed, sourcePathAllowed, materializedPathAllowed } from './production-source-paths.js';
11
+ import { assertNoUnanchoredFrameAnimationSources } from './production-animation-presence.js';
12
+ export { productionSourcePathAllowed } from './production-source-paths.js';
13
+ /** Legacy capability advertisement; newer builders explicitly enumerate supported rules. */
14
+ export const PRODUCTION_SOURCE_RULES_VERSION = 1;
15
+ export const SUPPORTED_PRODUCTION_SOURCE_RULES_VERSIONS = [1, 2];
16
+ export class ProductionSourceError extends Error {
17
+ constructor(code, file) {
18
+ super(file ? `${code}: ${file}` : code);
19
+ this.code = code;
20
+ this.file = file;
21
+ this.name = 'ProductionSourceError';
22
+ }
23
+ }
24
+ const execute = promisify(execFile);
25
+ const digest = (body) => createHash('sha256').update(body).digest('hex');
26
+ const AUXILIARY_METADATA = new Set(['.playcraft/skills.json', '.playcraft/skills.lock.json', '.playcraft/remix-references.json']);
27
+ /** Locked engineering guidance is saved with the project, but does not masquerade as build input. */
28
+ export function productionAuxiliaryPathAllowed(value) {
29
+ if (AUXILIARY_METADATA.has(value) || /^\.playcraft\/skill-artifacts\/[a-f0-9]{64}\.tar\.gz$/.test(value))
30
+ return true;
31
+ return value.startsWith('.agents/skills/') && productionSourcePathAllowed(value.slice('.agents/'.length));
32
+ }
33
+ /** Bounded, no-link reads used for both declarations and the exact production file set. */
34
+ export async function readProductionSourceFile(root, relative, maximum = 64 * 1024 * 1024) {
35
+ return readSourceFile(root, relative, maximum, false);
36
+ }
37
+ async function readSourceFile(root, relative, maximum, immutableAudio, selectedMember = false) {
38
+ if (!productionSourcePathAllowed(relative) && !(immutableAudio && sourcePathAllowed(relative, true) && productionImmutableAudioPath(relative)) && !(selectedMember && materializedPathAllowed(relative)))
39
+ throw new ProductionSourceError('production_input_path_forbidden', relative);
40
+ let current = root;
41
+ const parts = relative.split('/');
42
+ for (let index = 0; index < parts.length; index++) {
43
+ current = path.join(current, parts[index]);
44
+ const stat = await lstat(current);
45
+ if (stat.isSymbolicLink() || (index < parts.length - 1 ? !stat.isDirectory() : !stat.isFile() || stat.nlink !== 1 || stat.size > maximum))
46
+ throw new ProductionSourceError('production_input_path_unsafe', relative);
47
+ }
48
+ const file = await open(current, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
49
+ try {
50
+ const before = await file.stat();
51
+ if (!before.isFile() || before.nlink !== 1 || before.size > maximum)
52
+ throw new ProductionSourceError('production_input_path_unsafe', relative);
53
+ const body = await file.readFile(), after = await file.stat(), named = await lstat(current);
54
+ if (body.length !== before.size || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size ||
55
+ before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs || named.ino !== after.ino || named.dev !== after.dev)
56
+ throw new ProductionSourceError('production_input_changed', relative);
57
+ return { body, mode: before.mode & 0o111 ? '100755' : '100644' };
58
+ }
59
+ finally {
60
+ await file.close();
61
+ }
62
+ }
63
+ async function boundAudioFiles(root) {
64
+ const files = new Map();
65
+ for (const name of ['source', 'source/audio-bindings']) {
66
+ const entry = await lstat(path.join(root, name)).catch((error) => {
67
+ if (error.code === 'ENOENT')
68
+ return undefined;
69
+ throw error;
70
+ });
71
+ if (!entry || (name === 'source' && entry.isFile()))
72
+ return files;
73
+ if (!entry.isDirectory() || entry.isSymbolicLink())
74
+ throw new ProductionSourceError('production_input_path_unsafe', name);
75
+ }
76
+ const entries = await readdir(path.join(root, 'source/audio-bindings'), { withFileTypes: true });
77
+ if (entries.length > 1024)
78
+ throw new ProductionSourceError('production_input_limit');
79
+ for (const entry of entries) {
80
+ if (!entry.name.endsWith('.json'))
81
+ continue;
82
+ const bindingPath = `source/audio-bindings/${entry.name}`;
83
+ const file = await readProductionSourceFile(root, bindingPath, 16384);
84
+ const binding = workspaceAudioBindingSchema.parse(JSON.parse(file.body.toString('utf8')));
85
+ const directory = `dist/audio/${digest(binding.sourcePath)}/${binding.sourceContentHash}/${binding.representationSetHash}`;
86
+ if (bindingPath !== `source/audio-bindings/${binding.eventName}.json` || binding.modulePath !== `${directory}/sound.mjs`)
87
+ throw new ProductionSourceError('production_audio_binding_invalid', bindingPath);
88
+ files.set(bindingPath, file);
89
+ files.set(binding.sourcePath, await readProductionSourceFile(root, binding.sourcePath));
90
+ const bundle = await inspectAudioArtifactPackage(`${directory}/sound.${binding.sourcePath.endsWith('.pcscore.json') ? 'pcscore' : 'pcaudio'}.json`, async (name, maximum) => {
91
+ const member = await readSourceFile(root, name, maximum, true);
92
+ files.set(name, member);
93
+ return member.body;
94
+ });
95
+ if (bundle.sourcePath !== binding.sourcePath || bundle.sourceContentHash !== binding.sourceContentHash ||
96
+ digest(files.get(`${directory}/audition.wav`).body) !== binding.auditionContentHash)
97
+ throw new ProductionSourceError('production_audio_binding_invalid', bindingPath);
98
+ }
99
+ return files;
100
+ }
101
+ async function sourcePaths(root) {
102
+ const marker = await lstat(path.join(root, '.git')).catch(() => undefined);
103
+ if (marker) {
104
+ const { stdout } = await execute('git', ['-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', '-C', root,
105
+ 'ls-files', '--cached', '--others', '--exclude-standard', '-z'], { timeout: 60000, maxBuffer: 16 * 1024 * 1024,
106
+ env: { PATH: process.env.PATH, HOME: root, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' } });
107
+ return stdout.split('\0').filter(Boolean);
108
+ }
109
+ const paths = [];
110
+ async function visit(prefix = '') {
111
+ for (const entry of await readdir(path.join(root, prefix), { withFileTypes: true })) {
112
+ const name = prefix ? `${prefix}/${entry.name}` : entry.name;
113
+ if (!productionSourcePathAllowed(name) &&
114
+ !(entry.isDirectory() && [...PUBLIC_METADATA].some(file => file.startsWith(`${name}/`))))
115
+ continue;
116
+ if (entry.isDirectory())
117
+ await visit(name);
118
+ else
119
+ paths.push(name);
120
+ if (paths.length > 8192)
121
+ throw new ProductionSourceError('production_input_limit');
122
+ }
123
+ }
124
+ await visit();
125
+ return paths;
126
+ }
127
+ /** Undefined preserves the exact legacy fingerprint and save rules for older projects. */
128
+ export async function readProductionSourceSnapshot(root, options = {}) {
129
+ root = await realpath(root);
130
+ let declaration;
131
+ try {
132
+ declaration = await readProductionSourceFile(root, PRODUCTION_INPUTS_MANIFEST_PATH, 2 * 1024 * 1024);
133
+ }
134
+ catch (error) {
135
+ if (error.code === 'ENOENT') {
136
+ await assertNoUnanchoredFrameAnimationSources(root);
137
+ return undefined;
138
+ }
139
+ throw error;
140
+ }
141
+ let manifest;
142
+ try {
143
+ manifest = workspaceProductionInputsManifestSchema.parse(JSON.parse(declaration.body.toString('utf8')));
144
+ }
145
+ catch {
146
+ throw new ProductionSourceError('production_inputs_manifest_invalid', PRODUCTION_INPUTS_MANIFEST_PATH);
147
+ }
148
+ if (manifest.schemaVersion !== 3) {
149
+ try {
150
+ if (await hasWorkspacePublicSourceDeclaration(root))
151
+ throw new ProductionSourceError('production_public_workspace_upgrade_required', '.playcraft/workspace.json');
152
+ }
153
+ catch (error) {
154
+ if (error instanceof ProductionSourceError)
155
+ throw error;
156
+ throw new ProductionSourceError('production_public_workspace_invalid', '.playcraft/workspace.json');
157
+ }
158
+ }
159
+ const required = new Map();
160
+ for (const input of manifest.inputs) {
161
+ const { closureHash, ...body } = input;
162
+ if (computeProductionInputClosureHash(body) !== closureHash)
163
+ throw new ProductionSourceError('production_input_closure_changed');
164
+ for (const file of input.files) {
165
+ if (!materializedPathAllowed(file.path))
166
+ throw new ProductionSourceError('production_input_path_forbidden', file.path);
167
+ const previous = required.get(file.path);
168
+ if (previous && JSON.stringify(previous) !== JSON.stringify({ contentHash: file.contentHash, bytes: file.bytes, mode: file.mode }))
169
+ throw new ProductionSourceError('production_input_conflict', file.path);
170
+ required.set(file.path, { contentHash: file.contentHash, bytes: file.bytes, mode: file.mode });
171
+ }
172
+ }
173
+ const animationFiles = new Map();
174
+ const animationIndex = await readProductionSourceFile(root, FRAME_ANIMATION_BINDINGS_PATH, 2 * 1024 * 1024).catch((error) => {
175
+ if (error.code === 'ENOENT')
176
+ return undefined;
177
+ throw error;
178
+ });
179
+ const animationAnchor = manifest.schemaVersion === 1 ? undefined : manifest.animationBindings;
180
+ if (!animationAnchor)
181
+ await assertNoUnanchoredFrameAnimationSources(root);
182
+ if (animationAnchor && (!animationIndex || digest(animationIndex.body) !== animationAnchor.contentHash))
183
+ throw new ProductionSourceError('production_animation_index_changed', FRAME_ANIMATION_BINDINGS_PATH);
184
+ if (animationIndex) {
185
+ if (!animationAnchor)
186
+ throw new ProductionSourceError('production_animation_manifest_required', PRODUCTION_INPUTS_MANIFEST_PATH);
187
+ assertUniqueJsonKeys(animationIndex.body.toString('utf8'));
188
+ const index = frameAnimationBindingsSchema.parse(JSON.parse(animationIndex.body.toString('utf8')));
189
+ const closure = await inspectFrameAnimationBindings(index, manifest, async (name, maximum) => {
190
+ const file = await readProductionSourceFile(root, name, maximum);
191
+ return { bytes: file.body, mode: file.mode };
192
+ });
193
+ animationFiles.set(FRAME_ANIMATION_BINDINGS_PATH, animationIndex);
194
+ for (const [name, file] of closure)
195
+ animationFiles.set(name, { body: Buffer.from(file.bytes), mode: file.mode });
196
+ for (const [name, file] of animationFiles)
197
+ required.set(name, { contentHash: digest(file.body), bytes: file.body.length, mode: file.mode });
198
+ }
199
+ const audio = await readProductionAudioFiles(root, (name, maximum) => readSourceFile(root, name, maximum, true));
200
+ for (const [name, file] of await boundAudioFiles(root)) {
201
+ const previous = audio.get(name);
202
+ if (previous && (previous.mode !== file.mode || !previous.body.equals(file.body)))
203
+ throw new ProductionSourceError('production_input_changed', name);
204
+ audio.set(name, file);
205
+ }
206
+ for (const [name, file] of audio)
207
+ required.set(name, { contentHash: digest(file.body), bytes: file.body.length, mode: file.mode });
208
+ const publicFiles = manifest.schemaVersion === 3
209
+ ? (await readWorkspacePublicSourceClosure(root)).files
210
+ : new Map();
211
+ for (const [name, file] of publicFiles) {
212
+ const previous = animationFiles.get(name) ?? audio.get(name);
213
+ if (previous && (previous.mode !== file.mode || !previous.body.equals(file.body)))
214
+ throw new ProductionSourceError('production_input_conflict', name);
215
+ const immutable = required.get(name);
216
+ const current = { contentHash: digest(file.body), bytes: file.body.length, mode: file.mode };
217
+ if (immutable && JSON.stringify(immutable) !== JSON.stringify(current))
218
+ throw new ProductionSourceError('production_input_conflict', name);
219
+ required.set(name, current);
220
+ }
221
+ const excluded = options.excludedDirectories ?? [];
222
+ const excludedPath = (name) => options.excludedPath?.(name) || excluded.some(prefix => name === prefix || name.startsWith(`${prefix}/`));
223
+ for (const name of required.keys())
224
+ if (excludedPath(name))
225
+ throw new ProductionSourceError('production_input_is_generated', name);
226
+ const candidates = new Set([...(await sourcePaths(root)), PRODUCTION_INPUTS_MANIFEST_PATH, ...required.keys()]);
227
+ const files = new Map();
228
+ let total = 0;
229
+ for (const name of [...candidates].sort()) {
230
+ if ((!productionSourcePathAllowed(name) && !audio.has(name) && !publicFiles.has(name) && !(required.has(name) && materializedPathAllowed(name))) || excludedPath(name))
231
+ continue;
232
+ let file;
233
+ try {
234
+ file = name === PRODUCTION_INPUTS_MANIFEST_PATH ? declaration : publicFiles.get(name) ?? animationFiles.get(name) ?? audio.get(name) ?? await readSourceFile(root, name, 64 * 1024 * 1024, false, required.has(name));
235
+ }
236
+ catch (error) {
237
+ if (!required.has(name) && error.code === 'ENOENT')
238
+ continue;
239
+ throw error;
240
+ }
241
+ const expected = required.get(name);
242
+ if (expected && (expected.contentHash !== digest(file.body) || expected.bytes !== file.body.length || expected.mode !== file.mode))
243
+ throw new ProductionSourceError('production_input_changed', name);
244
+ total += file.body.length;
245
+ if (files.size >= 8192 || total > 256 * 1024 * 1024)
246
+ throw new ProductionSourceError('production_input_limit');
247
+ files.set(name, file);
248
+ }
249
+ const sourceRulesVersion = manifest.schemaVersion === 3 ? 2 : 1;
250
+ const hash = createHash('sha256').update(`playcraft-production-source-v${sourceRulesVersion}\0`);
251
+ for (const [name, file] of files)
252
+ hash.update(name).update('\0').update(file.mode).update('\0').update(file.body).update('\0');
253
+ return { sourceRulesVersion, files, requiredPaths: new Set([PRODUCTION_INPUTS_MANIFEST_PATH, ...required.keys()]), fingerprint: hash.digest('hex') };
254
+ }
255
+ /** Check actual Git-tree bytes and executable bits before declaring save/freeze successful. */
256
+ export async function verifyProductionSourceSnapshot(snapshot, read) {
257
+ for (const [name, expected] of snapshot.files) {
258
+ const actual = await read(name);
259
+ if (!actual || actual.mode !== expected.mode || !actual.body.equals(expected.body))
260
+ throw new ProductionSourceError('production_input_not_committed', name);
261
+ }
262
+ }
@@ -0,0 +1,5 @@
1
+ export declare const PUBLIC_METADATA: Set<string>;
2
+ /** Credentials and process paths are never promoted merely because a declaration names them. */
3
+ export declare function productionSourcePathAllowed(value: string): boolean;
4
+ export declare function materializedPathAllowed(value: string): boolean;
5
+ export declare function sourcePathAllowed(value: string, selectedMember: boolean): boolean;
@@ -0,0 +1,27 @@
1
+ import { workspaceProductionInputPathSchema } from '@playcraft/common/cloud-workspace/runtime';
2
+ const PRIVATE_NAMES = new Set([
3
+ '.git', 'node_modules', '.ssh', '.aws', '.azure', '.gnupg', '.codex', '.npm', '.pnpm-store',
4
+ '.config', '.npmrc', '.yarnrc', '.yarnrc.yml', '.netrc', '.git-credentials', 'credentials',
5
+ 'credentials.json', 'secrets', 'id_rsa', 'id_ed25519', 'settings.local.json',
6
+ '.playcraft.json', 'playcraft.config.json', '.agents', '.claude',
7
+ ]);
8
+ const PROCESS_NAMES = new Set(['work', '.tmp', '.temp', '.cache', '.next', '.vite', '.turbo',
9
+ 'coverage', '.playcraft-temp', '.playcraft-preview-out', 'dist', 'dist-all', '.ds_store', 'thumbs.db', '.eslintcache', '.parcel-cache']);
10
+ export const PUBLIC_METADATA = new Set(['.playcraft/model-build-inputs.json']);
11
+ /** Credentials and process paths are never promoted merely because a declaration names them. */
12
+ export function productionSourcePathAllowed(value) {
13
+ return sourcePathAllowed(value, false);
14
+ }
15
+ export function materializedPathAllowed(value) {
16
+ return workspaceProductionInputPathSchema.safeParse(value).success && sourcePathAllowed(value, true);
17
+ }
18
+ export function sourcePathAllowed(value, selectedMember) {
19
+ if (!value || value.includes('\\') || value.includes('\0') || value.startsWith('/') || value.includes(':') ||
20
+ value.split('/').some(segment => !segment || segment === '.' || segment === '..'))
21
+ return false;
22
+ const parts = value.split('/');
23
+ if (parts.some(segment => PRIVATE_NAMES.has(segment.toLowerCase()) || (!selectedMember && PROCESS_NAMES.has(segment.toLowerCase())) ||
24
+ /^\.env(?:$|\.)/i.test(segment) || /\.(?:pem|key|p12|pfx)$/i.test(segment)))
25
+ return false;
26
+ return !parts.some(segment => segment.toLowerCase() === '.playcraft') || PUBLIC_METADATA.has(value);
27
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 跳转版本规则:同一份游戏源码按「第 N 次点击起跳商店」或「游玩满 N 秒后下一次点击跳商店」
3
+ * 打出多个版本。规则在构建时随渠道适配器注入 HTML,由 templates/patches/playcraft-redirect-policy.js
4
+ * 在运行时执行,不改动游戏代码。
5
+ */
6
+ export type PlayableRedirectRule = {
7
+ /** 从第 N 次点击起,每次点击都直接跳商店 */
8
+ clicks?: number;
9
+ /** 首次触摸后累计游玩满 N 秒,下一次点击跳商店 */
10
+ seconds?: number;
11
+ };
12
+ export declare const PLAYABLE_REDIRECT_LIMITS: {
13
+ readonly clicks: {
14
+ readonly min: 1;
15
+ readonly max: 20;
16
+ };
17
+ readonly seconds: {
18
+ readonly min: 1;
19
+ readonly max: 600;
20
+ };
21
+ };
22
+ /** 规范化跳转规则:无有效阈值时返回 undefined(不注入任何脚本)。 */
23
+ export declare function normalizePlayableRedirect(value: unknown): PlayableRedirectRule | undefined;
@@ -0,0 +1,25 @@
1
+ export const PLAYABLE_REDIRECT_LIMITS = {
2
+ clicks: { min: 1, max: 20 },
3
+ seconds: { min: 1, max: 600 },
4
+ };
5
+ function boundedInteger(value, limits) {
6
+ if (typeof value !== 'number' || !Number.isInteger(value))
7
+ return undefined;
8
+ if (value < limits.min || value > limits.max)
9
+ return undefined;
10
+ return value;
11
+ }
12
+ /** 规范化跳转规则:无有效阈值时返回 undefined(不注入任何脚本)。 */
13
+ export function normalizePlayableRedirect(value) {
14
+ if (!value || typeof value !== 'object' || Array.isArray(value))
15
+ return undefined;
16
+ const source = value;
17
+ const clicks = boundedInteger(source.clicks, PLAYABLE_REDIRECT_LIMITS.clicks);
18
+ const seconds = boundedInteger(source.seconds, PLAYABLE_REDIRECT_LIMITS.seconds);
19
+ if (clicks === undefined && seconds === undefined)
20
+ return undefined;
21
+ return {
22
+ ...(clicks !== undefined ? { clicks } : {}),
23
+ ...(seconds !== undefined ? { seconds } : {}),
24
+ };
25
+ }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { PlayableRedirectRule } from './redirect-policy.js';
1
2
  export type Platform = 'playcraft' | 'facebook' | 'snapchat' | 'ironsource' | 'applovin' | 'google' | 'tiktok' | 'unity' | 'liftoff' | 'moloco' | 'bigo' | 'inmobi' | 'adikteev' | 'remerge' | 'mintegral';
2
3
  export type OutputFormat = 'html' | 'zip';
3
4
  /**
@@ -20,6 +21,7 @@ export interface ComplianceValidationOptions {
20
21
  export type BuildMode = 'classic' | 'esm';
21
22
  export type ESMMode = 'auto' | 'enabled' | 'disabled';
22
23
  export interface BuildOptions {
24
+ deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
23
25
  platform: Platform;
24
26
  format?: OutputFormat;
25
27
  outputDir?: string;
@@ -64,6 +66,8 @@ export interface BuildOptions {
64
66
  adNetwork?: string;
65
67
  totalInteractions?: number;
66
68
  };
69
+ /** 跳转版本规则(点击次数 / 游玩时长);仅在有效时随 CTA 适配器注入 */
70
+ redirect?: PlayableRedirectRule;
67
71
  }
68
72
  export interface BaseBuildMetadata {
69
73
  mode: BuildMode;
@@ -76,6 +80,9 @@ export interface BaseBuildMetadata {
76
80
  buildTool?: BuildTool;
77
81
  skipChannelBuild?: boolean;
78
82
  buildOutputDir?: string;
83
+ /** Explicit output from the project's delivery recipe; never selected by filename scanning. */
84
+ deliveryArtifact?: string;
85
+ deliveryRecipeDigest?: string;
79
86
  }
80
87
  export interface LocalBuildOptions {
81
88
  scriptsConcatenate?: boolean;
@@ -116,8 +123,8 @@ export interface ProjectManifest {
116
123
  path: string;
117
124
  preload?: boolean;
118
125
  tags?: string[];
119
- i18n?: Record<string, any>;
120
- data?: any;
126
+ i18n?: Record<string, unknown>;
127
+ data?: unknown;
121
128
  file?: {
122
129
  filename: string;
123
130
  size: number;
@@ -225,6 +232,9 @@ export interface BaseBuildOptions {
225
232
  /** 渠道产物格式(playable-scripts 阶段;与 Vite 阶段 format 对齐) */
226
233
  format?: OutputFormat;
227
234
  validation?: ComplianceValidationOptions;
235
+ deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
236
+ /** See `ProjectDeliveryOptions.trustedDependencyRoot`. */
237
+ trustedDependencyRoot?: string;
228
238
  }
229
239
  /**
230
240
  * 基础构建输出
@@ -0,0 +1,36 @@
1
+ import type { Platform } from '../types.js';
2
+ import { type RuntimeLoadOptions } from './runtime-load.js';
3
+ import { type ArtifactQaReport, type BrowserDriver, type PlayableArtifact, type QaProgressEvent, type QaStageId } from './types.js';
4
+ export declare const ARTIFACT_QA_REPORT_VERSION = "0.3.0";
5
+ /** Bump when an artifact rule, its severity, its matching or its step changes. */
6
+ export declare const ARTIFACT_QA_RULES_VERSION = "2026-11-11.1";
7
+ export interface RunArtifactQaOptions {
8
+ /** Rules to judge by: `playcraft` (default) checks the playable itself; a channel adds its rules. */
9
+ profile?: Platform;
10
+ /** Steps to run, always in the order of `QA_STAGES`; default all of them. */
11
+ stages?: QaStageId[];
12
+ /**
13
+ * Size limit of a channel profile, e.g. from the channel's platform adapter (`size` step); a
14
+ * channel enforces it. The `playcraft` profile has no hard limit and only analyses size.
15
+ */
16
+ sizeLimitBytes?: number;
17
+ /** Project source root, scanned for hints that help locate each step's problems. */
18
+ projectRoot?: string;
19
+ sourceGlobs?: string[];
20
+ /** Headless browser for the `resources`, `launch` and `cta` checks; without it they are skipped. */
21
+ driver?: BrowserDriver;
22
+ /** Why no driver was provided, e.g. Chromium is missing; shown as the skip reason. */
23
+ driverUnavailableReason?: string;
24
+ runtime?: Pick<RuntimeLoadOptions, 'viewports' | 'settleMs' | 'timeoutMs' | 'onDiagnostics'>;
25
+ /** Called when each step starts and ends, so callers can show QA progress step by step. */
26
+ onProgress?: (event: QaProgressEvent) => void | Promise<void>;
27
+ }
28
+ /** Step a rule belongs to; channel package and entry rules not matched otherwise are `code`. */
29
+ export declare function qaStageOfRule(ruleId: string): QaStageId;
30
+ /**
31
+ * Judges a built artifact step by step, in the order of `QA_STAGES`. Static checks, channel rules
32
+ * and the headless browser each run once; every result is reported under the step its rule belongs
33
+ * to. The browser opens in the first step that needs it. Results depend only on the artifact and
34
+ * the options, never on how the artifact was built.
35
+ */
36
+ export declare function runArtifactQa(artifact: PlayableArtifact, options?: RunArtifactQaOptions): Promise<ArtifactQaReport>;