@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE +2 -0
  3. package/README.md +85 -19
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/calendar/address.d.ts +49 -0
  7. package/dist/calendar/address.js +153 -0
  8. package/dist/calendar/fetch.d.ts +24 -0
  9. package/dist/calendar/fetch.js +146 -0
  10. package/dist/calendar/ics-faux.d.ts +39 -0
  11. package/dist/calendar/ics-faux.js +236 -0
  12. package/dist/calendar/labels.d.ts +3 -0
  13. package/dist/calendar/labels.js +61 -0
  14. package/dist/calendar/names.d.ts +52 -0
  15. package/dist/calendar/names.js +54 -0
  16. package/dist/calendar/parse.d.ts +108 -0
  17. package/dist/calendar/parse.js +625 -0
  18. package/dist/calendar/routes.d.ts +17 -0
  19. package/dist/calendar/routes.js +81 -0
  20. package/dist/calendar/tools.d.ts +23 -0
  21. package/dist/calendar/tools.js +124 -0
  22. package/dist/cli.js +3 -1
  23. package/dist/computer-record.d.ts +55 -0
  24. package/dist/computer-record.js +315 -0
  25. package/dist/computer-setting.d.ts +1 -0
  26. package/dist/computer-setting.js +15 -2
  27. package/dist/computers.js +2 -14
  28. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  29. package/dist/console/assets/index-Bz6IWncl.js +711 -0
  30. package/dist/console/index.html +2 -2
  31. package/dist/decisions.js +0 -4
  32. package/dist/eval-feed.d.ts +2 -2
  33. package/dist/eval-feed.js +9 -5
  34. package/dist/feed/parse.d.ts +3 -2
  35. package/dist/feed/parse.js +9 -18
  36. package/dist/feed/pointer.d.ts +2 -0
  37. package/dist/feed/pointer.js +17 -0
  38. package/dist/file-types.js +1 -0
  39. package/dist/host-command.d.ts +3 -0
  40. package/dist/host-command.js +18 -0
  41. package/dist/host.d.ts +3 -0
  42. package/dist/host.js +3 -0
  43. package/dist/import-sources.js +25 -5
  44. package/dist/learn/audit.d.ts +123 -0
  45. package/dist/learn/audit.js +159 -0
  46. package/dist/learn/check.d.ts +14 -0
  47. package/dist/learn/check.js +194 -14
  48. package/dist/learn/compile.d.ts +75 -78
  49. package/dist/learn/compile.js +175 -176
  50. package/dist/learn/folder.d.ts +9 -0
  51. package/dist/learn/folder.js +13 -2
  52. package/dist/learn/promote.d.ts +138 -196
  53. package/dist/learn/promote.js +68 -184
  54. package/dist/learn/replay-calls.d.ts +5 -0
  55. package/dist/learn/replay-calls.js +12 -1
  56. package/dist/learn/secrets.d.ts +8 -0
  57. package/dist/learn/secrets.js +12 -0
  58. package/dist/learn/skills.js +2 -4
  59. package/dist/learn/workflow-nodes.d.ts +1 -2
  60. package/dist/learn/workflow-nodes.js +2 -3
  61. package/dist/learned-nodes.d.ts +9 -34
  62. package/dist/learned-nodes.js +11 -23
  63. package/dist/learned-workflow.d.ts +6 -8
  64. package/dist/learned-workflow.js +18 -57
  65. package/dist/learning-batch.d.ts +13 -5
  66. package/dist/learning-batch.js +34 -8
  67. package/dist/learning-cost.d.ts +11 -4
  68. package/dist/learning-cost.js +4 -2
  69. package/dist/learning-routes.js +1 -1
  70. package/dist/learning-setting.d.ts +38 -0
  71. package/dist/learning-setting.js +83 -0
  72. package/dist/learning-words.d.ts +3 -0
  73. package/dist/learning-words.js +3 -0
  74. package/dist/learning.d.ts +3 -2
  75. package/dist/learning.js +5 -3
  76. package/dist/mcp-oauth.d.ts +8 -0
  77. package/dist/mcp-oauth.js +7 -0
  78. package/dist/mcp-private-hosts.d.ts +13 -0
  79. package/dist/mcp-private-hosts.js +16 -0
  80. package/dist/openapi.d.ts +1 -0
  81. package/dist/openapi.js +195 -59
  82. package/dist/run-files.d.ts +6 -2
  83. package/dist/run-files.js +29 -7
  84. package/dist/run-launch.d.ts +6 -3
  85. package/dist/run-launch.js +2 -0
  86. package/dist/run-learning-served.d.ts +2 -2
  87. package/dist/run-reads-over-store.d.ts +5 -1
  88. package/dist/run-reads-over-store.js +8 -4
  89. package/dist/run-recordings.d.ts +20 -0
  90. package/dist/run-recordings.js +133 -0
  91. package/dist/runner/adapter-loop.d.ts +5 -1
  92. package/dist/runner/adapter-loop.js +20 -8
  93. package/dist/runner/adapter-run-spec.d.ts +16 -1
  94. package/dist/runner/adapter-run-spec.js +36 -11
  95. package/dist/runner/audit.d.ts +64 -0
  96. package/dist/runner/audit.js +338 -0
  97. package/dist/runner/beside.js +2 -2
  98. package/dist/runner/cli-run-spec.js +25 -12
  99. package/dist/runner/feedback-round.d.ts +9 -25
  100. package/dist/runner/feedback-round.js +19 -40
  101. package/dist/runner/harness-loops.js +1 -15
  102. package/dist/runner/journal-kinds.d.ts +0 -7
  103. package/dist/runner/journal-kinds.js +0 -7
  104. package/dist/runner/learning-dispatch.d.ts +0 -16
  105. package/dist/runner/learning-dispatch.js +4 -47
  106. package/dist/runner/learning-end.d.ts +62 -13
  107. package/dist/runner/learning-end.js +180 -74
  108. package/dist/runner/learning-factory.d.ts +1 -1
  109. package/dist/runner/learning-factory.js +1 -4
  110. package/dist/runner/learning-loop.d.ts +2 -38
  111. package/dist/runner/learning-loop.js +8 -116
  112. package/dist/runner/main.d.ts +11 -0
  113. package/dist/runner/main.js +30 -3
  114. package/dist/runner/mcp-run.d.ts +2 -2
  115. package/dist/runner/promotion.d.ts +78 -50
  116. package/dist/runner/promotion.js +371 -503
  117. package/dist/runner/reflect-hook.d.ts +15 -0
  118. package/dist/runner/reflect-hook.js +28 -14
  119. package/dist/runner/store-secrets.js +3 -1
  120. package/dist/runner/workflow-first.d.ts +6 -11
  121. package/dist/runner/workflow-first.js +24 -25
  122. package/dist/runs-over-store.d.ts +1 -1
  123. package/dist/sdk/runs.js +2 -1
  124. package/dist/secrets.js +2 -2
  125. package/dist/server.d.ts +4 -3
  126. package/dist/server.js +132 -26
  127. package/dist/store/agent-body.d.ts +5 -3
  128. package/dist/store/agent-body.js +14 -10
  129. package/dist/store/sqlite/store.js +1 -0
  130. package/dist/store/store.d.ts +3 -0
  131. package/dist/store-reads/learning.d.ts +18 -7
  132. package/dist/store-reads/learning.js +36 -23
  133. package/dist/store-reads/loop.d.ts +5 -39
  134. package/dist/store-reads/loop.js +21 -80
  135. package/dist/store-view.d.ts +5 -0
  136. package/dist/store-view.js +16 -2
  137. package/dist/template-eval.d.ts +7 -0
  138. package/dist/template-eval.js +54 -6
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +14 -1
  141. package/dist/timeline/computer.js +2 -1
  142. package/dist/tool-list.js +1 -0
  143. package/dist/tools.d.ts +7 -0
  144. package/dist/tools.js +11 -0
  145. package/dist/trigger-feed.js +67 -18
  146. package/dist/validate.js +7 -2
  147. package/dist/workspace/computer-for-claim.d.ts +7 -0
  148. package/dist/workspace/computer-for-claim.js +12 -2
  149. package/dist/workspace/paths.d.ts +4 -0
  150. package/dist/workspace/paths.js +9 -0
  151. package/dist/workspace/resolve-computer.d.ts +3 -1
  152. package/dist/workspace/run-tools.d.ts +1 -1
  153. package/dist/workspace/run-tools.js +14 -3
  154. package/launcher/agentrun-serve +31 -24
  155. package/package.json +10 -9
  156. package/templates/README.md +11 -2
  157. package/dist/console/assets/index-C3gNPz58.css +0 -1
  158. package/dist/console/assets/index-COGhx_2Z.js +0 -711
  159. package/dist/learn/general.d.ts +0 -69
  160. package/dist/learn/general.js +0 -75
  161. package/dist/learn/refit.d.ts +0 -48
  162. package/dist/learn/refit.js +0 -264
  163. package/dist/runner/step-guard.d.ts +0 -62
  164. package/dist/runner/step-guard.js +0 -93
