@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/NOTICE +2 -0
  3. package/README.md +149 -21
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/api-only.d.ts +3 -1
  7. package/dist/api-only.js +4 -2
  8. package/dist/api-token.d.ts +30 -0
  9. package/dist/api-token.js +89 -0
  10. package/dist/calendar/address.d.ts +49 -0
  11. package/dist/calendar/address.js +153 -0
  12. package/dist/calendar/fetch.d.ts +24 -0
  13. package/dist/calendar/fetch.js +146 -0
  14. package/dist/calendar/ics-faux.d.ts +39 -0
  15. package/dist/calendar/ics-faux.js +236 -0
  16. package/dist/calendar/labels.d.ts +3 -0
  17. package/dist/calendar/labels.js +61 -0
  18. package/dist/calendar/names.d.ts +52 -0
  19. package/dist/calendar/names.js +54 -0
  20. package/dist/calendar/parse.d.ts +108 -0
  21. package/dist/calendar/parse.js +625 -0
  22. package/dist/calendar/routes.d.ts +17 -0
  23. package/dist/calendar/routes.js +81 -0
  24. package/dist/calendar/tools.d.ts +23 -0
  25. package/dist/calendar/tools.js +124 -0
  26. package/dist/cli.js +22 -6
  27. package/dist/composio-made.d.ts +54 -0
  28. package/dist/composio-made.js +83 -0
  29. package/dist/composio-preset.d.ts +16 -8
  30. package/dist/composio-preset.js +106 -43
  31. package/dist/composio-triggers.d.ts +7 -2
  32. package/dist/composio-triggers.js +13 -7
  33. package/dist/computer-attach.d.ts +29 -11
  34. package/dist/computer-attach.js +141 -47
  35. package/dist/computer-keys.d.ts +4 -0
  36. package/dist/computer-keys.js +5 -0
  37. package/dist/computer-record.d.ts +55 -0
  38. package/dist/computer-record.js +315 -0
  39. package/dist/computer-setting.d.ts +1 -0
  40. package/dist/computer-setting.js +15 -2
  41. package/dist/computers.d.ts +11 -1
  42. package/dist/computers.js +23 -26
  43. package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
  44. package/dist/console/assets/index-DYJ_wj27.js +711 -0
  45. package/dist/console/index.html +2 -2
  46. package/dist/decisions.js +9 -2
  47. package/dist/eval-feed.d.ts +26 -0
  48. package/dist/eval-feed.js +72 -0
  49. package/dist/eval-mailbox.d.ts +4 -1
  50. package/dist/eval-mailbox.js +11 -3
  51. package/dist/exa-keyless.d.ts +1 -1
  52. package/dist/exa-keyless.js +1 -1
  53. package/dist/feed/feed-faux.d.ts +62 -0
  54. package/dist/feed/feed-faux.js +123 -0
  55. package/dist/feed/fetch.d.ts +41 -0
  56. package/dist/feed/fetch.js +128 -0
  57. package/dist/feed/parse.d.ts +42 -0
  58. package/dist/feed/parse.js +291 -0
  59. package/dist/feed/pointer.d.ts +2 -0
  60. package/dist/feed/pointer.js +17 -0
  61. package/dist/file-types.js +1 -0
  62. package/dist/host-command.d.ts +3 -0
  63. package/dist/host-command.js +18 -0
  64. package/dist/host.d.ts +3 -0
  65. package/dist/host.js +3 -0
  66. package/dist/learn/check.d.ts +17 -1
  67. package/dist/learn/check.js +240 -5
  68. package/dist/learn/compile.d.ts +48 -27
  69. package/dist/learn/compile.js +134 -101
  70. package/dist/learn/promote.d.ts +61 -5
  71. package/dist/learn/promote.js +12 -2
  72. package/dist/learned-nodes.d.ts +21 -4
  73. package/dist/learned-nodes.js +21 -8
  74. package/dist/learned-workflow.d.ts +3 -3
  75. package/dist/learned-workflow.js +14 -5
  76. package/dist/learning-setting.d.ts +23 -0
  77. package/dist/learning-setting.js +51 -0
  78. package/dist/learning-words.d.ts +3 -0
  79. package/dist/learning-words.js +3 -0
  80. package/dist/learning.d.ts +3 -2
  81. package/dist/learning.js +5 -3
  82. package/dist/mcp-oauth.d.ts +23 -1
  83. package/dist/mcp-oauth.js +46 -5
  84. package/dist/mcp-pin-first.d.ts +4 -2
  85. package/dist/mcp-pin-first.js +4 -3
  86. package/dist/mcp-private-hosts.d.ts +13 -0
  87. package/dist/mcp-private-hosts.js +16 -0
  88. package/dist/mcp-servers-store.d.ts +58 -5
  89. package/dist/mcp-servers-store.js +136 -17
  90. package/dist/mcp.d.ts +2 -2
  91. package/dist/mcp.js +2 -2
  92. package/dist/observation/http.d.ts +4 -1
  93. package/dist/observation/http.js +5 -4
  94. package/dist/openapi.d.ts +1 -0
  95. package/dist/openapi.js +151 -21
  96. package/dist/print.d.ts +6 -3
  97. package/dist/print.js +4 -2
  98. package/dist/run-files.d.ts +6 -2
  99. package/dist/run-files.js +29 -7
  100. package/dist/run-labels.d.ts +23 -0
  101. package/dist/run-labels.js +79 -0
  102. package/dist/run-learning-served.d.ts +1 -1
  103. package/dist/run-reads-over-store.d.ts +5 -1
  104. package/dist/run-reads-over-store.js +8 -4
  105. package/dist/run-recordings.d.ts +20 -0
  106. package/dist/run-recordings.js +133 -0
  107. package/dist/run-secrets.js +12 -4
  108. package/dist/runner/adapter-loop.d.ts +1 -1
  109. package/dist/runner/adapter-loop.js +94 -16
  110. package/dist/runner/adapter-run-spec.d.ts +19 -0
  111. package/dist/runner/adapter-run-spec.js +57 -36
  112. package/dist/runner/beside.d.ts +6 -3
  113. package/dist/runner/beside.js +9 -7
  114. package/dist/runner/cli-run-spec.js +41 -32
  115. package/dist/runner/conformance/harness.js +69 -14
  116. package/dist/runner/conformance/subject.d.ts +4 -1
  117. package/dist/runner/feedback-round.d.ts +9 -25
  118. package/dist/runner/feedback-round.js +22 -40
  119. package/dist/runner/learning-end.d.ts +17 -7
  120. package/dist/runner/learning-end.js +79 -53
  121. package/dist/runner/main.d.ts +12 -1
  122. package/dist/runner/main.js +31 -4
  123. package/dist/runner/mcp-claim.d.ts +3 -0
  124. package/dist/runner/mcp-claim.js +1 -1
  125. package/dist/runner/mcp-run.d.ts +6 -2
  126. package/dist/runner/mcp-run.js +5 -3
  127. package/dist/runner/model-route.d.ts +4 -2
  128. package/dist/runner/model-route.js +8 -8
  129. package/dist/runner/promotion.d.ts +44 -4
  130. package/dist/runner/promotion.js +323 -21
  131. package/dist/runner/reflect-hook.d.ts +5 -0
  132. package/dist/runner/reflect-hook.js +22 -14
  133. package/dist/runner/store-secrets.js +3 -1
  134. package/dist/runner/workflow-first.d.ts +6 -11
  135. package/dist/runner/workflow-first.js +16 -20
  136. package/dist/runs-over-store.d.ts +1 -1
  137. package/dist/runs-over-store.js +5 -2
  138. package/dist/sdk/runs.d.ts +7 -1
  139. package/dist/sdk/runs.js +21 -7
  140. package/dist/secret-cut.js +3 -1
  141. package/dist/secrets.js +5 -3
  142. package/dist/server.d.ts +31 -5
  143. package/dist/server.js +240 -61
  144. package/dist/store/agent-body.d.ts +5 -3
  145. package/dist/store/agent-body.js +14 -10
  146. package/dist/store/dialect.d.ts +3 -0
  147. package/dist/store/dialect.js +1 -0
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/postgres/dialect.js +1 -0
  150. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  151. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  152. package/dist/store/schema.d.ts +9 -0
  153. package/dist/store/schema.js +26 -2
  154. package/dist/store/sqlite/connection.js +11 -3
  155. package/dist/store/sqlite/run-patch.d.ts +2 -1
  156. package/dist/store/sqlite/run-patch.js +3 -2
  157. package/dist/store/sqlite/store.js +64 -10
  158. package/dist/store/store.d.ts +38 -1
  159. package/dist/store-reads/journal.js +2 -1
  160. package/dist/store-reads/learning.d.ts +1 -1
  161. package/dist/store-reads/learning.js +6 -1
  162. package/dist/store-reads/loop.d.ts +1 -0
  163. package/dist/store-reads/loop.js +14 -4
  164. package/dist/store-reads/runs.d.ts +4 -3
  165. package/dist/store-reads/runs.js +3 -2
  166. package/dist/store-view.d.ts +5 -0
  167. package/dist/store-view.js +8 -2
  168. package/dist/template-eval.d.ts +11 -0
  169. package/dist/template-eval.js +177 -52
  170. package/dist/templates.d.ts +13 -1
  171. package/dist/templates.js +89 -18
  172. package/dist/timeline/computer.js +2 -1
  173. package/dist/timeline/origin.d.ts +1 -1
  174. package/dist/timeline/origin.js +2 -2
  175. package/dist/tool-list.js +1 -0
  176. package/dist/tools.d.ts +7 -0
  177. package/dist/tools.js +11 -0
  178. package/dist/trigger-adapter.d.ts +9 -4
  179. package/dist/trigger-adapters.js +2 -1
  180. package/dist/trigger-feed.d.ts +12 -0
  181. package/dist/trigger-feed.js +420 -0
  182. package/dist/triggers.d.ts +2 -1
  183. package/dist/triggers.js +23 -5
  184. package/dist/validate.js +7 -2
  185. package/dist/webhooks.js +9 -5
  186. package/dist/workspace/computer-deps.d.ts +5 -1
  187. package/dist/workspace/computer-deps.js +2 -2
  188. package/dist/workspace/computer-for-claim.d.ts +7 -0
  189. package/dist/workspace/computer-for-claim.js +12 -2
  190. package/dist/workspace/index.d.ts +1 -0
  191. package/dist/workspace/index.js +2 -0
  192. package/dist/workspace/paths.d.ts +4 -0
  193. package/dist/workspace/paths.js +9 -0
  194. package/dist/workspace/resolve-computer.d.ts +35 -4
  195. package/dist/workspace/resolve-computer.js +47 -9
  196. package/launcher/agentrun-serve +34 -22
  197. package/package.json +11 -9
  198. package/templates/README.md +38 -4
  199. package/dist/console/assets/index-Jbxjcmdp.js +0 -705
