@sema-agent/client-core 0.100.0 → 0.101.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 (335) hide show
  1. package/CHANGELOG.md +395 -0
  2. package/README.md +164 -117
  3. package/dist/adapt/arms.js +51 -16
  4. package/dist/adapt/textStream.js +7 -4
  5. package/dist/adapt/toolCards.js +9 -8
  6. package/dist/adapt.js +7 -1
  7. package/dist/adapter/activeRunSelfHeal.d.ts +24 -2
  8. package/dist/adapter/activeRunSelfHeal.js +108 -6
  9. package/dist/adapter/downstream/eventToSdkMessage.js +33 -12
  10. package/dist/adapter/downstream/terminalToSdkResult.d.ts +60 -1
  11. package/dist/adapter/downstream/terminalToSdkResult.js +209 -39
  12. package/dist/adapter/runStream.d.ts +4 -4
  13. package/dist/adapter/runStream.js +158 -43
  14. package/dist/agentsWireCaps.d.ts +2 -7
  15. package/dist/agentsWireCaps.js +1 -2
  16. package/dist/approvalDecidedByCapability.js +2 -2
  17. package/dist/approvalFrameFamilies.d.ts +33 -0
  18. package/dist/approvalFrameFamilies.js +120 -0
  19. package/dist/approvalsStreamLiveCapability.js +2 -2
  20. package/dist/attachmentsWireCaps.js +41 -13
  21. package/dist/callerCwdCapability.js +2 -2
  22. package/dist/centerWiringCapability.js +2 -2
  23. package/dist/clockReading.d.ts +2 -0
  24. package/dist/clockReading.js +4 -0
  25. package/dist/cloudConfigWireCaps.d.ts +19 -5
  26. package/dist/cloudConfigWireCaps.js +193 -56
  27. package/dist/coreValuePorts.d.ts +12 -2
  28. package/dist/coreValuePorts.js +9 -0
  29. package/dist/decideFailureNote.js +5 -3
  30. package/dist/decideReceipt.js +2 -2
  31. package/dist/deviceExecutorManagementCapability.js +2 -2
  32. package/dist/deviceFlowPolling.js +1 -1
  33. package/dist/disableSkillsWire.d.ts +1 -1
  34. package/dist/disableSkillsWire.js +4 -3
  35. package/dist/displayUntrusted.d.ts +1 -0
  36. package/dist/displayUntrusted.js +65 -8
  37. package/dist/engineCapReader.js +1 -1
  38. package/dist/engineConfigDrift.js +1 -1
  39. package/dist/engineErrorCodes.d.ts +14 -5
  40. package/dist/engineErrorCodes.js +27 -6
  41. package/dist/engineGenerationConvergence.d.ts +39 -0
  42. package/dist/engineGenerationConvergence.js +95 -0
  43. package/dist/engineGenerationPort.d.ts +61 -0
  44. package/dist/engineGenerationPort.js +144 -0
  45. package/dist/engineHealthFacts.d.ts +23 -0
  46. package/dist/engineHealthFacts.js +92 -0
  47. package/dist/engineIdentity.d.ts +4 -0
  48. package/dist/engineIdentity.js +11 -0
  49. package/dist/engineNoticeCodes.d.ts +2 -5
  50. package/dist/engineRowRef.js +3 -0
  51. package/dist/engineSessionMessages.js +2 -2
  52. package/dist/engineToolDirectory.js +2 -2
  53. package/dist/engineWireFor.d.ts +99 -0
  54. package/dist/engineWireFor.js +248 -6
  55. package/dist/engineWireTarget.d.ts +1 -0
  56. package/dist/engineWireTarget.js +8 -0
  57. package/dist/env/uiLanguage.js +1 -1
  58. package/dist/errorSupplementRoles.d.ts +3 -0
  59. package/dist/errorSupplementRoles.js +37 -0
  60. package/dist/executionLaneCapability.js +2 -2
  61. package/dist/fileHistoryCaptureCapability.js +3 -3
  62. package/dist/finalVerifyWire.d.ts +6 -3
  63. package/dist/finalVerifyWire.js +6 -23
  64. package/dist/flagInput.d.ts +4 -0
  65. package/dist/flagInput.js +24 -0
  66. package/dist/fleet/fleetLedger.js +5 -2
  67. package/dist/fleet/fleetProjection.d.ts +1 -0
  68. package/dist/fleet/fleetProjection.js +15 -2
  69. package/dist/gateVocabulary.js +3 -0
  70. package/dist/generated/engineFactTables.d.ts +7 -3
  71. package/dist/generated/engineFactTables.js +52 -0
  72. package/dist/generated/engineNoticeTables.js +12 -0
  73. package/dist/generated/settingsSchemaActiveTiers.d.ts +1 -0
  74. package/dist/generated/settingsSchemaActiveTiers.js +14 -0
  75. package/dist/generated/settingsSchemaCallerTextEcho.d.ts +1 -0
  76. package/dist/generated/settingsSchemaCallerTextEcho.js +8 -0
  77. package/dist/generated/settingsSchemaControlAndBidi.d.ts +1 -0
  78. package/dist/generated/settingsSchemaControlAndBidi.js +8 -0
  79. package/dist/generated/settingsSchemaDefaultModel.d.ts +11 -0
  80. package/dist/generated/settingsSchemaDefaultModel.js +25 -0
  81. package/dist/generated/settingsSchemaFns.d.ts +54 -0
  82. package/dist/generated/settingsSchemaFns.js +26 -1
  83. package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -1
  84. package/dist/generated/settingsSchemaMcpRequestEntry.js +1 -7
  85. package/dist/generated/settingsSchemaSafetyMergeSpec.d.ts +1 -0
  86. package/dist/generated/settingsSchemaSafetyMergeSpec.js +95 -0
  87. package/dist/generated/settingsSchemaSettingsSources.d.ts +1 -0
  88. package/dist/generated/settingsSchemaSettingsSources.js +58 -0
  89. package/dist/generated/settingsSchemaTables.d.ts +2 -0
  90. package/dist/generated/settingsSchemaTables.js +13 -0
  91. package/dist/generated/settingsSchemaUrlPattern.d.ts +1 -0
  92. package/dist/generated/settingsSchemaUrlPattern.js +183 -0
  93. package/dist/headlessPermissionModeWire.d.ts +18 -2
  94. package/dist/headlessPermissionModeWire.js +30 -19
  95. package/dist/hitl/allowRuleShadow.js +7 -5
  96. package/dist/hitl/approvalCardReading.d.ts +3 -0
  97. package/dist/hitl/approvalCardReading.js +17 -0
  98. package/dist/hitl/approvalCompleteParked.js +1 -1
  99. package/dist/hitl/approvalDelivery.d.ts +87 -0
  100. package/dist/hitl/approvalDelivery.js +193 -0
  101. package/dist/hitl/approvalResolution.d.ts +11 -0
  102. package/dist/hitl/approvalResolution.js +50 -11
  103. package/dist/hitl/askClassPair.d.ts +6 -0
  104. package/dist/hitl/askClassPair.js +30 -3
  105. package/dist/hitl/askParkAutoReopenBlock.d.ts +30 -0
  106. package/dist/hitl/askParkAutoReopenBlock.js +117 -0
  107. package/dist/hitl/askParkRowRouting.js +4 -1
  108. package/dist/hitl/attributionLadder.d.ts +42 -3
  109. package/dist/hitl/attributionLadder.js +79 -8
  110. package/dist/hitl/automaticAnswerVerdict.d.ts +6 -1
  111. package/dist/hitl/automaticAnswerVerdict.js +46 -11
  112. package/dist/hitl/crashConverged.js +2 -2
  113. package/dist/hitl/decisionConflict.d.ts +6 -2
  114. package/dist/hitl/decisionConflict.js +24 -9
  115. package/dist/hitl/decisionRefusal.d.ts +20 -10
  116. package/dist/hitl/decisionRefusal.js +99 -54
  117. package/dist/hitl/decisionSend.d.ts +3 -0
  118. package/dist/hitl/decisionSend.js +87 -103
  119. package/dist/hitl/frameRouter.d.ts +1 -0
  120. package/dist/hitl/frameRouter.js +9 -2
  121. package/dist/hitl/hitlBridge.d.ts +18 -6
  122. package/dist/hitl/hitlBridge.js +41 -37
  123. package/dist/hitl/livePendingAsk.js +4 -3
  124. package/dist/hitl/noAllowCause.js +1 -1
  125. package/dist/hitl/parkResolver.js +3 -2
  126. package/dist/hitl/persistedRulesWire.js +1 -0
  127. package/dist/hitl/planReviewWire.d.ts +4 -0
  128. package/dist/hitl/planReviewWire.js +59 -30
  129. package/dist/hitl/resumeRunningCard.d.ts +3 -2
  130. package/dist/hitl/resumeRunningCard.js +17 -11
  131. package/dist/hitl/sessionPolicyDeliverable.d.ts +5 -2
  132. package/dist/hitl/sessionPolicyDeliverable.js +62 -29
  133. package/dist/hitl/sessionPolicyWire.d.ts +13 -3
  134. package/dist/hitl/sessionPolicyWire.js +81 -16
  135. package/dist/hitl/standingRows.js +1 -1
  136. package/dist/hitl/toolApprovalWire.d.ts +9 -10
  137. package/dist/hitl/toolApprovalWire.js +72 -54
  138. package/dist/hookMatcherVerdict.d.ts +2 -0
  139. package/dist/hookMatcherVerdict.js +12 -0
  140. package/dist/hooksCompactTransition.d.ts +19 -0
  141. package/dist/hooksCompactTransition.js +41 -0
  142. package/dist/hooksWireCaps.d.ts +1 -1
  143. package/dist/hooksWireCaps.js +202 -203
  144. package/dist/host.d.ts +1 -14
  145. package/dist/host.js +0 -8
  146. package/dist/hostCallbackGuard.d.ts +1 -0
  147. package/dist/hostCallbackGuard.js +1 -1
  148. package/dist/hostSettingsSource.d.ts +172 -0
  149. package/dist/hostSettingsSource.js +675 -0
  150. package/dist/hostTurnSettings.d.ts +73 -17
  151. package/dist/hostTurnSettings.js +594 -97
  152. package/dist/httpHookPolicy.d.ts +37 -0
  153. package/dist/httpHookPolicy.js +176 -0
  154. package/dist/humanTurn.d.ts +2 -1
  155. package/dist/humanTurn.js +37 -7
  156. package/dist/humanTurnRead.js +4 -3
  157. package/dist/humanTurnSentences.d.ts +10 -0
  158. package/dist/humanTurnSentences.js +74 -0
  159. package/dist/i18n/messages.en.d.ts +184 -2
  160. package/dist/i18n/messages.en.js +187 -5
  161. package/dist/i18n/messages.zh.js +197 -5
  162. package/dist/i18n/translate.js +3 -3
  163. package/dist/index.d.ts +69 -15
  164. package/dist/index.js +45 -13
  165. package/dist/inheritEnvCapability.d.ts +3 -1
  166. package/dist/inheritEnvCapability.js +31 -17
  167. package/dist/inheritEnvWire.d.ts +2 -1
  168. package/dist/inheritEnvWire.js +11 -5
  169. package/dist/interactiveToolsWire.d.ts +4 -2
  170. package/dist/interactiveToolsWire.js +5 -5
  171. package/dist/jsonFaithful.d.ts +20 -0
  172. package/dist/jsonFaithful.js +152 -0
  173. package/dist/limitsWire.d.ts +7 -2
  174. package/dist/limitsWire.js +19 -13
  175. package/dist/liveInitToolFace.d.ts +6 -1
  176. package/dist/liveInitToolFace.js +5 -3
  177. package/dist/liveModelCatalog.d.ts +22 -0
  178. package/dist/liveModelCatalog.js +132 -18
  179. package/dist/mcpPanel.js +1 -1
  180. package/dist/mcpProbeCapability.js +2 -2
  181. package/dist/mcpStatusSupersetKeys.d.ts +24 -0
  182. package/dist/mcpStatusSupersetKeys.js +45 -0
  183. package/dist/mcpToolToggles.js +2 -1
  184. package/dist/mcpWireCaps.d.ts +39 -1
  185. package/dist/mcpWireCaps.js +254 -50
  186. package/dist/memoryComplianceCapability.js +2 -2
  187. package/dist/memoryOriginCapability.js +2 -2
  188. package/dist/model/catalogDefault.d.ts +24 -0
  189. package/dist/model/catalogDefault.js +4 -0
  190. package/dist/model/liveCatalogShape.js +5 -4
  191. package/dist/model/modelsPolicy.js +4 -3
  192. package/dist/model/onboardJudgement.d.ts +1 -0
  193. package/dist/model/onboardJudgement.js +1 -1
  194. package/dist/model/subagentModelWord.js +2 -2
  195. package/dist/modelCapabilityProbe.js +6 -6
  196. package/dist/modelIdentityResolvability.d.ts +10 -1
  197. package/dist/modelIdentityResolvability.js +62 -39
  198. package/dist/modsKernelIdentity.d.ts +10 -0
  199. package/dist/modsKernelIdentity.js +103 -0
  200. package/dist/modsKernelTransit.d.ts +8 -0
  201. package/dist/modsKernelTransit.js +6 -0
  202. package/dist/notifications.d.ts +30 -12
  203. package/dist/notifications.js +241 -53
  204. package/dist/outputStyleSeatCapability.js +2 -2
  205. package/dist/ownKey.d.ts +11 -0
  206. package/dist/ownKey.js +164 -3
  207. package/dist/panelReduce.js +1 -1
  208. package/dist/peerFrames.d.ts +1 -1
  209. package/dist/peerFrames.js +6 -2
  210. package/dist/peerLaneCapability.js +2 -2
  211. package/dist/permissionModesCapability.js +4 -4
  212. package/dist/permissionRuleIssue.js +2 -0
  213. package/dist/permissionRulesWriteCapability.js +2 -2
  214. package/dist/permissionsAllowGrantCapability.js +2 -2
  215. package/dist/permissionsDeclaration.d.ts +43 -4
  216. package/dist/permissionsDeclaration.js +102 -35
  217. package/dist/pluginHooksWire.d.ts +20 -4
  218. package/dist/pluginHooksWire.js +92 -53
  219. package/dist/prepareRefusal.d.ts +3 -2
  220. package/dist/prepareRefusal.js +27 -9
  221. package/dist/printInitToolFace.js +2 -2
  222. package/dist/printModelStatus.js +1 -1
  223. package/dist/projectMemory.d.ts +32 -0
  224. package/dist/projectMemory.js +70 -0
  225. package/dist/promptBlockedCopy.d.ts +2 -1
  226. package/dist/promptBlockedCopy.js +2 -1
  227. package/dist/promptDelivery.d.ts +23 -3
  228. package/dist/promptDelivery.js +169 -30
  229. package/dist/providerRejection.d.ts +19 -1
  230. package/dist/providerRejection.js +75 -4
  231. package/dist/queuedDelivery.d.ts +48 -0
  232. package/dist/queuedDelivery.js +233 -0
  233. package/dist/reattachWindow.d.ts +94 -0
  234. package/dist/reattachWindow.js +127 -0
  235. package/dist/request/printNotification.d.ts +1 -1
  236. package/dist/request/printNotification.js +5 -1
  237. package/dist/request/submissionIdentity.d.ts +37 -0
  238. package/dist/request/submissionIdentity.js +65 -0
  239. package/dist/request/taskRequest.d.ts +12 -4
  240. package/dist/request/taskRequest.js +221 -152
  241. package/dist/resultFrameKeys.d.ts +1 -0
  242. package/dist/resultFrameKeys.js +4 -1
  243. package/dist/retryStatus.d.ts +8 -0
  244. package/dist/retryStatus.js +57 -9
  245. package/dist/rewindArchiveCapability.js +2 -2
  246. package/dist/rewindEngineAction.d.ts +2 -0
  247. package/dist/rewindEngineAction.js +23 -1
  248. package/dist/rowKind.d.ts +36 -0
  249. package/dist/rowKind.js +97 -0
  250. package/dist/ruleCompileVerdict.d.ts +18 -0
  251. package/dist/ruleCompileVerdict.js +67 -2
  252. package/dist/ruleReadings.d.ts +58 -0
  253. package/dist/ruleReadings.js +132 -0
  254. package/dist/ruleRefusalSentence.d.ts +4 -0
  255. package/dist/ruleRefusalSentence.js +9 -3
  256. package/dist/runCancelContext.d.ts +0 -1
  257. package/dist/runCancelContext.js +1 -2
  258. package/dist/runTerminal.d.ts +5 -0
  259. package/dist/runTerminal.js +52 -17
  260. package/dist/sandboxWire.d.ts +1 -1
  261. package/dist/sandboxWire.js +4 -6
  262. package/dist/scenarioRefusal.js +1 -1
  263. package/dist/scenarioSkills.d.ts +20 -0
  264. package/dist/scenarioSkills.js +72 -0
  265. package/dist/scenarioWire.d.ts +5 -2
  266. package/dist/scenarioWire.js +9 -9
  267. package/dist/sealedKeyCapability.js +2 -2
  268. package/dist/seam.d.ts +2 -0
  269. package/dist/seam.js +2 -2
  270. package/dist/seatContract.d.ts +46 -1
  271. package/dist/seatContract.js +49 -19
  272. package/dist/selfOrchestrationDenial.js +1 -1
  273. package/dist/sessionPolicyCapability.js +2 -2
  274. package/dist/sessionRulesChildrenReadLive.d.ts +6 -0
  275. package/dist/sessionRulesChildrenReadLive.js +5 -0
  276. package/dist/sessionRulesNamespaceFormsCapability.d.ts +12 -0
  277. package/dist/sessionRulesNamespaceFormsCapability.js +29 -0
  278. package/dist/sessionSyncFileHistoryCapability.js +2 -2
  279. package/dist/settingsCredentialKeyPaths.js +60 -5
  280. package/dist/settingsHooksSalvage.d.ts +1 -0
  281. package/dist/settingsHooksSalvage.js +7 -1
  282. package/dist/settingsLayerAdmission.d.ts +4 -0
  283. package/dist/settingsLayerAdmission.js +16 -0
  284. package/dist/skillToolListsCapability.js +6 -5
  285. package/dist/skillsWireCaps.d.ts +14 -0
  286. package/dist/skillsWireCaps.js +47 -16
  287. package/dist/slashCommandGate.d.ts +24 -0
  288. package/dist/slashCommandGate.js +74 -0
  289. package/dist/slashCommandTable.d.ts +14 -0
  290. package/dist/slashCommandTable.js +99 -0
  291. package/dist/sqlEngineCapability.js +2 -2
  292. package/dist/steerPriorityCapability.js +2 -2
  293. package/dist/storePostureCapability.js +2 -2
  294. package/dist/subagent/agentStateDetail.js +1 -1
  295. package/dist/subagent/engineDelegatedPrompt.d.ts +9 -0
  296. package/dist/subagent/engineDelegatedPrompt.js +38 -7
  297. package/dist/subagent/engineRowStopGate.js +2 -2
  298. package/dist/subagent/engineSubagentResume.js +3 -3
  299. package/dist/subagent/engineTaskHandleWire.d.ts +1 -0
  300. package/dist/subagent/engineTaskHandleWire.js +10 -0
  301. package/dist/submitFailure.d.ts +8 -0
  302. package/dist/submitFailure.js +17 -0
  303. package/dist/supportFloor.d.ts +1 -0
  304. package/dist/supportFloor.js +7 -0
  305. package/dist/terminationIntent.d.ts +55 -0
  306. package/dist/terminationIntent.js +352 -0
  307. package/dist/toolHistoryMismatch.d.ts +8 -0
  308. package/dist/toolHistoryMismatch.js +37 -6
  309. package/dist/toolResult.d.ts +13 -3
  310. package/dist/toolResult.js +158 -9
  311. package/dist/toolResultContent.d.ts +13 -0
  312. package/dist/toolResultContent.js +82 -7
  313. package/dist/toolRoster.d.ts +18 -0
  314. package/dist/toolRoster.js +64 -0
  315. package/dist/turnFailurePresentation.js +27 -90
  316. package/dist/usageLimitAutoResume.d.ts +74 -0
  317. package/dist/usageLimitAutoResume.js +227 -0
  318. package/dist/userAttachmentEnvelope.js +1 -1
  319. package/dist/userAttachmentSeat.js +5 -5
  320. package/dist/userInvokedSkillsCapability.js +2 -2
  321. package/dist/webSearchBackendCapability.js +2 -2
  322. package/dist/wireErrorTriage.js +99 -50
  323. package/dist/wireFailureShape.d.ts +25 -1
  324. package/dist/wireFailureShape.js +92 -5
  325. package/dist/wireRefusalCopy.d.ts +24 -1
  326. package/dist/wireRefusalCopy.js +253 -32
  327. package/dist/wiringFleetDoctor.d.ts +3 -0
  328. package/dist/wiringFleetDoctor.js +21 -0
  329. package/dist/workflow.d.ts +2 -1
  330. package/dist/workflow.js +38 -1
  331. package/dist/workflowClient.d.ts +2 -7
  332. package/dist/workflowsJournalCapability.js +2 -2
  333. package/dist/writeProtectionCapability.js +2 -2
  334. package/docs/INTEGRATION-CLIENTS.md +607 -181
  335. package/package.json +14 -3
