@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
|
@@ -48,7 +48,6 @@ import { sideEffect } from "./side-effects.js";
|
|
|
48
48
|
import { McpClaimRefused } from "./mcp-claim.js";
|
|
49
49
|
import { CODEMODE, defersCatalog, isCatalogWire, TOOLS_CALL, TOOLS_SEARCH } from "@parcha/agentrun-kernel";
|
|
50
50
|
import { metaTools } from "./meta-tools.js";
|
|
51
|
-
import { builtinHarness } from "../harness-table.js";
|
|
52
51
|
import { Fenced } from "../store/index.js";
|
|
53
52
|
import { answerAsServed } from "../answer-json.js";
|
|
54
53
|
import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
|
|
@@ -211,13 +210,16 @@ function sideTurnsOf(records) {
|
|
|
211
210
|
}
|
|
212
211
|
return side;
|
|
213
212
|
}
|
|
214
|
-
/** What the request that just answered cost, from the session's records, and the bookings that answer gives (`turns`)
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
|
|
213
|
+
/** What the request that just answered cost, from the session's records, and the bookings that answer gives (`turns`),
|
|
214
|
+
* among the runner.turn records no answer was given yet (`given`). The answer reads its own conversation's (`own`: the
|
|
215
|
+
* turns its conversation asked; absent, every turn): a booking of a conversation asking beside it (a subagent's child,
|
|
216
|
+
* answering at about the same time) is left for that conversation's answer, neither read nor given. A side request's
|
|
217
|
+
* booking (sideTurnsOf) is given and never read: it is no answer's, and it stays on the run's ledger and cap. The answer
|
|
218
|
+
* reads its conversation's requests booked since the answer before it, their booked figures summed (a conversation asks
|
|
219
|
+
* one at a time, so that is its own; were a retry ever booked without an answer of its own, it would be summed in), null
|
|
220
|
+
* when any is unknown; undefined when none is booked. Each booking is given once, so one unknown figure stays that
|
|
221
|
+
* answer's, never every later answer's. */
|
|
222
|
+
export function bookingOfAnswer(records, given, own = () => true) {
|
|
221
223
|
const side = sideTurnsOf(records);
|
|
222
224
|
const turns = [];
|
|
223
225
|
let usd;
|
|
@@ -227,9 +229,13 @@ export function bookingOfAnswer(records, given) {
|
|
|
227
229
|
const turn = record.data;
|
|
228
230
|
if (typeof turn.turn !== "number" || given.has(turn.turn))
|
|
229
231
|
continue;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
if (side.has(turn.turn)) {
|
|
233
|
+
turns.push(turn.turn);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (!own(turn.turn))
|
|
232
237
|
continue;
|
|
238
|
+
turns.push(turn.turn);
|
|
233
239
|
// By the kernel's one rule (turnCostOf): an answer with no price of its own is unknown, never the hold it was booked at
|
|
234
240
|
// for the cap; one billed to a person's plan is $0 to the run.
|
|
235
241
|
const figure = turn.usd === undefined && turn.bookedUsd === undefined ? undefined : turnCostOf(turn).usd;
|
|
@@ -268,8 +274,11 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
|
|
|
268
274
|
// is never ended interrupted; it waits for its answer, which ends it (run once, refused, or withdrawn).
|
|
269
275
|
const parked = new Set();
|
|
270
276
|
const sent = new Set();
|
|
271
|
-
// A call of a tool that only nests calls (its start marked `nests`): never ended interrupted, as it
|
|
277
|
+
// A call of a tool that only nests calls (its start marked `nests`): never ended interrupted at a record's open, as it
|
|
278
|
+
// runs again whole; only the run's end ends it (openCalls).
|
|
272
279
|
const nesting = new Set();
|
|
280
|
+
// The calls still open: no end, and not parked unsent. None for a harness that says each call's end (endsItsCalls).
|
|
281
|
+
const openNow = () => (endsItsCalls ? [] : [...started].filter(([callId, ended]) => !ended && !(parked.has(callId) && !sent.has(callId))).map(([callId]) => callId));
|
|
273
282
|
// The call of the harness's own each call runs inside (nestedIn), named on the call's start.
|
|
274
283
|
const parents = new Map();
|
|
275
284
|
const parentOf = (callId) => {
|
|
@@ -322,8 +331,8 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
|
|
|
322
331
|
if ((entry.kind === KINDS.message || entry.kind === KINDS.input) && typeof data.requestId === "string")
|
|
323
332
|
followUps.add(data.requestId);
|
|
324
333
|
}
|
|
325
|
-
for (const
|
|
326
|
-
if (
|
|
334
|
+
for (const callId of openNow()) {
|
|
335
|
+
if (nesting.has(callId))
|
|
327
336
|
continue;
|
|
328
337
|
await append(KINDS.callEnd, { callId, status: "interrupted" });
|
|
329
338
|
started.set(callId, true);
|
|
@@ -486,7 +495,7 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
|
|
|
486
495
|
},
|
|
487
496
|
nestedIn: (callId, parent) => void parents.set(callId, parent),
|
|
488
497
|
unsentParked: () => [...parked].filter((callId) => !sent.has(callId) && started.get(callId) === false),
|
|
489
|
-
|
|
498
|
+
openCalls: () => openNow().sort((a, b) => Number(nesting.has(a)) - Number(nesting.has(b))),
|
|
490
499
|
noteEnd(callId, status, output) {
|
|
491
500
|
started.set(callId, true);
|
|
492
501
|
ends.set(callId, { status, ...(output === undefined ? {} : { output }) });
|
|
@@ -2040,7 +2049,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2040
2049
|
}
|
|
2041
2050
|
},
|
|
2042
2051
|
});
|
|
2043
|
-
const facts =
|
|
2052
|
+
const { facts } = spec;
|
|
2044
2053
|
// tools_search, tools_call and codemode over the session's tools (meta-tools.ts), on every harness (codemode on
|
|
2045
2054
|
// each but one that runs scripts of its own): what they call is called nested, each call asked about and recorded
|
|
2046
2055
|
// as its own tool's. A search finds a tool whose setting is not deny; an MCP tool's setting is its catalog name's.
|
|
@@ -2087,6 +2096,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2087
2096
|
const port = booking.models;
|
|
2088
2097
|
unbooked = 0;
|
|
2089
2098
|
bookingsWriting = 0;
|
|
2099
|
+
// The conversation each request of this claim was asked in, by its turn, where its client named one.
|
|
2100
|
+
const askedIn = new Map();
|
|
2090
2101
|
const counted = {
|
|
2091
2102
|
beforeRequest: async (request) => {
|
|
2092
2103
|
// The CLI's next request of its main model after its question to the person: never admitted, it asks for the
|
|
@@ -2118,6 +2129,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2118
2129
|
carried = undefined;
|
|
2119
2130
|
}
|
|
2120
2131
|
unbooked += 1;
|
|
2132
|
+
// The conversation that asked, as its client named it (pi's, one of several asking at once): whose answer reads
|
|
2133
|
+
// this request's booking (bookedCost).
|
|
2134
|
+
const conversation = request.conversation;
|
|
2135
|
+
if (ticket && conversation !== undefined)
|
|
2136
|
+
askedIn.set(ticket.turn, conversation);
|
|
2121
2137
|
// The harness's own side call (a title request on its smaller model): never a typical cost of its main requests.
|
|
2122
2138
|
if (ticket && request.side)
|
|
2123
2139
|
notOwn.add(ticket.turn);
|
|
@@ -2172,14 +2188,20 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2172
2188
|
};
|
|
2173
2189
|
// What the request that just answered cost, once the session's requests are booked (bookingOfAnswer): its own
|
|
2174
2190
|
// booking's figure, null when unknown; a side request's is given and never read. A refused request's record is its $0.
|
|
2191
|
+
// Its own is its conversation's (`conversation`, as the answer's harness names it and as its requests named it:
|
|
2192
|
+
// askedIn): with several conversations asking at once (pi's subagents), each answer reads the bookings of its
|
|
2193
|
+
// own conversation's requests, never one a conversation beside it is still to read. An answer that names no
|
|
2194
|
+
// conversation reads those of the requests that named none.
|
|
2175
2195
|
// The bookings already given to an answer: every one the session holds when it opens (an earlier claim's), then each
|
|
2176
2196
|
// this claim gives.
|
|
2177
2197
|
const given = new Set(turnsOf(await writer.read().catch(() => [])));
|
|
2178
|
-
const bookedCost = async () => {
|
|
2198
|
+
const bookedCost = async (conversation) => {
|
|
2179
2199
|
await bookingsSettled();
|
|
2180
|
-
const booking = bookingOfAnswer(await writer.read().catch(() => []), given);
|
|
2181
|
-
for (const turn of booking.turns)
|
|
2200
|
+
const booking = bookingOfAnswer(await writer.read().catch(() => []), given, (turn) => askedIn.get(turn) === conversation);
|
|
2201
|
+
for (const turn of booking.turns) {
|
|
2182
2202
|
given.add(turn);
|
|
2203
|
+
askedIn.delete(turn);
|
|
2204
|
+
}
|
|
2183
2205
|
return booking.usd;
|
|
2184
2206
|
};
|
|
2185
2207
|
// The gate a CLI's tool bridge asks before anything of a call: a call it refuses never reaches its host tool, so its
|
|
@@ -2264,7 +2286,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2264
2286
|
// each call it makes named under it, so its rows read as a codemode script's do on every other harness. Its start is
|
|
2265
2287
|
// marked `nests`, so a crash leaves it open: its harness ends it (ownCalls.ended) from its CLI's own answer to it after
|
|
2266
2288
|
// the resume, which comes after the rows of the calls it made, never as an interrupted end ahead of them. One no answer
|
|
2267
|
-
// of its CLI ends (a stop while it waits, a crash no resume follows) the run's end closes, interrupted (
|
|
2289
|
+
// of its CLI ends (a stop while it waits, a crash no resume follows) the run's end closes, interrupted (openCalls).
|
|
2268
2290
|
const ownCalls = record
|
|
2269
2291
|
? {
|
|
2270
2292
|
opened: (callId, name, input) => ownWrite(record.start(callId, name, input, false, true).catch(unlessSealed)),
|
|
@@ -3530,8 +3552,19 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3530
3552
|
throw new Error("the run's spec names no agent, so its end-of-run step cannot be asked");
|
|
3531
3553
|
// Every request from here is learning's, between the step's asks too, until the claim ends (reflecting).
|
|
3532
3554
|
reflecting = true;
|
|
3555
|
+
// The step's signal, as its contract says (loop-contract.ts EndOfRunTurn): aborted by what cuts askEndOfRun's turn, a
|
|
3556
|
+
// person's stop or cancel (stopAbort), a lost claim or a shutdown (deps.signal) and the session closing, so a request
|
|
3557
|
+
// the step sends of its own (a replay's grader, compare-end.ts) is cut with the run, never waited on.
|
|
3558
|
+
const closed = new AbortController();
|
|
3559
|
+
void harness?.closed.then(() => closed.abort(new Error("the Session closed")), () => closed.abort(new Error("the Session closed")));
|
|
3560
|
+
const signal = AbortSignal.any([deps.signal, stopAbort.signal, closed.signal]);
|
|
3533
3561
|
try {
|
|
3534
|
-
const rows = await step({ runId: claim.runId, agentId: spec.agentId, claim, outcome, signal
|
|
3562
|
+
const rows = await step({ runId: claim.runId, agentId: spec.agentId, claim, outcome, signal, ask: (prompt, opts) => askEndOfRun(claim, over, prompt, opts.deadlineMs, opts.again === true, opts.round ?? 1, opts.keep, opts.step), keptOf: await keptOf(claim) });
|
|
3563
|
+
// A replay's or a shadow's grader verdict (runner/compare-end.ts), on its root before its end: its metrics carry it
|
|
3564
|
+
// (workflow-first.ts pathMetrics), where the check and the audit read it.
|
|
3565
|
+
const on = harness;
|
|
3566
|
+
if (rows?.compared && !cut() && on)
|
|
3567
|
+
await on.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: KINDS.compared, data: rows.compared }), context);
|
|
3535
3568
|
return cut() ?? { kind: "rows", also: rows?.also ?? [] };
|
|
3536
3569
|
}
|
|
3537
3570
|
catch (error) {
|
|
@@ -3906,13 +3939,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3906
3939
|
const ends = cliRecord ?? (await openCliRecord(on, theGate.journal, context, now, undefined, true));
|
|
3907
3940
|
const recordEnds = ends.unsentParked();
|
|
3908
3941
|
const notRun = data.state === "stopped" ? STOPPED_WHILE_WAITING : ENDED_WHILE_WAITING;
|
|
3909
|
-
// A
|
|
3910
|
-
//
|
|
3911
|
-
//
|
|
3942
|
+
// A CLI's call still open when the run ends: nothing will end it now (a stop that cut it while it ran, a stop while its
|
|
3943
|
+
// call waited, a crash whose next drive never resumed its CLI's thread), so it ends with the run, interrupted, in the
|
|
3944
|
+
// end's commit: nothing of the stopped turn lands after the end. One that only nests calls (a harness's own: Codex's
|
|
3945
|
+
// `exec`) ends after the rows of its calls (their withdrawals above it in this commit); its own end on its way is
|
|
3912
3946
|
// written first. Marked `withRun`: a park or a stop failed nothing, so its row reads interrupted, never failed.
|
|
3913
3947
|
while (ownWrites.size > 0)
|
|
3914
3948
|
await Promise.allSettled([...ownWrites]);
|
|
3915
|
-
const cutOpen = ends.
|
|
3949
|
+
const cutOpen = ends.openCalls();
|
|
3916
3950
|
const ended = theGate.expect(writesEntry(KINDS.end), { run, ...(also.length ? { also } : {}), ...(take.length ? { take } : {}) });
|
|
3917
3951
|
// A seal while the end is committed fails it before it is awaited: handled here, read by the await below.
|
|
3918
3952
|
ended.catch(() => undefined);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
3
|
-
import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
3
|
+
import type { AdapterFacts, HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
5
5
|
import type { installForClaim, installSettled } from "../harness-install.js";
|
|
6
6
|
import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
|
|
@@ -15,9 +15,11 @@ import type { WebFake } from "../web-fake.js";
|
|
|
15
15
|
import { type HostToolCtx } from "../host-tools.js";
|
|
16
16
|
import { type LearnedWorkflow } from "../learning.js";
|
|
17
17
|
import { type ToolResults } from "../workspace/run-tools.js";
|
|
18
|
+
import { type ClaimModelKey } from "./claim-secrets.js";
|
|
18
19
|
import { type ClaimMcp } from "./mcp-run.js";
|
|
19
20
|
import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
|
|
20
21
|
import { type RunnerHarness } from "./adapters/index.js";
|
|
22
|
+
import { type SubagentTier } from "./subagent.js";
|
|
21
23
|
import { type Claim, type Journal } from "./loop-contract.js";
|
|
22
24
|
import type { ReplayCalls } from "../learn/replay-calls.js";
|
|
23
25
|
import type { ModelRoute } from "./model-route.js";
|
|
@@ -172,6 +174,16 @@ export declare function capModelOf(route: ModelRoute): CapModel;
|
|
|
172
174
|
/** Particle requests are never automatically replayed after an uncertain failure. Retry is a harness-wide setting,
|
|
173
175
|
* so a claim with any Particle route disables it for all its conversations, including subagents on other tiers. */
|
|
174
176
|
export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>): Pick<AdapterRunSpec, "retry">;
|
|
177
|
+
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
|
|
178
|
+
* modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
|
|
179
|
+
* provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
|
|
180
|
+
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone. A run with its
|
|
181
|
+
* own model key carries that key, and no saved key is read. Undefined when there is no fast model, the revision names
|
|
182
|
+
* agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
183
|
+
export declare function graderRouteOf(body: {
|
|
184
|
+
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
185
|
+
readonly learning?: unknown;
|
|
186
|
+
}, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[]): Promise<ModelRoute | undefined>;
|
|
175
187
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
176
188
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
177
189
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -216,9 +228,10 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
|
|
|
216
228
|
harness?: string;
|
|
217
229
|
approvals?: Approvals;
|
|
218
230
|
};
|
|
219
|
-
}, root: RunFiles, shell
|
|
231
|
+
}, root: RunFiles, shell: ShellPlace | undefined, options: {
|
|
220
232
|
readonly effectOf?: (name: string) => ToolEffect | undefined;
|
|
221
233
|
readonly argumentsOf?: ArgumentsOf;
|
|
234
|
+
readonly facts: AdapterFacts | undefined;
|
|
222
235
|
}): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
223
236
|
readonly permissions: RunPermissions;
|
|
224
237
|
readonly learn: (flows: readonly LearnedWorkflow[]) => void;
|
|
@@ -16,6 +16,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
16
16
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
17
17
|
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
18
|
import { inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
19
|
+
import { factsOf } from "../harness-table.js";
|
|
19
20
|
import { decisionProvidersIn } from "../decisions.js";
|
|
20
21
|
import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
|
|
21
22
|
import { liveForRun, runnerLiveOf } from "../live-reach.js";
|
|
@@ -50,6 +51,8 @@ import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
|
50
51
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
51
52
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
52
53
|
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
54
|
+
import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
|
|
55
|
+
import { agreeOnOf } from "../learning-setting.js";
|
|
53
56
|
import { catalogSessionNames, mcpWhereHeld } from "./mcp-run.js";
|
|
54
57
|
import { held as runnerSeam, heldOrThrow, heldSignInReads } from "./held.js";
|
|
55
58
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
@@ -58,7 +61,7 @@ import { DEFAULT_HARNESS } from "../harness.js";
|
|
|
58
61
|
import { agentEntriesOf } from "./loop.js";
|
|
59
62
|
import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
|
|
60
63
|
import { ClaimRefused } from "./loop-contract.js";
|
|
61
|
-
import { bookedSpend, cliRunMetrics, endCostOf, runCostOf, runMetrics } from "./metrics.js";
|
|
64
|
+
import { bookedSpend, cliRunMetrics, costBasisOf, endCostOf, runCostOf, runMetrics } from "./metrics.js";
|
|
62
65
|
import { journalEntries } from "./journal-reader.js";
|
|
63
66
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
64
67
|
import { replayCallsOver } from "./promotion.js";
|
|
@@ -123,6 +126,29 @@ export function modelRetryOf(routes) {
|
|
|
123
126
|
const SUBAGENT_ROUTE = "subagent-";
|
|
124
127
|
const subagentRoute = (tier) => `${SUBAGENT_ROUTE}${tier}`;
|
|
125
128
|
const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
|
|
129
|
+
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
|
|
130
|
+
* modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
|
|
131
|
+
* provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
|
|
132
|
+
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone. A run with its
|
|
133
|
+
* own model key carries that key, and no saved key is read. Undefined when there is no fast model, the revision names
|
|
134
|
+
* agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
135
|
+
export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut]) {
|
|
136
|
+
if (agreeOnOf(body.learning)?.length)
|
|
137
|
+
return undefined;
|
|
138
|
+
const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
|
|
139
|
+
for (const redact of new Set(holds))
|
|
140
|
+
holdClaimed(redact, savedKeys);
|
|
141
|
+
const env = claimModelEnv(deps.env, { ...savedKeys, ...claimed }, runKey);
|
|
142
|
+
if (body.modelTiers?.fast === undefined && tierModelOf(env, "fast") === undefined)
|
|
143
|
+
return undefined;
|
|
144
|
+
try {
|
|
145
|
+
return await deps.routeOf(body.modelTiers?.fast, env, "fast", PI_WIRES, undefined, cut);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
log(`learning: no grader route (${error instanceof Error ? error.message : String(error)}): the answers are compared whole`);
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
126
152
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
127
153
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
128
154
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -130,7 +156,7 @@ const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
|
|
|
130
156
|
export function modelAskOf(pinned, ref) {
|
|
131
157
|
return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
|
|
132
158
|
}
|
|
133
|
-
export async function adapterRunGate(store, claim, revision, root, shell, options
|
|
159
|
+
export async function adapterRunGate(store, claim, revision, root, shell, options) {
|
|
134
160
|
let current = await storeSettings(store);
|
|
135
161
|
const approvers = await readApprovers(store.settings);
|
|
136
162
|
// A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
|
|
@@ -138,7 +164,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
|
|
|
138
164
|
// Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
|
|
139
165
|
// default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
|
|
140
166
|
// An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
|
|
141
|
-
const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}) };
|
|
167
|
+
const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}), facts: options.facts };
|
|
142
168
|
const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
|
|
143
169
|
// The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
|
|
144
170
|
let learned = [];
|
|
@@ -448,8 +474,10 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
448
474
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
449
475
|
// The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
|
|
450
476
|
// the same path), for its path checks; it reads nothing in it.
|
|
451
|
-
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
452
|
-
|
|
477
|
+
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's facts
|
|
478
|
+
// are its entry's on the owner's table (factsOf): none for pi, nor for a module's harness on a runner of its own.
|
|
479
|
+
const facts = factsOf(deps.env, revision.body.harness);
|
|
480
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts });
|
|
453
481
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
454
482
|
// uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
|
|
455
483
|
// launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
|
|
@@ -536,6 +564,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
536
564
|
holdClaimed(cut, learnedKeys);
|
|
537
565
|
Object.assign(toolEnv, learnedKeys);
|
|
538
566
|
}
|
|
567
|
+
// A replay run's or a shadow's grader (runner/compare-end.ts), on a route of its own beside the session's, on the
|
|
568
|
+
// session's booking under the run's one cap. None: the pair is compared whole, in words saying so.
|
|
569
|
+
const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps) : undefined;
|
|
570
|
+
if (graderRoute)
|
|
571
|
+
tierRoutes.set(GRADER, graderRoute);
|
|
539
572
|
// The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
|
|
540
573
|
// Harness is open before the session, and at the run's end (the browser tool's reconcile and release hang off these). The
|
|
541
574
|
// adapter loop runs them from the spec's `lifecycle` (adapter-loop.ts hostLifecycle).
|
|
@@ -554,7 +587,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
554
587
|
const handTools = tools.hostTools(withKindTools(granted, tools), results);
|
|
555
588
|
// The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
|
|
556
589
|
// words, pass the run's one redactor before the harness, the model or the record has them.
|
|
557
|
-
const tiers = new Map([...[...tierRoutes].filter(([tier]) => !isSubagentRoute(tier)).map(([tier, { model }]) => [tier, { model }]), ...[...tierUnreachable].map(([tier, why]) => [tier, { why }])]);
|
|
590
|
+
const tiers = new Map([...[...tierRoutes].filter(([tier]) => !isSubagentRoute(tier) && tier !== GRADER).map(([tier, { model }]) => [tier, { model }]), ...[...tierUnreachable].map(([tier, why]) => [tier, { why }])]);
|
|
558
591
|
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate).
|
|
559
592
|
gate.learn(workflows);
|
|
560
593
|
// The run's monid endpoints (monid-run.ts), one host tool each from its revision's pin, on the claim's keys and beside
|
|
@@ -624,10 +657,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
624
657
|
// (adapter-loop.ts stepOf). Its learning folder is where the run's place keeps it — Mode 1 the agent's folder under the
|
|
625
658
|
// data directory, Mode 2 the agent's folder on THIS claim's Archil disk (the draft is checked against the seed on the disk, never this machine's
|
|
626
659
|
// local path) — so the end-of-run step reads the run's own Workspace, the one the run worked in.
|
|
627
|
-
// A replay run or an audit's shadow run
|
|
660
|
+
// 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
|
|
661
|
+
// from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
|
|
628
662
|
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
629
663
|
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
630
|
-
const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
|
|
664
|
+
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, {
|
|
631
665
|
store: deps.store,
|
|
632
666
|
data: deps.data,
|
|
633
667
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -646,6 +680,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
646
680
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
647
681
|
return {
|
|
648
682
|
adapter,
|
|
683
|
+
facts,
|
|
649
684
|
// Who keeps the run's visible record: its runner says (none: the adapter, as pi keeps its own).
|
|
650
685
|
...(runner.record ? { record: runner.record } : {}),
|
|
651
686
|
session,
|
|
@@ -704,12 +739,15 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
704
739
|
// metrics are its booking's, as a CLI harness's run reads them: the workflow's nodes and the agent's own after a handback.
|
|
705
740
|
// An MCP tool called by a hashed wire name is counted under its catalog name, as its timeline names it.
|
|
706
741
|
const catalog = await hashedMcpOf(deps.store, claim.runId);
|
|
742
|
+
// Its model requests as every session of its journal booked them: how they were priced (costBasis, which the sums
|
|
743
|
+
// over runs read), and, for a run its learned workflow served, its tokens.
|
|
744
|
+
const booked = bookedSpend((await journalEntries(deps.journal(claim), context)), "model");
|
|
707
745
|
const { metrics } = servedOf(entries)
|
|
708
|
-
? { metrics: cliRunMetrics(piShaped(entries),
|
|
746
|
+
? { metrics: cliRunMetrics(piShaped(entries), booked, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}), model: launch.model ? `${launch.model.provider}/${launch.model.modelId}` : route.model, catalog }) }
|
|
709
747
|
: runMetrics(entries, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}), catalog });
|
|
710
748
|
// Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
|
|
711
749
|
// cost an earlier end stored).
|
|
712
|
-
return { metrics: { ...metrics, ...path } };
|
|
750
|
+
return { metrics: { ...metrics, ...path, costBasis: costBasisOf(booked) } };
|
|
713
751
|
},
|
|
714
752
|
// A run started with hold: true holds its computer for its owner (computer-held.ts): the loop waits for their start
|
|
715
753
|
// and release, and runs their calls on it.
|
|
@@ -34,6 +34,8 @@ export interface RunnerHarness {
|
|
|
34
34
|
/** Every harness the runner runs, by name. */
|
|
35
35
|
export declare const RUNNER_HARNESSES: Readonly<Record<string, RunnerHarness>>;
|
|
36
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)
|
|
38
|
-
*
|
|
37
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
|
|
38
|
+
* other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
|
|
39
|
+
* run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
|
|
40
|
+
* the run's environment (this process's when not given). */
|
|
39
41
|
export declare function resolveHarness(harness: string, env?: NodeJS.ProcessEnv): RunnerHarness | undefined;
|
|
@@ -1,9 +1,7 @@
|
|
|
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";
|
|
5
|
-
import { acpPackage } from "../../acp-package.js";
|
|
6
|
-
import { GOOSE_ID } from "../../harness-goose.js";
|
|
4
|
+
import { harnessOf, ON_TABLE } from "../../harness-table.js";
|
|
7
5
|
import { piAdapter } from "./pi.js";
|
|
8
6
|
const CLAUDE_PACKAGE = "@parcha/agentrun-harness-claude";
|
|
9
7
|
const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
|
|
@@ -75,33 +73,15 @@ export const RUNNER_HARNESSES = {
|
|
|
75
73
|
});
|
|
76
74
|
},
|
|
77
75
|
},
|
|
78
|
-
// Goose, where its package is beside serve (acp-package.ts): on the binary `extra.binary` names, which its owner
|
|
79
|
-
// installed (harness-goose.ts); a run on serve's table builds its adapter from its entry (adapters.ts gooseOf).
|
|
80
|
-
[GOOSE_ID]: {
|
|
81
|
-
record: "loop",
|
|
82
|
-
adapter: async (launch, extra = {}) => {
|
|
83
|
-
const acp = acpPackage();
|
|
84
|
-
if (!acp)
|
|
85
|
-
throw new Error("Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
|
|
86
|
-
if (typeof extra.binary !== "string")
|
|
87
|
-
throw new Error("Goose's runner adapter needs the installed binary's path (extra.binary)");
|
|
88
|
-
return acp.gooseAdapter({
|
|
89
|
-
model: launch.model,
|
|
90
|
-
provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}), ...(launch.provider.auth ? { auth: launch.provider.auth } : {}) },
|
|
91
|
-
...(launch.price ? { price: launch.price } : {}),
|
|
92
|
-
...(launch.fetch ? { fetch: launch.fetch } : {}),
|
|
93
|
-
sessionsDir: launch.sessionsDir,
|
|
94
|
-
...extra,
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
76
|
};
|
|
99
77
|
/** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
|
|
100
|
-
* the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner)
|
|
101
|
-
*
|
|
78
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
|
|
79
|
+
* other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
|
|
80
|
+
* run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
|
|
81
|
+
* the run's environment (this process's when not given). */
|
|
102
82
|
export function resolveHarness(harness, env = process.env) {
|
|
103
83
|
const entry = harnessOf(env, harness);
|
|
104
84
|
if (!entry)
|
|
105
85
|
return undefined;
|
|
106
|
-
return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : undefined);
|
|
86
|
+
return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : entry.facts && entry.adapter ? ON_TABLE : undefined);
|
|
107
87
|
}
|
|
@@ -36,8 +36,11 @@ export type PreIntentAnswer = "allow" | {
|
|
|
36
36
|
export type PiSessionIO = SessionIO & {
|
|
37
37
|
gate?: (call: PreIntentCall, context: Context) => Promise<PreIntentAnswer>;
|
|
38
38
|
/** What the request that just answered cost, as the runner's booking wrote it (the session's ledger): its figure, null
|
|
39
|
-
* when unknown, undefined when none was booked. pi's own price for the model is none (the adapter does not know it).
|
|
40
|
-
|
|
39
|
+
* when unknown, undefined when none was booked. pi's own price for the model is none (the adapter does not know it).
|
|
40
|
+
* `conversation`: the answer's conversation, as each of its requests named it to the session's proxy (pi's own id for
|
|
41
|
+
* it: port-models.ts sessionApi), so an answer reads its own conversation's bookings, never those of a conversation
|
|
42
|
+
* asking beside it (a subagent's child). */
|
|
43
|
+
bookedCost?: (conversation?: string) => Promise<number | null | undefined>;
|
|
41
44
|
/** Keeps a tool call's computer calls beside it on the run's root, by the call's id (the loop's, as its host tools'
|
|
42
45
|
* are kept): each run's pi-native tool (code mode's script among them) runs inside recordingCalls with it, so its row
|
|
43
46
|
* carries the calls it made as a host tool's does. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
2
2
|
import { clampThinkingLevel, createModels, getSupportedThinkingLevels } from "@earendil-works/pi-ai/models";
|
|
3
|
-
import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
|
|
3
|
+
import { defineExtension, defineTool, GenerationTask, hook, ProviderDoc, ToolTask } from "@earendil-works/pi-durable";
|
|
4
4
|
import { anthropicPolicy, withWebSearches } from "@parcha/agentrun-harness-claude";
|
|
5
5
|
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
6
|
-
import { NATIVE_SEARCH_USD, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
6
|
+
import { conversationLabel, NATIVE_SEARCH_USD, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
7
7
|
import { INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
9
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
@@ -309,10 +309,13 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
309
309
|
// An answer's cost is the runner's booking of its request, never pi's $0 for a model it has no price for: set on
|
|
310
310
|
// the answer before pi stores it, so the answer, pi.usage and the live timeline carry it; unknown stays unknown.
|
|
311
311
|
hook(GenerationTask, {
|
|
312
|
-
afterResponse: async (message) => {
|
|
312
|
+
afterResponse: async (message, api, hookContext) => {
|
|
313
313
|
if (!io.bookedCost)
|
|
314
314
|
return;
|
|
315
|
-
|
|
315
|
+
// The conversation that asked, by the id pi sends with each of its requests (its pi.provider document's), as
|
|
316
|
+
// the session's client names it to the proxy (port-models.ts sessionApi).
|
|
317
|
+
const asked = await api.snapshot(ProviderDoc, api.conversationId, hookContext);
|
|
318
|
+
const usd = await io.bookedCost(conversationLabel(asked?.sessionId));
|
|
316
319
|
if (usd === undefined)
|
|
317
320
|
return;
|
|
318
321
|
const cost = message.usage?.cost;
|
package/dist/runner/audit.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export type AuditDeps = {
|
|
|
28
28
|
export declare const STOPPED_TWICE = "stopped: the workflow disagreed with the agent twice";
|
|
29
29
|
/** The audit numbers of revision `revisionId`'s definition (each one it leaves out at its default). */
|
|
30
30
|
export declare function auditLoopOfRevision(store: Pick<Store, "agents">, revisionId: string): Promise<AuditLoop>;
|
|
31
|
+
/** The answer paths an audit of a run of revision `revisionId` compares on, as its check does (learning-setting.ts
|
|
32
|
+
* agreeOnOf: its agree_on); undefined, the whole answer. A read that fails throws: settleAudits leaves the row to a
|
|
33
|
+
* later claim, never comparing on the whole answer an agent that named its fields (#3182 review). */
|
|
34
|
+
export declare function agreeOnOfRevision(store: Pick<Store, "agents">, revisionId: string): Promise<readonly string[] | undefined>;
|
|
35
|
+
/** The served answer shadow run `shadowRun` audits: its open line's `turn`'s answer, read from the served run by that row's
|
|
36
|
+
* id (what settleAudits compares the shadow's answer with); null when no open line names it, or it names no turn. */
|
|
37
|
+
export declare function auditedAnswerOf(deps: Pick<AuditDeps, "store" | "context" | "folder">, shadowRun: string): Promise<string | null>;
|
|
31
38
|
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
32
39
|
* started them): what the promotions read counts beside the audit line. */
|
|
33
40
|
export declare function notAuditableOf(store: Pick<Store, "runs">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
package/dist/runner/audit.js
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
// shadow) of an agent every tool of which only reads (learn/audit.ts auditWriterOf, the replay's readOnlyHint rule): a
|
|
13
13
|
// shadow never writes again.
|
|
14
14
|
// settleAudits: each open started line (no result row yet) whose two runs, read by id, ended writes its row (agreed:
|
|
15
|
-
// the audited answer, its `turn`'s, and the shadow's say the same, learn/promote.ts
|
|
16
|
-
// revision's agree_on
|
|
15
|
+
// the audited answer, its `turn`'s, and the shadow's say the same, learn/promote.ts compareAnswers, the check's one
|
|
16
|
+
// comparison: on the served run's revision's agree_on, learning-setting.ts agreeOnOf, else the grader's verdict the
|
|
17
|
+
// shadow kept at its end, runner/compare-end.ts; a follow-up's answer since is never
|
|
17
18
|
// read), oldest served run first; then, rows added or not, the hold rule reads the serving revisions'
|
|
18
19
|
// rows: a hold is a function of the ledger alone.
|
|
19
20
|
// applyHold: at least hold_disagree disagreements in the newest hold_window rows of the digest's current promotion
|
|
@@ -35,7 +36,7 @@ import { isObject } from "../validate.js";
|
|
|
35
36
|
import { auditableLaunch, auditChange, auditEveryOf, auditDrawn, auditsOffWords, auditWriterOf, holdOf, ledgerOf, lineKey, openAudits, rowsOf, shadowRunId } from "../learn/audit.js";
|
|
36
37
|
import { lastRunsOf } from "../learn/compile.js";
|
|
37
38
|
import { readLearning, writeLearning } from "../learn/folder.js";
|
|
38
|
-
import { CHECK_TEXT_MAX, promotionOf, promotionsOf, promotionStartOf, recordPromotion,
|
|
39
|
+
import { CHECK_TEXT_MAX, compareAnswers, comparedOf, promotionOf, promotionsOf, promotionStartOf, recordPromotion, servingOf } from "../learn/promote.js";
|
|
39
40
|
import { excerptShown } from "../learn/secrets.js";
|
|
40
41
|
import { auditRoomOf } from "./learning-end.js";
|
|
41
42
|
import { answerOf, answerRowOf } from "./promotion.js";
|
|
@@ -69,9 +70,15 @@ export async function auditLoopOfRevision(store, revisionId) {
|
|
|
69
70
|
/** The answer paths an audit of a run of revision `revisionId` compares on, as its check does (learning-setting.ts
|
|
70
71
|
* agreeOnOf: its agree_on); undefined, the whole answer. A read that fails throws: settleAudits leaves the row to a
|
|
71
72
|
* later claim, never comparing on the whole answer an agent that named its fields (#3182 review). */
|
|
72
|
-
async function agreeOnOfRevision(store, revisionId) {
|
|
73
|
+
export async function agreeOnOfRevision(store, revisionId) {
|
|
73
74
|
return agreeOnOf((await store.agents.revision(revisionId))?.body?.learning);
|
|
74
75
|
}
|
|
76
|
+
/** The served answer shadow run `shadowRun` audits: its open line's `turn`'s answer, read from the served run by that row's
|
|
77
|
+
* id (what settleAudits compares the shadow's answer with); null when no open line names it, or it names no turn. */
|
|
78
|
+
export async function auditedAnswerOf(deps, shadowRun) {
|
|
79
|
+
const open = openAudits(await readLedger(deps)).find((line) => line.shadow_run === shadowRun);
|
|
80
|
+
return open ? auditedAnswer(deps, open) : null;
|
|
81
|
+
}
|
|
75
82
|
/** The served runs of `workflow` (at `digest` when given) that `keep` keeps too, the newest `n` of them (lastRunsOf: the
|
|
76
83
|
* shadows and the agent's own runs among them never push one out of the read). */
|
|
77
84
|
const servedRuns = (store, agentId, n, workflow, digest, keep = () => true) => lastRunsOf(store, agentId, n, (row) => served(row) && metricsOf(row).workflow === workflow && (digest === undefined || metricsOf(row).workflow_digest === digest) && keep(row));
|
|
@@ -245,8 +252,10 @@ export async function settleAudits(deps) {
|
|
|
245
252
|
return null;
|
|
246
253
|
// The audited answer (the row's turn), never the run's newest: a follow-up since may have answered again.
|
|
247
254
|
const [a, b] = [await auditedAnswer(deps, row), await answerOf(store, row.shadow_run, deps.context)];
|
|
248
|
-
//
|
|
249
|
-
|
|
255
|
+
// The check's one comparison (compareAnswers): on the fields the served run's revision says carry the decision, else
|
|
256
|
+
// equal, else the grader's verdict its shadow kept at its end (runner/compare-end.ts), else the whole answer.
|
|
257
|
+
const verdict = comparedOf(isObject(shadow.metrics) ? shadow.metrics.audit?.compared : undefined);
|
|
258
|
+
return a === null || b === null ? null : compareAnswers(a, b, await agreeOnOfRevision(store, served.revisionId), verdict).same;
|
|
250
259
|
}) : { all: lines, added: [] };
|
|
251
260
|
const written = rowsOf(added);
|
|
252
261
|
if (written.length)
|
|
@@ -14,6 +14,7 @@ import { getSealedKey } from "../server-keys.js";
|
|
|
14
14
|
import { PLAN_PROVIDER, planOf, planReaderOf, withPlan } from "../chatgpt-plan.js";
|
|
15
15
|
import { handsParallel } from "../tool-plane.js";
|
|
16
16
|
import { held, held as runnerSeam } from "./held.js";
|
|
17
|
+
import { savedGatewayIn } from "../model-gateway.js";
|
|
17
18
|
import { noServerKeyWords, runKeyEndedFor, runModelOrigin, withRunModelKey, withRunModelKeyLater } from "../run-model-key.js";
|
|
18
19
|
import { openRunLaunch } from "../store/seal.js";
|
|
19
20
|
import { StoreLaunchMissing } from "../store/store.js";
|
|
@@ -32,8 +33,11 @@ export async function claimSecrets(deps, revision, launch) {
|
|
|
32
33
|
// in its place, and the run would hold a key its model never sends and lack the one it does.
|
|
33
34
|
const scoped = launch.model && !needs.tiers ? { ...needs, model: `${launch.model.provider}/${launch.model.modelId}` } : needs;
|
|
34
35
|
const env = { ...base };
|
|
36
|
+
// The key of a gateway saved in the console (model-gateway.ts) stays on the run environment its model routes read, never
|
|
37
|
+
// on the tools': it is read there by name alone (claimModelEnv), as a run's own model key is.
|
|
38
|
+
const savedGateway = savedGatewayIn(deps.env ?? {});
|
|
35
39
|
for (const name of keysFor(scoped, working))
|
|
36
|
-
if (working[name] !== undefined)
|
|
40
|
+
if (working[name] !== undefined && !(savedGateway && name === GATEWAY_KEY_ENV))
|
|
37
41
|
env[name] = working[name];
|
|
38
42
|
const decision = decisionKeysFor(working, { providers: needs.decisionProviders, parallelWeb: launch.plane ? handsParallel(launch.plane) : false });
|
|
39
43
|
for (const [name, value] of Object.entries(decision))
|