@skillcdn/console 0.6.2 → 0.6.4

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 (253) hide show
  1. package/README.md +16 -9
  2. package/SKILLCDN.md +3 -2
  3. package/dist/agent-page.d.ts +2 -0
  4. package/dist/agent-page.d.ts.map +1 -1
  5. package/dist/agent-page.js +46 -5
  6. package/dist/agent-page.js.map +1 -1
  7. package/dist/agent-state.d.ts +9 -0
  8. package/dist/agent-state.d.ts.map +1 -0
  9. package/dist/agent-state.js +28 -0
  10. package/dist/agent-state.js.map +1 -0
  11. package/dist/api.d.ts +6 -4
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +6 -4
  14. package/dist/api.js.map +1 -1
  15. package/dist/cli/cli.d.ts +2 -0
  16. package/dist/cli/cli.d.ts.map +1 -1
  17. package/dist/cli/cli.js +948 -252
  18. package/dist/cli/cli.js.map +1 -1
  19. package/dist/cli/format.d.ts +44 -7
  20. package/dist/cli/format.d.ts.map +1 -1
  21. package/dist/cli/format.js +168 -13
  22. package/dist/cli/format.js.map +1 -1
  23. package/dist/cli/help.d.ts +82 -9
  24. package/dist/cli/help.d.ts.map +1 -1
  25. package/dist/cli/help.js +855 -331
  26. package/dist/cli/help.js.map +1 -1
  27. package/dist/cli/pack.d.ts +13 -12
  28. package/dist/cli/pack.d.ts.map +1 -1
  29. package/dist/cli/pack.js +33 -45
  30. package/dist/cli/pack.js.map +1 -1
  31. package/dist/cli/plugin-cli.d.ts.map +1 -1
  32. package/dist/cli/plugin-cli.js +8 -5
  33. package/dist/cli/plugin-cli.js.map +1 -1
  34. package/dist/cli/runner-files.d.ts +16 -0
  35. package/dist/cli/runner-files.d.ts.map +1 -0
  36. package/dist/cli/runner-files.js +125 -0
  37. package/dist/cli/runner-files.js.map +1 -0
  38. package/dist/cli/runner-host.d.ts +7 -0
  39. package/dist/cli/runner-host.d.ts.map +1 -1
  40. package/dist/cli/runner-host.js +40 -2
  41. package/dist/cli/runner-host.js.map +1 -1
  42. package/dist/cli/skill-path.d.ts +11 -0
  43. package/dist/cli/skill-path.d.ts.map +1 -0
  44. package/dist/cli/skill-path.js +44 -0
  45. package/dist/cli/skill-path.js.map +1 -0
  46. package/dist/client.d.ts +32 -1
  47. package/dist/client.d.ts.map +1 -1
  48. package/dist/client.js +15 -1
  49. package/dist/client.js.map +1 -1
  50. package/dist/components/agent-page.d.ts +93 -6
  51. package/dist/components/agent-page.d.ts.map +1 -1
  52. package/dist/components/agent-page.js +202 -10
  53. package/dist/components/agent-page.js.map +1 -1
  54. package/dist/components/agents.d.ts +6 -6
  55. package/dist/components/agents.d.ts.map +1 -1
  56. package/dist/components/agents.js +16 -9
  57. package/dist/components/agents.js.map +1 -1
  58. package/dist/components/people.d.ts.map +1 -1
  59. package/dist/components/people.js +7 -2
  60. package/dist/components/people.js.map +1 -1
  61. package/dist/components/picker.d.ts +16 -0
  62. package/dist/components/picker.d.ts.map +1 -1
  63. package/dist/components/picker.js +69 -4
  64. package/dist/components/picker.js.map +1 -1
  65. package/dist/console.css +40 -0
  66. package/dist/console.js +2 -2
  67. package/dist/console.js.map +1 -1
  68. package/dist/feed-words.d.ts.map +1 -1
  69. package/dist/feed-words.js +12 -1
  70. package/dist/feed-words.js.map +1 -1
  71. package/dist/i18n/en.d.ts +64 -6
  72. package/dist/i18n/en.d.ts.map +1 -1
  73. package/dist/i18n/en.js +59 -10
  74. package/dist/i18n/en.js.map +1 -1
  75. package/dist/i18n/ko.d.ts.map +1 -1
  76. package/dist/i18n/ko.js +49 -9
  77. package/dist/i18n/ko.js.map +1 -1
  78. package/dist/limits.d.ts +26 -0
  79. package/dist/limits.d.ts.map +1 -1
  80. package/dist/limits.js +26 -0
  81. package/dist/limits.js.map +1 -1
  82. package/dist/onboarding.d.ts +18 -6
  83. package/dist/onboarding.d.ts.map +1 -1
  84. package/dist/onboarding.js +42 -7
  85. package/dist/onboarding.js.map +1 -1
  86. package/dist/plugin/args.d.ts +24 -2
  87. package/dist/plugin/args.d.ts.map +1 -1
  88. package/dist/plugin/args.js +20 -2
  89. package/dist/plugin/args.js.map +1 -1
  90. package/dist/plugin/context.d.ts +39 -7
  91. package/dist/plugin/context.d.ts.map +1 -1
  92. package/dist/plugin/define.d.ts.map +1 -1
  93. package/dist/plugin/define.js +12 -3
  94. package/dist/plugin/define.js.map +1 -1
  95. package/dist/plugin/rest-schemas.d.ts +2 -0
  96. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  97. package/dist/plugin/rest-schemas.js +1 -0
  98. package/dist/plugin/rest-schemas.js.map +1 -1
  99. package/dist/routes.d.ts +2 -0
  100. package/dist/routes.d.ts.map +1 -1
  101. package/dist/routes.js +2 -0
  102. package/dist/routes.js.map +1 -1
  103. package/dist/rules.d.ts +4 -1
  104. package/dist/rules.d.ts.map +1 -1
  105. package/dist/rules.js +5 -2
  106. package/dist/rules.js.map +1 -1
  107. package/dist/runner/acp.d.ts.map +1 -1
  108. package/dist/runner/acp.js +9 -3
  109. package/dist/runner/acp.js.map +1 -1
  110. package/dist/runner/claude.d.ts.map +1 -1
  111. package/dist/runner/claude.js +53 -1
  112. package/dist/runner/claude.js.map +1 -1
  113. package/dist/runner/codex.d.ts.map +1 -1
  114. package/dist/runner/codex.js +18 -3
  115. package/dist/runner/codex.js.map +1 -1
  116. package/dist/runner/config.d.ts +18 -0
  117. package/dist/runner/config.d.ts.map +1 -1
  118. package/dist/runner/config.js +77 -1
  119. package/dist/runner/config.js.map +1 -1
  120. package/dist/runner/desk.d.ts +7 -0
  121. package/dist/runner/desk.d.ts.map +1 -1
  122. package/dist/runner/desk.js +14 -4
  123. package/dist/runner/desk.js.map +1 -1
  124. package/dist/runner/message.d.ts +16 -22
  125. package/dist/runner/message.d.ts.map +1 -1
  126. package/dist/runner/message.js +72 -120
  127. package/dist/runner/message.js.map +1 -1
  128. package/dist/runner/runner.d.ts +41 -1
  129. package/dist/runner/runner.d.ts.map +1 -1
  130. package/dist/runner/runner.js +557 -23
  131. package/dist/runner/runner.js.map +1 -1
  132. package/dist/runner/slack-status.d.ts +19 -0
  133. package/dist/runner/slack-status.d.ts.map +1 -0
  134. package/dist/runner/slack-status.js +332 -0
  135. package/dist/runner/slack-status.js.map +1 -0
  136. package/dist/runner/slack.d.ts.map +1 -1
  137. package/dist/runner/slack.js +258 -59
  138. package/dist/runner/slack.js.map +1 -1
  139. package/dist/runner/types.d.ts +128 -15
  140. package/dist/runner/types.d.ts.map +1 -1
  141. package/dist/runner/types.js.map +1 -1
  142. package/dist/runner/usage.d.ts +6 -1
  143. package/dist/runner/usage.d.ts.map +1 -1
  144. package/dist/runner/usage.js +9 -2
  145. package/dist/runner/usage.js.map +1 -1
  146. package/dist/runner.d.ts +2 -2
  147. package/dist/runner.d.ts.map +1 -1
  148. package/dist/runner.js.map +1 -1
  149. package/dist/schemas.d.ts +635 -6
  150. package/dist/schemas.d.ts.map +1 -1
  151. package/dist/schemas.js +197 -15
  152. package/dist/schemas.js.map +1 -1
  153. package/dist/secret-file.d.ts +21 -0
  154. package/dist/secret-file.d.ts.map +1 -0
  155. package/dist/secret-file.js +59 -0
  156. package/dist/secret-file.js.map +1 -0
  157. package/dist/services.d.ts.map +1 -1
  158. package/dist/services.js +3 -2
  159. package/dist/services.js.map +1 -1
  160. package/dist/setup-guide.d.ts +2 -2
  161. package/dist/setup-guide.d.ts.map +1 -1
  162. package/dist/setup-guide.js +6 -5
  163. package/dist/setup-guide.js.map +1 -1
  164. package/dist/vocabulary.d.ts +17 -2
  165. package/dist/vocabulary.d.ts.map +1 -1
  166. package/dist/vocabulary.js +15 -2
  167. package/dist/vocabulary.js.map +1 -1
  168. package/dist/wake-text.d.ts +43 -0
  169. package/dist/wake-text.d.ts.map +1 -0
  170. package/dist/wake-text.js +115 -0
  171. package/dist/wake-text.js.map +1 -0
  172. package/docs/specs/cli.md +39 -25
  173. package/docs/specs/plugins.md +10 -9
  174. package/docs/specs/rest.md +34 -15
  175. package/docs/specs/runner.md +108 -25
  176. package/docs/start.md +28 -6
  177. package/package.json +3 -3
  178. package/skills/building-a-plugin/SKILL.md +2 -2
  179. package/skills/deploying-a-console/SKILL.md +3 -3
  180. package/skills/deploying-a-console/references/access.md +15 -1
  181. package/skills/deploying-a-console/references/resources.md +2 -2
  182. package/skills/deploying-a-console/scripts/github-app.mjs +593 -0
  183. package/skills/keeping-the-pack/SKILL.md +87 -0
  184. package/skills/planning-the-board/SKILL.md +6 -6
  185. package/skills/planning-the-board/references/a-task.md +1 -1
  186. package/skills/planning-the-board/references/setting-up.md +9 -5
  187. package/skills/running-an-agent/SKILL.md +21 -17
  188. package/skills/running-an-agent/references/preparing-the-machine.md +4 -3
  189. package/skills/running-an-agent/references/several-tasks.md +8 -2
  190. package/skills/running-an-agent/references/slack-app.md +31 -8
  191. package/skills/running-an-agent/references/the-account-and-the-invitation.md +1 -1
  192. package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -1
  193. package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +4 -4
  194. package/skills/running-an-agent/references/your-first-task.md +11 -5
  195. package/skills/trying-a-console/SKILL.md +136 -0
  196. package/skills/trying-a-console/references/when-it-does-not-go.md +30 -0
  197. package/skills/working-the-board/SKILL.md +6 -6
  198. package/skills/working-the-board/references/terms.md +3 -1
  199. package/skills/working-the-board/references/the-pack.md +14 -7
  200. package/skills/working-the-board/references/what-they-were-told.md +1 -1
  201. package/src/agent-page.tsx +111 -4
  202. package/src/agent-state.ts +33 -0
  203. package/src/api.ts +43 -0
  204. package/src/cli/cli.ts +1190 -313
  205. package/src/cli/format.ts +207 -13
  206. package/src/cli/help.ts +991 -372
  207. package/src/cli/pack.ts +55 -62
  208. package/src/cli/plugin-cli.ts +8 -5
  209. package/src/cli/runner-files.ts +137 -0
  210. package/src/cli/runner-host.ts +48 -2
  211. package/src/cli/skill-path.ts +51 -0
  212. package/src/client.ts +103 -0
  213. package/src/components/agent-page.tsx +446 -20
  214. package/src/components/agents.tsx +27 -28
  215. package/src/components/people.tsx +7 -3
  216. package/src/components/picker.tsx +79 -5
  217. package/src/console.tsx +1 -1
  218. package/src/feed-words.ts +14 -1
  219. package/src/i18n/en.ts +64 -11
  220. package/src/i18n/ko.ts +55 -9
  221. package/src/limits.ts +26 -0
  222. package/src/onboarding.ts +60 -21
  223. package/src/plugin/args.ts +29 -3
  224. package/src/plugin/context.ts +40 -7
  225. package/src/plugin/define.ts +18 -3
  226. package/src/plugin/rest-schemas.ts +3 -0
  227. package/src/routes.ts +2 -0
  228. package/src/rules.ts +5 -2
  229. package/src/runner/acp.ts +9 -3
  230. package/src/runner/claude.ts +58 -1
  231. package/src/runner/codex.ts +18 -3
  232. package/src/runner/config.ts +114 -1
  233. package/src/runner/desk.ts +15 -4
  234. package/src/runner/message.ts +88 -126
  235. package/src/runner/runner.ts +682 -27
  236. package/src/runner/slack-status.ts +423 -0
  237. package/src/runner/slack.ts +310 -67
  238. package/src/runner/types.ts +124 -13
  239. package/src/runner/usage.ts +16 -3
  240. package/src/runner.ts +4 -0
  241. package/src/schemas.ts +245 -13
  242. package/src/secret-file.ts +76 -0
  243. package/src/services.ts +3 -2
  244. package/src/setup-guide.ts +6 -5
  245. package/src/styles/README.md +1 -1
  246. package/src/styles/pages/agents.css +40 -0
  247. package/src/vocabulary.ts +21 -2
  248. package/src/wake-text.ts +133 -0
  249. package/dist/cli/command-words.d.ts +0 -20
  250. package/dist/cli/command-words.d.ts.map +0 -1
  251. package/dist/cli/command-words.js +0 -51
  252. package/dist/cli/command-words.js.map +0 -1
  253. package/src/cli/command-words.ts +0 -56
