@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,7 @@
1
+ export { capabilities, CONTRACT, DEFAULT_PORT, type Serve, type ServeOptions, startServe } from "./server.js";
2
+ export { SERVER_LOCK, type ServerLock, ServerLockHeldError, takeServerLock } from "./server-lock.js";
3
+ export { ApiError, ERROR_STATUS, type ErrorCode } from "./errors.js";
4
+ export { defaultMaxRuns, type Health } from "./host.js";
5
+ export { banner, type TokenSource } from "./print.js";
6
+ export { ASK_TOOL, BOUND_TOOLS, TOOLS, type ToolEntry } from "./tools.js";
7
+ export type { FauxHelpers } from "./model.js";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { capabilities, CONTRACT, DEFAULT_PORT, startServe } from "./server.js";
2
+ export { SERVER_LOCK, ServerLockHeldError, takeServerLock } from "./server-lock.js";
3
+ export { ApiError, ERROR_STATUS } from "./errors.js";
4
+ export { defaultMaxRuns } from "./host.js";
5
+ export { banner } from "./print.js";
6
+ export { ASK_TOOL, BOUND_TOOLS, TOOLS } from "./tools.js";
@@ -0,0 +1,37 @@
1
+ /** How long a provider has to answer a check. */
2
+ export declare const CHECK_MS = 5000;
3
+ /** What a saved key's row says of its check (GET /settings/tool-keys' `check`): accepted by its provider, or kept not
4
+ * checked and why. `at` is when it was checked; a key kept before this server checked keys has none. */
5
+ export type KeyCheck = {
6
+ state: "accepted";
7
+ at: string;
8
+ } | {
9
+ state: "not_checked";
10
+ reason: string;
11
+ at?: string;
12
+ };
13
+ /** A check's outcome: a KeyCheck to keep with the key, or the provider's refusal, in its words, when it is not kept. */
14
+ export type CheckOutcome = KeyCheck | {
15
+ state: "refused";
16
+ message: string;
17
+ };
18
+ type Call = {
19
+ url: string;
20
+ method?: "POST";
21
+ headers: Record<string, string>;
22
+ body?: string;
23
+ };
24
+ /** Each provider's check, by key id (tool-keys.ts' TOOL_KEYS, and a model provider's key where the server keeps one),
25
+ * made with the key and the server's environment, at the base this server sends that provider's calls to. */
26
+ export declare const KEY_CHECKS: Record<string, (key: string, env: NodeJS.ProcessEnv) => Call>;
27
+ /** A key not checked, by key id, and why: OpenAI answers 401 (missing_scope) to a restricted key that works but may not
28
+ * list models, which the 401 rule would refuse. */
29
+ export declare const NOT_CHECKED: Record<string, string>;
30
+ /** `row`'s key checked against its provider through `fetcher` (undefined: a faux server with no fake for it, so no call
31
+ * is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait. A refusal names the key as
32
+ * `name` (the server's own key, by its variable), else "this key" (the one a PUT sends). */
33
+ export declare function checkKey(row: {
34
+ id: string;
35
+ label: string;
36
+ }, key: string, env: NodeJS.ProcessEnv, fetcher: typeof fetch | undefined | null, ms?: number, stop?: AbortSignal, name?: string): Promise<CheckOutcome>;
37
+ export {};
@@ -0,0 +1,112 @@
1
+ // A key a person saves (tool-keys.ts) is checked against its provider before it is kept: one authenticated call that
2
+ // costs nothing, given CHECK_MS to answer. A 401 is the provider refusing the key, and the save is refused with nothing
3
+ // kept; a 2xx is the key accepted. A 403 is the provider knowing the key and not answering this call: a key scoped away
4
+ // from it (an OpenAI restricted key without the Models permission) may still do its tools' work, so it is never refused.
5
+ // That, no such call for the provider, no answer in time, the network, a redirect (never followed: Node's fetch carries
6
+ // a key's own header, x-api-key or x-bb-api-key, to wherever one points), or any other status keeps the key as not
7
+ // checked, saying why: an answer that does not say whether a key works never stops a save.
8
+ // Never a paid request: each call below cites the provider's pages that show it is not billed. No outcome holds the
9
+ // key: the provider's first sentence is quoted only when it holds no KEY_PIECE characters of the key in a row.
10
+ import { MONID_API } from "./monid.js";
11
+ import { isObject } from "./validate.js";
12
+ /** How long a provider has to answer a check. */
13
+ export const CHECK_MS = 5_000;
14
+ /** The fewest characters of a key in a row that keep a provider's words from being quoted. */
15
+ const KEY_PIECE = 6;
16
+ /** The most characters of a provider's words quoted. */
17
+ const QUOTE = 200;
18
+ const base = (set, fallback) => (set?.trim() || fallback).replace(/\/+$/, "");
19
+ /** Each provider's check, by key id (tool-keys.ts' TOOL_KEYS, and a model provider's key where the server keeps one),
20
+ * made with the key and the server's environment, at the base this server sends that provider's calls to. */
21
+ export const KEY_CHECKS = {
22
+ // A discover of one result, as every monid tool call starts. That discover costs nothing is read from monid's pricing
23
+ // page, not stated there: it prices running an endpoint, and shows that price in discover's results
24
+ // (https://docs.monid.ai/guide/pricing.html, https://docs.monid.ai/api/discover.html).
25
+ monid: (key) => ({ url: `${MONID_API}/v1/discover`, method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/json" }, body: JSON.stringify({ query: "company data", limit: 1 }) }),
26
+ // A list of the key's monitors: Parallel prices searches, extracts, decisions, task runs and a monitor's executions,
27
+ // never a list (https://docs.parallel.ai/api-reference/monitor/list-monitors, https://docs.parallel.ai/getting-started/pricing).
28
+ parallel: (key) => ({ url: "https://api.parallel.ai/v1/monitors?limit=1", headers: { "x-api-key": key } }),
29
+ // A list of the key's projects: Browserbase bills a session's browser time and proxy bandwidth, and this opens no
30
+ // session (https://docs.browserbase.com/reference/api/list-projects, https://docs.browserbase.com/account/billing/plans).
31
+ browserbase: (key, env) => ({ url: `${base(env.BROWSERBASE_BASE_URL, "https://api.browserbase.com")}/v1/projects`, headers: { "x-bb-api-key": key } }),
32
+ // A list of the key's browser sessions, one at most: Kernel bills a browser's running time, and this starts none
33
+ // (https://www.kernel.sh/docs/api-reference/browsers/list-browser-sessions, https://www.kernel.sh/docs/info/pricing).
34
+ kernel: (key, env) => ({ url: `${base(env.KERNEL_BASE_URL, "https://api.onkernel.com")}/browsers?limit=1`, headers: { authorization: `Bearer ${key}` } }),
35
+ // A list of the account's models: TypeSafe prices a System One request's input tokens
36
+ // (https://docs.typesafe.ai/api/list-models, https://docs.typesafe.ai/models).
37
+ typesafe: (key, env) => ({ url: `${base(env.TYPESAFE_BASE_URL, "https://api.typesafe.ai")}/v1/models`, headers: { authorization: `Bearer ${key}` } }),
38
+ // A model provider's key: its list of models, or OpenRouter's record of the key; each prices tokens, and these use none
39
+ // (https://platform.claude.com/docs/en/api/models/list, https://openrouter.ai/docs/api-reference/limits). OpenAI's is
40
+ // in NOT_CHECKED.
41
+ anthropic: (key, env) => ({ url: `${base(env.ANTHROPIC_BASE_URL, "https://api.anthropic.com")}/v1/models?limit=1`, headers: { "x-api-key": key, "anthropic-version": "2023-06-01" } }),
42
+ openrouter: (key) => ({ url: "https://openrouter.ai/api/v1/key", headers: { authorization: `Bearer ${key}` } }),
43
+ };
44
+ /** A key not checked, by key id, and why: OpenAI answers 401 (missing_scope) to a restricted key that works but may not
45
+ * list models, which the 401 rule would refuse. */
46
+ export const NOT_CHECKED = {
47
+ openai: "OpenAI keys aren't checked here: a restricted key can work without listing models",
48
+ };
49
+ /** The provider's words in an answer's `text`: its JSON error's message, else plain text (never a page), its first
50
+ * sentence, at most QUOTE characters; empty when they hold KEY_PIECE characters of `key` in a row, or there are none. */
51
+ function quoted(text, key) {
52
+ let words = text.trim();
53
+ try {
54
+ const json = JSON.parse(words);
55
+ const error = isObject(json) ? json.error : undefined;
56
+ const said = isObject(json) ? [isObject(error) ? error.message : error, json.message, json.detail].find((item) => typeof item === "string") : undefined;
57
+ words = typeof said === "string" ? said : "";
58
+ }
59
+ catch {
60
+ if (words.startsWith("<"))
61
+ words = "";
62
+ }
63
+ const sentence = words.replace(/\s+/g, " ").trim().split(/(?<=[.!?]) /)[0].replace(/\.$/, "").slice(0, QUOTE);
64
+ const piece = Math.min(KEY_PIECE, key.length);
65
+ for (let at = 0; at + piece <= key.length; at++)
66
+ if (sentence.includes(key.slice(at, at + piece)))
67
+ return "";
68
+ return sentence;
69
+ }
70
+ /** `row`'s key checked against its provider through `fetcher` (undefined: a faux server with no fake for it, so no call
71
+ * is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait. A refusal names the key as
72
+ * `name` (the server's own key, by its variable), else "this key" (the one a PUT sends). */
73
+ export async function checkKey(row, key, env, fetcher, ms = CHECK_MS, stop, name = "this key") {
74
+ const at = new Date().toISOString();
75
+ const notChecked = (reason) => ({ state: "not_checked", reason, at });
76
+ if (Object.hasOwn(NOT_CHECKED, row.id))
77
+ return notChecked(NOT_CHECKED[row.id]);
78
+ const check = Object.hasOwn(KEY_CHECKS, row.id) ? KEY_CHECKS[row.id] : undefined;
79
+ if (!check)
80
+ return notChecked(`${row.label} has no call that costs nothing to check a key with`);
81
+ if (!fetcher)
82
+ return notChecked(`This server runs on faux providers and has no fake ${row.label} to check the key with`);
83
+ const { url, ...init } = check(key, env);
84
+ let res;
85
+ try {
86
+ res = await fetcher(url, { ...init, redirect: "manual", signal: stop ? AbortSignal.any([AbortSignal.timeout(ms), stop]) : AbortSignal.timeout(ms) });
87
+ }
88
+ catch (error) {
89
+ if (error?.name === "TimeoutError")
90
+ return notChecked(`${row.label} did not answer in ${ms / 1000} s`);
91
+ const cause = error?.cause?.code;
92
+ const why = quoted(typeof cause === "string" ? cause : String(error?.message ?? error), key);
93
+ return notChecked(`${row.label} could not be reached${why ? ` (${why})` : ""}`);
94
+ }
95
+ const { status } = res;
96
+ if (status >= 200 && status < 300) {
97
+ await res.body?.cancel().catch(() => undefined);
98
+ return { state: "accepted", at };
99
+ }
100
+ if (status >= 300 && status < 400) {
101
+ await res.body?.cancel().catch(() => undefined);
102
+ return notChecked(`${row.label} answered ${status} (a redirect, not followed)`);
103
+ }
104
+ // The status decides. The provider's words only add to it: quoted when its body reads in time, else not at all, so a
105
+ // 401 whose body is cut off or stalls past the deadline still refuses the key.
106
+ const said = quoted(await res.text().catch(() => ""), key);
107
+ if (status === 401)
108
+ return { state: "refused", message: `${row.label} refused ${name} (401${said ? `: ${said}` : ""})` };
109
+ if (status === 403)
110
+ return notChecked(`${row.label} would not answer the check (403${said ? `: ${said}` : ""}); the key may still work for its tools`);
111
+ return notChecked(`${row.label} answered ${status}${said ? ` (${said})` : ""}`);
112
+ }
@@ -0,0 +1,51 @@
1
+ /** The key a run's model requests carry, and who reads it: a provider's (saved in Settings → Model keys, or set where
2
+ * AgentRun starts), or serve's gateway's (set where AgentRun starts only). */
3
+ export type RunKey = {
4
+ who: string;
5
+ field: string;
6
+ saved: boolean;
7
+ };
8
+ /** The key `harness`'s run of model `ref` (the revision's; none, this host's default for the harness) sends, by the route
9
+ * each harness takes (adapters.ts, model.ts); undefined where it is not a model key this server names. */
10
+ export declare function runKeyOf(env: NodeJS.ProcessEnv, harness?: string, ref?: string): RunKey | undefined;
11
+ /** `text`, a run's error as serve shows it, with no held secret in it: the one rule learning's checker uses
12
+ * (learn/secrets.ts redactSecrets: each value as written, JSON-escaped, base64 at each offset, hex and percent-encoded,
13
+ * and secret-shaped text), over `secrets`, the values the server holds and handed its run.
14
+ *
15
+ * Only the head serve can show is read: SHOWN characters, plus room for the longest held value in its widest encoded
16
+ * form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
17
+ * starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
18
+ * error costs no more to redact than a short one, whatever it holds. */
19
+ export declare function redacted(text: string, secrets: readonly string[]): string;
20
+ /** How many texts redactedAnswer has read in this process: a test reads it to see a run's view served from what an
21
+ * earlier view redacted (runs.ts servedOnce). */
22
+ export declare const answerPasses: {
23
+ count: number;
24
+ };
25
+ /** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
26
+ * in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
27
+ * whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
28
+ * finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none. A run of more
29
+ * than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
30
+ * by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
31
+ * output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
32
+ export declare function redactedAnswer(text: string, secrets: readonly string[]): string;
33
+ /** `value`, a run's workflow output, with redactedAnswer applied to each string and number in it, property NAMES
34
+ * included (a dictionary field can be keyed by anything a run wrote), its shape kept. Two names of one object that come
35
+ * out the same would merge one value over the other: that object is withheld whole, as "[redacted]". */
36
+ export declare function redactedOutput(value: unknown, secrets: readonly string[]): unknown;
37
+ /** What a thinking or text block may show while it streams (pi-durable-agent's `redactLive`): what has streamed so far,
38
+ * redacted by the same rule as redacted(), less a fixed tail held back until the block ends, when its settled row
39
+ * replaces this one whole. A key whose head has streamed but not its tail cannot be found by any redactor, and a key
40
+ * ending inside the tail would show its head. So the tail is the most a held value takes in its widest form (6 times it,
41
+ * plus 16), and only output that comes from raw text before it is kept: as in redacted(), each replacement moves what
42
+ * follows it left by at most S characters in all, so output[0, visible - S) comes from raw text before `visible`, where
43
+ * every key that starts ends inside what was read and was found whole, a key split by a line break among them. At most
44
+ * SHOWN characters are read past the tail, so a long stream costs no more than a short one. */
45
+ export declare function redactedLive(text: string, secrets: readonly string[]): string;
46
+ /** `text`, a run's error, in a person's words when it is a provider's 401 for `key` (REFUSED), with no value of
47
+ * `secrets` in it; undefined when it is not one. */
48
+ export declare function keyRefusal(text: string | undefined, key: RunKey | undefined, secrets?: readonly string[]): string | undefined;
49
+ /** `text`, a run's error, with no loopback address in it: Codex's `url:` tail goes (tried at the last "url:" only), and
50
+ * any other, with a scheme or bare with its port, becomes "a local address". */
51
+ export declare function withoutLoopback(text: string): string;
@@ -0,0 +1,191 @@
1
+ // A model provider that refuses the run's key (401) says so in a person's words, naming the key and where to set it,
2
+ // in place of the provider's raw answer as each harness passes it on. Formed where a run's error is (runs.ts), so it
3
+ // holds on every harness. Only the shapes the harnesses give count (REFUSED); a 401 anywhere else in an error (a
4
+ // count, a file name, a duration, another service's status) is no refused key, and the error is left as it is.
5
+ import { DEFAULT_HARNESS } from "./harness.js";
6
+ import { redactSecrets, valueMatcher } from "./learn/secrets.js";
7
+ import { hostModel, MODEL_KEYS, openRouterOnly } from "./model.js";
8
+ const row = (id) => {
9
+ const found = MODEL_KEYS.find((r) => r.id === id);
10
+ return found && { who: found.label, field: found.field, saved: true };
11
+ };
12
+ /** The key `harness`'s run of model `ref` (the revision's; none, this host's default for the harness) sends, by the route
13
+ * each harness takes (adapters.ts, model.ts); undefined where it is not a model key this server names. */
14
+ export function runKeyOf(env, harness = DEFAULT_HARNESS, ref) {
15
+ const named = ref ?? hostModel(env, "default", harness);
16
+ const provider = named?.includes("/") ? named.slice(0, named.indexOf("/")) : undefined;
17
+ const gateway = { who: "The gateway at AGENT_MODEL_BASE_URL", field: "AGENT_MODEL_API_KEY", saved: false };
18
+ if (harness === "claude-agent")
19
+ return row(provider === "openrouter" || openRouterOnly("claude-agent", env) ? "openrouter" : "anthropic");
20
+ if (env.AGENT_MODEL_BASE_URL)
21
+ return gateway;
22
+ if (harness === "codex" || harness === "opencode")
23
+ return row(provider === "openrouter" || openRouterOnly(harness, env) ? "openrouter" : "openai");
24
+ return provider === undefined ? undefined : row(provider);
25
+ }
26
+ /** The provider's own words after its 401: the message of the JSON it answered, else the text, its status word and any
27
+ * `url:` tail cut; its first sentence only, at most 200 characters. */
28
+ function detailOf(rest) {
29
+ const brace = rest.indexOf("{");
30
+ if (brace >= 0) {
31
+ try {
32
+ const body = JSON.parse(rest.slice(brace, rest.lastIndexOf("}") + 1));
33
+ const said = typeof body.error === "object" ? body.error?.message : body.error ?? body.message;
34
+ if (typeof said === "string")
35
+ rest = said;
36
+ }
37
+ catch {
38
+ rest = rest.slice(0, brace);
39
+ }
40
+ }
41
+ const text = rest.replace(/^[\s:.-]*(unauthorized\b)?[\s:.-]*/i, "").replace(/,?\s*url:.*$/is, "").trim();
42
+ return (text.split(/(?<=[.!?])\s/)[0] ?? "").slice(0, 200).replace(/[.\s]+$/, "");
43
+ }
44
+ /** The most of a run's error or a tool's output serve ever shows: a Timeline row's text, cut at 2000 characters
45
+ * (pi-durable-agent's CAPS.text; a summary and a tool result's preview at 500), which the error box reads too. */
46
+ const SHOWN = 2000;
47
+ /** `text`, a run's error as serve shows it, with no held secret in it: the one rule learning's checker uses
48
+ * (learn/secrets.ts redactSecrets: each value as written, JSON-escaped, base64 at each offset, hex and percent-encoded,
49
+ * and secret-shaped text), over `secrets`, the values the server holds and handed its run.
50
+ *
51
+ * Only the head serve can show is read: SHOWN characters, plus room for the longest held value in its widest encoded
52
+ * form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
53
+ * starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
54
+ * error costs no more to redact than a short one, whatever it holds. */
55
+ export function redacted(text, secrets) {
56
+ const longest = secrets.reduce((most, value) => Math.max(most, value.length), 0);
57
+ const window = SHOWN + 6 * longest + 16;
58
+ if (text.length <= window)
59
+ return redactSecrets(text, secrets, Buffer.byteLength(text));
60
+ const out = redactSecrets(text.slice(0, window), secrets, window * 4);
61
+ // A replacement moves what follows it left by at most S characters in all: the shortening, plus 2 for each "[redacted]"
62
+ // (a value of 8 or 9 characters grows into it). So output[0, SHOWN - S) comes from raw text before SHOWN, where every
63
+ // key that starts ends inside the window and was found whole; past that, a copy the window cut could come into view.
64
+ const shift = window - out.length + 2 * out.split("[redacted]").length - 2;
65
+ const keep = SHOWN - shift;
66
+ return keep <= 0 ? "[redacted]" : `${out.slice(0, keep)}...`;
67
+ }
68
+ /** The most of a run's answer one redaction pass reads: learning's redactSecrets restarts after each overlapping match,
69
+ * so its cost grows with the square of what it reads; pieces this size keep each pass small. */
70
+ const ANSWER_PIECE = 8192;
71
+ /** How many texts redactedAnswer has read in this process: a test reads it to see a run's view served from what an
72
+ * earlier view redacted (runs.ts servedOnce). */
73
+ export const answerPasses = { count: 0 };
74
+ /** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
75
+ * in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
76
+ * whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
77
+ * finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none. A run of more
78
+ * than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
79
+ * by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
80
+ * output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
81
+ export function redactedAnswer(text, secrets) {
82
+ if (!text)
83
+ return text;
84
+ answerPasses.count++;
85
+ const parts = [];
86
+ for (let from = 0; from < text.length;) {
87
+ let to = Math.min(text.length, from + ANSWER_PIECE);
88
+ if (to < text.length) {
89
+ const space = text.slice(from, to).search(/\s[^\s]*$/);
90
+ if (space <= 0) {
91
+ // No whitespace in this piece: the run of text with none goes on to the next whitespace, read as one.
92
+ const next = text.slice(to).search(/\s/);
93
+ to = next < 0 ? text.length : to + next;
94
+ parts.push(to - from > ANSWER_PIECE ? "[redacted]" : redactSecrets(text.slice(from, to), secrets, Buffer.byteLength(text.slice(from, to))));
95
+ from = to;
96
+ continue;
97
+ }
98
+ to = from + space + 1;
99
+ }
100
+ const piece = text.slice(from, to);
101
+ parts.push(redactSecrets(piece, secrets, Buffer.byteLength(piece)));
102
+ from = to;
103
+ }
104
+ const out = parts.join("");
105
+ return valueMatcher(secrets)(out) ? "[redacted]" : out;
106
+ }
107
+ /** `value`, a run's workflow output, with redactedAnswer applied to each string and number in it, property NAMES
108
+ * included (a dictionary field can be keyed by anything a run wrote), its shape kept. Two names of one object that come
109
+ * out the same would merge one value over the other: that object is withheld whole, as "[redacted]". */
110
+ export function redactedOutput(value, secrets) {
111
+ if (typeof value === "string")
112
+ return redactedAnswer(value, secrets);
113
+ // A held value can be all digits (a gateway's key), and a record can quote it as a number: one whose digits hold a held
114
+ // value, by the same rule as a string's, is withheld as "[redacted]". A boolean's text is shorter than any held value.
115
+ // A number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy).
116
+ if (typeof value === "number" || typeof value === "bigint") {
117
+ const text = String(value);
118
+ const held = redactedAnswer(text, secrets) !== text || secrets.some((secret) => secret.trim() !== "" && Number(secret) === Number(value));
119
+ return held ? "[redacted]" : value;
120
+ }
121
+ if (Array.isArray(value))
122
+ return value.map((item) => redactedOutput(item, secrets));
123
+ if (value && typeof value === "object") {
124
+ const entries = Object.entries(value).map(([key, item]) => [redactedAnswer(key, secrets), redactedOutput(item, secrets)]);
125
+ return new Set(entries.map(([key]) => key)).size === entries.length ? Object.fromEntries(entries) : "[redacted]";
126
+ }
127
+ return value;
128
+ }
129
+ /** What a thinking or text block may show while it streams (pi-durable-agent's `redactLive`): what has streamed so far,
130
+ * redacted by the same rule as redacted(), less a fixed tail held back until the block ends, when its settled row
131
+ * replaces this one whole. A key whose head has streamed but not its tail cannot be found by any redactor, and a key
132
+ * ending inside the tail would show its head. So the tail is the most a held value takes in its widest form (6 times it,
133
+ * plus 16), and only output that comes from raw text before it is kept: as in redacted(), each replacement moves what
134
+ * follows it left by at most S characters in all, so output[0, visible - S) comes from raw text before `visible`, where
135
+ * every key that starts ends inside what was read and was found whole, a key split by a line break among them. At most
136
+ * SHOWN characters are read past the tail, so a long stream costs no more than a short one. */
137
+ export function redactedLive(text, secrets) {
138
+ const hold = 6 * secrets.reduce((most, value) => Math.max(most, value.length), 0) + 16;
139
+ const visible = Math.min(SHOWN, text.length - hold);
140
+ if (visible <= 0)
141
+ return "";
142
+ const window = Math.min(text.length, visible + hold);
143
+ const out = redactSecrets(text.slice(0, window), secrets, window * 4);
144
+ const shift = window - out.length + 2 * (out.split("[redacted]").length - 1);
145
+ const keep = visible - shift;
146
+ return keep <= 0 ? "" : out.slice(0, keep);
147
+ }
148
+ /** A provider's 401 as each harness puts it, at the start of the run's error:
149
+ * - pi-ai: `401: <body>` (its OpenAI-shaped APIs, OpenRouter's chat completions among them), `401 <body>` (Anthropic's
150
+ * SDK), or `<provider> API error (401): <body>` (its Responses API, serve's gateway's `agent-model API error (401): …`);
151
+ * - the Claude CLI, named by its adapter: `claude-agent: Failed to authenticate. API Error: 401 <message>`;
152
+ * - the Codex binary, named by its adapter: `codex: unexpected status 401 Unauthorized: <message>, url: …`.
153
+ * The match ends at the status, and the provider's words follow it. */
154
+ const REFUSED = /^(?:401\b|[^:\n]*\berror \(401\)|(?:claude-agent: )?(?:Failed to authenticate\. )?API Error: 401\b|(?:codex: )?unexpected status 401\b)/;
155
+ /** `text`, a run's error, in a person's words when it is a provider's 401 for `key` (REFUSED), with no value of
156
+ * `secrets` in it; undefined when it is not one. */
157
+ export function keyRefusal(text, key, secrets = []) {
158
+ if (!text || !key)
159
+ return undefined;
160
+ // Every held key's value out of the whole text first: cut afterwards, a key the provider echoed across the cut would
161
+ // keep its start in the words.
162
+ const said = redacted(text, secrets);
163
+ const at = REFUSED.exec(said);
164
+ if (!at)
165
+ return undefined;
166
+ const detail = detailOf(said.slice(at[0].length));
167
+ const where = key.saved ? "set it where AgentRun starts, or save it in Settings → Model keys." : "set it where AgentRun starts.";
168
+ return `${key.who} refused ${key.field} (401${detail ? `: ${detail}` : ""}): ${where}`;
169
+ }
170
+ /** Codex's errors end on the address it sent the request to (", url: " and then serve's own loopback model proxy, with
171
+ * its port and /v1/responses); any loopback address in a run's error is the host's, never a person's. Only a loopback
172
+ * host itself: a host name that only starts with a loopback name goes on past it, is a public host, and keeps its
173
+ * address. Every pattern is tried at one place or advances past what it read, so a rewrite takes time in proportion to
174
+ * the text. */
175
+ const LOOPBACK_TAIL = /^url:\s*https?:\/\/(?:127\.0\.0\.1|localhost|\[::1\])(?![\w.-])(:\d+)?\S*\s*$/i; // key-gate: loopback-rule strips the loopback proxy address codex prints
176
+ const LOOPBACK = /https?:\/\/(?:127\.0\.0\.1|localhost|\[::1\])(?![\w.-])(:\d+)?[^\s,;:)\x22\x27\]]*/gi; // key-gate: loopback-rule replaces any loopback address in a run error
177
+ const LOOPBACK_BARE = /(?<![\w.\/-])(?:127\.0\.0\.1|localhost|\[::1\])(:\d+)(?![\w.-])/gi; // key-gate: loopback-rule replaces a bare loopback address with its port, a refused connection to the proxy
178
+ /** `text`, a run's error, with no loopback address in it: Codex's `url:` tail goes (tried at the last "url:" only), and
179
+ * any other, with a scheme or bare with its port, becomes "a local address". */
180
+ export function withoutLoopback(text) {
181
+ let at = -1;
182
+ for (const found of text.matchAll(/url:/gi))
183
+ at = found.index;
184
+ let out = text;
185
+ if (at >= 0 && LOOPBACK_TAIL.test(text.slice(at))) {
186
+ out = text.slice(0, at).trimEnd();
187
+ if (out.endsWith(","))
188
+ out = out.slice(0, -1);
189
+ }
190
+ return out.replace(LOOPBACK, "a local address").replace(LOOPBACK_BARE, "a local address");
191
+ }
@@ -0,0 +1,108 @@
1
+ import { type LearnedNote } from "./notes.js";
2
+ import { type DraftReader } from "./skills.js";
3
+ /** Byte caps (UTF-8) and counts. Over a cap is refused, never cut. */
4
+ export declare const CAPS: Readonly<{
5
+ /** One note's file. */
6
+ note: 4096;
7
+ /** One note a run proposes: the note cap less HOST_LINES, so a run's note stays within `note` once the host merges
8
+ * it, and a person can still retire it and a later run supersede it, each read and checked against `note`. */
9
+ runNote: number;
10
+ /** New notes in one run. */
11
+ newNotes: 8;
12
+ /** Notes one run's new notes supersede, together. */
13
+ supersedes: 8;
14
+ /** Changed paths in one run; over it nothing else is read. */
15
+ changes: 64;
16
+ /** One skill's SKILL.md, or one workflow draft's workflow.json: one grader reads each whole beside the notes, so the
17
+ * most a run proposes stays within its prompt (grade.ts GRADE_CAPS.prompt). */
18
+ file: 16384;
19
+ /** One draft's README.md, which the host writes from the one-line description its block gives. */
20
+ readme: 1024;
21
+ /** Skills one run adds or changes. */
22
+ skills: 1;
23
+ /** Workflow drafts one run adds or changes. */
24
+ workflows: 1;
25
+ }>;
26
+ /** The rule a problem breaks. SPEC.md lists each. */
27
+ export type Rule = "too_many_files" | "outside" | "file_name" | "file_mode" | "encoding" | "edited" | "deleted" | "exists" | "too_large" | "too_many_notes" | "invisible_unicode" | "secret_shape" | "secret_value" | "note" | "status" | "supersedes" | "index_full" | "skill" | "skill_outcome" | "too_many_skills" | "workflow" | "too_many_workflows" | "no_tool_list" | "executable_node" | "skill_front_matter" | "skill_status";
28
+ /** One problem with what a run proposed, printable as it is. */
29
+ export type Problem = {
30
+ readonly rule: Rule;
31
+ readonly path?: string;
32
+ readonly detail: string;
33
+ };
34
+ /** One file of the run's copy that differs from the commit it started from. `mode` is git's (`100644` a regular file,
35
+ * `120000` a link, `040000` a folder; anything else is not a regular file). A change that is not a deletion carries its
36
+ * bytes, or only its `size` when that is over the note cap. */
37
+ export type Change = {
38
+ readonly path: string;
39
+ readonly status: "added" | "modified" | "deleted";
40
+ readonly mode?: string;
41
+ readonly size?: number;
42
+ readonly bytes?: Uint8Array;
43
+ };
44
+ /** The folder a proposal is checked against (the run's seed, or main at merge time): every path it holds, and its active
45
+ * notes. */
46
+ export type Base = {
47
+ readonly files: Iterable<string>;
48
+ readonly active: readonly LearnedNote[];
49
+ };
50
+ /** A new note that passed, with its whole text. */
51
+ export type ProposedNote = LearnedNote & {
52
+ readonly text: string;
53
+ };
54
+ export type CheckInput = {
55
+ readonly base: Base;
56
+ readonly changes: readonly Change[];
57
+ /** Values the host holds as secrets: a file, or a file's name, that holds one is refused. */
58
+ readonly refuseValues?: readonly string[];
59
+ /** How the run's job ended, its status (`completed`, `failed`, ...). Only a completed run adds or changes a skill:
60
+ * without it, none does. */
61
+ readonly outcome?: string;
62
+ /** The tools a workflow draft may name: the agent's granted tools a workflow's call node runs here (tools.ts
63
+ * learnedWorkflowTools). Without it, a draft that names a tool is refused. */
64
+ readonly tools?: readonly string[];
65
+ /** The agent's granted tools the gate does not allow, with what each is set to (tools.ts learnedDraftTools): a draft
66
+ * whose call node calls one is refused, in the words a workflow revision's is (learn/skills.ts gatedNodes). */
67
+ readonly gated?: Readonly<Record<string, string>>;
68
+ /** The workflow DSL a draft is read with; a proposal that holds a draft is checked with it, never without. */
69
+ readonly dsl?: DraftReader;
70
+ /** The skills' and drafts' files whose text in the run's seed has a status (a person retired it, or it waits for its
71
+ * owner's OK): a run never changes those. A draft's is its README.md. */
72
+ readonly kept?: readonly string[];
73
+ };
74
+ /** `ok` when `problems` is empty; then `notes` are the new notes, each in shape. */
75
+ export type ProposalCheck = {
76
+ readonly ok: boolean;
77
+ readonly problems: Problem[];
78
+ readonly notes: ProposedNote[];
79
+ };
80
+ /** `problem` as it may be printed: its path and detail cut of `values` and of secret shapes, whole when over PRINT_MAX. */
81
+ export declare const printable: (problem: Problem, values: readonly string[]) => Problem;
82
+ /** The checks one note's file passes by itself (SPEC.md), as a person writes it through the host: its name, the note cap,
83
+ * UTF-8, hidden characters, secret shapes and the host's values in its name and text, and its front matter. A person
84
+ * may set `status` and `superseded_by`; what a run may not do (edit, delete, set status) is checkProposal's. Every
85
+ * problem is printable. */
86
+ export declare function checkNote(path: string, bytes: Uint8Array, refuseValues?: readonly string[]): {
87
+ problems: Problem[];
88
+ note?: ProposedNote;
89
+ };
90
+ /** Checks what a run proposes against SPEC.md: its notes, and a skill or workflow drafts beside them (learnedChecked).
91
+ * `MEMORY.md` is the host's: a change to it is ignored, never refused. */
92
+ /** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
93
+ * name and text scans (nameScanned, textOf) of each change, its text read whole (an edit, a file over its cap, one not
94
+ * a regular file included), printable as checkProposal's are. A text that is not UTF-8 is `encoding`: unread, so
95
+ * never trusted. Empty when nothing in them must be refused. Ahead of keeping some items of a proposal the checks
96
+ * refuse (propose.ts): an item refused before its text was read hides nothing. */
97
+ export declare function unstorable(changes: readonly Change[], refuseValues?: readonly string[]): Problem[];
98
+ export declare function checkProposal(input: CheckInput): ProposalCheck;
99
+ /** The notes the active ones of `notes` supersede, each by the note that supersedes it. A note that waits for its
100
+ * owner's OK (`status: pending`) supersedes nothing until it is approved: what it names stays active. The one rule the
101
+ * merge writes by (grade.ts mergeProposal) and its index is counted by (mergeProblems). */
102
+ export declare function supersededBy(notes: readonly LearnedNote[]): Map<string, string>;
103
+ /** What stops `notes` from joining `base` as they are: a name `base` holds (`exists`), a `supersedes` that names no
104
+ * active note of `base` or one another new note supersedes too, or more than CAPS.supersedes notes superseded, and an
105
+ * index past INDEX_LINES, counted as the merge makes it (supersededBy: a pending note adds no line and replaces none).
106
+ * The checker asks it of the run's seed, where every new note is active; the host asks it again of main at merge time,
107
+ * with each note as it merges it, since other runs may have merged meanwhile. */
108
+ export declare function mergeProblems(base: Base, notes: readonly LearnedNote[], refuseValues?: readonly string[]): Problem[];