@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48

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 (292) hide show
  1. package/CHANGELOG.md +211 -1
  2. package/NOTICE +4 -0
  3. package/README.md +350 -53
  4. package/dist/acp-package.d.ts +53 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +3 -4
  7. package/dist/adapter-facts.js +4 -4
  8. package/dist/adapters.d.ts +3 -5
  9. package/dist/adapters.js +1 -31
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/answer-json.d.ts +10 -0
  13. package/dist/answer-json.js +24 -0
  14. package/dist/api-only.d.ts +11 -11
  15. package/dist/api-only.js +16 -11
  16. package/dist/archil-routes.js +2 -1
  17. package/dist/browser-live.d.ts +9 -4
  18. package/dist/browser-live.js +18 -5
  19. package/dist/cap.js +10 -2
  20. package/dist/chatgpt-plan.js +2 -1
  21. package/dist/cli.js +109 -41
  22. package/dist/composio-made.d.ts +19 -2
  23. package/dist/composio-made.js +17 -5
  24. package/dist/composio-preset.d.ts +42 -7
  25. package/dist/composio-preset.js +106 -70
  26. package/dist/composio-triggers.d.ts +9 -4
  27. package/dist/composio-triggers.js +20 -13
  28. package/dist/computer-attach.d.ts +11 -10
  29. package/dist/computer-attach.js +13 -14
  30. package/dist/computer-commands.d.ts +3 -0
  31. package/dist/computer-commands.js +3 -2
  32. package/dist/computer-lost.d.ts +4 -0
  33. package/dist/computer-lost.js +8 -3
  34. package/dist/computer-routes.d.ts +8 -5
  35. package/dist/computer-routes.js +7 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +2 -0
  38. package/dist/computers.d.ts +14 -76
  39. package/dist/computers.js +24 -68
  40. package/dist/conformance.d.ts +4 -0
  41. package/dist/conformance.js +6 -0
  42. package/dist/console/assets/index-CTGegcKt.css +1 -0
  43. package/dist/console/assets/index-D1Se6mgG.js +715 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/cost-heal.d.ts +13 -0
  46. package/dist/cost-heal.js +27 -0
  47. package/dist/dial-relay.d.ts +6 -2
  48. package/dist/dial-relay.js +9 -12
  49. package/dist/email/routes.js +2 -1
  50. package/dist/errors.d.ts +2 -0
  51. package/dist/errors.js +5 -0
  52. package/dist/exa-keyless.d.ts +1 -1
  53. package/dist/exa-keyless.js +1 -1
  54. package/dist/faux-computers.d.ts +2 -3
  55. package/dist/faux-computers.js +9 -31
  56. package/dist/github-connection.js +2 -1
  57. package/dist/harness-archive.d.ts +19 -2
  58. package/dist/harness-archive.js +49 -15
  59. package/dist/harness-check.d.ts +75 -0
  60. package/dist/harness-check.js +518 -0
  61. package/dist/harness-cursor.d.ts +28 -0
  62. package/dist/harness-cursor.js +42 -0
  63. package/dist/harness-goose.d.ts +4 -29
  64. package/dist/harness-goose.js +6 -86
  65. package/dist/harness-module.d.ts +4 -0
  66. package/dist/harness-module.js +1 -0
  67. package/dist/harness-owned.d.ts +52 -0
  68. package/dist/harness-owned.js +92 -0
  69. package/dist/harness-recipe.d.ts +127 -0
  70. package/dist/harness-recipe.js +335 -0
  71. package/dist/harness-table.d.ts +120 -5
  72. package/dist/harness-table.js +280 -6
  73. package/dist/harness.d.ts +2 -0
  74. package/dist/harness.js +5 -4
  75. package/dist/host-check.d.ts +6 -0
  76. package/dist/host-check.js +14 -0
  77. package/dist/host.d.ts +10 -3
  78. package/dist/host.js +17 -3
  79. package/dist/import-sources.d.ts +2 -0
  80. package/dist/import-sources.js +2 -0
  81. package/dist/import-summary.d.ts +15 -5
  82. package/dist/import-summary.js +24 -8
  83. package/dist/import.d.ts +24 -4
  84. package/dist/import.js +108 -26
  85. package/dist/key-refusal.d.ts +3 -1
  86. package/dist/key-refusal.js +26 -5
  87. package/dist/key-words.d.ts +1 -1
  88. package/dist/key-words.js +4 -4
  89. package/dist/learn/check.d.ts +3 -0
  90. package/dist/learn/check.js +31 -20
  91. package/dist/learn/compile.js +12 -5
  92. package/dist/learn/promote.d.ts +80 -2
  93. package/dist/learn/promote.js +95 -3
  94. package/dist/learn/secrets.d.ts +4 -0
  95. package/dist/learn/secrets.js +23 -0
  96. package/dist/learned-nodes.d.ts +4 -3
  97. package/dist/learned-workflow.js +4 -1
  98. package/dist/learning-cost.d.ts +6 -16
  99. package/dist/learning-cost.js +6 -12
  100. package/dist/learning-model.d.ts +18 -0
  101. package/dist/learning-model.js +77 -0
  102. package/dist/learning-words.d.ts +2 -0
  103. package/dist/learning-words.js +1 -1
  104. package/dist/listen-first.d.ts +10 -0
  105. package/dist/listen-first.js +25 -1
  106. package/dist/llms.txt +2 -1
  107. package/dist/mcp-gateway.d.ts +2 -1
  108. package/dist/mcp-gateway.js +31 -15
  109. package/dist/mcp-probe.d.ts +18 -6
  110. package/dist/mcp-probe.js +41 -8
  111. package/dist/mcp-secret-writes.d.ts +8 -0
  112. package/dist/mcp-secret-writes.js +104 -4
  113. package/dist/mcp-servers-store.d.ts +11 -5
  114. package/dist/mcp-servers-store.js +46 -20
  115. package/dist/model-form.d.ts +2 -1
  116. package/dist/model-form.js +30 -16
  117. package/dist/model-gateway.d.ts +113 -0
  118. package/dist/model-gateway.js +433 -0
  119. package/dist/model.d.ts +5 -3
  120. package/dist/model.js +26 -18
  121. package/dist/monid.js +1 -1
  122. package/dist/native/binding.d.ts +4 -0
  123. package/dist/native/binding.js +9 -0
  124. package/dist/native/cli.d.ts +3 -2
  125. package/dist/native/cli.js +6 -5
  126. package/dist/openapi.d.ts +2 -0
  127. package/dist/openapi.js +356 -43
  128. package/dist/owner.d.ts +4 -2
  129. package/dist/owner.js +10 -4
  130. package/dist/page.d.ts +9 -0
  131. package/dist/page.js +10 -2
  132. package/dist/port-models.js +17 -10
  133. package/dist/provider.d.ts +3 -3
  134. package/dist/provider.js +12 -3
  135. package/dist/public-address.d.ts +28 -0
  136. package/dist/public-address.js +62 -0
  137. package/dist/run-launch.d.ts +1 -1
  138. package/dist/run-launch.js +1 -1
  139. package/dist/run-secrets.d.ts +3 -2
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-trace.js +6 -3
  142. package/dist/runner/adapter-loop.d.ts +14 -8
  143. package/dist/runner/adapter-loop.js +58 -24
  144. package/dist/runner/adapter-run-spec.d.ts +15 -2
  145. package/dist/runner/adapter-run-spec.js +48 -10
  146. package/dist/runner/adapters/index.d.ts +4 -2
  147. package/dist/runner/adapters/index.js +6 -26
  148. package/dist/runner/adapters/pi.d.ts +5 -2
  149. package/dist/runner/adapters/pi.js +7 -4
  150. package/dist/runner/audit.d.ts +7 -0
  151. package/dist/runner/audit.js +15 -6
  152. package/dist/runner/claim-secrets.js +5 -1
  153. package/dist/runner/cli-run-spec.js +22 -10
  154. package/dist/runner/compare-end.d.ts +43 -0
  155. package/dist/runner/compare-end.js +95 -0
  156. package/dist/runner/computer-journal.d.ts +3 -0
  157. package/dist/runner/computer-journal.js +22 -2
  158. package/dist/runner/conformance/host-tools.d.ts +4 -0
  159. package/dist/runner/conformance/host-tools.js +14 -0
  160. package/dist/runner/harness-loops.d.ts +6 -1
  161. package/dist/runner/harness-loops.js +94 -54
  162. package/dist/runner/held.d.ts +5 -4
  163. package/dist/runner/journal-kinds.d.ts +4 -1
  164. package/dist/runner/journal-kinds.js +3 -0
  165. package/dist/runner/loop-contract.d.ts +10 -0
  166. package/dist/runner/main.d.ts +5 -5
  167. package/dist/runner/main.js +62 -11
  168. package/dist/runner/mcp-claim.js +40 -12
  169. package/dist/runner/meta-tools.js +4 -2
  170. package/dist/runner/metrics.d.ts +26 -0
  171. package/dist/runner/metrics.js +44 -1
  172. package/dist/runner/presence.d.ts +44 -0
  173. package/dist/runner/presence.js +96 -0
  174. package/dist/runner/promotion.d.ts +70 -7
  175. package/dist/runner/promotion.js +178 -28
  176. package/dist/runner/run-child-host.js +40 -10
  177. package/dist/runner/runner.d.ts +5 -0
  178. package/dist/runner/runner.js +8 -0
  179. package/dist/runner/sdk-loop.js +25 -1
  180. package/dist/runner/store-port.d.ts +3 -0
  181. package/dist/runner/store-secrets.js +19 -7
  182. package/dist/runner/workflow-first.d.ts +5 -2
  183. package/dist/runner/workflow-first.js +6 -3
  184. package/dist/runner/workflow-spec.js +3 -2
  185. package/dist/runs-over-store.d.ts +7 -2
  186. package/dist/runs-over-store.js +12 -4
  187. package/dist/sdk/check.d.ts +31 -0
  188. package/dist/sdk/check.js +58 -0
  189. package/dist/sdk/runs.d.ts +11 -3
  190. package/dist/sdk/runs.js +90 -15
  191. package/dist/sdk/schema.js +12 -4
  192. package/dist/secret-writes.d.ts +16 -3
  193. package/dist/secret-writes.js +28 -3
  194. package/dist/server-secrets-store.js +5 -0
  195. package/dist/server.d.ts +34 -2
  196. package/dist/server.js +437 -90
  197. package/dist/sign-ins-secrets.js +4 -1
  198. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  199. package/dist/slack-url.d.ts +5 -0
  200. package/dist/slack-url.js +11 -0
  201. package/dist/slack.d.ts +107 -0
  202. package/dist/slack.js +292 -0
  203. package/dist/start-switches.d.ts +28 -0
  204. package/dist/start-switches.js +37 -0
  205. package/dist/stats.d.ts +1 -1
  206. package/dist/stats.js +2 -1
  207. package/dist/stop-signals.d.ts +11 -0
  208. package/dist/stop-signals.js +22 -0
  209. package/dist/store/agent-body.d.ts +1 -1
  210. package/dist/store/agent-body.js +2 -2
  211. package/dist/store/index.d.ts +3 -3
  212. package/dist/store/index.js +1 -1
  213. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  214. package/dist/store/postgres/store.d.ts +1 -1
  215. package/dist/store/postgres/store.js +4 -2
  216. package/dist/store/schema.d.ts +13 -5
  217. package/dist/store/schema.js +20 -11
  218. package/dist/store/seal.d.ts +16 -4
  219. package/dist/store/sqlite/store.d.ts +1 -1
  220. package/dist/store/sqlite/store.js +112 -28
  221. package/dist/store/store.d.ts +78 -24
  222. package/dist/store/store.js +11 -0
  223. package/dist/store-reads/analytics.js +3 -2
  224. package/dist/store-reads/cap.d.ts +7 -0
  225. package/dist/store-reads/cap.js +11 -1
  226. package/dist/store-reads/journal.js +27 -1
  227. package/dist/store-reads/learning.d.ts +23 -2
  228. package/dist/store-reads/learning.js +29 -8
  229. package/dist/store-reads/runs.d.ts +9 -0
  230. package/dist/store-reads/runs.js +19 -6
  231. package/dist/store-reads/stats.d.ts +4 -1
  232. package/dist/store-reads/stats.js +15 -6
  233. package/dist/store-view.d.ts +125 -14
  234. package/dist/store-view.js +156 -21
  235. package/dist/telemetry.d.ts +7 -7
  236. package/dist/telemetry.js +38 -15
  237. package/dist/template-eval.js +5 -2
  238. package/dist/template-github-permissions.d.ts +5 -1
  239. package/dist/template-github-permissions.js +7 -3
  240. package/dist/timeline/index.d.ts +1 -1
  241. package/dist/timeline/index.js +1 -1
  242. package/dist/timeline/timeline.d.ts +8 -0
  243. package/dist/timeline/timeline.js +30 -0
  244. package/dist/tool-gate.d.ts +8 -4
  245. package/dist/tool-gate.js +6 -7
  246. package/dist/tool-keys-store.js +2 -2
  247. package/dist/tool-keys.js +2 -1
  248. package/dist/tool-plane.d.ts +4 -0
  249. package/dist/tool-plane.js +12 -12
  250. package/dist/trigger-adapter.d.ts +3 -4
  251. package/dist/trigger-adapter.js +2 -2
  252. package/dist/trigger-composio.js +3 -3
  253. package/dist/trigger-email.js +0 -2
  254. package/dist/trigger-feed.js +0 -2
  255. package/dist/trigger-schedule.js +3 -0
  256. package/dist/trigger-secrets-shown.d.ts +6 -3
  257. package/dist/trigger-secrets-shown.js +22 -13
  258. package/dist/trigger-targets.d.ts +12 -3
  259. package/dist/trigger-targets.js +90 -10
  260. package/dist/triggers.d.ts +2 -2
  261. package/dist/validate.js +5 -1
  262. package/dist/viewer-credential.d.ts +25 -0
  263. package/dist/viewer-credential.js +51 -0
  264. package/dist/webhooks.d.ts +82 -8
  265. package/dist/webhooks.js +128 -45
  266. package/dist/wires.d.ts +6 -1
  267. package/dist/wires.js +5 -0
  268. package/dist/workspace/attach.d.ts +3 -2
  269. package/dist/workspace/attach.js +2 -1
  270. package/dist/workspace/attached-computers.d.ts +6 -8
  271. package/dist/workspace/attached-computers.js +27 -24
  272. package/dist/workspace/computer-deps.d.ts +2 -3
  273. package/dist/workspace/computer-deps.js +3 -6
  274. package/dist/workspace/computer-for-claim.js +72 -96
  275. package/dist/workspace/computer-kept.d.ts +0 -7
  276. package/dist/workspace/computer-kept.js +0 -17
  277. package/dist/workspace/resolve-computer.d.ts +23 -14
  278. package/dist/workspace/resolve-computer.js +66 -61
  279. package/dist/workspace/synced-folder.d.ts +20 -15
  280. package/dist/workspace/synced-folder.js +33 -43
  281. package/launcher/agentrun-serve +4 -1
  282. package/package.json +18 -10
  283. package/skills/agentrun-serve/SKILL.md +11 -0
  284. package/templates/README.md +1 -1
  285. package/templates/code-review/agent.md +2 -3
  286. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  287. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  288. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  289. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  290. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  291. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  292. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -12,13 +12,15 @@ import { join, resolve } from "node:path";
