@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
@@ -0,0 +1,63 @@
1
+ // The repository a run a person starts reaches (the start body's `repo`): what an agent is bound to, and which one a start
2
+ // may name. A run a GitHub trigger starts has its repository from the signed event; a run started by hand has none unless
3
+ // the start gives it, since the GitHub App's token is made for one repository and never for all it covers.
4
+ //
5
+ // An agent is bound to the repositories its GitHub triggers take events from: each rule's `where` condition on
6
+ // /repository/full_name, its `in` list. A start's `repo` must be one of them, so a start never reaches a repository the
7
+ // agent's own triggers do not; naming one the agent is not bound to is refused in words. A start that names none takes the
8
+ // agent's repository when it is bound to exactly one. A trigger rule with no such condition takes every repository the App
9
+ // is installed on: the agent is then bound to all of them (`open`), a start may name any, and none is taken by default.
10
+ import { isObject } from "./validate.js";
11
+ /** `owner/name`, as github.ts githubTargetOf reads a repository. */
12
+ export const REPO_NAME = /^[^/\s]+\/[^/\s]+$/;
13
+ const FULL_NAME = "/repository/full_name";
14
+ /** `agentId`'s binding, from the triggers (their source and target as stored): none (no repos, not open) for an agent no
15
+ * GitHub trigger starts. */
16
+ export function bindingOf(triggers, agentId) {
17
+ const repos = [];
18
+ let open = false;
19
+ for (const { source, target } of triggers) {
20
+ if (!isObject(target) || target.kind !== "start_run" || target.agent_id !== agentId)
21
+ continue;
22
+ if (!isObject(source) || source.kind !== "github")
23
+ continue;
24
+ const rules = Array.isArray(source.accept) ? source.accept : [];
25
+ // A github trigger with no accept takes every event the App sends, from any repository.
26
+ if (!rules.length)
27
+ open = true;
28
+ for (const rule of rules) {
29
+ // A rule's conditions all hold: each `in` list on the repository narrows the rule, so they are intersected; rules
30
+ // are alternatives, so what they name is joined.
31
+ let named;
32
+ for (const c of isObject(rule) && Array.isArray(rule.where) ? rule.where : []) {
33
+ if (!isObject(c) || c.pointer !== FULL_NAME || !Array.isArray(c.in))
34
+ continue;
35
+ const list = c.in.filter((v) => typeof v === "string" && REPO_NAME.test(v));
36
+ named = named === undefined ? list : named.filter((r) => list.some((l) => l.toLowerCase() === r.toLowerCase()));
37
+ }
38
+ if (named === undefined)
39
+ open = true;
40
+ for (const repo of named ?? [])
41
+ if (!repos.some((r) => r.toLowerCase() === repo.toLowerCase()))
42
+ repos.push(repo);
43
+ }
44
+ }
45
+ return { repos, open };
46
+ }
47
+ /** The repository a manual start runs against: `named` (the body's `repo`) when it is one the agent is bound to, else the
48
+ * agent's one repository when `named` is absent and the first message names none (`words`: it names its own). Undefined
49
+ * when the run is to have none. `refused`: why a named one is not allowed, in words for the 422. */
50
+ export function repoOf(binding, named, words) {
51
+ if (named === undefined)
52
+ return !binding.open && binding.repos.length === 1 && !words ? { repo: binding.repos[0] } : {};
53
+ const bound = binding.repos.find((r) => r.toLowerCase() === named.toLowerCase());
54
+ if (bound)
55
+ return { repo: bound };
56
+ if (binding.open)
57
+ return { repo: named };
58
+ return {
59
+ refused: binding.repos.length
60
+ ? `This agent is bound to ${binding.repos.join(", ")}, not ${named}: start the run with one of those, or leave repo out.`
61
+ : `This agent is bound to no GitHub repository, so a run of it cannot name ${named}: bind it with a GitHub trigger whose accept names the repository, or write the repository's URL in the run's first message.`,
62
+ };
63
+ }
@@ -1,4 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import { type TimelineEvent } from "./timeline/index.js";
3
3
  import { type ItemStatus } from "./learning.js";
4
4
  import { type SignInReader } from "./run-view.js";
@@ -65,7 +65,7 @@ export type Approval = {
65
65
  resolved?: true;
66
66
  };
