@parcha/agentrun-serve 0.1.0-beta.53 → 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 +29 -2
- package/README.md +82 -13
- package/dist/agent-package.js +1 -1
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +1 -1
- package/dist/api-only.d.ts +1 -2
- package/dist/api-only.js +1 -2
- package/dist/cli.js +6 -1
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +4 -3
- package/dist/computer-needs.d.ts +1 -1
- package/dist/computer-needs.js +1 -1
- package/dist/computer-setting.d.ts +4 -2
- 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/errors.d.ts +4 -0
- package/dist/errors.js +7 -0
- 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/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/mcp-probe.js +2 -2
- package/dist/openapi.js +108 -4
- package/dist/runner/adapter-run-spec.js +1 -1
- package/dist/runner/cli-run-spec.js +1 -1
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +15 -3
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/run-child-host.js +7 -4
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +23 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.js +80 -10
- package/dist/store/agent-body.d.ts +2 -2
- package/dist/store/agent-body.js +2 -2
- 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 +17 -0
- package/dist/template-import.js +32 -0
- package/dist/templates.d.ts +78 -73
- package/dist/templates.js +10 -8
- package/dist/trigger-launch-hook.d.ts +5 -3
- package/dist/trigger-launch-hook.js +5 -4
- package/dist/triggers.js +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +2 -2
- 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/templates/README.md +3 -2
- 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-BFgyZzF_.js +0 -734
- package/dist/console/assets/index-DbilxljH.css +0 -1
package/dist/openapi.js
CHANGED
|
@@ -1093,7 +1093,10 @@ const COMPUTERS_VIEW = closed({
|
|
|
1093
1093
|
tools: { type: "array", items: { type: "string" }, description: "The model's tools the kind brings, by name." },
|
|
1094
1094
|
settings: { type: "array", items: { type: "string" }, description: "The fields an agent's computer of this kind may set beside its kind and provider; none for kind none. Whether a provider offers a value is its own (images, persistent, gpu)." },
|
|
1095
1095
|
record: {
|
|
1096
|
-
|
|
1096
|
+
oneOf: [
|
|
1097
|
+
closed({ available: { type: "boolean", const: true, description: "An agent's computer of this kind may set `record: true` here: the kind records (a desktop, a phone or a browser) and this server has ffmpeg on its PATH, read at each call." } }),
|
|
1098
|
+
closed({ available: { type: "boolean", const: false, description: "An agent's computer of this kind may not set `record: true` here." }, why: { type: "string", description: "Why not, in plain words: the kind has no screen to record, or this server has no ffmpeg." } }),
|
|
1099
|
+
],
|
|
1097
1100
|
description: "Whether a run of this kind can record a video of its screen on this server (an agent's `computer.record`), and why not.",
|
|
1098
1101
|
},
|
|
1099
1102
|
providers: { type: "array", items: COMPUTER_PROVIDER, description: "The providers that serve the kind." },
|
|
@@ -1298,6 +1301,44 @@ const GITHUB_CONNECTION = closed({ connected: { const: true }, app_id: { type: "
|
|
|
1298
1301
|
/** GET /integrations/github: whether a GitHub App is connected, always a 200 (not connected is an answer, never a 404 a
|
|
1299
1302
|
* browser logs as an error), and the App when it is. */
|
|
1300
1303
|
const GITHUB_STATUS = { oneOf: [closed({ connected: { const: false } }, "No GitHub App is connected to this server: Connect GitHub in Settings."), GITHUB_CONNECTION] };
|
|
1304
|
+
/** Suggested agents (suggestions.ts): their routes and answers. */
|
|
1305
|
+
const SUGGESTIONS_MARK = { "x-agentrun-serve": "suggestions/1" };
|
|
1306
|
+
const SUGGESTION_ID = { name: "suggestion_id", in: "path", required: true, schema: { type: "string", pattern: "^sg_[0-9a-f]{20}$" }, description: "A suggestion's id: the same repository and key always give the same one." };
|
|
1307
|
+
const SUGGESTED_LINE = closed({ path: { type: "string", description: "From the repository's root." }, line: { type: "integer", minimum: 1 }, quote: { type: "string", description: "That line, as the scan read it." }, url: { type: "string", format: "uri", description: "The line on GitHub, at the commit the scan read." } });
|
|
1308
|
+
const SUGGESTED_INPUT = closed({ name: { type: "string" }, type: { enum: ["string", "number", "integer", "boolean"] }, description: { type: "string" }, required: { type: "boolean" } });
|
|
1309
|
+
const SUGGESTED_OUTPUT = closedWith({ name: { type: "string" }, type: { enum: ["string", "number", "integer", "boolean", "string_list"] }, description: { type: "string" } }, { enum: { type: "array", items: { type: "string" }, description: "The values a choice the app branches on takes." } });
|
|
1310
|
+
const SUGGESTION = closed({
|
|
1311
|
+
id: { type: "string" },
|
|
1312
|
+
repo: { type: "string", description: "owner/name" },
|
|
1313
|
+
key: { type: "string", description: "The job's kebab-case name: the created agent's package name, its folder `.agentrun/agents/<key>` and its branch `agentrun/<key>`." },
|
|
1314
|
+
status: { enum: ["open", "created", "discarded"] },
|
|
1315
|
+
title: { type: "string" }, summary: { type: "string" }, why: { type: "string" }, impact: { enum: ["high", "medium", "low"] },
|
|
1316
|
+
evidence: { type: "array", items: SUGGESTED_LINE },
|
|
1317
|
+
agent: closedWith({ name: { type: "string" }, description: { type: "string" }, inputs: { type: "array", items: SUGGESTED_INPUT }, output: { type: "array", items: SUGGESTED_OUTPUT }, tools: { type: "array", items: { enum: ["web_search", "web_fetch"] } }, tier: { enum: ["fast", "balanced", "strong"] } }, { instructions: { type: "string", description: "The agent's instructions: on GET /suggestions/{suggestion_id} alone." } }),
|
|
1318
|
+
integration: closed({ language: { enum: ["typescript", "javascript", "python", "other"] }, path: { type: "string", description: "The client file the pull request adds." }, call_site: closed({ path: { type: "string" }, line: { type: "integer", minimum: 1 }, note: { type: "string" }, url: { type: "string", format: "uri" } }) }),
|
|
1319
|
+
scan: closed({ run_id: { type: "string" }, commit: { type: ["string", "null"] }, at: { type: "string", format: "date-time" } }),
|
|
1320
|
+
decided_at: { type: ["string", "null"], format: "date-time" },
|
|
1321
|
+
created: { oneOf: [{ type: "null" }, closed({ agent_id: { type: "string" }, template_id: { type: "string", description: "The imported template the agent was applied from: github:<owner>/<repo>/.agentrun/agents/<key>." }, branch: { type: ["string", "null"] }, pull_request: { oneOf: [{ type: "null" }, closed({ number: { type: "integer" }, url: { type: "string", format: "uri" } })] }, pull_error: { type: ["string", "null"], description: "Why the pull request was not opened though the agent was made: a create sent again opens it." } })] },
|
|
1322
|
+
});
|
|
1323
|
+
const SUGGESTION_READINESS = closed({
|
|
1324
|
+
ready: { type: "boolean", description: "Whether this server's GitHub App can open the pull request now, as GitHub says." },
|
|
1325
|
+
reason: { enum: [null, "not_connected", "not_installed", "github_failed", "permission_missing"] },
|
|
1326
|
+
message: { type: ["string", "null"] },
|
|
1327
|
+
missing: { type: "array", items: { type: "string" }, description: "The permissions the installation lacks, as `contents: write`." },
|
|
1328
|
+
install_url: { type: ["string", "null"], format: "uri", description: "Where the App is installed on more repositories." },
|
|
1329
|
+
permissions_url: { type: ["string", "null"], format: "uri", description: "The App's permissions page on GitHub, where its owner adds what is missing." },
|
|
1330
|
+
installation_url: { type: ["string", "null"], format: "uri", description: "The installation's page, where its account accepts new permissions." },
|
|
1331
|
+
});
|
|
1332
|
+
const SUGGESTION_WHOLE = { ...SUGGESTION, required: [...SUGGESTION.required, "files", "problems", "github"], properties: { ...SUGGESTION.properties, files: { type: "array", items: closed({ path: { type: "string" }, content: { type: "string" } }), description: "The files a create adds to the repository, rendered now." }, problems: { type: "array", items: { type: "string" }, description: "Why the package would not check (a create is refused); empty when it checks." }, github: SUGGESTION_READINESS } };
|
|
1333
|
+
const SUGGESTIONS_LIST = closed({
|
|
1334
|
+
github: closed({ connected: { type: "boolean" }, app: { type: ["string", "null"] }, installations: { type: "array", items: closed({ account: { type: "string" } }) }, install_url: { type: ["string", "null"], format: "uri" } }),
|
|
1335
|
+
repositories: { type: "array", items: closed({
|
|
1336
|
+
repo: { type: "string" },
|
|
1337
|
+
scan: closed({ run_id: { type: "string" }, agent_id: { type: "string" }, started_at: { type: "string", format: "date-time" }, status: { enum: ["running", "waiting", "completed", "failed", "cancelled"], description: "`waiting`: the scan's run stopped without ending (at its cost cap or asking for input, `input_required`, or paused): it is resumed or cancelled on its run's page, and a new scan starts a new run." }, ended_at: { type: ["string", "null"], format: "date-time" }, app: { type: ["string", "null"], description: "What the scan says the app does." }, commit: { type: ["string", "null"] }, found: { type: ["integer", "null"] }, dropped: { type: "array", items: { type: "string" }, description: "Each suggestion of the answer that did not check, and why." }, already_decided: { type: "integer", description: "Suggestions of the answer left out because a person had decided them." }, error: { type: ["string", "null"] } }),
|
|
1338
|
+
counts: closed({ open: { type: "integer" }, created: { type: "integer" }, discarded: { type: "integer" } }),
|
|
1339
|
+
}) },
|
|
1340
|
+
suggestions: { type: "array", items: SUGGESTION },
|
|
1341
|
+
});
|
|
1301
1342
|
/** templates/1: template packages, listed and applied (templates.ts; the format is templates/README.md). */
|
|
1302
1343
|
const TEMPLATE_MARK = { "x-agentrun-serve": "templates/1" };
|
|
1303
1344
|
/** template-computer/1: a package's computer preference list, and what this server would pick of it. */
|
|
@@ -1342,7 +1383,7 @@ const TEMPLATE = closed({
|
|
|
1342
1383
|
},
|
|
1343
1384
|
effort: { type: ["string", "null"], description: "Its thinking level, the definition's `thinking`." },
|
|
1344
1385
|
tools: { type: ["array", "null"], items: { type: "string" }, description: "The tools its agent is granted; null: those a new agent gets." },
|
|
1345
|
-
checkout: { enum: ["pull_request", null], description: "What the server checks out in each run's folder before its first turn, set as the agent definition's `checkout` at apply: `pull_request`, the pull request the run's GitHub event names, at its head, in `repo
|
|
1386
|
+
checkout: { enum: ["pull_request", "repository", null], description: "What the server checks out in each run's folder before its first turn, set as the agent definition's `checkout` at apply: `pull_request`, the pull request the run's GitHub event names, at its head, in `repo/`; `repository`, the head of the default branch of the repository the run names; each fetched with a read-only token the agent never holds. Null: none." },
|
|
1346
1387
|
tool_policy: { type: ["object", "null"], additionalProperties: false, required: ["bash"], properties: { bash: BASH_POLICY }, description: "A policy by tool, bash's alone: apply writes it as the tool's policy in the agent's tool_settings, so the tool gate refuses any command it does not allow, whatever bash's permission. Null: none.", "x-agentrun-serve": "bash-policy/1" },
|
|
1347
1388
|
computer: { type: ["array", "null"], items: { enum: [...COMPUTER_ENTRIES] }, description: "The computers it prefers, in order: `shell`, a computer that gives the agent a shell here (Docker's sandbox, or Archil's serverless exec on the runner in Mode 2); `none`, no shell. Apply takes the first this server meets now and writes it as the agent's `computer`; with `none`, the shell tools in `tools` are not granted, said in a `computer` warning. Null: where this server puts a new agent.", ...TEMPLATE_COMPUTER_MARK },
|
|
1348
1389
|
needs: { ...NEEDS, type: ["array", "null"], description: "The programs its agent's sandbox must have on its PATH, or the libraries its code loads by their pip or npm names (`python-pptx`, `pptxgenjs`) (the manifest's `needs`, read only beside `computer: [shell]`). Apply writes them onto the sandbox it picks as the agent's `computer.needs`, which each run checks in its box before its first model request; where the shell here is no sandbox (Archil's serverless exec, or none), apply is refused (409) in words naming them and `AGENTRUN_DOCKER_IMAGE`. They name no image: a Docker box's is the server's `AGENTRUN_DOCKER_IMAGE`. Null: none.", "x-agentrun-serve": "template-needs/1" },
|
|
@@ -2896,7 +2937,7 @@ const EXTENSIONS = {
|
|
|
2896
2937
|
post: {
|
|
2897
2938
|
operationId: "connectGitHub", tags: ["local"], summary: "Start Connect GitHub: the app-manifest form the console posts to GitHub",
|
|
2898
2939
|
description: "GitHub's app-manifest flow, which makes the server's one GitHub App. Answers the form the console auto-submits: `action` (GitHub's new-App page, under `org` when given, with `state` on it) and `manifest` (a field of that form, as JSON): a name GitHub lets the person edit, the server's public URL, its hook `/v2/hooks/github`, its callback and its setup URL, the App's permissions (pull requests write, contents, metadata and issues read) and events (pull_request, issue_comment, release). `state` is random, used once, good for an hour, and bound to the browser that started it by a cookie on the callback's path; GitHub reads it from `action`'s URL, and the form posts only `manifest`. 409 github_no_public_url (\"GitHub can't reach this server: set its public URL first\") with no public URL (AGENTRUN_PUBLIC_URL); 409 github_already_connected (\"This server already has a GitHub App. Disconnect it first.\"); 409 github_wrong_origin (\"Open this server at <public URL> to connect GitHub.\", `details.public_url` that URL, for the console's link) when the request came to another address than the public URL, where GitHub sends the browser back: nothing is started.",
|
|
2899
|
-
requestBody: { required: false, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { org: { type: "string", pattern: "^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$", description: "The GitHub organization to make the App under; absent, the signed-in GitHub user." } } } } } },
|
|
2940
|
+
requestBody: { required: false, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { org: { type: "string", pattern: "^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$", description: "The GitHub organization to make the App under; absent, the signed-in GitHub user." }, contents: { enum: ["read", "write"], description: "The App's Contents permission: read (the default), or write, which suggested agents' pull requests need (they add files on a new branch). Nothing else is widened.", "x-agentrun-serve": "suggestions/1" } } } } } },
|
|
2900
2941
|
responses: { "200": json(closed({ action: { type: "string", format: "uri" }, manifest: { type: "object", description: "GitHub's app manifest, posted as the form's `manifest` field." }, state: { type: "string" } }), "The form to post to GitHub."), ...errors(400, 401, 403, 409, 415, 422, 429, 500) },
|
|
2901
2942
|
...GITHUB_MARK,
|
|
2902
2943
|
"x-agentrun-browser-only": "Its state is bound by a cookie to the browser that posts the form to GitHub, which sends that browser back to the callback: Connect GitHub runs in the console.",
|
|
@@ -2922,6 +2963,69 @@ const EXTENSIONS = {
|
|
|
2922
2963
|
"x-agentrun-browser-only": "GitHub sends the browser here once the App is installed; it takes no token, and it checks the cookie the callback set in that browser.",
|
|
2923
2964
|
},
|
|
2924
2965
|
},
|
|
2966
|
+
"/integrations/github/repositories": {
|
|
2967
|
+
get: {
|
|
2968
|
+
operationId: "listGitHubRepositories", tags: ["local"], summary: "The repositories this server's GitHub App is installed on",
|
|
2969
|
+
description: "Each installation's repositories, as GitHub lists them now (GET /installation/repositories with a token of that installation holding metadata read alone, revoked after), sorted by name, at most 500 (`truncated` past that). An installation GitHub did not list is in `unread` with why. 409 github_not_connected with no App.",
|
|
2970
|
+
responses: { "200": json(closed({ repositories: { type: "array", items: closedWith({ full_name: { type: "string" }, private: { type: "boolean" }, account: { type: "string" }, installation: { type: "integer" } }, { default_branch: { type: "string" }, description: { type: "string" } }) }, truncated: { type: "boolean" }, unread: { type: "array", items: closed({ account: { type: "string" }, why: { type: "string" } }) } }), "The repositories."), ...errors(401, 409, 429, 500) },
|
|
2971
|
+
...SUGGESTIONS_MARK,
|
|
2972
|
+
},
|
|
2973
|
+
},
|
|
2974
|
+
"/suggestions": {
|
|
2975
|
+
get: {
|
|
2976
|
+
operationId: "listSuggestions", tags: ["local"], summary: "Suggested agents: each repository's scan and the agents it suggests",
|
|
2977
|
+
description: "Whether GitHub is connected, each repository scanned (its newest scan: running, or what was read of its answer), and its suggestions: open and created by default (`status` picks open, created, discarded or all), open first, then by impact. A scan that ended is read here once: each suggestion of the agent-scout's answer is checked field by field (a path inside the repository, a client path its language's and outside `.github/`, typed inputs and answer), and one that does not check is dropped and listed with why. A newer scan replaces the open suggestions of the one before; a decided one (created or discarded) stays as decided, and the next scan is told not to suggest it again.",
|
|
2978
|
+
parameters: [{ name: "repo", in: "query", required: false, schema: { type: "string" }, description: "owner/name: one repository's alone." }, { name: "status", in: "query", required: false, schema: { enum: ["open", "created", "discarded", "all"] } }],
|
|
2979
|
+
responses: { "200": json(SUGGESTIONS_LIST, "Suggested agents."), ...errors(401, 422, 429, 500) },
|
|
2980
|
+
...SUGGESTIONS_MARK,
|
|
2981
|
+
},
|
|
2982
|
+
},
|
|
2983
|
+
"/suggestions/scans": {
|
|
2984
|
+
post: {
|
|
2985
|
+
operationId: "scanForSuggestions", tags: ["local"], summary: "Scan a repository for places its app needs an agent",
|
|
2986
|
+
description: "Starts a run of the bundled agent-scout template's agent (applied here the first time, then reused) on `repo`: the server checks the head of its default branch out read-only in the run's folder (`checkout: repository`, with the GitHub App's contents-read token, or anonymously), and the run answers at most five suggestions. Its first message lists the suggestions already decided on the repository, so none comes back. 202 with the run; 200 with the scan still running, when one is. The repository's scan is reserved in the store before the run starts, on every server sharing it: a second scan sent while one is starting is 409 home_busy (retryable), and starts nothing. What the apply or the start refuses is the answer (409 agent_not_runnable with no model key, say), and takes the reservation back.",
|
|
2987
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["repo"], properties: { repo: { type: "string", description: "owner/name, or its https://github.com URL." } } } } } },
|
|
2988
|
+
responses: { "200": json(closed({ repo: { type: "string" }, run_id: { type: "string" }, agent_id: { type: "string" }, status: { const: "running" }, already_running: { type: "boolean" } }), "The scan already running."), "202": json(closed({ repo: { type: "string" }, run_id: { type: "string" }, agent_id: { type: "string" }, status: { const: "running" }, already_running: { type: "boolean" } }), "The scan started."), ...errors(400, 401, 409, 415, 422, 429, 500) },
|
|
2989
|
+
...SUGGESTIONS_MARK,
|
|
2990
|
+
},
|
|
2991
|
+
},
|
|
2992
|
+
"/suggestions/{suggestion_id}": {
|
|
2993
|
+
get: {
|
|
2994
|
+
operationId: "getSuggestion", tags: ["local"], summary: "One suggested agent whole: its instructions, the files a create adds, and whether GitHub lets it",
|
|
2995
|
+
description: "The suggestion with its agent's instructions; `files`, the files a create pushes (its package's `agent.md` and `output.schema.json` under `.agentrun/agents/<key>/`, and the client at `integration.path`), rendered now from its checked fields; `problems`, why its package would not check; and `github`, whether this server's GitHub App can open its pull request now, read from GitHub (the installation that covers the repository and its permissions), with what is missing and the pages that fix it.",
|
|
2996
|
+
parameters: [SUGGESTION_ID, { name: "name", in: "query", required: false, schema: { type: "string", minLength: 3, maxLength: 60 }, description: "The agent's name a create would be sent (`POST .../create` `name`): `files` are rendered with it, as the create pushes them. 422 when it is not 3 to 60 characters." }],
|
|
2997
|
+
responses: { "200": json(SUGGESTION_WHOLE, "The suggestion."), ...errors(401, 404, 422, 429, 500) },
|
|
2998
|
+
...SUGGESTIONS_MARK,
|
|
2999
|
+
},
|
|
3000
|
+
},
|
|
3001
|
+
"/suggestions/{suggestion_id}/discard": {
|
|
3002
|
+
post: {
|
|
3003
|
+
operationId: "discardSuggestion", tags: ["local"], summary: "Discard a suggested agent: it goes away, and later scans leave it out",
|
|
3004
|
+
description: "Open to discarded (a discarded one answers as it is). 409 suggestion_decided for a created one, whose pull request is closed on GitHub instead; 409 home_busy while a create of it runs.",
|
|
3005
|
+
parameters: [SUGGESTION_ID],
|
|
3006
|
+
responses: { "200": json(SUGGESTION, "Discarded."), ...errors(401, 404, 409, 429, 500) },
|
|
3007
|
+
...SUGGESTIONS_MARK,
|
|
3008
|
+
},
|
|
3009
|
+
},
|
|
3010
|
+
"/suggestions/{suggestion_id}/restore": {
|
|
3011
|
+
post: {
|
|
3012
|
+
operationId: "restoreSuggestion", tags: ["local"], summary: "Bring a discarded suggestion back (an undo)",
|
|
3013
|
+
description: "Discarded to open (an open one answers as it is). 409 suggestion_decided for a created one.",
|
|
3014
|
+
parameters: [SUGGESTION_ID],
|
|
3015
|
+
responses: { "200": json(SUGGESTION, "Open again."), ...errors(401, 404, 409, 429, 500) },
|
|
3016
|
+
...SUGGESTIONS_MARK,
|
|
3017
|
+
},
|
|
3018
|
+
},
|
|
3019
|
+
"/suggestions/{suggestion_id}/create": {
|
|
3020
|
+
post: {
|
|
3021
|
+
operationId: "createSuggestedAgent", tags: ["local"], summary: "Create a suggested agent: a branch with its package and client, the agent made here, and a pull request",
|
|
3022
|
+
description: "Checks the package rendered from the suggestion as an imported one is checked (422 with each problem), then reads the GitHub App's installation on the repository: 409 github_not_connected, 409 github_not_installed (`details.install_url`), or 409 github_permission_missing (`details.missing`, `permissions_url`, `installation_url`) when it lacks Contents or Pull requests write; nothing is written. Then, with one installation token narrowed to the repository (contents and pull requests write, metadata read; revoked after): the files are committed over the default branch's head on a new branch `agentrun/<key>` (409 github_file_exists when one is already there: the pull request only adds files); the package is applied here as the imported template `github:<owner>/<repo>/.agentrun/agents/<key>` at that commit (a refusal, such as 409 agent_not_runnable, deletes the branch and makes nothing); and the pull request is opened, naming the agent's id and the variables the client reads. 201 with the suggestion, `created` holding the agent, the branch and the pull request, and the apply's `warnings`. A created suggestion answers 200 as it is; one whose agent was made and whose pull request failed (502 github_failed, `details.agent_id`) opens only the pull request when sent again. A create claims the suggestion in the store before it writes to GitHub, on every server sharing it: 409 home_busy (retryable) while another create of it runs; a claim older than 15 minutes, left by a server that stopped, is taken over. 409 suggestion_decided for a discarded one.",
|
|
3023
|
+
parameters: [SUGGESTION_ID],
|
|
3024
|
+
requestBody: { required: false, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { name: { type: "string", minLength: 3, maxLength: 60, description: "The agent's name, in place of the suggestion's." } } } } } },
|
|
3025
|
+
responses: { "200": json({ ...SUGGESTION, required: [...SUGGESTION.required, "warnings"], properties: { ...SUGGESTION.properties, warnings: { type: "array", items: { type: "object" } } } }, "Created already."), "201": json({ ...SUGGESTION, required: [...SUGGESTION.required, "warnings"], properties: { ...SUGGESTION.properties, warnings: { type: "array", items: { type: "object" } } } }, "Created: the agent, its branch and its pull request."), ...errors(401, 404, 409, 415, 422, 429, 500), "502": { description: "`github_failed`: GitHub refused or did not answer a step; with `details.agent_id` when the agent was made and only its pull request failed (send the create again to open it).", headers: { "X-Request-Id": ref("headers/RequestId") }, content: { "application/json": { schema: ref("schemas/Error") } } } },
|
|
3026
|
+
...SUGGESTIONS_MARK,
|
|
3027
|
+
},
|
|
3028
|
+
},
|
|
2925
3029
|
"/settings/mcp-servers/oauth/client.json": {
|
|
2926
3030
|
get: {
|
|
2927
3031
|
operationId: "mcpOAuthClient", tags: ["local"], summary: "This server's OAuth client metadata document", security: [{}],
|
|
@@ -3794,7 +3898,7 @@ const FIELD_EXTENSIONS = {
|
|
|
3794
3898
|
repick: { type: "boolean", default: false, description: "`true`: a learned workflow compiled from now on re-picks its answer's quotes from the pages its run fetched. When a quote in its first answer is in none of those pages, its one re-pick writes the answer again from the pages themselves (each sent as data, told it is untrusted text from the web and never instructions, with no tools), not from its compact notes alone. It is read when a draft is committed, so a workflow already kept is unchanged until its next compile. It reaches a re-pick of one model step, in the workflow or in the composed workflow that writes its answer; any other re-pick is kept as compiled, and the server's log says so. An agent whose workflows run through an SDK bridge ignores it. `false` or absent: the re-pick reads its compact notes and its draft." },
|
|
3795
3899
|
repick_max_chars: { type: "integer", minimum: 1, maximum: REPICK_MAX_CHARS_MAX, default: REPICK_MAX_CHARS_DEFAULT, description: "The most characters of state a re-pick over the pages sends its model: past it, the longest strings (the pages) are cut first, each to one length and marked where it was cut. Its cost is the served run's, under the run's cost cap like every model request of the run. Read with `repick`, at each compile." },
|
|
3796
3900
|
} }], default: false, description: "Whether an agentic revision's runs learn: `true`, its owner's corrections and learned workflows; an object, the same with the loop's numbers set on it (`compile_after`, `agree_min`, `alone_min`, `agree_on`, `audit_every`, `audit_every_later`, `audit_later_after`, `hold_window`, `hold_disagree`, `stop_window`, `repick`, `repick_max_chars`, each optional: one left out is its default; `true` is every default); `false`, nothing. A run that learns starts from what its agent has learned, its corrections.md whole in its instructions under `# Learned` and its learned workflows behind its learned_workflow tool; once its job is due, it is asked one compile turn that writes the job as a learned workflow, checked and committed. Kept when a definition says so, true, false or an object (its numbers in one order); a number out of range or an unknown key is a 422 `wrong_type`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
|
|
3797
|
-
checkout: { enum: ["pull_request", "none"], description: "What the server checks out in each run's folder before its first turn, an agentic definition's alone. `pull_request`: the pull request the run's GitHub event names (a GitHub trigger's firing: its repository, number, head and base), at its head, detached, in `repo/`, with its base and their merge base fetched beside it (refs `pr/head`, `pr/base`, `pr/merge-base`). The fetch is the server's own, one command on the run's folder, with an installation token of the server's GitHub App narrowed to that repository and `contents: read`, which the agent never holds: it is never in the folder, the checkout's git config, its remote's URL, the agent's environment or the log. With no App, or one not installed there, the fetch is anonymous, which a public repository answers. The run's system prompt says what was checked out, or why nothing was (no pull request named, the fetch failed), so it can read the change another way, such as the GitHub MCP. The checkout is removed when the run's claim ends. An edit that leaves it out keeps the agent's; `none` clears it. A template sets it from its manifest's `checkout`.", "x-agentrun-serve": "checkout/1" },
|
|
3901
|
+
checkout: { enum: ["pull_request", "repository", "none"], description: "What the server checks out in each run's folder before its first turn, an agentic definition's alone. `repository` (suggestions/1): the repository the run names (its start's `repo`, else the first https://github.com/<owner>/<repo> its first message names), at the head of its default branch, one commit deep, detached, in `repo/` (ref `repo/head`), its files listed one a line in `repo/.git/agentrun-files` for an agent with no shell; fetched as below. `pull_request`: the pull request the run's GitHub event names (a GitHub trigger's firing: its repository, number, head and base), at its head, detached, in `repo/`, with its base and their merge base fetched beside it (refs `pr/head`, `pr/base`, `pr/merge-base`). The fetch is the server's own, one command on the run's folder, with an installation token of the server's GitHub App narrowed to that repository and `contents: read`, which the agent never holds: it is never in the folder, the checkout's git config, its remote's URL, the agent's environment or the log. With no App, or one not installed there, the fetch is anonymous, which a public repository answers. The run's system prompt says what was checked out, or why nothing was (no pull request named, the fetch failed), so it can read the change another way, such as the GitHub MCP. The checkout is removed when the run's claim ends. An edit that leaves it out keeps the agent's; `none` clears it. A template sets it from its manifest's `checkout`.", "x-agentrun-serve": "checkout/1" },
|
|
3798
3902
|
max_requests: { type: "integer", minimum: 0, description: "The most requests on free models (a catalog price of all zeros, which a dollar cap cannot stop) each of the agent's runs makes, below the server's own limit (`limits.free_model_requests`, AGENTRUN_FREE_MODEL_REQUESTS): a run stops at the lower of the two. The request after that many is not sent, and the run ends `failed`, its error `spend_cap_reached`: \"Not sent: this run reached its 20-request limit for free models.\" (the number is the limit it stopped at). It counts what the server's limit counts; a paid request never counts. Above 0 sets it, 0 clears it, and an edit that leaves it out keeps the agent's. A template sets it from its manifest's `budget.max_requests`.", "x-agentrun-serve": "maxrequests/1" },
|
|
3799
3903
|
},
|
|
3800
3904
|
AgentCreate: {
|
|
@@ -320,7 +320,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
320
320
|
// turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
|
|
321
321
|
// there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
|
|
322
322
|
// person's stop ends the fetch at once (run.stopped).
|
|
323
|
-
const checkout = body.checkout
|
|
323
|
+
const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
|
|
324
324
|
holds.hold({ checkout });
|
|
325
325
|
// The run's skills and its learning seed, laid in its folder through the run's Workspace now, before its computer
|
|
326
326
|
// exists: on Archil the computer's mount of the folder takes the disk's write delegation, and from then on every write
|
|
@@ -362,7 +362,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
362
362
|
: await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
|
|
363
363
|
holds.hold({ ws });
|
|
364
364
|
// The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
|
|
365
|
-
const checkout = body.checkout
|
|
365
|
+
const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
|
|
366
366
|
holds.hold({ checkout });
|
|
367
367
|
// A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
|
|
368
368
|
if (!(deps.sealKey === undefined && runnerSeam()))
|
package/dist/runner/metrics.d.ts
CHANGED
|
@@ -115,9 +115,11 @@ export type EndCost = {
|
|
|
115
115
|
readonly costUpperBound: boolean;
|
|
116
116
|
};
|
|
117
117
|
export declare const endCostOf: (cost: RunCost) => EndCost;
|
|
118
|
-
/** The run's model requests billed to a
|
|
118
|
+
/** The run's model requests billed to a person's plan (runner.turn `billing` "plan", booked at no price: a ChatGPT plan's,
|
|
119
|
+
* chatgpt-plan.ts, or Claude Code's login's):
|
|
119
120
|
* how many and their tokens (input, output and cache, as each booking reported them). Each is $0 to the run by the
|
|
120
|
-
* kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced.
|
|
121
|
+
* kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. One still in
|
|
122
|
+
* flight (its runner.request marked `plan`, no runner.turn yet) is one of them, with no tokens yet. */
|
|
121
123
|
export declare function planSpend(entries: readonly EntryLike[]): {
|
|
122
124
|
readonly requests: number;
|
|
123
125
|
readonly tokens: number;
|
package/dist/runner/metrics.js
CHANGED
|
@@ -104,7 +104,10 @@ export function bookedSpend(entries, which) {
|
|
|
104
104
|
if (e.kind === RUNNER_RECORDS.request && !answered.has(turnOf(e))) {
|
|
105
105
|
requests += 1;
|
|
106
106
|
count(e);
|
|
107
|
-
|
|
107
|
+
// One billed to a person's plan (its record's `plan`, Admitted.plan) is $0 to the run however it ends, as the cap's
|
|
108
|
+
// reader (the kernel's sessionSpendOf) holds it: in flight it is a known $0, never unpriced.
|
|
109
|
+
if (e.data?.plan !== true)
|
|
110
|
+
unpriced += 1;
|
|
108
111
|
unmetered += 1;
|
|
109
112
|
continue;
|
|
110
113
|
}
|
|
@@ -199,13 +202,22 @@ export function runCostOf(entries, { unbooked = false } = {}) {
|
|
|
199
202
|
return { usd, known, bounded: usd === null ? 0 : Math.max(0, round(usd - known)), unpriced: cost.unpriced, atMost: cost.atMost ?? 0, requests: parts.reduce((sum, part) => sum + part.requests, 0) };
|
|
200
203
|
}
|
|
201
204
|
export const endCostOf = (cost) => ({ costUsd: cost.usd, costUpperBound: cost.usd !== null && cost.atMost > 0 });
|
|
202
|
-
/** The run's model requests billed to a
|
|
205
|
+
/** The run's model requests billed to a person's plan (runner.turn `billing` "plan", booked at no price: a ChatGPT plan's,
|
|
206
|
+
* chatgpt-plan.ts, or Claude Code's login's):
|
|
203
207
|
* how many and their tokens (input, output and cache, as each booking reported them). Each is $0 to the run by the
|
|
204
|
-
* kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced.
|
|
208
|
+
* kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. One still in
|
|
209
|
+
* flight (its runner.request marked `plan`, no runner.turn yet) is one of them, with no tokens yet. */
|
|
205
210
|
export function planSpend(entries) {
|
|
211
|
+
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
212
|
+
const answered = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.turn).map(turnOf));
|
|
206
213
|
let requests = 0;
|
|
207
214
|
let tokens = 0;
|
|
208
215
|
for (const e of entries) {
|
|
216
|
+
if (e.kind === RUNNER_RECORDS.request) {
|
|
217
|
+
if (e.data?.plan === true && !answered.has(turnOf(e)))
|
|
218
|
+
requests += 1;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
209
221
|
if (e.kind !== RUNNER_RECORDS.turn)
|
|
210
222
|
continue;
|
|
211
223
|
const d = (e.data ?? {});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Workspace } from "../workspace/workspace.js";
|
|
2
2
|
import type { GithubAppMint } from "./mcp-github.js";
|
|
3
3
|
import type { AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
4
|
-
/** What an agent's revision keeps of its definition's `checkout` (validate.ts CHECKOUTS; `none` keeps nothing)
|
|
5
|
-
|
|
4
|
+
/** What an agent's revision keeps of its definition's `checkout` (validate.ts CHECKOUTS; `none` keeps nothing):
|
|
5
|
+
* `pull_request`, the pull request the run's GitHub event names; `repository`, the head of the default branch of the
|
|
6
|
+
* repository the run names (repoCheckout below). */
|
|
7
|
+
export type Checkout = "pull_request" | "repository";
|
|
6
8
|
/** The folder, in the run's own, the checkout lands in. */
|
|
7
9
|
export declare const CHECKOUT_DIR = "repo";
|
|
8
10
|
/** How long the whole checkout may take: inside Archil's exec bound, on either mode. */
|
|
@@ -45,7 +47,8 @@ export interface PrCheckoutOptions {
|
|
|
45
47
|
export declare function prCheckout(options: PrCheckoutOptions): Promise<PrCheckout>;
|
|
46
48
|
/** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
|
|
47
49
|
* MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
|
|
48
|
-
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch.
|
|
50
|
+
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. `kind` is the revision's
|
|
51
|
+
* checkout: the pull request the run's event names, or the repository the run names (repoCheckout). */
|
|
49
52
|
export declare function prCheckoutForClaim(deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "githubApi" | "githubWeb">, workspace: Workspace, launch: {
|
|
50
53
|
readonly input: unknown;
|
|
51
54
|
readonly repo?: string | undefined;
|
|
@@ -57,4 +60,18 @@ export declare function prCheckoutForClaim(deps: Pick<AdapterSpecDeps, "store" |
|
|
|
57
60
|
hold(values: readonly string[]): void;
|
|
58
61
|
}, signal?: AbortSignal, held?: (part: {
|
|
59
62
|
end(): Promise<void>;
|
|
60
|
-
}) => void): Promise<PrCheckout>;
|
|
63
|
+
}) => void, kind?: Checkout): Promise<PrCheckout>;
|
|
64
|
+
/** The file in the checkout's .git that lists its files, one path a line (git ls-tree), so an agent with `read` and no
|
|
65
|
+
* shell can still find what to open. */
|
|
66
|
+
export declare const FILE_LIST = "agentrun-files";
|
|
67
|
+
/** What a repository's checkout reads of the run, beside a pull request's options: `repo`, the launch's (the start body's,
|
|
68
|
+
* checked against the agent's binding), else the first https://github.com/<owner>/<repo> the run's first message names
|
|
69
|
+
* (github.ts githubTargetOf: its owner's words, or a github trigger's payload tag). */
|
|
70
|
+
export type RepoCheckoutOptions = PrCheckoutOptions & {
|
|
71
|
+
readonly repo?: string;
|
|
72
|
+
};
|
|
73
|
+
/** The repository the run names, checked out in the run's folder at the head of its default branch, one commit deep: the
|
|
74
|
+
* server's own fetch, with the App's token for that one repository and `contents: read` alone (or none: anonymous, which
|
|
75
|
+
* a public repository answers), revoked once the fetch is done, never kept. Never throws for a checkout that could not be
|
|
76
|
+
* made: the run is told why. */
|
|
77
|
+
export declare function repoCheckout(options: RepoCheckoutOptions): Promise<PrCheckout>;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// tools can read the change instead. The checkout is removed when the claim lets go (spec-holds.ts), and made again by
|
|
23
23
|
// the next claim of the same run.
|
|
24
24
|
import { randomUUID } from "node:crypto";
|
|
25
|
-
import { GITHUB_WEB, githubPullOf } from "../github.js";
|
|
25
|
+
import { GITHUB_WEB, githubPullOf, githubTargetOf } from "../github.js";
|
|
26
26
|
import { isObject } from "../validate.js";
|
|
27
27
|
import { COMMAND_MAX_MS } from "../workspace/archil-exec.js";
|
|
28
28
|
import { shellEnv } from "../workspace/hands.js";
|
|
@@ -168,9 +168,108 @@ function checkoutNote(pull, mergeBase) {
|
|
|
168
168
|
}
|
|
169
169
|
/** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
|
|
170
170
|
* MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
|
|
171
|
-
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch.
|
|
172
|
-
|
|
171
|
+
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. `kind` is the revision's
|
|
172
|
+
* checkout: the pull request the run's event names, or the repository the run names (repoCheckout). */
|
|
173
|
+
export async function prCheckoutForClaim(deps, workspace, launch, redact, signal, held, kind = "pull_request") {
|
|
173
174
|
const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
|
|
174
175
|
const access = await githubAppAccess(deps.store, deps.sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, hold: (values) => redact.hold(values), ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
|
|
175
|
-
|
|
176
|
+
const common = { workspace, input: launch.input, fromGitHub, ...(access ? { mint: access.mint } : {}), ...(access?.revoke ? { revoke: access.revoke } : {}), hold: (secrets) => redact.hold(secrets), ...(deps.githubWeb ? { web: deps.githubWeb } : {}), ...(signal ? { signal } : {}), ...(held ? { held } : {}) };
|
|
177
|
+
if (kind === "repository")
|
|
178
|
+
return repoCheckout({ ...common, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
|
|
179
|
+
return prCheckout(common);
|
|
176
180
|
}
|
|
181
|
+
/** The file in the checkout's .git that lists its files, one path a line (git ls-tree), so an agent with `read` and no
|
|
182
|
+
* shell can still find what to open. */
|
|
183
|
+
export const FILE_LIST = "agentrun-files";
|
|
184
|
+
/** The exec's script for a repository's checkout: $1 the remote's URL (no credential), $2 the folder, $3 the URL prefix
|
|
185
|
+
* the header is for, $4 this claim's checkout id. Its stdin's first line is an Authorization header, or empty. It fetches
|
|
186
|
+
* the remote's HEAD (its default branch) one commit deep, and checks it out detached (ref repo/head). Its exit codes name
|
|
187
|
+
* the step that failed (10 the folder, 11 the fetch, 12 the checkout); on success it lists the files in
|
|
188
|
+
* .git/${FILE_LIST} and prints the commit, how many files there are and the default branch's name (empty when the
|
|
189
|
+
* remote did not say). */
|
|
190
|
+
const REPO_SCRIPT = `set -u
|
|
191
|
+
url=$1 dir=$2 scope=$3 claim=$4
|
|
192
|
+
IFS= read -r auth || true
|
|
193
|
+
export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null
|
|
194
|
+
if [ -n "\${auth:-}" ]; then export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.$scope.extraheader" GIT_CONFIG_VALUE_0="$auth"; fi
|
|
195
|
+
auth=
|
|
196
|
+
rm -rf "\${dir:?}"
|
|
197
|
+
git init -q "$dir" >/dev/null 2>&1 && cd "$dir" && printf '%s\\n' "$claim" > .git/${OWNER_FILE} && git remote add origin "$url" || exit 10
|
|
198
|
+
branch=$(git ls-remote --symref origin HEAD 2>/dev/null | awk '$1 == "ref:" { sub("^refs/heads/", "", $2); print $2; exit }')
|
|
199
|
+
git -c maintenance.auto=false -c gc.auto=0 fetch -q --no-tags --no-recurse-submodules --depth=1 origin HEAD || exit 11
|
|
200
|
+
git update-ref refs/repo/head FETCH_HEAD || exit 12
|
|
201
|
+
git -c advice.detachedHead=false checkout -q --detach FETCH_HEAD || exit 12
|
|
202
|
+
git ls-tree -r --name-only HEAD > .git/${FILE_LIST} || exit 12
|
|
203
|
+
printf '%s %s %s\\n' "$(git rev-parse HEAD)" "$(wc -l < .git/${FILE_LIST} | tr -d ' ')" "$branch"
|
|
204
|
+
`;
|
|
205
|
+
/** The repository the run names, checked out in the run's folder at the head of its default branch, one commit deep: the
|
|
206
|
+
* server's own fetch, with the App's token for that one repository and `contents: read` alone (or none: anonymous, which
|
|
207
|
+
* a public repository answers), revoked once the fetch is done, never kept. Never throws for a checkout that could not be
|
|
208
|
+
* made: the run is told why. */
|
|
209
|
+
export async function repoCheckout(options) {
|
|
210
|
+
const { workspace } = options;
|
|
211
|
+
const named = options.repo !== undefined ? { repo: options.repo } : githubTargetOf(isObject(options.input) ? options.input.content : options.input, { payload: options.fromGitHub === true });
|
|
212
|
+
const [owner, name, extra] = (named?.repo ?? "").split("/");
|
|
213
|
+
if (!named || !owner || !name || extra !== undefined || !REPO_OWNER.test(owner) || !REPO_NAME_PART.test(name) || name === "." || name === "..")
|
|
214
|
+
return noCheckout("No checkout was made: this run names no GitHub repository (https://github.com/<owner>/<repo> in its first message), so there is no repo/ folder.");
|
|
215
|
+
const repo = `${owner}/${name}`;
|
|
216
|
+
const web = (options.web ?? GITHUB_WEB).replace(/\/+$/, "");
|
|
217
|
+
let token;
|
|
218
|
+
let anonymous = "";
|
|
219
|
+
if (options.mint) {
|
|
220
|
+
try {
|
|
221
|
+
const got = await options.mint({ repo, ...("installation" in named && named.installation !== undefined ? { installation: named.installation } : {}) }, { contents: "read" });
|
|
222
|
+
if (got.ok)
|
|
223
|
+
token = got.token;
|
|
224
|
+
else
|
|
225
|
+
anonymous = got.reason === "not_installed" ? `the GitHub App is not installed on ${repo}` : got.message;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
anonymous = `GitHub did not make a token (${error?.message ?? error})`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else
|
|
232
|
+
anonymous = "this server has no GitHub App";
|
|
233
|
+
const header = token ? `Authorization: Basic ${Buffer.from(`x-access-token:${token}`, "utf8").toString("base64")}` : "";
|
|
234
|
+
const secrets = token ? [token, header, header.slice("Authorization: Basic ".length)] : [];
|
|
235
|
+
if (secrets.length)
|
|
236
|
+
options.hold?.(secrets);
|
|
237
|
+
const claim = randomUUID();
|
|
238
|
+
const removal = async () => {
|
|
239
|
+
const result = await workspace.exec(["sh", "-c", `[ "$(cat "\${1:?}/.git/${OWNER_FILE}" 2>/dev/null)" = "$2" ] || exit 0; rm -rf -- "\${1:?}"`, "sh", CHECKOUT_DIR, claim], { env: shellEnv(), timeoutMs: CHECKOUT_MS });
|
|
240
|
+
if (result.code !== 0)
|
|
241
|
+
throw new Error(`the run's ${CHECKOUT_DIR}/ checkout could not be removed (exit ${result.code ?? result.signal}): ${tail(result.stderr, secrets)}`);
|
|
242
|
+
};
|
|
243
|
+
const failed = async (why) => {
|
|
244
|
+
await removal().catch(() => { });
|
|
245
|
+
return noCheckout(`The repository ${repo} could not be checked out (${why}), so there is no ${CHECKOUT_DIR}/ folder: read it through the GitHub tools if you have them, else say that you could not read it.`);
|
|
246
|
+
};
|
|
247
|
+
options.held?.({ end: removal });
|
|
248
|
+
let result;
|
|
249
|
+
try {
|
|
250
|
+
result = await workspace.exec(["sh", "-c", REPO_SCRIPT, "sh", `${web}/${repo}.git`, CHECKOUT_DIR, `${web}/`, claim], { env: shellEnv(), stdin: Buffer.from(`${header}\n`, "utf8"), timeoutMs: options.timeoutMs ?? CHECKOUT_MS, ...(options.signal ? { signal: options.signal } : {}) });
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (options.signal?.aborted)
|
|
254
|
+
throw error;
|
|
255
|
+
return failed(`the fetch could not run: ${tail(String(error?.message ?? error), secrets)}`);
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
if (token && options.revoke)
|
|
259
|
+
await options.revoke(token).catch(() => { });
|
|
260
|
+
}
|
|
261
|
+
if (result.timedOut)
|
|
262
|
+
return failed(`the fetch took more than ${Math.round((options.timeoutMs ?? CHECKOUT_MS) / 1000)} s`);
|
|
263
|
+
if (result.code !== 0) {
|
|
264
|
+
const step = result.code === 10 ? "its folder could not be made" : result.code === 11 ? `${web}/${repo} did not give its default branch${token ? "" : `, fetched with no token: ${anonymous}`}` : result.code === 12 ? "its head could not be checked out" : `git ended with ${result.code ?? result.signal}`;
|
|
265
|
+
const said = tail(result.stderr, secrets);
|
|
266
|
+
return failed(said ? `${step}: ${said}` : step);
|
|
267
|
+
}
|
|
268
|
+
const [sha = "", count = "", branch = ""] = Buffer.from(result.stdout).toString("utf8").trim().split(/\s+/);
|
|
269
|
+
const at = /^[0-9a-f]{40}$/.test(sha) ? sha : "its head";
|
|
270
|
+
const named_ = /^[A-Za-z0-9._\/-]{1,255}$/.test(branch) ? ` ${branch}` : "";
|
|
271
|
+
const files = /^\d{1,9}$/.test(count) ? `Its ${count} ${count === "1" ? "file is" : "files are"} listed in ${CHECKOUT_DIR}/.git/${FILE_LIST}, one path a line. ` : "";
|
|
272
|
+
return { note: `The repository ${repo} is checked out in ${CHECKOUT_DIR}/ at the head of its default branch${named_}, commit ${at} (ref repo/head), by the server before this run began. ${files}It is a shallow clone (that one commit, no history), and no credential is kept in it.`, end: removal };
|
|
273
|
+
}
|
|
274
|
+
const REPO_OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
|
|
275
|
+
const REPO_NAME_PART = /^[A-Za-z0-9._-]{1,100}$/;
|
|
@@ -47,7 +47,7 @@ import { agentDirName, recordingsFolder, runFolder, scratchFolder } from "../wor
|
|
|
47
47
|
import { keptKeyOf } from "../workspace/computer-kept.js";
|
|
48
48
|
import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, learnedDecisionKeys, openRunModelKey, savedModelKeys, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
49
49
|
import { githubAppAccess } from "./github-app.js";
|
|
50
|
-
import { githubPullOf } from "../github.js";
|
|
50
|
+
import { githubPullOf, githubTargetOf } from "../github.js";
|
|
51
51
|
import { isObject } from "../validate.js";
|
|
52
52
|
import { liveForRun, runnerLiveOf } from "../live-reach.js";
|
|
53
53
|
import { learningFolderOf, secretsShown } from "../learning.js";
|
|
@@ -720,15 +720,18 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
720
720
|
// A run's process mints for one thing alone: its revision's pull-request checkout (pr-checkout.ts), of the pull
|
|
721
721
|
// request its launch's payload names, contents read. Its MCP mints on the runner (mcp above). So the mint handed
|
|
722
722
|
// here makes that token and no other, whatever repository or permissions the process names.
|
|
723
|
-
|
|
723
|
+
// A repository checkout's is the repository the run names (its start's repo, else the first https://github.com
|
|
724
|
+
// URL its owner's words name): the same one repository, contents read.
|
|
725
|
+
if (revision.body.checkout !== "pull_request" && revision.body.checkout !== "repository")
|
|
724
726
|
return undefined;
|
|
725
|
-
const
|
|
727
|
+
const content = isObject(launch.input) ? launch.input.content : launch.input;
|
|
728
|
+
const pull = revision.body.checkout === "pull_request" ? githubPullOf(content, { payload: fromGitHub }) : launch.repo !== undefined ? { repo: launch.repo } : githubTargetOf(content, { payload: fromGitHub });
|
|
726
729
|
if (!pull)
|
|
727
730
|
return undefined;
|
|
728
731
|
const access = await github();
|
|
729
732
|
if (!access)
|
|
730
733
|
return undefined;
|
|
731
|
-
const bound = { repo: pull.repo, ...(pull.installation !== undefined ? { installation: pull.installation } : {}) };
|
|
734
|
+
const bound = { repo: pull.repo, ...("installation" in pull && pull.installation !== undefined ? { installation: pull.installation } : {}) };
|
|
732
735
|
const mint = async (to) => {
|
|
733
736
|
if (to?.repo !== bound.repo || to.installation !== bound.installation) {
|
|
734
737
|
log(`run ${claim.runId}: its process asked for a GitHub token of another repository than its pull request's, which a run's process may not`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Interfaces } from "../live-reach.js";
|
|
1
2
|
import type { Settings } from "../store/store.js";
|
|
2
3
|
/** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
|
|
3
4
|
export declare const RUN_ENV_KEY = "server.run_env";
|
|
@@ -31,6 +32,8 @@ export interface RunnerEnvCheckOptions {
|
|
|
31
32
|
readonly read: (name: string) => string | undefined;
|
|
32
33
|
/** Whether a TCP connect to `host`:`port` is answered within `ms` (a test's stand-in). */
|
|
33
34
|
readonly answers?: (host: string, port: number, ms: number) => Promise<boolean>;
|
|
35
|
+
/** This machine's network interfaces (a test's stand-in), for AGENTRUN_RUNNER_LIVE_HOST given as an IPv4 block. */
|
|
36
|
+
readonly interfaces?: Interfaces;
|
|
34
37
|
}
|
|
35
38
|
/** How long a forwarder has to answer the check's connect. */
|
|
36
39
|
export declare const FORWARDER_MS = 2000;
|
|
@@ -25,6 +25,7 @@ import { HARNESS_MODULES_SETTING, HARNESS_RECIPES_SETTING } from "../harness-tab
|
|
|
25
25
|
import { GATEWAY_IDS_ENV } from "../model-gateway.js";
|
|
26
26
|
import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV, MCP_ALLOW_LOOPBACK_ENV } from "../start-switches.js";
|
|
27
27
|
import { DOCKER_IMAGE_ENV } from "../box-image.js";
|
|
28
|
+
import { RunnerLiveRefused, runnerLiveOf } from "../live-reach.js";
|
|
28
29
|
import { bootSealKey } from "../seal-key.js";
|
|
29
30
|
import { SECRET_NAMES } from "../secrets.js";
|
|
30
31
|
import { SEAL_KEY_ENV } from "../tool-keys.js";
|
|
@@ -197,8 +198,30 @@ export async function checkRunnerEnv(options) {
|
|
|
197
198
|
for (const name of SERVER_ONLY)
|
|
198
199
|
if (read(name)?.trim())
|
|
199
200
|
rows.push({ state: "warn", name, why: "the server's own secret: a runner never needs it, so leave it off the runner" });
|
|
201
|
+
const liveRow = liveHostRow(env, options.interfaces);
|
|
202
|
+
if (liveRow)
|
|
203
|
+
rows.push(liveRow);
|
|
200
204
|
return rows;
|
|
201
205
|
}
|
|
206
|
+
/** AGENTRUN_RUNNER_LIVE_HOST's row, where it is set: the host the server reaches this runner at (an address, never a
|
|
207
|
+
* secret); warn where it names no host; bad where an IPv4 block holds none or several of this machine's addresses (live-reach.ts runnerLiveOf). */
|
|
208
|
+
function liveHostRow(env, interfaces) {
|
|
209
|
+
const name = "AGENTRUN_RUNNER_LIVE_HOST";
|
|
210
|
+
if (!env[name]?.trim())
|
|
211
|
+
return undefined;
|
|
212
|
+
try {
|
|
213
|
+
// The key is not read here: the host alone is.
|
|
214
|
+
const live = runnerLiveOf(env, Buffer.alloc(32), interfaces);
|
|
215
|
+
return live
|
|
216
|
+
? { state: "ok", name, why: `the server reaches this runner's relay and viewers at ${live.host}` }
|
|
217
|
+
: { state: "warn", name, why: "not a host name, an IPv4 address or an IPv4 block other than loopback: this runner's relay and viewers stay on loopback, where a server on another host cannot reach them" };
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
if (error instanceof RunnerLiveRefused)
|
|
221
|
+
return { state: "bad", name, why: error.message };
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
202
225
|
/** The check's lines: one per row (its state, its name, why), then the outcome. */
|
|
203
226
|
export function checkLines(rows) {
|
|
204
227
|
const width = Math.max(0, ...rows.map((row) => row.name.length));
|
package/dist/server.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { type Store } from "./store/index.js";
|
|
|
11
11
|
import { type BoxOffer } from "./place-offers.js";
|
|
12
12
|
import { type StoredKeys } from "./secrets.js";
|
|
13
13
|
import { type ComposioControl } from "./composio-preset.js";
|
|
14
|
+
import type { UsageEventName } from "./telemetry.js";
|
|
14
15
|
import type { TriggerAdapter } from "./trigger-adapter.js";
|
|
15
16
|
import { type TriggerClock } from "./triggers.js";
|
|
16
17
|
import type { LaunchHook } from "./trigger-launch-hook.js";
|
|
@@ -27,6 +28,9 @@ export type ServeOptions = {
|
|
|
27
28
|
/** On Postgres: told when this server's owner lock is lost for good (another server took the schema, or the lock could
|
|
28
29
|
* not be taken back): every store call is refused from then. The CLI exits 1 on it, so the platform restarts the server. */
|
|
29
30
|
onStoreLost?: (error: Error) => void;
|
|
31
|
+
/** Told when someone uses a feature the anonymous counts name (telemetry.ts UsageEventName: a suggestions scan, a
|
|
32
|
+
* discard, a suggested agent created). The CLI hands it the counts' `used`; it hears the event's name and nothing else. */
|
|
33
|
+
onUsage?: (event: UsageEventName) => void;
|
|
30
34
|
/** The owner, signed in with a password (owner.ts): the page asks for it, and the token stays for scripts and the CLI. */
|
|
31
35
|
accounts?: boolean;
|
|
32
36
|
/** With accounts: the first visit sets the password with no setup code (a server with no public address). Honored only
|
|
@@ -298,6 +302,13 @@ export type Serve = {
|
|
|
298
302
|
* loopback. The runner beside it is told them with localInstall (runner/beside.ts mcpOwn), so its runs' loopback reads
|
|
299
303
|
* never reach this server, as its own reads never do. */
|
|
300
304
|
own: readonly string[];
|
|
305
|
+
/** With --faux-github: the fake GitHub's API and its repository's site, for a test's own runner alone
|
|
306
|
+
* (test/support.mjs): the runner's GitHub API has one way in, a test runner's option, so neither the CLI's runner nor
|
|
307
|
+
* any setting is ever pointed at it. */
|
|
308
|
+
fauxGitHub?: {
|
|
309
|
+
api: string;
|
|
310
|
+
web?: string;
|
|
311
|
+
};
|
|
301
312
|
/** What a stop waits on: the runs whose processes still finish their turn, and the longest it waits on them. */
|
|
302
313
|
stopping(): {
|
|
303
314
|
runs: number;
|