@almadar/core 10.28.0 → 10.30.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.
@@ -129,8 +129,11 @@ interface ParsedBinding {
129
129
  * `user` is the authenticated user / agent context (see binding.ts) and is
130
130
  * read-only in guards/effects/ticks — atoms reference `@user.id` and
131
131
  * `@user.role` for ownership / role-based gating.
132
+ * `callsitePayload` is the call-site-captured event payload emitted by the
133
+ * compiler's inline-trait hoisting; the runtime BindingResolver resolves it
134
+ * at the composing effect.
132
135
  */
133
- declare const CORE_BINDINGS: readonly ["entity", "payload", "state", "now", "config", "computed", "trait", "user"];
136
+ declare const CORE_BINDINGS: readonly ["entity", "payload", "state", "now", "config", "computed", "trait", "user", "callsitePayload"];
134
137
  type CoreBinding = (typeof CORE_BINDINGS)[number];
135
138
  /**
136
139
  * Parses a binding reference into its components.
@@ -1,9 +1,10 @@
1
- import { h as FactoryParamValue, c as FactoryConfigTier, b as FactoryConfigParam, F as FactoryCallSite, j as FactorySignature, R as RuleOverlay, r as RuleOverlayEntry, q as PresentationOverlay, s as TraitOverlay } from '../types-DFn3sWpV.js';
2
- export { a as FactoryCallSiteParams, d as FactoryEntitySignature, e as FactoryEventSignature, f as FactoryExposure, g as FactoryPageSignature, i as FactoryProvenance, k as FactorySignatureCatalog, l as FactorySignatureEntityField, m as FactoryTraitSignature, o as JsonSchema, p as JsonSchemaType, J as JsonValue, O as OwnershipOverlayEntry, P as PresentationNavItem, S as SchemaFieldType, t as TraitOverlayEntry, u as TraitOverlayListener } from '../types-DFn3sWpV.js';
3
- import { a as EntityPersistence, E as EntityField } from '../pattern-types-BeQXwgpZ.js';
4
- import { a as TraitReference } from '../trait-DZkS625T.js';
1
+ import { h as FactoryParamValue, c as FactoryConfigTier, b as FactoryConfigParam, F as FactoryCallSite, j as FactorySignature, R as RuleOverlay, p as RuleOverlayEntry, o as PresentationOverlay, T as TraitOverlay } from '../types-yW22YNNt.js';
2
+ export { a as FactoryCallSiteParams, d as FactoryEntitySignature, e as FactoryEventSignature, f as FactoryExposure, g as FactoryPageSignature, i as FactoryProvenance, k as FactorySignatureCatalog, l as FactorySignatureEntityField, m as FactoryTraitSignature, J as JsonSchema, n as JsonSchemaType, O as OwnershipOverlayEntry, P as PresentationNavItem, S as SchemaFieldType, q as TraitOverlayEntry, r as TraitOverlayListener } from '../types-yW22YNNt.js';
3
+ import { a as EntityPersistence, E as EntityField } from '../pattern-types-CLcOXOmW.js';
4
+ import { a as TraitReference } from '../trait-CwWjkU-1.js';
5
+ export { J as JsonValue } from '../json-DOTchoRS.js';
5
6
  import 'zod';
6
- import '../expression-C6X4A8L7.js';
7
+ import '../expression-CB9R3KWk.js';
7
8
 
8
9
  /**
9
10
  * Typed questionnaire surface — shapes the studio renders + answers.
@@ -1,8 +1,8 @@
1
- import { O as OrbitalSchema, M as MakeTraitRefOpts, a as OrbitalDefinition } from '../builders-BN3WLFYM.js';
2
- import { C as CallSiteConfig, b as CallSiteConfigEntry, c as Trait } from '../trait-DZkS625T.js';
3
- import { E as EntityField, a as EntityPersistence } from '../pattern-types-BeQXwgpZ.js';
1
+ import { O as OrbitalSchema, M as MakeTraitRefOpts, a as OrbitalDefinition } from '../builders-C458pIMW.js';
2
+ import { C as CallSiteConfig, b as CallSiteConfigEntry, c as Trait } from '../trait-CwWjkU-1.js';
3
+ import { E as EntityField, a as EntityPersistence } from '../pattern-types-CLcOXOmW.js';
4
4
  import 'zod';
5
- import '../expression-C6X4A8L7.js';
5
+ import '../expression-CB9R3KWk.js';
6
6
 
7
7
  /**
8
8
  * Orbital factory manifest types — shared across all packages.
@@ -148,6 +148,67 @@ declare function rewriteEntityInInlineTrait(trait: Trait, oldName: string, newNa
148
148
  * - generated `mergeExtraTraitWithOverlay` in dispatch.ts
149
149
  */
150
150
  declare function mergeCallSiteConfigOverrides(base: CallSiteConfig, overrides: CallSiteConfig): Record<string, CallSiteConfigEntry>;
151
+ /**
152
+ * Apply `traitOverrides.<T>.name` renames to trait DECLARATIONS only,
153
+ * AFTER the schema has been stamped (V4-W4 stamp-before-rename).
154
+ *
155
+ * A trait rename is a pure display-name change: it renames the declaration
156
+ * (`traits[].name` for inline traits, the ref object's local `name` for
157
+ * reference traits) and nothing else. Every REFERENCE to the trait —
158
+ * `pages[].traits[].ref`, `@trait.<canonical>` tokens in sibling config /
159
+ * stateMachine effect trees — is left carrying its canonical name AND its
160
+ * stamped id (page ref `refId`, the referring trait's `traitEmbedIds`
161
+ * side-map). Readers resolve those references by stable id onto the renamed
162
+ * declaration, so no token/page-ref rewrite is needed (this replaced the
163
+ * deleted `applyTraitRenames`).
164
+ *
165
+ * The keys are canonical names because stamping ran while the declaration
166
+ * still carried its canonical name (the factory no longer renames — see
167
+ * `applyParamsToOrb`), so `trait.name === canonicalKey` at this point.
168
+ *
169
+ * Pure — returns a new schema. Applied per orbital; the same override key
170
+ * renames the matching declaration in every orbital that owns it (matches
171
+ * the former per-orbital `applyParamsToOrb` semantics).
172
+ */
173
+ declare function applyDeclarationTraitRenames(schema: OrbitalSchema, renames: ReadonlyMap<string, string>,
174
+ /**
175
+ * Rename timestamp (ISO string) for the ledger `renames[]` audit row. Threaded
176
+ * from the persistence layer (which owns the clock). The stamp keyed each inline
177
+ * trait's ledger `curName` to its canonical name; without this update the renamed
178
+ * declaration disagrees with `curName` → `ORB_ID_NAME_MISMATCH` on the page ref.
179
+ */
180
+ at: string): OrbitalSchema;
181
+ /** A single entity display rename: `from` (canonical name at stamp) → `to`. */
182
+ interface EntityDeclarationRename {
183
+ readonly from: string;
184
+ readonly to: string;
185
+ }
186
+ /**
187
+ * Apply an entity rename to DECLARATIONS only, AFTER the schema has been
188
+ * stamped (V4-W4 stamp-before-rename). The entity, its `@entity.<from>` body
189
+ * tokens, and every trait/page `linkedEntity` were all emitted CANONICAL by
190
+ * the factory, so stamping keyed `entityRefIds`/`linkedEntityId` by `from`.
191
+ *
192
+ * This renames only the visible declaration surface — `entity.name` and every
193
+ * trait/page `linkedEntity` whose value is `from` — leaving the `@entity.<from>`
194
+ * body tokens and every stamped id untouched. Readers resolve those tokens by
195
+ * `entityRefIds` id and resolve `linkedEntity` by `linkedEntityId`, so the
196
+ * rename lands on the right declaration without any body rewrite (this is what
197
+ * lets the factory stop calling `rebindInlineTraitEntity`). Collection is not
198
+ * renamed here — its effective value was already baked at build time.
199
+ *
200
+ * Pure — returns a new schema. Applied to every orbital whose primary entity
201
+ * is named `from` (mirrors the former per-orbital `applyParamsToOrb` scope for
202
+ * a single-orbital write).
203
+ */
204
+ declare function applyDeclarationEntityRename(schema: OrbitalSchema, rename: EntityDeclarationRename,
205
+ /**
206
+ * Rename timestamp (ISO string) for the ledger `renames[]` audit row. Threaded
207
+ * from the persistence layer (which owns the clock). The stamp keyed the ledger
208
+ * `curName` to the canonical entity name; without this update the renamed
209
+ * declaration disagrees with `curName` → `ORB_ID_NAME_MISMATCH`.
210
+ */
211
+ at: string): OrbitalSchema;
151
212
  /**
152
213
  * The overlay. Resolves the effective entity name + collection, calls
153
214
  * `makeOrbitalWithUses` with the rewritten data, then applies the params'
@@ -171,4 +232,4 @@ declare function applyParamsToOrb(orb: OrbitalSchema, orbitalName: string, _mani
171
232
 
172
233
  declare function applyParamsToWholeOrb(orb: OrbitalSchema, manifests: readonly OrbitalParamsManifest[], params: OrbitalFactoryParams): OrbitalSchema;
173
234
 
174
- export { type OrbitalFactoryParams, type OrbitalParamsManifest, type OrbitalTraitOverride, type ParamFieldDescriptor, type ParamValidationError, type ParamValidationResult, applyParamsToOrb, applyParamsToWholeOrb, extractManifest, mergeCallSiteConfigOverrides, rebindInlineTraitEntity, rewriteEntityInInlineTrait, validateOrbitalFactoryParams };
235
+ export { type EntityDeclarationRename, type OrbitalFactoryParams, type OrbitalParamsManifest, type OrbitalTraitOverride, type ParamFieldDescriptor, type ParamValidationError, type ParamValidationResult, applyDeclarationEntityRename, applyDeclarationTraitRenames, applyParamsToOrb, applyParamsToWholeOrb, extractManifest, mergeCallSiteConfigOverrides, rebindInlineTraitEntity, rewriteEntityInInlineTrait, validateOrbitalFactoryParams };
@@ -1,6 +1,90 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  // src/types/orbital.ts
4
+ var ID_PREFIXES = {
5
+ orbital: "orb_",
6
+ entity: "ent_",
7
+ trait: "trt_",
8
+ event: "evt_",
9
+ page: "pag_",
10
+ service: "svc_",
11
+ theme: "thm_",
12
+ palette: "pal_"
13
+ };
14
+ function brand(value) {
15
+ return value;
16
+ }
17
+ function makeIdKind(kind) {
18
+ const prefix = ID_PREFIXES[kind];
19
+ const is = (value) => value.startsWith(prefix) && value.length > prefix.length;
20
+ const as = (value) => {
21
+ if (!is(value)) {
22
+ throw new Error(
23
+ `Expected ${kind} id (prefix "${prefix}"), got: ${JSON.stringify(value)}`
24
+ );
25
+ }
26
+ return brand(value);
27
+ };
28
+ return { prefix, is, as };
29
+ }
30
+ var orbitalKind = makeIdKind("orbital");
31
+ var entityKind = makeIdKind("entity");
32
+ var traitKind = makeIdKind("trait");
33
+ var eventKind = makeIdKind("event");
34
+ var pageKind = makeIdKind("page");
35
+ var serviceKind = makeIdKind("service");
36
+ var themeKind = makeIdKind("theme");
37
+ var paletteKind = makeIdKind("palette");
38
+ var isOrbitalId = orbitalKind.is;
39
+ var isEntityId = entityKind.is;
40
+ var isTraitId = traitKind.is;
41
+ var isEventId = eventKind.is;
42
+ var isPageId = pageKind.is;
43
+ var isServiceId = serviceKind.is;
44
+ var isThemeId = themeKind.is;
45
+ var isPaletteEntryId = paletteKind.is;
46
+ function ledgerRename(ledger, id, to, at) {
47
+ const entry = ledger.entries[id];
48
+ if (entry === void 0) return ledger;
49
+ const updated = {
50
+ ...entry,
51
+ curName: to,
52
+ renames: [...entry.renames, { from: entry.curName, to, at }]
53
+ };
54
+ return { ...ledger, entries: { ...ledger.entries, [id]: updated } };
55
+ }
56
+ var OrbitalIdSchema = z.string().refine(isOrbitalId, { message: `Expected an orbital id (prefix "${ID_PREFIXES.orbital}")` });
57
+ var EntityIdSchema = z.string().refine(isEntityId, { message: `Expected an entity id (prefix "${ID_PREFIXES.entity}")` });
58
+ var TraitIdSchema = z.string().refine(isTraitId, { message: `Expected a trait id (prefix "${ID_PREFIXES.trait}")` });
59
+ var EventIdSchema = z.string().refine(isEventId, { message: `Expected an event id (prefix "${ID_PREFIXES.event}")` });
60
+ var PageIdSchema = z.string().refine(isPageId, { message: `Expected a page id (prefix "${ID_PREFIXES.page}")` });
61
+ z.string().refine(isServiceId, { message: `Expected a service id (prefix "${ID_PREFIXES.service}")` });
62
+ z.string().refine(isThemeId, { message: `Expected a theme id (prefix "${ID_PREFIXES.theme}")` });
63
+ z.string().refine(isPaletteEntryId, { message: `Expected a palette-entry id (prefix "${ID_PREFIXES.palette}")` });
64
+ var LedgerKindSchema = z.enum([
65
+ "orbital",
66
+ "entity",
67
+ "trait",
68
+ "event",
69
+ "page",
70
+ "service",
71
+ "theme"
72
+ ]);
73
+ var LedgerEntrySchema = z.object({
74
+ id: z.string(),
75
+ kind: LedgerKindSchema,
76
+ bakedName: z.string(),
77
+ curName: z.string(),
78
+ renames: z.array(
79
+ z.object({ from: z.string(), to: z.string(), at: z.string() })
80
+ ),
81
+ owner: z.enum(["std", "io", "workspace"]),
82
+ parent: TraitIdSchema.optional()
83
+ });
84
+ var IdentityLedgerSchema = z.object({
85
+ schemaVersion: z.literal(1),
86
+ entries: z.record(LedgerEntrySchema)
87
+ });
4
88
  z.enum([
5
89
  "string",
6
90
  "number",
@@ -25,6 +109,7 @@ var RelationCardinalitySchema = z.enum([
25
109
  ]);
26
110
  var RelationConfigSchema = z.object({
27
111
  entity: z.string().min(1, "Target entity is required"),
112
+ entityId: EntityIdSchema.optional(),
28
113
  field: z.string().optional(),
29
114
  cardinality: RelationCardinalitySchema.optional(),
30
115
  onDelete: z.enum(["cascade", "nullify", "restrict"]).optional(),
@@ -35,6 +120,7 @@ var RelationConfigSchema = z.object({
35
120
  }).transform((data) => {
36
121
  const normalized = {
37
122
  entity: data.entity || data.target || "",
123
+ entityId: data.entityId,
38
124
  cardinality: data.cardinality || data.type,
39
125
  field: data.field,
40
126
  onDelete: data.onDelete
@@ -324,10 +410,12 @@ var StateSchema = z.object({
324
410
  var PayloadFieldSchema = z.object({
325
411
  name: z.string().min(1),
326
412
  type: z.string().min(1),
327
- required: z.boolean().optional()
413
+ required: z.boolean().optional(),
414
+ properties: z.lazy(() => z.array(PayloadFieldSchema)).optional()
328
415
  });
329
416
  var EventSchema = z.object({
330
417
  key: z.string().min(1, "Event key is required"),
418
+ id: EventIdSchema.optional(),
331
419
  name: z.string().min(1, "Event name is required"),
332
420
  description: z.string().optional(),
333
421
  synonyms: z.string().optional(),
@@ -345,6 +433,7 @@ var TransitionSchema = z.object({
345
433
  from: z.string().min(1, "Transition source state is required"),
346
434
  to: z.string().min(1, "Transition target state is required"),
347
435
  event: z.string().min(1, "Transition event is required"),
436
+ eventId: EventIdSchema.optional(),
348
437
  guard: ExpressionSchema.nullish(),
349
438
  effects: z.array(EffectSchema).optional(),
350
439
  description: z.string().nullish()
@@ -371,14 +460,25 @@ var TraitConfigSchema = z.record(TraitConfigValueSchema);
371
460
  function isCallSiteConfigDeclaration(entry) {
372
461
  return typeof entry === "object" && entry !== null && !Array.isArray(entry) && "type" in entry && typeof entry.type === "string" && "default" in entry;
373
462
  }
463
+ var ConfigFieldItemsDeclarationSchema = z.lazy(
464
+ () => z.object({
465
+ type: z.string().optional(),
466
+ properties: z.record(TraitEntityFieldSchema).optional(),
467
+ items: ConfigFieldItemsDeclarationSchema.optional()
468
+ })
469
+ );
374
470
  var ConfigFieldDeclarationSchema = z.object({
375
471
  type: z.string(),
376
472
  default: TraitConfigValueSchema.optional(),
473
+ refId: z.string().optional(),
474
+ required: z.boolean().optional(),
377
475
  label: z.string().optional(),
378
476
  description: z.string().optional(),
379
477
  tier: z.string().optional(),
380
478
  values: z.array(z.string()).optional(),
381
- synonyms: z.string().optional()
479
+ synonyms: z.string().optional(),
480
+ items: ConfigFieldItemsDeclarationSchema.optional(),
481
+ properties: z.lazy(() => z.record(TraitEntityFieldSchema)).optional()
382
482
  });
383
483
  var DeclaredTraitConfigSchema = z.record(
384
484
  ConfigFieldDeclarationSchema
@@ -415,7 +515,9 @@ var TraitEntityFieldSchema = z.object({
415
515
  ]),
416
516
  required: z.boolean().optional(),
417
517
  default: z.unknown().optional(),
418
- values: z.array(z.string()).optional()
518
+ values: z.array(z.string()).optional(),
519
+ items: ConfigFieldItemsDeclarationSchema.optional(),
520
+ properties: z.lazy(() => z.record(TraitEntityFieldSchema)).optional()
419
521
  });
420
522
  var TraitDataEntitySchema = z.object({
421
523
  name: z.string().min(1),
@@ -434,9 +536,11 @@ var TraitTickSchema = z.object({
434
536
  interval: z.union([z.literal("frame"), z.number().positive()]),
435
537
  appliesTo: z.array(z.string()).optional(),
436
538
  pages: z.array(z.string()).optional(),
539
+ pageIds: z.array(PageIdSchema).optional(),
437
540
  guard: ExpressionSchema.optional(),
438
541
  effects: z.array(EffectSchema).min(1),
439
- emits: z.array(z.string()).optional()
542
+ emits: z.array(z.string()).optional(),
543
+ emitIds: z.array(EventIdSchema).optional()
440
544
  });
441
545
  var EventScopeSchema = z.enum(["internal", "external"]);
442
546
  var EventPayloadFieldSchema = z.object({
@@ -454,7 +558,8 @@ var EventPayloadFieldSchema = z.object({
454
558
  type: z.string().min(1),
455
559
  required: z.boolean().optional(),
456
560
  description: z.string().optional(),
457
- entityType: z.string().optional()
561
+ entityType: z.string().optional(),
562
+ properties: z.lazy(() => z.array(EventPayloadFieldSchema)).optional()
458
563
  });
459
564
  var TraitEventContractSchema = z.object({
460
565
  /**
@@ -462,12 +567,15 @@ var TraitEventContractSchema = z.object({
462
567
  * starts with a letter, then any letters / digits / underscores. Both
463
568
  * UPPER_SNAKE_CASE and PascalCase shapes are valid identifiers in the
464
569
  * post-Phase 2.5 nominal-event type system (events declared via
465
- * `type X = Event<T>`).
570
+ * `type X = Event<T>`). A pre-resolution `@config.<knob>` reference
571
+ * (Option B) is also legal — inline/resolve substitutes it with the
572
+ * knob's effective literal before codegen/runtime consume it.
466
573
  */
467
574
  event: z.string().min(1).regex(
468
- /^[A-Za-z][A-Za-z0-9_]*$/,
469
- "Event name must start with a letter and contain only letters, digits, and underscores"
575
+ /^([A-Za-z][A-Za-z0-9_]*|@config\.[A-Za-z_][A-Za-z0-9_]*)$/,
576
+ "Event name must start with a letter and contain only letters, digits, and underscores, or be a `@config.<knob>` reference"
470
577
  ),
578
+ eventId: EventIdSchema.optional(),
471
579
  description: z.string().optional(),
472
580
  synonyms: z.string().optional(),
473
581
  tier: z.string().optional(),
@@ -476,16 +584,24 @@ var TraitEventContractSchema = z.object({
476
584
  });
477
585
  var ListenSourceSchema = z.union([
478
586
  z.object({ kind: z.literal("any") }),
479
- z.object({ kind: z.literal("trait"), trait: z.string().min(1) }),
587
+ z.object({
588
+ kind: z.literal("trait"),
589
+ trait: z.string().min(1),
590
+ traitId: TraitIdSchema.optional()
591
+ }),
480
592
  z.object({
481
593
  kind: z.literal("orbital"),
482
594
  orbital: z.string().min(1),
483
- trait: z.string().min(1)
595
+ trait: z.string().min(1),
596
+ orbitalId: OrbitalIdSchema.optional(),
597
+ traitId: TraitIdSchema.optional()
484
598
  })
485
599
  ]);
486
600
  var TraitEventListenerSchema = z.object({
487
601
  event: z.string().min(1),
602
+ eventId: EventIdSchema.optional(),
488
603
  triggers: z.string().min(1),
604
+ triggersId: EventIdSchema.optional(),
489
605
  description: z.string().optional(),
490
606
  synonyms: z.string().optional(),
491
607
  tier: z.string().optional(),
@@ -501,14 +617,20 @@ var RequiredFieldSchema = z.object({
501
617
  });
502
618
  z.object({
503
619
  ref: z.string().min(1),
620
+ refId: TraitIdSchema.optional(),
621
+ // V4 local declaration id (see the interface doc) — declared so the
622
+ // strip-mode zod gate carries it through instead of dropping it.
623
+ id: TraitIdSchema.optional(),
504
624
  // Phase 1.2: optional registry path disambiguator, pairs with `ref`.
505
625
  from: z.string().optional(),
506
626
  linkedEntity: z.string().optional(),
627
+ linkedEntityId: EntityIdSchema.optional(),
507
628
  name: z.string().optional(),
508
629
  events: z.record(
509
630
  z.string().min(1, "events key (atom event name) must be non-empty"),
510
631
  z.string().min(1, "events value (caller event name) must be non-empty")
511
632
  ).optional(),
633
+ eventIds: z.record(z.string().min(1), EventIdSchema).optional(),
512
634
  fields: z.record(
513
635
  z.string().min(1, "fields key (canonical field name) must be non-empty"),
514
636
  z.string().min(1, "fields value (consumer field name) must be non-empty")
@@ -558,6 +680,7 @@ var SourceBehaviorMetadataSchema = z.object({
558
680
  originalName: z.string().min(1)
559
681
  });
560
682
  var TraitSchema = z.object({
683
+ id: TraitIdSchema.optional(),
561
684
  name: z.string().min(1),
562
685
  description: z.string().optional(),
563
686
  description_visual_prompt: z.string().optional(),
@@ -569,6 +692,9 @@ var TraitSchema = z.object({
569
692
  capabilities: z.array(z.string()).optional(),
570
693
  scope: TraitScopeSchema,
571
694
  linkedEntity: z.string().optional(),
695
+ linkedEntityId: EntityIdSchema.optional(),
696
+ entityRefIds: z.record(z.string().min(1), EntityIdSchema).optional(),
697
+ traitEmbedIds: z.record(z.string().min(1), TraitIdSchema).optional(),
572
698
  requiredFields: z.array(RequiredFieldSchema).optional(),
573
699
  dataEntities: z.array(TraitDataEntitySchema).optional(),
574
700
  stateMachine: StateMachineSchema.optional(),
@@ -611,10 +737,13 @@ var ViewTypeSchema = z.enum([
611
737
  ]);
612
738
  var PageTraitRefSchema = z.object({
613
739
  ref: z.string().min(1, "Trait ref is required"),
740
+ refId: TraitIdSchema.optional(),
614
741
  linkedEntity: z.string().optional(),
742
+ linkedEntityId: EntityIdSchema.optional(),
615
743
  config: TraitConfigSchema.optional()
616
744
  });
617
745
  z.object({
746
+ id: PageIdSchema.optional(),
618
747
  name: z.string().min(1, "Page name is required"),
619
748
  path: z.string().min(1, "Page path is required").startsWith("/", "Path must start with /"),
620
749
  primaryEntity: z.string().min(1, "Primary entity is required"),
@@ -622,6 +751,7 @@ z.object({
622
751
  title: z.string().optional()
623
752
  }).strict();
624
753
  var OrbitalPageSchema = z.object({
754
+ id: PageIdSchema.optional(),
625
755
  name: z.string().min(1, "Page name is required"),
626
756
  path: z.string().min(1, "Page path is required").startsWith("/", "Path must start with /"),
627
757
  viewType: ViewTypeSchema.optional(),
@@ -1137,11 +1267,14 @@ var PageRefStringSchema = z.string().regex(
1137
1267
  );
1138
1268
  var PageRefObjectSchema = z.object({
1139
1269
  ref: PageRefStringSchema,
1270
+ refId: PageIdSchema.optional(),
1140
1271
  // Phase 1.2: optional registry path disambiguator, pairs with `ref`.
1141
1272
  from: z.string().optional(),
1142
1273
  path: z.string().startsWith("/").optional(),
1143
1274
  linkedEntity: z.string().optional(),
1144
- traits: z.array(TraitRefSchema).optional()
1275
+ linkedEntityId: EntityIdSchema.optional(),
1276
+ traits: z.array(TraitRefSchema).optional(),
1277
+ traitRefIds: z.array(TraitIdSchema).optional()
1145
1278
  });
1146
1279
  var PageRefSchema = z.union([
1147
1280
  PageSchema,
@@ -1177,6 +1310,7 @@ var ComputedEventListenerSchema = z.object({
1177
1310
  payloadMapping: z.record(z.string()).optional()
1178
1311
  });
1179
1312
  var OrbitalDefinitionSchema = z.object({
1313
+ id: OrbitalIdSchema.optional(),
1180
1314
  name: z.string().min(1, "Orbital name is required"),
1181
1315
  description: z.string().optional(),
1182
1316
  visual_prompt: z.string().optional(),
@@ -1237,7 +1371,12 @@ z.object({
1237
1371
  orbitals: z.array(OrbitalSchema).min(1, "At least one orbital is required"),
1238
1372
  services: z.array(ServiceDefinitionSchema).optional(),
1239
1373
  config: OrbitalConfigSchema.optional(),
1240
- _metadata: SchemaMetadataSchema.optional()
1374
+ _metadata: SchemaMetadataSchema.optional(),
1375
+ // V4 identity — optional/dual-carry until the Phase-7 flip. Present on
1376
+ // id-carrying `.orb` files so `parseOrbitalSchema` preserves them instead
1377
+ // of stripping unknown keys.
1378
+ schemaVersion: z.number().optional(),
1379
+ ledger: IdentityLedgerSchema.optional()
1241
1380
  });
1242
1381
  z.string().refine(
1243
1382
  (val) => {
@@ -1354,6 +1493,7 @@ function makeTraitRef(opts) {
1354
1493
  if (opts.from !== void 0) ref2.from = opts.from;
1355
1494
  if (opts.name !== void 0) ref2.name = opts.name;
1356
1495
  if (opts.linkedEntity !== void 0) ref2.linkedEntity = opts.linkedEntity;
1496
+ if (opts.linkedEntityId !== void 0) ref2.linkedEntityId = opts.linkedEntityId;
1357
1497
  if (opts.events !== void 0) ref2.events = opts.events;
1358
1498
  if (opts.fields !== void 0) ref2.fields = opts.fields;
1359
1499
  if (opts.effects !== void 0) ref2.effects = opts.effects;
@@ -1640,32 +1780,17 @@ function rewriteEntityInInlineTrait(trait, oldName, newName) {
1640
1780
  }
1641
1781
  return next;
1642
1782
  }
1643
- function rebuildTraits(ctx, effectiveEntityName, traits) {
1783
+ function rebuildTraits(traits) {
1644
1784
  return traits.map((t) => {
1645
- if (!isTraitReferenceObject(t)) {
1646
- if (typeof t === "string") return t;
1647
- return rebindInlineTraitEntity(t, ctx.canonicalEntityName, effectiveEntityName);
1648
- }
1649
- const rewrittenLinkedEntity = t.linkedEntity === ctx.canonicalEntityName ? effectiveEntityName : t.linkedEntity;
1650
- const opts = {
1651
- ...t,
1652
- linkedEntity: rewrittenLinkedEntity
1653
- };
1654
- return makeTraitRef(opts);
1785
+ if (!isTraitReferenceObject(t)) return t;
1786
+ return makeTraitRef({ ...t });
1655
1787
  });
1656
1788
  }
1657
- function rebuildPages(ctx, effectiveEntityName, pages) {
1789
+ function rebuildPages(pages) {
1658
1790
  if (!pages) return [];
1659
1791
  return pages.map((p) => {
1660
- if (!isPageRefObject(p)) {
1661
- return p;
1662
- }
1663
- const rewrittenLinkedEntity = p.linkedEntity === ctx.canonicalEntityName ? effectiveEntityName : p.linkedEntity;
1664
- const opts = {
1665
- ...p,
1666
- linkedEntity: rewrittenLinkedEntity
1667
- };
1668
- return makePageRef(opts);
1792
+ if (!isPageRefObject(p)) return p;
1793
+ return makePageRef({ ...p });
1669
1794
  });
1670
1795
  }
1671
1796
  function mergeCallSiteConfigOverrides(base, overrides) {
@@ -1683,19 +1808,75 @@ function mergeCallSiteConfigOverrides(base, overrides) {
1683
1808
  }
1684
1809
  return next;
1685
1810
  }
1811
+ function applyDeclarationTraitRenames(schema, renames, at) {
1812
+ if (renames.size === 0) return schema;
1813
+ const renamedTraitIds = [];
1814
+ const renameDeclaration = (t) => {
1815
+ if (typeof t !== "object" || t === null) return t;
1816
+ const named = t;
1817
+ if (typeof named.name !== "string") return t;
1818
+ const renamed = renames.get(named.name);
1819
+ if (renamed === void 0) return t;
1820
+ const id = t.id;
1821
+ if (typeof id === "string") renamedTraitIds.push({ id, to: renamed });
1822
+ return { ...t, name: renamed };
1823
+ };
1824
+ const orbitals = schema.orbitals.map((orbital) => {
1825
+ if (!("traits" in orbital) || !Array.isArray(orbital.traits)) return orbital;
1826
+ return { ...orbital, traits: orbital.traits.map(renameDeclaration) };
1827
+ });
1828
+ let ledger = schema.ledger;
1829
+ if (ledger !== void 0) {
1830
+ for (const { id, to } of renamedTraitIds) {
1831
+ ledger = ledgerRename(ledger, id, to, at);
1832
+ }
1833
+ }
1834
+ return { ...schema, orbitals, ...ledger !== schema.ledger ? { ledger } : {} };
1835
+ }
1836
+ function applyDeclarationEntityRename(schema, rename, at) {
1837
+ if (rename.from === rename.to) return schema;
1838
+ const linkedEntityIsFrom = (shape) => shape.linkedEntity === rename.from;
1839
+ const renamedEntityIds = [];
1840
+ const orbitals = schema.orbitals.map((orbital) => {
1841
+ const entity = orbital.entity;
1842
+ if (typeof entity !== "object" || entity === null || entity.name !== rename.from) {
1843
+ return orbital;
1844
+ }
1845
+ const entityId = entity.id;
1846
+ if (typeof entityId === "string") renamedEntityIds.push(entityId);
1847
+ const traits = orbital.traits.map(
1848
+ (t) => typeof t === "object" && t !== null && linkedEntityIsFrom(t) ? { ...t, linkedEntity: rename.to } : t
1849
+ );
1850
+ const pages = orbital.pages?.map(
1851
+ (p) => typeof p === "object" && p !== null && linkedEntityIsFrom(p) ? { ...p, linkedEntity: rename.to } : p
1852
+ );
1853
+ return {
1854
+ ...orbital,
1855
+ entity: { ...entity, name: rename.to },
1856
+ traits,
1857
+ ...pages !== void 0 ? { pages } : {}
1858
+ };
1859
+ });
1860
+ let ledger = schema.ledger;
1861
+ if (ledger !== void 0) {
1862
+ for (const id of renamedEntityIds) {
1863
+ ledger = ledgerRename(ledger, id, rename.to, at);
1864
+ }
1865
+ }
1866
+ return { ...schema, orbitals, ...ledger !== schema.ledger ? { ledger } : {} };
1867
+ }
1686
1868
  function applyParamsToOrb(orb, orbitalName, _manifest, params) {
1687
1869
  const orbital = findOrbitalOrThrow(orb, orbitalName);
1688
1870
  const canonicalEntity = assertResolvedEntity(orbital.entity, orbitalName, orb.name);
1689
1871
  const canonicalEntityName = canonicalEntity.name;
1690
- const effectiveEntityName = params.entityName ?? canonicalEntityName;
1691
1872
  const effectiveCollection = typeof canonicalEntity.collection === "string" ? params.collection ?? (params.entityName ? `${params.entityName.toLowerCase()}s` : canonicalEntity.collection) : params.collection;
1692
- const ctx = { canonicalEntityName, canonicalEntity };
1873
+ const ctx = { canonicalEntity };
1693
1874
  const built = makeOrbitalWithUses({
1694
1875
  name: orbital.name,
1695
1876
  uses: orbital.uses ?? [],
1696
- entity: buildEntity(ctx, effectiveEntityName, effectiveCollection, params),
1697
- traits: rebuildTraits(ctx, effectiveEntityName, orbital.traits),
1698
- pages: rebuildPages(ctx, effectiveEntityName, orbital.pages)
1877
+ entity: buildEntity(ctx, canonicalEntityName, effectiveCollection, params),
1878
+ traits: rebuildTraits(orbital.traits),
1879
+ pages: rebuildPages(orbital.pages)
1699
1880
  });
1700
1881
  if (built.traits && params.traitOverrides !== void 0) {
1701
1882
  built.traits = built.traits.map((t) => {
@@ -1722,7 +1903,6 @@ function applyParamsToOrb(orb, orbitalName, _manifest, params) {
1722
1903
  }
1723
1904
  merged.events = { ...t.events ?? {}, ...override.events };
1724
1905
  }
1725
- if (override.name !== void 0) merged.name = override.name;
1726
1906
  if (override.emitsScope !== void 0) merged.emitsScope = override.emitsScope;
1727
1907
  if (override.listens !== void 0) merged.listens = override.listens;
1728
1908
  return merged;
@@ -1755,6 +1935,6 @@ function applyParamsToWholeOrb(orb, manifests, params) {
1755
1935
  return { ...orb, orbitals: rebuilt };
1756
1936
  }
1757
1937
 
1758
- export { applyParamsToOrb, applyParamsToWholeOrb, extractManifest, mergeCallSiteConfigOverrides, rebindInlineTraitEntity, rewriteEntityInInlineTrait, validateOrbitalFactoryParams };
1938
+ export { applyDeclarationEntityRename, applyDeclarationTraitRenames, applyParamsToOrb, applyParamsToWholeOrb, extractManifest, mergeCallSiteConfigOverrides, rebindInlineTraitEntity, rewriteEntityInInlineTrait, validateOrbitalFactoryParams };
1759
1939
  //# sourceMappingURL=index.js.map
1760
1940
  //# sourceMappingURL=index.js.map