@altopelago/aeon-cli 0.11.0 → 0.12.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.
@@ -14,6 +14,10 @@ The CLI MUST support these commands:
14
14
  - `aeon inspect <file> --json --annotations`
15
15
  - `aeon inspect <file> --json --annotations-only`
16
16
  - `aeon inspect <file> --json --annotations-only --sort-annotations`
17
+ - `aeon inspect <file> --telex`
18
+ - `aeon inspect <file> --telex --include-headers`
19
+ - `aeon telex decode <file>`
20
+ - `aeon telex canonicalize <file>`
17
21
  - `aeon finalize <file>`
18
22
  - `aeon finalize <file> --json`
19
23
  - `aeon finalize <file> --map`
@@ -67,6 +71,9 @@ The CLI MUST NOT (except as explicitly required by `aeon finalize`):
67
71
 
68
72
  The CLI is an inspection/validation tool that only exposes events + errors.
69
73
 
74
+ Telex export is body-only by default. `--include-headers` selects the explicit
75
+ `aeon.document.v1` header plane; it does not turn header records into body paths.
76
+
70
77
  ## 5) `aeon check <file>` (human)
71
78
 
72
79
  ### 5.1 Purpose
package/README.md CHANGED
@@ -12,7 +12,7 @@ pnpm add -D @altopelago/aeon-cli
12
12
  Or run a pinned release directly:
13
13
 
14
14
  ```bash
15
- npx @altopelago/aeon-cli@0.11.0 check ./document.aeon
15
+ npx @altopelago/aeon-cli@0.12.1 check ./document.aeon
16
16
  ```
17
17
 
18
18
  ## Quick Start
@@ -20,6 +20,9 @@ npx @altopelago/aeon-cli@0.11.0 check ./document.aeon
20
20
  ```bash
21
21
  aeon check ./document.aeon
22
22
  aeon inspect ./document.aeon --json
23
+ aeon inspect ./document.aeon --telex
24
+ aeon telex decode ./stream.telex.aes
25
+ aeon telex canonicalize ./stream.telex.aes
23
26
  aeon finalize ./document.aeon --json
24
27
  aeon fmt ./document.aeon --write
25
28
  ```
@@ -31,6 +34,8 @@ aeon fmt ./document.aeon --write
31
34
  - `aeon doctor` - check environment and contract registry wiring
32
35
  - `aeon fmt [file]` - format AEON source, writing to stdout unless `--write` is used
33
36
  - `aeon inspect <file>` - inspect Assignment Events, diagnostics, and optional annotations
37
+ - `aeon inspect <file> --telex` - export body events as Telex (`--include-headers` is explicit)
38
+ - `aeon telex decode|canonicalize <file>` - import or canonicalize Telex
34
39
  - `aeon finalize <file>` - materialize AEON into JSON, map, header, or full views
35
40
  - `aeon bind <file>` - run the typed runtime binding pipeline with a schema
36
41
  - `aeon integrity validate|verify|sign <file>` - work with integrity envelopes
package/dist/main.d.ts CHANGED
@@ -8,6 +8,9 @@
8
8
  * - aeon doctor Check environment and contract wiring
9
9
  * - aeon fmt [file] Format AEON document (stdout by default)
10
10
  * - aeon inspect <file> Inspect AEON document (human-readable)
11
+ * - aeon telex decode <file> Decode and validate Telex
12
+ * - aeon telex canonicalize <file> Canonicalize Telex
13
+ * - aeon telex materialize <file> Materialize complete Telex as JSON
11
14
  * - aeon finalize <file> Finalize AEON document to JSON
12
15
  * - aeon bind <file> Run typed runtime binding with schema JSON
13
16
  * - aeon integrity validate <file> Validate integrity envelope
@@ -16,6 +19,9 @@
16
19
  *
17
20
  * Flags:
18
21
  * - --json Output as JSON (inspect/finalize/integrity)
22
+ * - --portable-aes Emit the portable flat AES projection (inspect JSON only)
23
+ * - --source-provenance Bind portable origin/span to the exact inspected UTF-8 source
24
+ * - --telex Export the portable AES stream as Telex (inspect only)
19
25
  * - --contract-registry Trusted contract registry JSON path (doctor/bind)
20
26
  * - --write Write formatted output back to file (fmt only)
21
27
  * - --annotations Include annotation stream records in inspect/bind output
@@ -28,9 +34,13 @@
28
34
  * - --recovery Enable recovery mode (partial results with errors)
29
35
  * - --max-input-bytes Maximum UTF-8 input size in bytes
30
36
  * - --max-attribute-depth Maximum attribute selector depth
31
- * - --max-separator-depth Maximum separator-spec depth
37
+ * - --max-clarifier-values Maximum clarifier values per datatype descriptor
38
+ * - --max-separator-depth Deprecated alias for --max-clarifier-values
32
39
  * - --max-generic-depth Maximum nested generic type depth
