@bastani/atomic 0.9.38-alpha.9 → 0.9.39-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 (144) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +16 -0
  3. package/dist/builtin/intercom/index.bundle.mjs +216 -2
  4. package/dist/builtin/intercom/package.json +1 -1
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +16 -0
  7. package/dist/builtin/subagents/package.json +1 -1
  8. package/dist/builtin/subagents/src/extension/index.bundle.mjs +16 -1
  9. package/dist/builtin/web-access/CHANGELOG.md +7 -0
  10. package/dist/builtin/web-access/package.json +1 -1
  11. package/dist/builtin/workflows/CHANGELOG.md +74 -0
  12. package/dist/builtin/workflows/package.json +1 -1
  13. package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +2 -15
  14. package/dist/builtin/workflows/src/extension/index.bundle.mjs +532 -64
  15. package/dist/builtin/workflows/src/index.js +301 -27
  16. package/dist/cli.js +13 -6
  17. package/dist/cli.js.map +1 -1
  18. package/dist/config.d.ts +1 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +1 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  23. package/dist/core/agent-session-extension-bindings.js +4 -1
  24. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  25. package/dist/core/agent-session-methods.d.ts +1 -0
  26. package/dist/core/agent-session-methods.d.ts.map +1 -1
  27. package/dist/core/agent-session-methods.js.map +1 -1
  28. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  29. package/dist/core/agent-session-prompt.js +57 -15
  30. package/dist/core/agent-session-prompt.js.map +1 -1
  31. package/dist/core/agent-session-types.d.ts +1 -0
  32. package/dist/core/agent-session-types.d.ts.map +1 -1
  33. package/dist/core/agent-session-types.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +1 -0
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +2 -0
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/export-html/index.d.ts.map +1 -1
  39. package/dist/core/export-html/index.js +13 -10
  40. package/dist/core/export-html/index.js.map +1 -1
  41. package/dist/core/extensions/api-types.d.ts +2 -0
  42. package/dist/core/extensions/api-types.d.ts.map +1 -1
  43. package/dist/core/extensions/api-types.js.map +1 -1
  44. package/dist/core/extensions/context-types.d.ts +5 -0
  45. package/dist/core/extensions/context-types.d.ts.map +1 -1
  46. package/dist/core/extensions/context-types.js.map +1 -1
  47. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  48. package/dist/core/extensions/loader-api.js +4 -0
  49. package/dist/core/extensions/loader-api.js.map +1 -1
  50. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  51. package/dist/core/extensions/runner-context.js +1 -0
  52. package/dist/core/extensions/runner-context.js.map +1 -1
  53. package/dist/core/extensions/runner.d.ts +1 -0
  54. package/dist/core/extensions/runner.d.ts.map +1 -1
  55. package/dist/core/extensions/runner.js +3 -0
  56. package/dist/core/extensions/runner.js.map +1 -1
  57. package/dist/core/extensions/runtime-types.d.ts +1 -0
  58. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  59. package/dist/core/extensions/runtime-types.js.map +1 -1
  60. package/dist/core/queued-input-admission.d.ts +20 -0
  61. package/dist/core/queued-input-admission.d.ts.map +1 -0
  62. package/dist/core/queued-input-admission.js +55 -0
  63. package/dist/core/queued-input-admission.js.map +1 -0
  64. package/dist/core/sdk-types.d.ts +7 -1
  65. package/dist/core/sdk-types.d.ts.map +1 -1
  66. package/dist/core/sdk-types.js.map +1 -1
  67. package/dist/core/sdk.js +1 -0
  68. package/dist/core/sdk.js.map +1 -1
  69. package/dist/core/session-manager-core.d.ts +1 -0
  70. package/dist/core/session-manager-core.d.ts.map +1 -1
  71. package/dist/core/session-manager-core.js +12 -0
  72. package/dist/core/session-manager-core.js.map +1 -1
  73. package/dist/core/storage/provider.d.ts +14 -0
  74. package/dist/core/storage/provider.d.ts.map +1 -1
  75. package/dist/core/storage/provider.js.map +1 -1
  76. package/dist/core/storage/session/legacy-session-store.d.ts +4 -1
  77. package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -1
  78. package/dist/core/storage/session/legacy-session-store.js +42 -2
  79. package/dist/core/storage/session/legacy-session-store.js.map +1 -1
  80. package/dist/core/storage/session/legacy-session-summary.d.ts +8 -0
  81. package/dist/core/storage/session/legacy-session-summary.d.ts.map +1 -1
  82. package/dist/core/storage/session/legacy-session-summary.js +42 -2
  83. package/dist/core/storage/session/legacy-session-summary.js.map +1 -1
  84. package/dist/extensions/mcp/client/transports/streamable-http.js +9 -8
  85. package/dist/extensions/mcp/client/transports/streamable-http.js.map +1 -1
  86. package/dist/modes/interactive/components/chat-session-host-actions.d.ts +4 -0
  87. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  88. package/dist/modes/interactive/components/chat-session-host-actions.js +104 -30
  89. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  90. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  91. package/dist/modes/interactive/components/chat-session-host-events.js +1 -0
  92. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  93. package/dist/modes/interactive/components/chat-session-host-state.d.ts +4 -0
  94. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  95. package/dist/modes/interactive/components/chat-session-host-state.js +4 -0
  96. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  97. package/dist/modes/interactive/components/session-selector.js +4 -3
  98. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  99. package/dist/modes/interactive/interactive-input-handling.js +8 -2
  100. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  101. package/dist/modes/interactive/interactive-mode-base.d.ts +4 -0
  102. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  103. package/dist/modes/interactive/interactive-mode-base.js +4 -0
  104. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  105. package/dist/modes/interactive/interactive-process-lifecycle.js +8 -2
  106. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  107. package/dist/modes/interactive/interactive-queueing.js +94 -73
  108. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  109. package/dist/modes/interactive/interactive-session-runtime.js +1 -0
  110. package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
  111. package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
  112. package/dist/modes/interactive-engine/create-isolated-runtime.js +2 -0
  113. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  114. package/dist/modes/interactive-engine/engine-heap.d.ts +24 -0
  115. package/dist/modes/interactive-engine/engine-heap.d.ts.map +1 -0
  116. package/dist/modes/interactive-engine/engine-heap.js +88 -0
  117. package/dist/modes/interactive-engine/engine-heap.js.map +1 -0
  118. package/dist/modes/rpc/rpc-client-api.d.ts +1 -0
  119. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  120. package/dist/modes/rpc/rpc-client-api.js +3 -0
  121. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  122. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  123. package/dist/modes/rpc/rpc-command-handler.js +7 -0
  124. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  125. package/dist/modes/rpc/rpc-types.d.ts +9 -0
  126. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  127. package/dist/modes/rpc/rpc-types.js.map +1 -1
  128. package/dist/utils/heap-relaunch.d.ts +14 -0
  129. package/dist/utils/heap-relaunch.d.ts.map +1 -0
  130. package/dist/utils/heap-relaunch.js +59 -0
  131. package/dist/utils/heap-relaunch.js.map +1 -0
  132. package/docs/environment-variables.md +2 -1
  133. package/docs/intercom/reference.md +1 -1
  134. package/docs/rpc/protocol.md +23 -0
  135. package/docs/sdk/web-server.md +1 -1
  136. package/docs/sdk.md +10 -1
  137. package/docs/session-format.md +1 -0
  138. package/docs/sessions.md +2 -0
  139. package/docs/settings.md +1 -1
  140. package/docs/usage.md +2 -0
  141. package/docs/workflows/api-reference.md +1 -1
  142. package/docs/workflows/operations.md +5 -1
  143. package/npm-shrinkwrap.json +32 -32
  144. package/package.json +3 -3
