@wildshard/shard-format 0.37.1 → 0.38.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.
@@ -0,0 +1,64 @@
1
+ import armed from './memory-armed.json' with { type: 'json' }
2
+
3
+ /**
4
+ * J426 (Jake, 2026-11-18, "get the shard passing the memory gate and then to LOCK THE GATE IN. And make it fail hard /
5
+ * mandatory") on J424 ("the gates should only block once an agent has done the work to get it under the gate"): the
6
+ * one armed-zone list, `memory-armed.json`. Every memory gate refuses an armed zone over its line, whatever the policy
7
+ * or the report-only switch; it reports every other zone. Engine's guards read the same JSON.
8
+ */
9
+ interface ArmedZone {
10
+ readonly armed: string
11
+ readonly by: string
12
+ readonly epoch: number
13
+ readonly playingBytes: number
14
+ readonly loadingBytes: number
15
+ readonly evidence: string
16
+ }
17
+
18
+ type ArmedKind = 'playing' | 'loading'
19
+
20
+ const ARMED_LINES: Readonly<Record<ArmedKind, number>> = Object.freeze({
21
+ playing: armed.lines.playingBytes,
22
+ loading: armed.lines.loadingBytes,
23
+ })
24
+
25
+ const ARMED_ZONES: Readonly<Record<string, ArmedZone>> = Object.freeze(
26
+ armed.zones,
27
+ )
28
+
29
+ /** True when `slug` is in the armed list (J426). */
30
+ function zoneArmed(slug?: string): boolean {
31
+ return slug !== undefined && Object.hasOwn(ARMED_ZONES, slug)
32
+ }
33
+
34
+ /** A rebuild of the same source moves the computed estimate by packing and compression drift only. */
35
+ const ARMED_ALLOWANCE = 0.005
36
+
37
+ /** What an armed zone's offline estimate refuses over: the J410 line, or, when the conservative estimate of a source
38
+ * that EM11 measured under the line already reads over it (Nine's playing), that reading at arming plus the
39
+ * allowance, so the gate locks in the measured state and refuses any growth. Undefined for a zone that only reports. */
40
+ function armedLine(
41
+ slug: string | undefined,
42
+ kind: ArmedKind,
43
+ ): number | undefined {
44
+ const zone =
45
+ slug === undefined || !zoneArmed(slug) ? undefined : ARMED_ZONES[slug]
46
+ if (zone === undefined) {
47
+ return undefined
48
+ }
49
+ const armedBytes = kind === 'playing' ? zone.playingBytes : zone.loadingBytes
50
+ return Math.max(
51
+ ARMED_LINES[kind],
52
+ armedBytes + Math.floor(armedBytes * ARMED_ALLOWANCE),
53
+ )
54
+ }
55
+
56
+ export {
57
+ ARMED_ALLOWANCE,
58
+ ARMED_LINES,
59
+ ARMED_ZONES,
60
+ type ArmedKind,
61
+ type ArmedZone,
62
+ armedLine,
63
+ zoneArmed,
64
+ }
@@ -38,9 +38,9 @@ function staleRuntimeCost(
38
38
  return `native resident measurement is stale: memory epoch ${String(epoch)}, current ${String(current)} (J408): re-measure the runtime home`
39
39
  }
40
40
 
