@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34
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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +92 -50
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +30 -2
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +121 -47
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +25 -60
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +133 -9
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +16 -38
- package/dist/server.js +145 -106
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +93 -17
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +53 -18
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +30 -18
- package/dist/tools.js +97 -107
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -4,7 +4,7 @@ import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
5
5
|
import type { installSettled } from "../harness-install.js";
|
|
6
6
|
import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
|
|
7
|
-
import type
|
|
7
|
+
import { type PinnedModel, type Tier } from "../model.js";
|
|
8
8
|
import { type RunLaunch } from "../run-launch.js";
|
|
9
9
|
import type { Store } from "../store/store.js";
|
|
10
10
|
import { type Permission, type RunFiles, type SettingFrom } from "../tool-gate.js";
|
|
@@ -13,12 +13,14 @@ import { type ToolHost } from "../tools.js";
|
|
|
13
13
|
import { type HostToolCtx } from "../host-tools.js";
|
|
14
14
|
import { type LearnedWorkflow } from "../learning.js";
|
|
15
15
|
import { type ToolResults } from "../workspace/run-tools.js";
|
|
16
|
+
import { type ClaimMcp } from "./mcp-run.js";
|
|
16
17
|
import { type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
|
|
17
18
|
import { type Claim, type Journal } from "./loop-contract.js";
|
|
18
19
|
import type { ModelRoute } from "./model-route.js";
|
|
19
20
|
import { type ArchilClaimOptions } from "../workspace/archil-claim.js";
|
|
20
21
|
import { type claimComputer, type ComputerDeps } from "../workspace/computer-deps.js";
|
|
21
22
|
import type { RunComputer } from "../workspace/run-tools.js";
|
|
23
|
+
import type { ShellPlace } from "../workspace/resolve-computer.js";
|
|
22
24
|
import type { Workspace } from "../workspace/workspace.js";
|
|
23
25
|
import { type HeldRedact } from "./redact.js";
|
|
24
26
|
/** What a claim gives the shared computerForClaim: the run, its epoch, its revision, its place and any computer choice. */
|
|
@@ -52,10 +54,10 @@ export declare const PI_WIRES: readonly Wire[];
|
|
|
52
54
|
/** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
|
|
53
55
|
* durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
|
|
54
56
|
export declare const BROWSER_ON_RUNNER = true;
|
|
55
|
-
/** Whether the runner installs the browser for a run whose revision grants `granted`,
|
|
56
|
-
* (
|
|
57
|
-
* held on this process's own spend. */
|
|
58
|
-
export declare const browserListed: (host: Pick<ToolHost, "ledger">, granted: readonly string[]) => boolean;
|
|
57
|
+
/** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
|
|
58
|
+
* (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
|
|
59
|
+
* booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
|
|
60
|
+
export declare const browserListed: (host: Pick<ToolHost, "ledger" | "browserComputer">, granted: readonly string[]) => boolean;
|
|
59
61
|
/** What the runner hands the spec builder, beside the claim and the loop's own Harness (the AdapterRun): the store (its
|
|
60
62
|
* agent and run reads, and the live-viewer seam the browser tool writes through), the data directory a Mode 1 run folder
|
|
61
63
|
* sits in, the model route, and the key the live-viewer tokens are sealed under. One per runner, not per claim. */
|
|
@@ -75,6 +77,8 @@ export interface AdapterSpecDeps {
|
|
|
75
77
|
readonly routeOf: (model: string | PinnedModel | undefined, env: NodeJS.ProcessEnv, tier?: Tier, wires?: readonly Wire[], upstream?: typeof fetch, redact?: (text: string) => string) => Promise<ModelRoute>;
|
|
76
78
|
/** The run's log line (what its Workspace and computer have to say that is not a run failure). */
|
|
77
79
|
readonly log?: (message: string) => void;
|
|
80
|
+
/** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
|
|
81
|
+
readonly gradeBound?: () => AbortSignal;
|
|
78
82
|
/** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
|
|
79
83
|
* The runner gives it; a test gives its own. */
|
|
80
84
|
readonly computerForClaim: ComputerForClaim;
|
|
@@ -122,8 +126,8 @@ export declare function modelAskOf(pinned: {
|
|
|
122
126
|
* The run's gate before a call's intent, as the adapter loop asks it: the revision's tool settings and approvals over the
|
|
123
127
|
* server's, from the one store (loadToolSettings), through RunGate (decide: deny with its words, a pin, allow, ask). The
|
|
124
128
|
* adapter loop handles the ask/park/answer on the journal itself, so only the answer is read here, never RunGate's own
|
|
125
|
-
* file-based approval flow. `root`: the run's
|
|
126
|
-
*
|
|
129
|
+
* file-based approval flow. `root`: the run's folder, the run's Workspace (Mode 2: its folder on the run's disk, never a
|
|
130
|
+
* folder of this machine) or the local folder's path, for the gate's path checks; nothing in it is read.
|
|
127
131
|
*
|
|
128
132
|
* The server's settings are read again at each call, from the store (a row of the local store: no cache, no signal from
|
|
129
133
|
* the server, which may be another process), so a permission set while the run goes reaches its next call ("applies at the
|
|
@@ -139,6 +143,11 @@ export type RunPermissions = {
|
|
|
139
143
|
readonly policy: (tool: string) => Permission;
|
|
140
144
|
readonly denyFrom: (tool: string) => SettingFrom;
|
|
141
145
|
readonly refresh: () => Promise<void>;
|
|
146
|
+
/** The gate's whole decision of one call with its arguments (RunGate.decide: its deny, its argument pins, its ask or a
|
|
147
|
+
* refusal where no one can approve), as the run's own call of the tool gets it: a learned workflow's MCP node's. */
|
|
148
|
+
readonly decide: (tool: string, args: unknown) => Promise<"allow" | "ask" | {
|
|
149
|
+
deny: string;
|
|
150
|
+
}>;
|
|
142
151
|
};
|
|
143
152
|
export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
|
|
144
153
|
kind: string;
|
|
@@ -147,8 +156,9 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
|
|
|
147
156
|
harness?: string;
|
|
148
157
|
approvals?: Approvals;
|
|
149
158
|
};
|
|
150
|
-
}, root: RunFiles): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
159
|
+
}, root: RunFiles, shell?: ShellPlace): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
151
160
|
readonly permissions: RunPermissions;
|
|
161
|
+
readonly learn: (flows: readonly LearnedWorkflow[]) => void;
|
|
152
162
|
}>;
|
|
153
163
|
/** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
|
|
154
164
|
* and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
|
|
@@ -183,6 +193,9 @@ export declare function learnedWorkflowHostTool(opts: {
|
|
|
183
193
|
/** The run's gate's permissions (adapterRunGate): each call node's tool is held to them, as main holds it. */
|
|
184
194
|
readonly permissions: RunPermissions;
|
|
185
195
|
readonly ctx: HostToolCtx;
|
|
196
|
+
/** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
|
|
197
|
+
* catalog name, each run through the run's own MCP as the loop wraps it. */
|
|
198
|
+
readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
|
|
186
199
|
}): Promise<HostTool | undefined>;
|
|
187
200
|
/** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
|
|
188
201
|
* hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
|
|
@@ -2,10 +2,11 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
2
2
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
3
3
|
import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
4
4
|
import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
|
|
5
|
+
import { thinkingLevel } from "../model.js";
|
|
5
6
|
import { firstMessage } from "../run-manifest.js";
|
|
6
|
-
import { learningStartOf } from "../run-launch.js";
|
|
7
|
+
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
7
8
|
import { isObject } from "../validate.js";
|
|
8
|
-
import { runGate } from "../tool-gate.js";
|
|
9
|
+
import { deniedText, noApproverText, runGate } from "../tool-gate.js";
|
|
9
10
|
import { loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
10
11
|
import { readApprovers } from "../server-approvers.js";
|
|
11
12
|
import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
|
|
@@ -18,7 +19,7 @@ import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
|
18
19
|
import { layLearningSeed } from "./learning-seed.js";
|
|
19
20
|
import { learningWorkspace } from "../learn/folder.js";
|
|
20
21
|
import { learningEndOfRun } from "./learning-end.js";
|
|
21
|
-
import { LEARNED_WORKFLOW_TOOL, learnedWorkflowTool } from "../learned-workflow.js";
|
|
22
|
+
import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
|
|
22
23
|
import { PORT_PROVIDER } from "../port-models.js";
|
|
23
24
|
import { promptOf, readsFiles } from "../skills.js";
|
|
24
25
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
@@ -28,7 +29,7 @@ import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
|
28
29
|
import { INPUTS_DIR, UPLOADS_DIR, Uploads } from "../uploads.js";
|
|
29
30
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
30
31
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
31
|
-
import { claimSecrets, withModelKeys } from "./claim-secrets.js";
|
|
32
|
+
import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
|
|
32
33
|
import { mcpForClaim } from "./mcp-run.js";
|
|
33
34
|
import { join } from "node:path";
|
|
34
35
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
@@ -50,10 +51,10 @@ const BROWSER_TOOL = "browser";
|
|
|
50
51
|
/** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
|
|
51
52
|
* durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
|
|
52
53
|
export const BROWSER_ON_RUNNER = true;
|
|
53
|
-
/** Whether the runner installs the browser for a run whose revision grants `granted`,
|
|
54
|
-
* (
|
|
55
|
-
* held on this process's own spend. */
|
|
56
|
-
export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && granted.includes(BROWSER_TOOL);
|
|
54
|
+
/** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
|
|
55
|
+
* (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
|
|
56
|
+
* booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
|
|
57
|
+
export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && (granted.includes(BROWSER_TOOL) || host.browserComputer !== undefined);
|
|
57
58
|
/** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
|
|
58
59
|
* model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
|
|
59
60
|
* overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
|
|
@@ -78,20 +79,59 @@ export function capModelOf(route) {
|
|
|
78
79
|
export function modelAskOf(pinned, ref) {
|
|
79
80
|
return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
|
|
80
81
|
}
|
|
81
|
-
export async function adapterRunGate(store, claim, revision, root) {
|
|
82
|
+
export async function adapterRunGate(store, claim, revision, root, shell) {
|
|
82
83
|
let current = await storeSettings(store);
|
|
83
84
|
const approvers = await readApprovers(store.settings);
|
|
84
85
|
// A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
|
|
85
86
|
const folder = typeof root === "string" ? root : COMPUTER_ROOT;
|
|
86
|
-
|
|
87
|
+
// Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
|
|
88
|
+
// default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
|
|
89
|
+
const gate = runGate({ root: folder, work: folder, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
|
|
90
|
+
// The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
|
|
91
|
+
let learned = [];
|
|
87
92
|
const decide = async (call) => {
|
|
88
93
|
current = await storeSettings(store);
|
|
89
|
-
|
|
94
|
+
const decision = await gate.decide(call.tool, call.args);
|
|
95
|
+
// A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings, decided for the whole call
|
|
96
|
+
// before any node runs, never mid-run: one set to deny refuses the call in the gate's words, nothing sent; one set to
|
|
97
|
+
// ask asks for the call, up front, on the run's one card (a running workflow can't park mid-call: it is never run
|
|
98
|
+
// again after a crash), and the person's allow lets that call's MCP nodes run, and only that call's.
|
|
99
|
+
// Checked whether the learned_workflow call is itself allowed or asked: a workflow that can't run is never put to a
|
|
100
|
+
// person.
|
|
101
|
+
if (call.tool !== LEARNED_WORKFLOW_TOOL || typeof decision === "object")
|
|
102
|
+
return decision;
|
|
103
|
+
const tools = await mcpOf(call.args);
|
|
104
|
+
const refused = (why) => ({ deny: `The learned workflow ${String(call.args.name)} was not run: ${why}` });
|
|
105
|
+
const denied = tools.find((tool) => gate.policy(tool) === "deny");
|
|
106
|
+
if (denied)
|
|
107
|
+
return refused(deniedText(denied, undefined, gate.denyFrom(denied)));
|
|
108
|
+
const asks = tools.filter((tool) => gate.policy(tool) === "ask");
|
|
109
|
+
// An ask no one can answer (the server's accounts off) is refused at once in the gate's words, never parked.
|
|
110
|
+
if (asks.length && !approvers)
|
|
111
|
+
return refused(noApproverText(asks[0], "no"));
|
|
112
|
+
// A card that could not name every MCP tool the person would approve (past its preview's bound) is never shown: the
|
|
113
|
+
// call is refused, so no allow covers a tool its approver did not see.
|
|
114
|
+
if (asks.length && !learnedAskFits(asks))
|
|
115
|
+
return refused(`its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.`);
|
|
116
|
+
return asks.length ? "ask" : decision;
|
|
117
|
+
};
|
|
118
|
+
/** The MCP tools the learned workflow a learned_workflow call names can call; none for another call or workflow. */
|
|
119
|
+
const mcpOf = async (args) => {
|
|
120
|
+
const flow = learned.find((one) => one.name === args?.name);
|
|
121
|
+
return flow ? learnedMcpTools(flow.workflow) : [];
|
|
90
122
|
};
|
|
91
123
|
// An ask is named as main's pending approval is (RunGate.askedAs: its settings key), beside the decision, which is
|
|
92
124
|
// unchanged. The permissions are the learned workflow's (main's toolGate.policy and denyFrom), over the same settings.
|
|
93
|
-
const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); } };
|
|
94
|
-
|
|
125
|
+
const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); }, decide: (tool, args) => gate.decide(tool, args) };
|
|
126
|
+
// What a learned_workflow call's card shows beside its own input: every MCP tool set to ask that the workflow can call,
|
|
127
|
+
// and that their arguments are decided while it runs, so the person sees what they approve.
|
|
128
|
+
const askedFor = async (tool, args) => {
|
|
129
|
+
if (tool !== LEARNED_WORKFLOW_TOOL)
|
|
130
|
+
return undefined;
|
|
131
|
+
const asks = (await mcpOf(args)).filter((one) => gate.policy(one) === "ask");
|
|
132
|
+
return asks.length ? learnedAskShown(asks) : undefined;
|
|
133
|
+
};
|
|
134
|
+
return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, learn: (flows) => void (learned = flows) });
|
|
95
135
|
}
|
|
96
136
|
/** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
|
|
97
137
|
* and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
|
|
@@ -221,9 +261,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
221
261
|
// ask it leaves into an allow). The adapter loop asks `gate` and handles the ask/park/answer on the journal itself, so
|
|
222
262
|
// only the permission is read here, never runGate's own file-based approval flow.
|
|
223
263
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
224
|
-
// The gate
|
|
225
|
-
//
|
|
226
|
-
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace);
|
|
264
|
+
// The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
|
|
265
|
+
// the same path), for its path checks; it reads nothing in it.
|
|
266
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
|
|
227
267
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
228
268
|
// uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
|
|
229
269
|
// launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
|
|
@@ -263,47 +303,66 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
263
303
|
// A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
|
|
264
304
|
// and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
|
|
265
305
|
// skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
|
|
266
|
-
// before the run's tools are bound. A learning fault
|
|
267
|
-
const seedLaid = start
|
|
306
|
+
// before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
|
|
307
|
+
const seedLaid = start && !seedFailed(start)
|
|
268
308
|
? await layLearningSeed({
|
|
269
309
|
work: ws.workspace,
|
|
270
310
|
seed: start.seed,
|
|
271
311
|
folder: () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil })),
|
|
272
312
|
own: Object.keys(revisionRow.skills ?? {}),
|
|
273
|
-
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data))),
|
|
313
|
+
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
|
|
274
314
|
log,
|
|
275
315
|
})
|
|
276
316
|
: undefined;
|
|
317
|
+
// The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
|
|
318
|
+
// chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
|
|
319
|
+
// onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
|
|
320
|
+
// becomes its model's.
|
|
321
|
+
const workflows = seedLaid?.workflows ?? [];
|
|
322
|
+
if (learnsWorkflows(revision.kind, workflows)) {
|
|
323
|
+
const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
|
|
324
|
+
holdClaimed(cut, learnedKeys);
|
|
325
|
+
Object.assign(toolEnv, learnedKeys);
|
|
326
|
+
}
|
|
277
327
|
// The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
|
|
278
328
|
// Harness is open before the session, and at the run's end (the browser tool's reconcile and release hang off these). The
|
|
279
329
|
// adapter loop runs them from the spec's `lifecycle` (adapter-loop.ts hostLifecycle).
|
|
280
330
|
const life = hostLifecycle();
|
|
281
331
|
// The ToolHost the non-hand tools (browser, web, MCP, decisions, monid) bind through (buildToolHost, the one the CLI
|
|
282
332
|
// spec builds too), on the claim's keys and the run's one ledger and redactor.
|
|
283
|
-
|
|
333
|
+
// An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
|
|
334
|
+
const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
|
|
335
|
+
const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
|
|
284
336
|
// The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
|
|
285
337
|
// Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
|
|
286
338
|
const results = new Map();
|
|
287
|
-
const handTools = tools.hostTools(withKindTools(granted, tools),
|
|
339
|
+
const handTools = tools.hostTools(withKindTools(granted, tools), results);
|
|
288
340
|
// The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
|
|
289
341
|
// words, pass the run's one redactor before the harness, the model or the record has them.
|
|
290
|
-
|
|
342
|
+
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate).
|
|
343
|
+
gate.learn(workflows);
|
|
344
|
+
const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, mcp)).map((tool) => answersCut(tool, cut));
|
|
291
345
|
const sessionTools = [...handTools, ...nonHandTools];
|
|
292
346
|
// The run's system prompt, as main's per-run process builds it (app.ts): the environment line first (environment.ts, as
|
|
293
347
|
// pi installs it before every other section), then the revision's instructions with what the agent learned laid in
|
|
294
348
|
// (learning.ts laidLearned, from the launch's learning start — the # Learned section decided once at launch, so the runner
|
|
295
|
-
// reads no learning folder
|
|
296
|
-
//
|
|
297
|
-
|
|
349
|
+
// reads no learning folder), its own skills through skills.ts promptOf, then the effort guidance (the launch's effort,
|
|
350
|
+
// never this process's environment). The one path for every harness.
|
|
351
|
+
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
352
|
+
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
298
353
|
const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
|
|
299
354
|
const guidance = effortGuidance(launch.effort);
|
|
300
355
|
const system = [environmentLine(), instructions, guidance].filter((line) => Boolean(line));
|
|
356
|
+
// The level pi thinks at: the launch's effort (the run's own, else its revision's, else the host's), every level pi's
|
|
357
|
+
// agent takes; none, pi's default.
|
|
358
|
+
const thinking = thinkingLevel(launch.effort);
|
|
301
359
|
const session = {
|
|
302
360
|
key: `run:${claim.runId}`,
|
|
303
361
|
label: runRow.agentId,
|
|
304
362
|
system,
|
|
305
363
|
tools: sessionTools,
|
|
306
364
|
context: "fresh",
|
|
365
|
+
...(thinking ? { thinking: thinking } : {}),
|
|
307
366
|
};
|
|
308
367
|
// The person's first message: the start body's content, with the run's file manifest beside it (run-manifest.ts), read
|
|
309
368
|
// through the run's Workspace (Mode 2: its inputs/ on the disk, never a folder of this machine).
|
|
@@ -401,7 +460,8 @@ export async function learnedWorkflowHostTool(opts) {
|
|
|
401
460
|
return undefined;
|
|
402
461
|
const flows = opts.workflows;
|
|
403
462
|
const models = await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL);
|
|
404
|
-
const
|
|
463
|
+
const mcpTools = (opts.mcp?.tools ?? []).map((one) => opts.mcp.catalogOf(one.name)).filter((name) => typeof name === "string");
|
|
464
|
+
const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: models, modelOf: () => ({ provider: PORT_PROVIDER, modelId: "session" }), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools });
|
|
405
465
|
return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
|
|
406
466
|
}
|
|
407
467
|
/** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
|
|
@@ -451,11 +511,10 @@ export function answersCut(tool, cut) {
|
|
|
451
511
|
export function buildToolHost(opts) {
|
|
452
512
|
const { root, claim, run, life } = opts;
|
|
453
513
|
return {
|
|
454
|
-
// The run's directory and its per-claim environment
|
|
455
|
-
//
|
|
514
|
+
// The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
|
|
515
|
+
// environment only.
|
|
456
516
|
where: { root, work: root, ref: { id: claim.runId } },
|
|
457
517
|
env: opts.env,
|
|
458
|
-
coding: { tools: [], extension: { name: "coding", tools: [] } },
|
|
459
518
|
install: (extension) => run.registry.install(extension),
|
|
460
519
|
onConversation: life.register.onConversation,
|
|
461
520
|
beforeResume: life.register.beforeResume,
|
|
@@ -463,7 +522,6 @@ export function buildToolHost(opts) {
|
|
|
463
522
|
personWait: life.register.personWait,
|
|
464
523
|
// The run row's summary staged on a commit of the run's (a hand-over's wait, its claim held: run.needs_input).
|
|
465
524
|
...(run.rowSummaryOn ? { rowSummaryOn: run.rowSummaryOn } : {}),
|
|
466
|
-
handoverInJournal: true,
|
|
467
525
|
store: opts.store,
|
|
468
526
|
claim,
|
|
469
527
|
sealKey: opts.sealKey,
|
|
@@ -500,7 +558,7 @@ export async function webHostTools(host, granted, ctx) {
|
|
|
500
558
|
}
|
|
501
559
|
return tools;
|
|
502
560
|
}
|
|
503
|
-
async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions) {
|
|
561
|
+
async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, mcp) {
|
|
504
562
|
// Fail closed (browserListed): the browser binds only on the native route (BROWSER_ON_RUNNER) and with the claim's
|
|
505
563
|
// one-ledger booking on its ToolHost (host.ledger.paid); otherwise its extension is not installed. learned_workflow
|
|
506
564
|
// binds below with no web tool, so a learned run with no web tool still lists it.
|
|
@@ -513,7 +571,7 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
|
|
|
513
571
|
// the session's tools the harness is told of: its model nodes run on the session's proxied models (run.ledger.models),
|
|
514
572
|
// each a request on the run's one route labelled learned_workflow. The agent's scoped keys (host.env) are its call
|
|
515
573
|
// nodes'.
|
|
516
|
-
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx });
|
|
574
|
+
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, ...(mcp ? { mcp } : {}) });
|
|
517
575
|
if (learned)
|
|
518
576
|
tools.push(learned);
|
|
519
577
|
// The browser (tl-browser), on pi's native route: tools.ts's own binding on this run's ToolHost (its store, claim and seal
|
|
@@ -19,6 +19,10 @@ export const RUNNER_HARNESSES = {
|
|
|
19
19
|
record: "loop",
|
|
20
20
|
adapter: async (launch, extra = {}) => {
|
|
21
21
|
const claude = (await import(CLAUDE_PACKAGE));
|
|
22
|
+
// The CLI the adapter checks, checked first off the event loop: a pass is kept, and the adapter's own check answers
|
|
23
|
+
// from it; a failure is the adapter's to report (warm).
|
|
24
|
+
if (!extra.standIn)
|
|
25
|
+
await claude.verifyClaudeAgentCliAsync(extra.cliPath ?? claude.claudeAgentExecutable());
|
|
22
26
|
return claude.claudeAgentAdapter({
|
|
23
27
|
model: launch.model,
|
|
24
28
|
provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}) },
|
|
@@ -33,6 +37,9 @@ export const RUNNER_HARNESSES = {
|
|
|
33
37
|
record: "loop",
|
|
34
38
|
adapter: async (launch, extra = {}) => {
|
|
35
39
|
const codex = (await import(CODEX_PACKAGE));
|
|
40
|
+
// Its binary checked first off the event loop, as claude-agent's CLI is (warm): a failure is the adapter's to report.
|
|
41
|
+
if (!extra.standIn)
|
|
42
|
+
await codex.verifyCodexAsync(extra.binary).catch(() => undefined);
|
|
36
43
|
// Codex's provider is its origin and credential, as serve gives it today (adapters.ts, codexOf): no headers.
|
|
37
44
|
return codex.codexAdapter({
|
|
38
45
|
model: launch.model,
|
|
@@ -48,7 +55,10 @@ export const RUNNER_HARNESSES = {
|
|
|
48
55
|
record: "loop",
|
|
49
56
|
adapter: async (launch, extra = {}) => {
|
|
50
57
|
// OpenCode's adapter is serve's own (its pinned binary is checked when the adapter is made); loaded when first asked.
|
|
51
|
-
const { openCodeAdapter } = await import("../../harness-opencode/index.js");
|
|
58
|
+
const { openCodeAdapter, verifyOpenCodeAsync } = await import("../../harness-opencode/index.js");
|
|
59
|
+
// Its binary checked first off the event loop, as codex's is (warm): a failure is the adapter's to report.
|
|
60
|
+
if (!extra.standIn)
|
|
61
|
+
await verifyOpenCodeAsync().catch(() => undefined);
|
|
52
62
|
return openCodeAdapter({
|
|
53
63
|
model: launch.model,
|
|
54
64
|
provider: { origin: launch.provider.origin, credential: launch.provider.credential },
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { Models } from "@earendil-works/pi-ai";
|
|
3
3
|
import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
|
|
4
|
-
import type
|
|
4
|
+
import { type AgentAdapter, type SessionIO, type Wire } from "@parcha/agentrun-kernel";
|
|
5
5
|
import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
|
|
6
|
-
import { CALL_REFUSED } from "
|
|
6
|
+
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
7
7
|
/** What the adapter loop lends pi for one claim: the run's Harness, its registry, and where pi's models go. */
|
|
8
8
|
export interface PiRun {
|
|
9
9
|
readonly harness: Harness;
|
|
@@ -101,3 +101,13 @@ export declare function refusalWords(): {
|
|
|
101
101
|
} | undefined;
|
|
102
102
|
readonly held: number;
|
|
103
103
|
};
|
|
104
|
+
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
105
|
+
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
106
|
+
* default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
|
|
107
|
+
* go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
|
|
108
|
+
* continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
|
|
109
|
+
* Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
|
|
110
|
+
export declare const HOST_TOOL_OUTPUT: Readonly<{
|
|
111
|
+
maxLines: number;
|
|
112
|
+
maxBytes: number;
|
|
113
|
+
}>;
|
|
@@ -2,12 +2,13 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
|
|
|
2
2
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
3
|
import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
|
|
4
4
|
import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
|
|
5
|
+
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
5
6
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
6
7
|
import { randomBytes } from "node:crypto";
|
|
7
8
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
8
9
|
import { sessionProvider } from "../../port-models.js";
|
|
9
10
|
import { KINDS } from "../journal-kinds.js";
|
|
10
|
-
import { CALL_REFUSED } from "
|
|
11
|
+
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
11
12
|
const PROVIDER = "agentrun-session";
|
|
12
13
|
const INPUT_REQUEST = "agentrun:input";
|
|
13
14
|
/** pi as an AgentAdapter for one claim's run. */
|
|
@@ -138,7 +139,8 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
138
139
|
// session's tools and the run's native extensions, on every open. A conversation a native tool opens takes this agent's
|
|
139
140
|
// model (pi copies its owner's), so its requests go through this session's proxy.
|
|
140
141
|
const instructions = spec.system.join("\n\n");
|
|
141
|
-
|
|
142
|
+
// Its thinking level, the session's (the run's effort), on every open; none leaves pi's default.
|
|
143
|
+
const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}), ...(spec.thinking ? { thinkingLevel: spec.thinking } : {}) };
|
|
142
144
|
const root = await run.harness.root(context, { agent });
|
|
143
145
|
await root.configure(agent, context);
|
|
144
146
|
// The run's input submission, if one was placed: its state says where the session is. Answered: idle. Open, or settled
|
|
@@ -237,15 +239,24 @@ export function refusalWords() {
|
|
|
237
239
|
},
|
|
238
240
|
};
|
|
239
241
|
}
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
242
|
+
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
243
|
+
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
244
|
+
* default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
|
|
245
|
+
* go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
|
|
246
|
+
* continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
|
|
247
|
+
* Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
|
|
248
|
+
export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS + 1, maxBytes: HOST_RESULT_MAX_CHARS * 3 });
|
|
249
|
+
/** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows, passed
|
|
250
|
+
* whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
|
|
251
|
+
* agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
|
|
252
|
+
* and pi's output stream (the running tool's live slot). */
|
|
243
253
|
function piTool(tool, io) {
|
|
244
254
|
return defineTool({
|
|
245
255
|
name: tool.name,
|
|
246
256
|
description: tool.description,
|
|
247
257
|
parameters: tool.inputSchema,
|
|
248
258
|
replay: tool.replay === "safe" ? "safe" : "unsafe",
|
|
259
|
+
outputLimits: HOST_TOOL_OUTPUT,
|
|
249
260
|
execute: async (args, api, toolContext) => {
|
|
250
261
|
io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
|
|
251
262
|
const ref = (await api.agent(toolContext)).model;
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
|
+
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
2
|
+
export declare const DRAIN_TIMEOUT = "30s";
|
|
3
|
+
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
4
|
+
* number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
|
|
5
|
+
* memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
|
|
6
|
+
* before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
|
|
7
|
+
export declare function besideRunnerOptions(serve: {
|
|
8
|
+
maxRuns?: number;
|
|
9
|
+
drainTimeout?: string;
|
|
10
|
+
}, env: NodeJS.ProcessEnv): {
|
|
11
|
+
loops: number;
|
|
12
|
+
drainMs: number;
|
|
13
|
+
};
|
|
14
|
+
/** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
|
|
15
|
+
* and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
|
|
16
|
+
* the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
|
|
17
|
+
export declare function besideStopping(server: {
|
|
18
|
+
runs: number;
|
|
19
|
+
boundMs: number;
|
|
20
|
+
}, held: number, drainMs: number): {
|
|
21
|
+
runs: number;
|
|
22
|
+
boundMs: number;
|
|
23
|
+
};
|
|
1
24
|
/** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
|
|
2
25
|
* its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
|
|
3
26
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
4
|
-
* caller hands its own: the template eval's in-process server, its faux's).
|
|
5
|
-
*
|
|
6
|
-
|
|
27
|
+
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
28
|
+
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
29
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
|
|
30
|
+
* closes its store. */
|
|
31
|
+
export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor }?: {
|
|
7
32
|
loops?: number;
|
|
33
|
+
drainMs?: number;
|
|
8
34
|
env?: NodeJS.ProcessEnv;
|
|
35
|
+
janitor?: boolean;
|
|
9
36
|
}): Promise<{
|
|
10
37
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
11
38
|
close: () => Promise<void>;
|
package/dist/runner/beside.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
// A runner beside a server on the same data directory: the CLI start's server-and-runner, the `runner` subcommand and
|
|
2
2
|
// the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
|
|
3
|
+
import { maxRunsOf } from "../host.js";
|
|
4
|
+
import { durationMs } from "../print.js";
|
|
5
|
+
import { runnerCloseBoundMs } from "./runner.js";
|
|
6
|
+
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
7
|
+
export const DRAIN_TIMEOUT = "30s";
|
|
8
|
+
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
9
|
+
* number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
|
|
10
|
+
* memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
|
|
11
|
+
* before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
|
|
12
|
+
export function besideRunnerOptions(serve, env) {
|
|
13
|
+
const drainTimeout = serve.drainTimeout ?? DRAIN_TIMEOUT;
|
|
14
|
+
const drainMs = durationMs(drainTimeout);
|
|
15
|
+
if (drainMs === undefined)
|
|
16
|
+
throw new Error(`the drain timeout ${drainTimeout} is not a duration such as 8s`);
|
|
17
|
+
return { loops: maxRunsOf(env, serve.maxRuns), drainMs };
|
|
18
|
+
}
|
|
19
|
+
/** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
|
|
20
|
+
* and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
|
|
21
|
+
* the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
|
|
22
|
+
export function besideStopping(server, held, drainMs) {
|
|
23
|
+
return { runs: server.runs + held, boundMs: Math.max(server.boundMs, runnerCloseBoundMs(drainMs)) };
|
|
24
|
+
}
|
|
3
25
|
/** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
|
|
4
26
|
* its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
|
|
5
27
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
6
|
-
* caller hands its own: the template eval's in-process server, its faux's).
|
|
7
|
-
*
|
|
8
|
-
|
|
28
|
+
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
29
|
+
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
30
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
|
|
31
|
+
* closes its store. */
|
|
32
|
+
export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {}) {
|
|
9
33
|
const { startRunner } = await import("./runner.js");
|
|
10
34
|
const { dispatchRunner } = await import("./harness-loops.js");
|
|
11
35
|
const { routeOf } = await import("./model-route.js");
|
|
@@ -36,6 +60,13 @@ export async function runnerBeside(dataDir, { loops, env } = {}) {
|
|
|
36
60
|
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
37
61
|
const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
|
|
38
62
|
const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
// It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
|
|
64
|
+
const { runnerMemory } = await import("./memory-claim.js");
|
|
65
|
+
const runner = startRunner({ store, createLoop, memory: runnerMemory(store), ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
66
|
+
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
67
|
+
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
68
|
+
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
69
|
+
const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
|
|
70
|
+
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
71
|
+
return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
|
|
41
72
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { LearnedWorkflow } from "../learning.js";
|
|
1
2
|
import type { RunLaunch } from "../run-launch.js";
|
|
2
3
|
import type { SealedKeys } from "../store/store.js";
|
|
3
|
-
import type { Revision } from "
|
|
4
|
+
import type { Revision } from "../agent-rows.js";
|
|
4
5
|
/** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
|
|
5
6
|
* environment (its own, with no server secret in it: those are the store's). */
|
|
6
7
|
export interface ClaimSecretsDeps {
|
|
@@ -15,6 +16,14 @@ export interface ClaimSecretsDeps {
|
|
|
15
16
|
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
16
17
|
* decision provider keys. A fresh object per claim, so no run's keys reach another's. */
|
|
17
18
|
export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
|
|
19
|
+
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
20
|
+
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
21
|
+
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
22
|
+
* run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
|
|
23
|
+
* lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
|
|
24
|
+
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
25
|
+
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
26
|
+
export declare function learnedDecisionKeys(deps: ClaimSecretsDeps, workflows: readonly Pick<LearnedWorkflow, "workflow">[], allowed: (provider: string) => boolean): Promise<Record<string, string>>;
|
|
18
27
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
19
28
|
export declare const MODEL_KEY_NAMES: readonly string[];
|
|
20
29
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|