@parcha/agentrun-serve 0.1.0-beta.49 → 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 (216) hide show
  1. package/CHANGELOG.md +173 -9
  2. package/README.md +246 -39
  3. package/dist/agent-delete.d.ts +3 -2
  4. package/dist/agent-delete.js +29 -4
  5. package/dist/agents-store.js +7 -3
  6. package/dist/api-only.d.ts +8 -10
  7. package/dist/api-only.js +11 -12
  8. package/dist/capacity.d.ts +50 -0
  9. package/dist/capacity.js +49 -0
  10. package/dist/cli-learning/claude-wire.d.ts +41 -0
  11. package/dist/cli-learning/claude-wire.js +258 -0
  12. package/dist/cli-learning/cli.d.ts +11 -0
  13. package/dist/cli-learning/cli.js +241 -0
  14. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  15. package/dist/cli-learning/codex-worktree.js +119 -0
  16. package/dist/cli-learning/connections.d.ts +62 -0
  17. package/dist/cli-learning/connections.js +87 -0
  18. package/dist/cli-learning/entry.d.ts +1 -0
  19. package/dist/cli-learning/entry.js +4 -0
  20. package/dist/cli-learning/evidence.d.ts +78 -0
  21. package/dist/cli-learning/evidence.js +492 -0
  22. package/dist/cli-learning/hook.d.ts +33 -0
  23. package/dist/cli-learning/hook.js +544 -0
  24. package/dist/cli-learning/install.d.ts +33 -0
  25. package/dist/cli-learning/install.js +335 -0
  26. package/dist/cli-learning/observation-proof.d.ts +14 -0
  27. package/dist/cli-learning/observation-proof.js +10 -0
  28. package/dist/cli-learning/policy.d.ts +48 -0
  29. package/dist/cli-learning/policy.js +363 -0
  30. package/dist/cli-learning/schema.d.ts +16 -0
  31. package/dist/cli-learning/schema.js +27 -0
  32. package/dist/cli-learning/state.d.ts +23 -0
  33. package/dist/cli-learning/state.js +61 -0
  34. package/dist/cli.js +24 -2
  35. package/dist/compute-cost.d.ts +101 -0
  36. package/dist/compute-cost.js +250 -0
  37. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  38. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/email/email-faux.d.ts +3 -1
  41. package/dist/email/email-faux.js +3 -2
  42. package/dist/email/routes.js +22 -12
  43. package/dist/eval-previous.d.ts +52 -0
  44. package/dist/eval-previous.js +164 -0
  45. package/dist/file-types.d.ts +2 -0
  46. package/dist/file-types.js +3 -1
  47. package/dist/harness-install.d.ts +6 -2
  48. package/dist/harness-install.js +40 -8
  49. package/dist/harness.d.ts +1 -1
  50. package/dist/harness.js +3 -2
  51. package/dist/learn/check.d.ts +8 -5
  52. package/dist/learn/check.js +25 -24
  53. package/dist/learn/repick.d.ts +22 -13
  54. package/dist/learn/repick.js +57 -56
  55. package/dist/learn/secrets.js +14 -3
  56. package/dist/learn/workflow-draft.d.ts +4 -0
  57. package/dist/learn/workflow-draft.js +10 -7
  58. package/dist/learned-workflow.js +8 -8
  59. package/dist/learning-setting.js +2 -2
  60. package/dist/learning-words.d.ts +1 -1
  61. package/dist/learning-words.js +1 -1
  62. package/dist/mcp-pin-first.js +2 -1
  63. package/dist/mcp-private-hosts.d.ts +24 -3
  64. package/dist/mcp-private-hosts.js +53 -3
  65. package/dist/model-gateway.d.ts +2 -0
  66. package/dist/model-gateway.js +3 -1
  67. package/dist/native/runtimes.d.ts +2 -0
  68. package/dist/native/runtimes.js +2 -0
  69. package/dist/observation/learning.d.ts +32 -0
  70. package/dist/observation/learning.js +66 -0
  71. package/dist/observation/observer.d.ts +8 -1
  72. package/dist/observation/observer.js +89 -9
  73. package/dist/observation/schema.js +12 -4
  74. package/dist/observation/usage-identity.d.ts +9 -0
  75. package/dist/observation/usage-identity.js +11 -0
  76. package/dist/openapi.js +113 -29
  77. package/dist/paid-calls.d.ts +13 -6
  78. package/dist/paid-calls.js +14 -8
  79. package/dist/run-launch.d.ts +16 -2
  80. package/dist/run-launch.js +6 -1
  81. package/dist/run-timeline-served.js +5 -3
  82. package/dist/run-usage.d.ts +23 -8
  83. package/dist/run-usage.js +100 -18
  84. package/dist/run-view.d.ts +2 -0
  85. package/dist/run-view.js +12 -7
  86. package/dist/runner/adapter-loop.d.ts +4 -0
  87. package/dist/runner/adapter-loop.js +44 -27
  88. package/dist/runner/adapter-run-spec.d.ts +8 -3
  89. package/dist/runner/adapter-run-spec.js +15 -8
  90. package/dist/runner/beside.d.ts +13 -0
  91. package/dist/runner/beside.js +27 -8
  92. package/dist/runner/big-writes.d.ts +33 -0
  93. package/dist/runner/big-writes.js +105 -0
  94. package/dist/runner/cli-run-spec.js +16 -8
  95. package/dist/runner/disk-free.d.ts +44 -0
  96. package/dist/runner/disk-free.js +96 -0
  97. package/dist/runner/feedback-round.d.ts +12 -8
  98. package/dist/runner/feedback-round.js +16 -30
  99. package/dist/runner/harness-loops.js +3 -1
  100. package/dist/runner/held.d.ts +4 -1
  101. package/dist/runner/journal-kinds.d.ts +1 -1
  102. package/dist/runner/learning-end.js +13 -4
  103. package/dist/runner/main.d.ts +17 -6
  104. package/dist/runner/main.js +187 -45
  105. package/dist/runner/metrics.d.ts +4 -0
  106. package/dist/runner/metrics.js +9 -0
  107. package/dist/runner/presence.d.ts +11 -2
  108. package/dist/runner/presence.js +31 -3
  109. package/dist/runner/run-child-host.d.ts +27 -17
  110. package/dist/runner/run-child-host.js +70 -116
  111. package/dist/runner/run-child.js +3 -0
  112. package/dist/runner/run-errors.js +2 -0
  113. package/dist/runner/runner-check.d.ts +51 -0
  114. package/dist/runner/runner-check.js +206 -0
  115. package/dist/runner/runner-metrics.d.ts +19 -0
  116. package/dist/runner/runner-metrics.js +49 -0
  117. package/dist/runner/runner.d.ts +37 -0
  118. package/dist/runner/runner.js +43 -3
  119. package/dist/runner/save-slots.d.ts +9 -0
  120. package/dist/runner/save-slots.js +91 -0
  121. package/dist/runner/sdk-loop.js +34 -22
  122. package/dist/runs-over-store.d.ts +8 -1
  123. package/dist/runs-over-store.js +57 -9
  124. package/dist/sdk/runs.d.ts +25 -6
  125. package/dist/sdk/runs.js +107 -35
  126. package/dist/sdk/runtimes.d.ts +19 -0
  127. package/dist/sdk/runtimes.js +23 -0
  128. package/dist/sdk/schema.d.ts +14 -8
  129. package/dist/sdk/schema.js +18 -6
  130. package/dist/server.d.ts +7 -0
  131. package/dist/server.js +151 -28
  132. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  133. package/dist/start-switches.js +2 -0
  134. package/dist/stats.d.ts +4 -0
  135. package/dist/stats.js +1 -1
  136. package/dist/store/agent-body.d.ts +13 -2
  137. package/dist/store/agent-body.js +19 -4
  138. package/dist/store/dialect.d.ts +2 -0
  139. package/dist/store/dialect.js +1 -0
  140. package/dist/store/index.d.ts +3 -3
  141. package/dist/store/index.js +2 -2
  142. package/dist/store/postgres/connection.d.ts +5 -2
  143. package/dist/store/postgres/connection.js +19 -7
  144. package/dist/store/postgres/dialect.js +1 -0
  145. package/dist/store/postgres/migrate.d.ts +30 -0
  146. package/dist/store/postgres/migrate.js +72 -5
  147. package/dist/store/postgres/migration-lint.d.ts +8 -0
  148. package/dist/store/postgres/migration-lint.js +119 -0
  149. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  150. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  151. package/dist/store/postgres/store.d.ts +8 -3
  152. package/dist/store/postgres/store.js +31 -11
  153. package/dist/store/schema.d.ts +26 -4
  154. package/dist/store/schema.js +45 -4
  155. package/dist/store/sqlite/connection.d.ts +3 -3
  156. package/dist/store/sqlite/connection.js +3 -3
  157. package/dist/store/sqlite/run-launch.d.ts +9 -1
  158. package/dist/store/sqlite/run-launch.js +44 -0
  159. package/dist/store/sqlite/store.d.ts +19 -4
  160. package/dist/store/sqlite/store.js +180 -93
  161. package/dist/store/store-schema.d.ts +34 -0
  162. package/dist/store/store-schema.js +125 -0
  163. package/dist/store/store.d.ts +61 -2
  164. package/dist/store/store.js +13 -0
  165. package/dist/store-reads/analytics.d.ts +3 -2
  166. package/dist/store-reads/analytics.js +20 -8
  167. package/dist/store-reads/cap.d.ts +9 -5
  168. package/dist/store-reads/cap.js +28 -2
  169. package/dist/store-reads/decisions.d.ts +21 -0
  170. package/dist/store-reads/decisions.js +22 -0
  171. package/dist/store-reads/journal.d.ts +8 -2
  172. package/dist/store-reads/journal.js +27 -8
  173. package/dist/store-view.d.ts +9 -4
  174. package/dist/store-view.js +48 -25
  175. package/dist/template-eval.d.ts +15 -1
  176. package/dist/template-eval.js +92 -13
  177. package/dist/templates.d.ts +4 -3
  178. package/dist/templates.js +4 -3
  179. package/dist/timeline/labels.js +17 -0
  180. package/dist/tool-gate.d.ts +4 -2
  181. package/dist/tool-list.js +1 -0
  182. package/dist/tools.d.ts +6 -2
  183. package/dist/tools.js +13 -1
  184. package/dist/trigger-targets.d.ts +21 -5
  185. package/dist/trigger-targets.js +13 -10
  186. package/dist/unified-usage.d.ts +24 -0
  187. package/dist/unified-usage.js +400 -0
  188. package/dist/uploads-archil.d.ts +100 -0
  189. package/dist/uploads-archil.js +430 -0
  190. package/dist/uploads.d.ts +55 -1
  191. package/dist/uploads.js +185 -98
  192. package/dist/validate.js +1 -1
  193. package/dist/web-fake.d.ts +25 -0
  194. package/dist/web-fake.js +38 -1
  195. package/dist/web-save.d.ts +75 -0
  196. package/dist/web-save.js +235 -0
  197. package/dist/workspace/archil-claim.d.ts +5 -2
  198. package/dist/workspace/archil-claim.js +5 -2
  199. package/dist/workspace/archil-disk.d.ts +11 -1
  200. package/dist/workspace/archil-disk.js +43 -10
  201. package/dist/workspace/archil.d.ts +3 -0
  202. package/dist/workspace/archil.js +102 -16
  203. package/dist/workspace/computer-for-claim.d.ts +14 -0
  204. package/dist/workspace/computer-for-claim.js +46 -7
  205. package/dist/workspace/computer-intervals.d.ts +9 -3
  206. package/dist/workspace/computer-intervals.js +17 -8
  207. package/dist/workspace/pieced.d.ts +14 -0
  208. package/dist/workspace/pieced.js +23 -0
  209. package/dist/workspace/run-disk.js +32 -12
  210. package/dist/workspace/run-workspace.d.ts +1 -1
  211. package/dist/workspace/run-workspace.js +11 -6
  212. package/package.json +10 -10
  213. package/skills/agentrun-serve/SKILL.md +52 -7
  214. package/templates/README.md +36 -7
  215. package/dist/console/assets/index-Bzn4eUYF.js +0 -715
  216. package/dist/console/assets/index-CR2ZGei1.css +0 -1
