@parcha/agentrun-serve 0.1.0-beta.45 → 0.1.0-beta.46
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 +17 -0
- package/README.md +18 -9
- package/dist/cli.js +10 -3
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -0
- package/dist/console/index.html +2 -2
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- package/dist/learn/compile.js +2 -2
- package/dist/learn/promote.d.ts +10 -4
- package/dist/learn/promote.js +31 -2
- package/dist/learning-setting.d.ts +17 -6
- package/dist/learning-setting.js +41 -5
- package/dist/openapi.js +6 -4
- package/dist/runner/audit.js +14 -5
- package/dist/runner/conformance/harness.js +19 -8
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/main.js +20 -1
- package/dist/runner/promotion.d.ts +4 -2
- package/dist/runner/promotion.js +18 -16
- package/dist/runner/run-child-host.js +12 -4
- package/dist/server.js +4 -2
- package/dist/templates.d.ts +6 -3
- package/dist/templates.js +38 -3
- package/dist/triggers.d.ts +5 -1
- package/dist/triggers.js +2 -1
- package/dist/webhooks.d.ts +3 -1
- package/dist/webhooks.js +1 -1
- package/package.json +10 -10
- package/templates/README.md +1 -1
- package/templates/inbound-lead/agent.md +2 -1
- package/templates/kyb/agent.md +2 -1
- package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
- package/dist/console/assets/index-DaFsZuzQ.css +0 -1
package/dist/console/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>AgentRun</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-CZZeCReB.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-C2MYaUBa.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/import.d.ts
CHANGED
|
@@ -136,6 +136,13 @@ export type ImportReport = {
|
|
|
136
136
|
}[];
|
|
137
137
|
skipped: Skipped[];
|
|
138
138
|
already: number;
|
|
139
|
+
/** Each session model a new revision does not pin (no model catalog here lists it): the agent's folder, the source, the
|
|
140
|
+
* model. The agent runs on the server's default for its harness. */
|
|
141
|
+
modelsLeftOut?: {
|
|
142
|
+
cwd: string;
|
|
143
|
+
source: Source;
|
|
144
|
+
model: string;
|
|
145
|
+
}[];
|
|
139
146
|
/** Keys and tokens cut out of what it wrote (secret-cut.ts): the environment's values, the saved keys, and those of a
|
|
140
147
|
* known format secretlint found. */
|
|
141
148
|
secretsRemoved?: number;
|
|
@@ -171,6 +178,9 @@ export declare function transcriptOf(session: Session, cut: (value: unknown) =>
|
|
|
171
178
|
batches: StorageWrite[][];
|
|
172
179
|
entries: EntryLike[];
|
|
173
180
|
};
|
|
181
|
+
/** What an imported agent is told when its project has no CLAUDE.md or AGENTS.md (or the harness's own file): an agentic
|
|
182
|
+
* revision with no instructions is refused every run (runnable.ts), so an import never writes one. */
|
|
183
|
+
export declare const importedInstructions: (project: string, source: Source) => string;
|
|
174
184
|
/** The secrets this server made and keeps, by value: its API token and its sign-in sessions' secret (still files beside the
|
|
175
185
|
* store), and its webhook's signing secret (`whsec_...`; webhooks.ts) and every value a trigger source keeps sealed, as
|
|
176
186
|
* store rows (server-secrets-store.ts), opened with the seal key of `env`, which the caller has (a dry run over a store
|
package/dist/import.js
CHANGED
|
@@ -16,7 +16,7 @@ import { REQUEST_COST, runMetricsOf } from "./timeline/index.js";
|
|
|
16
16
|
import { defaultData } from "./files.js";
|
|
17
17
|
import { childFiles, HARNESS_OF, mostEffortOf, readSession, SOURCES, sessionFiles } from "./import-sources.js";
|
|
18
18
|
import { hoursOf, summaryLines } from "./import-summary.js";
|
|
19
|
-
import { catalogPrices } from "./model.js";
|
|
19
|
+
import { catalogPrices, providerModels } from "./model.js";
|
|
20
20
|
import { logLine } from "./print.js";
|
|
21
21
|
import { launchBody } from "./run-launch.js";
|
|
22
22
|
import { DEFAULT_PORT } from "./server.js";
|
|
@@ -1044,19 +1044,27 @@ async function estimateOf(entries, catalog) {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
return Math.round(total * 1e6) / 1e6;
|
|
1046
1046
|
}
|
|
1047
|
+
/** What an imported agent is told when its project has no CLAUDE.md or AGENTS.md (or the harness's own file): an agentic
|
|
1048
|
+
* revision with no instructions is refused every run (runnable.ts), so an import never writes one. */
|
|
1049
|
+
export const importedInstructions = (project, source) => `You work on the project ${project}. Your past runs are its ${SOURCE_NAMES[source]} sessions, imported. Read the project's files before you change them, and say what you changed.`;
|
|
1050
|
+
const SOURCE_NAMES = { "claude-code": "Claude Code", codex: "Codex", pi: "pi" };
|
|
1047
1051
|
/** The revision of `source`'s harness this agent keeps already (one per source, by its note), or a new one to write: its
|
|
1048
1052
|
* id, and the `NewRevision` the caller stores (through agents.create for the agent's first, agents.addRevision for the
|
|
1049
|
-
* rest). The body is built and checked here (bodyOf), its instructions and skills cut.
|
|
1050
|
-
|
|
1053
|
+
* rest). The body is built and checked here (bodyOf), its instructions and skills cut. `model`: the harness's latest
|
|
1054
|
+
* session's, kept only when a model catalog here lists it. A coding app's own model (Codex's gpt-6.1-codex) is listed by
|
|
1055
|
+
* none and runs here on no key: pinned, every run of the agent is refused. Left out, the agent runs on this server's
|
|
1056
|
+
* default for its harness, and each imported run still names the model it ran on. `project`: its name as kept (keptName). */
|
|
1057
|
+
async function revisionFor(store, agentId, source, files, model, project, cut) {
|
|
1051
1058
|
const note = `imported from ${source}`;
|
|
1052
1059
|
const held = (await store.agents.revisions(agentId)).find((r) => r.note === note);
|
|
1053
1060
|
if (held)
|
|
1054
1061
|
return { id: held.id };
|
|
1055
1062
|
const harness = HARNESS_OF[source];
|
|
1056
|
-
const
|
|
1063
|
+
const own = INSTRUCTIONS[harness].map((name) => files.instructions[name]).find((text) => text !== undefined);
|
|
1064
|
+
const instructions = own?.trim() ? cut(own) : importedInstructions(project, source);
|
|
1057
1065
|
const { body, skills } = bodyOf({
|
|
1058
1066
|
kind: "agentic",
|
|
1059
|
-
instructions
|
|
1067
|
+
instructions,
|
|
1060
1068
|
skills: keptSkills(files.skills, cut),
|
|
1061
1069
|
tools: [],
|
|
1062
1070
|
...(model ? { model } : {}),
|
|
@@ -1107,6 +1115,12 @@ export async function runImport(store, plan, options) {
|
|
|
1107
1115
|
let prices;
|
|
1108
1116
|
const catalog = () => (prices ??= catalogPrices());
|
|
1109
1117
|
const held = await importedIn(store);
|
|
1118
|
+
// Whether a model catalog here lists a session's model ("provider/model id"), keys aside: one none lists is no model to pin.
|
|
1119
|
+
let models;
|
|
1120
|
+
const inCatalog = async (ref) => {
|
|
1121
|
+
const at = ref.indexOf("/");
|
|
1122
|
+
return at > 0 && (await (models ??= providerModels(options.env))).getModel(ref.slice(0, at), ref.slice(at + 1)) !== undefined;
|
|
1123
|
+
};
|
|
1110
1124
|
// Every key of the import is known before anything of it is written.
|
|
1111
1125
|
const known = await findKeys(plan, add, text, (listed) => held.get(`${listed.source}:${listed.id}`) !== undefined, options.signal);
|
|
1112
1126
|
const scannedAs = known.stamps;
|
|
@@ -1123,13 +1137,17 @@ export async function runImport(store, plan, options) {
|
|
|
1123
1137
|
add(await secretsIn(textNow));
|
|
1124
1138
|
const byStart = [...project.sessions].sort((a, b) => (a.startedAt ?? "").localeCompare(b.startedAt ?? ""));
|
|
1125
1139
|
const latest = byStart.at(-1);
|
|
1126
|
-
// The latest session's harness names the agent's current revision; its model, each harness's latest. The
|
|
1127
|
-
// is last in the order, so it is the last revision written — created with the agent, or added current.
|
|
1140
|
+
// The latest session's harness names the agent's current revision; its model, each harness's latest a catalog lists. The
|
|
1141
|
+
// latest source is last in the order, so it is the last revision written — created with the agent, or added current.
|
|
1128
1142
|
const order = [...new Set(project.sessions.map((s) => s.source))].sort((a, b) => (a === latest.source ? 1 : 0) - (b === latest.source ? 1 : 0));
|
|
1129
1143
|
const revisions = new Map();
|
|
1130
1144
|
const toWrite = [];
|
|
1131
1145
|
for (const source of order) {
|
|
1132
|
-
const
|
|
1146
|
+
const model = byStart.findLast((s) => s.source === source && s.model)?.model;
|
|
1147
|
+
const pinned = model && (await inCatalog(model)) ? model : undefined;
|
|
1148
|
+
const resolved = await revisionFor(store, project.agentId, source, files, pinned, keptName(project, text), text);
|
|
1149
|
+
if (resolved.create && model && !pinned)
|
|
1150
|
+
(report.modelsLeftOut ??= []).push({ cwd: project.cwd, source, model });
|
|
1133
1151
|
revisions.set(source, resolved.id);
|
|
1134
1152
|
if (resolved.create)
|
|
1135
1153
|
toWrite.push(resolved.create);
|
|
@@ -1497,6 +1515,8 @@ temp = tmpdir(), env, out = console.log, } = {}) {
|
|
|
1497
1515
|
out(`${report.secretsRemoved ?? 0} secret${report.secretsRemoved === 1 ? "" : "s"} removed`);
|
|
1498
1516
|
for (const line of leftOutLines(report.skipped))
|
|
1499
1517
|
out(line);
|
|
1518
|
+
for (const { cwd, source, model } of report.modelsLeftOut ?? [])
|
|
1519
|
+
out(`model not kept: ${cwd} (${source}) ran on ${model}, which no model catalog here lists; its agent runs on the server's default model until you pick one`);
|
|
1500
1520
|
// Every session found: those imported now, those held before, and those whose file an earlier import read whole.
|
|
1501
1521
|
const held = await importedIn(store);
|
|
1502
1522
|
const runs = [...plan.projects.flatMap((p) => p.sessions.flatMap((s) => held.get(`${s.source}:${s.id}`) ?? [])), ...plan.held];
|
package/dist/learn/compile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { LEARNED_MAX_TURNS, WORKFLOW_NAME } from "./workflow-draft.js";
|
|
3
|
-
import { championOf, checkShares, promotionOf } from "./promote.js";
|
|
3
|
+
import { championOf, checkShares, fieldsWords, promotionOf } from "./promote.js";
|
|
4
4
|
import { excerptShown, redactSecrets } from "./secrets.js";
|
|
5
5
|
import { isShadowRun } from "./audit.js";
|
|
6
6
|
/** The info word that opens a workflow draft's block in a compile answer: ````workflow <name>, fenced with four backticks
|
|
@@ -380,7 +380,7 @@ function heldLine(workflow, held) {
|
|
|
380
380
|
}
|
|
381
381
|
if (check && check.n !== undefined) {
|
|
382
382
|
const shares = checkShares({ n: check.n, agreed: check.agreed ?? 0, alone: check.alone ?? 0 });
|
|
383
|
-
return `Your learned workflow \`${workflow}\` does not run first: checked on ${check.n} ${check.n === 1 ? "input" : "inputs"} of your last ${check.compile_after} completed runs, it answered ${check.alone ?? 0} alone (${pct(shares.alone)}, at least ${pct(check.alone_min)} needed), and ${check.agreed ?? 0} of those said what you said (${pct(shares.agreement)}, at least ${pct(check.agree_min)} needed).`;
|
|
383
|
+
return `Your learned workflow \`${workflow}\` does not run first: checked on ${check.n} ${check.n === 1 ? "input" : "inputs"} of your last ${check.compile_after} completed runs, it answered ${check.alone ?? 0} alone (${pct(shares.alone)}, at least ${pct(check.alone_min)} needed), and ${check.agreed ?? 0} of those said what you said${check.agree_on?.length ? ` on ${fieldsWords(check.agree_on)}` : ""} (${pct(shares.agreement)}, at least ${pct(check.agree_min)} needed).`;
|
|
384
384
|
}
|
|
385
385
|
const why = `it was held (${clean(held.reason, 400).replace(/\n/g, " ").replace(/\.$/, "")}).`;
|
|
386
386
|
return `Your learned workflow \`${workflow}\` does not run first: ${why} It stays held until a new revision of it.`;
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -103,12 +103,14 @@ export interface AuditHold {
|
|
|
103
103
|
readonly disagreements: readonly AuditDisagreement[];
|
|
104
104
|
readonly stopped?: true;
|
|
105
105
|
}
|
|
106
|
-
/** The bar a compiled draft's check was started with: the agent definition's loop numbers then (learning-setting.ts),
|
|
107
|
-
*
|
|
106
|
+
/** The bar a compiled draft's check was started with: the agent definition's loop numbers then (learning-setting.ts), the
|
|
107
|
+
* answer paths it compares on (`agree_on`, the definition's; absent, the whole answer), and which check of the compile
|
|
108
|
+
* it is (`attempt`: 1, the first draft's; 2, the one recompile's, after which it stops). */
|
|
108
109
|
export interface CheckBar {
|
|
109
110
|
readonly compile_after: number;
|
|
110
111
|
readonly agree_min: number;
|
|
111
112
|
readonly alone_min: number;
|
|
113
|
+
readonly agree_on?: readonly string[];
|
|
112
114
|
readonly attempt: 1 | 2;
|
|
113
115
|
}
|
|
114
116
|
/** One input a check's draft did not agree on: the agent's run (`run`) and its input, the agent's recorded answer
|
|
@@ -263,8 +265,12 @@ export declare function trimPromotions(items: readonly PromotionRecord[]): Promo
|
|
|
263
265
|
/** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did. A
|
|
264
266
|
* check record keeps them as it was decided on. */
|
|
265
267
|
export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;
|
|
266
|
-
/** Whether two answers say the same: equal as JSON values, else as trimmed text.
|
|
267
|
-
|
|
268
|
+
/** Whether two answers say the same: equal as JSON values, else as trimmed text. On `on` (the revision's agree_on,
|
|
269
|
+
* dotted paths into the answer's JSON object): each path resolves in both answers to equal values; a path that does
|
|
270
|
+
* not resolve in either (a key missing, a segment through an array, text or null) disagrees, on both sides too. */
|
|
271
|
+
export declare function sameAnswer(a: string | null, b: string | null, on?: readonly string[]): boolean;
|
|
272
|
+
/** The fields a check or an audit compared on, in words: "mcc", "mcc and riskTier", "mcc, riskTier and siteStatus". */
|
|
273
|
+
export declare const fieldsWords: (on: readonly string[]) => string;
|
|
268
274
|
/** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
|
|
269
275
|
export declare const gradeView: (grade: Grade) => {
|
|
270
276
|
source: "feedback" | "eval";
|
package/dist/learn/promote.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { answerJson } from "../answer-json.js";
|
|
2
|
+
import { pathSegments } from "../learning-setting.js";
|
|
2
3
|
/** How many grades, and how many promotion records, an agent keeps (newest kept). */
|
|
3
4
|
export const GRADES_KEPT = 500;
|
|
4
5
|
export const PROMOTIONS_KEPT = 200;
|
|
@@ -227,8 +228,36 @@ function same(a, b) {
|
|
|
227
228
|
const [ka, kb] = [Object.keys(a), Object.keys(b)];
|
|
228
229
|
return ka.length === kb.length && ka.every((key) => same(a[key], b[key]));
|
|
229
230
|
}
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
232
|
+
/** Not there: a path of agree_on that does not resolve in an answer. */
|
|
233
|
+
const MISSING = Symbol("missing");
|
|
234
|
+
/** The value at a dotted path (learning-setting.ts pathSegments) of a JSON value: each segment an own key of an object
|
|
235
|
+
* (never an array's index, never through text or null); MISSING when one is not. */
|
|
236
|
+
function valueAt(value, path) {
|
|
237
|
+
let here = value;
|
|
238
|
+
for (const segment of pathSegments(path)) {
|
|
239
|
+
if (!isObject(here) || !Object.hasOwn(here, segment))
|
|
240
|
+
return MISSING;
|
|
241
|
+
here = here[segment];
|
|
242
|
+
}
|
|
243
|
+
return here;
|
|
244
|
+
}
|
|
245
|
+
/** Whether two answers say the same: equal as JSON values, else as trimmed text. On `on` (the revision's agree_on,
|
|
246
|
+
* dotted paths into the answer's JSON object): each path resolves in both answers to equal values; a path that does
|
|
247
|
+
* not resolve in either (a key missing, a segment through an array, text or null) disagrees, on both sides too. */
|
|
248
|
+
export function sameAnswer(a, b, on) {
|
|
249
|
+
if (a === null || b === null)
|
|
250
|
+
return false;
|
|
251
|
+
const [va, vb] = [valueOf(a), valueOf(b)];
|
|
252
|
+
if (!on?.length)
|
|
253
|
+
return same(va, vb);
|
|
254
|
+
return on.every((path) => {
|
|
255
|
+
const [x, y] = [valueAt(va, path), valueAt(vb, path)];
|
|
256
|
+
return x !== MISSING && y !== MISSING && same(x, y);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/** The fields a check or an audit compared on, in words: "mcc", "mcc and riskTier", "mcc, riskTier and siteStatus". */
|
|
260
|
+
export const fieldsWords = (on) => (on.length < 2 ? on.join("") : `${on.slice(0, -1).join(", ")} and ${on.at(-1)}`);
|
|
232
261
|
/** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
|
|
233
262
|
export const gradeView = (grade) => ({
|
|
234
263
|
run_id: grade.run, correct: grade.correct, ...(grade.expected ? { expected: grade.expected } : {}), source: grade.source, graded_at: grade.at,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** The loop's
|
|
1
|
+
/** The loop's settings as a definition may set them (each optional: its default stands in). */
|
|
2
2
|
export interface LearningLoop {
|
|
3
3
|
readonly compile_after?: number;
|
|
4
4
|
readonly agree_min?: number;
|
|
5
5
|
readonly alone_min?: number;
|
|
6
|
+
readonly agree_on?: readonly string[];
|
|
6
7
|
readonly audit_every?: number;
|
|
7
8
|
readonly audit_every_later?: number;
|
|
8
9
|
readonly audit_later_after?: number;
|
|
@@ -10,8 +11,9 @@ export interface LearningLoop {
|
|
|
10
11
|
readonly hold_disagree?: number;
|
|
11
12
|
readonly stop_window?: number;
|
|
12
13
|
}
|
|
13
|
-
/** The check's numbers (runner/promotion.ts): what a check record keeps of the loop
|
|
14
|
-
|
|
14
|
+
/** The check's numbers (runner/promotion.ts): what a check record keeps of the loop, with the paths it compares on (the
|
|
15
|
+
* definition's agree_on; absent, the whole answer). */
|
|
16
|
+
export type CheckLoop = Required<Pick<LearningLoop, "compile_after" | "agree_min" | "alone_min">> & Pick<LearningLoop, "agree_on">;
|
|
15
17
|
/** The audit's numbers (runner/audit.ts). */
|
|
16
18
|
export type AuditLoop = Required<Pick<LearningLoop, "audit_every" | "audit_every_later" | "audit_later_after" | "hold_window" | "hold_disagree" | "stop_window">>;
|
|
17
19
|
/** A definition's `learning`, as kept on an agentic revision. */
|
|
@@ -24,15 +26,24 @@ export declare const COMPILE_AFTER_MAX = 200;
|
|
|
24
26
|
export declare const AUDIT_DEFAULTS: AuditLoop;
|
|
25
27
|
/** The most any audit number may be: 1 in 1,000 runs, a window of 1,000 (the ledger keeps more rows than that). */
|
|
26
28
|
export declare const AUDIT_MAX = 1000;
|
|
29
|
+
/** The most paths agree_on names, the most characters of each, and the most segments of each. */
|
|
30
|
+
export declare const AGREE_ON_MAX = 16;
|
|
31
|
+
export declare const AGREE_ON_PATH_MAX = 128;
|
|
32
|
+
export declare const AGREE_ON_SEGMENTS_MAX = 8;
|
|
33
|
+
/** An agree_on path's segments: each a key of an object, from the answer's top level down (a dot always splits). */
|
|
34
|
+
export declare const pathSegments: (path: string) => string[];
|
|
27
35
|
/** Whether `learning` has the agent's runs learn (true, or an object): never false or absent. */
|
|
28
36
|
export declare const learnsOf: (learning: unknown) => boolean;
|
|
29
|
-
/** The
|
|
37
|
+
/** The paths a revision's two answers are compared on: its `learning.agree_on`; undefined, the whole answer. */
|
|
38
|
+
export declare const agreeOnOf: (learning: unknown) => readonly string[] | undefined;
|
|
39
|
+
/** The loop's numbers for a revision's `learning`: its object's, each one it leaves out at its default, with its
|
|
40
|
+
* agree_on when set. */
|
|
30
41
|
export declare function loopOf(learning: unknown): CheckLoop;
|
|
31
42
|
/** The audit's numbers for a revision's `learning`: its object's, each one it leaves out at its default (AUDIT_DEFAULTS). */
|
|
32
43
|
export declare function auditLoopOf(learning: unknown): AuditLoop;
|
|
33
44
|
/** What is wrong with a definition's `learning`, in words naming the field (`at` its path), or undefined when it is one
|
|
34
45
|
* of true, false or an object of the loop's numbers. */
|
|
35
46
|
export declare function learningSettingIssue(value: unknown, at?: string): string | undefined;
|
|
36
|
-
/** A valid `learning` as a revision keeps it: an object's
|
|
37
|
-
* one body. */
|
|
47
|
+
/** A valid `learning` as a revision keeps it: an object's keys in one order, so two definitions that say the same are
|
|
48
|
+
* one body (agree_on's list as its owner gave it: its order is theirs). */
|
|
38
49
|
export declare function learningSettingOf(value: LearningSetting): LearningSetting;
|
package/dist/learning-setting.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
// hold_window, hold_disagree: it stops serving (a hold) when its last hold_window audit rows hold at least
|
|
12
12
|
// hold_disagree disagreements;
|
|
13
13
|
// stop_window: a second hold within this many served runs of the first stops it for good.
|
|
14
|
+
// Both compare two answers (learn/promote.ts sameAnswer) on agree_on, the definition's dotted paths into the answer's
|
|
15
|
+
// JSON object that say the decision (`verdict.decision`); absent, the whole answer. Nothing is read off the output
|
|
16
|
+
// schema: its enum can be an echo of the owner's setting, not the decision, and a wrong field that promotes is worse than
|
|
17
|
+
// none.
|
|
14
18
|
export const COMPILE_AFTER_DEFAULT = 20;
|
|
15
19
|
export const AGREE_MIN_DEFAULT = 0.8;
|
|
16
20
|
export const ALONE_MIN_DEFAULT = 0.7;
|
|
@@ -20,7 +24,24 @@ export const AUDIT_DEFAULTS = { audit_every: 10, audit_every_later: 20, audit_la
|
|
|
20
24
|
/** The most any audit number may be: 1 in 1,000 runs, a window of 1,000 (the ledger keeps more rows than that). */
|
|
21
25
|
export const AUDIT_MAX = 1_000;
|
|
22
26
|
const AUDIT_KEYS = ["audit_every", "audit_every_later", "audit_later_after", "hold_window", "hold_disagree", "stop_window"];
|
|
23
|
-
const LOOP_KEYS = ["compile_after", "agree_min", "alone_min", ...AUDIT_KEYS];
|
|
27
|
+
const LOOP_KEYS = ["compile_after", "agree_min", "alone_min", "agree_on", ...AUDIT_KEYS];
|
|
28
|
+
/** The most paths agree_on names, the most characters of each, and the most segments of each. */
|
|
29
|
+
export const AGREE_ON_MAX = 16;
|
|
30
|
+
export const AGREE_ON_PATH_MAX = 128;
|
|
31
|
+
export const AGREE_ON_SEGMENTS_MAX = 8;
|
|
32
|
+
/** An agree_on path's segments: each a key of an object, from the answer's top level down (a dot always splits). */
|
|
33
|
+
export const pathSegments = (path) => path.split(".");
|
|
34
|
+
/** What is wrong with one agree_on path, in words, or undefined. */
|
|
35
|
+
function pathIssue(path) {
|
|
36
|
+
if (path.length > AGREE_ON_PATH_MAX)
|
|
37
|
+
return `over ${AGREE_ON_PATH_MAX} characters`;
|
|
38
|
+
const segments = pathSegments(path);
|
|
39
|
+
if (segments.some((segment) => !segment))
|
|
40
|
+
return "an empty segment";
|
|
41
|
+
if (segments.length > AGREE_ON_SEGMENTS_MAX)
|
|
42
|
+
return `more than ${AGREE_ON_SEGMENTS_MAX} segments`;
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
24
45
|
/** Each audit number's words, for its 422. */
|
|
25
46
|
const AUDIT_WORDS = {
|
|
26
47
|
audit_every: "audits 1 in this many served runs",
|
|
@@ -33,13 +54,18 @@ const AUDIT_WORDS = {
|
|
|
33
54
|
const isLoop = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
34
55
|
/** Whether `learning` has the agent's runs learn (true, or an object): never false or absent. */
|
|
35
56
|
export const learnsOf = (learning) => learning === true || isLoop(learning);
|
|
36
|
-
/** The
|
|
57
|
+
/** The paths a revision's two answers are compared on: its `learning.agree_on`; undefined, the whole answer. */
|
|
58
|
+
export const agreeOnOf = (learning) => (isLoop(learning) && learning.agree_on?.length ? [...learning.agree_on] : undefined);
|
|
59
|
+
/** The loop's numbers for a revision's `learning`: its object's, each one it leaves out at its default, with its
|
|
60
|
+
* agree_on when set. */
|
|
37
61
|
export function loopOf(learning) {
|
|
38
62
|
const set = isLoop(learning) ? learning : {};
|
|
63
|
+
const on = agreeOnOf(learning);
|
|
39
64
|
return {
|
|
40
65
|
compile_after: set.compile_after ?? COMPILE_AFTER_DEFAULT,
|
|
41
66
|
agree_min: set.agree_min ?? AGREE_MIN_DEFAULT,
|
|
42
67
|
alone_min: set.alone_min ?? ALONE_MIN_DEFAULT,
|
|
68
|
+
...(on ? { agree_on: on } : {}),
|
|
43
69
|
};
|
|
44
70
|
}
|
|
45
71
|
/** The audit's numbers for a revision's `learning`: its object's, each one it leaves out at its default (AUDIT_DEFAULTS). */
|
|
@@ -57,6 +83,16 @@ export function learningSettingIssue(value, at = "learning") {
|
|
|
57
83
|
const other = Object.keys(value).find((key) => !LOOP_KEYS.includes(key));
|
|
58
84
|
if (other !== undefined)
|
|
59
85
|
return `${at}.${other} is not one of the loop's numbers: ${LOOP_KEYS.join(", ")}`;
|
|
86
|
+
const on = value.agree_on;
|
|
87
|
+
if (on !== undefined) {
|
|
88
|
+
if (!(Array.isArray(on) && on.length >= 1 && on.length <= AGREE_ON_MAX && on.every((one) => typeof one === "string") && new Set(on).size === on.length))
|
|
89
|
+
return `${at}.agree_on is a list of 1 to ${AGREE_ON_MAX} distinct dotted paths into the answer's JSON object (e.g. verdict.decision)`;
|
|
90
|
+
for (const [i, path] of on.entries()) {
|
|
91
|
+
const why = pathIssue(path);
|
|
92
|
+
if (why)
|
|
93
|
+
return `${at}.agree_on[${i}] is not a dotted path into the answer's JSON object (e.g. verdict.decision): ${why}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
60
96
|
const { compile_after: after, agree_min: agree, alone_min: alone } = value;
|
|
61
97
|
if (after !== undefined && !(Number.isInteger(after) && after >= 1 && after <= COMPILE_AFTER_MAX))
|
|
62
98
|
return `${at}.compile_after is a whole number of completed runs from 1 to ${COMPILE_AFTER_MAX}`;
|
|
@@ -74,10 +110,10 @@ export function learningSettingIssue(value, at = "learning") {
|
|
|
74
110
|
return `${at}.hold_disagree is at most hold_window (${audit.hold_window}): the disagreements are counted in that many rows`;
|
|
75
111
|
return undefined;
|
|
76
112
|
}
|
|
77
|
-
/** A valid `learning` as a revision keeps it: an object's
|
|
78
|
-
* one body. */
|
|
113
|
+
/** A valid `learning` as a revision keeps it: an object's keys in one order, so two definitions that say the same are
|
|
114
|
+
* one body (agree_on's list as its owner gave it: its order is theirs). */
|
|
79
115
|
export function learningSettingOf(value) {
|
|
80
116
|
if (!isLoop(value))
|
|
81
117
|
return value;
|
|
82
|
-
return Object.fromEntries(LOOP_KEYS.flatMap((key) => (value[key] !== undefined ? [[key, value[key]]] : [])));
|
|
118
|
+
return Object.fromEntries(LOOP_KEYS.flatMap((key) => (value[key] !== undefined ? [[key, key === "agree_on" ? [...value.agree_on] : value[key]]] : [])));
|
|
83
119
|
}
|
package/dist/openapi.js
CHANGED
|
@@ -1135,7 +1135,7 @@ const TEMPLATE = closed({
|
|
|
1135
1135
|
input_schema: { type: ["object", "null"], description: "What each run of its agent takes as `input`: the package's `inputs`, compiled to the JSON Schema apply sets as the agent's `input_schema`. Null: the package names none, and a run takes `{content}`." },
|
|
1136
1136
|
secrets: { type: "array", items: { type: "string" }, description: "The keys this server must have, by variable name (a saved key counts), before apply makes anything." },
|
|
1137
1137
|
budget: { type: ["object", "null"], additionalProperties: false, required: ["per_run_usd"], properties: { per_run_usd: { type: "number" } }, description: "Each run's limit: per_run_usd, its spend cap (the agent's max_cost_usd), required of a package with triggers." },
|
|
1138
|
-
learning: { type: "boolean" },
|
|
1138
|
+
learning: { oneOf: [{ type: "boolean" }, { type: "object" }], description: "The agent's `learning` as apply sets it, as an agent definition takes it: true, false, or the loop's settings (kyb's `{agree_on: [\"verdict.decision\"]}`: its check and audit compare two answers on the verdict's decision alone)." },
|
|
1139
1139
|
approvals_default: { enum: ["ask", "never"], description: "What the package recommends for the agent's approvals: `ask`, the agent asks its person before a tool runs; `never`, it runs unattended (a template whose job runs on triggers). Deny settings and pins hold either way: a pinned write can only go where its pin says." },
|
|
1140
1140
|
triggers: { type: "array", items: { type: "object" }, description: "The triggers apply makes on its agent: POST /triggers bodies with no agent_id, placeholders unfilled. A trigger's `enabled` may be `${parameters.<name>}`, a boolean parameter with a default: apply makes it on or off by that value." },
|
|
1141
1141
|
skills: { type: "array", items: { type: "string" } },
|
|
@@ -1362,8 +1362,9 @@ const PROMOTION_CHECK = closedWith({
|
|
|
1362
1362
|
alone_min: { type: "number", minimum: 0, maximum: 1, description: "The bar on answering alone: the least share of the inputs it ran on that it must answer with no escalate and no failed step." },
|
|
1363
1363
|
attempt: { enum: [1, 2], description: "1: the compile's first check. 2: the check of its one recompile, after the first held it; held again, it stops (`stopped`)." },
|
|
1364
1364
|
}, {
|
|
1365
|
+
agree_on: { type: "array", items: { type: "string" }, minItems: 1, description: "The definition's `learning.agree_on` it compared the draft's answer and the agent's on: dotted paths into the answer's JSON object, each resolving in both answers to equal values. Left out when it compared the whole answer." },
|
|
1365
1366
|
n: { ...COUNT, description: "The inputs it ran on (a replay stopped at a write is none; one never created, or not ended, by the check's deadline counts, as failed). 0 with nothing to run on: never promoted, it stops (`stopped`) and `reason` says why." },
|
|
1366
|
-
agreed: { ...COUNT, description: "How many of them it answered alone with the agent's recorded answer." },
|
|
1367
|
+
agreed: { ...COUNT, description: "How many of them it answered alone with the agent's recorded answer (compared on `agree_on` when set, else whole)." },
|
|
1367
1368
|
alone: { ...COUNT, description: "How many of them it answered alone. Promoted when `alone`/`n` >= `alone_min` and `agreed`/`alone` >= `agree_min`." },
|
|
1368
1369
|
of: { type: "array", items: { type: "string" }, description: "The agent's runs whose inputs it ran on, newest first." },
|
|
1369
1370
|
cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null when one's cost is unknown." },
|
|
@@ -2600,7 +2601,7 @@ const EXTENSIONS = {
|
|
|
2600
2601
|
},
|
|
2601
2602
|
put: {
|
|
2602
2603
|
operationId: "saveWebhook", tags: ["local"], summary: "Set the webhook's URL",
|
|
2603
|
-
description: `Messages follow the Standard Webhooks spec (standardwebhooks.com), so a receiver verifies them with any of its libraries. Each is POSTed to \`url\` as JSON \`{type, timestamp, data}\`: \`run.needs_input\` when a run comes to need its person (status input_required; \`data.pending.kind\` \`question\` for an ask_person question, \`approval\` for a tool call that waits for a person's approval, \`stopped\` for a turn a person stopped, \`budget\` for a run paused at its spend cap, \`browser\` or \`computer\` for an agent's ask for the person in its browser or on its desktop or phone: always the run read's own \`pending.kind\`; no \`pending\` when the run waits on nothing named, as when its harness ended its turn on its own) and \`run.ended\` when it ends (completed, failed or cancelled), with \`data: {run_id, agent_id, status, title, url}\`, \`url\` the run on the page; and \`trigger.failed\` when a trigger's firing could not start its run (/triggers), with \`data: {trigger_id, name, firing_key, nominal_at, error: {code, message}, auto_paused}\`, \`auto_paused\` true when it was the ${FAILURES_TO_PAUSE}th in a row and turned the trigger off, its \`webhook-id\` the same for the same firing, after a restart too
|
|
2604
|
+
description: `Messages follow the Standard Webhooks spec (standardwebhooks.com), so a receiver verifies them with any of its libraries. Each is POSTed to \`url\` as JSON \`{type, timestamp, data}\`: \`run.needs_input\` when a run comes to need its person (status input_required; \`data.pending.kind\` \`question\` for an ask_person question, \`approval\` for a tool call that waits for a person's approval, \`stopped\` for a turn a person stopped, \`budget\` for a run paused at its spend cap, \`browser\` or \`computer\` for an agent's ask for the person in its browser or on its desktop or phone: always the run read's own \`pending.kind\`; no \`pending\` when the run waits on nothing named, as when its harness ended its turn on its own) and \`run.ended\` when it ends (completed, failed or cancelled), with \`data: {run_id, agent_id, agent_name, status, title, url}\`, \`url\` the run on the page; and \`trigger.failed\` when a trigger's firing could not start its run (/triggers), with \`data: {trigger_id, name, agent_id, agent_name, firing_key, nominal_at, error: {code, message}, auto_paused}\`, \`agent_id\` the agent the trigger runs as (a start_run target's agent, or the agent of the run a message_run target names, so always present), \`auto_paused\` true when it was the ${FAILURES_TO_PAUSE}th in a row and turned the trigger off, its \`webhook-id\` the same for the same firing, after a restart too. \`agent_name\` in each is the agent's name as the message is built, or its \`agent_id\` when it has none. Never a tool's arguments, an output or an input, which the API reads. Headers: \`webhook-id\` (the same on every try, the receiver's idempotency key), \`webhook-timestamp\` (Unix seconds) and \`webhook-signature: v1,<base64 HMAC-SHA256 of "{id}.{timestamp}.{body}">\` under the secret's 32 bytes; a receiver refuses a timestamp more than 5 minutes from its clock. A try not answered 2xx in 15 s (no redirect followed) is tried again after about 5 s, 5 min, 30 min, 2 h, 5 h and 10 h, with jitter, then logged as failed; pending messages go on after a restart. A 410 turns the webhook off until it is set again. The first PUT makes the secret and answers 201 with it, once; a later PUT keeps it, turns the webhook on again and answers 200. 422 for a URL that is not http or https, holds a user or password, or is over 2048 characters.`,
|
|
2604
2605
|
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["url"], properties: { url: { type: "string", format: "uri", maxLength: 2048 } } } } } },
|
|
2605
2606
|
responses: {
|
|
2606
2607
|
"201": json({ oneOf: [closed({ ...WEBHOOK_SET_FIELDS, signing_secret: WEBHOOK_SECRET }), closed({ ...WEBHOOK_SET_FIELDS, note: { type: "string", description: "To the API token, which is never shown the secret: the words that send the person to the console for it." } })] }, "Set, with its secret as `signing_secret`, shown this once to the owner's signed-in session; to the API token, its metadata and the words in its place."),
|
|
@@ -3222,13 +3223,14 @@ const FIELD_EXTENSIONS = {
|
|
|
3222
3223
|
compile_after: { type: "integer", minimum: 1, maximum: 200, default: 20, description: "The job compiles into a learned workflow once the agent has this many completed runs of its own." },
|
|
3223
3224
|
agree_min: { type: "number", minimum: 0, maximum: 1, default: 0.8, description: "The draft's one check replays it on the inputs of those runs: promoted only when, of the inputs it answered alone, at least this share say what the agent's own recorded answer said." },
|
|
3224
3225
|
alone_min: { type: "number", minimum: 0, maximum: 1, default: 0.7, description: "...and only when it answered at least this share of them alone (no escalate, no failed step). Under either bar it is recompiled once with the inputs it did not agree on, checked the same way, then promoted or stopped: nothing compiles again." },
|
|
3226
|
+
agree_on: { type: "array", items: { type: "string", minLength: 1, maxLength: 128, pattern: "^[^.]+(\\.[^.]+){0,7}$" }, minItems: 1, maxItems: 16, uniqueItems: true, description: "The fields of the answer that say the decision, as dotted paths into its JSON object, e.g. `[\"verdict.decision\"]` or `[\"mcc\", \"riskTier\"]` (each segment an object's key, never an array index; at most 8 segments and 128 characters): the check and the audit compare two answers on these alone, each path resolving in both to equal values (arrays in order, an object's keys in any order); a path that does not resolve in either answer, or in only one, disagrees. Never free text such as a rationale two runs never repeat. Kept in the order given. Absent: the whole answer, equal as JSON (keys in any order) or as trimmed text; nothing is read off the `output_schema`." },
|
|
3225
3227
|
audit_every: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_every, description: "Once a learned workflow serves, 1 in this many of the runs it answers alone (path `workflow`; a run it hands back is never drawn) is audited: drawn from the run's id, the same agent runs the same input again with learning off (a shadow run, hidden from the run list, its cost the agent's learning cost), and the two answers are compared (one row of GET .../learning/audits)." },
|
|
3226
3228
|
audit_every_later: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_every_later, description: "1 in this many once the workflow's revision served `audit_later_after` runs." },
|
|
3227
3229
|
audit_later_after: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_later_after, description: "The served runs after which `audit_every_later` applies." },
|
|
3228
3230
|
hold_window: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.hold_window, description: "The audit rows of the serving revision the hold rule reads: its newest this many (an owner's grade on a served run is one too)." },
|
|
3229
3231
|
hold_disagree: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.hold_disagree, description: "When at least this many of those rows disagree, the workflow stops serving (a hold, source `audit`) and is recompiled once with them as data, then checked again: promoted serves again, otherwise it stops. At most `hold_window`." },
|
|
3230
3232
|
stop_window: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.stop_window, description: "A second hold within this many served runs of the first stops the workflow for good, asking no compile." },
|
|
3231
|
-
} }], default: false, description: "Whether an agentic revision's runs learn: `true`, its owner's corrections and learned workflows; an object, the same with the loop's numbers set on it (`compile_after`, `agree_min`, `alone_min`, `audit_every`, `audit_every_later`, `audit_later_after`, `hold_window`, `hold_disagree`, `stop_window`, each optional: one left out is its default; `true` is every default); `false`, nothing. A run that learns starts from what its agent has learned, its corrections.md whole in its instructions under `# Learned` and its learned workflows behind its learned_workflow tool; once its job is due, it is asked one compile turn that writes the job as a learned workflow, checked and committed. Kept when a definition says so, true, false or an object (its numbers in one order); a number out of range or an unknown key is a 422 `wrong_type`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
|
|
3233
|
+
} }], default: false, description: "Whether an agentic revision's runs learn: `true`, its owner's corrections and learned workflows; an object, the same with the loop's numbers set on it (`compile_after`, `agree_min`, `alone_min`, `agree_on`, `audit_every`, `audit_every_later`, `audit_later_after`, `hold_window`, `hold_disagree`, `stop_window`, each optional: one left out is its default; `true` is every default); `false`, nothing. A run that learns starts from what its agent has learned, its corrections.md whole in its instructions under `# Learned` and its learned workflows behind its learned_workflow tool; once its job is due, it is asked one compile turn that writes the job as a learned workflow, checked and committed. Kept when a definition says so, true, false or an object (its numbers in one order); a number out of range or an unknown key is a 422 `wrong_type`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
|
|
3232
3234
|
checkout: { enum: ["pull_request", "none"], description: "What the server checks out in each run's folder before its first turn, an agentic definition's alone. `pull_request`: the pull request the run's GitHub event names (a GitHub trigger's firing: its repository, number, head and base), at its head, detached, in `repo/`, with its base and their merge base fetched beside it (refs `pr/head`, `pr/base`, `pr/merge-base`). The fetch is the server's own, one command on the run's folder, with an installation token of the server's GitHub App narrowed to that repository and `contents: read`, which the agent never holds: it is never in the folder, the checkout's git config, its remote's URL, the agent's environment or the log. With no App, or one not installed there, the fetch is anonymous, which a public repository answers. The run's system prompt says what was checked out, or why nothing was (no pull request named, the fetch failed), so it can read the change another way, such as the GitHub MCP. The checkout is removed when the run's claim ends. An edit that leaves it out keeps the agent's; `none` clears it. A template sets it from its manifest's `checkout`.", "x-agentrun-serve": "checkout/1" },
|
|
3233
3235
|
},
|
|
3234
3236
|
AgentCreate: {
|
package/dist/runner/audit.js
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
// shadow) of an agent every tool of which only reads (learn/audit.ts auditWriterOf, the replay's readOnlyHint rule): a
|
|
13
13
|
// shadow never writes again.
|
|
14
14
|
// settleAudits: each open started line (no result row yet) whose two runs, read by id, ended writes its row (agreed:
|
|
15
|
-
// the audited answer, its `turn`'s, and the shadow's say the same, learn/promote.ts sameAnswer
|
|
16
|
-
//
|
|
15
|
+
// the audited answer, its `turn`'s, and the shadow's say the same, learn/promote.ts sameAnswer, on the served run's
|
|
16
|
+
// revision's agree_on as the check compares, learning-setting.ts agreeOnOf; a follow-up's answer since is never
|
|
17
|
+
// read), oldest served run first; then, rows added or not, the hold rule reads the serving revisions'
|
|
17
18
|
// rows: a hold is a function of the ledger alone.
|
|
18
19
|
// applyHold: at least hold_disagree disagreements in the newest hold_window rows of the digest's current promotion
|
|
19
20
|
// hold the workflow (a promotion hold carrying `audit`, with those rows, each text cut of the host's secrets before
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
// Every number is the agent definition's (learning-setting.ts auditLoopOf). Nothing here fails a claim: a failure is logged.
|
|
25
26
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
26
27
|
import { overCapMessage } from "@parcha/agentrun-kernel/kernel/cap";
|
|
27
|
-
import { auditLoopOf } from "../learning-setting.js";
|
|
28
|
+
import { agreeOnOf, auditLoopOf } from "../learning-setting.js";
|
|
28
29
|
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
29
30
|
import { runEntries } from "../store-reads/journal.js";
|
|
30
31
|
import { runPathOverStore } from "../store-reads/learning.js";
|
|
@@ -65,6 +66,12 @@ export async function auditLoopOfRevision(store, revisionId) {
|
|
|
65
66
|
return auditLoopOf(undefined);
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
/** The answer paths an audit of a run of revision `revisionId` compares on, as its check does (learning-setting.ts
|
|
70
|
+
* agreeOnOf: its agree_on); undefined, the whole answer. A read that fails throws: settleAudits leaves the row to a
|
|
71
|
+
* later claim, never comparing on the whole answer an agent that named its fields (#3182 review). */
|
|
72
|
+
async function agreeOnOfRevision(store, revisionId) {
|
|
73
|
+
return agreeOnOf((await store.agents.revision(revisionId))?.body?.learning);
|
|
74
|
+
}
|
|
68
75
|
/** The served runs of `workflow` (at `digest` when given) that `keep` keeps too, the newest `n` of them (lastRunsOf: the
|
|
69
76
|
* shadows and the agent's own runs among them never push one out of the read). */
|
|
70
77
|
const servedRuns = (store, agentId, n, workflow, digest, keep = () => true) => lastRunsOf(store, agentId, n, (row) => served(row) && metricsOf(row).workflow === workflow && (digest === undefined || metricsOf(row).workflow_digest === digest) && keep(row));
|
|
@@ -233,11 +240,13 @@ export async function settleAudits(deps) {
|
|
|
233
240
|
rows.sort((a, b) => a.at - b.at || (a.row.run < b.row.run ? -1 : a.row.run > b.row.run ? 1 : 0));
|
|
234
241
|
const { all, added } = rows.length ? await addLines(deps, rows.map(({ row }) => row), async (row) => {
|
|
235
242
|
const shadow = await store.runs.get(row.shadow_run);
|
|
236
|
-
|
|
243
|
+
const served = await store.runs.get(row.run);
|
|
244
|
+
if (shadow?.state !== "ended" || !served)
|
|
237
245
|
return null;
|
|
238
246
|
// The audited answer (the row's turn), never the run's newest: a follow-up since may have answered again.
|
|
239
247
|
const [a, b] = [await auditedAnswer(deps, row), await answerOf(store, row.shadow_run, deps.context)];
|
|
240
|
-
|
|
248
|
+
// Compared on the fields the served run's revision says carry the decision, as its check compared.
|
|
249
|
+
return a === null || b === null ? null : sameAnswer(a, b, await agreeOnOfRevision(store, served.revisionId));
|
|
241
250
|
}) : { all: lines, added: [] };
|
|
242
251
|
const written = rowsOf(added);
|
|
243
252
|
if (written.length)
|
|
@@ -209,6 +209,10 @@ async function world(subject, t, timing = STEADY) {
|
|
|
209
209
|
const handed = new Set();
|
|
210
210
|
/** The command rows a loop's command() has answered: a steer it took is with the session by then (a CLI's has it). */
|
|
211
211
|
const answered = new Set();
|
|
212
|
+
/** What each command row's command() said, in order (taken, later or refused with its reason, or what it threw): for a
|
|
213
|
+
* case's failure message to name the branch a command took, never asserted on. */
|
|
214
|
+
const outcomes = new Map();
|
|
215
|
+
const outcomeSaid = (id, said) => outcomes.set(id, [...(outcomes.get(id) ?? []), said]);
|
|
212
216
|
/** Each runner's claims in flight (store.runs.claimMany), by its name: what claimsSettled waits for. */
|
|
213
217
|
const claiming = new Map();
|
|
214
218
|
/** `store` as runner `name` is handed it: the same store, its claims in flight counted (claiming). */
|
|
@@ -282,7 +286,10 @@ async function world(subject, t, timing = STEADY) {
|
|
|
282
286
|
command: (command) => {
|
|
283
287
|
handed.add(command.id);
|
|
284
288
|
const outcome = loop.command(command);
|
|
285
|
-
void Promise.resolve(outcome).then(() =>
|
|
289
|
+
void Promise.resolve(outcome).then((said) => {
|
|
290
|
+
outcomeSaid(command.id, said === null || typeof said !== "object" ? String(said) : "taken" in said ? "taken" : "later" in said ? `later: ${said.later}` : `refused: ${said.refused}`);
|
|
291
|
+
answered.add(command.id);
|
|
292
|
+
}, (error) => outcomeSaid(command.id, `threw ${error?.name ?? String(error)}`));
|
|
286
293
|
return outcome;
|
|
287
294
|
},
|
|
288
295
|
};
|
|
@@ -382,7 +389,7 @@ async function world(subject, t, timing = STEADY) {
|
|
|
382
389
|
assert.ok(ask, "the run wrote its ask");
|
|
383
390
|
return String(ask.data.callId);
|
|
384
391
|
};
|
|
385
|
-
return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), liveRows, servedRows };
|
|
392
|
+
return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), outcomeOf: (id) => (outcomes.get(id) ?? ["not answered"]).join(", then "), liveRows, servedRows };
|
|
386
393
|
}
|
|
387
394
|
/** What the process wrote after it said it stops at the point, in its file's order (each line is appended synchronously),
|
|
388
395
|
* or everything when it never said so. One millisecond of the clock can hold the loop's last write before the stop and
|
|
@@ -708,9 +715,13 @@ const CASES = [
|
|
|
708
715
|
async body(subject, t) {
|
|
709
716
|
const w = await world(subject, t);
|
|
710
717
|
const { tools, letSlowGo, slowStarted } = suiteTools();
|
|
711
|
-
|
|
718
|
+
// What the subject's model was handed, and at what priority, when it can say: a failure names it with the loop's
|
|
719
|
+
// outcome for the steer, so the branch that placed it is on the record (a CLI's own turn after the call reads `echo:`).
|
|
720
|
+
const received = [];
|
|
721
|
+
await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet, received: (message) => void received.push({ ...message }) });
|
|
712
722
|
await w.began(slowStarted, "the slow tool to start");
|
|
713
723
|
const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "check the totals" } });
|
|
724
|
+
const why = () => `the loop's outcome for the steer: ${w.outcomeOf(steer.id)}; the model was handed: ${JSON.stringify(received)}`;
|
|
714
725
|
// The tool goes on once the loop has answered the steer: the turn in flight has it, never a timer (as in
|
|
715
726
|
// message-mid-turn-kept). A steer that reaches a CLI only after the tool's end is the next turn by its facts.
|
|
716
727
|
await until(() => w.answered(steer.id), "the steer placed by the loop mid-turn");
|
|
@@ -723,11 +734,11 @@ const CASES = [
|
|
|
723
734
|
// Everything the model said once the call started. What it said with the call, before the call's row (a CLI's
|
|
724
735
|
// "Calling slow."), is that step's, as deny-note reads it; the step after the call said only the steer.
|
|
725
736
|
const said = messages.filter((message) => message.role === "model" && message.entry > slow.startEntry);
|
|
726
|
-
assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}`);
|
|
727
|
-
assert.ok(steered.entry > slow.endEntry,
|
|
728
|
-
assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}`);
|
|
729
|
-
assert.ok(said[0].entry > steered.entry);
|
|
730
|
-
assert.ok((await w.commandRow(steer.id)).takenAt !== null,
|
|
737
|
+
assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}; ${why()}`);
|
|
738
|
+
assert.ok(steered.entry > slow.endEntry, `after the tool's end: mid-turn, not lost; ${why()}`);
|
|
739
|
+
assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}; ${why()}`);
|
|
740
|
+
assert.ok(said[0].entry > steered.entry, why());
|
|
741
|
+
assert.ok((await w.commandRow(steer.id)).takenAt !== null, `the steer row is taken; ${why()}`);
|
|
731
742
|
},
|
|
732
743
|
},
|
|
733
744
|
{
|
|
@@ -61,6 +61,12 @@ export interface ConformanceSetup {
|
|
|
61
61
|
readonly hooks: KernelHooks;
|
|
62
62
|
/** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
|
|
63
63
|
readonly agentId?: string;
|
|
64
|
+
/** Called with each message the subject's model is handed, when the subject can see it (a stand-in's fake reports what
|
|
65
|
+
* it consumed and at what priority): for a case's failure message to name, never asserted on. */
|
|
66
|
+
readonly received?: (message: {
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly priority?: string;
|
|
69
|
+
}) => void;
|
|
64
70
|
}
|
|
65
71
|
export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "steer-placed-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run" | "meta-search" | "meta-call-park" | "meta-call-deny" | "meta-codemode-park" | "meta-codemode-stop" | "meta-codemode-crash";
|
|
66
72
|
export interface ConformanceSubject {
|
package/dist/runner/main.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// its turn for up to --drain-timeout (default AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT), then every loop left is stopped where it can resume
|
|
10
10
|
// and its run handed back for another runner (a loop that never stops is given up when its claim would run out, and its
|
|
11
11
|
// run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store schema it does not know 3, anything else 1.
|
|
12
|
+
// A run isolation it cannot give (run-child-host.ts runIsolationOf) is said, and it stays up claiming nothing until a stop: 0.
|
|
12
13
|
// An error nothing handles exits 1 at once, said with its stack (lastResort).
|
|
13
14
|
import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
14
15
|
import { join, resolve } from "node:path";
|
|
@@ -502,8 +503,11 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
502
503
|
catch (error) {
|
|
503
504
|
if (!(error instanceof RunIsolationRefused))
|
|
504
505
|
throw error;
|
|
506
|
+
// Said, then up and claiming nothing until a stop: in the image's server-and-runner either process's exit stops the
|
|
507
|
+
// container, which a platform that restarts it (Render, Railway) would loop on, the refusal lost in the restarts.
|
|
505
508
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
506
|
-
|
|
509
|
+
await untilSignalled(RUNNER_SIGNALS);
|
|
510
|
+
return 0;
|
|
507
511
|
}
|
|
508
512
|
if (isolation.kind === "uid" && holds.loops > isolation.slots)
|
|
509
513
|
console.error(`agentrun-serve runner: each run runs as a user of its own, and the helper reaches ${isolation.slots} slots from slot ${isolation.first}: this runner holds at most ${isolation.slots} runs at once`);
|
|
@@ -574,3 +578,18 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
574
578
|
}
|
|
575
579
|
/** The signals that stop a runner process. */
|
|
576
580
|
const RUNNER_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
581
|
+
/** Holds the process up, with nothing else to do, until one of `signals`. */
|
|
582
|
+
function untilSignalled(signals) {
|
|
583
|
+
return new Promise((resolve) => {
|
|
584
|
+
// A signal's listener alone does not keep Node's loop alive.
|
|
585
|
+
const alive = setInterval(() => { }, 2 ** 30);
|
|
586
|
+
const onSignal = () => {
|
|
587
|
+
for (const signal of signals)
|
|
588
|
+
process.off(signal, onSignal);
|
|
589
|
+
clearInterval(alive);
|
|
590
|
+
resolve();
|
|
591
|
+
};
|
|
592
|
+
for (const signal of signals)
|
|
593
|
+
process.on(signal, onSignal);
|
|
594
|
+
});
|
|
595
|
+
}
|