@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":"execution.types.js","sourceRoot":"","sources":["../../src/application/execution.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AgentAdapter,\n AgentObservation,\n Usage,\n} from \"../domain/agent.types.ts\";\nimport type { Brief } from \"../domain/prompts.types.ts\";\nimport type { ResponseSpec } from \"../domain/response.types.ts\";\nimport type { Logging } from \"../infrastructure/journal.types.ts\";\n\nexport interface DispatchOptions<T = undefined> {\n readonly agent?: AgentAdapter;\n readonly logging?: Logging;\n readonly label?: string;\n readonly brief: Brief;\n readonly passes?: number;\n readonly until?: string | readonly string[];\n readonly idleMs?: number;\n readonly idleWarningMs?: number;\n readonly settleMs?: number;\n readonly deadlineMs?: number;\n readonly expansionMs?: number;\n readonly signal?: AbortSignal;\n readonly continuation?: { readonly id: string; readonly fork?: boolean };\n readonly response?: ResponseSpec<T>;\n readonly observe?: (event: AgentObservation) => void;\n readonly warn?: (message: string) => void;\n readonly diagnostic?: (message: string) => void;\n}\n\nexport interface Turn {\n readonly text: string;\n readonly status: number;\n readonly conversation?: string;\n readonly transcript?: string;\n readonly usage: Usage;\n readonly durationMs: number;\n}\n\nexport interface AgentOutput {\n readonly completed: boolean;\n readonly conversation: string | undefined;\n append(chunk: string): void;\n flush(): void;\n result(): Pick<Turn, \"text\" | \"usage\" | \"conversation\">;\n}\n\nexport interface ActivityWatchdog {\n refresh(completed: boolean): void;\n close(): void;\n}\n\nexport interface Execution<T> {\n readonly text: string;\n readonly turns: readonly Turn[];\n readonly usage: Usage;\n readonly conversation?: string;\n readonly value: T;\n readonly completed: boolean;\n readonly completion?: string;\n}\n"]}
1
+ {"version":3,"file":"execution.types.js","sourceRoot":"","sources":["../../src/application/execution.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TransportReference } from \"../domain/transport.types.ts\";\nimport type {\n AgentAdapter,\n AgentObservation,\n Usage,\n} from \"../domain/agent.types.ts\";\nimport type { Brief } from \"../domain/prompts.types.ts\";\nimport type { ResponseSpec } from \"../domain/response.types.ts\";\nimport type { Logging } from \"../infrastructure/journal.types.ts\";\n\nexport interface DispatchOptions<T = undefined> {\n readonly agent?: AgentAdapter;\n readonly logging?: Logging;\n readonly label?: string;\n readonly brief: Brief;\n readonly passes?: number;\n readonly until?: string | readonly string[];\n readonly idleMs?: number;\n readonly idleWarningMs?: number;\n readonly settleMs?: number;\n readonly deadlineMs?: number;\n readonly expansionMs?: number;\n readonly signal?: AbortSignal;\n readonly continuation?: { readonly id: string; readonly fork?: boolean };\n readonly response?: ResponseSpec<T>;\n readonly observe?: (event: AgentObservation) => void;\n readonly warn?: (message: string) => void;\n readonly diagnostic?: (message: string) => void;\n}\n\nexport interface Turn {\n readonly text: string;\n readonly status: number;\n readonly conversation?: string;\n readonly transcript?: string;\n readonly transcriptReference?: TransportReference;\n readonly usage: Usage;\n readonly durationMs: number;\n}\n\nexport interface AgentOutput {\n readonly completed: boolean;\n readonly conversation: string | undefined;\n append(chunk: string): void;\n flush(): void;\n result(): Pick<Turn, \"text\" | \"usage\" | \"conversation\">;\n}\n\nexport interface ActivityWatchdog {\n refresh(completed: boolean): void;\n close(): void;\n}\n\nexport interface Execution<T> {\n readonly text: string;\n readonly turns: readonly Turn[];\n readonly usage: Usage;\n readonly conversation?: string;\n readonly value: T;\n readonly completed: boolean;\n readonly completion?: string;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { Transport, TransportReference } from "../domain/transport.types.ts";
1
2
  import type { AgentAdapter } from "../domain/agent.types.ts";
2
3
  import type { Command, CommandResult } from "../domain/command.types.ts";
3
4
  import type { Brief } from "../domain/prompts.types.ts";
@@ -42,6 +43,8 @@ export interface SandboxOptions extends WorkspaceOptions {
42
43
  readonly logging?: Logging;
43
44
  readonly bootstrap?: boolean;
44
45
  readonly conversationHome?: string;
46
+ readonly recoveryTransport?: Transport;
47
+ readonly activityTransport?: Transport;
45
48
  }
46
49
  export interface AttachOptions {
47
50
  readonly ask?: VariableQuestion;
@@ -64,6 +67,8 @@ export interface DispatchResult<T> extends Execution<T> {
64
67
  readonly directory: string;
65
68
  readonly commits: readonly Commit[];
66
69
  readonly transcript?: string;
70
+ readonly transcriptReference?: TransportReference;
71
+ readonly logReference?: TransportReference;
67
72
  readonly log?: string;
68
73
  readonly retainedDirectory?: string;
69
74
  resume<U = undefined>(options: ContinuationOptions<U>): Promise<DispatchResult<U>>;
@@ -1 +1 @@
1
- {"version":3,"file":"outpost.types.js","sourceRoot":"","sources":["../../src/application/outpost.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport type { Command, CommandResult } from \"../domain/command.types.ts\";\nimport type { Brief } from \"../domain/prompts.types.ts\";\nimport type { SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport type {\n BranchPolicy,\n Commit,\n Disposal,\n LifecycleHooks,\n StageLimits,\n WorkspaceRecord,\n} from \"../domain/workspace.types.ts\";\nimport type { StorageReservationOptions } from \"../infrastructure/storage-reservations.types.ts\";\nimport type { Logging } from \"../infrastructure/journal.types.ts\";\nimport type {\n SandboxDiagnosticOptions,\n SandboxDiagnosticReport,\n} from \"./doctor-sandbox.types.ts\";\nimport type { DispatchOptions, Execution } from \"./execution.types.ts\";\nimport type { VariableQuestion } from \"./interactive-brief.types.ts\";\n\nexport interface WorkspaceOptions {\n readonly storageQuota?: Omit<StorageReservationOptions, \"signal\">;\n readonly signal?: AbortSignal;\n readonly repository?: string;\n readonly branch?: BranchPolicy;\n readonly copies?: readonly string[];\n readonly limits?: StageLimits;\n readonly label?: string;\n readonly hooks?: LifecycleHooks;\n}\n\nexport interface Workspace extends WorkspaceRecord {\n dispatch<T = undefined>(\n options: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n > &\n DispatchOptions<T> & { readonly agent: AgentAdapter },\n ): Promise<DispatchResult<T>>;\n sandbox(\n options?: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n >,\n ): Promise<Sandbox>;\n attach(\n options: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n > &\n AttachOptions & { readonly agent: AgentAdapter },\n ): Promise<AttachResult>;\n close(options?: { readonly preserve?: boolean }): Promise<Disposal>;\n integrate(): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\nexport interface SandboxOptions extends WorkspaceOptions {\n readonly includeUncommitted?: boolean;\n readonly agent?: AgentAdapter;\n readonly provider?: SandboxProvider;\n readonly workspace?: Workspace;\n readonly hooks?: LifecycleHooks;\n readonly signal?: AbortSignal;\n readonly logging?: Logging;\n readonly bootstrap?: boolean;\n readonly conversationHome?: string;\n}\n\nexport interface AttachOptions {\n readonly ask?: VariableQuestion;\n readonly agent?: AgentAdapter;\n readonly brief?: Brief;\n readonly continuation?: { readonly id: string; readonly fork?: boolean };\n readonly signal?: AbortSignal;\n readonly terminal?: Command[\"terminal\"];\n}\n\nexport interface AttachResult extends CommandResult, Disposal {\n readonly commits: readonly Commit[];\n readonly branch: string;\n readonly directory: string;\n}\n\nexport interface DispatchResult<T> extends Execution<T> {\n readonly branch: string;\n readonly directory: string;\n readonly commits: readonly Commit[];\n readonly transcript?: string;\n readonly log?: string;\n readonly retainedDirectory?: string;\n resume<U = undefined>(\n options: ContinuationOptions<U>,\n ): Promise<DispatchResult<U>>;\n fork<U = undefined>(\n options: ContinuationOptions<U>,\n ): Promise<DispatchResult<U>>;\n}\n\nexport type ContinuationOptions<T = undefined> = DispatchOptions<T> &\n Omit<SandboxOptions, \"agent\">;\n\nexport interface WarmDispatchResult<T> extends Omit<\n DispatchResult<T>,\n \"resume\" | \"fork\"\n> {\n resume<U = undefined>(\n options: DispatchOptions<U>,\n ): Promise<WarmDispatchResult<U>>;\n fork<U = undefined>(\n options: DispatchOptions<U>,\n ): Promise<WarmDispatchResult<U>>;\n}\n\nexport interface Sandbox {\n diagnose(\n options?: SandboxDiagnosticOptions,\n ): Promise<SandboxDiagnosticReport>;\n readonly workspace: Workspace;\n readonly root: string;\n dispatch<T = undefined>(\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n resume<T = undefined>(\n id: string,\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n fork<T = undefined>(\n id: string,\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n attach(options?: AttachOptions): Promise<AttachResult>;\n command(command: Command): Promise<CommandResult>;\n close(options?: { readonly preserve?: boolean }): Promise<Disposal>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"outpost.types.js","sourceRoot":"","sources":["../../src/application/outpost.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Transport,\n TransportReference,\n} from \"../domain/transport.types.ts\";\nimport type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport type { Command, CommandResult } from \"../domain/command.types.ts\";\nimport type { Brief } from \"../domain/prompts.types.ts\";\nimport type { SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport type {\n BranchPolicy,\n Commit,\n Disposal,\n LifecycleHooks,\n StageLimits,\n WorkspaceRecord,\n} from \"../domain/workspace.types.ts\";\nimport type { StorageReservationOptions } from \"../infrastructure/storage-reservations.types.ts\";\nimport type { Logging } from \"../infrastructure/journal.types.ts\";\nimport type {\n SandboxDiagnosticOptions,\n SandboxDiagnosticReport,\n} from \"./doctor-sandbox.types.ts\";\nimport type { DispatchOptions, Execution } from \"./execution.types.ts\";\nimport type { VariableQuestion } from \"./interactive-brief.types.ts\";\n\nexport interface WorkspaceOptions {\n readonly storageQuota?: Omit<StorageReservationOptions, \"signal\">;\n readonly signal?: AbortSignal;\n readonly repository?: string;\n readonly branch?: BranchPolicy;\n readonly copies?: readonly string[];\n readonly limits?: StageLimits;\n readonly label?: string;\n readonly hooks?: LifecycleHooks;\n}\n\nexport interface Workspace extends WorkspaceRecord {\n dispatch<T = undefined>(\n options: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n > &\n DispatchOptions<T> & { readonly agent: AgentAdapter },\n ): Promise<DispatchResult<T>>;\n sandbox(\n options?: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n >,\n ): Promise<Sandbox>;\n attach(\n options: Omit<\n SandboxOptions,\n Exclude<keyof WorkspaceOptions, \"hooks\" | \"label\"> | \"workspace\"\n > &\n AttachOptions & { readonly agent: AgentAdapter },\n ): Promise<AttachResult>;\n close(options?: { readonly preserve?: boolean }): Promise<Disposal>;\n integrate(): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\nexport interface SandboxOptions extends WorkspaceOptions {\n readonly includeUncommitted?: boolean;\n readonly agent?: AgentAdapter;\n readonly provider?: SandboxProvider;\n readonly workspace?: Workspace;\n readonly hooks?: LifecycleHooks;\n readonly signal?: AbortSignal;\n readonly logging?: Logging;\n readonly bootstrap?: boolean;\n readonly conversationHome?: string;\n readonly recoveryTransport?: Transport;\n readonly activityTransport?: Transport;\n}\n\nexport interface AttachOptions {\n readonly ask?: VariableQuestion;\n readonly agent?: AgentAdapter;\n readonly brief?: Brief;\n readonly continuation?: { readonly id: string; readonly fork?: boolean };\n readonly signal?: AbortSignal;\n readonly terminal?: Command[\"terminal\"];\n}\n\nexport interface AttachResult extends CommandResult, Disposal {\n readonly commits: readonly Commit[];\n readonly branch: string;\n readonly directory: string;\n}\n\nexport interface DispatchResult<T> extends Execution<T> {\n readonly branch: string;\n readonly directory: string;\n readonly commits: readonly Commit[];\n readonly transcript?: string;\n readonly transcriptReference?: TransportReference;\n readonly logReference?: TransportReference;\n readonly log?: string;\n readonly retainedDirectory?: string;\n resume<U = undefined>(\n options: ContinuationOptions<U>,\n ): Promise<DispatchResult<U>>;\n fork<U = undefined>(\n options: ContinuationOptions<U>,\n ): Promise<DispatchResult<U>>;\n}\n\nexport type ContinuationOptions<T = undefined> = DispatchOptions<T> &\n Omit<SandboxOptions, \"agent\">;\n\nexport interface WarmDispatchResult<T> extends Omit<\n DispatchResult<T>,\n \"resume\" | \"fork\"\n> {\n resume<U = undefined>(\n options: DispatchOptions<U>,\n ): Promise<WarmDispatchResult<U>>;\n fork<U = undefined>(\n options: DispatchOptions<U>,\n ): Promise<WarmDispatchResult<U>>;\n}\n\nexport interface Sandbox {\n diagnose(\n options?: SandboxDiagnosticOptions,\n ): Promise<SandboxDiagnosticReport>;\n readonly workspace: Workspace;\n readonly root: string;\n dispatch<T = undefined>(\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n resume<T = undefined>(\n id: string,\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n fork<T = undefined>(\n id: string,\n options: DispatchOptions<T>,\n ): Promise<WarmDispatchResult<T>>;\n attach(options?: AttachOptions): Promise<AttachResult>;\n command(command: Command): Promise<CommandResult>;\n close(options?: { readonly preserve?: boolean }): Promise<Disposal>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { TransportReference } from "../domain/transport.types.ts";
2
+ import type { RecoveryArchiveOptions, RecoveryArchiveRestoreOptions } from "./recovery-archive.types.ts";
3
+ export declare function archiveRecovery(options: RecoveryArchiveOptions): Promise<TransportReference>;
4
+ export declare function materializeRecoveryArchive(options: RecoveryArchiveRestoreOptions): Promise<string>;
@@ -0,0 +1,29 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { archiveFiles, restoreArchiveFiles, } from "../infrastructure/transport-archive.js";
3
+ import { snapshotRecoveryTransfer } from "./recovery-restore-snapshot.js";
4
+ import { recoveryChecksumPaths } from "./recovery-checksum-paths.js";
5
+ import { recoveryChecksumDefaults } from "./recovery-checksums.constants.js";
6
+ import { verifyRecoveryTransfer } from "./recovery-verification.js";
7
+ import { invariant } from "../domain/errors.js";
8
+ export async function archiveRecovery(options) {
9
+ const snapshot = await snapshotRecoveryTransfer(options.directory, options.maxBytes);
10
+ try {
11
+ return await archiveFiles(options.transporter, snapshot.directory, [
12
+ ...recoveryChecksumPaths(snapshot.state),
13
+ recoveryChecksumDefaults.filename,
14
+ ], `recovery/${randomUUID()}`, options.maxBytes);
15
+ }
16
+ finally {
17
+ await snapshot.dispose();
18
+ }
19
+ }
20
+ export async function materializeRecoveryArchive(options) {
21
+ await restoreArchiveFiles(options.transporter, options.reference, options.destination, options.maxBytes);
22
+ const verified = await verifyRecoveryTransfer(options.destination, {
23
+ checksums: true,
24
+ ...(options.maxBytes === undefined ? {} : { maxBytes: options.maxBytes }),
25
+ });
26
+ invariant(verified.complete && verified.integrity === "checksums-match", "Recovery archive integrity verification failed; destination retained");
27
+ return options.destination;
28
+ }
29
+ //# sourceMappingURL=recovery-archive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery-archive.js","sourceRoot":"","sources":["../../src/application/recovery-archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,YAAY,EACZ,mBAAmB,GACpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAMhD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAA+B;IAE/B,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAC7C,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,QAAQ,CACjB,CAAC;IACF,IAAI,CAAC;QACH,OAAO,MAAM,YAAY,CACvB,OAAO,CAAC,WAAW,EACnB,QAAQ,CAAC,SAAS,EAClB;YACE,GAAG,qBAAqB,CAAC,QAAQ,CAAC,KAAK,CAAC;YACxC,wBAAwB,CAAC,QAAQ;SAClC,EACD,YAAY,UAAU,EAAE,EAAE,EAC1B,OAAO,CAAC,QAAQ,CACjB,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAAsC;IAEtC,MAAM,mBAAmB,CACvB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,QAAQ,CACjB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,WAAW,EAAE;QACjE,SAAS,EAAE,IAAI;QACf,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;KAC1E,CAAC,CAAC;IACH,SAAS,CACP,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,KAAK,iBAAiB,EAC7D,sEAAsE,CACvE,CAAC;IACF,OAAO,OAAO,CAAC,WAAW,CAAC;AAC7B,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { TransportReference } from \"../domain/transport.types.ts\";\nimport {\n archiveFiles,\n restoreArchiveFiles,\n} from \"../infrastructure/transport-archive.ts\";\nimport { snapshotRecoveryTransfer } from \"./recovery-restore-snapshot.ts\";\nimport { recoveryChecksumPaths } from \"./recovery-checksum-paths.ts\";\nimport { recoveryChecksumDefaults } from \"./recovery-checksums.constants.ts\";\nimport { verifyRecoveryTransfer } from \"./recovery-verification.ts\";\nimport { invariant } from \"../domain/errors.ts\";\nimport type {\n RecoveryArchiveOptions,\n RecoveryArchiveRestoreOptions,\n} from \"./recovery-archive.types.ts\";\n\nexport async function archiveRecovery(\n options: RecoveryArchiveOptions,\n): Promise<TransportReference> {\n const snapshot = await snapshotRecoveryTransfer(\n options.directory,\n options.maxBytes,\n );\n try {\n return await archiveFiles(\n options.transporter,\n snapshot.directory,\n [\n ...recoveryChecksumPaths(snapshot.state),\n recoveryChecksumDefaults.filename,\n ],\n `recovery/${randomUUID()}`,\n options.maxBytes,\n );\n } finally {\n await snapshot.dispose();\n }\n}\n\nexport async function materializeRecoveryArchive(\n options: RecoveryArchiveRestoreOptions,\n): Promise<string> {\n await restoreArchiveFiles(\n options.transporter,\n options.reference,\n options.destination,\n options.maxBytes,\n );\n const verified = await verifyRecoveryTransfer(options.destination, {\n checksums: true,\n ...(options.maxBytes === undefined ? {} : { maxBytes: options.maxBytes }),\n });\n invariant(\n verified.complete && verified.integrity === \"checksums-match\",\n \"Recovery archive integrity verification failed; destination retained\",\n );\n return options.destination;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { TransportReference, TransportStoreOptions } from "../domain/transport.types.ts";
2
+ export interface RecoveryArchiveOptions extends TransportStoreOptions {
3
+ readonly directory: string;
4
+ readonly maxBytes?: number;
5
+ }
6
+ export interface RecoveryArchiveRestoreOptions extends TransportStoreOptions {
7
+ readonly reference: TransportReference;
8
+ readonly destination: string;
9
+ readonly maxBytes?: number;
10
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=recovery-archive.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery-archive.types.js","sourceRoot":"","sources":["../../src/application/recovery-archive.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n TransportReference,\n TransportStoreOptions,\n} from \"../domain/transport.types.ts\";\nexport interface RecoveryArchiveOptions extends TransportStoreOptions {\n readonly directory: string;\n readonly maxBytes?: number;\n}\nexport interface RecoveryArchiveRestoreOptions extends TransportStoreOptions {\n readonly reference: TransportReference;\n readonly destination: string;\n readonly maxBytes?: number;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { inspectTransportRecovery } from "./transport-inspection.js";
1
2
  import { inspectResourceActivity } from "../infrastructure/resource-activity-inspection.js";
2
3
  import { inspectLocks } from "../infrastructure/git/lock-inspection.js";
3
4
  import { join } from "node:path";
@@ -6,6 +7,8 @@ import { git } from "../infrastructure/git/command.js";
6
7
  import { inspectWorktreeGit } from "../infrastructure/git/worktree-inspection.js";
7
8
  import { storageInventory } from "../infrastructure/storage-inventory.js";
8
9
  export async function inspectRecovery(options = {}) {
10
+ if (options.transporter)
11
+ return inspectTransportRecovery(options);
9
12
  const requested = await directory(options.repository);
10
13
  const repository = await directory((await git(requested, ["rev-parse", "--show-toplevel"])).trim());
11
14
  const inventory = await storageInventory(join(repository, ".outpost"), options.maxEntries);
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-inspection.js","sourceRoot":"","sources":["../../src/application/recovery-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAM1E,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAqC,EAAE;IAEvC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,MAAM,SAAS,CAChC,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAChE,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,gBAAgB,CACtC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,EAC5B,OAAO,CAAC,UAAU,CACnB,CAAC;IACF,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG;QAC3B,CAAC,CAAC,MAAM,kBAAkB,CACtB,UAAU,EACV,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CAAC;YACrE,EAAE,OAAO,IAAI,EAAE,CAClB;QACH,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK;QAC9B,CAAC,CAAC,MAAM,YAAY,CAChB,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC;YAChE,EAAE,OAAO,IAAI,EAAE,CAClB;QACH,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS;QACjC,CAAC,CAAC,MAAM,uBAAuB,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC;QAC/D,CAAC,CAAC,SAAS,CAAC;IACd,OAAO;QACL,UAAU;QACV,QAAQ,EAAE,YAAY;QACtB,GAAG,SAAS;QACZ,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7C,CAAC;AACJ,CAAC","sourcesContent":["import { inspectResourceActivity } from \"../infrastructure/resource-activity-inspection.ts\";\nimport { inspectLocks } from \"../infrastructure/git/lock-inspection.ts\";\nimport { join } from \"node:path\";\nimport { directory } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { inspectWorktreeGit } from \"../infrastructure/git/worktree-inspection.ts\";\nimport { storageInventory } from \"../infrastructure/storage-inventory.ts\";\nimport type {\n RecoveryInspection,\n RecoveryInspectionOptions,\n} from \"./recovery-inspection.types.ts\";\n\nexport async function inspectRecovery(\n options: RecoveryInspectionOptions = {},\n): Promise<RecoveryInspection> {\n const requested = await directory(options.repository);\n const repository = await directory(\n (await git(requested, [\"rev-parse\", \"--show-toplevel\"])).trim(),\n );\n const inventory = await storageInventory(\n join(repository, \".outpost\"),\n options.maxEntries,\n );\n const gitReport = options.git\n ? await inspectWorktreeGit(\n repository,\n inventory.categories.find((category) => category.name === \"workspaces\")\n ?.entries ?? [],\n )\n : undefined;\n const lockReport = options.locks\n ? await inspectLocks(\n inventory.categories.find((category) => category.name === \"locks\")\n ?.entries ?? [],\n )\n : undefined;\n const resources = options.resources\n ? await inspectResourceActivity(repository, options.maxEntries)\n : undefined;\n return {\n repository,\n activity: \"unverified\",\n ...inventory,\n ...(resources ? { resources } : {}),\n ...(gitReport ? { git: gitReport } : {}),\n ...(lockReport ? { locks: lockReport } : {}),\n };\n}\n"]}
1
+ {"version":3,"file":"recovery-inspection.js","sourceRoot":"","sources":["../../src/application/recovery-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAM1E,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAqC,EAAE;IAEvC,IAAI,OAAO,CAAC,WAAW;QAAE,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClE,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,MAAM,SAAS,CAChC,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,C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../infrastructure/resource-activity-inspection.ts\";\nimport { inspectLocks } from \"../infrastructure/git/lock-inspection.ts\";\nimport { join } from \"node:path\";\nimport { directory } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { inspectWorktreeGit } from \"../infrastructure/git/worktree-inspection.ts\";\nimport { storageInventory } from \"../infrastructure/storage-inventory.ts\";\nimport type {\n RecoveryInspection,\n RecoveryInspectionOptions,\n} from \"./recovery-inspection.types.ts\";\n\nexport async function inspectRecovery(\n options: RecoveryInspectionOptions = {},\n): Promise<RecoveryInspection> {\n if (options.transporter) return inspectTransportRecovery(options);\n const requested = await directory(options.repository);\n const repository = await directory(\n (await git(requested, [\"rev-parse\", \"--show-toplevel\"])).trim(),\n );\n const inventory = await storageInventory(\n join(repository, \".outpost\"),\n options.maxEntries,\n );\n const gitReport = options.git\n ? await inspectWorktreeGit(\n repository,\n inventory.categories.find((category) => category.name === \"workspaces\")\n ?.entries ?? [],\n )\n : undefined;\n const lockReport = options.locks\n ? await inspectLocks(\n inventory.categories.find((category) => category.name === \"locks\")\n ?.entries ?? [],\n )\n : undefined;\n const resources = options.resources\n ? await inspectResourceActivity(repository, options.maxEntries)\n : undefined;\n return {\n repository,\n activity: \"unverified\",\n ...inventory,\n ...(resources ? { resources } : {}),\n ...(gitReport ? { git: gitReport } : {}),\n ...(lockReport ? { locks: lockReport } : {}),\n };\n}\n"]}
@@ -1,8 +1,10 @@
1
+ import type { Transport } from "../domain/transport.types.ts";
1
2
  import type { ResourceInspection } from "../infrastructure/resource-activity.types.ts";
2
3
  import type { LockInspection } from "../infrastructure/git/lock-inspection.types.ts";
3
4
  import type { WorkspaceGitInspection } from "../infrastructure/git/worktree-inspection.types.ts";
4
5
  import type { StorageInventory } from "../infrastructure/storage-inventory.types.ts";
5
6
  export interface RecoveryInspectionOptions {
7
+ readonly transporter?: Transport;
6
8
  readonly repository?: string;
7
9
  readonly maxEntries?: number;
8
10
  readonly git?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-inspection.types.js","sourceRoot":"","sources":["../../src/application/recovery-inspection.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ResourceInspection } from \"../infrastructure/resource-activity.types.ts\";\nimport type { LockInspection } from \"../infrastructure/git/lock-inspection.types.ts\";\nimport type { WorkspaceGitInspection } from \"../infrastructure/git/worktree-inspection.types.ts\";\nimport type { StorageInventory } from \"../infrastructure/storage-inventory.types.ts\";\n\nexport interface RecoveryInspectionOptions {\n readonly repository?: string;\n readonly maxEntries?: number;\n readonly git?: boolean;\n readonly locks?: boolean;\n readonly resources?: boolean;\n}\nexport interface RecoveryInspection extends StorageInventory {\n readonly repository: string;\n readonly activity: \"unverified\";\n readonly git?: WorkspaceGitInspection;\n readonly locks?: LockInspection;\n readonly resources?: ResourceInspection;\n}\n"]}
1
+ {"version":3,"file":"recovery-inspection.types.js","sourceRoot":"","sources":["../../src/application/recovery-inspection.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Transport } from \"../domain/transport.types.ts\";\nimport type { ResourceInspection } from \"../infrastructure/resource-activity.types.ts\";\nimport type { LockInspection } from \"../infrastructure/git/lock-inspection.types.ts\";\nimport type { WorkspaceGitInspection } from \"../infrastructure/git/worktree-inspection.types.ts\";\nimport type { StorageInventory } from \"../infrastructure/storage-inventory.types.ts\";\n\nexport interface RecoveryInspectionOptions {\n readonly transporter?: Transport;\n readonly repository?: string;\n readonly maxEntries?: number;\n readonly git?: boolean;\n readonly locks?: boolean;\n readonly resources?: boolean;\n}\nexport interface RecoveryInspection extends StorageInventory {\n readonly repository: string;\n readonly activity: \"unverified\";\n readonly git?: WorkspaceGitInspection;\n readonly locks?: LockInspection;\n readonly resources?: ResourceInspection;\n}\n"]}
@@ -1,4 +1,5 @@
1
+ import type { TransportStoreOptions } from "../domain/transport.types.ts";
1
2
  import type { RecoveryPruneResult, RecoveryQuotaOptions, RecoveryRetentionOptions, RecoveryRetentionPlan } from "./recovery-retention.types.ts";
2
3
  export declare function planRecoveryRetention(options: RecoveryRetentionOptions): Promise<RecoveryRetentionPlan>;
3
- export declare function pruneRecoveryRetention(plan: RecoveryRetentionPlan): Promise<RecoveryPruneResult>;
4
+ export declare function pruneRecoveryRetention(plan: RecoveryRetentionPlan, options?: TransportStoreOptions): Promise<RecoveryPruneResult>;
4
5
  export declare function assertRecoveryQuota(options: RecoveryQuotaOptions): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import { planTransportRetention, pruneTransportRetention, } from "./transport-retention.js";
1
2
  import { lstat, rm } from "node:fs/promises";
2
3
  import { OutpostError, invariant } from "../domain/errors.js";
3
4
  import { git } from "../infrastructure/git/command.js";
@@ -47,6 +48,8 @@ async function workspaceReason(entry, inspection) {
47
48
  return "ELIGIBLE";
48
49
  }
49
50
  export async function planRecoveryRetention(options) {
51
+ if (options.transporter)
52
+ return planTransportRetention(options);
50
53
  retentionPolicy(options.policy);
51
54
  const policy = structuredClone(options.policy);
52
55
  const inspection = await inspectRecovery({
@@ -122,7 +125,12 @@ export async function planRecoveryRetention(options) {
122
125
  quota: !complete ? "unknown" : exceeded ? "exceeded" : "within",
123
126
  };
124
127
  }
125
- export async function pruneRecoveryRetention(plan) {
128
+ export async function pruneRecoveryRetention(plan, options) {
129
+ if (plan.source === "transport") {
130
+ invariant(options, "Transport retention requires its transporter");
131
+ return pruneTransportRetention(plan, options);
132
+ }
133
+ invariant(!options, "Local retention does not accept a transporter");
126
134
  retentionPolicy(plan.policy);
127
135
  invariant(plan.complete, "Cannot prune an incomplete retention plan");
128
136
  const removed = [];
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-retention.js","sourceRoot":"","sources":["../../src/application/recovery-retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAA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AU,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAClD,IACE,CAAC,UAAU,CAAC,QAAQ;QACpB,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ;QAEnD,MAAM,IAAI,YAAY,CACpB,WAAW,EACX,yCAAyC,EACzC;YACE,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK;YAClC,YAAY,EAAE,OAAO;YACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CACF,CAAC;AACN,CAAC","sourcesContent":["import { lstat, rm } from \"node:fs/promises\";\nimport { OutpostError, invariant } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { lock, lockPath } from \"../infrastructure/git/lock.ts\";\nimport { closedJournal } from \"../infrastructure/journal-retention.ts\";\nimport type { StorageEntry } from \"../infrastructure/storage-inventory.types.ts\";\nimport type { RecoveryInspection } from \"./recovery-inspection.types.ts\";\nimport { inspectRecovery } from \"./recovery-inspection.ts\";\nimport { retentionPolicy } from \"./recovery-retention-policy.ts\";\nimport type {\n RecoveryPruneResult,\n RecoveryRetainedEntry,\n RecoveryQuotaOptions,\n RecoveryRetentionEntry,\n RecoveryRetentionOptions,\n RecoveryRetentionPlan,\n} from \"./recovery-retention.types.ts\";\n\nasync function workspaceReason(\n entry: StorageEntry,\n inspection: RecoveryInspection,\n): Promise<string> {\n if (inspection.resources?.complete === false)\n return \"RESOURCE_ACTIVITY_UNKNOWN\";\n if (\n inspection.resources?.entries.some(\n (resource) => resource.record?.workspace === entry.path,\n )\n )\n return \"RESOURCE_ACTIVITY_RECORDED\";\n const workspace = inspection.git?.workspaces.find(\n (value) => value.path === entry.path,\n );\n if (!workspace || workspace.state !== \"registered\")\n return \"WORKSPACE_UNREGISTERED_OR_UNKNOWN\";\n if (workspace.branch === null) return \"DETACHED_WORKSPACE\";\n if (workspace.dirty) return \"DIRTY_WORKSPACE\";\n if (workspace.locked) return \"GIT_LOCKED_WORKSPACE\";\n try {\n await lstat(lockPath(inspection.repository, workspace.branch));\n return \"OPERATION_LOCK_PRESENT\";\n } catch (error) {\n if (!(\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ))\n return \"OWNERSHIP_UNKNOWN\";\n }\n try {\n const ignored = await git(entry.path, [\n \"ls-files\",\n \"--others\",\n \"--ignored\",\n \"--exclude-standard\",\n \"-z\",\n ]);\n if (ignored.length) return \"IGNORED_FILES\";\n } catch {\n return \"WORKSPACE_STATE_UNKNOWN\";\n }\n return \"ELIGIBLE\";\n}\n\nexport async function planRecoveryRetention(\n options: RecoveryRetentionOptions,\n): Promise<RecoveryRetentionPlan> {\n retentionPolicy(options.policy);\n const policy = structuredClone(options.policy);\n const inspection = await inspectRecovery({\n ...options,\n git: true,\n locks: true,\n resources: true,\n });\n const entries: RecoveryRetentionEntry[] = [];\n const inspectedAt = new Date().toISOString();\n const complete = inspection.complete && inspection.git?.complete !== false;\n for (const category of inspection.categories) {\n for (const entry of category.entries) {\n let reason = \"RECOVERY_DATA_PROTECTED\";\n if (category.name === \"locks\") reason = \"OWNERSHIP_RECORD_PROTECTED\";\n if (category.name === \"logs\") reason = \"LOG_ACTIVITY_OR_CONTENT_UNKNOWN\";\n if (category.name === \"workspaces\") reason = \"SCOPE_NOT_SELECTED\";\n if (\n category.name === \"workspaces\" &&\n policy.scopes.includes(\"clean-workspaces\")\n )\n reason = await workspaceReason(entry, inspection);\n if (\n category.name === \"logs\" &&\n policy.scopes.includes(\"closed-logs\") &&\n entry.kind === \"file\" &&\n entry.name.endsWith(\".jsonl\") &&\n (await closedJournal(entry.path))\n )\n reason = \"ELIGIBLE\";\n if (category.name === \"logs\" && entry.name.endsWith(\".closed.json\"))\n reason = \"CLOSURE_RECORD_PROTECTED\";\n if (\n reason === \"ELIGIBLE\" &&\n (!entry.modifiedAt ||\n Date.parse(inspectedAt) - Date.parse(entry.modifiedAt) <\n policy.minAgeMs)\n )\n reason = \"RETENTION_AGE\";\n if (reason === \"ELIGIBLE\" && (!complete || !entry.complete))\n reason = \"INCOMPLETE_INVENTORY\";\n const workspace = inspection.git?.workspaces.find(\n (value) => value.path === entry.path,\n );\n entries.push({\n path: entry.path,\n category: category.name,\n bytes: entry.bytes,\n eligible: reason === \"ELIGIBLE\",\n reason,\n ...(entry.modifiedAt ? { modifiedAt: entry.modifiedAt } : {}),\n ...(workspace?.state === \"registered\" && workspace.branch\n ? { branch: workspace.branch, head: workspace.head }\n : {}),\n });\n }\n }\n const projectedBytes =\n inspection.usage.bytes -\n entries\n .filter((entry) => entry.eligible)\n .reduce(\n (sum, entry) =>\n sum +\n entry.bytes +\n (entry.category === \"logs\"\n ? (entries.find(\n (other) => other.path === `${entry.path}.closed.json`,\n )?.bytes ?? 0)\n : 0),\n 0,\n );\n const workspaces = entries.filter(\n (entry) => entry.category === \"workspaces\" && !entry.eligible,\n ).length;\n const exceeded =\n (policy.maxBytes !== undefined && projectedBytes > policy.maxBytes) ||\n (policy.maxWorkspaces !== undefined && workspaces > policy.maxWorkspaces);\n return {\n repository: inspection.repository,\n policy,\n inspectedAt,\n inspection,\n entries,\n complete,\n usageBytes: inspection.usage.bytes,\n projectedBytes,\n quota: !complete ? \"unknown\" : exceeded ? \"exceeded\" : \"within\",\n };\n}\n\nexport async function pruneRecoveryRetention(\n plan: RecoveryRetentionPlan,\n): Promise<RecoveryPruneResult> {\n retentionPolicy(plan.policy);\n invariant(plan.complete, \"Cannot prune an incomplete retention plan\");\n const removed: string[] = [];\n const retained: RecoveryRetainedEntry[] = [];\n for (const candidate of plan.entries.filter((entry) => entry.eligible)) {\n const fresh = await planRecoveryRetention({\n repository: plan.repository,\n policy: plan.policy,\n });\n const entry = fresh.entries.find((value) => value.path === candidate.path);\n if (\n !entry?.eligible ||\n entry.head !== candidate.head ||\n entry.branch !== candidate.branch ||\n entry.bytes !== candidate.bytes ||\n entry.modifiedAt !== candidate.modifiedAt\n ) {\n retained.push({ path: candidate.path, reason: \"PLAN_CHANGED\" });\n continue;\n }\n try {\n if (entry.category === \"workspaces\" && entry.branch) {\n const release = await lock(plan.repository, entry.branch);\n try {\n const status = await git(entry.path, [\n \"status\",\n \"--porcelain=v1\",\n \"--ignored\",\n \"--untracked-files=all\",\n ]);\n invariant(!status.length, \"Workspace changed before pruning\");\n invariant(\n (await git(entry.path, [\"rev-parse\", \"HEAD\"])).trim() ===\n entry.head,\n \"Workspace HEAD changed before pruning\",\n );\n invariant(\n (\n await git(entry.path, [\"symbolic-ref\", \"--short\", \"HEAD\"])\n ).trim() === entry.branch,\n \"Workspace branch changed before pruning\",\n );\n await git(plan.repository, [\"worktree\", \"remove\", entry.path]);\n } finally {\n await release();\n }\n } else {\n const release = await lock(plan.repository, `journal:${entry.path}`);\n try {\n invariant(\n entry.category === \"logs\" && (await closedJournal(entry.path)),\n \"Journal changed before pruning\",\n );\n await rm(entry.path);\n await rm(`${entry.path}.closed.json`);\n } finally {\n await release();\n }\n }\n removed.push(entry.path);\n } catch {\n retained.push({\n path: candidate.path,\n reason: \"REVALIDATION_OR_REMOVAL_FAILED\",\n });\n }\n }\n return {\n removed,\n retained,\n after: await planRecoveryRetention({\n repository: plan.repository,\n policy: plan.policy,\n }),\n };\n}\n\nexport async function assertRecoveryQuota(\n options: RecoveryQuotaOptions,\n): Promise<void> {\n invariant(\n Number.isSafeInteger(options.maxBytes) && options.maxBytes >= 0,\n \"maxBytes must be a nonnegative integer\",\n );\n const reserve = options.reserveBytes ?? 0;\n invariant(\n Number.isSafeInteger(reserve) && reserve >= 0,\n \"reserveBytes must be a nonnegative integer\",\n );\n const inspection = await inspectRecovery(options);\n if (\n !inspection.complete ||\n inspection.usage.bytes + reserve > options.maxBytes\n )\n throw new OutpostError(\n \"workspace\",\n \"Outpost storage quota admission refused\",\n {\n usageBytes: inspection.usage.bytes,\n reserveBytes: reserve,\n maxBytes: options.maxBytes,\n complete: inspection.complete,\n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AAC,IAAI,CAAC;gBACZ,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,MAAM,EAAE,gCAAgC;aACzC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO;QACL,OAAO;QACP,QAAQ;QACR,KAAK,EAAE,MAAM,qBAAqB,CAAC;YACjC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;KACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAA6B;IAE7B,SAAS,CACP,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,EAC/D,wCAAwC,CACzC,CAAC;IACF,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC;IAC1C,SAAS,CACP,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAC7C,4CAA4C,CAC7C,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAClD,IACE,CAAC,UAAU,CAAC,QAAQ;QACpB,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ;QAEnD,MAAM,IAAI,YAAY,CACpB,WAAW,EACX,yCAAyC,EACzC;YACE,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK;YAClC,YAAY,EAAE,OAAO;YACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CACF,CAAC;AACN,CAAC","sourcesContent":["import type { TransportStoreOptions } from \"../domain/transport.types.ts\";\nimport {\n planTransportRetention,\n pruneTransportRetention,\n} from \"./transport-retention.ts\";\nimport { lstat, rm } from \"node:fs/promises\";\nimport { OutpostError, invariant } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { lock, lockPath } from \"../infrastructure/git/lock.ts\";\nimport { closedJournal } from \"../infrastructure/journal-retention.ts\";\nimport type { StorageEntry } from \"../infrastructure/storage-inventory.types.ts\";\nimport type { RecoveryInspection } from \"./recovery-inspection.types.ts\";\nimport { inspectRecovery } from \"./recovery-inspection.ts\";\nimport { retentionPolicy } from \"./recovery-retention-policy.ts\";\nimport type {\n RecoveryPruneResult,\n RecoveryRetainedEntry,\n RecoveryQuotaOptions,\n RecoveryRetentionEntry,\n RecoveryRetentionOptions,\n RecoveryRetentionPlan,\n} from \"./recovery-retention.types.ts\";\n\nasync function workspaceReason(\n entry: StorageEntry,\n inspection: RecoveryInspection,\n): Promise<string> {\n if (inspection.resources?.complete === false)\n return \"RESOURCE_ACTIVITY_UNKNOWN\";\n if (\n inspection.resources?.entries.some(\n (resource) => resource.record?.workspace === entry.path,\n )\n )\n return \"RESOURCE_ACTIVITY_RECORDED\";\n const workspace = inspection.git?.workspaces.find(\n (value) => value.path === entry.path,\n );\n if (!workspace || workspace.state !== \"registered\")\n return \"WORKSPACE_UNREGISTERED_OR_UNKNOWN\";\n if (workspace.branch === null) return \"DETACHED_WORKSPACE\";\n if (workspace.dirty) return \"DIRTY_WORKSPACE\";\n if (workspace.locked) return \"GIT_LOCKED_WORKSPACE\";\n try {\n await lstat(lockPath(inspection.repository, workspace.branch));\n return \"OPERATION_LOCK_PRESENT\";\n } catch (error) {\n if (!(\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ))\n return \"OWNERSHIP_UNKNOWN\";\n }\n try {\n const ignored = await git(entry.path, [\n \"ls-files\",\n \"--others\",\n \"--ignored\",\n \"--exclude-standard\",\n \"-z\",\n ]);\n if (ignored.length) return \"IGNORED_FILES\";\n } catch {\n return \"WORKSPACE_STATE_UNKNOWN\";\n }\n return \"ELIGIBLE\";\n}\n\nexport async function planRecoveryRetention(\n options: RecoveryRetentionOptions,\n): Promise<RecoveryRetentionPlan> {\n if (options.transporter) return planTransportRetention(options);\n retentionPolicy(options.policy);\n const policy = structuredClone(options.policy);\n const inspection = await inspectRecovery({\n ...options,\n git: true,\n locks: true,\n resources: true,\n });\n const entries: RecoveryRetentionEntry[] = [];\n const inspectedAt = new Date().toISOString();\n const complete = inspection.complete && inspection.git?.complete !== false;\n for (const category of inspection.categories) {\n for (const entry of category.entries) {\n let reason = \"RECOVERY_DATA_PROTECTED\";\n if (category.name === \"locks\") reason = \"OWNERSHIP_RECORD_PROTECTED\";\n if (category.name === \"logs\") reason = \"LOG_ACTIVITY_OR_CONTENT_UNKNOWN\";\n if (category.name === \"workspaces\") reason = \"SCOPE_NOT_SELECTED\";\n if (\n category.name === \"workspaces\" &&\n policy.scopes.includes(\"clean-workspaces\")\n )\n reason = await workspaceReason(entry, inspection);\n if (\n category.name === \"logs\" &&\n policy.scopes.includes(\"closed-logs\") &&\n entry.kind === \"file\" &&\n entry.name.endsWith(\".jsonl\") &&\n (await closedJournal(entry.path))\n )\n reason = \"ELIGIBLE\";\n if (category.name === \"logs\" && entry.name.endsWith(\".closed.json\"))\n reason = \"CLOSURE_RECORD_PROTECTED\";\n if (\n reason === \"ELIGIBLE\" &&\n (!entry.modifiedAt ||\n Date.parse(inspectedAt) - Date.parse(entry.modifiedAt) <\n policy.minAgeMs)\n )\n reason = \"RETENTION_AGE\";\n if (reason === \"ELIGIBLE\" && (!complete || !entry.complete))\n reason = \"INCOMPLETE_INVENTORY\";\n const workspace = inspection.git?.workspaces.find(\n (value) => value.path === entry.path,\n );\n entries.push({\n path: entry.path,\n category: category.name,\n bytes: entry.bytes,\n eligible: reason === \"ELIGIBLE\",\n reason,\n ...(entry.modifiedAt ? { modifiedAt: entry.modifiedAt } : {}),\n ...(workspace?.state === \"registered\" && workspace.branch\n ? { branch: workspace.branch, head: workspace.head }\n : {}),\n });\n }\n }\n const projectedBytes =\n inspection.usage.bytes -\n entries\n .filter((entry) => entry.eligible)\n .reduce(\n (sum, entry) =>\n sum +\n entry.bytes +\n (entry.category === \"logs\"\n ? (entries.find(\n (other) => other.path === `${entry.path}.closed.json`,\n )?.bytes ?? 0)\n : 0),\n 0,\n );\n const workspaces = entries.filter(\n (entry) => entry.category === \"workspaces\" && !entry.eligible,\n ).length;\n const exceeded =\n (policy.maxBytes !== undefined && projectedBytes > policy.maxBytes) ||\n (policy.maxWorkspaces !== undefined && workspaces > policy.maxWorkspaces);\n return {\n repository: inspection.repository,\n policy,\n inspectedAt,\n inspection,\n entries,\n complete,\n usageBytes: inspection.usage.bytes,\n projectedBytes,\n quota: !complete ? \"unknown\" : exceeded ? \"exceeded\" : \"within\",\n };\n}\n\nexport async function pruneRecoveryRetention(\n plan: RecoveryRetentionPlan,\n options?: TransportStoreOptions,\n): Promise<RecoveryPruneResult> {\n if (plan.source === \"transport\") {\n invariant(options, \"Transport retention requires its transporter\");\n return pruneTransportRetention(plan, options);\n }\n invariant(!options, \"Local retention does not accept a transporter\");\n retentionPolicy(plan.policy);\n invariant(plan.complete, \"Cannot prune an incomplete retention plan\");\n const removed: string[] = [];\n const retained: RecoveryRetainedEntry[] = [];\n for (const candidate of plan.entries.filter((entry) => entry.eligible)) {\n const fresh = await planRecoveryRetention({\n repository: plan.repository,\n policy: plan.policy,\n });\n const entry = fresh.entries.find((value) => value.path === candidate.path);\n if (\n !entry?.eligible ||\n entry.head !== candidate.head ||\n entry.branch !== candidate.branch ||\n entry.bytes !== candidate.bytes ||\n entry.modifiedAt !== candidate.modifiedAt\n ) {\n retained.push({ path: candidate.path, reason: \"PLAN_CHANGED\" });\n continue;\n }\n try {\n if (entry.category === \"workspaces\" && entry.branch) {\n const release = await lock(plan.repository, entry.branch);\n try {\n const status = await git(entry.path, [\n \"status\",\n \"--porcelain=v1\",\n \"--ignored\",\n \"--untracked-files=all\",\n ]);\n invariant(!status.length, \"Workspace changed before pruning\");\n invariant(\n (await git(entry.path, [\"rev-parse\", \"HEAD\"])).trim() ===\n entry.head,\n \"Workspace HEAD changed before pruning\",\n );\n invariant(\n (\n await git(entry.path, [\"symbolic-ref\", \"--short\", \"HEAD\"])\n ).trim() === entry.branch,\n \"Workspace branch changed before pruning\",\n );\n await git(plan.repository, [\"worktree\", \"remove\", entry.path]);\n } finally {\n await release();\n }\n } else {\n const release = await lock(plan.repository, `journal:${entry.path}`);\n try {\n invariant(\n entry.category === \"logs\" && (await closedJournal(entry.path)),\n \"Journal changed before pruning\",\n );\n await rm(entry.path);\n await rm(`${entry.path}.closed.json`);\n } finally {\n await release();\n }\n }\n removed.push(entry.path);\n } catch {\n retained.push({\n path: candidate.path,\n reason: \"REVALIDATION_OR_REMOVAL_FAILED\",\n });\n }\n }\n return {\n removed,\n retained,\n after: await planRecoveryRetention({\n repository: plan.repository,\n policy: plan.policy,\n }),\n };\n}\n\nexport async function assertRecoveryQuota(\n options: RecoveryQuotaOptions,\n): Promise<void> {\n invariant(\n Number.isSafeInteger(options.maxBytes) && options.maxBytes >= 0,\n \"maxBytes must be a nonnegative integer\",\n );\n const reserve = options.reserveBytes ?? 0;\n invariant(\n Number.isSafeInteger(reserve) && reserve >= 0,\n \"reserveBytes must be a nonnegative integer\",\n );\n const inspection = await inspectRecovery(options);\n if (\n !inspection.complete ||\n inspection.usage.bytes + reserve > options.maxBytes\n )\n throw new OutpostError(\n \"workspace\",\n \"Outpost storage quota admission refused\",\n {\n usageBytes: inspection.usage.bytes,\n reserveBytes: reserve,\n maxBytes: options.maxBytes,\n complete: inspection.complete,\n },\n );\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { Transport, TransportEntry } from "../domain/transport.types.ts";
1
2
  import type { RecoveryInspection } from "./recovery-inspection.types.ts";
2
3
  export interface RecoveryRetentionPolicy {
3
4
  readonly version: 1;
@@ -7,11 +8,14 @@ export interface RecoveryRetentionPolicy {
7
8
  readonly maxWorkspaces?: number;
8
9
  }
9
10
  export interface RecoveryRetentionOptions {
11
+ readonly transporter?: Transport;
10
12
  readonly repository?: string;
11
13
  readonly policy: RecoveryRetentionPolicy;
12
14
  readonly maxEntries?: number;
13
15
  }
14
16
  export interface RecoveryRetentionEntry {
17
+ readonly revision?: string;
18
+ readonly objects?: readonly TransportEntry[];
15
19
  readonly path: string;
16
20
  readonly category: string;
17
21
  readonly bytes: number;
@@ -22,6 +26,7 @@ export interface RecoveryRetentionEntry {
22
26
  readonly modifiedAt?: string;
23
27
  }
24
28
  export interface RecoveryRetentionPlan {
29
+ readonly source?: "transport";
25
30
  readonly repository: string;
26
31
  readonly policy: RecoveryRetentionPolicy;
27
32
  readonly inspectedAt: string;
@@ -45,6 +50,7 @@ export interface RecoveryPruneResult {
45
50
  readonly after: RecoveryRetentionPlan;
46
51
  }
47
52
  export interface RecoveryQuotaOptions {
53
+ readonly transporter?: Transport;
48
54
  readonly repository?: string;
49
55
  readonly maxBytes: number;
50
56
  readonly reserveBytes?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-retention.types.js","sourceRoot":"","sources":["../../src/application/recovery-retention.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RecoveryInspection } from \"./recovery-inspection.types.ts\";\nexport interface RecoveryRetentionPolicy {\n readonly version: 1;\n readonly scopes: readonly (\"clean-workspaces\" | \"closed-logs\")[];\n readonly minAgeMs: number;\n readonly maxBytes?: number;\n readonly maxWorkspaces?: number;\n}\nexport interface RecoveryRetentionOptions {\n readonly repository?: string;\n readonly policy: RecoveryRetentionPolicy;\n readonly maxEntries?: number;\n}\nexport interface RecoveryRetentionEntry {\n readonly path: string;\n readonly category: string;\n readonly bytes: number;\n readonly eligible: boolean;\n readonly reason: string;\n readonly branch?: string;\n readonly head?: string;\n readonly modifiedAt?: string;\n}\nexport interface RecoveryRetentionPlan {\n readonly repository: string;\n readonly policy: RecoveryRetentionPolicy;\n readonly inspectedAt: string;\n readonly inspection: RecoveryInspection;\n readonly entries: readonly RecoveryRetentionEntry[];\n readonly complete: boolean;\n readonly usageBytes: number;\n readonly projectedBytes: number;\n readonly quota: \"within\" | \"exceeded\" | \"unknown\";\n}\nexport interface RecoveryRetainedEntry {\n readonly path: string;\n readonly reason: string;\n}\nexport interface RecoveryPruneResult {\n readonly removed: readonly string[];\n readonly retained: readonly {\n readonly path: string;\n readonly reason: string;\n }[];\n readonly after: RecoveryRetentionPlan;\n}\nexport interface RecoveryQuotaOptions {\n readonly repository?: string;\n readonly maxBytes: number;\n readonly reserveBytes?: number;\n readonly maxEntries?: number;\n}\n"]}
1
+ {"version":3,"file":"recovery-retention.types.js","sourceRoot":"","sources":["../../src/application/recovery-retention.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Transport, TransportEntry } from \"../domain/transport.types.ts\";\nimport type { RecoveryInspection } from \"./recovery-inspection.types.ts\";\nexport interface RecoveryRetentionPolicy {\n readonly version: 1;\n readonly scopes: readonly (\"clean-workspaces\" | \"closed-logs\")[];\n readonly minAgeMs: number;\n readonly maxBytes?: number;\n readonly maxWorkspaces?: number;\n}\nexport interface RecoveryRetentionOptions {\n readonly transporter?: Transport;\n readonly repository?: string;\n readonly policy: RecoveryRetentionPolicy;\n readonly maxEntries?: number;\n}\nexport interface RecoveryRetentionEntry {\n readonly revision?: string;\n readonly objects?: readonly TransportEntry[];\n readonly path: string;\n readonly category: string;\n readonly bytes: number;\n readonly eligible: boolean;\n readonly reason: string;\n readonly branch?: string;\n readonly head?: string;\n readonly modifiedAt?: string;\n}\nexport interface RecoveryRetentionPlan {\n readonly source?: \"transport\";\n readonly repository: string;\n readonly policy: RecoveryRetentionPolicy;\n readonly inspectedAt: string;\n readonly inspection: RecoveryInspection;\n readonly entries: readonly RecoveryRetentionEntry[];\n readonly complete: boolean;\n readonly usageBytes: number;\n readonly projectedBytes: number;\n readonly quota: \"within\" | \"exceeded\" | \"unknown\";\n}\nexport interface RecoveryRetainedEntry {\n readonly path: string;\n readonly reason: string;\n}\nexport interface RecoveryPruneResult {\n readonly removed: readonly string[];\n readonly retained: readonly {\n readonly path: string;\n readonly reason: string;\n }[];\n readonly after: RecoveryRetentionPlan;\n}\nexport interface RecoveryQuotaOptions {\n readonly transporter?: Transport;\n readonly repository?: string;\n readonly maxBytes: number;\n readonly reserveBytes?: number;\n readonly maxEntries?: number;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { archiveRecovery } from "./recovery-archive.js";
1
2
  import { captureRecoveryChecksums } from "./recovery-checksum-capture.js";
2
3
  import { cp, mkdir, writeFile } from "node:fs/promises";
3
4
  import { dirname, join } from "node:path";
@@ -37,6 +38,13 @@ export async function backupHost(context, changes, synchronized, transfer) {
37
38
  };
38
39
  await writeFile(join(transfer, "state.json"), JSON.stringify(state));
39
40
  await captureRecoveryChecksums(transfer, state);
41
+ if (context.options.recoveryTransport) {
42
+ const reference = await archiveRecovery({
43
+ directory: transfer,
44
+ transporter: context.options.recoveryTransport,
45
+ });
46
+ await writeFile(join(transfer, "archive-reference.json"), JSON.stringify(reference), { mode: 0o600 });
47
+ }
40
48
  return { previousPatch, previousExtras };
41
49
  }
42
50
  //# sourceMappingURL=remote-backup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-backup.js","sourceRoot":"","sources":["../../src/application/remote-backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAMvD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAA+B,EAC/B,OAAsB,EACtB,YAAoB,EACpB,QAAgB;IAEhB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OA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checksum-capture.ts\";\nimport { cp, mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport type {\n HostBackup,\n RemoteChanges,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { extras } from \"./workspace-fingerprint.ts\";\n\nexport async function backupHost(\n context: RemoteWorkspaceContext,\n changes: RemoteChanges,\n synchronized: string,\n transfer: string,\n): Promise<HostBackup> {\n const { workspace } = context;\n const { head, incoming } = changes;\n const previousPatch = join(transfer, \"previous.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--binary\",\n \"HEAD\",\n `--output=${previousPatch}`,\n ]);\n await git(workspace.directory, [\n \"diff\",\n \"--cached\",\n \"--binary\",\n `--output=${join(transfer, \"previous-index.patch\")}`,\n ]);\n const previousExtras = await extras(workspace.directory);\n for (const file of previousExtras) {\n const backup = await safeDestination(\n join(transfer, \"previous-files\"),\n file,\n );\n await mkdir(dirname(backup), { recursive: true });\n await cp(await safeDestination(workspace.directory, file), backup, {\n dereference: false,\n verbatimSymlinks: true,\n });\n }\n const state = {\n previous: synchronized,\n next: head,\n previousExtras,\n incoming,\n };\n await writeFile(join(transfer, \"state.json\"), JSON.stringify(state));\n await captureRecoveryChecksums(transfer, state);\n\n return { previousPatch, previousExtras };\n}\n"]}
1
+ {"version":3,"file":"remote-backup.js","sourceRoot":"","sources":["../../src/application/remote-backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC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;QACd,QAAQ;KACT,CAAC;IACF,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,MAAM,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChD,IAAI,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC;YACtC,SAAS,EAAE,QAAQ;YACnB,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,iBAAiB;SAC/C,CAAC,CAAC;QACH,MAAM,SAAS,CACb,IAAI,CAAC,QAAQ,EAAE,wBAAwB,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EACzB,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import { archiveRecovery } from \"./recovery-archive.ts\";\nimport { captureRecoveryChecksums } from \"./recovery-checksum-capture.ts\";\nimport { cp, mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport type {\n HostBackup,\n RemoteChanges,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { extras } from \"./workspace-fingerprint.ts\";\n\nexport async function backupHost(\n context: RemoteWorkspaceContext,\n changes: RemoteChanges,\n synchronized: string,\n transfer: string,\n): Promise<HostBackup> {\n const { workspace } = context;\n const { head, incoming } = changes;\n const previousPatch = join(transfer, \"previous.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--binary\",\n \"HEAD\",\n `--output=${previousPatch}`,\n ]);\n await git(workspace.directory, [\n \"diff\",\n \"--cached\",\n \"--binary\",\n `--output=${join(transfer, \"previous-index.patch\")}`,\n ]);\n const previousExtras = await extras(workspace.directory);\n for (const file of previousExtras) {\n const backup = await safeDestination(\n join(transfer, \"previous-files\"),\n file,\n );\n await mkdir(dirname(backup), { recursive: true });\n await cp(await safeDestination(workspace.directory, file), backup, {\n dereference: false,\n verbatimSymlinks: true,\n });\n }\n const state = {\n previous: synchronized,\n next: head,\n previousExtras,\n incoming,\n };\n await writeFile(join(transfer, \"state.json\"), JSON.stringify(state));\n await captureRecoveryChecksums(transfer, state);\n if (context.options.recoveryTransport) {\n const reference = await archiveRecovery({\n directory: transfer,\n transporter: context.options.recoveryTransport,\n });\n await writeFile(\n join(transfer, \"archive-reference.json\"),\n JSON.stringify(reference),\n { mode: 0o600 },\n );\n }\n\n return { previousPatch, previousExtras };\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { Transport } from "../domain/transport.types.ts";
1
2
  import type { FileManifestEntry, SandboxLease } from "../domain/sandbox.types.ts";
2
3
  import type { StageLimits, WorkspaceRecord } from "../domain/workspace.types.ts";
3
4
  export interface RemoteSync {
@@ -5,6 +6,7 @@ export interface RemoteSync {
5
6
  close(): Promise<void>;
6
7
  }
7
8
  export interface RemoteSyncOptions {
9
+ readonly recoveryTransport?: Transport;
8
10
  readonly includeUncommitted?: boolean;
9
11
  readonly signal?: AbortSignal;
10
12
  readonly limits?: StageLimits;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-workspace.types.js","sourceRoot":"","sources":["../../src/application/remote-workspace.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n FileManifestEntry,\n SandboxLease,\n} from \"../domain/sandbox.types.ts\";\nimport type {\n StageLimits,\n WorkspaceRecord,\n} from \"../domain/workspace.types.ts\";\n\nexport interface RemoteSync {\n pull(): Promise<void>;\n close(): Promise<void>;\n}\n\nexport interface RemoteSyncOptions {\n readonly includeUncommitted?: boolean;\n readonly signal?: AbortSignal;\n readonly limits?: StageLimits;\n}\n\nexport interface RemoteWorkspaceContext {\n readonly transferred?: Map<string, FileManifestEntry>;\n readonly workspace: WorkspaceRecord;\n readonly lease: SandboxLease;\n readonly options: RemoteSyncOptions;\n readonly recovery: string;\n readonly remoteBundle: string;\n readonly run: (args: readonly string[]) => Promise<string>;\n readonly protectedFiles: readonly string[];\n readonly originalHead: string;\n readonly initialPatch: string;\n readonly initialIndex: string;\n}\nexport interface RemoteChanges {\n readonly manifest?: readonly FileManifestEntry[];\n readonly head: string;\n readonly patch: string;\n readonly incoming: readonly string[];\n}\nexport interface HostBackup {\n readonly previousPatch: string;\n readonly previousExtras: readonly string[];\n}\n"]}
1
+ {"version":3,"file":"remote-workspace.types.js","sourceRoot":"","sources":["../../src/application/remote-workspace.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Transport } from \"../domain/transport.types.ts\";\nimport type {\n FileManifestEntry,\n SandboxLease,\n} from \"../domain/sandbox.types.ts\";\nimport type {\n StageLimits,\n WorkspaceRecord,\n} from \"../domain/workspace.types.ts\";\n\nexport interface RemoteSync {\n pull(): Promise<void>;\n close(): Promise<void>;\n}\n\nexport interface RemoteSyncOptions {\n readonly recoveryTransport?: Transport;\n readonly includeUncommitted?: boolean;\n readonly signal?: AbortSignal;\n readonly limits?: StageLimits;\n}\n\nexport interface RemoteWorkspaceContext {\n readonly transferred?: Map<string, FileManifestEntry>;\n readonly workspace: WorkspaceRecord;\n readonly lease: SandboxLease;\n readonly options: RemoteSyncOptions;\n readonly recovery: string;\n readonly remoteBundle: string;\n readonly run: (args: readonly string[]) => Promise<string>;\n readonly protectedFiles: readonly string[];\n readonly originalHead: string;\n readonly initialPatch: string;\n readonly initialIndex: string;\n}\nexport interface RemoteChanges {\n readonly manifest?: readonly FileManifestEntry[];\n readonly head: string;\n readonly patch: string;\n readonly incoming: readonly string[];\n}\nexport interface HostBackup {\n readonly previousPatch: string;\n readonly previousExtras: readonly string[];\n}\n"]}
@@ -34,7 +34,8 @@ export function sandboxAgents(context) {
34
34
  const storage = storageFor(agent);
35
35
  invariant(storage, "This adapter does not support native conversations");
36
36
  const found = await storage.locate(id, workspace.repository, options.conversationHome);
37
- if (provider.placement !== "host" ||
37
+ if (found.reference !== undefined ||
38
+ provider.placement !== "host" ||
38
39
  workspace.directory !== workspace.repository)
39
40
  await storage.restore(found, {
40
41
  repository: workspace.repository,
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-agents.js","sourceRoot":"","sources":["../../src/application/sandbox-agents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMhD,MAAM,UAAU,aAAa,CAAC,OAA2B;IACvD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7E,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,WAAW,GAAG,KAAK,EACvB,QAAkC,EAClC,MAAmB,EACnB,EAAE;QACF,SAAS,CAAC,QAAQ,EAAE,mDAAmD,CAAC,CAAC;QACzE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;YACzB,QAAQ,CAAC,GAAG,CACV,QAAQ,EACR,QAAQ,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,KAAK,KAAK;gBAC5D,CAAC,CAAC,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC;gBACjD,CAAC,CAAC,QAAQ,CACb,CAAC;QACJ,MAAM,SAAS,GAAG,MAAM,gBAAgB,CACtC,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,SAAS,EAClB,QAAQ,CAAC,SAAS,CACnB,CAAC;QACF,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;Q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,KAAK,EAAE,EAAE,EAAE,EAAE;YACtB,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport type { Command } from \"../domain/command.types.ts\";\nimport { invariant } from \"../domain/errors.ts\";\nimport { resolveVariables } from \"../infrastructure/settings.ts\";\nimport { prepareAdapter } from \"./agent-bootstrap.ts\";\nimport { storageFor } from \"./agent-storage.ts\";\nimport type {\n ProvisionedSandbox,\n SandboxAgents,\n} from \"./sandbox-session.types.ts\";\n\nexport function sandboxAgents(context: ProvisionedSandbox): SandboxAgents {\n const { options, provider, workspace, runtime, prepared, staging } = context;\n const known = new Set<string>();\n const selectAgent = async (\n selected: AgentAdapter | undefined,\n signal: AbortSignal,\n ) => {\n invariant(selected, \"Provide an agent on the sandbox or this operation\");\n if (!prepared.has(selected))\n prepared.set(\n selected,\n provider.placement === \"remote\" && options.bootstrap !== false\n ? await prepareAdapter(selected, runtime, signal)\n : selected,\n );\n const variables = await resolveVariables(\n workspace.repository,\n selected.variables,\n provider.variables,\n );\n const adapter = prepared.get(selected)!;\n return {\n selected,\n adapter,\n executionLease: {\n ...runtime,\n invoke(command: Command) {\n return runtime.invoke({\n ...command,\n variables: { ...variables, ...command.variables },\n });\n },\n },\n };\n };\n const conversationKey = (agent: AgentAdapter, id: string) =>\n `${agent.storage?.name ?? agent.conversations ?? agent.name}:${id}`;\n const restore = async (id: string, agent: AgentAdapter) => {\n if (known.has(conversationKey(agent, id))) return;\n const storage = storageFor(agent);\n invariant(storage, \"This adapter does not support native conversations\");\n const found = await storage.locate(\n id,\n workspace.repository,\n options.conversationHome,\n );\n if (\n provider.placement !== \"host\" ||\n workspace.directory !== workspace.repository\n )\n await storage.restore(found, {\n repository: workspace.repository,\n sandbox: runtime,\n staging,\n });\n known.add(conversationKey(agent, id));\n };\n\n return {\n selectAgent,\n restore,\n remember: (agent, id) => {\n known.add(conversationKey(agent, id));\n },\n };\n}\n"]}
1
+ {"version":3,"file":"sandbox-agents.js","sourceRoot":"","sources":["../../src/application/sandbox-agents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMhD,MAAM,UAAU,aAAa,CAAC,OAA2B;IACvD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7E,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,WAAW,GAAG,KAAK,EACvB,QAAkC,EAClC,MAAmB,EACnB,EAAE;QACF,SAAS,CAAC,QAAQ,EAAE,mDAAmD,CAAC,CAAC;QACzE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;YACzB,QAAQ,CAAC,GAAG,CACV,QAAQ,EACR,QAAQ,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,KAAK,KAAK;gBAC5D,CAAC,CAAC,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC;gBACjD,CAAC,CAAC,QAAQ,CACb,CAAC;QACJ,MAAM,SAAS,GAAG,MAAM,gBAAgB,CACtC,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,SAAS,EAClB,QAAQ,CAAC,SAAS,CACnB,CAAC;QACF,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;QACxC,OAAO;YACL,QAAQ;YACR,OAAO;YACP,cAAc,EAAE;gBACd,GAAG,OAAO;gBACV,MAAM,CAAC,OAAgB;oBACr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eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentAdapter } from \"../domain/agent.types.ts\";\nimport type { Command } from \"../domain/command.types.ts\";\nimport { invariant } from \"../domain/errors.ts\";\nimport { resolveVariables } from \"../infrastructure/settings.ts\";\nimport { prepareAdapter } from \"./agent-bootstrap.ts\";\nimport { storageFor } from \"./agent-storage.ts\";\nimport type {\n ProvisionedSandbox,\n SandboxAgents,\n} from \"./sandbox-session.types.ts\";\n\nexport function sandboxAgents(context: ProvisionedSandbox): SandboxAgents {\n const { options, provider, workspace, runtime, prepared, staging } = context;\n const known = new Set<string>();\n const selectAgent = async (\n selected: AgentAdapter | undefined,\n signal: AbortSignal,\n ) => {\n invariant(selected, \"Provide an agent on the sandbox or this operation\");\n if (!prepared.has(selected))\n prepared.set(\n selected,\n provider.placement === \"remote\" && options.bootstrap !== false\n ? await prepareAdapter(selected, runtime, signal)\n : selected,\n );\n const variables = await resolveVariables(\n workspace.repository,\n selected.variables,\n provider.variables,\n );\n const adapter = prepared.get(selected)!;\n return {\n selected,\n adapter,\n executionLease: {\n ...runtime,\n invoke(command: Command) {\n return runtime.invoke({\n ...command,\n variables: { ...variables, ...command.variables },\n });\n },\n },\n };\n };\n const conversationKey = (agent: AgentAdapter, id: string) =>\n `${agent.storage?.name ?? agent.conversations ?? agent.name}:${id}`;\n const restore = async (id: string, agent: AgentAdapter) => {\n if (known.has(conversationKey(agent, id))) return;\n const storage = storageFor(agent);\n invariant(storage, \"This adapter does not support native conversations\");\n const found = await storage.locate(\n id,\n workspace.repository,\n options.conversationHome,\n );\n if (\n found.reference !== undefined ||\n provider.placement !== \"host\" ||\n workspace.directory !== workspace.repository\n )\n await storage.restore(found, {\n repository: workspace.repository,\n sandbox: runtime,\n staging,\n });\n known.add(conversationKey(agent, id));\n };\n\n return {\n selectAgent,\n restore,\n remember: (agent, id) => {\n known.add(conversationKey(agent, id));\n },\n };\n}\n"]}
@@ -61,6 +61,9 @@ export async function dispatchInSandbox(context, agents, result, dispatch) {
61
61
  return {
62
62
  ...turn,
63
63
  transcript: location.file,
64
+ ...(location.reference
65
+ ? { transcriptReference: location.reference }
66
+ : {}),
64
67
  ...(usage ? { usage } : {}),
65
68
  };
66
69
  });
@@ -98,6 +101,8 @@ export async function dispatchInSandbox(context, agents, result, dispatch) {
98
101
  commits: changes,
99
102
  transcript: transcript?.file,
100
103
  log: log.file,
104
+ logReference: log.reference,
105
+ transcriptReference: transcript?.reference,
101
106
  });
102
107
  throw failure;
103
108
  }
@@ -109,6 +114,10 @@ export async function dispatchInSandbox(context, agents, result, dispatch) {
109
114
  commits: changes,
110
115
  ...(transcript ? { transcript: transcript.file } : {}),
111
116
  ...(log.file ? { log: log.file } : {}),
117
+ ...(log.reference ? { logReference: log.reference } : {}),
118
+ ...(transcript?.reference
119
+ ? { transcriptReference: transcript.reference }
120
+ : {}),
112
121
  resume(next) {
113
122
  warmContinuation(next);
114
123
  invariant(conversation, "No conversation was emitted");
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-dispatch.js","sourceRoot":"","sources":["../../src/application/sandbox-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OA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,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,CAAI,IAAwB;YAChC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,SAAS,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAC;YACvD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAI,IAAwB;YAC9B,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,SAAS,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAC;YACvD,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport type { ConversationRecord } from \"../domain/conversation.types.ts\";\nimport { invariant, recordRecovery } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { commits } from \"../infrastructure/git/history.ts\";\nimport { journal } from \"../infrastructure/journal.ts\";\nimport { storageFor } from \"./agent-storage.ts\";\nimport { warmContinuation } from \"./continuation.ts\";\nimport { preflightDispatch } from \"./dispatch-validation.ts\";\nimport { execute } from \"./execution.ts\";\nimport type { DispatchOptions, Execution } from \"./execution.types.ts\";\nimport { notify } from \"./observation.ts\";\nimport type { Sandbox, WarmDispatchResult } from \"./outpost.types.ts\";\nimport type {\n ProvisionedSandbox,\n SandboxAgents,\n} from \"./sandbox-session.types.ts\";\n\nexport async function dispatchInSandbox<T>(\n context: ProvisionedSandbox,\n agents: SandboxAgents,\n result: Sandbox,\n dispatch: DispatchOptions<T>,\n): Promise<WarmDispatchResult<T>> {\n const { options, provider, workspace, runtime, sync, stop, staging } =\n context;\n const { selectAgent, restore } = agents;\n await preflightDispatch(\n dispatch,\n workspace.repository,\n dispatch.agent ?? options.agent,\n );\n const signal = dispatch.signal\n ? AbortSignal.any([dispatch.signal, stop.signal])\n : stop.signal;\n const { selected, adapter, executionLease } = await selectAgent(\n dispatch.agent ?? options.agent,\n signal,\n );\n if (dispatch.continuation) await restore(dispatch.continuation.id, selected);\n const baseline = (\n await git(workspace.directory, [\"rev-parse\", \"HEAD\"])\n ).trim();\n const log = await journal(\n workspace.repository,\n dispatch.logging ?? options.logging,\n dispatch.label,\n );\n let execution: Execution<T> | undefined,\n transcript: ConversationRecord | undefined;\n const captured = new Map<string, ConversationRecord>();\n const storage = storageFor(selected);\n let failure: unknown;\n let conversation = dispatch.continuation?.id;\n const conversations = new Set<string>(conversation ? [conversation] : []);\n const save = async (id: string) => {\n invariant(storage, \"Conversation storage is unavailable\");\n const location = await storage.capture(id, {\n repository: workspace.repository,\n sandbox: runtime,\n staging,\n ...(options.conversationHome ? { home: options.conversationHome } : {}),\n ...(dispatch.warn ? { warn: dispatch.warn } : {}),\n local: provider.placement === \"host\",\n });\n captured.set(id, location);\n transcript = location;\n return location;\n };\n try {\n execution = await execute(\n workspace,\n executionLease,\n adapter,\n provider.placement === \"host\",\n {\n ...dispatch,\n signal,\n observe(event) {\n if (event.kind === \"conversation\") {\n conversation = event.id;\n conversations.add(event.id);\n agents.remember(selected, event.id);\n }\n log.record(event);\n notify(dispatch.observe, event);\n },\n },\n async (turn) => {\n if (!turn.conversation || !storage || selected.capture === false)\n return turn;\n const location = await save(turn.conversation);\n const usage = selected.transcriptUsage?.(\n await readFile(location.file, \"utf8\"),\n );\n return {\n ...turn,\n transcript: location.file,\n ...(usage ? { usage } : {}),\n };\n },\n );\n } catch (cause) {\n failure = cause;\n log.record({\n kind: \"failure\",\n message: cause instanceof Error ? cause.message : String(cause),\n });\n }\n try {\n await sync?.pull();\n if (storage && selected.capture !== false)\n for (const id of conversations)\n if (failure || !captured.has(id)) await save(id);\n } catch (cause) {\n failure = failure\n ? new AggregateError(\n [failure, cause],\n \"Execution and recovery both failed\",\n )\n : cause;\n }\n try {\n await log.close();\n } catch (cause) {\n failure ??= cause;\n }\n const changes = await commits(\n workspace.directory,\n baseline,\n options.limits?.collectMs,\n );\n if (failure) {\n recordRecovery(failure, {\n branch: workspace.branch,\n directory: workspace.directory,\n commits: changes,\n transcript: transcript?.file,\n log: log.file,\n });\n throw failure;\n }\n invariant(execution, \"Execution did not produce a result\");\n return {\n ...execution,\n branch: workspace.branch,\n directory: workspace.directory,\n commits: changes,\n ...(transcript ? { transcript: transcript.file } : {}),\n ...(log.file ? { log: log.file } : {}),\n resume<U>(next: DispatchOptions<U>) {\n warmContinuation(next);\n invariant(conversation, \"No conversation was emitted\");\n return result.resume(conversation, { agent: selected, ...next });\n },\n fork<U>(next: DispatchOptions<U>) {\n warmContinuation(next);\n invariant(conversation, \"No conversation was emitted\");\n return result.fork(conversation, { agent: selected, ...next });\n },\n };\n}\n"]}
1
+ {"version":3,"file":"sandbox-dispatch.js","sourceRoot":"","sources":["../../src/application/sandbox-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAO1C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAC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C,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,UAAU,EAAE,SAAS;YACvB,CAAC,CAAC,EAAE,mBAAmB,EAAE,UAAU,CAAC,SAAS,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,CAAI,IAAwB;YAChC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,SAAS,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAC;YACvD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAI,IAAwB;YAC9B,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,SAAS,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAC;YACvD,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport type { ConversationRecord } from \"../domain/conversation.types.ts\";\nimport { invariant, recordRecovery } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { commits } from \"../infrastructure/git/history.ts\";\nimport { journal } from \"../infrastructure/journal.ts\";\nimport { storageFor } from \"./agent-storage.ts\";\nimport { warmContinuation } from \"./continuation.ts\";\nimport { preflightDispatch } from \"./dispatch-validation.ts\";\nimport { execute } from \"./execution.ts\";\nimport type { DispatchOptions, Execution } from \"./execution.types.ts\";\nimport { notify } from \"./observation.ts\";\nimport type { Sandbox, WarmDispatchResult } from \"./outpost.types.ts\";\nimport type {\n ProvisionedSandbox,\n SandboxAgents,\n} from \"./sandbox-session.types.ts\";\n\nexport async function dispatchInSandbox<T>(\n context: ProvisionedSandbox,\n agents: SandboxAgents,\n result: Sandbox,\n dispatch: DispatchOptions<T>,\n): Promise<WarmDispatchResult<T>> {\n const { options, provider, workspace, runtime, sync, stop, staging } =\n context;\n const { selectAgent, restore } = agents;\n await preflightDispatch(\n dispatch,\n workspace.repository,\n dispatch.agent ?? options.agent,\n );\n const signal = dispatch.signal\n ? AbortSignal.any([dispatch.signal, stop.signal])\n : stop.signal;\n const { selected, adapter, executionLease } = await selectAgent(\n dispatch.agent ?? options.agent,\n signal,\n );\n if (dispatch.continuation) await restore(dispatch.continuation.id, selected);\n const baseline = (\n await git(workspace.directory, [\"rev-parse\", \"HEAD\"])\n ).trim();\n const log = await journal(\n workspace.repository,\n dispatch.logging ?? options.logging,\n dispatch.label,\n );\n let execution: Execution<T> | undefined,\n transcript: ConversationRecord | undefined;\n const captured = new Map<string, ConversationRecord>();\n const storage = storageFor(selected);\n let failure: unknown;\n let conversation = dispatch.continuation?.id;\n const conversations = new Set<string>(conversation ? [conversation] : []);\n const save = async (id: string) => {\n invariant(storage, \"Conversation storage is unavailable\");\n const location = await storage.capture(id, {\n repository: workspace.repository,\n sandbox: runtime,\n staging,\n ...(options.conversationHome ? { home: options.conversationHome } : {}),\n ...(dispatch.warn ? { warn: dispatch.warn } : {}),\n local: provider.placement === \"host\",\n });\n captured.set(id, location);\n transcript = location;\n return location;\n };\n try {\n execution = await execute(\n workspace,\n executionLease,\n adapter,\n provider.placement === \"host\",\n {\n ...dispatch,\n signal,\n observe(event) {\n if (event.kind === \"conversation\") {\n conversation = event.id;\n conversations.add(event.id);\n agents.remember(selected, event.id);\n }\n log.record(event);\n notify(dispatch.observe, event);\n },\n },\n async (turn) => {\n if (!turn.conversation || !storage || selected.capture === false)\n return turn;\n const location = await save(turn.conversation);\n const usage = selected.transcriptUsage?.(\n await readFile(location.file, \"utf8\"),\n );\n return {\n ...turn,\n transcript: location.file,\n ...(location.reference\n ? { transcriptReference: location.reference }\n : {}),\n ...(usage ? { usage } : {}),\n };\n },\n );\n } catch (cause) {\n failure = cause;\n log.record({\n kind: \"failure\",\n message: cause instanceof Error ? cause.message : String(cause),\n });\n }\n try {\n await sync?.pull();\n if (storage && selected.capture !== false)\n for (const id of conversations)\n if (failure || !captured.has(id)) await save(id);\n } catch (cause) {\n failure = failure\n ? new AggregateError(\n [failure, cause],\n \"Execution and recovery both failed\",\n )\n : cause;\n }\n try {\n await log.close();\n } catch (cause) {\n failure ??= cause;\n }\n const changes = await commits(\n workspace.directory,\n baseline,\n options.limits?.collectMs,\n );\n if (failure) {\n recordRecovery(failure, {\n branch: workspace.branch,\n directory: workspace.directory,\n commits: changes,\n transcript: transcript?.file,\n log: log.file,\n logReference: log.reference,\n transcriptReference: transcript?.reference,\n });\n throw failure;\n }\n invariant(execution, \"Execution did not produce a result\");\n return {\n ...execution,\n branch: workspace.branch,\n directory: workspace.directory,\n commits: changes,\n ...(transcript ? { transcript: transcript.file } : {}),\n ...(log.file ? { log: log.file } : {}),\n ...(log.reference ? { logReference: log.reference } : {}),\n ...(transcript?.reference\n ? { transcriptReference: transcript.reference }\n : {}),\n resume<U>(next: DispatchOptions<U>) {\n warmContinuation(next);\n invariant(conversation, \"No conversation was emitted\");\n return result.resume(conversation, { agent: selected, ...next });\n },\n fork<U>(next: DispatchOptions<U>) {\n warmContinuation(next);\n invariant(conversation, \"No conversation was emitted\");\n return result.fork(conversation, { agent: selected, ...next });\n },\n };\n}\n"]}
@@ -46,6 +46,9 @@ export async function provisionSandbox(options) {
46
46
  try {
47
47
  activity = await registerResourceActivity({
48
48
  repository: workspace.repository,
49
+ ...(options.activityTransport
50
+ ? { transporter: options.activityTransport }
51
+ : {}),
49
52
  workspace: workspace.directory,
50
53
  provider: provider.name,
51
54
  placement: provider.placement,
@@ -74,6 +77,9 @@ export async function provisionSandbox(options) {
74
77
  });
75
78
  if (provider.placement === "remote") {
76
79
  sync = await seedRemote(workspace, lease, {
80
+ ...(options.recoveryTransport
81
+ ? { recoveryTransport: options.recoveryTransport }
82
+ : {}),
77
83
  ...(options.includeUncommitted ? { includeUncommitted: true } : {}),
78
84
  ...(options.limits ? { limits: options.limits } : {}),
79
85
  signal: setupSignal,