animader-cli 0.1.1 → 0.2.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,422 @@
1
+ // Editor schema associations and packaged resource staging.
2
+ //
3
+ // The exported snapshot's own `metadata.json` is the only manifest inventory:
4
+ // this module renders `sjon-lsp.sjon` from that metadata and stages the
5
+ // snapshot's exact bytes. It is portable — reads arrive through the injected
6
+ // `io` functions, no process is started and no network is touched. The
7
+ // explicit `prepare-editor-resources.mjs` script owns the one Zig build
8
+ // invocation.
9
+
10
+ import { PROJECT_FILES } from './contract.mjs';
11
+ import { projectError } from './errors.mjs';
12
+
13
+ export const EDITOR_RESOURCE_ROOT = new URL('../resources/editor/', import.meta.url);
14
+ export const EDITOR_CONFIG_PATH = 'sjon-lsp.sjon';
15
+ export const EDITOR_SCHEMA_DIR = '.animader/schemas';
16
+ export const EDITOR_CONFIG_VERSION = 1;
17
+
18
+ const SNAPSHOT_FORMAT = 'animader-schema-snapshot/1';
19
+ const SNAPSHOT_FILE = 'metadata.json';
20
+ const SOURCE_OWNERS = new Set(['animader', 'tempura', 'pngine']);
21
+ const DIRECTORY_PATTERNS = Object.freeze([
22
+ 'examples/cli',
23
+ 'npm/cli/starters',
24
+ 'demo/starters',
25
+ 'demo/pieces',
26
+ ]);
27
+ const VERIFIED_PROGRAM_FILES = Object.freeze([
28
+ 'examples/hello',
29
+ 'demo/fixture',
30
+ ]);
31
+
32
+ const PREPARE_REMEDY = 'Regenerate the packaged editor resources on a host with Zig: '
33
+ + 'node npm/cli/scripts/prepare-editor-resources.mjs --profile starter --output npm/cli/resources/editor '
34
+ + '(the repository gate runs that command through obs). A plain npm test in npm/cli or demo requires this preparation first.';
35
+
36
+ function metadataError(message) {
37
+ return projectError(
38
+ 'editor_metadata_invalid',
39
+ `editor snapshot metadata is invalid: ${message}`,
40
+ PREPARE_REMEDY,
41
+ );
42
+ }
43
+
44
+ function configError(message) {
45
+ return projectError(
46
+ 'editor_config_mismatch',
47
+ `editor configuration does not match the exported snapshot: ${message}`,
48
+ PREPARE_REMEDY,
49
+ );
50
+ }
51
+
52
+ function resourceError(code, message) {
53
+ return projectError(code, message, PREPARE_REMEDY);
54
+ }
55
+
56
+ /**
57
+ * Normalize one relative resource path lexically. Absolute paths, drive
58
+ * paths, backslashes, NULs, traversal and glob syntax are refused before
59
+ * any URL is joined or any file is read.
60
+ */
61
+ function normalizeResourcePath(value, label) {
62
+ if (typeof value !== 'string' || value === '') {
63
+ throw metadataError(`${label} is not a nonempty string`);
64
+ }
65
+ if (value.includes('\0')) throw metadataError(`${label} contains a NUL byte`);
66
+ if (value.includes('\\')) throw metadataError(`${label} contains a backslash: ${JSON.stringify(value)}`);
67
+ if (value.startsWith('/') || /^[A-Za-z]:/.test(value) || value.startsWith('//')) {
68
+ throw metadataError(`${label} is absolute: ${JSON.stringify(value)}`);
69
+ }
70
+ if (/[*?{}[\]:]/.test(value)) {
71
+ throw metadataError(`${label} contains glob or URL syntax: ${JSON.stringify(value)}`);
72
+ }
73
+ const segments = [];
74
+ for (const segment of value.split('/')) {
75
+ if (segment === '' || segment === '.') continue;
76
+ if (segment === '..') throw metadataError(`${label} traverses a parent: ${JSON.stringify(value)}`);
77
+ segments.push(segment);
78
+ }
79
+ if (segments.length === 0) throw metadataError(`${label} is empty after normalization`);
80
+ return segments.join('/');
81
+ }
82
+
83
+ function documentName(value, label) {
84
+ if (typeof value !== 'string' || value === '') {
85
+ throw projectError('editor_project_files_invalid', `editor ${label} document name is empty`);
86
+ }
87
+ if (value.includes('/') || value.includes('\\') || value.includes('\0') || value === '.' || value === '..') {
88
+ throw projectError(
89
+ 'editor_project_files_invalid',
90
+ `editor ${label} document name must be a plain root file name: ${JSON.stringify(value)}`,
91
+ );
92
+ }
93
+ return value;
94
+ }
95
+
96
+ /**
97
+ * Validate and normalize the exported `metadata.json`. The contract is fixed:
98
+ * ten sources, a nine-member timeline and a one-member program bundle, with
99
+ * every source belonging to exactly one bundle. The source *order* and
100
+ * manifest *order* are preserved as exported; nothing here re-sorts them.
101
+ */
102
+ function validateMetadata(metadata) {
103
+ if (metadata === null || typeof metadata !== 'object' || Array.isArray(metadata)) {
104
+ throw metadataError('the document is not an object');
105
+ }
106
+ if (metadata.format !== SNAPSHOT_FORMAT) {
107
+ throw metadataError(`format must be ${JSON.stringify(SNAPSHOT_FORMAT)}`);
108
+ }
109
+ if (!Array.isArray(metadata.sources) || metadata.sources.length === 0) {
110
+ throw metadataError('sources must be a nonempty array');
111
+ }
112
+
113
+ const sources = [];
114
+ const byFile = new Map();
115
+ for (const [index, source] of metadata.sources.entries()) {
116
+ if (source === null || typeof source !== 'object' || Array.isArray(source)) {
117
+ throw metadataError(`sources[${index}] is not an object`);
118
+ }
119
+ if (typeof source.name !== 'string' || !/^[a-z][a-z0-9_-]*$/.test(source.name)) {
120
+ throw metadataError(`sources[${index}].name is not a schema name`);
121
+ }
122
+ const file = normalizeResourcePath(source.file, `sources[${index}].file`);
123
+ if (!file.endsWith('.sjon')) {
124
+ throw metadataError(`sources[${index}].file must be a .sjon file: ${JSON.stringify(source.file)}`);
125
+ }
126
+ if (file !== `${source.name}.sjon`) {
127
+ throw metadataError(
128
+ `sources[${index}].file must be named after its source: ${JSON.stringify(source.file)}`,
129
+ );
130
+ }
131
+ if (file === SNAPSHOT_FILE) {
132
+ throw metadataError(`sources[${index}].file shadows the snapshot metadata file`);
133
+ }
134
+ if (byFile.has(file)) {
135
+ throw metadataError(`duplicate normalized source path ${JSON.stringify(file)}`);
136
+ }
137
+ if (!SOURCE_OWNERS.has(source.owner)) {
138
+ throw metadataError(`sources[${index}].owner is not animader, tempura or pngine`);
139
+ }
140
+ if (typeof source.optional !== 'boolean') {
141
+ throw metadataError(`sources[${index}].optional is not a boolean`);
142
+ }
143
+ if (!Number.isInteger(source.bytes) || source.bytes < 0) {
144
+ throw metadataError(`sources[${index}].bytes is not a nonnegative integer`);
145
+ }
146
+ if (typeof source.sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(source.sha256)) {
147
+ throw metadataError(`sources[${index}].sha256 is not 64 lowercase hex characters`);
148
+ }
149
+ const normalized = {
150
+ name: source.name,
151
+ file,
152
+ owner: source.owner,
153
+ optional: source.optional,
154
+ bytes: source.bytes,
155
+ sha256: source.sha256,
156
+ };
157
+ sources.push(normalized);
158
+ byFile.set(file, normalized);
159
+ }
160
+
161
+ if (sources.length !== 10) {
162
+ throw metadataError(`exactly ten sources are required; found ${sources.length}`);
163
+ }
164
+ if (!Array.isArray(metadata.bundles) || metadata.bundles.length !== 2) {
165
+ throw metadataError('exactly the timeline and program bundles are required');
166
+ }
167
+
168
+ const bundles = new Map();
169
+ for (const [index, bundle] of metadata.bundles.entries()) {
170
+ if (bundle === null || typeof bundle !== 'object' || Array.isArray(bundle)) {
171
+ throw metadataError(`bundles[${index}] is not an object`);
172
+ }
173
+ if (bundle.name !== 'timeline' && bundle.name !== 'program') {
174
+ throw metadataError(`bundles[${index}] has an unexpected name`);
175
+ }
176
+ if (bundles.has(bundle.name)) throw metadataError(`duplicate bundle ${JSON.stringify(bundle.name)}`);
177
+ if (!Array.isArray(bundle.manifests) || bundle.manifests.length === 0) {
178
+ throw metadataError(`bundle ${bundle.name} has no manifests`);
179
+ }
180
+ const expectedLength = bundle.name === 'timeline' ? 9 : 1;
181
+ if (bundle.manifests.length !== expectedLength) {
182
+ throw metadataError(
183
+ `bundle ${bundle.name} must contain ${expectedLength} manifests; found ${bundle.manifests.length}`,
184
+ );
185
+ }
186
+ const manifests = [];
187
+ const seen = new Set();
188
+ for (const [manifestIndex, manifest] of bundle.manifests.entries()) {
189
+ const file = normalizeResourcePath(manifest, `bundle ${bundle.name} manifest ${manifestIndex}`);
190
+ if (seen.has(file)) {
191
+ throw metadataError(`bundle ${bundle.name} repeats normalized path ${JSON.stringify(file)}`);
192
+ }
193
+ if (!byFile.has(file)) {
194
+ throw metadataError(`bundle ${bundle.name} names an unknown source ${JSON.stringify(file)}`);
195
+ }
196
+ seen.add(file);
197
+ manifests.push(file);
198
+ }
199
+ bundles.set(bundle.name, { name: bundle.name, manifests });
200
+ }
201
+ if (!bundles.has('timeline') || !bundles.has('program')) {
202
+ throw metadataError('both the timeline and program bundles are required');
203
+ }
204
+
205
+ const timeline = bundles.get('timeline');
206
+ const program = bundles.get('program');
207
+ const members = new Set(timeline.manifests);
208
+ for (const manifest of program.manifests) {
209
+ if (members.has(manifest)) {
210
+ throw metadataError(`source ${JSON.stringify(manifest)} belongs to both bundles`);
211
+ }
212
+ }
213
+ for (const source of sources) {
214
+ if (!members.has(source.file) && !program.manifests.includes(source.file)) {
215
+ throw metadataError(`source ${JSON.stringify(source.file)} has no bundle membership`);
216
+ }
217
+ }
218
+
219
+ return { sources, timeline, program };
220
+ }
221
+
222
+ /** Render one string vector in the fixed generated layout. */
223
+ function vectorLines(keyword, values) {
224
+ const indent = ' '.repeat(9 + keyword.length);
225
+ const lines = [` :${keyword} [${JSON.stringify(values[0])}`];
226
+ for (const value of values.slice(1)) lines.push(`${indent}${JSON.stringify(value)}`);
227
+ lines[lines.length - 1] += ']';
228
+ return lines;
229
+ }
230
+
231
+ /**
232
+ * Render the exact `sjon-lsp.sjon` configuration. The starter profile uses
233
+ * only the two root document names; the contributor profile uses the eight
234
+ * pinned per-directory patterns plus the two individually verified program
235
+ * files. Neither profile ever emits a bare directory `**` pattern.
236
+ *
237
+ * @param {Object} options
238
+ * @param {Object} options.metadata parsed exported `metadata.json`
239
+ * @param {'starter'|'contributor'} [options.profile]
240
+ * @param {Object} [options.projectFiles]
241
+ * @returns {string}
242
+ */
243
+ export function renderEditorConfig({
244
+ metadata,
245
+ profile = 'starter',
246
+ projectFiles = PROJECT_FILES,
247
+ } = {}) {
248
+ if (profile !== 'starter' && profile !== 'contributor') {
249
+ throw projectError(
250
+ 'editor_profile_invalid',
251
+ `unknown editor profile ${JSON.stringify(profile)}; expected starter or contributor`,
252
+ );
253
+ }
254
+ if (projectFiles === null || typeof projectFiles !== 'object') {
255
+ throw projectError('editor_project_files_invalid', 'editor project files must be an object');
256
+ }
257
+ const programName = documentName(projectFiles.program, 'program');
258
+ const timelineName = documentName(projectFiles.timeline, 'timeline');
259
+ const snapshot = validateMetadata(metadata);
260
+
261
+ let programFiles;
262
+ let timelineFiles;
263
+ if (profile === 'starter') {
264
+ programFiles = [programName];
265
+ timelineFiles = [timelineName];
266
+ } else {
267
+ programFiles = [
268
+ ...DIRECTORY_PATTERNS.map((directory) => `${directory}/**/${programName}`),
269
+ ...VERIFIED_PROGRAM_FILES.map((directory) => `${directory}/${programName}`),
270
+ ];
271
+ timelineFiles = DIRECTORY_PATTERNS.map(
272
+ (directory) => `${directory}/**/${timelineName}`,
273
+ );
274
+ }
275
+
276
+ const bundles = [
277
+ {
278
+ name: 'program',
279
+ files: programFiles,
280
+ manifests: snapshot.program.manifests.map((file) => `${EDITOR_SCHEMA_DIR}/${file}`),
281
+ },
282
+ {
283
+ name: 'timeline',
284
+ files: timelineFiles,
285
+ manifests: snapshot.timeline.manifests.map((file) => `${EDITOR_SCHEMA_DIR}/${file}`),
286
+ },
287
+ ];
288
+
289
+ const lines = [`(sjon-lsp :version ${EDITOR_CONFIG_VERSION}`, ' :bundles ['];
290
+ for (const bundle of bundles) {
291
+ lines.push(` (bundle :name ${bundle.name}`);
292
+ lines.push(...vectorLines('files', bundle.files));
293
+ lines.push(...vectorLines('manifests', bundle.manifests));
294
+ lines[lines.length - 1] = `${lines[lines.length - 1]})`;
295
+ }
296
+ lines[lines.length - 1] = `${lines[lines.length - 1]}])`;
297
+ return `${lines.join('\n')}\n`;
298
+ }
299
+
300
+ /**
301
+ * Every file a packaged/generated editor resource set contains, relative to
302
+ * the resource root: the configuration, the ten exported schemas in source
303
+ * order, then the snapshot metadata.
304
+ *
305
+ * @param {Object} metadata parsed exported `metadata.json`
306
+ * @returns {string[]}
307
+ */
308
+ export function editorResourcePaths(metadata) {
309
+ const snapshot = validateMetadata(metadata);
310
+ return [
311
+ EDITOR_CONFIG_PATH,
312
+ ...snapshot.sources.map((source) => `${EDITOR_SCHEMA_DIR}/${source.file}`),
313
+ `${EDITOR_SCHEMA_DIR}/${SNAPSHOT_FILE}`,
314
+ ];
315
+ }
316
+
317
+ function asResourceRoot(resourceRoot) {
318
+ const url = resourceRoot instanceof URL
319
+ ? new URL(resourceRoot.href)
320
+ : new URL(String(resourceRoot), EDITOR_RESOURCE_ROOT);
321
+ if (!url.pathname.endsWith('/')) url.pathname += '/';
322
+ return url;
323
+ }
324
+
325
+ async function readResource(io, root, path) {
326
+ try {
327
+ const bytes = await io.readFile(new URL(path, root));
328
+ if (!bytes || typeof bytes.byteLength !== 'number') {
329
+ throw new TypeError('readFile returned no byte array');
330
+ }
331
+ return bytes;
332
+ } catch (error) {
333
+ if (error?.code === 'ENOENT' || error?.code === 'ENOTDIR') {
334
+ throw resourceError('editor_resource_missing', `editor resource ${path} is missing`);
335
+ }
336
+ if (error?.code?.startsWith?.('editor_')) throw error;
337
+ throw resourceError(
338
+ 'editor_resource_unreadable',
339
+ `editor resource ${path} could not be read: ${error?.message ?? String(error)}`,
340
+ );
341
+ }
342
+ }
343
+
344
+ function decodeConfig(bytes, path) {
345
+ try {
346
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
347
+ } catch {
348
+ throw resourceError('editor_resource_corrupt', `editor resource ${path} is not valid UTF-8`);
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Read and validate the config, snapshot metadata, every listed schema, its
354
+ * byte count and its SHA-256 before returning any staged resource. The
355
+ * returned order is `editorResourcePaths`' order. No process execution and
356
+ * no network access happen here.
357
+ *
358
+ * @param {Object} options
359
+ * @param {Object} options.io
360
+ * @param {URL|string} [options.resourceRoot]
361
+ * @param {Object} [options.projectFiles]
362
+ * @returns {Promise<Array<{path: string, bytes: Uint8Array, sha256: string}>>}
363
+ */
364
+ export async function stageEditorResources({
365
+ io,
366
+ resourceRoot = EDITOR_RESOURCE_ROOT,
367
+ projectFiles = PROJECT_FILES,
368
+ } = {}) {
369
+ if (!io || typeof io.readFile !== 'function' || typeof io.hashBytes !== 'function') {
370
+ throw new TypeError('stageEditorResources needs io.readFile and io.hashBytes');
371
+ }
372
+ const root = asResourceRoot(resourceRoot);
373
+
374
+ const metadataPath = `${EDITOR_SCHEMA_DIR}/${SNAPSHOT_FILE}`;
375
+ const metadataBytes = await readResource(io, root, metadataPath);
376
+ let metadata;
377
+ try {
378
+ metadata = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(metadataBytes));
379
+ } catch (error) {
380
+ throw metadataError(`metadata.json is not valid UTF-8 JSON: ${error?.message ?? String(error)}`);
381
+ }
382
+ const snapshot = validateMetadata(metadata);
383
+
384
+ const configPath = EDITOR_CONFIG_PATH;
385
+ const configBytes = await readResource(io, root, configPath);
386
+ const configText = decodeConfig(configBytes, configPath);
387
+ const starter = renderEditorConfig({ metadata, profile: 'starter', projectFiles });
388
+ const contributor = renderEditorConfig({ metadata, profile: 'contributor', projectFiles });
389
+ if (configText !== starter && configText !== contributor) {
390
+ throw configError(`${configPath} is neither the starter nor the contributor form for this snapshot`);
391
+ }
392
+
393
+ const staged = [{
394
+ path: configPath,
395
+ bytes: configBytes,
396
+ sha256: io.hashBytes(configBytes),
397
+ }];
398
+ for (const source of snapshot.sources) {
399
+ const path = `${EDITOR_SCHEMA_DIR}/${source.file}`;
400
+ const bytes = await readResource(io, root, path);
401
+ if (bytes.byteLength !== source.bytes) {
402
+ throw resourceError(
403
+ 'editor_resource_corrupt',
404
+ `editor resource ${path} is ${bytes.byteLength} bytes; metadata records ${source.bytes}`,
405
+ );
406
+ }
407
+ const digest = io.hashBytes(bytes);
408
+ if (digest !== source.sha256) {
409
+ throw resourceError(
410
+ 'editor_resource_corrupt',
411
+ `editor resource ${path} digest ${digest} does not match metadata ${source.sha256}`,
412
+ );
413
+ }
414
+ staged.push({ path, bytes, sha256: digest });
415
+ }
416
+ staged.push({
417
+ path: metadataPath,
418
+ bytes: metadataBytes,
419
+ sha256: io.hashBytes(metadataBytes),
420
+ });
421
+ return staged;
422
+ }
package/lib/new.mjs CHANGED
@@ -10,6 +10,7 @@
10
10
  // There is no rollback and no transaction claim.
11
11
 
12
12
  import { PROJECT_FILES } from './contract.mjs';
13
+ import { stageEditorResources } from './editor-resources.mjs';
13
14
  import { DemoError, EXIT_CODES, projectError, usageError } from './errors.mjs';
14
15
  import { createTestTone } from './wav.mjs';
15
16
 
@@ -19,6 +20,7 @@ const CIRCLE_STARTER = new URL('../starters/circle/', import.meta.url).href;
19
20
  const STARTER_FILES = [
20
21
  { path: PROJECT_FILES.program, source: 'program.sjon' },
21
22
  { path: PROJECT_FILES.timeline, source: 'timeline.piece.sjon' },
23
+ { path: 'README.md', source: 'README.md' },
22
24
  { path: 'kernels/curl.wgsl', source: 'kernels/curl.wgsl' },
23
25
  { path: 'kernels/ember.wgsl', source: 'kernels/ember.wgsl' },
24
26
  { path: 'kernels/hash.wgsl', source: 'kernels/hash.wgsl' },
@@ -162,6 +164,10 @@ export function newUsageText() {
162
164
  ' soundtrack.opus — exactly one may exist at a time)',
163
165
  ' kernels/{curl,ember,hash,simplex}.wgsl',
164
166
  ' bake/spans.bin',
167
+ ' sjon-lsp.sjon editor associations for the snapshotted schemas',
168
+ ' .animader/schemas/metadata.json',
169
+ ' .animader/schemas/{piece,world,session,machine,bridge,tempura,midi,it,pacer,pngine}.sjon',
170
+ ' committed offline editor schema snapshot',
165
171
  '',
166
172
  'Options:',
167
173
  ` --starter NAME starter to copy (default: ember; available: ${starterList()})`,
@@ -276,6 +282,11 @@ export async function createProject({ folder, starter, io }) {
276
282
  staged.push({ path: entry.path, bytes, sha256: io.hashBytes(bytes) });
277
283
  }
278
284
 
285
+ // The shared packaged snapshot is staged after the starter's own files
286
+ // (the soundtrack stays the last starter entry) and before any write:
287
+ // a missing or stale resource refuses here, leaving the target empty.
288
+ staged.push(...await stageEditorResources({ io }));
289
+
279
290
  const created = [];
280
291
  for (const file of staged) {
281
292
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "animader-cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "The animader command line: project creation, dev server, build, standalone export and host/project doctor checks",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "license": "CC0-1.0",
13
13
  "dependencies": {
14
- "animader": "0.1.1",
14
+ "animader": "0.2.1",
15
15
  "esbuild": "0.24.2",
16
16
  "@mr_hugo/pacer": "0.2.0",
17
17
  "pngine": "4.1.0"
@@ -28,6 +28,7 @@
28
28
  "player",
29
29
  "hello",
30
30
  "starters",
31
+ "resources",
31
32
  "toolchain",
32
33
  "LICENSE"
33
34
  ],
@@ -0,0 +1,79 @@
1
+ ; animader bridge schema - the machine's public surface (plan 03).
2
+ ;
3
+ ; Two core forms live in the machine document (the machine document is
4
+ ; validated against the aggregate of `machine.sjon` and this manifest,
5
+ ; because the machine's public surface belongs beside the machine):
6
+ ;
7
+ ; (output :name phase :arity 1) what the machine exposes
8
+ ; (route :output phase :target "particles.phase" :registry 0)
9
+ ; optional: where it goes
10
+ ;
11
+ ; Without a route an output joins the host's registries by its own name;
12
+ ; with one it joins by `:target` in `:registry`. Every form is closed
13
+ ; (the default), so each key set is exact and an extra key is SJON's own
14
+ ; `unknown_key` diagnostic.
15
+ ;
16
+ ; A route's `:output` is a cross-reference to an `(output ...)` in the
17
+ ; same document: SJON owns the unresolved-name diagnostic (`not_cross_ref`
18
+ ; with the candidate span), so the bridge never re-checks it. Whether the
19
+ ; named target exists in the host's join list is the bridge's own
20
+ ; business: `Bridge.load` reports `output_unrouted`/`output_arity_mismatch`,
21
+ ; and a registry index at or above the host's count is `registry_unknown`.
22
+ ; The registry index is bounded here only by the wire (u8); the host's
23
+ ; count is what the bridge checks, so a host with two registries rejects a
24
+ ; route to registry 2 even though the house's own hosts expose three
25
+ ; (0 pngine uniforms, 1 audio params, 2 pacer control pins).
26
+ ;
27
+ ; `Bridge.Target`/`Output`/`Route` mirror these forms as plain structs;
28
+ ; `Bridge.load(gpa, targets, outputs, routes)` joins them with pacer's
29
+ ; `'PACT'` list, and `Bridge.encode` writes the frame's `'PACW'` bytes.
30
+ (plugin :name animader
31
+
32
+ ; ---- value kinds ----
33
+
34
+ (value-kind :name output-arity
35
+ :description "Value lanes an output carries: 1..4, pacer's Entry ncomp range."
36
+ :underlying number
37
+ :numeric (numeric-bounds :min 1 :max 4 :integer true)
38
+ :unit (unit-shape :reject true))
39
+
40
+ ; A host registry index. Pacer declares the same concept by the same name
41
+ ; (`registry-index`, `pacer/schema/pacer.sjon`): a bare name two preloaded
42
+ ; plugins claim is `ambiguous_element_kind` in every aggregate that holds
43
+ ; both, while this manifest is preloaded on its own (machine + bridge, no
44
+ ; pacer), so the kind must stay here under a name no loaded sibling declares.
45
+ ; The reference stays bare on purpose: a qualified kind reference consults
46
+ ; only the FIRST plugin bearing that namespace (`SJON/src/Schema.zig`,
47
+ ; `lookupGeneric`), and the three animader manifests share the plugin name
48
+ ; `animader`, so `animader/bridge-registry-index` would resolve against
49
+ ; machine.sjon, which declares no such kind. Ruled 2026-10-06, the eighth
50
+ ; ruling (expansible-player `docs/README.md`).
51
+ (value-kind :name bridge-registry-index
52
+ :description "Host registry index: 0 pngine uniforms, 1 audio params, 2 pacer control pins. The wire carries it as one u8; the host's own count is checked by Bridge.load, not here."
53
+ :underlying number
54
+ :numeric (numeric-bounds :min 0 :max 255 :integer true)
55
+ :unit (unit-shape :reject true))
56
+
57
+ (value-kind :name output-name
58
+ :description "Reference to an (output :name ...) declared in the same document."
59
+ :underlying symbol
60
+ :cross-ref (cross-ref :target output))
61
+
62
+ ; ---- the bridge forms ----
63
+
64
+ (form :name output
65
+ :description "A named numeric value the machine computes; required for every value the machine exposes."
66
+ (key :name name :type symbol
67
+ :description "Output name; the join key when no route exists.")
68
+ (key :name arity :type output-arity
69
+ :description "Number of value lanes this output carries."))
70
+
71
+ (form :name route
72
+ :description "Optional redirect: the output joins :target in :registry instead of by its own name. At most one route per output (route_duplicate)."
73
+ (key :name output :type output-name
74
+ :description "The output this route redirects.")
75
+ (key :name target :type string
76
+ :description "Host target name in the registry join list.")
77
+ (key :name registry :type bridge-registry-index :optional true :default 0
78
+ :description "Host registry index the target lives in; defaults to 0, the visual bus."))
79
+ )