@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30

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 (273) hide show
  1. package/CHANGELOG.md +748 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +2190 -2
  5. package/dist/adapters.d.ts +234 -0
  6. package/dist/adapters.js +585 -0
  7. package/dist/agents.d.ts +130 -0
  8. package/dist/agents.js +308 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +384 -0
  11. package/dist/background.d.ts +28 -0
  12. package/dist/background.js +376 -0
  13. package/dist/bound-files.d.ts +4 -0
  14. package/dist/bound-files.js +164 -0
  15. package/dist/box/record.d.ts +6 -0
  16. package/dist/box/record.js +41 -0
  17. package/dist/box/sweep.d.ts +53 -0
  18. package/dist/box/sweep.js +193 -0
  19. package/dist/box-egress.d.ts +98 -0
  20. package/dist/box-egress.js +259 -0
  21. package/dist/box-image.d.ts +98 -0
  22. package/dist/box-image.js +285 -0
  23. package/dist/box-relay-vm.d.ts +80 -0
  24. package/dist/box-relay-vm.js +389 -0
  25. package/dist/box-relay.d.ts +45 -0
  26. package/dist/box-relay.js +227 -0
  27. package/dist/boxes.d.ts +72 -0
  28. package/dist/boxes.js +189 -0
  29. package/dist/browser-cost.d.ts +41 -0
  30. package/dist/browser-cost.js +158 -0
  31. package/dist/cap.d.ts +332 -0
  32. package/dist/cap.js +992 -0
  33. package/dist/catalog.d.ts +20 -0
  34. package/dist/catalog.js +53 -0
  35. package/dist/cli.d.ts +2 -0
  36. package/dist/cli.js +167 -0
  37. package/dist/coding-tools.d.ts +35 -0
  38. package/dist/coding-tools.js +87 -0
  39. package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
  40. package/dist/console/assets/index-34jfpIbQ.js +481 -0
  41. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  42. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  53. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  54. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  57. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  58. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  59. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  60. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  61. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  62. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  63. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  64. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  65. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  66. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  67. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  68. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  69. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  70. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  71. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  72. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  73. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  74. package/dist/console/index.html +15 -0
  75. package/dist/content-filter.d.ts +7 -0
  76. package/dist/content-filter.js +23 -0
  77. package/dist/daytona-api.d.ts +21 -0
  78. package/dist/daytona-api.js +101 -0
  79. package/dist/decision-rows.d.ts +19 -0
  80. package/dist/decision-rows.js +123 -0
  81. package/dist/decisions.d.ts +94 -0
  82. package/dist/decisions.js +184 -0
  83. package/dist/effort-guidance.d.ts +5 -0
  84. package/dist/effort-guidance.js +14 -0
  85. package/dist/environment.d.ts +5 -0
  86. package/dist/environment.js +11 -0
  87. package/dist/errors.d.ts +74 -0
  88. package/dist/errors.js +69 -0
  89. package/dist/exa-keyless.d.ts +35 -0
  90. package/dist/exa-keyless.js +202 -0
  91. package/dist/fetch-page.d.ts +114 -0
  92. package/dist/fetch-page.js +182 -0
  93. package/dist/files.d.ts +65 -0
  94. package/dist/files.js +158 -0
  95. package/dist/grade.d.ts +93 -0
  96. package/dist/grade.js +328 -0
  97. package/dist/graph-served.d.ts +23 -0
  98. package/dist/graph-served.js +75 -0
  99. package/dist/graph-view.d.ts +102 -0
  100. package/dist/graph-view.js +219 -0
  101. package/dist/harness-app.d.ts +40 -0
  102. package/dist/harness-app.js +708 -0
  103. package/dist/harness-opencode/adapter.d.ts +45 -0
  104. package/dist/harness-opencode/adapter.js +272 -0
  105. package/dist/harness-opencode/binary.d.ts +18 -0
  106. package/dist/harness-opencode/binary.js +87 -0
  107. package/dist/harness-opencode/config.d.ts +24 -0
  108. package/dist/harness-opencode/config.js +61 -0
  109. package/dist/harness-opencode/harness.d.ts +77 -0
  110. package/dist/harness-opencode/harness.js +620 -0
  111. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  112. package/dist/harness-opencode/host/mcp.js +208 -0
  113. package/dist/harness-opencode/host/policy.d.ts +71 -0
  114. package/dist/harness-opencode/host/policy.js +419 -0
  115. package/dist/harness-opencode/host/server.d.ts +55 -0
  116. package/dist/harness-opencode/host/server.js +165 -0
  117. package/dist/harness-opencode/index.d.ts +9 -0
  118. package/dist/harness-opencode/index.js +6 -0
  119. package/dist/harness-opencode/verify.d.ts +32 -0
  120. package/dist/harness-opencode/verify.js +75 -0
  121. package/dist/harness-opencode/versions.d.ts +33 -0
  122. package/dist/harness-opencode/versions.js +64 -0
  123. package/dist/harness.d.ts +56 -0
  124. package/dist/harness.js +77 -0
  125. package/dist/home-path.d.ts +27 -0
  126. package/dist/home-path.js +78 -0
  127. package/dist/host-tools.d.ts +30 -0
  128. package/dist/host-tools.js +154 -0
  129. package/dist/host.d.ts +39 -0
  130. package/dist/host.js +85 -0
  131. package/dist/hosted-search.d.ts +27 -0
  132. package/dist/hosted-search.js +133 -0
  133. package/dist/import-sources.d.ts +104 -0
  134. package/dist/import-sources.js +629 -0
  135. package/dist/import-summary.d.ts +25 -0
  136. package/dist/import-summary.js +75 -0
  137. package/dist/import-worker.d.ts +26 -0
  138. package/dist/import-worker.js +41 -0
  139. package/dist/import.d.ts +145 -0
  140. package/dist/import.js +1222 -0
  141. package/dist/index.d.ts +7 -0
  142. package/dist/index.js +6 -0
  143. package/dist/key-check.d.ts +37 -0
  144. package/dist/key-check.js +112 -0
  145. package/dist/key-refusal.d.ts +51 -0
  146. package/dist/key-refusal.js +191 -0
  147. package/dist/learn/check.d.ts +108 -0
  148. package/dist/learn/check.js +277 -0
  149. package/dist/learn/grade.d.ts +80 -0
  150. package/dist/learn/grade.js +445 -0
  151. package/dist/learn/index.d.ts +7 -0
  152. package/dist/learn/index.js +11 -0
  153. package/dist/learn/invisible.d.ts +5 -0
  154. package/dist/learn/invisible.js +42 -0
  155. package/dist/learn/notes.d.ts +59 -0
  156. package/dist/learn/notes.js +147 -0
  157. package/dist/learn/reflect.d.ts +49 -0
  158. package/dist/learn/reflect.js +213 -0
  159. package/dist/learn/secrets.d.ts +18 -0
  160. package/dist/learn/secrets.js +131 -0
  161. package/dist/learn/skills.d.ts +97 -0
  162. package/dist/learn/skills.js +271 -0
  163. package/dist/learned-workflow.d.ts +59 -0
  164. package/dist/learned-workflow.js +191 -0
  165. package/dist/learning-routes.d.ts +196 -0
  166. package/dist/learning-routes.js +609 -0
  167. package/dist/learning-run.d.ts +306 -0
  168. package/dist/learning-run.js +819 -0
  169. package/dist/learning-words.d.ts +76 -0
  170. package/dist/learning-words.js +174 -0
  171. package/dist/learning.d.ts +418 -0
  172. package/dist/learning.js +946 -0
  173. package/dist/llm.d.ts +40 -0
  174. package/dist/llm.js +37 -0
  175. package/dist/llms.txt +37 -0
  176. package/dist/mcp-servers.d.ts +118 -0
  177. package/dist/mcp-servers.js +450 -0
  178. package/dist/mcp.d.ts +51 -0
  179. package/dist/mcp.js +392 -0
  180. package/dist/model.d.ts +186 -0
  181. package/dist/model.js +485 -0
  182. package/dist/monid.d.ts +74 -0
  183. package/dist/monid.js +277 -0
  184. package/dist/openapi/agentrun-v2.openapi.json +4806 -0
  185. package/dist/openapi.d.ts +10 -0
  186. package/dist/openapi.js +1727 -0
  187. package/dist/owner.d.ts +55 -0
  188. package/dist/owner.js +222 -0
  189. package/dist/packs.d.ts +71 -0
  190. package/dist/packs.js +180 -0
  191. package/dist/page.d.ts +32 -0
  192. package/dist/page.js +133 -0
  193. package/dist/paid-calls.d.ts +50 -0
  194. package/dist/paid-calls.js +110 -0
  195. package/dist/pause.d.ts +70 -0
  196. package/dist/pause.js +97 -0
  197. package/dist/pdf-pages.d.ts +44 -0
  198. package/dist/pdf-pages.js +147 -0
  199. package/dist/place.d.ts +69 -0
  200. package/dist/place.js +137 -0
  201. package/dist/print.d.ts +20 -0
  202. package/dist/print.js +29 -0
  203. package/dist/propose.d.ts +40 -0
  204. package/dist/propose.js +112 -0
  205. package/dist/quiet-sqlite-warning.d.ts +1 -0
  206. package/dist/quiet-sqlite-warning.js +14 -0
  207. package/dist/request-start.d.ts +22 -0
  208. package/dist/request-start.js +350 -0
  209. package/dist/result.d.ts +3 -0
  210. package/dist/result.js +5 -0
  211. package/dist/rows.d.ts +46 -0
  212. package/dist/rows.js +121 -0
  213. package/dist/run-box.d.ts +186 -0
  214. package/dist/run-box.js +590 -0
  215. package/dist/run-manifest.d.ts +27 -0
  216. package/dist/run-manifest.js +60 -0
  217. package/dist/runnable.d.ts +83 -0
  218. package/dist/runnable.js +170 -0
  219. package/dist/runs.d.ts +1062 -0
  220. package/dist/runs.js +3020 -0
  221. package/dist/secret-cut.d.ts +27 -0
  222. package/dist/secret-cut.js +109 -0
  223. package/dist/secrets.d.ts +62 -0
  224. package/dist/secrets.js +158 -0
  225. package/dist/server-lock.d.ts +44 -0
  226. package/dist/server-lock.js +140 -0
  227. package/dist/server.d.ts +722 -0
  228. package/dist/server.js +2118 -0
  229. package/dist/sessions.d.ts +4 -0
  230. package/dist/sessions.js +105 -0
  231. package/dist/sign-ins.d.ts +99 -0
  232. package/dist/sign-ins.js +288 -0
  233. package/dist/skills.d.ts +43 -0
  234. package/dist/skills.js +96 -0
  235. package/dist/stats.d.ts +106 -0
  236. package/dist/stats.js +103 -0
  237. package/dist/tool-gate.d.ts +266 -0
  238. package/dist/tool-gate.js +554 -0
  239. package/dist/tool-keys.d.ts +187 -0
  240. package/dist/tool-keys.js +315 -0
  241. package/dist/tool-plane.d.ts +228 -0
  242. package/dist/tool-plane.js +400 -0
  243. package/dist/tools.d.ts +202 -0
  244. package/dist/tools.js +372 -0
  245. package/dist/trigger-secrets.d.ts +32 -0
  246. package/dist/trigger-secrets.js +143 -0
  247. package/dist/triggers.d.ts +439 -0
  248. package/dist/triggers.js +863 -0
  249. package/dist/turn-end.d.ts +24 -0
  250. package/dist/turn-end.js +15 -0
  251. package/dist/turns.d.ts +34 -0
  252. package/dist/turns.js +202 -0
  253. package/dist/uploads.d.ts +104 -0
  254. package/dist/uploads.js +474 -0
  255. package/dist/usage-lines.d.ts +26 -0
  256. package/dist/usage-lines.js +28 -0
  257. package/dist/usage.d.ts +29 -0
  258. package/dist/usage.js +58 -0
  259. package/dist/validate.d.ts +57 -0
  260. package/dist/validate.js +184 -0
  261. package/dist/web-fetch.d.ts +64 -0
  262. package/dist/web-fetch.js +262 -0
  263. package/dist/web-search.d.ts +54 -0
  264. package/dist/web-search.js +136 -0
  265. package/dist/webhooks.d.ts +189 -0
  266. package/dist/webhooks.js +503 -0
  267. package/dist/workspace-paths.d.ts +33 -0
  268. package/dist/workspace-paths.js +104 -0
  269. package/dist/workspace.d.ts +88 -0
  270. package/dist/workspace.js +369 -0
  271. package/launcher/agentrun-serve +109 -0
  272. package/package.json +100 -4
  273. package/skills/agentrun-serve/SKILL.md +128 -0
