@jskit-ai/assistant-core 0.1.240 → 0.1.241

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 (101) hide show
  1. package/examples/conversation/package.json +5 -5
  2. package/package.json +5 -5
  3. package/src/client/conversation/AssistantTranscript.vue +26 -29
  4. package/src/client/conversation/LongTextPreviewBlocks.vue +11 -0
  5. package/src/client/conversation/messageDelivery.js +8 -2
  6. package/src/client/conversation/useAssistantAttachments.js +1 -1
  7. package/src/server/conversation/agentRun.js +12 -198
  8. package/src/server/conversation/attachments.js +6 -5
  9. package/src/server/conversation/boundedToolLoop.js +160 -0
  10. package/src/server/conversation/claudeHistory.js +20 -16
  11. package/src/server/conversation/claudeProcess.js +2 -2
  12. package/src/server/conversation/claudeTurn.js +41 -38
  13. package/src/server/conversation/codexAuthPreflight.js +104 -0
  14. package/src/server/conversation/codexClient.js +11 -16
  15. package/src/server/conversation/codexConfiguration.js +112 -98
  16. package/src/server/conversation/codexConversationStore.js +189 -0
  17. package/src/server/conversation/codexConversations.js +47 -44
  18. package/src/server/conversation/codexDetachedTurn.js +12 -11
  19. package/src/server/conversation/codexEvents.js +95 -99
  20. package/src/server/conversation/codexHelperExecution.js +3 -13
  21. package/src/server/conversation/codexHelperThreadLedger.js +7 -13
  22. package/src/server/conversation/codexHelperThreadRecovery.js +2 -16
  23. package/src/server/conversation/codexHelperThreads.js +5 -6
  24. package/src/server/conversation/codexHistoryAdapter.js +32 -26
  25. package/src/server/conversation/codexMessageCommands.js +22 -22
  26. package/src/server/conversation/codexMessageDelivery.js +12 -7
  27. package/src/server/conversation/codexModelCatalog.js +97 -0
  28. package/src/server/conversation/codexNotificationObserver.js +24 -40
  29. package/src/server/conversation/codexNotificationQueue.js +2 -3
  30. package/src/server/conversation/codexOutput.js +20 -27
  31. package/src/server/conversation/codexProcess.js +123 -127
  32. package/src/server/conversation/codexProcessLeader.js +3 -3
  33. package/src/server/conversation/codexProvider.js +31 -614
  34. package/src/server/conversation/codexProviderOwner.js +2 -2
  35. package/src/server/conversation/codexProviderSelection.js +38 -40
  36. package/src/server/conversation/codexRenewalCommands.js +13 -10
  37. package/src/server/conversation/codexRenewalThreads.js +412 -0
  38. package/src/server/conversation/codexRunJournal.js +24 -42
  39. package/src/server/conversation/codexRuntimeLifecycle.js +19 -15
  40. package/src/server/conversation/codexSessionCleanup.js +11 -10
  41. package/src/server/conversation/codexSessionReconciliation.js +6 -6
  42. package/src/server/conversation/codexThreadReadiness.js +19 -33
  43. package/src/server/conversation/codexThreadStatus.js +3 -3
  44. package/src/server/conversation/codexTurn.js +124 -297
  45. package/src/server/conversation/codexTurnRecovery.js +49 -28
  46. package/src/server/conversation/codexTurnState.js +34 -13
  47. package/src/server/conversation/commandWrapper.js +3 -0
  48. package/src/server/conversation/deliveryTiming.js +14 -5
  49. package/src/server/conversation/index.js +1 -0
  50. package/src/server/conversation/localExecution.js +13 -17
  51. package/src/server/conversation/normalize.js +8 -3
  52. package/src/server/conversation/openCodeClient.js +9 -10
  53. package/src/server/conversation/openCodeProcess.js +9 -5
  54. package/src/server/conversation/openCodeRuntime.js +10 -11
  55. package/src/server/conversation/openCodeTurn.js +43 -29
  56. package/src/server/conversation/providers/claudeDriver.js +8 -16
  57. package/src/server/conversation/providers/codexDriver.js +25 -41
  58. package/src/server/conversation/providers/opencodeDriver.js +17 -42
  59. package/src/server/conversation/providers/scoped.js +48 -4
  60. package/src/server/conversation/runtime.js +50 -49
  61. package/src/server/conversation/runtimeStateUpgrade.js +34 -22
  62. package/src/server/conversation/transcript.js +10 -10
  63. package/src/server/hosts/codexConfiguration.js +1 -0
  64. package/src/server/hosts/codexProvider.js +8 -6
  65. package/src/server/index.js +2 -1
  66. package/src/server/lib/assistantToolLoop.js +1 -153
  67. package/src/server/lib/serviceToolCatalog.js +17 -42
  68. package/src/shared/assistantResource.js +4 -2
  69. package/src/shared/conversation/attachments.js +4 -0
  70. package/src/shared/conversation/longTextBlocks.js +54 -19
  71. package/src/shared/conversation/numberedQuestionSugar.js +17 -10
  72. package/src/shared/conversation/pagination.js +4 -6
  73. package/src/shared/conversation/patches.js +1 -4
  74. package/src/shared/conversation/streaming.js +3 -11
  75. package/src/shared/conversation/turns.js +11 -0
  76. package/src/shared/index.js +1 -0
  77. package/test/assistantBoundedToolLoop.test.js +2 -2
  78. package/test/assistantResource.test.js +4 -4
  79. package/test/assistantSettingsResource.test.js +2 -2
  80. package/test/claudeConversationSession.test.js +11 -1
  81. package/test/claudeTurn.test.js +27 -7
  82. package/test/codexClient.test.js +20 -0
  83. package/test/codexConversationSession.test.js +2 -2
  84. package/test/codexConversationsCheckpoint.test.js +51 -0
  85. package/test/codexModelCatalog.test.js +1 -1
  86. package/test/codexProviderHome.test.js +51 -0
  87. package/test/codexProviderSelection.test.js +71 -0
  88. package/test/codexTurn.test.js +222 -6
  89. package/test/conversationAgentRun.test.js +2 -1
  90. package/test/conversationAttachments.test.js +27 -2
  91. package/test/conversationDeliveryTiming.test.js +21 -0
  92. package/test/conversationNormalize.test.js +11 -0
  93. package/test/fixtures/nestedListQuestionMessage.md +37 -0
  94. package/test/frameworkActions.test.js +2 -2
  95. package/test/longTextBlocks.test.js +102 -0
  96. package/test/messageDelivery.test.js +7 -1
  97. package/test/openCodeClient.test.js +20 -0
  98. package/test/openCodeRuntime.test.js +1 -1
  99. package/test/openCodeTurn.test.js +90 -0
  100. package/test/opencodeConversationSession.test.js +1 -1
  101. package/test/serviceToolCatalog.test.js +27 -0
