@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61

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 (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -25,6 +25,7 @@ import { TOOL_UNMETERED } from "./timeline/index.js";
25
25
  import { until } from "./until.js";
26
26
  import { meterFor, meterNamed } from "./fal-price.js";
27
27
  import { filedAnswer } from "./filed-answer.js";
28
+ import { filedSummary, UNREADABLE, unfiledSummary } from "./filed-tool.js";
28
29
  import { saveOnce } from "./save-once.js";
29
30
  import { paidLedger, paidStep } from "./paid-calls.js";
30
31
  import { metaToolOf } from "./mcp-meta.js";
@@ -187,6 +188,8 @@ function unreachable(error) {
187
188
  return deepest;
188
189
  }
189
190
  const said = (text, isError = false) => ({ content: [{ type: "text", text }], ...(isError ? { isError: true } : {}) });
191
+ /** The refusal of a call of a tool whose stored file setting does not read (filed-tool.ts UNREADABLE). */
192
+ const unreadableFile = (server, tool) => `${mcpToolName(server, tool)} can't be called: its file setting in the agent's tool settings does not read, so no call is let through until the owner sets it again or removes it (Settings → Tools). Nothing was sent.`;
190
193
  export function mcpGateway(options) {
191
194
  /** Each server's client, with the account query it was connected with (`query`, JSON): a message that binds the run to
192
195
  * another account connects again, so no session made as one account carries another's calls. */
@@ -280,13 +283,8 @@ export function mcpGateway(options) {
280
283
  upstream.catch(() => clients.get(server) === made && clients.delete(server));
281
284
  return upstream;
282
285
  };
283
- /** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
284
- * file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
285
- * run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
286
- * and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
287
- * neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
288
- * credential the call's server took or sent. */
289
- const textOf = async (server, tool, result, clean) => {
286
+ /** The answer's text, as textOf reads it before any clip, scrubbed: `other`, how many blocks of it are not text. */
287
+ const answerOf = (result, clean) => {
290
288
  const blocks = Array.isArray(result.content) ? result.content : [];
291
289
  const texts = blocks.flatMap((block) => {
292
290
  if (block?.type === "text" && typeof block.text === "string")
@@ -300,7 +298,16 @@ export function mcpGateway(options) {
300
298
  let text = clean(texts.join("\n\n"));
301
299
  if (!text && result.structuredContent !== undefined)
302
300
  text = clean(JSON.stringify(result.structuredContent));
303
- const other = blocks.length - texts.length;
301
+ return { text, other: blocks.length - texts.length };
302
+ };
303
+ /** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
304
+ * file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
305
+ * run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
306
+ * and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
307
+ * neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
308
+ * credential the call's server took or sent. */
309
+ const textOf = async (server, tool, result, clean) => {
310
+ const { text, other } = answerOf(result, clean);
304
311
  if (text.length <= MCP_CLIP && other === 0)
305
312
  return text;
306
313
  const name = `${tool}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
@@ -316,6 +323,25 @@ export function mcpGateway(options) {
316
323
  }
317
324
  return `${head}the whole answer is in the run's files at evidence/mcp/${server}/${name}.json]`;
318
325
  };
326
+ /** An answer of a tool the agent's setting files (options.filed): written whole, scrubbed, at
327
+ * <folder>/<tool>-<time>-<id>.json in the run's files before the model is answered, and the tool's result the summary
328
+ * alone (filed-tool.ts), never through the clip. An error answer is filed the same way and its summary answers an
329
+ * error, so the model can still react through a shown field. An answer with blocks that are not text is filed as the
330
+ * whole result's JSON. A write that fails (or a Workspace that cannot open) answers an error in the Workspace's words,
331
+ * none of the answer shown. */
332
+ const filedOf = async (setting, tool, result, clean) => {
333
+ const { text: answer, other } = answerOf(result, clean);
334
+ const text = other === 0 ? answer : clean(JSON.stringify(result));
335
+ const path = `${setting.folder}/${tool.replace(/[^A-Za-z0-9_.-]/g, "_")}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}.json`;
336
+ try {
337
+ await workspaceAt(await options.work()).write(path, text);
338
+ }
339
+ catch (error) {
340
+ // The Workspace's code and the port's line for it, never the error's message, which names paths.
341
+ return said(unfiledSummary(tool, text, setting.folder, workspaceErrorWords(error) ?? (typeof error?.code === "string" ? error.code : "write failed")), true);
342
+ }
343
+ return said(filedSummary(tool, text, path, setting.show), result.isError === true);
344
+ };
319
345
  /** The results `result` carries that `server`'s meter keeps (McpMeter.results), each filed at its `<dir>/<name>.json`
320
346
  * in the run's files, once (save-once.ts): a file, folder or link already there is kept, and a link on the way is never
321
347
  * followed. Scrubbed as the model's text is. Nothing is said of it in the answer, and a result that could not be filed
@@ -383,6 +409,12 @@ export function mcpGateway(options) {
383
409
  return said("", result.isError === true);
384
410
  // Filed before the answer is given, so a model that reads it next finds it.
385
411
  await fileResults(server, tool.name, result, clean);
412
+ const filing = options.filed?.(server, tool.name);
413
+ // UNREADABLE never gets here (unsendable refuses it unsent); never answered unfiled either way.
414
+ if (filing === UNREADABLE)
415
+ return said(unreadableFile(server, tool.name), true);
416
+ if (filing)
417
+ return await filedOf(filing, tool.name, result, clean);
386
418
  return said(await textOf(server, tool.name, result, clean), result.isError === true);
387
419
  }
388
420
  catch (error) {
@@ -422,6 +454,10 @@ export function mcpGateway(options) {
422
454
  const pinned = pins.get(server);
423
455
  if (!pinned?.tools.some((t) => t.name === tool))
424
456
  return `${tool} is not a tool of the MCP server ${server} in this run.`;
457
+ // A file setting that does not read fails closed, as a broken pin does: never a call whose answer goes to the model
458
+ // unfiled.
459
+ if (options.filed?.(server, tool) === UNREADABLE)
460
+ return unreadableFile(server, tool);
425
461
  const resourceProblem = resourceToolProblem(pinned.tools.find(t => t.name === tool));
426
462
  if (resourceProblem)
427
463
  return `The MCP operation ${tool} is invalid: ${resourceProblem}. Nothing was sent.`;
@@ -20,6 +20,13 @@ export declare const UNUSABLE: {
20
20
  * token handed, or which was sealed before the seal marked who handed it. */
21
21
  readonly composioOwnersUser: "the Composio user this run is bound to is one the owner connects on this install, and nothing marks the binding as the owner's: hand mcp_auth again on a message, or start a new run";
22
22
  };
23
+ /** What a run's timeline says of a server whose credential comes from each run when the run was handed none: its tools
24
+ * were left out of the run's (mcp-run.ts mcpForClaim), so the model is never offered a tool every call of which is
25
+ * refused. */
26
+ export declare const unconnectedWords: (server: string) => string;
27
+ /** The run's timeline note when a message hands the credential of servers whose tools its claim left out
28
+ * (unconnectedWords) while a turn is going: that turn's tools stay as they are, so the message waits for the next. */
29
+ export declare const connectedLaterWords: (servers: readonly string[]) => string;
23
30
  export declare const REFRESH_MARGIN_MS: number;
24
31
  /** How long an access token given with no expiry is taken to last: it is refreshed within the margin of then. */
25
32
  export declare const UNKNOWN_EXPIRY_MS: number;
package/dist/mcp-probe.js CHANGED
@@ -37,6 +37,13 @@ export const UNUSABLE = {
37
37
  * token handed, or which was sealed before the seal marked who handed it. */
38
38
  composioOwnersUser: "the Composio user this run is bound to is one the owner connects on this install, and nothing marks the binding as the owner's: hand mcp_auth again on a message, or start a new run",
39
39
  };
40
+ /** What a run's timeline says of a server whose credential comes from each run when the run was handed none: its tools
41
+ * were left out of the run's (mcp-run.ts mcpForClaim), so the model is never offered a tool every call of which is
42
+ * refused. */
43
+ export const unconnectedWords = (server) => `The MCP server ${server}'s tools were left out of this run: ${UNUSABLE.perRunMissing}.`;
44
+ /** The run's timeline note when a message hands the credential of servers whose tools its claim left out
45
+ * (unconnectedWords) while a turn is going: that turn's tools stay as they are, so the message waits for the next. */
46
+ export const connectedLaterWords = (servers) => `The MCP server${servers.length > 1 ? "s" : ""} ${servers.join(", ")} ${servers.length > 1 ? "were" : "was"} handed ${servers.length > 1 ? "their credentials" : "its credential"} by a message while this turn was going without ${servers.length > 1 ? "their" : "its"} tools: the message runs as the run's next turn, which has them.`;
40
47
  export const REFRESH_MARGIN_MS = 5 * 60_000;
41
48
  /** How long an access token given with no expiry is taken to last: it is refreshed within the margin of then. */
42
49
  export const UNKNOWN_EXPIRY_MS = 60 * 60_000;
@@ -8,7 +8,7 @@ export declare const RESOURCE_PAGES_MAX = 64;
8
8
  export declare const reservedResourceName: (name: string) => boolean;
9
9
  export declare function resourceTools(): {
10
10
  name: string;
11
- resource: "read" | "templates" | "list";
11
+ resource: "read" | "list" | "templates";
12
12
  title: string;
13
13
  description: string;
14
14
  input_schema: {
@@ -6,6 +6,12 @@ export declare class NativeDiscoveryError extends ApiError {
6
6
  }
7
7
  /** Resolve only through the supplied native PATH. Never substitutes a bundled managed runtime. */
8
8
  export declare function nativeExecutable(runtime: NativeRuntime, env?: NodeJS.ProcessEnv): Promise<string | null>;
9
+ /** The environment a native CLI starts with: `env`, with `USER` and `LOGNAME` filled in where it has none (unset or
10
+ * empty) by the user this process runs as (loginUser, from the user database). On macOS Claude Code names its Keychain
11
+ * item's account by `$USER`, else by its Bun runtime's userInfo, which reads `$USER` too: "unknown" with none. So a
12
+ * server started with no USER (a launchd service) would read the person's login under "unknown", where their terminal's
13
+ * `claude` never saved it, and say signed out. A USER `env` has is the person's own shell's and is kept as it is. */
14
+ export declare function nativeSpawnEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
9
15
  /** Metadata commands are bounded and never contain a prompt or a launch command. */
10
16
  export declare function nativeMetadata(binary: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, timeoutMs?: number): Promise<{
11
17
  code: number | null;
@@ -4,6 +4,7 @@ import { constants } from "node:fs";
4
4
  import { dirname, join, resolve, delimiter, basename } from "node:path";
5
5
  import { homedir, hostname } from "node:os";
6
6
  import { spawn } from "node:child_process";
7
+ import { loginUser } from "@parcha/agentrun-harness-claude/facts";
7
8
  import { ApiError } from "../errors.js";
8
9
  import { NATIVE_MINIMUM_VERSION, NATIVE_RUNTIME_FACTS, NATIVE_RUNTIMES, NATIVE_CLAUDE_POLICY_UNRESOLVED, NATIVE_CLAUDE_ADDITIONAL_POLICY_UNRESOLVED } from "./runtimes.js";
9
10
  export { NATIVE_MINIMUM_VERSION } from "./runtimes.js";
@@ -46,11 +47,23 @@ export async function nativeExecutable(runtime, env = process.env) {
46
47
  }
47
48
  return null;
48
49
  }
50
+ /** The environment a native CLI starts with: `env`, with `USER` and `LOGNAME` filled in where it has none (unset or
51
+ * empty) by the user this process runs as (loginUser, from the user database). On macOS Claude Code names its Keychain
52
+ * item's account by `$USER`, else by its Bun runtime's userInfo, which reads `$USER` too: "unknown" with none. So a
53
+ * server started with no USER (a launchd service) would read the person's login under "unknown", where their terminal's
54
+ * `claude` never saved it, and say signed out. A USER `env` has is the person's own shell's and is kept as it is. */
55
+ export function nativeSpawnEnv(env) {
56
+ const user = loginUser(), filled = { ...env };
57
+ for (const name of ["USER", "LOGNAME"])
58
+ if (!filled[name] && user[name])
59
+ filled[name] = user[name];
60
+ return filled;
61
+ }
49
62
  /** Metadata commands are bounded and never contain a prompt or a launch command. */
50
63
  export async function nativeMetadata(binary, args, cwd, env, timeoutMs = 5_000) {
51
64
  return new Promise((resolveResult) => {
52
65
  let stdout = "", done = false;
53
- const child = spawn(binary, args, { cwd, env, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "ignore"] });
66
+ const child = spawn(binary, args, { cwd, env: nativeSpawnEnv(env), detached: process.platform !== "win32", stdio: ["ignore", "pipe", "ignore"] });
54
67
  const finish = (code) => { if (done)
55
68
  return; done = true; clearTimeout(timer); resolveResult({ code, stdout }); };
56
69
  const timer = setTimeout(() => { try {
@@ -17,6 +17,11 @@ export declare class RemoteConnectors {
17
17
  constructor(store: Store, now?: () => number);
18
18
  private connector;
19
19
  private targets;
20
+ /** Connector transport health only: an online worker does not establish any external session's liveness. */
21
+ health(id: string): Promise<{
22
+ status: "current" | "offline" | "revoked" | "unreported";
23
+ last_seen_at: string | null;
24
+ }>;
20
25
  private view;
21
26
  list(): Promise<{
22
27
  connectors: {
@@ -43,6 +43,22 @@ export class RemoteConnectors {
43
43
  async targets(id) {
44
44
  return (await this.store.settings.all({ prefix: keyOf('target', `${id}.`) })).map(row => row.value);
45
45
  }
46
+ /** Connector transport health only: an online worker does not establish any external session's liveness. */
47
+ async health(id) {
48
+ let row;
49
+ try {
50
+ row = await this.connector(id);
51
+ }
52
+ catch (error) {
53
+ if (error instanceof ApiError && error.code === "not_found")
54
+ return { status: "unreported", last_seen_at: null };
55
+ throw error;
56
+ }
57
+ return {
58
+ status: row.revoked || row.expires <= this.now() ? "revoked" : row.last_seen + ONLINE_MS >= this.now() ? "current" : "offline",
59
+ last_seen_at: row.last_seen ? new Date(row.last_seen).toISOString() : null,
60
+ };
61
+ }
46
62
  async view(row) {
47
63
  const targets = await this.targets(row.id);
48
64
  return { id: row.id, connector_id: row.id, label: row.label, created_at: row.created_at, last_seen_at: row.last_seen ? new Date(row.last_seen).toISOString() : null,
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { StringDecoder } from "node:string_decoder";
3
3
  import { NATIVE_RUNTIME_FACTS } from "./runtimes.js";
4
- import { nativeExecutable, nativeMetadata } from "./discovery.js";
4
+ import { nativeExecutable, nativeMetadata, nativeSpawnEnv } from "./discovery.js";
5
5
  const unknownUsage = () => ({ input_tokens: null, output_tokens: null, cache_read_tokens: null, cache_write_tokens: null, cost_usd: null });
6
6
  const count = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
7
7
  /** A stop kills the source immediately, then gives its already reported events this long to finish recording. */
@@ -118,7 +118,8 @@ export async function openNativeSession(options) {
118
118
  const denials = [], toolNames = new Map();
119
119
  const seenEvents = new Set();
120
120
  let eventQueue = Promise.resolve(), eventsClosed = false;
121
- const child = spawn(binary, args, { cwd: target.project, env, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
121
+ // USER filled where the server has none, so the CLI reads the person's Keychain item (nativeSpawnEnv).
122
+ const child = spawn(binary, args, { cwd: target.project, env: nativeSpawnEnv(env), detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
122
123
  active = child;
123
124
  const emit = (event) => { eventQueue = eventQueue.then(() => eventsClosed ? undefined : options.onEvent?.(event)).then(() => { }); eventQueue.catch(error => stop(error instanceof Error ? error : new Error("Native event recording failed."))); };
124
125
  const abort = () => stop(new NativeRuntimeError("Native turn was cancelled; its outcome may be incomplete. Inspect the recorded session before retrying.", "aborted", sessionId));
@@ -60,7 +60,7 @@ export declare class Observations {
60
60
  id: string;
61
61
  workspace_id: string;
62
62
  kind: string;
63
- state: "revoked" | "active";
63
+ state: "active" | "revoked";
64
64
  display_name: string;
65
65
  owner_user_id: string;
66
66
  cli_version: string;
@@ -86,7 +86,7 @@ export declare class Observations {
86
86
  id: string;
87
87
  workspace_id: string;
88
88
  kind: string;
89
- state: "revoked" | "active";
89
+ state: "active" | "revoked";
90
90
  display_name: string;
91
91
  owner_user_id: string;
92
92
  cli_version: string;
@@ -111,7 +111,7 @@ export declare class Observations {
111
111
  id: string;
112
112
  workspace_id: string;
113
113
  kind: string;
114
- state: "revoked" | "active";
114
+ state: "active" | "revoked";
115
115
  display_name: string;
116
116
  owner_user_id: string;
117
117
  cli_version: string;
@@ -133,7 +133,7 @@ export declare class Observations {
133
133
  id: string;
134
134
  workspace_id: string;
135
135
  kind: string;
136
- state: "revoked" | "active";
136
+ state: "active" | "revoked";
137
137
  display_name: string;
138
138
  owner_user_id: string;
139
139
  cli_version: string;
@@ -179,7 +179,7 @@ export declare class Observations {
179
179
  id: string;
180
180
  workspace_id: string;
181
181
  kind: string;
182
- state: "revoked" | "active";
182
+ state: "active" | "revoked";
183
183
  display_name: string;
184
184
  owner_user_id: string;
185
185
  cli_version: string;
@@ -204,7 +204,7 @@ export declare class Observations {
204
204
  id: string;
205
205
  workspace_id: string;
206
206
  kind: string;
207
- state: "revoked" | "active";
207
+ state: "active" | "revoked";
208
208
  display_name: string;
209
209
  owner_user_id: string;
210
210
  cli_version: string;
@@ -88,6 +88,41 @@ export declare function ollamaRelisted(env: NodeJS.ProcessEnv): Promise<readonly
88
88
  * one none): none where it was never asked. Synchronous, for the host's default model (model.ts hostModel), which a
89
89
  * listing primes before it is read. */
90
90
  export declare function ollamaKept(env: NodeJS.ProcessEnv): readonly OllamaListed[];
91
+ /** Forgets the listing kept for the Ollama `env` names, and the one under way for it, so the next ollamaModels asks it
92
+ * again at once: after a pull here (local-model.ts), the model is in the picker with no wait for OLLAMA_TTL_MS. A
93
+ * listing under way when it is forgotten still answers its caller, but is never kept: it may be from before the pull. */
94
+ export declare function ollamaForget(env: NodeJS.ProcessEnv): void;
95
+ /** How long the version of the Ollama here is waited for (ollamaVersion): a listing's deadline. */
96
+ export declare const OLLAMA_VERSION_TIMEOUT_MS = 2000;
97
+ /** The version the Ollama `env` names says it is (GET /api/version), or undefined where it names none, is refused, down,
98
+ * hung past `timeoutMs` or answers another shape. Nothing thrown. */
99
+ export declare function ollamaVersion(env: NodeJS.ProcessEnv, { fetch: send, timeoutMs }?: {
100
+ fetch?: typeof fetch;
101
+ timeoutMs?: number;
102
+ }): Promise<string | undefined>;
103
+ /** One line of a pull's progress as Ollama streams it (POST /api/pull): its status, and a layer's digest with its bytes. */
104
+ export type OllamaPullLine = {
105
+ readonly status: string;
106
+ readonly digest?: string;
107
+ readonly total?: number;
108
+ readonly completed?: number;
109
+ };
110
+ /** How long a pull may go with no byte from Ollama before it stops (ollamaPull): a registry that stalls, or an Ollama
111
+ * that wedges, frees the one pull here instead of holding it at `pulling` until the server restarts. */
112
+ export declare const PULL_STALL_MS = 120000;
113
+ /** The longest progress line a pull takes: Ollama's are a few hundred bytes, so a stream that sends no newline ends. */
114
+ export declare const PULL_LINE_MAX: number;
115
+ /**
116
+ * Pulls `tag` through the Ollama `env` names (POST /api/pull, streamed as NDJSON), each line of progress to `onLine` as it
117
+ * comes. Resolves once Ollama says `success`; throws, in Ollama's words, on an `error` line, a refusal, a stream that ends
118
+ * before `success`, or `signal`; in its own, on `stallMs` with no byte from Ollama (the answer's head or a chunk of the
119
+ * stream) or a line past PULL_LINE_MAX. No deadline on the whole: a model is gigabytes, and a pull that moves is let run.
120
+ */
121
+ export declare function ollamaPull(env: NodeJS.ProcessEnv, tag: string, onLine: (line: OllamaPullLine) => void, { fetch: send, signal, stallMs }?: {
122
+ fetch?: typeof fetch;
123
+ signal?: AbortSignal;
124
+ stallMs?: number;
125
+ }): Promise<void>;
91
126
  /** `env`'s Ollama listing as last kept (ollamaKept), in one string: each model's tag, capabilities and trained context.
92
127
  * A server compares it to see a model pulled, removed or an Ollama started since it made its offers (server.ts). */
93
128
  export declare const ollamaListing: (env: NodeJS.ProcessEnv) => string;
@@ -80,6 +80,9 @@ function splitHostPort(hostport) {
80
80
  * for it. */
81
81
  const kept = new Map();
82
82
  const asking = new Map();
83
+ /** Bumped by ollamaForget, per address: a listing asked before a forget answers its caller but is never kept, since it
84
+ * may be from before the pull that made the forget. */
85
+ const forgets = new Map();
83
86
  /** The clock a listing is kept by: Date.now, or a test's (ollamaClock). */
84
87
  let now = Date.now;
85
88
  /** A test's clock for the kept listings, so it ages them without waiting; with none, Date.now again. */
@@ -181,6 +184,7 @@ export async function listOllama(env, { fetch: send = globalThis.fetch, timeoutM
181
184
  return [];
182
185
  const deadline = AbortSignal.timeout(timeoutMs);
183
186
  const ask = askerOf(base, send, deadline);
187
+ const asked = forgets.get(base) ?? 0;
184
188
  let models = [];
185
189
  let whole = false;
186
190
  let down = false;
@@ -197,7 +201,9 @@ export async function listOllama(env, { fetch: send = globalThis.fetch, timeoutM
197
201
  }
198
202
  const before = kept.get(base)?.models;
199
203
  const listing = whole ? { at: now(), models } : { at: -Infinity, models: !down && before?.length ? before : models };
200
- kept.set(base, listing);
204
+ // A forget since this listing was asked: it answers its caller, and is never kept.
205
+ if ((forgets.get(base) ?? 0) === asked)
206
+ kept.set(base, listing);
201
207
  return listing.models;
202
208
  }
203
209
  /** Whether `error` is a refused connection (ECONNREFUSED anywhere in its causes): nothing listens at the address. */
@@ -239,7 +245,9 @@ export async function ollamaModels(env) {
239
245
  return known.models;
240
246
  let listing = asking.get(base);
241
247
  if (!listing) {
242
- listing = listOllama(env).finally(() => asking.delete(base));
248
+ const mine = listOllama(env).finally(() => { if (asking.get(base) === mine)
249
+ asking.delete(base); });
250
+ listing = mine;
243
251
  asking.set(base, listing);
244
252
  }
245
253
  return known ? known.models : listing;
@@ -261,6 +269,104 @@ export function ollamaKept(env) {
261
269
  const base = baseOf(env);
262
270
  return base === undefined ? [] : (kept.get(base)?.models ?? []);
263
271
  }
272
+ /** Forgets the listing kept for the Ollama `env` names, and the one under way for it, so the next ollamaModels asks it
273
+ * again at once: after a pull here (local-model.ts), the model is in the picker with no wait for OLLAMA_TTL_MS. A
274
+ * listing under way when it is forgotten still answers its caller, but is never kept: it may be from before the pull. */
275
+ export function ollamaForget(env) {
276
+ const base = baseOf(env);
277
+ if (base === undefined)
278
+ return;
279
+ forgets.set(base, (forgets.get(base) ?? 0) + 1);
280
+ kept.delete(base);
281
+ asking.delete(base);
282
+ }
283
+ /** How long the version of the Ollama here is waited for (ollamaVersion): a listing's deadline. */
284
+ export const OLLAMA_VERSION_TIMEOUT_MS = OLLAMA_LIST_TIMEOUT_MS;
285
+ /** The version the Ollama `env` names says it is (GET /api/version), or undefined where it names none, is refused, down,
286
+ * hung past `timeoutMs` or answers another shape. Nothing thrown. */
287
+ export async function ollamaVersion(env, { fetch: send = globalThis.fetch, timeoutMs = OLLAMA_VERSION_TIMEOUT_MS } = {}) {
288
+ const base = baseOf(env);
289
+ if (base === undefined)
290
+ return undefined;
291
+ try {
292
+ const answer = (await askerOf(base, send, AbortSignal.timeout(timeoutMs))("/api/version"));
293
+ return typeof answer?.version === "string" && answer.version.length > 0 && answer.version.length <= 64 ? answer.version : undefined;
294
+ }
295
+ catch {
296
+ return undefined;
297
+ }
298
+ }
299
+ /** How long a pull may go with no byte from Ollama before it stops (ollamaPull): a registry that stalls, or an Ollama
300
+ * that wedges, frees the one pull here instead of holding it at `pulling` until the server restarts. */
301
+ export const PULL_STALL_MS = 120_000;
302
+ /** The longest progress line a pull takes: Ollama's are a few hundred bytes, so a stream that sends no newline ends. */
303
+ export const PULL_LINE_MAX = 64 * 1024;
304
+ /**
305
+ * Pulls `tag` through the Ollama `env` names (POST /api/pull, streamed as NDJSON), each line of progress to `onLine` as it
306
+ * comes. Resolves once Ollama says `success`; throws, in Ollama's words, on an `error` line, a refusal, a stream that ends
307
+ * before `success`, or `signal`; in its own, on `stallMs` with no byte from Ollama (the answer's head or a chunk of the
308
+ * stream) or a line past PULL_LINE_MAX. No deadline on the whole: a model is gigabytes, and a pull that moves is let run.
309
+ */
310
+ export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fetch, signal, stallMs = PULL_STALL_MS } = {}) {
311
+ const base = baseOf(env);
312
+ if (base === undefined)
313
+ throw new Error("no Ollama is asked here");
314
+ const stall = new AbortController();
315
+ let timer;
316
+ const moved = () => {
317
+ clearTimeout(timer);
318
+ timer = setTimeout(() => stall.abort(), stallMs);
319
+ };
320
+ const stopped = signal ? AbortSignal.any([signal, stall.signal]) : stall.signal;
321
+ moved();
322
+ try {
323
+ const response = await send(`${base}/api/pull`, { method: "POST", redirect: "error", signal: stopped, headers: { "content-type": "application/json" }, body: JSON.stringify({ model: tag, stream: true }) });
324
+ if (!response.ok || !response.body) {
325
+ const said = safeJson(await response.text().catch(() => ""));
326
+ throw new Error(typeof said?.error === "string" ? said.error : `/api/pull: ${response.status}`);
327
+ }
328
+ const decoder = new TextDecoder();
329
+ let rest = "";
330
+ let succeeded = false;
331
+ const take = (text) => {
332
+ const line = safeJson(text);
333
+ if (!line || typeof line !== "object")
334
+ return;
335
+ if (typeof line.error === "string")
336
+ throw new Error(line.error);
337
+ if (typeof line.status !== "string")
338
+ return;
339
+ if (line.status === "success")
340
+ succeeded = true;
341
+ onLine({ status: line.status, ...(typeof line.digest === "string" ? { digest: line.digest } : {}), ...(line.total !== undefined ? { total: count(line.total) } : {}), ...(line.completed !== undefined ? { completed: count(line.completed) } : {}) });
342
+ };
343
+ for await (const chunk of response.body) {
344
+ moved();
345
+ rest += decoder.decode(chunk, { stream: true });
346
+ let cut;
347
+ while ((cut = rest.indexOf("\n")) >= 0) {
348
+ const text = rest.slice(0, cut).trim();
349
+ rest = rest.slice(cut + 1);
350
+ if (text)
351
+ take(text);
352
+ }
353
+ if (rest.length > PULL_LINE_MAX)
354
+ throw new Error(`Ollama sent a progress line longer than ${PULL_LINE_MAX} bytes, so the pull stopped. Press Pull again.`);
355
+ }
356
+ if (rest.trim())
357
+ take(rest.trim());
358
+ if (!succeeded)
359
+ throw new Error("the pull ended before Ollama said success");
360
+ }
361
+ catch (error) {
362
+ if (stall.signal.aborted && !signal?.aborted)
363
+ throw new Error(`Ollama sent nothing for ${Math.round(stallMs / 1000)} s, so the pull stopped. Press Pull again.`);
364
+ throw error;
365
+ }
366
+ finally {
367
+ clearTimeout(timer);
368
+ }
369
+ }
264
370
  /** `env`'s Ollama listing as last kept (ollamaKept), in one string: each model's tag, capabilities and trained context.
265
371
  * A server compares it to see a model pulled, removed or an Ollama started since it made its offers (server.ts). */
266
372
  export const ollamaListing = (env) => ollamaKept(env).map((model) => `${model.name}=${model.capabilities.join(",")}@${model.trained ?? ""}`).join(" ");