@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.
- package/CHANGELOG.md +149 -1
- package/README.md +295 -37
- package/dist/agent-delete.d.ts +5 -6
- package/dist/agent-delete.js +30 -67
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +26 -20
- package/dist/agents-store.js +42 -34
- package/dist/api-only.d.ts +25 -6
- package/dist/api-only.js +34 -13
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +76 -8
- package/dist/composio-preset.d.ts +3 -1
- package/dist/composio-preset.js +5 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +5 -2
- package/dist/computer-setting.js +8 -1
- package/dist/computers.d.ts +0 -2
- package/dist/computers.js +1 -1
- package/dist/console/assets/index-B_85An2t.js +745 -0
- package/dist/console/assets/index-n1YsbnYh.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +10 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.js +10 -13
- package/dist/github-connection.d.ts +50 -1
- package/dist/github-connection.js +96 -3
- package/dist/github-faux.d.ts +11 -2
- package/dist/github-faux.js +138 -7
- package/dist/github-pull-request.d.ts +37 -0
- package/dist/github-pull-request.js +110 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +14 -1
- package/dist/learn/commit.js +156 -1
- package/dist/learn/compile.js +22 -8
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +10 -1
- package/dist/learn/learning.sh +15 -3
- package/dist/learn/promote.d.ts +2 -2
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning.d.ts +9 -6
- package/dist/learning.js +9 -4
- package/dist/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/mcp-gateway.js +15 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +8 -3
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +16 -12
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +275 -40
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +16 -1
- package/dist/run-launch.js +30 -1
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-view.d.ts +17 -0
- package/dist/run-view.js +25 -1
- package/dist/runner/adapter-loop.d.ts +11 -3
- package/dist/runner/adapter-loop.js +138 -22
- package/dist/runner/adapter-run-spec.js +26 -13
- package/dist/runner/audit.d.ts +2 -0
- package/dist/runner/audit.js +9 -1
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +29 -3
- package/dist/runner/claim-secrets.js +38 -4
- package/dist/runner/cli-run-spec.js +24 -13
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +11 -1
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +2 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +7 -2
- package/dist/runner/learning-end.js +22 -10
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-run.d.ts +10 -7
- package/dist/runner/mcp-run.js +3 -5
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +15 -3
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +14 -6
- package/dist/runner/promotion.js +98 -41
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +178 -45
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +28 -2
- package/dist/runner/runner.js +26 -9
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.d.ts +34 -6
- package/dist/runs-over-store.js +133 -25
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +117 -26
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +79 -32
- package/dist/server.js +673 -113
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +6 -2
- package/dist/store/agent-body.js +18 -7
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +2 -1
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +4 -12
- package/dist/store/sqlite/run-launch.js +5 -19
- package/dist/store/sqlite/store.js +224 -170
- package/dist/store/store.d.ts +116 -39
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +2 -2
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/suggestions.d.ts +282 -0
- package/dist/suggestions.js +919 -0
- package/dist/telemetry.d.ts +8 -1
- package/dist/telemetry.js +12 -4
- package/dist/template-import.d.ts +27 -2
- package/dist/template-import.js +148 -13
- package/dist/templates.d.ts +103 -77
- package/dist/templates.js +71 -17
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/trigger-launch-hook.d.ts +49 -0
- package/dist/trigger-launch-hook.js +91 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +1 -1
- package/dist/uploads.js +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +3 -4
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +1 -1
- package/dist/workspace/synced-folder.js +11 -14
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +8 -4
- package/templates/agent-scout/agent.md +46 -0
- package/templates/agent-scout/skills/scout/SKILL.md +88 -0
- package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
- package/dist/console/assets/index-B-D0EM3j.js +0 -733
- package/dist/console/assets/index-DlQepP2J.css +0 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Capture only a managed project's settled durable Workspace. Source authority/configuration never comes from the
|
|
2
|
+
// task's files. The lifecycle holds its strict drain across this entire read and publishes under its claim/CAS.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { secretsIn } from "../secret-cut.js";
|
|
5
|
+
import { secretShapes } from "../learn/secrets.js";
|
|
6
|
+
import { sourceSnapshotDigest } from "../native/source-snapshot-types.js";
|
|
7
|
+
import { relativeSegments } from "../workspace/paths.js";
|
|
8
|
+
import { SnapshotError, validateSourceSnapshot } from "./snapshots.js";
|
|
9
|
+
import { ProjectCaptureRefusal, recheckCapture } from "./capture-refusal.js";
|
|
10
|
+
const MAX = { files: 10_000, bytes: 64 * 1024 * 1024, fileBytes: 8 * 1024 * 1024, gitBytes: 32 * 1024 * 1024, manifestBytes: 4 * 1024 * 1024 };
|
|
11
|
+
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
12
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
13
|
+
const contains = (parent, path) => path === parent || path.startsWith(`${parent}/`);
|
|
14
|
+
/** This validator is synchronous and inspects only supplied bytes; no backend operation can be hidden by its refusal. */
|
|
15
|
+
function validateCapture(snapshot, limits) {
|
|
16
|
+
try {
|
|
17
|
+
validateSourceSnapshot(snapshot, limits);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof SnapshotError)
|
|
21
|
+
throw new ProjectCaptureRefusal(error.code, error.message);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function portable(path, root = false) {
|
|
26
|
+
if (typeof path !== "string" || /[\x00-\x1f\x7f]/.test(path) || Buffer.byteLength(path) > 4096 || !root && path === "")
|
|
27
|
+
throw new ProjectCaptureRefusal("prerequisite", "The project contains an unsupported path.");
|
|
28
|
+
try {
|
|
29
|
+
relativeSegments(path);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new ProjectCaptureRefusal("prerequisite", "The project contains a path outside its root.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const excluded = (path, exclusions) => exclusions.some(item => item.recursive ? contains(item.path, path) : item.path === path);
|
|
36
|
+
const credentialPath = (path) => path.split("/").some(part => /^(?:\.env(?:\..*)?|auth\.json|credentials(?:\.json)?|\.credentials\.json|\.claude\.json|id_(?:rsa|ed25519)|\.netrc|\.npmrc|\.pypirc|\.ssh|\.aws|\.gnupg)$/i.test(part)) || /\.(?:pem|p12|pfx|key)$/i.test(path);
|
|
37
|
+
/** Workspace.stat intentionally carries no modes, and Archil's file API cannot identify links. A bounded trusted
|
|
38
|
+
* metadata command checks the real destination filesystem instead. Failure or truncation is a prerequisite, never
|
|
39
|
+
* invented 0644/0755 metadata. It executes no project program and never traverses a link or Git control tree. */
|
|
40
|
+
async function inventory(work, exclusions, limits, signal, select) {
|
|
41
|
+
const format = String.raw `%y\0%m\0%s\0%p\0`;
|
|
42
|
+
const prune = [".git", ...exclusions.map(item => item.path)];
|
|
43
|
+
const entries = [], pending = [""];
|
|
44
|
+
while (pending.length) {
|
|
45
|
+
const directory = pending.shift();
|
|
46
|
+
const args = ["find", directory ? `./${directory}` : ".", ...(select ? ["-maxdepth", "1", ...(directory ? ["-mindepth", "1"] : [])] : []), "(", ...prune.flatMap((path, index) => [...(index ? ["-o"] : []), "-path", `./${path.replace(/[\\*?\[\]]/g, "\\$&")}`]), ")", "-prune", "-printf", format, "-o", "-printf", format];
|
|
47
|
+
const result = await work.exec(args, { env: { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" }, timeoutMs: 30_000, maxOutput: limits.manifestBytes, ...(signal ? { signal } : {}) });
|
|
48
|
+
signal?.throwIfAborted();
|
|
49
|
+
if (result.code !== 0 || result.signal || result.timedOut || result.truncated)
|
|
50
|
+
throw new SnapshotError("prerequisite", "The destination could not read a complete project inventory with file modes.");
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(result.stdout);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new ProjectCaptureRefusal("prerequisite", "The project contains a filename that is not portable UTF-8.");
|
|
57
|
+
}
|
|
58
|
+
const columns = text.split("\0");
|
|
59
|
+
if (columns.pop() !== "" || columns.length % 4 !== 0)
|
|
60
|
+
throw new ProjectCaptureRefusal("prerequisite", "The destination returned incomplete filesystem metadata.");
|
|
61
|
+
const candidates = [];
|
|
62
|
+
for (let at = 0; at < columns.length; at += 4) {
|
|
63
|
+
const [kind, rawMode, rawBytes, rawPath] = columns.slice(at, at + 4);
|
|
64
|
+
const path = rawPath === "." ? "" : rawPath.startsWith("./") ? rawPath.slice(2) : rawPath;
|
|
65
|
+
portable(path, true);
|
|
66
|
+
if (excluded(path, exclusions)) {
|
|
67
|
+
if (kind === "d" && exclusions.some(item => item.path === path && !item.recursive))
|
|
68
|
+
throw new SnapshotError("conflict", "A host-owned input file became a directory; its children were preserved.");
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!/^[0-7]{1,4}$/.test(rawMode) || !/^\d+$/.test(rawBytes) || !Number.isSafeInteger(Number(rawBytes))) {
|
|
72
|
+
throw new ProjectCaptureRefusal("prerequisite", "Links, special files or privileged modes require an explicit project representation.");
|
|
73
|
+
}
|
|
74
|
+
candidates.push({ path, type: kind === "d" ? "directory" : kind === "f" ? "file" : "unsupported", mode: parseInt(rawMode, 8), bytes: kind === "d" ? 0 : Number(rawBytes) });
|
|
75
|
+
}
|
|
76
|
+
const selected = select ? await select(candidates) : undefined;
|
|
77
|
+
for (const entry of candidates) {
|
|
78
|
+
if (selected && !selected.has(entry.path))
|
|
79
|
+
continue;
|
|
80
|
+
if (entry.path !== ".git" && entry.path.split("/").includes(".git"))
|
|
81
|
+
throw new ProjectCaptureRefusal("prerequisite", "Nested Git repositories need their own complete project representation.");
|
|
82
|
+
if (entry.type === "unsupported" || entry.mode > 0o777)
|
|
83
|
+
throw new ProjectCaptureRefusal("prerequisite", "Links, special files or privileged modes require an explicit project representation.");
|
|
84
|
+
entries.push({ ...entry, type: entry.type });
|
|
85
|
+
if (entries.length > limits.files)
|
|
86
|
+
throw new ProjectCaptureRefusal("limit", "The complete project inventory exceeds its file limit.");
|
|
87
|
+
if (select && entry.path && entry.path !== ".git" && entry.type === "directory")
|
|
88
|
+
pending.push(entry.path);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return entries.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
92
|
+
}
|
|
93
|
+
function sourcePath(snapshot, entry) {
|
|
94
|
+
if (entry.role === "project")
|
|
95
|
+
return entry.path === "project" ? "" : entry.path.slice("project/".length);
|
|
96
|
+
if (entry.role === "skill") {
|
|
97
|
+
const skill = snapshot.skills.find(skill => contains(skill.path, entry.path));
|
|
98
|
+
if (skill)
|
|
99
|
+
return `.agents/skills/${skill.name}${entry.path.slice(skill.path.length)}`;
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
/** A complete immutable successor, or a refusal. Original source instructions, tool policy and skill identities
|
|
104
|
+
* remain configuration; current project and authored-skill bytes/modes become the separately pinned project. */
|
|
105
|
+
export async function captureProject(options) {
|
|
106
|
+
const { workspace: work, baseline, signal } = options;
|
|
107
|
+
signal?.throwIfAborted();
|
|
108
|
+
validateCapture(baseline, options.limits);
|
|
109
|
+
if (!baseline.complete)
|
|
110
|
+
throw new ProjectCaptureRefusal("incomplete", "A project checkpoint needs its complete baseline.");
|
|
111
|
+
for (const item of options.exclude) {
|
|
112
|
+
portable(item.path);
|
|
113
|
+
if (contains(".git", item.path) || item.path === ".agents" || contains(".agents/skills", item.path))
|
|
114
|
+
throw new SnapshotError("conflict", "Project metadata and authored skills cannot be declared host scratch.");
|
|
115
|
+
}
|
|
116
|
+
for (const entry of baseline.entries) {
|
|
117
|
+
const path = sourcePath(baseline, entry);
|
|
118
|
+
if (path !== undefined && excluded(path, options.exclude))
|
|
119
|
+
throw new SnapshotError("conflict", "A host-owned exclusion collides with original project content.");
|
|
120
|
+
}
|
|
121
|
+
const cap = { ...MAX, ...options.limits };
|
|
122
|
+
const probe = await inventory(work, options.exclude, cap, signal, async (rows) => new Set(rows.filter(row => row.path === "" || row.path === ".git").map(row => row.path)));
|
|
123
|
+
const gitEntry = probe.find(entry => entry.path === ".git");
|
|
124
|
+
// Imported skills and explicit owner-authored skill files remain required even when Git ignores .agents/.
|
|
125
|
+
// Named skills keep their whole asset directory; standalone owned companions keep only their exact paths.
|
|
126
|
+
const ownedSkillFiles = baseline.entries.filter(entry => entry.role === "project" && entry.type === "file" && entry.path.startsWith("project/.agents/skills/"))
|
|
127
|
+
.map(entry => entry.path.slice("project/".length));
|
|
128
|
+
const retainedSkills = [...new Set([...baseline.skills.map(skill => `.agents/skills/${skill.name}`), ...ownedSkillFiles,
|
|
129
|
+
...ownedSkillFiles.filter(path => path.endsWith("/SKILL.md") && path !== ".agents/skills/SKILL.md").map(path => path.slice(0, -9))])];
|
|
130
|
+
let git;
|
|
131
|
+
if (gitEntry || baseline.project.git) {
|
|
132
|
+
if (gitEntry?.type !== "directory" || !options.git)
|
|
133
|
+
throw new ProjectCaptureRefusal("prerequisite", "Git project capture requires a complete safe isolated Git metadata capability.");
|
|
134
|
+
git = await options.git(work, { inventory: select => inventory(work, options.exclude, cap, signal, select), retain: retainedSkills, exclude: options.exclude, limits: cap, ...(signal ? { signal } : {}), ...(options.secretValues ? { secretValues: options.secretValues } : {}) });
|
|
135
|
+
for (const path of git.files)
|
|
136
|
+
portable(path);
|
|
137
|
+
if (git.bundle.length > cap.gitBytes)
|
|
138
|
+
throw new ProjectCaptureRefusal("limit", "Git history exceeds the project checkpoint limit.");
|
|
139
|
+
}
|
|
140
|
+
const before = git?.inventory ?? await inventory(work, options.exclude, cap, signal);
|
|
141
|
+
const selected = (entry) => entry.path !== ".git" && (!git || entry.path === "" || git.files.some(path => entry.path === path || entry.type === "directory" && contains(entry.path, path))
|
|
142
|
+
|| retainedSkills.some(path => contains(path, entry.path) || entry.type === "directory" && contains(entry.path, path)));
|
|
143
|
+
const entries = baseline.entries.filter(entry => entry.role === "instruction").map(entry => ({ ...entry }));
|
|
144
|
+
const blobs = Object.create(null), observed = new Map();
|
|
145
|
+
let expanded = 0;
|
|
146
|
+
const keep = (bytes) => { const sha = hash(bytes); blobs[sha] = Buffer.from(bytes).toString("base64"); return sha; };
|
|
147
|
+
for (const entry of entries)
|
|
148
|
+
if (entry.type === "file") {
|
|
149
|
+
blobs[entry.sha256] = baseline.blobs[entry.sha256];
|
|
150
|
+
expanded += entry.bytes;
|
|
151
|
+
}
|
|
152
|
+
for (const entry of before.filter(selected)) {
|
|
153
|
+
signal?.throwIfAborted();
|
|
154
|
+
if (credentialPath(entry.path) || options.secretValues?.some(value => value && entry.path.includes(value)))
|
|
155
|
+
throw new ProjectCaptureRefusal("prerequisite", "Credential-bearing project paths must remain outside the durable source checkpoint.");
|
|
156
|
+
if (entry.bytes > cap.fileBytes || expanded + entry.bytes > cap.bytes)
|
|
157
|
+
throw new ProjectCaptureRefusal("limit", "The project checkpoint exceeds its byte limits.");
|
|
158
|
+
const skill = baseline.skills.find(skill => contains(`.agents/skills/${skill.name}`, entry.path));
|
|
159
|
+
const path = skill ? `${skill.path}${entry.path.slice(`.agents/skills/${skill.name}`.length)}` : `project${entry.path ? `/${entry.path}` : ""}`;
|
|
160
|
+
const target = { path, role: skill ? "skill" : "project", type: entry.type, mode: entry.mode, bytes: entry.bytes };
|
|
161
|
+
if (entry.type === "file") {
|
|
162
|
+
const body = await work.read(entry.path, { length: entry.bytes + 1 });
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
if (body.length !== entry.bytes)
|
|
165
|
+
throw new SnapshotError("conflict", "Project bytes changed while the checkpoint was read.");
|
|
166
|
+
const text = Buffer.from(body).toString("utf8");
|
|
167
|
+
if (options.secretValues?.some(value => value && (text.includes(value) || entry.path.includes(value) || text.includes(JSON.stringify(value).slice(1, -1)))) || secretShapes(text).length || (await secretsIn(text)).length) {
|
|
168
|
+
throw new ProjectCaptureRefusal("prerequisite", "Credential-bearing content was withheld from the project checkpoint.");
|
|
169
|
+
}
|
|
170
|
+
target.sha256 = keep(body);
|
|
171
|
+
observed.set(entry.path, target.sha256);
|
|
172
|
+
expanded += body.length;
|
|
173
|
+
}
|
|
174
|
+
entries.push(target);
|
|
175
|
+
}
|
|
176
|
+
for (const skill of baseline.skills)
|
|
177
|
+
if (!entries.some(entry => entry.path === `${skill.path}/SKILL.md` && entry.type === "file"))
|
|
178
|
+
throw new ProjectCaptureRefusal("incomplete", "A required authored skill is missing from the current project.");
|
|
179
|
+
if (!git && !same(before, await recheckCapture(() => inventory(work, options.exclude, cap, signal))))
|
|
180
|
+
throw new SnapshotError("conflict", "Project metadata changed during checkpoint capture.");
|
|
181
|
+
// Backend mount inode/timestamp identities can change between execs. Verify actual bytes instead of treating a
|
|
182
|
+
// fresh mount's inode as a source mutation, or trusting unchanged sizes as proof of unchanged content.
|
|
183
|
+
for (const entry of before.filter(entry => entry.type === "file" && selected(entry))) {
|
|
184
|
+
signal?.throwIfAborted();
|
|
185
|
+
const body = await work.read(entry.path, { length: entry.bytes + 1 });
|
|
186
|
+
if (body.length !== entry.bytes || hash(body) !== observed.get(entry.path))
|
|
187
|
+
throw new SnapshotError("conflict", "Project bytes changed during checkpoint capture.");
|
|
188
|
+
}
|
|
189
|
+
if (git?.verify)
|
|
190
|
+
await recheckCapture(git.verify);
|
|
191
|
+
const project = git ? { git: { ...git.metadata, bundle: { sha256: keep(git.bundle), bytes: git.bundle.length } } } : { git: null };
|
|
192
|
+
// Project rewrites have already been applied before dispatch. Their original-source receipts remain in the
|
|
193
|
+
// separately pinned source snapshot; replaying that transform over current managed bytes would be incorrect.
|
|
194
|
+
// External instruction assets were never materialized, so retain their verifiable provenance while its exact
|
|
195
|
+
// installer receipt still exists. No transformation is inferred from task-authored replacement content.
|
|
196
|
+
const transforms = baseline.transforms?.filter(transform => transform.path.startsWith("instructions/")
|
|
197
|
+
&& entries.some(entry => entry.path === transform.receipt.path && entry.sha256 === transform.receipt.sha256));
|
|
198
|
+
for (const transform of transforms ?? [])
|
|
199
|
+
blobs[transform.destination_sha256] = baseline.blobs[transform.destination_sha256];
|
|
200
|
+
const { transforms: _transforms, ...original } = baseline;
|
|
201
|
+
const value = { ...original, entries, blobs, project, ...(transforms?.length ? { transforms } : {}), complete: true, blockers: [] };
|
|
202
|
+
const result = { ...value, digest: sourceSnapshotDigest(value) };
|
|
203
|
+
signal?.throwIfAborted();
|
|
204
|
+
validateCapture(result, options.limits);
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SnapshotError } from "./snapshots.js";
|
|
2
|
+
/** A stable policy/data refusal after completed reads or commands, never an execution failure, cancellation or
|
|
3
|
+
* observed mutation. This alone does not settle ownership: the caller must still finish every owned cleanup. */
|
|
4
|
+
export declare class ProjectCaptureRefusal extends SnapshotError {
|
|
5
|
+
}
|
|
6
|
+
/** A previously valid inventory becoming invalid is an observed change, not a stable policy refusal. */
|
|
7
|
+
export declare function recheckCapture<T>(read: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SnapshotError } from "./snapshots.js";
|
|
2
|
+
/** A stable policy/data refusal after completed reads or commands, never an execution failure, cancellation or
|
|
3
|
+
* observed mutation. This alone does not settle ownership: the caller must still finish every owned cleanup. */
|
|
4
|
+
export class ProjectCaptureRefusal extends SnapshotError {
|
|
5
|
+
}
|
|
6
|
+
/** A previously valid inventory becoming invalid is an observed change, not a stable policy refusal. */
|
|
7
|
+
export async function recheckCapture(read) {
|
|
8
|
+
try {
|
|
9
|
+
return await read();
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error instanceof ProjectCaptureRefusal)
|
|
13
|
+
throw new SnapshotError("conflict", "Project metadata changed during checkpoint verification.");
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Move changes execution, not the source's evidence identity. Only this retained, enrolled revision may receive
|
|
2
|
+
* source prompt windows; it never adopts the managed revision's tools, permissions or workflow execution. */
|
|
3
|
+
import type { AgentEntry } from "../agents-store.js";
|
|
4
|
+
import { type CliLearningBinding } from "../store/agent-body.js";
|
|
5
|
+
import type { RevisionRow, Store } from "../store/store.js";
|
|
6
|
+
import { type SourceRecord } from "./registry.js";
|
|
7
|
+
export declare function cliCaptureOf(store: Pick<Store, "agents" | "settings">, entry: AgentEntry): Promise<{
|
|
8
|
+
revision: RevisionRow;
|
|
9
|
+
binding: CliLearningBinding;
|
|
10
|
+
source?: SourceRecord;
|
|
11
|
+
} | undefined>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cliLearningOf } from "../store/agent-body.js";
|
|
2
|
+
import { sourceKey } from "./registry.js";
|
|
3
|
+
import { sourceSyncOf } from "./types.js";
|
|
4
|
+
export async function cliCaptureOf(store, entry) {
|
|
5
|
+
if (!entry.revision)
|
|
6
|
+
return undefined;
|
|
7
|
+
const own = cliLearningOf(entry.revision.body);
|
|
8
|
+
if (own)
|
|
9
|
+
return { revision: entry.revision, binding: own };
|
|
10
|
+
const moved = sourceSyncOf(entry.revision.body);
|
|
11
|
+
if (!moved)
|
|
12
|
+
return undefined;
|
|
13
|
+
const source = await store.settings.get(sourceKey(entry.agent.id));
|
|
14
|
+
if (!source || source.id !== moved.id || source.agent_id !== entry.agent.id)
|
|
15
|
+
return undefined;
|
|
16
|
+
const revision = await store.agents.revision(source.capture_revision);
|
|
17
|
+
const binding = cliLearningOf(revision?.body);
|
|
18
|
+
if (!revision || revision.agentId !== entry.agent.id || !binding || binding.runtime !== source.source.runtime
|
|
19
|
+
|| binding.project !== source.source.project || source.source.selector.kind !== "project")
|
|
20
|
+
return undefined;
|
|
21
|
+
return { revision, binding, source };
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Store } from "../store/store.js";
|
|
2
|
+
import { projectCheckpointStatuses } from "./checkpoints.js";
|
|
3
|
+
export declare const checkpointAckPrefix: (agentId: string) => string;
|
|
4
|
+
type Reader = typeof projectCheckpointStatuses;
|
|
5
|
+
export type ProjectReceipt = {
|
|
6
|
+
run_id: string;
|
|
7
|
+
entry_id: number;
|
|
8
|
+
attempt_epoch?: never;
|
|
9
|
+
} | {
|
|
10
|
+
run_id: string;
|
|
11
|
+
entry_id: null;
|
|
12
|
+
attempt_epoch: number;
|
|
13
|
+
};
|
|
14
|
+
export type ProjectIssue = ProjectReceipt & {
|
|
15
|
+
status: "pending" | "conflict" | "uncertain";
|
|
16
|
+
reason?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function unresolvedProjects(store: Store, agentId: string, read?: Reader): Promise<ProjectIssue[]>;
|
|
19
|
+
export declare function acknowledgeProjects(store: Store, agentId: string, receipts: unknown, read?: Reader): Promise<void>;
|
|
20
|
+
export declare function requireSavedProject(store: Store, agentId: string): Promise<void>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** An owner acknowledges specific unresolved run receipts, never every past/future failure. Candidate bytes and
|
|
2
|
+
* receipts remain available for inspection; this choice only permits later runs to use the current saved project. */
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { ApiError } from "../errors.js";
|
|
5
|
+
import { canonical } from "../store/agent-body.js";
|
|
6
|
+
import { projectCheckpointStatuses } from "./checkpoints.js";
|
|
7
|
+
export const checkpointAckPrefix = (agentId) => `source-sync.checkpoint.${agentId}.`;
|
|
8
|
+
const key = (agentId, runId) => checkpointAckPrefix(agentId) + createHash("sha256").update(runId).digest("hex");
|
|
9
|
+
const identity = (row) => canonical([row.run_id, row.entry_id, row.attempt_epoch ?? null]);
|
|
10
|
+
export async function unresolvedProjects(store, agentId, read = projectCheckpointStatuses) {
|
|
11
|
+
const latest = new Map();
|
|
12
|
+
for (const row of await read(store, agentId)) {
|
|
13
|
+
const before = latest.get(row.runId);
|
|
14
|
+
// The projection emits a missing-end row only for the latest terminal claim, after every earlier real end.
|
|
15
|
+
if (!before || row.entryId === null || before.entryId !== null && before.entryId < row.entryId)
|
|
16
|
+
latest.set(row.runId, row);
|
|
17
|
+
}
|
|
18
|
+
const unresolved = [];
|
|
19
|
+
for (const row of latest.values()) {
|
|
20
|
+
if (row.status === "published")
|
|
21
|
+
continue;
|
|
22
|
+
if (row.entryId === null && (!Number.isSafeInteger(row.attemptEpoch) || row.attemptEpoch < 1))
|
|
23
|
+
throw new Error("The missing project checkpoint has no claim identity.");
|
|
24
|
+
const receipt = row.entryId === null ? { run_id: row.runId, entry_id: null, attempt_epoch: row.attemptEpoch } : { run_id: row.runId, entry_id: row.entryId };
|
|
25
|
+
const issue = { ...receipt, status: row.status, ...(row.reason ? { reason: row.reason } : {}) };
|
|
26
|
+
if (canonical(await store.settings.get(key(agentId, row.runId)) ?? null) !== canonical(issue))
|
|
27
|
+
unresolved.push(issue);
|
|
28
|
+
}
|
|
29
|
+
return unresolved.sort((a, b) => a.run_id.localeCompare(b.run_id));
|
|
30
|
+
}
|
|
31
|
+
export async function acknowledgeProjects(store, agentId, receipts, read = projectCheckpointStatuses) {
|
|
32
|
+
if (!Array.isArray(receipts) || !receipts.length || receipts.length > 1000 || receipts.some(row => !row || typeof row !== "object"
|
|
33
|
+
|| Object.keys(row).some(name => !["run_id", "entry_id", "attempt_epoch"].includes(name)) || typeof row.run_id !== "string"
|
|
34
|
+
|| (row.entry_id === null ? !Number.isSafeInteger(row.attempt_epoch) || row.attempt_epoch < 1
|
|
35
|
+
: !Number.isSafeInteger(row.entry_id) || row.entry_id < 1 || row.attempt_epoch !== undefined))) {
|
|
36
|
+
throw new ApiError("input_invalid", "Choose the unresolved run receipts you reviewed.");
|
|
37
|
+
}
|
|
38
|
+
const wanted = new Set(receipts.map(identity));
|
|
39
|
+
if (wanted.size !== receipts.length)
|
|
40
|
+
throw new ApiError("input_invalid", "Choose each run receipt once.");
|
|
41
|
+
const issues = await unresolvedProjects(store, agentId, read);
|
|
42
|
+
const selected = issues.filter(row => wanted.has(identity(row)));
|
|
43
|
+
if (selected.length !== wanted.size || selected.some(row => row.status === "pending"))
|
|
44
|
+
throw new ApiError("precondition_failed", "The project receipts changed. Refresh and review them before continuing.");
|
|
45
|
+
for (const issue of selected)
|
|
46
|
+
await store.settings.put(key(agentId, issue.run_id), issue);
|
|
47
|
+
}
|
|
48
|
+
export async function requireSavedProject(store, agentId) {
|
|
49
|
+
const issues = await unresolvedProjects(store, agentId);
|
|
50
|
+
if (issues.length)
|
|
51
|
+
throw new ApiError("agent_not_runnable", "A prior run's project changes were not saved as the current project. Review its receipts on the agent page before starting another run.", { details: { project_issues: issues } });
|
|
52
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Store } from "../store/store.js";
|
|
2
|
+
export interface ProjectCandidate {
|
|
3
|
+
readonly version: 1;
|
|
4
|
+
readonly status: "candidate";
|
|
5
|
+
readonly sourceId: string;
|
|
6
|
+
readonly runId: string;
|
|
7
|
+
readonly epoch: number;
|
|
8
|
+
readonly baselineRevision: string;
|
|
9
|
+
readonly baselineDigest: string;
|
|
10
|
+
readonly revision: string;
|
|
11
|
+
readonly digest: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ProjectUncertain {
|
|
14
|
+
readonly version: 1;
|
|
15
|
+
readonly status: "uncertain";
|
|
16
|
+
readonly sourceId: string;
|
|
17
|
+
readonly runId: string;
|
|
18
|
+
readonly epoch: number;
|
|
19
|
+
readonly reason: "project_not_settled" | "project_capture_failed" | "project_baseline_invalid";
|
|
20
|
+
/** Fixed internal diagnostic only; never exception text, source paths or credential values. */
|
|
21
|
+
readonly stage?: "drain" | "settle" | "sync" | "baseline" | "read" | "open" | "capture" | "commit" | "cleanup";
|
|
22
|
+
}
|
|
23
|
+
/** Auxiliary learning retains its result and evidence, but never applies its private project edits to the agent. */
|
|
24
|
+
export interface ProjectDiscarded {
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
readonly status: "discarded";
|
|
27
|
+
readonly sourceId: string;
|
|
28
|
+
readonly runId: string;
|
|
29
|
+
readonly epoch: number;
|
|
30
|
+
readonly reason: "auxiliary_project_changes_not_applied";
|
|
31
|
+
}
|
|
32
|
+
export type ProjectCheckpoint = ProjectCandidate | ProjectUncertain | ProjectDiscarded;
|
|
33
|
+
export interface ProjectCheckpointStatus {
|
|
34
|
+
readonly runId: string;
|
|
35
|
+
readonly entryId: number | null;
|
|
36
|
+
readonly status: "published" | "pending" | "conflict" | "uncertain";
|
|
37
|
+
/** A terminal claim with no journal end has no entry ID. Its actual claim epoch pins the owner's review. */
|
|
38
|
+
readonly attemptEpoch?: number;
|
|
39
|
+
readonly revision?: string;
|
|
40
|
+
readonly digest?: string;
|
|
41
|
+
readonly reason?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function projectCandidate(input: Omit<ProjectCandidate, "version" | "status" | "revision">): ProjectCandidate;
|
|
44
|
+
/** Returns the immutable chain a run itself wrote, rooted at its admission pin. Later owner/source edits are never
|
|
45
|
+
* adopted as that run's baseline. A conflicting predecessor remains a conflict for all its descendants. */
|
|
46
|
+
export declare function projectBaseline(store: Store, runId: string): Promise<{
|
|
47
|
+
sourceId: string;
|
|
48
|
+
revision: string;
|
|
49
|
+
digest: string;
|
|
50
|
+
epoch: number;
|
|
51
|
+
} | undefined>;
|
|
52
|
+
/** Reports committed receipts without moving a revision or writing any state. A pending candidate can still lose
|
|
53
|
+
* its baseline before an explicit reconciliation. Callers choose the latest entry per run for an owner decision. */
|
|
54
|
+
export declare function projectCheckpointStatuses(store: Store, agentId: string): Promise<ProjectCheckpointStatus[]>;
|
|
55
|
+
export declare function reconcileProjectCheckpoints(store: Store, agentId: string, options?: {
|
|
56
|
+
runId?: string;
|
|
57
|
+
}): Promise<ProjectCheckpointStatus[]>;
|
|
58
|
+
/** Compose after ordinary resource cleanup. If the process dies before this callback, pre-start reconciliation
|
|
59
|
+
* reads the same committed candidate; neither path repeats capture or a model/tool action. */
|
|
60
|
+
export declare function projectRunEnded(store: Store, next?: (claim: {
|
|
61
|
+
readonly runId: string;
|
|
62
|
+
readonly epoch: number;
|
|
63
|
+
}) => Promise<void>): (claim: {
|
|
64
|
+
readonly runId: string;
|
|
65
|
+
readonly epoch: number;
|
|
66
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/** Project publication is a separate CAS after the run's committed terminal receipt. A failed or lost publication
|
|
2
|
+
* never reruns a model/tool or rewrites the project's baseline; a later explicit reconciliation retries the same immutable candidate. */
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { readLaunchBody } from "../run-launch.js";
|
|
5
|
+
import { canonical } from "../store/agent-body.js";
|
|
6
|
+
import { AgentArchived, AgentDeleting, AgentPurged, RevisionMoved } from "../store/store.js";
|
|
7
|
+
import { sourceSyncOf } from "./types.js";
|
|
8
|
+
const hex = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
9
|
+
const id = (value) => typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(value);
|
|
10
|
+
export function projectCandidate(input) {
|
|
11
|
+
const revision = `project-${createHash("sha256").update(canonical(input)).digest("hex")}`;
|
|
12
|
+
return { version: 1, status: "candidate", ...input, revision };
|
|
13
|
+
}
|
|
14
|
+
function candidateOf(value) {
|
|
15
|
+
if (!value || typeof value !== "object")
|
|
16
|
+
return;
|
|
17
|
+
const row = value;
|
|
18
|
+
if (row.version !== 1 || row.status !== "candidate" || !hex(row.sourceId) || !hex(row.baselineDigest) || !hex(row.digest)
|
|
19
|
+
|| !id(row.runId) || !id(row.baselineRevision) || !Number.isSafeInteger(row.epoch) || row.epoch < 1)
|
|
20
|
+
return;
|
|
21
|
+
const { sourceId, runId, epoch, baselineRevision, baselineDigest, digest } = row;
|
|
22
|
+
return projectCandidate({ sourceId, runId, epoch, baselineRevision, baselineDigest, digest }).revision === row.revision ? row : undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Returns the immutable chain a run itself wrote, rooted at its admission pin. Later owner/source edits are never
|
|
25
|
+
* adopted as that run's baseline. A conflicting predecessor remains a conflict for all its descendants. */
|
|
26
|
+
export async function projectBaseline(store, runId) {
|
|
27
|
+
const run = await store.runs.get(runId), launch = readLaunchBody((await store.runs.launch(runId))?.body);
|
|
28
|
+
const placed = launch?.sourceProject;
|
|
29
|
+
if (!run || !placed || placed.baselineRevision !== run.revisionId || launch?.audit || launch?.replay)
|
|
30
|
+
return;
|
|
31
|
+
const initial = await store.agents.revision(run.revisionId), binding = sourceSyncOf(initial?.body);
|
|
32
|
+
if (!initial || initial.agentId !== run.agentId || binding?.id !== placed.sourceId || binding.project !== placed.digest)
|
|
33
|
+
return;
|
|
34
|
+
let baseline = { sourceId: placed.sourceId, revision: placed.baselineRevision, digest: placed.digest, epoch: 0 };
|
|
35
|
+
for (const row of await store.runs.projectCheckpoints({ agentId: run.agentId, runId })) {
|
|
36
|
+
const candidate = candidateOf(row.checkpoint);
|
|
37
|
+
if (candidate && candidate.runId === runId && candidate.sourceId === baseline.sourceId && candidate.epoch === row.attemptEpoch && candidate.epoch > baseline.epoch && candidate.epoch <= run.epoch
|
|
38
|
+
&& candidate.baselineRevision === baseline.revision && candidate.baselineDigest === baseline.digest)
|
|
39
|
+
baseline = { sourceId: baseline.sourceId, revision: candidate.revision, digest: candidate.digest, epoch: candidate.epoch };
|
|
40
|
+
}
|
|
41
|
+
return baseline;
|
|
42
|
+
}
|
|
43
|
+
/** Reports committed receipts without moving a revision or writing any state. A pending candidate can still lose
|
|
44
|
+
* its baseline before an explicit reconciliation. Callers choose the latest entry per run for an owner decision. */
|
|
45
|
+
export function projectCheckpointStatuses(store, agentId) {
|
|
46
|
+
return processCheckpoints(store, agentId, {}, false);
|
|
47
|
+
}
|
|
48
|
+
export function reconcileProjectCheckpoints(store, agentId, options = {}) {
|
|
49
|
+
return processCheckpoints(store, agentId, options, true);
|
|
50
|
+
}
|
|
51
|
+
async function processCheckpoints(store, agentId, options, publish) {
|
|
52
|
+
const rows = await store.runs.projectCheckpoints({ agentId, ...options }), results = [];
|
|
53
|
+
const chains = new Map();
|
|
54
|
+
const pending = new Map();
|
|
55
|
+
for (const row of rows) {
|
|
56
|
+
const uncertain = (reason) => ({ runId: row.runId, entryId: row.entryId, ...(row.attemptEpoch === undefined ? {} : { attemptEpoch: row.attemptEpoch }), status: "uncertain", reason });
|
|
57
|
+
const candidate = candidateOf(row.checkpoint), run = await store.runs.get(row.runId);
|
|
58
|
+
if (!run || run.agentId !== agentId || run.revisionId !== row.revisionId) {
|
|
59
|
+
results.push(uncertain("project_not_settled"));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const launch = readLaunchBody((await store.runs.launch(row.runId))?.body);
|
|
63
|
+
if (row.entryId === null) {
|
|
64
|
+
// Absence is durable failure evidence, never a reconstructed candidate or permission to discard writes.
|
|
65
|
+
const placed = launch?.sourceProject, binding = sourceSyncOf((await store.agents.revision(row.revisionId))?.body);
|
|
66
|
+
results.push(uncertain(placed && binding?.id === placed.sourceId && binding.project === placed.digest && placed.baselineRevision === row.revisionId
|
|
67
|
+
? "project_not_settled" : "project_baseline_invalid"));
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (launch?.audit || launch?.replay) {
|
|
71
|
+
const receipt = row.checkpoint, placed = launch.sourceProject;
|
|
72
|
+
const binding = sourceSyncOf((await store.agents.revision(row.revisionId))?.body);
|
|
73
|
+
// This is an authorization boundary, not merely a candidate-shape check. Even a forged, otherwise valid
|
|
74
|
+
// candidate from a learning run must never become the agent's next project revision.
|
|
75
|
+
if (placed && binding?.id === placed.sourceId && binding.project === placed.digest && placed.baselineRevision === row.revisionId
|
|
76
|
+
&& receipt?.version === 1 && receipt.status === "discarded" && receipt.runId === row.runId && receipt.sourceId === placed.sourceId
|
|
77
|
+
&& Number.isSafeInteger(receipt.epoch) && receipt.epoch >= 1 && receipt.epoch === row.attemptEpoch && receipt.epoch <= run.epoch && receipt.reason === "auxiliary_project_changes_not_applied") {
|
|
78
|
+
// A later settled auxiliary attempt supersedes that run's earlier failed saves without publishing files.
|
|
79
|
+
// Independent source-write receipts remain untouched, even when this run's project issue is resolved.
|
|
80
|
+
for (let index = results.length - 1; index >= 0; index--)
|
|
81
|
+
if (results[index].runId === row.runId)
|
|
82
|
+
results.splice(index, 1);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
results.push(uncertain("auxiliary_project_changes_not_applied"));
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
let chain = chains.get(row.runId);
|
|
89
|
+
if (!chain) {
|
|
90
|
+
const placed = launch?.sourceProject;
|
|
91
|
+
const initial = await store.agents.revision(row.revisionId), binding = sourceSyncOf(initial?.body);
|
|
92
|
+
if (!placed || placed.baselineRevision !== row.revisionId || binding?.id !== placed.sourceId || binding.project !== placed.digest) {
|
|
93
|
+
results.push(uncertain("project_baseline_invalid"));
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
chain = { sourceId: placed.sourceId, revision: placed.baselineRevision, digest: placed.digest, epoch: 0 };
|
|
97
|
+
}
|
|
98
|
+
if (!candidate) {
|
|
99
|
+
const receipt = row.checkpoint;
|
|
100
|
+
const reason = receipt?.version === 1 && receipt.status === "uncertain" && receipt.runId === row.runId && receipt.sourceId === chain.sourceId
|
|
101
|
+
&& Number.isSafeInteger(receipt.epoch) && receipt.epoch >= 1 && receipt.epoch === row.attemptEpoch && receipt.epoch <= run.epoch
|
|
102
|
+
&& (receipt.reason === "project_not_settled" || receipt.reason === "project_capture_failed" || receipt.reason === "project_baseline_invalid")
|
|
103
|
+
? receipt.reason : "project_not_settled";
|
|
104
|
+
results.push(uncertain(reason));
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (candidate.runId !== row.runId || candidate.sourceId !== chain.sourceId || candidate.baselineRevision !== chain.revision
|
|
108
|
+
|| candidate.baselineDigest !== chain.digest || candidate.epoch !== row.attemptEpoch || candidate.epoch <= chain.epoch || candidate.epoch > run.epoch) {
|
|
109
|
+
results.push(uncertain("project_baseline_invalid"));
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
chains.set(row.runId, { sourceId: candidate.sourceId, revision: candidate.revision, digest: candidate.digest, epoch: candidate.epoch });
|
|
113
|
+
const status = (state) => ({ runId: row.runId, entryId: row.entryId, status: state, revision: candidate.revision, digest: candidate.digest });
|
|
114
|
+
const baseline = await store.agents.revision(candidate.baselineRevision) ?? pending.get(candidate.baselineRevision), binding = sourceSyncOf(baseline?.body);
|
|
115
|
+
if (!baseline || baseline.agentId !== agentId || binding?.id !== candidate.sourceId || binding.project !== candidate.baselineDigest) {
|
|
116
|
+
results.push(status("conflict"));
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const next = { id: candidate.revision, kind: baseline.kind, body: { ...baseline.body, sourceSync: { ...binding, project: candidate.digest } },
|
|
120
|
+
...(baseline.skills === null ? {} : { skills: baseline.skills }), ...(baseline.package ? { package: baseline.package } : {}),
|
|
121
|
+
...(baseline.mcpPin === null ? {} : { mcpPin: baseline.mcpPin }), ...(baseline.monidPin ? { monidPin: baseline.monidPin } : {}), note: "Project checkpoint from a completed run." };
|
|
122
|
+
const matches = async () => {
|
|
123
|
+
const saved = await store.agents.revision(candidate.revision);
|
|
124
|
+
return !!saved && saved.agentId === agentId && saved.parent === candidate.baselineRevision && saved.kind === next.kind
|
|
125
|
+
&& canonical(saved.body) === canonical(next.body) && canonical(saved.skills) === canonical(next.skills ?? null)
|
|
126
|
+
&& canonical(saved.package) === canonical(next.package ?? null) && canonical(saved.mcpPin) === canonical(next.mcpPin ?? null) && canonical(saved.monidPin) === canonical(next.monidPin ?? null);
|
|
127
|
+
};
|
|
128
|
+
if (await matches()) {
|
|
129
|
+
results.push(status("published"));
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (!publish) {
|
|
133
|
+
const agent = await store.agents.get(agentId);
|
|
134
|
+
if (agent && agent.archivedAt === null && agent.purgedAt === null && (agent.currentRevision === candidate.baselineRevision || pending.has(candidate.baselineRevision))) {
|
|
135
|
+
pending.set(candidate.revision, { ...baseline, id: candidate.revision, parent: candidate.baselineRevision, body: next.body });
|
|
136
|
+
results.push(status("pending"));
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
results.push(status("conflict"));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
await store.agents.addRevision({ ...next, agentId, ifCurrent: candidate.baselineRevision });
|
|
144
|
+
results.push(status("published"));
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// The response may be lost after commit, or another reconciler may have saved the same exact candidate.
|
|
148
|
+
if (await matches())
|
|
149
|
+
results.push(status("published"));
|
|
150
|
+
else if (error instanceof RevisionMoved || error instanceof AgentArchived || error instanceof AgentDeleting || error instanceof AgentPurged)
|
|
151
|
+
results.push(status("conflict"));
|
|
152
|
+
else
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return results;
|
|
157
|
+
}
|
|
158
|
+
/** Compose after ordinary resource cleanup. If the process dies before this callback, pre-start reconciliation
|
|
159
|
+
* reads the same committed candidate; neither path repeats capture or a model/tool action. */
|
|
160
|
+
export function projectRunEnded(store, next) {
|
|
161
|
+
return async (claim) => {
|
|
162
|
+
await next?.(claim);
|
|
163
|
+
const run = await store.runs.get(claim.runId);
|
|
164
|
+
if (!run || run.purgedAt !== null || !sourceSyncOf((await store.agents.revision(run.revisionId))?.body))
|
|
165
|
+
return;
|
|
166
|
+
await reconcileProjectCheckpoints(store, run.agentId, { runId: run.id });
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Claim-time moved-project checks. No seeding, no restoration of task edits, and no private control handle reaches
|
|
2
|
+
* the harness. A missing placement refuses before inputs, skills, computer allocation or model dispatch. */
|
|
3
|
+
import type { RunLaunch } from "../run-launch.js";
|
|
4
|
+
import type { RevisionRow, RunRow, Store } from "../store/store.js";
|
|
5
|
+
import type { Workspace } from "../workspace/workspace.js";
|
|
6
|
+
import { type SourceWorkspaceOptions } from "./workspace.js";
|
|
7
|
+
export declare function verifyPlacedProject(store: Store, run: RunRow, revision: RevisionRow, launch: RunLaunch, options: SourceWorkspaceOptions): Promise<boolean>;
|
|
8
|
+
/** Full authored assets already exist in the seeded workspace. Only discover their current SKILL.md files; stale
|
|
9
|
+
* revision text must never recreate a directory the task removed. The host's computer-kind guidance remains its own
|
|
10
|
+
* add-only asset, unless an authored skill selected that name. */
|
|
11
|
+
export declare function movedSkillFiles(work: Workspace, authored: Readonly<Record<string, unknown>>, computer?: string): Promise<readonly string[]>;
|