@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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 +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
3
3
|
import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
@@ -24,10 +24,12 @@ import type { RunComputerHold } from "./computer-journal.js";
|
|
|
24
24
|
import type { ShellPlace } from "../workspace/resolve-computer.js";
|
|
25
25
|
import type { Workspace } from "../workspace/workspace.js";
|
|
26
26
|
import { type HeldRedact } from "./redact.js";
|
|
27
|
-
/** What a claim gives the shared computerForClaim: the run, its epoch,
|
|
27
|
+
/** What a claim gives the shared computerForClaim: the run, its epoch, the claim itself (a live view's row is fenced on it
|
|
28
|
+
* and names its runner), its revision, its place and any computer choice. */
|
|
28
29
|
export interface ClaimLaunch {
|
|
29
30
|
readonly runId: string;
|
|
30
31
|
readonly epoch: number;
|
|
32
|
+
readonly claim?: unknown;
|
|
31
33
|
readonly revisionId: string;
|
|
32
34
|
readonly place?: unknown;
|
|
33
35
|
readonly computer?: unknown;
|
|
@@ -116,6 +118,10 @@ export interface AdapterSpecDeps {
|
|
|
116
118
|
/** A test runner's fake GitHub MCP origin, the one a github_app server may be at (mcp-claim.ts githubMcpOrigin):
|
|
117
119
|
* for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP (github.ts GITHUB_MCP_ORIGIN). Only a test's in-process runner sets it; the CLI's runner never does. */
|
|
118
120
|
readonly githubMcpOrigin?: string;
|
|
121
|
+
/** Whether this runner's runs may reach an MCP server whose URL is on loopback: only a runner beside a local-install
|
|
122
|
+
* server (runner/beside.ts, Serve.localInstall) is told so, by that server in its own process. Absent, never: a hosted
|
|
123
|
+
* or standalone runner's loopback is its host's other services. */
|
|
124
|
+
readonly mcpLoopback?: boolean;
|
|
119
125
|
/** For tests only: the adapter loop's model retry (adapter-loop.ts retry and stream), so a test whose provider fails a run
|
|
120
126
|
* on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
|
|
121
127
|
* it; absent, MODEL_RETRY and MODEL_STREAM. */
|
|
@@ -235,6 +241,8 @@ export declare function learnedWorkflowHostTool(opts: {
|
|
|
235
241
|
/** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
|
|
236
242
|
* catalog name, each run through the run's own MCP as the loop wraps it. */
|
|
237
243
|
readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
|
|
244
|
+
/** The run's own Workspace (Mode 2: its folder on the run's disk): a decision node's images are read through it. */
|
|
245
|
+
readonly workspace?: Workspace;
|
|
238
246
|
/** The model a node on the session's own port runs on (a node of no tier, or of a tier not in `tiers`), as the run's
|
|
239
247
|
* route names it: what its trace says it ran on. A node of a tier in `tiers` names that tier's model. */
|
|
240
248
|
readonly modelName?: (tier: string | undefined) => string | undefined;
|
|
@@ -243,7 +251,7 @@ export declare function learnedWorkflowHostTool(opts: {
|
|
|
243
251
|
* hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
|
|
244
252
|
* `gated` is undefined here, as for the hands). Their paid requests are booked by the adapter loop on the run's one ledger
|
|
245
253
|
* (bookedIn), as main books them, so they run. The browser (through host.liveViewers), MCP (the MCP claim step's
|
|
246
|
-
* mcpForClaim(claim, store, sealKey, pin) -> { sessionMcp,
|
|
254
|
+
* mcpForClaim(claim, store, sealKey, pin) -> { sessionMcp, release }), the learned workflow and decisions are
|
|
247
255
|
* each a named todo, added as their seams land. */
|
|
248
256
|
/** The run's live-viewer writers over the store (browser-live.ts): a session's hand-over written sealed, and gone. Its
|
|
249
257
|
* viewer token, minted in the run, is held by `cut`, the run's one redactor, as it is handed over, before it is written. */
|
|
@@ -2,13 +2,15 @@ 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 { inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
5
|
+
import { decisionProvidersIn } from "../decisions.js";
|
|
5
6
|
import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
|
|
7
|
+
import { runnerLiveOf } from "../live-reach.js";
|
|
6
8
|
import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes } from "../model.js";
|
|
7
9
|
import { firstMessage } from "../run-manifest.js";
|
|
8
10
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
9
11
|
import { isObject } from "../validate.js";
|
|
10
12
|
import { deniedText, mcpServersOf, noApproverText, runGate } from "../tool-gate.js";
|
|
11
|
-
import { loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
13
|
+
import { DECISION_PROVIDER_KEYS, loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
12
14
|
import { readApprovers } from "../server-approvers.js";
|
|
13
15
|
import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
|
|
14
16
|
import { hostToolOf } from "../host-tools.js";
|
|
@@ -19,7 +21,7 @@ import { effortGuidance } from "../effort-guidance.js";
|
|
|
19
21
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
20
22
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
21
23
|
import { learningWorkspace } from "../learn/folder.js";
|
|
22
|
-
import { learningEndOfRun } from "./learning-end.js";
|
|
24
|
+
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
23
25
|
import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
|
|
24
26
|
import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
|
|
25
27
|
import { promptOf, readsFiles } from "../skills.js";
|
|
@@ -30,20 +32,25 @@ import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
|
30
32
|
import { copyRunFiles } from "../uploads.js";
|
|
31
33
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
32
34
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
33
|
-
import {
|
|
35
|
+
import { durableWait } from "../workflow/pi-versions.js";
|
|
36
|
+
import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
34
37
|
import { mcpForClaim } from "./mcp-run.js";
|
|
35
38
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
36
39
|
import { piAdapter } from "./adapters/pi.js";
|
|
40
|
+
import { computerCodemode } from "./adapters/pi-computer.js";
|
|
37
41
|
import { agentEntriesOf } from "./loop.js";
|
|
38
42
|
import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
|
|
39
43
|
import { wireName } from "../catalog.js";
|
|
40
44
|
import { ClaimRefused } from "./loop-contract.js";
|
|
41
|
-
import { runMetrics } from "./metrics.js";
|
|
45
|
+
import { bookedSpend, runEndCost, runMetrics } from "./metrics.js";
|
|
46
|
+
import { journalEntries } from "./journal-reader.js";
|
|
42
47
|
import { specBuilt } from "./spec-holds.js";
|
|
43
48
|
import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
44
49
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
45
50
|
import { computerReadyWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
46
51
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
52
|
+
import { heldSpecOf } from "./held-run.js";
|
|
53
|
+
import { loopComputerOf } from "./computer-channel.js";
|
|
47
54
|
import { githubAppAccess } from "./github-app.js";
|
|
48
55
|
import { prCheckoutForClaim } from "./pr-checkout.js";
|
|
49
56
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
@@ -145,7 +152,14 @@ export async function adapterRunGate(store, claim, revision, root, shell, mcpSer
|
|
|
145
152
|
};
|
|
146
153
|
// The revision's tool-call budget (tool-budget.ts), which the adapter loop holds each conversation's calls to.
|
|
147
154
|
const toolCalls = revision.body.maxToolCalls;
|
|
148
|
-
|
|
155
|
+
// A tool's setting now, read from the store as each call's is (SessionIO.permission: Codex's live search, which runs
|
|
156
|
+
// inside a model request, is offered only while it says allow). A read that fails is a deny, never the last good read's
|
|
157
|
+
// allow: a deny saved since may be in what did not read, and no call reaches the gate to say otherwise.
|
|
158
|
+
const permission = async (tool) => {
|
|
159
|
+
current = await storeSettings(store);
|
|
160
|
+
return current.unreadable ? "deny" : gate.policy(tool);
|
|
161
|
+
};
|
|
162
|
+
return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, permission, learn: (flows) => void (learned = flows), ...(toolCalls === undefined ? {} : { toolCalls }) });
|
|
149
163
|
}
|
|
150
164
|
/** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
|
|
151
165
|
* and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
|
|
@@ -221,15 +235,15 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
221
235
|
// credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
|
|
222
236
|
// anything the spec would have to let go: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its
|
|
223
237
|
// words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
|
|
224
|
-
// A credential the claim opens mid-run (a GitHub App token, a per_run server's
|
|
238
|
+
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
|
|
225
239
|
const hold = (values) => cut.hold(values);
|
|
226
|
-
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
|
|
240
|
+
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.mcpLoopback ? { loopback: true } : {}) });
|
|
227
241
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
228
242
|
holds.hold({ passed: mcp });
|
|
229
243
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
230
244
|
// Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
|
|
231
245
|
// when the computer cannot be had: the run fails in its words.
|
|
232
|
-
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
|
|
246
|
+
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
|
|
233
247
|
// revokeMount removes the run's Archil mount credential when the computer is released (and if a start fails after a mint);
|
|
234
248
|
// the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent. What
|
|
235
249
|
// became of the agent's own computer (a persistent setting) is said on the run's timeline.
|
|
@@ -239,6 +253,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
239
253
|
// A desktop's or a phone's hold (the person's take-over) wraps its ports: a call made while the person holds it waits,
|
|
240
254
|
// and the agent's hand-over (computer_request_handoff) asks the person through it.
|
|
241
255
|
holds.hold({ computer });
|
|
256
|
+
const loopComputer = loopComputerOf(computer.computer, computer.held);
|
|
257
|
+
const heldComputer = heldSpecOf(launch, loopComputer);
|
|
242
258
|
// Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv).
|
|
243
259
|
const bashPolicy = bashPolicyOf(body.toolSettings);
|
|
244
260
|
const tools = await runTools(ws.workspace, computer.computer, { mode, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }) });
|
|
@@ -269,7 +285,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
269
285
|
// (adapter-loop waitInClaim, the browser's personWait below). It stays out of the session's host tools and REPLAY, so a CLI harness still
|
|
270
286
|
// refuses it (runnable.ts). pi only.
|
|
271
287
|
// - the browser's durable extension, when the run gets one (bindNonHandTools, below, before the session opens).
|
|
272
|
-
|
|
288
|
+
// - pi's code mode, with a desktop or a phone (pi-computer.ts): the `codemode` tool beside the run's own, its scripts
|
|
289
|
+
// with `computer` bound on the run's held port.
|
|
290
|
+
const native = [...(granted.includes(ASK_TOOL) ? [defineExtension({ name: "ask_person", tools: [askPerson] })] : []), ...(tools.computer ? [computerCodemode(tools.computer)] : [])];
|
|
273
291
|
// pi-native tools in the session's own extension (PiAdapterOptions.tools): the subagent tool, pushed below.
|
|
274
292
|
const piTools = [];
|
|
275
293
|
// A run granted subagent (runner/subagent.ts): the model of each of its tiers, the revision's own (modelTiers) else the
|
|
@@ -309,6 +327,10 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
309
327
|
...(route.like ? { like: route.like } : {}),
|
|
310
328
|
...(route.price ? { price: route.price } : {}),
|
|
311
329
|
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
330
|
+
// The run's web_search is its provider's hosted search (the launch's plane, as its start resolved it): the session's
|
|
331
|
+
// proxy admits that search's one request (it goes through the session's port: buildToolHost's `search`) and books it
|
|
332
|
+
// with each search it ran.
|
|
333
|
+
...(launch.plane?.web_search === "native" ? { webSearch: true } : {}),
|
|
312
334
|
tiers: tierRoutes,
|
|
313
335
|
});
|
|
314
336
|
// The gate before a call's intent: the run's revision's tool settings through runGate (approvals "never" turns the one
|
|
@@ -318,6 +340,11 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
318
340
|
// 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
|
|
319
341
|
// the same path), for its path checks; it reads nothing in it.
|
|
320
342
|
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted));
|
|
343
|
+
// What a script's shell and files are held to: this gate, so a denied bash or write holds inside computer_script and codemode.
|
|
344
|
+
tools.computer?.guard.install(async (tool, args) => {
|
|
345
|
+
await gate.permissions.refresh();
|
|
346
|
+
return gate.permissions.decide(tool, args);
|
|
347
|
+
});
|
|
321
348
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
322
349
|
// uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
|
|
323
350
|
// launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
|
|
@@ -326,6 +353,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
326
353
|
const capModel = capModelOf(route);
|
|
327
354
|
// And each tier's model (tierRoutes, filled below), by the route its request names (its tier's proxy, ModelRequest.route),
|
|
328
355
|
// priced as that route books it: one id the run's model and a tier share is priced apart, never at the other's price.
|
|
356
|
+
const besideOf = spentBesideOf(launch, deps.store, claim.runId);
|
|
329
357
|
const runCap = {
|
|
330
358
|
capUsd: () => launch.maxCostUsd,
|
|
331
359
|
modelOf: (id, by) => {
|
|
@@ -335,6 +363,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
335
363
|
return tierRoute && tierRoute.model === id ? capModelOf(tierRoute) : undefined;
|
|
336
364
|
},
|
|
337
365
|
...(launch.capMode === "strict" ? { mode: "strict" } : {}),
|
|
366
|
+
// What its learning runs' grades took beside it, read by every gate with its own sessions (none: it queues none).
|
|
367
|
+
...(besideOf ? { beside: besideOf } : {}),
|
|
338
368
|
};
|
|
339
369
|
// The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
|
|
340
370
|
// has a cap. A park names the cap the loop holds the run to then (a raise's, else this one).
|
|
@@ -374,6 +404,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
374
404
|
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
|
|
375
405
|
log,
|
|
376
406
|
...(start.notesOnly ? { workflows: false } : {}),
|
|
407
|
+
...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
|
|
377
408
|
})
|
|
378
409
|
: undefined;
|
|
379
410
|
// The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
|
|
@@ -427,7 +458,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
427
458
|
// reads no learning folder), its own skills through skills.ts promptOf, then the effort guidance (the launch's effort,
|
|
428
459
|
// never this process's environment). The one path for every harness.
|
|
429
460
|
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
430
|
-
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
461
|
+
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
|
|
431
462
|
const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
|
|
432
463
|
const guidance = effortGuidance(launch.effort);
|
|
433
464
|
const system = [environmentLine(), checkout?.note, instructions, guidance].filter((line) => Boolean(line));
|
|
@@ -486,6 +517,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
486
517
|
signIns: signInReads(deps.store, deps.sealKey),
|
|
487
518
|
handed: runnerSecrets(toolEnv),
|
|
488
519
|
stored: () => storeSecrets(deps.store, deps.sealKey, deps.data),
|
|
520
|
+
// A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
|
|
521
|
+
decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
|
|
489
522
|
learningFolder: archil === undefined
|
|
490
523
|
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
491
524
|
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
@@ -509,22 +542,31 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
509
542
|
// The tool host's install lifecycle (its bindings' onConversation/beforeResume/beforeRelease), run by the adapter loop.
|
|
510
543
|
lifecycle: life,
|
|
511
544
|
agentId: runRow.agentId,
|
|
512
|
-
// The run's
|
|
513
|
-
// take-over and a hand-back to it.
|
|
514
|
-
...(
|
|
545
|
+
// The run's computer as the claim made it, with the person's hold on a desktop or phone: the loop shows the hold up,
|
|
546
|
+
// applies a take-over and a hand-back to it, and answers the computer call channel's rows on it.
|
|
547
|
+
...(loopComputer ? { computer: loopComputer } : {}),
|
|
515
548
|
workRoot: root,
|
|
516
549
|
// The end's metrics and cost, from the run's journal, as the old per-run end path read them (metrics.ts runMetrics =
|
|
517
550
|
// runs.ts storedMetrics/costOf). A pi run adds its effort, no model (metrics.ts).
|
|
518
551
|
endPatch: async () => {
|
|
519
552
|
// The root's entries and every conversation a task of the run owns (a subagent's): a child's requests are the run's.
|
|
520
553
|
const entries = await agentEntriesOf(deps.journal(claim), context);
|
|
521
|
-
const { metrics
|
|
554
|
+
const { metrics } = runMetrics(entries, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}) });
|
|
555
|
+
// Its cost is its booking's, as a CLI run's is (metrics.ts bookedSpend, the one reader): every model request its
|
|
556
|
+
// session's proxy booked, pi's own answers and its side calls (a learned workflow's nodes, web_search's hosted search
|
|
557
|
+
// with its fee) alike, and its decisions (a learned workflow's decision nodes, LS-07; one that reported none is
|
|
558
|
+
// unknown, never the cap's hold for it). A request a cancel or a stop cut while it streamed is booked at no known cost
|
|
559
|
+
// (the provider may bill what it streamed), so the run's cost is unknown, never the $0 its cut answer carries.
|
|
560
|
+
const all = (await journalEntries(deps.journal(claim), context));
|
|
522
561
|
// Its paid tool calls (a Parallel search's, a monid call's, a person's browser time), booked on the run's one ledger
|
|
523
|
-
// (
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
return {
|
|
562
|
+
// (each on its cap, in its own session, not on the root), are the run's cost too; any part unknown leaves the run's unknown.
|
|
563
|
+
const total = runEndCost({ model: bookedSpend(all, "model").usd, paid: run.ledger?.paid ? run.ledger.paid.spentUsd() : 0, decisions: bookedSpend(all, "decisions").usd });
|
|
564
|
+
// An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
|
|
565
|
+
return { costUsd: total, metrics };
|
|
527
566
|
},
|
|
567
|
+
// A run started with hold: true holds its computer for its owner (computer-held.ts): the loop waits for their start
|
|
568
|
+
// and release, and runs their calls on it.
|
|
569
|
+
...(heldComputer ? { held: heldComputer } : {}),
|
|
528
570
|
// The pass's resources go once the loop writes nothing more through them: its tools' end (background processes ended,
|
|
529
571
|
// scratch swept), its computer let go, then its Workspace's end (Mode 2 sweeps the exec spill).
|
|
530
572
|
// The run's Archil mount credential is revoked at its end on every outcome, even with no computer (the computer's
|
|
@@ -543,7 +585,8 @@ export function hostToolCtxOf(run, context, results, root) {
|
|
|
543
585
|
env: async () => ({ cwd: root }),
|
|
544
586
|
commit: (change, at, options) => run.harness.commit(change, at, options),
|
|
545
587
|
snapshot: ((...args) => Reflect.apply(run.harness.snapshot, run.harness, args)),
|
|
546
|
-
|
|
588
|
+
// Never on the call's signal (durableWait): an abort while it registers rejects this wait, never one unhandled.
|
|
589
|
+
waitForTask: (id, at) => durableWait((bare) => run.harness.waitForTask(id, bare), at),
|
|
547
590
|
agent: async (at) => {
|
|
548
591
|
const conversation = await run.harness.conversation(ROOT_CONVERSATION_ID, at);
|
|
549
592
|
if (!conversation)
|
|
@@ -616,14 +659,20 @@ export async function learnedWorkflowHostTool(opts) {
|
|
|
616
659
|
throw new Error(`the run's ${tier} model could not be reached: ${model.why}`);
|
|
617
660
|
return { provider: tierProvider(tier), modelId: model.model };
|
|
618
661
|
};
|
|
619
|
-
|
|
662
|
+
// Its decision nodes (LS-07) on the decision providers the run's keys give (decisions.ts decisionProvidersIn over `env`,
|
|
663
|
+
// the claim's own), each booked on the run's one cap (ledger.decisions) and a refusal of it pausing the run
|
|
664
|
+
// (ledger.pause). A run whose keys give none runs no decision node: the check refuses it before any node runs.
|
|
665
|
+
const providers = await decisionProvidersIn(opts.env);
|
|
666
|
+
const decisions = providers ? { decisions: { providers, book: opts.run.ledger.decisions, pause: (refusal) => opts.run.ledger.pause(refusal) } } : {};
|
|
667
|
+
// A call node's native web_search goes through the session's port too, labelled web_search, as the run's own does.
|
|
668
|
+
const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: tieredModels(byProvider), modelOf, search: () => opts.run.ledger.models(WEB_SEARCH_TOOL), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools, ...decisions, ...(opts.workspace ? { workspace: opts.workspace } : {}), ...(opts.modelName ? { modelName: opts.modelName } : {}) });
|
|
620
669
|
return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
|
|
621
670
|
}
|
|
622
671
|
/** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
|
|
623
672
|
* hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
|
|
624
673
|
* `gated` is undefined here, as for the hands). Their paid requests are booked by the adapter loop on the run's one ledger
|
|
625
674
|
* (bookedIn), as main books them, so they run. The browser (through host.liveViewers), MCP (the MCP claim step's
|
|
626
|
-
* mcpForClaim(claim, store, sealKey, pin) -> { sessionMcp,
|
|
675
|
+
* mcpForClaim(claim, store, sealKey, pin) -> { sessionMcp, release }), the learned workflow and decisions are
|
|
627
676
|
* each a named todo, added as their seams land. */
|
|
628
677
|
/** The run's live-viewer writers over the store (browser-live.ts): a session's hand-over written sealed, and gone. Its
|
|
629
678
|
* viewer token, minted in the run, is held by `cut`, the run's one redactor, as it is handed over, before it is written. */
|
|
@@ -664,6 +713,7 @@ export function answersCut(tool, cut) {
|
|
|
664
713
|
* session's viewer over through (the store, never files), and the run's own Workspace (`workspace`: in Mode 2 its folder
|
|
665
714
|
* on the run's disk), where a tool files what the run's read finds later. */
|
|
666
715
|
export function buildToolHost(opts) {
|
|
716
|
+
const liveAt = runnerLiveOf(opts.env, opts.sealKey);
|
|
667
717
|
const { root, claim, run, life } = opts;
|
|
668
718
|
return {
|
|
669
719
|
// The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
|
|
@@ -684,9 +734,14 @@ export function buildToolHost(opts) {
|
|
|
684
734
|
// browser holds and settles its calls here (host.ledger.paid), never on this process's own spend, and a refusal at the
|
|
685
735
|
// cap parks the run (pause). browserListed reads it to fail closed.
|
|
686
736
|
ledger: run.ledger,
|
|
737
|
+
// A native web_search's models: the session's port under a side key labelled web_search, so the search request goes
|
|
738
|
+
// through the run's one route (its proxy, policy, key, price and cap), this run's alone (#2458).
|
|
739
|
+
search: () => run.ledger.models(WEB_SEARCH_TOOL),
|
|
687
740
|
// The run's one redactor: the browser's answers pass it inside their call, before pi stores them (tools.ts).
|
|
688
741
|
redact: opts.redact,
|
|
689
742
|
liveViewers: liveViewersOf(opts.store, opts.sealKey, claim, opts.redact),
|
|
743
|
+
// A runner on another host than its server (AGENTRUN_RUNNER_LIVE_HOST): its browser's viewer answers there.
|
|
744
|
+
...(liveAt ? { liveAt } : {}),
|
|
690
745
|
// What a tool files for the run's read (monid's whole answer past the model's cut) goes in the run's own Workspace, the
|
|
691
746
|
// one its hands read: in Mode 2 its folder on the run's disk, never the local folder at `root`.
|
|
692
747
|
workspace: opts.workspace,
|
|
@@ -726,7 +781,7 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
|
|
|
726
781
|
// the session's tools the harness is told of: its model nodes run on the session's proxied models (run.ledger.models),
|
|
727
782
|
// each a request on the run's one route labelled learned_workflow. The agent's scoped keys (host.env) are its call
|
|
728
783
|
// nodes'.
|
|
729
|
-
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, tiers, ...(mcp ? { mcp } : {}), ...(modelName ? { modelName } : {}) });
|
|
784
|
+
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, tiers, ...(mcp ? { mcp } : {}), ...(host.workspace ? { workspace: host.workspace } : {}), ...(modelName ? { modelName } : {}) });
|
|
730
785
|
if (learned)
|
|
731
786
|
tools.push(learned);
|
|
732
787
|
// The browser (tl-browser), on pi's native route: tools.ts's own binding on this run's ToolHost (its store, claim and seal
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Extension } from "@earendil-works/pi-durable";
|
|
2
|
+
import { type ScriptComputer } from "../../workspace/index.js";
|
|
3
|
+
/** The code mode tool's name, as the model calls it and the gate reads it. */
|
|
4
|
+
export declare const PI_CODEMODE_TOOL = "codemode";
|
|
5
|
+
/** pi's code mode extension with `computer` bound to `computer`'s surface: install it among the run's pi-native
|
|
6
|
+
* extensions (PiAdapterOptions.extensions). No `models.*` in scripts: a script's paid work is the run's own tools. */
|
|
7
|
+
export declare function computerCodemode(computer: ScriptComputer): Extension;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CodemodeSandbox } from "@earendil-works/pi-codemode";
|
|
2
|
+
import { CODEMODE_TOOL_NAME, createCodemodeExtension } from "@earendil-works/pi-durable/codemode";
|
|
3
|
+
import { COMPUTER_CALL_GLOBAL, scriptPrelude } from "@parcha/agentrun-computer/surface";
|
|
4
|
+
import { SCRIPT_MAX_MS } from "../../workspace/index.js";
|
|
5
|
+
/** The code mode tool's name, as the model calls it and the gate reads it. */
|
|
6
|
+
export const PI_CODEMODE_TOOL = CODEMODE_TOOL_NAME;
|
|
7
|
+
const MEMORY_BYTES = 256 * 1024 * 1024;
|
|
8
|
+
/** A sandbox whose every script starts with `prelude`: one line, so the script's own line numbers hold. A rerun after a
|
|
9
|
+
* restart starts from the same code, so its replay is the first run's. */
|
|
10
|
+
class PreludedSandbox extends CodemodeSandbox {
|
|
11
|
+
#prelude;
|
|
12
|
+
constructor(prelude, options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this.#prelude = prelude;
|
|
15
|
+
}
|
|
16
|
+
execute(code, options) {
|
|
17
|
+
return super.execute(`${this.#prelude}\n${code}`, options);
|
|
18
|
+
}
|
|
19
|
+
start(code, options) {
|
|
20
|
+
return super.start(`${this.#prelude}\n${code}`, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** pi's code mode extension with `computer` bound to `computer`'s surface: install it among the run's pi-native
|
|
24
|
+
* extensions (PiAdapterOptions.extensions). No `models.*` in scripts: a script's paid work is the run's own tools. */
|
|
25
|
+
export function computerCodemode(computer) {
|
|
26
|
+
const sandbox = new PreludedSandbox(scriptPrelude(computer.card), { timeoutMs: SCRIPT_MAX_MS, memoryLimitBytes: MEMORY_BYTES });
|
|
27
|
+
return createCodemodeExtension({
|
|
28
|
+
sandbox,
|
|
29
|
+
models: false,
|
|
30
|
+
// No tool listed again in the system prompt's codemode section: every tool is offered as itself (code mode "on"),
|
|
31
|
+
// computer_script's description declares `computer` once, and a script finds any other with searchTools().
|
|
32
|
+
inlineBudget: 0,
|
|
33
|
+
globals: [{
|
|
34
|
+
name: COMPUTER_CALL_GLOBAL,
|
|
35
|
+
spread: true,
|
|
36
|
+
// The value whole, images and all: a script shows one with image(...).
|
|
37
|
+
execute: async (given, _api, context) => {
|
|
38
|
+
const [op, args] = given;
|
|
39
|
+
return (await computer.guard.call(String(op), args, (sent) => computer.port.call(String(op), sent ?? {}, context.abortSignal)));
|
|
40
|
+
},
|
|
41
|
+
}],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { Models } from "@earendil-works/pi-ai";
|
|
3
3
|
import { type Extension, type Harness, type Registry, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
4
|
import { type AgentAdapter, type SessionIO, type SessionPort, type Wire } from "@parcha/agentrun-kernel";
|
|
@@ -77,6 +77,10 @@ export interface PiAdapterOptions {
|
|
|
77
77
|
* claim's Harness. Their tools pass the session's gate (its beforeTool hook), and every conversation they open takes
|
|
78
78
|
* its model from the root's agent, through this session's proxy and its booking. */
|
|
79
79
|
readonly extensions?: readonly Extension[];
|
|
80
|
+
/** The run's web_search is its provider's own hosted search (its plane resolves it "native", hosted-search.ts): the
|
|
81
|
+
* session's policy admits that hosted tool, a request carrying it held at its search allowance, and the proxy prices
|
|
82
|
+
* each search the provider reports at its fee, so the search's one request is booked once with its searches. */
|
|
83
|
+
readonly webSearch?: boolean;
|
|
80
84
|
/** pi-native tools the session's own extension carries beside its host tools (the subagent tool: runner/subagent.ts):
|
|
81
85
|
* pi's own tool tasks, under the session's gate like every call. Read when the session opens. A conversation one of
|
|
82
86
|
* them opens keeps the session's extension, so its calls pass the same gate; its own `tools` say which it is offered. */
|
|
@@ -110,12 +114,13 @@ export declare function openTierProxies(tiers: ReadonlyMap<string, TierModel>, h
|
|
|
110
114
|
* every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
|
|
111
115
|
* dropped, and a request that offers the session's tools is the turn's answer request. `auth`: how the provider takes
|
|
112
116
|
* its credential (default x-api-key). */
|
|
113
|
-
export declare function piPolicy(model: string, tools: readonly string[], auth?: "bearer" | "x-api-key"): ProviderPolicy;
|
|
117
|
+
export declare function piPolicy(model: string, tools: readonly string[], auth?: "bearer" | "x-api-key", webSearch?: boolean): ProviderPolicy;
|
|
114
118
|
/** The policy of the session's wire, the one each CLI harness of that wire applies (no fork of either): Anthropic's
|
|
115
119
|
* Messages as claude-agent's (piPolicy), OpenAI's Responses as codex's, which takes pi's tools as the session's own by
|
|
116
120
|
* name. Either way every other tool definition is dropped and the request that offers them is the turn's answer
|
|
117
|
-
* request.
|
|
118
|
-
|
|
121
|
+
* request. `webSearch`: the run's web_search is the provider's hosted search, whose one tool each wire's policy admits
|
|
122
|
+
* as its CLI's own search (claude-agent's on Messages, codex's live search on Responses). */
|
|
123
|
+
export declare function policyFor(provider: PiAdapterOptions["provider"], model: string, tools: readonly string[], webSearch?: boolean): Promise<ProviderPolicy>;
|
|
119
124
|
/** A refused call's words by call (the gate's deny, main's words), held from the refusal (beforeTool's block) to the
|
|
120
125
|
* call's result (afterTool): a blocked result becomes those words alone, an error, as main gives a refused call's
|
|
121
126
|
* result, never pi's framing of a blocked call. Every other result is pi's own. `held`: the words still held. */
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
2
2
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
3
|
import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
|
|
4
|
-
import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
|
|
4
|
+
import { anthropicPolicy, CLAUDE_WEB_SEARCH_USD, withWebSearches } from "@parcha/agentrun-harness-claude";
|
|
5
5
|
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
6
6
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
8
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
9
|
+
import { durableWait } from "../../workflow/pi-versions.js";
|
|
10
|
+
import { HOSTED_SEARCH_ALLOWANCE_TOKENS } from "../../hosted-search.js";
|
|
9
11
|
import { sessionProvider, tierProvider } from "../../port-models.js";
|
|
10
12
|
import { KINDS } from "../journal-kinds.js";
|
|
11
13
|
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
@@ -30,7 +32,8 @@ async function openPi(options, spec, io) {
|
|
|
30
32
|
const context = withAbortSignal(io.signal, BACKGROUND_CONTEXT);
|
|
31
33
|
// The session's route: pi-ai's requests reach the provider only through this proxy, which admits and books each one
|
|
32
34
|
// through the runner's booking (io.models).
|
|
33
|
-
|
|
35
|
+
// Its web_search native (options.webSearch): the session's own proxy admits the hosted search and prices its searches.
|
|
36
|
+
const proxy = await routeProxy(options, io.models, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)], options.redact, undefined, options.webSearch === true);
|
|
34
37
|
// An open that fails from here (the claim lost while the session opened) closes the proxies: their servers would hold
|
|
35
38
|
// the runner's process open.
|
|
36
39
|
let tiers;
|
|
@@ -47,17 +50,19 @@ async function openPi(options, spec, io) {
|
|
|
47
50
|
}
|
|
48
51
|
/** A proxy on `hooks` (the session's booking: its requests are the run's, under its one cap) for `route`'s model, with its
|
|
49
52
|
* origin, credential, price and fetch, its provider's errors through `redact`. `tools`: the tool names its policy admits
|
|
50
|
-
* by name on a request of the session's own key (none for a tier's: only side keys reach it).
|
|
51
|
-
|
|
53
|
+
* by name on a request of the session's own key (none for a tier's: only side keys reach it). `webSearch`: the session's
|
|
54
|
+
* own proxy admits its provider's hosted search and prices each search it ran (policyFor, withSearches). */
|
|
55
|
+
async function routeProxy(route, hooks, tools, redact, tier, webSearch = false) {
|
|
56
|
+
const price = route.price && webSearch ? await withSearches(route.provider.api, route.price) : route.price;
|
|
52
57
|
return startModelProxy({
|
|
53
58
|
// A tier's proxy names its tier on each request (ModelRequest.route), so the run's cap prices it as this route books it.
|
|
54
59
|
...(tier === undefined ? {} : { route: tier }),
|
|
55
|
-
policy: await policyFor(route.provider, route.model, tools),
|
|
60
|
+
policy: await policyFor(route.provider, route.model, tools, webSearch),
|
|
56
61
|
hooks,
|
|
57
62
|
model: route.model,
|
|
58
63
|
origin: route.provider.origin,
|
|
59
64
|
credential: async () => (await route.provider.credential()) ?? "",
|
|
60
|
-
...(
|
|
65
|
+
...(price ? { price: price } : {}),
|
|
61
66
|
...(route.provider.headers ? { headers: route.provider.headers } : {}),
|
|
62
67
|
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
63
68
|
...(redact ? { redact } : {}),
|
|
@@ -97,19 +102,74 @@ export async function openTierProxies(tiers, hooks, redact, tools = []) {
|
|
|
97
102
|
* every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
|
|
98
103
|
* dropped, and a request that offers the session's tools is the turn's answer request. `auth`: how the provider takes
|
|
99
104
|
* its credential (default x-api-key). */
|
|
100
|
-
export function piPolicy(model, tools, auth) {
|
|
101
|
-
|
|
105
|
+
export function piPolicy(model, tools, auth, webSearch = false) {
|
|
106
|
+
const policy = anthropicPolicy({ model, tools: [], builtins: tools, ...(auth ? { auth } : {}), ...(webSearch ? { webSearch: true, webSearchAllowance: HOSTED_SEARCH_ALLOWANCE_TOKENS } : {}) });
|
|
107
|
+
if (!webSearch)
|
|
108
|
+
return policy;
|
|
109
|
+
// The hosted search's fees held with its tokens: each use its tool's max_uses allows, at the search's fee. One with no
|
|
110
|
+
// max_uses has no bound, and its worst case is unknown (the proxy's feeMaxUsd).
|
|
111
|
+
return { ...policy, feeMaxUsd: (body) => searchesAllowed(body, (tool) => typeof tool.type === "string" && tool.type.startsWith("web_search_"), "max_uses") * CLAUDE_WEB_SEARCH_USD };
|
|
112
|
+
}
|
|
113
|
+
/** The most searches `body` allows its hosted search tool (the one `isSearch` picks): its `limit` (the tool's own key, or
|
|
114
|
+
* the body's on Responses), Infinity when it states none, 0 when the body offers no search. */
|
|
115
|
+
function searchesAllowed(body, isSearch, limit, bodyLimit = false) {
|
|
116
|
+
const search = Array.isArray(body.tools) ? body.tools.find((tool) => typeof tool === "object" && tool !== null && isSearch(tool)) : undefined;
|
|
117
|
+
if (!search)
|
|
118
|
+
return 0;
|
|
119
|
+
const most = bodyLimit ? body[limit] : search[limit];
|
|
120
|
+
return typeof most === "number" && Number.isInteger(most) && most >= 0 ? most : Infinity;
|
|
102
121
|
}
|
|
103
122
|
/** The policy of the session's wire, the one each CLI harness of that wire applies (no fork of either): Anthropic's
|
|
104
123
|
* Messages as claude-agent's (piPolicy), OpenAI's Responses as codex's, which takes pi's tools as the session's own by
|
|
105
124
|
* name. Either way every other tool definition is dropped and the request that offers them is the turn's answer
|
|
106
|
-
* request.
|
|
107
|
-
|
|
125
|
+
* request. `webSearch`: the run's web_search is the provider's hosted search, whose one tool each wire's policy admits
|
|
126
|
+
* as its CLI's own search (claude-agent's on Messages, codex's live search on Responses). */
|
|
127
|
+
export async function policyFor(provider, model, tools, webSearch = false) {
|
|
108
128
|
if (provider.api === "anthropic-messages")
|
|
109
|
-
return piPolicy(model, tools, provider.auth);
|
|
129
|
+
return piPolicy(model, tools, provider.auth, webSearch);
|
|
110
130
|
// Loaded when a session of its wire opens, as the runner loads the codex harness.
|
|
111
|
-
const { codexPolicy } = (await import("@parcha/agentrun-harness-codex"));
|
|
112
|
-
|
|
131
|
+
const { codexPolicy, webSearchUsd } = (await import("@parcha/agentrun-harness-codex"));
|
|
132
|
+
if (!webSearch)
|
|
133
|
+
return codexPolicy({ model, tools });
|
|
134
|
+
return searchOnce(codexPolicy({ model, tools, webSearch: "live" }), codexPolicy({ model, tools }), webSearchUsd(model));
|
|
135
|
+
}
|
|
136
|
+
/** Codex's live-search policy (`live`) as pi's session takes it. The Codex CLI offers its search on every request; pi
|
|
137
|
+
* offers it on one request alone, its web_search's hosted search (hosted-search.ts), so two of its rules are pi's here:
|
|
138
|
+
* - a request that offered no search ran none (0), read from the request's body, where codex's reads every answer that
|
|
139
|
+
* does not state its count as unknown; the search's own request is read as codex reads it;
|
|
140
|
+
* - the hosted search's request has an input bound, its body's (`plain`, the policy with no search) plus the input
|
|
141
|
+
* HOSTED_SEARCH_ALLOWANCE_TOKENS allows its at most HOSTED_MAX_USES searches, as claude-agent's policy bounds Claude's
|
|
142
|
+
* search, so a capped run holds it and does not refuse it as unmeasured; and its fees are held with its tokens, each
|
|
143
|
+
* call its `max_tool_calls` allows at `searchUsd`, the model's price of one (none known: its worst case is unknown). */
|
|
144
|
+
function searchOnce(live, plain, searchUsd) {
|
|
145
|
+
const offersSearch = (body) => Array.isArray(body.tools) && body.tools.some((tool) => typeof tool === "object" && tool !== null && tool.type === "web_search");
|
|
146
|
+
return {
|
|
147
|
+
...live,
|
|
148
|
+
usageOf: (text, body) => {
|
|
149
|
+
if (!body || offersSearch(body))
|
|
150
|
+
return live.usageOf(text, body);
|
|
151
|
+
const usage = plain.usageOf(text, body);
|
|
152
|
+
return usage && { ...usage, webSearches: 0 };
|
|
153
|
+
},
|
|
154
|
+
feeMaxUsd: (body) => {
|
|
155
|
+
const most = searchesAllowed(body, (tool) => tool.type === "web_search", "max_tool_calls", true);
|
|
156
|
+
return most === 0 ? 0 : most * (searchUsd ?? Number.NaN);
|
|
157
|
+
},
|
|
158
|
+
serverInputOverhead: (body) => {
|
|
159
|
+
if (!offersSearch(body))
|
|
160
|
+
return live.serverInputOverhead?.(body);
|
|
161
|
+
const base = plain.serverInputOverhead?.({ ...body, tools: body.tools.filter((tool) => !(typeof tool === "object" && tool !== null && tool.type === "web_search")) });
|
|
162
|
+
return base === undefined ? undefined : base + HOSTED_SEARCH_ALLOWANCE_TOKENS;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** `price` with each web search a response reports added at its provider's fee, as the wire's CLI prices its own search
|
|
167
|
+
* (claude-agent's flat fee on Messages, codex's per model on Responses). */
|
|
168
|
+
async function withSearches(api, price) {
|
|
169
|
+
if (api === "anthropic-messages")
|
|
170
|
+
return withWebSearches(price);
|
|
171
|
+
const codex = (await import("@parcha/agentrun-harness-codex"));
|
|
172
|
+
return codex.withWebSearches(price);
|
|
113
173
|
}
|
|
114
174
|
/** The session on its proxy: pi's models through it, the host's tools and the gate as pi's extension, the root's state. */
|
|
115
175
|
async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
@@ -227,7 +287,9 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
227
287
|
let state = existing === undefined ? "new" : later ? "open_turn" : existing.status === "done" ? "idle" : "open_turn";
|
|
228
288
|
let running;
|
|
229
289
|
const watch = (submission) => {
|
|
230
|
-
|
|
290
|
+
// Its wait never holds the claim's signal (durableWait): an abort while it registers (a close, a lost claim, as a
|
|
291
|
+
// resumed loop opens) ends the turn interrupted here, never as a rejection nothing handles, which ends the process.
|
|
292
|
+
running = durableWait((at) => submission.wait(at), context).then((record) => {
|
|
231
293
|
state = "idle";
|
|
232
294
|
const status = record.status === "done" ? "completed" : "failed";
|
|
233
295
|
io.onEvent({ type: "turn_end", status });
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -26,13 +26,17 @@ export declare function besideStopping(server: {
|
|
|
26
26
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
27
27
|
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
28
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.
|
|
30
|
-
*
|
|
31
|
-
|
|
29
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
|
|
30
|
+
* holds each paired computer's socket in this process, so a run here takes one. Returns the runner and a close() that
|
|
31
|
+
* stops both and closes its store. */
|
|
32
|
+
export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor, hub, mcpLoopback, onLine }?: {
|
|
32
33
|
loops?: number;
|
|
33
34
|
drainMs?: number;
|
|
34
35
|
env?: NodeJS.ProcessEnv;
|
|
35
36
|
janitor?: boolean;
|
|
37
|
+
hub?: import("@parcha/agentrun-computer").AttachHub;
|
|
38
|
+
mcpLoopback?: boolean;
|
|
39
|
+
onLine?: (line: string) => void;
|
|
36
40
|
}): Promise<{
|
|
37
41
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
38
42
|
close: () => Promise<void>;
|