@wildshard/shard-format 0.70.0 → 0.71.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.
Files changed (63) hide show
  1. package/package.json +15 -3
  2. package/src/cli/corpus-candidate.ts +228 -0
  3. package/src/cli/corpus-command.ts +32 -3
  4. package/src/cli/corpus-pins.ts +73 -0
  5. package/src/cli/corpus-report.ts +36 -0
  6. package/src/cli/corpus-tar.ts +28 -0
  7. package/src/cli/corpus-usage.ts +24 -3
  8. package/src/cli/corpus.ts +50 -68
  9. package/src/cli/format-diff-range.ts +112 -0
  10. package/src/cli/main.ts +39 -9
  11. package/src/cli/pack.ts +20 -3
  12. package/src/cli/validate.ts +1 -1
  13. package/src/format/clientOwnership.ts +1 -1
  14. package/src/format/clientTrails.ts +121 -46
  15. package/src/format/cook-deprecations.ts +53 -0
  16. package/src/format/cook-preparation.ts +2 -1
  17. package/src/format/creature-rest-rig.ts +248 -0
  18. package/src/format/creature-skin-bounds.ts +146 -0
  19. package/src/format/deprecations.ts +18 -21
  20. package/src/format/edge-observations.ts +67 -0
  21. package/src/format/empty-shardfile.ts +4 -2
  22. package/src/format/entry-read-set.ts +147 -0
  23. package/src/format/format-migrate-rebuild.ts +4 -1
  24. package/src/format/format-migrate.ts +7 -1
  25. package/src/format/format-migration-envelope.ts +19 -0
  26. package/src/format/format-migration-prune.ts +42 -1
  27. package/src/format/format-migrations.ts +8 -1
  28. package/src/format/format-window.ts +71 -0
  29. package/src/format/immutable.ts +4 -1
  30. package/src/format/json-schema.ts +1468 -0
  31. package/src/format/lootEconomy.ts +4 -1
  32. package/src/format/mat4.ts +225 -0
  33. package/src/format/memory-armed.json +1 -9
  34. package/src/format/memory-armed.ts +46 -17
  35. package/src/format/memory-epoch.ts +10 -3
  36. package/src/format/memory-line.ts +17 -6
  37. package/src/format/outputFields.ts +3 -2
  38. package/src/format/outputIndex.ts +14 -1
  39. package/src/format/platformDataSections.ts +5 -0
  40. package/src/format/platformFileFamilies.ts +3 -3
  41. package/src/format/play-area.ts +95 -0
  42. package/src/format/policy-verdict.ts +12 -2
  43. package/src/format/registeredJson.ts +2 -2
  44. package/src/format/runtime-tier.ts +14 -7
  45. package/src/format/save-revision.ts +105 -0
  46. package/src/format/schema-source.ts +70 -0
  47. package/src/format/sections.ts +4 -1
  48. package/src/format/server-plan.ts +42 -0
  49. package/src/format/server-reads.ts +23 -0
  50. package/src/format/shardSchema.ts +9 -4
  51. package/src/format/shardSections.ts +17 -7
  52. package/src/format/shardfile-assets.ts +5 -5
  53. package/src/format/shardfile-stream-admit.ts +19 -10
  54. package/src/format/shardfile-stream-facts.ts +2 -1
  55. package/src/format/shardfile-stream.ts +2 -3
  56. package/src/format/shardfileValidation.ts +16 -9
  57. package/src/format/species-deprecations.ts +79 -0
  58. package/src/format/stateLineage.ts +12 -6
  59. package/src/format/tread-boxes.ts +65 -0
  60. package/src/format/vehicle-hulls.ts +124 -0
  61. package/src/format/version.ts +74 -17
  62. package/src/format/whole-inputs.ts +51 -0
  63. package/src/tools/runtime-hosts.json +4 -0
package/src/cli/corpus.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createWriteStream } from 'node:fs'
2
- import { mkdir, open, readFile, rm, writeFile } from 'node:fs/promises'
2
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
3
3
  import path from 'node:path'
4
4
  import { Readable } from 'node:stream'
5
5
  import { pipeline } from 'node:stream/promises'
@@ -16,8 +16,13 @@ import {
16
16
  string,
17
17
  } from 'valibot'
18
18
 