67
67
  /** `args_shown`: the call's arguments as the server shows them (shownArgs), which the gate's resume message names. */
68
- /** `by`: "message", a deny a person's message gave while the call waited (Runs.message). */
68
+ /** `by`: "message", a deny a person's message gave while the call waited (Runs.message); "setting", the allow the tool's setting gave an ask that waited (the person flipped the tool to allow). */
69
69
  /** `superseded`: the answer a stop or a cancel overrode before the run's process acted on it, kept as it was given. */
70
70
  /** `ended`: a withdrawal by a run that ended (completed or failed) with the call waiting, which nobody stopped. */
71
71
  export type ApprovalAnswer = {
@@ -73,12 +73,12 @@ export type ApprovalAnswer = {
73
73
  note?: string;
74
74
  answered_at: string;
75
75
  args_shown?: string;
76
- by?: "message";
76
+ by?: "message" | "setting";
77
77
  superseded?: {
78
78
  decision: string;
79
79
  answered_at: string;
80
80
  note?: string;
81
- by?: "message";
81
+ by?: "message" | "setting";
82
82
  };
83
83
  ended?: true;
84
84
  };
package/dist/run-view.js CHANGED
@@ -170,7 +170,7 @@ export function answersOf(entries, { final } = {}) {
170
170
  continue;
171
171
  const superseded = given ? { superseded: { decision: given.decision, answered_at: given.answered_at, ...(given.note !== undefined ? { note: given.note } : {}), ...(given.by ? { by: given.by } : {}) } } : {};
172
172
  // A deny a person's message gave keeps that it was (`by`): its row reads "Declined by your message".
173
- out[d.callId] = { decision, ...(d.note !== undefined ? { note: d.note } : {}), answered_at: d.answeredAt ?? "", ...(decision === "deny" && d.by === "message" ? { by: "message" } : {}), ...superseded };
173
+ out[d.callId] = { decision, ...(d.note !== undefined ? { note: d.note } : {}), answered_at: d.answeredAt ?? "", ...(decision === "deny" && d.by === "message" ? { by: "message" } : decision === "allow" && d.by === "setting" ? { by: "setting" } : {}), ...superseded };
174
174
  }
175
175
  // How the run ended after each entry: the state of the first agentrun.end at or after it, else the final row's.
176
176
  let endedAs = final;
@@ -569,14 +569,15 @@ export function outcomeSays(tool, answer, failed, redact) {
569
569
  const note = noteShown(answer.note, redact);
570
570
  return note ? `AgentRun: You declined ${tool}: ${note}` : `AgentRun: You declined ${tool}.`;
571
571
  }
572
- return `AgentRun: ${tool} ran once you allowed it${failed ? ", and failed" : "; its result went to the agent"}`;
572
+ const ran = answer.by === "setting" ? "ran, as its setting allows it" : "ran once you allowed it";
573
+ return `AgentRun: ${tool} ${ran}${failed ? ", and failed" : "; its result went to the agent"}`;
573
574
  }
574
575
  /** What a person reads when they open the outcome row: the outcome, then the call's result (`rest`), or the refusal's words.
575
576
  * An empty result says so: "Its result: (no output)", never "Its result:" and nothing. */
576
577
  export function outcomeShows(tool, answer, rest, failed) {
577
578
  if (answer.decision === "deny")
578
579
  return `${answer.by === "message" ? `Your message declined ${tool}.` : `You declined ${tool}.`}${rest.trim() ? `\n${rest.trim()}` : ""}`;
579
- const head = `${tool} ran once you allowed it${failed ? ", and failed" : ""}.`;
580
+ const head = `${tool} ${answer.by === "setting" ? "ran, as its setting allows it" : "ran once you allowed it"}${failed ? ", and failed" : ""}.`;
580
581
  return rest.trim() ? `${head} Its result:\n${rest}` : `${head} Its result: (no output)`;
581
582
  }
582
583
  /** A call's own rows (its call's, its result's) before its outcome shows: what came of the approval so far. */
@@ -589,6 +590,12 @@ function callSays(answer) {
589
590
  return answer.ended ? ENDED_WHILE_WAITING : STOPPED_WHILE_WAITING;
590
591
  return "Allowed: it runs now";
591
592
  }
