@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -5,6 +5,26 @@ import { type Ledger } from "./paid-calls.js";
|
|
|
5
5
|
import type { Plane } from "./tool-plane.js";
|
|
6
6
|
import { type SettingFrom } from "./tool-gate.js";
|
|
7
7
|
import type { Complete } from "./llm.js";
|
|
8
|
+
/** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
|
|
9
|
+
export declare const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
|
|
10
|
+
/** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
|
|
11
|
+
* are the workflow's to decide, then every one of them by name. The card leads with these (the call's own input after
|
|
12
|
+
* them), so they are never cut behind a long input. */
|
|
13
|
+
export declare const learnedAskShown: (asks: readonly string[]) => Record<string, unknown>;
|
|
14
|
+
/** The most bytes of the card those fields may take: the card's preview is cut at ARGS_PREVIEW_BYTES (2 KB), and its
|
|
15
|
+
* braces and the call's name follow them. A workflow whose ask-gated MCP tools would not all show is refused, never
|
|
16
|
+
* approved by a person who could not see what they approved. */
|
|
17
|
+
export declare const LEARNED_ASK_CARD_BYTES: number;
|
|
18
|
+
/** Whether every MCP tool set to ask that the workflow can call fits on its card (learnedAskShown, LEARNED_ASK_CARD_BYTES). */
|
|
19
|
+
export declare const learnedAskFits: (asks: readonly string[]) => boolean;
|
|
20
|
+
/** The MCP tools a person's approval of a learned_workflow call covers: exactly those its card named (learnedAskShown's
|
|
21
|
+
* `mcp_calls`, read from the card they approved, host-calls.ts HostCalls.approved). None when no person approved it,
|
|
22
|
+
* or the card named none. A tool set to ask that the card did not name (one set to ask after the card was shown) is
|
|
23
|
+
* never run under that approval. */
|
|
24
|
+
export declare const learnedApprovedTools: (card: Readonly<Record<string, unknown>> | undefined) => ReadonlySet<string>;
|
|
25
|
+
/** The MCP tools a learned workflow's call nodes name (`via: "tool"`, `tool: "mcp:<server>/<tool>"`), each once; none for
|
|
26
|
+
* one that does not read. The run's gate asks about them before the workflow's call runs (adapter-run-spec.ts). */
|
|
27
|
+
export declare function learnedMcpTools(workflow: string): Promise<string[]>;
|
|
8
28
|
export declare const LEARNED_WORKFLOW_TOOL = "learned_workflow";
|
|
9
29
|
/** One line of a learned workflow's output for its row: an object's fields as `name value`, each value whole or, when
|
|
10
30
|
* longer than VALUE_MAX, only as its size, and whole fields only until LINE_MAX. Nothing is ever cut inside a value:
|
|
@@ -37,15 +57,24 @@ export type LearnedWorkflowRun = {
|
|
|
37
57
|
complete?: Complete;
|
|
38
58
|
/** The run's gate's permission of a tool now (tool-gate.ts RunGate policy): a call node's tool set to ask or deny is
|
|
39
59
|
* refused before any node runs, and asked again as each call node runs, a composed workflow's inner ones too, so one
|
|
40
|
-
* set to either since the call began is refused there, never run.
|
|
41
|
-
|
|
60
|
+
* set to either since the call began is refused there, never run. Required: a learned workflow never runs a tool
|
|
61
|
+
* on a default of allow (#2153). */
|
|
62
|
+
policy: (tool: string) => string;
|
|
42
63
|
/** Where the gate's permission of a tool was set (tool-gate.ts RunGate denyFrom), so a refusal names it: this agent's
|
|
43
|
-
* settings or this server's.
|
|
44
|
-
denyFrom
|
|
64
|
+
* settings or this server's. */
|
|
65
|
+
denyFrom: (tool: string) => SettingFrom;
|
|
45
66
|
/** Reads the gate's settings again (a runner's are in its store, read anew at each of its gate's decisions), awaited as
|
|
46
67
|
* each call node runs, before `policy` is asked: a tool set to deny since the call began is then refused. None: the
|
|
47
68
|
* gate reads its settings live (main's process). */
|
|
48
69
|
refresh?: () => Promise<void>;
|
|
70
|
+
/** The run's MCP tools by catalog name (`mcp:<server>/<tool>`): those the claim's pin holds, which its revision grants.
|
|
71
|
+
* A call node may name one of these; it runs through the run's own MCP, as the loop wrapped it (host-calls.ts). */
|
|
72
|
+
mcpTools?: readonly string[];
|
|
73
|
+
/** The gate's whole decision of an MCP node's call with its arguments, as the run's own call of the tool gets it
|
|
74
|
+
* (RunGate.decide: deny, argument pins, ask, no approver). Required for an MCP node: one with none is never sent. */
|
|
75
|
+
decide?: (tool: string, args: unknown) => Promise<"allow" | "ask" | {
|
|
76
|
+
deny: string;
|
|
77
|
+
}>;
|
|
49
78
|
};
|
|
50
79
|
/** The most characters of a learned workflow's output its answer holds, monid's bound (monid.ts CLIP): within the
|
|
51
80
|
* host's result bound, which each CLI is told to pass whole (host-bounds.test). */
|
|
@@ -56,7 +85,10 @@ export declare function learnedText(text: string): string;
|
|
|
56
85
|
/** What a learned workflow's model node is refused with when it names a tool: it runs in a session of its own here.
|
|
57
86
|
* The check before the run refuses such a workflow first (draftProblems); this one holds should it not. */
|
|
58
87
|
export declare const NODE_TOOLS_REFUSED = "a learned workflow's model node runs without tools here";
|
|
59
|
-
/** The tool's description
|
|
88
|
+
/** The tool's description, sent with every model request of the run, so it holds what a model needs to call it right and
|
|
89
|
+
* no more: one line of what the tool does (one call, by name, a JSON input with the listed fields, `*` marking a required
|
|
90
|
+
* one; what it answers), then each workflow on a line of its own (workflowLine): its name, its input's fields and the
|
|
91
|
+
* line its README says what it does with. */
|
|
60
92
|
export declare const learnedWorkflowDescription: (workflows: readonly LearnedWorkflow[]) => string;
|
|
61
93
|
/** The run's `learned_workflow` tool over `run.workflows`. */
|
|
62
94
|
export declare function learnedWorkflowTool(run: LearnedWorkflowRun): ToolRegistration;
|
package/dist/learned-workflow.js
CHANGED
|
@@ -1,12 +1,60 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-durable";
|
|
2
|
-
import { registerLabel, registerOutcome } from "
|
|
2
|
+
import { registerLabel, registerOutcome } from "./timeline/index.js";
|
|
3
3
|
import { sideRequests } from "./cap.js";
|
|
4
4
|
import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
|
|
5
5
|
import { workflowLine } from "./learning.js";
|
|
6
6
|
import { ledgerOf } from "./paid-calls.js";
|
|
7
7
|
import { forModel } from "./result.js";
|
|
8
|
-
import { deniedText } from "./tool-gate.js";
|
|
9
|
-
import { allows, CALL_TOOLS, learnedDraftTools, toolOf } from "./tools.js";
|
|
8
|
+
import { ARGS_PREVIEW_BYTES, deniedText } from "./tool-gate.js";
|
|
9
|
+
import { allows, CALL_TOOLS, learnedDraftTools, toolOf, workflowTools } from "./tools.js";
|
|
10
|
+
import { hostCalls } from "./host-calls.js";
|
|
11
|
+
import { workflowNodes } from "./model.js";
|
|
12
|
+
/** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
|
|
13
|
+
export const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
|
|
14
|
+
/** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
|
|
15
|
+
* are the workflow's to decide, then every one of them by name. The card leads with these (the call's own input after
|
|
16
|
+
* them), so they are never cut behind a long input. */
|
|
17
|
+
export const learnedAskShown = (asks) => ({ mcp_arguments: LEARNED_MCP_ARGUMENTS, mcp_calls: [...asks] });
|
|
18
|
+
/** The most bytes of the card those fields may take: the card's preview is cut at ARGS_PREVIEW_BYTES (2 KB), and its
|
|
19
|
+
* braces and the call's name follow them. A workflow whose ask-gated MCP tools would not all show is refused, never
|
|
20
|
+
* approved by a person who could not see what they approved. */
|
|
21
|
+
export const LEARNED_ASK_CARD_BYTES = ARGS_PREVIEW_BYTES - 128;
|
|
22
|
+
/** Whether every MCP tool set to ask that the workflow can call fits on its card (learnedAskShown, LEARNED_ASK_CARD_BYTES). */
|
|
23
|
+
export const learnedAskFits = (asks) => Buffer.byteLength(JSON.stringify(learnedAskShown(asks)), "utf8") <= LEARNED_ASK_CARD_BYTES;
|
|
24
|
+
/** The MCP tools a person's approval of a learned_workflow call covers: exactly those its card named (learnedAskShown's
|
|
25
|
+
* `mcp_calls`, read from the card they approved, host-calls.ts HostCalls.approved). None when no person approved it,
|
|
26
|
+
* or the card named none. A tool set to ask that the card did not name (one set to ask after the card was shown) is
|
|
27
|
+
* never run under that approval. */
|
|
28
|
+
export const learnedApprovedTools = (card) => new Set(Array.isArray(card?.mcp_calls) ? card.mcp_calls.filter((name) => typeof name === "string") : []);
|
|
29
|
+
/** An MCP tool's catalog name, `mcp:<server>/<tool>`: a call node that names one runs it through the run's own MCP. */
|
|
30
|
+
const MCP_TOOL = /^mcp:[^/]+\/.+$/;
|
|
31
|
+
/** The MCP tools a learned workflow's call nodes name (`via: "tool"`, `tool: "mcp:<server>/<tool>"`), each once; none for
|
|
32
|
+
* one that does not read. The run's gate asks about them before the workflow's call runs (adapter-run-spec.ts). */
|
|
33
|
+
export async function learnedMcpTools(workflow) {
|
|
34
|
+
let doc;
|
|
35
|
+
try {
|
|
36
|
+
doc = JSON.parse(workflow);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
|
|
42
|
+
try {
|
|
43
|
+
return workflowTools(workflowNodes(doc, inspectWorkflow(doc))).calls.filter((tool) => MCP_TOOL.test(tool));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** A call node's MCP result as the workflow's value: its text as JSON when it parses, else `{ text }`. */
|
|
50
|
+
const mcpValue = (text) => {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(text);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return { text };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
10
58
|
export const LEARNED_WORKFLOW_TOOL = "learned_workflow";
|
|
11
59
|
/** The most of a learned workflow's output its result line shows, and the longest value it shows as written. */
|
|
12
60
|
const LINE_MAX = 120;
|
|
@@ -66,10 +114,12 @@ export function learnedText(text) {
|
|
|
66
114
|
/** What a learned workflow's model node is refused with when it names a tool: it runs in a session of its own here.
|
|
67
115
|
* The check before the run refuses such a workflow first (draftProblems); this one holds should it not. */
|
|
68
116
|
export const NODE_TOOLS_REFUSED = "a learned workflow's model node runs without tools here";
|
|
69
|
-
/** The tool's description
|
|
117
|
+
/** The tool's description, sent with every model request of the run, so it holds what a model needs to call it right and
|
|
118
|
+
* no more: one line of what the tool does (one call, by name, a JSON input with the listed fields, `*` marking a required
|
|
119
|
+
* one; what it answers), then each workflow on a line of its own (workflowLine): its name, its input's fields and the
|
|
120
|
+
* line its README says what it does with. */
|
|
70
121
|
export const learnedWorkflowDescription = (workflows) => [
|
|
71
|
-
"
|
|
72
|
-
"schema says. It answers the workflow's output as JSON, or why it did not run. The workflows:",
|
|
122
|
+
"Runs one of this agent's learned workflows in one call, by name, on a JSON input with the fields below (* required). Answers its output as JSON, or why it did not run.",
|
|
73
123
|
...workflows.map(workflowLine),
|
|
74
124
|
].join("\n");
|
|
75
125
|
/** One model request as a pi-ai event stream, sent through `models.completeSimple` as the run's own request, under its
|
|
@@ -109,8 +159,9 @@ export function learnedWorkflowTool(run) {
|
|
|
109
159
|
additionalProperties: false,
|
|
110
160
|
required: ["name", "input"],
|
|
111
161
|
properties: {
|
|
112
|
-
|
|
113
|
-
|
|
162
|
+
// No words of their own: the description says what each is, and the parameters go with every request too.
|
|
163
|
+
name: { type: "string", enum: names },
|
|
164
|
+
input: { type: "object" },
|
|
114
165
|
},
|
|
115
166
|
},
|
|
116
167
|
execute: async (args, api, context) => {
|
|
@@ -133,7 +184,24 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
133
184
|
// Checked again at the call, against the agent's own tools as its run has them, before any node runs: what merged under
|
|
134
185
|
// another revision may name one it has no more.
|
|
135
186
|
// The tools the gate allows now; one set to ask or deny is refused in the words a workflow revision's call node is.
|
|
136
|
-
|
|
187
|
+
// A run handed no gate (a caller past the types) runs nothing: a tool is never allowed for want of a policy.
|
|
188
|
+
if (typeof run.policy !== "function" || typeof run.denyFrom !== "function")
|
|
189
|
+
return refuse("its run gave no tool policy for its call nodes");
|
|
190
|
+
const { tools, gated, deniedBy } = learnedDraftTools(run.granted, run.policy, run.plane, run.denyFrom);
|
|
191
|
+
// The run's MCP tools, held to the same gate: one set to allow may be named, and one set to ask only when a person
|
|
192
|
+
// approved this call with a card that named it (its ask is the call's own: adapter-run-spec.ts adapterRunGate); one set
|
|
193
|
+
// to deny is refused in its words. One the run's pin does not hold is no tool of the run at all.
|
|
194
|
+
const approved = learnedApprovedTools(hostCalls()?.approved);
|
|
195
|
+
for (const name of run.mcpTools ?? []) {
|
|
196
|
+
const setting = run.policy(name);
|
|
197
|
+
if (setting === "allow" || (setting === "ask" && approved.has(name)))
|
|
198
|
+
tools.push(name);
|
|
199
|
+
else {
|
|
200
|
+
gated[name] = setting;
|
|
201
|
+
if (setting === "deny")
|
|
202
|
+
deniedBy[name] = run.denyFrom(name);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
137
205
|
const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy);
|
|
138
206
|
if (problems.length)
|
|
139
207
|
return refuse(problems.map(({ detail }) => detail).join("; "));
|
|
@@ -165,6 +233,32 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
165
233
|
};
|
|
166
234
|
const runEffect = async ({ node, input: given, signal: own, executionPath, item }) => {
|
|
167
235
|
const tool = node.via === "tool" ? node.tool : undefined;
|
|
236
|
+
// Its call id under the workflow's call: the node, its execution path, its item in a map. Its paid requests are booked
|
|
237
|
+
// under it, as a call of its own.
|
|
238
|
+
const callId = `${ledger?.call ?? LEARNED_WORKFLOW_TOOL}/${node.label}@${executionPath ?? ""}${item ? `#${item.index}` : ""}`;
|
|
239
|
+
if (tool && MCP_TOOL.test(tool)) {
|
|
240
|
+
// An MCP tool of the run, through the run's own MCP as the loop wrapped it (its flush, its booking on the run's one
|
|
241
|
+
// ledger, a CLI's record, the stop's abort), after the gate's rule read again now, as the harness's own call is.
|
|
242
|
+
const send = (run.mcpTools ?? []).includes(tool) && run.decide ? hostCalls()?.mcp(tool) : undefined;
|
|
243
|
+
if (!send || !run.decide)
|
|
244
|
+
throw new Error(`call node "${node.label}": this agent runs no tool ${tool}`);
|
|
245
|
+
// The gate's whole decision of this call with the arguments the workflow resolved, as the harness's own call of the
|
|
246
|
+
// tool gets it: its deny, its argument pins (a messaging tool held to one channel), its ask, or no one to approve.
|
|
247
|
+
// The call's approval lifts only an ask, never a pin or a deny, and only for a tool its card named: one set to ask
|
|
248
|
+
// since the card was shown was never approved.
|
|
249
|
+
await run.refresh?.();
|
|
250
|
+
const verdict = await run.decide(tool, given);
|
|
251
|
+
if (typeof verdict === "object")
|
|
252
|
+
throw new Error(verdict.deny);
|
|
253
|
+
const card = hostCalls()?.approved;
|
|
254
|
+
if (verdict === "ask" && !learnedApprovedTools(card).has(tool)) {
|
|
255
|
+
throw new Error(card ? `This ${tool} call needs a person's approval, and the approval given for this learned workflow did not cover it: its card did not name ${tool}. It was not run.` : `This ${tool} call needs a person's approval, which was not given for this call; it was not run.`);
|
|
256
|
+
}
|
|
257
|
+
const answer = await send(given, { callId, signal: own });
|
|
258
|
+
if (answer.isError)
|
|
259
|
+
throw new Error(answer.text);
|
|
260
|
+
return mcpValue(answer.text);
|
|
261
|
+
}
|
|
168
262
|
const effect = tool && allows(CALL_TOOLS, tool) && tools.includes(tool) ? toolOf(tool)?.effect : undefined;
|
|
169
263
|
if (!effect)
|
|
170
264
|
throw new Error(`call node "${node.label}": this agent runs no tool ${tool ?? `via ${node.via}`}`);
|
|
@@ -172,13 +266,13 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
172
266
|
// a tool set to deny since the call began is refused in the gate's words, one set to ask too, since a call node
|
|
173
267
|
// cannot wait for an approval. Neither runs.
|
|
174
268
|
await run.refresh?.();
|
|
175
|
-
const permission = run.policy
|
|
269
|
+
const permission = run.policy(tool);
|
|
176
270
|
if (permission === "deny")
|
|
177
|
-
throw new Error(deniedText(tool, undefined, run.denyFrom
|
|
271
|
+
throw new Error(deniedText(tool, undefined, run.denyFrom(tool)));
|
|
178
272
|
if (permission === "ask")
|
|
179
273
|
throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
|
|
180
274
|
// Its paid requests booked under the tool's call, as a call of its own: the node, its execution path, its item in a map.
|
|
181
|
-
const booked = ledger ? { ledger: { call:
|
|
275
|
+
const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
|
|
182
276
|
return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
|
|
183
277
|
};
|
|
184
278
|
try {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import { type Problem } from "./learn/index.js";
|
|
3
2
|
import { type ItemStatus, type Learning, type NoteRuns, type Shown } from "./learning.js";
|
|
4
3
|
import type { Impact } from "./learning-run.js";
|
|
5
|
-
import type {
|
|
4
|
+
import type { Store } from "./store/store.js";
|
|
6
5
|
type Page<T> = {
|
|
7
6
|
items: T[];
|
|
8
7
|
total: number;
|
|
@@ -149,47 +148,8 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
149
148
|
text: string;
|
|
150
149
|
etag: string;
|
|
151
150
|
}>;
|
|
152
|
-
/** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
|
|
153
|
-
* host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
|
|
154
|
-
export declare function runLearning(run: Run, shown: Shown, secrets: readonly string[], data: string): Promise<{
|
|
155
|
-
seed: string | null;
|
|
156
|
-
merged: string | null;
|
|
157
|
-
pending: {
|
|
158
|
-
file: string;
|
|
159
|
-
name: string;
|
|
160
|
-
}[];
|
|
161
|
-
verdict: {
|
|
162
|
-
merge: boolean;
|
|
163
|
-
reason: string;
|
|
164
|
-
items: {
|
|
165
|
-
why: string;
|
|
166
|
-
question?: string | undefined;
|
|
167
|
-
origin?: "run" | "you" | undefined;
|
|
168
|
-
pending?: boolean | undefined;
|
|
169
|
-
file: string;
|
|
170
|
-
keep: boolean;
|
|
171
|
-
}[];
|
|
172
|
-
} | null;
|
|
173
|
-
problems: Problem[];
|
|
174
|
-
cost_usd: {
|
|
175
|
-
grade: number | null;
|
|
176
|
-
};
|
|
177
|
-
tokens: {
|
|
178
|
-
grade: import("./learning.js").Tokens | null;
|
|
179
|
-
};
|
|
180
|
-
given?: import("./learning.js").NoteUsed[];
|
|
181
|
-
read?: import("./learning.js").NoteUsed[];
|
|
182
|
-
learned?: import("./learning.js").NoteLearned[];
|
|
183
|
-
skills?: import("./learning.js").LearnedFile[];
|
|
184
|
-
workflows?: import("./learning.js").LearnedFile[];
|
|
185
|
-
run: string;
|
|
186
|
-
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
187
|
-
reason: "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "cancelled" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
188
|
-
detail: string | null;
|
|
189
|
-
at: string;
|
|
190
|
-
} | null>;
|
|
191
151
|
/** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
|
|
192
|
-
* settled: the one shape, read from
|
|
152
|
+
* settled: the one shape, read from the one store (store-reads/learning.ts
|
|
193
153
|
* runLearningOverStore). */
|
|
194
154
|
export declare function runLearningBody(input: {
|
|
195
155
|
readonly id: string;
|
|
@@ -215,7 +175,11 @@ export declare function runLearningBody(input: {
|
|
|
215
175
|
keep: boolean;
|
|
216
176
|
}[];
|
|
217
177
|
} | null;
|
|
218
|
-
problems:
|
|
178
|
+
problems: {
|
|
179
|
+
detail: string;
|
|
180
|
+
path?: string | undefined;
|
|
181
|
+
rule: import("./learn/check.js").Rule;
|
|
182
|
+
}[];
|
|
219
183
|
cost_usd: {
|
|
220
184
|
grade: number | null;
|
|
221
185
|
};
|
|
@@ -229,15 +193,18 @@ export declare function runLearningBody(input: {
|
|
|
229
193
|
workflows?: import("./learning.js").LearnedFile[];
|
|
230
194
|
run: string;
|
|
231
195
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
232
|
-
reason: "empty" | "
|
|
196
|
+
reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
233
197
|
detail: string | null;
|
|
234
198
|
at: string;
|
|
235
199
|
};
|
|
236
|
-
/** GET /runs/{id}/learning/diff: once merged
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
|
|
200
|
+
/** GET /runs/{id}/learning/diff over the one store: once merged (its learning end, store-reads/learning.ts
|
|
201
|
+
* runLearningEnd), its merge commit against its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json` in
|
|
202
|
+
* its agent's learning folder); before, its kept proposal (new notes only, from its learning_proposals row) against its
|
|
203
|
+
* seed; a run that proposed nothing, no file, against the seed its launch's learning start names. A run that does not
|
|
204
|
+
* learn (no learning start and no learning end) is not_found. A file's patch is withheld when too large (as the script
|
|
205
|
+
* wrote it), or when it holds one of the host's secrets now (`shown`); any other is served as every learning text is
|
|
206
|
+
* (`shown.text`: a loopback address reads "a local address"). */
|
|
207
|
+
export declare function runDiffOverStore(data: string, store: Store, runId: string, shown: Shown): Promise<{
|
|
241
208
|
base: string;
|
|
242
209
|
head: string;
|
|
243
210
|
files: ({
|
package/dist/learning-routes.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
|
|
1
|
+
import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, frontMatter, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, statusOnOneLine, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
|
|
3
2
|
import { beforeRetire, blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
|
|
4
3
|
import { ApiError, invalid } from "./errors.js";
|
|
5
|
-
import {
|
|
6
|
-
import { currentLearning, holdsForOk, detailShown, learningFolderOf, notesView, PROPOSAL, readPin, secretsShown, withAgentRepo } from "./learning.js";
|
|
4
|
+
import { detailShown, learningFolderOf, notesView, reasonShown, secretsShown, withAgentRepo } from "./learning.js";
|
|
7
5
|
import { isObject } from "./validate.js";
|
|
6
|
+
import { launchOf } from "./handed-values.js";
|
|
7
|
+
import { learningStartOf } from "./run-launch.js";
|
|
8
|
+
import { runLearningEnd } from "./store-reads/learning.js";
|
|
8
9
|
/** The agent view's first pages, and the most a page holds. */
|
|
9
10
|
const NOTES_PAGE = 50;
|
|
10
11
|
const LOG_PAGE = 20;
|
|
@@ -353,10 +354,13 @@ export async function writeNote(data, agentId, raw, input) {
|
|
|
353
354
|
throw new ApiError("precondition_failed", "The folder has a note by this name: read it, then edit it with If-Match.");
|
|
354
355
|
// A note whose text holds one of the host's secrets as they are now (a value made secret after it was written) is
|
|
355
356
|
// read cut of it, under its own ETag: an edit of what was shown would write the cut over the hidden text. Only a
|
|
356
|
-
// retire reaches it.
|
|
357
|
+
// retire reaches it. So is one holding a loopback address, read as "a local address" (secretsShown).
|
|
357
358
|
if (given !== undefined && current && secretsShown(input.refuse).holds(current.text)) {
|
|
358
359
|
throw refused([{ rule: "secret_value", path: file, detail: "This note holds a value the server now keeps secret, so its text was shown with that value hidden, and saving would replace the hidden text. Retire it and write a new note instead." }]);
|
|
359
360
|
}
|
|
361
|
+
if (given !== undefined && current && secretsShown(input.refuse).text(current.text) !== current.text) {
|
|
362
|
+
throw refused([{ rule: "note", path: file, detail: "This note holds a local address, so its text was shown with it hidden, and saving would replace it. Retire it and write a new note instead." }]);
|
|
363
|
+
}
|
|
360
364
|
let text = given;
|
|
361
365
|
// A note that waits for its owner's OK is made active by an approval alone: an edit keeps it waiting, so one that
|
|
362
366
|
// drops or changes its status is refused, whoever sends it.
|
|
@@ -388,6 +392,10 @@ export async function writeNote(data, agentId, raw, input) {
|
|
|
388
392
|
const kind = learned.kind === "skill" ? "skill" : "workflow";
|
|
389
393
|
if (status !== "retired")
|
|
390
394
|
throw new ApiError("bad_request", `The ${kind} is not retired: it is ${status}.`);
|
|
395
|
+
// Read as retired since its front matter reads no way, or its status is set on more than one line, which no
|
|
396
|
+
// writer edits (learnedStatus): refused until it is written so it does.
|
|
397
|
+
if (!frontMatter(current.text) || !statusOnOneLine(current.text))
|
|
398
|
+
throw refused([printable({ rule: kind, path: file, detail: UNCLEAR_FRONT }, input.refuse)]);
|
|
391
399
|
text = released(current.text);
|
|
392
400
|
const problems = skillProblems(text, learned.name).map((detail) => printable({ rule: kind, path: file, detail }, input.refuse));
|
|
393
401
|
const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
|
|
@@ -495,24 +503,14 @@ export async function writeNote(data, agentId, raw, input) {
|
|
|
495
503
|
}
|
|
496
504
|
});
|
|
497
505
|
}
|
|
498
|
-
/** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
|
|
499
|
-
* host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
|
|
500
|
-
export async function runLearning(run, shown, secrets, data) {
|
|
501
|
-
// What it held for its owner's OK as it reads now (learning.ts currentLearning); its record stays as the merge wrote it.
|
|
502
|
-
const learning = holdsForOk(run.meta.learning) ? currentLearning(run.meta.learning, await statusesOf(data, run.agentId)) : run.meta.learning;
|
|
503
|
-
if (!learning)
|
|
504
|
-
return null;
|
|
505
|
-
const pin = await readPin(run.dir).catch(() => undefined);
|
|
506
|
-
return runLearningBody({ id: run.id, learning, seed: pin?.seed ?? null, settled: run.settled }, shown, secrets);
|
|
507
|
-
}
|
|
508
506
|
/** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
|
|
509
|
-
* settled: the one shape, read from
|
|
507
|
+
* settled: the one shape, read from the one store (store-reads/learning.ts
|
|
510
508
|
* runLearningOverStore). */
|
|
511
509
|
export function runLearningBody(input, shown, secrets) {
|
|
512
510
|
const { learning } = input;
|
|
513
511
|
const { state, reason, at, verdict, problems, merged, cost_usd, tokens, pending } = learning;
|
|
514
512
|
return {
|
|
515
|
-
run: input.id, state, reason, detail: detailShown(learning, shown), at,
|
|
513
|
+
run: input.id, state, reason: reasonShown(reason, shown), detail: detailShown(learning, shown), at,
|
|
516
514
|
// Once it settled (a run that runs again for a follow-up is still reading).
|
|
517
515
|
...notesView(learning, shown, input.settled),
|
|
518
516
|
seed: input.seed,
|
|
@@ -520,9 +518,10 @@ export function runLearningBody(input, shown, secrets) {
|
|
|
520
518
|
// The merge's notes that wait for a person's OK: on main as `status: pending`, read by no run until approved.
|
|
521
519
|
pending: (pending ?? []).map(({ file, name }) => ({ file: shown.name(file), name: shown.text(name) })),
|
|
522
520
|
// The grader's, with its item for each new note: a name holding one of the host's secrets reads [redacted], and
|
|
523
|
-
// each text is cut of them.
|
|
524
|
-
verdict: verdict ? { merge: verdict.merge, reason: shown.text(verdict.reason), items: (verdict.items ?? []).map(({ file, keep, pending: waits, origin, question, why }) => ({ file: shown.name(file), keep, ...(waits ? { pending: true } : {}), ...(origin ? { origin } : {}), ...(question ? { question: shown.text(question) } : {}), why: shown.text(why) })) } : null,
|
|
525
|
-
|
|
521
|
+
// each text is cut of them, its origin too (a kept row read back is untrusted).
|
|
522
|
+
verdict: verdict ? { merge: verdict.merge, reason: shown.text(verdict.reason), items: (verdict.items ?? []).map(({ file, keep, pending: waits, origin, question, why }) => ({ file: shown.name(file), keep, ...(waits ? { pending: true } : {}), ...(origin ? { origin: shown.text(origin) } : {}), ...(question ? { question: shown.text(question) } : {}), why: shown.text(why) })) } : null,
|
|
523
|
+
// Each cut of the host's secrets (printable), then as every served text is (`shown`: no loopback address).
|
|
524
|
+
problems: (problems ?? []).map((problem) => printable(problem, secrets)).map(({ rule, path, detail }) => ({ rule: shown.text(rule), ...(path === undefined ? {} : { path: shown.text(path) }), detail: shown.text(detail) })),
|
|
526
525
|
// The grade's alone: the end-of-run turn's cost is in the run's own totals.
|
|
527
526
|
cost_usd: { grade: cost_usd?.grade ?? null },
|
|
528
527
|
tokens: { grade: tokens?.grade ?? null },
|
|
@@ -537,28 +536,39 @@ function addedPatch(text) {
|
|
|
537
536
|
const added = [...lines.map((one) => `+${one}\n`), ...(last ? [`+${last}\n\\n`] : [])];
|
|
538
537
|
return `@@ -0,0 +1${added.length === 1 ? "" : `,${added.length}`} @@\n${added.join("")}`;
|
|
539
538
|
}
|
|
540
|
-
/** GET /runs/{id}/learning/diff: once merged
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
539
|
+
/** GET /runs/{id}/learning/diff over the one store: once merged (its learning end, store-reads/learning.ts
|
|
540
|
+
* runLearningEnd), its merge commit against its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json` in
|
|
541
|
+
* its agent's learning folder); before, its kept proposal (new notes only, from its learning_proposals row) against its
|
|
542
|
+
* seed; a run that proposed nothing, no file, against the seed its launch's learning start names. A run that does not
|
|
543
|
+
* learn (no learning start and no learning end) is not_found. A file's patch is withheld when too large (as the script
|
|
544
|
+
* wrote it), or when it holds one of the host's secrets now (`shown`); any other is served as every learning text is
|
|
545
|
+
* (`shown.text`: a loopback address reads "a local address"). */
|
|
546
|
+
export async function runDiffOverStore(data, store, runId, shown) {
|
|
547
|
+
const [end, kept, launch, row] = await Promise.all([runLearningEnd(store, runId), store.learning.proposal(runId), launchOf(store, runId), store.runs.get(runId)]);
|
|
548
|
+
const start = launch ? learningStartOf(launch) : undefined;
|
|
549
|
+
if (!row || (!end && !start))
|
|
547
550
|
throw new ApiError("not_found", "the run does not learn, so it proposed nothing");
|
|
548
551
|
const file = (name, status, patch) => {
|
|
549
552
|
const path = shown.name(name);
|
|
550
|
-
|
|
553
|
+
if (Buffer.byteLength(patch) > PATCH_CAP)
|
|
554
|
+
return { path, status, withheld: "too_large" };
|
|
555
|
+
if (shown.holds(patch))
|
|
556
|
+
return { path, status, withheld: "secret" };
|
|
557
|
+
const served = shown.text(patch);
|
|
558
|
+
return Buffer.byteLength(served) > PATCH_CAP ? { path, status, withheld: "too_large" } : { path, status, patch: served };
|
|
551
559
|
};
|
|
552
|
-
if (
|
|
553
|
-
const folder = learningFolderOf(data,
|
|
554
|
-
const diff = await readRunDiff(folder.workspace,
|
|
555
|
-
if (!diff || diff.merge !==
|
|
560
|
+
if (end?.merged) {
|
|
561
|
+
const folder = learningFolderOf(data, row.agentId);
|
|
562
|
+
const diff = await readRunDiff(folder.workspace, runId).catch((error) => Promise.reject(routeFailure(error))).finally(() => folder.end());
|
|
563
|
+
if (!diff || diff.merge !== end.merged)
|
|
556
564
|
throw new ApiError("not_found", "the run's merge is not in its agent's learning folder");
|
|
557
565
|
return { base: diff.parent, head: diff.merge, files: diff.files.map((entry) => ("patch" in entry ? file(entry.path, entry.status, entry.patch) : { path: shown.name(entry.path), status: entry.status, withheld: entry.withheld })) };
|
|
558
566
|
}
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
567
|
+
const kept_ = isObject(kept?.proposal) ? kept.proposal.proposal : undefined;
|
|
568
|
+
const proposal = isObject(kept_) && typeof kept_.seed === "string" && Array.isArray(kept_.notes) ? { seed: kept_.seed, notes: kept_.notes } : undefined;
|
|
569
|
+
if (proposal) {
|
|
570
|
+
const notes = proposal.notes.filter((note) => isObject(note) && typeof note.file === "string" && NOTE_FILE.test(note.file) && typeof note.text === "string");
|
|
562
571
|
return { base: proposal.seed, head: null, files: notes.map((note) => file(note.file, "added", addedPatch(note.text))) };
|
|
563
|
-
|
|
572
|
+
}
|
|
573
|
+
return { base: start?.seed ?? null, head: null, files: [] };
|
|
564
574
|
}
|