@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52

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 (232) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +236 -30
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +13 -2
  5. package/dist/agent-delete.js +14 -5
  6. package/dist/agents-store.d.ts +5 -1
  7. package/dist/agents-store.js +17 -7
  8. package/dist/api-only.d.ts +6 -3
  9. package/dist/api-only.js +8 -5
  10. package/dist/archil-routes.d.ts +1 -0
  11. package/dist/archil-routes.js +28 -2
  12. package/dist/capacity.d.ts +50 -0
  13. package/dist/capacity.js +49 -0
  14. package/dist/cli-learning/claude-wire.d.ts +41 -0
  15. package/dist/cli-learning/claude-wire.js +258 -0
  16. package/dist/cli-learning/cli.d.ts +11 -0
  17. package/dist/cli-learning/cli.js +241 -0
  18. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  19. package/dist/cli-learning/codex-worktree.js +119 -0
  20. package/dist/cli-learning/connections.d.ts +62 -0
  21. package/dist/cli-learning/connections.js +87 -0
  22. package/dist/cli-learning/entry.d.ts +1 -0
  23. package/dist/cli-learning/entry.js +4 -0
  24. package/dist/cli-learning/evidence.d.ts +78 -0
  25. package/dist/cli-learning/evidence.js +492 -0
  26. package/dist/cli-learning/hook.d.ts +33 -0
  27. package/dist/cli-learning/hook.js +544 -0
  28. package/dist/cli-learning/install.d.ts +33 -0
  29. package/dist/cli-learning/install.js +335 -0
  30. package/dist/cli-learning/observation-proof.d.ts +14 -0
  31. package/dist/cli-learning/observation-proof.js +10 -0
  32. package/dist/cli-learning/policy.d.ts +48 -0
  33. package/dist/cli-learning/policy.js +363 -0
  34. package/dist/cli-learning/schema.d.ts +16 -0
  35. package/dist/cli-learning/schema.js +27 -0
  36. package/dist/cli-learning/state.d.ts +23 -0
  37. package/dist/cli-learning/state.js +61 -0
  38. package/dist/cli.js +24 -2
  39. package/dist/computer-setting.d.ts +8 -0
  40. package/dist/computer-setting.js +11 -0
  41. package/dist/computers.d.ts +6 -2
  42. package/dist/computers.js +2 -2
  43. package/dist/console/assets/index-B-D0EM3j.js +733 -0
  44. package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
  45. package/dist/console/index.html +2 -2
  46. package/dist/email/email-faux.d.ts +3 -1
  47. package/dist/email/email-faux.js +3 -2
  48. package/dist/email/routes.js +22 -12
  49. package/dist/fal-price.d.ts +76 -0
  50. package/dist/fal-price.js +368 -0
  51. package/dist/harness-install.d.ts +6 -2
  52. package/dist/harness-install.js +40 -8
  53. package/dist/harness.d.ts +1 -1
  54. package/dist/harness.js +2 -2
  55. package/dist/learn/commit.d.ts +5 -0
  56. package/dist/learn/commit.js +4 -1
  57. package/dist/learn/compile.d.ts +13 -5
  58. package/dist/learn/compile.js +24 -7
  59. package/dist/learn/delete.d.ts +12 -6
  60. package/dist/learn/delete.js +17 -11
  61. package/dist/learn/folder.d.ts +11 -0
  62. package/dist/learn/folder.js +20 -3
  63. package/dist/learn/learning-of.d.ts +8 -0
  64. package/dist/learn/learning-of.js +8 -0
  65. package/dist/learn/learning.sh +14 -1
  66. package/dist/learn/promote.d.ts +51 -7
  67. package/dist/learn/promote.js +51 -8
  68. package/dist/learn/secrets.js +14 -3
  69. package/dist/learning-reset.d.ts +18 -0
  70. package/dist/learning-reset.js +115 -0
  71. package/dist/learning-routes.d.ts +1 -1
  72. package/dist/learning-words.d.ts +6 -1
  73. package/dist/learning-words.js +6 -1
  74. package/dist/learning.d.ts +8 -6
  75. package/dist/learning.js +5 -4
  76. package/dist/llms.txt +1 -0
  77. package/dist/mcp-gateway.d.ts +39 -2
  78. package/dist/mcp-gateway.js +41 -10
  79. package/dist/mcp-pin-first.js +3 -2
  80. package/dist/mcp-private-hosts.d.ts +24 -3
  81. package/dist/mcp-private-hosts.js +53 -3
  82. package/dist/mcp-servers-store.d.ts +1 -0
  83. package/dist/mcp-servers-store.js +2 -1
  84. package/dist/media-duration.d.ts +2 -0
  85. package/dist/media-duration.js +136 -0
  86. package/dist/model-gateway.d.ts +2 -0
  87. package/dist/model-gateway.js +3 -1
  88. package/dist/native/runtimes.d.ts +2 -0
  89. package/dist/native/runtimes.js +2 -0
  90. package/dist/observation/learning.d.ts +32 -0
  91. package/dist/observation/learning.js +66 -0
  92. package/dist/observation/observer.d.ts +8 -1
  93. package/dist/observation/observer.js +89 -9
  94. package/dist/observation/schema.js +12 -4
  95. package/dist/observation/usage-identity.d.ts +9 -0
  96. package/dist/observation/usage-identity.js +11 -0
  97. package/dist/openapi.js +133 -24
  98. package/dist/provider.d.ts +8 -0
  99. package/dist/provider.js +14 -2
  100. package/dist/refusal-words.d.ts +0 -3
  101. package/dist/refusal-words.js +0 -3
  102. package/dist/request-metadata.d.ts +20 -0
  103. package/dist/request-metadata.js +24 -0
  104. package/dist/run-launch.d.ts +27 -4
  105. package/dist/run-launch.js +18 -3
  106. package/dist/run-learning-served.d.ts +2 -2
  107. package/dist/run-usage.d.ts +48 -4
  108. package/dist/run-usage.js +156 -39
  109. package/dist/run-view.d.ts +2 -0
  110. package/dist/run-view.js +8 -7
  111. package/dist/runner/adapter-loop.d.ts +3 -1
  112. package/dist/runner/adapter-loop.js +41 -35
  113. package/dist/runner/adapter-run-spec.d.ts +1 -1
  114. package/dist/runner/adapter-run-spec.js +15 -15
  115. package/dist/runner/audit.d.ts +8 -3
  116. package/dist/runner/audit.js +21 -6
  117. package/dist/runner/beside.d.ts +13 -0
  118. package/dist/runner/beside.js +27 -8
  119. package/dist/runner/claim-secrets.d.ts +2 -1
  120. package/dist/runner/claim-secrets.js +5 -3
  121. package/dist/runner/cli-run-spec.d.ts +1 -1
  122. package/dist/runner/cli-run-spec.js +14 -13
  123. package/dist/runner/conformance/harness.js +4 -2
  124. package/dist/runner/disk-free.d.ts +44 -0
  125. package/dist/runner/disk-free.js +96 -0
  126. package/dist/runner/dispatch.js +4 -2
  127. package/dist/runner/feedback-round.d.ts +12 -8
  128. package/dist/runner/feedback-round.js +16 -30
  129. package/dist/runner/harness-loops.js +8 -3
  130. package/dist/runner/journal-kinds.d.ts +4 -1
  131. package/dist/runner/learning-end.d.ts +2 -1
  132. package/dist/runner/learning-end.js +51 -22
  133. package/dist/runner/main.d.ts +17 -6
  134. package/dist/runner/main.js +187 -45
  135. package/dist/runner/mcp-claim.js +1 -1
  136. package/dist/runner/mcp-run.d.ts +9 -0
  137. package/dist/runner/mcp-run.js +16 -1
  138. package/dist/runner/model-route.js +7 -4
  139. package/dist/runner/presence.d.ts +11 -2
  140. package/dist/runner/presence.js +31 -3
  141. package/dist/runner/promotion.d.ts +40 -21
  142. package/dist/runner/promotion.js +130 -59
  143. package/dist/runner/run-child-host.d.ts +12 -15
  144. package/dist/runner/run-child-host.js +52 -112
  145. package/dist/runner/run-errors.js +2 -0
  146. package/dist/runner/runner-check.d.ts +51 -0
  147. package/dist/runner/runner-check.js +206 -0
  148. package/dist/runner/runner-metrics.d.ts +19 -0
  149. package/dist/runner/runner-metrics.js +49 -0
  150. package/dist/runner/runner.d.ts +37 -0
  151. package/dist/runner/runner.js +58 -6
  152. package/dist/runner/sdk-loop.d.ts +2 -2
  153. package/dist/runner/sdk-loop.js +37 -25
  154. package/dist/runner/store-port.d.ts +3 -0
  155. package/dist/runner/workflow-spec.js +3 -3
  156. package/dist/runs-over-store.d.ts +13 -3
  157. package/dist/runs-over-store.js +71 -16
  158. package/dist/sdk/check.d.ts +6 -5
  159. package/dist/sdk/check.js +17 -16
  160. package/dist/sdk/runs.d.ts +22 -2
  161. package/dist/sdk/runs.js +167 -82
  162. package/dist/server.d.ts +3 -0
  163. package/dist/server.js +230 -43
  164. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  165. package/dist/start-switches.js +2 -0
  166. package/dist/stats.d.ts +4 -0
  167. package/dist/stats.js +1 -1
  168. package/dist/store/agent-body.d.ts +16 -0
  169. package/dist/store/agent-body.js +20 -3
  170. package/dist/store/dialect.d.ts +2 -0
  171. package/dist/store/dialect.js +1 -0
  172. package/dist/store/index.d.ts +3 -3
  173. package/dist/store/index.js +2 -2
  174. package/dist/store/journal/storage.d.ts +2 -0
  175. package/dist/store/journal/storage.js +2 -1
  176. package/dist/store/postgres/connection.d.ts +5 -2
  177. package/dist/store/postgres/connection.js +19 -7
  178. package/dist/store/postgres/dialect.js +1 -0
  179. package/dist/store/postgres/migrate.d.ts +30 -0
  180. package/dist/store/postgres/migrate.js +72 -5
  181. package/dist/store/postgres/migration-lint.d.ts +8 -0
  182. package/dist/store/postgres/migration-lint.js +119 -0
  183. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  184. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  185. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  186. package/dist/store/postgres/store.d.ts +8 -3
  187. package/dist/store/postgres/store.js +31 -11
  188. package/dist/store/schema.d.ts +32 -2
  189. package/dist/store/schema.js +74 -5
  190. package/dist/store/sqlite/run-launch.d.ts +31 -1
  191. package/dist/store/sqlite/run-launch.js +111 -2
  192. package/dist/store/sqlite/run-patch.d.ts +2 -1
  193. package/dist/store/sqlite/run-patch.js +4 -3
  194. package/dist/store/sqlite/store.d.ts +17 -0
  195. package/dist/store/sqlite/store.js +226 -37
  196. package/dist/store/store-schema.d.ts +34 -0
  197. package/dist/store/store-schema.js +125 -0
  198. package/dist/store/store.d.ts +120 -5
  199. package/dist/store/store.js +13 -0
  200. package/dist/store-reads/analytics.d.ts +3 -2
  201. package/dist/store-reads/analytics.js +20 -8
  202. package/dist/store-reads/learning.d.ts +12 -8
  203. package/dist/store-reads/learning.js +33 -24
  204. package/dist/store-reads/loop.d.ts +4 -3
  205. package/dist/store-reads/loop.js +7 -5
  206. package/dist/store-view.d.ts +4 -3
  207. package/dist/store-view.js +11 -7
  208. package/dist/template-eval.js +4 -4
  209. package/dist/templates.d.ts +6 -2
  210. package/dist/templates.js +7 -5
  211. package/dist/timeline/labels.js +1 -1
  212. package/dist/tool-gate.d.ts +4 -2
  213. package/dist/tools.js +1 -1
  214. package/dist/unified-usage.d.ts +24 -0
  215. package/dist/unified-usage.js +400 -0
  216. package/dist/uploads-archil.d.ts +100 -0
  217. package/dist/uploads-archil.js +431 -0
  218. package/dist/uploads.d.ts +52 -1
  219. package/dist/uploads.js +186 -108
  220. package/dist/validate.js +5 -1
  221. package/dist/web-save.d.ts +3 -0
  222. package/dist/web-save.js +17 -2
  223. package/dist/workspace/archil-disk.d.ts +6 -5
  224. package/dist/workspace/archil-disk.js +27 -12
  225. package/dist/workspace/archil-exec.js +1 -1
  226. package/dist/workspace/archil.js +4 -3
  227. package/dist/workspace/revision-skills.js +24 -11
  228. package/dist/workspace/synced-folder.d.ts +3 -3
  229. package/dist/workspace/synced-folder.js +7 -6
  230. package/package.json +10 -10
  231. package/skills/agentrun-serve/SKILL.md +52 -7
  232. package/dist/console/assets/index-D7G6o-1E.js +0 -720