593
+ /** A row without the `refused` mark: it says a call was refused before it ran, so only that call's own tool_result row has it;
594
+ * the approval, message and outcome rows made from a result keep their own status. */
595
+ const unrefused = (row) => {
596
+ const { refused: _refused, ...rest } = row;
597
+ return rest;
598
+ };
592
599
  /** A synthesized row's id: the approval's own, so a pass over rows this function gave drops and remakes it. */
593
600
  const approvalRowId = (callId) => `approval:${callId}`;
594
601
  /** The rows of a run whose calls waited for approval, as the runner writes it (store-view.ts): the gate's ask
@@ -630,18 +637,18 @@ export function withApprovalRows(rows, asks, answers, redact) {
630
637
  // writes none), so the approval and outcome rows take a new id once it is there: served anew below the result, the
631
638
  // call's own rows, then its approval, then what came of it, as a person reads it.
632
639
  const at = result ? `${approvalRowId(approval.call_id)}:after` : approvalRowId(approval.call_id);
633
- const head = !answer ? "Waiting for your approval" : answer.decision === "canceled" ? "Withdrawn when the run was cancelled" : answer.decision === "withdrawn" ? (answer.ended ? "Withdrawn when the run ended" : "Withdrawn when the run was stopped") : answer.by === "message" ? "Declined by your message" : "Asked your approval";
634
- const asked = { ...row, id: at, kind: APPROVAL_ROW, summary: `${head}: ${approval.tool} ${clip(args, 400)}`, text: args, tool_name: approval.tool, tool_status: null, tool_input_preview: clip(args, 500), tool_result_preview: null, tool_result_size_bytes: null };
640
+ const head = !answer ? "Waiting for your approval" : answer.decision === "canceled" ? "Withdrawn when the run was cancelled" : answer.decision === "withdrawn" ? (answer.ended ? "Withdrawn when the run ended" : "Withdrawn when the run was stopped") : answer.by === "message" ? "Declined by your message" : answer.by === "setting" ? "Allowed by the tool's setting" : "Asked your approval";
641
+ const asked = { ...unrefused(row), id: at, kind: APPROVAL_ROW, summary: `${head}: ${approval.tool} ${clip(args, 400)}`, text: args, tool_name: approval.tool, tool_status: null, tool_input_preview: clip(args, 500), tool_result_preview: null, tool_result_size_bytes: null };
635
642
  if (!outcome)
636
643
  return [own, asked];
637
644
  const failed = answer.decision === "allow" && result?.tool_status === "failed";
638
645
  // The result's words: a tool_result row keeps them as its preview (the renderer's, redacted and cut), its text empty.
639
- const told = { ...(result ?? row), id: `${at}:outcome`, kind: "phase", origin: "server", summary: outcomeSays(approval.tool, answer, failed, redact), text: outcomeShows(approval.tool, answer, redact(result?.text || result?.tool_result_preview || ""), failed), tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null };
646
+ const told = { ...unrefused(result ?? row), id: `${at}:outcome`, kind: "phase", origin: "server", summary: outcomeSays(approval.tool, answer, failed, redact), text: outcomeShows(approval.tool, answer, redact(result?.text || result?.tool_result_preview || ""), failed), tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null };
640
647
  // A person's message that declined the call (runs-over-store.ts message: a deny carrying their words) is theirs as any
641
648
  // message is: its own row, between the approval and what came of it, as main's declineBy kept it.
642
649
  if (answer.decision === "deny" && answer.by === "message" && answer.note) {
643
650
  const words = redact(answer.note);
644
- const { origin: _origin, ...base } = result ?? row;
651
+ const { origin: _origin, ...base } = unrefused(result ?? row);
645
652
  const theirs = { ...base, id: `${at}:message`, kind: "user_message", summary: clip(`You: ${words.split("\n", 1)[0]}`, 500), text: words, tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null };
646
653
  return [own, asked, theirs, told];
647
654
  }
@@ -6,12 +6,21 @@ import { type MessageOrigin } from "../timeline/index.js";
6
6
  import { type Claim, type EndOfRunTurn, type LoopFactory } from "./loop-contract.js";
7
7
  import { Parked } from "./loop.js";
8
8
  import type { PiRun } from "./adapters/pi.js";
9
- import { type RunComputerHold } from "./computer-journal.js";
9
+ import { type HeldSpec } from "./held-run.js";
10
+ import { type LoopComputer } from "./computer-channel.js";
10
11
  import { type RunCapOptions, type RunDecisions, type RunTools } from "@parcha/agentrun-kernel/kernel/cap";
11
12
  import { type PortModels } from "../port-models.js";
12
- /** The run's cap as its spec gives it: the kernel runCap's options but its sessions, which the loop's are. */
13
- export type RunCapConfig = Omit<RunCapOptions, "sessions">;
13
+ /** The run's cap's config, as its spec gives it: the kernel runCap's options but its sessions (the loop's own), and
14
+ * `beside`, what was spent beside the run's sessions on its behalf (Store.learning.spentBeside: its learning runs'
15
+ * grades), which every gate of the run reads with its sessions' spend (runBooking's sessions.beside, overCap, the
16
+ * wrap-ups). None: nothing is. */
17
+ export type RunCapConfig = Omit<RunCapOptions, "sessions"> & {
18
+ beside?(): Promise<number | null>;
19
+ };
14
20
  import { type ClaimMcp } from "./mcp-run.js";
