@sema-agent/client-core 0.97.1 → 0.99.0

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 (353) hide show
  1. package/CHANGELOG.md +607 -0
  2. package/README.md +96 -46
  3. package/dist/adapt/arms.d.ts +1 -0
  4. package/dist/adapt/arms.js +188 -53
  5. package/dist/adapt/ids.d.ts +12 -1
  6. package/dist/adapt/ids.js +59 -8
  7. package/dist/adapt/instanceLedger.d.ts +50 -0
  8. package/dist/adapt/instanceLedger.js +147 -0
  9. package/dist/adapt/panelTasks.d.ts +1 -1
  10. package/dist/adapt/panelTasks.js +2 -2
  11. package/dist/adapt/textStream.d.ts +1 -0
  12. package/dist/adapt/textStream.js +24 -7
  13. package/dist/adapt/toolCards.d.ts +27 -5
  14. package/dist/adapt/toolCards.js +39 -6
  15. package/dist/adapt/wireShapes.js +6 -2
  16. package/dist/adapt.d.ts +2 -0
  17. package/dist/adapt.js +8 -3
  18. package/dist/adapter/activeRunSelfHeal.d.ts +9 -3
  19. package/dist/adapter/activeRunSelfHeal.js +205 -313
  20. package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
  21. package/dist/adapter/downstream/eventToSdkMessage.js +77 -36
  22. package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
  23. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
  24. package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
  25. package/dist/adapter/runStream.js +79 -48
  26. package/dist/adapter/types.d.ts +4 -4
  27. package/dist/adapter/types.js +2 -1
  28. package/dist/agentSession/backgroundView.js +2 -1
  29. package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
  30. package/dist/agentSession/engineAgentRegistryRead.js +12 -13
  31. package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
  32. package/dist/agentsWireCaps.d.ts +8 -11
  33. package/dist/agentsWireCaps.js +196 -194
  34. package/dist/approvalDecidedByCapability.d.ts +0 -4
  35. package/dist/approvalDecidedByCapability.js +0 -6
  36. package/dist/approvalsStreamLiveCapability.d.ts +0 -4
  37. package/dist/approvalsStreamLiveCapability.js +0 -6
  38. package/dist/assistantInbox.d.ts +34 -0
  39. package/dist/assistantInbox.js +118 -0
  40. package/dist/centerWiringCapability.js +9 -1
  41. package/dist/clientSlice.d.ts +0 -9
  42. package/dist/clientSlice.js +0 -3
  43. package/dist/cloudConfigWireCaps.d.ts +5 -3
  44. package/dist/cloudConfigWireCaps.js +106 -64
  45. package/dist/compensations.js +1 -1
  46. package/dist/connectorStatus.d.ts +21 -0
  47. package/dist/connectorStatus.js +112 -0
  48. package/dist/controlRouter.d.ts +18 -3
  49. package/dist/controlRouter.js +106 -67
  50. package/dist/coreValuePorts.d.ts +29 -4
  51. package/dist/coreValuePorts.js +10 -0
  52. package/dist/corruptSessionCopy.d.ts +2 -1
  53. package/dist/corruptSessionCopy.js +3 -3
  54. package/dist/decideReceipt.d.ts +2 -2
  55. package/dist/decideReceipt.js +5 -2
  56. package/dist/declared/supportFloorDeclared.js +3 -3
  57. package/dist/detachWire.js +3 -2
  58. package/dist/deviceExecutorManagementCapability.d.ts +0 -4
  59. package/dist/deviceExecutorManagementCapability.js +0 -6
  60. package/dist/deviceRebind.d.ts +49 -1
  61. package/dist/deviceRebind.js +221 -3
  62. package/dist/devicesFace.d.ts +34 -0
  63. package/dist/devicesFace.js +90 -0
  64. package/dist/displayUntrusted.d.ts +2 -0
  65. package/dist/displayUntrusted.js +253 -76
  66. package/dist/engineAgentAbsence.d.ts +1 -1
  67. package/dist/engineAgentPanelStore.d.ts +12 -4
  68. package/dist/engineAgentPanelStore.js +16 -11
  69. package/dist/engineCapReader.d.ts +2 -5
  70. package/dist/engineCapReader.js +8 -10
  71. package/dist/engineCapsCache.d.ts +12 -0
  72. package/dist/engineCapsCache.js +76 -18
  73. package/dist/engineCapsChange.d.ts +2 -0
  74. package/dist/engineCapsChange.js +9 -0
  75. package/dist/engineClosedSets.d.ts +1 -0
  76. package/dist/engineClosedSets.js +4 -1
  77. package/dist/engineErrorCodes.d.ts +11 -3
  78. package/dist/engineErrorCodes.js +11 -8
  79. package/dist/engineIdentity.d.ts +1 -0
  80. package/dist/engineIdentity.js +8 -0
  81. package/dist/engineRowRef.d.ts +28 -0
  82. package/dist/engineRowRef.js +114 -0
  83. package/dist/engineSessionMessages.d.ts +68 -0
  84. package/dist/engineSessionMessages.js +370 -0
  85. package/dist/engineTargetSeat.d.ts +27 -0
  86. package/dist/engineTargetSeat.js +199 -0
  87. package/dist/engineToolDirectory.d.ts +0 -9
  88. package/dist/engineToolDirectory.js +1 -94
  89. package/dist/engineUrl.d.ts +18 -0
  90. package/dist/engineUrl.js +52 -0
  91. package/dist/engineWireFor.js +3 -8
  92. package/dist/env/uiLanguage.d.ts +11 -1
  93. package/dist/env/uiLanguage.js +38 -2
  94. package/dist/eventLeg.d.ts +100 -0
  95. package/dist/eventLeg.js +305 -0
  96. package/dist/executionLaneCapability.d.ts +0 -4
  97. package/dist/executionLaneCapability.js +3 -16
  98. package/dist/fileHistoryCaptureCapability.d.ts +2 -5
  99. package/dist/fileHistoryCaptureCapability.js +13 -21
  100. package/dist/fileHistoryLegNotice.d.ts +2 -1
  101. package/dist/fileHistoryLegNotice.js +3 -3
  102. package/dist/fleet/fleetLedger.d.ts +0 -3
  103. package/dist/fleet/fleetLedger.js +21 -36
  104. package/dist/fleet/fleetProjection.d.ts +2 -2
  105. package/dist/fleet/fleetProjection.js +10 -8
  106. package/dist/frameBinding.d.ts +8 -0
  107. package/dist/frameBinding.js +35 -0
  108. package/dist/gateFailureCodes.d.ts +2 -0
  109. package/dist/gateFailureCodes.js +15 -0
  110. package/dist/gateOutcome.d.ts +3 -1
  111. package/dist/gateOutcome.js +41 -8
  112. package/dist/gateVocabulary.d.ts +10 -4
  113. package/dist/gateVocabulary.js +107 -47
  114. package/dist/generated/engineAskFaceTables.js +2 -2
  115. package/dist/generated/engineFactTables.d.ts +22 -3
  116. package/dist/generated/engineFactTables.js +51 -4
  117. package/dist/generated/engineNoticeTables.js +18 -3
  118. package/dist/generated/settingsSchemaFns.d.ts +6 -0
  119. package/dist/generated/settingsSchemaFns.js +57 -0
  120. package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
  121. package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
  122. package/dist/generated/settingsSchemaTables.d.ts +1 -0
  123. package/dist/generated/settingsSchemaTables.js +4 -0
  124. package/dist/generated/settingsSchemaTypes.d.ts +105 -0
  125. package/dist/generated/settingsSchemaTypes.js +1 -0
  126. package/dist/generated/toolNameTables.d.ts +1 -0
  127. package/dist/generated/toolNameTables.js +1 -0
  128. package/dist/hitl/allowRuleShadow.d.ts +8 -2
  129. package/dist/hitl/allowRuleShadow.js +36 -29
  130. package/dist/hitl/approvalCardReading.d.ts +15 -0
  131. package/dist/hitl/approvalCardReading.js +154 -0
  132. package/dist/hitl/approvalCardReasons.d.ts +14 -0
  133. package/dist/hitl/approvalCardReasons.js +119 -0
  134. package/dist/hitl/approvalHolds.d.ts +50 -15
  135. package/dist/hitl/approvalHolds.js +177 -27
  136. package/dist/hitl/approvalResolution.d.ts +51 -26
  137. package/dist/hitl/approvalResolution.js +86 -122
  138. package/dist/hitl/approvalsFeed.js +6 -18
  139. package/dist/hitl/askClassPair.d.ts +2 -0
  140. package/dist/hitl/askClassPair.js +17 -0
  141. package/dist/hitl/askGateWire.d.ts +20 -2
  142. package/dist/hitl/askGateWire.js +50 -1
  143. package/dist/hitl/askParkRowRouting.d.ts +5 -0
  144. package/dist/hitl/askParkRowRouting.js +32 -1
  145. package/dist/hitl/askSettlementLine.d.ts +28 -0
  146. package/dist/hitl/askSettlementLine.js +99 -0
  147. package/dist/hitl/automaticAnswerVerdict.d.ts +3 -2
  148. package/dist/hitl/automaticAnswerVerdict.js +29 -13
  149. package/dist/hitl/crashConverged.d.ts +11 -20
  150. package/dist/hitl/crashConverged.js +56 -0
  151. package/dist/hitl/crashConvergedNotice.d.ts +6 -3
  152. package/dist/hitl/crashConvergedNotice.js +48 -24
  153. package/dist/hitl/decisionConflict.js +3 -10
  154. package/dist/hitl/decisionRefusal.d.ts +40 -1
  155. package/dist/hitl/decisionRefusal.js +199 -42
  156. package/dist/hitl/frameRouter.d.ts +5 -2
  157. package/dist/hitl/frameRouter.js +27 -24
  158. package/dist/hitl/gateLedger.d.ts +2 -0
  159. package/dist/hitl/gateLedger.js +50 -13
  160. package/dist/hitl/hitlBridge.d.ts +2 -2
  161. package/dist/hitl/hitlBridge.js +13 -10
  162. package/dist/hitl/livePendingAsk.d.ts +3 -3
  163. package/dist/hitl/livePendingAsk.js +7 -18
  164. package/dist/hitl/parkResolver.d.ts +2 -24
  165. package/dist/hitl/parkResolver.js +61 -97
  166. package/dist/hitl/persistedRulesWire.d.ts +25 -0
  167. package/dist/hitl/persistedRulesWire.js +104 -2
  168. package/dist/hitl/planReviewWire.d.ts +31 -13
  169. package/dist/hitl/planReviewWire.js +120 -78
  170. package/dist/hitl/refusedToolNameProse.d.ts +0 -1
  171. package/dist/hitl/refusedToolNameProse.js +0 -3
  172. package/dist/hitl/replayedApproval.d.ts +4 -3
  173. package/dist/hitl/replayedApproval.js +7 -4
  174. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  175. package/dist/hitl/sessionPolicyDeliverable.js +48 -7
  176. package/dist/hitl/sessionPolicyWire.d.ts +34 -21
  177. package/dist/hitl/sessionPolicyWire.js +179 -70
  178. package/dist/hitl/standingRows.d.ts +20 -2
  179. package/dist/hitl/standingRows.js +69 -8
  180. package/dist/hitl/suspendedReopen.d.ts +2 -1
  181. package/dist/hitl/suspendedReopen.js +7 -10
  182. package/dist/hitl/toolApprovalWire.d.ts +103 -156
  183. package/dist/hitl/toolApprovalWire.js +661 -411
  184. package/dist/hookMatcherVerdict.d.ts +6 -1
  185. package/dist/hookMatcherVerdict.js +14 -7
  186. package/dist/hooksWireCaps.d.ts +2 -2
  187. package/dist/hooksWireCaps.js +174 -81
  188. package/dist/host.d.ts +21 -0
  189. package/dist/hostTurnSettings.d.ts +71 -0
  190. package/dist/hostTurnSettings.js +291 -0
  191. package/dist/humanTurn.d.ts +14 -1
  192. package/dist/humanTurn.js +100 -12
  193. package/dist/humanTurnRead.d.ts +2 -0
  194. package/dist/humanTurnRead.js +22 -1
  195. package/dist/i18n/messages.en.d.ts +703 -0
  196. package/dist/i18n/messages.en.js +701 -0
  197. package/dist/i18n/messages.zh.d.ts +3 -0
  198. package/dist/i18n/messages.zh.js +837 -0
  199. package/dist/i18n/translate.d.ts +25 -0
  200. package/dist/i18n/translate.js +127 -0
  201. package/dist/index.d.ts +78 -29
  202. package/dist/index.js +54 -18
  203. package/dist/inheritEnvCapability.d.ts +32 -0
  204. package/dist/inheritEnvCapability.js +104 -0
  205. package/dist/inheritEnvWire.d.ts +3 -2
  206. package/dist/inheritEnvWire.js +12 -14
  207. package/dist/interactiveHalt.js +17 -6
  208. package/dist/liveModelCatalog.d.ts +3 -3
  209. package/dist/liveModelCatalog.js +15 -13
  210. package/dist/liveQuestionStore.d.ts +2 -21
  211. package/dist/mcpLiveness.d.ts +2 -1
  212. package/dist/mcpPanel.d.ts +10 -1
  213. package/dist/mcpPanel.js +40 -13
  214. package/dist/mcpProbeCapability.d.ts +2 -1
  215. package/dist/mcpProbeCapability.js +7 -11
  216. package/dist/mcpProbeWire.d.ts +9 -2
  217. package/dist/mcpProbeWire.js +6 -1
  218. package/dist/mcpWireCaps.d.ts +47 -2
  219. package/dist/mcpWireCaps.js +164 -16
  220. package/dist/memoryEntriesWire.d.ts +4 -9
  221. package/dist/memoryEntriesWire.js +5 -10
  222. package/dist/model/modelSupplyRules.d.ts +0 -2
  223. package/dist/model/modelSupplyRules.js +3 -12
  224. package/dist/model/modelsPolicy.d.ts +0 -5
  225. package/dist/model/modelsPolicy.js +6 -36
  226. package/dist/model/onboardJudgement.d.ts +93 -0
  227. package/dist/model/onboardJudgement.js +415 -0
  228. package/dist/model/subagentModelWord.d.ts +31 -0
  229. package/dist/model/subagentModelWord.js +261 -0
  230. package/dist/model/tierVocabulary.d.ts +2 -0
  231. package/dist/model/tierVocabulary.js +17 -5
  232. package/dist/modelCapabilityProbe.d.ts +64 -0
  233. package/dist/modelCapabilityProbe.js +600 -0
  234. package/dist/modelIdentityResolvability.d.ts +3 -0
  235. package/dist/modelIdentityResolvability.js +26 -17
  236. package/dist/notifications.d.ts +6 -0
  237. package/dist/notifications.js +71 -23
  238. package/dist/outputStyleSeatCapability.d.ts +0 -3
  239. package/dist/outputStyleSeatCapability.js +0 -3
  240. package/dist/ownKey.d.ts +22 -0
  241. package/dist/ownKey.js +94 -3
  242. package/dist/panelReduce.d.ts +21 -10
  243. package/dist/panelReduce.js +728 -550
  244. package/dist/panelStateHolder.d.ts +3 -7
  245. package/dist/panelStateHolder.js +14 -130
  246. package/dist/peerLaneCapability.d.ts +0 -4
  247. package/dist/peerLaneCapability.js +0 -6
  248. package/dist/permissionRuleIssue.js +2 -0
  249. package/dist/permissionRulesWriteCapability.d.ts +2 -5
  250. package/dist/permissionRulesWriteCapability.js +8 -12
  251. package/dist/permissionWireCaps.d.ts +2 -2
  252. package/dist/permissionWireCaps.js +2 -0
  253. package/dist/permissionsAllowGrantCapability.d.ts +0 -4
  254. package/dist/permissionsAllowGrantCapability.js +0 -6
  255. package/dist/permissionsDeclaration.d.ts +0 -11
  256. package/dist/permissionsDeclaration.js +60 -53
  257. package/dist/pluginHooksWire.d.ts +46 -3
  258. package/dist/pluginHooksWire.js +219 -16
  259. package/dist/preemptWire.d.ts +44 -0
  260. package/dist/preemptWire.js +83 -0
  261. package/dist/printModelStatus.d.ts +63 -0
  262. package/dist/printModelStatus.js +155 -0
  263. package/dist/printToolResultFrame.js +15 -4
  264. package/dist/replayBody.d.ts +3 -0
  265. package/dist/replayBody.js +14 -0
  266. package/dist/request/taskRequest.d.ts +11 -6
  267. package/dist/request/taskRequest.js +112 -19
  268. package/dist/resumeRefusalCopy.d.ts +13 -9
  269. package/dist/resumeRefusalCopy.js +81 -118
  270. package/dist/retryStatus.d.ts +45 -0
  271. package/dist/retryStatus.js +185 -1
  272. package/dist/rewindArchiveCapability.d.ts +0 -4
  273. package/dist/rewindArchiveCapability.js +2 -10
  274. package/dist/rewindArchiveReading.d.ts +0 -1
  275. package/dist/rewindArchiveReading.js +0 -3
  276. package/dist/runCancelContext.d.ts +2 -1
  277. package/dist/runCancelContext.js +4 -2
  278. package/dist/runReattachPolicy.d.ts +31 -0
  279. package/dist/runReattachPolicy.js +46 -0
  280. package/dist/runTerminal.d.ts +3 -6
  281. package/dist/runTerminal.js +8 -9
  282. package/dist/sandboxWire.d.ts +3 -1
  283. package/dist/sandboxWire.js +76 -27
  284. package/dist/scenarioRefusal.d.ts +9 -0
  285. package/dist/scenarioRefusal.js +111 -0
  286. package/dist/scenarioWire.js +1 -1
  287. package/dist/seam.d.ts +48 -2
  288. package/dist/seam.js +25 -4
  289. package/dist/seatContract.d.ts +311 -18
  290. package/dist/seatContract.js +824 -100
  291. package/dist/selfOrchestrationDenial.js +7 -19
  292. package/dist/sessionIdSegment.d.ts +6 -0
  293. package/dist/sessionIdSegment.js +24 -0
  294. package/dist/sessionMemoryStatus.js +6 -11
  295. package/dist/sessionPolicyCapability.d.ts +2 -5
  296. package/dist/sessionPolicyCapability.js +8 -12
  297. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
  298. package/dist/sessionSyncFileHistoryCapability.js +0 -3
  299. package/dist/settingsHooksSalvage.d.ts +44 -0
  300. package/dist/settingsHooksSalvage.js +211 -0
  301. package/dist/skillToolListsCapability.d.ts +2 -4
  302. package/dist/skillToolListsCapability.js +8 -9
  303. package/dist/sqlEngineCapability.d.ts +0 -4
  304. package/dist/sqlEngineCapability.js +0 -6
  305. package/dist/sseIdleTriage.js +3 -2
  306. package/dist/steerPriorityCapability.d.ts +0 -3
  307. package/dist/steerPriorityCapability.js +0 -3
  308. package/dist/streamDrainingLegs.d.ts +4 -0
  309. package/dist/streamDrainingLegs.js +6 -1
  310. package/dist/subagent/engineCompactWire.d.ts +0 -1
  311. package/dist/subagent/engineCompactWire.js +7 -5
  312. package/dist/subagent/engineSubagentResume.js +15 -9
  313. package/dist/subagent/engineTaskHandleWire.js +4 -7
  314. package/dist/subagentContentStore.d.ts +3 -0
  315. package/dist/subagentContentStore.js +22 -10
  316. package/dist/submitReopen.d.ts +24 -0
  317. package/dist/submitReopen.js +75 -0
  318. package/dist/terminalStatuses.d.ts +3 -0
  319. package/dist/terminalStatuses.js +10 -2
  320. package/dist/toolHistoryMismatch.js +3 -2
  321. package/dist/toolResult.d.ts +10 -1
  322. package/dist/toolResult.js +34 -6
  323. package/dist/toolRoster.d.ts +3 -4
  324. package/dist/toolRoster.js +21 -22
  325. package/dist/turnFailurePresentation.d.ts +39 -0
  326. package/dist/turnFailurePresentation.js +402 -0
  327. package/dist/usageAnalytics.js +6 -11
  328. package/dist/userAttachmentEnvelope.d.ts +1 -0
  329. package/dist/userAttachmentEnvelope.js +37 -7
  330. package/dist/userAttachmentSeat.d.ts +21 -0
  331. package/dist/userAttachmentSeat.js +75 -0
  332. package/dist/userInvokedSkillsCapability.d.ts +11 -4
  333. package/dist/userInvokedSkillsCapability.js +31 -10
  334. package/dist/webSearchBackendCapability.d.ts +0 -4
  335. package/dist/webSearchBackendCapability.js +0 -6
  336. package/dist/wireErrorTriage.d.ts +7 -0
  337. package/dist/wireErrorTriage.js +26 -23
  338. package/dist/wireFailureShape.d.ts +62 -5
  339. package/dist/wireFailureShape.js +106 -5
  340. package/dist/wireRefusalCopy.d.ts +25 -3
  341. package/dist/wireRefusalCopy.js +74 -80
  342. package/dist/workflowsJournalCapability.d.ts +2 -5
  343. package/dist/workflowsJournalCapability.js +8 -12
  344. package/dist/writeProtectionCapability.d.ts +0 -4
  345. package/dist/writeProtectionCapability.js +0 -6
  346. package/docs/INTEGRATION-CLIENTS.md +1775 -56
  347. package/package.json +6 -5
  348. package/dist/attachmentSeatCapability.d.ts +0 -12
  349. package/dist/attachmentSeatCapability.js +0 -23
  350. package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
  351. package/dist/hitl/approvalOutcomeNote.js +0 -29
  352. package/dist/sessionReadRedactionCapability.d.ts +0 -13
  353. package/dist/sessionReadRedactionCapability.js +0 -35