33
- * - --max-nesting-depth Maximum container nesting depth
40
+ * - --max-generic-arguments Maximum generic arguments per datatype descriptor
41
+ * - --max-datatype-components Maximum components in one recursive datatype
42
+ * - --max-value-nesting-depth Maximum logical container nesting depth
43
+ * - --max-nesting-depth Deprecated alias for --max-value-nesting-depth
34
44
  * - --max-materialized-weight Maximum cumulative clone materialization weight
35
45
  * - --max-reference-depth Maximum clone resolution depth
36
46
  * - --schema Schema JSON path (bind only)
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG"}
package/dist/main.js CHANGED
@@ -8,6 +8,9 @@
8
8
  * - aeon doctor Check environment and contract wiring
9
9
  * - aeon fmt [file] Format AEON document (stdout by default)
10
10
  * - aeon inspect <file> Inspect AEON document (human-readable)
11
+ * - aeon telex decode <file> Decode and validate Telex
12
+ * - aeon telex canonicalize <file> Canonicalize Telex
13
+ * - aeon telex materialize <file> Materialize complete Telex as JSON
11
14
  * - aeon finalize <file> Finalize AEON document to JSON
12
15
  * - aeon bind <file> Run typed runtime binding with schema JSON
13
16
  * - aeon integrity validate <file> Validate integrity envelope
@@ -16,6 +19,9 @@
16
19
  *
17
20
  * Flags:
18
21
  * - --json Output as JSON (inspect/finalize/integrity)
22
+ * - --portable-aes Emit the portable flat AES projection (inspect JSON only)
23
+ * - --source-provenance Bind portable origin/span to the exact inspected UTF-8 source
24
+ * - --telex Export the portable AES stream as Telex (inspect only)
19
25
  * - --contract-registry Trusted contract registry JSON path (doctor/bind)
20
26
  * - --write Write formatted output back to file (fmt only)
21
27
  * - --annotations Include annotation stream records in inspect/bind output
@@ -28,9 +34,13 @@
28
34
  * - --recovery Enable recovery mode (partial results with errors)
29
35
  * - --max-input-bytes Maximum UTF-8 input size in bytes
30
36
  * - --max-attribute-depth Maximum attribute selector depth
31
- * - --max-separator-depth Maximum separator-spec depth
37
+ * - --max-clarifier-values Maximum clarifier values per datatype descriptor
38
+ * - --max-separator-depth Deprecated alias for --max-clarifier-values
32
39
  * - --max-generic-depth Maximum nested generic type depth
33
- * - --max-nesting-depth Maximum container nesting depth
40
+ * - --max-generic-arguments Maximum generic arguments per datatype descriptor
41
+ * - --max-datatype-components Maximum components in one recursive datatype
42
+ * - --max-value-nesting-depth Maximum logical container nesting depth
43
+ * - --max-nesting-depth Deprecated alias for --max-value-nesting-depth
34
44
  * - --max-materialized-weight Maximum cumulative clone materialization weight
35
45
  * - --max-reference-depth Maximum clone resolution depth
36
46
  * - --schema Schema JSON path (bind only)
@@ -54,8 +64,9 @@ import * as path from 'node:path';
54
64
  import { fileURLToPath } from 'node:url';
55
65
  import { createHash } from 'node:crypto';
56
66
  import { canonicalize } from '@altopelago/aeon-canonical';
57
- import { compile, VERSION, formatPath } from '@altopelago/aeon-core';
58
- import { finalizeJson, finalizeMap } from '@altopelago/aeon-finalize';
67
+ import { adaptTypeScriptAssignmentEventsToPortableAes, aeonCompileLimits, compile, exportTelex, finalizationLimits, loadAeonicLimits, telexLimits, VERSION, formatPath } from '@altopelago/aeon-core';
68
+ import { canonicalizeTelex, parseTelex, validateTelex } from '@altopelago/aeon-aes';
69
+ import { finalizeJson, finalizeMap, finalizePortableJson } from '@altopelago/aeon-finalize';
59
70
  import { buildCanonicalReceipt, computeCanonicalHash, computeByteHash, signStringPayload, validateEnvelopeEvents, verifyStringPayloadSignature, } from '@altopelago/aeon-integrity';
60
71
  import { tokenize } from '@altopelago/aeon-lexer';
61
72
  import { parse } from '@altopelago/aeon-parser';