@@ -1,7 +1,9 @@
1
1
  import { ApiError } from "../client.js";
2
+ import { compareVersions, judgeClient, parseVersion } from "../compat.js";
2
3
  import { MAX_RUNNER_LINE_LENGTH, MAX_RUNNER_OFFERS, MAX_TRANSCRIPT_ATTACHMENTS, MAX_TRANSCRIPT_BATCH, MAX_TRANSCRIPT_BATCH_BYTES, MAX_TRANSCRIPT_FACT_LENGTH, MAX_TRANSCRIPT_FACT_NAME_LENGTH, MAX_TRANSCRIPT_FACTS, MAX_TRANSCRIPT_TEXT_BYTES, } from "../limits.js";
3
4
  import { RUNNER_CHOICE } from "../schemas.js";
4
5
  import { hasForbiddenCodePoint } from "../text.js";
6
+ import { STATUS_AFTER } from "./config.js";
5
7
  import { composeSignals, deskName, GROUP_WINDOW_MS, introOf, makeMark, sleptOf, wakeTextOf, } from "./message.js";
6
8
  import { cutShown, cutShownEnd, redactorOf } from "./redact.js";
7
9
  import { limitWords, noteUsage, RESET_MARGIN_MS, runnerSays, usageSaid, usageToTell, usageWords, } from "./usage.js";
