@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56

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 (234) hide show
  1. package/CHANGELOG.md +142 -2
  2. package/README.md +310 -98
  3. package/dist/adapters.d.ts +11 -0
  4. package/dist/adapters.js +49 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-only.d.ts +16 -4
  11. package/dist/api-only.js +23 -7
  12. package/dist/calendar/tools.js +3 -2
  13. package/dist/chatgpt-plan.d.ts +16 -1
  14. package/dist/chatgpt-plan.js +116 -12
  15. package/dist/claude-login.d.ts +34 -5
  16. package/dist/claude-login.js +31 -7
  17. package/dist/claude-sign-in.d.ts +35 -0
  18. package/dist/claude-sign-in.js +90 -0
  19. package/dist/cli.js +5 -3
  20. package/dist/composio-made.d.ts +26 -1
  21. package/dist/composio-made.js +39 -2
  22. package/dist/composio-preset.d.ts +3 -2
  23. package/dist/composio-preset.js +46 -14
  24. package/dist/computer-held-routes.js +2 -3
  25. package/dist/computer-setting.d.ts +4 -2
  26. package/dist/computer-setting.js +0 -2
  27. package/dist/computers-running.d.ts +8 -0
  28. package/dist/computers-running.js +27 -0
  29. package/dist/console/assets/backend-Boh7tC4i.js +166 -0
  30. package/dist/console/assets/index-CQ3cJRzI.js +746 -0
  31. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/docker-host-addresses.d.ts +23 -3
  34. package/dist/docker-host-addresses.js +90 -18
  35. package/dist/exa-keyless.d.ts +2 -3
  36. package/dist/exa-keyless.js +43 -127
  37. package/dist/firecrawl-keyless.d.ts +41 -0
  38. package/dist/firecrawl-keyless.js +152 -0
  39. package/dist/handed-secret.d.ts +3 -1
  40. package/dist/handed-secret.js +4 -2
  41. package/dist/harness-keys.d.ts +98 -0
  42. package/dist/harness-keys.js +247 -0
  43. package/dist/harness-recipe-entry.d.ts +14 -9
  44. package/dist/harness-recipe-entry.js +25 -14
  45. package/dist/harness-table.d.ts +16 -1
  46. package/dist/harness-table.js +19 -7
  47. package/dist/harness.d.ts +4 -0
  48. package/dist/harness.js +12 -1
  49. package/dist/host-check.d.ts +6 -0
  50. package/dist/host-check.js +10 -0
  51. package/dist/import-summary.d.ts +1 -1
  52. package/dist/import-summary.js +1 -1
  53. package/dist/import.d.ts +5 -5
  54. package/dist/import.js +54 -67
  55. package/dist/key-refusal.d.ts +21 -5
  56. package/dist/key-refusal.js +231 -37
  57. package/dist/keyless-mcp.d.ts +36 -0
  58. package/dist/keyless-mcp.js +127 -0
  59. package/dist/learn/audit.d.ts +3 -3
  60. package/dist/learn/audit.js +3 -3
  61. package/dist/learn/commit.d.ts +8 -7
  62. package/dist/learn/commit.js +60 -20
  63. package/dist/learn/compile.d.ts +4 -3
  64. package/dist/learn/compile.js +7 -5
  65. package/dist/learn/folder.d.ts +16 -3
  66. package/dist/learn/folder.js +46 -13
  67. package/dist/learn/promote.d.ts +37 -13
  68. package/dist/learn/promote.js +112 -40
  69. package/dist/learn/secrets.d.ts +20 -10
  70. package/dist/learn/secrets.js +44 -176
  71. package/dist/learning-routes.d.ts +22 -17
  72. package/dist/learning-routes.js +40 -39
  73. package/dist/learning.js +2 -2
  74. package/dist/llms.txt +1 -1
  75. package/dist/manifest.d.ts +10 -0
  76. package/dist/manifest.js +30 -0
  77. package/dist/mcp-pin-first.d.ts +4 -2
  78. package/dist/mcp-pin-first.js +5 -2
  79. package/dist/mcp-secret-writes.d.ts +16 -7
  80. package/dist/mcp-secret-writes.js +35 -27
  81. package/dist/mcp-servers-store.d.ts +30 -6
  82. package/dist/mcp-servers-store.js +112 -28
  83. package/dist/mcp-sources.d.ts +10 -2
  84. package/dist/mcp-sources.js +9 -2
  85. package/dist/mcp-store.d.ts +13 -7
  86. package/dist/mcp-store.js +12 -9
  87. package/dist/model-form.d.ts +3 -2
  88. package/dist/model-form.js +11 -7
  89. package/dist/model.d.ts +20 -4
  90. package/dist/model.js +68 -9
  91. package/dist/native/history.d.ts +1 -1
  92. package/dist/native/history.js +2 -2
  93. package/dist/ollama-provider.d.ts +92 -0
  94. package/dist/ollama-provider.js +495 -0
  95. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  96. package/dist/openapi.d.ts +3 -3
  97. package/dist/openapi.js +197 -55
  98. package/dist/page.d.ts +11 -3
  99. package/dist/page.js +22 -7
  100. package/dist/place-offers.d.ts +25 -1
  101. package/dist/place-offers.js +62 -8
  102. package/dist/print.js +1 -1
  103. package/dist/purged-workflow.d.ts +35 -7
  104. package/dist/purged-workflow.js +73 -26
  105. package/dist/redact/match.d.ts +74 -0
  106. package/dist/redact/match.js +771 -0
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/run-timeline-served.d.ts +1 -1
  119. package/dist/run-timeline-served.js +4 -4
  120. package/dist/runner/adapter-loop.d.ts +9 -3
  121. package/dist/runner/adapter-loop.js +34 -15
  122. package/dist/runner/adapter-run-spec.d.ts +3 -0
  123. package/dist/runner/adapter-run-spec.js +9 -4
  124. package/dist/runner/audit.js +8 -4
  125. package/dist/runner/beside.d.ts +2 -1
  126. package/dist/runner/beside.js +13 -5
  127. package/dist/runner/claim-secrets.d.ts +5 -8
  128. package/dist/runner/claim-secrets.js +6 -0
  129. package/dist/runner/cli-run-spec.d.ts +1 -1
  130. package/dist/runner/cli-run-spec.js +41 -7
  131. package/dist/runner/harness-loops.d.ts +22 -9
  132. package/dist/runner/harness-loops.js +21 -11
  133. package/dist/runner/held.d.ts +3 -0
  134. package/dist/runner/learning-end.d.ts +1 -1
  135. package/dist/runner/learning-end.js +8 -3
  136. package/dist/runner/loop-contract.d.ts +9 -4
  137. package/dist/runner/main.js +12 -6
  138. package/dist/runner/mcp-claim.d.ts +3 -0
  139. package/dist/runner/mcp-claim.js +26 -2
  140. package/dist/runner/mcp-run.d.ts +3 -0
  141. package/dist/runner/mcp-run.js +2 -1
  142. package/dist/runner/metrics.d.ts +10 -10
  143. package/dist/runner/metrics.js +19 -38
  144. package/dist/runner/model-route.d.ts +3 -0
  145. package/dist/runner/model-route.js +6 -2
  146. package/dist/runner/presence.d.ts +4 -3
  147. package/dist/runner/presence.js +4 -2
  148. package/dist/runner/promotion.d.ts +15 -9
  149. package/dist/runner/promotion.js +25 -15
  150. package/dist/runner/run-child-host.d.ts +2 -0
  151. package/dist/runner/run-child-host.js +19 -9
  152. package/dist/runner/run-child.js +3 -1
  153. package/dist/runner/runner.d.ts +4 -0
  154. package/dist/runner/runner.js +33 -3
  155. package/dist/runner/sdk-loop.js +2 -0
  156. package/dist/runner/workflow-loop.d.ts +2 -2
  157. package/dist/runner/workflow-loop.js +1 -2
  158. package/dist/runner/workflow-spec.d.ts +1 -1
  159. package/dist/runner/workflow-spec.js +6 -6
  160. package/dist/sdk/check.d.ts +4 -1
  161. package/dist/sdk/check.js +2 -1
  162. package/dist/sdk/runs.d.ts +2 -2
  163. package/dist/sdk/runs.js +8 -6
  164. package/dist/secret-cut.js +2 -1
  165. package/dist/secret-writes.d.ts +3 -2
  166. package/dist/secret-writes.js +1 -1
  167. package/dist/server.d.ts +49 -10
  168. package/dist/server.js +324 -118
  169. package/dist/standard-webhooks.d.ts +11 -0
  170. package/dist/standard-webhooks.js +20 -2
  171. package/dist/store/dialect.d.ts +3 -0
  172. package/dist/store/dialect.js +1 -0
  173. package/dist/store/index.d.ts +2 -2
  174. package/dist/store/index.js +1 -1
  175. package/dist/store/postgres/dialect.js +3 -0
  176. package/dist/store/schema.js +5 -2
  177. package/dist/store/sqlite/store.js +133 -47
  178. package/dist/store/store.d.ts +64 -15
  179. package/dist/store/store.js +7 -0
  180. package/dist/store-reads/journal.d.ts +7 -2
  181. package/dist/store-reads/journal.js +9 -6
  182. package/dist/store-reads/learning.d.ts +12 -9
  183. package/dist/store-reads/learning.js +18 -24
  184. package/dist/store-view.d.ts +0 -5
  185. package/dist/store-view.js +10 -9
  186. package/dist/template-eval.d.ts +51 -6
  187. package/dist/template-eval.js +177 -53
  188. package/dist/template-import.js +4 -2
  189. package/dist/templates.d.ts +5 -3
  190. package/dist/templates.js +19 -40
  191. package/dist/timeline/index.d.ts +1 -1
  192. package/dist/timeline/index.js +1 -1
  193. package/dist/timeline/labels.d.ts +2 -2
  194. package/dist/timeline/labels.js +2 -2
  195. package/dist/timeline/timeline.d.ts +14 -9
  196. package/dist/timeline/timeline.js +15 -7
  197. package/dist/tool-gate.js +3 -1
  198. package/dist/tool-plane.d.ts +17 -9
  199. package/dist/tool-plane.js +38 -17
  200. package/dist/tools.js +2 -2
  201. package/dist/trigger-launch-hook.d.ts +16 -8
  202. package/dist/trigger-launch-hook.js +32 -23
  203. package/dist/trigger-targets.d.ts +18 -8
  204. package/dist/trigger-targets.js +42 -19
  205. package/dist/triggers.d.ts +85 -23
  206. package/dist/triggers.js +303 -96
  207. package/dist/validate.js +1 -1
  208. package/dist/web-fake.js +3 -3
  209. package/dist/web-fetch-direct.d.ts +4 -0
  210. package/dist/web-fetch-direct.js +8 -1
  211. package/dist/web-fetch.d.ts +12 -3
  212. package/dist/web-fetch.js +47 -14
  213. package/dist/web-search.d.ts +33 -4
  214. package/dist/web-search.js +100 -41
  215. package/dist/webhooks.js +4 -5
  216. package/dist/workspace/computer-deps.d.ts +2 -1
  217. package/dist/workspace/computer-deps.js +5 -4
  218. package/dist/workspace/computer-for-claim.d.ts +8 -2
  219. package/dist/workspace/computer-for-claim.js +28 -9
  220. package/dist/workspace/computer-janitor.d.ts +15 -7
  221. package/dist/workspace/computer-janitor.js +33 -8
  222. package/dist/workspace/computer-kept.d.ts +52 -4
  223. package/dist/workspace/computer-kept.js +118 -6
  224. package/dist/workspace/run-end-computers.d.ts +5 -1
  225. package/dist/workspace/run-end-computers.js +27 -1
  226. package/dist/wrapped.d.ts +57 -0
  227. package/dist/wrapped.js +51 -0
  228. package/launcher/agentrun-serve +5 -1
  229. package/package.json +17 -13
  230. package/templates/README.md +10 -9
  231. package/dist/console/assets/index-B_85An2t.js +0 -745
  232. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  233. package/dist/import-sources.d.ts +0 -116
  234. package/dist/import-sources.js +0 -693
