@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +455 -0
- package/README.md +376 -125
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
- package/dist/console/assets/index-Jbxjcmdp.js +705 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +83 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +15 -0
- package/dist/email/answer.js +217 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +373 -0
- package/dist/email/names.d.ts +50 -0
- package/dist/email/names.js +74 -0
- package/dist/email/routes.d.ts +10 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +27 -0
- package/dist/email/tools.js +562 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +12 -4
- package/dist/learn/compile.js +57 -20
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +130 -64
- package/dist/learn/promote.js +113 -202
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +35 -8
- package/dist/learning-cost.js +27 -9
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +39 -2
- package/dist/local-models.js +49 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +2 -1
- package/dist/openapi.js +404 -93
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +10 -2
- package/dist/port-models.js +6 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +14 -0
- package/dist/refusal-words.js +16 -2
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +13 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +44 -38
- package/dist/run-view.js +93 -56
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +48 -13
- package/dist/runner/adapter-loop.js +691 -254
- package/dist/runner/adapter-run-spec.d.ts +38 -12
- package/dist/runner/adapter-run-spec.js +175 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +95 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +59 -13
- package/dist/runner/journal-kinds.js +48 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +14 -3
- package/dist/runner/model-route.js +155 -19
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +76 -10
- package/dist/runner/promotion.js +476 -154
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +568 -137
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +5 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/connection.js +72 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +170 -34
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +67 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +115 -18
- package/dist/store-reads/learning.js +170 -68
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +84 -21
- package/dist/templates.js +254 -47
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +46 -44
- package/dist/tool-gate.js +101 -92
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +57 -16
- package/dist/tools.js +33 -28
- package/dist/trigger-adapter.d.ts +56 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +181 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +105 -8
- package/dist/triggers.js +286 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
package/dist/learn/refit.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// Threshold refit: a learned workflow's step guards (runner/step-guard.ts) re-chosen from graded rows, so a guard set too
|
|
2
|
+
// high (October's receipt hold: 46 of 54 revisions held) or too low is moved to where the rows say it belongs. Each guarded
|
|
3
|
+
// step's threshold becomes the cheapest one (the fewest hand-backs) that keeps the workflow's accuracy over the rows within
|
|
4
|
+
// PROMOTE_BAR of the agent's; a `both` guard's fit (logistic over [self, jev], Platt-style) is refit first when the rows
|
|
5
|
+
// hold at least FIT_MIN_ROWS with at least FIT_MIN_WRONG wrong, else kept. A guard may also be switched off (OFF: it never
|
|
6
|
+
// hands back, and the revision drops it): the cheapest setting of all, so a guard whose p says nothing of right and wrong
|
|
7
|
+
// goes. So may an escalate node a replay recorded instead of obeying (the DSL's softEscalates), on the same rule:
|
|
8
|
+
// one that stops right drafts is dropped from its chain, one that stops wrong ones stays. Pure: the rows in, the new
|
|
9
|
+
// workflow text and what changed out; runner/promotion.ts reads the rows (replays and graded served runs) and writes the
|
|
10
|
+
// revision.
|
|
11
|
+
import { softEscalates } from "@parcha/agentrun-dsl";
|
|
12
|
+
import { agentRight, answerCorrect, PROMOTE_BAR, sameAnswer, SOFT_ESCALATE_THRESHOLD, walkGuards } from "./promote.js";
|
|
2
13
|
import { workflowNodes } from "./workflow-nodes.js";
|
|
3
14
|
/** A switch set off: the guard or the escalate never hands back. Never a threshold the DSL takes (one is in (0, 1)). */
|
|
4
15
|
export const OFF = 0;
|
|
@@ -7,6 +18,18 @@ export const FIT_MIN_ROWS = 30;
|
|
|
7
18
|
export const THRESHOLD_MIN = 0.001;
|
|
8
19
|
export const THRESHOLD_MAX = 0.999;
|
|
9
20
|
export const FIT_MIN_WRONG = 5;
|
|
21
|
+
/** A replay's rows as the scorer reads them: those its workflow answered or handed back, never one it failed on or skipped
|
|
22
|
+
* (no evidence either way: the replay ran without what the graded run had, or stopped at a write it never runs). Answered
|
|
23
|
+
* alone only when every guard read a p (record-only, none handed back). */
|
|
24
|
+
export const refitRowsOf = (rows) => rows.flatMap((row) => {
|
|
25
|
+
if (row.outcome !== "answered" && row.outcome !== "handed_back")
|
|
26
|
+
return [];
|
|
27
|
+
const answered = row.outcome === "answered" && row.guards.every((guard) => guard.p !== null);
|
|
28
|
+
return [{
|
|
29
|
+
of: row.of, guards: row.guards, answered, agentCorrect: agentRight(row.recorded) ? 1 : 0,
|
|
30
|
+
wfCorrect: answered ? answerCorrect(row.answer, row.recorded) : null, agrees: answered && sameAnswer(row.answer, row.recorded.answer),
|
|
31
|
+
}];
|
|
32
|
+
});
|
|
10
33
|
const sigmoid = (z) => 1 / (1 + Math.exp(-z));
|
|
11
34
|
const round = (value, places = 4) => Math.round(value * 10 ** places) / 10 ** places;
|
|
12
35
|
/** A logistic fit of y over x (Newton's method with a small ridge, so separable rows stay finite): weights and bias. */
|
|
@@ -61,14 +84,15 @@ function solve(a, b) {
|
|
|
61
84
|
}
|
|
62
85
|
return m.map((row, i) => row[n] / row[i]);
|
|
63
86
|
}
|
|
64
|
-
/** The rows'
|
|
87
|
+
/** The rows' score, unrounded (scoreRows rounds it; the refit's search compares it as it is), with p read through `pOf`
|
|
88
|
+
* and each step held to `thresholds`: a row any guard of hands back on
|
|
65
89
|
* takes the agent's answer; one that answered alone, its grade. A row that did not answer alone because a guard handed
|
|
66
90
|
* it back (one of its guards escalated) and that no guard would hand back at `thresholds` would have answered with an
|
|
67
91
|
* answer nobody read: counted wrong, so a threshold never comes down past hand-backs with no evidence of what the
|
|
68
92
|
* workflow says there. One that did not answer for another reason (a step failed, an escalate node) takes the agent's
|
|
69
93
|
* answer at every threshold. A switch OFF never hands back, a missing p or not. */
|
|
70
|
-
function scoreAt(rows,
|
|
71
|
-
let [wf, agent, handed] = [0, 0, 0];
|
|
94
|
+
function scoreAt(rows, thresholds, pOf) {
|
|
95
|
+
let [wf, agent, handed, agree] = [0, 0, 0, 0];
|
|
72
96
|
for (const row of rows) {
|
|
73
97
|
agent += row.agentCorrect;
|
|
74
98
|
const under = row.guards.some((guard) => {
|
|
@@ -82,12 +106,25 @@ function scoreAt(rows, pOf, thresholds) {
|
|
|
82
106
|
if (under || (!known && !row.guards.some((guard) => guard.escalated))) {
|
|
83
107
|
handed += 1;
|
|
84
108
|
wf += row.agentCorrect;
|
|
109
|
+
continue;
|
|
85
110
|
}
|
|
86
|
-
|
|
111
|
+
if (known && row.wfCorrect)
|
|
87
112
|
wf += 1;
|
|
113
|
+
if (row.agrees)
|
|
114
|
+
agree += 1;
|
|
88
115
|
}
|
|
89
116
|
const n = rows.length || 1;
|
|
90
|
-
return { wf_acc: wf / n, agent_acc: agent / n, handed_back: handed };
|
|
117
|
+
return { n: rows.length, agree, wf_acc: wf / n, agent_acc: agent / n, handed_back: handed };
|
|
118
|
+
}
|
|
119
|
+
/** The one score of a workflow over rows (a replay's, a refit's, a serving check's), each step held to `thresholds` (a step
|
|
120
|
+
* not named, its row's own threshold) with p read through `pOf` (the row's p): `n` rows; `agree`, how many it answered
|
|
121
|
+
* alone with the agent's recorded answer; `agent_acc`, the agent's accuracy; `wf_acc`, the workflow's, a hand-back
|
|
122
|
+
* counting as the agent's answer (scoreAt); `delta` = wf_acc - agent_acc; `handed_back` (it answered n - handed_back
|
|
123
|
+
* alone: answersAlone). Accuracies to 1e-4, as the promotion record keeps them. */
|
|
124
|
+
export function scoreRows(rows, thresholds, pOf = (row) => row.p) {
|
|
125
|
+
const score = scoreAt(rows, thresholds, pOf);
|
|
126
|
+
const [agent_acc, wf_acc] = [round(score.agent_acc), round(score.wf_acc)];
|
|
127
|
+
return { n: score.n, agree: score.agree, agent_acc, wf_acc, delta: round(wf_acc - agent_acc), handed_back: score.handed_back };
|
|
91
128
|
}
|
|
92
129
|
/** How good one raise is, compared first to last: any accuracy gained before none; then accuracy per input handed back
|
|
93
130
|
* (a gain that hands back nothing first); then the fewest handed back. A raise that gains nothing ranks by its loss. */
|
|
@@ -98,10 +135,10 @@ const rankAbove = (a, b) => {
|
|
|
98
135
|
return a[i] > b[i];
|
|
99
136
|
return false;
|
|
100
137
|
};
|
|
101
|
-
/** The escalates of `doc` a refit may switch off: each a replay records (
|
|
138
|
+
/** The escalates of `doc` a refit may switch off: each a replay records (softEscalates) that is a step of a chain with
|
|
102
139
|
* a step that is no escalate, so the chain keeps a step once they are dropped. */
|
|
103
140
|
function switchableEscalates(doc) {
|
|
104
|
-
const soft =
|
|
141
|
+
const soft = softEscalates(doc);
|
|
105
142
|
const out = new Set();
|
|
106
143
|
for (const { node, prefix } of workflowNodes(doc)) {
|
|
107
144
|
if (node.node !== "chain" || !Array.isArray(node.steps))
|
|
@@ -124,7 +161,7 @@ export function refitGuards(text, rows, now) {
|
|
|
124
161
|
doc = JSON.parse(text);
|
|
125
162
|
}
|
|
126
163
|
catch {
|
|
127
|
-
return { guards: [], n: rows.length, agent_acc: 0, wf_acc: 0, delta: 0, handed_back: 0 };
|
|
164
|
+
return { guards: [], n: rows.length, agree: 0, agent_acc: 0, wf_acc: 0, delta: 0, handed_back: 0 };
|
|
128
165
|
}
|
|
129
166
|
const guards = [];
|
|
130
167
|
walkGuards(doc, (label, guard, node) => guards.push({ label, guard, node }));
|
|
@@ -153,8 +190,8 @@ export function refitGuards(text, rows, now) {
|
|
|
153
190
|
};
|
|
154
191
|
const was = new Map(guards.map(({ label, guard }) => [label, typeof guard.threshold === "number" ? guard.threshold : OFF]));
|
|
155
192
|
const thresholds = new Map([...was, ...escalates.map((label) => [label, SOFT_ESCALATE_THRESHOLD])]);
|
|
156
|
-
const agentAcc = scoreAt(rows,
|
|
157
|
-
const meets = (at) => scoreAt(rows,
|
|
193
|
+
const agentAcc = scoreAt(rows, thresholds, pOf).agent_acc;
|
|
194
|
+
const meets = (at) => scoreAt(rows, at, pOf).wf_acc >= agentAcc - PROMOTE_BAR - 1e-9;
|
|
158
195
|
// Each guard's candidates: OFF (hands back nothing), THRESHOLD_MIN (nothing but a missing p or one under it), each p its
|
|
159
196
|
// rows read within the DSL's range, its own threshold, and THRESHOLD_MAX; a step no row reached keeps its own. Each
|
|
160
197
|
// recorded escalate's: off or on.
|
|
@@ -171,11 +208,11 @@ export function refitGuards(text, rows, now) {
|
|
|
171
208
|
// handing back every input, and the step whose guard tells right from wrong is then never raised.
|
|
172
209
|
for (const [label, candidates] of candidatesOf)
|
|
173
210
|
thresholds.set(label, candidates[0]);
|
|
174
|
-
for (let now = scoreAt(rows,
|
|
211
|
+
for (let now = scoreAt(rows, thresholds, pOf); !meets(thresholds);) {
|
|
175
212
|
let best;
|
|
176
213
|
for (const [label, candidates] of candidatesOf) {
|
|
177
214
|
for (const at of candidates.filter((c) => c > thresholds.get(label))) {
|
|
178
|
-
const next = scoreAt(rows,
|
|
215
|
+
const next = scoreAt(rows, new Map([...thresholds, [label, at]]), pOf);
|
|
179
216
|
const rank = raiseRank(next.wf_acc - now.wf_acc, next.handed_back - now.handed_back);
|
|
180
217
|
if (!best || rankAbove(rank, best.rank))
|
|
181
218
|
best = { label, at, rank, next };
|
|
@@ -223,14 +260,5 @@ export function refitGuards(text, rows, now) {
|
|
|
223
260
|
for (const label of off)
|
|
224
261
|
changed.push({ node: label, was: null, threshold: null, escalate: true });
|
|
225
262
|
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
...(changed.length ? { text: JSON.stringify(doc) } : {}),
|
|
229
|
-
guards: changed,
|
|
230
|
-
n: rows.length,
|
|
231
|
-
agent_acc: round(score.agent_acc),
|
|
232
|
-
wf_acc: round(score.wf_acc),
|
|
233
|
-
delta: round(score.wf_acc - score.agent_acc),
|
|
234
|
-
handed_back: score.handed_back,
|
|
235
|
-
};
|
|
263
|
+
return { ...(changed.length ? { text: JSON.stringify(doc) } : {}), guards: changed, ...scoreRows(rows, thresholds, pOf) };
|
|
236
264
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// hit, recorded or already run in this replay, costs nothing and is never sent again.
|
|
8
8
|
// - A write is NEVER run in a replay: it is answered from the graded run's recording when a call there has the same
|
|
9
9
|
// tool and canonical args (its answer, an error included), else the replay of that input stops there and is skipped
|
|
10
|
-
// (SKIPPED_WRITE): no evidence either way, never scored wrong or failed (learn/
|
|
10
|
+
// (SKIPPED_WRITE): no evidence either way, never scored wrong or failed (learn/refit.ts refitRowsOf).
|
|
11
11
|
// The recording is the graded run's own journal (a CLI's record shaped as pi's), each tool call by the wire name the
|
|
12
12
|
// harness called it by (catalog.ts wireName): a call node names its tool by catalog name, matched through the same map.
|
|
13
13
|
// Prior art: MCP's tool annotations (readOnlyHint, destructiveHint, 2025-03-26 spec) for the read/write line; VCR-style
|
package/dist/learn/skills.d.ts
CHANGED
|
@@ -274,11 +274,6 @@ export declare const LEARNED_MAX_TURNS = 8;
|
|
|
274
274
|
* learned runner cannot run (LEARNED_NODES: a judge's on a run with no `decisions`; with them, one whose provider the run
|
|
275
275
|
* lacks or its gate holds to ask or deny). With no list it
|
|
276
276
|
* fails closed: a draft the DSL refuses only once given an empty list names a tool. */
|
|
277
|
-
/**
|
|
278
|
-
|
|
279
|
-
export type DraftAsk = {
|
|
280
|
-
readonly asked: readonly string[];
|
|
281
|
-
readonly fits: (asks: readonly string[]) => boolean;
|
|
282
|
-
};
|
|
283
|
-
export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, ask?: DraftAsk, decisions?: DraftDecisions): DraftProblem[];
|
|
277
|
+
/** `decisions` is the managed host's registry; `adapters` is an explicit backend callback contract, when supplied. */
|
|
278
|
+
export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, decisions?: DraftDecisions, adapters?: readonly ("runNode" | "runJudge")[]): DraftProblem[];
|
|
284
279
|
export {};
|
package/dist/learn/skills.js
CHANGED
|
@@ -942,28 +942,47 @@ const longNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node) =>
|
|
|
942
942
|
out.push({ rule: "workflow", detail: `the agent node at ${node.path} asks context fork: a learned workflow's model node starts a fresh session` });
|
|
943
943
|
return out;
|
|
944
944
|
});
|
|
945
|
+
/** The SDK bridge statically admits at most 128 nodes, separately from its dynamic step and tool-call budgets.
|
|
946
|
+
* Use the same DSL inspection as the bridge, including nested structural and composed workflow nodes. */
|
|
947
|
+
const sdkNodeLimit = (dsl, doc, adapters) => adapters !== undefined && dsl.inspectWorkflow(doc).nodes.length > 128
|
|
948
|
+
? [{ rule: "workflow", detail: "the SDK workflow bridge supports at most 128 static workflow nodes" }]
|
|
949
|
+
: [];
|
|
950
|
+
/** The SDK bridge never retries a delegated effect; check proposals and already approved selections against the
|
|
951
|
+
* same host restriction before delivery. Managed hosts retain their normal retry contract. */
|
|
952
|
+
const sdkRetries = (doc, adapters) => adapters === undefined ? [] : callNodes(doc).flatMap((node) => typeof node.retry === "object" && node.retry !== null && Number(node.retry.attempts) > 1
|
|
953
|
+
? [{ rule: "workflow", detail: "the SDK workflow bridge does not support automatic retries of delegated tool calls" }]
|
|
954
|
+
: []);
|
|
945
955
|
/** The node the learned runner cannot run, as the DSL's own check says it (assertWorkflowCapabilities, which runWorkflow
|
|
946
956
|
* makes before any node runs) with the runner's deps: none when it can run every one. */
|
|
947
|
-
const unrunnableNodes = (dsl, doc, decisions) => {
|
|
957
|
+
const unrunnableNodes = (dsl, doc, decisions, adapters) => {
|
|
948
958
|
const workflow = dsl.desugarWorkflow(doc);
|
|
949
|
-
//
|
|
950
|
-
|
|
951
|
-
const
|
|
952
|
-
//
|
|
953
|
-
const
|
|
959
|
+
// Managed runs name the providers their host can ask; SDK runs supply their own explicit adapter capabilities.
|
|
960
|
+
const judging = decisions ? { ...(adapters === undefined || adapters.includes("runJudge") ? { runJudge: async () => ({}) } : {}), decisionProviders: { providers: decisions.providers, default: decisions.default } } : {};
|
|
961
|
+
const callbacks = Object.fromEntries((adapters ?? ["runNode"]).map((name) => [name, async () => ({})]));
|
|
962
|
+
// Managed learned runs supply step guards; the SDK bridge advertises only the callbacks its backend implements.
|
|
963
|
+
const guards = adapters === undefined ? { guardStep: async () => ({ p: 1 }) } : {};
|
|
964
|
+
const runner = { runEffect: async () => ({}), ...callbacks, ...judging, ...guards };
|
|
954
965
|
try {
|
|
955
966
|
dsl.assertWorkflowCapabilities(workflow.root, runner, workflow);
|
|
956
967
|
return [];
|
|
957
968
|
}
|
|
958
969
|
catch (error) {
|
|
959
|
-
return [{ rule: "workflow", detail: `${error.message.slice(0, 200)}: ${LEARNED_NODES}` }];
|
|
970
|
+
return [{ rule: "workflow", detail: `${error.message.slice(0, 200)}: ${adapters === undefined ? LEARNED_NODES : "this host has no adapter for that node"}` }];
|
|
960
971
|
}
|
|
961
972
|
};
|
|
962
973
|
const issuesOf = (dsl, doc, tools) => {
|
|
963
974
|
const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
|
|
964
975
|
return valid.ok ? [] : valid.issues;
|
|
965
976
|
};
|
|
966
|
-
|
|
977
|
+
/** Why `workflows/<name>/workflow.json` is not a draft the host can run; empty when it is. The DSL's own
|
|
978
|
+
* `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
|
|
979
|
+
* and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
|
|
980
|
+
* apply_patch) is never on the list. A model node that names any tool is refused (MODEL_NODE_TOOLS), and a node the
|
|
981
|
+
* learned runner cannot run (LEARNED_NODES: a judge's on a run with no `decisions`; with them, one whose provider the run
|
|
982
|
+
* lacks or its gate holds to ask or deny). With no list it
|
|
983
|
+
* fails closed: a draft the DSL refuses only once given an empty list names a tool. */
|
|
984
|
+
/** `decisions` is the managed host's registry; `adapters` is an explicit backend callback contract, when supplied. */
|
|
985
|
+
export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, decisions, adapters) {
|
|
967
986
|
let doc;
|
|
968
987
|
try {
|
|
969
988
|
doc = JSON.parse(text);
|
|
@@ -980,17 +999,12 @@ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask,
|
|
|
980
999
|
let out;
|
|
981
1000
|
try {
|
|
982
1001
|
// A label names one step (workflow-nodes.ts repeatedLabels): its guard's threshold, replay score and refit included.
|
|
983
|
-
out = [...repeatedLabels(doc).map((label) => ({ rule: "workflow", detail: `the label "${label}" names two steps: give each step its own label` })), ...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc, decisions), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...gatedDecisions(dsl, doc, decisions), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
|
|
1002
|
+
out = [...repeatedLabels(doc).map((label) => ({ rule: "workflow", detail: `the label "${label}" names two steps: give each step its own label` })), ...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc, decisions, adapters), ...longNodes(dsl, doc), ...sdkNodeLimit(dsl, doc, adapters), ...sdkRetries(doc, adapters), ...gatedNodes(dsl, doc, gated, deniedBy), ...gatedDecisions(dsl, doc, decisions), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
|
|
984
1003
|
// A learned workflow answers the value at its output's path: one that names none would answer its whole state, which
|
|
985
1004
|
// fails its output schema when the call ends, after every node spent.
|
|
986
1005
|
const path = doc?.output?.path;
|
|
987
1006
|
if (typeof path !== "string" || !path)
|
|
988
1007
|
out.push({ rule: "workflow", detail: LEARNED_OUTPUT_PATH });
|
|
989
|
-
// Its MCP tools set to ask, on one approval card per learned call (#2424): a card that can't name them all is refused
|
|
990
|
-
// at the gate at every call, so the draft is refused here, in the gate's words.
|
|
991
|
-
const asks = ask ? draftMcpTools(doc).filter((tool) => ask.asked.includes(tool)) : [];
|
|
992
|
-
if (ask && asks.length && !ask.fits(asks))
|
|
993
|
-
out.push({ rule: "workflow", detail: `its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.` });
|
|
994
1008
|
// A composed workflow node's child too: its output is the value at its own output.path, or it fails the same way.
|
|
995
1009
|
for (const node of dsl.inspectWorkflow(doc).nodes) {
|
|
996
1010
|
if (node.kind !== "workflow")
|
package/dist/learned-nodes.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Skipped } from "./learn/replay-calls.js";
|
|
1
2
|
/** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards? }`, its call's id, the
|
|
2
3
|
* workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX) and every guard check it made
|
|
3
4
|
* (GuardRow, never capped: a map over more items than the trace holds keeps each); on a replay run's call that a write
|
|
@@ -29,7 +30,7 @@ export type LearnedNode = {
|
|
|
29
30
|
* `p` (through the guard's fit when it has one; null when a signal it reads was missing, so it handed back) and whether
|
|
30
31
|
* it handed the job back. A run's rows are its metrics' `guards` (runner/workflow-first.ts pathMetrics), each naming
|
|
31
32
|
* the workflow whose call made it (`workflow`: a run can call more than one, the next after the first hands back).
|
|
32
|
-
* `escalate`: no guard but an escalate node a replay recorded instead of obeying (
|
|
33
|
+
* `escalate`: no guard but an escalate node a replay recorded instead of obeying (the DSL's softEscalates), on
|
|
33
34
|
* its label: p 0 when it fired, else 1, at SOFT_ESCALATE_THRESHOLD, never `escalated` (the run went on past it). */
|
|
34
35
|
export type GuardRow = {
|
|
35
36
|
readonly node: string;
|
|
@@ -41,8 +42,19 @@ export type GuardRow = {
|
|
|
41
42
|
readonly escalated: boolean;
|
|
42
43
|
readonly workflow?: string;
|
|
43
44
|
};
|
|
45
|
+
/** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
|
|
46
|
+
* `entries`. A call run again (after a park or a crash: it nests calls) keeps an entry each time; the one that counts is
|
|
47
|
+
* its last that ran a node or made a check, as it holds every node and check its rerun made again. A rerun refused before
|
|
48
|
+
* any node ran (a replay run keeps that entry: `nodes: []`, ended `failed`) leaves the attempt before it standing; a call
|
|
49
|
+
* none of whose entries ran a node counts its last. What the run's guard rows (guardsOf) and its timeline rows'
|
|
50
|
+
* `learned_nodes` (store-reads/journal.ts) both read, so the two never pick apart. */
|
|
51
|
+
export declare function learnedCallEntries(entries: readonly {
|
|
52
|
+
readonly kind: string;
|
|
53
|
+
readonly data?: unknown;
|
|
54
|
+
}[]): Map<string, number>;
|
|
44
55
|
/** A run's guard rows, from its root entries: every guard check of every learned_workflow call (LEARNED_NODES `guards`,
|
|
45
|
-
* never the capped trace's), in order, each with its call's workflow
|
|
56
|
+
* never the capped trace's), in order, each with its call's workflow, from the entry that counts for each call
|
|
57
|
+
* (learnedCallEntries). What its metrics keep as `guards`. */
|
|
46
58
|
export declare function guardsOf(entries: readonly {
|
|
47
59
|
readonly kind: string;
|
|
48
60
|
readonly data?: unknown;
|
|
@@ -59,8 +71,4 @@ export declare function endedIn(entries: readonly {
|
|
|
59
71
|
export declare function replaySkippedIn(entries: readonly {
|
|
60
72
|
readonly kind: string;
|
|
61
73
|
readonly data?: unknown;
|
|
62
|
-
}[]):
|
|
63
|
-
tool: string;
|
|
64
|
-
step: string;
|
|
65
|
-
unmarked?: true;
|
|
66
|
-
} | undefined;
|
|
74
|
+
}[]): Skipped | undefined;
|
package/dist/learned-nodes.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// What a learned_workflow call keeps of its workflow's run beside itself in the run's journal: each node that ran, as
|
|
2
|
-
// the workflow DSL ended it (learned-workflow.ts runLearned writes it; store-reads/journal.ts runTimeline puts it on the
|
|
3
|
-
// call's result row as `learned_nodes`). Its own module, so the timeline's reader needs none of the tool's imports.
|
|
4
1
|
/** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards? }`, its call's id, the
|
|
5
2
|
* workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX) and every guard check it made
|
|
6
3
|
* (GuardRow, never capped: a map over more items than the trace holds keeps each); on a replay run's call that a write
|
|
@@ -9,14 +6,41 @@
|
|
|
9
6
|
export const LEARNED_NODES = "agentrun.learned_nodes";
|
|
10
7
|
/** The most nodes a call keeps: a map over a long list runs its body once per item. */
|
|
11
8
|
export const LEARNED_NODES_MAX = 64;
|
|
9
|
+
/** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
|
|
10
|
+
* `entries`. A call run again (after a park or a crash: it nests calls) keeps an entry each time; the one that counts is
|
|
11
|
+
* its last that ran a node or made a check, as it holds every node and check its rerun made again. A rerun refused before
|
|
12
|
+
* any node ran (a replay run keeps that entry: `nodes: []`, ended `failed`) leaves the attempt before it standing; a call
|
|
13
|
+
* none of whose entries ran a node counts its last. What the run's guard rows (guardsOf) and its timeline rows'
|
|
14
|
+
* `learned_nodes` (store-reads/journal.ts) both read, so the two never pick apart. */
|
|
15
|
+
export function learnedCallEntries(entries) {
|
|
16
|
+
const last = new Map();
|
|
17
|
+
const ran = new Set();
|
|
18
|
+
entries.forEach((entry, index) => {
|
|
19
|
+
if (entry.kind !== LEARNED_NODES)
|
|
20
|
+
return;
|
|
21
|
+
const data = entry.data;
|
|
22
|
+
if (typeof data?.call !== "string")
|
|
23
|
+
return;
|
|
24
|
+
const made = (Array.isArray(data.nodes) && data.nodes.length > 0) || (Array.isArray(data.guards) && data.guards.length > 0);
|
|
25
|
+
if (made)
|
|
26
|
+
ran.add(data.call);
|
|
27
|
+
if (made || !ran.has(data.call))
|
|
28
|
+
last.set(data.call, index);
|
|
29
|
+
});
|
|
30
|
+
return last;
|
|
31
|
+
}
|
|
12
32
|
/** A run's guard rows, from its root entries: every guard check of every learned_workflow call (LEARNED_NODES `guards`,
|
|
13
|
-
* never the capped trace's), in order, each with its call's workflow
|
|
33
|
+
* never the capped trace's), in order, each with its call's workflow, from the entry that counts for each call
|
|
34
|
+
* (learnedCallEntries). What its metrics keep as `guards`. */
|
|
14
35
|
export function guardsOf(entries) {
|
|
15
36
|
const rows = [];
|
|
16
|
-
|
|
37
|
+
const last = learnedCallEntries(entries);
|
|
38
|
+
for (const [index, entry] of entries.entries()) {
|
|
17
39
|
if (entry.kind !== LEARNED_NODES)
|
|
18
40
|
continue;
|
|
19
41
|
const data = entry.data;
|
|
42
|
+
if (typeof data?.call === "string" && last.get(data.call) !== index)
|
|
43
|
+
continue;
|
|
20
44
|
if (!Array.isArray(data?.guards))
|
|
21
45
|
continue;
|
|
22
46
|
const workflow = typeof data.workflow === "string" ? data.workflow : undefined;
|
|
@@ -9,29 +9,34 @@ import type { Complete } from "./llm.js";
|
|
|
9
9
|
import type { SearchOn } from "./web-search.js";
|
|
10
10
|
import type { Workspace } from "./workspace/workspace.js";
|
|
11
11
|
import type { DecisionProvider } from "@parcha/agentrun-dsl";
|
|
12
|
-
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
12
|
+
import type { NestedCalls, Refusal } from "@parcha/agentrun-kernel";
|
|
13
13
|
import type { RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
|
|
14
14
|
import { type ReplayCalls } from "./learn/replay-calls.js";
|
|
15
|
-
/** What a learned_workflow call's approval card says of its MCP
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* them
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
/** What a learned_workflow call's approval card says of its MCP actions' arguments: a `{name}` in one is filled in as
|
|
16
|
+
* the workflow runs. */
|
|
17
|
+
export declare const LEARNED_MCP_ARGUMENTS = "each {name} is filled in while the workflow runs, from its input or an earlier step";
|
|
18
|
+
/** An MCP action of a learned workflow: a call node's tool (`mcp:<server>/<tool>`) and its arguments as the workflow
|
|
19
|
+
* writes them (their shape: values, and the `{name}`s filled in as it runs). */
|
|
20
|
+
export type LearnedAction = {
|
|
21
|
+
readonly tool: string;
|
|
22
|
+
readonly args: unknown;
|
|
23
|
+
};
|
|
24
|
+
/** What a learned_workflow call's card shows of the MCP actions set to ask that the workflow can call: how their
|
|
25
|
+
* arguments are filled in, then each action with its arguments' shape, as many as the card's preview shows whole
|
|
26
|
+
* (LEARNED_ASK_CARD_BYTES). The card leads with these (the call's own input after them), so they are never cut behind a
|
|
27
|
+
* long input. An action past the bound is not named, so its call asks on its own as it runs, never approved unseen; and
|
|
28
|
+
* since an approval passes by tool (learnedApprovedTools), a tool with any action past the bound is not named at all. */
|
|
29
|
+
export declare function learnedAskShown(asks: readonly LearnedAction[]): Record<string, unknown>;
|
|
30
|
+
/** The fields of a learned_workflow call's card that only the gate writes (learnedAskShown): one of the same name in the
|
|
31
|
+
* call's input, which the model wrote, is never shown on its card. */
|
|
32
|
+
export declare const LEARNED_CARD_FIELDS: ReadonlySet<string>;
|
|
33
|
+
/** The MCP tools an approval card names (learnedAskShown's `mcp_calls`, read from the card a person approved): a call
|
|
34
|
+
* nested in the approved one whose tool is among them passes its ask. None for a card that named none. */
|
|
35
|
+
export declare const learnedApprovedTools: (card: unknown) => ReadonlySet<string>;
|
|
36
|
+
/** The MCP actions a learned workflow's call nodes name (`via: "tool"`, `tool: "mcp:<server>/<tool>"`), each with its
|
|
37
|
+
* arguments as written, once per distinct pair; none for one that does not read. The run's gate asks about them before
|
|
38
|
+
* the workflow's call runs (adapter-run-spec.ts). */
|
|
39
|
+
export declare function learnedMcpCalls(workflow: string): Promise<LearnedAction[]>;
|
|
35
40
|
export declare const LEARNED_WORKFLOW_TOOL = "learned_workflow";
|
|
36
41
|
/** One line of a learned workflow's output for its row: an object's fields as `name value`, and a text output (learnedOutput
|
|
37
42
|
* hands one back as it is, #2412) its lines, each value or line whole or, when longer than VALUE_MAX, only as its size,
|
|
@@ -98,14 +103,15 @@ export type LearnedWorkflowRun = {
|
|
|
98
103
|
readonly book: RunDecisions;
|
|
99
104
|
readonly pause?: (refusal: Refusal) => Promise<void>;
|
|
100
105
|
};
|
|
101
|
-
/** The run's MCP tools
|
|
102
|
-
* A call node may name one of these; it runs
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
/** The run's MCP tools: each catalog name (`mcp:<server>/<tool>`) the claim's pin holds, which its revision grants, to
|
|
107
|
+
* the name the session's tools hold it by. A call node may name one of these; it runs as a call nested in the
|
|
108
|
+
* workflow's (`nestedOf`). */
|
|
109
|
+
mcpTools?: ReadonlyMap<string, string>;
|
|
110
|
+
/** The session's tools as calls nested in the learned_workflow call of this id (NestedCalls, the harness's for a tool
|
|
111
|
+
* that `nests`): an MCP node runs as one, asked at the gate as its own tool with the arguments the workflow resolved
|
|
112
|
+
* (its deny, its argument pins, its ask: one the approved card named passes, any other parks for a person), recorded
|
|
113
|
+
* and booked on the run's one ledger as its own call. None: an MCP node is never sent. */
|
|
114
|
+
nestedOf?: (callId: string) => NestedCalls | undefined;
|
|
109
115
|
/** A replay run's (runner/promotion.ts): its call nodes go through the replay's rules (learn/replay-calls.ts: a read
|
|
110
116
|
* live through a cache seeded from the graded run's recorded calls, a write only ever answered from that recording),
|
|
111
117
|
* and a write the recording does not have stops the workflow there, skipped. Absent: every call node runs live. */
|
|
@@ -145,8 +151,12 @@ export declare function learnedWorkflowTool(run: LearnedWorkflowRun): ToolRegist
|
|
|
145
151
|
* LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
|
|
146
152
|
* which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
|
|
147
153
|
* added as it ends, the caller's to keep when the call is aborted (and so throws) part way. `guards`: where every guard
|
|
148
|
-
* check is added as it is made, never capped (a map's checks past the trace's cap too), the caller's to keep likewise.
|
|
149
|
-
|
|
154
|
+
* check is added as it is made, never capped (a map's checks past the trace's cap too), the caller's to keep likewise.
|
|
155
|
+
* `nested`: the session's tools as calls nested in this one, which its MCP nodes run as; and the values its first run
|
|
156
|
+
* fixed (`memo`), so a rerun of the call (after a park, a crash) goes on from what its model, decision and call nodes
|
|
157
|
+
* answered then, its MCP calls with the arguments they were asked and approved with, each recorded one answered from its
|
|
158
|
+
* record, never sent twice. */
|
|
159
|
+
export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[], guards?: GuardRow[], nested?: NestedCalls): Promise<{
|
|
150
160
|
text: string;
|
|
151
161
|
isError: boolean;
|
|
152
162
|
nodes: LearnedNode[];
|