19
- import { deprecationLines, storedDeprecations } from './corpus-deprecations.ts'
19
+ import { candidateField, onlyNamed } from './corpus-candidate.ts'
20
+ import { storedDeprecations } from './corpus-deprecations.ts'
21
+ import { withPins } from './corpus-pins.ts'
22
+ import { firstBytes, isPlainTar } from './corpus-tar.ts'
20
23
 
24
+ import type { Candidate } from './corpus-candidate.ts'
25
+ import type { Pin } from './corpus-pins.ts'
21
26
  import type { InferOutput } from 'valibot'
22
27
 
23
28
  // `shard-format corpus` (meta SHARD-COMPAT FE3, J486 Q47 Q52): run this
@@ -61,12 +66,17 @@ interface CorpusRow {
61
66
  readonly reason: string | undefined
62
67
  readonly cached: boolean
63
68
  readonly deprecations: readonly string[]
69
+ /** FE13: engine pins this original. */
70
+ readonly pinned?: true
71
+ /** FE3b: the candidate's verdict, when one runs. */
72
+ readonly candidate?: string
64
73
  }
65
74
 
66
75
  type Judgement = Readonly<{
67
76
  verdict: 'valid' | 'fails'
68
77
  reason?: string
69
78
  deprecations?: readonly string[]
79
+ candidate?: string
70
80
  transient: boolean
71
81
  }>
72
82
 
@@ -75,12 +85,15 @@ interface CorpusOptions {
75
85
  readonly cache: string
76
86
  readonly validator: string
77
87
  readonly fetch?: typeof fetch
88
+ /** FE13: engine's shard-file pins, judged with the kept originals. */
89
+ readonly pins?: readonly Pin[]
90
+ /** FE3b: a candidate chain and validator judged beside the current one; every original is fetched again. */
91
+ readonly candidate?: Candidate
92
+ /** Only these shards' originals (`slug`, or one revision as `slug@r5`): a candidate run over the shards it targets. */
93
+ readonly only?: readonly string[]
78
94
  }
79
95
 
80
96
  const NONE = 0
81
- const TAR_MAGIC_AT = 257
82
- const TAR_MAGIC = 'ustar'
83
- const PEEK_BYTES = 512
84
97
  const FETCH_TIMEOUT_MS = 900_000
85
98
  /** One original is at most a few hundred MB; a download that takes longer has stalled. */
86
99
  const DOWNLOAD_TIMEOUT_MS = 180_000
@@ -88,8 +101,6 @@ const DOWNLOAD_TRIES = 3
88
101
  const FIRST_TRY = 1
89
102
  const OK_LOW = 200
90
103
  const OK_HIGH = 300
91
- const SHORT_HASH = 12
92
- const VERDICT_WIDTH = 5
93
104
  const FIRST = 0
94
105
 
95
106
  function shortReason(error: unknown): string {
@@ -101,14 +112,6 @@ function shortReason(error: unknown): string {
101
112
  return `${code}${text}`.split('\n')[FIRST] ?? text
102
113
  }
103
114
 
104
- /** Whether the first bytes are a plain tarball (`ustar` at 257) rather than Brotli. */
105
- function isPlainTar(head: Readonly<Uint8Array>): boolean {
106
- const magic = new TextDecoder().decode(
107
- head.subarray(TAR_MAGIC_AT, TAR_MAGIC_AT + TAR_MAGIC.length),
108
- )
109
- return magic === TAR_MAGIC
110
- }
111
-
112
115
  /** Downloads one original to `file`: the validator reads it twice, so it is fetched once and read from disk. */
113
116
  async function download(
114
117
  options: Readonly<CorpusOptions>,
@@ -129,18 +132,6 @@ async function download(
129
132
  await pipeline(Readable.fromWeb(response.body), createWriteStream(file))
130
133
  }
131
134
 
132
- async function firstBytes(file: string): Promise<Uint8Array> {
133
- const handle = await open(file)
134
- try {
135
- const bytes = new Uint8Array(PEEK_BYTES)
136
- await handle.read(bytes, NONE, PEEK_BYTES, NONE)
137
- return bytes
138
- } finally {
139
- await handle.close()
140
- }
141
- }
142
-
143
- /** One original through the stream validator, as a stored file. */
144
135
  /** A download, tried again when it stalls or drops; the last error is thrown. */
145
136
  async function downloadWithRetries(
146
137
  options: Readonly<CorpusOptions>,
@@ -181,8 +172,12 @@ async function judge(
181
172
  }
182
173
  }
183
174
  const plain = isPlainTar(await firstBytes(file))
184
- const stored = await storedDeprecations(file, plain)
185
- return { verdict: 'valid', ...stored, transient: false }
175
+ return {
176
+ verdict: 'valid',
177
+ ...(await storedDeprecations(file, plain)),
178
+ ...(await candidateField(options.candidate, file, plain)),
179
+ transient: false,
180
+ }
186
181
  } catch (error: unknown) {
187
182
  return { verdict: 'fails', reason: shortReason(error), transient: false }
188
183
  } finally {
@@ -199,10 +194,12 @@ async function cachedVerdict(
199
194
  await readFile(path.join(options.cache, `${hash}.json`), 'utf8'),
200
195
  )
201
196
  const cached = parse(CachedSchema, raw)
197
+ // FE3b: a candidate run judges every original again.
202
198
  // A valid verdict cached before FE7 has no deprecation list: judge it again.
203
199
  const stale =
204
200
  cached.verdict === 'valid' && cached.deprecations === undefined
205
- return cached.validator === options.validator && !stale ? cached : undefined
201
+ const fresh = cached.validator === options.validator && !stale
202
+ return fresh && options.candidate === undefined ? cached : undefined
206
203
  } catch {
207
204
  return undefined
208
205
  }
@@ -246,55 +243,40 @@ async function row(
246
243
  }
247
244
  }
