@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31

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 (172) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/README.md +739 -116
  3. package/dist/adapters.d.ts +35 -6
  4. package/dist/adapters.js +152 -26
  5. package/dist/agents.d.ts +18 -7
  6. package/dist/agents.js +19 -10
  7. package/dist/app.js +101 -26
  8. package/dist/background.d.ts +29 -0
  9. package/dist/background.js +397 -0
  10. package/dist/box-egress-vm.d.ts +125 -0
  11. package/dist/box-egress-vm.js +350 -0
  12. package/dist/box-egress.d.ts +99 -0
  13. package/dist/box-egress.js +259 -0
  14. package/dist/box-image.d.ts +1 -1
  15. package/dist/box-image.js +9 -7
  16. package/dist/box-relay-vm.d.ts +84 -0
  17. package/dist/box-relay-vm.js +410 -0
  18. package/dist/box-relay.d.ts +8 -5
  19. package/dist/box-relay.js +14 -9
  20. package/dist/boxes.d.ts +28 -5
  21. package/dist/boxes.js +44 -18
  22. package/dist/browser-cost.d.ts +41 -0
  23. package/dist/browser-cost.js +158 -0
  24. package/dist/cap.d.ts +130 -21
  25. package/dist/cap.js +339 -67
  26. package/dist/cli.js +30 -4
  27. package/dist/coding-tools.d.ts +7 -3
  28. package/dist/coding-tools.js +16 -10
  29. package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
  30. package/dist/console/assets/index-CnJBf7Lc.js +486 -0
  31. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/content-filter.d.ts +7 -0
  34. package/dist/content-filter.js +23 -0
  35. package/dist/decision-rows.d.ts +11 -3
  36. package/dist/decision-rows.js +18 -11
  37. package/dist/decisions.d.ts +3 -3
  38. package/dist/decisions.js +4 -3
  39. package/dist/errors.d.ts +2 -0
  40. package/dist/errors.js +5 -2
  41. package/dist/files.d.ts +9 -1
  42. package/dist/files.js +10 -2
  43. package/dist/grade.d.ts +11 -11
  44. package/dist/grade.js +43 -55
  45. package/dist/graph-served.d.ts +23 -0
  46. package/dist/graph-served.js +75 -0
  47. package/dist/graph-view.d.ts +7 -5
  48. package/dist/graph-view.js +10 -3
  49. package/dist/harness-app.d.ts +4 -2
  50. package/dist/harness-app.js +110 -19
  51. package/dist/harness-opencode/adapter.d.ts +45 -0
  52. package/dist/harness-opencode/adapter.js +272 -0
  53. package/dist/harness-opencode/binary.d.ts +18 -0
  54. package/dist/harness-opencode/binary.js +87 -0
  55. package/dist/harness-opencode/config.d.ts +24 -0
  56. package/dist/harness-opencode/config.js +61 -0
  57. package/dist/harness-opencode/harness.d.ts +77 -0
  58. package/dist/harness-opencode/harness.js +620 -0
  59. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  60. package/dist/harness-opencode/host/mcp.js +208 -0
  61. package/dist/harness-opencode/host/policy.d.ts +71 -0
  62. package/dist/harness-opencode/host/policy.js +419 -0
  63. package/dist/harness-opencode/host/server.d.ts +55 -0
  64. package/dist/harness-opencode/host/server.js +165 -0
  65. package/dist/harness-opencode/index.d.ts +9 -0
  66. package/dist/harness-opencode/index.js +6 -0
  67. package/dist/harness-opencode/verify.d.ts +32 -0
  68. package/dist/harness-opencode/verify.js +75 -0
  69. package/dist/harness-opencode/versions.d.ts +33 -0
  70. package/dist/harness-opencode/versions.js +64 -0
  71. package/dist/harness.d.ts +4 -1
  72. package/dist/harness.js +5 -2
  73. package/dist/host-check.d.ts +12 -0
  74. package/dist/host-check.js +34 -0
  75. package/dist/host-tools.d.ts +12 -2
  76. package/dist/host-tools.js +26 -12
  77. package/dist/host.js +6 -2
  78. package/dist/hosted-search.js +5 -1
  79. package/dist/import.d.ts +2 -2
  80. package/dist/import.js +4 -3
  81. package/dist/key-check.d.ts +3 -2
  82. package/dist/key-check.js +7 -3
  83. package/dist/key-refusal.js +8 -4
  84. package/dist/key-words.d.ts +37 -0
  85. package/dist/key-words.js +40 -0
  86. package/dist/learn/check.d.ts +10 -1
  87. package/dist/learn/check.js +19 -1
  88. package/dist/learn/grade.d.ts +6 -2
  89. package/dist/learn/grade.js +28 -14
  90. package/dist/learn/index.d.ts +3 -3
  91. package/dist/learn/index.js +3 -3
  92. package/dist/learn/notes.js +2 -1
  93. package/dist/learn/reflect.d.ts +2 -2
  94. package/dist/learn/reflect.js +53 -5
  95. package/dist/learn/secrets.js +28 -8
  96. package/dist/learn/skills.d.ts +19 -4
  97. package/dist/learn/skills.js +95 -6
  98. package/dist/learned-workflow.d.ts +59 -0
  99. package/dist/learned-workflow.js +191 -0
  100. package/dist/learning-routes.d.ts +30 -1
  101. package/dist/learning-routes.js +173 -19
  102. package/dist/learning-run.d.ts +8 -6
  103. package/dist/learning-run.js +70 -27
  104. package/dist/learning-words.d.ts +12 -5
  105. package/dist/learning-words.js +34 -13
  106. package/dist/learning.d.ts +52 -3
  107. package/dist/learning.js +204 -4
  108. package/dist/mcp-gateway.d.ts +96 -0
  109. package/dist/mcp-gateway.js +408 -0
  110. package/dist/mcp-meta.d.ts +17 -0
  111. package/dist/mcp-meta.js +38 -0
  112. package/dist/mcp-servers.d.ts +33 -9
  113. package/dist/mcp-servers.js +58 -10
  114. package/dist/mcp.js +5 -5
  115. package/dist/model.d.ts +13 -11
  116. package/dist/model.js +11 -10
  117. package/dist/openapi/agentrun-v2.openapi.json +1 -0
  118. package/dist/openapi.js +407 -54
  119. package/dist/page.d.ts +2 -0
  120. package/dist/page.js +3 -0
  121. package/dist/paid-calls.d.ts +5 -1
  122. package/dist/paid-calls.js +1 -1
  123. package/dist/pause.d.ts +2 -0
  124. package/dist/place.d.ts +29 -5
  125. package/dist/place.js +51 -11
  126. package/dist/print.d.ts +7 -0
  127. package/dist/print.js +13 -0
  128. package/dist/propose.d.ts +2 -0
  129. package/dist/propose.js +38 -8
  130. package/dist/request-start.d.ts +12 -4
  131. package/dist/request-start.js +139 -15
  132. package/dist/run-box.d.ts +56 -4
  133. package/dist/run-box.js +183 -23
  134. package/dist/runnable.d.ts +13 -3
  135. package/dist/runnable.js +63 -6
  136. package/dist/runs.d.ts +266 -37
  137. package/dist/runs.js +884 -90
  138. package/dist/secrets.d.ts +27 -0
  139. package/dist/secrets.js +38 -2
  140. package/dist/server.d.ts +141 -36
  141. package/dist/server.js +562 -118
  142. package/dist/sign-ins.d.ts +99 -0
  143. package/dist/sign-ins.js +288 -0
  144. package/dist/skills.d.ts +16 -4
  145. package/dist/skills.js +35 -7
  146. package/dist/stats.d.ts +7 -2
  147. package/dist/stats.js +28 -7
  148. package/dist/tool-gate.d.ts +281 -0
  149. package/dist/tool-gate.js +585 -0
  150. package/dist/tool-keys.d.ts +48 -11
  151. package/dist/tool-keys.js +46 -8
  152. package/dist/tool-plane.d.ts +116 -27
  153. package/dist/tool-plane.js +232 -50
  154. package/dist/tools.d.ts +69 -14
  155. package/dist/tools.js +148 -26
  156. package/dist/trigger-secrets.d.ts +32 -0
  157. package/dist/trigger-secrets.js +143 -0
  158. package/dist/triggers.d.ts +439 -0
  159. package/dist/triggers.js +863 -0
  160. package/dist/turn-end.d.ts +3 -2
  161. package/dist/turn-end.js +3 -2
  162. package/dist/usage-lines.d.ts +26 -0
  163. package/dist/usage-lines.js +28 -0
  164. package/dist/validate.d.ts +2 -0
  165. package/dist/validate.js +11 -2
  166. package/dist/web-fetch.js +3 -3
  167. package/dist/webhooks.d.ts +11 -4
  168. package/dist/webhooks.js +17 -1
  169. package/launcher/agentrun-serve +1 -1
  170. package/package.json +16 -14
  171. package/dist/console/assets/index-BN7oVcO4.js +0 -445
  172. package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/cli.js CHANGED
