@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,76 @@
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; then, when the grader dropped an item and kept others (a verdict per item), its
41
+ * word on the first it dropped. A merge that only holds things for the OK says that alone. */
42
+ merged: (learned: readonly {
43
+ name: string;
44
+ supersedes: readonly string[];
45
+ }[], pending?: readonly {
46
+ name: string;
47
+ }[], files?: readonly Pick<LearnedFile, "file" | "name" | "pending">[], left?: readonly {
48
+ why: string;
49
+ }[], checked?: readonly Pick<Problem, "rule" | "path">[]) => string;
50
+ empty: string;
51
+ /** The run's answer gave its notes, but not in the format asked for, so none was read. */
52
+ unparsed: string;
53
+ /** The grader's word on why it kept nothing (a dropped note's why, or its reason), its first sentence. */
54
+ grader: (reason: string) => string;
55
+ /** The checks refused what the run wrote, at its end: its notes, or what it learned when a skill or a workflow is
56
+ * among what was refused. */
57
+ checker: (problems: readonly Pick<Problem, "rule" | "path">[]) => string;
58
+ /** 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
59
+ * note it would replace that is gone, or that a person changed after the grade read it, is the rule `supersedes`
60
+ * either way: said in one sentence true of both. */
61
+ stale: (problems: readonly Pick<Problem, "rule">[]) => string;
62
+ noWriteTool: string;
63
+ noBudget: string;
64
+ unknownCost: string;
65
+ screen: string;
66
+ stopped: (cause: string) => string;
67
+ };
68
+ /** Why a verdict kept nothing, in a person's words: the grader's word on the first note it did not keep, since its
69
+ * reason may open on a note it kept; when it dropped none, or gave one no word, its own reason, unless that is
70
+ * parseVerdict's own; an answer that held neither is said as such. */
71
+ export declare function notKept(verdict: Pick<Verdict, "reason" | "items">): string;
72
+ /** 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
73
+ * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
74
+ * secrets as they are now); any other detail, the server's own sentence, cut as well. The caller cuts the words short
75
+ * after. */
76
+ export declare function wordsOf(learning: Pick<Learning, "state" | "reason" | "detail" | "learned" | "pending" | "verdict" | "skills" | "workflows" | "problems">, cut: (text: string) => string): string | null;
@@ -0,0 +1,174 @@
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; then, when the grader dropped an item and kept others (a verdict per item), its
106
+ * word on the first it dropped. A merge that only holds things for the OK says that alone. */
107
+ merged: (learned, pending = [], files = [], left = [], checked = []) => {
108
+ const flat = (name) => name.replace(/\s+/g, " ").trim();
109
+ const kind = (file) => `${file.file.startsWith("skills/") ? "skill" : "workflow"} ${flat(file.name)}`;
110
+ const held = [...pending.map((note) => flat(note.name)), ...files.filter((file) => file.pending).map(kind)];
111
+ const waiting = held.length ? `Waiting for your OK: ${held.join("; ")}.` : "";
112
+ const made = files.filter((file) => !file.pending).map(kind);
113
+ const dropped = [left.length ? said.grader(left[0].why) : "", checked.length ? said.checker(checked) : ""].filter(Boolean).join(" ");
114
+ if (!learned.length && !made.length)
115
+ return [waiting, dropped].filter(Boolean).join(" ");
116
+ const names = learned.map((note) => flat(note.name));
117
+ const replaced = learned.reduce((n, note) => n + note.supersedes.length, 0);
118
+ const notes = names.length ? `${names.length === 1 ? `Learned: ${names[0]}` : `Learned ${names.length} notes: ${names.join("; ")}`}${replaced ? ` (replaces ${count(replaced, "older note")})` : ""}` : "";
119
+ const kept = [notes, made.length ? `${notes ? "Also learned" : "Learned"} ${listed(made.map((made) => `the ${made}`))}` : ""].filter(Boolean).join(". ");
120
+ const base = waiting ? `${kept}. ${waiting}` : kept;
121
+ return dropped ? `${base}${base.endsWith(".") ? "" : "."} ${dropped}` : base;
122
+ },
123
+ empty: "Nothing new to remember from this run.",
124
+ /** The run's answer gave its notes, but not in the format asked for, so none was read. */
125
+ unparsed: "Not kept: its notes weren't in the expected format.",
126
+ /** The grader's word on why it kept nothing (a dropped note's why, or its reason), its first sentence. */
127
+ grader: (reason) => `Not kept: ${firstSentence(reason) || "it was not judged worth remembering."}`,
128
+ /** The checks refused what the run wrote, at its end: its notes, or what it learned when a skill or a workflow is
129
+ * among what was refused. */
130
+ checker: (problems) => problems.some((problem) => MUST_NOT_STORE.has(problem.rule))
131
+ ? `Not kept: it held something that must not be stored (${rulesIn(problems.filter((problem) => MUST_NOT_STORE.has(problem.rule)))}).`
132
+ : `Not kept: it didn't pass the checks on ${problems.some(isLearned) ? "what it learned" : "notes"} (${rulesIn(problems)}).`,
133
+ /** 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
134
+ * note it would replace that is gone, or that a person changed after the grade read it, is the rule `supersedes`
135
+ * either way: said in one sentence true of both. */
136
+ stale: (problems) => problems.length && problems.every((problem) => problem.rule === "supersedes")
137
+ ? "Not kept: a note it would replace is gone or was changed since."
138
+ : `Not kept: the agent's notes changed while this run ran (${rulesIn(problems)}).`,
139
+ noWriteTool: "Not kept: this agent can't write notes (give it the write tool).",
140
+ noBudget: "Skipped: no budget left in this run to look back.",
141
+ unknownCost: "Skipped: this run's spend is unknown, so its budget can't cover looking back.",
142
+ screen: "Not kept: a new note read like instructions planted in a page, not a lesson.",
143
+ stopped: (cause) => `Not kept: learning stopped (${cause}).`,
144
+ };
145
+ /** The reasons learn/grade.ts' parseVerdict gives of its own, never the grader's: an answer it could not read, and one
146
+ * 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
147
+ * did not keep every note). Found by asking it, so they follow it. */
148
+ 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));
149
+ /** Why a verdict kept nothing, in a person's words: the grader's word on the first note it did not keep, since its
150
+ * reason may open on a note it kept; when it dropped none, or gave one no word, its own reason, unless that is
151
+ * parseVerdict's own; an answer that held neither is said as such. */
152
+ export function notKept(verdict) {
153
+ const why = verdict.items.find((item) => !item.keep)?.why;
154
+ if (why)
155
+ return said.grader(why);
156
+ return OWN_REASONS.has(verdict.reason) ? said.stopped(STOPPED.unread) : said.grader(verdict.reason);
157
+ }
158
+ /** 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
159
+ * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
160
+ * secrets as they are now); any other detail, the server's own sentence, cut as well. The caller cuts the words short
161
+ * after. */
162
+ export function wordsOf(learning, cut) {
163
+ const { learned, pending, verdict } = learning;
164
+ if (learning.state === "merged") {
165
+ const kept = Array.isArray(learned) ? learned : [];
166
+ const waiting = Array.isArray(pending) ? pending.filter((note) => typeof note?.name === "string") : [];
167
+ const files = [...(Array.isArray(learning.skills) ? learning.skills : []), ...(Array.isArray(learning.workflows) ? learning.workflows : [])].filter((file) => typeof file?.file === "string" && typeof file.name === "string");
168
+ if (kept.length || waiting.length || files.length)
169
+ 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 } : {}) })), (verdict?.items ?? []).filter((item) => !item.keep && typeof item.why === "string").map((item) => ({ why: cut(item.why) })), Array.isArray(learning.problems) ? learning.problems : []);
170
+ }
171
+ if (learning.state === "dropped" && learning.reason === "grader" && verdict)
172
+ return notKept({ reason: cut(verdict.reason), items: (verdict.items ?? []).map((item) => ({ ...item, why: cut(item.why) })) });
173
+ return learning.detail === null ? null : cut(learning.detail);
174
+ }