@@ -64,8 +64,7 @@ export { createCodexAppServerDetachedTurnWatcher, waitForCodexAppServerTurn } fr
64
64
  export { createCodexAppServerNotificationQueue } from "./codexNotificationQueue.js";
65
65
  import {
66
66
  assertCodexAppServerHelperAccountIdentity,
67
- createCodexHelperOwnershipError,
68
- readCodexAppServerAccountIdentity
67
+ createCodexHelperOwnershipError
69
68
  } from "./codexHelperExecution.js";
70
69
  export { sendPreparedCodexAppServerHelperTurn } from "./codexHelperExecution.js";
71
70
  import { createCodexHelperThreadLifecycle } from "./codexHelperThreads.js";
@@ -168,19 +167,11 @@ export function createCodexAppServerRunOwner({
168
167
  modelCatalogCacheMs,
169
168
  errorPrefix
170
169
  });
171
- const {
172
- ensureCodexAppServerProviderForActiveTurn,
173
- acquireCodexAppServerOutputProvider,
174
- codexAppServerRuntimeForVisibleTerminal,
175
- codexAppServerMessageContext,
176
- codexAppServerControlContext,
177
- codexAppServerObservationRecoveryContext
178
- } = codexProviderSelection;
179
170
  const acquireOutputProvider = providerSessions?.outputContext
