supertag-ai 0.2.0-alpha.5 → 0.2.0-alpha.7

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 (265) hide show
  1. package/README.md +13 -15
  2. package/dist/{chunk-PBAY7U4H.js → chunk-5EEBCIHE.js} +3 -3
  3. package/dist/{chunk-PBAY7U4H.js.map → chunk-5EEBCIHE.js.map} +1 -1
  4. package/dist/chunk-7I5O2AQ2.js +136 -0
  5. package/dist/chunk-7I5O2AQ2.js.map +1 -0
  6. package/dist/chunk-7U3AHYY3.js +10486 -0
  7. package/dist/chunk-7U3AHYY3.js.map +1 -0
  8. package/dist/{chunk-3AJCSJRB.js → chunk-AV6P35OM.js} +13 -15
  9. package/dist/chunk-AV6P35OM.js.map +1 -0
  10. package/dist/{chunk-H2D4SJJV.js → chunk-FGNUARJO.js} +10 -9
  11. package/dist/chunk-FGNUARJO.js.map +1 -0
  12. package/dist/chunk-FXQ4IGSL.js +136 -0
  13. package/dist/chunk-FXQ4IGSL.js.map +1 -0
  14. package/dist/{chunk-DVCC72IZ.js → chunk-IQIGPLQB.js} +3 -3
  15. package/dist/{chunk-DVCC72IZ.js.map → chunk-IQIGPLQB.js.map} +1 -1
  16. package/dist/chunk-NLJT7EUA.js +3195 -0
  17. package/dist/chunk-NLJT7EUA.js.map +1 -0
  18. package/dist/chunk-PEGY7YJA.js +84 -0
  19. package/dist/chunk-PEGY7YJA.js.map +1 -0
  20. package/dist/{chunk-2F76KZCF.js → chunk-PNIEQ6LP.js} +4 -4
  21. package/dist/{chunk-2F76KZCF.js.map → chunk-PNIEQ6LP.js.map} +1 -1
  22. package/dist/{chunk-YJCJLNXV.js → chunk-QTMCVECV.js} +55 -94
  23. package/dist/chunk-QTMCVECV.js.map +1 -0
  24. package/dist/{chunk-XWDU2LGD.js → chunk-UE7B7IPC.js} +4 -4
  25. package/dist/{chunk-XWDU2LGD.js.map → chunk-UE7B7IPC.js.map} +1 -1
  26. package/dist/{chunk-GGLTVY7F.js → chunk-US7635QX.js} +436 -459
  27. package/dist/chunk-US7635QX.js.map +1 -0
  28. package/dist/{chunk-4UEMA2QC.js → chunk-X2YMYYEO.js} +54 -173
  29. package/dist/chunk-X2YMYYEO.js.map +1 -0
  30. package/dist/{chunk-KUH6RQAM.js → chunk-X5UYJR3C.js} +77 -90
  31. package/dist/chunk-X5UYJR3C.js.map +1 -0
  32. package/dist/{chunk-XVXA3U5I.js → chunk-ZTO7N6RJ.js} +11 -27
  33. package/dist/chunk-ZTO7N6RJ.js.map +1 -0
  34. package/dist/cli.js +2 -2
  35. package/dist/cli.js.map +1 -1
  36. package/dist/control-plane.d.ts +511 -693
  37. package/dist/control-plane.js +3 -4
  38. package/dist/coordination.d.ts +1223 -11
  39. package/dist/coordination.js +21 -47
  40. package/dist/coordination.js.map +1 -1
  41. package/dist/core.d.ts +1 -1
  42. package/dist/core.js +1 -2
  43. package/dist/{cursor-sign-in-VZYMNUV7.js → cursor-sign-in-YGMDEBZU.js} +4 -5
  44. package/dist/cursor-sign-in-YGMDEBZU.js.map +1 -0
  45. package/dist/docs/README.md +33 -29
  46. package/dist/docs/concepts/README.md +34 -29
  47. package/dist/docs/concepts/context-and-permissions.md +4 -4
  48. package/dist/docs/concepts/how-it-works.md +20 -17
  49. package/dist/docs/concepts/interaction-model.md +38 -25
  50. package/dist/docs/concepts/multiplayer.md +90 -49
  51. package/dist/docs/concepts/roles.md +7 -20
  52. package/dist/docs/concepts/supertag-and-other-agent-systems.md +19 -16
  53. package/dist/docs/concepts/tags.md +9 -8
  54. package/dist/docs/concepts/tasks.md +216 -81
  55. package/dist/docs/concepts/workers.md +4 -4
  56. package/dist/docs/guides/coding-agent-operator.md +16 -15
  57. package/dist/docs/guides/custom-context.md +1 -1
  58. package/dist/docs/guides/custom-workers.md +3 -3
  59. package/dist/docs/guides/deploy-cloudflare.md +1 -1
  60. package/dist/docs/guides/deploy-fly.md +1 -1
  61. package/dist/docs/guides/deploy-modal.md +1 -1
  62. package/dist/docs/guides/deploy-railway.md +1 -1
  63. package/dist/docs/guides/deploy-render.md +1 -1
  64. package/dist/docs/guides/deployment-setup.md +1 -1
  65. package/dist/docs/guides/first-team.md +62 -49
  66. package/dist/docs/guides/harness-runtime.md +19 -46
  67. package/dist/docs/guides/notifications.md +3 -2
  68. package/dist/docs/guides/objective-decisions.md +114 -186
  69. package/dist/docs/guides/objective-overview.md +118 -155
  70. package/dist/docs/guides/objectives.md +220 -243
  71. package/dist/docs/guides/ongoing-responsibilities.md +138 -206
  72. package/dist/docs/guides/python-workers.md +41 -9
  73. package/dist/docs/guides/self-hosting.md +1 -1
  74. package/dist/docs/guides/shared-execution.md +1 -1
  75. package/dist/docs/guides/tag-messaging.md +82 -194
  76. package/dist/docs/guides/talk-to-a-tag.md +248 -0
  77. package/dist/docs/guides/teams.md +103 -144
  78. package/dist/docs/guides/troubleshooting.md +70 -13
  79. package/dist/docs/guides/workers.md +2 -2
  80. package/dist/docs/guides/workspaces.md +87 -79
  81. package/dist/docs/guides/workstreams.md +58 -251
  82. package/dist/docs/guides/write-an-objective.md +10 -10
  83. package/dist/docs/operations/cli.md +43 -66
  84. package/dist/docs/operations/control-plane.md +55 -72
  85. package/dist/docs/operations/install.md +58 -14
  86. package/dist/docs/operations/requirements.md +19 -15
  87. package/dist/docs/operations/resources.md +46 -69
  88. package/dist/docs/reference/api-stability.md +17 -14
  89. package/dist/docs/reference/artifacts.md +2 -2
  90. package/dist/docs/reference/context-resolution.md +13 -3
  91. package/dist/docs/reference/control-plane-api.md +293 -733
  92. package/dist/docs/reference/control-plane.md +1 -1
  93. package/dist/docs/reference/coordination.md +676 -1855
  94. package/dist/docs/reference/glossary.md +26 -30
  95. package/dist/docs/reference/iam.md +39 -26
  96. package/dist/docs/reference/operator-api/README.md +112 -0
  97. package/dist/docs/reference/operator-api/access.md +161 -0
  98. package/dist/docs/reference/operator-api/conversation.md +495 -0
  99. package/dist/docs/reference/operator-api/event.md +144 -0
  100. package/dist/docs/reference/operator-api/host.md +567 -0
  101. package/dist/docs/reference/operator-api/inbox.md +421 -0
  102. package/dist/docs/reference/operator-api/mailbox.md +232 -0
  103. package/dist/docs/reference/operator-api/objective.md +767 -0
  104. package/dist/docs/reference/operator-api/organization.md +558 -0
  105. package/dist/docs/reference/operator-api/resource.md +1183 -0
  106. package/dist/docs/reference/operator-api/shared.md +322 -0
  107. package/dist/docs/reference/operator-api/surface.md +352 -0
  108. package/dist/docs/reference/operator-api/team.md +223 -0
  109. package/dist/docs/reference/operator-api/work.md +1329 -0
  110. package/dist/docs/reference/resource-model.md +69 -82
  111. package/dist/docs/reference/scheduling-and-recovery.md +108 -128
  112. package/dist/docs/reference/supertag-yaml.md +4 -2
  113. package/dist/docs/reference/worker.md +90 -72
  114. package/dist/docs/surfaces/README.md +2 -2
  115. package/dist/{durable-worklet-ePEZC6dl.d.ts → durable-worklet-DVn2oCzG.d.ts} +2 -2
  116. package/dist/environments/e2b.d.ts +3 -3
  117. package/dist/environments/e2b.js +3 -4
  118. package/dist/environments/modal.d.ts +3 -3
  119. package/dist/environments/modal.js +3 -4
  120. package/dist/environments/shared-execution.d.ts +2 -2
  121. package/dist/environments/shared-execution.js +12 -6
  122. package/dist/environments/shared-execution.js.map +1 -1
  123. package/dist/harnesses/claude-code.d.ts +13 -3
  124. package/dist/harnesses/claude-code.js +4 -4
  125. package/dist/harnesses/codex.d.ts +14 -7
  126. package/dist/harnesses/codex.js +4 -4
  127. package/dist/harnesses/cursor.d.ts +3 -3
  128. package/dist/harnesses/cursor.js +5 -6
  129. package/dist/harnesses/opencode.d.ts +2 -2
  130. package/dist/harnesses/opencode.js +3 -4
  131. package/dist/harnesses-TZJPHPCT.js +5 -0
  132. package/dist/harnesses-TZJPHPCT.js.map +1 -0
  133. package/dist/{index-DCkmrR0S.d.ts → index-4JwxWljl.d.ts} +538 -1120
  134. package/dist/{index-XN-OK-Uq.d.ts → index-Csw9kVep.d.ts} +12 -24
  135. package/dist/{index-BN-4fC6K.d.ts → index-u5l3dViP.d.ts} +3 -3
  136. package/dist/index.d.ts +4 -4
  137. package/dist/index.js +4 -6
  138. package/dist/{mcp-custom-tools-gNa_8t0r.d.ts → mcp-custom-tools-DmMU_jnU.d.ts} +1 -1
  139. package/dist/{opencode-sign-in-KSCTH2WC.js → opencode-sign-in-TCOKDJYH.js} +4 -5
  140. package/dist/opencode-sign-in-TCOKDJYH.js.map +1 -0
  141. package/dist/resources/github.d.ts +8 -7
  142. package/dist/resources/github.js +3 -4
  143. package/dist/runner.d.ts +3 -3
  144. package/dist/runner.js +4 -5
  145. package/dist/runner.js.map +1 -1
  146. package/dist/{sandbox-workspace-environment-DRRCzSJQ.d.ts → sandbox-workspace-environment-CvpuiK5H.d.ts} +2 -2
  147. package/dist/spec/README.md +16 -22
  148. package/dist/spec/common.schema.json +1 -33
  149. package/dist/spec/manifests/context-set.schema.json +95 -0
  150. package/dist/spec/manifests/manifest.schema.json +32 -0
  151. package/dist/spec/manifests/objective.schema.json +160 -0
  152. package/dist/spec/manifests/permission-set.schema.json +167 -0
  153. package/dist/spec/manifests/role.schema.json +131 -0
  154. package/dist/spec/manifests/surface-account.schema.json +511 -0
  155. package/dist/spec/manifests/tag.schema.json +439 -0
  156. package/dist/spec/manifests/volume.schema.json +64 -0
  157. package/dist/spec/manifests/workspace.schema.json +202 -0
  158. package/dist/spec/objective.schema.json +36 -10
  159. package/dist/spec/objectives.md +92 -91
  160. package/dist/spec/proto/accepted-breaking-changes.json +15 -0
  161. package/dist/spec/proto/supertag/operator/v1/access.proto +138 -0
  162. package/dist/spec/proto/supertag/operator/v1/common.proto +150 -0
  163. package/dist/spec/proto/supertag/operator/v1/conversation.proto +515 -0
  164. package/dist/spec/proto/supertag/operator/v1/event.proto +162 -0
  165. package/dist/spec/proto/supertag/operator/v1/host.proto +551 -0
  166. package/dist/spec/proto/supertag/operator/v1/inbox.proto +470 -0
  167. package/dist/spec/proto/supertag/operator/v1/mailbox.proto +215 -0
  168. package/dist/spec/proto/supertag/operator/v1/objective.proto +894 -0
  169. package/dist/spec/proto/supertag/operator/v1/options.proto +155 -0
  170. package/dist/spec/proto/supertag/operator/v1/organization.proto +637 -0
  171. package/dist/spec/proto/supertag/operator/v1/resource.proto +1496 -0
  172. package/dist/spec/proto/supertag/operator/v1/surface.proto +344 -0
  173. package/dist/spec/proto/supertag/operator/v1/task.proto +132 -0
  174. package/dist/spec/proto/supertag/operator/v1/team.proto +204 -0
  175. package/dist/spec/proto/supertag/operator/v1/work.proto +1478 -0
  176. package/dist/spec/task-attempt-spec.schema.json +0 -3
  177. package/dist/spec/team.schema.json +3 -11
  178. package/dist/spec/worker-spi.md +13 -15
  179. package/dist/spec/workstream.schema.json +13 -42
  180. package/dist/spec/workstreams.md +37 -142
  181. package/dist/src-AABARFVT.js +8 -0
  182. package/dist/src-AABARFVT.js.map +1 -0
  183. package/dist/{src-NJP6L4P7.js → src-JBYMQTOH.js} +7 -8
  184. package/dist/src-JBYMQTOH.js.map +1 -0
  185. package/dist/src-NSMNFU2H.js +7 -0
  186. package/dist/{src-NJP6L4P7.js.map → src-NSMNFU2H.js.map} +1 -1
  187. package/dist/{src-IM5LBBN7.js → src-NZYS6TFE.js} +26550 -30502
  188. package/dist/src-NZYS6TFE.js.map +1 -0
  189. package/dist/{src-ITRVRAVT.js → src-PVNGXKKZ.js} +5 -6
  190. package/dist/src-PVNGXKKZ.js.map +1 -0
  191. package/dist/src-SU6BAMWL.js +6 -0
  192. package/dist/src-SU6BAMWL.js.map +1 -0
  193. package/dist/surfaces.d.ts +1 -1
  194. package/dist/testing.d.ts +2 -2
  195. package/dist/testing.js +2 -3
  196. package/dist/testing.js.map +1 -1
  197. package/dist/transport.d.ts +6 -18
  198. package/dist/transport.js +4 -6
  199. package/dist/worker.d.ts +6 -6
  200. package/dist/worker.js +2 -3
  201. package/drizzle/postgresql/0029_tense_ser_duncan.sql +2 -0
  202. package/drizzle/postgresql/0030_session_audience_backfill.sql +16 -0
  203. package/drizzle/postgresql/0031_dark_violations.sql +3 -0
  204. package/drizzle/postgresql/0032_objective_coordination_references.sql +7 -0
  205. package/drizzle/postgresql/0033_tag_sessions_objectives.sql +38 -0
  206. package/drizzle/postgresql/0034_teams_and_inboxes.sql +62 -0
  207. package/drizzle/postgresql/meta/0029_snapshot.json +8788 -0
  208. package/drizzle/postgresql/meta/0030_snapshot.json +8788 -0
  209. package/drizzle/postgresql/meta/0031_snapshot.json +8818 -0
  210. package/drizzle/postgresql/meta/0032_snapshot.json +8788 -0
  211. package/drizzle/postgresql/meta/0033_snapshot.json +6710 -0
  212. package/drizzle/postgresql/meta/0034_snapshot.json +7225 -0
  213. package/drizzle/postgresql/meta/_journal.json +42 -0
  214. package/drizzle/sqlite/0029_safe_white_tiger.sql +2 -0
  215. package/drizzle/sqlite/0030_session_audience_backfill.sql +18 -0
  216. package/drizzle/sqlite/0031_simple_queen_noir.sql +2 -0
  217. package/drizzle/sqlite/0032_objective_coordination_references.sql +58 -0
  218. package/drizzle/sqlite/0033_tag_sessions_objectives.sql +24 -0
  219. package/drizzle/sqlite/0034_teams_and_inboxes.sql +61 -0
  220. package/drizzle/sqlite/meta/0029_snapshot.json +7167 -0
  221. package/drizzle/sqlite/meta/0030_snapshot.json +7167 -0
  222. package/drizzle/sqlite/meta/0031_snapshot.json +7188 -0
  223. package/drizzle/sqlite/meta/0032_snapshot.json +7167 -0
  224. package/drizzle/sqlite/meta/0033_snapshot.json +5434 -0
  225. package/drizzle/sqlite/meta/0034_snapshot.json +5832 -0
  226. package/drizzle/sqlite/meta/_journal.json +42 -0
  227. package/package.json +4 -6
  228. package/dist/chunk-3AJCSJRB.js.map +0 -1
  229. package/dist/chunk-4UEMA2QC.js.map +0 -1
  230. package/dist/chunk-AJ6TWOBT.js +0 -1718
  231. package/dist/chunk-AJ6TWOBT.js.map +0 -1
  232. package/dist/chunk-FMADEKHP.js +0 -2187
  233. package/dist/chunk-FMADEKHP.js.map +0 -1
  234. package/dist/chunk-GGLTVY7F.js.map +0 -1
  235. package/dist/chunk-H2D4SJJV.js.map +0 -1
  236. package/dist/chunk-KUH6RQAM.js.map +0 -1
  237. package/dist/chunk-VMYJK5OS.js +0 -12815
  238. package/dist/chunk-VMYJK5OS.js.map +0 -1
  239. package/dist/chunk-XVMWCCXU.js +0 -457
  240. package/dist/chunk-XVMWCCXU.js.map +0 -1
  241. package/dist/chunk-XVXA3U5I.js.map +0 -1
  242. package/dist/chunk-YJCJLNXV.js.map +0 -1
  243. package/dist/cursor-sign-in-VZYMNUV7.js.map +0 -1
  244. package/dist/docs/guides/objective-coordination.md +0 -405
  245. package/dist/docs/reference/mailbox.md +0 -756
  246. package/dist/messaging.d.ts +0 -59
  247. package/dist/messaging.js +0 -5
  248. package/dist/messaging.js.map +0 -1
  249. package/dist/opencode-sign-in-KSCTH2WC.js.map +0 -1
  250. package/dist/spec/objective-manifest.schema.json +0 -96
  251. package/dist/spec/proto/supertag/authority/v1/authority.proto +0 -10
  252. package/dist/spec/proto/supertag/mailbox/v1/mailbox.proto +0 -129
  253. package/dist/spec/resource-deletion.schema.json +0 -50
  254. package/dist/spec/surface-account-manifest.schema.json +0 -231
  255. package/dist/spec/tag-directory.schema.json +0 -85
  256. package/dist/spec/tag-message.schema.json +0 -88
  257. package/dist/spec/tag-messaging.md +0 -191
  258. package/dist/src-25NGYB52.js +0 -7
  259. package/dist/src-25NGYB52.js.map +0 -1
  260. package/dist/src-6LBZD4HC.js +0 -7
  261. package/dist/src-6LBZD4HC.js.map +0 -1
  262. package/dist/src-IM5LBBN7.js.map +0 -1
  263. package/dist/src-ITRVRAVT.js.map +0 -1
  264. package/dist/src-OSKS5ATA.js +0 -8
  265. package/dist/src-OSKS5ATA.js.map +0 -1