@@ -2,7 +2,7 @@ import { type LearnedWorkflow } from "../learning.js";
2
2
  import type { RunLaunch } from "../run-launch.js";
3
3
  import { COST_WINDOW, type RunPath } from "../learning-cost.js";
4
4
  export { COST_WINDOW };
5
- import { type GuardRow } from "../learned-nodes.js";
5
+ import { type GuardRow, type LoopRow } from "../learned-nodes.js";
6
6
  import type { Skipped } from "../learn/replay-calls.js";
7
7
  /** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
8
8
  * revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
@@ -101,8 +101,8 @@ export interface FirstChoice {
101
101
  * is not promoted yet or was held (runner/promotion.ts): the text the run's learned_workflow tool runs (laidFor). */
102
102
  readonly champion?: LearnedWorkflow;
103
103
  }
104
- /** The learned workflows a run's tool runs once its first choice is made: the laid ones, a champion (FirstChoice) in
105
- * place of its laid revision. */
104
+ /** The laid learned workflows with a first choice's champion (FirstChoice) in place of its laid revision: what
105
+ * runner/promotion.ts toolFlowsFor reads the rest of from the promotion records, so the run's tool runs only what serves. */
106
106
  export declare const laidFor: (laid: readonly LearnedWorkflow[], choice: FirstChoice) => LearnedWorkflow[];
