poe-code 10.0.2 → 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.2",
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",
@@ -28308,6 +28392,7 @@ function run(source, options = {}) {
28308
28392
  const lifecycle = { hostCallbackDepth: 0 };
28309
28393
  const dumpController = createDumpController(lifecycle);
28310
28394
  const promiseTracker = createSandboxPromiseRejectionTracker();
28395
+ let completedSnapshot;
28311
28396
  const execute = async () => {
28312
28397
  const promiseReplay = new PromiseReplay(options.snapshot?.promiseReplay);
28313
28398
  return promiseReplayContext.run(promiseReplay, async () => {
@@ -28385,6 +28470,17 @@ function run(source, options = {}) {
28385
28470
  }),
28386
28471
  ...createRegexGlobals()
28387
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
+ }
28388
28484
  const initialInputs = prepareReplayInputs(
28389
28485
  {
28390
28486
  bindings: callerBindings,
@@ -28395,7 +28491,7 @@ function run(source, options = {}) {
28395
28491
  allowMissing: restoredSnapshot?.initialInputs !== void 0
28396
28492
  }),
28397
28493
  entryPointArgs: options.entryPointArgs === void 0 ? void 0 : deepCopyToSandbox([...options.entryPointArgs]),
28398
- importMeta: deepCopyToSandbox(options.importMeta ?? {})
28494
+ importMeta
28399
28495
  },
28400
28496
  restoredSnapshot?.initialInputs,
28401
28497
  (promise, id) => {
@@ -28460,6 +28556,7 @@ function run(source, options = {}) {
28460
28556
  });
28461
28557
  snapshotScheduler = activeSnapshotScheduler;
28462
28558
  createFailureSnapshot = () => createRunSnapshot({
28559
+ migration: restoredSnapshot?.migration,
28463
28560
  bindings: executionScope.snapshot().bindings,
28464
28561
  clock: options.clock,
28465
28562
  hostCalls: hostCalls.snapshot(),
@@ -28485,6 +28582,7 @@ function run(source, options = {}) {
28485
28582
  }
28486
28583
  const interpreterSnapshot2 = yieldPoint.snapshot();
28487
28584
  snapshot2 = createRunSnapshot({
28585
+ migration: restoredSnapshot?.migration,
28488
28586
  bindings: interpreterSnapshot2.bindings,
28489
28587
  clock: options.clock,
28490
28588
  hostCalls: hostCalls.snapshot(),
@@ -28526,6 +28624,7 @@ function run(source, options = {}) {
28526
28624
  }
28527
28625
  const interpreterSnapshot2 = yieldPoint.snapshot();
28528
28626
  snapshot2 = createRunSnapshot({
28627
+ migration: restoredSnapshot?.migration,
28529
28628
  bindings: interpreterSnapshot2.bindings,
28530
28629
  clock: options.clock,
28531
28630
  hostCalls: hostCalls.snapshot(),
@@ -28559,6 +28658,7 @@ function run(source, options = {}) {
28559
28658
  replayError = error.message;
28560
28659
  }
28561
28660
  const snapshot = createRunSnapshot({
28661
+ migration: restoredSnapshot?.migration,
28562
28662
  bindings: executionScope.snapshot().bindings,
28563
28663
  clock: options.clock,
28564
28664
  hostCalls: hostCalls.snapshot(),
@@ -28570,6 +28670,7 @@ function run(source, options = {}) {
28570
28670
  });
28571
28671
  if (replayError !== void 0) snapshot.replayError = replayError;
28572
28672
  dumpController.finalize(snapshot);
28673
+ completedSnapshot = snapshot;
28573
28674
  return {
28574
28675
  ...result2,
28575
28676
  snapshot
@@ -28606,7 +28707,17 @@ function run(source, options = {}) {
28606
28707
  const result = withRunResources(
28607
28708
  options.signal,
28608
28709
  () => withSandboxPromiseRejectionTracker(promiseTracker, execute)
28609
- );
28710
+ ).catch(async (error) => {
28711
+ if (completedSnapshot !== void 0) {
28712
+ try {
28713
+ await createSnapshotScheduler(options).write(completedSnapshot);
28714
+ } catch (snapshotError) {
28715
+ console.warn("Failed to write failure snapshot.", snapshotError);
28716
+ }
28717
+ }
28718
+ dumpController.fail(error);
28719
+ throw error;
28720
+ });
28610
28721
  return attachDumpController(result, dumpController);
28611
28722
  }
28612
28723
  async function throwIfReturnedPromiseRejected(result) {
@@ -28717,6 +28828,7 @@ function createRunSnapshot(input) {
28717
28828
  version: DUMP_FORMAT_VERSION,
28718
28829
  executionSemantics: EXECUTION_SEMANTICS,
28719
28830
  sourceHash: input.sourceHash,
28831
+ ...input.migration === void 0 ? {} : { migration: structuredClone(input.migration) },
28720
28832
  bindings: input.bindings,
28721
28833
  clock: input.clock?.snapshot(),
28722
28834
  ...input.hostCalls === void 0 || input.hostCalls.length === 0 ? {} : { hostCalls: input.hostCalls },
@@ -28786,6 +28898,7 @@ export {
28786
28898
  parse,
28787
28899
  parseModule,
28788
28900
  lint,
28901
+ hashSource,
28789
28902
  runResources,
28790
28903
  noopOtelSink,
28791
28904
  bindOtelSpan,
@@ -28797,15 +28910,26 @@ export {
28797
28910
  safeEndSpan,
28798
28911
  SandboxError,
28799
28912
  Budget,
28913
+ DUMP_FORMAT_VERSION,
28914
+ EXECUTION_SEMANTICS,
28915
+ serializeSafeJSSnapshot,
28800
28916
  SnapshotValidationError,
28917
+ validateSnapshotData,
28918
+ validateDumpEnvelope,
28919
+ encodeReplayData,
28801
28920
  HostOperationResumePolicyError,
28802
28921
  registerPendingHostCallPolicy,
28803
28922
  HostCallResumabilityError,
28923
+ assertSnapshotInactive,
28804
28924
  isSandboxClosure,
28805
28925
  deepCopyToSandbox,
28806
28926
  deepCopyFromSandbox,
28807
28927
  createSeededRandom,
28808
28928
  createReplayableRandom,
28929
+ validateMigrationSemantics,
28930
+ validateMigrationJournal,
28931
+ validateMigrationReconciliation,
28932
+ validateSnapshotMigration,
28809
28933
  restore,
28810
28934
  declareHostOperation,
28811
28935
  dump,
@@ -28815,4 +28939,4 @@ export {
28815
28939
  FileSnapshotBackend,
28816
28940
  run
28817
28941
  };
28818
- //# sourceMappingURL=chunk-RSK47E4C.js.map
28942
+ //# sourceMappingURL=chunk-JLYBD3E6.js.map