@bastani/atomic 0.9.78-alpha.1 → 0.9.79-alpha.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.
Files changed (176) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +12 -0
  3. package/dist/builtin/intercom/broker/broker.ts +198 -72
  4. package/dist/builtin/intercom/broker/client-message-validation.ts +38 -0
  5. package/dist/builtin/intercom/broker/client.ts +150 -11
  6. package/dist/builtin/intercom/broker/delivery-failure-reason.ts +1 -0
  7. package/dist/builtin/intercom/broker/departed-children.ts +23 -0
  8. package/dist/builtin/intercom/broker/hosted-session-errors.ts +188 -0
  9. package/dist/builtin/intercom/broker/hosted-sessions.ts +113 -0
  10. package/dist/builtin/intercom/broker/multinode-router.ts +7 -2
  11. package/dist/builtin/intercom/broker/presence-handler.ts +2 -1
  12. package/dist/builtin/intercom/broker/protocol-version.ts +6 -1
  13. package/dist/builtin/intercom/broker/recipient-gone-errors.ts +46 -5
  14. package/dist/builtin/intercom/broker/released-reply-errors.ts +1 -1
  15. package/dist/builtin/intercom/broker/send-handler.ts +19 -3
  16. package/dist/builtin/intercom/broker/socket-writes.ts +20 -1
  17. package/dist/builtin/intercom/hosted-session-timeout-error.ts +59 -0
  18. package/dist/builtin/intercom/index.bundle.mjs +634 -125
  19. package/dist/builtin/intercom/package.json +1 -1
  20. package/dist/builtin/intercom/types.ts +41 -3
  21. package/dist/builtin/mcp/package.json +1 -1
  22. package/dist/builtin/subagents/CHANGELOG.md +8 -0
  23. package/dist/builtin/subagents/package.json +1 -1
  24. package/dist/builtin/subagents/src/extension/index.bundle.mjs +90 -34
  25. package/dist/builtin/web-access/package.json +1 -1
  26. package/dist/builtin/workflows/CHANGELOG.md +9 -0
  27. package/dist/builtin/workflows/builtin/{chunk-89we7r4p.js → chunk-5hrzxynt.js} +1 -1
  28. package/dist/builtin/workflows/builtin/{chunk-8yfssw01.js → chunk-m56qhe4b.js} +1 -1
  29. package/dist/builtin/workflows/builtin/{chunk-wh2p4qjg.js → chunk-x8m4t2jy.js} +182 -33
  30. package/dist/builtin/workflows/builtin/goal.js +2 -2
  31. package/dist/builtin/workflows/builtin/index.js +3 -3
  32. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  33. package/dist/builtin/workflows/package.json +1 -1
  34. package/dist/builtin/workflows/src/extension/index.bundle.mjs +1243 -230
  35. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +854 -170
  36. package/dist/builtin/workflows/src/index.js +854 -170
  37. package/dist/builtin/workflows/src/local-worker-entry.mjs +854 -170
  38. package/dist/cli/startup-progress.d.ts +30 -0
  39. package/dist/cli/startup-progress.d.ts.map +1 -0
  40. package/dist/cli/startup-progress.js +78 -0
  41. package/dist/cli/startup-progress.js.map +1 -0
  42. package/dist/core/agent-session-events.d.ts.map +1 -1
  43. package/dist/core/agent-session-events.js +3 -0
  44. package/dist/core/agent-session-events.js.map +1 -1
  45. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  46. package/dist/core/agent-session-extension-bindings.js +2 -0
  47. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  48. package/dist/core/agent-session-methods.d.ts +2 -0
  49. package/dist/core/agent-session-methods.d.ts.map +1 -1
  50. package/dist/core/agent-session-methods.js.map +1 -1
  51. package/dist/core/agent-session-state.d.ts +12 -4
  52. package/dist/core/agent-session-state.d.ts.map +1 -1
  53. package/dist/core/agent-session-state.js +82 -15
  54. package/dist/core/agent-session-state.js.map +1 -1
  55. package/dist/core/agent-session.d.ts +3 -0
  56. package/dist/core/agent-session.d.ts.map +1 -1
  57. package/dist/core/agent-session.js +3 -0
  58. package/dist/core/agent-session.js.map +1 -1
  59. package/dist/core/builtin-resource-loader.d.ts.map +1 -1
  60. package/dist/core/builtin-resource-loader.js +3 -0
  61. package/dist/core/builtin-resource-loader.js.map +1 -1
  62. package/dist/core/debug.d.ts +2 -0
  63. package/dist/core/debug.d.ts.map +1 -1
  64. package/dist/core/debug.js +13 -0
  65. package/dist/core/debug.js.map +1 -1
  66. package/dist/core/export-html/ansi-to-html.d.ts +5 -0
  67. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  68. package/dist/core/export-html/ansi-to-html.js +57 -20
  69. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  70. package/dist/core/export-html/template.js +1 -1
  71. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  72. package/dist/core/export-html/tool-renderer.js +2 -3
  73. package/dist/core/export-html/tool-renderer.js.map +1 -1
  74. package/dist/core/extensions/workflow-activity-hub.d.ts +7 -0
  75. package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -1
  76. package/dist/core/extensions/workflow-activity-hub.js +104 -6
  77. package/dist/core/extensions/workflow-activity-hub.js.map +1 -1
  78. package/dist/core/keybindings.d.ts +0 -8
  79. package/dist/core/keybindings.d.ts.map +1 -1
  80. package/dist/core/keybindings.js +0 -1
  81. package/dist/core/keybindings.js.map +1 -1
  82. package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
  83. package/dist/core/mandatory-resource-loader.js +3 -0
  84. package/dist/core/mandatory-resource-loader.js.map +1 -1
  85. package/dist/core/resume/session-resume.d.ts +7 -1
  86. package/dist/core/resume/session-resume.d.ts.map +1 -1
  87. package/dist/core/resume/session-resume.js +136 -16
  88. package/dist/core/resume/session-resume.js.map +1 -1
  89. package/dist/core/session-history-index.d.ts +31 -0
  90. package/dist/core/session-history-index.d.ts.map +1 -0
  91. package/dist/core/session-history-index.js +82 -0
  92. package/dist/core/session-history-index.js.map +1 -0
  93. package/dist/core/session-manager-core.d.ts +3 -0
  94. package/dist/core/session-manager-core.d.ts.map +1 -1
  95. package/dist/core/session-manager-core.js +22 -17
  96. package/dist/core/session-manager-core.js.map +1 -1
  97. package/dist/core/session-manager-history.d.ts +3 -3
  98. package/dist/core/session-manager-history.d.ts.map +1 -1
  99. package/dist/core/session-manager-history.js +6 -5
  100. package/dist/core/session-manager-history.js.map +1 -1
  101. package/dist/core/storage/session/history-load-observer.d.ts +11 -0
  102. package/dist/core/storage/session/history-load-observer.d.ts.map +1 -0
  103. package/dist/core/storage/session/history-load-observer.js +25 -0
  104. package/dist/core/storage/session/history-load-observer.js.map +1 -0
  105. package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
  106. package/dist/core/storage/session/sql-session-store.js +6 -0
  107. package/dist/core/storage/session/sql-session-store.js.map +1 -1
  108. package/dist/core/tool-deactivation.d.ts +11 -0
  109. package/dist/core/tool-deactivation.d.ts.map +1 -0
  110. package/dist/core/tool-deactivation.js +13 -0
  111. package/dist/core/tool-deactivation.js.map +1 -0
  112. package/dist/core/tool-status.d.ts +6 -1
  113. package/dist/core/tool-status.d.ts.map +1 -1
  114. package/dist/core/tool-status.js +11 -3
  115. package/dist/core/tool-status.js.map +1 -1
  116. package/dist/extensions/llama/errors.js +1 -1
  117. package/dist/extensions/llama/errors.js.map +1 -1
  118. package/dist/extensions/llama/provider.d.ts +1 -1
  119. package/dist/extensions/llama/provider.js +1 -1
  120. package/dist/extensions/llama/provider.js.map +1 -1
  121. package/dist/main-session.d.ts +14 -2
  122. package/dist/main-session.d.ts.map +1 -1
  123. package/dist/main-session.js +42 -9
  124. package/dist/main-session.js.map +1 -1
  125. package/dist/main.d.ts.map +1 -1
  126. package/dist/main.js +4 -2
  127. package/dist/main.js.map +1 -1
  128. package/dist/modes/interactive/components/assistant-message.d.ts +6 -0
  129. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  130. package/dist/modes/interactive/components/assistant-message.js +13 -4
  131. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  132. package/dist/modes/interactive/components/task-detail.d.ts +1 -1
  133. package/dist/modes/interactive/components/task-detail.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/task-detail.js +1 -3
  135. package/dist/modes/interactive/components/task-detail.js.map +1 -1
  136. package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
  137. package/dist/modes/interactive/components/task-inspector.js +1 -7
  138. package/dist/modes/interactive/components/task-inspector.js.map +1 -1
  139. package/dist/modes/interactive/components/task-navigation.d.ts +0 -1
  140. package/dist/modes/interactive/components/task-navigation.d.ts.map +1 -1
  141. package/dist/modes/interactive/components/task-navigation.js +1 -3
  142. package/dist/modes/interactive/components/task-navigation.js.map +1 -1
  143. package/dist/modes/interactive/interactive-agent-events.js +5 -9
  144. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  145. package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
  146. package/dist/modes/interactive/interactive-deferred-startup.js +8 -5
  147. package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
  148. package/dist/modes/interactive/interactive-process-lifecycle.js +16 -10
  149. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  150. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  151. package/dist/modes/interactive/interactive-startup.js +2 -0
  152. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  153. package/dist/modes/interactive/interactive-unavailable-tools.d.ts +20 -0
  154. package/dist/modes/interactive/interactive-unavailable-tools.d.ts.map +1 -0
  155. package/dist/modes/interactive/interactive-unavailable-tools.js +40 -0
  156. package/dist/modes/interactive/interactive-unavailable-tools.js.map +1 -0
  157. package/dist/modes/interactive-engine/remote-component.js +1 -1
  158. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  159. package/docs/background-tasks.md +1 -1
  160. package/docs/extensions/api-reference.md +1 -1
  161. package/docs/extensions/events.md +2 -0
  162. package/docs/intercom/operations.md +2 -2
  163. package/docs/intercom/reference.md +12 -1
  164. package/docs/keybindings.md +2 -3
  165. package/docs/llama-cpp.md +9 -10
  166. package/docs/models/reference.md +1 -1
  167. package/docs/models-configuration.md +1 -1
  168. package/docs/sessions.md +6 -2
  169. package/docs/subagents.md +3 -1
  170. package/docs/usage.md +1 -1
  171. package/docs/workflows/operations.md +2 -2
  172. package/docs/worktree-snapshots.md +3 -1
  173. package/npm-shrinkwrap.json +32 -32
  174. package/package.json +4 -4
  175. package/schemas/keybindings.schema.json +0 -4
  176. package/schemas/models.schema.json +1 -1
