poe-code 10.0.3 → 10.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "10.0.3",
3
+ "version": "10.0.4",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -138,7 +138,10 @@ export async function runHarnessPair(mdPath, options) {
138
138
  throw error;
139
139
  }
140
140
  await hostCallReplay.flush();
141
- if (result.ok && options.preserveSnapshotOnSuccess !== true) {
141
+ if (result.ok && result.snapshot.migration !== undefined) {
142
+ await snapshotBackend.write(result.snapshot);
143
+ }
144
+ else if (result.ok && options.preserveSnapshotOnSuccess !== true) {
142
145
  await cleanupCompletedSnapshot(snapshotBackend, snapshotPath);
143
146
  }
144
147
  const usage = usageAccumulator.snapshot();
@@ -21213,6 +21213,89 @@ function shouldIncludeTemplateRaw(record2, key, includeTemplateRaw) {
21213
21213
  return false;
21214
21214
  }
21215
21215
 
21216
+ // packages/safejs/src/snapshot/migration.ts
21217
+ function validateMigrationSemantics(value) {
21218
+ if (!["jobs-v1", "jobs-v2", "jobs-v3", "jobs-v4", "jobs-v5"].includes(value))
21219
+ throw new TypeError(
21220
+ "Migration requires a supported execution-semantics marker (jobs-v1 through jobs-v5)."
21221
+ );
21222
+ }
21223
+ function validateMigrationJournal(sourceHash, replay, hostCalls = []) {
21224
+ if (replay === void 0)
21225
+ throw new TypeError("Migration requires a complete host replay journal.");
21226
+ if (!Array.isArray(hostCalls)) throw new TypeError("Invalid migration hostCalls.");
21227
+ const journal = new HostCallJournal(sourceHash, hostCalls, void 0, replay);
21228
+ try {
21229
+ const restored = journal.snapshotReplay();
21230
+ for (const call of restored.calls) {
21231
+ if (["created", "running"].includes(call.lifecycle) && call.outcome !== void 0)
21232
+ throw new TypeError("Unresolved migration calls cannot contain a recorded outcome.");
21233
+ for (const callback of call.callbacks ?? []) {
21234
+ if (!call.functions?.includes(callback.id))
21235
+ throw new TypeError("Migration callback has no registered source function.");
21236
+ }
21237
+ }
21238
+ return restored;
21239
+ } finally {
21240
+ journal.dispose();
21241
+ }
21242
+ }
21243
+ function validateMigrationReconciliation(value, checkpointDigest, calls) {
21244
+ validateSnapshotData(value);
21245
+ const receipt = value;
21246
+ if (receipt === null || typeof receipt !== "object" || receipt.checkpointDigest !== checkpointDigest || !isCheckpointDigest(receipt.checkpointDigest))
21247
+ throw new TypeError("Migration reconciliation must identify this exact checkpoint digest.");
21248
+ if (receipt.quiescent !== true)
21249
+ throw new TypeError(
21250
+ "Migration requires explicit host confirmation that execution, operations, and callbacks are quiescent."
21251
+ );
21252
+ if (!Array.isArray(receipt.calls))
21253
+ throw new TypeError("Migration reconciliation calls must be an array.");
21254
+ const pending = new Map(
21255
+ calls.filter((call) => !["settled", "consumed"].includes(call.lifecycle)).map((call) => [call.id, call])
21256
+ );
21257
+ for (const resolution of receipt.calls) {
21258
+ if (resolution === null || typeof resolution !== "object" || !pending.has(resolution.callId))
21259
+ throw new TypeError("Migration contains an unknown or duplicate call resolution.");
21260
+ if (!["not-performed", "fulfilled", "rejected"].includes(resolution.disposition) || resolution.disposition === "fulfilled" && !Object.hasOwn(resolution, "value") || resolution.disposition === "rejected" && !Object.hasOwn(resolution, "reason"))
21261
+ throw new TypeError(
21262
+ "Migration call resolution requires a reconciled outcome or confirmed non-performance."
21263
+ );
21264
+ pending.delete(resolution.callId);
21265
+ }
21266
+ if (pending.size > 0)
21267
+ throw new TypeError(
21268
+ `Migration requires external reconciliation for: ${[...pending.keys()].join(", ")}`
21269
+ );
21270
+ }
21271
+ function validateSnapshotMigration(value, sourceHash) {
21272
+ if (value === void 0) return void 0;
21273
+ validateSnapshotData(value);
21274
+ const migration = value;
21275
+ if (migration === null || typeof migration !== "object" || migration.version !== 1 || !Array.isArray(migration.history) || migration.history.length === 0)
21276
+ throw new TypeError("Invalid snapshot migration history.");
21277
+ decodeReplayData(migration.state);
21278
+ let previousTarget;
21279
+ for (const entry of migration.history) {
21280
+ if (entry === null || typeof entry !== "object" || typeof entry.sourceHash !== "string" || entry.sourceHash.length === 0 || typeof entry.targetSourceHash !== "string" || entry.targetSourceHash.length === 0 || previousTarget !== void 0 && previousTarget !== entry.sourceHash)
21281
+ throw new TypeError("Invalid snapshot migration ancestry.");
21282
+ validateMigrationSemantics(entry.executionSemantics);
21283
+ const replay = validateMigrationJournal(entry.sourceHash, entry.replay);
21284
+ validateMigrationReconciliation(
21285
+ entry.reconciliation,
21286
+ entry.reconciliation?.checkpointDigest,
21287
+ replay.calls
21288
+ );
21289
+ previousTarget = entry.targetSourceHash;
21290
+ }
21291
+ if (previousTarget !== sourceHash)
21292
+ throw new TypeError("Migration ancestry does not match the target source.");
21293
+ return migration;
21294
+ }
21295
+ function isCheckpointDigest(value) {
21296
+ return typeof value === "string" && value.length === 64 && [...value].every((character) => "0123456789abcdef".includes(character));
21297
+ }
21298
+
21216
21299
  // packages/safejs/src/restore.ts
21217
21300
  var SnapshotMismatchError = class extends Error {
21218
21301
  actualHash;
@@ -21230,6 +21313,7 @@ var SnapshotMismatchError = class extends Error {
21230
21313
  function restore(snapshot, options) {
21231
21314
  assertSnapshotInactive(snapshot);
21232
21315
  validateDumpEnvelope(snapshot);
21316
+ validateSnapshotMigration(snapshot.migration, snapshot.sourceHash);
21233
21317
  if (snapshot.executionSemantics !== EXECUTION_SEMANTICS && (snapshot.executionSemantics !== void 0 || snapshot.promiseReplay !== void 0 || snapshot.replay !== void 0 || snapshot.initialInputs !== void 0)) {
21234
21318
  throw new SnapshotValidationError(
21235
21319
  "unsupportedVersion",
@@ -28386,6 +28470,17 @@ function run(source, options = {}) {
28386
28470
  }),
28387
28471
  ...createRegexGlobals()
28388
28472
  };
28473
+ const importMeta = deepCopyToSandbox(options.importMeta ?? {});
28474
+ if (restoredSnapshot?.migration !== void 0) {
28475
+ if (Object.hasOwn(importMeta, "migration"))
28476
+ throw new TypeError("import.meta.migration is reserved for migrated checkpoint state.");
28477
+ Object.defineProperty(importMeta, "migration", {
28478
+ value: decodeReplayData(restoredSnapshot.migration.state),
28479
+ enumerable: true,
28480
+ configurable: true,
28481
+ writable: true
28482
+ });
28483
+ }
28389
28484
  const initialInputs = prepareReplayInputs(
28390
28485
  {
28391
28486
  bindings: callerBindings,
@@ -28396,7 +28491,7 @@ function run(source, options = {}) {
28396
28491
  allowMissing: restoredSnapshot?.initialInputs !== void 0
28397
28492
  }),
28398
28493
  entryPointArgs: options.entryPointArgs === void 0 ? void 0 : deepCopyToSandbox([...options.entryPointArgs]),
28399
- importMeta: deepCopyToSandbox(options.importMeta ?? {})
28494
+ importMeta
28400
28495
  },
28401
28496
  restoredSnapshot?.initialInputs,
28402
28497
  (promise, id) => {
@@ -28461,6 +28556,7 @@ function run(source, options = {}) {
28461
28556
  });
28462
28557
  snapshotScheduler = activeSnapshotScheduler;
28463
28558
  createFailureSnapshot = () => createRunSnapshot({
28559
+ migration: restoredSnapshot?.migration,
28464
28560
  bindings: executionScope.snapshot().bindings,
28465
28561
  clock: options.clock,
28466
28562
  hostCalls: hostCalls.snapshot(),
@@ -28486,6 +28582,7 @@ function run(source, options = {}) {
28486
28582
  }
28487
28583
  const interpreterSnapshot2 = yieldPoint.snapshot();
28488
28584
  snapshot2 = createRunSnapshot({
28585
+ migration: restoredSnapshot?.migration,
28489
28586
  bindings: interpreterSnapshot2.bindings,
28490
28587
  clock: options.clock,
28491
28588
  hostCalls: hostCalls.snapshot(),
@@ -28527,6 +28624,7 @@ function run(source, options = {}) {
28527
28624
  }
28528
28625
  const interpreterSnapshot2 = yieldPoint.snapshot();
28529
28626
  snapshot2 = createRunSnapshot({
28627
+ migration: restoredSnapshot?.migration,
28530
28628
  bindings: interpreterSnapshot2.bindings,
28531
28629
  clock: options.clock,
28532
28630
  hostCalls: hostCalls.snapshot(),
@@ -28560,6 +28658,7 @@ function run(source, options = {}) {
28560
28658
  replayError = error.message;
28561
28659
  }
28562
28660
  const snapshot = createRunSnapshot({
28661
+ migration: restoredSnapshot?.migration,
28563
28662
  bindings: executionScope.snapshot().bindings,
28564
28663
  clock: options.clock,
28565
28664
  hostCalls: hostCalls.snapshot(),
@@ -28729,6 +28828,7 @@ function createRunSnapshot(input) {
28729
28828
  version: DUMP_FORMAT_VERSION,
28730
28829
  executionSemantics: EXECUTION_SEMANTICS,
28731
28830
  sourceHash: input.sourceHash,
28831
+ ...input.migration === void 0 ? {} : { migration: structuredClone(input.migration) },
28732
28832
  bindings: input.bindings,
28733
28833
  clock: input.clock?.snapshot(),
28734
28834
  ...input.hostCalls === void 0 || input.hostCalls.length === 0 ? {} : { hostCalls: input.hostCalls },
@@ -28798,6 +28898,7 @@ export {
28798
28898
  parse,
28799
28899
  parseModule,
28800
28900
  lint,
28901
+ hashSource,
28801
28902
  runResources,
28802
28903
  noopOtelSink,
28803
28904
  bindOtelSpan,
@@ -28809,15 +28910,26 @@ export {
28809
28910
  safeEndSpan,
28810
28911
  SandboxError,
28811
28912
  Budget,
28913
+ DUMP_FORMAT_VERSION,
28914
+ EXECUTION_SEMANTICS,
28915
+ serializeSafeJSSnapshot,
28812
28916
  SnapshotValidationError,
28917
+ validateSnapshotData,
28918
+ validateDumpEnvelope,
28919
+ encodeReplayData,
28813
28920
  HostOperationResumePolicyError,
28814
28921
  registerPendingHostCallPolicy,
28815
28922
  HostCallResumabilityError,
28923
+ assertSnapshotInactive,
28816
28924
  isSandboxClosure,
28817
28925
  deepCopyToSandbox,
28818
28926
  deepCopyFromSandbox,
28819
28927
  createSeededRandom,
28820
28928
  createReplayableRandom,
28929
+ validateMigrationSemantics,
28930
+ validateMigrationJournal,
28931
+ validateMigrationReconciliation,
28932
+ validateSnapshotMigration,
28821
28933
  restore,
28822
28934
  declareHostOperation,
28823
28935
  dump,
@@ -28827,4 +28939,4 @@ export {
28827
28939
  FileSnapshotBackend,
28828
28940
  run
28829
28941
  };
28830
- //# sourceMappingURL=chunk-A2XBEN3H.js.map
28942
+ //# sourceMappingURL=chunk-JLYBD3E6.js.map