@@ -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);
@@ -397,17 +557,34 @@ const repicks = (step, check) => {
397
557
  const of = step.until.of;
398
558
  return of.predicate === "quote_missing" && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
399
559
  };
400
- /** The labels of the steps inside `node` (a loop's body) that write state key `key` from a `state` map. The DSL sends
401
- * such a step only the keys its map names (each pass a fresh model session), so on a re-pick it never sees the failed
402
- * draft, and a map naming the answer fails the first pass, which has none yet: only a step with no map reads the whole
403
- * state. A map's or a composed workflow's own steps write their item's or child's state, not this one. */
404
- const answersFromStateMap = (node, key, depth = 0) => {
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) => {
405
580
  if (!isNode(node) || depth > 32)
406
581
  return [];
407
- const own = writeKeyOf(node) === key && node.state !== undefined ? [String(node.label ?? node.node).slice(0, 64)] : [];
408
- const inner = node.node === "map" || node.node === "workflow" ? [] : childNodes(node).flatMap((child) => answersFromStateMap(child, key, depth + 1));
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));
409
584
  return [...own, ...inner];
410
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)`;
411
588
  /** The labels of the quote_missing escalates inside `node` (a loop's body), a composed workflow's included: each hands
412
589
  * back on the first pass's miss, so a re-pick loop around one never re-picks. */
413
590
  const quoteEscalatesIn = (node, depth = 0) => {
@@ -496,12 +673,12 @@ function quoteRule(workflow, schemasAround, depth = 0) {
496
673
  // A check inside the loop's body hands back on the first draft's miss: the loop never re-picks.
497
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`);
498
675
  }