package/README.md CHANGED
@@ -1,20 +1,18 @@
1
1
  # supertag-ai
2
2
 
3
- **Define outcomes, not tasks. An AI engineering team delivers them.**
3
+ **Persistent AI identities for engineering work.**
4
4
 
5
- SuperTag is open infrastructure for running autonomous AI engineering teams on your models,
6
- harnesses, and machines. Describe an outcome with success criteria, a budget, a deadline, and the
7
- approvals you want to keep. A team plans the work, runs it in parallel, reviews results, and brings
8
- you the decisions that need you.
5
+ SuperTag is the open alternative to dots for engineering work. A **Tag** is a persistent AI
6
+ identity with its own responsibilities and permissions. You talk to it in your terminal, in Slack,
7
+ or on a GitHub issue. It runs the work on your coding agents (Claude Code, Codex, Cursor, or
8
+ OpenCode), asks you when a decision is yours, and returns a git branch to review.
9
9
 
10
- Each team member is a **Tag**: a persistent AI identity with its own responsibilities and permissions.
11
- An **Objective** records the outcome the team works toward. A **Team** is a group of Tags with a lead,
12
- and a **Task** is one assignment accepted by a Tag. Objectives and their history survive individual
13
- agent sessions and restarts.
14
-
15
- For example: “People can invite teammates to a workspace and choose their role. Done when the
16
- end-to-end tests pass and the API docs cover it. Ask me before changing the database schema.”
17
- A lead Tag can coordinate builders and reviewers across that work while you steer the outcome.
10
+ For bigger work, give a Tag an **Objective**: an outcome with done-when evidence, a budget, a
11
+ deadline, and the approvals you keep. For example: “People can invite teammates to a workspace and
12
+ choose their role. Done when the end-to-end tests pass and the API docs cover it. Ask me before
13
+ changing the database schema.” The Tag plans the work and starts a **Session** for each piece,
14
+ including Sessions of the other Tags on its **Team**, a flat list of member Tags. A **Task** is one
15
+ turn of a Session. Objectives and their history survive individual agent sessions and restarts.
18
16
 