180
171
  ? async ({ sessionId, runtime, session }) => {
181
172
  const prepared = await providerSessions.outputContext({ sessionId, runtime, session });
182
173
  if (!prepared) return null;
183
- return acquireCodexAppServerOutputProvider(
174
+ return codexProviderSelection.acquireCodexAppServerOutputProvider(
184
175
  sessionId, session, prepared.managedIdentity, prepared.providerOptions
185
176
  );
186
177
  }
@@ -202,31 +193,6 @@ export function createCodexAppServerRunOwner({
202
193
  messageMetadata,
203
194
  snapshotRecoveryItemLimit
204
195
  });
205
- const {
206
- finalizedTurns: codexAppServerFinalizedTurns,
207
- finalAssistantResults: codexAppServerFinalAssistantResults,
208
- reasoningTurns: codexAppServerReasoningTurns,
209
- reasoningPersistQueues: codexAppServerReasoningPersistQueues,
210
- liveProgressItems: codexAppServerLiveProgressItems,
211
- liveProgressFingerprints: codexAppServerLiveProgressFingerprints,
212
- mirroredTerminalItems: codexAppServerMirroredTerminalItems,
213
- resultFinalizationKey: codexAppServerResultFinalizationKey,
214
- liveProgressCandidate: codexAppServerLiveProgressCandidate,
215
- conversationMessageId: codexAppServerConversationMessageId,
216
- readAgentRunForSession: readCodexAppServerAgentRunForSession,
217
- readFinalAssistantResult: readCodexAppServerFinalAssistantResult,
218
- persistAssistantReply: persistCodexAppServerAssistantReply,
219
- recordFinalAssistantResult: recordCodexAppServerFinalAssistantResult,
220
- recordReasoningForSession: recordCodexAppServerReasoningForSession,
221
- flushReasoningPersist: flushCodexAppServerReasoningPersist,
222
- splitReasoningTurn: splitCodexAppServerReasoningTurn,
223
- cleanupUntrackedTurn: cleanupCodexAppServerUntrackedTurn,
224
- streamMessage: codexAppServerStreamMessage,
225
- writeStream: writeCodexAppServerStream,
226
- writeLiveProgress: writeCodexAppServerLiveProgress,
227
- submitAssistantResult: submitCodexAppServerAssistantResult,
228
- reconcileObservedTurnItems: reconcileCodexAppServerObservedTurnItems
229
- } = codexAppServerOutput;
230
196
 
231
197
  const codexRunJournal = createCodexRunJournal({
232
198
  namespace,
@@ -247,25 +213,6 @@ export function createCodexAppServerRunOwner({
247
213
  admissionTaskFinished,
248
214
  orphanedPromptMessage
249
215
  });
250
- const {
251
- completedTurns: codexAppServerCompletedTurns,
252
- processedTurns: codexAppServerProcessedTurns,
253
- activeTimers: codexAppServerActiveTimers,
254
- finalizingTimers: codexAppServerFinalizingTimers,
255
- turnResultWasProcessed: codexAppServerTurnResultWasProcessed,
256
- claimTurnStart: claimCodexAppServerTurnStart,
257
- claimMessageStart: claimCodexAppServerMessageStart,
258
- writeAgentRun: writeCodexAppServerAgentRun,
259
- clearActiveTimer: clearCodexAppServerActiveTimer,
260
- clearFinalizingTimer: clearCodexAppServerFinalizingTimer,
261
- clearSessionRecoveryTimers: clearCodexAppServerSessionRecoveryTimers,
262
- agentRunRealtimePayload: codexAppServerAgentRunRealtimePayload,
263
- publishAgentRun: publishCodexAppServerAgentRun,
264
- markTurnFinalizing: markCodexAppServerTurnFinalizing,
265
- markTurnIdle: markCodexAppServerTurnIdle,
266
- resolveTurnId: resolveCodexAppServerTurnId,
267
- writeUserMessageOwnership: writeCodexAppServerUserMessageOwnership
268
- } = codexRunJournal;
269
216
 
270
217
  const codexResultSettlement = createCodexResultSettlement({
271
218
  journal: codexRunJournal,
@@ -276,12 +223,6 @@ export function createCodexAppServerRunOwner({
276
223
  debugError,
277
224
  turnState
278
225
  });
279
- const {
280
- resultFinalizations: codexAppServerResultFinalizations,
281
- finalizeAssistantResult: finalizeCodexAppServerAssistantResult,
282
- recoverFinalResponseBeforeOutcome: recoverCodexAppServerFinalResponseBeforeOutcome,
283
- adoptSuccessorTurn: adoptCodexAppServerSuccessorTurn
284
- } = codexResultSettlement;
285
226
 
286
227
  const codexTurnRecovery = createCodexTurnRecovery({
287
228
  journal: codexRunJournal,
@@ -308,13 +249,6 @@ export function createCodexAppServerRunOwner({
308
249
  outcomeNotice,
309
250
  resultDeliveryFailureMessage
310
251
  });
311
- const {
312
- scheduleActiveRecovery: scheduleCodexAppServerActiveRecovery,
313
- markTurnActive: markCodexAppServerTurnActive,
314
- recoverActiveTurn: recoverCodexAppServerActiveTurn,
315
- completeTurn: completeCodexAppServerTurn,
316
- stopTurnWithProviderFailure: stopCodexAppServerTurnWithProviderFailure
317
- } = codexTurnRecovery;
318
252
 
319
253
  const codexThreadStatus = createCodexThreadStatus({
320
254
  journal: codexRunJournal,
@@ -327,10 +261,6 @@ export function createCodexAppServerRunOwner({
327
261
  debugLog,
328
262
  debugError
329
263
  });
330
- const {
331
- reconcileThreadStatus: reconcileCodexAppServerThreadStatus,
332
- reconcileLoadedThreadStatus: reconcileCodexAppServerLoadedThreadStatus
333
- } = codexThreadStatus;
334
264
 
335
265
  const codexMessageDelivery = createCodexAppServerMessageDelivery({
336
266
  namespace,
@@ -343,13 +273,6 @@ export function createCodexAppServerRunOwner({
343
273
  journal: codexRunJournal,
344
274
  recovery: codexTurnRecovery
345
275
  });
346
- const {
347
- messageDeliveries: codexAppServerMessageDeliveries,
348
- pendingUserMessages: codexAppServerPendingUserMessages,
349
- withMessageDelivery: withCodexAppServerMessageDelivery,
350
- writeDeliveredUserMessage: writeCodexAppServerDeliveredUserMessage,
351
- mirrorTerminalUserMessage: mirrorCodexAppServerTerminalUserMessage
352
- } = codexMessageDelivery;
353
276
 
354
277
  const codexNotificationObserver = createCodexNotificationObserver({
355
278
  journal: codexRunJournal,
@@ -367,15 +290,6 @@ export function createCodexAppServerRunOwner({
367
290
  onNotificationSignal,
368
291
  turnStateFromAgentRun
369
292
  });
370
- const {
371
- eventSubscriptions: codexAppServerEventSubscriptions,
372
- automaticHookThreads: codexAppServerAutomaticHookThreads,
373
- eventSubscriptionKey: codexAppServerEventSubscriptionKey,
374
- eventSubscriptionIsCurrent: codexAppServerEventSubscriptionIsCurrent,
375
- unsubscribeEventSubscription: unsubscribeCodexAppServerEventSubscription,
376
- reconcileGoalUpdated: reconcileCodexAppServerGoalUpdated,
377
- subscribeEvents: subscribeCodexAppServerEvents
378
- } = codexNotificationObserver;
379
293
 
380
294
  const codexThreadReadiness = createCodexThreadReadiness({
381
295
  providerSessions,
@@ -387,58 +301,24 @@ export function createCodexAppServerRunOwner({
387
301
  debugLog,
388
302
  debugError
389
303
  });
390
- const {
391
- threadReconciliations: codexAppServerThreadReconciliations,
392
- ensureThreadReady: ensureCodexAppServerThreadReady,
393
- reconcileThread: reconcileCodexAppServerThreadForSession,
394
- waitForThreadReconciliations: waitForOtherCodexAppServerThreadReconciliations,
395
- checkManagedConnection: checkCodexAppServerManagedConnection,
396
- restoreLoadedThread: restoreCodexAppServerLoadedThread
397
- } = codexThreadReadiness;
398
304
 
399
305
  const codexConversations = createCodexConversationCommands({
400
306
  checkpoint,
401
- codexAppServerConversationMessageId,
402
- codexAppServerStreamMessage,
307
+ codexAppServerConversationMessageId: codexAppServerOutput.conversationMessageId,
308
+ codexAppServerStreamMessage: codexAppServerOutput.streamMessage,
403
309
  conversationPreparation,
404
- ensureCodexAppServerProviderForActiveTurn,
310
+ ensureCodexAppServerProviderForActiveTurn: codexProviderSelection.ensureCodexAppServerProviderForActiveTurn,
405
311
  errorPrefix,
406
312
  helperLifecycle,
407
313
  helperOwnershipError,
408
314
  interruptFailedCode,
409
315
  namespace,
410
316
  providerSessions,
411
- steerFailedCode
317
+ sessionConnection: codexProviderSelection.sessionConnection,
318
+ ensureSessionProvider: codexProviderSelection.ensureSessionProvider,
319
+ steerFailedCode,
320
+ turnOutcomes
412
321
  });
413
- const {
414
- codexAppServerConversations,
415
- codexAppServerConversationTurnStarts,
416
- codexAppServerConversation,
417
- withCodexAppServerConversationTurnStart,
418
- observeCodexConversation,
419
- readPersistentCodexConversation,
420
- codexAppServerEphemeralConversationSnapshot,
421
- prepareCodexAppServerConversationThread,
422
- codexAppServerConversationContext,
423
- codexAppServerEphemeralScopeContext,
424
- createCodexAppServerConversation,
425
- runDetachedCodexAppServerConversation,
426
- startCodexAppServerConversationTurn,
427
- readCodexAppServerConversation,
428
- waitForCodexAppServerConversationTurn,
429
- stopCodexAppServerConversation,
430
- deleteScopedCodexAppServerConversation,
431
- closeCodexAppServerConversations,
432
- interruptDetachedCodexAppServerConversationTurn,
433
- deleteDetachedCodexAppServerConversationThread,
434
- steerCodexAppServerConversationTurn,
435
- acquireCodexAppServerDetachedThread,
436
- codexAppServerDetachedThreadId,
437
- dispatchCodexAppServerDetachedTurn,
438
- runDetachedCodexAppServerTurn,
439
- interruptCodexAppServerConversation,
440
- stopPersistentCodexConversation
441
- } = codexConversations;
442
322
 
443
323
  const codexObservationControl = createCodexObservationControl({
444
324
  conversations: codexConversations,
@@ -451,11 +331,6 @@ export function createCodexAppServerRunOwner({
451
331
  turnState,
452
332
  errorPrefix
453
333
  });
454
- const {
455
- assertThreadCanResume: assertCodexAppServerThreadCanResume,
456
- createObservation: createCodexAppServerObservation,
457
- recoverObservationLoss: recoverCodexAppServerObservationLoss
458
- } = codexObservationControl;
459
334
 
460
335
  const codexTurnControl = createCodexTurnControl({
461
336
  journal: codexRunJournal,
@@ -469,7 +344,6 @@ export function createCodexAppServerRunOwner({
469
344
  turnOutcomes,
470
345
  turnState
471
346
  });
472
- const { interruptTurn: interruptCodexAppServerTurn } = codexTurnControl;
473
347
 
474
348
  const codexMessageCommands = createCodexMessageCommands({
475
349
  output: codexAppServerOutput,
@@ -493,47 +367,34 @@ export function createCodexAppServerRunOwner({
493
367
  turnAlreadyRunningError,
494
368
  turnState
495
369
  });
496
- const {
497
- selectMessageTurn: selectCodexAppServerMessageTurn,
498
- dispatchMessage: dispatchCodexAppServerMessage,
499
- startTurn: startCodexAppServerTurn,
500
- steerTurn: steerCodexAppServerTurn
501
- } = codexMessageCommands;
502
370
 
503
- const {
504
- runCodexAppServerRenewalHandover,
505
- runCodexAppServerRenewalSeed
506
- } = createCodexRenewalCommands({
507
- claimCodexAppServerTurnStart,
371
+ const codexRenewalCommands = createCodexRenewalCommands({
372
+ claimCodexAppServerTurnStart: codexRunJournal.claimTurnStart,
508
373
  codexAppServerNotificationQueue,
509
- completeCodexAppServerTurn,
374
+ completeCodexAppServerTurn: codexTurnRecovery.completeTurn,
510
375
  errorPrefix,
511
- markCodexAppServerTurnActive,
512
- markCodexAppServerTurnIdle,
376
+ markCodexAppServerTurnActive: codexTurnRecovery.markTurnActive,
377
+ markCodexAppServerTurnIdle: codexRunJournal.markTurnIdle,
513
378
  observer: codexNotificationObserver,
514
379
  selection: codexProviderSelection,
515
380
  turnAlreadyRunningError,
516
- writeCodexAppServerUserMessageOwnership
381
+ writeCodexAppServerUserMessageOwnership: codexRunJournal.writeUserMessageOwnership
517
382
  });
518
383
 
519
- const {
520
- prepareCodexAppServerGoalContext,
521
- validateCodexAppServerGoalInput,
522
- updateCodexAppServerGoal
523
- } = createCodexGoalCommands({
524
- conversationContext: codexAppServerConversationContext,
525
- ensureThreadReady: ensureCodexAppServerThreadReady,
384
+ const codexGoalCommands = createCodexGoalCommands({
385
+ conversationContext: codexConversations.codexAppServerConversationContext,
386
+ ensureThreadReady: codexThreadReadiness.ensureThreadReady,
526
387
  publish,
527
- readCodexAppServerAgentRunForSession,
528
- reconcileCodexAppServerGoalUpdated,
529
- submitCodexAppServerAssistantResult,
530
- subscribeCodexAppServerEvents,
388
+ readCodexAppServerAgentRunForSession: codexAppServerOutput.readAgentRunForSession,
389
+ reconcileCodexAppServerGoalUpdated: codexNotificationObserver.reconcileGoalUpdated,
390
+ submitCodexAppServerAssistantResult: codexAppServerOutput.submitAssistantResult,
391
+ subscribeCodexAppServerEvents: codexNotificationObserver.subscribeEvents,
531
392
  turnState
532
393
  });
533
394
 
534
395
  function recoverSessionObservationLoss(sessionId, runtime, session, preparation) {
535
- return recoverCodexAppServerObservationLoss(runtime, session,
536
- codexAppServerObservationRecoveryContext(sessionId, preparation));
396
+ return codexObservationControl.recoverObservationLoss(runtime, session,
397
+ codexProviderSelection.codexAppServerObservationRecoveryContext(sessionId, preparation));
537
398
  }
538
399
 
539
400
  async function ensureSessionReadiness(sessionId, prepared) {
@@ -546,7 +407,7 @@ export function createCodexAppServerRunOwner({
546
407
  turn = turnState(session);
547
408
  }
548
409
  if (!turn.active) {
549
- const recovered = await submitCodexAppServerAssistantResult(sessionId, turn.threadId, turn.turnId, { recoverFromProvider: true });
410
+ const recovered = await codexAppServerOutput.submitAssistantResult(sessionId, turn.threadId, turn.turnId, { recoverFromProvider: true });
550
411
  if (recovered.reason === "error") throw new Error(recovered.error);
551
412
  }
552
413
  // A verified stop is a usable composer state, not a reconnect loop.
@@ -557,18 +418,18 @@ export function createCodexAppServerRunOwner({
557
418
  if (threadId && connection.available && turnState(session).state !== "starting") {
558
419
  const providerKey = codexProviderSelection.managedProviderKeyForThread(sessionId, workdir, threadId);
559
420
  if (providerKey !== null) {
560
- const observed = await checkCodexAppServerManagedConnection(providerKey, { reconnect: false });
421
+ const observed = await codexThreadReadiness.checkManagedConnection(providerKey, { reconnect: false });
561
422
  if (!observed.requiresPreparation) {
562
423
  return prepared.ready(threadId);
563
424
  }
564
425
  }
565
426
  }
566
- return prepared.prepare(ensureCodexAppServerThreadReady);
427
+ return prepared.prepare(codexThreadReadiness.ensureThreadReady);
567
428
  }
568
429
 
569
430
  async function readExecutionProfileModelCatalog(sessionId, preparation) {
570
431
  if (preparation.assistantScope) {
571
- const context = await codexAppServerEphemeralScopeContext(
432
+ const context = await codexConversations.codexAppServerEphemeralScopeContext(
572
433
  sessionId, { agentSettings: preparation.agentSettings }, preparation.assistantScope
573
434
  );
574
435
  if (context.ok === false) return context;
@@ -583,153 +444,105 @@ export function createCodexAppServerRunOwner({
583
444
 
584
445
  const runOwner = {
585
446
  helperThreads: helperLifecycle,
586
- readAccountIdentity: provider => readCodexAppServerAccountIdentity(provider, helperOwnershipError),
587
447
  assertAccountIdentity: (provider, expectedSignature) => assertCodexAppServerHelperAccountIdentity(
588
448
  provider, expectedSignature, helperOwnershipError
589
449
  ),
590
- checkManagedConnection: checkCodexAppServerManagedConnection,
591
450
  ensureSessionReadiness,
592
- recoverSessionObservationLoss,
593
- restoreLoadedThread: restoreCodexAppServerLoadedThread,
594
- reconcileThread: reconcileCodexAppServerThreadForSession,
595
- threadReconciliations: codexAppServerThreadReconciliations,
596
- waitForThreadReconciliations: waitForOtherCodexAppServerThreadReconciliations,
597
- conversations: codexAppServerConversations,
451
+ conversations: codexConversations.codexAppServerConversations,
598
452
  hasActiveTemporaryConversation: codexConversations.hasActiveConversation,
599
453
  readExecutionProfileModelCatalog,
600
454
  readProviderAccountIdentity: codexProviderSelection.readProviderAccountIdentity,
601
- conversationTurnStarts: codexAppServerConversationTurnStarts,
602
- conversation: codexAppServerConversation,
603
- conversationSnapshot: codexAppServerEphemeralConversationSnapshot,
604
- withConversationTurnStart: withCodexAppServerConversationTurnStart,
605
- observeConversation: observeCodexConversation,
606
- readPersistentConversation: readPersistentCodexConversation,
607
- createConversation: createCodexAppServerConversation,
608
- runDetachedConversation: runDetachedCodexAppServerConversation,
609
- steerConversationTurn: steerCodexAppServerConversationTurn,
610
- startConversationTurn: startCodexAppServerConversationTurn,
611
- acquireDetachedThread: acquireCodexAppServerDetachedThread,
612
- detachedThreadId: codexAppServerDetachedThreadId,
613
- dispatchDetachedTurn: dispatchCodexAppServerDetachedTurn,
614
- runDetachedTurn: runDetachedCodexAppServerTurn,
615
- interruptConversation: interruptCodexAppServerConversation,
616
- deleteConversation: deleteScopedCodexAppServerConversation,
617
- readConversation: readCodexAppServerConversation,
618
- stopConversation: stopCodexAppServerConversation,
619
- closeConversations: closeCodexAppServerConversations,
620
- conversationContext: codexAppServerConversationContext,
621
- ephemeralScopeContext: codexAppServerEphemeralScopeContext,
622
- prepareConversationThread: prepareCodexAppServerConversationThread,
623
- interruptDetachedTurn: interruptDetachedCodexAppServerConversationTurn,
624
- deleteDetachedThread: deleteDetachedCodexAppServerConversationThread,
625
- stopPersistentConversation: stopPersistentCodexConversation,
626
- waitForConversationTurn: waitForCodexAppServerConversationTurn,
627
- withMessageDelivery: withCodexAppServerMessageDelivery,
628
- dispatchMessage: dispatchCodexAppServerMessage,
629
- ensureThreadReady: ensureCodexAppServerThreadReady,
630
- messageContext: codexAppServerMessageContext,
631
- outputProvider: acquireCodexAppServerOutputProvider,
632
- runtimeForVisibleTerminal: codexAppServerRuntimeForVisibleTerminal,
633
- controlContext: codexAppServerControlContext,
634
- observationRecoveryContext: codexAppServerObservationRecoveryContext,
635
- claimMessageStart: claimCodexAppServerMessageStart,
636
- assertThreadCanResume: assertCodexAppServerThreadCanResume,
455
+ conversation: codexConversations.codexAppServerConversation,
456
+ readPersistentConversation: codexConversations.readPersistentCodexConversation,
457
+ createConversation: codexConversations.createCodexAppServerConversation,
458
+ runDetachedConversation: codexConversations.runDetachedCodexAppServerConversation,
459
+ startConversationTurn: codexConversations.startCodexAppServerConversationTurn,
460
+ acquireDetachedThread: codexConversations.acquireCodexAppServerDetachedThread,
461
+ detachedThreadId: codexConversations.codexAppServerDetachedThreadId,
462
+ dispatchDetachedTurn: codexConversations.dispatchCodexAppServerDetachedTurn,
463
+ runDetachedTurn: codexConversations.runDetachedCodexAppServerTurn,
464
+ deleteConversation: codexConversations.deleteScopedCodexAppServerConversation,
465
+ readConversation: codexConversations.readCodexAppServerConversation,
466
+ stopConversation: codexConversations.stopCodexAppServerConversation,
467
+ conversationContext: codexConversations.codexAppServerConversationContext,
468
+ prepareConversationThread: codexConversations.prepareCodexAppServerConversationThread,
469
+ interruptDetachedTurn: codexConversations.interruptDetachedCodexAppServerConversationTurn,
470
+ deleteDetachedThread: codexConversations.deleteDetachedCodexAppServerConversationThread,
471
+ stopPersistentConversation: codexConversations.stopPersistentCodexConversation,
472
+ waitForConversationTurn: codexConversations.waitForCodexAppServerConversationTurn,
473
+ withMessageDelivery: codexMessageDelivery.withMessageDelivery,
474
+ dispatchMessage: codexMessageCommands.dispatchMessage,
475
+ ensureThreadReady: codexThreadReadiness.ensureThreadReady,
476
+ runtimeForVisibleTerminal: codexProviderSelection.codexAppServerRuntimeForVisibleTerminal,
477
+ controlContext: codexProviderSelection.codexAppServerControlContext,
478
+ assertThreadCanResume: codexObservationControl.assertThreadCanResume,
637
479
  createObservation(sessionId, context = {}) {
638
- if (!providerSessions) return createCodexAppServerObservation(sessionId, context);
480
+ if (!providerSessions) return codexObservationControl.createObservation(sessionId, context);
639
481
  const { providerKey } = context;
640
- return createCodexAppServerObservation(sessionId, {
482
+ return codexObservationControl.createObservation(sessionId, {
641
483
  ...context,
642
484
  retireProvider: () => runOwner.runtimeLifecycle.retireProvider(providerKey)
643
485
  });
644
486
  },
645
- selectMessageTurn: selectCodexAppServerMessageTurn,
646
- interruptTurn: interruptCodexAppServerTurn,
647
- recoverObservationLoss: recoverCodexAppServerObservationLoss,
648
- runRenewalHandover: runCodexAppServerRenewalHandover,
649
- runRenewalSeed: runCodexAppServerRenewalSeed,
650
- startTurn: startCodexAppServerTurn,
651
- steerTurn: steerCodexAppServerTurn,
652
- prepareGoalContext: prepareCodexAppServerGoalContext,
653
- validateGoalInput: validateCodexAppServerGoalInput,
654
- updateGoal: updateCodexAppServerGoal,
487
+ selectMessageTurn: codexMessageCommands.selectMessageTurn,
488
+ interruptTurn: codexTurnControl.interruptTurn,
489
+ recoverObservationLoss: codexObservationControl.recoverObservationLoss,
490
+ runRenewalHandover: codexRenewalCommands.runCodexAppServerRenewalHandover,
491
+ runRenewalSeed: codexRenewalCommands.runCodexAppServerRenewalSeed,
492
+ startTurn: codexMessageCommands.startTurn,
493
+ steerTurn: codexMessageCommands.steerTurn,
494
+ prepareGoalContext: codexGoalCommands.prepareCodexAppServerGoalContext,
495
+ validateGoalInput: codexGoalCommands.validateCodexAppServerGoalInput,
496
+ updateGoal: codexGoalCommands.updateCodexAppServerGoal,
655
497
  notificationQueue: codexAppServerNotificationQueue,
656
- messageDeliveries: codexAppServerMessageDeliveries,
657
- pendingUserMessages: codexAppServerPendingUserMessages,
658
- eventSubscriptions: codexAppServerEventSubscriptions,
659
- completedTurns: codexAppServerCompletedTurns,
498
+ messageDeliveries: codexMessageDelivery.messageDeliveries,
499
+ pendingUserMessages: codexMessageDelivery.pendingUserMessages,
500
+ eventSubscriptions: codexNotificationObserver.eventSubscriptions,
660
501
  promptDeliveries: codexAppServerPromptDeliveries,
661
- automaticHookThreads: codexAppServerAutomaticHookThreads,
662
- eventSubscriptionKey: codexAppServerEventSubscriptionKey,
663
- eventSubscriptionIsCurrent: codexAppServerEventSubscriptionIsCurrent,
664
- unsubscribeEventSubscription: unsubscribeCodexAppServerEventSubscription,
665
- scheduleActiveRecovery: scheduleCodexAppServerActiveRecovery,
666
- reconcileThreadStatus: reconcileCodexAppServerThreadStatus,
667
- reconcileLoadedThreadStatus: reconcileCodexAppServerLoadedThreadStatus,
668
- writeUserMessageOwnership: writeCodexAppServerUserMessageOwnership,
669
- mirrorTerminalUserMessage: mirrorCodexAppServerTerminalUserMessage,
670
- reconcileObservedTurnItems: reconcileCodexAppServerObservedTurnItems,
671
- markTurnActive: markCodexAppServerTurnActive,
672
- adoptSuccessorTurn: adoptCodexAppServerSuccessorTurn,
673
- recoverActiveTurn: recoverCodexAppServerActiveTurn,
674
- completeTurn: completeCodexAppServerTurn,
675
- stopTurnWithProviderFailure: stopCodexAppServerTurnWithProviderFailure,
676
- reconcileGoalUpdated: reconcileCodexAppServerGoalUpdated,
677
- writeDeliveredUserMessage: writeCodexAppServerDeliveredUserMessage,
678
- subscribeEvents: subscribeCodexAppServerEvents,
679
- activeTimers: codexAppServerActiveTimers,
680
- finalizingTimers: codexAppServerFinalizingTimers,
681
- resultFinalizations: codexAppServerResultFinalizations,
682
- clearActiveTimer: clearCodexAppServerActiveTimer,
683
- clearFinalizingTimer: clearCodexAppServerFinalizingTimer,
684
- clearSessionRecoveryTimers: clearCodexAppServerSessionRecoveryTimers,
685
- agentRunRealtimePayload: codexAppServerAgentRunRealtimePayload,
686
- publishAgentRun: publishCodexAppServerAgentRun,
687
- markTurnFinalizing: markCodexAppServerTurnFinalizing,
688
- markTurnIdle: markCodexAppServerTurnIdle,
689
- resolveTurnId: resolveCodexAppServerTurnId,
690
- finalizeAssistantResult: finalizeCodexAppServerAssistantResult,
691
- recoverFinalResponseBeforeOutcome: recoverCodexAppServerFinalResponseBeforeOutcome,
692
- finalizedTurns: codexAppServerFinalizedTurns,
693
- finalAssistantResults: codexAppServerFinalAssistantResults,
694
- reasoningTurns: codexAppServerReasoningTurns,
695
- reasoningPersistQueues: codexAppServerReasoningPersistQueues,
696
- liveProgressItems: codexAppServerLiveProgressItems,
697
- liveProgressFingerprints: codexAppServerLiveProgressFingerprints,
698
- mirroredTerminalItems: codexAppServerMirroredTerminalItems,
699
- liveProgressCandidate: codexAppServerLiveProgressCandidate,
700
- conversationMessageId: codexAppServerConversationMessageId,
701
- readAgentRunForSession: readCodexAppServerAgentRunForSession,
702
- readFinalAssistantResult: readCodexAppServerFinalAssistantResult,
703
- persistAssistantReply: persistCodexAppServerAssistantReply,
704
- recordFinalAssistantResult: recordCodexAppServerFinalAssistantResult,
705
- recordReasoningForSession: recordCodexAppServerReasoningForSession,
706
- flushReasoningPersist: flushCodexAppServerReasoningPersist,
707
- splitReasoningTurn: splitCodexAppServerReasoningTurn,
708
- cleanupUntrackedTurn: cleanupCodexAppServerUntrackedTurn,
709
- writeStream: writeCodexAppServerStream,
710
- writeLiveProgress: writeCodexAppServerLiveProgress,
711
- submitAssistantResult: submitCodexAppServerAssistantResult,
712
- processedTurns: codexAppServerProcessedTurns,
713
- resultFinalizationKey: codexAppServerResultFinalizationKey,
714
- turnResultWasProcessed: codexAppServerTurnResultWasProcessed,
715
- claimTurnStart: claimCodexAppServerTurnStart,
716
- writeAgentRun: writeCodexAppServerAgentRun
502
+ unsubscribeEventSubscription: codexNotificationObserver.unsubscribeEventSubscription,
503
+ scheduleActiveRecovery: codexTurnRecovery.scheduleActiveRecovery,
504
+ reconcileThreadStatus: codexThreadStatus.reconcileThreadStatus,
505
+ mirrorTerminalUserMessage: codexMessageDelivery.mirrorTerminalUserMessage,
506
+ recoverActiveTurn: codexTurnRecovery.recoverActiveTurn,
507
+ completeTurn: codexTurnRecovery.completeTurn,
508
+ stopTurnWithProviderFailure: codexTurnRecovery.stopTurnWithProviderFailure,
509
+ writeDeliveredUserMessage: codexMessageDelivery.writeDeliveredUserMessage,
510
+ subscribeEvents: codexNotificationObserver.subscribeEvents,
511
+ activeTimers: codexRunJournal.activeTimers,
512
+ finalizingTimers: codexRunJournal.finalizingTimers,
513
+ resultFinalizations: codexResultSettlement.resultFinalizations,
514
+ clearSessionRecoveryTimers: codexRunJournal.clearSessionRecoveryTimers,
515
+ publishAgentRun: codexRunJournal.publishAgentRun,
516
+ markTurnIdle: codexRunJournal.markTurnIdle,
517
+ finalizeAssistantResult: codexResultSettlement.finalizeAssistantResult,
518
+ finalizedTurns: codexAppServerOutput.finalizedTurns,
519
+ liveProgressItems: codexAppServerOutput.liveProgressItems,
520
+ liveProgressFingerprints: codexAppServerOutput.liveProgressFingerprints,
521
+ readAgentRunForSession: codexAppServerOutput.readAgentRunForSession,
522
+ readFinalAssistantResult: codexAppServerOutput.readFinalAssistantResult,
523
+ persistAssistantReply: codexAppServerOutput.persistAssistantReply,
524
+ recordFinalAssistantResult: codexAppServerOutput.recordFinalAssistantResult,
525
+ recordReasoningForSession: codexAppServerOutput.recordReasoningForSession,
526
+ writeStream: codexAppServerOutput.writeStream,
527
+ writeLiveProgress: codexAppServerOutput.writeLiveProgress,
528
+ submitAssistantResult: codexAppServerOutput.submitAssistantResult,
529
+ processedTurns: codexRunJournal.processedTurns,
530
+ resultFinalizationKey: codexAppServerOutput.resultFinalizationKey,
531
+ claimTurnStart: codexRunJournal.claimTurnStart,
532
+ writeAgentRun: codexRunJournal.writeAgentRun
717
533
  };
718
- const cleanup = createCodexSessionCleanup({
719
- namespace,
720
- runOwner,
721
- providerSessions,
722
- helperLifecycle,
723
- journal: codexRunJournal,
724
- conversations: codexConversations,
725
- debugLog,
726
- debugError
727
- });
728
- runOwner.closeSession = cleanup.closeSession;
729
- runOwner.closeProject = cleanup.closeProject;
730
534
  if (providerSessions) {
731
535
  runOwner.runtimeLifecycle = createCodexRuntimeLifecycle({
732
- runOwner,
536
+ pendingWork: {
537
+ conversationTurnStarts: codexConversations.codexAppServerConversationTurnStarts,
538
+ messageDeliveries: codexMessageDelivery.messageDeliveries,
539
+ reasoningPersistQueues: codexAppServerOutput.reasoningPersistQueues,
540
+ resultFinalizations: codexResultSettlement.resultFinalizations,
541
+ threadReconciliations: codexThreadReadiness.threadReconciliations,
542
+ notificationTasks: codexAppServerNotificationQueue.tasks
543
+ },
544
+ observer: codexNotificationObserver,
545
+ checkManagedConnection: codexThreadReadiness.checkManagedConnection,
733
546
  providerSessions,
734
547
  helperLifecycle,
735
548
  captureContext,
@@ -744,9 +557,23 @@ export function createCodexAppServerRunOwner({
744
557
  }
745
558
  runOwner.invalidateRuntimes = runOwner.runtimeLifecycle.invalidateRuntimes;
746
559
  Object.assign(runOwner, createCodexSessionReconciliation({
747
- runOwner, providerSessions, helperLifecycle, lifecycle: runOwner.runtimeLifecycle,
560
+ readiness: codexThreadReadiness, recoverSessionObservationLoss,
561
+ providerSessions, helperLifecycle, lifecycle: runOwner.runtimeLifecycle,
748
562
  createRuntime, namespace, turnState, sessionIdRequiredError, debugLog, debugError
749
563
  }));
750
564
  }
565
+ const cleanup = createCodexSessionCleanup({
566
+ namespace,
567
+ runOwner,
568
+ providerSessions,
569
+ sessionClosures: runOwner.runtimeLifecycle?.sessionClosures,
570
+ helperLifecycle,
571
+ journal: codexRunJournal,
572
+ conversations: codexConversations,
573
+ debugLog,
574
+ debugError
575
+ });
576
+ runOwner.closeSession = cleanup.closeSession;
577
+ runOwner.closeProject = cleanup.closeProject;
751
578
  return runOwner;
752
579
  }