@sema-agent/client-core 0.98.0 → 0.100.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 (236) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +61 -35
  3. package/dist/adapt/arms.js +120 -55
  4. package/dist/adapt/panelTasks.d.ts +3 -2
  5. package/dist/adapt/panelTasks.js +34 -11
  6. package/dist/adapt/textStream.d.ts +1 -1
  7. package/dist/adapt/textStream.js +51 -28
  8. package/dist/adapter/activeRunSelfHeal.d.ts +11 -3
  9. package/dist/adapter/activeRunSelfHeal.js +210 -294
  10. package/dist/adapter/downstream/eventToSdkMessage.d.ts +25 -6
  11. package/dist/adapter/downstream/eventToSdkMessage.js +176 -12
  12. package/dist/adapter/downstream/terminalToSdkResult.js +10 -0
  13. package/dist/adapter/downstream/wiringManifestView.d.ts +3 -1
  14. package/dist/adapter/downstream/wiringManifestView.js +1 -0
  15. package/dist/adapter/runStream.js +82 -40
  16. package/dist/adapter/types.d.ts +2 -0
  17. package/dist/adapter/types.js +2 -1
  18. package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
  19. package/dist/agentsWireCaps.d.ts +7 -3
  20. package/dist/agentsWireCaps.js +133 -39
  21. package/dist/cloudConfigWireCaps.d.ts +10 -1
  22. package/dist/cloudConfigWireCaps.js +181 -65
  23. package/dist/compactionStatus.d.ts +34 -0
  24. package/dist/compactionStatus.js +196 -0
  25. package/dist/controlRouter.d.ts +4 -2
  26. package/dist/controlRouter.js +39 -51
  27. package/dist/coreValuePorts.d.ts +26 -1
  28. package/dist/coreValuePorts.js +10 -0
  29. package/dist/corruptSessionCopy.d.ts +2 -1
  30. package/dist/corruptSessionCopy.js +3 -3
  31. package/dist/decideFailureNote.js +3 -3
  32. package/dist/declared/supportFloorDeclared.js +1 -1
  33. package/dist/detachWire.js +3 -2
  34. package/dist/devicesFace.d.ts +34 -0
  35. package/dist/devicesFace.js +90 -0
  36. package/dist/displayUntrusted.d.ts +1 -0
  37. package/dist/displayUntrusted.js +153 -5
  38. package/dist/engineAgentPanelStore.d.ts +14 -4
  39. package/dist/engineAgentPanelStore.js +14 -0
  40. package/dist/engineCapReader.d.ts +2 -1
  41. package/dist/engineCapReader.js +7 -5
  42. package/dist/engineCapsCache.d.ts +8 -0
  43. package/dist/engineCapsCache.js +59 -6
  44. package/dist/engineCapsChange.d.ts +2 -0
  45. package/dist/engineCapsChange.js +9 -0
  46. package/dist/engineErrorCodes.d.ts +11 -2
  47. package/dist/engineErrorCodes.js +11 -12
  48. package/dist/engineRowRef.js +4 -0
  49. package/dist/engineSessionMessages.d.ts +1 -0
  50. package/dist/engineSessionMessages.js +7 -1
  51. package/dist/engineTargetSeat.d.ts +27 -0
  52. package/dist/engineTargetSeat.js +199 -0
  53. package/dist/engineToolDirectory.d.ts +3 -0
  54. package/dist/engineToolDirectory.js +4 -2
  55. package/dist/engineWireFor.js +3 -8
  56. package/dist/env/uiLanguage.d.ts +2 -1
  57. package/dist/env/uiLanguage.js +3 -2
  58. package/dist/eventLeg.d.ts +7 -5
  59. package/dist/eventLeg.js +68 -49
  60. package/dist/fileHistoryCaptureCapability.d.ts +2 -4
  61. package/dist/fileHistoryCaptureCapability.js +12 -22
  62. package/dist/fileHistoryLegNotice.d.ts +2 -1
  63. package/dist/fileHistoryLegNotice.js +3 -3
  64. package/dist/frameBinding.d.ts +3 -0
  65. package/dist/frameBinding.js +12 -0
  66. package/dist/gateOutcome.js +16 -2
  67. package/dist/gateVocabulary.d.ts +8 -7
  68. package/dist/gateVocabulary.js +71 -73
  69. package/dist/generated/engineFactTables.d.ts +18 -1
  70. package/dist/generated/engineFactTables.js +56 -0
  71. package/dist/generated/engineNoticeTables.js +12 -3
  72. package/dist/generated/settingsSchemaFns.d.ts +18 -0
  73. package/dist/generated/settingsSchemaFns.js +70 -0
  74. package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
  75. package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
  76. package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -0
  77. package/dist/generated/settingsSchemaMcpRequestEntry.js +162 -0
  78. package/dist/generated/settingsSchemaTables.d.ts +2 -0
  79. package/dist/generated/settingsSchemaTables.js +9 -0
  80. package/dist/generated/settingsSchemaTypes.d.ts +133 -0
  81. package/dist/generated/settingsSchemaTypes.js +1 -0
  82. package/dist/hitl/allowRuleShadow.d.ts +2 -1
  83. package/dist/hitl/allowRuleShadow.js +18 -15
  84. package/dist/hitl/approvalCardReasons.d.ts +3 -2
  85. package/dist/hitl/approvalCardReasons.js +29 -30
  86. package/dist/hitl/approvalHolds.d.ts +17 -0
  87. package/dist/hitl/approvalHolds.js +114 -29
  88. package/dist/hitl/askClassPair.d.ts +2 -2
  89. package/dist/hitl/askClassPair.js +16 -0
  90. package/dist/hitl/askGateWire.js +2 -1
  91. package/dist/hitl/askSettlementLine.d.ts +14 -4
  92. package/dist/hitl/askSettlementLine.js +67 -47
  93. package/dist/hitl/attributionLadder.d.ts +23 -0
  94. package/dist/hitl/attributionLadder.js +67 -0
  95. package/dist/hitl/automaticAnswerVerdict.d.ts +2 -1
  96. package/dist/hitl/automaticAnswerVerdict.js +8 -8
  97. package/dist/hitl/crashConvergedNotice.d.ts +5 -4
  98. package/dist/hitl/crashConvergedNotice.js +28 -41
  99. package/dist/hitl/decisionLedger.d.ts +55 -0
  100. package/dist/hitl/decisionLedger.js +156 -0
  101. package/dist/hitl/decisionRefusal.d.ts +1 -0
  102. package/dist/hitl/decisionRefusal.js +1 -1
  103. package/dist/hitl/decisionSend.d.ts +113 -0
  104. package/dist/hitl/decisionSend.js +579 -0
  105. package/dist/hitl/frameRouter.js +7 -8
  106. package/dist/hitl/hitlBridge.d.ts +1 -0
  107. package/dist/hitl/hitlBridge.js +21 -9
  108. package/dist/hitl/persistedRulesWire.d.ts +6 -5
  109. package/dist/hitl/persistedRulesWire.js +55 -73
  110. package/dist/hitl/planReviewWire.d.ts +5 -0
  111. package/dist/hitl/planReviewWire.js +53 -76
  112. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  113. package/dist/hitl/sessionPolicyDeliverable.js +49 -9
  114. package/dist/hitl/sessionPolicyWire.d.ts +2 -1
  115. package/dist/hitl/sessionPolicyWire.js +23 -24
  116. package/dist/hitl/suspendedReopen.d.ts +2 -1
  117. package/dist/hitl/suspendedReopen.js +7 -10
  118. package/dist/hitl/toolApprovalWire.d.ts +17 -5
  119. package/dist/hitl/toolApprovalWire.js +120 -147
  120. package/dist/hooksWireCaps.js +145 -56
  121. package/dist/host.d.ts +21 -0
  122. package/dist/hostTurnSettings.d.ts +110 -0
  123. package/dist/hostTurnSettings.js +692 -0
  124. package/dist/humanTurn.d.ts +15 -1
  125. package/dist/humanTurn.js +100 -12
  126. package/dist/humanTurnRead.d.ts +2 -0
  127. package/dist/humanTurnRead.js +22 -1
  128. package/dist/i18n/messages.en.d.ts +713 -0
  129. package/dist/i18n/messages.en.js +713 -0
  130. package/dist/i18n/messages.zh.js +854 -1
  131. package/dist/index.d.ts +45 -13
  132. package/dist/index.js +27 -9
  133. package/dist/inheritEnvCapability.d.ts +4 -2
  134. package/dist/inheritEnvCapability.js +12 -5
  135. package/dist/inheritEnvWire.d.ts +3 -2
  136. package/dist/inheritEnvWire.js +14 -16
  137. package/dist/injectionLaneNotice.d.ts +5 -0
  138. package/dist/injectionLaneNotice.js +46 -0
  139. package/dist/interactiveHalt.js +17 -6
  140. package/dist/liveModelCatalog.d.ts +2 -1
  141. package/dist/liveModelCatalog.js +14 -8
  142. package/dist/mcpPanel.d.ts +10 -1
  143. package/dist/mcpPanel.js +42 -13
  144. package/dist/mcpProbeCapability.d.ts +2 -1
  145. package/dist/mcpProbeCapability.js +7 -11
  146. package/dist/mcpProbeWire.d.ts +3 -1
  147. package/dist/mcpProbeWire.js +5 -0
  148. package/dist/mcpReconnect.js +2 -2
  149. package/dist/mcpToolToggles.d.ts +6 -0
  150. package/dist/mcpToolToggles.js +46 -0
  151. package/dist/mcpWireCaps.d.ts +43 -3
  152. package/dist/mcpWireCaps.js +194 -59
  153. package/dist/mcpWireTransport.d.ts +4 -0
  154. package/dist/mcpWireTransport.js +18 -0
  155. package/dist/memoryEntriesWire.js +5 -10
  156. package/dist/model/onboardJudgement.d.ts +93 -0
  157. package/dist/model/onboardJudgement.js +415 -0
  158. package/dist/model/tierVocabulary.d.ts +2 -0
  159. package/dist/model/tierVocabulary.js +17 -5
  160. package/dist/modelCapabilityProbe.d.ts +65 -0
  161. package/dist/modelCapabilityProbe.js +601 -0
  162. package/dist/modelIdentityResolvability.d.ts +5 -0
  163. package/dist/modelIdentityResolvability.js +49 -22
  164. package/dist/ownKey.d.ts +33 -0
  165. package/dist/ownKey.js +109 -0
  166. package/dist/panelReduce.d.ts +11 -1
  167. package/dist/panelReduce.js +95 -16
  168. package/dist/panelStateHolder.d.ts +1 -0
  169. package/dist/panelStateHolder.js +10 -1
  170. package/dist/permissionRuleIssue.d.ts +2 -1
  171. package/dist/permissionRuleIssue.js +23 -20
  172. package/dist/permissionRulesWriteCapability.d.ts +2 -1
  173. package/dist/permissionRulesWriteCapability.js +8 -6
  174. package/dist/pluginHooksWire.d.ts +46 -3
  175. package/dist/pluginHooksWire.js +220 -12
  176. package/dist/prepareRefusal.d.ts +8 -0
  177. package/dist/prepareRefusal.js +72 -0
  178. package/dist/printModelStatus.d.ts +63 -0
  179. package/dist/printModelStatus.js +155 -0
  180. package/dist/request/taskRequest.d.ts +16 -10
  181. package/dist/request/taskRequest.js +195 -58
  182. package/dist/resumeRefusalCopy.d.ts +14 -9
  183. package/dist/resumeRefusalCopy.js +89 -144
  184. package/dist/retryStatus.d.ts +55 -0
  185. package/dist/retryStatus.js +155 -19
  186. package/dist/ruleRefusalSentence.d.ts +4 -0
  187. package/dist/ruleRefusalSentence.js +58 -0
  188. package/dist/sandboxWire.d.ts +2 -1
  189. package/dist/sandboxWire.js +55 -21
  190. package/dist/scenarioRefusal.d.ts +10 -0
  191. package/dist/scenarioRefusal.js +111 -0
  192. package/dist/seam.d.ts +48 -9
  193. package/dist/seam.js +54 -5
  194. package/dist/seatContract.d.ts +272 -14
  195. package/dist/seatContract.js +711 -23
  196. package/dist/selfOrchestrationDenial.js +7 -19
  197. package/dist/sessionIdSegment.d.ts +6 -0
  198. package/dist/sessionIdSegment.js +24 -0
  199. package/dist/sessionMemoryStatus.js +6 -11
  200. package/dist/sessionPolicyCapability.d.ts +2 -1
  201. package/dist/sessionPolicyCapability.js +8 -6
  202. package/dist/settingsCredentialKeyPaths.d.ts +8 -0
  203. package/dist/settingsCredentialKeyPaths.js +219 -0
  204. package/dist/settingsHooksSalvage.d.ts +44 -0
  205. package/dist/settingsHooksSalvage.js +211 -0
  206. package/dist/skillToolListsCapability.d.ts +2 -1
  207. package/dist/skillToolListsCapability.js +8 -6
  208. package/dist/skillsWireCaps.d.ts +0 -3
  209. package/dist/skillsWireCaps.js +1 -2
  210. package/dist/sseIdleTriage.js +3 -2
  211. package/dist/subagent/engineSubagentResume.js +15 -9
  212. package/dist/subagentContentStore.d.ts +4 -0
  213. package/dist/subagentContentStore.js +157 -27
  214. package/dist/toolHistoryMismatch.js +3 -2
  215. package/dist/toolRoster.d.ts +3 -2
  216. package/dist/toolRoster.js +21 -20
  217. package/dist/toolsFlagNames.d.ts +8 -0
  218. package/dist/toolsFlagNames.js +110 -0
  219. package/dist/turnFailurePresentation.d.ts +12 -1
  220. package/dist/turnFailurePresentation.js +220 -15
  221. package/dist/usageAnalytics.js +6 -11
  222. package/dist/userAttachmentEnvelope.d.ts +1 -0
  223. package/dist/userAttachmentEnvelope.js +37 -7
  224. package/dist/userAttachmentSeat.d.ts +21 -0
  225. package/dist/userAttachmentSeat.js +75 -0
  226. package/dist/userInvokedSkillsCapability.d.ts +11 -1
  227. package/dist/userInvokedSkillsCapability.js +31 -7
  228. package/dist/wireErrorTriage.d.ts +7 -0
  229. package/dist/wireErrorTriage.js +23 -1
  230. package/dist/wireFailureShape.js +2 -1
  231. package/dist/wireRefusalCopy.d.ts +62 -16
  232. package/dist/wireRefusalCopy.js +307 -148
  233. package/dist/workflowsJournalCapability.d.ts +2 -1
  234. package/dist/workflowsJournalCapability.js +8 -6
  235. package/docs/INTEGRATION-CLIENTS.md +951 -42
  236. package/package.json +5 -5
