@sema-agent/client-core 0.97.0 → 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 +429 -0
  2. package/README.md +74 -36
  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 -6
  29. package/dist/agentsWireCaps.js +177 -162
  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 +18 -0
  74. package/dist/engineToolDirectory.js +85 -0
  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 -18
  167. package/dist/index.js +38 -10
  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 +1305 -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,20 +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 } from './engineToolDirectory.js';
11
+ import { assemblyRefusal } from './wireFailureShape.js';
10
12
  export const MAX_TASK_AGENTS = 32;
11
- export const MAX_AGENT_NAME_CHARS = 64;
12
13
  export const MAX_AGENT_TEXT_CHARS = 4_096;
13
14
  export const MAX_AGENT_SYSTEM_PROMPT_CHARS = 65_536;
14
- export const MAX_AGENT_TOOLS = 64;
15
- export const MAX_AGENT_TOOL_NAME_CHARS = 128;
16
15
  export const MAX_AGENT_SKILL_CONTENT_CHARS = 1_048_576;
17
- export const MAX_AGENT_MAX_TURNS = 1_000;
18
16
  export const TASK_AGENT_WIRE_FIELDS = [
19
17
  'name',
20
18
  'whenToUse',
@@ -43,31 +41,6 @@ const SOURCE_RANK = {
43
41
  function sourceRank(source) {
44
42
  return SOURCE_RANK[source] ?? 5;
45
43
  }
46
- function unescapedIndexOf(s, ch, last) {
47
- for (let k = 0; k < s.length; k++) {
48
- const i = last ? s.length - 1 - k : k;
49
- if (s[i] !== ch)
50
- continue;
51
- let backslashes = 0;
52
- for (let j = i - 1; j >= 0 && s[j] === '\\'; j--)
53
- backslashes++;
54
- if (backslashes % 2 === 0)
55
- return i;
56
- }
57
- return -1;
58
- }
59
- function deniedEntryToolName(entry) {
60
- if (entry !== entry.trim())
61
- return undefined;
62
- const open = unescapedIndexOf(entry, '(', false);
63
- if (open === -1)
64
- return entry;
65
- const close = unescapedIndexOf(entry, ')', true);
66
- if (close === -1 || close <= open || close !== entry.length - 1)
67
- return entry;
68
- const name = entry.substring(0, open);
69
- return name.length === 0 ? entry : name.trim();
70
- }
71
44
  function toolNameFlawOf(entry, names, list) {
72
45
  if (typeof entry !== 'string' || entry.length === 0 || entry === '*')
73
46
  return undefined;
@@ -144,10 +117,6 @@ export function projectAgentsForWire(defs, deps) {
144
117
  const name = def.agentType;
145
118
  if (typeof name !== 'string' || name.length === 0)
146
119
  continue;
147
- if (name.length > MAX_AGENT_NAME_CHARS) {
148
- warnings.push(`agents wire: agent name "${name.slice(0, 40)}…" exceeds ${MAX_AGENT_NAME_CHARS} chars — definition skipped`);
149
- continue;
150
- }
151
120
  if (seen.has(name))
152
121
  continue;
153
122
  seen.add(name);
@@ -161,29 +130,23 @@ export function projectAgentsForWire(defs, deps) {
161
130
  warnings.push(`agents wire: agent "${name}" description truncated to ${MAX_AGENT_TEXT_CHARS} chars`);
162
131
  }
163
132
  }
164
- const projectTools = (list, label) => {
165
- if (!Array.isArray(list) || list.length === 0)
166
- return undefined;
167
- const kept = list.filter(t => typeof t === 'string' && t.length > 0 && t.length <= MAX_AGENT_TOOL_NAME_CHARS);
168
- 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)
169
136
  warnings.push(`agents wire: agent "${name}" ${label} had invalid entries — dropped`);
170
- }
171
- if (kept.length === 0)
172
- return undefined;
173
- if (kept.length > MAX_AGENT_TOOLS) {
174
- warnings.push(`agents wire: agent "${name}" ${label} truncated to ${MAX_AGENT_TOOLS} entries`);
175
- return kept.slice(0, MAX_AGENT_TOOLS);
176
- }
177
- return kept;
137
+ return entries;
178
138
  };
179
- const allowTools = projectTools(def.tools, 'tools');
180
- if (allowTools)
181
- item.allowTools = allowTools;
182
- const denyTools = projectTools(def.disallowedTools, 'disallowedTools');
183
- if (denyTools)
184
- item.denyTools = denyTools;
185
- const flaws = agentToolListFlaws([item], deps.toolRoster);
186
- if (flaws.length > 0) {
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
+ }
146
+ let whoMemo;
147
+ const whoOf = () => {
148
+ if (whoMemo !== undefined)
149
+ return whoMemo;
187
150
  let source;
188
151
  try {
189
152
  source = deps.agentSourceLabel?.(name);
@@ -191,25 +154,31 @@ export function projectAgentsForWire(defs, deps) {
191
154
  catch {
192
155
  source = undefined;
193
156
  }
194
- const who = `agent "${name}"${typeof source === 'string' && source.length > 0 ? ` (${capForDisplay(source, 120)})` : ''}`;
157
+ whoMemo = `agent "${name}"${typeof source === 'string' && source.length > 0 ? ` (${capForDisplay(source, 120)})` : ''}`;
158
+ return whoMemo;
159
+ };
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
+ });
169
+ if (flaws.length > 0) {
170
+ const who = whoOf();
195
171
  toolListFlaws.push(...flaws);
196
- const denyFlaws = flaws.filter(f => f.list === 'disallowedTools');
197
- const withhold = denyFlaws.length > 0 && deps.withholdRefusedDenyLists === true;
198
- if (denyFlaws.length > 0) {
199
- const what = `its disallowedTools ${denyFlaws.length === 1 ? 'entry' : 'entries'} ${denyFlaws.map(toolListFlawPhrase).join('; ')}`;
200
- warnings.push(withhold
201
- ? `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.`
202
- : `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.`);
172
+ for (const f of flaws) {
173
+ if (f.rewritten !== true)
174
+ continue;
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.`);
203
176
  }
204
- if (!withhold) {
205
- for (const f of flaws) {
206
- if (f.list !== 'tools')
207
- continue;
208
- warnings.push(`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.`);
209
- }
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.`);
210
181
  }
211
- if (withhold)
212
- continue;
213
182
  }
214
183
  if (def.memory !== undefined) {
215
184
  if (typeof def.memory === 'string' && AGENT_MEMORY_WORDS.has(def.memory)) {
@@ -275,62 +244,58 @@ export function projectAgentsForWire(defs, deps) {
275
244
  item.systemPrompt = prompt;
276
245
  }
277
246
  }
278
- if (def.maxTurns !== undefined) {
279
- if (typeof def.maxTurns === 'number' &&
280
- Number.isInteger(def.maxTurns) &&
281
- def.maxTurns >= 1 &&
282
- def.maxTurns <= MAX_AGENT_MAX_TURNS) {
283
- item.maxTurns = def.maxTurns;
284
- }
285
- else {
286
- warnings.push(`agents wire: agent "${name}" maxTurns ${String(def.maxTurns)} out of range (1..${MAX_AGENT_MAX_TURNS}) — dropped`);
287
- }
288
- }
247
+ if (def.maxTurns !== undefined)
248
+ item.maxTurns = def.maxTurns;
289
249
  out.push(item);
290
250
  }
291
251
  return { agents: out.length > 0 ? out : undefined, warnings, ...(toolListFlaws.length > 0 ? { toolListFlaws } : {}) };
292
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;
293
265
  export async function engineSupportsTaskAgents(baseUrl, opts) {
266
+ const budget = opts?.timeoutMs ?? TASK_AGENTS_CAPS_SETTLE_MS;
294
267
  if (opts?.client !== undefined) {
295
268
  const injected = opts.client;
296
269
  if (typeof injected?.capabilities !== 'function')
297
270
  return undefined;
298
- const got = await settleWithinDeadline(opts.timeoutMs ?? 3000, (signal) => injected.capabilities({ signal }));
299
- 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
+ }));
300
277
  }