@@ -15,6 +15,7 @@ export interface ArmDeps extends ProjectionArmDeps {
15
15
  readonly panel: PanelTaskLedger;
16
16
  readonly flags: TurnFlags;
17
17
  readonly inst: AdapterInstanceLedger;
18
+ readonly pass: number;
18
19
  }
19
20
  export type ProjectionArmFn = (m: Frame, deps: ProjectionArmDeps) => Generator<AdapterOutput>;
20
21
  type ArmFn = (m: Frame, deps: ArmDeps) => Generator<AdapterOutput>;
@@ -1,8 +1,8 @@
1
- import { ccToolDenialKindForToolEnd } from '../gateOutcome.js';
1
+ import { ccToolDenialKindForToolEnd, gateOutcomeOf } from '../gateOutcome.js';
2
2
  import { isSubFlowSegmentEnd, SEGMENT_END_IDENTITY_KEYS, snapshotSegmentIdentity, snapshotIsSubFlow } from '../adapter/types.js';
3
3
  import { classifyPeerNotification, renderPeerFrameTranscriptText } from '../peerFrames.js';
4
4
  import { dropQueuedNotificationsForRun, isEngineWorkflowNotified, isWorkflowCompletionCardEnqueued, markEngineWorkflowNotified, noteOwnWorkflowRun, normalizeTaskNotification, noteWorkflowCompletionCardEnqueued, renderTaskNotificationXml, taskNotificationDedupKey } from '../notifications.js';
