@skillcdn/console 0.5.0 → 0.5.1

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 (345) hide show
  1. package/README.md +68 -11
  2. package/SKILLCDN.md +3 -3
  3. package/dist/agent-page.d.ts.map +1 -1
  4. package/dist/agent-page.js +3 -2
  5. package/dist/agent-page.js.map +1 -1
  6. package/dist/api.d.ts +7 -6
  7. package/dist/api.d.ts.map +1 -1
  8. package/dist/api.js +6 -5
  9. package/dist/api.js.map +1 -1
  10. package/dist/charts.d.ts +103 -0
  11. package/dist/charts.d.ts.map +1 -0
  12. package/dist/charts.js +182 -0
  13. package/dist/charts.js.map +1 -0
  14. package/dist/cli/cli.d.ts +26 -2
  15. package/dist/cli/cli.d.ts.map +1 -1
  16. package/dist/cli/cli.js +1304 -383
  17. package/dist/cli/cli.js.map +1 -1
  18. package/dist/cli/command-words.d.ts +20 -0
  19. package/dist/cli/command-words.d.ts.map +1 -0
  20. package/dist/cli/command-words.js +51 -0
  21. package/dist/cli/command-words.js.map +1 -0
  22. package/dist/cli/credentials.d.ts +54 -5
  23. package/dist/cli/credentials.d.ts.map +1 -1
  24. package/dist/cli/credentials.js +126 -20
  25. package/dist/cli/credentials.js.map +1 -1
  26. package/dist/cli/directory.d.ts +19 -4
  27. package/dist/cli/directory.d.ts.map +1 -1
  28. package/dist/cli/directory.js +16 -8
  29. package/dist/cli/directory.js.map +1 -1
  30. package/dist/cli/format.d.ts +65 -8
  31. package/dist/cli/format.d.ts.map +1 -1
  32. package/dist/cli/format.js +242 -37
  33. package/dist/cli/format.js.map +1 -1
  34. package/dist/cli/help.d.ts +13 -4
  35. package/dist/cli/help.d.ts.map +1 -1
  36. package/dist/cli/help.js +92 -54
  37. package/dist/cli/help.js.map +1 -1
  38. package/dist/cli/main.js +76 -2
  39. package/dist/cli/main.js.map +1 -1
  40. package/dist/cli/pack.d.ts +69 -60
  41. package/dist/cli/pack.d.ts.map +1 -1
  42. package/dist/cli/pack.js +241 -270
  43. package/dist/cli/pack.js.map +1 -1
  44. package/dist/cli/plugin-check.d.ts +42 -0
  45. package/dist/cli/plugin-check.d.ts.map +1 -1
  46. package/dist/cli/plugin-check.js +221 -36
  47. package/dist/cli/plugin-check.js.map +1 -1
  48. package/dist/cli/plugin-cli.d.ts +6 -1
  49. package/dist/cli/plugin-cli.d.ts.map +1 -1
  50. package/dist/cli/plugin-cli.js +21 -4
  51. package/dist/cli/plugin-cli.js.map +1 -1
  52. package/dist/cli/plugin-main.js +1 -0
  53. package/dist/cli/plugin-main.js.map +1 -1
  54. package/dist/cli/serve.d.ts +33 -1
  55. package/dist/cli/serve.d.ts.map +1 -1
  56. package/dist/cli/serve.js +252 -3
  57. package/dist/cli/serve.js.map +1 -1
  58. package/dist/client.d.ts +48 -9
  59. package/dist/client.d.ts.map +1 -1
  60. package/dist/client.js +72 -80
  61. package/dist/client.js.map +1 -1
  62. package/dist/components/agent-page.d.ts +64 -1
  63. package/dist/components/agent-page.d.ts.map +1 -1
  64. package/dist/components/agent-page.js +244 -96
  65. package/dist/components/agent-page.js.map +1 -1
  66. package/dist/components/charts.d.ts +157 -0
  67. package/dist/components/charts.d.ts.map +1 -0
  68. package/dist/components/charts.js +182 -0
  69. package/dist/components/charts.js.map +1 -0
  70. package/dist/components/desk-records.d.ts +102 -0
  71. package/dist/components/desk-records.d.ts.map +1 -0
  72. package/dist/components/desk-records.js +221 -0
  73. package/dist/components/desk-records.js.map +1 -0
  74. package/dist/components/desk.d.ts +85 -0
  75. package/dist/components/desk.d.ts.map +1 -0
  76. package/dist/components/desk.js +135 -0
  77. package/dist/components/desk.js.map +1 -0
  78. package/dist/components/event-feed.d.ts.map +1 -1
  79. package/dist/components/event-feed.js +4 -1
  80. package/dist/components/event-feed.js.map +1 -1
  81. package/dist/components/home.d.ts.map +1 -1
  82. package/dist/components/home.js +4 -2
  83. package/dist/components/home.js.map +1 -1
  84. package/dist/components/plugin-settings.d.ts.map +1 -1
  85. package/dist/components/plugin-settings.js +54 -3
  86. package/dist/components/plugin-settings.js.map +1 -1
  87. package/dist/components/projects.d.ts.map +1 -1
  88. package/dist/components/projects.js +27 -7
  89. package/dist/components/projects.js.map +1 -1
  90. package/dist/components/rules.d.ts +8 -10
  91. package/dist/components/rules.d.ts.map +1 -1
  92. package/dist/components/rules.js +35 -13
  93. package/dist/components/rules.js.map +1 -1
  94. package/dist/components/setup.d.ts +9 -3
  95. package/dist/components/setup.d.ts.map +1 -1
  96. package/dist/components/setup.js +10 -4
  97. package/dist/components/setup.js.map +1 -1
  98. package/dist/console.css +677 -7
  99. package/dist/console.d.ts +5 -0
  100. package/dist/console.d.ts.map +1 -1
  101. package/dist/console.js +14 -8
  102. package/dist/console.js.map +1 -1
  103. package/dist/data.d.ts.map +1 -1
  104. package/dist/data.js +32 -33
  105. package/dist/data.js.map +1 -1
  106. package/dist/desk-page.d.ts +38 -0
  107. package/dist/desk-page.d.ts.map +1 -0
  108. package/dist/desk-page.js +184 -0
  109. package/dist/desk-page.js.map +1 -0
  110. package/dist/desk-records-page.d.ts +18 -0
  111. package/dist/desk-records-page.d.ts.map +1 -0
  112. package/dist/desk-records-page.js +130 -0
  113. package/dist/desk-records-page.js.map +1 -0
  114. package/dist/desk-records.d.ts +247 -0
  115. package/dist/desk-records.d.ts.map +1 -0
  116. package/dist/desk-records.js +543 -0
  117. package/dist/desk-records.js.map +1 -0
  118. package/dist/desk.d.ts +122 -0
  119. package/dist/desk.d.ts.map +1 -0
  120. package/dist/desk.js +211 -0
  121. package/dist/desk.js.map +1 -0
  122. package/dist/feed-stream.d.ts +39 -0
  123. package/dist/feed-stream.d.ts.map +1 -0
  124. package/dist/feed-stream.js +117 -0
  125. package/dist/feed-stream.js.map +1 -0
  126. package/dist/home-tiles.d.ts +10 -3
  127. package/dist/home-tiles.d.ts.map +1 -1
  128. package/dist/home-tiles.js +54 -31
  129. package/dist/home-tiles.js.map +1 -1
  130. package/dist/i18n/en.d.ts +180 -5
  131. package/dist/i18n/en.d.ts.map +1 -1
  132. package/dist/i18n/en.js +184 -7
  133. package/dist/i18n/en.js.map +1 -1
  134. package/dist/i18n/ko.d.ts.map +1 -1
  135. package/dist/i18n/ko.js +169 -6
  136. package/dist/i18n/ko.js.map +1 -1
  137. package/dist/index.d.ts +8 -0
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +8 -0
  140. package/dist/index.js.map +1 -1
  141. package/dist/limits.d.ts +11 -0
  142. package/dist/limits.d.ts.map +1 -1
  143. package/dist/limits.js +11 -0
  144. package/dist/limits.js.map +1 -1
  145. package/dist/onboarding.d.ts +6 -0
  146. package/dist/onboarding.d.ts.map +1 -1
  147. package/dist/onboarding.js +3 -3
  148. package/dist/onboarding.js.map +1 -1
  149. package/dist/plugin/context.d.ts +42 -11
  150. package/dist/plugin/context.d.ts.map +1 -1
  151. package/dist/plugin/limits.d.ts +2 -0
  152. package/dist/plugin/limits.d.ts.map +1 -1
  153. package/dist/plugin/limits.js +2 -0
  154. package/dist/plugin/limits.js.map +1 -1
  155. package/dist/plugin/manifest.d.ts +13 -0
  156. package/dist/plugin/manifest.d.ts.map +1 -1
  157. package/dist/plugin/manifest.js +30 -3
  158. package/dist/plugin/manifest.js.map +1 -1
  159. package/dist/plugin/rest-schemas.d.ts +55 -0
  160. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  161. package/dist/plugin/rest-schemas.js +37 -0
  162. package/dist/plugin/rest-schemas.js.map +1 -1
  163. package/dist/plugin/sandbox.d.ts.map +1 -1
  164. package/dist/plugin/sandbox.js +4 -1
  165. package/dist/plugin/sandbox.js.map +1 -1
  166. package/dist/plugin/testing.d.ts +6 -2
  167. package/dist/plugin/testing.d.ts.map +1 -1
  168. package/dist/plugin/testing.js +52 -10
  169. package/dist/plugin/testing.js.map +1 -1
  170. package/dist/plugin.d.ts +1 -1
  171. package/dist/plugin.d.ts.map +1 -1
  172. package/dist/plugin.js +1 -1
  173. package/dist/plugin.js.map +1 -1
  174. package/dist/records.d.ts +283 -0
  175. package/dist/records.d.ts.map +1 -0
  176. package/dist/records.js +543 -0
  177. package/dist/records.js.map +1 -0
  178. package/dist/routes.d.ts +3 -1
  179. package/dist/routes.d.ts.map +1 -1
  180. package/dist/routes.js +3 -1
  181. package/dist/routes.js.map +1 -1
  182. package/dist/rules.d.ts +30 -11
  183. package/dist/rules.d.ts.map +1 -1
  184. package/dist/rules.js +98 -45
  185. package/dist/rules.js.map +1 -1
  186. package/dist/runner/acp.d.ts +1 -1
  187. package/dist/runner/acp.d.ts.map +1 -1
  188. package/dist/runner/acp.js +31 -20
  189. package/dist/runner/acp.js.map +1 -1
  190. package/dist/runner/claude.d.ts +1 -1
  191. package/dist/runner/claude.d.ts.map +1 -1
  192. package/dist/runner/claude.js +85 -15
  193. package/dist/runner/claude.js.map +1 -1
  194. package/dist/runner/codex.d.ts +1 -1
  195. package/dist/runner/codex.d.ts.map +1 -1
  196. package/dist/runner/codex.js +19 -16
  197. package/dist/runner/codex.js.map +1 -1
  198. package/dist/runner/desk.d.ts +43 -2
  199. package/dist/runner/desk.d.ts.map +1 -1
  200. package/dist/runner/desk.js +166 -10
  201. package/dist/runner/desk.js.map +1 -1
  202. package/dist/runner/process.d.ts.map +1 -1
  203. package/dist/runner/process.js +11 -4
  204. package/dist/runner/process.js.map +1 -1
  205. package/dist/runner/redact.d.ts +39 -4
  206. package/dist/runner/redact.d.ts.map +1 -1
  207. package/dist/runner/redact.js +81 -5
  208. package/dist/runner/redact.js.map +1 -1
  209. package/dist/runner/runner.d.ts +15 -1
  210. package/dist/runner/runner.d.ts.map +1 -1
  211. package/dist/runner/runner.js +231 -33
  212. package/dist/runner/runner.js.map +1 -1
  213. package/dist/runner/task-scheduler.d.ts +20 -0
  214. package/dist/runner/task-scheduler.d.ts.map +1 -1
  215. package/dist/runner/task-scheduler.js +34 -4
  216. package/dist/runner/task-scheduler.js.map +1 -1
  217. package/dist/runner/types.d.ts +36 -1
  218. package/dist/runner/types.d.ts.map +1 -1
  219. package/dist/runner/types.js +17 -0
  220. package/dist/runner/types.js.map +1 -1
  221. package/dist/runner.d.ts +6 -6
  222. package/dist/runner.d.ts.map +1 -1
  223. package/dist/runner.js +5 -5
  224. package/dist/runner.js.map +1 -1
  225. package/dist/schemas.d.ts +509 -5
  226. package/dist/schemas.d.ts.map +1 -1
  227. package/dist/schemas.js +76 -16
  228. package/dist/schemas.js.map +1 -1
  229. package/dist/services.d.ts +22 -5
  230. package/dist/services.d.ts.map +1 -1
  231. package/dist/services.js +35 -15
  232. package/dist/services.js.map +1 -1
  233. package/dist/setup-guide.d.ts +3 -1
  234. package/dist/setup-guide.d.ts.map +1 -1
  235. package/dist/setup-guide.js +7 -4
  236. package/dist/setup-guide.js.map +1 -1
  237. package/dist/vocabulary.d.ts +14 -3
  238. package/dist/vocabulary.d.ts.map +1 -1
  239. package/dist/vocabulary.js +13 -3
  240. package/dist/vocabulary.js.map +1 -1
  241. package/docs/specs/cli.md +64 -38
  242. package/docs/specs/plugins.md +27 -20
  243. package/docs/specs/records.md +113 -0
  244. package/docs/specs/rest.md +20 -13
  245. package/docs/specs/runner.md +23 -17
  246. package/package.json +7 -2
  247. package/skills/building-a-console/SKILL.md +4 -4
  248. package/skills/building-a-plugin/SKILL.md +6 -6
  249. package/skills/deploying-a-console/SKILL.md +4 -4
  250. package/skills/deploying-a-console/references/resources.md +41 -4
  251. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  252. package/skills/keeping-a-desk/SKILL.md +133 -0
  253. package/skills/keeping-a-desk/collections.md +96 -0
  254. package/skills/planning-the-board/SKILL.md +14 -18
  255. package/skills/planning-the-board/references/a-task.md +2 -2
  256. package/skills/planning-the-board/references/project-rules.md +13 -14
  257. package/skills/planning-the-board/references/setting-up.md +15 -13
  258. package/skills/running-an-agent/SKILL.md +10 -9
  259. package/skills/working-the-board/SKILL.md +62 -44
  260. package/skills/working-the-board/references/terms.md +9 -5
  261. package/skills/working-the-board/references/the-pack.md +12 -10
  262. package/skills/working-the-board/references/the-sentence.md +2 -2
  263. package/src/agent-page.tsx +3 -1
  264. package/src/api.ts +77 -2
  265. package/src/charts.ts +250 -0
  266. package/src/cli/cli.ts +1698 -476
  267. package/src/cli/command-words.ts +56 -0
  268. package/src/cli/credentials.ts +181 -20
  269. package/src/cli/directory.ts +28 -10
  270. package/src/cli/format.ts +301 -46
  271. package/src/cli/help.ts +102 -54
  272. package/src/cli/main.ts +72 -2
  273. package/src/cli/pack.ts +333 -372
  274. package/src/cli/plugin-check.ts +275 -34
  275. package/src/cli/plugin-cli.ts +28 -4
  276. package/src/cli/plugin-main.ts +1 -0
  277. package/src/cli/serve.ts +295 -2
  278. package/src/client.ts +192 -177
  279. package/src/components/agent-page.tsx +489 -243
  280. package/src/components/charts.tsx +680 -0
  281. package/src/components/desk-records.tsx +724 -0
  282. package/src/components/desk.tsx +471 -0
  283. package/src/components/event-feed.tsx +5 -1
  284. package/src/components/home.tsx +12 -0
  285. package/src/components/plugin-settings.tsx +171 -12
  286. package/src/components/projects.tsx +29 -12
  287. package/src/components/rules.tsx +94 -34
  288. package/src/components/setup.tsx +18 -3
  289. package/src/console.tsx +17 -9
  290. package/src/data.ts +37 -34
  291. package/src/desk-page.tsx +332 -0
  292. package/src/desk-records-page.tsx +256 -0
  293. package/src/desk-records.ts +808 -0
  294. package/src/desk.ts +329 -0
  295. package/src/feed-stream.ts +144 -0
  296. package/src/home-tiles.ts +55 -35
  297. package/src/i18n/en.ts +196 -9
  298. package/src/i18n/ko.ts +178 -8
  299. package/src/index.ts +118 -0
  300. package/src/limits.ts +11 -0
  301. package/src/onboarding.ts +12 -4
  302. package/src/plugin/context.ts +55 -12
  303. package/src/plugin/limits.ts +2 -0
  304. package/src/plugin/manifest.ts +38 -2
  305. package/src/plugin/rest-schemas.ts +41 -0
  306. package/src/plugin/sandbox.ts +4 -1
  307. package/src/plugin/testing.ts +63 -12
  308. package/src/plugin.ts +2 -0
  309. package/src/records.ts +702 -0
  310. package/src/routes.ts +3 -1
  311. package/src/rules.ts +108 -47
  312. package/src/runner/acp.ts +47 -29
  313. package/src/runner/claude.ts +113 -23
  314. package/src/runner/codex.ts +35 -25
  315. package/src/runner/desk.ts +198 -12
  316. package/src/runner/process.ts +11 -4
  317. package/src/runner/redact.ts +92 -6
  318. package/src/runner/runner.ts +275 -34
  319. package/src/runner/task-scheduler.ts +36 -4
  320. package/src/runner/types.ts +47 -1
  321. package/src/runner.ts +27 -2
  322. package/src/schemas.ts +83 -15
  323. package/src/services.ts +49 -14
  324. package/src/setup-guide.ts +6 -2
  325. package/src/styles/README.md +11 -1
  326. package/src/styles/console.css +9 -0
  327. package/src/styles/pages/desk.css +126 -0
  328. package/src/styles/pages/documents.css +5 -0
  329. package/src/styles/parts/bars.css +80 -0
  330. package/src/styles/parts/chart.css +173 -0
  331. package/src/styles/parts/figures.css +65 -0
  332. package/src/styles/parts/legend.css +48 -0
  333. package/src/styles/parts/series.css +32 -0
  334. package/src/styles/parts/share.css +25 -0
  335. package/src/styles/parts/spark.css +23 -0
  336. package/src/styles/parts/stat.css +69 -0
  337. package/src/styles/tokens.css +13 -7
  338. package/src/vocabulary.ts +16 -3
  339. package/template/desk-web/README.md +8 -0
  340. package/template/desk-web/index.html +13 -0
  341. package/template/desk-web/package.json +25 -0
  342. package/template/desk-web/src/main.tsx +24 -0
  343. package/template/desk-web/src/page.tsx +51 -0
  344. package/template/desk-web/tsconfig.json +16 -0
  345. package/template/desk-web/vite.config.ts +15 -0
