@sema-agent/core 7.66.1 → 7.67.1

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 (904) hide show
  1. package/CHANGELOG.md +3518 -0
  2. package/LICENSE +2 -1
  3. package/dist/agents/agent-definition.js +2 -1
  4. package/dist/agents/agent-transcript-tool.d.ts +1 -1
  5. package/dist/agents/agent-transcript-tool.js +4 -3
  6. package/dist/agents/builtin-agents.d.ts +10 -7
  7. package/dist/agents/builtin-agents.js +1 -0
  8. package/dist/agents/cascade.d.ts +24 -11
  9. package/dist/agents/cascade.js +21 -9
  10. package/dist/agents/child-failure.d.ts +30 -0
  11. package/dist/agents/child-failure.js +25 -1
  12. package/dist/agents/composition-placement.d.ts +6 -2
  13. package/dist/agents/composition-placement.js +7 -3
  14. package/dist/agents/cross-session-envelope.d.ts +10 -1
  15. package/dist/agents/cross-session-envelope.js +6 -2
  16. package/dist/agents/cross-session-judge.d.ts +7 -1
  17. package/dist/agents/cross-session-judge.js +1 -0
  18. package/dist/agents/cumulative-stats.d.ts +36 -2
  19. package/dist/agents/cumulative-stats.js +44 -9
  20. package/dist/agents/delegation-registry-seat.js +2 -3
  21. package/dist/agents/inherited-tool-pool.d.ts +9 -4
  22. package/dist/agents/inherited-tool-pool.js +7 -1
  23. package/dist/agents/leg-label.d.ts +28 -0
  24. package/dist/agents/leg-label.js +9 -0
  25. package/dist/agents/list-agents-tool.d.ts +1 -1
  26. package/dist/agents/list-agents-tool.js +4 -4
  27. package/dist/agents/org-delivery-gate.d.ts +129 -23
  28. package/dist/agents/org-delivery-gate.js +41 -20
  29. package/dist/agents/peer-held-queue.d.ts +15 -10
  30. package/dist/agents/peer-held-queue.js +47 -19
  31. package/dist/agents/peer-notice-route.js +2 -2
  32. package/dist/agents/peer-notices.d.ts +13 -2
  33. package/dist/agents/peer-notices.js +12 -2
  34. package/dist/agents/peer-session-drain.d.ts +65 -15
  35. package/dist/agents/peer-session-drain.js +198 -41
  36. package/dist/agents/read-inbox-tool.d.ts +3 -2
  37. package/dist/agents/read-inbox-tool.js +7 -5
  38. package/dist/agents/repair-loop.js +20 -16
  39. package/dist/agents/retain-ledger.d.ts +1 -1
  40. package/dist/agents/retain-ledger.js +2 -4
  41. package/dist/agents/root-session-lane.d.ts +27 -0
  42. package/dist/agents/root-session-lane.js +57 -0
  43. package/dist/agents/roster-store.js +1 -2
  44. package/dist/agents/send-message-tool.js +6 -4
  45. package/dist/agents/subagent.d.ts +20 -4
  46. package/dist/agents/subagent.js +218 -183
  47. package/dist/agents/tool-filter.d.ts +3 -10
  48. package/dist/agents/tool-filter.js +0 -13
  49. package/dist/agents/verifier-independence.d.ts +31 -0
  50. package/dist/agents/verifier-independence.js +23 -0
  51. package/dist/agents/verify.d.ts +23 -11
  52. package/dist/agents/verify.js +28 -12
  53. package/dist/agents/yield-adoption.d.ts +24 -0
  54. package/dist/agents/yield-adoption.js +84 -0
  55. package/dist/bench/metrics.d.ts +2 -2
  56. package/dist/brain/anthropic.d.ts +4 -2
  57. package/dist/brain/anthropic.js +49 -35
  58. package/dist/brain/brain-faces.d.ts +11 -0
  59. package/dist/brain/brain-faces.js +6 -0
  60. package/dist/brain/cache-retention.d.ts +2 -0
  61. package/dist/brain/cache-retention.js +9 -0
  62. package/dist/brain/circuit-breaker.js +51 -26
  63. package/dist/brain/errors.d.ts +15 -1
  64. package/dist/brain/errors.js +8 -0
  65. package/dist/brain/failover.d.ts +6 -0
  66. package/dist/brain/failover.js +52 -37
  67. package/dist/brain/media-degrade.d.ts +5 -0
  68. package/dist/brain/media-degrade.js +4 -0
  69. package/dist/brain/model-capability.d.ts +2 -1
  70. package/dist/brain/model-lane.d.ts +169 -0
  71. package/dist/brain/model-lane.js +505 -0
  72. package/dist/brain/open-responses.js +19 -22
  73. package/dist/brain/openai.js +23 -22
  74. package/dist/brain/provider-message.d.ts +9 -0
  75. package/dist/brain/provider-message.js +18 -0
  76. package/dist/brain/reasoning-request.d.ts +9 -7
  77. package/dist/brain/reasoning-request.js +9 -10
  78. package/dist/brain/reasoning.d.ts +47 -13
  79. package/dist/brain/reasoning.js +20 -10
  80. package/dist/brain/route-adjudicator.d.ts +8 -2
  81. package/dist/brain/route-adjudicator.js +35 -1
  82. package/dist/brain/route-conformance.js +17 -0
  83. package/dist/brain/routing.d.ts +2 -0
  84. package/dist/brain/routing.js +19 -8
  85. package/dist/brain/status-sink.d.ts +5 -4
  86. package/dist/brain/status-sink.js +2 -2
  87. package/dist/brain/stream-engine.js +8 -2
  88. package/dist/brain/stream-shared.d.ts +12 -0
  89. package/dist/brain/stream-shared.js +18 -0
  90. package/dist/brain/timeout.d.ts +28 -0
  91. package/dist/brain/timeout.js +13 -4
  92. package/dist/brain/tool-schema-projection.d.ts +2 -0
  93. package/dist/brain/tool-schema-projection.js +108 -0
  94. package/dist/brain/usage-reading.d.ts +49 -0
  95. package/dist/brain/usage-reading.js +44 -0
  96. package/dist/brain/usage-reasoning.d.ts +38 -0
  97. package/dist/brain/usage-reasoning.js +9 -0
  98. package/dist/config/catalog.d.ts +3 -0
  99. package/dist/config/catalog.js +18 -9
  100. package/dist/core/a2a.d.ts +22 -4
  101. package/dist/core/a2a.js +191 -50
  102. package/dist/core/agent-definition.d.ts +3 -1
  103. package/dist/core/agent-state.d.ts +29 -16
  104. package/dist/core/agent-state.js +36 -9
  105. package/dist/core/allow-entry.d.ts +12 -3
  106. package/dist/core/allow-entry.js +10 -3
  107. package/dist/core/approval-display.d.ts +18 -0
  108. package/dist/core/approval-display.js +26 -0
  109. package/dist/core/approval-object.js +2 -2
  110. package/dist/core/approval-route.d.ts +16 -0
  111. package/dist/core/approval-route.js +5 -0
  112. package/dist/core/approval-words.d.ts +43 -0
  113. package/dist/core/approval-words.js +37 -0
  114. package/dist/core/ask-origin.d.ts +37 -10
  115. package/dist/core/ask-origin.js +19 -7
  116. package/dist/core/ask-question.d.ts +36 -8
  117. package/dist/core/ask-question.js +24 -9
  118. package/dist/core/ask-unresolvable-notice.d.ts +3 -2
  119. package/dist/core/ask-unresolvable-notice.js +3 -2
  120. package/dist/core/attachment-source.d.ts +50 -0
  121. package/dist/core/attachment-source.js +46 -0
  122. package/dist/core/auto-compaction.d.ts +151 -40
  123. package/dist/core/auto-compaction.js +115 -50
  124. package/dist/core/auto-mode.d.ts +5 -0
  125. package/dist/core/auto-mode.js +11 -4
  126. package/dist/core/background-agent-store.d.ts +151 -23
  127. package/dist/core/background-agent-store.js +201 -61
  128. package/dist/core/background-shell.d.ts +4 -1
  129. package/dist/core/background-shell.js +1 -0
  130. package/dist/core/cache-break-detector.d.ts +49 -25
  131. package/dist/core/cache-break-detector.js +99 -44
  132. package/dist/core/caller-text.d.ts +28 -0
  133. package/dist/core/caller-text.js +12 -0
  134. package/dist/core/canonical-json.d.ts +5 -0
  135. package/dist/core/canonical-json.js +7 -0
  136. package/dist/core/checkpoint-features.d.ts +80 -9
  137. package/dist/core/checkpoint-features.js +1 -1
  138. package/dist/core/checkpoint-generation.d.ts +8 -1
  139. package/dist/core/checkpoint-generation.js +3 -0
  140. package/dist/core/checkpoint-queries.d.ts +47 -14
  141. package/dist/core/checkpoint-queries.js +63 -30
  142. package/dist/core/checkpoint-requirements.d.ts +36 -3
  143. package/dist/core/checkpoint-requirements.js +11 -1
  144. package/dist/core/checkpoint-row-verdict.d.ts +0 -2
  145. package/dist/core/checkpoint-row-verdict.js +5 -8
  146. package/dist/core/checkpoint-store.d.ts +166 -41
  147. package/dist/core/checkpoint-store.js +96 -15
  148. package/dist/core/child-clamp-seats.d.ts +10 -2
  149. package/dist/core/child-clamp-seats.js +2 -2
  150. package/dist/core/classifier-unavailable-arm.d.ts +11 -9
  151. package/dist/core/classifier-unavailable-arm.js +4 -2
  152. package/dist/core/command-sandbox-dispatch.d.ts +13 -0
  153. package/dist/core/command-sandbox-dispatch.js +8 -0
  154. package/dist/core/command-sandbox.d.ts +231 -0
  155. package/dist/core/command-sandbox.js +344 -0
  156. package/dist/core/completion-id.d.ts +21 -0
  157. package/dist/core/completion-id.js +14 -0
  158. package/dist/core/config-refusal-codes.d.ts +22 -0
  159. package/dist/core/config-refusal-codes.js +196 -0
  160. package/dist/core/context-edit.d.ts +26 -0
  161. package/dist/core/context-edit.js +4 -2
  162. package/dist/core/context-guard.d.ts +80 -7
  163. package/dist/core/context-guard.js +126 -25
  164. package/dist/core/context-settings.d.ts +32 -0
  165. package/dist/core/context-settings.js +41 -3
  166. package/dist/core/contract-faces.d.ts +22 -0
  167. package/dist/core/contract-faces.js +1 -0
  168. package/dist/core/credential-echo.d.ts +2 -2
  169. package/dist/core/credential-echo.js +2 -2
  170. package/dist/core/cross-boundary-taint.d.ts +10 -8
  171. package/dist/core/decision-receipt.d.ts +3 -2
  172. package/dist/core/decision-receipt.js +1 -1
  173. package/dist/core/definition-entry-grammar.d.ts +42 -0
  174. package/dist/core/definition-entry-grammar.js +15 -0
  175. package/dist/core/engine-attestation.d.ts +19 -4
  176. package/dist/core/engine-attestation.js +4 -0
  177. package/dist/core/engine-capabilities.d.ts +8 -1
  178. package/dist/core/engine-capabilities.js +1 -1
  179. package/dist/core/engine-contracts/open-face-contract.d.ts +39 -0
  180. package/dist/core/engine-contracts/open-face-contract.js +57 -0
  181. package/dist/core/engine-notice.d.ts +164 -33
  182. package/dist/core/exclusive-temp.d.ts +25 -0
  183. package/dist/core/exclusive-temp.js +19 -0
  184. package/dist/core/existing-target.d.ts +112 -0
  185. package/dist/core/existing-target.js +88 -0
  186. package/dist/core/file-history-store.d.ts +14 -6
  187. package/dist/core/gate-lanes.js +8 -3
  188. package/dist/core/gate-outcome.d.ts +2 -1
  189. package/dist/core/git-worktree-env.d.ts +92 -1
  190. package/dist/core/git-worktree-env.js +87 -6
  191. package/dist/core/governance-codes.d.ts +49 -8
  192. package/dist/core/governance-codes.js +59 -8
  193. package/dist/core/hands-band.d.ts +10 -6
  194. package/dist/core/hooks.d.ts +60 -6
  195. package/dist/core/hooks.js +10 -2
  196. package/dist/core/host-floor.d.ts +24 -8
  197. package/dist/core/host-floor.js +45 -16
  198. package/dist/core/human-input-projection.d.ts +7 -0
  199. package/dist/core/human-input-projection.js +11 -3
  200. package/dist/core/image-admission.d.ts +16 -4
  201. package/dist/core/image-admission.js +29 -17
  202. package/dist/core/input-author.d.ts +43 -1
  203. package/dist/core/input-author.js +19 -0
  204. package/dist/core/isolation-scope.d.ts +41 -0
  205. package/dist/core/isolation-scope.js +10 -0
  206. package/dist/core/json-schema-seats.d.ts +11 -0
  207. package/dist/core/json-schema-seats.js +5 -0
  208. package/dist/core/leg-identity.d.ts +53 -5
  209. package/dist/core/leg-identity.js +32 -1
  210. package/dist/core/locked-config.d.ts +33 -38
  211. package/dist/core/locked-config.js +21 -3
  212. package/dist/core/lsp.js +2 -1
  213. package/dist/core/mailbox-store.d.ts +111 -18
  214. package/dist/core/mailbox-store.js +101 -13
  215. package/dist/core/mcp-call-meta.js +1 -1
  216. package/dist/core/mcp-connection-pool.d.ts +8 -2
  217. package/dist/core/mcp-connection-pool.js +3 -1
  218. package/dist/core/mcp-failure.d.ts +6 -1
  219. package/dist/core/mcp-failure.js +10 -0
  220. package/dist/core/mcp-host-read.d.ts +293 -0
  221. package/dist/core/mcp-host-read.js +428 -0
  222. package/dist/core/mcp-server-link.d.ts +28 -6
  223. package/dist/core/mcp-server-link.js +35 -7
  224. package/dist/core/mcp-server-spec.d.ts +22 -29
  225. package/dist/core/mcp-server-spec.js +7 -14
  226. package/dist/core/mcp-server-unavailable-notice.d.ts +32 -0
  227. package/dist/core/mcp-server-unavailable-notice.js +15 -0
  228. package/dist/core/mcp-session-end.d.ts +5 -2
  229. package/dist/core/mcp-session-end.js +7 -2
  230. package/dist/core/mcp-tool-meta.d.ts +6 -0
  231. package/dist/core/mcp-tool-meta.js +1 -0
  232. package/dist/core/mcp.d.ts +54 -19
  233. package/dist/core/mcp.js +194 -241
  234. package/dist/core/memory-engine/committed-shadow-read.d.ts +16 -0
  235. package/dist/core/memory-engine/committed-shadow-read.js +21 -0
  236. package/dist/core/memory-engine/consolidation-driver.js +2 -1
  237. package/dist/core/memory-engine/consolidation.d.ts +3 -3
  238. package/dist/core/memory-engine/control-objects.d.ts +4 -3
  239. package/dist/core/memory-engine/control-objects.js +6 -4
  240. package/dist/core/memory-engine/delegation-settlement.d.ts +127 -25
  241. package/dist/core/memory-engine/delegation-settlement.js +145 -18
  242. package/dist/core/memory-engine/distiller.d.ts +2 -1
  243. package/dist/core/memory-engine/distiller.js +10 -5
  244. package/dist/core/memory-engine/dual-root.js +2 -2
  245. package/dist/core/memory-engine/engine.d.ts +127 -33
  246. package/dist/core/memory-engine/engine.js +774 -323
  247. package/dist/core/memory-engine/entry-scan.d.ts +3 -0
  248. package/dist/core/memory-engine/entry-scan.js +8 -0
  249. package/dist/core/memory-engine/export-bundle.d.ts +4 -0
  250. package/dist/core/memory-engine/export-bundle.js +2 -0
  251. package/dist/core/memory-engine/file-backend.d.ts +62 -17
  252. package/dist/core/memory-engine/file-backend.js +155 -99
  253. package/dist/core/memory-engine/index.d.ts +1 -1
  254. package/dist/core/memory-engine/index.js +1 -1
  255. package/dist/core/memory-engine/layer-observations.d.ts +7 -1
  256. package/dist/core/memory-engine/layer-observations.js +6 -0
  257. package/dist/core/memory-engine/layout.d.ts +88 -26
  258. package/dist/core/memory-engine/layout.js +105 -29
  259. package/dist/core/memory-engine/memory-deployment.js +4 -4
  260. package/dist/core/memory-engine/mount-failed-notice.d.ts +24 -0
  261. package/dist/core/memory-engine/mount-failed-notice.js +22 -0
  262. package/dist/core/memory-engine/origin-clearance.d.ts +15 -1
  263. package/dist/core/memory-engine/origin-clearance.js +30 -10
  264. package/dist/core/memory-engine/scan.js +1 -1
  265. package/dist/core/memory-engine/scope-contract.js +4 -3
  266. package/dist/core/memory-engine/session-write-home.js +13 -1
  267. package/dist/core/memory-engine/sync-client.d.ts +1 -1
  268. package/dist/core/memory-engine/sync-client.js +3 -1
  269. package/dist/core/memory-engine/tools.d.ts +5 -4
  270. package/dist/core/memory-engine/tools.js +1 -1
  271. package/dist/core/memory-engine/types.d.ts +18 -1
  272. package/dist/core/memory-engine/types.js +1 -0
  273. package/dist/core/memory.d.ts +1 -1
  274. package/dist/core/memory.js +2 -6
  275. package/dist/core/mode-policy.d.ts +8 -1
  276. package/dist/core/mode-policy.js +6 -2
  277. package/dist/core/model-fallbacks.d.ts +105 -0
  278. package/dist/core/model-fallbacks.js +79 -0
  279. package/dist/core/model-receipt.d.ts +15 -3
  280. package/dist/core/model-receipt.js +22 -1
  281. package/dist/core/model-seat.d.ts +1 -1
  282. package/dist/core/mods/classic-events.d.ts +5 -1
  283. package/dist/core/mods/dollar.d.ts +47 -2
  284. package/dist/core/mods/dollar.js +28 -5
  285. package/dist/core/mods/kernel/budget.d.ts +6 -0
  286. package/dist/core/mods/kernel/budget.js +6 -0
  287. package/dist/core/mods/kernel/dispatch.d.ts +23 -2
  288. package/dist/core/mods/kernel/dispatch.js +104 -15
  289. package/dist/core/mods/kernel/events.d.ts +18 -1
  290. package/dist/core/mods/kernel/events.js +7 -6
  291. package/dist/core/mods/kernel/index.d.ts +2 -2
  292. package/dist/core/mods/kernel/index.js +1 -1
  293. package/dist/core/mods/kernel/receive.d.ts +2 -1
  294. package/dist/core/mods/lifecycle-stations.d.ts +13 -4
  295. package/dist/core/mods/lifecycle-stations.js +8 -3
  296. package/dist/core/mods/message-display.d.ts +81 -0
  297. package/dist/core/mods/message-display.js +369 -0
  298. package/dist/core/mods/prompt-submit.d.ts +1 -1
  299. package/dist/core/mods/prompt-submit.js +5 -2
  300. package/dist/core/mods/session-append.d.ts +2 -2
  301. package/dist/core/mods/session-append.js +2 -1
  302. package/dist/core/mods/session-compact.js +2 -2
  303. package/dist/core/mods/stations.d.ts +48 -18
  304. package/dist/core/mods/stations.js +100 -19
  305. package/dist/core/mods/stop-answers.d.ts +23 -0
  306. package/dist/core/mods/stop-answers.js +20 -0
  307. package/dist/core/mounted-mcp.d.ts +48 -8
  308. package/dist/core/mounted-mcp.js +82 -16
  309. package/dist/core/namespaced-rule-name.js +2 -1
  310. package/dist/core/own-property-receipt.js +3 -5
  311. package/dist/core/parent-spec-seat.d.ts +20 -1
  312. package/dist/core/parent-spec-seat.js +13 -3
  313. package/dist/core/park-selfcheck.js +1 -0
  314. package/dist/core/path-identity.js +2 -1
  315. package/dist/core/peer-seat.d.ts +21 -7
  316. package/dist/core/peer-seat.js +25 -16
  317. package/dist/core/permission-rule-consent.js +15 -5
  318. package/dist/core/permission-rule-model.d.ts +4 -2
  319. package/dist/core/permission-rule-model.js +43 -23
  320. package/dist/core/permission-rule-store.d.ts +31 -16
  321. package/dist/core/permission-rule-store.js +27 -18
  322. package/dist/core/present-plan-tool.d.ts +6 -1
  323. package/dist/core/present-plan-tool.js +11 -3
  324. package/dist/core/pricing.d.ts +8 -6
  325. package/dist/core/pricing.js +1 -1
  326. package/dist/core/principal-name.d.ts +13 -0
  327. package/dist/core/principal-name.js +9 -2
  328. package/dist/core/process-identity.d.ts +140 -0
  329. package/dist/core/process-identity.js +215 -0
  330. package/dist/core/protocol-http-auth.d.ts +28 -6
  331. package/dist/core/protocol-http-auth.js +22 -5
  332. package/dist/core/protocol-naming.d.ts +7 -0
  333. package/dist/core/protocol-naming.js +12 -2
  334. package/dist/core/protocol-revocation.d.ts +72 -0
  335. package/dist/core/protocol-revocation.js +98 -0
  336. package/dist/core/protocol-table.d.ts +4 -4
  337. package/dist/core/protocol-table.js +3 -2
  338. package/dist/core/push-queue.d.ts +35 -2
  339. package/dist/core/push-queue.js +60 -4
  340. package/dist/core/read-only-shell.d.ts +19 -0
  341. package/dist/core/read-only-shell.js +38 -11
  342. package/dist/core/real-approval.d.ts +26 -0
  343. package/dist/core/real-approval.js +15 -0
  344. package/dist/core/redaction-marks.d.ts +6 -2
  345. package/dist/core/redaction-marks.js +3 -0
  346. package/dist/core/reminder-mint.d.ts +6 -0
  347. package/dist/core/reminder-mint.js +9 -8
  348. package/dist/core/remote-env.d.ts +31 -15
  349. package/dist/core/remote-env.js +29 -0
  350. package/dist/core/request-copy-projection.d.ts +51 -0
  351. package/dist/core/request-copy-projection.js +410 -0
  352. package/dist/core/resume-config-judge.d.ts +69 -0
  353. package/dist/core/resume-config-judge.js +78 -0
  354. package/dist/core/resume-startup-cause.d.ts +14 -4
  355. package/dist/core/resume-startup-cause.js +12 -2
  356. package/dist/core/retention-policy.js +2 -1
  357. package/dist/core/retention.d.ts +119 -24
  358. package/dist/core/retention.js +60 -16
  359. package/dist/core/retired-keys.d.ts +0 -10
  360. package/dist/core/retired-keys.js +2 -3
  361. package/dist/core/roles.d.ts +24 -25
  362. package/dist/core/roles.js +148 -21
  363. package/dist/core/row-shape.d.ts +149 -0
  364. package/dist/core/row-shape.js +184 -0
  365. package/dist/core/runner/advertised-writable-dirs.js +10 -9
  366. package/dist/core/runner/advisor-instructions.d.ts +11 -27
  367. package/dist/core/runner/advisor-instructions.js +18 -20
  368. package/dist/core/runner/advisor-tool.js +1 -0
  369. package/dist/core/runner/announce-once-ledger.js +4 -1
  370. package/dist/core/runner/approval-feedback.d.ts +17 -8
  371. package/dist/core/runner/approval-feedback.js +18 -13
  372. package/dist/core/runner/approver-defect-announcer.d.ts +17 -0
  373. package/dist/core/runner/approver-defect-announcer.js +22 -0
  374. package/dist/core/runner/assemble-result.d.ts +29 -14
  375. package/dist/core/runner/assemble-result.js +16 -25
  376. package/dist/core/runner/cache-hit-account.d.ts +77 -0
  377. package/dist/core/runner/cache-hit-account.js +46 -0
  378. package/dist/core/runner/call-hook-stations.d.ts +3 -2
  379. package/dist/core/runner/call-hook-stations.js +5 -4
  380. package/dist/core/runner/changed-files-scan.d.ts +43 -0
  381. package/dist/core/runner/changed-files-scan.js +34 -0
  382. package/dist/core/runner/checkpoint-scope.d.ts +33 -9
  383. package/dist/core/runner/checkpoint-scope.js +27 -1
  384. package/dist/core/runner/classifier-ladder.d.ts +2 -2
  385. package/dist/core/runner/classifier-ladder.js +18 -9
  386. package/dist/core/runner/clock-and-limits.d.ts +15 -4
  387. package/dist/core/runner/clock-and-limits.js +19 -1
  388. package/dist/core/runner/compact-session.js +84 -14
  389. package/dist/core/runner/compaction-call-options.d.ts +2 -29
  390. package/dist/core/runner/compaction-call-options.js +2 -9
  391. package/dist/core/runner/compaction-restate.d.ts +18 -2
  392. package/dist/core/runner/compaction-restate.js +36 -2
  393. package/dist/core/runner/construction-doors.js +8 -0
  394. package/dist/core/runner/context-room.d.ts +55 -0
  395. package/dist/core/runner/context-room.js +71 -0
  396. package/dist/core/runner/contracts.d.ts +313 -205
  397. package/dist/core/runner/conversation-segment.d.ts +49 -14
  398. package/dist/core/runner/conversation-segment.js +92 -19
  399. package/dist/core/runner/cross-boundary-lane.d.ts +4 -0
  400. package/dist/core/runner/cross-boundary-lane.js +9 -6
  401. package/dist/core/runner/decide-continuation.js +1 -1
  402. package/dist/core/runner/deferred-ask.d.ts +62 -0
  403. package/dist/core/runner/deferred-ask.js +44 -0
  404. package/dist/core/runner/delegation-owner.d.ts +19 -0
  405. package/dist/core/runner/delegation-owner.js +27 -1
  406. package/dist/core/runner/denial-limit-arms.d.ts +10 -6
  407. package/dist/core/runner/denial-limit-arms.js +13 -7
  408. package/dist/core/runner/env-capability-census.d.ts +1 -1
  409. package/dist/core/runner/file-history-request.js +2 -1
  410. package/dist/core/runner/file-history-restore.d.ts +16 -2
  411. package/dist/core/runner/file-history-restore.js +9 -1
  412. package/dist/core/runner/gate-exit.d.ts +18 -5
  413. package/dist/core/runner/gate-exit.js +26 -15
  414. package/dist/core/runner/git-status-frame.d.ts +26 -8
  415. package/dist/core/runner/git-status-frame.js +14 -9
  416. package/dist/core/runner/halt-attribution.d.ts +29 -12
  417. package/dist/core/runner/halt-attribution.js +38 -11
  418. package/dist/core/runner/image.js +3 -2
  419. package/dist/core/runner/initial-run-state.d.ts +1 -1
  420. package/dist/core/runner/initial-run-state.js +4 -4
  421. package/dist/core/runner/language-frame.d.ts +66 -0
  422. package/dist/core/runner/language-frame.js +76 -0
  423. package/dist/core/runner/leg-frame.d.ts +81 -0
  424. package/dist/core/runner/leg-frame.js +68 -0
  425. package/dist/core/runner/main-call-account.d.ts +34 -0
  426. package/dist/core/runner/main-call-account.js +50 -0
  427. package/dist/core/runner/mcp-redial.d.ts +9 -7
  428. package/dist/core/runner/mcp-redial.js +20 -21
  429. package/dist/core/runner/memory-consolidation-driver.d.ts +2 -0
  430. package/dist/core/runner/memory-consolidation-driver.js +5 -3
  431. package/dist/core/runner/messages-omitted-seat.d.ts +2 -0
  432. package/dist/core/runner/messages-omitted-seat.js +21 -0
  433. package/dist/core/runner/model-fallback-seat.d.ts +23 -0
  434. package/dist/core/runner/model-fallback-seat.js +64 -0
  435. package/dist/core/runner/model-lane-seat.d.ts +12 -0
  436. package/dist/core/runner/model-lane-seat.js +35 -0
  437. package/dist/core/runner/nested-memory-content.d.ts +33 -0
  438. package/dist/core/runner/nested-memory-content.js +171 -0
  439. package/dist/core/runner/nested-memory-lane.d.ts +181 -0
  440. package/dist/core/runner/nested-memory-lane.js +673 -0
  441. package/dist/core/runner/park-commit.d.ts +7 -0
  442. package/dist/core/runner/park-commit.js +3 -0
  443. package/dist/core/runner/prepare-advisor.d.ts +7 -9
  444. package/dist/core/runner/prepare-advisor.js +11 -5
  445. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  446. package/dist/core/runner/prepare-artifact.js +8 -3
  447. package/dist/core/runner/prepare-ask-lane.d.ts +21 -3
  448. package/dist/core/runner/prepare-ask-lane.js +32 -28
  449. package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
  450. package/dist/core/runner/prepare-boundary-parks.js +21 -17
  451. package/dist/core/runner/prepare-caps-and-workflow.d.ts +10 -2
  452. package/dist/core/runner/prepare-caps-and-workflow.js +24 -18
  453. package/dist/core/runner/prepare-config-doors.d.ts +51 -5
  454. package/dist/core/runner/prepare-config-doors.js +73 -73
  455. package/dist/core/runner/prepare-context-lane.d.ts +68 -3
  456. package/dist/core/runner/prepare-context-lane.js +137 -27
  457. package/dist/core/runner/prepare-defer-classify.d.ts +0 -4
  458. package/dist/core/runner/prepare-defer-classify.js +9 -13
  459. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -8
  460. package/dist/core/runner/prepare-delegation-surface.js +72 -64
  461. package/dist/core/runner/prepare-execution-env.js +1 -9
  462. package/dist/core/runner/prepare-file-history.d.ts +3 -2
  463. package/dist/core/runner/prepare-file-history.js +11 -4
  464. package/dist/core/runner/prepare-gate-stations.d.ts +21 -11
  465. package/dist/core/runner/prepare-gate-stations.js +13 -13
  466. package/dist/core/runner/prepare-hands-readface.d.ts +23 -6
  467. package/dist/core/runner/prepare-hands-readface.js +18 -12
  468. package/dist/core/runner/prepare-inherited-gate.d.ts +12 -5
  469. package/dist/core/runner/prepare-inherited-gate.js +14 -10
  470. package/dist/core/runner/prepare-lsp.js +2 -1
  471. package/dist/core/runner/prepare-memory-engine-session.js +30 -10
  472. package/dist/core/runner/prepare-memory.d.ts +4 -0
  473. package/dist/core/runner/prepare-memory.js +38 -16
  474. package/dist/core/runner/prepare-offload-wrappers.d.ts +3 -16
  475. package/dist/core/runner/prepare-offload-wrappers.js +6 -5
  476. package/dist/core/runner/prepare-park-ask.d.ts +11 -3
  477. package/dist/core/runner/prepare-park-ask.js +23 -19
  478. package/dist/core/runner/prepare-policy-chain.d.ts +17 -3
  479. package/dist/core/runner/prepare-policy-chain.js +144 -120
  480. package/dist/core/runner/prepare-project-context.d.ts +15 -53
  481. package/dist/core/runner/prepare-project-context.js +20 -83
  482. package/dist/core/runner/prepare-prompt-assembly.d.ts +7 -1
  483. package/dist/core/runner/prepare-prompt-assembly.js +9 -7
  484. package/dist/core/runner/prepare-prompt-inputs.d.ts +9 -3
  485. package/dist/core/runner/prepare-prompt-inputs.js +5 -3
  486. package/dist/core/runner/prepare-protocol-tools.d.ts +9 -4
  487. package/dist/core/runner/prepare-protocol-tools.js +46 -27
  488. package/dist/core/runner/prepare-question-face.d.ts +6 -5
  489. package/dist/core/runner/prepare-question-face.js +7 -6
  490. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -0
  491. package/dist/core/runner/prepare-suspend-saga.js +1 -1
  492. package/dist/core/runner/prepare-task.d.ts +3 -3
  493. package/dist/core/runner/prepare-task.js +113 -61
  494. package/dist/core/runner/prepare-tool-disclosure-mount.js +6 -5
  495. package/dist/core/runner/prepare-turn-wiring.d.ts +33 -7
  496. package/dist/core/runner/prepare-turn-wiring.js +53 -17
  497. package/dist/core/runner/prepare-wiring-manifest.d.ts +42 -5
  498. package/dist/core/runner/prepare-wiring-manifest.js +81 -42
  499. package/dist/core/runner/prepare-workspace-restore.js +3 -2
  500. package/dist/core/runner/read-root-grant.js +2 -1
  501. package/dist/core/runner/reply-pricing.d.ts +31 -18
  502. package/dist/core/runner/reply-pricing.js +10 -15
  503. package/dist/core/runner/resume-admission.js +10 -15
  504. package/dist/core/runner/resume-apply.js +20 -9
  505. package/dist/core/runner/resume-checkpoint-screen.js +2 -4
  506. package/dist/core/runner/resume-internals-and-config.d.ts +12 -9
  507. package/dist/core/runner/resume-internals-and-config.js +37 -9
  508. package/dist/core/runner/resume-preflight.js +3 -3
  509. package/dist/core/runner/retired-runner-deps.js +3 -0
  510. package/dist/core/runner/rewind-files.js +6 -6
  511. package/dist/core/runner/run-attachment-seats.d.ts +1 -3
  512. package/dist/core/runner/run-attachment-seats.js +1 -6
  513. package/dist/core/runner/run-brain-sinks.d.ts +4 -7
  514. package/dist/core/runner/run-brain-sinks.js +7 -10
  515. package/dist/core/runner/run-clock-and-content.d.ts +8 -5
  516. package/dist/core/runner/run-clock-and-content.js +18 -3
  517. package/dist/core/runner/run-compaction-machinery.d.ts +8 -4
  518. package/dist/core/runner/run-compaction-machinery.js +4 -19
  519. package/dist/core/runner/run-git-lane.d.ts +8 -3
  520. package/dist/core/runner/run-git-lane.js +5 -3
  521. package/dist/core/runner/run-harness-handlers.d.ts +4 -1
  522. package/dist/core/runner/run-harness-handlers.js +70 -45
  523. package/dist/core/runner/run-identity-wiring.d.ts +6 -0
  524. package/dist/core/runner/run-identity-wiring.js +17 -8
  525. package/dist/core/runner/run-leg.d.ts +5 -2
  526. package/dist/core/runner/run-leg.js +156 -71
  527. package/dist/core/runner/run-notification-lane.d.ts +1 -1
  528. package/dist/core/runner/run-notification-lane.js +22 -10
  529. package/dist/core/runner/run-recovery-lanes.js +8 -6
  530. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -0
  531. package/dist/core/runner/run-settle-and-teardown.js +77 -26
  532. package/dist/core/runner/run-stop-and-final-verify.js +46 -12
  533. package/dist/core/runner/run-telemetry-and-budget-seats.js +19 -28
  534. package/dist/core/runner/run-terminal-adoption.d.ts +2 -2
  535. package/dist/core/runner/run-terminal-adoption.js +14 -9
  536. package/dist/core/runner/run-tool-mount-facts.js +5 -9
  537. package/dist/core/runner/run-turn-boundary.d.ts +3 -2
  538. package/dist/core/runner/run-turn-boundary.js +112 -106
  539. package/dist/core/runner/runtask.d.ts +28 -8
  540. package/dist/core/runner/runtask.js +132 -41
  541. package/dist/core/runner/session-file-state-replay.d.ts +5 -3
  542. package/dist/core/runner/session-file-state-replay.js +10 -3
  543. package/dist/core/runner/session-rule-policy.d.ts +3 -3
  544. package/dist/core/runner/session-verb-doors.d.ts +18 -3
  545. package/dist/core/runner/session-verb-doors.js +38 -6
  546. package/dist/core/runner/shell-env-withheld.d.ts +8 -5
  547. package/dist/core/runner/shell-env-withheld.js +4 -4
  548. package/dist/core/runner/side-call-account.d.ts +12 -8
  549. package/dist/core/runner/side-call-account.js +24 -15
  550. package/dist/core/runner/stream-halt-verbs.js +1 -0
  551. package/dist/core/runner/stream-mode-verb.js +2 -1
  552. package/dist/core/runner/stream-settle-backstop.js +4 -1
  553. package/dist/core/runner/stream-steer-verb.js +35 -19
  554. package/dist/core/runner/sub-agent-deny-lists.d.ts +47 -11
  555. package/dist/core/runner/sub-agent-deny-lists.js +140 -39
  556. package/dist/core/runner/teardown-bounded.d.ts +6 -0
  557. package/dist/core/runner/teardown-bounded.js +12 -7
  558. package/dist/core/runner/terminal-account.d.ts +2 -0
  559. package/dist/core/runner/terminal-account.js +6 -1
  560. package/dist/core/runner/tool-disclosure.js +2 -1
  561. package/dist/core/runner/tool-end-body.js +3 -1
  562. package/dist/core/runner/tool-face-overlay.d.ts +1 -1
  563. package/dist/core/runner/tool-face-overlay.js +1 -1
  564. package/dist/core/runner/tool-occurrence.d.ts +34 -9
  565. package/dist/core/runner/tool-occurrence.js +32 -21
  566. package/dist/core/runner/tool-progress-lane.d.ts +20 -5
  567. package/dist/core/runner/tool-progress-lane.js +27 -5
  568. package/dist/core/runner/tool-result-media-seat.d.ts +15 -4
  569. package/dist/core/runner/tool-result-media-seat.js +17 -1
  570. package/dist/core/runner/tool-table-view.js +1 -1
  571. package/dist/core/runner/turn-attachments.d.ts +44 -71
  572. package/dist/core/runner/turn-attachments.js +52 -104
  573. package/dist/core/runner/usage-accounting.d.ts +3 -2
  574. package/dist/core/runner/usage-accounting.js +3 -2
  575. package/dist/core/runner/void-verifier-pause.js +1 -1
  576. package/dist/core/runner-deps.d.ts +42 -158
  577. package/dist/core/runtime-caps.d.ts +16 -4
  578. package/dist/core/secret-env.d.ts +20 -3
  579. package/dist/core/secret-env.js +46 -23
  580. package/dist/core/sensitive-path-policy.d.ts +8 -0
  581. package/dist/core/sensitive-path-policy.js +10 -2
  582. package/dist/core/session-checkout.d.ts +32 -27
  583. package/dist/core/session-checkout.js +109 -61
  584. package/dist/core/session-log-transfer.js +2 -1
  585. package/dist/core/session-policy-store.d.ts +24 -11
  586. package/dist/core/session-policy-store.js +11 -2
  587. package/dist/core/session-store.d.ts +16 -2
  588. package/dist/core/session-store.js +43 -17
  589. package/dist/core/session.d.ts +31 -3
  590. package/dist/core/session.js +33 -2
  591. package/dist/core/shell-run-candidates.d.ts +20 -8
  592. package/dist/core/shell-run-candidates.js +44 -21
  593. package/dist/core/side-query.d.ts +17 -5
  594. package/dist/core/side-query.js +17 -14
  595. package/dist/core/skill-grant.js +2 -3
  596. package/dist/core/skills-directory.js +3 -66
  597. package/dist/core/snapshot-frame-seat.d.ts +8 -0
  598. package/dist/core/snapshot-frame-seat.js +24 -0
  599. package/dist/core/steer-replay.d.ts +19 -3
  600. package/dist/core/steer-replay.js +8 -1
  601. package/dist/core/store-contracts/background-agent-store-contract.d.ts +17 -2
  602. package/dist/core/store-contracts/background-agent-store-contract.js +131 -2
  603. package/dist/core/store-contracts/checkpoint-store-contract.js +63 -1
  604. package/dist/core/store-contracts/mailbox-store-contract.d.ts +15 -2
  605. package/dist/core/store-contracts/mailbox-store-contract.js +213 -3
  606. package/dist/core/store-contracts/permission-rule-write-contract.js +24 -0
  607. package/dist/core/store-contracts/session-deletion-cascade-contract.d.ts +15 -0
  608. package/dist/core/store-contracts/session-deletion-cascade-contract.js +288 -0
  609. package/dist/core/store-contracts/session-policy-store-contract.js +57 -36
  610. package/dist/core/store-contracts/session-repo-contract.js +130 -5
  611. package/dist/core/store-contracts/session-store-contract.d.ts +1 -1
  612. package/dist/core/store-contracts/session-store-contract.js +17 -0
  613. package/dist/core/store-contracts/task-list-store-contract.d.ts +32 -0
  614. package/dist/core/store-contracts/task-list-store-contract.js +240 -0
  615. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  616. package/dist/core/store-contracts/tool-result-store-contract.js +41 -0
  617. package/dist/core/stub-env.d.ts +2 -2
  618. package/dist/core/stub-env.js +1 -0
  619. package/dist/core/synthetic-read-verdict.d.ts +38 -28
  620. package/dist/core/synthetic-read-verdict.js +19 -28
  621. package/dist/core/task-event.d.ts +171 -19
  622. package/dist/core/task-intake.d.ts +26 -0
  623. package/dist/core/task-intake.js +31 -0
  624. package/dist/core/task-limits.d.ts +8 -6
  625. package/dist/core/task-notification.d.ts +88 -8
  626. package/dist/core/task-notification.js +45 -5
  627. package/dist/core/task-registry-agent.d.ts +24 -7
  628. package/dist/core/task-registry-agent.js +51 -28
  629. package/dist/core/task-registry-monitor.js +16 -14
  630. package/dist/core/task-registry-shared.d.ts +177 -35
  631. package/dist/core/task-registry-shared.js +44 -17
  632. package/dist/core/task-registry-workflow.js +8 -5
  633. package/dist/core/task-registry-yield.d.ts +32 -0
  634. package/dist/core/task-registry-yield.js +85 -0
  635. package/dist/core/task-registry.d.ts +88 -10
  636. package/dist/core/task-registry.js +124 -33
  637. package/dist/core/task-result.d.ts +126 -31
  638. package/dist/core/task-spec-members.d.ts +140 -1
  639. package/dist/core/task-spec-members.js +23 -8
  640. package/dist/core/task-spec.d.ts +181 -51
  641. package/dist/core/task-spec.js +1 -1
  642. package/dist/core/task-stream.d.ts +12 -2
  643. package/dist/core/terminal-cause.d.ts +12 -4
  644. package/dist/core/thrown-value.d.ts +49 -7
  645. package/dist/core/thrown-value.js +38 -2
  646. package/dist/core/tool-catalog-entries.js +13 -3
  647. package/dist/core/tool-data-door.d.ts +7 -0
  648. package/dist/core/tool-data-door.js +13 -0
  649. package/dist/core/tool-face-lists.d.ts +25 -0
  650. package/dist/core/tool-face-lists.js +38 -0
  651. package/dist/core/tool-face-reader.d.ts +0 -10
  652. package/dist/core/tool-face-reader.js +5 -3
  653. package/dist/core/tool-list-grammar.d.ts +103 -0
  654. package/dist/core/tool-list-grammar.js +130 -0
  655. package/dist/core/tool-mount-facts.d.ts +47 -0
  656. package/dist/core/tool-mount-facts.js +50 -0
  657. package/dist/core/tool-mount-plan.d.ts +196 -0
  658. package/dist/core/tool-mount-plan.js +404 -0
  659. package/dist/core/tool-mount-static.d.ts +12 -0
  660. package/dist/core/tool-mount-static.js +174 -0
  661. package/dist/core/tool-name-aliases.d.ts +60 -2
  662. package/dist/core/tool-name-aliases.js +22 -2
  663. package/dist/core/tool-name-list.d.ts +3 -0
  664. package/dist/core/tool-name-readings.d.ts +4 -0
  665. package/dist/core/tool-name-readings.js +1 -0
  666. package/dist/core/tool-policy.d.ts +246 -51
  667. package/dist/core/tool-policy.js +165 -71
  668. package/dist/core/tool-registry.d.ts +4 -11
  669. package/dist/core/tool-registry.js +0 -3
  670. package/dist/core/tool-result-bytes.d.ts +94 -0
  671. package/dist/core/tool-result-bytes.js +34 -0
  672. package/dist/core/tool-result-store.d.ts +97 -13
  673. package/dist/core/tool-result-store.js +52 -4
  674. package/dist/core/tool-roster.d.ts +71 -10
  675. package/dist/core/tool-roster.js +71 -21
  676. package/dist/core/tool-search-setting.d.ts +7 -9
  677. package/dist/core/tool-search-setting.js +23 -7
  678. package/dist/core/tool-spec.d.ts +32 -2
  679. package/dist/core/tools.js +6 -20
  680. package/dist/core/trace.d.ts +63 -11
  681. package/dist/core/trace.js +19 -0
  682. package/dist/core/types.d.ts +8 -6
  683. package/dist/core/types.js +3 -1
  684. package/dist/core/unmatched-tool-names.d.ts +37 -0
  685. package/dist/core/unmatched-tool-names.js +18 -0
  686. package/dist/core/untrusted-egress.d.ts +16 -5
  687. package/dist/core/untrusted-egress.js +202 -32
  688. package/dist/core/untrusted-text.d.ts +29 -8
  689. package/dist/core/untrusted-text.js +6 -3
  690. package/dist/core/user-attachment.d.ts +129 -35
  691. package/dist/core/user-attachment.js +124 -57
  692. package/dist/core/user-row-origin.d.ts +63 -0
  693. package/dist/core/user-row-origin.js +61 -0
  694. package/dist/core/wiring-manifest.d.ts +161 -39
  695. package/dist/core/wiring-manifest.js +42 -6
  696. package/dist/core/workflow-run-store-contract.d.ts +11 -1
  697. package/dist/core/workflow-run-store-contract.js +60 -7
  698. package/dist/core/workflow-run-store.d.ts +61 -12
  699. package/dist/core/workflow-run-store.js +100 -15
  700. package/dist/core/workspace-snapshot.d.ts +10 -14
  701. package/dist/core/workspace-snapshot.js +3 -22
  702. package/dist/core/write-protect.d.ts +3 -5
  703. package/dist/core/write-protect.js +2 -4
  704. package/dist/engine/compaction/compaction.d.ts +3 -0
  705. package/dist/engine/compaction/compaction.js +4 -3
  706. package/dist/engine/execution-env/node-execution-env.d.ts +15 -4
  707. package/dist/engine/execution-env/node-execution-env.js +80 -27
  708. package/dist/engine/harness/agent-harness.d.ts +143 -27
  709. package/dist/engine/harness/agent-harness.js +162 -74
  710. package/dist/engine/harness/types.d.ts +84 -13
  711. package/dist/engine/harness/types.js +21 -1
  712. package/dist/engine/llm/tool-turns.d.ts +4 -0
  713. package/dist/engine/llm/tool-turns.js +7 -2
  714. package/dist/engine/llm/types.d.ts +111 -24
  715. package/dist/engine/llm/types.js +69 -5
  716. package/dist/engine/llm/validation.js +2 -1
  717. package/dist/engine/loop/agent-loop.d.ts +39 -6
  718. package/dist/engine/loop/agent-loop.js +172 -82
  719. package/dist/engine/loop/types.d.ts +43 -4
  720. package/dist/engine/lsp/node-lsp-manager.d.ts +5 -3
  721. package/dist/engine/lsp/node-lsp-manager.js +14 -10
  722. package/dist/engine/session/import-validate.js +9 -0
  723. package/dist/engine/session/memory-repo.d.ts +8 -1
  724. package/dist/engine/session/memory-repo.js +20 -12
  725. package/dist/engine/session/repo-utils.d.ts +10 -0
  726. package/dist/engine/session/repo-utils.js +11 -5
  727. package/dist/engine/session/row-cells.d.ts +32 -0
  728. package/dist/engine/session/row-cells.js +25 -0
  729. package/dist/index.d.ts +64 -34
  730. package/dist/index.js +45 -21
  731. package/dist/internal/harness.d.ts +8 -6
  732. package/dist/internal/harness.js +6 -4
  733. package/dist/internal/llm.d.ts +2 -2
  734. package/dist/internal/llm.js +1 -1
  735. package/dist/orchestration/governance-baseline-validity.d.ts +7 -0
  736. package/dist/orchestration/governance-baseline-validity.js +33 -9
  737. package/dist/orchestration/run-workflow-tool.d.ts +2 -0
  738. package/dist/orchestration/run-workflow-tool.js +25 -12
  739. package/dist/orchestration/workflow-governance.d.ts +19 -4
  740. package/dist/orchestration/workflow-governance.js +30 -9
  741. package/dist/orchestration/workflow-primitives.d.ts +4 -1
  742. package/dist/orchestration/workflow-primitives.js +2 -2
  743. package/dist/orchestration/workflow-script-runner.d.ts +1 -1
  744. package/dist/orchestration/workflow-size-guideline.d.ts +1 -1
  745. package/dist/orchestration/workflow-types.d.ts +21 -12
  746. package/dist/orchestration/workflow-types.js +15 -4
  747. package/dist/orchestration/workflow.d.ts +37 -7
  748. package/dist/orchestration/workflow.js +81 -35
  749. package/dist/prompt-assembly/artifact-store.js +6 -9
  750. package/dist/prompt-assembly/assemble.d.ts +4 -10
  751. package/dist/prompt-assembly/assemble.js +1 -3
  752. package/dist/prompt-assembly/catalog/constitution.d.ts +0 -20
  753. package/dist/prompt-assembly/catalog/constitution.js +2 -0
  754. package/dist/prompt-assembly/catalog/core-behavior.js +5 -3
  755. package/dist/prompt-assembly/catalog/engine.d.ts +108 -0
  756. package/dist/prompt-assembly/catalog/engine.js +19 -0
  757. package/dist/prompt-assembly/catalog/environment.d.ts +276 -0
  758. package/dist/prompt-assembly/catalog/environment.js +61 -0
  759. package/dist/prompt-assembly/catalog/index.d.ts +9 -2
  760. package/dist/prompt-assembly/catalog/index.js +73 -2
  761. package/dist/prompt-assembly/catalog/locales/index.d.ts +16 -0
  762. package/dist/prompt-assembly/catalog/locales/index.js +22 -0
  763. package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.d.ts +7 -0
  764. package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.js +124 -0
  765. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.d.ts +6 -0
  766. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +120 -0
  767. package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.d.ts +8 -0
  768. package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.js +442 -0
  769. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +7 -0
  770. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +15 -0
  771. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.d.ts +7 -0
  772. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +50 -0
  773. package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.d.ts +7 -0
  774. package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.js +163 -0
  775. package/dist/prompt-assembly/catalog/locales/zh-Hans/role.d.ts +7 -0
  776. package/dist/prompt-assembly/catalog/locales/zh-Hans/role.js +148 -0
  777. package/dist/prompt-assembly/catalog/locales/zh-Hans/team.d.ts +6 -0
  778. package/dist/prompt-assembly/catalog/locales/zh-Hans/team.js +246 -0
  779. package/dist/prompt-assembly/catalog/role.js +3 -6
  780. package/dist/prompt-assembly/catalog/schema.d.ts +23 -1
  781. package/dist/prompt-assembly/catalog/schema.js +2 -0
  782. package/dist/prompt-assembly/composer.d.ts +6 -11
  783. package/dist/prompt-assembly/composer.js +7 -7
  784. package/dist/prompt-assembly/engine-text.d.ts +9 -0
  785. package/dist/prompt-assembly/engine-text.js +33 -0
  786. package/dist/prompt-assembly/event-registry.js +3 -3
  787. package/dist/prompt-assembly/explain.d.ts +1 -0
  788. package/dist/prompt-assembly/explain.js +1 -1
  789. package/dist/prompt-assembly/locale-review.d.ts +13 -0
  790. package/dist/prompt-assembly/locale-review.js +19 -0
  791. package/dist/prompt-assembly/overlay.d.ts +7 -3
  792. package/dist/prompt-assembly/overlay.js +27 -5
  793. package/dist/prompt-assembly/renderers.d.ts +4 -4
  794. package/dist/prompt-assembly/renderers.js +26 -17
  795. package/dist/prompt-assembly/role-base.d.ts +1 -1
  796. package/dist/prompt-assembly/select.d.ts +26 -5
  797. package/dist/prompt-assembly/select.js +25 -2
  798. package/dist/prompt-assembly/slots.d.ts +19 -0
  799. package/dist/prompt-assembly/slots.js +16 -0
  800. package/dist/prompt-assembly/sugar.d.ts +4 -7
  801. package/dist/prompt-assembly/sugar.js +1 -2
  802. package/dist/prompt-assembly/tool-catalog.d.ts +5 -1
  803. package/dist/prompt-assembly/tool-catalog.js +5 -1
  804. package/dist/prompt-assembly/turn-snapshot.d.ts +38 -10
  805. package/dist/prompt-assembly/turn-snapshot.js +43 -13
  806. package/dist/prompt-assembly/types.d.ts +3 -0
  807. package/dist/prompts/cowork.d.ts +6 -25
  808. package/dist/prompts/cowork.js +10 -12
  809. package/dist/prompts/default.d.ts +10 -32
  810. package/dist/prompts/default.js +37 -63
  811. package/dist/shell/lex.d.ts +39 -13
  812. package/dist/shell/lex.js +70 -30
  813. package/dist/stores/file/background-agent-store.d.ts +5 -0
  814. package/dist/stores/file/background-agent-store.js +35 -61
  815. package/dist/stores/file/checkpoint-store.d.ts +5 -3
  816. package/dist/stores/file/checkpoint-store.js +8 -10
  817. package/dist/stores/file/fs-atomic.d.ts +27 -70
  818. package/dist/stores/file/fs-atomic.js +52 -148
  819. package/dist/stores/file/index.d.ts +12 -0
  820. package/dist/stores/file/index.js +27 -2
  821. package/dist/stores/file/mailbox-store.d.ts +10 -1
  822. package/dist/stores/file/mailbox-store.js +40 -12
  823. package/dist/stores/file/permission-rule-adopt.js +5 -2
  824. package/dist/stores/file/permission-rule-store.d.ts +81 -20
  825. package/dist/stores/file/permission-rule-store.js +126 -33
  826. package/dist/stores/file/session-policy-store.d.ts +2 -2
  827. package/dist/stores/file/session-store.d.ts +21 -2
  828. package/dist/stores/file/session-store.js +27 -14
  829. package/dist/stores/file/task-list-store.js +23 -25
  830. package/dist/stores/file/tool-result-store.d.ts +45 -7
  831. package/dist/stores/file/tool-result-store.js +99 -36
  832. package/dist/stores/file/workflow-run-store.d.ts +1 -0
  833. package/dist/stores/file/workflow-run-store.js +14 -11
  834. package/dist/tools/artifact/artifact-tool.js +2 -0
  835. package/dist/tools/artifact/local-stub.js +6 -6
  836. package/dist/tools/fs/bash-program-position.d.ts +1 -2
  837. package/dist/tools/fs/bash-readonly-classifier.d.ts +35 -0
  838. package/dist/tools/fs/bash-readonly-classifier.js +50 -12
  839. package/dist/tools/fs/env-error-detail.d.ts +1 -0
  840. package/dist/tools/fs/env-error-detail.js +7 -0
  841. package/dist/tools/fs/fs-bash.d.ts +24 -6
  842. package/dist/tools/fs/fs-bash.js +73 -25
  843. package/dist/tools/fs/fs-pdf.js +6 -4
  844. package/dist/tools/fs/fs-read.d.ts +76 -31
  845. package/dist/tools/fs/fs-read.js +159 -79
  846. package/dist/tools/fs/fs-search-tools.d.ts +1 -1
  847. package/dist/tools/fs/fs-search-tools.js +3 -1
  848. package/dist/tools/fs/fs-shared.d.ts +59 -63
  849. package/dist/tools/fs/fs-shared.js +31 -18
  850. package/dist/tools/fs/fs-write.d.ts +13 -0
  851. package/dist/tools/fs/fs-write.js +69 -13
  852. package/dist/tools/fs/index.d.ts +19 -1
  853. package/dist/tools/fs/index.js +10 -2
  854. package/dist/tools/fs/pdf.js +10 -9
  855. package/dist/tools/fs/read-deny.js +4 -10
  856. package/dist/tools/fs/read-floor.d.ts +5 -4
  857. package/dist/tools/fs/removal-targets.d.ts +11 -5
  858. package/dist/tools/fs/removal-targets.js +62 -32
  859. package/dist/tools/fs/safety.d.ts +26 -19
  860. package/dist/tools/fs/safety.js +13 -8
  861. package/dist/tools/fs/search.d.ts +1 -1
  862. package/dist/tools/fs/shell-read-argv.js +1 -0
  863. package/dist/tools/fs/shell-read-bindings.d.ts +128 -26
  864. package/dist/tools/fs/shell-read-bindings.js +667 -139
  865. package/dist/tools/fs/shell-read-check.js +1 -1
  866. package/dist/tools/fs/shell-read-judge.d.ts +4 -1
  867. package/dist/tools/fs/shell-read-judge.js +5 -1
  868. package/dist/tools/fs/shell-read-plan.d.ts +4 -0
  869. package/dist/tools/fs/shell-read-plan.js +21 -19
  870. package/dist/tools/fs/shell-read-sourced.d.ts +4 -3
  871. package/dist/tools/fs/shell-read-sourced.js +18 -1
  872. package/dist/tools/fs/shell-read-start.d.ts +6 -6
  873. package/dist/tools/fs/shell-read-start.js +1 -6
  874. package/dist/tools/fs/shell-read-word.d.ts +4 -2
  875. package/dist/tools/fs/shell-read-word.js +7 -6
  876. package/dist/tools/fs/shell-read-workdir.d.ts +1 -1
  877. package/dist/tools/fs/shell-reentry-text.d.ts +24 -9
  878. package/dist/tools/fs/shell-reentry-text.js +50 -20
  879. package/dist/tools/monitor.d.ts +4 -0
  880. package/dist/tools/monitor.js +14 -4
  881. package/dist/tools/scheduler-tools.d.ts +5 -2
  882. package/dist/tools/scheduler-tools.js +8 -6
  883. package/dist/tools/task-list.d.ts +49 -20
  884. package/dist/tools/task-list.js +115 -35
  885. package/dist/tools/web.d.ts +13 -3
  886. package/dist/tools/web.js +17 -6
  887. package/dist/tools/worktree.d.ts +3 -2
  888. package/dist/tools/worktree.js +24 -25
  889. package/package.json +10 -3
  890. package/test/export-surface.snapshot.json +340 -32
  891. package/wire-changes/core-stores-sql@7.67.0.json +39 -0
  892. package/wire-changes/core-stores-sql@7.67.1.json +39 -0
  893. package/wire-changes/core@7.67.0.json +12578 -0
  894. package/wire-changes/core@7.67.1.json +406 -0
  895. package/wire-changes/mods-kernel@7.67.0.json +167 -0
  896. package/wire-changes/mods-kernel@7.67.1.json +39 -0
  897. package/wire-changes/primitives@7.67.0.json +325 -0
  898. package/wire-changes/primitives@7.67.1.json +39 -0
  899. package/wire-changes/wiki-gate@7.67.0.json +1636 -0
  900. package/wire-changes/wiki-gate@7.67.1.json +39 -0
  901. package/dist/brain/degrading.d.ts +0 -93
  902. package/dist/brain/degrading.js +0 -189
  903. package/dist/core/tool-conformance.d.ts +0 -20
  904. package/dist/core/tool-conformance.js +0 -37