248
245
 
249
- /** Every kept original's verdict, in the API's upload order. */
250
- async function runCorpus(
246
+ /** The API's public list of kept originals. */
247
+ async function listKept(
251
248
  options: Readonly<CorpusOptions>,
252
- ): Promise<CorpusRow[]> {
249
+ ): Promise<readonly StoredRecord[]> {
253
250
  const listed = await (options.fetch ?? fetch)(
254
251
  new URL('/api/shardfiles', options.api),
255
- {
256
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
257
- },
252
+ { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) },
258
253
  )
259
254
  if (listed.status < OK_LOW || listed.status >= OK_HIGH) {
260
255
  throw new Error(`list: HTTP ${String(listed.status)}`)
261
256
  }
262
- const { shardfiles } = parse(ListSchema, await listed.json())
257
+ return parse(ListSchema, await listed.json()).shardfiles
258
+ }
259
+
260
+ /** Every kept original's verdict, in the API's upload order, then engine's pins the list leaves out (FE13). */
261
+ async function runCorpus(
262
+ options: Readonly<CorpusOptions>,
263
+ ): Promise<CorpusRow[]> {
264
+ const kept = await listKept(options)
265
+ const shardfiles = kept.filter((stored: StoredRecord): boolean =>
266
+ onlyNamed(options.only, stored.revisions),
267
+ )
268
+ const pins = options.pins ?? []
269
+ const pinned = new Set(pins.map((pin: Readonly<Pin>): string => pin.hash))
263
270
  const rows: CorpusRow[] = []
264
- for (const stored of shardfiles) {
271
+ for (const stored of withPins(shardfiles, pins)) {
265
272
  // oxlint-disable-next-line eslint/no-await-in-loop -- one original at a time keeps memory bounded
266
- rows.push(await row(options, stored))
273
+ const found = await row(options, stored)
274
+ rows.push(pinned.has(stored.hash) ? { ...found, pinned: true } : found)
267
275
  }
268
276
  return rows
269
277
  }
270
278
 
271
- function corpusReport(rows: readonly CorpusRow[]): string {
272
- const lines = rows.map(
273
- (found: Readonly<CorpusRow>): string =>
274
- `${found.verdict.padEnd(VERDICT_WIDTH)} ${found.slug} r${String(found.revision)} ${found.hash.slice(FIRST, SHORT_HASH)}${found.reason === undefined ? '' : ` ${found.reason}`}`,
275
- )
276
- const failed = rows.filter(
277
- (found: Readonly<CorpusRow>): boolean => found.verdict === 'fails',
278
- ).length
279
- const fetched = rows.filter(
280
- (found: Readonly<CorpusRow>): boolean => !found.cached,
281
- )
282
- const bytes = fetched.reduce(
283
- (sum: number, found: Readonly<CorpusRow>): number =>
284
- sum + found.storedBytes,
285
- NONE,
286
- )
287
- lines.push(
288
- `corpus: ${String(rows.length)} kept originals, ${String(rows.length - failed)} valid, ${String(failed)} fail; fetched ${String(fetched.length)} (${String(bytes)} stored bytes), ${String(rows.length - fetched.length)} from cache`,
289
- ...deprecationLines(rows),
290
- )
291
- return lines.join('\n')
292
- }
279
+ export { type CorpusOptions, type CorpusRow, type StoredRecord, runCorpus }
293
280
 
294
- export {
295
- type CorpusOptions,
296
- type CorpusRow,
297
- corpusReport,
298
- isPlainTar,
299
- runCorpus,
300
- }
281
+ export { corpusReport } from './corpus-report.ts'
282
+ export { isPlainTar } from './corpus-tar.ts'
@@ -0,0 +1,112 @@
1
+ import { execFile } from 'node:child_process'
2
+ import { promisify } from 'node:util'
3
+
4
+ import { readLock } from './format-diff-lock.ts'
5
+ import { formatDiffReport } from './format-diff-report.ts'
6
+ import { formatDiff } from './format-diff.ts'
7
+
8
+ import type { LockData } from './format-diff-lock.ts'
9
+ import type { Report } from './format-diff.ts'
10
+
11
+ // SHARD-COMPAT FE6: range mode. `shard-format format-diff <a>..<b>` diffs
12
+ // each commit in the range that touched the format lock against the one
13
+ // before it, then the range's two ends: the net delta. A part added and
14
+ // removed inside the range shows in its steps and not in the net.
15
+
16
+ interface Locked {
17
+ readonly ref: string
18
+ readonly lock: LockData
19
+ }
20
+
21
+ interface RangeStep {
22
+ readonly from: string
23
+ readonly to: string
24
+ readonly report: Report
25
+ }
26
+
27
+ interface RangeReport {
28
+ readonly steps: readonly RangeStep[]
29
+ readonly net: Report
30
+ }
31
+
32
+ // eslint-disable-next-line typescript/strict-void-return -- Node execFile returns a child while its callback supplies the result.
33
+ const run = promisify(execFile)
34
+ const RANGE = '..'
35
+ const LOCK_PATH = 'src/format/lock'
36
+ const SHORT = 9
37
+ const FIRST = 0
38
+ const NEXT = 1
39
+
40
+ /** Each consecutive pair's diff, and the ends' diff. */
41
+ function rangeDiff(locks: readonly Readonly<Locked>[]): RangeReport {
42
+ const first = locks.at(FIRST)
43
+ const last = locks.at(-NEXT)
44
+ if (first === undefined || last === undefined) {
45
+ throw new Error('a range needs at least one lock')
46
+ }
47
+ const steps = locks
48
+ .slice(NEXT)
49
+ .map((to: Readonly<Locked>, at: number): RangeStep => ({
50
+ from: locks[at]?.ref ?? first.ref,
51
+ to: to.ref,
52
+ report: formatDiff(locks[at]?.lock ?? first.lock, to.lock),
53
+ }))
54
+ return { steps, net: formatDiff(first.lock, last.lock) }
55
+ }
56
+
57
+ /** `<a>..<b>`'s ends and every commit between that touched the lock, oldest first. */
58
+ async function rangeRefs(
59
+ range: string,
60
+ cwd: string,
61
+ ): Promise<readonly string[]> {
62
+ const [from = '', to = ''] = range.split(RANGE)
63
+ const { stdout } = await run(
64
+ 'git',
65
+ ['rev-list', '--reverse', `${from}..${to}`, '--', LOCK_PATH],
66
+ { cwd, encoding: 'utf8' },
67
+ )
68
+ const inside = stdout
69
+ .split('\n')
70
+ .filter((line: string): boolean => line !== '')
71
+ const parsed = await run('git', ['rev-parse', to], { cwd, encoding: 'utf8' })
72
+ const tip = parsed.stdout.trim()
73
+ return [from, ...inside.filter((sha: string): boolean => sha !== tip), to]
74
+ }
75
+
76
+ /** Lock every ref of a range and diff it. */
77
+ async function readRange(range: string, cwd: string): Promise<RangeReport> {
78
+ const refs = await rangeRefs(range, cwd)
79
+ const locks: Locked[] = []
80
+ for (const ref of refs) {
81
+ // oxlint-disable-next-line eslint/no-await-in-loop -- each ref unpacks into the same scratch folder
82
+ locks.push({ ref, lock: await readLock(ref, cwd) })
83
+ }
84
+ return rangeDiff(locks)
85
+ }
86
+
87
+ function isRange(operand: string): boolean {
88
+ return operand.includes(RANGE)
89
+ }
90
+
91
+ const short = (ref: string): string =>
92
+ /^[\da-f]{40}$/u.test(ref) ? ref.slice(FIRST, SHORT) : ref
93
+
94
+ /** Each step's report under its commit pair, then the net delta. */
95
+ function rangeReport(report: Readonly<RangeReport>): string {
96
+ return [
97
+ ...report.steps.map(
98
+ (step: Readonly<RangeStep>): string =>
99
+ `${short(step.from)}..${short(step.to)}\n${formatDiffReport(step.report)}`,
100
+ ),
101
+ `net\n${formatDiffReport(report.net)}`,
102
+ ].join('\n\n')
103
+ }
104
+
105
+ /** `format-diff <a>..<b>`: the range's report, as text or JSON. */
106
+ async function rangeOutput(range: string, json: boolean): Promise<string> {
107
+ const report = await readRange(range, process.cwd())
108
+ return json ? JSON.stringify(report, undefined, NEXT) : rangeReport(report)
109
+ }
110
+
111
+ export { isRange, rangeDiff, rangeOutput, rangeReport, readRange }
112
+ export type { Locked, RangeReport, RangeStep }
package/src/cli/main.ts CHANGED
@@ -3,6 +3,7 @@ import { parseArgs } from 'node:util'
3
3
 
4
4
  import { corpusCommand } from './corpus-command.ts'
5
5
  import { readLock } from './format-diff-lock.ts'
6
+ import { isRange, rangeOutput } from './format-diff-range.ts'
6
7
  import { formatDiffReport } from './format-diff-report.ts'
7
8
  import { formatDiff } from './format-diff.ts'
8
9
  import { packFolder } from './pack.ts'
@@ -31,12 +32,19 @@ Commands:
31
32
  Tar a folder into a shardfile: what its sections
32
33
  measure follows them, and format's validator must
33
34
  pass. Writes <slug>.tar by default
34
- corpus [--api <url>] [--cache <dir>] [--usage <file>]
35
+ corpus [--api <url>] [--cache <dir>] [--usage <file>] [--pins <file|url>]
36
+ [--candidate <module>] [--only <slug,...>]
35
37
  Validate every stored shard file the API keeps,
36
38
  as stored originals; list every failure. Exits 3
37
39
  when any fails. --usage writes who uses each
38
40
  deprecated path and chain step (FE13 reads it)
41
+ --candidate <module> judges each original again
42
+ under a candidate chain and validator (FE3b):
43
+ valid, migrates or fails by path; --only <slugs>
44
+ limits the run to those shards (slug@r5: one
45
+ revision)
39
46
  format-diff <a> <b> [--json]
47
+ format-diff <a>..<b> [--json] (FE6) each lock change in the range, then the net delta
40
48
  Classify every change between two format locks
41
49
  (a git ref or a folder holding src/format/lock):
42
50
  additive, deprecation, breaking or review, with
@@ -57,6 +65,9 @@ interface CliArgs {
57
65
  readonly version: boolean
58
66
  readonly json: boolean
59
67
  readonly usage: string | undefined
68
+ readonly pins: string | undefined
69
+ readonly candidate: string | undefined
70
+ readonly only: string | undefined
60
71
  }
61
72
 
62
73
  function parseCliArgs(argv: readonly string[]): CliArgs {
@@ -71,6 +82,9 @@ function parseCliArgs(argv: readonly string[]): CliArgs {
71
82
  version: { type: 'boolean', default: false },
72
83
  json: { type: 'boolean', default: false },
73
84
  usage: { type: 'string' },
85
+ pins: { type: 'string' },
86
+ candidate: { type: 'string' },
87
+ only: { type: 'string' },
74
88
  },
75
89
  })
