@wildshard/shard-format 0.67.0 → 0.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +7 -19
  2. package/src/cli/corpus-deprecations.ts +57 -0
  3. package/src/cli/corpus-gate.ts +114 -0
  4. package/src/cli/corpus-migrated.ts +68 -0
  5. package/src/cli/corpus.ts +300 -0
  6. package/src/cli/main.ts +41 -0
  7. package/src/format/cook-preparation.ts +22 -6
  8. package/src/format/creature-layers.ts +4 -0
  9. package/src/format/deprecations.ts +228 -0
  10. package/src/format/empty-shardfile.json +56 -0
  11. package/src/format/empty-shardfile.ts +43 -0
  12. package/src/format/format-migrate-inventory.ts +142 -0
  13. package/src/format/format-migrate-rebuild.ts +269 -0
  14. package/src/format/format-migrate.ts +290 -0
  15. package/src/format/format-migration-journal.ts +129 -0
  16. package/src/format/format-migration-ops.ts +230 -0
  17. package/src/format/format-migration-prune.ts +106 -0
  18. package/src/format/format-migrations.ts +124 -0
  19. package/src/format/issue-codes.ts +3 -1
  20. package/src/format/journal-glyphs.json +12 -0
  21. package/src/format/memory-armed.json +1 -39
  22. package/src/format/memory-armed.ts +41 -8
  23. package/src/format/memory-epoch.ts +2 -2
  24. package/src/format/memory-line.ts +4 -3
  25. package/src/format/memoryAdmission.ts +1 -1
  26. package/src/format/policy-verdict.ts +95 -0
  27. package/src/format/rows.ts +6 -4
  28. package/src/format/runtime-tier.ts +3 -3
  29. package/src/format/shardSections.ts +11 -1
  30. package/src/format/shardfile-assets.ts +12 -8
  31. package/src/format/shardfile-stream-admit.ts +41 -16
  32. package/src/format/shardfile-stream-rows.ts +3 -1
  33. package/src/format/shardfile-stream.ts +12 -9
  34. package/src/format/shardfileValidation.ts +30 -18
  35. package/src/format/stateLineage.ts +1 -1
  36. package/src/format/version.ts +11 -13
  37. package/src/format/baked-terrain.golden.json +0 -2760
  38. package/src/format/colliders.golden.json +0 -1619
  39. package/src/format/forest-placement.golden.json +0 -4588
  40. package/src/format/geometry-layout.golden.json +0 -180
  41. package/src/format/interact-table.golden.json +0 -340
  42. package/src/format/item-catalogue.golden.json +0 -2310
  43. package/src/format/memory-ratchet.ts +0 -107
  44. package/src/format/small-laws.golden.json +0 -57
  45. package/src/format/terrain-field.golden.json +0 -3998