19
17
  This package contains the **CLI and TypeScript extension SDK**. It is the only public SuperTag npm
20
18
  package; applications use its public entry points rather than private workspace packages.
@@ -129,7 +127,7 @@ Use explicit entry points for integrations and lower-level contracts:
129
127
  | `supertag-ai/worker` | Custom Workers, harnesses, input resolution, tools, environments, and continuity |
130
128
  | `supertag-ai/transport` | Worklet transport and protocol contracts |
131
129
  | `supertag-ai/messaging` | Tag messaging, Team channels, and custom Worker consumers |
132
- | `supertag-ai/coordination` | Typed operator client and the redacted coordination inbox |
130
+ | `supertag-ai/coordination` | Typed client for the operator inbox |
133
131
  | `supertag-ai/testing` | Extension conformance probes |
134
132
  | `supertag-ai/surfaces` | Custom collaboration surfaces |
135
133
  | `supertag-ai/control-plane` | Embedding the Control Plane |
@@ -163,7 +161,7 @@ To find bundled collaboration surface guides and manifests, run `supertag setup
163
161
  The matching Python SDK is published separately as `supertag` on PyPI:
164
162
 
165
163
  ```sh
166
- python -m pip install 'supertag==0.2.0a5'
164
+ python -m pip install 'supertag==0.2.0a7'
167
165
  ```
168
166
 
169
167
  Pin the prerelease explicitly so pip selects the matching SDK. Python applications can compose
@@ -1,4 +1,4 @@
1
- import { SandboxExecutionEnvironmentProvider, validatedDevcontainerDockerfile, SandboxWorkspaceEnvironment, materializeTrustedBuildContext, devcontainerImageUser, resolvedDevcontainerEnv, materializeSandboxArtifactFiles, listSandboxOutputFiles, prepareSandboxOutputDirectory } from './chunk-GGLTVY7F.js';
1
+ import { SandboxExecutionEnvironmentProvider, validatedDevcontainerDockerfile, SandboxWorkspaceEnvironment, materializeTrustedBuildContext, devcontainerImageUser, resolvedDevcontainerEnv, materializeSandboxArtifactFiles, listSandboxOutputFiles, prepareSandboxOutputDirectory } from './chunk-US7635QX.js';
2
2
  import { randomUUID } from 'crypto';
3
3
  import { writeFile, mkdir, mkdtemp, copyFile, rm } from 'fs/promises';
4
4
  import { posix, join } from 'path';
@@ -361,5 +361,5 @@ finally:
361
361
  `;
362
362
 
363
363
  export { E2BExecutionEnvironmentProvider, E2BWorkspaceEnvironment, E2B_REMOTE_SANDBOX_CAPABILITY, nativeTemplateClient, stageE2BDockerfile };