76
90
  const [command, ...operands] = positionals
@@ -84,6 +98,9 @@ function parseCliArgs(argv: readonly string[]): CliArgs {
84
98
  version: values.version,
85
99
  json: values.json,
86
100
  usage: values.usage,
101
+ pins: values.pins,
102
+ candidate: values.candidate,
103
+ only: values.only,
87
104
  }
88
105
  }
89
106
 
@@ -142,22 +159,35 @@ async function pack(args: CliArgs): Promise<number> {
142
159
  return await packReport(dir, args.out)
143
160
  }
144
161
 
162
+ /** `format-diff <a> <b>`: the two locks' report, as text or JSON. */
163
+ async function pairOutput(
164
+ before: string,
165
+ after: string,
166
+ json: boolean,
167
+ ): Promise<string> {
168
+ const cwd = process.cwd()
169
+ const report = formatDiff(
170
+ await readLock(before, cwd),
171
+ await readLock(after, cwd),
172
+ )
173
+ return json
174
+ ? JSON.stringify(report, undefined, JSON_INDENT)
175
+ : formatDiffReport(report)
176
+ }
177
+
145
178
  async function formatDiffCommand(args: CliArgs): Promise<number> {
146
179
  const [before, after, ...extra] = args.operands
180
+ if (before !== undefined && isRange(before) && after === undefined) {
181
+ process.stdout.write(`${await rangeOutput(before, args.json)}\n`)
182
+ return EXIT_OK
183
+ }
147
184
  if (before === undefined || after === undefined || extra.length > NONE) {
148
185
  process.stderr.write(
149
186
  `shard-format: format-diff takes two locks\n\n${USAGE}`,
150
187
  )
151
188
  return EXIT_USAGE
152
189
  }
153
- const cwd = process.cwd()
154
- const report = formatDiff(
155
- await readLock(before, cwd),
156
- await readLock(after, cwd),
157
- )
158
- process.stdout.write(
159
- `${args.json ? JSON.stringify(report, undefined, JSON_INDENT) : formatDiffReport(report)}\n`,
160
- )
190
+ process.stdout.write(`${await pairOutput(before, after, args.json)}\n`)
161
191
  return EXIT_OK
162
192
  }
