@sema-agent/client-core 0.97.1 → 0.98.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 (281) hide show
  1. package/CHANGELOG.md +408 -0
  2. package/README.md +74 -37
  3. package/dist/adapt/arms.d.ts +1 -0
  4. package/dist/adapt/arms.js +128 -34
  5. package/dist/adapt/ids.d.ts +12 -1
  6. package/dist/adapt/ids.js +59 -8
  7. package/dist/adapt/instanceLedger.d.ts +50 -0
  8. package/dist/adapt/instanceLedger.js +147 -0
  9. package/dist/adapt/textStream.d.ts +1 -0
  10. package/dist/adapt/textStream.js +24 -7
  11. package/dist/adapt/toolCards.d.ts +27 -5
  12. package/dist/adapt/toolCards.js +39 -6
  13. package/dist/adapt/wireShapes.js +6 -2
  14. package/dist/adapt.d.ts +2 -0
  15. package/dist/adapt.js +8 -3
  16. package/dist/adapter/activeRunSelfHeal.d.ts +5 -0
  17. package/dist/adapter/activeRunSelfHeal.js +51 -28
  18. package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
  19. package/dist/adapter/downstream/eventToSdkMessage.js +27 -34
  20. package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
  21. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
  22. package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
  23. package/dist/adapter/runStream.js +29 -13
  24. package/dist/adapter/types.d.ts +4 -4
  25. package/dist/agentSession/backgroundView.js +2 -1
  26. package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
  27. package/dist/agentSession/engineAgentRegistryRead.js +12 -13
  28. package/dist/agentsWireCaps.d.ts +8 -8
  29. package/dist/agentsWireCaps.js +168 -175
  30. package/dist/approvalDecidedByCapability.d.ts +0 -4
  31. package/dist/approvalDecidedByCapability.js +0 -6
  32. package/dist/approvalsStreamLiveCapability.d.ts +0 -4
  33. package/dist/approvalsStreamLiveCapability.js +0 -6
  34. package/dist/assistantInbox.d.ts +34 -0
  35. package/dist/assistantInbox.js +118 -0
  36. package/dist/centerWiringCapability.js +9 -1
  37. package/dist/clientSlice.d.ts +0 -9
  38. package/dist/clientSlice.js +0 -3
  39. package/dist/cloudConfigWireCaps.d.ts +4 -2
  40. package/dist/cloudConfigWireCaps.js +81 -61
  41. package/dist/compensations.js +1 -1
  42. package/dist/connectorStatus.d.ts +21 -0
  43. package/dist/connectorStatus.js +112 -0
  44. package/dist/controlRouter.d.ts +14 -1
  45. package/dist/controlRouter.js +68 -17
  46. package/dist/coreValuePorts.d.ts +3 -3
  47. package/dist/decideReceipt.d.ts +2 -2
  48. package/dist/decideReceipt.js +5 -2
  49. package/dist/declared/supportFloorDeclared.js +3 -3
  50. package/dist/deviceExecutorManagementCapability.d.ts +0 -4
  51. package/dist/deviceExecutorManagementCapability.js +0 -6
  52. package/dist/deviceRebind.d.ts +49 -1
  53. package/dist/deviceRebind.js +221 -3
  54. package/dist/displayUntrusted.d.ts +1 -0
  55. package/dist/displayUntrusted.js +250 -76
  56. package/dist/engineAgentAbsence.d.ts +1 -1
  57. package/dist/engineAgentPanelStore.d.ts +5 -4
  58. package/dist/engineAgentPanelStore.js +3 -12
  59. package/dist/engineCapReader.d.ts +0 -4
  60. package/dist/engineCapReader.js +1 -5
  61. package/dist/engineCapsCache.d.ts +4 -0
  62. package/dist/engineCapsCache.js +17 -12
  63. package/dist/engineClosedSets.d.ts +1 -0
  64. package/dist/engineClosedSets.js +4 -1
  65. package/dist/engineErrorCodes.d.ts +9 -2
  66. package/dist/engineErrorCodes.js +9 -1
  67. package/dist/engineIdentity.d.ts +1 -0
  68. package/dist/engineIdentity.js +8 -0
  69. package/dist/engineRowRef.d.ts +28 -0
  70. package/dist/engineRowRef.js +111 -0
  71. package/dist/engineSessionMessages.d.ts +67 -0
  72. package/dist/engineSessionMessages.js +364 -0
  73. package/dist/engineToolDirectory.d.ts +0 -9
  74. package/dist/engineToolDirectory.js +1 -94
  75. package/dist/engineUrl.d.ts +18 -0
  76. package/dist/engineUrl.js +52 -0
  77. package/dist/env/uiLanguage.d.ts +9 -0
  78. package/dist/env/uiLanguage.js +35 -0
  79. package/dist/eventLeg.d.ts +92 -0
  80. package/dist/eventLeg.js +285 -0
  81. package/dist/executionLaneCapability.d.ts +0 -4
  82. package/dist/executionLaneCapability.js +3 -16
  83. package/dist/fileHistoryCaptureCapability.d.ts +0 -4
  84. package/dist/fileHistoryCaptureCapability.js +5 -7
  85. package/dist/fleet/fleetLedger.d.ts +0 -3
  86. package/dist/fleet/fleetLedger.js +21 -36
  87. package/dist/fleet/fleetProjection.d.ts +2 -2
  88. package/dist/fleet/fleetProjection.js +10 -8
  89. package/dist/frameBinding.d.ts +5 -0
  90. package/dist/frameBinding.js +23 -0
  91. package/dist/gateFailureCodes.d.ts +2 -0
  92. package/dist/gateFailureCodes.js +15 -0
  93. package/dist/gateOutcome.d.ts +3 -1
  94. package/dist/gateOutcome.js +25 -6
  95. package/dist/gateVocabulary.d.ts +5 -0
  96. package/dist/gateVocabulary.js +64 -2
  97. package/dist/generated/engineAskFaceTables.js +2 -2
  98. package/dist/generated/engineFactTables.d.ts +6 -3
  99. package/dist/generated/engineFactTables.js +22 -4
  100. package/dist/generated/engineNoticeTables.js +9 -0
  101. package/dist/generated/toolNameTables.d.ts +1 -0
  102. package/dist/generated/toolNameTables.js +1 -0
  103. package/dist/hitl/allowRuleShadow.d.ts +6 -1
  104. package/dist/hitl/allowRuleShadow.js +21 -17
  105. package/dist/hitl/approvalCardReading.d.ts +15 -0
  106. package/dist/hitl/approvalCardReading.js +154 -0
  107. package/dist/hitl/approvalCardReasons.d.ts +13 -0
  108. package/dist/hitl/approvalCardReasons.js +120 -0
  109. package/dist/hitl/approvalHolds.d.ts +47 -15
  110. package/dist/hitl/approvalHolds.js +134 -28
  111. package/dist/hitl/approvalResolution.d.ts +51 -26
  112. package/dist/hitl/approvalResolution.js +86 -122
  113. package/dist/hitl/approvalsFeed.js +6 -18
  114. package/dist/hitl/askClassPair.d.ts +2 -0
  115. package/dist/hitl/askClassPair.js +1 -0
  116. package/dist/hitl/askGateWire.d.ts +20 -2
  117. package/dist/hitl/askGateWire.js +49 -1
  118. package/dist/hitl/askParkRowRouting.d.ts +5 -0
  119. package/dist/hitl/askParkRowRouting.js +32 -1
  120. package/dist/hitl/askSettlementLine.d.ts +18 -0
  121. package/dist/hitl/askSettlementLine.js +79 -0
  122. package/dist/hitl/automaticAnswerVerdict.d.ts +1 -1
  123. package/dist/hitl/automaticAnswerVerdict.js +21 -5
  124. package/dist/hitl/crashConverged.d.ts +11 -20
  125. package/dist/hitl/crashConverged.js +56 -0
  126. package/dist/hitl/crashConvergedNotice.d.ts +3 -1
  127. package/dist/hitl/crashConvergedNotice.js +48 -11
  128. package/dist/hitl/decisionConflict.js +3 -10
  129. package/dist/hitl/decisionRefusal.d.ts +40 -1
  130. package/dist/hitl/decisionRefusal.js +199 -42
  131. package/dist/hitl/frameRouter.d.ts +5 -2
  132. package/dist/hitl/frameRouter.js +20 -16
  133. package/dist/hitl/gateLedger.d.ts +2 -0
  134. package/dist/hitl/gateLedger.js +50 -13
  135. package/dist/hitl/hitlBridge.d.ts +1 -2
  136. package/dist/hitl/hitlBridge.js +10 -7
  137. package/dist/hitl/livePendingAsk.d.ts +3 -3
  138. package/dist/hitl/livePendingAsk.js +7 -18
  139. package/dist/hitl/parkResolver.d.ts +2 -24
  140. package/dist/hitl/parkResolver.js +61 -97
  141. package/dist/hitl/persistedRulesWire.d.ts +24 -0
  142. package/dist/hitl/persistedRulesWire.js +122 -2
  143. package/dist/hitl/planReviewWire.d.ts +26 -13
  144. package/dist/hitl/planReviewWire.js +112 -78
  145. package/dist/hitl/refusedToolNameProse.d.ts +0 -1
  146. package/dist/hitl/refusedToolNameProse.js +0 -3
  147. package/dist/hitl/replayedApproval.d.ts +4 -3
  148. package/dist/hitl/replayedApproval.js +7 -4
  149. package/dist/hitl/sessionPolicyDeliverable.js +2 -4
  150. package/dist/hitl/sessionPolicyWire.d.ts +32 -20
  151. package/dist/hitl/sessionPolicyWire.js +162 -52
  152. package/dist/hitl/standingRows.d.ts +20 -2
  153. package/dist/hitl/standingRows.js +69 -8
  154. package/dist/hitl/toolApprovalWire.d.ts +87 -152
  155. package/dist/hitl/toolApprovalWire.js +591 -380
  156. package/dist/hookMatcherVerdict.d.ts +6 -1
  157. package/dist/hookMatcherVerdict.js +14 -7
  158. package/dist/hooksWireCaps.d.ts +2 -2
  159. package/dist/hooksWireCaps.js +59 -55
  160. package/dist/i18n/messages.en.d.ts +121 -0
  161. package/dist/i18n/messages.en.js +119 -0
  162. package/dist/i18n/messages.zh.d.ts +3 -0
  163. package/dist/i18n/messages.zh.js +120 -0
  164. package/dist/i18n/translate.d.ts +25 -0
  165. package/dist/i18n/translate.js +127 -0
  166. package/dist/index.d.ts +53 -20
  167. package/dist/index.js +38 -11
  168. package/dist/inheritEnvCapability.d.ts +31 -0
  169. package/dist/inheritEnvCapability.js +104 -0
  170. package/dist/liveModelCatalog.d.ts +1 -2
  171. package/dist/liveModelCatalog.js +2 -6
  172. package/dist/liveQuestionStore.d.ts +2 -21
  173. package/dist/mcpLiveness.d.ts +2 -1
  174. package/dist/mcpProbeWire.d.ts +6 -1
  175. package/dist/mcpProbeWire.js +1 -1
  176. package/dist/mcpWireCaps.d.ts +13 -2
  177. package/dist/mcpWireCaps.js +48 -0
  178. package/dist/memoryEntriesWire.d.ts +4 -9
  179. package/dist/model/modelSupplyRules.d.ts +0 -2
  180. package/dist/model/modelSupplyRules.js +3 -12
  181. package/dist/model/modelsPolicy.d.ts +0 -5
  182. package/dist/model/modelsPolicy.js +6 -36
  183. package/dist/model/subagentModelWord.d.ts +31 -0
  184. package/dist/model/subagentModelWord.js +261 -0
  185. package/dist/notifications.d.ts +6 -0
  186. package/dist/notifications.js +71 -23
  187. package/dist/outputStyleSeatCapability.d.ts +0 -3
  188. package/dist/outputStyleSeatCapability.js +0 -3
  189. package/dist/ownKey.d.ts +15 -0
  190. package/dist/ownKey.js +60 -3
  191. package/dist/panelReduce.d.ts +15 -9
  192. package/dist/panelReduce.js +680 -549
  193. package/dist/panelStateHolder.d.ts +3 -7
  194. package/dist/panelStateHolder.js +14 -130
  195. package/dist/peerLaneCapability.d.ts +0 -4
  196. package/dist/peerLaneCapability.js +0 -6
  197. package/dist/permissionRulesWriteCapability.d.ts +0 -4
  198. package/dist/permissionRulesWriteCapability.js +0 -6
  199. package/dist/permissionWireCaps.d.ts +2 -2
  200. package/dist/permissionWireCaps.js +2 -0
  201. package/dist/permissionsAllowGrantCapability.d.ts +0 -4
  202. package/dist/permissionsAllowGrantCapability.js +0 -6
  203. package/dist/permissionsDeclaration.d.ts +0 -11
  204. package/dist/permissionsDeclaration.js +60 -53
  205. package/dist/pluginHooksWire.d.ts +1 -1
  206. package/dist/pluginHooksWire.js +3 -6
  207. package/dist/preemptWire.d.ts +44 -0
  208. package/dist/preemptWire.js +83 -0
  209. package/dist/printToolResultFrame.js +15 -4
  210. package/dist/replayBody.d.ts +3 -0
  211. package/dist/replayBody.js +14 -0
  212. package/dist/request/taskRequest.d.ts +0 -1
  213. package/dist/request/taskRequest.js +0 -3
  214. package/dist/resumeRefusalCopy.d.ts +2 -1
  215. package/dist/resumeRefusalCopy.js +38 -2
  216. package/dist/retryStatus.d.ts +8 -0
  217. package/dist/retryStatus.js +106 -1
  218. package/dist/rewindArchiveCapability.d.ts +0 -4
  219. package/dist/rewindArchiveCapability.js +2 -10
  220. package/dist/rewindArchiveReading.d.ts +0 -1
  221. package/dist/rewindArchiveReading.js +0 -3
  222. package/dist/runCancelContext.d.ts +2 -1
  223. package/dist/runCancelContext.js +4 -2
  224. package/dist/runReattachPolicy.d.ts +31 -0
  225. package/dist/runReattachPolicy.js +46 -0
  226. package/dist/runTerminal.d.ts +3 -6
  227. package/dist/runTerminal.js +8 -9
  228. package/dist/sandboxWire.d.ts +3 -1
  229. package/dist/sandboxWire.js +76 -27
  230. package/dist/scenarioWire.js +1 -1
  231. package/dist/seam.d.ts +24 -2
  232. package/dist/seam.js +15 -3
  233. package/dist/seatContract.d.ts +53 -10
  234. package/dist/seatContract.js +132 -81
  235. package/dist/sessionPolicyCapability.d.ts +0 -4
  236. package/dist/sessionPolicyCapability.js +0 -6
  237. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
  238. package/dist/sessionSyncFileHistoryCapability.js +0 -3
  239. package/dist/skillToolListsCapability.d.ts +0 -3
  240. package/dist/skillToolListsCapability.js +0 -3
  241. package/dist/sqlEngineCapability.d.ts +0 -4
  242. package/dist/sqlEngineCapability.js +0 -6
  243. package/dist/steerPriorityCapability.d.ts +0 -3
  244. package/dist/steerPriorityCapability.js +0 -3
  245. package/dist/streamDrainingLegs.d.ts +4 -0
  246. package/dist/streamDrainingLegs.js +6 -1
  247. package/dist/subagent/engineCompactWire.d.ts +0 -1
  248. package/dist/subagent/engineCompactWire.js +7 -5
  249. package/dist/subagent/engineTaskHandleWire.js +4 -7
  250. package/dist/subagentContentStore.js +1 -11
  251. package/dist/submitReopen.d.ts +24 -0
  252. package/dist/submitReopen.js +75 -0
  253. package/dist/terminalStatuses.d.ts +3 -0
  254. package/dist/terminalStatuses.js +10 -2
  255. package/dist/toolResult.d.ts +10 -1
  256. package/dist/toolResult.js +34 -6
  257. package/dist/toolRoster.d.ts +0 -2
  258. package/dist/toolRoster.js +0 -2
  259. package/dist/turnFailurePresentation.d.ts +28 -0
  260. package/dist/turnFailurePresentation.js +205 -0
  261. package/dist/userInvokedSkillsCapability.d.ts +0 -3
  262. package/dist/userInvokedSkillsCapability.js +0 -3
  263. package/dist/webSearchBackendCapability.d.ts +0 -4
  264. package/dist/webSearchBackendCapability.js +0 -6
  265. package/dist/wireErrorTriage.js +5 -24
  266. package/dist/wireFailureShape.d.ts +62 -5
  267. package/dist/wireFailureShape.js +105 -5
  268. package/dist/wireRefusalCopy.d.ts +12 -2
  269. package/dist/wireRefusalCopy.js +50 -52
  270. package/dist/workflowsJournalCapability.d.ts +0 -4
  271. package/dist/workflowsJournalCapability.js +0 -6
  272. package/dist/writeProtectionCapability.d.ts +0 -4
  273. package/dist/writeProtectionCapability.js +0 -6
  274. package/docs/INTEGRATION-CLIENTS.md +1253 -46
  275. package/package.json +5 -4
  276. package/dist/attachmentSeatCapability.d.ts +0 -12
  277. package/dist/attachmentSeatCapability.js +0 -23
  278. package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
  279. package/dist/hitl/approvalOutcomeNote.js +0 -29
  280. package/dist/sessionReadRedactionCapability.d.ts +0 -13
  281. package/dist/sessionReadRedactionCapability.js +0 -35
