@elie-laloum/outpost 4.0.0 → 4.2.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 (240) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +10 -6
  3. package/SECURITY.md +2 -0
  4. package/dist/adapters/agents/codex-adapter.js +2 -0
  5. package/dist/adapters/agents/codex-adapter.js.map +1 -1
  6. package/dist/adapters/agents/codex-provider.d.ts +2 -0
  7. package/dist/adapters/agents/codex-provider.js +32 -0
  8. package/dist/adapters/agents/codex-provider.js.map +1 -0
  9. package/dist/adapters/agents/codex-request.js +2 -1
  10. package/dist/adapters/agents/codex-request.js.map +1 -1
  11. package/dist/adapters/agents/gemini-request.js +2 -0
  12. package/dist/adapters/agents/gemini-request.js.map +1 -1
  13. package/dist/adapters/agents/settings.types.d.ts +5 -0
  14. package/dist/adapters/agents/settings.types.js.map +1 -1
  15. package/dist/adapters/models/openai-compatible.constants.d.ts +4 -0
  16. package/dist/adapters/models/openai-compatible.constants.js +10 -0
  17. package/dist/adapters/models/openai-compatible.constants.js.map +1 -0
  18. package/dist/adapters/models/openai-compatible.d.ts +3 -0
  19. package/dist/adapters/models/openai-compatible.js +78 -0
  20. package/dist/adapters/models/openai-compatible.js.map +1 -0
  21. package/dist/adapters/models/openai-compatible.types.d.ts +14 -0
  22. package/dist/adapters/models/openai-compatible.types.js +2 -0
  23. package/dist/adapters/models/openai-compatible.types.js.map +1 -0
  24. package/dist/adapters/models/openai-http.d.ts +1 -0
  25. package/dist/adapters/models/openai-http.js +30 -0
  26. package/dist/adapters/models/openai-http.js.map +1 -0
  27. package/dist/adapters/models/openai-request.d.ts +4 -0
  28. package/dist/adapters/models/openai-request.js +46 -0
  29. package/dist/adapters/models/openai-request.js.map +1 -0
  30. package/dist/adapters/models/openai-response.d.ts +3 -0
  31. package/dist/adapters/models/openai-response.js +65 -0
  32. package/dist/adapters/models/openai-response.js.map +1 -0
  33. package/dist/application/execution.types.d.ts +2 -0
  34. package/dist/application/execution.types.js.map +1 -1
  35. package/dist/application/outpost.types.d.ts +5 -0
  36. package/dist/application/outpost.types.js.map +1 -1
  37. package/dist/application/recovery-archive.d.ts +4 -0
  38. package/dist/application/recovery-archive.js +29 -0
  39. package/dist/application/recovery-archive.js.map +1 -0
  40. package/dist/application/recovery-archive.types.d.ts +10 -0
  41. package/dist/application/recovery-archive.types.js +2 -0
  42. package/dist/application/recovery-archive.types.js.map +1 -0
  43. package/dist/application/recovery-inspection.js +3 -0
  44. package/dist/application/recovery-inspection.js.map +1 -1
  45. package/dist/application/recovery-inspection.types.d.ts +2 -0
  46. package/dist/application/recovery-inspection.types.js.map +1 -1
  47. package/dist/application/recovery-retention.d.ts +2 -1
  48. package/dist/application/recovery-retention.js +9 -1
  49. package/dist/application/recovery-retention.js.map +1 -1
  50. package/dist/application/recovery-retention.types.d.ts +6 -0
  51. package/dist/application/recovery-retention.types.js.map +1 -1
  52. package/dist/application/remote-backup.js +8 -0
  53. package/dist/application/remote-backup.js.map +1 -1
  54. package/dist/application/remote-workspace.types.d.ts +2 -0
  55. package/dist/application/remote-workspace.types.js.map +1 -1
  56. package/dist/application/sandbox-agents.js +2 -1
  57. package/dist/application/sandbox-agents.js.map +1 -1
  58. package/dist/application/sandbox-dispatch.js +9 -0
  59. package/dist/application/sandbox-dispatch.js.map +1 -1
  60. package/dist/application/sandbox-provision.js +6 -0
  61. package/dist/application/sandbox-provision.js.map +1 -1
  62. package/dist/application/storage-reservation.js +3 -0
  63. package/dist/application/storage-reservation.js.map +1 -1
  64. package/dist/application/transport-inspection.constants.d.ts +2 -0
  65. package/dist/application/transport-inspection.constants.js +10 -0
  66. package/dist/application/transport-inspection.constants.js.map +1 -0
  67. package/dist/application/transport-inspection.d.ts +2 -0
  68. package/dist/application/transport-inspection.js +103 -0
  69. package/dist/application/transport-inspection.js.map +1 -0
  70. package/dist/application/transport-retention.d.ts +4 -0
  71. package/dist/application/transport-retention.js +153 -0
  72. package/dist/application/transport-retention.js.map +1 -0
  73. package/dist/cli/commands.js +55 -18
  74. package/dist/cli/commands.js.map +1 -1
  75. package/dist/cli/init-authentication.constants.d.ts +13 -0
  76. package/dist/cli/init-authentication.constants.js +10 -0
  77. package/dist/cli/init-authentication.constants.js.map +1 -0
  78. package/dist/cli/init-authentication.d.ts +4 -0
  79. package/dist/cli/init-authentication.js +43 -0
  80. package/dist/cli/init-authentication.js.map +1 -0
  81. package/dist/cli/init-command.js +74 -15
  82. package/dist/cli/init-command.js.map +1 -1
  83. package/dist/cli/main.constants.d.ts +102 -2
  84. package/dist/cli/main.constants.js +148 -46
  85. package/dist/cli/main.constants.js.map +1 -1
  86. package/dist/cli/scaffold-files.js +4 -3
  87. package/dist/cli/scaffold-files.js.map +1 -1
  88. package/dist/cli/scaffold-validation.js +19 -0
  89. package/dist/cli/scaffold-validation.js.map +1 -1
  90. package/dist/cli/scaffold.constants.d.ts +0 -5
  91. package/dist/cli/scaffold.constants.js +0 -5
  92. package/dist/cli/scaffold.constants.js.map +1 -1
  93. package/dist/cli/scaffold.js +13 -0
  94. package/dist/cli/scaffold.js.map +1 -1
  95. package/dist/cli/scaffold.types.d.ts +3 -0
  96. package/dist/cli/scaffold.types.js.map +1 -1
  97. package/dist/cli/starters.js +9 -2
  98. package/dist/cli/starters.js.map +1 -1
  99. package/dist/domain/conversation.types.d.ts +2 -0
  100. package/dist/domain/conversation.types.js.map +1 -1
  101. package/dist/domain/model.types.d.ts +15 -0
  102. package/dist/domain/model.types.js +2 -0
  103. package/dist/domain/model.types.js.map +1 -0
  104. package/dist/domain/transport.constants.d.ts +2 -0
  105. package/dist/domain/transport.constants.js +3 -0
  106. package/dist/domain/transport.constants.js.map +1 -0
  107. package/dist/domain/transport.d.ts +6 -0
  108. package/dist/domain/transport.js +21 -0
  109. package/dist/domain/transport.js.map +1 -0
  110. package/dist/domain/transport.types.d.ts +31 -0
  111. package/dist/domain/transport.types.js +2 -0
  112. package/dist/domain/transport.types.js.map +1 -0
  113. package/dist/index.d.ts +18 -1
  114. package/dist/index.js +8 -0
  115. package/dist/index.js.map +1 -1
  116. package/dist/infrastructure/artifact-store.js +10 -0
  117. package/dist/infrastructure/artifact-store.js.map +1 -1
  118. package/dist/infrastructure/artifact-store.types.d.ts +3 -1
  119. package/dist/infrastructure/artifact-store.types.js.map +1 -1
  120. package/dist/infrastructure/conversations/capture.js +1 -1
  121. package/dist/infrastructure/conversations/capture.js.map +1 -1
  122. package/dist/infrastructure/conversations.d.ts +2 -0
  123. package/dist/infrastructure/conversations.js +2 -0
  124. package/dist/infrastructure/conversations.js.map +1 -1
  125. package/dist/infrastructure/inspection-file.js +3 -3
  126. package/dist/infrastructure/inspection-file.js.map +1 -1
  127. package/dist/infrastructure/inspection-hash.js +4 -3
  128. package/dist/infrastructure/inspection-hash.js.map +1 -1
  129. package/dist/infrastructure/inspection-path.d.ts +1 -0
  130. package/dist/infrastructure/inspection-path.js +18 -0
  131. package/dist/infrastructure/inspection-path.js.map +1 -0
  132. package/dist/infrastructure/journal.js +6 -0
  133. package/dist/infrastructure/journal.js.map +1 -1
  134. package/dist/infrastructure/journal.types.d.ts +3 -0
  135. package/dist/infrastructure/journal.types.js.map +1 -1
  136. package/dist/infrastructure/local-transport.d.ts +3 -0
  137. package/dist/infrastructure/local-transport.js +146 -0
  138. package/dist/infrastructure/local-transport.js.map +1 -0
  139. package/dist/infrastructure/local-transport.types.d.ts +3 -0
  140. package/dist/infrastructure/local-transport.types.js +2 -0
  141. package/dist/infrastructure/local-transport.types.js.map +1 -0
  142. package/dist/infrastructure/resource-activity-inspection.d.ts +2 -1
  143. package/dist/infrastructure/resource-activity-inspection.js +2 -2
  144. package/dist/infrastructure/resource-activity-inspection.js.map +1 -1
  145. package/dist/infrastructure/resource-activity.js +42 -14
  146. package/dist/infrastructure/resource-activity.js.map +1 -1
  147. package/dist/infrastructure/resource-activity.types.d.ts +2 -0
  148. package/dist/infrastructure/resource-activity.types.js.map +1 -1
  149. package/dist/infrastructure/s3-transport.d.ts +4 -0
  150. package/dist/infrastructure/s3-transport.js +144 -0
  151. package/dist/infrastructure/s3-transport.js.map +1 -0
  152. package/dist/infrastructure/s3-transport.types.d.ts +6 -0
  153. package/dist/infrastructure/s3-transport.types.js +2 -0
  154. package/dist/infrastructure/s3-transport.types.js.map +1 -0
  155. package/dist/infrastructure/storage-inventory.types.d.ts +2 -1
  156. package/dist/infrastructure/storage-inventory.types.js.map +1 -1
  157. package/dist/infrastructure/storage-reservations.types.d.ts +2 -0
  158. package/dist/infrastructure/storage-reservations.types.js.map +1 -1
  159. package/dist/infrastructure/task-queue-bullmq-resources.d.ts +13 -0
  160. package/dist/infrastructure/task-queue-bullmq-resources.js +118 -0
  161. package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -0
  162. package/dist/infrastructure/task-queue-bullmq-state.d.ts +5 -0
  163. package/dist/infrastructure/task-queue-bullmq-state.js +26 -0
  164. package/dist/infrastructure/task-queue-bullmq-state.js.map +1 -0
  165. package/dist/infrastructure/task-queue-bullmq.constants.d.ts +7 -0
  166. package/dist/infrastructure/task-queue-bullmq.constants.js +79 -0
  167. package/dist/infrastructure/task-queue-bullmq.constants.js.map +1 -0
  168. package/dist/infrastructure/task-queue-bullmq.d.ts +3 -0
  169. package/dist/infrastructure/task-queue-bullmq.js +124 -0
  170. package/dist/infrastructure/task-queue-bullmq.js.map +1 -0
  171. package/dist/infrastructure/task-queue-bullmq.types.d.ts +17 -0
  172. package/dist/infrastructure/task-queue-bullmq.types.js +2 -0
  173. package/dist/infrastructure/task-queue-bullmq.types.js.map +1 -0
  174. package/dist/infrastructure/transport-archive.constants.d.ts +6 -0
  175. package/dist/infrastructure/transport-archive.constants.js +7 -0
  176. package/dist/infrastructure/transport-archive.constants.js.map +1 -0
  177. package/dist/infrastructure/transport-archive.d.ts +5 -0
  178. package/dist/infrastructure/transport-archive.js +157 -0
  179. package/dist/infrastructure/transport-archive.js.map +1 -0
  180. package/dist/infrastructure/transport-archive.types.d.ts +17 -0
  181. package/dist/infrastructure/transport-archive.types.js +2 -0
  182. package/dist/infrastructure/transport-archive.types.js.map +1 -0
  183. package/dist/infrastructure/transport-artifact-store.d.ts +3 -0
  184. package/dist/infrastructure/transport-artifact-store.js +31 -0
  185. package/dist/infrastructure/transport-artifact-store.js.map +1 -0
  186. package/dist/infrastructure/transport-artifact-store.types.d.ts +4 -0
  187. package/dist/infrastructure/transport-artifact-store.types.js +2 -0
  188. package/dist/infrastructure/transport-artifact-store.types.js.map +1 -0
  189. package/dist/infrastructure/transport-checkpoint.d.ts +5 -0
  190. package/dist/infrastructure/transport-checkpoint.js +105 -0
  191. package/dist/infrastructure/transport-checkpoint.js.map +1 -0
  192. package/dist/infrastructure/transport-checkpoint.types.d.ts +9 -0
  193. package/dist/infrastructure/transport-checkpoint.types.js +2 -0
  194. package/dist/infrastructure/transport-checkpoint.types.js.map +1 -0
  195. package/dist/infrastructure/transport-conversations.d.ts +4 -0
  196. package/dist/infrastructure/transport-conversations.js +69 -0
  197. package/dist/infrastructure/transport-conversations.js.map +1 -0
  198. package/dist/infrastructure/transport-conversations.types.d.ts +4 -0
  199. package/dist/infrastructure/transport-conversations.types.js +2 -0
  200. package/dist/infrastructure/transport-conversations.types.js.map +1 -0
  201. package/dist/infrastructure/transport-envelope.d.ts +7 -0
  202. package/dist/infrastructure/transport-envelope.js +47 -0
  203. package/dist/infrastructure/transport-envelope.js.map +1 -0
  204. package/dist/infrastructure/transport-journal.d.ts +6 -0
  205. package/dist/infrastructure/transport-journal.js +93 -0
  206. package/dist/infrastructure/transport-journal.js.map +1 -0
  207. package/dist/infrastructure/transport-journal.types.d.ts +10 -0
  208. package/dist/infrastructure/transport-journal.types.js +2 -0
  209. package/dist/infrastructure/transport-journal.types.js.map +1 -0
  210. package/dist/infrastructure/transport-json.d.ts +6 -0
  211. package/dist/infrastructure/transport-json.js +46 -0
  212. package/dist/infrastructure/transport-json.js.map +1 -0
  213. package/dist/infrastructure/transport-reservations.d.ts +5 -0
  214. package/dist/infrastructure/transport-reservations.js +89 -0
  215. package/dist/infrastructure/transport-reservations.js.map +1 -0
  216. package/dist/infrastructure/transport-reservations.types.d.ts +4 -0
  217. package/dist/infrastructure/transport-reservations.types.js +2 -0
  218. package/dist/infrastructure/transport-reservations.types.js.map +1 -0
  219. package/dist/infrastructure/transport.constants.d.ts +8 -0
  220. package/dist/infrastructure/transport.constants.js +9 -0
  221. package/dist/infrastructure/transport.constants.js.map +1 -0
  222. package/dist/infrastructure/workflow-checkpoint.js +7 -0
  223. package/dist/infrastructure/workflow-checkpoint.js.map +1 -1
  224. package/dist/infrastructure/workflow-checkpoint.types.d.ts +3 -1
  225. package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -1
  226. package/dist/providers/agents.d.ts +1 -1
  227. package/dist/providers/agents.js.map +1 -1
  228. package/dist/providers/daytona-command.constants.d.ts +2 -0
  229. package/dist/providers/daytona-command.constants.js +13 -0
  230. package/dist/providers/daytona-command.constants.js.map +1 -0
  231. package/dist/providers/daytona-command.js +9 -3
  232. package/dist/providers/daytona-command.js.map +1 -1
  233. package/dist/providers/daytona-output.d.ts +4 -0
  234. package/dist/providers/daytona-output.js +37 -0
  235. package/dist/providers/daytona-output.js.map +1 -0
  236. package/dist/providers/daytona-terminal.js +3 -1
  237. package/dist/providers/daytona-terminal.js.map +1 -1
  238. package/dist/providers/vercel-command.js +2 -2
  239. package/dist/providers/vercel-command.js.map +1 -1
  240. package/package.json +31 -6
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-provision.js","sourceRoot":"","sources":["../../src/application/sandbox-provision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,cAAc,E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AO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { lstat } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport { invariant } from \"../domain/errors.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { executeProcess } from \"../infrastructure/process.ts\";\nimport { resolveVariables } from \"../infrastructure/settings.ts\";\nimport { registerResourceActivity } from \"../infrastructure/resource-activity.ts\";\nimport type { ResourceActivity } from \"../infrastructure/resource-activity.types.ts\";\nimport { trackedSandboxLease } from \"./sandbox-activity.ts\";\nimport { boundedTransfers } from \"../infrastructure/transfer.ts\";\nimport { docker } from \"../providers/docker.ts\";\nimport { prepareAdapter } from \"./agent-bootstrap.ts\";\nimport { hooks } from \"./lifecycle-hooks.ts\";\nimport type { SandboxOptions } from \"./outpost.types.ts\";\nimport { uploadFiles } from \"./remote-upload.ts\";\nimport { seedRemote } from \"./remote-workspace.ts\";\nimport type { RemoteSync } from \"./remote-workspace.types.ts\";\nimport type { ProvisionedSandbox } from \"./sandbox-session.types.ts\";\nimport { startupFailure } from \"./startup-recovery.ts\";\nimport { workspaces } from \"./workspace-registry.ts\";\nimport { openWorkspace } from \"./workspace.ts\";\n\nexport async function provisionSandbox(\n options: SandboxOptions,\n): Promise<ProvisionedSandbox> {\n options.signal?.throwIfAborted();\n const provider = options.provider ?? docker();\n if (provider.placement === \"remote\" && !options.workspace && !options.branch)\n options = { ...options, branch: { mode: \"integrate\" } };\n invariant(\n !options.workspace ||\n (!options.repository &&\n !options.branch &&\n !options.copies &&\n !options.storageQuota),\n \"A supplied workspace owns its repository, branch, copied inputs and storage quota\",\n );\n const owned = !options.workspace;\n invariant(\n provider.placement !== \"remote\" ||\n ((options.workspace?.policy ?? options.branch)?.mode !== \"current\" &&\n (options.workspace || options.branch)),\n \"Remote providers require a named or integration workspace\",\n );\n const workspace = options.workspace ?? (await openWorkspace(options));\n const state = workspaces.get(workspace);\n invariant(\n state && !state.closed && !state.active,\n \"Workspace must be open and cannot belong to another sandbox\",\n );\n state.active = true;\n const lifecycle = options.hooks ?? state.hooks;\n const stop = new AbortController();\n const setupSignal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n let lease: SandboxLease | undefined, sync: RemoteSync | undefined;\n let activity: ResourceActivity | undefined;\n let acquisitionStarted = false;\n const prepared = new Map<AgentAdapter, AgentAdapter>();\n const staging = join(\n workspace.repository,\n \".outpost\",\n \"recovery\",\n \"conversations\",\n );\n try {\n activity = await registerResourceActivity({\n repository: workspace.repository,\n workspace: workspace.directory,\n provider: provider.name,\n placement: provider.placement,\n });\n const configured = await resolveVariables(\n workspace.repository,\n {},\n provider.variables,\n );\n const name = (\n await git(workspace.repository, [\"config\", \"--get\", \"user.name\"]).catch(\n () => \"Outpost\",\n )\n ).trim();\n const email = (\n await git(workspace.repository, [\"config\", \"--get\", \"user.email\"]).catch(\n () => \"outpost@localhost\",\n )\n ).trim();\n const variables = {\n GIT_AUTHOR_NAME: name,\n GIT_COMMITTER_NAME: name,\n GIT_AUTHOR_EMAIL: email,\n GIT_COMMITTER_EMAIL: email,\n ...configured,\n };\n acquisitionStarted = true;\n lease = boundedTransfers(\n trackedSandboxLease(\n await provider.acquire({\n repository: workspace.repository,\n directory: workspace.directory,\n gitDirectories: workspace.gitDirectories,\n variables,\n signal: setupSignal,\n }),\n activity,\n ),\n {\n ...(options.limits?.copyMs\n ? { deadlineMs: options.limits.copyMs }\n : {}),\n },\n );\n if (provider.placement === \"remote\") {\n sync = await seedRemote(workspace, lease, {\n ...(options.includeUncommitted ? { includeUncommitted: true } : {}),\n ...(options.limits ? { limits: options.limits } : {}),\n signal: setupSignal,\n });\n const copiedFiles: string[] = [];\n for (const path of options.copies ?? []) {\n const info = await lstat(join(workspace.directory, path)).catch(\n (error) => {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\")\n return undefined;\n throw error;\n },\n );\n if (!info) continue;\n if (info.isFile() || info.isSymbolicLink()) {\n copiedFiles.push(path.replaceAll(\"\\\\\", \"/\"));\n continue;\n }\n await lease.upload(\n join(workspace.directory, path),\n posix.join(lease.root, path.replaceAll(\"\\\\\", \"/\")),\n { signal: setupSignal },\n );\n }\n await uploadFiles(lease, workspace.directory, [...new Set(copiedFiles)], {\n signal: setupSignal,\n });\n if (options.bootstrap !== false && options.agent)\n prepared.set(\n options.agent,\n await prepareAdapter(options.agent, lease, setupSignal),\n );\n }\n const initialized = await Promise.allSettled(\n [\n hooks(\n lifecycle?.hostReady ?? [],\n workspace.directory,\n executeProcess,\n setupSignal,\n ),\n hooks(\n lifecycle?.sandboxReady ?? [],\n lease.root,\n lease.invoke.bind(lease),\n setupSignal,\n true,\n ),\n ].map((pending) =>\n pending.catch((cause) => {\n stop.abort(cause);\n throw cause;\n }),\n ),\n );\n const failure = initialized.find((item) => item.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n await activity.phase(\"ready\");\n } catch (cause) {\n await startupFailure(workspace, cause, options);\n const allocationUncertain = acquisitionStarted && !lease;\n let cleanupFailed = allocationUncertain;\n await activity?.phase(\"closing\").catch(() => {\n cleanupFailed = true;\n });\n await lease?.release().catch(() => {\n cleanupFailed = true;\n });\n if (activity && !(await activity.idle())) cleanupFailed = true;\n state.active = false;\n if (owned)\n await workspace.close({ preserve: cleanupFailed }).catch(() => {\n cleanupFailed = true;\n });\n if (cleanupFailed)\n await activity\n ?.phase(allocationUncertain ? \"allocation-uncertain\" : \"cleanup-failed\")\n .catch(() => undefined);\n if (!cleanupFailed) await activity?.remove().catch(() => undefined);\n throw cause;\n }\n\n return {\n options,\n provider,\n workspace,\n state,\n owned,\n stop,\n runtime: lease,\n activity,\n sync,\n prepared,\n staging,\n };\n}\n"]}
1
+ {"version":3,"file":"sandbox-provision.js","sourceRoot":"","sources":["../../src/application/sandbox-provision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB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AAa;YACf,MAAM,QAAQ;gBACZ,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,gBAAgB,CAAC;iBACvE,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC,aAAa;YAAE,MAAM,QAAQ,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACpE,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO;QACP,QAAQ;QACR,SAAS;QACT,KAAK;QACL,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,KAAK;QACd,QAAQ;QACR,IAAI;QACJ,QAAQ;QACR,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { lstat } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport { invariant } from \"../domain/errors.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { executeProcess } from \"../infrastructure/process.ts\";\nimport { resolveVariables } from \"../infrastructure/settings.ts\";\nimport { registerResourceActivity } from \"../infrastructure/resource-activity.ts\";\nimport type { ResourceActivity } from \"../infrastructure/resource-activity.types.ts\";\nimport { trackedSandboxLease } from \"./sandbox-activity.ts\";\nimport { boundedTransfers } from \"../infrastructure/transfer.ts\";\nimport { docker } from \"../providers/docker.ts\";\nimport { prepareAdapter } from \"./agent-bootstrap.ts\";\nimport { hooks } from \"./lifecycle-hooks.ts\";\nimport type { SandboxOptions } from \"./outpost.types.ts\";\nimport { uploadFiles } from \"./remote-upload.ts\";\nimport { seedRemote } from \"./remote-workspace.ts\";\nimport type { RemoteSync } from \"./remote-workspace.types.ts\";\nimport type { ProvisionedSandbox } from \"./sandbox-session.types.ts\";\nimport { startupFailure } from \"./startup-recovery.ts\";\nimport { workspaces } from \"./workspace-registry.ts\";\nimport { openWorkspace } from \"./workspace.ts\";\n\nexport async function provisionSandbox(\n options: SandboxOptions,\n): Promise<ProvisionedSandbox> {\n options.signal?.throwIfAborted();\n const provider = options.provider ?? docker();\n if (provider.placement === \"remote\" && !options.workspace && !options.branch)\n options = { ...options, branch: { mode: \"integrate\" } };\n invariant(\n !options.workspace ||\n (!options.repository &&\n !options.branch &&\n !options.copies &&\n !options.storageQuota),\n \"A supplied workspace owns its repository, branch, copied inputs and storage quota\",\n );\n const owned = !options.workspace;\n invariant(\n provider.placement !== \"remote\" ||\n ((options.workspace?.policy ?? options.branch)?.mode !== \"current\" &&\n (options.workspace || options.branch)),\n \"Remote providers require a named or integration workspace\",\n );\n const workspace = options.workspace ?? (await openWorkspace(options));\n const state = workspaces.get(workspace);\n invariant(\n state && !state.closed && !state.active,\n \"Workspace must be open and cannot belong to another sandbox\",\n );\n state.active = true;\n const lifecycle = options.hooks ?? state.hooks;\n const stop = new AbortController();\n const setupSignal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n let lease: SandboxLease | undefined, sync: RemoteSync | undefined;\n let activity: ResourceActivity | undefined;\n let acquisitionStarted = false;\n const prepared = new Map<AgentAdapter, AgentAdapter>();\n const staging = join(\n workspace.repository,\n \".outpost\",\n \"recovery\",\n \"conversations\",\n );\n try {\n activity = await registerResourceActivity({\n repository: workspace.repository,\n ...(options.activityTransport\n ? { transporter: options.activityTransport }\n : {}),\n workspace: workspace.directory,\n provider: provider.name,\n placement: provider.placement,\n });\n const configured = await resolveVariables(\n workspace.repository,\n {},\n provider.variables,\n );\n const name = (\n await git(workspace.repository, [\"config\", \"--get\", \"user.name\"]).catch(\n () => \"Outpost\",\n )\n ).trim();\n const email = (\n await git(workspace.repository, [\"config\", \"--get\", \"user.email\"]).catch(\n () => \"outpost@localhost\",\n )\n ).trim();\n const variables = {\n GIT_AUTHOR_NAME: name,\n GIT_COMMITTER_NAME: name,\n GIT_AUTHOR_EMAIL: email,\n GIT_COMMITTER_EMAIL: email,\n ...configured,\n };\n acquisitionStarted = true;\n lease = boundedTransfers(\n trackedSandboxLease(\n await provider.acquire({\n repository: workspace.repository,\n directory: workspace.directory,\n gitDirectories: workspace.gitDirectories,\n variables,\n signal: setupSignal,\n }),\n activity,\n ),\n {\n ...(options.limits?.copyMs\n ? { deadlineMs: options.limits.copyMs }\n : {}),\n },\n );\n if (provider.placement === \"remote\") {\n sync = await seedRemote(workspace, lease, {\n ...(options.recoveryTransport\n ? { recoveryTransport: options.recoveryTransport }\n : {}),\n ...(options.includeUncommitted ? { includeUncommitted: true } : {}),\n ...(options.limits ? { limits: options.limits } : {}),\n signal: setupSignal,\n });\n const copiedFiles: string[] = [];\n for (const path of options.copies ?? []) {\n const info = await lstat(join(workspace.directory, path)).catch(\n (error) => {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\")\n return undefined;\n throw error;\n },\n );\n if (!info) continue;\n if (info.isFile() || info.isSymbolicLink()) {\n copiedFiles.push(path.replaceAll(\"\\\\\", \"/\"));\n continue;\n }\n await lease.upload(\n join(workspace.directory, path),\n posix.join(lease.root, path.replaceAll(\"\\\\\", \"/\")),\n { signal: setupSignal },\n );\n }\n await uploadFiles(lease, workspace.directory, [...new Set(copiedFiles)], {\n signal: setupSignal,\n });\n if (options.bootstrap !== false && options.agent)\n prepared.set(\n options.agent,\n await prepareAdapter(options.agent, lease, setupSignal),\n );\n }\n const initialized = await Promise.allSettled(\n [\n hooks(\n lifecycle?.hostReady ?? [],\n workspace.directory,\n executeProcess,\n setupSignal,\n ),\n hooks(\n lifecycle?.sandboxReady ?? [],\n lease.root,\n lease.invoke.bind(lease),\n setupSignal,\n true,\n ),\n ].map((pending) =>\n pending.catch((cause) => {\n stop.abort(cause);\n throw cause;\n }),\n ),\n );\n const failure = initialized.find((item) => item.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n await activity.phase(\"ready\");\n } catch (cause) {\n await startupFailure(workspace, cause, options);\n const allocationUncertain = acquisitionStarted && !lease;\n let cleanupFailed = allocationUncertain;\n await activity?.phase(\"closing\").catch(() => {\n cleanupFailed = true;\n });\n await lease?.release().catch(() => {\n cleanupFailed = true;\n });\n if (activity && !(await activity.idle())) cleanupFailed = true;\n state.active = false;\n if (owned)\n await workspace.close({ preserve: cleanupFailed }).catch(() => {\n cleanupFailed = true;\n });\n if (cleanupFailed)\n await activity\n ?.phase(allocationUncertain ? \"allocation-uncertain\" : \"cleanup-failed\")\n .catch(() => undefined);\n if (!cleanupFailed) await activity?.remove().catch(() => undefined);\n throw cause;\n }\n\n return {\n options,\n provider,\n workspace,\n state,\n owned,\n stop,\n runtime: lease,\n activity,\n sync,\n prepared,\n staging,\n };\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { reserveTransportStorage } from "../infrastructure/transport-reservations.js";
1
2
  import { directory } from "../infrastructure/files.js";
2
3
  import { git } from "../infrastructure/git/command.js";
3
4
  import { reserveStorage } from "../infrastructure/storage-reservations.js";
@@ -5,6 +6,8 @@ export async function reserveRecoveryStorage(options) {
5
6
  options.signal?.throwIfAborted();
6
7
  const requested = await directory(options.repository);
7
8
  const root = await directory((await git(requested, ["rev-parse", "--show-toplevel"])).trim());
9
+ if (options.transporter)
10
+ return reserveTransportStorage(options.transporter, root, options);
8
11
  return reserveStorage(root, options);
9
12
  }
10
13
  //# sourceMappingURL=storage-reservation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-reservation.js","sourceRoot":"","sources":["../../src/application/storage-reservation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAI3E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAA0C;IAE1C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,MAAM,SAAS,CAC1B,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAChE,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { directory } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { reserveStorage } from \"../infrastructure/storage-reservations.ts\";\nimport type { StorageReservation } from \"../infrastructure/storage-reservations.types.ts\";\nimport type { RecoveryStorageReservationOptions } from \"./storage-reservation.types.ts\";\n\nexport async function reserveRecoveryStorage(\n options: RecoveryStorageReservationOptions,\n): Promise<StorageReservation> {\n options.signal?.throwIfAborted();\n const requested = await directory(options.repository);\n const root = await directory(\n (await git(requested, [\"rev-parse\", \"--show-toplevel\"])).trim(),\n );\n return reserveStorage(root, options);\n}\n"]}
1
+ {"version":3,"file":"storage-reservation.js","sourceRoot":"","sources":["../../src/application/storage-reservation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAI3E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAA0C;IAE1C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,MAAM,SAAS,CAC1B,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAChE,CAAC;IACF,IAAI,OAAO,CAAC,WAAW;QACrB,OAAO,uBAAuB,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACrE,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { reserveTransportStorage } from \"../infrastructure/transport-reservations.ts\";\nimport { directory } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { reserveStorage } from \"../infrastructure/storage-reservations.ts\";\nimport type { StorageReservation } from \"../infrastructure/storage-reservations.types.ts\";\nimport type { RecoveryStorageReservationOptions } from \"./storage-reservation.types.ts\";\n\nexport async function reserveRecoveryStorage(\n options: RecoveryStorageReservationOptions,\n): Promise<StorageReservation> {\n options.signal?.throwIfAborted();\n const requested = await directory(options.repository);\n const root = await directory(\n (await git(requested, [\"rev-parse\", \"--show-toplevel\"])).trim(),\n );\n if (options.transporter)\n return reserveTransportStorage(options.transporter, root, options);\n return reserveStorage(root, options);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { StorageCategoryName } from "../infrastructure/storage-inventory.types.ts";
2
+ export declare const transportCategories: readonly StorageCategoryName[];
@@ -0,0 +1,10 @@
1
+ export const transportCategories = [
2
+ "artifacts",
3
+ "checkpoints",
4
+ "conversations",
5
+ "recovery",
6
+ "logs",
7
+ "reservations",
8
+ "resources",
9
+ ];
10
+ //# sourceMappingURL=transport-inspection.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-inspection.constants.js","sourceRoot":"","sources":["../../src/application/transport-inspection.constants.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,mBAAmB,GAAmC;IACjE,WAAW;IACX,aAAa;IACb,eAAe;IACf,UAAU;IACV,MAAM;IACN,cAAc;IACd,WAAW;CACZ,CAAC","sourcesContent":["import type { StorageCategoryName } from \"../infrastructure/storage-inventory.types.ts\";\nexport const transportCategories: readonly StorageCategoryName[] = [\n \"artifacts\",\n \"checkpoints\",\n \"conversations\",\n \"recovery\",\n \"logs\",\n \"reservations\",\n \"resources\",\n];\n"]}
@@ -0,0 +1,2 @@
1
+ import type { RecoveryInspection, RecoveryInspectionOptions } from "./recovery-inspection.types.ts";
2
+ export declare function inspectTransportRecovery(options: RecoveryInspectionOptions): Promise<RecoveryInspection>;
@@ -0,0 +1,103 @@
1
+ import { transportDefaults } from "../infrastructure/transport.constants.js";
2
+ import { resourceRecord } from "../infrastructure/resource-activity-inspection.js";
3
+ import { jsonObject } from "../infrastructure/transport-json.js";
4
+ import { invariant, positive } from "../domain/errors.js";
5
+ import { transportCategories } from "./transport-inspection.constants.js";
6
+ export async function inspectTransportRecovery(options) {
7
+ const transporter = options.transporter;
8
+ invariant(transporter, "Transport is required");
9
+ invariant(!options.git && !options.locks, "Transport inspection cannot verify host Git or process locks");
10
+ const maxEntries = positive(options.maxEntries ?? transportDefaults.maxEntries, "maxEntries");
11
+ const buckets = transportCategories.map((name) => ({
12
+ name,
13
+ path: name,
14
+ entries: [],
15
+ }));
16
+ const categories = buckets;
17
+ const usage = {
18
+ bytes: 0,
19
+ files: 0,
20
+ directories: 0,
21
+ symlinks: 0,
22
+ other: 0,
23
+ };
24
+ const issues = [];
25
+ const resources = [];
26
+ let scannedEntries = 0, complete = true;
27
+ for await (const entry of transporter.list()) {
28
+ if (scannedEntries >= maxEntries) {
29
+ complete = false;
30
+ issues.push({ path: "", code: "ENTRY_LIMIT" });
31
+ break;
32
+ }
33
+ scannedEntries++;
34
+ const name = entry.key.split("/")[0];
35
+ const category = buckets.find((category) => category.name === name);
36
+ if (!category) {
37
+ complete = false;
38
+ issues.push({ path: entry.key, code: "UNKNOWN_TRANSPORT_CATEGORY" });
39
+ continue;
40
+ }
41
+ const stored = {
42
+ name: entry.key,
43
+ path: entry.key,
44
+ kind: "file",
45
+ modifiedAt: entry.modifiedAt,
46
+ complete: true,
47
+ bytes: entry.size,
48
+ files: 1,
49
+ directories: 0,
50
+ symlinks: 0,
51
+ other: 0,
52
+ revision: entry.revision,
53
+ };
54
+ category.entries.push(stored);
55
+ usage.bytes += entry.size;
56
+ usage.files++;
57
+ if (options.resources && name === "resources") {
58
+ try {
59
+ const object = await transporter.read(entry.key);
60
+ invariant(object?.revision === entry.revision, "Resource changed during inspection");
61
+ const record = resourceRecord(jsonObject(object));
62
+ resources.push({
63
+ path: entry.key,
64
+ record,
65
+ ownership: { status: "unknown", reason: "REMOTE_OWNER_UNVERIFIED" },
66
+ });
67
+ }
68
+ catch {
69
+ issues.push({ path: entry.key, code: "RESOURCE_RECORD_UNREADABLE" });
70
+ complete = false;
71
+ resources.push({
72
+ path: entry.key,
73
+ ownership: {
74
+ status: "unknown",
75
+ reason: "RESOURCE_RECORD_UNREADABLE",
76
+ },
77
+ });
78
+ }
79
+ }
80
+ }
81
+ return {
82
+ repository: options.repository ?? "",
83
+ root: "transport",
84
+ activity: "unverified",
85
+ categories,
86
+ usage,
87
+ issues,
88
+ complete,
89
+ scannedEntries,
90
+ maxEntries,
91
+ ...(options.resources
92
+ ? {
93
+ resources: {
94
+ scope: "recorded-sandboxes",
95
+ complete,
96
+ entries: resources,
97
+ issues,
98
+ },
99
+ }
100
+ : {}),
101
+ };
102
+ }
103
+ //# sourceMappingURL=transport-inspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-inspection.js","sourceRoot":"","sources":["../../src/application/transport-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAW7E,OAAO,EAAE,cAAc,EAAE,MAAM,mDAAmD,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAkC;IAElC,MAAM,WAAW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,MAAM,EAAE,yBAAyB,EAAE;iBACpE,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,4BAA4B,EAAE,CAAC,CAAC;gBACrE,QAAQ,GAAG,KAAK,CAAC;gBACjB,SAAS,CAAC,IAAI,CAAC;oBACb,IAAI,EAAE,KAAK,CAAC,GAAG;oBACf,SAAS,EAAE;wBACT,MAAM,EAAE,SAAS;wBACjB,MAAM,EAAE,4BAA4B;qBACrC;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;QACpC,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,YAAY;QACtB,UAAU;QACV,KAAK;QACL,MAAM;QACN,QAAQ;QACR,cAAc;QACd,UAAU;QACV,GAAG,CAAC,OAAO,CAAC,SAAS;YACnB,CAAC,CAAC;gBACE,SAAS,EAAE;oBACT,KAAK,EAAE,oBAAoB;oBAC3B,QAAQ;oBACR,OAAO,EAAE,SAAS;oBAClB,MAAM;iBACP;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { transportDefaults } from \"../infrastructure/transport.constants.ts\";\nimport type {\n RecoveryInspection,\n RecoveryInspectionOptions,\n} from \"./recovery-inspection.types.ts\";\nimport type {\n StorageCategory,\n StorageEntry,\n StorageUsage,\n} from \"../infrastructure/storage-inventory.types.ts\";\nimport type { ResourceInspectionEntry } from \"../infrastructure/resource-activity.types.ts\";\nimport { resourceRecord } from \"../infrastructure/resource-activity-inspection.ts\";\nimport { jsonObject } from \"../infrastructure/transport-json.ts\";\nimport { invariant, positive } from \"../domain/errors.ts\";\nimport { transportCategories } from \"./transport-inspection.constants.ts\";\n\nexport async function inspectTransportRecovery(\n options: RecoveryInspectionOptions,\n): Promise<RecoveryInspection> {\n const transporter = options.transporter;\n invariant(transporter, \"Transport is required\");\n invariant(\n !options.git && !options.locks,\n \"Transport inspection cannot verify host Git or process locks\",\n );\n const maxEntries = positive(\n options.maxEntries ?? transportDefaults.maxEntries,\n \"maxEntries\",\n );\n const buckets = transportCategories.map((name) => ({\n name,\n path: name,\n entries: [] as StorageEntry[],\n }));\n const categories: StorageCategory[] = buckets;\n const usage: StorageUsage = {\n bytes: 0,\n files: 0,\n directories: 0,\n symlinks: 0,\n other: 0,\n };\n const issues = [];\n const resources: ResourceInspectionEntry[] = [];\n let scannedEntries = 0,\n complete = true;\n for await (const entry of transporter.list()) {\n if (scannedEntries >= maxEntries) {\n complete = false;\n issues.push({ path: \"\", code: \"ENTRY_LIMIT\" });\n break;\n }\n scannedEntries++;\n const name = entry.key.split(\"/\")[0];\n const category = buckets.find((category) => category.name === name);\n if (!category) {\n complete = false;\n issues.push({ path: entry.key, code: \"UNKNOWN_TRANSPORT_CATEGORY\" });\n continue;\n }\n const stored = {\n name: entry.key,\n path: entry.key,\n kind: \"file\" as const,\n modifiedAt: entry.modifiedAt,\n complete: true,\n bytes: entry.size,\n files: 1,\n directories: 0,\n symlinks: 0,\n other: 0,\n revision: entry.revision,\n };\n category.entries.push(stored);\n usage.bytes += entry.size;\n usage.files++;\n if (options.resources && name === \"resources\") {\n try {\n const object = await transporter.read(entry.key);\n invariant(\n object?.revision === entry.revision,\n \"Resource changed during inspection\",\n );\n const record = resourceRecord(jsonObject(object));\n resources.push({\n path: entry.key,\n record,\n ownership: { status: \"unknown\", reason: \"REMOTE_OWNER_UNVERIFIED\" },\n });\n } catch {\n issues.push({ path: entry.key, code: \"RESOURCE_RECORD_UNREADABLE\" });\n complete = false;\n resources.push({\n path: entry.key,\n ownership: {\n status: \"unknown\",\n reason: \"RESOURCE_RECORD_UNREADABLE\",\n },\n });\n }\n }\n }\n return {\n repository: options.repository ?? \"\",\n root: \"transport\",\n activity: \"unverified\",\n categories,\n usage,\n issues,\n complete,\n scannedEntries,\n maxEntries,\n ...(options.resources\n ? {\n resources: {\n scope: \"recorded-sandboxes\",\n complete,\n entries: resources,\n issues,\n },\n }\n : {}),\n };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { TransportStoreOptions } from "../domain/transport.types.ts";
2
+ import type { RecoveryRetentionOptions, RecoveryRetentionPlan, RecoveryPruneResult } from "./recovery-retention.types.ts";
3
+ export declare function planTransportRetention(options: RecoveryRetentionOptions): Promise<RecoveryRetentionPlan>;
4
+ export declare function pruneTransportRetention(plan: RecoveryRetentionPlan, options: TransportStoreOptions): Promise<RecoveryPruneResult>;
@@ -0,0 +1,153 @@
1
+ import { invariant } from "../domain/errors.js";
2
+ import { inspectTransportRecovery } from "./transport-inspection.js";
3
+ import { journalSnapshot } from "../infrastructure/transport-journal.js";
4
+ import { jsonObject } from "../infrastructure/transport-json.js";
5
+ import { retentionPolicy } from "./recovery-retention-policy.js";
6
+ export async function planTransportRetention(options) {
7
+ const transporter = options.transporter;
8
+ invariant(transporter, "Transport is required");
9
+ retentionPolicy(options.policy);
10
+ invariant(!options.policy.scopes.includes("clean-workspaces") &&
11
+ options.policy.maxWorkspaces === undefined, "Transport retention cannot inspect local workspaces");
12
+ const inspection = await inspectTransportRecovery(options);
13
+ const inspectedAt = new Date().toISOString();
14
+ const entries = [];
15
+ const handled = new Set();
16
+ for (const category of inspection.categories) {
17
+ for (const entry of category.entries) {
18
+ if (handled.has(entry.path))
19
+ continue;
20
+ let eligible = false, reason = "RECOVERY_DATA_PROTECTED";
21
+ let objects = [];
22
+ if (category.name === "logs") {
23
+ const prefix = entry.path.slice(0, entry.path.lastIndexOf("/") + 1);
24
+ const group = category.entries.filter((value) => value.path.startsWith(prefix));
25
+ objects = group.map((value) => {
26
+ invariant(value.revision && value.modifiedAt, "Missing transport entry version");
27
+ return {
28
+ key: value.path,
29
+ revision: value.revision,
30
+ size: value.bytes,
31
+ modifiedAt: value.modifiedAt,
32
+ };
33
+ });
34
+ for (const object of objects)
35
+ handled.add(object.key);
36
+ const index = group.find((value) => value.path === prefix + "index");
37
+ reason = "LOG_ACTIVITY_OR_CONTENT_UNKNOWN";
38
+ if (index && options.policy.scopes.includes("closed-logs")) {
39
+ try {
40
+ const current = await transporter.read(index.path);
41
+ if (current?.revision === index.revision &&
42
+ journalSnapshot(jsonObject(current)).closed) {
43
+ eligible =
44
+ inspection.complete &&
45
+ objects.every((value) => Date.parse(inspectedAt) - Date.parse(value.modifiedAt) >=
46
+ options.policy.minAgeMs);
47
+ reason = eligible
48
+ ? "ELIGIBLE"
49
+ : "RETENTION_AGE_OR_INCOMPLETE_INVENTORY";
50
+ }
51
+ }
52
+ catch {
53
+ reason = "LOG_ACTIVITY_OR_CONTENT_UNKNOWN";
54
+ }
55
+ }
56
+ const indexObject = objects.find((value) => value.key === prefix + "index");
57
+ entries.push({
58
+ path: prefix + "index",
59
+ category: category.name,
60
+ bytes: objects.reduce((sum, value) => sum + value.size, 0),
61
+ eligible,
62
+ reason,
63
+ objects,
64
+ ...(indexObject
65
+ ? {
66
+ revision: indexObject.revision,
67
+ modifiedAt: indexObject.modifiedAt,
68
+ }
69
+ : {}),
70
+ });
71
+ continue;
72
+ }
73
+ entries.push({
74
+ path: entry.path,
75
+ category: category.name,
76
+ bytes: entry.bytes,
77
+ eligible,
78
+ reason,
79
+ ...(entry.revision ? { revision: entry.revision } : {}),
80
+ ...(entry.modifiedAt ? { modifiedAt: entry.modifiedAt } : {}),
81
+ });
82
+ }
83
+ }
84
+ const projectedBytes = inspection.usage.bytes -
85
+ entries
86
+ .filter((entry) => entry.eligible)
87
+ .reduce((sum, entry) => sum + entry.bytes, 0);
88
+ return {
89
+ repository: inspection.repository,
90
+ source: "transport",
91
+ policy: structuredClone(options.policy),
92
+ inspectedAt,
93
+ inspection,
94
+ entries,
95
+ complete: inspection.complete,
96
+ usageBytes: inspection.usage.bytes,
97
+ projectedBytes,
98
+ quota: !inspection.complete
99
+ ? "unknown"
100
+ : options.policy.maxBytes !== undefined &&
101
+ projectedBytes > options.policy.maxBytes
102
+ ? "exceeded"
103
+ : "within",
104
+ };
105
+ }
106
+ export async function pruneTransportRetention(plan, options) {
107
+ invariant(plan.complete, "Cannot prune an incomplete retention plan");
108
+ retentionPolicy(plan.policy);
109
+ const removed = [], retained = [];
110
+ for (const candidate of plan.entries.filter((entry) => entry.eligible)) {
111
+ const fresh = await planTransportRetention({
112
+ transporter: options.transporter,
113
+ policy: plan.policy,
114
+ repository: plan.repository,
115
+ });
116
+ const entry = fresh.entries.find((entry) => entry.path === candidate.path);
117
+ if (!entry?.eligible ||
118
+ entry.revision !== candidate.revision ||
119
+ JSON.stringify(entry.objects) !== JSON.stringify(candidate.objects)) {
120
+ retained.push({ path: candidate.path, reason: "PLAN_CHANGED" });
121
+ continue;
122
+ }
123
+ try {
124
+ invariant(entry.revision && entry.objects, "Missing log revisions");
125
+ await options.transporter.remove(entry.path, {
126
+ ifRevision: entry.revision,
127
+ });
128
+ for (const object of entry.objects) {
129
+ if (object.key !== entry.path)
130
+ await options.transporter.remove(object.key, {
131
+ ifRevision: object.revision,
132
+ });
133
+ }
134
+ removed.push(entry.path);
135
+ }
136
+ catch {
137
+ retained.push({
138
+ path: entry.path,
139
+ reason: "REVALIDATION_OR_REMOVAL_FAILED",
140
+ });
141
+ }
142
+ }
143
+ return {
144
+ removed,
145
+ retained,
146
+ after: await planTransportRetention({
147
+ transporter: options.transporter,
148
+ policy: plan.policy,
149
+ repository: plan.repository,
150
+ }),
151
+ };
152
+ }
153
+ //# sourceMappingURL=transport-retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-retention.js","sourceRoot":"","sources":["../../src/application/transport-retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAWhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,UAAU,EAA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Q,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,MAAM,EAAE,gCAAgC;aACzC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO;QACL,OAAO;QACP,QAAQ;QACR,KAAK,EAAE,MAAM,sBAAsB,CAAC;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { invariant } from \"../domain/errors.ts\";\nimport type {\n TransportStoreOptions,\n TransportEntry,\n} from \"../domain/transport.types.ts\";\nimport type {\n RecoveryRetentionOptions,\n RecoveryRetentionPlan,\n RecoveryRetentionEntry,\n RecoveryPruneResult,\n} from \"./recovery-retention.types.ts\";\nimport { inspectTransportRecovery } from \"./transport-inspection.ts\";\nimport { journalSnapshot } from \"../infrastructure/transport-journal.ts\";\nimport { jsonObject } from \"../infrastructure/transport-json.ts\";\nimport { retentionPolicy } from \"./recovery-retention-policy.ts\";\n\nexport async function planTransportRetention(\n options: RecoveryRetentionOptions,\n): Promise<RecoveryRetentionPlan> {\n const transporter = options.transporter;\n invariant(transporter, \"Transport is required\");\n retentionPolicy(options.policy);\n invariant(\n !options.policy.scopes.includes(\"clean-workspaces\") &&\n options.policy.maxWorkspaces === undefined,\n \"Transport retention cannot inspect local workspaces\",\n );\n const inspection = await inspectTransportRecovery(options);\n const inspectedAt = new Date().toISOString();\n const entries: RecoveryRetentionEntry[] = [];\n const handled = new Set<string>();\n for (const category of inspection.categories) {\n for (const entry of category.entries) {\n if (handled.has(entry.path)) continue;\n let eligible = false,\n reason = \"RECOVERY_DATA_PROTECTED\";\n let objects: TransportEntry[] = [];\n if (category.name === \"logs\") {\n const prefix = entry.path.slice(0, entry.path.lastIndexOf(\"/\") + 1);\n const group = category.entries.filter((value) =>\n value.path.startsWith(prefix),\n );\n objects = group.map((value) => {\n invariant(\n value.revision && value.modifiedAt,\n \"Missing transport entry version\",\n );\n return {\n key: value.path,\n revision: value.revision,\n size: value.bytes,\n modifiedAt: value.modifiedAt,\n };\n });\n for (const object of objects) handled.add(object.key);\n const index = group.find((value) => value.path === prefix + \"index\");\n reason = \"LOG_ACTIVITY_OR_CONTENT_UNKNOWN\";\n if (index && options.policy.scopes.includes(\"closed-logs\")) {\n try {\n const current = await transporter.read(index.path);\n if (\n current?.revision === index.revision &&\n journalSnapshot(jsonObject(current)).closed\n ) {\n eligible =\n inspection.complete &&\n objects.every(\n (value) =>\n Date.parse(inspectedAt) - Date.parse(value.modifiedAt) >=\n options.policy.minAgeMs,\n );\n reason = eligible\n ? \"ELIGIBLE\"\n : \"RETENTION_AGE_OR_INCOMPLETE_INVENTORY\";\n }\n } catch {\n reason = \"LOG_ACTIVITY_OR_CONTENT_UNKNOWN\";\n }\n }\n const indexObject = objects.find(\n (value) => value.key === prefix + \"index\",\n );\n entries.push({\n path: prefix + \"index\",\n category: category.name,\n bytes: objects.reduce((sum, value) => sum + value.size, 0),\n eligible,\n reason,\n objects,\n ...(indexObject\n ? {\n revision: indexObject.revision,\n modifiedAt: indexObject.modifiedAt,\n }\n : {}),\n });\n continue;\n }\n entries.push({\n path: entry.path,\n category: category.name,\n bytes: entry.bytes,\n eligible,\n reason,\n ...(entry.revision ? { revision: entry.revision } : {}),\n ...(entry.modifiedAt ? { modifiedAt: entry.modifiedAt } : {}),\n });\n }\n }\n const projectedBytes =\n inspection.usage.bytes -\n entries\n .filter((entry) => entry.eligible)\n .reduce((sum, entry) => sum + entry.bytes, 0);\n return {\n repository: inspection.repository,\n source: \"transport\",\n policy: structuredClone(options.policy),\n inspectedAt,\n inspection,\n entries,\n complete: inspection.complete,\n usageBytes: inspection.usage.bytes,\n projectedBytes,\n quota: !inspection.complete\n ? \"unknown\"\n : options.policy.maxBytes !== undefined &&\n projectedBytes > options.policy.maxBytes\n ? \"exceeded\"\n : \"within\",\n };\n}\n\nexport async function pruneTransportRetention(\n plan: RecoveryRetentionPlan,\n options: TransportStoreOptions,\n): Promise<RecoveryPruneResult> {\n invariant(plan.complete, \"Cannot prune an incomplete retention plan\");\n retentionPolicy(plan.policy);\n const removed: string[] = [],\n retained = [];\n for (const candidate of plan.entries.filter((entry) => entry.eligible)) {\n const fresh = await planTransportRetention({\n transporter: options.transporter,\n policy: plan.policy,\n repository: plan.repository,\n });\n const entry = fresh.entries.find((entry) => entry.path === candidate.path);\n if (\n !entry?.eligible ||\n entry.revision !== candidate.revision ||\n JSON.stringify(entry.objects) !== JSON.stringify(candidate.objects)\n ) {\n retained.push({ path: candidate.path, reason: \"PLAN_CHANGED\" });\n continue;\n }\n try {\n invariant(entry.revision && entry.objects, \"Missing log revisions\");\n await options.transporter.remove(entry.path, {\n ifRevision: entry.revision,\n });\n for (const object of entry.objects) {\n if (object.key !== entry.path)\n await options.transporter.remove(object.key, {\n ifRevision: object.revision,\n });\n }\n removed.push(entry.path);\n } catch {\n retained.push({\n path: entry.path,\n reason: \"REVALIDATION_OR_REMOVAL_FAILED\",\n });\n }\n }\n return {\n removed,\n retained,\n after: await planTransportRetention({\n transporter: options.transporter,\n policy: plan.policy,\n repository: plan.repository,\n }),\n };\n}\n"]}
@@ -1,28 +1,65 @@
1
- import { parseArgs } from "node:util";
1
+ import { Command, CommanderError, Option } from "commander";
2
2
  import { recoveryCommand } from "./recovery-command.js";
3
3
  import { doctorCommand } from "./doctor-command.js";
4
4
  import { imageCommand } from "./image-command.js";
5
5
  import { initializeCommand } from "./init-command.js";
6
- import { cliOptions, help } from "./main.constants.js";
6
+ import { cliOptions, commandOptions } from "./main.constants.js";
7
7
  export async function runCli(args = process.argv.slice(2)) {
8
- const invocation = parseArgs({
9
- args,
10
- allowPositionals: true,
11
- options: cliOptions,
12
- });
13
- if (invocation.values.help || !invocation.positionals.length) {
14
- process.stdout.write(help);
15
- return;
16
- }
17
- const commands = {
18
- doctor: doctorCommand,
19
- recovery: recoveryCommand,
8
+ const program = new Command()
9
+ .name("outpost")
10
+ .description("Outpost — sandboxed coding agents and workflows")
11
+ .exitOverride()
12
+ .configureOutput({ writeErr: () => { } });
13
+ const handlers = {
20
14
  init: initializeCommand,
15
+ doctor: doctorCommand,
21
16
  image: imageCommand,
17
+ recovery: recoveryCommand,
22
18
  };
23
- const name = invocation.positionals[0];
24
- if (!Object.hasOwn(commands, name))
25
- throw new Error("Unknown command. Run outpost --help.");
26
- await commands[name](invocation);
19
+ for (const [name, definition] of Object.entries(commandOptions)) {
20
+ const path = name.split(" ");
21
+ let command = program;
22
+ for (const part of path) {
23
+ command =
24
+ command.commands.find((item) => item.name() === part) ??
25
+ command.command(part);
26
+ }
27
+ command.description(definition.description);
28
+ for (const key of definition.options) {
29
+ const configuration = cliOptions[key];
30
+ const short = "short" in configuration ? `-${configuration.short}, ` : "";
31
+ command.addOption(new Option(`${short}--${key}${configuration.type === "string" ? " <value>" : ""}`, configuration.description));
32
+ }
33
+ if (name === "init")
34
+ command.addOption(new Option("--no-build", "Skip automatic container image build").default(undefined));
35
+ command.action(async () => {
36
+ const values = {};
37
+ const parsed = command.opts();
38
+ for (const option of command.options) {
39
+ const value = parsed[option.attributeName()];
40
+ if (typeof value === "string" || typeof value === "boolean")
41
+ values[option.long.replace(/^--(?:no-)?/, "")] = value;
42
+ }
43
+ await handlers[path[0]]({
44
+ values: values,
45
+ positionals: path,
46
+ });
47
+ });
48
+ }
49
+ for (const command of program.commands.filter((item) => item.commands.length)) {
50
+ command.allowExcessArguments().action(() => {
51
+ throw new Error(`Unknown command. Run outpost ${command.name()} --help.`);
52
+ });
53
+ }
54
+ try {
55
+ await program.parseAsync(args.length ? [...args] : ["--help"], {
56
+ from: "user",
57
+ });
58
+ }
59
+ catch (error) {
60
+ if (error instanceof CommanderError && error.exitCode === 0)
61
+ return;
62
+ throw error;
63
+ }
27
64
  }
28
65
  //# sourceMappingURL=commands.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAA0B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,SAAS,CAAC;QAC3B,IAAI;QACJ,gBAAgB,EAAE,IAAI;QACtB,OAAO,EAAE,UAAU;KACpB,CAAC,CAAC;IACH,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,MAAM,QAAQ,GAAyC;QACrD,MAAM,EAAE,aAAa;QACrB,QAAQ,EAAE,eAAe;QACzB,IAAI,EAAE,iBAAiB;QACvB,KAAK,EAAE,YAAY;KACpB,CAAC;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,MAAM,QAAQ,CAAC,IAAI,CAAE,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { parseArgs } from \"node:util\";\nimport { recoveryCommand } from \"./recovery-command.ts\";\nimport { doctorCommand } from \"./doctor-command.ts\";\nimport { imageCommand } from \"./image-command.ts\";\nimport { initializeCommand } from \"./init-command.ts\";\nimport { cliOptions, help } from \"./main.constants.ts\";\nimport type { CliCommand } from \"./main.types.ts\";\n\nexport async function runCli(\n args: readonly string[] = process.argv.slice(2),\n): Promise<void> {\n const invocation = parseArgs({\n args,\n allowPositionals: true,\n options: cliOptions,\n });\n if (invocation.values.help || !invocation.positionals.length) {\n process.stdout.write(help);\n return;\n }\n const commands: Readonly<Record<string, CliCommand>> = {\n doctor: doctorCommand,\n recovery: recoveryCommand,\n init: initializeCommand,\n image: imageCommand,\n };\n const name = invocation.positionals[0]!;\n if (!Object.hasOwn(commands, name))\n throw new Error(\"Unknown command. Run outpost --help.\");\n await commands[name]!(invocation);\n}\n"]}
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGjE,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAA0B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;SAC1B,IAAI,CAAC,SAAS,CAAC;SACf,WAAW,CAAC,iDAAiD,CAAC;SAC9D,YAAY,EAAE;SACd,eAAe,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAyC;QACrD,IAAI,EAAE,iBAAiB;QACv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K,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { Command, CommanderError, Option } from \"commander\";\nimport { recoveryCommand } from \"./recovery-command.ts\";\nimport { doctorCommand } from \"./doctor-command.ts\";\nimport { imageCommand } from \"./image-command.ts\";\nimport { initializeCommand } from \"./init-command.ts\";\nimport { cliOptions, commandOptions } from \"./main.constants.ts\";\nimport type { CliCommand, CliValues } from \"./main.types.ts\";\n\nexport async function runCli(\n args: readonly string[] = process.argv.slice(2),\n): Promise<void> {\n const program = new Command()\n .name(\"outpost\")\n .description(\"Outpost — sandboxed coding agents and workflows\")\n .exitOverride()\n .configureOutput({ writeErr: () => {} });\n const handlers: Readonly<Record<string, CliCommand>> = {\n init: initializeCommand,\n doctor: doctorCommand,\n image: imageCommand,\n recovery: recoveryCommand,\n };\n for (const [name, definition] of Object.entries(commandOptions)) {\n const path = name.split(\" \");\n let command = program;\n for (const part of path) {\n command =\n command.commands.find((item) => item.name() === part) ??\n command.command(part);\n }\n command.description(definition.description);\n for (const key of definition.options) {\n const configuration = cliOptions[key];\n const short = \"short\" in configuration ? `-${configuration.short}, ` : \"\";\n command.addOption(\n new Option(\n `${short}--${key}${configuration.type === \"string\" ? \" <value>\" : \"\"}`,\n configuration.description,\n ),\n );\n }\n if (name === \"init\")\n command.addOption(\n new Option(\n \"--no-build\",\n \"Skip automatic container image build\",\n ).default(undefined),\n );\n command.action(async () => {\n const values: Record<string, string | boolean> = {};\n const parsed = command.opts<Record<string, unknown>>();\n for (const option of command.options) {\n const value = parsed[option.attributeName()];\n if (typeof value === \"string\" || typeof value === \"boolean\")\n values[option.long!.replace(/^--(?:no-)?/, \"\")] = value;\n }\n await handlers[path[0]!]!({\n values: values as CliValues,\n positionals: path,\n });\n });\n }\n for (const command of program.commands.filter(\n (item) => item.commands.length,\n )) {\n command.allowExcessArguments().action(() => {\n throw new Error(`Unknown command. Run outpost ${command.name()} --help.`);\n });\n }\n try {\n await program.parseAsync(args.length ? [...args] : [\"--help\"], {\n from: \"user\",\n });\n } catch (error) {\n if (error instanceof CommanderError && error.exitCode === 0) return;\n throw error;\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ export declare const authenticationRecipes: {
2
+ readonly codex: {
3
+ readonly environment: "OPENAI_API_KEY=\n";
4
+ readonly login: "const {spawnSync}=require(\"node:child_process\"); const {existsSync}=require(\"node:fs\"); const {join}=require(\"node:path\"); const {homedir}=require(\"node:os\"); const installed=join(homedir(),\".outpost-tools\",\"bin\",\"codex\"); const result=spawnSync(existsSync(installed)?installed:\"codex\",[\"login\",\"--with-api-key\"],{stdio:\"inherit\",shell:process.platform===\"win32\"}); process.exit(result.status ?? 1);";
5
+ readonly seed: "const {mkdirSync,writeFileSync,readFileSync,chmodSync}=require(\"node:fs\"); const {join}=require(\"node:path\"); const {homedir}=require(\"node:os\"); const directory=join(homedir(),\".codex\"); mkdirSync(directory,{recursive:true,mode:0o700}); const target=join(directory,\"auth.json\"); writeFileSync(target,readFileSync(0),{mode:0o600}); chmodSync(target,0o600);";
6
+ };
7
+ readonly claude: {
8
+ readonly environment: "ANTHROPIC_API_KEY=\n";
9
+ };
10
+ readonly gemini: {
11
+ readonly environment: "GEMINI_API_KEY=\n";
12
+ };
13
+ };
@@ -0,0 +1,10 @@
1
+ export const authenticationRecipes = {
2
+ codex: {
3
+ environment: "OPENAI_API_KEY=\n",
4
+ login: 'const {spawnSync}=require("node:child_process"); const {existsSync}=require("node:fs"); const {join}=require("node:path"); const {homedir}=require("node:os"); const installed=join(homedir(),".outpost-tools","bin","codex"); const result=spawnSync(existsSync(installed)?installed:"codex",["login","--with-api-key"],{stdio:"inherit",shell:process.platform==="win32"}); process.exit(result.status ?? 1);',
5
+ seed: 'const {mkdirSync,writeFileSync,readFileSync,chmodSync}=require("node:fs"); const {join}=require("node:path"); const {homedir}=require("node:os"); const directory=join(homedir(),".codex"); mkdirSync(directory,{recursive:true,mode:0o700}); const target=join(directory,"auth.json"); writeFileSync(target,readFileSync(0),{mode:0o600}); chmodSync(target,0o600);',
6
+ },
7
+ claude: { environment: "ANTHROPIC_API_KEY=\n" },
8
+ gemini: { environment: "GEMINI_API_KEY=\n" },
9
+ };
10
+ //# sourceMappingURL=init-authentication.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-authentication.constants.js","sourceRoot":"","sources":["../../src/cli/init-authentication.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,KAAK,EAAE;QACL,WAAW,EAAE,mBAAmB;QAChC,KAAK,EACH,iZAAiZ;QACnZ,IAAI,EAAE,sWAAsW;KAC7W;IACD,MAAM,EAAE,EAAE,WAAW,EAAE,sBAAsB,EAAE;IAC/C,MAAM,EAAE,EAAE,WAAW,EAAE,mBAAmB,EAAE;CACpC,CAAC","sourcesContent":["export const authenticationRecipes = {\n codex: {\n environment: \"OPENAI_API_KEY=\\n\",\n login:\n 'const {spawnSync}=require(\"node:child_process\"); const {existsSync}=require(\"node:fs\"); const {join}=require(\"node:path\"); const {homedir}=require(\"node:os\"); const installed=join(homedir(),\".outpost-tools\",\"bin\",\"codex\"); const result=spawnSync(existsSync(installed)?installed:\"codex\",[\"login\",\"--with-api-key\"],{stdio:\"inherit\",shell:process.platform===\"win32\"}); process.exit(result.status ?? 1);',\n seed: 'const {mkdirSync,writeFileSync,readFileSync,chmodSync}=require(\"node:fs\"); const {join}=require(\"node:path\"); const {homedir}=require(\"node:os\"); const directory=join(homedir(),\".codex\"); mkdirSync(directory,{recursive:true,mode:0o700}); const target=join(directory,\"auth.json\"); writeFileSync(target,readFileSync(0),{mode:0o600}); chmodSync(target,0o600);',\n },\n claude: { environment: \"ANTHROPIC_API_KEY=\\n\" },\n gemini: { environment: \"GEMINI_API_KEY=\\n\" },\n} as const;\n"]}
@@ -0,0 +1,4 @@
1
+ import type { InitOptions } from "./scaffold.types.ts";
2
+ export declare function authenticationEnvironment(options: InitOptions): string;
3
+ export declare function authenticationInstructions(options: InitOptions): string;
4
+ export declare function authenticationSource(options: InitOptions): string;
@@ -0,0 +1,43 @@
1
+ import { authenticationRecipes } from "./init-authentication.constants.js";
2
+ export function authenticationEnvironment(options) {
3
+ if (options.baseUrl)
4
+ return `${options.apiKeyEnvironment ?? "OPENAI_API_KEY"}=\n`;
5
+ if (options.authentication === "login")
6
+ return "";
7
+ if (options.authentication === "oauth-token")
8
+ return "CLAUDE_CODE_OAUTH_TOKEN=\n";
9
+ return authenticationRecipes[options.agent ?? "codex"].environment;
10
+ }
11
+ export function authenticationInstructions(options) {
12
+ if (options.authentication === "login")
13
+ return "Run codex login on the host. For isolated providers, use file credential storage; the generated script copies auth.json into the private sandbox home.";
14
+ if (options.authentication === "oauth-token")
15
+ return "Run claude setup-token on the host, then set CLAUDE_CODE_OAUTH_TOKEN in the workflow .env or parent environment. This uses your Claude subscription.";
16
+ return ("Set " +
17
+ authenticationEnvironment(options).trim().replace("=", "") +
18
+ " in the workflow .env or parent environment. API usage is billed separately from subscriptions.");
19
+ }
20
+ export function authenticationSource(options) {
21
+ const agent = options.agent ?? "codex";
22
+ if (options.authentication === "login") {
23
+ if (options.provider === "local")
24
+ return "const authentication = {};";
25
+ return `const seed = await readFile(resolve(process.env.CODEX_HOME || resolve(homedir(), ".codex"), "auth.json"), "utf8");
26
+ try { JSON.parse(seed); } catch { throw new Error("Invalid Codex authentication file. Run codex login again with file credential storage."); }
27
+ const authentication = { sandboxReady: [{ executable: "node", arguments: ["-e", ${JSON.stringify(authenticationRecipes.codex.seed)}], stdin: seed }] };`;
28
+ }
29
+ const key = authenticationEnvironment(options).trim().replace("=", "");
30
+ const conflict = agent === "claude"
31
+ ? key === "ANTHROPIC_API_KEY"
32
+ ? "CLAUDE_CODE_OAUTH_TOKEN"
33
+ : "ANTHROPIC_API_KEY"
34
+ : undefined;
35
+ const check = `if (!variables[${JSON.stringify(key)}]) throw new Error(${JSON.stringify(`Missing ${key}. Configure the workflow .env or parent environment before starting a sandbox.`)});`;
36
+ const guard = conflict
37
+ ? `\nif (variables[${JSON.stringify(conflict)}]) throw new Error("Conflicting Claude authentication methods. Keep only the selected credential in the workflow environment.");`
38
+ : "";
39
+ if (agent !== "codex" || options.baseUrl)
40
+ return `${check}${guard}\nconst authentication = {};`;
41
+ return `${check}\nconst authentication = { sandboxReady: [{ executable: "node", arguments: ["-e", ${JSON.stringify(authenticationRecipes.codex.login)}], stdin: variables.OPENAI_API_KEY }] };`;
42
+ }
43
+ //# sourceMappingURL=init-authentication.js.map