163
193
 
package/src/cli/pack.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  parseOutputIndex,
8
8
  } from '../format/outputIndex.ts'
9
9
  import { receiptCost } from '../format/receipt-cost.ts'
10
+ import { asWrittenIdentity } from '../format/save-revision.ts'
10
11
  import { packFromMembers } from '../format/shardfile-reads.ts'
11
12
  import { writeTar } from '../format/tar.ts'
12
13
  import { validationSourceBytes } from '../format/validationReceipt.ts'
@@ -56,6 +57,9 @@ interface PackRow extends Listed {
56
57
  /** The rows of `shard.json` this reads; the rest passes through. */
57
58
  interface HeldIndex {
58
59
  readonly build: Readonly<{ sourceHash: string }>
60
+ /** FP26: which spelling of the save lineage the hashes cover. */
61
+ readonly formatVersion?: unknown
62
+ readonly identity?: unknown
59
63
  readonly files: readonly Listed[]
60
64
  readonly packs?: readonly PackRow[] | undefined
61
65
  readonly schemas?: readonly Listed[] | undefined
@@ -197,7 +201,21 @@ function sourceHash(index: HeldIndex, files: Files): string {
197
201
  jsonOf(held(files, row.path)),
198
202
  ]),
199
203
  )
200
- return sha256(validationSourceBytes(assembleOutputShardfile(index, payloads)))
204
+ // FP26: an older format's hash covers the identity as it wrote it (`revision`).
205
+ const shard = assembleOutputShardfile(index, payloads)
206
+ return sha256(
207
+ validationSourceBytes(asWrittenIdentity(shard, index.formatVersion)),
208
+ )
209
+ }
210
+
211
+ /** `shard.json` with its new source hash, the save lineage spelled as its format writes it (FP26). */
212
+ function indexBytes(index: HeldIndex, source: string): Uint8Array {
213
+ const build = { ...index.build, sourceHash: source }
214
+ const written = asWrittenIdentity(
215
+ { ...index, identity: index.identity, build },
216
+ index.formatVersion,
217
+ )
218
+ return validationSourceBytes(written)
201
219
  }
