@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.54

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 (287) hide show
  1. package/CHANGELOG.md +149 -1
  2. package/README.md +295 -37
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.d.ts +26 -20
  9. package/dist/agents-store.js +42 -34
  10. package/dist/api-only.d.ts +25 -6
  11. package/dist/api-only.js +34 -13
  12. package/dist/claude-login.d.ts +1 -0
  13. package/dist/claude-login.js +1 -1
  14. package/dist/cli-learning/cli.d.ts +3 -0
  15. package/dist/cli-learning/cli.js +17 -3
  16. package/dist/cli-learning/connections.js +3 -2
  17. package/dist/cli-learning/schema.js +2 -1
  18. package/dist/cli.js +76 -8
  19. package/dist/composio-preset.d.ts +3 -1
  20. package/dist/composio-preset.js +5 -3
  21. package/dist/composio-triggers.d.ts +4 -0
  22. package/dist/composio-triggers.js +4 -1
  23. package/dist/computer-needs.d.ts +32 -0
  24. package/dist/computer-needs.js +80 -0
  25. package/dist/computer-setting.d.ts +5 -2
  26. package/dist/computer-setting.js +8 -1
  27. package/dist/computers.d.ts +0 -2
  28. package/dist/computers.js +1 -1
  29. package/dist/console/assets/index-B_85An2t.js +745 -0
  30. package/dist/console/assets/index-n1YsbnYh.css +1 -0
  31. package/dist/console/index.html +2 -2
  32. package/dist/console-links.d.ts +1 -0
  33. package/dist/console-links.js +2 -0
  34. package/dist/env-switch.d.ts +14 -0
  35. package/dist/env-switch.js +23 -0
  36. package/dist/errors.d.ts +5 -0
  37. package/dist/errors.js +10 -0
  38. package/dist/eval-previous.js +4 -3
  39. package/dist/fal-price.js +10 -13
  40. package/dist/github-connection.d.ts +50 -1
  41. package/dist/github-connection.js +96 -3
  42. package/dist/github-faux.d.ts +11 -2
  43. package/dist/github-faux.js +138 -7
  44. package/dist/github-pull-request.d.ts +37 -0
  45. package/dist/github-pull-request.js +110 -0
  46. package/dist/handed-secret.d.ts +4 -0
  47. package/dist/handed-secret.js +10 -0
  48. package/dist/harness-archive.d.ts +15 -5
  49. package/dist/harness-archive.js +71 -34
  50. package/dist/harness-check.d.ts +2 -1
  51. package/dist/harness-check.js +36 -95
  52. package/dist/harness-egress.d.ts +23 -0
  53. package/dist/harness-egress.js +69 -0
  54. package/dist/harness-recipe-entry.d.ts +71 -0
  55. package/dist/harness-recipe-entry.js +184 -0
  56. package/dist/harness-recipe.d.ts +73 -6
  57. package/dist/harness-recipe.js +185 -31
  58. package/dist/harness-sign-in.d.ts +29 -0
  59. package/dist/harness-sign-in.js +122 -0
  60. package/dist/harness-table.d.ts +21 -0
  61. package/dist/harness-table.js +58 -3
  62. package/dist/harness-zip.d.ts +6 -0
  63. package/dist/harness-zip.js +203 -0
  64. package/dist/ids.d.ts +11 -0
  65. package/dist/ids.js +36 -0
  66. package/dist/learn/commit.d.ts +14 -1
  67. package/dist/learn/commit.js +156 -1
  68. package/dist/learn/compile.js +22 -8
  69. package/dist/learn/folder.d.ts +5 -0
  70. package/dist/learn/folder.js +10 -1
  71. package/dist/learn/learning.sh +15 -3
  72. package/dist/learn/promote.d.ts +2 -2
  73. package/dist/learn/secrets.js +30 -7
  74. package/dist/learning-routes.d.ts +23 -11
  75. package/dist/learning-routes.js +110 -20
  76. package/dist/learning.d.ts +9 -6
  77. package/dist/learning.js +9 -4
  78. package/dist/live-reach.d.ts +34 -7
  79. package/dist/live-reach.js +76 -11
  80. package/dist/mcp-gateway.js +15 -2
  81. package/dist/mcp-probe.d.ts +3 -0
  82. package/dist/mcp-probe.js +8 -3
  83. package/dist/mcp-resources.d.ts +44 -0
  84. package/dist/mcp-resources.js +100 -0
  85. package/dist/mcp-servers-store.d.ts +16 -12
  86. package/dist/model.d.ts +4 -4
  87. package/dist/model.js +6 -6
  88. package/dist/native/cli.js +9 -2
  89. package/dist/native/connection.d.ts +2 -2
  90. package/dist/native/connection.js +5 -2
  91. package/dist/native/discovery.d.ts +2 -0
  92. package/dist/native/discovery.js +10 -6
  93. package/dist/native/remote-worker-bridge.js +36 -4
  94. package/dist/native/remote.d.ts +18 -1
  95. package/dist/native/remote.js +126 -37
  96. package/dist/native/schema.d.ts +6 -0
  97. package/dist/native/schema.js +31 -6
  98. package/dist/native/source-account.d.ts +13 -0
  99. package/dist/native/source-account.js +114 -0
  100. package/dist/native/source-capture-hooks.d.ts +5 -0
  101. package/dist/native/source-capture-hooks.js +102 -0
  102. package/dist/native/source-mcp-selection.d.ts +13 -0
  103. package/dist/native/source-mcp-selection.js +72 -0
  104. package/dist/native/source-runtime-tools.d.ts +19 -0
  105. package/dist/native/source-runtime-tools.js +103 -0
  106. package/dist/native/source-snapshot-types.d.ts +138 -0
  107. package/dist/native/source-snapshot-types.js +12 -0
  108. package/dist/native/source-snapshot.d.ts +8 -0
  109. package/dist/native/source-snapshot.js +1201 -0
  110. package/dist/observation/learning.js +3 -2
  111. package/dist/openapi.js +275 -40
  112. package/dist/print.js +1 -1
  113. package/dist/purged-workflow.d.ts +12 -0
  114. package/dist/purged-workflow.js +43 -0
  115. package/dist/run-keys.d.ts +46 -0
  116. package/dist/run-keys.js +109 -0
  117. package/dist/run-launch.d.ts +16 -1
  118. package/dist/run-launch.js +30 -1
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-model-key.d.ts +2 -2
  121. package/dist/run-model-key.js +5 -5
  122. package/dist/run-secrets.d.ts +2 -0
  123. package/dist/run-secrets.js +7 -4
  124. package/dist/run-view.d.ts +17 -0
  125. package/dist/run-view.js +25 -1
  126. package/dist/runner/adapter-loop.d.ts +11 -3
  127. package/dist/runner/adapter-loop.js +138 -22
  128. package/dist/runner/adapter-run-spec.js +26 -13
  129. package/dist/runner/audit.d.ts +2 -0
  130. package/dist/runner/audit.js +9 -1
  131. package/dist/runner/beside.js +2 -1
  132. package/dist/runner/claim-secrets.d.ts +29 -3
  133. package/dist/runner/claim-secrets.js +38 -4
  134. package/dist/runner/cli-run-spec.js +24 -13
  135. package/dist/runner/harness-loops.d.ts +6 -0
  136. package/dist/runner/harness-loops.js +11 -1
  137. package/dist/runner/held.d.ts +4 -0
  138. package/dist/runner/journal-kinds.d.ts +2 -0
  139. package/dist/runner/learned-first.d.ts +2 -0
  140. package/dist/runner/learned-first.js +1 -1
  141. package/dist/runner/learning-end.d.ts +7 -2
  142. package/dist/runner/learning-end.js +22 -10
  143. package/dist/runner/learning-seed.d.ts +9 -3
  144. package/dist/runner/learning-seed.js +2 -2
  145. package/dist/runner/main.d.ts +1 -0
  146. package/dist/runner/main.js +20 -13
  147. package/dist/runner/mcp-claim.js +6 -1
  148. package/dist/runner/mcp-run.d.ts +10 -7
  149. package/dist/runner/mcp-run.js +3 -5
  150. package/dist/runner/metrics.d.ts +4 -2
  151. package/dist/runner/metrics.js +15 -3
  152. package/dist/runner/monid-run.js +9 -11
  153. package/dist/runner/pr-checkout.d.ts +21 -4
  154. package/dist/runner/pr-checkout.js +103 -4
  155. package/dist/runner/project-checkpoint.d.ts +35 -0
  156. package/dist/runner/project-checkpoint.js +116 -0
  157. package/dist/runner/project-drain.d.ts +8 -0
  158. package/dist/runner/project-drain.js +25 -0
  159. package/dist/runner/project-host.d.ts +10 -0
  160. package/dist/runner/project-host.js +52 -0
  161. package/dist/runner/promotion.d.ts +14 -6
  162. package/dist/runner/promotion.js +98 -41
  163. package/dist/runner/redact.d.ts +13 -0
  164. package/dist/runner/redact.js +67 -1
  165. package/dist/runner/run-channel.d.ts +9 -0
  166. package/dist/runner/run-channel.js +15 -2
  167. package/dist/runner/run-child-host.d.ts +8 -4
  168. package/dist/runner/run-child-host.js +178 -45
  169. package/dist/runner/run-errors.js +2 -2
  170. package/dist/runner/runner-check.d.ts +3 -0
  171. package/dist/runner/runner-check.js +28 -2
  172. package/dist/runner/runner.js +26 -9
  173. package/dist/runner/store-secrets.js +7 -3
  174. package/dist/runner/workflow-first.d.ts +4 -0
  175. package/dist/runner/workflow-first.js +13 -0
  176. package/dist/runner/workflow-loop.d.ts +2 -1
  177. package/dist/runner/workflow-loop.js +2 -1
  178. package/dist/runner/workflow-spec.js +1 -1
  179. package/dist/runs-over-store.d.ts +34 -6
  180. package/dist/runs-over-store.js +133 -25
  181. package/dist/sdk/runs.d.ts +11 -1
  182. package/dist/sdk/runs.js +117 -26
  183. package/dist/sdk/schema.js +12 -2
  184. package/dist/sdk/workflows.d.ts +1 -1
  185. package/dist/server.d.ts +79 -32
  186. package/dist/server.js +673 -113
  187. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  188. package/dist/source-sync/adoption.d.ts +15 -0
  189. package/dist/source-sync/adoption.js +36 -0
  190. package/dist/source-sync/auxiliary.d.ts +23 -0
  191. package/dist/source-sync/auxiliary.js +64 -0
  192. package/dist/source-sync/capture-git.d.ts +5 -0
  193. package/dist/source-sync/capture-git.js +272 -0
  194. package/dist/source-sync/capture-project.d.ts +53 -0
  195. package/dist/source-sync/capture-project.js +206 -0
  196. package/dist/source-sync/capture-refusal.d.ts +7 -0
  197. package/dist/source-sync/capture-refusal.js +16 -0
  198. package/dist/source-sync/capture.d.ts +11 -0
  199. package/dist/source-sync/capture.js +22 -0
  200. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  201. package/dist/source-sync/checkpoint-gate.js +52 -0
  202. package/dist/source-sync/checkpoints.d.ts +66 -0
  203. package/dist/source-sync/checkpoints.js +168 -0
  204. package/dist/source-sync/claim.d.ts +11 -0
  205. package/dist/source-sync/claim.js +48 -0
  206. package/dist/source-sync/destination.d.ts +47 -0
  207. package/dist/source-sync/destination.js +239 -0
  208. package/dist/source-sync/io.d.ts +15 -0
  209. package/dist/source-sync/io.js +52 -0
  210. package/dist/source-sync/local.d.ts +43 -0
  211. package/dist/source-sync/local.js +229 -0
  212. package/dist/source-sync/prepare.d.ts +59 -0
  213. package/dist/source-sync/prepare.js +93 -0
  214. package/dist/source-sync/projects.d.ts +61 -0
  215. package/dist/source-sync/projects.js +130 -0
  216. package/dist/source-sync/registry.d.ts +95 -0
  217. package/dist/source-sync/registry.js +226 -0
  218. package/dist/source-sync/service.d.ts +33 -0
  219. package/dist/source-sync/service.js +118 -0
  220. package/dist/source-sync/skill-edits.d.ts +12 -0
  221. package/dist/source-sync/skill-edits.js +122 -0
  222. package/dist/source-sync/snapshots.d.ts +48 -0
  223. package/dist/source-sync/snapshots.js +448 -0
  224. package/dist/source-sync/types.d.ts +9 -0
  225. package/dist/source-sync/types.js +14 -0
  226. package/dist/source-sync/workspace.d.ts +66 -0
  227. package/dist/source-sync/workspace.js +273 -0
  228. package/dist/store/agent-body.d.ts +6 -2
  229. package/dist/store/agent-body.js +18 -7
  230. package/dist/store/index.d.ts +2 -2
  231. package/dist/store/index.js +1 -1
  232. package/dist/store/schema.d.ts +2 -1
  233. package/dist/store/schema.js +2 -1
  234. package/dist/store/seal.d.ts +5 -1
  235. package/dist/store/seal.js +12 -3
  236. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  237. package/dist/store/sqlite/project-checkpoints.js +70 -0
  238. package/dist/store/sqlite/run-launch.d.ts +4 -12
  239. package/dist/store/sqlite/run-launch.js +5 -19
  240. package/dist/store/sqlite/store.js +224 -170
  241. package/dist/store/store.d.ts +116 -39
  242. package/dist/store/store.js +14 -1
  243. package/dist/store-reads/learning.d.ts +2 -2
  244. package/dist/store-view.d.ts +3 -1
  245. package/dist/store-view.js +17 -5
  246. package/dist/suggestions.d.ts +282 -0
  247. package/dist/suggestions.js +919 -0
  248. package/dist/telemetry.d.ts +8 -1
  249. package/dist/telemetry.js +12 -4
  250. package/dist/template-import.d.ts +27 -2
  251. package/dist/template-import.js +148 -13
  252. package/dist/templates.d.ts +103 -77
  253. package/dist/templates.js +71 -17
  254. package/dist/timeline/index.d.ts +1 -1
  255. package/dist/timeline/index.js +1 -1
  256. package/dist/timeline/timeline.d.ts +5 -0
  257. package/dist/timeline/timeline.js +8 -0
  258. package/dist/tool-plane.d.ts +12 -12
  259. package/dist/tools.d.ts +8 -8
  260. package/dist/trigger-launch-hook.d.ts +49 -0
  261. package/dist/trigger-launch-hook.js +91 -0
  262. package/dist/trigger-targets.d.ts +14 -1
  263. package/dist/trigger-targets.js +20 -0
  264. package/dist/triggers.d.ts +54 -5
  265. package/dist/triggers.js +143 -8
  266. package/dist/uploads-archil.js +1 -1
  267. package/dist/uploads.js +1 -1
  268. package/dist/validate.d.ts +1 -1
  269. package/dist/validate.js +3 -4
  270. package/dist/workspace/computer-for-claim.d.ts +2 -0
  271. package/dist/workspace/computer-for-claim.js +43 -0
  272. package/dist/workspace/paths.d.ts +6 -0
  273. package/dist/workspace/paths.js +6 -0
  274. package/dist/workspace/resolve-computer.d.ts +1 -0
  275. package/dist/workspace/run-tools.d.ts +2 -0
  276. package/dist/workspace/run-tools.js +8 -0
  277. package/dist/workspace/synced-folder.d.ts +1 -1
  278. package/dist/workspace/synced-folder.js +11 -14
  279. package/launcher/agentrun-serve +1 -1
  280. package/package.json +10 -10
  281. package/skills/agentrun-serve/SKILL.md +2 -1
  282. package/templates/README.md +8 -4
  283. package/templates/agent-scout/agent.md +46 -0
  284. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  285. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  286. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  287. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -0,0 +1,48 @@