@@ -0,0 +1,169 @@
1
+ /**
2
+ * The MODEL LANE — the one walk of a model request's fallback chain (the rule is stated in `core/model-fallbacks.ts`: the
3
+ * requested catalog entry, then the entries its `Model.fallbacks` words name; every hop served by the deployment's own Brain;
4
+ * only a failure before the first content, for a reason the gate admits, moves the request to the next hop).
5
+ *
6
+ * The lane is the Runner's Brain seat: `RunnerDeps.brain` wrapped once (`core/runner/model-lane-seat.ts` is the one accessor
7
+ * every engine read of the seat goes through), so the main loop and every side lane (compaction, the permission classifier, a
8
+ * side query, a mod's model call, the advisor) walk the same chain. A request for a model with no chain is the deployment
9
+ * Brain's own call, unchanged — the stream, the message and the error are exactly what the Brain answered.
10
+ *
11
+ * The three faces of the Brain contract:
12
+ * - `stream` walks hop by hop. Each hop's leading `start` and block-opening events are HELD; the first other event (a delta, a
13
+ * block end — content) commits the request to that hop, and from then on its outcome is the request's, success or failure
14
+ * (nothing is replayed: no tool runs twice, no text is said twice). A hop that is not the chain's last may carry the
15
+ * deployment's first-token deadline (`RunnerDeps.modelFallback.firstTokenMs`): it races every wait on the hop (the stream
16
+ * promise, each step, `result()`) and, when it fires, aborts the hop's signal with a coded `network` failure — a circuit
17
+ * breaker inside the deployment Brain counts it — and leaves the hop whatever the Brain does next.
18
+ * - `complete` is always present. A walked request walks the face its policy needs: the stream (above, read to its final
19
+ * message) when the policy sets a first-token deadline — a deadline is a fact about a stream's events — and otherwise the
20
+ * deployment Brain's non-streaming face hop by hop ({@link completeOf}: its own `complete`, else its stream read to its result),
21
+ * returning the hop's message as the Brain answered it (its `errorKind` included).
22
+ * - `adjudicateRoute` is the deployment Brain's own (the requested model is served first); each later hop is judged by it
23
+ * before it is dispatched, and a hop whose pairing it refuses is skipped — never sent, and named on the answer's marker with the
24
+ * refusal code (`skipped`).
25
+ *
26
+ * Hops other than the first are dispatched without the request's per-call identity (`apiKey`, `headers`, `metadata`): those
27
+ * were resolved for the requested model, and a hop is served with what the deployment Brain holds for the hop's own model.
28
+ *
29
+ * A walked request's answer carries a marker diagnostic ({@link DEGRADED_DIAGNOSTIC_TYPE}): who asked, which hops were tried,
30
+ * which were refused before dispatch, why the walk began, whether a hop served or the chain was exhausted, and which hop's message this is. An exhausted chain
31
+ * answers the FIRST hop's own terminal: the requested model's failure is the one its caller's recovery is built for.
32
+ *
33
+ * Every request an answer left behind on its way rides the answer in ONE diagnostic ({@link LEFT_BEHIND_DIAGNOSTIC_TYPE}): the
34
+ * hops the lane walked past and the gateways the failover decorator moved off, each with the usage its own message reported —
35
+ * every attempt is billed once, at its own model's price ({@link servedReadingOf}). The answer's own `usage` stays the answer's
36
+ * (the context reading of the next request is that message's).
37
+ */
38
+ import { type AssistantMessage, type AssistantMessageDiagnostic, type AssistantMessageEvent, type Model, type Usage } from "../internal/llm.js";
39
+ import type { Brain } from "../core/types.js";
40
+ import { type DegradeReason, type HopGate, type ReceivedModelFallbackPolicy } from "../core/model-fallbacks.js";
41
+ export { DEGRADE_REASONS, type DegradeReason } from "../core/model-fallbacks.js";
42
+ /** The `type` of the marker diagnostic a walked request's answer carries. */
43
+ export declare const DEGRADED_DIAGNOSTIC_TYPE = "degraded";
44
+ /** How a walk ended: a hop after the first served the request, or no hop did (the first hop's terminal is the answer). */
45
+ export type FallbackOutcome = "served" | "exhausted";
46
+ /** The `type` of the diagnostic that lists the requests an answer left behind on its way. */
47
+ export declare const LEFT_BEHIND_DIAGNOSTIC_TYPE = "left_behind";
48
+ /** One request an answer left behind on its way — a hop the lane walked past, a gateway the failover decorator moved off: the model
49
+ * it asked for and the usage its own message reported (`usageMissing` when it reported none the engine can trust — a request cut at
50
+ * its deadline, a request whose Brain threw, an entry of a list that did not read). `model` is `""` for a request no one can name. */
51
+ export interface LeftRequest {
52
+ model: string;
53
+ usage: Usage;
54
+ usageMissing?: true;
55
+ }
56
+ /** The marker, as read back off an answer. */
57
+ export interface DegradationInfo {
58
+ /** The requested model's id. */
59
+ from: string;
60
+ /** The last hop tried (the hop that served, for `served`). */
61
+ to: string;
62
+ /** Why the request left the first hop. */
63
+ reason: DegradeReason;
64
+ /** The hops tried after the first, in order. */
65
+ chain?: string[];
66
+ /** How the walk ended (absent on a marker that does not state it). */
67
+ outcome?: FallbackOutcome;
68
+ /** Whose message the answer is: `to` when a hop served, `from` when the chain was exhausted. */
69
+ answeredBy?: string;
70
+ /** The later hops the deployment Brain's route judgment refused before they were dispatched, in chain order — each the
71
+ * model it names and the refusal code the judgment stated (absent when it stated none). Absent when no hop was refused. */
72
+ skipped?: SkippedHop[];
73
+ }
74
+ /** A hop of a walk the deployment Brain's route judgment refused before dispatch: never sent, never billed. */
75
+ export interface SkippedHop {
76
+ model: string;
77
+ code?: string;
78
+ }
79
+ /** The `type` of the diagnostic a request's answer carries when its walk began and every later hop was refused before dispatch:
80
+ * no hop was tried, so the answer is the requested model's own and carries no marker — this says why none was tried. */
81
+ export declare const FALLBACK_UNSENT_DIAGNOSTIC_TYPE = "fallback_unsent";
82
+ /** A walk that sent no hop, as read back off an answer: the requested model's id, why the request left it, and the hops refused. */
83
+ export interface FallbackUnsent {
84
+ from: string;
85
+ reason: DegradeReason;
86
+ skipped: SkippedHop[];
87
+ }
88
+ /**
89
+ * The marker off an answer, or `undefined`. Strict on every member: a marker whose required members do not parse, or whose
90
+ * optional members are present and malformed, is not read at all (a half-read marker would bill some hops and drop others). An
91
+ * optional member that would not read is not an absent one — it comes back unreadable and fails the shape check like any malformed one.
92
+ */
93
+ export declare function readDegradation(msg: {
94
+ diagnostics?: AssistantMessageDiagnostic[];
95
+ } | undefined): DegradationInfo | undefined;
96
+ /** The walk that sent no hop off an answer ({@link FALLBACK_UNSENT_DIAGNOSTIC_TYPE}), or `undefined` — strict on every member, as the marker is. */
97
+ export declare function readFallbackUnsent(msg: {
98
+ diagnostics?: AssistantMessageDiagnostic[];
99
+ } | undefined): FallbackUnsent | undefined;
100
+ /**
101
+ * What a request left behind stands for in the list of the answer that moved past it: the requests IT left behind (its own list —
102
+ * a gateway the failover decorator moved off before this hop failed too), then itself, at the model it asked for. A message that
103
+ * reported no usage the engine can read is listed with a zero usage marked as a lower bound.
104
+ */
105
+ export declare function leftEntriesOf(msg: AssistantMessage, model: string): LeftRequest[];
106
+ /** The answer carries the requests left behind on its way: its own list (the requests it left behind itself), then `left`. */
107
+ export declare function carryLeftBehind(msg: AssistantMessage, left: readonly LeftRequest[]): void;
108
+ /** Who answered one message of a request for `requested`, and the requests billed beside it — each resolved to its `Model`. */
109
+ export interface ServedReading {
110
+ /** The model whose message this is. */
111
+ readonly served: Model;
112
+ /** The requests the answer left behind on its way, each billed at its own model's price. */
113
+ readonly attempts: readonly {
114
+ readonly model: Model;
115
+ readonly usage: Usage;
116
+ readonly usageMissing?: true;
117
+ }[];
118
+ /** The marker, when the answer is a walked request's. */
119
+ readonly degraded?: DegradationInfo;
120
+ /** The walk that began and sent no hop (every later hop refused before dispatch), when the answer is such a request's own. */
121
+ readonly unsent?: FallbackUnsent;
122
+ }
123
+ /**
124
+ * THE reading every accounting point makes of an answer: which model answered and which requests were left behind beside it,
125
+ * resolved over the chain the catalog door resolved for `requested` (ids are unique along a chain — the door refuses a repeat).
126
+ * The two are read independently: an answer the failover decorator served after moving off a gateway lists what it left behind
127
+ * with no marker at all. A marker that does not belong to this request (it names another requested model, or a hop the chain does
128
+ * not hold) is not this lane's and is not read: the message is the requested model's own. The list is read entry by entry: an entry
129
+ * the chain holds is billed at its model with the usage it reported; an entry that does not read whole, or names a model the chain
130
+ * does not hold, bills nothing priced and is booked as a lower bound at the requested model — what the account cannot price it says
131
+ * it is short of, rather than leaving it out.
132
+ */
133
+ export declare function servedReadingOf(requested: Model, msg: {
134
+ diagnostics?: AssistantMessageDiagnostic[];
135
+ } | undefined): ServedReading;
136
+ /**
137
+ * The terminal for a request whose Brain threw (or whose stream broke its protocol) instead of answering: the request was handed
138
+ * to the Brain, so what it cost is unknown — the usage is a lower bound (`usageMissing`), never a known zero.
139
+ */
140
+ export declare function errorMessageOf(model: Model, e: unknown, aborted: boolean): AssistantMessage;
141
+ /** The terminal event of a message: an error frame for an error / aborted message, else `done`. */
142
+ export declare function terminalOf(message: AssistantMessage): AssistantMessageEvent;
143
+ /** The message a terminal event carries (the one to tag and to read). */
144
+ export declare function terminalMessage(terminal: AssistantMessageEvent, fallback: AssistantMessage): AssistantMessage;
145
+ /** Whether a message carries content (the `complete` face's reading of "after the first content"). */
146
+ export declare function carriesContent(msg: AssistantMessage): boolean;
147
+ /**
148
+ * The gate's reading of one hop's outcome, over one row of the hop gate ({@link HopGate}): the reason word that moves the request
149
+ * to the next hop, `"next"` for a move that carries no reason word of its own (a non-first hop's `invalid_request` — a fact about
150
+ * that hop, not about the request — and any failure a row that admits every failure lets through), or `undefined` — the walk stops
151
+ * here. Never moves, whatever the row: a hop that committed (content reached the caller), a caller's abort, `length_empty`, an
152
+ * image or tool schema the provider refused (`errorKind`; the caller's request view repairs it). Never moves a reason-word row: a
153
+ * first hop's `invalid_request`, `refusal`, and a failure the Brain stated no code for (it did not classify it; the lane does not
154
+ * guess).
155
+ */
156
+ export declare function gateReadingOf(msg: AssistantMessage, hop: number, expired: boolean, callerAborted: boolean, gate: HopGate): DegradeReason | "next" | undefined;
157
+ /**
158
+ * The model lane over a deployment Brain and a received fallback policy — one Brain per (Brain, policy) pair, so every read of
159
+ * the seat answers the same object. A request whose model has no chain is the inner Brain's own call; so is a request whose
160
+ * options stand resilience down (`resilience.allowDegrade: false`). A lane handed in is answered as it is: a chain is walked
161
+ * once, by one lane, and every hop is the deployment Brain's own call.
162
+ */
163
+ export declare function modelLaneBrain(inner: Brain, policy?: ReceivedModelFallbackPolicy): Brain;
164
+ /**
165
+ * A pass-through of one Brain's stream that keeps the stream protocol whatever the Brain does: a Brain that rejects, or a stream
166
+ * that ends with no terminal event, still leaves one error terminal (otherwise `result()` would never settle and the caller
167
+ * would hang).
168
+ */
169
+ export declare function passthroughStream(brain: Brain, model: Model, context: Parameters<Brain["stream"]>[1], options: Parameters<Brain["stream"]>[2]): ReturnType<Brain["stream"]>;
@@ -0,0 +1,505 @@
1
+ import { createAssistantMessageEventStream, } from "../internal/llm.js";
2
+ import { completeOf } from "./brain-faces.js";
3
+ import { abortLikeName, BrainError, extractErrorCode, ZERO_USAGE } from "./errors.js";
4
+ import { CIRCUIT_OPEN_MARKER } from "./circuit-breaker.js";
5
+ import { armBrainCallDeadline } from "./timeout.js";
6
+ import { isExactCount, reasoningTokensOf } from "./usage-reasoning.js";
7
+ import { readElements, readMember, readMemberOrUnreadable, thrownText } from "../core/thrown-value.js";
8
+ import { ANY_HOP_FAILURE, DEFAULT_MODEL_FALLBACK_POLICY, hopGateAdmits, isDegradeReason, modelFallbackChainOf, } from "../core/model-fallbacks.js";
9
+ export { DEGRADE_REASONS } from "../core/model-fallbacks.js";
10
+ export const DEGRADED_DIAGNOSTIC_TYPE = "degraded";
11
+ export const LEFT_BEHIND_DIAGNOSTIC_TYPE = "left_behind";
12
+ export const FALLBACK_UNSENT_DIAGNOSTIC_TYPE = "fallback_unsent";
13
+ function readUsage(raw) {
14
+ const num = (v) => typeof v === "number" && Number.isFinite(v);
15
+ const input = readMember(raw, "input");
16
+ const output = readMember(raw, "output");
17
+ const cacheRead = readMemberOrUnreadable(raw, "cacheRead");
18
+ const cacheWrite = readMemberOrUnreadable(raw, "cacheWrite");
19
+ const cacheWriteLong = readMemberOrUnreadable(raw, "cacheWriteLong");
20
+ const totalTokens = readMember(raw, "totalTokens");
21
+ const reasoning = readMemberOrUnreadable(raw, "reasoning");
22
+ const cost = readMember(raw, "cost");
23
+ const costInput = readMember(cost, "input");
24
+ const costOutput = readMember(cost, "output");
25
+ const costCacheRead = readMember(cost, "cacheRead");
26
+ const costCacheWrite = readMember(cost, "cacheWrite");
27
+ const costTotal = readMember(cost, "total");
28
+ const optionalCount = (v) => v === undefined || isExactCount(v);
29
+ if (!(isExactCount(input) && isExactCount(output) && optionalCount(cacheRead) && optionalCount(cacheWrite) && optionalCount(cacheWriteLong) && isExactCount(totalTokens)))
30
+ return undefined;
31
+ if (cacheWriteLong !== undefined && (cacheWrite === undefined || cacheWriteLong > cacheWrite))
32
+ return undefined;
33
+ if (!(num(costInput) && num(costOutput) && num(costCacheRead) && num(costCacheWrite) && num(costTotal)))
34
+ return undefined;
35
+ const reading = reasoningTokensOf(output, reasoning);
36
+ if (reading.unreadable)
37
+ return undefined;
38
+ return { input, output, ...(cacheRead !== undefined ? { cacheRead } : {}), ...(cacheWrite !== undefined ? { cacheWrite } : {}), ...(cacheWriteLong !== undefined ? { cacheWriteLong } : {}), totalTokens, ...(reading.reasoning !== undefined ? { reasoning: reading.reasoning } : {}), cost: { input: costInput, output: costOutput, cacheRead: costCacheRead, cacheWrite: costCacheWrite, total: costTotal } };
39
+ }
40
+ function diagnosticOf(msg, type) {
41
+ for (const d of readElements(readMember(msg, "diagnostics")) ?? []) {
42
+ if (readMember(d, "type") === type)
43
+ return { details: readMember(d, "details") };
44
+ }
45
+ return undefined;
46
+ }
47
+ function putDiagnostic(msg, diag, replaces = []) {
48
+ const others = (readElements(readMember(msg, "diagnostics")) ?? []).filter((d) => {
49
+ const t = readMember(d, "type");
50
+ return t !== diag.type && !(typeof t === "string" && replaces.includes(t));
51
+ });
52
+ msg.diagnostics = [...others, diag];
53
+ }
54
+ export function readDegradation(msg) {
55
+ const det = diagnosticOf(msg, DEGRADED_DIAGNOSTIC_TYPE)?.details;
56
+ if (typeof det !== "object" || det === null)
57
+ return undefined;
58
+ const from = readMember(det, "from");
59
+ const to = readMember(det, "to");
60
+ const reason = readMember(det, "reason");
61
+ const chain = readMemberOrUnreadable(det, "chain");
62
+ const outcome = readMemberOrUnreadable(det, "outcome");
63
+ const answeredBy = readMemberOrUnreadable(det, "answeredBy");
64
+ const skippedList = readMemberOrUnreadable(det, "skipped");
65
+ if (typeof from !== "string" || typeof to !== "string" || !isDegradeReason(reason))
66
+ return undefined;
67
+ const hops = chain === undefined ? undefined : readElements(chain);
68
+ if (chain !== undefined && !(hops !== undefined && hops.every((c) => typeof c === "string")))
69
+ return undefined;
70
+ if (outcome !== undefined && outcome !== "served" && outcome !== "exhausted")
71
+ return undefined;
72
+ if (answeredBy !== undefined && typeof answeredBy !== "string")
73
+ return undefined;
74
+ const skipped = skippedList === undefined ? undefined : readSkippedHops(skippedList);
75
+ if (skipped === null)
76
+ return undefined;
77
+ return {
78
+ from,
79
+ to,
80
+ reason,
81
+ ...(hops !== undefined ? { chain: hops } : {}),
82
+ ...(outcome !== undefined ? { outcome } : {}),
83
+ ...(answeredBy !== undefined ? { answeredBy } : {}),
84
+ ...(skipped !== undefined ? { skipped } : {}),
85
+ };
86
+ }
87
+ function readSkippedHops(list) {
88
+ const entries = readElements(list);
89
+ if (entries === undefined)
90
+ return null;
91
+ const skipped = [];
92
+ for (const entry of entries) {
93
+ const model = readMember(entry, "model");
94
+ const code = readMemberOrUnreadable(entry, "code");
95
+ if (typeof model !== "string" || (code !== undefined && typeof code !== "string"))
96
+ return null;
97
+ skipped.push({ model, ...(code !== undefined ? { code } : {}) });
98
+ }
99
+ return skipped;
100
+ }
101
+ export function readFallbackUnsent(msg) {
102
+ const det = diagnosticOf(msg, FALLBACK_UNSENT_DIAGNOSTIC_TYPE)?.details;
103
+ if (typeof det !== "object" || det === null)
104
+ return undefined;
105
+ const from = readMember(det, "from");
106
+ const reason = readMember(det, "reason");
107
+ const skipped = readSkippedHops(readMember(det, "skipped"));
108
+ if (typeof from !== "string" || !isDegradeReason(reason) || skipped === null || skipped.length === 0)
109
+ return undefined;
110
+ return { from, reason, skipped };
111
+ }
112
+ const reportsKnownUsage = (flag) => flag === undefined || flag === false;
113
+ const unplacedRequest = () => ({ model: "", usage: ZERO_USAGE, usageMissing: true });
114
+ function readLeftRequest(raw) {
115
+ const model = readMember(raw, "model");
116
+ if (typeof model !== "string")
117
+ return unplacedRequest();
118
+ const usage = readUsage(readMember(raw, "usage"));
119
+ const known = usage !== undefined && reportsKnownUsage(readMemberOrUnreadable(raw, "usageMissing"));
120
+ return { model, usage: usage ?? ZERO_USAGE, ...(known ? {} : { usageMissing: true }) };
121
+ }
122
+ function readLeftBehind(msg) {
123
+ const diagnostic = diagnosticOf(msg, LEFT_BEHIND_DIAGNOSTIC_TYPE);
124
+ if (diagnostic === undefined)
125
+ return undefined;
126
+ const requests = readElements(readMember(diagnostic.details, "requests"));
127
+ return requests === undefined ? [unplacedRequest()] : requests.map(readLeftRequest);
128
+ }
129
+ export function leftEntriesOf(msg, model) {
130
+ const own = readUsage(readMember(msg, "usage"));
131
+ const known = own !== undefined && reportsKnownUsage(readMemberOrUnreadable(msg, "usageMissing"));
132
+ return [...(readLeftBehind(msg) ?? []), { model, usage: own ?? ZERO_USAGE, ...(known ? {} : { usageMissing: true }) }];
133
+ }
134
+ export function carryLeftBehind(msg, left) {
135
+ if (left.length === 0)
136
+ return;
137
+ putDiagnostic(msg, { type: LEFT_BEHIND_DIAGNOSTIC_TYPE, timestamp: Date.now(), details: { requests: [...(readLeftBehind(msg) ?? []), ...left] } });
138
+ }
139
+ export function servedReadingOf(requested, msg) {
140
+ const hops = [requested, ...modelFallbackChainOf(requested)];
141
+ const byId = (id) => hops.find((h) => h.id === id);
142
+ const attempts = (readLeftBehind(msg) ?? []).map((r) => {
143
+ const model = byId(r.model);
144
+ return model === undefined
145
+ ? { model: requested, usage: ZERO_USAGE, usageMissing: true }
146
+ : { model, usage: r.usage, ...(r.usageMissing === true ? { usageMissing: true } : {}) };
147
+ });
148
+ const marker = readDegradation(msg);
149
+ const served = marker !== undefined && marker.from === requested.id ? byId(marker.answeredBy ?? marker.to) : undefined;
150
+ if (served !== undefined && marker !== undefined)
151
+ return { served, attempts, degraded: marker };
152
+ const unsent = readFallbackUnsent(msg);
153
+ return unsent !== undefined && unsent.from === requested.id ? { served: requested, attempts, unsent } : { served: requested, attempts };
154
+ }
155
+ function tagUnsent(msg, info) {
156
+ putDiagnostic(msg, { type: FALLBACK_UNSENT_DIAGNOSTIC_TYPE, timestamp: Date.now(), details: { from: info.from, reason: info.reason, skipped: info.skipped.map((s) => ({ ...s })) } }, [DEGRADED_DIAGNOSTIC_TYPE]);
157
+ }
158
+ function tagDegraded(msg, info) {
159
+ putDiagnostic(msg, { type: DEGRADED_DIAGNOSTIC_TYPE, timestamp: Date.now(), details: { ...info } }, [FALLBACK_UNSENT_DIAGNOSTIC_TYPE]);
160
+ }
161
+ export function errorMessageOf(model, e, aborted) {
162
+ return {
163
+ role: "assistant",
164
+ content: [{ type: "text", text: "" }],
165
+ api: model.api,
166
+ provider: model.provider,
167
+ model: model.id,
168
+ stopReason: aborted ? "aborted" : "error",
169
+ errorMessage: thrownText(e),
170
+ usage: ZERO_USAGE,
171
+ usageMissing: true,
172
+ timestamp: Date.now(),
173
+ };
174
+ }
175
+ function errorFrameOf(message) {
176
+ return { type: "error", reason: message.stopReason === "aborted" ? "aborted" : "error", error: message };
177
+ }
178
+ export function terminalOf(message) {
179
+ return message.stopReason === "error" || message.stopReason === "aborted"
180
+ ? errorFrameOf(message)
181
+ : { type: "done", reason: message.stopReason, message };
182
+ }
183
+ export function terminalMessage(terminal, fallback) {
184
+ return terminal.type === "done" ? terminal.message : terminal.type === "error" ? terminal.error : fallback;
185
+ }
186
+ function isContentEvent(ev) {
187
+ return ev.type !== "start" && !ev.type.endsWith("_start");
188
+ }
189
+ export function carriesContent(msg) {
190
+ return (msg.content ?? []).some((b) => b.type === "text" ? b.text.length > 0 : b.type === "thinking" ? b.thinking.length > 0 : b.type === "toolCall");
191
+ }
192
+ export function gateReadingOf(msg, hop, expired, callerAborted, gate) {
193
+ if (callerAborted)
194
+ return undefined;
195
+ if (expired)
196
+ return hopGateAdmits(gate, "network") ? "network" : undefined;
197
+ if (msg.stopReason !== "error")
198
+ return undefined;
199
+ if (msg.errorKind === "length_empty" || msg.errorKind === "image_unprocessable" || msg.errorKind === "tool_schema_refused")
200
+ return undefined;
201
+ if (gate.on === ANY_HOP_FAILURE)
202
+ return "next";
203
+ const code = extractErrorCode(msg.errorMessage);
204
+ let reason;
205
+ switch (code) {
206
+ case "network":
207
+ reason = (msg.errorMessage ?? "").includes(CIRCUIT_OPEN_MARKER) ? "breaker_open" : "network";
208
+ break;
209
+ case "rate_limit":
210
+ reason = "rate_limit";
211
+ break;
212
+ case "server":
213
+ reason = "server_error";
214
+ break;
215
+ case "http":
216
+ reason = "last_resort";
217
+ break;
218
+ case "auth":
219
+ reason = "auth";
220
+ break;
221
+ case "stream_torn":
222
+ reason = "stream_torn";
223
+ break;
224
+ case "invalid_request":
225
+ return hop > 0 ? "next" : undefined;
226
+ default:
227
+ return undefined;
228
+ }
229
+ return hopGateAdmits(gate, reason) ? reason : undefined;
230
+ }
231
+ function refusedHop(inner, hop) {
232
+ const verdict = inner.adjudicateRoute?.(hop);
233
+ if (verdict?.ok !== false)
234
+ return undefined;
235
+ const code = readMember(verdict, "code");
236
+ return { model: hop.id, ...(typeof code === "string" ? { code } : {}) };
237
+ }
238
+ function hopOptionsOf(options) {
239
+ return options === undefined ? undefined : { ...options, apiKey: undefined, headers: undefined, metadata: undefined };
240
+ }
241
+ const NO_DEADLINE = (signal) => ({
242
+ signal: signal,
243
+ race: (p) => p,
244
+ expired: () => false,
245
+ stopClock: () => undefined,
246
+ disarm: () => undefined,
247
+ answered: () => undefined,
248
+ abandon: () => undefined,
249
+ });
250
+ async function runHop(inner, model, context, options, deadlineMs, out) {
251
+ const deadline = deadlineMs === undefined
252
+ ? NO_DEADLINE(options?.signal)
253
+ : armBrainCallDeadline(deadlineMs, options?.signal, () => new BrainError("network", `no content from ${model.id} within the fallback first-token deadline (${deadlineMs} ms)`));
254
+ const hopOptions = deadlineMs === undefined ? options : { ...(options ?? {}), signal: deadline.signal };
255
+ const held = [];
256
+ let committed = false;
257
+ let terminal;
258
+ let iterator;
259
+ let drained = false;
260
+ try {
261
+ const stream = await deadline.race(Promise.resolve(inner.stream(model, context, hopOptions)));
262
+ iterator = stream[Symbol.asyncIterator]();
263
+ for (;;) {
264
+ const step = await deadline.race(iterator.next());
265
+ if (step.done === true) {
266
+ drained = true;
267
+ break;
268
+ }
269
+ const ev = step.value;
270
+ if (ev.type === "done" || ev.type === "error") {
271
+ terminal = ev;
272
+ break;
273
+ }
274
+ if (!committed && !isContentEvent(ev)) {
275
+ held.push(ev);
276
+ continue;
277
+ }
278
+ if (!committed) {
279
+ committed = true;
280
+ deadline.stopClock();
281
+ for (const h of held)
282
+ out.push(h);
283
+ held.length = 0;
284
+ }
285
+ out.push(ev);
286
+ }
287
+ deadline.answered();
288
+ const message = await deadline.race(stream.result());
289
+ return { message, ...(terminal !== undefined ? { terminal } : {}), committed, held, expired: false };
290
+ }
291
+ catch (e) {
292
+ const expired = deadline.expired();
293
+ const callerAborted = options?.signal?.aborted === true;
294
+ const aborted = !expired && (callerAborted || abortLikeName(e) !== undefined);
295
+ return { message: errorMessageOf(model, e, aborted), committed, held, expired };
296
+ }
297
+ finally {
298
+ deadline.disarm();
299
+ const it = iterator;
300
+ if (it?.return !== undefined && !drained) {
301
+ void Promise.resolve()
302
+ .then(() => it.return?.())
303
+ .catch(() => undefined);
304
+ }
305
+ }
306
+ }
307
+ function walkStream(inner, policy, requested, chain, context, options) {
308
+ const out = createAssistantMessageEventStream();
309
+ void (async () => {
310
+ const hops = [requested, ...chain];
311
+ let first;
312
+ let reason;
313
+ const tried = [];
314
+ const skipped = [];
315
+ const left = [];
316
+ const markerOf = (outcome, answeredBy) => ({
317
+ from: requested.id,
318
+ to: tried.length > 0 ? tried[tried.length - 1] : requested.id,
319
+ reason: reason,
320
+ chain: [...tried],
321
+ outcome,
322
+ answeredBy: answeredBy.id,
323
+ ...(skipped.length > 0 ? { skipped: [...skipped] } : {}),
324
+ });
325
+ const answer = (run, info) => {
326
+ const terminal = run.terminal ?? terminalOf(run.message);
327
+ const message = terminalMessage(terminal, run.message);
328
+ if (info !== undefined)
329
+ tagDegraded(message, info);
330
+ else if (reason !== undefined && tried.length === 0 && skipped.length > 0)
331
+ tagUnsent(message, { from: requested.id, reason, skipped });
332
+ carryLeftBehind(message, left.filter((l) => l.run !== run).flatMap((l) => leftEntriesOf(l.run.message, l.model.id)));
333
+ if (!run.committed)
334
+ for (const h of run.held)
335
+ out.push(h);
336
+ out.push(terminal);
337
+ };
338
+ try {
339
+ for (let i = 0; i < hops.length; i++) {
340
+ const hop = hops[i];
341
+ if (i > 0) {
342
+ if (options?.signal?.aborted === true)
343
+ break;
344
+ const refused = refusedHop(inner, hop);
345
+ if (refused !== undefined) {
346
+ skipped.push(refused);
347
+ continue;
348
+ }
349
+ tried.push(hop.id);
350
+ }
351
+ const isLast = i === hops.length - 1;
352
+ const run = await runHop(inner, hop, context, i === 0 ? options : hopOptionsOf(options), !isLast ? policy.firstTokenMs : undefined, out);
353
+ if (i === 0)
354
+ first = run;
355
+ const failed = run.expired || run.message.stopReason === "error" || run.message.stopReason === "aborted";
356
+ if (run.committed || !failed) {
357
+ answer(run, i === 0 ? undefined : markerOf("served", hop));
358
+ return;
359
+ }
360
+ const reading = gateReadingOf(run.message, i, run.expired, options?.signal?.aborted === true, policy);
361
+ if (reading === undefined && i === 0) {
362
+ answer(run, undefined);
363
+ return;
364
+ }
365
+ left.push({ run, model: hop });
366
+ if (reading === undefined)
367
+ break;
368
+ if (reason === undefined && reading !== "next")
369
+ reason = reading;
370
+ }
371
+ const head = first;
372
+ answer(head, reason === undefined || tried.length === 0 ? undefined : markerOf("exhausted", requested));
373
+ }
374
+ catch (e) {
375
+ const aborted = options?.signal?.aborted === true || abortLikeName(e) !== undefined;
376
+ const shell = errorMessageOf(requested, e, aborted);
377
+ carryLeftBehind(shell, left.flatMap((l) => leftEntriesOf(l.run.message, l.model.id)));
378
+ out.push(errorFrameOf(shell));
379
+ }
380
+ })();
381
+ return out;
382
+ }
383
+ async function walkComplete(complete, inner, policy, requested, chain, context, options) {
384
+ const hops = [requested, ...chain];
385
+ let first;
386
+ let reason;
387
+ const tried = [];
388
+ const skipped = [];
389
+ const left = [];
390
+ const marked = (msg, outcome, answeredBy) => {
391
+ tagDegraded(msg, {
392
+ from: requested.id,
393
+ to: tried[tried.length - 1] ?? requested.id,
394
+ reason: reason,
395
+ chain: [...tried],
396
+ outcome,
397
+ answeredBy: answeredBy.id,
398
+ ...(skipped.length > 0 ? { skipped: [...skipped] } : {}),
399
+ });
400
+ carryLeftBehind(msg, left.filter((l) => l.message !== msg).flatMap((l) => leftEntriesOf(l.message, l.model.id)));
401
+ return msg;
402
+ };
403
+ for (let i = 0; i < hops.length; i++) {
404
+ const hop = hops[i];
405
+ if (i > 0) {
406
+ if (options?.signal?.aborted === true)
407
+ break;
408
+ const refused = refusedHop(inner, hop);
409
+ if (refused !== undefined) {
410
+ skipped.push(refused);
411
+ continue;
412
+ }
413
+ tried.push(hop.id);
414
+ }
415
+ let msg;
416
+ try {
417
+ msg = await complete(hop, context, i === 0 ? options : hopOptionsOf(options));
418
+ }
419
+ catch (e) {
420
+ const aborted = options?.signal?.aborted === true || abortLikeName(e) !== undefined;
421
+ msg = errorMessageOf(hop, e, aborted);
422
+ }
423
+ if (i === 0)
424
+ first = msg;
425
+ const failed = msg.stopReason === "error" || msg.stopReason === "aborted";
426
+ if (!failed || carriesContent(msg))
427
+ return i === 0 ? msg : marked(msg, "served", hop);
428
+ const reading = gateReadingOf(msg, i, false, options?.signal?.aborted === true, policy);
429
+ if (reading === undefined && i === 0)
430
+ return msg;
431
+ left.push({ message: msg, model: hop });
432
+ if (reading === undefined)
433
+ break;
434
+ if (reason === undefined && reading !== "next")
435
+ reason = reading;
436
+ }
437
+ const head = first;
438
+ if (reason !== undefined && tried.length === 0 && skipped.length > 0)
439
+ tagUnsent(head, { from: requested.id, reason, skipped });
440
+ return reason === undefined || tried.length === 0 ? head : marked(head, "exhausted", requested);
441
+ }
442
+ const LANES = new WeakMap();
443
+ const LANE_BRAINS = new WeakSet();
444
+ export function modelLaneBrain(inner, policy = DEFAULT_MODEL_FALLBACK_POLICY) {
445
+ if (LANE_BRAINS.has(inner))
446
+ return inner;
447
+ let byPolicy = LANES.get(inner);
448
+ if (byPolicy === undefined)
449
+ LANES.set(inner, (byPolicy = new Map()));
450
+ const known = byPolicy.get(policy);
451
+ if (known !== undefined)
452
+ return known;
453
+ const walks = (model, options) => {
454
+ if (options?.resilience?.allowDegrade === false)
455
+ return undefined;
456
+ const chain = modelFallbackChainOf(model);
457
+ return chain.length > 0 ? chain : undefined;
458
+ };
459
+ const stream = (model, context, options) => {
460
+ const chain = walks(model, options);
461
+ return chain === undefined ? inner.stream(model, context, options) : walkStream(inner, policy, model, chain, context, options);
462
+ };
463
+ const innerComplete = completeOf(inner);
464
+ const complete = (model, context, options) => {
465
+ const chain = walks(model, options);
466
+ if (chain === undefined)
467
+ return innerComplete(model, context, options);
468
+ return policy.firstTokenMs !== undefined
469
+ ? walkStream(inner, policy, model, chain, context, options).result()
470
+ : walkComplete(innerComplete, inner, policy, model, chain, context, options);
471
+ };
472
+ const lane = {
473
+ stream,
474
+ complete,
475
+ ...(inner.adjudicateRoute !== undefined
476
+ ? { adjudicateRoute: (model, perModelAuth) => inner.adjudicateRoute?.(model, perModelAuth) }
477
+ : {}),
478
+ };
479
+ byPolicy.set(policy, lane);
480
+ LANE_BRAINS.add(lane);
481
+ return lane;
482
+ }
483
+ export function passthroughStream(brain, model, context, options) {
484
+ const out = createAssistantMessageEventStream();
485
+ void (async () => {
486
+ try {
487
+ const inner = await brain.stream(model, context, options);
488
+ let sawTerminal = false;
489
+ for await (const ev of inner) {
490
+ if (ev.type === "done" || ev.type === "error")
491
+ sawTerminal = true;
492
+ out.push(ev);
493
+ }
494
+ if (!sawTerminal) {
495
+ await inner.result();
496
+ out.push(errorFrameOf(errorMessageOf(model, new Error("brain stream ended without a terminal event"), false)));
497
+ }
498
+ }
499
+ catch (e) {
500
+ const aborted = options?.signal?.aborted === true || abortLikeName(e) !== undefined;
501
+ out.push(errorFrameOf(errorMessageOf(model, e, aborted)));
502
+ }
503
+ })();
504
+ return out;
505
+ }