@wildshard/shard-format 0.66.1 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -19
- package/src/cli/corpus-deprecations.ts +41 -0
- package/src/cli/corpus.ts +300 -0
- package/src/cli/main.ts +32 -0
- package/src/format/cook-preparation.ts +22 -6
- package/src/format/deprecations.ts +132 -0
- package/src/format/empty-shardfile.json +56 -0
- package/src/format/empty-shardfile.ts +43 -0
- package/src/format/format-migrate-inventory.ts +142 -0
- package/src/format/format-migrate-rebuild.ts +269 -0
- package/src/format/format-migrate.ts +290 -0
- package/src/format/format-migration-journal.ts +129 -0
- package/src/format/format-migration-ops.ts +230 -0
- package/src/format/format-migration-prune.ts +106 -0
- package/src/format/format-migrations.ts +124 -0
- package/src/format/issue-codes.ts +3 -1
- package/src/format/items.ts +21 -3
- package/src/format/journal-glyphs.json +12 -0
- package/src/format/lootEconomy.ts +9 -1
- package/src/format/memory-armed.json +1 -39
- package/src/format/memory-armed.ts +41 -8
- package/src/format/memory-epoch.ts +2 -2
- package/src/format/memory-line.ts +4 -3
- package/src/format/memoryAdmission.ts +1 -1
- package/src/format/policy-verdict.ts +95 -0
- package/src/format/runtime-tier.ts +3 -3
- package/src/format/shardSections.ts +11 -1
- package/src/format/shardfile-assets.ts +12 -8
- package/src/format/shardfile-stream-admit.ts +41 -16
- package/src/format/shardfile-stream-rows.ts +3 -1
- package/src/format/shardfile-stream.ts +12 -9
- package/src/format/shardfileValidation.ts +30 -18
- package/src/format/stateLineage.ts +1 -1
- package/src/format/version.ts +11 -13
- package/src/format/baked-terrain.golden.json +0 -2760
- package/src/format/colliders.golden.json +0 -1619
- package/src/format/forest-placement.golden.json +0 -4588
- package/src/format/geometry-layout.golden.json +0 -180
- package/src/format/interact-table.golden.json +0 -340
- package/src/format/item-catalogue.golden.json +0 -2310
- package/src/format/memory-ratchet.ts +0 -107
- package/src/format/small-laws.golden.json +0 -57
- package/src/format/terrain-field.golden.json +0 -3998
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { zoneArmed } from './memory-armed.ts'
|
|
2
|
+
import { MEMORY_EPOCH } from './memory-epoch.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SHARD-COMPAT CP10 (J486 D1.1, Jake 2026-11-21): memory lines, budgets and runtime targets judge a shard file once,
|
|
6
|
+
* at upload. The API stores this verdict and its rule version (the memory epoch) beside the original; a stored
|
|
7
|
+
* original, an engine shard pin and a cook validate with `judged: 'stored'`, so a newer policy reaches new uploads only
|
|
8
|
+
* and never re-judges what was already admitted. Readability (schemas, inventory, hashes, preparation) is judged every
|
|
9
|
+
* time either way.
|
|
10
|
+
*/
|
|
11
|
+
type Judged = 'upload' | 'stored'
|
|
12
|
+
|
|
13
|
+
interface PolicyIssue {
|
|
14
|
+
readonly code: string
|
|
15
|
+
readonly metric: string
|
|
16
|
+
readonly actual: number
|
|
17
|
+
readonly limit: number
|
|
18
|
+
readonly severity: 'refusal' | 'warning'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface PolicyVerdict {
|
|
22
|
+
readonly judged: Judged
|
|
23
|
+
/** The rule version the verdict was reached under. */
|
|
24
|
+
readonly epoch: number
|
|
25
|
+
/** Whether the zone was on the armed list (J426) when judged. */
|
|
26
|
+
readonly armed: boolean
|
|
27
|
+
/** Every policy issue found: warnings on an upload (a refusal throws); warnings and would-be refusals when stored. */
|
|
28
|
+
readonly issues: readonly PolicyIssue[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function policyVerdict(
|
|
32
|
+
slug: string | undefined,
|
|
33
|
+
judged: Judged,
|
|
34
|
+
issues: readonly PolicyIssue[],
|
|
35
|
+
): PolicyVerdict {
|
|
36
|
+
return {
|
|
37
|
+
judged,
|
|
38
|
+
epoch: MEMORY_EPOCH,
|
|
39
|
+
armed: zoneArmed(slug),
|
|
40
|
+
issues: issues.map(
|
|
41
|
+
({ code, metric, actual, limit, severity }): PolicyIssue => ({
|
|
42
|
+
code,
|
|
43
|
+
metric,
|
|
44
|
+
actual,
|
|
45
|
+
limit,
|
|
46
|
+
severity,
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** What the host measures on its own engine build (script CPU and fuel) still refuses; the file's own facts do not. */
|
|
53
|
+
const MEASURED = 'perf-script-'
|
|
54
|
+
|
|
55
|
+
/** A performance report's issues for a stored original (engine `checkShardfile` in the cook): a fact of the file judged
|
|
56
|
+
* at upload only warns; an upload keeps every severity. */
|
|
57
|
+
function asJudged<
|
|
58
|
+
Issue extends Readonly<{ code: string; severity: 'refusal' | 'warning' }>,
|
|
59
|
+
>(issues: readonly Issue[], judged: Judged | undefined): Issue[] {
|
|
60
|
+
if (judged !== 'stored') {
|
|
61
|
+
return [...issues]
|
|
62
|
+
}
|
|
63
|
+
return issues.map((issue: Issue): Issue =>
|
|
64
|
+
issue.code.startsWith(MEASURED) ? issue : { ...issue, severity: 'warning' },
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The verdict each admitted shard object was judged with: read back by the validators, so no signature grows. */
|
|
69
|
+
const VERDICTS = new WeakMap<object, PolicyVerdict>()
|
|
70
|
+
|
|
71
|
+
function recordVerdict<Admitted extends object>(
|
|
72
|
+
shard: Admitted,
|
|
73
|
+
verdict: PolicyVerdict,
|
|
74
|
+
): Admitted {
|
|
75
|
+
VERDICTS.set(shard, verdict)
|
|
76
|
+
return shard
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function admittedVerdict(shard: Readonly<object>): PolicyVerdict {
|
|
80
|
+
const verdict = VERDICTS.get(shard)
|
|
81
|
+
if (verdict === undefined) {
|
|
82
|
+
throw new Error('admitted with no policy verdict')
|
|
83
|
+
}
|
|
84
|
+
return verdict
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
type Judged,
|
|
89
|
+
type PolicyIssue,
|
|
90
|
+
type PolicyVerdict,
|
|
91
|
+
admittedVerdict,
|
|
92
|
+
asJudged,
|
|
93
|
+
policyVerdict,
|
|
94
|
+
recordVerdict,
|
|
95
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UNNAMED_TIER, budgetTierLimits } from './budget-tiers.ts'
|
|
2
|
-
import { ratchetNote, ratchetSeverity } from './memory-
|
|
2
|
+
import { ratchetNote, ratchetSeverity } from './memory-armed.ts'
|
|
3
3
|
import { runtimeAccountedBytes } from './runtimeCost.ts'
|
|
4
4
|
|
|
5
5
|
import type { BudgetTier } from './budget-tiers.ts'
|
|
@@ -8,7 +8,7 @@ import type { BudgetTier } from './budget-tiers.ts'
|
|
|
8
8
|
type RuntimeTierSource = Readonly<{
|
|
9
9
|
runtime: Readonly<{ cost?: unknown }> | null
|
|
10
10
|
budgets: Readonly<{ client?: unknown; tier?: BudgetTier }>
|
|
11
|
-
/** J412: the zone whose
|
|
11
|
+
/** J412: the zone whose armed state applies (`memory-armed.ts`). */
|
|
12
12
|
identity?: Readonly<{ slug: string }>
|
|
13
13
|
}>
|
|
14
14
|
|
|
@@ -42,7 +42,7 @@ function runtimeTierIssues(source: RuntimeTierSource): RuntimeTierIssue[] {
|
|
|
42
42
|
return [
|
|
43
43
|
{
|
|
44
44
|
code: 'runtime-tier-memory',
|
|
45
|
-
metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)${severity === 'warning' ? ratchetNote(source.identity?.slug
|
|
45
|
+
metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)${severity === 'warning' ? ratchetNote(source.identity?.slug) : ''}`,
|
|
46
46
|
actual,
|
|
47
47
|
limit,
|
|
48
48
|
severity,
|
|
@@ -18,6 +18,8 @@ const positive = v.pipe(ShardNaturalSchema, v.minValue(1));
|
|
|
18
18
|
/** Finite wire number without an imposed gameplay range. */
|
|
19
19
|
export const ShardFiniteSchema: v.GenericSchema<ShardFiniteInput, ShardFinite> = v.pipe(v.number(), v.finite());
|
|
20
20
|
const name = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u), v.maxLength(limits.idCharacters));
|
|
21
|
+
/** A tick's time, in microseconds: at most one 60 Hz frame. */
|
|
22
|
+
const tickMicros = v.pipe(positive, v.maxValue(16_666));
|
|
21
23
|
/** Local SHA256 content identity. */
|
|
22
24
|
export const ShardHashSchema: v.GenericSchema<ShardHashInput, ShardHash> = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
|
|
23
25
|
/** Local or commons-qualified SHA256 content reference. */
|
|
@@ -50,7 +52,7 @@ export const SimSchema: v.GenericSchema<ShardSimInput, ShardSim> = v.strictObjec
|
|
|
50
52
|
/** Bounded player count and authored movement speed. */
|
|
51
53
|
export const AuthorCapsSchema: v.GenericSchema<ShardAuthorCapsInput, ShardAuthorCaps> = v.strictObject({ players: v.pipe(positive, v.maxValue(32)), speed: v.pipe(ShardFiniteSchema, v.minValue(0), v.maxValue(15)) });
|
|
52
54
|
/** Bounded authoritative simulation resource declarations. */
|
|
53
|
-
export const ServerBudgetSchema: v.GenericSchema<ShardServerBudgetInput, ShardServerBudget> = v.strictObject({ tickMicros
|
|
55
|
+
export const ServerBudgetSchema: v.GenericSchema<ShardServerBudgetInput, ShardServerBudget> = v.strictObject({ tickMicros, memory: positive, entities: v.pipe(ShardNaturalSchema, v.maxValue(10_000)), commandsPerTick: v.pipe(ShardNaturalSchema, v.maxValue(1024)), awakeMicros: v.exactOptional(tickMicros), shareWorker: v.exactOptional(name) });
|
|
54
56
|
/** Content-addressed file inventory and conservative costs. */
|
|
55
57
|
export const FilesSchema: v.GenericSchema<ShardFilesInput, ShardFiles> & { readonly pipe: readonly [v.ArraySchema<typeof file, undefined>, unknown] } = v.pipe(v.array(file), v.maxLength(limits.files));
|
|
56
58
|
/** Finite L0/L1 tile inventory. */
|
|
@@ -299,6 +301,10 @@ interface ShardServerBudgetInputFields {
|
|
|
299
301
|
memory: ShardNaturalInput;
|
|
300
302
|
entities: ShardNaturalInput;
|
|
301
303
|
commandsPerTick: ShardNaturalInput;
|
|
304
|
+
/** ONE-FORMAT OF31h2: the measured awake cost, mean microseconds a tick with one player in; the server weighs its workers by it. */
|
|
305
|
+
awakeMicros?: ShardNaturalInput;
|
|
306
|
+
/** OF31h2: the shard whose worker this one always shares. */
|
|
307
|
+
shareWorker?: string;
|
|
302
308
|
}
|
|
303
309
|
export type ShardServerBudgetInput = { [Key in keyof ShardServerBudgetInputFields]: ShardServerBudgetInputFields[Key] };
|
|
304
310
|
interface ShardServerBudgetFields {
|
|
@@ -306,6 +312,10 @@ interface ShardServerBudgetFields {
|
|
|
306
312
|
memory: ShardNatural;
|
|
307
313
|
entities: ShardNatural;
|
|
308
314
|
commandsPerTick: ShardNatural;
|
|
315
|
+
/** ONE-FORMAT OF31h2: the measured awake cost, mean microseconds a tick with one player in; the server weighs its workers by it. */
|
|
316
|
+
awakeMicros?: ShardNatural;
|
|
317
|
+
/** OF31h2: the shard whose worker this one always shares. */
|
|
318
|
+
shareWorker?: string;
|
|
309
319
|
}
|
|
310
320
|
export type ShardServerBudget = { [Key in keyof ShardServerBudgetFields]: ShardServerBudgetFields[Key] };
|
|
311
321
|
export type ShardFilesInput = (ShardFileRowsInput)[];
|
|
@@ -13,9 +13,10 @@ import type { Shardfile } from "./shardSchema.ts";
|
|
|
13
13
|
import type { ShardTerrain } from "./terrain.ts";
|
|
14
14
|
import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./budget.ts";
|
|
15
15
|
import { CONTENT_CAPS as C } from './contentBounds.ts';
|
|
16
|
-
import { ARMED_LINES } from './memory-armed.ts';
|
|
16
|
+
import { ARMED_LINES, ratchetLimit } from './memory-armed.ts';
|
|
17
|
+
import { asJudged } from './policy-verdict.ts';
|
|
18
|
+
import type { Judged } from './policy-verdict.ts';
|
|
17
19
|
import { staleRuntimeIssues } from './memory-epoch.ts';
|
|
18
|
-
import { ratchetLimit } from './memory-ratchet.ts';
|
|
19
20
|
import { MEMORY_HARD_BYTES, memoryLineIssues, runtimeOfflineBytes } from './memory-line.ts';
|
|
20
21
|
import { bootMemoryCosts } from './boot-memory-cost.ts';
|
|
21
22
|
import type { TierIndex } from './phone-files.ts';
|
|
@@ -28,7 +29,7 @@ import type { IssueCodeOf } from './issue-codes.ts';
|
|
|
28
29
|
import { isNavigationData, navigationCost } from './navigationBytes.ts';
|
|
29
30
|
|
|
30
31
|
type PerformancePolicy = 'refuse' | 'warn';
|
|
31
|
-
interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number; readonly index?: TierIndex }
|
|
32
|
+
interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number; readonly index?: TierIndex; readonly judged?: Judged }
|
|
32
33
|
|
|
33
34
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
34
35
|
function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number; index?: TierIndex }>): PerformanceReport['memory'] {
|
|
@@ -347,8 +348,8 @@ export function performanceReport(source: Shardfile, observations: PerformanceOb
|
|
|
347
348
|
if (observations.scripts.samples < 60 || observations.fuel.samples < 60) check(['perf-script-samples-missing', 'missing execution samples'], 60, Math.min(observations.scripts.samples, observations.fuel.samples));
|
|
348
349
|
// An explicit cold-network estimate, not a measured phone loading claim. The guide names both assumptions.
|
|
349
350
|
const bytesPerSecond = 1_000_000, setupSeconds = 1;
|
|
350
|
-
return { slug: source.identity.slug, policy, pass: !issues.some(issue => issue.severity === 'refusal'), native, memory, views, graphs, scripts: observations, download,
|
|
351
|
-
estimatedPlayable: { seconds: setupSeconds + download.playable / bytesPerSecond, bytesPerSecond, setupSeconds }, issues };
|
|
351
|
+
return { slug: source.identity.slug, policy, pass: !asJudged(issues, resolved.judged).some(issue => issue.severity === 'refusal'), native, memory, views, graphs, scripts: observations, download,
|
|
352
|
+
estimatedPlayable: { seconds: setupSeconds + download.playable / bytesPerSecond, bytesPerSecond, setupSeconds }, issues: asJudged(issues, resolved.judged) };
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
/** Human-readable card keeps estimates visibly distinct from measurements and prints every enforced limit. */
|
|
@@ -367,8 +368,11 @@ export function performanceReportLines(report: PerformanceReport): string[] {
|
|
|
367
368
|
...report.issues.map(issue => `${issue.severity.toUpperCase()}: ${issue.metric}: ${issue.actual} > ${issue.limit}`)];
|
|
368
369
|
}
|
|
369
370
|
|
|
370
|
-
/** Offline soft-cap policy and the hard loading ceiling (J445).
|
|
371
|
-
|
|
371
|
+
/** Offline soft-cap policy and the hard loading ceiling (J445). A stored shard file was judged at its upload (CP10):
|
|
372
|
+
* no memory line refuses it again. */
|
|
373
|
+
export function offlineMemoryAdmission(_policy: 'warn' | 'refuse', judged: 'upload' | 'stored' = 'upload'): MemoryAdmission {
|
|
372
374
|
// The hard loading ceiling applies to the armed list.
|
|
373
|
-
return new MemoryAdmission((): boolean => true,
|
|
375
|
+
return new MemoryAdmission((): boolean => true, judged === 'stored'
|
|
376
|
+
? (): number => Number.POSITIVE_INFINITY
|
|
377
|
+
: (owner, kind): number => ratchetLimit(owner, kind, MEMORY_HARD_BYTES));
|
|
374
378
|
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from './assetAdmission.ts'
|
|
11
11
|
import { issueError, withIssueCode } from './issue-codes.ts'
|
|
12
12
|
import { assembleOutputShardfile } from './outputIndex.ts'
|
|
13
|
+
import { admittedVerdict, recordVerdict } from './policy-verdict.ts'
|
|
13
14
|
import { offlineMemoryAdmission } from './shardfile-assets.ts'
|
|
14
15
|
import {
|
|
15
16
|
assertShardfileTargets,
|
|
@@ -20,6 +21,7 @@ import { validationSourceBytes } from './validationReceipt.ts'
|
|
|
20
21
|
|
|
21
22
|
import type { AssetAdmission } from './assetAdmission.ts'
|
|
22
23
|
import type { OutputIndex } from './outputIndex.ts'
|
|
24
|
+
import type { Judged, PolicyVerdict } from './policy-verdict.ts'
|
|
23
25
|
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
24
26
|
import type { AssetPasses } from './shardfile-stream-assets.ts'
|
|
25
27
|
import type { Shardfile } from './shardSchema.ts'
|
|
@@ -29,22 +31,24 @@ function admitHead(
|
|
|
29
31
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
30
32
|
index: OutputIndex,
|
|
31
33
|
payloads: ReadonlyMap<string, unknown>,
|
|
34
|
+
judged: Judged = 'upload',
|
|
32
35
|
): Shardfile {
|
|
33
36
|
const shard = withIssueCode('shard-schema', (): Shardfile =>
|
|
34
37
|
parseShardfile(assembleOutputShardfile(index, payloads), payloads),
|
|
35
38
|
)
|
|
36
39
|
withIssueCode('declared-costs', (): void => {
|
|
37
|
-
preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
|
|
40
|
+
preflightDeclaredCosts(shard, offlineMemoryAdmission('warn', judged))
|
|
38
41
|
})
|
|
39
|
-
withIssueCode('performance-targets', ():
|
|
42
|
+
const verdict = withIssueCode('performance-targets', (): PolicyVerdict =>
|
|
40
43
|
// MG6 epoch 5: the index lets the estimate count only the files a phone fetches (no mount bytes in the stream).
|
|
41
44
|
assertShardfileTargets(shard, 'warn', {
|
|
42
45
|
sections: payloads,
|
|
43
46
|
mountedImages: 0,
|
|
44
47
|
index,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
judged,
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
return recordVerdict(shard, verdict)
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/** The shard's head and its asset admission's first steps, or the refusal they gave: thrown only after the packs, the
|
|
@@ -54,15 +58,28 @@ function admitBeforeAssets(
|
|
|
54
58
|
index: OutputIndex,
|
|
55
59
|
payloads: ReadonlyMap<string, unknown>,
|
|
56
60
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's row type, only read
|
|
57
|
-
scripts: ScriptAdmissionRows
|
|
58
|
-
): Readonly<{
|
|
61
|
+
rows: Readonly<{ scripts: ScriptAdmissionRows; judged?: Judged | undefined }>,
|
|
62
|
+
): Readonly<{
|
|
63
|
+
admission: AssetAdmission | undefined
|
|
64
|
+
refusal: unknown
|
|
65
|
+
head?: Shardfile | undefined
|
|
66
|
+
judged?: Judged | undefined
|
|
67
|
+
}> {
|
|
68
|
+
const { scripts, judged } = rows
|
|
59
69
|
try {
|
|
60
|
-
const head = admitHead(index, payloads)
|
|
70
|
+
const head = admitHead(index, payloads, judged)
|
|
61
71
|
return {
|
|
62
72
|
admission: withIssueCode('asset-admission', (): AssetAdmission =>
|
|
63
|
-
assetAdmission(
|
|
73
|
+
assetAdmission(
|
|
74
|
+
head,
|
|
75
|
+
offlineMemoryAdmission('warn', judged),
|
|
76
|
+
scripts,
|
|
77
|
+
payloads,
|
|
78
|
+
),
|
|
64
79
|
),
|
|
65
80
|
refusal: undefined,
|
|
81
|
+
head,
|
|
82
|
+
judged,
|
|
66
83
|
}
|
|
67
84
|
} catch (error) {
|
|
68
85
|
return { admission: undefined, refusal: error }
|
|
@@ -72,12 +89,17 @@ function admitBeforeAssets(
|
|
|
72
89
|
/** `validateShardfileAssets` from the commons on, over what the later reads found. */
|
|
73
90
|
function admitAssets(
|
|
74
91
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- the admission state, which the commons update
|
|
75
|
-
before: Readonly<{
|
|
92
|
+
before: Readonly<{
|
|
93
|
+
admission: AssetAdmission | undefined
|
|
94
|
+
refusal: unknown
|
|
95
|
+
head?: Shardfile | undefined
|
|
96
|
+
judged?: Judged | undefined
|
|
97
|
+
}>,
|
|
76
98
|
later: Readonly<AssetPasses>,
|
|
77
99
|
hash: (bytes: Readonly<Uint8Array>) => string,
|
|
78
100
|
): Shardfile {
|
|
79
|
-
const { admission } = before
|
|
80
|
-
if (admission === undefined) {
|
|
101
|
+
const { admission, head } = before
|
|
102
|
+
if (admission === undefined || head === undefined) {
|
|
81
103
|
throw before.refusal
|
|
82
104
|
}
|
|
83
105
|
return withIssueCode('asset-admission', (): Shardfile => {
|
|
@@ -88,10 +110,13 @@ function admitAssets(
|
|
|
88
110
|
if (refused !== undefined) {
|
|
89
111
|
throw new Error(refused)
|
|
90
112
|
}
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
return recordVerdict(
|
|
114
|
+
admitAfterFiles(
|
|
115
|
+
admission,
|
|
116
|
+
later.assets,
|
|
117
|
+
offlineMemoryAdmission('warn', before.judged),
|
|
118
|
+
),
|
|
119
|
+
admittedVerdict(head),
|
|
95
120
|
)
|
|
96
121
|
})
|
|
97
122
|
}
|
|
@@ -164,7 +164,9 @@ function cookSteps(replay: Readonly<Replay>, index: OutputIndex): void {
|
|
|
164
164
|
index.cook === undefined
|
|
165
165
|
? undefined
|
|
166
166
|
: readCookData(readCanonicalJson(listedBytes(replay, index.cook)))
|
|
167
|
-
|
|
167
|
+
withIssueCode('preparation-invalid', (): void => {
|
|
168
|
+
requireCookPreparation(index, cook, replay.hash)
|
|
169
|
+
})
|
|
168
170
|
for (const mount of cook?.mounts ?? []) {
|
|
169
171
|
if (!mountSharesBlob(mount, index.files)) {
|
|
170
172
|
if (mount.path !== cookMountPath(mount.url)) {
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
// outside `blobs/`, `mounts/` and `packs/` are kept whole. Then the old
|
|
9
9
|
// validator's steps run in its order, so a refusal is the one it gives (its
|
|
10
10
|
// message may differ only for a blob whose declared kind contradicts its path).
|
|
11
|
-
//
|
|
12
11
|
// AC6a2: `validateShardfileAssets`' byte checks and the pack checks read
|
|
13
12
|
// assets by hash in any order (153 MB of blobs on the 327 MB pin), so they
|
|
14
|
-
// take a second read of the stored object (shardfile-stream-assets.ts), and a
|
|
15
|
-
//
|
|
16
|
-
// `open`: a host passes a function that opens the stored object afresh.
|
|
13
|
+
// take a second read of the stored object (shardfile-stream-assets.ts), and a further read per group of left-out
|
|
14
|
+
// packs (shardfile-stream-packs.ts). Hence `open`: a host passes a function that opens the stored object afresh.
|
|
17
15
|
|
|
18
16
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts'
|
|
17
|
+
import { deprecationReport } from './deprecations.ts'
|
|
19
18
|
import { assertSectionSides } from './feature-sides.ts'
|
|
20
19
|
import { issueError, withIssueCode } from './issue-codes.ts'
|
|
21
20
|
import { parseOutputIndex, validateOutputSection } from './outputIndex.ts'
|
|
21
|
+
import { admittedVerdict } from './policy-verdict.ts'
|
|
22
22
|
import { assertScriptSides } from './script-sides.ts'
|
|
23
23
|
import { scriptAdmissionRows } from './scriptContract.ts'
|
|
24
24
|
import { prepareAssetDecoders } from './shardfile-assets.ts'
|
|
@@ -37,7 +37,9 @@ import {
|
|
|
37
37
|
import { walkTar } from './shardfile-stream-tar.ts'
|
|
38
38
|
import { readCanonicalJson } from './shardfileValidation.ts'
|
|
39
39
|
|
|
40
|
+
import type { DeprecationReport } from './deprecations.ts'
|
|
40
41
|
import type { OutputIndex } from './outputIndex.ts'
|
|
42
|
+
import type { Judged, PolicyVerdict } from './policy-verdict.ts'
|
|
41
43
|
import type { ScriptAdmissionRows } from './scriptContract.ts'
|
|
42
44
|
import type { StoredSource } from './shardfile-stream-assets.ts'
|
|
43
45
|
import type { KeptMember, Replay } from './shardfile-stream-rows.ts'
|
|
@@ -58,10 +60,11 @@ interface StreamValidationPorts {
|
|
|
58
60
|
readonly decode?: (
|
|
59
61
|
stored: AsyncIterable<Uint8Array>,
|
|
60
62
|
) => AsyncIterable<Uint8Array>
|
|
63
|
+
readonly judged?: Judged
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
/** What one streaming validation found. */
|
|
64
|
-
interface StreamedShardfile {
|
|
67
|
+
interface StreamedShardfile extends DeprecationReport {
|
|
65
68
|
/** SHA-256 and byte length of the stored object, before decoding. */
|
|
66
69
|
readonly hash: string
|
|
67
70
|
readonly bytes: number
|
|
@@ -71,8 +74,7 @@ interface StreamedShardfile {
|
|
|
71
74
|
readonly shard: Shardfile
|
|
72
75
|
readonly sections: ReadonlyMap<string, unknown>
|
|
73
76
|
readonly scripts: ScriptAdmissionRows
|
|
74
|
-
|
|
75
|
-
readonly warnings: readonly string[]
|
|
77
|
+
readonly policy: PolicyVerdict
|
|
76
78
|
/** True only when every check `validateShardfileFolder` runs has run: always, since AC6a2. */
|
|
77
79
|
readonly complete: boolean
|
|
78
80
|
/** The checks still to run, by name, while `complete` is false: none, since AC6a2. */
|
|
@@ -263,7 +265,7 @@ async function validateShardfileStream(
|
|
|
263
265
|
)
|
|
264
266
|
const { sections, warnings, scripts } = readSections(replay, index)
|
|
265
267
|
replayBeforePacks(replay, index, scripts)
|
|
266
|
-
const before = admitBeforeAssets(index, sections, scripts)
|
|
268
|
+
const before = admitBeforeAssets(index, sections, { ...ports, scripts })
|
|
267
269
|
const later = await assetPasses({
|
|
268
270
|
open,
|
|
269
271
|
ports,
|
|
@@ -284,7 +286,8 @@ async function validateShardfileStream(
|
|
|
284
286
|
shard,
|
|
285
287
|
sections,
|
|
286
288
|
scripts,
|
|
287
|
-
warnings,
|
|
289
|
+
...deprecationReport({ index, sections }, warnings),
|
|
290
|
+
policy: admittedVerdict(shard),
|
|
288
291
|
complete: true,
|
|
289
292
|
pending: [],
|
|
290
293
|
heldBytes: Math.max(walked.heldBytes, later.heldBytes),
|
|
@@ -25,6 +25,10 @@ import { memoryContext, offlineMemoryIssues } from './memory-line.ts';
|
|
|
25
25
|
import { runtimeTierIssues } from './runtime-tier.ts';
|
|
26
26
|
import type { MemoryContext } from './memory-line.ts';
|
|
27
27
|
import { mountedImageBytes, NO_BYTES } from './boot-memory-cost.ts';
|
|
28
|
+
import { admittedVerdict, policyVerdict, recordVerdict } from './policy-verdict.ts';
|
|
29
|
+
import type { Judged, PolicyVerdict } from './policy-verdict.ts';
|
|
30
|
+
import { deprecationReport } from './deprecations.ts';
|
|
31
|
+
import type { DeprecationReport } from './deprecations.ts';
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* P1-F3 format validation of a built shardfile product (format 2: `shard.json`, sections, blobs, packs): the schema,
|
|
@@ -54,13 +58,19 @@ export interface ShardfileValidationPorts {
|
|
|
54
58
|
readonly definedJson?: (schemaBytes: Uint8Array, bytes: Uint8Array, name: string | undefined) => void;
|
|
55
59
|
/** Import check for a copied `runtime/` file (the retired copied-runtime arm). Without it such files are refused. */
|
|
56
60
|
readonly runtimeImports?: (path: string, source: string) => void;
|
|
61
|
+
/** SHARD-COMPAT CP10: `'stored'` for a shard file already admitted (a stored original, an engine pin, a cook): memory
|
|
62
|
+
* and budget policy only reports, since it was judged at upload. Default `'upload'`: the policy refuses. */
|
|
63
|
+
readonly judged?: Judged;
|
|
57
64
|
/** D31: hold no file's bytes between checks. `assets`, here and in the result, reads each file again from `files`, so a
|
|
58
65
|
* host's peak is its largest file rather than the shard, at the cost of those repeat reads. */
|
|
59
66
|
readonly readThrough?: boolean;
|
|
67
|
+
/** SHARD-COMPAT CP1: `'migrated'` for a migrated copy (`validateMigrated`), whose author preparation a render step may
|
|
68
|
+
* have left stale for the box's cook; the preparation check is skipped. Default `'author'`. */
|
|
69
|
+
readonly preparation?: 'author' | 'migrated';
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
/** A product that passed format validation. */
|
|
63
|
-
export interface ValidatedShardfile {
|
|
73
|
+
export interface ValidatedShardfile extends DeprecationReport {
|
|
64
74
|
readonly index: OutputIndex;
|
|
65
75
|
readonly shard: Shardfile;
|
|
66
76
|
/** Admitted bytes by hash (`commons:<hash>` for pinned commons). */
|
|
@@ -69,8 +79,8 @@ export interface ValidatedShardfile {
|
|
|
69
79
|
readonly sections: ReadonlyMap<string, unknown>;
|
|
70
80
|
/** The script admission rows the product was admitted with. */
|
|
71
81
|
readonly scripts: ScriptAdmissionRows;
|
|
72
|
-
/**
|
|
73
|
-
readonly
|
|
82
|
+
/** CP10: the policy verdict and its rule version, for the API to store beside an upload. */
|
|
83
|
+
readonly policy: PolicyVerdict;
|
|
74
84
|
/** AUDIO AU5: the shard's own recordings (audio mounts and non-commons `audio.recordings`), measured from their bytes. */
|
|
75
85
|
readonly audio: readonly RecordingMeasure[];
|
|
76
86
|
}
|
|
@@ -110,22 +120,24 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
|
|
|
110
120
|
return kind;
|
|
111
121
|
}
|
|
112
122
|
|
|
113
|
-
/** Refuse the declared targets a policy treats as refusals, before any byte is read or executed.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
/** Refuse the declared targets a policy treats as refusals, before any byte is read or executed; return the verdict.
|
|
124
|
+
* A stored shard file (CP10, the context's `judged`) is never refused here: it was judged at its upload. */
|
|
125
|
+
export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', context: MemoryContext = new Map()): PolicyVerdict {
|
|
126
|
+
// J412: the memory gates are ratchets; an issue in a zone not armed reports (`memory-armed.ts`) and is not thrown here.
|
|
127
|
+
const found = [...staleRuntimeIssues(source.runtime, undefined, source.identity), ...offlineMemoryIssues(source, context), ...runtimeTierIssues(source), ...performanceTargetIssues(source, policy)];
|
|
128
|
+
const issues = found.filter(issue => issue.severity === 'refusal'), judged = memoryContext(context).judged ?? 'upload';
|
|
129
|
+
if (issues.length > 0 && judged === 'upload') throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
|
|
130
|
+
return policyVerdict(source.identity.slug, judged, found);
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
/** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
|
|
122
134
|
export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
|
|
123
135
|
policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], context?: MemoryContext): Shardfile {
|
|
124
|
-
const sections = context === undefined ? undefined : memoryContext(context)
|
|
136
|
+
const { sections, judged } = context === undefined ? { sections: undefined, judged: undefined } : memoryContext(context);
|
|
125
137
|
const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
|
|
126
|
-
coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
|
|
127
|
-
coded('performance-targets', ():
|
|
128
|
-
return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts, sections));
|
|
138
|
+
coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy, judged)); });
|
|
139
|
+
const verdict = coded('performance-targets', (): PolicyVerdict => assertShardfileTargets(source, policy, context));
|
|
140
|
+
return recordVerdict(coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy, judged), undefined, scripts, sections)), verdict);
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
/** Refuse world target rows that name items or quests the shardfile does not declare. */
|
|
@@ -190,10 +202,10 @@ function checkServerAndKtx2(index: OutputIndex, read: ReadListed, assets: Readon
|
|
|
190
202
|
|
|
191
203
|
/** C0 (J137): the cook file; a mount passes the same hash and size checks as any listed file (`cook-invalid`). */
|
|
192
204
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
193
|
-
function readCook(index: OutputIndex, read: ReadListed,
|
|
205
|
+
function readCook(index: OutputIndex, read: ReadListed, ports: Pick<ShardfileValidationPorts, 'hash' | 'preparation'>): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } {
|
|
194
206
|
return coded('cook-invalid', (): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } => {
|
|
195
207
|
const cook = index.cook === undefined ? undefined : readCookData(readCanonicalJson(read(index.cook)));
|
|
196
|
-
requireCookPreparation(index, cook, hash);
|
|
208
|
+
if (ports.preparation !== 'migrated') { coded('preparation-invalid', (): void => { requireCookPreparation(index, cook, ports.hash); }); }
|
|
197
209
|
let mountedImages = NO_BYTES;
|
|
198
210
|
for (const mount of cook?.mounts ?? []) {
|
|
199
211
|
if (!mountSharesBlob(mount, index.files)) {
|
|
@@ -232,14 +244,14 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
|
|
|
232
244
|
}
|
|
233
245
|
checkServerAndKtx2(index, read, assets);
|
|
234
246
|
coded('pack-invalid', (): void => { checkPacks(index, new Set(files.paths()), { readFile: files.read, readListed: read, verify, hash: ports.hash }); });
|
|
235
|
-
const { cook, mountedImages } = readCook(index, read, ports
|
|
247
|
+
const { cook, mountedImages } = readCook(index, read, ports);
|
|
236
248
|
for (const entry of index.runtime?.files ?? []) {
|
|
237
249
|
if (ports.runtimeImports === undefined) throw issueError('runtime-files', 'Copied runtime files need a runtime import checker');
|
|
238
250
|
coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
|
|
239
251
|
}
|
|
240
252
|
for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
|
|
241
|
-
const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages, index });
|
|
253
|
+
const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages, index, judged: ports.judged ?? 'upload' });
|
|
242
254
|
checkWorldTargets(shard, payloads.get('world/targets'));
|
|
243
255
|
if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
|
|
244
|
-
return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
|
|
256
|
+
return { index, shard, assets, sections: payloads, scripts, ...deprecationReport({ index, sections: payloads }, warnings), policy: admittedVerdict(shard), audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
|
|
245
257
|
}
|
|
@@ -16,7 +16,7 @@ export function parseStateLineage(input: unknown): StateLineage { return v.parse
|
|
|
16
16
|
const path = v.pipe(v.string(), v.maxLength(240), v.regex(/^(?:[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/u));
|
|
17
17
|
const measured = { path, hash: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u)),
|
|
18
18
|
bytes: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)) };
|
|
19
|
-
const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.
|
|
19
|
+
const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: v.literal(2), sdk: v.picklist(['0.2', '0.3']),
|
|
20
20
|
version: v.picklist(SHARDFILE_VERSIONS), identity,
|
|
21
21
|
sections: v.pipe(v.array(v.strictObject({ ...measured, name: v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9-]*\/[a-zA-Z][a-zA-Z0-9_-]*$/u)),
|
|
22
22
|
schema: v.pipe(v.string(), v.maxLength(240)) })), v.maxLength(256)),
|
package/src/format/version.ts
CHANGED
|
@@ -42,40 +42,38 @@ function compareShardfileVersions(left: unknown, right: unknown): number {
|
|
|
42
42
|
return ZERO
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
45
|
+
/** The oldest format a reader admits (J486). Below it a shard file needs the migration chain or a re-upload. */
|
|
46
|
+
const SHARDFILE_FLOOR = '0.1.0.0'
|
|
47
|
+
|
|
48
|
+
/** A reader admits every format at or below its own in the same breaking format, down to the floor (J486,
|
|
49
|
+
* replacing WR11's N and N-1 window). Additive counters only add optional fields, so an older file is still a
|
|
50
|
+
* valid file; a newer one can carry declarations the reader does not know, so it waits for a newer reader. */
|
|
47
51
|
function compatibleShardfileVersion(
|
|
48
52
|
input: unknown,
|
|
49
53
|
reader: unknown = SHARDFILE_VERSION,
|
|
50
54
|
): boolean {
|
|
51
55
|
try {
|
|
52
|
-
const [major, minor, breaking
|
|
53
|
-
const [readMajor, readMinor, readBreaking
|
|
54
|
-
parseShardfileVersion(reader)
|
|
56
|
+
const [major, minor, breaking] = parseShardfileVersion(input)
|
|
57
|
+
const [readMajor, readMinor, readBreaking] = parseShardfileVersion(reader)
|
|
55
58
|
return (
|
|
56
59
|
major === readMajor &&
|
|
57
60
|
minor === readMinor &&
|
|
58
61
|
breaking === readBreaking &&
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
compareShardfileVersions(input, reader) <= ZERO &&
|
|
63
|
+
compareShardfileVersions(input, SHARDFILE_FLOOR) >= ZERO
|
|
61
64
|
)
|
|
62
65
|
} catch {
|
|
63
66
|
return false
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
/** Legacy callers use this only to validate the era's decimal minor; new code compares all four components. */
|
|
68
|
-
function shardfileRevision(input: unknown): number {
|
|
69
|
-
return parseShardfileVersion(input)[ONE]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
70
|
export {
|
|
73
71
|
SHARDFILE_VERSION,
|
|
74
72
|
SHARDFILE_VERSIONS,
|
|
73
|
+
SHARDFILE_FLOOR,
|
|
75
74
|
type ShardfileVersion,
|
|
76
75
|
type ShardfileVersionParts,
|
|
77
76
|
parseShardfileVersion,
|
|
78
77
|
compareShardfileVersions,
|
|
79
78
|
compatibleShardfileVersion,
|
|
80
|
-
shardfileRevision,
|
|
81
79
|
}
|