package/dist/page.d.ts CHANGED
@@ -24,10 +24,18 @@ export declare const cookiesOf: (req: IncomingMessage, name: string) => string[]
24
24
  export declare const overHttps: (req: IncomingMessage) => boolean;
25
25
  export declare const ownOrigin: (req: IncomingMessage) => string;
26
26
  export declare const isJson: (req: IncomingMessage) => boolean;
27
- /** The owner's session cookie: `__Host-` on https, so no other host or path can set it; else one per port. */
27
+ /** The owner's session cookie: `__Host-` on https, so no other host or path can set it; else one per port the browser opened. */
28
28
  export declare const ownerCookieName: (req: IncomingMessage) => string;
29
- /** A Set-Cookie line for the owner's session: `value`, or an empty one that ends it (`maxAgeS` 0). */
30
- export declare const ownerCookie: (req: IncomingMessage, value: string, maxAgeS: number) => string;
29
+ /** A Set-Cookie line for the owner's session: `value`, or an empty one that ends it (`maxAgeS` 0); under `name`, this
30
+ * request's own unless another is given. */
31
+ export declare const ownerCookie: (req: IncomingMessage, value: string, maxAgeS: number, name?: string) => string;
32
+ /** The owner's session cookies the request holds under this request's name and under any port's (`agentrun-<port>-session`),
33
+ * each with its name, valid or not: a browser sends a host's cookies to every port of it, so one signed in at 7340 and
34
+ * again through a tunnel at 8080 sends both to either. Which are this server's is the owner's to say (Owner.valid). */
35
+ export declare const sessionsAtEveryPort: (req: IncomingMessage) => Array<{
36
+ name: string;
37
+ value: string;
38
+ }>;
31
39
  /** The owner's session cookies the request holds, valid or not. */
