openpond 0.0.30-bootstrap.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 (193) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/LICENSE +21 -0
  3. package/README.md +162 -0
  4. package/RELEASE.md +20 -0
  5. package/dist/api/core.d.ts +22 -0
  6. package/dist/api/deployments.d.ts +30 -0
  7. package/dist/api/types.d.ts +624 -0
  8. package/dist/api.d.ts +90 -0
  9. package/dist/cache.d.ts +22 -0
  10. package/dist/chunks/app-layer-YKXEQGOW.js +163 -0
  11. package/dist/chunks/apps-GGSIN2ZF.js +539 -0
  12. package/dist/chunks/chunk-3CC6MH35.js +1663 -0
  13. package/dist/chunks/chunk-3Y4EL3P6.js +1090 -0
  14. package/dist/chunks/chunk-4HYJG2JE.js +3875 -0
  15. package/dist/chunks/chunk-5G4E547X.js +294 -0
  16. package/dist/chunks/chunk-74O6FGVN.js +598 -0
  17. package/dist/chunks/chunk-AUJLPKGI.js +632 -0
  18. package/dist/chunks/chunk-BYAPLT37.js +744 -0
  19. package/dist/chunks/chunk-FUP7EGT7.js +1845 -0
  20. package/dist/chunks/chunk-I6HN3ZGW.js +88 -0
  21. package/dist/chunks/chunk-KRKGHVMQ.js +294 -0
  22. package/dist/chunks/chunk-LHYK6QO2.js +1300 -0
  23. package/dist/chunks/chunk-NLBKZZEK.js +224 -0
  24. package/dist/chunks/chunk-OG75GMVO.js +1 -0
  25. package/dist/chunks/chunk-Q57SVPEH.js +11663 -0
  26. package/dist/chunks/chunk-UACZUFIA.js +47 -0
  27. package/dist/chunks/chunk-VQX33YAG.js +5135 -0
  28. package/dist/chunks/chunk-W5GKHH77.js +168 -0
  29. package/dist/chunks/chunk-WYDVQOBL.js +17581 -0
  30. package/dist/chunks/chunk-XSAXENQD.js +4167 -0
  31. package/dist/chunks/chunk-Y6G6WRTG.js +210 -0
  32. package/dist/chunks/cli-NVKNE4AZ.js +11 -0
  33. package/dist/chunks/cli-X3HPLSOV.js +19 -0
  34. package/dist/chunks/core-commands-IM2UKLU4.js +41 -0
  35. package/dist/chunks/extend-YXCBULPO.js +84 -0
  36. package/dist/chunks/harness-GMK6IY2U.js +140 -0
  37. package/dist/chunks/help-LMH5FGT2.js +65 -0
  38. package/dist/chunks/opchat-BWXZ32GX.js +169 -0
  39. package/dist/chunks/organizations-4ISQRGMQ.js +738 -0
  40. package/dist/chunks/profile-NLDZDT3L.js +1110 -0
  41. package/dist/chunks/project-agent-ZPVO25HA.js +892 -0
  42. package/dist/chunks/sandbox-command-5GFJ2U3V.js +1652 -0
  43. package/dist/chunks/sandbox-template-LZN4F55Z.js +1646 -0
  44. package/dist/chunks/src-3RBI4DNN.js +3595 -0
  45. package/dist/chunks/src-EYXQS6XD.js +73427 -0
  46. package/dist/chunks/teams-bot-WP3FHKGA.js +137 -0
  47. package/dist/cli.js +77 -0
  48. package/dist/client-types.d.ts +222 -0
  49. package/dist/client.d.ts +19 -0
  50. package/dist/config.d.ts +184 -0
  51. package/dist/hosted-chat.d.ts +162 -0
  52. package/dist/index.d.ts +5 -0
  53. package/dist/index.js +25481 -0
  54. package/dist/indicators.d.ts +38 -0
  55. package/dist/opchat-smoke.d.ts +47 -0
  56. package/dist/private-json-file.d.ts +3 -0
  57. package/dist/profile/local-profile-types.d.ts +160 -0
  58. package/dist/profile/local-profile.d.ts +69 -0
  59. package/dist/profile/profile-catalog.d.ts +14 -0
  60. package/dist/profile/profile-git.d.ts +17 -0
  61. package/dist/profile/profile-promotion.d.ts +21 -0
  62. package/dist/profile/profile-setup-gate.d.ts +22 -0
  63. package/dist/profile/profile-skills.d.ts +30 -0
  64. package/dist/profile/profile-source-upload.d.ts +29 -0
  65. package/dist/profile/source-upload-cache.d.ts +29 -0
  66. package/dist/sandbox/async-request-options.d.ts +2 -0
  67. package/dist/sandbox/client-handles.d.ts +113 -0
  68. package/dist/sandbox/client.d.ts +348 -0
  69. package/dist/sandbox/runtime-handle.d.ts +36 -0
  70. package/dist/sandbox/sandbox-instance-client.d.ts +72 -0
  71. package/dist/sandbox/smoke.d.ts +3 -0
  72. package/dist/sandbox/stream.d.ts +7 -0
  73. package/dist/sandbox/types/billing.d.ts +176 -0
  74. package/dist/sandbox/types/client.d.ts +103 -0
  75. package/dist/sandbox/types/core.d.ts +140 -0
  76. package/dist/sandbox/types/index.d.ts +14 -0
  77. package/dist/sandbox/types/io.d.ts +240 -0
  78. package/dist/sandbox/types/microsoft-teams-bot.d.ts +51 -0
  79. package/dist/sandbox/types/org-project-agent.d.ts +610 -0
  80. package/dist/sandbox/types/record.d.ts +53 -0
  81. package/dist/sandbox/types/responses.d.ts +295 -0
  82. package/dist/sandbox/types/runtime-profiles.d.ts +15 -0
  83. package/dist/sandbox/types/runtime.d.ts +152 -0
  84. package/dist/sandbox/types/schedules.d.ts +141 -0
  85. package/dist/sandbox/types/snapshots.d.ts +205 -0
  86. package/dist/sandbox/types/workflow-modes.d.ts +1 -0
  87. package/dist/sandbox/types/workload-sources.d.ts +20 -0
  88. package/dist/sandbox/url.d.ts +2 -0
  89. package/dist/sandbox-template/manifest.d.ts +304 -0
  90. package/dist/sandbox-template/manifest.js +18381 -0
  91. package/dist/skills/openpond-cli/SKILL.md +49 -0
  92. package/dist/skills/openpond-desktop-harness/SKILL.md +113 -0
  93. package/dist/skills/openpond-desktop-harness/agents/openai.yaml +4 -0
  94. package/dist/skills/openpond-taskset-authoring/SKILL.md +38 -0
  95. package/dist/skills/openpond-taskset-authoring/references/graders-and-rewards.md +11 -0
  96. package/dist/skills/openpond-taskset-authoring/references/method-selection.md +12 -0
  97. package/dist/skills/openpond-taskset-authoring/references/privacy-and-provenance.md +8 -0
  98. package/dist/skills/openpond-taskset-authoring/references/task-design.md +13 -0
  99. package/dist/stream.d.ts +20 -0
  100. package/dist/types.d.ts +57 -0
  101. package/dist/urls.d.ts +4 -0
  102. package/dist/web/assets/AppsView-Bu-Nc3Ew.js +1 -0
  103. package/dist/web/assets/AppsView-DIhprTIC.css +1 -0
  104. package/dist/web/assets/BrowserSidebar-CCguQ-DR.js +1 -0
  105. package/dist/web/assets/BrowserSidebar-D9i7gQzw.css +1 -0
  106. package/dist/web/assets/CloudWorkView-DNoPIlMj.css +1 -0
  107. package/dist/web/assets/CloudWorkView-Dr3xqLE5.js +1 -0
  108. package/dist/web/assets/CommandMenu-CnodJFHD.js +1 -0
  109. package/dist/web/assets/CommandMenu-hNQCm8mw.css +1 -0
  110. package/dist/web/assets/CommunityView-CIbjNUZr.js +1 -0
  111. package/dist/web/assets/CommunityView-DSik4sd2.css +1 -0
  112. package/dist/web/assets/GetStartedView-C3ZrnEz5.css +1 -0
  113. package/dist/web/assets/GetStartedView-C8nyH_PT.js +1 -0
  114. package/dist/web/assets/LabsExtensions-GtJzxDnK.js +1 -0
  115. package/dist/web/assets/LabsProfile-DG7rWYur.js +1 -0
  116. package/dist/web/assets/LabsRoute-D6MDHBzq.js +2 -0
  117. package/dist/web/assets/LabsRoute-TEt9j1vB.css +1 -0
  118. package/dist/web/assets/LabsSignals-BfsDN86w.js +1 -0
  119. package/dist/web/assets/LabsSignals-D6iA6Ryl.css +1 -0
  120. package/dist/web/assets/NewProjectDialog-CaKiCoVS.js +1 -0
  121. package/dist/web/assets/ProfileSettingsSection-DTQS2DVL.css +1 -0
  122. package/dist/web/assets/ProfileSettingsSection-DxEzoF3K.js +1 -0
  123. package/dist/web/assets/ProfileView-CEscW7Ru.js +1 -0
  124. package/dist/web/assets/SettingsView-DwbGu8Kj.css +1 -0
  125. package/dist/web/assets/SettingsView-JIRR_FO4.js +63 -0
  126. package/dist/web/assets/TeamChatView-B5M1ThhJ.js +3 -0
  127. package/dist/web/assets/TeamChatView-Bx44q3WV.css +1 -0
  128. package/dist/web/assets/TerminalOverlay-C1iP4OS1.js +19 -0
  129. package/dist/web/assets/TerminalOverlay-DwBiZLwk.css +1 -0
  130. package/dist/web/assets/TrainingSettingsSection-BDYvI2te.js +1 -0
  131. package/dist/web/assets/TrainingView-CoCFK6W3.js +5 -0
  132. package/dist/web/assets/WorkspaceDiffPanel-CMxKQeo7.js +14 -0
  133. package/dist/web/assets/WorkspaceEnvironmentMenu-B8JJbwIz.js +32 -0
  134. package/dist/web/assets/WorkspaceEnvironmentMenu-DGIFdG3o.css +1 -0
  135. package/dist/web/assets/WorkspaceGitDialogs-B4sp9BGn.js +1 -0
  136. package/dist/web/assets/WorkspaceMonacoEditor-BBqimG5X.js +845 -0
  137. package/dist/web/assets/WorkspaceMonacoEditor-BwKcXIZw.css +1 -0
  138. package/dist/web/assets/boxes-DAaDUabq.js +1 -0
  139. package/dist/web/assets/codicon-ngg6Pgfi.ttf +0 -0
  140. package/dist/web/assets/css.worker-DBVD8oXr.js +93 -0
  141. package/dist/web/assets/cssMode-CBF1mieJ.js +1 -0
  142. package/dist/web/assets/dockerfile-BG73LgW2.js +1 -0
  143. package/dist/web/assets/editor.worker-CdQrwHl8.js +26 -0
  144. package/dist/web/assets/git-commit-horizontal-CAickXpN.js +1 -0
  145. package/dist/web/assets/git-dialogs-BZDqS1eT.css +1 -0
  146. package/dist/web/assets/html.worker-CwpTb9lJ.js +470 -0
  147. package/dist/web/assets/htmlMode-2u8OHtWO.js +1 -0
  148. package/dist/web/assets/index-BdY6A-YN.css +1 -0
  149. package/dist/web/assets/index-CU2qhUYV.js +195 -0
  150. package/dist/web/assets/index-Dz2B3-4C.js +1 -0
  151. package/dist/web/assets/info-CQNTh78o.js +1 -0
  152. package/dist/web/assets/json.worker-BoL8UZqY.js +58 -0
  153. package/dist/web/assets/jsonMode-C4CWXViX.js +7 -0
  154. package/dist/web/assets/lspLanguageFeatures-CBs_BOlB.js +4 -0
  155. package/dist/web/assets/markdown-BFxVWTOG.js +1 -0
  156. package/dist/web/assets/monaco.contribution-C1LUxAKf.js +2 -0
  157. package/dist/web/assets/monaco.contribution-Cpf6dWsh.js +2 -0
  158. package/dist/web/assets/monaco.contribution-lOXpG2xQ.js +2 -0
  159. package/dist/web/assets/monaco.contribution-sd3cFkcN.js +2 -0
  160. package/dist/web/assets/monitor-DsIswrMV.js +1 -0
  161. package/dist/web/assets/play-CeRw21NV.js +1 -0
  162. package/dist/web/assets/python-CXYq3BUl.js +1 -0
  163. package/dist/web/assets/refresh-cw-N5b_6AP5.js +1 -0
  164. package/dist/web/assets/reply-BSKjZrJg.js +1 -0
  165. package/dist/web/assets/save-D0oHH1a3.js +1 -0
  166. package/dist/web/assets/settings-lists-BEg6LMcy.css +1 -0
  167. package/dist/web/assets/shell-DiJ1NA_G.js +1 -0
  168. package/dist/web/assets/toggleHighContrast-B7NOMXDY.css +1 -0
  169. package/dist/web/assets/toggleHighContrast-DRjlcwes.js +62 -0
  170. package/dist/web/assets/training-model-data-BPrc68VG.js +1 -0
  171. package/dist/web/assets/ts.worker-BH9nVgjN.js +67718 -0
  172. package/dist/web/assets/tsMode-x-1A7ZcB.js +11 -0
  173. package/dist/web/assets/wifi-off-Dt52ofzh.js +1 -0
  174. package/dist/web/assets/workers-Ciff6Dzi.js +1 -0
  175. package/dist/web/assets/yaml-CB67Kxnz.js +1 -0
  176. package/dist/web/connected-apps/github.svg +3 -0
  177. package/dist/web/connected-apps/google.svg +6 -0
  178. package/dist/web/connected-apps/linear.svg +3 -0
  179. package/dist/web/connected-apps/microsoft.svg +6 -0
  180. package/dist/web/connected-apps/notion.svg +3 -0
  181. package/dist/web/connected-apps/openpond-mcp.svg +4 -0
  182. package/dist/web/connected-apps/slack.svg +6 -0
  183. package/dist/web/connected-apps/x.svg +3 -0
  184. package/dist/web/favicon-16x16.png +0 -0
  185. package/dist/web/favicon-32x32.png +0 -0
  186. package/dist/web/index.html +16 -0
  187. package/dist/web/openpond-icon.png +0 -0
  188. package/dist/web/openpond-wordlogo-white.png +0 -0
  189. package/dist/web/tokens/eth.svg +1 -0
  190. package/dist/web/tokens/usdc.svg +1 -0
  191. package/docs/agent-edit-check-status-json.md +132 -0
  192. package/docs/command-reference.md +695 -0
  193. package/package.json +84 -0