@@ -481,7 +481,10 @@ function synthesized(schema, definitions, depth, seen) {
481
481
  }
482
482
  /** What the DSL's synthesizeInstance would build of `schema` over `definitions`, counted without building it. */
483
483
  export const synthesizedSize = (schema, definitions = {}) => synthesized(schema, definitions, 0, new Map());
484
- const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
484
+ /** A JSON object (no array, no null). */
485
+ export const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
486
+ /** A workflow node: an object naming its `node` kind. */
487
+ export const isNode = (value) => isObject(value) && typeof value.node === "string";
485
488
  /** The nodes directly inside `node`, as the DSL reads them (recovery/execution-path.ts childrenOf): a chain's steps, a
486
489
  * parallel's branches, a map's or a loop's body, a route's branch bodies. A composed workflow node's child is a
487
490
  * workflow, walked as one (eachWorkflow). Only these are node positions: an object anywhere else (a schema, a const, a
@@ -492,7 +495,7 @@ export function childNodes(node) {
492
495
  case "parallel": return Array.isArray(node.branches) ? node.branches : [];
493
496
  case "map":
494
497
  case "loop": return [node.body];
495
- case "route": return isRecord(node.branches) ? Object.values(node.branches).map((branch) => (isRecord(branch) ? branch.body : undefined)) : [];
498
+ case "route": return isObject(node.branches) ? Object.values(node.branches).map((branch) => (isObject(branch) ? branch.body : undefined)) : [];
496
499
  default: return [];
497
500
  }
498
501
  }
@@ -500,7 +503,7 @@ export function childNodes(node) {
500
503
  * around it (their maxIters multiplied), and each node of it at a node position with the loops around that node. */