21
+ /** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
22
+ * and the harness's next call runs it. */
23
+ export declare const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool runs it on its next call.";
15
24
  /** A pause or resume row on an agentic run, refused in main's words (runs.ts pause): only a workflow run pauses. */
16
25
  export declare const AGENTIC_PAUSE_REFUSED = "Only a workflow run pauses here: an agentic run's turn is stopped with POST /runs/{id}/stop.";
17
26
  /** What a raise meets, as the kernel cap's checkRaise reads it (run-adapters/src/kernel/cap/park.ts): the run's cap, the
@@ -58,6 +67,9 @@ export type SpecGate = ((call: ToolCall, options?: {
58
67
  /** The revision's tool-call budget (definition.max_tool_calls, tool-budget.ts): the calls each conversation may make. A
59
68
  * call past it is refused before anything else is asked; one the adapter counts no calls for (a CLI's) is not held. */
60
69
  readonly toolCalls?: number;
70
+ /** A tool's setting now, by any name a call reaches the gate by (a harness's own, Codex's `web_search`), read again at
71
+ * each ask: what the session reads (SessionIO.permission) for a tool no call of which reaches the gate before it runs. */
72
+ readonly permission?: (tool: string) => Promise<"allow" | "ask" | "deny">;
61
73
  };
62
74
  /** What one claimed run's adapter loop runs. */
63
75
  export interface AdapterRunSpec {
@@ -139,10 +151,14 @@ export interface AdapterRunSpec {
139
151
  /** Handed the run's own Harness commit once it opens (and after each restart's re-open): what a mark of the run's
140
152
  * commits through, so a commit after the claim is lost is refused by the fence like any other. */
141
153
  readonly harnessReady?: (commit: Harness["commit"]) => void;
142
- /** The run's desktop or phone and the person's hold on it (workspace/computer-hold.ts): the loop commits the hold's
143
- * changes to the run's journal, which the server reads (computer-routes.ts), and applies the person's take-over and
144
- * hand-back rows to it (runner/computer-journal.ts). */
145
- readonly computer?: RunComputerHold;
154
+ /** The run's computer when it speaks the protocol (a sandbox, a desktop or a phone): the loop answers the computer call
155
+ * channel's rows on it (runner/computer-channel.ts). On a desktop or a phone, with the person's hold on it
156
+ * (workspace/computer-hold.ts): the loop commits the hold's changes to the run's journal, which the server reads
157
+ * (computer-routes.ts), and applies the person's take-over and hand-back rows to it (runner/computer-journal.ts). */
158
+ readonly computer?: LoopComputer;
159
+ /** The run's computer held for its owner (a run started with `hold: true`, computer-held.ts): the agent's first input
160
+ * waits for the owner's start, and the run's end waits for the owner's release (runner/held-run.ts). */
161
+ readonly held?: HeldSpec;
146
162
  /** Lets this spec's resources go once the loop writes nothing more through them: called once, after its Session and
147
163
  * Harness are closed, when its pass ends (a restart's included) and at the run's end. Never throws out: a failure is
148
164
  * logged, and the end stands. */