@@ -96,6 +107,9 @@ switch (command) {
96
107
  case 'inspect':
97
108
  inspect(args.slice(1));
98
109
  break;
110
+ case 'telex':
111
+ telex(args.slice(1));
112
+ break;
99
113
  case 'finalize':
100
114
  finalize(args.slice(1));
101
115
  break;
@@ -134,6 +148,9 @@ Commands:
134
148
  doctor Check environment and contract wiring
135
149
  fmt [file] Format AEON document (stdout by default)
136
150
  inspect <file> Inspect AEON document
151
+ telex decode <file> Decode and validate Telex as JSON
152
+ telex canonicalize <file> Canonicalize a Telex stream
153
+ telex materialize <file> Materialize complete Telex as JSON
137
154
  finalize <file> Finalize AEON document to JSON
138
155
  bind <file> Run typed runtime binding with schema JSON
139
156
  integrity validate <file> Validate integrity envelope
@@ -144,6 +161,10 @@ Options:
144
161
  --write Write formatted output back to file (fmt only)
145
162
  --contract-registry Trusted contract registry JSON path (doctor/bind)
146
163
  --json Output as JSON (inspect/finalize)
164
+ --portable-aes Emit portable flat AES node projection (inspect JSON only)
165
+ --source-provenance Include exact-source origin/span (requires --portable-aes or --telex)
166
+ --telex Emit Telex instead of the inspect report
167
+ --include-headers Include AEON headers in the explicit document projection
147
168
  --annotations Include annotation stream records in inspect/bind output
148
169
  --annotations-only Output only annotation stream records in inspect output
149
170
  --sort-annotations Sort annotation records deterministically before output (inspect/bind)
@@ -154,9 +175,13 @@ Options:
154
175
  --recovery Enable recovery mode (partial results)
155
176
  --max-input-bytes Maximum UTF-8 input size in bytes
156
177
  --max-attribute-depth Maximum attribute selector depth
157
- --max-separator-depth Maximum separator-spec depth
178
+ --max-clarifier-values Maximum clarifier values per datatype descriptor
179
+ --max-separator-depth Deprecated alias for --max-clarifier-values
158
180
  --max-generic-depth Maximum nested generic type depth
159
- --max-nesting-depth Maximum container nesting depth
181
+ --max-generic-arguments Maximum generic arguments per datatype descriptor
182
+ --max-datatype-components Maximum components in one recursive datatype
183
+ --max-value-nesting-depth Maximum logical container nesting depth
184
+ --max-nesting-depth Deprecated alias for --max-value-nesting-depth
160
185
  --schema Schema JSON path (bind only)
161
186
  --profile Profile id (bind only)
162
187
  --contract-registry Trusted contract registry JSON path (bind only)
@@ -183,6 +208,10 @@ Examples:
183
208
  aeon fmt config.aeon --write
184
209
  aeon inspect config.aeon
185
210
  aeon inspect config.aeon --json
211
+ aeon inspect config.aeon --telex
212
+ aeon telex decode stream.telex.aes
213
+ aeon telex canonicalize stream.telex.aes
214
+ aeon telex materialize stream.telex.aes --scope full
186
215
  aeon inspect config.aeon --json --annotations
187
216
  aeon inspect config.aeon --json --annotations-only
188
217
  aeon inspect config.aeon --json --annotations-only --sort-annotations
@@ -331,14 +360,98 @@ function fmt(args) {
331
360
  }
332
361
  process.stdout.write(formatted);
333
362
  }
