@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42
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 +130 -0
- package/NOTICE +2 -0
- package/README.md +149 -21
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- 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 +22 -6
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- 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.d.ts +11 -1
- package/dist/computers.js +23 -26
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +72 -0
- package/dist/eval-mailbox.d.ts +4 -1
- package/dist/eval-mailbox.js +11 -3
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +42 -0
- package/dist/feed/parse.js +291 -0
- 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/learn/check.d.ts +17 -1
- package/dist/learn/check.js +240 -5
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -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 +23 -1
- package/dist/mcp-oauth.js +46 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +151 -21
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-learning-served.d.ts +1 -1
- 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/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +94 -16
- package/dist/runner/adapter-run-spec.d.ts +19 -0
- package/dist/runner/adapter-run-spec.js +57 -36
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +41 -32
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +12 -1
- package/dist/runner/main.js +31 -4
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +6 -2
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +4 -2
- package/dist/runner/model-route.js +8 -8
- package/dist/runner/promotion.d.ts +44 -4
- package/dist/runner/promotion.js +323 -21
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +16 -20
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +21 -7
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +5 -3
- package/dist/server.d.ts +31 -5
- package/dist/server.js +240 -61
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +11 -3
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +64 -10
- package/dist/store/store.d.ts +38 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +8 -2
- package/dist/template-eval.d.ts +11 -0
- package/dist/template-eval.js +177 -52
- package/dist/templates.d.ts +13 -1
- package/dist/templates.js +89 -18
- package/dist/timeline/computer.js +2 -1
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-adapter.d.ts +9 -4
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +420 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/validate.js +7 -2
- package/dist/webhooks.js +9 -5
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +35 -4
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +34 -22
- package/package.json +11 -9
- package/templates/README.md +38 -4
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
package/dist/learn/check.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// which is the grader's. The host reads the copy itself (regular files only, never a link followed) and hands each change
|
|
4
4
|
// here with its bytes; nothing the checker refuses is ever written to git. Every problem it reports is printable: its
|
|
5
5
|
// path and detail are cut of the host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
|
6
|
+
import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
|
|
6
7
|
import { hiddenCharacter } from "./invisible.js";
|
|
7
8
|
import { compiledLineBytes, INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile, ruleOf } from "./notes.js";
|
|
8
9
|
import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
|
|
@@ -183,6 +184,165 @@ export function answerTierProblems(doc) {
|
|
|
183
184
|
answered(doc);
|
|
184
185
|
return problems;
|
|
185
186
|
}
|
|
187
|
+
/** The key each page mark stands for (pageStateOf). */
|
|
188
|
+
const pageKeyOf = new WeakMap();
|
|
189
|
+
/** A state holding a page at each of `pages` and nothing else, as a static read sees it: a page has every path (its
|
|
190
|
+
* fields are the run's), so any path under one reads the page itself. */
|
|
191
|
+
function pageStateOf(pages) {
|
|
192
|
+
const state = Object.create(null);
|
|
193
|
+
for (const key of pages) {
|
|
194
|
+
const mark = new Proxy(Object.create(null), { get: (_target, prop) => (typeof prop === "string" ? mark : undefined) });
|
|
195
|
+
pageKeyOf.set(mark, key);
|
|
196
|
+
state[key] = mark;
|
|
197
|
+
}
|
|
198
|
+
return state;
|
|
199
|
+
}
|
|
200
|
+
/** The mark key (pageStateOf) the placeholder `path` reads in `state`, if it reads one. */
|
|
201
|
+
const markRead = (state, path) => {
|
|
202
|
+
const read = placeholderValue(state, path);
|
|
203
|
+
return read !== null && typeof read === "object" ? pageKeyOf.get(read) : undefined;
|
|
204
|
+
};
|
|
205
|
+
/** The page keys a value reads: each placeholder in its strings, at any depth, as interpolation fills them (the DSL's
|
|
206
|
+
* placeholdersOf: `{path?}` only as a whole string, literal text inside a longer one), resolved by the engine's own
|
|
207
|
+
* lookup (the DSL's placeholderValue: the path as written, so a real `state` key first, then the path after `state.`)
|
|
208
|
+
* over pageStateOf. A key holding compact facts is absent there, so a `{state.x}` read falls back to `x` as the engine
|
|
209
|
+
* may when its `state` key lacks `x`. */
|
|
210
|
+
function pagesRead(value, state, out = new Set(), depth = 0) {
|
|
211
|
+
if (depth > 32)
|
|
212
|
+
return out;
|
|
213
|
+
if (typeof value === "string") {
|
|
214
|
+
for (const { path } of placeholdersOf(value)) {
|
|
215
|
+
const key = markRead(state, path);
|
|
216
|
+
if (key !== undefined)
|
|
217
|
+
out.add(key);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else if (Array.isArray(value))
|
|
221
|
+
value.forEach((one) => pagesRead(one, state, out, depth + 1));
|
|
222
|
+
else if (isObject(value))
|
|
223
|
+
Object.values(value).forEach((one) => pagesRead(one, state, out, depth + 1));
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
/** Why a draft's model step off the fast tier reads a page (compact state): an agent, decide or extract step with no
|
|
227
|
+
* `"tier": "fast"` whose `state` map names a key that may hold a page a call step fetched (a call's result, a map's
|
|
228
|
+
* collected one, a pick or sift over pages, a composed workflow's answer when it is one, the key or anything under it),
|
|
229
|
+
* or, with no `state` map, which reads the whole state while such a key is in it (pagesRead: the engine's own lookup).
|
|
230
|
+
* 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
|
|
231
|
+
* branches each start from the same state and their writes merge, so a key one branch replaced is no page after it; a
|
|
232
|
+
* route runs one branch, so a key stays a page unless every branch replaced it; a loop's body is read pass after pass,
|
|
233
|
+
* each on every page its passes may leave, until the marks stop changing (within its maxIters); a map's body sees
|
|
234
|
+
* `item` as a page when its list is one, and its failedAs rows are short errors, never pages; a composed workflow's
|
|
235
|
+
* 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
|
|
236
|
+
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
237
|
+
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
238
|
+
* One line each, in words the compile retry acts on. */
|
|
239
|
+
export function compactStateProblems(doc) {
|
|
240
|
+
const problems = new Set();
|
|
241
|
+
const walk = (node, pages, depth) => {
|
|
242
|
+
const after = new Set(pages);
|
|
243
|
+
if (!isNode(node) || depth > 32)
|
|
244
|
+
return after;
|
|
245
|
+
const key = writeKeyOf(node);
|
|
246
|
+
const wrote = (page) => {
|
|
247
|
+
if (typeof key !== "string")
|
|
248
|
+
return;
|
|
249
|
+
if (page)
|
|
250
|
+
after.add(key);
|
|
251
|
+
else
|
|
252
|
+
after.delete(key);
|
|
253
|
+
};
|
|
254
|
+
const kind = node.node;
|
|
255
|
+
if (kind === "chain") {
|
|
256
|
+
let state = after;
|
|
257
|
+
for (const step of Array.isArray(node.steps) ? node.steps : [])
|
|
258
|
+
state = walk(step, state, depth + 1);
|
|
259
|
+
return state;
|
|
260
|
+
}
|
|
261
|
+
if (kind === "parallel") {
|
|
262
|
+
// Every branch starts from the same state and the engine merges their writes (disjoint, or the run fails): a key
|
|
263
|
+
// stays a page when no branch replaced it, and a page a branch wrote is one.
|
|
264
|
+
const outs = (Array.isArray(node.branches) ? node.branches : []).map((body) => walk(body, after, depth + 1));
|
|
265
|
+
const merged = new Set([...after].filter((one) => outs.every((out) => out.has(one))));
|
|
266
|
+
for (const out of outs)
|
|
267
|
+
for (const one of out)
|
|
268
|
+
if (!after.has(one))
|
|
269
|
+
merged.add(one);
|
|
270
|
+
return merged;
|
|
271
|
+
}
|
|
272
|
+
if (kind === "route") {
|
|
273
|
+
// One branch runs, after the choice is recorded: a page on any branch's way out is one.
|
|
274
|
+
wrote(false);
|
|
275
|
+
const bodies = childNodes(node);
|
|
276
|
+
if (!bodies.length)
|
|
277
|
+
return after;
|
|
278
|
+
const merged = new Set();
|
|
279
|
+
for (const body of bodies)
|
|
280
|
+
for (const one of walk(body, after, depth + 1))
|
|
281
|
+
merged.add(one);
|
|
282
|
+
return merged;
|
|
283
|
+
}
|
|
284
|
+
if (kind === "loop") {
|
|
285
|
+
// Any pass may be the last (do-while, up to maxIters): walk the body again on every page its passes may leave
|
|
286
|
+
// until the marks stop changing. The set read grows on each further pass, so it stops within one pass a key the
|
|
287
|
+
// workflow names, and never past maxIters; each pass's way out holds the ones before it.
|
|
288
|
+
const passes = typeof node.maxIters === "number" && node.maxIters >= 1 ? Math.floor(node.maxIters) : Number.POSITIVE_INFINITY;
|
|
289
|
+
let read = after;
|
|
290
|
+
let out = walk(node.body, read, depth + 1);
|
|
291
|
+
for (let pass = 2; pass <= passes; pass++) {
|
|
292
|
+
const next = new Set([...read, ...out]);
|
|
293
|
+
if (next.size === read.size)
|
|
294
|
+
break;
|
|
295
|
+
read = next;
|
|
296
|
+
out = walk(node.body, read, depth + 1);
|
|
297
|
+
}
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
if (kind === "map") {
|
|
301
|
+
const itemsPage = typeof node.itemsPath === "string" && after.has(node.itemsPath.split(".")[0]);
|
|
302
|
+
const inner = new Set(after);
|
|
303
|
+
if (itemsPage)
|
|
304
|
+
inner.add("item");
|
|
305
|
+
else
|
|
306
|
+
inner.delete("item");
|
|
307
|
+
const out = walk(node.body, inner, depth + 1);
|
|
308
|
+
const result = typeof node.resultPath === "string" && node.resultPath ? node.resultPath.split(".")[0] : isNode(node.body) && typeof node.body.as === "string" && node.body.as ? node.body.as : undefined;
|
|
309
|
+
// Each item's result, or its whole state (the state around the map too) when nothing picks one key.
|
|
310
|
+
wrote(result !== undefined ? out.has(result) : out.size > 0);
|
|
311
|
+
// Its failed items' rows are short error records, never the items.
|
|
312
|
+
if (typeof node.failedAs === "string" && node.failedAs)
|
|
313
|
+
after.delete(node.failedAs);
|
|
314
|
+
return after;
|
|
315
|
+
}
|
|
316
|
+
if (kind === "workflow") {
|
|
317
|
+
const child = isObject(node.workflow) ? node.workflow : {};
|
|
318
|
+
const input = isObject(node.input) ? node.input : {};
|
|
319
|
+
const state = pageStateOf(after);
|
|
320
|
+
const seen = new Set(Object.entries(input).filter(([, value]) => pagesRead(value, state).size > 0).map(([name]) => name));
|
|
321
|
+
const out = walk(child.root, seen, depth + 1);
|
|
322
|
+
const path = isObject(child.output) && typeof child.output.path === "string" ? child.output.path.split(".")[0] : "";
|
|
323
|
+
wrote(!!path && out.has(path));
|
|
324
|
+
return after;
|
|
325
|
+
}
|
|
326
|
+
if (kind === "call")
|
|
327
|
+
return wrote(true), after;
|
|
328
|
+
if (kind === "pick" || kind === "sift")
|
|
329
|
+
return wrote(typeof node.itemsPath === "string" && after.has(node.itemsPath.split(".")[0])), after;
|
|
330
|
+
if (TIERED_KINDS.has(kind) && node.tier !== "fast") {
|
|
331
|
+
const label = JSON.stringify(String(node.label ?? "(no label)").slice(0, 64));
|
|
332
|
+
const read = node.state === undefined ? [...after] : [...pagesRead(node.state, pageStateOf(after))];
|
|
333
|
+
if (read.length) {
|
|
334
|
+
const what = node.state === undefined
|
|
335
|
+
? `the whole run state (it has no "state" map), the page${read.length > 1 ? "s" : ""} ${read.map((one) => JSON.stringify(one.slice(0, 64))).join(", ")} included`
|
|
336
|
+
: `${read.map((one) => JSON.stringify(`{${one.slice(0, 64)}}`)).join(", ")}, ${read.length > 1 ? "pages" : "a page"} a call step fetched`;
|
|
337
|
+
problems.add(`the ${kind} step ${label} runs off the fast tier and reads ${what}: a page reaches a step on the agent's model only through a fast-tier step's output. Give it a "state" map naming only compact keys (the facts a fast-tier extract step wrote from the pages; in a re-pick loop its own draft too, as "{<its as>?}"), or, for legwork, "tier": "fast"`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
wrote(false);
|
|
341
|
+
return after;
|
|
342
|
+
};
|
|
343
|
+
walk(doc?.root, new Set(), 0);
|
|
344
|
+
return [...problems];
|
|
345
|
+
}
|
|
186
346
|
/** The property names that make an answer carry quotes. */
|
|
187
347
|
const QUOTE_KEYS = new Set(["quote", "quotes"]);
|
|
188
348
|
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -377,13 +537,64 @@ const writesKey = (node, key) => isNode(node) && (writeKeyOf(node) === key || (n
|
|
|
377
537
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
378
538
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
379
539
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|
|
380
|
-
* (a model's summary of a page is no page)
|
|
540
|
+
* (a model's summary of a page is no page), or, those checks in place, the step writing the answer hands back on its
|
|
541
|
+
* first miss instead of re-picking once (a loop of REPICK_PASSES until its check passes), or its quotes have more than
|
|
542
|
+
* one check (a loop's `until` waits on one: the others would hand back with no re-pick). A judge or an `ask` is never the quote check:
|
|
381
543
|
* H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
|
|
382
544
|
* quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
|
|
383
545
|
export function quoteCheckProblems(doc) {
|
|
384
546
|
return isObject(doc) ? quoteRule(doc, {}).problems : [];
|
|
385
547
|
}
|
|
386
548
|
const siteKey = (site) => site.keys.join("\u0000");
|
|
549
|
+
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
550
|
+
const REPICK_PASSES = 2;
|
|
551
|
+
const quoteMissingText = ({ path, field, pages }) => `{"predicate": "quote_missing", "path": ${JSON.stringify(path)}${field ? `, "field": ${JSON.stringify(field)}` : ""}, "pages": ${JSON.stringify(pages)}}`;
|
|
552
|
+
/** Whether `step` is the re-pick of an answer `check` reads: a loop of REPICK_PASSES until that check's quote_missing (its
|
|
553
|
+
* path, field and pages) no longer holds. */
|
|
554
|
+
const repicks = (step, check) => {
|
|
555
|
+
if (!isNode(step) || step.node !== "loop" || step.maxIters !== REPICK_PASSES || !isObject(step.until) || step.until.predicate !== "not" || !isObject(step.until.of))
|
|
556
|
+
return false;
|
|
557
|
+
const of = step.until.of;
|
|
558
|
+
return of.predicate === "quote_missing" && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
|
|
559
|
+
};
|
|
560
|
+
/** Whether a step's `state` map names state key `key` as the whole marked placeholder `"{answer?}"` (a whole string):
|
|
561
|
+
* null on a re-pick loop's first pass, before any draft exists, and the failed draft on its second. No path below the
|
|
562
|
+
* key counts (`"{answer.x?}"`, `"{state.answer?}"`, unmarked `"{answer}"`): paths are not validated, so only the key
|
|
563
|
+
* itself is sure to hold the draft. */
|
|
564
|
+
function readsDraft(state, key, depth = 0) {
|
|
565
|
+
if (depth > 32)
|
|
566
|
+
return false;
|
|
567
|
+
if (typeof state === "string")
|
|
568
|
+
return placeholdersOf(state).some(({ path, optional }) => optional && path === key);
|
|
569
|
+
if (Array.isArray(state))
|
|
570
|
+
return state.some((one) => readsDraft(one, key, depth + 1));
|
|
571
|
+
return isObject(state) && Object.values(state).some((one) => readsDraft(one, key, depth + 1));
|
|
572
|
+
}
|
|
573
|
+
/** The labels of the model steps inside `node` (a loop's body) that write state key `key` without reading their own
|
|
574
|
+
* draft through their `state` map (readsDraft). The DSL sends a step with a map only the keys it names (each pass a
|
|
575
|
+
* fresh model session), so one not naming the draft never sees it on the re-pick; naming it unmarked (`"{answer}"`)
|
|
576
|
+
* fails the first pass, which has none yet; and a step with no map reads the whole state, the pages included, which no
|
|
577
|
+
* step off the fast tier may (compactStateProblems). A map's or a composed workflow's own steps write their item's or
|
|
578
|
+
* child's state, not this one. */
|
|
579
|
+
const blindRepicks = (node, key, depth = 0) => {
|
|
580
|
+
if (!isNode(node) || depth > 32)
|
|
581
|
+
return [];
|
|
582
|
+
const own = writeKeyOf(node) === key && TIERED_KINDS.has(node.node) && !readsDraft(node.state, key) ? [String(node.label ?? node.node).slice(0, 64)] : [];
|
|
583
|
+
const inner = node.node === "map" || node.node === "workflow" ? [] : childNodes(node).flatMap((child) => blindRepicks(child, key, depth + 1));
|
|
584
|
+
return [...own, ...inner];
|
|
585
|
+
};
|
|
586
|
+
/** How a re-pick step reads its failed draft, as a refusal says it. */
|
|
587
|
+
const draftWords = (key) => `a "state" map naming the compact facts it answers from and its failed draft as an optional placeholder, "draft": "{${key}?}" (null on the first pass, before any draft exists; the failed draft on the second)`;
|
|
588
|
+
/** The labels of the quote_missing escalates inside `node` (a loop's body), a composed workflow's included: each hands
|
|
589
|
+
* back on the first pass's miss, so a re-pick loop around one never re-picks. */
|
|
590
|
+
const quoteEscalatesIn = (node, depth = 0) => {
|
|
591
|
+
if (!isNode(node) || depth > 32)
|
|
592
|
+
return [];
|
|
593
|
+
if (node.node === "escalate")
|
|
594
|
+
return isObject(node.when) && node.when.predicate === "quote_missing" ? [String(node.label ?? "(no label)").slice(0, 64)] : [];
|
|
595
|
+
const inner = node.node === "workflow" && isObject(node.workflow) ? [node.workflow.root] : childNodes(node);
|
|
596
|
+
return inner.flatMap((child) => quoteEscalatesIn(child, depth + 1));
|
|
597
|
+
};
|
|
387
598
|
/** quoteCheckProblems for one workflow (the draft's, or a composed workflow node's child, its schemas its own else
|
|
388
599
|
* `schemasAround`): whether the rule applies (its answer carries quotes and it fetches pages), and why it fails. Only a
|
|
389
600
|
* run's path through its top-level chain is sure to pass a step: a check is an escalate on quote_missing that is a step
|
|
@@ -439,7 +650,7 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
439
650
|
const field = read.field ?? "";
|
|
440
651
|
if (checks.some((check) => check.path === path && check.field === field))
|
|
441
652
|
continue;
|
|
442
|
-
const predicate =
|
|
653
|
+
const predicate = quoteMissingText({ path, field, pages });
|
|
443
654
|
problems.push(`the answer carries quotes (${where(site)}) and the workflow fetches pages: check them in code, with an escalate ${predicate} as a step of its top-level chain after the step that writes the answer (pages: the state keys its call steps write), never a judge`);
|
|
444
655
|
}
|
|
445
656
|
for (const { label, pages: read } of checks)
|
|
@@ -448,6 +659,27 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
448
659
|
if (!pages.includes(head))
|
|
449
660
|
problems.push(`the quote_missing escalate ${JSON.stringify(label)} reads ${JSON.stringify(String(page).slice(0, 64))} as a page, which no call step fetched: its pages are the state keys its call steps write (${pages.join(", ")})`);
|
|
450
661
|
}
|
|
662
|
+
// Once the checks hold, the answer re-picks once before one hands back (H5d, preregistered: the answer step once more
|
|
663
|
+
// over the run's pages kept 26 of 31 misses, right 76.9% against the draft's 50.0%, at 11.6% of the agent's cost
|
|
664
|
+
// where handing every miss back cost 21.7%): the step writing it is a loop of REPICK_PASSES until its check passes.
|
|
665
|
+
// A loop's `until` is one predicate and none joins two, so the loop waits on every check only when they are all one
|
|
666
|
+
// check (the same path, field and pages): a loop watching one of several lets the others hand back with no re-pick.
|
|
667
|
+
const [first] = checks;
|
|
668
|
+
const distinct = new Set(checks.map(quoteMissingText)).size;
|
|
669
|
+
if (!problems.length && distinct > 1) {
|
|
670
|
+
problems.push(`the answer's quotes are checked by ${distinct} different quote_missing escalates, and a re-pick loop's "until" reads one check (no predicate joins two), so the loop would let the others hand back with no re-pick: give the answer's quotes one place one check reads (a quote, a list of quotes or a list of records each holding its quote at one field), one quote_missing escalate on it after the step that writes the answer, and that step the body of a loop {"node": "loop", "label": "repick", "maxIters": ${REPICK_PASSES}, "until": {"predicate": "not", "of": <that same quote_missing>}, "body": <the step>}`);
|
|
671
|
+
}
|
|
672
|
+
else if (!problems.length && first && isNode(writer) && writer.node === "loop" && quoteEscalatesIn(writer.body).length) {
|
|
673
|
+
// A check inside the loop's body hands back on the first draft's miss: the loop never re-picks.
|
|
674
|
+
problems.push(`the re-pick loop ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} holds the quote_missing escalate ${JSON.stringify(quoteEscalatesIn(writer.body)[0])} in its body, which hands back on the first draft's miss, so the loop never re-picks: the check after the loop, never inside it, as a step of the top-level chain`);
|
|
675
|
+
}
|
|
676
|
+
else if (!problems.length && first && isNode(writer) && writer.node === "loop" && repicks(writer, first) && blindRepicks(writer.body, answerPath.split(".")[0]).length) {
|
|
677
|
+
// The re-pick must see the failed draft, and only through a state map that names it optionally (never the pages).
|
|
678
|
+
problems.push(`the step ${JSON.stringify(blindRepicks(writer.body, answerPath.split(".")[0])[0])} in the re-pick loop ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer without reading its failed draft, so its second pass writes the same miss again: give it ${draftWords(answerPath.split(".")[0])}. Naming it unmarked ("{${answerPath.split(".")[0]}}") fails the first pass, and no "state" map reads the whole state, the pages included`);
|
|
679
|
+
}
|
|
680
|
+
else if (!problems.length && first && !checks.every((check) => repicks(writer, check))) {
|
|
681
|
+
problems.push(`the step ${JSON.stringify(String(isNode(writer) ? writer.label ?? writer.node : "(no label)").slice(0, 64))} writes the answer and the escalate ${JSON.stringify(first.label)} hands it back on its first quote miss: give it one re-pick first, the step in a loop {"node": "loop", "label": "repick", "maxIters": ${REPICK_PASSES}, "until": {"predicate": "not", "of": ${quoteMissingText(first)}}, "body": <the step>} in its place, the step with ${draftWords(answerPath.split(".")[0])} and its instructions saying that a draft there failed the quote check, so a draft quoting text no page holds is written once more and only a second miss hands back: the check after the loop, never inside it`);
|
|
682
|
+
}
|
|
451
683
|
}
|
|
452
684
|
// A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
|
|
453
685
|
if (problems.length && child.problems.length)
|
|
@@ -458,7 +690,8 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
458
690
|
* regular file within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a skill's
|
|
459
691
|
* front matter (skillProblems), with no `status`, which is the host's; a draft the DSL validates against `tools` with
|
|
460
692
|
* no node that runs code (draftProblems), whose answering step runs on the agent's model (answerTierProblems), whose
|
|
461
|
-
* quotes of the pages it fetched are checked in code
|
|
693
|
+
* steps there read no page (compactStateProblems), whose quotes of the pages it fetched are checked in code
|
|
694
|
+
* (quoteCheckProblems); a README that names its folder and says what
|
|
462
695
|
* the draft is for. */
|
|
463
696
|
function learnedChecked(change, place, refused, input, add) {
|
|
464
697
|
const { path } = change;
|
|
@@ -486,10 +719,12 @@ function learnedChecked(change, place, refused, input, add) {
|
|
|
486
719
|
if (!input.dsl)
|
|
487
720
|
throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
|
|
488
721
|
const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.decisions, input.workflowAdapters);
|
|
489
|
-
// A draft the DSL reads parses: its answering step is held to the agent's model,
|
|
722
|
+
// A draft the DSL reads parses: its answering step is held to the agent's model, its steps there to compact state
|
|
723
|
+
// (the SDK bridge's runNode picks every model itself: it names no tier), and its quote check to code.
|
|
490
724
|
if (!problems.length) {
|
|
491
725
|
const doc = JSON.parse(text);
|
|
492
|
-
|
|
726
|
+
const compact = input.workflowAdapters === undefined ? compactStateProblems(doc) : [];
|
|
727
|
+
problems.push(...[...answerTierProblems(doc), ...compact, ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
|
|
493
728
|
}
|
|
494
729
|
for (const { rule, detail } of problems)
|
|
495
730
|
add(rule, detail, path);
|
package/dist/learn/compile.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import type { RunRow, Store } from "../store/store.js";
|
|
1
2
|
import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
|
|
2
|
-
import { type PromotionRecord } from "./promote.js";
|
|
3
|
-
/** How many active notes an agent keeps before its look-back compiles its job. */
|
|
4
|
-
export declare const COMPILE_AFTER_NOTES = 3;
|
|
5
|
-
/** How many completed runs an agent has (the ending one counted) before its look-back compiles its job. */
|
|
6
|
-
export declare const COMPILE_AFTER_RUNS = 5;
|
|
3
|
+
import { type CheckRecord, type PromotionRecord } from "./promote.js";
|
|
7
4
|
/** How many of the agent's last runs (before the ending one, which is in the session already) the compile turn reads. */
|
|
8
5
|
export declare const COMPILE_TRACES = 5;
|
|
9
6
|
/** How many times a refused draft goes back to the model with its errors: at most 1 + COMPILE_RETRIES attempts. */
|
|
@@ -41,6 +38,9 @@ export interface HeldAsk {
|
|
|
41
38
|
readonly delta: number;
|
|
42
39
|
readonly handed_back: number;
|
|
43
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
|
+
readonly check?: CheckRecord;
|
|
44
44
|
}
|
|
45
45
|
/** A run its learned workflow answered alone that a grade said was wrong (runner/feedback-round.ts, a `revise` round):
|
|
46
46
|
* the workflow's answer and the grade's words, each cut of the run's secrets. */
|
|
@@ -66,7 +66,8 @@ export interface CompileTrace {
|
|
|
66
66
|
* `reference`: the workflow language as compileReference renders it. `notes`: the agent's active notes, whole.
|
|
67
67
|
* `traces`: its last runs. `input`: this run's input as it was launched, whose fields a workflow's input takes. `tools`:
|
|
68
68
|
* 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); `jev`: whether one of them is Jev, not denied (
|
|
69
|
+
* provider (judge, pick and sift nodes are allowed); `jev`: whether one of them is Jev, not denied (no rule reads it
|
|
70
|
+
* now that no step takes a guard).
|
|
70
71
|
* `outputSchema`: the agent's, when it has one: a run serving the workflow serves its answer shaped to it, else hands the
|
|
71
72
|
* run back (answer-json.ts answerAsServed), so the workflow's final output must be that object. */
|
|
72
73
|
export type CompileAsk = {
|
|
@@ -124,23 +125,39 @@ export declare function promotedOf(records: readonly PromotionRecord[], workflow
|
|
|
124
125
|
/** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
|
|
125
126
|
* that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
|
|
126
127
|
* graded hold counts: with it held there is no champion. One with a revision queued is not: that newer revision replays
|
|
127
|
-
* next (a replay ahead of it held meanwhile asks for nothing).
|
|
128
|
+
* next (a replay ahead of it held meanwhile asks for nothing). Nor one a check stopped (its recompile's check held it
|
|
129
|
+
* too): nothing compiles it again. */
|
|
128
130
|
export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
|
|
131
|
+
/** Whether a store run ended completed (its state `ended`, a plain completion). */
|
|
132
|
+
export declare const completedRun: (run: {
|
|
133
|
+
readonly state: string;
|
|
134
|
+
readonly outcome: string | null;
|
|
135
|
+
}) => boolean;
|
|
136
|
+
/** 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. */
|
|
138
|
+
export declare const agentRun: (run: {
|
|
139
|
+
readonly state: string;
|
|
140
|
+
readonly outcome: string | null;
|
|
141
|
+
readonly metrics?: unknown;
|
|
142
|
+
}) => boolean;
|
|
143
|
+
/** The agent's last `n` completed runs of its own (agentRun: not one its learned workflow answered alone, not a replay;
|
|
144
|
+
* never `exceptRunId`, an archived run or an imported one), newest first, picked before anything else limits them: runs
|
|
145
|
+
* its workflow served since, however many, never push them out of the read (it reads more of the agent's ended runs
|
|
146
|
+
* until it has `n`, or there are no more). The one read of what compile_after counts and of a check's inputs. */
|
|
147
|
+
export declare function lastOwnRuns(store: Pick<Store, "runs">, agentId: string, n: number, exceptRunId?: string): Promise<RunRow[]>;
|
|
129
148
|
/** Whether a run's look-back compiles its agent's job: the run completed, the agent has no learned workflow (active or
|
|
130
|
-
* waiting for its owner's OK), none of its last COMPILE_QUIET_RUNS runs compiled, and it
|
|
131
|
-
*
|
|
149
|
+
* waiting for its owner's OK), none of its last COMPILE_QUIET_RUNS runs compiled, and it has `compileAfter` completed
|
|
150
|
+
* agent runs (its definition's compile_after, learning-setting.ts), the ending one counted. */
|
|
132
151
|
export declare const compileDue: (facts: {
|
|
133
152
|
readonly completed: boolean;
|
|
134
|
-
readonly notes: number;
|
|
135
153
|
readonly runs: number;
|
|
136
154
|
readonly workflows: number;
|
|
137
155
|
readonly compiledLately: boolean;
|
|
156
|
+
readonly compileAfter: number;
|
|
138
157
|
}) => boolean;
|
|
139
|
-
/** The threshold a compiled step's guard starts at (SPEC: the guard shape), until the host fits one on graded runs. */
|
|
140
|
-
export declare const GUARD_THRESHOLD = 0.7;
|
|
141
158
|
/** This host's addendum to the DSL's author contract: the node kinds it runs, and its rules, each one the checks hold a
|
|
142
|
-
* draft to (learn/skills.ts draftProblems; propose.ts).
|
|
143
|
-
*
|
|
159
|
+
* draft to (learn/skills.ts draftProblems; propose.ts; check.ts; guardProblems). No step takes a guard: code checks and
|
|
160
|
+
* escalate steps hand back, so `jev` (whether the run can call Jev) changes no rule. */
|
|
144
161
|
export declare function learnedHost(options: {
|
|
145
162
|
readonly tools: readonly string[];
|
|
146
163
|
readonly judges: boolean;
|
|
@@ -161,14 +178,19 @@ export declare const compileReference: (dsl: {
|
|
|
161
178
|
}) => string;
|
|
162
179
|
/** The worked example's input, as a run gives it. */
|
|
163
180
|
export declare const EXAMPLE_INPUT: {
|
|
164
|
-
readonly content: "
|
|
181
|
+
readonly content: "Is the parser library at https://example.org/parser under a permissive licence?";
|
|
165
182
|
};
|
|
166
|
-
/** The worked example
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
|
|
183
|
+
/** The tool the worked example's call step names: it stands for the tool the agent's runs read pages with. */
|
|
184
|
+
export declare const EXAMPLE_TOOL = "fetch_page";
|
|
185
|
+
/** The worked example: the cascade skeleton every repeated job compiles to (H1, H5d: ~$0.08 a run booked against the
|
|
186
|
+
* agent's ~$0.89), a whole job, input to answer, that the checks and the dry run pass (a test holds it to them). The
|
|
187
|
+
* legwork on the fast tier: an extract step reads the target from the input, a call step fetches its page (`fetches`:
|
|
188
|
+
* the run has a tool), an extract step copies compact facts from the page, the verbatim lines the answer will quote among
|
|
189
|
+
* them. The answer on the agent's own model (no tier: answerTierProblems) from those facts and its own draft alone, never
|
|
190
|
+
* 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. No step takes a guard.
|
|
192
|
+
* With no tool to fetch with, the facts come from the input and the answer quotes nothing it must check. */
|
|
193
|
+
export declare function compileExample(fetches?: boolean): Record<string, unknown>;
|
|
172
194
|
/** Whether `text` is a compile ask: `again` for an attempt the checks sent back, true for the first, else false. */
|
|
173
195
|
export declare const askedForCompile: (text: unknown) => "again" | boolean;
|
|
174
196
|
/** What a compiled workflow gives (#2412): the job's answer as the runs gave it, never a summary of it. */
|
|
@@ -215,17 +237,16 @@ type CheckedLike = {
|
|
|
215
237
|
/** Why the checks did not keep draft `name` from `checked` (each problem's words, its path's in front when it names
|
|
216
238
|
* another file); none when its workflow.json is in the proposal. */
|
|
217
239
|
export declare function draftErrorsOf(checked: CheckedLike | undefined, name: string): string[];
|
|
218
|
-
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
export declare function guardProblems(doc: unknown, options
|
|
222
|
-
readonly jev: boolean;
|
|
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?: {
|
|
223
244
|
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
224
245
|
}): string[];
|
|
225
246
|
/** The record's workflow when no attempt named one. */
|
|
226
247
|
export declare const UNNAMED = "(unnamed)";
|
|
227
248
|
/** The compile turn, start to end: ask, read, check (`check` over the look-back's answer with the draft in it, then the
|
|
228
|
-
* guards
|
|
249
|
+
* guards it must not carry, guardProblems), and on a refusal ask again with the errors, at most 1 + COMPILE_RETRIES
|
|
229
250
|
* times and within `deadlineMs`. What it ends with: `kept` with the answer and what the checks made of it when an
|
|
230
251
|
* attempt passed; else none, with every attempt. Notes over NOTES_MAX ask nothing: one attempt says why. */
|
|
231
252
|
export declare function compileTurn<C extends CheckedLike>(input: {
|