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

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 (146) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +142 -17
  3. package/dist/agents-store.js +7 -3
  4. package/dist/api-only.d.ts +2 -1
  5. package/dist/api-only.js +3 -2
  6. package/dist/capacity.d.ts +50 -0
  7. package/dist/capacity.js +49 -0
  8. package/dist/cli-learning/claude-wire.d.ts +41 -0
  9. package/dist/cli-learning/claude-wire.js +258 -0
  10. package/dist/cli-learning/cli.d.ts +11 -0
  11. package/dist/cli-learning/cli.js +241 -0
  12. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  13. package/dist/cli-learning/codex-worktree.js +119 -0
  14. package/dist/cli-learning/connections.d.ts +62 -0
  15. package/dist/cli-learning/connections.js +87 -0
  16. package/dist/cli-learning/entry.d.ts +1 -0
  17. package/dist/cli-learning/entry.js +4 -0
  18. package/dist/cli-learning/evidence.d.ts +78 -0
  19. package/dist/cli-learning/evidence.js +492 -0
  20. package/dist/cli-learning/hook.d.ts +33 -0
  21. package/dist/cli-learning/hook.js +544 -0
  22. package/dist/cli-learning/install.d.ts +33 -0
  23. package/dist/cli-learning/install.js +335 -0
  24. package/dist/cli-learning/observation-proof.d.ts +14 -0
  25. package/dist/cli-learning/observation-proof.js +10 -0
  26. package/dist/cli-learning/policy.d.ts +48 -0
  27. package/dist/cli-learning/policy.js +363 -0
  28. package/dist/cli-learning/schema.d.ts +16 -0
  29. package/dist/cli-learning/schema.js +27 -0
  30. package/dist/cli-learning/state.d.ts +23 -0
  31. package/dist/cli-learning/state.js +61 -0
  32. package/dist/cli.js +24 -2
  33. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  34. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  35. package/dist/console/index.html +2 -2
  36. package/dist/email/email-faux.d.ts +3 -1
  37. package/dist/email/email-faux.js +3 -2
  38. package/dist/email/routes.js +22 -12
  39. package/dist/harness-install.d.ts +6 -2
  40. package/dist/harness-install.js +40 -8
  41. package/dist/harness.d.ts +1 -1
  42. package/dist/harness.js +2 -2
  43. package/dist/learn/secrets.js +14 -3
  44. package/dist/learning-words.d.ts +1 -1
  45. package/dist/learning-words.js +1 -1
  46. package/dist/mcp-pin-first.js +2 -1
  47. package/dist/mcp-private-hosts.d.ts +24 -3
  48. package/dist/mcp-private-hosts.js +53 -3
  49. package/dist/model-gateway.d.ts +2 -0
  50. package/dist/model-gateway.js +3 -1
  51. package/dist/native/runtimes.d.ts +2 -0
  52. package/dist/native/runtimes.js +2 -0
  53. package/dist/observation/learning.d.ts +32 -0
  54. package/dist/observation/learning.js +66 -0
  55. package/dist/observation/observer.d.ts +8 -1
  56. package/dist/observation/observer.js +89 -9
  57. package/dist/observation/schema.js +12 -4
  58. package/dist/observation/usage-identity.d.ts +9 -0
  59. package/dist/observation/usage-identity.js +11 -0
  60. package/dist/openapi.js +89 -13
  61. package/dist/run-launch.d.ts +14 -0
  62. package/dist/run-launch.js +4 -0
  63. package/dist/run-view.d.ts +2 -0
  64. package/dist/run-view.js +12 -7
  65. package/dist/runner/adapter-loop.js +29 -26
  66. package/dist/runner/adapter-run-spec.js +2 -2
  67. package/dist/runner/beside.d.ts +13 -0
  68. package/dist/runner/beside.js +27 -8
  69. package/dist/runner/cli-run-spec.js +2 -2
  70. package/dist/runner/disk-free.d.ts +44 -0
  71. package/dist/runner/disk-free.js +96 -0
  72. package/dist/runner/feedback-round.d.ts +12 -8
  73. package/dist/runner/feedback-round.js +16 -30
  74. package/dist/runner/harness-loops.js +3 -1
  75. package/dist/runner/journal-kinds.d.ts +1 -1
  76. package/dist/runner/learning-end.js +4 -0
  77. package/dist/runner/main.d.ts +17 -6
  78. package/dist/runner/main.js +187 -45
  79. package/dist/runner/presence.d.ts +11 -2
  80. package/dist/runner/presence.js +31 -3
  81. package/dist/runner/run-child-host.d.ts +12 -15
  82. package/dist/runner/run-child-host.js +46 -108
  83. package/dist/runner/run-errors.js +2 -0
  84. package/dist/runner/runner-check.d.ts +51 -0
  85. package/dist/runner/runner-check.js +206 -0
  86. package/dist/runner/runner-metrics.d.ts +19 -0
  87. package/dist/runner/runner-metrics.js +49 -0
  88. package/dist/runner/runner.d.ts +37 -0
  89. package/dist/runner/runner.js +43 -3
  90. package/dist/runner/sdk-loop.js +34 -22
  91. package/dist/runs-over-store.d.ts +8 -1
  92. package/dist/runs-over-store.js +57 -9
  93. package/dist/sdk/runs.d.ts +22 -2
  94. package/dist/sdk/runs.js +103 -34
  95. package/dist/server.d.ts +3 -0
  96. package/dist/server.js +149 -26
  97. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  98. package/dist/start-switches.js +2 -0
  99. package/dist/stats.d.ts +4 -0
  100. package/dist/stats.js +1 -1
  101. package/dist/store/agent-body.d.ts +12 -0
  102. package/dist/store/agent-body.js +16 -2
  103. package/dist/store/dialect.d.ts +2 -0
  104. package/dist/store/dialect.js +1 -0
  105. package/dist/store/index.d.ts +3 -3
  106. package/dist/store/index.js +2 -2
  107. package/dist/store/postgres/connection.d.ts +5 -2
  108. package/dist/store/postgres/connection.js +19 -7
  109. package/dist/store/postgres/dialect.js +1 -0
  110. package/dist/store/postgres/migrate.d.ts +30 -0
  111. package/dist/store/postgres/migrate.js +72 -5
  112. package/dist/store/postgres/migration-lint.d.ts +8 -0
  113. package/dist/store/postgres/migration-lint.js +119 -0
  114. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  115. package/dist/store/postgres/store.d.ts +8 -3
  116. package/dist/store/postgres/store.js +31 -11
  117. package/dist/store/schema.d.ts +18 -1
  118. package/dist/store/schema.js +33 -2
  119. package/dist/store/sqlite/run-launch.d.ts +9 -1
  120. package/dist/store/sqlite/run-launch.js +44 -0
  121. package/dist/store/sqlite/store.d.ts +17 -0
  122. package/dist/store/sqlite/store.js +87 -10
  123. package/dist/store/store-schema.d.ts +34 -0
  124. package/dist/store/store-schema.js +125 -0
  125. package/dist/store/store.d.ts +53 -1
  126. package/dist/store/store.js +13 -0
  127. package/dist/store-reads/analytics.d.ts +3 -2
  128. package/dist/store-reads/analytics.js +20 -8
  129. package/dist/store-view.d.ts +4 -3
  130. package/dist/store-view.js +11 -7
  131. package/dist/templates.d.ts +3 -2
  132. package/dist/tool-gate.d.ts +4 -2
  133. package/dist/unified-usage.d.ts +24 -0
  134. package/dist/unified-usage.js +400 -0
  135. package/dist/uploads-archil.d.ts +100 -0
  136. package/dist/uploads-archil.js +430 -0
  137. package/dist/uploads.d.ts +55 -1
  138. package/dist/uploads.js +185 -98
  139. package/dist/validate.js +1 -1
  140. package/dist/workspace/archil-disk.d.ts +6 -5
  141. package/dist/workspace/archil-disk.js +27 -12
  142. package/dist/workspace/archil.js +3 -2
  143. package/package.json +10 -10
  144. package/skills/agentrun-serve/SKILL.md +52 -7
  145. package/dist/console/assets/index-D0mr9wfZ.css +0 -1
  146. package/dist/console/assets/index-D7G6o-1E.js +0 -720