@@ -0,0 +1,230 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types -- an op edits the shard it is handed, in place
2
+ /** The migration chain's ops (SHARD-COMPAT FE8): small data-only edits a step is built from, so a step reads as what it
3
+ * changes. Each op addresses one JSON document (the index, a section by name, or a JSON cook mount by path) and a key
4
+ * path inside it, where `*` stands for every element of an array or every value of an object. */
5
+ import type { MigratingShard } from './format-migrations.ts'
6
+
7
+ type JsonRecord = Record<string, unknown>
8
+ type Op = (shard: MigratingShard) => void
9
+
10
+ /** The document an op edits. */
11
+ type Target =
12
+ | { readonly index: true }
13
+ | { readonly section: string }
14
+ | { readonly mount: string }
15
+
16
+ const EVERY = '*'
17
+ const NONE = 0
18
+
19
+ function isRecord(value: unknown): value is JsonRecord {
20
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
21
+ }
22
+
23
+ function documentOf(shard: Readonly<MigratingShard>, target: Target): unknown {
24
+ if ('index' in target) {
25
+ return shard.index
26
+ }
27
+ if ('section' in target) {
28
+ return shard.sections.get(target.section)
29
+ }
30
+ return shard.mounts.get(target.mount)
31
+ }
32
+
33
+ /** The children `key` names under each of `values`. */
34
+ function step(values: readonly unknown[], key: string): unknown[] {
35
+ return values.flatMap((value: unknown): unknown[] => {
36
+ if (key === EVERY) {
37
+ if (Array.isArray(value)) {
38
+ return value
39
+ }
40
+ return isRecord(value) ? Object.values(value) : []
41
+ }
42
+ return isRecord(value) && Object.hasOwn(value, key) ? [value[key]] : []
43
+ })
44
+ }
45
+
46
+ /** Every object at `path` in the target document. */
47
+ function objectsAt(
48
+ shard: Readonly<MigratingShard>,
49
+ target: Target,
50
+ path: readonly string[],
51
+ ): JsonRecord[] {
52
+ let values: unknown[] = [documentOf(shard, target)]
53
+ for (const key of path) {
54
+ values = step(values, key)
55
+ }
56
+ return values.filter((value: unknown): value is JsonRecord => isRecord(value))
57
+ }
58
+
59
+ /** Rewrite an object's own keys in order, so a renamed key keeps its place. */
60
+ function rewriteKeys(
61
+ row: JsonRecord,
62
+ entries: readonly (readonly [string, unknown])[],
63
+ ): void {
64
+ for (const key of Object.keys(row)) {
65
+ Reflect.deleteProperty(row, key)
66
+ }
67
+ for (const [key, value] of entries) {
68
+ row[key] = value
69
+ }
70
+ }
71
+
72
+ /** `from` becomes `to` in each object at `path`; an object holding both with different values is refused. */
73
+ function rename(
74
+ target: Target,
75
+ path: readonly string[],
76
+ keys: Readonly<{ from: string; to: string }>,
77
+ ): Op {
78
+ return (shard: MigratingShard): void => {
79
+ for (const row of objectsAt(shard, target, path)) {
80
+ if (Object.hasOwn(row, keys.from)) {
81
+ if (Object.hasOwn(row, keys.to) && row[keys.to] !== row[keys.from]) {
82
+ throw new Error(`Rename ${keys.from} to ${keys.to}: both are set`)
83
+ }
84
+ const entries = Object.entries(row)
85
+ .filter(
86
+ ([key]: readonly [string, unknown]): boolean => key !== keys.to,
87
+ )
88
+ .map(
89
+ ([key, value]: readonly [string, unknown]): readonly [
90
+ string,
91
+ unknown,
92
+ ] => (key === keys.from ? [keys.to, value] : [key, value]),
93
+ )
94
+ rewriteKeys(row, entries)
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ /** `key` leaves each object at `path`. */
101
+ function drop(target: Target, path: readonly string[], key: string): Op {
102
+ return (shard: MigratingShard): void => {
103
+ for (const row of objectsAt(shard, target, path)) {
104
+ Reflect.deleteProperty(row, key)
105
+ }
106
+ }
107
+ }
108
+
109
+ /** Each object at `path` without `key` gets `value` (a fresh copy each time). */
110
+ function fill(
111
+ target: Target,
112
+ path: readonly string[],
113
+ field: Readonly<{ key: string; value: unknown }>,
114
+ ): Op {
115
+ return (shard: MigratingShard): void => {
116
+ for (const row of objectsAt(shard, target, path)) {
117
+ if (!Object.hasOwn(row, field.key)) {
118
+ row[field.key] = structuredClone(field.value)
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ /** Each object at `path` holding `key` has its value replaced by `change(value)`. */
125
+ function map(
126
+ target: Target,
127
+ path: readonly string[],
128
+ field: Readonly<{ key: string; change: (value: unknown) => unknown }>,
129
+ ): Op {
130
+ return (shard: MigratingShard): void => {
131
+ for (const row of objectsAt(shard, target, path)) {
132
+ if (Object.hasOwn(row, field.key)) {
133
+ row[field.key] = field.change(row[field.key])
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ /** The section `from` becomes `to` under schema id `schema`: its payload, index row and file path move together. */
140
+ function moveSection(
141
+ sections: Readonly<{ from: string; to: string; schema: string }>,
142
+ ): Op {
143
+ return (shard: MigratingShard): void => {
144
+ const payload = shard.sections.get(sections.from)
145
+ const rows: unknown = shard.index['sections']
146
+ const row: unknown = Array.isArray(rows)
147
+ ? rows.find(
148
+ (entry: unknown): boolean =>
149
+ isRecord(entry) && entry['name'] === sections.from,
150
+ )
151
+ : undefined
152
+ if (payload === undefined || !isRecord(row)) {
153
+ return
154
+ }
155
+ if (shard.sections.has(sections.to)) {
156
+ throw new Error(`Move ${sections.from} to ${sections.to}: it exists`)
157
+ }
158
+ shard.sections.delete(sections.from)
159
+ shard.sections.set(sections.to, payload)
160
+ Object.assign(row, {
161
+ name: sections.to,
162
+ path: `sections/${sections.to}.json`,
163
+ schema: sections.schema,
164
+ })
165
+ }
166
+ }
167
+
168
+ /** Every string equal to `from` under one of `keys`, anywhere in a section or JSON mount, becomes `to`. */
169
+ function renameKind(
170
+ kinds: Readonly<{ from: string; to: string; keys: readonly string[] }>,
171
+ ): Op {
172
+ const keys = new Set(kinds.keys)
173
+ const visit = (value: unknown): void => {
174
+ if (Array.isArray(value)) {
175
+ for (const item of value) {
176
+ visit(item)
177
+ }
178
+ } else if (isRecord(value)) {
179
+ for (const [key, item] of Object.entries(value)) {
180
+ if (keys.has(key) && item === kinds.from) {
181
+ value[key] = kinds.to
182
+ } else {
183
+ visit(item)
184
+ }
185
+ }
186
+ }
187
+ }
188
+ return (shard: MigratingShard): void => {
189
+ for (const value of [
190
+ ...shard.sections.values(),
191
+ ...shard.mounts.values(),
192
+ ]) {
193
+ visit(value)
194
+ }
195
+ }
196
+ }
197
+
198
+ /** Run ops in order as one step's `apply`. */
199
+ function ops(...steps: readonly Op[]): Op {
200
+ return (shard: MigratingShard): void => {
201
+ for (const op of steps) {
202
+ op(shard)
203
+ }
204
+ }
205
+ }
206
+
207
+ /** Whether any object at `path` still holds `key` (a repair step's `repairs`). */
208
+ function holds(
209
+ target: Target,
210
+ path: readonly string[],
211
+ key: string,
212
+ ): (shard: Readonly<MigratingShard>) => boolean {
213
+ return (shard: Readonly<MigratingShard>): boolean =>
214
+ objectsAt(shard, target, path).filter(
215
+ (row: Readonly<JsonRecord>): boolean => Object.hasOwn(row, key),
216
+ ).length > NONE
217
+ }
218
+
219
+ export {
220
+ type Op,
221
+ type Target,
222
+ drop,
223
+ fill,
224
+ holds,
225
+ map,
226
+ moveSection,
227
+ ops,
228
+ rename,
229
+ renameKind,
230
+ }
@@ -0,0 +1,106 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types -- a step edits the shard it is handed, in place
2
+ /** FORMAT-PRUNE's same-version chain steps (J486): each writes the one way a 0.1.0.1 reader already admits, so writers
3
+ * can stop writing the other way with no format bump. Both are repairs: they also run on 0.1.0.1 files that still carry
4
+ * the old shape. Refusing the old shape in new uploads waits until the API and engine read migrated copies (CP2, FE9). */
5
+ import type { FormatMigration, MigratingShard } from './format-migrations.ts'
6
+
7
+ type JsonRecord = Record<string, unknown>
8
+
9
+ const OLD_POINTER = 'gridShardfile'
10
+ const POINTER = 'shardfile'
11
+ const CURRENT = '0.1.0.1'
12
+ const NONE = 0
13
+
14
+ function isRecord(value: unknown): value is JsonRecord {
15
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
16
+ }
17
+
18
+ /** Each object under `value`, depth first. */
19
+ function objects(value: unknown, found: JsonRecord[]): JsonRecord[] {
20
+ if (Array.isArray(value)) {
21
+ for (const item of value) {
22
+ objects(item, found)
23
+ }
24
+ } else if (isRecord(value)) {
25
+ found.push(value)
26
+ for (const item of Object.values(value)) {
27
+ objects(item, found)
28
+ }
29
+ }
30
+ return found
31
+ }
32
+
33
+ /** Every object holding the old pointer, in each section and each JSON cook mount. */
34
+ function pointerObjects(
35
+ shard: Readonly<MigratingShard>,
36
+ ): readonly JsonRecord[] {
37
+ const found: JsonRecord[] = []
38
+ for (const value of [...shard.sections.values(), ...shard.mounts.values()]) {
39
+ objects(value, found)
40
+ }
41
+ return found.filter((row: Readonly<JsonRecord>): boolean =>
42
+ Object.hasOwn(row, OLD_POINTER),
43
+ )
44
+ }
45
+
46
+ /** Rename the old pointer key in place, keeping its position; naming two different files is refused, as the engine's
47
+ * lift refuses it (`legacyPointer.ts`). */
48
+ function renamePointer(row: JsonRecord): void {
49
+ const { [OLD_POINTER]: old, [POINTER]: now } = row
50
+ if (now !== undefined && old !== undefined && now !== old) {
51
+ throw new Error('A manifest names its shardfile once')
52
+ }
53
+ const entries = Object.entries(row)
54
+ for (const [key] of entries) {
55
+ Reflect.deleteProperty(row, key)
56
+ }
57
+ for (const [key, value] of entries) {
58
+ if (key !== OLD_POINTER) {
59
+ row[key] = value
60
+ } else if (now === undefined && old !== undefined) {
61
+ row[POINTER] = value
62
+ }
63
+ }
64
+ }
65
+
66
+ /** FORMAT-PRUNE FP8: `gridShardfile` becomes `shardfile`, in the level manifest and the discovery mount alike. */
67
+ const shardfilePointer: FormatMigration = {
68
+ id: 'fp8-shardfile-pointer',
69
+ to: CURRENT,
70
+ touches: 'data',
71
+ affects: [],
72
+ apply: (shard: MigratingShard): void => {
73
+ for (const row of pointerObjects(shard)) {
74
+ renamePointer(row)
75
+ }
76
+ },
77
+ repairs: (shard: Readonly<MigratingShard>): boolean =>
78
+ pointerObjects(shard).length > NONE,
79
+ }
80
+
81
+ function runtimeOf(shard: Readonly<MigratingShard>): JsonRecord | undefined {
82
+ const { runtime } = shard.index
83
+ return isRecord(runtime) ? runtime : undefined
84
+ }
85
+
86
+ function carriesTrust(shard: Readonly<MigratingShard>): boolean {
87
+ const runtime = runtimeOf(shard)
88
+ return runtime !== undefined && Object.hasOwn(runtime, 'trust')
89
+ }
90
+
91
+ /** FORMAT-PRUNE FP3: `runtime.trust` has no reader in any repo; the copy drops it. */
92
+ const dropRuntimeTrust: FormatMigration = {
93
+ id: 'fp3-drop-runtime-trust',
94
+ to: CURRENT,
95
+ touches: 'data',
96
+ affects: [],
97
+ apply: (shard: MigratingShard): void => {
98
+ const runtime = runtimeOf(shard)
99
+ if (runtime !== undefined) {
100
+ Reflect.deleteProperty(runtime, 'trust')
101
+ }
102
+ },
103
+ repairs: carriesTrust,
104
+ }
105
+
106
+ export { dropRuntimeTrust, shardfilePointer }
@@ -0,0 +1,124 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types -- a step edits the shard it is handed, in place
2
+ /** The migration chain's registry (SHARD-COMPAT CP1, J486). A migration is one pure, data-only step that rewrites an
3
+ * older shard file's JSON to a newer format version. It is not a save migration (`migrations.ts`) and not a catalogue
4
+ * schema change (api-server). The change's author adds its migration here in the same release (J486, Q49). */
5
+ import { journalGlyphImages } from './format-migration-journal.ts'
6
+ import { dropRuntimeTrust, shardfilePointer } from './format-migration-prune.ts'
7
+ import {
8
+ SHARDFILE_VERSIONS,
9
+ compareShardfileVersions,
10
+ parseShardfileVersion,
11
+ } from './version.ts'
12
+
13
+ /** What a migration may read and rewrite: the parsed `shard.json`, each section by name and each JSON cook mount under
14
+ * `mounts/` by path. */
15
+ interface MigratingShard {
16
+ readonly index: Record<string, unknown>
17
+ readonly sections: Map<string, unknown>
18
+ readonly mounts: Map<string, unknown>
19
+ }
20
+
21
+ /** One step of the chain. `to` is the format version the step writes; it runs on every file below it. A repair step
22
+ * (`repairs`) also runs on a file already at `to` when `repairs` finds the old shape there: a break that shipped
23
+ * inside `to`, or a second way `to` still admits. */
24
+ interface FormatMigration {
25
+ readonly id: string
26
+ readonly to: string
27
+ /** `data` edits JSON the preparation does not fence; `files` reaches what it does (named JSON blobs, programs), so
28
+ * like `affects: render` the copy's author preparation is stale and the box's cook prepares again (SP1b). */
29
+ readonly touches: 'data' | 'files'
30
+ /** `render` leaves the author preparation stale for the box's cook (SP1b); `save` needs a save migration (J197). */
31
+ readonly affects: readonly ('render' | 'save')[]
32
+ /** The save migration a step that `affects: save` ships with (J197): what players' saved state does across it. */
33
+ readonly saveMigration?: string
34
+ readonly apply: (shard: MigratingShard) => void
35
+ readonly repairs?: (shard: Readonly<MigratingShard>) => boolean
36
+ }
37
+
38
+ const TWO_PART = 2
39
+ const ZERO = 0
40
+ const ONE = 1
41
+ const LEGACY_SPELLING = '0.1'
42
+ const FOUR_PART_ZERO = '0.1.0.0'
43
+
44
+ /** FORMAT-PRUNE FP6: the two-part spelling `0.1` becomes `0.1.0.0`, the same format written the one way. */
45
+ const fourPartVersion: FormatMigration = {
46
+ id: 'fp6-four-part-version',
47
+ to: FOUR_PART_ZERO,
48
+ touches: 'data',
49
+ affects: [],
50
+ apply: (shard: Readonly<MigratingShard>): void => {
51
+ const { requires } = shard.index
52
+ if (
53
+ typeof requires === 'object' &&
54
+ requires !== null &&
55
+ Reflect.get(requires, 'sdk') === LEGACY_SPELLING
56
+ ) {
57
+ Reflect.set(requires, 'sdk', FOUR_PART_ZERO)
58
+ }
59
+ },
60
+ }
61
+
62
+ /** Every migration, oldest first. */
63
+ const FORMAT_MIGRATIONS: readonly FormatMigration[] = [
64
+ fourPartVersion,
65
+ journalGlyphImages,
66
+ shardfilePointer,
67
+ dropRuntimeTrust,
68
+ ]
69
+
70
+ /** Whether a file at `version` still needs a step that writes `to`. The legacy two-part spelling sits just below its
71
+ * four-part twin, so the spelling step runs once and never again. */
72
+ function versionBelow(version: string, to: string): boolean {
73
+ const left = parseShardfileVersion(version)
74
+ const right = parseShardfileVersion(to)
75
+ for (let index = ZERO; index < left.length; index += ONE) {
76
+ const difference = (left[index] ?? ZERO) - (right[index] ?? ZERO)
77
+ if (difference !== ZERO) {
78
+ return difference < ZERO
79
+ }
80
+ }
81
+ return (
82
+ version.split('.').length === TWO_PART && to.split('.').length > TWO_PART
83
+ )
84
+ }
85
+
86
+ /** Refuse one step: a `to` that is no format version, out of version order after `last`, or a save-affecting step with
87
+ * no save migration. */
88
+ function checkStep(step: Readonly<FormatMigration>, last: string): void {
89
+ if (
90
+ !SHARDFILE_VERSIONS.some((version: string): boolean => version === step.to)
91
+ ) {
92
+ throw new Error(`Migration ${step.id} writes ${step.to}, no format version`)
93
+ }
94
+ if (compareShardfileVersions(step.to, last) < ZERO) {
95
+ throw new Error(`Migration ${step.id} is out of version order`)
96
+ }
97
+ if (step.affects.includes('save') && step.saveMigration === undefined) {
98
+ throw new Error(
99
+ `Migration ${step.id} affects saves without a save migration`,
100
+ )
101
+ }
102
+ }
103
+
104
+ /** Refuse a registry the chain cannot run as written (FE8): a repeated id, or a step `checkStep` refuses. */
105
+ function checkMigrations(migrations: readonly FormatMigration[]): void {
106
+ const ids = new Set<string>()
107
+ let last: string = LEGACY_SPELLING
108
+ for (const step of migrations) {
109
+ if (ids.has(step.id)) {
110
+ throw new Error(`Migration ${step.id} is registered twice`)
111
+ }
112
+ ids.add(step.id)
113
+ checkStep(step, last)
114
+ last = step.to
115
+ }
116
+ }
117
+
118
+ export {
119
+ FORMAT_MIGRATIONS,
120
+ checkMigrations,
121
+ type FormatMigration,
122
+ type MigratingShard,
123
+ versionBelow,
124
+ }
@@ -36,7 +36,9 @@ const VALIDATE_CODES = {
36
36
  'pack-invalid':
37
37
  "A pack is missing a member, or a member or the pack's hash differs.",
38
38
  'cook-invalid':
39
- 'The cook file, its preparation, or a mount (path or bytes) is invalid (C0, J137).',
39
+ 'The cook file or a mount (path or bytes) is invalid (C0, J137).',
40
+ 'preparation-invalid':
41
+ "The author's preparation is missing, stale or invalid: its inputHash, fence or programs mount (J487, SHARD-COMPAT PR3; docs/preparation.md).",
40
42
  'runtime-files':
41
43
  'Copied runtime files are present without a runtime import checker, or fail it.',
42
44
  'unlisted-file': 'A file in the product is not listed in `shard.json`.',
@@ -0,0 +1,12 @@
1
+ {
2
+ "about": "Frozen engine table (SHARD-COMPAT CP1, design Q17): the seven journal glyphs a compendium icon could name before shard-format 036b383 made icons image-only, drawn as engine src/client/game/icons.ts drew them (64x64, currentColor; ghost without its glow filter, strokes without caps). The journal-glyph-images chain step writes each as an inert SVG image.",
3
+ "glyphs": {
4
+ "deer": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cellipse%20cx%3D%2237%22%20cy%3D%2235%22%20rx%3D%2216%22%20ry%3D%228.5%22%2F%3E%20%3Cpath%20d%3D%22M25%2031%20L20%2016%20L27%2015%20L31%2030%20Z%22%2F%3E%20%3Cellipse%20cx%3D%2220%22%20cy%3D%2215%22%20rx%3D%226.5%22%20ry%3D%224%22%2F%3E%20%3Cpath%20d%3D%22M15%2013%20L12%206%20L17%2011%20Z%22%2F%3E%20%3Cpath%20d%3D%22M25%2012%20L27%207%20L29%2012%20Z%22%2F%3E%20%3Cpath%20d%3D%22M20%2012%20L17%203%20M20%2012%20L23%202%20M17%203%20L14%204%20M18.5%207%20L15%206%20M23%202%20L26%201%20M21.5%206%20L25%205%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%221.8%22%2F%3E%20%3Cpath%20d%3D%22M52%2030%20L56%2026%20L55%2031%20Z%22%2F%3E%20%3Crect%20x%3D%2224%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2230%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2243%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2249%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3C%2Fsvg%3E",
5
+ "elk": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cellipse%20cx%3D%2238%22%20cy%3D%2236%22%20rx%3D%2217%22%20ry%3D%229.5%22%2F%3E%20%3Cpath%20d%3D%22M24%2032%20L18%2015%20L27%2013%20L32%2030%20Z%22%2F%3E%20%3Cpath%20d%3D%22M22%2026%20L19%2034%20L26%2031%20Z%22%2F%3E%20%3Cellipse%20cx%3D%2219%22%20cy%3D%2214%22%20rx%3D%227%22%20ry%3D%224.5%22%2F%3E%20%3Cpath%20d%3D%22M13%2012%20L9%206%20L15%2010%20Z%22%2F%3E%20%3Cpath%20d%3D%22M18%2011%20C12%208%208%203%206%20-2%20M18%2011%20C15%205%2013%201%2014%20-3%20M18%2011%20L24%20-1%20M20%205%20L17%202%20M22%202%20L19%20-1%20M13%205%20L9%204%20M11%208%20L6%208%20M22%204%20L25%201%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222.2%22%2F%3E%20%3Crect%20x%3D%2223%22%20y%3D%2242%22%20width%3D%223.6%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2230%22%20y%3D%2242%22%20width%3D%223.6%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2245%22%20y%3D%2242%22%20width%3D%223.6%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2252%22%20y%3D%2242%22%20width%3D%223.6%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3C%2Fsvg%3E",
6
+ "boar": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cpath%20d%3D%22M14%2034%20C12%2024%2024%2020%2036%2020%20C50%2020%2058%2026%2057%2036%20C56%2044%2048%2046%2036%2046%20C24%2046%2015%2044%2014%2034%20Z%22%2F%3E%20%3Cpath%20d%3D%22M15%2030%20L6%2035%20L8%2042%20L16%2042%20Z%22%2F%3E%20%3Cpath%20d%3D%22M7%2040%20L3%2044%20L6%2044.5%20Z%22%2F%3E%20%3Cpath%20d%3D%22M30%2020%20L33%2016%20L36%2020%20Z%20M40%2020%20L43%2016%20L46%2020%20Z%22%2F%3E%20%3Cpath%20d%3D%22M8%2043.5%20C9%2046.5%2012%2047%2014%2045%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%2F%3E%20%3Cpath%20d%3D%22M57%2030%20L61%2026%20L60%2033%20Z%22%2F%3E%20%3Crect%20x%3D%2218%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2225%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2241%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2248%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3C%2Fsvg%3E",
7
+ "bear": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cpath%20d%3D%22M8%2030%20C6%2024%2010%2020%2016%2020%20L20%2020%20C24%2014%2034%2012%2044%2014%20C54%2016%2060%2024%2058%2034%20C57%2042%2052%2046%2044%2046%20L20%2046%20C12%2046%208%2040%208%2030%20Z%22%2F%3E%20%3Cpath%20d%3D%22M10%2022%20C6%2022%204%2026%205%2030%20C7%2033%2012%2033%2014%2030%20L20%2030%20L20%2036%20C16%2040%2010%2038%208%2034%20Z%22%2F%3E%20%3Cpath%20d%3D%22M4%2032%20L1%2036%20L5%2036.5%20Z%22%2F%3E%20%3Ccircle%20cx%3D%2214%22%20cy%3D%2218%22%20r%3D%223.2%22%2F%3E%3Ccircle%20cx%3D%2221%22%20cy%3D%2215%22%20r%3D%223%22%2F%3E%20%3Crect%20x%3D%2216%22%20y%3D%2244%22%20width%3D%225.2%22%20height%3D%2213%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2224%22%20y%3D%2244%22%20width%3D%225.2%22%20height%3D%2213%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2240%22%20y%3D%2244%22%20width%3D%225.2%22%20height%3D%2213%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2248%22%20y%3D%2244%22%20width%3D%225.2%22%20height%3D%2213%22%20rx%3D%221%22%2F%3E%3C%2Fsvg%3E",
8
+ "antlers": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cpath%20d%3D%22M32%2058%20L32%2030%20M32%2030%20C22%2028%2014%2020%2012%208%20M32%2030%20C42%2028%2050%2020%2052%208%20M22%2026%20L16%2018%20M42%2026%20L48%2018%20M18%2016%20L10%2014%20M46%2016%20L54%2014%20M27%2029%20L24%2036%20M37%2029%20L40%2036%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%223.5%22%2F%3E%3C%2Fsvg%3E",
9
+ "ghost": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cg%20opacity%3D%220.7%22%3E%3Cellipse%20cx%3D%2237%22%20cy%3D%2235%22%20rx%3D%2216%22%20ry%3D%228.5%22%2F%3E%20%3Cpath%20d%3D%22M25%2031%20L20%2016%20L27%2015%20L31%2030%20Z%22%2F%3E%20%3Cellipse%20cx%3D%2220%22%20cy%3D%2215%22%20rx%3D%226.5%22%20ry%3D%224%22%2F%3E%20%3Cpath%20d%3D%22M15%2013%20L12%206%20L17%2011%20Z%22%2F%3E%20%3Cpath%20d%3D%22M25%2012%20L27%207%20L29%2012%20Z%22%2F%3E%20%3Cpath%20d%3D%22M20%2012%20L17%203%20M20%2012%20L23%202%20M17%203%20L14%204%20M18.5%207%20L15%206%20M23%202%20L26%201%20M21.5%206%20L25%205%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%221.8%22%2F%3E%20%3Cpath%20d%3D%22M52%2030%20L56%2026%20L55%2031%20Z%22%2F%3E%20%3Crect%20x%3D%2224%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2230%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2243%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2249%22%20y%3D%2240%22%20width%3D%223.2%22%20height%3D%2217%22%20rx%3D%221%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E",
10
+ "ironhide": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%220%200%2064%2064%22%20fill%3D%22currentColor%22%20stroke%3D%22none%22%3E%3Cg%20transform%3D%22translate(-4%20-6)%20scale(1.14)%22%3E%3Cpath%20d%3D%22M14%2034%20C12%2024%2024%2020%2036%2020%20C50%2020%2058%2026%2057%2036%20C56%2044%2048%2046%2036%2046%20C24%2046%2015%2044%2014%2034%20Z%22%2F%3E%20%3Cpath%20d%3D%22M15%2030%20L6%2035%20L8%2042%20L16%2042%20Z%22%2F%3E%20%3Cpath%20d%3D%22M7%2040%20L3%2044%20L6%2044.5%20Z%22%2F%3E%20%3Cpath%20d%3D%22M30%2020%20L33%2016%20L36%2020%20Z%20M40%2020%20L43%2016%20L46%2020%20Z%22%2F%3E%20%3Cpath%20d%3D%22M8%2043.5%20C9%2046.5%2012%2047%2014%2045%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%2F%3E%20%3Cpath%20d%3D%22M57%2030%20L61%2026%20L60%2033%20Z%22%2F%3E%20%3Crect%20x%3D%2218%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2225%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2241%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2248%22%20y%3D%2243%22%20width%3D%223.4%22%20height%3D%2214%22%20rx%3D%221%22%2F%3E%3Cpath%20d%3D%22M4%2046%20L-2%2052%20L5%2050%20Z%22%20transform%3D%22translate(4%20-4)%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E"
11
+ }
12
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$doc": "J426 (Jake, 2026-11-18): the one armed-zone list. A zone named here has done the work to get under the J410 lines, and from then on every memory gate refuses it back over them, with no override flag and no report-only fallback: the format's offline estimate over lines.playingBytes / lines.loadingBytes (check, validate, cook, upload), the declared worst-location total over the J408 1.5 GB line, the runtime tier and a stale runtime reading; engine's ledger, footprint and boot-line guards read the same list. A zone not named here reports only (J424). Each zone's playingBytes / loadingBytes are its offline estimate when it was armed (memory epoch in `epoch`); the offline estimate refuses over the larger of the line and that reading plus 0.5% (memory-armed.ts ARMED_ALLOWANCE), so a zone EM11 measured under the line whose conservative estimate reads over it (Nine's playing) is locked at its armed state. Decimal bytes. Format memory-armed.ts reads this; engine reads @wildshard/format/src/format/memory-armed.json. `held` (J424): zones armed once but moved out of `zones` because engine pins an older product of theirs that reads over the line; a held zone reports only, and moves back to `zones` (re-armed) when its engine re-pin lands. Its readings stay so re-arming changes nothing else.",
2
+ "$doc": "J426 (Jake, 2026-11-18): the one armed-zone list. A zone named here has done the work to get under the J410 lines, and from then on every memory gate refuses it back over them, with no override flag and no report-only fallback: the format's offline estimate over lines.playingBytes / lines.loadingBytes (check, validate, cook, upload), the declared worst-location total over the J408 1.5 GB line, the runtime tier and a stale runtime reading; engine's ledger, footprint and boot-line guards read the same list. A zone not named here reports only (J424). Each zone's playingBytes / loadingBytes are its offline estimate when it was armed (memory epoch in `epoch`); the offline estimate refuses over the larger of the line and that reading plus 0.5% (memory-armed.ts ARMED_ALLOWANCE), so a zone EM11 measured under the line whose conservative estimate reads over it (Nine's playing) is locked at its armed state. Decimal bytes. Format memory-armed.ts reads this; engine reads @wildshard/format/src/format/memory-armed.json. The four zones once held here (Driftwood, Nalati, Nine Dragon, Pine) are simply not armed: CP10 judges a stored original by its stored verdict, so no pinned product needs a hold (FORMAT-PRUNE FP12); arming moves to the API catalogue at FP27.",
3
3
  "lines": {
4
4
  "playingBytes": 1000000000,
5
5
  "loadingBytes": 1500000000
@@ -181,43 +181,5 @@
181
181
  "loadingBytes": 1108011593,
182
182
  "evidence": "engine-pinned product revision 2 (tar f4a1d611cccc), a shard with no runtime reading; epoch-8 golden estimate; mini-resweep reads every light zone under both J410 lines standalone"
183
183
  }
184
- },
185
- "held": {
186
- "driftwood-isle": {
187
- "armed": "2026-11-18",
188
- "by": "mini-pinemem5",
189
- "epoch": 8,
190
- "playingBytes": 820905616,
191
- "loadingBytes": 1157545785,
192
- "evidence": "shard-driftwood e736730 built with format 0.37 (epoch 8); codex-nalati locked pairs on the EM11 upper read 990.5 / 1,344.7 MB (meta MEMORY-GATES)",
193
- "held": "2026-11-18 opus-pin (J424, QA 11-18 row 29): engine pins an older product of this zone that reads over its line; re-arm (move back to zones) when engine's pin reaches the armed build"
194
- },
195
- "nalati-grasslands": {
196
- "armed": "2026-11-18",
197
- "by": "mini-pinemem5",
198
- "epoch": 8,
199
- "playingBytes": 945736154,
200
- "loadingBytes": 1328901899,
201
- "evidence": "shard-nalati 1d5014e8 built with format 0.37 (epoch 8); mini-resweep EM11 upper on the J420 stand-in: playing 0.940 GB less the worker, loading 1.470 GB (meta MEMORY-GATES)",
202
- "held": "2026-11-18 opus-pin (J424, QA 11-18 row 29): engine pins an older product of this zone that reads over its line; re-arm (move back to zones) when engine's pin reaches the armed build"
203
- },
204
- "nine-dragon-stack": {
205
- "armed": "2026-11-18",
206
- "by": "mini-pinemem5",
207
- "epoch": 8,
208
- "playingBytes": 1023504847,
209
- "loadingBytes": 1434692360,
210
- "evidence": "shard-nine-dragon 8779b872 built with format 0.37 (epoch 8); mini-pinemem6 prepared online boot on engine d0fd6e62, 9 pairs: playing upper 0.938 GB, loading upper 1.435 GB (meta 1677f091). The estimate's playing (1,023.5 MB) is over the 1.0 GB line, so it locks at that reading",
211
- "held": "2026-11-18 opus-pin (J424, QA 11-18 row 29): engine pins an older product of this zone that reads over its line; re-arm (move back to zones) when engine's pin reaches the armed build"
212
- },
213
- "pine-hollow": {
214
- "armed": "2026-11-18",
215
- "by": "mini-pinemem5",
216
- "epoch": 8,
217
- "playingBytes": 920666659,
218
- "loadingBytes": 1298769921,
219
- "evidence": "shard-pine-hollow 400ed4b7 built with format 0.37 (epoch 8); mini-pinemem6 prepared online boot on engine f0a96518, 9 pairs: playing upper 0.969 GB, loading upper 1.407 GB (meta 118a2b13)",
220
- "held": "2026-11-18 opus-pin (J424, QA 11-18 row 29): engine pins an older product of this zone that reads over its line; re-arm (move back to zones) when engine's pin reaches the armed build"
221
- }
222
184
  }
223
185
  }
@@ -24,12 +24,6 @@ const ARMED_ZONES: Readonly<Record<string, ArmedZone>> = Object.freeze(
24
24
 
25
25
  /** J424 (QA 11-18 row 29): a zone armed once but held out of `ARMED_ZONES` while engine pins an older product of it
26
26
  * that reads over its line. It reports only; it moves back to `zones` (re-armed) when its engine re-pin lands. */
27
- interface HeldZone extends ArmedZone {
28
- readonly held: string
29
- }
30
-
31
- const HELD_ZONES: Readonly<Record<string, HeldZone>> = Object.freeze(armed.held)
32
-
33
27
  /** True when `slug` is in the armed list (J426). */
34
28
  function zoneArmed(slug?: string): boolean {
35
29
  return slug !== undefined && Object.hasOwn(ARMED_ZONES, slug)
@@ -44,13 +38,52 @@ function armedLine(
44
38
  return zoneArmed(slug) ? ARMED_LINES[kind] : undefined
45
39
  }
46
40
 
41
+ type RatchetMetric = 'playing' | 'loading' | 'runtime'
42
+
43
+ /** J445: only the common loading ceiling can refuse an armed shard. Playing and runtime tier overages are reported. */
44
+ function ratchetLimit(
45
+ slug: string | undefined,
46
+ metric: RatchetMetric,
47
+ line: number,
48
+ ): number {
49
+ return metric === 'loading' && zoneArmed(slug)
50
+ ? line
51
+ : Number.POSITIVE_INFINITY
52
+ }
53
+
54
+ /** Describe the offline decision for a measured overage. */
55
+ function ratchetSeverity(
56
+ slug: string | undefined,
57
+ metric: RatchetMetric,
58
+ reading: Readonly<{ line: number; actual: number }>,
59
+ ): 'refusal' | 'warning' {
60
+ return reading.actual > ratchetLimit(slug, metric, reading.line)
61
+ ? 'refusal'
62
+ : 'warning'
63
+ }
64
+
65
+ /** The words a reported (not refused) issue carries: why it only reports (J424). */
66
+ function ratchetNote(slug: string | undefined): string {
67
+ return zoneArmed(slug)
68
+ ? ''
69
+ : ` (report-only, J424: ${slug ?? 'this shard'} is not armed)`
70
+ }
71
+
72
+ /** True when a stale runtime reading only reports: J424, every zone not armed (J426). */
73
+ function staleReadingAdmitted(slug: string | undefined): boolean {
74
+ return !zoneArmed(slug)
75
+ }
76
+
47
77
  export {
48
78
  ARMED_LINES,
49
79
  ARMED_ZONES,
50
80
  type ArmedKind,
51
81
  type ArmedZone,
52
82
  armedLine,
53
- HELD_ZONES,
54
- type HeldZone,
83
+ type RatchetMetric,
84
+ ratchetLimit,
85
+ ratchetNote,
86
+ ratchetSeverity,
87
+ staleReadingAdmitted,
55
88
  zoneArmed,
56
89
  }
@@ -1,4 +1,4 @@
1
- import { staleReadingAdmitted } from './memory-ratchet.ts'
1
+ import { staleReadingAdmitted } from './memory-armed.ts'
2
2
 
3
3
  /** MEMORY-GATES MG5 (J408, Jake 2026-11-17: "a stale runtimeCost is refused"): the memory model a runtime home's
4
4
  * `runtimeCost` reading must have been taken against. It rises when the model changes what it charges (MG6 adds shader
@@ -46,7 +46,7 @@ function staleRuntimeIssues(
46
46
  current: number = OLDEST_CURRENT_EPOCH,
47
47
  identity?: Readonly<{ slug: string; revision: number }>,
48
48
  ): StaleRuntimeIssue[] {
49
- const admitted = staleReadingAdmitted(identity?.slug, identity?.revision)
49
+ const admitted = staleReadingAdmitted(identity?.slug)
50
50
  const rows: EpochRow[] = []
51
51
  const cost = runtime === null ? undefined : runtime.cost
52
52
  if (cost !== undefined) {
@@ -2,8 +2,7 @@ import { parse } from 'valibot'
2
2
 
3
3
  import { bootMemoryCosts } from './boot-memory-cost.ts'
4
4
  import { worstContentCost } from './budget.ts'
5
- import { ARMED_LINES } from './memory-armed.ts'
6
- import { ratchetNote, ratchetSeverity } from './memory-ratchet.ts'
5
+ import { ARMED_LINES, ratchetNote, ratchetSeverity } from './memory-armed.ts'
7
6
  import { runtimeAccountedBytes, RuntimeCostSchema } from './runtimeCost.ts'
8
7
 
9
8
  import type { TierIndex } from './phone-files.ts'
@@ -45,7 +44,7 @@ function hardLineIssue(
45
44
  : overHardLine(bytes)
46
45
  return {
47
46
  code: `perf-${kind}-memory`,
48
- metric: `worst ${kind} total bytes${over}${severity === 'warning' ? ratchetNote(slug, kind) : ''}`,
47
+ metric: `worst ${kind} total bytes${over}${severity === 'warning' ? ratchetNote(slug) : ''}`,
49
48
  actual: bytes,
50
49
  limit: line,
51
50
  severity,
@@ -87,12 +86,14 @@ type MemoryContext =
87
86
  sections: ReadonlyMap<string, unknown>
88
87
  mountedImages: number
89
88
  index?: TierIndex
89
+ judged?: 'upload' | 'stored'
90
90
  }>
91
91
 
92
92
  function memoryContext(context: MemoryContext): Readonly<{
93
93
  sections: ReadonlyMap<string, unknown>
94
94
  mountedImages: number
95
95
  index?: TierIndex
96
+ judged?: 'upload' | 'stored'
96
97
  }> {
97
98
  return context instanceof Map
98
99
  ? { sections: context, mountedImages: EMPTY_BYTES }