12
12
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
13
13
  import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
14
14
  import { facts as openCodeFacts } from "./harness-opencode/facts.js";
15
- import { GOOSE_FACTS } from "./adapter-facts.js";
16
- import { gooseHidden } from "./harness-goose.js";
15
+ import { CURSOR_FACTS, GOOSE_FACTS } from "./adapter-facts.js";
16
+ import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
17
+ import { gooseHidden, gooseMissing } from "./harness-goose.js";
18
+ import { CURSOR_DEFAULT_MODEL, CURSOR_KEY, cursorCardOf, cursorHidden, cursorLimitsOf, cursorMissing } from "./harness-cursor.js";
17
19
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
18
20
  import { HARNESS_INSTALLS } from "./harness-install.js";
19
21
  import { chooseModel } from "./model.js";
20
22
  import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
21
- import { WIRES } from "./wires.js";
23
+ import { modelWire, wireOf, WIRES } from "./wires.js";
22
24
  import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
23
25
  /** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
24
26
  export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
@@ -64,6 +66,9 @@ const onOpenRouter = (id, vendor) => new RegExp(`^openrouter/${vendor}/[^/]+$`).
64
66
  /** An adapter harness's entry, from its facts and the factory that builds its adapter. */
65
67
  function adapterEntry(facts, make, extra = {}) {
66
68
  const { wire, id } = facts;
69
+ // A harness billed to its own plan is acpEntryOf's plan-billed entry (Cursor's): this one is for a model wire of ours.
70
+ if (!modelWire(wire))
71
+ throw new Error(`${id} is billed to its own plan, so its table entry is its own, never adapterEntry's`);
67
72
  const { vendor, gateway } = WIRES[wire];
68
73
  const installs = HARNESS_INSTALLS[id];
69
74
  const onPlan = PLAN_HARNESSES.includes(id);
@@ -113,6 +118,247 @@ function adapterEntry(facts, make, extra = {}) {
113
118
  };
114
119
  return Object.freeze(entry);
115
120
  }