499
- else if (!problems.length && first && isNode(writer) && writer.node === "loop" && repicks(writer, first) && answersFromStateMap(writer.body, answerPath.split(".")[0]).length) {
500
- // The re-pick must see the failed draft: its step reads the whole state (no `state` map).
501
- problems.push(`the step ${JSON.stringify(answersFromStateMap(writer.body, answerPath.split(".")[0])[0])} in the re-pick loop ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer from a "state" map, which passes it only the keys it names, so its second pass never sees the failed draft (and naming the answer there fails the first pass, before any draft exists): give it no "state" map, so it reads the whole run state, the failed draft included`);
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`);
502
679
  }
503
680
  else if (!problems.length && first && !checks.every((check) => repicks(writer, check))) {
504
- 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, its instructions saying that a draft already in state 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`);
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`);
505
682
  }
506
683
  }
507
684
  // A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
@@ -513,7 +690,8 @@ function quoteRule(workflow, schemasAround, depth = 0) {
513
690
  * regular file within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a skill's
514
691
  * front matter (skillProblems), with no `status`, which is the host's; a draft the DSL validates against `tools` with
515
692
  * no node that runs code (draftProblems), whose answering step runs on the agent's model (answerTierProblems), whose
516
- * quotes of the pages it fetched are checked in code (quoteCheckProblems); a README that names its folder and says what
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
517
695
  * the draft is for. */
518
696
  function learnedChecked(change, place, refused, input, add) {
519
697
  const { path } = change;
@@ -541,10 +719,12 @@ function learnedChecked(change, place, refused, input, add) {
541
719
  if (!input.dsl)
542
720
  throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
543
721
  const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.decisions, input.workflowAdapters);
544
- // A draft the DSL reads parses: its answering step is held to the agent's model, and its quote check to code.
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.
545
724
  if (!problems.length) {
546
725
  const doc = JSON.parse(text);
547
- problems.push(...[...answerTierProblems(doc), ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
726
+ const compact = input.workflowAdapters === undefined ? compactStateProblems(doc) : [];
727
+ problems.push(...[...answerTierProblems(doc), ...compact, ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
548
728
  }
549
729
  for (const { rule, detail } of problems)
550
730
  add(rule, detail, path);
@@ -1,16 +1,10 @@
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 AuditHold, 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. */
10
7
  export declare const COMPILE_RETRIES = 3;
11
- /** How many of an agent's runs before the ending one are read for an earlier compile: one there (it may still wait for
12
- * its grade, or it failed) asks none now, so a job is compiled at most once in that many runs. */
13
- export declare const COMPILE_QUIET_RUNS = 4;
14
8
  /** The longest the compile turn may take, every attempt in it, before the run ends with what it has. */
15
9
  export declare const COMPILE_TIMEOUT_MS: number;
16
10
  /** The most of a run's trace the compile turn holds, in characters. */
@@ -18,35 +12,16 @@ export declare const TRACE_MAX = 4000;
18
12
  /** The most of the agent's notes, together, the compile turn reads, in characters. It reads them whole, every rule kept:
19
13
  * notes over it compile nothing, and the record says why (compileTurn), never a workflow from a cut set of rules. */
20
14
  export declare const NOTES_MAX = 96000;
21
- /** A workflow the money rule stopped from running first (runner/workflow-first.ts costLineOf): its name, and its cost a
22
- * run over its last `runs` served runs against the agent's by hand, in dollars. */
23
- export interface ReviseAsk {
24
- readonly workflow: string;
25
- readonly served_usd: number;
26
- readonly by_hand_usd: number;
27
- readonly runs: number;
28
- }
29
- /** A workflow its promotion holds (runner/promotion.ts, learn/promote.ts): the run went by hand, and the hold's record
30
- * 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`. */
31
17
  export interface HeldAsk {
32
18
  readonly workflow: string;
33
19
  readonly digest: string;
34
- readonly source: PromotionRecord["source"];
35
20
  readonly reason: string;
36
- readonly replay?: {
37
- readonly n: number;
38
- readonly agree: number;
39
- readonly agent_acc: number;
40
- readonly wf_acc: number;
41
- readonly delta: number;
42
- readonly handed_back: number;
43
- };
44
- }
45
- /** A run its learned workflow answered alone that a grade said was wrong (runner/feedback-round.ts, a `revise` round):
46
- * the workflow's answer and the grade's words, each cut of the run's secrets. */
47
- export interface GradedAsk {
48
- readonly answer: string;
49
- readonly words: string;
21
+ readonly check?: CheckRecord;
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,12 +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, after it handed this run back (`handedBack`), the money rule stopped it (`revise`), a grade
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); `jev`: whether one of them is Jev, not denied (guards read it).
43
+ * provider (judge, pick and sift nodes are allowed).
70
44
  * `outputSchema`: the agent's, when it has one: a run serving the workflow serves its answer shaped to it, else hands the