@@ -9,7 +9,7 @@ import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/j
9
9
  import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf, toolWord, unmarkedWords } from "../learn/replay-calls.js";
10
10
  import { listed } from "../learning-words.js";
11
11
  import { isObject } from "../validate.js";
12
- import { agentRun, lastOwnRuns, newCompileAttempt } from "../learn/compile.js";
12
+ import { agentRun, lastOwnRuns, newCompileAttempt, sinceReset } from "../learn/compile.js";
13
13
  import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
14
14
  import { sendCommand } from "./commands.js";
15
15
  import { ClaimRefused } from "./loop-contract.js";
@@ -270,8 +270,9 @@ async function loopOfRevision(deps) {
270
270
  /** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
271
271
  * check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
272
272
  * first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
273
- * (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first revision after a first compile
274
- * whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
273
+ * (stopUnchecked) is no first check's hold: it spends no recompile, and neither does a connected agent's hold on its
274
+ * give-backs (heldOnGiveBacks: the revision after it is the same attempt). A workflow's first revision after a first
275
+ * compile whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
275
276
  export function attemptOf(records, name, digest) {
276
277
  const before = records.findLast((one) => one.workflow === name && one.digest !== digest);
277
278
  if (!before)
@@ -280,6 +281,8 @@ export function attemptOf(records, name, digest) {
280
281
  return 1;
281
282
  if (before.audit)
282
283
  return before.audit.stopped ? 1 : 2;
284
+ if (before.check && heldOnGiveBacks(before.check))
285
+ return before.check.attempt;
283
286
  return !before.check || (before.check.attempt === 1 && !before.check.stopped) ? 2 : 1;
284
287
  }
285
288
  /** The shadow runs a recompile's check runs on beside the agent's last runs: the disagreeing audit rows the workflow's
@@ -300,16 +303,19 @@ const checkable = (deps, row) => row.id !== deps.runId && agentRun(row) && row.a
300
303
  * never push them out of the read. And `audited`: an audit hold's disagreeing shadow runs (auditInputsOf), each ended.
301
304
  * Of those, the ones whose input `workflow` takes (fits), each with its launch read back; one with an uploaded file is
302
305
  * never an input. With how many of the agent's runs it looked at (`looked`) and why each it looked at is no input
303
- * (`unfit`, `files`). */
306
+ * (`unfit`, `files`). Every one of them a run on no named disk (one on a named disk learns nothing, learn/learning-of.ts)
307
+ * since the agent's learning's reset (sinceReset), the named and audited ones included. */
304
308
  async function checkInputs(deps, workflow, pick, audited = []) {
305
309
  const { resolveSchemaForWorkflow } = await import("@parcha/agentrun-dsl");
306
- const named = (await Promise.all(pick.of.map((id) => deps.store.runs.get(id)))).filter((row) => row !== undefined && checkable(deps, row));
310
+ const since = await sinceReset(deps.store, deps.agentId);
311
+ const learns = (row) => (row.disk ?? null) === null && since(row);
312
+ const named = (await Promise.all(pick.of.map((id) => deps.store.runs.get(id)))).filter((row) => row !== undefined && checkable(deps, row) && learns(row));
307
313
  const last = pick.n ? await lastOwnRuns(deps.store, deps.agentId, pick.n + pick.of.length, deps.runId) : [];
308
314
  const own = [...named, ...last.filter((row) => !pick.of.includes(row.id)).slice(0, pick.n)];
309
315
  // And an audit hold's disagreeing shadow runs: the agent's answers the recompile must say too.
310
316
  for (const id of audited) {
311
317
  const row = await deps.store.runs.get(id);
312
- if (row && row.state === "ended" && !own.some((one) => one.id === id))
318
+ if (row && row.state === "ended" && learns(row) && !own.some((one) => one.id === id))
313
319
  own.push(row);
314
320
  }
315
321
  const out = [];
@@ -474,45 +480,56 @@ async function settleCheck(deps, workflow, digest, record) {
474
480
  }
475
481
  return decided.record?.decided === "replaying" ? undefined : decided.record;
476
482
  }
477
- /** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
478
- * with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
479
- * when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
480
- * when it answered it with no escalate and no failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
481
- * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
482
- * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
483
- * (the one write: of two claims at once, one decides). */
484
- export async function decideCheck(deps, name, digest, bar, read, still, extra) {
485
- const now = deps.now ?? Date.now;
486
- const ran = read.rows.filter((row) => row.outcome !== "skipped_write");
483
+ /** A check's rows scored on its bar, added to `before` (a connected agent's turns checked so far): each input it ran on
484
+ * (a skipped write is none) agreed when the draft answered it alone with the agent's recorded answer (learn/promote.ts
485
+ * compareAnswers, the audit's one comparison: on the bar's agree_on when it names fields, else equal, or the same
486
+ * decision by the grader's verdict its replay run kept), alone when it answered it with no escalate and no failed step;
487
+ * the inputs it did not agree on, each text cut of the host's secrets whole, then shortened (learn/secrets.ts
488
+ * excerptShown); and the fast model that compared, when it read any input's answers. */
489
+ async function scoreRows(deps, bar, rows, before) {
490
+ const ran = rows.filter((row) => row.outcome !== "skipped_write");
487
491
  const alone = (row) => row.outcome === "answered";
488
492
  // Compared on the bar's agree_on when it names paths (the definition's), else equal answers agree and the grader's
489
493
  // verdict decides the rest; with no grader (no fast model), the whole answer.
490
494
  const compared = new Map(ran.map((row) => [row, compareAnswers(row.answer, row.agent, bar.agree_on, row.compared)]));
491
495
  const agrees = (row) => alone(row) && compared.get(row).same;
492
- const score = { n: ran.length, agreed: ran.filter(agrees).length, alone: ran.filter(alone).length };
493
- const ok = checkPasses(score, bar);
494
- // The fast model that compared, when it read any input's answers.
496
+ const score = { n: (before?.n ?? 0) + ran.length, agreed: (before?.agreed ?? 0) + ran.filter(agrees).length, alone: (before?.alone ?? 0) + ran.filter(alone).length };
495
497
  const grader = [...compared.values()].find((one) => one.grader !== undefined)?.grader;
496
- // Each text is cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown).
497
498
  const shown = await deps.shown();
498
499
  const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
499
- const disagreements = ran.filter((row) => !agrees(row)).map((row) => {
500
- const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
501
- return {
502
- run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
503
- ...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
504
- ...(differs ? { differs_on: cut(differs) } : {}),
505
- };
506
- });
500
+ const disagreements = [...(before?.disagreements ?? []), ...ran.filter((row) => !agrees(row)).map((row) => {
501
+ const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
502
+ return {
503
+ run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
504
+ ...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
505
+ ...(differs ? { differs_on: cut(differs) } : {}),
506
+ };
507
+ })];
508
+ return { score, disagreements, grader };
509
+ }
510
+ /** Two outcome counts added. */
511
+ const outcomesAdded = (a, b) => b ? { answered: a.answered + b.answered, handed_back: a.handed_back + b.handed_back, failed: a.failed + b.failed, skipped_write: a.skipped_write + b.skipped_write } : a;
512
+ /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
513
+ * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
514
+ * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
515
+ * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
516
+ * (the one write: of two claims at once, one decides). */
517
+ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
518
+ const now = deps.now ?? Date.now;
519
+ const { before } = read;
520
+ const { score, disagreements, grader } = await scoreRows(deps, bar, read.rows, before);
521
+ const ok = checkPasses(score, bar);
507
522
  const stopped = !ok && bar.attempt === 2;
508
523
  const pct = (value) => `${(value * 100).toFixed(1)}%`;
509
524
  const shares = checkShares(score);
510
525
  // Inputs stopped at a write the recording lacks are no evidence either way; one stopped at an MCP tool its server listed
511
526
  // with no readOnlyHint names that tool (skipWordsOf), never a data problem.
512
527
  const tools = skippedToolsOf(read.rows);
513
- const { skipped_write: skipped, failed } = read.outcomes;
528
+ const outcomes = outcomesAdded(read.outcomes, before?.outcomes);
529
+ const { skipped_write: skipped, failed } = outcomes;
514
530
  const { hint, why: skipWhy } = skipWordsOf(tools, skipped);
515
- const numbers = { of: read.rows.map((row) => row.of), cost_usd: read.cost, outcomes: read.outcomes, ...(read.unstarted ? { unstarted: read.unstarted } : {}), ...(tools.length ? { skipped_tools: tools } : {}), ...(read.fresh_reads ? { fresh_reads: read.fresh_reads } : {}) };
531
+ const fresh = (read.fresh_reads ?? 0) + (before?.fresh_reads ?? 0);
532
+ const numbers = { of: [...read.rows.map((row) => row.of), ...(before?.of ?? [])], cost_usd: read.cost, outcomes, ...(read.unstarted ? { unstarted: read.unstarted } : {}), ...(tools.length ? { skipped_tools: tools } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
516
533
  // Every input skipped at a write (each reserved input counts: one never created or never ended failed, so this is the
517
534
  // only way to none): nothing to check it on, so it stops, never promoted unchecked, and asks no recompile.
518
535
  if (!score.n) {
@@ -554,13 +571,22 @@ async function reserve(deps, workflow, digest, inputs, reason, still, check) {
554
571
  await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch);
555
572
  return reserved;
556
573
  }
557
- /** How many of a connected agent's reserved native turns its check gives back before it stops. A turn is given back
558
- * when it cannot be the check's baseline: cancelled or failed, a learned workflow or nested call in it, redacted
559
- * evidence, no shadow report, or a shadow that did not answer. One or two are ordinary (a person cancels a task, an
560
- * input carries a secret); five say the integration cannot give one (a client with no shadow check, inputs it never
561
- * resolves, a draft whose shadow always refuses), and each reserved turn runs without the champion. The fifth stops it
562
- * with nothing checked (stopUnchecked), which asks no recompile: a revision would have no baseline either. */
574
+ /** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
575
+ * nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
576
+ * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the next
577
+ * compile to revise and check afresh: five in a row say the integration cannot give a baseline now, not that it never will. */
563
578
  export const SDK_CHECK_RELEASES = 5;
579
+ /** Whether a hold's check is a connected agent's held on SDK_CHECK_RELEASES give-backs in a row (releaseSdkCheck): only
580
+ * a connected agent's check counts give-backs. */
581
+ const heldOnGiveBacks = (check) => (check?.released ?? 0) >= SDK_CHECK_RELEASES;
582
+ /** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
583
+ * recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
584
+ * check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
585
+ export function reviseAttemptOf(records, held) {
586
+ if (!held.check || !heldOnGiveBacks(held.check))
587
+ return 2;
588
+ return newCompileAttempt(records.filter((one) => one.workflow === held.workflow)) === 2 ? 2 : held.check.attempt;
589
+ }
564
590
  /** A connected agent's check waiting for a native turn (`via` sdk, replaying, no turn reserved). */
565
591
  const waitingSdk = (record) => record?.decided === "replaying" && record.via === "sdk" && !record.runs?.length;
566
592
  /** Whether a connected agent's check was overtaken: a record of another revision of its workflow came after its own
@@ -586,7 +612,7 @@ export const sdkInputText = (launch) => {
586
612
  * check on the native turn `runId`: the first the turn takes (`takes`) with no decision yet, or one waiting for a turn,
587
613
  * while no other revision of its workflow is checked; the guarded write keeps one reservation per workflow across
588
614
  * concurrent starts. First each SDK check of a candidate's workflow is moved on: one whose turn is past
589
- * REPLAY_DEADLINE_MS is decided as one failed row (sdkCheckDeadline), and one waiting at a revision the folder moved
615
+ * REPLAY_DEADLINE_MS is one failed row of its turns (sdkCheckDeadline), and one waiting at a revision the folder moved
590
616
  * past is set aside. A managed replay's record (no `via`) is never touched here. */
591
617
  export async function reserveSdkCheck(deps, turn) {
592
618
  const { revision } = turn;
@@ -613,34 +639,68 @@ export async function reserveSdkCheck(deps, turn) {
613
639
  if ((own && !waitingSdk(own)) || blocking(records, flow.name, digest).length)
614
640
  continue;
615
641
  const id = uuidv7();
642
+ const check = own?.check ?? { ...loopOf(turn.learning), attempt: attemptOf(records, flow.name, digest) };
616
643
  const reserved = await recordPromotion(deps.store.settings, deps.agentId, {
617
644
  workflow: flow.name, digest, at: iso(now()), decided: "replaying", via: "sdk",
618
- reason: "Checking it in the connected agent against one independent native turn before it can be reused.",
619
- replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision,
620
- check: own?.check ?? { ...loopOf(turn.learning), attempt: attemptOf(records, flow.name, digest) },
645
+ reason: `Checking it in the connected agent against an independent native turn before it can be reused: ${sdkTurnsWords(check)}.`,
646
+ replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision, check,
621
647
  }, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0);
622
648
  if (reserved.won)
623
649
  return { id, revision, digest, workflow: flow };
624
650
  }
625
651
  }
652
+ /** How far a connected agent's check is: its turns checked of the compile_after it decides on. */
653
+ const sdkTurnsWords = (check) => `${check.turns?.n ?? 0} of ${plural(check.compile_after, "native turn")} checked so far; it decides once on all of them, as a managed check does on the agent's inputs`;
654
+ /** One native turn's row of a connected agent's check: its shadow answered or handed back (sdk/check.ts settleSdkCheck),
655
+ * or the turn did not settle by REPLAY_DEADLINE_MS, a failed row (sdkCheckDeadline). A managed check decides once, on
656
+ * its compile_after inputs, and so does this one: the turn that makes compile_after decides on every turn collected
657
+ * (decideCheck, the same bar); a turn before it is scored and kept (check.turns), the record gives back its reserved
658
+ * turn, and the check waits for the next turn the draft takes, nothing decided or promoted, the agent answering
659
+ * meanwhile. No turn holds it early, as no input of a managed check does. Its rows are never skipped (a shadow stopped
660
+ * at a write gives its turn back), so each is one of the n. Kept only while `still` holds of the digest's record; a
661
+ * check a newer revision overtook keeps no turn (it would hide the newer record), as a release does. */
662
+ export async function sdkCheckTurn(deps, record, row, still, read = {}) {
663
+ // A turn that lands starts the give-back count again (SDK_CHECK_RELEASES counts them in a row).
664
+ const { turns: before, released: _released, ...bar } = record.check;
665
+ const outcomes = { ...NO_OUTCOMES, [row.outcome]: 1 };
666
+ // The turn lands once: its completion and its deadline can both read the reservation, and the first to write takes
667
+ // the turn off it, so the second finds it gone (heldTurn) and never adds the turn twice or replaces the first's row.
668
+ const turnStill = (was, current) => still(was, current) && heldTurn(was, record);
669
+ if ((before?.n ?? 0) + 1 >= bar.compile_after)
670
+ return decideCheck(deps, record.workflow, record.digest, bar, { rows: [row], cost: null, outcomes, unstarted: 0, ...read, ...(before ? { before } : {}) }, turnStill, sdkExtra(record));
671
+ if (overtaken(await promotionsOf(deps.store.settings, deps.agentId), record)) {
672
+ deps.log(`workflow-first: ${record.workflow} at ${record.digest} checked a native turn; a newer revision has a record since, so it is left as it is`);
673
+ return;
674
+ }
675
+ const { score, disagreements } = await scoreRows(deps, bar, [row], before);
676
+ const fresh = (before?.fresh_reads ?? 0) + (read.fresh_reads ?? 0);
677
+ const turns = { ...score, of: [row.of, ...(before?.of ?? [])], outcomes: outcomesAdded(outcomes, before?.outcomes), ...(disagreements.length ? { disagreements } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
678
+ const check = { ...bar, turns };
679
+ const { runs: _runs, inputs: _inputs, ...rest } = record;
680
+ const kept = await recordPromotion(deps.store.settings, deps.agentId, {
681
+ ...rest, at: iso((deps.now ?? Date.now)()), check,
682
+ reason: `Waiting for the next native turn of the connected agent that it takes: ${sdkTurnsWords(check)}. Nothing was promoted.`,
683
+ }, (was, current) => turnStill(was, current) && !overtaken(current, was));
684
+ if (kept.won)
685
+ deps.log(`workflow-first: ${record.workflow} at ${record.digest}: ${sdkTurnsWords(check)}`);
686
+ return kept;
687
+ }
626
688
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
627
- * turn, or the server stopped before the run's end): decided as every check is (decideCheck), on one failed row. Its
628
- * hold asks the one recompile, and a recompile's check that ends here stops (`stopped`): an abandoned check never
629
- * restarts its budget. */
689
+ * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
690
+ * replay run not ended by its deadline is a failed input. The hold the turns end in asks the one recompile, and a
691
+ * recompile's check held so stops (`stopped`): an abandoned check never restarts its budget. */
630
692
  export async function sdkCheckDeadline(deps, pending) {
631
693
  const runId = pending.runs?.[0];
632
- if (!runId || !pending.check || overtaken(await promotionsOf(deps.store.settings, deps.agentId), pending))
694
+ const { check } = pending;
695
+ if (!runId || !check || overtaken(await promotionsOf(deps.store.settings, deps.agentId), pending))
633
696
  return;
634
697
  const launch = await deps.store.runs.launch(runId).then((one) => readLaunchBody(one.body), () => undefined);
635
- return decideCheck(deps, pending.workflow, pending.digest, pending.check, {
636
- rows: [{ of: runId, input: sdkInputText(launch), agent: null, outcome: "failed", answer: null }],
637
- cost: null, outcomes: { ...NO_OUTCOMES, failed: 1 }, unstarted: 0,
638
- }, (was, current) => sameReplay(was, pending) && !overtaken(current, was), sdkExtra(pending));
698
+ return sdkCheckTurn(deps, { ...pending, check }, { of: runId, input: sdkInputText(launch), agent: null, outcome: "failed", answer: null }, (was, current) => sameReplay(was, pending) && !overtaken(current, was));
639
699
  }
640
700
  /** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
641
- * the next turn the draft takes, nothing decided or promoted, and the turn counts toward SDK_CHECK_RELEASES, whose last
642
- * stops it with nothing checked (stopUnchecked: no recompile). `counted` false: no turn ran (its start was not
643
- * admitted). Kept only while the record is still this reservation. */
701
+ * the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
702
+ * (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
703
+ * draft for the next compile, whose revision is checked afresh. Kept only while the record is still this reservation. */
644
704
  export async function releaseSdkCheck(deps, record, cause, counted = true) {
645
705
  if (!record.check)
646
706
  return;
@@ -651,28 +711,35 @@ export async function releaseSdkCheck(deps, record, cause, counted = true) {
651
711
  const released = (record.check.released ?? 0) + (counted ? 1 : 0);
652
712
  const why = excerptShown(cause, await deps.shown(), CHECK_TEXT_MAX);
653
713
  // Overtaken is read again inside the write: a newer revision's record can land while the cause is being cut.
654
- const still = (was, current) => sameReplay(was, record) && !overtaken(current, was);
714
+ const still = (was, current) => sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was);
655
715
  const bar = { ...record.check, ...(released ? { released } : {}) };
656
- if (released >= SDK_CHECK_RELEASES)
657
- return stopUnchecked(deps, record.workflow, record.digest, bar, `the connected agent gave back ${plural(released, "reserved native turn")} with no answer to check it against (the last: ${why})`, still, {}, sdkExtra(record));
716
+ const at = iso((deps.now ?? Date.now)());
717
+ if (released >= SDK_CHECK_RELEASES) {
718
+ // A hold, never `stopped`: it asks the next compile for a revision (learn/compile.ts heldNamesOf), checked afresh.
719
+ const reason = `the connected agent gave back ${plural(released, "reserved native turn")} in a row with no answer to check it against (the last: ${why}). It is not promoted; the agent's next compile revises it, and the revision is checked afresh`;
720
+ const held = await recordPromotion(deps.store.settings, deps.agentId, { workflow: record.workflow, digest: record.digest, at, decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [] }, ...seedOf(deps), ...sdkExtra(record) }, still);
721
+ if (held.won)
722
+ deps.log(`workflow-first: ${record.workflow} at ${record.digest} held: ${reason}`);
723
+ return held;
724
+ }
658
725
  const { runs: _runs, inputs: _inputs, ...rest } = record;
659
726
  const kept = await recordPromotion(deps.store.settings, deps.agentId, {
660
- ...rest, at: iso((deps.now ?? Date.now)()), check: bar,
661
- reason: `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} before the check stops)` : ""}. Nothing was promoted.`,
727
+ ...rest, at, check: bar,
728
+ reason: `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} in a row before it is held for a recompile)` : ""}. Nothing was promoted.`,
662
729
  }, still);
663
730
  if (kept.won)
664
731
  deps.log(`workflow-first: ${record.workflow} at ${record.digest} waits for another native turn: ${why}`);
665
732
  return kept;
666
733
  }
667
734
  /** A connected agent's check waiting at a revision the folder moved past (an owner's edit landed a newer one): set aside
668
- * with nothing checked, never promoted, and `stopped` as any stop with nothing checked, so it spends no recompile
669
- * (attemptOf): the newer revision is the one checked next. */
735
+ * with nothing decided, never promoted (the turns it checked kept on the record), and `stopped` as any stop with
736
+ * nothing checked, so it spends no recompile (attemptOf): the newer revision is the one checked next. */
670
737
  async function setAside(deps, pending) {
671
738
  if (!pending.check)
672
739
  return;
673
740
  await recordPromotion(deps.store.settings, deps.agentId, {
674
741
  ...pending, at: iso((deps.now ?? Date.now)()), decided: "hold",
675
- reason: `${NOTHING_TO_CHECK}: a newer revision of it landed before a native turn of the connected agent checked it. It is not promoted; the newer revision is checked instead`,
742
+ reason: `${NOTHING_TO_CHECK}: a newer revision of it landed before the connected agent's native turns finished checking it. It is not promoted; the newer revision is checked instead`,
676
743
  check: { ...pending.check, n: 0, agreed: 0, alone: 0, of: [], stopped: true },
677
744
  }, (was, current) => waitingSdk(was) && was.replay_id === pending.replay_id && !overtaken(current, was));
678
745
  }
@@ -704,6 +771,10 @@ function replayLaunchOf(deps) {
704
771
  * id. A replay settled meanwhile, and a newer replay of the same revision its owner started since (a held revision may
705
772
  * be replayed again), are not: an older replay's late decision never lands over a newer one. */
706
773
  const sameReplay = (was, record) => was?.decided === "replaying" && was.replay_id === record.replay_id;
774
+ /** Whether `was` still reserves `record`'s native turn (a connected agent's check: one turn reserved at a time, its run
775
+ * first in `runs`). A turn's row (sdkCheckTurn) and its give-back (releaseSdkCheck) each take the turn off the record, so
776
+ * a second writer that read the same reservation finds it gone. */
777
+ const heldTurn = (was, record) => record.runs?.[0] !== undefined && was?.runs?.[0] === record.runs[0];
707
778
  /** Cancels each of `record`'s replay runs not ended, as a person's cancel is (an in-flight one stops, what it spent booked
708
779
  * on its row): once its check is decided with runs still at work (past its deadline). How many were sent their cancel. The
709
780
  * record is the durable half: a cancel that is lost (a crash after the record, a write that fails) leaves a run whose
@@ -1,4 +1,3 @@
1
- import { type Stats } from "node:fs";
2
1
  import type { Duplex } from "node:stream";
3
2
  import type { Workspace } from "../workspace/workspace.js";
4
3
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
@@ -74,19 +73,16 @@ export declare class SlotHold {
74
73
  }
75
74
  /** The run's own top folders: its folder (work and recordings beneath it) and its scratch folder. */
76
75
  export declare const runTops: (data: string, agentId: string, runId: string) => string[];
77
- /** Every entry under `dir` the server's user owns, given to group `gid` as the helper's reown gives a slot's: a folder
78
- * the group's to enter and write (2770), a file's owner bits copied to the group, none for others. The whole tree, a
79
- * symlink never followed nor changed (an lstat's). Run while no process of the slot is alive (after its reap), so
80
- * nothing it walks is swapped under it. */
81
- export declare function toSlotGroup(dir: string, gid: number): Promise<void>;
82
- /** The other slots that own an entry anywhere under `dir`, as the helper's reown walks it: the whole tree, a symlink
83
- * never followed (an lstat's, never a directory). `statOf`: the stat it reads (a test's). */
84
- export declare function slotsUnder(dir: string, slot: number, statOf?: (path: string) => Promise<Stats>): Promise<number[]>;
76
+ /** At a claim, before anything of the run is placed: its top folders and everything in them the server's user's again
77
+ * (the helper's `own runner`), whoever an earlier claim left them to. Throws, in words, when they could not be. */
78
+ export declare function takeBackRunFolders(isolation: Extract<RunIsolation, {
79
+ kind: "uid";
80
+ }>, tops: readonly string[]): Promise<void>;
85
81
  /** After the run's process ended: every process of the slot's uid killed, its files in the shared temporary folders
86
- * removed, what it left in its folders readable and removable by the server's group, and its top folders the server's
87
- * own again (0770), which the slot's next run cannot enter. Whether the reap held: the helper kills until no process of
88
- * the uid is left, and says so; false when one still is, or the reap could not run (the slot is then never run on
89
- * again by this runner). */
82
+ * removed, and its top folders with everything in them given back to the server's user (the helper's `own runner`:
83
+ * the server's uid and group, folders 2770), which the slot's next run cannot enter. Whether the reap held: the helper
84
+ * kills until no process of the uid is left, and says so, and the folders were given back; false when a process still
85
+ * is, or either step could not run (the slot is then never run on again by this runner). */
90
86
  export declare function reapSlot(isolation: Extract<RunIsolation, {
91
87
  kind: "uid";
92
88
  }>, slot: number, tops: readonly string[], log: (line: string) => void): Promise<boolean>;
@@ -154,9 +150,10 @@ export declare const childArgv: () => string[];
154
150
  * A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
155
151
  * and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
156
152
  * run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
157
- * its inbox. A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
153
+ * its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
154
+ * A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
158
155
  * connectors, whose rows are the server's. */
159
- export declare const runsInRunner: (harness: string, launch: Pick<RunLaunch, "sdk" | "native">) => boolean;
156
+ export declare const runsInRunner: (harness: string, launch: Pick<RunLaunch, "sdk" | "native" | "cli_learning">) => boolean;
160
157
  /** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
161
158
  export declare const LOGIN_NEEDS_SERVER_USER = "A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set AGENTRUN_RUN_USER=same, or give the run a model_key.";
162
159
  /** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents