@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.38
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 +282 -0
- package/README.md +155 -92
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +39 -14
- package/dist/answer-json.d.ts +34 -1
- package/dist/answer-json.js +91 -9
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/browser-cost.js +52 -93
- package/dist/cap.d.ts +0 -390
- package/dist/cap.js +4 -937
- package/dist/catalog.js +1 -1
- package/dist/composio-preset.d.ts +17 -0
- package/dist/composio-preset.js +43 -1
- package/dist/computer-calls.d.ts +36 -24
- package/dist/computer-calls.js +110 -27
- package/dist/computer-live.d.ts +5 -0
- package/dist/computer-live.js +12 -0
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +3 -2
- package/dist/computer-view.js +5 -4
- package/dist/computer-viewer.js +26 -12
- package/dist/computers.d.ts +4 -1
- package/dist/computers.js +12 -6
- package/dist/console/assets/index-CjqQirbo.css +1 -0
- package/dist/console/assets/index-b6-XY5A9.js +576 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +3 -0
- package/dist/decisions.js +4 -0
- package/dist/faux-computers.js +4 -2
- package/dist/harness-opencode/adapter.js +7 -3
- package/dist/harness-opencode/facts.js +0 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -5
- package/dist/harness-opencode/host/policy.js +8 -32
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +0 -2
- package/dist/host-tools.d.ts +1 -5
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +0 -2
- package/dist/hosted-search.js +0 -21
- package/dist/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +6 -1
- package/dist/learn/check.js +12 -4
- package/dist/learn/commit.d.ts +10 -0
- package/dist/learn/commit.js +18 -4
- package/dist/learn/compile.d.ts +243 -0
- package/dist/learn/compile.js +471 -0
- package/dist/learn/general.d.ts +3 -0
- package/dist/learn/general.js +4 -2
- package/dist/learn/grade.d.ts +1 -1
- package/dist/learn/grade.js +7 -6
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +253 -0
- package/dist/learn/promote.js +428 -0
- package/dist/learn/refit.d.ts +39 -0
- package/dist/learn/refit.js +236 -0
- package/dist/learn/reflect.d.ts +5 -25
- package/dist/learn/reflect.js +14 -131
- package/dist/learn/replay-calls.d.ts +63 -0
- package/dist/learn/replay-calls.js +158 -0
- package/dist/learn/skills.d.ts +17 -9
- package/dist/learn/skills.js +132 -42
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +50 -2
- package/dist/learned-nodes.js +41 -2
- package/dist/learned-workflow.d.ts +19 -3
- package/dist/learned-workflow.js +105 -26
- package/dist/learning-batch.d.ts +2 -2
- package/dist/learning-batch.js +1 -1
- package/dist/learning-cost.d.ts +18 -6
- package/dist/learning-cost.js +15 -7
- package/dist/learning-routes.d.ts +14 -2
- package/dist/learning-routes.js +14 -3
- package/dist/learning-words.d.ts +7 -0
- package/dist/learning-words.js +7 -0
- package/dist/learning.d.ts +31 -6
- package/dist/learning.js +7 -4
- package/dist/llm.js +0 -3
- package/dist/mcp-gateway.d.ts +12 -20
- package/dist/mcp-gateway.js +16 -44
- package/dist/mcp-oauth.d.ts +5 -0
- package/dist/mcp-oauth.js +1 -1
- package/dist/mcp-pin-first.d.ts +37 -0
- package/dist/mcp-pin-first.js +107 -0
- package/dist/mcp-probe.d.ts +8 -9
- package/dist/mcp-probe.js +16 -33
- package/dist/mcp-servers-store.d.ts +89 -22
- package/dist/mcp-servers-store.js +131 -25
- package/dist/mcp-sources.d.ts +39 -0
- package/dist/mcp-sources.js +74 -0
- package/dist/mcp-store.d.ts +11 -0
- package/dist/mcp-store.js +16 -2
- package/dist/mcp-wire.d.ts +22 -0
- package/dist/mcp-wire.js +36 -0
- package/dist/mcp.js +3 -3
- package/dist/meta-tool-names.d.ts +1 -0
- package/dist/meta-tool-names.js +3 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +46 -15
- package/dist/monid.d.ts +51 -25
- package/dist/monid.js +226 -140
- package/dist/openapi.js +336 -66
- package/dist/paid-calls.d.ts +26 -29
- package/dist/paid-calls.js +46 -102
- package/dist/propose.d.ts +7 -1
- package/dist/propose.js +18 -6
- package/dist/provider.js +9 -2
- package/dist/reflect-range.js +2 -1
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +13 -0
- package/dist/run-launch.js +6 -0
- package/dist/run-learning-served.d.ts +13 -2
- package/dist/run-manifest.d.ts +5 -0
- package/dist/run-manifest.js +20 -0
- package/dist/run-secrets.js +2 -3
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +17 -6
- package/dist/run-view.js +51 -22
- package/dist/runnable.d.ts +0 -3
- package/dist/runnable.js +37 -29
- package/dist/runner/adapter-loop.d.ts +24 -10
- package/dist/runner/adapter-loop.js +852 -314
- package/dist/runner/adapter-run-spec.d.ts +12 -6
- package/dist/runner/adapter-run-spec.js +97 -46
- package/dist/runner/adapters/pi-computer.d.ts +3 -1
- package/dist/runner/adapters/pi-computer.js +13 -5
- package/dist/runner/adapters/pi.d.ts +16 -7
- package/dist/runner/adapters/pi.js +94 -33
- package/dist/runner/cli-run-spec.js +67 -27
- package/dist/runner/computer-channel.js +2 -1
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +145 -4
- package/dist/runner/conformance/subject.d.ts +11 -4
- package/dist/runner/end-of-run.d.ts +6 -5
- package/dist/runner/end-of-run.js +9 -6
- package/dist/runner/feedback-round.d.ts +52 -0
- package/dist/runner/feedback-round.js +79 -0
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +15 -0
- package/dist/runner/learning-end.d.ts +54 -19
- package/dist/runner/learning-end.js +272 -99
- package/dist/runner/learning-loop.d.ts +19 -1
- package/dist/runner/learning-loop.js +5 -2
- package/dist/runner/learning-seed.d.ts +4 -0
- package/dist/runner/learning-seed.js +14 -0
- package/dist/runner/loop-contract.d.ts +19 -3
- package/dist/runner/loop.d.ts +16 -1
- package/dist/runner/loop.js +21 -1
- package/dist/runner/mcp-claim.d.ts +5 -1
- package/dist/runner/mcp-claim.js +66 -50
- package/dist/runner/mcp-run.d.ts +16 -52
- package/dist/runner/mcp-run.js +12 -84
- package/dist/runner/meta-tools.d.ts +37 -0
- package/dist/runner/meta-tools.js +268 -0
- package/dist/runner/metrics.js +14 -3
- package/dist/runner/model-route.js +12 -3
- package/dist/runner/monid-run.d.ts +16 -0
- package/dist/runner/monid-run.js +96 -0
- package/dist/runner/promotion.d.ts +80 -0
- package/dist/runner/promotion.js +562 -0
- package/dist/runner/reflect-hook.d.ts +36 -21
- package/dist/runner/reflect-hook.js +138 -49
- package/dist/runner/runner.js +26 -4
- package/dist/runner/sessions.d.ts +8 -3
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +7 -12
- package/dist/runner/workflow-first.d.ts +216 -0
- package/dist/runner/workflow-first.js +303 -0
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +1 -0
- package/dist/runner/workflow-spec.js +7 -3
- package/dist/runs-over-store.d.ts +11 -2
- package/dist/runs-over-store.js +21 -11
- package/dist/server.d.ts +88 -16
- package/dist/server.js +380 -87
- package/dist/settings-wake.d.ts +8 -6
- package/dist/settings-wake.js +13 -7
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/command-wake.d.ts +3 -2
- package/dist/store/command-wake.js +4 -4
- package/dist/store/postgres/connection.js +3 -1
- package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
- package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +28 -8
- package/dist/store/sqlite/connection.d.ts +2 -2
- package/dist/store/sqlite/connection.js +2 -2
- package/dist/store/sqlite/run-patch.js +19 -7
- package/dist/store/sqlite/store.js +59 -18
- package/dist/store/store.d.ts +46 -14
- package/dist/store-reads/journal.d.ts +25 -1
- package/dist/store-reads/journal.js +63 -49
- package/dist/store-reads/learning.d.ts +101 -15
- package/dist/store-reads/learning.js +195 -61
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-view.d.ts +3 -2
- package/dist/store-view.js +35 -17
- package/dist/template-eval.d.ts +18 -9
- package/dist/template-eval.js +91 -66
- package/dist/template-github-permissions.d.ts +2 -2
- package/dist/template-github-permissions.js +2 -1
- package/dist/template-import.d.ts +31 -0
- package/dist/template-import.js +121 -0
- package/dist/template-source.d.ts +51 -0
- package/dist/template-source.js +371 -0
- package/dist/templates.d.ts +218 -46
- package/dist/templates.js +493 -181
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +4 -3
- package/dist/timeline/index.js +4 -3
- package/dist/timeline/labels.d.ts +6 -2
- package/dist/timeline/labels.js +93 -2
- package/dist/timeline/origin.d.ts +19 -5
- package/dist/timeline/origin.js +11 -4
- package/dist/timeline/timeline.d.ts +11 -17
- package/dist/timeline/timeline.js +24 -9
- package/dist/tool-gate.d.ts +73 -46
- package/dist/tool-gate.js +133 -66
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +26 -0
- package/dist/tool-list.js +43 -0
- package/dist/tool-names.d.ts +71 -0
- package/dist/tool-names.js +99 -0
- package/dist/tool-plane.d.ts +29 -27
- package/dist/tool-plane.js +65 -37
- package/dist/tools.d.ts +22 -6
- package/dist/tools.js +24 -20
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +91 -44
- package/dist/web-fetch.d.ts +1 -7
- package/dist/web-fetch.js +2 -22
- package/dist/workspace/computer-deps.d.ts +3 -0
- package/dist/workspace/computer-deps.js +5 -2
- package/dist/workspace/computer-for-claim.d.ts +6 -0
- package/dist/workspace/computer-for-claim.js +32 -14
- package/dist/workspace/computer-hold.js +7 -1
- package/dist/workspace/computer-script.d.ts +23 -7
- package/dist/workspace/computer-script.js +48 -14
- package/dist/workspace/index.d.ts +2 -2
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +21 -1
- package/dist/workspace/resolve-computer.js +32 -14
- package/dist/workspace/run-tools.d.ts +28 -10
- package/dist/workspace/run-tools.js +39 -11
- package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
- package/dist/wrap-up.js +21 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +9 -9
- package/templates/README.md +111 -45
- package/templates/code-review/agent.md +30 -14
- package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
- package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
- package/templates/code-review/evals/injection/case.yaml +2 -1
- package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
- package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
- package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
- package/templates/code-review/evals/never-flag/case.yaml +2 -1
- package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
- package/templates/code-review/evals/null-name/case.yaml +2 -1
- package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
- package/templates/code-review/evals/off-by-one/case.yaml +2 -1
- package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/case.yaml +16 -0
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
- package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/code-review/evals/other-repo/prompt.md +10 -0
- package/templates/code-review/evals/re-review/case.yaml +2 -1
- package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
- package/templates/code-review/evals/re-review-open/case.yaml +2 -1
- package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
- package/templates/code-review/evals/repo-rule/case.yaml +2 -1
- package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
- package/templates/code-review/evals/two-defects/case.yaml +2 -1
- package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
- package/templates/code-review/rules/CODEREVIEW.md +1 -1
- package/templates/code-review/skills/review/DEEP.md +3 -2
- package/templates/code-review/skills/review/REVIEWER.md +3 -2
- package/templates/code-review/skills/review/SKILL.md +4 -3
- package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
- package/templates/inbound-lead/agent.md +26 -16
- package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
- package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
- package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
- package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
- package/templates/kyb/agent.md +15 -5
- package/templates/kyb/evals/adverse-media/prompt.md +2 -7
- package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
- package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
- package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
- package/templates/kyb/evals/name-collision/prompt.md +2 -6
- package/templates/kyb/evals/no-invention/prompt.md +2 -6
- package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
- package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
- package/templates/kyb/kyb.schema.json +8 -7
- package/templates/kyb/skills/kyb/SKILL.md +9 -6
- package/templates/market-monitor/agent.md +19 -12
- package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +32 -10
- package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/learned-style/case.yaml +2 -1
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
- package/templates/release-notes/evals/other-repo/case.yaml +24 -0
- package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
- package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
- package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/release-notes/evals/other-repo/prompt.md +32 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
- package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
- package/templates/release-notes/notes.schema.json +1 -1
- package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
- package/dist/console/assets/index-Cn6JX1uH.js +0 -563
- package/dist/console/assets/index-DRN62V5v.css +0 -1
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.js +0 -62
- package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
- package/templates/code-review/evals/injection/graders/schema.md +0 -5
- package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
- package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
- package/templates/code-review/evals/null-name/graders/schema.md +0 -5
- package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
- package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
- package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
- package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
- package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
- package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
- package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
- package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
- package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
- package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
- package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { PROMOTE_BAR, SOFT_ESCALATE_THRESHOLD, softEscalatesOf, walkGuards } from "./promote.js";
|
|
2
|
+
import { workflowNodes } from "./workflow-nodes.js";
|
|
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
|
+
export const OFF = 0;
|
|
5
|
+
export const FIT_MIN_ROWS = 30;
|
|
6
|
+
/** The lowest and highest threshold a refit writes: the DSL takes a threshold in (0, 1), exclusive. */
|
|
7
|
+
export const THRESHOLD_MIN = 0.001;
|
|
8
|
+
export const THRESHOLD_MAX = 0.999;
|
|
9
|
+
export const FIT_MIN_WRONG = 5;
|
|
10
|
+
const sigmoid = (z) => 1 / (1 + Math.exp(-z));
|
|
11
|
+
const round = (value, places = 4) => Math.round(value * 10 ** places) / 10 ** places;
|
|
12
|
+
/** A logistic fit of y over x (Newton's method with a small ridge, so separable rows stay finite): weights and bias. */
|
|
13
|
+
export function fitLogistic(xs, ys, ridge = 1e-2) {
|
|
14
|
+
const d = xs[0]?.length ?? 0;
|
|
15
|
+
let beta = new Array(d + 1).fill(0);
|
|
16
|
+
for (let iter = 0; iter < 50; iter++) {
|
|
17
|
+
const grad = new Array(d + 1).fill(0);
|
|
18
|
+
const hess = Array.from({ length: d + 1 }, () => new Array(d + 1).fill(0));
|
|
19
|
+
xs.forEach((x, i) => {
|
|
20
|
+
const row = [1, ...x];
|
|
21
|
+
const p = sigmoid(row.reduce((sum, v, j) => sum + v * beta[j], 0));
|
|
22
|
+
const err = (ys[i] ? 1 : 0) - p;
|
|
23
|
+
for (let j = 0; j <= d; j++) {
|
|
24
|
+
grad[j] += err * row[j];
|
|
25
|
+
for (let k = 0; k <= d; k++)
|
|
26
|
+
hess[j][k] += p * (1 - p) * row[j] * row[k];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
for (let j = 1; j <= d; j++) {
|
|
30
|
+
grad[j] -= ridge * beta[j];
|
|
31
|
+
hess[j][j] += ridge;
|
|
32
|
+
}
|
|
33
|
+
const step = solve(hess, grad);
|
|
34
|
+
if (!step)
|
|
35
|
+
break;
|
|
36
|
+
beta = beta.map((v, j) => v + step[j]);
|
|
37
|
+
if (Math.max(...step.map(Math.abs)) < 1e-8)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return { w: beta.slice(1).map((v) => round(v, 6)), b: round(beta[0], 6) };
|
|
41
|
+
}
|
|
42
|
+
/** a·x = b by Gaussian elimination with partial pivoting; undefined when singular. */
|
|
43
|
+
function solve(a, b) {
|
|
44
|
+
const n = b.length;
|
|
45
|
+
const m = a.map((row, i) => [...row, b[i]]);
|
|
46
|
+
for (let col = 0; col < n; col++) {
|
|
47
|
+
let pivot = col;
|
|
48
|
+
for (let r = col + 1; r < n; r++)
|
|
49
|
+
if (Math.abs(m[r][col]) > Math.abs(m[pivot][col]))
|
|
50
|
+
pivot = r;
|
|
51
|
+
if (Math.abs(m[pivot][col]) < 1e-12)
|
|
52
|
+
return undefined;
|
|
53
|
+
[m[col], m[pivot]] = [m[pivot], m[col]];
|
|
54
|
+
for (let r = 0; r < n; r++) {
|
|
55
|
+
if (r === col)
|
|
56
|
+
continue;
|
|
57
|
+
const f = m[r][col] / m[col][col];
|
|
58
|
+
for (let c = col; c <= n; c++)
|
|
59
|
+
m[r][c] -= f * m[col][c];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return m.map((row, i) => row[n] / row[i]);
|
|
63
|
+
}
|
|
64
|
+
/** The rows' accuracies with p read through `pOf` and each step held to `thresholds`: a row any guard of hands back on
|
|
65
|
+
* takes the agent's answer; one that answered alone, its grade. A row that did not answer alone because a guard handed
|
|
66
|
+
* it back (one of its guards escalated) and that no guard would hand back at `thresholds` would have answered with an
|
|
67
|
+
* answer nobody read: counted wrong, so a threshold never comes down past hand-backs with no evidence of what the
|
|
68
|
+
* workflow says there. One that did not answer for another reason (a step failed, an escalate node) takes the agent's
|
|
69
|
+
* answer at every threshold. A switch OFF never hands back, a missing p or not. */
|
|
70
|
+
function scoreAt(rows, pOf, thresholds) {
|
|
71
|
+
let [wf, agent, handed] = [0, 0, 0];
|
|
72
|
+
for (const row of rows) {
|
|
73
|
+
agent += row.agentCorrect;
|
|
74
|
+
const under = row.guards.some((guard) => {
|
|
75
|
+
const at = thresholds.get(guard.node) ?? guard.threshold;
|
|
76
|
+
if (at === OFF)
|
|
77
|
+
return false;
|
|
78
|
+
const p = pOf(guard);
|
|
79
|
+
return p === null || p < at;
|
|
80
|
+
});
|
|
81
|
+
const known = row.answered && row.wfCorrect !== null;
|
|
82
|
+
if (under || (!known && !row.guards.some((guard) => guard.escalated))) {
|
|
83
|
+
handed += 1;
|
|
84
|
+
wf += row.agentCorrect;
|
|
85
|
+
}
|
|
86
|
+
else if (known && row.wfCorrect)
|
|
87
|
+
wf += 1;
|
|
88
|
+
}
|
|
89
|
+
const n = rows.length || 1;
|
|
90
|
+
return { wf_acc: wf / n, agent_acc: agent / n, handed_back: handed };
|
|
91
|
+
}
|
|
92
|
+
/** How good one raise is, compared first to last: any accuracy gained before none; then accuracy per input handed back
|
|
93
|
+
* (a gain that hands back nothing first); then the fewest handed back. A raise that gains nothing ranks by its loss. */
|
|
94
|
+
const raiseRank = (gain, added) => (gain > 1e-12 ? [1, added > 0 ? gain / added : Number.POSITIVE_INFINITY, -added] : [0, gain, -added]);
|
|
95
|
+
const rankAbove = (a, b) => {
|
|
96
|
+
for (let i = 0; i < a.length; i++)
|
|
97
|
+
if (a[i] !== b[i])
|
|
98
|
+
return a[i] > b[i];
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
/** The escalates of `doc` a refit may switch off: each a replay records (softEscalatesOf) that is a step of a chain with
|
|
102
|
+
* a step that is no escalate, so the chain keeps a step once they are dropped. */
|
|
103
|
+
function switchableEscalates(doc) {
|
|
104
|
+
const soft = softEscalatesOf(doc);
|
|
105
|
+
const out = new Set();
|
|
106
|
+
for (const { node, prefix } of workflowNodes(doc)) {
|
|
107
|
+
if (node.node !== "chain" || !Array.isArray(node.steps))
|
|
108
|
+
continue;
|
|
109
|
+
const steps = node.steps;
|
|
110
|
+
if (!steps.some((step) => step?.node !== "escalate"))
|
|
111
|
+
continue;
|
|
112
|
+
for (const step of steps)
|
|
113
|
+
if (step?.node === "escalate" && soft.has(`${prefix}${step.label}`))
|
|
114
|
+
out.add(`${prefix}${step.label}`);
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
/** The workflow `text`'s guards, and the escalates its replay recorded, refit over `rows` (`now`: the fit's fitted_at). A
|
|
119
|
+
* guard whose step no row reached keeps what it has, and so does an escalate no row recorded. Nothing changes (no
|
|
120
|
+
* `text`) when every guard keeps its threshold and fit and every escalate stays. */
|
|
121
|
+
export function refitGuards(text, rows, now) {
|
|
122
|
+
let doc;
|
|
123
|
+
try {
|
|
124
|
+
doc = JSON.parse(text);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return { guards: [], n: rows.length, agent_acc: 0, wf_acc: 0, delta: 0, handed_back: 0 };
|
|
128
|
+
}
|
|
129
|
+
const guards = [];
|
|
130
|
+
walkGuards(doc, (label, guard, node) => guards.push({ label, guard, node }));
|
|
131
|
+
const recorded = new Set(rows.flatMap((row) => row.guards.filter((g) => g.signal === "escalate").map((g) => g.node)));
|
|
132
|
+
const escalates = [...switchableEscalates(doc)].filter((label) => recorded.has(label));
|
|
133
|
+
const fits = new Map();
|
|
134
|
+
for (const { label, guard } of guards) {
|
|
135
|
+
if (guard.signal !== "both" || fits.has(label))
|
|
136
|
+
continue;
|
|
137
|
+
const data = rows.flatMap((row) => {
|
|
138
|
+
const one = row.guards.find((g) => g.node === label);
|
|
139
|
+
return one && typeof one.self === "number" && typeof one.jev === "number" && row.answered && row.wfCorrect !== null ? [{ x: [one.self, one.jev], y: row.wfCorrect }] : [];
|
|
140
|
+
});
|
|
141
|
+
if (data.length < FIT_MIN_ROWS || data.filter(({ y }) => !y).length < FIT_MIN_WRONG)
|
|
142
|
+
continue;
|
|
143
|
+
fits.set(label, { ...fitLogistic(data.map(({ x }) => x), data.map(({ y }) => y)), n: data.length, fitted_at: now });
|
|
144
|
+
}
|
|
145
|
+
// A step's p as the guard would read it with its new fit (the row's own p when no new fit).
|
|
146
|
+
const pOf = (row) => {
|
|
147
|
+
const fit = fits.get(row.node);
|
|
148
|
+
if (!fit)
|
|
149
|
+
return row.p;
|
|
150
|
+
if (typeof row.self !== "number" || typeof row.jev !== "number")
|
|
151
|
+
return null;
|
|
152
|
+
return sigmoid(fit.b + fit.w[0] * row.self + fit.w[1] * row.jev);
|
|
153
|
+
};
|
|
154
|
+
const was = new Map(guards.map(({ label, guard }) => [label, typeof guard.threshold === "number" ? guard.threshold : OFF]));
|
|
155
|
+
const thresholds = new Map([...was, ...escalates.map((label) => [label, SOFT_ESCALATE_THRESHOLD])]);
|
|
156
|
+
const agentAcc = scoreAt(rows, pOf, thresholds).agent_acc;
|
|
157
|
+
const meets = (at) => scoreAt(rows, pOf, at).wf_acc >= agentAcc - PROMOTE_BAR - 1e-9;
|
|
158
|
+
// Each guard's candidates: OFF (hands back nothing), THRESHOLD_MIN (nothing but a missing p or one under it), each p its
|
|
159
|
+
// rows read within the DSL's range, its own threshold, and THRESHOLD_MAX; a step no row reached keeps its own. Each
|
|
160
|
+
// recorded escalate's: off or on.
|
|
161
|
+
const candidatesOf = new Map(escalates.map((label) => [label, [OFF, SOFT_ESCALATE_THRESHOLD]]));
|
|
162
|
+
for (const [label, own] of was) {
|
|
163
|
+
const seen = rows.flatMap((row) => row.guards.filter((g) => g.node === label).map(pOf)).filter((p) => p !== null);
|
|
164
|
+
const at = (p) => Math.min(THRESHOLD_MAX, Math.max(THRESHOLD_MIN, round(p, 6)));
|
|
165
|
+
if (seen.length)
|
|
166
|
+
candidatesOf.set(label, [...new Set([OFF, THRESHOLD_MIN, ...seen.map(at), ...(own > 0 && own < 1 ? [own] : []), THRESHOLD_MAX])].sort((a, b) => a - b));
|
|
167
|
+
}
|
|
168
|
+
const kept = new Map(thresholds);
|
|
169
|
+
// Up from the bottom: while the bar is not met, the one raise (a guard to a higher candidate) that buys the most accuracy
|
|
170
|
+
// per input it hands back. Taking the steps in order instead traps the refit: the first step alone meets the bar only by
|
|
171
|
+
// handing back every input, and the step whose guard tells right from wrong is then never raised.
|
|
172
|
+
for (const [label, candidates] of candidatesOf)
|
|
173
|
+
thresholds.set(label, candidates[0]);
|
|
174
|
+
for (let now = scoreAt(rows, pOf, thresholds); !meets(thresholds);) {
|
|
175
|
+
let best;
|
|
176
|
+
for (const [label, candidates] of candidatesOf) {
|
|
177
|
+
for (const at of candidates.filter((c) => c > thresholds.get(label))) {
|
|
178
|
+
const next = scoreAt(rows, pOf, new Map([...thresholds, [label, at]]));
|
|
179
|
+
const rank = raiseRank(next.wf_acc - now.wf_acc, next.handed_back - now.handed_back);
|
|
180
|
+
if (!best || rankAbove(rank, best.rank))
|
|
181
|
+
best = { label, at, rank, next };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!best)
|
|
185
|
+
break;
|
|
186
|
+
thresholds.set(best.label, best.at);
|
|
187
|
+
now = best.next;
|
|
188
|
+
}
|
|
189
|
+
if (!meets(thresholds))
|
|
190
|
+
for (const [label, at] of kept)
|
|
191
|
+
thresholds.set(label, at);
|
|
192
|
+
// Then down: each step in turn, twice over, the lowest threshold (the fewest hand-backs) that keeps the bar, the others held.
|
|
193
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
194
|
+
for (const [label, candidates] of candidatesOf) {
|
|
195
|
+
const found = candidates.find((candidate) => candidate <= thresholds.get(label) && meets(new Map([...thresholds, [label, candidate]])));
|
|
196
|
+
if (found !== undefined)
|
|
197
|
+
thresholds.set(label, found);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const changed = [];
|
|
201
|
+
for (const { label, guard, node } of guards) {
|
|
202
|
+
const threshold = thresholds.get(label);
|
|
203
|
+
const fit = fits.get(label);
|
|
204
|
+
if (threshold === was.get(label) && !fit)
|
|
205
|
+
continue;
|
|
206
|
+
if (threshold === OFF) {
|
|
207
|
+
delete node.guard;
|
|
208
|
+
changed.push({ node: label, was: was.get(label), threshold: null });
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
guard.threshold = threshold;
|
|
212
|
+
if (fit)
|
|
213
|
+
guard.fit = fit;
|
|
214
|
+
if (!changed.some((one) => one.node === label))
|
|
215
|
+
changed.push({ node: label, was: was.get(label), threshold, ...(fit ? { fit } : {}) });
|
|
216
|
+
}
|
|
217
|
+
const off = new Set(escalates.filter((label) => thresholds.get(label) === OFF));
|
|
218
|
+
if (off.size) {
|
|
219
|
+
for (const { node, prefix } of workflowNodes(doc)) {
|
|
220
|
+
if (node.node === "chain" && Array.isArray(node.steps))
|
|
221
|
+
node.steps = node.steps.filter((step) => !(step?.node === "escalate" && off.has(`${prefix}${step.label}`)));
|
|
222
|
+
}
|
|
223
|
+
for (const label of off)
|
|
224
|
+
changed.push({ node: label, was: null, threshold: null, escalate: true });
|
|
225
|
+
}
|
|
226
|
+
const score = scoreAt(rows, pOf, thresholds);
|
|
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
|
+
};
|
|
236
|
+
}
|
package/dist/learn/reflect.d.ts
CHANGED
|
@@ -1,46 +1,26 @@
|
|
|
1
|
-
import { type DraftDecisions } from "./skills.js";
|
|
2
1
|
/** The info word that opens a note's block in the answer: ```note <file>. */
|
|
3
2
|
export declare const NOTE_BLOCK = "note";
|
|
4
3
|
/** The info words that open a skill's and a workflow draft's block: ````skill <name> and ````workflow <name>, each fenced
|
|
5
4
|
* with four backticks so a ``` line inside does not close it. */
|
|
6
5
|
export declare const SKILL_BLOCK = "skill";
|
|
7
6
|
export declare const WORKFLOW_BLOCK = "workflow";
|
|
8
|
-
/** How many earlier runs of an agent a learned skill has been given to before the host asks for its job as a workflow
|
|
9
|
-
* draft (`draftFor`): a run proposes one only when it thinks to, and few do. */
|
|
10
|
-
export declare const DRAFT_AFTER_RUNS = 3;
|
|
11
7
|
/** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
|
|
12
8
|
* follow-up opened it again from, so only what came since is new. */
|
|
13
9
|
export declare const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
|
|
14
10
|
/** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
|
|
15
11
|
* where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
|
|
16
|
-
* is how many notes are active in it, so how many lines the index has left.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* draft asked for: what each of `tools` takes and gives a call node, in the server's own words (tools.ts ToolEntry
|
|
21
|
-
* summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
|
|
22
|
-
* spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
|
|
23
|
-
* for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
|
|
24
|
-
* workflow draft, and asks for none (`draftFor` and `described` are not said). `decisions`, the run's decision providers
|
|
25
|
-
* (skills.ts DraftDecisions, the one the draft check reads): with a provider it has (draftDecisionProviders), a draft may
|
|
26
|
-
* use judge, pick and sift nodes; without, the prompt bans them as it always did. `later`, a later round's (a follow-up
|
|
27
|
-
* opened the run again after it looked back): the prompt says so (LATER_LOOK) after its first line. */
|
|
12
|
+
* is how many notes are active in it, so how many lines the index has left. The turn keeps notes and a skill; a job
|
|
13
|
+
* that repeats is compiled into a learned workflow by the compile turn (learn/compile.ts), never drafted here. `later`,
|
|
14
|
+
* a later round's (a follow-up opened the run again after it looked back): the prompt says so (LATER_LOOK) after its
|
|
15
|
+
* first line. */
|
|
28
16
|
export declare function reflectPrompt(options: {
|
|
29
17
|
dir: string;
|
|
30
18
|
active: number;
|
|
31
|
-
tools?: readonly string[];
|
|
32
|
-
draftFor?: readonly string[];
|
|
33
|
-
described?: readonly {
|
|
34
|
-
readonly name: string;
|
|
35
|
-
readonly does: string;
|
|
36
|
-
}[];
|
|
37
|
-
workflows?: boolean;
|
|
38
|
-
decisions?: DraftDecisions;
|
|
39
19
|
later?: boolean;
|
|
40
20
|
}): string;
|
|
41
21
|
/** The end-of-run turn asked again, once, when the parser refused its answer: why, in the parser's own words (`detail`,
|
|
42
22
|
* parseReflection's), and the whole answer again in the format. */
|
|
43
|
-
export declare function reflectAgain(detail: string
|
|
23
|
+
export declare function reflectAgain(detail: string): string;
|
|
44
24
|
/** The end-of-run turn asked again, once, when the checks left a workflow draft out because its dry run failed: which
|
|
45
25
|
* draft, in the host's own words, and why (`detail`, the check's words, made from the draft's own text: a step's label,
|
|
46
26
|
* a path) inside a data fence alone, cleaned of control and format characters and capped, its token one the detail
|
package/dist/learn/reflect.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// What a host asks of an agent once its run has answered or failed: one more turn in the same session, in which the agent
|
|
2
|
-
// answers with the notes it would keep, and a skill
|
|
3
|
-
//
|
|
2
|
+
// answers with the notes it would keep, and a skill when the work repeats, as text in a strict format, and uses no tool
|
|
3
|
+
// (a workflow is the compile turn's, learn/compile.ts, whose answer this parser reads too). The host parses the answer (parseReflection), checks what it gives (check.ts), a grader
|
|
4
4
|
// judges it (grade.ts), and the host merges it, rebuilding the index; the agent never writes the folder, and nothing it
|
|
5
5
|
// wrote during the task counts. The same on every harness: every model writes markdown, and no tool is needed.
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { CAPS } from "./check.js";
|
|
8
8
|
import { INDEX_FILE, INDEX_LINES } from "./notes.js";
|
|
9
|
-
import { draftDecisionProviders, LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
|
|
10
9
|
/** Control and invisible characters: none may reach the prompt through a value the host puts in it. */
|
|
11
10
|
const UNSEEN = /[\p{Cc}\p{Cf}]/u;
|
|
12
11
|
/** The info word that opens a note's block in the answer: ```note <file>. */
|
|
@@ -15,41 +14,21 @@ export const NOTE_BLOCK = "note";
|
|
|
15
14
|
* with four backticks so a ``` line inside does not close it. */
|
|
16
15
|
export const SKILL_BLOCK = "skill";
|
|
17
16
|
export const WORKFLOW_BLOCK = "workflow";
|
|
18
|
-
/** How many earlier runs of an agent a learned skill has been given to before the host asks for its job as a workflow
|
|
19
|
-
* draft (`draftFor`): a run proposes one only when it thinks to, and few do. */
|
|
20
|
-
export const DRAFT_AFTER_RUNS = 3;
|
|
21
|
-
/** A tool's name as the prompt may print it: a table tool's, or an MCP tool's a learned workflow may run (skills.ts
|
|
22
|
-
* LEARNED_MCP_TOOL). */
|
|
23
|
-
const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
24
|
-
const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
|
|
25
17
|
/** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
|
|
26
18
|
* follow-up opened it again from, so only what came since is new. */
|
|
27
19
|
export const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
|
|
28
20
|
/** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
|
|
29
21
|
* where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
|
|
30
|
-
* is how many notes are active in it, so how many lines the index has left.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* draft asked for: what each of `tools` takes and gives a call node, in the server's own words (tools.ts ToolEntry
|
|
35
|
-
* summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
|
|
36
|
-
* spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
|
|
37
|
-
* for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
|
|
38
|
-
* workflow draft, and asks for none (`draftFor` and `described` are not said). `decisions`, the run's decision providers
|
|
39
|
-
* (skills.ts DraftDecisions, the one the draft check reads): with a provider it has (draftDecisionProviders), a draft may
|
|
40
|
-
* use judge, pick and sift nodes; without, the prompt bans them as it always did. `later`, a later round's (a follow-up
|
|
41
|
-
* opened the run again after it looked back): the prompt says so (LATER_LOOK) after its first line. */
|
|
22
|
+
* is how many notes are active in it, so how many lines the index has left. The turn keeps notes and a skill; a job
|
|
23
|
+
* that repeats is compiled into a learned workflow by the compile turn (learn/compile.ts), never drafted here. `later`,
|
|
24
|
+
* a later round's (a follow-up opened the run again after it looked back): the prompt says so (LATER_LOOK) after its
|
|
25
|
+
* first line. */
|
|
42
26
|
export function reflectPrompt(options) {
|
|
43
|
-
const { dir, active,
|
|
44
|
-
const judges = draftDecisionProviders(decisions).length > 0;
|
|
27
|
+
const { dir, active, later = false } = options;
|
|
45
28
|
if (typeof dir !== "string" || dir === "" || dir.startsWith("/") || UNSEEN.test(dir))
|
|
46
29
|
throw new Error("the directory must be a path relative to the run's workspace, with no control or unseen characters");
|
|
47
30
|
if (!Number.isSafeInteger(active) || active < 0)
|
|
48
31
|
throw new Error("the count of active notes must be a whole number, 0 or more");
|
|
49
|
-
if (!Array.isArray(tools) || tools.some((tool) => typeof tool !== "string" || !printable(tool)))
|
|
50
|
-
throw new Error("each tool must be a tool's name");
|
|
51
|
-
if (!Array.isArray(draftFor) || draftFor.some((name) => typeof name !== "string" || !SKILL_NAME.test(name)))
|
|
52
|
-
throw new Error("each skill a draft is asked for must be a skill's name");
|
|
53
32
|
const left = Math.max(0, INDEX_LINES - active);
|
|
54
33
|
return [
|
|
55
34
|
"The task is done. Before the run ends, say what this run taught you that will help in later runs, if anything.",
|
|
@@ -93,29 +72,17 @@ export function reflectPrompt(options) {
|
|
|
93
72
|
"site, a source or a seller, or names where money or data goes.",
|
|
94
73
|
"What `# Learned` in your instructions, and this message, say about learning itself is not a lesson: never put it in a note or a skill, nor the sentence you say when you keep something.",
|
|
95
74
|
"",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"workflow draft for that job. Most runs keep neither. Neither holds this case's data: each is about the job, not the one case.",
|
|
101
|
-
] : [
|
|
102
|
-
"## Skills, only when the work repeats",
|
|
103
|
-
"",
|
|
104
|
-
"When this run did, to the end, a job this agent will be asked to do again, you may also keep one skill for that job.",
|
|
105
|
-
"Most runs keep none. It holds none of this case's data: it is about the job, not the one case.",
|
|
106
|
-
"Keep no workflow draft: this agent learns notes and skills alone.",
|
|
107
|
-
]),
|
|
75
|
+
"## Skills, only when the work repeats",
|
|
76
|
+
"",
|
|
77
|
+
"When this run did, to the end, a job this agent will be asked to do again, you may also keep one skill for that job.",
|
|
78
|
+
"Most runs keep none. It holds none of this case's data: it is about the job, not the one case.",
|
|
108
79
|
"Steps the person asks you to follow every time a task comes back are a skill, not a note: keep them as the skill, in",
|
|
109
80
|
"their words and with the exact output format they gave, and do not repeat them in a note.",
|
|
110
81
|
"A job you keep a skill for needs no note beside it.",
|
|
111
82
|
"A rule for every reply applies whatever the job is. Keep it as a note, which every later run reads. Steps or a format",
|
|
112
83
|
"for one kind of job, named by when it applies (\"whenever I ask for a weekly summary\", \"when you open a PR\"), are a",
|
|
113
84
|
"skill. A note holds its own lesson: never repeat another note's rule in it, so a retired rule stays retired.",
|
|
114
|
-
|
|
115
|
-
"A job that runs end to end as model and tool-call steps, from a defined input to a defined output, is a workflow draft,",
|
|
116
|
-
"and so is one the person asks you to keep as a workflow; its steps may also be a skill.",
|
|
117
|
-
...(draftFor.length ? [draftAsk(draftFor), ...describedLines(described, tools)] : []),
|
|
118
|
-
] : []),
|
|
85
|
+
"Keep no workflow here: when the job repeats, the host may ask for it as a workflow in a turn of its own, from your notes.",
|
|
119
86
|
"",
|
|
120
87
|
`A skill is how to do the job, step by step, as a SKILL.md: front matter with its \`name\` (lowercase letters, digits`,
|
|
121
88
|
"and single dashes) and a `description` of when to use it, then the steps. Open its block with four backticks, so a",
|
|
@@ -129,54 +96,12 @@ export function reflectPrompt(options) {
|
|
|
129
96
|
"---",
|
|
130
97
|
"1. Open the store's policies page first.",
|
|
131
98
|
"````",
|
|
132
|
-
"",
|
|
133
|
-
...(workflows ? [
|
|
134
|
-
"A workflow draft does the job as one workflow DSL document: front matter with one line that says what it does and",
|
|
135
|
-
"when to use it, then the JSON. " + (judges
|
|
136
|
-
? "It uses model and tool-call nodes, and may use judge (answers a question about a value), pick (chooses one of several options) and sift (keeps the items that pass a test) nodes, which run on this run's decision provider under its cap and tool policy; no code node, no shell or"
|
|
137
|
-
: "It uses model and tool-call nodes only: no judge, pick or sift node, no code node, no shell or"),
|
|
138
|
-
`executor call. Its model nodes name no tool. ${tools.length ? `Its call nodes may run only these tools: ${tools.join(", ")}.` : "It has no call node on a tool."} At most ${CAPS.file} bytes of JSON.`,
|
|
139
|
-
"To change a draft you were given, give it again whole under its name.",
|
|
140
|
-
"Its schemas are declared once under `schemas`, and `input` and `output` name one each by `schemaId`, never a schema",
|
|
141
|
-
"written in place.",
|
|
142
|
-
"Give its front matter an `example:` line too: one JSON object on one line, the input this run would have given it.",
|
|
143
|
-
"The host dry-runs the draft on it before it is kept (no model or tool is called) and never keeps the example.",
|
|
144
|
-
"",
|
|
145
|
-
`\`\`\`\`${WORKFLOW_BLOCK} find-policies`,
|
|
146
|
-
"---",
|
|
147
|
-
"description: Finds a store's refund policy from its public pages; use when a case asks for it",
|
|
148
|
-
`example: ${JSON.stringify(tools.includes("web_fetch") ? { url: "https://shop.example/policies" } : { text: "Refunds are accepted within 30 days of delivery." })}`,
|
|
149
|
-
"---",
|
|
150
|
-
JSON.stringify(exampleDraft(tools.includes("web_fetch"))),
|
|
151
|
-
"````",
|
|
152
|
-
] : []),
|
|
153
99
|
].join("\n");
|
|
154
100
|
}
|
|
155
|
-
/** The most of one tool's words the draft ask's description gives it. */
|
|
156
|
-
const DESCRIBED_MAX = 600;
|
|
157
|
-
/** What each of `tools` takes and gives a call node, from `described` (a tool's name and its words), one line each, under
|
|
158
|
-
* a line that says so; none when no tool of `tools` is described. */
|
|
159
|
-
const describedLines = (described, tools) => {
|
|
160
|
-
const lines = tools.flatMap((name) => {
|
|
161
|
-
const does = described.find((one) => one.name === name)?.does;
|
|
162
|
-
if (typeof does !== "string")
|
|
163
|
-
return [];
|
|
164
|
-
const flat = does.replace(new RegExp(UNSEEN.source, "gu"), " ").replace(/\s+/g, " ").trim().slice(0, DESCRIBED_MAX).trim();
|
|
165
|
-
return flat ? [`- \`${name}\`: ${flat}`] : [];
|
|
166
|
-
});
|
|
167
|
-
return lines.length ? ["What each tool a call node may run takes and gives:", ...lines] : [];
|
|
168
|
-
};
|
|
169
|
-
/** The one line that asks for a workflow draft of a skill's job, by the skill's name. */
|
|
170
|
-
const draftAsk = (names) => {
|
|
171
|
-
const listed = names.map((name) => `\`${name}\``).join(", ");
|
|
172
|
-
return names.length === 1
|
|
173
|
-
? `Your skill ${listed} has now served ${DRAFT_AFTER_RUNS} or more runs: this time, also keep its job as a workflow draft named \`${names[0]}\`, its steps as nodes, if the job runs end to end as model and tool-call steps. Its output is the job's answer in the output format the skill gives: its last node writes it, and \`output\` names that node's text.`
|
|
174
|
-
: `Your skills ${listed} have each served ${DRAFT_AFTER_RUNS} or more runs: this time, also keep one of their jobs as a workflow draft named like its skill, its steps as nodes, if the job runs end to end as model and tool-call steps. Its output is the job's answer in the output format its skill gives: its last node writes it, and \`output\` names that node's text.`;
|
|
175
|
-
};
|
|
176
101
|
/** The end-of-run turn asked again, once, when the parser refused its answer: why, in the parser's own words (`detail`,
|
|
177
102
|
* parseReflection's), and the whole answer again in the format. */
|
|
178
|
-
export function reflectAgain(detail
|
|
179
|
-
return `Your answer could not be read: ${detail}. Give the whole answer again in the format asked for above, every
|
|
103
|
+
export function reflectAgain(detail) {
|
|
104
|
+
return `Your answer could not be read: ${detail}. Give the whole answer again in the format asked for above, every note and skill block in it, and nothing else.`;
|
|
180
105
|
}
|
|
181
106
|
/** The end-of-run turn asked again, once, when the checks left a workflow draft out because its dry run failed: which
|
|
182
107
|
* draft, in the host's own words, and why (`detail`, the check's words, made from the draft's own text: a step's label,
|
|
@@ -213,48 +138,6 @@ function retryToken(file, said) {
|
|
|
213
138
|
return token;
|
|
214
139
|
}
|
|
215
140
|
}
|
|
216
|
-
/** The prompt's example workflow draft, whole: its schemas declared once, its input and output naming them by `schemaId`,
|
|
217
|
-
* and a chain the learned runner runs (a `web_fetch` call when the agent has it, then a model node; else two model
|
|
218
|
-
* nodes), so an agent copies a draft the DSL and the checker pass (a test validates this text). */
|
|
219
|
-
const exampleDraft = (fetches) => fetches
|
|
220
|
-
? {
|
|
221
|
-
v: 2,
|
|
222
|
-
name: "find-policies",
|
|
223
|
-
schemas: {
|
|
224
|
-
Store: { type: "object", properties: { url: { type: "string" } }, required: ["url"] },
|
|
225
|
-
Page: { type: "object", properties: { text: { type: "string" } } },
|
|
226
|
-
Policies: { type: "object", properties: { refund: { type: "string" } }, required: ["refund"] },
|
|
227
|
-
},
|
|
228
|
-
input: { schemaId: "Store" },
|
|
229
|
-
output: { schemaId: "Policies", path: "policies" },
|
|
230
|
-
root: {
|
|
231
|
-
node: "chain",
|
|
232
|
-
steps: [
|
|
233
|
-
{ node: "call", label: "fetch", via: "tool", tool: "web_fetch", args: { url: "{url}" }, out: "Page", as: "page", deadline_s: 30 },
|
|
234
|
-
{ node: "extract", label: "read", instructions: "Say the store's refund policy, from the page.", out: "Policies", as: "policies" },
|
|
235
|
-
],
|
|
236
|
-
},
|
|
237
|
-
}
|
|
238
|
-
: {
|
|
239
|
-
// With no tool to fetch with, the job's input is the page's text itself: every step reads what it is given,
|
|
240
|
-
// never a guess.
|
|
241
|
-
v: 2,
|
|
242
|
-
name: "find-policies",
|
|
243
|
-
schemas: {
|
|
244
|
-
Page: { type: "object", properties: { text: { type: "string" } }, required: ["text"] },
|
|
245
|
-
Lines: { type: "object", properties: { lines: { type: "string" } }, required: ["lines"] },
|
|
246
|
-
Policies: { type: "object", properties: { refund: { type: "string" } }, required: ["refund"] },
|
|
247
|
-
},
|
|
248
|
-
input: { schemaId: "Page" },
|
|
249
|
-
output: { schemaId: "Policies", path: "policies" },
|
|
250
|
-
root: {
|
|
251
|
-
node: "chain",
|
|
252
|
-
steps: [
|
|
253
|
-
{ node: "extract", label: "quote", instructions: "Copy the lines of the page's text that are about refunds.", out: "Lines", as: "lines" },
|
|
254
|
-
{ node: "extract", label: "read", instructions: "Say the store's refund policy, from those lines.", out: "Policies", as: "policies" },
|
|
255
|
-
],
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
141
|
/** The longest answer read, in UTF-16 units: 8 notes at the note cap, a skill and a workflow draft at theirs, fenced,
|
|
259
142
|
* with room for a few lines around them. */
|
|
260
143
|
export const ANSWER_MAX = 100_000;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The built-in tools a call node may run that read only: they change nothing outside the run (a web page or search read,
|
|
2
|
+
* a document's pages drawn into the run's own work/, one model completion). Every other built-in is a write. */
|
|
3
|
+
export declare const READ_TOOLS: readonly string[];
|
|
4
|
+
/** Why a replayed input is skipped, word for word: what a PromotionRecord's reason and the replay's row say. */
|
|
5
|
+
export declare const SKIPPED_WRITE = "needs a write the recording doesn't have";
|
|
6
|
+
/** `unmarked`: an MCP tool its server lists with no readOnlyHint and not destructive. A replay treats it as a write (nothing
|
|
7
|
+
* says it only reads), but its skip says why: the server may only have left the hint out (the hold's reason names it). */
|
|
8
|
+
export type ToolClass = "read" | "write" | "unmarked";
|
|
9
|
+
/** Whether `tool` (a catalog name) reads or writes: an MCP tool by `annotations` (its server's listing as the run's pin
|
|
10
|
+
* holds it, `{}` for a tool listed with none; undefined for one not listed): read only when readOnlyHint is true and
|
|
11
|
+
* destructiveHint is not, unmarked when it is listed with no readOnlyHint and not destructive; a built-in by READ_TOOLS;
|
|
12
|
+
* else write. */
|
|
13
|
+
export declare function toolClassOf(tool: string, annotations?: (tool: string) => Readonly<Record<string, unknown>> | undefined): ToolClass;
|
|
14
|
+
/** Why replay can't run MCP tools with no readOnlyHint (bare tool names, most-skipped first): "browse, fetch_page and 2
|
|
15
|
+
* more have no readOnlyHint, so replay can't run them: if they only read, mark them read-only in the MCP server". */
|
|
16
|
+
export declare function unmarkedWords(names: readonly string[]): string;
|
|
17
|
+
/** A catalog name as a person reads it in a reason: an MCP tool's own name, any other whole. */
|
|
18
|
+
export declare const toolWord: (tool: string) => string;
|
|
19
|
+
/** `value` as JSON with every object's keys sorted, at every depth: two argument objects that differ only in key order
|
|
20
|
+
* read the same. */
|
|
21
|
+
export declare function canonical(value: unknown): string;
|
|
22
|
+
/** A call's key: the tool's wire name (a catalog name or a wire name alike) and its canonical arguments. */
|
|
23
|
+
export declare const callKey: (tool: string, args: unknown) => string;
|
|
24
|
+
/** One recorded call's answer: its text, the structured details pi kept beside it (a built-in's whole value), and whether
|
|
25
|
+
* it ended an error. */
|
|
26
|
+
export type Recorded = {
|
|
27
|
+
readonly text: string;
|
|
28
|
+
readonly details?: unknown;
|
|
29
|
+
readonly isError: boolean;
|
|
30
|
+
};
|
|
31
|
+
type EntryLike = {
|
|
32
|
+
readonly kind: string;
|
|
33
|
+
readonly model?: readonly unknown[];
|
|
34
|
+
};
|
|
35
|
+
/** The calls a run's journal recorded (`entries`, pi-shaped: store-reads/journal.ts piShaped for a CLI's record), by
|
|
36
|
+
* callKey: each call's answer, the first one when a run made the same call twice. A call refused before it ran (its
|
|
37
|
+
* gate's deny) recorded no answer and is left out. */
|
|
38
|
+
export declare function recordedCalls(entries: readonly EntryLike[]): Map<string, Recorded>;
|
|
39
|
+
/** The write that stopped a replay's input: its tool and step, and `unmarked` when it is an MCP tool its server listed with
|
|
40
|
+
* no readOnlyHint (toolClassOf). */
|
|
41
|
+
export type Skipped = {
|
|
42
|
+
readonly tool: string;
|
|
43
|
+
readonly step: string;
|
|
44
|
+
readonly unmarked?: true;
|
|
45
|
+
};
|
|
46
|
+
/** A replay's call nodes (learned-workflow.ts runLearned's `run.replay`): `call` runs each by the rules above. `skipped`:
|
|
47
|
+
* the write that stopped it, once one did; `stop` aborts the workflow's run there. `live`: how many reads ran live. */
|
|
48
|
+
export interface ReplayCalls {
|
|
49
|
+
call(node: {
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly tool: string;
|
|
52
|
+
}, args: unknown, live: () => Promise<unknown>): Promise<unknown>;
|
|
53
|
+
readonly skipped: Skipped | undefined;
|
|
54
|
+
readonly stop: AbortSignal;
|
|
55
|
+
readonly live: number;
|
|
56
|
+
}
|
|
57
|
+
/** What a call node throws when its write has no recording: the replay of this input stops. */
|
|
58
|
+
export declare class ReplaySkipped extends Error {
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
/** The replay's call nodes over `recorded` (recordedCalls of the graded run), each tool classed by `classOf`. */
|
|
62
|
+
export declare function replayCalls(recorded: ReadonlyMap<string, Recorded>, classOf: (tool: string) => ToolClass): ReplayCalls;
|
|
63
|
+
export {};
|