363
+ /** Decode/validate or canonicalize an existing Telex stream. */
364
+ function telex(args) {
365
+ const action = args[0];
366
+ const file = args[1];
367
+ const usage = 'Usage: aeon telex <decode|canonicalize|materialize> <file> [--limits-file <path>] [--scope <payload|header|full>] [--strict|--transport] [--max-materialized-weight <n>] [--max-reference-depth <n>]';
368
+ if ((action !== 'decode' && action !== 'canonicalize' && action !== 'materialize') || !file || file.startsWith('--')) {
369
+ console.error(usage);
370
+ process.exit(2);
371
+ }
372
+ const mode = resolveFinalizeMode(args);
373
+ const scope = resolveFinalizeScope(args);
374
+ const maxMaterializedWeight = resolveDepthOption(args, '--max-materialized-weight');
375
+ const maxReferenceDepth = resolveDepthOption(args, '--max-reference-depth');
376
+ const limitsFile = getFlagValue(args, '--limits-file');
377
+ if (mode === null || scope === null || maxMaterializedWeight === null || maxReferenceDepth === null) {
378
+ console.error(usage);
379
+ process.exit(2);
380
+ }
381
+ if (args.includes('--limits-file') && !limitsFile) {
382
+ console.error('Error: --limits-file requires a path');
383
+ process.exit(2);
384
+ }
385
+ let selectedTelexLimits;
386
+ let selectedFinalizationLimits;
387
+ if (limitsFile) {
388
+ const loaded = loadAeonicLimits(fs.readFileSync(limitsFile, 'utf8'));
389
+ if (!loaded.limits) {
390
+ for (const error of loaded.errors)
391
+ console.error(`[${error.code}] ${error.path}: ${error.message}`);
392
+ process.exit(2);
393
+ }
394
+ try {
395
+ selectedTelexLimits = telexLimits(loaded.limits);
396
+ selectedFinalizationLimits = finalizationLimits(loaded.limits);
397
+ }
398
+ catch (error) {
399
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
400
+ process.exit(2);
401
+ }
402
+ }
403
+ const input = selectedTelexLimits
404
+ ? readFileWithLimit(file, selectedTelexLimits.maxInputBytes)
405
+ : readFile(file);
406
+ try {
407
+ if (action === 'canonicalize') {
408
+ process.stdout.write(canonicalizeTelex(input, selectedTelexLimits));
409
+ return;
410
+ }
411
+ const parsed = parseTelex(input, selectedTelexLimits);
412
+ const validation = validateTelex(parsed, {
413
+ ...selectedTelexLimits,
414
+ profile: parsed.profile,
415
+ projection: parsed.projection,
416
+ });
417
+ if (action === 'materialize') {
418
+ const finalized = finalizePortableJson(parsed.records, {
419
+ profile: parsed.profile,
420
+ projection: parsed.projection,
421
+ mode,
422
+ scope,
423
+ ...selectedTelexLimits,
424
+ ...selectedFinalizationLimits,
425
+ ...(maxMaterializedWeight !== undefined ? { maxMaterializedWeight } : {}),
426
+ ...(maxReferenceDepth !== undefined ? { maxReferenceDepth } : {}),
427
+ });
428
+ console.log(JSON.stringify(finalized, null, 2));
429
+ if (!validation.valid || (finalized.meta?.errors?.length ?? 0) > 0)
430
+ process.exit(1);
431
+ return;
432
+ }
433
+ console.log(JSON.stringify({ ...parsed, validation }, null, 2));
434
+ if (!validation.valid)
435
+ process.exit(1);
436
+ }
437
+ catch (error) {
438
+ const failure = error;
439
+ console.error(`[${failure.code ?? 'TELEX_SYNTAX_ERROR'}] ${failure.message ?? String(error)}`);
440
+ process.exit(1);
441
+ }
442
+ }
334
443
  /**
335
444
  * aeon inspect <file> [--json] [--recovery] [--annotations] [--annotations-only] [--sort-annotations]
336
445
  * Purpose: human inspection (default) or JSON output
337
446
  */
