@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36
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 +128 -0
- package/README.md +260 -168
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +13 -41
- package/dist/cap.js +24 -73
- package/dist/cli.js +4 -22
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +48 -7
- package/dist/computers.js +100 -23
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +7 -1
- package/dist/learn/check.js +123 -5
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +33 -0
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +86 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +43 -29
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +7 -0
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +19 -9
- package/dist/learned-workflow.js +62 -34
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +8 -3
- package/dist/learning-routes.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -6
- package/dist/learning.js +4 -2
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +5 -5
- package/dist/model.js +6 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +204 -47
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +1 -0
- package/dist/propose.js +25 -10
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +14 -1
- package/dist/run-launch.js +7 -2
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +5 -2
- package/dist/run-view.js +4 -3
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +16 -1
- package/dist/runner/adapter-loop.js +131 -30
- package/dist/runner/adapter-run-spec.d.ts +25 -4
- package/dist/runner/adapter-run-spec.js +103 -24
- package/dist/runner/adapters/pi.d.ts +11 -3
- package/dist/runner/adapters/pi.js +35 -12
- package/dist/runner/beside.js +6 -2
- package/dist/runner/cli-run-spec.d.ts +7 -0
- package/dist/runner/cli-run-spec.js +92 -38
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +8 -5
- package/dist/runner/github-app.js +2 -2
- package/dist/runner/harness-loops.js +1 -1
- package/dist/runner/journal-kinds.d.ts +15 -5
- package/dist/runner/journal-kinds.js +6 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +26 -5
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +73 -1
- package/dist/runner/learning-loop.js +203 -18
- package/dist/runner/learning-seed.d.ts +2 -0
- package/dist/runner/learning-seed.js +1 -1
- package/dist/runner/loop-contract.d.ts +8 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.js +12 -2
- package/dist/runner/mcp-claim.d.ts +4 -0
- package/dist/runner/mcp-claim.js +29 -1
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +0 -7
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +47 -12
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +18 -2
- package/dist/runner/workflow-host.js +23 -3
- package/dist/runner/workflow-loop.d.ts +5 -2
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +26 -14
- package/dist/runner/workflow-spec.js +97 -30
- package/dist/runs-over-store.d.ts +11 -6
- package/dist/runs-over-store.js +111 -24
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server.d.ts +32 -49
- package/dist/server.js +249 -199
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/deadline.js +9 -5
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +45 -12
- package/dist/store-reads/learning.d.ts +15 -1
- package/dist/store-reads/learning.js +68 -10
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.js +45 -19
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +3 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +8 -0
- package/dist/tool-budget.js +7 -1
- package/dist/tool-gate.d.ts +7 -1
- package/dist/tool-gate.js +7 -2
- package/dist/tool-plane.d.ts +33 -19
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +18 -34
- package/dist/tools.js +104 -70
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +30 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/computer-deps.d.ts +16 -8
- package/dist/workspace/computer-deps.js +18 -7
- package/dist/workspace/computer-for-claim.d.ts +42 -6
- package/dist/workspace/computer-for-claim.js +209 -9
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +7 -0
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +1 -0
- package/dist/workspace/resolve-computer.d.ts +42 -11
- package/dist/workspace/resolve-computer.js +65 -13
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +4 -4
- package/dist/workspace/run-tools.js +8 -6
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +10 -15
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
|
|
7
7
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
8
|
+
import { wireName } from "../catalog.js";
|
|
8
9
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
9
10
|
import { Hearing } from "../heard.js";
|
|
10
11
|
import { redactedAnswer } from "../key-refusal.js";
|
|
@@ -13,7 +14,7 @@ import { labelled } from "../reflect-range.js";
|
|
|
13
14
|
import { reflectFrom } from "../runner/end-of-run.js";
|
|
14
15
|
import { journalEntries, journalRecords } from "../runner/journal-reader.js";
|
|
15
16
|
import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
|
|
16
|
-
import { bookedSpend, costIsBooked } from "../runner/metrics.js";
|
|
17
|
+
import { bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
|
|
17
18
|
import { waitingText } from "../tool-gate.js";
|
|
18
19
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
19
20
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
@@ -123,7 +124,7 @@ export function withPaidCosts(entries) {
|
|
|
123
124
|
continue;
|
|
124
125
|
const d = (e.data ?? {});
|
|
125
126
|
if (typeof d.turn === "number" && typeof d.model === "string" && d.model.startsWith("paid:"))
|
|
126
|
-
named.set(d.turn, {
|
|
127
|
+
named.set(d.turn, { ...(typeof d.tool === "string" && d.tool ? { tool: d.tool, own: true } : { tool: d.model.slice("paid:".length) }), ...(typeof d.call === "string" ? { call: d.call } : {}), ...(typeof d.charged_by === "string" && d.charged_by ? { chargedBy: d.charged_by } : {}), ...(typeof d.tag === "string" && d.tag ? { tag: d.tag } : {}) });
|
|
127
128
|
}
|
|
128
129
|
const charges = [];
|
|
129
130
|
for (const e of entries) {
|
|
@@ -140,13 +141,31 @@ export function withPaidCosts(entries) {
|
|
|
140
141
|
}
|
|
141
142
|
if (!charges.length)
|
|
142
143
|
return [...entries];
|
|
144
|
+
// The tool each call ran, by its id, from the model's answers (a CLI run's record shaped as pi's: piShaped).
|
|
145
|
+
const toolOfCall = new Map();
|
|
146
|
+
for (const e of entries) {
|
|
147
|
+
if (e.kind !== "pi.assistant")
|
|
148
|
+
continue;
|
|
149
|
+
for (const message of (e.model ?? [])) {
|
|
150
|
+
for (const part of Array.isArray(message.content) ? message.content : []) {
|
|
151
|
+
const call = part;
|
|
152
|
+
if (call.type === "toolCall" && typeof call.id === "string" && typeof call.name === "string")
|
|
153
|
+
toolOfCall.set(call.id, call.name);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
143
157
|
const out = [...entries];
|
|
144
158
|
for (const charge of charges) {
|
|
145
159
|
// Who charged: the request's own charged_by, which the cap writes as main's charge label names it (parallel, monid, an
|
|
146
160
|
// MCP server, a browser vendor).
|
|
147
161
|
const by = charge.chargedBy;
|
|
148
162
|
const at = charge.call === undefined ? -1 : out.findIndex((e) => e.kind === "pi.tool-result" && String(e.model?.[0]?.toolCallId ?? "") === charge.call);
|
|
149
|
-
|
|
163
|
+
// Named for its call's tool where the request names none of its own: by what was paid for where that is the tool
|
|
164
|
+
// itself (an MCP tool's catalog name, whose wire name the call carries), else by the call's tool (web_fetch, for
|
|
165
|
+
// Parallel's extract). A request that names its tool (a browser step's "browser") keeps it.
|
|
166
|
+
const called = !charge.own && charge.call !== undefined ? toolOfCall.get(charge.call) : undefined;
|
|
167
|
+
const tool = called !== undefined && wireName(charge.tool) !== called ? called : charge.tool;
|
|
168
|
+
const data = { tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
|
|
150
169
|
const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}#${charge.turn}` };
|
|
151
170
|
out.splice(at >= 0 ? at + 1 : out.length, 0, entry);
|
|
152
171
|
}
|
|
@@ -193,7 +212,9 @@ function withLearnedNodes(rows, entries, redact) {
|
|
|
193
212
|
const one = (node ?? {});
|
|
194
213
|
if (typeof one.label !== "string" || typeof one.status !== "string")
|
|
195
214
|
return [];
|
|
196
|
-
|
|
215
|
+
// A model node's model and tier, each through the run's cut as the label is.
|
|
216
|
+
return [{ label: said(one.label), kind: String(one.kind ?? ""), status: one.status, duration_ms: typeof one.duration_ms === "number" ? one.duration_ms : 0,
|
|
217
|
+
...(typeof one.model === "string" ? { model: said(one.model) } : {}), ...(typeof one.tier === "string" ? { tier: said(one.tier) } : {}) }];
|
|
197
218
|
}));
|
|
198
219
|
}
|
|
199
220
|
if (!traces.size)
|
|
@@ -204,20 +225,31 @@ function withLearnedNodes(rows, entries, redact) {
|
|
|
204
225
|
* session of the run but its decisions'): its model requests and its paid tool calls, their sum (unknown while one's cost is, with what is known so far,
|
|
205
226
|
* costsofar/1), in the renderer's words (`Cost` once ended, else `Cost so far`). The renderer's own row is replaced in
|
|
206
227
|
* place; a run that booked a request and rendered none gets one at the end. One that booked none keeps its rows, with no
|
|
207
|
-
* usage row.
|
|
228
|
+
* usage row, unless it is a CLI run whose model worked with none booked (metrics.ts cliModelWorked: its requests went
|
|
229
|
+
* past its model proxy): its usage row says its cost is unknown, its model's work one charge with no price, so its view,
|
|
230
|
+
* live or ended, reads unknown, never $0. */
|
|
208
231
|
function bookedUsage(rows, entries, options) {
|
|
209
232
|
const model = bookedSpend(entries, "model");
|
|
210
233
|
const paid = bookedSpend(entries, "paid");
|
|
211
234
|
const at = rows.findIndex((row) => row.kind === "usage");
|
|
212
235
|
const kept = rows.filter((row) => row.kind !== "usage");
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
236
|
+
const unbooked = !model.requests && isCliRecord(entries) && cliModelWorked(entries);
|
|
237
|
+
if (!model.requests && !paid.requests && !unbooked) {
|
|
238
|
+
// A run whose cap refused its first request (its park at the cap, an agentrun.budget entry) says it sent none, as a
|
|
239
|
+
// pi run's usage line does: never a request it did not make, and never silence about why nothing ran.
|
|
240
|
+
if (!entries.some((entry) => entry.kind === KINDS.budget) || kept.length === 0)
|
|
241
|
+
return kept;
|
|
242
|
+
const last = kept[kept.length - 1];
|
|
243
|
+
return [...kept, { ...last, id: `${last.conversation_id ?? 0}:usage`, kind: "usage", summary: "no model request sent", agent_label: null, text: null, tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null, usage: { usd: 0, requests: 0 } }];
|
|
244
|
+
}
|
|
245
|
+
const usd = unbooked || model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
|
|
246
|
+
const unpriced = model.unpriced + paid.unpriced + (unbooked ? 1 : 0);
|
|
217
247
|
const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
|
|
218
248
|
const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
|
|
219
249
|
const charges = paid.requests ? ` and ${paid.requests} paid tool call${paid.requests === 1 ? "" : "s"}` : "";
|
|
220
|
-
const summary =
|
|
250
|
+
const summary = unbooked
|
|
251
|
+
? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${charges}`
|
|
252
|
+
: `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
|
|
221
253
|
const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
|
|
222
254
|
const last = rows[rows.length - 1];
|
|
223
255
|
const base = at >= 0 ? rows[at] : {
|
|
@@ -264,9 +296,10 @@ export async function wholeAnswers(store, runId, context, rows, options, whole)
|
|
|
264
296
|
const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
|
|
265
297
|
if (!rows.some(cut))
|
|
266
298
|
return rows;
|
|
267
|
-
|
|
299
|
+
// Kept by the store a snapshot was taken of: each snapshot's own store is a new object, and would never hit.
|
|
300
|
+
let kept = answersServed.get(store.origin);
|
|
268
301
|
if (!kept)
|
|
269
|
-
answersServed.set(store, (kept = new Map()));
|
|
302
|
+
answersServed.set(store.origin, (kept = new Map()));
|
|
270
303
|
const keyOf = (row) => `${runId}\0${row.id}\0${whole.key}`;
|
|
271
304
|
let uncut;
|
|
272
305
|
const out = [];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ItemStatus, type Learning, type NoteUsed, type Shown } from "../learning.js";
|
|
2
2
|
import { type RunLaunch } from "../run-launch.js";
|
|
3
3
|
import { type Impact } from "../learning-run.js";
|
|
4
|
+
import { type CostRun, type CostSummary } from "../learning-cost.js";
|
|
4
5
|
import { type Reflect } from "../reflect-range.js";
|
|
5
6
|
import type { NoteRuns } from "../learning.js";
|
|
6
7
|
import type { EntryLike, TimelineEvent } from "../timeline/index.js";
|
|
@@ -51,6 +52,19 @@ export declare function agentLearningOverStore(store: Store, agentId: string): P
|
|
|
51
52
|
impact: Impact;
|
|
52
53
|
notes: NoteRuns;
|
|
53
54
|
}>;
|
|
55
|
+
/** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
|
|
56
|
+
* agentic runs that ended (ended, stopped or failed), oldest first, numbered from 1, with its own cost and what learning
|
|
57
|
+
* added for it (runCostOf over its row's cost and its learning's spend, learningSpendOf), the path it took and the learned workflow it called
|
|
58
|
+
* (journalReadsOf), and the learned revision it started from (its launch's seed); and what the series shows
|
|
59
|
+
* (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left out; a learning
|
|
60
|
+
* run (a run's grade and merge) is no run of the list, and its cost is its run's learning. `limit`: the latest runs
|
|
61
|
+
* shown, each keeping its number; the summary is over every run. */
|
|
62
|
+
export declare function agentCostOverStore(store: Store, agentId: string, limit?: number): Promise<{
|
|
63
|
+
runs: CostRun[];
|
|
64
|
+
summary: CostSummary;
|
|
65
|
+
total_runs: number;
|
|
66
|
+
unknown_cost_runs: number;
|
|
67
|
+
}>;
|
|
54
68
|
/** What a run's claim laid of its learning seed: the learned skills and workflows it was given, by name. */
|
|
55
69
|
type Laid = {
|
|
56
70
|
readonly skills: readonly string[];
|
|
@@ -160,7 +174,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
160
174
|
workflows?: import("../learning.js").LearnedFile[];
|
|
161
175
|
run: string;
|
|
162
176
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
163
|
-
reason: "
|
|
177
|
+
reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
164
178
|
detail: string | null;
|
|
165
179
|
at: string;
|
|
166
180
|
} | null>;
|
|
@@ -11,6 +11,8 @@ import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
|
|
|
11
11
|
import { runLearningBody } from "../learning-routes.js";
|
|
12
12
|
import { learningStartOf, readLaunchBody } from "../run-launch.js";
|
|
13
13
|
import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
|
|
14
|
+
import { costSummary, runCostOf } from "../learning-cost.js";
|
|
15
|
+
import { runPathOf, workflowNameOf } from "../runner/learning-end.js";
|
|
14
16
|
import { reflects } from "../reflect-range.js";
|
|
15
17
|
import { notesOf } from "../usage.js";
|
|
16
18
|
import { runEntries, runReflect, runTimeline } from "./journal.js";
|
|
@@ -59,9 +61,12 @@ async function endOfKept(store, kept, row) {
|
|
|
59
61
|
const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
|
|
60
62
|
const cost = spent ? { cost_usd: { grade: spent.usd }, tokens: { grade: spent.tokens ?? null } } : {};
|
|
61
63
|
if (merged && graded) {
|
|
62
|
-
|
|
64
|
+
// Each item as the merge settled it: its record's verdict (a note it left out is no longer kept, and says why). A merge
|
|
65
|
+
// recorded with none (before the record kept it) reads no item decisions.
|
|
66
|
+
const verdict = merged.verdict;
|
|
67
|
+
const what = verdict ? learnedOf(keptOf(row.proposal, verdict), verdict) : { learned: [], pending: [], skills: [], workflows: [] };
|
|
63
68
|
return {
|
|
64
|
-
state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, verdict:
|
|
69
|
+
state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, ...(verdict ? { verdict } : {}), graded: { ...graded.graded }, ...cost, merged: merged.commit,
|
|
65
70
|
learned: what.learned, ...(what.pending.length ? { pending: what.pending } : {}), ...(what.skills.length ? { skills: what.skills } : {}), ...(what.workflows.length ? { workflows: what.workflows } : {}),
|
|
66
71
|
};
|
|
67
72
|
}
|
|
@@ -145,14 +150,7 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
145
150
|
const final = FINAL_STATES.includes(run.state);
|
|
146
151
|
const started = await learningStartOfRun(store, run.id);
|
|
147
152
|
const end = await runLearningEnd(store, run.id);
|
|
148
|
-
|
|
149
|
-
// offered): read once for a settled run and kept by its epoch (settledJournalReads), else read now.
|
|
150
|
-
const offered = !!(started?.skills?.length || started?.workflows?.length);
|
|
151
|
-
const journal = async () => ({
|
|
152
|
-
read: final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: true })) : [],
|
|
153
|
-
laid: offered ? laidOf(await runEntries(store, run.id, BACKGROUND_CONTEXT)) : undefined,
|
|
154
|
-
});
|
|
155
|
-
const { read, laid } = final ? await settledJournalReads(store, run.id, run.epoch, journal) : await journal();
|
|
153
|
+
const { read, laid } = await journalReadsOf(store, run, started);
|
|
156
154
|
if (started || end)
|
|
157
155
|
files.push(notesOf({ given: started?.given ?? [], read }));
|
|
158
156
|
// The row learningImpact reads (the file path's RunRow): an ended run is a completed one.
|
|
@@ -167,6 +165,66 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
167
165
|
}
|
|
168
166
|
return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
|
|
169
167
|
}
|
|
168
|
+
/** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
|
|
169
|
+
* agentic runs that ended (ended, stopped or failed), oldest first, numbered from 1, with its own cost and what learning
|
|
170
|
+
* added for it (runCostOf over its row's cost and its learning's spend, learningSpendOf), the path it took and the learned workflow it called
|
|
171
|
+
* (journalReadsOf), and the learned revision it started from (its launch's seed); and what the series shows
|
|
172
|
+
* (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left out; a learning
|
|
173
|
+
* run (a run's grade and merge) is no run of the list, and its cost is its run's learning. `limit`: the latest runs
|
|
174
|
+
* shown, each keeping its number; the summary is over every run. */
|
|
175
|
+
export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
176
|
+
const kinds = new Map();
|
|
177
|
+
const ended = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
|
|
178
|
+
const runs = [];
|
|
179
|
+
for (const run of ended) {
|
|
180
|
+
if (!kinds.has(run.revisionId))
|
|
181
|
+
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
|
|
182
|
+
if (kinds.get(run.revisionId) === "workflow")
|
|
183
|
+
continue;
|
|
184
|
+
const started = await learningStartOfRun(store, run.id);
|
|
185
|
+
const { looked, grade } = await learningSpendOf(store, run.id);
|
|
186
|
+
const { path, workflow } = await journalReadsOf(store, run, started);
|
|
187
|
+
runs.push({ n: runs.length + 1, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, ...runCostOf(run.costUsd, looked, grade) });
|
|
188
|
+
}
|
|
189
|
+
return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length };
|
|
190
|
+
}
|
|
191
|
+
/** What run `runId`'s learning spent, as its cost per run counts it: what it kept as it answered (`looked`: answeredOf),
|
|
192
|
+
* and its grade's spend (`grade`): its learning run's cost once that run ended, stopped or failed (runner/learning-loop.ts
|
|
193
|
+
* keeps the grade's spend there, a paid grade a person stopped included; null when unknown), 0 while it runs or when the
|
|
194
|
+
* run queued none. */
|
|
195
|
+
async function learningSpendOf(store, runId) {
|
|
196
|
+
const kept = await store.learning.proposal(runId);
|
|
197
|
+
if (!kept)
|
|
198
|
+
return { looked: null, grade: 0 };
|
|
199
|
+
const looked = answeredOf((kept.proposal ?? {}));
|
|
200
|
+
const learningRun = kept.learningRunId ? await store.runs.get(kept.learningRunId) : undefined;
|
|
201
|
+
return { looked, grade: learningRun && FINAL_STATES.includes(learningRun.state) ? (learningRun.costUsd ?? null) : 0 };
|
|
202
|
+
}
|
|
203
|
+
/** What a run's journal tells the agent's learning view and its cost per run: the notes its job opened (`read`, once
|
|
204
|
+
* final), what its claims laid of the skills and workflows it was offered (`laid`), and, for a run offered a learned
|
|
205
|
+
* workflow, the path it took and the workflow it called last (`path`, `workflow`: runner/learning-end.ts
|
|
206
|
+
* runPathOf, workflowNameOf; any other run's path is `agent`). Read once for a settled run and kept by its epoch
|
|
207
|
+
* (settledJournalReads), else read now. */
|
|
208
|
+
async function journalReadsOf(store, run, started) {
|
|
209
|
+
const final = FINAL_STATES.includes(run.state);
|
|
210
|
+
const offered = !!(started?.skills?.length || started?.workflows?.length);
|
|
211
|
+
const flows = !!started?.workflows?.length;
|
|
212
|
+
const journal = async () => {
|
|
213
|
+
const rows = (final && started?.given.length) || flows ? await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: final }) : [];
|
|
214
|
+
const entries = offered ? await runEntries(store, run.id, BACKGROUND_CONTEXT) : [];
|
|
215
|
+
const path = flows ? runPathOf(rows) : "agent";
|
|
216
|
+
return {
|
|
217
|
+
read: final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), rows) : [],
|
|
218
|
+
laid: offered ? laidOf(entries) : undefined,
|
|
219
|
+
path,
|
|
220
|
+
// Only a name the launch offered: a call's raw `name` (a failed call's included) is the model's text, never shown.
|
|
221
|
+
workflow: path === "agent" ? null : offeredName(workflowNameOf([...callArgsOf(entries).values()]), started?.workflows),
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
return final ? settledJournalReads(store, run.id, run.epoch, journal) : journal();
|
|
225
|
+
}
|
|
226
|
+
/** `name` when it is one of the learned workflows the run's launch offered, else null. */
|
|
227
|
+
const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
|
|
170
228
|
/** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
|
|
171
229
|
* and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
|
|
172
230
|
* next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type
|
|
2
|
+
import { type ImportedFrom, type RunRow, type Store } from "../store/store.js";
|
|
3
3
|
/** A revision's kind, as the row names it. */
|
|
4
4
|
export type RevisionKind = "agentic" | "workflow";
|
|
5
5
|
/** The run state the v2 API serves, as the old store kept it: a non-terminal run is 'running' (the live view refines its
|
|
@@ -19,9 +19,11 @@ export interface RunRowView {
|
|
|
19
19
|
readonly archivedAt?: string;
|
|
20
20
|
readonly importedFrom?: ImportedFrom;
|
|
21
21
|
}
|
|
22
|
-
/** A run's v2 state from A's state and
|
|
23
|
-
*
|
|
24
|
-
|
|
22
|
+
/** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
|
|
23
|
+
* stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
|
|
24
|
+
* stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
|
|
25
|
+
* stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
|
|
26
|
+
export declare function runReadState(run: RunRow, kind: RevisionKind): RunReadState;
|
|
25
27
|
/** The runs, newest first; `agent` and `revision` narrow it. Archived runs are listed too (the server filters them), with
|
|
26
28
|
* the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
|
|
27
29
|
export declare function listRuns(store: Store, filter: {
|
package/dist/store-reads/runs.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import { stoppedByPerson } from "../store/store.js";
|
|
1
2
|
import { spentOverStore } from "./cap.js";
|
|
2
3
|
const isoOf = (ms) => new Date(ms).toISOString();
|
|
3
|
-
/** A run's v2 state from A's state and
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
|
|
5
|
+
* stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
|
|
6
|
+
* stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
|
|
7
|
+
* stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
|
|
8
|
+
export function runReadState(run, kind) {
|
|
9
|
+
return stateOf(run, kind);
|
|
7
10
|
}
|
|
8
|
-
function stateOf(run) {
|
|
11
|
+
function stateOf(run, kind) {
|
|
9
12
|
switch (run.state) {
|
|
10
13
|
case "ended":
|
|
11
14
|
return run.outcome === "escalated" ? "escalated" : "completed";
|
|
12
15
|
case "stopped":
|
|
13
|
-
return "stopped";
|
|
16
|
+
return stoppedByPerson(run, kind) ? "running" : "stopped";
|
|
14
17
|
case "failed":
|
|
15
18
|
return "failed";
|
|
16
19
|
default:
|
|
@@ -21,16 +24,20 @@ function stateOf(run) {
|
|
|
21
24
|
* (the booked-so-far spend for a run not ended, else its stored cost). */
|
|
22
25
|
function viewOf(run, agentArchivedAt, kind, cost) {
|
|
23
26
|
const archivedAt = run.archivedAt ?? agentArchivedAt;
|
|
27
|
+
const state = stateOf(run, kind);
|
|
28
|
+
// A run that reads running has no end to show: a person's stop keeps its time and words in the store, for its reopen
|
|
29
|
+
// to clear, and the run is not over.
|
|
30
|
+
const over = state !== "running";
|
|
24
31
|
return {
|
|
25
32
|
id: run.id,
|
|
26
33
|
agent: run.agentId,
|
|
27
34
|
revision: run.revisionId,
|
|
28
35
|
kind,
|
|
29
|
-
state
|
|
36
|
+
state,
|
|
30
37
|
startedAt: isoOf(run.startedAt),
|
|
31
|
-
...(run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
|
|
38
|
+
...(over && run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
|
|
32
39
|
...(cost !== null ? { costUsd: cost } : {}),
|
|
33
|
-
...(run.summary !== null ? { summary: run.summary } : {}),
|
|
40
|
+
...(over && run.summary !== null ? { summary: run.summary } : {}),
|
|
34
41
|
...(archivedAt !== null ? { archivedAt: isoOf(archivedAt) } : {}),
|
|
35
42
|
...(run.importedFrom !== null ? { importedFrom: { source: run.importedFrom.source, session: run.importedFrom.session } } : {}),
|
|
36
43
|
};
|
|
@@ -47,7 +54,7 @@ function joins(store, context) {
|
|
|
47
54
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind ?? "agentic");
|
|
48
55
|
// A run that has not ended shows the spend booked so far (the cap's own reading over the journal, the figure it holds
|
|
49
56
|
// the run to), since cost_usd is written only at the end; an ended run shows its stored cost.
|
|
50
|
-
const cost = runReadState(run) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
|
|
57
|
+
const cost = runReadState(run, kinds.get(run.revisionId)) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
|
|
51
58
|
return viewOf(run, agentArchived.get(run.agentId), kinds.get(run.revisionId), cost);
|
|
52
59
|
},
|
|
53
60
|
};
|
|
@@ -16,8 +16,12 @@ export async function stats(store) {
|
|
|
16
16
|
const shown = new Map();
|
|
17
17
|
const hidden = new Map();
|
|
18
18
|
const running = [];
|
|
19
|
+
// Each revision's kind, read once: an agentic run a person stopped reads running (runReadState).
|
|
20
|
+
const kinds = new Map();
|
|
19
21
|
for (const run of runs) {
|
|
20
|
-
|
|
22
|
+
if (!kinds.has(run.revisionId))
|
|
23
|
+
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow" ? "workflow" : "agentic");
|
|
24
|
+
const state = runReadState(run, kinds.get(run.revisionId));
|
|
21
25
|
const runArchived = run.archivedAt !== null;
|
|
22
26
|
if (state === "running" && !runArchived && !archivedAgent.has(run.agentId))
|
|
23
27
|
running.push(run.id);
|
package/dist/store-view.js
CHANGED
|
@@ -13,7 +13,7 @@ import { said } from "./learning-words.js";
|
|
|
13
13
|
import { CONTENT_FILTER_WORDS, contentFiltered, MODERATED } from "./content-filter.js";
|
|
14
14
|
import { launchOf } from "./handed-values.js";
|
|
15
15
|
import { learningStartOf, seedFailed } from "./run-launch.js";
|
|
16
|
-
import { momentOf, pendingOf, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costView, soFarOf, withAsks, withApprovalRows, } from "./run-view.js";
|
|
16
|
+
import { momentOf, pendingOf, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costView, soFarOf, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
|
|
17
17
|
import { reflects } from "./reflect-range.js";
|
|
18
18
|
import { overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
|
|
19
19
|
import { bookedSpend } from "./runner/metrics.js";
|
|
@@ -22,16 +22,16 @@ import { capNowOf, KINDS } from "./runner/journal-kinds.js";
|
|
|
22
22
|
import { notesReadOf, runLearningEnd, withNotes } from "./store-reads/learning.js";
|
|
23
23
|
import { runReflect, runTimeline, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
|
|
24
24
|
import { readRun } from "./store-reads/runs.js";
|
|
25
|
-
import { runCutValues, runErrorWordsOf } from "./run-cut.js";
|
|
25
|
+
import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
|
|
26
26
|
import { Turns } from "./turns.js";
|
|
27
27
|
import { harnessOfBody } from "./harness.js";
|
|
28
28
|
import { browserAsk as browserAskOf, BROWSER_HANDOVER_KIND } from "./browser-commands.js";
|
|
29
29
|
import { computerAsk as computerAskOf, COMPUTER_HANDOVER_KIND } from "./computer-commands.js";
|
|
30
30
|
import { approvalsOf } from "./approvals.js";
|
|
31
|
-
import { FINAL_STATES } from "./store/store.js";
|
|
31
|
+
import { FINAL_STATES, stoppedByPerson } from "./store/store.js";
|
|
32
32
|
/** A run that has ended reads one of these (the old RunRow state → the v2 status: an escalation is a completion with a
|
|
33
33
|
* review; a stopped run is a cancellation), as runs.ts's STATUS_OF mapped them. A running run reads its status from the
|
|
34
|
-
* journal. */
|
|
34
|
+
* journal, and so does an agentic run a person stopped, which reads running (runReadState). */
|
|
35
35
|
const STATUS_OF = { completed: "completed", failed: "failed", escalated: "completed", stopped: "cancelled" };
|
|
36
36
|
/** A run that has reached a last state (its view is its ended shape). */
|
|
37
37
|
const TERMINAL = new Set(["completed", "failed", "cancelled"]);
|
|
@@ -43,9 +43,9 @@ const iso = (ms) => new Date(ms).toISOString();
|
|
|
43
43
|
const servedByStore = new WeakMap();
|
|
44
44
|
const SERVED_KEPT = 32;
|
|
45
45
|
function servedOnce(store, runId, input, values) {
|
|
46
|
-
let served = servedByStore.get(store);
|
|
46
|
+
let served = servedByStore.get(store.origin);
|
|
47
47
|
if (!served)
|
|
48
|
-
servedByStore.set(store, (served = new Map()));
|
|
48
|
+
servedByStore.set(store.origin, (served = new Map()));
|
|
49
49
|
const key = wholeAnswerFor(values).key;
|
|
50
50
|
const last = served.get(runId);
|
|
51
51
|
if (last && last.key === key && last.input === input)
|
|
@@ -99,8 +99,32 @@ function pausedOf(runRow, entries) {
|
|
|
99
99
|
function liveOf(runRow, now) {
|
|
100
100
|
return !FINAL_STATES.includes(runRow.state) && runRow.runner !== null && runRow.claimedUntil !== null && runRow.claimedUntil >= now;
|
|
101
101
|
}
|
|
102
|
-
/** Reads the run from the store and builds the RunView the view functions read.
|
|
102
|
+
/** Reads the run from the store and builds the RunView the view functions read. Every read of the run (its row, launch,
|
|
103
|
+
* journal, live tick and commands) is made in one snapshot of the store (Store.snapshot), so the view is of one moment: a
|
|
104
|
+
* runner's commit that lands while it is built is in all of it or in none. What is read through the server's own handles
|
|
105
|
+
* (the run's cut, which reads the agent's sign-ins, and the learning statuses of its folder) is read outside the snapshot,
|
|
106
|
+
* before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. */
|
|
103
107
|
async function storeRunOf(store, runId, deps) {
|
|
108
|
+
// The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
|
|
109
|
+
// run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
|
|
110
|
+
// was handed (rowShown's choke point). The snapshot renders under it, so it is read first, and read again after: the cut
|
|
111
|
+
// only grows, so one that is the same after the snapshot holds every value saved before the rows were read (underCut
|
|
112
|
+
// builds again under a cut that grew meanwhile).
|
|
113
|
+
const cutOf = async () => {
|
|
114
|
+
const known = await store.runs.get(runId);
|
|
115
|
+
return known ? runCutValues(deps, store, runId, { runRow: known, launch: await launchOf(store, runId) }) : undefined;
|
|
116
|
+
};
|
|
117
|
+
if (!(await store.runs.get(runId)))
|
|
118
|
+
return undefined;
|
|
119
|
+
const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut)));
|
|
120
|
+
if (!run?.shownEnd || !holdsForOk(run.shownEnd) || !deps.statuses)
|
|
121
|
+
return run && { ...run, learningEnd: run.shownEnd };
|
|
122
|
+
// What the learning end held for its owner's OK reads as it stands now on its agent's folder's main (learning.ts
|
|
123
|
+
// currentLearning); its record stays as the merge wrote it.
|
|
124
|
+
return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)) };
|
|
125
|
+
}
|
|
126
|
+
/** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
|
|
127
|
+
async function storeRunIn(store, runId, deps, cut) {
|
|
104
128
|
const context = BACKGROUND_CONTEXT;
|
|
105
129
|
const row = await readRun(store, runId, context);
|
|
106
130
|
if (!row)
|
|
@@ -109,10 +133,6 @@ async function storeRunOf(store, runId, deps) {
|
|
|
109
133
|
if (!runRow)
|
|
110
134
|
return undefined;
|
|
111
135
|
const launch = await launchOf(store, runId);
|
|
112
|
-
// The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
|
|
113
|
-
// run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
|
|
114
|
-
// was handed (rowShown's choke point).
|
|
115
|
-
const cut = await runCutValues(deps, store, runId, { runRow, launch });
|
|
116
136
|
const unshown = cut === "unreadable";
|
|
117
137
|
const values = cut === "unreadable" ? [] : cut.values;
|
|
118
138
|
const revision = await store.agents.revision(row.revision);
|
|
@@ -152,9 +172,6 @@ async function storeRunOf(store, runId, deps) {
|
|
|
152
172
|
const under = !ended && started && !seedFailed(started) ? underWay(started, reflectRange, iso(runRow.startedAt)) : null;
|
|
153
173
|
const sofar = ended ?? under;
|
|
154
174
|
const shownEnd = sofar && withNotes(sofar, started, read);
|
|
155
|
-
// What it held for its owner's OK as it reads now, on its agent's folder's main (learning.ts currentLearning); its record
|
|
156
|
-
// stays as the merge wrote it.
|
|
157
|
-
const learningEnd = shownEnd && holdsForOk(shownEnd) && deps.statuses ? currentLearning(shownEnd, await deps.statuses(row.agent)) : shownEnd;
|
|
158
175
|
const turns = new Turns();
|
|
159
176
|
turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
|
|
160
177
|
const working = live && turns.open > 0;
|
|
@@ -173,7 +190,13 @@ async function storeRunOf(store, runId, deps) {
|
|
|
173
190
|
// The run's cap as it stands, through the one reader the runner's gate reads too (capNowOf): a raise taken shows in the
|
|
174
191
|
// run's cost.cap_usd and its budget card, never the old cap.
|
|
175
192
|
const capUsd = capNowOf(launch?.maxCostUsd, records.entries);
|
|
176
|
-
|
|
193
|
+
// A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
|
|
194
|
+
// stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it.
|
|
195
|
+
const meta = {
|
|
196
|
+
...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}),
|
|
197
|
+
...(Object.keys(answers).length ? { approvals: answers } : {}),
|
|
198
|
+
...(stoppedByPerson(runRow, row.kind) ? { stopped_after: usersOf(rows) } : {}),
|
|
199
|
+
};
|
|
177
200
|
// The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
|
|
178
201
|
// raise clears it). Read over the same meta cap and rows the card's figures and time come from.
|
|
179
202
|
const budget = budgetOf(records.entries, { meta, rows, updatedAt: iso(updatedAtMs) });
|
|
@@ -212,8 +235,8 @@ async function storeRunOf(store, runId, deps) {
|
|
|
212
235
|
...(row.importedFrom ? { imported: { source: row.importedFrom.source, session: row.importedFrom.session } } : {}),
|
|
213
236
|
kind: row.kind,
|
|
214
237
|
...(outcome ? { outcome } : {}),
|
|
215
|
-
//
|
|
216
|
-
cancel:
|
|
238
|
+
// A cancel is the run's outcome 'cancelled', never its state alone: a person's stop is stopped too, and is no cancel.
|
|
239
|
+
cancel: runRow.outcome === "cancelled",
|
|
217
240
|
working,
|
|
218
241
|
submitted,
|
|
219
242
|
updatedAt: iso(updatedAtMs),
|
|
@@ -235,7 +258,7 @@ async function storeRunOf(store, runId, deps) {
|
|
|
235
258
|
// What its decisions booked (their own session, never on the usage row, which counts its model requests and paid tools).
|
|
236
259
|
const booked = bookedSpend(records.entries, "decisions");
|
|
237
260
|
const decisions = booked.requests ? booked : undefined;
|
|
238
|
-
return { row, runRow, launch, rows, version, harness, learningEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions };
|
|
261
|
+
return { row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions };
|
|
239
262
|
}
|
|
240
263
|
/** A run's learning as the view shows it: its end from the store (what it held for the owner's OK as it reads now), in a
|
|
241
264
|
* person's words cut of the host's secrets now, and, for an ended run, the notes it read. */
|
|
@@ -387,7 +410,10 @@ export async function momentOverStore(store, runId, deps = { origin: "", serverS
|
|
|
387
410
|
const run = await storeRunOf(store, runId, deps);
|
|
388
411
|
if (!run)
|
|
389
412
|
return undefined;
|
|
390
|
-
|
|
413
|
+
// What is archived of it: its agent (whose archive holds its runs too, so it is said first: unarchiving the run alone would
|
|
414
|
+
// not open it), else the run's own archive time.
|
|
415
|
+
const archived = (await store.agents.get(run.row.agent))?.archivedAt ? "agent" : run.row.archivedAt ? "run" : undefined;
|
|
416
|
+
return { ...momentOf(run.view, factsOf(run), run.live), ...(archived ? { archived } : {}) };
|
|
391
417
|
}
|
|
392
418
|
/** A run's timeline rows as the VIEW renders them (storeRunOf's view.rows: withAsks, so a run waiting on a question carries
|
|
393
419
|
* its `:waiting` row). The run-ended/run-needs-input follower reads these for its wait marker, main's marker and webhook-id.
|
package/dist/template-eval.js
CHANGED
|
@@ -954,7 +954,8 @@ async function sameAsLocal(ctx, one, agent) {
|
|
|
954
954
|
}
|
|
955
955
|
const served = ctx.served;
|
|
956
956
|
const view = JSON.parse(JSON.stringify(packageView(pkg)));
|
|
957
|
-
|
|
957
|
+
// computer_here is the server's answer to the package's computer list, never the package: not compared.
|
|
958
|
+
const differs = [...new Set([...Object.keys(view), ...Object.keys(served)])].filter((key) => key !== "computer_here" && !same(view[key], served[key]));
|
|
958
959
|
const { parameters } = applyBodyOf(pkg, { parameters: one.parameters, grants: one.grants });
|
|
959
960
|
const local = compiled(pkg, parameters, { mcp: [], defaultTools: [], grants: [] }).agent;
|
|
960
961
|
const sha = (text) => createHash("sha256").update(text).digest("hex");
|