364
- //# sourceMappingURL=chunk-PBAY7U4H.js.map
365
- //# sourceMappingURL=chunk-PBAY7U4H.js.map
364
+ //# sourceMappingURL=chunk-5EEBCIHE.js.map
365
+ //# sourceMappingURL=chunk-5EEBCIHE.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../runtime/environments/e2b/src/index.ts"],"names":[],"mappings":";;;;;;AA4BO,IAAM,6BAAA,GAAsD;AAAA,EACjE,EAAA,EAAI,uCAAA;AAAA,EACJ,OAAA,EAAS;AACX;AA6DA,IAAM,qBAAA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MAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,YAAA,IAAgB,EAAC;AACvC,MAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,QAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,MAC3E;AACA,MAAA,OAAO,EAAE,SAAS,EAAE,QAAA,EAAU,CAAC,GAAG,KAAK,GAAE,EAAE;AAAA,IAC7C;AAAA;AAEJ;AAIA,IAAM,YAAA,GAAe,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AA0BrB,IAAM,eAAA,GAAkB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"chunk-PBAY7U4H.js","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { copyFile, mkdir, mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport {\n type CapabilityIdentifier,\n devcontainerImageUser,\n type EnvironmentPlan,\n listSandboxOutputFiles,\n materializeSandboxArtifactFiles,\n materializeTrustedBuildContext,\n type ProcessSpec,\n prepareSandboxOutputDirectory,\n resolvedDevcontainerEnv,\n type SandboxBackend,\n SandboxExecutionEnvironmentProvider,\n type SandboxInstance,\n SandboxWorkspaceEnvironment,\n validatedDevcontainerDockerfile,\n type WorkspaceSandboxBuild,\n} from \"@supertag/worker-sdk\";\nimport {\n ApiClient,\n CommandExitError,\n ConnectionConfig,\n Sandbox,\n type SandboxOpts,\n Template,\n} from \"e2b\";\nexport const E2B_REMOTE_SANDBOX_CAPABILITY: CapabilityIdentifier = {\n id: \"supertag.execution.remote-sandbox.e2b\",\n version: 1,\n};\ninterface E2BCommandResultLike {\n readonly exitCode: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\ninterface E2BCommandHandleLike {\n readonly pid: number;\n wait(): Promise<E2BCommandResultLike>;\n kill(): Promise<boolean>;\n sendStdin(data: string | Uint8Array): Promise<void>;\n closeStdin(): Promise<void>;\n}\n\ninterface E2BCommandOptionsLike {\n readonly background?: boolean;\n readonly cwd?: string;\n readonly envs?: Record<string, string>;\n readonly onStdout?: (data: string) => void | Promise<void>;\n readonly onStderr?: (data: string) => void | Promise<void>;\n readonly stdin?: boolean;\n readonly timeoutMs?: number;\n readonly signal?: AbortSignal;\n}\n\n/** Minimal E2B surface used by the provider and replaceable by tests. */\nexport interface E2BSandboxClient {\n readonly sandboxId: string;\n readonly files: {\n makeDir(path: string): Promise<boolean>;\n write(path: string, data: string | ArrayBuffer): Promise<unknown>;\n read(path: string, options?: { format: \"bytes\" }): Promise<string | Uint8Array>;\n };\n readonly commands: {\n run(\n command: string,\n options: E2BCommandOptionsLike & { readonly background: true },\n ): Promise<E2BCommandHandleLike>;\n run(command: string, options?: E2BCommandOptionsLike): Promise<E2BCommandResultLike>;\n };\n kill(): Promise<boolean>;\n}\n\nexport interface E2BSandboxFactory {\n create(options: SandboxOpts): Promise<E2BSandboxClient>;\n}\n\nexport interface E2BExecutionEnvironmentProviderOptions {\n /** E2B template or snapshot name. Defaults to E2B's `base` template. */\n readonly template?: string;\n /** Base directory created inside each sandbox. */\n readonly rootDirectory?: string;\n /** Sandbox lifetime enforced by E2B. */\n readonly sandboxTimeoutMs?: number;\n readonly requestTimeoutMs?: number;\n readonly maxOutputCharacters?: number;\n /** Test/custom-client seam. Authentication must still remain outside Worker Profiles. */\n readonly sandboxFactory?: E2BSandboxFactory;\n}\n\nconst defaultSandboxFactory: E2BSandboxFactory = {\n async create(options) {\n return await Sandbox.create(options);\n },\n};\nconst E2B_BACKEND: Pick<SandboxBackend, \"guarantees\" | \"capabilities\"> = {\n guarantees: {\n filesystemIsolation: \"sandbox\",\n networkPolicy: \"enforced\",\n processTreeTermination: true,\n scopedHttp: false,\n },\n capabilities: {\n networkModes: [\"none\", \"allowlist\", \"unrestricted\"],\n readOnlyMounts: true,\n boundedSymlinkSafeReads: true,\n outputFiles: true,\n streamOutput: true,\n streamInput: true,\n },\n};\n/** E2B adapter; portable preparation and lifecycle live in SandboxExecutionEnvironmentProvider. */\nexport class E2BExecutionEnvironmentProvider extends SandboxExecutionEnvironmentProvider {\n constructor(options: E2BExecutionEnvironmentProviderOptions = {}) {\n const backend: SandboxBackend = {\n ...E2B_BACKEND,\n async create(input) {\n const sandbox = await (options.sandboxFactory ?? defaultSandboxFactory).create({\n metadata: {\n \"supertag.taskId\": input.taskId,\n \"supertag.attemptId\": input.attemptId,\n \"supertag.tagId\": input.tagId,\n },\n ...networkOptions(input.network),\n ...(options.template === undefined ? {} : { template: options.template }),\n ...(options.sandboxTimeoutMs === undefined\n ? {}\n : { timeoutMs: options.sandboxTimeoutMs }),\n ...(options.requestTimeoutMs === undefined\n ? {}\n : { requestTimeoutMs: options.requestTimeoutMs }),\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n return adaptE2B(sandbox);\n },\n };\n super({\n id: \"e2b\",\n backend,\n capabilities: [E2B_REMOTE_SANDBOX_CAPABILITY],\n rootDirectory: options.rootDirectory ?? \"/home/user/supertag-tasks\",\n ...(options.maxOutputCharacters === undefined\n ? {}\n : { maxOutputCharacters: options.maxOutputCharacters }),\n });\n }\n}\n/** One E2B template build for a prepared Workspace. Everything in it is trusted. */\nexport interface E2BTemplateBuildSpec {\n /** New template name, unique to this host. */\n readonly name: string;\n /** The template to start from: the base, or an earlier prepared template for a warm build. */\n readonly from: string;\n readonly baseKind?: \"template\" | \"image\" | \"dockerfile\";\n readonly dockerfile?: string;\n readonly containerEnv?: Readonly<Record<string, string>>;\n readonly remoteEnv?: Readonly<Record<string, string>>;\n /** `remoteUser`, `containerUser`, or the Dockerfile's last `USER`; owns what prepare writes. */\n readonly user?: string;\n readonly workspaceFolder?: string;\n /** Harness install command from the Worker Profile; absent for a warm build. */\n readonly harnessInstall?: string;\n /** Installs Node.js, as root, for a stdio MCP server in the sandbox; absent for a warm build. */\n readonly mcpRuntimeInstall?: string;\n /** The stdio MCP server's trusted copy beside the checkout, created with it for `user`. */\n readonly mcpDirectory?: string;\n /** Private host build context with trusted blobs and a content bundle. */\n readonly contextDirectory: string;\n /** The content bundle's file name inside `contextDirectory`. */\n readonly contentFile: string;\n /** Where the build places the content bundle. */\n readonly contentDestination: string;\n /** The prepare script, run with `sh -c` after the bundle is in place. */\n readonly script: string;\n readonly signal?: AbortSignal;\n}\n\n/** The E2B template operations a Workspace environment needs; replaceable by tests. */\nexport interface E2BTemplateClient {\n /** Builds a template and returns its template ID. */\n build(spec: E2BTemplateBuildSpec): Promise<string>;\n /** Deletes a template; a template already gone succeeds. */\n delete(templateId: string): Promise<void>;\n}\n\nexport interface E2BWorkspaceEnvironmentOptions {\n /** Private host directory for bundles read back from sandboxes. */\n readonly stagingDirectory: string;\n /** Template every cold prepare starts from. Defaults to E2B's `base` template. */\n readonly template?: string;\n /** The checkout inside every template and Task sandbox. */\n readonly workspaceDirectory?: string;\n /** Directory for bundles in transit inside a sandbox. */\n readonly transferDirectory?: string;\n readonly sandboxTimeoutMs?: number;\n readonly requestTimeoutMs?: number;\n /** Test/custom-client seams. E2B credentials stay in E2B's own environment variables. */\n readonly templateClient?: E2BTemplateClient;\n readonly sandboxFactory?: E2BSandboxFactory;\n}\n\nexport const nativeTemplateClient: E2BTemplateClient = {\n async build(spec) {\n const builder = Template({ fileContextPath: spec.contextDirectory });\n let template =\n spec.baseKind === \"dockerfile\"\n ? builder.fromDockerfile(await stageE2BDockerfile(spec))\n : spec.baseKind === \"image\"\n ? builder.fromImage(spec.from)\n : builder.fromTemplate(spec.from);\n // Defense in depth: inspect the SDK's own parsed steps before it can hash/upload local files.\n if (spec.baseKind === \"dockerfile\") {\n const steps = (template as unknown as { instructions?: Array<{ type?: string }> })\n .instructions;\n if (!Array.isArray(steps))\n throw new Error(\"E2B devcontainer build.dockerfile could not be verified\");\n for (const step of steps)\n if (step.type === \"COPY\" || step.type === \"ADD\")\n throw new Error(`E2B devcontainer build.dockerfile cannot use ${step.type}`);\n }\n if (spec.mcpRuntimeInstall !== undefined)\n template = template.runCmd(spec.mcpRuntimeInstall, { user: \"root\" });\n if (spec.harnessInstall !== undefined) template = template.runCmd(spec.harnessInstall);\n if (spec.user) template = template.setUser(\"root\");\n const owned = [\n posix.dirname(spec.contentDestination),\n spec.workspaceFolder ?? \"/home/user/workspace\",\n ...(spec.mcpDirectory === undefined ? [] : [spec.mcpDirectory]),\n ]\n .map(shellQuote)\n .join(\" \");\n template = template.runCmd(`mkdir -p ${owned}`);\n if (spec.user) template = template.runCmd(`chown -R ${shellQuote(spec.user)} ${owned}`);\n template = template.copy(spec.contentFile, spec.contentDestination, {\n mode: 0o600,\n ...(spec.user ? { user: spec.user } : {}),\n });\n const env = { ...spec.containerEnv, ...spec.remoteEnv };\n if (Object.keys(env).length > 0) template = template.setEnvs(env);\n if (spec.workspaceFolder) template = template.setWorkdir(spec.workspaceFolder);\n if (spec.user) template = template.setUser(spec.user);\n template = template.runCmd(`sh -c ${shellQuote(spec.script)}`);\n return (await Template.build(template, spec.name)).templateId;\n },\n async delete(templateId) {\n const client = new ApiClient(new ConnectionConfig());\n const result = await client.api.DELETE(\"/templates/{templateID}\", {\n params: { path: { templateID: templateId } },\n });\n if (result.error !== undefined && result.response.status !== 404)\n throw new Error(\n `E2B template ${templateId} could not be deleted (${result.response.status})`,\n );\n },\n};\n\n/** Gives the SDK a path that can only name a file inside this build's private context. */\nexport async function stageE2BDockerfile(spec: E2BTemplateBuildSpec): Promise<string> {\n if (spec.dockerfile === undefined)\n throw new Error(\"E2B devcontainer build.dockerfile is missing\");\n const source = validatedDevcontainerDockerfile(spec.dockerfile, undefined);\n const path = join(spec.contextDirectory, `.supertag-${randomUUID()}.Dockerfile`);\n await writeFile(path, source, { flag: \"wx\", mode: 0o600 });\n return path;\n}\n\n/**\n * Named Workspaces on E2B. `prepare` builds a template from the base (or, warm, from an earlier\n * prepared template): Node.js for a stdio MCP server, harness install, the trusted commit's\n * bundle copied in, checkout, and\n * `setup`, all inside E2B's build. `start` creates the Task's sandbox from the template with the\n * Task's network policy. Task sandboxes are never turned into templates.\n */\nexport class E2BWorkspaceEnvironment extends SandboxWorkspaceEnvironment {\n constructor(options: E2BWorkspaceEnvironmentOptions) {\n const templates = options.templateClient ?? nativeTemplateClient;\n const sandboxes = options.sandboxFactory ?? defaultSandboxFactory;\n const base = options.template ?? \"base\";\n super({\n stagingDirectory: options.stagingDirectory,\n driver: {\n provider: \"e2b\",\n base,\n workspaceDirectory: options.workspaceDirectory ?? \"/home/user/workspace\",\n transferDirectory: options.transferDirectory ?? \"/home/user/.supertag-transfer\",\n backend: E2B_BACKEND,\n refuse(definition) {\n if (definition.devcontainer?.build && !definition.trustedRepository)\n return \"E2B devcontainer build.context needs the trusted repository\";\n try {\n resolvedDevcontainerEnv(\n definition.devcontainer,\n definition.devcontainer?.workspaceFolder ?? \"/home/user/workspace\",\n );\n if (definition.devcontainer?.build) {\n const build = definition.devcontainer.build;\n if (build.dockerfileContent === undefined)\n return \"E2B devcontainer build.dockerfile content is missing\";\n validatedDevcontainerDockerfile(build.dockerfileContent, build.args);\n devcontainerImageUser(definition.devcontainer);\n }\n } catch (error) {\n return error instanceof Error ? error.message : String(error);\n }\n return undefined;\n },\n async build(input: WorkspaceSandboxBuild) {\n input.signal?.throwIfAborted();\n // A private build context holding only the bundle, so nothing else on the host uploads.\n await mkdir(options.stagingDirectory, { recursive: true, mode: 0o700 });\n const context = await mkdtemp(join(options.stagingDirectory, \"e2b-context-\"));\n try {\n const devcontainer = input.devcontainer;\n if (devcontainer?.build) {\n if (!input.trustedRepository)\n throw new Error(\"E2B devcontainer build.context needs a trusted repository\");\n await materializeTrustedBuildContext({\n repository: input.trustedRepository,\n trustedCommit: input.trustedCommit,\n context: devcontainer.build.context ?? \".\",\n destination: context,\n });\n }\n const user = devcontainerImageUser(devcontainer);\n const contentFile = `.supertag-content-${input.name}.bundle`;\n await copyFile(input.content.bundle, join(context, contentFile));\n return await templates.build({\n name: input.name,\n from: input.from ?? devcontainer?.image ?? base,\n baseKind:\n input.from !== undefined\n ? \"template\"\n : devcontainer?.build\n ? \"dockerfile\"\n : devcontainer?.image\n ? \"image\"\n : \"template\",\n ...(devcontainer?.build?.dockerfileContent === undefined\n ? {}\n : {\n dockerfile: validatedDevcontainerDockerfile(\n devcontainer.build.dockerfileContent,\n devcontainer.build.args,\n ),\n }),\n ...(devcontainer === undefined\n ? {}\n : {\n containerEnv: resolvedDevcontainerEnv(devcontainer, input.workspaceDirectory),\n }),\n ...(user === undefined ? {} : { user }),\n workspaceFolder: input.workspaceDirectory,\n ...(input.mcpDirectory === undefined ? {} : { mcpDirectory: input.mcpDirectory }),\n ...(input.from === undefined && input.mcpRuntimeInstall !== undefined\n ? { mcpRuntimeInstall: input.mcpRuntimeInstall }\n : {}),\n ...(input.from === undefined &&\n input.harness.commands.length > 0 &&\n input.harness.install !== undefined\n ? { harnessInstall: input.harness.install }\n : {}),\n contextDirectory: context,\n contentFile,\n contentDestination: input.contentPath,\n script: input.script,\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n } finally {\n await rm(context, { recursive: true, force: true });\n }\n },\n async create(input) {\n const sandbox = await sandboxes.create({\n template: input.artifact,\n metadata: {\n \"supertag.taskId\": input.taskId,\n \"supertag.attemptId\": input.attemptId,\n },\n ...networkOptions(input.network),\n ...(options.sandboxTimeoutMs === undefined\n ? {}\n : { timeoutMs: options.sandboxTimeoutMs }),\n ...(options.requestTimeoutMs === undefined\n ? {}\n : { requestTimeoutMs: options.requestTimeoutMs }),\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n return adaptE2B(sandbox);\n },\n remove: (artifact) => templates.delete(artifact),\n },\n });\n }\n}\n\nfunction adaptE2B(sandbox: E2BSandboxClient): SandboxInstance {\n const instance: SandboxInstance = {\n id: sandbox.sandboxId,\n prepareOutputDirectory: (root, path) => prepareSandboxOutputDirectory(instance, root, path),\n listOutputFiles: (root, query) => listSandboxOutputFiles(instance, root, query),\n materializeArtifactFiles: (input) => materializeSandboxArtifactFiles(instance, input),\n async mkdir(path) {\n await sandbox.files.makeDir(path);\n },\n async write(path, bytes, options) {\n const handle = await sandbox.commands.run(`python3 -c ${shellQuote(EXCLUSIVE_WRITE)}`, {\n background: true,\n stdin: true,\n envs: {\n SUPERTAG_FILE_PATH: path,\n SUPERTAG_FILE_MODE: String(options.mode ?? 0o600),\n SUPERTAG_FILE_EXCLUSIVE: String(options.exclusive),\n },\n timeoutMs: 30000,\n });\n await handle.sendStdin(Buffer.from(bytes).toString(\"base64\"));\n await handle.closeStdin();\n try {\n const result = await handle.wait();\n if (result.exitCode !== 0) throw new Error(\"Staged file could not be written exclusively\");\n } catch {\n throw new Error(\"Staged file could not be written exclusively\");\n }\n },\n async read(path, options) {\n const result = await sandbox.commands.run(`python3 -c ${shellQuote(BOUNDED_READ)}`, {\n envs: { SUPERTAG_FILE_PATH: path, SUPERTAG_FILE_LIMIT: String(options.maximumBytes) },\n timeoutMs: 5000,\n });\n if (result.exitCode !== 0)\n throw new Error(\"Output must be a bounded regular file without symbolic links\");\n if (result.stdout.length > 4 * Math.ceil(options.maximumBytes / 3))\n throw new Error(\"Artifact transport exceeded bound\");\n const bytes = new Uint8Array(Buffer.from(result.stdout, \"base64\"));\n if (bytes.byteLength > options.maximumBytes)\n throw new Error(\"Expected bounded binary artifact\");\n return bytes;\n },\n async makeReadOnly(path) {\n const result = await sandbox.commands.run(`chmod -R a-w ${shellQuote(path)}`);\n if (result.exitCode !== 0) throw new Error(\"Failed to make E2B mount read-only\");\n },\n async start(spec, options) {\n const handle = await sandbox.commands.run(renderCommand(spec), {\n background: true,\n ...(spec.cwd ? { cwd: spec.cwd } : {}),\n ...(spec.environment === undefined ? {} : { envs: { ...spec.environment } }),\n ...(spec.stdin === undefined && !spec.streamInput ? {} : { stdin: true }),\n ...(spec.timeoutMs === undefined ? {} : { timeoutMs: spec.timeoutMs }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n // The E2B SDK awaits these callbacks before reading the next event, so returning the\n // consumer's promise stops reading this command's output stream until it drains.\n onStdout: (text) => options.onOutput({ stream: \"stdout\", text }),\n onStderr: (text) => options.onOutput({ stream: \"stderr\", text }),\n });\n if (spec.stdin !== undefined) {\n await handle.sendStdin(spec.stdin);\n await handle.closeStdin();\n }\n return {\n pid: handle.pid,\n terminate: () => handle.kill(),\n ...(spec.streamInput\n ? {\n write: (bytes: Uint8Array) => handle.sendStdin(bytes),\n endInput: () => handle.closeStdin(),\n }\n : {}),\n async wait() {\n try {\n return await handle.wait();\n } catch (error) {\n if (error instanceof CommandExitError)\n return { exitCode: error.exitCode, stdout: error.stdout, stderr: error.stderr };\n throw error;\n }\n },\n };\n },\n terminate: () => sandbox.kill(),\n };\n return instance;\n}\nfunction renderCommand(spec: ProcessSpec): string {\n return [spec.command, ...(spec.args ?? [])].map(shellQuote).join(\" \");\n}\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\nfunction networkOptions(\n network: EnvironmentPlan[\"network\"],\n): Pick<SandboxOpts, \"allowInternetAccess\" | \"network\"> {\n switch (network.mode) {\n case \"none\":\n return { allowInternetAccess: false };\n case \"unrestricted\":\n return { allowInternetAccess: true };\n case \"allowlist\": {\n const hosts = network.allowedHosts ?? [];\n if (hosts.length === 0) {\n throw new Error(\"An E2B network allowlist must contain at least one host\");\n }\n return { network: { allowOut: [...hosts] } };\n }\n }\n}\n\n// Walk directory descriptors rather than checking paths before a separate read.\n// O_NONBLOCK prevents an attacker substituting a FIFO before the regular-file check.\nconst BOUNDED_READ = `import os, stat, base64\nparts = os.environ[\"SUPERTAG_FILE_PATH\"].split(\"/\")\nlimit = int(os.environ[\"SUPERTAG_FILE_LIMIT\"])\nfd = os.open(\"/\", os.O_RDONLY | os.O_DIRECTORY)\ntry:\n for part in [p for p in parts if p]:\n if part in (\".\", \"..\"): raise ValueError(\"invalid path\")\n flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK\n next_fd = os.open(part, flags, dir_fd=fd)\n os.close(fd)\n fd = next_fd\n if not stat.S_ISREG(os.fstat(fd).st_mode): raise ValueError(\"not regular\")\n chunks = []\n remaining = limit + 1\n while remaining:\n chunk = os.read(fd, min(65536, remaining))\n if not chunk: break\n chunks.append(chunk)\n remaining -= len(chunk)\n data = b\"\".join(chunks)\n if len(data) > limit: raise ValueError(\"too large\")\n print(base64.b64encode(data).decode(\"ascii\"), end=\"\")\nfinally:\n os.close(fd)\n`;\n\nconst EXCLUSIVE_WRITE = `import os, sys, base64\nparts = [p for p in os.environ[\"SUPERTAG_FILE_PATH\"].split(\"/\") if p]\nif not parts or any(p in (\".\", \"..\") for p in parts): raise ValueError(\"invalid path\")\nfd = os.open(\"/\", os.O_RDONLY | os.O_DIRECTORY)\ntry:\n for part in parts[:-1]:\n next_fd = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=fd)\n os.close(fd)\n fd = next_fd\n flags = os.O_WRONLY | os.O_CREAT | os.O_NOFOLLOW\n flags |= os.O_EXCL if os.environ[\"SUPERTAG_FILE_EXCLUSIVE\"] == \"true\" else os.O_TRUNC\n out = os.open(parts[-1], flags, int(os.environ[\"SUPERTAG_FILE_MODE\"]), dir_fd=fd)\n with os.fdopen(out, \"wb\") as target:\n target.write(base64.b64decode(sys.stdin.buffer.read(), validate=True))\nfinally:\n os.close(fd)\n`;\n"]}
1
+ {"version":3,"sources":["../../runtime/environments/e2b/src/index.ts"],"names":[],"mappings":";;;;;;AA4BO,IAAM,6BAAA,GAAsD;AAAA,EACjE,EAAA,EAAI,uCAAA;AAAA,EACJ,OAAA,EAAS;AACX;AA6DA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,MAAM,OAAO,OAAA,EAAS;AACpB,IAAA,OAAO,MAAM,OAAA,CAAQ,MAAA,CA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W,CAAA,EAAG;AACtB,QAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,MAC3E;AACA,MAAA,OAAO,EAAE,SAAS,EAAE,QAAA,EAAU,CAAC,GAAG,KAAK,GAAE,EAAE;AAAA,IAC7C;AAAA;AAEJ;AAIA,IAAM,YAAA,GAAe,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AA0BrB,IAAM,eAAA,GAAkB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"chunk-5EEBCIHE.js","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { copyFile, mkdir, mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport {\n type CapabilityIdentifier,\n devcontainerImageUser,\n type EnvironmentPlan,\n listSandboxOutputFiles,\n materializeSandboxArtifactFiles,\n materializeTrustedBuildContext,\n type ProcessSpec,\n prepareSandboxOutputDirectory,\n resolvedDevcontainerEnv,\n type SandboxBackend,\n SandboxExecutionEnvironmentProvider,\n type SandboxInstance,\n SandboxWorkspaceEnvironment,\n validatedDevcontainerDockerfile,\n type WorkspaceSandboxBuild,\n} from \"@supertag/worker-sdk\";\nimport {\n ApiClient,\n CommandExitError,\n ConnectionConfig,\n Sandbox,\n type SandboxOpts,\n Template,\n} from \"e2b\";\nexport const E2B_REMOTE_SANDBOX_CAPABILITY: CapabilityIdentifier = {\n id: \"supertag.execution.remote-sandbox.e2b\",\n version: 1,\n};\ninterface E2BCommandResultLike {\n readonly exitCode: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\ninterface E2BCommandHandleLike {\n readonly pid: number;\n wait(): Promise<E2BCommandResultLike>;\n kill(): Promise<boolean>;\n sendStdin(data: string | Uint8Array): Promise<void>;\n closeStdin(): Promise<void>;\n}\n\ninterface E2BCommandOptionsLike {\n readonly background?: boolean;\n readonly cwd?: string;\n readonly envs?: Record<string, string>;\n readonly onStdout?: (data: string) => void | Promise<void>;\n readonly onStderr?: (data: string) => void | Promise<void>;\n readonly stdin?: boolean;\n readonly timeoutMs?: number;\n readonly signal?: AbortSignal;\n}\n\n/** Minimal E2B surface used by the provider and replaceable by tests. */\nexport interface E2BSandboxClient {\n readonly sandboxId: string;\n readonly files: {\n makeDir(path: string): Promise<boolean>;\n write(path: string, data: string | ArrayBuffer): Promise<unknown>;\n read(path: string, options?: { format: \"bytes\" }): Promise<string | Uint8Array>;\n };\n readonly commands: {\n run(\n command: string,\n options: E2BCommandOptionsLike & { readonly background: true },\n ): Promise<E2BCommandHandleLike>;\n run(command: string, options?: E2BCommandOptionsLike): Promise<E2BCommandResultLike>;\n };\n kill(): Promise<boolean>;\n}\n\nexport interface E2BSandboxFactory {\n create(options: SandboxOpts): Promise<E2BSandboxClient>;\n}\n\nexport interface E2BExecutionEnvironmentProviderOptions {\n /** E2B template or snapshot name. Defaults to E2B's `base` template. */\n readonly template?: string;\n /** Base directory created inside each sandbox. */\n readonly rootDirectory?: string;\n /** Sandbox lifetime enforced by E2B. */\n readonly sandboxTimeoutMs?: number;\n readonly requestTimeoutMs?: number;\n readonly maxOutputCharacters?: number;\n /** Test/custom-client seam. Authentication must still remain outside Worker Profiles. */\n readonly sandboxFactory?: E2BSandboxFactory;\n}\n\nconst defaultSandboxFactory: E2BSandboxFactory = {\n async create(options) {\n return await Sandbox.create(options);\n },\n};\nconst E2B_BACKEND: Pick<SandboxBackend, \"guarantees\" | \"capabilities\"> = {\n guarantees: {\n filesystemIsolation: \"sandbox\",\n networkPolicy: \"enforced\",\n processTreeTermination: true,\n scopedHttp: false,\n },\n capabilities: {\n networkModes: [\"none\", \"allowlist\", \"unrestricted\"],\n readOnlyMounts: true,\n boundedSymlinkSafeReads: true,\n outputFiles: true,\n streamOutput: true,\n streamInput: true,\n },\n};\n/** E2B adapter; portable preparation and lifecycle live in SandboxExecutionEnvironmentProvider. */\nexport class E2BExecutionEnvironmentProvider extends SandboxExecutionEnvironmentProvider {\n constructor(options: E2BExecutionEnvironmentProviderOptions = {}) {\n const backend: SandboxBackend = {\n ...E2B_BACKEND,\n async create(input) {\n const sandbox = await (options.sandboxFactory ?? defaultSandboxFactory).create({\n metadata: {\n \"supertag.taskId\": input.taskId,\n \"supertag.attemptId\": input.attemptId,\n \"supertag.tagId\": input.tagId,\n },\n ...networkOptions(input.network),\n ...(options.template === undefined ? {} : { template: options.template }),\n ...(options.sandboxTimeoutMs === undefined\n ? {}\n : { timeoutMs: options.sandboxTimeoutMs }),\n ...(options.requestTimeoutMs === undefined\n ? {}\n : { requestTimeoutMs: options.requestTimeoutMs }),\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n return adaptE2B(sandbox);\n },\n };\n super({\n id: \"e2b\",\n backend,\n capabilities: [E2B_REMOTE_SANDBOX_CAPABILITY],\n rootDirectory: options.rootDirectory ?? \"/home/user/supertag-tasks\",\n ...(options.maxOutputCharacters === undefined\n ? {}\n : { maxOutputCharacters: options.maxOutputCharacters }),\n });\n }\n}\n/** One E2B template build for a prepared Workspace. Everything in it is trusted. */\nexport interface E2BTemplateBuildSpec {\n /** New template name, unique to this host. */\n readonly name: string;\n /** The template to start from: the base, or an earlier prepared template for a warm build. */\n readonly from: string;\n readonly baseKind?: \"template\" | \"image\" | \"dockerfile\";\n readonly dockerfile?: string;\n readonly containerEnv?: Readonly<Record<string, string>>;\n readonly remoteEnv?: Readonly<Record<string, string>>;\n /** `remoteUser`, `containerUser`, or the Dockerfile's last `USER`; owns what prepare writes. */\n readonly user?: string;\n readonly workspaceFolder?: string;\n /** Harness install command from the Worker Profile; absent for a warm build. */\n readonly harnessInstall?: string;\n /** Installs Node.js, as root, for a stdio MCP server in the sandbox; absent for a warm build. */\n readonly mcpRuntimeInstall?: string;\n /** The stdio MCP server's trusted copy beside the checkout, created with it for `user`. */\n readonly mcpDirectory?: string;\n /** Private host build context with trusted blobs and a content bundle. */\n readonly contextDirectory: string;\n /** The content bundle's file name inside `contextDirectory`. */\n readonly contentFile: string;\n /** Where the build places the content bundle. */\n readonly contentDestination: string;\n /** The prepare script, run with `sh -c` after the bundle is in place. */\n readonly script: string;\n readonly signal?: AbortSignal;\n}\n\n/** The E2B template operations a Workspace environment needs; replaceable by tests. */\nexport interface E2BTemplateClient {\n /** Builds a template and returns its template ID. */\n build(spec: E2BTemplateBuildSpec): Promise<string>;\n /** Deletes a template; a template already gone succeeds. */\n delete(templateId: string): Promise<void>;\n}\n\nexport interface E2BWorkspaceEnvironmentOptions {\n /** Private host directory for bundles read back from sandboxes. */\n readonly stagingDirectory: string;\n /** Template every cold prepare starts from. Defaults to E2B's `base` template. */\n readonly template?: string;\n /** The checkout inside every template and Task sandbox. */\n readonly workspaceDirectory?: string;\n /** Directory for bundles in transit inside a sandbox. */\n readonly transferDirectory?: string;\n readonly sandboxTimeoutMs?: number;\n readonly requestTimeoutMs?: number;\n /** Test/custom-client seams. E2B credentials stay in E2B's own environment variables. */\n readonly templateClient?: E2BTemplateClient;\n readonly sandboxFactory?: E2BSandboxFactory;\n}\n\nexport const nativeTemplateClient: E2BTemplateClient = {\n async build(spec) {\n const builder = Template({ fileContextPath: spec.contextDirectory });\n let template =\n spec.baseKind === \"dockerfile\"\n ? builder.fromDockerfile(await stageE2BDockerfile(spec))\n : spec.baseKind === \"image\"\n ? builder.fromImage(spec.from)\n : builder.fromTemplate(spec.from);\n // Defense in depth: inspect the SDK's own parsed steps before it can hash/upload local files.\n if (spec.baseKind === \"dockerfile\") {\n const steps = (template as unknown as { instructions?: Array<{ type?: string }> })\n .instructions;\n if (!Array.isArray(steps))\n throw new Error(\"E2B devcontainer build.dockerfile could not be verified\");\n for (const step of steps)\n if (step.type === \"COPY\" || step.type === \"ADD\")\n throw new Error(`E2B devcontainer build.dockerfile cannot use ${step.type}`);\n }\n if (spec.mcpRuntimeInstall !== undefined)\n template = template.runCmd(spec.mcpRuntimeInstall, { user: \"root\" });\n if (spec.harnessInstall !== undefined) template = template.runCmd(spec.harnessInstall);\n if (spec.user) template = template.setUser(\"root\");\n const owned = [\n posix.dirname(spec.contentDestination),\n spec.workspaceFolder ?? \"/home/user/workspace\",\n ...(spec.mcpDirectory === undefined ? [] : [spec.mcpDirectory]),\n ]\n .map(shellQuote)\n .join(\" \");\n template = template.runCmd(`mkdir -p ${owned}`);\n if (spec.user) template = template.runCmd(`chown -R ${shellQuote(spec.user)} ${owned}`);\n template = template.copy(spec.contentFile, spec.contentDestination, {\n mode: 0o600,\n ...(spec.user ? { user: spec.user } : {}),\n });\n const env = { ...spec.containerEnv, ...spec.remoteEnv };\n if (Object.keys(env).length > 0) template = template.setEnvs(env);\n if (spec.workspaceFolder) template = template.setWorkdir(spec.workspaceFolder);\n if (spec.user) template = template.setUser(spec.user);\n template = template.runCmd(`sh -c ${shellQuote(spec.script)}`);\n return (await Template.build(template, spec.name)).templateId;\n },\n async delete(templateId) {\n const client = new ApiClient(new ConnectionConfig());\n const result = await client.api.DELETE(\"/templates/{templateID}\", {\n params: { path: { templateID: templateId } },\n });\n if (result.error !== undefined && result.response.status !== 404)\n throw new Error(\n `E2B template ${templateId} could not be deleted (${result.response.status})`,\n );\n },\n};\n\n/** Gives the SDK a path that can only name a file inside this build's private context. */\nexport async function stageE2BDockerfile(spec: E2BTemplateBuildSpec): Promise<string> {\n if (spec.dockerfile === undefined)\n throw new Error(\"E2B devcontainer build.dockerfile is missing\");\n const source = validatedDevcontainerDockerfile(spec.dockerfile, undefined);\n const path = join(spec.contextDirectory, `.supertag-${randomUUID()}.Dockerfile`);\n await writeFile(path, source, { flag: \"wx\", mode: 0o600 });\n return path;\n}\n\n/**\n * Named Workspaces on E2B. `prepare` builds a template from the base (or, warm, from an earlier\n * prepared template): Node.js for a stdio MCP server, harness install, the trusted commit's\n * bundle copied in, checkout, and\n * `setup`, all inside E2B's build. `start` creates the Task's sandbox from the template with the\n * Task's network policy. Task sandboxes are never turned into templates.\n */\nexport class E2BWorkspaceEnvironment extends SandboxWorkspaceEnvironment {\n constructor(options: E2BWorkspaceEnvironmentOptions) {\n const templates = options.templateClient ?? nativeTemplateClient;\n const sandboxes = options.sandboxFactory ?? defaultSandboxFactory;\n const base = options.template ?? \"base\";\n super({\n stagingDirectory: options.stagingDirectory,\n driver: {\n provider: \"e2b\",\n base,\n workspaceDirectory: options.workspaceDirectory ?? \"/home/user/workspace\",\n transferDirectory: options.transferDirectory ?? \"/home/user/.supertag-transfer\",\n backend: E2B_BACKEND,\n refuse(definition) {\n if (definition.devcontainer?.build && !definition.trustedRepository)\n return \"E2B devcontainer build.context needs the trusted repository\";\n try {\n resolvedDevcontainerEnv(\n definition.devcontainer,\n definition.devcontainer?.workspaceFolder ?? \"/home/user/workspace\",\n );\n if (definition.devcontainer?.build) {\n const build = definition.devcontainer.build;\n if (build.dockerfileContent === undefined)\n return \"E2B devcontainer build.dockerfile content is missing\";\n validatedDevcontainerDockerfile(build.dockerfileContent, build.args);\n devcontainerImageUser(definition.devcontainer);\n }\n } catch (error) {\n return error instanceof Error ? error.message : String(error);\n }\n return undefined;\n },\n async build(input: WorkspaceSandboxBuild) {\n input.signal?.throwIfAborted();\n // A private build context holding only the bundle, so nothing else on the host uploads.\n await mkdir(options.stagingDirectory, { recursive: true, mode: 0o700 });\n const context = await mkdtemp(join(options.stagingDirectory, \"e2b-context-\"));\n try {\n const devcontainer = input.devcontainer;\n if (devcontainer?.build) {\n if (!input.trustedRepository)\n throw new Error(\"E2B devcontainer build.context needs a trusted repository\");\n await materializeTrustedBuildContext({\n repository: input.trustedRepository,\n trustedCommit: input.trustedCommit,\n context: devcontainer.build.context ?? \".\",\n destination: context,\n });\n }\n const user = devcontainerImageUser(devcontainer);\n const contentFile = `.supertag-content-${input.name}.bundle`;\n await copyFile(input.content.bundle, join(context, contentFile));\n return await templates.build({\n name: input.name,\n from: input.from ?? devcontainer?.image ?? base,\n baseKind:\n input.from !== undefined\n ? \"template\"\n : devcontainer?.build\n ? \"dockerfile\"\n : devcontainer?.image\n ? \"image\"\n : \"template\",\n ...(devcontainer?.build?.dockerfileContent === undefined\n ? {}\n : {\n dockerfile: validatedDevcontainerDockerfile(\n devcontainer.build.dockerfileContent,\n devcontainer.build.args,\n ),\n }),\n ...(devcontainer === undefined\n ? {}\n : {\n containerEnv: resolvedDevcontainerEnv(devcontainer, input.workspaceDirectory),\n }),\n ...(user === undefined ? {} : { user }),\n workspaceFolder: input.workspaceDirectory,\n ...(input.mcpDirectory === undefined ? {} : { mcpDirectory: input.mcpDirectory }),\n ...(input.from === undefined && input.mcpRuntimeInstall !== undefined\n ? { mcpRuntimeInstall: input.mcpRuntimeInstall }\n : {}),\n ...(input.from === undefined &&\n input.harness.commands.length > 0 &&\n input.harness.install !== undefined\n ? { harnessInstall: input.harness.install }\n : {}),\n contextDirectory: context,\n contentFile,\n contentDestination: input.contentPath,\n script: input.script,\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n } finally {\n await rm(context, { recursive: true, force: true });\n }\n },\n async create(input) {\n const sandbox = await sandboxes.create({\n template: input.artifact,\n metadata: {\n \"supertag.taskId\": input.taskId,\n \"supertag.attemptId\": input.attemptId,\n },\n ...networkOptions(input.network),\n ...(options.sandboxTimeoutMs === undefined\n ? {}\n : { timeoutMs: options.sandboxTimeoutMs }),\n ...(options.requestTimeoutMs === undefined\n ? {}\n : { requestTimeoutMs: options.requestTimeoutMs }),\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n return adaptE2B(sandbox);\n },\n remove: (artifact) => templates.delete(artifact),\n },\n });\n }\n}\n\nfunction adaptE2B(sandbox: E2BSandboxClient): SandboxInstance {\n const instance: SandboxInstance = {\n id: sandbox.sandboxId,\n prepareOutputDirectory: (root, path) => prepareSandboxOutputDirectory(instance, root, path),\n listOutputFiles: (root, query) => listSandboxOutputFiles(instance, root, query),\n materializeArtifactFiles: (input) => materializeSandboxArtifactFiles(instance, input),\n async mkdir(path) {\n await sandbox.files.makeDir(path);\n },\n async write(path, bytes, options) {\n const handle = await sandbox.commands.run(`python3 -c ${shellQuote(EXCLUSIVE_WRITE)}`, {\n background: true,\n stdin: true,\n envs: {\n SUPERTAG_FILE_PATH: path,\n SUPERTAG_FILE_MODE: String(options.mode ?? 0o600),\n SUPERTAG_FILE_EXCLUSIVE: String(options.exclusive),\n },\n timeoutMs: 30000,\n });\n await handle.sendStdin(Buffer.from(bytes).toString(\"base64\"));\n await handle.closeStdin();\n try {\n const result = await handle.wait();\n if (result.exitCode !== 0) throw new Error(\"Staged file could not be written exclusively\");\n } catch {\n throw new Error(\"Staged file could not be written exclusively\");\n }\n },\n async read(path, options) {\n const result = await sandbox.commands.run(`python3 -c ${shellQuote(BOUNDED_READ)}`, {\n envs: { SUPERTAG_FILE_PATH: path, SUPERTAG_FILE_LIMIT: String(options.maximumBytes) },\n timeoutMs: 5000,\n });\n if (result.exitCode !== 0)\n throw new Error(\"Output must be a bounded regular file without symbolic links\");\n if (result.stdout.length > 4 * Math.ceil(options.maximumBytes / 3))\n throw new Error(\"Artifact transport exceeded bound\");\n const bytes = new Uint8Array(Buffer.from(result.stdout, \"base64\"));\n if (bytes.byteLength > options.maximumBytes)\n throw new Error(\"Expected bounded binary artifact\");\n return bytes;\n },\n async makeReadOnly(path) {\n const result = await sandbox.commands.run(`chmod -R a-w ${shellQuote(path)}`);\n if (result.exitCode !== 0) throw new Error(\"Failed to make E2B mount read-only\");\n },\n async start(spec, options) {\n const handle = await sandbox.commands.run(renderCommand(spec), {\n background: true,\n ...(spec.cwd ? { cwd: spec.cwd } : {}),\n ...(spec.environment === undefined ? {} : { envs: { ...spec.environment } }),\n ...(spec.stdin === undefined && !spec.streamInput ? {} : { stdin: true }),\n ...(spec.timeoutMs === undefined ? {} : { timeoutMs: spec.timeoutMs }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n // The E2B SDK awaits these callbacks before reading the next event, so returning the\n // consumer's promise stops reading this command's output stream until it drains.\n onStdout: (text) => options.onOutput({ stream: \"stdout\", text }),\n onStderr: (text) => options.onOutput({ stream: \"stderr\", text }),\n });\n if (spec.stdin !== undefined) {\n await handle.sendStdin(spec.stdin);\n await handle.closeStdin();\n }\n return {\n pid: handle.pid,\n terminate: () => handle.kill(),\n ...(spec.streamInput\n ? {\n write: (bytes: Uint8Array) => handle.sendStdin(bytes),\n endInput: () => handle.closeStdin(),\n }\n : {}),\n async wait() {\n try {\n return await handle.wait();\n } catch (error) {\n if (error instanceof CommandExitError)\n return { exitCode: error.exitCode, stdout: error.stdout, stderr: error.stderr };\n throw error;\n }\n },\n };\n },\n terminate: () => sandbox.kill(),\n };\n return instance;\n}\nfunction renderCommand(spec: ProcessSpec): string {\n return [spec.command, ...(spec.args ?? [])].map(shellQuote).join(\" \");\n}\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\nfunction networkOptions(\n network: EnvironmentPlan[\"network\"],\n): Pick<SandboxOpts, \"allowInternetAccess\" | \"network\"> {\n switch (network.mode) {\n case \"none\":\n return { allowInternetAccess: false };\n case \"unrestricted\":\n return { allowInternetAccess: true };\n case \"allowlist\": {\n const hosts = network.allowedHosts ?? [];\n if (hosts.length === 0) {\n throw new Error(\"An E2B network allowlist must contain at least one host\");\n }\n return { network: { allowOut: [...hosts] } };\n }\n }\n}\n\n// Walk directory descriptors rather than checking paths before a separate read.\n// O_NONBLOCK prevents an attacker substituting a FIFO before the regular-file check.\nconst BOUNDED_READ = `import os, stat, base64\nparts = os.environ[\"SUPERTAG_FILE_PATH\"].split(\"/\")\nlimit = int(os.environ[\"SUPERTAG_FILE_LIMIT\"])\nfd = os.open(\"/\", os.O_RDONLY | os.O_DIRECTORY)\ntry:\n for part in [p for p in parts if p]:\n if part in (\".\", \"..\"): raise ValueError(\"invalid path\")\n flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK\n next_fd = os.open(part, flags, dir_fd=fd)\n os.close(fd)\n fd = next_fd\n if not stat.S_ISREG(os.fstat(fd).st_mode): raise ValueError(\"not regular\")\n chunks = []\n remaining = limit + 1\n while remaining:\n chunk = os.read(fd, min(65536, remaining))\n if not chunk: break\n chunks.append(chunk)\n remaining -= len(chunk)\n data = b\"\".join(chunks)\n if len(data) > limit: raise ValueError(\"too large\")\n print(base64.b64encode(data).decode(\"ascii\"), end=\"\")\nfinally:\n os.close(fd)\n`;\n\nconst EXCLUSIVE_WRITE = `import os, sys, base64\nparts = [p for p in os.environ[\"SUPERTAG_FILE_PATH\"].split(\"/\") if p]\nif not parts or any(p in (\".\", \"..\") for p in parts): raise ValueError(\"invalid path\")\nfd = os.open(\"/\", os.O_RDONLY | os.O_DIRECTORY)\ntry:\n for part in parts[:-1]:\n next_fd = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=fd)\n os.close(fd)\n fd = next_fd\n flags = os.O_WRONLY | os.O_CREAT | os.O_NOFOLLOW\n flags |= os.O_EXCL if os.environ[\"SUPERTAG_FILE_EXCLUSIVE\"] == \"true\" else os.O_TRUNC\n out = os.open(parts[-1], flags, int(os.environ[\"SUPERTAG_FILE_MODE\"]), dir_fd=fd)\n with os.fdopen(out, \"wb\") as target:\n target.write(base64.b64decode(sys.stdin.buffer.read(), validate=True))\nfinally:\n os.close(fd)\n`;\n"]}