@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,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
+ }
package/dist/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface ComplianceValidationOptions {
20
20
  export type BuildMode = 'classic' | 'esm';
21
21
  export type ESMMode = 'auto' | 'enabled' | 'disabled';
22
22
  export interface BuildOptions {
23
+ deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
23
24
  platform: Platform;
24
25
  format?: OutputFormat;
25
26
  outputDir?: string;
@@ -76,6 +77,9 @@ export interface BaseBuildMetadata {
76
77
  buildTool?: BuildTool;
77
78
  skipChannelBuild?: boolean;
78
79
  buildOutputDir?: string;
80
+ /** Explicit output from the project's delivery recipe; never selected by filename scanning. */
81
+ deliveryArtifact?: string;
82
+ deliveryRecipeDigest?: string;
79
83
  }
80
84
  export interface LocalBuildOptions {
81
85
  scriptsConcatenate?: boolean;
@@ -220,6 +224,7 @@ export interface BaseBuildOptions {
220
224
  /** 渠道产物格式(playable-scripts 阶段;与 Vite 阶段 format 对齐) */
221
225
  format?: OutputFormat;
222
226
  validation?: ComplianceValidationOptions;
227
+ deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
223
228
  }
224
229
  /**
225
230
  * 基础构建输出
@@ -0,0 +1,44 @@
1
+ import type { Platform } from '../types.js';
2
+ import { type RuntimeLoadOptions } from './runtime-load.js';
3
+ import { type ArtifactQaReport, type BrowserDriver, type PlayableArtifact, type QaStageId, type QaStageReport } from './types.js';
4
+ export declare const ARTIFACT_QA_REPORT_VERSION = "0.2.0";
5
+ /** Bump when an artifact rule, its severity or its matching changes. */
6
+ export declare const ARTIFACT_QA_RULES_VERSION = "2026-11-10.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
+ /** Stages to run, in this order; default all of `QA_STAGES`. */
11
+ stages?: QaStageId[];
12
+ /** Size limit of the profile, e.g. from the channel's platform adapter (`base` stage). */
13
+ sizeLimitBytes?: number;
14
+ /** Project source root (`source-hints` stage). */
15
+ projectRoot?: string;
16
+ sourceGlobs?: string[];
17
+ /** Headless browser (`runtime-load` stage); without it the stage is reported as skipped. */
18
+ driver?: BrowserDriver;
19
+ /** Why no driver was provided, e.g. Chromium is missing; becomes the runtime-load skip reason. */
20
+ driverUnavailableReason?: string;
21
+ runtime?: Pick<RuntimeLoadOptions, 'viewports' | 'settleMs' | 'timeoutMs'>;
22
+ }
23
+ /**
24
+ * Judges a built artifact by running each requested stage independently and collecting their
25
+ * reports. Stages never read each other's results, so any stage can also be called on its own.
26
+ * Results depend only on the artifact and the options, never on how the artifact was built.
27
+ */
28
+ export declare function runArtifactQa(artifact: PlayableArtifact, options?: RunArtifactQaOptions): Promise<ArtifactQaReport>;
29
+ /**
30
+ * `channel` stage: the channel's existing `html-artifact` / `delivery-package` rules, the same
31
+ * rules export validation uses. Needs only the artifact and a channel profile.
32
+ */
33
+ export declare function runChannelStage(artifact: PlayableArtifact, options: {
34
+ profile: Platform;
35
+ }): Promise<QaStageReport>;
36
+ /**
37
+ * `source-hints` stage: scans project source to help locate problems. Advisory: it never affects
38
+ * the overall result. Needs only the project root.
39
+ */
40
+ export declare function runSourceHintsStage(options: {
41
+ projectRoot: string;
42
+ profile?: Platform;
43
+ sourceGlobs?: string[];
44
+ }): Promise<QaStageReport>;
@@ -0,0 +1,170 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { runBaseStage } from './artifact-rules.js';
4
+ import { runRuntimeLoadStage } from './runtime-load.js';
5
+ import { findSourcePatterns, scanSourceForCompliance } from './source-scanner.js';
6
+ import { idleStageReport, ranStageReport, runPlayableValidation, summarize, } from './validation-runner.js';
7
+ import { QA_STAGES, } from './types.js';
8
+ export const ARTIFACT_QA_REPORT_VERSION = '0.2.0';
9
+ /** Bump when an artifact rule, its severity or its matching changes. */
10
+ export const ARTIFACT_QA_RULES_VERSION = '2026-11-10.1';
11
+ const ADSDK_PACKAGE = '@playcraft/adsdk';
12
+ /** Published adsdk methods are `playcraftInit` etc.; the short names appear in skills and templates. */
13
+ const ADSDK_CALLS = {
14
+ init: /\bsdk\s*\.\s*(?:init|playcraftInit)\s*\(/g,
15
+ start: /\bsdk\s*\.\s*(?:start|playcraftStart)\s*\(/g,
16
+ interactive: /\bsdk\s*\.\s*(?:interactive|playcraftInteractive)\s*\(/g,
17
+ finish: /\bsdk\s*\.\s*(?:finish|playcraftFinish)\s*\(/g,
18
+ install: /\bsdk\s*\.\s*(?:install|playcraftInstall)\s*\(/g,
19
+ };
20
+ /**
21
+ * Judges a built artifact by running each requested stage independently and collecting their
22
+ * reports. Stages never read each other's results, so any stage can also be called on its own.
23
+ * Results depend only on the artifact and the options, never on how the artifact was built.
24
+ */
25
+ export async function runArtifactQa(artifact, options = {}) {
26
+ const profile = options.profile ?? 'playcraft';
27
+ const stages = [];
28
+ for (const stage of options.stages ?? QA_STAGES)
29
+ stages.push(await runStage(stage, artifact, { ...options, profile }));
30
+ const counted = stages.filter((stage) => stage.status === 'ran' && !stage.advisory);
31
+ return {
32
+ version: ARTIFACT_QA_REPORT_VERSION,
33
+ rulesVersion: ARTIFACT_QA_RULES_VERSION,
34
+ profile,
35
+ artifact: {
36
+ sourcePath: artifact.sourcePath,
37
+ container: artifact.container,
38
+ layout: artifact.layout,
39
+ entry: artifact.entry,
40
+ digest: artifact.digest,
41
+ totalSize: artifact.totalSize,
42
+ fileCount: artifact.files.length,
43
+ },
44
+ summary: summarize(counted.flatMap((stage) => stage.results), counted.flatMap((stage) => stage.manualChecklist), counted.flatMap((stage) => stage.externalChecklist)),
45
+ incomplete: stages.some((stage) => stage.status === 'skipped' && !stage.advisory),
46
+ stages,
47
+ };
48
+ }
49
+ function runStage(stage, artifact, options) {
50
+ switch (stage) {
51
+ case 'base':
52
+ return runBaseStage(artifact, {
53
+ profile: options.profile,
54
+ ...(options.sizeLimitBytes !== undefined ? { sizeLimitBytes: options.sizeLimitBytes } : {}),
55
+ });
56
+ case 'channel':
57
+ return runChannelStage(artifact, { profile: options.profile });
58
+ case 'runtime-load':
59
+ return options.driver
60
+ ? runRuntimeLoadStage(artifact, {
61
+ driver: options.driver,
62
+ profile: options.profile,
63
+ ...options.runtime,
64
+ })
65
+ : Promise.resolve(idleStageReport('runtime-load', 'skipped', options.driverUnavailableReason ?? 'No headless browser driver was provided'));
66
+ case 'source-hints':
67
+ return options.projectRoot
68
+ ? runSourceHintsStage({
69
+ projectRoot: options.projectRoot,
70
+ profile: options.profile,
71
+ ...(options.sourceGlobs ? { sourceGlobs: options.sourceGlobs } : {}),
72
+ })
73
+ : Promise.resolve(idleStageReport('source-hints', 'skipped', 'No project root was provided', true));
74
+ }
75
+ }
76
+ /**
77
+ * `channel` stage: the channel's existing `html-artifact` / `delivery-package` rules, the same
78
+ * rules export validation uses. Needs only the artifact and a channel profile.
79
+ */
80
+ export async function runChannelStage(artifact, options) {
81
+ if (options.profile === 'playcraft')
82
+ return idleStageReport('channel', 'not-applicable', 'The playcraft profile has no channel rules');
83
+ const startedAt = Date.now();
84
+ const report = await runPlayableValidation({
85
+ projectRoot: path.dirname(artifact.sourcePath),
86
+ channel: options.profile,
87
+ engine: 'unknown',
88
+ buildChain: 'generic',
89
+ ...channelPaths(artifact),
90
+ }, stagesFor(artifact));
91
+ return ranStageReport('channel', startedAt, report.results, {
92
+ manualChecklist: report.manualChecklist,
93
+ externalChecklist: report.externalChecklist,
94
+ });
95
+ }
96
+ /**
97
+ * `source-hints` stage: scans project source to help locate problems. Advisory: it never affects
98
+ * the overall result. Needs only the project root.
99
+ */
100
+ export async function runSourceHintsStage(options) {
101
+ const startedAt = Date.now();
102
+ const results = await collectSourceHints(options.projectRoot, options.profile ?? 'playcraft', options.sourceGlobs);
103
+ return ranStageReport('source-hints', startedAt, results, { advisory: true });
104
+ }
105
+ /** Same stage choice as the workspace delivery re-check: HTML artifacts, or the delivery package. */
106
+ function stagesFor(artifact) {
107
+ if (artifact.container === 'html')
108
+ return ['html-artifact'];
109
+ if (artifact.container === 'zip')
110
+ return ['delivery-package'];
111
+ return ['html-artifact', 'delivery-package'];
112
+ }
113
+ function channelPaths(artifact) {
114
+ if (artifact.container === 'html')
115
+ return { htmlPath: artifact.sourcePath };
116
+ if (artifact.container === 'zip')
117
+ return { packagePath: artifact.sourcePath };
118
+ return {
119
+ htmlPath: path.join(artifact.sourcePath, artifact.entry),
120
+ packagePath: artifact.sourcePath,
121
+ };
122
+ }
123
+ async function collectSourceHints(projectRoot, profile, sourceGlobs) {
124
+ const root = path.resolve(projectRoot);
125
+ const relative = (file) => file && path.isAbsolute(file) ? path.relative(root, file).replace(/\\/g, '/') : file;
126
+ const hints = (await scanSourceForCompliance({
127
+ projectRoot: root,
128
+ channel: profile,
129
+ engine: 'unknown',
130
+ buildChain: 'generic',
131
+ ...(sourceGlobs ? { sourceGlobs } : {}),
132
+ })).filter((hint) => hint.status !== 'pass');
133
+ hints.push(...(await adsdkHints(root, sourceGlobs)));
134
+ return hints.map((hint) => ({
135
+ ...hint,
136
+ ...(hint.file ? { file: relative(hint.file) } : {}),
137
+ }));
138
+ }
139
+ async function adsdkHints(root, sourceGlobs) {
140
+ const hint = (ruleId, message, recommendation) => ({
141
+ ruleId,
142
+ channel: 'common',
143
+ stage: 'prebuild-source',
144
+ severity: 'warning',
145
+ status: 'warning',
146
+ message,
147
+ recommendation,
148
+ owner: 'playcraft-build',
149
+ confidence: 'medium',
150
+ });
151
+ if (!(await dependsOn(root, ADSDK_PACKAGE)))
152
+ return [
153
+ hint('common.adsdk.dependency.missing', `The project does not depend on ${ADSDK_PACKAGE}.`, `Install ${ADSDK_PACKAGE} and wire sdk.init, start, interactive, finish and install, so CTA and lifecycle signals reach every channel.`),
154
+ ];
155
+ const found = await findSourcePatterns(root, ADSDK_CALLS, sourceGlobs);
156
+ return Object.keys(ADSDK_CALLS)
157
+ .filter((call) => !found.has(call))
158
+ .map((call) => hint(`common.adsdk.${call}.missing`, `No sdk.${call}() call was found in the project source.`, call === 'install'
159
+ ? 'Call sdk.install() from the download / CTA button.'
160
+ : `Call sdk.${call}() at the matching lifecycle point (init → start → interactive → finish → install).`));
161
+ }
162
+ async function dependsOn(root, name) {
163
+ try {
164
+ const manifest = JSON.parse(await fs.readFile(path.join(root, 'package.json'), 'utf-8'));
165
+ return Boolean(manifest.dependencies?.[name] ?? manifest.devDependencies?.[name]);
166
+ }
167
+ catch {
168
+ return false;
169
+ }
170
+ }
@@ -0,0 +1,28 @@
1
+ import type { Platform } from '../types.js';
2
+ import type { PlayableArtifact, QaStageReport } from './types.js';
3
+ /**
4
+ * `base-output` rules: channel-independent checks that read the built artifact only. They do not
5
+ * depend on the engine or the build tool that produced the artifact.
6
+ */
7
+ export declare const BASE_OUTPUT_RULE_IDS: {
8
+ readonly entryParsable: "common.artifact.entry.parsable";
9
+ readonly sizeBudget: "common.artifact.size.budget";
10
+ readonly localReference: "common.artifact.local-reference.resolvable";
11
+ readonly externalResource: "common.artifact.external-resource.forbidden";
12
+ readonly devAddress: "common.artifact.dev-address.forbidden";
13
+ readonly inlineData: "common.artifact.inline-data.valid";
14
+ readonly sizeBreakdown: "common.artifact.size.breakdown";
15
+ readonly debugResidue: "common.artifact.debug-residue.review";
16
+ readonly directRedirect: "common.artifact.redirect.direct.review";
17
+ readonly persistentStorage: "common.artifact.storage.persistent.review";
18
+ readonly viewportMeta: "common.artifact.viewport-meta.present";
19
+ };
20
+ export type BaseOutputRuleId = (typeof BASE_OUTPUT_RULE_IDS)[keyof typeof BASE_OUTPUT_RULE_IDS];
21
+ export interface BaseStageOptions {
22
+ /** Profile whose external-resource allowlist applies; default `playcraft`. */
23
+ profile?: Platform;
24
+ /** Size limit of the profile; default 5 MB, the cap most channels use. */
25
+ sizeLimitBytes?: number;
26
+ }
27
+ /** `base` stage: static checks of the artifact files. Needs only the artifact. */
28
+ export declare function runBaseStage(artifact: PlayableArtifact, options?: BaseStageOptions): Promise<QaStageReport>;