121
+ /** An adapter harness's adapter for one run, from `facts` and its builder: the launch serve chooses for the run's model
122
+ * on this server's keys (providerFor, priceOf). A module's, and the built-in Goose's. An error `missing` or the builder
123
+ * throws is a HarnessUnavailable with the fix its code names in the facts (fixOf: install, pins). */
124
+ function moduleAdapter(facts, build, { missing }, host = {}) {
125
+ return async (env, needs) => {
126
+ const { fixOf, harnessLog, priceOf } = await import("./adapters.js");
127
+ const unavailable = (error) => (error instanceof HarnessUnavailable ? error : new HarnessUnavailable(error.message, fixOf(facts, error)));
128
+ // What no key fixes is said first (a binary): a refusal for it names no key.
129
+ let lacks;
130
+ try {
131
+ lacks = await missing?.(env);
132
+ }
133
+ catch (error) {
134
+ throw unavailable(error);
135
+ }
136
+ if (lacks)
137
+ throw new HarnessUnavailable(lacks);
138
+ const provider = providerFor(facts.wire, env, needs.model, facts.id);
139
+ // A person's Claude Code login is its CLI's alone (claude-login.ts): no request of this harness goes on it; a key of
140
+ // its wire's vendor's, or OpenRouter's, runs it.
141
+ if (provider.login)
142
+ throw new HarnessUnavailable(`${facts.label} runs on a model key: Claude Code's login on this machine is its CLI's alone.`, undefined, [wireOf(facts.wire).key, "OPENROUTER_API_KEY"]);
143
+ try {
144
+ return await build({
145
+ model: provider.modelId,
146
+ provider: { origin: provider.origin, credential: provider.credential, ...(provider.auth ? { auth: provider.auth } : {}) },
147
+ price: priceOf({ ...needs, model: provider.priceModel }),
148
+ log: host.log ?? harnessLog(facts.id, env),
149
+ ...(needs.confine ? { confine: needs.confine } : {}),
150
+ ...(needs.skills?.length ? { skills: needs.skills } : {}),
151
+ env,
152
+ });
153
+ }
154
+ catch (error) {
155
+ throw unavailable(error);
156
+ }
157
+ };
158
+ }
159
+ /** `recipe`, once its `keys` name no key this server holds for something else (harness-recipe.ts serverKey, the
160
+ * loader's rule 1) but its own built-in harness's (builtinOwns: Cursor's CURSOR_API_KEY). Its keys are read from the
161
+ * launch's environment, where a server key is readable by name, and a module's or a check's recipe is not the loader's:
162
+ * checked as each launch's recipe is made, before its agent starts, so the harness's offer at start says it. */
163
+ async function ownKeysOnly(facts, recipe) {
164
+ const { RECIPE_CODES, serverKey } = await import("./harness-recipe.js");
165
+ const named = (recipe.keys ?? []).filter((name) => serverKey(name) && !builtinOwns(facts.id, name));
166
+ if (named.length)
167
+ throw new HarnessUnavailable(`${RECIPE_CODES.keys}: ${facts.label}'s recipe names ${named.join(", ")} in keys, a key this server holds for something else; a recipe names only keys saved for its own harness.`);
168
+ return recipe;
169
+ }
170
+ /** The runner of an entry run on serve's table (its facts' adapter, cli-run-spec.ts), never by a runner's adapter of its
171
+ * own: a module's, and Goose's and Cursor's (resolveHarness). Its adapter says so if it is ever asked. The loop keeps the
172
+ * run's record, as for every CLI harness. */
173
+ export const ON_TABLE = Object.freeze({
174
+ record: "loop",
175
+ adapter: async () => {
176
+ throw new Error("this harness runs from its table entry (facts and adapter), not a runner adapter");
177
+ },
178
+ });
179
+ /** What an ACP harness promises by default: a resume by the agent's session/load, tool calls through its permission asks,
180
+ * its model through the session's proxy (Goose's). */
181
+ const ACP_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "proxy" });
182
+ /** As ACP_PROMISES, with a resume by a new session given the conversation so far: a module's ACP agent's, unless it
183
+ * says "load" (AcpEntryOptions.resume). */
184
+ const ACP_RESTART_PROMISES = Object.freeze({ ...ACP_PROMISES, resume: "restart" });
185
+ /** The code a module's ACP entry is refused by at its first launch when it promises resume "load" and its recipe
186
+ * declares no session/load (AcpEntryOptions.resume). */
187
+ export const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
188
+ /** An adapter harness's whole entry over the builder of its adapter for one run (moduleAdapter), run from the table
189
+ * (ON_TABLE): a module's (HarnessModuleKit.adapterEntry, which takes no `hidden`) and the built-in Goose's. */
190
+ const moduleEntryOf = (facts, adapter, { missing, ...extra } = {}, host = {}) => Object.freeze({ ...adapterEntry(facts, moduleAdapter(facts, adapter, missing ? { missing } : {}, host), extra), runner: ON_TABLE });
191
+ /** A proxy-billed ACP agent's whole entry, moduleEntryOf over serve's own ACP adapter: a module's (HarnessModuleKit.acpEntry,
192
+ * `host` none) and a proxy-billed recipe's under harness-check (AcpEntryHost). Its agent's allowlist and keys are read
193
+ * from the launch's environment, never this process's, and its recipe names no server key (ownKeysOnly). */
194
+ function acpProxyEntryOf(options, host = {}) {
195
+ const { facts, resume = "restart" } = options;
196
+ return moduleEntryOf(facts, async (launch) => {
197
+ const acp = acpPackage();
198
+ if (!acp)
199
+ throw new HarnessUnavailable(`${facts.label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
200
+ const recipe = await ownKeysOnly(facts, options.recipe(launch));
201
+ // Promising less than the recipe declares is allowed; promising a session/load the agent is never asked for is not.
202
+ if (resume === "load" && !recipe.declares.load)
203
+ throw new HarnessUnavailable(`${HARNESS_RESUME_UNDECLARED}: ${facts.label} (${facts.id}) promises resume "load", but its recipe's declares.load is false, so its run would restart instead: declare session/load in the recipe, or leave resume at "restart".`);
204
+ return acp.acpAdapter({
205
+ recipe,
206
+ proxy: options.proxy(launch),
207
+ ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}),
208
+ ...(launch.confine ? { confine: launch.confine } : {}),
209
+ env: launch.env,
210
+ log: launch.log,
211
+ });
212
+ }, { promises: resume === "load" ? ACP_PROMISES : ACP_RESTART_PROMISES, ...(options.missing ? { missing: options.missing } : {}) }, host);
213
+ }
214
+ /** What a plan-billed ACP harness promises: as ACP_PROMISES, billed to its owner's plan. */
215
+ const ACP_PLAN_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "plan" });
216
+ /** The model id of a plan-billed agent's own default (`<id>/default`). */
217
+ const PLAN_DEFAULT_MODEL = "default";
218
+ /** A plan-billed ACP agent's whole entry: its models are the ones its vendor lists for its owner, named `<id>/<model-id>`
219
+ * (`<id>/default`: the vendor's own default), checked against that list when its session opens (ACP_MODEL_UNLISTED);
220
+ * no model key, route, proxy, catalog or price of ours is its, and it has no runner adapter of a module's (ON_TABLE). */
221
+ function acpPlanEntryOf(options, host = {}) {
222
+ const { facts } = options;
223
+ const { id, label } = facts;
224
+ if (modelWire(facts.wire))
225
+ throw new Error(`${id} runs on a model wire of ours, so its ACP entry is the proxy-billed one`);
226
+ const prefix = `${id}/`;
227
+ const make = async (env, needs) => {
228
+ const { fixOf, harnessLog } = await import("./adapters.js");
229
+ // What no key fixes is said first, as for the built-in harnesses' binaries.
230
+ const lacks = await options.missing?.(env);
231
+ if (lacks)
232
+ throw new HarnessUnavailable(lacks);
233
+ const acp = acpPackage();
234
+ if (!acp)
235
+ throw new HarnessUnavailable(`${label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
236
+ if (needs.model.provider !== id)
237
+ throw new HarnessUnavailable(`${label} runs ${label}'s models, named ${prefix}<model-id>; the run's model is ${needs.model.provider}/${needs.model.modelId}.`);
238
+ const log = host.log ?? harnessLog(id, env);
239
+ try {
240
+ const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env }));
241
+ // Its keys (recipe.keys) are read from the run's environment, which holds its own (ownKeys: run-secrets.ts keysFor).
242
+ return acp.acpAdapter({ recipe, ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}), ...(needs.confine ? { confine: needs.confine } : {}), env, log });
243
+ }
244
+ catch (error) {
245
+ if (error instanceof HarnessUnavailable)
246
+ throw error;
247
+ throw new HarnessUnavailable(error.message, fixOf(facts, error));
248
+ }
249
+ };
250
+ const entry = {
251
+ id,
252
+ label,
253
+ steer: facts.steer,
254
+ runMib: facts.runMib,
255
+ oneAlwaysFits: false,
256
+ facts,
257
+ promises: ACP_PLAN_PROMISES,
258
+ ...(options.ownKeys ? { ownKeys: Object.freeze([...options.ownKeys]) } : {}),
259
+ ...(options.hidden ? { hidden: options.hidden } : {}),
260
+ ...(options.card ? { card: options.card } : {}),
261
+ runs: (_env, model) => model.startsWith(prefix),
262
+ onWire: () => true,
263
+ model: async (_env, ref, available) => {
264
+ if (!available)
265
+ return undefined;
266
+ const named = ref ?? `${prefix}${PLAN_DEFAULT_MODEL}`;
267
+ const modelId = named.startsWith(prefix) ? named.slice(prefix.length) : "";
268
+ if (!modelId || !acpPackage()?.MODEL_ID.test(modelId))
269
+ return { why: `${label} runs a model ${label} lists for your ${label} API key, named ${prefix}<model-id> (${prefix}${PLAN_DEFAULT_MODEL} for ${label}'s own default); ${named} is not one.`, host: false, needs: "model" };
270
+ return { model: { provider: id, modelId } };
271
+ },
272
+ priceModel: (_env, model) => model,
273
+ adapter: make,
274
+ refusal: async (env, given, { atStart }) => {
275
+ const { startReason } = await import("./adapters.js");
276
+ try {
277
+ const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } });
278
+ const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
279
+ return problems.length ? { reason: problems.join(" ") } : undefined;
280
+ }
281
+ catch (error) {
282
+ return { reason: atStart ? startReason(error) : error.message };
283
+ }
284
+ },
285
+ };
286
+ return Object.freeze(entry);
287
+ }
288
+ export function acpEntryOf(options, host = {}) {
289
+ return modelWire(options.facts.wire) ? acpProxyEntryOf(options, host) : acpPlanEntryOf(options, host);
290
+ }
291
+ /** The kit a harness module is handed (HarnessModuleKit): never a host's log (AcpEntryHost), so its launches log as
292
+ * their harness. */
293
+ const MODULE_KIT = Object.freeze({
294
+ adapterEntry: (facts, adapter, extra) => moduleEntryOf(facts, adapter, extra),
295
+ acpEntry: (options) => acpProxyEntryOf(options),
296
+ });
297
+ /** Why Goose cannot run here (harness-owned.ts `missing`: not installed, or not the pinned binary) as an error of its
298
+ * code, so moduleAdapter refuses it with the install fix its facts name. */
299
+ const gooseRefused = (missing) => Object.assign(new Error(missing.message), { code: missing.code });
300
+ /** Goose's adapter for one run (moduleAdapter's builder, after its `missing`): its package's gooseAdapter on the binary
301
+ * its owner installed into the data's harnesses directory (`agentrun harness install goose`) and from nowhere else,
302
+ * looked up and verified again (its sha256 is kept per file identity, so only the first look reads it). Its model goes
303
+ * where claude-agent's does, the host's Anthropic Messages provider, through a model proxy of its own. */
304
+ async function gooseLaunch(launch) {
305
+ const found = await gooseMissing(launch.env);
306
+ if ("missing" in found)
307
+ throw gooseRefused(found.missing);
308
+ return acpPackage().gooseAdapter({
309
+ binary: found.binary, sha256: found.sha256, model: launch.model, provider: launch.provider, price: launch.price, log: launch.log,
310
+ ...(launch.confine ? { confine: launch.confine } : {}),
311
+ });
312
+ }
313
+ /** What Cursor gives acpEntryOf for its plan-billed entry: billed to its owner's Cursor plan on the owner's Cursor API key
314
+ * (`ownKeys`), its model one Cursor lists for that key (`cursor/<model-id>`, `cursor/default` for Cursor's own). Listed
315
+ * only once its owner has installed it (`agentrun harness install cursor`): `missing` is its release, looked up and
316
+ * verified (harness-cursor.ts cursorMissing), and `beforeStart` checks its launcher and every file beside it again
317
+ * before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says. */
318
+ function cursorOptions(facts) {
319
+ /** Cursor's launcher, or the HarnessUnavailable that says why it is not here, with the fix (install, pins) it names. */
320
+ const launcher = async (env) => {
321
+ const found = await cursorMissing(env);
322
+ if (!("missing" in found))
323
+ return found.binary;
324
+ const { fixOf } = await import("./adapters.js");
325
+ throw new HarnessUnavailable(found.missing.message, fixOf(facts, found.missing));
326
+ };
327
+ return {
328
+ facts,
329
+ ownKeys: [CURSOR_KEY],
330
+ hidden: cursorHidden,
331
+ card: cursorCardOf,
332
+ missing: async (env) => void (await launcher(env)),
333
+ recipe: async (launch) => {
334
+ if (!launch.env[CURSOR_KEY])
335
+ throw new HarnessUnavailable(`${facts.label} runs on your Cursor API key, and ${CURSOR_KEY} is not set where AgentRun starts: set it there (it is handed to Cursor's runs alone), then restart AgentRun.`);
336
+ const acp = acpPackage();
337
+ let limits;
338
+ try {
339
+ limits = cursorLimitsOf(acp, launch.env);
340
+ }
341
+ catch (error) {
342
+ throw new HarnessUnavailable(error.message);
343
+ }
344
+ const model = launch.model === CURSOR_DEFAULT_MODEL ? undefined : launch.model;
345
+ return acp.cursorRecipe({ command: await launcher(launch.env), limits, ...(model ? { model } : {}) });
346
+ },
347
+ beforeStart: async (command) => {
348
+ const acp = acpPackage();
349
+ const release = acp.pinnedRelease(acp.CURSOR_PIN, acp.acpPlatform(), true);
350
+ const root = release && acp.cursorRootOf(command, release.cmd);
351
+ // The launcher is the one cursorMissing found at its pinned path: a release or folder lost since is refused.
352
+ if (!release?.treeSha256 || !root)
353
+ throw new Error(`ACP_BINARY_MISMATCH: the Cursor launcher at ${command} is not at its pinned path inside its folder`);
354
+ // The tree's digest covers every file it runs, the launcher among them (as cursorAdapter's check does).
355
+ await acp.verifyPinnedTree(root, release.treeSha256);
356
+ },
357
+ };
358
+ }
359
+ /** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
360
+ * server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
361
+ export const BUILTIN_OWN_KEYS = Object.freeze([CURSOR_KEY]);
116
362
  /** The harnesses this server runs, by id. */