32
40
  export declare const heldSessions: (req: IncomingMessage) => string[];
33
41
  /** Whether the request holds a session the owner signed in. */
package/dist/page.js CHANGED
@@ -9,7 +9,7 @@ import { readFile, realpath, stat } from "node:fs/promises";
9
9
  import { extname, join, sep } from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { ApiError } from "./errors.js";
12
- import { hostRefusedPage, movedPage } from "./host-check.js";
12
+ import { hostPort, hostRefusedPage, movedPage } from "./host-check.js";
13
13
  // img-src names Google's favicon service and the four hosts it redirects to: the console's Keys page shows a provider's
14
14
  // icon from it (apps/console/src/components/ProviderIcon.tsx), sent with no referrer. Everything else is this origin's.
15
15
  const CSP = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https://www.google.com https://t0.gstatic.com https://t1.gstatic.com https://t2.gstatic.com https://t3.gstatic.com; base-uri 'none'; form-action https://github.com; frame-ancestors 'none'";
@@ -65,16 +65,31 @@ export class ConsoleSessions {
65
65
  return this.ids.has(digest(value).toString("hex"));
66
66
  }
67
67
  }
68
- /** One name per port: cookies are kept per host, not per port, and another server on this machine has another token. */
69
- const cookieName = (req) => `agentrun-${req.socket.localPort}`;
68
+ /** One name per port the browser opened: cookies are kept per host, not per port, and another server on this machine has
69
+ * another token. The port is the Host header's, the browser's: a server in a container sees its own port on its socket
70
+ * (7340, published at 7350), and so does another beside it. A Host with no port keeps the socket's. */
71
+ const browserPort = (req) => hostPort(req.headers.host) ?? req.socket.localPort;
72
+ const cookieName = (req) => `agentrun-${browserPort(req)}`;
70
73
  export const cookiesOf = (req, name) => String(req.headers.cookie ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(`${name}=`)).map((part) => part.slice(name.length + 1));
71
74
  export const overHttps = (req) => String(req.headers["x-forwarded-proto"] ?? "").split(",")[0].trim().toLowerCase() === "https";
72
75
  export const ownOrigin = (req) => `${overHttps(req) ? "https" : "http"}://${String(req.headers.host ?? "").toLowerCase()}`;