301
278
  const client = makeEngineWireClient({
302
279
  baseUrl,
303
280
  ...(opts?.authToken ? { token: opts.authToken } : {}),
304
281
  ...(opts?.principal ? { principal: opts.principal } : {}),
305
- timeoutMs: opts?.timeoutMs ?? 3000,
282
+ timeoutMs: budget,
306
283
  ...(opts?.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}),
307
284
  });
308
285
  if (!client)
309
286
  return undefined;
310
- try {
311
- const caps = await client.capabilities();
312
- return taskAgentsOf(caps);
313
- }
314
- catch {
315
- return undefined;
316
- }
317
- }
318
- function taskAgentsOf(caps) {
319
- if (caps === null || typeof caps !== 'object')
320
- return false;
321
- try {
322
- return ownDataField(caps, 'taskAgents') === true;
323
- }
324
- catch {
325
- return undefined;
326
- }
287
+ return taskAgentsVerdictOf(await engineCapValueVia(undefined, 'taskAgents', () => client.capabilities()));
327
288
  }
328
289
  let activeProjector = null;
329
290
  let preparedKey = null;
291
+ let preparedCapsGen = null;
330
292
  let preparedPromise = null;
331
293
  let payload;
332
- let capsVerdict;
333
- 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
+ }
334
299
  const emittedWarnings = new Set();