71
45
  * run back (answer-json.ts answerAsServed), so the workflow's final output must be that object. */
72
46
  export type CompileAsk = {
@@ -86,7 +60,6 @@ export type CompileAsk = {
86
60
  readonly does: string;
87
61
  }[];
88
62
  readonly judges: boolean;
89
- readonly jev?: boolean;
90
63
  } & ({
91
64
  readonly mode: "new";
92
65
  } | {
@@ -96,10 +69,7 @@ export type CompileAsk = {
96
69
  /** The commit of main `current` was read at: the revision's conflict base (its merge refuses a change to the workflow
97
70
  * on main after this read, never one before it, which the revision was written over). Never told the model. */
98
71
  readonly base?: string;
99
- readonly handedBack?: true;
100
- readonly revise?: ReviseAsk;
101
- readonly graded?: GradedAsk;
102
- readonly held?: HeldAsk;
72
+ readonly held: HeldAsk;
103
73
  });
104
74
  /** One attempt of the compile turn: whether its draft passed the checks, and else why not, in the checks' words. */
105
75
  export type CompileAttempt = {
@@ -117,34 +87,66 @@ export type CompiledRecord = {
117
87
  readonly digest?: string;
118
88
  readonly promoted?: boolean;
119
89
  };
120
- /** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, or
121
- * once a threshold refit of it was (its new revision serves in its place); false while held, or once a newer revision
122
- * 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. */
123
92
  export declare function promotedOf(records: readonly PromotionRecord[], workflow: string, digest: string): boolean | undefined;
124
93
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
125
94
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
126
- * 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). */
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. */
128
97
  export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
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). */
111
+ export declare const completedRun: (run: {
112
+ readonly id: string;
113
+ readonly state: string;
114
+ readonly outcome: string | null;
115
+ }) => boolean;
116
+ /** Whether a store run is a completed run of the agent's own (completedRun), not one its learned workflow answered alone
117
+ * nor a check's replay run (nor an audit's shadow, completedRun): what compile_after counts. */
118
+ export declare const agentRun: (run: {
119
+ readonly id: string;
120
+ readonly state: string;
121
+ readonly outcome: string | null;
122
+ readonly metrics?: unknown;
123
+ }) => boolean;
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[]>;
129
136
  /** 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 keeps COMPILE_AFTER_NOTES
131
- * active notes or has COMPILE_AFTER_RUNS completed runs. */
137
+ * waiting for its owner's OK), and it has `compileAfter` completed
138
+ * agent runs (its definition's compile_after, learning-setting.ts), the ending one counted. */
132
139
  export declare const compileDue: (facts: {
133
140
  readonly completed: boolean;
134
- readonly notes: number;
135
141
  readonly runs: number;
136
142
  readonly workflows: number;
137
- readonly compiledLately: boolean;
143
+ readonly compileAfter: number;
138
144
  }) => 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
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
142
- * draft to (learn/skills.ts draftProblems; propose.ts). `jev`: the run can call Jev (one of its decision providers,
143
- * not denied), so every step is asked for a guard Jev reads. */
146
+ * draft to (learn/skills.ts draftProblems; propose.ts; check.ts). */
144
147
  export declare function learnedHost(options: {
145
148
  readonly tools: readonly string[];
146
149
  readonly judges: boolean;
147
- readonly jev?: boolean;
148
150
  readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
149
151
  }): AuthorHostAddendum;
150
152
  /** The workflow language for the compile turn, generated: the DSL's own author contract (rendered from its vocabulary, so
@@ -156,19 +158,23 @@ export declare const compileReference: (dsl: {
156
158
  }, options: {
157
159
  readonly tools: readonly string[];
158
160
  readonly judges: boolean;
159
- readonly jev?: boolean;
160
161
  readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
161
162
  }) => string;
162
163
  /** The worked example's input, as a run gives it. */
163
164
  export declare const EXAMPLE_INPUT: {
164
- readonly content: "Refund request: order 1043, a $42 kettle that arrived broken, bought 9 days ago.";
165
+ readonly content: "Is the parser library at https://example.org/parser under a permissive licence?";
165
166
  };
166
- /** The worked example: a whole job, input to answer, that the checks and the dry run pass (a test holds it to them).
167
- * An extract step reads the facts on the fast tier, a judge asks one typed question of them (with a decision provider),
168
- * a decide step answers on the agent's own model (no tier: answerTierProblems), and an escalate step hands back a case the policy does not cover. With Jev (`jev`) each judgment step is
169
- * guarded on its own confidence and Jev's (`both`) and the extract step on Jev's; without, the judgment steps on their
170
- * own confidence alone. */
171
- export declare function compileExample(judges: boolean, jev?: boolean): Record<string, unknown>;
167
+ /** The tool the worked example's call step names: it stands for the tool the agent's runs read pages with. */
168
+ export declare const EXAMPLE_TOOL = "fetch_page";
169
+ /** The worked example: the cascade skeleton every repeated job compiles to (H1, H5d: ~$0.08 a run booked against the
170
+ * 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
171
+ * legwork on the fast tier: an extract step reads the target from the input, a call step fetches its page (`fetches`:
172
+ * the run has a tool), an extract step copies compact facts from the page, the verbatim lines the answer will quote among
173
+ * them. The answer on the agent's own model (no tier: answerTierProblems) from those facts and its own draft alone, never
174
+ * the page (compactStateProblems), in a re-pick loop of 2 until its quotes are in the page (quoteCheckProblems); then the
175
+ * quote check hands back a second miss, and an escalate step a case the policy does not cover.
176
+ * With no tool to fetch with, the facts come from the input and the answer quotes nothing it must check. */
177
+ export declare function compileExample(fetches?: boolean): Record<string, unknown>;
172
178
  /** Whether `text` is a compile ask: `again` for an attempt the checks sent back, true for the first, else false. */
173
179
  export declare const askedForCompile: (text: unknown) => "again" | boolean;
174
180
  /** What a compiled workflow gives (#2412): the job's answer as the runs gave it, never a summary of it. */
@@ -181,16 +187,12 @@ export declare function compilePrompt(ask: CompileAsk): string;
181
187
  * fenced as data), and the attempt it was. */