@@ -114,11 +114,23 @@ function index(items, cache) {
114
114
  }
115
115
  return byId;
116
116
  }
117
+ var publishedSnapshotArrays = new WeakSet;
118
+ function markPublishedSnapshotArray(items) {
119
+ publishedSnapshotArrays.add(items);
120
+ }
121
+ function isPublishedSnapshotArray(items) {
122
+ return publishedSnapshotArrays.has(items);
123
+ }
124
+ function frozenIndex(items, cache) {
125
+ return cache.get(items) ?? (isPublishedSnapshotArray(items) || Object.isFrozen(items) ? index(items, cache) : undefined);
126
+ }
117
127
  function findSnapshotRun(runs, runId) {
118
- return Object.isFrozen(runs) ? index(runs, runIndexes).get(runId) : runs.find((run) => run.id === runId);
128
+ const byId = frozenIndex(runs, runIndexes);
129
+ return byId === undefined ? runs.find((run) => run.id === runId) : byId.get(runId);
119
130
  }
120
131
  function findSnapshotStage(stages, stageId) {
121
- return Object.isFrozen(stages) ? index(stages, stageIndexes).get(stageId) : stages.find((stage) => stage.id === stageId);
132
+ const byId = frozenIndex(stages, stageIndexes);
133
+ return byId === undefined ? stages.find((stage) => stage.id === stageId) : byId.get(stageId);
122
134
  }