@@ -18,6 +20,14 @@ import { limitWords, noteUsage, RESET_MARGIN_MS, runnerSays, usageSaid, usageToT
18
20
  // a signal received, a word of the driver's, a timer that fired. What the product prints is
19
21
  // numbered and kept for the next batch as it arrives, so that nothing of a session is left
20
22
  // behind when the session ends.
23
+ /** How long a wake a source raised is waited for on the stream before the source is shown nothing of it. */
24
+ const RAISED_MS = 60_000;
25
+ /** From how far away a moment is said with its day in a status. */
26
+ const FAR_MS = 20 * 60 * 60_000;
27
+ /** How long the runner's end waits for the wake sources to take back what they showed. */
28
+ const SHOWN_END_MS = 3000;
29
+ /** What the wake sources are said as the runner ends. */
30
+ const LAST_STATUS = { state: "idle", last: true };
21
31
  /** How often the runner says it is there. */
22
32
  export const HEARTBEAT_MS = 30_000;
23
33
  /** How often what the product did is sent, while there is something to send. */
@@ -60,8 +70,21 @@ const SOURCE_HELD_MS = 60_000;
60
70
  const SLEPT_MS = 60_000;
61
71
  /** The kinds of event that are the agent's own answer: what it said, thought or called. */
62
72
  const ANSWERS = new Set(["assistant", "thinking", "tool_call"]);
73
+ /**
74
+ * How long before its wake is on the record a message may have been written (ADR-0166): what a
75
+ * wake source reads for a wake, and the wakes ahead of it, are waited for half a minute at the
76
+ * most, and the messenger's clock and the console's differ by less than the rest.
77
+ */
78
+ const RAISED_AFTER_MS = 60_000;
79
+ /** What an agent told to update the command is told with it (ADR-0101): the runner does the rest. */
80
+ const UPDATE_FOLLOWS = "The runner sees the update and is started again with it by itself, once no turn is under way.";
81
+ const UPDATE_OTHERWISE = "Where you cannot update it, say so to whom you report to.";
63
82
  /** How many signals the runner writes down as kept for the agent beside what the record sends again. */
64
83
  const MAX_KEPT = 50;
84
+ /** How many kinds of output a driver has no reading for the runner keeps as said on a record already. */
85
+ const MAX_UNKNOWN_SAID = 32;
86
+ /** How many of them a session names where it says that the product's version may be why. */
87
+ const MAX_UNKNOWN_NAMED = 3;
65
88
  /** How long before its moment a timer may ring: a delivery asked for at a moment is taken within it. */
66
89
  const TIMER_EARLY_MS = 20;
67
90
  /**
@@ -164,6 +187,19 @@ const lineOf = (value) => {
164
187
  const line = (value ?? "").trim().slice(0, MAX_RUNNER_LINE_LENGTH).trim();
165
188
  return line.length === 0 || hasForbiddenCodePoint(line) ? null : line;
166
189
  };
190
+ /** What a wake source keeps, which says whether it changed since it was last written down. */
191
+ class Kept extends Map {
192
+ changed = false;
193
+ set(name, value) {
194
+ this.changed = true;
195
+ return super.set(name, value);
196
+ }
197
+ delete(name) {
198
+ const had = super.delete(name);
199
+ this.changed ||= had;
200
+ return had;
201
+ }
202
+ }
167
203
  export function createRunner(options) {
168
204
  const { client, driver, config, log } = options;
169
205
  const timing = {
@@ -238,14 +274,41 @@ export function createRunner(options) {
238
274
  let received = 0;
239
275
  let handled = 0;
240
276
  let conversation;
277
+ /**
278
+ * When the conversation the agent goes on with began (ADR-0166), 0 where nothing says, and
279
+ * whether that moment is of a conversation no session has begun yet: the session that begins
280
+ * it then leaves the moment as it stands.
281
+ */
282
+ let began = 0;
283
+ let renewed = false;
284
+ /**
285
+ * The signals the conversation holds already, by number (ADR-0166): the product of the open
286
+ * session took them there as a usage limit was reached, its driver vouching that what it
287
+ * took stands (`can.holdsTaken`), and the agent never answered. Handed over again in that
288
+ * session, they are named and not said a second time. Until a turn completes, the
289
+ * conversation is let go or put in fewer words, or the session ends: nothing says before a
290
+ * session's first message whether its product went on with the conversation, so a session
291
+ * begun after is said them whole.
292
+ */
293
+ const above = new Set();
294
+ /** What each wake source keeps, by its name, and whether it changed since it was last written. */
295
+ const keeps = new Map();
296
+ /**
297
+ * How the agent stands and why, with when the runner said so (`at`): the console is told that
298
+ * moment with the reason, since a reason is said again the same under a state that stays, a
299
+ * turn that completed after another say, and nothing else tells the two apart.
300
+ */
241
301
  let stands = {
242
302
  state: "running",
243
303
  reason: "started",
304
+ at: options.now(),
244
305
  };
245
306
  let said = "";
246
307
  let settings = { model: null, effort: null };
247
308
  let probe = { version: undefined, models: [], efforts: [] };
248
309
  let productVersion = null;
310
+ /** The kinds of output the driver had no reading for that a record says already (ADR-0182). */
311
+ const unknownSaid = new Set();
249
312
  let session;
250
313
  /** What was received and not handed to the product yet, in order. */
251
314
  let pending = [];
@@ -290,6 +353,8 @@ export function createRunner(options) {
290
353
  let secretValues = new Map();
291
354
  let redact = redactorOf([]);
292
355
  let tooOldSaid = false;
356
+ /** The version of the console the agent was told a newer command exists for (ADR-0182). */
357
+ let toldNewer;
293
358
  /** The console took as many wakes of this runner's as an hour takes: until when none is raised, and how long that was. */
294
359
  let wakesHeld;
295
360
  /**
@@ -316,6 +381,25 @@ export function createRunner(options) {
316
381
  let slept;
317
382
  /** How each wake source stands, by its name: what the heartbeat says of them. */
318
383
  const sources = new Map();
384
+ /**
385
+ * The wake sources that show how the agent stands (ADR-0170), by name: the host each runs
386
+ * with, and what it was last said and when.
387
+ */
388
+ const shows = new Map();
389
+ /**
390
+ * What `runner.json` says of how the agent stands is shown: `false` for not at all, and the
391
+ * sources' own way where it says nothing, a desk of before and a config put together by hand
392
+ * among them.
393
+ */
394
+ const shownAs = config.status ?? {};
395
+ /** Since when the agent is at work without a pause: a turn under way, or something that goes on in its session with none. */
396
+ let atWorkSince;
397
+ /**
398
+ * What each wake source raised that the stream has not brought back yet: when it was raised,
399
+ * and its number once the console took it. A message that reached the runner is on its way
400
+ * to the agent from then on, which its source shows.
401
+ */
402
+ const raising = new Map();
319
403
  /**
320
404
  * The signals a product was handed and never took, since it did not start or was not signed
321
405
  * in, which are kept to be sent again; and, of those, the ones a reset gave one more try: a
@@ -351,14 +435,105 @@ export function createRunner(options) {
351
435
  ? {}
352
436
  : { limited: { since: limited.since, until: limited.until } }),
353
437
  ...(kept.length === 0 ? {} : { kept }),
438
+ ...(began === 0 ? {} : { began }),
439
+ ...(unknownSaid.size === 0 ? {} : { unknown: [...unknownSaid] }),
440
+ ...(toldNewer === undefined ? {} : { newer: toldNewer }),
354
441
  });
355
442
  }
356
443
  catch {
357
444
  log("the runner's state could not be written; it goes on from the console's record");
358
445
  }
359
446
  };
447
+ /**
448
+ * When a conversation that begins now is taken to have begun (ADR-0166): now, or, where wakes
449
+ * of a wake source wait to be handed over, a little before the oldest of them was raised.
450
+ * They are handed over in the new conversation, which holds them from then on: counted as
451
+ * from before it, their messages would be carried once more with the next wake. `handed` is
452
+ * what the conversation holds beside what waits: what a session was handed in it already,
453
+ * where the moment is set once the session is under way.
454
+ */
455
+ const beginsAt = (handed = []) => {
456
+ let at = options.now();
457
+ for (const signal of [...pending, ...handed]) {
458
+ const raised = signal.source === "messenger" ? Date.parse(signal.at) : Number.NaN;
459
+ if (Number.isFinite(raised)) {
460
+ at = Math.min(at, raised - RAISED_AFTER_MS);
461
+ }
462
+ }
463
+ return at;
464
+ };
465
+ /**
466
+ * The driver named the conversation its session runs in. Where it began one in place of the
467
+ * one it was asked to go on with (`anew`), the agent's conversation began with the session
468
+ * (ADR-0166): it holds what the session was handed, and nothing from before.
469
+ */
470
+ const converses = (target, event) => {
471
+ conversation = event.id;
472
+ if (event.anew === true) {
473
+ began = beginsAt([...target.sent, ...target.handed.flatMap((message) => message.signals)]);
474
+ above.clear();
475
+ }
476
+ };
477
+ /**
478
+ * The product put the conversation in fewer words (ADR-0166): what the agent was handed
479
+ * before is a summary at best, so what a wake source brought before counts no more, and what
480
+ * the product took is not named as standing there. What it was handed and has not taken yet
481
+ * it reads after, whole: the conversation is taken to hold that.
482
+ */
483
+ const summarized = (target) => {
484
+ began = beginsAt(target.handed.flatMap((message) => message.signals));
485
+ above.clear();
486
+ for (const signal of target.taken.flat()) {
487
+ target.summarized.add(signal.number);
488
+ }
489
+ };
490
+ /**
491
+ * When the agent's conversation began, as a wake source is told it (ADR-0166): never after
492
+ * now. A moment ahead of the clock, kept by a runner whose machine's clock ran ahead or set
493
+ * back since, is none a message was written before: counted from, every wake of a place
494
+ * would carry again what the last one carried, for as long as the clock is behind it. It is
495
+ * taken as now, and kept so.
496
+ */
497
+ const beganBy = () => {
498
+ const now = options.now();
499
+ if (began > now) {
500
+ began = now;
501
+ void persist();
502
+ }
503
+ return began;
504
+ };
505
+ /**
506
+ * Lets go of the conversation kept: the next session begins a new one, which holds nothing
507
+ * the agent was handed before this moment (ADR-0166), but for what waits to be handed over.
508
+ */
509
+ const letGo = () => {
510
+ conversation = undefined;
511
+ began = beginsAt();
512
+ renewed = true;
513
+ above.clear();
514
+ };
515
+ /** Writes what the wake sources keep where it changed since it was last written. */
516
+ const keepKept = async () => {
517
+ const store = options.wakes?.kept;
518
+ if (store === undefined) {
519
+ return;
520
+ }
521
+ for (const [name, kept] of keeps) {
522
+ if (!kept.changed) {
523
+ continue;
524
+ }
525
+ kept.changed = false;
526
+ try {
527
+ await store.save(name, [...kept]);
528
+ }
529
+ catch {
530
+ // Kept in memory still, and written with the next change.
531
+ sayOnce(`kept ${name}`, `what the wake source ${name} keeps could not be written; it is kept while the runner runs`);
532
+ }
533
+ }
534
+ };
360
535
  const setState = (state, reason) => {
361
- stands = { state, reason };
536
+ stands = { state, reason, at: options.now() };
362
537
  push({ t: "heartbeat" });
363
538
  };
364
539
  /** Asks for a delivery after the window that groups what arrives together, or at a moment. */
@@ -774,6 +949,7 @@ export function createRunner(options) {
774
949
  took: false,
775
950
  taken: [],
776
951
  unread: 0,
952
+ summarized: new Set(),
777
953
  returning: false,
778
954
  background: 0,
779
955
  own: false,
@@ -783,12 +959,24 @@ export function createRunner(options) {
783
959
  waiting: 0,
784
960
  refused: false,
785
961
  running: { model: settings.model, effort: settings.effort },
962
+ unknown: [],
963
+ versionSaid: false,
786
964
  written: handed.written,
787
965
  pumped: Promise.resolve(),
788
966
  };
789
967
  started.pumped = pump(started);
790
968
  session = started;
791
969
  renew = false;
970
+ if (resume === undefined) {
971
+ // A conversation of its own: it holds nothing the agent was handed before (ADR-0166).
972
+ // Where it was let go a moment ago, at a reset say, it began then, and what was kept
973
+ // for it since is handed over in it.
974
+ if (!renewed) {
975
+ began = beginsAt();
976
+ }
977
+ above.clear();
978
+ }
979
+ renewed = false;
792
980
  log(`session ${started.id} began${resume === undefined ? "" : ", going on with the conversation before"}`);
793
981
  push({ t: "heartbeat" });
794
982
  return started;
@@ -805,6 +993,9 @@ export function createRunner(options) {
805
993
  }
806
994
  await target.pumped;
807
995
  await hearLast(target);
996
+ // What was named as standing in the conversation was taken by this session's product: a
997
+ // session begun after is said it whole (ADR-0166).
998
+ above.clear();
808
999
  // What the product was handed and never took is sent again, by the console where the
809
1000
  // runner itself ends and by the runner where the product had not started; else it is on
810
1001
  // the record as never read.
@@ -940,7 +1131,7 @@ export function createRunner(options) {
940
1131
  (session === undefined || !goesOn(session)) &&
941
1132
  limited === undefined) {
942
1133
  await end("restarted");
943
- conversation = undefined;
1134
+ letGo();
944
1135
  }
945
1136
  const target = session ?? (await begin());
946
1137
  if (target === undefined) {
@@ -973,6 +1164,11 @@ export function createRunner(options) {
973
1164
  // what the driver says of its product.
974
1165
  const takesPictures = target.driver.images?.() ?? driver.can.images;
975
1166
  for (const signal of batch) {
1167
+ // What is only named is handed over with nothing: its files stand in the desk and its
1168
+ // pictures in the conversation, with the message the product took (ADR-0166).
1169
+ if (above.has(signal.number)) {
1170
+ continue;
1171
+ }
976
1172
  const taken = new Set();
977
1173
  for (const file of signal.attachments) {
978
1174
  const picture = PICTURE_TYPES.has(file.contentType);
@@ -1020,10 +1216,15 @@ export function createRunner(options) {
1020
1216
  ]);
1021
1217
  }
1022
1218
  }
1219
+ // What the conversation holds already, the product having taken it there as the limit was
1220
+ // reached, is named and not said again (ADR-0166).
1221
+ const named = batch.filter((signal) => above.has(signal.number)).length;
1023
1222
  const composed = composeSignals(batch, {
1024
1223
  mark: target.mark,
1025
1224
  time: options.time,
1026
1225
  attached: (signal) => attached.get(signal.number) ?? [],
1226
+ own: options.account,
1227
+ above: (signal) => above.has(signal.number),
1027
1228
  });
1028
1229
  const intro = target.first ? introOf(target.mark, resetBy) : undefined;
1029
1230
  // What the runner says of its own goes ahead of the signals, under its own header: that
@@ -1033,12 +1234,20 @@ export function createRunner(options) {
1033
1234
  const returned = back ? limited : undefined;
1034
1235
  look();
1035
1236
  const told = slept;
1237
+ const newer = newerCommand();
1036
1238
  const text = [
1037
1239
  intro,
1038
1240
  returned === undefined
1039
1241
  ? undefined
1040
- : runnerSays(target.mark, limitWords(returned, { now: options.now(), moment, follow: batch.length, early })),
1242
+ : runnerSays(target.mark, limitWords(returned, {
1243
+ now: options.now(),
1244
+ moment,
1245
+ follow: batch.length - named,
1246
+ above: named,
1247
+ early,
1248
+ })),
1041
1249
  told === undefined ? undefined : sleptOf(told, { mark: target.mark, moment }),
1250
+ newer === undefined ? undefined : runnerSays(target.mark, newer.words),
1042
1251
  composed.text,
1043
1252
  ]
1044
1253
  .filter((part) => part !== undefined)
@@ -1057,6 +1266,12 @@ export function createRunner(options) {
1057
1266
  if (slept === told) {
1058
1267
  slept = undefined;
1059
1268
  }
1269
+ if (newer !== undefined) {
1270
+ // Told once for that version of the console, whichever runner is started after.
1271
+ toldNewer = newer.version;
1272
+ log(`a newer command exists: the console runs ${newer.version}, and this runner runs from ${options.version}; the agent was told, with what installs it`);
1273
+ await persist();
1274
+ }
1060
1275
  if (returned !== undefined) {
1061
1276
  // Handed over, and not yet read: the agent stands as stopped until it answers.
1062
1277
  returned.handed = true;
@@ -1156,7 +1371,9 @@ export function createRunner(options) {
1156
1371
  * Hears what the product said as its session was ended. Its words wait in the queue behind
1157
1372
  * whatever ended the session, and are let go there once the session is no longer the open
1158
1373
  * one: a message it said it took then is taken, and not sent again, and the conversation it
1159
- * named is the one to go on with, where that message is.
1374
+ * named is the one to go on with, where that message is. That it began that conversation
1375
+ * anew, or put it in fewer words, moves the moment the conversation began as it does in a
1376
+ * session that goes on (ADR-0166): the next session goes on with what was said here.
1160
1377
  */
1161
1378
  const hearLast = async (target) => {
1162
1379
  let named = false;
@@ -1166,7 +1383,11 @@ export function createRunner(options) {
1166
1383
  }
1167
1384
  const { event } = message;
1168
1385
  if (event.type === "conversation") {
1169
- conversation = event.id;
1386
+ converses(target, event);
1387
+ named = true;
1388
+ }
1389
+ else if (event.type === "compacted") {
1390
+ summarized(target);
1170
1391
  named = true;
1171
1392
  }
1172
1393
  else if (event.type === "taken") {
@@ -1357,7 +1578,7 @@ export function createRunner(options) {
1357
1578
  limited = undefined;
1358
1579
  await end(signal.kind === "reset" ? "reset" : "restarted");
1359
1580
  if (signal.kind === "reset") {
1360
- conversation = undefined;
1581
+ letGo();
1361
1582
  resetBy = { by, ...(signal.text.trim().length > 0 ? { number: signal.number } : {}) };
1362
1583
  // What a product was handed and never took is tried once more, in the new
1363
1584
  // conversation: a product that does not start with it again is not sent it a
@@ -1464,6 +1685,17 @@ export function createRunner(options) {
1464
1685
  for (const signal of untaken) {
1465
1686
  owed.delete(signal.number);
1466
1687
  }
1688
+ // What the product took stands in the conversation, which the agent goes on in: handed
1689
+ // over again in this session, it is named and not said a second time (ADR-0166). Only
1690
+ // where the driver vouches that what it said was taken stands there, and not for what was
1691
+ // taken before the product put the conversation in fewer words.
1692
+ if (driver.can.holdsTaken === true) {
1693
+ for (const signal of unanswered) {
1694
+ if (!target.summarized.has(signal.number)) {
1695
+ above.add(signal.number);
1696
+ }
1697
+ }
1698
+ }
1467
1699
  target.taken = [];
1468
1700
  target.sent = [];
1469
1701
  target.returning = false;
@@ -1568,7 +1800,7 @@ export function createRunner(options) {
1568
1800
  return;
1569
1801
  }
1570
1802
  await end("reset");
1571
- conversation = undefined;
1803
+ letGo();
1572
1804
  // Where a supervisor reset the agent meanwhile, the first message says so: the account's
1573
1805
  // words are read under their own header all the same.
1574
1806
  resetBy ??= {
@@ -1581,6 +1813,60 @@ export function createRunner(options) {
1581
1813
  setState("running", "reset");
1582
1814
  scheduleDeliver();
1583
1815
  };
1816
+ /**
1817
+ * What is said of the product's version where the driver was not tried with it (ADR-0182),
1818
+ * or nothing: where it was, where the product said no version, and for a driver that names
1819
+ * no version it was tried with, a protocol's say, which is held to the protocol and to no
1820
+ * build. Said where something went wrong and never as a standing word of the account: a
1821
+ * product updates itself every few days and works on, and a line that always stands is read
1822
+ * by nobody.
1823
+ */
1824
+ const untried = () => {
1825
+ const version = lineOf(productVersion ?? probe.version ?? null);
1826
+ const { name, tried } = driver.product;
1827
+ const newest = tried.at(-1);
1828
+ return version === null || newest === undefined || tried.includes(version)
1829
+ ? undefined
1830
+ : `${name} ${version} is a version the driver was not tried with (the newest it was tried with is ${newest})`;
1831
+ };
1832
+ /**
1833
+ * The driver had no reading for something the product wrote (ADR-0182). In the runner's own
1834
+ * lines once for a kind in a session, whatever the version. On the record once for a kind,
1835
+ * whichever session first met it, and only under a version the driver was not tried with:
1836
+ * there it may be why the agent is not heard as it should be, and whoever reads the record
1837
+ * for that finds it where it happened.
1838
+ */
1839
+ const meetsUnknown = async (target, what) => {
1840
+ if (target.unknown.includes(what)) {
1841
+ return;
1842
+ }
1843
+ target.unknown.push(what);
1844
+ const version = untried();
1845
+ log(`the product wrote ${what}, which the driver does not read${version === undefined ? "" : `; ${version}`}`);
1846
+ if (version === undefined || unknownSaid.has(what) || unknownSaid.size >= MAX_UNKNOWN_SAID) {
1847
+ return;
1848
+ }
1849
+ unknownSaid.add(what);
1850
+ record(target, "status", `The product wrote ${what}, which the driver does not read: something it says may be missed. ${version}. A newer console command may know it.`, { unknown: what });
1851
+ await persist();
1852
+ };
1853
+ /**
1854
+ * The product failed, or its session ended as none should: where the driver was not tried
1855
+ * with the product's version, the record says that the version may be why (ADR-0182), once
1856
+ * in a session, with what the driver had no reading for in it.
1857
+ */
1858
+ const versionMayBeWhy = (target) => {
1859
+ const version = untried();
1860
+ if (version === undefined || target.versionSaid) {
1861
+ return;
1862
+ }
1863
+ target.versionSaid = true;
1864
+ const met = target.unknown.length === 0
1865
+ ? ""
1866
+ : ` In this session it wrote what the driver does not read: ${target.unknown.slice(0, MAX_UNKNOWN_NAMED).join("; ")}${target.unknown.length > MAX_UNKNOWN_NAMED ? ", and more" : ""}.`;
1867
+ record(target, "status", `The product's version may be why: ${version}.${met} A newer console command may know it.`, { untried: true });
1868
+ log(`the product's version may be why the agent could not go on: ${version}`);
1869
+ };
1584
1870
  const onDriver = async (target, event, unread = 0) => {
1585
1871
  if (target !== session) {
1586
1872
  return;
@@ -1597,7 +1883,7 @@ export function createRunner(options) {
1597
1883
  return;
1598
1884
  }
1599
1885
  case "conversation": {
1600
- conversation = event.id;
1886
+ converses(target, event);
1601
1887
  await persist();
1602
1888
  return;
1603
1889
  }
@@ -1617,6 +1903,8 @@ export function createRunner(options) {
1617
1903
  }
1618
1904
  target.sent = [];
1619
1905
  target.returning = false;
1906
+ // The agent is done with all it was handed: nothing of it is owed a second saying.
1907
+ above.clear();
1620
1908
  if (limited !== undefined) {
1621
1909
  // A turn completed: whatever stopped the agent is over.
1622
1910
  limited = undefined;
@@ -1634,11 +1922,20 @@ export function createRunner(options) {
1634
1922
  }
1635
1923
  return;
1636
1924
  }
1925
+ case "compacted": {
1926
+ summarized(target);
1927
+ await persist();
1928
+ return;
1929
+ }
1637
1930
  case "usage": {
1638
1931
  noteUsage(usageSeen, event.windows, options.now());
1639
1932
  await onUsage(target, event.windows);
1640
1933
  return;
1641
1934
  }
1935
+ case "unknown": {
1936
+ await meetsUnknown(target, event.what);
1937
+ return;
1938
+ }
1642
1939
  case "cannot_go_on": {
1643
1940
  // Reported, and nothing restarted: a supervisor's signal is tried at once, the rest after the cool-down.
1644
1941
  target.turn = false;
@@ -1687,6 +1984,10 @@ export function createRunner(options) {
1687
1984
  target.sent = [];
1688
1985
  waits = cooled(waits);
1689
1986
  setState(event.state, event.reason);
1987
+ // The product failed, and no sign-in or model's refusal is why: its version may be.
1988
+ if (event.reason === "crashed" || event.reason === "start") {
1989
+ versionMayBeWhy(target);
1990
+ }
1690
1991
  if (pending.length > 0) {
1691
1992
  scheduleDeliver(waits.until);
1692
1993
  }
@@ -1707,6 +2008,13 @@ export function createRunner(options) {
1707
2008
  ...pending,
1708
2009
  ].sort((one, other) => one.number - other.number);
1709
2010
  }
2011
+ // An end as none should be, which nothing the product said explains: not after a
2012
+ // usage limit, a sign-in that ran out or a model's refusal, which say why themselves.
2013
+ if (event.how === "crashed" &&
2014
+ limited === undefined &&
2015
+ !["usage_limit", "sign_in", "model_refused"].includes(stands.reason)) {
2016
+ versionMayBeWhy(target);
2017
+ }
1710
2018
  await end(event.how, true);
1711
2019
  // A product that ended before it answered the word that it is back, or refused it, was
1712
2020
  // not brought back: the word is owed still, at the moment the runner waits for, or
@@ -1745,6 +2053,39 @@ export function createRunner(options) {
1745
2053
  images: driver.can.images,
1746
2054
  resume: driver.can.resume,
1747
2055
  });
2056
+ /**
2057
+ * What the agent is told of a newer command (ADR-0182), or nothing: the console runs a
2058
+ * version newer than the one the runner runs from, within what it takes, and the agent was
2059
+ * not told of that version or of a newer one yet: a console that goes back, or two of one
2060
+ * deployment that answer in turn, tell nothing again. Said with the next message the agent is handed, ahead of
2061
+ * it and under the runner's own header: a turn begins with that message anyway, so none is
2062
+ * begun for an update, and an agent with nothing to do is told when it next has. Nothing
2063
+ * while the package on the machine is another version already, which the runner ends for by
2064
+ * itself. Nothing installs anything: the agent does, and the runner sees it (ADR-0101).
2065
+ */
2066
+ const newerCommand = () => {
2067
+ const seen = options.consoleVersion?.();
2068
+ const theirs = parseVersion(seen);
2069
+ const own = parseVersion(options.version);
2070
+ if (seen === undefined || theirs === undefined || own === undefined) {
2071
+ return undefined;
2072
+ }
2073
+ const told = parseVersion(toldNewer);
2074
+ if (told !== undefined && compareVersions(theirs, told) <= 0) {
2075
+ return undefined;
2076
+ }
2077
+ if (updatedTo !== undefined || seenVersion !== undefined) {
2078
+ return undefined;
2079
+ }
2080
+ const install = options.updateCommand?.();
2081
+ if (install === undefined || judgeClient(own, theirs).verdict !== "behind") {
2082
+ return undefined;
2083
+ }
2084
+ return {
2085
+ version: seen,
2086
+ words: `A newer command exists: the console runs ${seen}, and this runner runs from ${options.version}. Nothing is refused meanwhile. Update it once what you are at allows: ${install}\n${UPDATE_FOLLOWS}\n${UPDATE_OTHERWISE}`,
2087
+ };
2088
+ };
1748
2089
  /**
1749
2090
  * Says something of the runner's own to the agent, in the open session, under a header that
1750
2091
  * carries the session's mark: read after the tool call under way. The agent has a turn's work
@@ -1789,22 +2130,142 @@ export function createRunner(options) {
1789
2130
  push({ t: "heartbeat" });
1790
2131
  }
1791
2132
  };
2133
+ /**
2134
+ * Whether the agent is thinking over what a wake source raised (ADR-0170): the turn a wake
2135
+ * of that source's was handed over in is under way, or one is on its way to the agent, a
2136
+ * message the source took and reads for, a wake raised and not back on the stream yet, or
2137
+ * one waiting to be handed over. What waits is nothing the agent thinks over while nothing
2138
+ * is handed over at all, a supervisor's stop standing or the agent unable to go on.
2139
+ */
2140
+ const thinksOf = (name, now) => {
2141
+ const own = (signal) => signal.kind === "wake" &&
2142
+ signal.source === "messenger" &&
2143
+ signal.key?.startsWith(`${name}:`) === true;
2144
+ if (session?.turn === true && session.sent.some(own)) {
2145
+ return true;
2146
+ }
2147
+ if (held || waits !== undefined) {
2148
+ return false;
2149
+ }
2150
+ const raised = raising.get(name);
2151
+ for (const one of raised ?? []) {
2152
+ // Back on the stream, and among what waits from then on; or never to come, for all the
2153
+ // runner waits for it.
2154
+ if ((one.number !== undefined && one.number <= handled) || now - one.at >= RAISED_MS) {
2155
+ raised?.delete(one);
2156
+ }
2157
+ }
2158
+ return (raised?.size ?? 0) > 0 || pending.some(own);
2159
+ };
2160
+ /**
2161
+ * How the agent stands to whoever waits for it at a wake source (ADR-0170). Its usage limit
2162
+ * first, until the moment the product named where it named one: nothing is answered before
2163
+ * it, whatever else goes on, and past it the runner brings the agent back in a turn as any
2164
+ * other. Then that it has been at work for longer than `runner.json` gives a turn, whatever
2165
+ * woke it; then that it thinks over what this source raised.
2166
+ */
2167
+ const statusFor = (name, now) => {
2168
+ if (limited !== undefined && (limited.until === undefined || now < limited.until)) {
2169
+ return limited.until === undefined
2170
+ ? { state: "limited" }
2171
+ : { state: "limited", until: limited.until };
2172
+ }
2173
+ if (atWorkSince !== undefined &&
2174
+ shownAs !== false &&
2175
+ now - atWorkSince >= (shownAs.after ?? STATUS_AFTER) * 1000) {
2176
+ return { state: "working" };
2177
+ }
2178
+ return { state: thinksOf(name, now) ? "thinking" : "idle" };
2179
+ };
2180
+ /**
2181
+ * A moment as a status says one: the hour and the minute in the workspace's zone, and with
2182
+ * its day where it is most of a day away, as the command writes a moment's.
2183
+ */
2184
+ const statusTime = (at) => {
2185
+ const iso = new Date(at).toISOString();
2186
+ const written = moment(iso);
2187
+ const day = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(written);
2188
+ return at - options.now() < FAR_MS || day === null
2189
+ ? options.time(iso)
2190
+ : `${day[1]} ${day[2]}${written.endsWith("Z") ? " UTC" : ""}`;
2191
+ };
2192
+ /** Says to a wake source how the agent stands. What the source cannot show costs the agent nothing. */
2193
+ const say = (one, status, signal) => Promise.resolve()
2194
+ .then(() => one.source.show?.(one.host, status, {
2195
+ words: shownAs === false ? {} : shownAs,
2196
+ language: options.language,
2197
+ now: options.now,
2198
+ time: statusTime,
2199
+ signal,
2200
+ }))
2201
+ .catch((error) => {
2202
+ sayOnce(`status ${one.source.name}`, `the wake source ${one.source.name} could not show how the agent stands (${codeOf(error)})`);
2203
+ });
2204
+ /**
2205
+ * Has the wake sources show how the agent stands (ADR-0170): each is said when that changed,
2206
+ * and again every heartbeat while it stands, so that a source keeps what it shows from
2207
+ * lapsing. Nothing is said where `runner.json` turned it off.
2208
+ */
2209
+ const showStatus = () => {
2210
+ if (shownAs === false) {
2211
+ return;
2212
+ }
2213
+ const now = options.now();
2214
+ const active = session !== undefined && (session.turn || goesOn(session));
2215
+ atWorkSince = active ? (atWorkSince ?? now) : undefined;
2216
+ for (const [name, one] of shows) {
2217
+ const status = statusFor(name, now);
2218
+ const word = `${status.state} ${status.state === "limited" ? (status.until ?? "") : ""}`;
2219
+ if (word === one.said && now - one.at < timing.heartbeatMs) {
2220
+ continue;
2221
+ }
2222
+ one.said = word;
2223
+ one.at = now;
2224
+ void say(one, status, abort.signal);
2225
+ }
2226
+ };
2227
+ /**
2228
+ * The last thing the sources are said: nothing to show, as the runner ends, so that what they
2229
+ * showed is taken back. Waited for a few seconds and no longer: a messenger that does not
2230
+ * answer holds no runner's end, and what stays there ends by itself.
2231
+ */
2232
+ const showLast = async () => {
2233
+ if (shownAs === false || shows.size === 0) {
2234
+ return;
2235
+ }
2236
+ const ending = new AbortController();
2237
+ const over = new Promise((resolve) => {
2238
+ ending.signal.addEventListener("abort", () => resolve(), { once: true });
2239
+ });
2240
+ const timer = setTimeout(() => ending.abort(), SHOWN_END_MS);
2241
+ await Promise.race([
2242
+ Promise.all([...shows.values()].map((one) => say(one, LAST_STATUS, ending.signal))),
2243
+ over,
2244
+ ]);
2245
+ clearTimeout(timer);
2246
+ ending.abort();
2247
+ };
1792
2248
  /**
1793
2249
  * Why the agent stands as it does, and until when where the runner knows: when its usage
1794
2250
  * limit resets. A console of before the word `usage_limit` refuses a heartbeat that says it,
1795
2251
  * and with it everything else the heartbeat carries: such a console is said `crashed`, the
1796
- * nearest word it takes, and no moment.
2252
+ * nearest word it takes, and no moment. With it, when the runner said so, which a console of
2253
+ * before reads past.
1797
2254
  */
1798
2255
  const saidOfState = () => {
2256
+ // A moment kept by a runner before this one is taken as it reads; one that is no moment is now.
2257
+ const at = Number.isFinite(stands.at) && Math.abs(stands.at) <= 8.64e15 ? stands.at : options.now();
2258
+ const reasonAt = new Date(at).toISOString();
1799
2259
  if (stands.reason !== "usage_limit") {
1800
- return { reason: stands.reason };
2260
+ return { reason: stands.reason, reasonAt };
1801
2261
  }
1802
2262
  if (plainWords) {
1803
- return { reason: "crashed" };
2263
+ return { reason: "crashed", reasonAt };
1804
2264
  }
1805
2265
  return {
1806
2266
  reason: stands.reason,
1807
2267
  until: limited?.until === undefined ? null : new Date(limited.until).toISOString(),
2268
+ reasonAt,
1808
2269
  };
1809
2270
  };
1810
2271
  /**
@@ -1853,7 +2314,7 @@ export function createRunner(options) {
1853
2314
  if (answer.state === "stopped" && !held && answer.latest <= handled) {
1854
2315
  held = true;
1855
2316
  await end("stopped");
1856
- stands = { state: "stopped", reason: "stop" };
2317
+ stands = { state: "stopped", reason: "stop", at: options.now() };
1857
2318
  }
1858
2319
  }
1859
2320
  catch (error) {
@@ -1876,12 +2337,10 @@ export function createRunner(options) {
1876
2337
  // runner then sees and starts again for; and whom to tell where it cannot.
1877
2338
  if (session !== undefined && !session.first) {
1878
2339
  const target = session;
1879
- const update = install === undefined
1880
- ? ""
1881
- : ` Update it: ${install}\nThe runner sees the update and is started again with it by itself, once no turn is under way.`;
2340
+ const update = install === undefined ? "" : ` Update it: ${install}\n${UPDATE_FOLLOWS}`;
1882
2341
  // Not told where it could not be: the runner's own line above says it to whoever
1883
2342
  // reads its output.
1884
- await sayToAgent(target, `The console no longer takes this version of the command the runner runs from, and hears nothing of this session until it is updated.${update}\nWhere you cannot update it, say so to whom you report to.`);
2343
+ await sayToAgent(target, `The console no longer takes this version of the command the runner runs from, and hears nothing of this session until it is updated.${update}\n${UPDATE_OTHERWISE}`);
1885
2344
  }
1886
2345
  }
1887
2346
  return;
@@ -1994,6 +2453,20 @@ export function createRunner(options) {
1994
2453
  if (source.run === undefined || wakes === undefined) {
1995
2454
  return;
1996
2455
  }
2456
+ // What the source kept under a runner before this one, where the machine keeps it
2457
+ // (ADR-0166): the ids and the moments of what it brought, so that a runner started again
2458
+ // says nothing a second time. What does not read is nothing kept.
2459
+ const kept = new Kept();
2460
+ try {
2461
+ for (const [name, value] of (await wakes.kept?.load(source.name)) ?? []) {
2462
+ kept.set(name, value);
2463
+ }
2464
+ }
2465
+ catch {
2466
+ log(`what the wake source ${source.name} kept could not be read; it begins with nothing`);
2467
+ }
2468
+ kept.changed = false;
2469
+ keeps.set(source.name, kept);
1997
2470
  const host = {
1998
2471
  secret: async (name) => secretValues.get(name),
1999
2472
  channels: options.config.channels ?? [],
@@ -2008,10 +2481,21 @@ export function createRunner(options) {
2008
2481
  // what someone else wrote, and a text with no line of the source's as words whole, so
2009
2482
  // that no word of a message reads as a line of the source's when the signal returns.
2010
2483
  const text = wakeTextOf("parts" in raised ? raised.parts : [{ words: raised.text }]);
2484
+ // On its way to the agent from here, which the source shows (ADR-0170): until the
2485
+ // stream brings it back, or the console did not take it.
2486
+ const underWay = {
2487
+ at: options.now(),
2488
+ number: undefined,
2489
+ };
2490
+ const others = raising.get(source.name) ?? new Set();
2491
+ raising.set(source.name, others.add(underWay));
2492
+ push({ t: "shown" });
2011
2493
  try {
2012
- await client.raiseWake({ source: "messenger", key: raised.key, text });
2494
+ underWay.number = (await client.raiseWake({ source: "messenger", key: raised.key, text })).number;
2013
2495
  }
2014
2496
  catch (error) {
2497
+ others.delete(underWay);
2498
+ push({ t: "shown" });
2015
2499
  if (codeOf(error) !== "signal.too_many") {
2016
2500
  throw error;
2017
2501
  }
@@ -2026,7 +2510,29 @@ export function createRunner(options) {
2026
2510
  }
2027
2511
  return true;
2028
2512
  },
2029
- kept: new Map(),
2513
+ // Taken by the source, and on its way to the agent before any wake of it went up
2514
+ // (ADR-0170): shown from here, until the source says the wake was raised or will not be.
2515
+ heard: () => {
2516
+ // A message whose wake the console takes none of for a while is let go when it is
2517
+ // raised (ADR-0132): it reaches no agent, and nothing shows the agent thinking it over.
2518
+ if (wakesHeld !== undefined && options.now() < wakesHeld.until) {
2519
+ return () => undefined;
2520
+ }
2521
+ const taken = {
2522
+ at: options.now(),
2523
+ number: undefined,
2524
+ };
2525
+ const others = raising.get(source.name) ?? new Set();
2526
+ raising.set(source.name, others.add(taken));
2527
+ push({ t: "shown" });
2528
+ return () => {
2529
+ if (others.delete(taken)) {
2530
+ push({ t: "shown" });
2531
+ }
2532
+ };
2533
+ },
2534
+ kept,
2535
+ began: beganBy,
2030
2536
  log,
2031
2537
  stands: (state, why) => sourceStands(source.name, state, why),
2032
2538
  fetch: wakes.fetch,
@@ -2043,9 +2549,12 @@ export function createRunner(options) {
2043
2549
  }),
2044
2550
  };
2045
2551
  sourceStands(source.name, "waiting");
2552
+ if (source.show !== undefined) {
2553
+ shows.set(source.name, { source, host, said: "", at: 0 });
2554
+ }
2046
2555
  let wait = timing.reconnectMs;
2047
2556
  while (!stopped) {
2048
- const began = options.now();
2557
+ const startedAt = options.now();
2049
2558
  try {
2050
2559
  await source.run(host, abort.signal);
2051
2560
  // Ended with no error, a connection the other side closed say: it listens no more
@@ -2061,7 +2570,7 @@ export function createRunner(options) {
2061
2570
  }
2062
2571
  }
2063
2572
  wait =
2064
- options.now() - began >= SOURCE_HELD_MS
2573
+ options.now() - startedAt >= SOURCE_HELD_MS
2065
2574
  ? timing.reconnectMs
2066
2575
  : Math.min(wait * 2, MAX_SOURCE_PAUSE_MS);
2067
2576
  await pause(wait);
@@ -2103,10 +2612,13 @@ export function createRunner(options) {
2103
2612
  const kept = await options.state.load().catch(() => undefined);
2104
2613
  delivered = kept?.delivered ?? 0;
2105
2614
  conversation = kept?.conversation;
2615
+ // A moment after now is none the conversation began at: held to the clock here, and
2616
+ // wherever a wake source asks.
2617
+ began = Math.min(kept?.began ?? 0, options.now());
2106
2618
  if (conversation !== undefined && kept?.driver !== undefined && kept.driver !== driver.name) {
2107
2619
  // Another product's conversation is nothing this one can go on with: asked to, it fails
2108
2620
  // at every turn until a supervisor resets it.
2109
- conversation = undefined;
2621
+ letGo();
2110
2622
  log(`the conversation kept was begun under the driver ${kept.driver}: a new one begins under ${driver.name}`);
2111
2623
  }
2112
2624
  // What a runner before this one held for the agent alone is taken from the stream once
@@ -2116,6 +2628,10 @@ export function createRunner(options) {
2116
2628
  for (const number of kept?.kept ?? []) {
2117
2629
  reread.add(number);
2118
2630
  }
2631
+ for (const what of (kept?.unknown ?? []).slice(-MAX_UNKNOWN_SAID)) {
2632
+ unknownSaid.add(what);
2633
+ }
2634
+ toldNewer = kept?.newer;
2119
2635
  if (kept?.limited !== undefined) {
2120
2636
  // A usage limit stopped the agent under a runner before this one: it is brought back
2121
2637
  // all the same, when the limit resets or after the cool-down where no moment is known.
@@ -2128,9 +2644,14 @@ export function createRunner(options) {
2128
2644
  tries: 1,
2129
2645
  until: known === undefined ? now + timing.coolDownMs : known + timing.resetMarginMs,
2130
2646
  };
2131
- stands = { state: "failed", reason: "usage_limit" };
2647
+ // Said as of when the limit was reached, which the runner before this one kept.
2648
+ stands = { state: "failed", reason: "usage_limit", at: kept.limited.since };
2132
2649
  log(`the product's usage limit stopped the agent before this runner started: tried again at ${new Date(waits.until).toISOString()}`);
2133
2650
  }
2651
+ if ((kept?.began ?? 0) > began) {
2652
+ // Kept as it is taken, once everything else the file said is in place again.
2653
+ await persist();
2654
+ }
2134
2655
  probe = await driver.probe();
2135
2656
  const left = probe.models.length +
2136
2657
  probe.efforts.length -
@@ -2158,7 +2679,7 @@ export function createRunner(options) {
2158
2679
  delivered = Math.max(delivered, first.delivered);
2159
2680
  if (first.state === "stopped") {
2160
2681
  held = true;
2161
- stands = { state: "stopped", reason: "stop" };
2682
+ stands = { state: "stopped", reason: "stop", at: options.now() };
2162
2683
  }
2163
2684
  break;
2164
2685
  }
@@ -2233,6 +2754,10 @@ export function createRunner(options) {
2233
2754
  if (session !== undefined) {
2234
2755
  await flush(session);
2235
2756
  }
2757
+ await keepKept();
2758
+ }
2759
+ else if (message.t === "shown") {
2760
+ // Looked at below, as after anything else.
2236
2761
  }
2237
2762
  else {
2238
2763
  // A timer counts no time the machine sleeps in, and rings late by as much: what
@@ -2285,6 +2810,9 @@ export function createRunner(options) {
2285
2810
  catch (error) {
2286
2811
  log(`the runner could not do what it was about to (${codeOf(error)}); it goes on`);
2287
2812
  }
2813
+ // Whatever was done may have changed how the agent stands to whoever waits for it,
2814
+ // and so does the time that passed: looked at once a second at the least.
2815
+ showStatus();
2288
2816
  }
2289
2817
  }
2290
2818
  finally {
@@ -2294,12 +2822,18 @@ export function createRunner(options) {
2294
2822
  for (const timer of timers) {
2295
2823
  clearTimeout(timer);
2296
2824
  }
2825
+ // What the wake sources showed of the agent is taken back while its session ends
2826
+ // (ADR-0170): a runner that is gone shows nothing.
2827
+ const shown = showLast();
2297
2828
  // A session ended for an update goes on, in the runner started after, as one a
2298
2829
  // supervisor restarted does: with the same conversation.
2299
2830
  await end(how === "stopped" ? "exited" : "restarted");
2831
+ await shown;
2300
2832
  abort.abort();
2301
2833
  await listening;
2302
2834
  await Promise.all(sourcing);
2835
+ // What the sources raised as they ended is kept too.
2836
+ await keepKept();
2303
2837
  log(how === "updated"
2304
2838
  ? "the runner ended, for the update"
2305
2839
  : how === "changed"