@neocompose/cli 0.80.0 → 0.81.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.
@@ -1013,11 +1013,11 @@ var NeoWorldSystemClassKind = {
1013
1013
  ObjectCollider: "objectCollider",
1014
1014
  SortingGroup: "sortingGroup",
1015
1015
  LayerGroupBase: "layerGroupBase",
1016
- SpriteObject: "spriteObject",
1017
1016
  PlacementTile: "placementTile",
1018
1017
  TileLayerLink: "tileLayerLink",
1019
1018
  ObjectLayerLink: "objectLayerLink",
1020
1019
  Object: "object",
1020
+ SpriteObject: "spriteObject",
1021
1021
  SmartTile: "smartTile",
1022
1022
  SmartTileRule: "smartTileRule",
1023
1023
  SmartTileNeighbor: "smartTileNeighbor",
@@ -3600,6 +3600,8 @@ function isNSFunctionVariantApply(value) {
3600
3600
  if (!isNSPointer(info.variantPointer)) return false;
3601
3601
  if (info.rowPointer !== void 0 && !isNSPointer(info.rowPointer))
3602
3602
  return false;
3603
+ if (info.declarativeReplay !== void 0 && info.declarativeReplay !== true)
3604
+ return false;
3603
3605
  return isNSTypeInfoClass(info.schemaClassInfo) && info.schemaClassInfo.required;
3604
3606
  }
3605
3607
  function isNSFunctionClassConstructor(value) {
@@ -5284,7 +5286,9 @@ function isLiteralValueContent(value) {
5284
5286
  for (const field of [
5285
5287
  "instanceConstructorId",
5286
5288
  "instanceVariantId",
5287
- "instanceVariantRowValueId"
5289
+ "instanceVariantRowValueId",
5290
+ "instanceAppliedVariantId",
5291
+ "instanceAppliedVariantRowValueId"
5288
5292
  ]) {
5289
5293
  const provenance = getField(value, field);
5290
5294
  if (provenance !== void 0 && provenance !== null && (typeof provenance !== "string" || provenance.length === 0)) {
@@ -5310,6 +5314,9 @@ function isInitValueContent(value) {
5310
5314
  if (getField(value, "instanceConstructorId") !== void 0) return false;
5311
5315
  if (getField(value, "instanceVariantId") !== void 0) return false;
5312
5316
  if (getField(value, "instanceVariantRowValueId") !== void 0) return false;
5317
+ if (getField(value, "instanceAppliedVariantId") !== void 0) return false;
5318
+ if (getField(value, "instanceAppliedVariantRowValueId") !== void 0)
5319
+ return false;
5313
5320
  const classIdField = getField(value, "classId");
5314
5321
  return classIdField === void 0 || classIdField === null;
5315
5322
  }
@@ -6081,6 +6088,8 @@ var LITERAL_INSTANCE_IDENTITY_FIELDS = [
6081
6088
  "instanceConstructorId",
6082
6089
  "instanceVariantId",
6083
6090
  "instanceVariantRowValueId",
6091
+ "instanceAppliedVariantId",
6092
+ "instanceAppliedVariantRowValueId",
6084
6093
  "genericBindings"
6085
6094
  ];
6086
6095
  function replaceLiteralValueClass(value, classId) {
@@ -6103,7 +6112,11 @@ function pickInstanceProvenance(source) {
6103
6112
  ...source.constructorArgs === void 0 ? {} : { constructorArgs: source.constructorArgs },
6104
6113
  ...source.instanceConstructorId === void 0 ? {} : { instanceConstructorId: source.instanceConstructorId },
6105
6114
  ...source.instanceVariantId === void 0 ? {} : { instanceVariantId: source.instanceVariantId },
6106
- ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId }
6115
+ ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId },
6116
+ ...source.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: source.instanceAppliedVariantId },
6117
+ ...source.instanceAppliedVariantRowValueId === void 0 ? {} : {
6118
+ instanceAppliedVariantRowValueId: source.instanceAppliedVariantRowValueId
6119
+ }
6107
6120
  };
6108
6121
  }
6109
6122
  function isVirtualInstanceRootShape(value) {
@@ -6276,7 +6289,7 @@ function decodeContentField(container, field, scope, children) {
6276
6289
  )
6277
6290
  };
6278
6291
  }
6279
- const decoded = {};
6292
+ const decoded = /* @__PURE__ */ Object.create(null);
6280
6293
  for (const [key, entry] of Object.entries(
6281
6294
  container
6282
6295
  )) {
@@ -7343,64 +7356,6 @@ var WORLD_SYSTEM_CLASS_DEFINITIONS = [
7343
7356
  modifier: 1 /* Abstract */,
7344
7357
  worldKind: "layerGroupBase"
7345
7358
  },
7346
- {
7347
- classId: "system_d48b66ab-4d59-47e7-a25a-591fe97062de",
7348
- name: "NeoSpriteObject",
7349
- extendsWorldKind: "objectBase",
7350
- schemaFields: [
7351
- {
7352
- memberId: "system_441cb790-a45f-4488-a5a9-6f375af6c369",
7353
- memberKind: "string",
7354
- defaultValue: "",
7355
- format: 1 /* Plain */,
7356
- distribution: 1 /* Packed */,
7357
- requirement: 1 /* Required */,
7358
- schemaKey: "Name"
7359
- },
7360
- {
7361
- memberId: "system_e9288ba9-f5a2-4485-8443-6afb155b31e0",
7362
- memberKind: "sprite",
7363
- defaultValue: { fileId: "", sliceIndex: 0 },
7364
- requirement: 1 /* Required */,
7365
- schemaKey: "Sprite"
7366
- },
7367
- {
7368
- memberId: "system_9fcab37a-9743-4e35-8eee-80cb560f1433",
7369
- memberKind: "bool",
7370
- defaultValue: false,
7371
- docsText: "Mirrors the sprite horizontally about its own centre. Maps to SpriteRenderer.flipX.",
7372
- requirement: 1 /* Required */,
7373
- schemaKey: "FlipX"
7374
- },
7375
- {
7376
- memberId: "system_ddd09f08-1656-4404-b36b-5570a4c01fcf",
7377
- memberKind: "bool",
7378
- defaultValue: false,
7379
- docsText: "Mirrors the sprite vertically about its own centre. Maps to SpriteRenderer.flipY.",
7380
- requirement: 1 /* Required */,
7381
- schemaKey: "FlipY"
7382
- },
7383
- {
7384
- memberId: "system_f2a8c86d-ace5-421b-9475-0f3f6f97b2a6",
7385
- memberKind: "enum",
7386
- defaultValue: ["system_9d607a4f-60c3-4347-94fc-f24b538bf468"],
7387
- docsText: "How this sprite reacts to sprite masks. Maps to SpriteRenderer.maskInteraction. The web canvas has no real sprite mask, so anything other than None previews as a distinguishable treatment rather than as the mask itself \u2014 only Unity renders the real thing.",
7388
- enumId: "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec",
7389
- requirement: 1 /* Required */,
7390
- schemaKey: "MaskInteraction"
7391
- },
7392
- {
7393
- memberId: "system_6f32f1f2-83ea-42fc-8647-34ed0946b7f1",
7394
- memberKind: "int",
7395
- defaultValue: null,
7396
- docsText: "Added to the object layer's sorting order; it does not replace it. The result competes with every renderer in the sorting layer, or in the enclosing sorting group, and among equal orders the renderer lower on screen draws in front. Leave unset to use the layer's order.",
7397
- minValue: -32768,
7398
- maxValue: 32767,
7399
- schemaKey: "SortingOrder"
7400
- }
7401
- ],
7402
- worldKind: "spriteObject"
7403
- },
7404
7359
  {
7405
7360
  classId: "system_ccc3330c-2db5-44dc-9c8e-5ebfe430dec9",
7406
7361
  name: "NeoPlacementTile",
@@ -7479,6 +7434,7 @@ var WORLD_SYSTEM_CLASS_DEFINITIONS = [
7479
7434
  memberId: "system_5a9ca1f5-a21b-4d4e-8c55-00341af594b4",
7480
7435
  memberKind: "list",
7481
7436
  defaultValue: [],
7437
+ docsText: "The cells this object occupies, as offsets from its placement cell. An empty list occupies nothing: the object blocks no placement and answers no cell query, but a placed object still has a Cell.",
7482
7438
  entryMemberId: "system_96c7650a-1805-5b27-ae99-d1e49d3cb207",
7483
7439
  requirement: 1 /* Required */,
7484
7440
  schemaKey: "PlacementTiles"
@@ -7663,6 +7619,64 @@ var WORLD_SYSTEM_CLASS_DEFINITIONS = [
7663
7619
  ],
7664
7620
  worldKind: "object"
7665
7621
  },
7622
+ {
7623
+ classId: "system_d48b66ab-4d59-47e7-a25a-591fe97062de",
7624
+ name: "NeoSpriteObject",
7625
+ extendsWorldKind: "object",
7626
+ schemaFields: [
7627
+ {
7628
+ memberId: "system_441cb790-a45f-4488-a5a9-6f375af6c369",
7629
+ memberKind: "string",
7630
+ defaultValue: "",
7631
+ format: 1 /* Plain */,
7632
+ distribution: 1 /* Packed */,
7633
+ requirement: 1 /* Required */,
7634
+ schemaKey: "Name"
7635
+ },
7636
+ {
7637
+ memberId: "system_e9288ba9-f5a2-4485-8443-6afb155b31e0",
7638
+ memberKind: "sprite",
7639
+ defaultValue: { fileId: "", sliceIndex: 0 },
7640
+ requirement: 1 /* Required */,
7641
+ schemaKey: "Sprite"
7642
+ },
7643
+ {
7644
+ memberId: "system_9fcab37a-9743-4e35-8eee-80cb560f1433",
7645
+ memberKind: "bool",
7646
+ defaultValue: false,
7647
+ docsText: "Mirrors the sprite horizontally about its own centre. Maps to SpriteRenderer.flipX.",
7648
+ requirement: 1 /* Required */,
7649
+ schemaKey: "FlipX"
7650
+ },
7651
+ {
7652
+ memberId: "system_ddd09f08-1656-4404-b36b-5570a4c01fcf",
7653
+ memberKind: "bool",
7654
+ defaultValue: false,
7655
+ docsText: "Mirrors the sprite vertically about its own centre. Maps to SpriteRenderer.flipY.",
7656
+ requirement: 1 /* Required */,
7657
+ schemaKey: "FlipY"
7658
+ },
7659
+ {
7660
+ memberId: "system_f2a8c86d-ace5-421b-9475-0f3f6f97b2a6",
7661
+ memberKind: "enum",
7662
+ defaultValue: ["system_9d607a4f-60c3-4347-94fc-f24b538bf468"],
7663
+ docsText: "How this sprite reacts to sprite masks. Maps to SpriteRenderer.maskInteraction. The web canvas has no real sprite mask, so anything other than None previews as a distinguishable treatment rather than as the mask itself \u2014 only Unity renders the real thing.",
7664
+ enumId: "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec",
7665
+ requirement: 1 /* Required */,
7666
+ schemaKey: "MaskInteraction"
7667
+ },
7668
+ {
7669
+ memberId: "system_6f32f1f2-83ea-42fc-8647-34ed0946b7f1",
7670
+ memberKind: "int",
7671
+ defaultValue: null,
7672
+ docsText: "Added to the object layer's sorting order; it does not replace it. The result competes with every renderer in the sorting layer, or in the enclosing sorting group, and among equal orders the renderer lower on screen draws in front. Leave unset to use the layer's order.",
7673
+ minValue: -32768,
7674
+ maxValue: 32767,
7675
+ schemaKey: "SortingOrder"
7676
+ }
7677
+ ],
7678
+ worldKind: "spriteObject"
7679
+ },
7666
7680
  {
7667
7681
  classId: "system_9f34deed-2616-43c9-b614-d812da89ee51",
7668
7682
  name: "NeoSmartTile",
@@ -11532,12 +11546,8 @@ function evaluateLiteralContainer(args) {
11532
11546
  const literal3 = {
11533
11547
  value: evaluated.value,
11534
11548
  classId: evaluated.classId,
11535
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
11536
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
11537
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
11538
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
11539
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
11540
- }
11549
+ ...pickInstanceProvenance(evaluated),
11550
+ ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) }
11541
11551
  };
11542
11552
  if (isMemberLookupBase(args.member)) {
11543
11553
  if (evaluated.existingValueRow !== void 0) {
@@ -11870,15 +11880,9 @@ function buildNewValue(projectId, body, timestamp2 = Date.now()) {
11870
11880
  if (body.constructorArgs !== void 0 && body.constructorArgs !== null) {
11871
11881
  props.constructorArgs = deepClonePlainData(body.constructorArgs);
11872
11882
  }
11873
- if (body.instanceConstructorId !== void 0) {
11874
- props.instanceConstructorId = body.instanceConstructorId;
11875
- }
11876
- if (body.instanceVariantId !== void 0) {
11877
- props.instanceVariantId = body.instanceVariantId;
11878
- }
11879
- if (body.instanceVariantRowValueId !== void 0) {
11880
- props.instanceVariantRowValueId = body.instanceVariantRowValueId;
11881
- }
11883
+ const { constructorArgs: _constructorArgs, ...provenance } = pickInstanceProvenance(body);
11884
+ void _constructorArgs;
11885
+ Object.assign(props, provenance);
11882
11886
  return props;
11883
11887
  }
11884
11888
  function retargetInitializerRootValueIds(rows, fromValueId, toValueId) {
@@ -11959,11 +11963,7 @@ function completeDefaultClassRecord(args) {
11959
11963
  if (!shouldMaterializeChildDefaultForRoot(
11960
11964
  args.constructorRoot,
11961
11965
  resolvedChildMember,
11962
- defaultSettlesConstruction2,
11963
- documentHasInitValueContent(
11964
- args.document,
11965
- resolvedChildMember.defaultValue
11966
- )
11966
+ defaultSettlesConstruction2
11967
11967
  )) {
11968
11968
  continue;
11969
11969
  }
@@ -12074,7 +12074,7 @@ function cloneDefaultDictionaryRecord(args) {
12074
12074
  args.document,
12075
12075
  args.member.entryMemberId
12076
12076
  );
12077
- const value = {};
12077
+ const value = /* @__PURE__ */ Object.create(null);
12078
12078
  for (const [key, sourceValueId] of Object.entries(sourceValue)) {
12079
12079
  value[key] = cloneDefaultValueForMember({
12080
12080
  document: args.document,
@@ -12351,9 +12351,7 @@ function cloneMemberValueBase(body) {
12351
12351
  return {
12352
12352
  value: deepClonePlainData(body.value),
12353
12353
  classId: body.classId,
12354
- ...body.instanceConstructorId === void 0 ? {} : { instanceConstructorId: body.instanceConstructorId },
12355
- ...body.instanceVariantId === void 0 ? {} : { instanceVariantId: body.instanceVariantId },
12356
- ...body.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: body.instanceVariantRowValueId },
12354
+ ...pickInstanceProvenance({ ...body, constructorArgs: void 0 }),
12357
12355
  ...body.constructorArgs === void 0 || body.constructorArgs === null ? {} : {
12358
12356
  constructorArgs: deepClonePlainData(body.constructorArgs)
12359
12357
  }
@@ -12391,11 +12389,6 @@ function shouldMaterializeChildDefault(member) {
12391
12389
  }
12392
12390
  return member.defaultValue !== void 0;
12393
12391
  }
12394
- function shouldMaterializeConstructorChildDefault(member, isInitializer = isInitValueContent(member.defaultValue)) {
12395
- if (isInitializer) return true;
12396
- if (!isRequiredMember(member)) return false;
12397
- return shouldMaterializeChildDefault(member);
12398
- }
12399
12392
  function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member, defaultSettlesConstruction2, isInitializer = isInitValueContent(member.defaultValue)) {
12400
12393
  if (constructorRoot === void 0) return false;
12401
12394
  if (!constructorRoot.providedSchemaKeys.has(schemaKey)) return false;
@@ -12404,16 +12397,11 @@ function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member, de
12404
12397
  }
12405
12398
  return !isInitializer && !defaultSettlesConstruction2;
12406
12399
  }
12407
- function shouldMaterializeChildDefaultForRoot(constructorRoot, member, defaultSettlesConstruction2, isInitializer = isInitValueContent(member.defaultValue)) {
12408
- if (constructorRoot === void 0)
12409
- return shouldMaterializeChildDefault(member);
12410
- if (constructorRoot.omitMissingRequired === true && !defaultSettlesConstruction2) {
12400
+ function shouldMaterializeChildDefaultForRoot(constructorRoot, member, defaultSettlesConstruction2) {
12401
+ if (constructorRoot?.omitMissingRequired === true && !defaultSettlesConstruction2) {
12411
12402
  return false;
12412
12403
  }
12413
- if (constructorRoot.runsMemberInitializers === true) {
12414
- return shouldMaterializeChildDefault(member);
12415
- }
12416
- return shouldMaterializeConstructorChildDefault(member, isInitializer);
12404
+ return shouldMaterializeChildDefault(member);
12417
12405
  }
12418
12406
  function primitiveFallbackValue(document2, member) {
12419
12407
  if (isMemberBoolBase(member)) return { value: false };
@@ -13342,7 +13330,7 @@ function toCanonicalJsonValue(value) {
13342
13330
  });
13343
13331
  }
13344
13332
  const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
13345
- const canonicalObject = {};
13333
+ const canonicalObject = /* @__PURE__ */ Object.create(null);
13346
13334
  for (const [key, entryValue] of entries) {
13347
13335
  const canonicalValue = toCanonicalJsonValue(entryValue);
13348
13336
  if (canonicalValue === void 0) continue;
@@ -16249,7 +16237,11 @@ function buildIndex(source) {
16249
16237
  }
16250
16238
  const placement = {
16251
16239
  valueId,
16252
- isNeoObject: kinds.get(row.classId) === NeoWorldSystemClassKind.Object,
16240
+ isNeoObject: classInheritsWorldKind(
16241
+ row.classId,
16242
+ NeoWorldSystemClassKind.Object,
16243
+ relations.classesById
16244
+ ),
16253
16245
  classId: row.classId,
16254
16246
  gridId: root.id,
16255
16247
  layerId,
@@ -16980,6 +16972,7 @@ function makeUnindexedEvaluatorLookups(members, storedValues) {
16980
16972
  hasStoredValueId: (id) => valueById.has(id),
16981
16973
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
16982
16974
  virtualInstanceRowsForValue: () => [],
16975
+ virtualInstanceRootIdForValue: () => null,
16983
16976
  rowForValueReference: (value) => valueRefMap.get(value) ?? null
16984
16977
  };
16985
16978
  }
@@ -17163,6 +17156,7 @@ function createEvaluatorLookupsBuild(members, storedValues, options = {}) {
17163
17156
  hasStoredValueId: (id) => valueById.has(id),
17164
17157
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
17165
17158
  virtualInstanceRowsForValue: () => [],
17159
+ virtualInstanceRootIdForValue: () => null,
17166
17160
  rowForValueReference: (value) => rowByValueReference.get(value) ?? null,
17167
17161
  evaluatorIndexes: indexes3.result,
17168
17162
  ...options.constructorInitializerDocument === void 0 ? {} : {
@@ -17280,6 +17274,7 @@ function layerEvaluatorLookups(base, overlay) {
17280
17274
  hasStoredValueId: (id) => overlay.rows.has(id) || !overlay.hiddenIds.has(id) && (base.hasStoredValueId?.(id) ?? false),
17281
17275
  unorderedListEntryIds,
17282
17276
  virtualInstanceRowsForValue: () => [],
17277
+ virtualInstanceRootIdForValue: () => null,
17283
17278
  rowForValueReference: (value) => evaluatorIndexes2.rowByValueReference.get(value) ?? null,
17284
17279
  evaluatorIndexes: evaluatorIndexes2,
17285
17280
  constructorInitializerIndexes: constructorInitializerIndexes2
@@ -17685,13 +17680,15 @@ function bindThisValue(ctx, thisValue) {
17685
17680
  function observeValueWrite(ctx, row) {
17686
17681
  ctx.beforeValueWrite?.(row);
17687
17682
  ctx.__getterSubscriptions?.noteValueWrite(row.id);
17683
+ forgetVariantResolutionCopy(ctx, row.id);
17688
17684
  }
17689
17685
  function assertStoredReplayMutableValue(value, ctx, label, key) {
17690
- const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false;
17686
+ const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false || hasVariantResolutionCopies(ctx);
17691
17687
  if (ctx.storedConstructionReplay !== true && !ctx.assertValueWritable && !observesWrites)
17692
17688
  return;
17693
17689
  let rowId = findKnownRowIdByValueReference(value, ctx);
17694
17690
  if (rowId === null) return;
17691
+ forgetVariantResolutionCopy(ctx, rowId);
17695
17692
  const container = ctx.beforeValueWrite && evalValueById(ctx, rowId, ctx.__runtimeSessionValues, ctx.__valueOverlay);
17696
17693
  if (container) ctx.beforeValueWrite?.(container);
17697
17694
  if (key !== void 0 && value !== null && typeof value === "object") {
@@ -26499,12 +26496,7 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
26499
26496
  deleteRuntimeSessionValue(ctx, rootRow.id);
26500
26497
  ctx.__executionState?.constructorGroups.delete(rootRow.id);
26501
26498
  const constructorArgs = typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue.get(result.value) ?? rootRow.constructorArgs ?? void 0 : void 0;
26502
- const provenance = pickInstanceProvenance({
26503
- constructorArgs,
26504
- instanceConstructorId: rootRow.instanceConstructorId,
26505
- instanceVariantId: rootRow.instanceVariantId,
26506
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
26507
- });
26499
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs });
26508
26500
  return {
26509
26501
  value: result.value,
26510
26502
  classId: rootRow.classId ?? null,
@@ -27369,7 +27361,7 @@ function evalVariantInitialize(info, scope, ctx) {
27369
27361
  scope,
27370
27362
  ctx
27371
27363
  );
27372
- stampInstanceVariantProvenance(instance, selection, ctx, true);
27364
+ stampInstanceVariantProvenance(instance, selection, ctx);
27373
27365
  return instance;
27374
27366
  }
27375
27367
  const graph = resolveVariantGraph(selection, ctx);
@@ -27400,12 +27392,16 @@ function evalVariantInitialize(info, scope, ctx) {
27400
27392
  ctx,
27401
27393
  ctx.__variantDeclarativeAnsweredValueIds
27402
27394
  );
27403
- stampInstanceVariantProvenance(instance, selection, ctx, true);
27395
+ stampInstanceVariantProvenance(instance, selection, ctx);
27404
27396
  return instance;
27405
27397
  } finally {
27406
27398
  closeFrame();
27407
27399
  }
27408
27400
  }
27401
+ function isInsideAnotherExpansion(valueId, ctx) {
27402
+ const ownerRootId = ctx.vm.databaseVM?.virtualInstanceRootIdForValue(valueId) ?? null;
27403
+ return ownerRootId !== null && ownerRootId !== valueId;
27404
+ }
27409
27405
  function evalVariantApply(info, scope, ctx) {
27410
27406
  const receiver = evalPointer(info.receiverPointer, scope, ctx);
27411
27407
  if (receiver === null || receiver === void 0) {
@@ -27417,12 +27413,12 @@ function evalVariantApply(info, scope, ctx) {
27417
27413
  evalPointer(info.variantPointer, scope, ctx),
27418
27414
  "ToVariant argument"
27419
27415
  );
27420
- if (selection.variantId === null) {
27421
- stampInstanceVariantProvenance(receiver, selection, ctx);
27416
+ const graph = selection.variantId === null ? null : resolveVariantGraph(selection, ctx);
27417
+ if (info.declarativeReplay === true) {
27418
+ if (graph !== null) applyVariantDeclarativeHalves(receiver, graph, ctx);
27422
27419
  return receiver;
27423
27420
  }
27424
- const graph = resolveVariantGraph(selection, ctx);
27425
- const rowParameters = resolveVariantRowParameter({
27421
+ const rowParameters = graph === null ? [] : resolveVariantRowParameter({
27426
27422
  graph,
27427
27423
  selection,
27428
27424
  explicitPointer: info.rowPointer,
@@ -27431,13 +27427,18 @@ function evalVariantApply(info, scope, ctx) {
27431
27427
  });
27432
27428
  const rootRow = trackedRowForValueReference(receiver, ctx);
27433
27429
  if (rootRow === null || !isLiteralValueContent(rootRow)) {
27430
+ if (graph === null) return receiver;
27434
27431
  throw new NSGetterRuntimeError(
27435
27432
  "ToVariant receiver has no addressable instance root."
27436
27433
  );
27437
27434
  }
27438
- const priorInstanceRoot = ctx.__runtimeSessionValues?.has(rootRow.id) === true ? null : deepClonePlainData(rootRow);
27439
- const applyValue = graph.root.Apply;
27440
- if (applyValue !== void 0 && applyValue !== null) {
27435
+ if (graph === null && typeof rootRow.instanceAppliedVariantId !== "string") {
27436
+ return receiver;
27437
+ }
27438
+ const inPlace = ctx.__runtimeSessionValues?.has(rootRow.id) === true || isInsideAnotherExpansion(rootRow.id, ctx);
27439
+ const priorInstanceRoot = inPlace ? null : deepClonePlainData(rootRow);
27440
+ const applyValue = graph?.root.Apply;
27441
+ if (graph !== null && applyValue !== void 0 && applyValue !== null) {
27441
27442
  invokeVariantClosure({
27442
27443
  closureValueId: applyValue,
27443
27444
  ctx,
@@ -27447,17 +27448,12 @@ function evalVariantApply(info, scope, ctx) {
27447
27448
  });
27448
27449
  }
27449
27450
  if (priorInstanceRoot === null) {
27450
- stampInstanceVariantProvenance(receiver, selection, ctx);
27451
- applyVariantDeclarativeHalves(receiver, graph, ctx);
27451
+ if (graph !== null) applyVariantDeclarativeHalves(receiver, graph, ctx);
27452
27452
  return receiver;
27453
27453
  }
27454
27454
  priorInstanceRoot.value = deepClonePlainData(rootRow.value);
27455
- const answeredSlots = collectVariantDeclarativeAnsweredSlots(
27456
- receiver,
27457
- graph,
27458
- ctx
27459
- );
27460
- stampInstanceVariantProvenance(receiver, selection, ctx);
27455
+ const answeredSlots = graph === null ? [] : collectVariantDeclarativeAnsweredSlots(receiver, graph, ctx);
27456
+ stampAppliedVariantProvenance(rootRow, receiver, selection, ctx);
27461
27457
  const resolver = ctx.vm.databaseVM?.resolveVariantInstanceGraph;
27462
27458
  if (resolver === void 0) {
27463
27459
  if (answeredSlots.length > 0) {
@@ -27466,26 +27462,41 @@ function evalVariantApply(info, scope, ctx) {
27466
27462
  );
27467
27463
  }
27468
27464
  } else {
27465
+ const overlay = ctx.__valueOverlay;
27466
+ const copies = overlay === void 0 ? void 0 : variantResolutionCopies(overlay);
27469
27467
  const resolution = resolver.call(ctx.vm.databaseVM, {
27470
27468
  priorInstanceRoot,
27471
27469
  nextInstanceRoot: deepClonePlainData(rootRow),
27472
27470
  answeredValueIds: [...new Set(answeredSlots.map((slot) => slot.valueId))],
27473
27471
  localRows: [
27474
27472
  ...ctx.__runtimeSessionValues?.values() ?? [],
27475
- ...ctx.__valueOverlay?.values() ?? []
27476
- ]
27473
+ ...overlay?.values() ?? []
27474
+ ],
27475
+ virtualCopyIds: unwrittenVariantResolutionCopyIds(
27476
+ overlay,
27477
+ copies?.byRootId.get(rootRow.id)
27478
+ )
27477
27479
  });
27478
27480
  for (const valueId of resolution.clearedValueIds) {
27479
27481
  const previous = readNeoScriptRuntimeRow(ctx, valueId);
27480
27482
  if (previous) observeValueWrite(ctx, previous);
27481
27483
  deleteRuntimeSessionValue(ctx, valueId);
27482
- ctx.__valueOverlay?.delete(valueId);
27484
+ overlay?.delete(valueId);
27483
27485
  }
27486
+ for (const valueId of copies?.byRootId.get(rootRow.id)?.keys() ?? []) {
27487
+ forgetVariantResolutionCopy(ctx, valueId);
27488
+ }
27489
+ const virtualValueIds = new Set(resolution.virtualValueIds);
27484
27490
  for (const row of resolution.rows) {
27485
27491
  if (row.id === rootRow.id) continue;
27486
27492
  const previous = readNeoScriptRuntimeRow(ctx, row.id);
27487
27493
  if (previous) observeValueWrite(ctx, previous);
27488
- ctx.__valueOverlay?.set(row.id, deepClonePlainData(row));
27494
+ if (overlay === void 0 || copies === void 0) continue;
27495
+ const copy = deepClonePlainData(row);
27496
+ overlay.set(row.id, copy);
27497
+ if (virtualValueIds.has(row.id)) {
27498
+ trackVariantResolutionCopy(copies, rootRow.id, copy);
27499
+ }
27489
27500
  }
27490
27501
  if (typeof receiver !== "object" || receiver === null || Array.isArray(receiver) || typeof resolution.root.value !== "object" || resolution.root.value === null || Array.isArray(resolution.root.value)) {
27491
27502
  throw new NSGetterRuntimeError(
@@ -27499,14 +27510,70 @@ function evalVariantApply(info, scope, ctx) {
27499
27510
  }
27500
27511
  return receiver;
27501
27512
  }
27502
- function stampInstanceVariantProvenance(instance, selection, ctx, preserveLookupRow = false) {
27513
+ var variantResolutionCopiesByOverlay = /* @__PURE__ */ new WeakMap();
27514
+ function variantResolutionCopies(overlay) {
27515
+ let copies = variantResolutionCopiesByOverlay.get(overlay);
27516
+ if (copies === void 0) {
27517
+ copies = { byRootId: /* @__PURE__ */ new Map(), rootIdByValueId: /* @__PURE__ */ new Map() };
27518
+ variantResolutionCopiesByOverlay.set(overlay, copies);
27519
+ }
27520
+ return copies;
27521
+ }
27522
+ function hasVariantResolutionCopies(ctx) {
27523
+ const overlay = ctx.__valueOverlay;
27524
+ if (overlay === void 0) return false;
27525
+ const copies = variantResolutionCopiesByOverlay.get(overlay);
27526
+ return copies !== void 0 && copies.rootIdByValueId.size > 0;
27527
+ }
27528
+ function trackVariantResolutionCopy(copies, rootId, copy) {
27529
+ let rootCopies = copies.byRootId.get(rootId);
27530
+ if (rootCopies === void 0) {
27531
+ rootCopies = /* @__PURE__ */ new Map();
27532
+ copies.byRootId.set(rootId, rootCopies);
27533
+ }
27534
+ rootCopies.set(copy.id, copy);
27535
+ copies.rootIdByValueId.set(copy.id, rootId);
27536
+ }
27537
+ function unwrittenVariantResolutionCopyIds(overlay, rootCopies) {
27538
+ if (overlay === void 0 || rootCopies === void 0) return [];
27539
+ const ids = [];
27540
+ for (const [id, copy] of rootCopies) {
27541
+ if (overlay.get(id) === copy) ids.push(id);
27542
+ }
27543
+ return ids;
27544
+ }
27545
+ function forgetVariantResolutionCopy(ctx, valueId) {
27546
+ const overlay = ctx.__valueOverlay;
27547
+ if (overlay === void 0) return;
27548
+ const copies = variantResolutionCopiesByOverlay.get(overlay);
27549
+ const rootId = copies?.rootIdByValueId.get(valueId);
27550
+ if (copies === void 0 || rootId === void 0) return;
27551
+ copies.rootIdByValueId.delete(valueId);
27552
+ copies.byRootId.get(rootId)?.delete(valueId);
27553
+ }
27554
+ function stampInstanceVariantProvenance(instance, selection, ctx) {
27503
27555
  const row = trackedRowForValueReference(instance, ctx);
27504
27556
  if (row === null || !isLiteralValueContent(row)) return;
27505
- if (preserveLookupRow && row.id === selection.rowValueId) return;
27557
+ if (row.id === selection.rowValueId) return;
27506
27558
  assertStoredReplayMutableValue(instance, ctx, "variant provenance");
27507
27559
  row.instanceVariantId = selection.variantId;
27508
27560
  row.instanceVariantRowValueId = selection.rowValueId;
27509
27561
  }
27562
+ function stampAppliedVariantProvenance(rootRow, instance, selection, ctx) {
27563
+ const applied = typeof rootRow.instanceAppliedVariantId === "string";
27564
+ const variantId = applied ? rootRow.instanceAppliedVariantId : rootRow.instanceVariantId ?? null;
27565
+ const rowValueId = applied ? rootRow.instanceAppliedVariantRowValueId : rootRow.instanceVariantRowValueId;
27566
+ if (variantId === selection.variantId && (rowValueId ?? null) === selection.rowValueId) {
27567
+ return;
27568
+ }
27569
+ assertStoredReplayMutableValue(instance, ctx, "variant provenance");
27570
+ if (!isVirtualInstanceRootShape(rootRow)) {
27571
+ rootRow.instanceConstructorId = null;
27572
+ rootRow.constructorArgs = {};
27573
+ }
27574
+ rootRow.instanceAppliedVariantId = selection.variantId;
27575
+ rootRow.instanceAppliedVariantRowValueId = selection.rowValueId;
27576
+ }
27510
27577
  function constructDeclaredClassValue(info, scope, ctx) {
27511
27578
  const descriptor = validateClassConstructorDescriptor(info, ctx, false);
27512
27579
  const schemaClass2 = descriptor.schemaClass;
@@ -27589,6 +27656,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record4, info, scope
27589
27656
  );
27590
27657
  }
27591
27658
  const rootRecord = root.value;
27659
+ recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
27592
27660
  if (record4 !== null) {
27593
27661
  const encoded = {};
27594
27662
  for (let index = 0; index < argumentValues.length; index += 1) {
@@ -27629,7 +27697,6 @@ function constructDeclaredClassValueWithinFrame(descriptor, record4, info, scope
27629
27697
  }
27630
27698
  const argumentsByValue = ctx.__constructedArgumentsByValue ?? (ctx.__constructedArgumentsByValue = /* @__PURE__ */ new WeakMap());
27631
27699
  argumentsByValue.set(rootRecord, encoded);
27632
- recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
27633
27700
  root.constructorArgs = deepClonePlainData(encoded);
27634
27701
  root.instanceConstructorId = record4.id;
27635
27702
  } else {
@@ -28022,7 +28089,7 @@ function cloneConstructorArgumentGraph(args) {
28022
28089
  member.classArguments,
28023
28090
  args.ctx.vm.classes
28024
28091
  );
28025
- const record4 = {};
28092
+ const record4 = /* @__PURE__ */ Object.create(null);
28026
28093
  clone.value = record4;
28027
28094
  const sourceRecord = {
28028
28095
  ...virtualExpandedRecordForReceiver(source.value, args.ctx),
@@ -28066,7 +28133,7 @@ function cloneConstructorArgumentGraph(args) {
28066
28133
  `Constructor import references missing Dictionary entry member '${member.entryMemberId}'.`
28067
28134
  );
28068
28135
  }
28069
- const record4 = {};
28136
+ const record4 = /* @__PURE__ */ Object.create(null);
28070
28137
  clone.value = record4;
28071
28138
  const entryEnv = envFromStamp(clone.genericBindings);
28072
28139
  for (const [key, childId] of Object.entries(source.value)) {
@@ -28309,7 +28376,7 @@ function materializeConstructorArgumentValue(args) {
28309
28376
  args.ctx.vm.members
28310
28377
  );
28311
28378
  const row = registerConstructorArgumentRow(args, {});
28312
- const record4 = {};
28379
+ const record4 = /* @__PURE__ */ Object.create(null);
28313
28380
  for (const [key, rawEntry] of Object.entries(args.value)) {
28314
28381
  const entry = constructorCollectionEntryValue(
28315
28382
  rawEntry,
@@ -32312,12 +32379,7 @@ function materializeInitializerValue(args) {
32312
32379
  value: evaluated.value,
32313
32380
  ...evaluated.classId === null ? {} : { classId: evaluated.classId },
32314
32381
  ...evaluated.genericBindings === void 0 ? {} : { genericBindings: { ...evaluated.genericBindings } },
32315
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
32316
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
32317
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
32318
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
32319
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
32320
- }
32382
+ ...deepClonePlainData(pickInstanceProvenance(evaluated))
32321
32383
  };
32322
32384
  const allCreated = [root, ...createdValues];
32323
32385
  if (evaluated.provisionalRootId !== void 0) {
@@ -32340,7 +32402,8 @@ function materializeInitializerValue(args) {
32340
32402
  return {
32341
32403
  root,
32342
32404
  createdValues,
32343
- pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set()
32405
+ pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set(),
32406
+ pinnedSchemaKeysByValueId: evaluated.pinnedSchemaKeysByValueId ?? /* @__PURE__ */ new Map()
32344
32407
  };
32345
32408
  }
32346
32409
  function materializeMemberDefaultValue(args) {
@@ -32457,7 +32520,12 @@ function materializeMemberDefaultValue(args) {
32457
32520
  storageKeyDeclarations,
32458
32521
  supersededRootId: built.id
32459
32522
  });
32460
- return { root, createdValues: interior, pinnedRootSchemaKeys: /* @__PURE__ */ new Set() };
32523
+ return {
32524
+ root,
32525
+ createdValues: interior,
32526
+ pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
32527
+ pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
32528
+ };
32461
32529
  }
32462
32530
 
32463
32531
  // ../packages/neoscript-runtime/src/virtual-instance-graph.ts
@@ -32487,6 +32555,7 @@ function buildVirtualInstanceMaterializedIndex(args) {
32487
32555
  })
32488
32556
  };
32489
32557
  }
32558
+ var KEPT_ROW_SAMPLE_LIMIT = 12;
32490
32559
  function derivesContentFromMemberDefault(args) {
32491
32560
  const member = args.member;
32492
32561
  if (!isMemberClassBase(member)) return false;
@@ -32639,6 +32708,8 @@ function expandStoredInstance(args) {
32639
32708
  instanceConstructorId: _instanceConstructorId,
32640
32709
  instanceVariantId: _instanceVariantId,
32641
32710
  instanceVariantRowValueId: _instanceVariantRowValueId,
32711
+ instanceAppliedVariantId: _instanceAppliedVariantId,
32712
+ instanceAppliedVariantRowValueId: _instanceAppliedVariantRowValueId,
32642
32713
  ...envelope
32643
32714
  } = instanceRoot;
32644
32715
  void _value;
@@ -32647,6 +32718,8 @@ function expandStoredInstance(args) {
32647
32718
  void _instanceConstructorId;
32648
32719
  void _instanceVariantId;
32649
32720
  void _instanceVariantRowValueId;
32721
+ void _instanceAppliedVariantId;
32722
+ void _instanceAppliedVariantRowValueId;
32650
32723
  const closedRootMember = closeClassArgumentsFromRowStamp(
32651
32724
  rootMember,
32652
32725
  instanceRoot
@@ -32728,11 +32801,26 @@ function expandStoredInstance(args) {
32728
32801
  }
32729
32802
  };
32730
32803
  };
32731
- const materialized = derivesContentFromMemberDefault({
32804
+ const constructed = derivesContentFromMemberDefault({
32732
32805
  member: replayMember,
32733
32806
  instanceRoot,
32734
32807
  effectiveClassId: classId
32735
32808
  }) ? replayDeclaredDefault() : replay([]);
32809
+ const appliedVariantId = instanceRoot.instanceAppliedVariantId;
32810
+ const materialized = typeof appliedVariantId !== "string" ? constructed : trackMaterialization(
32811
+ () => replayAppliedVariant({
32812
+ evaluateInitializer: args.evaluateInitializer,
32813
+ document: args.document,
32814
+ member: replayMember,
32815
+ constructed,
32816
+ classId,
32817
+ variantId: appliedVariantId,
32818
+ variantRowValueId: instanceRoot.instanceAppliedVariantRowValueId ?? null,
32819
+ ...readTracking === void 0 ? {} : { readTracking },
32820
+ saveStaticBindings: args.saveStaticBindings,
32821
+ sessionStaticBindings: args.sessionStaticBindings
32822
+ })
32823
+ );
32736
32824
  const rows = [materialized.root, ...materialized.createdValues];
32737
32825
  assertVirtualExpansionIsLiteral(rows);
32738
32826
  return {
@@ -32741,6 +32829,80 @@ function expandStoredInstance(args) {
32741
32829
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
32742
32830
  };
32743
32831
  }
32832
+ function replayAppliedVariant(args) {
32833
+ const rootId = args.constructed.root.id;
32834
+ const sessionValues = /* @__PURE__ */ new Map();
32835
+ sessionValues.set(rootId, args.constructed.root);
32836
+ for (const row of args.constructed.createdValues)
32837
+ sessionValues.set(row.id, row);
32838
+ const variant2 = args.document.databaseVM?.variantById?.(args.variantId) ?? args.document.variants?.find((entry) => entry.id === args.variantId);
32839
+ const variantClassId = variant2?.classId ?? args.classId;
32840
+ const schemaClassInfo = {
32841
+ type: 7 /* Class */,
32842
+ required: true,
32843
+ classId: args.classId
32844
+ };
32845
+ args.evaluateInitializer({
32846
+ init: {
32847
+ code: `virtual-applied-variant:${rootId}`,
32848
+ compiled: {
32849
+ compilerRevision: NEOSCRIPT_COMPILER_REVISION,
32850
+ parameters: evaluatorEnvelopeParameters(),
32851
+ instructions: [
32852
+ {
32853
+ type: "return" /* return */,
32854
+ pointer: {
32855
+ type: "function" /* function */,
32856
+ function: {
32857
+ type: "variantApply" /* variantApply */,
32858
+ info: {
32859
+ receiverPointer: {
32860
+ type: "reference" /* reference */,
32861
+ valueId: rootId
32862
+ },
32863
+ variantPointer: {
32864
+ type: "variant" /* variant */,
32865
+ classId: variantClassId,
32866
+ variantId: args.variantId,
32867
+ rowValueId: args.variantRowValueId
32868
+ },
32869
+ schemaClassInfo,
32870
+ declarativeReplay: true
32871
+ }
32872
+ }
32873
+ }
32874
+ }
32875
+ ],
32876
+ typeInfo: schemaClassInfo
32877
+ }
32878
+ },
32879
+ member: args.member,
32880
+ document: args.document,
32881
+ createdValues: [],
32882
+ sessionValues,
32883
+ storedConstructionReplay: true,
32884
+ sourceValueId: rootId,
32885
+ ...args.readTracking === void 0 ? {} : { readTracking: args.readTracking },
32886
+ saveStaticBindings: args.saveStaticBindings,
32887
+ sessionStaticBindings: args.sessionStaticBindings
32888
+ });
32889
+ const root = sessionValues.get(rootId);
32890
+ if (root === void 0) {
32891
+ throw new Error(
32892
+ `Applied variant "${args.variantId}" replay lost instance root "${rootId}".`
32893
+ );
32894
+ }
32895
+ sessionValues.delete(rootId);
32896
+ return {
32897
+ ...args.constructed,
32898
+ root: {
32899
+ ...root,
32900
+ instanceAppliedVariantId: args.variantId,
32901
+ instanceAppliedVariantRowValueId: args.variantRowValueId
32902
+ },
32903
+ createdValues: [...sessionValues.values()]
32904
+ };
32905
+ }
32744
32906
  function resolveVirtualInstanceGraph(args) {
32745
32907
  const expansion = args.expansionIndex ?? indexExpansion(args);
32746
32908
  const recorder = args.readRecorder ?? null;
@@ -33559,6 +33721,11 @@ function expandStoredClassValue(args) {
33559
33721
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
33560
33722
  };
33561
33723
  }
33724
+ function owningInstanceRootId(graph) {
33725
+ let owner = graph;
33726
+ while (owner?.containingGraph !== void 0) owner = owner.containingGraph;
33727
+ return owner?.instanceRootId ?? null;
33728
+ }
33562
33729
  function isStoredClassResolutionRoot(value) {
33563
33730
  if (!isLiteralValueContent(value)) return false;
33564
33731
  if (isVirtualInstanceRootShape(value)) return true;
@@ -33648,6 +33815,393 @@ function planVirtualOverrideResets(args) {
33648
33815
  });
33649
33816
  return { deletes, updates };
33650
33817
  }
33818
+ function planCollapseVirtualInstance(args) {
33819
+ const protectedIds = args.protectedValueIds ?? /* @__PURE__ */ new Set();
33820
+ const pinnedIds = args.pinnedValueIds ?? /* @__PURE__ */ new Set();
33821
+ const deleteIds = /* @__PURE__ */ new Set();
33822
+ const pairingMismatchIds = /* @__PURE__ */ new Set();
33823
+ const updates = [];
33824
+ const subtreeFacts = /* @__PURE__ */ new Map();
33825
+ const stampsByPath = /* @__PURE__ */ new Map();
33826
+ const reproducibleByPath = /* @__PURE__ */ new Map();
33827
+ const isReproduciblePath = (location) => {
33828
+ const cached = reproducibleByPath.get(location.pathKey);
33829
+ if (cached !== void 0) return cached;
33830
+ reproducibleByPath.set(location.pathKey, false);
33831
+ const reproducible = computeReproduciblePath(location);
33832
+ reproducibleByPath.set(location.pathKey, reproducible);
33833
+ return reproducible;
33834
+ };
33835
+ const nestedRootIds = args.nestedRootValueIds ?? /* @__PURE__ */ new Set();
33836
+ const isNestedRoot = (valueId) => valueId !== args.graph.root.id && nestedRootIds.has(valueId);
33837
+ const ownsChildInterior = (child) => {
33838
+ const stored = child.materializedRow;
33839
+ if (stored === null) return true;
33840
+ if (isNestedRoot(stored.id)) return false;
33841
+ if (!isLiteralValueContent(stored)) return true;
33842
+ const provenance = args.graph.compareCreationProvenance(child);
33843
+ if (!provenance.sameType) return false;
33844
+ if (provenance.sameRecipe) return true;
33845
+ if (typeof stored.instanceConstructorId === "string") return false;
33846
+ if (typeof stored.instanceVariantId === "string") return false;
33847
+ if (typeof stored.instanceAppliedVariantId === "string") return false;
33848
+ const storedArgs = stored.constructorArgs;
33849
+ if (storedArgs != null && Object.keys(storedArgs).length > 0) return false;
33850
+ return !isInitValueContent(child.member.defaultValue);
33851
+ };
33852
+ const valuesById = args.valuesById ?? /* @__PURE__ */ new Map();
33853
+ const frameDerivedLineages = /* @__PURE__ */ new Set();
33854
+ for (const location of args.graph.locationsByPath.values()) {
33855
+ const derived = location.virtualRow.sourceValueId;
33856
+ if (typeof derived === "string") frameDerivedLineages.add(derived);
33857
+ }
33858
+ const ownsLineageByPath = /* @__PURE__ */ new Map();
33859
+ const frameOwnsLineage = (location) => {
33860
+ const cached = ownsLineageByPath.get(location.pathKey);
33861
+ if (cached !== void 0) return cached;
33862
+ ownsLineageByPath.set(location.pathKey, true);
33863
+ let owns = true;
33864
+ let parentPath = parentPathKey(location.pathKey);
33865
+ while (parentPath !== null) {
33866
+ const ancestor = args.graph.locationsByPath.get(parentPath);
33867
+ if (ancestor === void 0) break;
33868
+ const ancestorId = ancestor.materializedRow?.id;
33869
+ if (ancestorId !== void 0 && isNestedRoot(ancestorId)) {
33870
+ owns = false;
33871
+ break;
33872
+ }
33873
+ parentPath = parentPathKey(parentPath);
33874
+ }
33875
+ ownsLineageByPath.set(location.pathKey, owns);
33876
+ return owns;
33877
+ };
33878
+ const isCrossFrameLineageRecord = (location, stored) => {
33879
+ const storedSource = stored.sourceValueId ?? null;
33880
+ if (storedSource === null) return false;
33881
+ if (storedSource === stored.id) return false;
33882
+ if (frameDerivedLineages.has(storedSource)) return false;
33883
+ const named = valuesById.get(storedSource);
33884
+ if (named === void 0) return false;
33885
+ if (!isLiteralValueContent(stored)) return false;
33886
+ if (!isLiteralValueContent(named)) {
33887
+ return args.graph.compareLeafContent(location);
33888
+ }
33889
+ return semanticEqual(
33890
+ normalizeLeafPayload(named, location.member),
33891
+ normalizeLeafPayload(stored, location.member)
33892
+ );
33893
+ };
33894
+ const computeReproduciblePath = (location) => {
33895
+ const segment = location.parentSegment;
33896
+ if (segment === null || location.pathKey === ROOT_PATH) return true;
33897
+ const parentPath = parentPathKey(location.pathKey);
33898
+ if (parentPath === null) return true;
33899
+ const parent = args.graph.locationsByPath.get(parentPath);
33900
+ if (parent === void 0) return false;
33901
+ if (!isReproduciblePath(parent)) return false;
33902
+ if (!isMemberEntryCollectionBase(parent.member)) return true;
33903
+ if (listKindOf(parent.member) !== 1 /* Unordered */) return true;
33904
+ return unorderedEntryMatchedByProvenance(location);
33905
+ };
33906
+ const normalizedStoredRow = (location, stored) => {
33907
+ const cached = stampsByPath.get(location.pathKey);
33908
+ if (cached !== void 0) return withLegacyLineage(stored, cached);
33909
+ const stamp = settleLineage(stored, location.virtualRow, {
33910
+ reproduciblePosition: isReproduciblePath(location),
33911
+ frameOwnsLineage: frameOwnsLineage(location),
33912
+ crossFrameRecord: isCrossFrameLineageRecord(location, stored)
33913
+ });
33914
+ stampsByPath.set(location.pathKey, stamp);
33915
+ return withLegacyLineage(stored, stamp);
33916
+ };
33917
+ const compareSubtree = (location) => {
33918
+ const cached = subtreeFacts.get(location.pathKey);
33919
+ if (cached !== void 0) return cached;
33920
+ const stored = location.materializedRow;
33921
+ if (stored !== null && isInitValueContent(stored)) {
33922
+ const result2 = {
33923
+ defaultEqual: false,
33924
+ contentEqual: false,
33925
+ protected: true
33926
+ };
33927
+ subtreeFacts.set(location.pathKey, result2);
33928
+ return result2;
33929
+ }
33930
+ const real = stored === null ? null : normalizedStoredRow(location, stored);
33931
+ if (real === null) {
33932
+ const result2 = {
33933
+ defaultEqual: true,
33934
+ contentEqual: true,
33935
+ protected: false
33936
+ };
33937
+ subtreeFacts.set(location.pathKey, result2);
33938
+ return result2;
33939
+ }
33940
+ let protectedSubtree = protectedIds.has(real.id) || pinnedIds.has(real.id) || args.removableValueIds !== void 0 && !args.removableValueIds.has(real.id) || location.parentId === args.graph.root.id && location.parentSegment?.kind === "class" && args.graph.pinnedRootSchemaKeys?.has(
33941
+ location.parentSegment.schemaKey
33942
+ ) === true;
33943
+ const ownsLineage = frameOwnsLineage(location);
33944
+ const pairingMismatch = provenancePairingDisagrees(
33945
+ real,
33946
+ location.virtualRow,
33947
+ {
33948
+ reproduciblePosition: isReproduciblePath(location),
33949
+ frameOwnsLineage: true,
33950
+ crossFrameRecord: isCrossFrameLineageRecord(location, real)
33951
+ }
33952
+ );
33953
+ let defaultEqual = !pairingMismatch && args.graph.compareCreationProvenance(location).sameRecipe;
33954
+ let contentEqual = true;
33955
+ const storedIsNull = real.value === null;
33956
+ const virtualIsNull = location.virtualRow.value === null;
33957
+ if (storedIsNull || virtualIsNull) {
33958
+ defaultEqual &&= storedIsNull && virtualIsNull;
33959
+ contentEqual &&= storedIsNull && virtualIsNull;
33960
+ } else if (isMemberClassBase(location.member)) {
33961
+ for (const schemaKey of Object.keys(stringRecord(real.value))) {
33962
+ const child = args.graph.locationsByPath.get(
33963
+ appendVirtualValuePath(location.pathKey, {
33964
+ kind: "class",
33965
+ schemaKey
33966
+ })
33967
+ );
33968
+ if (child === void 0) {
33969
+ defaultEqual = false;
33970
+ contentEqual = false;
33971
+ continue;
33972
+ }
33973
+ const facts = compareSubtree(child);
33974
+ defaultEqual &&= facts.defaultEqual;
33975
+ contentEqual &&= facts.contentEqual;
33976
+ protectedSubtree ||= facts.protected;
33977
+ }
33978
+ } else if (isMemberEntryCollectionBase(location.member)) {
33979
+ if (listKindOf(location.member) === 1 /* Unordered */) {
33980
+ protectedSubtree = true;
33981
+ const storedEntries = args.graph.materializedUnorderedEntryIdsByContainerId.get(real.id) ?? [];
33982
+ const virtualEntries = args.graph.expandedChildPathsByParentPath.get(location.pathKey) ?? [];
33983
+ const resolvedEntries = args.graph.childPathsByParentPath.get(location.pathKey) ?? [];
33984
+ const storedIsArray = Array.isArray(real.value);
33985
+ const virtualIsArray = Array.isArray(location.virtualRow.value);
33986
+ const entryCountsAgree = storedEntries.length === virtualEntries.length && resolvedEntries.length === storedEntries.length;
33987
+ defaultEqual &&= storedIsArray;
33988
+ defaultEqual &&= virtualIsArray;
33989
+ defaultEqual &&= entryCountsAgree;
33990
+ contentEqual &&= storedIsArray;
33991
+ contentEqual &&= virtualIsArray;
33992
+ contentEqual &&= entryCountsAgree;
33993
+ const resolvedStoredIds = [];
33994
+ for (const childPath of resolvedEntries) {
33995
+ const child = args.graph.locationsByPath.get(childPath);
33996
+ if (child?.materializedRow === null || child === void 0) {
33997
+ defaultEqual = false;
33998
+ contentEqual = false;
33999
+ continue;
34000
+ }
34001
+ resolvedStoredIds.push(child.materializedRow.id);
34002
+ const facts = compareSubtree(child);
34003
+ defaultEqual &&= facts.defaultEqual;
34004
+ contentEqual &&= facts.contentEqual;
34005
+ }
34006
+ const membershipEqual = semanticEqual(
34007
+ resolvedStoredIds.sort(),
34008
+ [...storedEntries].sort()
34009
+ );
34010
+ defaultEqual &&= membershipEqual;
34011
+ contentEqual &&= membershipEqual;
34012
+ } else {
34013
+ const stored2 = Array.isArray(real.value) ? real.value : null;
34014
+ const virtual = Array.isArray(location.virtualRow.value) ? location.virtualRow.value : null;
34015
+ const bothArrays = stored2 !== null && virtual !== null;
34016
+ const lengthsAgree = stored2?.length === virtual?.length;
34017
+ defaultEqual &&= bothArrays;
34018
+ defaultEqual &&= lengthsAgree;
34019
+ contentEqual &&= bothArrays;
34020
+ contentEqual &&= lengthsAgree;
34021
+ for (let index = 0; index < (stored2?.length ?? 0); index += 1) {
34022
+ if (stored2?.[index] === null && virtual?.[index] === null) continue;
34023
+ const child = args.graph.locationsByPath.get(
34024
+ appendVirtualValuePath(location.pathKey, { kind: "list", index })
34025
+ );
34026
+ if (child === void 0) {
34027
+ defaultEqual = false;
34028
+ contentEqual = false;
34029
+ continue;
34030
+ }
34031
+ const facts = compareSubtree(child);
34032
+ defaultEqual &&= facts.defaultEqual;
34033
+ contentEqual &&= facts.contentEqual;
34034
+ protectedSubtree ||= facts.protected;
34035
+ }
34036
+ }
34037
+ } else if (isMemberDictionaryBase(location.member)) {
34038
+ const stored2 = stringRecord(real.value);
34039
+ const virtual = stringRecord(location.virtualRow.value);
34040
+ const keysEqual = semanticEqual(
34041
+ Object.keys(stored2).sort(),
34042
+ Object.keys(virtual).sort()
34043
+ );
34044
+ defaultEqual &&= keysEqual;
34045
+ contentEqual &&= keysEqual;
34046
+ for (const key of Object.keys(stored2)) {
34047
+ const child = args.graph.locationsByPath.get(
34048
+ appendVirtualValuePath(location.pathKey, { kind: "dictionary", key })
34049
+ );
34050
+ if (child === void 0) {
34051
+ defaultEqual = false;
34052
+ contentEqual = false;
34053
+ continue;
34054
+ }
34055
+ const facts = compareSubtree(child);
34056
+ defaultEqual &&= facts.defaultEqual;
34057
+ contentEqual &&= facts.contentEqual;
34058
+ protectedSubtree ||= facts.protected;
34059
+ }
34060
+ } else {
34061
+ const leafEqual = args.graph.compareLeafContent(location);
34062
+ defaultEqual &&= leafEqual;
34063
+ contentEqual &&= leafEqual;
34064
+ }
34065
+ const result = { defaultEqual, contentEqual, protected: protectedSubtree };
34066
+ if (pairingMismatch && ownsLineage && contentEqual) {
34067
+ pairingMismatchIds.add(real.id);
34068
+ }
34069
+ subtreeFacts.set(location.pathKey, result);
34070
+ return result;
34071
+ };
34072
+ const deleteSubtree = (location) => {
34073
+ const descendants = [];
34074
+ const pending = [location.pathKey];
34075
+ while (pending.length > 0) {
34076
+ const path = pending.pop();
34077
+ if (path === void 0) continue;
34078
+ const candidate = args.graph.locationsByPath.get(path);
34079
+ if (candidate !== void 0) descendants.push(candidate);
34080
+ for (const childPath of args.graph.childPathsByParentPath.get(path) ?? []) {
34081
+ pending.push(childPath);
34082
+ }
34083
+ }
34084
+ descendants.sort(
34085
+ (left, right) => pathDepth(right.pathKey) - pathDepth(left.pathKey)
34086
+ );
34087
+ for (const candidate of descendants) {
34088
+ if (candidate.materializedRow !== null) {
34089
+ deleteIds.add(candidate.materializedRow.id);
34090
+ }
34091
+ }
34092
+ };
34093
+ const sparsifyClass = (location) => {
34094
+ const real = location.materializedRow;
34095
+ if (real === null || isInitValueContent(real) || !isMemberClassBase(location.member))
34096
+ return;
34097
+ const stored = stringRecord(real.value);
34098
+ const next = {};
34099
+ for (const [schemaKey, childId] of Object.entries(stored)) {
34100
+ const child = args.graph.locationsByPath.get(
34101
+ appendVirtualValuePath(location.pathKey, { kind: "class", schemaKey })
34102
+ );
34103
+ if (child === void 0) {
34104
+ next[schemaKey] = childId;
34105
+ continue;
34106
+ }
34107
+ const facts = compareSubtree(child);
34108
+ if (facts.defaultEqual && !facts.protected) {
34109
+ deleteSubtree(child);
34110
+ continue;
34111
+ }
34112
+ next[schemaKey] = child.materializedRow?.id ?? childId;
34113
+ if (!isMemberClassBase(child.member)) continue;
34114
+ if (!ownsChildInterior(child)) continue;
34115
+ sparsifyClass(child);
34116
+ }
34117
+ if (!semanticEqual(stored, next)) {
34118
+ updates.push({ valueId: real.id, value: next });
34119
+ }
34120
+ };
34121
+ const stampSurvivingRow = (valueId, pathKey) => {
34122
+ const stamp = stampsByPath.get(pathKey);
34123
+ if (stamp === void 0) return;
34124
+ if (stampIsEmpty(stamp)) return;
34125
+ const sourceValueId = stamp.clearSourceValueId ? null : stamp.sourceValueId;
34126
+ const existing = updates.find((update) => update.valueId === valueId);
34127
+ if (existing !== void 0) {
34128
+ if (sourceValueId !== null || stamp.clearSourceValueId) {
34129
+ existing.sourceValueId = sourceValueId;
34130
+ }
34131
+ return;
34132
+ }
34133
+ const location = args.graph.locationsById.get(valueId);
34134
+ const stored = location?.materializedRow;
34135
+ if (stored === void 0 || stored === null) return;
34136
+ updates.push({
34137
+ valueId,
34138
+ // Payload untouched: this update exists to carry lineage. The corpus
34139
+ // planner drops a change whose row is byte-identical, so a re-run over an
34140
+ // already-corrected row produces nothing.
34141
+ value: stored.value,
34142
+ ...sourceValueId === null && !stamp.clearSourceValueId ? {} : { sourceValueId }
34143
+ });
34144
+ };
34145
+ sparsifyClass(args.graph.root);
34146
+ const deletes = [...deleteIds].sort((left, right) => {
34147
+ const leftLocation = args.graph.locationsById.get(left);
34148
+ const rightLocation = args.graph.locationsById.get(right);
34149
+ return pathDepth(rightLocation?.pathKey ?? ROOT_PATH) - pathDepth(leftLocation?.pathKey ?? ROOT_PATH);
34150
+ });
34151
+ const locatedRows = [];
34152
+ for (const location of args.graph.locationsByPath.values()) {
34153
+ if (location.pathKey === ROOT_PATH) continue;
34154
+ const row = location.materializedRow;
34155
+ if (row === null) continue;
34156
+ locatedRows.push({ id: row.id, pathKey: location.pathKey });
34157
+ }
34158
+ locatedRows.sort((left, right) => left.pathKey.localeCompare(right.pathKey));
34159
+ const materializedNonRoot = [];
34160
+ const seenIds = /* @__PURE__ */ new Set();
34161
+ for (const entry of locatedRows) {
34162
+ if (seenIds.has(entry.id)) continue;
34163
+ seenIds.add(entry.id);
34164
+ materializedNonRoot.push(entry);
34165
+ }
34166
+ const keptRowReasons = /* @__PURE__ */ new Map();
34167
+ const breakdown = { content: 0, provenanceOnly: 0, pinnedOrReference: 0 };
34168
+ const provenanceOnlySampleIds = [];
34169
+ const contentSampleIds = [];
34170
+ let keptReferenceTargetRows = 0;
34171
+ for (const entry of materializedNonRoot) {
34172
+ if (protectedIds.has(entry.id)) keptReferenceTargetRows += 1;
34173
+ if (deleteIds.has(entry.id)) continue;
34174
+ if (args.removableValueIds === void 0)
34175
+ stampSurvivingRow(entry.id, entry.pathKey);
34176
+ const reason = keptRowReason(subtreeFacts.get(entry.pathKey));
34177
+ keptRowReasons.set(entry.id, reason);
34178
+ breakdown[reason] += 1;
34179
+ if (reason === "provenanceOnly" && provenanceOnlySampleIds.length < KEPT_ROW_SAMPLE_LIMIT) {
34180
+ provenanceOnlySampleIds.push(entry.id);
34181
+ }
34182
+ if (reason === "content" && contentSampleIds.length < KEPT_ROW_SAMPLE_LIMIT) {
34183
+ contentSampleIds.push(entry.id);
34184
+ }
34185
+ }
34186
+ return {
34187
+ deletes,
34188
+ updates,
34189
+ deletedDefaultEqualRows: deletes.length,
34190
+ keptOverrideRows: keptRowReasons.size,
34191
+ keptReferenceTargetRows,
34192
+ pairingMismatchValueIds: [...pairingMismatchIds].sort(),
34193
+ keptRowBreakdown: breakdown,
34194
+ provenanceOnlySampleIds,
34195
+ contentSampleIds,
34196
+ keptRowReasons
34197
+ };
34198
+ }
34199
+ function keptRowReason(facts) {
34200
+ if (facts === void 0) return "content";
34201
+ if (!facts.contentEqual) return "content";
34202
+ if (!facts.defaultEqual) return "provenanceOnly";
34203
+ return "pinnedOrReference";
34204
+ }
33651
34205
  function closeClassArgumentsFromRowStamp(member, row) {
33652
34206
  if (!isMemberClassBase(member)) return member;
33653
34207
  const stamp = row.genericBindings;
@@ -33986,7 +34540,9 @@ function compareContextualCreationProvenance(left, right, context) {
33986
34540
  constructorArgs: literal3.constructorArgs ?? {},
33987
34541
  instanceConstructorId: literal3.instanceConstructorId ?? null,
33988
34542
  instanceVariantId: literal3.instanceVariantId ?? null,
33989
- instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null
34543
+ instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null,
34544
+ instanceAppliedVariantId: literal3.instanceAppliedVariantId ?? null,
34545
+ instanceAppliedVariantRowValueId: literal3.instanceAppliedVariantRowValueId ?? null
33990
34546
  };
33991
34547
  };
33992
34548
  return {
@@ -33997,10 +34553,80 @@ function compareContextualCreationProvenance(left, right, context) {
33997
34553
  )
33998
34554
  };
33999
34555
  }
34556
+ var SYNTHETIC_LINEAGE_PREFIXES = ["missing-expansion:", "path:"];
34557
+ function unorderedEntryMatchedByProvenance(location) {
34558
+ const storedSource = location.materializedRow?.sourceValueId ?? null;
34559
+ if (storedSource === null) return false;
34560
+ return storedSource === (location.virtualRow.sourceValueId ?? null);
34561
+ }
34562
+ function adoptableLineage(stored, expanded, reproduciblePosition) {
34563
+ if (!reproduciblePosition) return null;
34564
+ const expandedSource = expanded.sourceValueId ?? null;
34565
+ if (expandedSource === null) return null;
34566
+ if (expandedSource === stored.id) return null;
34567
+ if (SYNTHETIC_LINEAGE_PREFIXES.some(
34568
+ (prefix) => expandedSource.startsWith(prefix)
34569
+ )) {
34570
+ return null;
34571
+ }
34572
+ return expandedSource;
34573
+ }
34574
+ function storedLineageIsMeaningless(materialized, reproduciblePosition) {
34575
+ const storedSource = materialized.sourceValueId ?? null;
34576
+ if (storedSource === null) return false;
34577
+ if (storedSource === materialized.id) return true;
34578
+ return !reproduciblePosition;
34579
+ }
34580
+ function provenancePairingDisagrees(materialized, expanded, frame) {
34581
+ const storedSource = materialized.sourceValueId ?? null;
34582
+ if (storedSource === null) return false;
34583
+ if (!frame.frameOwnsLineage) return false;
34584
+ if (frame.crossFrameRecord) return false;
34585
+ if (storedLineageIsMeaningless(materialized, frame.reproduciblePosition)) {
34586
+ return false;
34587
+ }
34588
+ return storedSource !== (expanded.sourceValueId ?? null);
34589
+ }
34590
+ function settleLineage(stored, expanded, frame) {
34591
+ const nothing = { sourceValueId: null, clearSourceValueId: false };
34592
+ if (!frame.frameOwnsLineage) return nothing;
34593
+ const storedSource = stored.sourceValueId ?? null;
34594
+ const expandedSource = expanded.sourceValueId ?? null;
34595
+ if (storedSource === null) {
34596
+ return {
34597
+ sourceValueId: adoptableLineage(
34598
+ stored,
34599
+ expanded,
34600
+ frame.reproduciblePosition
34601
+ ),
34602
+ clearSourceValueId: false
34603
+ };
34604
+ }
34605
+ if (storedSource === expandedSource) return nothing;
34606
+ if (frame.crossFrameRecord && frame.reproduciblePosition) {
34607
+ return expandedSource === null ? { sourceValueId: null, clearSourceValueId: true } : { sourceValueId: expandedSource, clearSourceValueId: false };
34608
+ }
34609
+ if (storedLineageIsMeaningless(stored, frame.reproduciblePosition)) {
34610
+ return { sourceValueId: null, clearSourceValueId: true };
34611
+ }
34612
+ return nothing;
34613
+ }
34000
34614
  function readClassId(row) {
34001
34615
  const classId = Reflect.get(row, "classId");
34002
34616
  return typeof classId === "string" ? classId : null;
34003
34617
  }
34618
+ function stampIsEmpty(stamp) {
34619
+ return stamp.sourceValueId === null && !stamp.clearSourceValueId;
34620
+ }
34621
+ function withLegacyLineage(stored, stamp) {
34622
+ if (stampIsEmpty(stamp)) return stored;
34623
+ const next = {
34624
+ ...stored,
34625
+ ...stamp.sourceValueId === null ? {} : { sourceValueId: stamp.sourceValueId }
34626
+ };
34627
+ if (stamp.clearSourceValueId) delete next.sourceValueId;
34628
+ return next;
34629
+ }
34004
34630
  function literalRow(row) {
34005
34631
  if (!isLiteralValueContent(row)) {
34006
34632
  throw new Error(`Expected literal instance row "${row.id}".`);
@@ -34216,40 +34842,37 @@ function resolveVariantInstanceGraphForDocument(args) {
34216
34842
  rootMember,
34217
34843
  readRecorder: args.readRecorder
34218
34844
  });
34219
- const priorGraph = resolveVirtualInstanceGraph({
34845
+ let priorInstanceRoot = args.priorInstanceRoot;
34846
+ let nextInstanceRoot = args.nextInstanceRoot;
34847
+ const resolvePriorGraph = () => resolveVirtualInstanceGraph({
34220
34848
  document: document2,
34221
- instanceRoot: args.priorInstanceRoot,
34849
+ instanceRoot: priorInstanceRoot,
34222
34850
  rootMember,
34223
34851
  expandedRoot: priorExpanded.root,
34224
34852
  expandedRows: priorExpanded.rows,
34225
34853
  materializedRows: [...materializedById.values()],
34226
34854
  readRecorder: args.readRecorder
34227
34855
  });
34228
- const priorAnsweredIds = [];
34229
- const incomingAnsweredIds = [];
34230
- for (const valueId of args.answeredValueIds) {
34231
- const bucket = priorGraph.locationsById.has(valueId) ? priorAnsweredIds : incomingAnsweredIds;
34232
- bucket.push(valueId);
34233
- }
34234
34856
  const clearedValueIds = /* @__PURE__ */ new Set();
34235
- let nextInstanceRoot = args.nextInstanceRoot;
34236
- const resetAnsweredValues = (graph, valueIds) => {
34237
- if (valueIds.length === 0) return;
34238
- const reset = planVirtualOverrideResets({ graph, valueIds });
34857
+ const applyReset = (graph, reset) => {
34239
34858
  for (const valueId of reset.deletes) {
34240
34859
  clearedValueIds.add(valueId);
34241
34860
  materializedById.delete(valueId);
34242
34861
  }
34243
34862
  for (const update of reset.updates) {
34244
34863
  if (update.valueId === nextInstanceRoot.id) {
34245
- const nextRecord = { ...stringRecord(nextInstanceRoot.value) };
34246
34864
  const resetRecord = stringRecord(update.value);
34247
34865
  const priorRecord = stringRecord(graph.root.materializedRow?.value);
34248
- for (const schemaKey of Object.keys(priorRecord)) {
34249
- if (!Object.hasOwn(resetRecord, schemaKey))
34250
- delete nextRecord[schemaKey];
34251
- }
34252
- nextInstanceRoot = { ...nextInstanceRoot, value: nextRecord };
34866
+ const withoutReset = (root2) => {
34867
+ const record4 = { ...stringRecord(root2.value) };
34868
+ for (const schemaKey of Object.keys(priorRecord)) {
34869
+ if (!Object.hasOwn(resetRecord, schemaKey))
34870
+ delete record4[schemaKey];
34871
+ }
34872
+ return { ...root2, value: record4 };
34873
+ };
34874
+ priorInstanceRoot = withoutReset(literalRow(priorInstanceRoot));
34875
+ nextInstanceRoot = withoutReset(literalRow(nextInstanceRoot));
34253
34876
  }
34254
34877
  const existing = materializedById.get(update.valueId);
34255
34878
  if (existing !== void 0) {
@@ -34261,6 +34884,28 @@ function resolveVariantInstanceGraphForDocument(args) {
34261
34884
  }
34262
34885
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
34263
34886
  };
34887
+ let priorGraph = resolvePriorGraph();
34888
+ if (args.virtualCopyIds !== void 0 && args.virtualCopyIds.length > 0) {
34889
+ const collapse = planCollapseVirtualInstance({
34890
+ graph: priorGraph,
34891
+ removableValueIds: new Set(args.virtualCopyIds)
34892
+ });
34893
+ if (collapse.deletes.length > 0 || collapse.updates.length > 0) {
34894
+ applyReset(priorGraph, collapse);
34895
+ materializedById.set(priorInstanceRoot.id, priorInstanceRoot);
34896
+ priorGraph = resolvePriorGraph();
34897
+ }
34898
+ }
34899
+ const priorAnsweredIds = [];
34900
+ const incomingAnsweredIds = [];
34901
+ for (const valueId of args.answeredValueIds) {
34902
+ const bucket = priorGraph.locationsById.has(valueId) ? priorAnsweredIds : incomingAnsweredIds;
34903
+ bucket.push(valueId);
34904
+ }
34905
+ const resetAnsweredValues = (graph, valueIds) => {
34906
+ if (valueIds.length === 0) return;
34907
+ applyReset(graph, planVirtualOverrideResets({ graph, valueIds }));
34908
+ };
34264
34909
  resetAnsweredValues(priorGraph, priorAnsweredIds);
34265
34910
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
34266
34911
  const nextExpanded = expandStoredInstance({
@@ -34304,10 +34949,15 @@ function resolveVariantInstanceGraphForDocument(args) {
34304
34949
  `ToVariant failed to resolve instance root '${args.nextInstanceRoot.id}'.`
34305
34950
  );
34306
34951
  }
34952
+ const virtualValueIds = /* @__PURE__ */ new Set();
34953
+ for (const location of nextGraph.locationsById.values()) {
34954
+ if (location.materializedRow === null) virtualValueIds.add(location.id);
34955
+ }
34307
34956
  return {
34308
34957
  root,
34309
34958
  rows: [...nextGraph.rowsById.values()],
34310
- clearedValueIds: [...clearedValueIds]
34959
+ clearedValueIds: [...clearedValueIds],
34960
+ virtualValueIds: [...virtualValueIds]
34311
34961
  };
34312
34962
  }
34313
34963
  function variantSwapDeclaredMember(document2, rootValueId) {
@@ -34694,6 +35344,7 @@ function initializerEvaluatorLookups(document2, readTracking) {
34694
35344
  return resolved;
34695
35345
  },
34696
35346
  virtualInstanceRowsForValue: (receiverValueId) => databaseVM.virtualInstanceRowsForValue(receiverValueId),
35347
+ virtualInstanceRootIdForValue: (valueId) => databaseVM.virtualInstanceRootIdForValue(valueId),
34697
35348
  ...databaseVM.worldGridQueryIndex === void 0 ? {} : { worldGridQueryIndex: () => databaseVM.worldGridQueryIndex() },
34698
35349
  rowForValueReference: (value) => databaseVM.rowForValueReference?.(value) ?? null,
34699
35350
  resolveVariantInstanceGraph: (args) => {
@@ -34749,6 +35400,9 @@ function initializerEvaluatorLookups(document2, readTracking) {
34749
35400
  valueById: (id) => indexedLookups.valueById(id) ?? headlessVirtualResolver.valueById(id),
34750
35401
  rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? headlessVirtualResolver.rowForValueReference(value),
34751
35402
  virtualInstanceRowsForValue: (receiverValueId) => headlessVirtualResolver.virtualInstanceRowsForValue(receiverValueId),
35403
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(
35404
+ headlessVirtualResolver.virtualInstanceGraphForValue(valueId)
35405
+ ),
34752
35406
  recordVirtualInstanceReads: (reads, read) => headlessVirtualResolver.recordReads(reads, read),
34753
35407
  // Headless hosts still evaluate `ToVariant` during
34754
35408
  // stored-construction replay — production's variant-constructed
@@ -34871,6 +35525,7 @@ function evaluateMemberInitializer(args) {
34871
35525
  );
34872
35526
  const compiled = compileMemberInitializer(args, databaseVM);
34873
35527
  const ctx = {
35528
+ ...args.sessionValues === void 0 ? {} : { __runtimeSessionValues: args.sessionValues },
34874
35529
  debugSink: args.document.debugSink,
34875
35530
  beforeValueAllocation: args.document.beforeValueAllocation,
34876
35531
  listenerDefaultCapture: args.document.listenerDefaultCapture,
@@ -34941,10 +35596,13 @@ function evaluateMemberInitializer(args) {
34941
35596
  args.argumentValues ?? [],
34942
35597
  {
34943
35598
  exportInitializerValues: true,
34944
- initializerResult: {
34945
- member: args.member,
34946
- genericEnv: args.genericEnv
34947
- }
35599
+ // Seeded rows already hold their placement.
35600
+ ...args.sessionValues === void 0 ? {
35601
+ initializerResult: {
35602
+ member: args.member,
35603
+ genericEnv: args.genericEnv
35604
+ }
35605
+ } : {}
34948
35606
  }
34949
35607
  );
34950
35608
  } catch (error) {
@@ -34967,9 +35625,12 @@ function evaluateMemberInitializer(args) {
34967
35625
  );
34968
35626
  }
34969
35627
  const rootRow = initializerRootRow(result.value, created);
35628
+ const pinnedSchemaKeysByValueId = /* @__PURE__ */ new Map();
34970
35629
  for (const row of created) {
34971
35630
  if (row === rootRow) continue;
34972
35631
  args.createdValues.push(row);
35632
+ const keys = typeof row.value === "object" && row.value !== null ? ctx.__constructedFieldSchemaKeysByValue?.get(row.value) : void 0;
35633
+ if (keys !== void 0) pinnedSchemaKeysByValueId.set(row.id, keys);
34973
35634
  }
34974
35635
  if (rootRow === null) return { value: result.value, classId: null };
34975
35636
  const constructorArgs = (typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue?.get(result.value) : void 0) ?? // An implicit `new()` records its empty args on the row rather than in
@@ -34977,17 +35638,13 @@ function evaluateMemberInitializer(args) {
34977
35638
  // origin or the recipe reads as an unrecorded overload.
34978
35639
  rootRow.constructorArgs ?? void 0;
34979
35640
  const pinnedRootSchemaKeys = typeof result.value === "object" && result.value !== null ? ctx.__constructedFieldSchemaKeysByValue?.get(result.value) : void 0;
34980
- const provenance = pickInstanceProvenance({
34981
- constructorArgs,
34982
- instanceConstructorId: rootRow.instanceConstructorId,
34983
- instanceVariantId: rootRow.instanceVariantId,
34984
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
34985
- });
35641
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs });
34986
35642
  return {
34987
35643
  value: result.value,
34988
35644
  classId: rootRow.classId ?? null,
34989
35645
  ...rootRow.genericBindings === void 0 ? {} : { genericBindings: { ...rootRow.genericBindings } },
34990
35646
  ...pinnedRootSchemaKeys === void 0 ? {} : { pinnedRootSchemaKeys },
35647
+ ...pinnedSchemaKeysByValueId.size === 0 ? {} : { pinnedSchemaKeysByValueId },
34991
35648
  provisionalRootId: rootRow.id,
34992
35649
  ...provenance,
34993
35650
  ...provenance.constructorArgs === void 0 ? {} : {
@@ -35061,6 +35718,7 @@ function headlessVirtualInstanceLookups(document2, options = {}) {
35061
35718
  valueById: (id) => indexed.valueById(id) ?? virtual.valueById(id),
35062
35719
  rowForValueReference: (value) => indexed.rowForValueReference(value) ?? virtual.rowForValueReference(value),
35063
35720
  virtualInstanceRowsForValue: (receiverValueId) => virtual.virtualInstanceRowsForValue(receiverValueId),
35721
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(virtual.virtualInstanceGraphForValue(valueId)),
35064
35722
  // Stored-construction replay evaluates `ToVariant`, and production's
35065
35723
  // variant-constructed placements collapse through exactly this path.
35066
35724
  resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument2({
@@ -41305,7 +41963,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
41305
41963
  };
41306
41964
  }
41307
41965
  resolveDictionaryKey(expectedKey, keyAst, scope, pos, requireNonOptional, dictionaryLiteral = false) {
41308
- const key = this.resolveExpression(keyAst, scope);
41966
+ const key = this.resolveExpression(keyAst, scope, expectedKey);
41309
41967
  if (requireNonOptional && isNullable(key.type)) {
41310
41968
  throw new CompileError(
41311
41969
  `Dictionary keys must be non-optional; got ${this.describe(key.type)}`,
@@ -53768,7 +54426,6 @@ var TILE_CLASS_LEVEL_KEYS = worldSystemSchemaFieldsForKind(
53768
54426
  ).flatMap(
53769
54427
  (field) => field.mutability === 1 /* ReadOnly */ ? [field.schemaKey] : []
53770
54428
  );
53771
- var WORLD_PLACEMENT_ASSET_KIND = /* @__PURE__ */ new Map([[NeoWorldSystemClassKind.Object, NeoWorldSystemClassKind.Object]]);
53772
54429
 
53773
54430
  // ../src/database/general-function-call-ir-source-recompile.ts
53774
54431
  var VOID_ACTION_TYPE_INFO = {
@@ -58806,7 +59463,7 @@ var INITIALIZER_KEY_PLACEHOLDER = new RegExp(
58806
59463
 
58807
59464
  // ../packages/manifest/schema-contract/registry.mjs
58808
59465
  var PROJECT_SCHEMA_CONTRACT = Object.freeze({
58809
- cliVersion: "0.80.0",
59466
+ cliVersion: "0.81.1",
58810
59467
  projectFileUploadBatchSize: 32,
58811
59468
  documentRecords: {
58812
59469
  member: {
@@ -60647,7 +61304,7 @@ var SCRIPT_COLLECTION_READERS = {
60647
61304
  };
60648
61305
 
60649
61306
  // ../src/models/exports/unity-codegen-revision.ts
60650
- var UNITY_CODEGEN_REVISION = "edfd4061dffcd1a747b234cd135b99beca6f4cf1958cb69715029c5935dd7f1b";
61307
+ var UNITY_CODEGEN_REVISION = "d4026a3848848c8507d45dd54b6d31c1a0588b17b64c35e3fe9b25c89eb2fc05";
60651
61308
 
60652
61309
  // src/export-cache.ts
60653
61310
  var CACHE_BUILD = JSON.stringify([