@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48
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 +211 -1
- package/NOTICE +4 -0
- package/README.md +350 -53
- package/dist/acp-package.d.ts +53 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +3 -4
- package/dist/adapter-facts.js +4 -4
- package/dist/adapters.d.ts +3 -5
- package/dist/adapters.js +1 -31
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/answer-json.d.ts +10 -0
- package/dist/answer-json.js +24 -0
- package/dist/api-only.d.ts +11 -11
- package/dist/api-only.js +16 -11
- package/dist/archil-routes.js +2 -1
- package/dist/browser-live.d.ts +9 -4
- package/dist/browser-live.js +18 -5
- package/dist/cap.js +10 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +109 -41
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-routes.d.ts +8 -5
- package/dist/computer-routes.js +7 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +14 -76
- package/dist/computers.js +24 -68
- package/dist/conformance.d.ts +4 -0
- package/dist/conformance.js +6 -0
- package/dist/console/assets/index-CTGegcKt.css +1 -0
- package/dist/console/assets/index-D1Se6mgG.js +715 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +75 -0
- package/dist/harness-check.js +518 -0
- package/dist/harness-cursor.d.ts +28 -0
- package/dist/harness-cursor.js +42 -0
- package/dist/harness-goose.d.ts +4 -29
- package/dist/harness-goose.js +6 -86
- package/dist/harness-module.d.ts +4 -0
- package/dist/harness-module.js +1 -0
- package/dist/harness-owned.d.ts +52 -0
- package/dist/harness-owned.js +92 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +335 -0
- package/dist/harness-table.d.ts +120 -5
- package/dist/harness-table.js +280 -6
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +5 -4
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +24 -4
- package/dist/import.js +108 -26
- package/dist/key-refusal.d.ts +3 -1
- package/dist/key-refusal.js +26 -5
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +12 -5
- package/dist/learn/promote.d.ts +80 -2
- package/dist/learn/promote.js +95 -3
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +23 -0
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-model.d.ts +18 -0
- package/dist/learning-model.js +77 -0
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +2 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +30 -16
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +5 -3
- package/dist/model.js +26 -18
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +356 -43
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +9 -0
- package/dist/page.js +10 -2
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +7 -4
- package/dist/run-trace.js +6 -3
- package/dist/runner/adapter-loop.d.ts +14 -8
- package/dist/runner/adapter-loop.js +58 -24
- package/dist/runner/adapter-run-spec.d.ts +15 -2
- package/dist/runner/adapter-run-spec.js +48 -10
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +6 -26
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +15 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +22 -10
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/conformance/host-tools.d.ts +4 -0
- package/dist/runner/conformance/host-tools.js +14 -0
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +62 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/meta-tools.js +4 -2
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +44 -0
- package/dist/runner/presence.js +96 -0
- package/dist/runner/promotion.d.ts +70 -7
- package/dist/runner/promotion.js +178 -28
- package/dist/runner/run-child-host.js +40 -10
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/sdk-loop.js +25 -1
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +12 -4
- package/dist/sdk/check.d.ts +31 -0
- package/dist/sdk/check.js +58 -0
- package/dist/sdk/runs.d.ts +11 -3
- package/dist/sdk/runs.js +90 -15
- package/dist/sdk/schema.js +12 -4
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +34 -2
- package/dist/server.js +437 -90
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +112 -28
- package/dist/store/store.d.ts +78 -24
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +125 -14
- package/dist/store-view.js +156 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/template-eval.js +5 -2
- package/dist/template-github-permissions.d.ts +5 -1
- package/dist/template-github-permissions.js +7 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/timeline/timeline.js +30 -0
- package/dist/tool-gate.d.ts +8 -4
- package/dist/tool-gate.js +6 -7
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.d.ts +4 -0
- package/dist/tool-plane.js +12 -12
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +12 -3
- package/dist/trigger-targets.js +90 -10
- package/dist/triggers.d.ts +2 -2
- package/dist/validate.js +5 -1
- package/dist/viewer-credential.d.ts +25 -0
- package/dist/viewer-credential.js +51 -0
- package/dist/webhooks.d.ts +82 -8
- package/dist/webhooks.js +128 -45
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +23 -14
- package/dist/workspace/resolve-computer.js +66 -61
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +18 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/templates/code-review/agent.md +2 -3
- package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
- package/templates/code-review/evals/other-repo/case.yaml +0 -1
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
|
@@ -20,6 +20,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
20
20
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
21
21
|
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
22
22
|
import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
|
|
23
|
+
import { modelWire } from "../wires.js";
|
|
23
24
|
import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
|
|
24
25
|
import { claimSettled, claudeCliIn, installDirOf, installForClaim, installingWords } from "../harness-install.js";
|
|
25
26
|
import { HarnessUnavailable } from "../provider.js";
|
|
@@ -27,7 +28,7 @@ import { effortGuidance } from "../effort-guidance.js";
|
|
|
27
28
|
import { outputContract } from "../answer-json.js";
|
|
28
29
|
import { wireName } from "../catalog.js";
|
|
29
30
|
import { environmentLine, runZone } from "../environment.js";
|
|
30
|
-
import { harnessOf } from "../harness-table.js";
|
|
31
|
+
import { factsOf, harnessOf } from "../harness-table.js";
|
|
31
32
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
32
33
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
33
34
|
import { learningWorkspace } from "../learn/folder.js";
|
|
@@ -48,7 +49,7 @@ import { settingOfDefinition } from "../computer-setting.js";
|
|
|
48
49
|
import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
49
50
|
import { hadComputer } from "./computer-journal.js";
|
|
50
51
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
51
|
-
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
|
|
52
|
+
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
|
|
52
53
|
import { openTierProxies } from "./adapters/pi.js";
|
|
53
54
|
import { signInReads } from "../sign-ins-store.js";
|
|
54
55
|
import { isWebHostTool } from "../tool-list.js";
|
|
@@ -62,13 +63,14 @@ import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
|
62
63
|
import { decisionProvidersIn } from "../decisions.js";
|
|
63
64
|
import { resolveHarness } from "./adapters/index.js";
|
|
64
65
|
import { entriesOf } from "./loop.js";
|
|
65
|
-
import { bookedSpend, cliModelWorked, cliRunMetrics, endCostOf, runCostOf } from "./metrics.js";
|
|
66
|
+
import { bookedSpend, cliModelWorked, cliRunMetrics, costBasisOf, endCostOf, runCostOf } from "./metrics.js";
|
|
66
67
|
import { journalEntries } from "./journal-reader.js";
|
|
67
68
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
68
69
|
import { replayCallsOver } from "./promotion.js";
|
|
69
70
|
import { learnedFirstWhereHeld } from "./learned-first.js";
|
|
70
71
|
import { pathMetrics } from "./workflow-first.js";
|
|
71
72
|
import { AUDIT_PARKED, withAudit } from "./audit.js";
|
|
73
|
+
import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
|
|
72
74
|
import { runPathOverStore } from "../store-reads/learning.js";
|
|
73
75
|
import { specBuilt } from "./spec-holds.js";
|
|
74
76
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
@@ -120,11 +122,12 @@ export function capModelOf(id, wire, listed, unpriced, plan = false) {
|
|
|
120
122
|
return { id, api: wire, price, outputCeiling: typeof listed?.maxTokens === "number" ? listed.maxTokens : null };
|
|
121
123
|
}
|
|
122
124
|
/** The model a CLI run of `entry` on `chosen` (modelsOf) is capped at, on its `wire`: the catalog entry that bills it
|
|
123
|
-
* (its entry's priceModel), priced by capModelOf.
|
|
125
|
+
* (its entry's priceModel), priced by capModelOf. A harness its vendor bills to its owner's plan (no model wire of ours:
|
|
126
|
+
* modelWire, Cursor's) is the plan rule's, as a ChatGPT plan's model is. */
|
|
124
127
|
function chosenCapModel(entry, env, chosen, wire) {
|
|
125
128
|
const priced = entry.priceModel(env, chosen.model);
|
|
126
129
|
const listed = chosen.models.getModel(priced.provider, priced.modelId);
|
|
127
|
-
return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER);
|
|
130
|
+
return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER || !modelWire(wire));
|
|
128
131
|
}
|
|
129
132
|
/** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
|
|
130
133
|
* at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
|
|
@@ -544,8 +547,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
544
547
|
// The gate before a call's intent, the same as the pi spec: the revision's tool settings over the store's, read from the
|
|
545
548
|
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
546
549
|
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
547
|
-
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
548
|
-
|
|
550
|
+
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's
|
|
551
|
+
// native tools are named by its facts on the owner's table (factsOf: a module's harness's too).
|
|
552
|
+
const ownerFacts = factsOf(deps.env, name);
|
|
553
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts: ownerFacts });
|
|
549
554
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
550
555
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
551
556
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -581,6 +586,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
581
586
|
// are skipped, in words, where the run brought its own key or the server holds none.
|
|
582
587
|
const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
|
|
583
588
|
const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
|
|
589
|
+
// A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
|
|
590
|
+
// is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
|
|
591
|
+
const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut]) : undefined;
|
|
592
|
+
if (graderRoute)
|
|
593
|
+
tierRoutes.set(GRADER, graderRoute);
|
|
584
594
|
// Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
|
|
585
595
|
// them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
|
|
586
596
|
const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff }, seedLaid?.workflows ?? []);
|
|
@@ -660,10 +670,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
660
670
|
// The run's end-of-run step, when it learns, the same as the pi spec's: the compile turn and the owner's correction over
|
|
661
671
|
// the run's store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this
|
|
662
672
|
// claim's Archil disk — so the draft is checked against the seed in the run's own Workspace, never this machine's local path.
|
|
663
|
-
// A replay run or an audit's shadow run
|
|
673
|
+
// A replay run or an audit's shadow run learns nothing at its end: it is the promotion's, never the agent's to learn
|
|
674
|
+
// from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
|
|
664
675
|
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
665
676
|
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
666
|
-
const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
|
|
677
|
+
const endOfRun = launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, folder: learningFolder, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
|
|
667
678
|
store: deps.store,
|
|
668
679
|
data: deps.data,
|
|
669
680
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -682,6 +693,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
682
693
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
683
694
|
return {
|
|
684
695
|
adapter,
|
|
696
|
+
facts: ownerFacts,
|
|
685
697
|
session,
|
|
686
698
|
input,
|
|
687
699
|
// A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
|
|
@@ -740,7 +752,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
740
752
|
const metrics = cliRunMetrics(piShaped(entries), booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}`, catalog: await hashedMcpOf(deps.store, claim.runId) });
|
|
741
753
|
// Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
|
|
742
754
|
// cost an earlier end stored).
|
|
743
|
-
return { metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries) } };
|
|
755
|
+
return { metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries), costBasis: costBasisOf(booked) } };
|
|
744
756
|
},
|
|
745
757
|
// A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
|
|
746
758
|
...(heldComputer ? { held: heldComputer } : {}),
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LearningFolder } from "../learn/folder.js";
|
|
2
|
+
import { type GraderReply } from "../learn/promote.js";
|
|
3
|
+
import type { PortModels } from "../port-models.js";
|
|
4
|
+
import type { RunLaunch } from "../run-launch.js";
|
|
5
|
+
import type { Store } from "../store/store.js";
|
|
6
|
+
import type { EndOfRunTurn } from "./loop-contract.js";
|
|
7
|
+
/** The grader's route among a run's tier routes (never a learned workflow's tier, nor a subagent's), which is also the
|
|
8
|
+
* label its requests carry on the run's record. */
|
|
9
|
+
export declare const GRADER = "grader";
|
|
10
|
+
export type CompareEndDeps = {
|
|
11
|
+
readonly store: Store;
|
|
12
|
+
readonly folder: () => LearningFolder;
|
|
13
|
+
readonly log: (line: string) => void;
|
|
14
|
+
readonly redact?: (text: string) => string;
|
|
15
|
+
};
|
|
16
|
+
/** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
|
|
17
|
+
* asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
|
|
18
|
+
* agree_on, graderRouteOf), and the two answers are not already the same. In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
|
|
19
|
+
* learning ledger, which no run's process may. A comparison that fails keeps no verdict: the pair then differs, compared
|
|
20
|
+
* whole (compareAnswers), in the log's words. */
|
|
21
|
+
export declare function compareEndOfRun(launch: RunLaunch, deps: CompareEndDeps): EndOfRunTurn | undefined;
|
|
22
|
+
/** How long one grader request may take before it is cut: a verdict is a few words, so a request this late is stuck. */
|
|
23
|
+
export declare const GRADER_DEADLINE_MS = 60000;
|
|
24
|
+
/** One request to the grader's model over `models` (the run's port on the grader's route): its reply's text, the run's
|
|
25
|
+
* cap refusing it (`refused`: the proxy sent nothing and booked nothing), or a failure on its way (`failed`). pi-ai
|
|
26
|
+
* retries nothing of its own: the one retry is gradeAnswers'. Bounded by `signal` (the run's stop, its lost claim, its
|
|
27
|
+
* session closing) and `deadlineMs`, one combined abort signal: either one aborts the request and answers `cut`, and
|
|
28
|
+
* gradeAnswers asks it no more. Whatever it spent before it was cut is booked as any cut request is (the run's cap at its
|
|
29
|
+
* worst case). */
|
|
30
|
+
export declare function graderAsk(models: PortModels, request: {
|
|
31
|
+
readonly system: string;
|
|
32
|
+
readonly user: string;
|
|
33
|
+
}, given?: {
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
readonly deadlineMs?: number;
|
|
36
|
+
}): Promise<GraderReply>;
|
|
37
|
+
/** `step` with the run's grader handed in: its fast model's name and one request to it, over `models` (the run's port on
|
|
38
|
+
* GRADER), cut by the step's `signal` (the loop aborts it on a person's stop or cancel, a lost claim or the session
|
|
39
|
+
* closing) or at GRADER_DEADLINE_MS. No grader: no step at all, so the run ends as it did before there was one. */
|
|
40
|
+
export declare function withGrader(step: EndOfRunTurn | undefined, grader: {
|
|
41
|
+
readonly model: string;
|
|
42
|
+
readonly models: () => Promise<PortModels>;
|
|
43
|
+
} | undefined): EndOfRunTurn | undefined;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
|
+
import { gradeAnswers, sameAnswer } from "../learn/promote.js";
|
|
3
|
+
import { runPathOverStore } from "../store-reads/learning.js";
|
|
4
|
+
import { auditedAnswerOf } from "./audit.js";
|
|
5
|
+
import { held, heldEndOfRun } from "./held.js";
|
|
6
|
+
import { answerOf } from "./promotion.js";
|
|
7
|
+
/** The grader's route among a run's tier routes (never a learned workflow's tier, nor a subagent's), which is also the
|
|
8
|
+
* label its requests carry on the run's record. */
|
|
9
|
+
export const GRADER = "grader";
|
|
10
|
+
/** The most tokens the grader's verdict may take: a JSON object of a few words. */
|
|
11
|
+
const GRADER_MAX_TOKENS = 1_000;
|
|
12
|
+
/** The job input as the grader reads it: the launch's text, or its typed input as JSON. */
|
|
13
|
+
const inputText = (input) => (typeof input === "string" ? input : JSON.stringify(input ?? null));
|
|
14
|
+
/** The two answers a replay run or a shadow compares at its end: the agent's and the workflow's. A replay's workflow
|
|
15
|
+
* answer is its own, when the workflow it replays answered it; the agent's is its graded run's. A shadow's agent answer
|
|
16
|
+
* is its own; the workflow's is the served run's answer it audits (its open ledger line's turn). Null: nothing to
|
|
17
|
+
* compare. */
|
|
18
|
+
async function pairOf(launch, deps, runId) {
|
|
19
|
+
if (launch.replay) {
|
|
20
|
+
const path = await runPathOverStore(deps.store, runId, launch.learning, deps.redact);
|
|
21
|
+
if (path.path !== "workflow" || path.workflow !== launch.replay.workflow)
|
|
22
|
+
return null;
|
|
23
|
+
const [workflow, agent] = [await answerOf(deps.store, runId, BACKGROUND_CONTEXT), await answerOf(deps.store, launch.replay.of, BACKGROUND_CONTEXT)];
|
|
24
|
+
return workflow === null || agent === null ? null : { agent, workflow };
|
|
25
|
+
}
|
|
26
|
+
if (launch.audit) {
|
|
27
|
+
const [agent, workflow] = [await answerOf(deps.store, runId, BACKGROUND_CONTEXT), await auditedAnswerOf({ store: deps.store, context: BACKGROUND_CONTEXT, folder: deps.folder }, runId)];
|
|
28
|
+
return workflow === null || agent === null ? null : { agent, workflow };
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
|
|
33
|
+
* asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
|
|
34
|
+
* agree_on, graderRouteOf), and the two answers are not already the same. In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
|
|
35
|
+
* learning ledger, which no run's process may. A comparison that fails keeps no verdict: the pair then differs, compared
|
|
36
|
+
* whole (compareAnswers), in the log's words. */
|
|
37
|
+
export function compareEndOfRun(launch, deps) {
|
|
38
|
+
if (held())
|
|
39
|
+
return heldEndOfRun();
|
|
40
|
+
return async (input) => {
|
|
41
|
+
if (input.cut !== undefined || input.outcome !== "completed" || !input.grade || input.grader === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
try {
|
|
44
|
+
const pair = await pairOf(launch, deps, input.runId);
|
|
45
|
+
if (!pair || sameAnswer(pair.agent, pair.workflow))
|
|
46
|
+
return undefined;
|
|
47
|
+
const grade = input.grade;
|
|
48
|
+
const compared = await gradeAnswers(inputText(launch.input), pair.agent, pair.workflow, { model: input.grader, ask: (request) => grade(request) });
|
|
49
|
+
return { also: [], compared };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
deps.log(`learning: run ${input.runId}'s comparison was not asked (${error?.message ?? error})`);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** How long one grader request may take before it is cut: a verdict is a few words, so a request this late is stuck. */
|
|
58
|
+
export const GRADER_DEADLINE_MS = 60_000;
|
|
59
|
+
/** One request to the grader's model over `models` (the run's port on the grader's route): its reply's text, the run's
|
|
60
|
+
* cap refusing it (`refused`: the proxy sent nothing and booked nothing), or a failure on its way (`failed`). pi-ai
|
|
61
|
+
* retries nothing of its own: the one retry is gradeAnswers'. Bounded by `signal` (the run's stop, its lost claim, its
|
|
62
|
+
* session closing) and `deadlineMs`, one combined abort signal: either one aborts the request and answers `cut`, and
|
|
63
|
+
* gradeAnswers asks it no more. Whatever it spent before it was cut is booked as any cut request is (the run's cap at its
|
|
64
|
+
* worst case). */
|
|
65
|
+
export async function graderAsk(models, request, given = {}) {
|
|
66
|
+
const failure = (words) => (/spend_cap_reached/.test(words) ? { refused: words } : { failed: words });
|
|
67
|
+
const deadlineMs = given.deadlineMs ?? GRADER_DEADLINE_MS;
|
|
68
|
+
const stopped = { cut: "its request was stopped with the run" };
|
|
69
|
+
if (given.signal?.aborted)
|
|
70
|
+
return stopped;
|
|
71
|
+
const limit = AbortSignal.timeout(deadlineMs);
|
|
72
|
+
const signal = given.signal ? AbortSignal.any([given.signal, limit]) : limit;
|
|
73
|
+
// An aborted request answers by whichever signal aborted it: the run's stop, else the deadline.
|
|
74
|
+
const cutOf = () => (given.signal?.aborted ? stopped : { cut: `its request gave no answer within ${deadlineMs / 1000} s` });
|
|
75
|
+
try {
|
|
76
|
+
const model = models.getModels()[0];
|
|
77
|
+
if (!model)
|
|
78
|
+
return { failed: "the grader's route is not up" };
|
|
79
|
+
const message = await models.completeSimple(model, { systemPrompt: request.system, messages: [{ role: "user", content: request.user, timestamp: Date.now() }] }, { maxTokens: GRADER_MAX_TOKENS, maxRetries: 0, signal });
|
|
80
|
+
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
81
|
+
return signal.aborted ? cutOf() : failure(message.errorMessage ?? message.stopReason);
|
|
82
|
+
return { text: message.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("") };
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return signal.aborted ? cutOf() : failure(error?.message ?? String(error));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** `step` with the run's grader handed in: its fast model's name and one request to it, over `models` (the run's port on
|
|
89
|
+
* GRADER), cut by the step's `signal` (the loop aborts it on a person's stop or cancel, a lost claim or the session
|
|
90
|
+
* closing) or at GRADER_DEADLINE_MS. No grader: no step at all, so the run ends as it did before there was one. */
|
|
91
|
+
export function withGrader(step, grader) {
|
|
92
|
+
if (!step || !grader)
|
|
93
|
+
return undefined;
|
|
94
|
+
return (input) => step({ ...input, grader: grader.model, grade: async (request) => graderAsk(await grader.models(), request, { signal: input.signal }) });
|
|
95
|
+
}
|
|
@@ -24,6 +24,9 @@ export type ComputerHoldChange = {
|
|
|
24
24
|
/** Calls `listener` after each change of run `runId`'s hold is committed to its journal, in order, in this process.
|
|
25
25
|
* Returns the unsubscribe. */
|
|
26
26
|
export declare function onComputerHold(runId: string, listener: (change: ComputerHoldChange) => void): () => void;
|
|
27
|
+
/** A change run `runId`'s own process committed (Held.computerHold), signalled in its runner's process: its state, end and
|
|
28
|
+
* words as data, the words cut by the runner's redactor (`cut`); anything else is no change and is dropped. */
|
|
29
|
+
export declare function heardComputerHold(runId: string, change: unknown, cut: (text: string) => string): void;
|
|
27
30
|
/** Whether a command row is the person's turn with the run's computer. */
|
|
28
31
|
export declare const isComputerCommand: (command: Pick<Command, "kind">) => boolean;
|
|
29
32
|
/** The journal's side of run `runId`'s hold, for the pass whose Harness `commit` writes root entries (in one commit, in
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HOST_PHASE } from "../timeline/index.js";
|
|
2
|
-
import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, holdIn, holdWords, takeEndedWords, } from "../computer-commands.js";
|
|
2
|
+
import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, ENDS, holdIn, holdWords, STATES, takeEndedWords, } from "../computer-commands.js";
|
|
3
|
+
import { held } from "./held.js";
|
|
3
4
|
import { KINDS } from "./journal-kinds.js";
|
|
4
5
|
import { journalEntries } from "./journal-reader.js";
|
|
5
6
|
/** Whether the run's journal says an earlier claim made the run a computer of its own (KINDS.computerMade, which only a
|
|
@@ -28,6 +29,25 @@ const signal = (runId, change) => {
|
|
|
28
29
|
catch { /* a listener's error is not the hold's */ }
|
|
29
30
|
}
|
|
30
31
|
};
|
|
32
|
+
/** A committed change, signalled where the run's viewer listens: in this process, or, in a run's own process
|
|
33
|
+
* (run-child.ts), in its runner's, which holds the run's computer and its view (Held.computerHold). */
|
|
34
|
+
const committed = (runId, change) => {
|
|
35
|
+
const runner = held();
|
|
36
|
+
if (runner)
|
|
37
|
+
void runner.computerHold(change).catch(() => undefined);
|
|
38
|
+
else
|
|
39
|
+
signal(runId, change);
|
|
40
|
+
};
|
|
41
|
+
/** A change run `runId`'s own process committed (Held.computerHold), signalled in its runner's process: its state, end and
|
|
42
|
+
* words as data, the words cut by the runner's redactor (`cut`); anything else is no change and is dropped. */
|
|
43
|
+
export function heardComputerHold(runId, change, cut) {
|
|
44
|
+
if (!change || typeof change !== "object")
|
|
45
|
+
return;
|
|
46
|
+
const { state, ended, message } = change;
|
|
47
|
+
if (!STATES.includes(state) || (ended !== undefined && !ENDS.includes(ended)) || (message !== undefined && typeof message !== "string"))
|
|
48
|
+
return;
|
|
49
|
+
signal(runId, { state: state, ...(ended !== undefined ? { ended: ended } : {}), ...(typeof message === "string" ? { message: cut(message) } : {}) });
|
|
50
|
+
}
|
|
31
51
|
/** Whether a command row is the person's turn with the run's computer. */
|
|
32
52
|
export const isComputerCommand = (command) => command.kind === COMPUTER_TAKE_OVER || command.kind === COMPUTER_HAND_BACK;
|
|
33
53
|
/** The journal's side of run `runId`'s hold, for the pass whose Harness `commit` writes root entries (in one commit, in
|
|
@@ -79,7 +99,7 @@ export function journalHold(runId, computer, commit, now = Date.now) {
|
|
|
79
99
|
const off = hold.on((event) => {
|
|
80
100
|
const entries = entriesOf(event);
|
|
81
101
|
const change = changeOf(event, entries);
|
|
82
|
-
void write(entries).then(() => change &&
|
|
102
|
+
void write(entries).then(() => change && committed(runId, change), () => undefined);
|
|
83
103
|
});
|
|
84
104
|
return {
|
|
85
105
|
/** The run's computer is up for this pass: the server shows it live, the agent driving. `prior`, the run's root
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
2
|
+
import type { SuiteTool } from "./subject.js";
|
|
3
|
+
/** The suite's `tools` (setup.tools) as host tools, in their order. */
|
|
4
|
+
export declare function suiteHostTools(tools: Readonly<Record<string, SuiteTool>>): HostTool[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The suite's `tools` (setup.tools) as host tools, in their order. */
|
|
2
|
+
export function suiteHostTools(tools) {
|
|
3
|
+
return Object.values(tools).map((tool) => ({
|
|
4
|
+
name: tool.name,
|
|
5
|
+
description: `The suite's ${tool.name} tool.`,
|
|
6
|
+
inputSchema: { type: "object", properties: {} },
|
|
7
|
+
replay: tool.replaySafe ? "safe" : "never",
|
|
8
|
+
call: async (args, context) => ({
|
|
9
|
+
text: String(await tool.run((args ?? {}), context.signal)),
|
|
10
|
+
...(tool.images ? { images: tool.images } : {}),
|
|
11
|
+
...(tool.structured !== undefined ? { structured: tool.structured } : {}),
|
|
12
|
+
}),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
@@ -8,8 +8,13 @@ export declare class NeverFits extends ClaimRefused {
|
|
|
8
8
|
}
|
|
9
9
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
10
10
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
11
|
-
export declare function resolveRunnerLoop(
|
|
11
|
+
export declare function resolveRunnerLoop(given: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
|
|
12
12
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
13
13
|
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
14
14
|
* start and the test server pass this to startRunner. */
|
|
15
15
|
export declare function dispatchRunner(deps: AdapterSpecDeps): LoopFactory;
|
|
16
|
+
/** `deps` with the model gateway saved in the console laid over its run environment (model-gateway.ts withSavedGateway),
|
|
17
|
+
* read from the store now; `deps` itself where none is saved or the runner's environment names its own. A run's own
|
|
18
|
+
* process (no seal key) reads nothing of it: its runner laid it over the claim (run-child-host.ts) and marked it
|
|
19
|
+
* (SAVED_GATEWAY_ENV), and only that mark is read here. */
|
|
20
|
+
export declare function withSavedGatewayDeps(deps: AdapterSpecDeps): Promise<AdapterSpecDeps>;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { envGatewayInForce, readSavedGateway, savedGatewayIn, savedGatewayMarked, SAVED_GATEWAY_ENV, withSavedGateway } from "../model-gateway.js";
|
|
2
|
+
import { GATEWAY_KEY_ENV } from "../model.js";
|
|
3
|
+
import { heldRedactor } from "./redact.js";
|
|
4
|
+
import { envValue } from "../key-meta.js";
|
|
1
5
|
import { createSdkLoop } from "./sdk-loop.js";
|
|
2
6
|
import { createNativeLoop } from "./native-loop.js";
|
|
3
7
|
// The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
|
|
@@ -29,63 +33,86 @@ export class NeverFits extends ClaimRefused {
|
|
|
29
33
|
}
|
|
30
34
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
31
35
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
32
|
-
export function resolveRunnerLoop(
|
|
36
|
+
export function resolveRunnerLoop(given) {
|
|
33
37
|
return async (harness, launch, runId) => {
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
|
|
41
|
-
// The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
|
|
42
|
-
// store-secrets.ts), and every one the server keeps is held by the run's one redactor.
|
|
43
|
-
return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
|
|
44
|
-
}
|
|
45
|
-
// A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
|
|
46
|
-
// start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
|
|
47
|
-
if (launch.sdk)
|
|
48
|
-
return createSdkLoop(launch, deps, async () => {
|
|
49
|
-
const base = deps.env ?? process.env;
|
|
50
|
-
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
51
|
-
// It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
|
|
52
|
-
// skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
53
|
-
const off = noServerKeyFor(env, "An SDK run's compile turn");
|
|
54
|
-
if (off) {
|
|
55
|
-
deps.log?.(off);
|
|
56
|
-
throw new Error(off);
|
|
57
|
-
}
|
|
58
|
-
return askRouteOf(launch.learning.model, env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
|
|
59
|
-
});
|
|
60
|
-
if (launch.native)
|
|
61
|
-
return createNativeLoop(launch, deps);
|
|
62
|
-
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
63
|
-
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
64
|
-
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
65
|
-
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
66
|
-
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
67
|
-
const env = deps.env ?? process.env;
|
|
68
|
-
const runner = resolveHarness(harness, env);
|
|
69
|
-
if (runner) {
|
|
70
|
-
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
71
|
-
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
72
|
-
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
73
|
-
// the host's memory and its OOM kill would take every run on it.
|
|
74
|
-
const tooBig = neverFits(harness, hostMemory(), env);
|
|
75
|
-
if (tooBig)
|
|
76
|
-
throw new NeverFits(tooBig);
|
|
77
|
-
const entry = harnessOf(env, harness);
|
|
78
|
-
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
79
|
-
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
80
|
-
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
81
|
-
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
82
|
-
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
83
|
-
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
84
|
-
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
85
|
-
}
|
|
86
|
-
return undefined;
|
|
38
|
+
// The model gateway saved in the console (model-gateway.ts), read from the store at each claim and laid over the run
|
|
39
|
+
// environment as its variables would be, so a gateway saved or removed since reaches the next run with no restart. A
|
|
40
|
+
// gateway the runner's environment names wins, and nothing saved is read over it.
|
|
41
|
+
const deps = await withSavedGatewayDeps(given);
|
|
42
|
+
const made = await loopOn(deps, harness, launch, runId);
|
|
43
|
+
return made && holdingGatewayKey(made, deps.env);
|
|
87
44
|
};
|
|
88
45
|
}
|
|
46
|
+
/** `made` with the saved gateway's key, as this claim read it, held by the run's one redactor before the loop starts: the
|
|
47
|
+
* key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
|
|
48
|
+
* saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
|
|
49
|
+
* where the gateway is not the saved one. */
|
|
50
|
+
function holdingGatewayKey(made, env) {
|
|
51
|
+
const key = env && savedGatewayIn(env) ? env[GATEWAY_KEY_ENV] : undefined;
|
|
52
|
+
if (!key)
|
|
53
|
+
return made;
|
|
54
|
+
return (loopDeps) => {
|
|
55
|
+
if (loopDeps.redact)
|
|
56
|
+
heldRedactor(loopDeps.redact).hold([key]);
|
|
57
|
+
return made(loopDeps);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The loop a claimed run runs on, over `deps` (the saved gateway laid over its environment). */
|
|
61
|
+
async function loopOn(deps, harness, launch, runId) {
|
|
62
|
+
// A workflow revision runs on the workflow loop whatever the harness its body names (its default is pi): read the
|
|
63
|
+
// revision to tell it apart from an agentic pi run.
|
|
64
|
+
const run = await deps.store.runs.get(runId);
|
|
65
|
+
const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
|
|
66
|
+
if (revision && isWorkflowRevision(revision)) {
|
|
67
|
+
// A workflow run on the workflow loop: its claim-time spec (workflow-spec.ts) resolves each tier's model the one way
|
|
68
|
+
// the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
|
|
69
|
+
// The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
|
|
70
|
+
// store-secrets.ts), and every one the server keeps is held by the run's one redactor.
|
|
71
|
+
return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
|
|
72
|
+
}
|
|
73
|
+
// A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
|
|
74
|
+
// start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
|
|
75
|
+
if (launch.sdk)
|
|
76
|
+
return createSdkLoop(launch, deps, async () => {
|
|
77
|
+
const base = deps.env ?? process.env;
|
|
78
|
+
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
79
|
+
// It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
|
|
80
|
+
// skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
81
|
+
const off = noServerKeyFor(env, "An SDK run's compile turn");
|
|
82
|
+
if (off) {
|
|
83
|
+
deps.log?.(off);
|
|
84
|
+
throw new Error(off);
|
|
85
|
+
}
|
|
86
|
+
return askRouteOf(launch.learning.model, env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
|
|
87
|
+
});
|
|
88
|
+
if (launch.native)
|
|
89
|
+
return createNativeLoop(launch, deps);
|
|
90
|
+
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
91
|
+
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
92
|
+
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
93
|
+
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
94
|
+
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
95
|
+
const env = deps.env ?? process.env;
|
|
96
|
+
const runner = resolveHarness(harness, env);
|
|
97
|
+
if (runner) {
|
|
98
|
+
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
99
|
+
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
100
|
+
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
101
|
+
// the host's memory and its OOM kill would take every run on it.
|
|
102
|
+
const tooBig = neverFits(harness, hostMemory(), env);
|
|
103
|
+
if (tooBig)
|
|
104
|
+
throw new NeverFits(tooBig);
|
|
105
|
+
const entry = harnessOf(env, harness);
|
|
106
|
+
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
107
|
+
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
108
|
+
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
109
|
+
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
110
|
+
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
111
|
+
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
112
|
+
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
89
116
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
90
117
|
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
91
118
|
* start and the test server pass this to startRunner. */
|
|
@@ -95,3 +122,16 @@ export function dispatchRunner(deps) {
|
|
|
95
122
|
resolve: resolveRunnerLoop(deps),
|
|
96
123
|
});
|
|
97
124
|
}
|
|
125
|
+
/** `deps` with the model gateway saved in the console laid over its run environment (model-gateway.ts withSavedGateway),
|
|
126
|
+
* read from the store now; `deps` itself where none is saved or the runner's environment names its own. A run's own
|
|
127
|
+
* process (no seal key) reads nothing of it: its runner laid it over the claim (run-child-host.ts) and marked it
|
|
128
|
+
* (SAVED_GATEWAY_ENV), and only that mark is read here. */
|
|
129
|
+
export async function withSavedGatewayDeps(deps) {
|
|
130
|
+
const base = deps.env ?? process.env;
|
|
131
|
+
if (envValue(base, SAVED_GATEWAY_ENV) === "1")
|
|
132
|
+
return { ...deps, env: savedGatewayMarked(base) };
|
|
133
|
+
if (envGatewayInForce(base) || !deps.sealKey)
|
|
134
|
+
return deps;
|
|
135
|
+
const saved = await readSavedGateway(deps.store, deps.sealKey);
|
|
136
|
+
return saved ? { ...deps, env: withSavedGateway(base, saved) } : deps;
|
|
137
|
+
}
|
package/dist/runner/held.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import type { PlanReader } from "../chatgpt-plan.js";
|
|
|
2
2
|
import type { Tier } from "../model.js";
|
|
3
3
|
import type { RunSignIn } from "../sign-ins-store.js";
|
|
4
4
|
import type { LiveHandover } from "../browser-live.js";
|
|
5
|
+
import type { ComputerHoldChange } from "./computer-journal.js";
|
|
5
6
|
import type { ApprovalPrice, ToolEffect } from "../tool-gate.js";
|
|
6
7
|
import type { OpenedAccount } from "../email/account.js";
|
|
7
8
|
import type { SavedCalendar } from "../calendar/address.js";
|
|
8
9
|
import type { Workspace } from "../workspace/workspace.js";
|
|
9
10
|
import type { GithubAppAccessAt } from "./github-app.js";
|
|
10
11
|
import type { HarnessInstallEntry, HarnessPins } from "../harness-install.js";
|
|
11
|
-
import type { AlsoRow } from "../store/store.js";
|
|
12
12
|
import type { RunModelKey } from "../store/seal.js";
|
|
13
13
|
import type { EndOfRunKept, EndOfRunTurn } from "./loop-contract.js";
|
|
14
14
|
import type { LearnedFirst } from "./learned-first.js";
|
|
@@ -90,6 +90,9 @@ export interface Held {
|
|
|
90
90
|
/** A browser session's viewer handed over, and taken back (browser-live.ts). */
|
|
91
91
|
liveViewerPut(handover: LiveHandover): Promise<boolean>;
|
|
92
92
|
liveViewerDrop(tag?: string): Promise<void>;
|
|
93
|
+
/** A change of the claim's computer's hold, committed to the run's journal here: signalled on the runner, whose live
|
|
94
|
+
* view of the computer tells its open viewer (computer-journal.ts heardComputerHold). */
|
|
95
|
+
computerHold(change: ComputerHoldChange): Promise<void>;
|
|
93
96
|
/** The MCP credentials run `from` was handed, sealed again for run `id`, a run this one starts (promotion.ts,
|
|
94
97
|
* audit.ts): none unless `from` is the claim's own run. */
|
|
95
98
|
handOn(from: string, id: string): Promise<Uint8Array | undefined>;
|
|
@@ -119,9 +122,7 @@ export interface Held {
|
|
|
119
122
|
* what the run's learning must never keep is every secret the runner holds, which no run's process is given. Its
|
|
120
123
|
* turns are asked through `input.ask`, the run's own session; `input.keptOf` is read once, for the round the runner
|
|
121
124
|
* reads. */
|
|
122
|
-
endOfRun(input: HeldEndOfRunInput): Promise<
|
|
123
|
-
readonly also: readonly AlsoRow[];
|
|
124
|
-
} | undefined>;
|
|
125
|
+
endOfRun(input: HeldEndOfRunInput): Promise<Awaited<ReturnType<EndOfRunTurn>>>;
|
|
125
126
|
/** The claim's learned first choice (learned-first.ts learnedFirst), run by the runner over the workflows it reads at the
|
|
126
127
|
* claim's seed: `laid` says only whether the process's seed lay laid any (false: none is laid). Its audits, promotion
|
|
127
128
|
* and replay reads are the runner's. */
|
|
@@ -74,6 +74,9 @@ export declare const KINDS: {
|
|
|
74
74
|
* later claim that asks the same turn again reads the first ask's (the commit of main a compile turn was asked at among
|
|
75
75
|
* them), never its own. Neither a call nor a message: the reader passes over it. */
|
|
76
76
|
readonly endOfRunKept: "agentrun.end-of-run.kept";
|
|
77
|
+
/** A replay run's or an audit shadow's grader verdict (learn/promote.ts Compared), from its end-of-run step, written on
|
|
78
|
+
* the root before its end: its metrics carry it (`replay.compared`, `audit.compared`). Neither a call nor a message. */
|
|
79
|
+
readonly compared: "agentrun.learning.compared";
|
|
77
80
|
/** How the run's job's own turn ended (JobEndData: the end it gives the run, a CLI's error answer), as the claim that
|
|
78
81
|
* read it decided, written on the root before the end-of-run step asks its first turn. A claim that finds that turn
|
|
79
82
|
* open ends the run on the newest one, never working the job's end out again. Neither a call nor a message. */
|
|
@@ -208,7 +211,7 @@ export interface CallEndData {
|
|
|
208
211
|
readonly callId: string;
|
|
209
212
|
readonly status: CallStatus;
|
|
210
213
|
readonly output?: unknown;
|
|
211
|
-
/** On an `interrupted` end the run's own end wrote (a call
|
|
214
|
+
/** On an `interrupted` end the run's own end wrote (a CLI's call still open: adapter-loop.ts openCalls):
|
|
212
215
|
* nothing ended it, so it has no outcome. Its row reads interrupted, never failed (CALL_ENDED_WITH_RUN). */
|
|
213
216
|
readonly withRun?: true;
|
|
214
217
|
/** When it was written (ms, the loop's clock): the Timeline dates the result's row by it. */
|
|
@@ -74,6 +74,9 @@ export const KINDS = {
|
|
|
74
74
|
* later claim that asks the same turn again reads the first ask's (the commit of main a compile turn was asked at among
|
|
75
75
|
* them), never its own. Neither a call nor a message: the reader passes over it. */
|
|
76
76
|
endOfRunKept: "agentrun.end-of-run.kept",
|
|
77
|
+
/** A replay run's or an audit shadow's grader verdict (learn/promote.ts Compared), from its end-of-run step, written on
|
|
78
|
+
* the root before its end: its metrics carry it (`replay.compared`, `audit.compared`). Neither a call nor a message. */
|
|
79
|
+
compared: "agentrun.learning.compared",
|
|
77
80
|
/** How the run's job's own turn ended (JobEndData: the end it gives the run, a CLI's error answer), as the claim that
|
|
78
81
|
* read it decided, written on the root before the end-of-run step asks its first turn. A claim that finds that turn
|
|
79
82
|
* open ends the run on the newest one, never working the job's end out again. Neither a call nor a message. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AlsoRow, Claim, Command, Journal } from "../store/store.js";
|
|
2
2
|
import type { Redact } from "./redact.js";
|
|
3
|
+
import type { Compared, GraderReply } from "../learn/promote.js";
|
|
3
4
|
export type { AlsoRow, Claim, Command, Journal };
|
|
4
5
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
5
6
|
* answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
|
|
@@ -64,9 +65,18 @@ export type EndOfRunTurn = (input: {
|
|
|
64
65
|
* earlier claim (or this one) started, readable before `ask`, so a step that skips or is cut never asks, and still
|
|
65
66
|
* closes that look-back with its first ask's figures. Undefined when none asked it, or the loop keeps no record (pi's). */
|
|
66
67
|
keptOf?(round: number): EndOfRunKept | undefined;
|
|
68
|
+
/** A replay run's or an audit shadow's grader (learn/promote.ts): its fast model's name (`grader`), and one request to
|
|
69
|
+
* it (`grade`), sent through the run's own session on its one cap, booked as the run's spend; a refusal of that cap
|
|
70
|
+
* never parks the run (`refused`). Absent when the run has no grader route (no fast model, or agree_on named). */
|
|
71
|
+
readonly grader?: string;
|
|
72
|
+
grade?(request: {
|
|
73
|
+
readonly system: string;
|
|
74
|
+
readonly user: string;
|
|
75
|
+
}): Promise<GraderReply>;
|
|
67
76
|
readonly signal: AbortSignal;
|
|
68
77
|
}) => Promise<{
|
|
69
78
|
readonly also: readonly AlsoRow[];
|
|
79
|
+
readonly compared?: Compared;
|
|
70
80
|
} | undefined>;
|
|
71
81
|
/** How a loop's start() ended. The run's own outcome (state, cost) is already in the journal's last commit. */
|
|
72
82
|
export type LoopEnd = {
|