@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.44
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 +126 -0
- package/README.md +221 -31
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-sources.js +25 -5
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +203 -87
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +516 -134
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// The runner's pi spec (design 2.1: "the runner takes every run"). What app.ts built for a run it launched — the run's
|
|
2
|
+
// workspace, its computer, its tools, its model route, its spend cap and its end metrics — built here instead, from the
|
|
3
|
+
// run's launch record and its revision, and handed to the kernel's adapter loop (adapter-loop.ts) as one AdapterRunSpec.
|
|
4
|
+
// The dispatch switch (dispatch.ts resolve) runs a pi run on `createAdapterLoop((claim, run) =>
|
|
5
|
+
// adapterRunSpecFromLaunch(launch, run, deps, claim, runner))`, and so does a harness a module adds with no adapter facts
|
|
6
|
+
// of its own: the session's adapter is the run's runner's (RunnerHarness.adapter), pi's for a pi run.
|
|
7
|
+
//
|
|
8
|
+
// The one ledger (B2c): pi's model requests go through the session's proxy, booked by the runner's booking under the
|
|
9
|
+
// run's cap; the cap prices a request as main's calculateCost does (tiers included), on the hold and the booking. The
|
|
10
|
+
// tools are the kernel registry's hands on the run's Workspace (runTools), and — once built through the ToolHost below —
|
|
11
|
+
// tools.ts's full set (browser, web, MCP, decisions, monid) by their own names. The gate before a call's intent is the
|
|
12
|
+
// run's revision's tool settings, read through runGate (approvals "never" among them), the adapter loop asking it.
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { stopRunWith } from "../paid-calls.js";
|
|
1
15
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
16
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
3
17
|
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
@@ -29,16 +43,17 @@ import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
|
|
|
29
43
|
import { promptOf, readsFiles } from "../skills.js";
|
|
30
44
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
31
45
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
32
|
-
import { COMPUTER_ROOT, recordingsFolder, runFolder } from "../workspace/paths.js";
|
|
46
|
+
import { COMPUTER_ROOT, recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
|
|
33
47
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
34
48
|
import { placeRunInputs } from "../uploads.js";
|
|
35
49
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
36
50
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
37
51
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
38
|
-
import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys,
|
|
52
|
+
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
39
53
|
import { catalogSessionNames, mcpForClaim } from "./mcp-run.js";
|
|
40
54
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
41
|
-
import {
|
|
55
|
+
import { RUNNER_HARNESSES } from "./adapters/index.js";
|
|
56
|
+
import { DEFAULT_HARNESS } from "../harness.js";
|
|
42
57
|
import { agentEntriesOf } from "./loop.js";
|
|
43
58
|
import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
|
|
44
59
|
import { ClaimRefused } from "./loop-contract.js";
|
|
@@ -47,6 +62,7 @@ import { journalEntries } from "./journal-reader.js";
|
|
|
47
62
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
48
63
|
import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
|
|
49
64
|
import { pathMetrics, servedOf, workflowFirstOf } from "./workflow-first.js";
|
|
65
|
+
import { AUDIT_PARKED, settleAudits, withAudit } from "./audit.js";
|
|
50
66
|
import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
|
|
51
67
|
import { specBuilt } from "./spec-holds.js";
|
|
52
68
|
import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
@@ -202,12 +218,14 @@ export async function storeSettings(store) {
|
|
|
202
218
|
return { settings: {}, problems: ["the stored tool settings could not be read"], unreadable: true };
|
|
203
219
|
}
|
|
204
220
|
}
|
|
205
|
-
/** pi's spec for a claimed run
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
/** pi's spec for a claimed run, on `runner`'s adapter (pi's when none is given; a harness module's runner for a harness it
|
|
222
|
+
* adds with no adapter facts), its visible record kept as that runner says (RunnerHarness.record). What it makes for the
|
|
223
|
+
* run (its Archil mount credential, its Workspace, its computer, its tools) is held until the spec's release; a build
|
|
224
|
+
* that throws part-way lets go what it made by then (spec-holds.ts). */
|
|
225
|
+
export function adapterRunSpecFromLaunch(launch, run, deps, claim, runner = RUNNER_HARNESSES[DEFAULT_HARNESS]) {
|
|
226
|
+
return specBuilt((holds) => adapterSpec(launch, run, deps, claim, holds, runner));
|
|
209
227
|
}
|
|
210
|
-
async function adapterSpec(launch, run, deps, claim, holds) {
|
|
228
|
+
async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
211
229
|
const context = BACKGROUND_CONTEXT;
|
|
212
230
|
// What this claim may reach on loopback, read once for its MCP servers and its calendar_events alike (mcpReachOf).
|
|
213
231
|
const reach = await mcpReachOf(deps);
|
|
@@ -316,7 +334,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
316
334
|
// claim's is a new one whatever ended the earlier claim (a lost runner, a server's stop, a park past its keep). The
|
|
317
335
|
// computer a park kept, attached again, brings its mount credential with it (inheritMount): none is minted. A
|
|
318
336
|
// recording of its screen (computer.record) goes in the run's recordings folder, beside its folder, said on its timeline.
|
|
319
|
-
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
337
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
320
338
|
// The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
|
|
321
339
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
322
340
|
// 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,
|
|
@@ -340,11 +358,20 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
340
358
|
// tools unlock and its model needs, scoped to the run as the old per-run environment was, so one run's keys never reach
|
|
341
359
|
// another's on this runner (claim-secrets.ts). MCP credentials are the other per-claim secret and come through mcp-claim.
|
|
342
360
|
const toolEnv = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
|
|
361
|
+
// The run's own model key, when its caller handed one (model_key, sealed in its launch): opened at every claim, a reclaim
|
|
362
|
+
// after a crash among them, and held by the run's one redactor. Its model routes read it alone; its tools never do.
|
|
363
|
+
// A run that starts on the server's key holds the claim's key holder too: a message's first key reaches its next request.
|
|
364
|
+
const runKey = await claimModelKey({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, claim.runId);
|
|
365
|
+
const keyed = keyedAtClaim(runKey);
|
|
366
|
+
if (keyed)
|
|
367
|
+
withoutModelKeys(toolEnv);
|
|
368
|
+
if (runKey)
|
|
369
|
+
holdRunKey(cut, runKey);
|
|
343
370
|
// The keys it opened join the run's one redactor before any tool or model request can echo one.
|
|
344
371
|
holdClaimed(cut, toolEnv);
|
|
345
372
|
// The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
|
|
346
|
-
// saved in Settings → Model keys runs the next run with no restart (withModelKeys).
|
|
347
|
-
const modelEnv =
|
|
373
|
+
// saved in Settings → Model keys runs the next run with no restart (withModelKeys). A run with its own key: that key.
|
|
374
|
+
const modelEnv = claimModelEnv(deps.env, toolEnv, runKey);
|
|
348
375
|
const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
|
|
349
376
|
await planBeforeRun(modelEnv, route.provider.plan ? { provider: PLAN_PROVIDER } : undefined);
|
|
350
377
|
// The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
|
|
@@ -373,9 +400,10 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
373
400
|
// requests as that route books them.
|
|
374
401
|
const tierWhy = new Map();
|
|
375
402
|
if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL)) {
|
|
376
|
-
|
|
403
|
+
// A run with its own model key: its subagents' models carry that key too, and no saved key is read.
|
|
404
|
+
const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
|
|
377
405
|
holdClaimed(cut, savedKeys);
|
|
378
|
-
const tierEnv =
|
|
406
|
+
const tierEnv = claimModelEnv(deps.env, { ...savedKeys, ...toolEnv }, runKey);
|
|
379
407
|
for (const tier of SUBAGENT_TIERS) {
|
|
380
408
|
if (body.modelTiers?.[tier] === undefined && tierModelOf(tierEnv, tier) === undefined)
|
|
381
409
|
continue;
|
|
@@ -387,17 +415,28 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
387
415
|
}
|
|
388
416
|
}
|
|
389
417
|
}
|
|
390
|
-
|
|
418
|
+
// The run's adapter is its runner's (runner/adapters/index.ts RunnerHarness: pi's, or the one a harness module's entry
|
|
419
|
+
// brings), made from the run's launch on its route. Its private files, where it keeps any, go in this claim's folder of
|
|
420
|
+
// the run's scratch (the CLI spec's layout), swept at the claim's end with the earlier claims' and any parent left empty.
|
|
421
|
+
// pi's own options (its extensions, tools, redactor, the model's catalog entry, hosted search, tiers, and the route's
|
|
422
|
+
// whole provider) are the harness's own options (`extra`), passed on as given.
|
|
423
|
+
const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
|
|
424
|
+
const harnesses = join(scratch, "harness");
|
|
425
|
+
holds.hold({ scratch: { sweep: async () => (await import("./cli-run-spec.js")).sweepScratch(harnesses, claim.epoch, [harnesses, scratch, dirname(scratch)]) } });
|
|
426
|
+
const adapter = await runner.adapter({
|
|
391
427
|
run,
|
|
428
|
+
model: route.model,
|
|
429
|
+
provider: route.provider,
|
|
430
|
+
...(route.price ? { price: route.price } : {}),
|
|
431
|
+
sessionsDir: join(harnesses, String(claim.epoch)),
|
|
432
|
+
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
433
|
+
}, {
|
|
392
434
|
// Read when the session opens (pi.ts), so the browser's extension pushed by bindNonHandTools below is in it.
|
|
393
435
|
extensions: native,
|
|
394
436
|
tools: piTools,
|
|
395
|
-
model: route.model,
|
|
396
437
|
provider: route.provider,
|
|
397
438
|
redact: cut,
|
|
398
439
|
...(route.like ? { like: route.like } : {}),
|
|
399
|
-
...(route.price ? { price: route.price } : {}),
|
|
400
|
-
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
401
440
|
// The run's web_search is its provider's hosted search (the launch's plane, as its start resolved it): the session's
|
|
402
441
|
// proxy admits that search's one request (it goes through the session's port: buildToolHost's `search`) and books it
|
|
403
442
|
// with each search it ran.
|
|
@@ -429,7 +468,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
429
468
|
const tierRoute = tierRoutes.get(by);
|
|
430
469
|
return tierRoute && tierRoute.model === id ? capModelOf(tierRoute) : undefined;
|
|
431
470
|
},
|
|
432
|
-
// What its learning runs' grades took beside it, read by every gate with its own sessions
|
|
471
|
+
// What its learning runs' grades and its audit's shadow took beside it, read by every gate with its own sessions
|
|
472
|
+
// (none: it queues none).
|
|
433
473
|
...(besideOf ? { beside: besideOf } : {}),
|
|
434
474
|
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
|
|
435
475
|
freeRequests: freeModelRequestsOf(deps.env),
|
|
@@ -457,15 +497,22 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
457
497
|
// chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
|
|
458
498
|
// onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
|
|
459
499
|
// becomes its model's.
|
|
460
|
-
// A replay run lays the workflow it replays
|
|
500
|
+
// A replay run lays only the workflow it replays (runner/promotion.ts replayLaid).
|
|
461
501
|
const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
|
|
462
502
|
// The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
|
|
463
503
|
// chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
|
|
464
504
|
// serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
|
|
465
505
|
// five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
|
|
466
506
|
// (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
|
|
507
|
+
// The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
|
|
508
|
+
// Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit, a replay check and
|
|
509
|
+
// the learning run's grade are skipped, in words, where the run brought its own key or the server holds none.
|
|
510
|
+
const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
|
|
511
|
+
const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
|
|
512
|
+
if (launch.learning && !launch.replay && !launch.audit)
|
|
513
|
+
await settleAudits(audits);
|
|
467
514
|
const promotion = claimPromotion({
|
|
468
|
-
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
|
|
515
|
+
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff,
|
|
469
516
|
});
|
|
470
517
|
const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
|
|
471
518
|
// A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
|
|
@@ -483,9 +530,10 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
483
530
|
// The keys those tiers' models need (tierModelKeys: a key saved in Settings too, which claimSecrets opened only for the
|
|
484
531
|
// run's own model), held by the run's one redactor, on the tiers' route env alone (withModelKeys, never enumerable),
|
|
485
532
|
// never on the tools' (toolEnv).
|
|
486
|
-
|
|
533
|
+
// A run with its own model key: its learned nodes' tiers carry that key too, and no saved key is read.
|
|
534
|
+
const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
487
535
|
holdClaimed(cut, tierKeys);
|
|
488
|
-
const tierEnv =
|
|
536
|
+
const tierEnv = claimModelEnv(deps.env, { ...toolEnv, ...tierKeys }, runKey);
|
|
489
537
|
for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
|
|
490
538
|
if ("why" in routed)
|
|
491
539
|
tierUnreachable.set(tier, routed.why);
|
|
@@ -581,10 +629,13 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
581
629
|
// Its learning folder is where the run's place keeps it — Mode 1 the agent's folder under the data directory, Mode 2 the
|
|
582
630
|
// agent's folder on THIS claim's Archil disk (the proposal is checked against the seed on the disk, never this machine's
|
|
583
631
|
// local path) — so the end-of-run step reads the run's own Workspace, the one the run worked in.
|
|
584
|
-
// A replay run asks nothing at its end: it is the promotion's, never the agent's to learn from.
|
|
585
|
-
|
|
632
|
+
// A replay run or an audit's shadow run asks nothing at its end: it is the promotion's, never the agent's to learn from.
|
|
633
|
+
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
634
|
+
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
635
|
+
const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
|
|
586
636
|
store: deps.store,
|
|
587
637
|
data: deps.data,
|
|
638
|
+
spendOff,
|
|
588
639
|
...(deps.env ? { env: deps.env } : {}),
|
|
589
640
|
// What the run must never learn beside the runner's secrets: the keys its claim handed it, every secret the server
|
|
590
641
|
// keeps sealed (storeSecrets: the run's redactor holds the same list), and its sign-in's pointers, read back from the
|
|
@@ -598,9 +649,11 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
598
649
|
learningFolder: archil === undefined
|
|
599
650
|
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
600
651
|
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
601
|
-
});
|
|
652
|
+
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
602
653
|
return {
|
|
603
654
|
adapter,
|
|
655
|
+
// Who keeps the run's visible record: its runner says (none: the adapter, as pi keeps its own).
|
|
656
|
+
...(runner.record ? { record: runner.record } : {}),
|
|
604
657
|
session,
|
|
605
658
|
input,
|
|
606
659
|
// A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
|
|
@@ -615,6 +668,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
615
668
|
// The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
|
|
616
669
|
// the catalog tools the session mounts; absent when none.
|
|
617
670
|
...(catalog ? { mcp: catalog } : {}),
|
|
671
|
+
// The run's own model key: a command row opens it again before the next model request (a message's new key).
|
|
672
|
+
...(runKey ? { modelKey: runKey } : {}),
|
|
618
673
|
// The run's end-of-run step, when it learns (the spec's, which the loop prefers over its deps': adapter-loop.ts stepOf).
|
|
619
674
|
...(endOfRun ? { endOfRun } : {}),
|
|
620
675
|
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
@@ -623,6 +678,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
623
678
|
// The tool host's install lifecycle (its bindings' onConversation/beforeResume/beforeRelease), run by the adapter loop.
|
|
624
679
|
lifecycle: life,
|
|
625
680
|
agentId: runRow.agentId,
|
|
681
|
+
// An audit's shadow run waits on no one: where it would park (an approval, a raise of its cap, a person's answer) it
|
|
682
|
+
// ends at once, its row `parked` (runner/audit.ts).
|
|
683
|
+
...(launch.audit ? { neverWaits: AUDIT_PARKED } : {}),
|
|
626
684
|
// 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,
|
|
627
685
|
// applies a take-over and a hand-back to it, and answers the computer call channel's rows on it.
|
|
628
686
|
...(loopComputer ? { computer: loopComputer } : {}),
|
|
@@ -33,5 +33,7 @@ export interface RunnerHarness {
|
|
|
33
33
|
}
|
|
34
34
|
/** Every harness the runner runs, by name. */
|
|
35
35
|
export declare const RUNNER_HARNESSES: Readonly<Record<string, RunnerHarness>>;
|
|
36
|
-
/** The harness the launch names,
|
|
37
|
-
|
|
36
|
+
/** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
|
|
37
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner). Undefined when
|
|
38
|
+
* the table has none by that name. `env`: the run's environment (this process's when not given). */
|
|
39
|
+
export declare function resolveHarness(harness: string, env?: NodeJS.ProcessEnv): RunnerHarness | undefined;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
2
2
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
3
3
|
import { facts as openCodeFacts } from "../../harness-opencode/facts.js";
|
|
4
|
+
import { harnessOf } from "../../harness-table.js";
|
|
4
5
|
import { piAdapter } from "./pi.js";
|
|
5
6
|
const CLAUDE_PACKAGE = "@parcha/agentrun-harness-claude";
|
|
6
7
|
const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
|
|
7
8
|
/** Every harness the runner runs, by name. */
|
|
8
9
|
export const RUNNER_HARNESSES = {
|
|
9
10
|
pi: {
|
|
10
|
-
|
|
11
|
+
// `extra`: pi's own options (PiAdapterOptions), as the run's spec gives them (adapter-run-spec.ts): its extensions,
|
|
12
|
+
// tools, redactor, tiers, and the route's whole provider over the launch's.
|
|
13
|
+
adapter: async (launch, extra = {}) => piAdapter({
|
|
11
14
|
run: launch.run,
|
|
12
15
|
model: launch.model,
|
|
13
16
|
provider: { api: launch.provider.api ?? "anthropic-messages", origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}), ...(launch.provider.auth ? { auth: launch.provider.auth } : {}) },
|
|
14
17
|
...(launch.price ? { price: launch.price } : {}),
|
|
15
18
|
...(launch.fetch ? { fetch: launch.fetch } : {}),
|
|
19
|
+
...extra,
|
|
16
20
|
}),
|
|
17
21
|
},
|
|
18
22
|
[claudeFacts.id]: {
|
|
@@ -70,7 +74,12 @@ export const RUNNER_HARNESSES = {
|
|
|
70
74
|
},
|
|
71
75
|
},
|
|
72
76
|
};
|
|
73
|
-
/** The harness the launch names,
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
/** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
|
|
78
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner). Undefined when
|
|
79
|
+
* the table has none by that name. `env`: the run's environment (this process's when not given). */
|
|
80
|
+
export function resolveHarness(harness, env = process.env) {
|
|
81
|
+
const entry = harnessOf(env, harness);
|
|
82
|
+
if (!entry)
|
|
83
|
+
return undefined;
|
|
84
|
+
return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : undefined);
|
|
76
85
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord/context";
|
|
2
|
+
import { type AuditLoop } from "../learning-setting.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
4
|
+
import { type RunRow, type Store } from "../store/store.js";
|
|
5
|
+
import { type LearningFolder } from "../learn/folder.js";
|
|
6
|
+
import type { Shown } from "../learning.js";
|
|
7
|
+
import type { EndOfRunTurn } from "./loop-contract.js";
|
|
8
|
+
import { type WorkflowFirst } from "./workflow-first.js";
|
|
9
|
+
/** What the audit reads and writes at a claim (or the server's grade): the agent, the run claimed (none for a grade),
|
|
10
|
+
* its revision (whose definition holds the numbers) and launch, the agent's learning folder, the host's secrets as a
|
|
11
|
+
* hold's texts are cut of them (`shown`, as a check's are), the seal key (a shadow is handed the per_run MCP
|
|
12
|
+
* credentials its served run was). */
|
|
13
|
+
export type AuditDeps = {
|
|
14
|
+
readonly store: Store;
|
|
15
|
+
readonly agentId: string;
|
|
16
|
+
readonly revisionId: string;
|
|
17
|
+
readonly context: Context;
|
|
18
|
+
readonly folder: () => LearningFolder;
|
|
19
|
+
readonly shown: () => Promise<Pick<Shown, "text">>;
|
|
20
|
+
readonly log: (line: string) => void;
|
|
21
|
+
readonly sealKey?: Buffer;
|
|
22
|
+
readonly now?: () => number;
|
|
23
|
+
/** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff): a shadow is a run the runner
|
|
24
|
+
* starts with no caller's key. Absent: it runs. */
|
|
25
|
+
readonly spendOff?: (what: string) => string | undefined;
|
|
26
|
+
};
|
|
27
|
+
/** The words a second hold within stop_window leaves on its record: what the owner reads. */
|
|
28
|
+
export declare const STOPPED_TWICE = "stopped: the workflow disagreed with the agent twice";
|
|
29
|
+
/** The audit numbers of revision `revisionId`'s definition (each one it leaves out at its default). */
|
|
30
|
+
export declare function auditLoopOfRevision(store: Pick<Store, "agents">, revisionId: string): Promise<AuditLoop>;
|
|
31
|
+
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
32
|
+
* started them): what the promotions read counts beside the audit line. */
|
|
33
|
+
export declare function notAuditableOf(store: Pick<Store, "runs">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
|
34
|
+
/** The words a shadow run ends failed with where it would wait on a person (AdapterRunSpec.neverWaits: an approval, a
|
|
35
|
+
* raise of its cap, which is what its served run's cap left, a question), what it would wait on after them: its row is
|
|
36
|
+
* `parked`, with no verdict. */
|
|
37
|
+
export declare const AUDIT_PARKED = "the audit ended where it would wait on a person";
|
|
38
|
+
/** The served run's end-of-run step `step` (none for a run that only uses what its agent learned), its audit started
|
|
39
|
+
* after it (startAudit) on an end the run reached on its own (a cut run starts none): the learned workflow that served
|
|
40
|
+
* it, read from its journal whatever claim it served on (servedOf), and, for a capped run, what its cap leaves once this
|
|
41
|
+
* end is counted (auditRoomOf: its job, its look-back, the grades beside it and the one this end queues). A run that
|
|
42
|
+
* could never be audited (no learning start, or not auditableLaunch) keeps `step` as it is. */
|
|
43
|
+
export declare function withAudit(step: EndOfRunTurn | undefined, deps: AuditDeps & {
|
|
44
|
+
readonly launch: RunLaunch;
|
|
45
|
+
readonly redact?: (text: string) => string;
|
|
46
|
+
}): EndOfRunTurn | undefined;
|
|
47
|
+
/** Starts the shadow of run `runId`, at its end, when the learned workflow `serve` served it first and its id is drawn:
|
|
48
|
+
* never for a replay or a shadow, a run that does not learn, one not auditable (auditableLaunch: a trigger started it,
|
|
49
|
+
* or it was handed files), nor a run of an agent that can call a tool that writes (auditWriterOf). A capped run's shadow
|
|
50
|
+
* is capped at what its cap leaves (`room`, read now: the served run spent all it will under it), so the two never
|
|
51
|
+
* spend past the served run's cap; with less than a run's smallest cap left (or a spend not known), no shadow is started
|
|
52
|
+
* and its row says `skipped: "no allowance"`. Its started line is appended first: a shadow is created only once the
|
|
53
|
+
* ledger names it (settlement finds it there, never in a window of runs), and one whose line could not be written is
|
|
54
|
+
* never created. Idempotent: one line and one shadow per run. */
|
|
55
|
+
export declare function startAudit(deps: AuditDeps & {
|
|
56
|
+
readonly runId: string;
|
|
57
|
+
readonly launch: RunLaunch;
|
|
58
|
+
readonly room?: () => Promise<number | null>;
|
|
59
|
+
}, serve: Pick<WorkflowFirst, "name" | "digest" | "replay"> | undefined): Promise<void>;
|
|
60
|
+
/** Writes the row of each open audit (a started line with no row yet) whose two runs, read by id, ended, the batch
|
|
61
|
+
* oldest served run first (the ledger's tail is its newest); a run that is gone (its shadow never created, say) ends it
|
|
62
|
+
* with no verdict. Then applies the hold rule over the ledger as it is now, rows added or not: the hold is a function of
|
|
63
|
+
* the ledger, so one a crash or a failed write lost after the rows were committed is made at the next claim. */
|
|
64
|
+
export declare function settleAudits(deps: AuditDeps): Promise<void>;
|
|
65
|
+
/** The row an owner's grade of served run `run` writes (source grade, agreed = the grade, counted for the digest's
|
|
66
|
+
* promotion now), then the hold rule: only for a run the workflow answered alone (its answer is the workflow's).
|
|
67
|
+
* Nothing else: no round, no compile by itself. */
|
|
68
|
+
export declare function gradeRow(deps: AuditDeps, run: RunRow, correct: boolean): Promise<void>;
|