@githolon/dsl 0.102.1 → 0.102.3

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.
package/src/usd_layers.ts CHANGED
@@ -83,6 +83,11 @@ export const NOMOS_USD_LAYERED_PACKAGE_FORMAT = "nomos.usd-layered-package.v1";
83
83
  /** The self-contained ledger/runtime stage: native law plus indexed executable plan assets. */
84
84
  export const NOMOS_USD_PLAN_PACKAGE_FORMAT = "nomos.openusd-plan-package.v2";
85
85
 
86
+ /** Append generated lines without turning a large law into function arguments. */
87
+ function appendLines(target: string[], lines: readonly string[]): void {
88
+ for (const line of lines) target.push(line);
89
+ }
90
+
86
91
  // ── small codecs ───────────────────────────────────────────────────────────────────
87
92
 
88
93
  /** Escape a string for a double-quoted usda string literal. */
@@ -201,7 +206,8 @@ export function nativeValueLines(name: string, value: unknown, indent: string):
201
206
  const position = `i${String(index).padStart(6, "0")}`;
202
207
  const identity = key === undefined ? position : `${position}:k${keyHex(key)}`;
203
208
  if (child !== null && typeof child === "object") {
204
- lines.push("", ...emitContainer(identity.replace(/:/g, "_"), child, `${at} `));
209
+ lines.push("");
210
+ appendLines(lines, emitContainer(identity.replace(/:/g, "_"), child, `${at} `));
205
211
  } else {
206
212
  lines.push(scalarLine(child, identity, `${at} `));
207
213
  }
@@ -210,11 +216,9 @@ export function nativeValueLines(name: string, value: unknown, indent: string):
210
216
  return lines;
211
217
  };
212
218
  const rootName = `__nms_${primName(name)}_${hash}`;
213
- return [
214
- `${indent}custom string nomos:value:${name} = ${usdaString(hash)}`,
215
- "",
216
- ...emitContainer(rootName, value, indent),
217
- ];
219
+ const lines = [`${indent}custom string nomos:value:${name} = ${usdaString(hash)}`, ""];
220
+ appendLines(lines, emitContainer(rootName, value, indent));
221
+ return lines;
218
222
  }
219
223
 
220
224
  /** Field→driver map with keys sorted (the canonical schema shape `manifest.ts` emits). */
@@ -243,7 +247,11 @@ function domainLayerAttrLines(domain: string, layer: UsdLayer, indent: string):
243
247
  ["eraCertGate", layer.nomosEraCertGate], ["valueObjects", layer.nomosValueObjects],
244
248
  ["contracts", layer.nomosContracts], ["foreignRefs", layer.nomosForeignRefs], ["flowGate", layer.nomosFlowGate],
245
249
  ];
246
- for (const [name, value] of values) if (value !== undefined) attrs.push("", ...nativeValueLines(name, value, indent));
250
+ for (const [name, value] of values) {
251
+ if (value === undefined) continue;
252
+ attrs.push("");
253
+ appendLines(attrs, nativeValueLines(name, value, indent));
254
+ }
247
255
  return attrs;
248
256
  }
249
257
 
