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

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 (247) hide show
  1. package/CHANGELOG.md +164 -1
  2. package/NOTICE +4 -0
  3. package/README.md +267 -40
  4. package/dist/acp-package.d.ts +35 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +5 -2
  7. package/dist/adapter-facts.js +6 -3
  8. package/dist/adapters.d.ts +7 -0
  9. package/dist/adapters.js +39 -0
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/api-only.d.ts +7 -10
  13. package/dist/api-only.js +7 -10
  14. package/dist/archil-routes.js +2 -1
  15. package/dist/cap.js +12 -2
  16. package/dist/chatgpt-plan.js +2 -1
  17. package/dist/cli.js +109 -41
  18. package/dist/composio-made.d.ts +19 -2
  19. package/dist/composio-made.js +17 -5
  20. package/dist/composio-preset.d.ts +42 -7
  21. package/dist/composio-preset.js +106 -70
  22. package/dist/composio-triggers.d.ts +9 -4
  23. package/dist/composio-triggers.js +20 -13
  24. package/dist/computer-attach.d.ts +11 -10
  25. package/dist/computer-attach.js +13 -14
  26. package/dist/computer-commands.d.ts +3 -0
  27. package/dist/computer-commands.js +3 -2
  28. package/dist/computer-lost.d.ts +4 -0
  29. package/dist/computer-lost.js +8 -3
  30. package/dist/computer-setting.d.ts +2 -0
  31. package/dist/computer-setting.js +2 -0
  32. package/dist/computers.d.ts +9 -75
  33. package/dist/computers.js +20 -66
  34. package/dist/console/assets/index-BBFzAxLB.js +715 -0
  35. package/dist/console/assets/index-BRi-Rgq6.css +1 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/cost-heal.d.ts +13 -0
  38. package/dist/cost-heal.js +27 -0
  39. package/dist/dial-relay.d.ts +6 -2
  40. package/dist/dial-relay.js +9 -12
  41. package/dist/email/routes.js +2 -1
  42. package/dist/errors.d.ts +2 -0
  43. package/dist/errors.js +5 -0
  44. package/dist/exa-keyless.d.ts +1 -1
  45. package/dist/exa-keyless.js +1 -1
  46. package/dist/faux-computers.d.ts +2 -3
  47. package/dist/faux-computers.js +9 -31
  48. package/dist/github-connection.js +2 -1
  49. package/dist/harness-archive.d.ts +19 -2
  50. package/dist/harness-archive.js +49 -15
  51. package/dist/harness-check.d.ts +73 -0
  52. package/dist/harness-check.js +489 -0
  53. package/dist/harness-cursor.d.ts +45 -0
  54. package/dist/harness-cursor.js +121 -0
  55. package/dist/harness-recipe.d.ts +127 -0
  56. package/dist/harness-recipe.js +357 -0
  57. package/dist/harness-table.d.ts +12 -0
  58. package/dist/harness-table.js +62 -2
  59. package/dist/harness.d.ts +2 -0
  60. package/dist/harness.js +3 -2
  61. package/dist/host-check.d.ts +6 -0
  62. package/dist/host-check.js +14 -0
  63. package/dist/host.d.ts +10 -3
  64. package/dist/host.js +17 -3
  65. package/dist/import-sources.d.ts +2 -0
  66. package/dist/import-sources.js +2 -0
  67. package/dist/import-summary.d.ts +15 -5
  68. package/dist/import-summary.js +24 -8
  69. package/dist/import.d.ts +24 -4
  70. package/dist/import.js +108 -26
  71. package/dist/key-refusal.d.ts +1 -0
  72. package/dist/key-refusal.js +8 -3
  73. package/dist/key-words.d.ts +1 -1
  74. package/dist/key-words.js +4 -4
  75. package/dist/learn/check.d.ts +3 -0
  76. package/dist/learn/check.js +31 -20
  77. package/dist/learn/compile.js +12 -5
  78. package/dist/learn/promote.d.ts +69 -2
  79. package/dist/learn/promote.js +95 -3
  80. package/dist/learned-nodes.d.ts +4 -3
  81. package/dist/learned-workflow.js +4 -1
  82. package/dist/learning-cost.d.ts +6 -16
  83. package/dist/learning-cost.js +6 -12
  84. package/dist/learning-words.d.ts +2 -0
  85. package/dist/learning-words.js +1 -1
  86. package/dist/listen-first.d.ts +10 -0
  87. package/dist/listen-first.js +25 -1
  88. package/dist/llms.txt +1 -1
  89. package/dist/mcp-gateway.d.ts +2 -1
  90. package/dist/mcp-gateway.js +31 -15
  91. package/dist/mcp-probe.d.ts +18 -6
  92. package/dist/mcp-probe.js +41 -8
  93. package/dist/mcp-secret-writes.d.ts +8 -0
  94. package/dist/mcp-secret-writes.js +104 -4
  95. package/dist/mcp-servers-store.d.ts +11 -5
  96. package/dist/mcp-servers-store.js +46 -20
  97. package/dist/model-form.d.ts +2 -1
  98. package/dist/model-form.js +22 -8
  99. package/dist/model-gateway.d.ts +113 -0
  100. package/dist/model-gateway.js +433 -0
  101. package/dist/model.d.ts +2 -1
  102. package/dist/model.js +9 -7
  103. package/dist/monid.js +1 -1
  104. package/dist/native/binding.d.ts +4 -0
  105. package/dist/native/binding.js +9 -0
  106. package/dist/native/cli.d.ts +3 -2
  107. package/dist/native/cli.js +6 -5
  108. package/dist/openapi.d.ts +2 -0
  109. package/dist/openapi.js +322 -39
  110. package/dist/owner.d.ts +4 -2
  111. package/dist/owner.js +10 -4
  112. package/dist/page.d.ts +8 -0
  113. package/dist/page.js +9 -1
  114. package/dist/port-models.js +17 -10
  115. package/dist/provider.d.ts +3 -3
  116. package/dist/provider.js +12 -3
  117. package/dist/public-address.d.ts +28 -0
  118. package/dist/public-address.js +62 -0
  119. package/dist/run-launch.d.ts +1 -1
  120. package/dist/run-launch.js +1 -1
  121. package/dist/run-secrets.d.ts +3 -2
  122. package/dist/run-secrets.js +6 -4
  123. package/dist/runner/adapter-loop.d.ts +10 -7
  124. package/dist/runner/adapter-loop.js +57 -22
  125. package/dist/runner/adapter-run-spec.d.ts +12 -0
  126. package/dist/runner/adapter-run-spec.js +40 -6
  127. package/dist/runner/adapters/index.js +16 -0
  128. package/dist/runner/adapters/pi.d.ts +5 -2
  129. package/dist/runner/adapters/pi.js +7 -4
  130. package/dist/runner/audit.d.ts +7 -0
  131. package/dist/runner/audit.js +15 -6
  132. package/dist/runner/claim-secrets.js +5 -1
  133. package/dist/runner/cli-run-spec.js +15 -7
  134. package/dist/runner/compare-end.d.ts +43 -0
  135. package/dist/runner/compare-end.js +95 -0
  136. package/dist/runner/computer-journal.d.ts +3 -0
  137. package/dist/runner/computer-journal.js +22 -2
  138. package/dist/runner/harness-loops.d.ts +6 -1
  139. package/dist/runner/harness-loops.js +94 -54
  140. package/dist/runner/held.d.ts +5 -4
  141. package/dist/runner/journal-kinds.d.ts +4 -1
  142. package/dist/runner/journal-kinds.js +3 -0
  143. package/dist/runner/loop-contract.d.ts +10 -0
  144. package/dist/runner/main.d.ts +5 -5
  145. package/dist/runner/main.js +62 -11
  146. package/dist/runner/mcp-claim.js +40 -12
  147. package/dist/runner/metrics.d.ts +26 -0
  148. package/dist/runner/metrics.js +44 -1
  149. package/dist/runner/presence.d.ts +41 -0
  150. package/dist/runner/presence.js +89 -0
  151. package/dist/runner/promotion.d.ts +9 -4
  152. package/dist/runner/promotion.js +33 -14
  153. package/dist/runner/run-child-host.js +40 -10
  154. package/dist/runner/runner.d.ts +5 -0
  155. package/dist/runner/runner.js +8 -0
  156. package/dist/runner/store-port.d.ts +3 -0
  157. package/dist/runner/store-secrets.js +19 -7
  158. package/dist/runner/workflow-first.d.ts +5 -2
  159. package/dist/runner/workflow-first.js +6 -3
  160. package/dist/runs-over-store.d.ts +6 -2
  161. package/dist/runs-over-store.js +14 -4
  162. package/dist/sdk/runs.d.ts +1 -1
  163. package/dist/sdk/runs.js +6 -1
  164. package/dist/sdk/schema.js +1 -1
  165. package/dist/secret-writes.d.ts +16 -3
  166. package/dist/secret-writes.js +28 -3
  167. package/dist/server-secrets-store.js +5 -0
  168. package/dist/server.d.ts +31 -2
  169. package/dist/server.js +322 -51
  170. package/dist/sign-ins-secrets.js +4 -1
  171. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  172. package/dist/slack-url.d.ts +5 -0
  173. package/dist/slack-url.js +11 -0
  174. package/dist/slack.d.ts +107 -0
  175. package/dist/slack.js +292 -0
  176. package/dist/start-switches.d.ts +28 -0
  177. package/dist/start-switches.js +37 -0
  178. package/dist/stats.d.ts +1 -1
  179. package/dist/stats.js +2 -1
  180. package/dist/stop-signals.d.ts +11 -0
  181. package/dist/stop-signals.js +22 -0
  182. package/dist/store/agent-body.d.ts +1 -1
  183. package/dist/store/agent-body.js +2 -2
  184. package/dist/store/index.d.ts +3 -3
  185. package/dist/store/index.js +1 -1
  186. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  187. package/dist/store/postgres/store.d.ts +1 -1
  188. package/dist/store/postgres/store.js +4 -2
  189. package/dist/store/schema.d.ts +13 -5
  190. package/dist/store/schema.js +20 -11
  191. package/dist/store/seal.d.ts +16 -4
  192. package/dist/store/sqlite/store.d.ts +1 -1
  193. package/dist/store/sqlite/store.js +106 -27
  194. package/dist/store/store.d.ts +75 -23
  195. package/dist/store/store.js +11 -0
  196. package/dist/store-reads/analytics.js +3 -2
  197. package/dist/store-reads/cap.d.ts +7 -0
  198. package/dist/store-reads/cap.js +11 -1
  199. package/dist/store-reads/journal.js +27 -1
  200. package/dist/store-reads/learning.d.ts +23 -2
  201. package/dist/store-reads/learning.js +29 -8
  202. package/dist/store-reads/runs.d.ts +9 -0
  203. package/dist/store-reads/runs.js +19 -6
  204. package/dist/store-reads/stats.d.ts +4 -1
  205. package/dist/store-reads/stats.js +15 -6
  206. package/dist/store-view.d.ts +123 -14
  207. package/dist/store-view.js +154 -21
  208. package/dist/telemetry.d.ts +7 -7
  209. package/dist/telemetry.js +38 -15
  210. package/dist/timeline/timeline.js +18 -0
  211. package/dist/tool-keys-store.js +2 -2
  212. package/dist/tool-keys.js +2 -1
  213. package/dist/tool-plane.js +2 -2
  214. package/dist/trigger-adapter.d.ts +3 -4
  215. package/dist/trigger-adapter.js +2 -2
  216. package/dist/trigger-composio.js +3 -3
  217. package/dist/trigger-email.js +0 -2
  218. package/dist/trigger-feed.js +0 -2
  219. package/dist/trigger-schedule.js +3 -0
  220. package/dist/trigger-secrets-shown.d.ts +6 -3
  221. package/dist/trigger-secrets-shown.js +22 -13
  222. package/dist/trigger-targets.d.ts +1 -1
  223. package/dist/trigger-targets.js +19 -8
  224. package/dist/triggers.d.ts +2 -2
  225. package/dist/webhooks.d.ts +82 -8
  226. package/dist/webhooks.js +128 -45
  227. package/dist/wires.d.ts +6 -1
  228. package/dist/wires.js +5 -0
  229. package/dist/workspace/attach.d.ts +3 -2
  230. package/dist/workspace/attach.js +2 -1
  231. package/dist/workspace/attached-computers.d.ts +6 -8
  232. package/dist/workspace/attached-computers.js +27 -24
  233. package/dist/workspace/computer-deps.d.ts +2 -3
  234. package/dist/workspace/computer-deps.js +3 -6
  235. package/dist/workspace/computer-for-claim.js +72 -96
  236. package/dist/workspace/computer-kept.d.ts +0 -7
  237. package/dist/workspace/computer-kept.js +0 -17
  238. package/dist/workspace/resolve-computer.d.ts +18 -14
  239. package/dist/workspace/resolve-computer.js +47 -60
  240. package/dist/workspace/synced-folder.d.ts +20 -15
  241. package/dist/workspace/synced-folder.js +33 -43
  242. package/launcher/agentrun-serve +4 -1
  243. package/package.json +10 -10
  244. package/skills/agentrun-serve/SKILL.md +11 -0
  245. package/templates/README.md +1 -1
  246. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  247. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -12,13 +12,14 @@ 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";