41
- /** A refusal, whatever the policy, for a runtime home's reading and for its images-first reading, each stale against
42
- * `current`. Takes the shard's `runtime` (null for a data-only shard). J412: a report instead for exactly the pinned
43
- * revision the ratchet names (`memory-ratchet.ts` `staleRevision`), given its `identity`. */
41
+ /** A refusal, whatever the policy, for an armed runtime home's reading and for its images-first reading, each stale against
42
+ * `current`. Takes the shard's `runtime` (null for a data-only shard). J424 / J426: a refusal only for an armed zone
43
+ * (`memory-armed.ts`), given its `identity`; every other shard reports. */
44
44
  function staleRuntimeIssues(
45
45
  runtime: Readonly<{ cost?: EpochRow | undefined }> | null,
46
46
  current: number = OLDEST_CURRENT_EPOCH,
@@ -59,7 +59,7 @@ function staleRuntimeIssues(
59
59
  .filter((row: EpochRow): boolean => staleRuntimeCost(row, current) !== '')
60
60
  .map((row: EpochRow): StaleRuntimeIssue => ({
61
61
  code: 'perf-native-resident-unmeasured',
62
- metric: `${staleRuntimeCost(row, current)}${admitted ? ' (report-only, J412 ratchet: the pinned revision)' : ''}`,
62
+ metric: `${staleRuntimeCost(row, current)}${admitted ? ' (report-only, J424: the zone is not armed)' : ''}`,
63
63
  actual: row.epoch ?? LEGACY_EPOCH,
64
64
  limit: current,
65
65
  severity: admitted ? 'warning' : 'refusal',
@@ -2,6 +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 { armedLine } from './memory-armed.ts'
5
6
  import { ratchetNote, ratchetSeverity } from './memory-ratchet.ts'
6
7
  import { runtimeAccountedBytes, RuntimeCostSchema } from './runtimeCost.ts'
7
8
 
@@ -24,12 +25,12 @@ function overHardLine(bytes: number): string {
24
25
  return ` (over the ${(MEMORY_HARD_BYTES / GB).toFixed(DIGITS)} GB phone line, J408: a phone would close the page)`
25
26
  }
26
27
 
27
- /** J408 (MG4): the issue for a worst-playing or loading estimate over the hard line. J412: a refusal only over the
28
- * zone's ratchet baseline (`memory-ratchet.ts`); at or under it, a report. */
28
+ /** J408 (MG4): the issue for a worst-playing or loading estimate over the hard line, or over `zone.line`. J424 /
29
+ * J426: a refusal only for an armed zone (`memory-armed.ts`); every other zone reports. */
29
30
  function hardLineIssue(
30
31
  kind: 'playing' | 'loading',
31
32
  bytes: number,
32
- slug?: string,
33
+ zone?: string | Readonly<{ slug: string; line: number }>,
33
34
  ): {
34
35
  readonly code: 'perf-playing-memory' | 'perf-loading-memory'
35
36
  readonly metric: string
@@ -37,15 +38,18 @@ function hardLineIssue(
37
38
  readonly limit: number
38
39
  readonly severity: 'refusal' | 'warning'
39
40
  } {
40
- const severity = ratchetSeverity(slug, kind, {
41
- line: MEMORY_HARD_BYTES,
42
- actual: bytes,
43
- })
41
+ const { slug, line } =
42
+ typeof zone === 'object' ? zone : { slug: zone, line: MEMORY_HARD_BYTES }
43
+ const severity = ratchetSeverity(slug, kind, { line, actual: bytes })
44
+ const over =
45
+ line === MEMORY_HARD_BYTES
46
+ ? overHardLine(bytes)
47
+ : ` (over the ${(line / GB).toFixed(DIGITS)} GB ${kind} line, J410; ${slug ?? ''} is armed, J426)`
44
48
  return {
45
49
  code: `perf-${kind}-memory`,
46
- metric: `worst ${kind} total bytes${overHardLine(bytes)}${severity === 'warning' ? ratchetNote(slug, kind) : ''}`,
50
+ metric: `worst ${kind} total bytes${over}${severity === 'warning' ? ratchetNote(slug, kind) : ''}`,
47
51
  actual: bytes,
48
- limit: MEMORY_HARD_BYTES,
52
+ limit: line,
49
53
  severity,
50
54
  }
51
55
  }
@@ -108,10 +112,14 @@ function offlineMemoryIssues(
108
112
  commons: runtime + commons,
109
113
  boot: bootMemoryCosts(source, sections, { mountedImages, index }),
110
114
  })
115
+ // J426: an armed zone's calibrated estimate answers to the J410 lines; every other zone's reports over J408's.
116
+ const { slug } = source.identity
117
+ const line = (kind: 'playing' | 'loading'): number =>
118
+ armedLine(slug, kind) ?? MEMORY_HARD_BYTES
111
119
  return (['playing', 'loading'] as const)
112
- .filter((kind): boolean => cost[kind] > MEMORY_HARD_BYTES)
120
+ .filter((kind): boolean => cost[kind] > line(kind))
113
121
  .map((kind): ReturnType<typeof hardLineIssue> =>
114
- hardLineIssue(kind, cost[kind], source.identity.slug),
122
+ hardLineIssue(kind, cost[kind], { slug, line: line(kind) }),
115
123
  )
116
124
  }
117
125
 
@@ -1,3 +1,5 @@
1
+ import { zoneArmed } from './memory-armed.ts'
2
+
1
3
  /**
2
4
  * J411 / J412 (Jake, 2026-11-18): memory gates are ratchets. "With these new gates we should definitely be landing
3
5
  * improvements even if they don't meet the new high standards." The J408 phone line (1.5 GB playing and loading), the
@@ -9,7 +11,8 @@
9
11
  * source's, in decimal bytes. Nine's and Pine's loading rows are engine's full-check performance report of the pinned
10
12
  * product (the offline estimate reads 1,667 and 1,697 MB); Pine's playing row is its declared admission. A cut ratchets
11
13
  * the row down; a zone
12
- * that passes a line loses that field, and the line refuses again. `staleRevision` is the pinned product's
14
+ * that passes a line loses that field. J424 / J426 (2026-11-18): the baselines only report now; a zone refuses only once
15
+ * it is armed (`memory-armed.ts`), and then over the line itself. `staleRevision` is the pinned product's
13
16
  * `identity.revision`: it admits that revision's pre-epoch-3 runtime reading; any later revision must carry a current one.
14
17
  */
15
18
  interface MemoryBaseline {
@@ -48,21 +51,17 @@ const RATCHET_ALLOWANCE = 0.005
48
51
 
49
52
  type RatchetMetric = 'playing' | 'loading' | 'runtime'
50
53
 
51
- /** The bytes over which `slug` refuses on `metric`: the line, or its baseline plus the allowance when that is higher. */
54
+ /** The bytes over which `slug` refuses on `metric`. J426 (on J424): an armed zone (`memory-armed.json`) refuses over
55
+ * `line`; every other zone reports only, so its limit is unbounded. The baselines above are kept for the report. */
52
56
  function ratchetLimit(
53
57
  slug: string | undefined,
54
- metric: RatchetMetric,
58
+ _metric: RatchetMetric,
55
59
  line: number,
56
60
  ): number {
57
- const baseline =
58
- slug === undefined ? undefined : MEMORY_RATCHET[slug]?.[metric]
59
- if (baseline === undefined) {
60
- return line
61
- }
62
- return Math.max(line, baseline + Math.floor(baseline * RATCHET_ALLOWANCE))
61
+ return zoneArmed(slug) ? line : Number.POSITIVE_INFINITY
63
62
  }
64
63
 
65
- /** 'refusal' over the ratchet, 'warning' over the line but within the zone's baseline. */
64
+ /** 'refusal' for an armed zone over the line, 'warning' for every other reading over it. */
66
65
  function ratchetSeverity(
67
66
  slug: string | undefined,
68
67
  metric: RatchetMetric,
@@ -73,25 +72,25 @@ function ratchetSeverity(
73
72
  : 'warning'
74
73
  }
75
74
 
76
- /** The words a reported (not refused) issue carries. */
75
+ /** The words a reported (not refused) issue carries: why it only reports, and the zone's J412 baseline if it has one. */
77
76
  function ratchetNote(slug: string | undefined, metric: RatchetMetric): string {
77
+ if (zoneArmed(slug)) {
78
+ return ''
79
+ }
78
80
  const baseline =
79
81
  slug === undefined ? undefined : MEMORY_RATCHET[slug]?.[metric]
82
+ const zone = slug ?? 'this shard'
80
83
  return baseline === undefined
81
- ? ''
82
- : ` (report-only, J412 ratchet: ${slug ?? ''} baseline ${String(baseline)})`
84
+ ? ` (report-only, J424: ${zone} is not armed)`
85
+ : ` (report-only, J424: ${zone} is not armed; J412 baseline ${String(baseline)})`
83
86
  }
84
87
 
85
- /** True when `revision` of `slug` is the pinned product whose stale reading the ratchet admits. */
88
+ /** True when a stale runtime reading only reports: J424, every zone not armed (J426). */
86
89
  function staleReadingAdmitted(
87
90
  slug: string | undefined,
88
- revision: number | undefined,
91
+ _revision: number | undefined,
89
92
  ): boolean {
90
- return (
91
- slug !== undefined &&
92
- revision !== undefined &&
93
- MEMORY_RATCHET[slug]?.staleRevision === revision
94
- )
93
+ return !zoneArmed(slug)
95
94
  }
96
95
 
97
96
  export {
@@ -0,0 +1,224 @@
1
+ /**
2
+ * ONE-FORMAT OF17a's primitive table: each family from meta `docs/plans/one-format/HOSTS.md` (approved, J420), the
3
+ * hosts it replaces and what switches it on. `primitives.ts` derives a product's list from it.
4
+ */
5
+ interface PrimitiveSwitch {
6
+ readonly section: string
7
+ readonly path: readonly string[]
8
+ /** When set, the family is on only if some row of the list at `path` has this key (a dotted key reads a nested one). */
9
+ readonly having?: string
10
+ /** With `having`: only a row whose `having` key holds this value counts. */
11
+ readonly equals?: string
12
+ /** Only a row without this key counts. */
13
+ readonly lacking?: string
14
+ }
15
+ interface Primitive {
16
+ readonly name: string
17
+ /** The ONE-FORMAT row that builds it. */
18
+ readonly row: string
19
+ /** The server hosts and page features it replaces (HOSTS.md). A host split across two families sits in the first. */
20
+ readonly hosts: readonly string[]
21
+ readonly on: PrimitiveSwitch | readonly PrimitiveSwitch[] | 'always' | 'later'
22
+ }
23
+ const TABLE: readonly Primitive[] = [
24
+ {
25
+ name: 'collision',
26
+ row: 'OF41',
27
+ on: 'always',
28
+ hosts: ['collision', 'collision.pieces'],
29
+ },
30
+ {
31
+ name: 'plumbing',
32
+ row: 'OF18',
33
+ on: 'always',
34
+ hosts: [
35
+ 'commands',
36
+ 'decisions',
37
+ 'engine.creatures.update',
38
+ 'strings.register',
39
+ 'content.catalogue',
40
+ 'debug.expose',
41
+ 'audio.cues',
42
+ 'audio.scene',
43
+ 'player.enter',
44
+ 'bag.finds',
45
+ 'state.adventure',
46
+ ],
47
+ },
48
+ {
49
+ name: 'population',
50
+ row: 'OF29',
51
+ on: { section: 'actors/creatures', path: ['creatures', 'spawns'] },
52
+ hosts: [
53
+ 'population.roster',
54
+ 'population.spawn-script',
55
+ 'population.shelter',
56
+ 'population.environment',
57
+ 'population.mixed',
58
+ 'population.poses',
59
+ 'population.reactions',
60
+ 'population.settle',
61
+ 'population.homes',
62
+ 'population.wildlife',
63
+ ],
64
+ },
65
+ {
66
+ name: 'elites',
67
+ row: 'OF33',
68
+ on: [
69
+ {
70
+ section: 'actors/creatures',
71
+ path: ['creatures', 'spawns'],
72
+ having: 'rank',
73
+ },
74
+ {
75
+ section: 'combat/encounters',
76
+ path: ['encounters'],
77
+ having: 'kind',
78
+ equals: 'elite',
79
+ },
80
+ ],
81
+ hosts: [
82
+ 'population.elites',
83
+ 'population.elites-ready',
84
+ 'riding.elites',
85
+ 'riding.elites-ready',
86
+ 'elite.entry',
87
+ 'elite.construct',
88
+ ],
89
+ },
90
+ {
91
+ name: 'boss',
92
+ row: 'OF34',
93
+ on: [
94
+ {
95
+ section: 'combat/encounters',
96
+ path: ['encounters'],
97
+ having: 'kind',
98
+ equals: 'boss',
99
+ },
100
+ { section: 'actors/spawns', path: ['runtime', 'spawns', 'bosses'] },
101
+ ],
102
+ hosts: ['boss.ground', 'boss.spawned', 'boss.held'],
103
+ },
104
+ {
105
+ name: 'boss.arena',
106
+ row: 'OF34',
107
+ on: {
108
+ section: 'combat/encounters',
109
+ path: ['encounters'],
110
+ having: 'arena.bounds',
111
+ },
112
+ hosts: ['boss.arena', 'boss.open-arena'],
113
+ },
114
+ {
115
+ name: 'riding',
116
+ row: 'CC40',
117
+ on: {
118
+ section: 'actors/species',
119
+ path: ['rows', 'species'],
120
+ having: 'mount',
121
+ },
122
+ hosts: [
123
+ 'riding.mounted',
124
+ 'riding.roster',
125
+ 'riding.groups',
126
+ 'riding.hunt',
127
+ 'riding.trample',
128
+ 'riding.environment',
129
+ 'riding.taming',
130
+ 'riding.session',
131
+ 'taming.entry',
132
+ ],
133
+ },
134
+ {
135
+ name: 'patrol',
136
+ row: 'OF37',
137
+ on: { section: 'actors/creatures', path: ['creatures', 'patrols'] },
138
+ hosts: ['encounter.patrol', 'timed.encounters'],
139
+ },
140
+ {
141
+ name: 'held.melee',
142
+ row: 'OF38',
143
+ on: {
144
+ section: 'combat/items',
145
+ path: ['items', 'rows'],
146
+ having: 'kind',
147
+ equals: 'weapon',
148
+ lacking: 'ranged',
149
+ },
150
+ hosts: [
151
+ 'item.swept',
152
+ 'held.melee',
153
+ 'held.arms',
154
+ 'held.claims',
155
+ 'held.cosmetics',
156
+ ],
157
+ },
158
+ {
159
+ name: 'held.ranged',
160
+ row: 'OF38',
161
+ on: { section: 'combat/items', path: ['items', 'rows'], having: 'ranged' },
162
+ hosts: [
163
+ 'item.ranged',
164
+ 'combat.motion',
165
+ 'ammunition',
166
+ 'loadout',
167
+ 'held.ranged-feel',
168
+ 'held.ranged-page',
169
+ 'combat.targets',
170
+ ],
171
+ },
172
+ {
173
+ name: 'sky',
174
+ row: 'OF41',
175
+ on: { section: 'world/days', path: ['rows', 'days'] },
176
+ hosts: ['day.toon', 'day.keyed-sky', 'day.declared'],
177
+ },
178
+ {
179
+ name: 'weather',
180
+ row: 'OF41',
181
+ on: { section: 'world/weather', path: ['rows', 'weather'] },
182
+ hosts: [
183
+ 'weather.program',
184
+ 'weather.native',
185
+ 'weather.forest',
186
+ 'weather.fields',
187
+ ],
188
+ },
189
+ {
190
+ name: 'water.sea',
191
+ row: 'OF40',
192
+ on: {
193
+ section: 'world/water',
194
+ path: ['water'],
195
+ having: 'kind',
196
+ equals: 'sea',
197
+ },
198
+ hosts: ['water.sea', 'world.water'],
199
+ },
200
+ { name: 'water.field', row: 'OF40', on: 'later', hosts: ['water.field'] },
201
+ {
202
+ name: 'grapple',
203
+ row: 'OF41',
204
+ on: { section: 'state/modes', path: ['modes', 'grapple'] },
205
+ hosts: ['grapple'],
206
+ },
207
+ {
208
+ name: 'portal',
209
+ row: 'OF41',
210
+ on: {
211
+ section: 'world/edge',
212
+ path: ['entryways'],
213
+ having: 'kind',
214
+ equals: 'portalLink',
215
+ },
216
+ hosts: ['portal.ride'],
217
+ },
218
+ ]
219
+ const PRIMITIVES: readonly Primitive[] = Object.freeze(
220
+ TABLE.map((row): Primitive => Object.freeze(row)),
221
+ )
222
+
223
+ export type { Primitive, PrimitiveSwitch }
224
+ export { PRIMITIVES }