182
188
  export declare function compileAgain(errors: readonly string[], attempt: number): string;
183
189
  /** A compile answer read: the draft's block whole (to check), its name and the notes it says it carries out (only ones
184
- * the turn was given); `unchanged` for a revision the model kept as it is (never a held one's); else why it can't be
185
- * read. */
190
+ * the turn was given); else why it can't be read. */
186
191
  export type CompileRead = {
187
192
  readonly ok: true;
188
193
  readonly name: string;
189
194
  readonly block: string;
190
195
  readonly from_notes: readonly string[];
191
- } | {
192
- readonly ok: false;
193
- readonly unchanged: true;
194
196
  } | {
195
197
  readonly ok: false;
196
198
  readonly error: string;
@@ -215,19 +217,13 @@ type CheckedLike = {
215
217
  /** Why the checks did not keep draft `name` from `checked` (each problem's words, its path's in front when it names
216
218
  * another file); none when its workflow.json is in the proposal. */
217
219
  export declare function draftErrorsOf(checked: CheckedLike | undefined, name: string): string[];
218
- /** What a draft's guards leave out of the ones the compile turn asked for (learnedHost's rules), one line each: a
219
- * judgment step with no guard; with Jev, an extract or call step with none, or one reading its own confidence (it
220
- * reports none); without Jev, a guard that reads it (it would hand every case back). None when every one is there. */
221
- export declare function guardProblems(doc: unknown, options: {
222
- readonly jev: boolean;
223
- readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
224
- }): string[];
225
220
  /** The record's workflow when no attempt named one. */
226
221
  export declare const UNNAMED = "(unnamed)";
227
- /** 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 the turn asked for, 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
229
223
  * times and within `deadlineMs`. What it ends with: `kept` with the answer and what the checks made of it when an
230
- * attempt passed; else none, with every attempt. Notes over NOTES_MAX ask nothing: one attempt says why. */
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. */
231
227
  export declare function compileTurn<C extends CheckedLike>(input: {
232
228
  /** One attempt's ask (`attempt` from 1), within `deadlineMs`: its answer, or undefined when the turn timed out or failed. */
233
229
  readonly ask: (prompt: string, attempt: number, deadlineMs: number) => Promise<{
@@ -247,5 +243,6 @@ export declare function compileTurn<C extends CheckedLike>(input: {
247
243
  checked: C;
248
244
  };
249
245
  draftErrors: string[];
246
+ drafted?: true;
250
247
  }>;
251
248
  export {};