501
504
  function eachWorkflow(doc, visit) {
502
505
  const walkNode = (value, around) => {
503
- if (!isRecord(value))
506
+ if (!isObject(value))
504
507
  return;
505
508
  const within = visit.node ? visit.node(value, around) : around;
506
509
  if (value.node === "workflow")
@@ -509,7 +512,7 @@ function eachWorkflow(doc, visit) {
509
512
  walkNode(child, within);
510
513
  };
511
514
  const walkWorkflow = (value, around) => {
512
- if (!isRecord(value))
515
+ if (!isObject(value))
513
516
  return;
514
517
  visit.workflow?.(value);
515
518
  walkNode(value.root, around);
@@ -529,12 +532,12 @@ const SCHEMA_LISTS = ["anyOf", "oneOf", "allOf", "prefixItems"];
529
532
  const SCHEMA_ONES = ["items", "additionalItems", "additionalProperties", "contains", "not", "if", "then", "else", "propertyNames", "unevaluatedItems", "unevaluatedProperties"];
530
533
  /** Each schema in `schema`, itself first, at schema positions only (each once). */
531
534
  function eachSchema(schema, visit, seen = new Set()) {
532
- if (!isRecord(schema) || seen.has(schema))
535
+ if (!isObject(schema) || seen.has(schema))
533
536
  return;
534
537
  seen.add(schema);
535
538
  visit(schema);
536
539
  for (const key of SCHEMA_MAPS)
537
- if (isRecord(schema[key]))
540
+ if (isObject(schema[key]))
538
541
  for (const sub of Object.values(schema[key]))
539
542
  eachSchema(sub, visit, seen);
540
543
  for (const key of SCHEMA_LISTS)
@@ -643,7 +646,7 @@ function shapeOf(schema, depth = 0) {
643
646
  oneOf = shapeOf(value, depth + 1);
644
647
  else if (key === "type")
645
648
  out.type = Array.isArray(value) ? [...new Set(value.map((one) => (one === "integer" ? "number" : one)))] : value === "integer" ? "number" : value;
646
- else if (MAP_KEYWORDS.has(key) && isRecord(value))
649
+ else if (MAP_KEYWORDS.has(key) && isObject(value))
647
650
  out[key] = Object.fromEntries(Object.entries(value).map(([name, sub]) => [name, shapeOf(sub, depth + 1)]));
648
651
  else if (SUB_KEYWORDS.has(key))
649
652
  out[key] = shapeOf(value, depth + 1);
@@ -33,8 +33,8 @@ import { defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
33
33
  import { registerLabel, registerOutcome } from "./timeline/index.js";
34
34
  import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
35
35
  import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
36
- import { repickLabels } from "./learn/check.js";
37
- import { capState, REPICK_MARK, repickPageCaps } from "./learn/repick.js";
36
+ import { repickLabels, repickSiteOf } from "./learn/check.js";
37
+ import { capState, REPICK_MARK, repickMarked } from "./learn/repick.js";
38
38
  import { decisionsAsked, deniedDecisionWords } from "./learn/workflow-draft.js";
39
39
  import { DEFAULT_DECISION_PROVIDER } from "./decisions.js";
40
40
  import { workflowLine } from "./learning.js";
@@ -332,13 +332,13 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = [], n
332
332
  const doc = JSON.parse(flow.workflow);
333
333
  // Its quote re-pick loops (check.ts repickLabels): their exits are the run's re-picks (LoopRow `repick`).
334
334
  const repickAt = repickLabels(doc);
335
- // Each re-pick's pass over the run's pages (learning.repick, learn/repick.ts), by its label, with the most characters
336
- // of state it sends: its prompt state is cut to that (capState), its longest strings first; the workflow's state, which
337
- // the quote check after it reads, stays whole.
338
- const pageCaps = repickPageCaps(doc);
335
+ // The re-pick's pass over the run's pages (learning.repick, learn/repick.ts), by its label as the run gives it, with the
336
+ // most characters of state it sends: its prompt state is cut to that (capState), its longest strings first; the
337
+ // workflow's state, which the quote check after it reads, stays whole.
338
+ const pages = repickMarked(repickSiteOf(doc));
339
339
  // The marker's key is the host's: an input holding it would pick the re-pick's pass (or fail its route), whatever the
340
340
  // input's schema says of it, so such an input is refused before anything runs.
341
- if (pageCaps.size && Object.hasOwn(input, REPICK_MARK))
341
+ if (pages && Object.hasOwn(input, REPICK_MARK))
342
342
  return refuse(`its input holds "${REPICK_MARK}", the key its quote re-pick keeps its pass under`);
343
343
  // What a node answered the first time this call ran it, in every rerun of the call (`nested.memo`, by `key`): a rerun
344
344
  // after a park or a crash goes on from the same answers, so its MCP calls are asked with the arguments a person saw,
@@ -397,7 +397,7 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = [], n
397
397
  const model = !ref ? undefined : ref.provider === PORT_PROVIDER ? (run.modelName?.(tier) ?? undefined) : ref.modelId;
398
398
  if (model && typeof request.executionPath === "string")
399
399
  ranOn.set(request.executionPath, { model, ...(tier ? { tier } : {}) });
400
- const cap = pageCaps.get(request.label);
400
+ const cap = request.label === pages?.label ? pages.cap : undefined;
401
401
  const user = cap === undefined ? request.user : capState(request.user, cap);
402
402
  // A state past the cap with every string cut to nothing is never sent: the node fails and the re-pick hands back.
403
403
  if (user === undefined)
@@ -16,8 +16,8 @@
16
16
  // schema: its enum can be an echo of the owner's setting, not the decision, and a wrong field that promotes is worse than
17
17
  // none.
18
18
  // A compile reads two more (runner/learning-end.ts checkDraftOf, learn/repick.ts), off by default:
19
- // repick: the answer's quote re-pick (learn/check.ts quoteRule) reads the run's fetched pages on its second pass, as
20
- // H6c's re-pick tier did, where the compiled one reads its compact facts and its draft alone;
19
+ // repick: the answer's quote re-pick (learn/check.ts quoteRule) reads the run's fetched pages on its second pass,
20
+ // where the compiled one reads its compact facts and its draft alone;
21
21
  // repick_max_chars: the most characters of state that second pass sends, its longest strings cut first.
22
22
  // Each is read when a draft is committed, so a change reaches the workflows compiled after it, never one already kept.
23
23
  export const COMPILE_AFTER_DEFAULT = 20;
@@ -17,7 +17,7 @@ export declare const STOPPED: {
17
17
  readonly notCopied: "what the agent learned could not be handed to the run, so the run started without it";
18
18
  readonly noSeed: "the run started without what the agent learned";
19
19
  readonly cancelled: "the run was cancelled";
20
- readonly cancelledLooking: "the run was cancelled while it wrote what it learned";
20
+ readonly cancelledLooking: "a stop or cancel cut it while it wrote what it learned";
21
21
  readonly crashed: "the run's process ended before it could keep what it learned";
22
22
  readonly failed: "writing what it learned ended on an error";
23
23
  readonly unanswered: "the turn that writes its workflow ended before it answered";
@@ -55,7 +55,7 @@ export const STOPPED = {
55
55
  notCopied: "what the agent learned could not be handed to the run, so the run started without it",
56
56
  noSeed: "the run started without what the agent learned",
57
57
  cancelled: "the run was cancelled",
58
- cancelledLooking: "the run was cancelled while it wrote what it learned",
58
+ cancelledLooking: "a stop or cancel cut it while it wrote what it learned",
59
59
  crashed: "the run's process ended before it could keep what it learned",
60
60
  failed: "writing what it learned ended on an error",
61
61
  unanswered: "the turn that writes its workflow ended before it answered",
@@ -1,3 +1,4 @@
1
+ import { cliLearningOf } from "./store/agent-body.js";
1
2
  // A revision saved with no MCP pin (before pins were made at save, or an inline agent's version stored then) is pinned
2
3
  // once, at its first run, as a save would pin it: each granted server still saved here listed once
3
4
  // (McpServersOverStore.pinListing, the save's own listing), the pin made of those listings (mcp-gateway.ts mcpPinOf), and
@@ -22,7 +23,7 @@ import { GITHUB_UNUSABLE } from "./runner/mcp-github.js";
22
23
  export async function pinFirst(revision, deps) {
23
24
  // Native source MCP names and SDK callback tools belong to their source, never this server's managed registry.
24
25
  // Their runnable guards must refuse managed execution without listing or pinning those names first.
25
- if (nativeOf(revision.body) || sdkOf(revision.body))
26
+ if (nativeOf(revision.body) || sdkOf(revision.body) || cliLearningOf(revision.body))
26
27
  return undefined;
27
28
  if (revision.mcpPin !== undefined && revision.mcpPin !== null)
28
29
  return revision.mcpPin;
@@ -1,3 +1,4 @@
1
+ import net from "node:net";
1
2
  import type { Settings } from "./store/index.js";
2
3
  /** The store.settings key the list lives under: `{ hosts: string[] }`, each a URL's hostname as hostKey (mcp-meta.ts)
3
4
  * keeps it: lowercase, every final dot gone, an IPv6 literal in its URL form (`[fd00::1]`). */
@@ -6,19 +7,39 @@ export declare const MCP_PRIVATE_HOSTS_KEY = "mcp.private_oauth_hosts";
6
7
  export declare const MAX_PRIVATE_HOSTS = 32;
7
8
  /** Where an owner allows a host, as a refusal names it. */
8
9
  export declare const PRIVATE_HOSTS_PAGE = "Settings \u2192 MCP servers";
10
+ /** The operator's bound on the owner's private hosts, read from the environment of the process that dials. */
11
+ export declare const PRIVATE_HOSTS_ENV = "AGENTRUN_PRIVATE_HOSTS";
12
+ /** What the operator set: the owner's list as it is (`owner`, unset), no owner's list (`none`, also for a value that is
13
+ * neither: `invalid` names why), or the ranges a listed host must also resolve in. */
14
+ export type PrivateHostsBound = {
15
+ readonly mode: "owner";
16
+ } | {
17
+ readonly mode: "none";
18
+ readonly invalid?: string;
19
+ } | {
20
+ readonly mode: "ranges";
21
+ readonly ranges: readonly string[];
22
+ readonly list: net.BlockList;
23
+ };
24
+ /** The operator's bound as `env` sets it (PRIVATE_HOSTS_ENV). */
25
+ export declare function privateHostsBound(env?: NodeJS.ProcessEnv): PrivateHostsBound;
26
+ /** The bound as the capabilities' switches show it: unset (null), `none`, or the ranges; a value read as none says so. */
27
+ export declare const privateHostsSwitchValue: (env?: NodeJS.ProcessEnv) => string | null;
28
+ /** Why an owner's list cannot be saved under the operator's bound, or undefined when it can. */
29
+ export declare const ownerListRefused: (env?: NodeJS.ProcessEnv) => string | undefined;
9
30
  /** Whether `address` is in a range a listed host may resolve to (ALLOWABLE), and not a cloud metadata service's. */
10
31
  export declare const inAllowableRange: (address: string) => boolean;
11
32
  /** Every address on this machine's network interfaces: never an authorization server's, listed or not. */
12
33
  export declare function localAddresses(): string[];
13
34
  /** Whether a private address `address`, which a listed host resolves to, may be dialled: only in ALLOWABLE, and never one
14
35
  * of `own` (this machine's addresses, and this server's own; an IPv4-mapped form is the same address). */
15
- export declare function privateAllowed(address: string, own: readonly string[]): boolean;
36
+ export declare function privateAllowed(address: string, own: readonly string[], env?: NodeJS.ProcessEnv): boolean;
16
37
  /** The private-network hosts the owner allows an authorization server, or an MCP server itself (mcp-oauth.ts
17
38
  * mcpServerAt), on: read from the store at each use, so a host removed is refused from the next request on. The one read
18
39
  * of the setting, for the server's sign-in, preview, save and refresh and the runner's token refresh and calls alike. */
19
40
  export declare function privateOAuthHosts(store: {
20
41
  settings: Pick<Settings, "get">;
21
- }): Promise<string[]>;
42
+ }, env?: NodeJS.ProcessEnv): Promise<string[]>;
22
43
  /** The store.settings key a server keeps its own addresses under at each start (Serve.own: where it listens, and its
23
44
  * public address when that is on loopback): `{ own: string[] }`. Addresses alone, never its loopback opt-in, which each
24
45
  * process reads from its own environment: a runner in its own process with its own opt-in reads them so its runs never
@@ -38,7 +59,7 @@ export declare function savePrivateOAuthHosts(store: {
38
59
  }, hosts: readonly string[]): Promise<void>;
39
60
  /** A PUT body `{ hosts }` checked: the list as kept (each entry hostKey'd, the first of any repeat kept), or 422 with
40
61
  * every entry that is not a host name or an IP address on a private network, in words. */
41
- export declare function checkPrivateHosts(body: Record<string, unknown>): string[];
62
+ export declare function checkPrivateHosts(body: Record<string, unknown>, env?: NodeJS.ProcessEnv): string[];
42
63
  /** What the route reads and writes: the store-backed registry (mcp-servers-store.ts McpServersOverStore). */
43
64
  export type PrivateHostsRegistry = {
44
65
  privateHosts(): Promise<{
@@ -6,6 +6,13 @@
6
6
  // (RFC 1918, 100.64.0.0/10, fc00::/7), still only over https; loopback, link-local (cloud metadata among it, and the
7
7
  // metadata services inside those ranges), unspecified, multicast, broadcast, reserved and this machine's own addresses
8
8
  // stay refused whatever the list says.
9
+ //
10
+ // Above the owner, the operator (AGENTRUN_PRIVATE_HOSTS, read from each process's own environment at each use, so a
11
+ // server and each of its runners hold to their own): unset, the owner's list holds as above (a machine one owner uses);
12
+ // `none`, no owner's list is read and none can be saved, so nothing of an MCP server or a calendar reaches a private
13
+ // network (a runner many customers share, whose private network is the platform's own); or a comma list of ranges
14
+ // (`10.20.0.0/16,fd12:3456::/32`) a listed host's every address must also fall in. A value that is neither is read as
15
+ // `none` (fail closed), and the capabilities' switches show it.
9
16
  import net from "node:net";
10
17
  import os from "node:os";
11
18
  import { invalid } from "./errors.js";
@@ -26,6 +33,37 @@ for (const [base, bits] of [["10.0.0.0", 8], ["172.16.0.0", 12], ["192.168.0.0",
26
33
  ALLOWABLE.addSubnet(base, bits, "ipv4");
27
34
  ALLOWABLE.addSubnet("fc00::", 7, "ipv6");
28
35
  const familyOf = (address) => (net.isIPv6(address) ? "ipv6" : "ipv4");
36
+ /** The operator's bound on the owner's private hosts, read from the environment of the process that dials. */
37
+ export const PRIVATE_HOSTS_ENV = "AGENTRUN_PRIVATE_HOSTS";
38
+ /** The operator's bound as `env` sets it (PRIVATE_HOSTS_ENV). */
39
+ export function privateHostsBound(env = process.env) {
40
+ const raw = env[PRIVATE_HOSTS_ENV]?.trim();
41
+ if (!raw)
42
+ return { mode: "owner" };
43
+ if (raw === "none")
44
+ return { mode: "none" };
45
+ const list = new net.BlockList();
46
+ const ranges = [];
47
+ for (const entry of raw.split(",").map((one) => one.trim()).filter(Boolean)) {
48
+ const match = /^([^/]+)\/(\d{1,3})$/.exec(entry);
49
+ const family = match ? net.isIP(match[1]) : 0;
50
+ const bits = match ? Number(match[2]) : NaN;
51
+ if (!match || family === 0 || bits > (family === 4 ? 32 : 128))
52
+ return { mode: "none", invalid: `${PRIVATE_HOSTS_ENV}: ${entry} is not an address range such as 10.20.0.0/16 (or none); read as none` };
53
+ list.addSubnet(match[1], bits, family === 4 ? "ipv4" : "ipv6");
54
+ ranges.push(entry);
55
+ }
56
+ if (!ranges.length)
57
+ return { mode: "none", invalid: `${PRIVATE_HOSTS_ENV}=${raw} names no range; read as none` };
58
+ return { mode: "ranges", ranges, list };
59
+ }
60
+ /** The bound as the capabilities' switches show it: unset (null), `none`, or the ranges; a value read as none says so. */
61
+ export const privateHostsSwitchValue = (env = process.env) => {
62
+ const bound = privateHostsBound(env);
63
+ return bound.mode === "owner" ? null : bound.mode === "none" ? (bound.invalid ? `none (${bound.invalid})` : "none") : bound.ranges.join(",");
64
+ };
65
+ /** Why an owner's list cannot be saved under the operator's bound, or undefined when it can. */
66
+ export const ownerListRefused = (env = process.env) => privateHostsBound(env).mode === "none" ? `This server's operator allows no private-network host (${PRIVATE_HOSTS_ENV}=none): an MCP server or a calendar is reached on a public address alone.` : undefined;
29
67
  /** The cloud metadata services inside ALLOWABLE (AWS's over IPv6 in fc00::/7, Alibaba Cloud's in 100.64/10): never
30
68
  * allowable whatever the list says. The rest (169.254.169.254 among them) are link-local, outside it already. The same
31
69
  * addresses the computer's egress table refuses (packages/computer/src/docker/egress-table.ts). */
@@ -41,9 +79,14 @@ export function localAddresses() {
41
79
  }
42
80
  /** Whether a private address `address`, which a listed host resolves to, may be dialled: only in ALLOWABLE, and never one
43
81
  * of `own` (this machine's addresses, and this server's own; an IPv4-mapped form is the same address). */
44
- export function privateAllowed(address, own) {
82
+ export function privateAllowed(address, own, env = process.env) {
45
83
  if (!inAllowableRange(address))
46
84
  return false;
85
+ const bound = privateHostsBound(env);
86
+ if (bound.mode === "none")
87
+ return false;
88
+ if (bound.mode === "ranges" && !bound.list.check(address, familyOf(address)))
89
+ return false;
47
90
  const mine = new net.BlockList();
48
91
  for (const one of own)
49
92
  if (net.isIP(one))
@@ -59,7 +102,10 @@ function hostsOf(value) {
59
102
  /** The private-network hosts the owner allows an authorization server, or an MCP server itself (mcp-oauth.ts
60
103
  * mcpServerAt), on: read from the store at each use, so a host removed is refused from the next request on. The one read
61
104
  * of the setting, for the server's sign-in, preview, save and refresh and the runner's token refresh and calls alike. */
62
- export async function privateOAuthHosts(store) {
105
+ export async function privateOAuthHosts(store, env = process.env) {
106
+ // The operator's `none`: the owner's list is not read, so no host of it is allowed anywhere this process dials.
107
+ if (privateHostsBound(env).mode === "none")
108
+ return [];
63
109
  return hostsOf(await store.settings.get(MCP_PRIVATE_HOSTS_KEY));
64
110
  }
65
111
  /** The store.settings key a server keeps its own addresses under at each start (Serve.own: where it listens, and its
@@ -134,13 +180,17 @@ function entryOf(value, field) {
134
180
  }
135
181
  /** A PUT body `{ hosts }` checked: the list as kept (each entry hostKey'd, the first of any repeat kept), or 422 with
136
182
  * every entry that is not a host name or an IP address on a private network, in words. */
137
- export function checkPrivateHosts(body) {
183
+ export function checkPrivateHosts(body, env = process.env) {
138
184
  const issues = unknownFields(body, ["hosts"]);
139
185
  const { hosts } = body;
140
186
  if (!Array.isArray(hosts)) {
141
187
  issues.push({ field: "hosts", reason: hosts === undefined ? "missing" : "wrong_type", message: "hosts is a list of host names or IP addresses (an empty list allows none)." });
142
188
  throw invalid(issues);
143
189
  }
190
+ // Under the operator's `none` only the empty list is saved: an owner's host would never be allowed.
191
+ const refused = hosts.length ? ownerListRefused(env) : undefined;
192
+ if (refused)
193
+ throw invalid([{ field: "hosts", reason: "not_an_option", message: refused }]);
144
194
  if (hosts.length > MAX_PRIVATE_HOSTS)
145
195
  issues.push({ field: "hosts", reason: "too_long", message: `hosts holds at most ${MAX_PRIVATE_HOSTS} hosts; it holds ${hosts.length}.` });
146
196
  const kept = [];
@@ -13,6 +13,8 @@ export declare const GATEWAY_KEY_ROW = "model_gateway.api_key";
13
13
  * `bare`, the part after the provider (AGENT_MODEL_GATEWAY_IDS=bare). The tiers' own models go as saved either way. */
14
14
  export declare const GATEWAY_IDS: readonly ["as_named", "bare"];
15
15
  export type GatewayIds = (typeof GATEWAY_IDS)[number];
16
+ /** Whether a gateway is sent a model id whole or bare: read by the process that sends (a runner, for its runs). */
17
+ export declare const GATEWAY_IDS_ENV = "AGENT_MODEL_GATEWAY_IDS";
16
18
  /** How long the test waits for the gateway, and how many ids it lists. */
17
19
  export declare const TEST_TIMEOUT_MS = 10000;
18
20
  /** The most of the gateway's answer to the test that is read: a list of MAX_LISTED models is far smaller. */
@@ -53,7 +53,9 @@ export const GATEWAY_KEY_ROW = "model_gateway.api_key";
53
53
  export const GATEWAY_IDS = ["as_named", "bare"];
54
54
  /** The variable each tier's model fills, as the environment names it (model.ts TIER_ENV). */
55
55
  const TIER_VARS = { default: "AGENT_MODEL", fast: "AGENT_MODEL_FAST", strong: "AGENT_MODEL_STRONG" };
56
- const IDS_VAR = "AGENT_MODEL_GATEWAY_IDS";
56
+ /** Whether a gateway is sent a model id whole or bare: read by the process that sends (a runner, for its runs). */
57
+ export const GATEWAY_IDS_ENV = "AGENT_MODEL_GATEWAY_IDS";
58
+ const IDS_VAR = GATEWAY_IDS_ENV;
57
59
  const BASE_VAR = "AGENT_MODEL_BASE_URL";
58
60
  /** The longest key and model id taken: a header value, a name. */
59
61
  const MAX_KEY_CHARS = 4096;
@@ -12,6 +12,7 @@ export declare const NATIVE_RUNTIME_FACTS: Readonly<{
12
12
  readonly label: "Claude Code CLI";
13
13
  readonly minimumVersion: "2.1.322";
14
14
  readonly namedSelector: "agent";
15
+ readonly captureRuntime: "claude-code-cli";
15
16
  readonly protocol: "claude-json";
16
17
  readonly authStatus: readonly string[];
17
18
  readonly authStatusJson: true;
@@ -35,6 +36,7 @@ export declare const NATIVE_RUNTIME_FACTS: Readonly<{
35
36
  readonly label: "Codex CLI";
36
37
  readonly minimumVersion: "0.167.2";
37
38
  readonly namedSelector: "profile";
39
+ readonly captureRuntime: "codex-cli";
38
40
  readonly protocol: "codex-json";
39
41
  readonly authStatus: readonly string[];
40
42
  readonly authStatusJson: false;
@@ -1,6 +1,7 @@
1
1
  export const NATIVE_RUNTIME_FACTS = Object.freeze({
2
2
  "claude-code": Object.freeze({
3
3
  binary: "claude", label: "Claude Code CLI", minimumVersion: "2.1.322", namedSelector: "agent",
4
+ captureRuntime: "claude-code-cli",
4
5
  protocol: "claude-json", authStatus: Object.freeze(["auth", "status", "--json"]),
5
6
  authStatusJson: true, loginCommand: "claude auth login",
6
7
  observation: Object.freeze({
@@ -15,6 +16,7 @@ export const NATIVE_RUNTIME_FACTS = Object.freeze({
15
16
  }),
16
17
  codex: Object.freeze({
17
18
  binary: "codex", label: "Codex CLI", minimumVersion: "0.167.2", namedSelector: "profile",
19
+ captureRuntime: "codex-cli",
18
20
  protocol: "codex-json", authStatus: Object.freeze(["login", "status"]),
19
21
  authStatusJson: false, loginCommand: "codex login",
20
22
  observation: Object.freeze({
@@ -0,0 +1,32 @@
1
+ import { CliLearningConnections } from "../cli-learning/connections.js";
2
+ import { type CliLearningObservationScope, type CliLearningReadiness } from "../cli-learning/observation-proof.js";
3
+ import type { Store } from "../store/store.js";
4
+ export type LearningReport = {
5
+ readiness: CliLearningReadiness;
6
+ connection_id?: string;
7
+ native_session_hash?: string;
8
+ proof?: string;
9
+ };
10
+ /** Persist only verified identifiers and the generation that authorized them, never credentials or proofs. */
11
+ export type LearningAssociation = {
12
+ readiness: CliLearningReadiness;
13
+ connection_id?: string;
14
+ native_session_hash?: string;
15
+ generation?: string;
16
+ };
17
+ export type ObservedLearning = {
18
+ state: "on" | "off" | "setup_required" | "unknown" | "unsupported";
19
+ reason: "ready" | "source_setup_required" | "source_unknown" | "delegated_session" | "connection_unavailable" | "server_disabled" | "agent_disabled" | "awaiting_activation";
20
+ agent_id?: string;
21
+ connection_id?: string;
22
+ mode?: "off" | "notes" | "corrections" | "workflows";
23
+ };
24
+ export declare class ObservationLearning {
25
+ private readonly store;
26
+ private readonly connections;
27
+ private readonly enabled;
28
+ constructor(store: Store, connections: CliLearningConnections, enabled?: boolean);
29
+ verify(report: LearningReport, scope: Omit<CliLearningObservationScope, "connection_id" | "readiness" | "native_session_hash">): Promise<LearningAssociation>;
30
+ view(association: LearningAssociation | undefined, runtime: "codex" | "claude-code"): Promise<ObservedLearning>;
31
+ }
32
+ export declare function unboundLearning(readiness?: CliLearningReadiness): ObservedLearning;
@@ -0,0 +1,66 @@
1
+ import { createHash, timingSafeEqual } from "node:crypto";
2
+ import { getAgent } from "../agents-store.js";
3
+ import { cliLearningObservationProof } from "../cli-learning/observation-proof.js";
4
+ import { learnsOf } from "../learning-setting.js";
5
+ import { cliLearningOf, learningSettingForBody } from "../store/agent-body.js";
6
+ export class ObservationLearning {
7
+ store;
8
+ connections;
9
+ enabled;
10
+ constructor(store, connections, enabled = true) {
11
+ this.store = store;
12
+ this.connections = connections;
13
+ this.enabled = enabled;
14
+ }
15
+ async verify(report, scope) {
16
+ if (!report.connection_id)
17
+ return { readiness: report.readiness };
18
+ const row = await this.connections.get(report.connection_id).catch(() => undefined);
19
+ if (!row?.active || row.runtime !== scope.runtime || !report.proof || !report.native_session_hash)
20
+ return { readiness: "unknown" };
21
+ const expected = cliLearningObservationProof(this.connections.token(row), { ...scope, connection_id: row.connection_id, readiness: report.readiness, native_session_hash: report.native_session_hash });
22
+ if (!timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(report.proof, "hex")))
23
+ return { readiness: "unknown" };
24
+ return { readiness: report.readiness, connection_id: row.connection_id, generation: row.generation, native_session_hash: report.native_session_hash };
25
+ }
26
+ async view(association, runtime) {
27
+ const readiness = association?.readiness ?? "unknown";
28
+ if (!association?.connection_id)
29
+ return unboundLearning(readiness);
30
+ const row = await this.connections.get(association.connection_id).catch(() => undefined);
31
+ if (!row?.active || row.generation !== association.generation || row.runtime !== runtime)
32
+ return { state: "unknown", reason: "connection_unavailable" };
33
+ const entry = await getAgent(this.store, row.agent_id);
34
+ const binding = cliLearningOf(entry?.revision?.body);
35
+ if (!entry || entry.agent.archivedAt != null || !binding || binding.connection_id !== row.connection_id || binding.runtime !== runtime || binding.project !== row.project)
36
+ return { state: "unknown", reason: "connection_unavailable" };
37
+ // Source hooks deliver owner corrections; they do not expose a workflow execution bridge.
38
+ const mode = learnsOf(learningSettingForBody(entry.revision.body)) ? "corrections" : "off";
39
+ const linked = { agent_id: row.agent_id, connection_id: row.connection_id, mode };
40
+ if (!this.enabled)
41
+ return { state: "off", reason: "server_disabled", ...linked };
42
+ if (mode === "off")
43
+ return { state: "off", reason: "agent_disabled", ...linked };
44
+ if (readiness !== "ready")
45
+ return { ...unboundLearning(readiness), ...linked };
46
+ let activated = Boolean(association.native_session_hash && row.hook_sessions?.[association.native_session_hash]);
47
+ // Older connections already have a last-window receipt. It proves activation only for that exact
48
+ // native session and current credential generation; another session in the project proves nothing.
49
+ if (!activated && row.last_run_id) {
50
+ const launch = await this.store.runs.launch(row.last_run_id).catch(() => undefined);
51
+ const window = launch?.body?.cli_learning;
52
+ activated = Boolean(window && window.connection_id === row.connection_id && window.connection_generation === row.generation
53
+ && createHash("sha256").update(window.session_id).digest("hex") === association.native_session_hash);
54
+ }
55
+ if (!activated)
56
+ return { state: "unknown", reason: "awaiting_activation", ...linked };
57
+ return { state: "on", reason: "ready", ...linked };
58
+ }
59
+ }
60
+ export function unboundLearning(readiness = "unknown") {
61
+ if (readiness === "setup_required")
62
+ return { state: "setup_required", reason: "source_setup_required" };
63
+ if (readiness === "unsupported")
64
+ return { state: "unsupported", reason: "delegated_session" };
65
+ return { state: "unknown", reason: "source_unknown" };
66
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Store } from "../store/store.js";
2
2
  import { type NativeObservationHarness } from "../native/runtimes.js";
3
+ import { ObservationLearning } from "./learning.js";
3
4
  export declare const MAX_OTLP_PAYLOAD_BYTES = 1048576;
4
5
  type Harness = NativeObservationHarness;
5
6
  type Selection = {
@@ -17,6 +18,10 @@ export declare class ObservationError extends Error {
17
18
  }
18
19
  export declare const observationCapabilities: () => {
19
20
  version: number;
21
+ session_labels: boolean;
22
+ cli_learning: {
23
+ session_association: boolean;
24
+ };
20
25
  ingestion_modes: string[];
21
26
  supported_harnesses: ("codex" | "claude")[];
22
27
  logs_formats: string[];
@@ -25,6 +30,7 @@ export declare const observationCapabilities: () => {
25
30
  max_log_records: number;
26
31
  max_payload_bytes: number;
27
32
  token_usage: {
33
+ polling: boolean;
28
34
  supported_harnesses: ("codex" | "claude")[];
29
35
  model_attribute: string;
30
36
  count_attributes: string[];
@@ -40,7 +46,8 @@ export declare const observationCapabilities: () => {
40
46
  export declare class Observations {
41
47
  readonly store: Store;
42
48
  readonly now: () => number;
43
- constructor(store: Store, now?: () => number);
49
+ private readonly learning?;
50
+ constructor(store: Store, now?: () => number, learning?: ObservationLearning | undefined);
44
51
  private stamp;
45
52
  private rows;
46
53
  private row;