@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.43
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 +74 -0
- package/NOTICE +2 -0
- package/README.md +85 -19
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +3 -1
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.js +2 -14
- package/dist/console/assets/index-BrcDSBD8.css +1 -0
- package/dist/console/assets/index-Bz6IWncl.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/eval-feed.d.ts +2 -2
- package/dist/eval-feed.js +9 -5
- package/dist/feed/parse.d.ts +3 -2
- package/dist/feed/parse.js +9 -18
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/import-sources.js +25 -5
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +14 -0
- package/dist/learn/check.js +194 -14
- package/dist/learn/compile.d.ts +75 -78
- package/dist/learn/compile.js +175 -176
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +138 -196
- package/dist/learn/promote.js +68 -184
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.js +2 -4
- package/dist/learn/workflow-nodes.d.ts +1 -2
- package/dist/learn/workflow-nodes.js +2 -3
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +11 -4
- package/dist/learning-cost.js +4 -2
- package/dist/learning-routes.js +1 -1
- package/dist/learning-setting.d.ts +38 -0
- package/dist/learning-setting.js +83 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +8 -0
- package/dist/mcp-oauth.js +7 -0
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +195 -59
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/runner/adapter-loop.d.ts +5 -1
- package/dist/runner/adapter-loop.js +20 -8
- package/dist/runner/adapter-run-spec.d.ts +16 -1
- package/dist/runner/adapter-run-spec.js +36 -11
- package/dist/runner/audit.d.ts +64 -0
- package/dist/runner/audit.js +338 -0
- package/dist/runner/beside.js +2 -2
- package/dist/runner/cli-run-spec.js +25 -12
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +19 -40
- package/dist/runner/harness-loops.js +1 -15
- package/dist/runner/journal-kinds.d.ts +0 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +62 -13
- package/dist/runner/learning-end.js +180 -74
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/main.d.ts +11 -0
- package/dist/runner/main.js +30 -3
- package/dist/runner/mcp-run.d.ts +2 -2
- package/dist/runner/promotion.d.ts +78 -50
- package/dist/runner/promotion.js +371 -503
- package/dist/runner/reflect-hook.d.ts +15 -0
- package/dist/runner/reflect-hook.js +28 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +24 -25
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/sdk/runs.js +2 -1
- package/dist/secrets.js +2 -2
- package/dist/server.d.ts +4 -3
- package/dist/server.js +132 -26
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/sqlite/store.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/learning.d.ts +18 -7
- package/dist/store-reads/learning.js +36 -23
- package/dist/store-reads/loop.d.ts +5 -39
- package/dist/store-reads/loop.js +21 -80
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +16 -2
- package/dist/template-eval.d.ts +7 -0
- package/dist/template-eval.js +54 -6
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +14 -1
- package/dist/timeline/computer.js +2 -1
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-feed.js +67 -18
- package/dist/validate.js +7 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +3 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/launcher/agentrun-serve +31 -24
- package/package.json +10 -9
- package/templates/README.md +11 -2
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-COGhx_2Z.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
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-Bz6IWncl.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BrcDSBD8.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/decisions.js
CHANGED
|
@@ -152,10 +152,6 @@ export function providersNamed(nodes) {
|
|
|
152
152
|
}
|
|
153
153
|
if (node.verify)
|
|
154
154
|
ids.add(DEFAULT_DECISION_PROVIDER);
|
|
155
|
-
// A step guard that reads Jev (runner/step-guard.ts) asks Jev, whatever provider its node names.
|
|
156
|
-
const signal = node.guard?.signal;
|
|
157
|
-
if (signal === "jev" || signal === "both")
|
|
158
|
-
ids.add("jev");
|
|
159
155
|
}
|
|
160
156
|
return [...ids];
|
|
161
157
|
}
|
package/dist/eval-feed.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export type CaseFeeds = {
|
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
};
|
|
24
24
|
/** The fake feeds of one run of a case on `fixture`, for a trigger that reads `urls` (its first the fixture's) and, for a
|
|
25
|
-
* JSON list, its items at `under
|
|
26
|
-
export declare function caseFeeds(fixture: FeedFixture, urls: readonly string[], under?: string): Promise<CaseFeeds>;
|
|
25
|
+
* JSON list, its items at `under` and each item's id at `idAt` (the trigger's own id pointer: /id when it names none). */
|
|
26
|
+
export declare function caseFeeds(fixture: FeedFixture, urls: readonly string[], under?: string, idAt?: string): Promise<CaseFeeds>;
|
package/dist/eval-feed.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// words keep the package's URLs. The trigger's first poll, at the apply, takes its start on the fixture's items; the
|
|
6
6
|
// fixture's `item` is then added (or, when one there has its id, put in its place: an incident updated) and the trigger's
|
|
7
7
|
// next poll fires on it.
|
|
8
|
+
import { pointed } from "./feed/pointer.js";
|
|
8
9
|
import { FEED_FORMATS, startFeedFaux } from "./feed/feed-faux.js";
|
|
9
10
|
import { isObject } from "./validate.js";
|
|
10
11
|
const FIXTURE_FIELDS = ["description", "format", "title", "items", "item", "trigger"];
|
|
@@ -37,8 +38,8 @@ export function feedFixtureOf(value, at, bad) {
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
/** The fake feeds of one run of a case on `fixture`, for a trigger that reads `urls` (its first the fixture's) and, for a
|
|
40
|
-
* JSON list, its items at `under
|
|
41
|
-
export async function caseFeeds(fixture, urls, under) {
|
|
41
|
+
* JSON list, its items at `under` and each item's id at `idAt` (the trigger's own id pointer: /id when it names none). */
|
|
42
|
+
export async function caseFeeds(fixture, urls, under, idAt = "/id") {
|
|
42
43
|
const fakes = new Map();
|
|
43
44
|
try {
|
|
44
45
|
for (const [i, url] of urls.entries()) {
|
|
@@ -54,9 +55,12 @@ export async function caseFeeds(fixture, urls, under) {
|
|
|
54
55
|
return {
|
|
55
56
|
route: (url) => fakes.get(url)?.url,
|
|
56
57
|
deliver() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// The item's id as the trigger reads it: at its id pointer in a JSON list, its `id` in any other format.
|
|
59
|
+
const idOf = (one) => (fixture.format === "json-list" ? pointed(one, idAt) : one.id);
|
|
60
|
+
const id = idOf(fixture.item);
|
|
61
|
+
const has = (one) => id !== undefined && id !== null && typeof id !== "object" && idOf(one) === id;
|
|
62
|
+
if (first.items().some(has))
|
|
63
|
+
first.set(first.items().map((one) => (has(one) ? fixture.item : one)));
|
|
60
64
|
else
|
|
61
65
|
first.add(fixture.item);
|
|
62
66
|
},
|
package/dist/feed/parse.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { pointed } from "./pointer.js";
|
|
2
|
+
export { pointed };
|
|
1
3
|
/** The most characters of an item's summary its payload holds. */
|
|
2
4
|
export declare const SUMMARY_CHARS = 4000;
|
|
3
5
|
/** One item as a feed trigger reads it. `key`: what it is known by (its id, else its link, else a hash of its title and
|
|
@@ -26,6 +28,7 @@ export type ParsedFeed = {
|
|
|
26
28
|
export type ListPointers = {
|
|
27
29
|
items?: string;
|
|
28
30
|
id?: string;
|
|
31
|
+
updated?: string;
|
|
29
32
|
};
|
|
30
33
|
/** A body that is no feed this reads: its words. */
|
|
31
34
|
export declare class FeedUnreadable extends Error {
|
|
@@ -37,5 +40,3 @@ export declare function htmlToText(html: string): string;
|
|
|
37
40
|
/** `body` read as a feed. A JSON document is a JSON Feed (its `version` says so) unless `pointers` name a list, else a
|
|
38
41
|
* JSON list; anything else is read as XML: RSS or Atom. Throws FeedUnreadable in words. */
|
|
39
42
|
export declare function parseFeed(body: string, pointers?: ListPointers): ParsedFeed;
|
|
40
|
-
/** The value at JSON Pointer `pointer` in `doc`, or undefined. */
|
|
41
|
-
export declare function pointed(doc: unknown, pointer: string): unknown;
|
package/dist/feed/parse.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// tags dropped, its entities decoded, a block a line).
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { XMLParser, XMLValidator } from "fast-xml-parser";
|
|
8
|
+
import { pointed } from "./pointer.js";
|
|
9
|
+
export { pointed };
|
|
8
10
|
/** The most characters of an item's summary its payload holds. */
|
|
9
11
|
export const SUMMARY_CHARS = 4000;
|
|
10
12
|
/** The most characters of a title. */
|
|
@@ -266,23 +268,12 @@ function jsonFeedOf(doc) {
|
|
|
266
268
|
}),
|
|
267
269
|
};
|
|
268
270
|
}
|
|
269
|
-
/** The
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const part = raw.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
276
|
-
if (Array.isArray(at) && /^(0|[1-9]\d*)$/.test(part))
|
|
277
|
-
at = at[Number(part)];
|
|
278
|
-
else if (at && typeof at === "object" && !Array.isArray(at) && Object.hasOwn(at, part))
|
|
279
|
-
at = at[part];
|
|
280
|
-
else
|
|
281
|
-
return undefined;
|
|
282
|
-
}
|
|
283
|
-
return at;
|
|
284
|
-
}
|
|
285
|
-
function jsonListOf(doc, { items: itemsAt = "", id: idAt = "/id" }) {
|
|
271
|
+
/** The instant a JSON list's `updated` pointer reads, in ms: a date string it names; anything else, none. */
|
|
272
|
+
const instantOf = (value) => {
|
|
273
|
+
const at = typeof value === "string" ? Date.parse(value) : NaN;
|
|
274
|
+
return Number.isNaN(at) ? null : at;
|
|
275
|
+
};
|
|
276
|
+
function jsonListOf(doc, { items: itemsAt = "", id: idAt = "/id", updated: updatedAt }) {
|
|
286
277
|
const items = pointed(doc, itemsAt);
|
|
287
278
|
if (!Array.isArray(items))
|
|
288
279
|
throw new FeedUnreadable(itemsAt ? `nothing at ${itemsAt} in its JSON is a list` : "its JSON is no list, and the trigger names no items pointer to one");
|
|
@@ -294,7 +285,7 @@ function jsonListOf(doc, { items: itemsAt = "", id: idAt = "/id" }) {
|
|
|
294
285
|
const id = str(pointed(object, idAt));
|
|
295
286
|
const link = str(object.html_url) ?? str(object.url) ?? str(object.link);
|
|
296
287
|
const title = str(object.title, TITLE_CHARS) ?? str(object.name, TITLE_CHARS);
|
|
297
|
-
return { key: id ?? link ?? `hash:${hash(title ?? JSON.stringify(one))}`, id, link, title, published: null, updated: null, author: null, summary: null, categories: [], raw: one };
|
|
288
|
+
return { key: id ?? link ?? `hash:${hash(title ?? JSON.stringify(one))}`, id, link, title, published: null, updated: updatedAt === undefined ? null : instantOf(pointed(object, updatedAt)), author: null, summary: null, categories: [], raw: one };
|
|
298
289
|
}),
|
|
299
290
|
};
|
|
300
291
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A JSON Pointer read (RFC 6901), kept apart from the feed parser so the trigger reads it without loading the parser.
|
|
2
|
+
/** The value at JSON Pointer `pointer` in `doc`, or undefined. */
|
|
3
|
+
export function pointed(doc, pointer) {
|
|
4
|
+
if (pointer === "")
|
|
5
|
+
return doc;
|
|
6
|
+
let at = doc;
|
|
7
|
+
for (const raw of pointer.split("/").slice(1)) {
|
|
8
|
+
const part = raw.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
9
|
+
if (Array.isArray(at) && /^(0|[1-9]\d*)$/.test(part))
|
|
10
|
+
at = at[Number(part)];
|
|
11
|
+
else if (at && typeof at === "object" && !Array.isArray(at) && Object.hasOwn(at, part))
|
|
12
|
+
at = at[part];
|
|
13
|
+
else
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return at;
|
|
17
|
+
}
|
package/dist/file-types.js
CHANGED
|
@@ -4,6 +4,7 @@ import { extname } from "node:path";
|
|
|
4
4
|
const TYPES = new Map(Object.entries({
|
|
5
5
|
txt: "text/plain; charset=utf-8", md: "text/markdown; charset=utf-8", csv: "text/csv; charset=utf-8", json: "application/json", jsonl: "application/x-ndjson",
|
|
6
6
|
html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", pdf: "application/pdf",
|
|
7
|
+
mp4: "video/mp4",
|
|
7
8
|
}));
|
|
8
9
|
/** The types a file is served as in the page (every known type but PDF); any other is a download. */
|
|
9
10
|
export const INLINE_TYPES = new Set([...TYPES.values()].filter((type) => type !== "application/pdf"));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Whether a folder of `path` (a PATH value) holds an executable file named `command`; on Windows, with an executable
|
|
2
|
+
* extension too (platform-tools installs adb.exe). */
|
|
3
|
+
export declare function commandOnPath(command: string, path: string | undefined, platform?: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Whether a program this server runs on its own machine is there: a provider's (the phone's adb, computers.ts) and the
|
|
2
|
+
// screen recorder's ffmpeg (computer-record.ts).
|
|
3
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
4
|
+
import { delimiter, join } from "node:path";
|
|
5
|
+
/** Whether a folder of `path` (a PATH value) holds an executable file named `command`; on Windows, with an executable
|
|
6
|
+
* extension too (platform-tools installs adb.exe). */
|
|
7
|
+
export function commandOnPath(command, path, platform = process.platform) {
|
|
8
|
+
const named = platform === "win32" ? [command, ...[".exe", ".cmd", ".bat"].map((extension) => `${command}${extension}`)] : [command];
|
|
9
|
+
return (path ?? "").split(delimiter).some((folder) => folder !== "" && named.some((file) => {
|
|
10
|
+
try {
|
|
11
|
+
accessSync(join(folder, file), constants.X_OK);
|
|
12
|
+
return statSync(join(folder, file)).isFile();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { statfs } from "node:fs/promises";
|
|
2
2
|
import type { Store } from "./store/index.js";
|
|
3
|
+
/** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
|
|
4
|
+
* never go to (runner/main.ts runnerLoopback). */
|
|
5
|
+
export declare const DEFAULT_PORT = 7340;
|
|
3
6
|
/** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
|
|
4
7
|
* 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
|
|
5
8
|
* reserved for the high end, 81, plus 47 (+58%), since what it holds grows with the agents and runs it keeps. That is
|
package/dist/host.js
CHANGED
|
@@ -7,6 +7,9 @@ import { totalmem } from "node:os";
|
|
|
7
7
|
import { REQUEST_BUSY_MS, whenFree } from "./agents.js";
|
|
8
8
|
import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
|
|
9
9
|
import { builtinHarness } from "./harness-table.js";
|
|
10
|
+
/** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
|
|
11
|
+
* never go to (runner/main.ts runnerLoopback). */
|
|
12
|
+
export const DEFAULT_PORT = 7340;
|
|
10
13
|
const MiB = 2 ** 20;
|
|
11
14
|
/** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
|
|
12
15
|
* 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
|
package/dist/import-sources.js
CHANGED
|
@@ -166,7 +166,7 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
166
166
|
activeMs: 0,
|
|
167
167
|
copies: 0,
|
|
168
168
|
};
|
|
169
|
-
|
|
169
|
+
let turns = [];
|
|
170
170
|
let first;
|
|
171
171
|
let last;
|
|
172
172
|
const names = new Map();
|
|
@@ -175,14 +175,17 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
175
175
|
const current = { keyed: new Map(), seen: seen ?? new Set(), copied: new Set() };
|
|
176
176
|
const codex = { events: false, held: [], records: false, responses: new Set(), items: new Map(), results: new Map() };
|
|
177
177
|
const titles = { summaries: [], uuids: new Set() };
|
|
178
|
-
const
|
|
178
|
+
const rememberUser = (turn) => {
|
|
179
179
|
if (turn.role === "user") {
|
|
180
180
|
session.users += 1;
|
|
181
181
|
session.firstPrompt ??= turn.text;
|
|
182
182
|
session.titleText ??= personsWords(turn.text);
|
|
183
183
|
}
|
|
184
|
+
};
|
|
185
|
+
const add = (turn) => {
|
|
186
|
+
rememberUser(turn);
|
|
184
187
|
if (keep)
|
|
185
|
-
turns.
|
|
188
|
+
turns.push(turn);
|
|
186
189
|
};
|
|
187
190
|
const record = source === "claude-code" ? claudeRecord : source === "codex" ? codexRecord : piRecord;
|
|
188
191
|
const lines = createInterface({
|
|
@@ -216,8 +219,25 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
216
219
|
}
|
|
217
220
|
// Older Codex writes each of the person's turns twice, as a user_message event and as a user message; current Codex
|
|
218
221
|
// writes the user message alone. One source per file, so no turn counts twice.
|
|
219
|
-
if (!codex.events)
|
|
220
|
-
|
|
222
|
+
if (!codex.events && codex.held.length) {
|
|
223
|
+
// Held indexes refer to the non-user turns as read. Merge both ordered lists once: inserting each user into
|
|
224
|
+
// the middle of the transcript shifts its remaining turns again and again on a long current-Codex session.
|
|
225
|
+
const ordered = [];
|
|
226
|
+
let next = 0;
|
|
227
|
+
for (const { index, turn } of codex.held) {
|
|
228
|
+
rememberUser(turn);
|
|
229
|
+
if (keep) {
|
|
230
|
+
while (next < index)
|
|
231
|
+
ordered.push(turns[next++]);
|
|
232
|
+
ordered.push(turn);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (keep) {
|
|
236
|
+
while (next < turns.length)
|
|
237
|
+
ordered.push(turns[next++]);
|
|
238
|
+
turns = ordered;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
221
241
|
if (!session.id)
|
|
222
242
|
session.id = source === "pi" ? basename(file, ".jsonl").split("_").pop() : basename(file, ".jsonl");
|
|
223
243
|
const sourceTitle = titles.custom ?? titles.ai ?? titles.summaries.findLast(({ leaf }) => leaf === undefined || titles.uuids.has(leaf))?.title;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Workspace } from "../workspace/index.js";
|
|
2
|
+
import type { AuditLoop } from "../learning-setting.js";
|
|
3
|
+
import type { RunLaunch } from "../run-launch.js";
|
|
4
|
+
import { AUDITS_FILE, type FolderChange, type FolderRead } from "./folder.js";
|
|
5
|
+
import { type PromotionRecord } from "./promote.js";
|
|
6
|
+
export { AUDITS_FILE };
|
|
7
|
+
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
|
|
8
|
+
* folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
|
|
9
|
+
export declare const AUDITS_KEPT = 2000;
|
|
10
|
+
/** What every shadow run's id starts with: its served run's id follows (shadowRunId). No server-minted id starts so. */
|
|
11
|
+
export declare const SHADOW_PREFIX = "audit.";
|
|
12
|
+
/** One finished audit. `run`: the served run; `shadow_run`: its shadow (null for a grade's row, or one never started);
|
|
13
|
+
* `workflow` at `digest` served it, under the promotion begun at `promoted_at` (learn/promote.ts promotionStartOf: the
|
|
14
|
+
* one serving when its shadow started, or at the grade; null: none); `agreed`: whether the two answers say the same (a
|
|
15
|
+
* grade's: the grade), null when either answer is missing (a shadow that failed, parked or never ran: no evidence either
|
|
16
|
+
* way, never counted by the hold rule); the two runs' costs (null unknown). `turn`: the served run's answer the audit is
|
|
17
|
+
* of, the id of its answer row (its newest final answer when the audit began, or at the grade): a follow-up's later
|
|
18
|
+
* answer is never the one compared; absent when it had none. `skipped`: a drawn run whose cap left its shadow no
|
|
19
|
+
* allowance (less than a run's smallest cap): no shadow was started. `parked`: its shadow came to wait on a person (an
|
|
20
|
+
* approval, a question, a raise of its cap: what the served run's cap left) and ended there, so it has no answer. */
|
|
21
|
+
export interface AuditRow {
|
|
22
|
+
readonly run: string;
|
|
23
|
+
readonly shadow_run: string | null;
|
|
24
|
+
readonly workflow: string;
|
|
25
|
+
readonly digest: string;
|
|
26
|
+
readonly promoted_at: string | null;
|
|
27
|
+
readonly source: "shadow" | "grade";
|
|
28
|
+
readonly agreed: boolean | null;
|
|
29
|
+
readonly served_cost: number | null;
|
|
30
|
+
readonly shadow_cost: number | null;
|
|
31
|
+
readonly turn?: string;
|
|
32
|
+
readonly skipped?: "no allowance";
|
|
33
|
+
readonly parked?: true;
|
|
34
|
+
readonly at: string;
|
|
35
|
+
}
|
|
36
|
+
/** A shadow audit begun (runner/audit.ts startAudit), written before its shadow run is created: open until a row of
|
|
37
|
+
* source `shadow` for the same `run` is written. `turn`: the served run's answer row it audits (AuditRow.turn). */
|
|
38
|
+
export interface AuditStarted {
|
|
39
|
+
readonly source: "started";
|
|
40
|
+
readonly run: string;
|
|
41
|
+
readonly shadow_run: string;
|
|
42
|
+
readonly workflow: string;
|
|
43
|
+
readonly digest: string;
|
|
44
|
+
readonly promoted_at: string | null;
|
|
45
|
+
readonly turn?: string;
|
|
46
|
+
readonly at: string;
|
|
47
|
+
}
|
|
48
|
+
/** One line of the ledger, in the order written. */
|
|
49
|
+
export type LedgerLine = AuditRow | AuditStarted;
|
|
50
|
+
/** The rows of `lines` (the finished audits), oldest first. */
|
|
51
|
+
export declare const rowsOf: (lines: readonly LedgerLine[]) => AuditRow[];
|
|
52
|
+
/** The started lines of `lines` with no result row yet: the audits settlement still owes, oldest first. */
|
|
53
|
+
export declare function openAudits(lines: readonly LedgerLine[]): AuditStarted[];
|
|
54
|
+
/** Whether served run `runId` is audited at 1 in `k`: the first 8 hex digits of sha256("audit:" + its id), read as a
|
|
55
|
+
* number, are a multiple of k. A function of the id and k alone, so a claim taken again draws the same. */
|
|
56
|
+
export declare const auditDrawn: (runId: string, k: number) => boolean;
|
|
57
|
+
/** The k a served run is drawn at: `audit_every`, or `audit_every_later` once its revision served `audit_later_after`. */
|
|
58
|
+
export declare const auditEveryOf: (loop: AuditLoop, served: number) => number;
|
|
59
|
+
/** The shadow run's id for served run `runId`: one per served run, ever (a second create is the store's constraint). */
|
|
60
|
+
export declare const shadowRunId: (runId: string) => string;
|
|
61
|
+
/** Whether `runId` is a shadow run's. */
|
|
62
|
+
export declare const isShadowRun: (runId: string) => boolean;
|
|
63
|
+
/** The first tool agent revision `revision` can call (its grants, and what its computer brings) that is not read-only by
|
|
64
|
+
* the rule a check's replay skips a write by (learn/replay-calls.ts toolClassOf: an MCP tool by its pinned annotations,
|
|
65
|
+
* readOnlyHint, a built-in by READ_TOOLS); undefined when every one only reads. An agent that can call one is never
|
|
66
|
+
* audited: its shadow, a second run of the agent on the same input, could do that write again. */
|
|
67
|
+
export declare function auditWriterOf(revision: {
|
|
68
|
+
readonly body: unknown;
|
|
69
|
+
readonly mcpPin: unknown;
|
|
70
|
+
} | undefined): string | undefined;
|
|
71
|
+
/** What the promotions read says of an agent never audited (auditWriterOf names `tool`). */
|
|
72
|
+
export declare const auditsOffWords: (tool: string) => string;
|
|
73
|
+
/** Whether a served run's launch can be audited: started over the API (no trigger, no origin of its first message) with no
|
|
74
|
+
* uploaded files. A triggered run's context (a GitHub event's checkout, the thread it answers on) is never rebuilt for a
|
|
75
|
+
* shadow, which could answer there too: its served run is not auditable (its record's metrics.not_auditable). */
|
|
76
|
+
export declare const auditableLaunch: (launch: Pick<RunLaunch, "trigger" | "inputOrigin" | "files">) => boolean;
|
|
77
|
+
/** The lines of a ledger's text, in the order written; one out of shape is skipped. */
|
|
78
|
+
export declare function parseLedger(text: string): LedgerLine[];
|
|
79
|
+
/** The ledger's text for `lines`: from the AUDITS_KEPT-th newest row on, and every open started line before it. */
|
|
80
|
+
export declare function auditsText(lines: readonly LedgerLine[]): string;
|
|
81
|
+
/** The ledger's lines on the folder's main as `folder` reads it (none before the first). */
|
|
82
|
+
export declare function ledgerOf(folder: FolderRead): Promise<LedgerLine[]>;
|
|
83
|
+
/** The ledger's rows on the folder's main: its finished audits, oldest first. */
|
|
84
|
+
export declare const readAudits: (ws: Workspace) => Promise<AuditRow[]>;
|
|
85
|
+
/** A line's place in the ledger: one per served run and source (a started line's, its shadow's row, a grade's row). */
|
|
86
|
+
export declare const lineKey: (line: LedgerLine) => string;
|
|
87
|
+
/** The change that appends `lines` to the ledger `before` (none when each is there already: lineKey), with the lines it
|
|
88
|
+
* appends. */
|
|
89
|
+
export declare function auditChange(before: readonly LedgerLine[], lines: readonly LedgerLine[]): {
|
|
90
|
+
added: LedgerLine[];
|
|
91
|
+
change?: FolderChange;
|
|
92
|
+
};
|
|
93
|
+
/** The rows the hold rule counts for `workflow` at `digest` under the promotion begun at `promotedAt` (learn/promote.ts
|
|
94
|
+
* promotionStartOf; none counted for null): those with a verdict, the newest `hold_window` of them. */
|
|
95
|
+
export declare const windowOf: (rows: readonly AuditRow[], workflow: string, digest: string, promotedAt: string | null, loop: Pick<AuditLoop, "hold_window">) => AuditRow[];
|
|
96
|
+
/** The hold rule: the counted rows (windowOf) when at least `hold_disagree` of them disagree, else undefined. */
|
|
97
|
+
export declare function holdOf(rows: readonly AuditRow[], workflow: string, digest: string, promotedAt: string | null, loop: Pick<AuditLoop, "hold_window" | "hold_disagree">): {
|
|
98
|
+
rows: AuditRow[];
|
|
99
|
+
disagreed: AuditRow[];
|
|
100
|
+
} | undefined;
|
|
101
|
+
/** A workflow's audit line, as the promotions read shows it: the bar, and the counted rows and disagreements now. */
|
|
102
|
+
export type AuditLine = {
|
|
103
|
+
readonly window: number;
|
|
104
|
+
readonly disagree: number;
|
|
105
|
+
readonly rows: number;
|
|
106
|
+
readonly disagreed: number;
|
|
107
|
+
};
|
|
108
|
+
export declare function auditLineOf(rows: readonly AuditRow[], workflow: string, digest: string, promotedAt: string | null, loop: Pick<AuditLoop, "hold_window" | "hold_disagree">): AuditLine;
|
|
109
|
+
/** What the promotions read says of each learned workflow beside what serves (learn/promote.ts servingOf, in its order):
|
|
110
|
+
* `state` (`checking`, its newest record is a check at work; `serving`, a revision serves; `stopped`, its newest record
|
|
111
|
+
* is a hold that stops it; `held`, else), its newest decided check's numbers, and its audit line over the rows of the
|
|
112
|
+
* serving (else the newest) revision's newest promotion (the ones the hold rule counts). */
|
|
113
|
+
export type ServingLine = {
|
|
114
|
+
readonly state: "serving" | "checking" | "held" | "stopped";
|
|
115
|
+
readonly check: {
|
|
116
|
+
readonly n: number;
|
|
117
|
+
readonly agreed: number;
|
|
118
|
+
readonly alone: number;
|
|
119
|
+
readonly attempt: 1 | 2;
|
|
120
|
+
} | null;
|
|
121
|
+
readonly audit: AuditLine | null;
|
|
122
|
+
};
|
|
123
|
+
export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">): ServingLine[];
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// The audit ledger: audits.jsonl at the top of an agent's git learning folder, one JSON line each, appended by the host
|
|
2
|
+
// alone (runner/audit.ts, and the server for an owner's grade). A `started` line is a shadow audit begun (written before
|
|
3
|
+
// its shadow run is created); a row is one finished audit of a run a promoted learned workflow served first: its shadow
|
|
4
|
+
// run's answer (the same agent on the same input, learning off) against the served one (source `shadow`, the started
|
|
5
|
+
// line's result), or an owner's grade of the served run (source `grade`, agreed = the grade). The open audits are the
|
|
6
|
+
// started lines with no result row: settlement reads their two runs by id, so none is ever lost to a window of runs.
|
|
7
|
+
// Each line keeps the promotion it counts for (`promoted_at`), and the hold rule reads the newest rows of the serving
|
|
8
|
+
// revision's current promotion (holdOf). The engine never reads a row's domain: only whether two answers say the same
|
|
9
|
+
// (learn/promote.ts sameAnswer) and what each run cost.
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { COMPUTER_TOOLS } from "@parcha/agentrun-kernel/kernel";
|
|
12
|
+
import { pinAnnotations, toolClassOf, toolWord } from "./replay-calls.js";
|
|
13
|
+
import { AUDITS_FILE, readLearning } from "./folder.js";
|
|
14
|
+
import { promotionStartOf, servingOf } from "./promote.js";
|
|
15
|
+
export { AUDITS_FILE };
|
|
16
|
+
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
|
|
17
|
+
* folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
|
|
18
|
+
export const AUDITS_KEPT = 2_000;
|
|
19
|
+
/** What every shadow run's id starts with: its served run's id follows (shadowRunId). No server-minted id starts so. */
|
|
20
|
+
export const SHADOW_PREFIX = "audit.";
|
|
21
|
+
/** The rows of `lines` (the finished audits), oldest first. */
|
|
22
|
+
export const rowsOf = (lines) => lines.filter((line) => line.source !== "started");
|
|
23
|
+
/** The started lines of `lines` with no result row yet: the audits settlement still owes, oldest first. */
|
|
24
|
+
export function openAudits(lines) {
|
|
25
|
+
const done = new Set(lines.filter((line) => line.source === "shadow").map((line) => line.run));
|
|
26
|
+
return lines.filter((line) => line.source === "started" && !done.has(line.run));
|
|
27
|
+
}
|
|
28
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
29
|
+
/** Whether served run `runId` is audited at 1 in `k`: the first 8 hex digits of sha256("audit:" + its id), read as a
|
|
30
|
+
* number, are a multiple of k. A function of the id and k alone, so a claim taken again draws the same. */
|
|
31
|
+
export const auditDrawn = (runId, k) => Number.parseInt(sha256(`audit:${runId}`).slice(0, 8), 16) % Math.max(1, k) === 0;
|
|
32
|
+
/** The k a served run is drawn at: `audit_every`, or `audit_every_later` once its revision served `audit_later_after`. */
|
|
33
|
+
export const auditEveryOf = (loop, served) => (served >= loop.audit_later_after ? loop.audit_every_later : loop.audit_every);
|
|
34
|
+
/** The shadow run's id for served run `runId`: one per served run, ever (a second create is the store's constraint). */
|
|
35
|
+
export const shadowRunId = (runId) => {
|
|
36
|
+
const id = `${SHADOW_PREFIX}${runId}`;
|
|
37
|
+
return id.length <= 128 ? id : `${SHADOW_PREFIX}${sha256(runId).slice(0, 40)}`;
|
|
38
|
+
};
|
|
39
|
+
/** Whether `runId` is a shadow run's. */
|
|
40
|
+
export const isShadowRun = (runId) => runId.startsWith(SHADOW_PREFIX);
|
|
41
|
+
/** The tools an agent's computer brings beside its grants (a browser's one tool, a desktop's or a phone's kernel tools). */
|
|
42
|
+
const broughtBy = (computer) => {
|
|
43
|
+
const kind = computer?.kind;
|
|
44
|
+
return kind === "browser" ? ["browser"] : kind === "desktop" || kind === "phone" ? COMPUTER_TOOLS : [];
|
|
45
|
+
};
|
|
46
|
+
/** The first tool agent revision `revision` can call (its grants, and what its computer brings) that is not read-only by
|
|
47
|
+
* the rule a check's replay skips a write by (learn/replay-calls.ts toolClassOf: an MCP tool by its pinned annotations,
|
|
48
|
+
* readOnlyHint, a built-in by READ_TOOLS); undefined when every one only reads. An agent that can call one is never
|
|
49
|
+
* audited: its shadow, a second run of the agent on the same input, could do that write again. */
|
|
50
|
+
export function auditWriterOf(revision) {
|
|
51
|
+
const body = revision?.body;
|
|
52
|
+
const granted = Array.isArray(body?.tools) ? body.tools.filter((tool) => typeof tool === "string") : [];
|
|
53
|
+
const annotations = pinAnnotations(revision?.mcpPin);
|
|
54
|
+
return [...granted, ...broughtBy(body?.computer)].find((tool) => toolClassOf(tool, annotations) !== "read");
|
|
55
|
+
}
|
|
56
|
+
/** What the promotions read says of an agent never audited (auditWriterOf names `tool`). */
|
|
57
|
+
export const auditsOffWords = (tool) => `audits off: ${toolWord(tool)} can write`;
|
|
58
|
+
/** Whether a served run's launch can be audited: started over the API (no trigger, no origin of its first message) with no
|
|
59
|
+
* uploaded files. A triggered run's context (a GitHub event's checkout, the thread it answers on) is never rebuilt for a
|
|
60
|
+
* shadow, which could answer there too: its served run is not auditable (its record's metrics.not_auditable). */
|
|
61
|
+
export const auditableLaunch = (launch) => !launch.trigger && !launch.inputOrigin && !launch.files?.length;
|
|
62
|
+
const isLine = (value) => {
|
|
63
|
+
if (value === null || typeof value !== "object")
|
|
64
|
+
return false;
|
|
65
|
+
const line = value;
|
|
66
|
+
const cost = (one) => one === null || (typeof one === "number" && Number.isFinite(one));
|
|
67
|
+
const common = typeof line.run === "string" && typeof line.workflow === "string" && typeof line.digest === "string" && (line.promoted_at === null || typeof line.promoted_at === "string")
|
|
68
|
+
&& (line.turn === undefined || typeof line.turn === "string") && typeof line.at === "string";
|
|
69
|
+
if (line.source === "started")
|
|
70
|
+
return common && typeof line.shadow_run === "string";
|
|
71
|
+
return common && (line.shadow_run === null || typeof line.shadow_run === "string") && (line.source === "shadow" || line.source === "grade")
|
|
72
|
+
&& (line.agreed === null || typeof line.agreed === "boolean") && cost(line.served_cost) && cost(line.shadow_cost);
|
|
73
|
+
};
|
|
74
|
+
/** Why a row has no verdict, as written (AuditRow.skipped, AuditRow.parked): never one of a row with one. */
|
|
75
|
+
const noVerdictOf = (line) => line.agreed !== null ? {} : line.skipped === "no allowance" ? { skipped: "no allowance" } : line.parked === true ? { parked: true } : {};
|
|
76
|
+
/** A line's turn (AuditRow.turn), as written: none when it has none. */
|
|
77
|
+
const turnOf = (line) => (line.turn === undefined ? {} : { turn: line.turn });
|
|
78
|
+
/** The lines of a ledger's text, in the order written; one out of shape is skipped. */
|
|
79
|
+
export function parseLedger(text) {
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const raw of text.split("\n")) {
|
|
82
|
+
if (!raw.trim())
|
|
83
|
+
continue;
|
|
84
|
+
try {
|
|
85
|
+
const value = JSON.parse(raw);
|
|
86
|
+
if (!isLine(value))
|
|
87
|
+
continue;
|
|
88
|
+
const { run, workflow, digest, promoted_at, at } = value;
|
|
89
|
+
out.push(value.source === "started"
|
|
90
|
+
? { source: "started", run, shadow_run: value.shadow_run, workflow, digest, promoted_at, ...turnOf(value), at }
|
|
91
|
+
: { run, shadow_run: value.shadow_run, workflow, digest, promoted_at, source: value.source, agreed: value.agreed, served_cost: value.served_cost, shadow_cost: value.shadow_cost, ...turnOf(value), ...noVerdictOf(value), at });
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// A torn line is no line.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** The ledger's text for `lines`: from the AUDITS_KEPT-th newest row on, and every open started line before it. */
|
|
100
|
+
export function auditsText(lines) {
|
|
101
|
+
const rows = lines.flatMap((line, i) => (line.source === "started" ? [] : [i]));
|
|
102
|
+
const from = rows.length > AUDITS_KEPT ? rows[rows.length - AUDITS_KEPT] : 0;
|
|
103
|
+
const open = new Set(openAudits(lines));
|
|
104
|
+
return lines.filter((line, i) => i >= from || open.has(line)).map((line) => JSON.stringify(line)).join("\n") + "\n";
|
|
105
|
+
}
|
|
106
|
+
/** The ledger's lines on the folder's main as `folder` reads it (none before the first). */
|
|
107
|
+
export async function ledgerOf(folder) {
|
|
108
|
+
const at = folder.snapshot?.audits;
|
|
109
|
+
return at ? parseLedger(await folder.body(AUDITS_FILE, at.oid)) : [];
|
|
110
|
+
}
|
|
111
|
+
/** The ledger's rows on the folder's main: its finished audits, oldest first. */
|
|
112
|
+
export const readAudits = async (ws) => rowsOf(await readLearning(ws, ledgerOf));
|
|
113
|
+
/** A line's place in the ledger: one per served run and source (a started line's, its shadow's row, a grade's row). */
|
|
114
|
+
export const lineKey = (line) => `${line.source}:${line.run}`;
|
|
115
|
+
/** The change that appends `lines` to the ledger `before` (none when each is there already: lineKey), with the lines it
|
|
116
|
+
* appends. */
|
|
117
|
+
export function auditChange(before, lines) {
|
|
118
|
+
const known = new Set(before.map(lineKey));
|
|
119
|
+
const added = [];
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
if (known.has(lineKey(line)))
|
|
122
|
+
continue;
|
|
123
|
+
known.add(lineKey(line));
|
|
124
|
+
added.push(line);
|
|
125
|
+
}
|
|
126
|
+
const rows = rowsOf(added).length;
|
|
127
|
+
const said = rows ? `${rows} audit row${rows === 1 ? "" : "s"}` : `${added.length} audit${added.length === 1 ? "" : "s"} started`;
|
|
128
|
+
return added.length ? { added, change: { by: { host: said }, writes: [{ path: AUDITS_FILE, text: auditsText([...before, ...added]) }] } } : { added };
|
|
129
|
+
}
|
|
130
|
+
/** The rows the hold rule counts for `workflow` at `digest` under the promotion begun at `promotedAt` (learn/promote.ts
|
|
131
|
+
* promotionStartOf; none counted for null): those with a verdict, the newest `hold_window` of them. */
|
|
132
|
+
export const windowOf = (rows, workflow, digest, promotedAt, loop) => promotedAt === null ? [] : rows.filter((row) => row.workflow === workflow && row.digest === digest && row.promoted_at === promotedAt && row.agreed !== null).slice(-loop.hold_window);
|
|
133
|
+
/** The hold rule: the counted rows (windowOf) when at least `hold_disagree` of them disagree, else undefined. */
|
|
134
|
+
export function holdOf(rows, workflow, digest, promotedAt, loop) {
|
|
135
|
+
const counted = windowOf(rows, workflow, digest, promotedAt, loop);
|
|
136
|
+
const disagreed = counted.filter((row) => row.agreed === false);
|
|
137
|
+
return disagreed.length >= loop.hold_disagree ? { rows: counted, disagreed } : undefined;
|
|
138
|
+
}
|
|
139
|
+
export function auditLineOf(rows, workflow, digest, promotedAt, loop) {
|
|
140
|
+
const counted = windowOf(rows, workflow, digest, promotedAt, loop);
|
|
141
|
+
return { window: loop.hold_window, disagree: loop.hold_disagree, rows: counted.length, disagreed: counted.filter((row) => row.agreed === false).length };
|
|
142
|
+
}
|
|
143
|
+
export function servingLinesOf(records, rows, loop) {
|
|
144
|
+
return servingOf(records).map(({ workflow, digest }) => {
|
|
145
|
+
const own = records.filter((one) => one.workflow === workflow);
|
|
146
|
+
const newest = own.at(-1);
|
|
147
|
+
const state = newest?.decided === "replaying" ? "checking"
|
|
148
|
+
: digest !== null ? "serving"
|
|
149
|
+
: newest?.decided === "hold" && (newest.check?.stopped || newest.audit?.stopped) ? "stopped"
|
|
150
|
+
: "held";
|
|
151
|
+
const checked = own.findLast((one) => one.check?.n !== undefined)?.check;
|
|
152
|
+
const at = digest ?? newest?.digest;
|
|
153
|
+
return {
|
|
154
|
+
state,
|
|
155
|
+
check: checked ? { n: checked.n, agreed: checked.agreed ?? 0, alone: checked.alone ?? 0, attempt: checked.attempt } : null,
|
|
156
|
+
audit: at === undefined ? null : auditLineOf(rows, workflow, at, promotionStartOf(records, workflow, at)?.at ?? null, loop),
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
package/dist/learn/check.d.ts
CHANGED
|
@@ -109,6 +109,20 @@ export declare const printable: (problem: Problem, values: readonly string[]) =>
|
|
|
109
109
|
* its item and are never the answer; a loop's body writes the state around it. Legwork on fast and an answer on strong
|
|
110
110
|
* pass. Out of sample (H1), the same answering step on the fast model scored 8.5-9.6 points lower than on the agent's. */
|
|
111
111
|
export declare function answerTierProblems(doc: unknown): string[];
|
|
112
|
+
/** Why a draft's model step off the fast tier reads a page (compact state): an agent, decide or extract step with no
|
|
113
|
+
* `"tier": "fast"` whose `state` map names a key that may hold a page a call step fetched (a call's result, a map's
|
|
114
|
+
* collected one, a pick or sift over pages, a composed workflow's answer when it is one, the key or anything under it),
|
|
115
|
+
* or, with no `state` map, which reads the whole state while such a key is in it (pagesRead: the engine's own lookup).
|
|
116
|
+
* Read in run order: a key holds a page from the step that fetched it until a model step writes over it; a parallel's
|
|
117
|
+
* branches each start from the same state and their writes merge, so a key one branch replaced is no page after it; a
|
|
118
|
+
* route runs one branch, so a key stays a page unless every branch replaced it; a loop's body is read pass after pass,
|
|
119
|
+
* each on every page its passes may leave, until the marks stop changing (within its maxIters); a map's body sees
|
|
120
|
+
* `item` as a page when its list is one, and its failedAs rows are short errors, never pages; a composed workflow's
|
|
121
|
+
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
122
|
+
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
123
|
+
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
124
|
+
* One line each, in words the compile retry acts on. */
|
|
125
|
+
export declare function compactStateProblems(doc: unknown): string[];
|
|
112
126
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
113
127
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
114
128
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|