@@ -1753,6 +1753,10 @@ function asAgentSession(activeSession) {
1753
1753
  }
1754
1754
  return;
1755
1755
  }
1756
+ function isStageSessionQuiescent(session) {
1757
+ const sdk = session;
1758
+ return !session.isStreaming && (session.pendingMessageCount ?? 0) === 0 && session.queuedMessagesPaused !== true && sdk.isCompacting !== true && sdk.isRetrying !== true && sdk.isBashRunning !== true && sdk.hasPendingBashMessages !== true;
1759
+ }
1756
1760
  function normalizeSessionCreateResult(created) {
1757
1761
  if ("session" in created)
1758
1762
  return created;
@@ -5218,6 +5222,7 @@ function buildRuntimeAdapters(builtWith, options = {}) {
5218
5222
  }, options.sdk));
5219
5223
  const broker = options.stageUiBroker ?? currentStageUiBroker();
5220
5224
  const adapters = {
5225
+ ...options.ownerSessionClosing === undefined ? {} : { ownerSessionClosing: options.ownerSessionClosing },
5221
5226
  agentSession: {
5222
5227
  async create(stageOptions, meta) {
5223
5228
  const pi = resolveSurface();
@@ -9383,6 +9388,20 @@ class PromptReservationState {
9383
9388
 
9384
9389
  // dist/builtin/workflows/src/durable/journal/journal-backend.ts
9385
9390
  var PROCESS_HOLDER_ID = randomUUID4();
9391
+ var processExitCleanups = new Set;
9392
+ function runProcessExitCleanups() {
9393
+ for (const cleanup of processExitCleanups)
9394
+ cleanup();
9395
+ }
9396
+ function addProcessExitCleanup(cleanup) {
9397
+ if (processExitCleanups.size === 0)
9398
+ process.once("exit", runProcessExitCleanups);
9399
+ processExitCleanups.add(cleanup);
9400
+ }
9401
+ function removeProcessExitCleanup(cleanup) {
9402
+ if (processExitCleanups.delete(cleanup) && processExitCleanups.size === 0)
9403
+ process.off("exit", runProcessExitCleanups);
9404
+ }
9386
9405
  function* invoke(action) {
9387
9406
  try {
9388
9407
  const result = action();
@@ -10009,7 +10028,7 @@ class JournalDurableBackend {
10009
10028
  process.exitCode = 1;
10010
10029
  });
10011
10030
  };
10012
- process.once("exit", this.processExitCleanup);
10031
+ addProcessExitCleanup(this.processExitCleanup);
10013
10032
  }
10014
10033
  async withWorkflowLease(runId, action) {
10015
10034
  this.ensureOpen();
@@ -10077,7 +10096,7 @@ class JournalDurableBackend {
10077
10096
  return this.closing;
10078
10097
  this.state = "closing";
10079
10098
  if (this.processExitCleanup !== undefined) {
10080
- process.off("exit", this.processExitCleanup);
10099
+ removeProcessExitCleanup(this.processExitCleanup);
10081
10100
  this.processExitCleanup = undefined;
10082
10101
  }
10083
10102
  if (this.timer !== undefined)
@@ -10115,28 +10134,62 @@ async function initializeDurableBackend(options = {}) {
10115
10134
  projectTrusted: options.projectTrusted
10116
10135
  }).getSettings() : undefined
10117
10136
  });
10118
- const key = "createRun" in selection ? selection : selection.kind === "memory" && choice !== undefined ? choice : storageSelectionKey(selection, getAgentDir3());
10137
+ const holder = options.holder;
10138
+ const key = "createRun" in selection ? selection : selection.kind === "memory" && choice !== undefined ? choice : selection.kind === "memory" && holder !== undefined ? holder : storageSelectionKey(selection, getAgentDir3());
10119
10139
  const ownsJournal = choice === undefined || !("createRun" in choice);
10120
10140
  owner.selectedBackends ??= new Map;
10121
10141
  const selected = owner.selectedBackends;
10122
10142
  const existing = selected.get(key);
10123
- let ready;
10124
- if (existing !== undefined) {
10125
- ready = existing.ready;
10126
- } else {
10127
- ready = openSelectedRunJournal(selection).then((journal) => JournalDurableBackend.open(journal, { ownsJournal })).then((opened) => {
10143
+ const entry = existing ?? {
10144
+ ready: openSelectedRunJournal(selection).then((journal) => JournalDurableBackend.open(journal, { ownsJournal })).then((opened) => {
10128
10145
  if (ownsJournal)
10129
10146
  opened.closeOnProcessExit();
10130
10147
  entry.close = () => opened.close();
10131
10148
  return opened;
10132
10149
  }).catch((error) => {
10133
- selected.delete(key);
10150
+ if (selected.get(key) === entry)
10151
+ selected.delete(key);
10134
10152
  throw error;
10135
- });
10136
- const entry = { ready };
10153
+ }),
10154
+ holders: new Set,
10155
+ pinned: false
10156
+ };
10157
+ if (existing === undefined)
10137
10158
  selected.set(key, entry);
10138
- }
10139
- return withRunJournalConfigSource(selection, () => ready);
10159
+ if (holder === undefined)
10160
+ entry.pinned = true;
10161
+ else
10162
+ entry.holders.add(holder);
10163
+ return withRunJournalConfigSource(selection, () => entry.ready);
10164
+ }
10165
+
10166
+ // dist/builtin/workflows/src/durable/run-result.ts
10167
+ var RUN_RESULT_CHECKPOINT_NAME = "workflow-run-result";
10168
+ var RUN_RESULT_CHECKPOINT_ID_PREFIX = "run-result:";
10169
+ async function recordRunResultCheckpointAsync(backend, run) {
10170
+ const result = run.result;
10171
+ const hasResult = result !== undefined && Object.keys(result).length > 0;
10172
+ const recorded = backend.getToolCheckpoint(run.id, RUN_RESULT_CHECKPOINT_NAME);
10173
+ if (!hasResult && recorded === undefined)
10174
+ return false;
10175
+ if (backend.listCheckpoints(run.id).length === 0)
10176
+ return false;
10177
+ const output = hasResult ? { result } : {};
10178
+ if (recorded !== undefined && durableHash(recorded.output) === durableHash(output))
10179
+ return false;
10180
+ const previousSequence = Number(recorded?.checkpointId.slice(RUN_RESULT_CHECKPOINT_ID_PREFIX.length));
10181
+ const sequence = Number.isSafeInteger(previousSequence) ? previousSequence + 1 : 1;
10182
+ const completedAt = Math.max(Date.now(), recorded?.completedAt ?? 0);
10183
+ await backend.commitCheckpoint({
10184
+ kind: "tool",
10185
+ workflowId: run.id,
10186
+ checkpointId: `${RUN_RESULT_CHECKPOINT_ID_PREFIX}${sequence}`,
10187
+ name: RUN_RESULT_CHECKPOINT_NAME,
10188
+ argsHash: RUN_RESULT_CHECKPOINT_NAME,
10189
+ output,
10190
+ completedAt
10191
+ });
10192
+ return true;
10140
10193
  }
10141
10194
 
10142
10195
  // dist/builtin/workflows/src/shared/persistence-restore-helpers.ts
@@ -13938,9 +13991,9 @@ function createStageControlRegistry() {
13938
13991
  const _byRun = new Map;
13939
13992
  const pendingDisposals = new Set;
13940
13993
  const sessionStores = new Map;
13994
+ const releaseListeners = new Set;
13941
13995
  let generation = 0;
13942
- function rememberSessionStore(handle) {
13943
- const store = handle.sessionStore;
13996
+ function rememberSessionStore(handle, store = handle.sessionStore) {
13944
13997
  if (store === undefined)
13945
13998
  return;
13946
13999
  let stores = sessionStores.get(handle.runId);
@@ -13989,6 +14042,35 @@ function createStageControlRegistry() {
13989
14042
  function disposeEntryInBackground(entry, message) {
13990
14043
  disposeEntry(entry).catch((err) => console.warn(message, err));
13991
14044
  }
14045
+ async function releaseIdleEntry(runId, stageId, entry) {
14046
+ const gate = entry.handle.releaseGate;
14047
+ if (gate === undefined || entry.disposal !== undefined)
14048
+ return;
14049
+ const epoch = entry.epoch;
14050
+ const savedIn = await gate.savedForReopen();
14051
+ if (savedIn === undefined)
14052
+ return;
14053
+ const runMap = _byRun.get(runId);
14054
+ if (runMap?.get(stageId) !== entry || entry.epoch !== epoch || entry.leases.size > 0)
14055
+ return;
14056
+ if (entry.disposal !== undefined || !gate.idle())
14057
+ return;
14058
+ const { stageName, sessionId } = entry.handle;
14059
+ rememberSessionStore(entry.handle, savedIn);
14060
+ runMap.delete(stageId);
14061
+ if (runMap.size === 0)
14062
+ _byRun.delete(runId);
14063
+ await disposeEntry(entry);
14064
+ if (sessionId === undefined)
14065
+ return;
14066
+ for (const listener of [...releaseListeners]) {
14067
+ try {
14068
+ listener({ runId, stageId, stageName, sessionId });
14069
+ } catch (error) {
14070
+ console.warn("atomic-workflows: released stage listener failed", error);
14071
+ }
14072
+ }
14073
+ }
13992
14074
  function makeRunHandle(runId) {
13993
14075
  return {
13994
14076
  runId,
@@ -14048,7 +14130,8 @@ function createStageControlRegistry() {
14048
14130
  handle,
14049
14131
  controlsDependencies: true,
14050
14132
  permanent: true,
14051
- leases: new Set
14133
+ leases: new Set,
14134
+ epoch: 0
14052
14135
  });
14053
14136
  if (displaced !== undefined && displaced.handle !== handle && !displaced.permanent) {
14054
14137
  disposeEntryInBackground(displaced, "atomic-workflows: displaced provisional stage handle dispose failed");
@@ -14070,6 +14153,7 @@ function createStageControlRegistry() {
14070
14153
  const existing = runMap.get(stageId);
14071
14154
  if (existing !== undefined && existing.handle.isDisposed !== true) {
14072
14155
  existing.permanent = true;
14156
+ existing.epoch += 1;
14073
14157
  return existing.handle;
14074
14158
  }
14075
14159
  if (existing !== undefined) {
@@ -14081,7 +14165,8 @@ function createStageControlRegistry() {
14081
14165
  handle,
14082
14166
  controlsDependencies: false,
14083
14167
  permanent: true,
14084
- leases: new Set
14168
+ leases: new Set,
14169
+ epoch: 0
14085
14170
  });
14086
14171
  return handle;
14087
14172
  },
@@ -14098,11 +14183,13 @@ function createStageControlRegistry() {
14098
14183
  handle: create(),
14099
14184
  controlsDependencies: false,
14100
14185
  permanent: false,
14101
- leases: new Set
14186
+ leases: new Set,
14187
+ epoch: 0
14102
14188
  };
14103
14189
  runMap.set(stageId, entry);
14104
14190
  }
14105
14191
  const leasedEntry = entry;
14192
+ leasedEntry.epoch += 1;
14106
14193
  const token = Symbol("detached-stage-handle-lease");
14107
14194
  leasedEntry.leases.add(token);
14108
14195
  let settled = false;
@@ -14155,8 +14242,10 @@ function createStageControlRegistry() {
14155
14242
  },
14156
14243
  claim(runId, stageId) {
14157
14244
  const entry = _byRun.get(runId)?.get(stageId);
14158
- if (entry !== undefined)
14245
+ if (entry !== undefined) {
14159
14246
  entry.permanent = true;
14247
+ entry.epoch += 1;
14248
+ }
14160
14249
  return entry?.handle;
14161
14250
  },
14162
14251
  get(runId, stageId) {
@@ -14206,6 +14295,21 @@ function createStageControlRegistry() {
14206
14295
  _byRun.delete(runId);
14207
14296
  }
14208
14297
  await disposeEntries(entries);
14298
+ },
14299
+ async releaseIdle(runId) {
14300
+ for (const [stageId, entry] of [..._byRun.get(runId) ?? []]) {
14301
+ try {
14302
+ await releaseIdleEntry(runId, stageId, entry);
14303
+ } catch (error) {
14304
+ console.warn("atomic-workflows: completed stage session release failed", error);
14305
+ }
14306
+ }
14307
+ },
14308
+ onStageReleased(listener) {
14309
+ releaseListeners.add(listener);
14310
+ return () => {
14311
+ releaseListeners.delete(listener);
14312
+ };
14209
14313
  }
14210
14314
  };
14211
14315
  }
@@ -15317,6 +15421,12 @@ async function finalizeDurableTerminalStatus(input) {
15317
15421
  return;
15318
15422
  const durableStatus = toDurableStatus(status);
15319
15423
  if (durableStatus !== undefined) {
15424
+ try {
15425
+ await recordRunResultCheckpointAsync(input.durableBackend, input.runSnapshot);
15426
+ } catch (error) {
15427
+ if (input.runSnapshot.result !== undefined)
15428
+ throw error;
15429
+ }
15320
15430
  if (durableStatus === "failed" || durableStatus === "blocked") {
15321
15431
  await recordRunTimingCheckpointAsync(input.durableBackend, input.runSnapshot);
15322
15432
  }
@@ -15467,6 +15577,30 @@ function createDurableStageSessionRecorder(input) {
15467
15577
  };
15468
15578
  }
15469
15579
 
15580
+ // dist/builtin/workflows/src/shared/session-transcript.ts
15581
+ async function isReopenableSession(store, sessionId) {
15582
+ try {
15583
+ const snapshot = await store.load(sessionId);
15584
+ return snapshot.header.id === sessionId && snapshot.entries.some(isUsableContextMessage);
15585
+ } catch {
15586
+ return false;
15587
+ }
15588
+ }
15589
+ function isUsableContextMessage(entry) {
15590
+ return entry.type === "message" && typeof entry.id === "string" && typeof entry.timestamp === "string" && typeof entry.message?.role === "string" && hasUsableMessageContent(entry.message.content);
15591
+ }
15592
+ function hasUsableMessageContent(content) {
15593
+ if (typeof content === "string")
15594
+ return content.trim().length > 0;
15595
+ return Array.isArray(content) && content.some(hasUsableContentBlock);
15596
+ }
15597
+ function hasUsableContentBlock(block) {
15598
+ if (typeof block !== "object" || block === null)
15599
+ return false;
15600
+ const contentBlock = block;
15601
+ return [contentBlock.text, contentBlock.thinking, contentBlock.data, contentBlock.name].some((value) => typeof value === "string" && value.trim().length > 0);
15602
+ }
15603
+
15470
15604
  // dist/builtin/workflows/src/shared/stage-session-store.ts
15471
15605
  import { randomUUID as randomUUID6 } from "node:crypto";
15472
15606
  import { dirname as dirname9, resolve as resolve9 } from "node:path";
@@ -15925,7 +16059,7 @@ var unsettledResumeClaims = new WeakMap;
15925
16059
 
15926
16060
  // dist/builtin/workflows/src/durable/completed-catalog.ts
15927
16061
  function isReservedRunCheckpointHash(argsHash) {
15928
- return [RUN_TIMING_CHECKPOINT_NAME, RUN_USAGE_CHECKPOINT_NAME].includes(argsHash) || argsHash === WORKFLOW_HEARTBEAT_ANCHOR_CHECKPOINT_NAME;
16062
+ return [RUN_TIMING_CHECKPOINT_NAME, RUN_USAGE_CHECKPOINT_NAME, RUN_RESULT_CHECKPOINT_NAME].includes(argsHash) || argsHash === WORKFLOW_HEARTBEAT_ANCHOR_CHECKPOINT_NAME;
15929
16063
  }
15930
16064
  function durableNestedRunSnapshots(backend, rootWorkflowId) {
15931
16065
  const handle = backend.getWorkflow(rootWorkflowId);
@@ -17308,6 +17442,7 @@ function createTrackedStageCaller(input) {
17308
17442
  throw err;
17309
17443
  }
17310
17444
  const trackStageLifecycle = !runtime.state.stageFinalized;
17445
+ runtime.state.sessionCheckpointed = false;
17311
17446
  let applyTerminalStageState;
17312
17447
  let terminalStateIsSuccess = false;
17313
17448
  let stageResultBeforeBudget;
@@ -17578,6 +17713,7 @@ function createTrackedStageCaller(input) {
17578
17713
  } else if (runtime.state.stageClosedByWorkflowExit || runtime.exit.currentWorkflowExitAbortReason() !== undefined) {
17579
17714
  await runtime.releaseLiveHandle().catch(() => {});
17580
17715
  }
17716
+ runtime.state.sessionCheckpointed = finalizationError === undefined;
17581
17717
  input.limiter.release();
17582
17718
  if (finalizationError !== undefined)
17583
17719
  throwFinalizationError(finalizationError.error);
@@ -17776,6 +17912,11 @@ function stageSessionQueueUpdateEvent(session) {
17776
17912
  return;
17777
17913
  return { type: "queue_update", steering, followUp };
17778
17914
  }
17915
+ function stageQueuedUserMessageCount(queued) {
17916
+ if (!queued)
17917
+ return 0;
17918
+ return queued.steering.length + queued.followUp.length;
17919
+ }
17779
17920
 
17780
17921
  // dist/builtin/workflows/src/runs/foreground/stage-tool-execution-buffer.ts
17781
17922
  function eventType(event) {
@@ -17849,7 +17990,29 @@ function createStageControlHandle(runtime) {
17849
17990
  toolExecutions.record(event);
17850
17991
  queuedUserMessages.record(event);
17851
17992
  });
17852
- return {
17993
+ let externalSubscribers = 0;
17994
+ const countSubscription = (unsubscribe) => {
17995
+ externalSubscribers += 1;
17996
+ let active = true;
17997
+ return () => {
17998
+ if (!active)
17999
+ return;
18000
+ active = false;
18001
+ externalSubscribers -= 1;
18002
+ unsubscribe();
18003
+ };
18004
+ };
18005
+ let activeOperations = 0;
18006
+ const tracked = async (operation) => {
18007
+ activeOperations += 1;
18008
+ try {
18009
+ return await operation();
18010
+ } finally {
18011
+ activeOperations -= 1;
18012
+ }
18013
+ };
18014
+ const sessionSaved = () => runtime.stageSnapshot.status === "completed" && runtime.state.stageFinalized && runtime.state.sessionCheckpointed && !runtime.state.liveHandleReleased && !runtime.state.stageClosedByWorkflowExit;
18015
+ const handle = {
17853
18016
  runId: runtime.runId,
17854
18017
  stageId: runtime.stageId,
17855
18018
  stageName: runtime.name,
@@ -18020,18 +18183,41 @@ function createStageControlHandle(runtime) {
18020
18183
  }
18021
18184
  },
18022
18185
  subscribe(listener) {
18023
- return runtime.innerCtx.subscribe(listener);
18186
+ return countSubscription(runtime.innerCtx.subscribe(listener));
18024
18187
  },
18025
18188
  subscribeDeliveryActivity(listener) {
18026
- return runtime.innerCtx.__subscribeDeliveryActivity(listener);
18189
+ return countSubscription(runtime.innerCtx.__subscribeDeliveryActivity(listener));
18027
18190
  },
18028
18191
  async dispose() {
18029
18192
  unsubscribeStageEvents();
18030
18193
  toolExecutions.clear();
18031
18194
  queuedUserMessages.clear();
18032
18195
  await runtime.releaseLiveHandle();
18196
+ },
18197
+ releaseGate: {
18198
+ async savedForReopen() {
18199
+ if (!sessionSaved())
18200
+ return;
18201
+ const store = runtime.innerCtx.__persistedSessionStore();
18202
+ const sessionId = runtime.innerCtx.__sessionMeta().sessionId ?? runtime.stageSnapshot.sessionId;
18203
+ if (store === undefined || sessionId === undefined)
18204
+ return;
18205
+ return await isReopenableSession(store, sessionId) ? store : undefined;
18206
+ },
18207
+ idle() {
18208
+ return sessionSaved() && externalSubscribers === 0 && activeOperations === 0 && stageQueuedUserMessageCount(queuedUserMessages.snapshot()) === 0 && !runtime.state.waitingForStageChatTurn && runtime.state.wakeWaitingForStageChatTurn === undefined && runtime.state.readinessController === undefined && runtime.state.resumeContinuationPending === false && runtime.innerCtx.__idleForRelease();
18209
+ }
18033
18210
  }
18034
18211
  };
18212
+ const { ensureAttached, sendUserMessage, prompt, steer, followUp, pause, resume } = handle;
18213
+ handle.ensureAttached = () => tracked(ensureAttached);
18214
+ handle.sendUserMessage = (text, options, beforeDelivery) => tracked(() => sendUserMessage(text, options, beforeDelivery));
18215
+ handle.prompt = (text) => tracked(() => prompt(text));
18216
+ handle.steer = (text) => tracked(() => steer(text));
18217
+ handle.followUp = (text) => tracked(() => followUp(text));
18218
+ handle.pause = () => tracked(pause);
18219
+ handle.resume = (message, beforeResume) => tracked(() => resume(message, beforeResume));
18220
+ return handle;
18035
18221
  }
18036
18222
 
18037
18223
  // dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts
@@ -18155,6 +18341,10 @@ function createReplayStageContext(input) {
18155
18341
  return;
18156
18342
  },
18157
18343
  __pendingMessageCount: () => 0,
18344
+ __persistedSessionStore: () => {
18345
+ return;
18346
+ },
18347
+ __idleForRelease: () => false,
18158
18348
  __modelFallbackMeta: () => ({
18159
18349
  ...replaySource.model !== undefined ? { model: replaySource.model } : {},
18160
18350
  ...replaySource.thinkingLevel !== undefined ? { thinkingLevel: replaySource.thinkingLevel } : {},
@@ -18895,6 +19085,9 @@ class StageMessageAdmission {
18895
19085
  return this.runAdmitted(operation, admission);
18896
19086
  return admission.then((release) => this.runAdmitted(operation, release));
18897
19087
  }
19088
+ isBusy() {
19089
+ return this.tail !== undefined || this.starting !== undefined || this.owned !== undefined || this.startedGenerations.length > 0;
19090
+ }
18898
19091
  isOwned(session) {
18899
19092
  return this.session === session && this.owned?.state === "owned";
18900
19093
  }
@@ -19919,6 +20112,7 @@ class StageSessionController {
19919
20112
  messageAdmission = new StageMessageAdmission;
19920
20113
  deliveryActivity = new StageDeliveryActivity;
19921
20114
  artifactCapture = new StageArtifactCapture;
20115
+ callerSessionManager;
19922
20116
  beginOutputGeneration() {
19923
20117
  this.artifactCapture.reset();
19924
20118
  }
@@ -20374,6 +20568,25 @@ class StageSessionController {
20374
20568
  pendingMessageCount() {
20375
20569
  return typeof this.session?.pendingMessageCount === "number" ? this.session.pendingMessageCount : 0;
20376
20570
  }
20571
+ persistedSessionStore() {
20572
+ return this.session === undefined ? undefined : this.callerSessionManager?.getSessionStore();
20573
+ }
20574
+ isIdleForRelease() {
20575
+ const session = this.session;
20576
+ if (session === undefined || this.disposed || this.pendingDisposal || this.disposalPromise !== undefined)
20577
+ return false;
20578
+ if (this.activeCreation !== undefined || this.ownedCreationPromise !== undefined)
20579
+ return false;
20580
+ if (this.sessionShutdownPromise !== undefined || this.replacement.retiringSession !== undefined)
20581
+ return false;
20582
+ if (this.pauseControl.isPaused())
20583
+ return false;
20584
+ if (this.thrownErrorRetryStates.size > 0)
20585
+ return false;
20586
+ if (this.messageAdmission.isBusy())
20587
+ return false;
20588
+ return isStageSessionQuiescent(session);
20589
+ }
20377
20590
  bindAbortSignal() {
20378
20591
  const { signal } = this.opts;
20379
20592
  if (!signal)
@@ -20928,7 +21141,10 @@ class StageSessionController {
20928
21141
  this.modelRoute?.assertCurrent();
20929
21142
  if (this.modelRoute && candidate && (typeof candidate.value === "string" || !this.modelRoute.allowsModel(candidate.value, candidate.reasoningLevel)))
20930
21143
  throw new Error("Workflow stage execution candidate is no longer eligible.");
20931
- created = this.opts.adapters.agentSession ? await this.opts.adapters.agentSession.create(await stripWorkflowOnlyOptions2(stageOptions, this.opts.defaultSessionDir, this.meta, this.opts.pendingStageDelivery), {
21144
+ const adapter = this.opts.adapters.agentSession ?? missingAdapter(consumer);
21145
+ const createOptions = await stripWorkflowOnlyOptions2(stageOptions, this.opts.defaultSessionDir, this.meta, this.opts.pendingStageDelivery);
21146
+ this.callerSessionManager = createOptions.sessionManager;
21147
+ created = await adapter.create(createOptions, {
20932
21148
  ...this.meta,
20933
21149
  startupSignal: this.startupWait.signal,
20934
21150
  isFallbackAttempt: candidate !== undefined && candidate !== (await this.modelCandidates())[0],
@@ -20938,7 +21154,7 @@ class StageSessionController {
20938
21154
  },
20939
21155
  stageOptions,
20940
21156
  ...this.sharedOrchestrationContext !== undefined ? { orchestrationContext: this.sharedOrchestrationContext } : {}
20941
- }) : missingAdapter(consumer);
21157
+ });
20942
21158
  } catch (error) {
20943
21159
  if (error instanceof StageSessionBindingCleanupFailure) {
20944
21160
  this.bindingCleanupFailure = error;
@@ -21748,6 +21964,12 @@ ${nextPrompt}`;
21748
21964
  __pendingMessageCount() {
21749
21965
  return controller.pendingMessageCount();
21750
21966
  },
21967
+ __persistedSessionStore() {
21968
+ return controller.persistedSessionStore();
21969
+ },
21970
+ __idleForRelease() {
21971
+ return controller.isIdleForRelease();
21972
+ },
21751
21973
  __modelFallbackMeta() {
21752
21974
  return controller.currentModelFallbackMeta();
21753
21975
  },
@@ -21919,6 +22141,7 @@ function createWorkflowStageFactory(input) {
21919
22141
  liveHandleReleased: false,
21920
22142
  stageClosedByWorkflowExit: false,
21921
22143
  stageFinalized: false,
22144
+ sessionCheckpointed: false,
21922
22145
  skippedForParallelFailFast: false,
21923
22146
  stageControlDropped: false
21924
22147
  };
@@ -22316,6 +22539,26 @@ class EngineRuntime {
22316
22539
  }
22317
22540
  }
22318
22541
 
22542
+ // dist/builtin/workflows/src/engine/session-closed-error.ts
22543
+ import { isStaleExtensionContextError as isStaleExtensionContextError2 } from "@bastani/atomic";
22544
+ var MAX_CAUSE_DEPTH = 8;
22545
+ function reportsClosedSession(error) {
22546
+ return "code" in error && error.code === "SessionClosed" || isStaleExtensionContextError2(error);
22547
+ }
22548
+ function isSessionClosedError(error) {
22549
+ let current = error;
22550
+ for (let depth = 0;depth < MAX_CAUSE_DEPTH && current !== undefined; depth++) {
22551
+ try {
22552
+ if (reportsClosedSession(current))
22553
+ return true;
22554
+ current = current.cause instanceof Error ? current.cause : undefined;
22555
+ } catch {
22556
+ return false;
22557
+ }
22558
+ }
22559
+ return false;
22560
+ }
22561
+
22319
22562
  // dist/builtin/workflows/src/engine/workflow-activity.ts
22320
22563
  import { runCallback as runCallback4 } from "@bastani/atomic";
22321
22564
  function nextEventLoopTurn() {
@@ -22742,6 +22985,27 @@ async function executeRun(def, resolvedInputs, opts) {
22742
22985
  toolNodes: [...runSnapshot.toolNodes]
22743
22986
  };
22744
22987
  };
22988
+ const suspendForClosedSession = async (reason) => {
22989
+ abandonInFlightAsCancelled(reason);
22990
+ const durable = durableBackend.getWorkflow(runId);
22991
+ let resumable;
22992
+ if (durable?.status === "running") {
22993
+ resumable = isDurableWorkflowResumable({ ...durable, status: "paused", resumable: true });
22994
+ await transitionDurableWorkflowStatus(durableBackend, runId, ["running"], "paused", undefined, resumable);
22995
+ await recordRunTimingCheckpointAsync(durableBackend, runSnapshot);
22996
+ }
22997
+ activeStore.recordRunPaused(runId, undefined, {
22998
+ exitReason: WORKFLOW_GRACEFUL_QUIT_EXIT_REASON,
22999
+ ...resumable === undefined ? {} : { resumable }
23000
+ });
23001
+ return {
23002
+ runId,
23003
+ status: "paused",
23004
+ exitReason: WORKFLOW_GRACEFUL_QUIT_EXIT_REASON,
23005
+ stages: [...runSnapshot.stages],
23006
+ toolNodes: [...runSnapshot.toolNodes]
23007
+ };
23008
+ };
22745
23009
  const resolvePromptNodeTopology = createDurableStageTopologyResolver(durableBackend, runId);
22746
23010
  const priorPromptStageCheckpoints = durableBackend.listCheckpoints(runId).filter((checkpoint) => checkpoint.kind === "stage");
22747
23011
  let promptNodeUi;
@@ -23104,8 +23368,10 @@ async function executeRun(def, resolvedInputs, opts) {
23104
23368
  if (returned.status === "completed")
23105
23369
  assertFrontierConsumed();
23106
23370
  const recorded = activeStore.recordRunEnd(runId, returned.status, result, returned.error, returned.metadata);
23107
- if (opts.parentRun === undefined)
23371
+ if (opts.parentRun === undefined) {
23108
23372
  await recordRunTimingCheckpointAsync(durableBackend, runSnapshot);
23373
+ await recordRunResultCheckpointAsync(durableBackend, runSnapshot);
23374
+ }
23109
23375
  await durableBackend.commitWorkflowStatus(runId, returned.status, undefined, returned.metadata?.resumable);
23110
23376
  await appendRunEndWhenRecorded(opts.persistence, recorded, {
23111
23377
  runId,
@@ -23133,8 +23399,14 @@ async function executeRun(def, resolvedInputs, opts) {
23133
23399
  err = selectedTerminalEvent.error;
23134
23400
  }
23135
23401
  const gracefulQuit = observedQuitCancellation() ?? observedTaskTailQuit ?? findWorkflowGracefulQuit(err) ?? findWorkflowGracefulQuit(ownController.signal.reason);
23136
- if (gracefulQuit !== undefined)
23402
+ const ownerClosing = opts.adapters?.ownerSessionClosing?.() === true;
23403
+ if (gracefulQuit !== undefined) {
23404
+ if (ownerClosing && gracefulQuit.runId !== runId)
23405
+ return await suspendForClosedSession(gracefulQuit);
23137
23406
  return suspendForGracefulQuit(gracefulQuit);
23407
+ }
23408
+ if (ownerClosing && err instanceof Error && isSessionClosedError(err))
23409
+ return await suspendForClosedSession(err);
23138
23410
  await admittedTools.closeAndDrain();
23139
23411
  if (ownController.signal.aborted)
23140
23412
  await Promise.allSettled([...pendingChildWorkflows]);
@@ -23238,6 +23510,8 @@ async function executeRun(def, resolvedInputs, opts) {
23238
23510
  terminalEvents.dispose();
23239
23511
  if (opts.stageControlRegistry === undefined && opts.executionMode !== "interactive" && isTerminalRunStatus(runSnapshot.status) && runSnapshot.resumable !== true) {
23240
23512
  await stageRegistry.clear(runId);
23513
+ } else if (isTerminalRunStatus(runSnapshot.status)) {
23514
+ await stageRegistry.releaseIdle(runId);
23241
23515
  }
23242
23516
  }
23243
23517
  }
package/dist/cli.js CHANGED
@@ -13,6 +13,7 @@ import { APP_NAME, VERSION } from "./config.js";
13
13
  import { markLifecycleTiming } from "./core/lifecycle-timings.js";
14
14
  import { ATOMIC_AI_AGENT } from "./utils/agent-attribution.js";
15
15
  import { enablePersistentCompileCache } from "./utils/compile-cache.js";
16
+ import { headlessHeapRelaunchArgs, relaunchWithHeap } from "./utils/heap-relaunch.js";
16
17
  markLifecycleTiming("process-entry");
17
18
  enablePersistentCompileCache();
18
19
  process.title = APP_NAME;
@@ -24,10 +25,16 @@ if (args[0] === "--version" || args[0] === "-v") {
24
25
  console.log(VERSION);
25
26
  process.exit(0);
26
27
  }
27
- // No top-level await: the compiled binary is built with --bytecode (CJS),
28
- // which forbids TLA anywhere in the bundled graph.
29
- void Promise.all([import("./core/http-dispatcher.js"), import("./main.js")]).then(([{ configureHttpDispatcher }, { main }]) => {
30
- configureHttpDispatcher();
31
- main(args);
32
- });
28
+ const heapArgs = headlessHeapRelaunchArgs(args);
29
+ if (heapArgs.length > 0) {
30
+ relaunchWithHeap(heapArgs, args);
31
+ }
32
+ else {
33
+ // No top-level await: the compiled binary is built with --bytecode (CJS),
34
+ // which forbids TLA anywhere in the bundled graph.
35
+ void Promise.all([import("./core/http-dispatcher.js"), import("./main.js")]).then(([{ configureHttpDispatcher }, { main }]) => {
36
+ configureHttpDispatcher();
37
+ main(args);
38
+ });
39
+ }
33
40
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAExE,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAErC,4BAA4B,EAAE,CAAC;AAE/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,CAAC;AAC/D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,eAAe,CAAC;AACvC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAA+B,CAAC;AAE/D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,0EAA0E;AAC1E,mDAAmD;AACnD,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,2BAA2B,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAChF,CAAC,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;IAC3C,uBAAuB,EAAE,CAAC;IAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;AACZ,CAAC,CACD,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * CLI entry point for the refactored coding agent.\n * Uses main.ts with AgentSession and new mode modules.\n *\n * Test with: bun src/cli.ts [args...]\n *\n * Deliberately keeps the static entry graph to config, compile-cache support,\n * attribution, and the disabled-by-default lifecycle seam. The full CLI graph\n * loads dynamically so metadata fast paths (for example `--version`) skip it.\n */\nimport { APP_NAME, VERSION } from \"./config.js\";\nimport { markLifecycleTiming } from \"./core/lifecycle-timings.ts\";\nimport { ATOMIC_AI_AGENT } from \"./utils/agent-attribution.ts\";\nimport { enablePersistentCompileCache } from \"./utils/compile-cache.ts\";\n\nmarkLifecycleTiming(\"process-entry\");\n\nenablePersistentCompileCache();\n\nprocess.title = APP_NAME;\nprocess.env[`${APP_NAME.toUpperCase()}_CODING_AGENT`] = \"true\";\nprocess.env.AI_AGENT = ATOMIC_AI_AGENT;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nconst args = process.argv.slice(2);\n\nif (args[0] === \"--version\" || args[0] === \"-v\") {\n\tconsole.log(VERSION);\n\tprocess.exit(0);\n}\n\n// No top-level await: the compiled binary is built with --bytecode (CJS),\n// which forbids TLA anywhere in the bundled graph.\nvoid Promise.all([import(\"./core/http-dispatcher.ts\"), import(\"./main.ts\")]).then(\n\t([{ configureHttpDispatcher }, { main }]) => {\n\t\tconfigureHttpDispatcher();\n\t\tmain(args);\n\t},\n);\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEtF,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAErC,4BAA4B,EAAE,CAAC;AAE/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,CAAC;AAC/D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,eAAe,CAAC;AACvC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAA+B,CAAC;AAE/D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,MAAM,QAAQ,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;AAChD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IACzB,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;KAAM,CAAC;IACP,0EAA0E;IAC1E,mDAAmD;IACnD,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,2BAA2B,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAChF,CAAC,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;QAC3C,uBAAuB,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * CLI entry point for the refactored coding agent.\n * Uses main.ts with AgentSession and new mode modules.\n *\n * Test with: bun src/cli.ts [args...]\n *\n * Deliberately keeps the static entry graph to config, compile-cache support,\n * attribution, and the disabled-by-default lifecycle seam. The full CLI graph\n * loads dynamically so metadata fast paths (for example `--version`) skip it.\n */\nimport { APP_NAME, VERSION } from \"./config.js\";\nimport { markLifecycleTiming } from \"./core/lifecycle-timings.ts\";\nimport { ATOMIC_AI_AGENT } from \"./utils/agent-attribution.ts\";\nimport { enablePersistentCompileCache } from \"./utils/compile-cache.ts\";\nimport { headlessHeapRelaunchArgs, relaunchWithHeap } from \"./utils/heap-relaunch.ts\";\n\nmarkLifecycleTiming(\"process-entry\");\n\nenablePersistentCompileCache();\n\nprocess.title = APP_NAME;\nprocess.env[`${APP_NAME.toUpperCase()}_CODING_AGENT`] = \"true\";\nprocess.env.AI_AGENT = ATOMIC_AI_AGENT;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nconst args = process.argv.slice(2);\n\nif (args[0] === \"--version\" || args[0] === \"-v\") {\n\tconsole.log(VERSION);\n\tprocess.exit(0);\n}\n\nconst heapArgs = headlessHeapRelaunchArgs(args);\nif (heapArgs.length > 0) {\n\trelaunchWithHeap(heapArgs, args);\n} else {\n\t// No top-level await: the compiled binary is built with --bytecode (CJS),\n\t// which forbids TLA anywhere in the bundled graph.\n\tvoid Promise.all([import(\"./core/http-dispatcher.ts\"), import(\"./main.ts\")]).then(\n\t\t([{ configureHttpDispatcher }, { main }]) => {\n\t\t\tconfigureHttpDispatcher();\n\t\t\tmain(args);\n\t\t},\n\t);\n}\n"]}
package/dist/config.d.ts CHANGED
@@ -82,6 +82,7 @@ export declare const ENV_CLEAR_ON_SHRINK: string;
82
82
  export declare const ENV_HARDWARE_CURSOR: string;
83
83
  export declare const ENV_CLIPBOARD_OSC52: string;
84
84
  export declare const ENV_TIMING: string;
85
+ export declare const ENV_HEAP_MB: string;
85
86
  export declare const WORKFLOW_STAGE_SUBAGENT_GUARD_ENV: string;
86
87
  export declare function getEnvNames(name: string): string[];
87
88
  export declare function getEnvValue(name: string): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,WAAW,SAItB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,SAA2C,CAAC;AAEvE,gEAAgE;AAChE,eAAO,MAAM,YAAY,SAAyB,CAAC;AAcnD,YAAY,EAAE,aAAa,EAAE,iBAAiB,E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