@@ -7,10 +7,12 @@ import { secret } from "./secrets.js";
7
7
  import "./quiet-sqlite-warning.js";
8
8
  import { parseArgs } from "node:util";
9
9
  import { spawn } from "node:child_process";
10
- import { defaultData } from "./files.js";
10
+ import { chmodSync, rmSync, writeFileSync } from "node:fs";
11
+ import { join, resolve } from "node:path";
12
+ import { defaultData, SERVER_FILE } from "./files.js";
11
13
  import { canOpen } from "./host.js";
12
14
  import { resetPassword } from "./owner.js";
13
- import { banner } from "./print.js";
15
+ import { banner, boxImageLine } from "./print.js";
14
16
  import { DEFAULT_PORT, startServe } from "./server.js";
15
17
  const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL]
16
18
  agentrun-serve reset-password [--data DIR]
@@ -138,13 +140,31 @@ const given = secret("AGENTRUN_TOKEN") || undefined;
138
140
  // A stdout its reader closed (a pipe left behind) loses the log lines, never the server.
139
141
  process.stdout.on("error", () => undefined);
140
142
  const accounts = process.env.AGENTRUN_ACCOUNTS !== "0";
143
+ // The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
144
+ // before the banner is printed waits for it.
145
+ let imageSaid = false;
146
+ let bannered = false;
147
+ const early = [];
148
+ const onBoxImage = (state) => {
149
+ const line = boxImageLine(state, imageSaid);
150
+ if (line === undefined)
151
+ return;
152
+ imageSaid = true;
153
+ if (bannered)
154
+ console.log(line);
155
+ else
156
+ early.push(line);
157
+ };
141
158
  let serve;