@@ -22,7 +22,7 @@ import {
22
22
  introOf,
23
23
  makeMark,
24
24
  } from "./message.js";
25
- import { redactorOf } from "./redact.js";
25
+ import { cutShown, cutShownEnd, type Redactor, redactorOf } from "./redact.js";
26
26
  import type {
27
27
  Driver,
28
28
  DriverEvent,
@@ -57,6 +57,13 @@ export const MAX_COOL_DOWN_MS = 4 * 60 * 60_000;
57
57
  export const RECONNECT_MS = 5000;
58
58
  /** What an autosave's commit says: the runner's, and never the agent's own words. */
59
59
  export const AUTOSAVE_MESSAGE = "Autosave at the end of a session";
60
+ /**
61
+ * How long the runner holds back what the console refused as more than an hour takes
62
+ * (ADR-0132), the events of a session and the wakes of its wake sources: a minute at first,
63
+ * twice as long after each refusal that follows, a quarter of an hour at most.
64
+ */
65
+ export const HOLD_MS = 60_000;
66
+ export const MAX_HOLD_MS = 15 * 60_000;
60
67
  /** The longest the runner waits before it starts a wake source again that keeps ending at once. */
61
68
  export const MAX_SOURCE_PAUSE_MS = 5 * 60_000;
62
69
  /** How long a wake source holds before the runner takes it to have worked. */
@@ -103,7 +110,12 @@ export type RunnerClient = Pick<
103
110
 
104
111
  /** What the runner keeps between its own restarts. No secret is in it. */
105
112
  export interface RunnerState {
106
- /** The number of the last signal handed to the product. */
113
+ /**
114
+ * The number of the last signal that is delivered, every one before it too (ADR-0131): the
115
+ * product said it took it, or the record says it was never read or was let go, or the runner
116
+ * acted on it itself. One handed to a product that has not said so is not delivered yet, and
117
+ * is sent again to a runner started after.
118
+ */
107
119
  readonly delivered: number;
108
120
  /** The conversation the next session goes on with, where the product resumes one. */
109
121
  readonly conversation: string | undefined;
@@ -182,6 +194,8 @@ export interface RunnerOptions {
182
194
  coolDownMs: number;
183
195
  maxCoolDownMs: number;
184
196
  reconnectMs: number;
197
+ holdMs: number;
198
+ maxHoldMs: number;
185
199
  }>;
186
200
  /** The bounds, for a test to lower. */
187
201
  readonly bounds?: Partial<{ outboxBytes: number }>;
@@ -252,7 +266,14 @@ interface OpenSession {
252
266
  written: boolean;
253
267
  /** Writes its signals on the record, as never read where so, and only those asked for where some are. */
254
268
  readonly write: (unread?: boolean, only?: (signal: RestSignal) => boolean) => void;
269
+ /** Its signals: counted as delivered once the product took the message. */
270
+ readonly signals: readonly RestSignal[];
255
271
  }[];
272
+ /**
273
+ * Whether the product took a message of this session, or completed a turn of it. One that
274
+ * has not is still starting, for all the runner knows: it took nothing it was handed.
275
+ */
276
+ took: boolean;
256
277
  /** The number of the last event of it. */
257
278
  n: number;
258
279
  /** What the product did and the console has not been sent yet, and what that holds of memory. */
@@ -260,6 +281,10 @@ interface OpenSession {
260
281
  waiting: number;
261
282
  /** Whether the console takes nothing more of it: over there, or its month away. */
262
283
  refused: boolean;
284
+ /** The console took as many of its events as an hour takes: until when nothing is sent, and how long that was. */
285
+ hold?: { readonly until: number; readonly pause: number } | undefined;
286
+ /** Why the console did not take what waits, in its code: said where the session ends with it unsent. */
287
+ unsent?: string | undefined;
263
288
  running: { model: string | null; effort: string | null };
264
289
  /** The files written for it, to remove at its end. */
265
290
  readonly written: string[];
@@ -345,8 +370,13 @@ export function createRunner(options: RunnerOptions): Runner {
345
370
  coolDownMs: COOL_DOWN_MS,
346
371
  maxCoolDownMs: MAX_COOL_DOWN_MS,
347
372
  reconnectMs: RECONNECT_MS,
373
+ holdMs: HOLD_MS,
374
+ maxHoldMs: MAX_HOLD_MS,
348
375
  ...options.timing,
349
376
  };
377
+ /** How long what an hour's bound refused is held back: the first time, and twice as long each time after. */
378
+ const heldFor = (before: { readonly pause: number } | undefined): number =>
379
+ before === undefined ? timing.holdMs : Math.min(before.pause * 2, timing.maxHoldMs);
350
380
  const bounds = { outboxBytes: MAX_OUTBOX_BYTES, ...options.bounds };
351
381
 
352
382
  // What keeps failing is said once, and again when what is said of it changes, so that an hour
@@ -396,7 +426,12 @@ export function createRunner(options: RunnerOptions): Runner {
396
426
  };
397
427
 
398
428
  // What the runner holds.
429
+ /** The number of the last signal delivered, every one before it too: what is kept and said to the console. */
399
430
  let delivered = 0;
431
+ /** The signals handed to the product that it has not taken yet, by number: not delivered, and not sent twice. */
432
+ const owed = new Set<number>();
433
+ /** The highest number of a signal the product took, or the record says was never read or let go. */
434
+ let settled = 0;
400
435
  /** The number of the last signal the stream gave, and of the last one acted on: the second is behind the first while one waits in the queue. */
401
436
  let received = 0;
402
437
  let handled = 0;
@@ -427,8 +462,10 @@ export function createRunner(options: RunnerOptions): Runner {
427
462
  /** The values of the account's store, by what the store said of them last. */
428
463
  let secretsStamp: string | undefined;
429
464
  let secretValues = new Map<string, string>();
430
- let redact: (text: string) => string = (text) => text;
465
+ let redact: Redactor = redactorOf([]);
431
466
  let tooOldSaid = false;
467
+ /** The console took as many wakes of this runner's as an hour takes: until when none is raised, and how long that was. */
468
+ let wakesHeld: { readonly until: number; readonly pause: number } | undefined;
432
469
  /**
433
470
  * The package the runner runs from, where it is another version than the runner's: the one
434
471
  * last seen, and the one seen twice running, which the runner ends for.
@@ -569,11 +606,18 @@ export function createRunner(options: RunnerOptions): Runner {
569
606
  const codeOf = (error: unknown): string =>
570
607
  error instanceof ApiError ? error.code : error instanceof Error ? error.name : "error";
571
608
 
572
- /** Sends what the product did, a batch at a time, the pictures first. What the console has already is left there. */
573
- const flush = async (target: OpenSession): Promise<void> => {
609
+ /**
610
+ * Sends what the product did, a batch at a time, the pictures first. What the console has
611
+ * already is left there. Nothing is sent while the console holds the session to its hour
612
+ * (ADR-0132), but at the session's end, which is `last`.
613
+ */
614
+ const flush = async (target: OpenSession, last = false): Promise<void> => {
574
615
  if (flushing) {
575
616
  return;
576
617
  }
618
+ if (!last && target.hold !== undefined && options.now() < target.hold.until) {
619
+ return;
620
+ }
577
621
  flushing = true;
578
622
  const about = `transcript ${target.id}`;
579
623
  try {
@@ -623,6 +667,8 @@ export function createRunner(options: RunnerOptions): Runner {
623
667
  for (const event of target.outbox.splice(0, batch.length)) {
624
668
  target.waiting -= event.held;
625
669
  }
670
+ target.hold = undefined;
671
+ target.unsent = undefined;
626
672
  sayOver(about, `the transcript of session ${target.id} is sent again`);
627
673
  sayOver(`outbox ${target.id}`);
628
674
  } catch (error) {
@@ -670,6 +716,22 @@ export function createRunner(options: RunnerOptions): Runner {
670
716
  target.waiting += only.held - before;
671
717
  continue;
672
718
  }
719
+ if (code === "transcript.too_many") {
720
+ // As many events as the console takes of a session within an hour: what waits is
721
+ // kept, within what the runner keeps, and sent again after a while, longer each
722
+ // time, so that the console is not asked every second for what it will refuse.
723
+ const pause = heldFor(target.hold);
724
+ target.hold = { until: options.now() + pause, pause };
725
+ target.unsent = code;
726
+ // Nothing is kept past the session's end: what is let go then is said there.
727
+ if (!last) {
728
+ sayOnce(
729
+ about,
730
+ `the console takes no more events of session ${target.id} within the hour (${code}); they are kept and sent again later`,
731
+ );
732
+ }
733
+ return;
734
+ }
673
735
  if (
674
736
  code === "transcript.session_over" ||
675
737
  code === "transcript.session_not_found" ||
@@ -685,8 +747,10 @@ export function createRunner(options: RunnerOptions): Runner {
685
747
  }
686
748
  }
687
749
  } catch (error) {
688
- // Kept, and sent with the next batch. Said once for as long as it lasts, and when it is over.
689
- if (!stopped) {
750
+ // Kept, and sent with the next batch. Said once for as long as it lasts, and when it is
751
+ // over; at the session's end there is no next batch, and what is let go is said there.
752
+ target.unsent = codeOf(error);
753
+ if (!stopped && !last) {
690
754
  sayOnce(
691
755
  about,
692
756
  `the transcript of session ${target.id} waits to be sent (${codeOf(error)})`,
@@ -759,7 +823,12 @@ export function createRunner(options: RunnerOptions): Runner {
759
823
  machine: options.machine,
760
824
  });
761
825
  } catch (error) {
762
- log(`a session could not be begun at the console (${codeOf(error)})`);
826
+ const code = codeOf(error);
827
+ log(
828
+ code === "transcript.too_many_sessions"
829
+ ? `the console begins no more sessions of this account within the hour (${code}); tried again after the cool-down`
830
+ : `a session could not be begun at the console (${code})`,
831
+ );
763
832
  for (const path of handed.written) {
764
833
  await options.files.remove(path).catch(() => undefined);
765
834
  }
@@ -775,12 +844,17 @@ export function createRunner(options: RunnerOptions): Runner {
775
844
  effort: settings.effort,
776
845
  resume,
777
846
  permissions: config.permissions,
847
+ // Whatever the driver shows a part of is cut once the secrets, as the store has them
848
+ // now, are out of it: no part of one stands where a text was cut.
849
+ cut: (text, most, more) => cutShown(redact, text, most, more),
850
+ cutEnd: (text, most, more) => cutShownEnd(redact, text, most, more),
778
851
  }),
779
852
  startedAt: options.now(),
780
853
  first: true,
781
854
  turn: false,
782
855
  sent: [],
783
856
  handed: [],
857
+ took: false,
784
858
  n: 0,
785
859
  outbox: [],
786
860
  waiting: 0,
@@ -813,10 +887,28 @@ export function createRunner(options: RunnerOptions): Runner {
813
887
  await target.driver.stop().catch(() => undefined);
814
888
  }
815
889
  await target.pumped;
816
- // What the product was handed and never took is on the record as that.
817
- settle(target, true);
890
+ await hearLast(target);
891
+ // What the product was handed and never took is sent again, by the console where the
892
+ // runner itself ends and by the runner where the product had not started; else it is on
893
+ // the record as never read.
894
+ await leave(target, stopped ? "after" : already || target.took ? undefined : "next");
818
895
  record(target, "status", `The session ended: ${how}.`, { ended: how });
819
- await flush(target);
896
+ await flush(target, true);
897
+ // What the console did not take by now goes with the session: nothing of it is sent
898
+ // later, and the runner's line says how many, where an earlier one said they were kept.
899
+ const unsent = target.outbox.length;
900
+ if (unsent > 0) {
901
+ const one = unsent === 1;
902
+ log(
903
+ `${unsent} ${one ? "event" : "events"} of session ${target.id} ${one ? "was" : "were"} let go unsent when it ended: ${
904
+ target.unsent === "transcript.too_many"
905
+ ? `the console takes no more of it within the hour (${target.unsent})`
906
+ : `the console did not take ${one ? "it" : "them"} (${target.unsent ?? "error"})`
907
+ }`,
908
+ );
909
+ }
910
+ saidOf.delete(`transcript ${target.id}`);
911
+ saidOf.delete(`outbox ${target.id}`);
820
912
  try {
821
913
  await client.endAgentSession(target.id, { how });
822
914
  } catch (error) {
@@ -1018,26 +1110,136 @@ export function createRunner(options: RunnerOptions): Runner {
1018
1110
  if (waited) {
1019
1111
  write();
1020
1112
  }
1021
- target.handed.push({ written: waited, write });
1113
+ target.handed.push({ written: waited, write, signals: batch });
1022
1114
  target.turn = true;
1023
1115
  // Everything handed over since the agent was last done: what a product that took nothing is sent again.
1024
1116
  target.sent = [...target.sent, ...batch];
1025
- delivered = Math.max(delivered, ...batch.map((signal) => signal.number));
1026
- await persist();
1117
+ // Handed over, and not delivered until the product says it took it: a product that did
1118
+ // not start took nothing, and a runner that ends then is sent it again when it is back.
1119
+ for (const signal of batch) {
1120
+ owed.add(signal.number);
1121
+ }
1027
1122
  await account();
1028
1123
  };
1029
1124
 
1125
+ /** Counts signals as delivered: the product took them, or the record says what became of them. */
1126
+ const count = async (signals: readonly RestSignal[]): Promise<void> => {
1127
+ for (const signal of signals) {
1128
+ owed.delete(signal.number);
1129
+ settled = Math.max(settled, signal.number);
1130
+ }
1131
+ await account();
1132
+ };
1133
+
1134
+ /**
1135
+ * The product took the oldest message it was handed: on the record now, where it was not
1136
+ * written at once, and delivered.
1137
+ */
1138
+ const take = async (target: OpenSession): Promise<void> => {
1139
+ target.took = true;
1140
+ const message = target.handed.shift();
1141
+ if (message !== undefined) {
1142
+ if (!message.written) {
1143
+ message.write();
1144
+ }
1145
+ await count(message.signals);
1146
+ }
1147
+ };
1148
+
1030
1149
  /**
1031
- * Writes on the record what the product was handed and the record does not hold yet: all of
1032
- * it once the agent is done with what it was sent, or as never read where the session is
1033
- * over or the agent cannot go on.
1150
+ * The agent is done with what it was sent: what the product was handed and did not say it
1151
+ * took is taken, on the record where the record does not hold it yet, and delivered.
1034
1152
  */
1035
- const settle = (target: OpenSession, unread = false): void => {
1153
+ const settle = async (target: OpenSession): Promise<void> => {
1154
+ target.took = true;
1155
+ const counted: RestSignal[] = [];
1036
1156
  for (const message of target.handed.splice(0)) {
1037
1157
  if (!message.written) {
1038
- message.write(unread);
1158
+ message.write();
1159
+ }
1160
+ counted.push(...message.signals);
1161
+ }
1162
+ await count(counted);
1163
+ };
1164
+
1165
+ /**
1166
+ * Hears what the product said as its session was ended. Its words wait in the queue behind
1167
+ * whatever ended the session, and are let go there once the session is no longer the open
1168
+ * one: a message it said it took then is taken, and not sent again, and the conversation it
1169
+ * named is the one to go on with, where that message is.
1170
+ */
1171
+ const hearLast = async (target: OpenSession): Promise<void> => {
1172
+ let named = false;
1173
+ for (const message of queue) {
1174
+ if (message.t !== "driver" || message.session !== target) {
1175
+ continue;
1176
+ }
1177
+ const { event } = message;
1178
+ if (event.type === "conversation") {
1179
+ conversation = event.id;
1180
+ named = true;
1181
+ } else if (event.type === "taken") {
1182
+ await take(target);
1183
+ } else if (event.type === "turn_completed") {
1184
+ await settle(target);
1185
+ record(target, "status", "The turn completed.", { turn: "completed" });
1186
+ }
1187
+ }
1188
+ if (named) {
1189
+ await persist();
1190
+ }
1191
+ };
1192
+
1193
+ /**
1194
+ * What becomes of what the product was handed and never took, as its session ends
1195
+ * (ADR-0131). Sent again, it is not delivered, and the record holds nothing more of it than
1196
+ * a line that says so: by the console to the runner started `after` this one, where the
1197
+ * runner itself ends; by this runner in the `next` session, where the product had taken
1198
+ * nothing of this one, and so had not started. Else it is let go: on the record as never
1199
+ * read, which delivers it; what the record holds since it was handed over, to a product that
1200
+ * waited for a message, is said in a line not to have been taken.
1201
+ */
1202
+ const leave = async (target: OpenSession, again?: "after" | "next"): Promise<void> => {
1203
+ const messages = target.handed.splice(0);
1204
+ const signals = messages.flatMap((message) => message.signals);
1205
+ if (signals.length === 0) {
1206
+ return;
1207
+ }
1208
+ const numbersOf = (some: readonly RestSignal[]): string =>
1209
+ some.map((signal) => `#${signal.number}`).join(", ");
1210
+ if (again !== undefined) {
1211
+ const numbers = numbersOf(signals);
1212
+ record(
1213
+ target,
1214
+ "status",
1215
+ `The session ended before the product took what it was sent: ${numbers}. It is sent again.`,
1216
+ );
1217
+ log(`${numbers} not taken when session ${target.id} ended: sent again`);
1218
+ if (again === "next") {
1219
+ for (const signal of signals) {
1220
+ // Waits to be handed over again: owed no word of the product's, and not delivered.
1221
+ owed.delete(signal.number);
1222
+ sentBefore.add(signal.number);
1223
+ }
1224
+ pending = [...signals, ...pending];
1225
+ }
1226
+ return;
1227
+ }
1228
+ const written = messages.filter((message) => message.written).flatMap((one) => one.signals);
1229
+ if (written.length > 0) {
1230
+ record(
1231
+ target,
1232
+ "status",
1233
+ `The session ended before the product took what it was sent: ${numbersOf(written)}. Whoever sent it says it again where it still matters.`,
1234
+ );
1235
+ }
1236
+ for (const message of messages) {
1237
+ if (!message.written) {
1238
+ message.write(true);
1039
1239
  }
1040
1240
  }
1241
+ // On the record as never read: delivered.
1242
+ await count(signals);
1041
1243
  };
1042
1244
 
1043
1245
  /**
@@ -1062,13 +1264,24 @@ export function createRunner(options: RunnerOptions): Runner {
1062
1264
  };
1063
1265
 
1064
1266
  /**
1065
- * A signal that is the runner's own to act on, a stop or a choice of model say, counts as
1066
- * delivered once nothing received before it still waits to be handed to the product.
1267
+ * Counts what is delivered: signals in order, up to the last one the product took, the record
1268
+ * says was never read or let go, or the runner acted on itself, a stop or a choice of model
1269
+ * say, and never past one that still waits to be handed to the product or that the product
1270
+ * has not said it took.
1067
1271
  */
1068
1272
  const account = async (signal?: RestSignal): Promise<void> => {
1069
1273
  acted = Math.max(acted, signal?.number ?? 0);
1070
- if (pending.length === 0 && acted > delivered) {
1071
- delivered = acted;
1274
+ const most = Math.max(settled, acted);
1275
+ let least = Number.POSITIVE_INFINITY;
1276
+ for (const kept of pending) {
1277
+ least = Math.min(least, kept.number);
1278
+ }
1279
+ for (const number of owed) {
1280
+ least = Math.min(least, number);
1281
+ }
1282
+ const next = Math.min(most, least - 1);
1283
+ if (next > delivered) {
1284
+ delivered = next;
1072
1285
  await persist();
1073
1286
  }
1074
1287
  };
@@ -1082,7 +1295,11 @@ export function createRunner(options: RunnerOptions): Runner {
1082
1295
 
1083
1296
  const onSignal = async (signal: RestSignal): Promise<void> => {
1084
1297
  handled = Math.max(handled, signal.number);
1085
- if (signal.number <= delivered || pending.some((kept) => kept.number === signal.number)) {
1298
+ if (
1299
+ signal.number <= delivered ||
1300
+ owed.has(signal.number) ||
1301
+ pending.some((kept) => kept.number === signal.number)
1302
+ ) {
1086
1303
  return;
1087
1304
  }
1088
1305
  const by = signal.by?.name ?? signal.by?.login ?? "a supervisor";
@@ -1090,8 +1307,9 @@ export function createRunner(options: RunnerOptions): Runner {
1090
1307
  case "stop": {
1091
1308
  held = true;
1092
1309
  if (session !== undefined) {
1093
- // What the product had not taken is on the record before the stop that leaves it unread.
1094
- settle(session, true);
1310
+ // What the product had not taken is on the record before the stop that leaves it
1311
+ // unread; what a product that had not started was handed waits for the restart.
1312
+ await leave(session, session.took ? undefined : "next");
1095
1313
  record(session, "person", signal.text, signalData(signal));
1096
1314
  }
1097
1315
  await end("stopped");
@@ -1212,16 +1430,12 @@ export function createRunner(options: RunnerOptions): Runner {
1212
1430
  return;
1213
1431
  }
1214
1432
  case "taken": {
1215
- // The oldest message handed over: on the record now, where it was not written at once.
1216
- const message = target.handed.shift();
1217
- if (message !== undefined && !message.written) {
1218
- message.write();
1219
- }
1433
+ await take(target);
1220
1434
  return;
1221
1435
  }
1222
1436
  case "turn_completed": {
1223
1437
  // The agent is done with everything it was sent: what a product did not say it took is taken.
1224
- settle(target);
1438
+ await settle(target);
1225
1439
  // The record says where a turn ends, so that whoever reads it live knows the agent is done.
1226
1440
  record(target, "status", "The turn completed.", { turn: "completed" });
1227
1441
  target.turn = false;
@@ -1274,10 +1488,14 @@ export function createRunner(options: RunnerOptions): Runner {
1274
1488
  }
1275
1489
  for (const signal of again) {
1276
1490
  sentBefore.add(signal.number);
1491
+ // Waits to be handed over again: owed no word of the product's, and not delivered.
1492
+ owed.delete(signal.number);
1277
1493
  }
1278
1494
  pending = [...again, ...pending];
1279
1495
  // Sent again, and on the record when it is taken then.
1280
1496
  target.handed = [];
1497
+ // What was let go is on the record as that, and is delivered: it is sent no more.
1498
+ await count(gone);
1281
1499
  }
1282
1500
  target.sent = [];
1283
1501
  waits = cooled(waits);
@@ -1379,7 +1597,7 @@ export function createRunner(options: RunnerOptions): Runner {
1379
1597
  // the product says it took then is this message, which the record holds nothing
1380
1598
  // of, and not the message of a signal that waits behind it.
1381
1599
  target.turn = true;
1382
- target.handed.push({ written: true, write: () => undefined });
1600
+ target.handed.push({ written: true, write: () => undefined, signals: [] });
1383
1601
  } catch {
1384
1602
  // Not told: the runner's own line above says it to whoever reads its output.
1385
1603
  }
@@ -1453,7 +1671,30 @@ export function createRunner(options: RunnerOptions): Runner {
1453
1671
  const host: WakeHost = {
1454
1672
  secret: async (name) => secretValues.get(name),
1455
1673
  raise: async (raised) => {
1456
- await client.raiseWake({ source: "messenger", key: raised.key, text: raised.text });
1674
+ // The console takes so many wakes a runner raises itself within an hour (ADR-0132):
1675
+ // past that, what the sources raise is let go for a while, longer each time, and said
1676
+ // once, so that a source that repeats itself costs the console nothing more.
1677
+ if (wakesHeld !== undefined && options.now() < wakesHeld.until) {
1678
+ return;
1679
+ }
1680
+ try {
1681
+ await client.raiseWake({ source: "messenger", key: raised.key, text: raised.text });
1682
+ } catch (error) {
1683
+ if (codeOf(error) !== "signal.too_many") {
1684
+ throw error;
1685
+ }
1686
+ const pause = heldFor(wakesHeld);
1687
+ wakesHeld = { until: options.now() + pause, pause };
1688
+ sayOnce(
1689
+ "wakes",
1690
+ "the console takes no more wakes of this runner's within the hour (signal.too_many); what its wake sources raise is let go for a while",
1691
+ );
1692
+ return;
1693
+ }
1694
+ if (wakesHeld !== undefined) {
1695
+ wakesHeld = undefined;
1696
+ sayOver("wakes", "the console takes the wakes of this runner's wake sources again");
1697
+ }
1457
1698
  },
1458
1699
  log,
1459
1700
  fetch: wakes.fetch,
@@ -8,8 +8,9 @@ import { KEEPER_VARIABLE, type Service, type ServiceCommand, type ServiceInput }
8
8
  // The system starts a task once and in a window, gives it the account's environment and not the
9
9
  // one the machine was set up in, keeps none of its words, and ends it by ending the one process
10
10
  // it started: so what the task starts is a few lines of the system's own shell, in no window,
11
- // which start the runner with the setup's `PATH`, keep its lines, start it again when it ends
12
- // and tell it which process keeps it. Written from the system's own documentation, the Task
11
+ // which start the runner with the setup's `PATH`, keep its lines in a log that is put aside
12
+ // when it is full, start it again when it ends and tell it which process keeps it. Written from
13
+ // the system's own documentation, the Task
13
14
  // Scheduler's schema and schtasks, and run on Windows 11; the module says what to write and what
14
15
  // to run, and whoever sets the machine up does it.
15
16
 
@@ -22,6 +23,14 @@ const RESTART_SECONDS = 10;
22
23
  /** The most a task's command line carries, with room left for the shell's own path. */
23
24
  const MAX_COMMAND = 30_000;
24
25
 
26
+ /**
27
+ * How large the log is before it is put aside, in bytes, and how many logs put aside are kept:
28
+ * the runner's lines hold a few megabytes at most, on a machine that runs for years. The other
29
+ * services leave it to the system, whose journal keeps to a size of its own.
30
+ */
31
+ export const MAX_LOG_BYTES = 4 * 1024 * 1024;
32
+ export const KEPT_LOGS = 3;
33
+
25
34
  /** What a task's name, and so the name of an OS account in it, cannot hold. */
26
35
  const UNNAMEABLE = /[\\/:*?"<>|]/;
27
36
 
@@ -76,6 +85,29 @@ const word = (text: string): string => {
76
85
  return parts.length === 1 ? (parts[0] ?? "''") : `(${parts.join(" + [char]37 + ")})`;
77
86
  };
78
87
 
88
+ /**
89
+ * What keeps a line in the log, as a function of the shell's, `Keep`: the log is put aside
90
+ * first where it is full, as `<log>.1`, the ones put aside before each moved one on and the
91
+ * oldest let go, and the line is added and the log let go of, so that it is read while the
92
+ * runner runs. Whoever writes the log bounds it: a runner that cannot start writes lines too.
93
+ * The log itself is moved first, to a spare name, `<log>.0`, and the ones put aside are
94
+ * touched only once that worked: a log that cannot be moved, read by something that holds it
95
+ * say, is added to as it is and put aside at a later line, and costs none of them, where
96
+ * letting the oldest go first lost one at every line. A spare name left by a step after it
97
+ * that did not work is gone on from, the log after it added to meanwhile. The log is `$log`;
98
+ * no quote and no percent sign is written, as nothing of the task's line may hold one.
99
+ */
100
+ export function logKeeper(maxBytes: number = MAX_LOG_BYTES, kept: number = KEPT_LOGS): string {
101
+ const aside = [
102
+ "$spare = $log + '.0'",
103
+ "if (-not [IO.File]::Exists($spare)) { [IO.File]::Move($log, $spare) }",
104
+ `$last = $log + '.${kept}'`,
105
+ "if ([IO.File]::Exists($last)) { [IO.File]::Delete($last) }",
106
+ `for ($i = ${kept - 1}; $i -ge 0; $i--) { $from = $log + '.' + $i; if ([IO.File]::Exists($from)) { [IO.File]::Move($from, $log + '.' + ($i + 1)) } }`,
107
+ ].join("; ");
108
+ return `function Keep($line) { try { $now = [IO.FileInfo]$log; if ($now.Exists -and $now.Length -ge ${maxBytes}) { ${aside} } } catch { }; [IO.File]::AppendAllText($log, [string]$line + [Environment]::NewLine) }`;
109
+ }
110
+
79
111
  /**
80
112
  * What the task starts, in the system's own shell and on one line: the runner in the desk with
81
113
  * the `PATH` the machine was set up with, its lines added to the log as they come, and the
@@ -86,13 +118,13 @@ const word = (text: string): string => {
86
118
  */
87
119
  export function taskScript(input: ServiceInput, log: string): string {
88
120
  const [runner = "", ...words] = input.program;
89
- // A line is added to the log and the log is let go of, so that it is read while the runner runs.
90
- const kept = "[IO.File]::AppendAllText($log, [string]$_ + [Environment]::NewLine)";
121
+ const kept = "Keep $_";
91
122
  return [
92
123
  // A line the runner writes of an error is a line, and what it writes is read as it wrote it.
93
124
  "$ErrorActionPreference = 'Continue'",
94
125
  "[Console]::OutputEncoding = [Text.Encoding]::UTF8",
95
126
  `$log = ${word(log)}`,
127
+ logKeeper(),
96
128
  `$runner = ${word(runner)}`,
97
129
  `$words = @(${words.map(word).join(", ")})`,
98
130
  // A runner left behind is the same program, started with the same words to their end as
@@ -101,6 +101,49 @@ export interface StartOptions {
101
101
  * names it; the driver's own for a run nobody attends where nothing names one.
102
102
  */
103
103
  readonly permissions?: string | undefined;
104
+ /**
105
+ * What cuts a text to what the transcript shows of it. A driver cuts whatever it shows a
106
+ * part of through this, and never by itself first; left out, a text is cut as it is.
107
+ */
108
+ readonly cut?: Cut | undefined;
109
+ /**
110
+ * What keeps the end of a text to what the transcript shows of it, the secrets out first: the
111
+ * end of what the product wrote on its standard error, which says why it ended. A driver shows
112
+ * that through this (`errorsShown`); left out, a text is cut as it is.
113
+ */
114
+ readonly cutEnd?: Cut | undefined;
115
+ }
116
+
117
+ /**
118
+ * A text within `most` characters as the transcript shows it, ended by the mark of a cut where
119
+ * it was longer: the account's secrets are taken out first and the text is cut after, so that
120
+ * no part of one stands at the cut. `more` says that the text is itself the beginning of a
121
+ * longer one, which the driver kept to a bound: its last characters may begin a secret, and
122
+ * are not shown.
123
+ */
124
+ export type Cut = (text: string, most: number, more?: boolean) => string;
125
+
126
+ /** A text cut as it is, with the mark of a cut: what a driver cuts with where it was handed nothing to cut with. */
127
+ export const plainCut: Cut = (text, most) =>
128
+ text.length > most ? `${text.slice(0, most)}…` : text;
129
+
130
+ /** The end of a text kept as it is, begun by the mark of a cut: what a driver keeps the end of a text with where it was handed nothing to. */
131
+ export const plainCutEnd: Cut = (text, most, more = false) =>
132
+ text.length > most || more ? `…${text.slice(Math.max(0, text.length - most))}` : text;
133
+
134
+ /** How much of the end of what a product wrote on its standard error an event shows. */
135
+ export const MAX_ERRORS_SHOWN = 4000;
136
+
137
+ /**
138
+ * What a product wrote on its standard error as an event shows it: its end, within
139
+ * `MAX_ERRORS_SHOWN`, kept through `cutEnd`, so that the secrets are out before it is cut. A
140
+ * text whose beginning the child let go begins with the mark of a cut (`Child.errors`), and its
141
+ * first characters may be the end of a secret: they are not shown.
142
+ */
143
+ export function errorsShown(errors: string, cutEnd: Cut): string {
144
+ const text = errors.trim();
145
+ const more = text.startsWith("…");
146
+ return cutEnd(more ? text.slice(1) : text, MAX_ERRORS_SHOWN, more);
104
147
  }
105
148
 
106
149
  /** What the installed product is and offers, asked without starting a session. */
@@ -149,7 +192,10 @@ export interface Child {
149
192
  end(): void;
150
193
  /** Its standard output, a line at a time, until it closes. Read once. */
151
194
  readonly lines: AsyncIterable<string>;
152
- /** The end of what it wrote on its standard error, bounded. */
195
+ /**
196
+ * The end of what it wrote on its standard error, bounded: where its beginning was let go, it
197
+ * begins with the mark of a cut (`…`), since what it begins with may be the end of a secret.
198
+ */
153
199
  errors(): string;
154
200
  kill(signal: "SIGINT" | "SIGTERM" | "SIGKILL"): void;
155
201
  /** How it ended: its exit code, or the signal that ended it; or why it never started. Never rejects. */