15
+ import { CURSOR_FACTS, GOOSE_FACTS } from "./adapter-facts.js";
16
16
  import { gooseHidden } from "./harness-goose.js";
17
+ import { CURSOR_DEFAULT_MODEL, CURSOR_KEY, CURSOR_PROVIDER, cursorCardOf, cursorHidden } from "./harness-cursor.js";
17
18
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
18
19
  import { HARNESS_INSTALLS } from "./harness-install.js";
19
20
  import { chooseModel } from "./model.js";
20
21
  import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
21
- import { WIRES } from "./wires.js";
22
+ import { modelWire, WIRES } from "./wires.js";
22
23
  import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
23
24
  /** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
24
25
  export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
@@ -64,6 +65,9 @@ const onOpenRouter = (id, vendor) => new RegExp(`^openrouter/${vendor}/[^/]+$`).
64
65
  /** An adapter harness's entry, from its facts and the factory that builds its adapter. */
65
66
  function adapterEntry(facts, make, extra = {}) {
66
67
  const { wire, id } = facts;
68
+ // A harness billed to its own plan has an entry of its own (cursorEntry): this one is for a model wire of ours.
69
+ if (!modelWire(wire))
70
+ throw new Error(`${id} is billed to its own plan, so its table entry is its own, never adapterEntry's`);
67
71
  const { vendor, gateway } = WIRES[wire];
68
72
  const installs = HARNESS_INSTALLS[id];
69
73
  const onPlan = PLAN_HARNESSES.includes(id);
@@ -113,6 +117,56 @@ function adapterEntry(facts, make, extra = {}) {
113
117
  };
114
118
  return Object.freeze(entry);
115
119
  }