@@ -0,0 +1,44 @@
1
+ import type { KeyEnv } from "../key-meta.js";
2
+ import type { Settings } from "../store/store.js";
3
+ /** The file in the server's data root that holds its id (made once, kept across starts). */
4
+ export declare const DATA_ROOT_FILE = "data-root.id";
5
+ /** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
6
+ export declare const DATA_ROOT_KEY = "server.data_root";
7
+ /** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
8
+ export declare function dataRootIdIn(dataDir: string): string | undefined;
9
+ /** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
10
+ * the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
11
+ export declare function recordDataRoot(store: {
12
+ settings: Pick<Settings, "put">;
13
+ }, dataDir: string): Promise<string>;
14
+ /** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
15
+ * last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
16
+ * none started yet), which a caller takes as shared. */
17
+ export declare function sharesServerDisk(store: {
18
+ settings: Pick<Settings, "get">;
19
+ }, dataDir: string): Promise<boolean | undefined>;
20
+ /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
21
+ * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
22
+ * (runner-check.ts RUN_ENV_KEY). */
23
+ export declare function serverInArchilMode(store: {
24
+ settings: Pick<Settings, "get">;
25
+ }): Promise<boolean>;
26
+ /** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
27
+ * whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
28
+ * holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
29
+ * is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
30
+ * on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
31
+ export declare function diskFreeRefusal(store: {
32
+ settings: Pick<Settings, "get">;
33
+ }, dataDir: string, env: KeyEnv, storeKind: string): Promise<string | undefined>;
34
+ /** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
35
+ export declare const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
36
+ /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
37
+ export declare const DISK_FREE_NO_ARCHIL: string;
38
+ /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
39
+ export declare const DISK_FREE_GATE_MS = 5000;
40
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
41
+ * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
42
+ export declare function diskFreeGate(store: {
43
+ settings: Pick<Settings, "get">;
44
+ }, dataDir: string, env: KeyEnv, storeKind: string, now?: () => number): (fresh: boolean) => Promise<string | undefined>;
@@ -0,0 +1,96 @@
1
+ // A runner on a disk of its own (a disk-free runner): `agentrun-serve runner --data D` where D is the runner's own local
2
+ // directory, not the server's, on the Postgres store AGENTRUN_STORE_URL names. Its data directory then holds only what
3
+ // is the runner's: its heartbeat, its runs' uid slots and their scratch, and the harnesses it installs at a claim. It never
4
+ // reads the server's: a run's folder is on Archil (Mode 2), which every machine reaches; Mode 1 keeps it on the server's
5
+ // own disk, which this runner can't see, so a disk-free runner claims nothing while the server is in Mode 1.
6
+ //
7
+ // Which disk is the server's: the server keeps an id of its data root in a file there (DATA_ROOT_FILE, made once) and
8
+ // says it in the store at each start (DATA_ROOT_KEY). A runner whose data directory holds the same id shares the server's
9
+ // disk (the image's server-and-runner, compose's runners on one /data volume); any other runner is disk-free. A store
10
+ // whose server has not said its data root yet (one older than this) is taken as shared, as every runner was before.
11
+ // SQLite is in the data directory, so a runner on it always shares the server's.
12
+ import { randomBytes } from "node:crypto";
13
+ import { readFileSync, writeFileSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ import { ARCHIL_SETTINGS_ENV, loadArchilSettings } from "../archil-settings.js";
16
+ import { serverRunEnv } from "./runner-check.js";
17
+ /** The file in the server's data root that holds its id (made once, kept across starts). */
18
+ export const DATA_ROOT_FILE = "data-root.id";
19
+ /** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
20
+ export const DATA_ROOT_KEY = "server.data_root";
21
+ const ID = /^[0-9a-f]{32}$/;
22
+ /** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
23
+ export function dataRootIdIn(dataDir) {
24
+ try {
25
+ const id = readFileSync(join(dataDir, DATA_ROOT_FILE), "utf8").trim();
26
+ return ID.test(id) ? id : undefined;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ /** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
33
+ * the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
34
+ export async function recordDataRoot(store, dataDir) {
35
+ let id = dataRootIdIn(dataDir);
36
+ if (id === undefined) {
37
+ id = randomBytes(16).toString("hex");
38
+ writeFileSync(join(dataDir, DATA_ROOT_FILE), `${id}\n`, { mode: 0o600 });
39
+ }
40
+ await store.settings.put(DATA_ROOT_KEY, { v: 1, id });
41
+ return id;
42
+ }
43
+ /** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
44
+ * last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
45
+ * none started yet), which a caller takes as shared. */
46
+ export async function sharesServerDisk(store, dataDir) {
47
+ const said = await store.settings.get(DATA_ROOT_KEY);
48
+ const id = typeof said === "object" && said !== null ? said.id : undefined;
49
+ if (typeof id !== "string" || !ID.test(id))
50
+ return undefined;
51
+ return dataRootIdIn(dataDir) === id;
52
+ }
53
+ /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
54
+ * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
55
+ * (runner-check.ts RUN_ENV_KEY). */
56
+ export async function serverInArchilMode(store) {
57
+ if ((await loadArchilSettings(store)) !== undefined)
58
+ return true;
59
+ const names = await serverRunEnv(store);
60
+ return names !== undefined && [ARCHIL_SETTINGS_ENV.region, ARCHIL_SETTINGS_ENV.s3Url].every((name) => names.includes(name));
61
+ }
62
+ /** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
63
+ * whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
64
+ * holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
65
+ * is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
66
+ * on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
67
+ export async function diskFreeRefusal(store, dataDir, env, storeKind) {
68
+ if (storeKind === "sqlite")
69
+ return undefined;
70
+ if ((await sharesServerDisk(store, dataDir)) !== false)
71
+ return undefined;
72
+ if (!(await serverInArchilMode(store)))
73
+ return DISK_FREE_MODE_1;
74
+ if ((await loadArchilSettings(store, env)) === undefined)
75
+ return DISK_FREE_NO_ARCHIL;
76
+ return undefined;
77
+ }
78
+ /** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
79
+ export const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
80
+ /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
81
+ export const DISK_FREE_NO_ARCHIL = `this runner's data directory is not the server's, and the server keeps each run's folder on Archil (Mode 2) by the Archil settings in its environment, which this runner does not hold. Hand this runner the server's ${ARCHIL_SETTINGS_ENV.region} and ${ARCHIL_SETTINGS_ENV.s3Url} (and ${ARCHIL_SETTINGS_ENV.image} when the server has it), or save the Archil settings in the store.`;
82
+ /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
83
+ export const DISK_FREE_GATE_MS = 5_000;
84
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
85
+ * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
86
+ export function diskFreeGate(store, dataDir, env, storeKind, now = Date.now) {
87
+ let kept;
88
+ return async (fresh) => {
89
+ const at = now();
90
+ if (!fresh && kept && at - kept.at < DISK_FREE_GATE_MS)
91
+ return kept.words;
92
+ const words = await diskFreeRefusal(store, dataDir, env, storeKind);
93
+ kept = { at, words };
94
+ return words;
95
+ };
96
+ }
@@ -15,13 +15,17 @@ export interface KeptEnd {
15
15
  readonly outcome?: EndData["outcome"];
16
16
  readonly endedAt: number;
17
17
  }
18
- /** A feedback round, as its steer's body carries it (`feedback`) and its FEEDBACK entry keeps it: the round, whether the
19
- * grade said right, the grade's words (`text`), and the end the run had when the grade opened it again (`kept`). */
18
+ /** A feedback round, as its FEEDBACK entry keeps it: the round, whether the grade said right, and the grade's words
19
+ * (`text`). */
20
20
  export interface FeedbackData {
21
21
  readonly round: FeedbackRound;
22
22
  readonly correct: boolean;
23
23
  readonly text: string;
24
- readonly kept?: KeptEnd;
24
+ }
25
+ /** A feedback round as its steer's body carries it (`feedback`, beside the words): with the end the run had when the
26
+ * grade opened it again (`kept`), which the steer's taking keeps as the job's end (KINDS.jobEnd, beside FEEDBACK). */
27
+ export interface FeedbackSteer extends FeedbackData {
28
+ readonly kept: KeptEnd;
25
29
  }
