@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/runner/dispatch.js
CHANGED
|
@@ -25,6 +25,13 @@ export class LaunchUnreadable extends Error {
|
|
|
25
25
|
super(`run ${runId}: its launch record could not be read as a launch (it names no place, or is not an object).`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
/** The first wait before a buffered row whose delivery threw is tried again, and the most any later wait (doubling)
|
|
29
|
+
* grows to. */
|
|
30
|
+
export const REPLAY_RETRY_FIRST_MS = 250;
|
|
31
|
+
export const REPLAY_RETRY_MAX_MS = 5_000;
|
|
32
|
+
/** How many times in all a buffered row's delivery is tried before the dispatch stops trying it on this claim: a row that
|
|
33
|
+
* fails for a lasting reason is said once and left untaken for the run's next claim, never tried for the whole run. */
|
|
34
|
+
export const REPLAY_TRIES = 5;
|
|
28
35
|
/** The loop factory the runner holds for every run: `createDispatchLoop(deps)` picks each run's harness loop at its
|
|
29
36
|
* claim. The inner loop gets the same LoopDeps the dispatch does, so the runner's fence, flush, live and end-of-run
|
|
30
37
|
* channels reach it unchanged. */
|
|
@@ -62,16 +69,83 @@ function dispatchLoop(deps, loopDeps) {
|
|
|
62
69
|
// buffered row and no buffered stop is lost between choosing the loop and replaying what was buffered.
|
|
63
70
|
inner = factory(innerDeps);
|
|
64
71
|
const end = inner.start(claim);
|
|
65
|
-
// Replay the buffered commands through the inner loop in order, each awaited, then let its `delivered` resolve.
|
|
72
|
+
// Replay the buffered commands through the inner loop in order, each awaited, then let its `delivered` resolve. A
|
|
73
|
+
// command whose delivery throws is never thrown out of here, where nothing would catch it and the runner's process
|
|
74
|
+
// would go down. The runner already moved past its row (the dispatch said it holds it), so the dispatch tries it again
|
|
75
|
+
// itself while the inner loop runs, as the runner tries again a row whose delivery threw (a store that failed for a
|
|
76
|
+
// moment), up to REPLAY_TRIES times. Once the inner loop has ended, or the tries are spent, a row still not delivered
|
|
77
|
+
// stays untaken (the store's take is the inner loop's own commit), so the run's next claim delivers it again and
|
|
78
|
+
// nobody's words are lost.
|
|
66
79
|
const buffered = early.splice(0);
|
|
67
|
-
void (
|
|
80
|
+
void replay(claim.runId, inner, buffered, end);
|
|
81
|
+
// The buffered stop, not awaited here (start() returns the inner loop's end): an inner stop that throws is said in
|
|
82
|
+
// the log, never an unhandled rejection, which would end the runner process and every run it holds.
|
|
83
|
+
if (earlyStop) {
|
|
84
|
+
inner.stop(earlyStop).catch((error) => {
|
|
85
|
+
const text = error?.message ?? String(error);
|
|
86
|
+
console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact ? loopDeps.redact(text) : text}`);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return end;
|
|
90
|
+
}
|
|
91
|
+
/** Hands each of `buffered` to `loop` once, in order, then lets the loop's `delivered` resolve; the ones whose delivery
|
|
92
|
+
* threw are tried again, in order, until each goes through, the loop has ended, or a row has been tried REPLAY_TRIES
|
|
93
|
+
* times (said once; it and the failed rows after it are left untaken for the run's next claim). Never rejects. */
|
|
94
|
+
async function replay(runId, loop, buffered, end, tries = REPLAY_TRIES) {
|
|
95
|
+
let ended = false;
|
|
96
|
+
const loopEnded = end.then(() => undefined, () => undefined).then(() => void (ended = true));
|
|
97
|
+
let lastError;
|
|
98
|
+
const delivers = async (command) => {
|
|
99
|
+
try {
|
|
100
|
+
await loop.command(command);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
lastError = error;
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
// What went wrong, cut of the values the run holds (LoopDeps.redact), as the log may not show them.
|
|
109
|
+
const why = () => {
|
|
110
|
+
const text = lastError?.message ?? String(lastError);
|
|
111
|
+
return loopDeps.redact ? loopDeps.redact(text) : text;
|
|
112
|
+
};
|
|
113
|
+
const failed = [];
|
|
114
|
+
try {
|
|
115
|
+
// Every row is tried once before the inner loop's `delivered` resolves, a later one even when an earlier one threw:
|
|
116
|
+
// a loop that waits on `delivered` (a run reopened by a follow-up) never goes on with a row still held here.
|
|
68
117
|
for (const command of buffered)
|
|
69
|
-
await
|
|
118
|
+
if (!(await delivers(command)))
|
|
119
|
+
failed.push(command);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
70
122
|
replayed();
|
|
71
|
-
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
123
|
+
}
|
|
124
|
+
if (failed.length === 0)
|
|
125
|
+
return;
|
|
126
|
+
console.warn(`[runner] ${runId}: a ${failed[0].kind} row held before its loop was chosen was not delivered (${why()}); it is tried again while the loop runs, up to ${tries} times in all`);
|
|
127
|
+
// How many times the first row still to deliver has been tried: once, in the pass above.
|
|
128
|
+
let tried = 1;
|
|
129
|
+
for (let wait = REPLAY_RETRY_FIRST_MS; failed.length > 0 && !ended; wait = Math.min(wait * 2, REPLAY_RETRY_MAX_MS)) {
|
|
130
|
+
if (tried >= tries) {
|
|
131
|
+
console.warn(`[runner] ${runId}: a ${failed[0].kind} row held before its loop was chosen was tried ${tried} times and not delivered (${why()}); it and the ${failed.length - 1} after it are left untaken, for the run's next claim`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let timer;
|
|
135
|
+
await Promise.race([loopEnded, new Promise((resolve) => (timer = setTimeout(resolve, wait)))]);
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
if (ended)
|
|
138
|
+
break;
|
|
139
|
+
// The first row again; once it goes through, the rows after it at once, in order, until one throws.
|
|
140
|
+
while (failed.length > 0 && !ended) {
|
|
141
|
+
tried += 1;
|
|
142
|
+
if (!(await delivers(failed[0])))
|
|
143
|
+
break;
|
|
144
|
+
failed.shift();
|
|
145
|
+
// Every row left was tried once in the first pass.
|
|
146
|
+
tried = 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
75
149
|
}
|
|
76
150
|
return {
|
|
77
151
|
start(claim) {
|
|
@@ -10,12 +10,18 @@ export declare const reflectRequestId: (runId: string, again?: boolean) => strin
|
|
|
10
10
|
* is answered from its submission, never asked of the model twice. */
|
|
11
11
|
export declare const REFLECT_AGAIN = ":again";
|
|
12
12
|
/** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
|
|
13
|
-
* turn's request id;
|
|
14
|
-
*
|
|
13
|
+
* turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
|
|
14
|
+
* adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
|
|
15
|
+
* its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
|
|
16
|
+
* end, is the turn's (the server's labelled: after the entry before it). */
|
|
15
17
|
export declare function reflectFrom(submissions: readonly {
|
|
16
18
|
readonly type?: string;
|
|
17
19
|
readonly requestId?: string;
|
|
18
20
|
readonly entry?: unknown;
|
|
21
|
+
}[], entries?: readonly {
|
|
22
|
+
readonly kind?: string;
|
|
23
|
+
readonly id?: unknown;
|
|
24
|
+
readonly data?: unknown;
|
|
19
25
|
}[]): number | undefined;
|
|
20
26
|
/** The refusal of the end-of-run turn's write or edit under work/.learning/: the tool gate's one text (NOTE_ONLY_TEXT), so
|
|
21
27
|
* the adapter loop's refusal and the gate's are the same words. */
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// answer's note blocks, never from a file it writes there. The words and the rule are the tool gate's own
|
|
4
4
|
// (tool-gate.ts NOTE_ONLY_TEXT, underLearning), kept equal by a test.
|
|
5
5
|
import { posix, resolve, sep, join } from "node:path";
|
|
6
|
+
import { KINDS } from "./journal-kinds.js";
|
|
6
7
|
/** The prefix of the end-of-run turn's request id: the server's own (turns.ts REFLECT_REQUEST). */
|
|
7
8
|
export const REFLECT_PREFIX = "learn-reflect-";
|
|
8
9
|
/** The label a reader puts on the end-of-run turn's rows and messages: the server's (learning.ts LEARNING_LABEL). */
|
|
@@ -15,11 +16,16 @@ export const reflectRequestId = (runId, again = false) => `${REFLECT_PREFIX}${ru
|
|
|
15
16
|
* is answered from its submission, never asked of the model twice. */
|
|
16
17
|
export const REFLECT_AGAIN = ":again";
|
|
17
18
|
/** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
|
|
18
|
-
* turn's request id;
|
|
19
|
-
*
|
|
20
|
-
|
|
19
|
+
* turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
|
|
20
|
+
* adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
|
|
21
|
+
* its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
|
|
22
|
+
* end, is the turn's (the server's labelled: after the entry before it). */
|
|
23
|
+
export function reflectFrom(submissions, entries = []) {
|
|
21
24
|
const placed = submissions.filter((record) => record.type === "input" && typeof record.requestId === "string" && record.requestId.startsWith(REFLECT_PREFIX) && record.entry !== undefined);
|
|
22
|
-
|
|
25
|
+
if (placed.length)
|
|
26
|
+
return Math.min(...placed.map((record) => Number(record.entry)));
|
|
27
|
+
const asked = entries.find((entry) => entry.kind === KINDS.endOfRunTurn && entry.data?.role === "person");
|
|
28
|
+
return asked === undefined ? undefined : Number(asked.id);
|
|
23
29
|
}
|
|
24
30
|
/** The refusal of the end-of-run turn's write or edit under work/.learning/: the tool gate's one text (NOTE_ONLY_TEXT), so
|
|
25
31
|
* the adapter loop's refusal and the gate's are the same words. */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// sealed-settings-store.ts writes them), opened here with the runner's seal key and held only in the bound mint's closure.
|
|
5
5
|
// No App (never connected, disconnected, or rows that do not open under this key): no access, and such a server's calls
|
|
6
6
|
// are refused in words (GITHUB_UNUSABLE.noAccess).
|
|
7
|
-
import { unseal } from "
|
|
7
|
+
import { unseal } from "../sealing.js";
|
|
8
8
|
import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubTargetOf, mintInstallationToken } from "../github.js";
|
|
9
9
|
import { isObject } from "../validate.js";
|
|
10
10
|
const ADAPTER = "github";
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { RunLaunch } from "../run-launch.js";
|
|
2
2
|
import { type AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
3
|
+
import { type GradeRouteAsk } from "./learning-dispatch.js";
|
|
4
|
+
import type { GraderRoute } from "./learning-ask.js";
|
|
3
5
|
import type { LoopFactory } from "./loop-contract.js";
|
|
4
6
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
5
7
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
6
8
|
export declare function resolveRunnerLoop(deps: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
|
|
9
|
+
/** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
|
|
10
|
+
* one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
|
|
11
|
+
* is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
|
|
12
|
+
* by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
|
|
13
|
+
* the default tier. */
|
|
14
|
+
export declare function gradeRouteFor(grade: GradeRouteAsk, env: NodeJS.ProcessEnv, routeOf: AdapterSpecDeps["routeOf"]): Promise<GraderRoute>;
|
|
7
15
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
8
|
-
* dispatch (dispatch.ts) reads each run's launch and asks
|
|
16
|
+
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
9
17
|
* start and the test server pass this to startRunner. */
|
|
10
18
|
export declare function dispatchRunner(deps: AdapterSpecDeps): LoopFactory;
|
|
@@ -38,9 +38,10 @@ export function resolveRunnerLoop(deps) {
|
|
|
38
38
|
routeOf: async (grade) => {
|
|
39
39
|
const base = deps.env ?? process.env;
|
|
40
40
|
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
41
|
-
return
|
|
41
|
+
return gradeRouteFor(grade, env, deps.routeOf);
|
|
42
42
|
},
|
|
43
43
|
...(deps.log ? { log: deps.log } : {}),
|
|
44
|
+
...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
// The harness's own entry decides which spec builds the run, by the entry's facts and never the harness's name: an entry
|
|
@@ -59,8 +60,20 @@ export function resolveRunnerLoop(deps) {
|
|
|
59
60
|
return undefined;
|
|
60
61
|
};
|
|
61
62
|
}
|
|
63
|
+
/** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
|
|
64
|
+
* one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
|
|
65
|
+
* is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
|
|
66
|
+
* by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
|
|
67
|
+
* the default tier. */
|
|
68
|
+
export function gradeRouteFor(grade, env, routeOf) {
|
|
69
|
+
return gradeRouteOf(gradeModelFor(grade), env, (model) => (grade.model !== undefined && model === grade.model
|
|
70
|
+
// The runner's environment under the grader as its strong model: every key it holds read through it, a non-enumerable
|
|
71
|
+
// one (a launcher-held or Settings key) too, which a copy would drop.
|
|
72
|
+
? routeOf(undefined, Object.create(env, { AGENT_MODEL_STRONG: { value: model, enumerable: true } }), "strong", PI_WIRES)
|
|
73
|
+
: routeOf(model, env, "default", PI_WIRES)));
|
|
74
|
+
}
|
|
62
75
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
63
|
-
* dispatch (dispatch.ts) reads each run's launch and asks
|
|
76
|
+
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
64
77
|
* start and the test server pass this to startRunner. */
|
|
65
78
|
export function dispatchRunner(deps) {
|
|
66
79
|
return createDispatchLoop({
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import type { MessageOrigin } from "
|
|
1
|
+
import type { MessageOrigin } from "../timeline/index.js";
|
|
2
|
+
/** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
|
|
3
|
+
* sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
|
|
4
|
+
* other. */
|
|
5
|
+
export declare const MESSAGE_SENT_AGAIN = "Your message was sent again after the runner restarted: it may have reached the model before, and this turn is paid again.";
|
|
2
6
|
export declare const KINDS: {
|
|
3
7
|
/** A tool call about to run: written before it runs (and before the flush that precedes a side effect). */
|
|
4
8
|
readonly callStart: "agentrun.call.start";
|
|
9
|
+
/** A call whose start was written at its park (CallStartData.parked) is about to be sent: committed and flushed before
|
|
10
|
+
* the send, once. Only a parked call with this mark may have been sent; one without it never left. */
|
|
11
|
+
readonly callSent: "agentrun.call.sent";
|
|
5
12
|
/** How it ended: written after it ran, or by recovery for a start with no end (replay-safe reruns and ends done;
|
|
6
13
|
* any other ends interrupted, and the model is told). */
|
|
7
14
|
readonly callEnd: "agentrun.call.end";
|
|
8
15
|
/** A message: the person's, a steer, or the model's. */
|
|
9
16
|
readonly message: "agentrun.message";
|
|
17
|
+
/** A message a CLI run took mid-turn is about to be sent as a turn of its own (adapter-loop.ts sendAfterTurn): its
|
|
18
|
+
* command row's id, committed and flushed before the send. Its row is taken only after the send, so a runner lost in
|
|
19
|
+
* between leaves this mark with the row untaken: the next claim sends it again and says so (MESSAGE_SENT_AGAIN). Neither
|
|
20
|
+
* a call nor a message, so the reader passes over it. */
|
|
21
|
+
readonly messageSending: "agentrun.message.sending";
|
|
10
22
|
/** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
|
|
11
23
|
* the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
|
|
12
24
|
* reads it as any message. */
|
|
@@ -118,6 +130,9 @@ export interface CallStartData {
|
|
|
118
130
|
readonly input: unknown;
|
|
119
131
|
/** May run again after a crash (it changes nothing outside the run): the tool registry's own flag. */
|
|
120
132
|
readonly replaySafe: boolean;
|
|
133
|
+
/** Written as the call reached its gate through a CLI's own MCP client, before any answer: nothing is sent until its
|
|
134
|
+
* agentrun.call.sent mark (KINDS.callSent). */
|
|
135
|
+
readonly parked?: true;
|
|
121
136
|
/** When it was written (ms, the loop's clock): the Timeline dates the call's row by it. */
|
|
122
137
|
readonly at?: number;
|
|
123
138
|
}
|
|
@@ -166,12 +181,12 @@ export interface AskData {
|
|
|
166
181
|
/** Its approval price (the spec's approvalPrice); null when it has none. */
|
|
167
182
|
readonly price?: ApprovalPrice | null;
|
|
168
183
|
}
|
|
169
|
-
/** How an ask was answered: approved, denied,
|
|
170
|
-
export type AnswerDecision = "allow" | "deny" | "withdrawn";
|
|
184
|
+
/** How an ask was answered: approved, denied, withdrawn (a stop while the call waited) or canceled (a cancel). */
|
|
185
|
+
export type AnswerDecision = "allow" | "deny" | "withdrawn" | "canceled";
|
|
171
186
|
export interface AnswerData {
|
|
172
187
|
readonly callId: string;
|
|
173
188
|
readonly approved: boolean;
|
|
174
|
-
/** allow, deny, or
|
|
189
|
+
/** allow, deny, withdrawn or canceled: main's resolved entry. Optional for an answer written before it. */
|
|
175
190
|
readonly decision?: AnswerDecision;
|
|
176
191
|
/** When it was answered (ISO), from the loop's clock (or the runner's, for an end it writes itself). */
|
|
177
192
|
readonly answeredAt?: string;
|
|
@@ -191,12 +206,13 @@ export interface AnswerData {
|
|
|
191
206
|
/** The withdrawn answers a stopped end writes in `entries`: for every call still waiting (an ask with no answer), and
|
|
192
207
|
* for every approved call that had not finished (no result, or one its abort wrote), which the stop overrides, keeping
|
|
193
208
|
* the allow it was given (main's supersede: an answer the run had not acted on to the end is withdrawn by the stop). A
|
|
194
|
-
* call that finished before the stop keeps its allow and its result.
|
|
209
|
+
* call that finished before the stop keeps its allow and its result. `decision`: "canceled" for a cancel's end, whose
|
|
210
|
+
* calls read cancelled with their run; "withdrawn" for a stop's. */
|
|
195
211
|
export declare function withdrawnAnswers(entries: readonly {
|
|
196
212
|
readonly kind: string;
|
|
197
213
|
readonly data?: unknown;
|
|
198
214
|
readonly model?: unknown;
|
|
199
|
-
}[], answeredAt: string): AnswerData[];
|
|
215
|
+
}[], answeredAt: string, decision?: "withdrawn" | "canceled"): AnswerData[];
|
|
200
216
|
export interface EndData {
|
|
201
217
|
readonly state: "ended" | "stopped" | "failed";
|
|
202
218
|
readonly summary?: string;
|
|
@@ -215,3 +231,5 @@ export interface SessionKeyData {
|
|
|
215
231
|
/** The conversation whose entries are this session's resume log. */
|
|
216
232
|
readonly conversation: number;
|
|
217
233
|
}
|
|
234
|
+
/** The session a workflow's model requests are booked under, in its run's journal. */
|
|
235
|
+
export declare const WORKFLOW_SESSION = "workflow";
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
|
|
2
|
+
/** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
|
|
3
|
+
* sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
|
|
4
|
+
* other. */
|
|
5
|
+
export const MESSAGE_SENT_AGAIN = "Your message was sent again after the runner restarted: it may have reached the model before, and this turn is paid again.";
|
|
2
6
|
export const KINDS = {
|
|
3
7
|
/** A tool call about to run: written before it runs (and before the flush that precedes a side effect). */
|
|
4
8
|
callStart: "agentrun.call.start",
|
|
9
|
+
/** A call whose start was written at its park (CallStartData.parked) is about to be sent: committed and flushed before
|
|
10
|
+
* the send, once. Only a parked call with this mark may have been sent; one without it never left. */
|
|
11
|
+
callSent: "agentrun.call.sent",
|
|
5
12
|
/** How it ended: written after it ran, or by recovery for a start with no end (replay-safe reruns and ends done;
|
|
6
13
|
* any other ends interrupted, and the model is told). */
|
|
7
14
|
callEnd: "agentrun.call.end",
|
|
8
15
|
/** A message: the person's, a steer, or the model's. */
|
|
9
16
|
message: "agentrun.message",
|
|
17
|
+
/** A message a CLI run took mid-turn is about to be sent as a turn of its own (adapter-loop.ts sendAfterTurn): its
|
|
18
|
+
* command row's id, committed and flushed before the send. Its row is taken only after the send, so a runner lost in
|
|
19
|
+
* between leaves this mark with the row untaken: the next claim sends it again and says so (MESSAGE_SENT_AGAIN). Neither
|
|
20
|
+
* a call nor a message, so the reader passes over it. */
|
|
21
|
+
messageSending: "agentrun.message.sending",
|
|
10
22
|
/** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
|
|
11
23
|
* the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
|
|
12
24
|
* reads it as any message. */
|
|
@@ -90,8 +102,9 @@ function finished(entries, callId) {
|
|
|
90
102
|
/** The withdrawn answers a stopped end writes in `entries`: for every call still waiting (an ask with no answer), and
|
|
91
103
|
* for every approved call that had not finished (no result, or one its abort wrote), which the stop overrides, keeping
|
|
92
104
|
* the allow it was given (main's supersede: an answer the run had not acted on to the end is withdrawn by the stop). A
|
|
93
|
-
* call that finished before the stop keeps its allow and its result.
|
|
94
|
-
|
|
105
|
+
* call that finished before the stop keeps its allow and its result. `decision`: "canceled" for a cancel's end, whose
|
|
106
|
+
* calls read cancelled with their run; "withdrawn" for a stop's. */
|
|
107
|
+
export function withdrawnAnswers(entries, answeredAt, decision = "withdrawn") {
|
|
95
108
|
const answers = new Map();
|
|
96
109
|
for (const entry of entries)
|
|
97
110
|
if (entry.kind === KINDS.answer)
|
|
@@ -107,10 +120,12 @@ export function withdrawnAnswers(entries, answeredAt) {
|
|
|
107
120
|
seen.add(callId);
|
|
108
121
|
const given = answers.get(callId);
|
|
109
122
|
if (!given)
|
|
110
|
-
out.push({ callId, approved: false, decision
|
|
111
|
-
else if (given.approved && given.decision !== "withdrawn" && !finished(entries, callId)) {
|
|
112
|
-
out.push({ callId, approved: false, decision
|
|
123
|
+
out.push({ callId, approved: false, decision, answeredAt });
|
|
124
|
+
else if (given.approved && given.decision !== "withdrawn" && given.decision !== "canceled" && !finished(entries, callId)) {
|
|
125
|
+
out.push({ callId, approved: false, decision, answeredAt, superseded: { decision: "allow", ...(given.answeredAt ? { answeredAt: given.answeredAt } : {}) } });
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
128
|
return out;
|
|
116
129
|
}
|
|
130
|
+
/** The session a workflow's model requests are booked under, in its run's journal. */
|
|
131
|
+
export const WORKFLOW_SESSION = "workflow";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import { type MessageOrigin } from "
|
|
2
|
+
import { type MessageOrigin } from "../timeline/index.js";
|
|
3
3
|
import type { EntryRecord, SubmissionRecord, TaskRecord } from "@earendil-works/pi-durable";
|
|
4
4
|
import { type CallEndData, type MessageRole } from "./journal-kinds.js";
|
|
5
5
|
import type { JournalReads } from "../store/store.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { originOf } from "
|
|
1
|
+
import { originOf } from "../timeline/index.js";
|
|
2
2
|
import { reflectFrom } from "./end-of-run.js";
|
|
3
3
|
import { KINDS } from "./journal-kinds.js";
|
|
4
4
|
const PAGE = 500;
|
|
@@ -97,7 +97,7 @@ export function messagesOf(from) {
|
|
|
97
97
|
const out = [];
|
|
98
98
|
const records = asRecords(from);
|
|
99
99
|
// The end-of-run turn's, from the entry its input placed on (the reader's tag, as the server's labelled() reads it).
|
|
100
|
-
const from_ = reflectFrom(records.submissions ?? []);
|
|
100
|
+
const from_ = reflectFrom(records.submissions ?? [], records.entries);
|
|
101
101
|
const turn = (entry) => (from_ !== undefined && entry >= from_ ? { learning: true } : {});
|
|
102
102
|
for (const entry of recordOf(records.entries)) {
|
|
103
103
|
const at = entryNumber(entry);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { LearningLoopDeps } from "./learning-loop.js";
|
|
3
|
+
/** How long the ask waits, once the grade answered, for the proxy to book its request: the proxy books a request after its
|
|
4
|
+
* client has the whole answer (when the provider's stream ends, which can come later), so the spend is read once it is
|
|
5
|
+
* booked. One booked later than this reads unknown (null), never $0. */
|
|
6
|
+
export declare const GRADE_BOOKING_WAIT_MS = 10000;
|
|
3
7
|
/** The session the grader's requests are booked under, in the learning run's journal. */
|
|
4
8
|
export declare const GRADE_SESSION = "learning.grade";
|
|
5
9
|
/** Where the grader's request goes: the route's wire (`api`, Anthropic's Messages or OpenAI's Responses) at `origin`, for
|
|
@@ -13,6 +13,10 @@ import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
|
13
13
|
import { sessionProvider } from "../port-models.js";
|
|
14
14
|
import { policyFor } from "./adapters/pi.js";
|
|
15
15
|
import { journalSessions } from "./sessions.js";
|
|
16
|
+
/** How long the ask waits, once the grade answered, for the proxy to book its request: the proxy books a request after its
|
|
17
|
+
* client has the whole answer (when the provider's stream ends, which can come later), so the spend is read once it is
|
|
18
|
+
* booked. One booked later than this reads unknown (null), never $0. */
|
|
19
|
+
export const GRADE_BOOKING_WAIT_MS = 10_000;
|
|
16
20
|
/** The session the grader's requests are booked under, in the learning run's journal. */
|
|
17
21
|
export const GRADE_SESSION = "learning.grade";
|
|
18
22
|
const PROVIDER = "agentrun-grade";
|
|
@@ -40,6 +44,8 @@ export function bookedAsk(options) {
|
|
|
40
44
|
// The cap is the learning run's: asked with every session of the run summed, never this one's alone.
|
|
41
45
|
const hostCheck = options.beforeRequest ? runBooking(sessions, options.beforeRequest) : undefined;
|
|
42
46
|
let refused;
|
|
47
|
+
// Told once the grade's own request is booked (its request_end), never by a cut request booked before it.
|
|
48
|
+
let booked;
|
|
43
49
|
const booking = await modelPortFor(writer, {
|
|
44
50
|
key: GRADE_SESSION,
|
|
45
51
|
label: "grade",
|
|
@@ -53,11 +59,14 @@ export function bookedAsk(options) {
|
|
|
53
59
|
onEvent: async (event) => {
|
|
54
60
|
if (event.type === "request_start")
|
|
55
61
|
await run.flush();
|
|
62
|
+
if (event.type === "request_end")
|
|
63
|
+
booked?.();
|
|
56
64
|
},
|
|
57
65
|
});
|
|
58
66
|
// A grade request an earlier attempt sent and a crash cut is booked first, at its held figure.
|
|
59
67
|
await booking.bookCut();
|
|
60
68
|
const before = booking.spentUsd();
|
|
69
|
+
const bookedOnce = new Promise((resolve) => (booked = () => resolve(true)));
|
|
61
70
|
// The policy of the route's wire, as pi's session takes it (pi.ts policyFor: claude-agent's on Messages, codex's on
|
|
62
71
|
// Responses, no fork); the grade offers no tool.
|
|
63
72
|
const proxy = await startModelProxy({
|
|
@@ -81,7 +90,12 @@ export function bookedAsk(options) {
|
|
|
81
90
|
if (answer.stopReason === "error" || answer.stopReason === "aborted")
|
|
82
91
|
throw new Error(`the grade's request failed: ${answer.errorMessage ?? answer.stopReason}`);
|
|
83
92
|
const text = answer.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("");
|
|
84
|
-
|
|
93
|
+
// The spend once the proxy booked this request: read before, it is the spend without it ($0 for the grade). Not
|
|
94
|
+
// booked within the wait: unknown.
|
|
95
|
+
let timer;
|
|
96
|
+
const inTime = await Promise.race([bookedOnce, new Promise((resolve) => (timer = setTimeout(() => resolve(false), GRADE_BOOKING_WAIT_MS)))]);
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
const after = inTime ? booking.spentUsd() : null;
|
|
85
99
|
const usd = before === null || after === null ? null : after - before;
|
|
86
100
|
// pi-ai counts cache reads and writes apart from input, as the grade's tokens do.
|
|
87
101
|
const used = answer.usage;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TimelineEvent } from "../timeline/index.js";
|
|
2
|
+
import { type LearningFolder } from "../learn/folder.js";
|
|
2
3
|
import { type RunLaunch } from "../run-launch.js";
|
|
3
4
|
import { type SignInReader } from "../run-view.js";
|
|
4
5
|
import type { Store } from "../store/store.js";
|
|
@@ -23,9 +24,23 @@ export interface LearningEndDeps {
|
|
|
23
24
|
/** Every secret the server keeps sealed, read once at the run's end (store-secrets.ts storeSecrets over the store, the
|
|
24
25
|
* seal key and the data directory), never learned. A throw is a list that can't be read: the run learns nothing. */
|
|
25
26
|
readonly stored?: () => Promise<readonly string[]>;
|
|
26
|
-
/** The grade model the server names (learning.ts gradeModelOf); none, from `env` as the server reads it. */
|
|
27
|
-
readonly gradeModel?: string;
|
|
28
27
|
}
|
|
29
28
|
/** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
|
|
30
29
|
* does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
|
|
31
30
|
export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
|
|
31
|
+
/** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
|
|
32
|
+
* nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
|
|
33
|
+
* its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
|
|
34
|
+
* came in. Anything else is asked its end-of-run turn. */
|
|
35
|
+
export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
|
|
36
|
+
/** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
|
|
37
|
+
* no repeated job. */
|
|
38
|
+
export declare const DRAFT_SCAN_RUNS = 200;
|
|
39
|
+
/** The learned skill whose job the end-of-run turn asks for as a workflow draft: of the skills run `runId` was offered
|
|
40
|
+
* (its launch's learning start), the first in the seed's order (the one changed last first) offered to DRAFT_AFTER_RUNS
|
|
41
|
+
* or more runs of agent `agentId` started before it (each run's launch says what it was offered; its latest
|
|
42
|
+
* DRAFT_SCAN_RUNS runs are read newest first, those after `runId` in that order counted, only until every skill has its
|
|
43
|
+
* count), with no learned workflow of its name on the agent's main, active or waiting for
|
|
44
|
+
* its owner's OK (the folder's snapshot). One at most: a turn keeps one workflow draft. None when no skill qualifies, or
|
|
45
|
+
* when the folder can't be read: a read that fails asks for nothing, never a draft that may be there already. */
|
|
46
|
+
export declare function draftForOf(deps: Pick<LearningEndDeps, "store" | "learningFolder">, agentId: string, runId: string, offered: readonly string[]): Promise<string[]>;
|