@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36
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 +128 -0
- package/README.md +260 -168
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +13 -41
- package/dist/cap.js +24 -73
- package/dist/cli.js +4 -22
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +48 -7
- package/dist/computers.js +100 -23
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +7 -1
- package/dist/learn/check.js +123 -5
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +33 -0
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +86 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +43 -29
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +7 -0
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +19 -9
- package/dist/learned-workflow.js +62 -34
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +8 -3
- package/dist/learning-routes.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -6
- package/dist/learning.js +4 -2
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +5 -5
- package/dist/model.js +6 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +204 -47
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +1 -0
- package/dist/propose.js +25 -10
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +14 -1
- package/dist/run-launch.js +7 -2
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +5 -2
- package/dist/run-view.js +4 -3
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +16 -1
- package/dist/runner/adapter-loop.js +131 -30
- package/dist/runner/adapter-run-spec.d.ts +25 -4
- package/dist/runner/adapter-run-spec.js +103 -24
- package/dist/runner/adapters/pi.d.ts +11 -3
- package/dist/runner/adapters/pi.js +35 -12
- package/dist/runner/beside.js +6 -2
- package/dist/runner/cli-run-spec.d.ts +7 -0
- package/dist/runner/cli-run-spec.js +92 -38
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +8 -5
- package/dist/runner/github-app.js +2 -2
- package/dist/runner/harness-loops.js +1 -1
- package/dist/runner/journal-kinds.d.ts +15 -5
- package/dist/runner/journal-kinds.js +6 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +26 -5
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +73 -1
- package/dist/runner/learning-loop.js +203 -18
- package/dist/runner/learning-seed.d.ts +2 -0
- package/dist/runner/learning-seed.js +1 -1
- package/dist/runner/loop-contract.d.ts +8 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.js +12 -2
- package/dist/runner/mcp-claim.d.ts +4 -0
- package/dist/runner/mcp-claim.js +29 -1
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +0 -7
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +47 -12
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +18 -2
- package/dist/runner/workflow-host.js +23 -3
- package/dist/runner/workflow-loop.d.ts +5 -2
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +26 -14
- package/dist/runner/workflow-spec.js +97 -30
- package/dist/runs-over-store.d.ts +11 -6
- package/dist/runs-over-store.js +111 -24
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server.d.ts +32 -49
- package/dist/server.js +249 -199
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/deadline.js +9 -5
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +45 -12
- package/dist/store-reads/learning.d.ts +15 -1
- package/dist/store-reads/learning.js +68 -10
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.js +45 -19
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +3 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +8 -0
- package/dist/tool-budget.js +7 -1
- package/dist/tool-gate.d.ts +7 -1
- package/dist/tool-gate.js +7 -2
- package/dist/tool-plane.d.ts +33 -19
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +18 -34
- package/dist/tools.js +104 -70
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +30 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/computer-deps.d.ts +16 -8
- package/dist/workspace/computer-deps.js +18 -7
- package/dist/workspace/computer-for-claim.d.ts +42 -6
- package/dist/workspace/computer-for-claim.js +209 -9
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +7 -0
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +1 -0
- package/dist/workspace/resolve-computer.d.ts +42 -11
- package/dist/workspace/resolve-computer.js +65 -13
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +4 -4
- package/dist/workspace/run-tools.js +8 -6
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +10 -15
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
package/dist/triggers.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type TriggerFailed = {
|
|
|
55
55
|
};
|
|
56
56
|
auto_paused: boolean;
|
|
57
57
|
};
|
|
58
|
-
/** A run's provenance, kept
|
|
58
|
+
/** A run's provenance, kept with its launch row: the trigger that started it, and the firing. `name`: the trigger's name as
|
|
59
59
|
* it was at the firing, put on the run so its Timeline row names the trigger without a store read (runs.ts
|
|
60
60
|
* servedTriggerRow); a rename pushes the new name (server.ts triggerChanged). */
|
|
61
61
|
export type RunTrigger = {
|
|
@@ -454,10 +454,10 @@ export declare class Triggers {
|
|
|
454
454
|
* check. */
|
|
455
455
|
private given;
|
|
456
456
|
/** A run's title, from the trigger that starts it: "<its source> <its name>" (the word its Timeline row begins with,
|
|
457
|
-
*
|
|
457
|
+
* TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
|
|
458
458
|
* pull_request opened"); never its input, which may be a sender's markup. */
|
|
459
459
|
private titleOf;
|
|
460
|
-
/** Who a firing's input is from (
|
|
460
|
+
/** Who a firing's input is from (a MessageOrigin): the trigger, by its definition as it fires, never
|
|
461
461
|
* by its payload. Only a source whose words are its owner's (a schedule's, fired on time or by hand) gives owner true;
|
|
462
462
|
* a pushed source's come from outside, its body empty or not. */
|
|
463
463
|
private originOf;
|
package/dist/triggers.js
CHANGED
|
@@ -913,7 +913,7 @@ export class Triggers {
|
|
|
913
913
|
return { ...target, input: this.inputOf(trigger, { by: "manual", nominalAt: now, payload: null }) };
|
|
914
914
|
}
|
|
915
915
|
/** A run's title, from the trigger that starts it: "<its source> <its name>" (the word its Timeline row begins with,
|
|
916
|
-
*
|
|
916
|
+
* TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
|
|
917
917
|
* pull_request opened"); never its input, which may be a sender's markup. */
|
|
918
918
|
titleOf(trigger, firing) {
|
|
919
919
|
const source = TRIGGER_LABELS[trigger.source.kind] ?? trigger.source.kind;
|
|
@@ -922,7 +922,7 @@ export class Triggers {
|
|
|
922
922
|
const action = attrs?.action;
|
|
923
923
|
return `${source} ${trigger.name}${event ? `: ${event}${action ? ` ${action}` : ""}` : ""}`;
|
|
924
924
|
}
|
|
925
|
-
/** Who a firing's input is from (
|
|
925
|
+
/** Who a firing's input is from (a MessageOrigin): the trigger, by its definition as it fires, never
|
|
926
926
|
* by its payload. Only a source whose words are its owner's (a schedule's, fired on time or by hand) gives owner true;
|
|
927
927
|
* a pushed source's come from outside, its body empty or not. */
|
|
928
928
|
originOf(trigger) {
|
package/dist/turn-end.d.ts
CHANGED
|
@@ -7,9 +7,6 @@ export { TURN_END } from "./timeline/index.js";
|
|
|
7
7
|
* for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
|
|
8
8
|
export declare const MESSAGE = "adapter.message";
|
|
9
9
|
export declare const MESSAGE_END = "adapter.message_end";
|
|
10
|
-
/** The root's marker of a paid request already written as a pi.assistant entry (`{ key, request, unpriced? }`, in the
|
|
11
|
-
* entry's commit): `unpriced` when its cost was not in yet, which a REQUEST_COST_LATE naming it brings. */
|
|
12
|
-
export declare const BOOKED = "adapter.request";
|
|
13
10
|
/** What a turn's end says: the message it took (the MESSAGE id), the session's own outcome (`failed` too when the bridge
|
|
14
11
|
* wrote the turn's error, in `error`), the entry of the turn's answer (its last request with text and no call; null
|
|
15
12
|
* when the turn showed no text), and whether a request it made is still unbooked (its cost then comes later, as a
|
package/dist/turn-end.js
CHANGED
|
@@ -10,9 +10,6 @@ export { TURN_END } from "./timeline/index.js";
|
|
|
10
10
|
* for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
|
|
11
11
|
export const MESSAGE = "adapter.message";
|
|
12
12
|
export const MESSAGE_END = "adapter.message_end";
|
|
13
|
-
/** The root's marker of a paid request already written as a pi.assistant entry (`{ key, request, unpriced? }`, in the
|
|
14
|
-
* entry's commit): `unpriced` when its cost was not in yet, which a REQUEST_COST_LATE naming it brings. */
|
|
15
|
-
export const BOOKED = "adapter.request";
|
|
16
13
|
/** The `api` of every assistant message serve's bridge writes for a claude-agent or codex request (harness-app.ts): its
|
|
17
14
|
* stop reason says nothing of the turn's end (a cost, a cut, an interruption and an answer read alike). */
|
|
18
15
|
export const ADAPTER_API = "agentrun-adapter";
|
package/dist/usage-lines.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** A run's meters, from
|
|
1
|
+
/** A run's meters, from the one store (store-reads/cap.ts metersOverStore) or its live rows: each null when one of its charges is unknown. */
|
|
2
2
|
export type RunMeters = {
|
|
3
3
|
tools: number | null;
|
|
4
4
|
tokens: number | null;
|
package/dist/validate.d.ts
CHANGED
|
@@ -9,12 +9,18 @@ export declare const isObject: (value: unknown) => value is Json;
|
|
|
9
9
|
export declare const IDEMPOTENCY_TTL_S = 86400;
|
|
10
10
|
export declare const stable: (value: unknown) => string;
|
|
11
11
|
export declare const DEFINITION_FIELDS: string[];
|
|
12
|
+
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
13
|
+
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
14
|
+
* `repo/`; `none` clears it on an edit. */
|
|
15
|
+
export declare const CHECKOUTS: readonly ["pull_request", "none"];
|
|
12
16
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
13
17
|
export declare const NOT_KEPT: Record<string, string>;
|
|
14
18
|
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
15
19
|
export declare const MAX_TOOL_CALLS = 1000;
|
|
16
20
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
17
21
|
export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
|
|
22
|
+
/** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
|
|
23
|
+
export declare const MODEL_TIER_NAMES: readonly ["fast", "strong"];
|
|
18
24
|
/** `provider/model-id`. */
|
|
19
25
|
export declare const MODEL_REF: RegExp;
|
|
20
26
|
/** A body's fields that `allowed` does not name, each as the 422's not_allowed issue. */
|
package/dist/validate.js
CHANGED
|
@@ -17,7 +17,11 @@ export const isObject = (value) => typeof value === "object" && value !== null &
|
|
|
17
17
|
/** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
|
|
18
18
|
export const IDEMPOTENCY_TTL_S = 86_400;
|
|
19
19
|
export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
|
|
20
|
-
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls"];
|
|
20
|
+
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls", "checkout"];
|
|
21
|
+
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
22
|
+
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
23
|
+
* `repo/`; `none` clears it on an edit. */
|
|
24
|
+
export const CHECKOUTS = ["pull_request", "none"];
|
|
21
25
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
22
26
|
export const NOT_KEPT = {
|
|
23
27
|
input_schema: "The agent store keeps no input_schema: an agentic run takes {content}, and a workflow checks its input against its own schema.",
|
|
@@ -26,6 +30,8 @@ export const NOT_KEPT = {
|
|
|
26
30
|
export const MAX_TOOL_CALLS = 1_000;
|
|
27
31
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
28
32
|
export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
|
|
33
|
+
/** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
|
|
34
|
+
export const MODEL_TIER_NAMES = ["fast", "strong"];
|
|
29
35
|
/** `provider/model-id`. */
|
|
30
36
|
export const MODEL_REF = /^[^/\s]+\/\S+$/;
|
|
31
37
|
const SKILL_FILE = "/SKILL.md";
|
|
@@ -79,6 +85,20 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
79
85
|
else if (typeof d.model !== "string" || !MODEL_REF.test(d.model))
|
|
80
86
|
out.push(issue(`${at}.model`, "bad_format", `${at}.model is "provider/model-id"`));
|
|
81
87
|
}
|
|
88
|
+
if (d.model_tiers !== undefined) {
|
|
89
|
+
if (d.workflow !== undefined)
|
|
90
|
+
out.push(issue(`${at}.model_tiers`, "not_allowed", "A workflow revision keeps no model tiers: each model node names its tier, run on this host's model for it.", `Remove ${at}.model_tiers.`));
|
|
91
|
+
else if (!isObject(d.model_tiers) || !Object.keys(d.model_tiers).length)
|
|
92
|
+
out.push(issue(`${at}.model_tiers`, "wrong_type", `${at}.model_tiers is an object of ${MODEL_TIER_NAMES.join(", ")} to "provider/model-id"`));
|
|
93
|
+
else {
|
|
94
|
+
for (const [tier, ref] of Object.entries(d.model_tiers)) {
|
|
95
|
+
if (!MODEL_TIER_NAMES.includes(tier))
|
|
96
|
+
out.push(issue(`${at}.model_tiers.${tier}`, "not_allowed", `${at}.model_tiers names ${MODEL_TIER_NAMES.join(" and ")} alone`, `Remove ${at}.model_tiers.${tier}.`));
|
|
97
|
+
else if (typeof ref !== "string" || !MODEL_REF.test(ref))
|
|
98
|
+
out.push(issue(`${at}.model_tiers.${tier}`, "bad_format", `${at}.model_tiers.${tier} is "provider/model-id"`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
82
102
|
if (d.harness !== undefined && !HARNESSES.includes(d.harness))
|
|
83
103
|
out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${HARNESSES.join(", ")}`));
|
|
84
104
|
if (d.place !== undefined)
|
|
@@ -94,8 +114,8 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
94
114
|
if (d.learning !== undefined) {
|
|
95
115
|
if (d.workflow !== undefined)
|
|
96
116
|
out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
|
|
97
|
-
else if (typeof d.learning !== "boolean")
|
|
98
|
-
out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true or
|
|
117
|
+
else if (typeof d.learning !== "boolean" && d.learning !== "notes")
|
|
118
|
+
out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true, false or "notes": true learns notes, skills and workflows, "notes" notes and skills alone`));
|
|
99
119
|
}
|
|
100
120
|
// An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
|
|
101
121
|
// completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
|
|
@@ -132,6 +152,13 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
132
152
|
if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
|
|
133
153
|
out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
|
|
134
154
|
}
|
|
155
|
+
// The server's checkout before each run's first turn: kept by an edit that leaves it out, cleared by `none`.
|
|
156
|
+
if (d.checkout !== undefined) {
|
|
157
|
+
if (d.workflow !== undefined)
|
|
158
|
+
out.push(issue(`${at}.checkout`, "not_allowed", "A workflow revision keeps no checkout: only an agentic run starts in a checkout.", `Remove ${at}.checkout.`));
|
|
159
|
+
else if (!CHECKOUTS.includes(d.checkout))
|
|
160
|
+
out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
|
|
161
|
+
}
|
|
135
162
|
// The tool calls each conversation of an agentic run may make (tool-budget.ts): above 0 sets the budget, 0 clears it, and
|
|
136
163
|
// an edit that leaves it out keeps the agent's, as the default cap is kept.
|
|
137
164
|
if (d.max_tool_calls !== undefined) {
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export type WebhookSecret = Pick<SealedSettingsOverStore, "get" | "mint" | "remo
|
|
|
58
58
|
export { signatureOf } from "./standard-webhooks.js";
|
|
59
59
|
/** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
|
|
60
60
|
* so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
|
|
61
|
-
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
|
|
61
|
+
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
|
|
62
62
|
* was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
|
|
63
63
|
* row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
|
|
64
64
|
* marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
|
|
@@ -71,6 +71,7 @@ export declare function waitMarkerOf(rows: readonly {
|
|
|
71
71
|
id?: unknown;
|
|
72
72
|
at?: unknown;
|
|
73
73
|
asked_at?: unknown;
|
|
74
|
+
cap_usd?: unknown;
|
|
74
75
|
} | null | undefined, waiting: boolean, learningLabel: string): string | undefined;
|
|
75
76
|
export declare class Webhooks {
|
|
76
77
|
private readonly store;
|
package/dist/webhooks.js
CHANGED
|
@@ -55,7 +55,7 @@ function configOf(value) {
|
|
|
55
55
|
}
|
|
56
56
|
/** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
|
|
57
57
|
* so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
|
|
58
|
-
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
|
|
58
|
+
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
|
|
59
59
|
* was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
|
|
60
60
|
* row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
|
|
61
61
|
* marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
|
|
@@ -66,8 +66,11 @@ export function waitMarkerOf(rows, pending, waiting, learningLabel) {
|
|
|
66
66
|
const kind = pending?.kind;
|
|
67
67
|
if (kind === "approval" && typeof pending?.id === "string")
|
|
68
68
|
return `approval:${pending.id}`;
|
|
69
|
+
// A pause at the cap, by when it came and the cap it waits at: waits at one cap are one pause, told once, and a raise that
|
|
70
|
+
// still does not cover the step pauses the run anew at the higher cap, told again (the runner writes no row for the
|
|
71
|
+
// refused step, so its time alone would not move).
|
|
69
72
|
if (kind === "budget" && typeof pending?.at === "string")
|
|
70
|
-
return `budget:${pending.at}`;
|
|
73
|
+
return `budget:${pending.at}${typeof pending.cap_usd === "number" ? `:${pending.cap_usd}` : ""}`;
|
|
71
74
|
if ((kind === "browser" || kind === "computer") && typeof pending?.asked_at === "string")
|
|
72
75
|
return `${kind}:${pending.asked_at}`;
|
|
73
76
|
return rows.findLast((r) => r.kind === "waiting")?.id ?? last();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type DecisionExchange, type DecisionReceipt } from "@parcha/agentrun-dsl";
|
|
2
|
+
import type { DocumentReader } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { WorkflowInvocation } from "./task.js";
|
|
4
|
+
type Context = WorkflowInvocation["context"];
|
|
5
|
+
/** The interpreter's two decision hooks over one invocation of a workflow task. */
|
|
6
|
+
export type DecisionRecovery = {
|
|
7
|
+
/** The interpreter's `recordDecision`: commits the receipt's row after every row recorded before it, and resolves
|
|
8
|
+
* once that commit is durable; a commit that fails rejects this receipt's call. The task's state is untouched. */
|
|
9
|
+
recordDecision(receipt: DecisionReceipt, exchange: DecisionExchange): Promise<void>;
|
|
10
|
+
/** The interpreter's `recovery.decision`: the receipt rebuilt from the last answered row this run recorded under
|
|
11
|
+
* `id`, or undefined when it recorded none (a request that failed, one recorded without its identity, or one another
|
|
12
|
+
* run recorded, is asked again). */
|
|
13
|
+
decision(id: string): Promise<DecisionReceipt | undefined>;
|
|
14
|
+
};
|
|
15
|
+
/** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
|
|
16
|
+
* handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
|
|
17
|
+
* `recovery.decision` beside the driver's recovery hooks. */
|
|
18
|
+
export declare function decisionRecovery(invocation: {
|
|
19
|
+
key: string;
|
|
20
|
+
runtime: Pick<WorkflowInvocation["runtime"], "commit"> & DocumentReader;
|
|
21
|
+
context: Context;
|
|
22
|
+
}): DecisionRecovery;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// A workflow task's decision receipts, durable in its run's Session: each receipt is a row (decisions.ts) committed
|
|
2
|
+
// through the task's own commit before the interpreter acts on its answers, and a resumed run's request is answered
|
|
3
|
+
// from the row its earlier process committed, so the judge is not asked again and the run decides what it decided.
|
|
4
|
+
// Every run in the Session shares the rows' document, and a receipt's id does not name its run, so each row carries
|
|
5
|
+
// the run's key and a run is answered only from its own rows.
|
|
6
|
+
import { DECISION_RECEIPT_VERSION } from "@parcha/agentrun-dsl";
|
|
7
|
+
import { appendDecision, DECISION_ROW_VERSION, readDecisionsFrom } from "./decisions.js";
|
|
8
|
+
/** What a receipt says of its provider beside its answers, each only when present: who answered, the sources, the
|
|
9
|
+
* questions refused, where each confidence came from, the images it carried and the state the judge saw. A replay gives the run all of it again. */
|
|
10
|
+
const kept = (from) => ({
|
|
11
|
+
...(from.provider !== undefined ? { provider: from.provider } : {}),
|
|
12
|
+
...(from.images !== undefined ? { images: from.images } : {}),
|
|
13
|
+
...(from.cost_basis !== undefined ? { cost_basis: from.cost_basis } : {}),
|
|
14
|
+
...(from.state !== undefined ? { state: from.state, state_truncated: from.state_truncated === true } : {}),
|
|
15
|
+
...(from.evidence !== undefined ? { evidence: from.evidence } : {}),
|
|
16
|
+
...(from.refused !== undefined ? { refused: from.refused } : {}),
|
|
17
|
+
...(from.confidence_source !== undefined ? { confidence_source: from.confidence_source } : {}),
|
|
18
|
+
});
|
|
19
|
+
/** A receipt as the row the run `key` stores: the receipt's own fields, its identity, and the request's size. */
|
|
20
|
+
function rowOf(receipt, exchange, key) {
|
|
21
|
+
return {
|
|
22
|
+
v: DECISION_ROW_VERSION, at: receipt.at, node: receipt.node, kind: receipt.kind, item: receipt.item, execution_path: receipt.execution_path,
|
|
23
|
+
request_sha256: receipt.request_sha256,
|
|
24
|
+
request_bytes: Buffer.byteLength(JSON.stringify({ state: exchange.request.state, questions: exchange.request.questions })),
|
|
25
|
+
model: receipt.model, questions: receipt.questions, answers: receipt.answers, rule: receipt.rule, action: receipt.action,
|
|
26
|
+
usage: receipt.usage, cost_usd: receipt.cost_usd, latency_ms: receipt.latency_ms,
|
|
27
|
+
// An error the receipt kept cut says so, and the row keeps saying it: a host holds its tail back (serve graph-served.ts).
|
|
28
|
+
...(receipt.error !== undefined ? { error: receipt.error, ...(receipt.error_truncated === true ? { error_truncated: true } : {}) } : {}),
|
|
29
|
+
status: receipt.status, ...kept(receipt),
|
|
30
|
+
decision_id: receipt.id, request: receipt.request, state_sha256: receipt.state_sha256, run_key: key,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The receipt the run `key`'s last answered row under `id` is: a rule is set only on an answered receipt, and an
|
|
34
|
+
* answered one carries no error. */
|
|
35
|
+
function answeredReceipt(rows, id, key) {
|
|
36
|
+
const row = rows.findLast((stored) => stored.run_key === key && stored.decision_id === id && stored.rule !== null && stored.error === undefined
|
|
37
|
+
&& stored.request !== undefined && stored.state_sha256 !== undefined && stored.execution_path !== null);
|
|
38
|
+
if (!row)
|
|
39
|
+
return undefined;
|
|
40
|
+
return {
|
|
41
|
+
v: DECISION_RECEIPT_VERSION, id, at: row.at, node: row.node, kind: row.kind, item: row.item, execution_path: row.execution_path,
|
|
42
|
+
request: row.request, status: "answered", state_sha256: row.state_sha256,
|
|
43
|
+
questions: row.questions, answers: row.answers, rule: row.rule, action: row.action,
|
|
44
|
+
model: row.model, usage: row.usage, cost_usd: row.cost_usd, request_sha256: row.request_sha256, latency_ms: row.latency_ms,
|
|
45
|
+
...kept(row),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
|
|
49
|
+
* handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
|
|
50
|
+
* `recovery.decision` beside the driver's recovery hooks. */
|
|
51
|
+
export function decisionRecovery(invocation) {
|
|
52
|
+
const { key, runtime, context } = invocation;
|
|
53
|
+
const harness = {
|
|
54
|
+
commit: async (change) => {
|
|
55
|
+
let result;
|
|
56
|
+
await runtime.commit(async (tx) => { result = await change(tx); return undefined; }, context);
|
|
57
|
+
return result;
|
|
58
|
+
},
|
|
59
|
+
// The form the store holds is settled once per invocation, from this reader: the run's open.
|
|
60
|
+
snapshot: ((...args) => runtime.snapshot(...args)),
|
|
61
|
+
};
|
|
62
|
+
// The run's rows as read so far: a resumed process reads the store once, and each later answer reads only the rows after them.
|
|
63
|
+
const known = [];
|
|
64
|
+
let next = 0;
|
|
65
|
+
let chain = Promise.resolve();
|
|
66
|
+
return {
|
|
67
|
+
recordDecision(receipt, exchange) {
|
|
68
|
+
const row = rowOf(receipt, exchange, key);
|
|
69
|
+
const committed = chain.then(() => appendDecision(harness, row, context));
|
|
70
|
+
chain = committed.catch(() => undefined);
|
|
71
|
+
return committed;
|
|
72
|
+
},
|
|
73
|
+
async decision(id) {
|
|
74
|
+
const read = await readDecisionsFrom(harness, next, context);
|
|
75
|
+
known.push(...read.rows);
|
|
76
|
+
next = read.next;
|
|
77
|
+
return answeredReceipt(known, id, key);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type DocumentReader, type Harness } from "@earendil-works/pi-durable";
|
|
3
|
+
/** The session document that holds a run's decision rows. */
|
|
4
|
+
export declare const DECISION_RECEIPTS_DOC = "agentrun.decisions";
|
|
5
|
+
/** The stored row's version. */
|
|
6
|
+
export declare const DECISION_ROW_VERSION = 1;
|
|
7
|
+
/** How the answers became the action, with every threshold applied. */
|
|
8
|
+
export type DecisionRowRule =
|
|
9
|
+
/** judge: each question's decoded value (choice, noul at 0.5, rounded score). */
|
|
10
|
+
{
|
|
11
|
+
kind: "judge";
|
|
12
|
+
}
|
|
13
|
+
/** pick: the chosen option names an item by its position, or none. */
|
|
14
|
+
| {
|
|
15
|
+
kind: "pick";
|
|
16
|
+
options: string[];
|
|
17
|
+
none: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** route: the chosen branch, or the unsure branch when the choice's confidence is below `gte`. */
|
|
20
|
+
| {
|
|
21
|
+
kind: "route";
|
|
22
|
+
unsure: {
|
|
23
|
+
gte: number;
|
|
24
|
+
branch: string;
|
|
25
|
+
} | null;
|
|
26
|
+
}
|
|
27
|
+
/** sift: an item is kept when its `keep` measure meets `gte`; every item without a keep rule. */
|
|
28
|
+
| {
|
|
29
|
+
kind: "sift";
|
|
30
|
+
items: number;
|
|
31
|
+
ids: string[];
|
|
32
|
+
keep: {
|
|
33
|
+
id: string;
|
|
34
|
+
measure: "confidence" | "value";
|
|
35
|
+
gte: number;
|
|
36
|
+
} | null;
|
|
37
|
+
}
|
|
38
|
+
/** ask: the predicate holds when p_yes meets `gte`. */
|
|
39
|
+
| {
|
|
40
|
+
kind: "ask";
|
|
41
|
+
gte: number;
|
|
42
|
+
}
|
|
43
|
+
/** verify: a noul question fails when p_yes is below its threshold (null: not judged, an empty field); a failed
|
|
44
|
+
* question the submission holds is doubted, a failed one it lacks is unmet. */
|
|
45
|
+
| {
|
|
46
|
+
kind: "verify";
|
|
47
|
+
thresholds: Record<string, number | null>;
|
|
48
|
+
present: string[];
|
|
49
|
+
};
|
|
50
|
+
/** One stored decision row. */
|
|
51
|
+
export type DecisionRow = {
|
|
52
|
+
v: typeof DECISION_ROW_VERSION;
|
|
53
|
+
at: string;
|
|
54
|
+
node: string;
|
|
55
|
+
kind: "judge" | "pick" | "sift" | "route" | "ask" | "verify";
|
|
56
|
+
item: number | null;
|
|
57
|
+
execution_path: string | null;
|
|
58
|
+
request_sha256: string | null;
|
|
59
|
+
request_bytes: number;
|
|
60
|
+
model: string | null;
|
|
61
|
+
questions: Record<string, unknown>;
|
|
62
|
+
answers: Record<string, unknown>;
|
|
63
|
+
rule: DecisionRowRule | null;
|
|
64
|
+
/** What the run did with the answers; null when the node did not act on them. */
|
|
65
|
+
action: unknown;
|
|
66
|
+
usage: {
|
|
67
|
+
input_tokens: number;
|
|
68
|
+
output_tokens: number;
|
|
69
|
+
} | null;
|
|
70
|
+
cost_usd: number | null;
|
|
71
|
+
latency_ms: number;
|
|
72
|
+
/** The request's error, as its receipt kept it: whole up to 64 KB, a longer one cut there with `error_truncated`. */
|
|
73
|
+
error?: string;
|
|
74
|
+
error_truncated?: boolean;
|
|
75
|
+
/** How the request ended (`answered`, `failed` or `cancelled`); absent on a row written before it was kept. */
|
|
76
|
+
status?: "answered" | "failed" | "cancelled";
|
|
77
|
+
/** The provider that answered, when the host's judge names it or the node pins it. */
|
|
78
|
+
provider?: string;
|
|
79
|
+
/** The sources the provider grounded its answers in, as the receipt has them; absent when it gave none. */
|
|
80
|
+
evidence?: Array<{
|
|
81
|
+
url: string;
|
|
82
|
+
title: string | null;
|
|
83
|
+
excerpts: string[];
|
|
84
|
+
scope: string;
|
|
85
|
+
}>;
|
|
86
|
+
/** The questions whose answer came back as a refusal. */
|
|
87
|
+
refused?: string[];
|
|
88
|
+
/** For each choice and score answer, whether its confidence is the provider's own or was derived. */
|
|
89
|
+
confidence_source?: Record<string, string>;
|
|
90
|
+
/** The images the request carried, by digest (token, reference, SHA-256, type, size), never their bytes. */
|
|
91
|
+
images?: Array<{
|
|
92
|
+
token: string;
|
|
93
|
+
ref: string;
|
|
94
|
+
sha256: string | null;
|
|
95
|
+
mime: string | null;
|
|
96
|
+
bytes: number | null;
|
|
97
|
+
}>;
|
|
98
|
+
/** The state the judge saw, or past 64 KB of JSON the first 64 KB of its text, with `state_truncated` saying which. */
|
|
99
|
+
state?: unknown;
|
|
100
|
+
state_truncated?: boolean;
|
|
101
|
+
/** The request's spend is on its frozen driver's state, so a cost fold counts it there, not here. */
|
|
102
|
+
driver_spend?: true;
|
|
103
|
+
/** The receipt's id, its place among its node's requests, the digest of the state it was asked with, and the key of
|
|
104
|
+
* the workflow run that asked it. A row that carries all four is the whole receipt again, so that run, resumed, can be
|
|
105
|
+
* answered from it (`decisionRecovery`); another run in the same Session never is. */
|
|
106
|
+
decision_id?: string;
|
|
107
|
+
request?: {
|
|
108
|
+
index: number;
|
|
109
|
+
count: number;
|
|
110
|
+
items?: number[];
|
|
111
|
+
};
|
|
112
|
+
state_sha256?: string;
|
|
113
|
+
run_key?: string;
|
|
114
|
+
/** The id its host admitted the request under before sending it, when the host admits its requests so that one the run
|
|
115
|
+
* stopped before it answered is still counted. The row settles that admission in the row's own commit: a cost fold
|
|
116
|
+
* counts an admission no row names, and never one a row names. */
|
|
117
|
+
admission?: string;
|
|
118
|
+
/** How the cost was reached (reported by the provider, estimated by the host, unknown), when the judge said. */
|
|
119
|
+
cost_basis?: "reported" | "estimate" | "unknown";
|
|
120
|
+
};
|
|
121
|
+
/** How many rows the keyed form holds: its next key. A few bytes, so rewriting it at every commit costs the same at every count. */
|
|
122
|
+
export declare const DECISION_COUNT_DOC = "agentrun.decisions.count";
|
|
123
|
+
/** A keyed row's key: its place, zero-padded so the keys sort in commit order. */
|
|
124
|
+
export declare const decisionKey: (place: number) => string;
|
|
125
|
+
/** Commit one row, appended after every row committed before it. */
|
|
126
|
+
export declare function appendDecision(harness: Pick<Harness, "commit">, row: DecisionRow, context?: Context): Promise<void>;
|
|
127
|
+
/** Every row the run's Session holds, in commit order. */
|
|
128
|
+
export declare function readDecisions(read: DocumentReader, context?: Context): Promise<DecisionRow[]>;
|
|
129
|
+
/** The rows from place `from` on and the place after the last: only the new ones are read, so a reader that keeps `next`
|
|
130
|
+
* reads each row once. */
|
|
131
|
+
export declare function readDecisionsFrom(read: Pick<DocumentReader, "snapshot">, from: number, context?: Context): Promise<{
|
|
132
|
+
rows: DecisionRow[];
|
|
133
|
+
next: number;
|
|
134
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A run's decision rows as pi-durable stores them, one row per typed question the run asked, in commit order: the KEYED
|
|
2
|
+
// family, one document of kind `agentrun.decisions` per row, written once. The row is a stored format (version 1); it
|
|
3
|
+
// does not change with the interpreter: a host maps `@parcha/agentrun-dsl`'s `DecisionReceipt` to a row, with the facts only
|
|
4
|
+
// the host has (the request's size and metering, whether the node acted on the answers), and this module stores and reads
|
|
5
|
+
// rows without looking inside them.
|
|
6
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
7
|
+
import { defineDoc, defineDocFamily } from "@earendil-works/pi-durable";
|
|
8
|
+
/** The session document that holds a run's decision rows. */
|
|
9
|
+
export const DECISION_RECEIPTS_DOC = "agentrun.decisions";
|
|
10
|
+
/** The stored row's version. */
|
|
11
|
+
export const DECISION_ROW_VERSION = 1;
|
|
12
|
+
/** The keyed form: one document per row, of the same kind, keyed by the row's place in the run's rows (`keyOf`), written once. The
|
|
13
|
+
* document's value is exactly the row. */
|
|
14
|
+
const DecisionRowDoc = defineDocFamily({ kind: DECISION_RECEIPTS_DOC, version: 1, scope: "session", family: true, initial: () => ({}), checkpointWhen: () => false });
|
|
15
|
+
/** How many rows the keyed form holds: its next key. A few bytes, so rewriting it at every commit costs the same at every count. */
|
|
16
|
+
export const DECISION_COUNT_DOC = "agentrun.decisions.count";
|
|
17
|
+
const DecisionCountDoc = defineDoc({ kind: DECISION_COUNT_DOC, version: 1, scope: "session", initial: () => ({ count: 0 }), checkpointWhen: () => false });
|
|
18
|
+
/** A keyed row's key: its place, zero-padded so the keys sort in commit order. */
|
|
19
|
+
export const decisionKey = (place) => String(place).padStart(8, "0");
|
|
20
|
+
/** Commit one row, appended after every row committed before it. */
|
|
21
|
+
export async function appendDecision(harness, row, context = BACKGROUND_CONTEXT) {
|
|
22
|
+
const stored = JSON.parse(JSON.stringify(row));
|
|
23
|
+
await harness.commit(async (tx) => {
|
|
24
|
+
const count = await tx.doc(DecisionCountDoc);
|
|
25
|
+
const place = count.count;
|
|
26
|
+
count.count = place + 1;
|
|
27
|
+
Object.assign(await tx.doc(DecisionRowDoc, decisionKey(place), null), stored);
|
|
28
|
+
}, context);
|
|
29
|
+
}
|
|
30
|
+
/** Every row the run's Session holds, in commit order. */
|
|
31
|
+
export async function readDecisions(read, context = BACKGROUND_CONTEXT) {
|
|
32
|
+
return (await readDecisionsFrom(read, 0, context)).rows;
|
|
33
|
+
}
|
|
34
|
+
/** The rows from place `from` on and the place after the last: only the new ones are read, so a reader that keeps `next`
|
|
35
|
+
* reads each row once. */
|
|
36
|
+
export async function readDecisionsFrom(read, from, context = BACKGROUND_CONTEXT) {
|
|
37
|
+
const total = (await read.snapshot(DecisionCountDoc, context))?.count ?? 0;
|
|
38
|
+
const rows = [];
|
|
39
|
+
for (let at = from; at < total; at += 64) {
|
|
40
|
+
const batch = await Promise.all(Array.from({ length: Math.min(64, total - at) }, (_, i) => read.snapshot(DecisionRowDoc, decisionKey(at + i), context)));
|
|
41
|
+
for (const doc of batch)
|
|
42
|
+
if (doc !== undefined)
|
|
43
|
+
rows.push(doc);
|
|
44
|
+
}
|
|
45
|
+
return { rows, next: total };
|
|
46
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PiRunner } from './runner.js';
|
|
2
|
+
import type { PiHostContext, PiHostRunnerOptions, PiSessionFactory } from './types.js';
|
|
3
|
+
export declare const PI_MODEL_SETUP_MESSAGE = "AgentRun requires an active Pi model. Use /login to connect a provider, then /model to select it. Try /agentrun demo without model access.";
|
|
4
|
+
export declare function createPiHostSessionFactory(context: PiHostContext): PiSessionFactory;
|
|
5
|
+
export declare function createPiHostRunner(context: PiHostContext, options?: PiHostRunnerOptions): PiRunner;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Agent } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import { SUBMIT_TOOL } from './host-tools.js';
|
|
3
|
+
import { createPiRunner } from './runner.js';
|
|
4
|
+
import { workflowToolContext } from './tool-context.js';
|
|
5
|
+
import { OperatorError } from './operator-error.js';
|
|
6
|
+
export const PI_MODEL_SETUP_MESSAGE = 'AgentRun requires an active Pi model. Use /login to connect a provider, then /model to select it. Try /agentrun demo without model access.';
|
|
7
|
+
function selectedModel(context) {
|
|
8
|
+
const model = context.model;
|
|
9
|
+
if (!model)
|
|
10
|
+
throw new OperatorError(PI_MODEL_SETUP_MESSAGE);
|
|
11
|
+
if (!context.modelRegistry || typeof context.modelRegistry.streamSimple !== 'function' || typeof context.modelRegistry.getAll !== 'function') {
|
|
12
|
+
throw new OperatorError('AgentRun requires the host public model registry');
|
|
13
|
+
}
|
|
14
|
+
if (!context.modelRegistry.getAll().some(known => known.id === model.id && known.provider === model.provider && known.api === model.api)) {
|
|
15
|
+
throw new OperatorError(PI_MODEL_SETUP_MESSAGE);
|
|
16
|
+
}
|
|
17
|
+
return model;
|
|
18
|
+
}
|
|
19
|
+
export function createPiHostSessionFactory(context) {
|
|
20
|
+
const model = selectedModel(context);
|
|
21
|
+
const stream = context.modelRegistry.streamSimple.bind(context.modelRegistry);
|
|
22
|
+
const toolContext = workflowToolContext(context);
|
|
23
|
+
return async (options) => {
|
|
24
|
+
if (options.model !== model)
|
|
25
|
+
throw new Error('The child session must use the captured active Pi model');
|
|
26
|
+
let delivered = false, turns = 0;
|
|
27
|
+
const allowed = new Set(options.tools);
|
|
28
|
+
const tools = options.customTools.filter(tool => allowed.has(tool.name)).map(tool => ({
|
|
29
|
+
name: tool.name, label: tool.label, description: tool.description,
|
|
30
|
+
parameters: tool.parameters,
|
|
31
|
+
async execute(id, args, signal, onUpdate) {
|
|
32
|
+
const result = await tool.execute(id, args, signal, onUpdate, toolContext);
|
|
33
|
+
if (tool.name === SUBMIT_TOOL && result.details?.accepted === true)
|
|
34
|
+
delivered = true;
|
|
35
|
+
return result;
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
const agent = new Agent({
|
|
39
|
+
initialState: { model, thinkingLevel: options.thinkingLevel, systemPrompt: options.resourceLoader.getSystemPrompt() ?? '', tools },
|
|
40
|
+
streamFn: (_model, transcript, streamOptions) => stream(model, transcript, streamOptions),
|
|
41
|
+
toolExecution: 'sequential',
|
|
42
|
+
finishTurn: () => {
|
|
43
|
+
turns++;
|
|
44
|
+
if (delivered || (options.maxTurns !== undefined && turns >= options.maxTurns))
|
|
45
|
+
return { action: 'end' };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
let disposed = false;
|
|
49
|
+
const unsubscribers = new Set();
|
|
50
|
+
return { session: {
|
|
51
|
+
async prompt(text) {
|
|
52
|
+
if (disposed)
|
|
53
|
+
throw new Error('Pi host child session is disposed');
|
|
54
|
+
await agent.prompt(text);
|
|
55
|
+
},
|
|
56
|
+
subscribe(listener) {
|
|
57
|
+
if (disposed)
|
|
58
|
+
throw new Error('Pi host child session is disposed');
|
|
59
|
+
const unsubscribe = agent.subscribe(event => { listener(event); });
|
|
60
|
+
unsubscribers.add(unsubscribe);
|
|
61
|
+
return () => { unsubscribe(); unsubscribers.delete(unsubscribe); };
|
|
62
|
+
},
|
|
63
|
+
async abort() { agent.abort(); },
|
|
64
|
+
dispose() {
|
|
65
|
+
if (disposed)
|
|
66
|
+
return;
|
|
67
|
+
disposed = true;
|
|
68
|
+
agent.abort();
|
|
69
|
+
agent.clearAllQueues();
|
|
70
|
+
for (const unsubscribe of unsubscribers)
|
|
71
|
+
unsubscribe();
|
|
72
|
+
unsubscribers.clear();
|
|
73
|
+
},
|
|
74
|
+
} };
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function createPiHostRunner(context, options = {}) {
|
|
78
|
+
const model = selectedModel(context);
|
|
79
|
+
// The host session's thinking level is not a node's: a node that names none thinks at medium, unless the caller
|
|
80
|
+
// passes its own `thinkingLevel`.
|
|
81
|
+
return createPiRunner({
|
|
82
|
+
...options, model, cwd: options.cwd ?? context.cwd,
|
|
83
|
+
sessionFactory: createPiHostSessionFactory(context),
|
|
84
|
+
});
|
|
85
|
+
}
|