@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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 +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// merge's call merges once.
|
|
14
14
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
15
15
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
16
|
+
import { GENERAL_NO_BUDGET, GENERAL_THRESHOLD, ONE_CASE } from "../learn/general.js";
|
|
16
17
|
import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
|
|
17
18
|
import { mergedNote, parseNoteFile, ruleOf } from "../learn/notes.js";
|
|
18
19
|
import { learnedPlace } from "../learn/skills.js";
|
|
@@ -26,6 +27,32 @@ export const GRADE_MAX_TOKENS = 16_000;
|
|
|
26
27
|
/** A folder the merge could not reach (the workspace or its exec down): the run parks and is retried after this, doubling
|
|
27
28
|
* per try up to the last. */
|
|
28
29
|
export const UNAVAILABLE_BACKOFF_MS = [30_000, 120_000, 600_000, 1_800_000];
|
|
30
|
+
/** A grader call its learning run's cap refused before it was sent (learning-ask.ts bookedAsk: the run's cap left, its
|
|
31
|
+
* launch's max_cost_usd): nothing of it was spent, and the grade is skipped, said so (said.noRoomToGrade), never run past
|
|
32
|
+
* the cap, never a failure. `forGood`: no room could ever send it (its spend or price unknown), not only none now. */
|
|
33
|
+
export class GradeOverCap extends Error {
|
|
34
|
+
forGood;
|
|
35
|
+
booked;
|
|
36
|
+
/** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
|
|
37
|
+
constructor(message, forGood, booked) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.forGood = forGood;
|
|
40
|
+
this.booked = booked;
|
|
41
|
+
this.name = "GradeOverCap";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** A generality check its learning run's cap refused before any of its requests left (learning-dispatch.ts general: its
|
|
45
|
+
* worst case over the cap left): nothing of it was sent or spent, and it is skipped as `unchecked` "no_budget"
|
|
46
|
+
* (GENERAL_NO_BUDGET), said so, the grader then judged against the cap on its own. `forGood`: no room could ever send it
|
|
47
|
+
* (its provider's price unknown here), not only none now. */
|
|
48
|
+
export class GeneralOverCap extends Error {
|
|
49
|
+
forGood;
|
|
50
|
+
constructor(message, forGood) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.forGood = forGood;
|
|
53
|
+
this.name = "GeneralOverCap";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
29
56
|
const ROOT = ROOT_CONVERSATION_ID;
|
|
30
57
|
/** The graded item a proposal's file is judged as (grade.ts itemOf): a draft's README.md with its workflow.json, every
|
|
31
58
|
* other file as itself. */
|
|
@@ -130,7 +157,7 @@ const itemsByFile = (verdict) => {
|
|
|
130
157
|
* the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
|
|
131
158
|
* is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
|
|
132
159
|
* README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict. */
|
|
133
|
-
export function mergeChangeOf(runId, merging, verdict, graded) {
|
|
160
|
+
export function mergeChangeOf(runId, merging, verdict, graded, round = 1) {
|
|
134
161
|
const judged = itemsByFile(verdict);
|
|
135
162
|
const notes = merging.notes.map(({ file, text }) => ({ path: file, text: mergedNote(text, { origin: judged.get(file)?.origin ?? "run" }) }));
|
|
136
163
|
const files = (merging.files ?? []).map(({ file, text }) => ({ path: file, text }));
|
|
@@ -142,7 +169,7 @@ export function mergeChangeOf(runId, merging, verdict, graded) {
|
|
|
142
169
|
// main already holds the same rule of as a note (dropped unsaid), so no old skill stays served beside its note.
|
|
143
170
|
const retire = verdict.items.flatMap((item) => (item.note && (item.keep || item.why === SAME_NOTE) && learnedPlace(item.file)?.kind === "skill" ? [{ skill: item.file, note: item.note.file, rule: ruleOfText(item.note.file, item.note.text) }] : []));
|
|
144
171
|
return {
|
|
145
|
-
kind: "merge", runId, reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
|
|
172
|
+
kind: "merge", runId, ...(round > 1 ? { round } : {}), reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
|
|
146
173
|
...(held.length ? { held } : {}), graded, ...(merging.seed ? { seed: merging.seed } : {}), ...(retire.length ? { retire } : {}),
|
|
147
174
|
};
|
|
148
175
|
}
|
|
@@ -278,7 +305,8 @@ export function createLearningLoop(learning) {
|
|
|
278
305
|
await append(KINDS.learningDropped, { source: "", reason: "no_source", detail: said.stopped(STOPPED.notChecked) }, "failed");
|
|
279
306
|
return { state: "failed", error: { code: "learning_no_source", message: "the learning run names no run that learned" } };
|
|
280
307
|
}
|
|
281
|
-
const
|
|
308
|
+
const round = source.round ?? 1;
|
|
309
|
+
const kept = await learning.proposal(source.runId, round);
|
|
282
310
|
if (!kept) {
|
|
283
311
|
await append(KINDS.learningDropped, { source: source.runId, reason: "no_proposal", detail: said.stopped(STOPPED.notChecked) }, "ended");
|
|
284
312
|
return { state: "ended" };
|
|
@@ -311,22 +339,131 @@ export function createLearningLoop(learning) {
|
|
|
311
339
|
// A note named like one main holds now is settled alone, out of the grade (readMain's `taken`); the rest is
|
|
312
340
|
// graded. Nothing left to grade keeps nothing.
|
|
313
341
|
const taken = new Map((main.taken ?? []).map(({ path, reason }) => [path, reason]));
|
|
314
|
-
|
|
342
|
+
let grading = proposal.notes.filter(({ file }) => !taken.has(file));
|
|
315
343
|
const settledItems = [...taken].map(([file, reason]) => ({ file, keep: false, question: "Duplicate", why: reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, "")) }));
|
|
344
|
+
// What the grader spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
|
|
345
|
+
// added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
|
|
346
|
+
let usd = 0;
|
|
347
|
+
let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
|
|
348
|
+
// What the generality pre-check's Jev requests spent (its kept dollars, null once unknown), outside the
|
|
349
|
+
// grader's records, and the most they may have spent (`beside`: those dollars, else their worst case), which
|
|
350
|
+
// each grader call's room under the cap leaves out. The grade ends with both: Jev's and the grader's.
|
|
351
|
+
let checkUsd = 0;
|
|
352
|
+
let beside = 0;
|
|
353
|
+
const spent = () => (checkUsd === null || usd === null ? null : checkUsd + usd);
|
|
354
|
+
// The generality pre-check: a note Jev scores under the bar rests on its one input, and is dropped before the
|
|
355
|
+
// grader reads it, its why said with the grader's items. Jev down or not set up here: every note is graded.
|
|
356
|
+
let screened = false;
|
|
357
|
+
// Why the check could not run, kept on the grade's (or the drop's) entry: never a silent skip.
|
|
358
|
+
let unchecked;
|
|
359
|
+
if (grading.length && learning.general) {
|
|
360
|
+
const threshold = learning.generalThreshold ?? GENERAL_THRESHOLD;
|
|
361
|
+
const input = proposal.asked?.[0] ?? proposal.triggered?.[0]?.text;
|
|
362
|
+
// The check is paid and Jev dedupes none, so it is made durable as the grade's ask is (learning-ask.ts
|
|
363
|
+
// bookedAsk): marked sent before its requests leave, and its end kept before the grader starts. A restart
|
|
364
|
+
// reuses a check that ended, paying nothing again; one an earlier attempt sent with no end after it was cut,
|
|
365
|
+
// what it spent is unknown (null, as a cut grade request is booked before it is asked again), and it is
|
|
366
|
+
// asked again with that unknown kept.
|
|
367
|
+
let ended = [...entries].reverse().find((entry) => entry.kind === KINDS.learningGeneral)?.data;
|
|
368
|
+
if (!ended) {
|
|
369
|
+
const sentMarks = entries.filter((entry) => entry.kind === KINDS.learningGeneralSent);
|
|
370
|
+
const cut = sentMarks.length > 0;
|
|
371
|
+
if (cut)
|
|
372
|
+
learning.log?.(`learning run ${claim.runId}: a generality check an earlier attempt sent was cut, so what it spent is unknown; it is asked again`);
|
|
373
|
+
// Under a cap: the most the cut attempts' requests may have spent (each mark's worst case), and this one's.
|
|
374
|
+
const cutHeld = sentMarks.reduce((sum, entry) => sum + (entry.data?.held ?? 0), 0);
|
|
375
|
+
let sentHeld = 0;
|
|
376
|
+
let checked;
|
|
377
|
+
let failed;
|
|
378
|
+
let overCap;
|
|
379
|
+
try {
|
|
380
|
+
checked = await learning.general(grading, { ...(source.instructions ? { job: source.instructions } : {}), ...(input !== undefined ? { input } : {}) }, AbortSignal.any([deps.signal, stopAsk.signal]), source.runId, async (held) => {
|
|
381
|
+
sentHeld += held ?? 0;
|
|
382
|
+
await append(KINDS.learningGeneralSent, { source: source.runId, ...(held !== undefined ? { held } : {}) });
|
|
383
|
+
await deps.flush();
|
|
384
|
+
}, cutHeld);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
// Cut by a stop, a lost claim or a shutdown: what it sent spent what nobody knows. A stop row ends the run
|
|
388
|
+
// stopped with that unknown; otherwise nothing more is written, and the next attempt finds it sent with no
|
|
389
|
+
// end, books it unknown and asks again.
|
|
390
|
+
if (stopped || deps.signal.aborted) {
|
|
391
|
+
spend = null;
|
|
392
|
+
return (await halted()) ?? { state: "interrupted" };
|
|
393
|
+
}
|
|
394
|
+
// No room under the run's cap for its worst case: nothing sent, skipped, said so (never silent), and the
|
|
395
|
+
// grader judged against the cap on its own.
|
|
396
|
+
if (error instanceof GeneralOverCap)
|
|
397
|
+
overCap = error;
|
|
398
|
+
else {
|
|
399
|
+
// Its requests were sent and one failed: what they spent is unknown, never 0 (as an ask that fails is).
|
|
400
|
+
// Its error is kept and logged cut of the runner's secrets (LoopDeps.redact).
|
|
401
|
+
const message = error?.message ?? String(error);
|
|
402
|
+
failed = deps.redact ? deps.redact(message) : message;
|
|
403
|
+
learning.log?.(`learning run ${claim.runId}: the generality check could not run, so the grader reads every note: ${failed}`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const held = cutHeld + sentHeld;
|
|
407
|
+
const bound = held > 0 ? { held } : {};
|
|
408
|
+
if (checked)
|
|
409
|
+
ended = { source: source.runId, scores: checked.scores, usd: cut ? null : checked.usd, ...bound };
|
|
410
|
+
else if (overCap) {
|
|
411
|
+
learning.log?.(`learning run ${claim.runId}: the generality check has no room under the cap (${overCap.message}), so the grader reads every note`);
|
|
412
|
+
ended = { source: source.runId, unchecked: GENERAL_NO_BUDGET, usd: cut ? null : 0, ...bound };
|
|
413
|
+
}
|
|
414
|
+
else if (failed !== undefined)
|
|
415
|
+
ended = { source: source.runId, unchecked: failed, usd: null, ...bound };
|
|
416
|
+
else if (cut)
|
|
417
|
+
ended = { source: source.runId, unchecked: "no Jev is set up on this host now", usd: null, ...bound };
|
|
418
|
+
// Kept, durably, before the grader starts: a restart from here on asks Jev nothing.
|
|
419
|
+
if (ended) {
|
|
420
|
+
await append(KINDS.learningGeneral, ended);
|
|
421
|
+
await deps.flush();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (ended) {
|
|
425
|
+
checkUsd = ended.usd;
|
|
426
|
+
beside = ended.usd ?? ended.held ?? 0;
|
|
427
|
+
if (ended.unchecked !== undefined)
|
|
428
|
+
unchecked = ended.unchecked;
|
|
429
|
+
if (ended.scores) {
|
|
430
|
+
screened = true;
|
|
431
|
+
const scores = ended.scores;
|
|
432
|
+
const below = grading.filter(({ file }) => typeof scores[file] === "number" && scores[file] < threshold);
|
|
433
|
+
settledItems.push(...below.map(({ file }) => ({ file, keep: false, question: "General", why: ONE_CASE(scores[file], threshold) })));
|
|
434
|
+
grading = grading.filter((note) => !below.includes(note));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
// The notes the graded ones supersede, of those main gave: a dropped note's are not the grade's.
|
|
439
|
+
const replacing = new Set(grading.flatMap((note) => { const parsed = parseNoteFile(note.file, note.text); return Array.isArray(parsed) ? [] : parsed.supersedes; }));
|
|
440
|
+
const superseded = main.superseded.filter(({ file }) => replacing.has(file));
|
|
316
441
|
if (!grading.length && !proposal.files?.length) {
|
|
317
|
-
const verdict = { merge: false, reason: "Every new note is named like one the agent holds now.", items: settledItems };
|
|
318
|
-
|
|
442
|
+
const verdict = { merge: false, reason: settledItems.some(({ question }) => question === "General") ? "No new note holds beyond the one input it came from, or each is named like one the agent holds now." : "Every new note is named like one the agent holds now.", items: settledItems };
|
|
443
|
+
// A proposal the generality check emptied is recorded as a grade (its verdict, each item's why, what the check
|
|
444
|
+
// spent) before it is dropped, so the run's learning reads why each note was left out.
|
|
445
|
+
if (screened)
|
|
446
|
+
await append(KINDS.learningGraded, { source: source.runId, verdict, usd: spent(), tokens, graded: main.graded });
|
|
447
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)), usd: spent(), tokens }, "ended");
|
|
319
448
|
return { state: "ended" };
|
|
320
449
|
}
|
|
321
450
|
const items = gradedItems(grading, (proposal.files ?? []));
|
|
322
451
|
const prompt = gradePrompt({
|
|
323
|
-
run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded
|
|
452
|
+
run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded, proposed: grading,
|
|
324
453
|
...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.drafted?.length ? { drafted: proposal.drafted } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}), ...(proposal.held ? { held: proposal.held } : {}),
|
|
325
454
|
});
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
455
|
+
/** The asks of this attempt that answered: the records holding more requests than these is an earlier attempt's. */
|
|
456
|
+
let answered = 0;
|
|
457
|
+
// Once an ask read the grade's records (`booked`), its dollars are theirs: an earlier attempt's requests counted too.
|
|
458
|
+
const fromRecords = (booked) => {
|
|
459
|
+
if (!booked)
|
|
460
|
+
return;
|
|
461
|
+
usd = booked.usd;
|
|
462
|
+
// A request an earlier attempt sent (a restart before the grade was saved): its dollars are in the records,
|
|
463
|
+
// its tokens in nothing this attempt read, so they are unknown, never none.
|
|
464
|
+
if (booked.turns > answered)
|
|
465
|
+
tokens = null;
|
|
466
|
+
};
|
|
330
467
|
// `again`: what the grade is told after its last answer, below the same prompt.
|
|
331
468
|
const ask = async (again) => {
|
|
332
469
|
// Stopped before this ask: nothing is sent, so nothing of it is spent (what it spent stays as it was).
|
|
@@ -335,16 +472,24 @@ export function createLearningLoop(learning) {
|
|
|
335
472
|
const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
|
|
336
473
|
let answer;
|
|
337
474
|
try {
|
|
338
|
-
answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
|
|
475
|
+
answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS, ...(beside > 0 ? { beside } : {}) }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
|
|
339
476
|
}
|
|
340
477
|
catch (error) {
|
|
341
|
-
|
|
342
|
-
|
|
478
|
+
// A call the cap refused was never sent: it spent nothing, and what the grade spent before it stands, as its
|
|
479
|
+
// records hold it (an earlier attempt's included).
|
|
480
|
+
if (error instanceof GradeOverCap)
|
|
481
|
+
fromRecords(error.booked);
|
|
482
|
+
else {
|
|
483
|
+
usd = null;
|
|
484
|
+
tokens = null;
|
|
485
|
+
}
|
|
343
486
|
throw error;
|
|
344
487
|
}
|
|
488
|
+
answered += 1;
|
|
345
489
|
usd = usd === null || answer.usd === null || !Number.isFinite(answer.usd) ? null : usd + answer.usd;
|
|
346
490
|
const more = answer.tokens ?? null;
|
|
347
491
|
tokens = tokens === null || more === null ? null : { input: tokens.input + more.input, cache_read: tokens.cache_read + more.cache_read, cache_write: tokens.cache_write + more.cache_write, output: tokens.output + more.output };
|
|
492
|
+
fromRecords(answer.booked);
|
|
348
493
|
return answer.text;
|
|
349
494
|
};
|
|
350
495
|
let verdict;
|
|
@@ -362,19 +507,26 @@ export function createLearningLoop(learning) {
|
|
|
362
507
|
}
|
|
363
508
|
}
|
|
364
509
|
catch (error) {
|
|
365
|
-
// What the asks spent: a cut one's unknown (null), kept on a stopped run's row as
|
|
366
|
-
|
|
510
|
+
// What the asks spent (and the check before them): a cut one's unknown (null), kept on a stopped run's row as
|
|
511
|
+
// on a dropped one's.
|
|
512
|
+
spend = spent();
|
|
367
513
|
const end = await halted();
|
|
368
514
|
if (end)
|
|
369
515
|
return end;
|
|
370
|
-
|
|
516
|
+
// No room under the run's cap for the grade (a call the cap refused): skipped, said so, with what it spent
|
|
517
|
+
// before (an earlier ask's), never a failure and never past the cap.
|
|
518
|
+
if (error instanceof GradeOverCap) {
|
|
519
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "no_budget", detail: error.forGood ? said.gradeUncapped : said.noRoomToGrade, usd: spent(), tokens, ...(unchecked !== undefined ? { unchecked } : {}) }, "ended");
|
|
520
|
+
return { state: "ended" };
|
|
521
|
+
}
|
|
522
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd: spent(), tokens, ...(unchecked !== undefined ? { unchecked } : {}) }, "ended");
|
|
371
523
|
void error;
|
|
372
524
|
return { state: "ended" };
|
|
373
525
|
}
|
|
374
526
|
if (settledItems.length)
|
|
375
527
|
verdict = { ...verdict, items: [...verdict.items, ...settledItems] };
|
|
376
|
-
graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
|
|
377
|
-
spend = usd;
|
|
528
|
+
graded = { source: source.runId, verdict, usd: spent(), tokens, graded: main.graded, ...(unchecked !== undefined ? { unchecked } : {}) };
|
|
529
|
+
spend = graded.usd;
|
|
378
530
|
await append(KINDS.learningGraded, graded);
|
|
379
531
|
// The verdict is durable before the merge, its side effect.
|
|
380
532
|
await deps.flush();
|
|
@@ -393,7 +545,7 @@ export function createLearningLoop(learning) {
|
|
|
393
545
|
let onMain = {};
|
|
394
546
|
let already = false;
|
|
395
547
|
try {
|
|
396
|
-
const merge = await learning.merged(ws, source.runId, notePaths);
|
|
548
|
+
const merge = await learning.merged(ws, source.runId, notePaths, source.round);
|
|
397
549
|
already = merge !== undefined;
|
|
398
550
|
onMain = merge ? merge.texts : notePaths.length ? await learning.mainTexts(ws, notePaths) : {};
|
|
399
551
|
}
|
|
@@ -405,7 +557,7 @@ export function createLearningLoop(learning) {
|
|
|
405
557
|
const taken = already ? { verdict: oneItemAFile(proposal, graded.verdict), replace: [], graded: {} } : takenOnMain(proposal, graded.verdict, onMain);
|
|
406
558
|
const verdict = taken.verdict;
|
|
407
559
|
const merging = keptOf(proposal, verdict);
|
|
408
|
-
const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded });
|
|
560
|
+
const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded }, round);
|
|
409
561
|
// Nothing new left to merge: dropped, unless the grader kept a re-filed skill whose rule main already holds as a
|
|
410
562
|
// note (takenOnMain's SAME_NOTE). Its old SKILL.md is still retired (mergeChangeOf's retire), in a write of that
|
|
411
563
|
// alone, so no old skill stays served beside the note.
|
|
@@ -17,7 +17,14 @@ export interface LearningSeedLay {
|
|
|
17
17
|
readonly log: (line: string) => void;
|
|
18
18
|
/** False for a run of a revision that says `learning: "notes"`: its notes and skills are laid, never a learned workflow. */
|
|
19
19
|
readonly workflows?: false;
|
|
20
|
+
/** The notes its # Learned section names in no way, over the learning budget (the launch's `notesLeftOut`), by file:
|
|
21
|
+
* said in the run's log, so a run that read only some of what its agent learned says which it did not. */
|
|
22
|
+
readonly notesLeftOut?: readonly string[];
|
|
20
23
|
}
|
|
24
|
+
/** The most notes the log line names: past it, it says how many more. */
|
|
25
|
+
export declare const LEFT_OUT_NAMED = 100;
|
|
26
|
+
/** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
|
|
27
|
+
export declare const notesLeftOutLine: (files: readonly string[] | undefined) => string | undefined;
|
|
21
28
|
/** What the claim laid of the run's seed: the seed it read, the learned skills' files it laid, by their paths under
|
|
22
29
|
* `.agents/skills/`, for the skill list the run's harness is handed beside the revision's own, and the learned workflows
|
|
23
30
|
* the run's learned_workflow tool runs, cut of the server's secrets as the skills are (none of either when the lay
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { chooseSkills, chooseWorkflows, layLearned, LEARNED_DIR, laySkills, readerOf, seedFrom, takeSkills } from "../learning.js";
|
|
2
|
+
/** The most notes the log line names: past it, it says how many more. */
|
|
3
|
+
export const LEFT_OUT_NAMED = 100;
|
|
4
|
+
/** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
|
|
5
|
+
export const notesLeftOutLine = (files) => {
|
|
6
|
+
if (!files?.length)
|
|
7
|
+
return undefined;
|
|
8
|
+
const named = files.slice(0, LEFT_OUT_NAMED).join(", ");
|
|
9
|
+
const more = files.length > LEFT_OUT_NAMED ? `, and ${files.length - LEFT_OUT_NAMED} more` : "";
|
|
10
|
+
return `starts without ${files.length} of the notes its agent learned in its # Learned section, over the learning budget (the notes that bear most on it are given whole; the rest stay in ${LEARNED_DIR}/): ${named}${more}`;
|
|
11
|
+
};
|
|
2
12
|
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
3
13
|
/** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
|
|
4
14
|
* skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
|
|
@@ -29,6 +39,9 @@ export async function layLearningSeed(lay) {
|
|
|
29
39
|
await laySkills(lay.work, taken, made);
|
|
30
40
|
for (const path of seed.skipped)
|
|
31
41
|
lay.log(`its learning folder's ${path} was not read`);
|
|
42
|
+
const leftOut = notesLeftOutLine(lay.notesLeftOut);
|
|
43
|
+
if (leftOut)
|
|
44
|
+
lay.log(leftOut);
|
|
32
45
|
for (const name of left)
|
|
33
46
|
lay.log(`starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
|
|
34
47
|
const workflows = lay.workflows === false ? { flows: [], left: [] } : chooseWorkflows(seed, shown);
|
|
@@ -95,6 +95,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
|
|
|
95
95
|
},
|
|
96
96
|
command: (command) => loop.command(command),
|
|
97
97
|
stop: (reason) => loop.stop(reason),
|
|
98
|
+
keepsComputer: (reason) => loop.keepsComputer?.(reason) ?? false,
|
|
98
99
|
};
|
|
99
100
|
},
|
|
100
101
|
close: async () => {
|
|
@@ -34,11 +34,14 @@ export type EndOfRunTurn = (input: {
|
|
|
34
34
|
/** The run was cut before it could look back: by a person's stop (`stopped`), by one during the end-of-run turn
|
|
35
35
|
* (`stopped-looking`), or by a fault (`faulted`). The step must not call `ask`: it returns only what a cut run keeps. */
|
|
36
36
|
readonly cut?: "stopped" | "stopped-looking" | "faulted";
|
|
37
|
-
/** `again`: the turn asked once more in the same session (its first answer out of format), as its own request.
|
|
37
|
+
/** `again`: the turn asked once more in the same session (its first answer out of format), as its own request.
|
|
38
|
+
* `round`: which end of the run this is (1, its first, when absent): an end after a follow-up opened the run again is
|
|
39
|
+
* a later round, asked of the model anew under a request of its own. */
|
|
38
40
|
ask(prompt: string, opts: {
|
|
39
41
|
readonly origin: "reflect";
|
|
40
42
|
readonly deadlineMs: number;
|
|
41
43
|
readonly again?: true;
|
|
44
|
+
readonly round?: number;
|
|
42
45
|
}): Promise<EndOfRunAnswer>;
|
|
43
46
|
readonly signal: AbortSignal;
|
|
44
47
|
}) => Promise<{
|
|
@@ -121,6 +124,10 @@ export interface Loop {
|
|
|
121
124
|
command(command: Command): Promise<CommandOutcome>;
|
|
122
125
|
/** Aborts the in-flight turn; resolves once the loop will write nothing more. */
|
|
123
126
|
stop(reason: StopReason): Promise<void>;
|
|
127
|
+
/** Whether a person's stop `reason` ends only the agent, the run keeping its computer for its owner (a held computer,
|
|
128
|
+
* computer-held.ts): the runner then goes on handing it rows (the owner's calls and release) until it ends. Absent:
|
|
129
|
+
* never. */
|
|
130
|
+
keepsComputer?(reason: StopReason): boolean;
|
|
124
131
|
}
|
|
125
132
|
export interface LoopDeps {
|
|
126
133
|
/** The run's journal (store.journal(claim)) behind the runner's own fence: after a claim-lost stop, a commit is
|
package/dist/runner/loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import { type ConversationId, type EntryRecord, type StorageWrite } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { KernelHooks, ToolCall } from "./conformance/subject.js";
|
|
4
4
|
import { type Command, type HeldState, type Journal, type LoopDeps } from "./loop-contract.js";
|
|
@@ -29,6 +29,10 @@ type Expected = {
|
|
|
29
29
|
readonly run?: Staged["run"];
|
|
30
30
|
readonly also?: Staged["also"];
|
|
31
31
|
readonly take?: readonly number[];
|
|
32
|
+
readonly answer?: {
|
|
33
|
+
readonly command: number;
|
|
34
|
+
readonly value: unknown;
|
|
35
|
+
};
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* The run's journal with the loop's staging matched to commits. stage() replaces what was staged, so the loop never
|
package/dist/runner/loop.js
CHANGED
|
@@ -94,7 +94,8 @@ function merge(all) {
|
|
|
94
94
|
// call where that record's batch was refused.
|
|
95
95
|
const effect = all.find(({ expected }) => expected.run !== undefined || (expected.also ?? []).length > 0)?.at.id;
|
|
96
96
|
// Each take keyed to the record its expectation matched: the store writes it only with that record's batch.
|
|
97
|
-
|
|
97
|
+
// An answer is a value for one of the expectation's own take ids: it rides on that StagedTake.
|
|
98
|
+
const take = all.flatMap(({ expected, at }) => (expected.take ?? []).map((command) => (expected.answer?.command === command ? { command, effect: at.id, answer: expected.answer.value } : { command, effect: at.id })));
|
|
98
99
|
return { ...(run ? { run } : {}), ...(also.length ? { also } : {}), ...(effect !== undefined && (run || also.length) ? { effect } : {}), ...(take.length ? { take } : {}) };
|
|
99
100
|
}
|
|
100
101
|
/** Whether `batches` write an entry of `kind` whose data `test` accepts. */
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Store } from "../store/index.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type KeyEnv } from "../key-meta.js";
|
|
3
|
+
import { type ComputerDeps, type ComputerDepsOptions } from "../workspace/computer-deps.js";
|
|
3
4
|
import type { LoopFactory } from "./loop-contract.js";
|
|
4
5
|
import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
|
|
5
6
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
@@ -61,6 +62,17 @@ export declare function openRunnerStore(dataDir: string, env: NodeJS.ProcessEnv,
|
|
|
61
62
|
* but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
|
|
62
63
|
* a spread of the object or a spawn given it carries none. */
|
|
63
64
|
export declare function runEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
65
|
+
/** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
|
|
66
|
+
* of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
|
|
67
|
+
* runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
|
|
68
|
+
* provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
|
|
69
|
+
* --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
|
|
70
|
+
* reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
|
|
71
|
+
export declare const runnerComputers: (store: Store, env: KeyEnv, sealKey: Buffer, own?: Pick<ComputerDepsOptions, "kinds" | "load" | "dockerPaths" | "hostAddresses" | "hostWhy" | "hub">) => {
|
|
72
|
+
computerForClaim: typeof import("../workspace/computer-deps.js").claimComputer;
|
|
73
|
+
computerDeps: ComputerDeps;
|
|
74
|
+
factories: import("../computer-keys.js").ProviderFactories;
|
|
75
|
+
};
|
|
64
76
|
/** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
|
|
65
77
|
* process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
|
|
66
78
|
* run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
|
package/dist/runner/main.js
CHANGED
|
@@ -21,18 +21,23 @@ import { claimInstallsStopped } from "../harness-install.js";
|
|
|
21
21
|
import { HARNESS_TABLE_ENV } from "../harness-table.js";
|
|
22
22
|
import { maxRunsOf } from "../host.js";
|
|
23
23
|
import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
24
|
-
import { durationMs } from "../print.js";
|
|
24
|
+
import { durationMs, runLine } from "../print.js";
|
|
25
25
|
import { bootSealKey } from "../seal-key.js";
|
|
26
26
|
import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
27
27
|
import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
|
|
28
28
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
29
29
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
30
|
+
import { claimViewOpener } from "../computer-live.js";
|
|
31
|
+
import { runnerLiveOf } from "../live-reach.js";
|
|
32
|
+
import { envValue } from "../key-meta.js";
|
|
33
|
+
import { fauxComputers } from "../faux-computers.js";
|
|
30
34
|
import { computerDepsFrom } from "../workspace/computer-deps.js";
|
|
31
35
|
import { startJanitor } from "../workspace/computer-janitor.js";
|
|
32
36
|
import { createDispatchLoop } from "./dispatch.js";
|
|
33
37
|
import { resolveRunnerLoop } from "./harness-loops.js";
|
|
34
38
|
import { routeOf } from "./model-route.js";
|
|
35
39
|
import { runnerMemory } from "./memory-claim.js";
|
|
40
|
+
import { sweepEndedScratch } from "./scratch-sweep.js";
|
|
36
41
|
import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
|
|
37
42
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
38
43
|
/** A store this runner cannot use, or arguments it cannot take, in words a person starting it can act on. */
|
|
@@ -84,6 +89,15 @@ export function runEnv(env = process.env) {
|
|
|
84
89
|
}
|
|
85
90
|
return out;
|
|
86
91
|
}
|
|
92
|
+
/** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
|
|
93
|
+
* of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
|
|
94
|
+
* runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
|
|
95
|
+
* provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
|
|
96
|
+
* --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
|
|
97
|
+
* reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
|
|
98
|
+
export const runnerComputers = (store, env, sealKey, own = {}) =>
|
|
99
|
+
// A runner on another host than its server (AGENTRUN_RUNNER_LIVE_HOST): its viewers answer there (live-reach.ts).
|
|
100
|
+
computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runnerLiveOf(env, sealKey)), ...(envValue(env, FAUX_ENV) ? { faux: fauxComputers() } : {}), ...own });
|
|
87
101
|
/** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
|
|
88
102
|
* process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
|
|
89
103
|
* run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
|
|
@@ -105,13 +119,17 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
105
119
|
if (!sealKey)
|
|
106
120
|
throw new RunnerRefused(`A runner needs the server's seal key (${SEAL_KEY_ENV}): start it through the server's launcher, which hands it over.`);
|
|
107
121
|
const runs = runEnv(env);
|
|
108
|
-
// The run's computer at its claim, composed once (
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
|
|
122
|
+
// The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
|
|
123
|
+
// agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
|
|
124
|
+
// mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
|
|
125
|
+
// view opened with it.
|
|
126
|
+
const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
|
|
112
127
|
const deps = {
|
|
113
128
|
env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
|
|
114
129
|
computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
|
|
130
|
+
// A run's log lines (a learning run's skipped generality check, a sweep that failed) on the runner's stderr, as its
|
|
131
|
+
// warnings are.
|
|
132
|
+
log: (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`),
|
|
115
133
|
};
|
|
116
134
|
return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
|
|
117
135
|
}
|
|
@@ -177,6 +195,8 @@ export async function startRunnerProcess(options) {
|
|
|
177
195
|
// warnings, said where the runner says its others (warn: stderr unless a test gives its own).
|
|
178
196
|
if (options.janitor && typeof parts !== "function")
|
|
179
197
|
janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
|
|
198
|
+
// Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
|
|
199
|
+
await sweepEndedScratch(store, options.dataDir, { log: warn });
|
|
180
200
|
runner = startRunner({
|
|
181
201
|
store,
|
|
182
202
|
createLoop,
|
|
@@ -333,6 +353,8 @@ function said(name, event) {
|
|
|
333
353
|
return `Runner ${name} released ${event.runId} (${event.end})`;
|
|
334
354
|
if (event.type === "claim-lost")
|
|
335
355
|
return `Runner ${name} lost its claim on ${event.runId} (${event.why})`;
|
|
356
|
+
if (event.type === "started" || event.type === "ended")
|
|
357
|
+
return runLine(event);
|
|
336
358
|
return undefined;
|
|
337
359
|
}
|
|
338
360
|
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
|
|
@@ -27,15 +27,19 @@ export interface McpClaimOptions {
|
|
|
27
27
|
now?: () => number;
|
|
28
28
|
/** The authorization servers' network (mcp-oauth.ts). */
|
|
29
29
|
network?: OAuthNetwork;
|
|
30
|
+
/** Whether this runner may reach a loopback address (McpForClaimOptions.loopback): a refresh's request to a loopback
|
|
31
|
+
* authorization server is sent only then. Absent, never. */
|
|
32
|
+
loopback?: boolean;
|
|
30
33
|
/** For a github_app server (auth github_app, nothing sealed): the server's GitHub App mint and the run's repository
|
|
31
34
|
* (runner/mcp-github.ts). None: such a server's calls are refused in words. */
|
|
32
35
|
githubApp?: GithubAppAccess;
|
|
33
36
|
/** For tests only (no environment or CLI flag maps onto it): the one origin a github_app server may have, a fake for
|
|
34
37
|
* GitHub's hosted MCP (GITHUB_MCP_ORIGIN). */
|
|
35
38
|
githubMcpOrigin?: string;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
+
/** The run's redactors (runner/redact.ts, the spec's `cut`): every credential value this step hands the gateway (each
|
|
40
|
+
* header's value and a Bearer's bare token: a saved one, a refreshed OAuth token, a minted GitHub App token, a per_run
|
|
41
|
+
* server's handed one at the claim and at each fresh()) is held by them as it is handed over, before any call carries
|
|
42
|
+
* it. None: the gateway's per-call scrub alone. */
|
|
39
43
|
hold?: (values: string[]) => void;
|
|
40
44
|
/** For tests: the timer a github_app token's refresh and expiry are armed on. */
|
|
41
45
|
githubTimer?: GithubTimer;
|
|
@@ -50,15 +54,14 @@ export interface McpClaimStep {
|
|
|
50
54
|
/** Each pinned server's URL now, with its headers or why they can't be used: the run's gateway's `credentials`, which
|
|
51
55
|
* it reads at every request, so a refresh or a removal here reaches a gateway already built. */
|
|
52
56
|
readonly credentials: McpCredentials;
|
|
53
|
-
/** Every credential value held, for the redaction set. */
|
|
54
|
-
readonly secrets: ReadonlySet<string>;
|
|
55
57
|
/** Refresh what has expired, and open the credentials again; then confirm the claim. Before a resumed loop's next
|
|
56
58
|
* model request. */
|
|
57
59
|
fresh(): Promise<void>;
|
|
58
60
|
/** Drop every credential held: the loop ended, or the claim is lost. */
|
|
59
61
|
release(): void;
|
|
60
|
-
/** Before each call of `server` (the gateway's beforeCall):
|
|
61
|
-
*
|
|
62
|
+
/** Before each call of `server` (the gateway's beforeCall): its row stamp read (opened again when it changed or its
|
|
63
|
+
* access token near its end refreshed behind the call while still valid, waited on once run out; its entry dropped when it is no longer saved), then a github_app token
|
|
64
|
+
* whose App was disconnected or replaced since it was minted is dropped, revoked, and the call refused in words. */
|
|
62
65
|
beforeCall(server: string, signal: AbortSignal): Promise<void>;
|
|
63
66
|
}
|
|
64
67
|
/** The MCP step of `options.claim`: its pin made or read and checked, its credentials opened (refreshed as due). */
|