@@ -1,21 +1,18 @@
1
1
  import { hostEnv } from './hostEnv.js';
2
- import { ownDataField } from './ownKey.js';
3
2
  import { makeEngineWireClient } from './engineWireSdk.js';
4
3
  import { frozenSet } from './frozenSet.js';
5
4
  import { settleWithinDeadline } from './abortableSleep.js';
5
+ import { engineCapValue, engineCapValueVia, engineCapsGeneration, engineCapsLandingOf, engineCapsSettled, kickEngineCapsProbe } from './engineCapsCache.js';
6
6
  import { ruleToolNameVerdictOf } from './protocolSegment.js';
7
7
  import { CORE_PROTOCOL_PREFIXES } from './generated/toolNameTables.js';
8
8
  import { rosterMountedNames } from './rosterMountedNames.js';
9
9
  import { capForDisplay } from './fleetTaskDesc.js';
10
- import { deniedEntryToolName, mcpEntryReadingOf } from './engineToolDirectory.js';
10
+ import { deniedEntryToolName } from './engineToolDirectory.js';
11
+ import { assemblyRefusal } from './wireFailureShape.js';
11
12
  export const MAX_TASK_AGENTS = 32;
12
- export const MAX_AGENT_NAME_CHARS = 64;
13
13
  export const MAX_AGENT_TEXT_CHARS = 4_096;
