@parcha/agentrun-serve 0.1.0-beta.42 → 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 +21 -0
- package/README.md +8 -7
- package/dist/console/assets/index-BrcDSBD8.css +1 -0
- package/dist/console/assets/{index-DYJ_wj27.js → index-Bz6IWncl.js} +186 -186
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- 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/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +86 -200
- package/dist/learn/promote.js +57 -183
- 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 +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/openapi.js +95 -55
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +17 -2
- package/dist/runner/adapter-run-spec.js +16 -5
- package/dist/runner/audit.d.ts +64 -0
- package/dist/runner/audit.js +338 -0
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +15 -5
- package/dist/runner/feedback-round.js +1 -4
- 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 +52 -13
- package/dist/runner/learning-end.js +124 -44
- 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.js +1 -1
- package/dist/runner/promotion.d.ts +50 -54
- package/dist/runner/promotion.js +191 -583
- package/dist/runner/reflect-hook.d.ts +10 -0
- package/dist/runner/reflect-hook.js +6 -0
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/server.js +61 -16
- package/dist/store/sqlite/store.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/learning.d.ts +17 -6
- package/dist/store-reads/learning.js +36 -23
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-view.js +12 -2
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +9 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- 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/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/compile.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { RunRow, Store } from "../store/store.js";
|
|
2
2
|
import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
|
|
3
|
-
import { type CheckRecord, type PromotionRecord } from "./promote.js";
|
|
3
|
+
import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
|
|
4
4
|
/** How many of the agent's last runs (before the ending one, which is in the session already) the compile turn reads. */
|
|
5
5
|
export declare const COMPILE_TRACES = 5;
|
|
6
6
|
/** How many times a refused draft goes back to the model with its errors: at most 1 + COMPILE_RETRIES attempts. */
|
|
7
7
|
export declare const COMPILE_RETRIES = 3;
|
|
8
|
-
/** How many of an agent's runs before the ending one are read for an earlier compile: one there (it may still wait for
|
|
9
|
-
* its grade, or it failed) asks none now, so a job is compiled at most once in that many runs. */
|
|
10
|
-
export declare const COMPILE_QUIET_RUNS = 4;
|
|
11
8
|
/** The longest the compile turn may take, every attempt in it, before the run ends with what it has. */
|
|
12
9
|
export declare const COMPILE_TIMEOUT_MS: number;
|
|
13
10
|
/** The most of a run's trace the compile turn holds, in characters. */
|
|
@@ -15,38 +12,16 @@ export declare const TRACE_MAX = 4000;
|
|
|
15
12
|
/** The most of the agent's notes, together, the compile turn reads, in characters. It reads them whole, every rule kept:
|
|
16
13
|
* notes over it compile nothing, and the record says why (compileTurn), never a workflow from a cut set of rules. */
|
|
17
14
|
export declare const NOTES_MAX = 96000;
|
|
18
|
-
/** A workflow
|
|
19
|
-
*
|
|
20
|
-
export interface ReviseAsk {
|
|
21
|
-
readonly workflow: string;
|
|
22
|
-
readonly served_usd: number;
|
|
23
|
-
readonly by_hand_usd: number;
|
|
24
|
-
readonly runs: number;
|
|
25
|
-
}
|
|
26
|
-
/** A workflow its promotion holds (runner/promotion.ts, learn/promote.ts): the run went by hand, and the hold's record
|
|
27
|
-
* says why, from its replay on the agent's graded inputs (`replay`'s numbers) or the graded runs it served (`reason`). */
|
|
15
|
+
/** A workflow its promotion holds (runner/promotion.ts, learn/promote.ts): the run went by hand, and the hold's record says
|
|
16
|
+
* why, from its one check on the agent's own runs (`check`'s numbers and the inputs it disagreed on) or its `reason`. */
|
|
28
17
|
export interface HeldAsk {
|
|
29
18
|
readonly workflow: string;
|
|
30
19
|
readonly digest: string;
|
|
31
|
-
readonly source: PromotionRecord["source"];
|
|
32
20
|
readonly reason: string;
|
|
33
|
-
readonly replay?: {
|
|
34
|
-
readonly n: number;
|
|
35
|
-
readonly agree: number;
|
|
36
|
-
readonly agent_acc: number;
|
|
37
|
-
readonly wf_acc: number;
|
|
38
|
-
readonly delta: number;
|
|
39
|
-
readonly handed_back: number;
|
|
40
|
-
};
|
|
41
|
-
/** A check's hold (source `check`): its numbers and bar, and the inputs it disagreed on, which the recompile reads as
|
|
42
|
-
* data. */
|
|
43
21
|
readonly check?: CheckRecord;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export interface GradedAsk {
|
|
48
|
-
readonly answer: string;
|
|
49
|
-
readonly words: string;
|
|
22
|
+
/** An audit's hold (runner/audit.ts): its window and bar, and the audited runs it disagreed on with the
|
|
23
|
+
* agent's own answer, which the recompile reads as data. */
|
|
24
|
+
readonly audit?: AuditHold;
|
|
50
25
|
}
|
|
51
26
|
/** One of the agent's earlier runs as the compile turn reads it: what it was asked, each tool call it made (`tool`, its
|
|
52
27
|
* input as the timeline previews it, and whether it failed), its answer, and what a person said after (feedback). */
|
|
@@ -61,13 +36,11 @@ export interface CompileTrace {
|
|
|
61
36
|
readonly feedback: readonly string[];
|
|
62
37
|
}
|
|
63
38
|
/** What the compile turn is asked with. `mode` new: the job as a new workflow; revise: `workflow`, whose text is
|
|
64
|
-
* `current`, again whole,
|
|
65
|
-
* said the answer it gave this run alone was wrong (`graded`) or its promotion holds it (`held`).
|
|
39
|
+
* `current`, again whole, once its promotion holds it (`held`).
|
|
66
40
|
* `reference`: the workflow language as compileReference renders it. `notes`: the agent's active notes, whole.
|
|
67
41
|
* `traces`: its last runs. `input`: this run's input as it was launched, whose fields a workflow's input takes. `tools`:
|
|
68
42
|
* those a call node may run, with what each takes and gives (`described`); `judges`: whether the run has a decision
|
|
69
|
-
* provider (judge, pick and sift nodes are allowed)
|
|
70
|
-
* now that no step takes a guard).
|
|
43
|
+
* provider (judge, pick and sift nodes are allowed).
|
|
71
44
|
* `outputSchema`: the agent's, when it has one: a run serving the workflow serves its answer shaped to it, else hands the
|
|
72
45
|
* run back (answer-json.ts answerAsServed), so the workflow's final output must be that object. */
|
|
73
46
|
export type CompileAsk = {
|
|
@@ -87,7 +60,6 @@ export type CompileAsk = {
|
|
|
87
60
|
readonly does: string;
|
|
88
61
|
}[];
|
|
89
62
|
readonly judges: boolean;
|
|
90
|
-
readonly jev?: boolean;
|
|
91
63
|
} & ({
|
|
92
64
|
readonly mode: "new";
|
|
93
65
|
} | {
|
|
@@ -97,10 +69,7 @@ export type CompileAsk = {
|
|
|
97
69
|
/** The commit of main `current` was read at: the revision's conflict base (its merge refuses a change to the workflow
|
|
98
70
|
* on main after this read, never one before it, which the revision was written over). Never told the model. */
|
|
99
71
|
readonly base?: string;
|
|
100
|
-
readonly
|
|
101
|
-
readonly revise?: ReviseAsk;
|
|
102
|
-
readonly graded?: GradedAsk;
|
|
103
|
-
readonly held?: HeldAsk;
|
|
72
|
+
readonly held: HeldAsk;
|
|
104
73
|
});
|
|
105
74
|
/** One attempt of the compile turn: whether its draft passed the checks, and else why not, in the checks' words. */
|
|
106
75
|
export type CompileAttempt = {
|
|
@@ -118,50 +87,66 @@ export type CompiledRecord = {
|
|
|
118
87
|
readonly digest?: string;
|
|
119
88
|
readonly promoted?: boolean;
|
|
120
89
|
};
|
|
121
|
-
/** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted,
|
|
122
|
-
*
|
|
123
|
-
* was skipped for a newer one; undefined while it is queued or replayed, or before its first claim decides it. */
|
|
90
|
+
/** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, false
|
|
91
|
+
* while held; undefined while its check runs, or before its first claim decides it. */
|
|
124
92
|
export declare function promotedOf(records: readonly PromotionRecord[], workflow: string, digest: string): boolean | undefined;
|
|
125
93
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
126
94
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* too): nothing compiles it again. */
|
|
95
|
+
* hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
|
|
96
|
+
* compiles it again. */
|
|
130
97
|
export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
|
|
131
|
-
/**
|
|
98
|
+
/** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
|
|
99
|
+
* learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
|
|
100
|
+
export declare const DRAFT_FAILED = "its draft failed its checks";
|
|
101
|
+
/** Whether a promotion record is a compile turn's failed draft (DRAFT_FAILED), not a check's decision. */
|
|
102
|
+
export declare const draftFailedOf: (record: PromotionRecord) => boolean;
|
|
103
|
+
/** Which compile a new workflow's is, for an agent with no learned workflow: 2 (the one recompile) right after a first
|
|
104
|
+
* compile whose drafts all failed their checks (the agent's newest record), else 1. */
|
|
105
|
+
export declare function newCompileAttempt(records: readonly PromotionRecord[]): 1 | 2;
|
|
106
|
+
/** Whether the agent's compile stopped on its drafts: its newest record is a recompile's failed draft (nothing compiles
|
|
107
|
+
* a new workflow again until its owner acts). */
|
|
108
|
+
export declare function compileStoppedOf(records: readonly PromotionRecord[]): boolean;
|
|
109
|
+
/** Whether a store run ended completed (its state `ended`, a plain completion), and is no audit's shadow run (an
|
|
110
|
+
* agent's answer kept for an audit, never a run of the agent's own to learn from). */
|
|
132
111
|
export declare const completedRun: (run: {
|
|
112
|
+
readonly id: string;
|
|
133
113
|
readonly state: string;
|
|
134
114
|
readonly outcome: string | null;
|
|
135
115
|
}) => boolean;
|
|
136
116
|
/** Whether a store run is a completed run of the agent's own (completedRun), not one its learned workflow answered alone
|
|
137
|
-
* nor a check's replay run: what compile_after counts. */
|
|
117
|
+
* nor a check's replay run (nor an audit's shadow, completedRun): what compile_after counts. */
|
|
138
118
|
export declare const agentRun: (run: {
|
|
119
|
+
readonly id: string;
|
|
139
120
|
readonly state: string;
|
|
140
121
|
readonly outcome: string | null;
|
|
141
122
|
readonly metrics?: unknown;
|
|
142
123
|
}) => boolean;
|
|
143
|
-
/** The agent's
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
124
|
+
/** The agent's newest `n` runs that `keep` keeps (of those the store lists by `listed`: e.g. only ended, not archived),
|
|
125
|
+
* newest first, picked before anything else limits them: runs it does not keep, however many, never push them out of the
|
|
126
|
+
* read (it reads more of the agent's runs until it has `n`, or there are no more). */
|
|
127
|
+
export declare function lastRunsOf(store: Pick<Store, "runs">, agentId: string, n: number, keep: (row: RunRow) => boolean, listed?: {
|
|
128
|
+
readonly state?: "ended";
|
|
129
|
+
readonly archived?: false;
|
|
130
|
+
}): Promise<RunRow[]>;
|
|
131
|
+
/** The agent's last `n` completed runs of its own (agentRun: not one its learned workflow answered alone, not a replay
|
|
132
|
+
* nor a shadow audit; never `exceptRunId`, an archived run or an imported one), newest first (lastRunsOf: runs its
|
|
133
|
+
* workflow served since never push them out of the read). The one read of what compile_after counts and of a check's
|
|
134
|
+
* inputs. */
|
|
135
|
+
export declare const lastOwnRuns: (store: Pick<Store, "runs">, agentId: string, n: number, exceptRunId?: string) => Promise<RunRow[]>;
|
|
148
136
|
/** Whether a run's look-back compiles its agent's job: the run completed, the agent has no learned workflow (active or
|
|
149
|
-
* waiting for its owner's OK),
|
|
137
|
+
* waiting for its owner's OK), and it has `compileAfter` completed
|
|
150
138
|
* agent runs (its definition's compile_after, learning-setting.ts), the ending one counted. */
|
|
151
139
|
export declare const compileDue: (facts: {
|
|
152
140
|
readonly completed: boolean;
|
|
153
141
|
readonly runs: number;
|
|
154
142
|
readonly workflows: number;
|
|
155
|
-
readonly compiledLately: boolean;
|
|
156
143
|
readonly compileAfter: number;
|
|
157
144
|
}) => boolean;
|
|
158
145
|
/** This host's addendum to the DSL's author contract: the node kinds it runs, and its rules, each one the checks hold a
|
|
159
|
-
* draft to (learn/skills.ts draftProblems; propose.ts; check.ts
|
|
160
|
-
* escalate steps hand back, so `jev` (whether the run can call Jev) changes no rule. */
|
|
146
|
+
* draft to (learn/skills.ts draftProblems; propose.ts; check.ts). */
|
|
161
147
|
export declare function learnedHost(options: {
|
|
162
148
|
readonly tools: readonly string[];
|
|
163
149
|
readonly judges: boolean;
|
|
164
|
-
readonly jev?: boolean;
|
|
165
150
|
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
166
151
|
}): AuthorHostAddendum;
|
|
167
152
|
/** The workflow language for the compile turn, generated: the DSL's own author contract (rendered from its vocabulary, so
|
|
@@ -173,7 +158,6 @@ export declare const compileReference: (dsl: {
|
|
|
173
158
|
}, options: {
|
|
174
159
|
readonly tools: readonly string[];
|
|
175
160
|
readonly judges: boolean;
|
|
176
|
-
readonly jev?: boolean;
|
|
177
161
|
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
178
162
|
}) => string;
|
|
179
163
|
/** The worked example's input, as a run gives it. */
|
|
@@ -188,7 +172,7 @@ export declare const EXAMPLE_TOOL = "fetch_page";
|
|
|
188
172
|
* the run has a tool), an extract step copies compact facts from the page, the verbatim lines the answer will quote among
|
|
189
173
|
* them. The answer on the agent's own model (no tier: answerTierProblems) from those facts and its own draft alone, never
|
|
190
174
|
* the page (compactStateProblems), in a re-pick loop of 2 until its quotes are in the page (quoteCheckProblems); then the
|
|
191
|
-
* quote check hands back a second miss, and an escalate step a case the policy does not cover.
|
|
175
|
+
* quote check hands back a second miss, and an escalate step a case the policy does not cover.
|
|
192
176
|
* With no tool to fetch with, the facts come from the input and the answer quotes nothing it must check. */
|
|
193
177
|
export declare function compileExample(fetches?: boolean): Record<string, unknown>;
|
|
194
178
|
/** Whether `text` is a compile ask: `again` for an attempt the checks sent back, true for the first, else false. */
|
|
@@ -203,16 +187,12 @@ export declare function compilePrompt(ask: CompileAsk): string;
|
|
|
203
187
|
* fenced as data), and the attempt it was. */
|
|
204
188
|
export declare function compileAgain(errors: readonly string[], attempt: number): string;
|
|
205
189
|
/** A compile answer read: the draft's block whole (to check), its name and the notes it says it carries out (only ones
|
|
206
|
-
* the turn was given);
|
|
207
|
-
* read. */
|
|
190
|
+
* the turn was given); else why it can't be read. */
|
|
208
191
|
export type CompileRead = {
|
|
209
192
|
readonly ok: true;
|
|
210
193
|
readonly name: string;
|
|
211
194
|
readonly block: string;
|
|
212
195
|
readonly from_notes: readonly string[];
|
|
213
|
-
} | {
|
|
214
|
-
readonly ok: false;
|
|
215
|
-
readonly unchanged: true;
|
|
216
196
|
} | {
|
|
217
197
|
readonly ok: false;
|
|
218
198
|
readonly error: string;
|
|
@@ -237,18 +217,13 @@ type CheckedLike = {
|
|
|
237
217
|
/** Why the checks did not keep draft `name` from `checked` (each problem's words, its path's in front when it names
|
|
238
218
|
* another file); none when its workflow.json is in the proposal. */
|
|
239
219
|
export declare function draftErrorsOf(checked: CheckedLike | undefined, name: string): string[];
|
|
240
|
-
/** The guards a draft carries, one line each: none is asked for (learnedHost's rules: code checks and escalate steps
|
|
241
|
-
* hand back; chain14b's step guards made 0 judgments live and its page and facts guards read at chance), so each is
|
|
242
|
-
* refused, the SDK bridge's in its words (it has no guardStep callback). None when no step has one. */
|
|
243
|
-
export declare function guardProblems(doc: unknown, options?: {
|
|
244
|
-
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
245
|
-
}): string[];
|
|
246
220
|
/** The record's workflow when no attempt named one. */
|
|
247
221
|
export declare const UNNAMED = "(unnamed)";
|
|
248
|
-
/** The compile turn, start to end: ask, read, check (`check` over the look-back's answer with the draft in it,
|
|
249
|
-
* guards it must not carry, guardProblems), and on a refusal ask again with the errors, at most 1 + COMPILE_RETRIES
|
|
222
|
+
/** The compile turn, start to end: ask, read, check (`check` over the look-back's answer with the draft in it), and on a refusal ask again with the errors, at most 1 + COMPILE_RETRIES
|
|
250
223
|
* times and within `deadlineMs`. What it ends with: `kept` with the answer and what the checks made of it when an
|
|
251
|
-
* attempt passed; else none, with every attempt
|
|
224
|
+
* attempt passed; else none, with every attempt, and `drafted` when an attempt answered (its drafts failed their
|
|
225
|
+
* checks: the compile's attempt, DRAFT_FAILED; a turn that never answered is none). Notes over NOTES_MAX ask nothing:
|
|
226
|
+
* one attempt says why. */
|
|
252
227
|
export declare function compileTurn<C extends CheckedLike>(input: {
|
|
253
228
|
/** One attempt's ask (`attempt` from 1), within `deadlineMs`: its answer, or undefined when the turn timed out or failed. */
|
|
254
229
|
readonly ask: (prompt: string, attempt: number, deadlineMs: number) => Promise<{
|
|
@@ -268,5 +243,6 @@ export declare function compileTurn<C extends CheckedLike>(input: {
|
|
|
268
243
|
checked: C;
|
|
269
244
|
};
|
|
270
245
|
draftErrors: string[];
|
|
246
|
+
drafted?: true;
|
|
271
247
|
}>;
|
|
272
248
|
export {};
|