@@ -379,7 +387,7 @@ export function usdaLayerText(
379
387
  for (const [field, driver] of Object.entries(prim.schema)) {
380
388
  body.push(`${ind3}custom string nomos:driver:${fieldToken(field)} = ${usdaString(driverToken(driver))}`);
381
389
  }
382
- body.push(...relationLines(domainScope, aggById.get(prim.type), ind3));
390
+ appendLines(body, relationLines(domainScope, aggById.get(prim.type), ind3));
383
391
  } else {
384
392
  body.push(
385
393
  `${ind3}custom string nomos:kind = "directive"`,
@@ -392,13 +400,16 @@ export function usdaLayerText(
392
400
  body.push(`${ind3}custom string[] nomos:reads = ${usdaStringArray(prim.reads)}`);
393
401
  }
394
402
  if (prim.emits !== undefined) {
395
- body.push("", ...nativeValueLines("emits", prim.emits, ind3));
403
+ body.push("");
404
+ appendLines(body, nativeValueLines("emits", prim.emits, ind3));
396
405
  }
397
406
  if (prim.secondaryOutputs !== undefined) {
398
- body.push("", ...nativeValueLines("secondaryOutputs", prim.secondaryOutputs, ind3));
407
+ body.push("");
408
+ appendLines(body, nativeValueLines("secondaryOutputs", prim.secondaryOutputs, ind3));
399
409
  }
400
410
  if (prim.payloadJsonSchema !== undefined) {
401
- body.push("", ...nativeValueLines("payloadJsonSchema", prim.payloadJsonSchema, ind3));
411
+ body.push("");
412
+ appendLines(body, nativeValueLines("payloadJsonSchema", prim.payloadJsonSchema, ind3));
402
413
  }
403
414
  }
404
415
  body.push(`${ind2}}`, ``);
@@ -424,7 +435,9 @@ export function usdaLayerText(
424
435
  `${ind3}custom string nomos:id = ${usdaString(d.id)}`,
425
436
  `${ind3}custom string nomos:of = ${usdaString(d.of)}`,
426
437
  ``,
427
- ...nativeValueLines("returns", d.returns, ind3),
438
+ );
439
+ appendLines(body, nativeValueLines("returns", d.returns, ind3));
440
+ body.push(
428
441
  `${ind2}}`,
429
442
  ``,
430
443
  );
@@ -439,7 +452,9 @@ export function usdaLayerText(
439
452
  `${ind3}custom string nomos:refField = ${usdaString(c.refField)}`,
440
453
  `${ind3}custom string nomos:readsFrom = ${usdaString(c.reads)}`,
441
454
  ``,
442
- ...nativeValueLines("returns", c.returns, ind3),
455
+ );
456
+ appendLines(body, nativeValueLines("returns", c.returns, ind3));
457
+ body.push(
443
458
  `${ind2}}`,
444
459
  ``,
445
460
  );
@@ -447,7 +462,7 @@ export function usdaLayerText(
447
462
  // Drop the trailing blank line inside the scope.
448
463
  if (body[body.length - 1] === "") body.pop();
449
464
 
450
- return [
465
+ const lines = [
451
466
  `#usda 1.0`,
452
467
  `(`,
453
468
  ` customLayerData = {`,
@@ -461,14 +476,17 @@ export function usdaLayerText(
461
476
  `{`,
462
477
  ` def Scope ${usdaString(primName(domain))}`,
463
478
  ` {`,
464
- // Stable ids + holon-owned manifests: native layer-level law values.
465
- ...domainLayerAttrLines(domain, layer, " "),
466
- ``,
467
- ...body,
479
+ ];
480
+ // Stable ids + holon-owned manifests: native layer-level law values.
481
+ appendLines(lines, domainLayerAttrLines(domain, layer, " "));
482
+ lines.push(``);
483
+ appendLines(lines, body);
484
+ lines.push(
468
485
  ` }`,
469
486
  `}`,
470
487
  ``,
471
- ].join("\n");
488
+ );
489
+ return lines.join("\n");
472
490
  }
473
491
 
474
492
  /**
@@ -482,26 +500,18 @@ export function layeredRootUsda(
482
500
  composed?: UsdDocument,
483
501
  ): string {
484
502
  const strongestFirst = [...sublayerRelPathsWeakToStrong].reverse();
485
- const composedDomainOpinions =
486
- composed === undefined || composed.layers.length === 0
487
- ? []
488
- : [
489
- ``,
490
- `over "Nomos"`,
491
- `{`,
492
- ...composed.layers.flatMap((layer) => {
493
- const domain = layer.path.slice(layer.path.lastIndexOf("/") + 1);
494
- return [
495
- ` over ${usdaString(primName(domain))}`,
496
- ` {`,
497
- ...domainLayerAttrLines(domain, layer, " "),
498
- ` }`,
499
- ];
500
- }),
501
- `}`,
502
- ``,
503
- ];
504
- return [
503
+ const composedDomainOpinions: string[] = [];
504
+ if (composed !== undefined && composed.layers.length > 0) {
505
+ composedDomainOpinions.push(``, `over "Nomos"`, `{`);
506
+ for (const layer of composed.layers) {
507
+ const domain = layer.path.slice(layer.path.lastIndexOf("/") + 1);
508
+ composedDomainOpinions.push(` over ${usdaString(primName(domain))}`, ` {`);
509
+ appendLines(composedDomainOpinions, domainLayerAttrLines(domain, layer, " "));
510
+ composedDomainOpinions.push(` }`);
511
+ }
512
+ composedDomainOpinions.push(`}`, ``);
513
+ }
514
+ const lines = [
505
515
  `#usda 1.0`,
506
516
  `(`,
507
517
  ` doc = """Nomos layered domain package. subLayers are STRONGEST-FIRST (USD layer-stack`,
@@ -512,14 +522,17 @@ export function layeredRootUsda(
512
522
  ` string "nomos:format" = ${usdaString(NOMOS_USD_LAYERED_PACKAGE_FORMAT)}`,
513
523
  ` }`,
514
524
  ` subLayers = [`,
515
- ...strongestFirst.map(
516
- (p, i) => ` @${p}@${i < strongestFirst.length - 1 ? "," : ""}`,
517
- ),
525
+ ];
526
+ strongestFirst.forEach((p, index) => {
527
+ lines.push(` @${p}@${index < strongestFirst.length - 1 ? "," : ""}`);
528
+ });
529
+ lines.push(
518
530
  ` ]`,
519
531
  `)`,
520
- ...composedDomainOpinions,
521
- ``,
522
- ].join("\n");
532
+ );
533
+ appendLines(lines, composedDomainOpinions);
534
+ lines.push(``);
535
+ return lines.join("\n");
523
536
  }
524
537
 
525
538
  export interface UsdPlanAsset {
@@ -579,7 +592,8 @@ export function nativePlanPackageUsda(
579
592
  if (opened && balance === 0) { end = index; break; }
580
593
  }
581
594
  if (end < 0) throw new Error(`usd-layers: native domain '${domain}' has unbalanced scopes`);
582
- domainBlocks.push(...lines.slice(start, end + 1), "");
595
+ appendLines(domainBlocks, lines.slice(start, end + 1));
596
+ domainBlocks.push("");
583
597
  }
584
598
  if (domainBlocks[domainBlocks.length - 1] === "") domainBlocks.pop();
585
599
 
@@ -617,7 +631,7 @@ export function nativePlanPackageUsda(
617
631
  if (runtime[runtime.length - 1] === "") runtime.pop();
618
632
  runtime.push(` }`, `}`);
619
633
 
620
- return [
634
+ const lines = [
621
635
  `#usda 1.0`,
622
636
  `(`,
623
637
  ` customLayerData = {`,
@@ -627,12 +641,15 @@ export function nativePlanPackageUsda(
627
641
  ``,
628
642
  `def Scope "Nomos"`,
629
643
  `{`,
630
- ...domainBlocks,
644
+ ];
645
+ appendLines(lines, domainBlocks);
646
+ lines.push(
631
647
  `}`,
632
648
  ``,
633
- ...runtime,
634
- ``,
635
- ].join("\n");
649
+ );
650
+ appendLines(lines, runtime);
651
+ lines.push(``);
652
+ return lines.join("\n");
636
653
  }
637
654
 
638
655
  // ── the ordered opinion-map fold (flatten) ───────────────────────────────────────────
@@ -166,8 +166,8 @@ export function workspaceSharing(options: WorkspaceSharingOptions): WorkspaceSha
166
166
  businessBirthInternal: true as const,
167
167
  };
168
168
  const b64 = z.string().regex(/^[A-Za-z0-9+/]+={0,2}$/, "expected base64");
169
- const redeem = nomosImplementationDetail(
170
- directive(redeemId)
169
+ const redeem = nomosImplementationDetail({
170
+ ...directive(redeemId)
171
171
  .mutates(options.orders)
172
172
  .payload(z.object({
173
173
  orderId: z.string().min(1),
@@ -199,7 +199,9 @@ export function workspaceSharing(options: WorkspaceSharingOptions): WorkspaceSha
199
199
  })
200
200
  .alsoEnsures(RelationTuple)
201
201
  .alsoEnsures(NomosInvitationClaim),
202
- );
202
+ // Possession proof is verified by NomosInvitationGate and intentionally never persisted.
203
+ nomosInvariantConsumedPayloadFields: ["invitationSignature"] as const,
204
+ });
203
205
  const gate = workspaceInvariant(`NomosInvitationGate:${options.orders.id}`)
204
206
  .on(redeemId)
205
207
  .reads(({ intent }) => [