@@ -1,8 +1,9 @@
1
1
  import { ccToolDenialKindForToolEnd, gateOutcomeOf } from '../gateOutcome.js';
2
+ import { terminalOwnerOf } from '../seam.js';
2
3
  import { isSubFlowSegmentEnd, SEGMENT_END_IDENTITY_KEYS, snapshotSegmentIdentity, snapshotIsSubFlow } from '../adapter/types.js';
3
4
  import { classifyPeerNotification, renderPeerFrameTranscriptText } from '../peerFrames.js';
4
5
  import { dropQueuedNotificationsForRun, isEngineWorkflowNotified, isWorkflowCompletionCardEnqueued, markEngineWorkflowNotified, noteOwnWorkflowRun, normalizeTaskNotification, noteWorkflowCompletionCardEnqueued, renderTaskNotificationXml, taskNotificationDedupKey } from '../notifications.js';
5
- import { mapBrainStatusToRetry } from '../retryStatus.js';
6
+ import { retryStatusFromArm } from '../retryStatus.js';
6
7
  import { steeringInjectedToAttachments } from '../steering.js';
7
8
  import { projectDiagnosticsFrame } from '../diagnostics.js';
8
9
  import { recordEngineToolLabel } from '../engineToolLabelStore.js';
@@ -12,9 +13,11 @@ import { recordWorkflowAgentTaskId } from '../workflow.js';
12
13
  import { isCoreTaskNotificationTerminal, isCoreTaskNotificationTerminalNotSuccess, isCoreTaskProgressTerminal, isCoreTaskProgressTerminalNotSuccess } from '../terminalStatuses.js';
