@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
@@ -1,8 +1,155 @@
1
+ export const PARKED_TOOL_ROWS_MAX = 64;
2
+ export const LATEST_START_ROWS_MAX = 1024;
3
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
4
+ function ownData(o, key) {
5
+ try {
6
+ if (typeof o !== 'object' || o === null)
7
+ return undefined;
8
+ const d = Object.getOwnPropertyDescriptor(o, key);
9
+ return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
10
+ }
11
+ catch {
12
+ return undefined;
13
+ }
14
+ }
1
15
  export function createAdapterInstanceLedger() {
2
16
  const renderedNotifications = new Set();
3
17
  const seenWorkflowToolCallIds = new Set();
4
18
  const firedSubagentStartHookTaskIds = new Set();
19
+ const parkedRows = new Map();
20
+ let passSeq = 0;
21
+ let rowSeq = 0;
22
+ const addParkedRow = (r) => {
23
+ const seq = ++rowSeq;
24
+ const key = `${r.sessionId}\u0000${r.parkedRun ?? ''}\u0000${seq}`;
25
+ parkedRows.set(key, { ...r, key, seq });
26
+ while (parkedRows.size > PARKED_TOOL_ROWS_MAX) {
27
+ const oldest = parkedRows.keys().next();
28
+ if (oldest.done === true)
29
+ break;
30
+ parkedRows.delete(oldest.value);
31
+ }
32
+ };
33
+ const latestStartRows = new Map();
34
+ const callKey = (sessionId, toolCallId) => `${sessionId}\u0000${toolCallId}`;
35
+ const isClaimable = (r) => r.card.rowUuid !== undefined && latestStartRows.get(callKey(r.sessionId, r.toolCallId)) === r.card.rowUuid;
36
+ const setLatestStartRow = (key, rowUuid) => {
37
+ latestStartRows.delete(key);
38
+ latestStartRows.set(key, rowUuid);
39
+ if (latestStartRows.size <= LATEST_START_ROWS_MAX)
40
+ return;
41
+ const pinned = new Set([...parkedRows.values()].map((r) => callKey(r.sessionId, r.toolCallId)));
42
+ for (const k of latestStartRows.keys()) {
43
+ if (latestStartRows.size <= LATEST_START_ROWS_MAX)
44
+ break;
45
+ if (!pinned.has(k))
46
+ latestStartRows.delete(k);
47
+ }
48
+ };
49
+ const latestFor = (sessionId, toolCallId, pass) => {
50
+ let hit;
51
+ for (const r of parkedRows.values()) {
52
+ if (r.sessionId === sessionId && r.toolCallId === toolCallId && (pass === undefined || r.pass === pass))
53
+ hit = r;
54
+ }
55
+ return hit;
56
+ };
5
57
  return {
58
+ beginPass: () => ++passSeq,
59
+ parkToolRow: (row) => {
60
+ addParkedRow({ sessionId: row.sessionId, toolCallId: row.toolCallId, card: row.card, pass: row.pass });
61
+ },
62
+ parkedToolRowFor: (sessionId, toolCallId) => {
63
+ const r = latestFor(sessionId, toolCallId);
64
+ return r !== undefined && isClaimable(r) ? r : undefined;
65
+ },
66
+ noteParkedFact: (sessionId, pass, fact) => {
67
+ if (fact.heldCallId === undefined)
68
+ return;
69
+ const r = latestFor(sessionId, fact.heldCallId, pass);
70
+ if (r === undefined)
71
+ return;
72
+ if (fact.checkpointId !== undefined)
73
+ r.checkpointId = fact.checkpointId;
74
+ if (fact.taskId !== undefined)
75
+ r.parkedRun = fact.taskId;
76
+ },
77
+ retireParkedRowsOfRun: (sessionId, pass, taskId) => {
78
+ for (const [key, r] of parkedRows) {
79
+ if (r.sessionId !== sessionId)
80
+ continue;
81
+ if (r.parkedRun !== undefined ? r.parkedRun === taskId : r.pass === pass)
82
+ parkedRows.delete(key);
83
+ }
84
+ },
85
+ dropParkedToolRow: (key) => {
86
+ parkedRows.delete(key);
87
+ },
88
+ noteStartRow: (sessionId, toolCallId, rowUuid) => {
89
+ setLatestStartRow(callKey(sessionId, toolCallId), rowUuid ?? null);
90
+ },
91
+ listParkedToolRows: () => [...parkedRows.values()].filter(isClaimable).map((r) => ({
92
+ sessionId: r.sessionId,
93
+ toolCallId: r.toolCallId,
94
+ ...(r.parkedRun !== undefined ? { parkedRun: r.parkedRun } : {}),
95
+ ...(r.checkpointId !== undefined ? { checkpointId: r.checkpointId } : {}),
96
+ card: {
97
+ id: r.card.id,
98
+ name: r.card.name,
99
+ rawInput: r.card.rawInput,
100
+ ...(r.card.eventId !== undefined ? { eventId: r.card.eventId } : {}),
101
+ ...(r.card.parentToolCallId !== undefined ? { parentToolCallId: r.card.parentToolCallId } : {}),
102
+ ...(r.card.rowUuid !== undefined ? { rowUuid: r.card.rowUuid } : {}),
103
+ ...(r.card.engineRef !== undefined ? { engineRef: r.card.engineRef } : {}),
104
+ },
105
+ })),
106
+ takeParkedToolRows: (rows) => {
107
+ let n = 0;
108
+ let list = [];
109
+ try {
110
+ list = Array.isArray(rows) ? [...rows] : [];
111
+ }
112
+ catch {
113
+ list = [];
114
+ }
115
+ for (const raw of list) {
116
+ const sessionId = str(ownData(raw, 'sessionId'));
117
+ const toolCallId = str(ownData(raw, 'toolCallId'));
118
+ const card = ownData(raw, 'card');
119
+ const id = str(ownData(card, 'id'));
120
+ const name = str(ownData(card, 'name'));
121
+ if (sessionId === undefined || toolCallId === undefined || id === undefined || id !== toolCallId || name === undefined)
122
+ continue;
123
+ const rowUuid = str(ownData(card, 'rowUuid'));
124
+ if ([...parkedRows.values()].some((r) => r.sessionId === sessionId && r.toolCallId === toolCallId && r.card.rowUuid === rowUuid))
125
+ continue;
126
+ const eventId = str(ownData(card, 'eventId'));
127
+ const parentToolCallId = str(ownData(card, 'parentToolCallId'));
128
+ const engineRef = ownData(card, 'engineRef');
129
+ const parkedRun = str(ownData(raw, 'parkedRun'));
130
+ const checkpointId = str(ownData(raw, 'checkpointId'));
131
+ const ck = callKey(sessionId, toolCallId);
132
+ if (!latestStartRows.has(ck) && rowUuid !== undefined)
133
+ setLatestStartRow(ck, rowUuid);
134
+ addParkedRow({
135
+ sessionId,
136
+ toolCallId,
137
+ card: {
138
+ id,
139
+ name,
140
+ rawInput: ownData(card, 'rawInput'),
141
+ ...(eventId !== undefined ? { eventId } : {}),
142
+ ...(parentToolCallId !== undefined ? { parentToolCallId } : {}),
143
+ ...(rowUuid !== undefined ? { rowUuid } : {}),
144
+ ...(typeof engineRef === 'object' && engineRef !== null ? { engineRef: engineRef } : {}),
145
+ },
146
+ ...(parkedRun !== undefined ? { parkedRun } : {}),
147
+ ...(checkpointId !== undefined ? { checkpointId } : {}),
148
+ });
149
+ n++;
150
+ }
151
+ return n;
152
+ },
6
153
  hasRenderedNotification: (key) => renderedNotifications.has(key),
7
154
  addRenderedNotification: (key) => {
8
155
  renderedNotifications.add(key);
@@ -10,7 +10,7 @@ export interface PanelTaskLedger {
10
10
  noteResidency(taskId: string, residentKey?: string): void;
11
11
  start(taskId: string, agentType?: string): Generator<AdapterOutput>;
12
12
  settle(cardId: string | null, isError: boolean, report?: string): Generator<AdapterOutput>;
13
- settleFromNotification(taskId: string, isError: boolean): Generator<AdapterOutput>;
13
+ settleFromNotification(taskId: string, isError: boolean, sessionId?: string): Generator<AdapterOutput>;
14
14
  settleFromTerminalTick(taskId: string, isError: boolean): Generator<AdapterOutput>;
15
15
  }
16
16
  export declare function createPanelTaskLedger(ctx: AdapterContext, cards: OpenCardView, inst: AdapterInstanceLedger): PanelTaskLedger;
@@ -88,7 +88,7 @@ export function createPanelTaskLedger(ctx, cards, inst) {
88
88
  });
89
89
  }
90
90
  },
