@parcha/agentrun-serve 0.1.0-beta.33 → 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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- 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 +1 -1
- package/dist/api-only.js +2 -2
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- 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 +92 -50
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- 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 +30 -2
- 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/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/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 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +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 +1 -7
- package/dist/harness-install.js +1 -18
- 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/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 +14 -15
- 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 +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- 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 +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- 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 +12 -14
- 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 +121 -47
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +25 -60
- 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 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- 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 +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- 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 +24 -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/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- 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 +133 -9
- 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 +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- 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/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 +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +16 -38
- package/dist/server.js +145 -106
- 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 +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- 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 +9 -2
- 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 +41 -12
- package/dist/store/store.d.ts +35 -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 +9 -6
- package/dist/store-reads/journal.js +93 -17
- 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 +53 -18
- 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 +5 -101
- package/dist/tool-keys.js +8 -267
- 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 +30 -18
- package/dist/tools.js +97 -107
- package/dist/trigger-adapter.d.ts +2 -2
- 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 +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- 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/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- 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 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- 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-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- 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/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- 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
package/dist/page.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export declare const sendHostRefused: (req: IncomingMessage, res: ServerResponse
|
|
|
21
21
|
/** `publicUrl`: the address people open (AGENTRUN_PUBLIC_URL); an https one adds HSTS to every page answer (hstsHeaders). */
|
|
22
22
|
type PageServer = {
|
|
23
23
|
token: string;
|
|
24
|
-
dir: string;
|
|
25
24
|
authFailed?: (route: string, reason: string) => void;
|
|
26
25
|
owner?: Owner;
|
|
27
26
|
console?: string | undefined;
|
|
@@ -34,8 +33,7 @@ export declare const byOwnerSession: (req: IncomingMessage) => boolean;
|
|
|
34
33
|
/** Whether `req` came from the accounts-off console's page session (answerPage). */
|
|
35
34
|
export declare const byConsoleSession: (req: IncomingMessage) => boolean;
|
|
36
35
|
/**
|
|
37
|
-
* Answers the console's paths ("/" and its /assets/*, and the addresses that moved to "/") and the
|
|
38
|
-
* returns true; returns false for every other path. On a /v2 path with no Authorization header, the browser's cookie
|
|
36
|
+
* Answers the console's paths ("/" and its /assets/*, and the addresses that moved to "/"), and returns true; returns false for every other path. On a /v2 path with no Authorization header, the browser's cookie
|
|
39
37
|
* becomes the Bearer header for a GET or HEAD, and for any other method only when the request's Origin is this server's
|
|
40
38
|
* own origin and its body is application/json, or the request is a PUT or POST to a route that takes bytes, with any
|
|
41
39
|
* content type.
|
package/dist/page.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// hashed assets under /assets/, public, under one strict CSP. The console signs a person in itself. With accounts it
|
|
3
3
|
// takes the owner's session cookie (owner.ts); without, the server's token as a cookie that the printed link (`/?token=`)
|
|
4
4
|
// sets once. Either stands in for the Bearer header on /v2, and for a write only from this origin with a JSON body, or
|
|
5
|
-
// with any body on a route that takes bytes (a PUT or POST marked `raw` in server.ts).
|
|
6
|
-
// store's read-only JSON (/api/*, pi-durable-agent's store page's data) answers the Bearer token or either cookie.
|
|
5
|
+
// with any body on a route that takes bytes (a PUT or POST marked `raw` in server.ts).
|
|
7
6
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
8
7
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
9
8
|
import { extname, join, sep } from "node:path";
|
|
10
9
|
import { fileURLToPath } from "node:url";
|
|
11
|
-
import { storeApi } from "@parcha/pi-durable-agent/serve";
|
|
12
10
|
import { ApiError } from "./errors.js";
|
|
13
11
|
import { hostRefusedPage } from "./host-check.js";
|
|
14
12
|
// img-src names Google's favicon service and the four hosts it redirects to: the console's Keys page shows a provider's
|
|
@@ -79,18 +77,9 @@ async function file(req, res, raw, dir, rel, status = 200) {
|
|
|
79
77
|
return missing();
|
|
80
78
|
send(req, res, status, type, await readFile(real), { "cache-control": rel.startsWith("assets/") ? "public, max-age=31536000, immutable" : "no-store" });
|
|
81
79
|
}
|
|
82
|
-
async function answer(req, res, raw, server
|
|
80
|
+
async function answer(req, res, raw, server) {
|
|
83
81
|
if (req.method !== "GET" && req.method !== "HEAD")
|
|
84
82
|
return refuse(req, res, new ApiError("method_not_allowed", `the console answers GET and HEAD; ${req.method} is not one`, {}, { allow: "GET, HEAD" }));
|
|
85
|
-
if (raw.startsWith("/api/")) {
|
|
86
|
-
if (!held && !same(String(req.headers.authorization ?? ""), `Bearer ${server.token}`)) {
|
|
87
|
-
server.authFailed?.(raw, req.headers.authorization === undefined ? "no_credential" : "wrong_token");
|
|
88
|
-
return refuse(req, res, new ApiError("unauthenticated", "the page's data needs the cookie the printed link sets, or Authorization: Bearer <the token>"));
|
|
89
|
-
}
|
|
90
|
-
const url = new URL(req.url ?? "/", "http://serve");
|
|
91
|
-
const { status, value } = await storeApi({ dir: server.dir })(url.pathname, url.searchParams);
|
|
92
|
-
return send(req, res, status, "application/json; charset=utf-8", JSON.stringify(value));
|
|
93
|
-
}
|
|
94
83
|
const dir = server.console ?? CONSOLE_DIR;
|
|
95
84
|
if (MOVED.has(raw))
|
|
96
85
|
return redirect(res, `/${(req.url ?? "").slice(raw.length)}`);
|
|
@@ -124,8 +113,7 @@ const consoleSessions = new WeakSet();
|
|
|
124
113
|
/** Whether `req` came from the accounts-off console's page session (answerPage). */
|
|
125
114
|
export const byConsoleSession = (req) => consoleSessions.has(req);
|
|
126
115
|
/**
|
|
127
|
-
* Answers the console's paths ("/" and its /assets/*, and the addresses that moved to "/") and the
|
|
128
|
-
* returns true; returns false for every other path. On a /v2 path with no Authorization header, the browser's cookie
|
|
116
|
+
* Answers the console's paths ("/" and its /assets/*, and the addresses that moved to "/"), and returns true; returns false for every other path. On a /v2 path with no Authorization header, the browser's cookie
|
|
129
117
|
* becomes the Bearer header for a GET or HEAD, and for any other method only when the request's Origin is this server's
|
|
130
118
|
* own origin and its body is application/json, or the request is a PUT or POST to a route that takes bytes, with any
|
|
131
119
|
* content type.
|
|
@@ -146,12 +134,12 @@ export function answerPage(req, res, raw, server) {
|
|
|
146
134
|
}
|
|
147
135
|
return false;
|
|
148
136
|
}
|
|
149
|
-
if (raw !== "/" && !raw.startsWith("/assets/") && !
|
|
137
|
+
if (raw !== "/" && !raw.startsWith("/assets/") && !MOVED.has(raw))
|
|
150
138
|
return false;
|
|
151
|
-
// Every page answer (the console, its assets, its redirects
|
|
139
|
+
// Every page answer (the console, its assets, its redirects) at an https public address: HSTS.
|
|
152
140
|
for (const [name, value] of Object.entries(hstsHeaders(server.publicUrl)))
|
|
153
141
|
res.setHeader(name, value);
|
|
154
|
-
answer(req, res, raw, server
|
|
142
|
+
answer(req, res, raw, server).catch(() => {
|
|
155
143
|
if (!res.headersSent)
|
|
156
144
|
refuse(req, res, new ApiError("internal", "the console could not be read"));
|
|
157
145
|
else
|
package/dist/paid-calls.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
3
3
|
import { type ToolExecutionApi, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
-
import { type SyncTarget } from "@parcha/pi-durable-disk";
|
|
5
4
|
/** Parallel's published prices (https://docs.parallel.ai/getting-started/pricing, read 2026-11-03): a `fast` search
|
|
6
5
|
* $1 per 1,000 requests for up to 10 results, each further result $1 per 1,000; an extract $1 per 1,000 URLs. */
|
|
7
6
|
export declare const PARALLEL_SEARCH_USD = 0.001;
|
|
@@ -55,37 +54,25 @@ export type PaidBooking = {
|
|
|
55
54
|
basis: string;
|
|
56
55
|
call?: string;
|
|
57
56
|
chargedBy?: string;
|
|
57
|
+
tool?: string;
|
|
58
|
+
tag?: string;
|
|
59
|
+
owed?: true;
|
|
60
|
+
hold?: true;
|
|
61
|
+
ref?: string;
|
|
58
62
|
}): Promise<unknown>;
|
|
59
63
|
/** `givenBack`: the hold let go unused, nothing sent (RunTools.settle). */
|
|
60
64
|
settle(id: string, usd: number | null, options?: {
|
|
61
65
|
readonly givenBack?: true;
|
|
62
66
|
}): Promise<unknown>;
|
|
63
67
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
export declare const noStoreToSync: (store: SyncTarget | undefined) => boolean;
|
|
68
|
-
/** A hold that could not be made durable (writeHold): nothing was sent. Its message says why, after "was not sent: ". */
|
|
69
|
-
export declare class HoldNotDurable extends Error {
|
|
70
|
-
readonly name = "HoldNotDurable";
|
|
71
|
-
}
|
|
72
|
-
/** The run's journal a hold is synced in (settleIn), for another barrier before a paid effect: browser-cost.ts'. */
|
|
73
|
-
export declare const runJournal: () => SyncTarget | undefined;
|
|
74
|
-
/** A paid call's hold (TOOL_STARTED, at what the cap holds it at), written by `write` (the call's own commit), then the
|
|
75
|
-
* run journal's barrier (pi-durable-disk barriers.ts, paidToolHold): the hold is on disk before the call is sent, so a
|
|
76
|
-
* box loss never leaves a sent call the cap does not count. Every paid call writes its hold here: a paid request
|
|
77
|
-
* (paidRequest), monid.run (monid.ts) and a priced MCP call (mcp-gateway.ts), so a new paid tool gets the sync with it.
|
|
78
|
-
* Whatever throws, the caller sends nothing (holdRefusal says why): with no store to sync it writes no hold
|
|
79
|
-
* (HoldNotDurable); a write that fails throws its own error; a sync that fails after the write settles the hold at $0
|
|
80
|
-
* under its call (best effort), so no cap counts a call that never left, and throws HoldNotDurable. */
|
|
68
|
+
/** A paid call's hold (TOOL_STARTED, at what the cap holds it at), written by `write` (the call's own commit) before the
|
|
69
|
+
* call is sent. Every paid call off the run's one ledger writes its hold here: a paid request (paidRequest) and
|
|
70
|
+
* monid.run (monid.ts). A write that fails throws its own error, and the caller sends nothing (holdRefusal says why). */
|
|
81
71
|
export declare function writeHold(write: (kind: string, data: Record<string, string | number | null>) => Promise<void>, data: Record<string, string | number | null>): Promise<void>;
|
|
82
|
-
/** What a paid call
|
|
72
|
+
/** What a paid call whose hold writeHold could not write tells the model: `name` was not sent, and why. */
|
|
83
73
|
export declare const holdRefusal: (name: string, error: unknown) => string;
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
export declare const settleOnRoot: (kind: string, data: Record<string, string | number | null>) => Promise<void> | undefined;
|
|
87
|
-
/** The ledger of a tool call: its id, and its commits to the run's store. Its mark (TOOL_STARTED) is the call's own
|
|
88
|
-
* commit, so a stopped turn sends nothing new; its settle goes to the run's root when that is set (settleIn). On the
|
|
74
|
+
/** The ledger of a tool call: its id, and its commits to the run's store. Its mark (TOOL_STARTED) and its settle are the
|
|
75
|
+
* call's own commits, so a stopped turn sends nothing new. On the
|
|
89
76
|
* runner the call runs inside the run's one ledger (the adapter loop's bookedIn, which carries the run's paid tool calls
|
|
90
77
|
* and its pause): its `paid` and `pause` are kept, so a paid request is admitted on the run's cap before it is sent and
|
|
91
78
|
* settled there, never booked beside it where the cap does not judge it. */
|
|
@@ -102,17 +89,24 @@ export declare function paidRequest(fee: Fee, send: () => Promise<Response>): Pr
|
|
|
102
89
|
/** The run's one ledger the current call books on (Ledger.paid), when it has one: the runner's. */
|
|
103
90
|
export declare const paidLedger: () => PaidBooking | undefined;
|
|
104
91
|
/** One paid step on the run's one ledger `paid`, under call `call`: admitted at `holdUsd` (refused unsent: the cap's words,
|
|
105
|
-
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold).
|
|
106
|
-
|
|
92
|
+
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold). One refused
|
|
93
|
+
* for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
|
|
94
|
+
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. */
|
|
95
|
+
export declare function paidStep<T>(paid: PaidBooking, call: string | undefined, fee: {
|
|
107
96
|
name: string;
|
|
108
97
|
holdUsd: number;
|
|
109
98
|
basis: string;
|
|
110
99
|
by: string;
|
|
100
|
+
tool?: string;
|
|
101
|
+
tag?: string;
|
|
102
|
+
owed?: true;
|
|
103
|
+
hold?: true;
|
|
104
|
+
ref?: string;
|
|
111
105
|
}, run: () => Promise<T>, chargeOf: (outcome: {
|
|
112
106
|
result: T;
|
|
113
107
|
} | {
|
|
114
108
|
thrown: unknown;
|
|
115
|
-
}) => number | null): Promise<{
|
|
109
|
+
}) => number | null, pause?: Ledger["pause"]): Promise<{
|
|
116
110
|
refused: string;
|
|
117
111
|
} | {
|
|
118
112
|
result: T;
|
package/dist/paid-calls.js
CHANGED
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
// tool books without the call passed down to it.
|
|
16
16
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
17
17
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
18
|
-
import { TOOL_COST, TOOL_STARTED } from "
|
|
19
|
-
import { BARRIER, JOURNAL_SYNCHRONOUS, syncNow } from "@parcha/pi-durable-disk";
|
|
18
|
+
import { TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
|
|
20
19
|
import { paidCall, SPEND_CAP_REACHED } from "./cap.js";
|
|
21
20
|
/** Parallel's published prices (https://docs.parallel.ai/getting-started/pricing, read 2026-11-03): a `fast` search
|
|
22
21
|
* $1 per 1,000 requests for up to 10 results, each further result $1 per 1,000; an extract $1 per 1,000 URLs. */
|
|
@@ -58,65 +57,24 @@ const roomOf = (error) => {
|
|
|
58
57
|
// Its code rides with it: the model request the pause refuses next is the cap's refusal (Refusal.code), never a failure.
|
|
59
58
|
return { refuse: String(given.message), code: SPEND_CAP_REACHED, forGood: false, figures: given.figures };
|
|
60
59
|
};
|
|
61
|
-
/** A paid step refused for room pauses the run, through the call's ledger
|
|
62
|
-
|
|
60
|
+
/** A paid step refused for room pauses the run, through `pause` (the call's ledger's, Ledger.pause, by default), before
|
|
61
|
+
* its refusal is told. */
|
|
62
|
+
const pauseOn = async (error, pause = ledgers.getStore()?.pause) => {
|
|
63
63
|
const room = roomOf(error);
|
|
64
|
-
const pause = ledgers.getStore()?.pause;
|
|
65
64
|
if (room && pause)
|
|
66
65
|
await pause(room);
|
|
67
66
|
};
|
|
68
67
|
const ledgers = new AsyncLocalStorage();
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* (
|
|
72
|
-
let rootRecord;
|
|
73
|
-
/** The run's store, for the barrier after each hold (writeHold): set with the root's commit, once the run is open. */
|
|
74
|
-
let holdStore;
|
|
75
|
-
/** The run journal's level: the store's own once one is open, this before (FULL syncs every commit, NORMAL only at a
|
|
76
|
-
* barrier). */
|
|
77
|
-
let journalLevel = JOURNAL_SYNCHRONOUS;
|
|
78
|
-
export const settleIn = (record, store, journal = JOURNAL_SYNCHRONOUS) => {
|
|
79
|
-
rootRecord = record;
|
|
80
|
-
holdStore = store;
|
|
81
|
-
// Only a test passes `journal`, to run the barriers at NORMAL before the run journal is NORMAL (pi-durable-disk 2b).
|
|
82
|
-
journalLevel = journal;
|
|
83
|
-
};
|
|
84
|
-
/** Whether a barrier on the run journal has nothing to sync: no store open, while the journal syncs only at barriers. A
|
|
85
|
-
* hold or a start mark written then would sit in the store with nothing to make it durable, so none is written. */
|
|
86
|
-
export const noStoreToSync = (store) => store === undefined && journalLevel !== "FULL";
|
|
87
|
-
/** A hold that could not be made durable (writeHold): nothing was sent. Its message says why, after "was not sent: ". */
|
|
88
|
-
export class HoldNotDurable extends Error {
|
|
89
|
-
name = "HoldNotDurable";
|
|
90
|
-
}
|
|
91
|
-
/** The run's journal a hold is synced in (settleIn), for another barrier before a paid effect: browser-cost.ts'. */
|
|
92
|
-
export const runJournal = () => holdStore;
|
|
93
|
-
/** A paid call's hold (TOOL_STARTED, at what the cap holds it at), written by `write` (the call's own commit), then the
|
|
94
|
-
* run journal's barrier (pi-durable-disk barriers.ts, paidToolHold): the hold is on disk before the call is sent, so a
|
|
95
|
-
* box loss never leaves a sent call the cap does not count. Every paid call writes its hold here: a paid request
|
|
96
|
-
* (paidRequest), monid.run (monid.ts) and a priced MCP call (mcp-gateway.ts), so a new paid tool gets the sync with it.
|
|
97
|
-
* Whatever throws, the caller sends nothing (holdRefusal says why): with no store to sync it writes no hold
|
|
98
|
-
* (HoldNotDurable); a write that fails throws its own error; a sync that fails after the write settles the hold at $0
|
|
99
|
-
* under its call (best effort), so no cap counts a call that never left, and throws HoldNotDurable. */
|
|
68
|
+
/** A paid call's hold (TOOL_STARTED, at what the cap holds it at), written by `write` (the call's own commit) before the
|
|
69
|
+
* call is sent. Every paid call off the run's one ledger writes its hold here: a paid request (paidRequest) and
|
|
70
|
+
* monid.run (monid.ts). A write that fails throws its own error, and the caller sends nothing (holdRefusal says why). */
|
|
100
71
|
export async function writeHold(write, data) {
|
|
101
|
-
if (noStoreToSync(holdStore))
|
|
102
|
-
throw new HoldNotDurable("the run's store is not open, so its hold cannot be made durable");
|
|
103
72
|
await write(TOOL_STARTED, data);
|
|
104
|
-
try {
|
|
105
|
-
await syncNow(holdStore, BARRIER.paidToolHold);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
const { heldUsd: _held, ...label } = data;
|
|
109
|
-
await write(TOOL_COST, { ...label, usd: 0 }).catch(() => undefined);
|
|
110
|
-
throw new HoldNotDurable(`its hold could not be made durable (${String(error?.message ?? error).slice(0, 200)})`);
|
|
111
|
-
}
|
|
112
73
|
}
|
|
113
|
-
/** What a paid call
|
|
114
|
-
export const holdRefusal = (name, error) =>
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
export const settleOnRoot = (kind, data) => rootRecord?.(kind, data);
|
|
118
|
-
/** The ledger of a tool call: its id, and its commits to the run's store. Its mark (TOOL_STARTED) is the call's own
|
|
119
|
-
* commit, so a stopped turn sends nothing new; its settle goes to the run's root when that is set (settleIn). On the
|
|
74
|
+
/** What a paid call whose hold writeHold could not write tells the model: `name` was not sent, and why. */
|
|
75
|
+
export const holdRefusal = (name, error) => `${name} was not sent: its mark could not be written (${String(error?.message ?? error).slice(0, 200)})`;
|
|
76
|
+
/** The ledger of a tool call: its id, and its commits to the run's store. Its mark (TOOL_STARTED) and its settle are the
|
|
77
|
+
* call's own commits, so a stopped turn sends nothing new. On the
|
|
120
78
|
* runner the call runs inside the run's one ledger (the adapter loop's bookedIn, which carries the run's paid tool calls
|
|
121
79
|
* and its pause): its `paid` and `pause` are kept, so a paid request is admitted on the run's cap before it is sent and
|
|
122
80
|
* settled there, never booked beside it where the cap does not judge it. */
|
|
@@ -124,7 +82,7 @@ export const ledgerOf = (api, context) => {
|
|
|
124
82
|
const outer = ledgers.getStore();
|
|
125
83
|
return {
|
|
126
84
|
call: api.callId,
|
|
127
|
-
record: (kind, data) =>
|
|
85
|
+
record: (kind, data) => api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind, data })), context),
|
|
128
86
|
...(outer?.paid ? { paid: outer.paid } : {}),
|
|
129
87
|
...(outer?.pause ? { pause: outer.pause } : {}),
|
|
130
88
|
};
|
|
@@ -182,16 +140,22 @@ let paidSeq = 0;
|
|
|
182
140
|
/** The run's one ledger the current call books on (Ledger.paid), when it has one: the runner's. */
|
|
183
141
|
export const paidLedger = () => ledgers.getStore()?.paid;
|
|
184
142
|
/** One paid step on the run's one ledger `paid`, under call `call`: admitted at `holdUsd` (refused unsent: the cap's words,
|
|
185
|
-
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold).
|
|
186
|
-
|
|
187
|
-
|
|
143
|
+
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold). One refused
|
|
144
|
+
* for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
|
|
145
|
+
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. */
|
|
146
|
+
export async function paidStep(paid, call, fee, run, chargeOf, pause) {
|
|
147
|
+
const id = `${call ?? fee.ref ?? fee.name}#${(paidSeq += 1)}`;
|
|
148
|
+
let admitted;
|
|
188
149
|
try {
|
|
189
|
-
await paid.admit({ id, name: fee.name, holdUsd: fee.holdUsd, basis: fee.basis, call, chargedBy: fee.by });
|
|
150
|
+
admitted = await paid.admit({ id, name: fee.name, holdUsd: fee.holdUsd, basis: fee.basis, ...(call === undefined ? {} : { call }), chargedBy: fee.by, ...(fee.tool ? { tool: fee.tool } : {}), ...(fee.tag ? { tag: fee.tag } : {}), ...(fee.owed ? { owed: true } : {}), ...(fee.hold ? { hold: true } : {}), ...(fee.ref === undefined ? {} : { ref: fee.ref }) });
|
|
190
151
|
}
|
|
191
152
|
catch (error) {
|
|
192
|
-
await pauseOn(error);
|
|
153
|
+
await pauseOn(error, pause);
|
|
193
154
|
return { refused: error?.code === "spend_cap_reached" ? String(error.message) : holdRefusal(fee.name, error) };
|
|
194
155
|
}
|
|
156
|
+
// Its ref booked already (by this claim or an earlier one): no step was opened, so nothing is settled.
|
|
157
|
+
if (admitted?.booked === true)
|
|
158
|
+
return { result: await run() };
|
|
195
159
|
let outcome;
|
|
196
160
|
try {
|
|
197
161
|
outcome = { result: await run() };
|
|
@@ -199,7 +163,8 @@ export async function paidStep(paid, call, fee, run, chargeOf) {
|
|
|
199
163
|
catch (thrown) {
|
|
200
164
|
outcome = { thrown };
|
|
201
165
|
}
|
|
202
|
-
|
|
166
|
+
// A hold-only step (`hold`) is given back, never a charge: its money is booked by its own charges' steps.
|
|
167
|
+
await (fee.hold ? paid.settle(id, 0, { givenBack: true }) : paid.settle(id, chargeOf(outcome))).catch(() => undefined);
|
|
203
168
|
if ("thrown" in outcome)
|
|
204
169
|
throw outcome.thrown;
|
|
205
170
|
return outcome;
|
package/dist/propose.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
// Learning, after a run: the notes its end-of-run turn answered with, and a skill or a workflow draft beside them, are read
|
|
2
2
|
// by the host (learn/reflect.ts parseReflection), checked against the commit the run started from (learn/check.ts
|
|
3
|
-
// checkProposal), and kept
|
|
4
|
-
// is
|
|
5
|
-
//
|
|
3
|
+
// checkProposal), and kept as its proposal (`learning-proposal.json`, in the directory the caller gives), or dropped. The
|
|
4
|
+
// answer is what the runner's end-of-run turn read from the run's store (runner/learning-end.ts), never the run's work;
|
|
5
|
+
// and no file the run wrote is read at all, in `.learning/` or anywhere. The seed is
|
|
6
6
|
// read from the agent's learning folder through its Workspace, as the reflect hook's check reads it (learn/seed-check.ts):
|
|
7
7
|
// the snapshot and its bodies when main is the seed (no exec), else one read-only exec of the learning script at that
|
|
8
8
|
// commit. Nothing is written to git here, and nothing is written at all before the checks pass: what they refuse (a
|
|
9
9
|
// note holding a secret among them) is never kept anywhere.
|
|
10
10
|
import { join } from "node:path";
|
|
11
|
-
import { checkProposal, draftFiles, unstorable, parseReflection, redactSecrets, shortMessage, SKILLS_DIR, WORKFLOWS_DIR } from "./learn/index.js";
|
|
11
|
+
import { checkProposal, draftDryRun, draftFiles, NOTE_BLOCK, unstorable, parseReflection, redactSecrets, shortMessage, SKILL_BLOCK, SKILLS_DIR, WORKFLOW_BLOCK, WORKFLOWS_DIR } from "./learn/index.js";
|
|
12
12
|
import { folderAt, readLearning, readSnapshot } from "./learn/folder.js";
|
|
13
13
|
import { baseOf } from "./learn/seed-check.js";
|
|
14
14
|
import { writeDurable } from "./files.js";
|
|
15
15
|
import { PROPOSAL } from "./learning.js";
|
|
16
|
-
/** The rules that refuse a proposal whole, whatever item they name:
|
|
17
|
-
*
|
|
18
|
-
* not see), which says the run's answer is not to be trusted for any item, and text that is
|
|
19
|
-
* read for one. Every other problem is its item's alone
|
|
20
|
-
|
|
16
|
+
/** The rules that refuse a proposal whole, whatever item they name: a path outside what a run may write, a deletion,
|
|
17
|
+
* the folder's index full (the notes' total, which no one item is past), anything that must never be stored (a secret,
|
|
18
|
+
* a character a reader does not see), which says the run's answer is not to be trusted for any item, and text that is
|
|
19
|
+
* not UTF-8, which cannot be read for one. Every other problem is its item's alone: a count cap names the items past it
|
|
20
|
+
* (learn/check.ts), a size cap the item over it, and they are left out and the rest kept; unstorable reads every item's
|
|
21
|
+
* text whole first. */
|
|
22
|
+
const WHOLE = new Set(["outside", "deleted", "index_full", "secret_value", "secret_shape", "invisible_unicode", "encoding"]);
|
|
21
23
|
/** The item a changed file belongs to: a draft's two files are one item (its folder), every other file is itself. */
|
|
22
24
|
const itemOf = (path) => (path.startsWith(`${WORKFLOWS_DIR}/`) ? path.split("/").slice(0, 2).join("/") : path);
|
|
23
25
|
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
@@ -82,14 +84,21 @@ async function seedAt(lw, seed, wanted) {
|
|
|
82
84
|
* `tools`, those a draft may name (tools.ts learnedWorkflowTools); `refuse`: this host's secrets. */
|
|
83
85
|
export const proposeRun = async (input) => {
|
|
84
86
|
const parsed = parseReflection(input.turn.answer);
|
|
85
|
-
// Each skill and draft as the folder would hold it
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
// Each skill and draft as the folder would hold it, keyed by its block (kind and name) so the changes keep the
|
|
88
|
+
// answer's order; a draft is its two files, given together or not at all. A draft's `example:` line, by its
|
|
89
|
+
// workflow.json's path: the input its dry run runs on, never a file's (draftFiles leaves it out of the README).
|
|
90
|
+
const fileGroups = new Map();
|
|
91
|
+
const examples = new Map();
|
|
92
|
+
const keyOf = (kind, name) => `${kind}\u0000${name}`;
|
|
93
|
+
for (const { name, text } of parsed.ok ? (parsed.skills ?? []) : [])
|
|
94
|
+
fileGroups.set(keyOf(SKILL_BLOCK, name), [{ file: `${SKILLS_DIR}/${name}/SKILL.md`, text }]);
|
|
95
|
+
for (const { name, text } of parsed.ok ? (parsed.workflows ?? []) : []) {
|
|
96
|
+
const { json, readme, example } = draftFiles(name, text);
|
|
97
|
+
if (example !== undefined)
|
|
98
|
+
examples.set(`${WORKFLOWS_DIR}/${name}/workflow.json`, example);
|
|
99
|
+
fileGroups.set(keyOf(WORKFLOW_BLOCK, name), [{ file: `${WORKFLOWS_DIR}/${name}/workflow.json`, text: json }, { file: `${WORKFLOWS_DIR}/${name}/README.md`, text: readme }]);
|
|
100
|
+
}
|
|
101
|
+
const given = [...fileGroups.values()];
|
|
93
102
|
// The seed is read whatever the answer: a seed the folder does not hold fails the check.
|
|
94
103
|
const { snapshot, texts } = await seedAt(input.folder, input.seed, () => (parsed.ok ? [...parsed.notes.map(({ file }) => file), ...given.flat().map(({ file }) => file)] : []));
|
|
95
104
|
if (!parsed.ok)
|
|
@@ -97,39 +106,72 @@ export const proposeRun = async (input) => {
|
|
|
97
106
|
const { base, kept } = baseOf(snapshot);
|
|
98
107
|
const held = new Set(base.files);
|
|
99
108
|
const files = given.filter((group) => group.some(({ file, text }) => texts.get(file) !== text)).flat();
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
];
|
|
109
|
+
const changeOf = ({ file, text }) => ({ path: file, status: held.has(file) ? "modified" : "added", mode: "100644", bytes: Buffer.from(text) });
|
|
110
|
+
// Each changed item in the order the answer gave its block, whatever its kind: a count cap names the items past it in
|
|
111
|
+
// that order (learn/check.ts), so a skill the answer led with is never the one past the changed-path cap.
|
|
112
|
+
const noteTexts = new Map(parsed.notes.map(({ file, text }) => [file, text]));
|
|
113
|
+
const changed = new Set(files.map(({ file }) => file));
|
|
114
|
+
const changes = parsed.order.flatMap(({ kind, name }) => {
|
|
115
|
+
if (kind === NOTE_BLOCK) {
|
|
116
|
+
const text = noteTexts.get(name);
|
|
117
|
+
return texts.get(name) !== text ? [changeOf({ file: name, text })] : [];
|
|
118
|
+
}
|
|
119
|
+
return (fileGroups.get(keyOf(kind, name)) ?? []).filter(({ file }) => changed.has(file)).map(changeOf);
|
|
120
|
+
});
|
|
104
121
|
// The workflow DSL reads a draft, and is loaded only when there is one to read.
|
|
105
122
|
const dsl = files.some(({ file }) => file.endsWith("/workflow.json")) ? await import("@parcha/agentrun-dsl") : undefined;
|
|
123
|
+
// A draft's example: the run's own input, so read as every text the run gave is, for what must never be stored (a
|
|
124
|
+
// held secret, a secret's shape): one that holds any refuses the whole answer, said at the draft's README, though it
|
|
125
|
+
// is never written there.
|
|
126
|
+
const exampled = files.filter(({ file }) => examples.has(file)).map(({ file }) => ({ path: file.replace(/workflow\.json$/, "README.md"), status: "added", mode: "100644", bytes: Buffer.from(examples.get(file)) }));
|
|
127
|
+
const leaky = unstorable(exampled, input.refuse);
|
|
128
|
+
if (leaky.length)
|
|
129
|
+
return { state: "dropped", reason: "checker", problems: leaky };
|
|
106
130
|
// A skill or a draft whose seed text has a status is a person's call (retired, or waiting for their OK): never changed.
|
|
107
|
-
const
|
|
131
|
+
const dryRuns = {};
|
|
132
|
+
const check = (some) => checkProposal({ base, changes: some, refuseValues: input.refuse, ...(kept.length ? { kept } : {}), ...(input.outcome === undefined ? {} : { outcome: input.outcome }), ...(input.tools ? { tools: input.tools } : {}), ...(input.gated ? { gated: input.gated } : {}), ...(input.deniedBy ? { deniedBy: input.deniedBy } : {}), ...(dsl ? { dsl, dryRuns } : {}) });
|
|
133
|
+
// The static checks first, every one (validateWorkflow with executeCode: false, draftProblems' refusal of code nodes,
|
|
134
|
+
// caps, secrets): a draft they refuse is never dry-run, nor is any when they refuse the answer whole. Then each draft
|
|
135
|
+
// left is dry-run on its example, else on a synthesized input (learn/skills.ts draftDryRun): every model and tool
|
|
136
|
+
// answer synthesized, nothing sent, paid or run, and no code it holds run in this process.
|
|
137
|
+
if (dsl) {
|
|
138
|
+
const statics = check(changes).problems;
|
|
139
|
+
const whole = statics.some((problem) => WHOLE.has(problem.rule) || problem.path === undefined);
|
|
140
|
+
const refused = new Set(statics.flatMap((problem) => (problem.path === undefined ? [] : [itemOf(problem.path)])));
|
|
141
|
+
if (!whole)
|
|
142
|
+
for (const { file, text } of files)
|
|
143
|
+
if (file.endsWith("/workflow.json") && !refused.has(itemOf(file)))
|
|
144
|
+
dryRuns[file] = await draftDryRun(dsl, text, examples.get(file));
|
|
145
|
+
}
|
|
108
146
|
// A verdict per item from the checks too: the items a problem names are left out (a draft's two files together),
|
|
109
|
-
// and the rest is checked again; a problem that names no item, or one that refuses the whole (WHOLE),
|
|
110
|
-
// as does a rest
|
|
147
|
+
// and the rest is checked again, until it passes; a problem that names no item, or one that refuses the whole (WHOLE),
|
|
148
|
+
// drops it all, as does a rest with nothing left. A later pass can name what an earlier one did not reach (the
|
|
149
|
+
// supersedes count, asked only of a rest with no other problem); each pass leaves out at least one item, so it ends.
|
|
111
150
|
let checked = check(changes);
|
|
112
151
|
let left = [];
|
|
113
|
-
|
|
152
|
+
const out = new Set();
|
|
114
153
|
if (checked.problems.length) {
|
|
115
154
|
const named = new Set(changes.map(({ path }) => itemOf(path)));
|
|
116
|
-
if (checked.problems.some((problem) => WHOLE.has(problem.rule) || problem.path === undefined || !named.has(itemOf(problem.path))))
|
|
117
|
-
return { state: "dropped", reason: "checker", problems: checked.problems };
|
|
118
155
|
// Before any item is kept from an answer the checks refuse: every name and text it gave, read whole. Something
|
|
119
156
|
// that must never be stored anywhere in it (in an item the checks refused unread, too) refuses it all.
|
|
120
157
|
const never = unstorable(changes, input.refuse);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
158
|
+
for (;;) {
|
|
159
|
+
if (checked.problems.some((problem) => WHOLE.has(problem.rule) || problem.path === undefined || !named.has(itemOf(problem.path))))
|
|
160
|
+
return { state: "dropped", reason: "checker", problems: [...left, ...checked.problems] };
|
|
161
|
+
if (never.length)
|
|
162
|
+
return { state: "dropped", reason: "checker", problems: [...left, ...checked.problems, ...never] };
|
|
163
|
+
left = [...left, ...checked.problems];
|
|
164
|
+
for (const problem of checked.problems)
|
|
165
|
+
out.add(itemOf(problem.path));
|
|
166
|
+
const rest = changes.filter(({ path }) => !out.has(itemOf(path)));
|
|
167
|
+
if (!rest.length)
|
|
168
|
+
return { state: "dropped", reason: "checker", problems: left };
|
|
169
|
+
checked = check(rest);
|
|
170
|
+
if (!checked.problems.length)
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
132
173
|
}
|
|
174
|
+
const passing = files.filter(({ file }) => !out.has(itemOf(file)));
|
|
133
175
|
if (!checked.notes.length && !passing.length)
|
|
134
176
|
return { state: "dropped", reason: "empty" };
|
|
135
177
|
// Each message cut of the host's secrets whole first, and only then shortened: a secret the cut fell inside would
|
|
@@ -138,7 +180,9 @@ export const proposeRun = async (input) => {
|
|
|
138
180
|
const asked = input.turn.asked.map((message) => shortMessage(redactSecrets(message, input.refuse, Number.POSITIVE_INFINITY)));
|
|
139
181
|
// A trigger's input, apart from what the user said, cut and shortened the same way.
|
|
140
182
|
const triggered = (input.turn.triggered ?? []).map(({ source, text }) => ({ source, text: shortMessage(redactSecrets(text, input.refuse, Number.POSITIVE_INFINITY)) }));
|
|
141
|
-
|
|
183
|
+
// How each kept draft's dry run went, for the grader: passed, or not run and why.
|
|
184
|
+
const ran = Object.fromEntries(passing.filter(({ file }) => dryRuns[file]).map(({ file }) => [file, dryRuns[file]]));
|
|
185
|
+
const proposal = { seed: input.seed, notes: checked.notes.map(({ file, text }) => ({ file, text })), ...(passing.length ? { files: passing } : {}), ...(Object.keys(ran).length ? { dryRuns: ran } : {}), asked, ...(triggered.length ? { triggered } : {}) };
|
|
142
186
|
await writeDurable(join(input.runDir, PROPOSAL), `${JSON.stringify(proposal)}\n`);
|
|
143
187
|
const count = (suffix) => passing.filter(({ file }) => file.endsWith(suffix)).length;
|
|
144
188
|
return { state: "proposed", notes: proposal.notes.length, skills: count("/SKILL.md"), workflows: count("/workflow.json"), ...(left.length ? { left } : {}) };
|
package/dist/push-handler.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type PushDeps = {
|
|
|
37
37
|
status: number;
|
|
38
38
|
body: Record<string, unknown>;
|
|
39
39
|
} | undefined>;
|
|
40
|
-
/** A source's sealed setting (sealed-settings.ts): its key, for a scope. */
|
|
40
|
+
/** A source's sealed setting (sealed-settings-store.ts): its key, for a scope. */
|
|
41
41
|
setting(adapterId: string, scope: string, field: string): string | undefined;
|
|
42
42
|
/** A refusal, said: its route and why. */
|
|
43
43
|
refused(route: string, reason: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TimelineEvent } from "./timeline/index.js";
|
|
2
|
+
import type { Status } from "./run-view.js";
|
|
3
|
+
/** A run's end-of-run turn: the job's outcome, the newest store entry before the turn and, once the run ended, the newest
|
|
4
|
+
* after it (its rows are those between), its deadline, and how it ended. */
|
|
5
|
+
export type Reflect = {
|
|
6
|
+
outcome: Status;
|
|
7
|
+
after: number;
|
|
8
|
+
until?: number;
|
|
9
|
+
deadline: string;
|
|
10
|
+
ended?: true;
|
|
11
|
+
timedOut?: true;
|
|
12
|
+
};
|
|
13
|
+
/** The run asked its end-of-run turn and has not ended since. */
|
|
14
|
+
export declare const reflecting: (run: {
|
|
15
|
+
meta: {
|
|
16
|
+
reflect?: Reflect;
|
|
17
|
+
};
|
|
18
|
+
}) => boolean;
|
|
19
|
+
/** Whether entry `id` (a number), or the row `id`, is the end-of-run turn's. Before the run has ended every later entry
|
|
20
|
+
* is, and so is a live row. */
|
|
21
|
+
export declare function reflects(reflect: Reflect | undefined, id: string | number): boolean;
|
|
22
|
+
/** `rows` with the end-of-run turn's labelled: never the run's answer (meaningful skips the label), its answer shown as
|
|
23
|
+
* a text row, and its message as the host's, in a person's words (learning-words.ts): what the model is asked stays in
|
|
24
|
+
* the run's store, and no row shows it. */
|
|
25
|
+
export declare function labelled(reflect: Reflect | undefined, rows: TimelineEvent[]): TimelineEvent[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LEARNING_LABEL } from "./learning.js";
|
|
2
|
+
import { said } from "./learning-words.js";
|
|
3
|
+
import { askedForDryRun } from "./learn/reflect.js";
|
|
4
|
+
/** The run asked its end-of-run turn and has not ended since. */
|
|
5
|
+
export const reflecting = (run) => run.meta.reflect !== undefined && run.meta.reflect.until === undefined;
|
|
6
|
+
/** A row's store entry, from its id (`<conversation>:<entry>[:...]`); NaN for a row no entry made (a live one, usage). */
|
|
7
|
+
const entryOf = (id) => Number(id.split(":")[1]);
|
|
8
|
+
/** Whether entry `id` (a number), or the row `id`, is the end-of-run turn's. Before the run has ended every later entry
|
|
9
|
+
* is, and so is a live row. */
|
|
10
|
+
export function reflects(reflect, id) {
|
|
11
|
+
if (!reflect)
|
|
12
|
+
return false;
|
|
13
|
+
const entry = typeof id === "number" ? id : entryOf(id);
|
|
14
|
+
if (Number.isInteger(entry))
|
|
15
|
+
return entry > reflect.after && (reflect.until === undefined || entry <= reflect.until);
|
|
16
|
+
return reflect.until === undefined && typeof id === "string" && id.includes(":live:");
|
|
17
|
+
}
|
|
18
|
+
/** `rows` with the end-of-run turn's labelled: never the run's answer (meaningful skips the label), its answer shown as
|
|
19
|
+
* a text row, and its message as the host's, in a person's words (learning-words.ts): what the model is asked stays in
|
|
20
|
+
* the run's store, and no row shows it. */
|
|
21
|
+
export function labelled(reflect, rows) {
|
|
22
|
+
if (!reflect)
|
|
23
|
+
return rows;
|
|
24
|
+
return rows.map((row) => (!reflects(reflect, row.id) ? row : {
|
|
25
|
+
...row, agent_label: LEARNING_LABEL,
|
|
26
|
+
...(row.kind === "final_answer" ? { kind: "text_block" } : {}),
|
|
27
|
+
// The turn asked again for a draft whose dry run failed says so; every other message of the turn is its ask.
|
|
28
|
+
...(row.kind === "user_message" ? (askedForDryRun(row.text) ? { summary: said.askedDryRun, text: said.askedDryRun } : { summary: said.asked, text: said.asked }) : {}),
|
|
29
|
+
}));
|
|
30
|
+
}
|
package/dist/refusal-words.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export declare const NOT_RUN = "It was not run: nothing was sent and nothing was
|
|
|
3
3
|
/** What a refusal says instead when an earlier attempt of the call may have been sent: an approved call cut mid-flight,
|
|
4
4
|
* or a replay-safe call the kernel runs again after a crash. Never a claim that nothing was charged. */
|
|
5
5
|
export declare const RAN_UNKNOWN = "It had started before the deny, and whether it took effect is not known.";
|
|
6
|
+
/** A call that waited for approval when its run was stopped: withdrawn, never sent (its row's words, and its end's). */
|
|
7
|
+
export declare const STOPPED_WHILE_WAITING = "Not run: the run was stopped while it waited";
|
|
8
|
+
/** A call that waited when its run ended (completed or failed) without anyone stopping it: never sent. */
|
|
9
|
+
export declare const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
|
|
6
10
|
/** Where a permission was set (permissionFrom's `from`): the agent's own tool settings, the server's, or the default; or
|
|
7
11
|
* "unattended": an ask the agent's approvals "never" allowed. */
|
|
8
12
|
export type SettingFrom = "agent" | "server" | "default" | "unattended";
|
|
@@ -15,7 +19,7 @@ export declare const denyPlace: (from?: SettingFrom) => string;
|
|
|
15
19
|
export declare const deniedText: (tool: string, heldTo?: string, from?: SettingFrom, ran?: "no" | "unknown") => string;
|
|
16
20
|
/** A workflow model node's tool set to ask: a model node cannot wait for a person's approval (the gate parks no workflow
|
|
17
21
|
* call), so the call is refused unrun and the model reads why (tool-gate.ts RunGate, on main and on the runner). */
|
|
18
|
-
export declare const modelNodeAskText: (tool: string) => string;
|
|
22
|
+
export declare const modelNodeAskText: (tool: string, ran?: "no" | "unknown") => string;
|
|
19
23
|
/** A workflow call node's tool set to ask: a call node cannot wait for a person's approval, so it is refused unrun
|
|
20
24
|
* (main's per-run process and the runner's workflow spec, the same words). */
|
|
21
25
|
export declare const callNodeAskText: (tool: string) => string;
|
package/dist/refusal-words.js
CHANGED
|
@@ -5,6 +5,10 @@ export const NOT_RUN = "It was not run: nothing was sent and nothing was charged
|
|
|
5
5
|
/** What a refusal says instead when an earlier attempt of the call may have been sent: an approved call cut mid-flight,
|
|
6
6
|
* or a replay-safe call the kernel runs again after a crash. Never a claim that nothing was charged. */
|
|
7
7
|
export const RAN_UNKNOWN = "It had started before the deny, and whether it took effect is not known.";
|
|
8
|
+
/** A call that waited for approval when its run was stopped: withdrawn, never sent (its row's words, and its end's). */
|
|
9
|
+
export const STOPPED_WHILE_WAITING = "Not run: the run was stopped while it waited";
|
|
10
|
+
/** A call that waited when its run ended (completed or failed) without anyone stopping it: never sent. */
|
|
11
|
+
export const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
|
|
8
12
|
/** Where a deny was set, in words: the place a person changes it. */
|
|
9
13
|
export const denyPlace = (from = "server") => (from === "agent" ? "for this agent" : from === "default" ? "by default" : "on this server");
|
|
10
14
|
/** The refusal of a call whose tool is set to deny; of one held to another tool's setting (`heldTo`, a shell tool's
|
|
@@ -17,7 +21,7 @@ export const deniedText = (tool, heldTo, from = "server", ran = "no") => {
|
|
|
17
21
|
};
|
|
18
22
|
/** A workflow model node's tool set to ask: a model node cannot wait for a person's approval (the gate parks no workflow
|
|
19
23
|
* call), so the call is refused unrun and the model reads why (tool-gate.ts RunGate, on main and on the runner). */
|
|
20
|
-
export const modelNodeAskText = (tool) => `This ${tool} call needs a person's approval, which a workflow's model node cannot wait for; it was not run
|
|
24
|
+
export const modelNodeAskText = (tool, ran = "no") => `This ${tool} call needs a person's approval, which a workflow's model node cannot wait for; ${ran === "no" ? "it was not run." : `it was not run again. ${RAN_UNKNOWN}`}`;
|
|
21
25
|
/** A workflow call node's tool set to ask: a call node cannot wait for a person's approval, so it is refused unrun
|
|
22
26
|
* (main's per-run process and the runner's workflow spec, the same words). */
|
|
23
27
|
export const callNodeAskText = (tool) => `This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`;
|
package/dist/rows.d.ts
CHANGED