@@ -1,6 +1,7 @@
1
1
  export declare const REDACTION_MARKER_PREFIX = "\u00ABredacted";
2
2
  export declare function looksLikeKnownSecret(s: string): boolean;
3
3
  export declare function isDiagnosticValueWord(value: string): boolean;
4
+ export declare function percentBoundaryReadingOf(text: string): string;
4
5
  export declare function washCredentials(text: string): string;
5
6
  export type DisplayMark = 'escape' | 'dot' | 'space';
6
7
  export interface DisplayFace {
@@ -1407,6 +1407,10 @@ function percentBoundaryDecode(text) {
1407
1407
  }
1408
1408
  return { decoded: chars.join(''), from, to };
1409
1409
  }
1410
+ export function percentBoundaryReadingOf(text) {
1411
+ const wide = percentBoundaryDecode(text);
1412
+ return wide === null ? text : wide.decoded;
1413
+ }
1410
1414
  const MAX_PERCENT_VIEW_LAYERS = 3;
1411
1415
  function percentLayers(text) {
1412
1416
  const out = [];
@@ -3911,11 +3915,12 @@ function screenSurfaces(text, o) {
3911
3915
  function percentSurfaces(raw, text, base, o) {
3912
3916
  const surfaces = [];
3913
3917
  const contents = [];
3918
+ const locals = [];
3914
3919
  for (const layer of percentLayers(text))
3915
- layerSurfaces(raw, layer, base, o, surfaces, contents);
3916
- return { surfaces, contents };
3920
+ layerSurfaces(raw, layer, base, o, surfaces, contents, true, base === null ? locals : undefined);
3921
+ return { surfaces, contents, locals };
3917
3922
  }
3918
- function layerSurfaces(raw, layer, base, o, surfaces, contents, decoded = true) {
3923
+ function layerSurfaces(raw, layer, base, o, surfaces, contents, decoded = true, locals) {
3919
3924
  const n = layer.text.length;
3920
3925
  const ps = new Int32Array(n);
3921
3926
  const pe = new Int32Array(n);
@@ -3937,6 +3942,52 @@ function layerSurfaces(raw, layer, base, o, surfaces, contents, decoded = true)
3937
3942
  surfaces.push(base === null ? { ...joined, rawDot: null, decoded } : { ...joined, decoded });
3938
3943
  for (const [a, b] of VD.contents)
3939
3944
  contents.push({ sub: layer.text.slice(a, b), rawAt: (k) => ps[a + k] ?? 0, rawEndAt: (k) => pe[a + k] ?? 0 });
3945
+ if (locals !== undefined && decoded && base === null && hasLineBreakAny(layer.text)) {
3946
+ locals.push({ text: layer.text, view: VD, ps, pe });
3947
+ if (layer.text.includes('+')) {
3948
+ const spaced = layer.text.split('+').join(' ');
3949
+ locals.push({ text: spaced, view: buildScanView(spaced, o), ps, pe });
3950
+ }
3951
+ }
3952
+ }
3953
+ function hasLineBreakAny(text) {
3954
+ for (let i = 0; i < text.length; i++) {
3955
+ const c = text.charCodeAt(i);
3956
+ if ((c === 0x0a || c === 0x0d || c === 0x5c) && lineBreakLengthAt(text, i) > 0)
3957
+ return true;
3958
+ }
3959
+ return false;
3960
+ }
3961
+ function decodedLayerLocalCandidates(L, o, out) {
3962
+ const layerSep = { ...separatedSurface(L.text, L.view), rawDot: null, decoded: true };
3963
+ const layerJoined = joinedSurface(L.text, L.view);
3964
+ const surfaces = layerJoined === null ? [layerSep] : [layerSep, { ...layerJoined, rawDot: null, decoded: true }];
3965
+ const blocks = { raw: L.text, view: L.view, out: [], lines: [null, null], marks: null };
3966
+ const found = [];
3967
+ for (const S of surfaces) {
3968
+ const cands = [];
3969
+ const regions = [];
3970
+ if (o.urls) {
3971
+ const unitPos = (k) => S.dropped(k) || L.view.rawUnit[S.rawStart(k)] === 1;
3972
+ urlCandidates(S.text, [], regions, unitPos, (k) => unitPos(k) || S.painted(k), o.queryByShape ?? false, o.wholeAddress === true, false);
3973
+ }
3974
+ runLabelPasses(S, regions, cands, blocks);
3975
+ for (const c of cands) {
3976
+ const r = toRaw(S, c);
3977
+ if (r !== null)
3978
+ found.push(r);
3979
+ }
3980
+ }
3981
+ for (const r of blocks.out)
3982
+ found.push(r);
3983
+ for (const r of found) {
3984
+ const start = L.ps[r.start];
3985
+ const end = L.pe[r.end - 1];
3986
+ if (start === undefined || end === undefined || end <= start)
3987
+ continue;
3988
+ const tokenEnd = r.tokenEnd > r.start ? (L.pe[Math.min(r.tokenEnd, L.text.length) - 1] ?? end) : end;
3989
+ out.push({ ...r, start, end, tokenEnd });
3990
+ }
3940
3991
  }
3941
3992
  function parserViewLayer(text) {
3942
3993
  if (!/[\t\n\r]/.test(text))
@@ -4209,6 +4260,13 @@ function toRaw(S, c) {
4209
4260
  const te = c.te > b ? S.rawEnd(c.te - 1) : S.rawEnd(b - 1);
4210
4261
  return { start: S.rawStart(a), end: S.rawEnd(b - 1), kind: c.kind, cls: c.cls, tokenEnd: te };
4211
4262
  }
4263
+ function runLabelPasses(S, regions, cands, blocks) {
4264
+ labelCandidates(S, 'scheme', regions, cands, blocks);
4265
+ labelCandidates(S, 'token', regions, cands, blocks);
4266
+ labelCandidates(S, 'label', regions, cands, blocks);
4267
+ labelCandidates(S, 'scheme', regions, cands, blocks, true);
4268
+ labelCandidates(S, 'label', regions, cands, blocks, true);
4269
+ }
4212
4270
  function collectCandidates(text, o, nested) {
4213
4271
  const V = buildScanView(text, o);
4214
4272
  const separated = separatedSurface(text, V);
@@ -4252,11 +4310,7 @@ function collectCandidates(text, o, nested) {
4252
4310
  if (o.words) {
4253
4311
  editsToCandidates(pemEdits(S, (blk) => { if (S === regionSurface)
4254
4312
  pemBlocksSeen.push(pemBlockToRaw(S, blk)); }), 'pem', cands);
4255
- labelCandidates(S, 'scheme', regions, cands, blocks);
4256
- labelCandidates(S, 'token', regions, cands, blocks);
4257
- labelCandidates(S, 'label', regions, cands, blocks);
4258
- labelCandidates(S, 'scheme', regions, cands, blocks, true);
4259
- labelCandidates(S, 'label', regions, cands, blocks, true);
4313
+ runLabelPasses(S, regions, cands, blocks);
4260
4314
  editsToCandidates(authParamEdits(S.text), 'param', cands);
4261
4315
  editsToCandidates(proseLiteralEdits(S.text), 'prose', cands);
4262
4316
  }
@@ -4266,6 +4320,9 @@ function collectCandidates(text, o, nested) {
4266
4320
  raw.push(S.rawDot !== null ? { ...r, dotted: true } : r);
4267
4321
  }
4268
4322
  }
4323
+ if (o.words)
4324
+ for (const L of decoded.locals)
4325
+ decodedLayerLocalCandidates(L, o, raw);
4269
4326
  if (!nested) {
4270
4327
  for (const [a, b] of V.contents) {
4271
4328
  const sub = text.slice(a, b);
@@ -11,7 +11,7 @@ function freezeReading(reading, seen = new Set()) {
11
11
  seen.add(reading);
12
12
  Object.freeze(reading);
13
13
  for (const d of Object.values(Object.getOwnPropertyDescriptors(reading))) {
14
- if ('value' in d)
14
+ if (Object.hasOwn(d, 'value'))
15
15
  freezeReading(d.value, seen);
16
16
  }
17
17
  return reading;
@@ -3,7 +3,7 @@ function countOf(v) {
3
3
  }
4
4
  function ownValue(o, key) {
5
5
  const d = Object.getOwnPropertyDescriptor(o, key);
6
- return d !== undefined && 'value' in d ? d.value : undefined;
6
+ return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
7
7
  }
8
8
  export function readEngineConfigApplyState(health) {
9
9
  try {
@@ -1,4 +1,6 @@
1
+ import { SDK_STATUS_DERIVED_COARSE_CODES } from './generated/sdkFactTables.js';
1
2
  import type { RunDeathVerdictCode } from '@sema-agent/sdk';
3
+ import type { SDKResultError } from '@sema-agent/agent-types';
2
4
  export declare const LIMITS_MAX_TOKENS_EXCEEDED = "limits.max_tokens_exceeded";
3
5
  export declare const LIMITS_MAX_COST_EXCEEDED = "limits.max_cost_exceeded";
4
6
  export declare const LIMITS_MAX_TURNS_EXCEEDED = "limits.max_turns_exceeded";
@@ -8,8 +10,6 @@ export declare const USAGE_WINDOW_EXHAUSTED = "usage.window_exhausted";
8
10
  export declare const ENV_LIFETIME_EXPIRED = "env.lifetime_expired";
9
11
  export declare const FLEET_LEASE_UNAVAILABLE = "fleet.lease_unavailable";
10
12
  export declare const CONFIG_LIMIT_INVALID = "config.limit_invalid";
11
- export declare const CONFIG_STRATEGY_FIND_LIMIT_INVALID = "config.strategy_find_limit_invalid";
12
- export declare const CONFIG_STRATEGY_MAX_SIZE_INVALID = "config.strategy_max_size_invalid";
13
13
  export declare const CONFIG_LIMIT_UNKNOWN_KEY = "config.limit_unknown_key";
14
14
  export declare const CONFIG_DELEGATION_ENTRY_CAPS = "config.delegation_entry_caps";
15
15
  export declare const CONFIG_MEMORY_PROJECT_KEY_SPELLING = "config.memory_project_key_spelling";
@@ -18,6 +18,7 @@ export declare const CONFIG_LEGACY_TOOL_NAME = "config.legacy_tool_name";
18
18
  export declare const CONFIG_IMAGE_INVALID = "config.image_invalid";
19
19
  export declare const CONFIG_AGENT_UNKNOWN_TOOL = "config.agent.unknown_tool";
20
20
  export declare const CONFIG_TOOL_FACE_CONTROL = "config.tool_face_control";
21
+ export declare const CONFIG_MCP_SERVER_NAME_COLLISION = "config.mcp_server_name_collision";
21
22
  export declare const PROMPT_ASSEMBLED_ROLE_REFUSED = "prompt.assembled_role_refused";
22
23
  export declare const CONFIG_OUTPUT_STYLE_INVALID = "config.output_style_invalid";
23
24
  export declare const RULES_INERT_ENTRY = "rules.inert_entry";
@@ -30,6 +31,8 @@ export declare function isDelegationCapCode(code: string | undefined): boolean;
30
31
  export type DelegationCapDisposition = 'wait-for-slot' | 'reuse-existing-or-await-reap';
31
32
  export declare function delegationCapDispositionOf(code: string | undefined): DelegationCapDisposition | undefined;
32
33
  export declare const MCP_SERVER_REVOKED = "mcp.server_revoked";
34
+ export declare const MCP_TOOL_DECLARATION_CHANGED = "mcp.tool_declaration_changed";
35
+ export declare const MCP_TOOL_LISTING_UNREACHED = "mcp.tool_listing_unreached";
33
36
  export declare function isConfigRefusalCode(code: string | undefined): boolean;
34
37
  export declare const TOOL_END_INTERRUPTED_NEVER_STARTED = "interrupted_never_started";
35
38
  export declare const TOOL_END_INTERRUPTED_OUTCOME_UNKNOWN = "interrupted_outcome_unknown";
@@ -63,8 +66,13 @@ export declare const STOP_NOT_LANDED = "stop.not_landed";
63
66
  export declare const STOP_NOT_LOCAL = "stop.not_local";
64
67
  export declare const STOP_PARKED = "stop.parked";
65
68
  export declare const OUTPUT_INVALID = "output.invalid";
69
+ export type ResultLimitWord = 'wall_clock' | 'tokens' | 'turns' | 'budget_usd' | 'structured_output_retries';
70
+ export declare const RESULT_LIMIT_WORDS: readonly ResultLimitWord[];
71
+ export declare function resultLimitRowOfCode(code: string | undefined): {
72
+ readonly word: ResultLimitWord;
73
+ readonly subtype: SDKResultError['subtype'];
74
+ } | undefined;
66
75
  export declare const RESUME_POLICY_FOLD_CODE = "resume_blocked_by_policy";
67
- export declare const STATUS_DERIVED_COARSE_CODES: readonly ["request.rejected", "auth.unauthorized", "auth.forbidden", "not_found.resource", "request.payload_too_large", "request.unprocessable", "limit.rate_exceeded", "capability.unavailable", "internal.error"];
68
76
  export declare function isStatusDerivedCoarseCode(code: string | null | undefined): boolean;
69
77
  export declare const RESUME_AT_ERROR_CODE_PREFIX = "resume_at.";
70
78
  export declare const REWIND_ERROR_CODE_PREFIXES: readonly ["resume_at.", "rewind_snapshot."];
@@ -81,7 +89,7 @@ export declare const CHECKPOINT_REFUSED_PARK_CODES: readonly string[];
81
89
  export declare function isRefusedParkCode(code: string | null | undefined): code is typeof CHECKPOINT_UNSUPPORTED_VERSION | typeof CHECKPOINT_WALLTIME_AXIS_RETIRED | typeof CHECKPOINT_CONFIG_REFUSED;
82
90
  export declare function refusalSaysStillPending(err: object): boolean;
83
91
  export declare function refusalRetriableReading(err: object): boolean | undefined;
84
- export type StatusDerivedCoarseCode = (typeof STATUS_DERIVED_COARSE_CODES)[number];
92
+ export type StatusDerivedCoarseCode = (typeof SDK_STATUS_DERIVED_COARSE_CODES)[number];
85
93
  export declare const RESUME_PLACEMENT_MISMATCH = "resume.placement_mismatch";
86
94
  export declare const RESUME_CONTEXT_UNAVAILABLE = "conflict.resume_context_unavailable";
87
95
  export declare const RESUME_RETRY_LATER_CODES: readonly string[];
@@ -102,6 +110,8 @@ export declare const CONFLICT_NOT_RESUMABLE = "conflict.not_resumable";
102
110
  export declare const GATE_NOT_TOOL_APPROVAL = "gate_not_tool_approval";
103
111
  export declare const DECIDE_PARK_MOVED_CODES: readonly string[];
104
112
  export declare function isDecideParkMovedCode(code: string | null | undefined): boolean;
113
+ export declare const DECIDE_ROW_UNREVIVABLE = "decide.row_unrevivable";
114
+ export declare function isDecideRowUnrevivableCode(code: string | null | undefined): boolean;
105
115
  export declare const APPROVAL_STALE = "approval_stale";
106
116
  export declare const APPROVAL_BINDING_MISMATCH = "approval_binding_mismatch";
107
117
  export declare const CHECKPOINT_INVALID_OUTCOME = "checkpoint.invalid_outcome";
@@ -119,7 +129,6 @@ export declare const ASK_IDEMPOTENCY_CONFLICT = "conflict.ask_idempotency";
119
129
  export declare const ASK_PARKING_RETRY = "parking.ask_retry";
120
130
  export declare const ASK_DECISION_LANE_DISABLED = "feature.approval_ask_disabled";
121
131
  export declare const ASK_GONE_DENIED_WORD: "routing_failure_fail_closed";
122
- export declare const RUN_DEATH_VERDICT_CODES: readonly ["run.stalled", "run.orphaned", "approval.expired"];
123
132
  export type { RunDeathVerdictCode };
124
133
  export declare const RUN_STALLED: "run.stalled";
125
134
  export declare const RUN_ORPHANED: "run.orphaned";
@@ -1,6 +1,6 @@
1
1
  import { frozenSet } from './frozenSet.js';
2
2
  import { ownDataField } from './ownKey.js';
3
- import { SDK_DENY_REASON_ROUTING_FAILURE, SDK_RUN_DEATH_VERDICT_CODES, SDK_STATUS_DERIVED_COARSE_CODES } from './generated/sdkFactTables.js';
3
+ import { SDK_DENY_REASON_ROUTING_FAILURE, SDK_STATUS_DERIVED_COARSE_CODES } from './generated/sdkFactTables.js';
4
4
  export const LIMITS_MAX_TOKENS_EXCEEDED = 'limits.max_tokens_exceeded';
5
5
  export const LIMITS_MAX_COST_EXCEEDED = 'limits.max_cost_exceeded';
6
6
  export const LIMITS_MAX_TURNS_EXCEEDED = 'limits.max_turns_exceeded';
@@ -13,8 +13,6 @@ export const USAGE_WINDOW_EXHAUSTED = 'usage.window_exhausted';
13
13
  export const ENV_LIFETIME_EXPIRED = 'env.lifetime_expired';
14
14
  export const FLEET_LEASE_UNAVAILABLE = 'fleet.lease_unavailable';
15
15
  export const CONFIG_LIMIT_INVALID = 'config.limit_invalid';
16
- export const CONFIG_STRATEGY_FIND_LIMIT_INVALID = 'config.strategy_find_limit_invalid';
17
- export const CONFIG_STRATEGY_MAX_SIZE_INVALID = 'config.strategy_max_size_invalid';
18
16
  export const CONFIG_LIMIT_UNKNOWN_KEY = 'config.limit_unknown_key';
19
17
  export const CONFIG_DELEGATION_ENTRY_CAPS = 'config.delegation_entry_caps';
20
18
  export const CONFIG_MEMORY_PROJECT_KEY_SPELLING = 'config.memory_project_key_spelling';
@@ -23,6 +21,7 @@ export const CONFIG_LEGACY_TOOL_NAME = 'config.legacy_tool_name';
23
21
  export const CONFIG_IMAGE_INVALID = 'config.image_invalid';
24
22
  export const CONFIG_AGENT_UNKNOWN_TOOL = 'config.agent.unknown_tool';
25
23
  export const CONFIG_TOOL_FACE_CONTROL = 'config.tool_face_control';
24
+ export const CONFIG_MCP_SERVER_NAME_COLLISION = 'config.mcp_server_name_collision';
26
25
  export const PROMPT_ASSEMBLED_ROLE_REFUSED = 'prompt.assembled_role_refused';
27
26
  export const CONFIG_OUTPUT_STYLE_INVALID = 'config.output_style_invalid';
28
27
  export const RULES_INERT_ENTRY = 'rules.inert_entry';
@@ -48,6 +47,8 @@ export function delegationCapDispositionOf(code) {
48
47
  return undefined;
49
48
  }
50
49
  export const MCP_SERVER_REVOKED = 'mcp.server_revoked';
50
+ export const MCP_TOOL_DECLARATION_CHANGED = 'mcp.tool_declaration_changed';
51
+ export const MCP_TOOL_LISTING_UNREACHED = 'mcp.tool_listing_unreached';
51
52
  export function isConfigRefusalCode(code) {
52
53
  return typeof code === 'string' && code.startsWith('config.');
53
54
  }
@@ -112,10 +113,27 @@ export const STOP_NOT_LANDED = 'stop.not_landed';
112
113
  export const STOP_NOT_LOCAL = 'stop.not_local';
113
114
  export const STOP_PARKED = 'stop.parked';
114
115
  export const OUTPUT_INVALID = 'output.invalid';
116
+ const RESULT_LIMIT_TABLE = Object.freeze([
117
+ Object.freeze({ code: LIMITS_MAX_TURNS_EXCEEDED, word: 'turns', subtype: 'error_max_turns' }),
118
+ Object.freeze({ code: LIMITS_MAX_COST_EXCEEDED, word: 'budget_usd', subtype: 'error_max_budget_usd' }),
119
+ Object.freeze({ code: OUTPUT_INVALID, word: 'structured_output_retries', subtype: 'error_max_structured_output_retries' }),
120
+ Object.freeze({ code: LIMITS_MAX_WALLTIME_EXCEEDED, word: 'wall_clock', subtype: 'error_during_execution' }),
121
+ Object.freeze({ code: LIMITS_MAX_TOKENS_EXCEEDED, word: 'tokens', subtype: 'error_during_execution' }),
122
+ ]);
123
+ export const RESULT_LIMIT_WORDS = Object.freeze(RESULT_LIMIT_TABLE.map((r) => r.word));
124
+ const _limitWordPins = [true, true];
125
+ void _limitWordPins;
126
+ export function resultLimitRowOfCode(code) {
127
+ if (typeof code !== 'string' || code.length === 0)
128
+ return undefined;
129
+ for (const row of RESULT_LIMIT_TABLE)
130
+ if (row.code === code)
131
+ return row;
132
+ return undefined;
133
+ }
115
134
  export const RESUME_POLICY_FOLD_CODE = 'resume_blocked_by_policy';
116
- export const STATUS_DERIVED_COARSE_CODES = SDK_STATUS_DERIVED_COARSE_CODES;
117
135
  export function isStatusDerivedCoarseCode(code) {
118
- return typeof code === 'string' && STATUS_DERIVED_COARSE_CODES.includes(code);
136
+ return typeof code === 'string' && SDK_STATUS_DERIVED_COARSE_CODES.includes(code);
119
137
  }
120
138
  export const RESUME_AT_ERROR_CODE_PREFIX = 'resume_at.';
121
139
  export const REWIND_ERROR_CODE_PREFIXES = Object.freeze([RESUME_AT_ERROR_CODE_PREFIX, 'rewind_snapshot.']);
@@ -189,6 +207,10 @@ export const DECIDE_PARK_MOVED_CODES = Object.freeze([
189
207
  export function isDecideParkMovedCode(code) {
190
208
  return typeof code === 'string' && DECIDE_PARK_MOVED_CODES.includes(code);
191
209
  }
210
+ export const DECIDE_ROW_UNREVIVABLE = 'decide.row_unrevivable';
211
+ export function isDecideRowUnrevivableCode(code) {
212
+ return typeof code === 'string' && code === DECIDE_ROW_UNREVIVABLE;
213
+ }
192
214
  export const APPROVAL_STALE = 'approval_stale';
193
215
  export const APPROVAL_BINDING_MISMATCH = 'approval_binding_mismatch';
194
216
  export const CHECKPOINT_INVALID_OUTCOME = 'checkpoint.invalid_outcome';
@@ -213,7 +235,6 @@ export const ASK_IDEMPOTENCY_CONFLICT = 'conflict.ask_idempotency';
213
235
  export const ASK_PARKING_RETRY = 'parking.ask_retry';
214
236
  export const ASK_DECISION_LANE_DISABLED = 'feature.approval_ask_disabled';
215
237
  export const ASK_GONE_DENIED_WORD = SDK_DENY_REASON_ROUTING_FAILURE;
216
- export const RUN_DEATH_VERDICT_CODES = SDK_RUN_DEATH_VERDICT_CODES;
217
238
  const _runDeathVerdictCodePin = true;
218
239
  void _runDeathVerdictCodePin;
219
240
  export const RUN_STALLED = 'run.stalled';
@@ -0,0 +1,39 @@
1
+ export interface ApprovalWindowAnchor {
2
+ readonly receivedAtMs?: number;
3
+ readonly expiresInMs?: number;
4
+ }
5
+ export declare const ENGINE_GENERATION_WINDOW_MARGIN_MS = 5000;
6
+ export declare const ENGINE_STOPPED_CALL_PHASES: readonly ["engine-stopped-awaiting-approval", "engine-stopped-before-result"];
7
+ export type EngineStoppedCallPhase = (typeof ENGINE_STOPPED_CALL_PHASES)[number];
8
+ export interface EndedGenerationCard {
9
+ readonly callKey: string;
10
+ readonly toolCallId?: string;
11
+ readonly parkRow: boolean;
12
+ readonly windowLeftMs?: number;
13
+ readonly closedByEngine?: boolean;
14
+ }
15
+ export interface EndedGenerationOpenedCall {
16
+ readonly toolCallId: string;
17
+ readonly generation: number;
18
+ }
19
+ export interface EndedGenerationPhaseHold {
20
+ readonly toolCallId: string;
21
+ readonly generation: number;
22
+ }
23
+ export interface EndedGenerationFacts {
24
+ readonly cards: readonly EndedGenerationCard[];
25
+ readonly opened: readonly EndedGenerationOpenedCall[];
26
+ readonly phases?: readonly EndedGenerationPhaseHold[];
27
+ readonly endedGeneration: number;
28
+ }
29
+ export interface EndedGenerationPhaseChange {
30
+ readonly toolCallId: string;
31
+ readonly phase: EngineStoppedCallPhase;
32
+ readonly viaCallKey?: string;
33
+ }
34
+ export interface EngineGenerationConvergence {
35
+ readonly retract: readonly string[];
36
+ readonly phases: readonly EndedGenerationPhaseChange[];
37
+ }
38
+ export declare function approvalWindowLeftMs(keys: Readonly<ApprovalWindowAnchor> | null | undefined, nowMs: number): number | undefined;
39
+ export declare function convergeEndedEngineGeneration(facts: EndedGenerationFacts): EngineGenerationConvergence;
@@ -0,0 +1,95 @@
1
+ import { usableClockMs } from './clockReading.js';
2
+ export const ENGINE_GENERATION_WINDOW_MARGIN_MS = 5_000;
3
+ export const ENGINE_STOPPED_CALL_PHASES = Object.freeze(['engine-stopped-awaiting-approval', 'engine-stopped-before-result']);
4
+ const EMPTY = Object.freeze({ retract: Object.freeze([]), phases: Object.freeze([]) });
5
+ const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
6
+ export function approvalWindowLeftMs(keys, nowMs) {
7
+ try {
8
+ const now = usableClockMs(nowMs);
9
+ if (typeof keys !== 'object' || keys === null || now === null)
10
+ return undefined;
11
+ const { receivedAtMs, expiresInMs } = keys;
12
+ if (usableClockMs(receivedAtMs) === null || typeof expiresInMs !== 'number' || !Number.isFinite(expiresInMs))
13
+ return undefined;
14
+ if (now < receivedAtMs)
15
+ return undefined;
16
+ return receivedAtMs + expiresInMs - now;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ function forEachGuarded(items, visit) {
23
+ let skipped = 0;
24
+ for (const item of items) {
25
+ try {
26
+ visit(item);
27
+ }
28
+ catch {
29
+ skipped += 1;
30
+ }
31
+ }
32
+ return skipped;
33
+ }
34
+ function windowDefinitelyOpen(card) {
35
+ if (card.closedByEngine === true)
36
+ return false;
37
+ const left = card.windowLeftMs;
38
+ return typeof left === 'number' && Number.isFinite(left) && left > ENGINE_GENERATION_WINDOW_MARGIN_MS;
39
+ }
40
+ export function convergeEndedEngineGeneration(facts) {
41
+ try {
42
+ if (typeof facts !== 'object' || facts === null)
43
+ return EMPTY;
44
+ const ended = facts.endedGeneration;
45
+ if (typeof ended !== 'number' || !Number.isFinite(ended))
46
+ return EMPTY;
47
+ const retract = [];
48
+ const phases = [];
49
+ const held = new Map();
50
+ const holds = facts.phases;
51
+ if (Array.isArray(holds)) {
52
+ forEachGuarded(holds, (p) => {
53
+ if (typeof p === 'object' && p !== null && nonEmpty(p.toolCallId) && typeof p.generation === 'number')
54
+ held.set(p.toolCallId, p.generation);
55
+ });
56
+ }
57
+ const cards = facts.cards;
58
+ if (Array.isArray(cards)) {
59
+ forEachGuarded(cards, (card) => {
60
+ if (typeof card !== 'object' || card === null || !nonEmpty(card.callKey))
61
+ return;
62
+ if (card.parkRow !== false || !windowDefinitelyOpen(card))
63
+ return;
64
+ if (retract.includes(card.callKey))
65
+ return;
66
+ const id = card.toolCallId;
67
+ retract.push(card.callKey);
68
+ if (!nonEmpty(id))
69
+ return;
70
+ const heldGen = held.get(id);
71
+ if (heldGen !== undefined && heldGen !== ended)
72
+ return;
73
+ if (phases.some((p) => p.toolCallId === id))
74
+ return;
75
+ phases.push({ toolCallId: id, phase: 'engine-stopped-awaiting-approval', viaCallKey: card.callKey });
76
+ held.set(id, ended);
77
+ });
78
+ }
79
+ const opened = facts.opened;
80
+ if (Array.isArray(opened)) {
81
+ forEachGuarded(opened, (call) => {
82
+ if (typeof call !== 'object' || call === null || !nonEmpty(call.toolCallId) || call.generation !== ended)
83
+ return;
84
+ if (held.has(call.toolCallId))
85
+ return;
86
+ phases.push({ toolCallId: call.toolCallId, phase: 'engine-stopped-before-result' });
87
+ held.set(call.toolCallId, ended);
88
+ });
89
+ }
90
+ return Object.freeze({ retract: Object.freeze(retract), phases: Object.freeze(phases.map((p) => Object.freeze(p))) });
91
+ }
92
+ catch {
93
+ return EMPTY;
94
+ }
95
+ }
@@ -0,0 +1,61 @@
1
+ export declare const REATTACH_RUN_STATES: readonly ["done", "died", "parked", "running", "unreachable", "unauthorized", "engine-known-dead"];
2
+ export type ReattachRunState = (typeof REATTACH_RUN_STATES)[number];
3
+ export interface ReattachLivenessReading {
4
+ readonly state: ReattachRunState;
5
+ readonly notFound?: boolean;
6
+ }
7
+ export interface ReattachOutageStopLineParts {
8
+ readonly taskId: string;
9
+ readonly action: string;
10
+ readonly nextMessage: string;
11
+ }
12
+ export type ReattachOutageStopLine = (parts: ReattachOutageStopLineParts) => string;
13
+ export interface EndedGenerationMaterials {
14
+ readonly restartPending: boolean;
15
+ readonly outageStopLine?: ReattachOutageStopLine;
16
+ }
17
+ export interface EngineGenerationPort {
18
+ current: () => number;
19
+ endedMaterials: () => Promise<EndedGenerationMaterials>;
20
+ replacementInFlight?: () => boolean;
21
+ awaitEngineInstalled?: (signal: AbortSignal, maxMs: number) => Promise<boolean>;
22
+ }
23
+ export type EngineGenerationReading = {
24
+ readonly known: true;
25
+ readonly generation: number;
26
+ } | {
27
+ readonly known: false;
28
+ };
29
+ export declare function engineGenerationReadingOf(read: (() => number | undefined) | undefined): EngineGenerationReading;
30
+ export declare function engineGenerationOfPort(port: EngineGenerationPort | undefined): EngineGenerationReading;
31
+ export interface EngineGenerationEndedFacts {
32
+ readonly run: EngineGenerationReading;
33
+ readonly current: EngineGenerationReading;
34
+ readonly freshCredentialAdopted?: boolean;
35
+ }
36
+ export declare function engineGenerationEnded(facts: EngineGenerationEndedFacts): boolean;
37
+ export interface ApprovalFrameGenerationFacts {
38
+ readonly streamOpenedIn: EngineGenerationReading;
39
+ readonly current: EngineGenerationReading;
40
+ readonly freshCredentialAdopted?: boolean;
41
+ }
42
+ export declare function approvalFrameGenerationVerdict(facts: ApprovalFrameGenerationFacts): 'admit' | 'drop';
43
+ export declare const REATTACH_AWAIT_NEXT_ENGINE_MS = 245000;
44
+ export declare function unreachableForSettle(liveness: ReattachLivenessReading): boolean;
45
+ export type EndedGenerationSettleStep = 'await-next-engine' | 'refresh-credentials' | 'credentials-rejected' | 'hand-over-terminal' | 'parked' | 'engine-stopped';
46
+ export interface EndedGenerationSettleFacts {
47
+ readonly liveness: ReattachLivenessReading;
48
+ readonly canAwaitNextEngine: boolean;
49
+ readonly awaitedNextEngine: boolean;
50
+ readonly refreshedCredentials: boolean | null;
51
+ readonly terminalReadable?: boolean;
52
+ }
53
+ export declare function endedGenerationSettleStep(facts: EndedGenerationSettleFacts): EndedGenerationSettleStep;
54
+ export declare const AWAIT_ENGINE_INSTALL_POLL_MS = 200;
55
+ export interface AwaitNextEngineDeps {
56
+ readonly installed: () => boolean;
57
+ readonly replacing: () => boolean;
58
+ readonly now?: () => number;
59
+ readonly pollMs?: number;
60
+ }
61
+ export declare function awaitNextEngineInstalled(signal: AbortSignal, maxMs: number, deps: AwaitNextEngineDeps): Promise<boolean>;
@@ -0,0 +1,144 @@
1
+ import { usableClockMs } from './clockReading.js';
2
+ import { readSignalAborted, tryListenAbortOnce, tryUnlistenAbort } from './engineWireFor.js';
3
+ export const REATTACH_RUN_STATES = Object.freeze(['done', 'died', 'parked', 'running', 'unreachable', 'unauthorized', 'engine-known-dead']);
4
+ const UNKNOWN = Object.freeze({ known: false });
5
+ export function engineGenerationReadingOf(read) {
6
+ if (typeof read !== 'function')
7
+ return UNKNOWN;
8
+ try {
9
+ const g = read();
10
+ return typeof g === 'number' && Number.isFinite(g) ? Object.freeze({ known: true, generation: g }) : UNKNOWN;
11
+ }
12
+ catch {
13
+ return UNKNOWN;
14
+ }
15
+ }
16
+ export function engineGenerationOfPort(port) {
17
+ if (typeof port !== 'object' || port === null)
18
+ return UNKNOWN;
19
+ return engineGenerationReadingOf(() => port.current());
20
+ }
21
+ export function engineGenerationEnded(facts) {
22
+ try {
23
+ const { run, current, freshCredentialAdopted } = facts;
24
+ const runGeneration = knownGenerationOf(run);
25
+ if (runGeneration === null)
26
+ return false;
27
+ if (freshCredentialAdopted === true)
28
+ return true;
29
+ const currentGeneration = knownGenerationOf(current);
30
+ if (currentGeneration === null)
31
+ return false;
32
+ return currentGeneration !== runGeneration;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ function knownGenerationOf(reading) {
39
+ if (typeof reading !== 'object' || reading === null)
40
+ return null;
41
+ const raw = reading;
42
+ const known = raw.known;
43
+ const generation = raw.generation;
44
+ return known === true && typeof generation === 'number' && Number.isFinite(generation) ? generation : null;
45
+ }
46
+ export function approvalFrameGenerationVerdict(facts) {
47
+ try {
48
+ return engineGenerationEnded({ run: facts.streamOpenedIn, current: facts.current, ...(facts.freshCredentialAdopted === true ? { freshCredentialAdopted: true } : {}) }) ? 'drop' : 'admit';
49
+ }
50
+ catch {
51
+ return 'admit';
52
+ }
53
+ }
54
+ export const REATTACH_AWAIT_NEXT_ENGINE_MS = 245_000;
55
+ export function unreachableForSettle(liveness) {
56
+ try {
57
+ return liveness.state === 'engine-known-dead' || (liveness.state === 'unreachable' && liveness.notFound !== true);
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ export function endedGenerationSettleStep(facts) {
64
+ try {
65
+ const liveness = facts.liveness;
66
+ if (typeof liveness !== 'object' || liveness === null || !REATTACH_RUN_STATES.includes(liveness.state))
67
+ return 'engine-stopped';
68
+ if (facts.canAwaitNextEngine === true && facts.awaitedNextEngine !== true && unreachableForSettle(liveness))
69
+ return 'await-next-engine';
70
+ if (liveness.state === 'unauthorized')
71
+ return facts.refreshedCredentials === null ? 'refresh-credentials' : 'credentials-rejected';
72
+ if (liveness.state === 'done')
73
+ return facts.terminalReadable === false ? 'engine-stopped' : 'hand-over-terminal';
74
+ if (liveness.state === 'parked')
75
+ return 'parked';
76
+ return 'engine-stopped';
77
+ }
78
+ catch {
79
+ return 'engine-stopped';
80
+ }
81
+ }
82
+ export const AWAIT_ENGINE_INSTALL_POLL_MS = 200;
83
+ export function awaitNextEngineInstalled(signal, maxMs, deps) {
84
+ const clock = typeof deps.now === 'function' ? deps.now : () => performance.now();
85
+ const pollMs = typeof deps.pollMs === 'number' && Number.isFinite(deps.pollMs) && deps.pollMs > 0 ? deps.pollMs : AWAIT_ENGINE_INSTALL_POLL_MS;
86
+ const budgetMs = typeof maxMs === 'number' && Number.isFinite(maxMs) ? Math.max(0, maxMs) : 0;
87
+ const maxTicks = Math.ceil(budgetMs / pollMs) + 1;
88
+ const read = (f) => {
89
+ try {
90
+ return f() === true;
91
+ }
92
+ catch {
93
+ return false;
94
+ }
95
+ };
96
+ const now = () => {
97
+ try {
98
+ return usableClockMs(clock());
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ };
104
+ return new Promise((resolve) => {
105
+ if (readSignalAborted(signal) === true) {
106
+ resolve(false);
107
+ return;
108
+ }
109
+ const start = now();
110
+ const deadline = start === null ? null : start + budgetMs;
111
+ let timer;
112
+ let done = false;
113
+ let ticks = 0;
114
+ const finish = (v) => {
115
+ if (done)
116
+ return;
117
+ done = true;
118
+ if (timer !== undefined)
119
+ clearTimeout(timer);
120
+ tryUnlistenAbort(signal, onAbort);
121
+ resolve(v);
122
+ };
123
+ const onAbort = () => finish(false);
124
+ tryListenAbortOnce(signal, onAbort);
125
+ const tick = () => {
126
+ if (done)
127
+ return;
128
+ ticks += 1;
129
+ if (read(deps.installed))
130
+ return finish(true);
131
+ if (done)
132
+ return;
133
+ if (!read(deps.replacing))
134
+ return finish(read(deps.installed));
135
+ if (done)
136
+ return;
137
+ const t = now();
138
+ if (deadline === null || t === null || t >= deadline || ticks >= maxTicks)
139
+ return finish(false);
140
+ timer = setTimeout(tick, pollMs);
141
+ };
142
+ tick();
143
+ });
144
+ }
@@ -0,0 +1,23 @@
1
+ import type { HealthAuthKind } from '@sema-agent/sdk';
2
+ export interface EngineHealthCenterFacts {
3
+ readonly issuer?: string;
4
+ readonly webBaseUrl?: string;
5
+ readonly sessionsVisible: boolean | 'unknown';
6
+ }
7
+ export interface EngineHealthAuthFacts {
8
+ readonly required: boolean;
9
+ readonly kinds: readonly (HealthAuthKind | (string & {}))[];
10
+ readonly identityAttach: 'available' | 'unavailable';
11
+ }
12
+ export interface EngineHealthDrainingFacts {
13
+ readonly actionId: string;
14
+ readonly since: number;
15
+ readonly deadlineAt: number;
16
+ }
17
+ export interface EngineHealthFacts {
18
+ readonly center?: EngineHealthCenterFacts;
19
+ readonly auth?: EngineHealthAuthFacts;
20
+ readonly operator?: 'present' | 'absent';
21
+ readonly draining?: EngineHealthDrainingFacts;
22
+ }
23
+ export declare function readEngineHealthFacts(health: object | null | undefined): EngineHealthFacts;