73
76
  export const isJson = (req) => String(req.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase() === "application/json";
74
- /** The owner's session cookie: `__Host-` on https, so no other host or path can set it; else one per port. */
75
- export const ownerCookieName = (req) => (overHttps(req) ? "__Host-agentrun-session" : `agentrun-${req.socket.localPort}-session`);
76
- /** A Set-Cookie line for the owner's session: `value`, or an empty one that ends it (`maxAgeS` 0). */
77
- export const ownerCookie = (req, value, maxAgeS) => `${ownerCookieName(req)}=${value}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${maxAgeS}${overHttps(req) ? "; Secure" : ""}`;
77
+ /** The owner's session cookie: `__Host-` on https, so no other host or path can set it; else one per port the browser opened. */
78
+ export const ownerCookieName = (req) => (overHttps(req) ? "__Host-agentrun-session" : `agentrun-${browserPort(req)}-session`);
79
+ /** A Set-Cookie line for the owner's session: `value`, or an empty one that ends it (`maxAgeS` 0); under `name`, this
80
+ * request's own unless another is given. */
81
+ export const ownerCookie = (req, value, maxAgeS, name = ownerCookieName(req)) => `${name}=${value}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${maxAgeS}${overHttps(req) ? "; Secure" : ""}`;
82
+ /** The owner's session cookies the request holds under this request's name and under any port's (`agentrun-<port>-session`),
83
+ * each with its name, valid or not: a browser sends a host's cookies to every port of it, so one signed in at 7340 and
84
+ * again through a tunnel at 8080 sends both to either. Which are this server's is the owner's to say (Owner.valid). */
85
+ export const sessionsAtEveryPort = (req) => {
86
+ const own = ownerCookieName(req);
87
+ return String(req.headers.cookie ?? "").split(";").flatMap((part) => {
88
+ const at = part.indexOf("=");
89
+ const name = part.slice(0, at).trim();
90
+ return at > 0 && (name === own || /^agentrun-\d{1,5}-session$/.test(name)) ? [{ name, value: part.slice(at + 1).trim() }] : [];
91
+ });
92
+ };
78
93
  /** The owner's session cookies the request holds, valid or not. */
79
94
  export const heldSessions = (req) => cookiesOf(req, ownerCookieName(req));
80
95
  /** Whether the request holds a session the owner signed in. */
@@ -41,6 +41,27 @@ export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySe
41
41
  export declare const DOCKER_NOT_IN_GROUP = "This server's process isn't in the docker group: restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
42
42
  /** The same, when the group file does not list this user in the docker group (or cannot say): joining comes first. */
43
43
  export declare const DOCKER_JOIN_GROUP = "This server's process isn't in the docker group: add this user to it with `sudo usermod -aG docker $USER`, then restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
44
+ /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: the one-container `docker run`,
45
+ * deploy/'s compose file and a Kubernetes pod give it none, so it asks a daemon that is not there. Starting Docker or
46
+ * joining its group would not help: compose.yaml at the repository's root mounts the host's socket, which is root on
47
+ * that host (compose.yaml's own header says so), so the words say that too. */
48
+ export declare const DOCKER_NO_SOCKET = "This server runs in a container with no Docker socket, so its agents get file tools and web_fetch but no shell: for a shell in Docker sandboxes, give it the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
49
+ /** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
50
+ * socket's. usermod in the container would not last past its restart. */
51
+ export declare const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
52
+ /** Whether this server runs in a container, whether it is AgentRun's own image (IMAGE_ENV), and how it tells whether a
53
+ * path is there (`exists`: the socket a failed probe names). What a failed probe says to do. */
54
+ export type ContainerFacts = {
55
+ inside: boolean;
56
+ image?: boolean;
57
+ exists?: (path: string) => boolean;
58
+ };
59
+ /** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
60
+ * is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
61
+ export declare const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
62
+ /** A container: AgentRun's image (IMAGE_ENV), or a runtime's mark (/.dockerenv, Podman's /run/.containerenv), which alone
63
+ * is some other container (a dev container). */
64
+ export declare const containerOf: (env: NodeJS.ProcessEnv, exists?: (path: string) => boolean) => ContainerFacts;
44
65
  /** How long Docker's probe may take. */
45
66
  export declare const PROBE_TIMEOUT_MS = 5000;
46
67
  /** What `docker version` says of this machine's Docker daemon: it answers (`up`), or why not. `absent`: no daemon
@@ -59,7 +80,7 @@ export declare function askDockerDaemon(env: NodeJS.ProcessEnv, signal: AbortSig
59
80
  file: string;
60
81
  user: string;
61
82
  ids: readonly number[];
62
- }): Promise<DockerDaemon>;
83
+ }, container?: ContainerFacts): Promise<DockerDaemon>;
63
84
  /** What placeOffers takes beyond the environment. */
64
85
  export type PlaceOffersOptions = {
65
86
  /** A provider key's value as a run's claim reads it (key-meta.ts keyReader); default `env`'s alone. */
@@ -73,6 +94,9 @@ export type PlaceOffersOptions = {
73
94
  user: string;
74
95
  ids: readonly number[];
75
96
  };
97
+ /** Whether this server runs in a container, and how a path is checked, which say a failed probe's fix (containerReason);
98
+ * default this process's. */
99
+ container?: ContainerFacts;
76
100
  /** Under --faux only: Docker answers, whatever AGENTRUN_BOXES lists, and nothing asks it. */
77
101
  fauxDocker?: boolean;
78
102
  };
@@ -10,6 +10,7 @@
10
10
  // provider requires are set (the server's environment, else saved in Settings → Computers), and are not asked anything
11
11
  // at the start: a key the vendor refuses fails the run's computer start, in the vendor's words.
12
12
  import { execFile } from "node:child_process";
13
+ import { existsSync } from "node:fs";
13
14
  import { readFile } from "node:fs/promises";
14
15
  import { userInfo } from "node:os";
15
16
  import { PROVIDERS } from "@parcha/agentrun-computer";
@@ -81,6 +82,52 @@ const ownGroups = () => {
81
82
  catch { }
82
83
  return { file: "/etc/group", user, ids: process.getgroups?.() ?? [] };
83
84
  };
85
+ /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: the one-container `docker run`,
86
+ * deploy/'s compose file and a Kubernetes pod give it none, so it asks a daemon that is not there. Starting Docker or
87
+ * joining its group would not help: compose.yaml at the repository's root mounts the host's socket, which is root on
88
+ * that host (compose.yaml's own header says so), so the words say that too. */
89
+ export const DOCKER_NO_SOCKET = "This server runs in a container with no Docker socket, so its agents get file tools and web_fetch but no shell: for a shell in Docker sandboxes, give it the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
90
+ /** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
91
+ * socket's. usermod in the container would not last past its restart. */
92
+ export const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
93
+ /** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
94
+ * is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
95
+ export const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
96
+ /** A container: AgentRun's image (IMAGE_ENV), or a runtime's mark (/.dockerenv, Podman's /run/.containerenv), which alone
97
+ * is some other container (a dev container). */
98
+ export const containerOf = (env, exists = existsSync) => {
99
+ const image = env[IMAGE_ENV] === "1";
100
+ return { inside: image || exists("/.dockerenv") || exists("/run/.containerenv"), image };
101
+ };
102
+ /** A reason in a container that is not AgentRun's image: the host's words, said to be the container's (its own Docker, its
103
+ * own docker group), never compose.yaml's, which is not there to use. */
104
+ const inOtherContainer = (container, reason) => (container.inside && !container.image ? `This server runs in a container. ${reason}` : reason);
105
+ /** The daemon address docker names when it cannot connect ("Cannot connect to the Docker daemon at unix:///….sock."):
106
+ * the one its DOCKER_HOST or current context resolved to. Matched, never shown. */
107
+ const DAEMON_AT = /docker daemon at ([a-z]+:\/\/\S+?)\.?(?:\s|$)/i;
108
+ /** Whether the socket a failed probe asked is there: the unix socket docker named (DAEMON_AT); any other address (tcp,
109
+ * ssh) is one; with none named, DOCKER_HOST or DOCKER_CONTEXT is one, else the default /var/run/docker.sock. */
110
+ function socketThere(endpoint, env, exists) {
111
+ if (endpoint !== undefined)
112
+ return endpoint.startsWith("unix://") ? exists(endpoint.slice("unix://".length)) : true;
113
+ return Boolean(env.DOCKER_HOST || env.DOCKER_CONTEXT) || exists("/var/run/docker.sock");
114
+ }
115
+ /** A failed probe's reason in AgentRun's image, where the host's words (start Docker, usermod) are the wrong fix: a socket
116
+ * that refused this process (wherever it is) is its group's; a socket that is not there is compose.yaml's. Undefined on
117
+ * a host and in another container (inOtherContainer), and for a socket that is there and whose daemon does not answer
118
+ * (the host's Docker is down). */
119
+ const containerReason = (answer, env, container) => {
120
+ if (!container.inside || !container.image || answer.failed === undefined)
121
+ return undefined;
122
+ if (answer.denied)
123
+ return DOCKER_SOCKET_GROUP;
124
+ return socketThere(answer.endpoint, env, container.exists ?? existsSync) ? undefined : DOCKER_NO_SOCKET;
125
+ };
126
+ /** The daemon address in docker's stderr, when it names one (DAEMON_AT). */
127
+ const endpointIn = (stderr) => {
128
+ const named = DAEMON_AT.exec(String(stderr))?.[1];
129
+ return named !== undefined ? { endpoint: named } : {};
130
+ };
84
131
  /** docker's own words for a socket that refused this process (the CLI's, or the connect's EACCES). Matched, never shown. */
85
132
  const SOCKET_DENIED = /permission denied while trying to connect to the docker daemon socket|docker\.sock: connect: permission denied/i;
86
133
  /** How long Docker's probe may take. */
@@ -94,23 +141,27 @@ function errorName(error) {
94
141
  }
95
142
  /** Asks this machine's Docker daemon its version (`docker version`), as the Docker computer's check (docker-daemon.ts)
96
143
  * does: the CLI is on PATH and its daemon answers this user. `signal` bounds it. */
97
- export async function askDockerDaemon(env, signal, groups = ownGroups()) {
144
+ export async function askDockerDaemon(env, signal, groups = ownGroups(), container = containerOf(env)) {
98
145
  // Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
99
146
  // name shaped like a key.
100
147
  const dockerEnv = withoutSecrets(env);
101
148
  const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, signal, maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
102
149
  const code = error?.code;
103
- resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
150
+ resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
104
151
  }));
105
- const absent = (reason) => ({ up: false, absent: true, reason });
152
+ const absent = (reason) => ({ up: false, absent: true, reason: inOtherContainer(container, reason) });
106
153
  // The box's probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
107
154
  // first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
155
+ // In a container, the fix is its socket or that socket's group (containerReason), never the host's.
156
+ const inside = containerReason(answer, env, container);
157
+ if (inside !== undefined)
158
+ return { up: false, absent: !answer.denied, reason: inside };
108
159
  if (answer.failed === "ENOENT")
109
160
  return absent("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
110
161
  // Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
111
162
  // a restart alone where the group file already lists this user, else joining it first.
112
163
  if (answer.denied)
113
- return { up: false, absent: false, reason: (await joinedSince(groups)) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP };
164
+ return { up: false, absent: false, reason: inOtherContainer(container, (await joinedSince(groups)) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP) };
114
165
  if (answer.failed)
115
166
  return absent(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
116
167
  if (!answer.out.trim())
@@ -119,20 +170,23 @@ export async function askDockerDaemon(env, signal, groups = ownGroups()) {
119
170
  }
120
171
  /** Docker's offer: `docker version` names the daemon's version, so the CLI is on PATH and its daemon answers this user.
121
172
  * Bounded by `timeoutMs`; never rejects. */
122
- async function probeDocker(env, timeoutMs, groups) {
123
- const no = (reason) => ({ id: "docker", available: false, reason });
173
+ async function probeDocker(env, timeoutMs, groups, container) {
174
+ const no = (reason) => ({ id: "docker", available: false, reason: inOtherContainer(container, reason) });
124
175
  // Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
125
176
  // name shaped like a key.
126
177
  const dockerEnv = withoutSecrets(env);
127
178
  const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
128
179
  const failed = error;
129
180
  const code = failed?.code;
130
- resolve({ ...(failed ? { failed: typeof code === "number" ? `exit ${code}` : errorName(failed), ...(failed.killed ? { late: true } : {}), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
181
+ resolve({ ...(failed ? { failed: typeof code === "number" ? `exit ${code}` : errorName(failed), ...(failed.killed ? { late: true } : {}), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
131
182
  }));
132
183
  // Docker is on by default, so its reason is often a first-time user's first read: what is wrong in plain words, what
133
184
  // the probe saw, then what to do.
134
185
  if (answer.late)
135
186
  return no(`Docker isn't answering on this machine (docker version took over ${timeoutMs} ms): start Docker, then restart AgentRun`);
187
+ const inside = containerReason(answer, env, container);
188
+ if (inside !== undefined)
189
+ return no(inside);
136
190
  if (answer.failed === "ENOENT")
137
191
  return no("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
138
192
  // Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
@@ -169,7 +223,7 @@ export async function placeOffers(env, options = {}) {
169
223
  if (!enabled.has(id))
170
224
  return { id, available: false, reason: notEnabled(id, enabled) };
171
225
  if (id === "docker")
172
- return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups());
226
+ return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups(), options.container ?? containerOf(env));
173
227
  return remoteOffer(id, keyOf);
174
228
  }));
175
229
  }
package/dist/print.js CHANGED
@@ -16,7 +16,7 @@ export function banner(o) {
16
16
  `AGENTRUN_API_KEY=${key}`,
17
17
  ...(o.tokenIds && (o.tokenIds.length > 1 || o.source === "list") ? [`API tokens taken (ids): ${o.tokenIds.join(", ")}`] : []),
18
18
  o.apiOnly
19
- ? "API only (AGENTRUN_API_ONLY=1): the run and deploy routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
19
+ ? "API only (AGENTRUN_API_ONLY=1): the run and deploy routes, the MCP server names, a Composio server's save and a server's delete are served; the console, sign-in, setup, other settings, the MCP endpoint, triggers and hooks are refused."
20
20
  : o.accounts || o.launchCode === undefined ? `Open ${o.publicUrl ?? o.url}/` : `Open ${o.publicUrl ?? o.url}/?launch=${o.launchCode}`,
21
21
  ...(o.boxes ? [o.boxes] : []),
22
22
  ];
@@ -1,12 +1,40 @@
1
1
  import { ApiError } from "./errors.js";
2
- import type { Snapshot } from "./learn/folder.js";
2
+ import { type LearningFolder, type SnapChange, type Snapshot } from "./learn/folder.js";
3
+ import type { PromotionRecord, Refused } from "./learn/promote.js";
3
4
  import type { RunRow, Store } from "./store/index.js";
5
+ import type { Workspace } from "./workspace/index.js";
4
6
  /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
5
7
  * meter as /usage read it at its purge (null: unknown, or none read). */
6
8
  export declare function purgedRun(row: RunRow): ApiError;
7
- /** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
8
- * workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
9
- * (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
10
- * main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
11
- * every read of a learned workflow's text asks. */
12
- export declare function purgedWorkflows(snapshot: Snapshot | undefined, store: Pick<Store, "runs">): Promise<ReadonlyMap<string, RunRow>>;
9
+ /** Which of `runIds` are purged, each with its row: by its row's purge time. One store read per run. */
10
+ export declare function purgedRows(store: Pick<Store, "runs">, runIds: Iterable<string>): Promise<ReadonlyMap<string, RunRow>>;
11
+ /** The one gate every read of the learning folder at a commit goes through, main's or a past commit's (learn/folder.ts
12
+ * snapshotAt, folderAt): the view, the log and a workflow's revisions, a merge's diff, a run's seed (learning.ts seedAt)
13
+ * and the champion read by digest, an SDK start's receipt, and a compile ask (runner/learning-end.ts compileAskOf).
14
+ * `workflows`: each learned workflow of `snapshot` whose workflow.json a purged run wrote (SnapLearned.run: the run of
15
+ * the newest commit that changed the file, over main's whole history, which a purge's put-back hands to the run that
16
+ * wrote those bytes), by name, with that run's row; no read lays, checks, replays, serves or shows it. `served`, read
17
+ * only when `log` is asked: whether a change of the snapshot's log is served (no purged run's merge is), so a log the
18
+ * folder rebuilds names one and still serves none. */
19
+ export declare function purgeGate(snapshot: Snapshot | undefined, store: Pick<Store, "runs">, log?: boolean): Promise<{
20
+ workflows: ReadonlyMap<string, RunRow>;
21
+ served: (change: SnapChange) => boolean;
22
+ }>;
23
+ /** The promotion records of `workflows` that championOf skips (learn/promote.ts Refused), read through purgeGate at
24
+ * each record's commit of the learning folder at `ws`: newest promotion first, whatever its digest's newest decision
25
+ * (a champion held since included: skipping it may leave an earlier one serving), one the gate refuses at its commit (a
26
+ * purged run wrote its workflow there) is skipped with every record of its workflow at that commit (by workflow and
27
+ * commit, so a copy of the records read later is skipped alike, a hold of it included), until the newest promotion left
28
+ * is one the gate lets through, or none is left. The holds are walked the same way, newest first: a hold at a commit the
29
+ * gate refuses (a check that ended after its revision's run was purged holds it there) is skipped with its commit's
30
+ * records, until the newest hold left is one the gate lets through, so the compile's held names (learn/compile.ts
31
+ * heldNamesOf) never ask a revision of a purged run's text. A record with no commit is let through, and so is a commit
32
+ * the folder no longer has (reading its text fails on its own). A commit whose read throws refuses none here and is said
33
+ * (Refused.unread), so the promotions trim trims nothing on it (recordPromotion); a store read of the gate's that throws
34
+ * throws, so every write that asks fails closed. One read-only exec per commit asked. */
35
+ export declare function refusedOf(records: readonly PromotionRecord[], workflows: Iterable<string>, ws: Workspace, store: Pick<Store, "runs">): Promise<Refused>;
36
+ /** refusedOf in the learning folder `folder` opens for each ask (ended after it), over `workflows` (every workflow of
37
+ * the records when absent): the port a champion's readers and the promotions trim ask (runner/promotion.ts
38
+ * PromotionDeps refused, learn/promote.ts recordPromotion). An end() that throws is said to `log` (when given) and never
39
+ * fails the ask: the answer was read. */
40
+ export declare const refusedIn: (folder: () => Pick<LearningFolder, "workspace" | "end">, store: Pick<Store, "runs">, log?: (line: string) => void) => (records: readonly PromotionRecord[], workflows?: Iterable<string>) => Promise<Refused>;
@@ -1,14 +1,9 @@
1
1
  // What a purged run (DELETE /v2/runs/{id}, agent-delete.ts purgeRun) answers, and the one rule for a learned workflow
2
- // whose text it wrote: its purge takes it off main (learn/commit.ts forgetRunText), and every read at a past commit
3
- // refuses it, so it is never served or executed.
4
- // - The learned file read (GET .../learning/files/workflows/<name>/workflow.json) of one still on main (its run
5
- // purged before purges took it off) is 410 purged with the run's tombstone, as every route of the run is (purgedRun).
6
- // - The champion read by digest (GET .../learning/promotions) reads no commit for it.
7
- // - A later merge's diff (GET /runs/{id}/learning/diff) serves that file against nothing: never the purged text.
8
- // - An SDK start sent again (sdk/runs.ts receipt) whose receipt pinned it is 410 purged, as the file read.
9
- // - A run's seed (learning.ts seedAt) leaves it out, so no claim lays, checks, replays or serves it, and a champion
10
- // read at its commit finds none: the run goes on as it does when no champion serves.
2
+ // whose text it wrote: its purge puts back the version before it, or takes it off main when it wrote it new
3
+ // (learn/commit.ts forgetRunText), and every read of the folder at a commit asks purgeGate, so a purged run's text is
4
+ // never served or executed and none of its merges is shown.
11
5
  import { ApiError } from "./errors.js";
6
+ import { snapshotAt } from "./learn/folder.js";
12
7
  const isoOrNull = (ms) => (ms === null ? null : new Date(ms).toISOString());
13
8
  /** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
14
9
  * meter as /usage read it at its purge (null: unknown, or none read). */
@@ -22,22 +17,74 @@ export function purgedRun(row) {
22
17
  },
23
18
  });
24
19
  }
25
- /** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
26
- * workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
27
- * (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
28
- * main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
29
- * every read of a learned workflow's text asks. */
30
- export async function purgedWorkflows(snapshot, store) {
31
- const writers = new Map();
32
- for (const item of snapshot?.workflows ?? [])
33
- if (item.run)
34
- writers.set(item.name, item.run);
35
- const rows = new Map(await Promise.all([...new Set(writers.values())].map(async (run) => [run, await store.runs.get(run)])));
36
- const purged = new Map();
37
- for (const [name, run] of writers) {
38
- const row = rows.get(run);
39
- if (row && row.purgedAt !== null)
40
- purged.set(name, row);
20
+ /** Which of `runIds` are purged, each with its row: by its row's purge time. One store read per run. */
21
+ export async function purgedRows(store, runIds) {
22
+ const rows = await Promise.all([...new Set(runIds)].map((run) => store.runs.get(run)));
23
+ return new Map(rows.flatMap((row) => (row && row.purgedAt !== null ? [[row.id, row]] : [])));
24
+ }
25
+ /** The one gate every read of the learning folder at a commit goes through, main's or a past commit's (learn/folder.ts
26
+ * snapshotAt, folderAt): the view, the log and a workflow's revisions, a merge's diff, a run's seed (learning.ts seedAt)
27
+ * and the champion read by digest, an SDK start's receipt, and a compile ask (runner/learning-end.ts compileAskOf).
28
+ * `workflows`: each learned workflow of `snapshot` whose workflow.json a purged run wrote (SnapLearned.run: the run of
29
+ * the newest commit that changed the file, over main's whole history, which a purge's put-back hands to the run that
30
+ * wrote those bytes), by name, with that run's row; no read lays, checks, replays, serves or shows it. `served`, read
31
+ * only when `log` is asked: whether a change of the snapshot's log is served (no purged run's merge is), so a log the
32
+ * folder rebuilds names one and still serves none. */
33
+ export async function purgeGate(snapshot, store, log = false) {
34
+ const writers = new Map((snapshot?.workflows ?? []).flatMap((item) => (item.run ? [[item.name, item.run]] : [])));
35
+ const logged = log ? (snapshot?.log ?? []).flatMap(({ by }) => ("run" in by ? [by.run] : [])) : [];
36
+ const purged = await purgedRows(store, [...writers.values(), ...logged]);
37
+ const workflows = new Map([...writers].flatMap(([name, run]) => (purged.has(run) ? [[name, purged.get(run)]] : [])));
38
+ return {
39
+ workflows,
40
+ served: ({ by }) => {
41
+ if (!log)
42
+ throw new Error("the purge gate was not asked for the log");
43
+ return !("run" in by && purged.has(by.run));
44
+ },
45
+ };
46
+ }
47
+ /** The promotion records of `workflows` that championOf skips (learn/promote.ts Refused), read through purgeGate at
48
+ * each record's commit of the learning folder at `ws`: newest promotion first, whatever its digest's newest decision
49
+ * (a champion held since included: skipping it may leave an earlier one serving), one the gate refuses at its commit (a
50
+ * purged run wrote its workflow there) is skipped with every record of its workflow at that commit (by workflow and
51
+ * commit, so a copy of the records read later is skipped alike, a hold of it included), until the newest promotion left
52
+ * is one the gate lets through, or none is left. The holds are walked the same way, newest first: a hold at a commit the
53
+ * gate refuses (a check that ended after its revision's run was purged holds it there) is skipped with its commit's
54
+ * records, until the newest hold left is one the gate lets through, so the compile's held names (learn/compile.ts
55
+ * heldNamesOf) never ask a revision of a purged run's text. A record with no commit is let through, and so is a commit
56
+ * the folder no longer has (reading its text fails on its own). A commit whose read throws refuses none here and is said
57
+ * (Refused.unread), so the promotions trim trims nothing on it (recordPromotion); a store read of the gate's that throws
58
+ * throws, so every write that asks fails closed. One read-only exec per commit asked. */
59
+ export async function refusedOf(records, workflows, ws, store) {
60
+ const refused = new Set();
61
+ const skip = (one) => one.commit !== undefined && refused.has(`${one.workflow}\0${one.commit}`);
62
+ let unread = false;
63
+ const reads = new Map();
64
+ const gated = (commit) => reads.get(commit) ?? reads.set(commit, snapshotAt(ws, commit).then(async (at) => (await purgeGate(at, store)).workflows, () => {
65
+ unread = true;
66
+ return new Map();
67
+ })).get(commit);
68
+ const newestOf = (workflow, decided) => records.findLast((one) => one.workflow === workflow && one.decided === decided && !skip(one));
69
+ for (const workflow of new Set(workflows)) {
70
+ for (const decided of ["promote", "hold"]) {
71
+ for (let last = newestOf(workflow, decided); last?.commit && (await gated(last.commit)).has(workflow); last = newestOf(workflow, decided)) {
72
+ refused.add(`${workflow}\0${last.commit}`);
73
+ }
74
+ }
41
75
  }
42
- return purged;
76
+ return Object.assign(skip, { unread });
43
77
  }
78
+ /** refusedOf in the learning folder `folder` opens for each ask (ended after it), over `workflows` (every workflow of
79
+ * the records when absent): the port a champion's readers and the promotions trim ask (runner/promotion.ts
80
+ * PromotionDeps refused, learn/promote.ts recordPromotion). An end() that throws is said to `log` (when given) and never
81
+ * fails the ask: the answer was read. */
82
+ export const refusedIn = (folder, store, log) => async (records, workflows) => {
83
+ const { workspace, end } = folder();
84
+ try {
85
+ return await refusedOf(records, workflows ?? records.map((one) => one.workflow), workspace, store);
86
+ }
87
+ finally {
88
+ await end().catch((error) => log?.(`learning: the learning folder did not end after the purge gate's ask: ${error instanceof Error ? error.message : String(error)}`));
89
+ }
90
+ };
@@ -0,0 +1,74 @@
1
+ export type Span = [start: number, end: number];
2
+ /** The characters the shape scanners have visited in this process: the text each prefix search passes over, each run
3
+ * read, each guard read back. A test sets it to 0, redacts, and reads it: a scanner that read a run once per start
4
+ * inside it would count the square of the run's length. */
5
+ export declare const scanned: {
6
+ chars: number;
7
+ };
8
+ /** `text` with A-Z lowered and nothing else changed, so each offset is the same in both. */
9
+ export declare const asciiLower: (text: string) => string;
10
+ /** What a scan of one start found: the span it matched (start -1 for none), and where the search for the next prefix
11
+ * goes on. */
12
+ type Found = {
13
+ start: number;
14
+ end: number;
15
+ next: number;
16
+ };
17
+ /** A secret's shape as a scanner: its prefixes (found as written, or in the text lowered with `ci`), and what reads on
18
+ * from one. Each scan says where the next start is looked for: past the run it read, less the prefix's length but one,
19
+ * as a prefix can start in a run's last characters and end past it; a start inside the run is not read again, as it
20
+ * ends where the run does and is no longer than this one. Where a shape's run can hold its own prefix and start a
21
+ * different run (a Bearer scheme inside a token), its scan says so. */
22
+ export type Shape = {
23
+ readonly kind: string;
24
+ readonly prefixes: readonly string[];
25
+ readonly ci?: boolean;
26
+ readonly scan: (text: string, at: number, prefix: string) => Found;
27
+ };
28
+ /** Text shaped like a secret, by kind. The same shapes the Pi learning loop's guard refuses. */
29
+ export declare const SECRET_SHAPES: readonly Shape[];
30
+ /** A bank's numbers beside their words, which learning never keeps: an account, IBAN, routing or sort-code number. Not
31
+ * one of SECRET_SHAPES: a run may show its user an account number (a finance job's answer), and those shapes cut every
32
+ * run's view; only what learning keeps refuses them. */
33
+ export declare const MONEY_SHAPES: readonly Shape[];
34
+ /** The kinds of `shapes` in `text`, each once, in their order. */
35
+ export declare function shapeKinds(text: string, shapes: readonly Shape[]): string[];
36
+ /** What the matcher looks for of a set of held values (learn/secrets.ts derives it of each value and its spellings):
37
+ * - `forms`: found as they stand and cut in place (as written, as JSON writes it, squeezed, base64, percent);
38
+ * - `hexes`: a value's hex, lowered, found in any case and cut in place;
39
+ * - `folds`: a hex identifier's digits, found in any case with one separator ("-", "_", ":", ".") allowed between any
40
+ * two, and cut in place;
41
+ * - `plain`: what the whole-text check looks for in each squeezed view (with `hexes` in it lowered, `folds` in it
42
+ * folded). */
43
+ export type Needles = {
44
+ readonly forms: readonly string[];
45
+ readonly hexes: readonly string[];
46
+ readonly folds: readonly string[];
47
+ readonly plain: readonly string[];
48
+ };
49
+ /** `found` in order, each run of overlapping or touching spans as one. */
50
+ export declare function merged(found: readonly (readonly [number, number])[]): Span[];
51
+ /** `text` with each of `spans` (merged, in order) replaced by "[redacted]". */
52
+ export declare function cutAt(text: string, spans: readonly Span[]): string;
53
+ /** Whether `text` holds a held value in a form the cut does not find as it stands: split by whitespace, percent or
54
+ * form encoded, an NFKC variant, its hex in any case, a hex identifier folded (`fold`). With `cuts`, a value whose
55
+ * every character the view read comes from inside the cuts is not held: it is cut in place. */
56
+ export declare function holds(text: string, needles: Needles, { fold, cuts }?: {
57
+ fold?: boolean;
58
+ cuts?: readonly Span[];
59
+ }): boolean;
60
+ /** planCut's first step: every form, hex, folded identifier and shape of `text` as it came, and `held`, merged. */
61
+ export declare function cutSpans(text: string, needles: Needles, shapes: readonly Shape[], held?: readonly (readonly [number, number])[]): Span[];
62
+ /** Where `text` is cut of `needles` and of each of `shapes`, and the text so cut; or "whole" when it must be withheld
63
+ * whole. `held`: spans cut in place beside the finds. The order is fixed:
64
+ * 1. every form, hex, folded identifier and shape is found in the text as it came, and the spans merged;
65
+ * 2. the views of the text as it came are read for each held value: one any of whose characters comes from outside
66
+ * the spans withholds the text (a cut can hide part of a value, so the check never reads the cut text for it);
67
+ * 3. the spans are cut;
68
+ * 4. what is left is read again, for a value or a shape the cut made (a value whose rest the cut joined, a shape whose
69
+ * guard the cut removed), and withholds the text if it holds one. */
70
+ export declare function planCut(text: string, needles: Needles, shapes: readonly Shape[], held?: readonly (readonly [number, number])[]): {
71
+ spans: Span[];
72
+ out: string;
73
+ } | "whole";
74
+ export {};