@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53
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 +160 -1
- package/README.md +306 -36
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +14 -4
- package/dist/agent-delete.js +30 -58
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +28 -18
- package/dist/agents-store.js +48 -34
- package/dist/api-only.d.ts +30 -8
- package/dist/api-only.js +40 -16
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- 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 +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -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 +9 -0
- package/dist/computer-setting.js +19 -1
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.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 +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +365 -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 +19 -1
- package/dist/learn/commit.js +160 -2
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +46 -15
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +16 -0
- package/dist/learn/folder.js +30 -4
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +29 -4
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +15 -10
- package/dist/learning.js +14 -8
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +56 -12
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +17 -12
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- 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 +211 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +29 -5
- package/dist/run-launch.js +44 -4
- 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-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +18 -1
- package/dist/run-view.js +28 -8
- package/dist/runner/adapter-loop.d.ts +14 -4
- package/dist/runner/adapter-loop.js +150 -31
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +35 -22
- package/dist/runner/audit.d.ts +10 -3
- package/dist/runner/audit.js +30 -7
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +31 -4
- package/dist/runner/claim-secrets.js +43 -7
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +32 -20
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +16 -3
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +5 -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 +9 -3
- package/dist/runner/learning-end.js +66 -29
- 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 +7 -2
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +14 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/monid-run.js +9 -11
- 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 +51 -24
- package/dist/runner/promotion.js +206 -78
- 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 +174 -42
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +41 -12
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- 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 +4 -4
- package/dist/runs-over-store.d.ts +39 -8
- package/dist/runs-over-store.js +147 -32
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +185 -78
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +678 -124
- 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 +8 -0
- package/dist/store/agent-body.js +20 -6
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +43 -4
- 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 +14 -0
- package/dist/store/sqlite/run-launch.js +58 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +319 -153
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +173 -33
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-eval.js +4 -4
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +29 -5
- package/dist/templates.js +68 -14
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.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/tools.js +1 -1
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -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 +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +4 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- 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/revision-skills.js +24 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
|
@@ -359,7 +359,8 @@ A refusal comes back as a tool error holding the server's `error`: `code`, `mess
|
|
|
359
359
|
## 4. Create an agent
|
|
360
360
|
|
|
361
361
|
Look for one first with `agents_list` and inspect the server's templates through `GET /v2/templates` or the
|
|
362
|
-
matching Node CLI's `template list
|
|
362
|
+
matching Node CLI's `template list`, then read the one you would apply whole (its instructions and every skill file)
|
|
363
|
+
with `GET /v2/templates/{id}` or `template get`. Offer a suitable template or a custom agent; ask only for missing details
|
|
363
364
|
about the job, inputs, expected result and required tools. Before applying a template, explain its tool grants
|
|
364
365
|
and triggers and confirm any permissions not already granted. Use the apply schema from this server's OpenAPI document.
|
|
365
366
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CliLearningConnections } from "../cli-learning/connections.js";
|
|
2
|
+
import type { NativeBinding } from "../native/types.js";
|
|
3
|
+
import type { SettingsGuard, Store } from "../store/store.js";
|
|
4
|
+
export type CliAdoption = {
|
|
5
|
+
connection_id: string;
|
|
6
|
+
credential_epoch: string;
|
|
7
|
+
proof: string;
|
|
8
|
+
};
|
|
9
|
+
export type VerifiedAdoption = {
|
|
10
|
+
agentId: string;
|
|
11
|
+
connectionId: string;
|
|
12
|
+
guards: readonly SettingsGuard[];
|
|
13
|
+
};
|
|
14
|
+
export type AdoptionResolver = (connectorId: string, targetId: string, target: NativeBinding, input: unknown) => Promise<VerifiedAdoption>;
|
|
15
|
+
export declare function cliAdoptionResolver(store: Store, connections: CliLearningConnections): AdoptionResolver;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** An existing source credential may prove association, never choose an arbitrary destination agent. */
|
|
2
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
3
|
+
import { getAgent } from "../agents-store.js";
|
|
4
|
+
import { ApiError } from "../errors.js";
|
|
5
|
+
import { canonical, isObject } from "../store/agent-body.js";
|
|
6
|
+
import { cliCaptureOf } from "./capture.js";
|
|
7
|
+
export function cliAdoptionResolver(store, connections) {
|
|
8
|
+
return async (connectorId, targetId, target, input) => {
|
|
9
|
+
const refuse = () => { throw new ApiError("forbidden", "The existing CLI connection did not authorize this source association. Connect on the same server from its source machine."); };
|
|
10
|
+
if (!isObject(input) || Object.keys(input).some(key => !["connection_id", "credential_epoch", "proof"].includes(key))
|
|
11
|
+
|| typeof input.connection_id !== "string" || typeof input.credential_epoch !== "string" || !/^[a-f0-9]{64}$/.test(input.credential_epoch)
|
|
12
|
+
|| typeof input.proof !== "string" || !/^[a-f0-9]{64}$/.test(input.proof))
|
|
13
|
+
return refuse();
|
|
14
|
+
const row = await connections.get(input.connection_id).catch(error => {
|
|
15
|
+
if (error instanceof ApiError && error.code === "not_found")
|
|
16
|
+
return undefined;
|
|
17
|
+
throw error;
|
|
18
|
+
});
|
|
19
|
+
if (!row?.active || row.runtime !== target.runtime || row.project !== target.project || row.native.machine_id !== target.machine_id
|
|
20
|
+
|| canonical(row.native.selector) !== canonical(target.selector) || target.selector.kind !== "project")
|
|
21
|
+
return refuse();
|
|
22
|
+
const token = connections.token(row);
|
|
23
|
+
const epoch = createHash("sha256").update(token).digest("hex");
|
|
24
|
+
const message = JSON.stringify(["agentrun-source-sync-adoption-v1", connectorId, targetId, row.connection_id, epoch,
|
|
25
|
+
target.runtime, target.machine_id, target.project, target.selector.kind, target.selector.name ?? null]);
|
|
26
|
+
const expected = createHmac("sha256", token).update(message).digest();
|
|
27
|
+
if (input.credential_epoch !== epoch || !timingSafeEqual(expected, Buffer.from(input.proof, "hex")))
|
|
28
|
+
return refuse();
|
|
29
|
+
const entry = await getAgent(store, row.agent_id);
|
|
30
|
+
const capture = entry && await cliCaptureOf(store, entry);
|
|
31
|
+
if (!entry || entry.agent.archivedAt || entry.agent.purgedAt || capture?.binding.connection_id !== row.connection_id)
|
|
32
|
+
return refuse();
|
|
33
|
+
return { agentId: row.agent_id, connectionId: row.connection_id,
|
|
34
|
+
guards: [{ key: `cli-learning-connection:${row.connection_id}`, fields: { active: true, generation: row.generation, agent_id: row.agent_id } }] };
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
2
|
+
import { type StartDeps } from "../runs-over-store.js";
|
|
3
|
+
import type { RunRow, Store } from "../store/store.js";
|
|
4
|
+
import { type SourceWorkspaceOptions } from "./workspace.js";
|
|
5
|
+
export interface AuxiliaryRun {
|
|
6
|
+
readonly agentId: string;
|
|
7
|
+
readonly runId: string;
|
|
8
|
+
readonly revisionId: string;
|
|
9
|
+
readonly launch: RunLaunch;
|
|
10
|
+
readonly sealed?: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export type AuxiliaryAdmitter = (request: AuxiliaryRun) => Promise<{
|
|
13
|
+
readonly run: RunRow;
|
|
14
|
+
readonly created: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
/** Reuses ordinary placement's rollback/lost-commit rules. The deterministic receipt remains after an uncertain
|
|
17
|
+
* preparation/admission; a retry cannot replace its writer. An existing admitted row is read before opening storage. */
|
|
18
|
+
export declare function auxiliaryAdmitter(store: Store, options: {
|
|
19
|
+
data: string;
|
|
20
|
+
project?: StartDeps["project"];
|
|
21
|
+
}): AuxiliaryAdmitter;
|
|
22
|
+
/** Runner-side counterpart of the server's StartDeps.project. Only trusted host options enter this factory. */
|
|
23
|
+
export declare function sourceAuxiliaryAdmitter(store: Store, options: SourceWorkspaceOptions): AuxiliaryAdmitter;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Host-only admission of learning work. Every auxiliary project is a fresh copy of its reserved revision, never the
|
|
2
|
+
* served run's mutable files or private placement marker. Its execution settles without publishing project changes. */
|
|
3
|
+
import { ApiError } from "../errors.js";
|
|
4
|
+
import { withAgentRepo } from "../learning.js";
|
|
5
|
+
import { resetAtOf } from "../learn/promote.js";
|
|
6
|
+
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
7
|
+
import { withHeldFiles } from "../runs-over-store.js";
|
|
8
|
+
import { canonical } from "../store/agent-body.js";
|
|
9
|
+
import { beginSourceIO } from "./io.js";
|
|
10
|
+
import { projectPlacement } from "./projects.js";
|
|
11
|
+
import { sourceSyncOf } from "./types.js";
|
|
12
|
+
import { openRunPlacement, sourceSnapshotReader } from "./workspace.js";
|
|
13
|
+
const refused = (message) => new ApiError("agent_not_runnable", message);
|
|
14
|
+
/** Reuses ordinary placement's rollback/lost-commit rules. The deterministic receipt remains after an uncertain
|
|
15
|
+
* preparation/admission; a retry cannot replace its writer. An existing admitted row is read before opening storage. */
|
|
16
|
+
export function auxiliaryAdmitter(store, options) {
|
|
17
|
+
return async ({ agentId, runId, revisionId, launch, sealed }) => {
|
|
18
|
+
if (Boolean(launch.audit) === Boolean(launch.replay) || launch.sourceProject || launch.files?.length)
|
|
19
|
+
throw refused("Auxiliary learning needs its own audit or replay launch and a fresh project placement.");
|
|
20
|
+
const revision = await store.agents.revision(revisionId);
|
|
21
|
+
if (!revision || revision.agentId !== agentId)
|
|
22
|
+
throw refused("The auxiliary run's reserved agent revision is unavailable.");
|
|
23
|
+
const source = sourceSyncOf(revision.body);
|
|
24
|
+
const admitted = async () => {
|
|
25
|
+
const existing = await store.runs.get(runId);
|
|
26
|
+
if (!existing)
|
|
27
|
+
return;
|
|
28
|
+
const kept = readLaunchBody((await store.runs.launch(runId)).body);
|
|
29
|
+
const pin = kept?.sourceProject;
|
|
30
|
+
const { sourceProject: _pin, ...plain } = kept ?? {};
|
|
31
|
+
// Placement may pin the agent's disk when the original request named none; all other launch fields remain exact.
|
|
32
|
+
const expected = { ...launch, ...(launch.archilDisk === undefined && kept?.archilDisk ? { archilDisk: kept.archilDisk } : {}) };
|
|
33
|
+
if (existing.purgedAt !== null || existing.agentId !== agentId || existing.revisionId !== revisionId || !kept
|
|
34
|
+
|| canonical(launchBody(plain)) !== canonical(launchBody(expected))
|
|
35
|
+
|| (source ? !pin || pin.sourceId !== source.id || pin.digest !== source.project || pin.baselineRevision !== revisionId : pin !== undefined))
|
|
36
|
+
throw refused("The reserved auxiliary run ID already belongs to a different or unavailable launch.");
|
|
37
|
+
return existing;
|
|
38
|
+
};
|
|
39
|
+
const existing = await admitted();
|
|
40
|
+
if (existing)
|
|
41
|
+
return { run: existing, created: false };
|
|
42
|
+
if (source && !options.project)
|
|
43
|
+
throw refused("This auxiliary learning run needs project placement before it can start.");
|
|
44
|
+
return withAgentRepo(options.data, agentId, async () => {
|
|
45
|
+
const existing = await admitted();
|
|
46
|
+
if (existing)
|
|
47
|
+
return { run: existing, created: false };
|
|
48
|
+
const reset = await resetAtOf(store.settings, agentId);
|
|
49
|
+
if (launch.learning && reset !== undefined && !(launch.learning.seededAt !== undefined && launch.learning.seededAt > reset))
|
|
50
|
+
throw refused("The agent's learning was reset after this replay was reserved; its old seed cannot start a new check.");
|
|
51
|
+
const project = options.project && { ...options.project, hold: () => beginSourceIO(store, agentId, "placement", `auxiliary:${runId}`) };
|
|
52
|
+
const run = await withHeldFiles(store, { project }, runId, agentId, revision, launch, prepared => store.runs.create({ id: runId, agentId, revisionId }, { body: launchBody(prepared), ...(sealed ? { sealed } : {}) }));
|
|
53
|
+
return { run, created: true };
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Runner-side counterpart of the server's StartDeps.project. Only trusted host options enter this factory. */
|
|
58
|
+
export function sourceAuxiliaryAdmitter(store, options) {
|
|
59
|
+
return auxiliaryAdmitter(store, { data: options.data, project: projectPlacement({
|
|
60
|
+
hold: ({ agentId }) => beginSourceIO(store, agentId, "placement"),
|
|
61
|
+
snapshots: agentId => sourceSnapshotReader(store, agentId, options),
|
|
62
|
+
destination: target => openRunPlacement(store, target, options),
|
|
63
|
+
}) });
|
|
64
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Workspace } from "../workspace/workspace.js";
|
|
2
|
+
import type { ProjectGitCapture, ProjectGitOptions } from "./capture-project.js";
|
|
3
|
+
/** scratch must be a fresh private folder outside the model's tool root, on the same explicitly pinned backend.
|
|
4
|
+
* Its caller owns cleanup and holds the executor's strict drain until this promise settles. */
|
|
5
|
+
export declare function captureGit(work: Workspace, scratch: Workspace, options: ProjectGitOptions): Promise<ProjectGitCapture>;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Git reads only a bounded, server-private copy. The managed project's config, hooks, filters and path
|
|
2
|
+
// indirections are never given to Git, even if a task changes them between metadata reads.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { secretsIn } from "../secret-cut.js";
|
|
5
|
+
import { secretShapes } from "../learn/secrets.js";
|
|
6
|
+
import { relativeSegments } from "../workspace/paths.js";
|
|
7
|
+
import { SnapshotError } from "./snapshots.js";
|
|
8
|
+
import { ProjectCaptureRefusal, recheckCapture } from "./capture-refusal.js";
|
|
9
|
+
const ENV = { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_SYSTEM: "/dev/null", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1", GIT_TERMINAL_PROMPT: "0", GIT_NO_LAZY_FETCH: "1" };
|
|
10
|
+
const GIT = ["git", "--git-dir=database", "--work-tree=work", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-c", "core.attributesFile=/dev/null", "-c", "core.excludesFile=/dev/null", "-c", "core.quotePath=false", "-c", "protocol.allow=never", "-c", "gc.auto=0", "-c", "maintenance.auto=false"];
|
|
11
|
+
const digest = (body) => createHash("sha256").update(body).digest("hex");
|
|
12
|
+
function refuse(message = "Git metadata needs an explicit safe, complete project representation.") { throw new ProjectCaptureRefusal("prerequisite", message); }
|
|
13
|
+
function pathOf(value) {
|
|
14
|
+
if (!value || /[\x00-\x1f\x7f]/.test(value) || Buffer.byteLength(value) > 4096 || value.split("/").includes(".git"))
|
|
15
|
+
refuse();
|
|
16
|
+
try {
|
|
17
|
+
relativeSegments(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
refuse();
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function text(bytes) {
|
|
25
|
+
try {
|
|
26
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return refuse("Git paths must be portable UTF-8.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
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);
|
|
33
|
+
async function execute(work, argv, options, max, stdin, noMatches = false) {
|
|
34
|
+
options.signal?.throwIfAborted();
|
|
35
|
+
const result = await work.exec([...argv], { env: ENV, timeoutMs: 30_000, maxOutput: max, ...(stdin ? { stdin } : {}), ...(options.signal ? { signal: options.signal } : {}) });
|
|
36
|
+
options.signal?.throwIfAborted();
|
|
37
|
+
if (result.code !== 0 && !(noMatches && result.code === 1) || result.signal || result.timedOut || result.truncated)
|
|
38
|
+
throw new SnapshotError("prerequisite", "Git capture could not finish within its safe bounds.");
|
|
39
|
+
return Buffer.from(result.stdout);
|
|
40
|
+
}
|
|
41
|
+
async function databaseInventory(work, options) {
|
|
42
|
+
const result = await execute(work, ["find", ".git", "(", "-path", ".git/hooks", "-o", "-path", ".git/logs", ")", "-prune", "-o", "-printf", String.raw `%y\0%m\0%s\0%p\0`], options, options.limits.manifestBytes);
|
|
43
|
+
const fields = text(result).split("\0"), rows = [];
|
|
44
|
+
if (fields.pop() !== "" || fields.length % 4)
|
|
45
|
+
refuse();
|
|
46
|
+
for (let n = 0; n < fields.length; n += 4) {
|
|
47
|
+
const [kind, mode, bytes, raw] = fields.slice(n, n + 4);
|
|
48
|
+
if (raw === ".git") {
|
|
49
|
+
if (kind !== "d")
|
|
50
|
+
refuse();
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!raw.startsWith(".git/"))
|
|
54
|
+
refuse();
|
|
55
|
+
const path = pathOf(raw.slice(5));
|
|
56
|
+
if (!["d", "f"].includes(kind) || !/^[0-7]{1,3}$/.test(mode) || !/^\d+$/.test(bytes) || !Number.isSafeInteger(Number(bytes)))
|
|
57
|
+
refuse();
|
|
58
|
+
rows.push({ path, kind, bytes: kind === "d" ? 0 : Number(bytes), mode: parseInt(mode, 8) });
|
|
59
|
+
if (rows.length > options.limits.files)
|
|
60
|
+
throw new ProjectCaptureRefusal("limit", "The Git database exceeds its file limit.");
|
|
61
|
+
}
|
|
62
|
+
return rows.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
63
|
+
}
|
|
64
|
+
const copied = (path) => ["HEAD", "index", "packed-refs", "info/exclude"].includes(path) || path === "objects" || path.startsWith("objects/") || path === "refs" || path.startsWith("refs/");
|
|
65
|
+
const forbidden = (path) => ["commondir", "gitdir", "shallow", "objects/info/alternates", "objects/info/http-alternates"].includes(path) || /^(?:worktrees|modules)(?:\/|$)/.test(path);
|
|
66
|
+
/** scratch must be a fresh private folder outside the model's tool root, on the same explicitly pinned backend.
|
|
67
|
+
* Its caller owns cleanup and holds the executor's strict drain until this promise settles. */
|
|
68
|
+
export async function captureGit(work, scratch, options) {
|
|
69
|
+
options = { ...options, signal: AbortSignal.any([AbortSignal.timeout(30_000), ...(options.signal ? [options.signal] : [])]) };
|
|
70
|
+
if ((await scratch.list("")).length)
|
|
71
|
+
refuse("Git checkpoint scratch must be a fresh private folder.");
|
|
72
|
+
const before = await databaseInventory(work, options), held = new Map(), working = new Map();
|
|
73
|
+
let copiedBytes = 0;
|
|
74
|
+
if (before.some(row => forbidden(row.path) && (row.kind === "d" || row.bytes > 0)))
|
|
75
|
+
refuse();
|
|
76
|
+
const read = async (row) => {
|
|
77
|
+
if (row.bytes > options.limits.gitBytes)
|
|
78
|
+
throw new ProjectCaptureRefusal("limit", "Git control bytes exceed the checkpoint limit.");
|
|
79
|
+
const bytes = Buffer.from(await work.read(`.git/${row.path}`, { length: row.bytes + 1 }));
|
|
80
|
+
options.signal?.throwIfAborted();
|
|
81
|
+
if (bytes.length !== row.bytes)
|
|
82
|
+
throw new SnapshotError("conflict", "Git bytes changed during checkpoint capture.");
|
|
83
|
+
held.set(row.path, digest(bytes));
|
|
84
|
+
return bytes;
|
|
85
|
+
};
|
|
86
|
+
for (const row of before.filter(row => /^config(?:\.worktree)?$/.test(row.path))) {
|
|
87
|
+
if (row.kind !== "f")
|
|
88
|
+
refuse();
|
|
89
|
+
const config = text(await read(row));
|
|
90
|
+
if (/^\s*\[\s*(?:include|includeIf|filter|extensions|submodule)(?:\s|\]|\")/mi.test(config)
|
|
91
|
+
|| /^\s*(?:worktree\s*=|bare\s*=\s*true|excludesfile\s*=|sparsecheckout\s*=)/mi.test(config))
|
|
92
|
+
refuse("Git includes, filters, sparse indexes and external stores need an explicit safe representation.");
|
|
93
|
+
}
|
|
94
|
+
await scratch.mkdir("database");
|
|
95
|
+
await scratch.mkdir("work");
|
|
96
|
+
for (const row of before.filter(row => copied(row.path))) {
|
|
97
|
+
options.signal?.throwIfAborted();
|
|
98
|
+
if (row.kind === "d")
|
|
99
|
+
await scratch.mkdir(`database/${row.path}`);
|
|
100
|
+
else {
|
|
101
|
+
copiedBytes += row.bytes;
|
|
102
|
+
if (copiedBytes > options.limits.gitBytes)
|
|
103
|
+
throw new ProjectCaptureRefusal("limit", "The private Git database exceeds the checkpoint limit.");
|
|
104
|
+
await scratch.write(`database/${row.path}`, await read(row));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await scratch.write("database/config", "[core]\n repositoryformatversion = 0\n bare = false\n filemode = true\n");
|
|
108
|
+
const git = (args, maximum = options.limits.manifestBytes) => execute(scratch, [...GIT, ...args], options, maximum);
|
|
109
|
+
const head = text(await git(["rev-parse", "--verify", "HEAD"])).trim();
|
|
110
|
+
if (!/^[a-f0-9]{40}$/.test(head))
|
|
111
|
+
refuse("This Git object format needs a supported complete export.");
|
|
112
|
+
const headBytes = await scratch.read("database/HEAD", { length: 4097 }), headText = text(headBytes).trim();
|
|
113
|
+
let branch = null;
|
|
114
|
+
if (headText.startsWith("ref: ")) {
|
|
115
|
+
const ref = headText.slice(5);
|
|
116
|
+
if (!ref.startsWith("refs/heads/"))
|
|
117
|
+
refuse();
|
|
118
|
+
await git(["check-ref-format", ref]);
|
|
119
|
+
branch = ref.slice(11);
|
|
120
|
+
}
|
|
121
|
+
else if (headText !== head)
|
|
122
|
+
refuse();
|
|
123
|
+
const tree = text(await git(["rev-parse", "--verify", `${head}^{tree}`])).trim();
|
|
124
|
+
if (text(await git(["write-tree"])).trim() !== tree)
|
|
125
|
+
refuse("Commit or unstage index changes before checkpointing this project.");
|
|
126
|
+
const index = new Map();
|
|
127
|
+
for (const row of text(await git(["ls-files", "--stage", "-z"])).split("\0").filter(Boolean)) {
|
|
128
|
+
const match = /^(100644|100755) ([a-f0-9]{40}) 0\t(.+)$/.exec(row);
|
|
129
|
+
if (!match)
|
|
130
|
+
refuse();
|
|
131
|
+
index.set(pathOf(match[3]), { mode: match[1], oid: match[2] });
|
|
132
|
+
}
|
|
133
|
+
// Evaluate each directory's rules in the isolated database before descending. Neither the ignored tree's
|
|
134
|
+
// contents nor its links/nested repositories consume the durable project's limits. Tracked descendants and
|
|
135
|
+
// authored skills remain selected even under an ignored parent.
|
|
136
|
+
const trackedParents = new Set();
|
|
137
|
+
for (const path of index.keys()) {
|
|
138
|
+
const parts = path.split("/");
|
|
139
|
+
for (let n = 1; n <= parts.length; n++)
|
|
140
|
+
trackedParents.add(parts.slice(0, n).join("/"));
|
|
141
|
+
}
|
|
142
|
+
const select = async (rows) => {
|
|
143
|
+
// Each traversal evaluates the current names/rules afresh. Otherwise a deleted ignore file or a directory
|
|
144
|
+
// replaced by a regular file could retain its old ignored status in this private verification view.
|
|
145
|
+
if (rows.some(row => row.path === "")) {
|
|
146
|
+
await scratch.remove("work", { recursive: true });
|
|
147
|
+
await scratch.mkdir("work");
|
|
148
|
+
}
|
|
149
|
+
// Git must know which candidates are directories, but a trailing slash would apply that directory's own
|
|
150
|
+
// rules to an empty child on the verification pass. Empty placeholders preserve Git's normal path semantics.
|
|
151
|
+
for (const row of rows)
|
|
152
|
+
if (row.path && row.path !== ".git" && row.type === "directory")
|
|
153
|
+
await scratch.mkdir(`work/${row.path}`);
|
|
154
|
+
for (const row of rows.filter(row => row.path.split("/").at(-1) === ".gitignore")) {
|
|
155
|
+
if (row.type !== "file" || row.bytes > options.limits.fileBytes)
|
|
156
|
+
refuse("Git ignore rules need a bounded regular file.");
|
|
157
|
+
const bytes = await work.read(row.path, { length: row.bytes + 1 }), sha = digest(bytes), previous = working.get(row.path);
|
|
158
|
+
if (bytes.length !== row.bytes || previous && (previous.bytes !== row.bytes || previous.sha !== sha))
|
|
159
|
+
throw new SnapshotError("conflict", "Git ignore rules changed during checkpoint capture.");
|
|
160
|
+
working.set(row.path, { bytes: row.bytes, sha });
|
|
161
|
+
await scratch.write(`work/${row.path}`, bytes);
|
|
162
|
+
}
|
|
163
|
+
const names = rows.filter(row => row.path && row.path !== ".git").map(row => row.path);
|
|
164
|
+
const ignored = new Set();
|
|
165
|
+
if (names.length) {
|
|
166
|
+
const output = text(await execute(scratch, [...GIT, "check-ignore", "--no-index", "--stdin", "-z"], options, options.limits.manifestBytes, Buffer.from(`${names.join("\0")}\0`), true));
|
|
167
|
+
const found = output.split("\0");
|
|
168
|
+
if (found.pop() !== "")
|
|
169
|
+
refuse("Git returned incomplete ignore selection.");
|
|
170
|
+
const requested = new Set(names);
|
|
171
|
+
for (const name of found) {
|
|
172
|
+
if (!requested.has(name))
|
|
173
|
+
refuse();
|
|
174
|
+
ignored.add(name);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return new Set(rows.filter(row => row.path === "" || row.path === ".git" || !ignored.has(row.path) || trackedParents.has(row.path)
|
|
178
|
+
|| options.retain.some(path => row.path === path || row.path.startsWith(`${path}/`) || path.startsWith(`${row.path}/`))).map(row => row.path));
|
|
179
|
+
};
|
|
180
|
+
const inventory = await options.inventory(select);
|
|
181
|
+
// Only selected placeholders and ignore rules enter the private work tree; no project program is executed.
|
|
182
|
+
for (const row of inventory) {
|
|
183
|
+
if (!row.path || row.path === ".git")
|
|
184
|
+
continue;
|
|
185
|
+
if (row.type === "directory")
|
|
186
|
+
await scratch.mkdir(`work/${row.path}`);
|
|
187
|
+
else if (row.path.split("/").at(-1) !== ".gitignore")
|
|
188
|
+
await scratch.write(`work/${row.path}`, new Uint8Array());
|
|
189
|
+
}
|
|
190
|
+
const files = [...new Set([...index.keys(), ...text(await git(["ls-files", "--others", "--exclude-standard", "-z"])).split("\0").filter(Boolean).map(pathOf)])].sort();
|
|
191
|
+
const unsafePath = (path) => credentialPath(path) || options.secretValues?.some(value => value && path.includes(value)) === true
|
|
192
|
+
|| options.exclude.some(item => path === item.path || item.recursive && path.startsWith(`${item.path}/`));
|
|
193
|
+
const safeBytes = async (body) => {
|
|
194
|
+
const value = Buffer.from(body).toString("utf8");
|
|
195
|
+
if (options.secretValues?.some(secret => secret && (value.includes(secret) || value.includes(JSON.stringify(secret).slice(1, -1)))) || secretShapes(value).length || (await secretsIn(value)).length)
|
|
196
|
+
refuse("Credential-bearing Git history was withheld from the checkpoint.");
|
|
197
|
+
};
|
|
198
|
+
// A branch name is output metadata; `bundle ... HEAD` need not contain it in any scanned history object.
|
|
199
|
+
if (branch !== null)
|
|
200
|
+
await safeBytes(Buffer.from(branch));
|
|
201
|
+
const deleted = [];
|
|
202
|
+
let dirty = false;
|
|
203
|
+
for (const path of files) {
|
|
204
|
+
if (unsafePath(path))
|
|
205
|
+
refuse("Git history or tracked paths contain credentials or host-owned runtime input.");
|
|
206
|
+
const row = inventory.find(row => row.path === path), tracked = index.get(path);
|
|
207
|
+
if (!row) {
|
|
208
|
+
if (tracked) {
|
|
209
|
+
deleted.push(path);
|
|
210
|
+
dirty = true;
|
|
211
|
+
}
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (row.type !== "file" || row.bytes > options.limits.fileBytes)
|
|
215
|
+
refuse();
|
|
216
|
+
const body = Buffer.from(await work.read(path, { length: row.bytes + 1 }));
|
|
217
|
+
options.signal?.throwIfAborted();
|
|
218
|
+
if (body.length !== row.bytes)
|
|
219
|
+
throw new SnapshotError("conflict", "Project bytes changed during Git capture.");
|
|
220
|
+
working.set(path, { bytes: row.bytes, sha: digest(body) });
|
|
221
|
+
const oid = createHash("sha1").update(`blob ${body.length}\0`).update(body).digest("hex");
|
|
222
|
+
if (!tracked || tracked.oid !== oid || (tracked.mode === "100755") !== !!(row.mode & 0o111))
|
|
223
|
+
dirty = true;
|
|
224
|
+
}
|
|
225
|
+
const objects = text(await git(["rev-list", "--objects", head])).split("\n").filter(Boolean);
|
|
226
|
+
if (objects.length > options.limits.files)
|
|
227
|
+
throw new ProjectCaptureRefusal("limit", "Git history exceeds its object limit.");
|
|
228
|
+
let historyBytes = 0;
|
|
229
|
+
for (const line of objects) {
|
|
230
|
+
const match = /^([a-f0-9]{40})(?: (.*))?$/.exec(line);
|
|
231
|
+
if (!match || match[2] && unsafePath(pathOf(match[2])))
|
|
232
|
+
refuse();
|
|
233
|
+
const oid = match[1], kind = text(await git(["cat-file", "-t", oid])).trim();
|
|
234
|
+
const body = await git(["cat-file", "-p", oid], options.limits.fileBytes);
|
|
235
|
+
historyBytes += body.length;
|
|
236
|
+
if (historyBytes > options.limits.gitBytes)
|
|
237
|
+
throw new ProjectCaptureRefusal("limit", "Expanded Git history exceeds its checkpoint limit.");
|
|
238
|
+
await safeBytes(body);
|
|
239
|
+
if (kind === "commit") {
|
|
240
|
+
// Every historical alias is checked: rev-list names shared blobs only once, which is insufficient when the
|
|
241
|
+
// same object also appears under a credential or runtime-input path in another commit.
|
|
242
|
+
for (const entry of text(await git(["ls-tree", "-r", "-z", oid])).split("\0").filter(Boolean)) {
|
|
243
|
+
const found = /^(100644|100755) blob [a-f0-9]{40}\t(.+)$/.exec(entry);
|
|
244
|
+
if (!found || unsafePath(pathOf(found[2])))
|
|
245
|
+
refuse("Git history contains unsupported or excluded paths.");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else if (!["tree", "blob"].includes(kind))
|
|
249
|
+
refuse();
|
|
250
|
+
}
|
|
251
|
+
const bundle = await git(["bundle", "create", "-", "HEAD"], options.limits.gitBytes);
|
|
252
|
+
const verify = () => recheckCapture(async () => {
|
|
253
|
+
if (JSON.stringify(inventory) !== JSON.stringify(await options.inventory(select)))
|
|
254
|
+
throw new SnapshotError("conflict", "Project metadata changed during checkpoint capture.");
|
|
255
|
+
if (JSON.stringify(before) !== JSON.stringify(await databaseInventory(work, options)))
|
|
256
|
+
throw new SnapshotError("conflict", "Git metadata changed during checkpoint capture.");
|
|
257
|
+
for (const row of before.filter(row => held.has(row.path))) {
|
|
258
|
+
const bytes = await work.read(`.git/${row.path}`, { length: row.bytes + 1 });
|
|
259
|
+
options.signal?.throwIfAborted();
|
|
260
|
+
if (bytes.length !== row.bytes || digest(bytes) !== held.get(row.path))
|
|
261
|
+
throw new SnapshotError("conflict", "Git bytes changed during checkpoint capture.");
|
|
262
|
+
}
|
|
263
|
+
for (const [path, was] of working) {
|
|
264
|
+
const bytes = await work.read(path, { length: was.bytes + 1 });
|
|
265
|
+
options.signal?.throwIfAborted();
|
|
266
|
+
if (bytes.length !== was.bytes || digest(bytes) !== was.sha)
|
|
267
|
+
throw new SnapshotError("conflict", "Project bytes changed after Git capture.");
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
await verify();
|
|
271
|
+
return { files, inventory, bundle, verify, metadata: { head, branch, dirty, deleted, history: "complete" } };
|
|
272
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type SourceSnapshot } from "../native/source-snapshot-types.js";
|
|
2
|
+
import type { Workspace } from "../workspace/workspace.js";
|
|
3
|
+
import { type SnapshotLimits } from "./snapshots.js";
|
|
4
|
+
export interface ProjectExclusion {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly recursive: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ProjectGitCapture {
|
|
9
|
+
readonly metadata: NonNullable<SourceSnapshot["project"]["git"]>;
|
|
10
|
+
readonly bundle: Uint8Array;
|
|
11
|
+
/** Git's tracked and untracked nonignored files, obtained without running source config/hooks/filters. */
|
|
12
|
+
readonly files: readonly string[];
|
|
13
|
+
readonly inventory: readonly ProjectInventoryEntry[];
|
|
14
|
+
/** Recheck the isolated view's original bytes after project capture, while the same strict drain remains held. */
|
|
15
|
+
readonly verify?: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface ProjectInventoryEntry {
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly type: "file" | "directory";
|
|
20
|
+
readonly mode: number;
|
|
21
|
+
readonly bytes: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ProjectInventoryCandidate {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly type: "file" | "directory" | "unsupported";
|
|
26
|
+
readonly mode: number;
|
|
27
|
+
readonly bytes: number;
|
|
28
|
+
}
|
|
29
|
+
export type ProjectInventorySelector = (entries: readonly ProjectInventoryCandidate[]) => Promise<ReadonlySet<string>>;
|
|
30
|
+
export interface ProjectGitOptions {
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
readonly secretValues?: readonly string[];
|
|
33
|
+
/** Select names before validating or descending into them; ignored dependency trees are not project content. */
|
|
34
|
+
readonly inventory: (select: ProjectInventorySelector) => Promise<readonly ProjectInventoryEntry[]>;
|
|
35
|
+
readonly retain: readonly string[];
|
|
36
|
+
readonly exclude: readonly ProjectExclusion[];
|
|
37
|
+
readonly limits: SnapshotLimits;
|
|
38
|
+
}
|
|
39
|
+
export interface ProjectCaptureOptions {
|
|
40
|
+
readonly workspace: Workspace;
|
|
41
|
+
readonly baseline: SourceSnapshot;
|
|
42
|
+
/** Exact paths owned by this run's host (placed input files and declared scratch roots), never guessed exclusions. */
|
|
43
|
+
readonly exclude: readonly ProjectExclusion[];
|
|
44
|
+
/** A safe isolated Git view, with bounded objects/history, no source configuration or untrusted execution. Missing
|
|
45
|
+
* capability blocks a Git project; it never flattens that project into an apparently complete plain directory. */
|
|
46
|
+
readonly git?: (workspace: Workspace, options: ProjectGitOptions) => Promise<ProjectGitCapture>;
|
|
47
|
+
readonly secretValues?: readonly string[];
|
|
48
|
+
readonly signal?: AbortSignal;
|
|
49
|
+
readonly limits?: Partial<SnapshotLimits>;
|
|
50
|
+
}
|
|
51
|
+
/** A complete immutable successor, or a refusal. Original source instructions, tool policy and skill identities
|
|
52
|
+
* remain configuration; current project and authored-skill bytes/modes become the separately pinned project. */
|
|
53
|
+
export declare function captureProject(options: ProjectCaptureOptions): Promise<SourceSnapshot>;
|