123
135
 
124
136
  // dist/builtin/workflows/src/durable/prompt-reservations.ts
@@ -768,6 +780,50 @@ function flattenTruncatedString(value) {
768
780
  return value.split("").join("");
769
781
  }
770
782
 
783
+ // dist/builtin/workflows/src/shared/run-stage-index.ts
784
+ var indexes = new WeakMap;
785
+ function asksForInput(stage) {
786
+ return stage.pendingPrompt !== undefined || stage.inputRequest !== undefined || stage.status === "awaiting_input" || stage.awaitingInputSince !== undefined;
787
+ }
788
+ function isFinished(stage) {
789
+ return stage.status === "completed" || stage.status === "failed" || stage.status === "skipped";
790
+ }
791
+ function indexFrom(stages, asking, unfinished) {
792
+ const pending = [];
793
+ const waiting = [];
794
+ for (const position of unfinished) {
795
+ const stage = stages[position];
796
+ if (stage.status === "pending")
797
+ pending.push(stage);
798
+ if (asksForInput(stage))
799
+ waiting.push(stage);
800
+ }
801
+ return { index: { awaitingInput: asking > 0, pending, waiting }, asking, unfinished };
802
+ }
803
+ function indexRunFrom(run, previous, changed, appendedFrom) {
804
+ const known = indexes.get(previous);
805
+ if (known === undefined || !Object.isFrozen(run))
806
+ return;
807
+ let asking = known.asking;
808
+ const unfinished = new Set(known.unfinished);
809
+ const update = (position, before) => {
810
+ const stage = run.stages[position];
811
+ if (before !== undefined && asksForInput(before))
812
+ asking--;
813
+ if (asksForInput(stage))
814
+ asking++;
815
+ if (isFinished(stage))
816
+ unfinished.delete(position);
817
+ else
818
+ unfinished.add(position);
819
+ };
820
+ for (const position of changed)
821
+ update(position, previous.stages[position]);
822
+ for (let position = appendedFrom;position < run.stages.length; position++)
823
+ update(position, undefined);
824
+ indexes.set(run, indexFrom(run.stages, asking, [...unfinished].sort((left, right) => left - right)));
825
+ }
826
+
771
827
  // dist/builtin/workflows/src/shared/tool-payload-bounds.ts