120
+ /** Cursor's entry, from its facts: billed to its owner's Cursor plan on the owner's Cursor API key (`ownKeys`), so no
121
+ * model key, proxy, catalog or cap of ours is its. Its model is one Cursor lists for that key, named `cursor/<model-id>`
122
+ * (`cursor/default`: Cursor's own default), checked against Cursor's list when its session opens (ACP_MODEL_UNLISTED).
123
+ * Listed only once its owner has installed it (`agentrun harness install cursor`), and stopped by its owner's turn and
124
+ * tool-call limits (harness-cursor.ts cursorLimitsOf), which its card says. */
125
+ function cursorEntry(facts) {
126
+ const { id } = facts;
127
+ const prefix = `${CURSOR_PROVIDER}/`;
128
+ const entry = {
129
+ id,
130
+ label: facts.label,
131
+ steer: facts.steer,
132
+ runMib: facts.runMib,
133
+ oneAlwaysFits: false,
134
+ facts,
135
+ promises: Object.freeze({ resume: "load", tool_gate: "permission", billing: "plan" }),
136
+ ownKeys: Object.freeze([CURSOR_KEY]),
137
+ hidden: cursorHidden,
138
+ card: cursorCardOf,
139
+ runs: (_env, model) => model.startsWith(prefix),
140
+ onWire: () => true,
141
+ model: async (_env, ref, available) => {
142
+ if (!available)
143
+ return undefined;
144
+ const named = ref ?? `${prefix}${CURSOR_DEFAULT_MODEL}`;
145
+ const modelId = named.startsWith(prefix) ? named.slice(prefix.length) : "";
146
+ const { acpPackage } = await import("./acp-package.js");
147
+ if (!modelId || !acpPackage()?.MODEL_ID.test(modelId))
148
+ return { why: `${facts.label} runs a model Cursor lists for your Cursor API key, named ${prefix}<model-id> (${prefix}${CURSOR_DEFAULT_MODEL} for Cursor's own default); ${named} is not one.`, host: false, needs: "model" };
149
+ return { model: { provider: CURSOR_PROVIDER, modelId } };
150
+ },
151
+ priceModel: (_env, model) => model,
152
+ adapter: async (env, needs) => (await import("./adapters.js")).cursorOf(env, needs),
153
+ refusal: async (env, given, { atStart }) => {
154
+ const { cursorOf, startReason } = await import("./adapters.js");
155
+ try {
156
+ const adapter = await cursorOf(env, given ?? { model: { provider: CURSOR_PROVIDER, modelId: CURSOR_DEFAULT_MODEL }, models: { getModel: () => undefined } });
157
+ const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
158
+ return problems.length ? { reason: problems.join(" ") } : undefined;
159
+ }
160
+ catch (error) {
161
+ return { reason: atStart ? startReason(error) : error.message };
162
+ }
163
+ },
164
+ };
165
+ return Object.freeze(entry);
166
+ }
167
+ /** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
168
+ * server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
169
+ export const BUILTIN_OWN_KEYS = Object.freeze([CURSOR_KEY]);
116
170
  /** The harnesses this server runs, by id. */
