@parcha/agentrun-serve 0.0.0-bootstrap.0 → 0.1.0-beta.29

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 (229) hide show
  1. package/CHANGELOG.md +560 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +1724 -0
  5. package/dist/adapters.d.ts +205 -0
  6. package/dist/adapters.js +459 -0
  7. package/dist/agents.d.ts +124 -0
  8. package/dist/agents.js +302 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +324 -0
  11. package/dist/bound-files.d.ts +4 -0
  12. package/dist/bound-files.js +164 -0
  13. package/dist/box/record.d.ts +6 -0
  14. package/dist/box/record.js +41 -0
  15. package/dist/box/sweep.d.ts +53 -0
  16. package/dist/box/sweep.js +193 -0
  17. package/dist/box-image.d.ts +98 -0
  18. package/dist/box-image.js +283 -0
  19. package/dist/box-relay.d.ts +42 -0
  20. package/dist/box-relay.js +222 -0
  21. package/dist/boxes.d.ts +54 -0
  22. package/dist/boxes.js +182 -0
  23. package/dist/cap.d.ts +224 -0
  24. package/dist/cap.js +721 -0
  25. package/dist/catalog.d.ts +20 -0
  26. package/dist/catalog.js +53 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +167 -0
  29. package/dist/coding-tools.d.ts +31 -0
  30. package/dist/coding-tools.js +81 -0
  31. package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
  32. package/dist/console/assets/index-BN7oVcO4.js +445 -0
  33. package/dist/console/assets/index-By-jkqki.css +1 -0
  34. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  35. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  36. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  37. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  38. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  39. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  40. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  41. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  42. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  53. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  54. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  57. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  58. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  59. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  60. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  61. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  62. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  63. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  64. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  65. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  66. package/dist/console/index.html +15 -0
  67. package/dist/daytona-api.d.ts +21 -0
  68. package/dist/daytona-api.js +101 -0
  69. package/dist/decision-rows.d.ts +11 -0
  70. package/dist/decision-rows.js +116 -0
  71. package/dist/decisions.d.ts +94 -0
  72. package/dist/decisions.js +184 -0
  73. package/dist/effort-guidance.d.ts +5 -0
  74. package/dist/effort-guidance.js +14 -0
  75. package/dist/environment.d.ts +5 -0
  76. package/dist/environment.js +11 -0
  77. package/dist/errors.d.ts +72 -0
  78. package/dist/errors.js +66 -0
  79. package/dist/exa-keyless.d.ts +35 -0
  80. package/dist/exa-keyless.js +202 -0
  81. package/dist/fetch-page.d.ts +114 -0
  82. package/dist/fetch-page.js +182 -0
  83. package/dist/files.d.ts +60 -0
  84. package/dist/files.js +153 -0
  85. package/dist/grade.d.ts +96 -0
  86. package/dist/grade.js +348 -0
  87. package/dist/graph-view.d.ts +100 -0
  88. package/dist/graph-view.js +212 -0
  89. package/dist/harness-app.d.ts +38 -0
  90. package/dist/harness-app.js +626 -0
  91. package/dist/harness.d.ts +53 -0
  92. package/dist/harness.js +74 -0
  93. package/dist/home-path.d.ts +27 -0
  94. package/dist/home-path.js +78 -0
  95. package/dist/host-tools.d.ts +20 -0
  96. package/dist/host-tools.js +140 -0
  97. package/dist/host.d.ts +39 -0
  98. package/dist/host.js +81 -0
  99. package/dist/hosted-search.d.ts +27 -0
  100. package/dist/hosted-search.js +129 -0
  101. package/dist/import-sources.d.ts +104 -0
  102. package/dist/import-sources.js +629 -0
  103. package/dist/import-summary.d.ts +25 -0
  104. package/dist/import-summary.js +75 -0
  105. package/dist/import-worker.d.ts +26 -0
  106. package/dist/import-worker.js +41 -0
  107. package/dist/import.d.ts +145 -0
  108. package/dist/import.js +1221 -0
  109. package/dist/index.d.ts +7 -0
  110. package/dist/index.js +6 -0
  111. package/dist/key-check.d.ts +36 -0
  112. package/dist/key-check.js +108 -0
  113. package/dist/key-refusal.d.ts +51 -0
  114. package/dist/key-refusal.js +187 -0
  115. package/dist/learn/check.d.ts +99 -0
  116. package/dist/learn/check.js +259 -0
  117. package/dist/learn/grade.d.ts +79 -0
  118. package/dist/learn/grade.js +433 -0
  119. package/dist/learn/index.d.ts +7 -0
  120. package/dist/learn/index.js +11 -0
  121. package/dist/learn/invisible.d.ts +5 -0
  122. package/dist/learn/invisible.js +42 -0
  123. package/dist/learn/notes.d.ts +59 -0
  124. package/dist/learn/notes.js +146 -0
  125. package/dist/learn/reflect.d.ts +49 -0
  126. package/dist/learn/reflect.js +167 -0
  127. package/dist/learn/secrets.d.ts +18 -0
  128. package/dist/learn/secrets.js +111 -0
  129. package/dist/learn/skills.d.ts +84 -0
  130. package/dist/learn/skills.js +198 -0
  131. package/dist/learning-routes.d.ts +196 -0
  132. package/dist/learning-routes.js +609 -0
  133. package/dist/learning-run.d.ts +304 -0
  134. package/dist/learning-run.js +797 -0
  135. package/dist/learning-words.d.ts +73 -0
  136. package/dist/learning-words.js +171 -0
  137. package/dist/learning.d.ts +377 -0
  138. package/dist/learning.js +801 -0
  139. package/dist/llm.d.ts +40 -0
  140. package/dist/llm.js +37 -0
  141. package/dist/llms.txt +37 -0
  142. package/dist/mcp-servers.d.ts +115 -0
  143. package/dist/mcp-servers.js +445 -0
  144. package/dist/mcp.d.ts +51 -0
  145. package/dist/mcp.js +392 -0
  146. package/dist/model.d.ts +184 -0
  147. package/dist/model.js +484 -0
  148. package/dist/monid.d.ts +74 -0
  149. package/dist/monid.js +277 -0
  150. package/dist/openapi/agentrun-v2.openapi.json +4805 -0
  151. package/dist/openapi.d.ts +10 -0
  152. package/dist/openapi.js +1417 -0
  153. package/dist/owner.d.ts +55 -0
  154. package/dist/owner.js +222 -0
  155. package/dist/packs.d.ts +71 -0
  156. package/dist/packs.js +180 -0
  157. package/dist/page.d.ts +32 -0
  158. package/dist/page.js +133 -0
  159. package/dist/paid-calls.d.ts +46 -0
  160. package/dist/paid-calls.js +110 -0
  161. package/dist/pause.d.ts +68 -0
  162. package/dist/pause.js +97 -0
  163. package/dist/pdf-pages.d.ts +44 -0
  164. package/dist/pdf-pages.js +147 -0
  165. package/dist/place.d.ts +46 -0
  166. package/dist/place.js +105 -0
  167. package/dist/print.d.ts +20 -0
  168. package/dist/print.js +29 -0
  169. package/dist/propose.d.ts +38 -0
  170. package/dist/propose.js +82 -0
  171. package/dist/quiet-sqlite-warning.d.ts +1 -0
  172. package/dist/quiet-sqlite-warning.js +14 -0
  173. package/dist/request-start.d.ts +14 -0
  174. package/dist/request-start.js +226 -0
  175. package/dist/result.d.ts +3 -0
  176. package/dist/result.js +5 -0
  177. package/dist/rows.d.ts +46 -0
  178. package/dist/rows.js +121 -0
  179. package/dist/run-box.d.ts +134 -0
  180. package/dist/run-box.js +440 -0
  181. package/dist/run-manifest.d.ts +27 -0
  182. package/dist/run-manifest.js +60 -0
  183. package/dist/runnable.d.ts +80 -0
  184. package/dist/runnable.js +162 -0
  185. package/dist/runs.d.ts +840 -0
  186. package/dist/runs.js +2279 -0
  187. package/dist/secret-cut.d.ts +27 -0
  188. package/dist/secret-cut.js +109 -0
  189. package/dist/secrets.d.ts +50 -0
  190. package/dist/secrets.js +140 -0
  191. package/dist/server-lock.d.ts +44 -0
  192. package/dist/server-lock.js +140 -0
  193. package/dist/server.d.ts +626 -0
  194. package/dist/server.js +1756 -0
  195. package/dist/sessions.d.ts +4 -0
  196. package/dist/sessions.js +105 -0
  197. package/dist/skills.d.ts +31 -0
  198. package/dist/skills.js +68 -0
  199. package/dist/stats.d.ts +101 -0
  200. package/dist/stats.js +82 -0
  201. package/dist/tool-keys.d.ts +151 -0
  202. package/dist/tool-keys.js +273 -0
  203. package/dist/tool-plane.d.ts +143 -0
  204. package/dist/tool-plane.js +242 -0
  205. package/dist/tools.d.ts +147 -0
  206. package/dist/tools.js +253 -0
  207. package/dist/turn-end.d.ts +23 -0
  208. package/dist/turn-end.js +14 -0
  209. package/dist/turns.d.ts +34 -0
  210. package/dist/turns.js +202 -0
  211. package/dist/uploads.d.ts +104 -0
  212. package/dist/uploads.js +474 -0
  213. package/dist/usage.d.ts +29 -0
  214. package/dist/usage.js +58 -0
  215. package/dist/validate.d.ts +55 -0
  216. package/dist/validate.js +175 -0
  217. package/dist/web-fetch.d.ts +64 -0
  218. package/dist/web-fetch.js +262 -0
  219. package/dist/web-search.d.ts +54 -0
  220. package/dist/web-search.js +136 -0
  221. package/dist/webhooks.d.ts +182 -0
  222. package/dist/webhooks.js +487 -0
  223. package/dist/workspace-paths.d.ts +33 -0
  224. package/dist/workspace-paths.js +104 -0
  225. package/dist/workspace.d.ts +88 -0
  226. package/dist/workspace.js +369 -0
  227. package/launcher/agentrun-serve +109 -0
  228. package/package.json +96 -1
  229. package/skills/agentrun-serve/SKILL.md +128 -0
