@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/runner/main.js
CHANGED
|
@@ -26,7 +26,7 @@ import { dockerPathsForRuns } from "../box-paths.js";
|
|
|
26
26
|
import { hostCommandRefusals } from "../computers.js";
|
|
27
27
|
import { hostAddressesOnce } from "../docker-host-addresses.js";
|
|
28
28
|
import { claimInstallsStopped } from "../harness-install.js";
|
|
29
|
-
import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessTable } from "../harness-table.js";
|
|
29
|
+
import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARNESS_RECIPES_SETTING, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessRecipesEnv, harnessRecipesOf, harnessTable } from "../harness-table.js";
|
|
30
30
|
import { DEFAULT_PORT, maxRunsOf } from "../host.js";
|
|
31
31
|
import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
32
32
|
import { durationMs, runLine } from "../print.js";
|
|
@@ -35,6 +35,7 @@ import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
|
35
35
|
import { migrationsIn, openStore, RunnerBelowFloor, SchemaVersionUnknown, StoreAwaitsServer, storePlace, storeTarget } from "../store/index.js";
|
|
36
36
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
37
37
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
38
|
+
import { LAUNCH_HOOK_SECRET_ENV } from "../trigger-launch-hook.js";
|
|
38
39
|
import { FAUX_BROWSER_ENV } from "../tools.js";
|
|
39
40
|
import { claimViewOpener } from "../computer-live.js";
|
|
40
41
|
import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
|
|
@@ -46,6 +47,7 @@ import { envValue } from "../key-meta.js";
|
|
|
46
47
|
import { fauxComputers } from "../faux-computers.js";
|
|
47
48
|
import { computerDepsFrom } from "../workspace/computer-deps.js";
|
|
48
49
|
import { startJanitor } from "../workspace/computer-janitor.js";
|
|
50
|
+
import { projectRunEnded } from "../source-sync/checkpoints.js";
|
|
49
51
|
import { runEndComputers } from "../workspace/run-end-computers.js";
|
|
50
52
|
import { createDispatchLoop } from "./dispatch.js";
|
|
51
53
|
import { resolveRunnerLoop } from "./harness-loops.js";
|
|
@@ -91,9 +93,9 @@ export async function openRunnerStore(dataDir, env, warn, url) {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
/** The runner's own secrets, which a run never gets, not even in the runner's in-process environment: the server's
|
|
94
|
-
* tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey),
|
|
95
|
-
* database password). */
|
|
96
|
-
const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
|
|
96
|
+
* tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), the store's connection (its URL holds a
|
|
97
|
+
* database password), and the launch hook's signing secret (the server's alone). */
|
|
98
|
+
const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name === LAUNCH_HOOK_SECRET_ENV || name.startsWith("AGENTRUN_STORE_");
|
|
97
99
|
/** A run's environment as the runner hands its loops (AdapterSpecDeps.env): this process's, less the runner's own
|
|
98
100
|
* secrets, with every other secret the launcher's pipe handed it (a model key, a tool key, a box key) readable by name
|
|
99
101
|
* but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
|
|
@@ -129,7 +131,7 @@ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runner
|
|
|
129
131
|
export function besideRunEnv(env, switches) {
|
|
130
132
|
const out = runEnv(env);
|
|
131
133
|
for (const name of Object.keys(out))
|
|
132
|
-
if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV)
|
|
134
|
+
if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV || name === HARNESS_RECIPES_ENV)
|
|
133
135
|
delete out[name];
|
|
134
136
|
return Object.assign(out, switches);
|
|
135
137
|
}
|
|
@@ -268,7 +270,7 @@ export async function startRunnerProcess(options) {
|
|
|
268
270
|
// Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
|
|
269
271
|
await sweepEndedScratch(store, options.dataDir, { log: warn });
|
|
270
272
|
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
|
|
271
|
-
const runEnded = typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn }) : undefined;
|
|
273
|
+
const runEnded = projectRunEnded(store, typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn }) : undefined);
|
|
272
274
|
runner = startRunner({
|
|
273
275
|
store,
|
|
274
276
|
createLoop,
|
|
@@ -278,7 +280,7 @@ export async function startRunnerProcess(options) {
|
|
|
278
280
|
...(options.drainMs ? { drainMs: options.drainMs } : {}),
|
|
279
281
|
memory,
|
|
280
282
|
...(options.onEvent ? { onEvent: options.onEvent } : {}),
|
|
281
|
-
|
|
283
|
+
runEnded,
|
|
282
284
|
// A runner on a disk of its own claims nothing while the server keeps runs' folders on the server's disk (Mode 1),
|
|
283
285
|
// and says why on its presence row (disk-free.ts): those runs wait for a runner on the server's disk.
|
|
284
286
|
claimGate: diskFreeGate(store, options.dataDir, env, kind),
|
|
@@ -425,9 +427,10 @@ export function runnerArgs(argv) {
|
|
|
425
427
|
let fauxBrowser;
|
|
426
428
|
let check = false;
|
|
427
429
|
const harnessModules = [];
|
|
430
|
+
const harnessRecipes = [];
|
|
428
431
|
for (let i = 0; i < argv.length; i++) {
|
|
429
432
|
const given = argv[i];
|
|
430
|
-
const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module))=(.*)$/s.exec(given);
|
|
433
|
+
const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module|harness-recipe))=(.*)$/s.exec(given);
|
|
431
434
|
const arg = equals ? equals[1] : given;
|
|
432
435
|
const value = () => {
|
|
433
436
|
const next = equals ? equals[2] : argv[++i];
|
|
@@ -457,6 +460,8 @@ export function runnerArgs(argv) {
|
|
|
457
460
|
fauxBrowser = value();
|
|
458
461
|
else if (arg === "--harness-module")
|
|
459
462
|
harnessModules.push(value());
|
|
463
|
+
else if (arg === "--harness-recipe")
|
|
464
|
+
harnessRecipes.push(value());
|
|
460
465
|
else if (arg === "--check")
|
|
461
466
|
check = true;
|
|
462
467
|
else if (arg === "--env")
|
|
@@ -464,7 +469,7 @@ export function runnerArgs(argv) {
|
|
|
464
469
|
else if (arg === "--heartbeat")
|
|
465
470
|
heartbeatOnly = true;
|
|
466
471
|
else
|
|
467
|
-
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...], or --check --data D [--name N], or --check --env [--data D], or --check --heartbeat --data D [--name N]`);
|
|
472
|
+
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...] [--harness-recipe F ...], or --check --data D [--name N], or --check --env [--data D], or --check --heartbeat --data D [--name N]`);
|
|
468
473
|
}
|
|
469
474
|
if (envOnly && !check)
|
|
470
475
|
throw new RunnerRefused("--env goes with --check: runner --check --env [--data D]");
|
|
@@ -474,14 +479,14 @@ export function runnerArgs(argv) {
|
|
|
474
479
|
throw new RunnerRefused("--check takes --env (its environment alone) or --heartbeat (its heartbeat alone), not both: give neither to check both");
|
|
475
480
|
// `--check --env` checks the environment alone, which needs no data directory where the store is AGENTRUN_STORE_URL's.
|
|
476
481
|
if (envOnly)
|
|
477
|
-
return { dataDir: dataDir ?? "", check: true, envOnly: true, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }) };
|
|
482
|
+
return { dataDir: dataDir ?? "", check: true, envOnly: true, ...(harnessModules.length ? { harnessModules } : {}), ...(harnessRecipes.length ? { harnessRecipes } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }) };
|
|
478
483
|
if (!dataDir)
|
|
479
484
|
throw new RunnerRefused("a runner needs its data directory: --data D");
|
|
480
485
|
if (heartbeatOnly)
|
|
481
486
|
return { dataDir, check: true, heartbeatOnly: true, ...(name === undefined ? {} : { name }) };
|
|
482
487
|
if (fauxBrowser !== undefined && faux === undefined)
|
|
483
488
|
throw new RunnerRefused("--faux-browser goes with --faux");
|
|
484
|
-
return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
|
|
489
|
+
return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(harnessRecipes.length ? { harnessRecipes } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
|
|
485
490
|
}
|
|
486
491
|
/** Runs until SIGTERM or SIGINT, or until the store's runner floor rises above this runner (RunnerProcess.outdated),
|
|
487
492
|
* then closes: nothing more claimed, the drain, its runs handed back. Answers the floor's words when that was the stop,
|
|
@@ -565,9 +570,10 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
565
570
|
// here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
|
|
566
571
|
// run: a module that names a built-in, repeats an id, gives an id the API does not carry or lacks a member refuses the
|
|
567
572
|
// start in words naming the module and the id, never failing every run the runner would claim.
|
|
573
|
+
// Its harness recipes the same way: --harness-recipe, else AGENTRUN_SERVE_HARNESS_RECIPES, each loaded here.
|
|
568
574
|
let modules;
|
|
569
575
|
try {
|
|
570
|
-
modules = harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir);
|
|
576
|
+
modules = { ...harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir), ...harnessRecipesEnv(harnessRecipesOf(args.harnessRecipes, given), args.dataDir) };
|
|
571
577
|
harnessTable(modules);
|
|
572
578
|
}
|
|
573
579
|
catch (error) {
|
|
@@ -704,7 +710,8 @@ async function runnerCheck(args, env, name) {
|
|
|
704
710
|
// Harness modules given as --harness-module hold what AGENTRUN_SERVE_HARNESS_MODULES would (harness-table.ts
|
|
705
711
|
// harnessModulesOf): a runner started with the flag is checked with it.
|
|
706
712
|
const flagged = "harnessModules" in args && args.harnessModules?.length ? args.harnessModules.join(",") : undefined;
|
|
707
|
-
const
|
|
713
|
+
const recipesFlagged = "harnessRecipes" in args && args.harnessRecipes?.length ? args.harnessRecipes.join(",") : undefined;
|
|
714
|
+
const read = (one) => (one === HARNESS_MODULES_SETTING && flagged !== undefined ? flagged : one === HARNESS_RECIPES_SETTING && recipesFlagged !== undefined ? recipesFlagged : (secret(one) ?? env[one]));
|
|
708
715
|
const rows = args.heartbeatOnly ? [] : await checkRunnerEnv({ ...(args.dataDir ? { dataDir: args.dataDir } : {}), env, read });
|
|
709
716
|
// What the runner's start refuses before it claims (runnerMain): its run slots, drain and free-model requests, the
|
|
710
717
|
// Archil settings it is given, and its runs' isolation (the user each run runs as, and the image's helper that switches
|
package/dist/runner/mcp-claim.js
CHANGED
|
@@ -56,6 +56,7 @@ import { mcpNameOf } from "../tool-names.js";
|
|
|
56
56
|
import { composioMadeKey, composioPerRun } from "../composio-made.js";
|
|
57
57
|
import { composioRunQuery } from "../composio-preset.js";
|
|
58
58
|
import { META_REASON, metaToolOf } from "../mcp-meta.js";
|
|
59
|
+
import { resourceToolProblem } from "../mcp-resources.js";
|
|
59
60
|
import { credentialInQuery, credentialInQueryWords, shownUrl } from "../mcp-probe.js";
|
|
60
61
|
import { privateOAuthHosts } from "../mcp-private-hosts.js";
|
|
61
62
|
import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "../github.js";
|
|
@@ -479,9 +480,13 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
|
|
|
479
480
|
const saved = (found ?? {});
|
|
480
481
|
// Every tool the revision pinned, granted or not, against the meta tools known now (the list grows after a save).
|
|
481
482
|
for (const [server, { url, tools }] of Object.entries(saved)) {
|
|
482
|
-
for (const tool of tools)
|
|
483
|
+
for (const tool of tools) {
|
|
483
484
|
if (metaToolOf(url, tool.name))
|
|
484
485
|
throw new McpClaimRefused(`mcp:${server}/${tool.name} can't be granted: ${META_REASON}`);
|
|
486
|
+
const problem = resourceToolProblem(tool);
|
|
487
|
+
if (problem)
|
|
488
|
+
throw new McpClaimRefused(`mcp:${server}/${tool.name} can't be granted: ${problem}. Save the agent again. Nothing was sent.`);
|
|
489
|
+
}
|
|
485
490
|
}
|
|
486
491
|
// The granted tools alone, keyed by server with no prototype (a server named `constructor` is a server like any other).
|
|
487
492
|
const pinned = Object.create(null);
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { Harness } from "@earendil-works/pi-durable";
|
|
3
3
|
import { type McpGatewayOptions } from "../mcp-gateway.js";
|
|
4
|
-
import { type MediaReader } from "../fal-price.js";
|
|
5
4
|
import { type WebFake } from "../web-fake.js";
|
|
6
5
|
import type { SaveSlots } from "../web-save.js";
|
|
7
6
|
import { type OAuthNetwork } from "../mcp-oauth.js";
|
|
@@ -59,9 +58,16 @@ export interface McpForClaimOptions {
|
|
|
59
58
|
connectMs?: number;
|
|
60
59
|
};
|
|
61
60
|
readonly githubTimer?: GithubTimer;
|
|
62
|
-
/** Whether the run has a spend cap
|
|
63
|
-
|
|
64
|
-
readonly
|
|
61
|
+
/** Whether the run has a spend cap (its launch's max_cost_usd): under one, a metered job that can't be priced is refused
|
|
62
|
+
* unsent. None: it has. */
|
|
63
|
+
readonly capped?: boolean;
|
|
64
|
+
/** Where a metered job's input media are read from, through the guard web_save downloads by: an eval's web fake `web`,
|
|
65
|
+
* else the faux module or the public network by `env`, in web_save's `slots`. None: such a job can't be priced. */
|
|
66
|
+
readonly media?: {
|
|
67
|
+
readonly env: NodeJS.ProcessEnv;
|
|
68
|
+
readonly web?: WebFake;
|
|
69
|
+
readonly slots?: SaveSlots;
|
|
70
|
+
};
|
|
65
71
|
/** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
|
|
66
72
|
readonly hold?: (values: string[]) => void;
|
|
67
73
|
}
|
|
@@ -89,9 +95,6 @@ export interface ClaimMcp {
|
|
|
89
95
|
/** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
|
|
90
96
|
release(): void;
|
|
91
97
|
}
|
|
92
|
-
/** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
|
|
93
|
-
* module, else the public network), in `slots`. */
|
|
94
|
-
export declare const mediaForClaim: (env: NodeJS.ProcessEnv, web?: WebFake, slots?: SaveSlots) => MediaReader;
|
|
95
98
|
/** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
|
|
96
99
|
export declare function catalogSessionNames(catalog: Pick<ClaimMcp, "tools" | "catalogOf"> | undefined, grant: string): string[];
|
|
97
100
|
/** The run's MCP for one claim: undefined when it grants no MCP tool. Throws McpClaimRefused (a granted tool its pin lacks,
|
package/dist/runner/mcp-run.js
CHANGED
|
@@ -13,9 +13,6 @@ import { mcpClaim } from "./mcp-claim.js";
|
|
|
13
13
|
import { registryListing } from "../mcp-pin-first.js";
|
|
14
14
|
import { heldOrThrow } from "./held.js";
|
|
15
15
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
16
|
-
/** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
|
|
17
|
-
* module, else the public network), in `slots`. */
|
|
18
|
-
export const mediaForClaim = (env, web, slots) => publicMedia(async () => (web ? fakeSaveOptions(web) : fetchOptions(env, FAUX_ENV)), slots);
|
|
19
16
|
/** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
|
|
20
17
|
export function catalogSessionNames(catalog, grant) {
|
|
21
18
|
const given = (catalog?.tools ?? []).flatMap((tool) => (permissionKeys(catalog.catalogOf(tool.name) ?? "").includes(grant) ? [tool.name] : []));
|
|
@@ -60,6 +57,7 @@ export async function mcpForClaim(options) {
|
|
|
60
57
|
return undefined;
|
|
61
58
|
}
|
|
62
59
|
const network = options.network ?? systemNetwork;
|
|
60
|
+
const media = options.media;
|
|
63
61
|
const gateway = mcpGateway({
|
|
64
62
|
pin,
|
|
65
63
|
credentials: step.credentials,
|
|
@@ -81,8 +79,8 @@ export async function mcpForClaim(options) {
|
|
|
81
79
|
commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
|
|
82
80
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
83
81
|
...(options.callBounds ? { bounds: options.callBounds } : {}),
|
|
84
|
-
|
|
85
|
-
...(
|
|
82
|
+
capped: () => options.capped !== false,
|
|
83
|
+
...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
|
|
86
84
|
});
|
|
87
85
|
const catalog = new Map();
|
|
88
86
|
const declared = new Map();
|
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 ?? {});
|
package/dist/runner/monid-run.js
CHANGED
|
@@ -25,21 +25,19 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
|
|
|
25
25
|
const faux = await fauxFetch(env, FAUX_MONID_ENV);
|
|
26
26
|
return monidClient({ key: env[MONID_KEY_ENV] ?? "", ...(faux ? { fetch: faux } : {}) });
|
|
27
27
|
};
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
const overHold =
|
|
28
|
+
/** Logs a charge monid made for `name`'s call above the `heldUsd` it was held at: maxCost checks only monid's estimate,
|
|
29
|
+
* so such a charge is booked as charged (by its paid step), and the run's cap decides whether the run goes on
|
|
30
|
+
* (adapter-loop.ts paidUnder: it stops once its charges pass the cap). */
|
|
31
|
+
const overHold = (name, charged, heldUsd) => {
|
|
32
32
|
if (typeof charged !== "number" || Math.round(charged * 1e6) <= Math.round(heldUsd * 1e6))
|
|
33
33
|
return;
|
|
34
|
-
|
|
35
|
-
console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: ${words}`);
|
|
36
|
-
await stopRun(words);
|
|
34
|
+
console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: monid charged ${money(charged)}, more than the ${money(heldUsd)} held`);
|
|
37
35
|
};
|
|
38
36
|
// monid's estimate for the call `callId` priced by usage, read once the call may run, on the run's ledger `ledger`:
|
|
39
37
|
// the call sent with maxCost 0, which monid refuses unrun and uncharged, naming the estimate, or runs when it estimates
|
|
40
38
|
// the call at $0 (a free run). So the read is a paid step of the call, marked at $0 before it is sent (a crash while
|
|
41
39
|
// monid holds it leaves its possible charge on record, unknown), given back when monid refused it unrun, else settled
|
|
42
|
-
// at what monid charged, a charge above $0
|
|
40
|
+
// at what monid charged, a charge above $0 left to the run's cap as any charge above its hold is. One whose charge is unknown (no answer, FAILED with no
|
|
43
41
|
// cost) stops a capped run too: its $0 hold bounds nothing, so the cap can't be kept. One its call's signal cut off is
|
|
44
42
|
// left as a crash leaves it: the run is stopping or its claim is going.
|
|
45
43
|
const estimated = async (ledger, callId, name, at, input, signal) => {
|
|
@@ -61,7 +59,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
|
|
|
61
59
|
console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: ${words}`);
|
|
62
60
|
await stopRun(words);
|
|
63
61
|
}
|
|
64
|
-
|
|
62
|
+
overHold(name, charged, 0);
|
|
65
63
|
return { answer: step.result };
|
|
66
64
|
};
|
|
67
65
|
/** A call of the fixed-price endpoint `at` (`name`) with `input`, held at its pinned `usd`: its price read again first
|
|
@@ -86,7 +84,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
|
|
|
86
84
|
return { answer: read.answer };
|
|
87
85
|
};
|
|
88
86
|
/** One paid step for the call `callId` of `name` on the run's ledger `ledger`: held at `held.usd`, `send` run, settled at
|
|
89
|
-
* what monid says it charged; a charge above the hold
|
|
87
|
+
* what monid says it charged; a charge above the hold is logged (overHold) and left to the run's cap. */
|
|
90
88
|
const paidCall = async (ledger, callId, name, held, send) => {
|
|
91
89
|
const paid = await paidStep(ledger, callId, { name, holdUsd: held.usd, basis: held.basis, by: "monid", reported: true }, send, (outcome) => {
|
|
92
90
|
if (!("result" in outcome))
|
|
@@ -96,7 +94,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
|
|
|
96
94
|
});
|
|
97
95
|
if ("refused" in paid)
|
|
98
96
|
return paid;
|
|
99
|
-
|
|
97
|
+
overHold(name, chargeOf(paid.result), held.usd);
|
|
100
98
|
return paid;
|
|
101
99
|
};
|
|
102
100
|
const tools = names.flatMap((name) => {
|
|
@@ -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}$/;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The moved project's strict end hook: no effect dispatch while this runs, every tracked process stopped, then
|
|
2
|
+
* actual backend folder sync and stable capture. A failed/uncertain step leaves an explicit receipt, never a pointer. */
|
|
3
|
+
import type { Claim, Store } from "../store/store.js";
|
|
4
|
+
import type { RunLaunch } from "../run-launch.js";
|
|
5
|
+
import type { RunTools } from "../workspace/run-tools.js";
|
|
6
|
+
import type { ClaimComputer } from "../workspace/computer-for-claim.js";
|
|
7
|
+
import { type ProjectCheckpoint, type ProjectUncertain } from "../source-sync/checkpoints.js";
|
|
8
|
+
import { type SourceWorkspaceOptions } from "../source-sync/workspace.js";
|
|
9
|
+
export declare function runProjectCheckpoint(input: {
|
|
10
|
+
store: Store;
|
|
11
|
+
agentId: string;
|
|
12
|
+
claim: Claim;
|
|
13
|
+
launch: RunLaunch;
|
|
14
|
+
tools: Pick<RunTools, "workspace" | "settleProject">;
|
|
15
|
+
computer: ClaimComputer;
|
|
16
|
+
workspace: SourceWorkspaceOptions;
|
|
17
|
+
secrets(): Promise<readonly string[]>;
|
|
18
|
+
/** Trusted host capability already holds durable ownership through its remote-call drain and this capture. */
|
|
19
|
+
ioHeld?: true;
|
|
20
|
+
}): {
|
|
21
|
+
uncertain: () => ProjectUncertain;
|
|
22
|
+
/** Host-private evidence, never a field the child can supply in a checkpoint receipt. */
|
|
23
|
+
refusalSettled: () => boolean;
|
|
24
|
+
capture(signal: AbortSignal): Promise<ProjectCheckpoint>;
|
|
25
|
+
};
|
|
26
|
+
/** The isolated child asks only for its host-bound checkpoint; it receives no store/cache/credential capability. */
|
|
27
|
+
export declare function projectCheckpointForRun(input: Parameters<typeof runProjectCheckpoint>[0], dispatched: () => void): {
|
|
28
|
+
uncertain: () => ProjectUncertain;
|
|
29
|
+
/** Host-private evidence, never a field the child can supply in a checkpoint receipt. */
|
|
30
|
+
refusalSettled: () => boolean;
|
|
31
|
+
capture(signal: AbortSignal): Promise<ProjectCheckpoint>;
|
|
32
|
+
} | {
|
|
33
|
+
capture: (signal: AbortSignal) => Promise<ProjectCheckpoint>;
|
|
34
|
+
uncertain: () => ProjectUncertain;
|
|
35
|
+
};
|