117
171
  const BUILTIN = Object.freeze({
118
172
  [DEFAULT_HARNESS]: PI,
@@ -140,7 +194,13 @@ const BUILTIN = Object.freeze({
140
194
  hidden: gooseHidden,
141
195
  }),
142
196
  } : {}),
197
+ // Cursor, over ACP, where the same package is beside serve: its owner installs its pinned release (`agentrun harness
198
+ // install cursor`, harness-cursor.ts) and sets CURSOR_API_KEY; listed only once it is installed and verified.
199
+ ...(CURSOR_FACTS ? { [CURSOR_FACTS.id]: cursorEntry(CURSOR_FACTS) } : {}),
143
200
  });
201
+ /** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
202
+ * needs it too): a recipe or module never takes one (harness-recipe.ts). */
203
+ export const BUILTIN_HARNESS_IDS = Object.freeze(Object.keys(BUILTIN));
144
204
  const loaded = new Map();
145
205
  const requireHere = createRequire(import.meta.url);
146
206
  /** The members a harness module's new entry gives: what the table's readers ask of every entry. */
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" } : {};
@@ -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
  }
package/dist/import.d.ts CHANGED
@@ -72,6 +72,9 @@ export type ImportOptions = {
72
72
  signal?: AbortSignal;
73
73
  /** Each key secretlint finds, as it finds it: for what the CLI prints, cut with the keys the import cuts. */
74
74
  onKeys?: (keys: readonly string[]) => void;
75
+ /** How far the import is, for the CLI's progress line: `keys`, the sessions read for keys before anything is written
76
+ * (`done` of `total`); `write`, the sessions written or passed over. Counts alone, never a name or a path. */
77
+ onProgress?: (step: "keys" | "write", done: number, total: number) => void;
75
78
  /** Read each session file through secretlint for the cut (default). Setup's count sets it false: a count keeps no
76
79
  * transcript, so it reads none, and a server's start never scans a whole history to say how many sessions it has. */
77
80
  keys?: boolean;
@@ -111,7 +114,7 @@ export type ProjectPlan = {
111
114
  * again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the files of each
112
115
  * session's subagents, whose usage is its run's: Claude Code's by the session file beside them, Codex's by `source:thread`; `untied`, those of subagents whose file names
113
116
  * no parent, counted in a summary's totals alone. `found`: each other planned session measured,
114
- * when the plan was made to (`measure`). */
117
+ * when the plan was made to (`measure`). `stopped`: `signal` ended the listing with session files still unlisted. */
115
118
  export type Plan = {
116
119
  projects: ProjectPlan[];
117
120
  skipped: Skipped[];
@@ -124,6 +127,7 @@ export type Plan = {
124
127
  }[];
125
128
  found?: Found[];
126
129
  secretsFound?: number;
130
+ stopped?: true;
127
131
  };
128
132
  export type ImportReport = {
129
133
  agents: {
@@ -146,6 +150,9 @@ export type ImportReport = {
146
150
  /** Keys and tokens cut out of what it wrote (secret-cut.ts): the environment's values, the saved keys, and those of a
147
151
  * known format secretlint found. */
148
152
  secretsRemoved?: number;
153
+ /** `signal` ended it with sessions of the plan still to take, or the plan was itself stopped (`Plan.stopped`): the
154
+ * next import takes the rest. Absent when a stop came with nothing left to take: the import is whole. */
155
+ stopped?: true;
149
156
  };
150
157
  /** The projects of `plan` for the owner to choose from, the latest active first (then by folder), at most MAX_CANDIDATES.
151
158
  * With `env`, the values of its keys are cut from a name and a folder as the import cuts them. */
@@ -208,10 +215,23 @@ export declare function leftOutOf(skipped: readonly Pick<Skipped, "kind" | "what
208
215
  export declare function describePlan(plan: Plan, store?: ImportStore, { verbose }?: {
209
216
  verbose?: boolean;
210
217
  }): Promise<string[]>;
211
- /** `agentrun-serve import ARGS`: its exit code. */
212
- export declare function importCommand(args: string[], usage: string, { home, temp, env, out, }?: {
218
+ /** What `importCommand` takes besides its arguments. */
219
+ type ImportDeps = {
213
220
  home?: string;
214
221
  env?: NodeJS.ProcessEnv;
215
222
  out?: (line: string) => void;
216
223
  temp?: string;
217
- }): Promise<number>;
224
+ /** Where the import says how far it is while it works (default: one line on stderr, on a terminal only). */
225
+ progress?: Progress;
226
+ };
227
+ /** `agentrun-serve import ARGS`: its exit code. The first Ctrl+C (or SIGTERM) once it writes stops it between two
228
+ * sessions: each is written whole (importRun is atomic), what is written stays, and the next import picks up the rest.
229
+ * Its listeners stay until everything it says is printed, since its lines are held until the end; a Ctrl+C it took is
230
+ * in the code (130) whenever it came. */
231
+ export declare function importCommand(args: string[], usage: string, deps?: ImportDeps): Promise<number>;
232
+ /** Where the CLI says how far an import is: `show` a line in place of the last, `done` clears it. */
233
+ export type Progress = {
234
+ show: (text: string) => void;
235
+ done: () => void;
236
+ };
237
+ export {};