@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
// The reads the server made from a run's own database, now from A's journal (store.readJournal): a run's entries in log
|
|
2
|
+
// order, its timeline (the renderer unchanged), and what was said to it (its hearing). The old path read each run's
|
|
3
|
+
// its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
|
|
4
|
+
// The renderer and the hearing keep their words; only where the entries come from changes.
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
|
|
2
7
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
3
8
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
4
9
|
import { Hearing } from "../heard.js";
|
|
5
|
-
import {
|
|
10
|
+
import { redactedAnswer } from "../key-refusal.js";
|
|
11
|
+
import { labelled } from "../reflect-range.js";
|
|
6
12
|
import { reflectFrom } from "../runner/end-of-run.js";
|
|
7
13
|
import { journalEntries, journalRecords } from "../runner/journal-reader.js";
|
|
8
|
-
import { KINDS } from "../runner/journal-kinds.js";
|
|
14
|
+
import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
|
|
15
|
+
import { bookedSpend, costIsBooked } from "../runner/metrics.js";
|
|
16
|
+
import { waitingText } from "../tool-gate.js";
|
|
9
17
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
10
18
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
11
19
|
export async function runEntries(store, runId, context) {
|
|
@@ -16,7 +24,7 @@ export async function runEntries(store, runId, context) {
|
|
|
16
24
|
* before its input; `until`, the run's end entry once written. Undefined for a run that asked none. */
|
|
17
25
|
export async function runReflect(store, runId, context) {
|
|
18
26
|
const records = await journalRecords(store.readJournal(runId), context);
|
|
19
|
-
const from = reflectFrom(records.submissions ?? []);
|
|
27
|
+
const from = reflectFrom(records.submissions ?? [], records.entries);
|
|
20
28
|
if (from === undefined)
|
|
21
29
|
return undefined;
|
|
22
30
|
const end = records.entries.find((entry) => entry.kind === KINDS.end && Number(entry.id) >= from);
|
|
@@ -27,24 +35,65 @@ export async function runReflect(store, runId, context) {
|
|
|
27
35
|
* tool call its assistant tool-call and its result. So a claude-agent / codex / opencode run reads the same rows, words
|
|
28
36
|
* and final answer as a pi run of the same conversation. A run's own pi entries and its end-of-run turn (already model
|
|
29
37
|
* shaped) pass through unchanged, so a pi run is untouched. */
|
|
38
|
+
/** The calls the CLI record holds parked at their gate (a start marked parked) with no sent mark and no end. */
|
|
39
|
+
function parkedUnsent(entries) {
|
|
40
|
+
const parked = new Set();
|
|
41
|
+
const past = new Set();
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const callId = entry.data?.callId;
|
|
44
|
+
if (typeof callId !== "string")
|
|
45
|
+
continue;
|
|
46
|
+
if (entry.kind === KINDS.callStart && entry.data.parked === true)
|
|
47
|
+
parked.add(callId);
|
|
48
|
+
else if (entry.kind === KINDS.callSent || entry.kind === KINDS.callEnd)
|
|
49
|
+
past.add(callId);
|
|
50
|
+
}
|
|
51
|
+
for (const callId of past)
|
|
52
|
+
parked.delete(callId);
|
|
53
|
+
return parked;
|
|
54
|
+
}
|
|
30
55
|
function piShaped(entries) {
|
|
31
|
-
|
|
56
|
+
const waiting = parkedUnsent(entries);
|
|
57
|
+
return entries.flatMap((entry) => {
|
|
32
58
|
const data = (entry.data ?? {});
|
|
59
|
+
// A call through a CLI's own MCP client that its gate parked (adapter-loop.ts park): the CLI was answered the gate's
|
|
60
|
+
// waiting words (mcp-run.ts), which the record never keeps as the call's end, since an end is its outcome and the call
|
|
61
|
+
// is answered from it. While the call is parked and unsent, those words show as its result row from its ask on, as pi's
|
|
62
|
+
// parked call shows them; its sent mark or its end (run, refused, withdrawn) ends that.
|
|
63
|
+
// Once per call, at its first ask: a call asked again (a resume, a raise while it waits) shows one waiting result.
|
|
64
|
+
if (entry.kind === KINDS.ask && typeof data.callId === "string" && waiting.delete(data.callId)) {
|
|
65
|
+
const tool = typeof data.tool === "string" ? data.tool : "tool";
|
|
66
|
+
const timestamp = typeof data.requestedAt === "string" && Number.isFinite(Date.parse(data.requestedAt)) ? { timestamp: Date.parse(data.requestedAt) } : {};
|
|
67
|
+
// Its own id (the ask's, marked), so the renderer never takes it for the ask entry seen twice.
|
|
68
|
+
const result = { ...entry, id: `${String(entry.id)}:parked`, kind: "pi.tool-result", data: {}, model: [{ role: "tool", toolCallId: data.callId, content: waitingText(tool), ...timestamp }] };
|
|
69
|
+
return [entry, result];
|
|
70
|
+
}
|
|
71
|
+
// When the record's entry was written (`at`), as pi's own message carries its timestamp: the Timeline dates the row by it.
|
|
72
|
+
const timestamp = typeof data.at === "number" ? { timestamp: data.at } : {};
|
|
33
73
|
if (entry.kind === KINDS.message) {
|
|
34
74
|
const text = typeof data.text === "string" ? data.text : "";
|
|
35
75
|
if (data.role === "person")
|
|
36
|
-
return { ...entry, kind: "pi.user", model: [{ role: "user", content: text }] };
|
|
76
|
+
return { ...entry, kind: "pi.user", model: [{ role: "user", content: text, ...timestamp }] };
|
|
37
77
|
// A model turn's text; its stop reason is the answer's (a cut at the output limit reads "length", as pi's does).
|
|
38
78
|
const stopReason = data.stopReason === "length" ? "length" : "stop";
|
|
39
|
-
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason, content: [{ type: "text", text }], ...(typeof data.outputTokens === "number" ? { usage: { output: data.outputTokens } } : {}) }] };
|
|
79
|
+
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason, content: [{ type: "text", text }], ...(typeof data.outputTokens === "number" ? { usage: { output: data.outputTokens } } : {}), ...timestamp }] };
|
|
80
|
+
}
|
|
81
|
+
// The end-of-run turn's answer, as the CLI record keeps it (adapter-loop.ts answered): a model turn that ended, so the
|
|
82
|
+
// timeline shows it as pi's end-of-run turn shows its own (labelled then marks it the learning's).
|
|
83
|
+
if (entry.kind === KINDS.endOfRunTurn && data.role === "model") {
|
|
84
|
+
const text = typeof data.text === "string" ? data.text : "";
|
|
85
|
+
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "stop", content: [{ type: "text", text }] }] };
|
|
40
86
|
}
|
|
41
87
|
if (entry.kind === KINDS.callStart) {
|
|
42
|
-
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }] }] };
|
|
88
|
+
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
|
|
43
89
|
}
|
|
44
90
|
if (entry.kind === KINDS.callEnd) {
|
|
45
|
-
// A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text.
|
|
91
|
+
// A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text. One
|
|
92
|
+
// a crash cut, written with no output, reads in the words its model was given (endedAnswer: the kernel's interrupted
|
|
93
|
+
// text), as pi's own interrupted result does, never an empty failure.
|
|
46
94
|
const failed = data.status !== undefined && data.status !== "done";
|
|
47
|
-
|
|
95
|
+
const content = data.output === undefined && data.status === "interrupted" ? endedAnswer("", { status: "interrupted" }).text : (data.output ?? "");
|
|
96
|
+
return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...timestamp }] };
|
|
48
97
|
}
|
|
49
98
|
return entry;
|
|
50
99
|
});
|
|
@@ -63,13 +112,15 @@ export function withPaidCosts(entries) {
|
|
|
63
112
|
if (typeof conv !== "number")
|
|
64
113
|
return [...entries];
|
|
65
114
|
// Each paid request's tool and the call it ran under, by its turn; then each turn's cost, paired by turn.
|
|
115
|
+
// Its tool: the one the request names (`tool`: a browser step's "browser", which the renderer folds into its call's row
|
|
116
|
+
// with its session `tag`, as main's browser charge), else its paid name.
|
|
66
117
|
const named = new Map();
|
|
67
118
|
for (const e of entries) {
|
|
68
119
|
if (e.conversationId !== conv || e.kind !== RUNNER_RECORDS.request)
|
|
69
120
|
continue;
|
|
70
121
|
const d = (e.data ?? {});
|
|
71
122
|
if (typeof d.turn === "number" && typeof d.model === "string" && d.model.startsWith("paid:"))
|
|
72
|
-
named.set(d.turn, { 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 } : {}) });
|
|
123
|
+
named.set(d.turn, { tool: typeof d.tool === "string" && d.tool ? d.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 } : {}) });
|
|
73
124
|
}
|
|
74
125
|
const charges = [];
|
|
75
126
|
for (const e of entries) {
|
|
@@ -82,7 +133,7 @@ export function withPaidCosts(entries) {
|
|
|
82
133
|
// is unknown (null) is a charge of an unknown amount (main's TOOL_COST with no usd).
|
|
83
134
|
if (!req || d.givenBack === true)
|
|
84
135
|
continue;
|
|
85
|
-
charges.push({ ...req, usd: typeof d.usd === "number" && Number.isFinite(d.usd) && d.usd >= 0 ? d.usd : null });
|
|
136
|
+
charges.push({ ...req, turn: d.turn, usd: typeof d.usd === "number" && Number.isFinite(d.usd) && d.usd >= 0 ? d.usd : null });
|
|
86
137
|
}
|
|
87
138
|
if (!charges.length)
|
|
88
139
|
return [...entries];
|
|
@@ -92,23 +143,124 @@ export function withPaidCosts(entries) {
|
|
|
92
143
|
// MCP server, a browser vendor).
|
|
93
144
|
const by = charge.chargedBy;
|
|
94
145
|
const at = charge.call === undefined ? -1 : out.findIndex((e) => e.kind === "pi.tool-result" && String(e.model?.[0]?.toolCallId ?? "") === charge.call);
|
|
95
|
-
const data = { tool: charge.tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
|
|
96
|
-
const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}` };
|
|
146
|
+
const data = { tool: charge.tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
|
|
147
|
+
const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}#${charge.turn}` };
|
|
97
148
|
out.splice(at >= 0 ? at + 1 : out.length, 0, entry);
|
|
98
149
|
}
|
|
99
150
|
return out;
|
|
100
151
|
}
|
|
152
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). */
|
|
153
|
+
export const isCliRecord = (entries) => entries.some((entry) => entry.kind === KINDS.message || entry.kind === KINDS.callStart || entry.kind === KINDS.callEnd);
|
|
101
154
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
102
155
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
103
|
-
* (withPaidCosts).
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* (
|
|
156
|
+
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
157
|
+
* costIsBooked) has the usage row the renderer folds from its model turns put in its booking's words (bookedUsage): its
|
|
158
|
+
* model requests at what the run's model proxy booked them at, and its paid tool calls at what they charged, as a pi
|
|
159
|
+
* run's usage row counts them; its decisions' rows and cost come from their receipts (decision-rows.ts withDecisions),
|
|
160
|
+
* once. The end-of-run turn's rows are labelled as the server labels them (reflect-range.ts labelled). */
|
|
107
161
|
export async function runTimeline(store, runId, context, options = {}) {
|
|
108
162
|
const entries = await runEntries(store, runId, context);
|
|
109
|
-
const cli = entries
|
|
110
|
-
const
|
|
111
|
-
|
|
163
|
+
const cli = isCliRecord(entries);
|
|
164
|
+
const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), options);
|
|
165
|
+
const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : rendered;
|
|
166
|
+
return labelled((await runReflect(store, runId, context)), await datedRows(store, runId, rows));
|
|
167
|
+
}
|
|
168
|
+
/** A CLI or workflow run's `rows` with its usage row in its booking's words (runner/metrics.ts bookedSpend over every
|
|
169
|
+
* 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,
|
|
170
|
+
* costsofar/1), in the renderer's words (`Cost` once ended, else `Cost so far`). The renderer's own row is replaced in
|
|
171
|
+
* place; a run that booked a request and rendered none gets one at the end. One that booked none keeps its rows, with no
|
|
172
|
+
* usage row. */
|
|
173
|
+
function bookedUsage(rows, entries, options) {
|
|
174
|
+
const model = bookedSpend(entries, "model");
|
|
175
|
+
const paid = bookedSpend(entries, "paid");
|
|
176
|
+
const at = rows.findIndex((row) => row.kind === "usage");
|
|
177
|
+
const kept = rows.filter((row) => row.kind !== "usage");
|
|
178
|
+
if (!model.requests && !paid.requests)
|
|
179
|
+
return kept;
|
|
180
|
+
const usd = model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
|
|
181
|
+
const unpriced = model.unpriced + paid.unpriced;
|
|
182
|
+
const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
|
|
183
|
+
const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
|
|
184
|
+
const charges = paid.requests ? ` and ${paid.requests} paid tool call${paid.requests === 1 ? "" : "s"}` : "";
|
|
185
|
+
const summary = `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
|
|
186
|
+
const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
|
|
187
|
+
const last = rows[rows.length - 1];
|
|
188
|
+
const base = at >= 0 ? rows[at] : {
|
|
189
|
+
...last, id: `${last?.conversation_id ?? 0}:usage`, agent_label: null, text: null,
|
|
190
|
+
tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null,
|
|
191
|
+
};
|
|
192
|
+
const row = { ...base, kind: "usage", summary, usage };
|
|
193
|
+
const out = [...kept];
|
|
194
|
+
out.splice(at >= 0 ? at : out.length, 0, row);
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
/** `rows` with none dated 1970: a row the renderer found no time for (an entry of a CLI record written before its entries
|
|
198
|
+
* carried `at`; the store's entry rows keep no write time of their own) reads the run's start, the earliest time it can
|
|
199
|
+
* have, never epoch 0. Every other row is as the renderer dated it. */
|
|
200
|
+
async function datedRows(store, runId, rows) {
|
|
201
|
+
if (!rows.some((row) => Date.parse(row.timestamp) === 0))
|
|
202
|
+
return rows;
|
|
203
|
+
const run = await store.runs.get(runId);
|
|
204
|
+
if (!run)
|
|
205
|
+
return rows;
|
|
206
|
+
const started = new Date(run.startedAt).toISOString();
|
|
207
|
+
return rows.map((row) => (Date.parse(row.timestamp) === 0 ? { ...row, timestamp: started, created_at: started } : row));
|
|
208
|
+
}
|
|
209
|
+
/** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
|
|
210
|
+
export const wholeAnswerFor = (values) => ({
|
|
211
|
+
serve: (text) => redactedAnswer(text, values),
|
|
212
|
+
key: createHash("sha256").update(JSON.stringify([...values].sort())).digest("hex"),
|
|
213
|
+
});
|
|
214
|
+
/** What each store's readers last served of a cut answer row, by run, row and held value set: a console polls a run's
|
|
215
|
+
* view and its Timeline, and an answer a run was made to write can be large (main's runs.ts servedOnce). A row is an
|
|
216
|
+
* entry's, whose words never change. Kept by store, the newest ANSWERS_KEPT of each. */
|
|
217
|
+
const answersServed = new WeakMap();
|
|
218
|
+
const ANSWERS_KEPT = 32;
|
|
219
|
+
/** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
|
|
220
|
+
* cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
|
|
221
|
+
* shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
|
|
222
|
+
* "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
|
|
223
|
+
* from the journal, settled as the rows were, with no text cap and none
|
|
224
|
+
* of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
|
|
225
|
+
* of it and never cuts. Every other row is as it was. */
|
|
226
|
+
export async function wholeAnswers(store, runId, context, rows, options, whole) {
|
|
227
|
+
// The rows' redactor gives exactly "[redacted]" for a text whose head it read was all held or secret-shaped values: the
|
|
228
|
+
// rest of the answer is past what it read, so that row is read again too.
|
|
229
|
+
const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
|
|
230
|
+
if (!rows.some(cut))
|
|
231
|
+
return rows;
|
|
232
|
+
let kept = answersServed.get(store);
|
|
233
|
+
if (!kept)
|
|
234
|
+
answersServed.set(store, (kept = new Map()));
|
|
235
|
+
const keyOf = (row) => `${runId}\0${row.id}\0${whole.key}`;
|
|
236
|
+
let uncut;
|
|
237
|
+
const out = [];
|
|
238
|
+
for (const row of rows) {
|
|
239
|
+
if (!cut(row)) {
|
|
240
|
+
out.push(row);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const key = keyOf(row);
|
|
244
|
+
let served = kept.get(key);
|
|
245
|
+
if (served === undefined) {
|
|
246
|
+
uncut ??= new Map((await runTimeline(store, runId, context, { settled: options.settled, caps: { ...options.caps, text: Number.POSITIVE_INFINITY } })).map((one) => [one.id, one.text]));
|
|
247
|
+
const text = uncut.get(row.id);
|
|
248
|
+
if (text === undefined || text === null) {
|
|
249
|
+
out.push(row);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
served = whole.serve(text);
|
|
253
|
+
kept.delete(key);
|
|
254
|
+
kept.set(key, served);
|
|
255
|
+
for (const oldest of kept.keys()) {
|
|
256
|
+
if (kept.size <= ANSWERS_KEPT)
|
|
257
|
+
break;
|
|
258
|
+
kept.delete(oldest);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
out.push({ ...row, text: served });
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
112
264
|
}
|
|
113
265
|
/** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
|
|
114
266
|
* user entry noted in log order, its origin read by the same matcher. */
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type Learning, type NoteUsed, type Shown } from "../learning.js";
|
|
1
|
+
import { type ItemStatus, type Learning, type NoteUsed, type Shown } from "../learning.js";
|
|
2
2
|
import { type RunLaunch } from "../run-launch.js";
|
|
3
|
-
import { type Impact
|
|
3
|
+
import { type Impact } from "../learning-run.js";
|
|
4
|
+
import type { Reflect } from "../reflect-range.js";
|
|
4
5
|
import type { NoteRuns } from "../learning.js";
|
|
5
|
-
import type { TimelineEvent } from "
|
|
6
|
+
import type { TimelineEvent } from "../timeline/index.js";
|
|
6
7
|
import type { AnalyticsFilter } from "./analytics.js";
|
|
7
8
|
import type { Store } from "../store/store.js";
|
|
8
9
|
/** A run's learning end: the Learning fields its end sets. */
|
|
@@ -23,6 +24,18 @@ export type LearningCounts = {
|
|
|
23
24
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
24
25
|
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. */
|
|
25
26
|
export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter): Promise<LearningCounts>;
|
|
27
|
+
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
28
|
+
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
29
|
+
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
30
|
+
* of the store (Learning.spend), whatever the number of runs. */
|
|
31
|
+
export declare function learningSpendOverStore(store: Store, window: {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
agent: string;
|
|
36
|
+
at: string;
|
|
37
|
+
cost: number | null;
|
|
38
|
+
}[]>;
|
|
26
39
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
27
40
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
28
41
|
* agentLearningOverStore's. */
|
|
@@ -52,9 +65,10 @@ export declare function notesReadOf(given: readonly NoteUsed[] | undefined, refl
|
|
|
52
65
|
export declare function withNotes(end: RunLearningEnd, started: RunLaunch["learning"], read: readonly NoteUsed[]): RunLearning;
|
|
53
66
|
/** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
|
|
54
67
|
* run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
|
|
55
|
-
* what it held for its owner's OK as
|
|
56
|
-
* once the run is final. Null when the run kept
|
|
57
|
-
|
|
68
|
+
* what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
|
|
69
|
+
* read only when it held something; none: as the merge wrote it), settled once the run is final. Null when the run kept
|
|
70
|
+
* no learning. */
|
|
71
|
+
export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
|
|
58
72
|
seed: string | null;
|
|
59
73
|
merged: string | null;
|
|
60
74
|
pending: {
|
|
@@ -73,7 +87,11 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
73
87
|
keep: boolean;
|
|
74
88
|
}[];
|
|
75
89
|
} | null;
|
|
76
|
-
problems:
|
|
90
|
+
problems: {
|
|
91
|
+
detail: string;
|
|
92
|
+
path?: string | undefined;
|
|
93
|
+
rule: import("../learn/check.js").Rule;
|
|
94
|
+
}[];
|
|
77
95
|
cost_usd: {
|
|
78
96
|
grade: number | null;
|
|
79
97
|
};
|
|
@@ -87,7 +105,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
87
105
|
workflows?: import("../learning.js").LearnedFile[];
|
|
88
106
|
run: string;
|
|
89
107
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
90
|
-
reason: "empty" | "
|
|
108
|
+
reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
91
109
|
detail: string | null;
|
|
92
110
|
at: string;
|
|
93
111
|
} | null>;
|
|
@@ -109,6 +109,13 @@ export async function learningCountsOverStore(store, filter) {
|
|
|
109
109
|
}
|
|
110
110
|
return out;
|
|
111
111
|
}
|
|
112
|
+
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
113
|
+
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
114
|
+
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
115
|
+
* of the store (Learning.spend), whatever the number of runs. */
|
|
116
|
+
export async function learningSpendOverStore(store, window) {
|
|
117
|
+
return (await store.learning.spend(window)).map((one) => ({ agent: one.agentId, at: timeOf(one.at), cost: one.costUsd }));
|
|
118
|
+
}
|
|
112
119
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
113
120
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
114
121
|
* agentLearningOverStore's. */
|
|
@@ -186,9 +193,10 @@ async function learningStartOfRun(store, runId) {
|
|
|
186
193
|
}
|
|
187
194
|
/** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
|
|
188
195
|
* run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
|
|
189
|
-
* what it held for its owner's OK as
|
|
190
|
-
* once the run is final. Null when the run kept
|
|
191
|
-
|
|
196
|
+
* what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
|
|
197
|
+
* read only when it held something; none: as the merge wrote it), settled once the run is final. Null when the run kept
|
|
198
|
+
* no learning. */
|
|
199
|
+
export async function runLearningOverStore(store, runId, shown, secrets, statuses) {
|
|
192
200
|
const end = await runLearningEnd(store, runId);
|
|
193
201
|
if (!end)
|
|
194
202
|
return null;
|
|
@@ -197,6 +205,6 @@ export async function runLearningOverStore(store, runId, shown, secrets) {
|
|
|
197
205
|
const settled = row !== undefined && FINAL_STATES.includes(row.state);
|
|
198
206
|
const read = started?.given.length ? notesReadOf(started.given, await runReflect(store, runId, BACKGROUND_CONTEXT), await runTimeline(store, runId, BACKGROUND_CONTEXT, { settled })) : [];
|
|
199
207
|
const learning = withNotes(end, started, read);
|
|
200
|
-
const current = holdsForOk(learning) ? currentLearning(learning,
|
|
208
|
+
const current = holdsForOk(learning) && row && statuses ? currentLearning(learning, await statuses(row.agentId)) : learning;
|
|
201
209
|
return runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled }, shown, secrets);
|
|
202
210
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import { type WorkflowRunView } from "
|
|
2
|
+
import { type WorkflowRunView } from "../workflow-run.js";
|
|
3
3
|
import type { Store } from "../store/store.js";
|
|
4
4
|
/** The workflow run `runId`'s view from A: its graph's node status, and, once it ended, its outcome, the node it escalated
|
|
5
5
|
* at and its output, read from the run's journal (no claim). Undefined when there is no such run, or its revision is gone
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
|
-
import { readWorkflowRun } from "
|
|
2
|
+
import { readWorkflowRun } from "../workflow-run.js";
|
|
3
3
|
/** The workflow run `runId`'s view from A: its graph's node status, and, once it ended, its outcome, the node it escalated
|
|
4
4
|
* at and its output, read from the run's journal (no claim). Undefined when there is no such run, or its revision is gone
|
|
5
5
|
* or is not a workflow. A read never writes or fences. */
|
package/dist/store-view.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { TimelineEvent } from "
|
|
1
|
+
import type { TimelineEvent } from "./timeline/index.js";
|
|
2
|
+
import { type ItemStatus } from "./learning.js";
|
|
2
3
|
import { type RunMoment, type SignInReader } from "./run-view.js";
|
|
3
4
|
import { type Store } from "./store/store.js";
|
|
4
5
|
/** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
|
|
@@ -15,6 +16,9 @@ export interface ViewDeps {
|
|
|
15
16
|
* run's error names a refused key in plain words, as its Timeline's error row does. Default: this process's
|
|
16
17
|
* environment (the server passes it with the keys a person saved). */
|
|
17
18
|
readonly keyEnv?: () => NodeJS.ProcessEnv;
|
|
19
|
+
/** Each learned item's status on agent `agentId`'s learning folder's main (learning-routes.ts statusesOf): what a run held
|
|
20
|
+
* for its owner's OK reads as it stands there. None: as the merge wrote it. */
|
|
21
|
+
readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
|
|
18
22
|
}
|
|
19
23
|
/** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
|
|
20
24
|
export declare function viewOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
|
package/dist/store-view.js
CHANGED
|
@@ -6,15 +6,19 @@
|
|
|
6
6
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
7
7
|
import { runLink } from "./console-links.js";
|
|
8
8
|
import { redacted, redactedAnswer, redactedOutput, withoutLoopback } from "./key-refusal.js";
|
|
9
|
+
import { structuredAnswer } from "./answer-json.js";
|
|
9
10
|
import { currentLearning, holdsForOk, learningView, LEARNING_LABEL, secretsShown, shortOf } from "./learning.js";
|
|
11
|
+
import { said } from "./learning-words.js";
|
|
10
12
|
import { launchOf } from "./handed-values.js";
|
|
11
|
-
import { learningStartOf } from "./run-launch.js";
|
|
13
|
+
import { learningStartOf, seedFailed } from "./run-launch.js";
|
|
12
14
|
import { momentOf, pendingOf, approvalOf, asksOf, answersOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costView, soFarOf, withAsks, withApprovalRows, } from "./run-view.js";
|
|
13
|
-
import { reflects } from "./
|
|
15
|
+
import { reflects } from "./reflect-range.js";
|
|
16
|
+
import { overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
|
|
17
|
+
import { bookedSpend } from "./runner/metrics.js";
|
|
14
18
|
import { journalRecords, recordOf } from "./runner/journal-reader.js";
|
|
15
19
|
import { KINDS } from "./runner/journal-kinds.js";
|
|
16
20
|
import { notesReadOf, runLearningEnd, withNotes } from "./store-reads/learning.js";
|
|
17
|
-
import { runReflect, runTimeline } from "./store-reads/journal.js";
|
|
21
|
+
import { runReflect, runTimeline, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
|
|
18
22
|
import { readRun } from "./store-reads/runs.js";
|
|
19
23
|
import { runCutValues, runErrorWordsOf } from "./run-cut.js";
|
|
20
24
|
import { Turns } from "./turns.js";
|
|
@@ -30,10 +34,41 @@ const STATUS_OF = { completed: "completed", failed: "failed", escalated: "comple
|
|
|
30
34
|
/** A run that has reached a last state (its view is its ended shape). */
|
|
31
35
|
const TERMINAL = new Set(["completed", "failed", "cancelled"]);
|
|
32
36
|
const iso = (ms) => new Date(ms).toISOString();
|
|
37
|
+
/** What a view last served of each run's answer, by store and run: the answer it read (`input`), the digest of the values
|
|
38
|
+
* it was redacted of (`key`) and what that gave (`out`), so a second view of the same answer and values reads nothing
|
|
39
|
+
* again (main's runs.ts servedOnce: a console polls a run's view, and an answer can be large). Newest SERVED_KEPT runs of
|
|
40
|
+
* each store. */
|
|
41
|
+
const servedByStore = new WeakMap();
|
|
42
|
+
const SERVED_KEPT = 32;
|
|
43
|
+
function servedOnce(store, runId, input, values) {
|
|
44
|
+
let served = servedByStore.get(store);
|
|
45
|
+
if (!served)
|
|
46
|
+
servedByStore.set(store, (served = new Map()));
|
|
47
|
+
const key = wholeAnswerFor(values).key;
|
|
48
|
+
const last = served.get(runId);
|
|
49
|
+
if (last && last.key === key && last.input === input)
|
|
50
|
+
return last.out;
|
|
51
|
+
const out = redactedAnswer(input, values);
|
|
52
|
+
served.delete(runId);
|
|
53
|
+
served.set(runId, { input, key, out });
|
|
54
|
+
for (const oldest of served.keys()) {
|
|
55
|
+
if (served.size <= SERVED_KEPT)
|
|
56
|
+
break;
|
|
57
|
+
served.delete(oldest);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
33
61
|
/** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's. */
|
|
34
62
|
const answerOf = (rows) => rows.findLast((r) => r.kind === "final_answer" && r.agent_label !== LEARNING_LABEL)?.text ?? null;
|
|
35
|
-
/** A failed run's error from its row (its own words are the summary; the store keeps no code or detail apart).
|
|
36
|
-
|
|
63
|
+
/** A failed run's error from its row (its own words are the summary; the store keeps no code or detail apart). A run
|
|
64
|
+
* its cap ended once its cost passed it (the kernel's overCapEnd) is code spend_cap_reached, its message the words after
|
|
65
|
+
* the code, as main served it; every other failure is run_failed. */
|
|
66
|
+
const errorOfRow = (summary) => {
|
|
67
|
+
const over = overCapMessage(summary);
|
|
68
|
+
if (over !== undefined)
|
|
69
|
+
return { code: SPEND_CAP_REACHED, message: over, retryable: false };
|
|
70
|
+
return { code: "run_failed", message: summary ?? "The run failed.", retryable: false };
|
|
71
|
+
};
|
|
37
72
|
const reviewOfRow = (state, summary) => (state !== "escalated" ? null : { kind: null, node: null, reason: summary ?? "The workflow escalated." });
|
|
38
73
|
const reviewAt = (review, endedAt) => (review ? { kind: review.kind, node: review.node, reason: review.reason, at: endedAt } : null);
|
|
39
74
|
/** A run's facts as statusOf and momentOf read them, built from the run's journal: whether it stands parked at its cap
|
|
@@ -79,10 +114,17 @@ async function storeRunOf(store, runId, deps) {
|
|
|
79
114
|
const harness = launch?.harness ?? harnessOfBody((revision?.body ?? {}));
|
|
80
115
|
// Whether the run ran unattended, from the revision it is pinned to (approvals "never"), else the default (ask).
|
|
81
116
|
const approvalsMode = approvalsOf(revision?.body?.approvals);
|
|
117
|
+
const outputSchema = row.kind === "agentic" ? revision?.body?.outputSchema : undefined;
|
|
82
118
|
const terminal = row.state !== "running";
|
|
119
|
+
// Its structured answer, from the final answer as the journal keeps it: never the served text, which a held value
|
|
120
|
+
// (a number among them) or a long answer's cut would have changed, so a block that meets the schema reads as written.
|
|
121
|
+
const rawAnswer = outputSchema !== undefined && terminal ? answerOf(await runTimeline(store, runId, context, { settled: true, caps: { text: Number.POSITIVE_INFINITY } })) : null;
|
|
122
|
+
const structured = rawAnswer ? structuredAnswer(rawAnswer, outputSchema) : undefined;
|
|
83
123
|
// The timeline, then the waiting row a run asking a question shows (withAsks), as the file path's rows carried it, so a
|
|
84
124
|
// run waiting on a question reads the same status and pending.
|
|
85
|
-
|
|
125
|
+
// Its final answer whole (store-reads/journal.ts wholeAnswers), as main served a run's answer: a row's cut is no answer's.
|
|
126
|
+
const timelineOptions = { settled: terminal, redact: (text) => redacted(text, values) };
|
|
127
|
+
const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
|
|
86
128
|
const revisions = await store.agents.revisions(row.agent);
|
|
87
129
|
const version = revisions.findIndex((r) => r.id === row.revision) + 1;
|
|
88
130
|
const ended = await runLearningEnd(store, runId);
|
|
@@ -97,9 +139,17 @@ async function storeRunOf(store, runId, deps) {
|
|
|
97
139
|
const records = await journalRecords(store.readJournal(runId), context);
|
|
98
140
|
const reflectRange = (await runReflect(store, runId, context));
|
|
99
141
|
const skip = reflectRange ? (id) => reflects(reflectRange, id) : undefined;
|
|
100
|
-
// The run's learning end with the notes its start gave it and those its job read (its own reads, keyed on the given
|
|
142
|
+
// The run's learning end with the notes its start gave it and those its job read (its own reads, keyed on the given, read
|
|
143
|
+
// from its rows uncut: a note whose name holds a secret is cut where it is shown, after it is matched). Before its end, a
|
|
144
|
+
// run that learns is seeded, then looking back once its end-of-run turn starts (main's seeded and reflecting).
|
|
101
145
|
const started = launch ? learningStartOf(launch) : undefined;
|
|
102
|
-
const
|
|
146
|
+
const read = started?.given.length ? notesReadOf(started.given, reflectRange, await runTimeline(store, runId, context, { settled: terminal })) : [];
|
|
147
|
+
const under = !ended && started && !seedFailed(started) ? underWay(started, reflectRange, iso(runRow.startedAt)) : null;
|
|
148
|
+
const sofar = ended ?? under;
|
|
149
|
+
const shownEnd = sofar && withNotes(sofar, started, read);
|
|
150
|
+
// What it held for its owner's OK as it reads now, on its agent's folder's main (learning.ts currentLearning); its record
|
|
151
|
+
// stays as the merge wrote it.
|
|
152
|
+
const learningEnd = shownEnd && holdsForOk(shownEnd) && deps.statuses ? currentLearning(shownEnd, await deps.statuses(row.agent)) : shownEnd;
|
|
103
153
|
const turns = new Turns();
|
|
104
154
|
turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
|
|
105
155
|
const working = live && turns.open > 0;
|
|
@@ -115,7 +165,11 @@ async function storeRunOf(store, runId, deps) {
|
|
|
115
165
|
// The rows a person reads: each call that waited for approval in order (held, your approval, what came of it), its
|
|
116
166
|
// arguments and the person's notes through the run's redactor, as the file path's withApprovals served them.
|
|
117
167
|
const rows = withApprovalRows(timeline, approvals, answers, redactorOf(values));
|
|
118
|
-
|
|
168
|
+
// The run's cap as it stands: its newest raise's (the agentrun.raise entries the runner's loop holds it to, adapter-loop
|
|
169
|
+
// capNow), else its launch's; a raise taken shows in the run's cost.cap_usd and its budget card, never the old cap.
|
|
170
|
+
const raisedCapUsd = records.entries.findLast((entry) => entry.kind === KINDS.raise && typeof entry.data?.capUsd === "number" && entry.data.capUsd > 0)?.data;
|
|
171
|
+
const capUsd = launch?.maxCostUsd === undefined ? undefined : Math.max(launch.maxCostUsd, raisedCapUsd?.capUsd ?? 0);
|
|
172
|
+
const meta = { ...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}), ...(Object.keys(answers).length ? { approvals: answers } : {}) };
|
|
119
173
|
// The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
|
|
120
174
|
// raise clears it). Read over the same meta cap and rows the card's figures and time come from.
|
|
121
175
|
const budget = budgetOf(records.entries, { meta, rows, updatedAt: iso(updatedAtMs) });
|
|
@@ -169,16 +223,22 @@ async function storeRunOf(store, runId, deps) {
|
|
|
169
223
|
// A completed workflow run's output, from its end (the workflow loop keeps it there, as main kept it on the run).
|
|
170
224
|
const end = row.kind === "workflow" ? records.entries.findLast((entry) => entry.kind === KINDS.end) : undefined;
|
|
171
225
|
const output = end?.data?.output ?? null;
|
|
172
|
-
|
|
226
|
+
// What its decisions booked (their own session, never on the usage row, which counts its model requests and paid tools).
|
|
227
|
+
const booked = bookedSpend(records.entries, "decisions");
|
|
228
|
+
const decisions = booked.requests ? booked : undefined;
|
|
229
|
+
return { row, runRow, launch, rows, version, harness, learningEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, structured, decisions };
|
|
173
230
|
}
|
|
174
|
-
/** A run's learning as the view shows it: its end from the store
|
|
175
|
-
*
|
|
176
|
-
* dropped) reads as it was written. */
|
|
231
|
+
/** 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
|
|
232
|
+
* person's words cut of the host's secrets now, and, for an ended run, the notes it read. */
|
|
177
233
|
function learningViewOf(learningEnd, shown, settled) {
|
|
178
234
|
if (!learningEnd)
|
|
179
235
|
return null;
|
|
180
|
-
|
|
181
|
-
|
|
236
|
+
return learningView(learningEnd, shown, settled);
|
|
237
|
+
}
|
|
238
|
+
/** A learning run's learning before its end (main's learning-run.ts onStart and its end-of-run turn): seeded, saying how
|
|
239
|
+
* many notes its seed held, until its end-of-run turn starts; then looking back. */
|
|
240
|
+
function underWay(started, reflect, at) {
|
|
241
|
+
return reflect ? { state: "reflecting", reason: null, detail: said.reflecting, at } : { state: "seeded", reason: null, detail: said.seeded(started.seedNotes ?? 0), at };
|
|
182
242
|
}
|
|
183
243
|
/** The cost a run's view shows (runs.ts cost): its rows' cost, else what the store kept; a cap's room noted when it has
|
|
184
244
|
* one. A terminal run holds no request in flight, so its overshoot bound is 0. */
|
|
@@ -189,9 +249,12 @@ function costOfView(run) {
|
|
|
189
249
|
// no stored cost (its column is written only at the end), so it reads undefined, which costView turns into 0 before any
|
|
190
250
|
// request — never null.
|
|
191
251
|
const stored = run.row.state === "running" ? undefined : run.runRow.costUsd;
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
const
|
|
252
|
+
// Its decisions' booked cost joins its usage row's (costView), one unknown making it unknown.
|
|
253
|
+
const decisions = run.decisions;
|
|
254
|
+
const usd = imported ? (stored ?? null) : costView(run.rows, stored, decisions ? decisions.usd : undefined);
|
|
255
|
+
const soFar = usd === null && !imported ? soFarOf(run.rows, decisions ? { known: decisions.known, unpriced: decisions.unpriced } : undefined) : undefined;
|
|
256
|
+
// The run's cap as it stands (its view's meta: the newest raise's, else the launch's).
|
|
257
|
+
const cap = run.view.meta.max_cost_usd;
|
|
195
258
|
const bound = cap === undefined ? {} : { overshoot_bound_usd: 0 };
|
|
196
259
|
return { usd, basis: "estimate", charge_state: null, cap_usd: cap ?? null, ...bound, ...(soFar ?? {}) };
|
|
197
260
|
}
|
|
@@ -200,16 +263,21 @@ export async function viewOverStore(store, runId, deps) {
|
|
|
200
263
|
const run = await storeRunOf(store, runId, deps);
|
|
201
264
|
if (!run)
|
|
202
265
|
return undefined;
|
|
203
|
-
const { row, runRow, launch, view, unshown, values, output } = run;
|
|
266
|
+
const { row, runRow, launch, view, unshown, values, output, structured } = run;
|
|
204
267
|
const { status, state } = statusOf(view, factsOf(run));
|
|
205
268
|
const terminal = TERMINAL.has(status);
|
|
206
269
|
const endedAtMs = terminal ? (runRow.endedAt ?? runRow.startedAt) : null;
|
|
207
270
|
const shownWords = (text) => withoutLoopback(redacted(text, values));
|
|
208
|
-
|
|
271
|
+
// The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
|
|
272
|
+
// was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
|
|
273
|
+
const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values) : text);
|
|
209
274
|
const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
|
|
210
|
-
// A workflow run's output, as its end kept it
|
|
211
|
-
//
|
|
212
|
-
|
|
275
|
+
// A workflow run's output, as its end kept it; an agentic run's, its final answer's structured part when its agent has
|
|
276
|
+
// an output schema and the answer's last fenced json block meets it (storeRunOf's `structured`), else none. Served as
|
|
277
|
+
// runs.ts serves it (servedOutput): each string in it cut of the values the run holds, its shape kept; none while the
|
|
278
|
+
// run's sign-in can't be read back.
|
|
279
|
+
const ownOutput = row.kind === "workflow" ? output : status === "completed" && structured && "value" in structured ? structured.value : null;
|
|
280
|
+
const servedOutput = !unshown && ownOutput !== null && ownOutput !== undefined ? redactedOutput(ownOutput, values) : null;
|
|
213
281
|
const result = status === "completed" ? { output: servedOutput, final_answer: servedAnswer(finalAnswer) } : null;
|
|
214
282
|
// A failed run's reason in the model's own words when the store holds them: the last model-error row's text (a provider's
|
|
215
283
|
// refusal, rendered from its pi.assistant error entry), else the run row's summary (the runner's generic "gave no answer").
|