@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,48 @@
|
|
|
1
|
+
import { kindSkillOf } from "../workspace/kind-skills.js";
|
|
2
|
+
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
3
|
+
import { verifySourceProject } from "./projects.js";
|
|
4
|
+
import { SnapshotError } from "./snapshots.js";
|
|
5
|
+
import { sourceSyncOf } from "./types.js";
|
|
6
|
+
import { sourceRunControl } from "./workspace.js";
|
|
7
|
+
export async function verifyPlacedProject(store, run, revision, launch, options) {
|
|
8
|
+
const binding = sourceSyncOf(revision.body), placed = launch.sourceProject;
|
|
9
|
+
if (!binding && !placed)
|
|
10
|
+
return false;
|
|
11
|
+
if (!binding || !placed || placed.sourceId !== binding.id || placed.digest !== binding.project || placed.baselineRevision !== revision.id || revision.id !== run.revisionId)
|
|
12
|
+
throw new SnapshotError("prerequisite", "This moved project needs normal project placement before it can run. Auxiliary runs must prepare their own project and completion receipt.");
|
|
13
|
+
const control = await sourceRunControl(store, { agentId: run.agentId, runId: run.id, launch }, options);
|
|
14
|
+
try {
|
|
15
|
+
await verifySourceProject(control.workspace, placed);
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
await control.end();
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
/** Full authored assets already exist in the seeded workspace. Only discover their current SKILL.md files; stale
|
|
23
|
+
* revision text must never recreate a directory the task removed. The host's computer-kind guidance remains its own
|
|
24
|
+
* add-only asset, unless an authored skill selected that name. */
|
|
25
|
+
export async function movedSkillFiles(work, authored, computer) {
|
|
26
|
+
const kind = kindSkillOf(computer), authoredNames = new Set(Object.keys(authored).map(path => path.split("/")[0]));
|
|
27
|
+
if (kind && !authoredNames.has(kind.name))
|
|
28
|
+
await layOwnSkills(work, {}, { computer });
|
|
29
|
+
const root = ".agents/skills", stat = await work.stat(root);
|
|
30
|
+
if (!stat)
|
|
31
|
+
return [];
|
|
32
|
+
if (stat.kind !== "dir")
|
|
33
|
+
throw new SnapshotError("conflict", "The moved project's skills directory is not a directory.");
|
|
34
|
+
const entries = await work.list(root);
|
|
35
|
+
if (entries.length > 10_000)
|
|
36
|
+
throw new SnapshotError("limit", "The moved project has too many skill entries.");
|
|
37
|
+
// Ordinary owner-authored skill paths may be nested. Keep those exact paths discoverable as well as current
|
|
38
|
+
// top-level skills, without recreating any missing file from the revision text.
|
|
39
|
+
const candidates = new Set([...Object.keys(authored).filter(path => path.endsWith("/SKILL.md")), ...entries.map(entry => `${entry.name}/SKILL.md`)]);
|
|
40
|
+
if (candidates.size > 10_000)
|
|
41
|
+
throw new SnapshotError("limit", "The moved project has too many skill entries.");
|
|
42
|
+
const paths = [];
|
|
43
|
+
for (const file of candidates) {
|
|
44
|
+
if ((await work.stat(`${root}/${file}`))?.kind === "file")
|
|
45
|
+
paths.push(file);
|
|
46
|
+
}
|
|
47
|
+
return paths.sort();
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SourceSnapshot, SourceSnapshotTool } from "../native/source-snapshot-types.js";
|
|
2
|
+
import { type BoxOffer } from "../place-offers.js";
|
|
3
|
+
import { type Place } from "../place.js";
|
|
4
|
+
import type { Store } from "../store/store.js";
|
|
5
|
+
import type { SourcePreparationDeps } from "./prepare.js";
|
|
6
|
+
export declare function sourceToolConnections(store: Store, agentId: string, snapshot: SourceSnapshot): Promise<{
|
|
7
|
+
candidates: {
|
|
8
|
+
name: string;
|
|
9
|
+
auth: string;
|
|
10
|
+
}[];
|
|
11
|
+
selected?: string | undefined;
|
|
12
|
+
name: string;
|
|
13
|
+
ready: boolean;
|
|
14
|
+
}[]>;
|
|
15
|
+
/** The owner explicitly chooses the destination account. Source OAuth tokens and private command environments never
|
|
16
|
+
* cross the source boundary. The binding expires when the source requirement or the saved account changes. */
|
|
17
|
+
export declare function bindSourceTool(store: Store, agentId: string, source: SourceSnapshotTool, server: string): Promise<void>;
|
|
18
|
+
/** Only explicitly represented native policies are mapped. Unknown constraints never disappear into a permissive
|
|
19
|
+
* host default. File operations are workspace-scoped; shell work requires the host's real sandbox and network rule. */
|
|
20
|
+
export declare function sourcePolicy(snapshot: SourceSnapshot, boxes: readonly BoxOffer[], external: readonly string[]): {
|
|
21
|
+
blockers: {
|
|
22
|
+
path?: string | undefined;
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}[];
|
|
26
|
+
} | {
|
|
27
|
+
source: Record<string, unknown>;
|
|
28
|
+
tools: string[];
|
|
29
|
+
approvals: "ask";
|
|
30
|
+
place: Place;
|
|
31
|
+
toolSettings: {
|
|
32
|
+
[k: string]: {
|
|
33
|
+
permission: "ask" | "allow";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare function destinationPreparation(store: Store, agentId: string, options: {
|
|
38
|
+
env: () => NodeJS.ProcessEnv;
|
|
39
|
+
boxes: () => readonly BoxOffer[];
|
|
40
|
+
check: SourcePreparationDeps["check"];
|
|
41
|
+
/** Successful probes of this server's destination only. Another or later runner must enforce the same
|
|
42
|
+
* prerequisite at claim: a server-local probe cannot establish a remote runner's isolation policy. */
|
|
43
|
+
projectExecution(): Promise<{
|
|
44
|
+
readonly storage: "local" | "archil";
|
|
45
|
+
readonly isolation: "uid" | "process";
|
|
46
|
+
}>;
|
|
47
|
+
}): SourcePreparationDeps;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/** Resolve source requirements against this server's ordinary model, tool and execution registries. */
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { ApiError } from "../errors.js";
|
|
4
|
+
import { factsOf, harnessForSourceProtocol } from "../harness-table.js";
|
|
5
|
+
import { NATIVE_RUNTIME_FACTS } from "../native/runtimes.js";
|
|
6
|
+
import { chooseModel } from "../model.js";
|
|
7
|
+
import { formOf, pickerCandidates } from "../model-form.js";
|
|
8
|
+
import { missingMcpTools, selectedMcpTool, sourceMcpSelection } from "../native/source-mcp-selection.js";
|
|
9
|
+
import { resourceToolOperation } from "../mcp-resources.js";
|
|
10
|
+
import { BOX_IDS } from "../place-offers.js";
|
|
11
|
+
import { NEW_AGENT_TOOLS } from "../place.js";
|
|
12
|
+
import { isHostTool } from "../tool-list.js";
|
|
13
|
+
import { wireOf } from "../wires.js";
|
|
14
|
+
import { canonical, isObject } from "../store/agent-body.js";
|
|
15
|
+
const digest = (value) => createHash("sha256").update(canonical(value)).digest("hex");
|
|
16
|
+
const bindingKey = (agentId, name) => `source-sync.tool.${agentId}.${digest(name)}`;
|
|
17
|
+
const stamp = (row) => ({ url: row.url, auth: row.auth, credential: row.credentialChangedAt, sealedHash: row.sealed ? createHash("sha256").update(row.sealed).digest("hex") : null, tools: digest(row.tools) });
|
|
18
|
+
const refused = (code, message, path) => ({ blockers: [{ code, message, ...(path ? { path } : {}) }] });
|
|
19
|
+
function selectedTools(source, row) {
|
|
20
|
+
if (!sourceMcpSelection(source.selection) || !Array.isArray(source.resources)
|
|
21
|
+
|| source.resources.some(op => !["list", "templates", "read"].includes(op)))
|
|
22
|
+
throw new ApiError("input_invalid", "Sync this source's complete MCP tool and resource selection before choosing its destination.");
|
|
23
|
+
if (!Array.isArray(row.tools))
|
|
24
|
+
throw new ApiError("input_invalid", "Refresh the destination MCP catalog first.");
|
|
25
|
+
const selected = [], ordinary = [];
|
|
26
|
+
for (const tool of row.tools) {
|
|
27
|
+
if (!isObject(tool) || typeof tool.name !== "string" || !isObject(tool.input_schema))
|
|
28
|
+
throw new ApiError("input_invalid", "The destination MCP catalog is incomplete.");
|
|
29
|
+
const resource = resourceToolOperation(tool);
|
|
30
|
+
if (tool.resource !== undefined && !resource)
|
|
31
|
+
throw new ApiError("input_invalid", "The destination resource capability is invalid; refresh its catalog.");
|
|
32
|
+
if (resource) {
|
|
33
|
+
if (source.resources.includes(resource))
|
|
34
|
+
selected.push(`mcp:${row.name}/${tool.name}`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
ordinary.push(tool.name);
|
|
38
|
+
if (selectedMcpTool(source.selection, source.name, tool.name))
|
|
39
|
+
selected.push(`mcp:${row.name}/${tool.name}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (missingMcpTools(source.selection, source.name, ordinary).length)
|
|
43
|
+
throw new ApiError("input_invalid", "A required source tool is missing from the destination MCP catalog.");
|
|
44
|
+
// Empty is meaningful: an explicit zero-tool source may point at a tools-only server whose
|
|
45
|
+
// native resource listing is empty. Preserve zero grants; never replace them with all tools.
|
|
46
|
+
return selected;
|
|
47
|
+
}
|
|
48
|
+
const needsSignIn = (source, row) => source.credentials.length > 0 && row.auth === "none"
|
|
49
|
+
|| row.auth !== "none" && (!row.sealed || row.tokenLeftMs !== null && row.tokenLeftMs <= 0);
|
|
50
|
+
export async function sourceToolConnections(store, agentId, snapshot) {
|
|
51
|
+
const rows = await store.mcp.servers();
|
|
52
|
+
return Promise.all(snapshot.configuration.tools.map(async (source) => {
|
|
53
|
+
const binding = await store.settings.get(bindingKey(agentId, source.name));
|
|
54
|
+
const selected = binding && rows.find(row => row.name === binding.server);
|
|
55
|
+
const ready = !!(binding && selected && binding.requirement === digest(source) && canonical(stamp(selected)) === canonical(binding.stamp));
|
|
56
|
+
return { name: source.name, ready, ...(ready ? { selected: binding.server } : {}),
|
|
57
|
+
candidates: rows.filter(row => source.transport === "http" && source.url === row.url).map(row => ({ name: row.name, auth: row.auth })) };
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
/** The owner explicitly chooses the destination account. Source OAuth tokens and private command environments never
|
|
61
|
+
* cross the source boundary. The binding expires when the source requirement or the saved account changes. */
|
|
62
|
+
export async function bindSourceTool(store, agentId, source, server) {
|
|
63
|
+
const row = await store.mcp.server(server);
|
|
64
|
+
if (!row)
|
|
65
|
+
throw new ApiError("input_invalid", "Connect and verify the destination tool server first.");
|
|
66
|
+
if (needsSignIn(source, row))
|
|
67
|
+
throw new ApiError("auth_required", "Sign in to this destination tool server first.");
|
|
68
|
+
if (source.transport !== "http" || source.url !== row.url)
|
|
69
|
+
throw new ApiError("input_invalid", "This source tool needs a verified destination equivalent before it can move.");
|
|
70
|
+
selectedTools(source, row);
|
|
71
|
+
await store.settings.put(bindingKey(agentId, source.name), { requirement: digest(source), server, stamp: stamp(row) });
|
|
72
|
+
}
|
|
73
|
+
/** Only explicitly represented native policies are mapped. Unknown constraints never disappear into a permissive
|
|
74
|
+
* host default. File operations are workspace-scoped; shell work requires the host's real sandbox and network rule. */
|
|
75
|
+
export function sourcePolicy(snapshot, boxes, external) {
|
|
76
|
+
const policy = snapshot.configuration.permissions, evidence = snapshot.configuration.native_tools;
|
|
77
|
+
const block = () => refused("policy_mapping", "This source permission policy needs a supported AgentRun equivalent before Move.", "configuration.permissions");
|
|
78
|
+
if (!evidence?.complete)
|
|
79
|
+
return refused("native_tool_closure", "Sync complete native tool requirements before Move.", "configuration.native_tools");
|
|
80
|
+
const capabilities = new Set(evidence.capabilities), tools = new Set();
|
|
81
|
+
const missing = (name) => refused("native_capability", `The source capability ${JSON.stringify(name)} needs a verified equivalent on this agent's destination harness.`, "configuration.native_tools");
|
|
82
|
+
for (const capability of capabilities) {
|
|
83
|
+
let mapped;
|
|
84
|
+
switch (capability) {
|
|
85
|
+
case "file_read":
|
|
86
|
+
case "image_read":
|
|
87
|
+
mapped = ["read"];
|
|
88
|
+
break;
|
|
89
|
+
case "file_write":
|
|
90
|
+
mapped = ["write"];
|
|
91
|
+
break;
|
|
92
|
+
case "file_edit":
|
|
93
|
+
mapped = ["edit"];
|
|
94
|
+
break;
|
|
95
|
+
case "shell":
|
|
96
|
+
mapped = NEW_AGENT_TOOLS;
|
|
97
|
+
break;
|
|
98
|
+
case "web_search":
|
|
99
|
+
mapped = ["web_search"];
|
|
100
|
+
break;
|
|
101
|
+
case "web_fetch":
|
|
102
|
+
mapped = ["web_fetch"];
|
|
103
|
+
break;
|
|
104
|
+
case "user_input":
|
|
105
|
+
mapped = ["ask_person"];
|
|
106
|
+
break;
|
|
107
|
+
case "file_search":
|
|
108
|
+
case "clock":
|
|
109
|
+
case "sleep":
|
|
110
|
+
case "worktree":
|
|
111
|
+
// Reuse an already authorized shell; never grant a write-capable shell to a read-only tool list.
|
|
112
|
+
if (!capabilities.has("shell"))
|
|
113
|
+
return missing(capability);
|
|
114
|
+
mapped = ["bash"];
|
|
115
|
+
break;
|
|
116
|
+
case "subagents":
|
|
117
|
+
mapped = ["subagent"];
|
|
118
|
+
break;
|
|
119
|
+
// The selected server-local resource operations come through the ordinary pinned MCP
|
|
120
|
+
// path below. A tools-only server adds none; native empty resource discovery adds no access.
|
|
121
|
+
case "mcp_resources":
|
|
122
|
+
mapped = [];
|
|
123
|
+
break;
|
|
124
|
+
// Ending the conversation and loading captured authored skills have direct managed equivalents.
|
|
125
|
+
// Planning-mode transitions, context reset APIs and feedback delivery need their own proofs.
|
|
126
|
+
case "session_end":
|
|
127
|
+
case "skills":
|
|
128
|
+
mapped = [];
|
|
129
|
+
break;
|
|
130
|
+
default: return missing(capability);
|
|
131
|
+
}
|
|
132
|
+
for (const name of mapped) {
|
|
133
|
+
// Both source protocols select adapters. Their actual host registry excludes Pi-only tools.
|
|
134
|
+
if (!isHostTool(name))
|
|
135
|
+
return missing(capability);
|
|
136
|
+
tools.add(name);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
let shellPermission, externalPermission;
|
|
140
|
+
if (NATIVE_RUNTIME_FACTS[snapshot.source.runtime].protocol === "codex-json") {
|
|
141
|
+
if (Object.keys(policy).some(key => !["approval_policy", "sandbox_mode", "sandbox_workspace_write", "web_search", "project_trust"].includes(key)))
|
|
142
|
+
return block();
|
|
143
|
+
if (policy.project_trust !== undefined && policy.project_trust !== "trusted")
|
|
144
|
+
return block();
|
|
145
|
+
// Codex workspace-write protects .git/.codex/.agents even inside writable roots. Our host
|
|
146
|
+
// shell has no equivalent protected-path enforcement yet; a generic container is insufficient.
|
|
147
|
+
if (policy.sandbox_mode !== "danger-full-access")
|
|
148
|
+
return block();
|
|
149
|
+
if (policy.approval_policy !== "never" && policy.approval_policy !== "on-request")
|
|
150
|
+
return block();
|
|
151
|
+
if (policy.sandbox_workspace_write !== undefined && (!isObject(policy.sandbox_workspace_write) || Object.keys(policy.sandbox_workspace_write).length))
|
|
152
|
+
return block();
|
|
153
|
+
if (![undefined, "disabled", "live", "cached"].includes(policy.web_search))
|
|
154
|
+
return block();
|
|
155
|
+
if (capabilities.has("web_search") && policy.web_search !== "live")
|
|
156
|
+
return refused("web_search_mapping", "The source's cached-search policy needs a verified cached destination route before Move.", "configuration.permissions.web_search");
|
|
157
|
+
shellPermission = "allow";
|
|
158
|
+
externalPermission = "ask";
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (Object.keys(policy).some(key => !["defaultMode", "permissionMode", "tools", "disallowedTools"].includes(key)))
|
|
162
|
+
return block();
|
|
163
|
+
const mode = policy.permissionMode ?? policy.defaultMode;
|
|
164
|
+
if (mode !== "bypassPermissions")
|
|
165
|
+
return block();
|
|
166
|
+
// Bypass is not permission to skip Claude's critical-operation checks. Keep an explicit
|
|
167
|
+
// owner ask for shell and external operations instead of widening those exceptional effects.
|
|
168
|
+
shellPermission = "ask";
|
|
169
|
+
externalPermission = "ask";
|
|
170
|
+
}
|
|
171
|
+
const box = boxes.find(box => box.available && BOX_IDS.includes(box.id) && box.network !== "none");
|
|
172
|
+
if (!box)
|
|
173
|
+
return refused("execution_environment", "Set up an AgentRun sandbox with the network access this source requires.");
|
|
174
|
+
const names = [...tools].sort();
|
|
175
|
+
return { source: policy, tools: names, approvals: "ask", place: { mode: "sandbox", box: box.id },
|
|
176
|
+
toolSettings: Object.fromEntries([...names, ...external].map(name => [NEW_AGENT_TOOLS.includes(name) ? "bash" : name, { permission: external.includes(name) ? externalPermission : NEW_AGENT_TOOLS.includes(name) ? shellPermission : "allow" }])) };
|
|
177
|
+
}
|
|
178
|
+
export function destinationPreparation(store, agentId, options) {
|
|
179
|
+
const authenticated = new Set();
|
|
180
|
+
return {
|
|
181
|
+
model: async (snapshot) => {
|
|
182
|
+
const source = snapshot.configuration.model, harness = harnessForSourceProtocol(NATIVE_RUNTIME_FACTS[snapshot.source.runtime].protocol);
|
|
183
|
+
if (!source)
|
|
184
|
+
return refused("model_mapping", "Sync the source's effective model before Move.");
|
|
185
|
+
const env = options.env(), candidates = pickerCandidates(env, harness);
|
|
186
|
+
// Exact catalog IDs only; an alias such as `sonnet` cannot be guessed into a different model version.
|
|
187
|
+
const matches = candidates.filter(id => id === source || id.slice(id.lastIndexOf("/") + 1) === source);
|
|
188
|
+
// The picker is a short convenience list, not the model catalog. Preserve its configured
|
|
189
|
+
// route preference, otherwise ask the registered source wire's vendor for the exact ID.
|
|
190
|
+
const facts = factsOf(env, harness), vendor = facts && wireOf(facts.wire)?.vendor;
|
|
191
|
+
if (!matches.length && vendor && !env.AGENT_MODEL_BASE_URL && !source.includes("/"))
|
|
192
|
+
matches.push(formOf(env, vendor, source));
|
|
193
|
+
if (matches.length !== 1)
|
|
194
|
+
return refused("model_mapping", `Configure one destination route for the source model ${JSON.stringify(source)} in Settings → Model keys.`);
|
|
195
|
+
const model = matches[0], chosen = await chooseModel(env, model, "default", harness);
|
|
196
|
+
if ("why" in chosen)
|
|
197
|
+
return refused("model_authentication", chosen.why);
|
|
198
|
+
authenticated.add("model-provider");
|
|
199
|
+
return { sourceModel: source, model, harness };
|
|
200
|
+
},
|
|
201
|
+
tool: async (source) => {
|
|
202
|
+
const key = bindingKey(agentId, source.name);
|
|
203
|
+
const binding = await store.settings.get(key);
|
|
204
|
+
const row = binding && await store.mcp.server(binding.server);
|
|
205
|
+
if (!binding || binding.requirement !== digest(source) || !row || canonical(stamp(row)) !== canonical(binding.stamp))
|
|
206
|
+
return refused("tool_connection", `Connect ${JSON.stringify(source.name)} on AgentRun and choose the account this agent should use.`, `configuration.tools.${source.name}`);
|
|
207
|
+
if (needsSignIn(source, row))
|
|
208
|
+
return refused("tool_authentication", `Sign in to the destination connection for ${JSON.stringify(source.name)}.`);
|
|
209
|
+
let names;
|
|
210
|
+
try {
|
|
211
|
+
names = selectedTools(source, row);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (!(error instanceof ApiError))
|
|
215
|
+
throw error;
|
|
216
|
+
return refused("tool_capabilities", error.message, `configuration.tools.${source.name}`);
|
|
217
|
+
}
|
|
218
|
+
source.credentials.forEach(name => authenticated.add(name));
|
|
219
|
+
return { source, tools: names, mcpGuards: [{ name: row.name, url: row.url, auth: row.auth, credentialChangedAt: row.credentialChangedAt, tools: row.tools, sealed: row.sealed }], guards: [{ key, fields: { requirement: binding.requirement, server: binding.server, stamp: binding.stamp } }] };
|
|
220
|
+
},
|
|
221
|
+
policy: async (snapshot, external) => {
|
|
222
|
+
let execution;
|
|
223
|
+
try {
|
|
224
|
+
execution = await options.projectExecution();
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return refused("project_mode_fidelity", "Verify a destination that preserves project file permissions before Move.");
|
|
228
|
+
}
|
|
229
|
+
// The per-user helper recursively replaces permission bits, not merely ownership. The source's
|
|
230
|
+
// exact local modes cannot survive that transform; the separate Archil project is untouched.
|
|
231
|
+
if (execution.storage === "local" && execution.isolation === "uid")
|
|
232
|
+
return refused("project_mode_fidelity", "This runner rewrites local project file permissions for per-user isolation. A moved project needs a destination that preserves its original permissions.");
|
|
233
|
+
return sourcePolicy(snapshot, options.boxes(), external);
|
|
234
|
+
},
|
|
235
|
+
credentials: async (names) => names.every(name => authenticated.has(name)) ? { resolved: [...names] }
|
|
236
|
+
: refused("credentials_missing", "Set up the destination credentials required by this source's tools and model."),
|
|
237
|
+
check: options.check,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Store } from "../store/store.js";
|
|
2
|
+
type IOStore = Pick<Store, "agents" | "settings">;
|
|
3
|
+
export declare const SOURCE_IO_LIMIT = 32;
|
|
4
|
+
export declare const sourceIOPrefix: (agentId: string) => string;
|
|
5
|
+
export interface SourceIOReceipt {
|
|
6
|
+
/** Call only after every owned write/exec and resource cleanup settled. For placement, this includes confirmed
|
|
7
|
+
* admission (the live run now protects the files) or confirmed rollback. Never call after an uncertain failure. */
|
|
8
|
+
settled(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function beginSourceIO(store: IOStore, agentId: string, kind: "snapshot" | "placement", operation?: string): Promise<SourceIOReceipt>;
|
|
11
|
+
export declare function withSourceIO<T>(store: IOStore, agentId: string, kind: "snapshot" | "placement", work: () => Promise<T>): Promise<T>;
|
|
12
|
+
/** Call only AFTER deletion's durable archive/purging mark and BEFORE any folder/disk removal. The caller must keep
|
|
13
|
+
* that mark through failure/retry. Reading this alone does not reserve deletion or authorize an unmarked purge. */
|
|
14
|
+
export declare function requireSourceIOIdle(store: Pick<Store, "settings">, agentId: string): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Private durable I/O ownership, not a lease. Deletion first marks the agent archived/purging, then checks these
|
|
2
|
+
* receipts before removing any folders/disks. Writers insert first, then check that mark, then touch the filesystem.
|
|
3
|
+
* Those opposite orders prevent either process from overlooking an already admitted writer. Never use a read-only
|
|
4
|
+
* store snapshot here: each read must see the preceding committed insertion/mark from the other process.
|
|
5
|
+
*
|
|
6
|
+
* A returned/aborted remote request need not mean its remote writes stopped. Unknown outcomes remain recorded,
|
|
7
|
+
* regardless of age. Recovery needs independent proof that the old writer AND any remote operations have settled;
|
|
8
|
+
* this module deliberately offers no timeout takeover or bulk clear. */
|
|
9
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
10
|
+
import { purgingKey } from "../agent-delete.js";
|
|
11
|
+
import { ApiError } from "../errors.js";
|
|
12
|
+
import { canonical } from "../store/agent-body.js";
|
|
13
|
+
export const SOURCE_IO_LIMIT = 32;
|
|
14
|
+
export const sourceIOPrefix = (agentId) => `source-sync.io.${createHash("sha256").update(agentId).digest("hex")}.`;
|
|
15
|
+
const instance = randomUUID();
|
|
16
|
+
const busy = () => new ApiError("agent_not_runnable", "A source operation is still writing or has an unresolved outcome. Confirm that its owning writer and remote operations have stopped before deleting this agent or recovering its source write receipt.");
|
|
17
|
+
export async function beginSourceIO(store, agentId, kind, operation) {
|
|
18
|
+
// A reserved auxiliary run can be offered by several runners. Its deterministic operation key makes the existing
|
|
19
|
+
// durable receipt an exclusive preparation fence too. An unknown owner is never displaced on age or retry.
|
|
20
|
+
const prefix = sourceIOPrefix(agentId), token = randomUUID(), key = prefix + (operation === undefined ? token : createHash("sha256").update(operation).digest("hex"));
|
|
21
|
+
const value = { version: 1, token, instance, kind, startedAt: Date.now() };
|
|
22
|
+
const saved = await store.settings.putIfAbsent(key, value, { prefix, limit: SOURCE_IO_LIMIT });
|
|
23
|
+
if (canonical(saved ?? null) !== canonical(value))
|
|
24
|
+
throw busy();
|
|
25
|
+
const receipt = { async settled() {
|
|
26
|
+
if (!await store.settings.removeIf(key, value) && await store.settings.get(key) !== undefined)
|
|
27
|
+
throw new ApiError("precondition_failed", "The source write receipt changed; its new owner must resolve it.");
|
|
28
|
+
} };
|
|
29
|
+
try {
|
|
30
|
+
const agent = await store.agents.get(agentId);
|
|
31
|
+
if (!agent || agent.archivedAt !== null || agent.purgedAt !== null || await store.settings.get(purgingKey(agentId)) !== undefined)
|
|
32
|
+
throw new ApiError("agent_not_runnable", "Source writes require an active agent that is not being deleted.");
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// No filesystem callback has been dispatched, so this exact receipt is safe to release, even on a failed read.
|
|
36
|
+
await receipt.settled().catch(() => undefined);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return receipt;
|
|
40
|
+
}
|
|
41
|
+
export async function withSourceIO(store, agentId, kind, work) {
|
|
42
|
+
const receipt = await beginSourceIO(store, agentId, kind);
|
|
43
|
+
const result = await work();
|
|
44
|
+
await receipt.settled();
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/** Call only AFTER deletion's durable archive/purging mark and BEFORE any folder/disk removal. The caller must keep
|
|
48
|
+
* that mark through failure/retry. Reading this alone does not reserve deletion or authorize an unmarked purge. */
|
|
49
|
+
export async function requireSourceIOIdle(store, agentId) {
|
|
50
|
+
if ((await store.settings.all({ prefix: sourceIOPrefix(agentId) })).length)
|
|
51
|
+
throw busy();
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { selectedNative } from "../native/connection.js";
|
|
2
|
+
import { exportSourceSnapshot } from "../native/source-snapshot.js";
|
|
3
|
+
import type { Store } from "../store/store.js";
|
|
4
|
+
import { SourceSync, type SourceAuthority, type SourceIdentity } from "./registry.js";
|
|
5
|
+
export type SourceLocalConsent = {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly scope: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const sourceLocalKey: (agentId: string) => string;
|
|
10
|
+
/** The wire carries only this digest, never device/inode/user/profile metadata. Configuration contents are not in
|
|
11
|
+
* the scope: editing those contents is the authorized input to sync. Replacing a folder or changing user is not. */
|
|
12
|
+
export declare function sourceLocalConsent(target: SourceIdentity, env?: NodeJS.ProcessEnv): Promise<SourceLocalConsent>;
|
|
13
|
+
export interface LocalSourcesOptions {
|
|
14
|
+
readonly env?: () => NodeJS.ProcessEnv;
|
|
15
|
+
readonly selected?: typeof selectedNative;
|
|
16
|
+
readonly export?: typeof exportSourceSnapshot;
|
|
17
|
+
readonly secrets?: () => readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export declare class LocalSources {
|
|
20
|
+
readonly store: Store;
|
|
21
|
+
readonly options: LocalSourcesOptions;
|
|
22
|
+
constructor(store: Store, options?: LocalSourcesOptions);
|
|
23
|
+
private capture;
|
|
24
|
+
/** Called after explicit CLI consent, before SourceSync.grant. An owner-disabled source record stays disabled;
|
|
25
|
+
* this proves export scope, not permission to undo the owner's pause or move execution back to the source. */
|
|
26
|
+
grant(agentId: string, consent: unknown): Promise<SourceAuthority>;
|
|
27
|
+
private checked;
|
|
28
|
+
authorize(agentId: string): Promise<SourceAuthority>;
|
|
29
|
+
/** Native disconnect calls this before changing its binding. CLI disconnect also fences through active/generation.
|
|
30
|
+
* It does not edit a managed revision, kill a run or delete any captured snapshot. */
|
|
31
|
+
revoke(agentId: string): Promise<void>;
|
|
32
|
+
publisher(sync: SourceSync, options?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
agentWrite?: <T>(agentId: string, call: () => Promise<T>) => Promise<T>;
|
|
35
|
+
}): {
|
|
36
|
+
tick: (signal?: AbortSignal) => Promise<{
|
|
37
|
+
published: number;
|
|
38
|
+
unchanged: number;
|
|
39
|
+
refused: number;
|
|
40
|
+
failed: number;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
}
|