deepline 0.3.461 → 0.3.462

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 (296) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +7593 -0
  2. package/dist/bundling-sources/sdk/src/client.ts +8 -7366
  3. package/dist/bundling-sources/sdk/src/http-core.ts +1239 -0
  4. package/dist/bundling-sources/sdk/src/http.ts +6 -1231
  5. package/dist/bundling-sources/sdk/src/index.ts +4 -1
  6. package/dist/bundling-sources/sdk/src/play.ts +5 -5
  7. package/dist/bundling-sources/sdk/src/plays/client-core.ts +437 -0
  8. package/dist/bundling-sources/sdk/src/plays/client.ts +4 -421
  9. package/dist/bundling-sources/sdk/src/plays/input-example.ts +3 -4
  10. package/dist/bundling-sources/sdk/src/plays/play-description.ts +1 -1
  11. package/dist/bundling-sources/sdk/src/plays/run-request.ts +1 -1
  12. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  13. package/dist/bundling-sources/sdk/src/server.ts +43 -0
  14. package/dist/bundling-sources/sdk/src/types.ts +15 -5
  15. package/dist/bundling-sources/shared_libs/integration-contracts/billing-entitlements.ts +15 -0
  16. package/dist/bundling-sources/shared_libs/monitors/callback-security.ts +0 -307
  17. package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +3 -0
  18. package/dist/bundling-sources/shared_libs/monitors/lifecycle-notifications.ts +3 -2
  19. package/dist/bundling-sources/shared_libs/monitors/package.json +2 -0
  20. package/dist/bundling-sources/shared_libs/monitors/provider-callback-verification.ts +34 -0
  21. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +59 -0
  22. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +94 -1
  23. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +11 -1
  24. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-failure-codes.ts +24 -0
  25. package/dist/bundling-sources/shared_libs/observability/dlq.ts +32 -0
  26. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +57 -3
  27. package/dist/bundling-sources/shared_libs/observability/scheduled-work.ts +1 -0
  28. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +66 -1
  29. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-column-storage.ts +36 -7
  30. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +250 -11
  31. package/dist/bundling-sources/shared_libs/play-runtime/array-input-store.ts +319 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +991 -359
  33. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +17 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +13 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +110 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +155 -6
  37. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-registry.ts +110 -6
  38. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +127 -13
  39. package/dist/bundling-sources/shared_libs/play-runtime/execution-capabilities.ts +14 -1
  40. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +57 -1
  41. package/dist/bundling-sources/shared_libs/play-runtime/free-company-lookup-batching.ts +218 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/gateway-postgres-admission.ts +42 -5
  43. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-budget-state-backend.ts +6 -1
  44. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +92 -31
  45. package/dist/bundling-sources/shared_libs/play-runtime/governor/block-reserving-budget-state-backend.ts +69 -14
  46. package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +93 -23
  47. package/dist/bundling-sources/shared_libs/play-runtime/governor/in-memory-rate-state-backend.ts +15 -4
  48. package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +22 -18
  49. package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +5 -0
  50. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +2 -0
  51. package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +190 -14
  52. package/dist/bundling-sources/shared_libs/play-runtime/memory-ledger.ts +131 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +77 -2
  54. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +271 -2
  55. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +51 -0
  56. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +2 -0
  57. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +27 -1
  58. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-batching-registry.ts +2 -0
  59. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +3 -0
  60. package/dist/bundling-sources/shared_libs/play-runtime/provider-text-for-log.ts +63 -0
  61. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +19 -0
  62. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-event-transport.ts +112 -16
  63. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +104 -2
  64. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +265 -151
  65. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-gateway-transport.ts +17 -0
  66. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-progress-push.ts +35 -14
  67. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-sheet-persistence-retry.ts +12 -1
  68. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +4 -0
  69. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-labels.ts +36 -0
  70. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +136 -70
  71. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +237 -36
  72. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +148 -4
  73. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +6 -0
  74. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +285 -32
  75. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +251 -56
  76. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +29 -4
  77. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/sandbox-create-outcome.ts +27 -0
  78. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +22 -1
  79. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +1397 -382
  80. package/dist/bundling-sources/shared_libs/play-runtime/runtime-array-input-receipts.ts +920 -0
  81. package/dist/bundling-sources/shared_libs/play-runtime/runtime-constants.ts +16 -0
  82. package/dist/bundling-sources/shared_libs/play-runtime/runtime-environment.ts +38 -0
  83. package/dist/bundling-sources/shared_libs/play-runtime/runtime-flow.ts +6 -0
  84. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +26 -1
  85. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +30 -0
  86. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +14 -3
  87. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +31 -4
  88. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-transition.ts +47 -0
  89. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-compute-usage.ts +20 -7
  90. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +12 -0
  91. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +9 -0
  92. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +10 -0
  93. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +4 -0
  94. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +1496 -320
  95. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +31 -1
  96. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +1389 -129
  97. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +36 -0
  98. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-dispatch-authority.ts +4 -0
  99. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +162 -23
  100. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +499 -115
  101. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +377 -9
  102. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +117 -8
  103. package/dist/bundling-sources/shared_libs/play-runtime/secret-resolution-retry-policy.ts +25 -0
  104. package/dist/bundling-sources/shared_libs/play-runtime/terminal-runtime-performance.ts +391 -0
  105. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +40 -0
  106. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/index.ts +6 -0
  107. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/mapped-calls.ts +171 -0
  108. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/receipt-cohort.ts +16 -1
  109. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +26 -3
  110. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +16 -2
  111. package/dist/bundling-sources/shared_libs/play-runtime/transport-error-diagnostics.ts +28 -0
  112. package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-storage-contract.ts +55 -5
  113. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +41 -1
  114. package/dist/bundling-sources/shared_libs/plays/contracts.ts +4 -0
  115. package/dist/bundling-sources/shared_libs/plays/dataset.ts +9 -3
  116. package/dist/bundling-sources/shared_libs/plays/deploy/manifest-contract.ts +2 -0
  117. package/dist/bundling-sources/shared_libs/plays/deploy/manifest.ts +3 -2
  118. package/dist/bundling-sources/shared_libs/plays/deploy/project-serializer.ts +2 -2
  119. package/dist/bundling-sources/shared_libs/plays/run-output-summary.ts +66 -0
  120. package/dist/bundling-sources/shared_libs/plays/script-entry.ts +1 -1
  121. package/dist/bundling-sources/shared_libs/product-notifications/catalog.ts +43 -1
  122. package/dist/bundling-sources/shared_libs/product-notifications/content.ts +9 -0
  123. package/dist/bundling-sources/shared_libs/product-notifications/email.ts +91 -13
  124. package/dist/bundling-sources/shared_libs/product-notifications/events.ts +3 -0
  125. package/dist/bundling-sources/shared_libs/product-notifications/slack-delivery.ts +41 -24
  126. package/dist/bundling-sources/shared_libs/security/attested-client-ip.ts +91 -0
  127. package/dist/bundling-sources/shared_libs/security/internal-actor.ts +0 -11
  128. package/dist/cli/{auth-6HJXNWUG.mjs → auth-JDLEY7VU.mjs} +5 -4
  129. package/dist/cli/auth-UXKY6TCC.js +41 -0
  130. package/dist/cli/{billing-6P5HO6QG.js → billing-HXAXB3XZ.js} +152 -78
  131. package/dist/cli/{billing-MJ42N7YF.mjs → billing-SDHLBLMV.mjs} +84 -10
  132. package/dist/cli/{chunk-5MDIZX7M.js → chunk-3ACMRZRV.js} +8 -6
  133. package/dist/cli/{chunk-FGLKOWSC.mjs → chunk-3KZCFOZ6.mjs} +1 -1
  134. package/dist/cli/chunk-4KQ6SIBC.mjs +1038 -0
  135. package/dist/cli/{chunk-Z2GUFYT6.js → chunk-5LEAXRHV.js} +11 -11
  136. package/dist/cli/{chunk-MEAIOXJL.mjs → chunk-6NNVJDVR.mjs} +7 -5
  137. package/dist/cli/{chunk-NMJ4D2WO.js → chunk-6PMCRYDA.js} +216 -91
  138. package/dist/cli/{chunk-RY4IVOU3.mjs → chunk-6RNQGWFD.mjs} +16 -806
  139. package/dist/cli/{chunk-EBU7LQ64.js → chunk-6V7KVRR5.js} +3 -3
  140. package/dist/cli/{chunk-OZBWRICM.js → chunk-7LFIMWMW.js} +2 -2
  141. package/dist/cli/chunk-7MJ6VI2T.mjs +19 -0
  142. package/dist/cli/chunk-7SWNPNML.js +1039 -0
  143. package/dist/cli/{chunk-IHHLTHE7.mjs → chunk-7U3XNPOA.mjs} +267 -38
  144. package/dist/cli/{chunk-5FDKJQZE.js → chunk-7VZHXVOQ.js} +1 -1
  145. package/dist/cli/{chunk-R64BGGRQ.mjs → chunk-AT636LLU.mjs} +2 -2
  146. package/dist/cli/{chunk-MDJPEGVN.js → chunk-BGTPIMSM.js} +392 -261
  147. package/dist/cli/{chunk-KVJ5VHW5.mjs → chunk-CKSOY47X.mjs} +2 -2
  148. package/dist/cli/{chunk-7DH2FD7Y.mjs → chunk-D464JW3N.mjs} +5 -85
  149. package/dist/cli/chunk-D6DXOUTO.mjs +827 -0
  150. package/dist/cli/{describe-2WQY7ZCY.js → chunk-EM4TXCCI.js} +27 -44
  151. package/dist/cli/chunk-F6QV42MC.mjs +91 -0
  152. package/dist/cli/chunk-FKVYR3QA.mjs +1039 -0
  153. package/dist/cli/{chunk-FGMX4HUZ.js → chunk-GEGW5HPZ.js} +29 -27
  154. package/dist/cli/{chunk-TNMBPMMC.js → chunk-HUB3CCM2.js} +13 -4
  155. package/dist/cli/{chunk-ACCR7POB.js → chunk-I6VHOU5O.js} +27 -27
  156. package/dist/cli/{chunk-Z2XUZC34.js → chunk-IAYSWZDJ.js} +188 -76
  157. package/dist/cli/chunk-JF3TLIMQ.js +19 -0
  158. package/dist/cli/{chunk-HDFRJ4IT.mjs → chunk-JVHOS3K3.mjs} +177 -65
  159. package/dist/cli/{chunk-V7REJRDZ.mjs → chunk-LFXLQEZN.mjs} +1 -1
  160. package/dist/cli/{chunk-CRYOUPEB.js → chunk-LROWFPGN.js} +16 -16
  161. package/dist/cli/{chunk-SLEUWLJE.mjs → chunk-MSY22NQW.mjs} +5 -5
  162. package/dist/cli/{chunk-BGY2PLP7.mjs → chunk-MUUQZIOF.mjs} +23 -49
  163. package/dist/cli/{chunk-FCAZQ7WV.js → chunk-NBLSCHKK.js} +52 -50
  164. package/dist/cli/{chunk-QAJAJPKK.mjs → chunk-NHRWZPWZ.mjs} +4 -2
  165. package/dist/cli/{chunk-KXMNM4AQ.js → chunk-NMU3VR5U.js} +4 -5
  166. package/dist/cli/{chunk-QIW7TVV6.mjs → chunk-O2RX5A66.mjs} +14 -12
  167. package/dist/cli/{chunk-SAZFZQRI.js → chunk-OMQ23IXL.js} +2 -2
  168. package/dist/cli/{chunk-5IYOUBFZ.js → chunk-OPJAJBD4.js} +28 -54
  169. package/dist/cli/{chunk-FJZILBL7.mjs → chunk-PHSEINNH.mjs} +5 -5
  170. package/dist/cli/{chunk-3DNKFH2G.mjs → chunk-PKHVSIJG.mjs} +19 -1
  171. package/dist/cli/{chunk-WIYWSYDS.mjs → chunk-Q2EIZKVX.mjs} +3 -3
  172. package/dist/cli/{chunk-5FY72YOV.js → chunk-QJZ6WNWD.js} +8 -8
  173. package/dist/cli/{chunk-EIMG75BT.mjs → chunk-S3A4IXBQ.mjs} +4 -5
  174. package/dist/cli/{chunk-3BMLICF7.mjs → chunk-S42YIQNE.mjs} +13 -8
  175. package/dist/cli/{chunk-RFONC4WJ.mjs → chunk-S6UAJR6V.mjs} +3 -3
  176. package/dist/cli/{chunk-G7L27KZB.mjs → chunk-TKAQR3IB.mjs} +31 -21
  177. package/dist/cli/{chunk-QWRHGGUH.js → chunk-UAJFWWZE.js} +20 -2
  178. package/dist/cli/{chunk-VZBCEA5S.mjs → chunk-UDRPEZ5F.mjs} +223 -92
  179. package/dist/cli/{chunk-KCCOQ5G5.js → chunk-ULK7JGGI.js} +511 -282
  180. package/dist/cli/chunk-V335HGX5.js +1038 -0
  181. package/dist/cli/{chunk-MGXEUZHL.mjs → chunk-V3MEA7NB.mjs} +7 -5
  182. package/dist/cli/{chunk-O6QOMHCH.js → chunk-VFGVXXZP.js} +37 -35
  183. package/dist/cli/chunk-VLEVVDWG.js +91 -0
  184. package/dist/cli/{chunk-R2GLGLDR.mjs → chunk-VPHN2HAL.mjs} +216 -91
  185. package/dist/cli/{chunk-CFUTOWE4.js → chunk-WG3KGAII.js} +8 -88
  186. package/dist/cli/{describe-FRAVCY5F.mjs → chunk-WIY6U6GD.mjs} +19 -36
  187. package/dist/cli/{chunk-PNATXKLP.js → chunk-XANRM3QA.js} +6 -6
  188. package/dist/cli/{chunk-KGQNIA37.js → chunk-XQCTG5OO.js} +44 -34
  189. package/dist/cli/{chunk-T3MVIPHG.mjs → chunk-XZAFIOUQ.mjs} +1 -1
  190. package/dist/cli/chunk-Y4DPU4OM.js +827 -0
  191. package/dist/cli/chunk-YT5EODJO.js +920 -0
  192. package/dist/cli/{chunk-SCIR5JXW.js → chunk-ZGQSFYD2.js} +56 -51
  193. package/dist/cli/{chunk-QEYHTIV4.mjs → chunk-ZUK6LIJB.mjs} +10 -1
  194. package/dist/cli/command-docs.d.mts +5 -0
  195. package/dist/cli/command-docs.d.ts +5 -0
  196. package/dist/cli/command-docs.js +2 -2
  197. package/dist/cli/command-docs.mjs +1 -1
  198. package/dist/cli/{csv-NX7NO3O6.js → csv-C56GSCEU.js} +13 -12
  199. package/dist/cli/{csv-DQ6GW5B5.mjs → csv-L54JS7TF.mjs} +4 -3
  200. package/dist/cli/{db-R72DFMP6.js → db-MOGRMZTA.js} +30 -27
  201. package/dist/cli/{db-2YP33M4K.mjs → db-YVBUW2DX.mjs} +10 -7
  202. package/dist/cli/describe-KYEULWPG.js +48 -0
  203. package/dist/cli/describe-NLZKKT7C.mjs +48 -0
  204. package/dist/cli/describe-core.d.mts +153 -5
  205. package/dist/cli/describe-core.d.ts +153 -5
  206. package/dist/cli/describe-core.js +9 -5
  207. package/dist/cli/describe-core.mjs +10 -6
  208. package/dist/cli/{executions-ZLHD4QIT.js → executions-A7L4ULPP.js} +9 -7
  209. package/dist/cli/{executions-WFBU7L2Q.mjs → executions-ZBGSTT37.mjs} +7 -5
  210. package/dist/cli/{feedback-CN3HJFVF.mjs → feedback-G6GU37FD.mjs} +6 -5
  211. package/dist/cli/{feedback-NDV6TPHG.js → feedback-OHLY7RYD.js} +10 -9
  212. package/dist/cli/getting-started.d.mts +6 -6
  213. package/dist/cli/getting-started.d.ts +6 -6
  214. package/dist/cli/getting-started.js +2 -2
  215. package/dist/cli/getting-started.mjs +1 -1
  216. package/dist/cli/git-P76N4NDQ.js +25 -0
  217. package/dist/cli/{git-QAD6E3HW.mjs → git-PKZW3QD5.mjs} +5 -4
  218. package/dist/cli/index.js +152 -142
  219. package/dist/cli/index.mjs +56 -46
  220. package/dist/cli/{legacy-noops-KVC5QJ74.js → legacy-noops-5LM3D724.js} +8 -7
  221. package/dist/cli/{legacy-noops-TPTKNBI2.mjs → legacy-noops-LJJYG6YA.mjs} +5 -4
  222. package/dist/cli/{monitors-SV57JFLO.mjs → monitors-72QV4ALO.mjs} +19 -6
  223. package/dist/cli/{monitors-KCROV6PJ.js → monitors-UX3H5DC2.js} +103 -90
  224. package/dist/cli/{org-KX6QIR7A.mjs → org-6RRRKOCP.mjs} +9 -6
  225. package/dist/cli/{org-NJYX5743.js → org-IF7ISUVB.js} +70 -67
  226. package/dist/cli/pages-3SU3HKL7.js +252 -0
  227. package/dist/cli/pages-DXDYYKEK.mjs +252 -0
  228. package/dist/cli/{play-IQQ57L7Z.mjs → play-AHASKRLA.mjs} +512 -1508
  229. package/dist/cli/{play-32L7EQN4.js → play-EUIUVLUH.js} +1090 -2086
  230. package/dist/cli/{providers-4WEC2EQN.mjs → providers-GWGE3WY3.mjs} +7 -5
  231. package/dist/cli/{providers-ZQV6QLVQ.js → providers-V5WU4VXJ.js} +10 -8
  232. package/dist/cli/{quickstart-RQ76RIUE.mjs → quickstart-OXKQ5ZST.mjs} +5 -4
  233. package/dist/cli/{quickstart-HKUSFADF.js → quickstart-QP65I5PF.js} +13 -12
  234. package/dist/cli/run-6MM72IGL.mjs +443 -0
  235. package/dist/cli/run-F3FTYS56.js +443 -0
  236. package/dist/cli/search-OYKOOI7A.js +32 -0
  237. package/dist/cli/{search-ZRAVFBZC.mjs → search-ZMEBVJZB.mjs} +8 -6
  238. package/dist/cli/{secrets-J3G5Y43U.js → secrets-ACND5N6A.js} +16 -14
  239. package/dist/cli/{secrets-CMJOVNVH.mjs → secrets-XRCJFF3L.mjs} +7 -5
  240. package/dist/cli/{sessions-MDQYY5CB.mjs → sessions-RTK3CEW6.mjs} +5 -4
  241. package/dist/cli/{sessions-WY7VN4AE.js → sessions-ZGRJPCFF.js} +6 -5
  242. package/dist/cli/{settings-HTNTFKCE.js → settings-PD5KWQQZ.js} +80 -77
  243. package/dist/cli/{settings-4RWZPCT5.mjs → settings-XDRBPRDE.mjs} +14 -11
  244. package/dist/cli/{setup-P3GYYZWG.mjs → setup-3HPYAOCC.mjs} +12 -10
  245. package/dist/cli/{setup-QGCAP62X.js → setup-E2Q6PXHC.js} +53 -51
  246. package/dist/cli/{skills-7NAE4ICL.mjs → skills-OOQFMPOV.mjs} +7 -6
  247. package/dist/cli/skills-XYWV52KB.js +31 -0
  248. package/dist/cli/tools-ASCDZJCK.js +55 -0
  249. package/dist/cli/tools-C5ZT3UIC.mjs +55 -0
  250. package/dist/cli/update-5RQSEIFM.js +33 -0
  251. package/dist/cli/{update-GODLRKNB.mjs → update-ZWJTADIW.mjs} +9 -8
  252. package/dist/cli/{workflow-4BXOUVEO.mjs → workflow-23NMPAJ7.mjs} +10 -8
  253. package/dist/cli/{workflow-AO3A6LXN.js → workflow-TCXU5YJV.js} +20 -18
  254. package/dist/client-DS2IWYZF.d.ts +10 -0
  255. package/dist/client-DTwnz_AW.d.mts +10 -0
  256. package/dist/{client-CYqG23K1.d.ts → client-core-B_6HAIBy.d.ts} +385 -12
  257. package/dist/{client-BbU5_j7n.d.mts → client-core-DzBSlY1U.d.mts} +385 -12
  258. package/dist/{compiler-manifest-CWz_sNOQ.d.ts → compiler-manifest-Dcyd3-Zd.d.mts} +43 -1
  259. package/dist/{compiler-manifest-CWz_sNOQ.d.mts → compiler-manifest-Dcyd3-Zd.d.ts} +43 -1
  260. package/dist/errors-d-sTrZhe.d.mts +142 -0
  261. package/dist/errors-yQwfgrcX.d.ts +142 -0
  262. package/dist/{index-BF2JB_Ug.d.mts → index-C6oXchjN.d.mts} +1 -1
  263. package/dist/{index-4NPXDzlD.d.ts → index-P56zy_z5.d.ts} +1 -1
  264. package/dist/index.d.mts +11 -147
  265. package/dist/index.d.ts +11 -147
  266. package/dist/index.js +15 -11
  267. package/dist/index.mjs +14 -10
  268. package/dist/install-integrity.json +141 -104
  269. package/dist/plays/bundle-play-file.d.mts +3 -3
  270. package/dist/plays/bundle-play-file.d.ts +3 -3
  271. package/dist/plays/bundle-play-file.mjs +2 -1
  272. package/dist/plays/play-description.d.mts +2 -2
  273. package/dist/plays/play-description.d.ts +2 -2
  274. package/dist/plays/play-description.js +2 -2
  275. package/dist/plays/play-description.mjs +1 -1
  276. package/dist/plays/run-request.d.mts +2 -2
  277. package/dist/plays/run-request.d.ts +2 -2
  278. package/dist/release.d.mts +1 -1
  279. package/dist/release.d.ts +1 -1
  280. package/dist/release.js +2 -2
  281. package/dist/release.mjs +1 -1
  282. package/dist/server.d.mts +17 -0
  283. package/dist/server.d.ts +17 -0
  284. package/dist/server.js +76 -0
  285. package/dist/server.mjs +76 -0
  286. package/package.json +6 -1
  287. package/dist/cli/auth-IACERYQH.js +0 -40
  288. package/dist/cli/chunk-PQUUWFXY.js +0 -95
  289. package/dist/cli/chunk-YBWAG72P.mjs +0 -95
  290. package/dist/cli/chunk-YQDUODZW.js +0 -1710
  291. package/dist/cli/git-JVI36ZFV.js +0 -24
  292. package/dist/cli/search-75X5LTDE.js +0 -30
  293. package/dist/cli/skills-BKJ53JOQ.js +0 -30
  294. package/dist/cli/tools-COWMIEJ6.mjs +0 -45
  295. package/dist/cli/tools-TASOCE7I.js +0 -45
  296. package/dist/cli/update-SJIKVME6.js +0 -32