1
+ import { type SourceSnapshot, type SourceSnapshotEntry } from "../native/source-snapshot-types.js";
2
+ import { type Workspace } from "../workspace/workspace.js";
3
+ export declare class SnapshotError extends Error {
4
+ readonly code: "invalid" | "incomplete" | "missing" | "corrupt" | "limit" | "prerequisite" | "conflict" | "unsafe_resume";
5
+ constructor(code: "invalid" | "incomplete" | "missing" | "corrupt" | "limit" | "prerequisite" | "conflict" | "unsafe_resume", message: string);
6
+ }
7
+ export type SnapshotLimits = {
8
+ files: number;
9
+ bytes: number;
10
+ fileBytes: number;
11
+ gitBytes: number;
12
+ manifestBytes: number;
13
+ };
14
+ /** Validate available content and diagnostics identically for complete/incomplete uploads, without writing. Missing
15
+ * skill closure or Git history is allowed only in an explicitly incomplete snapshot, never committed or seeded. */
16
+ export declare function validateSourceSnapshot(snapshot: SourceSnapshot, given?: Partial<SnapshotLimits>): void;
17
+ /** Writes verified content first, then its complete immutable manifest. Returns no current pointer: the service may
18
+ * publish this digest only in its authorized store CAS. Failed writes leave at most unreferenced content. */
19
+ export declare function commitSourceSnapshot(work: Workspace, snapshot: SourceSnapshot, given?: Partial<SnapshotLimits>): Promise<string>;
20
+ /** Reads only a committed manifest; verifies every exact binary blob and the full manifest digest. */
21
+ export declare function readSourceSnapshot(work: Workspace, sha: string, given?: Partial<SnapshotLimits>): Promise<SourceSnapshot>;
22
+ export type SeedEntry = SourceSnapshotEntry & {
23
+ path: string;
24
+ };
25
+ export interface SeedPreparation {
26
+ /** Apply and verify exact modes durably through the destination's capabilities. No ambient host filesystem. */
27
+ applyModes(work: Workspace, entries: readonly SeedEntry[]): Promise<void>;
28
+ /** Restore Git metadata/index only, never checkout files or execute hooks, filters or network operations. Must be
29
+ * idempotent before dispatch and return only when HEAD/branch/index match the supplied source metadata. */
30
+ restoreGit?(work: Workspace, git: NonNullable<SourceSnapshot["project"]["git"]>, bundle: Uint8Array): Promise<void>;
31
+ }
32
+ export declare function seedEntries(snapshot: SourceSnapshot): SeedEntry[];
33
+ /** Seed one pinned project in an exclusive pre-admission placement. `control` is a separate, private run-owned
34
+ * Workspace, inaccessible to agent tools. The caller guarantees exclusive initialization and proves beforeDispatch;
35
+ * these booleans are evidence supplied by that lifecycle, not locks this module acquires. A missing marker proves nothing.
36
+ * A matching completed marker makes reclaim read-only, preserving every later edit. This is not a checkpoint. */
37
+ export declare function seedSourceSnapshot(options: {
38
+ snapshots: Workspace;
39
+ destination: Workspace;
40
+ control: Workspace;
41
+ digest: string;
42
+ beforeDispatch: boolean;
43
+ exclusiveInitialization: boolean;
44
+ preparation?: SeedPreparation;
45
+ limits?: Partial<SnapshotLimits>;
46
+ }): Promise<{
47
+ seeded: boolean;
48
+ }>;
@@ -0,0 +1,448 @@
1
+ // Immutable source bundles and first-task seeding over Workspace. Authority/current pointers belong to the caller's
2
+ // store transaction. This layer neither chooses a current snapshot nor proves project continuity between runs.
3
+ import { createHash } from "node:crypto";
4
+ import { isNativeRuntime, NATIVE_RUNTIME_FACTS } from "../native/runtimes.js";
5
+ import { removeOwnedCaptureHooks } from "../native/source-capture-hooks.js";
6
+ import { sourceMcpSelection } from "../native/source-mcp-selection.js";
7
+ import { sourceAccountMetadataValid } from "../native/source-account.js";
8
+ import { SOURCE_NATIVE_CAPABILITIES, sourceSnapshotDigest } from "../native/source-snapshot-types.js";
9
+ import { relativeSegments } from "../workspace/paths.js";
10
+ export class SnapshotError extends Error {
11
+ code;
12
+ constructor(code, message) {
13
+ super(message);
14
+ this.code = code;
15
+ this.name = "SnapshotError";
16
+ }
17
+ }
18
+ const MAX = { files: 10_000, bytes: 64 * 1024 * 1024, fileBytes: 8 * 1024 * 1024, gitBytes: 32 * 1024 * 1024, manifestBytes: 4 * 1024 * 1024 };
19
+ const digestPattern = /^[a-f0-9]{64}$/;
20
+ const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
21
+ const canonical = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item)
22
+ ? Object.fromEntries(Object.keys(item).sort().map(key => [key, item[key]])) : item);
23
+ function fail(message) { throw new SnapshotError("invalid", message); }
24
+ const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
25
+ const strings = (value) => Array.isArray(value) && value.every(item => typeof item === "string");
26
+ const size = (value) => Number.isSafeInteger(value) && Number(value) >= 0;
27
+ function limits(given = {}) {
28
+ const result = { ...MAX, ...given };
29
+ for (const key of Object.keys(MAX))
30
+ if (!Number.isSafeInteger(result[key]) || result[key] <= 0 || result[key] > MAX[key])
31
+ throw new SnapshotError("limit", "Snapshot limits must be positive and no larger than the supported ceiling.");
32
+ return result;
33
+ }
34
+ function digest(value) { if (typeof value !== "string" || !digestPattern.test(value))
35
+ fail("A snapshot digest must be a SHA-256 hex value."); }
36
+ function path(value) {
37
+ if (typeof value !== "string" || Buffer.byteLength(value) > 4096 || /[\x00-\x1f\x7f]/.test(value))
38
+ fail("A snapshot path is invalid.");
39
+ try {
40
+ if (relativeSegments(value).length === 0)
41
+ fail("A snapshot entry must name a path below its root.");
42
+ }
43
+ catch {
44
+ fail("A snapshot path must remain inside its namespace.");
45
+ }
46
+ }
47
+ /** Refuse non-JSON/deep input before canonicalizing it; manifests are untrusted, including their policy objects. */
48
+ function jsonTree(value, maximum) {
49
+ let nodes = 0, bytes = 0;
50
+ const seen = new Set();
51
+ const visit = (v, depth) => {
52
+ if (++nodes > 200_000 || depth > 32)
53
+ throw new SnapshotError("limit", "Snapshot metadata is too complex.");
54
+ if (typeof v === "string")
55
+ bytes += Buffer.byteLength(v);
56
+ else if (v === null || typeof v === "boolean" || typeof v === "number" && Number.isFinite(v))
57
+ bytes += 8;
58
+ else if (typeof v === "object" && v !== null && (Array.isArray(v) || Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null)) {
59
+ if (seen.has(v))
60
+ fail("Snapshot metadata must be JSON.");
61
+ seen.add(v);
62
+ for (const [key, item] of Object.entries(v)) {
63
+ bytes += Buffer.byteLength(key);
64
+ visit(item, depth + 1);
65
+ }
66
+ seen.delete(v);
67
+ }
68
+ else
69
+ fail("Snapshot metadata must be JSON.");
70
+ if (bytes > maximum)
71
+ throw new SnapshotError("limit", "Snapshot metadata exceeds its byte limit.");
72
+ };
73
+ visit(value, 0);
74
+ }
75
+ function manifestOf(snapshot) { return { ...snapshot, blobs: Object.keys(snapshot.blobs).sort() }; }
76
+ function validateManifest(value, cap) {
77
+ jsonTree(value, cap.manifestBytes);
78
+ if (!record(value) || value.version !== 1 || typeof value.complete !== "boolean" || !strings(value.blobs) || !Array.isArray(value.entries) || !Array.isArray(value.blockers))
79
+ fail("The source snapshot manifest is invalid.");
80
+ digest(value.digest);
81
+ if (value.complete !== (value.blockers.length === 0))
82
+ fail("Snapshot completeness must agree with its blockers.");
83
+ for (const blocker of value.blockers)
84
+ if (!record(blocker) || typeof blocker.code !== "string" || typeof blocker.message !== "string" || blocker.path !== undefined && typeof blocker.path !== "string")
85
+ fail("Snapshot diagnostics are invalid.");
86
+ if (value.entries.length > cap.files || value.blobs.length > cap.files * 2 + 1)
87
+ throw new SnapshotError("limit", "The source snapshot has too many entries.");
88
+ if (new Set(value.blobs).size !== value.blobs.length)
89
+ fail("Snapshot blob identities must be unique.");
90
+ value.blobs.forEach(digest);
91
+ const source = value.source;
92
+ if (!record(source) || !isNativeRuntime(source.runtime) || typeof source.machine_id !== "string" || typeof source.project !== "string" || !record(source.selector)
93
+ || !["project", "profile", "agent"].includes(source.selector.kind) || source.selector.kind !== "project" && typeof source.selector.name !== "string")
94
+ fail("Snapshot source identity is invalid.");
95
+ const entries = new Map(), references = new Map();
96
+ const reference = (sha, bytes, maximum) => {
97
+ digest(sha);
98
+ if (!size(bytes))
99
+ fail("A snapshot byte count is invalid.");
100
+ if (bytes > maximum)
101
+ throw new SnapshotError("limit", "A snapshot blob exceeds its byte limit.");
102
+ if (references.has(sha) && references.get(sha) !== bytes)
103
+ fail("A shared blob has conflicting byte counts.");
104
+ references.set(sha, bytes);
105
+ };
106
+ for (const entry of value.entries) {
107
+ if (!record(entry))
108
+ fail("A snapshot entry is invalid.");
109
+ path(entry.path);
110
+ if (!["project", "instruction", "skill"].includes(entry.role) || !["file", "directory"].includes(entry.type) || !size(entry.mode) || entry.mode > 0o777 || !size(entry.bytes))
111
+ fail("A snapshot entry has invalid metadata.");
112
+ const prefix = entry.role === "instruction" ? "instructions" : entry.role === "skill" ? "skills" : "project";
113
+ if (entry.path !== prefix && !entry.path.startsWith(`${prefix}/`))
114
+ fail("A snapshot entry is outside its declared namespace.");
115
+ if (entry.path === prefix && entry.type !== "directory")
116
+ fail("A snapshot namespace root must be a directory.");
117
+ if (entry.role === "project" && entry.path.split("/").includes(".git"))
118
+ fail("Project entries cannot carry Git control files.");
119
+ if (entries.has(entry.path))
120
+ fail("Snapshot entry paths must be unique.");
121
+ entries.set(entry.path, entry);
122
+ if (entry.type === "file")
123
+ reference(entry.sha256, entry.bytes, cap.fileBytes);
124
+ else if (entry.bytes !== 0 || entry.sha256 !== undefined)
125
+ fail("A snapshot directory cannot carry file content.");
126
+ }
127
+ for (const entry of entries.values()) {
128
+ const parts = entry.path.split("/");
129
+ for (let n = 1; n < parts.length; n++)
130
+ if (entries.get(parts.slice(0, n).join("/"))?.type === "file")
131
+ fail("A snapshot file cannot contain another entry.");
132
+ }
133
+ const instructions = value.instructions;
134
+ if (!record(instructions) || typeof instructions.text !== "string" || !Array.isArray(instructions.layers))
135
+ fail("Snapshot instructions are invalid.");
136
+ for (const layer of instructions.layers)
137
+ if (!record(layer) || typeof layer.source !== "string" || !size(layer.precedence) || entries.get(layer.path)?.role !== "instruction" || entries.get(layer.path)?.type !== "file")
138
+ fail("An instruction layer has no captured file.");
139
+ if (!Array.isArray(value.skills))
140
+ fail("Snapshot skills are invalid.");
141
+ const skillNames = new Set(), skillPaths = [];
142
+ for (const skill of value.skills) {
143
+ if (!record(skill) || typeof skill.source !== "string")
144
+ fail("Snapshot skill identity is invalid.");
145
+ path(skill.name);
146
+ path(skill.path);
147
+ if (skill.name.includes("/") || !skill.path.startsWith("skills/") || value.complete && (skillNames.has(skill.name) || entries.get(`${skill.path}/SKILL.md`)?.type !== "file"))
148
+ fail("A complete selected skill must have one unique name and captured SKILL.md.");
149
+ if (skillPaths.some(p => skill.path.startsWith(`${p}/`) || p.startsWith(`${skill.path}/`) || p === skill.path))
150
+ fail("Selected skill roots must not overlap.");
151
+ skillNames.add(skill.name);
152
+ skillPaths.push(skill.path);
153
+ }
154
+ for (const entry of entries.values())
155
+ if (entry.role === "skill" && !skillPaths.some(p => entry.path === p || entry.path.startsWith(`${p}/`)))
156
+ fail("A skill asset is outside the selected skill closure.");
157
+ const config = value.configuration;
158
+ if (!record(config) || !(config.model === null || typeof config.model === "string") || !Array.isArray(config.tools) || !record(config.permissions) || !strings(config.credentials))
159
+ fail("Snapshot configuration is invalid.");
160
+ for (const tool of config.tools)
161
+ if (!record(tool) || typeof tool.name !== "string" || !["http", "stdio"].includes(tool.transport) || !strings(tool.credentials) || tool.url !== undefined && typeof tool.url !== "string"
162
+ || tool.selection !== undefined && !sourceMcpSelection(tool.selection)
163
+ || tool.resources !== undefined && (!strings(tool.resources) || tool.resources.length > 3 || new Set(tool.resources).size !== tool.resources.length || tool.resources.some((op) => !["list", "templates", "read"].includes(op))))
164
+ fail("Snapshot tool requirements are invalid.");
165
+ const nativeTools = config.native_tools;
166
+ if (config.native_account !== undefined && (!sourceAccountMetadataValid(config.native_account)
167
+ || value.complete && ["managed", "unknown"].includes(config.native_account.plan ?? "")))
168
+ fail("Snapshot native account policy evidence is invalid or incomplete.");
169
+ if (nativeTools !== undefined) {
170
+ const known = new Set(SOURCE_NATIVE_CAPABILITIES);
171
+ if (!record(nativeTools) || !(nativeTools.version === null || typeof nativeTools.version === "string") || typeof nativeTools.complete !== "boolean"
172
+ || !["versioned-runtime", "native-resolved"].includes(nativeTools.source) || !strings(nativeTools.capabilities) || !strings(nativeTools.disabled)
173
+ || nativeTools.capabilities.length + nativeTools.disabled.length > known.size || value.complete && !nativeTools.complete
174
+ || new Set([...nativeTools.capabilities, ...nativeTools.disabled]).size !== nativeTools.capabilities.length + nativeTools.disabled.length
175
+ || [...nativeTools.capabilities, ...nativeTools.disabled].some(item => !known.has(item)))
176
+ fail("Snapshot native capability evidence is invalid.");
177
+ }
178
+ if (!record(value.project))
179
+ fail("Snapshot project metadata is invalid.");
180
+ const git = value.project.git;
181
+ if (git !== null) {
182
+ if (!record(git) || !(git.head === null || typeof git.head === "string" && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(git.head)) || !(git.branch === null || typeof git.branch === "string") || typeof git.dirty !== "boolean" || !strings(git.deleted) || !["complete", "unavailable"].includes(git.history))
183
+ fail("Git project metadata is invalid.");
184
+ if (value.complete && (git.history !== "complete" || !git.head || !record(git.bundle)))
185
+ fail("A complete Git project needs restorable history.");
186
+ for (const deleted of git.deleted) {
187
+ path(deleted);
188
+ if (deleted.split("/").includes(".git") || entries.has(`project/${deleted}`))
189
+ fail("A Git deletion cannot name control files or captured content.");
190
+ }
191
+ if (git.bundle !== undefined) {
192
+ if (!record(git.bundle))
193
+ fail("A Git bundle is invalid.");
194
+ reference(git.bundle.sha256, git.bundle.bytes, cap.gitBytes);
195
+ }
196
+ }
197
+ if (value.transforms !== undefined && (!Array.isArray(value.transforms) || value.transforms.length > value.entries.length))
198
+ fail("Snapshot transforms are invalid.");
199
+ const transformed = new Set();
200
+ for (const transform of value.transforms ?? []) {
201
+ if (!record(transform) || transform.kind !== "agentrun-capture-hooks" || typeof transform.path !== "string" || transformed.has(transform.path)
202
+ || !record(transform.receipt))
203
+ fail("A capture-hook transform is invalid or duplicated.");
204
+ const original = entries.get(transform.path), receipt = entries.get(transform.receipt.path);
205
+ const projectPath = NATIVE_RUNTIME_FACTS[source.runtime].protocol === "codex-json" ? "project/.codex/hooks.json" : "project/.claude/settings.local.json";
206
+ const external = /^instructions\/capture-hooks\/[a-f0-9]{12}\/hooks\.json$/.test(transform.path) && NATIVE_RUNTIME_FACTS[source.runtime].protocol === "codex-json";
207
+ if (!original || original.type !== "file" || original.sha256 !== transform.original_sha256 || original.bytes !== transform.original_bytes
208
+ || (transform.path !== projectPath && !external) || original.role !== (external ? "instruction" : "project")
209
+ || transform.receipt.path !== `project/.agentrun/cli-learning/${source.runtime}.json`
210
+ || !receipt || receipt.type !== "file" || receipt.role !== "project" || receipt.sha256 !== transform.receipt.sha256)
211
+ fail("A capture-hook transform does not match its source and installer receipt.");
212
+ reference(transform.destination_sha256, transform.destination_bytes, cap.fileBytes);
213
+ transformed.add(transform.path);
214
+ }
215
+ if (value.blobs.length !== references.size || value.blobs.some((sha) => !references.has(sha)))
216
+ fail("Every snapshot blob must match one referenced asset or Git bundle.");
217
+ if ([...references.values()].reduce((sum, bytes) => sum + bytes, 0) > cap.bytes)
218
+ throw new SnapshotError("limit", "The snapshot exceeds its total byte limit.");
219
+ const expanded = [...entries.values()].reduce((sum, entry) => sum + entry.bytes, 0) + (git?.bundle?.bytes ?? 0) + (value.transforms ?? []).reduce((sum, transform) => sum + transform.destination_bytes, 0);
220
+ if (expanded > cap.bytes)
221
+ throw new SnapshotError("limit", "The expanded source files exceed the snapshot byte limit.");
222
+ if (Buffer.byteLength(canonical(value)) > cap.manifestBytes)
223
+ throw new SnapshotError("limit", "The manifest exceeds its byte limit.");
224
+ const shaped = value;
225
+ if (sourceSnapshotDigest({ ...shaped, blobs: Object.fromEntries(shaped.blobs.map(sha => [sha, ""])) }) !== shaped.digest)
226
+ throw new SnapshotError("corrupt", "The source manifest does not match its digest.");
227
+ return shaped;
228
+ }
229
+ function blobSizes(manifest) {
230
+ const result = new Map(manifest.entries.filter(entry => entry.type === "file").map(entry => [entry.sha256, entry.bytes]));
231
+ for (const transform of manifest.transforms ?? [])
232
+ result.set(transform.destination_sha256, transform.destination_bytes);
233
+ const bundle = manifest.project.git?.bundle;
234
+ if (bundle)
235
+ result.set(bundle.sha256, bundle.bytes);
236
+ return result;
237
+ }
238
+ async function readBounded(work, name, maximum) {
239
+ const stat = await work.stat(name);
240
+ if (!stat)
241
+ return undefined;
242
+ if (stat.kind !== "file")
243
+ throw new SnapshotError("corrupt", "A snapshot object is not a regular file.");
244
+ if (stat.size > maximum)
245
+ throw new SnapshotError("limit", "A stored snapshot object exceeds its byte limit.");
246
+ const bytes = await work.read(name, { length: maximum + 1 });
247
+ if (bytes.length > maximum)
248
+ throw new SnapshotError("limit", "A stored snapshot object exceeds its byte limit.");
249
+ return bytes;
250
+ }
251
+ const manifestPath = (sha) => `manifests/${sha}.json`;
252
+ const blobPath = (sha) => `blobs/${sha}`;
253
+ function verifiedSnapshot(snapshot, given) {
254
+ const cap = limits(given);
255
+ if (!record(snapshot) || !record(snapshot.blobs))
256
+ fail("A snapshot must include its blobs.");
257
+ const manifest = validateManifest(manifestOf(snapshot), cap), decoded = new Map();
258
+ for (const [sha, bytes] of blobSizes(manifest)) {
259
+ const encoded = snapshot.blobs[sha];
260
+ if (typeof encoded !== "string" || encoded.length > Math.ceil(bytes / 3) * 4)
261
+ fail("A snapshot blob has invalid base64 or length.");
262
+ const body = Buffer.from(encoded, "base64");
263
+ if (body.length !== bytes || body.toString("base64") !== encoded || hash(body) !== sha)
264
+ throw new SnapshotError("corrupt", "A source blob does not match its digest and byte count.");
265
+ decoded.set(sha, body);
266
+ }
267
+ for (const transform of manifest.transforms ?? []) {
268
+ let reproduced;
269
+ try {
270
+ reproduced = removeOwnedCaptureHooks(decoded.get(transform.original_sha256), decoded.get(transform.receipt.sha256), manifest.source);
271
+ }
272
+ catch {
273
+ throw new SnapshotError("invalid", "A capture-hook transform has no verified installer ownership.");
274
+ }
275
+ if (transform.path.startsWith("project/") !== (reproduced.configRoot === manifest.source.project)
276
+ || !reproduced.bytes.equals(Buffer.from(decoded.get(transform.destination_sha256))))
277
+ throw new SnapshotError("invalid", "A capture-hook transform changes more than the verified owned handlers.");
278
+ }
279
+ return { cap, manifest, decoded };
280
+ }
281
+ /** Validate available content and diagnostics identically for complete/incomplete uploads, without writing. Missing
282
+ * skill closure or Git history is allowed only in an explicitly incomplete snapshot, never committed or seeded. */
283
+ export function validateSourceSnapshot(snapshot, given) {
284
+ verifiedSnapshot(snapshot, given);
285
+ }
286
+ /** Writes verified content first, then its complete immutable manifest. Returns no current pointer: the service may
287
+ * publish this digest only in its authorized store CAS. Failed writes leave at most unreferenced content. */
288
+ export async function commitSourceSnapshot(work, snapshot, given) {
289
+ const { cap, manifest, decoded } = verifiedSnapshot(snapshot, given);
290
+ if (!manifest.complete)
291
+ throw new SnapshotError("incomplete", "Only a complete source snapshot can be committed.");
292
+ const encodedManifest = canonical(manifest), held = await readBounded(work, manifestPath(manifest.digest), cap.manifestBytes);
293
+ if (held !== undefined && Buffer.from(held).toString("utf8") !== encodedManifest)
294
+ throw new SnapshotError("corrupt", "A committed snapshot manifest cannot be replaced.");
295
+ // Validate every existing object before any writes, including on idempotent retries.
296
+ const missing = [];
297
+ for (const [sha, body] of decoded) {
298
+ const saved = await readBounded(work, blobPath(sha), body.length);
299
+ if (saved === undefined) {
300
+ if (held !== undefined)
301
+ throw new SnapshotError("corrupt", "A committed snapshot is missing content.");
302
+ missing.push([sha, body]);
303
+ }
304
+ else if (saved.length !== body.length || hash(saved) !== sha)
305
+ throw new SnapshotError("corrupt", "Stored snapshot content no longer matches its digest.");
306
+ }
307
+ for (const [sha, body] of missing)
308
+ await work.write(blobPath(sha), body);
309
+ if (held === undefined)
310
+ await work.write(manifestPath(manifest.digest), encodedManifest);
311
+ return manifest.digest;
312
+ }
313
+ /** Reads only a committed manifest; verifies every exact binary blob and the full manifest digest. */
314
+ export async function readSourceSnapshot(work, sha, given) {
315
+ digest(sha);
316
+ const cap = limits(given), bytes = await readBounded(work, manifestPath(sha), cap.manifestBytes);
317
+ if (bytes === undefined)
318
+ throw new SnapshotError("missing", "The complete source snapshot has not been committed.");
319
+ let raw;
320
+ try {
321
+ raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
322
+ }
323
+ catch {
324
+ throw new SnapshotError("corrupt", "The snapshot manifest is not valid JSON.");
325
+ }
326
+ const manifest = validateManifest(raw, cap);
327
+ if (!manifest.complete)
328
+ throw new SnapshotError("incomplete", "The stored snapshot is not complete.");
329
+ if (manifest.digest !== sha)
330
+ throw new SnapshotError("corrupt", "The requested snapshot and stored manifest disagree.");
331
+ const blobs = {};
332
+ for (const [id, expected] of blobSizes(manifest)) {
333
+ const body = await readBounded(work, blobPath(id), expected);
334
+ if (body === undefined || body.length !== expected || hash(body) !== id)
335
+ throw new SnapshotError("corrupt", "Stored snapshot content is missing or does not match its digest.");
336
+ blobs[id] = Buffer.from(body).toString("base64");
337
+ }
338
+ const snapshot = { ...manifest, blobs };
339
+ verifiedSnapshot(snapshot, given);
340
+ return snapshot;
341
+ }
342
+ export function seedEntries(snapshot) {
343
+ const entries = new Map();
344
+ for (const source of snapshot.entries) {
345
+ let target;
346
+ if (source.role === "project")
347
+ target = source.path === "project" ? "" : source.path.slice("project/".length);
348
+ else if (source.role === "skill") {
349
+ const skill = snapshot.skills.find(skill => source.path === skill.path || source.path.startsWith(`${skill.path}/`));
350
+ target = `.agents/skills/${skill.name}${source.path.slice(skill.path.length)}`;
351
+ }
352
+ if (target === undefined)
353
+ continue; // Instruction layers are managed configuration, not another ambient file copy.
354
+ if (target !== "")
355
+ path(target);
356
+ if (target.split("/").includes(".git"))
357
+ fail("Project entries cannot write Git control paths.");
358
+ const transform = snapshot.transforms?.find(item => item.path === source.path);
359
+ const entry = { ...source, path: target, ...(transform ? { sha256: transform.destination_sha256, bytes: transform.destination_bytes } : {}) }, previous = entries.get(target);
360
+ if (previous && (previous.type !== entry.type || previous.mode !== entry.mode || previous.bytes !== entry.bytes || previous.sha256 !== entry.sha256))
361
+ throw new SnapshotError("conflict", "Project files and authored skills disagree at the same destination path.");
362
+ entries.set(target, entry);
363
+ }
364
+ for (const entry of entries.values()) {
365
+ const parts = entry.path.split("/");
366
+ for (let n = 1; n < parts.length; n++)
367
+ if (entries.get(parts.slice(0, n).join("/"))?.type === "file")
368
+ throw new SnapshotError("conflict", "A seeded file would replace a required directory.");
369
+ }
370
+ return [...entries.values()].sort((a, b) => a.path.split("/").length - b.path.split("/").length || a.path.localeCompare(b.path));
371
+ }
372
+ /** Seed one pinned project in an exclusive pre-admission placement. `control` is a separate, private run-owned
373
+ * Workspace, inaccessible to agent tools. The caller guarantees exclusive initialization and proves beforeDispatch;
374
+ * these booleans are evidence supplied by that lifecycle, not locks this module acquires. A missing marker proves nothing.
375
+ * A matching completed marker makes reclaim read-only, preserving every later edit. This is not a checkpoint. */
376
+ export async function seedSourceSnapshot(options) {
377
+ const { snapshots, destination, control, preparation } = options;
378
+ if (destination === control)
379
+ throw new SnapshotError("invalid", "Seed control must be private and separate from the project workspace.");
380
+ const snapshot = await readSourceSnapshot(snapshots, options.digest, options.limits), entries = seedEntries(snapshot);
381
+ const markerPath = "source-seed.json", markerBytes = await readBounded(control, markerPath, 1024);
382
+ let marker;
383
+ if (markerBytes !== undefined) {
384
+ try {
385
+ marker = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(markerBytes));
386
+ }
387
+ catch {
388
+ throw new SnapshotError("corrupt", "The private seed marker is invalid.");
389
+ }
390
+ if (!marker || marker.version !== 1 || marker.digest !== snapshot.digest || !["writing", "complete"].includes(marker.phase))
391
+ throw new SnapshotError("conflict", "The run's seed marker does not match its pinned snapshot.");
392
+ if (marker.phase === "complete")
393
+ return { seeded: false };
394
+ }
395
+ if (options.beforeDispatch !== true || options.exclusiveInitialization !== true)
396
+ throw new SnapshotError("unsafe_resume", "An unfinished seed requires exclusive initialization before the first task starts.");
397
+ if (!preparation?.applyModes || snapshot.project.git && !preparation.restoreGit)
398
+ throw new SnapshotError("prerequisite", "The destination must support verified file modes and any required Git restoration before seeding.");
399
+ const gitControl = await destination.stat(".git");
400
+ if (gitControl && (!marker || !snapshot.project.git || gitControl.kind !== "dir"))
401
+ throw new SnapshotError("conflict", "Seeding would replace existing Git metadata.");
402
+ for (const deleted of snapshot.project.git?.deleted ?? [])
403
+ if (await destination.stat(deleted))
404
+ throw new SnapshotError("conflict", "A path deleted in the source already exists in the destination; it was preserved.");
405
+ // Inspect every destination and parent before writing. Never follow a planted link or replace unrelated input.
406
+ for (const entry of entries) {
407
+ const parts = entry.path.split("/");
408
+ for (let n = 1; n < parts.length; n++) {
409
+ const parent = await destination.stat(parts.slice(0, n).join("/"));
410
+ if (parent && parent.kind !== "dir")
411
+ throw new SnapshotError("conflict", "A seeded path has a non-directory parent.");
412
+ }
413
+ const current = await destination.stat(entry.path);
414
+ if (!current)
415
+ continue;
416
+ if (entry.type === "directory" && current.kind === "dir")
417
+ continue;
418
+ if (!marker || entry.type !== "file" || current.kind !== "file" || current.size !== entry.bytes)
419
+ throw new SnapshotError("conflict", "Seeding would replace an existing project file.");
420
+ if (hash(await destination.read(entry.path, { length: entry.bytes + 1 })) !== entry.sha256)
421
+ throw new SnapshotError("conflict", "An interrupted seed found a changed file; it was preserved.");
422
+ }
423
+ if (!marker)
424
+ await control.write(markerPath, canonical({ version: 1, digest: snapshot.digest, phase: "writing" }));
425
+ if (snapshot.project.git)
426
+ await preparation.restoreGit(destination, snapshot.project.git, Buffer.from(snapshot.blobs[snapshot.project.git.bundle.sha256], "base64"));
427
+ for (const entry of entries) {
428
+ if (entry.type === "directory") {
429
+ if (entry.path !== "")
430
+ await destination.mkdir(entry.path);
431
+ }
432
+ else {
433
+ const existing = await destination.stat(entry.path);
434
+ if (existing) {
435
+ if (!marker || existing.kind !== "file" || existing.size !== entry.bytes || hash(await destination.read(entry.path, { length: entry.bytes + 1 })) !== entry.sha256)
436
+ throw new SnapshotError("conflict", "A destination file changed during initialization; it was preserved.");
437
+ }
438
+ else
439
+ await destination.write(entry.path, Buffer.from(snapshot.blobs[entry.sha256], "base64"));
440
+ }
441
+ }
442
+ await preparation.applyModes(destination, entries);
443
+ for (const entry of entries)
444
+ if (entry.type === "file" && hash(await destination.read(entry.path, { length: entry.bytes + 1 })) !== entry.sha256)
445
+ throw new SnapshotError("corrupt", "Seeded content changed before initialization completed.");
446
+ await control.write(markerPath, canonical({ version: 1, digest: snapshot.digest, phase: "complete" }));
447
+ return { seeded: true };
448
+ }
@@ -0,0 +1,9 @@
1
+ /** Provenance of a managed revision made from an authorized source. Source credentials never live here. */
2
+ export interface SourceSyncBinding {
3
+ readonly id: string;
4
+ readonly snapshot: string;
5
+ readonly project: string;
6
+ /** Hash of the last applied configuration. An ordinary edit retains this baseline, so a later sync detects it. */
7
+ readonly configuration: string;
8
+ }
9
+ export declare function sourceSyncOf(body: unknown): SourceSyncBinding | undefined;
@@ -0,0 +1,14 @@
1
+ export function sourceSyncOf(body) {
2
+ if (!body || typeof body !== "object")
3
+ return undefined;
4
+ const value = body.sourceSync;
5
+ if (!value || typeof value !== "object")
6
+ return undefined;
7
+ const row = value;
8
+ if (Object.keys(row).length !== 4 || typeof row.id !== "string" || !/^[a-f0-9]{64}$/.test(row.id))
9
+ return undefined;
10
+ for (const key of ["snapshot", "project", "configuration"])
11
+ if (typeof row[key] !== "string" || !/^[a-f0-9]{64}$/.test(row[key]))
12
+ return undefined;
13
+ return value;
14
+ }
@@ -0,0 +1,66 @@
1
+ import type { KeyEnv } from "../key-meta.js";
2
+ import type { LaunchDisk, RunLaunch } from "../run-launch.js";
3
+ import type { Store } from "../store/store.js";
4
+ import { type ArchilDiskOptions, type ArchilDisk } from "../workspace/archil-disk.js";
5
+ import { type Workspace } from "../workspace/workspace.js";
6
+ import { type SeedPreparation } from "./snapshots.js";
7
+ import { type ProjectCaptureOptions } from "./capture-project.js";
8
+ type SourceStore = Pick<Store, "settings" | "sealedKeys">;
9
+ export interface SourceWorkspaceOptions {
10
+ readonly data: string;
11
+ readonly sealKey: Buffer | undefined;
12
+ readonly env?: KeyEnv;
13
+ readonly signal?: AbortSignal;
14
+ readonly control?: {
15
+ readonly baseUrl?: string;
16
+ readonly fetch?: typeof fetch;
17
+ readonly makeDisk?: (options: ArchilDiskOptions) => ArchilDisk;
18
+ };
19
+ }
20
+ export interface SourceWorkspace {
21
+ readonly mode: "local" | "archil";
22
+ readonly workspace: Workspace;
23
+ readonly launchDisk?: LaunchDisk;
24
+ end(): Promise<void>;
25
+ }
26
+ type RunTarget = {
27
+ readonly runId?: string;
28
+ readonly launch?: RunLaunch;
29
+ readonly requirePinned?: true;
30
+ readonly readOnly?: true;
31
+ };
32
+ /** Immutable cache on the agent's disk, or the caller's explicit pinned run disk. Account credentials stay in the
33
+ * resolver's closure; no secret or large snapshot is written to settings. Mode 2 never falls back to local files. */
34
+ export declare function sourceWorkspace(store: SourceStore, agentId: string, options: SourceWorkspaceOptions, target?: RunTarget): Promise<SourceWorkspace>;
35
+ /** Existing immutable source bytes only. Opening or closing a reader never allocates a disk, updates its ownership,
36
+ * writes files or sweeps execution spill. A missing retained source is an explicit prerequisite, not an empty cache. */
37
+ export declare function sourceSnapshotReader(store: SourceStore, agentId: string, options: SourceWorkspaceOptions, target?: RunTarget): Promise<SourceWorkspace>;
38
+ /** Runner verification opens only its private completed receipt. It allocates no disk, makes no directory, seeds
39
+ * nothing and gives no private file access to model tools. Missing pinned Mode 2 storage is a refusal. */
40
+ export declare function sourceRunControl(store: SourceStore, target: {
41
+ agentId: string;
42
+ runId: string;
43
+ launch: RunLaunch;
44
+ }, options: SourceWorkspaceOptions): Promise<SourceWorkspace>;
45
+ /** The caller holds the run's strict executor drain and storage sync across this operation. Git's temporary copy
46
+ * lives beside the private seed receipt, never in the model's project. It is removed only after all reads/commands
47
+ * have settled. This capability does not seed, change authority, or publish a checkpoint pointer. */
48
+ export declare function captureManagedProject(store: SourceStore, target: {
49
+ agentId: string;
50
+ runId: string;
51
+ launch: RunLaunch;
52
+ } & Omit<ProjectCaptureOptions, "git">, options: SourceWorkspaceOptions): Promise<import("../native/source-snapshot-types.js").SourceSnapshot>;
53
+ export interface SourceRunPlacement extends SourceWorkspace {
54
+ readonly control: Workspace;
55
+ readonly preparation: SeedPreparation;
56
+ /** Caller first resolves uncertain admission. This only removes the owned, still unadmitted run's folders. */
57
+ undo(): Promise<void>;
58
+ }
59
+ /** Called under the start path's exclusive reservation, before any run is admitted. Upload placement may already
60
+ * have made inputs/ and pinned a disk. All operations settle before this returns; end does not disable rollback. */
61
+ export declare function openRunPlacement(store: SourceStore & Pick<Store, "runs">, target: {
62
+ agentId: string;
63
+ runId: string;
64
+ launch: RunLaunch;
65
+ }, options: SourceWorkspaceOptions): Promise<SourceRunPlacement>;
66
+ export {};