@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40
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 +455 -0
- package/README.md +376 -125
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
- package/dist/console/assets/index-Jbxjcmdp.js +705 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +83 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +15 -0
- package/dist/email/answer.js +217 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +373 -0
- package/dist/email/names.d.ts +50 -0
- package/dist/email/names.js +74 -0
- package/dist/email/routes.d.ts +10 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +27 -0
- package/dist/email/tools.js +562 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +12 -4
- package/dist/learn/compile.js +57 -20
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +130 -64
- package/dist/learn/promote.js +113 -202
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +35 -8
- package/dist/learning-cost.js +27 -9
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +39 -2
- package/dist/local-models.js +49 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +2 -1
- package/dist/openapi.js +404 -93
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +10 -2
- package/dist/port-models.js +6 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +14 -0
- package/dist/refusal-words.js +16 -2
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +13 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +44 -38
- package/dist/run-view.js +93 -56
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +48 -13
- package/dist/runner/adapter-loop.js +691 -254
- package/dist/runner/adapter-run-spec.d.ts +38 -12
- package/dist/runner/adapter-run-spec.js +175 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +95 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +59 -13
- package/dist/runner/journal-kinds.js +48 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +14 -3
- package/dist/runner/model-route.js +155 -19
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +76 -10
- package/dist/runner/promotion.js +476 -154
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +568 -137
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +5 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/connection.js +72 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +170 -34
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +67 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +115 -18
- package/dist/store-reads/learning.js +170 -68
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +84 -21
- package/dist/templates.js +254 -47
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +46 -44
- package/dist/tool-gate.js +101 -92
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +57 -16
- package/dist/tools.js +33 -28
- package/dist/trigger-adapter.d.ts +56 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +181 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +105 -8
- package/dist/triggers.js +286 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
package/dist/template-eval.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// touches the owner's server) or on one named by its address and token. Per case: a fake MCP server per `mcp` fixture,
|
|
5
5
|
// saved under its name with no credential and recording every call; the package applied with the case's parameters and
|
|
6
6
|
// grants, a fresh agent per run, its learning seeded from the case's notes; one run per `runs` with the prompt's body as
|
|
7
|
-
// its input and the case's cap, waited for; then its answer, its tool calls (its timeline
|
|
8
|
-
// the
|
|
7
|
+
// its input and the case's cap, on the case's clock when it sets one (`now`), waited for; then its answer, its tool calls (its timeline read with calls=whole, each
|
|
8
|
+
// call's arguments and its output's head through the run's redaction, and the fakes' own logs) and its files, graded, and held to the package's output schema when it declares one (outputVerdict,
|
|
9
9
|
// the server's own verdict). Every grader is deterministic but `llm`, which is itself a run on the same
|
|
10
10
|
// server: a grader agent with no tools that sees the rubric, the run's input, its answer and its calls, never another
|
|
11
11
|
// grader or an expected answer, and answers {pass, reason}. readCases checks a package's cases without running one.
|
|
@@ -18,11 +18,20 @@ import { parseDocument } from "yaml";
|
|
|
18
18
|
import { answerJson, lastJsonBlock } from "./answer-json.js";
|
|
19
19
|
import { checkNote } from "./learn/index.js";
|
|
20
20
|
import { NOTE_FILE } from "./learn/notes.js";
|
|
21
|
+
import { linkCheck } from "./link-check.js";
|
|
21
22
|
import { inputMessage } from "./run-manifest.js";
|
|
22
23
|
import { shownUrl } from "./mcp-probe.js";
|
|
23
|
-
import { MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName } from "./tool-names.js";
|
|
24
|
+
import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, monidNameOf, parseToolName } from "./tool-names.js";
|
|
25
|
+
import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailboxVerdict, seed, seededFaux, snapshot } from "./eval-mailbox.js";
|
|
26
|
+
import { EMAIL_TOOLS } from "./email/names.js";
|
|
24
27
|
import { settingsKeyOf, shellToolOf } from "./tool-gate.js";
|
|
28
|
+
import { webShownOf } from "./timeline/index.js";
|
|
25
29
|
import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
|
|
30
|
+
import { webFixtureOf } from "./web-fake.js";
|
|
31
|
+
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
32
|
+
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
33
|
+
import { dayIn, serverZone } from "./environment.js";
|
|
34
|
+
import { instantOf } from "./trigger-adapter.js";
|
|
26
35
|
import { applyBodyOf, compiled, filledPins, onServerName, onServers, packageView, readPackage } from "./templates.js";
|
|
27
36
|
import { inputIssues, inputSchemaOf, isObject, MODEL_REF } from "./validate.js";
|
|
28
37
|
/** What a grader run is told, whatever the rubric: blind, strict, and its verdict as one JSON block. */
|
|
@@ -36,20 +45,31 @@ End your reply with exactly one fenced json block and nothing after it:
|
|
|
36
45
|
\`\`\``;
|
|
37
46
|
/** Each grader run's cap, in dollars. */
|
|
38
47
|
export const GRADER_CAP_USD = 0.5;
|
|
48
|
+
/** The most characters an llm grader's prompt takes (about 30k tokens, under GRADER_CAP_USD at $15 per million input
|
|
49
|
+
* tokens): past it, its calls and a fake MCP server's calls share what is left, each list cut in proportion to its
|
|
50
|
+
* size, the middle of the longest results (or arguments) first, then the middle calls (fitCalls). The rubric, the task
|
|
51
|
+
* and the answer are never cut: they are what the grader judges, so a prompt can pass the cap by what they hold alone,
|
|
52
|
+
* and then the calls are cut to a note that says so. */
|
|
53
|
+
export const GRADER_PROMPT_MAX = 120_000;
|
|
39
54
|
/** How long one run may take before the eval cancels it and fails it. */
|
|
40
55
|
export const RUN_TIMEOUT_MS = 30 * 60_000;
|
|
41
56
|
/** How long a run may stay queued, no runner having taken it, before the eval stops waiting on it: it fails by that
|
|
42
57
|
* name, its state when the wait gave up, never by the run's whole timeout. */
|
|
43
58
|
export const QUEUE_TIMEOUT_MS = 2 * 60_000;
|
|
44
59
|
export const GRADER_NAME = "Template eval grader";
|
|
60
|
+
/** The folder under TMPDIR where local evals keep the one install of each harness's pin they all share. */
|
|
61
|
+
export const EVAL_HARNESSES = "agentrun-eval-harnesses";
|
|
62
|
+
/** An owner's data folder is the eval's own server's to open (EvalOptions.data): a named server keeps its own. */
|
|
63
|
+
export const ON_DATA_WITH_SERVER = "--on-data is the data folder of the eval's own server, and --server names another server: give one of them";
|
|
45
64
|
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
46
65
|
const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
|
|
47
|
-
const CASE_FIELDS = ["parameters", "grants", "mcp", "learning"];
|
|
66
|
+
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email"];
|
|
48
67
|
const GRADER_FIELDS = {
|
|
49
68
|
llm: ["type", "target"],
|
|
50
69
|
regex: ["type", "pattern", "flags", "expect", "target"],
|
|
51
|
-
tool_used: ["type", "tool", "tools", "expect", "count", "args"],
|
|
70
|
+
tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "args"],
|
|
52
71
|
file_exists: ["type", "path"],
|
|
72
|
+
mailbox: ["type", "message_id", "in", "not_in"],
|
|
53
73
|
};
|
|
54
74
|
/** A target: a field of the answer's JSON, dotted for a nested one. */
|
|
55
75
|
const TARGET = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
@@ -58,6 +78,8 @@ const ENDED = ["completed", "failed", "cancelled"];
|
|
|
58
78
|
const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule each fake MCP server listens on loopback only, for a server on this machine
|
|
59
79
|
/** A host name on this machine: a case with fake MCP servers needs a server here, which reaches them on loopback. */
|
|
60
80
|
const LOOPBACK_HOST = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule a server on this machine reaches the fakes
|
|
81
|
+
/** A case's fields that the eval's own runner alone binds (EvalFakes), each with what it does: a named server refuses them. */
|
|
82
|
+
const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"]];
|
|
61
83
|
/** A case's run input: its prompt's body as content (none when empty), then its typed fields. */
|
|
62
84
|
export const runInput = (content, fields) => ({ ...(content ? { content } : {}), ...fields });
|
|
63
85
|
/** Cases that do not check: every problem, each naming its file. */
|
|
@@ -132,7 +154,19 @@ function fixtureOf(text, name, at, bad) {
|
|
|
132
154
|
return { server: value.server, description: value.description, tools };
|
|
133
155
|
}
|
|
134
156
|
/** A grader file checked, by its type's fields. */
|
|
135
|
-
function graderOf(p, file, text,
|
|
157
|
+
function graderOf(p, file, text, bad) {
|
|
158
|
+
const grader = graderOfType(p, file, text, bad);
|
|
159
|
+
const front = frontOf(text);
|
|
160
|
+
const layouts = grader && typeof front !== "string" ? front.data.layouts : undefined;
|
|
161
|
+
if (layouts === undefined || !grader)
|
|
162
|
+
return grader;
|
|
163
|
+
// Graded on the runs of these layouts of an email case alone (eval-mailbox.ts LAYOUTS), where a package's right
|
|
164
|
+
// behaviour differs by server: on the others it is not a grader of the run at all.
|
|
165
|
+
if (!Array.isArray(layouts) || !layouts.length || !layouts.every((l) => LAYOUTS.includes(l)) || new Set(layouts).size !== layouts.length)
|
|
166
|
+
return bad(`${file}: layouts is a list of ${LAYOUTS.join(" and ")}, each once`), undefined;
|
|
167
|
+
return { ...grader, layouts: layouts };
|
|
168
|
+
}
|
|
169
|
+
function graderOfType(p, file, text, bad) {
|
|
136
170
|
const front = frontOf(text);
|
|
137
171
|
if (typeof front === "string")
|
|
138
172
|
return bad(`${file}: ${front}`), undefined;
|
|
@@ -140,8 +174,10 @@ function graderOf(p, file, text, mcp, bad) {
|
|
|
140
174
|
const type = data.type;
|
|
141
175
|
if (typeof type !== "string" || !Object.hasOwn(GRADER_FIELDS, type))
|
|
142
176
|
return bad(`${file}: type is one of ${Object.keys(GRADER_FIELDS).join(", ")}`), undefined;
|
|
143
|
-
|
|
144
|
-
|
|
177
|
+
// Every grader may name the layouts it grades (graderOf); its own fields are its type's.
|
|
178
|
+
const fields = [...GRADER_FIELDS[type], "layouts"];
|
|
179
|
+
for (const field of unknown(data, fields))
|
|
180
|
+
bad(`${file}: a ${type} grader has no field ${field}: its fields are ${fields.join(", ")}`);
|
|
145
181
|
const target = data.target;
|
|
146
182
|
if (target !== undefined && !(typeof target === "string" && TARGET.test(target)))
|
|
147
183
|
bad(`${file}: target is a field of the answer's JSON (a.b for a nested one)`);
|
|
@@ -173,9 +209,21 @@ function graderOf(p, file, text, mcp, bad) {
|
|
|
173
209
|
if (!Array.isArray(tools) || !tools.length || !tools.every((t) => typeof t === "string") || (data.tool !== undefined && data.tools !== undefined))
|
|
174
210
|
return bad(`${file}: a tool_used grader names tool (one gate name) or tools (a list), not both`), undefined;
|
|
175
211
|
const listed = p.mcp.flatMap(({ toolkit, tools: names }) => names.map((name) => mcpToolName(toolkit, name)));
|
|
212
|
+
// A monid endpoint by the name the package grants it, as its calls are named on the timeline. A provider's wildcard
|
|
213
|
+
// is filled from monid's listing when the agent is saved, which is not read here: its endpoints are not known, and
|
|
214
|
+
// a misspelt one would pass not_called unseen, so a grader names an endpoint the package grants by name.
|
|
215
|
+
const endpoints = (p.tools ?? []).filter((tool) => monidNameOf(tool));
|
|
176
216
|
for (const tool of tools) {
|
|
177
|
-
if (
|
|
178
|
-
|
|
217
|
+
if (isMonidName(tool)) {
|
|
218
|
+
if (endpoints.includes(tool))
|
|
219
|
+
continue;
|
|
220
|
+
const provider = monidNameOf(tool)?.provider;
|
|
221
|
+
const wildcard = provider !== undefined && p.tools?.includes(`monid:${provider}/*`) ? `; monid:${provider}/* grants its endpoints by monid's listing when the agent is saved, which is not read here: grant ${tool} by name` : "";
|
|
222
|
+
bad(`${file}: ${tool} is not a monid endpoint the package grants by name (it grants ${endpoints.join(", ") || "none"})${wildcard}`);
|
|
223
|
+
}
|
|
224
|
+
else if (mcpNameOf(tool) ? !listed.includes(tool) : !(BOUND_TOOLS.includes(tool) || tool === ASK_TOOL)) {
|
|
225
|
+
bad(`${file}: ${tool} is neither a tool this server binds, an MCP tool the package lists (mcp:<toolkit>/<tool>) nor a monid endpoint it grants by name (monid:<provider>/<endpoint>)`);
|
|
226
|
+
}
|
|
179
227
|
}
|
|
180
228
|
const expect = data.expect ?? "called";
|
|
181
229
|
if (expect !== "called" && expect !== "not_called")
|
|
@@ -185,20 +233,38 @@ function graderOf(p, file, text, mcp, bad) {
|
|
|
185
233
|
return bad(`${file}: count is a whole number of calls, 0 or more`), undefined;
|
|
186
234
|
if (count !== undefined && ((data.expect === "called" && count === 0) || (expect === "not_called" && count > 0)))
|
|
187
235
|
bad(`${file}: expect ${expect} and count ${count} say different things`);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
236
|
+
// at_least: that many matching calls or more (a run that searched once more than the case needs still passes).
|
|
237
|
+
const atLeast = data.at_least;
|
|
238
|
+
if (atLeast !== undefined && !(Number.isSafeInteger(atLeast) && atLeast >= 1))
|
|
239
|
+
return bad(`${file}: at_least is a whole number of calls, 1 or more`), undefined;
|
|
240
|
+
if (atLeast !== undefined && count !== undefined)
|
|
241
|
+
return bad(`${file}: count is an exact number of calls and at_least a least one: give one, not both`), undefined;
|
|
242
|
+
if (atLeast !== undefined && expect === "not_called")
|
|
243
|
+
bad(`${file}: expect not_called and at_least ${atLeast} say different things`);
|
|
244
|
+
// Any call's arguments are known: a faked MCP tool's from its fake's log, any other's from the run's timeline read
|
|
245
|
+
// with calls=whole (each string through the run's redaction and cut at CAPS.text).
|
|
246
|
+
if (data.args !== undefined && !isObject(data.args))
|
|
247
|
+
bad(`${file}: args is a mapping of the arguments a call must carry`);
|
|
248
|
+
return { file, type, tools: tools, expect, ...(count !== undefined ? { count: count } : {}), ...(atLeast !== undefined ? { atLeast: atLeast } : {}), ...(isObject(data.args) ? { args: data.args } : {}) };
|
|
197
249
|
}
|
|
198
250
|
case "file_exists":
|
|
199
251
|
if (typeof data.path !== "string" || !data.path.trim() || data.path.startsWith("/") || data.path.split("/").includes(".."))
|
|
200
252
|
return bad(`${file}: a file_exists grader names a path in the run's work folder`), undefined;
|
|
201
253
|
return { file, type, path: data.path.replace(/^\.\//, "") };
|
|
254
|
+
case "mailbox": {
|
|
255
|
+
// Where one message of the case's fake mailbox is after the run: in a mailbox (or under a Gmail label), in none of some.
|
|
256
|
+
const notIn = data.not_in ?? [];
|
|
257
|
+
const named = (name) => typeof name === "string" && name.trim() !== "";
|
|
258
|
+
if (typeof data.message_id !== "string" || !/^<[^<>\s]+>$/.test(data.message_id))
|
|
259
|
+
return bad(`${file}: a mailbox grader names a message_id in angle brackets, <id@host>`), undefined;
|
|
260
|
+
if (data.in !== undefined && !named(data.in))
|
|
261
|
+
return bad(`${file}: in is a mailbox's name (INBOX, Drafts, Sent, a folder or a label)`), undefined;
|
|
262
|
+
if (!Array.isArray(notIn) || !notIn.every(named))
|
|
263
|
+
return bad(`${file}: not_in is a list of mailboxes' names`), undefined;
|
|
264
|
+
if (data.in === undefined && !notIn.length)
|
|
265
|
+
return bad(`${file}: a mailbox grader says where the message is (in) or is not (not_in)`), undefined;
|
|
266
|
+
return { file, type, messageId: data.message_id, ...(typeof data.in === "string" ? { in: data.in } : {}), notIn: notIn };
|
|
267
|
+
}
|
|
202
268
|
}
|
|
203
269
|
return undefined;
|
|
204
270
|
}
|
|
@@ -230,8 +296,6 @@ export function readCases(dir, names) {
|
|
|
230
296
|
// as the server checks a run's, so a case the agent's schema refuses fails here, before any run.
|
|
231
297
|
const body = typeof prompt === "string" ? "" : prompt.body.trim();
|
|
232
298
|
const fields = f.input === undefined ? undefined : isObject(f.input) && !Object.hasOwn(f.input, "content") ? f.input : (bad(`${at}/prompt.md: input is a mapping of the run's typed input, by field (the body is its content)`), undefined);
|
|
233
|
-
for (const issue of inputIssues(runInput(body, fields), inputSchemaOf(pkg.inputSchema)))
|
|
234
|
-
bad(`${at}/prompt.md: ${issue.message}`);
|
|
235
299
|
// The Input: block is the server's, made from `input:` as for a run started through the API: never the body's own.
|
|
236
300
|
if (/^Input:[ \t]*\r?\n[ \t]*`{3,}/m.test(body))
|
|
237
301
|
bad(`${at}/prompt.md: its body holds an Input: block, which the server writes from input: (the front matter): give the fields there`);
|
|
@@ -239,10 +303,16 @@ export function readCases(dir, names) {
|
|
|
239
303
|
const c = typeof spec === "string" ? (bad(`${at}/case.yaml: ${spec}`), {}) : isObject(spec) ? spec : (bad(`${at}/case.yaml: is not a mapping`), {});
|
|
240
304
|
for (const field of unknown(c, CASE_FIELDS))
|
|
241
305
|
bad(`${at}/case.yaml: no field ${field}: its fields are ${CASE_FIELDS.join(", ")}`);
|
|
306
|
+
// An email case's run is on its trigger's input, and its prompt gives none (`email` below holds it to that).
|
|
307
|
+
if (c.email === undefined)
|
|
308
|
+
for (const issue of inputIssues(runInput(body, fields), inputSchemaOf(pkg.inputSchema)))
|
|
309
|
+
bad(`${at}/prompt.md: ${issue.message}`);
|
|
242
310
|
if (c.parameters !== undefined && !isObject(c.parameters))
|
|
243
311
|
bad(`${at}/case.yaml: parameters is a mapping, the apply's parameters`);
|
|
244
312
|
if (c.grants !== undefined && !(Array.isArray(c.grants) && c.grants.every((g) => typeof g === "string")))
|
|
245
313
|
bad(`${at}/case.yaml: grants is a list of gate names (mcp:<server>/<tool>)`);
|
|
314
|
+
if (c.now !== undefined && instantOf(c.now) === undefined)
|
|
315
|
+
bad(`${at}/case.yaml: now is a date and time with its offset (2026-11-14T09:00:00Z), not ${JSON.stringify(c.now)}`);
|
|
246
316
|
const parameters = isObject(c.parameters) ? c.parameters : {};
|
|
247
317
|
const grants = Array.isArray(c.grants) ? c.grants : [];
|
|
248
318
|
// The apply's own check of its body, here: a parameter or grant it would refuse fails the case before any run.
|
|
@@ -280,6 +350,75 @@ export function readCases(dir, names) {
|
|
|
280
350
|
if (server !== undefined && mcp[server] && !Object.hasOwn(mcp[server].tools, tool))
|
|
281
351
|
bad(`${at}/case.yaml: grants ${grant}, a tool the fake ${server} does not serve`);
|
|
282
352
|
}
|
|
353
|
+
// The case's web fake: every web call failing (`unavailable`), or a fixture file of the case (web-fake.ts).
|
|
354
|
+
let web;
|
|
355
|
+
if (c.web !== undefined) {
|
|
356
|
+
const path = c.web === "unavailable" ? undefined : inside(root, c.web, "file");
|
|
357
|
+
// Only a package that names a web tool has one: one that names no tools gets its computer's shell tools, or none.
|
|
358
|
+
if (!pkg.tools?.includes(WEB_SEARCH_TOOL) && !pkg.tools?.includes(WEB_FETCH_TOOL))
|
|
359
|
+
bad(`${at}/case.yaml: web fakes web_search and web_fetch, and the package's tools name neither`);
|
|
360
|
+
else if (c.web === "unavailable")
|
|
361
|
+
web = "unavailable";
|
|
362
|
+
else if (!path)
|
|
363
|
+
bad(`${at}/case.yaml: web is unavailable, or a fixture file in the case (not ${JSON.stringify(c.web)})`);
|
|
364
|
+
else {
|
|
365
|
+
let parsed;
|
|
366
|
+
try {
|
|
367
|
+
parsed = JSON.parse(readFileSync(join(root, path), "utf8"));
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
bad(`${at}/${path}: is not JSON (${error.message})`);
|
|
371
|
+
}
|
|
372
|
+
if (parsed !== undefined)
|
|
373
|
+
web = webFixtureOf(parsed, `${at}/${path}`, bad);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// The case's monid fake: every call of the package's monid endpoints unsent, monid unreachable (runner/monid-run.ts).
|
|
377
|
+
let monid;
|
|
378
|
+
if (c.monid !== undefined) {
|
|
379
|
+
const kind = (tool) => parseToolName(tool)?.kind;
|
|
380
|
+
if (c.monid !== "unavailable")
|
|
381
|
+
bad(`${at}/case.yaml: monid is unavailable (not ${JSON.stringify(c.monid)})`);
|
|
382
|
+
else if (!(pkg.tools ?? []).some((tool) => kind(tool) === "monid" || kind(tool) === "monid-provider"))
|
|
383
|
+
bad(`${at}/case.yaml: monid fakes the package's monid endpoints, and it grants none`);
|
|
384
|
+
else
|
|
385
|
+
monid = "unavailable";
|
|
386
|
+
}
|
|
387
|
+
// The case's fake mailbox: its fixture, and the package's trigger its runs start from (eval-mailbox.ts).
|
|
388
|
+
let email;
|
|
389
|
+
if (c.email !== undefined) {
|
|
390
|
+
const path = inside(root, c.email, "file");
|
|
391
|
+
let parsed;
|
|
392
|
+
if (!path)
|
|
393
|
+
bad(`${at}/case.yaml: email is a mailbox fixture file in the case (not ${JSON.stringify(c.email)})`);
|
|
394
|
+
else {
|
|
395
|
+
try {
|
|
396
|
+
parsed = JSON.parse(readFileSync(join(root, path), "utf8"));
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
bad(`${at}/${path}: is not JSON (${error.message})`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const fixture = parsed === undefined ? undefined : mailboxFixtureOf(parsed, `${at}/${path}`, bad);
|
|
403
|
+
if (!(pkg.tools ?? []).some((tool) => EMAIL_TOOLS.includes(tool)))
|
|
404
|
+
bad(`${at}/case.yaml: email fakes the server's email account, and the package's tools name no email tool`);
|
|
405
|
+
// A run with a new message is the email trigger's firing on it; one without, the schedule's.
|
|
406
|
+
const kind = fixture?.message ? "email" : "schedule";
|
|
407
|
+
const kindOf = (t) => (isObject(t.source) ? t.source.kind : undefined);
|
|
408
|
+
const named = fixture?.trigger === undefined ? undefined : pkg.triggers.find((t) => t.name === fixture.trigger);
|
|
409
|
+
const starts = named ? [named] : pkg.triggers.filter((t) => kindOf(t) === kind);
|
|
410
|
+
if (!fixture)
|
|
411
|
+
undefined;
|
|
412
|
+
else if (fixture.trigger !== undefined && !named)
|
|
413
|
+
bad(`${at}/${path}: trigger ${fixture.trigger} is not one of the package's triggers (${pkg.triggers.map((t) => String(t.name)).join(", ") || "none"})`);
|
|
414
|
+
else if (starts.length !== 1 || kindOf(starts[0]) !== kind)
|
|
415
|
+
bad(`${at}/${path}: ${fixture.message ? "a fixture with a new message starts its run through the package's email trigger" : "a fixture with no new message starts its run as the package's schedule"}, and ${named ? `${fixture.trigger} is a ${String(kindOf(named))} trigger` : starts.length ? `the package has ${starts.length}: name one with trigger` : "the package has none"}`);
|
|
416
|
+
else
|
|
417
|
+
email = { ...fixture, trigger: String(starts[0].name) };
|
|
418
|
+
// Its run is the trigger's, on the trigger's input and cap: the prompt gives neither.
|
|
419
|
+
if (body || fields || f.max_cost_usd !== undefined)
|
|
420
|
+
bad(`${at}/prompt.md: an email case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
|
|
421
|
+
}
|
|
283
422
|
const learning = [];
|
|
284
423
|
if (c.learning !== undefined) {
|
|
285
424
|
const folder = inside(root, c.learning, "dir");
|
|
@@ -309,8 +448,15 @@ export function readCases(dir, names) {
|
|
|
309
448
|
for (const entry of readdirSync(join(root, "graders"), { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
310
449
|
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
311
450
|
continue;
|
|
312
|
-
const grader = graderOf(pkg, `${at}/graders/${entry.name}`, readFileSync(join(root, "graders", entry.name), "utf8"),
|
|
313
|
-
|
|
451
|
+
const grader = graderOf(pkg, `${at}/graders/${entry.name}`, readFileSync(join(root, "graders", entry.name), "utf8"), bad);
|
|
452
|
+
const unrun = grader?.layouts?.filter((layout) => email && !email.layouts.includes(layout)) ?? [];
|
|
453
|
+
if (grader?.type === "mailbox" && c.email === undefined)
|
|
454
|
+
bad(`${at}/graders/${entry.name}: a mailbox grader reads the case's fake mailbox, and the case has no email`);
|
|
455
|
+
else if (grader?.layouts && c.email === undefined)
|
|
456
|
+
bad(`${at}/graders/${entry.name}: layouts grades the runs of an email case's layouts, and the case has no email`);
|
|
457
|
+
else if (unrun.length)
|
|
458
|
+
bad(`${at}/graders/${entry.name}: layouts names ${unrun.join(", ")}, which the case's fixture does not run on (${email.layouts.join(", ")})`);
|
|
459
|
+
else if (grader)
|
|
314
460
|
graders.push({ ...grader, file: entry.name });
|
|
315
461
|
}
|
|
316
462
|
if (problems.length > before)
|
|
@@ -318,7 +464,7 @@ export function readCases(dir, names) {
|
|
|
318
464
|
cases.push({
|
|
319
465
|
name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
|
|
320
466
|
...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
|
|
321
|
-
parameters, grants, mcp, learning, graders,
|
|
467
|
+
parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}),
|
|
322
468
|
});
|
|
323
469
|
}
|
|
324
470
|
if (problems.length)
|
|
@@ -437,7 +583,8 @@ export function gradeDeterministic(grader, run, faked) {
|
|
|
437
583
|
return { pass, reason: pass ? `the run's work folder holds ${grader.path}` : `the run's work folder has no ${grader.path}${run.files.length ? ` (it holds ${run.files.slice(0, 10).join(", ")}${run.files.length > 10 ? ", ..." : ""})` : " (it holds no file)"}` };
|
|
438
584
|
}
|
|
439
585
|
case "tool_used": {
|
|
440
|
-
// A faked MCP tool's calls are its fake's log (each call that reached it, whole); any other tool's, the timeline's
|
|
586
|
+
// A faked MCP tool's calls are its fake's log (each call that reached it, whole); any other tool's, the timeline's,
|
|
587
|
+
// its arguments as the run's redaction shows them (callsOf).
|
|
441
588
|
const calls = grader.tools.flatMap((tool) => {
|
|
442
589
|
const server = mcpNameOf(tool)?.server;
|
|
443
590
|
const from = server !== undefined && faked.includes(server) ? run.mcpCalls : run.calls;
|
|
@@ -447,9 +594,13 @@ export function gradeDeterministic(grader, run, faked) {
|
|
|
447
594
|
const said = `${calls.length} call${calls.length === 1 ? "" : "s"} of ${what}`;
|
|
448
595
|
if (grader.count !== undefined)
|
|
449
596
|
return { pass: calls.length === grader.count, reason: `${said}; the grader expects exactly ${grader.count}` };
|
|
597
|
+
if (grader.atLeast !== undefined)
|
|
598
|
+
return { pass: calls.length >= grader.atLeast, reason: `${said}; the grader expects at least ${grader.atLeast}` };
|
|
450
599
|
const pass = grader.expect === "called" ? calls.length > 0 : calls.length === 0;
|
|
451
600
|
return { pass, reason: `${said}; the grader expects ${grader.expect === "called" ? "at least one" : "none"}` };
|
|
452
601
|
}
|
|
602
|
+
case "mailbox":
|
|
603
|
+
return run.mailbox ? mailboxVerdict(run.mailbox, grader.messageId, grader.in, grader.notIn) : { pass: false, reason: "the run has no fake mailbox to read" };
|
|
453
604
|
}
|
|
454
605
|
}
|
|
455
606
|
/** The output check of a completed run of a package that declares `output`, beside its case's graders: the server's own
|
|
@@ -461,20 +612,112 @@ export function outputVerdict(pkg, result) {
|
|
|
461
612
|
const why = isObject(result) && typeof result.output_error === "string" ? result.output_error : undefined;
|
|
462
613
|
return { grader: "output", type: "output", cost_usd: null, pass: why === undefined, reason: why === undefined ? `the answer's json meets ${pkg.output.schema}` : `the answer misses ${pkg.output.schema}: ${why}` };
|
|
463
614
|
}
|
|
464
|
-
/** The input a grader run gets for an llm grader: the rubric, the run
|
|
465
|
-
*
|
|
466
|
-
|
|
615
|
+
/** The input a grader run gets for an llm grader: the rubric, the clock the run ran on when its case set one (the grader's
|
|
616
|
+
* own run is on the real clock), the run's input, its answer (its target field marked when the grader names one), its
|
|
617
|
+
* calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
|
|
618
|
+
export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
467
619
|
const target = grader.target ? targetOf(run.answer, grader.target) : undefined;
|
|
468
|
-
const
|
|
469
|
-
|
|
620
|
+
const at = run.now === undefined ? undefined : instantOf(run.now);
|
|
621
|
+
const before = [
|
|
470
622
|
"Grade this run against the rubric.",
|
|
471
623
|
`<rubric>\n${grader.rubric}\n</rubric>`,
|
|
624
|
+
...(at === undefined ? [] : [`The run ran on a clock set to ${run.now}: its date was ${dayIn(new Date(at), serverZone())} (${serverZone()}), whatever today's date is where you are.`]),
|
|
472
625
|
`<task untrusted>\n${input}\n</task>`,
|
|
473
626
|
`<answer untrusted>\n${run.answer || "(the run gave no answer)"}\n</answer>`,
|
|
474
627
|
...(grader.target ? [`The rubric is about the answer's \`${grader.target}\`${target && "text" in target ? ", shown here; the whole answer is above for anything else it checks" : ""}.`, `<target field="${grader.target}" untrusted>\n${target && "text" in target ? target.text : `(${target.why})`}\n</target>`] : []),
|
|
475
|
-
|
|
476
|
-
...(run.
|
|
477
|
-
]
|
|
628
|
+
// What the run did to its fake mailbox: the messages it added (a draft, a copy in Sent), moved or labelled, and sent.
|
|
629
|
+
...(run.mailbox ? [`<mailbox-after untrusted>\nThe run's email account was a fake mailbox (layout ${run.mailbox.after.layout}). What the run left in it:\n${mailboxText(run.mailbox.after)}\n</mailbox-after>`] : []),
|
|
630
|
+
];
|
|
631
|
+
// Each call with its arguments (else its input's preview), its status and its output's head.
|
|
632
|
+
const lines = run.calls.map((call, i) => ({
|
|
633
|
+
head: `${i + 1}. ${call.tool}${call.arguments ? ` ${JSON.stringify(call.arguments)}` : call.preview ? ` (${call.preview})` : ""}${call.status ? ` -> ${call.status}` : ""}`,
|
|
634
|
+
result: call.result ?? "",
|
|
635
|
+
tool: call.name ?? call.tool,
|
|
636
|
+
}));
|
|
637
|
+
// Each call a fake MCP server received, its arguments whole in its log: they are the part a cut may take.
|
|
638
|
+
const mcpLines = run.mcpCalls.map((call, i) => ({ head: `${i + 1}. ${call.tool}`, result: JSON.stringify(call.arguments ?? {}) }));
|
|
639
|
+
const wrap = (text) => `<tool-calls untrusted>\n${text}\n</tool-calls>`;
|
|
640
|
+
const wrapMcp = (text) => `<mcp-calls untrusted>\nThe calls the MCP servers received, with their arguments, in order:\n${text}\n</mcp-calls>`;
|
|
641
|
+
// A run that searched or fetched: each link its answer cites, matched against its web calls' urls in code (link-check.ts).
|
|
642
|
+
const links = linkCheck(run.answer, run.calls);
|
|
643
|
+
const linked = links === undefined ? [] : [`<link-check untrusted>\n${links}\n</link-check>`];
|
|
644
|
+
// Both lists share the room the rubric, the task, the answer and the link check leave, each in proportion to its whole size.
|
|
645
|
+
const room = max - [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
|
|
646
|
+
const wholeOf = (list) => list.reduce((sum, one) => sum + one.head.length + one.result.length + 3, 0);
|
|
647
|
+
const [callsWhole, mcpWhole] = [wholeOf(lines), wholeOf(mcpLines)];
|
|
648
|
+
const mcpRoom = callsWhole + mcpWhole <= room ? mcpWhole : Math.floor((room * mcpWhole) / Math.max(1, callsWhole + mcpWhole));
|
|
649
|
+
const after = mcpLines.length ? [wrapMcp(fitCalls(mcpLines, mcpRoom, "argument list"))] : [];
|
|
650
|
+
return [...before, wrap(lines.length ? fitCalls(lines, room - mcpRoom) : "(none)"), ...linked, ...after].join("\n\n");
|
|
651
|
+
}
|
|
652
|
+
/** A grader's calls, one line each (`head`, then `: <result>`), in at most `room` characters: whole when they fit; else
|
|
653
|
+
* each result past a length L keeps its first two thirds and last third of L with its middle cut and marked, L the
|
|
654
|
+
* longest that fits, a web call's (`tool`, web-calls.ts) every url whole and each of its snippets or its page's text cut
|
|
655
|
+
* to L; else, when the web calls' url lists alone pass the room, every other result cut to nothing and each url list
|
|
656
|
+
* keeping its head and tail as a result does; else, every result cut to nothing, the middle calls dropped and marked. A
|
|
657
|
+
* cut says so on the list's first line, so the grader knows what it does not see; `what` names what follows each head
|
|
658
|
+
* there (a fake MCP server's list cuts a call's arguments). */
|
|
659
|
+
export function fitCalls(lines, room, what = "result") {
|
|
660
|
+
const line = (head, result) => (result ? `${head}: ${result}` : head);
|
|
661
|
+
const whole = lines.map((one) => line(one.head, one.result)).join("\n");
|
|
662
|
+
if (whole.length <= room)
|
|
663
|
+
return whole;
|
|
664
|
+
const said = (cut) => `(Cut to keep this prompt under its cap: ${cut}.)`;
|
|
665
|
+
const middle = (text, keep) => {
|
|
666
|
+
if (text.length <= keep)
|
|
667
|
+
return text;
|
|
668
|
+
const marker = ` [... ${text.length - keep} characters cut ...] `;
|
|
669
|
+
const tail = Math.floor(keep / 3);
|
|
670
|
+
return `${text.slice(0, keep - tail)}${marker}${text.slice(text.length - tail)}`;
|
|
671
|
+
};
|
|
672
|
+
const webs = lines.map((one) => (one.tool ? webShownOf(one.tool, one.result) : undefined));
|
|
673
|
+
const LONG = said(`each long ${what} keeps its head and tail, its middle cut where marked${webs.some(Boolean) ? "; a web_search keeps every result's url, title and date, and a web_fetch its url and title, their snippets and page text cut" : ""}`);
|
|
674
|
+
// What a result cut to `keep` adds to its line, ": " included: the marker a cut adds is at most 40 characters, counted
|
|
675
|
+
// on every result `keep` cuts.
|
|
676
|
+
const cutTo = (text, keep) => (text.length > keep ? keep + 42 : text ? text.length + 2 : 0);
|
|
677
|
+
const high = Math.max(...lines.map((one) => one.result.length));
|
|
678
|
+
const longest = (size) => {
|
|
679
|
+
let [low, top] = [0, high];
|
|
680
|
+
while (low < top) {
|
|
681
|
+
const mid = Math.ceil((low + top) / 2);
|
|
682
|
+
if (size(mid) <= room)
|
|
683
|
+
low = mid;
|
|
684
|
+
else
|
|
685
|
+
top = mid - 1;
|
|
686
|
+
}
|
|
687
|
+
return low;
|
|
688
|
+
};
|
|
689
|
+
// A web call's line is measured as it is shown.
|
|
690
|
+
const size = (keep) => LONG.length + 1 + lines.reduce((sum, one, i) => sum + (webs[i] ? line(one.head, webs[i](keep)).length : one.head.length + cutTo(one.result, keep)) + 1, 0);
|
|
691
|
+
if (size(0) <= room) {
|
|
692
|
+
const keep = longest(size);
|
|
693
|
+
return [LONG, ...lines.map((one, i) => line(one.head, webs[i] ? webs[i](keep) : middle(one.result, keep)))].join("\n");
|
|
694
|
+
}
|
|
695
|
+
// The web calls' url lists alone pass the room: every other result is left out, and each list keeps its head and tail.
|
|
696
|
+
if (webs.some(Boolean)) {
|
|
697
|
+
const OVER = said(`the web calls' url lists alone pass it, so every other ${what} is left out, and each url list keeps its head and tail, its middle cut where marked`);
|
|
698
|
+
const lists = webs.map((web) => web?.(0) ?? "");
|
|
699
|
+
const over = (keep) => OVER.length + 1 + lines.reduce((sum, one, i) => sum + one.head.length + cutTo(lists[i], keep) + 1, 0);
|
|
700
|
+
if (over(0) <= room) {
|
|
701
|
+
const keep = longest(over);
|
|
702
|
+
return [OVER, ...lines.map((one, i) => line(one.head, lists[i] ? middle(lists[i], keep) : ""))].join("\n");
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
// Not even every call's head fits: the first and last calls, as many as fit, with no result, the middle ones dropped.
|
|
706
|
+
const heads = lines.map((one) => one.head);
|
|
707
|
+
const kept = [[], []];
|
|
708
|
+
let used = 200;
|
|
709
|
+
for (let i = 0, j = heads.length - 1; i <= j;) {
|
|
710
|
+
const next = kept[0].length <= kept[1].length ? heads[i] : heads[j];
|
|
711
|
+
if (used + next.length + 1 > room)
|
|
712
|
+
break;
|
|
713
|
+
used += next.length + 1;
|
|
714
|
+
if (kept[0].length <= kept[1].length)
|
|
715
|
+
kept[0].push(heads[i++]);
|
|
716
|
+
else
|
|
717
|
+
kept[1].unshift(heads[j--]);
|
|
718
|
+
}
|
|
719
|
+
const dropped = heads.length - kept[0].length - kept[1].length;
|
|
720
|
+
return [said(`every ${what} is left out, and ${dropped} call${dropped === 1 ? "" : "s"} in the middle`), ...kept[0], `[... ${dropped} call${dropped === 1 ? "" : "s"} cut ...]`, ...kept[1]].join("\n");
|
|
478
721
|
}
|
|
479
722
|
/** A grader run's answer read as its verdict: the last json block's (else the last JSON object's) {pass, reason}. */
|
|
480
723
|
export function verdictOf(answer) {
|
|
@@ -548,9 +791,14 @@ async function bytesOf(req) {
|
|
|
548
791
|
function apiOf(baseUrl, token) {
|
|
549
792
|
return async (method, path, body, headers = {}, options = {}) => {
|
|
550
793
|
const raw = typeof body === "string";
|
|
794
|
+
// The console's page takes a write from its session only with a JSON body type, a body or not (page.ts answerPage):
|
|
795
|
+
// a bodiless DELETE from the session without it is refused (401), so it goes with it too.
|
|
796
|
+
const session = Boolean(headers.cookie) && method !== "GET" && method !== "HEAD";
|
|
797
|
+
const type = body === undefined ? (session ? "application/json" : undefined) : raw ? "text/markdown" : "application/json";
|
|
551
798
|
const res = await fetch(`${baseUrl}${path}`, {
|
|
552
799
|
method,
|
|
553
|
-
|
|
800
|
+
// A request made from the console's session (its cookie) goes without the token, which would make it the token's.
|
|
801
|
+
headers: { ...(headers.cookie ? {} : { authorization: `Bearer ${token}` }), ...(type ? { "content-type": type } : {}), ...headers },
|
|
554
802
|
...(body === undefined ? {} : { body: raw ? body : JSON.stringify(body) }),
|
|
555
803
|
...(options.signal ? { signal: options.signal } : {}),
|
|
556
804
|
}).catch((error) => {
|
|
@@ -594,7 +842,8 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
594
842
|
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
595
843
|
signal.throwIfAborted();
|
|
596
844
|
}
|
|
597
|
-
|
|
845
|
+
// calls=whole: each call's arguments and its output's head (tool_input, tool_result_text), which its graders read.
|
|
846
|
+
const page = expectOk(`reading run ${runId}'s timeline`, await api("GET", `/runs/${runId}/timeline?after=${after}&wait_ms=5000&calls=whole`));
|
|
598
847
|
if (page.reset)
|
|
599
848
|
view.clear();
|
|
600
849
|
for (const id of page.drop ?? [])
|
|
@@ -622,18 +871,19 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
622
871
|
await sleep(250);
|
|
623
872
|
}
|
|
624
873
|
}
|
|
625
|
-
/** The calls in a run's rows: each tool_use row by its gate name, with its result's status and preview. */
|
|
626
874
|
/** A run's tool calls, each named as a grader names it: the gate's own rule (RunGate.enter), its settings key, but a
|
|
627
875
|
* shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
|
|
628
876
|
* call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
|
|
629
|
-
* under another name) is named on the package's toolkit, as the package's graders name it.
|
|
630
|
-
|
|
877
|
+
* under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
|
|
878
|
+
* its output's head as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
|
|
879
|
+
export function callsOf(rows, harness, toolkits = {}) {
|
|
631
880
|
const results = new Map(rows.filter((row) => row.kind === "tool_result" && row.tool_use_id).map((row) => [String(row.tool_use_id), row]));
|
|
632
881
|
return rows.filter((row) => row.kind === "tool_use" && typeof row.tool_name === "string").map((row) => {
|
|
633
882
|
const name = row.tool_name;
|
|
634
883
|
const result = results.get(String(row.tool_use_id));
|
|
635
|
-
const key = settingsKeyOf(harness, name
|
|
636
|
-
|
|
884
|
+
const key = settingsKeyOf(harness, name);
|
|
885
|
+
const output = typeof result?.tool_result_text === "string" ? result.tool_result_text : (result?.tool_result_preview ?? null);
|
|
886
|
+
return { tool: shellToolOf(name) ?? (key === undefined ? undefined : onServerName(key, toolkits)) ?? name, name, preview: row.tool_input_preview ?? null, ...(isObject(row.tool_input) ? { arguments: row.tool_input } : {}), status: result?.tool_status ?? null, result: output };
|
|
637
887
|
});
|
|
638
888
|
}
|
|
639
889
|
/** Every file path of a run's work folder (the files route, page by page). */
|
|
@@ -696,26 +946,60 @@ export function v2Base(url) {
|
|
|
696
946
|
* case that does not check throws (PackageError, CaseError) before anything runs. */
|
|
697
947
|
export async function evalTemplate(options) {
|
|
698
948
|
const log = options.log ?? (() => undefined);
|
|
949
|
+
if (options.data !== undefined && options.server)
|
|
950
|
+
throw new Error(ON_DATA_WITH_SERVER);
|
|
699
951
|
const { pkg, cases } = readCases(options.dir, options.cases);
|
|
700
952
|
if (options.graderModel !== undefined && !MODEL_REF.test(options.graderModel))
|
|
701
953
|
throw new CaseError(options.dir, [`--grader-model is "provider/model-id", not ${options.graderModel}`]);
|
|
954
|
+
// A case's fakes are bound by the eval's own runner, in this process: a named server's runs would search the real web,
|
|
955
|
+
// run on its real clock and call monid for real.
|
|
956
|
+
const refused = options.server ? cases.flatMap((one) => OWN_SERVER_FAKES.filter(([field]) => one[field] !== undefined).map(([, what]) => `evals/${one.name}: ${what} on the eval's own server alone: run it without --server`)) : [];
|
|
957
|
+
if (refused.length)
|
|
958
|
+
throw new CaseError(options.dir, refused);
|
|
959
|
+
// Each run's fakes, by the agent the eval made for it (runOnce), which the runner beside the server reads at the claim.
|
|
960
|
+
const fakes = new Map();
|
|
961
|
+
const clock = !options.server && cases.some((one) => one.email) ? evalClock() : undefined;
|
|
702
962
|
const started = new Date().toISOString();
|
|
703
963
|
const scratch = options.server ? undefined : mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), "agentrun-eval-"));
|
|
964
|
+
// The in-process server's data: the owner's folder (options.data), which stays, or one in the scratch, gone with it.
|
|
965
|
+
const data = options.server ? undefined : (options.data ?? join(scratch, "data"));
|
|
704
966
|
let close = async () => undefined;
|
|
705
967
|
let api;
|
|
968
|
+
let owner;
|
|
706
969
|
if (options.server)
|
|
707
970
|
api = apiOf(v2Base(options.server.baseUrl), options.server.token);
|
|
708
971
|
else {
|
|
709
972
|
// The package alone in a templates folder of its own, so the server applies exactly this folder, on a data
|
|
710
973
|
// directory of its own, gone when the eval is.
|
|
711
974
|
cpSync(options.dir, join(scratch, "templates", pkg.name), { recursive: true });
|
|
975
|
+
// The owner's folder with work of its own is refused before anything runs: the eval's server would start its enabled
|
|
976
|
+
// triggers and its runner would claim its runs not ended, out of the eval's report and cleanup, on a model or a faux.
|
|
977
|
+
if (options.data !== undefined) {
|
|
978
|
+
const work = await workOf(options.data).catch((error) => (removeTree(scratch), Promise.reject(error)));
|
|
979
|
+
if (work) {
|
|
980
|
+
removeTree(scratch);
|
|
981
|
+
throw new Error(`the server on ${options.data} has work of its own: ${work}, which the eval's server and runner would take up: disable its triggers and let its runs and learning batches end (or stop them), then run the eval; or run it without --on-data`);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
712
984
|
const { startServe } = await import("./server.js");
|
|
985
|
+
// Claude Code and Codex installed once for every local eval under this TMPDIR, not into each eval's data: the
|
|
986
|
+
// data's harnesses are links to that one install (harness-install.ts sharedInstaller).
|
|
987
|
+
const { sharedInstaller } = await import("./harness-install.js");
|
|
988
|
+
const harnessInstall = sharedInstaller(join(process.env.TMPDIR ?? tmpdir(), EVAL_HARNESSES));
|
|
713
989
|
// A local install by construction: its own scratch server, reached on loopback, its fake MCP servers there too.
|
|
714
990
|
// Its fakes stand in for the package's MCP needs (mcpStandIns): each is saved as the source and toolkit it fakes.
|
|
715
|
-
|
|
991
|
+
// A token of its own on a scratch folder. On the owner's folder none is given: a given token makes the server remove
|
|
992
|
+
// the folder's .token (server.ts), the owner's saved API token, so the eval's server reads the one the folder keeps,
|
|
993
|
+
// and a .token it had to make there (the folder had none) goes when it closes, the folder as it was.
|
|
994
|
+
const serve = await startServe({ mcpLoopback: true, mcpStandIns: true, data: data, port: 0, ...(options.data === undefined ? { token: randomBytes(24).toString("base64url") } : {}), templates: join(scratch, "templates"), drainTimeout: "5s", harnessInstall, ...(options.serve ?? {}), ...(clock ? { triggerClock: clock } : {}) }).catch((error) => {
|
|
716
995
|
removeTree(scratch);
|
|
717
996
|
throw error;
|
|
718
997
|
});
|
|
998
|
+
const closeServe = async () => {
|
|
999
|
+
await serve.close();
|
|
1000
|
+
if (options.data !== undefined && serve.tokenMade && serve.tokenFile)
|
|
1001
|
+
rmSync(serve.tokenFile, { force: true });
|
|
1002
|
+
};
|
|
719
1003
|
// A runner beside it on the same data (the CLI start's server-and-runner, runner/beside.ts): a server alone takes runs
|
|
720
1004
|
// and leaves them queued, since on the one store a runner claims and runs each. Its runs' environment is this
|
|
721
1005
|
// process's, with the server's faux when the eval gave one (server.ts fauxEnvOf), so a faux eval never reaches a model.
|
|
@@ -724,26 +1008,51 @@ export async function evalTemplate(options) {
|
|
|
724
1008
|
const { withoutFaux } = await import("./model.js");
|
|
725
1009
|
const serveOptions = options.serve ?? {};
|
|
726
1010
|
// Its run lines go to stderr: stdout is the eval's report.
|
|
727
|
-
const beside = await runnerBeside(
|
|
728
|
-
await
|
|
1011
|
+
const beside = await runnerBeside(data, { mcpLoopback: serve.localInstall, evalFakes: (agentId) => fakes.get(agentId), harnessInstall, onLine: (line) => console.error(line), ...(serveOptions.faux ? { env: { ...withoutFaux(process.env), ...fauxEnvOf({ data: data, ...serveOptions }) } } : {}) }).catch(async (error) => {
|
|
1012
|
+
await closeServe();
|
|
729
1013
|
removeTree(scratch);
|
|
730
1014
|
throw error;
|
|
731
1015
|
});
|
|
732
1016
|
close = async () => {
|
|
733
1017
|
await beside.close();
|
|
734
|
-
await
|
|
1018
|
+
await closeServe();
|
|
735
1019
|
};
|
|
736
1020
|
api = apiOf(serve.baseUrl, serve.token);
|
|
1021
|
+
// An email case saves its fake mailbox as the server's email account, a secret write, which the API token never
|
|
1022
|
+
// makes: the eval owns its own scratch server, so it opens that server's console from its launch link, as the owner
|
|
1023
|
+
// who started it would, and makes those writes from that session.
|
|
1024
|
+
if (clock && serve.launchCode) {
|
|
1025
|
+
const origin = new URL(serve.baseUrl).origin;
|
|
1026
|
+
const opened = await fetch(`${origin}/?launch=${encodeURIComponent(serve.launchCode)}`, { redirect: "manual" }).catch(() => undefined);
|
|
1027
|
+
const cookie = opened?.headers.getSetCookie().map((line) => line.split(";")[0]).join("; ");
|
|
1028
|
+
await opened?.body?.cancel().catch(() => undefined);
|
|
1029
|
+
if (cookie)
|
|
1030
|
+
owner = { cookie, origin };
|
|
1031
|
+
}
|
|
1032
|
+
// On the owner's folder, an email case's fake mailbox would replace the account its server keeps (one account, saved
|
|
1033
|
+
// and removed per run): refused before anything runs, the account as it was.
|
|
1034
|
+
if (clock && options.data !== undefined) {
|
|
1035
|
+
const kept = await api("GET", "/settings/email", undefined, owner).catch(() => undefined);
|
|
1036
|
+
const address = kept?.status === 200 && isObject(kept.body) ? kept.body.address : undefined;
|
|
1037
|
+
if (typeof address === "string" || kept?.status !== 200) {
|
|
1038
|
+
await close();
|
|
1039
|
+
removeTree(scratch);
|
|
1040
|
+
throw new Error(typeof address === "string"
|
|
1041
|
+
? `the server on ${options.data} keeps an email account (${address}), and an email case saves its fake mailbox as the server's account in its place: remove it (DELETE /v2/settings/email), run the eval, and save it again; or run the eval without --on-data`
|
|
1042
|
+
: `the server on ${options.data} did not say whether it keeps an email account (GET /settings/email ${kept?.status ?? "failed"}), which an email case's fake mailbox would replace: nothing ran`);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
737
1045
|
}
|
|
738
1046
|
const results = [];
|
|
739
1047
|
let grader;
|
|
740
1048
|
const made = { agents: [], runs: new Set(), triggers: new Set() };
|
|
741
1049
|
const ctx = {
|
|
742
|
-
api, pkg, options, made, log,
|
|
1050
|
+
api, pkg, options, made, log, fakes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}),
|
|
743
1051
|
graderAgent: async () => {
|
|
744
1052
|
if (grader)
|
|
745
1053
|
return grader;
|
|
746
|
-
|
|
1054
|
+
// No computer: a grader reads, it never runs a command, and a server with no sandbox would fail its run at the start.
|
|
1055
|
+
const agent = expectOk("making the grader agent", await api("POST", "/agents", { definition: { version: 1, name: GRADER_NAME, description: "Grades a template eval's runs against a rubric: answers {pass, reason}.", instructions: GRADER_INSTRUCTIONS, skills: [], tools: [], computer: { kind: "none" }, learning: false, max_cost_usd: GRADER_CAP_USD, ...(options.graderModel ? { model: options.graderModel } : {}) } }));
|
|
747
1056
|
grader = String(agent.agent_id);
|
|
748
1057
|
made.agents.push(grader);
|
|
749
1058
|
return grader;
|
|
@@ -761,7 +1070,7 @@ export async function evalTemplate(options) {
|
|
|
761
1070
|
finally {
|
|
762
1071
|
await cleanUp(api, made);
|
|
763
1072
|
// On an owner's server, what the eval made goes to the archive (an archived agent and its runs stay readable).
|
|
764
|
-
if (options.server)
|
|
1073
|
+
if (options.server || options.data !== undefined)
|
|
765
1074
|
for (const id of made.agents)
|
|
766
1075
|
await api("POST", `/agents/${encodeURIComponent(id)}/archive`, {}).catch(() => undefined);
|
|
767
1076
|
await close();
|
|
@@ -777,7 +1086,7 @@ export async function evalTemplate(options) {
|
|
|
777
1086
|
const graderCost = sum(graders.map((g) => g.cost_usd));
|
|
778
1087
|
return {
|
|
779
1088
|
package: { name: pkg.name, version: pkg.version, dir: options.dir },
|
|
780
|
-
server: options.server ? { kind: "remote", base_url: v2Base(options.server.baseUrl) } : { kind: "in_process" },
|
|
1089
|
+
server: options.server ? { kind: "remote", base_url: v2Base(options.server.baseUrl) } : { kind: "in_process", ...(options.data !== undefined ? { data: options.data } : {}) },
|
|
781
1090
|
grader_model: options.graderModel ?? null,
|
|
782
1091
|
approvals: { measured: "never", package: pkg.approvals ?? "ask" },
|
|
783
1092
|
started_at: started, finished_at: new Date().toISOString(),
|
|
@@ -793,14 +1102,16 @@ async function runCase(ctx, one) {
|
|
|
793
1102
|
const saved = [];
|
|
794
1103
|
const runs = [];
|
|
795
1104
|
const total = options.runs ?? one.runs;
|
|
1105
|
+
// A server an owner keeps (--server, or the owner's folder with --on-data): its MCP servers are the owner's.
|
|
1106
|
+
const owners = Boolean(options.server) || options.data !== undefined;
|
|
796
1107
|
try {
|
|
797
1108
|
for (const [name, fixture] of Object.entries(one.mcp)) {
|
|
798
1109
|
// A fake listens on this machine's loopback, which only a server on this machine reaches.
|
|
799
1110
|
if (options.server && !LOOPBACK_HOST.test(new URL(options.server.baseUrl).hostname))
|
|
800
1111
|
throw new ApiFailure(`the case fakes the MCP server ${name} on this machine's loopback, which the server at ${new URL(options.server.baseUrl).host} cannot reach: run it on a server on this machine`);
|
|
801
1112
|
// An owner's server keeps its own MCP servers: a case never replaces one, it fails instead.
|
|
802
|
-
if (
|
|
803
|
-
throw new ApiFailure(`the server already has an MCP server named ${name}, and the case would replace it with its fake: run the eval on its own server (no --server), or on one without ${name}`);
|
|
1113
|
+
if (owners && (await api("GET", `/settings/mcp-servers/${name}`)).status !== 404)
|
|
1114
|
+
throw new ApiFailure(`the server already has an MCP server named ${name}, and the case would replace it with its fake: run the eval on its own server (no --server, no --on-data), or on one without ${name}`);
|
|
804
1115
|
const need = ctx.pkg.mcp.find((one) => one.toolkit === name);
|
|
805
1116
|
// An owner's server records what made each server, so there a fake is only ever a url one with its toolkit: one
|
|
806
1117
|
// standing in for a Composio or GitHub need is the eval's own server's alone.
|
|
@@ -812,18 +1123,22 @@ async function runCase(ctx, one) {
|
|
|
812
1123
|
saved.push({ name, url: fake.url });
|
|
813
1124
|
// Another eval on the same server may have saved its own fake under the name meanwhile: then neither case's calls
|
|
814
1125
|
// can be told apart, and this one fails rather than run on a fake it does not own.
|
|
815
|
-
if (
|
|
1126
|
+
if (owners && !(await ownsFake(api, name, fake.url)))
|
|
816
1127
|
throw new ApiFailure(`another eval saved its own MCP server named ${name} on this server meanwhile: run one eval of this package at a time on a server`);
|
|
817
1128
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1129
|
+
// An email case's runs repeat on each of its mailbox's layouts, each run on a fake account of its own.
|
|
1130
|
+
const layouts = one.email ? one.email.layouts : [undefined];
|
|
1131
|
+
for (const layout of layouts) {
|
|
1132
|
+
for (let n = 1; n <= total; n++) {
|
|
1133
|
+
options.signal?.throwIfAborted();
|
|
1134
|
+
for (const fake of fakes)
|
|
1135
|
+
fake.calls.length = 0;
|
|
1136
|
+
const result = layout ? await mailRun(ctx, one, n, fakes, layout) : await runOnce(ctx, one, n, fakes);
|
|
1137
|
+
log(`case ${one.name} run ${n}${layout ? ` (${layout})` : ""}: ${result.status}, ${result.pass ? "pass" : "FAIL"}${result.cost_usd === null ? "" : ` (${usd(result.cost_usd)})`}`);
|
|
1138
|
+
runs.push(result);
|
|
1139
|
+
}
|
|
825
1140
|
}
|
|
826
|
-
return { name: one.name, description: one.description, pass: runs.length === total && runs.every((r) => r.pass), runs, cost_usd: caseCost(runs) };
|
|
1141
|
+
return { name: one.name, description: one.description, pass: runs.length === total * layouts.length && runs.every((r) => r.pass), runs, cost_usd: caseCost(runs) };
|
|
827
1142
|
}
|
|
828
1143
|
catch (error) {
|
|
829
1144
|
if (!(error instanceof ApiFailure))
|
|
@@ -839,18 +1154,116 @@ async function runCase(ctx, one) {
|
|
|
839
1154
|
await api("DELETE", `/settings/mcp-servers/${name}`).catch(() => undefined);
|
|
840
1155
|
for (const fake of fakes)
|
|
841
1156
|
await fake.close();
|
|
1157
|
+
// The eval's own server's email account was the last run's fake mailbox, gone with it.
|
|
1158
|
+
// A removal that fails is said: on an owner's folder the fake would stay as their account.
|
|
1159
|
+
if (one.email) {
|
|
1160
|
+
const removed = await api("DELETE", "/settings/email", undefined, ctx.owner).catch((error) => ({ status: 0, body: error.message }));
|
|
1161
|
+
if (removed.status !== 204 && removed.status !== 404)
|
|
1162
|
+
ctx.log(`case ${one.name}: the server's email account (the case's fake mailbox) was not removed: DELETE /settings/email ${removed.status} ${JSON.stringify(removed.body).slice(0, 200)}`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
/** What the stopped server on `data` would do on its own once started, said ("1 enabled trigger, 2 runs not ended"), or
|
|
1167
|
+
* undefined when nothing: its enabled triggers and its runs not ended. Opened as its server opens it, so a folder another
|
|
1168
|
+
* server holds is refused here with the store's own words. */
|
|
1169
|
+
async function workOf(data) {
|
|
1170
|
+
const { openStore } = await import("./store/open.js");
|
|
1171
|
+
const store = await openStore({ dataDir: data, role: "server" });
|
|
1172
|
+
try {
|
|
1173
|
+
const triggers = (await store.triggers.all()).filter((one) => one.enabled && !one.disabled).length;
|
|
1174
|
+
// The runs not ended a list shows, and every run a runner would claim: the list leaves out built-in learning runs
|
|
1175
|
+
// (a kept learning's), which the eval's runner claims as any other.
|
|
1176
|
+
const runs = new Set();
|
|
1177
|
+
for (const state of ["queued", "running", "parked"])
|
|
1178
|
+
for (const run of await store.runs.list({ state }))
|
|
1179
|
+
runs.add(run.id);
|
|
1180
|
+
for (const id of await store.runs.claimable())
|
|
1181
|
+
runs.add(id);
|
|
1182
|
+
// A learning batch still running, which the eval's server would resume at its start (learning-batch.ts resume), its
|
|
1183
|
+
// next rows' runs with it.
|
|
1184
|
+
const batches = (await store.settings.all()).filter(({ key, value }) => /^learning_batch\/lb_[0-9a-f]{16}$/.test(key) && isObject(value) && value.status === "running").length;
|
|
1185
|
+
const said = [triggers ? `${triggers} enabled trigger${triggers === 1 ? "" : "s"}` : "", runs.size ? `${runs.size} run${runs.size === 1 ? "" : "s"} not ended` : "", batches ? `${batches} learning batch${batches === 1 ? "" : "es"} running` : ""].filter(Boolean);
|
|
1186
|
+
return said.length ? said.join(", ") : undefined;
|
|
1187
|
+
}
|
|
1188
|
+
finally {
|
|
1189
|
+
await store.close();
|
|
842
1190
|
}
|
|
843
1191
|
}
|
|
844
1192
|
/** Whether the server's MCP server `name` is still this eval's fake at `url`. */
|
|
845
1193
|
const ownsFake = (api, name, url) => api("GET", `/settings/mcp-servers/${name}`).then((read) => read.status === 200 && isObject(read.body) && read.body.url === shownUrl(url), () => false);
|
|
846
1194
|
const caseCost = (runs) => Math.round(runs.reduce((sum, r) => sum + (r.cost_usd ?? 0) + r.graders.reduce((g, x) => g + (x.cost_usd ?? 0), 0), 0) * 1e6) / 1e6;
|
|
847
|
-
/** One run of
|
|
848
|
-
|
|
1195
|
+
/** One run of an email case on `layout`: a fresh fake account seeded from the case's mailbox, saved as the server's email
|
|
1196
|
+
* account, the run started as the package's trigger starts it (runOnce), then the account closed: runs never share one. */
|
|
1197
|
+
async function mailRun(ctx, one, n, fakes, layout) {
|
|
1198
|
+
const fixture = one.email;
|
|
1199
|
+
const faux = await seededFaux(fixture, layout, one.now !== undefined ? new Date(instantOf(one.now)) : undefined);
|
|
1200
|
+
try {
|
|
1201
|
+
// Plaintext, which the server allows only to a mail server on this machine's loopback, where the fake listens.
|
|
1202
|
+
expectOk("saving the case's fake mailbox as the server's email account", await ctx.api("PUT", "/settings/email", { preset: "other", address: fixture.account.address, user: faux.user, password: faux.password, imap: faux.imap, smtp: faux.smtp }, ctx.owner));
|
|
1203
|
+
return { ...(await runOnce(ctx, one, n, fakes, { faux, layout })), layout };
|
|
1204
|
+
}
|
|
1205
|
+
finally {
|
|
1206
|
+
await faux.close();
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
/** The run of an email case's trigger on `mail`: its first poll waited on at the apply, on the account as seeded (the history),
|
|
1210
|
+
* then the case's new message delivered, and the trigger's own next time come on the eval's clock, so its poll (or its
|
|
1211
|
+
* schedule) fires through the engine's path; the run is its firing's. */
|
|
1212
|
+
async function triggerRun(ctx, one, agentId, triggerId, mail) {
|
|
1213
|
+
const { api, options } = ctx;
|
|
1214
|
+
const fixture = one.email;
|
|
1215
|
+
const read = () => api("GET", `/triggers/${encodeURIComponent(triggerId)}`).then((answered) => expectOk(`reading the package's trigger ${fixture.trigger}`, answered));
|
|
1216
|
+
const firings = async () => expectOk(`reading the firings of ${fixture.trigger}`, await api("GET", `/triggers/${encodeURIComponent(triggerId)}/firings`)).firings ?? [];
|
|
1217
|
+
const known = new Set((await firings()).map((f) => String(f.key)));
|
|
1218
|
+
const trigger = await read();
|
|
1219
|
+
// The new message arrives where the trigger watches: its source's mailbox (INBOX by default).
|
|
1220
|
+
const watched = isObject(trigger.source) && typeof trigger.source.mailbox === "string" ? trigger.source.mailbox : "INBOX";
|
|
1221
|
+
if (fixture.message)
|
|
1222
|
+
seed(mail.faux, mail.layout, watched, fixture.message);
|
|
1223
|
+
// What the account holds before the run: what it adds or moves is read against this.
|
|
1224
|
+
const before = snapshot(mail.faux);
|
|
1225
|
+
if (typeof trigger.next_at !== "string")
|
|
1226
|
+
throw new ApiFailure(`the package's trigger ${fixture.trigger} has no next time to fire at${isObject(trigger.disabled) ? ` (it is off: ${String(trigger.disabled.detail ?? trigger.disabled.reason)})` : ""}`);
|
|
1227
|
+
ctx.clock.to(Date.parse(trigger.next_at));
|
|
1228
|
+
const deadline = Date.now() + (options.queueTimeoutMs ?? QUEUE_TIMEOUT_MS);
|
|
1229
|
+
for (;;) {
|
|
1230
|
+
options.signal?.throwIfAborted();
|
|
1231
|
+
const fresh = (await firings()).filter((f) => !known.has(String(f.key)));
|
|
1232
|
+
const started = fresh.find((f) => typeof f.run_id === "string");
|
|
1233
|
+
if (started) {
|
|
1234
|
+
ctx.made.runs.add(String(started.run_id));
|
|
1235
|
+
// Off at once, before the run is waited on or graded: a repeating schedule (or a second message) would start
|
|
1236
|
+
// another paid run on the same fake account, which no report counts and which changes what the graders read.
|
|
1237
|
+
expectOk(`turning off the package's trigger ${fixture.trigger} after its run started`, await api("PATCH", `/triggers/${encodeURIComponent(triggerId)}`, { enabled: false }));
|
|
1238
|
+
return { runId: String(started.run_id), before };
|
|
1239
|
+
}
|
|
1240
|
+
const failed = fresh.find((f) => f.status === "failed");
|
|
1241
|
+
if (failed)
|
|
1242
|
+
throw new ApiFailure(`the package's trigger ${fixture.trigger} fired and its run was refused: ${String(failed.error ?? "no reason given")}`);
|
|
1243
|
+
if (Date.now() > deadline) {
|
|
1244
|
+
const last = (await read()).last_check;
|
|
1245
|
+
const check = isObject(last) ? last : undefined;
|
|
1246
|
+
const said = fresh.flatMap((f) => (typeof f.reason === "string" ? [f.reason] : []));
|
|
1247
|
+
throw new ApiFailure(`the package's trigger ${fixture.trigger} started no run of ${agentId} within ${Math.round((options.queueTimeoutMs ?? QUEUE_TIMEOUT_MS) / 1000)} s of its time${check ? `; its last check: ${String(check.message)}` : ""}${said.length ? `; its firings: ${said.join(" ")}` : ""}${fixture.message ? " (its accept rules may leave the case's message)" : ""}`);
|
|
1248
|
+
}
|
|
1249
|
+
await sleep(200);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
/** One run of a case: a fresh agent (so one run's learning never reaches the next), its notes, the run, its grades. An
|
|
1253
|
+
* email case's run (`mail`) is its trigger's (triggerRun). */
|
|
1254
|
+
async function runOnce(ctx, one, n, fakes, mail) {
|
|
849
1255
|
const { api, pkg, options, made } = ctx;
|
|
850
1256
|
const stopped = () => options.signal?.throwIfAborted();
|
|
851
1257
|
await serverPins(ctx, one);
|
|
852
1258
|
// Each faked toolkit on its fake, by name: never on a server of the same toolkit the owner saved.
|
|
853
1259
|
const servers = Object.fromEntries(fakes.map((fake) => [fake.name, fake.name]));
|
|
1260
|
+
// An email case with a clock of its own: the trigger clock goes to the case's `now` before the apply makes the trigger
|
|
1261
|
+
// (and before it is turned on), so its next time, and the run's "Started by ... for <time>" line, is the case's date on
|
|
1262
|
+
// every run. Left where the run before took it, a schedule's next time is a later day each run, with no mail of the case.
|
|
1263
|
+
// A millisecond before it: a schedule's next time is strictly after the clock, so a case whose `now` is the schedule's
|
|
1264
|
+
// own time (an evening digest's 18:00) fires for that time, not the next day's.
|
|
1265
|
+
if (mail && one.now !== undefined)
|
|
1266
|
+
ctx.clock?.set(instantOf(one.now) - 1);
|
|
854
1267
|
// Approvals never, for the eval's own agent only: a run that stopped at its first ask would measure nothing. The
|
|
855
1268
|
// package's default (ask, say, for a template whose tools cost money) is the owner's at install, and stays as it is;
|
|
856
1269
|
// the report says how it was measured.
|
|
@@ -859,9 +1272,19 @@ async function runOnce(ctx, one, n, fakes) {
|
|
|
859
1272
|
made.agents.push(agentId);
|
|
860
1273
|
// An eval's agent runs only the eval's runs: the package's triggers (a weekly schedule, say) would start paid runs of
|
|
861
1274
|
// their own, into the fakes' logs, and outlive the eval. Each one the apply made is deleted at once.
|
|
862
|
-
|
|
863
|
-
|
|
1275
|
+
// An email case's run is its one trigger's (readCases chose it): that one stays, until the run is read.
|
|
1276
|
+
let kept;
|
|
1277
|
+
for (const id of Array.isArray(applied.trigger_ids) ? applied.trigger_ids.map(String) : []) {
|
|
1278
|
+
if (mail && !kept && expectOk(`reading the package's trigger ${id}`, await api("GET", `/triggers/${encodeURIComponent(id)}`)).name === one.email.trigger)
|
|
1279
|
+
kept = id;
|
|
1280
|
+
else
|
|
1281
|
+
made.triggers.add(id);
|
|
1282
|
+
}
|
|
864
1283
|
await deleteTriggers(api, made, true);
|
|
1284
|
+
if (mail && !kept)
|
|
1285
|
+
throw new ApiFailure(`the apply made no trigger named ${one.email.trigger}`);
|
|
1286
|
+
if (kept)
|
|
1287
|
+
made.triggers.add(kept);
|
|
865
1288
|
const agent = expectOk(`reading the agent ${agentId}`, await api("GET", `/agents/${encodeURIComponent(agentId)}`));
|
|
866
1289
|
// The saved server the apply gave each need ({toolkit: server}; null for a need it left unset).
|
|
867
1290
|
const used = Object.fromEntries(Object.entries(isObject(applied.servers) ? applied.servers : {}).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -871,11 +1294,24 @@ async function runOnce(ctx, one, n, fakes) {
|
|
|
871
1294
|
expectOk(`seeding the note ${note.file}`, await api("PUT", `/agents/${encodeURIComponent(agentId)}/learning/files/${encodeURIComponent(note.file)}`, note.text, { "if-none-match": "*" }));
|
|
872
1295
|
}
|
|
873
1296
|
stopped();
|
|
874
|
-
|
|
1297
|
+
// The case's fakes, for this run's agent alone, before its run can be claimed.
|
|
1298
|
+
ctx.fakes.set(agentId, { ...(one.web !== undefined ? { web: one.web } : {}), ...(one.now !== undefined ? { now: new Date(instantOf(one.now)) } : {}), ...(one.monid !== undefined ? { monid: one.monid } : {}), ...(mail ? { email: { imap: mail.faux.imap, smtp: mail.faux.smtp, kind: mail.layout } } : {}) });
|
|
1299
|
+
let runId;
|
|
1300
|
+
let after;
|
|
1301
|
+
if (mail && kept) {
|
|
1302
|
+
// A trigger the package ships off is turned on for the eval's run: its start is taken then, on the history.
|
|
1303
|
+
if (expectOk(`reading the package's trigger ${one.email.trigger}`, await api("GET", `/triggers/${encodeURIComponent(kept)}`)).enabled !== true)
|
|
1304
|
+
expectOk(`turning on the package's trigger ${one.email.trigger}`, await api("PATCH", `/triggers/${encodeURIComponent(kept)}`, { enabled: true }));
|
|
1305
|
+
const started = await triggerRun(ctx, one, agentId, kept, mail);
|
|
1306
|
+
runId = started.runId;
|
|
1307
|
+
after = () => mailboxAfter(mail.faux, mail.layout, started.before);
|
|
1308
|
+
}
|
|
1309
|
+
else
|
|
1310
|
+
runId = await startRun(ctx, agentId, { input: runInput(one.input, one.fields), ...(one.maxCostUsd !== undefined ? { max_cost_usd: one.maxCostUsd } : {}) }, "starting the run");
|
|
875
1311
|
// A run started is paid for: whatever fails after this (a read, a grade) still gives it a result, with its cost where
|
|
876
1312
|
// the server says it, so the case's total never drops it.
|
|
877
1313
|
try {
|
|
878
|
-
return await ranOnce(ctx, one, n, fakes, agent, agentId, runId, used);
|
|
1314
|
+
return await ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, after);
|
|
879
1315
|
}
|
|
880
1316
|
catch (error) {
|
|
881
1317
|
if (!(error instanceof ApiFailure))
|
|
@@ -883,10 +1319,15 @@ async function runOnce(ctx, one, n, fakes) {
|
|
|
883
1319
|
const cost = await api("GET", `/runs/${runId}`).then((read) => (read.status === 200 && isObject(read.body) ? costOf(read.body) : null), () => null);
|
|
884
1320
|
return { run: n, agent_id: agentId, run_id: runId, status: "unknown", pass: false, error: `after the run started: ${error.message}`, cost_usd: cost, graders: [] };
|
|
885
1321
|
}
|
|
1322
|
+
finally {
|
|
1323
|
+
// Its trigger goes with its run: left, it would poll the next run's account.
|
|
1324
|
+
if (kept)
|
|
1325
|
+
await deleteTriggers(api, made);
|
|
1326
|
+
}
|
|
886
1327
|
}
|
|
887
1328
|
/** The started run `runId` of `agentId` waited on, read and graded; its calls on the saved servers `used` gave its needs
|
|
888
|
-
* ({toolkit: server}) named on the package's toolkits. */
|
|
889
|
-
async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used) {
|
|
1329
|
+
* ({toolkit: server}) named on the package's toolkits; an email run's fake mailbox read once it has ended (`after`). */
|
|
1330
|
+
async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, after) {
|
|
890
1331
|
const { api, options } = ctx;
|
|
891
1332
|
const stopped = () => options.signal?.throwIfAborted();
|
|
892
1333
|
const ended = await waitRun(api, runId, Date.now() + (options.runTimeoutMs ?? RUN_TIMEOUT_MS), options.signal, options.queueTimeoutMs);
|
|
@@ -895,21 +1336,26 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used) {
|
|
|
895
1336
|
await settle(ctx, runId, ended.status);
|
|
896
1337
|
// Its metrics once it has ended (a cancelled run's end writes them too), before the eval's server can go.
|
|
897
1338
|
const metrics = await metricsOf(api, agentId, options.signal);
|
|
1339
|
+
const mailbox = after ? await after() : undefined;
|
|
898
1340
|
stopped();
|
|
899
1341
|
const result = isObject(view.result) ? view.result : {};
|
|
900
1342
|
const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
|
|
901
1343
|
const record = {
|
|
902
1344
|
answer: typeof result.final_answer === "string" ? result.final_answer : "",
|
|
903
|
-
calls: callsOf(ended.rows, harness,
|
|
1345
|
+
calls: callsOf(ended.rows, harness, Object.fromEntries(Object.entries(used).map(([toolkit, server]) => [server, toolkit]))),
|
|
904
1346
|
mcpCalls: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))),
|
|
905
1347
|
files: await (async () => {
|
|
906
1348
|
const listed = await filesOf(api, runId);
|
|
907
1349
|
const named = one.graders.flatMap((grader) => (grader.type === "file_exists" ? [grader.path] : []));
|
|
908
1350
|
return [...listed, ...(await presentOf(api, runId, named.filter((path) => !listed.includes(path))))];
|
|
909
1351
|
})(),
|
|
1352
|
+
...(one.now !== undefined ? { now: one.now } : {}),
|
|
1353
|
+
...(mailbox ? { mailbox } : {}),
|
|
910
1354
|
};
|
|
911
1355
|
stopped();
|
|
912
|
-
const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics };
|
|
1356
|
+
const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}) };
|
|
1357
|
+
// The grader's task: the input the run was given, an email run's its trigger's (the payload in its tag).
|
|
1358
|
+
const task = after ? inputMessage(view.input ?? {}) : inputMessage(runInput(one.input, one.fields));
|
|
913
1359
|
// Waiting on its person's answer (an ask_person question, a tool call's approval) is where such a run stops, and is
|
|
914
1360
|
// graded; paused at its cap, or stopped, it did not get there.
|
|
915
1361
|
const pending = isObject(view.pending) && typeof view.pending.kind === "string" ? view.pending.kind : undefined;
|
|
@@ -924,6 +1370,9 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used) {
|
|
|
924
1370
|
const graders = output ? [output] : [];
|
|
925
1371
|
for (const grader of one.graders) {
|
|
926
1372
|
stopped();
|
|
1373
|
+
// A grader of some layouts is not one of a run on another.
|
|
1374
|
+
if (grader.layouts && !(record.mailbox && grader.layouts.includes(record.mailbox.after.layout)))
|
|
1375
|
+
continue;
|
|
927
1376
|
if (grader.type !== "llm") {
|
|
928
1377
|
graders.push({ grader: grader.file, type: grader.type, cost_usd: null, ...gradeDeterministic(grader, record, Object.keys(one.mcp)) });
|
|
929
1378
|
continue;
|
|
@@ -935,7 +1384,7 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used) {
|
|
|
935
1384
|
}
|
|
936
1385
|
// A grade that fails to read fails that grader alone: the run's own result and cost stay.
|
|
937
1386
|
try {
|
|
938
|
-
graders.push({ grader: grader.file, type: grader.type, ...(await gradeLlm(ctx, await ctx.graderAgent(), graderInput(grader,
|
|
1387
|
+
graders.push({ grader: grader.file, type: grader.type, ...(await gradeLlm(ctx, await ctx.graderAgent(), graderInput(grader, task, record))) });
|
|
939
1388
|
}
|
|
940
1389
|
catch (error) {
|
|
941
1390
|
if (!(error instanceof ApiFailure))
|
|
@@ -994,11 +1443,13 @@ async function sameAsLocal(ctx, one, agent, used) {
|
|
|
994
1443
|
}
|
|
995
1444
|
/** The pins a case's apply fills (from its parameters) set on the in-process server before it applies, as an owner sets
|
|
996
1445
|
* them (deploy/walk.md): the server's pin holds the call to the case's own target beside the agent's own, as it does in
|
|
997
|
-
* production. Another server's (--server) settings are its owner's, left as they are
|
|
998
|
-
* holds the write.
|
|
1446
|
+
* production. Another server's (--server) settings are its owner's, left as they are, and so are those of the owner's
|
|
1447
|
+
* folder (--on-data): there the agent's own pin alone holds the write. No permission is written on any: every eval
|
|
1448
|
+
* applies with approvals never (runOnce), so a granted tool runs with no one to answer and a tool the case did not grant
|
|
1449
|
+
* is refused. */
|
|
999
1450
|
async function serverPins(ctx, one) {
|
|
1000
1451
|
const { api, pkg, options } = ctx;
|
|
1001
|
-
if (options.server)
|
|
1452
|
+
if (options.server || options.data !== undefined)
|
|
1002
1453
|
return;
|
|
1003
1454
|
const { parameters } = applyBodyOf(pkg, { parameters: one.parameters, grants: one.grants });
|
|
1004
1455
|
// Each fake is saved under its toolkit's name, so the package's own tool names are the server's.
|
|
@@ -1085,6 +1536,12 @@ const cell = (text) => text.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
|
|
|
1085
1536
|
* any case failed, however many passed beside it. (2: nothing ran, and 130: stopped, are the CLI's own.) */
|
|
1086
1537
|
export const exitCodeOf = (report) => (report.cases.every((c) => c.pass) ? 0 : 1);
|
|
1087
1538
|
/** The report as markdown: a line per case, then each failure with every grader that failed and why. */
|
|
1539
|
+
/** A case's runs passed: "2/3", or per layout for an email case's ("gmail 2/3, folders 3/3"). */
|
|
1540
|
+
function passedOf(runs) {
|
|
1541
|
+
const count = (some) => `${some.filter((r) => r.pass).length}/${some.length}`;
|
|
1542
|
+
const layouts = [...new Set(runs.flatMap((r) => (r.layout ? [r.layout] : [])))];
|
|
1543
|
+
return layouts.length ? layouts.map((layout) => `${layout} ${count(runs.filter((r) => r.layout === layout))}`).join(", ") : count(runs);
|
|
1544
|
+
}
|
|
1088
1545
|
export function markdownReport(report) {
|
|
1089
1546
|
const lines = [
|
|
1090
1547
|
`# Evals: ${report.package.name} ${report.package.version}`,
|
|
@@ -1095,8 +1552,11 @@ export function markdownReport(report) {
|
|
|
1095
1552
|
"",
|
|
1096
1553
|
"| Case | Runs passed | Result | Cost |",
|
|
1097
1554
|
"|---|---|---|---|",
|
|
1098
|
-
...report.cases.map((c) => `| ${c.name} | ${c.runs
|
|
1555
|
+
...report.cases.map((c) => `| ${c.name} | ${passedOf(c.runs)} | ${c.pass ? "pass" : "**fail**"} | ${usd(c.cost_usd)} |`),
|
|
1099
1556
|
];
|
|
1557
|
+
// An email case's runs read a fake mailbox, never real mail: the report says so, and counts them per layout.
|
|
1558
|
+
if (report.cases.some((c) => c.runs.some((r) => r.layout)))
|
|
1559
|
+
lines.push("", "Email cases ran on a fake mailbox seeded from each case's fixture (no real mail was read or sent), each run on a fresh account, reported per layout.");
|
|
1100
1560
|
const failed = report.cases.filter((c) => !c.pass);
|
|
1101
1561
|
if (failed.length)
|
|
1102
1562
|
lines.push("", "## Failures");
|
|
@@ -1105,7 +1565,7 @@ export function markdownReport(report) {
|
|
|
1105
1565
|
if (c.error)
|
|
1106
1566
|
lines.push(`- ${cell(c.error)}`);
|
|
1107
1567
|
for (const run of c.runs.filter((r) => !r.pass)) {
|
|
1108
|
-
lines.push(`- run ${run.run}${run.run_id ? ` (${run.run_id})` : ""}: ${run.status}${run.error ? `: ${cell(run.error)}` : ""}`);
|
|
1568
|
+
lines.push(`- run ${run.run}${run.layout ? ` on ${run.layout}` : ""}${run.run_id ? ` (${run.run_id})` : ""}: ${run.status}${run.error ? `: ${cell(run.error)}` : ""}`);
|
|
1109
1569
|
for (const g of run.graders.filter((x) => !x.pass))
|
|
1110
1570
|
lines.push(` - ${g.grader} (${g.type}): ${cell(g.reason)}`);
|
|
1111
1571
|
}
|