@@ -10,6 +10,25 @@ import {
10
10
  const DAYTONA_PROVIDER = RuntimeSandboxProvider.Daytona;
11
11
  const DEFAULT_BATCH_SIZE = 500;
12
12
  const MAX_BATCH_SIZE = 1_000;
13
+ const EXACT_READ_CONCURRENCY = 8;
14
+
15
+ async function mapWithConcurrency<T, R>(
16
+ items: readonly T[],
17
+ concurrency: number,
18
+ map: (item: T) => Promise<R>,
19
+ ): Promise<R[]> {
20
+ const results = new Array<R>(items.length);
21
+ let next = 0;
22
+ await Promise.all(
23
+ Array.from({ length: Math.min(concurrency, items.length) }, async () => {
24
+ while (next < items.length) {
25
+ const index = next++;
26
+ results[index] = await map(items[index]!);
27
+ }
28
+ }),
29
+ );
30
+ return results;
31
+ }
13
32
  /** Never classify a very recent resource from a provider snapshot as absent. */
14
33
  export const RUNTIME_SANDBOX_LEDGER_RECONCILIATION_MINIMUM_AGE_MS =
15
34
  10 * 60 * 1_000;
@@ -71,13 +90,33 @@ function batchSize(value: number | undefined): number {
71
90
  return value;
72
91
  }
73
92
 
93
+ /**
94
+ * A read of one exact sandbox id. Only `absent`, Daytona's 404 for that id,
95
+ * settles a ledger row: a list can omit a sandbox that is still running.
96
+ */
97
+ export type RuntimeSandboxExactReadOutcome = 'absent' | 'present' | 'unknown';
98
+
99
+ /** Keyset position in the absent-candidate order, so a pass never revisits. */
100
+ export type RuntimeSandboxLedgerReconciliationCursor = {
101
+ /** Exact PostgreSQL timestamptz text; milliseconds are insufficient. */
102
+ providerCreatedAt: string;
103
+ operationKey: string;
104
+ };
105
+
74
106
  export type RuntimeSandboxLedgerReconciliationSummary = {
75
107
  provider: RuntimeSandboxProvider.Daytona;
76
108
  providerSandboxCount: number;
77
109
  matchedLiveSandboxes: number;
78
110
  unmatchedProviderSandboxIds: string[];
79
111
  liveLeasesToSeed: number;
112
+ /** Rows missing from the provider list in this batch. */
80
113
  absentLedgerRows: number;
114
+ /** Of those, the rows Daytona answered 404 for when read by exact id. */
115
+ confirmedAbsentLedgerRows: number;
116
+ /** Missing from the list, yet Daytona still returns them by id. */
117
+ listOmittedSandboxIds: string[];
118
+ /** Missing from the list, and the exact read did not answer. */
119
+ absenceUnconfirmedSandboxIds: string[];
81
120
  seededLeases: number;
82
121
  /** Historical or raced leases released because deletion was already durable. */
83
122
  releasedTerminalLeases: number;
@@ -85,6 +124,8 @@ export type RuntimeSandboxLedgerReconciliationSummary = {
85
124
  /** Reserved creates recovered from Daytona's exact operation-key label. */
86
125
  recoveredReservedOperations: number;
87
126
  hasMoreAbsentLedgerRows: boolean;
127
+ /** Where the next batch resumes; null when this batch saw no candidates. */
128
+ nextCursor: RuntimeSandboxLedgerReconciliationCursor | null;
88
129
  dryRun: boolean;
89
130
  diagnostics: readonly RuntimeSandboxLedgerReconciliationDiagnostic[];
90
131
  };
@@ -585,9 +626,10 @@ async function releaseTerminalSandboxCapacityLeases(
585
626
  * This is intentionally a rollout/migration operation, not a hot-path read:
586
627
  * Daytona's label-scoped list is the authority for provider presence. A live
587
628
  * provider resource is seeded into the soft-capacity lease table. An older
588
- * durable resource absent from that inventory is completed in the cleanup
589
- * ledger with a provider-confirmed-absent audit event; the resource history is
590
- * never deleted or rewritten.
629
+ * durable resource absent from that inventory is read by its exact id, and
630
+ * only a 404 completes it in the cleanup ledger with a provider-confirmed-absent
631
+ * audit event: a list can omit a sandbox that is still running. The resource
632
+ * history is never deleted or rewritten.
591
633
  */
592
634
  export async function reconcileRuntimeDaytonaSandboxLedger(
593
635
  client: PostgresSchedulerQueryClient,
@@ -599,6 +641,16 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
599
641
  * Resources recorded later than this snapshot are never classified absent.
600
642
  */
601
643
  inventoryCapturedAtMs: number;
644
+ /**
645
+ * Reads one sandbox by its exact id, in its routing domain. A row missing
646
+ * from the list is marked deleted only when this answers `absent`.
647
+ */
648
+ readExactSandbox: (sandbox: {
649
+ sandboxId: string;
650
+ routingDomain: string | null;
651
+ }) => Promise<RuntimeSandboxExactReadOutcome>;
652
+ /** Resume after this candidate; the previous batch's `nextCursor`. */
653
+ after?: RuntimeSandboxLedgerReconciliationCursor | null;
602
654
  dryRun: boolean;
603
655
  batchSize?: number;
604
656
  minimumAgeMs?: number;
@@ -889,11 +941,15 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
889
941
  unmatchedProviderSandboxIds,
890
942
  liveLeasesToSeed: 0,
891
943
  absentLedgerRows: 0,
944
+ confirmedAbsentLedgerRows: 0,
945
+ listOmittedSandboxIds: [],
946
+ absenceUnconfirmedSandboxIds: [],
892
947
  seededLeases: 0,
893
948
  releasedTerminalLeases,
894
949
  markedDeleted: 0,
895
950
  recoveredReservedOperations,
896
951
  hasMoreAbsentLedgerRows: false,
952
+ nextCursor: null,
897
953
  dryRun: input.dryRun,
898
954
  diagnostics,
899
955
  };
@@ -906,10 +962,14 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
906
962
  org_id: string;
907
963
  environment: string;
908
964
  routing_domain: string | null;
965
+ provider_created_at_text: string;
966
+ operation_key: string;
909
967
  }>(
910
968
  RuntimeSandboxLedgerReconciliationPhase.FindAbsentOperations,
911
969
  `
912
- SELECT sandbox_id, run_id, attempt, org_id, environment, routing_domain
970
+ SELECT sandbox_id, run_id, attempt, org_id, environment, routing_domain,
971
+ provider_created_at::text AS provider_created_at_text,
972
+ operation_key
913
973
  FROM ${operations}
914
974
  WHERE provider = $1
915
975
  AND environment = 'production'
@@ -934,6 +994,12 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
934
994
  -- an operation recorded after it as absent.
935
995
  AND provider_created_at <= to_timestamp($4::double precision / 1000.0)
936
996
  AND provider_created_at <= clock_timestamp() - ($5::integer * interval '1 millisecond')
997
+ -- A row the exact read did not settle stays live, so later batches
998
+ -- resume after it instead of reading it again.
999
+ AND (
1000
+ $7::timestamptz IS NULL
1001
+ OR (provider_created_at, operation_key) > ($7::timestamptz, $8::text)
1002
+ )
937
1003
  ORDER BY provider_created_at, operation_key
938
1004
  LIMIT $6
939
1005
  `,
@@ -944,10 +1010,21 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
944
1010
  input.inventoryCapturedAtMs,
945
1011
  minimumAgeMs,
946
1012
  limit + 1,
1013
+ input.after?.providerCreatedAt ?? null,
1014
+ input.after?.operationKey ?? null,
947
1015
  ],
948
1016
  );
949
1017
  const hasMoreAbsentLedgerRows = candidates.rows.length > limit;
950
- const absent = candidates.rows.slice(0, limit).map((row) => ({
1018
+ const batch = candidates.rows.slice(0, limit);
1019
+ const lastCandidate = batch.at(-1);
1020
+ const nextCursor: RuntimeSandboxLedgerReconciliationCursor | null =
1021
+ lastCandidate
1022
+ ? {
1023
+ providerCreatedAt: lastCandidate.provider_created_at_text,
1024
+ operationKey: lastCandidate.operation_key,
1025
+ }
1026
+ : null;
1027
+ const listAbsent = batch.map((row) => ({
951
1028
  sandboxId: row.sandbox_id,
952
1029
  runId: row.run_id,
953
1030
  attempt: Number(row.attempt),
@@ -955,6 +1032,27 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
955
1032
  environment: row.environment,
956
1033
  routingDomain: row.routing_domain,
957
1034
  }));
1035
+ // Absence from a list is not deletion. Read each id; only a 404 settles it.
1036
+ const exactReads = await mapWithConcurrency(
1037
+ listAbsent,
1038
+ EXACT_READ_CONCURRENCY,
1039
+ async (row) => ({
1040
+ row,
1041
+ outcome: await input.readExactSandbox({
1042
+ sandboxId: row.sandboxId,
1043
+ routingDomain: row.routingDomain,
1044
+ }),
1045
+ }),
1046
+ );
1047
+ const absent = exactReads
1048
+ .filter((read) => read.outcome === 'absent')
1049
+ .map((read) => read.row);
1050
+ const listOmittedSandboxIds = exactReads
1051
+ .filter((read) => read.outcome === 'present')
1052
+ .map((read) => read.row.sandboxId);
1053
+ const absenceUnconfirmedSandboxIds = exactReads
1054
+ .filter((read) => read.outcome === 'unknown')
1055
+ .map((read) => read.row.sandboxId);
958
1056
 
959
1057
  const leaseRows = live.length
960
1058
  ? await measuredQuery<{
@@ -1015,12 +1113,16 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
1015
1113
  matchedLiveSandboxes: live.length,
1016
1114
  unmatchedProviderSandboxIds,
1017
1115
  liveLeasesToSeed: liveLeasesToSeed.length,
1018
- absentLedgerRows: absent.length,
1116
+ absentLedgerRows: listAbsent.length,
1117
+ confirmedAbsentLedgerRows: absent.length,
1118
+ listOmittedSandboxIds,
1119
+ absenceUnconfirmedSandboxIds,
1019
1120
  seededLeases: 0,
1020
1121
  releasedTerminalLeases,
1021
1122
  markedDeleted: 0,
1022
1123
  recoveredReservedOperations,
1023
1124
  hasMoreAbsentLedgerRows,
1125
+ nextCursor,
1024
1126
  dryRun: true,
1025
1127
  diagnostics,
1026
1128
  };
@@ -1137,7 +1239,10 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
1137
1239
  SELECT
1138
1240
  '${DAYTONA_PROVIDER}', sandbox_id, routing_domain, run_id, attempt,
1139
1241
  0, NULL, 'reconciled_provider_confirmed_absent',
1140
- jsonb_build_object('source', 'runtime-sandbox-ledger-reconciliation')
1242
+ jsonb_build_object(
1243
+ 'source', 'runtime-sandbox-ledger-reconciliation',
1244
+ 'evidence', 'exact_id_not_found'
1245
+ )
1141
1246
  FROM changed
1142
1247
  ),
1143
1248
  operation_deleted AS (
@@ -1206,12 +1311,16 @@ export async function reconcileRuntimeDaytonaSandboxLedger(
1206
1311
  matchedLiveSandboxes: live.length,
1207
1312
  unmatchedProviderSandboxIds,
1208
1313
  liveLeasesToSeed: liveLeasesToSeed.length,
1209
- absentLedgerRows: absent.length,
1314
+ absentLedgerRows: listAbsent.length,
1315
+ confirmedAbsentLedgerRows: absent.length,
1316
+ listOmittedSandboxIds,
1317
+ absenceUnconfirmedSandboxIds,
1210
1318
  seededLeases,
1211
1319
  releasedTerminalLeases,
1212
1320
  markedDeleted: marked.rows.length,
1213
1321
  recoveredReservedOperations,
1214
1322
  hasMoreAbsentLedgerRows,
1323
+ nextCursor,
1215
1324
  dryRun: false,
1216
1325
  diagnostics,
1217
1326
  };
@@ -1,3 +1,5 @@
1
+ import { RUNNER_GATEWAY_CONNECTION_RETRY_BUDGET_MS } from './runtime-constants';
2
+
1
3
  export const SECRET_RESOLUTION_MAX_ATTEMPTS = 3;
2
4
  export const SECRET_RESOLUTION_MAX_RETRY_AFTER_MS = 2_000;
3
5
  // Per-attempt client deadline for the secret-resolution gateway call. This is an
@@ -84,3 +86,26 @@ export function secretResolutionRetryDecision(input: {
84
86
  retryAfterExceedsCap: false,
85
87
  };
86
88
  }
89
+
90
+ /** A request timeout or a network-level fetch failure: nothing came back. */
91
+ export function secretResolutionGotNoResponse(error: unknown): boolean {
92
+ if (!(error instanceof Error)) return false;
93
+ return error.name === 'TimeoutError' || /^fetch failed$/i.test(error.message);
94
+ }
95
+
96
+ /**
97
+ * The wait before resending a lookup that got no response once its ordinary
98
+ * attempts are spent, or null when the sandbox network-cut budget is used up.
99
+ */
100
+ export function secretResolutionOutageRetryDelayMs(input: {
101
+ attempt: number;
102
+ elapsedMs: number;
103
+ }): number | null {
104
+ const delayMs = Math.min(
105
+ 8_000,
106
+ 1_000 * Math.max(1, input.attempt - SECRET_RESOLUTION_MAX_ATTEMPTS + 1),
107
+ );
108
+ return input.elapsedMs + delayMs <= RUNNER_GATEWAY_CONNECTION_RETRY_BUDGET_MS
109
+ ? delayMs
110
+ : null;
111
+ }
@@ -0,0 +1,391 @@
1
+ import { runtimeWorkCountersFromStats } from './runtime-work-counters';
2
+
3
+ /** Closed producer-owned terminal sample. Never read this from Play output.
4
+ * CPU is runner-process lifetime usage; peaks are process high-water samples.
5
+ * These are neither database CPU nor provider occupancy/billable seconds.
6
+ */
7
+ export const TERMINAL_RUNTIME_PHASES = [
8
+ 'rowAdmission',
9
+ 'providerAdmission',
10
+ 'externalExecution',
11
+ 'providerResidence',
12
+ 'fixtureDelay',
13
+ 'transportSlotWait',
14
+ 'fetchToHeaders',
15
+ 'bodyRead',
16
+ 'eventLoopLag',
17
+ 'receiptSettlement',
18
+ 'receiptClaim',
19
+ 'receiptHydrationGateWait',
20
+ 'receiptCompletionQueue',
21
+ 'receiptCompletionFlight',
22
+ 'receiptCompletionReadBack',
23
+ 'rowPersistence',
24
+ 'dispatchQueueWait',
25
+ 'rowResolverGap',
26
+ 'toolCallLogicalWall',
27
+ 'resultDelivery',
28
+ 'deliveryWrap',
29
+ 'deliveryPublishWait',
30
+ 'deliveryResolve',
31
+ 'flightSerialize',
32
+ 'flightTransport',
33
+ 'flightDecode',
34
+ 'gatewayAuthLaunch',
35
+ 'gatewayAuthVerify',
36
+ 'gatewayBodyParse',
37
+ 'gatewayBodyInflate',
38
+ 'gatewayPoolWait',
39
+ 'gatewayReceiptValuePersist',
40
+ 'gatewayCallback',
41
+ 'gatewayRoundTrip',
42
+ 'gatewayRequestSerialize',
43
+ 'gatewayRequestPack',
44
+ ] as const;
45
+ export type TerminalRuntimePhase = (typeof TERMINAL_RUNTIME_PHASES)[number];
46
+ export type TerminalRuntimeSegment = {
47
+ attempt: number;
48
+ invocationSeq: number;
49
+ segmentId: string;
50
+ };
51
+ export type TerminalRuntimePerformanceUnavailableReason =
52
+ | 'invalid_runner_stats'
53
+ | 'invalid_terminal_performance';
54
+ export type TerminalRuntimeHistogram = [
55
+ number,
56
+ number,
57
+ number,
58
+ number,
59
+ number,
60
+ number,
61
+ number,
62
+ number,
63
+ number,
64
+ number,
65
+ number,
66
+ number,
67
+ number,
68
+ number,
69
+ number,
70
+ number,
71
+ number,
72
+ number,
73
+ ];
74
+ export type TerminalRuntimeDistribution = {
75
+ count: number;
76
+ totalMs: number;
77
+ maxMs: number | null;
78
+ ewmaMs: number | null;
79
+ p50Ms: number | null;
80
+ p90Ms: number | null;
81
+ p99Ms: number | null;
82
+ /** Bucket0 <1ms; buckets1..16 powers of two; bucket17 >=65536ms. */
83
+ histogram: TerminalRuntimeHistogram;
84
+ };
85
+ /** Decoded runner execute-envelope UTF-8 bytes, not upstream wire bytes or RSS. */
86
+ export type TerminalRuntimeToolResponseBodyAdmission = {
87
+ turns: number;
88
+ measuredTurns: number;
89
+ decodedUtf8BytesTotal: number;
90
+ decodedUtf8BytesMax: number;
91
+ /** Peak simultaneous expected-or-measured gate reservations. */
92
+ permitBytesPeak: number;
93
+ /** Delayed requests may abort before admission; refusals may repeat. */
94
+ queuedTurns: number;
95
+ budgetRefusals: number;
96
+ progressAdmissions: number;
97
+ unpricedAdmissions: number;
98
+ };
99
+ export type TerminalRuntimePerformance = TerminalRuntimeSegment & {
100
+ scope: 'terminal_attempt';
101
+ process: {
102
+ cpuUserMs: number;
103
+ cpuSystemMs: number;
104
+ rssBytes: number | null;
105
+ maxRssBytes: number | null;
106
+ heapUsedBytes: number | null;
107
+ externalBytes: number | null;
108
+ };
109
+ counters: {
110
+ logicalCalls: number;
111
+ providerRequests: number;
112
+ provider429s: number;
113
+ };
114
+ phases: Partial<Record<TerminalRuntimePhase, TerminalRuntimeDistribution>>;
115
+ /** Maximum individual map peak; not a sum or simultaneous whole-run peak. */
116
+ rows: { mapCount: number; maxIndividualMapActiveRowPeak: number };
117
+ /** Missing means an older/partial producer, never measured zero bytes. */
118
+ memoryAdmission?: {
119
+ toolResponseBody: TerminalRuntimeToolResponseBodyAdmission;
120
+ };
121
+ };
122
+ function record(value: unknown): Record<string, unknown> | undefined {
123
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
124
+ ? (value as Record<string, unknown>)
125
+ : undefined;
126
+ }
127
+ function finite(value: unknown): value is number {
128
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0;
129
+ }
130
+ function count(value: unknown): value is number {
131
+ return finite(value) && Number.isSafeInteger(value);
132
+ }
133
+ function nullable(value: unknown): value is number | null {
134
+ return value === null || finite(value);
135
+ }
136
+ function segment(
137
+ value: Record<string, unknown>,
138
+ ): TerminalRuntimeSegment | undefined {
139
+ if (
140
+ !count(value.attempt) ||
141
+ !count(value.invocationSeq) ||
142
+ value.invocationSeq === 0 ||
143
+ typeof value.segmentId !== 'string' ||
144
+ !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
145
+ value.segmentId,
146
+ )
147
+ )
148
+ return undefined;
149
+ return {
150
+ attempt: value.attempt,
151
+ invocationSeq: value.invocationSeq,
152
+ segmentId: value.segmentId,
153
+ };
154
+ }
155
+ function distribution(value: unknown): TerminalRuntimeDistribution | undefined {
156
+ const v = record(value);
157
+ if (
158
+ !v ||
159
+ !count(v.count) ||
160
+ !finite(v.totalMs) ||
161
+ !nullable(v.maxMs) ||
162
+ !nullable(v.ewmaMs) ||
163
+ !nullable(v.p50Ms) ||
164
+ !nullable(v.p90Ms) ||
165
+ !nullable(v.p99Ms) ||
166
+ !Array.isArray(v.histogram) ||
167
+ v.histogram.length !== 18 ||
168
+ !v.histogram.every(count)
169
+ )
170
+ return undefined;
171
+ if (v.histogram.reduce((a: number, b: number) => a + b, 0) !== v.count)
172
+ return undefined;
173
+ if (
174
+ v.count === 0
175
+ ? v.totalMs !== 0 ||
176
+ [v.maxMs, v.ewmaMs, v.p50Ms, v.p90Ms, v.p99Ms].some((x) => x !== null)
177
+ : [v.maxMs, v.ewmaMs, v.p50Ms, v.p90Ms, v.p99Ms].some((x) => x === null)
178
+ )
179
+ return undefined;
180
+ if (
181
+ v.p50Ms !== null &&
182
+ v.p90Ms !== null &&
183
+ v.p99Ms !== null &&
184
+ v.maxMs !== null &&
185
+ !(v.p50Ms <= v.p90Ms && v.p90Ms <= v.p99Ms && v.p99Ms <= v.maxMs)
186
+ )
187
+ return undefined;
188
+ return {
189
+ count: v.count,
190
+ totalMs: v.totalMs,
191
+ maxMs: v.maxMs,
192
+ ewmaMs: v.ewmaMs,
193
+ p50Ms: v.p50Ms,
194
+ p90Ms: v.p90Ms,
195
+ p99Ms: v.p99Ms,
196
+ histogram: [...v.histogram] as TerminalRuntimeHistogram,
197
+ };
198
+ }
199
+ function toolResponseBodyAdmission(
200
+ value: unknown,
201
+ ): TerminalRuntimeToolResponseBodyAdmission | undefined {
202
+ const v = record(value);
203
+ if (
204
+ !v ||
205
+ !count(v.turns) ||
206
+ !count(v.measuredTurns) ||
207
+ !count(v.decodedUtf8BytesTotal) ||
208
+ !count(v.decodedUtf8BytesMax) ||
209
+ !count(v.permitBytesPeak) ||
210
+ !count(v.queuedTurns) ||
211
+ !count(v.budgetRefusals) ||
212
+ !count(v.progressAdmissions) ||
213
+ !count(v.unpricedAdmissions)
214
+ )
215
+ return undefined;
216
+ if (
217
+ v.measuredTurns > v.turns ||
218
+ v.progressAdmissions + v.unpricedAdmissions > v.turns ||
219
+ (v.measuredTurns === 0 &&
220
+ (v.decodedUtf8BytesTotal !== 0 || v.decodedUtf8BytesMax !== 0)) ||
221
+ v.decodedUtf8BytesMax > v.decodedUtf8BytesTotal ||
222
+ v.decodedUtf8BytesTotal > v.decodedUtf8BytesMax * v.measuredTurns ||
223
+ v.decodedUtf8BytesMax > v.permitBytesPeak
224
+ )
225
+ return undefined;
226
+ return {
227
+ turns: v.turns,
228
+ measuredTurns: v.measuredTurns,
229
+ decodedUtf8BytesTotal: v.decodedUtf8BytesTotal,
230
+ decodedUtf8BytesMax: v.decodedUtf8BytesMax,
231
+ permitBytesPeak: v.permitBytesPeak,
232
+ queuedTurns: v.queuedTurns,
233
+ budgetRefusals: v.budgetRefusals,
234
+ progressAdmissions: v.progressAdmissions,
235
+ unpricedAdmissions: v.unpricedAdmissions,
236
+ };
237
+ }
238
+ /** Reconstruct known fixed fields; unknown keys never enter the public document. */
239
+ export function normalizeTerminalRuntimePerformance(
240
+ value: unknown,
241
+ expectedSegment?: TerminalRuntimeSegment,
242
+ ): TerminalRuntimePerformance | undefined {
243
+ const v = record(value);
244
+ if (!v || v.scope !== 'terminal_attempt') return undefined;
245
+ const identity = segment(v);
246
+ if (
247
+ !identity ||
248
+ (expectedSegment &&
249
+ (identity.attempt !== expectedSegment.attempt ||
250
+ identity.invocationSeq !== expectedSegment.invocationSeq ||
251
+ identity.segmentId !== expectedSegment.segmentId))
252
+ )
253
+ return undefined;
254
+ const p = record(v.process),
255
+ c = record(v.counters),
256
+ rows = record(v.rows),
257
+ rawPhases = record(v.phases);
258
+ if (
259
+ !p ||
260
+ !finite(p.cpuUserMs) ||
261
+ !finite(p.cpuSystemMs) ||
262
+ !nullable(p.rssBytes) ||
263
+ !nullable(p.maxRssBytes) ||
264
+ !nullable(p.heapUsedBytes) ||
265
+ !nullable(p.externalBytes) ||
266
+ !c ||
267
+ !count(c.logicalCalls) ||
268
+ !count(c.providerRequests) ||
269
+ !count(c.provider429s) ||
270
+ !rows ||
271
+ !count(rows.mapCount) ||
272
+ !count(rows.maxIndividualMapActiveRowPeak) ||
273
+ !rawPhases
274
+ )
275
+ return undefined;
276
+ const phases: TerminalRuntimePerformance['phases'] = {};
277
+ for (const key of TERMINAL_RUNTIME_PHASES) {
278
+ if (!Object.hasOwn(rawPhases, key)) continue;
279
+ const phase = distribution(rawPhases[key]);
280
+ if (!phase) return undefined;
281
+ phases[key] = phase;
282
+ }
283
+ let memoryAdmission: TerminalRuntimePerformance['memoryAdmission'];
284
+ if (Object.hasOwn(v, 'memoryAdmission')) {
285
+ const rawMemory = record(v.memoryAdmission);
286
+ if (!rawMemory) return undefined;
287
+ if (Object.hasOwn(rawMemory, 'toolResponseBody')) {
288
+ const body = toolResponseBodyAdmission(rawMemory.toolResponseBody);
289
+ if (!body) return undefined;
290
+ memoryAdmission = { toolResponseBody: body };
291
+ }
292
+ }
293
+ return {
294
+ scope: 'terminal_attempt',
295
+ ...identity,
296
+ process: {
297
+ cpuUserMs: p.cpuUserMs,
298
+ cpuSystemMs: p.cpuSystemMs,
299
+ rssBytes: p.rssBytes,
300
+ maxRssBytes: p.maxRssBytes,
301
+ heapUsedBytes: p.heapUsedBytes,
302
+ externalBytes: p.externalBytes,
303
+ },
304
+ counters: {
305
+ logicalCalls: c.logicalCalls,
306
+ providerRequests: c.providerRequests,
307
+ provider429s: c.provider429s,
308
+ },
309
+ phases,
310
+ rows: {
311
+ mapCount: rows.mapCount,
312
+ maxIndividualMapActiveRowPeak: rows.maxIndividualMapActiveRowPeak,
313
+ },
314
+ ...(memoryAdmission ? { memoryAdmission } : {}),
315
+ };
316
+ }
317
+ export function normalizeTerminalRuntimePerformanceUnavailableReason(
318
+ value: unknown,
319
+ ): TerminalRuntimePerformanceUnavailableReason | undefined {
320
+ return value === 'invalid_runner_stats' ||
321
+ value === 'invalid_terminal_performance'
322
+ ? value
323
+ : undefined;
324
+ }
325
+ /** Canonical Context.getStats() + scheduler-injected identity, never authored output. */
326
+ export function terminalRuntimePerformanceFromStats(
327
+ stats: unknown,
328
+ identity: TerminalRuntimeSegment,
329
+ ): TerminalRuntimePerformance | undefined {
330
+ const root = record(stats),
331
+ resources = record(root?.runtimeResources),
332
+ rawPhases = record(resources?.phases),
333
+ maps = record(resources?.mapAdmission);
334
+ const counters = runtimeWorkCountersFromStats(stats);
335
+ if (
336
+ !resources ||
337
+ !rawPhases ||
338
+ !maps ||
339
+ !counters ||
340
+ counters.provider429s === undefined
341
+ )
342
+ return undefined;
343
+ const phases: Record<string, unknown> = {};
344
+ for (const key of TERMINAL_RUNTIME_PHASES) {
345
+ if (!Object.hasOwn(rawPhases, key)) continue;
346
+ const raw = record(rawPhases[key]);
347
+ if (!raw || !Array.isArray(raw.buckets)) return undefined;
348
+ const histogram: number[] = Array(18).fill(0);
349
+ for (const bucket of raw.buckets) {
350
+ if (
351
+ !Array.isArray(bucket) ||
352
+ bucket.length !== 2 ||
353
+ !count(bucket[0]) ||
354
+ bucket[0] >= 18 ||
355
+ !count(bucket[1]) ||
356
+ bucket[1] === 0 ||
357
+ histogram[bucket[0]] !== 0
358
+ )
359
+ return undefined;
360
+ histogram[bucket[0]] = bucket[1];
361
+ }
362
+ phases[key] = { ...raw, histogram };
363
+ }
364
+ let mapCount = 0,
365
+ maxIndividualMapActiveRowPeak = 0;
366
+ // Scan every canonical map; no map names or scaling collections are retained.
367
+ for (const key in maps) {
368
+ if (!Object.hasOwn(maps, key)) continue;
369
+ const map = record(maps[key]);
370
+ if (!map || !count(map.activeRowPeak)) return undefined;
371
+ mapCount += 1;
372
+ maxIndividualMapActiveRowPeak = Math.max(
373
+ maxIndividualMapActiveRowPeak,
374
+ map.activeRowPeak,
375
+ );
376
+ }
377
+ return normalizeTerminalRuntimePerformance(
378
+ {
379
+ scope: 'terminal_attempt',
380
+ ...identity,
381
+ process: resources.process,
382
+ counters,
383
+ phases,
384
+ rows: { mapCount, maxIndividualMapActiveRowPeak },
385
+ ...(Object.hasOwn(resources, 'memoryAdmission')
386
+ ? { memoryAdmission: resources.memoryAdmission }
387
+ : {}),
388
+ },
389
+ identity,
390
+ );
391
+ }