772
828
  var TOOL_PAYLOAD_MAX_KEYS = 2048;
773
829
  var TOOL_PAYLOAD_VALUE_LIMIT = 16384;
@@ -1129,26 +1185,43 @@ function sameSourceShape(value, shape) {
1129
1185
  }
1130
1186
  return index === shape.keys.length;
1131
1187
  }
1188
+ function isSettledStage(stage) {
1189
+ return stage.status === "completed" || stage.status === "failed" || stage.status === "skipped";
1190
+ }
1132
1191
  function projectStage(stage) {
1192
+ const compact = compactStage(stage);
1193
+ deepFreezeGraphValue(compact);
1133
1194
  return {
1134
1195
  shape: sourceShape(stage),
1135
1196
  parentCount: stage.parentIds.length,
1136
1197
  toolEventCount: stage.toolEvents.length,
1137
1198
  lastToolEvent: stage.toolEvents.at(-1),
1138
1199
  noticeCount: stage.notices?.length,
1139
- compact: compactStage(stage)
1200
+ settled: isSettledStage(stage),
1201
+ compact
1140
1202
  };
1141
1203
  }
1142
1204
  function stageUnchanged(stage, projected) {
1143
1205
  return sameSourceShape(stage, projected.shape) && stage.parentIds.length === projected.parentCount && stage.toolEvents.length === projected.toolEventCount && stage.toolEvents.at(-1) === projected.lastToolEvent && stage.notices?.length === projected.noticeCount;
1144
1206
  }