335
300
  function warnOnce(msg) {
336
301
  if (emittedWarnings.has(msg))
@@ -338,45 +303,60 @@ function warnOnce(msg) {
338
303
  emittedWarnings.add(msg);
339
304
  console.error(`[sema] ${msg}`);
340
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
+ }
341
334
  function applyProjectionIfCurrent(generation, projected) {
342
335
  if (generation === null || preparedPromise !== generation)
343
336
  return false;
344
- const accepted = capsVerdict !== false;
337
+ const accepted = capsVerdictAt(preparedKey) !== false;
345
338
  if (accepted) {
346
339
  for (const w of projected.warnings)
347
340
  warnOnce(w);
348
341
  payload = projected.agents;
349
342
  }
350
- settleGeneration?.();
343
+ else {
344
+ payload = undefined;
345
+ }
346
+ concludeGeneration(generation, 'ok');
347
+ currentGeneration?.settle();
351
348
  return accepted;
352
349
  }
353
- function startCapsProbe(cfg) {
354
- const land = (verdict) => {
355
- if (capsVerdict !== probe)
356
- return verdict;
357
- capsVerdict = verdict;
358
- if (verdict === false) {
359
- payload = undefined;
360
- settleGeneration?.();
361
- }
362
- return verdict;
363
- };
364
- const probe = engineSupportsTaskAgents(cfg.baseUrl, {
365
- authToken: cfg.authToken,
366
- principal: cfg.principal,
367
- }).then(land, () => land(undefined));
368
- capsVerdict = probe;
369
- return probe;
370
- }
371
- function capsSettled() {
372
- return capsVerdict instanceof Promise ? capsVerdict : Promise.resolve();
373
- }
374
- async function runPrepare(cfg, projector, probe, generation) {
350
+ async function runPrepare(cfg, projector, generation) {
375
351
  try {
376
- const [caps, projected] = await Promise.all([probe, projector()]);
377
- if (caps === false) {
378
- if (projected.agents && preparedKey === cfg.baseUrl) {
379
- 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
+ }
380
360
  }
381
361
  return;
382
362
  }
@@ -389,29 +369,33 @@ async function runPrepare(cfg, projector, probe, generation) {
389
369
  catch (e) {
390
370
  if (preparedPromise === generation)
391
371
  payload = undefined;
372
+ concludeGeneration(generation, 'failed');
392
373
  if (hostEnv().SEMA_DEBUG) {
393
- 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);
394
375
  }
395
376
  }
396
377
  }
397
378
  export function prepareTaskAgentsWireWith(cfg, projector) {
398
379
  const key = cfg.baseUrl;
399
- if (preparedPromise && preparedKey === key)
380
+ kickTaskAgentsCaps(cfg);
381
+ const capsGen = engineCapsGeneration(key);
382
+ if (preparedPromise && preparedKey === key && preparedCapsGen === capsGen)
400
383
  return preparedPromise;
401
384
  preparedKey = key;
385
+ preparedCapsGen = capsGen;
402
386
  activeProjector = projector;
403
- const probe = startCapsProbe(cfg);
404
- return startGeneration(generation => runPrepare(cfg, projector, probe, generation));
387
+ watchCapsVerdict(key);
388
+ return startGeneration(generation => runPrepare(cfg, projector, generation));
405
389
  }
406
390
  function startGeneration(run) {
407
391
  let settle;
408
392
  const generation = new Promise(resolve => {
409
393
  settle = resolve;
410
394
  });
411
- const superseded = settleGeneration;
395
+ const superseded = currentGeneration;
412
396
  preparedPromise = generation;
413
- settleGeneration = settle;
414
- superseded?.();
397
+ currentGeneration = { settle, outcome: undefined };
398
+ superseded?.settle();
415
399
  void run(generation).then(settle, settle);
416
400
  return generation;
417
401
  }
@@ -423,28 +407,36 @@ export function invalidateTaskAgentsWire() {
423
407
  return startGeneration(generation => runReproject(projector, generation));
424
408
  }
425
409
  async function runReproject(projector, generation) {
410
+ const base = preparedKey;
426
411
  try {
427
412
  let projected;
428
413
  try {
429
414
  projected = await projector();
430
415
  }
431
416
  catch (e) {
417
+ concludeGeneration(generation, 'failed');
432
418
  if (hostEnv().SEMA_DEBUG) {
433
- 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);
434
420
  }
435
421
  return;
436
422
  }
437
- await capsSettled();
423
+ await capsSettledAt(base);
438
424
  applyProjectionIfCurrent(generation, projected);
439
425
  }
440
426
  catch {
427
+ concludeGeneration(generation, 'failed');
441
428
  }
442
429
  }
443
430
  export async function awaitTaskAgentsWire(timeoutMs = 4000) {
444
431
  if (!preparedPromise)
445
- return;
446
- if (capsVerdict === false)
447
- 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
+ }
448
440
  let timeoutHandle;
449
441
  let timedOut = false;
450
442
  const deadline = new Promise(resolve => {
@@ -464,33 +456,56 @@ export async function awaitTaskAgentsWire(timeoutMs = 4000) {
464
456
  if (timeoutHandle !== undefined)
465
457
  clearTimeout(timeoutHandle);
466
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;
467
492
  }
468
493
  export function taskAgentsField() {
469
- const current = payload;
470
- if (preparedPromise && capsVerdict !== false && activeProjector) {
471
- const generation = preparedPromise;
472
- let refreshing;
473
- try {
474
- refreshing = activeProjector();
475
- }
476
- catch {
477
- return current ? { agents: current } : {};
478
- }
479
- void refreshing
480
- .then(async (p) => {
481
- await capsSettled();
482
- applyProjectionIfCurrent(generation, p);
483
- })
484
- .catch(() => { });
494
+ const base = preparedKey;
495
+ if (capsVerdictAt(base) === false) {
496
+ payload = undefined;
497
+ return {};
485
498
  }
499
+ const current = payload;
500
+ kickTaskAgentsRefresh();
486
501
  return current ? { agents: current } : {};
487
502
  }
488
503
  export function _resetAgentsWireForTest() {
489
504
  activeProjector = null;
490
505
  preparedKey = null;
506
+ preparedCapsGen = null;
491
507
  preparedPromise = null;
492
- settleGeneration = null;
508
+ currentGeneration = null;
493
509
  payload = undefined;
494
- capsVerdict = undefined;
495
510
  emittedWarnings.clear();
496
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>;