142
159
  try {
143
160
  serve = await startServe({
161
+ onBoxImage,
144
162
  data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), allowHosts: values["allow-host"],
145
163
  ...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
146
164
  ...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
147
- ...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true, ...(publicUrl ? { publicUrl } : {}) } : {}),
165
+ // The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
166
+ ...(publicUrl ? { publicUrl } : {}),
167
+ ...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}),
148
168
  });
149
169
  }
150
170
  catch (error) {
@@ -158,10 +178,16 @@ for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token:
158
178
  // With a public address the setup link and its code are printed as the code is made (owner.ts).
159
179
  if (serve.setupUrl && !publicUrl)
160
180
  console.log(`Set your password: ${serve.setupUrl} (the first visit sets it)`);
181
+ bannered = true;
182
+ for (const line of early.splice(0))
183
+ console.log(line);
161
184
  // The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
162
185
  // and the browser's history.
163
186
  if (values.open && canOpen(process.env))
164
187
  spawn(process.platform === "darwin" ? "open" : "xdg-open", [`${publicUrl ?? serve.url}/`], { stdio: "ignore", detached: true }).on("error", () => { }).unref();
165
- const stop = () => void serve.close().then(() => process.exit(0));
188
+ const record = join(resolve(data), SERVER_FILE);
189
+ writeFileSync(record, `${JSON.stringify({ base_url: serve.baseUrl, pid: process.pid, ...(serve.tokenFile ? { token_file: serve.tokenFile } : {}) })}\n`, { mode: 0o600 });
190
+ chmodSync(record, 0o600);
191
+ const stop = () => void serve.close().then(() => (rmSync(record, { force: true }), process.exit(0)));
166
192
  process.once("SIGINT", stop);
167
193
  process.once("SIGTERM", stop);
@@ -1,10 +1,13 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import { type Extension, type ToolRegistration } from "@earendil-works/pi-durable";
3
+ import { SHELL_TOOLS } from "./background.js";
3
4
  import { type Place } from "./place.js";
4
5
  /** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
5
6
  * call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
6
7
  export declare const CodingTools: Extension;
7
- /** The tools a box runs: pi's, by name. */
8
+ /** The tools that run a command in the box, never on this machine: bash, and the background tools (background.ts). */
9
+ export { SHELL_TOOLS };
10
+ /** The tools a box runs, by name: pi's four and the background tools. */
8
11
  export declare const BOXED_TOOLS: readonly string[];
9
12
  /** A run's coding tools and the extension a conversation selects for them. */
10
13
  export type CodingSource = {
@@ -26,6 +29,7 @@ export type BoxedEnv = {
26
29
  * path. */
27
30
  export declare function boxPath(path: string, hostWork?: string): string | undefined;
28
31
  /** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
29
- * each with its arguments, output and replay as pi ships it and its environment the box's. A file tool's path stays in
30
- * the box's work dir; bash's command is the box's own. */
32
+ * each with its arguments, output and replay as pi ships it and its environment the box's, and the background tools
33
+ * (background.ts), each call a command in the box. A file tool's path stays in the box's work dir; bash's command is
34
+ * the box's own. */
31
35
  export declare function codingSource(place: Place, box?: BoxedEnv): CodingSource;
@@ -4,19 +4,20 @@
4
4
  // wrapped so a refusal names the path the call gave (asGivenRefusals), and the extension keeps everything else pi's
5
5
  // carries (its name, so a conversation selects it as before).
6
6
  //
7
- // A run whose place is a box gets codingSource's instead: pi's own read, write, edit and bash, each call made on the
8
- // box's environment (run-box.ts), so the shell exists only in the box. One source feeds pi's tool table (tools.ts,
7
+ // A run whose place is a box gets codingSource's instead: pi's own read, write, edit and bash, and the background tools
8
+ // (background.ts), each call made on the box's environment (run-box.ts), so the shell exists only in the box. One source feeds pi's tool table (tools.ts,
9
9
  // app.ts) and another harness's host tools (host-tools.ts).
10
10
  //
11
11
  // Where the box binds the run's work/ from this machine and the confinement holds directory handles (Docker on Linux),
12
12
  // read, write and edit run on this machine instead, on the bind's source (bound-files.ts): a command in the box costs
13
- // far more than a file read. bash always runs in the box, and every tool of any other box (or of any host that reaches
14
- // directories by path) does too.
13
+ // far more than a file read. bash and the background tools always run in the box, and every tool of any other box (or of
14
+ // any host that reaches directories by path) does too.
15
15
  import { posix } from "node:path";
16
16
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
17
17
  import { FileError } from "@earendil-works/pi-durable/env";
18
18
  import { HOST_PHASE } from "@parcha/pi-durable-agent/timeline";
19
19
  import { ArchilCodingTools } from "@parcha/pi-durable-disk";
20
+ import { BACKGROUND_TOOLS, backgroundTools, SHELL_TOOLS } from "./background.js";
20
21
  import { boundFiles } from "./bound-files.js";
21
22
  import { BOX_WORK } from "./place.js";
22
23
  import { asGivenRefusals, refuseOutsideWorkspace } from "./workspace-paths.js";
@@ -27,8 +28,12 @@ const pis = ArchilCodingTools;
27
28
  /** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
28
29
  * call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
29
30
  export const CodingTools = { ...pis, tools: asGivenRefusals((pis.tools ?? []).filter((tool) => tool.name !== "bash")) };
30
- /** The tools a box runs: pi's, by name. */
31
- export const BOXED_TOOLS = ["read", "write", "edit", "bash"];
31
+ /** pi's tools a box runs, by name. */
32
+ const PI_BOXED = ["read", "write", "edit", "bash"];
33
+ /** The tools that run a command in the box, never on this machine: bash, and the background tools (background.ts). */
34
+ export { SHELL_TOOLS };
35
+ /** The tools a box runs, by name: pi's four and the background tools. */
36
+ export const BOXED_TOOLS = [...PI_BOXED, ...BACKGROUND_TOOLS];
32
37
  /** A failed call's error with what the file environment said, where pi's message gives only its code (edit's "Error
33
38
  * code: permission_denied."), so the model reads why and what it can do. */
34
39
  const withCause = (error) => {
@@ -47,15 +52,16 @@ export function boxPath(path, hostWork) {
47
52
  return at === BOX_WORK || at.startsWith(`${BOX_WORK}/`) ? named : undefined;
48
53
  }
49
54
  /** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
50
- * each with its arguments, output and replay as pi ships it and its environment the box's. A file tool's path stays in
51
- * the box's work dir; bash's command is the box's own. */
55
+ * each with its arguments, output and replay as pi ships it and its environment the box's, and the background tools
56
+ * (background.ts), each call a command in the box. A file tool's path stays in the box's work dir; bash's command is
57
+ * the box's own. */
52
58
  export function codingSource(place, box) {
53
59
  if (place.mode === "runner")
54
60
  return { extension: CodingTools, tools: CodingTools.tools ?? [] };
55
61
  if (!box)
56
62
  throw new Error("a run whose place is a box needs its box for its coding tools");
57
63
  const here = box.hostWork && writesHeld() ? boundFiles(box.hostWork) : undefined;
58
- const tools = asGivenRefusals((pis.tools ?? []).filter((tool) => BOXED_TOOLS.includes(tool.name)).map((tool) => ({
64
+ const tools = asGivenRefusals([...(pis.tools ?? []).filter((tool) => PI_BOXED.includes(tool.name)), ...backgroundTools()].map((tool) => ({
59
65
  ...tool,
60
66
  execute: async (args, api, context) => {
61
67
  // A file tool's path in the box's words, or refused as the confined tools refuse (refuseOutsideWorkspace): named
@@ -67,7 +73,7 @@ export function codingSource(place, box) {
67
73
  const given = inBox === undefined ? args : { ...args, path: inBox };
68
74
  // read, write and edit on this machine's work/, where the box binds it; no box is made for them. A box an earlier
69
75
  // process left has its left commands killed first, so none of them changes work/ under these tools.
70
- if (here && tool.name !== "bash" && (await box.bound?.()) === true) {
76
+ if (here && !SHELL_TOOLS.includes(tool.name) && (await box.bound?.()) === true) {
71
77
  await box.leftEnded?.(context);
72
78
  return tool.execute(given, { ...api, env: here }, context).catch((error) => Promise.reject(withCause(error)));
73
79
  }