@sema-agent/server 1.185.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (765) hide show
  1. package/LICENSE +102 -0
  2. package/README.md +207 -0
  3. package/deploy/sema-up/README.md +145 -0
  4. package/deploy/sema-up/chart/Chart.yaml +11 -0
  5. package/deploy/sema-up/chart/templates/gitea.yaml +63 -0
  6. package/deploy/sema-up/chart/templates/minio.yaml +62 -0
  7. package/deploy/sema-up/chart/templates/namespace-sandbox.yaml +9 -0
  8. package/deploy/sema-up/chart/templates/pg-cluster.yaml +57 -0
  9. package/deploy/sema-up/chart/templates/registry.yaml +88 -0
  10. package/deploy/sema-up/chart/templates/sandbox-rbac.yaml +45 -0
  11. package/deploy/sema-up/chart/templates/server-v4pro.yaml +76 -0
  12. package/deploy/sema-up/chart/templates/server.yaml +88 -0
  13. package/deploy/sema-up/chart/values-full-single.yaml +9 -0
  14. package/deploy/sema-up/chart/values.yaml +100 -0
  15. package/deploy/sema-up/cluster-up.sh +432 -0
  16. package/deploy/sema-up/kube-up.sh +377 -0
  17. package/deploy/sema-up/lib/parse-machines.py +117 -0
  18. package/deploy/sema-up/machines.example.yaml +53 -0
  19. package/deploy/sema-up/preflight.sh +168 -0
  20. package/deploy/sema-up/sema-up.sh +758 -0
  21. package/deploy/sema-up/smoke.sh +100 -0
  22. package/deploy/sema-up/stack/compose.dataroot.yaml +16 -0
  23. package/deploy/sema-up/stack/compose.yaml +155 -0
  24. package/deploy/sema-up/stack/sema-stack-cluster.yaml +189 -0
  25. package/dist/approval.d.ts +27 -0
  26. package/dist/approval.d.ts.map +1 -0
  27. package/dist/approval.js +127 -0
  28. package/dist/approval.js.map +1 -0
  29. package/dist/audit.d.ts +29 -0
  30. package/dist/audit.d.ts.map +1 -0
  31. package/dist/audit.js +95 -0
  32. package/dist/audit.js.map +1 -0
  33. package/dist/auth-bridge.d.ts +29 -0
  34. package/dist/auth-bridge.d.ts.map +1 -0
  35. package/dist/auth-bridge.js +145 -0
  36. package/dist/auth-bridge.js.map +1 -0
  37. package/dist/bake-runner/main.d.ts +20 -0
  38. package/dist/bake-runner/main.d.ts.map +1 -0
  39. package/dist/bake-runner/main.js +216 -0
  40. package/dist/bake-runner/main.js.map +1 -0
  41. package/dist/bake-runner/protocol.d.ts +49 -0
  42. package/dist/bake-runner/protocol.d.ts.map +1 -0
  43. package/dist/bake-runner/protocol.js +86 -0
  44. package/dist/bake-runner/protocol.js.map +1 -0
  45. package/dist/bake-runner/runner.d.ts +86 -0
  46. package/dist/bake-runner/runner.d.ts.map +1 -0
  47. package/dist/bake-runner/runner.js +228 -0
  48. package/dist/bake-runner/runner.js.map +1 -0
  49. package/dist/bench/l8/artifact.d.ts +62 -0
  50. package/dist/bench/l8/artifact.d.ts.map +1 -0
  51. package/dist/bench/l8/artifact.js +129 -0
  52. package/dist/bench/l8/artifact.js.map +1 -0
  53. package/dist/bench/l8/escape.d.ts +18 -0
  54. package/dist/bench/l8/escape.d.ts.map +1 -0
  55. package/dist/bench/l8/escape.js +9 -0
  56. package/dist/bench/l8/escape.js.map +1 -0
  57. package/dist/bench/l8/index.d.ts +5 -0
  58. package/dist/bench/l8/index.d.ts.map +1 -0
  59. package/dist/bench/l8/index.js +5 -0
  60. package/dist/bench/l8/index.js.map +1 -0
  61. package/dist/bench/l8/probes.d.ts +75 -0
  62. package/dist/bench/l8/probes.d.ts.map +1 -0
  63. package/dist/bench/l8/probes.js +178 -0
  64. package/dist/bench/l8/probes.js.map +1 -0
  65. package/dist/bench/l8/run-probes.d.ts +21 -0
  66. package/dist/bench/l8/run-probes.d.ts.map +1 -0
  67. package/dist/bench/l8/run-probes.js +130 -0
  68. package/dist/bench/l8/run-probes.js.map +1 -0
  69. package/dist/bench/s1/arms.d.ts +84 -0
  70. package/dist/bench/s1/arms.d.ts.map +1 -0
  71. package/dist/bench/s1/arms.js +329 -0
  72. package/dist/bench/s1/arms.js.map +1 -0
  73. package/dist/bench/s1/live-deps.d.ts +25 -0
  74. package/dist/bench/s1/live-deps.d.ts.map +1 -0
  75. package/dist/bench/s1/live-deps.js +449 -0
  76. package/dist/bench/s1/live-deps.js.map +1 -0
  77. package/dist/bench/s1/oracle.d.ts +34 -0
  78. package/dist/bench/s1/oracle.d.ts.map +1 -0
  79. package/dist/bench/s1/oracle.js +29 -0
  80. package/dist/bench/s1/oracle.js.map +1 -0
  81. package/dist/bench/s1/repair-oracle-adapter.d.ts +9 -0
  82. package/dist/bench/s1/repair-oracle-adapter.d.ts.map +1 -0
  83. package/dist/bench/s1/repair-oracle-adapter.js +27 -0
  84. package/dist/bench/s1/repair-oracle-adapter.js.map +1 -0
  85. package/dist/bench/s1/reviewer.d.ts +31 -0
  86. package/dist/bench/s1/reviewer.d.ts.map +1 -0
  87. package/dist/bench/s1/reviewer.js +26 -0
  88. package/dist/bench/s1/reviewer.js.map +1 -0
  89. package/dist/bench/s1/row.d.ts +29 -0
  90. package/dist/bench/s1/row.d.ts.map +1 -0
  91. package/dist/bench/s1/row.js +55 -0
  92. package/dist/bench/s1/row.js.map +1 -0
  93. package/dist/bench/s1/run-firm.d.ts +49 -0
  94. package/dist/bench/s1/run-firm.d.ts.map +1 -0
  95. package/dist/bench/s1/run-firm.js +291 -0
  96. package/dist/bench/s1/run-firm.js.map +1 -0
  97. package/dist/bench/s1/runner-ctx.d.ts +44 -0
  98. package/dist/bench/s1/runner-ctx.d.ts.map +1 -0
  99. package/dist/bench/s1/runner-ctx.js +59 -0
  100. package/dist/bench/s1/runner-ctx.js.map +1 -0
  101. package/dist/bench/s1/tasks.d.ts +48 -0
  102. package/dist/bench/s1/tasks.d.ts.map +1 -0
  103. package/dist/bench/s1/tasks.js +194 -0
  104. package/dist/bench/s1/tasks.js.map +1 -0
  105. package/dist/boot-reclaim.d.ts +10 -0
  106. package/dist/boot-reclaim.d.ts.map +1 -0
  107. package/dist/boot-reclaim.js +13 -0
  108. package/dist/boot-reclaim.js.map +1 -0
  109. package/dist/brain.d.ts +8 -0
  110. package/dist/brain.d.ts.map +1 -0
  111. package/dist/brain.js +83 -0
  112. package/dist/brain.js.map +1 -0
  113. package/dist/budget.d.ts +25 -0
  114. package/dist/budget.d.ts.map +1 -0
  115. package/dist/budget.js +107 -0
  116. package/dist/budget.js.map +1 -0
  117. package/dist/capabilities/builtin-tools.d.ts +3 -0
  118. package/dist/capabilities/builtin-tools.d.ts.map +1 -0
  119. package/dist/capabilities/builtin-tools.js +11 -0
  120. package/dist/capabilities/builtin-tools.js.map +1 -0
  121. package/dist/capabilities/code-review-council.d.ts +21 -0
  122. package/dist/capabilities/code-review-council.d.ts.map +1 -0
  123. package/dist/capabilities/code-review-council.js +113 -0
  124. package/dist/capabilities/code-review-council.js.map +1 -0
  125. package/dist/capabilities/collab-wire.d.ts +34 -0
  126. package/dist/capabilities/collab-wire.d.ts.map +1 -0
  127. package/dist/capabilities/collab-wire.js +2 -0
  128. package/dist/capabilities/collab-wire.js.map +1 -0
  129. package/dist/capabilities/collab-workflows.d.ts +40 -0
  130. package/dist/capabilities/collab-workflows.d.ts.map +1 -0
  131. package/dist/capabilities/collab-workflows.js +90 -0
  132. package/dist/capabilities/collab-workflows.js.map +1 -0
  133. package/dist/capabilities/oa-tools.d.ts +9 -0
  134. package/dist/capabilities/oa-tools.d.ts.map +1 -0
  135. package/dist/capabilities/oa-tools.js +44 -0
  136. package/dist/capabilities/oa-tools.js.map +1 -0
  137. package/dist/capabilities/prompt.d.ts +3 -0
  138. package/dist/capabilities/prompt.d.ts.map +1 -0
  139. package/dist/capabilities/prompt.js +6 -0
  140. package/dist/capabilities/prompt.js.map +1 -0
  141. package/dist/capabilities/prompts/code-review.d.ts +11 -0
  142. package/dist/capabilities/prompts/code-review.d.ts.map +1 -0
  143. package/dist/capabilities/prompts/code-review.js +39 -0
  144. package/dist/capabilities/prompts/code-review.js.map +1 -0
  145. package/dist/capabilities/prompts/identity.d.ts +2 -0
  146. package/dist/capabilities/prompts/identity.d.ts.map +1 -0
  147. package/dist/capabilities/prompts/identity.js +6 -0
  148. package/dist/capabilities/prompts/identity.js.map +1 -0
  149. package/dist/capabilities/prompts/team.d.ts +6 -0
  150. package/dist/capabilities/prompts/team.d.ts.map +1 -0
  151. package/dist/capabilities/prompts/team.js +6 -0
  152. package/dist/capabilities/prompts/team.js.map +1 -0
  153. package/dist/capabilities/repo-tools.d.ts +19 -0
  154. package/dist/capabilities/repo-tools.d.ts.map +1 -0
  155. package/dist/capabilities/repo-tools.js +98 -0
  156. package/dist/capabilities/repo-tools.js.map +1 -0
  157. package/dist/capabilities/scenarios.d.ts +72 -0
  158. package/dist/capabilities/scenarios.d.ts.map +1 -0
  159. package/dist/capabilities/scenarios.js +241 -0
  160. package/dist/capabilities/scenarios.js.map +1 -0
  161. package/dist/capabilities/select-environment-tool.d.ts +22 -0
  162. package/dist/capabilities/select-environment-tool.d.ts.map +1 -0
  163. package/dist/capabilities/select-environment-tool.js +86 -0
  164. package/dist/capabilities/select-environment-tool.js.map +1 -0
  165. package/dist/capabilities/skills.d.ts +12 -0
  166. package/dist/capabilities/skills.d.ts.map +1 -0
  167. package/dist/capabilities/skills.js +50 -0
  168. package/dist/capabilities/skills.js.map +1 -0
  169. package/dist/capabilities/team.d.ts +31 -0
  170. package/dist/capabilities/team.d.ts.map +1 -0
  171. package/dist/capabilities/team.js +66 -0
  172. package/dist/capabilities/team.js.map +1 -0
  173. package/dist/config-provider.d.ts +47 -0
  174. package/dist/config-provider.d.ts.map +1 -0
  175. package/dist/config-provider.js +156 -0
  176. package/dist/config-provider.js.map +1 -0
  177. package/dist/config.d.ts +272 -0
  178. package/dist/config.d.ts.map +1 -0
  179. package/dist/config.js +605 -0
  180. package/dist/config.js.map +1 -0
  181. package/dist/degenerate-instrument.d.ts +17 -0
  182. package/dist/degenerate-instrument.d.ts.map +1 -0
  183. package/dist/degenerate-instrument.js +113 -0
  184. package/dist/degenerate-instrument.js.map +1 -0
  185. package/dist/elicitation.d.ts +47 -0
  186. package/dist/elicitation.d.ts.map +1 -0
  187. package/dist/elicitation.js +151 -0
  188. package/dist/elicitation.js.map +1 -0
  189. package/dist/env-facts.d.ts +18 -0
  190. package/dist/env-facts.d.ts.map +1 -0
  191. package/dist/env-facts.js +26 -0
  192. package/dist/env-facts.js.map +1 -0
  193. package/dist/finance/cost-taxonomy.d.ts +34 -0
  194. package/dist/finance/cost-taxonomy.d.ts.map +1 -0
  195. package/dist/finance/cost-taxonomy.js +26 -0
  196. package/dist/finance/cost-taxonomy.js.map +1 -0
  197. package/dist/fleet/fleet-bus.d.ts +137 -0
  198. package/dist/fleet/fleet-bus.d.ts.map +1 -0
  199. package/dist/fleet/fleet-bus.js +249 -0
  200. package/dist/fleet/fleet-bus.js.map +1 -0
  201. package/dist/fleet-client.d.ts +50 -0
  202. package/dist/fleet-client.d.ts.map +1 -0
  203. package/dist/fleet-client.js +150 -0
  204. package/dist/fleet-client.js.map +1 -0
  205. package/dist/fleet-lease.d.ts +76 -0
  206. package/dist/fleet-lease.d.ts.map +1 -0
  207. package/dist/fleet-lease.js +124 -0
  208. package/dist/fleet-lease.js.map +1 -0
  209. package/dist/hooks/hook-runner.d.ts +41 -0
  210. package/dist/hooks/hook-runner.d.ts.map +1 -0
  211. package/dist/hooks/hook-runner.js +975 -0
  212. package/dist/hooks/hook-runner.js.map +1 -0
  213. package/dist/http/idempotency.d.ts +12 -0
  214. package/dist/http/idempotency.d.ts.map +1 -0
  215. package/dist/http/idempotency.js +49 -0
  216. package/dist/http/idempotency.js.map +1 -0
  217. package/dist/http/server.d.ts +185 -0
  218. package/dist/http/server.d.ts.map +1 -0
  219. package/dist/http/server.js +4845 -0
  220. package/dist/http/server.js.map +1 -0
  221. package/dist/http/wire-gate.d.ts +3 -0
  222. package/dist/http/wire-gate.d.ts.map +1 -0
  223. package/dist/http/wire-gate.js +6 -0
  224. package/dist/http/wire-gate.js.map +1 -0
  225. package/dist/images/bake-validate.d.ts +41 -0
  226. package/dist/images/bake-validate.d.ts.map +1 -0
  227. package/dist/images/bake-validate.js +183 -0
  228. package/dist/images/bake-validate.js.map +1 -0
  229. package/dist/images/manifest.d.ts +36 -0
  230. package/dist/images/manifest.d.ts.map +1 -0
  231. package/dist/images/manifest.js +69 -0
  232. package/dist/images/manifest.js.map +1 -0
  233. package/dist/index.d.ts +25 -0
  234. package/dist/index.d.ts.map +1 -0
  235. package/dist/index.js +25 -0
  236. package/dist/index.js.map +1 -0
  237. package/dist/key-resolver.d.ts +5 -0
  238. package/dist/key-resolver.d.ts.map +1 -0
  239. package/dist/key-resolver.js +15 -0
  240. package/dist/key-resolver.js.map +1 -0
  241. package/dist/leader/diffout.d.ts +24 -0
  242. package/dist/leader/diffout.d.ts.map +1 -0
  243. package/dist/leader/diffout.js +54 -0
  244. package/dist/leader/diffout.js.map +1 -0
  245. package/dist/leader/diffup.d.ts +14 -0
  246. package/dist/leader/diffup.d.ts.map +1 -0
  247. package/dist/leader/diffup.js +81 -0
  248. package/dist/leader/diffup.js.map +1 -0
  249. package/dist/leader/endpoint.d.ts +30 -0
  250. package/dist/leader/endpoint.d.ts.map +1 -0
  251. package/dist/leader/endpoint.js +76 -0
  252. package/dist/leader/endpoint.js.map +1 -0
  253. package/dist/leader/fanout.d.ts +46 -0
  254. package/dist/leader/fanout.d.ts.map +1 -0
  255. package/dist/leader/fanout.js +109 -0
  256. package/dist/leader/fanout.js.map +1 -0
  257. package/dist/leader/grader-env-factory.d.ts +36 -0
  258. package/dist/leader/grader-env-factory.d.ts.map +1 -0
  259. package/dist/leader/grader-env-factory.js +73 -0
  260. package/dist/leader/grader-env-factory.js.map +1 -0
  261. package/dist/leader/leader.d.ts +102 -0
  262. package/dist/leader/leader.d.ts.map +1 -0
  263. package/dist/leader/leader.js +354 -0
  264. package/dist/leader/leader.js.map +1 -0
  265. package/dist/leader/merge.d.ts +109 -0
  266. package/dist/leader/merge.d.ts.map +1 -0
  267. package/dist/leader/merge.js +184 -0
  268. package/dist/leader/merge.js.map +1 -0
  269. package/dist/leader/planner.d.ts +26 -0
  270. package/dist/leader/planner.d.ts.map +1 -0
  271. package/dist/leader/planner.js +137 -0
  272. package/dist/leader/planner.js.map +1 -0
  273. package/dist/leader/repair-oracle.d.ts +34 -0
  274. package/dist/leader/repair-oracle.d.ts.map +1 -0
  275. package/dist/leader/repair-oracle.js +83 -0
  276. package/dist/leader/repair-oracle.js.map +1 -0
  277. package/dist/leader/repair-wire.d.ts +49 -0
  278. package/dist/leader/repair-wire.d.ts.map +1 -0
  279. package/dist/leader/repair-wire.js +90 -0
  280. package/dist/leader/repair-wire.js.map +1 -0
  281. package/dist/leader/wire.d.ts +66 -0
  282. package/dist/leader/wire.d.ts.map +1 -0
  283. package/dist/leader/wire.js +452 -0
  284. package/dist/leader/wire.js.map +1 -0
  285. package/dist/lsp/e2b-bridge.d.ts +8 -0
  286. package/dist/lsp/e2b-bridge.d.ts.map +1 -0
  287. package/dist/lsp/e2b-bridge.js +71 -0
  288. package/dist/lsp/e2b-bridge.js.map +1 -0
  289. package/dist/lsp/e2b-manager.d.ts +16 -0
  290. package/dist/lsp/e2b-manager.d.ts.map +1 -0
  291. package/dist/lsp/e2b-manager.js +49 -0
  292. package/dist/lsp/e2b-manager.js.map +1 -0
  293. package/dist/lsp/lsp-frames.d.ts +2 -0
  294. package/dist/lsp/lsp-frames.d.ts.map +1 -0
  295. package/dist/lsp/lsp-frames.js +25 -0
  296. package/dist/lsp/lsp-frames.js.map +1 -0
  297. package/dist/lsp/manager.d.ts +41 -0
  298. package/dist/lsp/manager.d.ts.map +1 -0
  299. package/dist/lsp/manager.js +84 -0
  300. package/dist/lsp/manager.js.map +1 -0
  301. package/dist/lsp/types.d.ts +2 -0
  302. package/dist/lsp/types.d.ts.map +1 -0
  303. package/dist/lsp/types.js +2 -0
  304. package/dist/lsp/types.js.map +1 -0
  305. package/dist/lsp/ws-transport.d.ts +28 -0
  306. package/dist/lsp/ws-transport.d.ts.map +1 -0
  307. package/dist/lsp/ws-transport.js +209 -0
  308. package/dist/lsp/ws-transport.js.map +1 -0
  309. package/dist/lsp-evict.d.ts +2 -0
  310. package/dist/lsp-evict.d.ts.map +1 -0
  311. package/dist/lsp-evict.js +14 -0
  312. package/dist/lsp-evict.js.map +1 -0
  313. package/dist/main.d.ts +2 -0
  314. package/dist/main.d.ts.map +1 -0
  315. package/dist/main.js +1526 -0
  316. package/dist/main.js.map +1 -0
  317. package/dist/memory-export.d.ts +3 -0
  318. package/dist/memory-export.d.ts.map +1 -0
  319. package/dist/memory-export.js +8 -0
  320. package/dist/memory-export.js.map +1 -0
  321. package/dist/memory-sync-client.d.ts +29 -0
  322. package/dist/memory-sync-client.d.ts.map +1 -0
  323. package/dist/memory-sync-client.js +133 -0
  324. package/dist/memory-sync-client.js.map +1 -0
  325. package/dist/memory-sync.d.ts +41 -0
  326. package/dist/memory-sync.d.ts.map +1 -0
  327. package/dist/memory-sync.js +183 -0
  328. package/dist/memory-sync.js.map +1 -0
  329. package/dist/model-select.d.ts +8 -0
  330. package/dist/model-select.d.ts.map +1 -0
  331. package/dist/model-select.js +12 -0
  332. package/dist/model-select.js.map +1 -0
  333. package/dist/observability/cost-quota.d.ts +21 -0
  334. package/dist/observability/cost-quota.d.ts.map +1 -0
  335. package/dist/observability/cost-quota.js +42 -0
  336. package/dist/observability/cost-quota.js.map +1 -0
  337. package/dist/observability/logger.d.ts +9 -0
  338. package/dist/observability/logger.d.ts.map +1 -0
  339. package/dist/observability/logger.js +35 -0
  340. package/dist/observability/logger.js.map +1 -0
  341. package/dist/observability/metrics.d.ts +76 -0
  342. package/dist/observability/metrics.d.ts.map +1 -0
  343. package/dist/observability/metrics.js +263 -0
  344. package/dist/observability/metrics.js.map +1 -0
  345. package/dist/observability/otel-exporter.d.ts +37 -0
  346. package/dist/observability/otel-exporter.d.ts.map +1 -0
  347. package/dist/observability/otel-exporter.js +95 -0
  348. package/dist/observability/otel-exporter.js.map +1 -0
  349. package/dist/observability/principal-context.d.ts +5 -0
  350. package/dist/observability/principal-context.d.ts.map +1 -0
  351. package/dist/observability/principal-context.js +9 -0
  352. package/dist/observability/principal-context.js.map +1 -0
  353. package/dist/observability/rate-limit.d.ts +18 -0
  354. package/dist/observability/rate-limit.d.ts.map +1 -0
  355. package/dist/observability/rate-limit.js +30 -0
  356. package/dist/observability/rate-limit.js.map +1 -0
  357. package/dist/observability/tool-trace.d.ts +6 -0
  358. package/dist/observability/tool-trace.d.ts.map +1 -0
  359. package/dist/observability/tool-trace.js +73 -0
  360. package/dist/observability/tool-trace.js.map +1 -0
  361. package/dist/orchestration/hardened-vm-runner.d.ts +26 -0
  362. package/dist/orchestration/hardened-vm-runner.d.ts.map +1 -0
  363. package/dist/orchestration/hardened-vm-runner.js +217 -0
  364. package/dist/orchestration/hardened-vm-runner.js.map +1 -0
  365. package/dist/orchestration/hardened-vm-worker-runner.d.ts +4 -0
  366. package/dist/orchestration/hardened-vm-worker-runner.d.ts.map +1 -0
  367. package/dist/orchestration/hardened-vm-worker-runner.js +79 -0
  368. package/dist/orchestration/hardened-vm-worker-runner.js.map +1 -0
  369. package/dist/orchestration/hardened-vm-worker.d.ts +2 -0
  370. package/dist/orchestration/hardened-vm-worker.d.ts.map +1 -0
  371. package/dist/orchestration/hardened-vm-worker.js +80 -0
  372. package/dist/orchestration/hardened-vm-worker.js.map +1 -0
  373. package/dist/orchestration/subagent-steer.d.ts +12 -0
  374. package/dist/orchestration/subagent-steer.d.ts.map +1 -0
  375. package/dist/orchestration/subagent-steer.js +45 -0
  376. package/dist/orchestration/subagent-steer.js.map +1 -0
  377. package/dist/orchestration/workflow-agent-steer.d.ts +14 -0
  378. package/dist/orchestration/workflow-agent-steer.d.ts.map +1 -0
  379. package/dist/orchestration/workflow-agent-steer.js +41 -0
  380. package/dist/orchestration/workflow-agent-steer.js.map +1 -0
  381. package/dist/orchestration/workflow-completion-inbox.d.ts +101 -0
  382. package/dist/orchestration/workflow-completion-inbox.d.ts.map +1 -0
  383. package/dist/orchestration/workflow-completion-inbox.js +327 -0
  384. package/dist/orchestration/workflow-completion-inbox.js.map +1 -0
  385. package/dist/orchestration/workflow-notify-journal.d.ts +120 -0
  386. package/dist/orchestration/workflow-notify-journal.d.ts.map +1 -0
  387. package/dist/orchestration/workflow-notify-journal.js +297 -0
  388. package/dist/orchestration/workflow-notify-journal.js.map +1 -0
  389. package/dist/per-task-image.d.ts +27 -0
  390. package/dist/per-task-image.d.ts.map +1 -0
  391. package/dist/per-task-image.js +37 -0
  392. package/dist/per-task-image.js.map +1 -0
  393. package/dist/plan-cache-probe.d.ts +21 -0
  394. package/dist/plan-cache-probe.d.ts.map +1 -0
  395. package/dist/plan-cache-probe.js +79 -0
  396. package/dist/plan-cache-probe.js.map +1 -0
  397. package/dist/plugins/approval-exemption-store.d.ts +56 -0
  398. package/dist/plugins/approval-exemption-store.d.ts.map +1 -0
  399. package/dist/plugins/approval-exemption-store.js +216 -0
  400. package/dist/plugins/approval-exemption-store.js.map +1 -0
  401. package/dist/plugins/background-shell-support.d.ts +64 -0
  402. package/dist/plugins/background-shell-support.d.ts.map +1 -0
  403. package/dist/plugins/background-shell-support.js +235 -0
  404. package/dist/plugins/background-shell-support.js.map +1 -0
  405. package/dist/plugins/blob-backend.d.ts +44 -0
  406. package/dist/plugins/blob-backend.d.ts.map +1 -0
  407. package/dist/plugins/blob-backend.js +188 -0
  408. package/dist/plugins/blob-backend.js.map +1 -0
  409. package/dist/plugins/caching-session-store.d.ts +51 -0
  410. package/dist/plugins/caching-session-store.d.ts.map +1 -0
  411. package/dist/plugins/caching-session-store.js +142 -0
  412. package/dist/plugins/caching-session-store.js.map +1 -0
  413. package/dist/plugins/file-outcome-sink.d.ts +20 -0
  414. package/dist/plugins/file-outcome-sink.d.ts.map +1 -0
  415. package/dist/plugins/file-outcome-sink.js +14 -0
  416. package/dist/plugins/file-outcome-sink.js.map +1 -0
  417. package/dist/plugins/file-resume-anchor-store.d.ts +19 -0
  418. package/dist/plugins/file-resume-anchor-store.d.ts.map +1 -0
  419. package/dist/plugins/file-resume-anchor-store.js +103 -0
  420. package/dist/plugins/file-resume-anchor-store.js.map +1 -0
  421. package/dist/plugins/file-run-store.d.ts +95 -0
  422. package/dist/plugins/file-run-store.d.ts.map +1 -0
  423. package/dist/plugins/file-run-store.js +446 -0
  424. package/dist/plugins/file-run-store.js.map +1 -0
  425. package/dist/plugins/file-workflow-journal-store.d.ts +2 -0
  426. package/dist/plugins/file-workflow-journal-store.d.ts.map +1 -0
  427. package/dist/plugins/file-workflow-journal-store.js +2 -0
  428. package/dist/plugins/file-workflow-journal-store.js.map +1 -0
  429. package/dist/plugins/host-platform.d.ts +19 -0
  430. package/dist/plugins/host-platform.d.ts.map +1 -0
  431. package/dist/plugins/host-platform.js +71 -0
  432. package/dist/plugins/host-platform.js.map +1 -0
  433. package/dist/plugins/local-checkpoint-store.d.ts +41 -0
  434. package/dist/plugins/local-checkpoint-store.d.ts.map +1 -0
  435. package/dist/plugins/local-checkpoint-store.js +217 -0
  436. package/dist/plugins/local-checkpoint-store.js.map +1 -0
  437. package/dist/plugins/local-session-store.d.ts +69 -0
  438. package/dist/plugins/local-session-store.d.ts.map +1 -0
  439. package/dist/plugins/local-session-store.js +431 -0
  440. package/dist/plugins/local-session-store.js.map +1 -0
  441. package/dist/plugins/memory-engine-pg.d.ts +47 -0
  442. package/dist/plugins/memory-engine-pg.d.ts.map +1 -0
  443. package/dist/plugins/memory-engine-pg.js +306 -0
  444. package/dist/plugins/memory-engine-pg.js.map +1 -0
  445. package/dist/plugins/memory-engine-tidb.d.ts +40 -0
  446. package/dist/plugins/memory-engine-tidb.d.ts.map +1 -0
  447. package/dist/plugins/memory-engine-tidb.js +296 -0
  448. package/dist/plugins/memory-engine-tidb.js.map +1 -0
  449. package/dist/plugins/memory-engine-vector-util.d.ts +2 -0
  450. package/dist/plugins/memory-engine-vector-util.d.ts.map +1 -0
  451. package/dist/plugins/memory-engine-vector-util.js +2 -0
  452. package/dist/plugins/memory-engine-vector-util.js.map +1 -0
  453. package/dist/plugins/memory-resume-anchor-store.d.ts +12 -0
  454. package/dist/plugins/memory-resume-anchor-store.d.ts.map +1 -0
  455. package/dist/plugins/memory-resume-anchor-store.js +31 -0
  456. package/dist/plugins/memory-resume-anchor-store.js.map +1 -0
  457. package/dist/plugins/memory-run-store.d.ts +75 -0
  458. package/dist/plugins/memory-run-store.d.ts.map +1 -0
  459. package/dist/plugins/memory-run-store.js +267 -0
  460. package/dist/plugins/memory-run-store.js.map +1 -0
  461. package/dist/plugins/memory-sync-store-pg.d.ts +78 -0
  462. package/dist/plugins/memory-sync-store-pg.d.ts.map +1 -0
  463. package/dist/plugins/memory-sync-store-pg.js +152 -0
  464. package/dist/plugins/memory-sync-store-pg.js.map +1 -0
  465. package/dist/plugins/memory-sync-store-tidb.d.ts +32 -0
  466. package/dist/plugins/memory-sync-store-tidb.d.ts.map +1 -0
  467. package/dist/plugins/memory-sync-store-tidb.js +146 -0
  468. package/dist/plugins/memory-sync-store-tidb.js.map +1 -0
  469. package/dist/plugins/pg-approval-store.d.ts +28 -0
  470. package/dist/plugins/pg-approval-store.d.ts.map +1 -0
  471. package/dist/plugins/pg-approval-store.js +107 -0
  472. package/dist/plugins/pg-approval-store.js.map +1 -0
  473. package/dist/plugins/pg-breaker-state.d.ts +20 -0
  474. package/dist/plugins/pg-breaker-state.d.ts.map +1 -0
  475. package/dist/plugins/pg-breaker-state.js +89 -0
  476. package/dist/plugins/pg-breaker-state.js.map +1 -0
  477. package/dist/plugins/pg-checkpoint-store.d.ts +34 -0
  478. package/dist/plugins/pg-checkpoint-store.d.ts.map +1 -0
  479. package/dist/plugins/pg-checkpoint-store.js +193 -0
  480. package/dist/plugins/pg-checkpoint-store.js.map +1 -0
  481. package/dist/plugins/pg-cost-quota.d.ts +18 -0
  482. package/dist/plugins/pg-cost-quota.d.ts.map +1 -0
  483. package/dist/plugins/pg-cost-quota.js +189 -0
  484. package/dist/plugins/pg-cost-quota.js.map +1 -0
  485. package/dist/plugins/pg-file-snapshot-store.d.ts +26 -0
  486. package/dist/plugins/pg-file-snapshot-store.d.ts.map +1 -0
  487. package/dist/plugins/pg-file-snapshot-store.js +181 -0
  488. package/dist/plugins/pg-file-snapshot-store.js.map +1 -0
  489. package/dist/plugins/pg-image-bake.d.ts +42 -0
  490. package/dist/plugins/pg-image-bake.d.ts.map +1 -0
  491. package/dist/plugins/pg-image-bake.js +471 -0
  492. package/dist/plugins/pg-image-bake.js.map +1 -0
  493. package/dist/plugins/pg-image-index.d.ts +23 -0
  494. package/dist/plugins/pg-image-index.d.ts.map +1 -0
  495. package/dist/plugins/pg-image-index.js +252 -0
  496. package/dist/plugins/pg-image-index.js.map +1 -0
  497. package/dist/plugins/pg-outcome-ledger.d.ts +23 -0
  498. package/dist/plugins/pg-outcome-ledger.d.ts.map +1 -0
  499. package/dist/plugins/pg-outcome-ledger.js +102 -0
  500. package/dist/plugins/pg-outcome-ledger.js.map +1 -0
  501. package/dist/plugins/pg-pool.d.ts +7 -0
  502. package/dist/plugins/pg-pool.d.ts.map +1 -0
  503. package/dist/plugins/pg-pool.js +233 -0
  504. package/dist/plugins/pg-pool.js.map +1 -0
  505. package/dist/plugins/pg-rate-limiter.d.ts +49 -0
  506. package/dist/plugins/pg-rate-limiter.d.ts.map +1 -0
  507. package/dist/plugins/pg-rate-limiter.js +193 -0
  508. package/dist/plugins/pg-rate-limiter.js.map +1 -0
  509. package/dist/plugins/pg-resume-anchor-store.d.ts +14 -0
  510. package/dist/plugins/pg-resume-anchor-store.d.ts.map +1 -0
  511. package/dist/plugins/pg-resume-anchor-store.js +23 -0
  512. package/dist/plugins/pg-resume-anchor-store.js.map +1 -0
  513. package/dist/plugins/pg-run-store.d.ts +76 -0
  514. package/dist/plugins/pg-run-store.d.ts.map +1 -0
  515. package/dist/plugins/pg-run-store.js +301 -0
  516. package/dist/plugins/pg-run-store.js.map +1 -0
  517. package/dist/plugins/pg-session-policy-store.d.ts +12 -0
  518. package/dist/plugins/pg-session-policy-store.d.ts.map +1 -0
  519. package/dist/plugins/pg-session-policy-store.js +88 -0
  520. package/dist/plugins/pg-session-policy-store.js.map +1 -0
  521. package/dist/plugins/pg-session-storage.d.ts +59 -0
  522. package/dist/plugins/pg-session-storage.d.ts.map +1 -0
  523. package/dist/plugins/pg-session-storage.js +484 -0
  524. package/dist/plugins/pg-session-storage.js.map +1 -0
  525. package/dist/plugins/pg-session-store.d.ts +2 -0
  526. package/dist/plugins/pg-session-store.d.ts.map +1 -0
  527. package/dist/plugins/pg-session-store.js +2 -0
  528. package/dist/plugins/pg-session-store.js.map +1 -0
  529. package/dist/plugins/pg-tool-result-store.d.ts +16 -0
  530. package/dist/plugins/pg-tool-result-store.d.ts.map +1 -0
  531. package/dist/plugins/pg-tool-result-store.js +52 -0
  532. package/dist/plugins/pg-tool-result-store.js.map +1 -0
  533. package/dist/plugins/pg-workflow-journal-store.d.ts +11 -0
  534. package/dist/plugins/pg-workflow-journal-store.d.ts.map +1 -0
  535. package/dist/plugins/pg-workflow-journal-store.js +28 -0
  536. package/dist/plugins/pg-workflow-journal-store.js.map +1 -0
  537. package/dist/plugins/pg-workflow-run-store.d.ts +55 -0
  538. package/dist/plugins/pg-workflow-run-store.d.ts.map +1 -0
  539. package/dist/plugins/pg-workflow-run-store.js +216 -0
  540. package/dist/plugins/pg-workflow-run-store.js.map +1 -0
  541. package/dist/plugins/remote-env-adb.d.ts +119 -0
  542. package/dist/plugins/remote-env-adb.d.ts.map +1 -0
  543. package/dist/plugins/remote-env-adb.js +502 -0
  544. package/dist/plugins/remote-env-adb.js.map +1 -0
  545. package/dist/plugins/remote-env-e2b.d.ts +162 -0
  546. package/dist/plugins/remote-env-e2b.d.ts.map +1 -0
  547. package/dist/plugins/remote-env-e2b.js +931 -0
  548. package/dist/plugins/remote-env-e2b.js.map +1 -0
  549. package/dist/plugins/remote-env-host.d.ts +141 -0
  550. package/dist/plugins/remote-env-host.d.ts.map +1 -0
  551. package/dist/plugins/remote-env-host.js +868 -0
  552. package/dist/plugins/remote-env-host.js.map +1 -0
  553. package/dist/plugins/remote-env-k8s.d.ts +209 -0
  554. package/dist/plugins/remote-env-k8s.d.ts.map +1 -0
  555. package/dist/plugins/remote-env-k8s.js +1206 -0
  556. package/dist/plugins/remote-env-k8s.js.map +1 -0
  557. package/dist/plugins/remote-env-local-docker.d.ts +124 -0
  558. package/dist/plugins/remote-env-local-docker.d.ts.map +1 -0
  559. package/dist/plugins/remote-env-local-docker.js +597 -0
  560. package/dist/plugins/remote-env-local-docker.js.map +1 -0
  561. package/dist/plugins/remote-env-ssh.d.ts +122 -0
  562. package/dist/plugins/remote-env-ssh.d.ts.map +1 -0
  563. package/dist/plugins/remote-env-ssh.js +511 -0
  564. package/dist/plugins/remote-env-ssh.js.map +1 -0
  565. package/dist/plugins/remote-shell.d.ts +7 -0
  566. package/dist/plugins/remote-shell.d.ts.map +1 -0
  567. package/dist/plugins/remote-shell.js +25 -0
  568. package/dist/plugins/remote-shell.js.map +1 -0
  569. package/dist/plugins/s3-presign.d.ts +13 -0
  570. package/dist/plugins/s3-presign.d.ts.map +1 -0
  571. package/dist/plugins/s3-presign.js +55 -0
  572. package/dist/plugins/s3-presign.js.map +1 -0
  573. package/dist/plugins/scheduler-support.d.ts +39 -0
  574. package/dist/plugins/scheduler-support.d.ts.map +1 -0
  575. package/dist/plugins/scheduler-support.js +141 -0
  576. package/dist/plugins/scheduler-support.js.map +1 -0
  577. package/dist/plugins/session-store.d.ts +7 -0
  578. package/dist/plugins/session-store.d.ts.map +1 -0
  579. package/dist/plugins/session-store.js +14 -0
  580. package/dist/plugins/session-store.js.map +1 -0
  581. package/dist/plugins/store-backend.d.ts +88 -0
  582. package/dist/plugins/store-backend.d.ts.map +1 -0
  583. package/dist/plugins/store-backend.js +197 -0
  584. package/dist/plugins/store-backend.js.map +1 -0
  585. package/dist/plugins/tidb-approval-store.d.ts +39 -0
  586. package/dist/plugins/tidb-approval-store.d.ts.map +1 -0
  587. package/dist/plugins/tidb-approval-store.js +81 -0
  588. package/dist/plugins/tidb-approval-store.js.map +1 -0
  589. package/dist/plugins/tidb-breaker-state.d.ts +18 -0
  590. package/dist/plugins/tidb-breaker-state.d.ts.map +1 -0
  591. package/dist/plugins/tidb-breaker-state.js +75 -0
  592. package/dist/plugins/tidb-breaker-state.js.map +1 -0
  593. package/dist/plugins/tidb-checkpoint-store.d.ts +50 -0
  594. package/dist/plugins/tidb-checkpoint-store.d.ts.map +1 -0
  595. package/dist/plugins/tidb-checkpoint-store.js +196 -0
  596. package/dist/plugins/tidb-checkpoint-store.js.map +1 -0
  597. package/dist/plugins/tidb-cost-quota.d.ts +16 -0
  598. package/dist/plugins/tidb-cost-quota.d.ts.map +1 -0
  599. package/dist/plugins/tidb-cost-quota.js +34 -0
  600. package/dist/plugins/tidb-cost-quota.js.map +1 -0
  601. package/dist/plugins/tidb-file-snapshot-store.d.ts +26 -0
  602. package/dist/plugins/tidb-file-snapshot-store.d.ts.map +1 -0
  603. package/dist/plugins/tidb-file-snapshot-store.js +183 -0
  604. package/dist/plugins/tidb-file-snapshot-store.js.map +1 -0
  605. package/dist/plugins/tidb-image-bake.d.ts +102 -0
  606. package/dist/plugins/tidb-image-bake.d.ts.map +1 -0
  607. package/dist/plugins/tidb-image-bake.js +400 -0
  608. package/dist/plugins/tidb-image-bake.js.map +1 -0
  609. package/dist/plugins/tidb-image-index.d.ts +71 -0
  610. package/dist/plugins/tidb-image-index.d.ts.map +1 -0
  611. package/dist/plugins/tidb-image-index.js +192 -0
  612. package/dist/plugins/tidb-image-index.js.map +1 -0
  613. package/dist/plugins/tidb-outcome-ledger.d.ts +58 -0
  614. package/dist/plugins/tidb-outcome-ledger.d.ts.map +1 -0
  615. package/dist/plugins/tidb-outcome-ledger.js +98 -0
  616. package/dist/plugins/tidb-outcome-ledger.js.map +1 -0
  617. package/dist/plugins/tidb-pool.d.ts +11 -0
  618. package/dist/plugins/tidb-pool.d.ts.map +1 -0
  619. package/dist/plugins/tidb-pool.js +485 -0
  620. package/dist/plugins/tidb-pool.js.map +1 -0
  621. package/dist/plugins/tidb-rate-limiter.d.ts +15 -0
  622. package/dist/plugins/tidb-rate-limiter.d.ts.map +1 -0
  623. package/dist/plugins/tidb-rate-limiter.js +34 -0
  624. package/dist/plugins/tidb-rate-limiter.js.map +1 -0
  625. package/dist/plugins/tidb-resume-anchor-store.d.ts +14 -0
  626. package/dist/plugins/tidb-resume-anchor-store.d.ts.map +1 -0
  627. package/dist/plugins/tidb-resume-anchor-store.js +23 -0
  628. package/dist/plugins/tidb-resume-anchor-store.js.map +1 -0
  629. package/dist/plugins/tidb-run-store.d.ts +107 -0
  630. package/dist/plugins/tidb-run-store.d.ts.map +1 -0
  631. package/dist/plugins/tidb-run-store.js +321 -0
  632. package/dist/plugins/tidb-run-store.js.map +1 -0
  633. package/dist/plugins/tidb-session-policy-store.d.ts +12 -0
  634. package/dist/plugins/tidb-session-policy-store.d.ts.map +1 -0
  635. package/dist/plugins/tidb-session-policy-store.js +88 -0
  636. package/dist/plugins/tidb-session-policy-store.js.map +1 -0
  637. package/dist/plugins/tidb-session-storage.d.ts +15 -0
  638. package/dist/plugins/tidb-session-storage.d.ts.map +1 -0
  639. package/dist/plugins/tidb-session-storage.js +101 -0
  640. package/dist/plugins/tidb-session-storage.js.map +1 -0
  641. package/dist/plugins/tidb-session-store.d.ts +46 -0
  642. package/dist/plugins/tidb-session-store.d.ts.map +1 -0
  643. package/dist/plugins/tidb-session-store.js +360 -0
  644. package/dist/plugins/tidb-session-store.js.map +1 -0
  645. package/dist/plugins/tidb-tool-result-store.d.ts +15 -0
  646. package/dist/plugins/tidb-tool-result-store.d.ts.map +1 -0
  647. package/dist/plugins/tidb-tool-result-store.js +41 -0
  648. package/dist/plugins/tidb-tool-result-store.js.map +1 -0
  649. package/dist/plugins/tidb-workflow-journal-store.d.ts +11 -0
  650. package/dist/plugins/tidb-workflow-journal-store.d.ts.map +1 -0
  651. package/dist/plugins/tidb-workflow-journal-store.js +28 -0
  652. package/dist/plugins/tidb-workflow-journal-store.js.map +1 -0
  653. package/dist/plugins/tidb-workflow-run-store.d.ts +61 -0
  654. package/dist/plugins/tidb-workflow-run-store.d.ts.map +1 -0
  655. package/dist/plugins/tidb-workflow-run-store.js +227 -0
  656. package/dist/plugins/tidb-workflow-run-store.js.map +1 -0
  657. package/dist/plugins/web-search.d.ts +27 -0
  658. package/dist/plugins/web-search.d.ts.map +1 -0
  659. package/dist/plugins/web-search.js +143 -0
  660. package/dist/plugins/web-search.js.map +1 -0
  661. package/dist/plugins/workflow-journal-limits.d.ts +2 -0
  662. package/dist/plugins/workflow-journal-limits.d.ts.map +1 -0
  663. package/dist/plugins/workflow-journal-limits.js +2 -0
  664. package/dist/plugins/workflow-journal-limits.js.map +1 -0
  665. package/dist/plugins/worktree-isolation.d.ts +16 -0
  666. package/dist/plugins/worktree-isolation.d.ts.map +1 -0
  667. package/dist/plugins/worktree-isolation.js +55 -0
  668. package/dist/plugins/worktree-isolation.js.map +1 -0
  669. package/dist/plugins/write-behind-counter.d.ts +43 -0
  670. package/dist/plugins/write-behind-counter.d.ts.map +1 -0
  671. package/dist/plugins/write-behind-counter.js +144 -0
  672. package/dist/plugins/write-behind-counter.js.map +1 -0
  673. package/dist/project-memory.d.ts +14 -0
  674. package/dist/project-memory.d.ts.map +1 -0
  675. package/dist/project-memory.js +96 -0
  676. package/dist/project-memory.js.map +1 -0
  677. package/dist/question.d.ts +42 -0
  678. package/dist/question.d.ts.map +1 -0
  679. package/dist/question.js +140 -0
  680. package/dist/question.js.map +1 -0
  681. package/dist/resource-suspend.d.ts +11 -0
  682. package/dist/resource-suspend.d.ts.map +1 -0
  683. package/dist/resource-suspend.js +6 -0
  684. package/dist/resource-suspend.js.map +1 -0
  685. package/dist/router/route-orchestration.d.ts +31 -0
  686. package/dist/router/route-orchestration.d.ts.map +1 -0
  687. package/dist/router/route-orchestration.js +49 -0
  688. package/dist/router/route-orchestration.js.map +1 -0
  689. package/dist/run-local.d.ts +26 -0
  690. package/dist/run-local.d.ts.map +1 -0
  691. package/dist/run-local.js +337 -0
  692. package/dist/run-local.js.map +1 -0
  693. package/dist/runs.d.ts +39 -0
  694. package/dist/runs.d.ts.map +1 -0
  695. package/dist/runs.js +392 -0
  696. package/dist/runs.js.map +1 -0
  697. package/dist/runtime-caps-resolver.d.ts +32 -0
  698. package/dist/runtime-caps-resolver.d.ts.map +1 -0
  699. package/dist/runtime-caps-resolver.js +134 -0
  700. package/dist/runtime-caps-resolver.js.map +1 -0
  701. package/dist/runtime-governance.d.ts +18 -0
  702. package/dist/runtime-governance.d.ts.map +1 -0
  703. package/dist/runtime-governance.js +103 -0
  704. package/dist/runtime-governance.js.map +1 -0
  705. package/dist/sandbox-pkg-source.d.ts +11 -0
  706. package/dist/sandbox-pkg-source.d.ts.map +1 -0
  707. package/dist/sandbox-pkg-source.js +56 -0
  708. package/dist/sandbox-pkg-source.js.map +1 -0
  709. package/dist/sealed-key.d.ts +29 -0
  710. package/dist/sealed-key.d.ts.map +1 -0
  711. package/dist/sealed-key.js +122 -0
  712. package/dist/sealed-key.js.map +1 -0
  713. package/dist/security.d.ts +153 -0
  714. package/dist/security.d.ts.map +1 -0
  715. package/dist/security.js +292 -0
  716. package/dist/security.js.map +1 -0
  717. package/dist/sema-registry.d.ts +187 -0
  718. package/dist/sema-registry.d.ts.map +1 -0
  719. package/dist/sema-registry.js +456 -0
  720. package/dist/sema-registry.js.map +1 -0
  721. package/dist/session-sync.d.ts +96 -0
  722. package/dist/session-sync.d.ts.map +1 -0
  723. package/dist/session-sync.js +181 -0
  724. package/dist/session-sync.js.map +1 -0
  725. package/dist/session-titler.d.ts +30 -0
  726. package/dist/session-titler.d.ts.map +1 -0
  727. package/dist/session-titler.js +77 -0
  728. package/dist/session-titler.js.map +1 -0
  729. package/dist/spec-fields.d.ts +5 -0
  730. package/dist/spec-fields.d.ts.map +1 -0
  731. package/dist/spec-fields.js +43 -0
  732. package/dist/spec-fields.js.map +1 -0
  733. package/dist/task-cwd.d.ts +15 -0
  734. package/dist/task-cwd.d.ts.map +1 -0
  735. package/dist/task-cwd.js +33 -0
  736. package/dist/task-cwd.js.map +1 -0
  737. package/dist/task-mcp.d.ts +20 -0
  738. package/dist/task-mcp.d.ts.map +1 -0
  739. package/dist/task-mcp.js +93 -0
  740. package/dist/task-mcp.js.map +1 -0
  741. package/dist/task-settings.d.ts +36 -0
  742. package/dist/task-settings.d.ts.map +1 -0
  743. package/dist/task-settings.js +141 -0
  744. package/dist/task-settings.js.map +1 -0
  745. package/dist/task-workflow.d.ts +25 -0
  746. package/dist/task-workflow.d.ts.map +1 -0
  747. package/dist/task-workflow.js +43 -0
  748. package/dist/task-workflow.js.map +1 -0
  749. package/dist/trace/artifacts.d.ts +17 -0
  750. package/dist/trace/artifacts.d.ts.map +1 -0
  751. package/dist/trace/artifacts.js +65 -0
  752. package/dist/trace/artifacts.js.map +1 -0
  753. package/dist/trace/project.d.ts +170 -0
  754. package/dist/trace/project.d.ts.map +1 -0
  755. package/dist/trace/project.js +239 -0
  756. package/dist/trace/project.js.map +1 -0
  757. package/dist/trace/redact.d.ts +5 -0
  758. package/dist/trace/redact.d.ts.map +1 -0
  759. package/dist/trace/redact.js +83 -0
  760. package/dist/trace/redact.js.map +1 -0
  761. package/dist/usage-analytics.d.ts +36 -0
  762. package/dist/usage-analytics.d.ts.map +1 -0
  763. package/dist/usage-analytics.js +89 -0
  764. package/dist/usage-analytics.js.map +1 -0
  765. package/package.json +78 -0