26
30
  /** Whether the run's root `entries` hold a job's end kept for its look-back (KINDS.jobEnd) with no run end after it: the
27
31
  * job ended and its look-back is under way, whether or not that look-back has asked anything yet. A follow-up's turn
@@ -31,8 +35,8 @@ export declare function jobEndOpen(entries: readonly {
31
35
  }[]): boolean;
32
36
  /** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
33
37
  * look-back under way, or one whose job's end was never kept):
34
- * - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
35
- * - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
38
+ * - the job's end kept for it (KINDS.jobEnd, with its time), newer than the run's last end: by its claim before the
39
+ * end-of-run step, or for a grade's round by the steer's taking;
36
40
  * - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
37
41
  * A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
38
42
  export declare function keptEndOf(entries: readonly {
@@ -45,9 +49,9 @@ export declare function keptEndOf(entries: readonly {
45
49
  export declare function feedbackRoundOf(grade: {
46
50
  readonly path: RunPath;
47
51
  }, label: string | undefined): FeedbackRound | undefined;
48
- /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
49
- * message API never does), else undefined. */
50
- export declare function feedbackOf(body: unknown): FeedbackData | undefined;
52
+ /** The feedback round a steer's body asks for (`body.feedback`, the server's own: openFeedbackRound writes it with the
53
+ * end it kept, and the message API never does), else undefined. */
54
+ export declare function feedbackOf(body: unknown): FeedbackSteer | undefined;
51
55
  /** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
52
56
  * it, else undefined. */
