@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.59
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 +376 -0
- package/README.md +393 -118
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +7 -5
- package/dist/box-paths.js +12 -8
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +121 -0
- package/dist/claude-login-token.js +797 -0
- package/dist/claude-login.d.ts +119 -34
- package/dist/claude-login.js +551 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +325 -328
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +40 -19
- package/dist/computer-attach.js +326 -62
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +12 -11
- package/dist/computers.js +11 -8
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +139 -5
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +13 -5
- package/dist/env-switch.js +24 -6
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +12 -4
- package/dist/fal-price.js +110 -26
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +173 -0
- package/dist/learn/ledger.js +225 -0
- package/dist/learn/promote.d.ts +82 -39
- package/dist/learn/promote.js +61 -66
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +40 -21
- package/dist/learning-cost.js +30 -21
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +9 -0
- package/dist/live-reach.js +9 -0
- package/dist/mcp-api-only-origins.d.ts +23 -3
- package/dist/mcp-api-only-origins.js +57 -17
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +234 -61
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +59 -34
- package/dist/place-offers.js +100 -58
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +5 -4
- package/dist/provider.js +26 -13
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +97 -63
- package/dist/runner/adapter-run-spec.d.ts +34 -14
- package/dist/runner/adapter-run-spec.js +120 -75
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +29 -13
- package/dist/runner/claim-secrets.d.ts +27 -18
- package/dist/runner/claim-secrets.js +61 -47
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +93 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +19 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +24 -18
- package/dist/runner/mcp-claim.js +24 -7
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +11 -4
- package/dist/runner/presence.js +11 -6
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +38 -12
- package/dist/runner/run-child-host.js +231 -83
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +5 -3
- package/dist/runner/runner.js +14 -10
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +138 -37
- package/dist/runner/workflow-first.js +230 -99
- package/dist/runner/workflow-spec.js +2 -2
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +33 -10
- package/dist/server.js +454 -136
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +44 -4
- package/dist/store/schema.js +111 -11
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +19 -2
- package/dist/store/sqlite/run-patch.js +67 -2
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +177 -32
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +74 -25
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +102 -136
- package/dist/store-reads/learning.js +251 -302
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +91 -9
- package/dist/template-eval.js +448 -105
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +14 -14
- package/dist/timeline/web-calls.js +18 -30
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.d.ts +4 -9
- package/dist/web-save.js +27 -55
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +38 -11
- package/dist/workspace/attached-computers.js +81 -16
- package/dist/workspace/computer-deps.d.ts +29 -7
- package/dist/workspace/computer-deps.js +36 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +166 -57
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +152 -0
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +25 -9
- package/dist/console/assets/backend-DVhHzJX2.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/template-eval.js
CHANGED
|
@@ -31,6 +31,9 @@ import { CALENDAR_EVENTS } from "./calendar/names.js";
|
|
|
31
31
|
import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
|
|
32
32
|
import { builtinHarness } from "./harness-table.js";
|
|
33
33
|
import { CALLS_PAGE_ROWS, webShownOf } from "./timeline/index.js";
|
|
34
|
+
/** The rows a calls=whole timeline page holds at most, the page size this eval reads with: learn-bench reads its steps'
|
|
35
|
+
* timelines the same way. */
|
|
36
|
+
export { CALLS_PAGE_ROWS };
|
|
34
37
|
import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
|
|
35
38
|
import { webFixtureOf } from "./web-fake.js";
|
|
36
39
|
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
@@ -41,6 +44,7 @@ import { instantOf } from "./trigger-adapter.js";
|
|
|
41
44
|
import { applyBodyOf, compiled, filledPins, filledSource, onServerName, onServers, packageView, readPackage } from "./templates.js";
|
|
42
45
|
import { INPUTS_DIR } from "./uploads.js";
|
|
43
46
|
import { inputIssues, inputSchemaOf, isObject, MODEL_REF } from "./validate.js";
|
|
47
|
+
import { RUN_FILE_CUT_MAX } from "./run-files.js";
|
|
44
48
|
/** What a grader run is told, whatever the rubric: blind, strict, and its verdict as one JSON block. */
|
|
45
49
|
export const GRADER_INSTRUCTIONS = `You grade one run of an AI agent against one rubric. You see the rubric, the task the agent was given, its answer, and the tool calls it made; nothing else, and nothing else matters.
|
|
46
50
|
|
|
@@ -53,8 +57,10 @@ End your reply with exactly one fenced json block and nothing after it:
|
|
|
53
57
|
/** Each grader run's cap, in dollars. */
|
|
54
58
|
export const GRADER_CAP_USD = 0.5;
|
|
55
59
|
/** The most characters an llm grader's prompt takes (about 30k tokens, under GRADER_CAP_USD at $15 per million input
|
|
56
|
-
* tokens): past it,
|
|
57
|
-
*
|
|
60
|
+
* tokens): past it, the final files take room first, never so much that the calls' arguments get less than half of it,
|
|
61
|
+
* the tool state's texts left out before a file of the run's own is cut (fitFiles); its calls and a fake MCP server's
|
|
62
|
+
* calls share what is left, each list cut in proportion to its size and the fake's given at least half, the middle of
|
|
63
|
+
* the longest results (or arguments) first, then the middle calls (fitCalls), and a <cuts> note counts it all. The rubric, the task
|
|
58
64
|
* and the answer are never cut: they are what the grader judges, so a prompt can pass the cap by what they hold alone,
|
|
59
65
|
* and then the calls are cut to a note that says so. */
|
|
60
66
|
export const GRADER_PROMPT_MAX = 120_000;
|
|
@@ -73,7 +79,7 @@ const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning",
|
|
|
73
79
|
const GRADER_FIELDS = {
|
|
74
80
|
llm: ["type", "target"],
|
|
75
81
|
regex: ["type", "pattern", "flags", "expect", "target"],
|
|
76
|
-
tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "args"],
|
|
82
|
+
tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "at_most", "args", "args_file"],
|
|
77
83
|
file_exists: ["type", "path"],
|
|
78
84
|
mailbox: ["type", "message_id", "in", "not_in"],
|
|
79
85
|
handed: ["type", "expect", "dropped"],
|
|
@@ -275,14 +281,34 @@ function graderOfType(p, file, text, bad) {
|
|
|
275
281
|
if (atLeast !== undefined && !(Number.isSafeInteger(atLeast) && atLeast >= 1))
|
|
276
282
|
return bad(`${file}: at_least is a whole number of calls, 1 or more`), undefined;
|
|
277
283
|
if (atLeast !== undefined && count !== undefined)
|
|
278
|
-
return bad(`${file}: count is an exact number of calls and at_least a
|
|
284
|
+
return bad(`${file}: count is an exact number of calls and at_least a lower bound: give one, not both`), undefined;
|
|
279
285
|
if (atLeast !== undefined && expect === "not_called")
|
|
280
286
|
bad(`${file}: expect not_called and at_least ${atLeast} say different things`);
|
|
287
|
+
// at_most: that many matching calls or fewer, and at least one (expect: called, as at_least), or at least at_least
|
|
288
|
+
// when both are given. None is expect: not_called's to say, so at_most is 1 or more.
|
|
289
|
+
const atMost = data.at_most;
|
|
290
|
+
if (atMost !== undefined && !(Number.isSafeInteger(atMost) && atMost >= 1))
|
|
291
|
+
return bad(`${file}: at_most is a whole number of calls, 1 or more (for none, say expect: not_called)`), undefined;
|
|
292
|
+
if (atMost !== undefined && count !== undefined)
|
|
293
|
+
return bad(`${file}: count is an exact number of calls and at_most an upper bound: give one, not both`), undefined;
|
|
294
|
+
if (atMost !== undefined && expect === "not_called")
|
|
295
|
+
bad(`${file}: expect not_called and at_most ${atMost} say different things`);
|
|
296
|
+
if (atMost !== undefined && atLeast !== undefined && atLeast > atMost)
|
|
297
|
+
bad(`${file}: at_least ${atLeast} and at_most ${atMost} leave no number of calls to pass`);
|
|
281
298
|
// 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
|
|
282
|
-
// with calls=whole (each string through the run's redaction and cut at
|
|
299
|
+
// with calls=whole (each string through the run's redaction and cut at CALL_RESULT_CHARS).
|
|
283
300
|
if (data.args !== undefined && !isObject(data.args))
|
|
284
301
|
bad(`${file}: args is a mapping of the arguments a call must carry`);
|
|
285
|
-
|
|
302
|
+
// args_file: a file the run writes, a JSON list of argument objects, each carried by its own call (the values a run
|
|
303
|
+
// computes, which a grader can't hold as literals). Its number of calls is the list's length, or count.
|
|
304
|
+
const argsFile = data.args_file;
|
|
305
|
+
if (argsFile !== undefined && (typeof argsFile !== "string" || !argsFile.trim() || argsFile.startsWith("/") || argsFile.split("/").includes("..")))
|
|
306
|
+
return bad(`${file}: args_file names a path in the run's work folder`), undefined;
|
|
307
|
+
if (argsFile !== undefined && expect === "not_called")
|
|
308
|
+
bad(`${file}: args_file lists the calls the run sends, and expect not_called says it sends none`);
|
|
309
|
+
if (argsFile !== undefined && (atLeast !== undefined || atMost !== undefined))
|
|
310
|
+
bad(`${file}: args_file's calls number its list's length (or count): at_least and at_most don't apply`);
|
|
311
|
+
return { file, type, tools: tools, expect, ...(count !== undefined ? { count: count } : {}), ...(atLeast !== undefined ? { atLeast: atLeast } : {}), ...(atMost !== undefined ? { atMost: atMost } : {}), ...(isObject(data.args) ? { args: data.args } : {}), ...(typeof argsFile === "string" ? { argsFile } : {}) };
|
|
286
312
|
}
|
|
287
313
|
case "file_exists":
|
|
288
314
|
if (typeof data.path !== "string" || !data.path.trim() || data.path.startsWith("/") || data.path.split("/").includes(".."))
|
|
@@ -634,6 +660,40 @@ const same = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical
|
|
|
634
660
|
const canonical = (value) => (Array.isArray(value) ? value.map(canonical) : isObject(value) ? Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])])) : value);
|
|
635
661
|
/** Whether `call` carries `args`: each key's value equal, an object's compared as a subset in turn. */
|
|
636
662
|
const carries = (call, args) => (isObject(args) ? isObject(call) && Object.entries(args).every(([key, value]) => Object.hasOwn(call, key) && carries(call[key], value)) : same(call, args));
|
|
663
|
+
/** What the run's cut writes in place of a secret's span in a file it serves (handed-values.ts). */
|
|
664
|
+
const CUT_MARK = "[redacted]";
|
|
665
|
+
/** Whether `text` is `entry` with each CUT_MARK standing for one character or more of it. A scan from the left, each
|
|
666
|
+
* part between marks placed at its first fit: linear in the text, so no list the run wrote can make it backtrack. */
|
|
667
|
+
const cutMatches = (text, entry) => {
|
|
668
|
+
const parts = entry.split(CUT_MARK);
|
|
669
|
+
const first = parts[0], last = parts[parts.length - 1];
|
|
670
|
+
if (!text.startsWith(first))
|
|
671
|
+
return false;
|
|
672
|
+
let at = first.length;
|
|
673
|
+
for (const part of parts.slice(1, -1)) {
|
|
674
|
+
const found = text.indexOf(part, at + 1);
|
|
675
|
+
if (found < 0)
|
|
676
|
+
return false;
|
|
677
|
+
at = found + part.length;
|
|
678
|
+
}
|
|
679
|
+
return text.length - last.length >= at + 1 && text.endsWith(last);
|
|
680
|
+
};
|
|
681
|
+
/** `same` for a value read under the run's cut: equal throughout, but a string of `entry` holding CUT_MARK is matched by
|
|
682
|
+
* cutMatches. Arrays and the objects inside them are whole, keys and length alike, as `same` compares them. */
|
|
683
|
+
const sameCut = (call, entry) => {
|
|
684
|
+
if (Array.isArray(entry))
|
|
685
|
+
return Array.isArray(call) && call.length === entry.length && entry.every((value, i) => sameCut(call[i], value));
|
|
686
|
+
if (isObject(entry))
|
|
687
|
+
return isObject(call) && Object.keys(call).length === Object.keys(entry).length && Object.entries(entry).every(([key, value]) => Object.hasOwn(call, key) && sameCut(call[key], value));
|
|
688
|
+
if (typeof entry === "string" && entry.includes(CUT_MARK))
|
|
689
|
+
return typeof call === "string" && cutMatches(call, entry);
|
|
690
|
+
return same(call, entry);
|
|
691
|
+
};
|
|
692
|
+
/** carries for an args_file entry, which is read under the run's cut while a fake's calls are whole: objects as subsets
|
|
693
|
+
* and everything else equal, as `carries`, except that a string of the entry holding CUT_MARK carries a call's string
|
|
694
|
+
* where each mark stands for one character or more (sameCut). So a call that sent a held secret still carries the entry
|
|
695
|
+
* that names it cut. Nothing of the call's value is said. */
|
|
696
|
+
const carriesCut = (call, entry) => isObject(entry) ? isObject(call) && Object.entries(entry).every(([key, value]) => Object.hasOwn(call, key) && carriesCut(call[key], value)) : sameCut(call, entry);
|
|
637
697
|
/** Whether `fixture`'s tool answers `args` with one of its answers (the first whose `when` matches), else its default. */
|
|
638
698
|
export function fakeAnswer(fixture, tool, args) {
|
|
639
699
|
const spec = fixture.tools[tool];
|
|
@@ -734,17 +794,23 @@ export function gradeDeterministic(grader, run, faked) {
|
|
|
734
794
|
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)"}` };
|
|
735
795
|
}
|
|
736
796
|
case "tool_used": {
|
|
737
|
-
// A faked MCP tool's calls are its fake's log (each call that reached it, whole); any other
|
|
738
|
-
// its arguments as the run's redaction shows them (callsOf).
|
|
797
|
+
// A faked MCP tool's calls are its fake's log (each call that reached it, whole: fakeLog, never shown); any other
|
|
798
|
+
// tool's, the timeline's, its arguments as the run's redaction shows them (callsOf).
|
|
739
799
|
const calls = grader.tools.flatMap((tool) => {
|
|
740
800
|
const server = mcpNameOf(tool)?.server;
|
|
741
|
-
const from = server !== undefined && faked.includes(server) ? run.
|
|
801
|
+
const from = server !== undefined && faked.includes(server) ? run.fakeLog : run.calls;
|
|
742
802
|
return from.filter((call) => call.tool === tool && (!grader.args || carries(call.arguments, grader.args)));
|
|
743
803
|
});
|
|
744
804
|
const what = `${grader.tools.join(" or ")}${grader.args ? ` with ${JSON.stringify(grader.args)}` : ""}`;
|
|
745
805
|
const said = `${calls.length} call${calls.length === 1 ? "" : "s"} of ${what}`;
|
|
806
|
+
if (grader.argsFile !== undefined)
|
|
807
|
+
return argsFileVerdict(grader.argsFile, run.argsFiles?.[grader.argsFile], calls, said, grader.count);
|
|
746
808
|
if (grader.count !== undefined)
|
|
747
809
|
return { pass: calls.length === grader.count, reason: `${said}; the grader expects exactly ${grader.count}` };
|
|
810
|
+
if (grader.atMost !== undefined) {
|
|
811
|
+
const least = grader.atLeast ?? 1;
|
|
812
|
+
return { pass: calls.length >= least && calls.length <= grader.atMost, reason: `${said}; the grader expects at least ${grader.atLeast ?? "one"} and at most ${grader.atMost}` };
|
|
813
|
+
}
|
|
748
814
|
if (grader.atLeast !== undefined)
|
|
749
815
|
return { pass: calls.length >= grader.atLeast, reason: `${said}; the grader expects at least ${grader.atLeast}` };
|
|
750
816
|
const pass = grader.expect === "called" ? calls.length > 0 : calls.length === 0;
|
|
@@ -756,6 +822,49 @@ export function gradeDeterministic(grader, run, faked) {
|
|
|
756
822
|
return handedVerdict(run.handed, grader.expect, grader.dropped);
|
|
757
823
|
}
|
|
758
824
|
}
|
|
825
|
+
/** A tool_used grader's verdict on its args_file: each listed argument object carried (carries) by its own call of
|
|
826
|
+
* `calls` (the grader's tools, its `args` kept), no call standing for two entries, and as many calls as the list has
|
|
827
|
+
* entries (or `count`). The entries are given calls by a maximum matching, so one call that carries two entries counts
|
|
828
|
+
* for one of them, whatever order they are listed in. */
|
|
829
|
+
export function argsFileVerdict(path, file, calls, said, count) {
|
|
830
|
+
if (file === undefined || "why" in file)
|
|
831
|
+
return { pass: false, reason: `the run's ${path} could not be read${file ? `: ${file.why}` : ""}` };
|
|
832
|
+
let entries;
|
|
833
|
+
try {
|
|
834
|
+
entries = JSON.parse(file.text);
|
|
835
|
+
}
|
|
836
|
+
catch (error) {
|
|
837
|
+
return { pass: false, reason: `the run's ${path} is not JSON: ${error.message}` };
|
|
838
|
+
}
|
|
839
|
+
if (!Array.isArray(entries))
|
|
840
|
+
return { pass: false, reason: `the run's ${path} is not a list of argument objects` };
|
|
841
|
+
const odd = entries.findIndex((entry) => !isObject(entry));
|
|
842
|
+
if (odd >= 0)
|
|
843
|
+
return { pass: false, reason: `entry ${odd + 1} of the run's ${path} is not an argument object` };
|
|
844
|
+
// Kuhn's augmenting paths: owner[c] is the entry call c stands for.
|
|
845
|
+
const carriers = entries.map((entry) => calls.flatMap((call, c) => (carriesCut(call.arguments, entry) ? [c] : [])));
|
|
846
|
+
const owner = new Array(calls.length).fill(-1);
|
|
847
|
+
const give = (e, seen) => carriers[e].some((c) => {
|
|
848
|
+
if (seen.has(c))
|
|
849
|
+
return false;
|
|
850
|
+
seen.add(c);
|
|
851
|
+
if (owner[c] === -1 || give(owner[c], seen))
|
|
852
|
+
return (owner[c] = e), true;
|
|
853
|
+
return false;
|
|
854
|
+
});
|
|
855
|
+
const unmatched = entries.flatMap((_, e) => (give(e, new Set()) ? [] : [e]));
|
|
856
|
+
const head = (e) => { const text = JSON.stringify(entries[e]); return text.length > 200 ? `${text.slice(0, 200)}...` : text; };
|
|
857
|
+
if (unmatched.length) {
|
|
858
|
+
const e = unmatched[0];
|
|
859
|
+
const why = carriers[e].length ? `every call that carries it stands for another entry` : `no call carries it`;
|
|
860
|
+
return { pass: false, reason: `${said}; ${unmatched.length} of the ${entries.length} entries in the run's ${path} have no call of their own: entry ${e + 1} (${head(e)}): ${why}` };
|
|
861
|
+
}
|
|
862
|
+
const expected = count ?? entries.length;
|
|
863
|
+
const each = `each of the ${entries.length} entries in the run's ${path} is carried by its own call`;
|
|
864
|
+
if (calls.length !== expected)
|
|
865
|
+
return { pass: false, reason: `${said}; ${each}, and the grader expects exactly ${expected} call${expected === 1 ? "" : "s"}` };
|
|
866
|
+
return { pass: true, reason: `${said}; ${each}` };
|
|
867
|
+
}
|
|
759
868
|
/** The output check of a completed run of a package that declares `output`, beside its case's graders: the server's own
|
|
760
869
|
* verdict (`result.output_error`, why the answer still missed the schema after the runner's one retry), so no case
|
|
761
870
|
* carries a grader for it. Undefined for a package with no output schema. */
|
|
@@ -782,37 +891,156 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
|
782
891
|
...(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>`] : []),
|
|
783
892
|
];
|
|
784
893
|
// The files the run left, ahead of its calls. A call shows a file's bytes only in its arguments or its output, each cut
|
|
785
|
-
// where the timeline cuts it (
|
|
786
|
-
//
|
|
894
|
+
// where the timeline cuts it (its arguments' names and values at CALL_RESULT_CHARS in all, its output at as many), and
|
|
895
|
+
// a cut call reads to a grader as a run that did less than its file holds.
|
|
787
896
|
const files = run.finalFiles ?? [];
|
|
788
897
|
const texts = files.filter((file) => file.text !== undefined);
|
|
789
898
|
// Each call with its arguments (else its input's preview), its status and its output's head; a call that names a file
|
|
790
|
-
//
|
|
791
|
-
|
|
792
|
-
|
|
899
|
+
// says where it is. A string argument `held` names (a write's content that a file's text holds whole and whose head
|
|
900
|
+
// and tail <files> shows: shows) is cut at FILE_ARG_CHARS there, so the grader's room never holds those bytes twice.
|
|
901
|
+
const callsOf = (held, shown = () => true) => run.calls.map((call, i) => {
|
|
902
|
+
const args = call.arguments ? JSON.stringify(inFiles(call.arguments, held)) : undefined;
|
|
903
|
+
const tail = call.status ? ` -> ${call.status}` : "";
|
|
793
904
|
const result = call.result ?? "";
|
|
794
|
-
const
|
|
795
|
-
|
|
905
|
+
const whole = `${i + 1}. ${call.tool}${args !== undefined ? ` ${args}` : call.preview ? ` (${call.preview})` : ""}${tail}`;
|
|
906
|
+
const named = texts.flatMap((file) => (file.name !== undefined && shown(file.name) && (whole.includes(file.name) || result.includes(file.name)) ? [file.name] : [])).sort((a, b) => b.length - a.length)[0];
|
|
907
|
+
const pointer = named ? ` [the file ${named} is in <files>, whole unless marked cut]` : "";
|
|
908
|
+
const head = (shown) => `${i + 1}. ${call.tool}${shown !== undefined ? ` ${shown}` : call.preview ? ` (${call.preview})` : ""}${tail}${pointer}`;
|
|
909
|
+
return { args, head, result, tool: call.name ?? call.tool };
|
|
796
910
|
});
|
|
797
|
-
|
|
798
|
-
|
|
911
|
+
const linesOf = (list) => list.map((call) => ({ head: call.head(call.args), result: call.result, tool: call.tool }));
|
|
912
|
+
// Each call a fake MCP server received, its arguments as the run's timeline shows them (RunRecord.mcpCalls, under the
|
|
913
|
+
// run's cut; never the fake's own log): they are the part a cut of this prompt may take.
|
|
914
|
+
const mcpLines = run.mcpCalls.map((call, i) => ({ head: `${i + 1}. ${call.tool}`, result: call.arguments !== undefined ? JSON.stringify(call.arguments) : (call.preview ?? "{}") }));
|
|
799
915
|
const wrap = (text) => `<tool-calls untrusted>\n${text}\n</tool-calls>`;
|
|
800
916
|
const wrapMcp = (text) => `<mcp-calls untrusted>\nThe calls the MCP servers received, with their arguments, in order:\n${text}\n</mcp-calls>`;
|
|
801
917
|
// A run that searched or fetched: each link its answer cites, matched against its web calls' urls in code (link-check.ts).
|
|
802
918
|
const links = linkCheck(run.answer, run.calls);
|
|
803
919
|
const linked = links === undefined ? [] : [`<link-check untrusted>\n${links}\n</link-check>`];
|
|
804
920
|
const wrapFiles = (text) => `<files untrusted>\nThe files in the run's work folder when it ended, each text file whole unless marked cut (a call below that shows one only in part shows a cut of it):\n${text}\n</files>`;
|
|
805
|
-
const room = max - [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : []), ...(files.length ? [wrapFiles("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
|
|
806
921
|
const wholeOf = (list) => list.reduce((sum, one) => sum + one.head.length + one.result.length + 3, 0);
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
//
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
922
|
+
const headsOf = (list) => list.reduce((sum, one) => sum + one.head.length + 1, 0);
|
|
923
|
+
const mcpWhole = wholeOf(mcpLines);
|
|
924
|
+
const fixed = [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : []), ...(files.length ? [wrapFiles("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
|
|
925
|
+
// A prompt that is cut says what was (cutsNote), at the top of the evidence, in room it keeps for that note: built once
|
|
926
|
+
// to count the cuts, then again with room for the note they make (a few characters more, for counts that grow).
|
|
927
|
+
const whole = fixed + (files.length ? fitFiles(files, Number.MAX_SAFE_INTEGER).length : 0) + wholeOf(linesOf(callsOf(() => false))) + mcpWhole;
|
|
928
|
+
if (whole <= max)
|
|
929
|
+
return build(0).text;
|
|
930
|
+
const first = build(0);
|
|
931
|
+
// Under a cap so tight the note would take more than a twentieth of it, the marks each cut leaves in place say it: the
|
|
932
|
+
// room goes to the evidence (a web call's url list before a summary of what was cut).
|
|
933
|
+
if (first.note === undefined)
|
|
934
|
+
return first.text;
|
|
935
|
+
if (first.note.length > max / 20)
|
|
936
|
+
return build(0, false).text;
|
|
937
|
+
const second = build(first.note.length + 2 + 24);
|
|
938
|
+
return second.text.length <= max ? second.text : build(CUTS_NOTE_ROOM + 2).text;
|
|
939
|
+
function build(reserve, noted = true) {
|
|
940
|
+
const room = max - fixed - reserve;
|
|
941
|
+
// The files come first: they take what they need of the room, but no more than leaves the calls a quarter of it (or
|
|
942
|
+
// all they need, when that is less), so a call's result is cut before a file is; and never more than leaves the calls'
|
|
943
|
+
// arguments half of it (or all they need): what a run sent is what a rubric checks, a file it can hold too. What the
|
|
944
|
+
// calls need counts each argument a file's text holds whole cut, as it is when <files> shows that file whole.
|
|
945
|
+
const inText = (text) => texts.some((file) => file.text !== undefined && file.text.includes(bareOf(text)));
|
|
946
|
+
const needLines = linesOf(callsOf(inText));
|
|
947
|
+
const need = wholeOf(needLines);
|
|
948
|
+
const argsFloor = Math.min(headsOf(needLines) + mcpWhole, Math.floor(room / 2));
|
|
949
|
+
const fittedFiles = files.length ? fitFilesWith(files, Math.max(0, room - Math.max(Math.min(need + mcpWhole, Math.floor(room / 4)), argsFloor))) : undefined;
|
|
950
|
+
const shownFiles = fittedFiles?.text;
|
|
951
|
+
const showing = (name) => shownFiles !== undefined && shownFiles.includes(`<file path="${name}" `);
|
|
952
|
+
// An argument is cut only when a file's text holds all of it and <files> as shown shows its head and tail. A write of a
|
|
953
|
+
// whole file <files> shows cut is cut at FILE_ARG_CHARS: its head and tail are in <files>, and its middle is cut in
|
|
954
|
+
// both, as the file's block marks. One whose text the cut of its file takes from there (an append in its middle, or a
|
|
955
|
+
// first write the appends after it push past the shown head) stays in its call, cut as fitArgs cuts it, as does a
|
|
956
|
+
// write a later one overwrote that shares the file's head and tail.
|
|
957
|
+
const calls = callsOf((text) => inText(text) && shownFiles !== undefined && shows(shownFiles, text), showing);
|
|
958
|
+
const lines = linesOf(calls);
|
|
959
|
+
const callsWhole = wholeOf(lines);
|
|
960
|
+
// Both call lists share the room the rest leave, each in proportion to its whole size; and the fake MCP servers' list,
|
|
961
|
+
// which is its calls' arguments, gets at least half of it (or all it needs), as the timeline's arguments do of theirs
|
|
962
|
+
// (fitArgs): a timeline's long results never take what a run sent to a fake down to a few characters each.
|
|
963
|
+
const left = room - (shownFiles === undefined ? 0 : shownFiles.length);
|
|
964
|
+
const mcpRoom = callsWhole + mcpWhole <= left ? mcpWhole : Math.max(Math.floor((left * mcpWhole) / Math.max(1, callsWhole + mcpWhole)), Math.min(mcpWhole, Math.floor(left / 2)));
|
|
965
|
+
const mcpFit = mcpLines.length ? fitCallsWith(mcpLines, mcpRoom, "argument list") : undefined;
|
|
966
|
+
// The calls' arguments take what the rest of the calls' lines (their heads' other parts and their results) leave of
|
|
967
|
+
// the calls' room, and when that is less than half of it, half (fitArgs): whole when the calls fit, and a call with
|
|
968
|
+
// long arguments never leaves the others without their results.
|
|
969
|
+
const callsRoom = left - mcpRoom;
|
|
970
|
+
const rest = callsWhole - calls.reduce((sum, call) => sum + (call.args?.length ?? 0), 0);
|
|
971
|
+
const kept = fitArgs(calls.map((call) => call.args), Math.max(Math.floor(callsRoom / 2), callsRoom - rest));
|
|
972
|
+
const fitted = kept === undefined ? lines : calls.map((call, i) => ({ head: call.head(kept[i]), result: call.result, tool: call.tool }));
|
|
973
|
+
const callsFit = fitted.length ? fitCallsWith(fitted, callsRoom) : undefined;
|
|
974
|
+
const note = cutsNote({
|
|
975
|
+
files: fittedFiles,
|
|
976
|
+
calls: callsFit && { args: kept === undefined ? 0 : kept.filter((shown, i) => shown !== calls[i].args).length, results: callsFit.cut, dropped: callsFit.dropped },
|
|
977
|
+
mcp: mcpFit && { args: mcpFit.cut, dropped: mcpFit.dropped },
|
|
978
|
+
});
|
|
979
|
+
return { text: [...before, ...(note && noted ? [note] : []), ...(shownFiles === undefined ? [] : [wrapFiles(shownFiles)]), wrap(callsFit ? callsFit.text : "(none)"), ...linked, ...(mcpFit ? [wrapMcp(mcpFit.text)] : [])].join("\n\n"), note };
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
/** The most characters the note on what a grader's input cut takes (cutsNote). */
|
|
983
|
+
const CUTS_NOTE_ROOM = 900;
|
|
984
|
+
/** What a grader's input cut, said once ahead of the evidence, so a grader reads a condition only the cut part could show
|
|
985
|
+
* as unseen, never as consistent: each list's cuts, counted. Undefined when nothing was cut. */
|
|
986
|
+
function cutsNote(cut) {
|
|
987
|
+
const n = (count, one) => `${count} ${count === 1 ? one : `${one}s`}`;
|
|
988
|
+
const of = (count, one) => `${count} ${count === 1 ? `${one}'s` : `${one}s'`}`;
|
|
989
|
+
const lines = [
|
|
990
|
+
...(cut.files && (cut.files.cut || cut.files.out || cut.files.state) ? [`- <files>: ${[cut.files.state ? `${n(cut.files.state, "file")} of tool state (under a folder whose name starts with ".") listed by name alone` : "", cut.files.cut ? `${of(cut.files.cut, "file")} text cut in the middle` : "", cut.files.out ? `${of(cut.files.out, "file")} text left out` : ""].filter(Boolean).join("; ")}.`] : []),
|
|
991
|
+
...(cut.calls && (cut.calls.args || cut.calls.results || cut.calls.dropped) ? [`- <tool-calls>: ${[cut.calls.args ? `${of(cut.calls.args, "call")} arguments cut in the middle` : "", cut.calls.results ? `${n(cut.calls.results, "result")} cut or left out` : "", cut.calls.dropped ? `${n(cut.calls.dropped, "call")} in the middle left out` : ""].filter(Boolean).join("; ")}.`] : []),
|
|
992
|
+
...(cut.mcp && (cut.mcp.args || cut.mcp.dropped) ? [`- <mcp-calls>: ${[cut.mcp.args ? `${of(cut.mcp.args, "call")} arguments cut or left out` : "", cut.mcp.dropped ? `${n(cut.mcp.dropped, "call")} in the middle left out` : ""].filter(Boolean).join("; ")}.`] : []),
|
|
993
|
+
];
|
|
994
|
+
if (!lines.length)
|
|
995
|
+
return undefined;
|
|
996
|
+
return ["<cuts>", "This input is cut to stay under its cap; each cut is marked where it is:", ...lines, "What a cut leaves out was not seen: a condition only it could show is not shown to hold.", "</cuts>"].join("\n");
|
|
997
|
+
}
|
|
998
|
+
/** How much of a write's content a grader's call line shows when a file in <files> holds it whole. */
|
|
999
|
+
const FILE_ARG_CHARS = 2000;
|
|
1000
|
+
/** A call's copy of a text with the trailing "..." where the timeline cut it at its budget left off. */
|
|
1001
|
+
function bareOf(text) {
|
|
1002
|
+
return text.endsWith("...") ? text.slice(0, -3) : text;
|
|
1003
|
+
}
|
|
1004
|
+
/** Whether `where` shows the first and last FILE_ARG_CHARS characters of a call's copy of `text` (bareOf). */
|
|
1005
|
+
function shows(where, text) {
|
|
1006
|
+
const bare = bareOf(text);
|
|
1007
|
+
return where.includes(bare.slice(0, FILE_ARG_CHARS)) && where.includes(bare.slice(-FILE_ARG_CHARS));
|
|
1008
|
+
}
|
|
1009
|
+
/** A call's arguments with each string past FILE_ARG_CHARS that `held` names (one a file holds and <files> shows) cut there,
|
|
1010
|
+
* ending "...", in a list or an object at any depth. */
|
|
1011
|
+
function inFiles(value, held) {
|
|
1012
|
+
if (typeof value === "string")
|
|
1013
|
+
return value.length > FILE_ARG_CHARS && held(value) ? `${value.slice(0, FILE_ARG_CHARS - 3)}...` : value;
|
|
1014
|
+
if (Array.isArray(value))
|
|
1015
|
+
return value.map((item) => inFiles(item, held));
|
|
1016
|
+
if (!value || typeof value !== "object")
|
|
1017
|
+
return value;
|
|
1018
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inFiles(item, held)]));
|
|
1019
|
+
}
|
|
1020
|
+
/** Each call's arguments (their JSON, none for a call with none) in at most `room` characters in all: undefined when they
|
|
1021
|
+
* fit whole; else each past a length L keeps its first two thirds and last third of L with its middle cut and marked
|
|
1022
|
+
* (middle), L the longest that fits, so the longest are cut first. A list no longer than L and a marker (40 characters)
|
|
1023
|
+
* stays whole, so a cut never takes a short list's text for a marker as long; when even L = 0 passes the room, the
|
|
1024
|
+
* short lists stay whole, the long ones show their marker alone, and fitCalls drops calls as it does. */
|
|
1025
|
+
export function fitArgs(args, room) {
|
|
1026
|
+
const cuts = (text, keep) => text.length > keep + 40;
|
|
1027
|
+
const sizeOf = (keep) => args.reduce((sum, text) => sum + (text === undefined ? 0 : cuts(text, keep) ? keep + 40 : text.length), 0);
|
|
1028
|
+
if (sizeOf(Number.MAX_SAFE_INTEGER) <= room)
|
|
1029
|
+
return undefined;
|
|
1030
|
+
const keep = longestKeep(sizeOf, Math.max(0, ...args.map((text) => text?.length ?? 0)), room);
|
|
1031
|
+
return args.map((text) => (text !== undefined && cuts(text, keep) ? middle(text, keep) : text));
|
|
1032
|
+
}
|
|
1033
|
+
/** The longest keep in [0, high] whose `size` is within `room`, else 0: `size` never falls as keep grows. */
|
|
1034
|
+
function longestKeep(size, high, room) {
|
|
1035
|
+
let [low, top] = [0, high];
|
|
1036
|
+
while (low < top) {
|
|
1037
|
+
const mid = Math.ceil((low + top) / 2);
|
|
1038
|
+
if (size(mid) <= room)
|
|
1039
|
+
low = mid;
|
|
1040
|
+
else
|
|
1041
|
+
top = mid - 1;
|
|
1042
|
+
}
|
|
1043
|
+
return low;
|
|
816
1044
|
}
|
|
817
1045
|
/** A grader's calls, one line each (`head`, then `: <result>`), in at most `room` characters: whole when they fit; else
|
|
818
1046
|
* each result past a length L keeps its first two thirds and last third of L with its middle cut and marked, L the
|
|
@@ -822,10 +1050,16 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
|
822
1050
|
* cut says so on the list's first line, so the grader knows what it does not see; `what` names what follows each head
|
|
823
1051
|
* there (a fake MCP server's list cuts a call's arguments). */
|
|
824
1052
|
export function fitCalls(lines, room, what = "result") {
|
|
1053
|
+
return fitCallsWith(lines, room, what).text;
|
|
1054
|
+
}
|
|
1055
|
+
/** fitCalls, with how many results it cut or left out (`cut`) and how many calls it dropped (`dropped`), for the note on
|
|
1056
|
+
* what a grader's input cut (cutsNote). */
|
|
1057
|
+
function fitCallsWith(lines, room, what = "result") {
|
|
825
1058
|
const line = (head, result) => (result ? `${head}: ${result}` : head);
|
|
826
1059
|
const whole = lines.map((one) => line(one.head, one.result)).join("\n");
|
|
827
1060
|
if (whole.length <= room)
|
|
828
|
-
return whole;
|
|
1061
|
+
return { text: whole, cut: 0, dropped: 0 };
|
|
1062
|
+
const results = lines.filter((one) => one.result).length;
|
|
829
1063
|
const said = saidCut;
|
|
830
1064
|
const webs = lines.map((one) => (one.tool ? webShownOf(one.tool, one.result) : undefined));
|
|
831
1065
|
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" : ""}`);
|
|
@@ -833,22 +1067,12 @@ export function fitCalls(lines, room, what = "result") {
|
|
|
833
1067
|
// on every result `keep` cuts.
|
|
834
1068
|
const cutTo = (text, keep) => (text.length > keep ? keep + 42 : text ? text.length + 2 : 0);
|
|
835
1069
|
const high = Math.max(...lines.map((one) => one.result.length));
|
|
836
|
-
const longest = (size) =>
|
|
837
|
-
let [low, top] = [0, high];
|
|
838
|
-
while (low < top) {
|
|
839
|
-
const mid = Math.ceil((low + top) / 2);
|
|
840
|
-
if (size(mid) <= room)
|
|
841
|
-
low = mid;
|
|
842
|
-
else
|
|
843
|
-
top = mid - 1;
|
|
844
|
-
}
|
|
845
|
-
return low;
|
|
846
|
-
};
|
|
1070
|
+
const longest = (size) => longestKeep(size, high, room);
|
|
847
1071
|
// A web call's line is measured as it is shown.
|
|
848
1072
|
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);
|
|
849
1073
|
if (size(0) <= room) {
|
|
850
1074
|
const keep = longest(size);
|
|
851
|
-
return [LONG, ...lines.map((one, i) => line(one.head, webs[i] ? webs[i](keep) : middle(one.result, keep)))].join("\n");
|
|
1075
|
+
return { text: [LONG, ...lines.map((one, i) => line(one.head, webs[i] ? webs[i](keep) : middle(one.result, keep)))].join("\n"), cut: lines.filter((one) => one.result.length > keep).length, dropped: 0 };
|
|
852
1076
|
}
|
|
853
1077
|
// The web calls' url lists alone pass the room: every other result is left out, and each list keeps its head and tail.
|
|
854
1078
|
if (webs.some(Boolean)) {
|
|
@@ -857,7 +1081,7 @@ export function fitCalls(lines, room, what = "result") {
|
|
|
857
1081
|
const over = (keep) => OVER.length + 1 + lines.reduce((sum, one, i) => sum + one.head.length + cutTo(lists[i], keep) + 1, 0);
|
|
858
1082
|
if (over(0) <= room) {
|
|
859
1083
|
const keep = longest(over);
|
|
860
|
-
return [OVER, ...lines.map((one, i) => line(one.head, lists[i] ? middle(lists[i], keep) : ""))].join("\n");
|
|
1084
|
+
return { text: [OVER, ...lines.map((one, i) => line(one.head, lists[i] ? middle(lists[i], keep) : ""))].join("\n"), cut: results, dropped: 0 };
|
|
861
1085
|
}
|
|
862
1086
|
}
|
|
863
1087
|
// Not even every call's head fits: the first and last calls, as many as fit, with no result, the middle ones dropped.
|
|
@@ -875,7 +1099,9 @@ export function fitCalls(lines, room, what = "result") {
|
|
|
875
1099
|
kept[1].unshift(heads[j--]);
|
|
876
1100
|
}
|
|
877
1101
|
const dropped = heads.length - kept[0].length - kept[1].length;
|
|
878
|
-
|
|
1102
|
+
if (!dropped)
|
|
1103
|
+
return { text: [said(`every ${what} is left out`), ...kept[0], ...kept[1]].join("\n"), cut: results, dropped };
|
|
1104
|
+
return { text: [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"), cut: results, dropped };
|
|
879
1105
|
}
|
|
880
1106
|
/** A cut's note, on the first line of what it cut. */
|
|
881
1107
|
const saidCut = (cut) => `(Cut to keep this prompt under its cap: ${cut}.)`;
|
|
@@ -894,28 +1120,38 @@ function middle(text, keep) {
|
|
|
894
1120
|
* its size on a last line, cut to the room when even that passes it. Each file is named by its cut name alone: one with
|
|
895
1121
|
* none is in a block with no path, or counted. */
|
|
896
1122
|
export function fitFiles(files, room) {
|
|
1123
|
+
return fitFilesWith(files, room).text;
|
|
1124
|
+
}
|
|
1125
|
+
/** Whether a final file is a tool's state, not the run's work: under a folder whose name starts with "." (the package's
|
|
1126
|
+
* own skills copied under `.agents/skills`, a tool's cache such as `film/.hyperframes`). A file with no name is not. */
|
|
1127
|
+
export function toolState(name) {
|
|
1128
|
+
return name !== undefined && name.split("/").slice(0, -1).some((part) => part.startsWith("."));
|
|
1129
|
+
}
|
|
1130
|
+
/** fitFiles, with how many texts it cut in the middle (`cut`) or left out (`out`), and how many of tool state (toolState)
|
|
1131
|
+
* it listed by name alone (`state`), for the note on what a grader's input cut (cutsNote). A run's own files come first:
|
|
1132
|
+
* past the room, the tool state's texts are left out before any other file is cut. */
|
|
1133
|
+
function fitFilesWith(files, room) {
|
|
897
1134
|
const block = (file, text) => `<file${file.name === undefined ? "" : ` path="${file.name}"`} bytes="${file.bytes}">\n${text}\n</file>`;
|
|
898
|
-
const
|
|
1135
|
+
const all = files.filter((file) => file.text !== undefined);
|
|
899
1136
|
const others = files.filter((file) => file.text === undefined);
|
|
900
1137
|
const named = others.length ? [`Not shown (not text, or past what a grader is given), by path and size in bytes: ${namesOf(others)}`] : [];
|
|
901
|
-
const whole = [...
|
|
1138
|
+
const whole = [...all.map((file) => block(file, file.text)), ...named].join("\n");
|
|
902
1139
|
if (whole.length <= room)
|
|
903
|
-
return whole;
|
|
1140
|
+
return { text: whole, cut: 0, out: 0, state: 0 };
|
|
1141
|
+
const state = all.filter((file) => toolState(file.name));
|
|
1142
|
+
const texts = all.filter((file) => !toolState(file.name));
|
|
1143
|
+
const listed = [...named, ...(state.length ? [`Not shown (tool state: under a folder whose name starts with ".", left out before any file of the run's own is cut), by path and size in bytes: ${namesOf(state)}`] : [])];
|
|
1144
|
+
const own = [...texts.map((file) => block(file, file.text)), ...listed].join("\n");
|
|
1145
|
+
if (own.length <= room)
|
|
1146
|
+
return { text: own, cut: 0, out: 0, state: state.length };
|
|
904
1147
|
const LONG = saidCut("each long file keeps its head and tail, its middle cut where marked");
|
|
905
|
-
const size = (keep) => LONG.length + 1 + texts.reduce((sum, file) => sum + block(file, "").length + (file.text.length <= keep ? file.text.length : keep + 40) + 1, 0) +
|
|
1148
|
+
const size = (keep) => LONG.length + 1 + texts.reduce((sum, file) => sum + block(file, "").length + (file.text.length <= keep ? file.text.length : keep + 40) + 1, 0) + listed.reduce((sum, line) => sum + line.length + 1, 0);
|
|
906
1149
|
if (texts.length && size(0) <= room) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
const mid = Math.ceil((low + top) / 2);
|
|
910
|
-
if (size(mid) <= room)
|
|
911
|
-
low = mid;
|
|
912
|
-
else
|
|
913
|
-
top = mid - 1;
|
|
914
|
-
}
|
|
915
|
-
return [LONG, ...texts.map((file) => block(file, middle(file.text, low))), ...named].join("\n");
|
|
1150
|
+
const keep = longestKeep(size, Math.max(...texts.map((file) => file.text.length)), room);
|
|
1151
|
+
return { text: [LONG, ...texts.map((file) => block(file, middle(file.text, keep))), ...listed].join("\n"), cut: texts.filter((file) => file.text.length > keep).length, out: 0, state: state.length };
|
|
916
1152
|
}
|
|
917
1153
|
const list = [saidCut("every file's text is left out"), `By path and size in bytes: ${namesOf(files)}`].join("\n");
|
|
918
|
-
return list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)}
|
|
1154
|
+
return { text: list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)} ...`, cut: 0, out: all.length, state: 0 };
|
|
919
1155
|
}
|
|
920
1156
|
/** Files by their cut names and sizes, "a.mp4 (9000000), b.txt (5)", and those with no name counted after them: a file is
|
|
921
1157
|
* never named to a grader by anything but its cut name. */
|
|
@@ -943,7 +1179,8 @@ export function verdictOf(answer) {
|
|
|
943
1179
|
return undefined;
|
|
944
1180
|
}
|
|
945
1181
|
/** A fake MCP server for `fixture` on loopback, Streamable HTTP through the official SDK, one stateless server per
|
|
946
|
-
* request; every tool call is recorded (its gate name and arguments) and answered from the fixture
|
|
1182
|
+
* request; every tool call is recorded (its gate name and arguments) and answered from the fixture as it is written, so
|
|
1183
|
+
* the agent and a script it runs read the answer a real server of that shape gives (a JSON text parses as JSON). */
|
|
947
1184
|
export async function startFake(name, fixture) {
|
|
948
1185
|
const { createMcpHandler, fromJsonSchema, McpServer } = await import("@modelcontextprotocol/server").catch((error) => {
|
|
949
1186
|
throw new Error(`a case with an mcp fixture needs @modelcontextprotocol/server installed beside agentrun-serve: ${error.message}`);
|
|
@@ -1042,17 +1279,41 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
1042
1279
|
export const CLAIM_READ_TIMEOUT_MS = 10_000;
|
|
1043
1280
|
/** The least time between two of those reads of one run. */
|
|
1044
1281
|
export const CLAIM_READ_EVERY_MS = 5_000;
|
|
1045
|
-
/**
|
|
1046
|
-
|
|
1047
|
-
|
|
1282
|
+
/** How long a timeline page read asks the server to wait for a new row (its wait_ms). */
|
|
1283
|
+
const PAGE_WAIT_MS = 5_000;
|
|
1284
|
+
/** How long that read may take: its wait, and 10 s for the answer to arrive. */
|
|
1285
|
+
export const PAGE_READ_TIMEOUT_MS = PAGE_WAIT_MS + 10_000;
|
|
1286
|
+
/** The bound of a read in waitRun made at `now`: `capMs`, or the time left to `deadline` when that is less (`ms`, whole
|
|
1287
|
+
* milliseconds and never below 0, as AbortSignal.timeout takes them), and whether the time left is what bounds it
|
|
1288
|
+
* (`atDeadline`). */
|
|
1289
|
+
export function readBound(deadline, capMs, now) {
|
|
1290
|
+
const left = deadline - now;
|
|
1291
|
+
return left < capMs ? { ms: Math.max(0, Math.ceil(left)), atDeadline: true } : { ms: capMs, atDeadline: false };
|
|
1292
|
+
}
|
|
1293
|
+
/** A read in waitRun, bounded as readBound says and by the eval's stop (`stop`): the `signal` its request takes, whether
|
|
1294
|
+
* to `send` it at all (not with no time left), and `byDeadline()`, true once the deadline ended it. The wait takes that
|
|
1295
|
+
* as its end, with no second read of the clock: the timer runs on a monotonic clock in whole milliseconds, and
|
|
1296
|
+
* Date.now() can still read a millisecond short of the deadline when it fires. */
|
|
1297
|
+
function bounded(deadline, capMs, stop) {
|
|
1298
|
+
const { ms, atDeadline } = readBound(deadline, capMs, Date.now());
|
|
1299
|
+
const timeout = AbortSignal.timeout(ms);
|
|
1300
|
+
return { signal: stop ? AbortSignal.any([stop, timeout]) : timeout, send: ms > 0, byDeadline: () => atDeadline && (ms === 0 || timeout.aborted) };
|
|
1301
|
+
}
|
|
1302
|
+
/** Whether a runner holds the run now (the run read's `claim`): "deadline" when the read ran to the run's `deadline`, or
|
|
1303
|
+
* there was no time left to send it; undefined when it fails, takes over CLAIM_READ_TIMEOUT_MS or is stopped by
|
|
1304
|
+
* `signal` (the eval's stop): not known, so never a reason to cancel the run as unheld. */
|
|
1048
1305
|
async function heldNow(api, runId, deadline, signal) {
|
|
1049
|
-
const
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1306
|
+
const read = bounded(deadline, CLAIM_READ_TIMEOUT_MS, signal);
|
|
1307
|
+
const answered = read.send ? await api("GET", `/runs/${runId}`, undefined, {}, { signal: read.signal }).catch(() => undefined) : undefined;
|
|
1308
|
+
if (read.byDeadline())
|
|
1309
|
+
return "deadline";
|
|
1310
|
+
return answered?.status === 200 && isObject(answered.body) ? isObject(answered.body.claim) : undefined;
|
|
1052
1311
|
}
|
|
1053
1312
|
/** A run waited for: its rows until it ends (completed, failed, cancelled) or waits on a person (input_required), or
|
|
1054
|
-
* `deadline` passes (then it is cancelled). A stop of the eval (`signal`) cancels it too, and throws.
|
|
1055
|
-
|
|
1313
|
+
* `deadline` passes (then it is cancelled). A stop of the eval (`signal`) cancels it too, and throws. Each of its reads
|
|
1314
|
+
* ends at the deadline and at the stop (bounded), so a server that stalls one never holds the wait past either.
|
|
1315
|
+
* Exported for its tests. */
|
|
1316
|
+
export async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIMEOUT_MS) {
|
|
1056
1317
|
const view = new Map();
|
|
1057
1318
|
let after = 0;
|
|
1058
1319
|
const started = Date.now();
|
|
@@ -1062,63 +1323,104 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
1062
1323
|
// page asks (at most one read in CLAIM_READ_EVERY_MS): a claim can lapse for a moment on a stalled machine (not renewed
|
|
1063
1324
|
// in time, then claimed again), so one read that finds none never ends the wait. The run is cancelled only when reads
|
|
1064
1325
|
// found no runner holding it from the first such read to one queueTimeoutMs later, none between them finding one. A read
|
|
1065
|
-
// that doesn't answer (failed, stalled past its bound
|
|
1066
|
-
// deadline still end the wait.
|
|
1326
|
+
// that doesn't answer (failed, stalled past its bound, or stopped) says neither.
|
|
1067
1327
|
let unheldSince = started;
|
|
1068
1328
|
let everHeld = false;
|
|
1069
1329
|
let askedAt = -Infinity;
|
|
1330
|
+
let rows = [];
|
|
1331
|
+
let state;
|
|
1070
1332
|
for (;;) {
|
|
1071
1333
|
if (signal?.aborted) {
|
|
1072
1334
|
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
1073
1335
|
signal.throwIfAborted();
|
|
1074
1336
|
}
|
|
1075
1337
|
// calls=whole: each call's arguments and its output, whole to CALL_RESULT_CHARS (tool_input, tool_result_text), which its graders read.
|
|
1076
|
-
// CALLS_PAGE_ROWS rows a page, the most a calls=whole page holds (an older server's default is 500).
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
if (
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1338
|
+
// CALLS_PAGE_ROWS rows a page, the most a calls=whole page holds (an older server's default is 500). A page its bound
|
|
1339
|
+
// cut (stalled past PAGE_READ_TIMEOUT_MS, run to the deadline, or stopped) is no page: it is asked again, unless the
|
|
1340
|
+
// stop or the deadline below ends the wait.
|
|
1341
|
+
const read = bounded(deadline, PAGE_READ_TIMEOUT_MS, signal);
|
|
1342
|
+
const answered = read.send
|
|
1343
|
+
? await api("GET", `/runs/${runId}/timeline?after=${after}&wait_ms=${PAGE_WAIT_MS}&calls=whole&limit=${CALLS_PAGE_ROWS}`, undefined, {}, { signal: read.signal }).catch((error) => {
|
|
1344
|
+
if (read.signal.aborted)
|
|
1345
|
+
return undefined;
|
|
1346
|
+
throw error;
|
|
1347
|
+
})
|
|
1348
|
+
: undefined;
|
|
1349
|
+
let timedOut = read.byDeadline();
|
|
1350
|
+
const page = answered === undefined ? undefined : expectOk(`reading run ${runId}'s timeline`, answered);
|
|
1351
|
+
if (page) {
|
|
1352
|
+
if (page.reset)
|
|
1353
|
+
view.clear();
|
|
1354
|
+
for (const id of page.drop ?? [])
|
|
1355
|
+
view.delete(id);
|
|
1356
|
+
for (const row of page.rows ?? [])
|
|
1357
|
+
view.set(String(row.id), row);
|
|
1358
|
+
after = Number(page.next_after ?? after);
|
|
1359
|
+
rows = [...view.values()].sort((a, b) => Number(a.seq ?? 0) - Number(b.seq ?? 0));
|
|
1360
|
+
state = page.state;
|
|
1361
|
+
const status = String(page.status);
|
|
1362
|
+
if (ENDED.includes(status) && page.final && !page.has_more)
|
|
1363
|
+
return { status, rows };
|
|
1364
|
+
if (status === "input_required" && !page.has_more) {
|
|
1365
|
+
const waiting = rows.findLast((row) => row.kind === "waiting");
|
|
1366
|
+
return { status, rows, waiting: typeof waiting?.summary === "string" ? waiting.summary : "it waits on a person" };
|
|
1367
|
+
}
|
|
1368
|
+
// A page that isn't queued shows a runner took the run: a later queued page starts no lapse from before it.
|
|
1369
|
+
if (status !== "queued") {
|
|
1097
1370
|
everHeld = true;
|
|
1098
1371
|
unheldSince = undefined;
|
|
1099
1372
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1373
|
+
if (status === "queued" && (everHeld || Date.now() - started > queueTimeoutMs) && Date.now() - askedAt >= CLAIM_READ_EVERY_MS) {
|
|
1374
|
+
askedAt = Date.now();
|
|
1375
|
+
const held = await heldNow(api, runId, deadline, signal);
|
|
1376
|
+
if (held === "deadline")
|
|
1377
|
+
timedOut = true;
|
|
1378
|
+
else if (held === true) {
|
|
1379
|
+
everHeld = true;
|
|
1380
|
+
unheldSince = undefined;
|
|
1381
|
+
}
|
|
1382
|
+
else if (held === false) {
|
|
1383
|
+
unheldSince ??= askedAt;
|
|
1384
|
+
if (Date.now() - unheldSince >= queueTimeoutMs) {
|
|
1385
|
+
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
1386
|
+
return { status: "timed_out", rows, why: `the run stayed queued for ${Math.round(queueTimeoutMs / 1000)} s with no runner holding it, and it was cancelled` };
|
|
1387
|
+
}
|
|
1105
1388
|
}
|
|
1106
1389
|
}
|
|
1107
1390
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1391
|
+
if (signal?.aborted)
|
|
1392
|
+
continue;
|
|
1393
|
+
// A read the deadline ended, or the clock at the deadline, not only past it. A cancel that fails is sent again once the
|
|
1394
|
+
// wait's answer is settled (settle cancels a run not ended): the wait still ends timed out.
|
|
1395
|
+
if (timedOut || Date.now() >= deadline) {
|
|
1396
|
+
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
1397
|
+
return { status: "timed_out", rows, why: `the run took longer than ${Math.round((deadline - started) / 1000)} s (state ${String(state ?? "unknown")} when the wait gave up) and was cancelled` };
|
|
1112
1398
|
}
|
|
1113
|
-
if (page
|
|
1399
|
+
if (page?.has_more !== true && page?.unchanged === true)
|
|
1114
1400
|
await sleep(250);
|
|
1115
1401
|
}
|
|
1116
1402
|
}
|
|
1403
|
+
/** The calls on the faked MCP servers `faked` that ran, as the run's timeline shows them (`calls`, from callsOf: each
|
|
1404
|
+
* argument through the run's redaction): each call on a faked server's tool the run did not refuse before it ran and
|
|
1405
|
+
* whose result row the timeline holds. A call refused (a deny, a cap, an approval never given) never reached the fake,
|
|
1406
|
+
* and one with no result (cut off) has no outcome to show. One that failed on its way to the fake shows, with its
|
|
1407
|
+
* error as its result, never as a success; a tool_used grader counts only what the fake logged (fakeLog). What an llm
|
|
1408
|
+
* grader's <mcp-calls> and the report's `mcp_calls` show, never the fake's own log. */
|
|
1409
|
+
export function mcpCallsOf(calls, faked) {
|
|
1410
|
+
return calls.filter((call) => !call.refused && call.status != null && faked.includes(mcpNameOf(call.tool)?.server ?? ""));
|
|
1411
|
+
}
|
|
1412
|
+
/** A run's calls for its graders and its report, from its timeline's (callsOf) and the fakes it ran against: its calls,
|
|
1413
|
+
* its fake MCP calls (mcpCallsOf) and the fakes' own log whole. The template eval's runs and learn-bench's steps both
|
|
1414
|
+
* read them here. */
|
|
1415
|
+
export function callRecordOf(calls, faked, fakes) {
|
|
1416
|
+
return { calls: [...calls], mcpCalls: mcpCallsOf(calls, faked), fakeLog: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))) };
|
|
1417
|
+
}
|
|
1117
1418
|
/** A run's tool calls, each named as a grader names it: the gate's own rule (RunGate.enter), its settings key, but a
|
|
1118
1419
|
* shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
|
|
1119
1420
|
* call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
|
|
1120
1421
|
* under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
|
|
1121
|
-
* its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews
|
|
1422
|
+
* its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews, and
|
|
1423
|
+
* `refused` when its result row says the run refused it before it ran (a deny, a pin, an approval never given). */
|
|
1122
1424
|
export function callsOf(rows, harness, toolkits = {}) {
|
|
1123
1425
|
const results = new Map(rows.filter((row) => row.kind === "tool_result" && row.tool_use_id).map((row) => [String(row.tool_use_id), row]));
|
|
1124
1426
|
// The rows are a server's, read over its API: the names are the built-in harness's, the only facts known here.
|
|
@@ -1128,7 +1430,7 @@ export function callsOf(rows, harness, toolkits = {}) {
|
|
|
1128
1430
|
const result = results.get(String(row.tool_use_id));
|
|
1129
1431
|
const key = settingsKeyOf(harness, name, names);
|
|
1130
1432
|
const output = typeof result?.tool_result_text === "string" ? result.tool_result_text : (result?.tool_result_preview ?? null);
|
|
1131
|
-
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 };
|
|
1433
|
+
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, ...(result?.refused === true ? { refused: true } : {}) };
|
|
1132
1434
|
});
|
|
1133
1435
|
}
|
|
1134
1436
|
/** Every file of a run's work folder (the files route, page by page), each with its name under the run's cut (`?cut=run`). */
|
|
@@ -1158,7 +1460,7 @@ export const FILE_READ_TIMEOUT_MS = 10_000;
|
|
|
1158
1460
|
export const FILE_READS_TIMEOUT_MS = 30_000;
|
|
1159
1461
|
/** A run's final files for its llm graders: each text file's whole text, read smallest first while the texts read stay
|
|
1160
1462
|
* within GRADER_PROMPT_MAX UTF-8 bytes in all (one grader input holds that many characters, and a character is at least
|
|
1161
|
-
* a byte), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
|
|
1463
|
+
* a byte), the run's own files before any of tool state (toolState), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
|
|
1162
1464
|
* secrets (`?cut=run`, run-reads-over-store.ts cutRunFile): every value its timeline's calls are cut of, and every secret
|
|
1163
1465
|
* shape, is "[redacted]" in the text a grader sees. An answer without the cut's mark (`x-agentrun-cut: run`: a server
|
|
1164
1466
|
* that doesn't know the cut and would serve the raw bytes) leaves the text out. A read that fails, is refused (403, 413,
|
|
@@ -1168,7 +1470,7 @@ export async function finalFilesOf(api, runId, listed, signal, readTimeoutMs = F
|
|
|
1168
1470
|
const texts = new Map();
|
|
1169
1471
|
let left = GRADER_PROMPT_MAX;
|
|
1170
1472
|
const until = Date.now() + Math.max(FILE_READS_TIMEOUT_MS, readTimeoutMs);
|
|
1171
|
-
for (const file of [...listed].filter((one) => !one.unreadable && (one.type === null || TEXT_TYPE.test(one.type))).sort((a, b) => a.bytes - b.bytes)) {
|
|
1473
|
+
for (const file of [...listed].filter((one) => !one.unreadable && (one.type === null || TEXT_TYPE.test(one.type))).sort((a, b) => Number(toolState(a.path)) - Number(toolState(b.path)) || a.bytes - b.bytes)) {
|
|
1172
1474
|
if (file.bytes > left)
|
|
1173
1475
|
continue;
|
|
1174
1476
|
signal?.throwIfAborted();
|
|
@@ -1192,6 +1494,38 @@ export async function finalFilesOf(api, runId, listed, signal, readTimeoutMs = F
|
|
|
1192
1494
|
// Each by its cut name alone: its path is for the reads above, never a grader.
|
|
1193
1495
|
return listed.map((file) => ({ ...(file.name !== undefined ? { name: file.name } : {}), bytes: file.bytes, ...(texts.has(file.path) ? { text: texts.get(file.path) } : {}) }));
|
|
1194
1496
|
}
|
|
1497
|
+
/** The most bytes of an args_file a tool_used grader reads: the most a cut read answers (run-files.ts). */
|
|
1498
|
+
export const ARGS_FILE_MAX = RUN_FILE_CUT_MAX;
|
|
1499
|
+
/** Each file a tool_used grader's args_file names, read whole under the run's cut (as finalFilesOf reads a file: an
|
|
1500
|
+
* answer without the cut's mark is refused), by its path: its text, or why there is none (absent, refused, past
|
|
1501
|
+
* ARGS_FILE_MAX bytes, a read that failed or took past `readTimeoutMs`). */
|
|
1502
|
+
export async function argsFilesOf(api, runId, paths, signal, readTimeoutMs = FILE_READ_TIMEOUT_MS) {
|
|
1503
|
+
const out = {};
|
|
1504
|
+
for (const path of new Set(paths)) {
|
|
1505
|
+
signal?.throwIfAborted();
|
|
1506
|
+
const bound = AbortSignal.timeout(readTimeoutMs);
|
|
1507
|
+
const read = await api("GET", `${filePath(runId, path)}?cut=run`, undefined, {}, { text: true, signal: signal ? AbortSignal.any([signal, bound]) : bound }).catch((error) => {
|
|
1508
|
+
if (signal?.aborted)
|
|
1509
|
+
throw error;
|
|
1510
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
1511
|
+
});
|
|
1512
|
+
if ("error" in read)
|
|
1513
|
+
out[path] = { why: `the read failed (${read.error})` };
|
|
1514
|
+
else if (read.status === 404)
|
|
1515
|
+
out[path] = { why: "its work folder has no such file" };
|
|
1516
|
+
else if (read.status === 413)
|
|
1517
|
+
out[path] = { why: `it is past ${ARGS_FILE_MAX} bytes` };
|
|
1518
|
+
else if (read.status !== 200 || typeof read.body !== "string")
|
|
1519
|
+
out[path] = { why: `the server answered ${read.status}` };
|
|
1520
|
+
else if (read.headers?.get("x-agentrun-cut") !== "run")
|
|
1521
|
+
out[path] = { why: "the server did not read it under the run's cut" };
|
|
1522
|
+
else if (Buffer.byteLength(read.body) > ARGS_FILE_MAX)
|
|
1523
|
+
out[path] = { why: `it is past ${ARGS_FILE_MAX} bytes` };
|
|
1524
|
+
else
|
|
1525
|
+
out[path] = { text: read.body };
|
|
1526
|
+
}
|
|
1527
|
+
return out;
|
|
1528
|
+
}
|
|
1195
1529
|
/** Each path a file_exists grader names that the run's work folder holds, read one by one (GET /runs/{id}/files/{path}):
|
|
1196
1530
|
* the listing is capped (its `truncated`), so a file past its cap or depth is never taken for absent. Only the status
|
|
1197
1531
|
* is read: the file's body is cancelled unread, whatever its size. */
|
|
@@ -1239,6 +1573,11 @@ export async function evalTemplate(options) {
|
|
|
1239
1573
|
const log = options.log ?? (() => undefined);
|
|
1240
1574
|
if (options.data !== undefined && options.server)
|
|
1241
1575
|
throw new Error(ON_DATA_WITH_SERVER);
|
|
1576
|
+
// A NaN bound would never end a wait (no clock reads past it); a fraction of a millisecond is rounded up (readBound).
|
|
1577
|
+
for (const [name, ms] of [["runTimeoutMs", options.runTimeoutMs], ["queueTimeoutMs", options.queueTimeoutMs]]) {
|
|
1578
|
+
if (ms !== undefined && !(Number.isFinite(ms) && ms > 0))
|
|
1579
|
+
throw new RangeError(`${name} is a time in milliseconds over 0, not ${ms}`);
|
|
1580
|
+
}
|
|
1242
1581
|
const { pkg, cases } = readCases(options.dir, options.cases);
|
|
1243
1582
|
if (options.graderModel !== undefined && !MODEL_REF.test(options.graderModel))
|
|
1244
1583
|
throw new CaseError(options.dir, [`--grader-model is "provider/model-id", not ${options.graderModel}`]);
|
|
@@ -1735,10 +2074,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1735
2074
|
const result = isObject(view.result) ? view.result : {};
|
|
1736
2075
|
const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
|
|
1737
2076
|
const listed = await filesOf(api, runId);
|
|
2077
|
+
const calls = callsOf(ended.rows, harness, Object.fromEntries(Object.entries(used).map(([toolkit, server]) => [server, toolkit])));
|
|
1738
2078
|
const record = {
|
|
1739
2079
|
answer: typeof result.final_answer === "string" ? result.final_answer : "",
|
|
1740
|
-
calls
|
|
1741
|
-
mcpCalls: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))),
|
|
2080
|
+
...callRecordOf(calls, Object.keys(one.mcp), fakes),
|
|
1742
2081
|
files: await (async () => {
|
|
1743
2082
|
const paths = listed.map((file) => file.path);
|
|
1744
2083
|
const named = one.graders.flatMap((grader) => (grader.type === "file_exists" ? [grader.path] : []));
|
|
@@ -1766,6 +2105,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1766
2105
|
// The files it left, read whole for its llm graders: only a run they grade, so a case of other graders reads none.
|
|
1767
2106
|
if (graded && one.graders.some((grader) => grader.type === "llm"))
|
|
1768
2107
|
record.finalFiles = await finalFilesOf(api, runId, listed, options.signal, options.fileReadTimeoutMs);
|
|
2108
|
+
// The lists a tool_used grader's calls are matched against, read whole.
|
|
2109
|
+
const argsFiles = one.graders.flatMap((grader) => (grader.type === "tool_used" && grader.argsFile !== undefined ? [grader.argsFile] : []));
|
|
2110
|
+
if (argsFiles.length)
|
|
2111
|
+
record.argsFiles = await argsFilesOf(api, runId, argsFiles, options.signal, options.fileReadTimeoutMs);
|
|
1769
2112
|
const graders = output ? [output] : [];
|
|
1770
2113
|
for (const grader of one.graders) {
|
|
1771
2114
|
stopped();
|