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

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 (261) hide show
  1. package/CHANGELOG.md +122 -1
  2. package/README.md +213 -24
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agents-store.d.ts +26 -20
  8. package/dist/agents-store.js +41 -33
  9. package/dist/api-only.d.ts +26 -6
  10. package/dist/api-only.js +35 -13
  11. package/dist/claude-login.d.ts +1 -0
  12. package/dist/claude-login.js +1 -1
  13. package/dist/cli-learning/cli.d.ts +3 -0
  14. package/dist/cli-learning/cli.js +17 -3
  15. package/dist/cli-learning/connections.js +3 -2
  16. package/dist/cli-learning/schema.js +2 -1
  17. package/dist/cli.js +70 -7
  18. package/dist/composio-preset.d.ts +2 -1
  19. package/dist/composio-preset.js +4 -3
  20. package/dist/composio-triggers.d.ts +4 -0
  21. package/dist/composio-triggers.js +4 -1
  22. package/dist/computer-needs.d.ts +32 -0
  23. package/dist/computer-needs.js +80 -0
  24. package/dist/computer-setting.d.ts +1 -0
  25. package/dist/computer-setting.js +8 -1
  26. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  27. package/dist/console/assets/index-DbilxljH.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/console-links.d.ts +1 -0
  30. package/dist/console-links.js +2 -0
  31. package/dist/env-switch.d.ts +14 -0
  32. package/dist/env-switch.js +23 -0
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +3 -0
  35. package/dist/eval-previous.js +4 -3
  36. package/dist/fal-price.js +10 -13
  37. package/dist/handed-secret.d.ts +4 -0
  38. package/dist/handed-secret.js +10 -0
  39. package/dist/harness-archive.d.ts +15 -5
  40. package/dist/harness-archive.js +71 -34
  41. package/dist/harness-check.d.ts +2 -1
  42. package/dist/harness-check.js +36 -95
  43. package/dist/harness-egress.d.ts +23 -0
  44. package/dist/harness-egress.js +69 -0
  45. package/dist/harness-recipe-entry.d.ts +71 -0
  46. package/dist/harness-recipe-entry.js +184 -0
  47. package/dist/harness-recipe.d.ts +73 -6
  48. package/dist/harness-recipe.js +185 -31
  49. package/dist/harness-sign-in.d.ts +29 -0
  50. package/dist/harness-sign-in.js +122 -0
  51. package/dist/harness-table.d.ts +21 -0
  52. package/dist/harness-table.js +58 -3
  53. package/dist/harness-zip.d.ts +6 -0
  54. package/dist/harness-zip.js +203 -0
  55. package/dist/ids.d.ts +11 -0
  56. package/dist/ids.js +36 -0
  57. package/dist/learn/commit.d.ts +14 -1
  58. package/dist/learn/commit.js +156 -1
  59. package/dist/learn/compile.js +22 -8
  60. package/dist/learn/folder.d.ts +5 -0
  61. package/dist/learn/folder.js +10 -1
  62. package/dist/learn/learning.sh +15 -3
  63. package/dist/learn/promote.d.ts +2 -2
  64. package/dist/learn/secrets.js +30 -7
  65. package/dist/learning-routes.d.ts +23 -11
  66. package/dist/learning-routes.js +110 -20
  67. package/dist/learning.d.ts +9 -6
  68. package/dist/learning.js +9 -4
  69. package/dist/mcp-gateway.js +15 -2
  70. package/dist/mcp-probe.d.ts +3 -0
  71. package/dist/mcp-probe.js +7 -2
  72. package/dist/mcp-resources.d.ts +44 -0
  73. package/dist/mcp-resources.js +100 -0
  74. package/dist/mcp-servers-store.d.ts +16 -12
  75. package/dist/model.d.ts +4 -4
  76. package/dist/model.js +6 -6
  77. package/dist/native/cli.js +9 -2
  78. package/dist/native/connection.d.ts +2 -2
  79. package/dist/native/connection.js +5 -2
  80. package/dist/native/discovery.d.ts +2 -0
  81. package/dist/native/discovery.js +10 -6
  82. package/dist/native/remote-worker-bridge.js +36 -4
  83. package/dist/native/remote.d.ts +18 -1
  84. package/dist/native/remote.js +126 -37
  85. package/dist/native/schema.d.ts +6 -0
  86. package/dist/native/schema.js +31 -6
  87. package/dist/native/source-account.d.ts +13 -0
  88. package/dist/native/source-account.js +114 -0
  89. package/dist/native/source-capture-hooks.d.ts +5 -0
  90. package/dist/native/source-capture-hooks.js +102 -0
  91. package/dist/native/source-mcp-selection.d.ts +13 -0
  92. package/dist/native/source-mcp-selection.js +72 -0
  93. package/dist/native/source-runtime-tools.d.ts +19 -0
  94. package/dist/native/source-runtime-tools.js +103 -0
  95. package/dist/native/source-snapshot-types.d.ts +138 -0
  96. package/dist/native/source-snapshot-types.js +12 -0
  97. package/dist/native/source-snapshot.d.ts +8 -0
  98. package/dist/native/source-snapshot.js +1201 -0
  99. package/dist/observation/learning.js +3 -2
  100. package/dist/openapi.js +167 -36
  101. package/dist/print.js +1 -1
  102. package/dist/purged-workflow.d.ts +12 -0
  103. package/dist/purged-workflow.js +43 -0
  104. package/dist/run-keys.d.ts +46 -0
  105. package/dist/run-keys.js +109 -0
  106. package/dist/run-launch.d.ts +16 -1
  107. package/dist/run-launch.js +30 -1
  108. package/dist/run-learning-served.d.ts +2 -2
  109. package/dist/run-model-key.d.ts +2 -2
  110. package/dist/run-model-key.js +5 -5
  111. package/dist/run-secrets.d.ts +2 -0
  112. package/dist/run-secrets.js +7 -4
  113. package/dist/run-view.d.ts +17 -0
  114. package/dist/run-view.js +25 -1
  115. package/dist/runner/adapter-loop.d.ts +11 -3
  116. package/dist/runner/adapter-loop.js +138 -22
  117. package/dist/runner/adapter-run-spec.js +25 -12
  118. package/dist/runner/audit.d.ts +2 -0
  119. package/dist/runner/audit.js +9 -1
  120. package/dist/runner/beside.js +2 -1
  121. package/dist/runner/claim-secrets.d.ts +29 -3
  122. package/dist/runner/claim-secrets.js +38 -4
  123. package/dist/runner/cli-run-spec.js +23 -12
  124. package/dist/runner/harness-loops.d.ts +6 -0
  125. package/dist/runner/harness-loops.js +11 -1
  126. package/dist/runner/held.d.ts +4 -0
  127. package/dist/runner/journal-kinds.d.ts +2 -0
  128. package/dist/runner/learned-first.d.ts +2 -0
  129. package/dist/runner/learned-first.js +1 -1
  130. package/dist/runner/learning-end.d.ts +7 -2
  131. package/dist/runner/learning-end.js +22 -10
  132. package/dist/runner/learning-seed.d.ts +9 -3
  133. package/dist/runner/learning-seed.js +2 -2
  134. package/dist/runner/main.d.ts +1 -0
  135. package/dist/runner/main.js +20 -13
  136. package/dist/runner/mcp-claim.js +6 -1
  137. package/dist/runner/mcp-run.d.ts +10 -7
  138. package/dist/runner/mcp-run.js +3 -5
  139. package/dist/runner/monid-run.js +9 -11
  140. package/dist/runner/project-checkpoint.d.ts +35 -0
  141. package/dist/runner/project-checkpoint.js +116 -0
  142. package/dist/runner/project-drain.d.ts +8 -0
  143. package/dist/runner/project-drain.js +25 -0
  144. package/dist/runner/project-host.d.ts +10 -0
  145. package/dist/runner/project-host.js +52 -0
  146. package/dist/runner/promotion.d.ts +14 -6
  147. package/dist/runner/promotion.js +98 -41
  148. package/dist/runner/redact.d.ts +13 -0
  149. package/dist/runner/redact.js +67 -1
  150. package/dist/runner/run-channel.d.ts +9 -0
  151. package/dist/runner/run-channel.js +15 -2
  152. package/dist/runner/run-child-host.d.ts +8 -4
  153. package/dist/runner/run-child-host.js +171 -41
  154. package/dist/runner/run-errors.js +2 -2
  155. package/dist/runner/runner-check.js +5 -2
  156. package/dist/runner/runner.js +26 -9
  157. package/dist/runner/store-secrets.js +7 -3
  158. package/dist/runner/workflow-first.d.ts +4 -0
  159. package/dist/runner/workflow-first.js +13 -0
  160. package/dist/runner/workflow-loop.d.ts +2 -1
  161. package/dist/runner/workflow-loop.js +2 -1
  162. package/dist/runner/workflow-spec.js +1 -1
  163. package/dist/runs-over-store.d.ts +34 -6
  164. package/dist/runs-over-store.js +133 -25
  165. package/dist/sdk/runs.d.ts +11 -1
  166. package/dist/sdk/runs.js +117 -26
  167. package/dist/sdk/schema.js +12 -2
  168. package/dist/sdk/workflows.d.ts +1 -1
  169. package/dist/server.d.ts +68 -32
  170. package/dist/server.js +600 -110
  171. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  172. package/dist/source-sync/adoption.d.ts +15 -0
  173. package/dist/source-sync/adoption.js +36 -0
  174. package/dist/source-sync/auxiliary.d.ts +23 -0
  175. package/dist/source-sync/auxiliary.js +64 -0
  176. package/dist/source-sync/capture-git.d.ts +5 -0
  177. package/dist/source-sync/capture-git.js +272 -0
  178. package/dist/source-sync/capture-project.d.ts +53 -0
  179. package/dist/source-sync/capture-project.js +206 -0
  180. package/dist/source-sync/capture-refusal.d.ts +7 -0
  181. package/dist/source-sync/capture-refusal.js +16 -0
  182. package/dist/source-sync/capture.d.ts +11 -0
  183. package/dist/source-sync/capture.js +22 -0
  184. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  185. package/dist/source-sync/checkpoint-gate.js +52 -0
  186. package/dist/source-sync/checkpoints.d.ts +66 -0
  187. package/dist/source-sync/checkpoints.js +168 -0
  188. package/dist/source-sync/claim.d.ts +11 -0
  189. package/dist/source-sync/claim.js +48 -0
  190. package/dist/source-sync/destination.d.ts +47 -0
  191. package/dist/source-sync/destination.js +239 -0
  192. package/dist/source-sync/io.d.ts +15 -0
  193. package/dist/source-sync/io.js +52 -0
  194. package/dist/source-sync/local.d.ts +43 -0
  195. package/dist/source-sync/local.js +229 -0
  196. package/dist/source-sync/prepare.d.ts +59 -0
  197. package/dist/source-sync/prepare.js +93 -0
  198. package/dist/source-sync/projects.d.ts +61 -0
  199. package/dist/source-sync/projects.js +130 -0
  200. package/dist/source-sync/registry.d.ts +95 -0
  201. package/dist/source-sync/registry.js +226 -0
  202. package/dist/source-sync/service.d.ts +33 -0
  203. package/dist/source-sync/service.js +118 -0
  204. package/dist/source-sync/skill-edits.d.ts +12 -0
  205. package/dist/source-sync/skill-edits.js +122 -0
  206. package/dist/source-sync/snapshots.d.ts +48 -0
  207. package/dist/source-sync/snapshots.js +448 -0
  208. package/dist/source-sync/types.d.ts +9 -0
  209. package/dist/source-sync/types.js +14 -0
  210. package/dist/source-sync/workspace.d.ts +66 -0
  211. package/dist/source-sync/workspace.js +273 -0
  212. package/dist/store/agent-body.d.ts +4 -0
  213. package/dist/store/agent-body.js +16 -5
  214. package/dist/store/index.d.ts +2 -2
  215. package/dist/store/index.js +1 -1
  216. package/dist/store/schema.d.ts +2 -1
  217. package/dist/store/schema.js +2 -1
  218. package/dist/store/seal.d.ts +5 -1
  219. package/dist/store/seal.js +12 -3
  220. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  221. package/dist/store/sqlite/project-checkpoints.js +70 -0
  222. package/dist/store/sqlite/run-launch.d.ts +4 -12
  223. package/dist/store/sqlite/run-launch.js +5 -19
  224. package/dist/store/sqlite/store.js +224 -170
  225. package/dist/store/store.d.ts +116 -39
  226. package/dist/store/store.js +14 -1
  227. package/dist/store-reads/learning.d.ts +2 -2
  228. package/dist/store-view.d.ts +3 -1
  229. package/dist/store-view.js +17 -5
  230. package/dist/template-import.d.ts +10 -2
  231. package/dist/template-import.js +116 -13
  232. package/dist/templates.d.ts +26 -5
  233. package/dist/templates.js +62 -10
  234. package/dist/timeline/index.d.ts +1 -1
  235. package/dist/timeline/index.js +1 -1
  236. package/dist/timeline/timeline.d.ts +5 -0
  237. package/dist/timeline/timeline.js +8 -0
  238. package/dist/tool-plane.d.ts +12 -12
  239. package/dist/tools.d.ts +8 -8
  240. package/dist/trigger-launch-hook.d.ts +47 -0
  241. package/dist/trigger-launch-hook.js +90 -0
  242. package/dist/trigger-targets.d.ts +14 -1
  243. package/dist/trigger-targets.js +20 -0
  244. package/dist/triggers.d.ts +54 -5
  245. package/dist/triggers.js +143 -8
  246. package/dist/uploads-archil.js +1 -1
  247. package/dist/uploads.js +1 -1
  248. package/dist/validate.js +1 -2
  249. package/dist/workspace/computer-for-claim.d.ts +2 -0
  250. package/dist/workspace/computer-for-claim.js +43 -0
  251. package/dist/workspace/paths.d.ts +6 -0
  252. package/dist/workspace/paths.js +6 -0
  253. package/dist/workspace/resolve-computer.d.ts +1 -0
  254. package/dist/workspace/run-tools.d.ts +2 -0
  255. package/dist/workspace/run-tools.js +8 -0
  256. package/launcher/agentrun-serve +1 -1
  257. package/package.json +10 -10
  258. package/skills/agentrun-serve/SKILL.md +2 -1
  259. package/templates/README.md +5 -2
  260. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  261. package/dist/console/assets/index-DlQepP2J.css +0 -1