5
- import { mapBrainStatusToRetry } from '../retryStatus.js';
5
+ import { retryStatusFromArm } from '../retryStatus.js';
6
6
  import { steeringInjectedToAttachments } from '../steering.js';
7
7
  import { projectDiagnosticsFrame } from '../diagnostics.js';
8
8
  import { recordEngineToolLabel } from '../engineToolLabelStore.js';
@@ -12,13 +12,64 @@ import { recordWorkflowAgentTaskId } from '../workflow.js';
12
12
  import { isCoreTaskNotificationTerminal, isCoreTaskNotificationTerminalNotSuccess, isCoreTaskProgressTerminal, isCoreTaskProgressTerminalNotSuccess } from '../terminalStatuses.js';
13
13
  import { readToolHistoryMismatchKey } from '../toolHistoryMismatch.js';
14
14
  import { readProviderRejectionResendKey } from '../providerRejection.js';
15
- import { readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
16
- import { washCredentials } from '../displayUntrusted.js';
15
+ import { contextUsageReadingOf, guardedRead, humanInputAttachmentsOf, readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
16
+ import { CORE_USER_ATTACHMENT_LABEL_MAX } from '../generated/engineFactTables.js';
17
+ import { ESCAPE_FACE, paintAndCap, washCredentials } from '../displayUntrusted.js';
17
18
  import { resolveEnginePanelTaskId } from '../engineAgentPanelStore.js';
18
19
  import { fleetRowAgentType } from '../fleet/fleetRowAgentType.js';
19
20
  import { chrome, mainLane, transcript, messageIdentityOf } from './ids.js';
21
+ import { engineRefOf } from '../engineRowRef.js';
22
+ import { isReplayMarked, RESULT_REPLAYED_TEXT } from '../replayBody.js';
20
23
  import { wiringManifestViewOf } from '../adapter/downstream/wiringManifestView.js';
24
+ import { isUnsettledHeldToolEnd } from '../engineRowRef.js';
21
25
  import { CANCEL_MESSAGE, decisionOf, flattenWireOutput, REJECT_MESSAGE, sanitizeToolUseBlock, shortTaskLabel, TASK_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './wireShapes.js';
26
+ function hostOwnString(o, key) {
27
+ return readFrameStringKey(o, key);
28
+ }
29
+ function continuesParkDeclarationOf(ctx) {
30
+ const decl = guardedRead(() => ctx.continuesPark);
31
+ return typeof decl === 'object' && decl !== null ? decl : undefined;
32
+ }
33
+ function continuesParkWitness(ctx, row) {
34
+ const decl = continuesParkDeclarationOf(ctx);
35
+ if (decl === undefined)
36
+ return false;
37
+ if (hostOwnString(decl, 'toolCallId') !== row.toolCallId)
38
+ return false;
39
+ const cp = hostOwnString(decl, 'checkpointId');
40
+ if (cp !== undefined && row.checkpointId !== undefined && cp !== row.checkpointId)
41
+ return false;
42
+ const parkedTaskId = hostOwnString(decl, 'parkedTaskId');
43
+ if (parkedTaskId !== undefined && row.parkedRun !== undefined && parkedTaskId !== row.parkedRun)
44
+ return false;
45
+ return true;
46
+ }
47
+ function claimParkedCard(m, callId, toolName, deps) {
48
+ const { ctx, cards, inst, pass } = deps;
49
+ if (cards.has(callId))
50
+ return undefined;
51
+ const row = inst.parkedToolRowFor(ctx.sessionId, callId);
52
+ if (row === undefined)
53
+ return undefined;
54
+ if (readFrameStringKey(m, 'parentToolCallId') !== row.card.parentToolCallId)
55
+ return undefined;
56
+ if (toolName !== undefined && toolName !== row.card.name)
57
+ return undefined;
58
+ const frameRun = engineRefOf(m)?.taskId;
59
+ if (frameRun !== undefined) {
60
+ const decl = continuesParkDeclarationOf(ctx);
61
+ const allowed = [row.parkedRun, row.card.engineRef?.taskId, readFrameStringKey(decl, 'parkedTaskId'), readFrameStringKey(decl, 'continuationTaskId')].filter((x) => x !== undefined);
62
+ if (allowed.length > 0 && !allowed.includes(frameRun))
63
+ return undefined;
64
+ }
65
+ if (row.pass !== pass && !continuesParkWitness(ctx, row))
66
+ return undefined;
67
+ inst.dropParkedToolRow(row.key);
68
+ return row.card;
69
+ }
70
+ function laneOfCard(p) {
71
+ return p.parentToolCallId !== undefined && p.parentToolCallId !== '' ? { lane: 'subagent', parentToolCallId: p.parentToolCallId } : mainLane();
72
+ }
22
73
  function toolHistoryKeyCarry(m) {
23
74
  if (m._sema_api_error_message !== true)
24
75
  return {};
@@ -33,7 +84,8 @@ function providerResendKeyCarry(m) {
33
84
  const key = readProviderRejectionResendKey(typeof raw === 'object' && raw !== null ? raw : undefined);
34
85
  return key === undefined ? {} : { _sema_provider_rejection_resend: key };
35
86
  }
36
- const assistantArm = function* (m, { ctx, idOf, text, cards, inst }) {
87
+ const assistantArm = function* (m, deps) {
88
+ const { ctx, idOf, text, cards, inst } = deps;
37
89
  const message = m.message;
38
90
  const blocks = Array.isArray(message?.content)
39
91
  ? message.content
@@ -61,21 +113,27 @@ const assistantArm = function* (m, { ctx, idOf, text, cards, inst }) {
61
113
  }
62
114
  yield* text.takeAnswerSegment();
63
115
  yield* text.takeThinking();
64
- text.beginAssistantMessage();
65
- const cardIdentity = messageIdentityOf(m, ctx);
66
- yield transcript({
67
- type: 'assistant',
68
- message: {
69
- id: cards.mintResponseId(m),
70
- role: 'assistant',
71
- content: renderBlocks,
72
- ...(cardIdentity.model !== undefined ? { model: cardIdentity.model } : {}),
73
- },
74
- uuid: idOf(m),
75
- session_id: ctx.sessionId,
76
- parent_tool_use_id: null,
77
- ...(readFrameTrueMark(m, '_sema_tool_recovered') ? { _sema_tool_recovered: true } : {}),
78
- }, ctx.now());
116
+ const claimed = claimParkedCard(m, toolUseId, toolName, deps);
117
+ const startUuid = claimed !== undefined ? claimed.rowUuid : idOf(m);
118
+ if (claimed === undefined)
119
+ inst.noteStartRow(ctx.sessionId, toolUseId, startUuid);
120
+ if (claimed === undefined) {
121
+ text.beginAssistantMessage();
122
+ const cardIdentity = messageIdentityOf(m, ctx);
123
+ yield transcript({
124
+ type: 'assistant',
125
+ message: {
126
+ id: cards.mintResponseId(m),
127
+ role: 'assistant',
128
+ content: renderBlocks,
129
+ ...(cardIdentity.model !== undefined ? { model: cardIdentity.model } : {}),
130
+ },
131
+ uuid: startUuid,
132
+ session_id: ctx.sessionId,
133
+ parent_tool_use_id: null,
134
+ ...(readFrameTrueMark(m, '_sema_tool_recovered') ? { _sema_tool_recovered: true } : {}),
135
+ }, ctx.now());
136
+ }
79
137
  if (decision === 'reject' || decision === 'cancel') {
80
138
  cards.resetResponseId();
81
139
  yield transcript({
@@ -116,18 +174,23 @@ const assistantArm = function* (m, { ctx, idOf, text, cards, inst }) {
116
174
  }, ctx.now());
117
175
  return;
118
176
  }
119
- cards.open({
177
+ cards.open(claimed !== undefined ? { ...claimed, rawInput: san.rawInput } : {
120
178
  id: toolUseId,
121
179
  name: toolName,
122
180
  rawInput: san.rawInput,
123
181
  ...(san.eventId !== undefined ? { eventId: san.eventId } : {}),
124
182
  ...(san.parentToolCallId !== undefined ? { parentToolCallId: san.parentToolCallId } : {}),
183
+ engineRef: engineRefOf(m),
184
+ ...(startUuid !== undefined ? { rowUuid: startUuid } : {}),
125
185
  });
126
186
  if (WORKFLOW_TOOL_NAMES.has(toolName))
127
187
  inst.markWorkflowCard(toolUseId);
128
188
  return;
129
189
  }
130
190
  const textBlock = blocks.find(b => b?.type === 'text');
191
+ const thinkingBlock = blocks.find(b => b?.type === 'thinking');
192
+ if ((textBlock && typeof textBlock.text === 'string' && textBlock.text.length > 0) || (thinkingBlock && typeof thinkingBlock.thinking === 'string'))
193
+ text.anchorWindow(m);
131
194
  if (textBlock && typeof textBlock.text === 'string' && textBlock.text.length > 0) {
132
195
  const rowText = m._sema_api_error_message === true ? washCredentials(textBlock.text) : textBlock.text;
133
196
  text.appendAnswer(rowText);
@@ -145,7 +208,6 @@ const assistantArm = function* (m, { ctx, idOf, text, cards, inst }) {
145
208
  }, ctx.now());
146
209
  text.markEmittedText(rowText);
147
210
  }
148
- const thinkingBlock = blocks.find(b => b?.type === 'thinking');
149
211
  if (thinkingBlock && typeof thinkingBlock.thinking === 'string') {
150
212
  yield transcript({
151
213
  type: 'assistant',
@@ -249,8 +311,15 @@ const humanInputArm = function* (m) {
249
311
  ...(actor !== undefined && Object.keys(actor).length > 0 ? { actor } : {}),
250
312
  ...(str(m.entryId) !== undefined ? { entryId: str(m.entryId) } : {}),
251
313
  ...(str(m.eventId) !== undefined ? { eventId: str(m.eventId) } : {}),
314
+ ...humanInputAttachmentsForChrome(m),
252
315
  });
253
316
  };
317
+ function humanInputAttachmentsForChrome(m) {
318
+ const rows = humanInputAttachmentsOf(m);
319
+ if (rows === undefined)
320
+ return {};
321
+ return { attachments: rows.map((r) => (r.label !== undefined ? { ...r, label: paintAndCap(r.label, ESCAPE_FACE, CORE_USER_ATTACHMENT_LABEL_MAX) } : r)) };
322
+ }
254
323
  const messageCommittedArm = function* (m) {
255
324
  if (typeof m.parentToolCallId === 'string')
256
325
  return;
@@ -360,20 +429,13 @@ const toolRosterDeltaArm = function* (m) {
360
429
  const contextUsageArm = function* (m) {
361
430
  if (isSubFlowSegmentEnd(m))
362
431
  return;
363
- const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
364
- const usedTokens = num(m.usedTokens);
365
- const windowTokens = num(m.windowTokens);
366
- const compactAtTokens = num(m.compactAtTokens);
367
- const sections = Array.isArray(m.sections) ? m.sections : undefined;
368
- if (usedTokens === undefined && windowTokens === undefined && compactAtTokens === undefined && sections === undefined)
432
+ const reading = contextUsageReadingOf(m);
433
+ if (reading === undefined)
369
434
  return;
370
435
  yield chrome({
371
436
  kind: 'context_usage',
372
437
  laneProof: mainLane(),
373
- ...(usedTokens !== undefined ? { usedTokens } : {}),
374
- ...(windowTokens !== undefined ? { windowTokens } : {}),
375
- ...(compactAtTokens !== undefined ? { compactAtTokens } : {}),
376
- ...(sections !== undefined ? { sections } : {}),
438
+ ...reading,
377
439
  ...(typeof m.eventId === 'string' && m.eventId.length > 0 ? { eventId: m.eventId } : {}),
378
440
  });
379
441
  };
@@ -404,6 +466,51 @@ const compactionOutcomeArm = function* (m) {
404
466
  ...(eventId !== undefined ? { eventId } : {}),
405
467
  });
406
468
  };
469
+ const taskStartedArm = function* (m) {
470
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
471
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
472
+ const taskId = str(m.taskId);
473
+ if (taskId === undefined)
474
+ return;
475
+ const idSnap = snapshotSegmentIdentity(m);
476
+ if (idSnap === null)
477
+ return;
478
+ const parent = str(idSnap.parentToolCallId);
479
+ const laneProof = parent !== undefined ? { lane: 'subagent', parentToolCallId: parent } : mainLane();
480
+ const sessionId = str(m.sessionId);
481
+ const model = str(m.model);
482
+ const taskType = str(m.taskType);
483
+ const seq = num(m.seq);
484
+ const workflowRunId = str(m.workflowRunId);
485
+ const workflowAgentLabel = str(m.workflowAgentLabel);
486
+ const parentTaskId = str(m.parentTaskId);
487
+ const parentSessionId = str(m.parentSessionId);
488
+ const rootSessionId = str(m.rootSessionId);
489
+ const name = str(m.name);
490
+ const spawnName = str(m.spawnName);
491
+ const agentType = str(m.agentType);
492
+ const startedAt = num(m.startedAt);
493
+ const eventId = str(idSnap.eventId);
494
+ yield chrome({
495
+ kind: 'subagent_started',
496
+ laneProof,
497
+ taskId,
498
+ ...(sessionId !== undefined ? { sessionId } : {}),
499
+ ...(model !== undefined ? { model } : {}),
500
+ ...(taskType !== undefined ? { taskType } : {}),
501
+ ...(seq !== undefined ? { seq } : {}),
502
+ ...(workflowRunId !== undefined ? { workflowRunId } : {}),
503
+ ...(workflowAgentLabel !== undefined ? { workflowAgentLabel } : {}),
504
+ ...(parentTaskId !== undefined ? { parentTaskId } : {}),
505
+ ...(parentSessionId !== undefined ? { parentSessionId } : {}),
506
+ ...(rootSessionId !== undefined ? { rootSessionId } : {}),
507
+ ...(name !== undefined ? { name } : {}),
508
+ ...(spawnName !== undefined ? { spawnName } : {}),
509
+ ...(agentType !== undefined ? { agentType } : {}),
510
+ ...(startedAt !== undefined ? { startedAt } : {}),
511
+ ...(eventId !== undefined ? { eventId } : {}),
512
+ });
513
+ };
407
514
  const promptManifestRows = (v, pick) => {
408
515
  if (!Array.isArray(v))
409
516
  return undefined;
@@ -516,7 +623,8 @@ const promptSuggestionsArm = function* (m) {
516
623
  yield chrome({ kind: 'prompt_suggestions', laneProof: mainLane(), suggestions: list });
517
624
  }
518
625
  };
519
- const toolEndResultArm = function* (m, { idOf, cards, panel }) {
626
+ const toolEndResultArm = function* (m, deps) {
627
+ const { idOf, cards, panel, ctx, inst, pass } = deps;
520
628
  const callId = typeof m.toolCallId === 'string' ? m.toolCallId : undefined;
521
629
  recordEngineToolLabel(callId, m.label);
522
630
  if (callId !== undefined) {
@@ -524,10 +632,25 @@ const toolEndResultArm = function* (m, { idOf, cards, panel }) {
524
632
  if (launched !== null)
525
633
  registerSubagentContentAlias(callId, launched.taskId);
526
634
  }
635
+ if (callId !== undefined && isUnsettledHeldToolEnd(m)) {
636
+ const held = cards.detach(callId);
637
+ if (held !== undefined) {
638
+ inst.parkToolRow({ sessionId: ctx.sessionId, toolCallId: callId, card: held, pass });
639
+ yield chrome({ kind: 'tool_parked', laneProof: laneOfCard(held), toolUseId: callId, ...(held.rowUuid !== undefined ? { rowUuid: held.rowUuid } : {}) });
640
+ }
641
+ return;
642
+ }
527
643
  if (callId !== undefined) {
528
644
  yield* panel.settle(callId, m.isError === true, m.output !== undefined ? flattenWireOutput(m.output) : undefined);
529
645
  }
530
- const p = callId !== undefined ? cards.peek(callId) : undefined;
646
+ let p = callId !== undefined ? cards.peek(callId) : undefined;
647
+ if (p === undefined && callId !== undefined) {
648
+ const claimed = claimParkedCard(m, callId, readFrameStringKey(m, 'toolName'), deps);
649
+ if (claimed !== undefined) {
650
+ cards.open(claimed);
651
+ p = claimed;
652
+ }
653
+ }
531
654
  if (p === undefined || callId === undefined)
532
655
  return;
533
656
  const structured = m.structured;
@@ -537,6 +660,7 @@ const toolEndResultArm = function* (m, { idOf, cards, panel }) {
537
660
  const closeParent = typeof closeParentRaw === 'string' ? closeParentRaw : undefined;
538
661
  const stampedRaw = m._sema_denial_kind;
539
662
  const closeDenialKindRaw = typeof stampedRaw === 'string' ? stampedRaw : ccToolDenialKindForToolEnd(m);
663
+ const closeGate = guardedRead(() => gateOutcomeOf(m));
540
664
  yield* cards.close(p, {
541
665
  output: m.output,
542
666
  structured,
@@ -544,8 +668,10 @@ const toolEndResultArm = function* (m, { idOf, cards, panel }) {
544
668
  isError: m.isError === true,
545
669
  eventId: closeEventId,
546
670
  parentToolCallId: closeParent,
671
+ engineRef: engineRefOf(m),
547
672
  ...(typeof closeDenialKindRaw === 'string' ? { denialKind: closeDenialKindRaw } : {}),
548
- ...(readFrameTrueMark(m, 'notExecuted') ? { notExecuted: true } : {}),
673
+ ...(closeGate !== undefined ? { gate: closeGate } : {}),
674
+ closeArm: m,
549
675
  });
550
676
  const s = structured !== undefined && structured !== null && typeof structured === 'object'
551
677
  ? structured
@@ -641,7 +767,7 @@ const taskProgressArm = function* (m, { ctx, cards, panel, inst }) {
641
767
  : typeof input.task === 'string'
642
768
  ? input.task
643
769
  : undefined;
644
- const identity = resolveEnginePanelTaskId(taskId, explicitParent);
770
+ const identity = resolveEnginePanelTaskId(taskId);
645
771
  if (!panel.isLive(taskId)) {
646
772
  yield* panel.start(taskId, fleetRowAgentType(identity.taskId));
647
773
  }
@@ -761,6 +887,8 @@ const resultArm = function* (m, { ctx, idOf, text, cards, panel, flags }) {
761
887
  resultLength: terminalText.length,
762
888
  });
763
889
  }
890
+ if (isReplayMarked(m))
891
+ yield chrome({ kind: 'result_replayed', laneProof: mainLane(), text: RESULT_REPLAYED_TEXT });
764
892
  };
765
893
  const taskNotificationArm = function* (m, { ctx, idOf, panel, inst }) {
766
894
  const n = (m.notification ?? {});
@@ -801,7 +929,8 @@ const taskNotificationArm = function* (m, { ctx, idOf, panel, inst }) {
801
929
  });
802
930
  dropQueuedNotificationsForRun(taskId);
803
931
  if (n.task_type !== 'background_bash' && n.task_type !== 'monitor') {
804
- yield* panel.settleFromNotification(taskId, isCoreTaskNotificationTerminalNotSuccess(rawStatus));
932
+ const bgSessionId = n.task_type === 'background_agent' && typeof n.sessionId === 'string' && n.sessionId.length > 0 ? n.sessionId : undefined;
933
+ yield* panel.settleFromNotification(taskId, isCoreTaskNotificationTerminalNotSuccess(rawStatus), bgSessionId);
805
934
  }
806
935
  }
807
936
  const peerFrame = classifyPeerNotification(n);
@@ -844,23 +973,9 @@ const workflowCompleteArm = function* (m) {
844
973
  });
845
974
  };
846
975
  const retryStatusArm = function* (m, { ctx, flags }) {
847
- if (typeof m.parentToolCallId === 'string')
976
+ const status = retryStatusFromArm(m, ctx.now());
977
+ if (status === undefined)
848
978
  return;
849
- const status = mapBrainStatusToRetry({
850
- phase: typeof m.phase === 'string' ? m.phase : '',
851
- ...(typeof m.detail === 'string' ? { detail: m.detail } : {}),
852
- ...(typeof m.retryInSec === 'number' ? { retryInSec: m.retryInSec } : {}),
853
- ...(typeof m.retryInMs === 'number' ? { retryInMs: m.retryInMs } : {}),
854
- ...(typeof m.attempt === 'number' ? { attempt: m.attempt } : {}),
855
- ...(typeof m.maxRetries === 'number' ? { maxRetries: m.maxRetries } : {}),
856
- ...(typeof m.errClass === 'string' ? { errClass: m.errClass } : {}),
857
- ...(typeof m.retryAtMs === 'number' ? { retryAtMs: m.retryAtMs } : {}),
858
- ...(typeof m.errorStatus === 'number' ? { errorStatus: m.errorStatus } : {}),
859
- ...(typeof m.elapsedMs === 'number' ? { elapsedMs: m.elapsedMs } : {}),
860
- ...(typeof m.timeoutMs === 'number' ? { timeoutMs: m.timeoutMs } : {}),
861
- ...(typeof m.providerCondition === 'string' && m.providerCondition.length > 0 ? { providerCondition: m.providerCondition } : {}),
862
- ...(typeof m.providerConditionSource === 'string' && m.providerConditionSource.length > 0 ? { providerConditionSource: m.providerConditionSource } : {}),
863
- }, ctx.now());
864
979
  if (status === null) {
865
980
  if (flags.takeRetryOverlay())
866
981
  yield chrome({ kind: 'retry_status', laneProof: mainLane(), status: null });
@@ -869,11 +984,31 @@ const retryStatusArm = function* (m, { ctx, flags }) {
869
984
  yield chrome({ kind: 'retry_status', laneProof: mainLane(), status });
870
985
  flags.noteRetryOverlay();
871
986
  };
987
+ const terminalFactArm = function* (m, { ctx, inst, pass }) {
988
+ const taskId = readFrameStringKey(m, 'taskId');
989
+ const paused = guardedRead(() => {
990
+ const d = Object.getOwnPropertyDescriptor(m, 'paused');
991
+ return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
992
+ });
993
+ if (typeof paused === 'object' && paused !== null) {
994
+ const heldCallId = readFrameStringKey(paused, 'heldCallId');
995
+ const checkpointId = readFrameStringKey(paused, 'checkpointId');
996
+ inst.noteParkedFact(ctx.sessionId, pass, {
997
+ ...(heldCallId !== undefined ? { heldCallId } : {}),
998
+ ...(checkpointId !== undefined ? { checkpointId } : {}),
999
+ ...(taskId !== undefined ? { taskId } : {}),
1000
+ });
1001
+ return;
1002
+ }
1003
+ inst.retireParkedRowsOfRun(ctx.sessionId, pass, taskId);
1004
+ };
872
1005
  export const ARMS = new Map([
873
1006
  ['assistant', assistantArm],
1007
+ ['terminal_fact', terminalFactArm],
874
1008
  ['user', userArm],
875
1009
  ['tool_end_result', toolEndResultArm],
876
1010
  ['task_progress', taskProgressArm],
1011
+ ['task_started', taskStartedArm],
877
1012
  ['stream_event', streamEventArm],
878
1013
  ['turn_usage', turnUsageArm],
879
1014
  ['result', resultArm],
@@ -1,7 +1,16 @@
1
1
  import type { AdapterContext, AdapterOutput, ChromeEvent, LaneProof } from '../seam.js';
2
+ import { type EngineRowRef } from '../engineRowRef.js';
2
3
  export type Frame = Record<string, unknown>;
3
4
  export declare const mainLane: () => LaneProof;
4
- export type IdOf = (frame: Frame, suffix?: string) => string;
5
+ export interface RowSidecars {
6
+ readonly ref?: EngineRowRef;
7
+ readonly replay?: true;
8
+ }
9
+ export interface IdOf {
10
+ (frame: Frame, suffix?: string): string;
11
+ adopt(id: string, ref: EngineRowRef | undefined): string;
12
+ sidecarsOfId(id: string): RowSidecars | undefined;
13
+ }
5
14
  export declare function messageIdentityOf(frame: Frame, ctx: {
6
15
  model?: string;
7
16
  }): {
@@ -11,3 +20,5 @@ export declare function messageIdentityOf(frame: Frame, ctx: {
11
20
  export declare const chrome: (event: ChromeEvent) => AdapterOutput;
12
21
  export declare const transcript: (message: Frame, nowMs: number) => AdapterOutput;
13
22
  export declare function makeIdOf(ctx: AdapterContext): IdOf;
23
+ export declare function segmentRowId(idOf: IdOf, open: Frame, close: Frame | null, tag: 'text' | 'thinking'): string;
24
+ export declare function carryRowSidecars(out: AdapterOutput, idOf: IdOf): AdapterOutput;
package/dist/adapt/ids.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { deriveTranscriptId } from '../seam.js';
2
+ import { engineRefOf } from '../engineRowRef.js';
3
+ import { isReplayMarked } from '../replayBody.js';
2
4
  export const mainLane = () => ({ lane: 'main' });
3
5
  export function messageIdentityOf(frame, ctx) {
4
6
  const msg = frame.message;
@@ -24,17 +26,66 @@ export const transcript = (message, nowMs) => {
24
26
  : { ...message, timestamp: new Date(nowMs).toISOString() }),
25
27
  };
26
28
  };
29
+ function frameKeyOf(frame) {
30
+ if (frame === null)
31
+ return undefined;
32
+ return typeof frame.id === 'string' && frame.id.length > 0
33
+ ? frame.id
34
+ : typeof frame.uuid === 'string' && frame.uuid.length > 0
35
+ ? frame.uuid
36
+ : undefined;
37
+ }
27
38
  export function makeIdOf(ctx) {
28
- return (frame, suffix) => {
29
- const base = typeof frame.id === 'string' && frame.id.length > 0
30
- ? frame.id
31
- : typeof frame.uuid === 'string' && frame.uuid.length > 0
32
- ? frame.uuid
33
- : undefined;
34
- return deriveTranscriptId({
39
+ const ledger = new Map();
40
+ const note = (id, ref, replay) => {
41
+ if ((ref === undefined && !replay) || ledger.has(id))
42
+ return;
43
+ ledger.set(id, { ...(ref !== undefined ? { ref } : {}), ...(replay ? { replay: true } : {}) });
44
+ };
45
+ const idOf = (frame, suffix) => {
46
+ const base = frameKeyOf(frame);
47
+ const id = deriveTranscriptId({
35
48
  ...(base !== undefined ? { id: base } : {}),
36
- ...(typeof frame.seq === 'number' ? { seq: frame.seq } : {}),
37
49
  ...(typeof frame.toolCallId === 'string' ? { toolCallId: frame.toolCallId } : {}),
38
50
  }, ctx, suffix);
51
+ note(id, engineRefOf(frame), isReplayMarked(frame));
52
+ return id;
53
+ };
54
+ return Object.assign(idOf, {
55
+ adopt: (id, ref) => {
56
+ note(id, ref, false);
57
+ return id;
58
+ },
59
+ sidecarsOfId: (id) => {
60
+ const row = ledger.get(id);
61
+ if (row === undefined)
62
+ return undefined;
63
+ return { ...(row.ref !== undefined ? { ref: { ...row.ref } } : {}), ...(row.replay === true ? { replay: true } : {}) };
64
+ },
65
+ });
66
+ }
67
+ export function segmentRowId(idOf, open, close, tag) {
68
+ const closeKey = frameKeyOf(close);
69
+ if (closeKey === undefined)
70
+ return idOf.adopt(idOf({}, tag), engineRefOf(open));
71
+ return idOf(open, `${tag}~${closeKey}`);
72
+ }
73
+ export function carryRowSidecars(out, idOf) {
74
+ if (out.plane !== 'transcript')
75
+ return out;
76
+ const row = out.message;
77
+ const uuid = row.uuid;
78
+ if (typeof uuid !== 'string')
79
+ return out;
80
+ const side = idOf.sidecarsOfId(uuid);
81
+ if (side === undefined)
82
+ return out;
83
+ const addRef = side.ref !== undefined && !Object.hasOwn(row, '_sema_engine_ref');
84
+ const addReplay = side.replay === true && !Object.hasOwn(row, '_sema_replay');
85
+ if (!addRef && !addReplay)
86
+ return out;
87
+ return {
88
+ plane: 'transcript',
89
+ message: Object.assign({}, out.message, addRef ? { _sema_engine_ref: side.ref } : {}, addReplay ? { _sema_replay: true } : {}),
39
90
  };
40
91
  }
@@ -1,3 +1,17 @@
1
+ import type { PendingToolUse } from './toolCards.js';
2
+ import type { EngineRowRef } from '../engineRowRef.js';
3
+ export declare const PARKED_TOOL_ROWS_MAX = 64;
4
+ export declare const LATEST_START_ROWS_MAX = 1024;
5
+ export interface ParkedToolRow {
6
+ readonly key: string;
7
+ readonly sessionId: string;
8
+ readonly toolCallId: string;
9
+ readonly card: PendingToolUse;
10
+ readonly pass?: number;
11
+ readonly seq: number;
12
+ parkedRun?: string;
13
+ checkpointId?: string;
14
+ }
1
15
  export interface AdapterInstanceLedger {
2
16
  hasRenderedNotification(key: string): boolean;
3
17
  addRenderedNotification(key: string): void;
@@ -7,5 +21,41 @@ export interface AdapterInstanceLedger {
7
21
  markWorkflowCard(toolUseId: string): void;
8
22
  hasFiredSubagentStart(taskId: string): boolean;
9
23
  markFiredSubagentStart(taskId: string): void;
24
+ beginPass(): number;
25
+ parkToolRow(row: ParkToolRowInput): void;
26
+ parkedToolRowFor(sessionId: string, toolCallId: string): ParkedToolRow | undefined;
27
+ noteParkedFact(sessionId: string, pass: number, fact: ParkedTerminalFact): void;
28
+ retireParkedRowsOfRun(sessionId: string, pass: number, taskId: string | undefined): void;
29
+ dropParkedToolRow(key: string): void;
30
+ noteStartRow(sessionId: string, toolCallId: string, rowUuid: string | undefined): void;
31
+ listParkedToolRows(): ParkedToolRowSnapshot[];
32
+ takeParkedToolRows(rows: {} | null | undefined): number;
33
+ }
34
+ export interface ParkToolRowInput {
35
+ readonly sessionId: string;
36
+ readonly toolCallId: string;
37
+ readonly card: PendingToolUse;
38
+ readonly pass: number;
39
+ }
40
+ export interface ParkedTerminalFact {
41
+ readonly heldCallId?: string;
42
+ readonly checkpointId?: string;
43
+ readonly taskId?: string;
44
+ }
45
+ export interface ParkedToolCardSnapshot {
46
+ readonly id: string;
47
+ readonly name: string;
48
+ readonly rawInput: {} | null | undefined;
49
+ readonly eventId?: string;
50
+ readonly parentToolCallId?: string;
51
+ readonly rowUuid?: string;
52
+ readonly engineRef?: EngineRowRef;
53
+ }
54
+ export interface ParkedToolRowSnapshot {
55
+ readonly sessionId: string;
56
+ readonly toolCallId: string;
57
+ readonly parkedRun?: string;
58
+ readonly checkpointId?: string;
59
+ readonly card: ParkedToolCardSnapshot;
10
60
  }
11
61
  export declare function createAdapterInstanceLedger(): AdapterInstanceLedger;