@@ -0,0 +1,73 @@
1
+ import { type Problem, type Verdict } from "./learn/index.js";
2
+ import type { LearnedFile, Learning } from "./learning.js";
3
+ /** `text` on one line, at most `max` characters, cut at a word with an ellipsis when it is longer. */
4
+ export declare function short(text: string, max: number): string;
5
+ /** The most a run's view, its whole learning and its timeline row say of its learning (its detail, cut short once it is
6
+ * cut of the host's secrets), and the most a run list's row says. */
7
+ export declare const DETAIL_MAX = 300;
8
+ export declare const LIST_DETAIL = 140;
9
+ /** The first sentence of `text`, by Unicode's sentence rules (so "e.g." or a URL's dot does not end it), read as one
10
+ * line (a model's line break is no sentence's end), whole; empty for an empty text. */
11
+ export declare function firstSentence(text: string): string;
12
+ /** Why learning stopped, said plainly: the cause inside "Not kept: learning stopped (...)". */
13
+ export declare const STOPPED: {
14
+ readonly noGit: "this server has no git that learning can use, so the run started without its notes";
15
+ readonly unreadable: "the agent's notes could not be read, so the run started without them";
16
+ readonly notCopied: "the agent's notes could not be copied into the run, so the run started without them";
17
+ readonly serverStopped: "the server stopped while it set up the run's notes, so the run started without them";
18
+ readonly cancelled: "the run was cancelled";
19
+ readonly cancelledLooking: "the run was cancelled while it looked back";
20
+ readonly crashed: "the run's process ended before it could look back";
21
+ readonly crashedLooking: "the run's process ended while it looked back";
22
+ readonly timedOut: "looking back took too long";
23
+ readonly notAsked: "looking back could not start";
24
+ readonly failed: "looking back ended on an error";
25
+ readonly notSetAside: "the new notes could not be set aside to be checked";
26
+ readonly notChecked: "the new notes could not be checked";
27
+ readonly screenDown: "the safety check on new notes could not run";
28
+ readonly noReview: "the review of the new notes gave no answer";
29
+ readonly unread: "the review of the new notes gave an answer that could not be read";
30
+ readonly notReviewed: "the new notes could not be reviewed or saved";
31
+ };
32
+ /** A run's learning, in words, by where it stands. */
33
+ export declare const said: {
34
+ seeded: (notes: number) => string;
35
+ reflecting: string;
36
+ /** The end-of-run turn's message, as a person reads it in the timeline: never the prompt the model is sent. */
37
+ asked: string;
38
+ proposed: (notes: number, skills?: number, workflows?: number) => string;
39
+ /** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
40
+ * waits for the owner's OK, by name. A merge that only holds things for the OK says that alone. */
41
+ merged: (learned: readonly {
42
+ name: string;
43
+ supersedes: readonly string[];
44
+ }[], pending?: readonly {
45
+ name: string;
46
+ }[], files?: readonly Pick<LearnedFile, "file" | "name" | "pending">[]) => string;
47
+ empty: string;
48
+ /** The run's answer gave its notes, but not in the format asked for, so none was read. */
49
+ unparsed: string;
50
+ /** The grader's word on why it kept nothing (a dropped note's why, or its reason), its first sentence. */
51
+ grader: (reason: string) => string;
52
+ /** The checks refused what the run wrote, at its end: its notes, or what it learned when a skill or a workflow is
53
+ * among what was refused. */
54
+ checker: (problems: readonly Pick<Problem, "rule" | "path">[]) => string;
55
+ /** The agent's notes as they are now no longer take what the run wrote (another run's or a person's change since). A
56
+ * note it would replace that is gone, or that a person changed after the grade read it, is the rule `supersedes`
57
+ * either way: said in one sentence true of both. */
58
+ stale: (problems: readonly Pick<Problem, "rule">[]) => string;
59
+ noWriteTool: string;
60
+ noBudget: string;
61
+ unknownCost: string;
62
+ screen: string;
63
+ stopped: (cause: string) => string;
64
+ };
65
+ /** Why a verdict kept nothing, in a person's words: the grader's word on the first note it did not keep, since its
66
+ * reason may open on a note it kept; when it dropped none, or gave one no word, its own reason, unless that is
67
+ * parseVerdict's own; an answer that held neither is said as such. */
68
+ export declare function notKept(verdict: Pick<Verdict, "reason" | "items">): string;
69
+ /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, or why the
70
+ * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
71
+ * secrets as they are now); any other detail, the server's own sentence, cut as well. The caller cuts the words short
72
+ * after. */
73
+ export declare function wordsOf(learning: Pick<Learning, "state" | "reason" | "detail" | "learned" | "pending" | "verdict" | "skills" | "workflows">, cut: (text: string) => string): string | null;
@@ -0,0 +1,171 @@
1
+ // What a person reads of a run's learning: every `detail` of Run.learning, which the run's learning row in its timeline
2
+ // shows as its summary too, in one place and in a user's words, a note that waits for the owner's OK included. Never the
3
+ // machine's: no "main", "merged into", "end-of-run turn", "grader's verdict" or "proposal". The reason codes (learning.ts
4
+ // LEARNING_REASONS) stay as they are for machines; only these sentences are for people.
5
+ //
6
+ // Text a model wrote (a note's name, the grader's reason) is never shortened where it is said: a value that becomes a
7
+ // secret later is found only whole, so a part of it kept would show for good. A run's learning keeps the parts its
8
+ // words are made of (`learned`, `verdict`), and each read says them again (wordsOf): every part cut of the host's
9
+ // secrets as they are then, and only then the words cut short (DETAIL_MAX for a run, LIST_DETAIL for a list's row).
10
+ import { CAPS, learnedPlace, parseVerdict } from "./learn/index.js";
11
+ /** `n` of `one`, said as a person says it: "1 note", "2 notes". */
12
+ const count = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
13
+ /** `parts` as a person lists them: "a", "a and b", "a, b and c". */
14
+ const listed = (parts) => (parts.length < 2 ? parts.join("") : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`);
15
+ /** `text` on one line, at most `max` characters, cut at a word with an ellipsis when it is longer. */
16
+ export function short(text, max) {
17
+ const flat = text.replace(/\s+/g, " ").trim();
18
+ if (flat.length <= max)
19
+ return flat;
20
+ const cut = flat.slice(0, max - 1);
21
+ const word = cut.lastIndexOf(" ");
22
+ return `${(word > max / 2 ? cut.slice(0, word) : cut).replace(/[\s,;:.]+$/, "")}…`;
23
+ }
24
+ /** The most a run's view, its whole learning and its timeline row say of its learning (its detail, cut short once it is
25
+ * cut of the host's secrets), and the most a run list's row says. */
26
+ export const DETAIL_MAX = 300;
27
+ export const LIST_DETAIL = 140;
28
+ const SENTENCES = new Intl.Segmenter("en", { granularity: "sentence" });
29
+ /** The first sentence of `text`, by Unicode's sentence rules (so "e.g." or a URL's dot does not end it), read as one
30
+ * line (a model's line break is no sentence's end), whole; empty for an empty text. */
31
+ export function firstSentence(text) {
32
+ return (SENTENCES.segment(text.replace(/\s+/g, " ").trim())[Symbol.iterator]().next().value?.segment ?? "").trim();
33
+ }
34
+ /** A checker's rule, in words. Every rule learn/check.ts' checker has; one it adds later reads as its code. */
35
+ const RULE_WORDS = {
36
+ secret_value: "one of this server's secrets",
37
+ secret_shape: "text that looks like a key or a password",
38
+ invisible_unicode: "a character a reader can't see",
39
+ too_many_files: "too many files changed at once",
40
+ outside: "a file that is not a note",
41
+ file_name: "a file name a note can't have",
42
+ file_mode: "a link or a folder where a note goes",
43
+ encoding: "text that is not UTF-8",
44
+ edited: "a change to a note it had (a new note replaces an old one instead)",
45
+ deleted: "a deleted note",
46
+ exists: "a note under a name already taken",
47
+ too_large: `a note over ${CAPS.note / 1024} KB`,
48
+ too_many_notes: `more than ${CAPS.newNotes} new notes`,
49
+ note: "a note whose header is not in shape",
50
+ status: "a note status that only the server sets",
51
+ supersedes: "a replaced note that isn't there to replace",
52
+ index_full: "too many notes (retire one first)",
53
+ skill: "a skill whose header is not in shape",
54
+ skill_outcome: "a skill from a run that didn't finish its job",
55
+ too_many_skills: `more than ${CAPS.skills} skill at once`,
56
+ workflow: "a workflow that can't run here",
57
+ too_many_workflows: `more than ${CAPS.workflows} workflow at once`,
58
+ no_tool_list: "a workflow whose tools couldn't be checked",
59
+ executable_node: "a workflow that runs code or commands",
60
+ skill_front_matter: "a skill or workflow whose header sets more than its name and description",
61
+ skill_status: "a change to a skill or workflow a person retired or hasn't approved yet",
62
+ };
63
+ /** The rules whose words name a note, said of a skill's or a workflow's file instead. */
64
+ const LEARNED_WORDS = {
65
+ file_name: "a skill or workflow name that can't be used",
66
+ file_mode: "a link or a folder where a skill or workflow goes",
67
+ deleted: "a deleted skill or workflow",
68
+ too_large: `a skill or workflow over ${CAPS.file / 1024} KB`,
69
+ status: "a skill status that only the server sets",
70
+ };
71
+ /** Whether a problem is about a skill or a workflow draft, by its path or its rule. */
72
+ const isLearned = (problem) => (problem.path !== undefined && learnedPlace(problem.path) !== undefined) || /skill|workflow|tool_list|executable/.test(problem.rule);
73
+ const wordOf = (problem) => (isLearned(problem) ? LEARNED_WORDS[problem.rule] : undefined) ?? RULE_WORDS[problem.rule] ?? problem.rule;
74
+ /** What a person must not see stored in a note at all: a secret, or what hides text. */
75
+ const MUST_NOT_STORE = new Set(["secret_value", "secret_shape", "invisible_unicode"]);
76
+ const rulesIn = (problems) => [...new Set(problems.map(wordOf))].join("; ");
77
+ /** Why learning stopped, said plainly: the cause inside "Not kept: learning stopped (...)". */
78
+ export const STOPPED = {
79
+ noGit: "this server has no git that learning can use, so the run started without its notes",
80
+ unreadable: "the agent's notes could not be read, so the run started without them",
81
+ notCopied: "the agent's notes could not be copied into the run, so the run started without them",
82
+ serverStopped: "the server stopped while it set up the run's notes, so the run started without them",
83
+ cancelled: "the run was cancelled",
84
+ cancelledLooking: "the run was cancelled while it looked back",
85
+ crashed: "the run's process ended before it could look back",
86
+ crashedLooking: "the run's process ended while it looked back",
87
+ timedOut: "looking back took too long",
88
+ notAsked: "looking back could not start",
89
+ failed: "looking back ended on an error",
90
+ notSetAside: "the new notes could not be set aside to be checked",
91
+ notChecked: "the new notes could not be checked",
92
+ screenDown: "the safety check on new notes could not run",
93
+ noReview: "the review of the new notes gave no answer",
94
+ unread: "the review of the new notes gave an answer that could not be read",
95
+ notReviewed: "the new notes could not be reviewed or saved",
96
+ };
97
+ /** A run's learning, in words, by where it stands. */
98
+ export const said = {
99
+ seeded: (notes) => (notes === 0 ? "Started with nothing learned yet." : `Started from ${count(notes, "note")}.`),
100
+ reflecting: "Looking back on this run…",
101
+ /** The end-of-run turn's message, as a person reads it in the timeline: never the prompt the model is sent. */
102
+ asked: "Looking back on this run.",
103
+ proposed: (notes, skills = 0, workflows = 0) => `Checking ${listed([...(notes || !(skills || workflows) ? [count(notes, "new note")] : []), ...(skills ? [count(skills, "skill")] : []), ...(workflows ? [count(workflows, "workflow")] : [])])}…`,
104
+ /** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
105
+ * waits for the owner's OK, by name. A merge that only holds things for the OK says that alone. */
106
+ merged: (learned, pending = [], files = []) => {
107
+ const flat = (name) => name.replace(/\s+/g, " ").trim();
108
+ const kind = (file) => `${file.file.startsWith("skills/") ? "skill" : "workflow"} ${flat(file.name)}`;
109
+ const held = [...pending.map((note) => flat(note.name)), ...files.filter((file) => file.pending).map(kind)];
110
+ const waiting = held.length ? `Waiting for your OK: ${held.join("; ")}.` : "";
111
+ const made = files.filter((file) => !file.pending).map(kind);
112
+ if (!learned.length && !made.length)
113
+ return waiting;
114
+ const names = learned.map((note) => flat(note.name));
115
+ const replaced = learned.reduce((n, note) => n + note.supersedes.length, 0);
116
+ const notes = names.length ? `${names.length === 1 ? `Learned: ${names[0]}` : `Learned ${names.length} notes: ${names.join("; ")}`}${replaced ? ` (replaces ${count(replaced, "older note")})` : ""}` : "";
117
+ const kept = [notes, made.length ? `${notes ? "Also learned" : "Learned"} ${listed(made.map((made) => `the ${made}`))}` : ""].filter(Boolean).join(". ");
118
+ return waiting ? `${kept}. ${waiting}` : kept;
119
+ },
120
+ empty: "Nothing new to remember from this run.",
121
+ /** The run's answer gave its notes, but not in the format asked for, so none was read. */
122
+ unparsed: "Not kept: its notes weren't in the expected format.",
123
+ /** The grader's word on why it kept nothing (a dropped note's why, or its reason), its first sentence. */
124
+ grader: (reason) => `Not kept: ${firstSentence(reason) || "it was not judged worth remembering."}`,
125
+ /** The checks refused what the run wrote, at its end: its notes, or what it learned when a skill or a workflow is
126
+ * among what was refused. */
127
+ checker: (problems) => problems.some((problem) => MUST_NOT_STORE.has(problem.rule))
128
+ ? `Not kept: it held something that must not be stored (${rulesIn(problems.filter((problem) => MUST_NOT_STORE.has(problem.rule)))}).`
129
+ : `Not kept: it didn't pass the checks on ${problems.some(isLearned) ? "what it learned" : "notes"} (${rulesIn(problems)}).`,
130
+ /** The agent's notes as they are now no longer take what the run wrote (another run's or a person's change since). A
131
+ * note it would replace that is gone, or that a person changed after the grade read it, is the rule `supersedes`
132
+ * either way: said in one sentence true of both. */
133
+ stale: (problems) => problems.length && problems.every((problem) => problem.rule === "supersedes")
134
+ ? "Not kept: a note it would replace is gone or was changed since."
135
+ : `Not kept: the agent's notes changed while this run ran (${rulesIn(problems)}).`,
136
+ noWriteTool: "Not kept: this agent can't write notes (give it the write tool).",
137
+ noBudget: "Skipped: no budget left in this run to look back.",
138
+ unknownCost: "Skipped: this run's spend is unknown, so its budget can't cover looking back.",
139
+ screen: "Not kept: a new note read like instructions planted in a page, not a lesson.",
140
+ stopped: (cause) => `Not kept: learning stopped (${cause}).`,
141
+ };
142
+ /** The reasons learn/grade.ts' parseVerdict gives of its own, never the grader's: an answer it could not read, and one
143
+ * it refused (an item for a file it was not asked about, a file judged twice, a new note with no item, a merge that
144
+ * did not keep every note). Found by asking it, so they follow it. */
145
+ const OWN_REASONS = new Set(["", "[]", '{"merge":true,"reason":"r","items":[{"file":"a.md","keep":false,"why":"w"}]}', '{"merge":false,"reason":"r","items":[]}', '{"merge":false,"reason":"r","items":[{"file":"b.md","keep":false,"why":"w"}]}', '{"merge":false,"reason":"r","items":[{"file":"a.md","keep":false,"why":"w"},{"file":"a.md","keep":false,"why":"w"}]}'].map((answer) => parseVerdict(answer, ["a.md"]).reason));
146
+ /** Why a verdict kept nothing, in a person's words: the grader's word on the first note it did not keep, since its
147
+ * reason may open on a note it kept; when it dropped none, or gave one no word, its own reason, unless that is
148
+ * parseVerdict's own; an answer that held neither is said as such. */
149
+ export function notKept(verdict) {
150
+ const why = verdict.items.find((item) => !item.keep)?.why;
151
+ if (why)
152
+ return said.grader(why);
153
+ return OWN_REASONS.has(verdict.reason) ? said.stopped(STOPPED.unread) : said.grader(verdict.reason);
154
+ }
155
+ /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, or why the
156
+ * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
157
+ * secrets as they are now); any other detail, the server's own sentence, cut as well. The caller cuts the words short
158
+ * after. */
159
+ export function wordsOf(learning, cut) {
160
+ const { learned, pending, verdict } = learning;
161
+ if (learning.state === "merged") {
162
+ const kept = Array.isArray(learned) ? learned : [];
163
+ const waiting = Array.isArray(pending) ? pending.filter((note) => typeof note?.name === "string") : [];
164
+ const files = [...(Array.isArray(learning.skills) ? learning.skills : []), ...(Array.isArray(learning.workflows) ? learning.workflows : [])].filter((file) => typeof file?.file === "string" && typeof file.name === "string");
165
+ if (kept.length || waiting.length || files.length)
166
+ return said.merged(kept.map((note) => ({ name: cut(note.name), supersedes: note.supersedes })), waiting.map((note) => ({ name: cut(note.name) })), files.map((file) => ({ file: file.file, name: cut(file.name), ...(file.pending ? { pending: true } : {}) })));
167
+ }
168
+ if (learning.state === "dropped" && learning.reason === "grader" && verdict)
169
+ return notKept({ reason: cut(verdict.reason), items: (verdict.items ?? []).map((item) => ({ ...item, why: cut(item.why) })) });
170
+ return learning.detail === null ? null : cut(learning.detail);
171
+ }
@@ -0,0 +1,377 @@
1
+ import { type LearnedNote, type Problem, type Verdict } from "./learn/index.js";
2
+ /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
3
+ * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
4
+ export declare const LEARNING_MODES: readonly ["on", "off"];
5
+ export type LearningMode = (typeof LEARNING_MODES)[number];
6
+ export declare const LEARNING_ENV = "AGENTRUN_SERVE_LEARNING";
7
+ /** The switch: `given`, else AGENTRUN_SERVE_LEARNING, else on. Any other value is an error, and the server does not start. */
8
+ export declare function learningOf(env: NodeJS.ProcessEnv, given?: string): LearningMode;
9
+ /** How much of what a run learned its instructions hold under `# Learned` by default, in UTF-8 bytes (learnedOf): its
10
+ * notes whole while they fit, else the index and the notes changed last, whole, while they fit. */
11
+ export declare const LEARNING_BUDGET = 8000;
12
+ export declare const LEARNING_BUDGET_ENV = "AGENTRUN_SERVE_LEARNING_BUDGET";
13
+ /** The learning budget: `given` (`--learning-budget`), else AGENTRUN_SERVE_LEARNING_BUDGET, else LEARNING_BUDGET. Any
14
+ * value that is not a whole number of bytes, 0 or more, is an error, and the server does not start. */
15
+ export declare function learningBudgetOf(env: NodeJS.ProcessEnv, given?: number): number;
16
+ /** Where a run's learning stands (its `learning`, runs.ts): `seeded` once it starts from what its agent learned,
17
+ * `reflecting` while its end-of-run turn runs and until what it answered is checked, `proposed` once that passed the
18
+ * checks and is kept in the run's directory (propose.ts), `merged` once it is on main (grade.ts), or `dropped` with a
19
+ * reason from the closed list. A learning fault never refuses a run: it starts with nothing learned, `seed_failed`. */
20
+ export declare const LEARNING_STATES: readonly ["seeded", "reflecting", "proposed", "merged", "dropped"];
21
+ export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "no_write_tool", "tool_denied", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "screen", "screen_down", "grader", "grade_failed"];
22
+ /** The reasons only an older server gave (an agent with no write tool, or a tool gate denying it, from before the
23
+ * end-of-run turn answered with its notes): still read, from a run's serve.json and the ledger, and counted; never
24
+ * given now. */
25
+ export declare const LEGACY_LEARNING_REASONS: readonly LearningReason[];
26
+ export type LearningState = (typeof LEARNING_STATES)[number];
27
+ export type LearningReason = (typeof LEARNING_REASONS)[number];
28
+ /** Tokens by the platform's names, as a run's metrics and /v2/stats count them: `input` is the input neither read from
29
+ * nor written to the cache. */
30
+ export type Tokens = {
31
+ input: number;
32
+ cache_read: number;
33
+ cache_write: number;
34
+ output: number;
35
+ };
36
+ export declare const NO_TOKENS: Tokens;
37
+ /** The variable that names the grader's model, as `--grade-model` does. */
38
+ export declare const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
39
+ /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
40
+ * (AGENT_MODEL_STRONG); undefined when it names none, and each run is graded on its agent's own model (grade.ts). A
41
+ * name is a model as the strong tier takes one: sent as it is to a gateway, a provider/model-id otherwise. */
42
+ export declare const gradeModelOf: (env: NodeJS.ProcessEnv, given?: string) => string | undefined;
43
+ /** A note a run read from its copy of the folder (`used`), by its file and its front matter's name. */
44
+ export type NoteUsed = {
45
+ file: string;
46
+ name: string;
47
+ };
48
+ /** A note a run's learning added to the folder (`learned`): its file, its name, and the notes it superseded. */
49
+ export type NoteLearned = NoteUsed & {
50
+ supersedes: string[];
51
+ };
52
+ /** A run's learning as serve.json keeps it. Past the view's four fields: the checker's `problems` (printable), the
53
+ * grader's `verdict` and the blob of each note it read superseded (`graded`, by file), both kept before the merge, the
54
+ * merge commit, and what the grade cost (null when unknown, never 0), which is in no run's totals; the notes the run
55
+ * read from `.learning/` (`used`, found in its rows as it settles), and once merged the notes it added (`learned`);
56
+ * and how many notes it started from (`seed_notes`). Names are kept as written, and cut of the host's secrets as they
57
+ * leave. */
58
+ export type Learning = {
59
+ state: LearningState;
60
+ reason: LearningReason | null;
61
+ detail: string | null;
62
+ at: string;
63
+ problems?: Problem[];
64
+ verdict?: Verdict;
65
+ graded?: Record<string, string>;
66
+ merged?: string;
67
+ cost_usd?: {
68
+ grade: number | null;
69
+ };
70
+ tokens?: {
71
+ grade: Tokens | null;
72
+ };
73
+ used?: NoteUsed[];
74
+ learned?: NoteLearned[];
75
+ /** How many active notes the run started from: its seed's, set as it is seeded (none for a seed that failed). */
76
+ seed_notes?: number;
77
+ /** Once it asked its end-of-run turn: when its job's answer was final (before it looked back), and what the run had
78
+ * cost by then (null when unknown); once that turn ended, what the turn itself cost (null when unknown). */
79
+ answered_at?: string;
80
+ job_cost_usd?: number | null;
81
+ look_back_usd?: number | null;
82
+ /** A merge's notes that wait for a person's OK (`status: pending` on main): in no index, and no run reads them until
83
+ * approved. */
84
+ pending?: {
85
+ file: string;
86
+ name: string;
87
+ }[];
88
+ /** A merge's skill and workflow draft, by name and the path of its SKILL.md or workflow.json; `pending` when it waits
89
+ * for a person's OK (`status: pending` in its SKILL.md or README.md), and no run is given it until approved. */
90
+ skills?: LearnedFile[];
91
+ workflows?: LearnedFile[];
92
+ };
93
+ /** A skill or a workflow draft a merge added or changed. */
94
+ export type LearnedFile = {
95
+ file: string;
96
+ name: string;
97
+ pending?: true;
98
+ };
99
+ /** What a run's learning keeps whatever its learning does after: what it read, how many notes it started from, and its
100
+ * answer's time and its costs (learning-run.ts setLearning). */
101
+ export declare const KEPT_LEARNING: readonly ["used", "seed_notes", "answered_at", "job_cost_usd", "look_back_usd"];
102
+ /** What a text or a name that leaves shows of the host's secrets now: none (secretsShown). */
103
+ export type Shown = {
104
+ text: (text: string) => string;
105
+ name: (name: string) => string;
106
+ holds: (text: string) => boolean;
107
+ };
108
+ /** The host's secrets as a reader cuts them: a text holding a value or a shape is cut of it (whole when long:
109
+ * learn/secrets.ts redactSecrets), and a file's name holding one reads REDACTED whole, not a name of the folder's (its
110
+ * route still answers the real name, to a caller who knows it); any other text or name is shown as it is. */
111
+ export declare function secretsShown(values: readonly string[]): Shown;
112
+ /** The notes a run read and learned, as a view or a list shows them, each name cut of the host's secrets (`shown`):
113
+ * `used` once the run settled, `learned` and `pending` (what waits for the owner's OK) once it merged, and the skill
114
+ * and the workflow draft it merged (`skills`, `workflows`, each `pending` while it waits), each only when it holds one.
115
+ * serve.json's are read as untrusted: an entry out of shape is left out. */
116
+ export declare function notesView({ state, used, learned, pending, skills, workflows }: Learning, shown: Shown, settled: boolean): {
117
+ used?: NoteUsed[];
118
+ learned?: NoteLearned[];
119
+ pending?: NoteUsed[];
120
+ skills?: LearnedFile[];
121
+ workflows?: LearnedFile[];
122
+ };
123
+ /** A run's learning in a person's words as a read shows them (learning-words.ts wordsOf): each part cut of the host's
124
+ * secrets as they are now (`shown`) first, then the words cut short to `max`, so a secret is never shown in part. */
125
+ export declare const detailShown: (learning: Learning, shown: Shown, max?: number) => string | null;
126
+ /** A run's learning as its view shows it: the state, why in a person's words (detailShown), and when, and the notes it
127
+ * read, learned and holds for the owner's OK (notesView). */
128
+ export declare const learningView: (learning: Learning, shown: Shown, settled: boolean) => {
129
+ used?: NoteUsed[];
130
+ learned?: NoteLearned[];
131
+ pending?: NoteUsed[];
132
+ skills?: LearnedFile[];
133
+ workflows?: LearnedFile[];
134
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
135
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
136
+ detail: string | null;
137
+ at: string;
138
+ };
139
+ /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
140
+ * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
141
+ * (notesView); never its time. */
142
+ export declare const shortLearning: (learning: Learning | null, shown: Shown, settled: boolean) => ({
143
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
144
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
145
+ detail: string | null;
146
+ } & Omit<{
147
+ used?: NoteUsed[];
148
+ learned?: NoteLearned[];
149
+ pending?: NoteUsed[];
150
+ skills?: LearnedFile[];
151
+ workflows?: LearnedFile[];
152
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
153
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
154
+ detail: string | null;
155
+ at: string;
156
+ }, "at" | "reason" | "state" | "detail">) | null;
157
+ /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
158
+ export declare function shortOf<T extends {
159
+ state: LearningState;
160
+ reason: LearningReason | null;
161
+ detail: string | null;
162
+ at: string;
163
+ }>({ state, reason, detail, at: _, ...notes }: T): {
164
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
165
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
166
+ detail: string | null;
167
+ } & Omit<T, "at" | "reason" | "state" | "detail">;
168
+ /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
169
+ export declare const LEARNING_LABEL = "learning";
170
+ /** A run's proposal, in its directory (propose.ts): the seed it was checked against, each new note's file and text, its
171
+ * skill's and workflow draft's files by path and text (`files`: a SKILL.md, a workflow.json and its README.md; absent
172
+ * when it gives none), and what the user said in the run as the grader reads it (each message cut of the host's
173
+ * secrets, then shortened to GRADE_CAPS.askedMessage; absent in a proposal kept before the grader read them). */
174
+ export declare const PROPOSAL = "learning-proposal.json";
175
+ export type Proposal = {
176
+ seed: string;
177
+ notes: {
178
+ file: string;
179
+ text: string;
180
+ }[];
181
+ files?: {
182
+ file: string;
183
+ text: string;
184
+ }[];
185
+ asked?: string[];
186
+ };
187
+ /** A run's pin, in its directory: written once, when the run is made, and never changed by a resume. */
188
+ export declare const LEARNING_PIN = "learning.json";
189
+ /** Where a run finds its agent's notes: in its work, a copy the run may read and nothing reads back. */
190
+ export declare const LEARNED_DIR = ".learning";
191
+ /** What the run's end-of-run turn answered, and what the user said in the run, kept in the run's directory as the run
192
+ * settles (learning-run.ts beforeSettle), where the host alone reads it: what propose.ts checks. */
193
+ export declare const LEARNING_TURN = "learning-turn.json";
194
+ export type Turn = {
195
+ answer: string;
196
+ asked: string[];
197
+ };
198
+ /** What a run's pin holds: the commit of main it was seeded from, and what it reads under `# Learned` (learnedOf), when
199
+ * it learned anything. `learned`, the index alone, is a pin an earlier server wrote, read as that server gave it.
200
+ * `skills`: the files of the learned skills laid in its work, by their paths under `.agents/skills/`, as a revision
201
+ * names its own; `skills_left_out`: the learned skills it does not get, over their budget or holding a secret. */
202
+ export type Pin = {
203
+ seed: string;
204
+ section?: string;
205
+ learned?: string;
206
+ skills?: string[];
207
+ skills_left_out?: string[];
208
+ };
209
+ /** What a run is seeded from: main's commit, its index and its active notes by file, and the name of every entry at its
210
+ * top. `skipped` names what was there and not read. `recent`, when seedOf read it: the active notes' files, the one
211
+ * changed last on main first. `skills`, when seedOf read them: the skills the agent wrote, the one changed last on main
212
+ * first. */
213
+ export type Seed = {
214
+ sha: string;
215
+ index?: string;
216
+ notes: Record<string, string>;
217
+ files: string[];
218
+ skipped: string[];
219
+ recent?: string[];
220
+ skills?: LearnedSkill[];
221
+ };
222
+ /** The most bytes of learned skills one run gets, every file of each together. They get no more than what the
223
+ * revision's own skills leave of the adapters' cap on a run's skills in all (SKILL_BYTES): over that cap an adapter
224
+ * refuses the whole set, and every skill, the revision's too, would be inlined in the prompt (skills.ts splitSkills). */
225
+ export declare const LEARNED_SKILLS_BUDGET: number;
226
+ /** A skill the agent wrote, as a seed holds it: its name, its files' bytes together, and each file's text by its path
227
+ * inside the skill, read only when the skill could fit a run's budget at all. */
228
+ export type LearnedSkill = {
229
+ name: string;
230
+ bytes: number;
231
+ files?: Record<string, string>;
232
+ };
233
+ /** The agent's learning folder: its home's `learning/` entry, which only the host writes. The home is files.ts homeOf,
234
+ * the one definition the home's routes use too, so two ids that differ only in case never share a folder. */
235
+ export declare const learningRepo: (data: string, agentId: string) => string;
236
+ /** The agent's learning folder, its home and the folder made where absent (checkedFolder). A link swapped in for a part
237
+ * just made is caught by the check after. `<data>/homes` is the operator's, as the data directory is. Every write into
238
+ * the folder goes through it, in the agent's queue: before anything reads or makes the repository, and again once
239
+ * `git init` has made `.git`; before a run's end-of-run turn reads its seed again (seedAt), before its proposal is
240
+ * checked against it (propose.ts), before its grade reads main and its merge writes it (grade.ts), and before a
241
+ * person's edit, create or retire (learning-routes.ts). A refusal throws: a run about to start starts with nothing
242
+ * learned (seed_failed), a run that ended drops what it learned (reflect_failed, propose_failed or grade_failed), and
243
+ * a person's write is an error. */
244
+ export declare const agentFolder: (data: string, agentId: string) => Promise<string>;
245
+ /** The agent's learning folder for a person's read, outside the queue: the same check as agentFolder's, and nothing
246
+ * made. A link or a non-directory throws as it does there; a missing level passes, so a folder never made reads as
247
+ * empty (mainOf finds no main). */
248
+ export declare const readFolder: (data: string, agentId: string) => Promise<string>;
249
+ /** One git call on `repo` (none for `init`), from `cwd`: its stdout, or a rejection naming the command and its stderr.
250
+ * `env` adds to the call's environment (a temporary index, a work tree named outright). */
251
+ export declare function git(cwd: string, repo: string | undefined, args: readonly string[], input?: string | Uint8Array, env?: NodeJS.ProcessEnv): Promise<Buffer>;
252
+ export declare const line: (out: Buffer) => string;
253
+ /** Why this host keeps no learning folder, or undefined when it can: git MIN_GIT or later on `env`'s PATH. */
254
+ export declare function learningBlocker(env?: NodeJS.ProcessEnv): Promise<string | undefined>;
255
+ /** Runs `work` once every call queued before it on the agent's folder has finished: one at a time per agent, in this
256
+ * process. Everything that touches an agent's folder goes through it, so two runs made at once never both make it. */
257
+ export declare const withAgentRepo: <T>(data: string, agentId: string, work: () => Promise<T>) => Promise<T>;
258
+ /** Runs `work` after every grade of the agent's runs queued before it (grade.ts): one grade at a time per agent, each
259
+ * against main as the one before left it. Its own queue, so a grade's model call never holds a run's seed. */
260
+ export declare const withAgentGrade: <T>(data: string, agentId: string, work: () => Promise<T>) => Promise<T>;
261
+ /** Main's commit, or undefined when there is no main yet: no repository, one whose `init` never finished, or one whose
262
+ * making stopped before main. A main that is there, by its ref, and names no commit git can read is an error: the
263
+ * repository is never made again over it. */
264
+ export declare function mainOf(cwd: string, repo: string): Promise<string | undefined>;
265
+ /** Makes the agent's folder, or finishes one whose making stopped before main: `init` with no template, then the host's
266
+ * one commit on main, holding an empty `MEMORY.md` alone, made with plumbing. The working tree and the index show that
267
+ * commit's tree first (written here, never checked out; a `MEMORY.md` that is a link is refused, never written
268
+ * through), and main is created last, only where it is not there yet: a making that stops anywhere before leaves no
269
+ * main, and the next one does it all again. Called in the queue, on the folder agentFolder made and checked; `check`
270
+ * checks it again once `.git` is made. */
271
+ export declare function openAgentRepo(cwd: string, repo: string, check: () => Promise<unknown>): Promise<string>;
272
+ /** Brings the folder's checked-out files in line with commit `sha` of main: host-only files, so no hook or filter runs,
273
+ * with the work tree named outright, the folder itself. Why it could not, when it could not. In the queue, on the
274
+ * folder agentFolder checked. */
275
+ export declare const checkOut: (repo: string, sha: string) => Promise<Error | undefined>;
276
+ /** The blobs `oids` hold, in order, read in one `cat-file --batch`. One git cannot read throws. */
277
+ export declare function readBlobs(cwd: string, repo: string, oids: readonly string[]): Promise<Buffer[]>;
278
+ /** What commit `sha` holds for a run, read with plumbing: its index and its active notes, the `.md` files at its top.
279
+ * Only a regular file (mode 100644) under FILE_CAP, in UTF-8, is read, and only a note in shape (learn/notes.ts
280
+ * parseNoteFile); anything else is named in `skipped`. Only an active note is a run's: a pending, superseded or retired
281
+ * one is not, and nothing serves it (learnedOf, layLearned). A read git fails (an
282
+ * object missing, a timeout) throws. */
283
+ export declare function readSeed(cwd: string, repo: string, sha: string): Promise<Seed>;
284
+ /** The skills commit `sha` holds under SKILLS_DIR, read with plumbing, by name. A skill is read when its folder's
285
+ * name and each of its files' paths are in shape, it holds a SKILL.md, and each file is a regular one (mode 100644) in
286
+ * UTF-8; else it is named in `skipped`. Only an active skill is a run's, one whose SKILL.md sets no status (or
287
+ * `active`): one held for its owner's OK (`status: pending`), or with any other status, is left out as a note that is
288
+ * not active is (readSeed). One over LEARNED_SKILLS_BUDGET, which no run could get, is held with its bytes and none of
289
+ * its files. A symbolic link or a submodule at SKILLS_DIR or anywhere under it throws, as a read
290
+ * git fails does: the run starts with nothing learned, and no link is ever laid in its work or followed. */
291
+ export declare function readSkills(cwd: string, repo: string, sha: string): Promise<{
292
+ skills: LearnedSkill[];
293
+ skipped: string[];
294
+ }>;
295
+ /** Each file's place in main's first-parent log from `sha`, by the newest commit that changed it: 0 for those the newest
296
+ * commit changed, and so on, so two changes in one second keep their order. A run's notes (seedOf) and a person's view
297
+ * of them (learning-routes.ts) are in this order, the one changed last first. */
298
+ export declare function changedOrder(cwd: string, repo: string, sha: string): Promise<Map<string, number>>;
299
+ /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent, and
300
+ * what that commit holds, its active notes in the order they changed on main, the one changed last first (then by
301
+ * name). In the agent's queue. */
302
+ export declare function seedOf(data: string, agentId: string): Promise<Seed>;
303
+ /** The skills the agent wrote at commit `sha` (readSkills): what a run's pin names, laid again. In the agent's queue,
304
+ * through agentFolder. */
305
+ export declare const skillsAt: (data: string, agentId: string, sha: string) => Promise<LearnedSkill[]>;
306
+ /** What commit `sha` of the agent's folder holds for a run, as seedOf reads main: a run's seed, read again. In the
307
+ * agent's queue, through agentFolder. */
308
+ export declare const seedAt: (data: string, agentId: string, sha: string) => Promise<Seed>;
309
+ /** The active notes of a seed, parsed. */
310
+ export declare const activeOf: (seed: Pick<Seed, "notes">) => LearnedNote[];
311
+ /** Test seams, tests only: once a part of an agent's learning folder is made (before its check), before a run's
312
+ * learned files are written, once its pin is in place, before what its end-of-run turn wrote is checked, as a run that
313
+ * learns opens again for a follow-up, and as each git call starts (its arguments). */
314
+ export declare const learningTestHooks: {
315
+ git?: (args: readonly string[]) => void;
316
+ afterMkdir?: (dir: string) => Promise<void> | void;
317
+ beforePin?: (runDir: string) => Promise<void> | void;
318
+ afterPin?: (runDir: string) => Promise<void> | void;
319
+ beforePropose?: (runDir: string) => Promise<void> | void;
320
+ beforeReopen?: (runDir: string) => Promise<void> | void;
321
+ };
322
+ /** As the run in `runDir` settles after its end-of-run turn ended, before it reads ended and before a follow-up can
323
+ * open it again: what the turn answered and what the user said, kept whole in `<run dir>/learning-turn.json`, so
324
+ * nothing the run does after its end reaches what is checked. One already there stays (a server that went after it
325
+ * was written). Throws when the write fails. */
326
+ export declare function keepTurn(runDir: string, turn: Turn): Promise<void>;
327
+ /** The turn a run's directory keeps (keepTurn). One that is not there, or out of shape, throws. */
328
+ export declare function readTurn(runDir: string): Promise<Turn>;
329
+ /** Lays `seed`'s index and active notes in `dir`, made fresh: whatever was there goes. The index names the active notes
330
+ * alone (servedIndex), and each file is cut of the host's secrets (`shown`), the index a line at a time. */
331
+ export declare function layLearned(dir: string, seed: Seed, shown: Shown): Promise<void>;
332
+ /** How a run reads what it learned (learnedOf): the server's learning budget, in bytes; whether its agent has the read
333
+ * tool; the host's secrets, which every text is cut of. */
334
+ export type LearnedOptions = {
335
+ budget: number;
336
+ read: boolean;
337
+ shown: Shown;
338
+ };
339
+ /** What a run of `seed` reads under `# Learned`, the same for every harness, or undefined when it learned nothing. Only
340
+ * active notes are served: a pending, superseded or retired one is never there, whole or in the index, nor counted
341
+ * toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its active notes, newest
342
+ * first (`seed.recent`, else by name): each whole while all fit `budget`, the UTF-8 bytes of
343
+ * what follows the first paragraph. Past it, or when the index names a note main does not hold whole: the index as a
344
+ * run loads it (learn/notes.ts loadedIndex, the first 200 lines and no more than 25 KB, past the budget when it is
345
+ * larger), then the newest notes that fit what is left, each whole, and the rest named only in the index; an agent
346
+ * with the read tool is told they are in `.learning/`, one without is not. Every text is cut of the host's secrets. */
347
+ export declare function learnedOf(seed: Seed, options: LearnedOptions): string | undefined;
348
+ /** Writes `seed` into the run just made in `runDir`: the index and each active note into `work/.learning/`, made fresh
349
+ * (whatever was there goes), then the pin, with what the run reads under `# Learned` (learnedOf) and the learned
350
+ * skills it gets beside the revision's `own` skill files (chooseSkills), then those skills, last, into
351
+ * `work/.agents/skills/`. A write that fails leaves no `.learning/`, no learned skill and no pin, and throws. */
352
+ export declare function pinSeed(runDir: string, work: string, seed: Seed, options: LearnedOptions & {
353
+ own?: readonly string[];
354
+ }): Promise<Pin>;
355
+ /** Lays the learned skills a reopened run's pin names (`pin.skills`) again, fresh, from `read` (the skills of its seed's
356
+ * commit: skillsAt): what the run wrote over them, or took away, is not what it learned. Each only with the files the
357
+ * pin names. Throws when it cannot, a link on the way among the reasons. */
358
+ export declare function layPinnedSkills(work: string, pin: Pin, read: () => Promise<LearnedSkill[]>): Promise<void>;
359
+ /** Takes back a seed whose copy a server went down during (runs.ts load): the learned skills its pin names, the pin,
360
+ * then its `work/.learning/`. True when the pin or the copy was there. */
361
+ export declare function dropSeed(runDir: string, work: string): Promise<boolean>;
362
+ /** The run's pin, as its process reads it: undefined when the run has none (its agent does not learn, its seed failed, a
363
+ * workflow's run). A pin out of shape is an error, never read as none. */
364
+ export declare function readPin(runDir: string): Promise<Pin | undefined>;
365
+ /** The heading of what a run learned, in its instructions. */
366
+ export declare const LEARNED_HEADING = "# Learned";
367
+ /** A run's instructions, with `# Learned` after them when its pin in `runDir` says it learns: that it learns, then what
368
+ * the pin says it learned, or that it has learned nothing yet. A run with no pin (its agent does not learn, its seed
369
+ * failed, a workflow's run) is never asked what to keep, so it is told nothing. And its skill files: the revision's
370
+ * `own`, then the learned ones its pin names, by their paths under `.agents/skills/` in `work`, but for a skill named
371
+ * like one of the revision's, which is the revision's. A learned skill the work no longer holds whole, as a harness reads
372
+ * it (no link on the way: workspace.ts), is left out: a learning fault never fails a run. The one path for every harness
373
+ * (app.ts): pi's system prompt, claude-agent's and codex's instructions, and the skills each gets. */
374
+ export declare function withLearned(runDir: string, work: string, instructions: string, own?: readonly string[]): Promise<{
375
+ instructions: string;
376
+ skills: string[];
377
+ }>;