14
14
  export const MAX_AGENT_SYSTEM_PROMPT_CHARS = 65_536;
15
- export const MAX_AGENT_TOOLS = 64;
16
- export const MAX_AGENT_TOOL_NAME_CHARS = 128;
17
15
  export const MAX_AGENT_SKILL_CONTENT_CHARS = 1_048_576;
18
- export const MAX_AGENT_MAX_TURNS = 1_000;
19
16
  export const TASK_AGENT_WIRE_FIELDS = [
20
17
  'name',
21
18
  'whenToUse',
@@ -120,10 +117,6 @@ export function projectAgentsForWire(defs, deps) {
120
117
  const name = def.agentType;
121
118
  if (typeof name !== 'string' || name.length === 0)
122
119
  continue;
123
- if (name.length > MAX_AGENT_NAME_CHARS) {
124
- warnings.push(`agents wire: agent name "${name.slice(0, 40)}…" exceeds ${MAX_AGENT_NAME_CHARS} chars — definition skipped`);
125
- continue;
126
- }
127
120
  if (seen.has(name))
128
121
  continue;
129
122
  seen.add(name);
@@ -137,27 +130,19 @@ export function projectAgentsForWire(defs, deps) {
137
130
  warnings.push(`agents wire: agent "${name}" description truncated to ${MAX_AGENT_TEXT_CHARS} chars`);
138
131
  }
139
132
  }
140
- const projectTools = (list, label) => {
141
- if (!Array.isArray(list) || list.length === 0)
142
- return undefined;
143
- const kept = list.filter(t => typeof t === 'string' && t.length > 0 && t.length <= MAX_AGENT_TOOL_NAME_CHARS);
144
- if (kept.length !== list.length) {
133
+ const toolEntries = (list, label) => {
134
+ const entries = list.filter((t) => typeof t === 'string' && t.length > 0);
135
+ if (entries.length !== list.length)
145
136
  warnings.push(`agents wire: agent "${name}" ${label} had invalid entries — dropped`);
146
- }
147
- if (kept.length === 0)
148
- return undefined;
149
- if (kept.length > MAX_AGENT_TOOLS) {
150
- warnings.push(`agents wire: agent "${name}" ${label} truncated to ${MAX_AGENT_TOOLS} entries`);
151
- return kept.slice(0, MAX_AGENT_TOOLS);
152
- }
153
- return kept;
137
+ return entries;
154
138
  };
155
- const allowTools = projectTools(def.tools, 'tools');
156
- if (allowTools)
157
- item.allowTools = allowTools;
158
- const denyTools = projectTools(def.disallowedTools, 'disallowedTools');
159
- if (denyTools)
160
- item.denyTools = denyTools;
139
+ if (Array.isArray(def.tools))
140
+ item.allowTools = toolEntries(def.tools, 'tools');
141
+ if (Array.isArray(def.disallowedTools)) {
142
+ const denyTools = toolEntries(def.disallowedTools, 'disallowedTools');
143
+ if (denyTools.length > 0)
144
+ item.denyTools = denyTools;
145
+ }
161
146
  let whoMemo;
162
147
  const whoOf = () => {
163
148
  if (whoMemo !== undefined)
@@ -172,67 +157,29 @@ export function projectAgentsForWire(defs, deps) {
172
157
  whoMemo = `agent "${name}"${typeof source === 'string' && source.length > 0 ? ` (${capForDisplay(source, 120)})` : ''}`;
173
158
  return whoMemo;
174
159
  };
175
- const flaws = agentToolListFlaws([item], deps.toolRoster);
176
- const flawedEntries = new Set(flaws.map((f) => `${f.list}\u0000${f.entry}`));
177
- const omittedAllowFlaws = new Set(flaws.filter((f) => f.list === 'tools' && f.kind !== 'unjudged').map((f) => f.entry));
160
+ const rosterInHand = typeof rosterMountedNames(deps.toolRoster) === 'object';
161
+ const flaws = agentToolListFlaws([item], deps.toolRoster).map((f) => {
162
+ if (!rosterInHand || f.list !== 'disallowedTools' || f.kind !== 'retired' || f.currentName === undefined || f.toolName !== undefined)
163
+ return f;
164
+ const to = f.currentName;
165
+ if (item.denyTools !== undefined)
166
+ item.denyTools = item.denyTools.map((e) => (e === f.entry ? to : e));
167
+ return { ...f, rewritten: true };
168
+ });
178
169
  if (flaws.length > 0) {
179
170
  const who = whoOf();
180
171
  toolListFlaws.push(...flaws);
181
- const denyFlaws = flaws.filter(f => f.list === 'disallowedTools');
182
- const withhold = denyFlaws.length > 0 && deps.withholdRefusedDenyLists === true;
183
- if (denyFlaws.length > 0) {
184
- const what = `its disallowedTools ${denyFlaws.length === 1 ? 'entry' : 'entries'} ${denyFlaws.map(toolListFlawPhrase).join('; ')}`;
185
- warnings.push(withhold
186
- ? `agents wire: ${who} is not sent to the engine — ${what}, and this engine refuses to start a run whose agent definitions name a tool that way. Fix the entry in the agent definition; until then this agent is not available.`
187
- : `agents wire: ${who}: ${what} — tool names are matched exactly, so ${denyFlaws.length === 1 ? 'this entry hides' : 'these entries hide'} nothing from the agent, and newer engines refuse to start a run with it. Fix the entry in the agent definition.`);
188
- }
189
- if (!withhold) {
190
- for (const f of flaws) {
191
- if (f.list !== 'tools')
192
- continue;
193
- warnings.push(f.kind === 'unjudged'
194
- ? `agents wire: ${who}: its tools entry ${toolListFlawPhrase(f)} — tool names are matched exactly, so this entry does not give the agent that tool. Fix the entry in the agent definition.`
195
- : `agents wire: ${who}: its tools entry ${toolListFlawPhrase(f)} — tool names are matched exactly, so no tool answers to this entry; it is omitted (newer engines refuse a request whose agent definitions name it). Fix the entry in the agent definition.`);
196
- }
197
- }
198
- if (withhold)
199
- continue;
200
- }
201
- const filterList = (key, label) => {
202
- const entries = item[key];
203
- if (entries === undefined)
204
- return;
205
- const kept = [];
206
- for (const entry of entries) {
207
- if (label === 'tools' && omittedAllowFlaws.has(entry))
208
- continue;
209
- if (flawedEntries.has(`${label}\u0000${entry}`)) {
210
- kept.push(entry);
172
+ for (const f of flaws) {
173
+ if (f.rewritten !== true)
211
174
  continue;
212
- }
213
- const toolName = label === 'disallowedTools' ? deniedEntryToolName(entry) : entry;
214
- const reading = toolName === undefined ? 'outside' : mcpEntryReadingOf(toolName, deps.toolDirectory);
215
- if (reading === 'unanswered') {
216
- warnings.push(`agents wire: ${whoOf()} ${label} entry ${JSON.stringify(entry)} names no tool this deployment answers to — omitted: no MCP server of that name is declared for this session, so there is nothing to ${label === 'tools' ? 'give' : 'hide'}, and newer engines refuse a request whose agent definitions name such a tool. Remove the entry or configure the server.`);
217
- continue;
218
- }
219
- if (reading === 'unchecked') {
220
- warnings.push(`agents wire: ${whoOf()} ${label} entry ${JSON.stringify(entry)} could not be checked against the MCP servers this session declares — sent as written; if no such server is declared, newer engines refuse the whole request until the entry is removed.`);
221
- }
222
- kept.push(entry);
223
- }
224
- if (key === 'allowTools') {
225
- item.allowTools = kept;
226
- }
227
- else if (kept.length > 0) {
228
- item.denyTools = kept;
175
+ warnings.push(`agents wire: ${who}: its disallowedTools entry ${toolListFlawPhrase(f)} — rewritten to ${JSON.stringify(f.currentName)} for this run (this run's tools include none named ${JSON.stringify(f.entry)}). Update the entry in the agent definition.`);
229
176
  }
230
- else {
231
- delete item.denyTools;
177
+ for (const f of flaws) {
178
+ if (f.list !== 'tools')
179
+ continue;
180
+ warnings.push(`agents wire: ${who}: its tools entry ${toolListFlawPhrase(f)} — sent as written; tool names are matched exactly, so this entry gives the agent nothing unless this run has a tool with exactly that name. Fix the entry in the agent definition.`);
232
181
  }
233
- };
234
- filterList('denyTools', 'disallowedTools');
235
- filterList('allowTools', 'tools');
182
+ }
236
183
  if (def.memory !== undefined) {
237
184
  if (typeof def.memory === 'string' && AGENT_MEMORY_WORDS.has(def.memory)) {
238
185
  item.memory = { scopes: [`agent:${name}`], writeScope: `agent:${name}` };
@@ -297,62 +244,58 @@ export function projectAgentsForWire(defs, deps) {
297
244
  item.systemPrompt = prompt;
298
245
  }
299
246
  }
300
- if (def.maxTurns !== undefined) {
301
- if (typeof def.maxTurns === 'number' &&
302
- Number.isInteger(def.maxTurns) &&
303
- def.maxTurns >= 1 &&
304
- def.maxTurns <= MAX_AGENT_MAX_TURNS) {
305
- item.maxTurns = def.maxTurns;
306
- }
307
- else {
308
- warnings.push(`agents wire: agent "${name}" maxTurns ${String(def.maxTurns)} out of range (1..${MAX_AGENT_MAX_TURNS}) — dropped`);
309
- }
310
- }
247
+ if (def.maxTurns !== undefined)
248
+ item.maxTurns = def.maxTurns;
311
249
  out.push(item);
312
250
  }
313
251
  return { agents: out.length > 0 ? out : undefined, warnings, ...(toolListFlaws.length > 0 ? { toolListFlaws } : {}) };
314
252
  }
253
+ function taskAgentsVerdictOf(v) {
254
+ switch (v.kind) {
255
+ case 'value':
256
+ return v.value === true;
257
+ case 'unobserved':
258
+ case 'unreadable':
259
+ return undefined;
260
+ default:
261
+ return false;
262
+ }
263
+ }
264
+ const TASK_AGENTS_CAPS_SETTLE_MS = 3000;
315
265
  export async function engineSupportsTaskAgents(baseUrl, opts) {
266
+ const budget = opts?.timeoutMs ?? TASK_AGENTS_CAPS_SETTLE_MS;
316
267
  if (opts?.client !== undefined) {
317
268
  const injected = opts.client;
318
269
  if (typeof injected?.capabilities !== 'function')
319
270
  return undefined;
320
- const got = await settleWithinDeadline(opts.timeoutMs ?? 3000, (signal) => injected.capabilities({ signal }));
321
- return got.kind === 'value' ? taskAgentsOf(got.value) : undefined;
271
+ return taskAgentsVerdictOf(await engineCapValueVia(undefined, 'taskAgents', async () => {
272
+ const got = await settleWithinDeadline(budget, (signal) => injected.capabilities({ signal }));
273
+ if (got.kind !== 'value')
274
+ throw new Error('capabilities probe did not settle within its budget');
275
+ return got.value;
276
+ }));
322
277
  }
323
278
  const client = makeEngineWireClient({
324
279
  baseUrl,
325
280
  ...(opts?.authToken ? { token: opts.authToken } : {}),
326
281
  ...(opts?.principal ? { principal: opts.principal } : {}),
327
- timeoutMs: opts?.timeoutMs ?? 3000,
282
+ timeoutMs: budget,
328
283
  ...(opts?.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}),
329
284
  });
330
285
  if (!client)
331
286
  return undefined;
332
- try {
333
- const caps = await client.capabilities();
334
- return taskAgentsOf(caps);
335
- }
336
- catch {
337
- return undefined;
338
- }
339
- }
340
- function taskAgentsOf(caps) {
341
- if (caps === null || typeof caps !== 'object')
342
- return false;
343
- try {
344
- return ownDataField(caps, 'taskAgents') === true;
345
- }
346
- catch {
347
- return undefined;
348
- }
287
+ return taskAgentsVerdictOf(await engineCapValueVia(undefined, 'taskAgents', () => client.capabilities()));
349
288
  }
350
289
  let activeProjector = null;
351
290
  let preparedKey = null;
291
+ let preparedCapsGen = null;
352
292
  let preparedPromise = null;
353
293
  let payload;
354
- let capsVerdict;
355
- let settleGeneration = null;
294
+ let currentGeneration = null;
295
+ function concludeGeneration(generation, outcome) {
296
+ if (generation !== null && preparedPromise === generation && currentGeneration !== null)
297
+ currentGeneration.outcome = outcome;
298
+ }
356
299
  const emittedWarnings = new Set();
357
300
  function warnOnce(msg) {
358
301
  if (emittedWarnings.has(msg))
@@ -360,45 +303,60 @@ function warnOnce(msg) {
360
303
  emittedWarnings.add(msg);
361
304
  console.error(`[sema] ${msg}`);
362
305
  }
306
+ function capsVerdictAt(baseUrl) {
307
+ return baseUrl === null ? undefined : taskAgentsVerdictOf(engineCapValue(baseUrl, 'taskAgents'));
308
+ }
309
+ function capsSettledAt(baseUrl) {
310
+ return baseUrl === null ? Promise.resolve() : engineCapsSettled(baseUrl, { withinMs: TASK_AGENTS_CAPS_SETTLE_MS });
311
+ }
312
+ function kickTaskAgentsCaps(cfg) {
313
+ if (engineCapsLandingOf(cfg.baseUrl).kind !== 'not_landed')
314
+ return;
315
+ const client = makeEngineWireClient({
316
+ baseUrl: cfg.baseUrl,
317
+ ...(cfg.authToken ? { token: cfg.authToken } : {}),
318
+ ...(cfg.principal ? { principal: cfg.principal } : {}),
319
+ timeoutMs: TASK_AGENTS_CAPS_SETTLE_MS,
320
+ });
321
+ if (!client)
322
+ return;
323
+ kickEngineCapsProbe(cfg.baseUrl, () => client.capabilities());
324
+ }
325
+ function watchCapsVerdict(baseUrl) {
326
+ void engineCapsSettled(baseUrl).then(() => {
327
+ if (preparedKey !== baseUrl || capsVerdictAt(baseUrl) !== false)
328
+ return;
329
+ payload = undefined;
330
+ concludeGeneration(preparedPromise, 'ok');
331
+ currentGeneration?.settle();
332
+ });
333
+ }
363
334
  function applyProjectionIfCurrent(generation, projected) {
364
335
  if (generation === null || preparedPromise !== generation)
365
336
  return false;
366
- const accepted = capsVerdict !== false;
337
+ const accepted = capsVerdictAt(preparedKey) !== false;
367
338
  if (accepted) {
368
339
  for (const w of projected.warnings)
369
340
  warnOnce(w);
370
341
  payload = projected.agents;
371
342
  }
372
- settleGeneration?.();
343
+ else {
344
+ payload = undefined;
345
+ }
346
+ concludeGeneration(generation, 'ok');
347
+ currentGeneration?.settle();
373
348
  return accepted;
374
349
  }
375
- function startCapsProbe(cfg) {
376
- const land = (verdict) => {
377
- if (capsVerdict !== probe)
378
- return verdict;
379
- capsVerdict = verdict;
380
- if (verdict === false) {
381
- payload = undefined;
382
- settleGeneration?.();
383
- }
384
- return verdict;
385
- };
386
- const probe = engineSupportsTaskAgents(cfg.baseUrl, {
387
- authToken: cfg.authToken,
388
- principal: cfg.principal,
389
- }).then(land, () => land(undefined));
390
- capsVerdict = probe;
391
- return probe;
392
- }
393
- function capsSettled() {
394
- return capsVerdict instanceof Promise ? capsVerdict : Promise.resolve();
395
- }
396
- async function runPrepare(cfg, projector, probe, generation) {
350
+ async function runPrepare(cfg, projector, generation) {
397
351
  try {
398
- const [caps, projected] = await Promise.all([probe, projector()]);
399
- if (caps === false) {
400
- if (projected.agents && preparedKey === cfg.baseUrl) {
401
- warnOnce(`agents wire: this engine does not support per-task custom agents (capabilities.taskAgents is not true: the engine does not report it, or this deployment turns it off, for example a multi-tenant one; this client cannot tell which) — ${projected.agents.length} custom agent definition(s) will NOT be sent`);
352
+ const [, projected] = await Promise.all([capsSettledAt(cfg.baseUrl), projector()]);
353
+ if (capsVerdictAt(cfg.baseUrl) === false) {
354
+ if (preparedKey === cfg.baseUrl) {
355
+ payload = undefined;
356
+ concludeGeneration(generation, 'ok');
357
+ if (projected.agents) {
358
+ warnOnce(`agents wire: this engine does not support per-task custom agents (capabilities.taskAgents is not true: the engine does not report it, or this deployment turns it off, for example a multi-tenant one; this client cannot tell which) — ${projected.agents.length} custom agent definition(s) will NOT be sent`);
359
+ }
402
360
  }
403
361
  return;
404
362
  }
@@ -411,29 +369,33 @@ async function runPrepare(cfg, projector, probe, generation) {
411
369
  catch (e) {
412
370
  if (preparedPromise === generation)
413
371
  payload = undefined;
372
+ concludeGeneration(generation, 'failed');
414
373
  if (hostEnv().SEMA_DEBUG) {
415
- console.error('[sema] agents wire prepare soft-failed (no agents stamped):', e);
374
+ console.error('[sema] agents wire prepare failed (the readiness gate refuses this turn):', e);
416
375
  }
417
376
  }
418
377
  }
419
378
  export function prepareTaskAgentsWireWith(cfg, projector) {
420
379
  const key = cfg.baseUrl;
421
- if (preparedPromise && preparedKey === key)
380
+ kickTaskAgentsCaps(cfg);
381
+ const capsGen = engineCapsGeneration(key);
382
+ if (preparedPromise && preparedKey === key && preparedCapsGen === capsGen)
422
383
  return preparedPromise;
423
384
  preparedKey = key;
385
+ preparedCapsGen = capsGen;
424
386
  activeProjector = projector;
425
- const probe = startCapsProbe(cfg);
426
- return startGeneration(generation => runPrepare(cfg, projector, probe, generation));
387
+ watchCapsVerdict(key);
388
+ return startGeneration(generation => runPrepare(cfg, projector, generation));
427
389
  }
428
390
  function startGeneration(run) {
429
391
  let settle;
430
392
  const generation = new Promise(resolve => {
431
393
  settle = resolve;
432
394
  });
433
- const superseded = settleGeneration;
395
+ const superseded = currentGeneration;
434
396
  preparedPromise = generation;
435
- settleGeneration = settle;
436
- superseded?.();
397
+ currentGeneration = { settle, outcome: undefined };
398
+ superseded?.settle();
437
399
  void run(generation).then(settle, settle);
438
400
  return generation;
439
401
  }
@@ -445,28 +407,36 @@ export function invalidateTaskAgentsWire() {
445
407
  return startGeneration(generation => runReproject(projector, generation));
446
408
  }
447
409
  async function runReproject(projector, generation) {
410
+ const base = preparedKey;
448
411
  try {
449
412
  let projected;
450
413
  try {
451
414
  projected = await projector();
452
415
  }
453
416
  catch (e) {
417
+ concludeGeneration(generation, 'failed');
454
418
  if (hostEnv().SEMA_DEBUG) {
455
- console.error('[sema] agents wire re-project soft-failed (no agents stamped until the next successful projection):', e);
419
+ console.error('[sema] agents wire re-project failed (the readiness gate refuses until a projection succeeds):', e);
456
420
  }
457
421
  return;
458
422
  }
459
- await capsSettled();
423
+ await capsSettledAt(base);
460
424
  applyProjectionIfCurrent(generation, projected);
461
425
  }
462
426
  catch {
427
+ concludeGeneration(generation, 'failed');
463
428
  }
464
429
  }
465
430
  export async function awaitTaskAgentsWire(timeoutMs = 4000) {
466
431
  if (!preparedPromise)
467
- return;
468
- if (capsVerdict === false)
469
- return;
432
+ return taskAgentsReady();
433
+ if (capsVerdictAt(preparedKey) === false)
434
+ return taskAgentsReady();
435
+ const projector = activeProjector;
436
+ if (currentGeneration?.outcome === 'failed' && projector !== null) {
437
+ payload = undefined;
438
+ void startGeneration(generation => runReproject(projector, generation));
439
+ }
470
440
  let timeoutHandle;
471
441
  let timedOut = false;
472
442
  const deadline = new Promise(resolve => {
@@ -486,33 +456,56 @@ export async function awaitTaskAgentsWire(timeoutMs = 4000) {
486
456
  if (timeoutHandle !== undefined)
487
457
  clearTimeout(timeoutHandle);
488
458
  }
459
+ if (preparedPromise === null || capsVerdictAt(preparedKey) === false)
460
+ return taskAgentsReady();
461
+ const outcome = currentGeneration?.outcome;
462
+ if (outcome === 'ok')
463
+ return taskAgentsReady();
464
+ if (outcome === 'failed')
465
+ return Object.freeze({ ok: false, refusal: assemblyRefusal('agents_projection_failed') });
466
+ kickTaskAgentsRefresh();
467
+ return Object.freeze({ ok: false, refusal: assemblyRefusal('agents_not_ready') });
468
+ }
469
+ function taskAgentsReady() {
470
+ return Object.freeze({ ok: true });
471
+ }
472
+ function kickTaskAgentsRefresh() {
473
+ const projector = activeProjector;
474
+ if (!preparedPromise || projector === null)
475
+ return false;
476
+ const generation = preparedPromise;
477
+ const base = preparedKey;
478
+ let refreshing;
479
+ try {
480
+ refreshing = projector();
481
+ }
482
+ catch {
483
+ return false;
484
+ }
485
+ void refreshing
486
+ .then(async (p) => {
487
+ await capsSettledAt(base);
488
+ applyProjectionIfCurrent(generation, p);
489
+ })
490
+ .catch(() => { });
491
+ return true;
489
492
  }
490
493
  export function taskAgentsField() {
491
- const current = payload;
492
- if (preparedPromise && capsVerdict !== false && activeProjector) {
493
- const generation = preparedPromise;
494
- let refreshing;
495
- try {
496
- refreshing = activeProjector();
497
- }
498
- catch {
499
- return current ? { agents: current } : {};
500
- }
501
- void refreshing
502
- .then(async (p) => {
503
- await capsSettled();
504
- applyProjectionIfCurrent(generation, p);
505
- })
506
- .catch(() => { });
494
+ const base = preparedKey;
495
+ if (capsVerdictAt(base) === false) {
496
+ payload = undefined;
497
+ return {};
507
498
  }
499
+ const current = payload;
500
+ kickTaskAgentsRefresh();
508
501
  return current ? { agents: current } : {};
509
502
  }
510
503
  export function _resetAgentsWireForTest() {
511
504
  activeProjector = null;
512
505
  preparedKey = null;
506
+ preparedCapsGen = null;
513
507
  preparedPromise = null;
514
- settleGeneration = null;
508
+ currentGeneration = null;
515
509
  payload = undefined;
516
- capsVerdict = undefined;
517
510
  emittedWarnings.clear();
518
511
  }
@@ -9,9 +9,5 @@ export type ApprovalDecidedByReading = {
9
9
  value: true;
10
10
  };
11
11
  export declare function projectApprovalDecidedByCapability(caps: unknown): ApprovalDecidedByReading | undefined;
12
- export declare function noteEngineCapsForApprovalDecidedBy(baseUrl: string, caps: unknown, opts?: {
13
- generation?: number;
14
- }): void;
15
12
  export declare function observedApprovalDecidedBy(baseUrl?: string | undefined): ApprovalDecidedByReading;
16
13
  export declare function approvalDecidedByAdmitted(reading: ApprovalDecidedByReading | undefined): boolean;
17
- export declare function __resetApprovalDecidedByReadingsForTests(): void;
@@ -18,9 +18,6 @@ const reader = createEngineCapReader({
18
18
  name: 'approvalDecidedBy',
19
19
  project: projectApprovalDecidedByCapability,
20
20
  });
21
- export function noteEngineCapsForApprovalDecidedBy(baseUrl, caps, opts) {
22
- reader.note(baseUrl, caps, opts);
23
- }
24
21
  export function observedApprovalDecidedBy(baseUrl = engineWireTarget()?.baseUrl) {
25
22
  return reader.observed(baseUrl);
26
23
  }
@@ -36,6 +33,3 @@ export function approvalDecidedByAdmitted(reading) {
36
33
  return false;
37
34
  }
38
35
  }
39
- export function __resetApprovalDecidedByReadingsForTests() {
40
- reader.__resetForTests();
41
- }
@@ -9,10 +9,6 @@ export type ApprovalsStreamLiveReading = {
9
9
  live: boolean;
10
10
  };
11
11
  export declare function projectApprovalsStreamLiveCapability(caps: unknown): ApprovalsStreamLiveReading | undefined;
12
- export declare function noteEngineCapsForApprovalsStreamLive(baseUrl: string, caps: unknown, opts?: {
13
- generation?: number;
14
- }): void;
15
12
  export declare function observedApprovalsStreamLive(baseUrl?: string | undefined): ApprovalsStreamLiveReading;
16
13
  export declare function livePendingNeedsReconcile(reading: ApprovalsStreamLiveReading): boolean;
17
14
  export declare function approvalsStreamLiveDoctorDetail(reading: ApprovalsStreamLiveReading): string;
18
- export declare function __resetApprovalsStreamLiveReadingsForTests(): void;
@@ -22,9 +22,6 @@ const reader = createEngineCapReader({
22
22
  name: 'approvalsStreamLive',
23
23
  project: projectApprovalsStreamLiveCapability,
24
24
  });
25
- export function noteEngineCapsForApprovalsStreamLive(baseUrl, caps, opts) {
26
- reader.note(baseUrl, caps, opts);
27
- }
28
25
  export function observedApprovalsStreamLive(baseUrl = engineWireTarget()?.baseUrl) {
29
26
  return reader.observed(baseUrl);
30
27
  }
@@ -45,6 +42,3 @@ export function approvalsStreamLiveDoctorDetail(reading) {
45
42
  : 'live approval push off on this deployment (no checkpoint store or tool approvals disabled; the engine reports one bit for both, so this client cannot tell which) — suspended asks are only visible through the reconcile cadence, so the client polls for them';
46
43
  }
47
44
  }
48
- export function __resetApprovalsStreamLiveReadingsForTests() {
49
- reader.__resetForTests();
50
- }
@@ -0,0 +1,34 @@
1
+ import type { AgentClient } from '@sema-agent/sdk';
2
+ export type AssistantInboxVerb = Pick<AgentClient['assistant'], 'inbox'>;
3
+ export interface AssistantInboxEntry {
4
+ readonly sessionId: string;
5
+ readonly scope?: string;
6
+ readonly gateKind?: string;
7
+ readonly severity?: 1 | 2 | 3 | 4 | 5;
8
+ readonly spentMicroUsd?: number;
9
+ readonly deadlineMs?: number;
10
+ readonly createdAtMs?: number;
11
+ readonly objective?: string;
12
+ readonly inputPreview?: string;
13
+ readonly requiresRealApproval?: true;
14
+ readonly mandated?: true;
15
+ readonly hasBidiControls?: true;
16
+ }
17
+ export type AssistantInboxUnavailableReason = 'unauthorized' | 'unreadable' | 'failed';
18
+ export type AssistantInboxReading = {
19
+ readonly kind: 'present';
20
+ readonly entries: readonly AssistantInboxEntry[];
21
+ readonly dropped: number;
22
+ } | {
23
+ readonly kind: 'unavailable';
24
+ readonly reason: AssistantInboxUnavailableReason;
25
+ readonly status?: number;
26
+ readonly errorCode?: string;
27
+ } | {
28
+ readonly kind: 'not-reported';
29
+ readonly via: 'lane-absent' | 'unarmed';
30
+ };
31
+ export declare function isAssistantLaneAbsent(err: {} | null | undefined): boolean;
32
+ export declare function readAssistantInbox(assistant: AssistantInboxVerb | null | undefined, opts?: {
33
+ readonly signal?: AbortSignal | undefined;
34
+ }): Promise<AssistantInboxReading>;