338
447
  function inspect(args) {
339
- const inspectUsage = 'Usage: aeon inspect <file> [--json] [--recovery] [--strict|--transport] [--annotations] [--annotations-only] [--sort-annotations] [--datatype-policy <reserved_only|allow_custom>] [--max-input-bytes <n>] [--max-events <n>] [--max-attribute-depth <n>] [--max-separator-depth <n>] [--max-generic-depth <n>] [--max-nesting-depth <n>]';
340
- const file = findFileWithValueFlags(args, ['--datatype-policy', '--max-input-bytes', '--max-events', '--max-attribute-depth', '--max-separator-depth', '--max-generic-depth', '--max-nesting-depth']);
448
+ const inspectUsage = 'Usage: aeon inspect <file> [--json|--telex] [--portable-aes] [--source-provenance] [--include-headers] [--recovery] [--strict|--transport] [--annotations] [--annotations-only] [--sort-annotations] [--datatype-policy <reserved_only|allow_custom>] [--limits-file <path>] [--max-input-bytes <n>] [--max-events <n>] [--max-attribute-depth <n>] [--max-clarifier-values <n>] [--max-generic-depth <n>] [--max-generic-arguments <n>] [--max-datatype-components <n>] [--max-value-nesting-depth <n>]';
449
+ const file = findFileWithValueFlags(args, ['--datatype-policy', '--limits-file', '--max-input-bytes', '--max-events', '--max-attribute-depth', '--max-clarifier-values', '--max-separator-depth', '--max-generic-depth', '--max-generic-arguments', '--max-datatype-components', '--max-value-nesting-depth', '--max-nesting-depth']);
341
450
  const jsonOutput = args.includes('--json');
451
+ const telexOutput = args.includes('--telex');
452
+ const includeHeaders = args.includes('--include-headers');
453
+ const portableAes = args.includes('--portable-aes');
454
+ const sourceProvenance = args.includes('--source-provenance');
342
455
  const recovery = args.includes('--recovery');
343
456
  const annotationsOnly = args.includes('--annotations-only');
344
457
  const includeAnnotations = args.includes('--annotations');
@@ -348,14 +461,39 @@ function inspect(args) {
348
461
  const maxInputBytes = resolveMaxInputBytes(args);
349
462
  const maxEvents = resolveDepthOption(args, '--max-events');
350
463
  const maxAttributeDepth = resolveDepthOption(args, '--max-attribute-depth');
464
+ const maxClarifierValues = resolveDepthOption(args, '--max-clarifier-values');
351
465
  const maxSeparatorDepth = resolveDepthOption(args, '--max-separator-depth');
352
466
  const maxGenericDepth = resolveDepthOption(args, '--max-generic-depth');
467
+ const maxGenericArguments = resolveDepthOption(args, '--max-generic-arguments');
468
+ const maxDatatypeComponents = resolveDepthOption(args, '--max-datatype-components');
469
+ const maxValueNestingDepth = resolveDepthOption(args, '--max-value-nesting-depth');
353
470
  const maxNestingDepth = resolveDepthOption(args, '--max-nesting-depth');
471
+ const limitsFile = getFlagValue(args, '--limits-file');
354
472
  if (!file) {
355
473
  console.error('Error: No file specified');
356
474
  console.error(inspectUsage);
357
475
  process.exit(2);
358
476
  }
477
+ if (portableAes && !jsonOutput) {
478
+ console.error('Error: --portable-aes requires --json');
479
+ console.error(inspectUsage);
480
+ process.exit(2);
481
+ }
482
+ if (sourceProvenance && !portableAes && !telexOutput) {
483
+ console.error('Error: --source-provenance requires --portable-aes or --telex');
484
+ console.error(inspectUsage);
485
+ process.exit(2);
486
+ }
487
+ if (telexOutput && (jsonOutput || portableAes || annotationsOnly || includeAnnotations)) {
488
+ console.error('Error: --telex cannot be combined with JSON or annotation output flags');
489
+ console.error(inspectUsage);
490
+ process.exit(2);
491
+ }
492
+ if (includeHeaders && !telexOutput && !(jsonOutput && portableAes)) {
493
+ console.error('Error: --include-headers requires --telex or --json --portable-aes');
494
+ console.error(inspectUsage);
495
+ process.exit(2);
496
+ }
359
497
  if (args.includes('--datatype-policy') && !datatypePolicy) {
360
498
  console.error('Error: Invalid value for --datatype-policy (expected reserved_only or allow_custom)');
361
499
  console.error(inspectUsage);
@@ -378,6 +516,10 @@ function inspect(args) {
378
516
  console.error('Error: Invalid value for --max-attribute-depth (expected a non-negative integer)');
379
517
  process.exit(2);
380
518
  }
519
+ if (maxClarifierValues === null) {
520
+ console.error('Error: Invalid value for --max-clarifier-values (expected a non-negative integer)');
521
+ process.exit(2);
522
+ }
381
523
  if (maxSeparatorDepth === null) {
382
524
  console.error('Error: Invalid value for --max-separator-depth (expected a non-negative integer)');
383
525
  process.exit(2);
@@ -386,12 +528,46 @@ function inspect(args) {
386
528
  console.error('Error: Invalid value for --max-generic-depth (expected a non-negative integer)');
387
529
  process.exit(2);
388
530
  }
531
+ if (maxGenericArguments === null) {
532
+ console.error('Error: Invalid value for --max-generic-arguments (expected a non-negative integer)');
533
+ process.exit(2);
534
+ }
535
+ if (maxDatatypeComponents === null) {
536
+ console.error('Error: Invalid value for --max-datatype-components (expected a non-negative integer)');
537
+ process.exit(2);
538
+ }
539
+ if (maxValueNestingDepth === null) {
540
+ console.error('Error: Invalid value for --max-value-nesting-depth (expected a non-negative integer)');
541
+ process.exit(2);
542
+ }
389
543
  if (maxNestingDepth === null) {
390
544
  console.error('Error: Invalid value for --max-nesting-depth (expected a non-negative integer)');
391
545
  process.exit(2);
392
546
  }
393
- const input = readFileWithLimit(file, maxInputBytes);
547
+ let limitsOptions;
548
+ if (args.includes('--limits-file')) {
549
+ if (!limitsFile) {
550
+ console.error('Error: --limits-file requires a path');
551
+ process.exit(2);
552
+ }
553
+ const loaded = loadAeonicLimits(fs.readFileSync(limitsFile, 'utf8'));
554
+ if (!loaded.limits) {
555
+ for (const error of loaded.errors)
556
+ console.error(`[${error.code}] ${error.path}: ${error.message}`);
557
+ process.exit(2);
558
+ }
559
+ try {
560
+ limitsOptions = aeonCompileLimits(loaded.limits);
561
+ }
562
+ catch (error) {
563
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
564
+ process.exit(2);
565
+ }
566
+ }
567
+ const effectiveInputLimit = maxInputBytes ?? limitsOptions?.maxInputBytes;
568
+ const input = readFileWithLimit(file, effectiveInputLimit);
394
569
  const result = compile(input, {
570
+ ...limitsOptions,
395
571
  recovery,
396
572
  emitAnnotations: includeAnnotations || annotationsOnly,
397
573
  ...(effectiveMode ? { mode: effectiveMode } : {}),
@@ -399,14 +575,34 @@ function inspect(args) {
399
575
  ...(maxInputBytes !== undefined ? { maxInputBytes } : {}),
400
576
  ...(maxEvents !== undefined ? { maxEvents } : {}),
401
577
  ...(maxAttributeDepth !== undefined ? { maxAttributeDepth } : {}),
402
- ...(maxSeparatorDepth !== undefined ? { maxSeparatorDepth } : {}),
578
+ ...(maxClarifierValues !== undefined
579
+ ? { maxClarifierValues }
580
+ : maxSeparatorDepth !== undefined ? { maxSeparatorDepth } : {}),
403
581
  ...(maxGenericDepth !== undefined ? { maxGenericDepth } : {}),
404
- ...(maxNestingDepth !== undefined ? { maxNestingDepth } : {}),
582
+ ...(maxGenericArguments !== undefined ? { maxGenericArguments } : {}),
583
+ ...(maxDatatypeComponents !== undefined ? { maxDatatypeComponents } : {}),
584
+ ...(maxValueNestingDepth !== undefined
585
+ ? { maxValueNestingDepth }
586
+ : maxNestingDepth !== undefined ? { maxNestingDepth } : {}),
405
587
  });
406
588
  const headerInfo = extractHeaderInfo(input);
407
589
  const mode = headerInfo.mode;
408
- if (jsonOutput) {
409
- outputJSON(result, { includeAnnotations, annotationsOnly, sortAnnotations }, headerInfo);
590
+ if (telexOutput && result.errors.length === 0) {
591
+ process.stdout.write(exportTelex(result.events, {
592
+ includeHeaders,
593
+ headerFieldNames: result.header ? [...result.header.fields.keys()] : [],
594
+ ...(sourceProvenance ? { sourceBytes: Buffer.from(input, 'utf8') } : {}),
595
+ }));
596
+ }
597
+ else if (jsonOutput) {
598
+ outputJSON(result, {
599
+ includeAnnotations,
600
+ annotationsOnly,
601
+ sortAnnotations,
602
+ portableAes,
603
+ includeHeaders,
604
+ ...(sourceProvenance ? { sourceBytes: Buffer.from(input, 'utf8') } : {}),
605
+ }, headerInfo);
410
606
  }
411
607
  else {
412
608
  outputMarkdown(file, result, {
@@ -431,8 +627,8 @@ function inspect(args) {
431
627
  * Purpose: finalize AES into JSON output
432
628
  */
433
629
  function finalize(args) {
434
- const finalizeUsage = 'Usage: aeon finalize <file> [--json|--map] [--recovery] [--strict|--transport] [--projected] [--include-path <$.path>] [--scope <payload|header|full>] [--datatype-policy <reserved_only|allow_custom>] [--max-input-bytes <n>] [--max-materialized-weight <n>] [--max-reference-depth <n>]';
435
- const file = findFileWithValueFlags(args, ['--datatype-policy', '--include-path', '--scope', '--max-input-bytes', '--max-materialized-weight', '--max-reference-depth']);
630
+ const finalizeUsage = 'Usage: aeon finalize <file> [--json|--map] [--recovery] [--strict|--transport] [--projected] [--include-path <$.path>] [--scope <payload|header|full>] [--datatype-policy <reserved_only|allow_custom>] [--limits-file <path>] [--max-input-bytes <n>] [--max-materialized-weight <n>] [--max-reference-depth <n>]';
631
+ const file = findFileWithValueFlags(args, ['--datatype-policy', '--include-path', '--scope', '--limits-file', '--max-input-bytes', '--max-materialized-weight', '--max-reference-depth']);
436
632
  const recovery = args.includes('--recovery');
437
633
  const mode = resolveFinalizeMode(args);
438
634
  const effectiveMode = resolveCoreMode(args);
@@ -442,6 +638,7 @@ function finalize(args) {
442
638
  const maxInputBytes = resolveMaxInputBytes(args);
443
639
  const maxMaterializedWeight = resolveDepthOption(args, '--max-materialized-weight');
444
640
  const maxReferenceDepth = resolveDepthOption(args, '--max-reference-depth');
641
+ const limitsFile = getFlagValue(args, '--limits-file');
445
642
  const includePaths = getFlagValues(args, '--include-path');
446
643
  const projected = args.includes('--projected') || includePaths.length > 0;
447
644
  if (!file) {
@@ -475,6 +672,10 @@ function finalize(args) {
475
672
  console.error('Error: Invalid value for --max-reference-depth (expected a non-negative integer)');
476
673
  process.exit(2);
477
674
  }
675
+ if (args.includes('--limits-file') && !limitsFile) {
676
+ console.error('Error: --limits-file requires a path');
677
+ process.exit(2);
678
+ }
478
679
  if (args.includes('--include-path') && includePaths.length === 0) {
479
680
  console.error('Error: Missing value for --include-path <$.path>');
480
681
  console.error(finalizeUsage);
@@ -485,14 +686,35 @@ function finalize(args) {
485
686
  console.error(finalizeUsage);
486
687
  process.exit(2);
487
688
  }
488
- const input = readFileWithLimit(file, maxInputBytes);
689
+ let limitsOptions;
690
+ let finalizeLimitOptions;
691
+ if (limitsFile) {
692
+ const loaded = loadAeonicLimits(fs.readFileSync(limitsFile, 'utf8'));
693
+ if (!loaded.limits) {
694
+ for (const error of loaded.errors)
695
+ console.error(`[${error.code}] ${error.path}: ${error.message}`);
696
+ process.exit(2);
697
+ }
698
+ try {
699
+ limitsOptions = aeonCompileLimits(loaded.limits);
700
+ finalizeLimitOptions = finalizationLimits(loaded.limits);
701
+ }
702
+ catch (error) {
703
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
704
+ process.exit(2);
705
+ }
706
+ }
707
+ const effectiveInputLimit = maxInputBytes ?? limitsOptions?.maxInputBytes;
708
+ const input = readFileWithLimit(file, effectiveInputLimit);
489
709
  const result = compile(input, {
710
+ ...limitsOptions,
490
711
  recovery,
491
712
  ...(effectiveMode ? { mode: effectiveMode } : {}),
492
713
  ...(datatypePolicy ? { datatypePolicy } : {}),
493
714
  ...(maxInputBytes !== undefined ? { maxInputBytes } : {}),
494
715
  });
495
716
  const finalizeOptions = {
717
+ ...finalizeLimitOptions,
496
718
  mode,
497
719
  scope,
498
720
  ...(result.header ? { header: result.header } : {}),
@@ -876,7 +1098,7 @@ function integrityVerify(args) {
876
1098
  diagnostics.errors.push({
877
1099
  level: 'error',
878
1100
  code: 'ENVELOPE_HASH_MISMATCH',
879
- message: 'canonical_hash does not match computed AES hash',
1101
+ message: 'canonical_hash does not match computed legacy AEON canonical hash',
880
1102
  });
881
1103
  }
882
1104
  }
@@ -1206,8 +1428,14 @@ function integritySign(args) {
1206
1428
  /**
1207
1429
  * JSON output (--json flag)
1208
1430
  */
1431
+ function isLegacyVisibleEvent(event) {
1432
+ if (event.sourcePlane !== undefined) {
1433
+ return event.sourcePlane !== 'header' || event.path.segments.length > 2;
1434
+ }
1435
+ return !event.key.startsWith('aeon:');
1436
+ }
1209
1437
  function outputJSON(result, options, headerInfo) {
1210
- const visibleEvents = result.events.filter(e => !e.key.startsWith('aeon:'));
1438
+ const visibleEvents = result.events.filter(isLegacyVisibleEvent);
1211
1439
  const annotations = options.sortAnnotations
1212
1440
  ? sortAnnotationRecords(result.annotations ?? [])
1213
1441
  : (result.annotations ?? []);
@@ -1216,14 +1444,22 @@ function outputJSON(result, options, headerInfo) {
1216
1444
  return;
1217
1445
  }
1218
1446
  const output = {
1219
- events: visibleEvents.map(event => ({
1220
- path: formatPath(event.path),
1221
- key: event.key,
1222
- datatype: event.datatype ?? null,
1223
- span: event.span,
1224
- // Preserve AST-like shape (no coercion/inference)
1225
- value: jsonSafe(event.value),
1226
- })),
1447
+ events: options.portableAes
1448
+ ? [...adaptTypeScriptAssignmentEventsToPortableAes(options.includeHeaders ? result.events : visibleEvents, {
1449
+ includeHeaders: options.includeHeaders,
1450
+ headerFieldNames: result.header ? [...result.header.fields.keys()] : [],
1451
+ ...(options.sourceBytes === undefined ? {} : { sourceBytes: options.sourceBytes }),
1452
+ }).events]
1453
+ : visibleEvents.map(event => ({
1454
+ path: formatPath(event.path),
1455
+ key: event.key,
1456
+ ...(event.structuralId !== undefined ? { structuralId: event.structuralId } : {}),
1457
+ datatype: event.datatype ?? null,
1458
+ span: event.span,
1459
+ // Preserve AST-like shape (no coercion/inference)
1460
+ value: jsonSafe(event.value),
1461
+ ...(event.annotations ? { annotations: jsonSafe(event.annotations) } : {}),
1462
+ })),
1227
1463
  errors: result.errors.map(error => ({
1228
1464
  code: error.code,
1229
1465
  path: getErrorPath(error) ?? '$',
@@ -1234,6 +1470,9 @@ function outputJSON(result, options, headerInfo) {
1234
1470
  message: error.message,
1235
1471
  })),
1236
1472
  };
1473
+ if (options.portableAes && options.includeHeaders) {
1474
+ output.projection = 'aeon.document.v1';
1475
+ }
1237
1476
  if (options.includeAnnotations) {
1238
1477
  output.annotations = annotations;
1239
1478
  }
@@ -1357,7 +1596,8 @@ function finalizeMapOutput(result, options) {
1357
1596
  function entryToJson(entry) {
1358
1597
  return {
1359
1598
  path: entry.path,
1360
- value: entry.value,
1599
+ ...(entry.structuralId !== undefined ? { structuralId: entry.structuralId } : {}),
1600
+ value: jsonSafe(entry.value),
1361
1601
  span: entry.span,
1362
1602
  ...(entry.datatype ? { datatype: entry.datatype } : {}),
1363
1603
  ...(entry.annotations ? { annotations: mapAnnotations(entry.annotations) } : {}),
@@ -1367,8 +1607,10 @@ function mapAnnotations(annotations) {
1367
1607
  const entries = {};
1368
1608
  for (const [key, value] of annotations.entries()) {
1369
1609
  entries[key] = {
1370
- value: value.value,
1610
+ ...(value.structuralId !== undefined ? { structuralId: value.structuralId } : {}),
1611
+ value: jsonSafe(value.value),
1371
1612
  ...(value.datatype ? { datatype: value.datatype } : {}),
1613
+ ...(value.annotations ? { annotations: mapAnnotations(value.annotations) } : {}),
1372
1614
  };
1373
1615
  }
1374
1616
  return entries;
@@ -1786,7 +2028,10 @@ function readSchemaContractAeonFile(file, expectedSchemaId) {
1786
2028
  }
1787
2029
  process.exit(2);
1788
2030
  }
1789
- const finalized = finalizeJson(compiled.events, { mode: 'strict' });
2031
+ const finalized = finalizeJson(compiled.events, {
2032
+ mode: 'strict',
2033
+ ...(compiled.header ? { header: compiled.header } : {}),
2034
+ });
1790
2035
  if ((finalized.meta?.errors?.length ?? 0) > 0) {
1791
2036
  console.error(`Error: Schema contract AEON file failed to finalize: ${file}`);
1792
2037
  for (const error of finalized.meta?.errors ?? []) {
@@ -2512,7 +2757,7 @@ function outputEnvelopeJson(errors, warnings, ok, verification, receipt) {
2512
2757
  console.log(JSON.stringify(payload, null, 2));
2513
2758
  }
2514
2759
  function outputMarkdown(file, result, info) {
2515
- const visibleEvents = result.events.filter(e => !e.key.startsWith('aeon:'));
2760
+ const visibleEvents = result.events.filter(isLegacyVisibleEvent);
2516
2761
  const annotations = info.sortAnnotations
2517
2762
  ? sortAnnotationRecords(result.annotations ?? [])
2518
2763
  : (result.annotations ?? []);
@@ -2671,18 +2916,23 @@ function inferPhaseLabelFromCode(code) {
2671
2916
  case 'UNTERMINATED_BLOCK_COMMENT':
2672
2917
  case 'UNTERMINATED_STRING':
2673
2918
  case 'UNTERMINATED_TRIMTICK':
2919
+ case 'INVALID_STRUCTURAL_IDENTITY':
2674
2920
  return 'Lexical Analysis';
2675
2921
  case 'SYNTAX_ERROR':
2676
2922
  case 'INVALID_DATE':
2677
2923
  case 'INVALID_TIME':
2678
2924
  case 'INVALID_DATETIME':
2679
2925
  case 'INVALID_SEPARATOR_CHAR':
2926
+ case 'CLARIFIER_VALUES_EXCEEDED':
2927
+ case 'GENERIC_ARGUMENTS_EXCEEDED':
2928
+ case 'DATATYPE_COMPONENTS_EXCEEDED':
2680
2929
  case 'SEPARATOR_DEPTH_EXCEEDED':
2681
2930
  case 'GENERIC_DEPTH_EXCEEDED':
2682
2931
  return 'Parsing';
2683
2932
  case 'HEADER_CONFLICT':
2684
2933
  case 'DUPLICATE_KEY':
2685
2934
  case 'DUPLICATE_CANONICAL_PATH':
2935
+ case 'DUPLICATE_STRUCTURAL_IDENTITY':
2686
2936
  case 'DATATYPE_LITERAL_MISMATCH':
2687
2937
  return 'Core Validation';
2688
2938
  case 'MISSING_REFERENCE_TARGET':