@@ -0,0 +1,27 @@
1
+ import { keyShaped } from "@parcha/pi-durable-disk/secret-name";
2
+ /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
3
+ * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
4
+ * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
5
+ * take it, so what one leaves out the others do. */
6
+ export { keyShaped };
7
+ export declare const REDACTED = "[redacted]";
8
+ /** A cut of every value of the key-shaped variables (8 characters or more) of `envs`, one environment or several (the
9
+ * process's and the keys saved on the server), out of a string, and out of every string in a JSON value, its field
10
+ * names included. `names` are secrets whatever their shape (the server's own, the launcher's list: AGENTRUN_SEAL_KEY
11
+ * among them, whose name matches no key pattern). */
12
+ export declare function secretCut(envs: NodeJS.ProcessEnv | readonly NodeJS.ProcessEnv[], names?: readonly string[]): {
13
+ text: ((value: string) => string) & {
14
+ removed: number;
15
+ probe: (value: string) => string;
16
+ };
17
+ json: (value: unknown) => unknown;
18
+ add: (values: readonly string[]) => void;
19
+ };
20
+ /** How many passes `secretsIn` has made in this process: for a test that a path makes none. */
21
+ export declare const secretlintCalls: {
22
+ count: number;
23
+ };
24
+ /** The keys secretlint's recommended rules find in `content`, in one pass: each as the rule names it (the secret
25
+ * itself where the rule gives it, else what it matched), and as a JSON string holding it would read it, decoded up to
26
+ * three times, so the cut finds it in a record's parsed text and in a shell's output kept in one as JSON. */
27
+ export declare function secretsIn(content: string): Promise<string[]>;
@@ -0,0 +1,109 @@
1
+ // The values of an environment's key-shaped variables, cut out of text this server keeps: the rule of the harness log's
2
+ // cut, for what the importer writes (a transcript can hold a key a tool printed or was given). The import adds the keys
3
+ // secretlint finds in what it reads (`secretsIn`): keys of a known format, whoever's they are.
4
+ import { lintSource } from "@secretlint/core";
5
+ import { secretLintProfiler } from "@secretlint/profiler";
6
+ import { rules as recommended } from "@secretlint/secretlint-rule-preset-recommend";
7
+ // No performance marks: the profiler would leave about 14 a call in the process's global buffer.
8
+ secretLintProfiler.setEnabled(false);
9
+ import { keyShaped } from "@parcha/pi-durable-disk/secret-name";
10
+ /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
11
+ * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
12
+ * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
13
+ * take it, so what one leaves out the others do. */
14
+ export { keyShaped };
15
+ export const REDACTED = "[redacted]";
16
+ /** A cut of every value of the key-shaped variables (8 characters or more) of `envs`, one environment or several (the
17
+ * process's and the keys saved on the server), out of a string, and out of every string in a JSON value, its field
18
+ * names included. `names` are secrets whatever their shape (the server's own, the launcher's list: AGENTRUN_SEAL_KEY
19
+ * among them, whose name matches no key pattern). */
20
+ export function secretCut(envs, names = []) {
21
+ // Every own name of each, enumerable or not: an environment object may hold a key it does not list.
22
+ const secrets = (Array.isArray(envs) ? envs : [envs])
23
+ .flatMap((env) => Object.getOwnPropertyNames(env).map((name) => [name, env[name]]))
24
+ .filter(([name, value]) => (keyShaped(name) || names.includes(name)) && typeof value === "string" && value.length >= 8)
25
+ .map(([, value]) => value)
26
+ // The longest first: a key that holds a shorter one is cut whole.
27
+ .sort((a, b) => b.length - a.length);
28
+ // `text.removed` counts the values it cut, each once however often it was met; `text.probe` cuts the same and counts
29
+ // nothing (a string never kept); `add` takes more values to cut (the keys secretlint found).
30
+ const removed = new Set();
31
+ // One pass a string: every value as it is and as a JSON string holds it (a quote or a backslash in it escaped), in one
32
+ // alternation, the longest first, so the longest value wins where two start at one place. Built again when values
33
+ // are added.
34
+ let pattern;
35
+ let owner = new Map();
36
+ const compile = () => {
37
+ owner = new Map();
38
+ for (const secret of secrets)
39
+ for (const form of [secret, JSON.stringify(secret).slice(1, -1)])
40
+ if (!owner.has(form))
41
+ owner.set(form, secret);
42
+ const forms = [...owner.keys()].sort((a, b) => b.length - a.length);
43
+ pattern = forms.length ? new RegExp(forms.map((form) => form.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), "g") : undefined;
44
+ };
45
+ compile();
46
+ const cut = (value, count) => pattern
47
+ ? value.replace(pattern, (form) => {
48
+ if (count)
49
+ removed.add(owner.get(form));
50
+ return REDACTED;
51
+ })
52
+ : value;
53
+ const text = Object.assign((value) => {
54
+ const out = cut(value, true);
55
+ text.removed = removed.size;
56
+ return out;
57
+ }, { removed: 0, probe: (value) => cut(value, false) });
58
+ const add = (values) => {
59
+ const fresh = values.filter((value) => value.length >= 8 && !secrets.includes(value));
60
+ if (!fresh.length)
61
+ return;
62
+ secrets.splice(0, secrets.length, ...[...secrets, ...fresh].sort((a, b) => b.length - a.length));
63
+ compile();
64
+ };
65
+ const json = (value) => {
66
+ if (typeof value === "string")
67
+ return text(value);
68
+ if (Array.isArray(value))
69
+ return value.map(json);
70
+ if (value !== null && typeof value === "object")
71
+ return Object.fromEntries(Object.entries(value).map(([name, inner]) => [text(name), json(inner)]));
72
+ return value;
73
+ };
74
+ return { text, json, add };
75
+ }
76
+ /** The recommended preset's rules, but its comment filter: a `secretlint-disable` line in what an import reads (a
77
+ * repository's own config a tool printed, a web page) would switch every rule off for the rest of it. */
78
+ const FILTER_COMMENTS = "@secretlint/secretlint-rule-filter-comments";
79
+ const SECRETLINT = { rules: recommended.filter((rule) => rule.meta.id !== FILTER_COMMENTS).map((rule) => ({ id: rule.meta.id, rule })) };
80
+ /** How many passes `secretsIn` has made in this process: for a test that a path makes none. */
81
+ export const secretlintCalls = { count: 0 };
82
+ /** The keys secretlint's recommended rules find in `content`, in one pass: each as the rule names it (the secret
83
+ * itself where the rule gives it, else what it matched), and as a JSON string holding it would read it, decoded up to
84
+ * three times, so the cut finds it in a record's parsed text and in a shell's output kept in one as JSON. */
85
+ export async function secretsIn(content) {
86
+ if (!content)
87
+ return [];
88
+ secretlintCalls.count += 1;
89
+ const { messages } = await lintSource({ source: { content, filePath: "/import.txt", ext: ".txt", contentType: "text" }, options: { config: SECRETLINT, maskSecrets: false } });
90
+ const decoded = (value) => {
91
+ try {
92
+ const out = JSON.parse(`"${value}"`);
93
+ return typeof out === "string" && out !== value ? out : undefined;
94
+ }
95
+ catch {
96
+ return undefined;
97
+ }
98
+ };
99
+ const found = new Set();
100
+ for (const message of messages) {
101
+ const named = Object.values(message.data ?? {}).filter((value) => typeof value === "string" && value.length >= 8 && content.includes(value));
102
+ for (const each of named.length ? named : [content.slice(message.range[0], message.range[1])]) {
103
+ let value = each;
104
+ for (let level = 0; value !== undefined && level < 3; level++)
105
+ (found.add(value), (value = decoded(value)));
106
+ }
107
+ }
108
+ return [...found];
109
+ }
@@ -0,0 +1,62 @@
1
+ /** The pipe and how many bytes of it are the secrets: the launcher's, or serve's to a run's process. */
2
+ export declare const SECRETS_FD_ENV = "AGENTRUN_SECRETS_FD";
3
+ export declare const SECRETS_LEN_ENV = "AGENTRUN_SECRETS_LEN";
4
+ /** The names of the secrets: the launcher's one list, which its `env -u`, serve's handover and the tests all read. Every
5
+ * key pi-ai's providers read is on it (model.ts' PROVIDER_KEYS, which the custody test checks against pi-ai's own
6
+ * table), so a key set for any provider's model is held here, never left in an environment. */
7
+ export declare const SECRET_NAMES: readonly string[];
8
+ /** The decision keys among them: a run's process gets them only on its decision descriptor (decisions.ts), never with
9
+ * the secrets on its pipe, which are its tools' environment. */
10
+ export declare const DECISION_KEYS: readonly string[];
11
+ /** Reads a tool key a person saved through a server's settings API (tool-keys.ts), by name, opened when asked for. Each
12
+ * server hands its own to what reads for it (its reading, its runs' handover), never through this module, so two
13
+ * servers in one process never read each other's saved keys. A run's process has none: it gets what it needs over its
14
+ * pipe, as it gets the rest. */
15
+ export type StoredKeys = (name: string) => string | undefined;
16
+ /** This host's secrets, for a scan of what a run wrote: each one the launcher lists, as this process holds it (never in
17
+ * the environment once handed over, so a scan of process.env alone sees none of them), and beside it the key a person
18
+ * saved under that name on the server `stored` reads for (a run that names its tool is handed it), and the value of
19
+ * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
20
+ * whitespace aside, matches too much text by chance to be refused, and is left out. */
21
+ export declare const hostSecrets: (env: NodeJS.ProcessEnv, stored?: StoredKeys) => string[];
22
+ /** A secret's value: this process's own, which wins (tool-keys.ts' `source: "server"` is exactly these), else a key
23
+ * saved on the server `stored` reads for, opened now. One that does not open is absent, never a crash. */
24
+ export declare const secret: (name: string, stored?: StoredKeys) => string | undefined;
25
+ /** `env` with the secrets this process holds, for this process's own reading: every one, or (`"own"`) only those it was
26
+ * started with, none saved. Each secret is a property that does not enumerate: `env.NAME` reads it, while a spread of
27
+ * the object, or a spawn given it (Node builds a child's environment from its enumerable keys), leaves it out. Which
28
+ * came from a saved key is said too (savedIn), never a value. */
29
+ export declare const withSecrets: (env: NodeJS.ProcessEnv, which?: "all" | "own", stored?: StoredKeys) => NodeJS.ProcessEnv;
30
+ /** The secrets of `env` (one withSecrets made) that were saved on the server, not its own, by name. */
31
+ export declare const savedIn: (env: NodeJS.ProcessEnv) => ReadonlySet<string>;
32
+ /** The environment a child gets: `env` with every secret name taken out, and every other name shaped like a key
33
+ * (secret-cut.ts' keyShaped) with them, a backstop for a key no list names. Nothing passes the rule by name: a run's own
34
+ * descriptors (its secrets' pipe, its decision keys') are set on the environment after this cut. The server holds only
35
+ * the names on the launcher's list, so such a key stays in its own environment, never in a run's or another child's.
36
+ * Every environment serve builds for a child from its own takes this cut. */
37
+ export declare const withoutSecrets: (env: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
38
+ /** What a run's process is handed: the secrets named `names` that this process holds, or its server saved (`stored`),
39
+ * as its pipe carries them. */
40
+ export declare function handover(names: readonly string[], stored?: StoredKeys): Buffer;
41
+ /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
42
+ export declare const handoverSignIn: (value: {
43
+ provider: string;
44
+ ref: string;
45
+ save: boolean;
46
+ }) => Buffer;
47
+ /** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
48
+ export declare function handedSignIn(): {
49
+ provider: string;
50
+ ref: string;
51
+ save: boolean;
52
+ } | undefined;
53
+ /** pi-ai's auth context over `env` (one `withSecrets` made): its providers find their keys there, not in process.env. */
54
+ export declare const authContextOf: (env: NodeJS.ProcessEnv) => {
55
+ env: (name: string) => Promise<string | undefined>;
56
+ fileExists: (path: string) => Promise<boolean>;
57
+ };
58
+ /** How this process got its secrets: over a pipe (`fd`, and whether it closed it), or none was handed over. */
59
+ export declare const handoverState: () => {
60
+ fd: number;
61
+ closed: boolean;
62
+ } | undefined;
@@ -0,0 +1,158 @@
1
+ // The secrets serve and each run's process hold: in this module's memory, never in the environment. The launcher
2
+ // (launcher/agentrun-serve) hands them to serve over a pipe, and serve hands each run's process those it needs over a
3
+ // pipe of its own; each side reads its pipe as this module loads, before anything else, and closes it. A value set on
4
+ // process.env would be the default environment of every child, so none is: code that needs one asks `secret(name)`,
5
+ // or gets an env object `withSecrets` made for its own use, which no spawn takes. In the server, a secret it was not
6
+ // started with may be a tool key saved through the settings API (tool-keys.ts): read by the same name, opened when asked
7
+ // for, and handed to a run's process over its pipe like the launcher's, at each launch.
8
+ //
9
+ // With no launcher (a test that starts the server in its own process), a secret set in the environment is read from it.
10
+ import { closeSync, existsSync, readFileSync, readSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { keyShaped } from "./secret-cut.js";
13
+ import { MIN_SECRET } from "./learn/secrets.js";
14
+ /** The pipe and how many bytes of it are the secrets: the launcher's, or serve's to a run's process. */
15
+ export const SECRETS_FD_ENV = "AGENTRUN_SECRETS_FD";
16
+ export const SECRETS_LEN_ENV = "AGENTRUN_SECRETS_LEN";
17
+ /** The names of the secrets: the launcher's one list, which its `env -u`, serve's handover and the tests all read. Every
18
+ * key pi-ai's providers read is on it (model.ts' PROVIDER_KEYS, which the custody test checks against pi-ai's own
19
+ * table), so a key set for any provider's model is held here, never left in an environment. */
20
+ export const SECRET_NAMES = (() => {
21
+ const launcher = readFileSync(new URL("../launcher/agentrun-serve", import.meta.url), "utf8");
22
+ const list = /^SECRETS='([A-Z0-9_ ]+)'$/m.exec(launcher)?.[1];
23
+ if (!list)
24
+ throw new Error("agentrun-serve's launcher names no SECRETS");
25
+ return list.split(" ").filter(Boolean);
26
+ })();
27
+ /** The decision keys among them: a run's process gets them only on its decision descriptor (decisions.ts), never with
28
+ * the secrets on its pipe, which are its tools' environment. */
29
+ export const DECISION_KEYS = ["TYPESAFE_API_KEY", "PARALLEL_API_KEY"];
30
+ const held = new Map();
31
+ /** Whether this process was handed its secrets over a pipe, and closed it. */
32
+ let handed;
33
+ /** The pair a run's saved sign-in comes as on the same pipe (sign-ins.ts): JSON `{provider, ref, save}`, held apart from
34
+ * the secrets, so it is no tool's environment and no key a scan looks for by name. */
35
+ const SIGN_IN_PAIR = "AGENTRUN_SIGN_IN";
36
+ let signIn;
37
+ /** NAME=VALUE pairs, each ended by a NUL. */
38
+ const encode = (pairs) => Buffer.concat([...pairs].map(([name, value]) => Buffer.from(`${name}=${value}\0`)));
39
+ function decode(bytes) {
40
+ for (const pair of bytes.toString("utf8").split("\0")) {
41
+ const at = pair.indexOf("=");
42
+ if (at > 0 && SECRET_NAMES.includes(pair.slice(0, at)))
43
+ held.set(pair.slice(0, at), pair.slice(at + 1));
44
+ else if (pair.slice(0, at) === SIGN_IN_PAIR)
45
+ signIn = pair.slice(at + 1);
46
+ }
47
+ }
48
+ /** Exactly `length` bytes of `fd`: the writer keeps its end open (the launcher's FIFO is open read-write), so there is
49
+ * no end of file to wait for. */
50
+ function readExactly(fd, length) {
51
+ const bytes = Buffer.alloc(length);
52
+ for (let read = 0; read < length;) {
53
+ const got = readSync(fd, bytes, read, length - read, null);
54
+ if (got === 0)
55
+ throw new Error(`the secrets' pipe ended after ${read} of ${length} bytes`);
56
+ read += got;
57
+ }
58
+ return bytes;
59
+ }
60
+ {
61
+ const fd = process.env[SECRETS_FD_ENV];
62
+ const length = process.env[SECRETS_LEN_ENV];
63
+ delete process.env[SECRETS_FD_ENV];
64
+ delete process.env[SECRETS_LEN_ENV];
65
+ if (fd !== undefined) {
66
+ handed = { fd: Number(fd), closed: false };
67
+ try {
68
+ decode(readExactly(handed.fd, Number(length ?? 0)));
69
+ }
70
+ finally {
71
+ // Every child this process starts would otherwise get the pipe: an inherited descriptor has no close-on-exec.
72
+ closeSync(handed.fd);
73
+ handed.closed = true;
74
+ }
75
+ }
76
+ for (const name of SECRET_NAMES) {
77
+ const value = process.env[name];
78
+ if (value === undefined)
79
+ continue;
80
+ if (!held.has(name))
81
+ held.set(name, value);
82
+ delete process.env[name];
83
+ }
84
+ }
85
+ /** A name an environment gives a secret: a key, a token, a secret or a password. */
86
+ const SECRET_NAME = /(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD)$/i;
87
+ /** This host's secrets, for a scan of what a run wrote: each one the launcher lists, as this process holds it (never in
88
+ * the environment once handed over, so a scan of process.env alone sees none of them), and beside it the key a person
89
+ * saved under that name on the server `stored` reads for (a run that names its tool is handed it), and the value of
90
+ * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
91
+ * whitespace aside, matches too much text by chance to be refused, and is left out. */
92
+ export const hostSecrets = (env, stored) => {
93
+ const held = SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]);
94
+ const named = Object.entries(env).filter(([name]) => SECRET_NAME.test(name) && !SECRET_NAMES.includes(name)).map(([, value]) => value ?? "");
95
+ return [...new Set([...held, ...named])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
96
+ };
97
+ /** A secret this process was started with: as handed over, else (no launcher) as its environment has it now. */
98
+ const own = (name) => held.get(name) ?? process.env[name];
99
+ /** A secret's value: this process's own, which wins (tool-keys.ts' `source: "server"` is exactly these), else a key
100
+ * saved on the server `stored` reads for, opened now. One that does not open is absent, never a crash. */
101
+ export const secret = (name, stored) => {
102
+ const value = own(name);
103
+ return value || (stored?.(name) ?? value);
104
+ };
105
+ /** The names whose values a withSecrets env took from the keys saved on the server (StoredKeys), not its own. */
106
+ const SAVED = Symbol("agentrun.saved-keys");
107
+ /** `env` with the secrets this process holds, for this process's own reading: every one, or (`"own"`) only those it was
108
+ * started with, none saved. Each secret is a property that does not enumerate: `env.NAME` reads it, while a spread of
109
+ * the object, or a spawn given it (Node builds a child's environment from its enumerable keys), leaves it out. Which
110
+ * came from a saved key is said too (savedIn), never a value. */
111
+ export const withSecrets = (env, which = "all", stored) => {
112
+ const out = { ...env };
113
+ const saved = new Set();
114
+ for (const name of SECRET_NAMES) {
115
+ const value = which === "own" ? own(name) : secret(name, stored);
116
+ if (value !== undefined)
117
+ Object.defineProperty(out, name, { value, enumerable: false, writable: false, configurable: false });
118
+ if (value !== undefined && which === "all" && !own(name))
119
+ saved.add(name);
120
+ }
121
+ Object.defineProperty(out, SAVED, { value: saved, enumerable: false });
122
+ return out;
123
+ };
124
+ /** The secrets of `env` (one withSecrets made) that were saved on the server, not its own, by name. */
125
+ export const savedIn = (env) => env[SAVED] ?? new Set();
126
+ /** The environment a child gets: `env` with every secret name taken out, and every other name shaped like a key
127
+ * (secret-cut.ts' keyShaped) with them, a backstop for a key no list names. Nothing passes the rule by name: a run's own
128
+ * descriptors (its secrets' pipe, its decision keys') are set on the environment after this cut. The server holds only
129
+ * the names on the launcher's list, so such a key stays in its own environment, never in a run's or another child's.
130
+ * Every environment serve builds for a child from its own takes this cut. */
131
+ export const withoutSecrets = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => !SECRET_NAMES.includes(name) && !keyShaped(name)));
132
+ /** What a run's process is handed: the secrets named `names` that this process holds, or its server saved (`stored`),
133
+ * as its pipe carries them. */
134
+ export function handover(names, stored) {
135
+ return encode(names.flatMap((name) => {
136
+ const value = secret(name, stored);
137
+ return value === undefined ? [] : [[name, value]];
138
+ }));
139
+ }
140
+ /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
141
+ export const handoverSignIn = (value) => encode([[SIGN_IN_PAIR, JSON.stringify(value)]]);
142
+ /** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
143
+ export function handedSignIn() {
144
+ try {
145
+ const value = signIn === undefined ? undefined : JSON.parse(signIn);
146
+ return value && typeof value.provider === "string" && typeof value.ref === "string" && value.ref && typeof value.save === "boolean" ? { provider: value.provider, ref: value.ref, save: value.save } : undefined;
147
+ }
148
+ catch {
149
+ return undefined;
150
+ }
151
+ }
152
+ /** pi-ai's auth context over `env` (one `withSecrets` made): its providers find their keys there, not in process.env. */
153
+ export const authContextOf = (env) => ({
154
+ env: async (name) => env[name],
155
+ fileExists: async (path) => existsSync(path.startsWith("~") ? homedir() + path.slice(1) : path),
156
+ });
157
+ /** How this process got its secrets: over a pipe (`fd`, and whether it closed it), or none was handed over. */
158
+ export const handoverState = () => (handed ? { ...handed } : undefined);
@@ -0,0 +1,44 @@
1
+ export declare const SERVER_LOCK = "server.lock";
2
+ /** The data root's server, as it last said: `{ pid, until }`, `until` (epoch ms) when it stops, null while it runs. */
3
+ export declare const SERVER_STATE = "server.state";
4
+ /** Another server holds the data root. Its message is the one line the CLI prints before it exits 1. */
5
+ export declare class ServerLockHeldError extends Error {
6
+ readonly code = "SERVER_LOCK_HELD";
7
+ readonly file: string;
8
+ constructor(file: string, options?: {
9
+ cause?: unknown;
10
+ });
11
+ }
12
+ /** A held server lock: released once, by the server's close. */
13
+ export interface ServerLock {
14
+ readonly file: string;
15
+ release(): void;
16
+ }
17
+ /** Takes the data root's server lock, or throws ServerLockHeldError while another server (in any process) holds it.
18
+ * Anything that fails after the lock is taken (its mode, on a filesystem that refuses one) closes the connection, so
19
+ * the lock is dropped before the error reaches the caller. `options.chmod` is for tests. */
20
+ export declare function takeServerLock(dataRoot: string, options?: {
21
+ chmod?: (file: string, mode: number) => void;
22
+ }): ServerLock;
23
+ /** A server that is stopping, by its mark: its process, and when its stop is over at the latest (epoch ms). */
24
+ export type Stopping = {
25
+ pid: number;
26
+ until: number;
27
+ };
28
+ /** Records the data root's server as this process, running: once, as it starts, right after it takes the lock. */
29
+ export declare function markRunning(dataRoot: string): void;
30
+ /** Records the data root's server as stopping until `until`, as its close begins: the same file, rewritten in place in one
31
+ * write of the same length, never made again (a record that is gone is left gone), so the stop adds no entry. */
32
+ export declare function markStopping(dataRoot: string, until: number): void;
33
+ /** The data root's server, when its record says it is stopping, its process lives and its time is still ahead; none
34
+ * otherwise (no record, one that can't be read, a server that runs, or one that died as it stopped). */
35
+ export declare function stoppingOf(dataRoot: string, now?: number): Stopping | undefined;
36
+ /** Takes the data root's server lock, as takeServerLock. When another server holds it and is stopping (its record),
37
+ * waits for that server as long as its process lives, under one cap, its record's `until` (the server's whole close:
38
+ * its runs' drain, their carry backs and their boxes' cleanup), retrying every `everyMs`, and tells `waiting` once as it
39
+ * starts to. A server that is not stopping is refused at once with ServerLockHeldError, as is one that still holds the
40
+ * lock at its `until`, or a holder that is not the stopping server (its process gone, the lock still held). */
41
+ export declare function takeServerLockAfterStop(dataRoot: string, options?: {
42
+ waiting?: (stopping: Stopping) => void;
43
+ everyMs?: number;
44
+ }): Promise<ServerLock>;
@@ -0,0 +1,140 @@
1
+ // One server per data root, written for AgentRun. A server takes <data>/server.lock before anything reads or writes the
2
+ // data root, and holds it until it closes; a second server on the same root is refused by name and touches nothing.
3
+ //
4
+ // The lock is SQLite's EXCLUSIVE lock, as pi-durable-disk's owner.lock: held on one connection for the server's life,
5
+ // dropped by the kernel when the process dies (a crashed server's file is reused by the next start, never refused for
6
+ // existing), and refused to a second connection whether it is in another process or in this one. The file is opened by
7
+ // SQLite alone: a POSIX lock is dropped when any descriptor the process holds on the file is closed, so no other code
8
+ // may open it (its mode is set by path).
9
+ //
10
+ // pi-durable-disk forgets a command record written in another pid namespace only under the precondition this lock
11
+ // keeps: two servers never hold one data root at once.
12
+ //
13
+ // A server that stops keeps the lock until its runs' processes have drained and exited, which takes up to their drain
14
+ // and a second. It says so in <data>/server.state: written once as the server starts, right after it takes the lock
15
+ // (its pid, not stopping), and rewritten in place as its close begins (when its stop is over at the latest). A stop never
16
+ // adds an entry to the data root, so a caller that removes the directory as soon as it signals the stop meets nothing
17
+ // new there. A start that finds the lock held reads that file only then, and waits for a server that is stopping instead
18
+ // of refusing it; a record whose pid is gone or whose time has passed is no stop.
19
+ import { chmodSync, closeSync, openSync, readFileSync, writeFileSync, writeSync } from "node:fs";
20
+ import { join } from "node:path";
21
+ import { DatabaseSync } from "node:sqlite";
22
+ import { processAlive } from "@parcha/agentrun-kernel/host";
23
+ import { sqliteBusy } from "./agents.js";
24
+ export const SERVER_LOCK = "server.lock";
25
+ /** The data root's server, as it last said: `{ pid, until }`, `until` (epoch ms) when it stops, null while it runs. */
26
+ export const SERVER_STATE = "server.state";
27
+ /** The record's length on disk: its JSON padded with spaces, so a rewrite in place leaves no tail of an earlier one. */
28
+ const STATE_BYTES = 128;
29
+ const stateOf = (until) => Buffer.from(JSON.stringify({ pid: process.pid, until }).padEnd(STATE_BYTES - 1) + "\n");
30
+ /** Another server holds the data root. Its message is the one line the CLI prints before it exits 1. */
31
+ export class ServerLockHeldError extends Error {
32
+ code = "SERVER_LOCK_HELD";
33
+ file;
34
+ constructor(file, options) {
35
+ super(`another server holds this data root (${file}): stop it, or start this one with another --data`, options);
36
+ this.name = "ServerLockHeldError";
37
+ this.file = file;
38
+ }
39
+ }
40
+ /** Takes the data root's server lock, or throws ServerLockHeldError while another server (in any process) holds it.
41
+ * Anything that fails after the lock is taken (its mode, on a filesystem that refuses one) closes the connection, so
42
+ * the lock is dropped before the error reaches the caller. `options.chmod` is for tests. */
43
+ export function takeServerLock(dataRoot, options = {}) {
44
+ const file = join(dataRoot, SERVER_LOCK);
45
+ const db = new DatabaseSync(file, { timeout: 0 });
46
+ try {
47
+ db.exec("PRAGMA locking_mode = EXCLUSIVE");
48
+ db.exec("PRAGMA journal_mode = MEMORY");
49
+ db.exec("BEGIN EXCLUSIVE");
50
+ db.exec("COMMIT");
51
+ (options.chmod ?? chmodSync)(file, 0o600);
52
+ }
53
+ catch (error) {
54
+ try {
55
+ db.close();
56
+ }
57
+ catch {
58
+ // the lock is dropped with the connection; the error that got here is the one to report
59
+ }
60
+ if (sqliteBusy(error))
61
+ throw new ServerLockHeldError(file, { cause: error });
62
+ throw error;
63
+ }
64
+ let held = true;
65
+ return {
66
+ file,
67
+ release() {
68
+ if (!held)
69
+ return;
70
+ held = false;
71
+ db.close();
72
+ },
73
+ };
74
+ }
75
+ /** Records the data root's server as this process, running: once, as it starts, right after it takes the lock. */
76
+ export function markRunning(dataRoot) {
77
+ writeFileSync(join(dataRoot, SERVER_STATE), stateOf(null), { mode: 0o600 });
78
+ }
79
+ /** Records the data root's server as stopping until `until`, as its close begins: the same file, rewritten in place in one
80
+ * write of the same length, never made again (a record that is gone is left gone), so the stop adds no entry. */
81
+ export function markStopping(dataRoot, until) {
82
+ let fd;
83
+ try {
84
+ fd = openSync(join(dataRoot, SERVER_STATE), "r+");
85
+ }
86
+ catch (error) {
87
+ if (error.code === "ENOENT")
88
+ return;
89
+ throw error;
90
+ }
91
+ try {
92
+ writeSync(fd, stateOf(until), 0, STATE_BYTES, 0);
93
+ }
94
+ finally {
95
+ closeSync(fd);
96
+ }
97
+ }
98
+ /** The data root's server, when its record says it is stopping, its process lives and its time is still ahead; none
99
+ * otherwise (no record, one that can't be read, a server that runs, or one that died as it stopped). */
100
+ export function stoppingOf(dataRoot, now = Date.now()) {
101
+ let mark;
102
+ try {
103
+ mark = JSON.parse(readFileSync(join(dataRoot, SERVER_STATE), "utf8"));
104
+ }
105
+ catch {
106
+ return undefined;
107
+ }
108
+ const { pid, until } = (mark ?? {});
109
+ if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0 || typeof until !== "number" || !(until > now))
110
+ return undefined;
111
+ return processAlive(pid) ? { pid, until } : undefined;
112
+ }
113
+ /** Takes the data root's server lock, as takeServerLock. When another server holds it and is stopping (its record),
114
+ * waits for that server as long as its process lives, under one cap, its record's `until` (the server's whole close:
115
+ * its runs' drain, their carry backs and their boxes' cleanup), retrying every `everyMs`, and tells `waiting` once as it
116
+ * starts to. A server that is not stopping is refused at once with ServerLockHeldError, as is one that still holds the
117
+ * lock at its `until`, or a holder that is not the stopping server (its process gone, the lock still held). */
118
+ export async function takeServerLockAfterStop(dataRoot, options = {}) {
119
+ try {
120
+ return takeServerLock(dataRoot);
121
+ }
122
+ catch (error) {
123
+ if (!(error instanceof ServerLockHeldError))
124
+ throw error;
125
+ const stopping = stoppingOf(dataRoot);
126
+ if (!stopping)
127
+ throw error;
128
+ options.waiting?.(stopping);
129
+ for (;;) {
130
+ await new Promise((resolve) => setTimeout(resolve, options.everyMs ?? 250));
131
+ try {
132
+ return takeServerLock(dataRoot);
133
+ }
134
+ catch (again) {
135
+ if (!(again instanceof ServerLockHeldError) || Date.now() >= stopping.until || !processAlive(stopping.pid))
136
+ throw again;
137
+ }
138
+ }
139
+ }
140
+ }