@@ -0,0 +1,1652 @@
1
+ import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
2
+ import {
3
+ buildSandboxCreateInput,
4
+ buildSandboxIntegrationAttachInput,
5
+ buildSandboxReplayInput,
6
+ buildSnapshotCreateInput,
7
+ buildTemplateBuildCreateInput,
8
+ createSandboxFromPlan,
9
+ formatReplayLine,
10
+ formatSandboxLine,
11
+ formatSandboxTemplateLine,
12
+ formatSnapshotCatalogLine,
13
+ formatTemplateBuildLine,
14
+ normalizeSnapshotValidationCleanup,
15
+ summarizeReplayArtifact,
16
+ summarizeSandbox,
17
+ waitForSandboxCreateReady
18
+ } from "./chunk-AUJLPKGI.js";
19
+ import {
20
+ readSandboxSecretValue,
21
+ resolveSandboxClient,
22
+ summarizeSandboxSecret
23
+ } from "./chunk-XSAXENQD.js";
24
+ import "./chunk-5G4E547X.js";
25
+ import {
26
+ parseBooleanOption,
27
+ parseIntegerOption,
28
+ parseJsonObjectOption,
29
+ parseNumberOption
30
+ } from "./chunk-3Y4EL3P6.js";
31
+ import "./chunk-UACZUFIA.js";
32
+
33
+ // src/cli/sandbox-files-command.ts
34
+ async function handleSandboxFilesCommand(client, subcommand, options, rest) {
35
+ if (subcommand === "list-files") {
36
+ const sandboxId = rest[1];
37
+ if (!sandboxId) {
38
+ throw new Error("usage: sandbox list-files <sandboxId> [--path <path>]");
39
+ }
40
+ const path = typeof options.path === "string" ? options.path.trim() : void 0;
41
+ const maxEntries = parseNumberOption(options.maxEntries, "max-entries");
42
+ const recursive = options.recursive !== void 0 ? parseBooleanOption(options.recursive) : void 0;
43
+ const result = await client.listFiles(sandboxId, {
44
+ ...path ? { path } : {},
45
+ ...recursive !== void 0 ? { recursive } : {},
46
+ ...maxEntries !== void 0 ? { maxEntries } : {}
47
+ });
48
+ console.log(
49
+ JSON.stringify(
50
+ {
51
+ sandbox: summarizeSandbox(result.sandbox),
52
+ files: result.files
53
+ },
54
+ null,
55
+ 2
56
+ )
57
+ );
58
+ return true;
59
+ }
60
+ if (subcommand === "upload-file") {
61
+ const sandboxId = rest[1];
62
+ const path = typeof options.path === "string" ? options.path.trim() : "";
63
+ const contents = typeof options.contents === "string" ? options.contents : typeof options.content === "string" ? options.content : "";
64
+ const contentsBase64 = typeof options.contentsBase64 === "string" ? options.contentsBase64.trim() : typeof options.contentBase64 === "string" ? options.contentBase64.trim() : "";
65
+ if (!sandboxId || !path) {
66
+ throw new Error(
67
+ 'usage: sandbox upload-file <sandboxId> --path <path> --contents "text"'
68
+ );
69
+ }
70
+ if (!contents && !contentsBase64) {
71
+ throw new Error(
72
+ 'usage: sandbox upload-file <sandboxId> --path <path> --contents "text"'
73
+ );
74
+ }
75
+ const result = contentsBase64 ? await client.uploadFileBase64(sandboxId, path, contentsBase64) : await client.uploadFile(sandboxId, path, contents);
76
+ console.log(
77
+ JSON.stringify(
78
+ {
79
+ sandbox: summarizeSandbox(result.sandbox),
80
+ file: result.file
81
+ },
82
+ null,
83
+ 2
84
+ )
85
+ );
86
+ return true;
87
+ }
88
+ if (subcommand === "download-file") {
89
+ const sandboxId = rest[1];
90
+ const path = typeof options.path === "string" ? options.path.trim() : "";
91
+ const offsetBytes = Number(options["offset-bytes"]);
92
+ const maxBytes = Number(options["max-bytes"]);
93
+ if (!sandboxId || !path) {
94
+ throw new Error("usage: sandbox download-file <sandboxId> --path <path>");
95
+ }
96
+ const result = await client.downloadFileResponse(sandboxId, {
97
+ path,
98
+ ...Number.isFinite(offsetBytes) ? { offsetBytes } : {},
99
+ ...Number.isFinite(maxBytes) ? { maxBytes } : {}
100
+ });
101
+ console.log(
102
+ JSON.stringify(
103
+ {
104
+ sandbox: summarizeSandbox(result.sandbox),
105
+ file: result.file,
106
+ contents: Buffer.from(result.file.contentsBase64, "base64").toString(
107
+ "utf-8"
108
+ )
109
+ },
110
+ null,
111
+ 2
112
+ )
113
+ );
114
+ return true;
115
+ }
116
+ if (subcommand === "search-files") {
117
+ const sandboxId = rest[1];
118
+ const query = typeof options.query === "string" ? options.query.trim() : "";
119
+ if (!sandboxId || !query) {
120
+ throw new Error(
121
+ "usage: sandbox search-files <sandboxId> --query <text> [--path <path>]"
122
+ );
123
+ }
124
+ const path = typeof options.path === "string" ? options.path.trim() : void 0;
125
+ const maxResults = parseNumberOption(options.maxResults, "max-results");
126
+ const result = await client.searchFiles(sandboxId, {
127
+ query,
128
+ ...path ? { path } : {},
129
+ ...maxResults !== void 0 ? { maxResults } : {}
130
+ });
131
+ console.log(
132
+ JSON.stringify(
133
+ {
134
+ sandbox: summarizeSandbox(result.sandbox),
135
+ matches: result.matches
136
+ },
137
+ null,
138
+ 2
139
+ )
140
+ );
141
+ return true;
142
+ }
143
+ if (subcommand === "delete-file") {
144
+ const sandboxId = rest[1];
145
+ const path = typeof options.path === "string" ? options.path.trim() : "";
146
+ if (!sandboxId || !path) {
147
+ throw new Error(
148
+ "usage: sandbox delete-file <sandboxId> --path <path> [--recursive]"
149
+ );
150
+ }
151
+ const result = await client.deleteFile(sandboxId, path, {
152
+ recursive: parseBooleanOption(options.recursive)
153
+ });
154
+ console.log(
155
+ JSON.stringify(
156
+ {
157
+ sandbox: summarizeSandbox(result.sandbox),
158
+ deleted: result.deleted
159
+ },
160
+ null,
161
+ 2
162
+ )
163
+ );
164
+ return true;
165
+ }
166
+ if (subcommand === "stat-file") {
167
+ const sandboxId = rest[1];
168
+ const path = typeof options.path === "string" ? options.path.trim() : "";
169
+ if (!sandboxId || !path) {
170
+ throw new Error("usage: sandbox stat-file <sandboxId> --path <path>");
171
+ }
172
+ const result = await client.statFile(sandboxId, path);
173
+ console.log(
174
+ JSON.stringify(
175
+ {
176
+ sandbox: summarizeSandbox(result.sandbox),
177
+ file: result.file
178
+ },
179
+ null,
180
+ 2
181
+ )
182
+ );
183
+ return true;
184
+ }
185
+ if (subcommand === "mkdir") {
186
+ const sandboxId = rest[1];
187
+ const path = typeof options.path === "string" ? options.path.trim() : "";
188
+ if (!sandboxId || !path) {
189
+ throw new Error(
190
+ "usage: sandbox mkdir <sandboxId> --path <path> [--recursive false]"
191
+ );
192
+ }
193
+ const result = await client.mkdir(sandboxId, {
194
+ path,
195
+ recursive: options.recursive !== void 0 ? parseBooleanOption(options.recursive) : void 0
196
+ });
197
+ console.log(
198
+ JSON.stringify(
199
+ {
200
+ sandbox: summarizeSandbox(result.sandbox),
201
+ directory: result.directory
202
+ },
203
+ null,
204
+ 2
205
+ )
206
+ );
207
+ return true;
208
+ }
209
+ if (subcommand === "move-file") {
210
+ const sandboxId = rest[1];
211
+ const fromPath = typeof options.fromPath === "string" ? options.fromPath.trim() : "";
212
+ const toPath = typeof options.toPath === "string" ? options.toPath.trim() : "";
213
+ if (!sandboxId || !fromPath || !toPath) {
214
+ throw new Error(
215
+ "usage: sandbox move-file <sandboxId> --from-path <path> --to-path <path> [--overwrite]"
216
+ );
217
+ }
218
+ const result = await client.moveFile(sandboxId, {
219
+ fromPath,
220
+ toPath,
221
+ overwrite: parseBooleanOption(options.overwrite)
222
+ });
223
+ console.log(
224
+ JSON.stringify(
225
+ {
226
+ sandbox: summarizeSandbox(result.sandbox),
227
+ moved: result.moved,
228
+ file: result.file
229
+ },
230
+ null,
231
+ 2
232
+ )
233
+ );
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+
239
+ // src/cli/sandbox-git-command.ts
240
+ async function handleSandboxGitCommand(client, subcommand, options, rest) {
241
+ if (subcommand === "git-status") {
242
+ const sandboxId = rest[1];
243
+ if (!sandboxId) {
244
+ throw new Error("usage: sandbox git-status <sandboxId>");
245
+ }
246
+ const result = await client.gitStatus(sandboxId);
247
+ console.log(
248
+ JSON.stringify(
249
+ {
250
+ sandbox: summarizeSandbox(result.sandbox),
251
+ status: result.status
252
+ },
253
+ null,
254
+ 2
255
+ )
256
+ );
257
+ return true;
258
+ }
259
+ if (subcommand === "git-diff") {
260
+ const sandboxId = rest[1];
261
+ if (!sandboxId) {
262
+ throw new Error("usage: sandbox git-diff <sandboxId> [--base-ref <ref>]");
263
+ }
264
+ const baseRef = typeof options.baseRef === "string" && options.baseRef.trim() ? options.baseRef.trim() : void 0;
265
+ const result = await client.gitDiff(sandboxId, {
266
+ ...baseRef ? { baseRef } : {}
267
+ });
268
+ console.log(
269
+ JSON.stringify(
270
+ {
271
+ sandbox: summarizeSandbox(result.sandbox),
272
+ diff: result.diff
273
+ },
274
+ null,
275
+ 2
276
+ )
277
+ );
278
+ return true;
279
+ }
280
+ if (subcommand === "git-export-patch") {
281
+ const sandboxId = rest[1];
282
+ if (!sandboxId) {
283
+ throw new Error(
284
+ "usage: sandbox git-export-patch <sandboxId> [--base-ref <ref>]"
285
+ );
286
+ }
287
+ const baseRef = typeof options.baseRef === "string" && options.baseRef.trim() ? options.baseRef.trim() : void 0;
288
+ const result = await client.gitExportPatch(sandboxId, {
289
+ ...baseRef ? { baseRef } : {}
290
+ });
291
+ console.log(
292
+ JSON.stringify(
293
+ {
294
+ sandbox: summarizeSandbox(result.sandbox),
295
+ patch: result.patch
296
+ },
297
+ null,
298
+ 2
299
+ )
300
+ );
301
+ return true;
302
+ }
303
+ if (subcommand === "git-branch") {
304
+ const sandboxId = rest[1];
305
+ const branch = typeof options.branch === "string" ? options.branch.trim() : "";
306
+ const startPoint = typeof options.startPoint === "string" && options.startPoint.trim() ? options.startPoint.trim() : void 0;
307
+ if (!sandboxId || !branch) {
308
+ throw new Error(
309
+ "usage: sandbox git-branch <sandboxId> --branch <name> [--create] [--start-point <ref>]"
310
+ );
311
+ }
312
+ const result = await client.gitBranch(sandboxId, {
313
+ branch,
314
+ create: parseBooleanOption(options.create),
315
+ ...startPoint ? { startPoint } : {}
316
+ });
317
+ console.log(
318
+ JSON.stringify(
319
+ {
320
+ sandbox: summarizeSandbox(result.sandbox),
321
+ branch: result.branch
322
+ },
323
+ null,
324
+ 2
325
+ )
326
+ );
327
+ return true;
328
+ }
329
+ if (subcommand === "git-commit") {
330
+ const sandboxId = rest[1];
331
+ const message = typeof options.message === "string" ? options.message.trim() : "";
332
+ const all = parseBooleanOption(options.all);
333
+ const rawPaths = typeof options.paths === "string" ? options.paths : typeof options.path === "string" ? options.path : "";
334
+ const paths = rawPaths.split(",").map((path) => path.trim()).filter(Boolean);
335
+ if (!sandboxId || !message || !all && paths.length === 0) {
336
+ throw new Error(
337
+ 'usage: sandbox git-commit <sandboxId> --message "..." [--all|--paths <csv>]'
338
+ );
339
+ }
340
+ const result = await client.gitCommit(sandboxId, {
341
+ message,
342
+ ...all ? { all: true } : { paths }
343
+ });
344
+ console.log(
345
+ JSON.stringify(
346
+ {
347
+ sandbox: summarizeSandbox(result.sandbox),
348
+ commit: result.commit
349
+ },
350
+ null,
351
+ 2
352
+ )
353
+ );
354
+ return true;
355
+ }
356
+ if (subcommand === "git-pull") {
357
+ const sandboxId = rest[1];
358
+ if (!sandboxId) {
359
+ throw new Error(
360
+ "usage: sandbox git-pull <sandboxId> [--remote origin] [--branch main] [--rebase|--ff-only false]"
361
+ );
362
+ }
363
+ const remote = typeof options.remote === "string" && options.remote.trim() ? options.remote.trim() : void 0;
364
+ const branch = typeof options.branch === "string" && options.branch.trim() ? options.branch.trim() : void 0;
365
+ const result = await client.gitPull(sandboxId, {
366
+ ...remote ? { remote } : {},
367
+ ...branch ? { branch } : {},
368
+ ...options.rebase !== void 0 ? { rebase: parseBooleanOption(options.rebase) } : {},
369
+ ...options.ffOnly !== void 0 ? { ffOnly: parseBooleanOption(options.ffOnly) } : {}
370
+ });
371
+ console.log(
372
+ JSON.stringify(
373
+ {
374
+ sandbox: summarizeSandbox(result.sandbox),
375
+ pull: result.pull
376
+ },
377
+ null,
378
+ 2
379
+ )
380
+ );
381
+ return true;
382
+ }
383
+ if (subcommand === "git-push") {
384
+ const sandboxId = rest[1];
385
+ if (!sandboxId) {
386
+ throw new Error(
387
+ "usage: sandbox git-push <sandboxId> [--remote origin] [--branch main] [--set-upstream] [--force-with-lease]"
388
+ );
389
+ }
390
+ const remote = typeof options.remote === "string" && options.remote.trim() ? options.remote.trim() : void 0;
391
+ const branch = typeof options.branch === "string" && options.branch.trim() ? options.branch.trim() : void 0;
392
+ const result = await client.gitPush(sandboxId, {
393
+ ...remote ? { remote } : {},
394
+ ...branch ? { branch } : {},
395
+ ...options.setUpstream !== void 0 ? { setUpstream: parseBooleanOption(options.setUpstream) } : {},
396
+ ...options.forceWithLease !== void 0 ? { forceWithLease: parseBooleanOption(options.forceWithLease) } : {}
397
+ });
398
+ console.log(
399
+ JSON.stringify(
400
+ {
401
+ sandbox: summarizeSandbox(result.sandbox),
402
+ push: result.push
403
+ },
404
+ null,
405
+ 2
406
+ )
407
+ );
408
+ return true;
409
+ }
410
+ return false;
411
+ }
412
+
413
+ // src/cli/sandbox-process-command.ts
414
+ async function handleSandboxProcessCommand(client, subcommand, options, rest) {
415
+ if (subcommand === "process-start") {
416
+ const sandboxId = rest[1];
417
+ const command = (typeof options.command === "string" ? options.command : null) || rest.slice(2).join(" ");
418
+ if (!sandboxId || !command.trim()) {
419
+ throw new Error(
420
+ "usage: sandbox process-start <sandboxId> --command <command>"
421
+ );
422
+ }
423
+ const timeoutSeconds = parseIntegerOption(
424
+ options.timeoutSeconds,
425
+ "timeout-seconds"
426
+ );
427
+ const result = await client.startProcess(sandboxId, {
428
+ command: command.trim(),
429
+ ...timeoutSeconds !== void 0 ? { timeoutSeconds } : {}
430
+ });
431
+ console.log(
432
+ JSON.stringify(
433
+ {
434
+ sandbox: summarizeSandbox(result.sandbox),
435
+ process: result.process
436
+ },
437
+ null,
438
+ 2
439
+ )
440
+ );
441
+ return true;
442
+ }
443
+ if (subcommand === "process-list") {
444
+ const sandboxId = rest[1];
445
+ if (!sandboxId) {
446
+ throw new Error("usage: sandbox process-list <sandboxId>");
447
+ }
448
+ const result = await client.listProcesses(sandboxId);
449
+ console.log(
450
+ JSON.stringify(
451
+ {
452
+ sandbox: summarizeSandbox(result.sandbox),
453
+ processes: result.processes
454
+ },
455
+ null,
456
+ 2
457
+ )
458
+ );
459
+ return true;
460
+ }
461
+ if (subcommand === "process-get") {
462
+ const sandboxId = rest[1];
463
+ const processId = rest[2];
464
+ if (!sandboxId || !processId) {
465
+ throw new Error(
466
+ "usage: sandbox process-get <sandboxId> <processId> [--since <cursor>]"
467
+ );
468
+ }
469
+ const since = parseIntegerOption(options.since, "since");
470
+ const result = await client.getProcess(sandboxId, processId, {
471
+ ...since !== void 0 ? { since } : {}
472
+ });
473
+ console.log(
474
+ JSON.stringify(
475
+ {
476
+ sandbox: summarizeSandbox(result.sandbox),
477
+ process: result.process,
478
+ output: result.output,
479
+ cursor: result.cursor,
480
+ completed: result.completed
481
+ },
482
+ null,
483
+ 2
484
+ )
485
+ );
486
+ return true;
487
+ }
488
+ if (subcommand === "process-stop") {
489
+ const sandboxId = rest[1];
490
+ const processId = rest[2];
491
+ if (!sandboxId || !processId) {
492
+ throw new Error("usage: sandbox process-stop <sandboxId> <processId>");
493
+ }
494
+ const result = await client.stopProcess(sandboxId, processId);
495
+ console.log(
496
+ JSON.stringify(
497
+ {
498
+ sandbox: summarizeSandbox(result.sandbox),
499
+ process: result.process
500
+ },
501
+ null,
502
+ 2
503
+ )
504
+ );
505
+ return true;
506
+ }
507
+ if (subcommand === "process-stream") {
508
+ const sandboxId = rest[1];
509
+ const processId = rest[2];
510
+ if (!sandboxId || !processId) {
511
+ throw new Error(
512
+ "usage: sandbox process-stream <sandboxId> <processId> [--since <cursor>]"
513
+ );
514
+ }
515
+ const since = parseIntegerOption(options.since, "since");
516
+ await client.streamProcessOutput(sandboxId, processId, {
517
+ ...since !== void 0 ? { since } : {}
518
+ });
519
+ return true;
520
+ }
521
+ if (subcommand === "pty-start") {
522
+ const sandboxId = rest[1];
523
+ if (!sandboxId) {
524
+ throw new Error(
525
+ "usage: sandbox pty-start <sandboxId> [--command <command>]"
526
+ );
527
+ }
528
+ const command = (typeof options.command === "string" ? options.command : null) || rest.slice(2).join(" ");
529
+ const timeoutSeconds = parseIntegerOption(
530
+ options.timeoutSeconds,
531
+ "timeout-seconds"
532
+ );
533
+ const rows = parseIntegerOption(options.rows, "rows");
534
+ const cols = parseIntegerOption(options.cols, "cols");
535
+ const result = await client.startPty(sandboxId, {
536
+ ...command.trim() ? { command: command.trim() } : {},
537
+ ...timeoutSeconds !== void 0 ? { timeoutSeconds } : {},
538
+ ...rows !== void 0 ? { rows } : {},
539
+ ...cols !== void 0 ? { cols } : {}
540
+ });
541
+ console.log(
542
+ JSON.stringify(
543
+ {
544
+ sandbox: summarizeSandbox(result.sandbox),
545
+ pty: result.pty
546
+ },
547
+ null,
548
+ 2
549
+ )
550
+ );
551
+ return true;
552
+ }
553
+ if (subcommand === "pty-list") {
554
+ const sandboxId = rest[1];
555
+ if (!sandboxId) {
556
+ throw new Error("usage: sandbox pty-list <sandboxId>");
557
+ }
558
+ const result = await client.listPtys(sandboxId);
559
+ console.log(
560
+ JSON.stringify(
561
+ {
562
+ sandbox: summarizeSandbox(result.sandbox),
563
+ ptys: result.ptys
564
+ },
565
+ null,
566
+ 2
567
+ )
568
+ );
569
+ return true;
570
+ }
571
+ if (subcommand === "pty-get") {
572
+ const sandboxId = rest[1];
573
+ const ptyId = rest[2];
574
+ if (!sandboxId || !ptyId) {
575
+ throw new Error(
576
+ "usage: sandbox pty-get <sandboxId> <ptyId> [--since <cursor>]"
577
+ );
578
+ }
579
+ const since = parseIntegerOption(options.since, "since");
580
+ const result = await client.getPty(sandboxId, ptyId, {
581
+ ...since !== void 0 ? { since } : {}
582
+ });
583
+ console.log(
584
+ JSON.stringify(
585
+ {
586
+ sandbox: summarizeSandbox(result.sandbox),
587
+ pty: result.pty,
588
+ output: result.output,
589
+ cursor: result.cursor,
590
+ completed: result.completed
591
+ },
592
+ null,
593
+ 2
594
+ )
595
+ );
596
+ return true;
597
+ }
598
+ if (subcommand === "pty-write") {
599
+ const sandboxId = rest[1];
600
+ const ptyId = rest[2];
601
+ const inputBase64 = typeof options.inputBase64 === "string" ? options.inputBase64.trim() : "";
602
+ const inputText = (typeof options.input === "string" ? options.input : null) || rest.slice(3).join(" ");
603
+ if (!sandboxId || !ptyId || !inputBase64 && !inputText) {
604
+ throw new Error(
605
+ "usage: sandbox pty-write <sandboxId> <ptyId> --input <text>"
606
+ );
607
+ }
608
+ const result = await client.writePtyInput(
609
+ sandboxId,
610
+ ptyId,
611
+ inputBase64 ? { dataBase64: inputBase64 } : inputText
612
+ );
613
+ console.log(
614
+ JSON.stringify(
615
+ {
616
+ sandbox: summarizeSandbox(result.sandbox),
617
+ pty: result.pty
618
+ },
619
+ null,
620
+ 2
621
+ )
622
+ );
623
+ return true;
624
+ }
625
+ if (subcommand === "pty-stop") {
626
+ const sandboxId = rest[1];
627
+ const ptyId = rest[2];
628
+ if (!sandboxId || !ptyId) {
629
+ throw new Error("usage: sandbox pty-stop <sandboxId> <ptyId>");
630
+ }
631
+ const result = await client.stopPty(sandboxId, ptyId);
632
+ console.log(
633
+ JSON.stringify(
634
+ {
635
+ sandbox: summarizeSandbox(result.sandbox),
636
+ pty: result.pty
637
+ },
638
+ null,
639
+ 2
640
+ )
641
+ );
642
+ return true;
643
+ }
644
+ if (subcommand === "pty-stream") {
645
+ const sandboxId = rest[1];
646
+ const ptyId = rest[2];
647
+ if (!sandboxId || !ptyId) {
648
+ throw new Error(
649
+ "usage: sandbox pty-stream <sandboxId> <ptyId> [--since <cursor>]"
650
+ );
651
+ }
652
+ const since = parseIntegerOption(options.since, "since");
653
+ await client.streamPtyOutput(sandboxId, ptyId, {
654
+ ...since !== void 0 ? { since } : {}
655
+ });
656
+ return true;
657
+ }
658
+ return false;
659
+ }
660
+
661
+ // src/cli/sandbox-replay-command.ts
662
+ async function handleSandboxReplayCommand(client, subcommand, options, rest) {
663
+ if (subcommand === "replays" || subcommand === "replay-list") {
664
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
665
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
666
+ const result = await client.listReplays({
667
+ ...teamId ? { teamId } : {},
668
+ ...projectId ? { projectId } : {}
669
+ });
670
+ if (parseBooleanOption(options.json)) {
671
+ console.log(JSON.stringify(result, null, 2));
672
+ return true;
673
+ }
674
+ if (result.replays.length === 0) {
675
+ console.log("no sandbox replays found");
676
+ return true;
677
+ }
678
+ for (const replay of result.replays) {
679
+ console.log(formatReplayLine(replay));
680
+ }
681
+ return true;
682
+ }
683
+ if (subcommand === "replay-start" || subcommand === "start-replay") {
684
+ const result = await client.startReplay(buildSandboxReplayInput(options));
685
+ console.log(JSON.stringify(result, null, 2));
686
+ return true;
687
+ }
688
+ if (subcommand === "replay-get" || subcommand === "get-replay") {
689
+ const replayId = rest[1];
690
+ if (!replayId) {
691
+ throw new Error("usage: sandbox replay-get <replayId> [--team-id <id>]");
692
+ }
693
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
694
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
695
+ const result = await client.getReplay(replayId, {
696
+ ...teamId ? { teamId } : {},
697
+ ...projectId ? { projectId } : {}
698
+ });
699
+ console.log(JSON.stringify(result, null, 2));
700
+ return true;
701
+ }
702
+ if (subcommand === "replay-logs" || subcommand === "logs-replay") {
703
+ const replayId = rest[1];
704
+ if (!replayId) {
705
+ throw new Error("usage: sandbox replay-logs <replayId> [--team-id <id>]");
706
+ }
707
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
708
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
709
+ const result = await client.getReplayLogs(replayId, {
710
+ ...teamId ? { teamId } : {},
711
+ ...projectId ? { projectId } : {}
712
+ });
713
+ for (const line of result.logs) {
714
+ console.log(line);
715
+ }
716
+ return true;
717
+ }
718
+ if (subcommand === "replay-artifacts" || subcommand === "artifacts-replay") {
719
+ const replayId = rest[1];
720
+ if (!replayId) {
721
+ throw new Error(
722
+ "usage: sandbox replay-artifacts <replayId> [--team-id <id>]"
723
+ );
724
+ }
725
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
726
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
727
+ const result = await client.getReplayArtifacts(replayId, {
728
+ ...teamId ? { teamId } : {},
729
+ ...projectId ? { projectId } : {}
730
+ });
731
+ console.log(
732
+ JSON.stringify(
733
+ {
734
+ replayId: result.replayId,
735
+ artifacts: result.artifacts.map(summarizeReplayArtifact)
736
+ },
737
+ null,
738
+ 2
739
+ )
740
+ );
741
+ return true;
742
+ }
743
+ if (subcommand === "replay-cancel" || subcommand === "cancel-replay") {
744
+ const replayId = rest[1];
745
+ if (!replayId) {
746
+ throw new Error(
747
+ "usage: sandbox replay-cancel <replayId> [--team-id <id>]"
748
+ );
749
+ }
750
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
751
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
752
+ const result = await client.cancelReplay(replayId, {
753
+ ...teamId ? { teamId } : {},
754
+ ...projectId ? { projectId } : {}
755
+ });
756
+ console.log(JSON.stringify(result, null, 2));
757
+ return true;
758
+ }
759
+ if (subcommand === "replay-watch" || subcommand === "watch-replay") {
760
+ const replayId = rest[1];
761
+ if (!replayId) {
762
+ throw new Error(
763
+ "usage: sandbox replay-watch <replayId> [--team-id <id>]"
764
+ );
765
+ }
766
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
767
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
768
+ const intervalMs = parseIntegerOption(options.intervalMs, "interval-ms") ?? 5e3;
769
+ const timeoutMs = parseIntegerOption(options.timeoutMs, "timeout-ms") ?? 15 * 60 * 1e3;
770
+ const startedAt = Date.now();
771
+ const seenLogs = /* @__PURE__ */ new Set();
772
+ while (Date.now() - startedAt <= timeoutMs) {
773
+ const result = await client.getReplay(replayId, {
774
+ ...teamId ? { teamId } : {},
775
+ ...projectId ? { projectId } : {}
776
+ });
777
+ for (const line of result.replay.logs) {
778
+ if (!seenLogs.has(line)) {
779
+ seenLogs.add(line);
780
+ console.log(line);
781
+ }
782
+ }
783
+ if (result.replay.state === "succeeded" || result.replay.state === "failed" || result.replay.state === "canceled") {
784
+ console.log(formatReplayLine(result.replay));
785
+ if (result.replay.state !== "succeeded") {
786
+ throw new Error(
787
+ `sandbox replay ${result.replay.state}: ${result.replay.error ?? "no error"}`
788
+ );
789
+ }
790
+ return true;
791
+ }
792
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
793
+ }
794
+ throw new Error(`sandbox replay did not finish within ${timeoutMs}ms`);
795
+ }
796
+ return false;
797
+ }
798
+
799
+ // src/cli/sandbox-runtime-command.ts
800
+ async function handleSandboxRuntimeCommand(client, subcommand, options, rest) {
801
+ if (subcommand === "runtime-list") {
802
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
803
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
804
+ const agentId = typeof options.agentId === "string" ? options.agentId.trim() : "";
805
+ const runtimes = await client.listSandboxRuntimes({
806
+ ...teamId ? { teamId } : {},
807
+ ...projectId ? { projectId } : {},
808
+ ...agentId ? { agentId } : {}
809
+ });
810
+ console.log(JSON.stringify({ runtimes }, null, 2));
811
+ return true;
812
+ }
813
+ if (subcommand === "runtime-get") {
814
+ const runtimeId = rest[1]?.trim();
815
+ if (!runtimeId) {
816
+ throw new Error("usage: sandbox runtime-get <runtimeId>");
817
+ }
818
+ const runtime = await client.getSandboxRuntime(runtimeId);
819
+ console.log(JSON.stringify({ runtime }, null, 2));
820
+ return true;
821
+ }
822
+ if (subcommand === "runtime-events") {
823
+ const runtimeId = rest[1]?.trim();
824
+ if (!runtimeId) {
825
+ throw new Error("usage: sandbox runtime-events <runtimeId>");
826
+ }
827
+ console.log(
828
+ JSON.stringify(await client.listSandboxRuntimeEvents(runtimeId), null, 2)
829
+ );
830
+ return true;
831
+ }
832
+ if (subcommand === "runtime-status") {
833
+ const runtimeId = rest[1]?.trim();
834
+ const status = typeof options.status === "string" && options.status.trim() ? options.status.trim() : "";
835
+ const expectedVersion = Number(options.expectedVersion);
836
+ const summary = typeof options.summary === "string" && options.summary.trim() ? options.summary.trim() : void 0;
837
+ if (!runtimeId || !status || !Number.isInteger(expectedVersion)) {
838
+ throw new Error(
839
+ "usage: sandbox runtime-status <runtimeId> --status <status> --expected-version <n>"
840
+ );
841
+ }
842
+ const runtime = await client.updateSandboxRuntimeStatus(runtimeId, {
843
+ status,
844
+ expectedVersion,
845
+ ...summary ? { summary } : {}
846
+ });
847
+ console.log(JSON.stringify({ runtime }, null, 2));
848
+ return true;
849
+ }
850
+ if (subcommand === "runtime-event") {
851
+ const runtimeId = rest[1]?.trim();
852
+ const type = typeof options.type === "string" && options.type.trim() ? options.type.trim() : "";
853
+ const summary = typeof options.summary === "string" && options.summary.trim() ? options.summary.trim() : void 0;
854
+ const payload = typeof options.payload === "string" && options.payload.trim() ? parseJsonObjectOption(options.payload, "payload") : void 0;
855
+ const lifecycleHint = typeof options.lifecycleHint === "string" && options.lifecycleHint.trim() ? parseJsonObjectOption(options.lifecycleHint, "lifecycle-hint") : void 0;
856
+ if (!runtimeId || !type) {
857
+ throw new Error(
858
+ "usage: sandbox runtime-event <runtimeId> --type <eventType> [--summary <text>] [--payload <json>] [--lifecycle-hint <json>]"
859
+ );
860
+ }
861
+ console.log(
862
+ JSON.stringify(
863
+ await client.emitSandboxRuntimeEvent(runtimeId, {
864
+ type,
865
+ ...summary ? { summary } : {},
866
+ ...payload ? { payload } : {},
867
+ ...lifecycleHint ? { lifecycleHint } : {}
868
+ }),
869
+ null,
870
+ 2
871
+ )
872
+ );
873
+ return true;
874
+ }
875
+ if (subcommand === "runtime-preserve-source" || subcommand === "runtime-preserve") {
876
+ const runtimeId = rest[1]?.trim();
877
+ const teamId = typeof options.teamId === "string" && options.teamId.trim() ? options.teamId.trim() : "";
878
+ const sandboxId = typeof options.sandboxId === "string" && options.sandboxId.trim() ? options.sandboxId.trim() : "";
879
+ const message = typeof options.message === "string" && options.message.trim() ? options.message.trim() : "";
880
+ if (!runtimeId) {
881
+ throw new Error(
882
+ "usage: sandbox runtime-preserve-source <runtimeId> [--team-id <id>] [--sandbox-id <id>] [--message <text>]"
883
+ );
884
+ }
885
+ console.log(
886
+ JSON.stringify(
887
+ await client.runtimes.preserveSource(
888
+ runtimeId,
889
+ {
890
+ ...sandboxId ? { sandboxId } : {},
891
+ ...message ? { message } : {}
892
+ },
893
+ {
894
+ ...teamId ? { teamId } : {}
895
+ }
896
+ ),
897
+ null,
898
+ 2
899
+ )
900
+ );
901
+ return true;
902
+ }
903
+ return false;
904
+ }
905
+
906
+ // src/cli/sandbox-secrets-command.ts
907
+ async function handleSandboxSecretsCommand(client, subcommand, options, rest) {
908
+ if (subcommand === "secrets" || subcommand === "secret-list") {
909
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
910
+ const secrets = await client.listSecrets({
911
+ ...teamId ? { teamId } : {}
912
+ });
913
+ if (parseBooleanOption(options.json)) {
914
+ console.log(
915
+ JSON.stringify(
916
+ { secrets: secrets.map(summarizeSandboxSecret) },
917
+ null,
918
+ 2
919
+ )
920
+ );
921
+ return true;
922
+ }
923
+ if (secrets.length === 0) {
924
+ console.log("no sandbox secrets found");
925
+ return true;
926
+ }
927
+ for (const secret of secrets) {
928
+ console.log(
929
+ `${secret.name} ${secret.status} v${secret.currentVersion ?? "current"} ${secret.secretRef}`
930
+ );
931
+ }
932
+ return true;
933
+ }
934
+ if (subcommand === "secret-create") {
935
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
936
+ const name = typeof options.name === "string" ? options.name.trim() : "";
937
+ const description = typeof options.description === "string" && options.description.trim() ? options.description.trim() : void 0;
938
+ const scope = options.scope === "project" || options.scope === "template" || options.scope === "team" ? options.scope : void 0;
939
+ if (!name) {
940
+ throw new Error(
941
+ "usage: sandbox secret-create --name <ENV_NAME> [--team-id <id>] [--stdin]"
942
+ );
943
+ }
944
+ const value = await readSandboxSecretValue(options, `Value for ${name}`);
945
+ const secret = await client.createSecret({
946
+ ...teamId ? { teamId } : {},
947
+ name,
948
+ value,
949
+ ...description ? { description } : {},
950
+ ...scope ? { scope } : {}
951
+ });
952
+ console.log(
953
+ JSON.stringify({ secret: summarizeSandboxSecret(secret) }, null, 2)
954
+ );
955
+ return true;
956
+ }
957
+ if (subcommand === "secret-rotate") {
958
+ const secretId = rest[1];
959
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
960
+ if (!secretId) {
961
+ throw new Error(
962
+ "usage: sandbox secret-rotate <secretId> [--team-id <id>] [--stdin]"
963
+ );
964
+ }
965
+ const value = await readSandboxSecretValue(options, "New secret value");
966
+ const secret = await client.rotateSecret(secretId, {
967
+ ...teamId ? { teamId } : {},
968
+ value
969
+ });
970
+ console.log(
971
+ JSON.stringify({ secret: summarizeSandboxSecret(secret) }, null, 2)
972
+ );
973
+ return true;
974
+ }
975
+ if (subcommand === "secret-attach") {
976
+ const secretId = rest[1];
977
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
978
+ const envName = typeof options.envName === "string" ? options.envName.trim() : "";
979
+ const targetType = options.targetType === "sandbox" || options.targetType === "template" || options.targetType === "project" || options.targetType === "agent" || options.targetType === "replay" ? options.targetType : void 0;
980
+ const targetId = typeof options.targetId === "string" ? options.targetId.trim() : "";
981
+ if (!secretId || !envName || !targetType || !targetId) {
982
+ throw new Error(
983
+ "usage: sandbox secret-attach <secretId> --env-name <ENV_NAME> --target-type sandbox|project|agent|template|replay --target-id <id>"
984
+ );
985
+ }
986
+ const secret = await client.attachSecret(secretId, {
987
+ ...teamId ? { teamId } : {},
988
+ envName,
989
+ targetType,
990
+ targetId
991
+ });
992
+ console.log(
993
+ JSON.stringify({ secret: summarizeSandboxSecret(secret) }, null, 2)
994
+ );
995
+ return true;
996
+ }
997
+ if (subcommand === "secret-revoke" || subcommand === "secret-delete") {
998
+ const secretId = rest[1];
999
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1000
+ if (!secretId) {
1001
+ throw new Error(
1002
+ `usage: sandbox ${subcommand} <secretId> [--team-id <id>]`
1003
+ );
1004
+ }
1005
+ const secret = subcommand === "secret-revoke" ? await client.revokeSecret(secretId, {
1006
+ ...teamId ? { teamId } : {}
1007
+ }) : await client.deleteSecret(secretId, {
1008
+ ...teamId ? { teamId } : {}
1009
+ });
1010
+ console.log(
1011
+ JSON.stringify({ secret: summarizeSandboxSecret(secret) }, null, 2)
1012
+ );
1013
+ return true;
1014
+ }
1015
+ return false;
1016
+ }
1017
+
1018
+ // src/cli/sandbox-template-builds-command.ts
1019
+ async function handleSandboxTemplateBuildsCommand(client, subcommand, options, rest) {
1020
+ if (subcommand === "published-snapshot-builds" || subcommand === "published-snapshot-build-list" || subcommand === "template-builds" || subcommand === "template-build-list") {
1021
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1022
+ if (!teamId) {
1023
+ throw new Error(
1024
+ "usage: sandbox published-snapshot-builds --team-id <id>"
1025
+ );
1026
+ }
1027
+ const builds = await client.listPublishedSnapshotBuilds({ teamId });
1028
+ if (parseBooleanOption(options.json)) {
1029
+ console.log(JSON.stringify({ builds }, null, 2));
1030
+ return true;
1031
+ }
1032
+ if (builds.length === 0) {
1033
+ console.log("no published snapshot builds found");
1034
+ return true;
1035
+ }
1036
+ for (const build of builds) {
1037
+ console.log(formatTemplateBuildLine(build));
1038
+ }
1039
+ return true;
1040
+ }
1041
+ if (subcommand === "published-snapshot-build-create" || subcommand === "create-published-snapshot-build" || subcommand === "template-build-create" || subcommand === "create-template-build") {
1042
+ const build = await client.createPublishedSnapshotBuild(
1043
+ buildTemplateBuildCreateInput(options)
1044
+ );
1045
+ console.log(JSON.stringify({ build }, null, 2));
1046
+ return true;
1047
+ }
1048
+ if (subcommand === "published-snapshot-build-get" || subcommand === "get-published-snapshot-build" || subcommand === "template-build-get" || subcommand === "get-template-build") {
1049
+ const buildId = rest[1];
1050
+ if (!buildId) {
1051
+ throw new Error("usage: sandbox published-snapshot-build-get <buildId>");
1052
+ }
1053
+ const build = await client.getPublishedSnapshotBuild(buildId);
1054
+ console.log(JSON.stringify({ build }, null, 2));
1055
+ return true;
1056
+ }
1057
+ if (subcommand === "published-snapshot-build-logs" || subcommand === "published-snapshot-build-log" || subcommand === "template-build-logs" || subcommand === "template-build-log") {
1058
+ const buildId = rest[1];
1059
+ if (!buildId) {
1060
+ throw new Error("usage: sandbox published-snapshot-build-logs <buildId>");
1061
+ }
1062
+ const logs = await client.getPublishedSnapshotBuildLogs(buildId);
1063
+ if (parseBooleanOption(options.json)) {
1064
+ console.log(JSON.stringify(logs, null, 2));
1065
+ return true;
1066
+ }
1067
+ for (const line of logs.logs) {
1068
+ console.log(line);
1069
+ }
1070
+ return true;
1071
+ }
1072
+ if (subcommand === "published-snapshot-build-cancel" || subcommand === "cancel-published-snapshot-build" || subcommand === "template-build-cancel" || subcommand === "cancel-template-build") {
1073
+ const buildId = rest[1];
1074
+ if (!buildId) {
1075
+ throw new Error(
1076
+ "usage: sandbox published-snapshot-build-cancel <buildId>"
1077
+ );
1078
+ }
1079
+ const build = await client.cancelPublishedSnapshotBuild(buildId);
1080
+ console.log(JSON.stringify({ build }, null, 2));
1081
+ return true;
1082
+ }
1083
+ if (subcommand === "published-snapshot-build-watch" || subcommand === "watch-published-snapshot-build" || subcommand === "template-build-watch" || subcommand === "watch-template-build") {
1084
+ const buildId = rest[1];
1085
+ if (!buildId) {
1086
+ throw new Error("usage: sandbox published-snapshot-build-watch <buildId>");
1087
+ }
1088
+ const intervalMs = parseIntegerOption(options.intervalMs, "interval-ms") ?? 5e3;
1089
+ const timeoutMs = parseIntegerOption(options.timeoutMs, "timeout-ms") ?? 15 * 60 * 1e3;
1090
+ const startedAt = Date.now();
1091
+ const seenLogs = /* @__PURE__ */ new Set();
1092
+ while (Date.now() - startedAt <= timeoutMs) {
1093
+ const [build, logs] = await Promise.all([
1094
+ client.getPublishedSnapshotBuild(buildId),
1095
+ client.getPublishedSnapshotBuildLogs(buildId)
1096
+ ]);
1097
+ for (const line of logs.logs) {
1098
+ if (!seenLogs.has(line)) {
1099
+ seenLogs.add(line);
1100
+ console.log(line);
1101
+ }
1102
+ }
1103
+ if (build.status === "succeeded" || build.status === "failed" || build.status === "cancelled") {
1104
+ console.log(formatTemplateBuildLine(build));
1105
+ if (build.status !== "succeeded") {
1106
+ throw new Error(
1107
+ `published snapshot build ${build.status}: ${build.error ?? "no error"}`
1108
+ );
1109
+ }
1110
+ return true;
1111
+ }
1112
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
1113
+ }
1114
+ throw new Error(
1115
+ `published snapshot build did not finish within ${timeoutMs}ms`
1116
+ );
1117
+ }
1118
+ return false;
1119
+ }
1120
+
1121
+ // src/cli/sandbox-command.ts
1122
+ function parseSandboxAsyncOption(options) {
1123
+ return parseBooleanOption(options.async) || parseBooleanOption(options.respondAsync);
1124
+ }
1125
+ async function runSandboxCommand(options, rest) {
1126
+ const subcommand = rest[0] || "list";
1127
+ const client = await resolveSandboxClient(options);
1128
+ if (subcommand === "list") {
1129
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1130
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1131
+ const agentId = typeof options.agentId === "string" ? options.agentId.trim() : "";
1132
+ const sandboxes = await client.list({
1133
+ ...teamId ? { teamId } : {},
1134
+ ...projectId ? { projectId } : {},
1135
+ ...agentId ? { agentId } : {}
1136
+ });
1137
+ if (sandboxes.length === 0) {
1138
+ console.log("no sandboxes found");
1139
+ return;
1140
+ }
1141
+ for (const sandbox of sandboxes) {
1142
+ console.log(formatSandboxLine(sandbox));
1143
+ }
1144
+ return;
1145
+ }
1146
+ if (subcommand === "mcp-config" || subcommand === "mcp-url") {
1147
+ const config = client.mcpServerConfig();
1148
+ console.log(
1149
+ JSON.stringify(
1150
+ {
1151
+ ...config,
1152
+ headers: {
1153
+ "openpond-api-key": "set OPENPOND_API_KEY or use your saved openpond profile"
1154
+ }
1155
+ },
1156
+ null,
1157
+ 2
1158
+ )
1159
+ );
1160
+ return;
1161
+ }
1162
+ if (await handleSandboxRuntimeCommand(client, subcommand, options, rest)) {
1163
+ return;
1164
+ }
1165
+ if (subcommand === "pricing") {
1166
+ const pricing = await client.pricing();
1167
+ console.log(JSON.stringify(pricing, null, 2));
1168
+ return;
1169
+ }
1170
+ if (subcommand === "costs") {
1171
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1172
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1173
+ const agentId = typeof options.agentId === "string" ? options.agentId.trim() : "";
1174
+ const costs = await client.costs({
1175
+ ...teamId ? { teamId } : {},
1176
+ ...projectId ? { projectId } : {},
1177
+ ...agentId ? { agentId } : {}
1178
+ });
1179
+ if (parseBooleanOption(options.summary)) {
1180
+ console.log(
1181
+ JSON.stringify(
1182
+ {
1183
+ costs: {
1184
+ teamId: costs.costs.teamId,
1185
+ ownerUserId: costs.costs.ownerUserId,
1186
+ generatedAt: costs.costs.generatedAt,
1187
+ summary: costs.costs.summary,
1188
+ lineItems: costs.costs.lineItems,
1189
+ tiers: costs.costs.pricing.tiers.map((tier) => ({
1190
+ key: tier.key,
1191
+ resources: tier.resources,
1192
+ keepRunningEstimate: tier.keepRunningEstimate
1193
+ }))
1194
+ }
1195
+ },
1196
+ null,
1197
+ 2
1198
+ )
1199
+ );
1200
+ return;
1201
+ }
1202
+ console.log(JSON.stringify(costs, null, 2));
1203
+ return;
1204
+ }
1205
+ if (await handleSandboxSecretsCommand(client, subcommand, options, rest)) {
1206
+ return;
1207
+ }
1208
+ if (subcommand === "snapshots" || subcommand === "snapshot-catalog") {
1209
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1210
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1211
+ const agentId = typeof options.agentId === "string" ? options.agentId.trim() : "";
1212
+ const query = typeof options.query === "string" && options.query.trim() ? options.query.trim() : typeof options.q === "string" && options.q.trim() ? options.q.trim() : "";
1213
+ const tag = typeof options.tag === "string" ? options.tag.trim() : "";
1214
+ const useCase = typeof options.useCase === "string" ? options.useCase.trim() : "";
1215
+ const replayState = typeof options.replayState === "string" ? options.replayState.trim() : "";
1216
+ const catalog = await client.snapshotCatalog({
1217
+ ...teamId ? { teamId } : {},
1218
+ ...projectId ? { projectId } : {},
1219
+ ...agentId ? { agentId } : {},
1220
+ ...query ? { q: query } : {},
1221
+ ...tag ? { tag } : {},
1222
+ ...useCase ? { useCase } : {},
1223
+ ...replayState === "draft" || replayState === "validated" || replayState === "published" ? { replayState } : {}
1224
+ });
1225
+ if (catalog.snapshots.length === 0) {
1226
+ console.log("no sandbox snapshots found");
1227
+ return;
1228
+ }
1229
+ for (const snapshot of catalog.snapshots) {
1230
+ console.log(formatSnapshotCatalogLine(snapshot));
1231
+ }
1232
+ return;
1233
+ }
1234
+ if (subcommand === "published-snapshots" || subcommand === "published-snapshot-catalog" || subcommand === "templates" || subcommand === "template-catalog") {
1235
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1236
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1237
+ const query = typeof options.query === "string" && options.query.trim() ? options.query.trim() : typeof options.q === "string" && options.q.trim() ? options.q.trim() : "";
1238
+ const name = typeof options.name === "string" && options.name.trim() ? options.name.trim() : typeof options.templateName === "string" && options.templateName.trim() ? options.templateName.trim() : "";
1239
+ const version = typeof options.version === "string" ? options.version.trim() : "";
1240
+ const tag = typeof options.tag === "string" ? options.tag.trim() : "";
1241
+ const useCase = typeof options.useCase === "string" ? options.useCase.trim() : "";
1242
+ const catalog = await client.publishedSnapshots({
1243
+ ...teamId ? { teamId } : {},
1244
+ ...projectId ? { projectId } : {},
1245
+ ...query ? { q: query } : {},
1246
+ ...name ? { name } : {},
1247
+ ...version ? { version } : {},
1248
+ ...tag ? { tag } : {},
1249
+ ...useCase ? { useCase } : {}
1250
+ });
1251
+ if (catalog.publishedSnapshots.length === 0) {
1252
+ console.log("no published snapshots found");
1253
+ return;
1254
+ }
1255
+ for (const template of catalog.publishedSnapshots) {
1256
+ console.log(formatSandboxTemplateLine(template));
1257
+ }
1258
+ return;
1259
+ }
1260
+ if (await handleSandboxTemplateBuildsCommand(
1261
+ client,
1262
+ subcommand,
1263
+ options,
1264
+ rest
1265
+ ) || await handleSandboxReplayCommand(client, subcommand, options, rest)) {
1266
+ return;
1267
+ }
1268
+ if (subcommand === "run-published-snapshot" || subcommand === "published-snapshot-run" || subcommand === "template-launch" || subcommand === "launch-template") {
1269
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1270
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1271
+ const snapshotId = typeof options.snapshotId === "string" && options.snapshotId.trim() ? options.snapshotId.trim() : typeof options.snapshot === "string" && options.snapshot.trim() ? options.snapshot.trim() : "";
1272
+ const templateName = typeof options.templateName === "string" && options.templateName.trim() ? options.templateName.trim() : typeof options.name === "string" && options.name.trim() ? options.name.trim() : typeof rest[1] === "string" && rest[1].trim() ? rest[1].trim() : "";
1273
+ const version = typeof options.version === "string" ? options.version.trim() : "";
1274
+ const useCase = typeof options.useCase === "string" ? options.useCase.trim() : "";
1275
+ if (!snapshotId && !templateName && !useCase) {
1276
+ throw new Error(
1277
+ "usage: sandbox run-published-snapshot [--snapshot-id <id>|--name <name>|--use-case <id>] [--version <v>]"
1278
+ );
1279
+ }
1280
+ const budgetUsd = typeof options.budgetUsd === "string" && options.budgetUsd.trim() ? options.budgetUsd.trim() : typeof options.budget === "string" && options.budget.trim() ? options.budget.trim() : "";
1281
+ const result = await client.runPublishedSnapshot({
1282
+ ...teamId ? { teamId } : {},
1283
+ ...projectId ? { projectId } : {},
1284
+ ...snapshotId ? { snapshotId } : {},
1285
+ ...templateName ? { templateName } : {},
1286
+ ...version ? { version } : {},
1287
+ ...useCase ? { useCase } : {},
1288
+ ...budgetUsd ? { budget: { maxUsd: budgetUsd } } : {},
1289
+ metadata: {
1290
+ source: "openpond-code-published-snapshot-run"
1291
+ }
1292
+ });
1293
+ console.log(JSON.stringify(result, null, 2));
1294
+ return;
1295
+ }
1296
+ if (subcommand === "snapshot-fork" || subcommand === "fork-snapshot") {
1297
+ const snapshotId = rest[1];
1298
+ if (!snapshotId) {
1299
+ throw new Error("snapshot-fork requires <snapshotId>");
1300
+ }
1301
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1302
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1303
+ const budgetUsd = typeof options.budgetUsd === "string" && options.budgetUsd.trim() ? options.budgetUsd.trim() : typeof options.budget === "string" && options.budget.trim() ? options.budget.trim() : "";
1304
+ const result = await client.forkSnapshot(snapshotId, {
1305
+ ...teamId ? { teamId } : {},
1306
+ ...projectId ? { projectId } : {},
1307
+ ...budgetUsd ? { budget: { maxUsd: budgetUsd } } : {},
1308
+ metadata: {
1309
+ source: "openpond-code-snapshot-fork",
1310
+ templateSnapshotId: snapshotId
1311
+ }
1312
+ });
1313
+ console.log(JSON.stringify(result, null, 2));
1314
+ return;
1315
+ }
1316
+ if (subcommand === "snapshot-create" || subcommand === "create-snapshot") {
1317
+ const sandboxId = rest[1];
1318
+ if (!sandboxId) {
1319
+ throw new Error(
1320
+ "usage: sandbox snapshot-create <sandboxId> --name <name>"
1321
+ );
1322
+ }
1323
+ const result = await client.createSnapshot(
1324
+ sandboxId,
1325
+ buildSnapshotCreateInput(options)
1326
+ );
1327
+ console.log(JSON.stringify(result, null, 2));
1328
+ return;
1329
+ }
1330
+ if (subcommand === "snapshot-validate" || subcommand === "validate-snapshot") {
1331
+ const sandboxId = rest[1];
1332
+ const snapshotId = rest[2];
1333
+ if (!sandboxId || !snapshotId) {
1334
+ throw new Error("snapshot-validate requires <sandboxId> <snapshotId>");
1335
+ }
1336
+ const cleanup = normalizeSnapshotValidationCleanup(options.cleanup);
1337
+ const result = await client.validateSnapshot(sandboxId, snapshotId, {
1338
+ ...cleanup ? { cleanup } : {}
1339
+ });
1340
+ console.log(JSON.stringify(result, null, 2));
1341
+ return;
1342
+ }
1343
+ if (subcommand === "snapshot-publish" || subcommand === "publish-snapshot") {
1344
+ const sandboxId = rest[1];
1345
+ const snapshotId = rest[2];
1346
+ if (!sandboxId || !snapshotId) {
1347
+ throw new Error("snapshot-publish requires <sandboxId> <snapshotId>");
1348
+ }
1349
+ const result = await client.publishSnapshot(sandboxId, snapshotId);
1350
+ console.log(JSON.stringify(result, null, 2));
1351
+ return;
1352
+ }
1353
+ if (subcommand === "integration-connections") {
1354
+ const teamId = typeof options.teamId === "string" ? options.teamId.trim() : "";
1355
+ const projectId = typeof options.projectId === "string" ? options.projectId.trim() : "";
1356
+ const agentId = typeof options.agentId === "string" ? options.agentId.trim() : "";
1357
+ const status = options.status === "active" || options.status === "revoked" || options.status === "error" || options.status === "all" ? options.status : void 0;
1358
+ const result = await client.integrationConnections({
1359
+ ...teamId ? { teamId } : {},
1360
+ ...projectId ? { projectId } : {},
1361
+ ...agentId ? { agentId } : {},
1362
+ ...status ? { status } : {}
1363
+ });
1364
+ console.log(JSON.stringify(result, null, 2));
1365
+ return;
1366
+ }
1367
+ if (subcommand === "create") {
1368
+ const result = await createSandboxFromPlan(
1369
+ client,
1370
+ buildSandboxCreateInput(options)
1371
+ );
1372
+ console.log(
1373
+ JSON.stringify(
1374
+ {
1375
+ sandbox: summarizeSandbox(result.sandbox),
1376
+ ...result.runtime ? { runtime: result.runtime } : {}
1377
+ },
1378
+ null,
1379
+ 2
1380
+ )
1381
+ );
1382
+ return;
1383
+ }
1384
+ if (subcommand === "exec") {
1385
+ const sandboxId = rest[1];
1386
+ const command = (typeof options.command === "string" ? options.command : null) || rest.slice(2).join(" ");
1387
+ if (!sandboxId || !command.trim()) {
1388
+ throw new Error("usage: sandbox exec <sandboxId> --command <command>");
1389
+ }
1390
+ const timeoutSeconds = parseIntegerOption(
1391
+ options.timeoutSeconds,
1392
+ "timeout-seconds"
1393
+ );
1394
+ const result = await client.exec(sandboxId, {
1395
+ command: command.trim(),
1396
+ ...timeoutSeconds !== void 0 ? { timeoutSeconds } : {}
1397
+ });
1398
+ console.log(
1399
+ JSON.stringify(
1400
+ {
1401
+ sandbox: summarizeSandbox(result.sandbox),
1402
+ command: result.command
1403
+ },
1404
+ null,
1405
+ 2
1406
+ )
1407
+ );
1408
+ return;
1409
+ }
1410
+ if (subcommand === "port" || subcommand === "preview") {
1411
+ const sandboxId = rest[1];
1412
+ const port = parseIntegerOption(options.port, "port");
1413
+ if (!sandboxId || port === void 0) {
1414
+ throw new Error("usage: sandbox port <sandboxId> --port <port>");
1415
+ }
1416
+ const label = typeof options.label === "string" ? options.label : void 0;
1417
+ const rawAccess = typeof options.access === "string" ? options.access.trim() : "";
1418
+ if (rawAccess && rawAccess !== "private" && rawAccess !== "public") {
1419
+ throw new Error("sandbox port --access must be private or public");
1420
+ }
1421
+ const access = rawAccess === "public" ? "public" : "private";
1422
+ const customDomain = typeof options.domain === "string" ? options.domain.trim() : "";
1423
+ const authToken = typeof options.authToken === "string" ? options.authToken : "";
1424
+ const authHeader = typeof options.authHeader === "string" ? options.authHeader.trim() : "";
1425
+ const authHeaderValue = typeof options.authHeaderValue === "string" ? options.authHeaderValue : "";
1426
+ if (authToken && (authHeader || authHeaderValue)) {
1427
+ throw new Error(
1428
+ "sandbox port auth options must use either --auth-token or --auth-header with --auth-header-value"
1429
+ );
1430
+ }
1431
+ if (authHeader && !authHeaderValue || !authHeader && authHeaderValue) {
1432
+ throw new Error(
1433
+ "sandbox port custom header auth requires both --auth-header and --auth-header-value"
1434
+ );
1435
+ }
1436
+ const result = await client.openPort(sandboxId, {
1437
+ port,
1438
+ ...label ? { label } : {},
1439
+ access,
1440
+ ...options["auto-start"] || options.autoStart ? { autoStart: true } : {},
1441
+ ...customDomain ? { customDomain } : {},
1442
+ ...authToken ? { authPolicy: { mode: "bearer", token: authToken } } : {},
1443
+ ...authHeader && authHeaderValue ? {
1444
+ authPolicy: {
1445
+ mode: "header",
1446
+ headerName: authHeader,
1447
+ headerValue: authHeaderValue
1448
+ }
1449
+ } : {}
1450
+ });
1451
+ console.log(JSON.stringify(result.preview, null, 2));
1452
+ return;
1453
+ }
1454
+ if (subcommand === "stop") {
1455
+ const sandboxId = rest[1];
1456
+ if (!sandboxId) {
1457
+ throw new Error(
1458
+ "usage: sandbox stop <sandboxId> [--fail-on-unpreserved-changes] [--async]"
1459
+ );
1460
+ }
1461
+ const result = await client.stop(sandboxId, {
1462
+ failOnUnpreservedChanges: parseBooleanOption(
1463
+ options.failOnUnpreservedChanges
1464
+ ),
1465
+ async: parseSandboxAsyncOption(options)
1466
+ });
1467
+ console.log(
1468
+ JSON.stringify(
1469
+ {
1470
+ sandbox: summarizeSandbox(result.sandbox),
1471
+ receipt: result.receipt
1472
+ },
1473
+ null,
1474
+ 2
1475
+ )
1476
+ );
1477
+ return;
1478
+ }
1479
+ if (subcommand === "start") {
1480
+ const sandboxId = rest[1];
1481
+ if (!sandboxId) {
1482
+ throw new Error("usage: sandbox start <sandboxId>");
1483
+ }
1484
+ const result = await client.start(sandboxId);
1485
+ console.log(
1486
+ JSON.stringify(
1487
+ {
1488
+ sandbox: await waitForSandboxCreateReady(client, result.sandbox),
1489
+ receipt: result.receipt
1490
+ },
1491
+ null,
1492
+ 2
1493
+ )
1494
+ );
1495
+ return;
1496
+ }
1497
+ if (subcommand === "delete") {
1498
+ const sandboxId = rest[1];
1499
+ if (!sandboxId) {
1500
+ throw new Error(
1501
+ "usage: sandbox delete <sandboxId> [--fail-on-unpreserved-changes] [--async]"
1502
+ );
1503
+ }
1504
+ const sandbox = await client.delete(sandboxId, {
1505
+ failOnUnpreservedChanges: parseBooleanOption(
1506
+ options.failOnUnpreservedChanges
1507
+ ),
1508
+ async: parseSandboxAsyncOption(options)
1509
+ });
1510
+ console.log(
1511
+ JSON.stringify({ sandbox: summarizeSandbox(sandbox) }, null, 2)
1512
+ );
1513
+ return;
1514
+ }
1515
+ if (subcommand === "receipts") {
1516
+ const sandboxId = rest[1];
1517
+ if (!sandboxId) {
1518
+ throw new Error("usage: sandbox receipts <sandboxId>");
1519
+ }
1520
+ const receipts = await client.receipts(sandboxId);
1521
+ console.log(JSON.stringify({ receipts }, null, 2));
1522
+ return;
1523
+ }
1524
+ if (subcommand === "logs") {
1525
+ const sandboxId = rest[1];
1526
+ if (!sandboxId) {
1527
+ throw new Error("usage: sandbox logs <sandboxId>");
1528
+ }
1529
+ const logs = await client.logs(sandboxId);
1530
+ for (const line of logs) {
1531
+ console.log(line);
1532
+ }
1533
+ return;
1534
+ }
1535
+ if (await handleSandboxProcessCommand(client, subcommand, options, rest) || await handleSandboxFilesCommand(client, subcommand, options, rest) || await handleSandboxGitCommand(client, subcommand, options, rest)) {
1536
+ return;
1537
+ }
1538
+ if (subcommand === "billing") {
1539
+ const sandboxId = rest[1];
1540
+ if (!sandboxId) {
1541
+ throw new Error("usage: sandbox billing <sandboxId>");
1542
+ }
1543
+ const result = await client.billing(sandboxId);
1544
+ console.log(
1545
+ JSON.stringify(
1546
+ {
1547
+ sandbox: summarizeSandbox(result.sandbox),
1548
+ billing: result.billing
1549
+ },
1550
+ null,
1551
+ 2
1552
+ )
1553
+ );
1554
+ return;
1555
+ }
1556
+ if (subcommand === "integration-leases") {
1557
+ const sandboxId = rest[1];
1558
+ if (!sandboxId) {
1559
+ throw new Error("usage: sandbox integration-leases <sandboxId>");
1560
+ }
1561
+ const result = await client.integrationLeases(sandboxId);
1562
+ console.log(
1563
+ JSON.stringify(
1564
+ {
1565
+ sandbox: summarizeSandbox(result.sandbox),
1566
+ integrationLeases: result.integrationLeases
1567
+ },
1568
+ null,
1569
+ 2
1570
+ )
1571
+ );
1572
+ return;
1573
+ }
1574
+ if (subcommand === "integration-attach") {
1575
+ const sandboxId = rest[1];
1576
+ if (!sandboxId) {
1577
+ throw new Error(
1578
+ "usage: sandbox integration-attach <sandboxId> --integration-connection <id> --integration-capabilities <csv>"
1579
+ );
1580
+ }
1581
+ const result = await client.attachIntegrationConnection(
1582
+ sandboxId,
1583
+ buildSandboxIntegrationAttachInput(options)
1584
+ );
1585
+ console.log(
1586
+ JSON.stringify(
1587
+ {
1588
+ sandbox: summarizeSandbox(result.sandbox),
1589
+ integrationLeases: result.integrationLeases
1590
+ },
1591
+ null,
1592
+ 2
1593
+ )
1594
+ );
1595
+ return;
1596
+ }
1597
+ if (subcommand === "integration-remove") {
1598
+ const sandboxId = rest[1];
1599
+ const leaseId = typeof options.leaseId === "string" ? options.leaseId.trim() : "";
1600
+ if (!sandboxId || !leaseId) {
1601
+ throw new Error(
1602
+ "usage: sandbox integration-remove <sandboxId> --lease-id <id>"
1603
+ );
1604
+ }
1605
+ const result = await client.removeIntegrationLease(sandboxId, leaseId);
1606
+ console.log(
1607
+ JSON.stringify(
1608
+ {
1609
+ sandbox: summarizeSandbox(result.sandbox),
1610
+ integrationLeases: result.integrationLeases
1611
+ },
1612
+ null,
1613
+ 2
1614
+ )
1615
+ );
1616
+ return;
1617
+ }
1618
+ if (subcommand === "smoke") {
1619
+ const repo = typeof options.repo === "string" ? options.repo.trim() : void 0;
1620
+ const budgetUsd = typeof options.budgetUsd === "string" ? options.budgetUsd.trim() : typeof options.budget === "string" ? options.budget.trim() : void 0;
1621
+ const keep = parseBooleanOption(options.keep);
1622
+ const preview = options.preview !== void 0 ? parseBooleanOption(options.preview) : !parseBooleanOption(options.noPreview);
1623
+ const snapshot = parseBooleanOption(options.snapshot);
1624
+ const fork = parseBooleanOption(options.fork);
1625
+ const smokeOptions = {
1626
+ ...repo ? { repo } : {},
1627
+ ...budgetUsd ? { budgetUsd } : {},
1628
+ keep,
1629
+ preview,
1630
+ snapshot,
1631
+ fork
1632
+ };
1633
+ if (typeof options.expectedMppMode === "string" && options.expectedMppMode.trim()) {
1634
+ smokeOptions.expectedMppMode = options.expectedMppMode.trim();
1635
+ }
1636
+ const cpu = parseNumberOption(options.cpu, "cpu");
1637
+ const memoryGb = parseNumberOption(options.memoryGb, "memory-gb");
1638
+ const diskGb = parseNumberOption(options.diskGb, "disk-gb");
1639
+ if (cpu !== void 0) smokeOptions.cpu = cpu;
1640
+ if (memoryGb !== void 0) smokeOptions.memoryGb = memoryGb;
1641
+ if (diskGb !== void 0) smokeOptions.diskGb = diskGb;
1642
+ const summary = await client.smoke(smokeOptions);
1643
+ console.log(JSON.stringify(summary, null, 2));
1644
+ return;
1645
+ }
1646
+ throw new Error(
1647
+ "usage: sandbox <list|mcp-config|runtime-list|runtime-get|runtime-events|runtime-status|runtime-event|runtime-preserve-source|pricing|costs|secrets|secret-create|secret-rotate|secret-attach|secret-revoke|secret-delete|snapshots|published-snapshots|run-published-snapshot|snapshot-fork|snapshot-validate|snapshot-publish|create|exec|port|preview|stop|start|delete|receipts|logs|billing|process-start|process-list|process-get|process-stop|process-stream|pty-start|pty-list|pty-get|pty-write|pty-stop|pty-stream|upload-file|download-file|list-files|search-files|delete-file|stat-file|mkdir|move-file|git-status|git-diff|git-export-patch|git-branch|git-commit|git-pull|git-push|smoke> [args]"
1648
+ );
1649
+ }
1650
+ export {
1651
+ runSandboxCommand
1652
+ };