@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60
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 +77 -0
- package/README.md +188 -106
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/chatgpt-plan.d.ts +4 -2
- package/dist/chatgpt-plan.js +13 -3
- package/dist/claude-login-token.d.ts +5 -0
- package/dist/claude-login-token.js +8 -0
- package/dist/claude-login.d.ts +49 -3
- package/dist/claude-login.js +140 -10
- package/dist/cli-learning/connections.js +1 -1
- package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +2 -2
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-table.d.ts +4 -0
- package/dist/harness-table.js +4 -0
- package/dist/harness.js +6 -2
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +9 -0
- package/dist/import.js +11 -1
- package/dist/key-refusal.d.ts +5 -0
- package/dist/key-refusal.js +25 -15
- package/dist/learn/audit.d.ts +20 -22
- package/dist/learn/audit.js +72 -55
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +4 -4
- package/dist/learn/compile.js +6 -7
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +40 -66
- package/dist/learn/promote.js +69 -207
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/openapi.js +89 -29
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +33 -11
- package/dist/place.js +61 -26
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +19 -4
- package/dist/redact/match.js +123 -30
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +6 -5
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-run-spec.js +11 -20
- package/dist/runner/audit.d.ts +2 -4
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +8 -14
- package/dist/runner/compare-end.d.ts +0 -2
- package/dist/runner/compare-end.js +6 -2
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +2 -3
- package/dist/runner/held.d.ts +0 -10
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +1 -1
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +3 -3
- package/dist/runner/learning-end.d.ts +12 -16
- package/dist/runner/learning-end.js +41 -75
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/native-loop.js +2 -3
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/run-child-host.d.ts +1 -9
- package/dist/runner/run-child-host.js +11 -67
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +2 -4
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +20 -7
- package/dist/sdk/runs.js +105 -68
- package/dist/secrets.d.ts +4 -0
- package/dist/secrets.js +44 -10
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +6 -0
- package/dist/server-keys.js +12 -0
- package/dist/server.d.ts +15 -15
- package/dist/server.js +214 -164
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/schema.d.ts +28 -2
- package/dist/store/schema.js +81 -5
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/store.d.ts +7 -1
- package/dist/store/sqlite/store.js +84 -18
- package/dist/store/store.d.ts +219 -6
- package/dist/store/store.js +13 -0
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +18 -22
- package/dist/store-reads/learning.js +35 -26
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +40 -11
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/tool-plane.d.ts +4 -2
- package/dist/tool-plane.js +9 -2
- package/dist/web-holds.d.ts +2 -0
- package/dist/web-holds.js +5 -2
- package/dist/web-run.js +2 -1
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-deps.js +5 -3
- package/dist/workspace/computer-providers.d.ts +11 -1
- package/dist/workspace/computer-providers.js +29 -2
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/workspace.d.ts +1 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -13
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/index-LwNL4L9q.js +0 -619
- package/dist/console/assets/styles-DQo8rzY-.css +0 -1
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
|
@@ -10,7 +10,7 @@ export declare function servedRunLearning(deps: {
|
|
|
10
10
|
}, store: Store, runId: string): Promise<{
|
|
11
11
|
run: string;
|
|
12
12
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
13
|
-
reason: "cancelled" | "reset" | "
|
|
13
|
+
reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
|
|
14
14
|
detail: string | null;
|
|
15
15
|
at: string;
|
|
16
16
|
workflows: import("./learning.js").LearnedFile[];
|
|
@@ -53,7 +53,7 @@ export declare function servedRunLearning(deps: {
|
|
|
53
53
|
};
|
|
54
54
|
run: string;
|
|
55
55
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
56
|
-
reason: "cancelled" | "reset" | "
|
|
56
|
+
reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
|
|
57
57
|
detail: string | null;
|
|
58
58
|
at: string;
|
|
59
59
|
workflows: import("./learning.js").LearnedFile[];
|
|
@@ -90,7 +90,7 @@ export declare function servedRunDiff(deps: {
|
|
|
90
90
|
signIns?: SignInReader;
|
|
91
91
|
sealKey: Buffer | undefined;
|
|
92
92
|
}, store: Store, data: string, runId: string): Promise<{
|
|
93
|
-
base: string;
|
|
93
|
+
base: string | null;
|
|
94
94
|
head: string;
|
|
95
95
|
files: ({
|
|
96
96
|
path: string;
|
|
@@ -31,5 +31,5 @@ export async function servedRunLearning(deps, store, runId) {
|
|
|
31
31
|
/** Run `runId`'s learning diff as GET /runs/{id}/learning/diff serves it (learning-routes.ts runDiffOverStore), cut as its
|
|
32
32
|
* learning is, or ApiError forbidden for a withheld run. */
|
|
33
33
|
export async function servedRunDiff(deps, store, data, runId) {
|
|
34
|
-
return runDiffOverStore(
|
|
34
|
+
return runDiffOverStore(store, runId, secretsShown(await learningCutOf(deps, store, runId)));
|
|
35
35
|
}
|
package/dist/run-listing.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface Lister {
|
|
|
19
19
|
/** The server's keys or settings changed: every failed run's listing (its error words) is marked behind before this
|
|
20
20
|
* resolves, so the next list builds it again. */
|
|
21
21
|
keysChanged(): Promise<void>;
|
|
22
|
-
/** A person changed agent `agentId`'s learning
|
|
22
|
+
/** A person changed agent `agentId`'s learning (a workflow approved, retired or restored): each of its runs
|
|
23
23
|
* whose listing read a workflow held for the owner's OK is marked behind before this resolves, so the next list says what
|
|
24
24
|
* the folder says now. A change made outside the server is read by the next pass. */
|
|
25
25
|
learningChanged(agentId: string): Promise<void>;
|
|
@@ -10,7 +10,7 @@ export type ServedTimelineDeps = {
|
|
|
10
10
|
readonly sealKey: Buffer | undefined;
|
|
11
11
|
/** The environment a run's model key is read from, with the keys a person saved (withSecrets, as main's plainKey). */
|
|
12
12
|
readonly keyEnv: () => NodeJS.ProcessEnv;
|
|
13
|
-
/** Each learned item's status on an agent's learning
|
|
13
|
+
/** Each learned item's status on an agent's newest learning save (learning-routes.ts statusesOf): what a run held for
|
|
14
14
|
* its owner's OK reads as it stands there. None: as the merge wrote it. */
|
|
15
15
|
readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
|
|
16
16
|
};
|
|
@@ -3,7 +3,7 @@ import { withDecisions } from "./decision-rows.js";
|
|
|
3
3
|
import { currentLearning, holdsForOk, secretsShown } from "./learning.js";
|
|
4
4
|
import { withLearning } from "./learning-run.js";
|
|
5
5
|
import { runLearningEnd } from "./store-reads/learning.js";
|
|
6
|
-
import { heldNumber,
|
|
6
|
+
import { heldNumber, redactedCall } from "./key-refusal.js";
|
|
7
7
|
import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
|
|
8
8
|
import { answersOf, asksOf, shownOf, stopAsked, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
|
|
9
9
|
import { launchOf } from "./handed-values.js";
|
|
@@ -11,7 +11,7 @@ import { capNowOf } from "./runner/journal-kinds.js";
|
|
|
11
11
|
import { journalRecords } from "./runner/journal-reader.js";
|
|
12
12
|
import { decisionsOverStore } from "./store-reads/decisions.js";
|
|
13
13
|
import { readRun } from "./store-reads/runs.js";
|
|
14
|
-
import { runTimeline, servedSince, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
|
|
14
|
+
import { rowCutsOnce, runTimeline, servedSince, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
|
|
15
15
|
import { FINAL_STATES } from "./store/store.js";
|
|
16
16
|
/** Run `runId`'s Timeline rows as served: cut by its one cut set, its decision rows among them, its error rows in the
|
|
17
17
|
* run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output whole to
|
|
@@ -27,7 +27,8 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
|
|
|
27
27
|
if (cut === "unreadable")
|
|
28
28
|
return undefined;
|
|
29
29
|
const { values } = cut;
|
|
30
|
-
|
|
30
|
+
// Each text cut once per held value set (rowCutsOnce): a reader that follows the run cuts only what an earlier read had not.
|
|
31
|
+
const { redact, holds } = rowCutsOnce(store, runId, cut, since);
|
|
31
32
|
return { values, redact, ...(await store.snapshot(async (snapshot) => {
|
|
32
33
|
// The rows a person reads: each call that waited for approval in order (held, your approval, what came of it), its
|
|
33
34
|
// arguments and the person's notes through the cut (run-view.ts withApprovalRows), as main's served Timeline read them.
|
|
@@ -50,7 +51,7 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
|
|
|
50
51
|
: stopAsked(view, run, await snapshot.commands(runId, 0)) ? "stopped" : undefined;
|
|
51
52
|
// A call's arguments, or a web call's output, split across two strings are withheld whole in every read, with calls
|
|
52
53
|
// or without (TimelineOptions.holds).
|
|
53
|
-
const options = { redact, holds
|
|
54
|
+
const options = { redact, holds, settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) => redactedCall(text, values, CALL_RESULT_CHARS, scrubUrls), input: (text, shown) => redactedCall(text, values, shown), held: (value) => heldNumber(value, values) } } : {}) };
|
|
54
55
|
const timeline = await wholeAnswers(snapshot, runId, context, await runTimeline(snapshot, runId, context, options), options, wholeAnswerFor(values), since);
|
|
55
56
|
// A run whose booked spend passed its cap says so, by how much, after its usage row (run-view.ts withOverCap, as main's
|
|
56
57
|
// served Timeline did): at the cap as it stands (a raise taken counts, capNowOf).
|
|
@@ -62,7 +63,7 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
|
|
|
62
63
|
// A workflow's decisions: their rows among the model nodes' by time, each text shown through the cut set, with as many
|
|
63
64
|
// characters held back from a text stored cut as a held value takes in its widest form (main's decisionShown).
|
|
64
65
|
const receipts = await decisionsOverStore(snapshot, runId, context).catch(() => null);
|
|
65
|
-
const decisionShown = { redact
|
|
66
|
+
const decisionShown = { redact, hold: 6 * values.reduce((most, value) => Math.max(most, value.length), 0) + 16 };
|
|
66
67
|
const own = receipts === null || receipts.length ? withDecisions(rows, receipts, decisionShown, { ended }) : rows;
|
|
67
68
|
// The run's learning end, once its learning merged or dropped (runLearningEnd).
|
|
68
69
|
const end = await runLearningEnd(snapshot, runId);
|
package/dist/runnable.js
CHANGED
|
@@ -11,7 +11,7 @@ import { harnessOf, onAdapter } from "./harness-table.js";
|
|
|
11
11
|
import { capShortOf } from "./cap-short.js";
|
|
12
12
|
import { chooseModel } from "./model.js";
|
|
13
13
|
import { llmTiers, MODEL_NODES, nodeTiers, unpricedModels, workflowNodes } from "./model.js";
|
|
14
|
-
import { boxAvailability, newAgentPlace, placeFix } from "./place.js";
|
|
14
|
+
import { boxAvailability, newAgentPlace, noPlaceIssue, placeFix } from "./place.js";
|
|
15
15
|
import { allows, BOUND_TOOLS, CALL_TOOLS, grantedTools, missingEnv, NODE_TOOLS, shellTools, toolOf, workflowTools } from "./tools.js";
|
|
16
16
|
import { DENIED, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
|
|
17
17
|
import { computerDenied, denyPlace, permissionFrom, permissionKeys, permissionOf } from "./tool-gate.js";
|
|
@@ -118,17 +118,30 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
118
118
|
// server's folder with the runner-only tools, which the runnerOnly check below holds to a sandbox place alone.
|
|
119
119
|
const onRunner = revision.kind === "agentic" && shellOf && (place?.mode ?? "runner") === "runner";
|
|
120
120
|
const runnerShell = onRunner && (await shellOf(revision.computer ?? { kind: "none" })) === "local" ? shellTools("local") : new Set();
|
|
121
|
-
/** A shell tool the runner does not run
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
/** A shell tool the runner does not run. One that names no place, on a runner with no shell (Mode 1), is there only
|
|
122
|
+
* because Docker's box, its default, is not here (place.ts defaultPlaceOf): it names a box or the runner, in the words
|
|
123
|
+
* its create is refused in (nameABox), never given another box. One whose place is the runner: a box this server runs in is the fix; with none, why
|
|
124
|
+
* Docker's box is not here and both ways out, fixing that or keeping the agent on the runner without the tool. Where
|
|
125
|
+
* the runner has a shell that runs others (Mode 2's Archil exec runs bash), it says which. */
|
|
124
126
|
const shellOnRunner = (tool, field, named) => {
|
|
127
|
+
const fresh = newAgentPlace(boxes);
|
|
128
|
+
if (!named && !runnerShell.size && "reason" in fresh) {
|
|
129
|
+
// A tool the box refuses (the browser) keeps this agent out of every box, so naming one is no way out: its words
|
|
130
|
+
// say that it is one tool or the other.
|
|
131
|
+
const boxless = (revision.tools ?? []).filter((one) => toolOf(one)?.runnerOnly);
|
|
132
|
+
if (!boxless.length)
|
|
133
|
+
return { ...noPlaceIssue(boxes), host: false, tool };
|
|
134
|
+
const them = new Intl.ListFormat("en", { type: "conjunction" }).format(boxless.map((one) => `"${one}"`));
|
|
135
|
+
return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${boxless.join(", ")} never ${boxless.length > 1 ? "run" : "runs"} in one, so no place runs this agent with both: remove "${tool}" from definition.tools to keep it on the runner, or remove ${them} and name a box.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool };
|
|
136
|
+
}
|
|
125
137
|
const where = named ? "this agent's place is the runner" : "this agent names no place, so it runs on the runner";
|
|
126
138
|
const has = runnerShell.size ? `whose shell here runs ${[...runnerShell].join(", ")} alone` : "which has no shell";
|
|
127
139
|
const box = boxAvailability(boxes).find((b) => b.available);
|
|
128
140
|
if (box)
|
|
129
141
|
return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${where}, ${has}: give it a sandbox computer (a sandbox place).`, fix: placeFix({ mode: "sandbox", box: box.id }), host: false, tool };
|
|
130
|
-
|
|
131
|
-
|
|
142
|
+
// In Mode 2 new agents do run on the runner (placesOf), so its words say so, as they always have; in Mode 1 a new
|
|
143
|
+
// agent names its place, so they say only why Docker's box is not here.
|
|
144
|
+
const why = "why" in fresh ? `${runnerShell.size ? "new agents run on the runner, because " : ""}the docker box is unavailable here: ${fresh.why}` : "no box runs execute in is available here";
|
|
132
145
|
return { field, reason: "not_an_option", message: `${tool} runs only in a box, and ${where}, ${has} (${runnerShell.size ? tool : "a shell"} needs a sandbox computer), and ${why}. Do that, or keep this agent on the runner: name "place": {"mode": "runner"} and remove "${tool}" from definition.tools.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool };
|
|
133
146
|
};
|
|
134
147
|
// A harness's own MCP client may drop or retype a shape of a tool's schema (its facts' schemaProblems, measured on its
|
|
@@ -199,8 +212,12 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
199
212
|
if (!allows(BOUND_TOOLS, tool))
|
|
200
213
|
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} is not a tool here: grant one of ${BOUND_TOOLS.join(", ")}, an MCP server's tool as mcp:<server>/<tool>, or a monid endpoint as monid:<provider>/<endpoint>.`, host: false, tool });
|
|
201
214
|
// A shell runs in a box; on the runner (no place names one) only what its shell here runs (runnerShell).
|
|
202
|
-
|
|
203
|
-
|
|
215
|
+
// One that names no place is refused at its place, once, whatever shell tools it names.
|
|
216
|
+
else if (toolOf(tool).sandboxOnly && (place?.mode ?? "runner") === "runner" && !runnerShell.has(tool)) {
|
|
217
|
+
const blocker = shellOnRunner(tool, `definition.tools[${index}]`, !!place && !revision.unnamed);
|
|
218
|
+
if (!out.some((b) => b.field === "definition.place" && b.message === blocker.message))
|
|
219
|
+
out.push(blocker);
|
|
220
|
+
}
|
|
204
221
|
// Its writes into work/ go by path from this machine, and a box's command could swap a link in on their way.
|
|
205
222
|
else if (toolOf(tool).runnerOnly && place?.mode === "sandbox")
|
|
206
223
|
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} does not run in a sandbox place yet: it saves files into the run's work/ from this server, outside the box, and a command in the box could point those writes elsewhere on this server. Give it to an agent whose place is the runner.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool });
|
|
@@ -36,9 +36,8 @@ import { withheldWhole } from "../key-refusal.js";
|
|
|
36
36
|
import { environmentLine, runZone } from "../environment.js";
|
|
37
37
|
import { effortGuidance } from "../effort-guidance.js";
|
|
38
38
|
import { outputContract } from "../answer-json.js";
|
|
39
|
-
import { laidLearned,
|
|
39
|
+
import { laidLearned, secretsShown } from "../learning.js";
|
|
40
40
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
41
|
-
import { learningWorkspace } from "../learn/folder.js";
|
|
42
41
|
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
43
42
|
import { learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpCalls, learnedWorkflowTool } from "../learned-workflow.js";
|
|
44
43
|
import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
|
|
@@ -445,15 +444,12 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
445
444
|
// setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
|
|
446
445
|
const kindSkills = movedProject ? [] : await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
|
|
447
446
|
const currentSkills = movedProject ? await movedSkillFiles(ws.workspace, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : [...Object.keys(body.skills ?? {}), ...kindSkills];
|
|
448
|
-
// A learning run's seed, read once from its
|
|
449
|
-
//
|
|
450
|
-
//
|
|
451
|
-
// store's runs; a run's own process (no seal key) reads no other run, and its runner reads the seed again
|
|
452
|
-
// (learned-first.ts learnedFirstWhereHeld).
|
|
447
|
+
// A learning run's seed, read once from its agent's learning rows (runner/learning-seed.ts): its learned workflows,
|
|
448
|
+
// cut of the server's secrets, the ones its learned_workflow tool runs. Read before the run's tools are bound. A
|
|
449
|
+
// learning fault, or a seed that failed (seedFailed), gives none.
|
|
453
450
|
const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
|
|
454
|
-
const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
|
|
455
451
|
const seedLaid = start && !seedFailed(start)
|
|
456
|
-
? await layLearningSeed({ seed: start.seed,
|
|
452
|
+
? await layLearningSeed({ seed: start.seed, store: deps.store, agentId: runRow.agentId, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
|
|
457
453
|
: undefined;
|
|
458
454
|
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
|
|
459
455
|
// credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
|
|
@@ -470,7 +466,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
470
466
|
// and a call reaches it only through the session this spec returns, after `tools` is made.
|
|
471
467
|
let filedIn;
|
|
472
468
|
const hold = (values) => cut.hold(values);
|
|
473
|
-
const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, fakes?.web, launch) });
|
|
469
|
+
const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, toolSettings: body.toolSettings, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, fakes?.web, launch) });
|
|
474
470
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
475
471
|
holds.hold({ passed: mcp });
|
|
476
472
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
@@ -670,12 +666,12 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
670
666
|
// The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
|
|
671
667
|
const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
|
|
672
668
|
// None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
|
|
673
|
-
const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log,
|
|
669
|
+
const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), admitAuxiliary } : undefined;
|
|
674
670
|
// Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
|
|
675
671
|
// them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
|
|
676
672
|
// running takes none of them: it settles no audit and starts no replay run, starts on no workflow, and its tool runs
|
|
677
673
|
// none (so no learned tier is routed, below).
|
|
678
|
-
const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log,
|
|
674
|
+
const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: { reason: "held" }, workflows: [] };
|
|
679
675
|
const firstChoice = learned.choice;
|
|
680
676
|
// A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
|
|
681
677
|
// answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
|
|
@@ -744,7 +740,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
744
740
|
// The run's system prompt, as main's per-run process builds it (app.ts): the environment line first (environment.ts, as
|
|
745
741
|
// pi installs it before every other section), then the revision's instructions with what the agent learned laid in
|
|
746
742
|
// (learning.ts laidLearned, from the launch's learning start — the # Learned section decided once at launch, so the runner
|
|
747
|
-
// reads no learning
|
|
743
|
+
// reads no learning rows), its own skills through skills.ts promptOf, the output schema it answers in (answer-json.ts
|
|
748
744
|
// outputContract, the CLI spec's too), then the effort guidance (the launch's effort, never this process's environment).
|
|
749
745
|
// The one path for every harness.
|
|
750
746
|
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
@@ -801,15 +797,13 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
801
797
|
const input = await firstMessage(inputMessage(launch.input), ws.workspace);
|
|
802
798
|
// The run's end-of-run step, when it learns (learningEndOfRun from the launch's learning start; none otherwise): the
|
|
803
799
|
// compile turn and the owner's correction over the run's store, asked in the end turn while the claim is held
|
|
804
|
-
// (adapter-loop.ts stepOf)
|
|
805
|
-
// data directory, Mode 2 the agent's folder on THIS claim's Archil disk (the draft is checked against the seed on the disk, never this machine's
|
|
806
|
-
// local path) — so the end-of-run step reads the run's own Workspace, the one the run worked in.
|
|
800
|
+
// (adapter-loop.ts stepOf), its draft checked against the seed in the agent's learning rows.
|
|
807
801
|
// A replay run or an audit's shadow run learns nothing at its end: it is the promotion's, never the agent's to learn
|
|
808
802
|
// from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
|
|
809
803
|
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
810
804
|
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
811
805
|
// A held run (no audits) takes none, and its runner refuses one too (run-child-host.ts heldFor).
|
|
812
|
-
const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store,
|
|
806
|
+
const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
|
|
813
807
|
store: deps.store,
|
|
814
808
|
data: deps.data,
|
|
815
809
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -822,9 +816,6 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
822
816
|
log,
|
|
823
817
|
// A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
|
|
824
818
|
decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
|
|
825
|
-
learningFolder: archil === undefined
|
|
826
|
-
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
827
|
-
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
828
819
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
829
820
|
return {
|
|
830
821
|
adapter,
|
package/dist/runner/audit.d.ts
CHANGED
|
@@ -3,12 +3,11 @@ import type { AuxiliaryAdmitter } from "../source-sync/auxiliary.js";
|
|
|
3
3
|
import { type AuditLoop } from "../learning-setting.js";
|
|
4
4
|
import { type RunLaunch } from "../run-launch.js";
|
|
5
5
|
import { type RunRow, type Store } from "../store/store.js";
|
|
6
|
-
import { type LearningFolder } from "../learn/folder.js";
|
|
7
6
|
import type { Shown } from "../learning.js";
|
|
8
7
|
import type { EndOfRunTurn } from "./loop-contract.js";
|
|
9
8
|
import { type WorkflowFirst } from "./workflow-first.js";
|
|
10
9
|
/** What the audit reads and writes at a claim (or the server's grade): the agent, the run claimed (none for a grade),
|
|
11
|
-
* its revision (whose definition holds the numbers) and launch, the
|
|
10
|
+
* its revision (whose definition holds the numbers) and launch, the host's secrets as a
|
|
12
11
|
* hold's texts are cut of them (`shown`, as a check's are), the seal key (a shadow is handed the per_run MCP
|
|
13
12
|
* credentials its served run was). */
|
|
14
13
|
export type AuditDeps = {
|
|
@@ -16,7 +15,6 @@ export type AuditDeps = {
|
|
|
16
15
|
readonly agentId: string;
|
|
17
16
|
readonly revisionId: string;
|
|
18
17
|
readonly context: Context;
|
|
19
|
-
readonly folder: () => LearningFolder;
|
|
20
18
|
readonly shown: () => Promise<Pick<Shown, "text">>;
|
|
21
19
|
readonly log: (line: string) => void;
|
|
22
20
|
readonly sealKey?: Buffer;
|
|
@@ -36,7 +34,7 @@ export declare function auditLoopOfRevision(store: Pick<Store, "agents">, revisi
|
|
|
36
34
|
export declare function agreeOnOfRevision(store: Pick<Store, "agents">, revisionId: string): Promise<readonly string[] | undefined>;
|
|
37
35
|
/** The served answer shadow run `shadowRun` audits: its open line's `turn`'s answer, read from the served run by that row's
|
|
38
36
|
* id (what settleAudits compares the shadow's answer with); null when no open line names it, or it names no turn. */
|
|
39
|
-
export declare function auditedAnswerOf(deps: Pick<AuditDeps, "store" | "
|
|
37
|
+
export declare function auditedAnswerOf(deps: Pick<AuditDeps, "store" | "agentId" | "context">, shadowRun: string): Promise<string | null>;
|
|
40
38
|
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
41
39
|
* started them): what the promotions read counts beside the audit line. */
|
|
42
40
|
export declare function notAuditableOf(store: Pick<Store, "runs" | "settings">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
package/dist/runner/audit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The shadow audit of a serving learned workflow, at a run's claim and its end (learn/audit.ts keeps the ledger).
|
|
2
2
|
// startAudit (withAudit: at the served run's end, before the end commits): a run the promoted workflow answered (path
|
|
3
|
-
// `workflow`; a run it handed back is never drawn and never counts as served) is drawn at 1 in k (auditDrawn, from its id), and a drawn one
|
|
3
|
+
// `workflow`; a run it handed back is never drawn and never counts as served) is drawn at 1 in k (auditDrawn, from its id), and a drawn one adds a `started` audit record (with the
|
|
4
4
|
// promotion serving it and the answer it audits, `turn`: the id of the run's newest answer row now), then starts its
|
|
5
5
|
// shadow run: the same agent and revision on the same input with learning off (no seed, no compile turn), marked as the
|
|
6
6
|
// audit of the served run (launch.audit), no row of the run list, billed to the agent as learning cost. Its cap is
|
|
@@ -37,11 +37,9 @@ import { runPathOverStore } from "../store-reads/learning.js";
|
|
|
37
37
|
import { FINAL_STATES, StoreConstraint } from "../store/store.js";
|
|
38
38
|
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
39
39
|
import { isObject } from "../validate.js";
|
|
40
|
-
import {
|
|
40
|
+
import { addAuditLines, auditableLaunch, auditEveryOf, auditDrawn, auditsOffWords, auditWriterOf, holdOf, ledgerOf, lineKey, openAudits, rowsOf, shadowRunId } from "../learn/audit.js";
|
|
41
41
|
import { lastRunsOf, sinceReset } from "../learn/compile.js";
|
|
42
|
-
import { readLearning, writeLearning } from "../learn/folder.js";
|
|
43
42
|
import { CHECK_TEXT_MAX, comparedGrade, comparedOf, gradesOf, promotionOf, promotionsOf, promotionStartOf, recordPromotion, servingOf } from "../learn/promote.js";
|
|
44
|
-
import { refusedIn } from "../purged-workflow.js";
|
|
45
43
|
import { excerptShown } from "../learn/secrets.js";
|
|
46
44
|
import { auditRoomOf } from "./learning-end.js";
|
|
47
45
|
import { answerJudged, answerOf, answerRowOf } from "./promotion.js";
|
|
@@ -184,7 +182,7 @@ export async function startAudit(deps, serve) {
|
|
|
184
182
|
return;
|
|
185
183
|
if ((await readLedger(deps)).some((line) => line.run === runId && line.source === "shadow"))
|
|
186
184
|
return;
|
|
187
|
-
const promoted = promotionStartOf(await promotionsOf(store.
|
|
185
|
+
const promoted = promotionStartOf(await promotionsOf(store.learning, agentId), serve.name, serve.digest);
|
|
188
186
|
// The answer audited: the run's newest answer now, at the end that drew it, kept by its row's id so a follow-up's
|
|
189
187
|
// answer since is never the one compared.
|
|
190
188
|
const turn = turnOf((await answerRowOf(store, runId, deps.context))?.id);
|
|
@@ -215,7 +213,14 @@ export async function startAudit(deps, serve) {
|
|
|
215
213
|
audit: { of: runId, workflow: serve.name, digest: serve.digest },
|
|
216
214
|
};
|
|
217
215
|
const started = { source: "started", run: runId, shadow_run: id, workflow: serve.name, digest: serve.digest, promoted_at: promoted?.at ?? null, ...turn, at: iso((deps.now ?? Date.now)()) };
|
|
218
|
-
|
|
216
|
+
// The ledger after (`all`, never `added`): a started line already there (a crash between it and its shadow) is in it,
|
|
217
|
+
// and its shadow is made now. None there: the append refused it, as a purge took the digest since the draw (or the
|
|
218
|
+
// run), and settleAudits would never settle a shadow with no line, so none is made.
|
|
219
|
+
const { all } = await addLines(deps, [started]);
|
|
220
|
+
if (!all.some((line) => lineKey(line) === lineKey(started))) {
|
|
221
|
+
log(`workflow-first: ${serve.name} at ${serve.digest} served this run, drawn for its audit (1 in ${k}); no shadow: the workflow's version was purged since`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
219
224
|
const sealed = await handedTo(deps, runId, id);
|
|
220
225
|
try {
|
|
221
226
|
if (sourceSyncOf(revision?.body))
|
|
@@ -251,7 +256,7 @@ export async function settleAudits(deps) {
|
|
|
251
256
|
const { store, log } = deps;
|
|
252
257
|
try {
|
|
253
258
|
// An agent with no promotion record never served a learned workflow: it has no ledger to read.
|
|
254
|
-
if (!(await promotionsOf(store.
|
|
259
|
+
if (!(await promotionsOf(store.learning, deps.agentId)).length)
|
|
255
260
|
return;
|
|
256
261
|
const lines = await readLedger(deps);
|
|
257
262
|
const now = (deps.now ?? Date.now)();
|
|
@@ -305,7 +310,7 @@ export async function gradeRow(deps, run, correct, expected) {
|
|
|
305
310
|
return;
|
|
306
311
|
if ((run.disk ?? null) !== null || !(await sinceReset(deps.store, deps.agentId))(run))
|
|
307
312
|
return;
|
|
308
|
-
const promoted = promotionStartOf(await promotionsOf(deps.store.
|
|
313
|
+
const promoted = promotionStartOf(await promotionsOf(deps.store.learning, deps.agentId), m.workflow, m.workflow_digest);
|
|
309
314
|
// The answer graded: the run's newest now, kept by its row's id (as a shadow's audit keeps its turn).
|
|
310
315
|
const turn = turnOf((await answerRowOf(deps.store, run.id, deps.context))?.id);
|
|
311
316
|
const row = { run: run.id, shadow_run: null, workflow: m.workflow, digest: m.workflow_digest, promoted_at: promoted?.at ?? null, source: "grade", agreed: correct, served_cost: run.costUsd, shadow_cost: null, ...turn, at: iso((deps.now ?? Date.now)()) };
|
|
@@ -321,58 +326,30 @@ export async function gradeRow(deps, run, correct, expected) {
|
|
|
321
326
|
}, true);
|
|
322
327
|
await holdByLedger(deps, rowsOf(all));
|
|
323
328
|
}
|
|
324
|
-
/** The
|
|
325
|
-
|
|
326
|
-
const folder = deps.folder();
|
|
327
|
-
try {
|
|
328
|
-
return await readLearning(folder.workspace, ledgerOf);
|
|
329
|
-
}
|
|
330
|
-
finally {
|
|
331
|
-
await folder.end().catch(() => undefined);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
329
|
+
/** The agent's ledger (learn/audit.ts ledgerOf). */
|
|
330
|
+
const readLedger = (deps) => ledgerOf(deps.store.learning, deps.agentId);
|
|
334
331
|
/** Appends `lines` (each not in the ledger yet, lineKey; a row's verdict read by `agreed` once it is known to be new) in
|
|
335
332
|
* their order, and answers the ledger after (`all`) with the lines it appended. A grade's row (`again`) replaces an
|
|
336
333
|
* earlier grade of the same run. */
|
|
337
334
|
async function addLines(deps, lines, agreed, again = false) {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const fresh = [];
|
|
345
|
-
for (const line of lines) {
|
|
346
|
-
const key = lineKey(line);
|
|
347
|
-
if (known.has(key))
|
|
348
|
-
continue;
|
|
349
|
-
if (line.source === "started" || !agreed) {
|
|
350
|
-
fresh.push(line);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (!verdicts.has(key))
|
|
354
|
-
verdicts.set(key, await agreed(line));
|
|
355
|
-
fresh.push({ ...line, agreed: verdicts.get(key) });
|
|
356
|
-
}
|
|
357
|
-
const change = auditChange(before, fresh);
|
|
358
|
-
return { result: { all: [...before, ...change.added], added: change.added }, ...(change.change ? { change: change.change } : {}) };
|
|
359
|
-
});
|
|
360
|
-
return done.result;
|
|
361
|
-
}
|
|
362
|
-
finally {
|
|
363
|
-
await folder.end().catch(() => undefined);
|
|
335
|
+
const known = new Set(again ? [] : (await readLedger(deps)).map(lineKey));
|
|
336
|
+
const fresh = [];
|
|
337
|
+
for (const line of lines) {
|
|
338
|
+
if (known.has(lineKey(line)))
|
|
339
|
+
continue;
|
|
340
|
+
fresh.push(line.source === "started" || !agreed ? line : { ...line, agreed: await agreed(line) });
|
|
364
341
|
}
|
|
342
|
+
return addAuditLines(deps.store.learning, deps.agentId, fresh, again);
|
|
365
343
|
}
|
|
366
344
|
/** The hold rule over the ledger's rows `all` for each workflow that serves now (its champion's digest, skipping a
|
|
367
|
-
*
|
|
345
|
+
* as a claim's), whether or not a row was just added:
|
|
368
346
|
* idempotent (applyHold holds only a digest whose newest record still promotes it). */
|
|
369
347
|
async function holdByLedger(deps, all) {
|
|
370
348
|
if (!all.length)
|
|
371
349
|
return;
|
|
372
350
|
const loop = await auditLoopOfRevision(deps.store, deps.revisionId);
|
|
373
|
-
const records = await promotionsOf(deps.store.
|
|
374
|
-
const
|
|
375
|
-
for (const { workflow, digest } of servingOf(records, refused)) {
|
|
351
|
+
const records = await promotionsOf(deps.store.learning, deps.agentId);
|
|
352
|
+
for (const { workflow, digest } of servingOf(records)) {
|
|
376
353
|
if (digest !== null)
|
|
377
354
|
await applyHold(deps, all, loop, workflow, digest);
|
|
378
355
|
}
|
|
@@ -384,7 +361,7 @@ async function holdByLedger(deps, all) {
|
|
|
384
361
|
* one holds). */
|
|
385
362
|
async function applyHold(deps, rows, loop, workflow, digest) {
|
|
386
363
|
const { store, agentId, log } = deps;
|
|
387
|
-
const records = await promotionsOf(store.
|
|
364
|
+
const records = await promotionsOf(store.learning, agentId);
|
|
388
365
|
const current = promotionOf(records, workflow, digest);
|
|
389
366
|
if (current?.decided !== "promote")
|
|
390
367
|
return;
|
|
@@ -400,7 +377,7 @@ async function applyHold(deps, rows, loop, workflow, digest) {
|
|
|
400
377
|
const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
|
|
401
378
|
const disagreements = [];
|
|
402
379
|
// A grade's row shows the right answer its grade gave, the known answer the served one missed.
|
|
403
|
-
const grades = hold.disagreed.some((row) => row.source === "grade") ? await gradesOf(store.
|
|
380
|
+
const grades = hold.disagreed.some((row) => row.source === "grade") ? await gradesOf(store.learning, agentId) : [];
|
|
404
381
|
for (const row of hold.disagreed) {
|
|
405
382
|
const input = await store.runs.launch(row.run).then((one) => inputText(readLaunchBody(one.body)?.input ?? null), () => "");
|
|
406
383
|
// The answer the row compared (its turn's), as the verdict read it: never a follow-up's since.
|
|
@@ -416,7 +393,7 @@ async function applyHold(deps, rows, loop, workflow, digest) {
|
|
|
416
393
|
audit: { window: loop.hold_window, disagree: loop.hold_disagree, rows: hold.rows.length, disagreements, ...(stopped ? { stopped: true } : {}) },
|
|
417
394
|
...(current.commit ? { commit: current.commit } : {}),
|
|
418
395
|
};
|
|
419
|
-
const kept = await recordPromotion(store.
|
|
396
|
+
const kept = await recordPromotion(store.learning, agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
|
|
420
397
|
if (kept.won)
|
|
421
398
|
log(`workflow-first: ${workflow} at ${digest} ${stopped ? `stopped (${said}, a second hold within ${loop.stop_window} served runs)` : reason}`);
|
|
422
399
|
}
|
|
@@ -30,9 +30,8 @@ import { wireName } from "../catalog.js";
|
|
|
30
30
|
import { environmentLine, runZone } from "../environment.js";
|
|
31
31
|
import { factsOf, harnessOf, planRecipeOf } from "../harness-table.js";
|
|
32
32
|
import { layHarnessKeys, openHarnessKeys, RECIPE_SIGN_IN_PERSON_ONLY, RECIPE_TURN_PERSON_ONLY } from "../harness-keys.js";
|
|
33
|
-
import { laidLearned,
|
|
33
|
+
import { laidLearned, secretsShown } from "../learning.js";
|
|
34
34
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
35
|
-
import { learningWorkspace } from "../learn/folder.js";
|
|
36
35
|
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
37
36
|
import { ollamaTagsOf, providerModels, runModels } from "../model.js";
|
|
38
37
|
import { OLLAMA_PROVIDER } from "../ollama-provider.js";
|
|
@@ -414,7 +413,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
414
413
|
let filedIn;
|
|
415
414
|
const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
|
|
416
415
|
redact.hold(values); };
|
|
417
|
-
const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, web, launch) });
|
|
416
|
+
const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, toolSettings: body.toolSettings, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, web, launch) });
|
|
418
417
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
419
418
|
holds.hold({ passed: mcp });
|
|
420
419
|
// The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
|
|
@@ -436,9 +435,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
436
435
|
// A learning run's seed read as the pi spec reads it (runner/learning-seed.ts): its learned workflows, the ones
|
|
437
436
|
// learned_workflow runs.
|
|
438
437
|
const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
|
|
439
|
-
const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
|
|
440
438
|
const seedLaid = start && !seedFailed(start)
|
|
441
|
-
? await layLearningSeed({ seed: start.seed,
|
|
439
|
+
? await layLearningSeed({ seed: start.seed, store: deps.store, agentId: runRow.agentId, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
|
|
442
440
|
: undefined;
|
|
443
441
|
// The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
|
|
444
442
|
// It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
|
|
@@ -490,7 +488,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
490
488
|
holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
|
|
491
489
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
492
490
|
// The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
|
|
493
|
-
// learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning
|
|
491
|
+
// learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning rows), its
|
|
494
492
|
// own skills through systemOf with the harness's own check (a harness that loads skills itself keeps in the prompt only
|
|
495
493
|
// those it would refuse, and is handed the rest), the output schema it answers in (answer-json.ts outputContract, as the
|
|
496
494
|
// pi spec gives it), then the effort guidance.
|
|
@@ -713,7 +711,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
713
711
|
// The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
|
|
714
712
|
const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
|
|
715
713
|
// None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
|
|
716
|
-
const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log,
|
|
714
|
+
const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), admitAuxiliary } : undefined;
|
|
717
715
|
// A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
|
|
718
716
|
// is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
|
|
719
717
|
// None for a held run its model kept from running, whose model runs nowhere.
|
|
@@ -724,7 +722,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
724
722
|
// them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
|
|
725
723
|
// running takes none of them, as on pi: it settles no audit and starts no replay run, starts on no workflow, and its
|
|
726
724
|
// tool runs none (so no learned tier is routed, below).
|
|
727
|
-
const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log,
|
|
725
|
+
const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: { reason: "held" }, workflows: [] };
|
|
728
726
|
const firstChoice = learned.choice;
|
|
729
727
|
// A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
|
|
730
728
|
// answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
|
|
@@ -801,14 +799,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
801
799
|
// A typed input's other fields follow its content as one json block (inputMessage).
|
|
802
800
|
const input = await firstMessage(inputMessage(launch.input), ws.workspace);
|
|
803
801
|
// The run's end-of-run step, when it learns, the same as the pi spec's: the compile turn and the owner's correction over
|
|
804
|
-
// the run's store, its
|
|
805
|
-
// claim's Archil disk — so the draft is checked against the seed in the run's own Workspace, never this machine's local path.
|
|
802
|
+
// the run's store, its draft checked against the seed in the agent's learning rows.
|
|
806
803
|
// A replay run or an audit's shadow run learns nothing at its end: it is the promotion's, never the agent's to learn
|
|
807
804
|
// from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
|
|
808
805
|
// A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
|
|
809
806
|
// withAudit): at its end, so the shadow's cap is what the run's own left.
|
|
810
807
|
// A held run (no audits) takes none, as on pi.
|
|
811
|
-
const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store,
|
|
808
|
+
const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
|
|
812
809
|
store: deps.store,
|
|
813
810
|
data: deps.data,
|
|
814
811
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -821,9 +818,6 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
821
818
|
log,
|
|
822
819
|
// A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
|
|
823
820
|
decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
|
|
824
|
-
learningFolder: archil === undefined
|
|
825
|
-
? (agentId) => learningFolderOf(deps.data, agentId)
|
|
826
|
-
: (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
|
|
827
821
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
828
822
|
return {
|
|
829
823
|
adapter,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { LearningFolder } from "../learn/folder.js";
|
|
2
1
|
import { type GraderReply } from "../learn/promote.js";
|
|
3
2
|
import type { PortModels } from "../port-models.js";
|
|
4
3
|
import type { RunLaunch } from "../run-launch.js";
|
|
@@ -9,7 +8,6 @@ import type { EndOfRunTurn } from "./loop-contract.js";
|
|
|
9
8
|
export declare const GRADER = "grader";
|
|
10
9
|
export type CompareEndDeps = {
|
|
11
10
|
readonly store: Store;
|
|
12
|
-
readonly folder: () => LearningFolder;
|
|
13
11
|
readonly log: (line: string) => void;
|
|
14
12
|
readonly redact?: (text: string) => string;
|
|
15
13
|
};
|
|
@@ -29,7 +29,11 @@ async function pairOf(launch, deps, runId) {
|
|
|
29
29
|
return workflow === null || agent === null ? null : { agent, workflow, graded };
|
|
30
30
|
}
|
|
31
31
|
if (launch.audit) {
|
|
32
|
-
|
|
32
|
+
// The shadow's agent's audit ledger: the shadow run is its agent's, as the served run it audits is.
|
|
33
|
+
const agentId = (await deps.store.runs.get(runId))?.agentId;
|
|
34
|
+
if (agentId === undefined)
|
|
35
|
+
return null;
|
|
36
|
+
const [agent, workflow] = [await answerOf(deps.store, runId, BACKGROUND_CONTEXT), await auditedAnswerOf({ store: deps.store, agentId, context: BACKGROUND_CONTEXT }, runId)];
|
|
33
37
|
return workflow === null || agent === null ? null : { agent, workflow };
|
|
34
38
|
}
|
|
35
39
|
return null;
|
|
@@ -37,7 +41,7 @@ async function pairOf(launch, deps, runId) {
|
|
|
37
41
|
/** Run `of`'s newest grade as the check judges it (comparedGrade), null when it has none. */
|
|
38
42
|
async function gradeOf(store, of) {
|
|
39
43
|
const source = await store.runs.get(of);
|
|
40
|
-
return comparedGrade(source ? (await gradesOf(store.
|
|
44
|
+
return comparedGrade(source ? (await gradesOf(store.learning, source.agentId)).findLast((one) => one.run === of) : undefined);
|
|
41
45
|
}
|
|
42
46
|
/** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
|
|
43
47
|
* asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
|