53
57
  export declare function pendingFeedbackOf(entries: readonly {
@@ -15,18 +15,12 @@ import { RunFinal } from "../store/store.js";
15
15
  import { KINDS } from "./journal-kinds.js";
16
16
  import { commandRequest } from "./loop.js";
17
17
  export const FEEDBACK_ROUNDS = ["correction"];
18
- const END_STATES = ["ended", "stopped", "failed"];
19
- const OUTCOMES = ["completed", "escalated", "stopped", "cancelled"];
20
- /** A kept end as a steer's body or a journal entry holds it, else undefined. */
21
- function keptOf(value) {
22
- const kept = value;
23
- if (!kept || typeof kept !== "object" || !END_STATES.includes(kept.state) || typeof kept.endedAt !== "number")
18
+ /** A feedback round's `round`, `correct` and words, else undefined. */
19
+ function roundOf(fed, text) {
20
+ const round = fed;
21
+ if (!round || typeof round !== "object" || !FEEDBACK_ROUNDS.includes(round.round) || typeof round.correct !== "boolean" || typeof text !== "string")
24
22
  return undefined;
25
- if (kept.summary !== undefined && typeof kept.summary !== "string")
26
- return undefined;
27
- if (kept.outcome !== undefined && !OUTCOMES.includes(kept.outcome))
28
- return undefined;
29
- return { state: kept.state, ...(kept.summary !== undefined ? { summary: kept.summary } : {}), ...(kept.outcome !== undefined ? { outcome: kept.outcome } : {}), endedAt: kept.endedAt };
23
+ return { round: round.round, correct: round.correct, text };
30
24
  }
31
25
  /** The end run `run` has now, as a grade's round keeps it: only one a round opens again (reopenableWhere: ended, or
32
26
  * stopped by a person), with its end time. */
@@ -43,21 +37,16 @@ export function jobEndOpen(entries) {
43
37
  }
44
38
  /** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
45
39
  * look-back under way, or one whose job's end was never kept):
46
- * - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
47
- * - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
40
+ * - the job's end kept for it (KINDS.jobEnd, with its time), newer than the run's last end: by its claim before the
41
+ * end-of-run step, or for a grade's round by the steer's taking;
48
42
  * - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
49
43
  * A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
50
44
  export function keptEndOf(entries, commands) {
51
- const last = (kind) => entries.findLastIndex((entry) => entry.kind === kind);
52
- const end = last(KINDS.end);
53
45
  if (jobEndOpen(entries)) {
54
- const data = entries[last(KINDS.jobEnd)].data;
55
- return keptOf(data?.end && data.endedAt !== undefined ? { ...data.end, endedAt: data.endedAt } : undefined);
46
+ const { end, endedAt } = entries.findLast((entry) => entry.kind === KINDS.jobEnd).data;
47
+ return { state: end.state, ...(end.summary !== undefined ? { summary: end.summary } : {}), ...(end.outcome !== undefined ? { outcome: end.outcome } : {}), endedAt };
56
48
  }
57
- const fed = last(KINDS.feedback);
58
- if (fed > end)
59
- return keptOf(entries[fed].data?.kept);
60
- const steer = commands.find((command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body)?.kept !== undefined);
49
+ const steer = commands.find((command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body) !== undefined);
61
50
  return steer ? feedbackOf(steer.body).kept : undefined;
62
51
  }
63
52
  /** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
@@ -66,15 +55,12 @@ export function keptEndOf(entries, commands) {
66
55
  export function feedbackRoundOf(grade, label) {
67
56
  return (grade.path === "agent" || grade.path === "handed_back") && label ? "correction" : undefined;
68
57
  }
69
- /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
70
- * message API never does), else undefined. */
58
+ /** The feedback round a steer's body asks for (`body.feedback`, the server's own: openFeedbackRound writes it with the
59
+ * end it kept, and the message API never does), else undefined. */
71
60
  export function feedbackOf(body) {
72
61
  const fed = body?.feedback;
73
- const text = body?.text;
74
- if (!fed || typeof fed !== "object" || !FEEDBACK_ROUNDS.includes(fed.round) || typeof fed.correct !== "boolean" || typeof text !== "string")
75
- return undefined;
76
- const kept = keptOf(fed.kept);
77
- return { round: fed.round, correct: fed.correct, text, ...(kept ? { kept } : {}) };
62
+ const round = roundOf(fed, body?.text);
63
+ return round && fed?.kept ? { ...round, kept: fed.kept } : undefined;
78
64
  }
79
65
  /** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
80
66
  * it, else undefined. */
@@ -82,7 +68,7 @@ export function pendingFeedbackOf(entries) {
82
68
  const at = entries.findLastIndex((entry) => entry.kind === KINDS.feedback);
83
69
  if (at < 0 || entries.slice(at + 1).some((entry) => entry.kind === KINDS.end))
84
70
  return undefined;
85
- return feedbackOf({ feedback: entries[at].data, text: entries[at].data?.text });
71
+ return roundOf(entries[at].data, entries[at].data?.text);
86
72
  }
87
73
  /** What the end-of-run turn of a feedback round is told before its prompt: the grade and its words. */
88
74
  export function feedbackAsk(feedback) {
@@ -125,7 +111,7 @@ export async function openFeedbackRound(store, grade, label, canTurn = () => tru
125
111
  const launched = await store.runs.launch(grade.run).catch(() => undefined);
126
112
  const launch = launched ? readLaunchBody(launched.body) : undefined;
127
113
  // Source sessions and application-owned SDK tasks cannot consume a managed feedback steer.
128
- if (launch?.native || launch?.sdk)
114
+ if (launch?.native || launch?.sdk || launch?.cli_learning)
129
115
  return null;
130
116
  const learning = launch?.learning;
131
117
  if (!learning || learning.use)
@@ -72,8 +72,10 @@ async function loopOn(deps, harness, launch, runId) {
72
72
  }
73
73
  // A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
74
74
  // start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
75
- if (launch.sdk)
75
+ if (launch.sdk || launch.cli_learning)
76
76
  return createSdkLoop(launch, deps, async () => {
77
+ if (launch.cli_learning)
78
+ throw new Error("Connected CLI capture has no workflow execution bridge.");
77
79
  const base = deps.env ?? process.env;
78
80
  const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
79
81
  // It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
@@ -348,7 +348,7 @@ export interface EndData {
348
348
  export interface JobEndData {
349
349
  readonly end: EndData;
350
350
  readonly failedWith?: string;
351
- readonly endedAt?: number;
351
+ readonly endedAt: number;
352
352
  }
353
353
  /** An escalated workflow run's review as its end keeps it: the escalation's kind, the escalate node's label (else the node
354
354
  * it escalated at), and its summary (else the run's). Served as the run's `review`, `at` its end. */
@@ -92,6 +92,10 @@ export function learningEndOfRun(launch, deps) {
92
92
  // A grade's feedback round always has something new, the grade's words (feedback-round.ts), whatever the job did.
93
93
  nothingNew: async (runId) => !pendingFeedbackOf(await runEntries(deps.store, runId, BACKGROUND_CONTEXT)) && onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
94
94
  feedback: async (runId) => {
95
+ // A source hook uploads task dialogue, not owner feedback addressed to AgentRun.
96
+ // CLI corrections are written explicitly through the owner corrections API.
97
+ if (launch.cli_learning)
98
+ return [];
95
99
  const [entries, rows] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })]);
96
100
  return ownerWords(entries, rows);
97
101
  },
@@ -37,6 +37,9 @@ export interface RunnerProcessOptions {
37
37
  storeUrl?: string;
38
38
  /** What a person should see at the start (a clock far from the store's Postgres): stderr by default. */
39
39
  warn?: (message: string) => void;
40
+ /** How often the store's runner floor is read again (Store.schemaState): each renewal (RUNNER_RENEW_EVERY_MS) unless a
41
+ * test says. */
42
+ floorEveryMs?: number;
40
43
  }
41
44
  export interface RunnerProcess {
42
45
  readonly runner: Runner;
@@ -48,6 +51,10 @@ export interface RunnerProcess {
48
51
  /** What its runs may hold, in MiB (RunnerMemory.budgetMib): its host's memory, or its container's limit, less the
49
52
  * server's own. Said once at its start, after the ready line. */
50
53
  readonly memoryMib: number;
54
+ /** Settles, once, with the words of why, when the store's runner floor rises above the version this build knows (a
55
+ * later server applied a migration that breaks earlier runners): this runner should close, handing its runs back, and
56
+ * its process exit non-zero. Never settles otherwise. */
57
+ readonly outdated: Promise<string>;
51
58
  /** Closes the runner (its loops stopped, its runs released), then its store connection. */
52
59
  close(): Promise<void>;
53
60
  }
@@ -157,12 +164,16 @@ export declare function runnerArgs(argv: readonly string[]): {
157
164
  faux?: string;
158
165
  fauxBrowser?: string;
159
166
  check?: true;
167
+ envOnly?: true;
168
+ heartbeatOnly?: true;
160
169
  harnessModules?: string[];
161
170
  };
162
- /** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
163
- * says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
164
- * that came before the handlers would end the process unclosed. */
165
- export declare function runUntilSignalled(process: RunnerProcess, signals?: readonly NodeJS.Signals[], ready?: () => void): Promise<void>;
171
+ /** Runs until SIGTERM or SIGINT, or until the store's runner floor rises above this runner (RunnerProcess.outdated),
172
+ * then closes: nothing more claimed, the drain, its runs handed back. Answers the floor's words when that was the stop,
173
+ * else undefined. `ready` is called once the signals are handled, never before: a line that says the runner is ready (on
174
+ * a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one that came before the
175
+ * handlers would end the process unclosed. `outdated`: told the floor's words before the close begins. */
176
+ export declare function runUntilSignalled(process: Pick<RunnerProcess, "close"> & Partial<Pick<RunnerProcess, "outdated">>, signals?: readonly NodeJS.Signals[], ready?: () => void, outdated?: (why: string) => void): Promise<string | undefined>;
166
177
  /** The runner process's last resort (runnerMain installs it for unhandledRejection and uncaughtException): says what
167
178
  * went wrong, in the runner's name with its stack, then exits 1 at once, closing nothing. A runner that went on after
168
179
  * an error nothing handled could keep renewing the claim of a run whose loop is dead, and that run would hang claimed
@@ -175,8 +186,8 @@ export declare function lastResort(name: string, write?: (line: string) => void,
175
186
  * lapse of every claim at once shows its cause. */
176
187
  export declare function troubleLine(name: string, event: RunnerEvent): string | undefined;
177
188
  /** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store this runner cannot open (a schema it does not
178
- * know, none set up yet, or one its server has yet to upgrade); 1: anything else; 0: closed on a signal, or --check found
179
- * a fresh heartbeat. AGENTRUN_RUNNER_NAME names it when --name does not. */
189
+ * know, none set up yet, or one its server has yet to upgrade), or one whose runner floor rose above it while it ran
190
+ * (closed, its runs handed back); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names it when --name does not. */
180
191
  export declare function runnerMain(argv: readonly string[], given?: NodeJS.ProcessEnv, hooks?: RunnerMainHooks): Promise<number>;
181
192
  /** A test's hooks into runnerMain: `started`, awaited once the runner has started claiming and before its stop handlers
182
193
  * take over from the ones its start listened on (the window a stop must not fall through). */