117
363
  const BUILTIN = Object.freeze({
118
364
  [DEFAULT_HARNESS]: PI,
@@ -135,12 +381,32 @@ const BUILTIN = Object.freeze({
135
381
  // Goose, over ACP, where its package is beside serve (acp-package.ts): its owner installs its pinned binary
136
382
  // (`agentrun harness install goose`, harness-goose.ts), never a run; listed only once it is installed and verified.
137
383
  ...(GOOSE_FACTS ? {
138
- [GOOSE_FACTS.id]: adapterEntry(GOOSE_FACTS, async (env, needs) => (await import("./adapters.js")).gooseOf(env, needs), {
139
- promises: Object.freeze({ resume: "load", tool_gate: "permission", billing: "proxy" }),
384
+ [GOOSE_FACTS.id]: moduleEntryOf(GOOSE_FACTS, gooseLaunch, {
385
+ missing: async (env) => {
386
+ const found = await gooseMissing(env);
387
+ if ("missing" in found)
388
+ throw gooseRefused(found.missing);
389
+ return undefined;
390
+ },
391
+ promises: ACP_PROMISES,
140
392
  hidden: gooseHidden,
141
393
  }),
142
394
  } : {}),
395
+ // Cursor, over ACP, where the same package is beside serve: its owner installs its pinned release (`agentrun harness
396
+ // install cursor`, harness-cursor.ts) and sets CURSOR_API_KEY; listed only once it is installed and verified.
397
+ ...(CURSOR_FACTS ? { [CURSOR_FACTS.id]: acpEntryOf(cursorOptions(CURSOR_FACTS)) } : {}),
143
398
  });
399
+ /** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
400
+ * needs it too): a recipe or module never takes one (harness-recipe.ts). */
401
+ export const BUILTIN_HARNESS_IDS = Object.freeze(Object.keys(BUILTIN));
402
+ /** Whether built-in harness `id` owns secret `key`: its own built-in entry names it in ownKeys. By the pair, so a key one
403
+ * built-in owns never crosses to another built-in, a module's entry or a test's; and none is owned where its harness's
404
+ * package is not beside serve (run-secrets.ts keysFor). */
405
+ export function builtinOwns(id, key) {
406
+ return Object.hasOwn(BUILTIN, id) && BUILTIN[id].ownKeys?.includes(key) === true;
407
+ }
408
+ /** The code a harness module's entry is refused by when its ownKeys names a key a built-in harness owns (BUILTIN_OWN_KEYS). */
409
+ export const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
144
410
  const loaded = new Map();
145
411
  const requireHere = createRequire(import.meta.url);
146
412
  /** The members a harness module's new entry gives: what the table's readers ask of every entry. */
@@ -150,7 +416,7 @@ function entriesOf(path, named) {
150
416
  const module = requireHere(resolve(path));
151
417
  if (typeof module.entries !== "function")
152
418
  throw new Error(`${named} names ${path}, which exports no entries(builtins)`);
153
- return module.entries(BUILTIN);
419
+ return module.entries(BUILTIN, MODULE_KIT);
154
420
  }
155
421
  /** The harness modules `env` names (HARNESS_MODULES_ENV): none when it names none. */
156
422
  function modulesOf(env) {
@@ -196,6 +462,9 @@ export function harnessTable(env) {
196
462
  const missing = WHOLE.filter((member) => entry[member] === undefined);
197
463
  if (missing.length)
198
464
  throw new Error(`harness module ${module}: its entry ${id} lacks ${missing.join(", ")}`);
465
+ const owned = (entry.ownKeys ?? []).filter((key) => BUILTIN_OWN_KEYS.includes(key));
466
+ if (owned.length)
467
+ throw Object.assign(new Error(`${HARNESS_KEY_OWNED}: harness module ${module}: its entry ${id} names ${owned.join(", ")} in ownKeys, a key a built-in harness owns and is handed alone: a module's harness takes none of ${BUILTIN_OWN_KEYS.join(", ")}`), { code: HARNESS_KEY_OWNED });
199
468
  built[id] = Object.freeze({ ...entry, id });
200
469
  }
201
470
  }
@@ -248,6 +517,11 @@ export const ownerHarness = (env, id) => {
248
517
  const key = id ?? DEFAULT_HARNESS;
249
518
  return Object.hasOwn(table, key) ? table[key] : undefined;
250
519
  };
520
+ /** The facts of harness `id`'s adapter on the owner's table (ownerTable: the built-in harnesses and those `env`'s modules
521
+ * add, never a test table's, so a stand-in keeps the facts of the harness it stands in for). Every reader of a harness's
522
+ * facts by id asks here: its models (model-form.ts), its key rows (model.ts), its search and tool names (tool-plane.ts,
523
+ * tool-gate.ts). Undefined for pi, for a module's harness that gives none, and for an id the table has none of. */
524
+ export const factsOf = (env, id) => ownerHarness(env, id)?.facts;
251
525
  /** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
252
526
  export const harnessOf = (env, id) => harnessTable(env)[id ?? DEFAULT_HARNESS];
253
527
  /** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
package/dist/harness.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare const PLAN_HARNESSES: readonly string[];
27
27
  * (or the first agent made on it) installs it (harness-install.ts). */
28
28
  /** `id`: one of the table's (harness-table.ts harnessIds): a built-in one (HARNESSES) or one an owner's harness module adds.
29
29
  * `label`: its name in a sentence. `promises`: what it promises (HarnessPromises), as capabilities show it. */
30
+ /** `card`: what its owner reads before running it (HarnessEntry.card: Cursor's, billed to the owner's plan). */
30
31
  export type HarnessOffer = {
31
32
  id: string;
32
33
  label: string;
@@ -37,6 +38,7 @@ export type HarnessOffer = {
37
38
  default_model?: string | null;
38
39
  keys?: readonly string[];
39
40
  installs?: "on_first_use";
41
+ card?: string;
40
42
  };
41
43
  /** A harness as capabilities list it: an offer with its `default_model` resolved (harnessOffers), never left out, and
42
44
  * the memory a run of it reserves (`run_memory_mib`). */
package/dist/harness.js CHANGED
@@ -11,7 +11,7 @@ export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
11
11
  * runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
12
12
  * (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
13
13
  export const RESERVED_HARNESS_IDS = Object.freeze([
14
- "learning", "sdk", "workflow", "claude-agent-sdk", "codex-sdk",
14
+ "learning", "sdk", "workflow", "claude-agent-sdk", "codex-sdk", "eve",
15
15
  ...Object.getOwnPropertyNames(Object.prototype).filter((name) => new RegExp(HARNESS_ID_PATTERN).test(name)),
16
16
  ]);
17
17
  /** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
@@ -42,7 +42,8 @@ export function harnessOffers(env) {
42
42
  const { harnessIds, harnessOf, NATIVE_PROMISES } = await import("./harness-table.js");
43
43
  const probed = await Promise.all(harnessIds(env).map(async (id) => {
44
44
  const entry = harnessOf(env, id);
45
- const named = { label: entry.label, promises: entry.promises ?? NATIVE_PROMISES };
45
+ const card = entry.card?.(env);
46
+ const named = { label: entry.label, promises: entry.promises ?? NATIVE_PROMISES, ...(card ? { card } : {}) };
46
47
  // The start's probe: these offers hold until a restart (server.ts), so the reason says so where installing fixes it.
47
48
  // Claude Code not installed yet says so (its install probes the offers again).
48
49
  const firstUse = entry.installs && !(await harnessInstalled(entry, env)) ? { installs: "on_first_use" } : {};
@@ -85,9 +86,9 @@ export function harnessOffers(env) {
85
86
  // lacks only a key is (a save warns of that, never refuses).
86
87
  const { MODEL_REF } = await import("./validate.js");
87
88
  const { providerFor, HarnessUnavailable } = await import("./provider.js");
88
- const { adapterFactsOf } = await import("./adapter-facts.js");
89
89
  const { FAUX_ENV } = await import("./model.js");
90
- const facts = adapterFactsOf(offer.id);
90
+ const { factsOf } = await import("./harness-table.js");
91
+ const facts = factsOf(env, offer.id);
91
92
  for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
92
93
  if (!MODEL_REF.test(id))
93
94
  continue;
@@ -11,3 +11,9 @@ export declare const hostFix: (port: number) => string;
11
11
  /** The page a browser gets for a refused Host: fixed text, under the console's CSP (page.ts). Its addresses carry no
12
12
  * scheme: a published package names no loopback URL (scripts/verify-packages.mjs). */
13
13
  export declare const hostRefusedPage: (port: number) => string;
14
+ /** What a script that sends a request under the server's earlier public address is told (public-address.ts): where it is
15
+ * now, `to`, the address its operator set. */
16
+ export declare const movedFix: (to: string) => string;
17
+ /** The page a browser gets for a page other than the console's, under the server's earlier public address: fixed text and
18
+ * the new address `to`, under the console's CSP. */
19
+ export declare const movedPage: (to: string) => string;
@@ -33,3 +33,17 @@ export const hostRefusedPage = (port) => `<!doctype html>
33
33
  <p>To serve it at a name of its own (behind HTTPS, for example), start it with <code>AGENTRUN_PUBLIC_URL=https://&lt;name&gt;</code>, or add the name with <code>--allow-host &lt;name&gt;</code>.</p>
34
34
  </body></html>
35
35
  `;
36
+ /** What a script that sends a request under the server's earlier public address is told (public-address.ts): where it is
37
+ * now, `to`, the address its operator set. */
38
+ export const movedFix = (to) => `this server's public address changed to ${to} (AGENTRUN_PUBLIC_URL); send requests there`;
39
+ const escaped = (text) => text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
40
+ /** The page a browser gets for a page other than the console's, under the server's earlier public address: fixed text and
41
+ * the new address `to`, under the console's CSP. */
42
+ export const movedPage = (to) => `<!doctype html>
43
+ <html lang="en"><head><meta charset="utf-8"><title>AgentRun moved</title></head>
44
+ <body>
45
+ <h1>AgentRun moved</h1>
46
+ <p>This AgentRun server's public address changed. Open it at <a href="${escaped(to)}/">${escaped(to)}</a>.</p>
47
+ <p>Sign in again there: a sign-in at the earlier address does not carry over. Links in earlier webhook messages still name the earlier address.</p>
48
+ </body></html>
49
+ `;
package/dist/host.d.ts CHANGED
@@ -30,19 +30,26 @@ export declare function neverFits(harness: string, memory: number, env?: NodeJS.
30
30
  /** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. A runner
31
31
  * holds at most this many; a run past it waits queued, never refused for a place. */
32
32
  export declare function maxRunsOf(env: NodeJS.ProcessEnv, given?: number): number;
33
+ /** The server's health. `degraded`: it serves, and every runner here refused to claim any run (`checks.runner` refused,
34
+ * `runner_refused` their words, runner/presence.ts); answered 200 like ok, since a platform whose health check restarts a
35
+ * service it reads as down would restart it in a loop, and a restart changes no runner's setting. `failing` (503) is the
36
+ * store or the disk. */
33
37
  export type Health = {
34
- status: "ok" | "failing";
38
+ status: "ok" | "degraded" | "failing";
35
39
  checks: {
36
40
  store: "ok" | "does_not_open";
37
41
  disk: "ok" | "below_floor" | "cannot_check";
42
+ runner?: "refused";
38
43
  };
44
+ runner_refused?: string;
39
45
  };
40
46
  /** How long health waits for the store's one read before it reads as failing (ms). */
41
47
  export declare const HEALTH_STORE_MS = 2000;
42
48
  /** Whether the server's store (`store`, the one it opened: SQLite in the data directory, or Postgres when
43
49
  * AGENTRUN_STORE_URL names one) answers one read within HEALTH_STORE_MS, and the data directory's disk has
44
50
  * `minFreeBytes` free; a disk it cannot measure fails. Says no path and no number. `fsStat` is node's statfs unless a
45
- * test gives another. */
46
- export declare function healthOf(store: Pick<Store, "agents">, data: string, minFreeBytes: number, fsStat?: typeof statfs): Promise<Health>;
51
+ * test gives another. `refused`: why no runner here can take a run (runner/presence.ts runnersRefused), read only when
52
+ * the store answered; health is then degraded, with a runner check that says so and their words. */
53
+ export declare function healthOf(store: Pick<Store, "agents">, data: string, minFreeBytes: number, fsStat?: typeof statfs, refused?: () => Promise<string | undefined>): Promise<Health>;
47
54
  /** Whether `--open` opens a browser here: not in CI, and on Linux or FreeBSD only with a display. */
48
55
  export declare const canOpen: (env: NodeJS.ProcessEnv, platform?: NodeJS.Platform) => boolean;
package/dist/host.js CHANGED
@@ -66,10 +66,12 @@ export const HEALTH_STORE_MS = 2_000;
66
66
  /** Whether the server's store (`store`, the one it opened: SQLite in the data directory, or Postgres when
67
67
  * AGENTRUN_STORE_URL names one) answers one read within HEALTH_STORE_MS, and the data directory's disk has
68
68
  * `minFreeBytes` free; a disk it cannot measure fails. Says no path and no number. `fsStat` is node's statfs unless a
69
- * test gives another. */
70
- export async function healthOf(store, data, minFreeBytes, fsStat = statfs) {
69
+ * test gives another. `refused`: why no runner here can take a run (runner/presence.ts runnersRefused), read only when
70
+ * the store answered; health is then degraded, with a runner check that says so and their words. */
71
+ export async function healthOf(store, data, minFreeBytes, fsStat = statfs, refused) {
71
72
  let answered = "ok";
72
73
  let timer;
74
+ const deadline = Date.now() + HEALTH_STORE_MS;
73
75
  try {
74
76
  // One indexed read of an id no agent has: the store's own connection, never a second open of a file.
75
77
  const read = whenFree(() => store.agents.get("health-check"), REQUEST_BUSY_MS);
@@ -86,7 +88,19 @@ export async function healthOf(store, data, minFreeBytes, fsStat = statfs) {
86
88
  }
87
89
  const free = await fsStat(data).then((fs) => fs.bavail * fs.bsize, () => undefined);
88
90
  const disk = free === undefined ? "cannot_check" : free >= minFreeBytes ? "ok" : "below_floor";
89
- return { status: answered === "ok" && disk === "ok" ? "ok" : "failing", checks: { store: answered, disk } };
91
+ if (answered !== "ok" || disk !== "ok")
92
+ return { status: "failing", checks: { store: answered, disk } };
93
+ // The runners' read within what is left of the same HEALTH_STORE_MS: one that does not answer in time is not read (ok),
94
+ // so health never waits on a store that answered once and is now slow (a pool filled between the two reads).
95
+ let words;
96
+ if (refused) {
97
+ const read = refused();
98
+ read.catch(() => undefined);
99
+ words = await Promise.race([read, new Promise((resolve) => {
100
+ timer = setTimeout(resolve, Math.max(0, deadline - Date.now()), undefined);
101
+ })]).catch(() => undefined).finally(() => clearTimeout(timer));
102
+ }
103
+ return words === undefined ? { status: "ok", checks: { store: answered, disk } } : { status: "degraded", checks: { store: answered, disk, runner: "refused" }, runner_refused: words };
90
104
  }
91
105
  /** Whether `--open` opens a browser here: not in CI, and on Linux or FreeBSD only with a display. */
92
106
  export const canOpen = (env, platform = process.platform) => !env.CI && (!["linux", "freebsd"].includes(platform) || Boolean(env.DISPLAY || env.WAYLAND_DISPLAY));
@@ -2,6 +2,8 @@ export declare const SOURCES: readonly ["claude-code", "codex", "pi"];
2
2
  export type Source = (typeof SOURCES)[number];
3
3
  /** The harness of serve that runs what each source ran. */
4
4
  export declare const HARNESS_OF: Record<Source, string>;
5
+ /** Each source's name as a person reads it. */
6
+ export declare const SOURCE_NAMES: Record<Source, string>;
5
7
  export type ToolCall = {
6
8
  type: "toolCall";
7
9
  id: string;
@@ -15,6 +15,8 @@ export const HARNESS_OF = {
15
15
  codex: "codex",
16
16
  pi: "pi",
17
17
  };
18
+ /** Each source's name as a person reads it. */
19
+ export const SOURCE_NAMES = { "claude-code": "Claude Code", codex: "Codex", pi: "pi" };
18
20
  /** The longest gap between two records counted as time at work, as WakaTime counts it: a longer gap is a session left
19
21
  * open and counts nothing. Claude Code's Bash tool runs a call for up to 10 minutes with nothing written. */
20
22
  export const ACTIVE_GAP_MS = 15 * 60_000;
@@ -14,8 +14,18 @@ export type Found = {
14
14
  };
15
15
  /** Requests by local hour of the day, from their times (ms). */
16
16
  export declare function hoursOf(times: Iterable<number>): number[];
17
- /** The summary's lines for `found`, ending with where to open the server (`open`, its address). `dryRun`: what an import
18
- * would take, nothing taken yet. */
19
- export declare function summaryLines(everything: readonly Found[], open: string, { dryRun }?: {
20
- dryRun?: boolean;
21
- }): string[];
17
+ /** What this import itself wrote: `sessions` imported into `agents`, and whether it was stopped before the end (Ctrl+C). */
18
+ export type Imported = {
19
+ sessions: number;
20
+ agents: number;
21
+ stopped?: boolean;
22
+ };
23
+ /** Where the console is once the server runs: `url`, and whether it is `known` (a public URL, or a port the person
24
+ * named), or only the default port, which the server passes over when another process has it. */
25
+ export type OpenAt = {
26
+ url?: string;
27
+ known: boolean;
28
+ };
29
+ /** The summary's lines for `found`, ending with where to open the server (`open`). `imported`: what the import wrote;
30
+ * absent, a dry run's summary: what an import would take, nothing taken yet. */
31
+ export declare function summaryLines(everything: readonly Found[], open: OpenAt, imported?: Imported): string[];
@@ -1,5 +1,4 @@
1
- import { SOURCES } from "./import-sources.js";
2
- const NAMES = { "claude-code": "Claude Code", codex: "Codex", pi: "pi" };
1
+ import { SOURCE_NAMES, SOURCES } from "./import-sources.js";
3
2
  /** Requests by local hour of the day, from their times (ms). */
4
3
  export function hoursOf(times) {
5
4
  const hours = new Array(24).fill(0);
@@ -11,9 +10,26 @@ export function hoursOf(times) {
11
10
  const count = (n) => n.toLocaleString("en-US");
12
11
  const compact = new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 });
13
12
  const plural = (n, one) => `${count(n)} ${one}${n === 1 ? "" : "s"}`;
14
- /** The summary's lines for `found`, ending with where to open the server (`open`, its address). `dryRun`: what an import
15
- * would take, nothing taken yet. */
16
- export function summaryLines(everything, open, { dryRun = false } = {}) {
13
+ /** The line saying what an import wrote: what it took now, out of every agent `found` makes; nothing new said as such,
14
+ * never as an import into agents that took nothing. */
15
+ function importedLine({ sessions, agents, stopped }, all, found) {
16
+ const into = `${plural(sessions, "session")} into ${agents === all || agents === 0 ? plural(agents, "agent") : `${count(agents)} of ${plural(all, "agent")}`}`;
17
+ if (stopped)
18
+ return `Stopped: imported ${into} before Ctrl+C; run the import again for the rest`;
19
+ if (sessions > 0)
20
+ return `Imported ${into} (one per project)`;
21
+ return found > 0 ? `Nothing new to import: ${found === 1 ? "this session is" : `all ${plural(found, "session")} are`} in ${plural(all, "agent")} already` : "Nothing to import";
22
+ }
23
+ /** The last line: where to open the console. A guessed address says it is the default, which the server's start may
24
+ * pass over for the next free port. */
25
+ function openLine({ url, known }) {
26
+ if (known && url)
27
+ return `Open ${url}/`;
28
+ return `Start the server, then open the address it prints${url ? ` (${url}/ unless that port is taken)` : ""}`;
29
+ }
30
+ /** The summary's lines for `found`, ending with where to open the server (`open`). `imported`: what the import wrote;
31
+ * absent, a dry run's summary: what an import would take, nothing taken yet. */
32
+ export function summaryLines(everything, open, imported) {
17
33
  // Sessions, agents, time and hours are the sessions'; tokens and tool calls take in the untied subagents' too.
18
34
  const found = everything.filter((f) => !f.untied);
19
35
  const by = SOURCES.map((source) => [source, found.filter((f) => f.source === source).length]).filter(([, n]) => n > 0);
@@ -41,10 +57,10 @@ export function summaryLines(everything, open, { dryRun = false } = {}) {
41
57
  const [top, topCalls] = [...calls].sort(([a, x], [b, y]) => y - x || a.localeCompare(b))[0] ?? [];
42
58
  const tool = !measured.length ? "unknown" : top === undefined || !total ? "none" : `${top} (${Math.round((100 * topCalls) / total)}%)`;
43
59
  return [
44
- `Found ${plural(found.length, "session")}${by.length ? ` ${by.map(([source, n]) => `${NAMES[source]} ${count(n)}`).join(" · ")}` : ""}`,
45
- `${dryRun ? "Would import into" : "Imported into"} ${plural(agents, "agent")} (one per project)`,
60
+ `Found ${plural(found.length, "session")}${by.length ? ` ${by.map(([source, n]) => `${SOURCE_NAMES[source]} ${count(n)}`).join(" · ")}` : ""}`,
61
+ imported ? importedLine(imported, agents, found.length) : `Would import into ${plural(agents, "agent")} (one per project)`,
46
62
  `+ ${used.join(" · ")}`,
47
63
  `+ Busiest hour: ${busiest === undefined ? "unknown" : `${String(busiest).padStart(2, "0")}:00`} · top tool: ${tool}`,
48
- `Open ${open}/`,
64
+ openLine(open),
49
65
  ];
50
66
  }