package/dist/print.js CHANGED
@@ -16,7 +16,7 @@ export function banner(o) {
16
16
  `AGENTRUN_API_KEY=${key}`,
17
17
  ...(o.tokenIds && (o.tokenIds.length > 1 || o.source === "list") ? [`API tokens taken (ids): ${o.tokenIds.join(", ")}`] : []),
18
18
  o.apiOnly
19
- ? "API only (AGENTRUN_API_ONLY=1): the run routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
19
+ ? "API only (AGENTRUN_API_ONLY=1): the run and deploy routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
20
20
  : o.accounts || o.launchCode === undefined ? `Open ${o.publicUrl ?? o.url}/` : `Open ${o.publicUrl ?? o.url}/?launch=${o.launchCode}`,
21
21
  ...(o.boxes ? [o.boxes] : []),
22
22
  ];
@@ -0,0 +1,12 @@
1
+ import { ApiError } from "./errors.js";
2
+ import type { Snapshot } from "./learn/folder.js";
3
+ import type { RunRow, Store } from "./store/index.js";
4
+ /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
5
+ * meter as /usage read it at its purge (null: unknown, or none read). */
6
+ export declare function purgedRun(row: RunRow): ApiError;
7
+ /** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
8
+ * workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
9
+ * (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
10
+ * main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
11
+ * every read of a learned workflow's text asks. */
12
+ export declare function purgedWorkflows(snapshot: Snapshot | undefined, store: Pick<Store, "runs">): Promise<ReadonlyMap<string, RunRow>>;
@@ -0,0 +1,43 @@
1
+ // What a purged run (DELETE /v2/runs/{id}, agent-delete.ts purgeRun) answers, and the one rule for a learned workflow
2
+ // whose text it wrote: its purge takes it off main (learn/commit.ts forgetRunText), and every read at a past commit
3
+ // refuses it, so it is never served or executed.
4
+ // - The learned file read (GET .../learning/files/workflows/<name>/workflow.json) of one still on main (its run
5
+ // purged before purges took it off) is 410 purged with the run's tombstone, as every route of the run is (purgedRun).
6
+ // - The champion read by digest (GET .../learning/promotions) reads no commit for it.
7
+ // - A later merge's diff (GET /runs/{id}/learning/diff) serves that file against nothing: never the purged text.
8
+ // - An SDK start sent again (sdk/runs.ts receipt) whose receipt pinned it is 410 purged, as the file read.
9
+ // - A run's seed (learning.ts seedAt) leaves it out, so no claim lays, checks, replays or serves it, and a champion
10
+ // read at its commit finds none: the run goes on as it does when no champion serves.
11
+ import { ApiError } from "./errors.js";
12
+ const isoOrNull = (ms) => (ms === null ? null : new Date(ms).toISOString());
13
+ /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
14
+ * meter as /usage read it at its purge (null: unknown, or none read). */
15
+ export function purgedRun(row) {
16
+ const meters = row.metrics?.purged?.meters;
17
+ return new ApiError("purged", `The run ${row.id} was purged: what it was given and did is gone, and its cost stays in every total.`, {
18
+ details: {
19
+ run_id: row.id, agent_id: row.agentId, state: row.state, started_at: isoOrNull(row.startedAt), ended_at: isoOrNull(row.endedAt),
20
+ cost_usd: row.costUsd ?? row.costAtMostUsd, cost_upper_bound: row.costUsd === null && row.costAtMostUsd !== null, tools_usd: typeof meters?.tools === "number" ? meters.tools : null,
21
+ purged_at: isoOrNull(row.purgedAt),
22
+ },
23
+ });
24
+ }
25
+ /** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
26
+ * workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
27
+ * (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
28
+ * main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
29
+ * every read of a learned workflow's text asks. */
30
+ export async function purgedWorkflows(snapshot, store) {
31
+ const writers = new Map();
32
+ for (const item of snapshot?.workflows ?? [])
33
+ if (item.run)
34
+ writers.set(item.name, item.run);
35
+ const rows = new Map(await Promise.all([...new Set(writers.values())].map(async (run) => [run, await store.runs.get(run)])));
36
+ const purged = new Map();
37
+ for (const [name, run] of writers) {
38
+ const row = rows.get(run);
39
+ if (row && row.purgedAt !== null)
40
+ purged.set(name, row);
41
+ }
42
+ return purged;
43
+ }
@@ -0,0 +1,46 @@
1
+ import { ApiError, type InputIssue } from "./errors.js";
2
+ import type { Revision } from "./agent-rows.js";
3
+ import { type RunNeeds } from "./run-secrets.js";
4
+ /** A run's own tool keys, by name. */
5
+ export type RunKeys = Readonly<Record<string, string>>;
6
+ /** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
7
+ export declare const keysOfTools: (tools: readonly string[]) => string[];
8
+ /** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
9
+ * can carry. A model key is not one. */
10
+ export declare const packageKeysOf: (revision: object) => string[];
11
+ /** The names a run of `revision`, whose needs are `needs` (run-secrets.ts needsOf), may carry in `keys`: each tool key its
12
+ * tools read (an agentic revision's tools, a workflow's on its nodes and calls, and its decision providers'), and its
13
+ * template's tool keys. */
14
+ export declare const declaredFrom: (needs: RunNeeds, revision: object) => string[];
15
+ /** The names a run of `revision` may carry in `keys` (declaredFrom). */
16
+ export declare function declaredKeys(revision: Pick<Revision, "kind" | "body"> & object): Promise<string[]>;
17
+ /** The longest key value taken. */
18
+ export declare const MAX_KEY = 8192;
19
+ /** `keys` as a body gives it, checked: tool key names (TOOL_FIELDS) to their values, each checked as every handed key is
20
+ * (handed-secret.ts), up to MAX_KEY. Each problem goes to `issues` by name, never with its value. */
21
+ export declare function runKeysOf(value: unknown, issues: InputIssue[]): RunKeys;
22
+ /** Each of `names` that `declared` leaves out, as a 422 issue at keys.<NAME>. */
23
+ export declare function undeclaredKeys(names: readonly string[], declared: readonly string[]): InputIssue[];
24
+ /** `env` with each of `names` set, for the checks a start makes and the tool plane it resolves (never a process's
25
+ * environment): a key the run carries counts as one this server holds. Every property of `env` is kept, its symbols
26
+ * among them. */
27
+ export declare function withCarried(env: NodeJS.ProcessEnv, names: readonly string[]): NodeJS.ProcessEnv;
28
+ /** Under the run-keys setting, each tool key `revision`'s template declared that `env` (the server's) does not hold and
29
+ * the run does not carry, as a 409 issue at keys.<NAME>: the apply made it on the promise each run brings it. */
30
+ export declare function keysOwed(revision: object, env: NodeJS.ProcessEnv, carried: readonly string[]): InputIssue[];
31
+ /** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
32
+ * gets when it is made or moved (firingsOwe). */
33
+ export declare const keysOwedRefusal: (owed: readonly InputIssue[]) => ApiError;
34
+ /** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
35
+ * keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
36
+ * which hands each firing to the backend in front of this server to start the run with its keys (trigger-launch-hook.ts). */
37
+ export declare const firingsOwe: (owed: readonly unknown[], target: "start_run" | "message_run", hooked: boolean) => boolean;
38
+ /** Why an apply under the run-keys setting does not make `trigger` of the `packageName` template (a start_run's) for an
39
+ * agent whose runs owe `owed`, or undefined when it makes it (firingsOwe). */
40
+ export declare function runKeysTriggerSkipped(packageName: string, trigger: {
41
+ name?: unknown;
42
+ source?: unknown;
43
+ }, owed: readonly string[], hooked: boolean): {
44
+ reason: "not_set_up_here";
45
+ message: string;
46
+ } | undefined;
@@ -0,0 +1,109 @@
1
+ // A run's own tool keys: `keys` on a run's start (POST /agents/{id}/runs, POST /runs) or on a message, by name, for the tool
2
+ // keys its revision declares (declaredKeys). They are taken out of the body before anything reads it, as model_key is
3
+ // (server.ts handedLaunchSecrets), sealed with the run's launch secrets (store/seal.ts sealRunLaunch), opened by its
4
+ // claim for its tools alone (runner/claim-secrets.ts), and erased with the rest when the run's turn ends. Stored only
5
+ // sealed with the run's launch, until its turn ends; never logged or answered: only their names are read before the seal,
6
+ // for the checks a start makes.
7
+ //
8
+ // AGENTRUN_RUN_KEYS=1 (env-switch.ts): an install whose runs bring the tool keys it does not hold. A template's
9
+ // apply then makes its agent though a tool key the template declares is not set here, and says so in a warning; a run of
10
+ // that revision that does not carry the key is refused (409 agent_not_runnable, at keys.<NAME>), and no trigger is made
11
+ // whose firings could not carry it (firingsOwe). Off, nothing changes.
12
+ import { ApiError } from "./errors.js";
13
+ import { handedSecretOf } from "./handed-secret.js";
14
+ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
15
+ import { needsOf, unlockedFields } from "./run-secrets.js";
16
+ import { TOOL_FIELDS } from "./tool-keys.js";
17
+ import { isObject } from "./validate.js";
18
+ import { RUN_KEYS_ENV } from "./env-switch.js";
19
+ /** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
20
+ export const keysOfTools = (tools) => unlockedFields(tools);
21
+ /** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
22
+ * can carry. A model key is not one. */
23
+ export const packageKeysOf = (revision) => (revision.package?.secrets ?? []).filter((name) => TOOL_FIELDS.includes(name));
24
+ /** The names a run of `revision`, whose needs are `needs` (run-secrets.ts needsOf), may carry in `keys`: each tool key its
25
+ * tools read (an agentic revision's tools, a workflow's on its nodes and calls, and its decision providers'), and its
26
+ * template's tool keys. */
27
+ export const declaredFrom = (needs, revision) => [...new Set([...keysOfTools([...needs.tools, ...needs.decisionProviders.map((provider) => `decisions.${provider}`)]), ...packageKeysOf(revision)])];
28
+ /** The names a run of `revision` may carry in `keys` (declaredFrom). */
29
+ export async function declaredKeys(revision) {
30
+ return declaredFrom(await needsOf(revision), revision);
31
+ }
32
+ /** The longest key value taken. */
33
+ export const MAX_KEY = 8192;
34
+ /** `keys` as a body gives it, checked: tool key names (TOOL_FIELDS) to their values, each checked as every handed key is
35
+ * (handed-secret.ts), up to MAX_KEY. Each problem goes to `issues` by name, never with its value. */
36
+ export function runKeysOf(value, issues) {
37
+ if (!isObject(value)) {
38
+ issues.push({ field: "keys", reason: "wrong_type", message: 'keys is an object of tool key names to their values, such as {"PARALLEL_API_KEY": "..."}.' });
39
+ return {};
40
+ }
41
+ const out = {};
42
+ for (const [name, given] of Object.entries(value)) {
43
+ const field = `keys.${name}`;
44
+ if (!TOOL_FIELDS.includes(name))
45
+ issues.push({ field, reason: "not_an_option", message: `${name} is not a tool key a run can carry: one of ${TOOL_FIELDS.join(", ")}.` });
46
+ else if (typeof given !== "string")
47
+ issues.push({ field, reason: "wrong_type", message: `${field} is the key's value, as text.` });
48
+ else {
49
+ const wrong = handedSecretOf(given, field, MAX_KEY);
50
+ if (wrong)
51
+ issues.push(wrong);
52
+ else
53
+ out[name] = given;
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+ /** Each of `names` that `declared` leaves out, as a 422 issue at keys.<NAME>. */
59
+ export function undeclaredKeys(names, declared) {
60
+ const reads = declared.length ? `it reads ${declared.join(", ")}` : "it reads none";
61
+ return names.filter((name) => !declared.includes(name)).map((name) => ({ field: `keys.${name}`, reason: "not_an_option", message: `${name} is a key no tool of this run's revision reads: ${reads}.` }));
62
+ }
63
+ /** What the start's checks read for a key a run carries: never a value, only that one is set. */
64
+ const CARRIED = "(carried by the run)";
65
+ /** `env` with each of `names` set, for the checks a start makes and the tool plane it resolves (never a process's
66
+ * environment): a key the run carries counts as one this server holds. Every property of `env` is kept, its symbols
67
+ * among them. */
68
+ export function withCarried(env, names) {
69
+ if (!names.length)
70
+ return env;
71
+ // A held secret is a fixed property (secrets.ts withSecrets), set even when empty: one the run carries and `env` holds
72
+ // empty is left out of the copy, then marked carried.
73
+ const owed = names.filter((name) => !env[name]);
74
+ const descriptors = Object.getOwnPropertyDescriptors(env);
75
+ for (const name of owed)
76
+ delete descriptors[name];
77
+ const out = Object.defineProperties({}, descriptors);
78
+ for (const name of owed)
79
+ Object.defineProperty(out, name, { value: CARRIED, enumerable: false, configurable: true });
80
+ return out;
81
+ }
82
+ /** Under the run-keys setting, each tool key `revision`'s template declared that `env` (the server's) does not hold and
83
+ * the run does not carry, as a 409 issue at keys.<NAME>: the apply made it on the promise each run brings it. */
84
+ export function keysOwed(revision, env, carried) {
85
+ return packageKeysOf(revision).filter((name) => !env[name] && !carried.includes(name)).map((name) => ({
86
+ field: `keys.${name}`,
87
+ reason: "not_set_up_here",
88
+ message: `This agent's template needs ${name}, which this server does not hold: it takes it from each run (${RUN_KEYS_ENV}=1).`,
89
+ fix: `Send keys.${name} with the run.`,
90
+ }));
91
+ }
92
+ /** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
93
+ * gets when it is made or moved (firingsOwe). */
94
+ export const keysOwedRefusal = (owed) => new ApiError("agent_not_runnable", owed.map((one) => one.message).join(" "), { fields: [...owed], details: { unbound: [], missing: {} } });
95
+ /** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
96
+ * keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
97
+ * which hands each firing to the backend in front of this server to start the run with its keys (trigger-launch-hook.ts). */
98
+ export const firingsOwe = (owed, target, hooked) => owed.length > 0 && (target === "message_run" || !hooked);
99
+ /** Why an apply under the run-keys setting does not make `trigger` of the `packageName` template (a start_run's) for an
100
+ * agent whose runs owe `owed`, or undefined when it makes it (firingsOwe). */
101
+ export function runKeysTriggerSkipped(packageName, trigger, owed, hooked) {
102
+ if (!firingsOwe(owed, "start_run", hooked))
103
+ return undefined;
104
+ const kind = isObject(trigger.source) ? String(trigger.source.kind) : "";
105
+ return {
106
+ reason: "not_set_up_here",
107
+ message: `The ${packageName} template's trigger ${String(trigger.name).trim()} (${kind}) was not made: each run of its agent must carry ${owed.join(" and ")} in keys (${RUN_KEYS_ENV}=1), and its firings would start runs without them. Start its runs through the API with keys, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to the backend in front of this server, which starts the run with its keys.`,
108
+ };
109
+ }
@@ -61,9 +61,12 @@ export interface RunLaunch {
61
61
  * runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
62
62
  readonly files?: readonly string[];
63
63
  /** The server copied `files` into the run's folder (work/inputs/) when it started the run, before its row was written:
64
- * a run on an Archil disk (Mode 2, uploads-archil.ts placeRunFiles). Its claim reads no upload (uploads.ts
64
+ * a run on an Archil disk (Mode 2, uploads-archil.ts placeRunFiles), or a moved project's local placement. Its claim reads no upload (uploads.ts
65
65
  * filesToCopy). Absent: the claim copies them from the server's data directory, as before. */
66
66
  readonly filesPlaced?: true;
67
+ /** A moved project's completed, private pre-admission placement. Claims verify this receipt; they never seed again.
68
+ * The control marker is outside the run's tool workspace. No source path or credential is kept in this record. */
69
+ readonly sourceProject?: SourceProjectLaunch;
67
70
  /** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
68
71
  * no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
69
72
  * the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
@@ -110,6 +113,18 @@ export interface RunLaunch {
110
113
  readonly minutes: number;
111
114
  };
112
115
  }
116
+ /** Immutable placement identity for a project copied before admission. */
117
+ export interface SourceProjectLaunch {
118
+ readonly version: 1;
119
+ readonly sourceId: string;
120
+ readonly baselineRevision: string;
121
+ readonly digest: string;
122
+ /** SHA-256 of the private complete marker's exact bytes. */
123
+ readonly receipt: string;
124
+ /** Exact preplaced upload paths, pinned in the private marker; never a whole inputs/ exclusion. */
125
+ readonly inputs?: readonly string[];
126
+ }
127
+ export declare function sourceProjectOf(value: unknown): SourceProjectLaunch | undefined;
113
128
  /** What a replay run replays: the graded run, and the learned workflow at the digest it decides. */
114
129
  export interface Replay {
115
130
  readonly of: string;
@@ -9,7 +9,31 @@ import { nativeOf } from "./native/binding.js";
9
9
  // the run's own trigger with owner === (the source is a schedule, whose words its owner wrote when they set it up), else
10
10
  // that trigger's own with owner false, so a forged or lost origin never reads as the person's or the owner's.
11
11
  import { originOf } from "./timeline/index.js";
12
- import { isObject } from "./validate.js";
12
+ import { ID, isObject } from "./validate.js";
13
+ import { relativeSegments } from "./workspace/paths.js";
14
+ export function sourceProjectOf(value) {
15
+ if (!isObject(value) || value.version !== 1 || Object.keys(value).length !== (value.inputs === undefined ? 5 : 6)
16
+ || typeof value.baselineRevision !== "string" || !ID.test(value.baselineRevision))
17
+ return undefined;
18
+ for (const key of ["sourceId", "digest", "receipt"])
19
+ if (typeof value[key] !== "string" || !/^[a-f0-9]{64}$/.test(value[key]))
20
+ return undefined;
21
+ if (value.inputs !== undefined) {
22
+ if (!Array.isArray(value.inputs) || value.inputs.length > 20 || !value.inputs.length || new Set(value.inputs).size !== value.inputs.length)
23
+ return undefined;
24
+ for (const input of value.inputs) {
25
+ if (typeof input !== "string" || input.length > 4096 || /[\x00-\x1f\x7f]/.test(input) || !input.startsWith("inputs/") || input === "inputs/message.md")
26
+ return undefined;
27
+ try {
28
+ relativeSegments(input);
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
34
+ }
35
+ return value;
36
+ }
13
37
  /** The disk a launch body names, as read back, or undefined. */
14
38
  const readDisk = (value) => isObject(value) && typeof value.disk_id === "string" && (value.kind === "launch" || value.kind === "agent") ? { diskId: value.disk_id, kind: value.kind } : undefined;
15
39
  /** The replay a launch body names, as read back, or undefined. */
@@ -70,6 +94,7 @@ export function launchBody(launch) {
70
94
  ...(launch.boxAllowSet ? { box_allow_set: true } : {}),
71
95
  ...(launch.files?.length ? { files: launch.files } : {}),
72
96
  ...(launch.filesPlaced ? { files_placed: true } : {}),
97
+ ...(launch.sourceProject ? { source_project: launch.sourceProject } : {}),
73
98
  ...(launch.learning ? { learning: { seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.noWorkflows ? { noWorkflows: true } : {}), ...(launch.learning.model ? { model: launch.learning.model } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}), ...(launch.learning.seededAt !== undefined ? { seededAt: launch.learning.seededAt } : {}) } } : {}),
74
99
  ...(launch.workflowFirst === false ? { workflow_first: false } : {}),
75
100
  ...(launch.replay ? { replay: { of: launch.replay.of, workflow: launch.replay.workflow, digest: launch.replay.digest } } : {}),
@@ -108,6 +133,9 @@ export function launchOnItsDisk(launch) {
108
133
  export function readLaunchBody(stored) {
109
134
  if (!isObject(stored))
110
135
  return undefined;
136
+ const sourceProject = sourceProjectOf(stored.source_project);
137
+ if (stored.source_project !== undefined && !sourceProject)
138
+ return undefined;
111
139
  const place = readPlace(stored.place);
112
140
  if (!place)
113
141
  return undefined;
@@ -135,6 +163,7 @@ export function readLaunchBody(stored) {
135
163
  ...(stored.box_allow_set === true ? { boxAllowSet: true } : {}),
136
164
  ...(Array.isArray(stored.files) && stored.files.every((id) => typeof id === "string") ? { files: stored.files } : {}),
137
165
  ...(stored.files_placed === true ? { filesPlaced: true } : {}),
166
+ ...(sourceProject ? { sourceProject } : {}),
138
167
  ...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { seed: null, section: "" } } : {}),
139
168
  ...(stored.workflow_first === false ? { workflowFirst: false } : {}),
140
169
  ...(readReplay(stored.replay) ? { replay: readReplay(stored.replay) } : {}),
@@ -9,7 +9,7 @@ export declare function servedRunLearning(deps: {
9
9
  }, store: Store, runId: string): Promise<{
10
10
  run: string;
11
11
  state: "dropped" | "merged" | "seeded" | "reflecting";
12
- reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
12
+ reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
13
13
  detail: string | null;
14
14
  at: string;
15
15
  workflows: import("./learning.js").LearnedFile[];
@@ -52,7 +52,7 @@ export declare function servedRunLearning(deps: {
52
52
  };
53
53
  run: string;
54
54
  state: "dropped" | "merged" | "seeded" | "reflecting";
55
- reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
55
+ reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
56
56
  detail: string | null;
57
57
  at: string;
58
58
  workflows: import("./learning.js").LearnedFile[];
@@ -7,8 +7,8 @@ export declare function runModelOrigin(env: NodeJS.ProcessEnv): string | undefin
7
7
  /** The variables a run's model key fills in a model route's env, for a gateway at `origin`: the gateway's key, and
8
8
  * ANTHROPIC_API_KEY where ANTHROPIC_BASE_URL is that same gateway. */
9
9
  export declare function runKeyNames(env: NodeJS.ProcessEnv, origin: string): string[];
10
- /** A model key `body` hands, checked: text of 1 to MAX_MODEL_KEY_CHARS characters with no whitespace or control character
11
- * (it goes in a header). Issues are pushed at `model_key`. */
10
+ /** A model key `body` hands, checked as every handed key is (handed-secret.ts), up to MAX_MODEL_KEY_CHARS. Issues are
11
+ * pushed at `model_key`. */
12
12
  export declare function modelKeyOf(value: unknown, issues: InputIssue[]): string | undefined;
13
13
  /** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
14
14
  * none the run holds, and none the server holds for its route. */
@@ -15,6 +15,7 @@
15
15
  // to spend is 422 model_key_required, never a failure at the first model call. Spend after a run's turn ended (its key
16
16
  // erased with that end, and revoked by its caller) or tied to no run, with no key to spend, is skipped or refused in words.
17
17
  import { ApiError } from "./errors.js";
18
+ import { handedSecretOf } from "./handed-secret.js";
18
19
  import { FAUX_ENV, GATEWAY_KEY_ENV, MODEL_PROVIDER, PROVIDER_KEYS } from "./model.js";
19
20
  import { gatewayBase } from "./provider.js";
20
21
  /** The longest model key a run takes: a header value, never a document. */
@@ -50,14 +51,13 @@ export function runKeyNames(env, origin) {
50
51
  }
51
52
  /** Every model key a model route reads by name: each of pi-ai's providers' and the gateway's. */
52
53
  const MODEL_KEY_NAMES = new Set([...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV]);
53
- /** A model key `body` hands, checked: text of 1 to MAX_MODEL_KEY_CHARS characters with no whitespace or control character
54
- * (it goes in a header). Issues are pushed at `model_key`. */
54
+ /** A model key `body` hands, checked as every handed key is (handed-secret.ts), up to MAX_MODEL_KEY_CHARS. Issues are
55
+ * pushed at `model_key`. */
55
56
  export function modelKeyOf(value, issues) {
56
57
  if (typeof value !== "string")
57
58
  return void issues.push({ field: "model_key", reason: "wrong_type", message: "model_key is the run's model key as text, such as a LiteLLM virtual key minted for this run." });
58
- if (!value.length || value.length > MAX_MODEL_KEY_CHARS || /[\s\x00-\x1f\x7f]/.test(value))
59
- return void issues.push({ field: "model_key", reason: "invalid", message: `model_key is 1 to ${MAX_MODEL_KEY_CHARS} characters with no space or control character.` });
60
- return value;
59
+ const wrong = handedSecretOf(value, "model_key", MAX_MODEL_KEY_CHARS);
60
+ return wrong ? void issues.push(wrong) : value;
61
61
  }
62
62
  /** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
63
63
  * none the run holds, and none the server holds for its route. */
@@ -7,6 +7,8 @@ type KeyRow = {
7
7
  fields: readonly string[];
8
8
  unlocks: readonly string[];
9
9
  };
10
+ /** Each field of a `tool` row of `rows` that unlocks one of `tools`: the tool keys a run of them reads. */
11
+ export declare const unlockedFields: (tools: readonly string[], rows?: readonly KeyRow[]) => string[];
10
12
  /** What of a revision decides the secrets its runs are handed, none of it a key, read once per revision (a revision
11
13
  * never changes): its harness, the model it names, the tools it binds (an agentic revision's `tools`, a workflow's on
12
14
  * its model nodes and its `call` nodes), a workflow's tiers (those its model nodes and `llm` calls run on), and its
@@ -8,6 +8,7 @@ import { GATEWAY_KEY_ENV, llmTiers, modelKeys, nodeTiers, PROVIDER_KEYS, workflo
8
8
  import { DECISION_KEYS, SECRET_NAMES } from "./secrets.js";
9
9
  import { TOOL_FIELDS, TOOL_KEYS, unlocksTool } from "./tool-keys.js";
10
10
  import { workflowTools } from "./tools.js";
11
+ import { LAUNCH_HOOK_SECRET_ENV } from "./trigger-launch-hook.js";
11
12
  import { ARCHIL_API_KEY_ENV } from "./workspace/archil-key.js";
12
13
  /** The computer providers' account keys a run never gets: every computer key (computer-keys.ts COMPUTER_KEY_NAMES) but
13
14
  * a tool key's field (Browserbase's and Kernel's, which a run's `browser` tool takes when its revision binds it). Only
@@ -16,14 +17,16 @@ const COMPUTER_ACCOUNT_KEYS = COMPUTER_KEY_NAMES.filter((name) => !TOOL_FIELDS.i
16
17
  /** The server's own secrets, which a run never gets: the API token, by name or by value, the seal key the tool keys are
17
18
  * kept under (tool-keys.ts), the store's URL (it may hold the database's password), the remote boxes' keys
18
19
  * (place-offers.ts BOX_KEYS) and every other computer provider's account key, which only the server's and the runner's
19
- * computer providers use, and the Archil account key (archil-key.ts), from which the claim mints each run's own mount
20
- * credential. */
21
- const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS, ...COMPUTER_ACCOUNT_KEYS, ARCHIL_API_KEY_ENV]);
20
+ * computer providers use, the Archil account key (archil-key.ts), from which the claim mints each run's own mount
21
+ * credential, and the launch hook's signing secret (trigger-launch-hook.ts). */
22
+ const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS, ...COMPUTER_ACCOUNT_KEYS, ARCHIL_API_KEY_ENV, LAUNCH_HOOK_SECRET_ENV]);
22
23
  /** The secrets a run may be handed: every one but the server's own and the decision keys, which go apart. */
23
24
  export const RUN_SECRETS = SECRET_NAMES.filter((name) => !SERVER_ONLY.has(name) && !DECISION_KEYS.includes(name));
24
25
  /** The fields a run gets only when its revision names what they unlock: a `tool` key's. Any other kind's (a model key's)
25
26
  * is the model's to need, as every model key is. */
26
27
  const scopedOf = (rows) => rows.filter((row) => row.kind === "tool").flatMap((row) => row.fields);
28
+ /** Each field of a `tool` row of `rows` that unlocks one of `tools`: the tool keys a run of them reads. */
29
+ export const unlockedFields = (tools, rows = TOOL_KEYS) => [...new Set(rows.filter((row) => row.kind === "tool" && row.unlocks.some((unlock) => tools.some((name) => unlocksTool(unlock, name)))).flatMap((row) => row.fields))];
27
30
  /** The model keys: every key of pi-ai's providers (model.ts' PROVIDER_KEYS) and the gateway's. A run gets those its model
28
31
  * needs and no other (keysFor). A workflow's decision keys, OpenRouter's among them, go apart (decisions.ts), whatever
29
32
  * its model. */
@@ -49,7 +52,7 @@ export async function needsOf(revision) {
49
52
  * (HarnessEntry.ownKeys: Cursor's CURSOR_API_KEY) on a run of any other harness. Read at each claim, so a key saved with no restart counts at
50
53
  * the next. */
51
54
  export function keysFor(needs, env, rows = TOOL_KEYS) {
52
- const unlocked = new Set(rows.filter((row) => row.unlocks.some((unlock) => needs.tools.some((name) => unlocksTool(unlock, name)))).flatMap((row) => row.fields));
55
+ const unlocked = new Set(unlockedFields(needs.tools, rows));
53
56
  const scoped = scopedOf(rows);
54
57
  const entry = harnessOf(env, needs.harness);
55
58
  const model = new Set(!entry || entry.facts ? harnessModelKeys(needs.harness, env, needs.model) : needs.tiers ? modelKeys(env, undefined, needs.tiers) : modelKeys(env, needs.model));
@@ -10,6 +10,20 @@ import type { CostParts } from "@parcha/agentrun-kernel";
10
10
  /** The sign-in read surface a run's served view needs: a run's handed-pointer cut reads only `peek` (the agent's saved
11
11
  * pointer) and `forgotten` (its tombstoned ones), over the store (sign-ins-store.ts signInReads). */
12
12
  export type SignInReader = ReturnType<typeof signInReads>;
13
+ /** How a run wound down for its spend cap (`max_cost_usd`), from its journal's root entries: the tool calls the cap's
14
+ * wrap-up refused (CAP_REFUSED, each call once however often it was refused: a replay is the same call), and whether it
15
+ * wound down under the cap it has now (`capUsd`, its newest raise's, else its start's): its model was told to wrap up
16
+ * under that cap (a CAP_WRAPUP naming it; the free-request limit's note names none, and is no dollar cap's), or a call
17
+ * was refused under it. A cap raised past a wrap-up is a new cap the run has not wound down under. `skip`: entries not
18
+ * the job's (its end-of-run turn's), which count for neither. The view's `stopped_for` and `budget_refused_calls`. */
19
+ export declare function windDownOf(entries: readonly {
20
+ readonly kind?: string;
21
+ readonly id?: unknown;
22
+ readonly data?: unknown;
23
+ }[], capUsd: number | undefined, skip?: (id: number) => boolean): {
24
+ readonly refusedCalls: number;
25
+ readonly woundDown: boolean;
26
+ };
13
27
  /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
14
28
  export declare const costOf: (rows: readonly TimelineEvent[]) => number | null;
15
29
  /** The run's cost in its usage row's own words (a bound with its exact part and holds, an unknown cost with what is
@@ -337,6 +351,9 @@ export interface RunMoment {
337
351
  readonly id: string;
338
352
  readonly agentId: string;
339
353
  readonly kind: "agentic" | "workflow";
354
+ /** The harness its revision names (run.harness): a trigger's message to a run on a plan-billed recipe is refused
355
+ * (trigger-targets.ts). Absent only where a caller builds a moment by hand. */
356
+ readonly harness?: string;
340
357
  /** Where an imported run came from (run.imported?.source); absent for a run started here. An imported run takes no act. */
341
358
  readonly importedSource?: string;
342
359
  /** A cancel is in flight (run.cancel), whether or not its end is written yet. */
package/dist/run-view.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // The pieces here so far: the cost reads (a run's cost, its paid tools' charges, the cost a view shows, what it has cost so
7
7
  // far when the total is unknown) and the served row transforms a view applies to the timeline (the over-cap row, the
8
8
  // paused run's waiting row). All read the same rows the timeline renders.
9
- import { chargedTool, isMessageRow, NOTE_SUFFIX, registerLabel, registerTurnEnding, scrubUrls } from "./timeline/index.js";
9
+ import { CAP_REFUSED, CAP_WRAPUP, chargedTool, isMessageRow, NOTE_SUFFIX, registerLabel, registerTurnEnding, scrubUrls } from "./timeline/index.js";
10
10
  import { CAP_TOLERANCE, FIT_TOLERANCE, money, roomRefusal } from "./cap.js";
11
11
  import { APPROVAL_ROW, previewOf } from "./tool-gate.js";
12
12
  import { ASK_TOOL, toolOf } from "./tools.js";
@@ -18,6 +18,29 @@ import { MIN_SECRET } from "./learn/secrets.js";
18
18
  import { costWordsOf, usageParts } from "./runner/metrics.js";
19
19
  import { KINDS } from "./runner/journal-kinds.js";
20
20
  import { ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
21
+ /** How a run wound down for its spend cap (`max_cost_usd`), from its journal's root entries: the tool calls the cap's
22
+ * wrap-up refused (CAP_REFUSED, each call once however often it was refused: a replay is the same call), and whether it
23
+ * wound down under the cap it has now (`capUsd`, its newest raise's, else its start's): its model was told to wrap up
24
+ * under that cap (a CAP_WRAPUP naming it; the free-request limit's note names none, and is no dollar cap's), or a call
25
+ * was refused under it. A cap raised past a wrap-up is a new cap the run has not wound down under. `skip`: entries not
26
+ * the job's (its end-of-run turn's), which count for neither. The view's `stopped_for` and `budget_refused_calls`. */
27
+ export function windDownOf(entries, capUsd, skip) {
28
+ const underCap = (cap) => capUsd !== undefined && typeof cap === "number" && Math.abs(cap - capUsd) <= CAP_TOLERANCE;
29
+ const calls = new Set();
30
+ let woundDown = false;
31
+ for (const entry of entries) {
32
+ if (entry.kind !== CAP_REFUSED && entry.kind !== CAP_WRAPUP)
33
+ continue;
34
+ if (skip?.(Number(entry.id)))
35
+ continue;
36
+ const data = (entry.data ?? {});
37
+ if (entry.kind === CAP_REFUSED && typeof data.callId === "string")
38
+ calls.add(data.callId);
39
+ if (underCap(data.capUsd))
40
+ woundDown = true;
41
+ }
42
+ return { refusedCalls: calls.size, woundDown };
43
+ }
21
44
  /** The run's newest usage row, which carries its cost. */
22
45
  const usageOf = (rows) => rows.findLast((r) => r.kind === "usage");
23
46
  /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
@@ -476,6 +499,7 @@ export function momentOf(run, facts, live) {
476
499
  id: run.id,
477
500
  agentId: run.agentId,
478
501
  kind: run.kind,
502
+ harness: run.harness,
479
503
  ...(run.imported ? { importedSource: run.imported.source } : {}),
480
504
  cancelled: run.cancel,
481
505
  terminal,
@@ -1,3 +1,4 @@
1
+ import type { ProjectCheckpoint } from "../source-sync/checkpoints.js";
1
2
  import { type ConversationId, type ConversationRetryPolicy, type ConversationStreamOptions, Harness, type Tx } from "@earendil-works/pi-durable";
2
3
  import { type AdapterFacts, type AgentAdapter, type Refusal, type SessionRecord, type SessionSpec } from "@parcha/agentrun-kernel";
3
4
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
@@ -5,6 +6,7 @@ import { type BudgetData, type EndData, type ToolCalls } from "./journal-kinds.j
5
6
  import { type MessageOrigin } from "../timeline/index.js";
6
7
  type EndCost = Required<Pick<EndData, "costUsd" | "costUpperBound">>;
7
8
  import { type Claim, type EndOfRunTurn, type LoopFactory } from "./loop-contract.js";
9
+ import { type HeldRedact } from "./redact.js";
8
10
  import { Parked } from "./loop.js";
9
11
  import type { PiRun } from "./adapters/pi.js";
10
12
  import { type HeldSpec } from "./held-run.js";
@@ -176,6 +178,12 @@ export interface AdapterRunSpec {
176
178
  readonly endCost?: () => Promise<EndCost>;
177
179
  /** The most the end's patch may take before the end is written without it. Default END_PATCH_MS. */
178
180
  readonly endPatchMs?: number;
181
+ /** Optional moved-project capture, only after actual dispatch has drained. Failure remains an explicit terminal receipt. */
182
+ readonly projectCheckpoint?: {
183
+ capture(signal: AbortSignal): Promise<ProjectCheckpoint>;
184
+ uncertain(): ProjectCheckpoint;
185
+ readonly timeoutMs?: number;
186
+ };
179
187
  /** The most a booking whose write has begun is waited for before an answer's cost, a park or the end goes on without
180
188
  * it. Default BOOKING_WRITE_MS. */
181
189
  readonly bookingWriteMs?: number;
@@ -285,9 +293,9 @@ export type AdapterRun = PiRun & {
285
293
  * learned workflow's model nodes). Read from the spec's runCap once the spec is known. */
286
294
  readonly ledger: RunLedger;
287
295
  /** The runner's one redactor (LoopDeps.redact; runner.ts), the same instance: the spec gives it to every place a secret
288
- * could reach text (the session's model proxy, the model route's translation, its log lines). Absent where no runner
289
- * gave one (a spec built alone). */
290
- readonly redact?: (text: string) => string;
296
+ * could reach text (the session's model proxy, the model route's translation, its log lines), and its claim carries the
297
+ * run's own tool keys into (claim-secrets.ts). Absent where no runner gave one (a spec built alone). */
298
+ readonly redact?: HeldRedact;
291
299
  /** The claim's signal (LoopDeps.signal): aborted on a lost claim or the runner's shutdown, never on a person's stop. A
292
300
  * spec's per-claim resources let go of what they hold at once on it (the run's Archil mount credential). Absent where
293
301
  * no loop gave one (a spec built alone). */