13
14
  import { readToolHistoryMismatchKey } from '../toolHistoryMismatch.js';
14
15
  import { readProviderRejectionResendKey } from '../providerRejection.js';
15
- import { contextUsageReadingOf, guardedRead, readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
16
- import { washCredentials } from '../displayUntrusted.js';
16
+ import { contextUsageReadingOf, guardedRead, humanInputAttachmentsOf, promptManifestIdentityOfFrame, promptManifestSectionViewOf, readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
17
+ import { CORE_USER_ATTACHMENT_LABEL_MAX } from '../generated/engineFactTables.js';
18
+ import { ESCAPE_FACE, paintAndCap, washCredentials } from '../displayUntrusted.js';
17
19
  import { resolveEnginePanelTaskId } from '../engineAgentPanelStore.js';
20
+ import { cycleSeqValue } from '../cycleOrder.js';
18
21
  import { fleetRowAgentType } from '../fleet/fleetRowAgentType.js';
19
22
  import { chrome, mainLane, transcript, messageIdentityOf } from './ids.js';
20
23
  import { engineRefOf } from '../engineRowRef.js';
@@ -22,27 +25,6 @@ import { isReplayMarked, RESULT_REPLAYED_TEXT } from '../replayBody.js';
22
25
  import { wiringManifestViewOf } from '../adapter/downstream/wiringManifestView.js';
23
26
  import { isUnsettledHeldToolEnd } from '../engineRowRef.js';
24
27
  import { CANCEL_MESSAGE, decisionOf, flattenWireOutput, REJECT_MESSAGE, sanitizeToolUseBlock, shortTaskLabel, TASK_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './wireShapes.js';
25
- function hostOwnString(o, key) {
26
- return readFrameStringKey(o, key);
27
- }
28
- function continuesParkDeclarationOf(ctx) {
29
- const decl = guardedRead(() => ctx.continuesPark);
30
- return typeof decl === 'object' && decl !== null ? decl : undefined;
31
- }
32
- function continuesParkWitness(ctx, row) {
33
- const decl = continuesParkDeclarationOf(ctx);
34
- if (decl === undefined)
35
- return false;
36
- if (hostOwnString(decl, 'toolCallId') !== row.toolCallId)
37
- return false;
38
- const cp = hostOwnString(decl, 'checkpointId');
39
- if (cp !== undefined && row.checkpointId !== undefined && cp !== row.checkpointId)
40
- return false;
41
- const parkedTaskId = hostOwnString(decl, 'parkedTaskId');
42
- if (parkedTaskId !== undefined && row.parkedRun !== undefined && parkedTaskId !== row.parkedRun)
43
- return false;
44
- return true;
45
- }
46
28
  function claimParkedCard(m, callId, toolName, deps) {
47
29
  const { ctx, cards, inst, pass } = deps;
48
30
  if (cards.has(callId))
@@ -56,12 +38,11 @@ function claimParkedCard(m, callId, toolName, deps) {
56
38
  return undefined;
57
39
  const frameRun = engineRefOf(m)?.taskId;
58
40
  if (frameRun !== undefined) {
59
- const decl = continuesParkDeclarationOf(ctx);
60
- const allowed = [row.parkedRun, row.card.engineRef?.taskId, readFrameStringKey(decl, 'parkedTaskId'), readFrameStringKey(decl, 'continuationTaskId')].filter((x) => x !== undefined);
41
+ const allowed = [row.parkedRun, row.card.engineRef?.taskId].filter((x) => x !== undefined);
61
42
  if (allowed.length > 0 && !allowed.includes(frameRun))
62
43
  return undefined;
63
44
  }
64
- if (row.pass !== pass && !continuesParkWitness(ctx, row))
45
+ if (row.pass !== pass)
65
46
  return undefined;
66
47
  inst.dropParkedToolRow(row.key);
67
48
  return row.card;
@@ -69,6 +50,12 @@ function claimParkedCard(m, callId, toolName, deps) {
69
50
  function laneOfCard(p) {
70
51
  return p.parentToolCallId !== undefined && p.parentToolCallId !== '' ? { lane: 'subagent', parentToolCallId: p.parentToolCallId } : mainLane();
71
52
  }
53
+ function terminalOwnerCarry(m) {
54
+ if (m._sema_api_error_message !== true)
55
+ return {};
56
+ const owner = terminalOwnerOf(m);
57
+ return owner === undefined ? {} : { _sema_terminal_owner: owner };
58
+ }
72
59
  function toolHistoryKeyCarry(m) {
73
60
  if (m._sema_api_error_message !== true)
74
61
  return {};
@@ -188,7 +175,7 @@ const assistantArm = function* (m, deps) {
188
175
  }
189
176
  const textBlock = blocks.find(b => b?.type === 'text');
190
177
  const thinkingBlock = blocks.find(b => b?.type === 'thinking');
191
- if ((textBlock && typeof textBlock.text === 'string' && textBlock.text.length > 0) || (thinkingBlock && typeof thinkingBlock.thinking === 'string'))
178
+ if (textBlock && typeof textBlock.text === 'string' && textBlock.text.length > 0)
192
179
  text.anchorWindow(m);
193
180
  if (textBlock && typeof textBlock.text === 'string' && textBlock.text.length > 0) {
194
181
  const rowText = m._sema_api_error_message === true ? washCredentials(textBlock.text) : textBlock.text;
@@ -204,6 +191,7 @@ const assistantArm = function* (m, deps) {
204
191
  ...(m._sema_api_error_message === true ? { _sema_api_error_message: true } : {}),
205
192
  ...toolHistoryKeyCarry(m),
206
193
  ...providerResendKeyCarry(m),
194
+ ...terminalOwnerCarry(m),
207
195
  }, ctx.now());
208
196
  text.markEmittedText(rowText);
209
197
  }
@@ -310,8 +298,15 @@ const humanInputArm = function* (m) {
310
298
  ...(actor !== undefined && Object.keys(actor).length > 0 ? { actor } : {}),
311
299
  ...(str(m.entryId) !== undefined ? { entryId: str(m.entryId) } : {}),
312
300
  ...(str(m.eventId) !== undefined ? { eventId: str(m.eventId) } : {}),
301
+ ...humanInputAttachmentsForChrome(m),
313
302
  });
314
303
  };
304
+ function humanInputAttachmentsForChrome(m) {
305
+ const rows = humanInputAttachmentsOf(m);
306
+ if (rows === undefined)
307
+ return {};
308
+ return { attachments: rows.map((r) => (r.label !== undefined ? { ...r, label: paintAndCap(r.label, ESCAPE_FACE, CORE_USER_ATTACHMENT_LABEL_MAX) } : r)) };
309
+ }
315
310
  const messageCommittedArm = function* (m) {
316
311
  if (typeof m.parentToolCallId === 'string')
317
312
  return;
@@ -449,12 +444,86 @@ const compactionOutcomeArm = function* (m) {
449
444
  const trigger = str(m.trigger);
450
445
  const reason = str(m.reason);
451
446
  const eventId = str(idSnap.eventId);
447
+ const pass = str(m.pass);
452
448
  yield chrome({
453
449
  kind: 'compaction_outcome',
454
450
  laneProof,
455
451
  outcome,
456
452
  ...(trigger !== undefined ? { trigger } : {}),
457
453
  ...(reason !== undefined ? { reason } : {}),
454
+ ...(pass !== undefined ? { pass } : {}),
455
+ ...(eventId !== undefined ? { eventId } : {}),
456
+ });
457
+ };
458
+ const compactionStartedArm = function* (m) {
459
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
460
+ const pass = str(m.pass);
461
+ const trigger = str(m.trigger);
462
+ if (pass === undefined || trigger === undefined)
463
+ return;
464
+ const idSnap = snapshotSegmentIdentity(m);
465
+ if (idSnap === null)
466
+ return;
467
+ let laneProof = mainLane();
468
+ if (snapshotIsSubFlow(idSnap)) {
469
+ const parent = str(idSnap.parentToolCallId);
470
+ if (parent === undefined)
471
+ return;
472
+ laneProof = { lane: 'subagent', parentToolCallId: parent };
473
+ }
474
+ const startedAt = typeof m.startedAt === 'number' && Number.isFinite(m.startedAt) ? m.startedAt : undefined;
475
+ const eventId = str(idSnap.eventId);
476
+ yield chrome({
477
+ kind: 'compaction_started',
478
+ laneProof,
479
+ pass,
480
+ trigger,
481
+ ...(startedAt !== undefined ? { startedAt } : {}),
482
+ ...(eventId !== undefined ? { eventId } : {}),
483
+ });
484
+ };
485
+ const taskStartedArm = function* (m) {
486
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
487
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
488
+ const taskId = str(m.taskId);
489
+ if (taskId === undefined)
490
+ return;
491
+ const idSnap = snapshotSegmentIdentity(m);
492
+ if (idSnap === null)
493
+ return;
494
+ const parent = str(idSnap.parentToolCallId);
495
+ const laneProof = parent !== undefined ? { lane: 'subagent', parentToolCallId: parent } : mainLane();
496
+ const sessionId = str(m.sessionId);
497
+ const model = str(m.model);
498
+ const taskType = str(m.taskType);
499
+ const seq = num(m.seq);
500
+ const workflowRunId = str(m.workflowRunId);
501
+ const workflowAgentLabel = str(m.workflowAgentLabel);
502
+ const parentTaskId = str(m.parentTaskId);
503
+ const parentSessionId = str(m.parentSessionId);
504
+ const rootSessionId = str(m.rootSessionId);
505
+ const name = str(m.name);
506
+ const spawnName = str(m.spawnName);
507
+ const agentType = str(m.agentType);
508
+ const startedAt = num(m.startedAt);
509
+ const eventId = str(idSnap.eventId);
510
+ yield chrome({
511
+ kind: 'subagent_started',
512
+ laneProof,
513
+ taskId,
514
+ ...(sessionId !== undefined ? { sessionId } : {}),
515
+ ...(model !== undefined ? { model } : {}),
516
+ ...(taskType !== undefined ? { taskType } : {}),
517
+ ...(seq !== undefined ? { seq } : {}),
518
+ ...(workflowRunId !== undefined ? { workflowRunId } : {}),
519
+ ...(workflowAgentLabel !== undefined ? { workflowAgentLabel } : {}),
520
+ ...(parentTaskId !== undefined ? { parentTaskId } : {}),
521
+ ...(parentSessionId !== undefined ? { parentSessionId } : {}),
522
+ ...(rootSessionId !== undefined ? { rootSessionId } : {}),
523
+ ...(name !== undefined ? { name } : {}),
524
+ ...(spawnName !== undefined ? { spawnName } : {}),
525
+ ...(agentType !== undefined ? { agentType } : {}),
526
+ ...(startedAt !== undefined ? { startedAt } : {}),
458
527
  ...(eventId !== undefined ? { eventId } : {}),
459
528
  });
460
529
  };
@@ -480,14 +549,8 @@ const promptAssembledArm = function* (m) {
480
549
  const chars = size(o.chars);
481
550
  return id === undefined || chars === undefined ? undefined : { id, chars };
482
551
  });
483
- const sections = promptManifestRows(m.sections, (o) => {
484
- const id = str(o.id);
485
- const chars = size(o.chars);
486
- if (id === undefined || chars === undefined)
487
- return undefined;
488
- const slot = str(o.slot);
489
- return { id, chars, ...(slot !== undefined ? { slot } : {}) };
490
- });
552
+ const sections = promptManifestRows(m.sections, (o) => promptManifestSectionViewOf(o));
553
+ const promptIdentity = promptManifestIdentityOfFrame(m);
491
554
  const tools = promptManifestRows(m.tools, (o) => {
492
555
  const wireName = str(o.wireName);
493
556
  return wireName === undefined ? undefined : { wireName };
@@ -514,6 +577,7 @@ const promptAssembledArm = function* (m) {
514
577
  ...(blocks !== undefined ? { blocks } : {}),
515
578
  ...(sections !== undefined ? { sections } : {}),
516
579
  ...(tools !== undefined ? { tools } : {}),
580
+ ...(promptIdentity !== undefined ? { identity: promptIdentity } : {}),
517
581
  ...(eventId !== undefined ? { eventId } : {}),
518
582
  });
519
583
  };
@@ -523,6 +587,7 @@ const textSegmentEndArm = function* (m, { text }) {
523
587
  const content = typeof m.content === 'string' ? m.content : '';
524
588
  if (content.length === 0)
525
589
  return;
590
+ text.anchorWindow(m);
526
591
  const r = text.replaceAnswerSegment(content, m);
527
592
  yield* text.drainLive();
528
593
  yield chrome({
@@ -538,7 +603,7 @@ const textSegmentEndArm = function* (m, { text }) {
538
603
  ...(r.committedRows !== undefined ? { committedRows: r.committedRows } : {}),
539
604
  ...(typeof m.eventId === 'string' && m.eventId.length > 0 ? { eventId: m.eventId } : {}),
540
605
  });
541
- text.rotateSegmentIdentity(m);
606
+ yield* text.endSegment();
542
607
  };
543
608
  const thinkingSegmentEndArm = function* (m, { text }) {
544
609
  if (isSubFlowSegmentEnd(m))
@@ -720,6 +785,15 @@ const taskProgressArm = function* (m, { ctx, cards, panel, inst }) {
720
785
  }
721
786
  panel.noteResidency(taskId, identity.taskId);
722
787
  panel.markLive(taskId);
788
+ const cycleSeq = cycleSeqValue(m.seq);
789
+ panel.noteCycle(taskId, cycleSeq);
790
+ const finalUsage = {};
791
+ if (isCoreTaskProgressTerminal(m.status)) {
792
+ if (typeof usage.totalTokens === 'number' && Number.isFinite(usage.totalTokens))
793
+ finalUsage.totalTokens = true;
794
+ if (typeof usage.toolUses === 'number' && Number.isFinite(usage.toolUses))
795
+ finalUsage.toolUses = true;
796
+ }
723
797
  yield chrome({
724
798
  kind: 'panel_task',
725
799
  laneProof: panel.laneOf(taskId),
@@ -735,11 +809,13 @@ const taskProgressArm = function* (m, { ctx, cards, panel, inst }) {
735
809
  ...(panel.isLiveBound(taskId) ? { cardBound: true } : {}),
736
810
  toolUses: typeof usage.toolUses === 'number' ? usage.toolUses : 0,
737
811
  totalTokens: typeof usage.totalTokens === 'number' ? usage.totalTokens : 0,
812
+ ...(cycleSeq !== undefined ? { cycleSeq } : {}),
813
+ ...(finalUsage.totalTokens === true || finalUsage.toolUses === true ? { final: finalUsage } : {}),
738
814
  },
739
815
  });
740
816
  if (isCoreTaskProgressTerminal(m.status) && !panel.isLiveBound(taskId)) {
741
817
  ctx.probe?.('tick', JSON.stringify({ t: ctx.now(), taskId, lane: 'foreground', settle: m.status }));
742
- yield* panel.settleFromTerminalTick(taskId, isCoreTaskProgressTerminalNotSuccess(m.status));
818
+ yield* panel.settleFromTerminalTick(taskId, isCoreTaskProgressTerminalNotSuccess(m.status), cycleSeq);
743
819
  }
744
820
  };
745
821
  const streamEventArm = function* (m, { text }) {
@@ -876,7 +952,8 @@ const taskNotificationArm = function* (m, { ctx, idOf, panel, inst }) {
876
952
  });
877
953
  dropQueuedNotificationsForRun(taskId);
878
954
  if (n.task_type !== 'background_bash' && n.task_type !== 'monitor') {
879
- yield* panel.settleFromNotification(taskId, isCoreTaskNotificationTerminalNotSuccess(rawStatus));
955
+ const bgSessionId = n.task_type === 'background_agent' && typeof n.sessionId === 'string' && n.sessionId.length > 0 ? n.sessionId : undefined;
956
+ yield* panel.settleFromNotification(taskId, isCoreTaskNotificationTerminalNotSuccess(rawStatus), bgSessionId);
880
957
  }
881
958
  }
882
959
  const peerFrame = classifyPeerNotification(n);
@@ -919,23 +996,9 @@ const workflowCompleteArm = function* (m) {
919
996
  });
920
997
  };
921
998
  const retryStatusArm = function* (m, { ctx, flags }) {
922
- if (typeof m.parentToolCallId === 'string')
999
+ const status = retryStatusFromArm(m, ctx.now());
1000
+ if (status === undefined)
923
1001
  return;
924
- const status = mapBrainStatusToRetry({
925
- phase: typeof m.phase === 'string' ? m.phase : '',
926
- ...(typeof m.detail === 'string' ? { detail: m.detail } : {}),
927
- ...(typeof m.retryInSec === 'number' ? { retryInSec: m.retryInSec } : {}),
928
- ...(typeof m.retryInMs === 'number' ? { retryInMs: m.retryInMs } : {}),
929
- ...(typeof m.attempt === 'number' ? { attempt: m.attempt } : {}),
930
- ...(typeof m.maxRetries === 'number' ? { maxRetries: m.maxRetries } : {}),
931
- ...(typeof m.errClass === 'string' ? { errClass: m.errClass } : {}),
932
- ...(typeof m.retryAtMs === 'number' ? { retryAtMs: m.retryAtMs } : {}),
933
- ...(typeof m.errorStatus === 'number' ? { errorStatus: m.errorStatus } : {}),
934
- ...(typeof m.elapsedMs === 'number' ? { elapsedMs: m.elapsedMs } : {}),
935
- ...(typeof m.timeoutMs === 'number' ? { timeoutMs: m.timeoutMs } : {}),
936
- ...(typeof m.providerCondition === 'string' && m.providerCondition.length > 0 ? { providerCondition: m.providerCondition } : {}),
937
- ...(typeof m.providerConditionSource === 'string' && m.providerConditionSource.length > 0 ? { providerConditionSource: m.providerConditionSource } : {}),
938
- }, ctx.now());
939
1002
  if (status === null) {
940
1003
  if (flags.takeRetryOverlay())
941
1004
  yield chrome({ kind: 'retry_status', laneProof: mainLane(), status: null });
@@ -968,6 +1031,7 @@ export const ARMS = new Map([
968
1031
  ['user', userArm],
969
1032
  ['tool_end_result', toolEndResultArm],
970
1033
  ['task_progress', taskProgressArm],
1034
+ ['task_started', taskStartedArm],
971
1035
  ['stream_event', streamEventArm],
972
1036
  ['turn_usage', turnUsageArm],
973
1037
  ['result', resultArm],
@@ -987,6 +1051,7 @@ export const ARMS = new Map([
987
1051
  ['tool_roster_delta', toolRosterDeltaArm],
988
1052
  ['context_usage', contextUsageArm],
989
1053
  ['compaction_outcome', compactionOutcomeArm],
1054
+ ['compaction_started', compactionStartedArm],
990
1055
  ['prompt_assembled', promptAssembledArm],
991
1056
  ['wiring_manifest', wiringManifestArm],
992
1057
  ['approval_request', approvalFrameArm('approval_request')],
@@ -7,10 +7,11 @@ export interface PanelTaskLedger {
7
7
  isLiveBound(taskId: string): boolean;
8
8
  isLive(taskId: string): boolean;
9
9
  markLive(taskId: string): void;
10
+ noteCycle(taskId: string, cycleSeq: number | undefined): void;
10
11
  noteResidency(taskId: string, residentKey?: string): void;
11
12
  start(taskId: string, agentType?: string): Generator<AdapterOutput>;
12
13
  settle(cardId: string | null, isError: boolean, report?: string): Generator<AdapterOutput>;
13
- settleFromNotification(taskId: string, isError: boolean): Generator<AdapterOutput>;
14
- settleFromTerminalTick(taskId: string, isError: boolean): Generator<AdapterOutput>;
14
+ settleFromNotification(taskId: string, isError: boolean, sessionId?: string): Generator<AdapterOutput>;
15
+ settleFromTerminalTick(taskId: string, isError: boolean, cycleSeq?: number): Generator<AdapterOutput>;
15
16
  }
16
17
  export declare function createPanelTaskLedger(ctx: AdapterContext, cards: OpenCardView, inst: AdapterInstanceLedger): PanelTaskLedger;
@@ -5,7 +5,15 @@ import { SUBAGENT_TOOL_NAMES } from './wireShapes.js';
5
5
  export function createPanelTaskLedger(ctx, cards, inst) {
6
6
  const taskCardBinding = new Map();
7
7
  const livePanelTasks = new Set();
8
- const endedPanelTasks = new Set();
8
+ const endedPanelTasks = new Map();
9
+ const seenCycle = new Map();
10
+ const currentGenerationEnded = (taskId) => {
11
+ if (!endedPanelTasks.has(taskId))
12
+ return false;
13
+ const prior = endedPanelTasks.get(taskId);
14
+ const seen = seenCycle.get(taskId);
15
+ return !(prior !== undefined && seen !== undefined && prior < seen);
16
+ };
9
17
  const liveBoundPanelTasks = new Set();
10
18
  const clearResidencyBothKeys = (taskId) => clearEnginePanelTaskResidentByWire(taskId);
11
19
  const subagentTypeById = new Map();
@@ -42,6 +50,13 @@ export function createPanelTaskLedger(ctx, cards, inst) {
42
50
  markLive: (taskId) => {
43
51
  livePanelTasks.add(taskId);
44
52
  },
53
+ noteCycle: (taskId, cycleSeq) => {
54
+ if (cycleSeq === undefined)
55
+ return;
56
+ const seen = seenCycle.get(taskId);
57
+ if (seen === undefined || cycleSeq > seen)
58
+ seenCycle.set(taskId, cycleSeq);
59
+ },
45
60
  noteResidency: (taskId, residentKey = taskId) => {
46
61
  if (liveBoundPanelTasks.has(taskId))
47
62
  clearEnginePanelTaskResident(residentKey);
@@ -69,9 +84,9 @@ export function createPanelTaskLedger(ctx, cards, inst) {
69
84
  continue;
70
85
  if (cardId === null && !liveBoundPanelTasks.has(taskId))
71
86
  continue;
72
- if (endedPanelTasks.has(taskId))
87
+ if (currentGenerationEnded(taskId))
73
88
  continue;
74
- endedPanelTasks.add(taskId);
89
+ endedPanelTasks.set(taskId, undefined);
75
90
  const mintLane = laneMinterFor(taskId);
76
91
  const agentType = subagentTypeById.get(taskId);
77
92
  yield chrome({
@@ -88,15 +103,15 @@ export function createPanelTaskLedger(ctx, cards, inst) {
88
103
  });
89
104
  }
90
105
  },
91
- *settleFromNotification(taskId, isError) {
106
+ *settleFromNotification(taskId, isError, sessionId) {
92
107
  clearResidencyBothKeys(taskId);
93
- if (endedPanelTasks.has(taskId))
108
+ if (currentGenerationEnded(taskId))
94
109
  return;
95
- endedPanelTasks.add(taskId);
110
+ endedPanelTasks.set(taskId, undefined);
96
111
  yield chrome({
97
112
  kind: 'panel_task',
98
113
  laneProof: mainLane(),
99
- event: panelEndFact(taskId, isError),
114
+ event: panelEndFact(taskId, isError, sessionId !== undefined ? { sessionId } : undefined),
100
115
  });
101
116
  if (inst.hasFiredSubagentStart(taskId)) {
102
117
  yield chrome({
@@ -108,10 +123,18 @@ export function createPanelTaskLedger(ctx, cards, inst) {
108
123
  });
109
124
  }
110
125
  },
111
- *settleFromTerminalTick(taskId, isError) {
112
- if (endedPanelTasks.has(taskId))
126
+ *settleFromTerminalTick(taskId, isError, cycleSeq) {
127
+ if (endedPanelTasks.has(taskId)) {
128
+ const prior = endedPanelTasks.get(taskId);
129
+ if (cycleSeq === undefined || prior === undefined || cycleSeq <= prior)
130
+ return;
131
+ }
132
+ const seen = seenCycle.get(taskId);
133
+ if (cycleSeq !== undefined && seen !== undefined && cycleSeq < seen) {
134
+ yield chrome({ kind: 'panel_task', laneProof: laneMinterFor(taskId)(), event: panelEndFact(taskId, isError, { cycleSeq }) });
113
135
  return;
114
- endedPanelTasks.add(taskId);
136
+ }
137
+ endedPanelTasks.set(taskId, cycleSeq);
115
138
  clearResidencyBothKeys(taskId);
116
139
  const mintLane = laneMinterFor(taskId);
117
140
  const card = taskCardBinding.get(taskId);
@@ -138,7 +161,7 @@ export function createPanelTaskLedger(ctx, cards, inst) {
138
161
  yield chrome({
139
162
  kind: 'panel_task',
140
163
  laneProof: mintLane(),
141
- event: panelEndFact(taskId, isError),
164
+ event: panelEndFact(taskId, isError, cycleSeq !== undefined ? { cycleSeq } : undefined),
142
165
  });
143
166
  },
144
167
  };
@@ -36,7 +36,7 @@ export interface TextStream {
36
36
  replaceThinkingSegment(content: string, anchor?: Frame): ThinkingSegmentReplacement;
37
37
  segmentId(): string;
38
38
  anchorWindow(frame: Frame): void;
39
- rotateSegmentIdentity(anchor: Frame): void;
39
+ endSegment(): Generator<AdapterOutput>;
40
40
  stampSegmentIdentity(out: AdapterOutput): AdapterOutput;
41
41
  readonly answerLength: number;
42
42
  }
@@ -38,7 +38,6 @@ export function createTextStream(ctx, idOf) {
38
38
  let segmentCommitted = '';
39
39
  let previousSegmentCommitted = '';
40
40
  let segmentWindowCloseArmed = false;
41
- let segmentSealed = '';
42
41
  const flushEveryMs = typeof ctx.coalesceIntervalMs === 'number' && ctx.coalesceIntervalMs >= 0
43
42
  ? ctx.coalesceIntervalMs
44
43
  : FLUSH_INTERVAL_MS;
@@ -55,6 +54,25 @@ export function createTextStream(ctx, idOf) {
55
54
  segmentIdCache = idOf(segmentWindowAnchor ?? {}, 'segment');
56
55
  return segmentIdCache;
57
56
  };
57
+ const openSegmentWindow = (frame) => {
58
+ if (segmentWindowAnchor !== null)
59
+ return;
60
+ segmentWindowAnchor = frame;
61
+ segmentIdCache = null;
62
+ };
63
+ const closeSegmentWindow = () => {
64
+ committedTextRows = [];
65
+ segmentWindowAnchor = null;
66
+ segmentIdCache = null;
67
+ };
68
+ const consumeArmedClose = () => {
69
+ if (!segmentWindowCloseArmed)
70
+ return;
71
+ segmentWindowCloseArmed = false;
72
+ previousSegmentCommitted = '';
73
+ segmentCommitted = '';
74
+ closeSegmentWindow();
75
+ };
58
76
  function* takeThinking() {
59
77
  if (thinking.length === 0)
60
78
  return;
@@ -77,9 +95,11 @@ export function createTextStream(ctx, idOf) {
77
95
  yield transcript(msg, ctx.now());
78
96
  }
79
97
  function* emitAnswerSegment() {
80
- const body = segmentSealed + answerSegment;
98
+ const body = answerSegment;
81
99
  if (body.length === 0)
82
100
  return;
101
+ if (segmentAnchor !== null)
102
+ openSegmentWindow(segmentAnchor);
83
103
  const anchor = segmentAnchor ?? {};
84
104
  const msg = {
85
105
  type: 'assistant',
@@ -90,10 +110,8 @@ export function createTextStream(ctx, idOf) {
90
110
  };
91
111
  const committedTextBeforeRow = committedText;
92
112
  committedText += body;
93
- segmentCommitted += answerSegment;
94
- if (answerSegment.length > 0)
95
- committedTextRows.push({ text: body, uuid: msg.uuid, sealedPrefix: segmentSealed, msgSerial: messageSerial, msgTextBefore: committedTextBeforeRow });
96
- segmentSealed = '';
113
+ segmentCommitted += body;
114
+ committedTextRows.push({ text: body, uuid: msg.uuid, msgSerial: messageSerial, msgTextBefore: committedTextBeforeRow });
97
115
  answerSegment = '';
98
116
  segmentAnchor = null;
99
117
  segmentLast = null;
@@ -108,7 +126,7 @@ export function createTextStream(ctx, idOf) {
108
126
  segmentCommitted = '';
109
127
  }
110
128
  function* takeAnswerSegmentOnIdle() {
111
- const body = segmentSealed + answerSegment;
129
+ const body = answerSegment;
112
130
  if (body.length === 0)
113
131
  return;
114
132
  if (idleFlushUsedInSegment)
@@ -149,28 +167,20 @@ export function createTextStream(ctx, idOf) {
149
167
  }
150
168
  return {
151
169
  *feedText(delta, frame) {
152
- if (segmentWindowCloseArmed) {
153
- segmentWindowCloseArmed = false;
154
- previousSegmentCommitted = '';
155
- segmentCommitted = '';
156
- committedTextRows = [];
157
- }
170
+ consumeArmedClose();
158
171
  if (thinking.length > 0 || thinkingPending.length > 0) {
159
172
  yield* drainLive();
160
173
  yield* takeThinking();
161
174
  }
162
- if (answerSegment.length === 0 && segmentSealed.length === 0)
175
+ if (answerSegment.length === 0)
163
176
  segmentAnchor = frame;
164
177
  segmentLast = frame;
165
- if (segmentWindowAnchor === null)
166
- segmentWindowAnchor = frame;
178
+ openSegmentWindow(frame);
167
179
  answer += delta;
168
180
  answerSegment += delta;
169
181
  textPending += delta;
170
182
  },
171
183
  *feedThinking(delta, frame) {
172
- if (segmentWindowAnchor === null)
173
- segmentWindowAnchor = frame;
174
184
  if (thinkingSettled) {
175
185
  if (thinking.length > 0) {
176
186
  yield* drainLive();
@@ -212,7 +222,7 @@ export function createTextStream(ctx, idOf) {
212
222
  const rows = uuidsUnique ? rowsAll : [];
213
223
  const rowUuids = rows.map((r) => r.uuid);
214
224
  const committedRowsOut = committedPrefixDiverged && rows.length > 0
215
- ? rows.map((r, i) => ({ uuid: r.uuid, text: i === 0 ? r.sealedPrefix + content : r.sealedPrefix }))
225
+ ? rows.map((r, i) => ({ uuid: r.uuid, text: i === 0 ? content : '' }))
216
226
  : undefined;
217
227
  const attribution = uuidsUnique
218
228
  ? {
@@ -287,11 +297,12 @@ export function createTextStream(ctx, idOf) {
287
297
  }
288
298
  }
289
299
  else {
290
- segmentSealed += verdict.tail;
300
+ answerSegment = verdict.tail;
291
301
  if (diverged && anchor !== undefined)
292
302
  segmentLast = anchor;
293
303
  }
294
- answerSegment = '';
304
+ if (committedPrefixDiverged)
305
+ answerSegment = '';
295
306
  if (answer.endsWith(liveSegment)) {
296
307
  answer = answer.slice(0, answer.length - liveSegment.length) + content;
297
308
  }
@@ -305,7 +316,6 @@ export function createTextStream(ctx, idOf) {
305
316
  return { diverged, committedPrefixLen, committedPrefixDiverged, ...attribution };
306
317
  },
307
318
  hasPendingContent: () => thinking.length > 0 ||
308
- segmentSealed.length > 0 ||
309
319
  answerSegment.length > 0 ||
310
320
  thinkingPending.length > 0 ||
311
321
  textPending.length > 0,
@@ -365,13 +375,21 @@ export function createTextStream(ctx, idOf) {
365
375
  },
366
376
  segmentId: segmentIdNow,
367
377
  anchorWindow: (frame) => {
368
- if (segmentWindowAnchor === null)
369
- segmentWindowAnchor = frame;
378
+ openSegmentWindow(frame);
370
379
  },
371
- rotateSegmentIdentity: (anchor) => {
372
- committedTextRows = [];
373
- segmentWindowAnchor = anchor;
374
- segmentIdCache = null;
380
+ *endSegment() {
381
+ try {
382
+ yield* emitAnswerSegment();
383
+ }
384
+ finally {
385
+ segmentAnchor = null;
386
+ segmentLast = null;
387
+ segmentCommitted = '';
388
+ previousSegmentCommitted = '';
389
+ idleFlushUsedInSegment = false;
390
+ textBlockOpen = false;
391
+ closeSegmentWindow();
392
+ }
375
393
  },
376
394
  stampSegmentIdentity: (out) => {
377
395
  if (out.plane !== 'transcript')
@@ -385,6 +403,11 @@ export function createTextStream(ctx, idOf) {
385
403
  const last = blocks[blocks.length - 1];
386
404
  if (last === undefined || last.type !== 'text' || typeof last.text !== 'string')
387
405
  return out;
406
+ if (segmentWindowAnchor === null) {
407
+ const rowUuid = out.message.uuid;
408
+ openSegmentWindow(typeof rowUuid === 'string' ? { uuid: rowUuid } : {});
409
+ }
410
+ ;
388
411
  out.message[SEMA_SEGMENT_ID_KEY] = segmentIdNow();
389
412
  return out;
390
413
  },
@@ -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';
@@ -39,11 +40,14 @@ export type ReopenCardVerdict = {
39
40
  dismissedByUser?: true;
40
41
  _sema_noPresentationSurface?: true;
41
42
  _sema_errorCode?: string;
43
+ _sema_reopenRefusal?: PlanReviewReopenRefusal;
42
44
  } | {
43
45
  reopened: true;
44
46
  firstSight: boolean;
45
47
  presented?: boolean;
46
48
  };
49
+ export declare const PLAN_REVIEW_REOPEN_REFUSALS: readonly ["invalid_call", "no_delivery_path", "not_presented", "gate_record_gone", "internal_error"];
50
+ export type PlanReviewReopenRefusal = (typeof PLAN_REVIEW_REOPEN_REFUSALS)[number];
47
51
  export interface RunningChoiceRequest {
48
52
  taskId: string;
49
53
  status: string;
@@ -139,6 +143,8 @@ export type SelfHealOutcome = {
139
143
  taskId: string;
140
144
  detail: string;
141
145
  delivery: 'rejected' | 'unknown';
146
+ errorCode?: string;
147
+ runStatus?: string;
142
148
  } | {
143
149
  kind: 'running-attach';
144
150
  taskId: string;
@@ -228,9 +234,11 @@ export interface ActiveRunSelfHealCopy {
228
234
  freshSession?: string;
229
235
  keepSessionWayOut?: () => string | null;
230
236
  engineDecidePath?: boolean;
237
+ endRun?: string;
238
+ wakeSession?: string | null;
231
239
  rowFor?: (outcome: SelfHealOutcome, signal: ActiveRunBusySignal | null | undefined) => string | undefined;
232
240
  headlessRowFor?: (signal: ActiveRunBusySignal) => string | undefined;
233
241
  }
234
- export declare const INTERACTIVE_WAY_OUT = "run /clear to keep working in a fresh session";
235
- export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration): string;
236
- export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy): string;
242
+ export declare const INTERACTIVE_WAY_OUT: string;
243
+ export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration, lang?: UiLanguage): string;
244
+ export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy, lang?: UiLanguage): string;