@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39
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 +418 -0
- package/README.md +325 -124
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +9 -2
- package/dist/learn/compile.js +52 -16
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +106 -51
- package/dist/learn/promote.js +82 -189
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +26 -8
- package/dist/learning-cost.js +17 -7
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +33 -2
- package/dist/local-models.js +43 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +394 -85
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +7 -2
- package/dist/port-models.js +5 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/run-launch.d.ts +10 -1
- package/dist/run-launch.js +11 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +42 -35
- package/dist/run-view.js +79 -44
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +42 -11
- package/dist/runner/adapter-loop.js +651 -247
- package/dist/runner/adapter-run-spec.d.ts +37 -12
- package/dist/runner/adapter-run-spec.js +139 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +94 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +37 -13
- package/dist/runner/journal-kinds.js +9 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +12 -3
- package/dist/runner/model-route.js +139 -18
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +74 -8
- package/dist/runner/promotion.js +365 -124
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +554 -130
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.js +3 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +133 -18
- package/dist/store/store.d.ts +52 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +85 -5
- package/dist/store-reads/learning.js +45 -17
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +70 -20
- package/dist/templates.js +191 -34
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +42 -42
- package/dist/tool-gate.js +97 -91
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +44 -16
- package/dist/tools.js +28 -28
- package/dist/trigger-adapter.d.ts +85 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +228 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +94 -9
- package/dist/triggers.js +263 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
|
@@ -17,53 +17,58 @@ import { mkdir, readdir, rm, rmdir } from "node:fs/promises";
|
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
19
19
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
|
-
import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
20
|
+
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
21
|
+
import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
|
|
21
22
|
import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
|
|
22
23
|
import { claimSettled, installDirOf, installForClaim, installingWords } from "../harness-install.js";
|
|
23
24
|
import { HarnessUnavailable } from "../provider.js";
|
|
24
25
|
import { effortGuidance } from "../effort-guidance.js";
|
|
25
26
|
import { outputContract } from "../answer-json.js";
|
|
26
27
|
import { wireName } from "../catalog.js";
|
|
27
|
-
import { environmentLine } from "../environment.js";
|
|
28
|
+
import { environmentLine, runZone } from "../environment.js";
|
|
28
29
|
import { harnessOf } from "../harness-table.js";
|
|
29
30
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
30
31
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
31
32
|
import { learningWorkspace } from "../learn/folder.js";
|
|
32
33
|
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
33
34
|
import { providerModels, runModels } from "../model.js";
|
|
34
|
-
import { firstMessage, inputMessage } from "../run-manifest.js";
|
|
35
|
+
import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
|
|
35
36
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
36
37
|
import { readsFiles, systemOf } from "../skills.js";
|
|
37
38
|
import { DATA_ENV } from "../server-fs.js";
|
|
38
|
-
import {
|
|
39
|
+
import { placeRunInputs } from "../uploads.js";
|
|
39
40
|
import { runFolder, scratchFolder } from "../workspace/paths.js";
|
|
40
41
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
41
42
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
42
43
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
43
44
|
import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
44
45
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
45
|
-
import {
|
|
46
|
+
import { settingOfDefinition } from "../computer-setting.js";
|
|
47
|
+
import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
48
|
+
import { hadComputer } from "./computer-journal.js";
|
|
46
49
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
47
50
|
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
|
|
48
51
|
import { openTierProxies } from "./adapters/pi.js";
|
|
49
52
|
import { signInReads } from "../sign-ins-store.js";
|
|
50
|
-
import { mcpServersOf } from "../tool-gate.js";
|
|
51
53
|
import { isWebHostTool } from "../tool-list.js";
|
|
52
54
|
import { hostToolOf } from "../host-tools.js";
|
|
53
55
|
import { ASK_TOOL, askPerson } from "../tools.js";
|
|
56
|
+
import { fakedPlane } from "../web-fake.js";
|
|
54
57
|
import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
55
58
|
import { mcpForClaim } from "./mcp-run.js";
|
|
56
59
|
import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
57
60
|
import { decisionProvidersIn } from "../decisions.js";
|
|
58
61
|
import { resolveHarness } from "./adapters/index.js";
|
|
59
62
|
import { entriesOf } from "./loop.js";
|
|
60
|
-
import { bookedSpend, cliModelWorked, cliRunMetrics,
|
|
63
|
+
import { bookedSpend, cliModelWorked, cliRunMetrics, endCostOf, runCostOf } from "./metrics.js";
|
|
61
64
|
import { journalEntries } from "./journal-reader.js";
|
|
65
|
+
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
62
66
|
import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid } from "./promotion.js";
|
|
63
67
|
import { laidFor, pathMetrics, workflowFirstOf } from "./workflow-first.js";
|
|
64
68
|
import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
|
|
65
69
|
import { specBuilt } from "./spec-holds.js";
|
|
66
70
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
71
|
+
import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
|
|
67
72
|
import { heldSpecOf } from "./held-run.js";
|
|
68
73
|
import { loopComputerOf } from "./computer-channel.js";
|
|
69
74
|
import { githubAppAccess } from "./github-app.js";
|
|
@@ -92,8 +97,11 @@ async function modelsOf(entry, env, ref) {
|
|
|
92
97
|
}
|
|
93
98
|
/** The model a CLI run is capped at: the catalog entry that bills it (its entry's priceModel), its cost WITH TIERS (the
|
|
94
99
|
* money rule: a request past a tier is held and booked at it, as main's calculateCost does), on the harness's wire. A
|
|
95
|
-
* model the catalog does not price is held at no price: its requests are unknown, never $0.
|
|
96
|
-
|
|
100
|
+
* model the catalog does not price is held at no price: its requests are unknown, never $0. A ChatGPT plan's model
|
|
101
|
+
* (`plan`) is billed to the plan: the one plan rule (planCapModel), pi's plan route's too (adapter-run-spec.ts capModelOf). */
|
|
102
|
+
export function capModelOf(id, wire, listed, unpriced, plan = false) {
|
|
103
|
+
if (plan)
|
|
104
|
+
return planCapModel(id, wire, typeof listed?.maxTokens === "number" ? listed.maxTokens : null);
|
|
97
105
|
const cost = listed?.cost;
|
|
98
106
|
const price = !unpriced && cost && typeof cost.input === "number" && typeof cost.output === "number"
|
|
99
107
|
? {
|
|
@@ -106,6 +114,19 @@ function capModelOf(id, wire, listed, unpriced) {
|
|
|
106
114
|
: null;
|
|
107
115
|
return { id, api: wire, price, outputCeiling: typeof listed?.maxTokens === "number" ? listed.maxTokens : null };
|
|
108
116
|
}
|
|
117
|
+
/** The model a CLI run of `entry` on `chosen` (modelsOf) is capped at, on its `wire`: the catalog entry that bills it
|
|
118
|
+
* (its entry's priceModel), priced by capModelOf. */
|
|
119
|
+
function chosenCapModel(entry, env, chosen, wire) {
|
|
120
|
+
const priced = entry.priceModel(env, chosen.model);
|
|
121
|
+
const listed = chosen.models.getModel(priced.provider, priced.modelId);
|
|
122
|
+
return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER);
|
|
123
|
+
}
|
|
124
|
+
/** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
|
|
125
|
+
* at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
|
|
126
|
+
* prices its least step on it. */
|
|
127
|
+
export async function cliCapModel(entry, env, ref) {
|
|
128
|
+
return chosenCapModel(entry, env, await modelsOf(entry, env, ref), entry.facts.wire);
|
|
129
|
+
}
|
|
109
130
|
/** A CLI run's environment: the runner's run environment (`env`, runner/main.ts runEnv), built from it itself and never
|
|
110
131
|
* a spread of it, with the model keys the claim opened (`claimed`, withModelKeys) and the server's data directory named
|
|
111
132
|
* (DATA_ENV). The run environment's secrets, and the keys added, are readable by name and never enumerable: the
|
|
@@ -213,6 +234,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
213
234
|
const runRow = await deps.store.runs.get(claim.runId);
|
|
214
235
|
if (!runRow)
|
|
215
236
|
throw new Error(`run ${claim.runId}: its row is gone from the store`);
|
|
237
|
+
// A template eval's fakes for this run (AdapterSpecDeps.evalFakes). Its web fake: its web tools answer from it, and its
|
|
238
|
+
// plane never offers the harness's own search (Claude's WebSearch, Codex's), which would answer in their place.
|
|
239
|
+
const fakes = deps.evalFakes?.(runRow.agentId);
|
|
240
|
+
const web = fakes?.web;
|
|
241
|
+
if (web)
|
|
242
|
+
launch = { ...launch, plane: fakedPlane(launch.plane) };
|
|
216
243
|
// The claim's private folder is swept at the spec's release, the claim's end, then the scratch folder if nothing else is
|
|
217
244
|
// in it, then the agent's: the next claim, here or on another runner, lays its own, its harness's session coming back from
|
|
218
245
|
// the run's journal. Its own per claim (by the claim's epoch), so a run reopened while this claim still lets go (its
|
|
@@ -306,7 +333,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
306
333
|
// Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go. The claim's Archil keys go
|
|
307
334
|
// from memory last, once nothing more reads the disk.
|
|
308
335
|
holds.hold({ archil, keys: archil });
|
|
309
|
-
// The run's Workspace at the claim,
|
|
336
|
+
// The run's Workspace at the claim, its uploaded files copied into work/inputs/ once and its opening message saved
|
|
337
|
+
// there as inputs/message.md (uploads.ts placeRunInputs).
|
|
310
338
|
const ws = archil === undefined
|
|
311
339
|
? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
|
|
312
340
|
: await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
|
|
@@ -314,19 +342,22 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
314
342
|
// The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
|
|
315
343
|
const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
|
|
316
344
|
holds.hold({ checkout });
|
|
317
|
-
|
|
318
|
-
await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
|
|
345
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
|
|
319
346
|
// The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
|
|
320
347
|
// It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
|
|
321
|
-
const
|
|
348
|
+
const claimSignal = run.stopped ?? run.signal;
|
|
349
|
+
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place }, deps.store,
|
|
322
350
|
// revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
|
|
323
351
|
// run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
|
|
324
352
|
// what became of the agent's own computer said on the run's timeline.
|
|
325
353
|
// A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
|
|
326
354
|
// whose computer is a browser is refused in words at its claim, before anything is made.
|
|
327
|
-
|
|
355
|
+
// A person's stop ends the claim's waits at once: a first image pull or registration (Agent37's runs minutes) among them.
|
|
356
|
+
// Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
|
|
357
|
+
// spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount).
|
|
358
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, hadComputer: () => hadComputer(deps.journal(claim), context), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
328
359
|
holds.hold({ computer });
|
|
329
|
-
const loopComputer = loopComputerOf(computer.computer, computer.held);
|
|
360
|
+
const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
|
|
330
361
|
const heldComputer = heldSpecOf(launch, loopComputer);
|
|
331
362
|
// The CLI works in the run's scratch folder on this machine (its working directory), its own files (home, state, the
|
|
332
363
|
// skills laid for it) in this claim's private folder inside it, never on the run's disk. The scratch is an alias of the
|
|
@@ -348,7 +379,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
348
379
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
349
380
|
// Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv), as the pi spec does.
|
|
350
381
|
const bashPolicy = bashPolicyOf(body.toolSettings);
|
|
351
|
-
|
|
382
|
+
// A computer that replaced an earlier claim's holds its acts to what it showed, as the pi spec's does.
|
|
383
|
+
const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
|
|
352
384
|
holds.hold({ tools });
|
|
353
385
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
354
386
|
// The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
|
|
@@ -360,8 +392,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
360
392
|
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
361
393
|
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
|
|
362
394
|
const check = await entry.skillCheck?.();
|
|
363
|
-
// The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts)
|
|
364
|
-
|
|
395
|
+
// The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts), with the kind's
|
|
396
|
+
// skill of a desktop or a phone (the revision's computer setting), in the harness's skill list beside the revision's.
|
|
397
|
+
const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
|
|
365
398
|
// A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
|
|
366
399
|
// the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
|
|
367
400
|
const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
|
|
@@ -378,7 +411,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
378
411
|
...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
|
|
379
412
|
})
|
|
380
413
|
: undefined;
|
|
381
|
-
const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
|
|
414
|
+
const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills, ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
|
|
382
415
|
const guidance = effortGuidance(launch.effort);
|
|
383
416
|
// The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
|
|
384
417
|
// environment main's server gives its runs: the server's data directory named (DATA_ENV), so the CLI's install is
|
|
@@ -392,11 +425,16 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
392
425
|
holdClaimed(redact, claimed);
|
|
393
426
|
const env = cliRunEnv(deps.env, deps.data, claimed, launch.plane);
|
|
394
427
|
const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
|
|
428
|
+
await planBeforeRun(env, chosen.model);
|
|
395
429
|
// The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
|
|
396
430
|
// (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
|
|
397
431
|
// or a command it runs reaches grants nothing; none on macOS. Where setpriv is not usable the run is refused, in pi's words.
|
|
398
432
|
const confine = confineOf(noNewPrivsPrefix());
|
|
399
|
-
|
|
433
|
+
// The run's clock: a template eval case's (EvalFakes.now), else the real one. Its environment line and the harness's own
|
|
434
|
+
// turn date (claude-agent's dateLine) read it.
|
|
435
|
+
const now = fakes?.now;
|
|
436
|
+
const zone = await runZone(deps.store, launch.inputOrigin);
|
|
437
|
+
const built = await entry.adapter(env, { zone, model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}), ...(now ? { now: () => now } : {}) });
|
|
400
438
|
// The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
|
|
401
439
|
// every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
|
|
402
440
|
// the CLI's own error names the harness first, as main words it (harness-app.ts: `<harness>: <error>`), so the run's
|
|
@@ -424,7 +462,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
424
462
|
return Object.assign(session, {
|
|
425
463
|
turnEnd: async () => {
|
|
426
464
|
const end = await turnEnd();
|
|
427
|
-
|
|
465
|
+
// A ChatGPT plan's limit reached is said as it is: it is the plan's, not the harness's.
|
|
466
|
+
return end.error && end.error !== PLAN_LIMIT_WORDS ? { ...end, error: `${name}: ${end.error}` } : end;
|
|
428
467
|
},
|
|
429
468
|
close: async () => {
|
|
430
469
|
await close();
|
|
@@ -440,9 +479,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
440
479
|
};
|
|
441
480
|
// The run's cap (its launch's maxCostUsd): the kernel's check before each paid request, at the catalog price of the
|
|
442
481
|
// model that bills the run, and what a refusal does to the run, with the kernel's raise rule.
|
|
443
|
-
const
|
|
444
|
-
const listed = chosen.models.getModel(priced.provider, priced.modelId);
|
|
445
|
-
const capModel = capModelOf(priced.modelId, facts.wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined);
|
|
482
|
+
const capModel = chosenCapModel(entry, env, chosen, facts.wire);
|
|
446
483
|
const capUsd = launch.maxCostUsd;
|
|
447
484
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
448
485
|
// uncapped), the model that bills this CLI run priced WITH tiers, strict where the launch says. The loop builds the
|
|
@@ -459,9 +496,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
459
496
|
const tierRoute = tierRoutes.get(by);
|
|
460
497
|
return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
|
|
461
498
|
},
|
|
462
|
-
...(launch.capMode === "strict" ? { mode: "strict" } : {}),
|
|
463
499
|
// What its learning runs' grades took beside it, read by every gate with its own sessions (none: it queues none).
|
|
464
500
|
...(besideOf ? { beside: besideOf } : {}),
|
|
501
|
+
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
|
|
502
|
+
freeRequests: freeModelRequestsOf(deps.env),
|
|
465
503
|
};
|
|
466
504
|
const cap = capUsd === undefined
|
|
467
505
|
? undefined
|
|
@@ -474,13 +512,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
474
512
|
};
|
|
475
513
|
// The gate before a call's intent, the same as the pi spec: the revision's tool settings over the store's, read from the
|
|
476
514
|
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
477
|
-
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
478
|
-
// (mcpServersOf its grants) hold a harness's own name for an MCP tool to that tool's settings.
|
|
515
|
+
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
479
516
|
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
480
|
-
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell,
|
|
481
|
-
// What a script's shell and files are held to: this gate's settings, decided as on the run's computer (gate.script), so a
|
|
482
|
-
// denied bash or write holds inside computer_script too.
|
|
483
|
-
tools.computer?.guard.install(gate.script);
|
|
517
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {});
|
|
484
518
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
485
519
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
486
520
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -497,7 +531,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
497
531
|
const held = run.redact ? heldRedactor(run.redact) : cut;
|
|
498
532
|
// The run's monid endpoints (monid-run.ts), one host tool each from its revision's pin, on the claim's keys and beside
|
|
499
533
|
// its MCP tools in the loop's one catalog seam; their answers pass the redactors as the web tools' do.
|
|
500
|
-
const monid = monidForClaim(
|
|
534
|
+
const monid = monidForClaim(revisionRow.monidPin ?? undefined, { ...claimed }, () => ws.workspace, claim.runId, () => launch.maxCostUsd !== undefined, fakes?.monid);
|
|
501
535
|
const catalog = withMonid(mcp, monid && { ...monid, tools: monid.tools.map((tool) => answersCut(tool, held)) });
|
|
502
536
|
const webNames = granted.filter(isWebHostTool);
|
|
503
537
|
let learnedTool;
|
|
@@ -517,7 +551,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
517
551
|
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
|
|
518
552
|
})), revision.body.outputSchema) : {};
|
|
519
553
|
// A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
|
|
520
|
-
await replayClaimed(deps.store, runRow.agentId, launch, firstChoice);
|
|
554
|
+
await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
|
|
521
555
|
// A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
|
|
522
556
|
// answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
|
|
523
557
|
const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
|
|
@@ -543,7 +577,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
543
577
|
toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
|
|
544
578
|
if (webNames.length) {
|
|
545
579
|
life = hostLifecycle();
|
|
546
|
-
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held });
|
|
580
|
+
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}) });
|
|
547
581
|
webTools = await webHostTools(host, granted, ctx);
|
|
548
582
|
}
|
|
549
583
|
if (learns) {
|
|
@@ -577,7 +611,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
577
611
|
const session = {
|
|
578
612
|
key: `run:${claim.runId}`,
|
|
579
613
|
label: runRow.agentId,
|
|
580
|
-
system: [environmentLine(), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
|
|
614
|
+
system: [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
|
|
581
615
|
// The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
|
|
582
616
|
// redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
|
|
583
617
|
tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
|
|
@@ -632,6 +666,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
632
666
|
agentId: runRow.agentId,
|
|
633
667
|
// The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
|
|
634
668
|
...(loopComputer ? { computer: loopComputer } : {}),
|
|
669
|
+
// A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
|
|
670
|
+
...(tools.computer ? { scriptComputer: tools.computer } : {}),
|
|
671
|
+
// A computer that replaced an earlier claim's: the model is told once, on its next request (the loop's computer note).
|
|
672
|
+
...(computer.replaced ? { computerNote: computerReplacedNote(computer.replaced) } : {}),
|
|
635
673
|
workRoot: root,
|
|
636
674
|
// Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
|
|
637
675
|
// against on the run's rows.
|
|
@@ -640,28 +678,34 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
640
678
|
// (metrics.ts cliRunMetrics). Its cost is its booking's too: the harness's own record carries no per-request cost or
|
|
641
679
|
// usage, so its model requests are counted at what the run's model proxy booked them at (bookedSpend over every
|
|
642
680
|
// session of its journal), as a pi run's are at its answers' costs and tokens.
|
|
681
|
+
// The end's cost: its booking's, by the one rule every reader of an ended run's cost takes (metrics.ts runCostOf), as
|
|
682
|
+
// the pi spec's: its model requests and its decisions (a learned workflow's, LS-07) at what they were booked at, and
|
|
683
|
+
// its paid tool calls (a Parallel extract or search, a monid call), booked in their own session; unknown when any part
|
|
684
|
+
// is. A run whose model answered or called a tool with no request booked (its requests went past its model proxy)
|
|
685
|
+
// spent what no booking read: unknown, never the $0 an empty booking sums to. One cheap read, apart from the metrics.
|
|
686
|
+
endCost: async () => {
|
|
687
|
+
const all = (await journalEntries(deps.journal(claim), context));
|
|
688
|
+
return endCostOf(runCostOf(all, { unbooked: cliModelWorked((await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context))) }));
|
|
689
|
+
},
|
|
643
690
|
endPatch: async () => {
|
|
644
691
|
const entries = await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context);
|
|
645
|
-
// Its tokens and model requests
|
|
646
|
-
// model requests and its decisions (a learned workflow's, LS-07) at what they were booked at (bookedSpend), and its
|
|
647
|
-
// paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own session,
|
|
648
|
-
// are the run's cost (runEndCost: unknown when any part is), as the pi spec's.
|
|
692
|
+
// Its tokens and model requests from one read of its booking (cliRunMetrics).
|
|
649
693
|
const all = (await journalEntries(deps.journal(claim), context));
|
|
650
694
|
const booked = bookedSpend(all, "model");
|
|
651
|
-
|
|
652
|
-
//
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
//
|
|
656
|
-
|
|
657
|
-
const total = runEndCost({ model, paid: run.ledger?.paid ? run.ledger.paid.spentUsd() : 0, decisions: bookedSpend(all, "decisions").usd });
|
|
658
|
-
// An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
|
|
659
|
-
return { costUsd: total, metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries) } };
|
|
695
|
+
// Its tools from its record read as pi's entries (piShaped: the CLI's calls and results are its own kinds, which no
|
|
696
|
+
// count reads as they are), an MCP tool called by a hashed wire name under its catalog name, as its timeline reads.
|
|
697
|
+
const metrics = cliRunMetrics(piShaped(entries), booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}`, catalog: await hashedMcpOf(deps.store, claim.runId) });
|
|
698
|
+
// Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
|
|
699
|
+
// cost an earlier end stored).
|
|
700
|
+
return { metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries) } };
|
|
660
701
|
},
|
|
661
702
|
// A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
|
|
662
703
|
...(heldComputer ? { held: heldComputer } : {}),
|
|
663
704
|
// The run's Archil mount credential is revoked at its end on every outcome, even with no computer (idempotent with
|
|
664
|
-
// the computer's release). A run that minted none revokes nothing.
|
|
665
|
-
|
|
705
|
+
// the computer's release). A run that minted none revokes nothing. At a park, a desktop or a phone is kept for the
|
|
706
|
+
// resume instead, its mount credential with it, as the pi spec's.
|
|
707
|
+
...(computer.keeps ? { keptWords: computerKeptWords(computer.keeps) } : {}),
|
|
708
|
+
release: (how) => holds.release(how),
|
|
709
|
+
endCheckout: () => holds.endCheckout(),
|
|
666
710
|
};
|
|
667
711
|
}
|
|
@@ -12,9 +12,12 @@ export type LoopComputer = {
|
|
|
12
12
|
readonly client: ComputerClient;
|
|
13
13
|
readonly hello?: HelloResult;
|
|
14
14
|
readonly hold?: ComputerHold;
|
|
15
|
+
/** The claim made it the run's own (computer-for-claim.ts ClaimComputer.made): the loop records its kind in the run's
|
|
16
|
+
* journal (KINDS.computerMade), so a later claim knows the run had one. */
|
|
17
|
+
readonly own?: true;
|
|
15
18
|
};
|
|
16
|
-
/** The loop's computer for a claim's (computerForClaim's `computer` and `
|
|
17
|
-
export declare function loopComputerOf(computer: RunComputer | undefined, held: HeldComputer | undefined): LoopComputer | undefined;
|
|
19
|
+
/** The loop's computer for a claim's (computerForClaim's `computer`, `held` and `made`): none for no computer or a browser. */
|
|
20
|
+
export declare function loopComputerOf(computer: RunComputer | undefined, held: HeldComputer | undefined, made?: string): LoopComputer | undefined;
|
|
18
21
|
/** A computer_call row's call, or why it is refused (a row the server wrote is always one; a hand-made one may not be). */
|
|
19
22
|
export declare function channelCallOf(command: Pick<Command, "body">): ComputerCall | {
|
|
20
23
|
readonly refused: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { callRecordOf, unrecorded } from "../computer-calls.js";
|
|
2
2
|
import { PROTOCOL_METHODS } from "../computer-channel.js";
|
|
3
|
-
/** The loop's computer for a claim's (computerForClaim's `computer` and `
|
|
4
|
-
export function loopComputerOf(computer, held) {
|
|
3
|
+
/** The loop's computer for a claim's (computerForClaim's `computer`, `held` and `made`): none for no computer or a browser. */
|
|
4
|
+
export function loopComputerOf(computer, held, made) {
|
|
5
5
|
if (!computer || computer.kind === "browser")
|
|
6
6
|
return undefined;
|
|
7
7
|
return {
|
|
@@ -9,6 +9,7 @@ export function loopComputerOf(computer, held) {
|
|
|
9
9
|
client: computer.computer.client,
|
|
10
10
|
...("hello" in computer ? { hello: computer.hello } : {}),
|
|
11
11
|
...(held && held.kind === computer.kind ? { hold: held.hold } : {}),
|
|
12
|
+
...(made === computer.kind ? { own: true } : {}),
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
/** A computer_call row's call, or why it is refused (a row the server wrote is always one; a hand-made one may not be). */
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { JournalReads } from "../store/store.js";
|
|
1
3
|
import type { HeldComputer, HoldEnd, HoldState } from "../workspace/computer-hold.js";
|
|
2
4
|
import type { Command, CommandOutcome } from "./loop-contract.js";
|
|
5
|
+
/** Whether the run's journal says an earlier claim made the run a computer of its own (KINDS.computerMade, which only a
|
|
6
|
+
* claim's pass writes): what a later claim asks (computerForClaim's hadComputer) before it makes a fresh one, so it
|
|
7
|
+
* says it replaces one even when nothing of the earlier claim's is left to let go (a server's stop, a park). */
|
|
8
|
+
export declare function hadComputer(journal: JournalReads, context: Context): Promise<boolean>;
|
|
3
9
|
/** One root entry, as the run's journal takes it. */
|
|
4
10
|
export type RootEntry = {
|
|
5
11
|
readonly kind: string;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
// The run's desktop or phone hold, on the runner: every change of the hold (workspace/computer-hold.ts) is committed to the
|
|
2
|
-
// run's journal with its Timeline row, which is what the server reads (computer-commands.ts, computer-routes.ts); and the
|
|
3
|
-
// person's take-over and hand-back rows are applied to the hold. The adapter loop calls this once the run's Harness is
|
|
4
|
-
// open, for a spec that carries a computer (AdapterRunSpec.computer).
|
|
5
|
-
//
|
|
6
|
-
// Commits go one at a time, in the order the hold changed, each at the change's own time. A row the hold took or ended a
|
|
7
|
-
// take for is taken by the commit that writes that change (its `by`); one the hold refuses is refused in words.
|
|
8
|
-
//
|
|
9
|
-
// onComputerHold is the change signal for whoever else in the runner's process shows the hold (tl-browser's run-side
|
|
10
|
-
// viewer and its bar): it fires after each computer.hold change entry is committed, with that change's Timeline words.
|
|
11
1
|
import { HOST_PHASE } from "../timeline/index.js";
|
|
12
2
|
import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, holdIn, holdWords, takeEndedWords, } from "../computer-commands.js";
|
|
3
|
+
import { KINDS } from "./journal-kinds.js";
|
|
4
|
+
import { journalEntries } from "./journal-reader.js";
|
|
5
|
+
/** Whether the run's journal says an earlier claim made the run a computer of its own (KINDS.computerMade, which only a
|
|
6
|
+
* claim's pass writes): what a later claim asks (computerForClaim's hadComputer) before it makes a fresh one, so it
|
|
7
|
+
* says it replaces one even when nothing of the earlier claim's is left to let go (a server's stop, a park). */
|
|
8
|
+
export async function hadComputer(journal, context) {
|
|
9
|
+
return (await journalEntries(journal, context)).some((entry) => entry.kind === KINDS.computerMade);
|
|
10
|
+
}
|
|
13
11
|
const listeners = new Map();
|
|
14
12
|
/** Calls `listener` after each change of run `runId`'s hold is committed to its journal, in order, in this process.
|
|
15
13
|
* Returns the unsubscribe. */
|
|
@@ -17,6 +17,7 @@ import { tmpdir } from "node:os";
|
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
19
19
|
import { DEFER_CATALOG_OVER } from "@parcha/agentrun-kernel";
|
|
20
|
+
import { INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
|
|
20
21
|
import { AnswerTaken, dropPostgresSchema, openPostgresStore, openStore, RunFinal, storeTarget, Unanswered } from "../../store/index.js";
|
|
21
22
|
import { sendCommand } from "../commands.js";
|
|
22
23
|
import { callsOf, journalRecords, messagesOf } from "../journal-reader.js";
|
|
@@ -472,7 +473,7 @@ async function crashThenResume(subject, t, tool, point, script = [{ call: tool }
|
|
|
472
473
|
await saidReleased(w.events);
|
|
473
474
|
resumedOnceByB(w.events, row);
|
|
474
475
|
saidTakenOver(await w.liveRows(), "runner-a");
|
|
475
|
-
return { ...(await w.read()), ran };
|
|
476
|
+
return { ...(await w.read()), ran, w };
|
|
476
477
|
}
|
|
477
478
|
/** Whether process `pid` is stopped (SIGSTOP), by the kernel's own word, on every platform the suite runs on: the state
|
|
478
479
|
* field of /proc/<pid>/stat is "T" where there is a /proc (Linux); elsewhere (macOS) `ps -o state=` answers a state that
|
|
@@ -1156,12 +1157,14 @@ const CASES = [
|
|
|
1156
1157
|
},
|
|
1157
1158
|
{
|
|
1158
1159
|
id: "meta-codemode-crash",
|
|
1159
|
-
title: "a crash after a codemode script's call's intent: the script runs again, the call is told interrupted, never run twice, and the script ends there",
|
|
1160
|
+
title: "a crash after a codemode script's call's intent: the script runs again, the call is told interrupted in the one wording every harness gives it, never run twice, and the script ends there",
|
|
1160
1161
|
async body(subject, t) {
|
|
1161
1162
|
const script = "await tools.effect({});\nawait tools.read({});\nreturn 'end';";
|
|
1162
|
-
const { ran } = await crashThenResume(subject, t, "effect", "beforeResult", [{ call: "codemode", args: { script } }, { say: "done" }]);
|
|
1163
|
+
const { ran, w } = await crashThenResume(subject, t, "effect", "beforeResult", [{ call: "codemode", args: { script } }, { say: "done" }]);
|
|
1163
1164
|
assert.equal(ran.effect, 1, "the effect ran once, never again after the crash");
|
|
1164
1165
|
assert.equal(ran.read, 0, "the script ended at the interrupted call: nothing after it ran");
|
|
1166
|
+
// Its row reads the kernel's words for an outcome not known (INTERRUPTED_TEXT), on pi, claude-agent and opencode alike.
|
|
1167
|
+
await nestedRowsShown(w, "codemode", [{ tool: "effect", result: new RegExp(`^${INTERRUPTED_TEXT.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) }]);
|
|
1165
1168
|
},
|
|
1166
1169
|
},
|
|
1167
1170
|
];
|
|
@@ -11,6 +11,8 @@ export declare const reflectRequestId: (runId: string, again?: boolean, round?:
|
|
|
11
11
|
/** The suffix of the end-of-run turn's re-ask's request id (EndOfRunTurn ask's `again`): one per round too, so a repeat
|
|
12
12
|
* is answered from its submission, never asked of the model twice. */
|
|
13
13
|
export declare const REFLECT_AGAIN = ":again";
|
|
14
|
+
/** The round shared by its look-back, re-ask and compile attempts, for range and durable accounting reads. */
|
|
15
|
+
export declare const reflectRoundId: (requestId: string) => string;
|
|
14
16
|
/** One round of a run's end-of-run turn in its journal: `from`, the entry its input placed (the turn's first); `until`, the
|
|
15
17
|
* run's end entry that closed it, once written. Every entry between is the turn's. */
|
|
16
18
|
export type ReflectRange = {
|
|
@@ -21,6 +21,8 @@ export const REFLECT_AGAIN = ":again";
|
|
|
21
21
|
const REFLECT_ROUND = ":round-";
|
|
22
22
|
/** What a round's re-ask or step adds to its request id (reflectRequestId): the round is the id without it. */
|
|
23
23
|
const REFLECT_STEP = /:(?:again|compile-\d+)$/;
|
|
24
|
+
/** The round shared by its look-back, re-ask and compile attempts, for range and durable accounting reads. */
|
|
25
|
+
export const reflectRoundId = (requestId) => requestId.replace(REFLECT_STEP, "");
|
|
24
26
|
/** Each round of the end-of-run turn in a run's journal, oldest first: each begins at the entry its input placed, from the
|
|
25
27
|
* input submissions under its request ids (its re-ask's within it); else, on a CLI harness, at the turn's prompt the CLI
|
|
26
28
|
* record wrote as it asked it (`entries`: adapter-loop.ts answering, an end-of-run-turn entry of the person's with its
|
|
@@ -32,7 +34,7 @@ export function reflectRanges(submissions, entries = []) {
|
|
|
32
34
|
const note = (requestId, entry) => {
|
|
33
35
|
if (!Number.isFinite(entry))
|
|
34
36
|
return;
|
|
35
|
-
const round = requestId
|
|
37
|
+
const round = reflectRoundId(requestId);
|
|
36
38
|
starts.set(round, Math.min(starts.get(round) ?? entry, entry));
|
|
37
39
|
};
|
|
38
40
|
for (const record of submissions) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Grade } from "../learn/promote.js";
|
|
2
2
|
import type { RunPath } from "../learning-cost.js";
|
|
3
|
-
import { type Store } from "../store/store.js";
|
|
3
|
+
import { type Command, type Store } from "../store/store.js";
|
|
4
4
|
export declare const FEEDBACK_ROUNDS: readonly ["revise", "look_back"];
|
|
5
5
|
export type FeedbackRound = (typeof FEEDBACK_ROUNDS)[number];
|
|
6
|
-
/** The most characters a grade's words (`label`) may hold. */
|
|
7
|
-
export declare const LABEL_MAX = 4000;
|
|
8
6
|
/** A feedback round, as its steer's body carries it (`feedback`) and its FEEDBACK entry keeps it: the round, whether the
|
|
9
7
|
* grade said right, the workflow a revision is asked of, and the grade's words (`text`). */
|
|
10
8
|
export interface FeedbackData {
|
|
@@ -20,9 +18,10 @@ export declare function feedbackRoundOf(grade: {
|
|
|
20
18
|
readonly path: RunPath;
|
|
21
19
|
readonly workflow?: string;
|
|
22
20
|
}, label: string | undefined): FeedbackRound | undefined;
|
|
23
|
-
/** The grade's words as the round says them: its `label`, else
|
|
24
|
-
*
|
|
25
|
-
|
|
21
|
+
/** The grade's words as the round says them: its `label`, else the fields a right answer holds (`expected`), else
|
|
22
|
+
* "(no words)". Never the verdict: feedbackAsk and the compile ask each say it once. (A right grade opens a round only
|
|
23
|
+
* with a label (feedbackRoundOf), so none reaches here without one.) */
|
|
24
|
+
export declare function feedbackWords(label: string | undefined, expected: Readonly<Record<string, unknown>> | undefined): string;
|
|
26
25
|
/** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
|
|
27
26
|
* message API never does), else undefined. */
|
|
28
27
|
export declare function feedbackOf(body: unknown): FeedbackData | undefined;
|
|
@@ -43,10 +42,38 @@ export declare function feedbackAsk(feedback: FeedbackData, seen?: {
|
|
|
43
42
|
readonly answer: string;
|
|
44
43
|
};
|
|
45
44
|
}): string;
|
|
45
|
+
/** How a feedback round stands (GET /runs/{id}/learning `graded.feedback_status`): `running` until it settles; `ended`,
|
|
46
|
+
* its run took the grade's words and ended after them; `not_run`, its run ended before it took them. */
|
|
47
|
+
export declare const FEEDBACK_STATUSES: readonly ["running", "ended", "not_run"];
|
|
48
|
+
export type FeedbackStatus = (typeof FEEDBACK_STATUSES)[number];
|
|
49
|
+
/** How the feedback round opened on steer `command` (store.runs.reopen's row, read now) stands, never by a clock:
|
|
50
|
+
* - `ended`: in its run's root `entries`, the FEEDBACK entry that took the steer (its requestId names the command) has
|
|
51
|
+
* the run's end entry after it, both in journal order (one writer, the run's runner);
|
|
52
|
+
* - `not_run`: no FEEDBACK entry took it and the row is refused. A runner writes nothing for the steer before that entry,
|
|
53
|
+
* so a reopened run that ends first (its claim refused, an end with nothing sent) leaves no trace of the round in its
|
|
54
|
+
* journal: its end's own commit refuses the row (the store's refuseLeftovers), in the same transaction as that end;
|
|
55
|
+
* - else `running`: the steer untaken (no runner took it yet; an end that left it so opened the run again with it), or
|
|
56
|
+
* taken with no end since, or a row that can't be read. */
|
|
57
|
+
export declare function feedbackStatus(entries: readonly {
|
|
58
|
+
readonly kind: string;
|
|
59
|
+
readonly data?: unknown;
|
|
60
|
+
}[], command: Pick<Command, "id" | "refused"> | undefined): FeedbackStatus;
|
|
61
|
+
/** A feedback round opened: the round, and the steer command it opened the run again on (feedbackStatus reads how it
|
|
62
|
+
* stands). */
|
|
63
|
+
export interface OpenedRound {
|
|
64
|
+
readonly round: FeedbackRound;
|
|
65
|
+
readonly command: number;
|
|
66
|
+
}
|
|
46
67
|
/** Opens run `grade.run` again on the feedback round its grade asks for (feedbackRoundOf), with the grade's words
|
|
47
|
-
* (`label`, else feedbackWords'), and says which: only a run that learns (its launch's learning start,
|
|
48
|
-
* only uses what was learned, nor a notes-only run's revision ask),
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
68
|
+
* (`label`, else feedbackWords'), and says which, with its steer: only a run that learns (its launch's learning start,
|
|
69
|
+
* never one that only uses what was learned, nor a notes-only run's revision ask), whose runner supports managed
|
|
70
|
+
* feedback, neither archived nor of an archived
|
|
71
|
+
* agent (closed history: a grade of it starts no paid work), and one the store opens again (an agentic run that answered
|
|
72
|
+
* or that a person stopped). Null when the grade asks for nothing more, or the run can't be opened again (the grade is
|
|
73
|
+
* kept either way). */
|
|
74
|
+
export declare function openFeedbackRound(store: Pick<Store, "runs" | "agents">, grade: Grade, label: string | undefined): Promise<OpenedRound | null>;
|
|
75
|
+
/** A grade's write (PUT /runs/{id}/grade): keeps `grade` for agent `agentId` naming no round, opens its run again on the
|
|
76
|
+
* round it asks for (openFeedbackRound), and only then marks the kept grade with that round and its steer. The grade is
|
|
77
|
+
* kept first, so the round's end reads it; the round is named last, so a reopen that fails (thrown, or a run that can't
|
|
78
|
+
* be opened again) leaves a grade naming none, never one claiming a round that didn't open. The grade as kept. */
|
|
79
|
+
export declare function keepGrade(store: Pick<Store, "runs" | "agents" | "settings">, agentId: string, grade: Grade, label: string | undefined): Promise<Grade>;
|