@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
package/dist/mcp-probe.js
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
// Nothing here opens a credential or touches a store: listServer connects to a URL with the official SDK client, agrees a
|
|
6
6
|
// protocol revision and lists every tool (all pages, under caps); the validation turns a request body into a URL, auth and
|
|
7
7
|
// prices, or a 422; no redirect is followed, so a credential goes only where the owner sends it.
|
|
8
|
-
import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID } from "./composio-preset.js";
|
|
8
|
+
import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID, COMPOSIO_USER_ID_WORDS } from "./composio-preset.js";
|
|
9
9
|
import { ApiError, invalid } from "./errors.js";
|
|
10
10
|
import { metaToolOf } from "./mcp-meta.js";
|
|
11
11
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
12
12
|
import { capped, MAX_RESPONSE, mcpClient, scrub } from "./mcp-wire.js";
|
|
13
|
+
import { reservedResourceName, resourceTools } from "./mcp-resources.js";
|
|
13
14
|
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
14
15
|
import { isObject, unknownFields } from "./validate.js";
|
|
15
16
|
/** The names AgentRun's own tools are called by, which no MCP server takes: claude-agent calls the kernel's host tools
|
|
@@ -67,7 +68,7 @@ const LOOPBACK = (host) => LOOPBACK_NAMES.includes(host) || LOOPBACK_V4.test(hos
|
|
|
67
68
|
/** A registry tool (input_schema, as the server listed it) in the harnesses' shape (the kernel's McpTool: inputSchema),
|
|
68
69
|
* as a run is pinned to it and a session binds it. */
|
|
69
70
|
export function boundTool(tool) {
|
|
70
|
-
return { name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}) };
|
|
71
|
+
return { name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}), ...(tool.resource !== undefined ? { resource: tool.resource } : {}) };
|
|
71
72
|
}
|
|
72
73
|
export const notFound = (name) => new ApiError("not_found", `No MCP server ${name}: GET /v2/settings/mcp-servers lists them.`);
|
|
73
74
|
export const credentialMissing = (type, message) => ({ field: type === "bearer" ? "auth.token" : type === "oauth" ? "auth.type" : "auth.headers", reason: "missing", message: type === "oauth" ? `${message} An OAuth server is signed in to first: POST /v2/settings/mcp-servers/{name}/oauth/start.` : message });
|
|
@@ -277,7 +278,7 @@ function composioBindingOf(field, entry, issues) {
|
|
|
277
278
|
const user = entry.composio_user_id;
|
|
278
279
|
const account = entry.connected_account_id;
|
|
279
280
|
if (typeof user !== "string" || !COMPOSIO_USER_ID.test(user))
|
|
280
|
-
issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message:
|
|
281
|
+
issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message: `composio_user_id is the Composio user this run's calls run as: ${COMPOSIO_USER_ID_WORDS}.` });
|
|
281
282
|
// The preset's default user is the one single-user preset servers call as: a run that forgot to name its own never lands there.
|
|
282
283
|
else if (user === COMPOSIO_USER)
|
|
283
284
|
issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is the Composio preset's shared default user, the one single-user preset servers call as: bind the run to its own person's Composio user." });
|
|
@@ -320,6 +321,8 @@ export async function listServer(url, headers, version, stop, send = fetch) {
|
|
|
320
321
|
for (let cursor, pages = 0;;) {
|
|
321
322
|
const page = await client.request({ method: "tools/list", ...(cursor !== undefined ? { params: { cursor } } : {}) }, { timeout: PREVIEW_MS, signal: deadline });
|
|
322
323
|
for (const tool of page.tools) {
|
|
324
|
+
if (reservedResourceName(tool.name))
|
|
325
|
+
throw invalid([{ field: "url", reason: "reserved", message: `The tool name ${tool.name} is reserved for AgentRun's resource operations.` }]);
|
|
323
326
|
const kept = {
|
|
324
327
|
name: tool.name,
|
|
325
328
|
...(tool.title ? { title: tool.title } : {}),
|
|
@@ -342,6 +345,8 @@ export async function listServer(url, headers, version, stop, send = fetch) {
|
|
|
342
345
|
cursor = page.nextCursor;
|
|
343
346
|
}
|
|
344
347
|
}
|
|
348
|
+
if (client.getServerCapabilities()?.resources)
|
|
349
|
+
tools.push(...resourceTools());
|
|
345
350
|
const instructions = client.getInstructions();
|
|
346
351
|
return {
|
|
347
352
|
protocol: client.getNegotiatedProtocolVersion() ?? "unknown",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const RESOURCE_OPERATIONS: readonly ["list", "templates", "read"];
|
|
2
|
+
export type ResourceOperation = typeof RESOURCE_OPERATIONS[number];
|
|
3
|
+
export declare const RESOURCE_NAMES: Record<ResourceOperation, string>;
|
|
4
|
+
export declare const RESOURCE_URI_MAX = 8192;
|
|
5
|
+
export declare const RESOURCE_LIST_MAX = 500;
|
|
6
|
+
export declare const RESOURCE_LIST_BYTES: number;
|
|
7
|
+
export declare const RESOURCE_PAGES_MAX = 64;
|
|
8
|
+
export declare const reservedResourceName: (name: string) => boolean;
|
|
9
|
+
export declare function resourceTools(): {
|
|
10
|
+
name: string;
|
|
11
|
+
resource: "read" | "templates" | "list";
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
input_schema: {
|
|
15
|
+
additionalProperties: boolean;
|
|
16
|
+
required?: string[] | undefined;
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
uri: {
|
|
20
|
+
type: string;
|
|
21
|
+
minLength: number;
|
|
22
|
+
maxLength: number;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
uri?: undefined;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
annotations: {
|
|
29
|
+
readOnlyHint: boolean;
|
|
30
|
+
destructiveHint: boolean;
|
|
31
|
+
idempotentHint: boolean;
|
|
32
|
+
openWorldHint: boolean;
|
|
33
|
+
};
|
|
34
|
+
}[];
|
|
35
|
+
/** A stored marker is accepted only with its exact operation name and bounded schema. Older ordinary tools without
|
|
36
|
+
* a marker remain ordinary tools; a name alone never turns tools/call into resources/read. */
|
|
37
|
+
export declare function resourceToolProblem(value: unknown): string | undefined;
|
|
38
|
+
export declare function resourceToolOperation(value: unknown): ResourceOperation | undefined;
|
|
39
|
+
type ResourceClient = {
|
|
40
|
+
request(input: unknown, options: unknown): Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
/** One bounded logical operation. Pagination belongs to this operation's deadline and fails if incomplete. */
|
|
43
|
+
export declare function resourceResult(client: ResourceClient, operation: ResourceOperation, args: Record<string, unknown>, signal: AbortSignal, timeout: number, clean: (text: string) => string): Promise<Record<string, unknown>>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Resource operations use the same per-server grants, revision pins, credentials and run gate as MCP tools.
|
|
2
|
+
// Only our probe creates these entries; an upstream tools/list entry never supplies the operation marker.
|
|
3
|
+
export const RESOURCE_OPERATIONS = ["list", "templates", "read"];
|
|
4
|
+
export const RESOURCE_NAMES = {
|
|
5
|
+
list: "agentrun_list_resources", templates: "agentrun_list_resource_templates", read: "agentrun_read_resource",
|
|
6
|
+
};
|
|
7
|
+
export const RESOURCE_URI_MAX = 8192;
|
|
8
|
+
export const RESOURCE_LIST_MAX = 500;
|
|
9
|
+
export const RESOURCE_LIST_BYTES = 1024 * 1024;
|
|
10
|
+
export const RESOURCE_PAGES_MAX = 64;
|
|
11
|
+
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
const keysAre = (value, keys) => Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
13
|
+
export const reservedResourceName = (name) => Object.values(RESOURCE_NAMES).includes(name);
|
|
14
|
+
export function resourceTools() {
|
|
15
|
+
return RESOURCE_OPERATIONS.map(resource => ({
|
|
16
|
+
name: RESOURCE_NAMES[resource], resource,
|
|
17
|
+
title: resource === "list" ? "List resources" : resource === "templates" ? "List resource templates" : "Read resource",
|
|
18
|
+
description: resource === "list" ? "List the resources available from this MCP server."
|
|
19
|
+
: resource === "templates" ? "List this MCP server's resource URI templates."
|
|
20
|
+
: "Read a resource URI from this MCP server. The URI is sent to the server, never fetched directly.",
|
|
21
|
+
input_schema: { type: "object", properties: resource === "read" ? { uri: { type: "string", minLength: 1, maxLength: RESOURCE_URI_MAX } } : {}, ...(resource === "read" ? { required: ["uri"] } : {}), additionalProperties: false },
|
|
22
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
/** A stored marker is accepted only with its exact operation name and bounded schema. Older ordinary tools without
|
|
26
|
+
* a marker remain ordinary tools; a name alone never turns tools/call into resources/read. */
|
|
27
|
+
export function resourceToolProblem(value) {
|
|
28
|
+
if (!object(value) || value.resource === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
const op = value.resource;
|
|
31
|
+
if (typeof op !== "string" || !RESOURCE_OPERATIONS.includes(op) || value.name !== RESOURCE_NAMES[op])
|
|
32
|
+
return "invalid resource operation marker";
|
|
33
|
+
const schema = value.inputSchema ?? value.input_schema;
|
|
34
|
+
const read = op === "read";
|
|
35
|
+
if (!object(schema) || !keysAre(schema, read ? ["type", "properties", "required", "additionalProperties"] : ["type", "properties", "additionalProperties"]) || schema.type !== "object" || schema.additionalProperties !== false || !object(schema.properties))
|
|
36
|
+
return "invalid resource operation schema";
|
|
37
|
+
if (!keysAre(schema.properties, read ? ["uri"] : []))
|
|
38
|
+
return "invalid resource operation arguments";
|
|
39
|
+
if (read) {
|
|
40
|
+
const uri = schema.properties.uri;
|
|
41
|
+
if (!object(uri) || !keysAre(uri, ["type", "minLength", "maxLength"]) || uri.type !== "string" || uri.minLength !== 1 || uri.maxLength !== RESOURCE_URI_MAX || !Array.isArray(schema.required) || schema.required.length !== 1 || schema.required[0] !== "uri")
|
|
42
|
+
return "invalid resource URI schema";
|
|
43
|
+
}
|
|
44
|
+
if (!object(value.annotations) || value.annotations.readOnlyHint !== true || value.annotations.destructiveHint !== false)
|
|
45
|
+
return "invalid resource operation effect";
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
export function resourceToolOperation(value) {
|
|
49
|
+
return object(value) && value.resource !== undefined && resourceToolProblem(value) === undefined ? value.resource : undefined;
|
|
50
|
+
}
|
|
51
|
+
/** One bounded logical operation. Pagination belongs to this operation's deadline and fails if incomplete. */
|
|
52
|
+
export async function resourceResult(client, operation, args, signal, timeout, clean) {
|
|
53
|
+
signal.throwIfAborted();
|
|
54
|
+
if (!keysAre(args, operation === "read" ? ["uri"] : []))
|
|
55
|
+
throw new Error("The resource operation has unexpected or missing arguments.");
|
|
56
|
+
if (operation === "read") {
|
|
57
|
+
if (typeof args.uri !== "string" || !args.uri.length || args.uri.length > RESOURCE_URI_MAX || /[\u0000-\u001f\u007f]/.test(args.uri))
|
|
58
|
+
throw new Error("A resource URI must be bounded text without control characters.");
|
|
59
|
+
const answer = await client.request({ method: "resources/read", params: { uri: args.uri } }, { signal, timeout });
|
|
60
|
+
if (!object(answer) || !Array.isArray(answer.contents) || answer.contents.length > RESOURCE_LIST_MAX || answer.contents.some(item => !object(item) || typeof item.uri !== "string" || (typeof item.text !== "string" && typeof item.blob !== "string")))
|
|
61
|
+
throw new Error("The MCP server returned invalid resource contents.");
|
|
62
|
+
for (const item of answer.contents)
|
|
63
|
+
if (typeof item.blob === "string") {
|
|
64
|
+
// The wire caps the whole response. Check the decoded binary too: a JSON-only scrub cannot see a token
|
|
65
|
+
// encoded inside a BlobResourceContents. Withhold it rather than corrupting arbitrary binary bytes.
|
|
66
|
+
const bytes = Buffer.from(item.blob, "base64");
|
|
67
|
+
if (bytes.toString("base64") !== item.blob)
|
|
68
|
+
throw new Error("The MCP server returned an invalid base64 resource.");
|
|
69
|
+
const decoded = bytes.toString("utf8");
|
|
70
|
+
if (clean(decoded) !== decoded)
|
|
71
|
+
throw new Error("The MCP resource contained a connection credential; its contents were withheld.");
|
|
72
|
+
}
|
|
73
|
+
return { content: answer.contents.map(resource => ({ type: "resource", resource })) };
|
|
74
|
+
}
|
|
75
|
+
const method = operation === "list" ? "resources/list" : "resources/templates/list";
|
|
76
|
+
const key = operation === "list" ? "resources" : "resourceTemplates";
|
|
77
|
+
const items = [], cursors = new Set();
|
|
78
|
+
let cursor, bytes = 0;
|
|
79
|
+
for (let pageNumber = 0; pageNumber < RESOURCE_PAGES_MAX; pageNumber++) {
|
|
80
|
+
signal.throwIfAborted();
|
|
81
|
+
const answer = await client.request({ method, ...(cursor === undefined ? {} : { params: { cursor } }) }, { signal, timeout });
|
|
82
|
+
if (!object(answer) || !Array.isArray(answer[key]))
|
|
83
|
+
throw new Error("The MCP server returned an invalid resource list.");
|
|
84
|
+
for (const item of answer[key]) {
|
|
85
|
+
if (!object(item) || typeof item.name !== "string" || typeof item[operation === "list" ? "uri" : "uriTemplate"] !== "string")
|
|
86
|
+
throw new Error("The MCP server returned an invalid resource entry.");
|
|
87
|
+
items.push(item);
|
|
88
|
+
bytes += Buffer.byteLength(JSON.stringify(item));
|
|
89
|
+
if (items.length > RESOURCE_LIST_MAX || bytes > RESOURCE_LIST_BYTES)
|
|
90
|
+
throw new Error("The MCP server's resource listing exceeds the item or byte limit; no incomplete listing was returned.");
|
|
91
|
+
}
|
|
92
|
+
if (answer.nextCursor === undefined)
|
|
93
|
+
return { structuredContent: { [key]: items } };
|
|
94
|
+
if (typeof answer.nextCursor !== "string" || answer.nextCursor.length > 4096 || cursors.has(answer.nextCursor))
|
|
95
|
+
throw new Error("The MCP server's resource cursor is invalid or repeats; no incomplete listing was returned.");
|
|
96
|
+
cursors.add(answer.nextCursor);
|
|
97
|
+
cursor = answer.nextCursor;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("The MCP server's resource list did not finish within the page limit.");
|
|
100
|
+
}
|
|
@@ -149,11 +149,11 @@ export declare class McpServersOverStore {
|
|
|
149
149
|
not_metered?: string[] | undefined;
|
|
150
150
|
tools: {
|
|
151
151
|
grant_problems?: Record<string, string>;
|
|
152
|
-
default_permission: "ask" | "
|
|
153
|
-
permissions: ("ask" | "
|
|
152
|
+
default_permission: "ask" | "deny" | "allow";
|
|
153
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
154
154
|
fallback_allow_reads?: true | undefined;
|
|
155
155
|
allow_reads?: true | undefined;
|
|
156
|
-
permission: "ask" | "
|
|
156
|
+
permission: "ask" | "deny" | "allow";
|
|
157
157
|
effect: import("./tool-gate.js").ToolEffect;
|
|
158
158
|
name: string;
|
|
159
159
|
title?: string;
|
|
@@ -161,6 +161,7 @@ export declare class McpServersOverStore {
|
|
|
161
161
|
input_schema: unknown;
|
|
162
162
|
output_schema?: unknown;
|
|
163
163
|
annotations?: unknown;
|
|
164
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
164
165
|
}[];
|
|
165
166
|
prices?: McpPrices | undefined;
|
|
166
167
|
instructions?: string | undefined;
|
|
@@ -190,11 +191,11 @@ export declare class McpServersOverStore {
|
|
|
190
191
|
not_metered?: string[] | undefined;
|
|
191
192
|
tools: {
|
|
192
193
|
grant_problems?: Record<string, string>;
|
|
193
|
-
default_permission: "ask" | "
|
|
194
|
-
permissions: ("ask" | "
|
|
194
|
+
default_permission: "ask" | "deny" | "allow";
|
|
195
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
195
196
|
fallback_allow_reads?: true | undefined;
|
|
196
197
|
allow_reads?: true | undefined;
|
|
197
|
-
permission: "ask" | "
|
|
198
|
+
permission: "ask" | "deny" | "allow";
|
|
198
199
|
effect: import("./tool-gate.js").ToolEffect;
|
|
199
200
|
name: string;
|
|
200
201
|
title?: string;
|
|
@@ -202,6 +203,7 @@ export declare class McpServersOverStore {
|
|
|
202
203
|
input_schema: unknown;
|
|
203
204
|
output_schema?: unknown;
|
|
204
205
|
annotations?: unknown;
|
|
206
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
205
207
|
}[];
|
|
206
208
|
prices?: McpPrices | undefined;
|
|
207
209
|
instructions?: string | undefined;
|
|
@@ -261,11 +263,11 @@ export declare class McpServersOverStore {
|
|
|
261
263
|
not_metered?: string[] | undefined;
|
|
262
264
|
tools: {
|
|
263
265
|
grant_problems?: Record<string, string>;
|
|
264
|
-
default_permission: "ask" | "
|
|
265
|
-
permissions: ("ask" | "
|
|
266
|
+
default_permission: "ask" | "deny" | "allow";
|
|
267
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
266
268
|
fallback_allow_reads?: true | undefined;
|
|
267
269
|
allow_reads?: true | undefined;
|
|
268
|
-
permission: "ask" | "
|
|
270
|
+
permission: "ask" | "deny" | "allow";
|
|
269
271
|
effect: import("./tool-gate.js").ToolEffect;
|
|
270
272
|
name: string;
|
|
271
273
|
title?: string;
|
|
@@ -273,6 +275,7 @@ export declare class McpServersOverStore {
|
|
|
273
275
|
input_schema: unknown;
|
|
274
276
|
output_schema?: unknown;
|
|
275
277
|
annotations?: unknown;
|
|
278
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
276
279
|
}[];
|
|
277
280
|
prices?: McpPrices | undefined;
|
|
278
281
|
instructions?: string | undefined;
|
|
@@ -306,11 +309,11 @@ export declare class McpServersOverStore {
|
|
|
306
309
|
not_metered?: string[] | undefined;
|
|
307
310
|
tools: {
|
|
308
311
|
grant_problems?: Record<string, string>;
|
|
309
|
-
default_permission: "ask" | "
|
|
310
|
-
permissions: ("ask" | "
|
|
312
|
+
default_permission: "ask" | "deny" | "allow";
|
|
313
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
311
314
|
fallback_allow_reads?: true | undefined;
|
|
312
315
|
allow_reads?: true | undefined;
|
|
313
|
-
permission: "ask" | "
|
|
316
|
+
permission: "ask" | "deny" | "allow";
|
|
314
317
|
effect: import("./tool-gate.js").ToolEffect;
|
|
315
318
|
name: string;
|
|
316
319
|
title?: string;
|
|
@@ -318,6 +321,7 @@ export declare class McpServersOverStore {
|
|
|
318
321
|
input_schema: unknown;
|
|
319
322
|
output_schema?: unknown;
|
|
320
323
|
annotations?: unknown;
|
|
324
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
321
325
|
}[];
|
|
322
326
|
prices?: McpPrices | undefined;
|
|
323
327
|
instructions?: string | undefined;
|
package/dist/model.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ import type { Revision } from "./agent-rows.js";
|
|
|
7
7
|
export declare const FAUX_ENV = "AGENTRUN_SERVE_FAUX";
|
|
8
8
|
/** Every test hook's name starts so (AGENTRUN_SERVE_FAUX, AGENTRUN_SERVE_FAUX_WEB, ...), but the harness table's
|
|
9
9
|
* (harness-table.ts HARNESS_TABLE_ENV), which withoutFaux drops by name, as it drops the resolved harness modules list
|
|
10
|
-
* (HARNESS_MODULES_ENV). */
|
|
10
|
+
* (HARNESS_MODULES_ENV) and recipes list (HARNESS_RECIPES_ENV). */
|
|
11
11
|
export declare const FAUX_PREFIX = "AGENTRUN_SERVE_FAUX";
|
|
12
|
-
/** `env` without a test hook's name or the resolved harness modules list: serve sets those from startServe's
|
|
13
|
-
* alone, so a name the server's own environment holds (an operator's export, a leftover) never gives its runs
|
|
14
|
-
* answers or
|
|
12
|
+
/** `env` without a test hook's name or the resolved harness modules or recipes list: serve sets those from startServe's
|
|
13
|
+
* options alone, so a name the server's own environment holds (an operator's export, a leftover) never gives its runs
|
|
14
|
+
* fake answers, loads a module or runs a recipe. */
|
|
15
15
|
export declare const withoutFaux: (env: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
|
|
16
16
|
/** Under `--faux` only: a module whose default export is the fetch the Anthropic and OpenAI providers send through (the
|
|
17
17
|
* tests' fake upstream), in place of their APIs. With it they are registered beside the faux model, for a tool's own
|
package/dist/model.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { isRouter, withLocalModels } from "./local-models.js";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
import { DEFAULT_HARNESS, PLAN_HARNESSES } from "./harness.js";
|
|
11
|
-
import { builtinHarness, factsOf, HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessIds, harnessOf } from "./harness-table.js";
|
|
11
|
+
import { builtinHarness, factsOf, HARNESS_MODULES_ENV, HARNESS_RECIPES_ENV, HARNESS_TABLE_ENV, harnessIds, harnessOf } from "./harness-table.js";
|
|
12
12
|
import { gatewayBase, modelGatewayBase } from "./provider.js";
|
|
13
13
|
import { modelFormWhy } from "./model-form.js";
|
|
14
14
|
// Leaves, which the key rows below read as this module loads, in any import order (wires.ts, adapter-facts.ts).
|
|
@@ -21,12 +21,12 @@ import { LOGIN_DEFAULT_MODEL, onClaudeLogin } from "./claude-login.js";
|
|
|
21
21
|
export const FAUX_ENV = "AGENTRUN_SERVE_FAUX";
|
|
22
22
|
/** Every test hook's name starts so (AGENTRUN_SERVE_FAUX, AGENTRUN_SERVE_FAUX_WEB, ...), but the harness table's
|
|
23
23
|
* (harness-table.ts HARNESS_TABLE_ENV), which withoutFaux drops by name, as it drops the resolved harness modules list
|
|
24
|
-
* (HARNESS_MODULES_ENV). */
|
|
24
|
+
* (HARNESS_MODULES_ENV) and recipes list (HARNESS_RECIPES_ENV). */
|
|
25
25
|
export const FAUX_PREFIX = "AGENTRUN_SERVE_FAUX";
|
|
26
|
-
/** `env` without a test hook's name or the resolved harness modules list: serve sets those from startServe's
|
|
27
|
-
* alone, so a name the server's own environment holds (an operator's export, a leftover) never gives its runs
|
|
28
|
-
* answers or
|
|
29
|
-
export const withoutFaux = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => !name.startsWith(FAUX_PREFIX) && name !== HARNESS_TABLE_ENV && name !== HARNESS_MODULES_ENV));
|
|
26
|
+
/** `env` without a test hook's name or the resolved harness modules or recipes list: serve sets those from startServe's
|
|
27
|
+
* options alone, so a name the server's own environment holds (an operator's export, a leftover) never gives its runs
|
|
28
|
+
* fake answers, loads a module or runs a recipe. */
|
|
29
|
+
export const withoutFaux = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => !name.startsWith(FAUX_PREFIX) && name !== HARNESS_TABLE_ENV && name !== HARNESS_MODULES_ENV && name !== HARNESS_RECIPES_ENV));
|
|
30
30
|
/** Under `--faux` only: a module whose default export is the fetch the Anthropic and OpenAI providers send through (the
|
|
31
31
|
* tests' fake upstream), in place of their APIs. With it they are registered beside the faux model, for a tool's own
|
|
32
32
|
* request to the provider the revision's model names (web_search's, hosted-search.ts); the run's turns stay faux. */
|
package/dist/native/cli.js
CHANGED
|
@@ -5,11 +5,13 @@ import { defaultData } from '../server-fs.js';
|
|
|
5
5
|
import { discoverNative } from './discovery.js';
|
|
6
6
|
import { nativeEnvironment } from './environment.js';
|
|
7
7
|
import { secret } from '../secrets.js';
|
|
8
|
+
import { selectedNative } from './connection.js';
|
|
9
|
+
import { sourceLocalConsent } from '../source-sync/local.js';
|
|
8
10
|
/** Source-machine handoff: discovery never launches a model; connection uses the existing local server credential.
|
|
9
11
|
* `usage`: the command's own line of the server's USAGE (cli.ts), which names every flag parsed here. */
|
|
10
12
|
export async function nativeMain(argv, usage) {
|
|
11
13
|
try {
|
|
12
|
-
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { project: { type: 'string' }, runtime: { type: 'string' }, agent: { type: 'string' }, profile: { type: 'string' }, url: { type: 'string' }, data: { type: 'string' } } });
|
|
14
|
+
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { project: { type: 'string' }, runtime: { type: 'string' }, agent: { type: 'string' }, profile: { type: 'string' }, url: { type: 'string' }, data: { type: 'string' }, 'no-sync': { type: 'boolean' } } });
|
|
13
15
|
const operation = positionals[0];
|
|
14
16
|
if (!values.project || !['discover', 'connect'].includes(operation ?? ''))
|
|
15
17
|
throw new Error(usage);
|
|
@@ -35,7 +37,12 @@ export async function nativeMain(argv, usage) {
|
|
|
35
37
|
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))
|
|
36
38
|
throw new Error('Run AgentRun on this source machine and connect to its loopback URL; hosted native pairing is not available yet.');
|
|
37
39
|
const token = secret('AGENTRUN_API_KEY') || secret('AGENTRUN_TOKEN') || (await readFile(join(data, '.token'), 'utf8')).trim();
|
|
38
|
-
const
|
|
40
|
+
const selection = { project: values.project, runtime: values.runtime, selector: values.agent ? { kind: 'agent', name: values.agent } : values.profile ? { kind: 'profile', name: values.profile } : { kind: 'project' } };
|
|
41
|
+
const env = nativeEnvironment();
|
|
42
|
+
const sourceSync = values['no-sync'] ? undefined : await sourceLocalConsent(await selectedNative(selection, env), env);
|
|
43
|
+
if (sourceSync)
|
|
44
|
+
console.error('Setup sync copies this selected project, instructions, authored skills and assets, supported tools/settings and bounded Git history to AgentRun. Credentials stay here; future source changes keep syncing. Use --no-sync to opt out.');
|
|
45
|
+
const response = await fetch(new URL('/v2/native/connect', url), { method: 'POST', headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' }, body: JSON.stringify({ ...selection, ...(sourceSync ? { source_sync: sourceSync } : {}) }) });
|
|
39
46
|
const body = await response.json();
|
|
40
47
|
if (!response.ok)
|
|
41
48
|
throw new Error(body.error?.message ?? `Connection failed (${response.status})`);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AgentEntry } from '../agents-store.js';
|
|
2
|
-
import type { Store } from '../store/store.js';
|
|
2
|
+
import type { Store, SettingsGuard } from '../store/store.js';
|
|
3
3
|
import type { NativeBinding, NativeTarget } from './types.js';
|
|
4
4
|
export declare function selectedNative(input: unknown, env?: NodeJS.ProcessEnv): Promise<NativeTarget>;
|
|
5
5
|
export declare function connectNative(store: Store, input: unknown, env?: NodeJS.ProcessEnv): Promise<AgentEntry>;
|
|
6
|
-
export declare function updateNative(store: Store, entry: AgentEntry, native: NativeBinding): Promise<AgentEntry>;
|
|
6
|
+
export declare function updateNative(store: Store, entry: AgentEntry, native: NativeBinding, settingsGuards?: readonly SettingsGuard[]): Promise<AgentEntry>;
|
|
7
7
|
export declare function verifyConnection(store: Store, entry: AgentEntry, env?: NodeJS.ProcessEnv): Promise<AgentEntry>;
|
|
8
8
|
export declare function launchNative(binding: NativeBinding, env?: NodeJS.ProcessEnv): Promise<NativeBinding>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sourceSyncOf } from "../source-sync/types.js";
|
|
1
2
|
import { nativeEnvironment } from "./environment.js";
|
|
2
3
|
import { basename } from 'node:path';
|
|
3
4
|
import { ApiError, invalid } from '../errors.js';
|
|
@@ -42,7 +43,9 @@ export async function connectNative(store, input, env = nativeEnvironment()) {
|
|
|
42
43
|
throw error;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
export async function updateNative(store, entry, native) {
|
|
46
|
+
export async function updateNative(store, entry, native, settingsGuards) {
|
|
47
|
+
if (sourceSyncOf(entry.revision?.body))
|
|
48
|
+
throw new ApiError("input_invalid", "This agent runs in AgentRun. Its source can sync setup, but reconnecting cannot take execution back.");
|
|
46
49
|
const before = definitionOf(entry.agent, entry.revision, entry.version);
|
|
47
50
|
const old = nativeOf(entry.revision?.body), execution = nativeExecutionOverrides(entry.revision?.body);
|
|
48
51
|
// Disconnect must remain possible, retaining these execution restrictions. Reconnect/conversion must never erase
|
|
@@ -59,7 +62,7 @@ export async function updateNative(store, entry, native) {
|
|
|
59
62
|
// on disconnect. Reconnect fills an absent legacy harness; managed conversion adopts the selected source harness.
|
|
60
63
|
const sourceHarness = native.runtime === 'claude-code' ? 'claude-agent' : 'codex';
|
|
61
64
|
const harness = old ? (entry.revision.body.harness ?? (native.connected ? sourceHarness : undefined)) : sourceHarness;
|
|
62
|
-
return commitAgent(store, entry, { definition: { ...definition, ...(harness ? { harness } : {}), native } }, { ifCurrent: entry.revision?.id ?? null });
|
|
65
|
+
return commitAgent(store, entry, { definition: { ...definition, ...(harness ? { harness } : {}), native } }, { ifCurrent: entry.revision?.id ?? null, ...(settingsGuards ? { settingsGuards } : {}) });
|
|
63
66
|
}
|
|
64
67
|
export async function verifyConnection(store, entry, env = nativeEnvironment()) {
|
|
65
68
|
const before = nativeOf(entry.revision?.body);
|
|
@@ -12,6 +12,8 @@ export declare function nativeMetadata(binary: string, args: string[], cwd: stri
|
|
|
12
12
|
stdout: string;
|
|
13
13
|
}>;
|
|
14
14
|
export declare function nativeIdentity(target: Pick<NativeTarget, "runtime" | "project" | "selector" | "machine_id">): string;
|
|
15
|
+
/** The existing native machine identity, shared with explicit source-consent checks before any source scan. */
|
|
16
|
+
export declare function nativeMachineId(): Promise<string>;
|
|
15
17
|
export declare function discoverNative(options: {
|
|
16
18
|
project: string;
|
|
17
19
|
runtime?: NativeRuntime;
|
package/dist/native/discovery.js
CHANGED
|
@@ -69,6 +69,15 @@ export async function nativeMetadata(binary, args, cwd, env, timeoutMs = 5_000)
|
|
|
69
69
|
export function nativeIdentity(target) {
|
|
70
70
|
return hash(JSON.stringify([target.runtime, target.project, target.selector.kind, target.selector.name ?? null, target.machine_id]));
|
|
71
71
|
}
|
|
72
|
+
/** The existing native machine identity, shared with explicit source-consent checks before any source scan. */
|
|
73
|
+
export async function nativeMachineId() {
|
|
74
|
+
let machine = hostname();
|
|
75
|
+
try {
|
|
76
|
+
machine = (await readFile("/etc/machine-id", "utf8")).trim();
|
|
77
|
+
}
|
|
78
|
+
catch { /* hostname fallback */ }
|
|
79
|
+
return hash(machine);
|
|
80
|
+
}
|
|
72
81
|
export async function discoverNative(options) {
|
|
73
82
|
const env = options.env ?? process.env, home = homeOf(env);
|
|
74
83
|
let project;
|
|
@@ -80,12 +89,7 @@ export async function discoverNative(options) {
|
|
|
80
89
|
catch {
|
|
81
90
|
throw new NativeDiscoveryError();
|
|
82
91
|
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
machine = (await readFile("/etc/machine-id", "utf8")).trim();
|
|
86
|
-
}
|
|
87
|
-
catch { /* hostname fallback */ }
|
|
88
|
-
const machine_id = hash(machine), targets = [];
|
|
92
|
+
const machine_id = await nativeMachineId(), targets = [];
|
|
89
93
|
for (const runtime of options.runtime ? [options.runtime] : NATIVE_RUNTIMES) {
|
|
90
94
|
const binary = await nativeExecutable(runtime, env);
|
|
91
95
|
const versionResult = binary ? await nativeMetadata(binary, ["--version"], project, env) : null;
|
|
@@ -10,6 +10,8 @@ import { discoverNative, nativeIdentity, verifyNative } from './discovery.js';
|
|
|
10
10
|
import { nativeEnvironment } from './environment.js';
|
|
11
11
|
import { openNativeSession } from './runtime.js';
|
|
12
12
|
import { snapshotNativeInstructions } from './instructions.js';
|
|
13
|
+
import { exportSourceSnapshot, SourceSnapshotError } from './source-snapshot.js';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
13
15
|
import { exportRemoteHistory } from '../import.js';
|
|
14
16
|
import { runnerSecrets, secretRedactor } from '../runner/redact.js';
|
|
15
17
|
import { redactedOutput } from '../key-refusal.js';
|
|
@@ -70,10 +72,15 @@ export async function runRemoteWorkerBridge(options = {}) {
|
|
|
70
72
|
const output = (value) => {
|
|
71
73
|
// These identities are generated by the connector, not native payload text. Redacting
|
|
72
74
|
// a serialized JSON line can erase them (or its braces) when a payload has a long atom.
|
|
73
|
-
|
|
75
|
+
// Export refuses secret-bearing content before digesting it. A second redaction pass would silently
|
|
76
|
+
// change authored bytes or content hashes; only this typed, local-only export can use its exact result.
|
|
77
|
+
const safe = 'result' in value ? { id: value.id, result: value.exactSnapshot ?? payload(value.result) }
|
|
74
78
|
: 'event' in value ? { session_key: value.session_key, event: payload(value.event) }
|
|
75
|
-
: { ...(value.id === undefined ? {} : { id: value.id }), error: redact(value.error) };
|
|
76
|
-
|
|
79
|
+
: { ...(value.id === undefined ? {} : { id: value.id }), error: redact(value.error), ...(value.code ? { code: value.code } : {}) };
|
|
80
|
+
const line = JSON.stringify(safe) + '\n';
|
|
81
|
+
if ('exactSnapshot' in value && value.exactSnapshot && Buffer.byteLength(line) > 128 * 1024 * 1024)
|
|
82
|
+
throw new SourceSnapshotError('limit', 'The complete source snapshot exceeds its transport limit; nothing was truncated.');
|
|
83
|
+
return process.stdout.write(line);
|
|
77
84
|
};
|
|
78
85
|
const close = async (sessionKey) => {
|
|
79
86
|
const held = sessions.get(sessionKey);
|
|
@@ -115,6 +122,25 @@ export async function runRemoteWorkerBridge(options = {}) {
|
|
|
115
122
|
const payload = message.payload === undefined ? {} : object(message.payload), type = message.type;
|
|
116
123
|
if (type === 'discover')
|
|
117
124
|
return discoverNative({ project: text(payload.project, 4096), ...(payload.runtime ? { runtime: runtime(payload.runtime) } : {}), env });
|
|
125
|
+
if (type === 'source-snapshot') {
|
|
126
|
+
// Only a local connector action can send this type; remote command dispatch never admits it.
|
|
127
|
+
const chosen = targetOf(message.target);
|
|
128
|
+
if (!Array.isArray(payload.authorized_roots) || !payload.authorized_roots.length || payload.authorized_roots.length > 32)
|
|
129
|
+
throw new Error('Source export needs locally approved source roots. Enable sync on the source machine.');
|
|
130
|
+
// Private local IPC, never an accepted network command. The connector holds a scoped credential
|
|
131
|
+
// outside this process's environment; include it in refusal without echoing it or rewriting bytes.
|
|
132
|
+
const held = payload.secret_values === undefined ? [] : payload.secret_values;
|
|
133
|
+
if (!Array.isArray(held) || held.length > 16 || held.some(value => typeof value !== 'string' || !value.length || Buffer.byteLength(value) > 8192)
|
|
134
|
+
|| held.reduce((bytes, value) => bytes + Buffer.byteLength(value), 0) > 64 * 1024)
|
|
135
|
+
throw new Error('Invalid local held-value envelope.');
|
|
136
|
+
const report = await discoverNative({ project: chosen.project, runtime: chosen.runtime, env });
|
|
137
|
+
const found = report.targets.find(target => nativeIdentity(target) === nativeIdentity(chosen));
|
|
138
|
+
if (!found)
|
|
139
|
+
throw new Error('The locally approved source target changed; discover it again.');
|
|
140
|
+
return exportSourceSnapshot({ target: found, authorizedRoots: payload.authorized_roots.map(root => text(root, 4096)),
|
|
141
|
+
home: env.HOME || homedir(), ...(env.CODEX_HOME ? { codexHome: env.CODEX_HOME } : {}),
|
|
142
|
+
...(env.CLAUDE_CONFIG_DIR ? { claudeHome: env.CLAUDE_CONFIG_DIR } : {}), secretValues: [...secrets, ...held], environment: env, signal });
|
|
143
|
+
}
|
|
118
144
|
// Local connector action only: the Python network worker never dispatches these operations.
|
|
119
145
|
if (type === 'history-preview' || type === 'history-export') {
|
|
120
146
|
const target = targetOf(message.target);
|
|
@@ -223,7 +249,13 @@ export async function runRemoteWorkerBridge(options = {}) {
|
|
|
223
249
|
}
|
|
224
250
|
const abort = new AbortController();
|
|
225
251
|
operations.set(id, abort);
|
|
226
|
-
const task = dispatch(message, abort.signal).then(result => { output({ id, result
|
|
252
|
+
const task = dispatch(message, abort.signal).then(result => { output({ id, result, ...(message.type === 'source-snapshot' ? { exactSnapshot: result } : {}) }); })
|
|
253
|
+
.catch(error => { if (message.type === 'source-snapshot') {
|
|
254
|
+
const code = error instanceof SourceSnapshotError ? (error.code === 'limit' ? 'snapshot_too_large' : error.code) : 'source_unavailable';
|
|
255
|
+
output({ id, error: 'The approved source snapshot could not be captured.', code });
|
|
256
|
+
}
|
|
257
|
+
else
|
|
258
|
+
output({ id, error: error instanceof Error ? error.message : 'Native operation failed.' }); }).finally(() => { operations.delete(id); pending.delete(task); });
|
|
227
259
|
pending.add(task);
|
|
228
260
|
}
|
|
229
261
|
await shutdown();
|
package/dist/native/remote.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/** Outbound connector transport. Credentials are scoped to one source; commands use source-approved opaque targets.
|
|
2
|
+
* The ordinary runner owns runs, journals and learning. A leased command is NEVER dispatched again after uncertainty.
|
|
3
|
+
* CAS settings rows keep this contract across API/runner processes and restarts without a second run registry. */
|
|
4
|
+
import type { AdoptionResolver } from "../source-sync/adoption.js";
|
|
5
|
+
import { type SourceAuthority } from "../source-sync/registry.js";
|
|
1
6
|
import { type AgentEntry } from '../agents-store.js';
|
|
2
7
|
import type { Store } from '../store/store.js';
|
|
3
8
|
import type { NativeBinding, NativeEvent, NativeResult, NativeSession } from './types.js';
|
|
@@ -7,6 +12,8 @@ export type RemoteCommandType = 'prepare' | 'open' | 'send' | 'close';
|
|
|
7
12
|
export declare class RemoteConnectors {
|
|
8
13
|
readonly store: Store;
|
|
9
14
|
readonly now: () => number;
|
|
15
|
+
/** One HTTP request's authenticated epoch. Reading its body can await a concurrent owner rotation. */
|
|
16
|
+
private authenticated?;
|
|
10
17
|
constructor(store: Store, now?: () => number);
|
|
11
18
|
private connector;
|
|
12
19
|
private targets;
|
|
@@ -23,12 +30,14 @@ export declare class RemoteConnectors {
|
|
|
23
30
|
observe: boolean;
|
|
24
31
|
native_execution: boolean;
|
|
25
32
|
history_import: boolean;
|
|
33
|
+
config_sync: boolean;
|
|
26
34
|
};
|
|
27
35
|
targets: {
|
|
28
36
|
target_id: string;
|
|
29
37
|
agent_id: string;
|
|
30
38
|
name: string;
|
|
31
39
|
history_only: boolean;
|
|
40
|
+
sync_only: boolean;
|
|
32
41
|
runtime: "codex" | "claude-code";
|
|
33
42
|
machine_id: string;
|
|
34
43
|
state: "ready" | "needs_verification" | "needs_attention";
|
|
@@ -60,12 +69,14 @@ export declare class RemoteConnectors {
|
|
|
60
69
|
observe: boolean;
|
|
61
70
|
native_execution: boolean;
|
|
62
71
|
history_import: boolean;
|
|
72
|
+
config_sync: boolean;
|
|
63
73
|
};
|
|
64
74
|
targets: {
|
|
65
75
|
target_id: string;
|
|
66
76
|
agent_id: string;
|
|
67
77
|
name: string;
|
|
68
78
|
history_only: boolean;
|
|
79
|
+
sync_only: boolean;
|
|
69
80
|
runtime: "codex" | "claude-code";
|
|
70
81
|
machine_id: string;
|
|
71
82
|
state: "ready" | "needs_verification" | "needs_attention";
|
|
@@ -95,12 +106,14 @@ export declare class RemoteConnectors {
|
|
|
95
106
|
observe: boolean;
|
|
96
107
|
native_execution: boolean;
|
|
97
108
|
history_import: boolean;
|
|
109
|
+
config_sync: boolean;
|
|
98
110
|
};
|
|
99
111
|
targets: {
|
|
100
112
|
target_id: string;
|
|
101
113
|
agent_id: string;
|
|
102
114
|
name: string;
|
|
103
115
|
history_only: boolean;
|
|
116
|
+
sync_only: boolean;
|
|
104
117
|
runtime: "codex" | "claude-code";
|
|
105
118
|
machine_id: string;
|
|
106
119
|
state: "ready" | "needs_verification" | "needs_attention";
|
|
@@ -117,10 +130,14 @@ export declare class RemoteConnectors {
|
|
|
117
130
|
}>;
|
|
118
131
|
assertReady(binding: NativeBinding): Promise<void>;
|
|
119
132
|
status(binding: NativeBinding): Promise<NativeBinding>;
|
|
120
|
-
importTarget(id: string, input: unknown): Promise<{
|
|
133
|
+
importTarget(id: string, input: unknown, resolveAdoption?: AdoptionResolver): Promise<{
|
|
121
134
|
agent_id: string;
|
|
122
135
|
native: NativeBinding;
|
|
123
136
|
}>;
|
|
137
|
+
syncAuthority(id: string, targetId: string): Promise<{
|
|
138
|
+
agentId: string;
|
|
139
|
+
authority: SourceAuthority;
|
|
140
|
+
}>;
|
|
124
141
|
disconnectTarget(binding: NativeBinding): Promise<void>;
|
|
125
142
|
importHistory(id: string, targetId: string, input: unknown, own?: readonly string[]): Promise<{
|
|
126
143
|
agent_id: string;
|