1145
1207
  function projectToolNode(node) {
1146
- return { shape: sourceShape(node), parentCount: node.parentIds.length, compact: compactToolNode(node) };
1208
+ const compact = compactToolNode(node);
1209
+ deepFreezeGraphValue(compact);
1210
+ return { shape: sourceShape(node), parentCount: node.parentIds.length, compact };
1147
1211
  }
1148
1212
  function toolNodeUnchanged(node, projected) {
1149
1213
  return sameSourceShape(node, projected.shape) && node.parentIds.length === projected.parentCount;
1150
1214
  }
1151
-
1215
+ function freezeCompactRun(run) {
1216
+ for (const [key, value] of Object.entries(run)) {
1217
+ if (key === "stages" || key === "toolNodes")
1218
+ markPublishedSnapshotArray(value);
1219
+ else
1220
+ deepFreezeGraphValue(value);
1221
+ }
1222
+ Object.freeze(run);
1223
+ }
1224
+ var snapshotLineages = new WeakMap;
1152
1225
  class GraphStoreSnapshotBuilder {
1153
1226
  projected = new Map;
1154
1227
  changedRuns = new Set;
@@ -1176,9 +1249,7 @@ class GraphStoreSnapshotBuilder {
1176
1249
  const next = new Map;
1177
1250
  const compactRuns = [];
1178
1251
  for (const run of runs) {
1179
- const known = previous.get(run.id);
1180
- const reusable = known?.source === run ? known : undefined;
1181
- const projected = reusable !== undefined && !this.changedRuns.has(run.id) && this.runUnchanged(run, reusable) ? reusable : this.projectRun(run, reusable);
1252
+ const projected = this.refreshRun(run, previous.get(run.id));
1182
1253
  next.set(run.id, projected);
1183
1254
  compactRuns.push(projected.compact);
1184
1255
  }
@@ -1186,38 +1257,36 @@ class GraphStoreSnapshotBuilder {
1186
1257
  this.changedRuns.clear();
1187
1258
  this.changedStages.clear();
1188
1259
  this.changedToolNodes.clear();
1189
- const snapshot = {
1190
- runs: compactRuns,
1191
- notices: notices.map((notice) => ({ ...notice })),
1260
+ const compactNotices = notices.map((notice) => ({ ...notice }));
1261
+ deepFreezeGraphValue(compactNotices);
1262
+ const snapshot = Object.freeze({
1263
+ runs: Object.freeze(compactRuns),
1264
+ notices: compactNotices,
1192
1265
  version
1193
- };
1194
- deepFreezeGraphValue(snapshot);
1266
+ });
1267
+ snapshotLineages.set(snapshot, this);
1195
1268
  return snapshot;
1196
1269
  }
1197
1270
  buildRun(run) {
1198
- const known = this.projected.get(run.id);
1199
- const reusable = known?.source === run ? known : undefined;
1200
- const projected = reusable !== undefined && !this.changedRuns.has(run.id) && this.runUnchanged(run, reusable) ? reusable : this.projectRun(run, reusable);
1201
- deepFreezeGraphValue(projected.compact);
1271
+ const projected = this.refreshRun(run, this.projected.get(run.id));
1202
1272
  this.projected.set(run.id, projected);
1203
1273
  this.changedRuns.delete(run.id);
1204
1274
  this.changedStages.delete(run.id);
1205
1275
  this.changedToolNodes.delete(run.id);
1206
1276
  return projected.compact;
1207
1277
  }
1208
- runUnchanged(run, projected) {
1209
- if (!sameSourceShape(run, projected.shape))
1210
- return false;
1211
- const { stages, toolNodes } = projected.compact;
1212
- if (run.stages.length !== stages.length || run.toolNodes.length !== toolNodes.length)
1278
+ refreshRun(run, known) {
1279
+ const reusable = known?.source === run ? known : undefined;
1280
+ if (reusable === undefined || this.changedRuns.has(run.id) || !sameSourceShape(run, reusable.shape))
1281
+ return this.projectRun(run, reusable);
1282
+ if (!this.toolNodesUnchanged(run, reusable))
1283
+ return this.projectRun(run, reusable);
1284
+ return this.patchStages(run, reusable) ?? this.projectRun(run, reusable);
1285
+ }
1286
+ toolNodesUnchanged(run, projected) {
1287
+ const { toolNodes } = projected.compact;
1288
+ if (run.toolNodes.length !== toolNodes.length)
1213
1289
  return false;
1214
- const changedStages = this.changedStages.get(run.id);
1215
- for (let index = 0;index < run.stages.length; index++) {
1216
- const stage = run.stages[index];
1217
- const known = projected.stages.get(stage);
1218
- if (known === undefined || known.compact !== stages[index] || changedStages?.has(stage.id) === true || !stageUnchanged(stage, known))
1219
- return false;
1220
- }
1221
1290
  const changedToolNodes = this.changedToolNodes.get(run.id);
1222
1291
  for (let index = 0;index < run.toolNodes.length; index++) {
1223
1292
  const node = run.toolNodes[index];
@@ -1227,15 +1296,86 @@ class GraphStoreSnapshotBuilder {
1227
1296
  }
1228
1297
  return true;
1229
1298
  }
1299
+ patchStages(run, projected) {
1300
+ const sources = projected.stageSources;
1301
+ if (run.stages.length < sources.length)
1302
+ return;
1303
+ for (let index = 0;index < sources.length; index++)
1304
+ if (run.stages[index] !== sources[index])
1305
+ return;
1306
+ const changed = new Set;
1307
+ const scoped = this.changedStages.get(run.id);
1308
+ if (scoped !== undefined) {
1309
+ if (projected.duplicateStageIds)
1310
+ return;
1311
+ for (const id of scoped) {
1312
+ const position = projected.stagePositions.get(id);
1313
+ if (position !== undefined)
1314
+ changed.add(position);
1315
+ }
1316
+ }
1317
+ for (const position of projected.unsettled)
1318
+ if (!changed.has(position) && !stageUnchanged(sources[position], projected.stages[position]))
1319
+ changed.add(position);
1320
+ if (changed.size === 0 && run.stages.length === sources.length)
1321
+ return projected;
1322
+ const previous = projected.compact;
1323
+ const appendedFrom = sources.length;
1324
+ const compactStages = previous.stages.slice();
1325
+ for (const position of changed) {
1326
+ const stage = projectStage(sources[position]);
1327
+ projected.stages[position] = stage;
1328
+ compactStages[position] = stage.compact;
1329
+ if (stage.settled)
1330
+ projected.unsettled.delete(position);
1331
+ else
1332
+ projected.unsettled.add(position);
1333
+ }
1334
+ for (let position = sources.length;position < run.stages.length; position++) {
1335
+ const source = run.stages[position];
1336
+ const stage = projectStage(source);
1337
+ sources.push(source);
1338
+ projected.stages.push(stage);
1339
+ compactStages.push(stage.compact);
1340
+ if (!stage.settled)
1341
+ projected.unsettled.add(position);
1342
+ if (projected.stagePositions.has(source.id))
1343
+ projected.duplicateStageIds = true;
1344
+ else
1345
+ projected.stagePositions.set(source.id, position);
1346
+ }
1347
+ const compact = { ...previous, stages: compactStages };
1348
+ freezeCompactRun(compact);
1349
+ indexRunFrom(compact, previous, changed, appendedFrom);
1350
+ projected.compact = compact;
1351
+ return projected;
1352
+ }
1230
1353
  projectRun(run, previous) {
1231
1354
  const changedStages = this.changedStages.get(run.id);
1232
- const stages = new Map;
1355
+ const previousStages = new Map;
1356
+ if (previous !== undefined)
1357
+ for (let index = 0;index < previous.stageSources.length; index++)
1358
+ previousStages.set(previous.stageSources[index], previous.stages[index]);
1359
+ const stageSources = [];
1360
+ const stages = [];
1361
+ const stagePositions = new Map;
1362
+ const unsettled = new Set;
1363
+ let duplicateStageIds = false;
1233
1364
  const compactStages = [];
1234
1365
  for (const stage of run.stages) {
1235
- let projected = stages.get(stage) ?? previous?.stages.get(stage);
1366
+ let projected = previousStages.get(stage);
1236
1367
  if (projected === undefined || changedStages?.has(stage.id) === true || !stageUnchanged(stage, projected))
1237
1368
  projected = projectStage(stage);
1238
- stages.set(stage, projected);
1369
+ previousStages.set(stage, projected);
1370
+ const position = stages.length;
1371
+ stageSources.push(stage);
1372
+ stages.push(projected);
1373
+ if (!projected.settled)
1374
+ unsettled.add(position);
1375
+ if (stagePositions.has(stage.id))
1376
+ duplicateStageIds = true;
1377
+ else
1378
+ stagePositions.set(stage.id, position);
1239
1379
  compactStages.push(projected.compact);
1240
1380
  }
1241
1381
  const changedToolNodes = this.changedToolNodes.get(run.id);
@@ -1248,12 +1388,18 @@ class GraphStoreSnapshotBuilder {
1248
1388
  toolNodes.set(node, projected);
1249
1389
  compactToolNodes.push(projected.compact);
1250
1390
  }
1391
+ const compact = compactRun(run, compactStages, compactToolNodes);
1392
+ freezeCompactRun(compact);
1251
1393
  return {
1252
1394
  source: run,
1253
1395
  shape: sourceShape(run),
1396
+ stageSources,
1254
1397
  stages,
1398
+ stagePositions,
1399
+ duplicateStageIds,
1400
+ unsettled,
1255
1401
  toolNodes,
1256
- compact: compactRun(run, compactStages, compactToolNodes)
1402
+ compact
1257
1403
  };
1258
1404
  }
1259
1405
  }
@@ -1284,6 +1430,9 @@ import { randomUUID } from "node:crypto";
1284
1430
  // dist/builtin/workflows/src/shared/expanded-workflow-graph.ts
1285
1431
  var leafExpansions = new WeakMap;
1286
1432
  var snapshotExpansions = new WeakMap;
1433
+ var settledStageCounts = new WeakMap;
1434
+ var expandedStageLists = new WeakSet;
1435
+ var chainExpansions = new WeakMap;
1287
1436
 
1288
1437
  // dist/builtin/workflows/src/shared/workflow-activity.ts
1289
1438
  function workflowActivityNodeKey(runId, nodeId) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  goal_default
3
- } from "./chunk-89we7r4p.js";
4
- import"./chunk-wh2p4qjg.js";
3
+ } from "./chunk-5hrzxynt.js";
4
+ import"./chunk-x8m4t2jy.js";
5
5
  import"./chunk-8kdrnrpa.js";
6
6
  import"./chunk-gp0s6m45.js";
7
7
  import"./chunk-n1910xc4.js";
@@ -16,8 +16,8 @@ import {
16
16
  } from "./chunk-va2h64a6.js";
17
17
  import {
18
18
  goal_default
19
- } from "./chunk-89we7r4p.js";
20
- import"./chunk-wh2p4qjg.js";
19
+ } from "./chunk-5hrzxynt.js";
20
+ import"./chunk-x8m4t2jy.js";
21
21
  import"./chunk-gp0s6m45.js";
22
22
  import {
23
23
  open_claude_design_default
@@ -27,7 +27,7 @@ import {
27
27
  } from "./chunk-8ycbc76t.js";
28
28
  import {
29
29
  ralph_default
30
- } from "./chunk-8yfssw01.js";
30
+ } from "./chunk-m56qhe4b.js";
31
31
  import {
32
32
  tournament_default
33
33
  } from "./chunk-r39ypw6b.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ralph_default
3
- } from "./chunk-8yfssw01.js";
4
- import"./chunk-wh2p4qjg.js";
3
+ } from "./chunk-m56qhe4b.js";
4
+ import"./chunk-x8m4t2jy.js";
5
5
  import"./chunk-8kdrnrpa.js";
6
6
  import"./chunk-gp0s6m45.js";
7
7
  import"./chunk-n1910xc4.js";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/workflows",
3
- "version": "0.9.78-alpha.1",
3
+ "version": "0.9.79-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for multi-stage workflow authoring and execution.",
6
6
  "contributors": [