@@ -0,0 +1,1206 @@
1
+ import path from "node:path";
2
+ import { readFileSync } from "node:fs";
3
+ import https from "node:https";
4
+ import http from "node:http";
5
+ import { StringDecoder } from "node:string_decoder";
6
+ import WebSocket from "ws";
7
+ import { shellQuote, kindFromMode } from "./remote-shell.js";
8
+ import { presignS3Url } from "./s3-presign.js";
9
+ import { FileError, ExecutionError, RemoteExecutionError, withRetry, RollingTailBuffer, markTruncated, } from "@sema-agent/core";
10
+ import { randomUUID } from "node:crypto";
11
+ import { BackgroundShellManager, seedMemStream, feedMemStream, drainMemStream } from "./background-shell-support.js";
12
+ const PROVIDER = "k8s";
13
+ const K8S_BG_DIR_ROOT = "/tmp/.sema-bg";
14
+ const K8S_BG_MAX_CONCURRENT = Math.max(1, Math.floor(Number(process.env.K8S_BG_MAX_CONCURRENT ?? "")) || 8);
15
+ const K8S_BG_DEFAULT_TIMEOUT_SEC = Math.max(1, Math.floor(Number(process.env.K8S_BG_DEFAULT_TIMEOUT_SEC ?? "")) || 300);
16
+ const K8S_BG_MAX_TIMEOUT_SEC = Math.max(K8S_BG_DEFAULT_TIMEOUT_SEC, Math.floor(Number(process.env.K8S_BG_MAX_TIMEOUT_SEC ?? "")) || 1800);
17
+ const K8S_BG_READ_CAP = Math.max(64 * 1024, Math.floor(Number(process.env.K8S_BG_READ_CAP ?? "")) || 1024 * 1024);
18
+ const K8S_BG_FILE_CAP = Math.max(K8S_BG_READ_CAP, Math.floor(Number(process.env.K8S_BG_FILE_CAP ?? "")) || 64 * 1024 * 1024);
19
+ const K8S_BG_MEM_CAP = Math.max(64 * 1024, Math.floor(Number(process.env.K8S_BG_MEM_CAP ?? "")) || 8 * 1024 * 1024);
20
+ export function buildBgRunnerScript(dir) {
21
+ const q = (name) => shellQuote(`${dir}/${name}`);
22
+ return [
23
+ `echo $$ > ${q("pgid.tmp")} 2>/dev/null && mv ${q("pgid.tmp")} ${q("pgid")} 2>/dev/null`,
24
+ `sh ${q("cmd.sh")} > ${q("out")} 2> ${q("err")} < /dev/null`,
25
+ `__RC=$?`,
26
+ `echo $__RC > ${q("exit.tmp")} 2>/dev/null && mv ${q("exit.tmp")} ${q("exit")} 2>/dev/null`,
27
+ ].join("\n");
28
+ }
29
+ export function buildBgLauncherScript(dir, cmdShB64, runnerShB64) {
30
+ const d = shellQuote(dir);
31
+ const q = (name) => shellQuote(`${dir}/${name}`);
32
+ return [
33
+ `mkdir -p ${d} && chmod 700 ${d}`,
34
+ `printf %s '${cmdShB64}' | base64 -d > ${q("cmd.sh")}`,
35
+ `printf %s '${runnerShB64}' | base64 -d > ${q("runner.sh")}`,
36
+ `setsid sh ${q("runner.sh")} >/dev/null 2>&1 &`,
37
+ `__i=0; while [ ! -s ${q("pgid")} ] && [ $__i -lt 40 ]; do __i=$((__i+1)); sleep 0.05; done`,
38
+ `if [ -s ${q("pgid")} ]; then echo SEMABG_LAUNCHED; else echo SEMABG_NOPGID; fi`,
39
+ ].join("\n");
40
+ }
41
+ export function buildBgPollScript(dir, stdoutCursor, stderrCursor, readCap) {
42
+ const d = shellQuote(dir);
43
+ const slice = (file, cursor) => [
44
+ `__N=$((__T - ${cursor}))`,
45
+ `if [ "$__N" -gt 0 ]; then`,
46
+ ` if [ "$__N" -le ${readCap} ]; then tail -c +$(( ${cursor} + 1 )) ${d}/${file} 2>/dev/null | head -c "$__N" | base64;`,
47
+ ` else tail -c +$(( __T - ${readCap} + 1 )) ${d}/${file} 2>/dev/null | head -c ${readCap} | base64; fi`,
48
+ `fi`,
49
+ ].join("\n");
50
+ return [
51
+ `if [ ! -d ${d} ]; then echo SEMABG_GONE; exit 0; fi`,
52
+ `__OT=$(wc -c < ${d}/out 2>/dev/null); __OT=$(( \${__OT:-0} + 0 ))`,
53
+ `__ET=$(wc -c < ${d}/err 2>/dev/null); __ET=$(( \${__ET:-0} + 0 ))`,
54
+ `__EX=$( [ -f ${d}/exit ] && cat ${d}/exit 2>/dev/null || echo - )`,
55
+ `__PG=$(cat ${d}/pgid 2>/dev/null); __PG=\${__PG:--}`,
56
+ `if [ "$__PG" = "-" ]; then __AL=1; elif kill -0 -"$__PG" 2>/dev/null; then __AL=1; else __AL=0; fi`,
57
+ `echo "SEMABG_META o=$__OT e=$__ET x=$__EX a=$__AL"`,
58
+ `echo SEMABG_O`,
59
+ `__T=$__OT`,
60
+ slice("out", stdoutCursor),
61
+ `echo SEMABG_E`,
62
+ `__T=$__ET`,
63
+ slice("err", stderrCursor),
64
+ `echo SEMABG_X`,
65
+ ].join("\n");
66
+ }
67
+ export function buildBgKillScript(dir) {
68
+ const d = shellQuote(dir);
69
+ return [
70
+ `__i=0; while [ ! -s ${d}/pgid ] && [ $__i -lt 40 ]; do __i=$((__i+1)); sleep 0.05; done`,
71
+ `__PG=$(cat ${d}/pgid 2>/dev/null); __PG=\${__PG:--}`,
72
+ `if [ "$__PG" != "-" ]; then kill -TERM -"$__PG" 2>/dev/null || kill -TERM "$__PG" 2>/dev/null; sleep 1; kill -KILL -"$__PG" 2>/dev/null || kill -KILL "$__PG" 2>/dev/null; fi`,
73
+ `echo SEMABG_KILLED`,
74
+ ].join("\n");
75
+ }
76
+ export function buildBgDisposeScript(dir) {
77
+ const d = shellQuote(dir);
78
+ return [
79
+ `__PG=$(cat ${d}/pgid 2>/dev/null); __PG=\${__PG:--}`,
80
+ `if [ "$__PG" != "-" ]; then kill -KILL -"$__PG" 2>/dev/null || kill -KILL "$__PG" 2>/dev/null; fi`,
81
+ `rm -rf ${d} 2>/dev/null`,
82
+ `echo SEMABG_DISPOSED`,
83
+ ].join("\n");
84
+ }
85
+ export function buildDetachCapableExec(dir, command) {
86
+ const d = shellQuote(dir);
87
+ const q = (name) => shellQuote(`${dir}/${name}`);
88
+ const cmdB64 = Buffer.from(command, "utf8").toString("base64");
89
+ const writePgid = (val) => `printf %s ${val} > ${q("pgid.tmp")} 2>/dev/null && mv ${q("pgid.tmp")} ${q("pgid")} 2>/dev/null`;
90
+ return [
91
+ `__cmd=$(printf %s '${cmdB64}' | base64 -d)`,
92
+ `mkdir -p ${d} 2>/dev/null`,
93
+ `trap 'rm -rf ${d} 2>/dev/null' EXIT`,
94
+ `if command -v setsid >/dev/null 2>&1; then`,
95
+ ` setsid sh -c "$__cmd" &`,
96
+ ` __pg=$!`,
97
+ ` ${writePgid('"$__pg"')}`,
98
+ ` wait "$__pg"; __rc=$?`,
99
+ `else`,
100
+ ` ${writePgid('"$$"')}`,
101
+ ` sh -c "$__cmd"; __rc=$?`,
102
+ `fi`,
103
+ `exit $__rc`,
104
+ ].join("\n");
105
+ }
106
+ export function parseBgPollOutput(raw) {
107
+ if (raw.includes("SEMABG_GONE")) {
108
+ return { gone: true, outTotal: 0, errTotal: 0, alive: false, stdout: "", stdoutBytes: 0, stderr: "", stderrBytes: 0 };
109
+ }
110
+ const lines = raw.split("\n");
111
+ const metaIdx = lines.findIndex((l) => l.startsWith("SEMABG_META "));
112
+ if (metaIdx < 0)
113
+ return undefined;
114
+ const oIdx = lines.indexOf("SEMABG_O", metaIdx + 1);
115
+ const eIdx = oIdx >= 0 ? lines.indexOf("SEMABG_E", oIdx + 1) : -1;
116
+ const xIdx = eIdx >= 0 ? lines.indexOf("SEMABG_X", eIdx + 1) : -1;
117
+ if (oIdx < 0 || eIdx < 0 || xIdx < 0)
118
+ return undefined;
119
+ const m = /o=(\d+) e=(\d+) x=(\S+) a=([01])/.exec(lines[metaIdx].slice("SEMABG_META ".length));
120
+ if (!m)
121
+ return undefined;
122
+ const outTotal = parseInt(m[1], 10);
123
+ const errTotal = parseInt(m[2], 10);
124
+ const exTok = m[3];
125
+ const alive = m[4] === "1";
126
+ const exitParsed = exTok === "-" ? NaN : parseInt(exTok, 10);
127
+ const exitCode = Number.isFinite(exitParsed) ? exitParsed : undefined;
128
+ const decode = (from, to) => {
129
+ const b64 = lines.slice(from, to).join("").replace(/\s+/g, "");
130
+ const buf = Buffer.from(b64, "base64");
131
+ return { text: buf.toString("utf8"), bytes: buf.length };
132
+ };
133
+ const o = decode(oIdx + 1, eIdx);
134
+ const e = decode(eIdx + 1, xIdx);
135
+ return {
136
+ gone: false,
137
+ outTotal,
138
+ errTotal,
139
+ ...(exitCode !== undefined ? { exitCode } : {}),
140
+ alive,
141
+ stdout: o.text,
142
+ stdoutBytes: o.bytes,
143
+ stderr: e.text,
144
+ stderrBytes: e.bytes,
145
+ };
146
+ }
147
+ const ok = (value) => ({ ok: true, value });
148
+ const unsupported = (op) => ({
149
+ ok: false,
150
+ error: new RemoteExecutionError("unsupported", `${op} is not supported on a Kata pod sandbox (no managed memory snapshot — capabilities.suspendable=false; durable suspend degrades to checkpoint + cold rebuild)`),
151
+ });
152
+ const SA_DIR = "/var/run/secrets/kubernetes.io/serviceaccount";
153
+ const EXEC_SUBPROTOCOLS = ["v5.channel.k8s.io", "v4.channel.k8s.io"];
154
+ const WRITE_CHUNK_BYTES = 64 * 1024;
155
+ export function applyPodSpecPatch(pod, patch) {
156
+ assertHardeningOnly(patch.podSecurityContext, "podSecurityContext");
157
+ assertHardeningOnly(patch.containerSecurityContext, "containerSecurityContext");
158
+ if (patch.labels) {
159
+ const identity = {};
160
+ for (const k of ["app", "managed-by"]) {
161
+ const v = pod.metadata.labels?.[k];
162
+ if (v !== undefined)
163
+ identity[k] = v;
164
+ }
165
+ pod.metadata.labels = { ...pod.metadata.labels, ...patch.labels, ...identity };
166
+ }
167
+ const spec = pod.spec;
168
+ assertVolumesPodLocal(patch.volumes, "volumes");
169
+ if (patch.volumes?.length)
170
+ spec.volumes = [...(spec.volumes ?? []), ...patch.volumes];
171
+ if (patch.podSecurityContext)
172
+ spec.securityContext = { ...(spec.securityContext ?? {}), ...patch.podSecurityContext };
173
+ const container = spec.containers?.[0];
174
+ if (container) {
175
+ if (patch.volumeMounts?.length)
176
+ container.volumeMounts = [...(container.volumeMounts ?? []), ...patch.volumeMounts];
177
+ if (patch.containerSecurityContext)
178
+ container.securityContext = { ...(container.securityContext ?? {}), ...patch.containerSecurityContext };
179
+ }
180
+ }
181
+ function assertHardeningOnly(sc, where) {
182
+ if (!sc)
183
+ return;
184
+ const bad = (msg) => {
185
+ throw new Error(`podSpecPatch.${where} rejected — it may only HARDEN, never weaken isolation: ${msg}`);
186
+ };
187
+ if (sc.privileged === true)
188
+ bad("privileged:true");
189
+ if (sc.allowPrivilegeEscalation === true)
190
+ bad("allowPrivilegeEscalation:true");
191
+ if (sc.readOnlyRootFilesystem === false)
192
+ bad("readOnlyRootFilesystem:false");
193
+ if (sc.runAsNonRoot === false)
194
+ bad("runAsNonRoot:false");
195
+ if (sc.runAsUser === 0)
196
+ bad("runAsUser:0 (root)");
197
+ const caps = sc.capabilities;
198
+ if (caps && Array.isArray(caps.add) && caps.add.length > 0)
199
+ bad(`capabilities.add ${JSON.stringify(caps.add)} (a hardening patch may only .drop)`);
200
+ if (sc.procMount === "Unmasked")
201
+ bad('procMount:"Unmasked" (re-exposes masked /proc)');
202
+ const seccomp = sc.seccompProfile;
203
+ if (seccomp && seccomp.type === "Unconfined")
204
+ bad('seccompProfile.type:"Unconfined" (disables syscall filtering)');
205
+ }
206
+ function assertVolumesPodLocal(volumes, where) {
207
+ if (!volumes?.length)
208
+ return;
209
+ const POD_LOCAL = new Set(["emptyDir", "configMap", "secret", "projected", "downwardAPI", "ephemeral"]);
210
+ for (const v of volumes) {
211
+ const vol = v;
212
+ const sources = Object.keys(vol).filter((k) => k !== "name");
213
+ for (const src of sources) {
214
+ if (!POD_LOCAL.has(src)) {
215
+ throw new Error(`podSpecPatch.${where} rejected — volume source ${JSON.stringify(src)} is not pod-local (host-backed sources like hostPath/csi/flexVolume cross the Kata VM boundary into the node FS). Allowed: ${[...POD_LOCAL].join("/")}`);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ export function execSocketTlsOptions(ca, insecureTls) {
221
+ const caList = ca ? [ca] : undefined;
222
+ return { ca: caList, rejectUnauthorized: !insecureTls, tls: { ca: caList, rejectUnauthorized: !insecureTls } };
223
+ }
224
+ export function errorMessageOf(e) {
225
+ if (e instanceof Error)
226
+ return e.message;
227
+ const m = e?.message;
228
+ return typeof m === "string" && m ? m : String(e);
229
+ }
230
+ export function exitCodeFromStatus(statusJson) {
231
+ try {
232
+ const s = JSON.parse(statusJson);
233
+ if (s.status === "Success")
234
+ return { exitCode: 0 };
235
+ const cause = s.details?.causes?.find((c) => c.reason === "ExitCode");
236
+ if (cause?.message?.trim()) {
237
+ const code = Number(cause.message);
238
+ if (Number.isFinite(code))
239
+ return { exitCode: code };
240
+ }
241
+ return { error: s.message || s.reason || "exec failed without an exit code" };
242
+ }
243
+ catch {
244
+ return { error: `unparseable exec status: ${statusJson.slice(0, 200)}` };
245
+ }
246
+ }
247
+ export class RemoteK8sExecutionEnv {
248
+ capabilities;
249
+ cwd;
250
+ podName;
251
+ podIP;
252
+ destroyed = false;
253
+ handleSnapshotId;
254
+ inFlightExecs = 0;
255
+ connectPromise;
256
+ cfg;
257
+ deps;
258
+ constructor(config, deps) {
259
+ this.cfg = {
260
+ apiUrl: config.apiUrl,
261
+ token: config.token,
262
+ caCert: config.caCert,
263
+ insecureTls: config.insecureTls ?? false,
264
+ namespace: config.namespace ?? "sandboxes",
265
+ image: config.image,
266
+ runtimeClass: config.runtimeClass ?? "kata-qemu",
267
+ mountPath: config.mountPath ?? "/workspace",
268
+ timeoutMs: config.timeoutMs ?? 30 * 60_000,
269
+ readyTimeoutMs: config.readyTimeoutMs ?? 120_000,
270
+ rpcTimeoutMs: config.rpcTimeoutMs ?? 30_000,
271
+ livenessMs: config.livenessMs ?? 120_000,
272
+ dataTimeoutMs: config.dataTimeoutMs ?? 5 * 60_000,
273
+ cpu: config.cpu ?? "1",
274
+ memory: config.memory ?? "2Gi",
275
+ retry: { maxAttempts: config.retry?.maxAttempts ?? 3, backoffMs: config.retry?.backoffMs ?? 1000 },
276
+ ...(config.s3Snapshot ? { s3Snapshot: config.s3Snapshot } : {}),
277
+ ...(config.sessionId ? { sessionId: config.sessionId } : {}),
278
+ ...(config.podSpecPatch ? { podSpecPatch: config.podSpecPatch } : {}),
279
+ ...(config.podEnv ? { podEnv: config.podEnv } : {}),
280
+ };
281
+ this.cwd = this.cfg.mountPath;
282
+ this.deps = deps ?? {};
283
+ this.capabilities = { isolation: true, suspendable: !!this.cfg.s3Snapshot };
284
+ const bgMax = Math.max(1, Math.min(K8S_BG_MAX_TIMEOUT_SEC, Math.floor(this.cfg.timeoutMs / 1000)));
285
+ this.backgroundCapabilities = {
286
+ supported: true,
287
+ maxConcurrent: K8S_BG_MAX_CONCURRENT,
288
+ defaultBgTimeoutSec: Math.min(K8S_BG_DEFAULT_TIMEOUT_SEC, bgMax),
289
+ maxBgTimeoutSec: bgMax,
290
+ supportsDetach: true,
291
+ };
292
+ }
293
+ resolve(p) {
294
+ return path.posix.isAbsolute(p) ? path.posix.normalize(p) : path.posix.normalize(path.posix.join(this.cwd, p));
295
+ }
296
+ workspaceHandle() {
297
+ return { sandboxId: this.podName ?? "(unconnected)", provider: PROVIDER, mountPath: this.cwd, ...(this.handleSnapshotId ? { snapshotId: this.handleSnapshotId } : {}) };
298
+ }
299
+ creds() {
300
+ const apiUrl = this.cfg.apiUrl ??
301
+ (process.env.KUBERNETES_SERVICE_HOST ? `https://${process.env.KUBERNETES_SERVICE_HOST}:${process.env.KUBERNETES_SERVICE_PORT ?? "443"}` : undefined);
302
+ if (!apiUrl)
303
+ throw new RemoteExecutionError("connect_failed", "no k8s API: set K8S_API_URL or run in-cluster");
304
+ let token = this.cfg.token;
305
+ let ca = this.cfg.caCert;
306
+ if (!token) {
307
+ try {
308
+ token = readFileSync(`${SA_DIR}/token`, "utf8").trim();
309
+ }
310
+ catch {
311
+ throw new RemoteExecutionError("auth_failed", "no k8s token: set K8S_TOKEN or run in-cluster with a service account");
312
+ }
313
+ }
314
+ if (!ca && !this.cfg.insecureTls) {
315
+ try {
316
+ ca = readFileSync(`${SA_DIR}/ca.crt`, "utf8");
317
+ }
318
+ catch {
319
+ throw new RemoteExecutionError("auth_failed", "no k8s CA: set K8S_CA_CERT_B64, K8S_INSECURE_TLS=true (lab), or run in-cluster");
320
+ }
321
+ }
322
+ return { apiUrl: apiUrl.replace(/\/+$/, ""), token, ca };
323
+ }
324
+ async request(method, apiPath, body, opts) {
325
+ if (this.deps.request)
326
+ return this.deps.request(method, apiPath, body, opts);
327
+ const { apiUrl, token, ca } = this.creds();
328
+ const url = new URL(apiUrl + apiPath);
329
+ const isHttps = url.protocol === "https:";
330
+ const payload = body === undefined ? undefined : JSON.stringify(body);
331
+ return new Promise((resolvePromise, rejectPromise) => {
332
+ const req = (isHttps ? https : http).request({
333
+ method,
334
+ hostname: url.hostname,
335
+ port: url.port || (isHttps ? 443 : 80),
336
+ path: url.pathname + url.search,
337
+ headers: {
338
+ authorization: `Bearer ${token}`,
339
+ accept: "application/json",
340
+ ...(payload ? { "content-type": "application/json", "content-length": Buffer.byteLength(payload) } : {}),
341
+ },
342
+ ...(isHttps ? { ca: ca ? [ca] : undefined, rejectUnauthorized: !this.cfg.insecureTls } : {}),
343
+ timeout: opts?.timeoutMs ?? this.cfg.rpcTimeoutMs,
344
+ signal: opts?.signal,
345
+ }, (res) => {
346
+ const bufs = [];
347
+ res.on("data", (d) => bufs.push(d));
348
+ res.on("end", () => {
349
+ const text = Buffer.concat(bufs).toString("utf8");
350
+ let json = undefined;
351
+ try {
352
+ json = text ? JSON.parse(text) : undefined;
353
+ }
354
+ catch {
355
+ json = { raw: text.slice(0, 500) };
356
+ }
357
+ resolvePromise({ status: res.statusCode ?? 0, json });
358
+ });
359
+ });
360
+ req.on("timeout", () => {
361
+ req.destroy(new Error(`k8s API ${method} ${apiPath} timed out`));
362
+ });
363
+ req.on("error", (e) => rejectPromise(e));
364
+ if (payload)
365
+ req.write(payload);
366
+ req.end();
367
+ });
368
+ }
369
+ openExec(url, headers) {
370
+ if (this.deps.openExec)
371
+ return this.deps.openExec(url, headers);
372
+ const { ca } = this.creds();
373
+ return new WebSocket(url, EXEC_SUBPROTOCOLS, {
374
+ headers,
375
+ ...(url.startsWith("wss:") ? execSocketTlsOptions(ca, this.cfg.insecureTls) : {}),
376
+ });
377
+ }
378
+ async connect(config) {
379
+ const policy = {
380
+ retryableCodes: ["connect_failed", "timeout", "transport_lost"],
381
+ maxAttempts: this.cfg.retry.maxAttempts,
382
+ backoffMs: (failed) => this.cfg.retry.backoffMs * failed,
383
+ };
384
+ const once = this.deps.connectOnce ?? ((s) => this.connectOnce(s));
385
+ return withRetry(() => once(config?.abortSignal), policy, { signal: config?.abortSignal });
386
+ }
387
+ async ensureConnected() {
388
+ if (this.podName)
389
+ return ok(undefined);
390
+ if (this.destroyed)
391
+ return { ok: false, error: new ExecutionError("shell_unavailable", "k8s sandbox destroyed") };
392
+ this.connectPromise ??= this.connect();
393
+ const r = await this.connectPromise;
394
+ if (!r.ok) {
395
+ this.connectPromise = undefined;
396
+ return { ok: false, error: new ExecutionError("shell_unavailable", `k8s sandbox connect failed: ${r.error.message}`, r.error) };
397
+ }
398
+ return ok(undefined);
399
+ }
400
+ async connectOnce(signal) {
401
+ if (signal?.aborted)
402
+ return { ok: false, error: new RemoteExecutionError("aborted", "connect aborted") };
403
+ if (this.destroyed)
404
+ return { ok: false, error: new RemoteExecutionError("connect_failed", "env already destroyed") };
405
+ const ns = this.cfg.namespace;
406
+ const pod = {
407
+ apiVersion: "v1",
408
+ kind: "Pod",
409
+ metadata: {
410
+ generateName: "sbx-",
411
+ labels: { app: "sema-sandbox", "managed-by": "sema-server" },
412
+ },
413
+ spec: {
414
+ ...(this.cfg.runtimeClass ? { runtimeClassName: this.cfg.runtimeClass } : {}),
415
+ restartPolicy: "Never",
416
+ automountServiceAccountToken: false,
417
+ activeDeadlineSeconds: Math.ceil(this.cfg.timeoutMs / 1000),
418
+ terminationGracePeriodSeconds: 1,
419
+ containers: [
420
+ {
421
+ name: "sandbox",
422
+ image: this.cfg.image,
423
+ command: this.cfg.podEnv?.SEMA_PKG_SOURCE
424
+ ? ["sh", "-c", "[ -f /opt/sema/pkg-source.sh ] && sh /opt/sema/pkg-source.sh || true; sleep infinity"]
425
+ : ["sh", "-c", "sleep infinity"],
426
+ ...(this.cfg.podEnv && Object.keys(this.cfg.podEnv).length > 0
427
+ ? { env: Object.entries(this.cfg.podEnv).map(([name, value]) => ({ name, value: String(value) })) }
428
+ : {}),
429
+ resources: { limits: { cpu: this.cfg.cpu, memory: this.cfg.memory } },
430
+ },
431
+ ],
432
+ },
433
+ };
434
+ if (this.cfg.podSpecPatch)
435
+ applyPodSpecPatch(pod, this.cfg.podSpecPatch);
436
+ let created;
437
+ try {
438
+ created = await this.request("POST", `/api/v1/namespaces/${ns}/pods`, pod, { signal });
439
+ }
440
+ catch (e) {
441
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `pod create RPC failed: ${e instanceof Error ? e.message : String(e)}`, e instanceof Error ? e : undefined) };
442
+ }
443
+ if (created.status === 401 || created.status === 403) {
444
+ return { ok: false, error: new RemoteExecutionError("auth_failed", `pod create denied (${created.status}): ${JSON.stringify(created.json).slice(0, 200)}`) };
445
+ }
446
+ if (created.status >= 300) {
447
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `pod create failed (${created.status}): ${JSON.stringify(created.json).slice(0, 300)}`) };
448
+ }
449
+ const name = created.json?.metadata?.name;
450
+ if (!name)
451
+ return { ok: false, error: new RemoteExecutionError("connect_failed", "pod create returned no name") };
452
+ const deadline = Date.now() + this.cfg.readyTimeoutMs;
453
+ let podIP;
454
+ for (;;) {
455
+ if (signal?.aborted) {
456
+ await this.deletePod(name).catch(() => { });
457
+ return { ok: false, error: new RemoteExecutionError("aborted", "connect aborted") };
458
+ }
459
+ let got;
460
+ try {
461
+ got = await this.request("GET", `/api/v1/namespaces/${ns}/pods/${name}`, undefined, { signal });
462
+ }
463
+ catch (e) {
464
+ await this.deletePod(name).catch(() => { });
465
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `pod status RPC failed: ${e instanceof Error ? e.message : String(e)}`, e instanceof Error ? e : undefined) };
466
+ }
467
+ const status = got.json?.status;
468
+ const phase = status?.phase;
469
+ if (phase === "Running") {
470
+ podIP = status?.podIP;
471
+ break;
472
+ }
473
+ if (phase === "Failed" || phase === "Succeeded") {
474
+ await this.deletePod(name).catch(() => { });
475
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `pod entered ${phase} before Running (${status?.reason ?? "?"})`) };
476
+ }
477
+ const waiting = status?.containerStatuses?.[0]?.state?.waiting;
478
+ if (waiting?.reason === "ImagePullBackOff" || waiting?.reason === "ErrImagePull") {
479
+ await this.deletePod(name).catch(() => { });
480
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `image pull failed for ${this.cfg.image}: ${waiting.message ?? waiting.reason}`) };
481
+ }
482
+ if (Date.now() > deadline) {
483
+ await this.deletePod(name).catch(() => { });
484
+ return { ok: false, error: new RemoteExecutionError("timeout", `pod not Running within ${this.cfg.readyTimeoutMs}ms (phase=${phase ?? "?"})`) };
485
+ }
486
+ await new Promise((r) => setTimeout(r, 1000));
487
+ }
488
+ if (this.destroyed) {
489
+ await this.deletePod(name).catch(() => { });
490
+ return { ok: false, error: new RemoteExecutionError("connect_failed", "env destroyed during connect") };
491
+ }
492
+ this.podName = name;
493
+ this.podIP = podIP;
494
+ const mk = await this.runExec(`mkdir -p ${shellQuote(this.cfg.mountPath)}`);
495
+ if (!mk.ok || mk.value.exitCode !== 0) {
496
+ await this.deletePod(name).catch(() => { });
497
+ this.podName = undefined;
498
+ this.podIP = undefined;
499
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `workspace mkdir failed: ${mk.ok ? mk.value.stderr : mk.error.message}`) };
500
+ }
501
+ return ok(this.workspaceHandle());
502
+ }
503
+ presignSnapshot(method, snapshotId) {
504
+ const s3 = this.cfg.s3Snapshot;
505
+ const prefix = s3.keyPrefix ?? "kata";
506
+ const session = this.cfg.sessionId ?? "_";
507
+ const safe = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
508
+ for (const [label, seg] of [["sessionId", session], ["snapshotId", snapshotId], ["keyPrefix", prefix]]) {
509
+ if (!safe.test(seg))
510
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `unsafe snapshot key segment (${label}): refusing to build a traversing object key`) };
511
+ }
512
+ return {
513
+ ok: true,
514
+ value: presignS3Url({
515
+ endpoint: s3.endpoint,
516
+ bucket: s3.bucket,
517
+ key: `${prefix}/${session}/${snapshotId}.tar.gz`,
518
+ method,
519
+ accessKey: s3.accessKey,
520
+ secretKey: s3.secretKey,
521
+ ...(s3.region ? { region: s3.region } : {}),
522
+ expiresSec: Math.min(s3.presignTtlSec ?? 600, 3600),
523
+ }),
524
+ };
525
+ }
526
+ redactUrl(text, url) {
527
+ return text.split(url).join("<presigned-url>").replace(/X-Amz-Signature=[0-9a-f]+/gi, "X-Amz-Signature=<redacted>");
528
+ }
529
+ async suspendVM(_options) {
530
+ if (!this.cfg.s3Snapshot)
531
+ return unsupported("suspendVM");
532
+ if (this.inFlightExecs > 0)
533
+ return { ok: false, error: new RemoteExecutionError("command_in_flight", "cannot suspend while a command is in flight (would snapshot a torn workspace)") };
534
+ const snapshotId = `kata-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
535
+ if (!this.podName)
536
+ return ok(snapshotId);
537
+ const presigned = this.presignSnapshot("PUT", snapshotId);
538
+ if (!presigned.ok)
539
+ return presigned;
540
+ const url = presigned.value;
541
+ const tmp = "/tmp/ws-snap.tgz";
542
+ const cmd = `tar czf ${tmp} -C ${shellQuote(this.cfg.mountPath)} . && curl -fsS -X PUT -T ${tmp} ${shellQuote(url)}; ` +
543
+ `rc=$?; rm -f ${tmp}; exit $rc`;
544
+ const r = await this.runExec(cmd, { timeoutMs: this.cfg.dataTimeoutMs, livenessMs: 0 });
545
+ if (!r.ok)
546
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `workspace snapshot upload failed: ${this.redactUrl(r.error.message, url)}`, r.error) };
547
+ if (r.value.exitCode !== 0)
548
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `workspace snapshot upload exited ${r.value.exitCode}: ${this.redactUrl(r.value.stderr, url).slice(0, 300)}`) };
549
+ const name = this.podName;
550
+ this.podName = undefined;
551
+ this.podIP = undefined;
552
+ await this.deletePod(name).catch(() => { });
553
+ return ok(snapshotId);
554
+ }
555
+ async resumeVM(snapshotId, options) {
556
+ if (!this.cfg.s3Snapshot)
557
+ return unsupported("resumeVM");
558
+ const presigned = this.presignSnapshot("GET", snapshotId);
559
+ if (!presigned.ok)
560
+ return presigned;
561
+ const c = await this.connect({ abortSignal: options?.abortSignal });
562
+ if (!c.ok)
563
+ return c;
564
+ const url = presigned.value;
565
+ const cmd = `code=$(curl -s -o /tmp/ws.tgz -w '%{http_code}' ${shellQuote(url)}); ` +
566
+ `if [ "$code" = "404" ]; then echo EMPTY_SNAPSHOT; exit 0; fi; ` +
567
+ `if [ "$code" != "200" ]; then echo "snapshot GET HTTP $code" >&2; exit 22; fi; ` +
568
+ `tar xzf /tmp/ws.tgz -C ${shellQuote(this.cfg.mountPath)} && rm -f /tmp/ws.tgz`;
569
+ const r = await this.runExec(cmd, { timeoutMs: this.cfg.dataTimeoutMs, livenessMs: 0 });
570
+ if (!r.ok)
571
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `workspace snapshot restore failed: ${this.redactUrl(r.error.message, url)}`, r.error) };
572
+ if (r.value.exitCode !== 0)
573
+ return { ok: false, error: new RemoteExecutionError("connect_failed", `workspace snapshot restore exited ${r.value.exitCode}: ${this.redactUrl(r.value.stderr, url).slice(0, 300)}`) };
574
+ this.handleSnapshotId = snapshotId;
575
+ return ok(this.workspaceHandle());
576
+ }
577
+ async postResumeInit() {
578
+ if (!this.cfg.s3Snapshot)
579
+ return unsupported("postResumeInit");
580
+ return ok(undefined);
581
+ }
582
+ async reconnect(_sessionToken) {
583
+ if (this.podName) {
584
+ const alive = await this.request("GET", `/api/v1/namespaces/${this.cfg.namespace}/pods/${this.podName}`).catch(() => undefined);
585
+ const phase = alive?.json?.status?.phase;
586
+ if (alive?.status === 200 && phase === "Running")
587
+ return ok(this.workspaceHandle());
588
+ this.podName = undefined;
589
+ this.podIP = undefined;
590
+ }
591
+ return this.connect();
592
+ }
593
+ async deletePod(name) {
594
+ await this.request("DELETE", `/api/v1/namespaces/${this.cfg.namespace}/pods/${name}?gracePeriodSeconds=0`, undefined, { timeoutMs: this.cfg.rpcTimeoutMs });
595
+ }
596
+ async destroy() {
597
+ await this.disposeBackgroundShells().catch(() => { });
598
+ this.destroyed = true;
599
+ const name = this.podName;
600
+ this.podName = undefined;
601
+ this.podIP = undefined;
602
+ if (name)
603
+ await this.deletePod(name).catch(() => { });
604
+ }
605
+ async cleanup() {
606
+ return this.destroy();
607
+ }
608
+ execUrl(command) {
609
+ const { apiUrl, token } = this.creds();
610
+ const base = apiUrl.replace(/^http/, "ws");
611
+ const q = new URLSearchParams();
612
+ q.append("container", "sandbox");
613
+ q.append("stdout", "true");
614
+ q.append("stderr", "true");
615
+ for (const part of ["sh", "-c", command])
616
+ q.append("command", part);
617
+ return { url: `${base}/api/v1/namespaces/${this.cfg.namespace}/pods/${this.podName}/exec?${q.toString()}`, headers: { authorization: `Bearer ${token}` } };
618
+ }
619
+ runExec(command, opts) {
620
+ let sock;
621
+ let headers;
622
+ let url;
623
+ try {
624
+ ({ url, headers } = this.execUrl(command));
625
+ sock = this.openExec(url, headers);
626
+ }
627
+ catch (e) {
628
+ return Promise.resolve({ ok: false, error: new ExecutionError("shell_unavailable", e instanceof Error ? e.message : String(e), e instanceof Error ? e : undefined) });
629
+ }
630
+ return new Promise((resolvePromise) => {
631
+ const boundOutput = !!opts?.boundOutput;
632
+ const outBufs = [];
633
+ const outTail = boundOutput ? new RollingTailBuffer() : undefined;
634
+ const errBuf = new RollingTailBuffer();
635
+ const outDecoder = opts?.onStdout ? new StringDecoder("utf8") : undefined;
636
+ const errDecoder = opts?.onStderr ? new StringDecoder("utf8") : undefined;
637
+ let statusFrame;
638
+ let settled = false;
639
+ let lastProgress = Date.now();
640
+ let spliceSink;
641
+ let sinkClosed = false;
642
+ let removeDetachListener;
643
+ const detachTee = opts?.detach?.tee;
644
+ const finish = (r) => {
645
+ if (settled)
646
+ return;
647
+ settled = true;
648
+ clearTimeout(wallTimer);
649
+ clearTimeout(livenessTimer);
650
+ opts?.signal?.removeEventListener("abort", onAbort);
651
+ removeDetachListener?.();
652
+ try {
653
+ (sock.terminate ?? sock.close).call(sock);
654
+ }
655
+ catch {
656
+ }
657
+ resolvePromise(r);
658
+ };
659
+ const wallMs = opts?.timeoutMs;
660
+ const wallTimer = wallMs ? setTimeout(() => finish({ ok: false, error: new ExecutionError("timeout", `command exceeded ${wallMs}ms`) }), wallMs) : undefined;
661
+ let livenessTimer;
662
+ const livenessMs = opts?.livenessMs ?? this.cfg.livenessMs;
663
+ const armLiveness = () => {
664
+ if (livenessMs <= 0)
665
+ return;
666
+ clearTimeout(livenessTimer);
667
+ const idle = Date.now() - lastProgress;
668
+ if (idle >= livenessMs) {
669
+ finish({ ok: false, error: new ExecutionError("timeout", `no output for ${idle}ms (exec liveness) — suspected hang`) });
670
+ return;
671
+ }
672
+ livenessTimer = setTimeout(armLiveness, livenessMs - idle);
673
+ };
674
+ armLiveness();
675
+ const onAbort = () => finish({ ok: false, error: new ExecutionError("aborted", "command aborted") });
676
+ if (opts?.signal) {
677
+ if (opts.signal.aborted)
678
+ return onAbort();
679
+ opts.signal.addEventListener("abort", onAbort, { once: true });
680
+ }
681
+ sock.on("message", (...args) => {
682
+ const data = args[0];
683
+ const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
684
+ if (buf.length === 0)
685
+ return;
686
+ lastProgress = Date.now();
687
+ const channel = buf[0];
688
+ const payload = buf.subarray(1);
689
+ if (spliceSink) {
690
+ if (channel === 1 || channel === 2)
691
+ spliceSink.data(channel, payload);
692
+ else if (channel === 3)
693
+ statusFrame = payload.toString("utf8");
694
+ return;
695
+ }
696
+ if (channel === 1) {
697
+ if (boundOutput)
698
+ outTail.push(payload);
699
+ else
700
+ outBufs.push(payload);
701
+ if (detachTee)
702
+ feedMemStream(detachTee.out, payload, K8S_BG_MEM_CAP);
703
+ if (outDecoder)
704
+ opts.onStdout(outDecoder.write(payload));
705
+ }
706
+ else if (channel === 2) {
707
+ errBuf.push(payload);
708
+ if (detachTee)
709
+ feedMemStream(detachTee.err, payload, K8S_BG_MEM_CAP);
710
+ if (errDecoder)
711
+ opts.onStderr(errDecoder.write(payload));
712
+ }
713
+ else if (channel === 3) {
714
+ statusFrame = payload.toString("utf8");
715
+ }
716
+ });
717
+ sock.on("error", (...args) => {
718
+ const e = args[0];
719
+ if (spliceSink) {
720
+ if (!sinkClosed) {
721
+ sinkClosed = true;
722
+ spliceSink.closed({ failed: true });
723
+ }
724
+ return;
725
+ }
726
+ finish({ ok: false, error: new ExecutionError("transport_lost", `exec socket error: ${errorMessageOf(e)}`, e instanceof Error ? e : undefined) });
727
+ });
728
+ sock.on("close", () => {
729
+ if (spliceSink) {
730
+ if (sinkClosed)
731
+ return;
732
+ sinkClosed = true;
733
+ if (statusFrame === undefined)
734
+ return spliceSink.closed({ failed: true });
735
+ const parsed = exitCodeFromStatus(statusFrame);
736
+ return spliceSink.closed("error" in parsed ? { failed: true } : { failed: false, exitCode: parsed.exitCode });
737
+ }
738
+ if (statusFrame === undefined) {
739
+ finish({ ok: false, error: new ExecutionError("transport_lost", "exec socket closed without status — k8s transport lost mid-command") });
740
+ return;
741
+ }
742
+ const parsed = exitCodeFromStatus(statusFrame);
743
+ if ("error" in parsed) {
744
+ finish({ ok: false, error: new ExecutionError("spawn_error", parsed.error) });
745
+ return;
746
+ }
747
+ const err = errBuf.result();
748
+ const stderr = markTruncated(err.text, err.droppedBytes);
749
+ if (boundOutput) {
750
+ const out = outTail.result();
751
+ finish(ok({ stdout: markTruncated(out.text, out.droppedBytes), stderr, exitCode: parsed.exitCode }));
752
+ }
753
+ else {
754
+ finish(ok({ stdout: Buffer.concat(outBufs).toString("utf8"), stderr, exitCode: parsed.exitCode }));
755
+ }
756
+ });
757
+ const detach = opts?.detach;
758
+ if (detach) {
759
+ const onDetach = () => {
760
+ if (settled || spliceSink)
761
+ return;
762
+ const out = outTail ? outTail.result() : { text: "", droppedBytes: 0 };
763
+ const err = errBuf.result();
764
+ const shellId = detach.adopt({ sock, reroute: (sink) => { spliceSink = sink; } });
765
+ if (shellId === undefined) {
766
+ spliceSink = undefined;
767
+ return;
768
+ }
769
+ settled = true;
770
+ clearTimeout(wallTimer);
771
+ clearTimeout(livenessTimer);
772
+ opts?.signal?.removeEventListener("abort", onAbort);
773
+ removeDetachListener?.();
774
+ resolvePromise(ok({ stdout: markTruncated(out.text, out.droppedBytes), stderr: markTruncated(err.text, err.droppedBytes), exitCode: 0, detached: { shellId } }));
775
+ };
776
+ if (detach.signal.aborted)
777
+ onDetach();
778
+ else {
779
+ detach.signal.addEventListener("abort", onDetach, { once: true });
780
+ removeDetachListener = () => detach.signal.removeEventListener("abort", onDetach);
781
+ }
782
+ }
783
+ });
784
+ }
785
+ async exec(command, options) {
786
+ const c = await this.ensureConnected();
787
+ if (!c.ok)
788
+ return c;
789
+ const detachSignal = options?.detachSignal;
790
+ this.inFlightExecs++;
791
+ try {
792
+ const composed = this.withCwdEnv(command, options?.cwd, options?.env);
793
+ if (!detachSignal) {
794
+ return await this.runExec(composed, {
795
+ signal: options?.abortSignal,
796
+ timeoutMs: options?.timeout != null ? options.timeout * 1000 : undefined,
797
+ boundOutput: true,
798
+ onStdout: options?.onStdout,
799
+ onStderr: options?.onStderr,
800
+ });
801
+ }
802
+ const adoptId = randomUUID();
803
+ const dir = `${K8S_BG_DIR_ROOT}/exec-${adoptId}`;
804
+ const tee = { out: seedMemStream(""), err: seedMemStream("") };
805
+ return await this.runExec(buildDetachCapableExec(dir, composed), {
806
+ signal: options?.abortSignal,
807
+ timeoutMs: options?.timeout != null ? options.timeout * 1000 : undefined,
808
+ boundOutput: true,
809
+ onStdout: options?.onStdout,
810
+ onStderr: options?.onStderr,
811
+ detach: {
812
+ signal: detachSignal,
813
+ tee,
814
+ adopt: (io) => {
815
+ const adopted = this.bgManager.adoptSync((ctx) => {
816
+ const mem = { out: tee.out, err: tee.err };
817
+ io.reroute({
818
+ data: (channel, payload) => feedMemStream(channel === 1 ? mem.out : mem.err, payload, K8S_BG_MEM_CAP),
819
+ closed: (terminal) => ctx.onTerminal(terminal.failed, terminal.exitCode),
820
+ });
821
+ return { jobId: adoptId, dir, stdoutCursor: 0, stderrCursor: 0, adopt: { mem, sock: io.sock } };
822
+ });
823
+ return adopted?.shellId;
824
+ },
825
+ },
826
+ });
827
+ }
828
+ finally {
829
+ this.inFlightExecs--;
830
+ }
831
+ }
832
+ async getHost(port) {
833
+ const c = await this.ensureConnected();
834
+ if (!c.ok || !this.podIP)
835
+ return undefined;
836
+ return `${this.podIP}:${port}`;
837
+ }
838
+ async startBackground(command) {
839
+ const wrapped = command.replace(/[\\"$`]/g, (c) => "\\" + c);
840
+ const r = await this.exec(`(nohup sh -c "${wrapped}" >>/tmp/lsp-bridge.log 2>&1 &) ; echo started`, { timeout: 30 });
841
+ if (!r.ok)
842
+ throw new RemoteExecutionError("connect_failed", `startBackground failed: ${r.error.message}`, r.error);
843
+ if (r.value.exitCode !== 0)
844
+ throw new RemoteExecutionError("connect_failed", `startBackground exited ${r.value.exitCode}: ${r.value.stderr.slice(0, 200)}`);
845
+ }
846
+ async *execStream(command, options) {
847
+ const c = await this.ensureConnected();
848
+ if (!c.ok)
849
+ throw new RemoteExecutionError("connect_failed", c.error.message, c.error);
850
+ this.inFlightExecs++;
851
+ const queue = [];
852
+ let finished = false;
853
+ let failure;
854
+ let exitCode = 0;
855
+ let wake;
856
+ const signalReady = () => {
857
+ const w = wake;
858
+ wake = undefined;
859
+ w?.();
860
+ };
861
+ let lastChunk = Date.now();
862
+ const idleMs = options?.readTimeoutMs ?? this.cfg.livenessMs;
863
+ const cap = options?.maxOutputBytes;
864
+ let bytes = 0;
865
+ const ac = new AbortController();
866
+ const signal = options?.signal ? AbortSignal.any([options.signal, ac.signal]) : ac.signal;
867
+ const done = this.runExec(this.withCwdEnv(command, options?.cwd, options?.env), {
868
+ signal,
869
+ boundOutput: true,
870
+ onStdout: (d) => {
871
+ lastChunk = Date.now();
872
+ queue.push({ type: "stdout", data: d });
873
+ signalReady();
874
+ },
875
+ onStderr: (d) => {
876
+ lastChunk = Date.now();
877
+ queue.push({ type: "stderr", data: d });
878
+ signalReady();
879
+ },
880
+ }).then((r) => {
881
+ if (r.ok)
882
+ exitCode = r.value.exitCode;
883
+ else {
884
+ const code = r.error.code === "aborted"
885
+ ? "aborted"
886
+ : r.error.code === "transport_lost"
887
+ ? "transport_lost"
888
+ : r.error.code === "timeout"
889
+ ? "timeout"
890
+ : r.error.code === "spawn_error" || r.error.code === "shell_unavailable"
891
+ ? "unknown"
892
+ : "connect_failed";
893
+ failure = new RemoteExecutionError(code, r.error.message, r.error);
894
+ }
895
+ finished = true;
896
+ signalReady();
897
+ });
898
+ try {
899
+ for (;;) {
900
+ while (queue.length) {
901
+ const chunk = queue.shift();
902
+ yield chunk;
903
+ if (cap != null && chunk.type !== "exit") {
904
+ bytes += Buffer.byteLength(chunk.data, "utf8");
905
+ if (bytes > cap)
906
+ throw new RemoteExecutionError("unknown", `execStream output exceeded maxOutputBytes=${cap}`);
907
+ }
908
+ }
909
+ if (failure)
910
+ throw failure;
911
+ if (finished)
912
+ break;
913
+ const waitMs = Math.max(1, idleMs - (Date.now() - lastChunk));
914
+ await new Promise((r) => {
915
+ wake = r;
916
+ setTimeout(r, Math.min(waitMs, 30_000));
917
+ });
918
+ if (!finished && Date.now() - lastChunk >= idleMs) {
919
+ throw new RemoteExecutionError("timeout", `execStream idle > ${idleMs}ms (suspected hang)`);
920
+ }
921
+ }
922
+ while (queue.length)
923
+ yield queue.shift();
924
+ yield { type: "exit", exitCode };
925
+ }
926
+ finally {
927
+ ac.abort();
928
+ await done.catch(() => { });
929
+ this.inFlightExecs--;
930
+ }
931
+ }
932
+ backgroundCapabilities;
933
+ _bgManager;
934
+ get bgManager() {
935
+ return (this._bgManager ??= new BackgroundShellManager(this.makeBgDriver(), this.backgroundCapabilities));
936
+ }
937
+ makeBgDriver() {
938
+ const self = this;
939
+ const bgExec = (script, boundOutput) => self.runExec(script, { timeoutMs: self.cfg.rpcTimeoutMs, livenessMs: self.cfg.livenessMs, boundOutput });
940
+ return {
941
+ async launch(command, options, ctx) {
942
+ const conn = await self.ensureConnected();
943
+ if (!conn.ok)
944
+ throw new Error(`pod connect failed: ${conn.error.message}`);
945
+ const jobId = randomUUID();
946
+ const dir = `${K8S_BG_DIR_ROOT}/${jobId}`;
947
+ const inner = self.withCwdEnv(command, options?.cwd, options?.env);
948
+ const cmdB64 = Buffer.from(inner, "utf8").toString("base64");
949
+ const runnerB64 = Buffer.from(buildBgRunnerScript(dir), "utf8").toString("base64");
950
+ const r = await bgExec(buildBgLauncherScript(dir, cmdB64, runnerB64), true);
951
+ if (!r.ok)
952
+ throw new Error(`background launch failed: ${r.error.message}`);
953
+ if (r.value.exitCode !== 0 || !r.value.stdout.includes("SEMABG_LAUNCHED")) {
954
+ throw new Error(`background launch exited ${r.value.exitCode}: ${r.value.stderr.slice(0, 200)}`);
955
+ }
956
+ void ctx;
957
+ return { jobId, dir, stdoutCursor: 0, stderrCursor: 0 };
958
+ },
959
+ async read(state) {
960
+ if (state.adopt) {
961
+ const o = drainMemStream(state.adopt.mem.out);
962
+ const e = drainMemStream(state.adopt.mem.err);
963
+ return {
964
+ stdout: o.text,
965
+ stderr: e.text,
966
+ bytesFromStart: state.adopt.mem.out.totalBytes + state.adopt.mem.err.totalBytes,
967
+ bytesDroppedBeforeCursor: o.dropped + e.dropped,
968
+ };
969
+ }
970
+ const r = await bgExec(buildBgPollScript(state.dir, state.stdoutCursor, state.stderrCursor, K8S_BG_READ_CAP), false);
971
+ if (!r.ok)
972
+ throw new Error(`background poll failed: ${r.error.message}`);
973
+ const p = parseBgPollOutput(r.value.stdout);
974
+ if (!p)
975
+ throw new Error("background poll: unparseable response");
976
+ if (p.gone) {
977
+ return { stdout: "", stderr: "", bytesFromStart: state.stdoutCursor + state.stderrCursor, bytesDroppedBeforeCursor: 0, terminal: { failed: true } };
978
+ }
979
+ const droppedO = Math.max(0, p.outTotal - state.stdoutCursor - p.stdoutBytes);
980
+ const droppedE = Math.max(0, p.errTotal - state.stderrCursor - p.stderrBytes);
981
+ state.stdoutCursor = p.outTotal;
982
+ state.stderrCursor = p.errTotal;
983
+ let terminal = p.exitCode !== undefined ? { failed: false, exitCode: p.exitCode } : !p.alive ? { failed: true } : undefined;
984
+ if (!terminal && (p.outTotal > K8S_BG_FILE_CAP || p.errTotal > K8S_BG_FILE_CAP)) {
985
+ void bgExec(buildBgKillScript(state.dir), true).catch(() => { });
986
+ terminal = { failed: true };
987
+ }
988
+ return {
989
+ stdout: p.stdout,
990
+ stderr: p.stderr,
991
+ bytesFromStart: p.outTotal + p.errTotal,
992
+ bytesDroppedBeforeCursor: droppedO + droppedE,
993
+ ...(terminal ? { terminal } : {}),
994
+ };
995
+ },
996
+ async kill(state) {
997
+ await bgExec(buildBgKillScript(state.dir), true).catch(() => { });
998
+ },
999
+ async disposeOne(state) {
1000
+ const closeAdopted = () => {
1001
+ if (!state.adopt)
1002
+ return;
1003
+ try {
1004
+ (state.adopt.sock.terminate ?? state.adopt.sock.close).call(state.adopt.sock);
1005
+ }
1006
+ catch { }
1007
+ };
1008
+ if (self.destroyed) {
1009
+ closeAdopted();
1010
+ return;
1011
+ }
1012
+ await bgExec(buildBgDisposeScript(state.dir), true).catch(() => { });
1013
+ closeAdopted();
1014
+ },
1015
+ };
1016
+ }
1017
+ spawnBackground(command, options) {
1018
+ return this.bgManager.spawn(command, options);
1019
+ }
1020
+ pollBackground(shellId) {
1021
+ return this.bgManager.poll(shellId);
1022
+ }
1023
+ killBackground(shellId) {
1024
+ return this.bgManager.kill(shellId);
1025
+ }
1026
+ disposeBackgroundShells(opts) {
1027
+ return this._bgManager ? this._bgManager.dispose(opts) : Promise.resolve();
1028
+ }
1029
+ async absolutePath(p) {
1030
+ return ok(this.resolve(p));
1031
+ }
1032
+ async joinPath(parts) {
1033
+ return ok(path.posix.join(...parts));
1034
+ }
1035
+ async readBinaryFile(p, abortSignal) {
1036
+ const abs = this.resolve(p);
1037
+ const r = await this.execData(`base64 < ${shellQuote(abs)}`, abortSignal);
1038
+ if (!r.ok)
1039
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1040
+ if (r.value.exitCode !== 0)
1041
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs, "not_found") };
1042
+ return ok(new Uint8Array(Buffer.from(r.value.stdout.replace(/\s+/g, ""), "base64")));
1043
+ }
1044
+ async readTextFile(p, abortSignal) {
1045
+ const r = await this.readBinaryFile(p, abortSignal);
1046
+ return r.ok ? ok(Buffer.from(r.value).toString("utf8")) : r;
1047
+ }
1048
+ async readTextLines(p, options) {
1049
+ const r = await this.readTextFile(p, options?.abortSignal);
1050
+ if (!r.ok)
1051
+ return r;
1052
+ let lines = r.value.split(/\r?\n/);
1053
+ if (lines.length > 0 && lines[lines.length - 1] === "")
1054
+ lines.pop();
1055
+ if (options?.maxLines != null)
1056
+ lines = lines.slice(0, options.maxLines);
1057
+ return ok(lines);
1058
+ }
1059
+ async writeFile(p, content, abortSignal) {
1060
+ const abs = this.resolve(p);
1061
+ const dir = path.posix.dirname(abs);
1062
+ if (dir && dir !== "." && dir !== "/") {
1063
+ const mk = await this.exec(`mkdir -p ${shellQuote(dir)}`, { abortSignal });
1064
+ if (!mk.ok)
1065
+ return { ok: false, error: new FileError("unknown", mk.error.message, dir, mk.error) };
1066
+ if (mk.value.exitCode !== 0)
1067
+ return { ok: false, error: this.fileErrorFrom(mk.value.stderr, dir) };
1068
+ }
1069
+ return this.writeChunked(abs, content, true, abortSignal);
1070
+ }
1071
+ async appendFile(p, content, abortSignal) {
1072
+ return this.writeChunked(this.resolve(p), content, false, abortSignal);
1073
+ }
1074
+ async writeChunked(abs, content, truncateFirst, abortSignal) {
1075
+ const bytes = typeof content === "string" ? Buffer.from(content, "utf8") : Buffer.from(content);
1076
+ for (let off = 0, first = true; off < bytes.length || first; off += WRITE_CHUNK_BYTES, first = false) {
1077
+ const b64 = bytes.subarray(off, off + WRITE_CHUNK_BYTES).toString("base64");
1078
+ const redirect = first && truncateFirst ? ">" : ">>";
1079
+ const r = await this.execData(`printf '%s' ${shellQuote(b64)} | base64 -d ${redirect} ${shellQuote(abs)}`, abortSignal);
1080
+ if (!r.ok)
1081
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1082
+ if (r.value.exitCode !== 0)
1083
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs) };
1084
+ }
1085
+ return ok(undefined);
1086
+ }
1087
+ async fileInfo(p, abortSignal) {
1088
+ const abs = this.resolve(p);
1089
+ const r = await this.exec(`stat -c '%s %Y %f' ${shellQuote(abs)}`, { abortSignal });
1090
+ if (!r.ok)
1091
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1092
+ if (r.value.exitCode !== 0)
1093
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs, "not_found") };
1094
+ const [sizeS, mtimeS, modeHex] = r.value.stdout.trim().split(/\s+/);
1095
+ return ok({ name: path.posix.basename(abs), path: abs, kind: kindFromMode(parseInt(modeHex ?? "0", 16)), size: Number(sizeS) || 0, mtimeMs: (Number(mtimeS) || 0) * 1000 });
1096
+ }
1097
+ async listDir(p, abortSignal) {
1098
+ const abs = this.resolve(p);
1099
+ const r = await this.exec(`ls -1A ${shellQuote(abs)}`, { abortSignal });
1100
+ if (!r.ok)
1101
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1102
+ if (r.value.exitCode !== 0)
1103
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs) };
1104
+ const names = r.value.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
1105
+ const out = [];
1106
+ for (const name of names) {
1107
+ const info = await this.fileInfo(path.posix.join(abs, name), abortSignal);
1108
+ out.push(info.ok ? info.value : { name, path: path.posix.join(abs, name), kind: "file", size: 0, mtimeMs: 0 });
1109
+ }
1110
+ return ok(out);
1111
+ }
1112
+ async canonicalPath(p, abortSignal) {
1113
+ const abs = this.resolve(p);
1114
+ const r = await this.exec(`realpath ${shellQuote(abs)}`, { abortSignal });
1115
+ if (!r.ok)
1116
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1117
+ if (r.value.exitCode !== 0)
1118
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs, "not_found") };
1119
+ return ok(r.value.stdout.trim());
1120
+ }
1121
+ async exists(p, abortSignal) {
1122
+ const abs = this.resolve(p);
1123
+ const r = await this.exec(`[ -e ${shellQuote(abs)} ] && printf yes || printf no`, { abortSignal });
1124
+ if (!r.ok)
1125
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1126
+ const out = r.value.stdout.trim();
1127
+ if (out === "yes")
1128
+ return ok(true);
1129
+ if (out === "no")
1130
+ return ok(false);
1131
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs) };
1132
+ }
1133
+ async createDir(p, options) {
1134
+ const abs = this.resolve(p);
1135
+ const r = await this.exec(`mkdir ${options?.recursive === false ? "" : "-p "}${shellQuote(abs)}`, { abortSignal: options?.abortSignal });
1136
+ if (!r.ok)
1137
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1138
+ if (r.value.exitCode !== 0)
1139
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs) };
1140
+ return ok(undefined);
1141
+ }
1142
+ async remove(p, options) {
1143
+ const abs = this.resolve(p);
1144
+ const flags = `${options?.recursive ? "r" : ""}${options?.force ? "f" : ""}`;
1145
+ const r = await this.exec(`rm ${flags ? `-${flags}` : ""} ${shellQuote(abs)}`, { abortSignal: options?.abortSignal });
1146
+ if (!r.ok)
1147
+ return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
1148
+ if (r.value.exitCode !== 0) {
1149
+ if (options?.force && /no such file/i.test(r.value.stderr))
1150
+ return ok(undefined);
1151
+ return { ok: false, error: this.fileErrorFrom(r.value.stderr, abs) };
1152
+ }
1153
+ return ok(undefined);
1154
+ }
1155
+ async createTempDir(prefix = "tmp-", abortSignal) {
1156
+ const r = await this.exec(`mktemp -d -p ${shellQuote(this.cwd)} ${shellQuote(`${prefix}XXXXXX`)}`, { abortSignal });
1157
+ return this.tempResult(r, "mktemp -d");
1158
+ }
1159
+ async createTempFile(options) {
1160
+ const tmpl = `${options?.prefix ?? ""}XXXXXX${options?.suffix ?? ""}`;
1161
+ const r = await this.exec(`mktemp -p ${shellQuote(this.cwd)} ${shellQuote(tmpl)}`, { abortSignal: options?.abortSignal });
1162
+ return this.tempResult(r, "mktemp");
1163
+ }
1164
+ async execData(command, abortSignal) {
1165
+ const c = await this.ensureConnected();
1166
+ if (!c.ok)
1167
+ return c;
1168
+ return this.runExec(command, { signal: abortSignal, timeoutMs: this.cfg.dataTimeoutMs });
1169
+ }
1170
+ withCwdEnv(command, cwd, env) {
1171
+ const parts = [];
1172
+ const dir = cwd ?? this.cwd;
1173
+ if (dir)
1174
+ parts.push(`cd ${shellQuote(this.resolve(dir))} &&`);
1175
+ if (env)
1176
+ for (const [k, v] of Object.entries(env))
1177
+ parts.push(`export ${k}=${shellQuote(v)};`);
1178
+ parts.push(command);
1179
+ return parts.join(" ");
1180
+ }
1181
+ fileErrorFrom(stderr, p, fallback = "unknown") {
1182
+ const msg = stderr.trim();
1183
+ if (/no such file/i.test(msg))
1184
+ return new FileError("not_found", msg, p);
1185
+ if (/permission denied/i.test(msg))
1186
+ return new FileError("permission_denied", msg, p);
1187
+ if (/is a directory/i.test(msg))
1188
+ return new FileError("is_directory", msg, p);
1189
+ if (/not a directory/i.test(msg))
1190
+ return new FileError("not_directory", msg, p);
1191
+ if (/input\/output error|too many levels|file name too long|no space left/i.test(msg))
1192
+ return new FileError("unknown", msg, p);
1193
+ return new FileError(fallback, msg || "command failed", p);
1194
+ }
1195
+ tempResult(r, label) {
1196
+ if (!r.ok)
1197
+ return { ok: false, error: new FileError("unknown", r.error.message, undefined, r.error) };
1198
+ if (r.value.exitCode !== 0)
1199
+ return { ok: false, error: new FileError("unknown", r.value.stderr.trim() || `${label} failed`) };
1200
+ return ok(r.value.stdout.trim());
1201
+ }
1202
+ }
1203
+ export function k8sExecutionEnvFactory(config) {
1204
+ return (ctx) => new RemoteK8sExecutionEnv({ ...config, sessionId: ctx.sessionId });
1205
+ }
1206
+ //# sourceMappingURL=remote-env-k8s.js.map