202
220
 
203
221
  /** The index's bytes, and the receipt that names them. */
@@ -206,8 +224,7 @@ function sealed(
206
224
  files: Files,
207
225
  ): readonly (readonly [string, Uint8Array])[] {
208
226
  const source = sourceHash(index, files)
209
- const build = { ...index.build, sourceHash: source }
210
- const bytes = validationSourceBytes({ ...index, build })
227
+ const bytes = indexBytes(index, source)
211
228
  const receipt = files.get(RECEIPT)
212
229
  if (receipt === undefined) {
213
230
  return [[INDEX, bytes]]
@@ -188,7 +188,7 @@ async function validateShardfile(target: string): Promise<ValidationSummary> {
188
188
  )
189
189
  return {
190
190
  slug: valid.shard.identity.slug,
191
- revision: valid.shard.identity.revision,
191
+ revision: valid.shard.identity.saveRevision,
192
192
  sections: valid.sections.size,
193
193
  assets: valid.assets.size,
194
194
  sourceHash: valid.index.build.sourceHash,
@@ -14,7 +14,7 @@ export function clientOwnershipRules(source: Shardfile, sections: ReadonlyMap<st
14
14
  // OF19d1: a page drawing its declared bodies from their looks needs no species program
15
15
  const errors: string[] = [...rigs], program = !pageDrawsDeclaredLooks(source, sections.get('sim/runtime-plan'), features);
16
16
  if (!page || source.runtime !== null) errors.push('Native client features require their typed data page owner');
17
- for (const kind of ['world.scenes', 'motion.channels', ...program ? ['species.program'] as const : [], 'held.melee', 'quest.page', 'population.homes'] as const)
17
+ for (const kind of ['world.scenes', 'motion.channels', ...program ? ['species.program'] as const : [], 'held.melee', 'quest.page'] as const)
18
18
  if (!features.some(row => row.kind === kind)) errors.push(`Data page requires ${kind}`);
19
19
  const quest = features.find(row => row.kind === 'quest.page'), held = features.find(row => row.kind === 'held.melee');
20
20
  const declared = source.questHost?.page;
@@ -1,56 +1,131 @@
1
- import {isJsonData} from './json.ts';
2
- import * as v from 'valibot';
1
+ import * as v from 'valibot'
3
2
 
4
- const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
5
- const real = v.pipe(v.number(), v.minValue(0), v.maxValue(10000));
3
+ import { isJsonData } from './json.ts'
4
+
5
+ const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128))
6
+ const real = v.pipe(v.number(), v.minValue(0), v.maxValue(10000))
7
+ const FEWEST_MEMBERS = 1
8
+ const MOST_MEMBERS = 256
9
+ const group = v.exactOptional(id)
10
+ const members = v.exactOptional(
11
+ v.pipe(v.array(id), v.minLength(FEWEST_MEMBERS), v.maxLength(MOST_MEMBERS)),
12
+ )
13
+ /** Whether no two trail rows share a system id. */
14
+ function uniqueIds(rows: readonly Readonly<{ id: string }>[]): boolean {
15
+ return (
16
+ new Set(rows.map((row: Readonly<{ id: string }>): string => row.id))
17
+ .size === rows.length
18
+ )
19
+ }
20
+ /** Whether every trail row names exactly one of its group and its members. */
21
+ function oneSource(
22
+ rows: readonly Partial<Readonly<Record<'group' | 'members', unknown>>>[],
23
+ ): boolean {
24
+ for (const row of rows) {
25
+ if ((row.group === undefined) === (row.members === undefined)) {
26
+ return false
27
+ }
28
+ }
29
+ return true
30
+ }
6
31
  /** Client-only trails follow actual native population groups in their local
7
- * world frame. Looks and timing are data; there are no owner callbacks. */
8
- export const ClientTrailsSchema: v.StrictObjectSchema<{ readonly kind: v.GenericSchema<ClientTrailsRowsInput['kind'], ClientTrailsRows['kind']>; readonly rows: v.GenericSchema<ClientTrailsRowsInput['rows'], ClientTrailsRows['rows']>; }, undefined> = v.strictObject({ kind: v.literal('fx.trail'), rows: v.pipe(v.array(v.strictObject({
9
- id, group: id, library: id, look: id, name: id,
10
- points: v.pipe(v.number(), v.integer(), v.minValue(2), v.maxValue(2048)),
11
- every: v.pipe(real, v.minValue(0.001)), width: real, minimum: real, movementSq: real,
12
- })), v.maxLength(64), v.check(rows => new Set(rows.map(row => row.id)).size === rows.length, 'Unique trail systems')) });
32
+ * world frame. Looks and timing are data; there are no owner callbacks. A row
33
+ * names a page population's group, or (ONE-FORMAT OF29e7a) the declared spawns
34
+ * it follows as `members`; exactly one. */
35
+ export const ClientTrailsSchema: v.StrictObjectSchema<
36
+ {
37
+ readonly kind: v.GenericSchema<
38
+ ClientTrailsRowsInput['kind'],
39
+ ClientTrailsRows['kind']
40
+ >
41
+ readonly rows: v.GenericSchema<
42
+ ClientTrailsRowsInput['rows'],
43
+ ClientTrailsRows['rows']
44
+ >
45
+ },
46
+ undefined
47
+ > = v.strictObject({
48
+ kind: v.literal('fx.trail'),
49
+ rows: v.pipe(
50
+ v.array(
51
+ v.strictObject({
52
+ id,
53
+ group,
54
+ members,
55
+ library: id,
56
+ look: id,
57
+ name: id,
58
+ points: v.pipe(
59
+ v.number(),
60
+ v.integer(),
61
+ v.minValue(2),
62
+ v.maxValue(2048),
63
+ ),
64
+ every: v.pipe(real, v.minValue(0.001)),
65
+ width: real,
66
+ minimum: real,
67
+ movementSq: real,
68
+ }),
69
+ ),
70
+ v.maxLength(64),
71
+ v.check<ClientTrailsRows['rows'], string>(
72
+ uniqueIds,
73
+ 'Unique trail systems',
74
+ ),
75
+ v.check<ClientTrailsRows['rows'], string>(
76
+ oneSource,
77
+ 'A trail names its group or its members',
78
+ ),
79
+ ),
80
+ })
13
81
 
14
82
  /** A predicted line uses prepared widths and a finite fade envelope. */
15
- export const ProjectedTrailSchema: v.GenericSchema<ProjectedTrailRowsInput, ProjectedTrailRows>=v.pipe(v.unknown(),v.check(isJsonData),v.strictObject({
16
- points:v.pipe(v.number(),v.integer(),v.minValue(2),v.maxValue(256)),
17
- width:v.tuple([real,real]),lifetime:v.pipe(real,v.minValue(.001)),fade:real,
18
- color:v.tuple([real,real,real]),order:v.pipe(v.number(),v.integer(),v.minValue(-100),v.maxValue(100)),
19
- }));
20
-
83
+ export const ProjectedTrailSchema: v.GenericSchema<
84
+ ProjectedTrailRowsInput,
85
+ ProjectedTrailRows
86
+ > = v.pipe(
87
+ v.unknown(),
88
+ v.check(isJsonData),
89
+ v.strictObject({
90
+ points: v.pipe(v.number(), v.integer(), v.minValue(2), v.maxValue(256)),
91
+ width: v.tuple([real, real]),
92
+ lifetime: v.pipe(real, v.minValue(0.001)),
93
+ fade: real,
94
+ color: v.tuple([real, real, real]),
95
+ order: v.pipe(v.number(), v.integer(), v.minValue(-100), v.maxValue(100)),
96
+ }),
97
+ )
21
98
 
22
99
  /** Admitted data contracts, independent of validator implementation metadata. */
23
- export type ClientTrailsRowsInput = ClientTrailsRows;
100
+ export type ClientTrailsRowsInput = ClientTrailsRows
24
101
  interface ClientTrailsRowsFields {
25
- kind: 'fx.trail';
26
- rows: ({
27
- id: string;
28
- group: string;
29
- library: string;
30
- look: string;
31
- name: string;
32
- points: number;
33
- every: number;
34
- width: number;
35
- minimum: number;
36
- movementSq: number;
37
- })[];
102
+ kind: 'fx.trail'
103
+ rows: {
104
+ id: string
105
+ group?: string
106
+ members?: string[]
107
+ library: string
108
+ look: string
109
+ name: string
110
+ points: number
111
+ every: number
112
+ width: number
113
+ minimum: number
114
+ movementSq: number
115
+ }[]
116
+ }
117
+ export type ClientTrailsRows = {
118
+ [Key in keyof ClientTrailsRowsFields]: ClientTrailsRowsFields[Key]
38
119
  }
39
- export type ClientTrailsRows = { [Key in keyof ClientTrailsRowsFields]: ClientTrailsRowsFields[Key] };
40
- export type ProjectedTrailRowsInput = unknown;
120
+ export type ProjectedTrailRowsInput = unknown
41
121
  interface ProjectedTrailRowsFields {
42
- points: number;
43
- width: [
44
- number,
45
- number
46
- ];
47
- lifetime: number;
48
- fade: number;
49
- color: [
50
- number,
51
- number,
52
- number
53
- ];
54
- order: number;
122
+ points: number
123
+ width: [number, number]
124
+ lifetime: number
125
+ fade: number
126
+ color: [number, number, number]
127
+ order: number
128
+ }
129
+ export type ProjectedTrailRows = {
130
+ [Key in keyof ProjectedTrailRowsFields]: ProjectedTrailRowsFields[Key]
55
131
  }
56
- export type ProjectedTrailRows = { [Key in keyof ProjectedTrailRowsFields]: ProjectedTrailRowsFields[Key] };