91
- *settleFromNotification(taskId, isError) {
91
+ *settleFromNotification(taskId, isError, sessionId) {
92
92
  clearResidencyBothKeys(taskId);
93
93
  if (endedPanelTasks.has(taskId))
94
94
  return;
@@ -96,7 +96,7 @@ export function createPanelTaskLedger(ctx, cards, inst) {
96
96
  yield chrome({
97
97
  kind: 'panel_task',
98
98
  laneProof: mainLane(),
99
- event: panelEndFact(taskId, isError),
99
+ event: panelEndFact(taskId, isError, sessionId !== undefined ? { sessionId } : undefined),
100
100
  });
101
101
  if (inst.hasFiredSubagentStart(taskId)) {
102
102
  yield chrome({
@@ -35,6 +35,7 @@ export interface TextStream {
35
35
  closeSegmentAuthorityWindowOnNextText(): void;
36
36
  replaceThinkingSegment(content: string, anchor?: Frame): ThinkingSegmentReplacement;
37
37
  segmentId(): string;
38
+ anchorWindow(frame: Frame): void;
38
39
  rotateSegmentIdentity(anchor: Frame): void;
39
40
  stampSegmentIdentity(out: AdapterOutput): AdapterOutput;
40
41
  readonly answerLength: number;
@@ -1,4 +1,4 @@
1
- import { chrome, mainLane, transcript, messageIdentityOf } from './ids.js';
1
+ import { chrome, mainLane, segmentRowId, transcript, messageIdentityOf } from './ids.js';
2
2
  import { estimateCjkTokens, FLUSH_INTERVAL_MS } from './wireShapes.js';
3
3
  import { resolveTextSegmentAuthority } from './textSegmentAuthority.js';
4
4
  export const SEMA_SEGMENT_ID_KEY = '_sema_segment_id';
@@ -44,14 +44,15 @@ export function createTextStream(ctx, idOf) {
44
44
  : FLUSH_INTERVAL_MS;
45
45
  let segmentAnchor = null;
46
46
  let thinkingAnchor = null;
47
+ let segmentLast = null;
48
+ let thinkingLast = null;
47
49
  let committedThinking = [];
48
50
  let thinkingSettled = false;
49
51
  let segmentWindowAnchor = null;
50
- let segmentWindowSerial = 0;
51
52
  let segmentIdCache = null;
52
53
  const segmentIdNow = () => {
53
54
  if (segmentIdCache === null)
54
- segmentIdCache = idOf(segmentWindowAnchor ?? {}, `segment${segmentWindowSerial}`);
55
+ segmentIdCache = idOf(segmentWindowAnchor ?? {}, 'segment');
55
56
  return segmentIdCache;
56
57
  };
57
58
  function* takeThinking() {
@@ -61,7 +62,7 @@ export function createTextStream(ctx, idOf) {
61
62
  const msg = {
62
63
  type: 'assistant',
63
64
  message: { role: 'assistant', content: [{ type: 'thinking', thinking }], ...messageIdentityOf(anchor, ctx) },
64
- uuid: idOf(anchor, 'thinking'),
65
+ uuid: segmentRowId(idOf, anchor, thinkingLast, 'thinking'),
65
66
  session_id: ctx.sessionId,
66
67
  parent_tool_use_id: null,
67
68
  };
@@ -70,6 +71,7 @@ export function createTextStream(ctx, idOf) {
70
71
  thinkingSettled = false;
71
72
  thinking = '';
72
73
  thinkingAnchor = null;
74
+ thinkingLast = null;
73
75
  thinkingBlockOpen = false;
74
76
  yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: false });
75
77
  yield transcript(msg, ctx.now());
@@ -82,7 +84,7 @@ export function createTextStream(ctx, idOf) {
82
84
  const msg = {
83
85
  type: 'assistant',
84
86
  message: { role: 'assistant', content: [{ type: 'text', text: body }], ...messageIdentityOf(anchor, ctx) },
85
- uuid: idOf(anchor, 'text'),
87
+ uuid: segmentRowId(idOf, anchor, segmentLast, 'text'),
86
88
  session_id: ctx.sessionId,
87
89
  parent_tool_use_id: null,
88
90
  };
@@ -94,6 +96,7 @@ export function createTextStream(ctx, idOf) {
94
96
  segmentSealed = '';
95
97
  answerSegment = '';
96
98
  segmentAnchor = null;
99
+ segmentLast = null;
97
100
  emittedAssistantText = true;
98
101
  textBlockOpen = false;
99
102
  yield transcript(msg, ctx.now());
@@ -158,6 +161,7 @@ export function createTextStream(ctx, idOf) {
158
161
  }
159
162
  if (answerSegment.length === 0 && segmentSealed.length === 0)
160
163
  segmentAnchor = frame;
164
+ segmentLast = frame;
161
165
  if (segmentWindowAnchor === null)
162
166
  segmentWindowAnchor = frame;
163
167
  answer += delta;
@@ -176,6 +180,7 @@ export function createTextStream(ctx, idOf) {
176
180
  thinkingSettled = false;
177
181
  }
178
182
  }
183
+ thinkingLast = frame;
179
184
  if (thinking.length === 0) {
180
185
  thinkingAnchor = frame;
181
186
  yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: true });
@@ -283,6 +288,8 @@ export function createTextStream(ctx, idOf) {
283
288
  }
284
289
  else {
285
290
  segmentSealed += verdict.tail;
291
+ if (diverged && anchor !== undefined)
292
+ segmentLast = anchor;
286
293
  }
287
294
  answerSegment = '';
288
295
  if (answer.endsWith(liveSegment)) {
@@ -290,6 +297,8 @@ export function createTextStream(ctx, idOf) {
290
297
  }
291
298
  if (segmentAnchor === null && anchor !== undefined)
292
299
  segmentAnchor = anchor;
300
+ if (segmentLast === null && anchor !== undefined)
301
+ segmentLast = anchor;
293
302
  segmentCommitted = '';
294
303
  previousSegmentCommitted = '';
295
304
  idleFlushUsedInSegment = false;
@@ -314,7 +323,7 @@ export function createTextStream(ctx, idOf) {
314
323
  if (typeof committed === 'string')
315
324
  committedText += committed;
316
325
  },
317
- replaceThinkingSegment: (content) => {
326
+ replaceThinkingSegment: (content, anchor) => {
318
327
  const rows = committedThinking;
319
328
  committedThinking = [];
320
329
  const prefix = rows.map((r) => r.text).join('');
@@ -330,6 +339,8 @@ export function createTextStream(ctx, idOf) {
330
339
  thinkingPending = content.startsWith(emitted) ? content.slice(emitted.length) : '';
331
340
  thinking = content;
332
341
  thinkingSettled = content.length > 0;
342
+ if (diverged && anchor !== undefined)
343
+ thinkingLast = anchor;
333
344
  return { diverged, committedPrefixLen: 0, committedPrefixDiverged: false, committedUuids: [] };
334
345
  }
335
346
  const committedPrefixDiverged = !content.startsWith(prefix);
@@ -340,19 +351,25 @@ export function createTextStream(ctx, idOf) {
340
351
  thinkingPending = tail.startsWith(emitted) ? tail.slice(emitted.length) : '';
341
352
  thinking = tail;
342
353
  thinkingSettled = tail.length > 0;
354
+ if (diverged && anchor !== undefined)
355
+ thinkingLast = anchor;
343
356
  }
344
357
  return { diverged, committedPrefixLen: prefix.length, committedPrefixDiverged: false, ...(last !== undefined ? { committedUuid: last } : {}), committedUuids: uuids };
345
358
  }
346
359
  thinking = '';
347
360
  thinkingPending = '';
348
361
  thinkingAnchor = null;
362
+ thinkingLast = null;
349
363
  thinkingSettled = false;
350
364
  return { diverged: true, committedPrefixLen: prefix.length, committedPrefixDiverged: true, ...(last !== undefined ? { committedUuid: last } : {}), committedUuids: uuids };
351
365
  },
352
366
  segmentId: segmentIdNow,
367
+ anchorWindow: (frame) => {
368
+ if (segmentWindowAnchor === null)
369
+ segmentWindowAnchor = frame;
370
+ },
353
371
  rotateSegmentIdentity: (anchor) => {
354
372
  committedTextRows = [];
355
- segmentWindowSerial += 1;
356
373
  segmentWindowAnchor = anchor;
357
374
  segmentIdCache = null;
358
375
  },
@@ -1,25 +1,44 @@
1
1
  import type { AdapterContext, AdapterOutput } from '../seam.js';
2
- import { structuredToToolUseResult, type ToolResultBody } from '../toolResult.js';
2
+ import { structuredToToolUseResult, type ToolKillCause, type ToolResultBody } from '../toolResult.js';
3
3
  import { type Frame, type IdOf } from './ids.js';
4
+ import type { EngineRowRef } from '../engineRowRef.js';
5
+ import { type GateOutcomeView } from '../gateOutcome.js';
4
6
  type RichToolUseResult = NonNullable<ReturnType<typeof structuredToToolUseResult>>;
5
7
  export interface ToolResultOutcome {
6
8
  readonly body: ToolResultBody;
7
9
  readonly rich: RichToolUseResult | null;
8
10
  }
9
11
  export type ToolResultOwner = 'leader' | 'subagent';
10
- export declare function toolResultOutcomeOf(toolName: string, end: ToolEndPayload | undefined, rawInput: PendingToolUse['rawInput'], owner: ToolResultOwner, ledgerTier?: (isError: boolean) => RichToolUseResult | null): ToolResultOutcome;
12
+ export declare function toolResultOutcomeOf(toolName: string, end: ToolEndPayload | undefined, rawInput: PendingToolUse['rawInput'], owner: ToolResultOwner, ledgerTier?: (isError: boolean) => RichToolUseResult | null, killCauseOf?: () => ToolKillCause | undefined): ToolResultOutcome;
11
13
  export interface ToolResultEnvelopeKeys {
12
14
  readonly tool_use_result?: ToolResultBody['toolUseResult'];
13
15
  readonly _sema_degraded?: ToolResultBody['degraded'];
14
16
  }
15
17
  export declare function toolResultEnvelopeParts(o: ToolResultOutcome): ToolResultEnvelopeKeys;
16
- interface PendingToolUse {
18
+ export interface PendingToolUse {
17
19
  id: string;
18
20
  name: string;
19
- rawInput: unknown;
21
+ rawInput: {} | null | undefined;
20
22
  eventId?: string;
21
23
  parentToolCallId?: string;
24
+ engineRef?: EngineRowRef | undefined;
25
+ rowUuid?: string | undefined;
22
26
  }
27
+ export declare function toolResultRowIdentity(sources: readonly {
28
+ readonly eventId?: string | undefined;
29
+ readonly engineRef?: EngineRowRef | undefined;
30
+ }[], toolCallId: string, ctx: Pick<AdapterContext, 'uuid'>): {
31
+ readonly uuid: string;
32
+ readonly engineRef?: EngineRowRef;
33
+ };
34
+ export interface ToolResultRowFlagParts {
35
+ readonly _sema_not_executed?: true;
36
+ readonly _sema_collateral_abort?: true;
37
+ readonly _sema_interrupted_never_started?: true;
38
+ readonly _sema_approval_window_expired?: true;
39
+ readonly _sema_denial_limit_window_expired?: true;
40
+ }
41
+ export declare function toolResultRowFlagParts(arm: object | null | undefined): ToolResultRowFlagParts;
23
42
  interface ToolEndPayload {
24
43
  output?: unknown;
25
44
  structured?: unknown;
@@ -28,7 +47,9 @@ interface ToolEndPayload {
28
47
  eventId?: string | undefined;
29
48
  parentToolCallId?: string | undefined;
30
49
  denialKind?: string | undefined;
31
- notExecuted?: boolean | undefined;
50
+ closeArm?: object | undefined;
51
+ engineRef?: EngineRowRef | undefined;
52
+ gate?: GateOutcomeView | undefined;
32
53
  }
33
54
  export interface OpenCardView {
34
55
  has(id: string): boolean;
@@ -37,6 +58,7 @@ export interface OpenCardView {
37
58
  }
38
59
  export interface ToolCardLedger extends OpenCardView {
39
60
  open(p: PendingToolUse): void;
61
+ detach(id: string): PendingToolUse | undefined;
40
62
  close(p: PendingToolUse, end?: ToolEndPayload): Generator<AdapterOutput>;
41
63
  sweep(): Generator<AdapterOutput>;
42
64
  mintResponseId(frame: Frame): string;
@@ -5,14 +5,17 @@ import { flattenWireOutput } from './wireShapes.js';
5
5
  import { toolResultBlocksOf } from '../toolResultContent.js';
6
6
  import { bashExitOf, bashExitReadingFailed } from '../bashExitReading.js';
7
7
  import { isCcToolDenialKind } from '../gateVocabulary.js';
8
+ import { guardedRead, readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
9
+ import { gateOutcomeOf, isApprovalWindowExpiredGate, isDenialLimitAutoDeniedGate } from '../gateOutcome.js';
10
+ import { TOOL_END_INTERRUPTED_NEVER_STARTED } from '../engineErrorCodes.js';
8
11
  function toolUseResultParts(v) {
9
12
  return v !== undefined ? { tool_use_result: v } : {};
10
13
  }
11
- export function toolResultOutcomeOf(toolName, end, rawInput, owner, ledgerTier) {
14
+ export function toolResultOutcomeOf(toolName, end, rawInput, owner, ledgerTier, killCauseOf) {
12
15
  const isError = end?.isError ?? false;
13
16
  const leaderLedger = owner === 'leader';
14
17
  const body = end && end.output !== undefined
15
- ? wireOutputToBody(toolName, end.output, isError, end.truncated === true, flattenWireOutput, end.structured, leaderLedger)
18
+ ? wireOutputToBody(toolName, end.output, isError, end.truncated === true, flattenWireOutput, end.structured, leaderLedger, killCauseOf)
16
19
  : degradedToolResultBody(isError);
17
20
  let rich = end?.structured !== undefined
18
21
  ? structuredToToolUseResult(end.structured, end.output !== undefined ? flattenWireOutput(end.output) : undefined, leaderLedger)
@@ -40,6 +43,27 @@ export function toolResultEnvelopeParts(o) {
40
43
  ...(o.body.degraded !== undefined ? { _sema_degraded: o.body.degraded } : {}),
41
44
  };
42
45
  }
46
+ export function toolResultRowIdentity(sources, toolCallId, ctx) {
47
+ for (const src of sources) {
48
+ if (typeof src.eventId === 'string' && src.eventId.length > 0) {
49
+ const ref = src.engineRef;
50
+ return { uuid: src.eventId, ...(ref !== undefined && ref.eventId === src.eventId ? { engineRef: ref } : {}) };
51
+ }
52
+ }
53
+ return { uuid: deriveTranscriptId({ toolCallId }, ctx) };
54
+ }
55
+ export function toolResultRowFlagParts(arm) {
56
+ if (arm === null || arm === undefined)
57
+ return {};
58
+ const gate = guardedRead(() => gateOutcomeOf(arm));
59
+ return {
60
+ ...(readFrameTrueMark(arm, 'notExecuted') ? { _sema_not_executed: true } : {}),
61
+ ...(readFrameTrueMark(arm, '_sema_collateral_abort') ? { _sema_collateral_abort: true } : {}),
62
+ ...(readFrameStringKey(arm, 'errorCode') === TOOL_END_INTERRUPTED_NEVER_STARTED ? { _sema_interrupted_never_started: true } : {}),
63
+ ...(isApprovalWindowExpiredGate(gate) ? { _sema_approval_window_expired: true } : {}),
64
+ ...(isDenialLimitAutoDeniedGate(gate) ? { _sema_denial_limit_window_expired: true } : {}),
65
+ };
66
+ }
43
67
  export function createToolCardLedger(ctx, idOf) {
44
68
  const pending = new Map();
45
69
  let assistantResponseId = null;
@@ -63,9 +87,9 @@ export function createToolCardLedger(ctx, idOf) {
63
87
  return null;
64
88
  lastLiveTodos = todo.newTodos;
65
89
  return { toolUseResult: todo.toolUseResult, isError: todo.isError };
66
- });
90
+ }, () => ctx.toolKillCause?.({ toolCallId: p.id, toolName: p.name }));
67
91
  const { body } = outcome;
68
- const eventId = end?.eventId ?? p.eventId;
92
+ const ident = toolResultRowIdentity([{ eventId: end?.eventId, engineRef: end?.engineRef }, { eventId: p.eventId, engineRef: p.engineRef }], p.id, ctx);
69
93
  yield transcript({
70
94
  type: 'user',
71
95
  message: {
@@ -79,12 +103,13 @@ export function createToolCardLedger(ctx, idOf) {
79
103
  },
80
104
  ],
81
105
  },
82
- uuid: eventId ?? deriveTranscriptId({ toolCallId: p.id }, ctx),
106
+ uuid: idOf.adopt(ident.uuid, ident.engineRef),
83
107
  session_id: ctx.sessionId,
84
108
  ...(parentToolCallId !== undefined ? { parent_tool_use_id: parentToolCallId } : {}),
85
109
  ...toolResultEnvelopeParts(outcome),
86
110
  ...(isCcToolDenialKind(end?.denialKind) ? { _sema_denial_kind: end.denialKind } : {}),
87
- ...(end?.notExecuted === true ? { _sema_not_executed: true } : {}),
111
+ ...(end?.gate !== undefined ? { _sema_gate: end.gate } : {}),
112
+ ...toolResultRowFlagParts(end?.closeArm),
88
113
  }, ctx.now());
89
114
  }
90
115
  function* closeCard(p, end) {
@@ -99,6 +124,14 @@ export function createToolCardLedger(ctx, idOf) {
99
124
  open: (p) => {
100
125
  pending.set(p.id, p);
101
126
  },
127
+ detach: (id) => {
128
+ const p = pending.get(id);
129
+ if (p === undefined)
130
+ return undefined;
131
+ pending.delete(id);
132
+ assistantResponseId = null;
133
+ return p;
134
+ },
102
135
  close: closeCard,
103
136
  *sweep() {
104
137
  for (const [, p] of pending) {
@@ -1,8 +1,13 @@
1
1
  import { frozenSet } from '../frozenSet.js';
2
+ import { CORE_BUILTIN_SUBAGENT_TYPES } from '../generated/engineFactTables.js';
2
3
  import { stripToolUseSideChannels } from '../adapter/types.js';
3
4
  import { toolEndOutputText } from '../toolResultContent.js';
4
5
  export const FLUSH_INTERVAL_MS = 100;
5
6
  export const IDLE_FLUSH_MS = 1500;
7
+ const SHELL_ROLE_SUBAGENT_TYPE = 'worker';
8
+ function isHonouredSubagentType(word) {
9
+ return word === SHELL_ROLE_SUBAGENT_TYPE || CORE_BUILTIN_SUBAGENT_TYPES.includes(word);
10
+ }
6
11
  export const SUBAGENT_TOOL_NAMES = frozenSet(['Task', 'Agent', 'Fork']);
7
12
  export const WORKFLOW_TOOL_NAMES = frozenSet(['Workflow', 'RunWorkflow', 'run_workflow']);
8
13
  export const TASK_TOOL_NAMES = new Set(['TodoWrite', 'TaskCreate', 'TaskUpdate']);
@@ -61,8 +66,7 @@ export function sanitizeToolUseBlock(block) {
61
66
  }
62
67
  if (SUBAGENT_TOOL_NAMES.has(out.name) && out.input && typeof out.input === 'object') {
63
68
  const inp = out.input;
64
- if (typeof inp.subagent_type === 'string' &&
65
- !['fork', 'general-purpose', 'worker'].includes(inp.subagent_type)) {
69
+ if (typeof inp.subagent_type === 'string' && !isHonouredSubagentType(inp.subagent_type)) {
66
70
  delete inp.subagent_type;
67
71
  }
68
72
  }
package/dist/adapt.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { AdapterContext, AdapterOutput, WireToCcAdapter } from './seam.js';
2
2
  export { CANCEL_MESSAGE, estimateCjkTokens, flattenWireOutput, FLUSH_INTERVAL_MS, IDLE_FLUSH_MS, REJECT_MESSAGE, sanitizeToolUseBlock, SUBAGENT_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './adapt/wireShapes.js';
3
+ import { type ParkedToolRowSnapshot } from './adapt/instanceLedger.js';
3
4
  export interface AdapterLedgerState {
4
5
  version: 1;
5
6
  renderedNotifications: string[];
6
7
  notifiedRuns: string[];
7
8
  cardEnqueuedRuns: string[];
9
+ parkedToolRows?: ParkedToolRowSnapshot[];
8
10
  }
9
11
  export declare const ADAPTER_COVERAGE: {
10
12
  readonly frames: readonly ["assistant", "user", "stream_event", "turn_usage", "result", "system", "task_notification", "workflow_complete", "diagnostics", "steering_injected", "workspace_changed", "human_input", "message_committed", "engine_notice", "text_end", "prompt_suggestions", "retry_status", "task_progress", "tool_end_result(label 补位 + 关卡 settle + response-id 复位 + 开卡台账出栈 + 经 cards.close 铸 tool_result)"];
package/dist/adapt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isEngineWorkflowNotified, isWorkflowCompletionCardEnqueued, listNotifiedRuns, listWorkflowCompletionCardsEnqueued, markEngineWorkflowNotified, noteWorkflowCompletionCardEnqueued, parseTranscriptNotificationSeeds, } from './notifications.js';
2
2
  export { CANCEL_MESSAGE, estimateCjkTokens, flattenWireOutput, FLUSH_INTERVAL_MS, IDLE_FLUSH_MS, REJECT_MESSAGE, sanitizeToolUseBlock, SUBAGENT_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './adapt/wireShapes.js';
3
3
  import { IDLE_FLUSH_MS } from './adapt/wireShapes.js';
4
- import { chrome, mainLane, makeIdOf } from './adapt/ids.js';
4
+ import { carryRowSidecars, chrome, mainLane, makeIdOf } from './adapt/ids.js';
5
5
  import { createTextStream } from './adapt/textStream.js';
6
6
  import { createToolCardLedger } from './adapt/toolCards.js';
7
7
  import { createPanelTaskLedger } from './adapt/panelTasks.js';
@@ -122,6 +122,7 @@ class WireToCcAdapterImpl {
122
122
  renderedNotifications: this.ledger.listRenderedNotifications(),
123
123
  notifiedRuns: listNotifiedRuns(),
124
124
  cardEnqueuedRuns: listWorkflowCompletionCardsEnqueued(),
125
+ ...((rows) => (rows.length > 0 ? { parkedToolRows: rows } : {}))(this.ledger.listParkedToolRows()),
125
126
  };
126
127
  }
127
128
  importLedger(state) {
@@ -142,6 +143,7 @@ class WireToCcAdapterImpl {
142
143
  n += this.ledger.takeRenderedNotifications(rendered);
143
144
  takeModule(s.notifiedRuns, isEngineWorkflowNotified, markEngineWorkflowNotified);
144
145
  takeModule(s.cardEnqueuedRuns, isWorkflowCompletionCardEnqueued, noteWorkflowCompletionCardEnqueued);
146
+ n += this.ledger.takeParkedToolRows(s.parkedToolRows);
145
147
  return n;
146
148
  }
147
149
  importLedgerFromTranscript(messages) {
@@ -159,19 +161,22 @@ class WireToCcAdapterImpl {
159
161
  async *adapt(frames, ctx) {
160
162
  const slot = {};
161
163
  for await (const out of this.adaptUnstamped(frames, ctx, slot)) {
162
- yield slot.text === undefined ? out : slot.text.stampSegmentIdentity(out);
164
+ const segmented = slot.text === undefined ? out : slot.text.stampSegmentIdentity(out);
165
+ yield slot.idOf === undefined ? segmented : carryRowSidecars(segmented, slot.idOf);
163
166
  }
164
167
  }
165
168
  async *adaptUnstamped(frames, ctx, slot) {
166
169
  const inst = this.ledger;
167
170
  const turnStartAt = ctx.now();
168
171
  const idOf = makeIdOf(ctx);
172
+ slot.idOf = idOf;
169
173
  const text = createTextStream(ctx, idOf);
170
174
  slot.text = text;
171
175
  const cards = createToolCardLedger(ctx, idOf);
172
176
  const panel = createPanelTaskLedger(ctx, cards, inst);
173
177
  const flags = createTurnFlags(ctx, turnStartAt);
174
- const deps = { ctx, idOf, text, cards, panel, flags, inst };
178
+ const pass = inst.beginPass();
179
+ const deps = { ctx, idOf, text, cards, panel, flags, inst, pass };
175
180
  yield chrome({ kind: 'retry_status', laneProof: mainLane(), status: null });
176
181
  yield chrome({ kind: 'prompt_suggestions', laneProof: mainLane(), suggestions: null });
177
182
  yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: false });
@@ -1,3 +1,4 @@
1
+ import type { UiLanguage } from '../env/uiLanguage.js';
1
2
  import type { ActiveRunBusySignal } from './runStream.js';
2
3
  import type { PlanReviewReopenTrigger } from '../hitl/planReviewWire.js';
3
4
  import { atMostOnceFailureClass } from '../atMostOnce.js';
@@ -99,6 +100,7 @@ export type SelfHealOutcome = {
99
100
  taskId: string;
100
101
  status: string;
101
102
  alreadyOffered?: true;
103
+ pendingGateKind?: string | null;
102
104
  } | {
103
105
  kind: 'running-not-found';
104
106
  taskId: string;
@@ -159,6 +161,10 @@ export type SelfHealOutcome = {
159
161
  } | {
160
162
  kind: 'ask-run-not-found';
161
163
  taskId: string;
164
+ } | {
165
+ kind: 'ask-run-settled';
166
+ taskId: string;
167
+ status: string;
162
168
  } | {
163
169
  kind: 'stale-park-cancelled';
164
170
  taskId: string;
@@ -226,6 +232,6 @@ export interface ActiveRunSelfHealCopy {
226
232
  rowFor?: (outcome: SelfHealOutcome, signal: ActiveRunBusySignal | null | undefined) => string | undefined;
227
233
  headlessRowFor?: (signal: ActiveRunBusySignal) => string | undefined;
228
234
  }
229
- export declare const INTERACTIVE_WAY_OUT = "run /clear to keep working in a fresh session";
230
- export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration): string;
231
- export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy): string;
235
+ export declare const INTERACTIVE_WAY_OUT: string;
236
+ export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration, lang?: UiLanguage): string;
237
+ export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy, lang?: UiLanguage): string;