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,1663 @@
1
+ import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
2
+ import {
3
+ materializeSourceUploadFile,
4
+ readSourceUploadCache,
5
+ writeSourceUploadCache
6
+ } from "./chunk-I6HN3ZGW.js";
7
+ import {
8
+ CreatePipelineRequestSchema
9
+ } from "./chunk-VQX33YAG.js";
10
+ import {
11
+ formatSandboxTemplateDiagnostics,
12
+ validateSandboxTemplateYaml
13
+ } from "./chunk-BYAPLT37.js";
14
+ import {
15
+ yaml
16
+ } from "./chunk-WYDVQOBL.js";
17
+ import {
18
+ parseSandboxRuntimePromotionPolicyOption,
19
+ parseSandboxWorkflowModeOption,
20
+ runCommand
21
+ } from "./chunk-XSAXENQD.js";
22
+ import {
23
+ optionString,
24
+ optionalJsonObject,
25
+ parseBooleanOption,
26
+ parseCsvOption,
27
+ parseIntegerOption,
28
+ requiredTeamId
29
+ } from "./chunk-3Y4EL3P6.js";
30
+
31
+ // src/cli/agent-sdk-command.ts
32
+ import { existsSync, readFileSync } from "node:fs";
33
+ import { createRequire } from "node:module";
34
+ import path from "node:path";
35
+ function resolveLocalAgentSdkCommand(cwd) {
36
+ const packageDistCli = path.join(
37
+ cwd,
38
+ "node_modules",
39
+ "openpond-agent-sdk",
40
+ "dist",
41
+ "cli.js"
42
+ );
43
+ if (existsSync(packageDistCli)) return { command: process.execPath, args: [packageDistCli] };
44
+ const localBin = path.join(cwd, "node_modules", ".bin", "openpond-agent");
45
+ if (existsSync(localBin)) return { command: localBin, args: [] };
46
+ const packageCli = path.join(
47
+ cwd,
48
+ "node_modules",
49
+ "openpond-agent-sdk",
50
+ "src",
51
+ "cli.ts"
52
+ );
53
+ if (existsSync(packageCli)) {
54
+ return nodeTypescriptCommand(path.dirname(path.dirname(packageCli)), packageCli);
55
+ }
56
+ const packageDependencyCli = resolveAgentSdkDependencyCli(cwd);
57
+ if (packageDependencyCli) return packageDependencyCli;
58
+ return { command: "openpond-agent", args: [] };
59
+ }
60
+ function resolveAgentSdkDependencyCli(cwd) {
61
+ const packageJsonPath = path.join(cwd, "package.json");
62
+ if (!existsSync(packageJsonPath)) return null;
63
+ try {
64
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
65
+ const versionSpec = packageJson.dependencies?.["openpond-agent-sdk"] ?? packageJson.devDependencies?.["openpond-agent-sdk"] ?? packageJson.peerDependencies?.["openpond-agent-sdk"];
66
+ if (!versionSpec?.startsWith("file:")) return null;
67
+ const packageRoot = path.resolve(cwd, versionSpec.slice("file:".length));
68
+ const sourceCli = path.join(packageRoot, "src", "cli.ts");
69
+ if (existsSync(sourceCli)) return nodeTypescriptCommand(packageRoot, sourceCli);
70
+ const distCli = path.join(packageRoot, "dist", "cli.js");
71
+ if (existsSync(distCli)) return { command: process.execPath, args: [distCli] };
72
+ } catch {
73
+ return null;
74
+ }
75
+ return null;
76
+ }
77
+ function nodeTypescriptCommand(packageRoot, sourceCli) {
78
+ const tsxCli = createRequire(path.join(packageRoot, "package.json")).resolve("tsx/cli");
79
+ return { command: process.execPath, args: [tsxCli, sourceCli] };
80
+ }
81
+
82
+ // src/cli/project-source-upload.ts
83
+ import { Buffer } from "node:buffer";
84
+ import { createHash } from "node:crypto";
85
+ import { existsSync as existsSync2, promises as fs, readFileSync as readFileSync2, statSync } from "node:fs";
86
+ import { tmpdir } from "node:os";
87
+ import path2 from "node:path";
88
+ import { gunzipSync } from "node:zlib";
89
+ var PROJECT_SOURCE_UPLOAD_MAX_FILES = 1500;
90
+ var PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES = 8 * 1024 * 1024;
91
+ var PROJECT_SOURCE_UPLOAD_MAX_BYTES = 100 * 1024 * 1024;
92
+ var PROJECT_SOURCE_UPLOAD_CONCURRENCY = 8;
93
+ var PROJECT_SOURCE_UPLOAD_LIMITS = {
94
+ maxFiles: PROJECT_SOURCE_UPLOAD_MAX_FILES,
95
+ maxFileBytes: PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES,
96
+ maxTotalBytes: PROJECT_SOURCE_UPLOAD_MAX_BYTES,
97
+ concurrency: PROJECT_SOURCE_UPLOAD_CONCURRENCY
98
+ };
99
+ var PROJECT_SOURCE_UPLOAD_TRANSPORT = {
100
+ mode: "single_json_payload",
101
+ chunkingSupported: false
102
+ };
103
+ var OPENPOND_PNPM_PACKAGE_MANAGER = "pnpm@11.13.0";
104
+ var AGENT_SDK_SOURCE_UPLOAD_METADATA_PATH = ".openpond/source-upload-metadata.json";
105
+ var AGENT_SDK_VENDOR_TARBALL_PATH = ".openpond/vendor/openpond-agent-sdk.tgz";
106
+ var AGENT_SDK_VENDOR_NPM_DEPENDENCY_DIR = ".openpond/vendor/npm";
107
+ var AGENT_SDK_MATERIALIZED_DEPENDENCY_SPEC = `file:${AGENT_SDK_VENDOR_TARBALL_PATH}`;
108
+ var AGENT_SDK_SYNTHESIZED_OPENPOND_YAML_SENTINEL = "# openpond-agent-sdk-source-upload: synthesized-openpond-yaml";
109
+ var AGENT_SDK_GENERATED_SKILLS_DIR = ".openpond/skills";
110
+ var AGENT_SDK_GENERATED_ARTIFACTS = [
111
+ ".openpond/agent-inspect.json",
112
+ ".openpond/agent-manifest.json",
113
+ ".openpond/action-registry.json",
114
+ ".openpond/openpond-manifest.preview.yaml",
115
+ ".openpond/runtime-bridge.mjs",
116
+ ".openpond/validator-report.md"
117
+ ];
118
+ function isSafeProjectSourcePath(filePath) {
119
+ return filePath.length > 0 && !filePath.includes("\0") && !path2.isAbsolute(filePath) && !filePath.split(/[\\/]+/).some((part) => !part || part === "." || part === "..");
120
+ }
121
+ function shouldSkipProjectSourcePath(filePath) {
122
+ return filePath.split(/[\\/]+/).some((segment) => {
123
+ const lower = segment.toLowerCase();
124
+ return lower === ".git" || lower === ".openpond" || lower === "node_modules" || lower === ".next" || lower === ".turbo" || lower.startsWith(".env");
125
+ });
126
+ }
127
+ async function resolveProjectSourceUploadBranch(projectPath, options) {
128
+ const explicit = optionString(options, "branch");
129
+ if (explicit) return explicit;
130
+ const branch = await runCommand("git", ["branch", "--show-current"], {
131
+ cwd: projectPath
132
+ });
133
+ if (branch.code !== 0) return null;
134
+ return branch.stdout.trim() || null;
135
+ }
136
+ async function collectProjectSourceUploadEntries(projectPath) {
137
+ const sourcePaths = await collectProjectSourceUploadPaths(projectPath);
138
+ if (sourcePaths.length === 0) {
139
+ throw new Error("no source files found to upload");
140
+ }
141
+ if (sourcePaths.length > PROJECT_SOURCE_UPLOAD_MAX_FILES) {
142
+ throw new Error(
143
+ `too many source files to upload: ${sourcePaths.length} > ${PROJECT_SOURCE_UPLOAD_MAX_FILES}`
144
+ );
145
+ }
146
+ const sortedSourcePaths = sourcePaths.sort();
147
+ const filesToUpload = (await mapWithConcurrency(sortedSourcePaths, PROJECT_SOURCE_UPLOAD_CONCURRENCY, async (sourcePath) => {
148
+ const absolutePath = path2.resolve(projectPath, sourcePath);
149
+ const relative = path2.relative(projectPath, absolutePath);
150
+ if (relative.startsWith("..") || path2.isAbsolute(relative)) {
151
+ throw new Error(`source path escapes project: ${sourcePath}`);
152
+ }
153
+ const stat = await fs.stat(absolutePath);
154
+ if (!stat.isFile()) return null;
155
+ if (stat.size > PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES) {
156
+ throw new Error(
157
+ `source file is too large: ${sourcePath} (${stat.size} bytes)`
158
+ );
159
+ }
160
+ return {
161
+ path: sourcePath.replace(/\\/g, "/"),
162
+ absolutePath,
163
+ size: stat.size,
164
+ mtimeMs: Math.trunc(stat.mtimeMs),
165
+ ctimeMs: Math.trunc(stat.ctimeMs)
166
+ };
167
+ })).filter((file) => file !== null);
168
+ let totalBytes = 0;
169
+ for (const file of filesToUpload) {
170
+ totalBytes += file.size;
171
+ if (totalBytes > PROJECT_SOURCE_UPLOAD_MAX_BYTES) {
172
+ throw new Error(
173
+ `source upload is too large: ${totalBytes} > ${PROJECT_SOURCE_UPLOAD_MAX_BYTES}`
174
+ );
175
+ }
176
+ }
177
+ const cache = await readSourceUploadCache(projectPath);
178
+ const materialized = await mapWithConcurrency(
179
+ filesToUpload,
180
+ PROJECT_SOURCE_UPLOAD_CONCURRENCY,
181
+ async (file) => materializeSourceUploadFile(file, cache)
182
+ );
183
+ await writeSourceUploadCache(projectPath, materialized).catch(() => {
184
+ });
185
+ const entries = materialized.map((item) => item.entry);
186
+ return {
187
+ entries,
188
+ fileCount: entries.length,
189
+ totalBytes,
190
+ limits: PROJECT_SOURCE_UPLOAD_LIMITS,
191
+ transport: PROJECT_SOURCE_UPLOAD_TRANSPORT
192
+ };
193
+ }
194
+ async function mapWithConcurrency(items, concurrency, mapper) {
195
+ const results = new Array(items.length);
196
+ let nextIndex = 0;
197
+ const workerCount = Math.max(1, Math.min(concurrency, items.length));
198
+ await Promise.all(
199
+ Array.from({ length: workerCount }, async () => {
200
+ while (nextIndex < items.length) {
201
+ const index = nextIndex;
202
+ nextIndex += 1;
203
+ results[index] = await mapper(items[index], index);
204
+ }
205
+ })
206
+ );
207
+ return results;
208
+ }
209
+ async function collectProjectSourceUploadPaths(projectPath) {
210
+ const files = await runCommand(
211
+ "git",
212
+ ["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
213
+ { cwd: projectPath }
214
+ );
215
+ if (files.code !== 0) {
216
+ if (existsSync2(path2.join(projectPath, ".git"))) {
217
+ throw new Error(
218
+ `git ls-files failed: ${files.stderr.trim() || files.stdout.trim() || "unknown error"}`
219
+ );
220
+ }
221
+ return collectFilesystemProjectSourceUploadPaths(projectPath);
222
+ }
223
+ return files.stdout.split("\0").map((filePath) => filePath.trim()).filter(Boolean).filter((filePath) => {
224
+ const normalized = filePath.replace(/\\/g, "/");
225
+ return isSafeProjectSourcePath(normalized) && !shouldSkipProjectSourcePath(normalized);
226
+ });
227
+ }
228
+ async function collectFilesystemProjectSourceUploadPaths(projectPath) {
229
+ const sourcePaths = [];
230
+ async function visit(relativeDir) {
231
+ const absoluteDir = path2.join(projectPath, relativeDir);
232
+ const entries = await fs.readdir(absoluteDir, { withFileTypes: true });
233
+ for (const entry of entries) {
234
+ const relativePath = path2.join(relativeDir, entry.name).replace(/\\/g, "/");
235
+ if (!isSafeProjectSourcePath(relativePath) || shouldSkipProjectSourcePath(relativePath)) {
236
+ continue;
237
+ }
238
+ if (entry.isDirectory()) {
239
+ await visit(relativePath);
240
+ continue;
241
+ }
242
+ if (entry.isFile()) sourcePaths.push(relativePath);
243
+ }
244
+ }
245
+ try {
246
+ await visit("");
247
+ } catch (error) {
248
+ throw new Error(
249
+ `filesystem source scan failed: ${error instanceof Error ? error.message : String(error)}`
250
+ );
251
+ }
252
+ return sourcePaths;
253
+ }
254
+ async function collectAgentSdkProjectSourceUploadEntries(projectPath, existingEntries) {
255
+ if (!isAgentSdkProject(projectPath)) {
256
+ return {
257
+ entries: [],
258
+ generatedManifestPath: null,
259
+ synthesizedOpenPondYaml: false,
260
+ uploadMetadataPath: null,
261
+ uploadMetadata: null,
262
+ uploadMetadataHash: null
263
+ };
264
+ }
265
+ await runAgentSdkProjectCheck(projectPath, "build");
266
+ await runAgentSdkProjectCheck(projectPath, "validate");
267
+ await runAgentSdkProjectCheck(projectPath, "eval");
268
+ const packageJson = readAgentSdkProjectPackageJson(projectPath);
269
+ const materializedDependency = await buildAgentSdkMaterializedDependency(
270
+ projectPath,
271
+ packageJson
272
+ );
273
+ const manifestPath = ".openpond/openpond-manifest.preview.yaml";
274
+ const manifestSource = await fs.readFile(path2.join(projectPath, manifestPath), "utf8");
275
+ const openPondYamlSource = sanitizeAgentSdkRuntimeManifestForOpenPondYaml(
276
+ manifestSource,
277
+ materializedDependency?.dependencySetup ?? null
278
+ );
279
+ const manifestResult = validateSandboxTemplateYaml(openPondYamlSource);
280
+ if (!manifestResult.ok) {
281
+ throw new Error(
282
+ `generated ${manifestPath} failed sandbox-template validation after openpond.yaml sanitization:
283
+ ${formatSandboxTemplateDiagnostics(
284
+ manifestResult.diagnostics
285
+ )}`
286
+ );
287
+ }
288
+ const entries = [];
289
+ if (materializedDependency?.rewrittenPackageJson) {
290
+ entries.push(
291
+ projectSourceUploadTextEntry(
292
+ "package.json",
293
+ `${JSON.stringify(materializedDependency.rewrittenPackageJson, null, 2)}
294
+ `
295
+ )
296
+ );
297
+ }
298
+ if (materializedDependency?.pnpmWorkspaceSource) {
299
+ entries.push(
300
+ projectSourceUploadTextEntry(
301
+ "pnpm-workspace.yaml",
302
+ materializedDependency.pnpmWorkspaceSource
303
+ )
304
+ );
305
+ }
306
+ for (const tarball of materializedDependency?.tarballs ?? []) {
307
+ entries.push(
308
+ projectSourceUploadBufferEntry(tarball.path, tarball.contents)
309
+ );
310
+ }
311
+ const generatedArtifactPaths = await collectAgentSdkGeneratedArtifactPaths(projectPath);
312
+ for (const artifactPath of generatedArtifactPaths) {
313
+ entries.push(await projectSourceUploadFileEntry(projectPath, artifactPath));
314
+ }
315
+ const hasAuthoredOpenPondYaml = existingEntries.some((entry) => entry.path === "openpond.yaml") || existsSync2(path2.join(projectPath, "openpond.yaml"));
316
+ if (!hasAuthoredOpenPondYaml) {
317
+ entries.push(projectSourceUploadTextEntry("openpond.yaml", openPondYamlSource));
318
+ } else {
319
+ const authoredSource = await fs.readFile(path2.join(projectPath, "openpond.yaml"), "utf8");
320
+ const authoredResult = validateSandboxTemplateYaml(authoredSource);
321
+ if (!authoredResult.ok) {
322
+ throw new Error(
323
+ `authored openpond.yaml failed sandbox-template validation:
324
+ ${formatSandboxTemplateDiagnostics(
325
+ authoredResult.diagnostics
326
+ )}`
327
+ );
328
+ }
329
+ }
330
+ const uploadMetadata = await buildAgentSdkSourceUploadMetadata(projectPath, {
331
+ packageJson,
332
+ generatedManifestPath: manifestPath,
333
+ generatedArtifactPaths,
334
+ synthesizedOpenPondYaml: !hasAuthoredOpenPondYaml,
335
+ openPondYamlSource,
336
+ dependencySetup: materializedDependency?.dependencySetup ?? null
337
+ });
338
+ const uploadMetadataSource = `${JSON.stringify(uploadMetadata, null, 2)}
339
+ `;
340
+ const uploadMetadataHash = {
341
+ sha256: sha256Hex(Buffer.from(uploadMetadataSource, "utf8")),
342
+ sizeBytes: Buffer.byteLength(uploadMetadataSource, "utf8")
343
+ };
344
+ entries.push(
345
+ projectSourceUploadTextEntry(
346
+ AGENT_SDK_SOURCE_UPLOAD_METADATA_PATH,
347
+ uploadMetadataSource
348
+ )
349
+ );
350
+ return {
351
+ entries,
352
+ generatedManifestPath: manifestPath,
353
+ synthesizedOpenPondYaml: !hasAuthoredOpenPondYaml,
354
+ uploadMetadataPath: AGENT_SDK_SOURCE_UPLOAD_METADATA_PATH,
355
+ uploadMetadata,
356
+ uploadMetadataHash
357
+ };
358
+ }
359
+ async function buildAgentSdkSourceUploadMetadata(projectPath, params) {
360
+ const packageManager = detectAgentSdkPackageManager(projectPath, params.packageJson);
361
+ const commandHints = buildAgentSdkCommandHints(params.packageJson, packageManager);
362
+ const setupRequirements = await collectAgentSdkSourceSetupRequirements(projectPath);
363
+ const artifactHashes = {};
364
+ for (const artifactPath of params.generatedArtifactPaths) {
365
+ const absolutePath = path2.join(projectPath, artifactPath);
366
+ if (!existsSync2(absolutePath)) continue;
367
+ const contents = await fs.readFile(absolutePath);
368
+ artifactHashes[artifactPath] = {
369
+ sha256: sha256Hex(contents),
370
+ sizeBytes: contents.byteLength
371
+ };
372
+ }
373
+ artifactHashes["openpond.yaml"] = {
374
+ sha256: sha256Hex(Buffer.from(params.openPondYamlSource, "utf8")),
375
+ sizeBytes: Buffer.byteLength(params.openPondYamlSource, "utf8")
376
+ };
377
+ return {
378
+ schema: "openpond.agent.source_upload.v1",
379
+ sourceTreeMode: "typescript_agent_sdk",
380
+ packageManager,
381
+ sdk: {
382
+ packageName: "openpond-agent-sdk",
383
+ versionSpec: readOpenPondAgentSdkVersionSpec(params.packageJson)
384
+ },
385
+ commands: commandHints,
386
+ ...params.dependencySetup ? { dependencySetup: params.dependencySetup } : {},
387
+ ...setupRequirements.length > 0 ? { setupRequirements } : {},
388
+ generatedManifestPath: params.generatedManifestPath,
389
+ synthesizedOpenPondYaml: params.synthesizedOpenPondYaml,
390
+ openPondYamlMode: params.synthesizedOpenPondYaml ? "synthesized" : "authored",
391
+ artifactHashes
392
+ };
393
+ }
394
+ async function collectAgentSdkGeneratedArtifactPaths(projectPath) {
395
+ const generatedArtifacts = /* @__PURE__ */ new Set();
396
+ for (const artifactPath of AGENT_SDK_GENERATED_ARTIFACTS) {
397
+ if (existsSync2(path2.join(projectPath, artifactPath))) {
398
+ generatedArtifacts.add(artifactPath);
399
+ }
400
+ }
401
+ for (const skillArtifactPath of await collectAgentSdkGeneratedSkillArtifactPaths(projectPath)) {
402
+ generatedArtifacts.add(skillArtifactPath);
403
+ }
404
+ return Array.from(generatedArtifacts).sort((left, right) => left.localeCompare(right));
405
+ }
406
+ async function collectAgentSdkGeneratedSkillArtifactPaths(projectPath) {
407
+ const skillsRoot = path2.join(projectPath, AGENT_SDK_GENERATED_SKILLS_DIR);
408
+ if (!existsSync2(skillsRoot)) return [];
409
+ const results = [];
410
+ async function visit(relativeDir) {
411
+ const absoluteDir = path2.join(projectPath, relativeDir);
412
+ const entries = await fs.readdir(absoluteDir, { withFileTypes: true });
413
+ entries.sort((left, right) => left.name.localeCompare(right.name));
414
+ for (const entry of entries) {
415
+ const relativePath = path2.join(relativeDir, entry.name).replace(/\\/g, "/");
416
+ if (!isSafeProjectSourcePath(relativePath)) continue;
417
+ if (entry.isDirectory()) {
418
+ await visit(relativePath);
419
+ continue;
420
+ }
421
+ if (entry.isFile()) results.push(relativePath);
422
+ }
423
+ }
424
+ await visit(AGENT_SDK_GENERATED_SKILLS_DIR);
425
+ return results;
426
+ }
427
+ async function collectAgentSdkSourceSetupRequirements(projectPath) {
428
+ const requirements = [];
429
+ const seen = /* @__PURE__ */ new Set();
430
+ for (const relativePath of [
431
+ ".openpond/action-registry.json",
432
+ ".openpond/agent-manifest.json"
433
+ ]) {
434
+ const payload = await readJsonFileIfExists(path2.join(projectPath, relativePath));
435
+ if (!payload) continue;
436
+ for (const actionRecord of [
437
+ ...recordArray(payload.actions),
438
+ ...recordArray(payload.actionCatalog)
439
+ ]) {
440
+ const actionId = text(actionRecord.id) ?? text(actionRecord.name);
441
+ const actionName = text(actionRecord.name) ?? actionId;
442
+ if (!actionId && !actionName) continue;
443
+ for (const setupRecord of recordArray(actionRecord.setupRequirements)) {
444
+ const setupRequirement = { ...setupRecord };
445
+ if (actionId) setupRequirement.actionId = actionId;
446
+ if (actionName && actionName !== actionId) setupRequirement.actionName = actionName;
447
+ const key = setupRequirementIdentity(setupRequirement);
448
+ if (seen.has(key)) continue;
449
+ seen.add(key);
450
+ requirements.push(setupRequirement);
451
+ }
452
+ }
453
+ }
454
+ return requirements;
455
+ }
456
+ async function readJsonFileIfExists(filePath) {
457
+ try {
458
+ const parsed = JSON.parse(await fs.readFile(filePath, "utf8"));
459
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
460
+ } catch {
461
+ return null;
462
+ }
463
+ }
464
+ function setupRequirementIdentity(record) {
465
+ return [
466
+ text(record.actionId) ?? "",
467
+ text(record.actionName) ?? "",
468
+ text(record.kind) ?? text(record.type) ?? "",
469
+ text(record.label) ?? text(record.name) ?? text(record.key) ?? text(record.provider) ?? text(record.tool) ?? text(record.command) ?? text(record.packageName) ?? ""
470
+ ].join(":");
471
+ }
472
+ function readAgentSdkProjectPackageJson(projectPath) {
473
+ const packageJsonPath = path2.join(projectPath, "package.json");
474
+ return JSON.parse(readFileSyncUtf8(packageJsonPath));
475
+ }
476
+ function detectAgentSdkPackageManager(projectPath, packageJson) {
477
+ const packageManager = packageJson.packageManager;
478
+ if (typeof packageManager === "string") {
479
+ const name = packageManager.split("@")[0];
480
+ if (name === "bun" || name === "npm" || name === "pnpm" || name === "yarn") {
481
+ return name;
482
+ }
483
+ }
484
+ if (existsSync2(path2.join(projectPath, "bun.lock")) || existsSync2(path2.join(projectPath, "bun.lockb"))) {
485
+ return "bun";
486
+ }
487
+ if (existsSync2(path2.join(projectPath, "pnpm-lock.yaml"))) return "pnpm";
488
+ if (existsSync2(path2.join(projectPath, "yarn.lock"))) return "yarn";
489
+ if (existsSync2(path2.join(projectPath, "package-lock.json")) || existsSync2(path2.join(projectPath, "npm-shrinkwrap.json"))) {
490
+ return "npm";
491
+ }
492
+ return "unknown";
493
+ }
494
+ function buildAgentSdkCommandHints(packageJson, packageManager) {
495
+ return {
496
+ inspect: buildAgentSdkCommandHint(
497
+ packageJson,
498
+ packageManager,
499
+ "agent:inspect",
500
+ "openpond-agent inspect --json"
501
+ ),
502
+ build: buildAgentSdkCommandHint(
503
+ packageJson,
504
+ packageManager,
505
+ "agent:build",
506
+ "openpond-agent build"
507
+ ),
508
+ validate: buildAgentSdkCommandHint(
509
+ packageJson,
510
+ packageManager,
511
+ "agent:validate",
512
+ "openpond-agent validate"
513
+ ),
514
+ eval: buildAgentSdkCommandHint(
515
+ packageJson,
516
+ packageManager,
517
+ "agent:eval",
518
+ "openpond-agent eval"
519
+ )
520
+ };
521
+ }
522
+ function buildAgentSdkCommandHint(packageJson, packageManager, scriptName, fallback) {
523
+ const scripts = packageJson.scripts;
524
+ const hasScript = scripts && typeof scripts === "object" && !Array.isArray(scripts) && typeof scripts[scriptName] === "string";
525
+ if (!hasScript) return fallback;
526
+ if (packageManager === "pnpm") return `pnpm run ${scriptName}`;
527
+ if (packageManager === "yarn") return `yarn ${scriptName}`;
528
+ if (packageManager === "npm") return `npm run ${scriptName}`;
529
+ if (packageManager === "bun") return `bun run ${scriptName}`;
530
+ return `pnpm run ${scriptName}`;
531
+ }
532
+ function readOpenPondAgentSdkVersionSpec(packageJson) {
533
+ for (const key of ["dependencies", "devDependencies", "peerDependencies"]) {
534
+ const dependencies = packageJson[key];
535
+ if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)) {
536
+ continue;
537
+ }
538
+ const value = dependencies["openpond-agent-sdk"];
539
+ if (typeof value === "string" && value.trim()) return value.trim();
540
+ }
541
+ return null;
542
+ }
543
+ async function buildAgentSdkMaterializedDependency(projectPath, packageJson) {
544
+ const sdkSource = resolveLocalOpenPondAgentSdkMaterializationSource(
545
+ projectPath,
546
+ packageJson
547
+ );
548
+ if (!sdkSource) return null;
549
+ const tempDir = await fs.mkdtemp(path2.join(tmpdir(), "openpond-agent-sdk-pack-"));
550
+ try {
551
+ const sdkContents = sdkSource.kind === "package_root" ? await packOpenPondAgentSdkPackageRoot(sdkSource.packageRoot, tempDir) : sdkSource.tarballContents;
552
+ const sdkDependencyTarballs = await packAgentSdkRuntimeDependencyTarballs({
553
+ sdkPackageJson: sdkSource.packageJson,
554
+ dependencyBaseDir: sdkSource.dependencyBaseDir,
555
+ tempDir
556
+ });
557
+ const packageManager = detectAgentSdkPackageManager(projectPath, packageJson);
558
+ const rewrittenPackageJson = rewriteAgentSdkPackageJsonForMaterialization(
559
+ packageJson,
560
+ sdkDependencyTarballs,
561
+ packageManager
562
+ );
563
+ const pnpmWorkspaceSource = packageManager === "pnpm" || packageManager === "unknown" ? buildAgentSdkPnpmWorkspaceSource(projectPath, sdkDependencyTarballs) : null;
564
+ const installCommand = agentSdkDependencyInstallCommand(packageManager);
565
+ const sdkPackage = {
566
+ packageName: "openpond-agent-sdk",
567
+ source: "uploaded_tarball",
568
+ path: AGENT_SDK_VENDOR_TARBALL_PATH,
569
+ sha256: sha256Hex(sdkContents),
570
+ sizeBytes: sdkContents.byteLength
571
+ };
572
+ return {
573
+ rewrittenPackageJson,
574
+ pnpmWorkspaceSource,
575
+ tarballs: [
576
+ {
577
+ ...sdkPackage,
578
+ contents: sdkContents
579
+ },
580
+ ...sdkDependencyTarballs
581
+ ],
582
+ dependencySetup: {
583
+ required: true,
584
+ packageManager,
585
+ installCommand,
586
+ commands: [installCommand],
587
+ packageJsonPath: "package.json",
588
+ expectedBinaryPath: "node_modules/.bin/openpond-agent",
589
+ generatedArtifactDirectory: ".openpond",
590
+ sdkPackage,
591
+ dependencyPackages: sdkDependencyTarballs.map((tarball) => ({
592
+ packageName: tarball.packageName,
593
+ source: tarball.source,
594
+ versionSpec: tarball.versionSpec,
595
+ path: tarball.path,
596
+ sha256: tarball.sha256,
597
+ sizeBytes: tarball.sizeBytes
598
+ }))
599
+ }
600
+ };
601
+ } finally {
602
+ await fs.rm(tempDir, { recursive: true, force: true });
603
+ }
604
+ }
605
+ async function packOpenPondAgentSdkPackageRoot(sdkPackageRoot, tempDir) {
606
+ const pack = await runCommand(
607
+ "npm",
608
+ ["pack", "--silent", "--pack-destination", tempDir, sdkPackageRoot],
609
+ { cwd: sdkPackageRoot }
610
+ );
611
+ if (pack.code !== 0) {
612
+ const details = [pack.stderr.trim(), pack.stdout.trim()].filter(Boolean).join("\n");
613
+ throw new Error(
614
+ `failed to pack openpond-agent-sdk for source upload${details ? `:
615
+ ${details}` : ""}`
616
+ );
617
+ }
618
+ const tarballName = pack.stdout.trim().split(/\r?\n/).filter(Boolean).pop();
619
+ if (!tarballName) {
620
+ throw new Error("failed to pack openpond-agent-sdk for source upload: npm pack did not return a tarball name");
621
+ }
622
+ return fs.readFile(path2.join(tempDir, tarballName));
623
+ }
624
+ async function packAgentSdkRuntimeDependencyTarballs(params) {
625
+ const dependencies = recordStringMap(params.sdkPackageJson.dependencies);
626
+ const pending = Object.entries(dependencies).sort(([left], [right]) => left.localeCompare(right)).map(([packageName, versionSpec]) => ({ packageName, versionSpec }));
627
+ const seen = /* @__PURE__ */ new Set();
628
+ const tarballs = [];
629
+ while (pending.length > 0) {
630
+ const { packageName, versionSpec } = pending.shift();
631
+ if (seen.has(packageName)) continue;
632
+ seen.add(packageName);
633
+ const packTarget = npmPackTargetForDependency({
634
+ packageName,
635
+ versionSpec,
636
+ dependencyBaseDir: params.dependencyBaseDir
637
+ });
638
+ const pack = await runCommand(
639
+ "npm",
640
+ ["pack", "--silent", "--pack-destination", params.tempDir, packTarget],
641
+ { cwd: params.dependencyBaseDir }
642
+ );
643
+ if (pack.code !== 0) {
644
+ const details = [pack.stderr.trim(), pack.stdout.trim()].filter(Boolean).join("\n");
645
+ throw new Error(
646
+ `failed to pack openpond-agent-sdk dependency ${packageName}${details ? `:
647
+ ${details}` : ""}`
648
+ );
649
+ }
650
+ const tarballName = pack.stdout.trim().split(/\r?\n/).filter(Boolean).pop();
651
+ if (!tarballName) {
652
+ throw new Error(
653
+ `failed to pack openpond-agent-sdk dependency ${packageName}: npm pack did not return a tarball name`
654
+ );
655
+ }
656
+ const contents = await fs.readFile(path2.join(params.tempDir, tarballName));
657
+ const packedPackageJson = readPackageJsonFromNpmTarball(contents);
658
+ tarballs.push({
659
+ packageName,
660
+ source: "npm_dependency_tarball",
661
+ versionSpec,
662
+ path: `${AGENT_SDK_VENDOR_NPM_DEPENDENCY_DIR}/${sanitizeNpmPackageNameForVendor(
663
+ packageName
664
+ )}.tgz`,
665
+ contents,
666
+ sha256: sha256Hex(contents),
667
+ sizeBytes: contents.byteLength
668
+ });
669
+ for (const [dependencyName, dependencySpec] of Object.entries(
670
+ recordStringMap(packedPackageJson.dependencies)
671
+ )) {
672
+ pending.push({ packageName: dependencyName, versionSpec: dependencySpec });
673
+ }
674
+ for (const [dependencyName, dependencySpec] of Object.entries(
675
+ recordStringMap(packedPackageJson.optionalDependencies)
676
+ )) {
677
+ if (!isSupportedSandboxOptionalDependency(dependencyName)) continue;
678
+ pending.push({ packageName: dependencyName, versionSpec: dependencySpec });
679
+ }
680
+ }
681
+ return tarballs.sort((left, right) => left.packageName.localeCompare(right.packageName));
682
+ }
683
+ function isSupportedSandboxOptionalDependency(packageName) {
684
+ if (packageName === "fsevents") return false;
685
+ if (packageName.startsWith("@esbuild/")) {
686
+ return packageName === "@esbuild/linux-x64" || packageName === "@esbuild/linux-arm64";
687
+ }
688
+ return true;
689
+ }
690
+ function npmPackTargetForDependency(params) {
691
+ if (params.versionSpec.startsWith("file:")) {
692
+ return path2.resolve(
693
+ params.dependencyBaseDir,
694
+ params.versionSpec.slice("file:".length)
695
+ );
696
+ }
697
+ return `${params.packageName}@${params.versionSpec}`;
698
+ }
699
+ function sanitizeNpmPackageNameForVendor(packageName) {
700
+ return packageName.replace(/^@/, "").replace(/[\/\\]/g, "__").replace(/[^a-zA-Z0-9._-]/g, "_");
701
+ }
702
+ function resolveLocalOpenPondAgentSdkMaterializationSource(projectPath, packageJson) {
703
+ const versionSpec = readOpenPondAgentSdkVersionSpec(packageJson);
704
+ if (versionSpec?.startsWith("file:")) {
705
+ const candidate = path2.resolve(projectPath, versionSpec.slice("file:".length));
706
+ if (isOpenPondAgentSdkPackageRoot(candidate)) {
707
+ return {
708
+ kind: "package_root",
709
+ packageRoot: candidate,
710
+ dependencyBaseDir: candidate,
711
+ packageJson: JSON.parse(
712
+ readFileSyncUtf8(path2.join(candidate, "package.json"))
713
+ )
714
+ };
715
+ }
716
+ if (isLocalNpmTarball(candidate)) {
717
+ const tarballContents = readFileSync2(candidate);
718
+ const tarballPackageJson = readPackageJsonFromNpmTarball(tarballContents);
719
+ if (tarballPackageJson.name === "openpond-agent-sdk") {
720
+ return {
721
+ kind: "tarball",
722
+ tarballPath: candidate,
723
+ tarballContents,
724
+ dependencyBaseDir: path2.dirname(candidate),
725
+ packageJson: tarballPackageJson
726
+ };
727
+ }
728
+ }
729
+ }
730
+ if (versionSpec?.startsWith("workspace:")) {
731
+ const candidate = findOpenPondAgentSdkPackageRootInAncestors(projectPath);
732
+ if (candidate) {
733
+ return {
734
+ kind: "package_root",
735
+ packageRoot: candidate,
736
+ dependencyBaseDir: candidate,
737
+ packageJson: JSON.parse(
738
+ readFileSyncUtf8(path2.join(candidate, "package.json"))
739
+ )
740
+ };
741
+ }
742
+ }
743
+ return null;
744
+ }
745
+ function findOpenPondAgentSdkPackageRootInAncestors(projectPath) {
746
+ let current = path2.resolve(projectPath);
747
+ while (true) {
748
+ if (isOpenPondAgentSdkPackageRoot(current)) return current;
749
+ const parent = path2.dirname(current);
750
+ if (parent === current) return null;
751
+ current = parent;
752
+ }
753
+ }
754
+ function isOpenPondAgentSdkPackageRoot(candidate) {
755
+ const packageJsonPath = path2.join(candidate, "package.json");
756
+ if (!existsSync2(packageJsonPath)) return false;
757
+ try {
758
+ const parsed = JSON.parse(readFileSyncUtf8(packageJsonPath));
759
+ return parsed.name === "openpond-agent-sdk";
760
+ } catch {
761
+ return false;
762
+ }
763
+ }
764
+ function isLocalNpmTarball(candidate) {
765
+ if (!existsSync2(candidate)) return false;
766
+ try {
767
+ return statSync(candidate).isFile() && (candidate.endsWith(".tgz") || candidate.endsWith(".tar.gz"));
768
+ } catch {
769
+ return false;
770
+ }
771
+ }
772
+ function readPackageJsonFromNpmTarball(tarballContents) {
773
+ const tarContents = gunzipSync(tarballContents);
774
+ let offset = 0;
775
+ while (offset + 512 <= tarContents.length) {
776
+ const header = tarContents.subarray(offset, offset + 512);
777
+ if (header.every((byte) => byte === 0)) break;
778
+ const name = readTarString(header, 0, 100);
779
+ const prefix = readTarString(header, 345, 155);
780
+ const entryPath = prefix ? `${prefix}/${name}` : name;
781
+ const sizeText = readTarString(header, 124, 12).trim();
782
+ const size = Number.parseInt(sizeText || "0", 8);
783
+ if (!Number.isFinite(size) || size < 0) {
784
+ throw new Error("failed to read openpond-agent-sdk tarball: invalid entry size");
785
+ }
786
+ const dataStart = offset + 512;
787
+ const dataEnd = dataStart + size;
788
+ if (entryPath === "package/package.json") {
789
+ return JSON.parse(
790
+ tarContents.subarray(dataStart, dataEnd).toString("utf8")
791
+ );
792
+ }
793
+ offset = dataStart + Math.ceil(size / 512) * 512;
794
+ }
795
+ throw new Error("failed to read openpond-agent-sdk tarball: missing package.json");
796
+ }
797
+ function readTarString(header, start, length) {
798
+ const field = header.subarray(start, start + length);
799
+ const nullIndex = field.indexOf(0);
800
+ return field.subarray(0, nullIndex === -1 ? field.length : nullIndex).toString("utf8");
801
+ }
802
+ function rewriteAgentSdkPackageJsonForMaterialization(packageJson, dependencyTarballs, packageManager) {
803
+ const rewritten = { ...packageJson };
804
+ const dependencies = recordCopy(rewritten.dependencies);
805
+ const overrides = recordCopy(rewritten.overrides);
806
+ dependencies["openpond-agent-sdk"] = AGENT_SDK_MATERIALIZED_DEPENDENCY_SPEC;
807
+ for (const tarball of dependencyTarballs) {
808
+ const dependencySpec = `file:${tarball.path}`;
809
+ dependencies[tarball.packageName] = dependencySpec;
810
+ overrides[tarball.packageName] = dependencySpec;
811
+ }
812
+ rewritten.dependencies = dependencies;
813
+ if (Object.keys(overrides).length > 0) {
814
+ rewritten.overrides = overrides;
815
+ }
816
+ if (packageManager === "unknown") {
817
+ rewritten.packageManager = OPENPOND_PNPM_PACKAGE_MANAGER;
818
+ }
819
+ for (const key of ["devDependencies", "peerDependencies"]) {
820
+ const entries = recordCopy(rewritten[key]);
821
+ delete entries["openpond-agent-sdk"];
822
+ if (Object.keys(entries).length > 0) {
823
+ rewritten[key] = entries;
824
+ } else {
825
+ delete rewritten[key];
826
+ }
827
+ }
828
+ return rewritten;
829
+ }
830
+ function buildAgentSdkPnpmWorkspaceSource(projectPath, dependencyTarballs) {
831
+ const workspacePath = path2.join(projectPath, "pnpm-workspace.yaml");
832
+ let workspace = {};
833
+ if (existsSync2(workspacePath)) {
834
+ const parsed = yaml.load(readFileSyncUtf8(workspacePath));
835
+ workspace = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? { ...parsed } : {};
836
+ }
837
+ if (!Array.isArray(workspace.packages)) workspace.packages = [];
838
+ const overrides = recordCopy(workspace.overrides);
839
+ for (const tarball of dependencyTarballs) {
840
+ overrides[tarball.packageName] = `file:${tarball.path}`;
841
+ }
842
+ workspace.overrides = overrides;
843
+ const allowBuilds = recordCopy(workspace.allowBuilds);
844
+ allowBuilds.esbuild = true;
845
+ const vendoredEsbuild = dependencyTarballs.find(
846
+ (tarball) => tarball.packageName === "esbuild"
847
+ );
848
+ if (vendoredEsbuild) {
849
+ allowBuilds[`esbuild@file:${vendoredEsbuild.path}`] = true;
850
+ }
851
+ workspace.allowBuilds = allowBuilds;
852
+ workspace.supportedArchitectures = {
853
+ os: ["linux"],
854
+ cpu: ["x64", "arm64"],
855
+ libc: ["glibc", "musl"]
856
+ };
857
+ return yaml.dump(workspace, { lineWidth: 120, noRefs: true });
858
+ }
859
+ function recordStringMap(value) {
860
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
861
+ const entries = {};
862
+ for (const [key, entryValue] of Object.entries(value)) {
863
+ if (typeof entryValue === "string" && entryValue.trim()) {
864
+ entries[key] = entryValue.trim();
865
+ }
866
+ }
867
+ return entries;
868
+ }
869
+ function recordCopy(value) {
870
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
871
+ return { ...value };
872
+ }
873
+ function recordArray(value) {
874
+ return Array.isArray(value) ? value.filter(
875
+ (item) => Boolean(item) && typeof item === "object" && !Array.isArray(item)
876
+ ) : [];
877
+ }
878
+ function text(value) {
879
+ return typeof value === "string" && value.trim() ? value.trim() : null;
880
+ }
881
+ function agentSdkDependencyInstallCommand(packageManager) {
882
+ if (packageManager === "npm") return "npm install --offline";
883
+ if (packageManager === "pnpm") return "pnpm install --offline";
884
+ if (packageManager === "yarn") return "yarn install --offline";
885
+ if (packageManager === "bun") return "bun install --offline";
886
+ return "pnpm install --offline";
887
+ }
888
+ function sha256Hex(contents) {
889
+ return createHash("sha256").update(contents).digest("hex");
890
+ }
891
+ function dependencySetupCommands(value) {
892
+ if (!value || typeof value !== "object" || Array.isArray(value)) return [];
893
+ const record = value;
894
+ if (Array.isArray(record.commands)) {
895
+ return record.commands.filter(
896
+ (command) => typeof command === "string" && command.trim() !== ""
897
+ );
898
+ }
899
+ return typeof record.installCommand === "string" && record.installCommand.trim() ? [record.installCommand.trim()] : [];
900
+ }
901
+ function mergeManifestSetupCommands(manifest, commands) {
902
+ if (commands.length === 0) return manifest;
903
+ const setup = manifest.setup && typeof manifest.setup === "object" && !Array.isArray(manifest.setup) ? recordCopy(manifest.setup) : {};
904
+ const existingCommands = Array.isArray(setup.commands) ? setup.commands.filter(
905
+ (command) => typeof command === "string" && command.trim() !== ""
906
+ ) : [];
907
+ const mergedCommands = [...commands];
908
+ for (const command of existingCommands) {
909
+ if (!mergedCommands.includes(command)) mergedCommands.push(command);
910
+ }
911
+ return {
912
+ ...manifest,
913
+ setup: {
914
+ ...setup,
915
+ commands: mergedCommands
916
+ }
917
+ };
918
+ }
919
+ function sanitizeAgentSdkRuntimeManifestForOpenPondYaml(source, dependencySetup) {
920
+ const parsed = yaml.load(source);
921
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
922
+ return `${AGENT_SDK_SYNTHESIZED_OPENPOND_YAML_SENTINEL}
923
+ ${source}`;
924
+ }
925
+ const manifest = mergeManifestSetupCommands(
926
+ { ...parsed },
927
+ dependencySetupCommands(dependencySetup)
928
+ );
929
+ delete manifest.schema;
930
+ sanitizeGeneratedManifestNamedCommands(manifest, "actions");
931
+ sanitizeGeneratedManifestNamedCommands(manifest, "services");
932
+ return `${AGENT_SDK_SYNTHESIZED_OPENPOND_YAML_SENTINEL}
933
+ ${yaml.dump(manifest, { lineWidth: -1, noRefs: true })}`;
934
+ }
935
+ function sanitizeGeneratedManifestNamedCommands(manifest, key) {
936
+ if (!Array.isArray(manifest[key])) return;
937
+ manifest[key] = manifest[key].map((entry) => {
938
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
939
+ return entry;
940
+ }
941
+ const sanitized = { ...entry };
942
+ delete sanitized.id;
943
+ delete sanitized.label;
944
+ return sanitized;
945
+ });
946
+ }
947
+ function isAgentSdkProject(projectPath) {
948
+ if (!existsSync2(path2.join(projectPath, "agent", "agent.ts"))) return false;
949
+ const packageJsonPath = path2.join(projectPath, "package.json");
950
+ if (!existsSync2(packageJsonPath)) return false;
951
+ try {
952
+ const parsed = JSON.parse(readFileSyncUtf8(packageJsonPath));
953
+ return Boolean(
954
+ parsed.dependencies?.["openpond-agent-sdk"] || parsed.devDependencies?.["openpond-agent-sdk"] || parsed.peerDependencies?.["openpond-agent-sdk"]
955
+ );
956
+ } catch {
957
+ return false;
958
+ }
959
+ }
960
+ function readFileSyncUtf8(filePath) {
961
+ return readFileSync2(filePath, "utf8");
962
+ }
963
+ async function runAgentSdkProjectCheck(projectPath, commandName) {
964
+ const command = resolveLocalAgentSdkCommand(projectPath);
965
+ const result = await runCommand(command.command, [...command.args, commandName, "--cwd", projectPath], {
966
+ cwd: projectPath
967
+ });
968
+ if (result.code !== 0) {
969
+ const details = [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n");
970
+ throw new Error(
971
+ `openpond agent ${commandName} failed for ${projectPath}${details ? `:
972
+ ${details}` : ""}`
973
+ );
974
+ }
975
+ }
976
+ async function projectSourceUploadFileEntry(projectPath, relativePath) {
977
+ const normalized = relativePath.replace(/\\/g, "/");
978
+ if (!isSafeProjectSourcePath(normalized) || normalized.startsWith(".env")) {
979
+ throw new Error(`unsafe generated source path: ${relativePath}`);
980
+ }
981
+ const absolutePath = path2.join(projectPath, normalized);
982
+ const stat = await fs.stat(absolutePath);
983
+ if (!stat.isFile()) {
984
+ throw new Error(`generated source path is not a file: ${relativePath}`);
985
+ }
986
+ if (stat.size > PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES) {
987
+ throw new Error(`generated source file is too large: ${relativePath} (${stat.size} bytes)`);
988
+ }
989
+ return {
990
+ path: normalized,
991
+ type: "file",
992
+ contentsBase64: Buffer.from(await fs.readFile(absolutePath)).toString("base64")
993
+ };
994
+ }
995
+ function projectSourceUploadTextEntry(relativePath, contents) {
996
+ const normalized = relativePath.replace(/\\/g, "/");
997
+ if (!isSafeProjectSourcePath(normalized) || normalized.startsWith(".env")) {
998
+ throw new Error(`unsafe generated source path: ${relativePath}`);
999
+ }
1000
+ const byteLength = Buffer.byteLength(contents, "utf8");
1001
+ if (byteLength > PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES) {
1002
+ throw new Error(`generated source file is too large: ${relativePath} (${byteLength} bytes)`);
1003
+ }
1004
+ return {
1005
+ path: normalized,
1006
+ type: "file",
1007
+ contentsBase64: Buffer.from(contents, "utf8").toString("base64")
1008
+ };
1009
+ }
1010
+ function projectSourceUploadBufferEntry(relativePath, contents) {
1011
+ const normalized = relativePath.replace(/\\/g, "/");
1012
+ if (!isSafeProjectSourcePath(normalized) || normalized.startsWith(".env")) {
1013
+ throw new Error(`unsafe generated source path: ${relativePath}`);
1014
+ }
1015
+ if (contents.byteLength > PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES) {
1016
+ throw new Error(
1017
+ `generated source file is too large: ${relativePath} (${contents.byteLength} bytes)`
1018
+ );
1019
+ }
1020
+ return {
1021
+ path: normalized,
1022
+ type: "file",
1023
+ contentsBase64: contents.toString("base64")
1024
+ };
1025
+ }
1026
+ function mergeProjectSourceUploadEntries(collected, extraEntries) {
1027
+ const byPath = /* @__PURE__ */ new Map();
1028
+ const regeneratesPnpmLock = extraEntries.some(
1029
+ (entry) => entry.path === "pnpm-workspace.yaml"
1030
+ );
1031
+ for (const entry of collected.entries) {
1032
+ if (regeneratesPnpmLock && entry.path === "pnpm-lock.yaml") continue;
1033
+ byPath.set(entry.path, entry);
1034
+ }
1035
+ for (const entry of extraEntries) byPath.set(entry.path, entry);
1036
+ const entries = Array.from(byPath.values()).sort(
1037
+ (left, right) => left.path.localeCompare(right.path)
1038
+ );
1039
+ const totalBytes = entries.reduce(
1040
+ (sum, entry) => sum + Buffer.byteLength(entry.contentsBase64, "base64"),
1041
+ 0
1042
+ );
1043
+ if (entries.length > PROJECT_SOURCE_UPLOAD_MAX_FILES) {
1044
+ throw new Error(`too many source files to upload: ${entries.length} > ${PROJECT_SOURCE_UPLOAD_MAX_FILES}`);
1045
+ }
1046
+ if (totalBytes > PROJECT_SOURCE_UPLOAD_MAX_BYTES) {
1047
+ throw new Error(`source upload is too large: ${totalBytes} > ${PROJECT_SOURCE_UPLOAD_MAX_BYTES}`);
1048
+ }
1049
+ return {
1050
+ entries,
1051
+ fileCount: entries.length,
1052
+ totalBytes,
1053
+ limits: PROJECT_SOURCE_UPLOAD_LIMITS,
1054
+ transport: PROJECT_SOURCE_UPLOAD_TRANSPORT
1055
+ };
1056
+ }
1057
+
1058
+ // src/cli/project-agent-inputs.ts
1059
+ import { randomUUID } from "node:crypto";
1060
+ function parseProjectSourceType(value) {
1061
+ const sourceType = typeof value === "string" && value.trim() ? value.trim() : "manual";
1062
+ if (sourceType !== "github_repo" && sourceType !== "internal_repo" && sourceType !== "template" && sourceType !== "manual") {
1063
+ throw new Error(
1064
+ "source-type must be one of github_repo, internal_repo, template, manual"
1065
+ );
1066
+ }
1067
+ return sourceType;
1068
+ }
1069
+ function parseAgentEntrypointScope(value) {
1070
+ if (value === void 0) return void 0;
1071
+ if (typeof value !== "string" || !value.trim()) {
1072
+ throw new Error("entrypoint-scope must be a non-empty value");
1073
+ }
1074
+ const scope = value.trim();
1075
+ if (scope !== "entire_manifest" && scope !== "start" && scope !== "action" && scope !== "service" && scope !== "schedule") {
1076
+ throw new Error(
1077
+ "entrypoint-scope must be one of entire_manifest, start, action, service, schedule"
1078
+ );
1079
+ }
1080
+ return scope;
1081
+ }
1082
+ function parseAgentTriggerType(value) {
1083
+ if (value === void 0) return void 0;
1084
+ if (typeof value !== "string" || !value.trim()) {
1085
+ throw new Error("trigger-type must be a non-empty value");
1086
+ }
1087
+ const triggerType = value.trim();
1088
+ if (triggerType !== "manual" && triggerType !== "schedule" && triggerType !== "endpoint" && triggerType !== "background") {
1089
+ throw new Error(
1090
+ "trigger-type must be one of manual, schedule, endpoint, background"
1091
+ );
1092
+ }
1093
+ return triggerType;
1094
+ }
1095
+ function parseAgentSourceMode(value, optionName = "source-mode") {
1096
+ if (value === void 0) return void 0;
1097
+ if (typeof value !== "string" || !value.trim()) {
1098
+ throw new Error(`${optionName} must be a non-empty value`);
1099
+ }
1100
+ const mode = value.trim();
1101
+ if (mode !== "latest_source" && mode !== "published_snapshot" && mode !== "auto") {
1102
+ throw new Error(
1103
+ `${optionName} must be one of latest_source, published_snapshot, auto`
1104
+ );
1105
+ }
1106
+ return mode;
1107
+ }
1108
+ function buildAgentSourceConfig(options) {
1109
+ const hasSourceMode = Object.prototype.hasOwnProperty.call(
1110
+ options,
1111
+ "sourceMode"
1112
+ );
1113
+ const mode = parseAgentSourceMode(
1114
+ hasSourceMode ? options.sourceMode : options.runtimeSourceMode,
1115
+ hasSourceMode ? "source-mode" : "runtime-source-mode"
1116
+ );
1117
+ const sourceRef = optionString(options, "sourceRef");
1118
+ const sourceCommitSha = optionString(options, "sourceCommitSha");
1119
+ const publishedSnapshotId = optionString(options, "publishedSnapshotId") || optionString(options, "snapshotId");
1120
+ const publishedSnapshotName = optionString(options, "publishedSnapshotName") || optionString(options, "snapshotName");
1121
+ const publishedSnapshotVersion = optionString(options, "publishedSnapshotVersion") || optionString(options, "snapshotVersion");
1122
+ const buildStatus = optionString(options, "buildStatus");
1123
+ const validationStatus = optionString(options, "validationStatus");
1124
+ const validatedAt = optionString(options, "validatedAt");
1125
+ const config = {
1126
+ ...mode ? { mode } : {},
1127
+ ...sourceRef ? { sourceRef } : {},
1128
+ ...sourceCommitSha ? { sourceCommitSha } : {},
1129
+ ...publishedSnapshotId ? { publishedSnapshotId } : {},
1130
+ ...publishedSnapshotName ? { publishedSnapshotName } : {},
1131
+ ...publishedSnapshotVersion ? { publishedSnapshotVersion } : {},
1132
+ ...buildStatus ? { buildStatus } : {},
1133
+ ...validationStatus ? { validationStatus } : {},
1134
+ ...validatedAt ? { validatedAt } : {}
1135
+ };
1136
+ return Object.keys(config).length > 0 ? config : void 0;
1137
+ }
1138
+ function buildAgentSourcePolicy(options, source = "manual") {
1139
+ const requirePublishedSnapshot = parseBooleanOption(
1140
+ options.requirePublishedSnapshot
1141
+ );
1142
+ const allowLatestSource = parseBooleanOption(options.allowLatestSource);
1143
+ if (!requirePublishedSnapshot && !allowLatestSource && source === "manual") {
1144
+ return void 0;
1145
+ }
1146
+ return {
1147
+ source,
1148
+ ...requirePublishedSnapshot ? { requirePublishedSnapshot } : {},
1149
+ ...allowLatestSource || source === "diagnostic" ? { allowLatestSource: allowLatestSource || source === "diagnostic" } : {}
1150
+ };
1151
+ }
1152
+ function parseAgentSourceCheckKind(value) {
1153
+ if (value === void 0) return void 0;
1154
+ if (typeof value !== "string" || !value.trim()) {
1155
+ throw new Error("check-kind must be a non-empty value");
1156
+ }
1157
+ const checkKind = value.trim();
1158
+ if (checkKind !== "validate" && checkKind !== "eval" && checkKind !== "publish_review" && checkKind !== "all") {
1159
+ throw new Error(
1160
+ "check-kind must be one of validate, eval, publish_review, all"
1161
+ );
1162
+ }
1163
+ return checkKind;
1164
+ }
1165
+ function parseAgentSourceCheckDispatch(value, optionName = "source-check-dispatch") {
1166
+ if (value === void 0) return void 0;
1167
+ if (typeof value !== "string" || !value.trim()) {
1168
+ throw new Error(`${optionName} must be a non-empty value`);
1169
+ }
1170
+ const dispatch = value.trim();
1171
+ if (dispatch !== "request_only" && dispatch !== "coding_core") {
1172
+ throw new Error(
1173
+ `${optionName} must be one of request_only, coding_core`
1174
+ );
1175
+ }
1176
+ return dispatch;
1177
+ }
1178
+ function parsePositiveLimit(value) {
1179
+ if (value === void 0) return void 0;
1180
+ const parsed = parseIntegerOption(value, "limit");
1181
+ if (parsed === void 0) return void 0;
1182
+ if (parsed <= 0) throw new Error("limit must be greater than 0");
1183
+ return parsed;
1184
+ }
1185
+ function buildAgentSourceChecksInput(teamId, options) {
1186
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1187
+ const checkKind = parseAgentSourceCheckKind(options.checkKind);
1188
+ const dispatch = parseAgentSourceCheckDispatch(
1189
+ options.sourceCheckDispatch ?? options.dispatch
1190
+ );
1191
+ return {
1192
+ teamId,
1193
+ ...optionString(options, "sourceRef") ? { sourceRef: optionString(options, "sourceRef") } : {},
1194
+ ...optionString(options, "baseSha") ? { baseSha: optionString(options, "baseSha") } : {},
1195
+ ...checkKind ? { checkKind } : {},
1196
+ ...dispatch ? { dispatch } : {},
1197
+ ...metadata ? { metadata } : {}
1198
+ };
1199
+ }
1200
+ function buildAgentSourcePublishInput(teamId, options) {
1201
+ return {
1202
+ teamId,
1203
+ ...optionString(options, "expectedManifestHash") ? { expectedManifestHash: optionString(options, "expectedManifestHash") } : {},
1204
+ ...optionString(options, "expectedSourceCommitSha") ? {
1205
+ expectedSourceCommitSha: optionString(
1206
+ options,
1207
+ "expectedSourceCommitSha"
1208
+ )
1209
+ } : {},
1210
+ ...optionString(options, "evalStatus") ? { evalStatus: optionString(options, "evalStatus") } : {},
1211
+ ...optionString(options, "workItemId") ? { workItemId: optionString(options, "workItemId") } : {},
1212
+ ...optionString(options, "taskRunId") ? { taskRunId: optionString(options, "taskRunId") } : {},
1213
+ ...optionString(options, "traceArtifactRef") ? { traceArtifactRef: optionString(options, "traceArtifactRef") } : {},
1214
+ ...optionString(options, "evalResultArtifactRef") ? { evalResultArtifactRef: optionString(options, "evalResultArtifactRef") } : {}
1215
+ };
1216
+ }
1217
+ function buildAgentEditOpenInput(agentId, teamId, options) {
1218
+ const projectId = optionString(options, "projectId");
1219
+ if (!projectId) {
1220
+ throw new Error(
1221
+ "agent edit open requires --project-id <id> so the edit work item is project scoped"
1222
+ );
1223
+ }
1224
+ const initialMessage = optionString(options, "initialMessage") || optionString(options, "message") || optionString(options, "prompt");
1225
+ const sourceRef = optionString(options, "sourceRef") ?? null;
1226
+ const baseSha = optionString(options, "baseSha") ?? null;
1227
+ return {
1228
+ teamId,
1229
+ projectId,
1230
+ ...initialMessage ? { initialMessage } : {},
1231
+ ...sourceRef ? { sourceRef } : {},
1232
+ ...baseSha ? { baseSha } : {},
1233
+ createPipelineRequest: buildAgentEditCreatePipelineRequest({
1234
+ agentId,
1235
+ teamId,
1236
+ projectId,
1237
+ objective: initialMessage || `Edit hosted agent ${agentId}`,
1238
+ sourceRef,
1239
+ baseSha,
1240
+ activeProfile: optionString(options, "profile") || "default"
1241
+ })
1242
+ };
1243
+ }
1244
+ function buildAgentEditCreatePipelineRequest(input) {
1245
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1246
+ return CreatePipelineRequestSchema.parse({
1247
+ schemaVersion: "openpond.createPipeline.request.v1",
1248
+ id: `create_request_${randomUUID()}`,
1249
+ operation: "edit",
1250
+ surface: "hosted_edit",
1251
+ command: "/edit",
1252
+ objective: input.objective,
1253
+ adapter: {
1254
+ kind: "hosted",
1255
+ sourceAuthority: "hosted_profile",
1256
+ teamId: input.teamId,
1257
+ projectId: input.projectId,
1258
+ activeProfile: input.activeProfile,
1259
+ sourceRef: input.sourceRef,
1260
+ baseSha: input.baseSha,
1261
+ workItemId: null,
1262
+ confirmationPolicy: "always_require_plan_approval"
1263
+ },
1264
+ actor: {
1265
+ id: null,
1266
+ kind: "user",
1267
+ label: null
1268
+ },
1269
+ scope: {
1270
+ conversationId: null,
1271
+ workItemId: null,
1272
+ projectId: input.projectId,
1273
+ targetProject: {
1274
+ id: input.projectId,
1275
+ name: null,
1276
+ workspacePath: null,
1277
+ sourceRef: input.sourceRef,
1278
+ baseSha: input.baseSha
1279
+ }
1280
+ },
1281
+ context: {
1282
+ messageIds: [],
1283
+ conversationExcerpts: [],
1284
+ attachments: [],
1285
+ apps: [],
1286
+ tools: [],
1287
+ targetRepoAssumptions: [`cloud project: ${input.projectId}`]
1288
+ },
1289
+ targetAgent: {
1290
+ agentId: input.agentId,
1291
+ displayName: null,
1292
+ defaultActionKey: `${input.agentId}.chat`
1293
+ },
1294
+ metadata: {
1295
+ source: "cli_agent_edit_open",
1296
+ selectedCommand: "/edit"
1297
+ },
1298
+ createdAt: now
1299
+ });
1300
+ }
1301
+ function buildCodingWorkItemChatInput(teamId, options) {
1302
+ const message = optionString(options, "message") || optionString(options, "prompt");
1303
+ if (!message) {
1304
+ throw new Error("agent edit chat requires --message <text>");
1305
+ }
1306
+ const mode = optionString(options, "chatMode") || "queue_cloud";
1307
+ if (mode !== "sync_cloud" && mode !== "queue_cloud") {
1308
+ throw new Error(
1309
+ "agent edit chat --chat-mode must be sync_cloud or queue_cloud"
1310
+ );
1311
+ }
1312
+ const payload = optionalJsonObject(options, "payload", "payload");
1313
+ return {
1314
+ teamId,
1315
+ message,
1316
+ mode,
1317
+ ...optionString(options, "sourceRef") ? { sourceRef: optionString(options, "sourceRef") } : {},
1318
+ ...optionString(options, "baseSha") ? { baseSha: optionString(options, "baseSha") } : {},
1319
+ ...payload ? { payload } : {}
1320
+ };
1321
+ }
1322
+ function buildCodingWorkItemBackgroundInput(teamId, options) {
1323
+ const payload = optionalJsonObject(options, "payload", "payload");
1324
+ const agentEdit = optionalJsonObject(options, "agentEdit", "agent-edit");
1325
+ const setup = optionalCommandList(options, "setup", "setup");
1326
+ const validation = optionalCommandList(options, "validation", "validation");
1327
+ const branchPolicy = optionalJsonObject(options, "branchPolicy", "branch-policy");
1328
+ return {
1329
+ teamId,
1330
+ ...optionString(options, "prompt") ? { prompt: optionString(options, "prompt") } : {},
1331
+ ...optionString(options, "sourceRef") ? { sourceRef: optionString(options, "sourceRef") } : {},
1332
+ ...optionString(options, "baseSha") ? { baseSha: optionString(options, "baseSha") } : {},
1333
+ ...optionString(options, "sourceRuntimeId") ? { sourceRuntimeId: optionString(options, "sourceRuntimeId") } : {},
1334
+ ...optionString(options, "sourceSandboxId") ? { sourceSandboxId: optionString(options, "sourceSandboxId") } : {},
1335
+ ...optionString(options, "agentId") ? { agentId: optionString(options, "agentId") } : {},
1336
+ ...agentEdit ? { agentEdit } : {},
1337
+ ...setup ? { setup } : {},
1338
+ ...validation ? { validation } : {},
1339
+ ...branchPolicy ? { branchPolicy } : {},
1340
+ ...payload ? { payload } : {}
1341
+ };
1342
+ }
1343
+ function optionalCommandList(options, key, displayName) {
1344
+ const value = optionalJsonObject(options, key, displayName);
1345
+ if (!value) return null;
1346
+ if (!Array.isArray(value.commands) || value.commands.some((command) => typeof command !== "string")) {
1347
+ throw new Error(`${displayName} must be a JSON object with a string commands array`);
1348
+ }
1349
+ return { commands: value.commands };
1350
+ }
1351
+ function buildCodingWorkItemPromotionInput(teamId, options) {
1352
+ const ref = optionString(options, "ref") || optionString(options, "artifactRef");
1353
+ if (!ref) throw new Error("result promotion requires --ref <artifact-ref>");
1354
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1355
+ return {
1356
+ teamId,
1357
+ ref,
1358
+ ...metadata ? { metadata } : {}
1359
+ };
1360
+ }
1361
+ function buildProjectUpsertInput(options) {
1362
+ const usage = "usage: project create --team-id <id> --name <name>";
1363
+ const teamId = requiredTeamId(options, usage);
1364
+ const name = optionString(options, "name");
1365
+ if (!name) {
1366
+ throw new Error(
1367
+ `${usage} [--source-type manual|github_repo|internal_repo|template]`
1368
+ );
1369
+ }
1370
+ const sourceType = parseProjectSourceType(options.sourceType);
1371
+ const repoUrl = optionString(options, "repoUrl") || optionString(options, "repo");
1372
+ const sourceConfig = {
1373
+ ...optionalJsonObject(options, "sourceConfig", "source-config") ?? {},
1374
+ ...repoUrl ? { repoUrl } : {}
1375
+ };
1376
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1377
+ return {
1378
+ teamId,
1379
+ name,
1380
+ sourceType,
1381
+ ...optionString(options, "slug") ? { slug: optionString(options, "slug") } : {},
1382
+ ...optionString(options, "description") ? { description: optionString(options, "description") } : {},
1383
+ ...options.status === "active" || options.status === "disabled" || options.status === "archived" ? { status: options.status } : {},
1384
+ ...Object.keys(sourceConfig).length > 0 ? { sourceConfig } : {},
1385
+ ...optionString(options, "normalizedSourceIdentity") ? {
1386
+ normalizedSourceIdentity: optionString(
1387
+ options,
1388
+ "normalizedSourceIdentity"
1389
+ )
1390
+ } : {},
1391
+ ...optionString(options, "externalId") ? { externalId: optionString(options, "externalId") } : {},
1392
+ ...optionString(options, "gitProvider") ? { gitProvider: optionString(options, "gitProvider") } : {},
1393
+ ...optionString(options, "gitHost") ? { gitHost: optionString(options, "gitHost") } : {},
1394
+ ...optionString(options, "gitOwner") ? { gitOwner: optionString(options, "gitOwner") } : {},
1395
+ ...optionString(options, "gitRepo") ? { gitRepo: optionString(options, "gitRepo") } : {},
1396
+ ...optionString(options, "gitBranch") ? { gitBranch: optionString(options, "gitBranch") } : {},
1397
+ ...optionString(options, "defaultBranch") ? { defaultBranch: optionString(options, "defaultBranch") } : {},
1398
+ ...optionString(options, "internalRepoPath") ? { internalRepoPath: optionString(options, "internalRepoPath") } : {},
1399
+ ...optionString(options, "templateSourceProjectId") ? {
1400
+ templateSourceProjectId: optionString(
1401
+ options,
1402
+ "templateSourceProjectId"
1403
+ )
1404
+ } : {},
1405
+ ...optionString(options, "templateRepoUrl") ? { templateRepoUrl: optionString(options, "templateRepoUrl") } : {},
1406
+ ...optionString(options, "templateBranch") ? { templateBranch: optionString(options, "templateBranch") } : {},
1407
+ ...optionString(options, "templateRemoteSha") ? { templateRemoteSha: optionString(options, "templateRemoteSha") } : {},
1408
+ ...metadata ? { metadata } : {}
1409
+ };
1410
+ }
1411
+ function buildProjectUpdateInput(teamId, options) {
1412
+ const repoUrl = optionString(options, "repoUrl") || optionString(options, "repo");
1413
+ const sourceConfig = optionalJsonObject(
1414
+ options,
1415
+ "sourceConfig",
1416
+ "source-config"
1417
+ );
1418
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1419
+ return {
1420
+ teamId,
1421
+ ...optionString(options, "name") ? { name: optionString(options, "name") } : {},
1422
+ ...optionString(options, "slug") ? { slug: optionString(options, "slug") } : {},
1423
+ ...optionString(options, "description") ? { description: optionString(options, "description") } : {},
1424
+ ...options.status === "active" || options.status === "disabled" || options.status === "archived" ? { status: options.status } : {},
1425
+ ...options.sourceType !== void 0 ? { sourceType: parseProjectSourceType(options.sourceType) } : {},
1426
+ ...sourceConfig || repoUrl ? {
1427
+ sourceConfig: {
1428
+ ...sourceConfig ?? {},
1429
+ ...repoUrl ? { repoUrl } : {}
1430
+ }
1431
+ } : {},
1432
+ ...optionString(options, "normalizedSourceIdentity") ? {
1433
+ normalizedSourceIdentity: optionString(
1434
+ options,
1435
+ "normalizedSourceIdentity"
1436
+ )
1437
+ } : {},
1438
+ ...optionString(options, "externalId") ? { externalId: optionString(options, "externalId") } : {},
1439
+ ...optionString(options, "gitProvider") ? { gitProvider: optionString(options, "gitProvider") } : {},
1440
+ ...optionString(options, "gitHost") ? { gitHost: optionString(options, "gitHost") } : {},
1441
+ ...optionString(options, "gitOwner") ? { gitOwner: optionString(options, "gitOwner") } : {},
1442
+ ...optionString(options, "gitRepo") ? { gitRepo: optionString(options, "gitRepo") } : {},
1443
+ ...optionString(options, "gitBranch") ? { gitBranch: optionString(options, "gitBranch") } : {},
1444
+ ...optionString(options, "defaultBranch") ? { defaultBranch: optionString(options, "defaultBranch") } : {},
1445
+ ...optionString(options, "internalRepoPath") ? { internalRepoPath: optionString(options, "internalRepoPath") } : {},
1446
+ ...optionString(options, "templateSourceProjectId") ? {
1447
+ templateSourceProjectId: optionString(
1448
+ options,
1449
+ "templateSourceProjectId"
1450
+ )
1451
+ } : {},
1452
+ ...optionString(options, "templateRepoUrl") ? { templateRepoUrl: optionString(options, "templateRepoUrl") } : {},
1453
+ ...optionString(options, "templateBranch") ? { templateBranch: optionString(options, "templateBranch") } : {},
1454
+ ...optionString(options, "templateRemoteSha") ? { templateRemoteSha: optionString(options, "templateRemoteSha") } : {},
1455
+ ...metadata ? { metadata } : {}
1456
+ };
1457
+ }
1458
+ function buildAgentUpsertInput(options) {
1459
+ const usage = "usage: agent create --team-id <id> --project-id <id> --name <name>";
1460
+ const teamId = requiredTeamId(options, usage);
1461
+ const projectId = optionString(options, "projectId");
1462
+ const name = optionString(options, "name");
1463
+ if (!projectId || !name) {
1464
+ throw new Error(usage);
1465
+ }
1466
+ const entrypointScope = parseAgentEntrypointScope(options.entrypointScope);
1467
+ const entrypointName = optionString(options, "entrypointName");
1468
+ const triggerType = parseAgentTriggerType(options.triggerType);
1469
+ const workflowMode = parseSandboxWorkflowModeOption(options.workflowMode);
1470
+ const promotionPolicy = parseSandboxRuntimePromotionPolicyOption(
1471
+ options.runtimePromotionPolicy
1472
+ );
1473
+ const agentSource = buildAgentSourceConfig(options);
1474
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1475
+ return {
1476
+ teamId,
1477
+ projectId,
1478
+ name,
1479
+ ...optionString(options, "slug") ? { slug: optionString(options, "slug") } : {},
1480
+ ...optionString(options, "description") ? { description: optionString(options, "description") } : {},
1481
+ ...options.status === "active" || options.status === "disabled" || options.status === "archived" ? { status: options.status } : {},
1482
+ ...entrypointScope ? {
1483
+ selectedEntrypoint: {
1484
+ scope: entrypointScope,
1485
+ name: entrypointName || null
1486
+ }
1487
+ } : {},
1488
+ ...triggerType ? { triggerType } : {},
1489
+ ...workflowMode ? { defaultWorkflowMode: workflowMode } : {},
1490
+ ...optionString(options, "defaultBranch") ? { defaultBranch: optionString(options, "defaultBranch") } : {},
1491
+ ...optionString(options, "sourceRefOverride") ? { sourceRefOverride: optionString(options, "sourceRefOverride") } : {},
1492
+ ...promotionPolicy ? { defaultPromotionPolicy: promotionPolicy } : {},
1493
+ ...agentSource ? { runtimeSource: agentSource } : {},
1494
+ ...optionalJsonObject(options, "endpointPolicy", "endpoint-policy") ? {
1495
+ endpointPolicy: optionalJsonObject(
1496
+ options,
1497
+ "endpointPolicy",
1498
+ "endpoint-policy"
1499
+ )
1500
+ } : {},
1501
+ ...optionalJsonObject(
1502
+ options,
1503
+ "backgroundTaskPolicy",
1504
+ "background-task-policy"
1505
+ ) ? {
1506
+ backgroundTaskPolicy: optionalJsonObject(
1507
+ options,
1508
+ "backgroundTaskPolicy",
1509
+ "background-task-policy"
1510
+ )
1511
+ } : {},
1512
+ ...optionalJsonObject(options, "resourcePolicy", "resource-policy") ? {
1513
+ defaultResourcePolicy: optionalJsonObject(
1514
+ options,
1515
+ "resourcePolicy",
1516
+ "resource-policy"
1517
+ )
1518
+ } : {},
1519
+ ...optionalJsonObject(options, "lifecyclePolicy", "lifecycle-policy") ? {
1520
+ defaultLifecyclePolicy: optionalJsonObject(
1521
+ options,
1522
+ "lifecyclePolicy",
1523
+ "lifecycle-policy"
1524
+ )
1525
+ } : {},
1526
+ ...optionalJsonObject(options, "checkpointPolicy", "checkpoint-policy") ? {
1527
+ defaultCheckpointPolicy: optionalJsonObject(
1528
+ options,
1529
+ "checkpointPolicy",
1530
+ "checkpoint-policy"
1531
+ )
1532
+ } : {},
1533
+ ...parseCsvOption(options.requiredIntegrations).length > 0 ? {
1534
+ requiredIntegrationRefs: parseCsvOption(options.requiredIntegrations)
1535
+ } : {},
1536
+ ...parseCsvOption(options.requiredEnv).length > 0 ? { requiredEnvironmentVariableRefs: parseCsvOption(options.requiredEnv) } : {},
1537
+ ...optionalJsonObject(options, "schedulePolicy", "schedule-policy") ? {
1538
+ schedulePolicy: optionalJsonObject(
1539
+ options,
1540
+ "schedulePolicy",
1541
+ "schedule-policy"
1542
+ )
1543
+ } : {},
1544
+ ...optionString(options, "externalId") ? { externalId: optionString(options, "externalId") } : {},
1545
+ ...metadata ? { metadata } : {}
1546
+ };
1547
+ }
1548
+ function buildAgentUpdateInput(teamId, options) {
1549
+ const entrypointScope = parseAgentEntrypointScope(options.entrypointScope);
1550
+ const entrypointName = optionString(options, "entrypointName");
1551
+ const triggerType = parseAgentTriggerType(options.triggerType);
1552
+ const workflowMode = parseSandboxWorkflowModeOption(options.workflowMode);
1553
+ const promotionPolicy = parseSandboxRuntimePromotionPolicyOption(
1554
+ options.runtimePromotionPolicy
1555
+ );
1556
+ const agentSource = buildAgentSourceConfig(options);
1557
+ const metadata = optionalJsonObject(options, "metadata", "metadata");
1558
+ return {
1559
+ teamId,
1560
+ ...optionString(options, "projectId") ? { projectId: optionString(options, "projectId") } : {},
1561
+ ...optionString(options, "name") ? { name: optionString(options, "name") } : {},
1562
+ ...optionString(options, "slug") ? { slug: optionString(options, "slug") } : {},
1563
+ ...optionString(options, "description") ? { description: optionString(options, "description") } : {},
1564
+ ...options.status === "active" || options.status === "disabled" || options.status === "archived" ? { status: options.status } : {},
1565
+ ...entrypointScope ? {
1566
+ selectedEntrypoint: {
1567
+ scope: entrypointScope,
1568
+ name: entrypointName || null
1569
+ }
1570
+ } : {},
1571
+ ...triggerType ? { triggerType } : {},
1572
+ ...workflowMode ? { defaultWorkflowMode: workflowMode } : {},
1573
+ ...optionString(options, "defaultBranch") ? { defaultBranch: optionString(options, "defaultBranch") } : {},
1574
+ ...optionString(options, "sourceRefOverride") ? { sourceRefOverride: optionString(options, "sourceRefOverride") } : {},
1575
+ ...promotionPolicy ? { defaultPromotionPolicy: promotionPolicy } : {},
1576
+ ...agentSource ? { runtimeSource: agentSource } : {},
1577
+ ...optionalJsonObject(options, "endpointPolicy", "endpoint-policy") ? {
1578
+ endpointPolicy: optionalJsonObject(
1579
+ options,
1580
+ "endpointPolicy",
1581
+ "endpoint-policy"
1582
+ )
1583
+ } : {},
1584
+ ...optionalJsonObject(
1585
+ options,
1586
+ "backgroundTaskPolicy",
1587
+ "background-task-policy"
1588
+ ) ? {
1589
+ backgroundTaskPolicy: optionalJsonObject(
1590
+ options,
1591
+ "backgroundTaskPolicy",
1592
+ "background-task-policy"
1593
+ )
1594
+ } : {},
1595
+ ...optionalJsonObject(options, "resourcePolicy", "resource-policy") ? {
1596
+ defaultResourcePolicy: optionalJsonObject(
1597
+ options,
1598
+ "resourcePolicy",
1599
+ "resource-policy"
1600
+ )
1601
+ } : {},
1602
+ ...optionalJsonObject(options, "lifecyclePolicy", "lifecycle-policy") ? {
1603
+ defaultLifecyclePolicy: optionalJsonObject(
1604
+ options,
1605
+ "lifecyclePolicy",
1606
+ "lifecycle-policy"
1607
+ )
1608
+ } : {},
1609
+ ...optionalJsonObject(options, "checkpointPolicy", "checkpoint-policy") ? {
1610
+ defaultCheckpointPolicy: optionalJsonObject(
1611
+ options,
1612
+ "checkpointPolicy",
1613
+ "checkpoint-policy"
1614
+ )
1615
+ } : {},
1616
+ ...parseCsvOption(options.requiredIntegrations).length > 0 ? {
1617
+ requiredIntegrationRefs: parseCsvOption(options.requiredIntegrations)
1618
+ } : {},
1619
+ ...parseCsvOption(options.requiredEnv).length > 0 ? { requiredEnvironmentVariableRefs: parseCsvOption(options.requiredEnv) } : {},
1620
+ ...optionalJsonObject(options, "schedulePolicy", "schedule-policy") ? {
1621
+ schedulePolicy: optionalJsonObject(
1622
+ options,
1623
+ "schedulePolicy",
1624
+ "schedule-policy"
1625
+ )
1626
+ } : {},
1627
+ ...optionString(options, "externalId") ? { externalId: optionString(options, "externalId") } : {},
1628
+ ...metadata ? { metadata } : {}
1629
+ };
1630
+ }
1631
+
1632
+ export {
1633
+ resolveLocalAgentSdkCommand,
1634
+ PROJECT_SOURCE_UPLOAD_MAX_FILES,
1635
+ PROJECT_SOURCE_UPLOAD_MAX_FILE_BYTES,
1636
+ PROJECT_SOURCE_UPLOAD_MAX_BYTES,
1637
+ PROJECT_SOURCE_UPLOAD_CONCURRENCY,
1638
+ PROJECT_SOURCE_UPLOAD_LIMITS,
1639
+ PROJECT_SOURCE_UPLOAD_TRANSPORT,
1640
+ resolveProjectSourceUploadBranch,
1641
+ collectProjectSourceUploadEntries,
1642
+ collectAgentSdkProjectSourceUploadEntries,
1643
+ mergeProjectSourceUploadEntries,
1644
+ parseProjectSourceType,
1645
+ parseAgentEntrypointScope,
1646
+ parseAgentTriggerType,
1647
+ parseAgentSourceMode,
1648
+ buildAgentSourceConfig,
1649
+ buildAgentSourcePolicy,
1650
+ parseAgentSourceCheckKind,
1651
+ parseAgentSourceCheckDispatch,
1652
+ parsePositiveLimit,
1653
+ buildAgentSourceChecksInput,
1654
+ buildAgentSourcePublishInput,
1655
+ buildAgentEditOpenInput,
1656
+ buildCodingWorkItemChatInput,
1657
+ buildCodingWorkItemBackgroundInput,
1658
+ buildCodingWorkItemPromotionInput,
1659
+ buildProjectUpsertInput,
1660
+ buildProjectUpdateInput,
1661
+ buildAgentUpsertInput,
1662
+ buildAgentUpdateInput
1663
+ };