@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
|
@@ -22,6 +22,7 @@ import { CAP_REFUSED, CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_O
|
|
|
22
22
|
import { raiseFollowUpId } from "../run-view.js";
|
|
23
23
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
24
24
|
import { genAiTracing } from "../otel/tracer.js";
|
|
25
|
+
import { tracedAgent, tracedEvent, tracedModel } from "../otel/genai.js";
|
|
25
26
|
/** The root entries a claim writes before its turn, whatever the run's turns are (its session's key, a phase row, a
|
|
26
27
|
* takeover's note, its computer's hold, the learning seed it laid, the computer it made): read past when a claim asks
|
|
27
28
|
* whether the run's root ends on its end (a fresh reopen). */
|
|
@@ -45,7 +46,7 @@ import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
|
|
|
45
46
|
import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
|
|
46
47
|
import { ADAPTER_API } from "../turn-end.js";
|
|
47
48
|
import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
|
|
48
|
-
import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
|
|
49
|
+
import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, REAL_TIMER, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
|
|
49
50
|
import { outputMiss, outputRetryWords } from "../answer-json.js";
|
|
50
51
|
import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
|
|
51
52
|
import { isComputerCommand, journalHold } from "./computer-journal.js";
|
|
@@ -67,23 +68,10 @@ import { Fenced } from "../store/index.js";
|
|
|
67
68
|
import { answerAsServed } from "../answer-json.js";
|
|
68
69
|
import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
|
|
69
70
|
import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
|
|
71
|
+
import { LEARNED_NODES } from "../learned-nodes.js";
|
|
70
72
|
import { warnHoldShort } from "../print.js";
|
|
71
73
|
import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
|
|
72
74
|
import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
73
|
-
/** What a session's requests were charged (sessionSpendOf's figures of those answered, a crash's cut one at its hold among
|
|
74
|
-
* them), never one still in flight at its hold. Null: one charged has no figure. */
|
|
75
|
-
function chargedOf(records) {
|
|
76
|
-
const read = sessionSpendOf(records);
|
|
77
|
-
let usd = 0;
|
|
78
|
-
for (const figure of read.figures) {
|
|
79
|
-
if (!read.answered.has(figure.turn))
|
|
80
|
-
continue;
|
|
81
|
-
if (figure.usd === null)
|
|
82
|
-
return null;
|
|
83
|
-
usd += figure.usd;
|
|
84
|
-
}
|
|
85
|
-
return usd;
|
|
86
|
-
}
|
|
87
75
|
/** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
|
|
88
76
|
* and the harness's next call runs it. */
|
|
89
77
|
export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool runs it on its next call.";
|
|
@@ -840,11 +828,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
840
828
|
* input's user entry left as pi writes it (its submission, which a re-claim answers from, unchanged), so the Timeline
|
|
841
829
|
* shows the next user entry with exactly this text as "AgentRun: …". Once per follow-up: the marker names its request
|
|
842
830
|
* id, and a re-claim that finds one under it writes none (a second would stay open, and could take a person's later
|
|
843
|
-
* message of the same words for the server's). A CLI's run records its follow-up
|
|
844
|
-
* the origin
|
|
831
|
+
* message of the same words for the server's). A CLI's run records its follow-up in its own record, written here with
|
|
832
|
+
* the origin (once under its request id, as the output retry's is), since the CLI's session keeps no user entry. */
|
|
845
833
|
const markServerFollowUp = async (theHarness, theRoot, text, requestId) => {
|
|
846
834
|
if (cliRecord)
|
|
847
|
-
return;
|
|
835
|
+
return await cliRecord.followUp(text, requestId, CAP_RAISED_ORIGIN);
|
|
848
836
|
const marked = (await entriesOf(gate.journal, theRoot.id, context)).some((entry) => entry.kind === MESSAGE_ORIGIN && entry.data?.requestId === requestId);
|
|
849
837
|
if (marked)
|
|
850
838
|
return;
|
|
@@ -1359,7 +1347,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1359
1347
|
};
|
|
1360
1348
|
/** run(claim), its trace ended with it: every span still open ends, with the claim's failure where it failed, handed to
|
|
1361
1349
|
* the exporter, which sends it in the background (tracer.ts: the claim's end never waits on a collector, and never
|
|
1362
|
-
* throws). */
|
|
1350
|
+
* throws). In a run's own process the end is posted to its runner, which exports; neither side flushes for it. */
|
|
1363
1351
|
async function traced(claim) {
|
|
1364
1352
|
try {
|
|
1365
1353
|
const end = await run(claim);
|
|
@@ -1569,8 +1557,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1569
1557
|
}
|
|
1570
1558
|
// The run's trace, from its claim's start, once its spec says what runs (a restart's spec changes nothing of it).
|
|
1571
1559
|
// The tracing is made long before (as the loop is): waited for only on the rare claim whose spec beat it.
|
|
1572
|
-
trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt
|
|
1573
|
-
|
|
1560
|
+
trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt });
|
|
1561
|
+
// Its agent, as the spec read it from the store, cut by the runner's redactor and of every secret shape (tracedAgent).
|
|
1562
|
+
const { agent, ...route } = spec.trace ?? {};
|
|
1563
|
+
trace?.known({ runId: claim.runId, ...(agent ? { agent: tracedAgent(agent, deps.redact) } : {}), harness: spec.adapter.id, ...(spec.facts?.wire === "plan" ? { plan: true } : {}), ...route });
|
|
1574
1564
|
mcp = spec.mcp;
|
|
1575
1565
|
specNow = spec;
|
|
1576
1566
|
specKnown = true;
|
|
@@ -1661,13 +1651,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1661
1651
|
for (const key of await sessions.keys()) {
|
|
1662
1652
|
if (key === spec.session.key)
|
|
1663
1653
|
continue;
|
|
1664
|
-
const
|
|
1654
|
+
const read = sessionSpendOf(await sessions.read(key));
|
|
1655
|
+
const spent = settled ? read.chargedUsd : read.spentUsd;
|
|
1665
1656
|
if (spent === null)
|
|
1666
1657
|
return undefined;
|
|
1667
1658
|
others += spent;
|
|
1668
1659
|
}
|
|
1669
1660
|
if (settled) {
|
|
1670
|
-
const own =
|
|
1661
|
+
const own = sessionSpendOf(await sessions.read(spec.session.key)).chargedUsd;
|
|
1671
1662
|
return own === null ? undefined : overCapEnd(others + own, cap);
|
|
1672
1663
|
}
|
|
1673
1664
|
// Its model session read as the cap reads it (the kernel's overCapOf: a request cut by a crash at its hold plus its
|
|
@@ -1874,9 +1865,16 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1874
1865
|
return reserveOf(requestFigures(asked));
|
|
1875
1866
|
};
|
|
1876
1867
|
let bookingNow;
|
|
1877
|
-
// The
|
|
1878
|
-
//
|
|
1879
|
-
|
|
1868
|
+
// The computer's notes, in order, each until a request carrying it is answered: the replaced computer's
|
|
1869
|
+
// (spec.computerNote), then where the run's files are (spec.computerFilesNote), unless a COMPUTER_NOTE row marked
|
|
1870
|
+
// `files` says an earlier claim told it. One note per request: the replaced computer's goes before the wrap-up, so
|
|
1871
|
+
// the wrap-up waits a request; the files note goes after a wrap-up that is due, so it never holds one back.
|
|
1872
|
+
const filesTold = spec.computerFilesNote !== undefined && (await entriesOf(gate.journal, wrapUpRoot.id, context))
|
|
1873
|
+
.some((entry) => entry.kind === COMPUTER_NOTE && entry.data?.files === true);
|
|
1874
|
+
const computerNotes = [
|
|
1875
|
+
...(spec.computerNote !== undefined ? [{ words: spec.computerNote }] : []),
|
|
1876
|
+
...(spec.computerFilesNote !== undefined && !filesTold ? [{ words: spec.computerFilesNote, files: true }] : []),
|
|
1877
|
+
];
|
|
1880
1878
|
// The server's note a request carries (the replaced computer's, else the cap's wrap-up; `cap` says the wrap-up's
|
|
1881
1879
|
// figures), one request at a time: from its take until that request's admission ends, then, admitted carrying it
|
|
1882
1880
|
// (`turn`), until that request ends. Told once that request is answered (afterRequest); given back for the next
|
|
@@ -1889,7 +1887,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1889
1887
|
const takeNote = (model, asked) => {
|
|
1890
1888
|
if (carried && (carried.turn !== undefined || Date.now() - carried.at < WRAP_UP_OFFER_MS))
|
|
1891
1889
|
return undefined;
|
|
1892
|
-
const
|
|
1890
|
+
const first = reflecting ? undefined : computerNotes[0];
|
|
1891
|
+
const note = first !== undefined && !first.files ? first : (wrapUpNote(model, asked) ?? first);
|
|
1893
1892
|
carried = note ? { ...note, at: Date.now() } : undefined;
|
|
1894
1893
|
return note?.words;
|
|
1895
1894
|
};
|
|
@@ -1907,10 +1906,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1907
1906
|
what = "the free-limit wrap-up's row";
|
|
1908
1907
|
}
|
|
1909
1908
|
else if (told.cap === undefined) {
|
|
1910
|
-
|
|
1909
|
+
if (computerNotes[0]?.words === told.words)
|
|
1910
|
+
computerNotes.shift();
|
|
1911
1911
|
kind = COMPUTER_NOTE;
|
|
1912
|
-
data = { words: rowWords(told.words) };
|
|
1913
|
-
what = "the replaced computer's note row";
|
|
1912
|
+
data = { words: rowWords(told.words), ...(told.files ? { files: true } : {}) };
|
|
1913
|
+
what = told.files ? "the computer files note's row" : "the replaced computer's note row";
|
|
1914
1914
|
}
|
|
1915
1915
|
else {
|
|
1916
1916
|
const { leftUsd, capUsd } = told.cap;
|
|
@@ -2195,8 +2195,9 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2195
2195
|
},
|
|
2196
2196
|
});
|
|
2197
2197
|
// A call a stop cut answers whatever its tool said of the abort: it ends interrupted, never as its outcome.
|
|
2198
|
+
// A nesting tool that ended at a refused nested call (a script stopped there) ends refused, as that call did.
|
|
2198
2199
|
if (record)
|
|
2199
|
-
await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.isError ? "failed" : "done", answer.text);
|
|
2200
|
+
await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.refused && answer.isError ? "refused" : answer.isError ? "failed" : "done", answer.text);
|
|
2200
2201
|
// A CLI's question to the person (a turn-ending tool's call, answered): its turn is cut at its next request,
|
|
2201
2202
|
// as pi's ends here (TurnCut). Any other call's end after it lets the turn go on.
|
|
2202
2203
|
if (record && endsTurn(tool.name) && !answer.isError && !stopAbort.signal.aborted)
|
|
@@ -2296,8 +2297,16 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2296
2297
|
carried = undefined;
|
|
2297
2298
|
}
|
|
2298
2299
|
unbooked += 1;
|
|
2299
|
-
|
|
2300
|
-
|
|
2300
|
+
// Its chat span names the model asked only when the run knows it (a route's model, or one its price table names by
|
|
2301
|
+
// that same id: a CLI's table prices every id as the session's model, so a priced id alone proves nothing, and a
|
|
2302
|
+
// body's model is the client's words), else its route's model; whichever, cut (genai.ts tracedModel).
|
|
2303
|
+
if (ticket && trace && request.paid === undefined) {
|
|
2304
|
+
const traced = specNow?.trace;
|
|
2305
|
+
const routed = request.route === undefined ? traced?.model : traced?.routes?.get(request.route)?.model;
|
|
2306
|
+
const known = (asked) => asked === traced?.model || [...(traced?.routes?.values() ?? [])].some((via) => via.model === asked) || specNow?.runCap.modelOf(asked)?.id === asked;
|
|
2307
|
+
const model = tracedModel(request.model, { known, ...(routed ? { routed } : {}), ...(deps.redact ? { redact: deps.redact } : {}) });
|
|
2308
|
+
chats.set(ticket.turn, trace.request(model, request.route));
|
|
2309
|
+
}
|
|
2301
2310
|
// The conversation that asked, as its client named it (pi's, one of several asking at once): whose answer reads
|
|
2302
2311
|
// this request's booking (bookedCost).
|
|
2303
2312
|
const conversation = request.conversation;
|
|
@@ -2471,7 +2480,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2471
2480
|
// Every harness's events reach its trace first (its tool calls, a plan harness's turns), with a record or without.
|
|
2472
2481
|
const recorded = record ? onEvent(record) : undefined;
|
|
2473
2482
|
const traceAnd = (event) => {
|
|
2474
|
-
trace?.event(event);
|
|
2483
|
+
trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, ...(deps.redact ? { redact: deps.redact } : {}) }));
|
|
2475
2484
|
recorded?.(event);
|
|
2476
2485
|
};
|
|
2477
2486
|
const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: bridgeGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
|
|
@@ -2749,13 +2758,6 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2749
2758
|
memo: async (_key, value) => (typeof value === "function" ? value() : value),
|
|
2750
2759
|
});
|
|
2751
2760
|
const serveFirst = async (first) => {
|
|
2752
|
-
// The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
|
|
2753
|
-
// cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
|
|
2754
|
-
const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
|
|
2755
|
-
if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
|
|
2756
|
-
return undefined;
|
|
2757
|
-
const { nests: _nests, ...plain } = bare;
|
|
2758
|
-
const learned = hosted(plain);
|
|
2759
2761
|
const [on, theRoot, theGate] = [harness, root, gate];
|
|
2760
2762
|
const args = { name: first.name, input: first.input };
|
|
2761
2763
|
const call = { callId: WORKFLOW_FIRST_CALL, tool: LEARNED_WORKFLOW_TOOL, args };
|
|
@@ -2779,9 +2781,17 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2779
2781
|
if (kept?.outcome === "answered")
|
|
2780
2782
|
return { outcome: "answered", text: ended?.output ?? "" };
|
|
2781
2783
|
// Handed back on an earlier claim whose handback never reached the agent (the session is still new): sent now, in
|
|
2782
|
-
// the words that claim would have sent (its why included)
|
|
2784
|
+
// the words that claim would have sent (its why included), with or without the tool now (the money rule may have
|
|
2785
|
+
// taken the workflow off it since: workflow-first.ts toolStopsOf).
|
|
2783
2786
|
if (kept)
|
|
2784
2787
|
return job(ended ? taken(recorded(ended)).text : "");
|
|
2788
|
+
// The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
|
|
2789
|
+
// cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
|
|
2790
|
+
const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
|
|
2791
|
+
if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
|
|
2792
|
+
return undefined;
|
|
2793
|
+
const { nests: _nests, ...plain } = bare;
|
|
2794
|
+
const learned = hosted(plain);
|
|
2785
2795
|
if (!ended) {
|
|
2786
2796
|
// A deny before anything is written leaves the run its agent's, as if the workflow were not there.
|
|
2787
2797
|
const before = await spec.gate?.({ callId: call.callId, tool: call.tool, args });
|
|
@@ -2793,6 +2803,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2793
2803
|
await rec.person(spec.input);
|
|
2794
2804
|
}
|
|
2795
2805
|
let answer;
|
|
2806
|
+
// Refused at its gate, on this claim or the one before: it ran nothing.
|
|
2807
|
+
let refused = ended?.status === "refused";
|
|
2796
2808
|
if (ended)
|
|
2797
2809
|
answer = recorded(ended);
|
|
2798
2810
|
else {
|
|
@@ -2807,6 +2819,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2807
2819
|
else
|
|
2808
2820
|
await rec.refused(WORKFLOW_FIRST_CALL, LEARNED_WORKFLOW_TOOL, args, false, verdict.deny);
|
|
2809
2821
|
answer = { text: verdict.deny, isError: true };
|
|
2822
|
+
refused = true;
|
|
2810
2823
|
}
|
|
2811
2824
|
else {
|
|
2812
2825
|
// A CLI's record takes the call's start and end inside the wrapper; pi's step record here.
|
|
@@ -2823,9 +2836,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2823
2836
|
answer = taken(answer);
|
|
2824
2837
|
const outcome = answer.isError ? "handed_back" : "answered";
|
|
2825
2838
|
const data = { workflow: first.name, digest: first.digest, ...(first.promotion !== undefined ? { promotion: first.promotion } : {}), revision: first.revision, call: WORKFLOW_FIRST_CALL, outcome };
|
|
2839
|
+
// A call refused at its gate keeps its record as one the tool refused does (learned-nodes.ts LEARNED_NODES
|
|
2840
|
+
// `refused`): no workflow ran it, so the money rule charges none and the run names none.
|
|
2841
|
+
const refusal = refused ? { call: WORKFLOW_FIRST_CALL, workflow: first.name, digest: first.digest, caller: "platform", nodes: [], ended: "failed", refused: true } : undefined;
|
|
2826
2842
|
await on.commit(async (tx) => {
|
|
2827
2843
|
if (outcome === "answered")
|
|
2828
2844
|
await tx.appendEntry(theRoot.id, { kind: KINDS.message, data: { role: "model", text: answer.text, at: now() } });
|
|
2845
|
+
if (refusal)
|
|
2846
|
+
await tx.appendEntry(theRoot.id, { kind: LEARNED_NODES, data: refusal });
|
|
2829
2847
|
await tx.appendEntry(theRoot.id, { kind: WORKFLOW_FIRST, data: data });
|
|
2830
2848
|
}, context);
|
|
2831
2849
|
return outcome === "answered" ? { outcome, text: answer.text } : job(answer.text);
|
|
@@ -2835,9 +2853,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2835
2853
|
// under way (the handback sent) never runs it again.
|
|
2836
2854
|
let served;
|
|
2837
2855
|
// A workflow this run already served or handed back on an earlier claim (its end on the root): recovered whatever the
|
|
2838
|
-
// money rule says now, so a crash before the handback never
|
|
2839
|
-
|
|
2840
|
-
const
|
|
2856
|
+
// money rule says now (its stop, or its fail-closed read of an unreadable past), so a crash before the handback never
|
|
2857
|
+
// makes the agent redo finished work. Only a run that learns keeps one.
|
|
2858
|
+
const keptFirst = spec.workflowFirst || !spec.learningLaid || followedUp || firstUnplaced || session.state !== "new" ? undefined : findData(await entriesOf(gate.journal, root.id, context), WORKFLOW_FIRST, () => true);
|
|
2859
|
+
const recovered = keptFirst && keptFirst.outcome !== "needs_revision" ? { name: keptFirst.workflow, digest: keptFirst.digest, revision: keptFirst.revision, input: {}, ...(spec.outputSchema !== undefined ? { outputSchema: spec.outputSchema } : {}) } : undefined;
|
|
2841
2860
|
const firstToServe = spec.workflowFirst ?? recovered;
|
|
2842
2861
|
// A fitting workflow the money rule stopped: why, on the root, once for the run, as the agent takes it.
|
|
2843
2862
|
if (spec.workflowRevise && !followedUp && !firstUnplaced && session.state === "new") {
|
|
@@ -3229,7 +3248,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3229
3248
|
return { deny: wrapUpDeny };
|
|
3230
3249
|
// A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
|
|
3231
3250
|
const replayed = call.replayed === true;
|
|
3232
|
-
const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf })) ?? "allow";
|
|
3251
|
+
const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf, approved: approvedOf })) ?? "allow";
|
|
3233
3252
|
// An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape), or
|
|
3234
3253
|
// with the reason a call its setting allows asks anyway (`because`).
|
|
3235
3254
|
const shown = typeof given === "object" && "ask" in given ? given.ask : undefined;
|
|
@@ -3423,6 +3442,17 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3423
3442
|
async function ranOf(tool) {
|
|
3424
3443
|
return toolCalls(await agentEntriesOf(gate.journal, context), tool);
|
|
3425
3444
|
}
|
|
3445
|
+
/** Whether a person approved the call `callId`, as answerOf reads it: its answer in the journal stands; else the
|
|
3446
|
+
* approve or deny for it among the claim's commands (read once they are all with the loop, deps.delivered), which
|
|
3447
|
+
* answerOf takes next. */
|
|
3448
|
+
async function approvedOf(callId) {
|
|
3449
|
+
const conversation = await harness.root(context);
|
|
3450
|
+
const known = findData(await entriesOf(gate.journal, conversation.id, context), KINDS.answer, (data) => data.callId === callId);
|
|
3451
|
+
if (known)
|
|
3452
|
+
return known.approved;
|
|
3453
|
+
await (deps.delivered ?? Promise.resolve());
|
|
3454
|
+
return inbox.find((command) => (command.kind === "approve" || command.kind === "deny") && approvalOf(command) === callId)?.kind === "approve";
|
|
3455
|
+
}
|
|
3426
3456
|
async function askStands(callId) {
|
|
3427
3457
|
standing ??= (async () => {
|
|
3428
3458
|
const conversation = await harness.root(context);
|
|
@@ -3563,10 +3593,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3563
3593
|
return turnOfRequest(on, conversation, last.requestId);
|
|
3564
3594
|
}
|
|
3565
3595
|
/** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
|
|
3566
|
-
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (
|
|
3567
|
-
* its time, now, which it answers; with no step to ask, nothing is kept. */
|
|
3596
|
+
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (its spec's endOfRun).
|
|
3597
|
+
* Kept with its time, now, which it answers; with no step to ask, nothing is kept. */
|
|
3568
3598
|
async function keepJobEnd(on, conversation, spec, data, failedWith) {
|
|
3569
|
-
if (!
|
|
3599
|
+
if (!spec.endOfRun)
|
|
3570
3600
|
return undefined;
|
|
3571
3601
|
const kept = jobEndOf(data, failedWith, now());
|
|
3572
3602
|
await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
|
|
@@ -3740,9 +3770,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3740
3770
|
return kept && typeof kept === "object" && !Array.isArray(kept) ? kept : undefined;
|
|
3741
3771
|
};
|
|
3742
3772
|
}
|
|
3743
|
-
/** The
|
|
3744
|
-
const stepOf = (spec) => spec.endOfRun ?? deps.endOfRun;
|
|
3745
|
-
/** The end-of-run step (stepOf: the spec's, else LoopDeps.endOfRun), asked once: the rows to stage with the end; `stopped` when a person's stop
|
|
3773
|
+
/** The end-of-run step (its spec's endOfRun; none without one), asked once: the rows to stage with the end; `stopped` when a person's stop
|
|
3746
3774
|
* came during it; `interrupted` when the claim was lost or the runner is closing (no end is written, and the next claim
|
|
3747
3775
|
* asks it again). A step that throws on its own writes the end without rows: the run's end never waits on it. `over`:
|
|
3748
3776
|
* the claim's overCap, read after each turn the step asks (askEndOfRun). */
|
|
@@ -3754,7 +3782,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3754
3782
|
return { kind: "interrupted" };
|
|
3755
3783
|
return undefined;
|
|
3756
3784
|
};
|
|
3757
|
-
const step =
|
|
3785
|
+
const step = spec.endOfRun;
|
|
3758
3786
|
if (!step)
|
|
3759
3787
|
return { kind: "rows", also: [] };
|
|
3760
3788
|
if (!spec.agentId)
|
|
@@ -3780,11 +3808,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3780
3808
|
return cut() ?? (console.warn(`[runner] ${claim.runId}: its end-of-run step failed: ${said(error)}`), { kind: "rows", also: [] });
|
|
3781
3809
|
}
|
|
3782
3810
|
}
|
|
3783
|
-
/** What a run cut before it could look back keeps beside its end (
|
|
3811
|
+
/** What a run cut before it could look back keeps beside its end (its spec's endOfRun with `cut`, never asking): a
|
|
3784
3812
|
* person's stop, before or during the end-of-run turn, or a fault. Bounded (CUT_STEP_MS): a step that reads a stalled
|
|
3785
3813
|
* store, or throws, keeps nothing, and the end is never held up by it. */
|
|
3786
3814
|
async function cutRows(claim, spec, cut) {
|
|
3787
|
-
const step =
|
|
3815
|
+
const step = spec.endOfRun;
|
|
3788
3816
|
if (!step || !spec.agentId)
|
|
3789
3817
|
return [];
|
|
3790
3818
|
const refuse = () => Promise.reject(new Error("a cut run's end-of-run step asks nothing"));
|
|
@@ -3899,9 +3927,9 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3899
3927
|
const spec = specNow;
|
|
3900
3928
|
if (!spec?.endPatch && !spec?.endCost)
|
|
3901
3929
|
return {};
|
|
3930
|
+
const bound = spec.endPatchTimer ?? REAL_TIMER;
|
|
3902
3931
|
let timer;
|
|
3903
|
-
const
|
|
3904
|
-
const late = new Promise((resolve) => (timer = setTimeout(() => resolve("late"), boundMs)));
|
|
3932
|
+
const late = new Promise((resolve) => (timer = bound.setTimeout(() => resolve("late"), END_PATCH_MS)));
|
|
3905
3933
|
// The cost, read apart (AdapterRunSpec.endCost): a patch whose metrics run late or fail never takes it with them. A
|
|
3906
3934
|
// read that fails is read again within the same bound (END_COST_TRIES): the stored cost is every reader's answer
|
|
3907
3935
|
// (the list, the view, usage), so a null there is kept only when the booking could not be read at all.
|
|
@@ -3909,7 +3937,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3909
3937
|
const cost = endCost
|
|
3910
3938
|
? readAgain(endCost, late, (error, tries, last) => console.warn(last ? `[runner] its end's cost failed ${tries} times, last: ${said(error)}; the end is written with its cost unknown` : `[runner] its end's cost failed: ${said(error)}; read again`)).then((answer) => {
|
|
3911
3939
|
if (answer === "late")
|
|
3912
|
-
console.warn(`[runner] its end's cost gave no answer within ${
|
|
3940
|
+
console.warn(`[runner] its end's cost gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its cost unknown`);
|
|
3913
3941
|
return answer === "late" || answer === "failed" ? { costUsd: null, costUpperBound: false } : answer;
|
|
3914
3942
|
})
|
|
3915
3943
|
: undefined;
|
|
@@ -3919,7 +3947,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3919
3947
|
try {
|
|
3920
3948
|
const patch = await Promise.race([spec.endPatch(data), late]);
|
|
3921
3949
|
if (patch === "late") {
|
|
3922
|
-
console.warn(`[runner] its end's patch gave no answer within ${
|
|
3950
|
+
console.warn(`[runner] its end's patch gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its ${cost ? "metrics" : "cost and metrics"} unknown`);
|
|
3923
3951
|
return END_PATCH_UNKNOWN;
|
|
3924
3952
|
}
|
|
3925
3953
|
return patch ?? {};
|
|
@@ -3934,7 +3962,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3934
3962
|
return read ? { ...patch, ...read } : patch;
|
|
3935
3963
|
}
|
|
3936
3964
|
finally {
|
|
3937
|
-
clearTimeout(timer);
|
|
3965
|
+
bound.clearTimeout(timer);
|
|
3938
3966
|
}
|
|
3939
3967
|
}
|
|
3940
3968
|
/** The run parked at its cap: its pending budget as an agentrun.budget entry, in one commit with the run parked in the
|
|
@@ -4035,12 +4063,18 @@ function adapterLoop(specOf, options, deps) {
|
|
|
4035
4063
|
}
|
|
4036
4064
|
/** At a park for `cause`, before its seal: a pass whose spec keeps its computer (AdapterRunSpec.keptWords) has it kept
|
|
4037
4065
|
* for the resume at its release (closeSession), once the run's timeline says so, for the person deciding; its owner's
|
|
4038
|
-
* live view is closed saying the cause.
|
|
4039
|
-
*
|
|
4066
|
+
* live view is closed saying the cause. The keep's row is written first (AdapterRunSpec.keep), under the claim's
|
|
4067
|
+
* fence: a park that keeps nothing (another runner's row still there, a write that failed, a claim that lost the run
|
|
4068
|
+
* and so writes nothing) says nothing of a keep, and its computer goes as at
|
|
4069
|
+
* the run's end. A commit that fails (the fence's refusal: a lost claim, whose run a later claim may hold already)
|
|
4070
|
+
* keeps nothing either: the computer goes as at the run's end, and its row with it. */
|
|
4040
4071
|
async function keepAtPark(on, cause) {
|
|
4041
|
-
const summary = specNow?.keptWords;
|
|
4072
|
+
const summary = specNow?.keptWords?.();
|
|
4042
4073
|
if (!summary)
|
|
4043
4074
|
return;
|
|
4075
|
+
const keep = specNow?.keep;
|
|
4076
|
+
if (keep && !(await keep().catch(() => false)))
|
|
4077
|
+
return;
|
|
4044
4078
|
parkedNow = await on.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary, at: Date.now() } }), context).then(() => cause, () => undefined);
|
|
4045
4079
|
}
|
|
4046
4080
|
/** The run's pause at its cap: its agentrun.budget entry, in one commit with the run parked in the cap's words. */
|
|
@@ -20,6 +20,7 @@ import { type ClaimModelKey } from "./claim-secrets.js";
|
|
|
20
20
|
import { type ClaimMcp } from "./mcp-run.js";
|
|
21
21
|
import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
|
|
22
22
|
import { type RunnerHarness } from "./adapters/index.js";
|
|
23
|
+
import { type BoundTimer } from "./loop.js";
|
|
23
24
|
import { type SubagentTier } from "./subagent.js";
|
|
24
25
|
import { type Claim, type Journal } from "./loop-contract.js";
|
|
25
26
|
import type { ReplayCalls } from "../learn/replay-calls.js";
|
|
@@ -67,6 +68,8 @@ export interface ClaimComputer {
|
|
|
67
68
|
release(): Promise<void>;
|
|
68
69
|
/** The release at the run's park, which keeps the computer it `keeps` (computer-for-claim.ts ClaimComputer.park). */
|
|
69
70
|
park?(): Promise<boolean>;
|
|
71
|
+
/** The park's keep written before the run's timeline says it (computer-for-claim.ts ClaimComputer.keepRow). */
|
|
72
|
+
keepRow?(): Promise<boolean>;
|
|
70
73
|
}
|
|
71
74
|
/** The one shared claim-time computer every spec takes (computer-for-claim.ts), passed in by the runner: the composer's
|
|
72
75
|
* (workspace/computer-deps.ts computerDepsFrom), or a test's stand-in. */
|
|
@@ -102,6 +105,9 @@ export interface AdapterSpecDeps {
|
|
|
102
105
|
readonly log?: (message: string) => void;
|
|
103
106
|
/** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
|
|
104
107
|
readonly gradeBound?: () => AbortSignal;
|
|
108
|
+
/** For tests: the timer a native or SDK run's end arms its bound on (END_PATCH_MS, loop.ts) while it waits on its cost
|
|
109
|
+
* and metrics read, as the adapter loop's spec.endPatchTimer. Default: the real one (REAL_TIMER). */
|
|
110
|
+
readonly endPatchTimer?: BoundTimer;
|
|
105
111
|
/** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
|
|
106
112
|
* The runner gives it; a test gives its own. */
|
|
107
113
|
readonly computerForClaim: ComputerForClaim;
|
|
@@ -159,6 +165,9 @@ export interface AdapterSpecDeps {
|
|
|
159
165
|
* on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
|
|
160
166
|
* it; absent, MODEL_RETRY and MODEL_STREAM. */
|
|
161
167
|
readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
|
|
168
|
+
/** The runs' GenAI tracing (AdapterLoopOptions.tracing): in a run's own process, the one posted to its runner
|
|
169
|
+
* (run-child.ts); absent, this process's own. */
|
|
170
|
+
readonly tracing?: AdapterLoopOptions["tracing"];
|
|
162
171
|
/** web_save's download slots (ToolHost.saveSlots): in a run's own process, its runner's (run-child.ts). */
|
|
163
172
|
readonly saveSlots?: SaveSlots;
|
|
164
173
|
}
|
|
@@ -200,23 +209,30 @@ export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>)
|
|
|
200
209
|
* translates its model's requests (its own `fetch`) is named by its upstream's host (ModelRoute.upstreamOrigin), never
|
|
201
210
|
* its proxy's placeholder origin; one whose upstream is unknown names no host. */
|
|
202
211
|
export declare const traceOfRoute: (route: ModelRoute) => import("../otel/genai.js").RouteTrace;
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
|
|
211
|
-
* provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
|
|
212
|
-
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone; in a run's own
|
|
213
|
-
* process its runner hands it the fast model's provider's keys alone (run-child-host.ts savedModelKeys, graderModelOf). A
|
|
214
|
-
* run with its own model key carries that key, and no saved key is read. Undefined when there is no fast model, the
|
|
215
|
-
* revision names agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
212
|
+
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): on the fast tier routedSubagentTiers names
|
|
213
|
+
* (the revision's modelTiers.fast, else AGENT_MODEL_FAST), on pi's wires, when its revision names no agree_on. Its route
|
|
214
|
+
* reads the saved key of that tier's model alone (subagentTierKeys), held by the run's redactors, on the route's env
|
|
215
|
+
* alone; in a run's own process its runner hands it that tier's model's key (run-child-host.ts subagentTierKeys). A run
|
|
216
|
+
* with its own model key carries that key, and no saved key is read. Undefined, with nothing read, when
|
|
217
|
+
* there is no fast tier or the revision names agree_on; undefined when no route can be made (logged: the pair is then
|
|
218
|
+
* compared whole). */
|
|
216
219
|
export declare function graderRouteOf(body: {
|
|
217
220
|
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
218
221
|
readonly learning?: unknown;
|
|
219
222
|
}, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[], claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<ModelRoute | undefined>;
|
|
223
|
+
/** A subagent run's tier routes (runner/subagent.ts): each tier routedSubagentTiers names, on its model (the revision's
|
|
224
|
+
* modelTiers, else the host's tier variable), under its own key (subagentRoute), on a route of its own. A tier's model may
|
|
225
|
+
* be another provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's
|
|
226
|
+
* model): so the routes read the saved model keys of those tiers' models alone (subagentTierKeys), held by the run's
|
|
227
|
+
* redactor, on the routes' env alone, never the run's tools (toolEnv). A run with its own model key carries that key,
|
|
228
|
+
* and no saved key is read. A tier no route can be made for here is in `why`, cut, and no failure of the run: a call on
|
|
229
|
+
* it answers why. */
|
|
230
|
+
export declare function subagentTierRoutes(body: {
|
|
231
|
+
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
232
|
+
}, keyed: boolean, runKey: ClaimModelKey | undefined, toolEnv: NodeJS.ProcessEnv, cut: HeldRedact, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<{
|
|
233
|
+
readonly routes: Map<string, ModelRoute>;
|
|
234
|
+
readonly why: Map<SubagentTier, string>;
|
|
235
|
+
}>;
|
|
220
236
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
221
237
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
222
238
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -250,7 +266,8 @@ export declare function modelAskOf(pinned: {
|
|
|
250
266
|
* The run's computer once off for the run (RunGate.computerOff): a call of its tools is refused before any settings read.
|
|
251
267
|
* `turnedOff`: an earlier claim turned it off (computer-journal.ts computerTurnedOff), so this claim's gate starts off.
|
|
252
268
|
* `onComputerOff`: told the computer's kind, and awaited, when this claim's first deny of a call of its tools turns it off,
|
|
253
|
-
* for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too.
|
|
269
|
+
* for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too. The gate's
|
|
270
|
+
* `computerOff` says whether it is off now, so a park lets it go instead of keeping it (spec-holds.ts Held.computerOff).
|
|
254
271
|
*/
|
|
255
272
|
/** The run's tool permissions as a learned workflow's call nodes are held to them (learned-workflow.ts policy, denyFrom,
|
|
256
273
|
* refresh): the same gate as the run's own calls, its settings read again from the store before each call node. */
|
|
@@ -262,6 +279,7 @@ export type RunPermissions = {
|
|
|
262
279
|
export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
|
|
263
280
|
kind: string;
|
|
264
281
|
body: {
|
|
282
|
+
tools?: readonly string[];
|
|
265
283
|
toolSettings?: unknown;
|
|
266
284
|
harness?: string;
|
|
267
285
|
approvals?: Approvals;
|
|
@@ -276,6 +294,8 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
|
|
|
276
294
|
readonly permissions: RunPermissions;
|
|
277
295
|
readonly learn: (flows: readonly LearnedWorkflow[]) => void;
|
|
278
296
|
readonly askedOn: (host: ToolHost) => void;
|
|
297
|
+
readonly computerOff: () => boolean; /** Whether the run can write a file now, as its gate decides a save_as (RunGate.writeBar): what its files note and computer_screenshot's save_as are offered by. */
|
|
298
|
+
readonly writes: () => boolean;
|
|
279
299
|
}>;
|
|
280
300
|
/** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
|
|
281
301
|
* and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
|