@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
package/dist/learn/promote.js
CHANGED
|
@@ -11,7 +11,11 @@ export const REFIT_EVERY = 20;
|
|
|
11
11
|
/** How many grades, and how many promotion records, an agent keeps (newest kept). */
|
|
12
12
|
export const GRADES_KEPT = 500;
|
|
13
13
|
export const PROMOTIONS_KEPT = 200;
|
|
14
|
+
/** The most characters a grade's words (`label`) may hold, and the most of them and of a wrong answer a revise ask shows. */
|
|
15
|
+
export const LABEL_MAX = 4_000;
|
|
14
16
|
export const GRADE_SOURCES = ["feedback", "eval"];
|
|
17
|
+
/** The ReplayScore fields of `x` alone (a scoreRows or refitGuards result, or a record's `replay`): the one pick of them. */
|
|
18
|
+
export const scoreOf = (x) => ({ n: x.n, agree: x.agree, agent_acc: x.agent_acc, wf_acc: x.wf_acc, delta: x.delta, handed_back: x.handed_back });
|
|
15
19
|
/** Whether a replay or refit answered alone on at least one of its inputs: one that hands back every input would never
|
|
16
20
|
* serve. The one spelling of it (clears, settle's hold, the compile's held line); the count is n - handed_back. */
|
|
17
21
|
export const answersAlone = (score) => score.handed_back < score.n;
|
|
@@ -58,30 +62,51 @@ export const putGrade = async (settings, agentId, grade) => {
|
|
|
58
62
|
});
|
|
59
63
|
return kept;
|
|
60
64
|
};
|
|
65
|
+
/** Marks the kept grade `grade` (its run, given at its `at`, kept at its `seq`) with the feedback round it opened and
|
|
66
|
+
* that round's steer, in place: its `seq` stays, so a serving digest's check never counts it twice. A newer grade of the
|
|
67
|
+
* run is left as it is, one given in the same millisecond too (its `seq` is another). The grade, marked. */
|
|
68
|
+
export const markGradeRound = async (settings, agentId, grade, opened) => {
|
|
69
|
+
const mark = { feedback: opened.round, feedbackCommand: opened.command };
|
|
70
|
+
await updateKept(settings, gradesKey(agentId), (items) => items.map((one) => (one.run === grade.run && one.at === grade.at && one.seq === grade.seq ? { ...one, ...mark } : one)));
|
|
71
|
+
return { ...grade, ...mark };
|
|
72
|
+
};
|
|
61
73
|
/** The agent's promotion records, oldest first. */
|
|
62
74
|
export const promotionsOf = async (settings, agentId) => itemsOf(await settings.get(promotionsKey(agentId)));
|
|
63
75
|
/** The newest record of `workflow` at `digest`, or undefined. */
|
|
64
76
|
export const promotionOf = (records, workflow, digest) => records.findLast((one) => one.workflow === workflow && one.digest === digest);
|
|
65
|
-
/** The champion of `workflow`: the newest record of the digest promoted last (a digest's place is its
|
|
66
|
-
*
|
|
77
|
+
/** The champion of `workflow`: the newest record of the digest promoted last (a digest's place is its latest win's,
|
|
78
|
+
* winsOf), while that digest's newest record still says promote. A newer revision replaying or held never stops it; a
|
|
67
79
|
* wrong served grade asks for a revision and never stops it; it stops when a newer revision's replay promotes that one
|
|
68
|
-
* (then the champion), or its own graded runs hold it (source graded: no champion until a revision is promoted).
|
|
69
|
-
*
|
|
80
|
+
* (then the champion), or its own graded runs hold it (source graded: no champion until a revision is promoted). A held
|
|
81
|
+
* revision its owner replays (runner/promotion.ts askReplay) and the replay promotes wins again: the champion from then.
|
|
82
|
+
* The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
|
|
70
83
|
export function championOf(records, workflow) {
|
|
71
84
|
const last = lastPromotedOf(records, workflow);
|
|
72
85
|
const now = last === undefined ? undefined : promotionOf(records, workflow, last);
|
|
73
86
|
return now?.decided === "promote" ? now : undefined;
|
|
74
87
|
}
|
|
75
|
-
/**
|
|
88
|
+
/** Each promote record's win, by index: the index of the promote record that began its digest's run of promote records
|
|
89
|
+
* (its first, or the first after a record of that digest that was not promote: a replay that promoted a held revision).
|
|
90
|
+
* A graded check's mark (a promote after a promote, runner/promotion.ts stillServing) is never a win of its own. */
|
|
91
|
+
function winsOf(records) {
|
|
92
|
+
const wins = new Map();
|
|
93
|
+
const streak = new Map();
|
|
94
|
+
records.forEach((one, i) => {
|
|
95
|
+
const at = JSON.stringify([one.workflow, one.digest]);
|
|
96
|
+
if (one.decided !== "promote")
|
|
97
|
+
return void streak.delete(at);
|
|
98
|
+
if (!streak.has(at))
|
|
99
|
+
streak.set(at, i);
|
|
100
|
+
wins.set(i, streak.get(at));
|
|
101
|
+
});
|
|
102
|
+
return wins;
|
|
103
|
+
}
|
|
104
|
+
/** The digest of `workflow` promoted last: the one whose latest win (winsOf) is the newest of every digest's. */
|
|
76
105
|
function lastPromotedOf(records, workflow) {
|
|
77
|
-
const seen = new Set();
|
|
78
106
|
let last;
|
|
79
|
-
for (const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
seen.add(one.digest);
|
|
83
|
-
last = one.digest;
|
|
84
|
-
}
|
|
107
|
+
for (const [i, win] of winsOf(records))
|
|
108
|
+
if (i === win && records[i].workflow === workflow)
|
|
109
|
+
last = records[i].digest;
|
|
85
110
|
return last;
|
|
86
111
|
}
|
|
87
112
|
/** The revisions of `workflow` other than `digest` whose newest record still says replaying, newest first: at most one
|
|
@@ -110,13 +135,14 @@ export function servingOf(records) {
|
|
|
110
135
|
/** The promotions list as it leaves (GET /agents/{id}/learning/promotions): the records and what serves (servingOf), every
|
|
111
136
|
* text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
|
|
112
137
|
* any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
|
|
113
|
-
* (`shown.text`: a reason, a refit guard's label, a digest, a run id). Numbers and the rest as they are.
|
|
138
|
+
* (`shown.text`: a reason, a refit guard's label, a digest, a run id). Numbers and the rest as they are. A replaying
|
|
139
|
+
* record's `launch` (a run launch: its notes, model and plane) never leaves: aggregates only. */
|
|
114
140
|
export function promotionsShown(records, shown) {
|
|
115
141
|
const cut = (value, key) => typeof value === "string" ? (key === "workflow" ? shown.name(value) : shown.text(value))
|
|
116
142
|
: Array.isArray(value) ? value.map((one) => cut(one))
|
|
117
143
|
: value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([field, one]) => [field, cut(one, field)]))
|
|
118
144
|
: value;
|
|
119
|
-
return { promotions: records.map((one) => cut(one)), serving: servingOf(records).map((one) => cut(one)) };
|
|
145
|
+
return { promotions: records.map(({ launch: _, ...one }) => cut(one)), serving: servingOf(records).map((one) => cut(one)) };
|
|
120
146
|
}
|
|
121
147
|
/** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
|
|
122
148
|
* and of every record kept (`items`: a check across revisions, one challenger at a time, in the same guarded write): so
|
|
@@ -136,26 +162,25 @@ export async function recordPromotion(settings, agentId, record, still) {
|
|
|
136
162
|
}
|
|
137
163
|
/** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
|
|
138
164
|
* before, whatever was dropped. championOf reads two things, and the trim keeps both: the place of every digest it can
|
|
139
|
-
* still see promoted (a promote record kept keeps its
|
|
140
|
-
*
|
|
141
|
-
*
|
|
165
|
+
* still see promoted (a promote record kept keeps its win, winsOf, beside it, so an older revision's late graded check
|
|
166
|
+
* never reads as a newer promotion), and the digest promoted last, its latest win and its newest record (so a held last
|
|
167
|
+
* revision is never trimmed into handing the champion back). The kept records are a run of the newest plus those wins,
|
|
168
|
+
* and a win's own run reaches no further back than it: a record that ended an older run of the same digest is newer
|
|
169
|
+
* than every record of that run, so a run is never joined to an older one by the trim. */
|
|
142
170
|
export function trimPromotions(items) {
|
|
143
171
|
if (items.length <= PROMOTIONS_KEPT)
|
|
144
172
|
return [...items];
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const at = JSON.stringify([one.workflow, one.digest]);
|
|
148
|
-
if (one.decided === "promote" && !firstPromote.has(at))
|
|
149
|
-
firstPromote.set(at, i);
|
|
150
|
-
});
|
|
151
|
-
const placeOf = (i) => (items[i].decided === "promote" ? firstPromote.get(JSON.stringify([items[i].workflow, items[i].digest])) : undefined);
|
|
173
|
+
const wins = winsOf(items);
|
|
174
|
+
const placeOf = (i) => wins.get(i);
|
|
152
175
|
const keep = new Set();
|
|
153
176
|
for (const workflow of new Set(items.map((one) => one.workflow))) {
|
|
154
177
|
const last = lastPromotedOf(items, workflow);
|
|
155
178
|
if (last === undefined)
|
|
156
179
|
continue;
|
|
157
|
-
|
|
158
|
-
|
|
180
|
+
const newest = items.findLastIndex((one) => one.workflow === workflow && one.digest === last);
|
|
181
|
+
// Its latest win: the newest win of that digest.
|
|
182
|
+
keep.add(Math.max(...[...wins].filter(([i, win]) => i === win && items[i].workflow === workflow && items[i].digest === last).map(([i]) => i)));
|
|
183
|
+
keep.add(newest);
|
|
159
184
|
}
|
|
160
185
|
for (let i = items.length - 1, room = PROMOTIONS_KEPT - keep.size; i >= 0 && room > 0; i--) {
|
|
161
186
|
if (keep.has(i))
|
|
@@ -171,11 +196,15 @@ export function trimPromotions(items) {
|
|
|
171
196
|
}
|
|
172
197
|
return items.filter((_, i) => keep.has(i));
|
|
173
198
|
}
|
|
174
|
-
/**
|
|
199
|
+
/** The text inside an answer that is one unlabelled fence and nothing else, or undefined. */
|
|
200
|
+
const WHOLE_FENCE = /^ {0,3}(`{3,}|~{3,})[ \t]*\r?\n([\s\S]*?)\r?\n {0,3}\1[`~]*[ \t]*$/;
|
|
201
|
+
/** An answer's value: its text as JSON when it is JSON (bare, or the whole of one unlabelled fence), else its last fenced
|
|
202
|
+
* json block, else its trimmed text. */
|
|
175
203
|
function valueOf(answer) {
|
|
176
204
|
const text = answer.trim();
|
|
205
|
+
const inner = WHOLE_FENCE.exec(text)?.[2];
|
|
177
206
|
try {
|
|
178
|
-
return JSON.parse(text);
|
|
207
|
+
return JSON.parse(inner ?? text);
|
|
179
208
|
}
|
|
180
209
|
catch {
|
|
181
210
|
const block = answerJson(text);
|
|
@@ -197,25 +226,36 @@ function same(a, b) {
|
|
|
197
226
|
}
|
|
198
227
|
/** Whether two answers say the same: equal as JSON values, else as trimmed text. */
|
|
199
228
|
export const sameAnswer = (a, b) => a !== null && b !== null && same(valueOf(a), valueOf(b));
|
|
200
|
-
/** Whether the workflow's `answer` to a graded input is right: with the grade's expected fields, when its JSON
|
|
201
|
-
* of them (or, one field expected, when the answer is that field's
|
|
202
|
-
* answers with
|
|
203
|
-
*
|
|
204
|
-
* it
|
|
229
|
+
/** Whether the workflow's `answer` to a graded input is right by its grade: with the grade's expected fields, when its JSON
|
|
230
|
+
* holds each of them (or, one field expected, when the answer is that field's value: a workflow whose output is one
|
|
231
|
+
* field answers with its text, or its JSON text when it is no text, learned-workflow.ts learnedOutput). Else, graded
|
|
232
|
+
* right, when it says what the graded run said. Graded wrong: on a run a learned workflow answered alone (`workflow`),
|
|
233
|
+
* when it says anything else (the bar on a wrong grade is the grade: saying what was graded wrong again is never a tie),
|
|
234
|
+
* and wrong when what it said could not be read (nothing says it differs); on a run the agent answered, wrong whatever it
|
|
235
|
+
* says (another answer proves nothing: a neutral tie with the agent's, agentRight). */
|
|
205
236
|
export function answerCorrect(answer, recorded) {
|
|
206
237
|
if (answer === null)
|
|
207
238
|
return false;
|
|
208
239
|
if (recorded.expected) {
|
|
209
240
|
const value = valueOf(answer);
|
|
210
241
|
const fields = Object.values(recorded.expected);
|
|
211
|
-
if (fields.length === 1 && typeof fields[0] === "string"
|
|
242
|
+
if (fields.length === 1 && (typeof fields[0] === "string" ? answer.trim() === fields[0].trim() : same(value, fields[0])))
|
|
212
243
|
return true;
|
|
213
244
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
214
245
|
return false;
|
|
215
246
|
return Object.entries(recorded.expected).every(([key, want]) => same(value[key], want));
|
|
216
247
|
}
|
|
217
|
-
|
|
248
|
+
if (recorded.correct)
|
|
249
|
+
return sameAnswer(answer, recorded.answer);
|
|
250
|
+
return recorded.path === "workflow" && recorded.answer !== null && !sameAnswer(answer, recorded.answer);
|
|
218
251
|
}
|
|
252
|
+
/** Whether the agent's answer to a replayed input is right, the agent's side of a replay's score: the graded run's grade
|
|
253
|
+
* when the answer graded is the agent's (path `agent`, or `handed_back`: the agent finished it). On a run a learned
|
|
254
|
+
* workflow answered alone (`workflow`) the store holds no answer of the agent's on that input, so a right grade is the
|
|
255
|
+
* agent's too and a wrong one counts the agent right: the grade's expected answer is the agent's when it gave one, and
|
|
256
|
+
* with none the agent is the default. So a revision held on runs it served wrong never ties its own wrong answers; it
|
|
257
|
+
* serves again only by answering them right (answerCorrect) or handing them back. */
|
|
258
|
+
export const agentRight = (recorded) => recorded.correct || recorded.path === "workflow";
|
|
219
259
|
/** The thresholds a workflow's guards serve at, by step label (the guard rows' `node`): every step of the workflow
|
|
220
260
|
* with a `guard` and a `label` (walkGuards). A label names one step: a learned draft that repeats one never runs
|
|
221
261
|
* (skills.ts draftProblems, repeatedLabels), so no two steps' rows share a threshold here or in a refit. */
|
|
@@ -247,127 +287,12 @@ export function walkGuards(doc, visit) {
|
|
|
247
287
|
/** The threshold a soft escalate's row (GuardRow signal `escalate`) is read at: its p is 0 when it fired, else 1, so it
|
|
248
288
|
* hands back at its serving setting exactly when it fired. */
|
|
249
289
|
export const SOFT_ESCALATE_THRESHOLD = 0.5;
|
|
250
|
-
const JUDGE_WROTE = new Set(["judge"]);
|
|
251
|
-
const OTHER_WROTE = new Set(["other"]);
|
|
252
|
-
const writersOf = (state, key) => state.get(key) ?? OTHER_WROTE;
|
|
253
|
-
/** The writers after any of `states`: each key's writers on every one of them. */
|
|
254
|
-
function joinWriters(states) {
|
|
255
|
-
const out = new Map();
|
|
256
|
-
for (const key of new Set(states.flatMap((state) => [...state.keys()]))) {
|
|
257
|
-
const each = states.map((state) => writersOf(state, key));
|
|
258
|
-
out.set(key, each.every((writers) => writers === each[0]) ? each[0] : new Set(each.flatMap((writers) => [...writers])));
|
|
259
|
-
}
|
|
260
|
-
return out;
|
|
261
|
-
}
|
|
262
|
-
const sameWriters = (a, b) => a.size === b.size && [...a].every(([key, writers]) => { const other = b.get(key); return other !== undefined && other.size === writers.size && [...writers].every((w) => other.has(w)); });
|
|
263
|
-
/** Past this nesting, or this many passes over a loop's body, softEscalatesOf reads every escalate as hard. */
|
|
264
|
-
const SOFT_WALK_DEPTH = 256;
|
|
265
|
-
const SOFT_WALK_PASSES = 16;
|
|
266
|
-
class SoftWalkTooDeep extends Error {
|
|
267
|
-
}
|
|
268
|
-
/** The writers after `value` (a workflow node) runs from `state`, as the DSL runs it (workflow.ts runNodeBody): a chain's
|
|
269
|
-
* steps in order; one route branch, any of them, after its `as` (its choice); a parallel's branches each from the same
|
|
270
|
-
* state, a key one wrote taking that branch's writer; a loop's body once or more, each pass from the last's; a map's
|
|
271
|
-
* body per item on its own copy (with `item`, `item_index`), only its `as` (and `failedAs`) left after; a child
|
|
272
|
-
* workflow on its own state, only its `as` left after. A judge writes its `as`; a code node with no `as` may write any
|
|
273
|
-
* key. Each escalate's verdict (whether its path's head was last written by a judge on every path to it) lands in
|
|
274
|
-
* `verdicts`, false on any pass where it is not. */
|
|
275
|
-
function walkWriters(value, state, prefix, verdicts, depth) {
|
|
276
|
-
const node = value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
277
|
-
if (!node)
|
|
278
|
-
return state;
|
|
279
|
-
if (depth > SOFT_WALK_DEPTH)
|
|
280
|
-
throw new SoftWalkTooDeep();
|
|
281
|
-
const wrote = (key, writers, from = state) => (typeof key === "string" && key !== "" ? new Map(from).set(key, writers) : from);
|
|
282
|
-
const asNode = (inner) => (inner && typeof inner === "object" && !Array.isArray(inner) ? inner : undefined);
|
|
283
|
-
switch (node.node) {
|
|
284
|
-
case "chain":
|
|
285
|
-
return (Array.isArray(node.steps) ? node.steps : []).reduce((at, step) => walkWriters(step, at, prefix, verdicts, depth + 1), state);
|
|
286
|
-
case "route": {
|
|
287
|
-
const routed = wrote(node.as, OTHER_WROTE);
|
|
288
|
-
const bodies = asNode(node.branches) ? Object.values(node.branches).map((branch) => asNode(branch)?.body) : [];
|
|
289
|
-
return bodies.length ? joinWriters(bodies.map((body) => walkWriters(body, routed, prefix, verdicts, depth + 1))) : routed;
|
|
290
|
-
}
|
|
291
|
-
case "parallel": {
|
|
292
|
-
const outs = (Array.isArray(node.branches) ? node.branches : []).map((branch) => walkWriters(branch, state, prefix, verdicts, depth + 1));
|
|
293
|
-
const merged = new Map(state);
|
|
294
|
-
for (const key of new Set(outs.flatMap((out) => [...out.keys()]))) {
|
|
295
|
-
const writers = outs.filter((out) => out.get(key) !== state.get(key));
|
|
296
|
-
if (writers.length)
|
|
297
|
-
merged.set(key, joinWriters(writers).get(key));
|
|
298
|
-
}
|
|
299
|
-
return merged;
|
|
300
|
-
}
|
|
301
|
-
case "loop": {
|
|
302
|
-
let entry = state;
|
|
303
|
-
for (let pass = 0; pass < SOFT_WALK_PASSES; pass++) {
|
|
304
|
-
const out = walkWriters(node.body, entry, prefix, verdicts, depth + 1);
|
|
305
|
-
const next = joinWriters([state, out]);
|
|
306
|
-
if (sameWriters(next, entry))
|
|
307
|
-
return out;
|
|
308
|
-
entry = next;
|
|
309
|
-
}
|
|
310
|
-
throw new SoftWalkTooDeep();
|
|
311
|
-
}
|
|
312
|
-
case "map": {
|
|
313
|
-
walkWriters(node.body, wrote("item_index", OTHER_WROTE, wrote("item", OTHER_WROTE)), prefix, verdicts, depth + 1);
|
|
314
|
-
return wrote(node.failedAs, OTHER_WROTE, wrote(node.as, OTHER_WROTE));
|
|
315
|
-
}
|
|
316
|
-
case "workflow":
|
|
317
|
-
walkWriters(asNode(node.workflow)?.root, new Map(), typeof node.label === "string" ? `${prefix}${node.label}/` : prefix, verdicts, depth + 1);
|
|
318
|
-
return wrote(node.as, OTHER_WROTE);
|
|
319
|
-
case "judge":
|
|
320
|
-
return wrote(node.as, JUDGE_WROTE);
|
|
321
|
-
case "escalate": {
|
|
322
|
-
if (typeof node.label !== "string")
|
|
323
|
-
return state;
|
|
324
|
-
let when = node.when;
|
|
325
|
-
while (when?.predicate === "not")
|
|
326
|
-
when = when.of;
|
|
327
|
-
const writers = typeof when?.path === "string" ? writersOf(state, when.path.split(".")[0]) : OTHER_WROTE;
|
|
328
|
-
const name = `${prefix}${node.label}`;
|
|
329
|
-
verdicts.set(name, (verdicts.get(name) ?? true) && writers.size === 1 && writers.has("judge"));
|
|
330
|
-
return state;
|
|
331
|
-
}
|
|
332
|
-
case "code":
|
|
333
|
-
if (typeof node.as === "string" && node.as !== "")
|
|
334
|
-
return wrote(node.as, OTHER_WROTE);
|
|
335
|
-
return new Map([...state].map(([key, writers]) => [key, writers.has("other") ? writers : new Set([...writers, "other"])]));
|
|
336
|
-
case "report":
|
|
337
|
-
return wrote("report_markdown", OTHER_WROTE);
|
|
338
|
-
case "artifact":
|
|
339
|
-
return wrote("artifact", OTHER_WROTE);
|
|
340
|
-
default:
|
|
341
|
-
// agent, decide, extract (`as`, else the label), pick, sift, call (`as`).
|
|
342
|
-
return wrote(typeof node.as === "string" && node.as !== "" ? node.as : node.label, OTHER_WROTE);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/** The escalate nodes of a workflow document a replay records instead of obeying, by label as the DSL names its step (a
|
|
346
|
-
* child's `parent/child`): each whose `when` (under any number of `not`s) reads a field a judge node wrote, the judge
|
|
347
|
-
* being the step that last wrote that path's head on every path the run can take to the escalate (walkWriters: a judge
|
|
348
|
-
* an extract overwrites, one in only some of a route's branches, one a code node with no `as` may have overwritten, are
|
|
349
|
-
* not). A judge's field is one model's opinion of a draft the workflow already wrote: the replay goes on to that draft
|
|
350
|
-
* and records whether the escalate fired (WorkflowDeps.softEscalate), so a refit can weigh the check against the drafts
|
|
351
|
-
* it stopped (learn/refit.ts). Every other escalate (on a call's result, a route's, the input) stays hard in a replay: it
|
|
352
|
-
* stops the run, as serving does. A document too deep to walk has none. */
|
|
353
|
-
export function softEscalatesOf(doc) {
|
|
354
|
-
const verdicts = new Map();
|
|
355
|
-
try {
|
|
356
|
-
walkWriters(doc && typeof doc === "object" && !Array.isArray(doc) ? doc.root : undefined, new Map(), "", verdicts, 0);
|
|
357
|
-
}
|
|
358
|
-
catch (error) {
|
|
359
|
-
if (error instanceof SoftWalkTooDeep)
|
|
360
|
-
return new Set();
|
|
361
|
-
throw error;
|
|
362
|
-
}
|
|
363
|
-
return new Set([...verdicts].flatMap(([name, soft]) => (soft ? [name] : [])));
|
|
364
|
-
}
|
|
365
290
|
/** The threshold a replay's guards read at: the least the DSL takes (a threshold is in (0, 1), exclusive), so a guard
|
|
366
291
|
* hands back only when p is null (a signal it reads is missing) or 0. */
|
|
367
292
|
export const RECORD_ONLY_THRESHOLD = 1e-9;
|
|
368
293
|
/** A workflow's text with every guard's threshold at RECORD_ONLY_THRESHOLD: each guard still reads its signals and
|
|
369
294
|
* records its row. What a replay runs, so every step's p is known for the refit and the serving thresholds are applied
|
|
370
|
-
* after (
|
|
295
|
+
* after (learn/refit.ts scoreRows). The text unchanged when it has no guard. */
|
|
371
296
|
export function recordOnly(workflowText) {
|
|
372
297
|
let doc;
|
|
373
298
|
try {
|
|
@@ -383,46 +308,14 @@ export function recordOnly(workflowText) {
|
|
|
383
308
|
});
|
|
384
309
|
return any ? JSON.stringify(doc) : workflowText;
|
|
385
310
|
}
|
|
386
|
-
/** Whether a replayed input would have been handed back serving at `thresholds` (by step; a step not named keeps its
|
|
387
|
-
* row's): it did not answer alone, or one of its guards read no p, or a p under its step's threshold (a soft escalate
|
|
388
|
-
* that fired among them: its row's p 0). */
|
|
389
|
-
export function escalates(row, thresholds) {
|
|
390
|
-
if (row.outcome !== "answered")
|
|
391
|
-
return true;
|
|
392
|
-
return row.guards.some((guard) => guard.p === null || guard.p < (thresholds.get(guard.node) ?? guard.threshold));
|
|
393
|
-
}
|
|
394
|
-
const round = (value) => Math.round(value * 1e4) / 1e4;
|
|
395
|
-
/** The replayed inputs a replay scores: those its workflow answered or handed back, never one it failed on or skipped. */
|
|
396
|
-
export const scoredRows = (rows) => rows.filter((row) => row.outcome === "answered" || row.outcome === "handed_back");
|
|
397
|
-
/** What a replay says at the serving `thresholds`, over the inputs it answered or handed back (scoredRows: a failed or
|
|
398
|
-
* skipped one is no evidence): each the workflow would have answered alone graded by answerCorrect, each it would have handed back the
|
|
399
|
-
* agent's recorded answer and grade. */
|
|
400
|
-
export function replayScore(all, thresholds) {
|
|
401
|
-
const rows = scoredRows(all);
|
|
402
|
-
let [agentRight, wfRight, agree, handed] = [0, 0, 0, 0];
|
|
403
|
-
for (const row of rows) {
|
|
404
|
-
if (row.recorded.correct)
|
|
405
|
-
agentRight += 1;
|
|
406
|
-
if (escalates(row, thresholds)) {
|
|
407
|
-
handed += 1;
|
|
408
|
-
if (row.recorded.correct)
|
|
409
|
-
wfRight += 1;
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
if (answerCorrect(row.answer, row.recorded))
|
|
413
|
-
wfRight += 1;
|
|
414
|
-
if (sameAnswer(row.answer, row.recorded.answer))
|
|
415
|
-
agree += 1;
|
|
416
|
-
}
|
|
417
|
-
const n = rows.length;
|
|
418
|
-
const [agent_acc, wf_acc] = n ? [round(agentRight / n), round(wfRight / n)] : [0, 0];
|
|
419
|
-
return { n, agree, agent_acc, wf_acc, delta: round(wf_acc - agent_acc), handed_back: handed };
|
|
420
|
-
}
|
|
421
311
|
/** Whether a score clears the bar: the workflow's accuracy at most PROMOTE_BAR under the agent path's, and it answered
|
|
422
312
|
* alone on at least one input (one that hands back every input scores the agent's own accuracy, and would never serve). */
|
|
423
|
-
export const clears = (score) => score
|
|
424
|
-
/**
|
|
313
|
+
export const clears = (score) => withinBar(score) && answersAlone(score);
|
|
314
|
+
/** Whether a score's workflow is at most PROMOTE_BAR under the agent: clears' bar, and what a replay of a held revision
|
|
315
|
+
* meets on the runs it was held on alone (runner/promotion.ts settle), where a hand-back on each is fine. */
|
|
316
|
+
export const withinBar = (score) => score.delta >= -PROMOTE_BAR - 1e-9;
|
|
317
|
+
/** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
|
|
425
318
|
export const gradeView = (grade) => ({
|
|
426
319
|
run_id: grade.run, correct: grade.correct, ...(grade.expected ? { expected: grade.expected } : {}), source: grade.source, graded_at: grade.at,
|
|
427
|
-
path: grade.path, workflow: grade.workflow ?? null, workflow_digest: grade.digest ?? null,
|
|
320
|
+
path: grade.path, workflow: grade.workflow ?? null, workflow_digest: grade.digest ?? null, feedback: grade.feedback ?? null,
|
|
428
321
|
});
|
package/dist/learn/refit.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GuardRow } from "../learned-nodes.js";
|
|
2
|
-
import { type RefitGuard } from "./promote.js";
|
|
2
|
+
import { type RefitGuard, type ReplayRow, type ReplayScore } from "./promote.js";
|
|
3
3
|
/** A switch set off: the guard or the escalate never hands back. Never a threshold the DSL takes (one is in (0, 1)). */
|
|
4
4
|
export declare const OFF = 0;
|
|
5
5
|
export declare const FIT_MIN_ROWS = 30;
|
|
@@ -7,32 +7,41 @@ export declare const FIT_MIN_ROWS = 30;
|
|
|
7
7
|
export declare const THRESHOLD_MIN = 0.001;
|
|
8
8
|
export declare const THRESHOLD_MAX = 0.999;
|
|
9
9
|
export declare const FIT_MIN_WRONG = 5;
|
|
10
|
-
/** One row
|
|
11
|
-
* that handed it back), whether the workflow answered it alone with every guard passing
|
|
12
|
-
* so whether that answer was right (`wfCorrect`; null: unknown)
|
|
13
|
-
*
|
|
10
|
+
/** One row the scorer (scoreRows) reads: the guard rows of one input (each step's p known up to where it stopped,
|
|
11
|
+
* `escalated` on the one that handed it back), whether the workflow answered it alone with every guard passing
|
|
12
|
+
* record-only (`answered`), and if so whether that answer was right (`wfCorrect`; null: unknown) and said what the
|
|
13
|
+
* agent's recorded answer said (`agrees`); `agentCorrect`, the chance the agent's answer to it is right (1 or 0 when
|
|
14
|
+
* known: a replayed row's agentRight; the agent's mean accuracy when not); `of`, the graded run a replayed row replays (refitRowsOf; a served
|
|
15
|
+
* run's row has none). */
|
|
14
16
|
export interface RefitRow {
|
|
15
17
|
readonly guards: readonly GuardRow[];
|
|
16
18
|
readonly answered: boolean;
|
|
17
19
|
readonly wfCorrect: boolean | null;
|
|
20
|
+
readonly agrees?: boolean;
|
|
18
21
|
readonly agentCorrect: number;
|
|
22
|
+
readonly of?: string;
|
|
19
23
|
}
|
|
20
24
|
/** What a refit chose: the workflow's new text (undefined when nothing changed), each guard it changed, and the rows'
|
|
21
|
-
*
|
|
22
|
-
export interface Refit {
|
|
25
|
+
* score at the new thresholds (scoreRows). */
|
|
26
|
+
export interface Refit extends ReplayScore {
|
|
23
27
|
readonly text?: string;
|
|
24
28
|
readonly guards: RefitGuard[];
|
|
25
|
-
readonly n: number;
|
|
26
|
-
readonly agent_acc: number;
|
|
27
|
-
readonly wf_acc: number;
|
|
28
|
-
readonly delta: number;
|
|
29
|
-
readonly handed_back: number;
|
|
30
29
|
}
|
|
30
|
+
/** A replay's rows as the scorer reads them: those its workflow answered or handed back, never one it failed on or skipped
|
|
31
|
+
* (no evidence either way: the replay ran without what the graded run had, or stopped at a write it never runs). Answered
|
|
32
|
+
* alone only when every guard read a p (record-only, none handed back). */
|
|
33
|
+
export declare const refitRowsOf: (rows: readonly ReplayRow[]) => RefitRow[];
|
|
31
34
|
/** A logistic fit of y over x (Newton's method with a small ridge, so separable rows stay finite): weights and bias. */
|
|
32
35
|
export declare function fitLogistic(xs: readonly (readonly number[])[], ys: readonly boolean[], ridge?: number): {
|
|
33
36
|
w: number[];
|
|
34
37
|
b: number;
|
|
35
38
|
};
|
|
39
|
+
/** 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
|
|
40
|
+
* not named, its row's own threshold) with p read through `pOf` (the row's p): `n` rows; `agree`, how many it answered
|
|
41
|
+
* alone with the agent's recorded answer; `agent_acc`, the agent's accuracy; `wf_acc`, the workflow's, a hand-back
|
|
42
|
+
* counting as the agent's answer (scoreAt); `delta` = wf_acc - agent_acc; `handed_back` (it answered n - handed_back
|
|
43
|
+
* alone: answersAlone). Accuracies to 1e-4, as the promotion record keeps them. */
|
|
44
|
+
export declare function scoreRows(rows: readonly RefitRow[], thresholds: ReadonlyMap<string, number>, pOf?: (row: GuardRow) => number | null): ReplayScore;
|
|
36
45
|
/** The workflow `text`'s guards, and the escalates its replay recorded, refit over `rows` (`now`: the fit's fitted_at). A
|
|
37
46
|
* guard whose step no row reached keeps what it has, and so does an escalate no row recorded. Nothing changes (no
|
|
38
47
|
* `text`) when every guard keeps its threshold and fit and every escalate stays. */
|
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 {};
|