107
107
  /** What serves a run in place of its laid workflow: the workflow (the laid one itself, or its champion's text), and the
108
108
  * promotion it serves under (WorkflowFirst.promotion). */
@@ -159,18 +159,12 @@ export declare function servedOf(entries: readonly {
159
159
  digest?: string;
160
160
  promotion?: number;
161
161
  } | undefined;
162
- /** Why a run's learned workflow did not run first, from its root entries: the money rule's WORKFLOW_FIRST entry
163
- * (outcome needs_revision) with its two numbers; undefined when there is none. */
164
- export declare function reviseOf(entries: readonly {
165
- readonly kind: string;
166
- readonly data?: unknown;
167
- }[]): Revise | undefined;
168
162
  /** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
169
163
  * (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
170
164
  * called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
171
165
  * which its grade keeps); and from its root `entries`, each step guard's check of its learned workflows' calls
172
- * (`guards`, learned-nodes.ts guardsOf), when one ran. learning-cost reads path and workflow from here. None for a run
173
- * that does not learn. */
166
+ * (`guards`, learned-nodes.ts guardsOf) and each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second
167
+ * pass), when one ran. learning-cost reads path and workflow from here. None for a run that does not learn. */
174
168
  export declare function pathMetrics(launch: RunLaunch, classified: {
175
169
  path: RunPath;
176
170
  workflow: string | null;
@@ -186,6 +180,7 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
186
180
  workflow_digest?: string;
187
181
  workflow_promotion?: number;
188
182
  guards?: GuardRow[];
183
+ loops?: LoopRow[];
189
184
  replay?: ReplayMetrics;
190
185
  };
191
186
  /** A replay run's record (metrics.replay): the graded run it replayed and how its workflow ended there. */
@@ -8,15 +8,17 @@
8
8
  // and the run's input passes it at the top level (validate.ts inputIssues, the check a run's input gets at start). Whether
9
9
  // the workflow can do the job is its own guards' call, never the engine's. Exactly one fitting active workflow serves;
10
10
  // none, or more than one (said in one log line), leaves the run to the agent. A launch's `workflowFirst: false` (RunCreate
11
- // `workflow_first`) forces the agent path. A handback is an escalation, never a failure: it asks the end-of-run turn for
12
- // the workflow's next revision, and never keeps the workflow from serving. One money rule does (costLineOf): a workflow
11
+ // `workflow_first`) forces the agent path. A handback is an escalation, never a failure: it asks for no revision (one run
12
+ // is one sample; a revision is asked only of a workflow its promotion holds), and never keeps the workflow from serving.
13
+ // One money rule does (costLineOf): a workflow
13
14
  // serves while its all-in cost a run over its last COST_WINDOW served runs at its digest stays under the agent's by-hand
14
15
  // cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first). Both sides read one all-in
15
16
  // cost a run, the cost page's (store-reads/learning.ts allInOf): its booked cost (the workflow and any handback's agent
16
17
  // work together) and every learning round booked for it (its look-backs, its grades, a follow-up's rounds). A run whose
17
18
  // all-in is unknown anywhere is left out of its side's mean and counted, never read as 0. Over that line it stops running
18
- // first: the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome needs_revision), its end-of-run turn asks for a revision, and the
19
- // agent's cost per run shows it needing one. A new revision of it (a new digest) serves again from zero. Fewer than
19
+ // first: the agent takes the run, the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
20
+ // needs_revision), and the agent's cost per run shows it stopped. The stop asks for no compile. A new revision of it (a
21
+ // new digest: one its hold asked, or its owner's) serves again from zero. Fewer than
20
22
  // COST_WINDOW served runs, or no by-hand cost at all (said in the log): it serves. Every input is the run record's path
21
23
  // (metrics.path, one classifier: store-reads/learning.ts runPathOverStore). The rule catches a workflow that costs more
22
24
  // than doing the job by hand; it does not catch one that answers wrong with confidence. The spec builders
@@ -28,7 +30,7 @@ import { COST_WINDOW } from "../learning-cost.js";
28
30
  export { COST_WINDOW };
29
31
  import { KINDS } from "./journal-kinds.js";
30
32
  import { inputIssues, isObject } from "../validate.js";
31
- import { endedIn, guardsOf, replaySkippedIn } from "../learned-nodes.js";
33
+ import { endedIn, guardsOf, loopsOf, replaySkippedIn } from "../learned-nodes.js";
32
34
  import { sameAnswer } from "../learn/promote.js";
33
35
  /** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
34
36
  * revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
@@ -85,8 +87,8 @@ export function workflowCostsOf(past) {
85
87
  return { workflow, digest, state: overLine(line) ? "needs_revision" : "serving", served: line.served.runs ? line.served : null, by_hand: line.by_hand, unknown_cost_runs: line.unknown_runs };
86
88
  });
87
89
  }
88
- /** The learned workflows a run's tool runs once its first choice is made: the laid ones, a champion (FirstChoice) in
89
- * place of its laid revision. */
90
+ /** The laid learned workflows with a first choice's champion (FirstChoice) in place of its laid revision: what
91
+ * runner/promotion.ts toolFlowsFor reads the rest of from the promotion records, so the run's tool runs only what serves. */
90
92
  export const laidFor = (laid, choice) => choice.champion ? laid.map((one) => (one.name === choice.champion.name ? choice.champion : one)) : [...laid];
91
93
  /** A workflow's input schema, resolved as the DSL resolves a schema reference, or undefined when it names none. */
92
94
  function inputSchemaOf(text, resolve) {
@@ -205,7 +207,7 @@ export async function workflowFirstOf(kind, workflows, launch, log, past, promot
205
207
  return serve;
206
208
  const revise = { workflow: chosen.name, digest, served_usd: line.served.mean_usd, by_hand_usd: line.by_hand.mean_usd, runs: line.served.runs, revision: launch.learning.seed, ...(outputSchema !== undefined ? { outputSchema } : {}) };
207
209
  const unknown = line.unknown_runs ? ` (${line.unknown_runs} run${line.unknown_runs === 1 ? "" : "s"} of unknown cost left out)` : "";
208
- log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand, both all-in${unknown}; it does not run first until a new revision of it, and this run asks for one`);
210
+ log?.(`workflow-first: ${chosen.name} cost $${revise.served_usd} a run over its last ${revise.runs} served runs, at or over $${revise.by_hand_usd} by hand, both all-in${unknown}; it does not run first until a new revision of it; the agent takes this run`);
209
211
  return { ...champion, revise };
210
212
  }
211
213
  /** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
@@ -217,25 +219,19 @@ export function servedOf(entries) {
217
219
  return undefined;
218
220
  return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}) };
219
221
  }
220
- /** Why a run's learned workflow did not run first, from its root entries: the money rule's WORKFLOW_FIRST entry
221
- * (outcome needs_revision) with its two numbers; undefined when there is none. */
222
- export function reviseOf(entries) {
223
- const kept = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && entry.data?.outcome === "needs_revision")?.data;
224
- if (!kept || typeof kept.workflow !== "string" || typeof kept.digest !== "string" || typeof kept.served_usd !== "number" || typeof kept.by_hand_usd !== "number" || typeof kept.runs !== "number")
225
- return undefined;
226
- return { workflow: kept.workflow, digest: kept.digest, served_usd: kept.served_usd, by_hand_usd: kept.by_hand_usd, runs: kept.runs };
227
- }
228
222
  /** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
229
223
  * (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
230
224
  * called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
231
225
  * which its grade keeps); and from its root `entries`, each step guard's check of its learned workflows' calls
232
- * (`guards`, learned-nodes.ts guardsOf), when one ran. learning-cost reads path and workflow from here. None for a run
233
- * that does not learn. */
226
+ * (`guards`, learned-nodes.ts guardsOf) and each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second
227
+ * pass), when one ran. learning-cost reads path and workflow from here. None for a run that does not learn. */
234
228
  export function pathMetrics(launch, classified, entries = []) {
235
229
  if (!launch.learning)
236
230
  return {};
237
231
  const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
238
232
  const guards = guardsOf(entries);
233
+ const loops = loopsOf(entries);
234
+ const rows = { ...(guards.length ? { guards } : {}), ...(loops.length ? { loops } : {}) };
239
235
  if (launch.replay) {
240
236
  // A replay run (runner/promotion.ts): path `replay`, whatever its workflow did, so the money rule and the agent's
241
237
  // by-hand cost never read it; how its workflow ended, for the replay's score (learn/promote.ts ReplayRow).
@@ -246,9 +242,9 @@ export function pathMetrics(launch, classified, entries = []) {
246
242
  // evidence. Skipped when a write it needed is not in the graded run's recording (learn/replay-calls.ts): never run.
247
243
  const skipped = replaySkippedIn(entries);
248
244
  const outcome = skipped ? "skipped_write" : path === "workflow" && workflow === name ? "answered" : path === "handed_back" && workflow === name && endedIn(entries, name) === "escalated" ? "handed_back" : "failed";
249
- return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...(guards.length ? { guards } : {}), replay: { of, outcome, ...(skipped ? { skipped } : {}) } };
245
+ return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, replay: { of, outcome, ...(skipped ? { skipped } : {}) } };
250
246
  }
251
- return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(guards.length ? { guards } : {}) };
247
+ return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...rows };
252
248
  }
253
249
  /** What run `entries` (its root's) say its learned workflow answered alone: the workflow and its answer (the model's
254
250
  * message written just before the WORKFLOW_FIRST entry, in its commit); undefined for a run it did not answer. A follow-up that opens such a
@@ -94,7 +94,7 @@ type StartBody = {
94
94
  readonly maxCostUsd?: number;
95
95
  readonly place?: unknown;
96
96
  readonly tools?: readonly unknown[];
97
- readonly learning?: boolean | "notes";
97
+ readonly learning?: import("./learning-setting.js").LearningSetting;
98
98
  readonly thinking?: unknown;
99
99
  };
100
100
  /** The pieces a start needs that live in the server's request layer, not here: the leaf validators (the create body's field
@@ -17,6 +17,7 @@ import { CAP_TOLERANCE, money } from "./cap.js";
17
17
  import { holdOf } from "./computer-held.js";
18
18
  import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
19
19
  import { ApiError, invalid, unsupported } from "./errors.js";
20
+ import { labelsOf } from "./run-labels.js";
20
21
  import { harnessOfBody } from "./harness.js";
21
22
  import { redacted, redactedOutput } from "./key-refusal.js";
22
23
  import { chooseWorkflows, LEARNING_BUDGET, learnedParts, learnsOf, RUN_LEARNING_USE } from "./learning.js";
@@ -447,7 +448,8 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
447
448
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
448
449
  const runId = (deps.newRunId ?? uuidv7)();
449
450
  try {
450
- return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) }));
451
+ const labels = labelsOf(body.labels);
452
+ return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) }));
451
453
  }
452
454
  catch (error) {
453
455
  // Only another writer of the store got here first under the same origin key: its run is the one asked for.
@@ -508,11 +510,12 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
508
510
  // one across.
509
511
  const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision) });
510
512
  const runId = (deps.newRunId ?? uuidv7)();
513
+ const labels = labelsOf(body.labels);
511
514
  try {
512
515
  return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
513
516
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
514
517
  revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
515
- run: { id: runId, ...(origin ? { origin } : {}) },
518
+ run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
516
519
  launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) },
517
520
  }));
518
521
  }
@@ -61,12 +61,18 @@ export declare function sdkInbox(store: Pick<Store, "settings">, runId: string):
61
61
  /** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
62
62
  * remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed. */
63
63
  export declare function closeSdkInbox(store: Pick<Store, "settings">, claim: Claim, reason: NonNullable<SdkInbox["closed"]>): Promise<SdkInbox>;
64
+ /** The key a server signs its SDK runs' credentials with: derived from its seal key (seal-key.ts), which stays the
65
+ * store's for its life, so adding, reordering or removing an API token (api-token.ts) never changes a run's credential. */
66
+ export declare const sdkRunSecret: (sealKey: Buffer) => string;
64
67
  export declare class SdkRuns {
65
68
  private readonly store;
66
69
  private readonly data;
67
70
  private readonly secret;
68
71
  private readonly secrets;
69
- constructor(store: Store, data: string, secret: string, secrets?: () => readonly string[]);
72
+ private readonly earlier;
73
+ /** `earlier` are the keys credentials were once signed with (the server's API tokens, before `secret` was its seal
74
+ * key's): a credential any of them signed is still taken, so a run started before an upgrade keeps its credential. */
75
+ constructor(store: Store, data: string, secret: string, secrets?: () => readonly string[], earlier?: readonly string[]);
70
76
  token(runId: string): string;
71
77
  authenticate(runId: string, token: string): Promise<void>;
72
78
  private clean;
package/dist/sdk/runs.js CHANGED
@@ -1,12 +1,13 @@
1
1
  // Backend SDK calls remain in their application. This inbox only records their evidence and immutable completion;
2
2
  // the ordinary fenced runner owns journals, reflection, checking and learning commits.
3
- import { createHmac, timingSafeEqual } from "node:crypto";
3
+ import { createHash, createHmac, timingSafeEqual } from "node:crypto";
4
4
  import { inspectWorkflow } from "@parcha/agentrun-dsl";
5
5
  import { ApiError } from "../errors.js";
6
6
  import { canonical, isObject } from "../store/agent-body.js";
7
7
  import { uuidv7 } from "../agents-store.js";
8
8
  import { launchBody } from "../run-launch.js";
9
9
  import { learningStartFor } from "../runs-over-store.js";
10
+ import { learnsWorkflowsOf } from "../learning-setting.js";
10
11
  import { chooseWorkflows, chooseSkills, learningFolderOf, readerOf, seedFrom, secretsShown } from "../learning.js";
11
12
  import { NATIVE_GRADE_INSTRUCTION_BYTES } from "../learn/grade.js";
12
13
  import { secretRedactor } from "../runner/redact.js";
@@ -117,28 +118,41 @@ function checkToolParents(row, events) {
117
118
  }
118
119
  }
119
120
  }
121
+ /** The key a server signs its SDK runs' credentials with: derived from its seal key (seal-key.ts), which stays the
122
+ * store's for its life, so adding, reordering or removing an API token (api-token.ts) never changes a run's credential. */
123
+ export const sdkRunSecret = (sealKey) => createHmac("sha256", sealKey).update("agentrun sdk-run credentials").digest("base64url");
124
+ const sign = (secret, runId) => `ar_sdk_${createHmac("sha256", secret).update(`sdk-run\0${runId}`).digest("base64url")}`;
125
+ const digest = (text) => createHash("sha256").update(text).digest();
120
126
  export class SdkRuns {
121
127
  store;
122
128
  data;
123
129
  secret;
124
130
  secrets;
125
- constructor(store, data, secret, secrets = () => []) {
131
+ earlier;
132
+ /** `earlier` are the keys credentials were once signed with (the server's API tokens, before `secret` was its seal
133
+ * key's): a credential any of them signed is still taken, so a run started before an upgrade keeps its credential. */
134
+ constructor(store, data, secret, secrets = () => [], earlier = []) {
126
135
  this.store = store;
127
136
  this.data = data;
128
137
  this.secret = secret;
129
138
  this.secrets = secrets;
139
+ this.earlier = earlier;
130
140
  }
131
141
  token(runId) {
132
- return `ar_sdk_${createHmac("sha256", this.secret).update(`sdk-run\0${runId}`).digest("base64url")}`;
142
+ return sign(this.secret, runId);
133
143
  }
134
144
  async authenticate(runId, token) {
135
- const expected = Buffer.from(this.token(runId)), actual = Buffer.from(token);
136
- if (expected.length !== actual.length || !timingSafeEqual(expected, actual))
145
+ // Every key compared, on equal-length digests, with no early return.
146
+ const given = digest(token);
147
+ let ok = false;
148
+ for (const key of [this.secret, ...this.earlier])
149
+ ok = timingSafeEqual(given, digest(sign(key, runId))) || ok;
150
+ if (!ok)
137
151
  throw new ApiError("unauthenticated", "This credential is scoped to a different SDK run.");
138
152
  await sdkInbox(this.store, runId);
139
153
  }
140
154
  clean(body, runId) {
141
- const redact = secretRedactor([...this.secrets(), ...(runId ? [this.token(runId)] : [])]);
155
+ const redact = secretRedactor([...this.secrets(), ...(runId ? [this.secret, ...this.earlier].map((key) => sign(key, runId)) : [])]);
142
156
  // Redact values structurally: a long string or encoded credential can be withheld whole,
143
157
  // so treating serialized JSON as prose could remove its delimiters and corrupt the envelope.
144
158
  return redactedOutput(body, redact.heldValues?.() ?? []);
@@ -172,7 +186,7 @@ export class SdkRuns {
172
186
  const revisionBody = entry.revision.body;
173
187
  if (revisionBody.maxCostUsd !== undefined)
174
188
  throw new ApiError("agent_not_runnable", "AgentRun cannot enforce a spend cap on an external SDK. Configure the budget in the backend SDK and remove this managed run cap.");
175
- const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && revisionBody.learning === true ? { learning: "notes" } : {}) }, { content: cleanedInput });
189
+ const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && learnsWorkflowsOf(revisionBody.learning) ? { learning: "notes" } : {}) }, { content: cleanedInput });
176
190
  if (learning) {
177
191
  if (Buffer.byteLength(instructions) > NATIVE_GRADE_INSTRUCTION_BYTES)
178
192
  refuse("Original SDK instructions exceed the 64 KiB grading evidence limit. Keep learning off or provide a complete policy within that limit.");
@@ -7,6 +7,7 @@ import { rules as recommended } from "@secretlint/secretlint-rule-preset-recomme
7
7
  // No performance marks: the profiler would leave about 14 a call in the process's global buffer.
8
8
  secretLintProfiler.setEnabled(false);
9
9
  import { keyShaped } from "./secret-name.js";
10
+ import { secretValues } from "./api-token.js";
10
11
  /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
11
12
  * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
12
13
  * The one rule: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
@@ -22,7 +23,8 @@ export function secretCut(envs, names = []) {
22
23
  const secrets = (Array.isArray(envs) ? envs : [envs])
23
24
  .flatMap((env) => Object.getOwnPropertyNames(env).map((name) => [name, env[name]]))
24
25
  .filter(([name, value]) => (keyShaped(name) || names.includes(name)) && typeof value === "string" && value.length >= 8)
25
- .map(([, value]) => value)
26
+ // AGENTRUN_TOKENS's each secret too, not only the list whole (api-token.ts secretValues).
27
+ .flatMap(([name, value]) => secretValues(name, value).filter((part) => part.length >= 8))
26
28
  // The longest first: a key that holds a shorter one is cut whole.
27
29
  .sort((a, b) => b.length - a.length);
28
30
  // `text.removed` counts the values it cut, each once however often it was met; `text.probe` cuts the same and counts
package/dist/secrets.js CHANGED
@@ -11,6 +11,7 @@ import { closeSync, existsSync, readFileSync, readSync } from "node:fs";
11
11
  import { homedir } from "node:os";
12
12
  import { keyShaped } from "./secret-cut.js";
13
13
  import { MIN_SECRET } from "./learn/secrets.js";
14
+ import { secretValues } from "./api-token.js";
14
15
  /** The pipe and how many bytes of it are the secrets: the launcher's, or serve's to a run's process. */
15
16
  export const SECRETS_FD_ENV = "AGENTRUN_SECRETS_FD";
16
17
  export const SECRETS_LEN_ENV = "AGENTRUN_SECRETS_LEN";
@@ -49,8 +50,8 @@ function decode(bytes) {
49
50
  signIn = pair.slice(at + 1);
50
51
  }
51
52
  }
52
- /** Exactly `length` bytes of `fd`: the writer keeps its end open (the launcher's FIFO is open read-write), so there is
53
- * no end of file to wait for. */
53
+ /** Exactly `length` bytes of `fd`, read as the launcher's writer writes them: the end of file before then is a writer
54
+ * gone short, and refused. */
54
55
  function readExactly(fd, length) {
55
56
  const bytes = Buffer.alloc(length);
56
57
  for (let read = 0; read < length;) {
@@ -94,7 +95,8 @@ const SECRET_NAME = /(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD)$/i;
94
95
  * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
95
96
  * whitespace aside, matches too much text by chance to be refused, and is left out. */
96
97
  export const hostSecrets = (env, stored) => {
97
- const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials()), ...sealKeys.keys(), ...heldTokens];
98
+ // AGENTRUN_TOKENS's each secret too, not only the list whole (api-token.ts secretValues).
99
+ const held = [...SECRET_NAMES.flatMap((name) => [...secretValues(name, secret(name) ?? ""), stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials()), ...sealKeys.keys(), ...heldTokens];
98
100
  const named = Object.entries(env).filter(([name]) => SECRET_NAME.test(name) && !SECRET_NAMES.includes(name)).map(([, value]) => value ?? "");
99
101
  return [...new Set([...held, ...named])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
100
102
  };
package/dist/server.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { type ModelNeeds } from "./model.js";
2
2
  import { type HarnessCapability } from "./harness.js";
3
3
  import { type HarnessInstaller } from "./harness-install.js";
4
+ import { DEFAULT_PORT } from "./host.js";
4
5
  import { type LearningMode } from "./learning.js";
5
6
  import { type Place } from "./place.js";
7
+ import { type ApiToken } from "./api-token.js";
6
8
  import { type Store } from "./store/index.js";
7
9
  import { type BoxOffer } from "./place-offers.js";
8
10
  import { type StoredKeys } from "./secrets.js";
@@ -10,9 +12,9 @@ import { type ComposioControl } from "./composio-preset.js";
10
12
  import type { TriggerAdapter } from "./trigger-adapter.js";
11
13
  import { type TriggerClock } from "./triggers.js";
12
14
  import { type ToolSettingsMap } from "./tool-plane.js";
13
- import { AttachHub } from "@parcha/agentrun-computer";
15
+ import { AttachHub, type HostedDial } from "@parcha/agentrun-computer";
14
16
  export declare const CONTRACT = "agentrun.v2/0";
15
- export declare const DEFAULT_PORT = 7340;
17
+ export { DEFAULT_PORT };
16
18
  export type ServeOptions = {
17
19
  /** The data directory: the agent store (`store.sqlite`) and its runs (`runs/<id>/`). */
18
20
  data: string;
@@ -54,8 +56,13 @@ export type ServeOptions = {
54
56
  /** The address to listen on (default 127.0.0.1). On any other address every `Host` name is served and the token is
55
57
  * the only lock: put TLS in front of it. */
56
58
  host?: string;
57
- /** The token to require in place of the one `DIR/.token` keeps: 32 characters or more, no whitespace. */
59
+ /** The token to require in place of the one `DIR/.token` keeps: 32 characters or more, no whitespace. Its id is
60
+ * `default` (api-token.ts). */
58
61
  token?: string;
62
+ /** More API tokens (AGENTRUN_TOKENS, api-token.ts parseTokens), each with an id: every one opens every route the
63
+ * token opens. Given these and no `token`, `DIR/.token` is neither read nor made, and the first is the server's
64
+ * token. Each id names its token in the request log; no line holds a secret. */
65
+ tokens?: readonly ApiToken[];
59
66
  /** Default 7340; 0 is any free port. */
60
67
  port?: number;
61
68
  /** When the port is taken at the listen, the next one that is not, of the 100 from it: the port is found by listening,
@@ -165,6 +172,10 @@ export type ServeOptions = {
165
172
  learningBudget?: number;
166
173
  /** A test's seam: the triggers' clock and timer (triggers.ts), in place of Date.now and setTimeout. */
167
174
  triggerClock?: TriggerClock;
175
+ /** A test's and a template eval's seam: the URL a feed trigger's read of `url` goes to in its place (a fake feed on
176
+ * loopback, feed/feed-faux.ts); null when it serves no feed at `url` (read as unreachable, nothing sent); undefined
177
+ * to read it as it is. The trigger, its payload and its words keep `url`. */
178
+ feedsAt?: (url: string) => string | null | undefined;
168
179
  /** The server's store (store/index.ts), where the triggers and their firings live, with the agents they run as. Without
169
180
  * it the trigger routes answer unavailable and nothing fires. */
170
181
  store?: Pick<Store, "triggers" | "runs" | "agents"> & Partial<Pick<Store, "liveViewers">>;
@@ -191,6 +202,10 @@ export type ServeOptions = {
191
202
  /** Whether the outbound webhook may send to a private network or this machine: off by default, so no caller of the API
192
203
  * can make the server POST inside its own network. The operator's AGENTRUN_WEBHOOK_PRIVATE_TARGETS=1 turns it on. */
193
204
  webhookPrivateTargets?: boolean;
205
+ /** A test's seam: the addresses the outbound webhook's receiver's name resolves to, at a save's check and at each try
206
+ * (webhooks.ts), in place of the system resolver's. A test's server answers its example hosts here, so no CI
207
+ * runner's resolver decides what a test sees. */
208
+ webhookLookup?: (host: string) => Promise<string[]>;
194
209
  };
195
210
  /** The test switches a run's process gets, each module path resolved: empty outside tests. A test's in-process runner
196
211
  * takes the same (test/support.mjs startInProcessRunner). */
@@ -201,11 +216,14 @@ export declare function fauxEnvOf(options: ServeOptions): NodeJS.ProcessEnv;
201
216
  /** `boxesLine`: what the start's banner says of the boxes, in words (place.ts boxesLine). */
202
217
  /** `launchCode`: with no accounts, the code of the console's link this start prints (`/?launch=<code>`), which gives the
203
218
  * browser that opens it a console session (page.ts ConsoleSessions). */
219
+ /** `token` is the first of `tokenIds` (the console's session stands for it); `tokenIds` are the ids of every token the
220
+ * server takes, in order (api-token.ts), never their secrets. */
204
221
  export type Serve = {
205
222
  url: string;
206
223
  baseUrl: string;
207
224
  port: number;
208
225
  token: string;
226
+ tokenIds: readonly string[];
209
227
  tokenFile: string | null;
210
228
  tokenMade: boolean;
211
229
  setupUrl?: string;
@@ -216,10 +234,19 @@ export type Serve = {
216
234
  /** The live sockets of the computers paired with this server (computer-attach.ts): a runner beside the server in this
217
235
  * process takes it (runner/beside.ts), so its runs can use them. */
218
236
  attachHub: AttachHub;
237
+ /** What a dial provider's create takes of this server (HostedProvider's dial): the address its machines dial
238
+ * (AGENTRUN_PUBLIC_URL, absent without one), the tokens it mints for them (computer-attach.ts machineTokens) and the
239
+ * hub their sockets land in. The runner beside the server hands it to its remote providers (runner/beside.ts). */
240
+ dial: HostedDial;
219
241
  /** Whether this server is a local install (listening on loopback, reached at no address off it): the one kind whose own
220
242
  * runner beside it may reach an MCP server's URL on loopback (runner/beside.ts mcpLoopback). Only that runner is told:
221
- * it is this process's finding, never a store's, so another host's runner on a shared store never inherits it. */
243
+ * it is this process's finding, never a store's, so another runner on a shared store never inherits it. A runner in
244
+ * its own process takes its own operator's opt-in from its own environment (runner/main.ts runnerLoopback). */
222
245
  localInstall: boolean;
246
+ /** This server's own addresses (McpServersOverStore.own): where it listens, and its public address when that is on
247
+ * loopback. The runner beside it is told them with localInstall (runner/beside.ts mcpOwn), so its runs' loopback reads
248
+ * never reach this server, as its own reads never do. */
249
+ own: readonly string[];
223
250
  /** What a stop waits on: the runs whose processes still finish their turn, and the longest it waits on them. */
224
251
  stopping(): {
225
252
  runs: number;
@@ -882,4 +909,3 @@ export declare function forCaller<T extends {
882
909
  learning: LearningCaps;
883
910
  }>(caps: T, ownerSession: boolean): T;
884
911
  export declare function startServe(options: ServeOptions): Promise<Serve>;
885
- export {};