@skillcdn/console 0.5.1 → 0.5.2

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 (288) hide show
  1. package/README.md +20 -2
  2. package/dist/agent-page.d.ts.map +1 -1
  3. package/dist/agent-page.js +4 -4
  4. package/dist/agent-page.js.map +1 -1
  5. package/dist/api.d.ts +5 -4
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +5 -4
  8. package/dist/api.js.map +1 -1
  9. package/dist/cli/cli.d.ts +32 -0
  10. package/dist/cli/cli.d.ts.map +1 -1
  11. package/dist/cli/cli.js +442 -93
  12. package/dist/cli/cli.js.map +1 -1
  13. package/dist/cli/format.d.ts +6 -2
  14. package/dist/cli/format.d.ts.map +1 -1
  15. package/dist/cli/format.js +25 -3
  16. package/dist/cli/format.js.map +1 -1
  17. package/dist/cli/help.d.ts.map +1 -1
  18. package/dist/cli/help.js +10 -5
  19. package/dist/cli/help.js.map +1 -1
  20. package/dist/cli/machine-check.d.ts +36 -0
  21. package/dist/cli/machine-check.d.ts.map +1 -0
  22. package/dist/cli/machine-check.js +151 -0
  23. package/dist/cli/machine-check.js.map +1 -0
  24. package/dist/cli/runner-host.d.ts +7 -0
  25. package/dist/cli/runner-host.d.ts.map +1 -1
  26. package/dist/cli/runner-host.js +2 -0
  27. package/dist/cli/runner-host.js.map +1 -1
  28. package/dist/cli/secret-notes.d.ts +8 -0
  29. package/dist/cli/secret-notes.d.ts.map +1 -0
  30. package/dist/cli/secret-notes.js +48 -0
  31. package/dist/cli/secret-notes.js.map +1 -0
  32. package/dist/client.d.ts +7 -1
  33. package/dist/client.d.ts.map +1 -1
  34. package/dist/client.js +6 -1
  35. package/dist/client.js.map +1 -1
  36. package/dist/components/agent-page.d.ts +106 -13
  37. package/dist/components/agent-page.d.ts.map +1 -1
  38. package/dist/components/agent-page.js +391 -102
  39. package/dist/components/agent-page.js.map +1 -1
  40. package/dist/components/agents.d.ts.map +1 -1
  41. package/dist/components/agents.js +1 -1
  42. package/dist/components/agents.js.map +1 -1
  43. package/dist/components/board.d.ts.map +1 -1
  44. package/dist/components/board.js +3 -2
  45. package/dist/components/board.js.map +1 -1
  46. package/dist/components/categories.js +1 -1
  47. package/dist/components/categories.js.map +1 -1
  48. package/dist/components/decision-list.d.ts.map +1 -1
  49. package/dist/components/decision-list.js +1 -1
  50. package/dist/components/decision-list.js.map +1 -1
  51. package/dist/components/event-feed.d.ts.map +1 -1
  52. package/dist/components/event-feed.js +3 -2
  53. package/dist/components/event-feed.js.map +1 -1
  54. package/dist/components/goals.d.ts +2 -0
  55. package/dist/components/goals.d.ts.map +1 -1
  56. package/dist/components/goals.js +1 -1
  57. package/dist/components/goals.js.map +1 -1
  58. package/dist/components/home.d.ts.map +1 -1
  59. package/dist/components/home.js +12 -6
  60. package/dist/components/home.js.map +1 -1
  61. package/dist/components/icon.d.ts +31 -0
  62. package/dist/components/icon.d.ts.map +1 -0
  63. package/dist/components/icon.js +169 -0
  64. package/dist/components/icon.js.map +1 -0
  65. package/dist/components/markdown.d.ts +6 -0
  66. package/dist/components/markdown.d.ts.map +1 -1
  67. package/dist/components/markdown.js +10 -2
  68. package/dist/components/markdown.js.map +1 -1
  69. package/dist/components/people.js +1 -1
  70. package/dist/components/people.js.map +1 -1
  71. package/dist/components/plugin-frame.d.ts.map +1 -1
  72. package/dist/components/plugin-frame.js +7 -0
  73. package/dist/components/plugin-frame.js.map +1 -1
  74. package/dist/components/projects.d.ts +17 -4
  75. package/dist/components/projects.d.ts.map +1 -1
  76. package/dist/components/projects.js +25 -6
  77. package/dist/components/projects.js.map +1 -1
  78. package/dist/components/sessions.d.ts.map +1 -1
  79. package/dist/components/sessions.js +3 -2
  80. package/dist/components/sessions.js.map +1 -1
  81. package/dist/components/setup.d.ts.map +1 -1
  82. package/dist/components/setup.js +2 -2
  83. package/dist/components/setup.js.map +1 -1
  84. package/dist/components/shell.d.ts.map +1 -1
  85. package/dist/components/shell.js +3 -2
  86. package/dist/components/shell.js.map +1 -1
  87. package/dist/components/tokens.js +1 -1
  88. package/dist/components/tokens.js.map +1 -1
  89. package/dist/components/ui.d.ts +5 -2
  90. package/dist/components/ui.d.ts.map +1 -1
  91. package/dist/components/ui.js +10 -7
  92. package/dist/components/ui.js.map +1 -1
  93. package/dist/connect-page.js +1 -1
  94. package/dist/connect-page.js.map +1 -1
  95. package/dist/console.css +473 -77
  96. package/dist/console.d.ts.map +1 -1
  97. package/dist/console.js +38 -31
  98. package/dist/console.js.map +1 -1
  99. package/dist/home-tiles.d.ts +9 -0
  100. package/dist/home-tiles.d.ts.map +1 -1
  101. package/dist/home-tiles.js +105 -23
  102. package/dist/home-tiles.js.map +1 -1
  103. package/dist/i18n/en.d.ts +48 -1
  104. package/dist/i18n/en.d.ts.map +1 -1
  105. package/dist/i18n/en.js +125 -2
  106. package/dist/i18n/en.js.map +1 -1
  107. package/dist/i18n/ko.d.ts.map +1 -1
  108. package/dist/i18n/ko.js +197 -79
  109. package/dist/i18n/ko.js.map +1 -1
  110. package/dist/i18n/particles.d.ts +7 -0
  111. package/dist/i18n/particles.d.ts.map +1 -0
  112. package/dist/i18n/particles.js +72 -0
  113. package/dist/i18n/particles.js.map +1 -0
  114. package/dist/icons/glyphs.d.ts +605 -0
  115. package/dist/icons/glyphs.d.ts.map +1 -0
  116. package/dist/icons/glyphs.js +104 -0
  117. package/dist/icons/glyphs.js.map +1 -0
  118. package/dist/icons/index.d.ts +59 -0
  119. package/dist/icons/index.d.ts.map +1 -0
  120. package/dist/icons/index.js +157 -0
  121. package/dist/icons/index.js.map +1 -0
  122. package/dist/index.d.ts +1 -0
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +1 -0
  125. package/dist/index.js.map +1 -1
  126. package/dist/limits.d.ts +9 -0
  127. package/dist/limits.d.ts.map +1 -1
  128. package/dist/limits.js +9 -0
  129. package/dist/limits.js.map +1 -1
  130. package/dist/marks.d.ts +9 -0
  131. package/dist/marks.d.ts.map +1 -1
  132. package/dist/marks.js +9 -0
  133. package/dist/marks.js.map +1 -1
  134. package/dist/onboarding.js +3 -3
  135. package/dist/onboarding.js.map +1 -1
  136. package/dist/plugin/web.d.ts +3 -0
  137. package/dist/plugin/web.d.ts.map +1 -1
  138. package/dist/plugin/web.js +5 -1
  139. package/dist/plugin/web.js.map +1 -1
  140. package/dist/runner/acp.d.ts.map +1 -1
  141. package/dist/runner/acp.js +2 -2
  142. package/dist/runner/acp.js.map +1 -1
  143. package/dist/runner/awake.d.ts +35 -0
  144. package/dist/runner/awake.d.ts.map +1 -0
  145. package/dist/runner/awake.js +95 -0
  146. package/dist/runner/awake.js.map +1 -0
  147. package/dist/runner/claude.d.ts.map +1 -1
  148. package/dist/runner/claude.js +19 -7
  149. package/dist/runner/claude.js.map +1 -1
  150. package/dist/runner/codex.d.ts.map +1 -1
  151. package/dist/runner/codex.js +2 -2
  152. package/dist/runner/codex.js.map +1 -1
  153. package/dist/runner/config.d.ts +5 -0
  154. package/dist/runner/config.d.ts.map +1 -1
  155. package/dist/runner/config.js +9 -0
  156. package/dist/runner/config.js.map +1 -1
  157. package/dist/runner/desk.d.ts.map +1 -1
  158. package/dist/runner/desk.js +5 -6
  159. package/dist/runner/desk.js.map +1 -1
  160. package/dist/runner/runner.d.ts +13 -2
  161. package/dist/runner/runner.d.ts.map +1 -1
  162. package/dist/runner/runner.js +141 -22
  163. package/dist/runner/runner.js.map +1 -1
  164. package/dist/runner/slack.d.ts.map +1 -1
  165. package/dist/runner/slack.js +10 -4
  166. package/dist/runner/slack.js.map +1 -1
  167. package/dist/runner/types.d.ts +15 -0
  168. package/dist/runner/types.d.ts.map +1 -1
  169. package/dist/runner/types.js +9 -0
  170. package/dist/runner/types.js.map +1 -1
  171. package/dist/schemas.d.ts +94 -1
  172. package/dist/schemas.d.ts.map +1 -1
  173. package/dist/schemas.js +81 -5
  174. package/dist/schemas.js.map +1 -1
  175. package/dist/services.d.ts.map +1 -1
  176. package/dist/services.js +9 -5
  177. package/dist/services.js.map +1 -1
  178. package/dist/setup-guide.d.ts +14 -3
  179. package/dist/setup-guide.d.ts.map +1 -1
  180. package/dist/setup-guide.js +41 -37
  181. package/dist/setup-guide.js.map +1 -1
  182. package/dist/tokens.d.ts.map +1 -1
  183. package/dist/tokens.js +5 -1
  184. package/dist/tokens.js.map +1 -1
  185. package/dist/vocabulary.d.ts +7 -0
  186. package/dist/vocabulary.d.ts.map +1 -1
  187. package/dist/vocabulary.js +6 -0
  188. package/dist/vocabulary.js.map +1 -1
  189. package/docs/specs/cli.md +10 -7
  190. package/docs/specs/plugins.md +17 -6
  191. package/docs/specs/rest.md +10 -8
  192. package/docs/specs/runner.md +26 -8
  193. package/package.json +7 -3
  194. package/skills/building-a-console/SKILL.md +2 -2
  195. package/skills/building-a-plugin/SKILL.md +2 -2
  196. package/skills/keeping-a-desk/SKILL.md +2 -2
  197. package/skills/running-an-agent/SKILL.md +47 -57
  198. package/skills/working-the-board/SKILL.md +5 -4
  199. package/skills/working-the-board/references/the-pack.md +1 -1
  200. package/src/agent-page.tsx +13 -1
  201. package/src/api.ts +32 -1
  202. package/src/cli/cli.ts +530 -106
  203. package/src/cli/format.ts +31 -3
  204. package/src/cli/help.ts +12 -4
  205. package/src/cli/machine-check.ts +223 -0
  206. package/src/cli/runner-host.ts +8 -0
  207. package/src/cli/secret-notes.ts +63 -0
  208. package/src/client.ts +23 -0
  209. package/src/components/agent-page.tsx +629 -112
  210. package/src/components/agents.tsx +9 -5
  211. package/src/components/board.tsx +3 -15
  212. package/src/components/categories.tsx +2 -2
  213. package/src/components/decision-list.tsx +11 -7
  214. package/src/components/event-feed.tsx +7 -2
  215. package/src/components/goals.tsx +33 -25
  216. package/src/components/home.tsx +30 -6
  217. package/src/components/icon.tsx +337 -0
  218. package/src/components/markdown.tsx +22 -2
  219. package/src/components/people.tsx +1 -1
  220. package/src/components/plugin-frame.tsx +7 -0
  221. package/src/components/projects.tsx +39 -5
  222. package/src/components/sessions.tsx +2 -13
  223. package/src/components/setup.tsx +2 -2
  224. package/src/components/shell.tsx +3 -20
  225. package/src/components/tokens.tsx +1 -1
  226. package/src/components/ui.tsx +16 -8
  227. package/src/connect-page.tsx +1 -1
  228. package/src/console.tsx +87 -53
  229. package/src/home-tiles.ts +127 -23
  230. package/src/i18n/en.ts +127 -2
  231. package/src/i18n/ko.ts +200 -79
  232. package/src/i18n/particles.ts +79 -0
  233. package/src/icons/glyphs.ts +112 -0
  234. package/src/icons/index.ts +195 -0
  235. package/src/index.ts +7 -0
  236. package/src/limits.ts +9 -0
  237. package/src/marks.ts +12 -0
  238. package/src/onboarding.ts +3 -3
  239. package/src/plugin/web.ts +9 -2
  240. package/src/runner/acp.ts +2 -1
  241. package/src/runner/awake.ts +135 -0
  242. package/src/runner/claude.ts +19 -4
  243. package/src/runner/codex.ts +2 -1
  244. package/src/runner/config.ts +9 -0
  245. package/src/runner/desk.ts +5 -6
  246. package/src/runner/runner.ts +183 -23
  247. package/src/runner/slack.ts +10 -4
  248. package/src/runner/types.ts +20 -0
  249. package/src/schemas.ts +94 -3
  250. package/src/services.ts +9 -5
  251. package/src/setup-guide.ts +43 -38
  252. package/src/styles/README.md +5 -4
  253. package/src/styles/base.css +17 -0
  254. package/src/styles/console.css +1 -0
  255. package/src/styles/drawn-by-pages.json +1 -1
  256. package/src/styles/pages/agents.css +103 -1
  257. package/src/styles/pages/board.css +0 -10
  258. package/src/styles/pages/calendar.css +1 -1
  259. package/src/styles/pages/connect.css +0 -10
  260. package/src/styles/pages/decisions.css +3 -1
  261. package/src/styles/pages/feed.css +5 -2
  262. package/src/styles/pages/home.css +5 -0
  263. package/src/styles/pages/roadmap.css +2 -2
  264. package/src/styles/pages/settings.css +11 -0
  265. package/src/styles/pages/task.css +0 -20
  266. package/src/styles/pages/thread.css +1 -1
  267. package/src/styles/parts/calendar.css +1 -1
  268. package/src/styles/parts/callout.css +1 -0
  269. package/src/styles/parts/detail.css +22 -0
  270. package/src/styles/parts/empty.css +2 -0
  271. package/src/styles/parts/eyebrow.css +1 -1
  272. package/src/styles/parts/facts.css +1 -1
  273. package/src/styles/parts/figures.css +1 -1
  274. package/src/styles/parts/form.css +2 -1
  275. package/src/styles/parts/icon.css +191 -0
  276. package/src/styles/parts/input.css +14 -4
  277. package/src/styles/parts/mark.css +36 -0
  278. package/src/styles/parts/menu.css +1 -7
  279. package/src/styles/parts/page.css +1 -1
  280. package/src/styles/parts/panel.css +10 -0
  281. package/src/styles/parts/person.css +5 -2
  282. package/src/styles/parts/progress.css +5 -2
  283. package/src/styles/parts/rows.css +1 -0
  284. package/src/styles/parts/settings.css +5 -0
  285. package/src/styles/parts/stat.css +1 -1
  286. package/src/styles/tokens.css +22 -7
  287. package/src/tokens.ts +5 -1
  288. package/src/vocabulary.ts +9 -0
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type FormEvent,
3
3
  memo,
4
+ type NamedExoticComponent,
4
5
  type ReactNode,
5
6
  useCallback,
6
7
  useEffect,
@@ -25,15 +26,19 @@ import {
25
26
  import { today } from "../dates.js";
26
27
  import { useWords } from "../i18n/index.js";
27
28
  import { isPicture } from "./files.js";
29
+ import { Markdown } from "./markdown.js";
28
30
  import { Lightbox, type PictureState, PictureThumb, usePicture } from "./pictures.js";
29
31
  import { Avatar, Badge, Button, Callout, cx, formatBytes, personName, Time } from "./ui.js";
30
32
 
31
33
  // The parts of an agent account's page (ADR-0085, ADR-0086): how it stands, what it is doing as
32
34
  // it happens, read as a conversation in a pane that follows its end, what a supervisor says to
33
35
  // it, shown as waiting until the agent takes it, what changes how it stands, its sessions, and
34
- // what its runner said of itself. Everything an agent's product printed is shown as text, in a
35
- // block that keeps its spaces and its lines, and is never made markup; a picture is shown by its
36
- // address at the console, and any other file is offered to save.
36
+ // what its runner said of itself. What the agent said is read as Markdown, rendered to elements
37
+ // and never to HTML, with no picture fetched from elsewhere; everything else its product printed,
38
+ // a thought, a tool's call and its answer, a note, is shown as text, in a block that keeps its
39
+ // spaces and its lines (ADR-0141). What a sub-agent did is read under the call that started it.
40
+ // A picture of the session is shown by its address at the console, and any other file is offered
41
+ // to save.
37
42
 
38
43
  /** How an agent stands, in a word, with the tone of it. */
39
44
  const STATE_TONES: Readonly<Record<AgentState, "success" | "neutral" | "warning" | "danger">> = {
@@ -112,6 +117,11 @@ export interface TranscriptViewProps {
112
117
  readonly onReadWhole?: ((n: number) => Promise<string>) | undefined;
113
118
  /** The account whose session this is: its picture stands beside what it said. */
114
119
  readonly agent?: RestPerson | undefined;
120
+ /**
121
+ * Whether the session is one whose agent is at work: a sub-agent the record neither answers
122
+ * nor ends is then running, and its row counts its time. Left out, no sub-agent is.
123
+ */
124
+ readonly live?: boolean | undefined;
115
125
  /**
116
126
  * The files that came with a signal, by its number, where the page has read the account's
117
127
  * record: what a supervisor sent that is no picture is offered to save from there.
@@ -141,7 +151,8 @@ const TOOL = "tool";
141
151
  /**
142
152
  * One thing of a session as a person reads it: what the agent was told, what woke it, what it
143
153
  * said and thought, a tool's call with what it answered and what was asked of it, and a note for
144
- * everything else, a status, an error, an event that was sealed.
154
+ * everything else, a status, an error, an event that was sealed. A call that started a sub-agent
155
+ * holds what that sub-agent did, as things of its own (ADR-0141).
145
156
  */
146
157
  export type TalkItem =
147
158
  | {
@@ -154,10 +165,25 @@ export type TalkItem =
154
165
  readonly call: RestTranscriptEvent | undefined;
155
166
  readonly result: RestTranscriptEvent | undefined;
156
167
  readonly permission: RestTranscriptEvent | undefined;
168
+ /**
169
+ * What the sub-agent this call started did, in order: the events that name the call as
170
+ * their parent, read as a conversation of their own. Nothing for a call that started none.
171
+ */
172
+ readonly steps?: readonly TalkItem[] | undefined;
173
+ /** When the turn or the session it ran in ended, where that came before its answer. */
174
+ readonly endedAt?: string | undefined;
157
175
  };
158
176
 
159
177
  /** The most characters of a sub-agent's name that a label shows. */
160
178
  const MAX_SUBAGENT_LABEL = 40;
179
+ /** The most characters of a sub-agent's name that its own row shows: what a runner writes of one. */
180
+ const MAX_SUBAGENT_NAME = 80;
181
+
182
+ /** The call an event names as the one that started the sub-agent it is of, or nothing. */
183
+ const parentOf = (event: RestTranscriptEvent | undefined): string | undefined => {
184
+ const parent = event?.data.parent;
185
+ return typeof parent === "string" && parent.length > 0 ? parent : undefined;
186
+ };
161
187
 
162
188
  /**
163
189
  * Whose an event is, where a sub-agent made it (ADR-0131): what the call that started the
@@ -165,8 +191,7 @@ const MAX_SUBAGENT_LABEL = 40;
165
191
  * event of the session's own, which is every event of a runner that does not say.
166
192
  */
167
193
  export function subagentOf(event: RestTranscriptEvent | undefined): string | undefined {
168
- const parent = event?.data.parent;
169
- if (typeof parent !== "string" || parent.length === 0) {
194
+ if (parentOf(event) === undefined) {
170
195
  return undefined;
171
196
  }
172
197
  const name = event?.data.subagent;
@@ -178,112 +203,340 @@ const idOf = (event: RestTranscriptEvent): string | undefined => {
178
203
  return typeof id === "string" && id.length > 0 ? id : undefined;
179
204
  };
180
205
 
206
+ /** Whether an event is where a turn ended, or the session did: the record's own word for it. */
207
+ const endsTurn = (event: RestTranscriptEvent): boolean =>
208
+ event.kind === "status" &&
209
+ event.sealed === null &&
210
+ (event.data.turn === "completed" || typeof event.data.ended === "string");
211
+
212
+ type ToolItem = Extract<TalkItem, { type: "tool" }>;
213
+
214
+ /** Things in the order they are read: the session's own, or one sub-agent's. */
215
+ type TalkLineOf = TalkItem[];
216
+
217
+ /** Where a tool thing stands: the line it is in, and its place there. */
218
+ interface TalkPlace {
219
+ readonly line: TalkLineOf;
220
+ readonly at: number;
221
+ }
222
+
181
223
  /**
182
224
  * The events of a session as the things a person reads, in order. A tool's call, what it
183
225
  * answered and what was asked before it ran are one thing, joined by the id the product gave
184
226
  * them; a call under an id whose call is done is another call, as an agent that numbers its
185
227
  * calls anew at every turn has it. What carries no id joins the call before it that waits.
228
+ *
229
+ * What a sub-agent did is read under the call that started it (ADR-0141): an event that names a
230
+ * call the session holds as its parent is a step of that call, in a line of the call's own, and
231
+ * not a thing of the line the call stands in. A call that says it starts a sub-agent (`starts`)
232
+ * has such a line from the first, empty; one a runner of before wrote has it from the first
233
+ * event that names it. An event that names a call the events do not hold stays where it stood.
234
+ * A turn or a session that ended ends every sub-agent still open in it.
186
235
  */
187
236
  export function talkOf(events: readonly RestTranscriptEvent[]): TalkItem[] {
188
- const items: TalkItem[] = [];
189
- type Tool = Extract<TalkItem, { type: "tool" }>;
190
- /** The tool things by the id they are open under, as places among the items. */
191
- const open = new Map<string, number>();
192
- const toolAt = (at: number | undefined): Tool | undefined => {
193
- const item = at === undefined ? undefined : items[at];
237
+ const top: TalkLineOf = [];
238
+ /** The tool things that still wait for something, by the id they are open under. */
239
+ const open = new Map<string, TalkPlace>();
240
+ /** The last call under each id, done or not: what a sub-agent's event names as its parent. */
241
+ const calls = new Map<string, TalkPlace>();
242
+ /** The line of each sub-agent, by the id of the call that started it. */
243
+ const lines = new Map<string, TalkLineOf>();
244
+ /** The calls that started a sub-agent and were not answered, as far as the events read say. */
245
+ let running: TalkPlace[] = [];
246
+ const toolAt = (place: TalkPlace | undefined): ToolItem | undefined => {
247
+ const item = place === undefined ? undefined : place.line[place.at];
194
248
  return item !== undefined && item.type === "tool" ? item : undefined;
195
249
  };
196
- /** The last tool thing that still waits for what `field` names, where nothing names an id. */
197
- const waiting = (field: "call" | "result"): number | undefined => {
198
- for (let at = items.length - 1; at >= 0; at -= 1) {
199
- const item = items[at];
250
+ /** The last tool thing of a line that still waits for an answer, where nothing names an id. */
251
+ const waiting = (line: TalkLineOf): TalkPlace | undefined => {
252
+ for (let at = line.length - 1; at >= 0; at -= 1) {
253
+ const item = line[at];
200
254
  if (item === undefined || item.type !== "tool") {
201
255
  return undefined;
202
256
  }
203
- if (item[field] === undefined) {
204
- return at;
257
+ if (item.result === undefined) {
258
+ return { line, at };
205
259
  }
206
260
  }
207
261
  return undefined;
208
262
  };
209
- const put = (id: string | undefined, tool: Tool, at: number | undefined): void => {
210
- if (at === undefined) {
211
- items.push(tool);
212
- if (id !== undefined) {
213
- open.set(id, items.length - 1);
214
- }
215
- } else {
216
- items[at] = tool;
263
+ const set = (place: TalkPlace, tool: ToolItem): void => {
264
+ place.line[place.at] = tool;
265
+ };
266
+ const push = (line: TalkLineOf, tool: ToolItem): TalkPlace => {
267
+ line.push(tool);
268
+ return { line, at: line.length - 1 };
269
+ };
270
+ /** The line of the sub-agent a call started, begun where it has none yet. */
271
+ const lineOf = (id: string, place: TalkPlace): TalkLineOf => {
272
+ const begun = lines.get(id);
273
+ if (begun !== undefined) {
274
+ return begun;
275
+ }
276
+ const line: TalkLineOf = [];
277
+ lines.set(id, line);
278
+ const tool = toolAt(place);
279
+ if (tool !== undefined) {
280
+ set(place, { ...tool, steps: line });
281
+ running.push(place);
217
282
  }
283
+ return line;
218
284
  };
219
285
  for (const event of events) {
286
+ // Whose line the event is of: the sub-agent's whose call it names, where the session holds
287
+ // that call, and the session's own otherwise.
288
+ const parent = parentOf(event);
289
+ const starter = parent === undefined ? undefined : calls.get(parent);
290
+ const line = parent === undefined || starter === undefined ? top : lineOf(parent, starter);
220
291
  // A sealed event says who sealed it and why, wherever it stood.
221
292
  if (event.sealed !== null) {
222
- items.push({ type: "note", event });
293
+ line.push({ type: "note", event });
223
294
  continue;
224
295
  }
225
296
  if (event.kind === "person") {
226
- items.push({ type: "told", event });
297
+ line.push({ type: "told", event });
227
298
  } else if (event.kind === "wake") {
228
- items.push({ type: "wake", event });
299
+ line.push({ type: "wake", event });
229
300
  } else if (event.kind === "assistant") {
230
- items.push({ type: "said", event });
301
+ line.push({ type: "said", event });
231
302
  } else if (event.kind === "thinking") {
232
- items.push({ type: "thought", event });
303
+ line.push({ type: "thought", event });
233
304
  } else if (event.kind === "tool_call") {
234
305
  const id = idOf(event);
235
- const at = id === undefined ? undefined : open.get(id);
236
- const held = toolAt(at);
237
- if (held !== undefined && held.call === undefined) {
238
- put(id, { ...held, call: event }, at);
306
+ const held = id === undefined ? undefined : open.get(id);
307
+ const asked = toolAt(held);
308
+ let place: TalkPlace;
309
+ if (held !== undefined && asked !== undefined && asked.call === undefined) {
310
+ set(held, { ...asked, call: event });
311
+ place = held;
239
312
  } else {
240
- put(id, { type: "tool", call: event, result: undefined, permission: undefined }, undefined);
313
+ place = push(line, { type: "tool", call: event, result: undefined, permission: undefined });
314
+ if (id !== undefined) {
315
+ open.set(id, place);
316
+ }
317
+ }
318
+ if (id !== undefined) {
319
+ // Another call under the id is another call, with a sub-agent of its own or none.
320
+ calls.set(id, place);
321
+ lines.delete(id);
322
+ if (typeof event.data.starts === "string") {
323
+ lineOf(id, place);
324
+ }
241
325
  }
242
326
  } else if (event.kind === "tool_result") {
243
327
  const id = idOf(event);
244
- const at = id === undefined ? waiting("result") : open.get(id);
245
- const held = toolAt(at);
246
- if (held !== undefined && held.result === undefined) {
247
- put(id, { ...held, result: event }, at);
328
+ const held = id === undefined ? waiting(line) : open.get(id);
329
+ const called = toolAt(held);
330
+ if (held !== undefined && called !== undefined && called.result === undefined) {
331
+ set(held, { ...called, result: event });
248
332
  if (id !== undefined) {
249
333
  open.delete(id);
250
334
  }
251
335
  } else {
252
- items.push({ type: "tool", call: undefined, result: event, permission: undefined });
336
+ line.push({ type: "tool", call: undefined, result: event, permission: undefined });
253
337
  }
254
338
  } else if (event.kind === "permission") {
255
339
  const id = idOf(event);
256
- const at = id === undefined ? undefined : open.get(id);
257
- const held = toolAt(at);
258
- if (held !== undefined && held.permission === undefined && held.result === undefined) {
259
- put(id, { ...held, permission: event }, at);
340
+ const held = id === undefined ? undefined : open.get(id);
341
+ const called = toolAt(held);
342
+ if (
343
+ held !== undefined &&
344
+ called !== undefined &&
345
+ called.permission === undefined &&
346
+ called.result === undefined
347
+ ) {
348
+ set(held, { ...called, permission: event });
260
349
  } else {
261
- put(id, { type: "tool", call: undefined, result: undefined, permission: event }, undefined);
350
+ const place = push(line, {
351
+ type: "tool",
352
+ call: undefined,
353
+ result: undefined,
354
+ permission: event,
355
+ });
356
+ if (id !== undefined) {
357
+ open.set(id, place);
358
+ }
262
359
  }
263
360
  } else {
264
- items.push({ type: "note", event });
361
+ line.push({ type: "note", event });
362
+ // Where the session's own line says a turn ended, or the session did, nothing started in
363
+ // it goes on: a sub-agent that was not answered by then is ended there.
364
+ if (parent === undefined && endsTurn(event)) {
365
+ for (const place of running) {
366
+ const tool = toolAt(place);
367
+ if (tool !== undefined && tool.result === undefined && tool.endedAt === undefined) {
368
+ set(place, { ...tool, endedAt: event.at });
369
+ }
370
+ }
371
+ running = [];
372
+ }
265
373
  }
266
374
  }
267
- return items;
375
+ return top;
268
376
  }
269
377
 
270
- /** What the agent is at while a turn is under way: thinking, at a tool, or at work between the two. */
378
+ /**
379
+ * What the agent is at while a turn is under way: thinking, at a tool, or at work between the two.
380
+ */
271
381
  export type Working =
272
382
  | { readonly at: "thinking" | "working" }
273
383
  | { readonly at: "tool"; readonly tool: string | undefined };
274
384
 
385
+ /** How a sub-agent stands: at work, done, failed, or ended with the turn or the session it ran in. */
386
+ export type SubAgentState = "running" | "done" | "failed" | "ended";
387
+
388
+ /** A sub-agent as the record alone says it (ADR-0141). */
389
+ export interface SubAgent {
390
+ /** The number of the event that began it: what it is told apart by. */
391
+ readonly n: number;
392
+ /** What the call that started it calls it; empty where nothing says. */
393
+ readonly name: string;
394
+ readonly startedAt: string;
395
+ readonly state: SubAgentState;
396
+ /** How long it ran, or has run so far, in whole seconds. */
397
+ readonly seconds: number;
398
+ /** How many tools it called. */
399
+ readonly calls: number;
400
+ /** What it is at, while it runs. */
401
+ readonly at: Working | undefined;
402
+ }
403
+
404
+ /** The first event of a thing: what it is numbered and timed by. */
405
+ const firstOf = (item: TalkItem): RestTranscriptEvent | undefined =>
406
+ item.type === "tool" ? (item.call ?? item.permission ?? item.result) : item.event;
407
+
408
+ /** The moments a thing holds, as numbers; none for one that reads as no moment. */
409
+ const momentsOf = (item: TalkItem): number[] =>
410
+ (item.type === "tool" ? [item.call, item.permission, item.result] : [item.event]).flatMap(
411
+ (event) => {
412
+ const at = event === undefined ? Number.NaN : Date.parse(event.at);
413
+ return Number.isFinite(at) ? [at] : [];
414
+ },
415
+ );
416
+
417
+ /** Whether what was asked of a call was answered with anything but leave to run. */
418
+ const refusedOf = (item: ToolItem): boolean => {
419
+ const answer = item.permission?.data.answer;
420
+ return typeof answer === "string" && answer.length > 0 && answer !== "allowed";
421
+ };
422
+
423
+ /** What a sub-agent is at, by its steps: its last tool that was not answered, a thought, or the work between. */
424
+ function atOf(steps: readonly TalkItem[]): Working {
425
+ for (let at = steps.length - 1; at >= 0; at -= 1) {
426
+ const step = steps[at];
427
+ if (
428
+ step !== undefined &&
429
+ step.type === "tool" &&
430
+ step.call !== undefined &&
431
+ step.result === undefined &&
432
+ !refusedOf(step)
433
+ ) {
434
+ const tool = step.call.data[TOOL];
435
+ return { at: "tool", tool: typeof tool === "string" && tool.length > 0 ? tool : undefined };
436
+ }
437
+ }
438
+ return steps[steps.length - 1]?.type === "thought" ? { at: "thinking" } : { at: "working" };
439
+ }
440
+
441
+ /**
442
+ * The sub-agent a call started, read off the record alone (ADR-0141): what the call calls it, or
443
+ * what its events do where a runner of before wrote them; when it started; how it stands, done
444
+ * or failed by the call's answer, ended where its turn or its session ended first, and at work
445
+ * otherwise, which only an open session's is (`live`); how long it ran, to its answer, to where
446
+ * it was ended or to the last thing it did, and to `now` while it runs; how many tools it
447
+ * called; and what it is at. Nothing for a thing that is no call that started a sub-agent.
448
+ */
449
+ export function subAgentOf(
450
+ item: TalkItem,
451
+ input: { readonly now: number; readonly live: boolean },
452
+ ): SubAgent | undefined {
453
+ if (item.type !== "tool" || item.steps === undefined) {
454
+ return undefined;
455
+ }
456
+ const first = firstOf(item);
457
+ if (first === undefined) {
458
+ return undefined;
459
+ }
460
+ const steps = item.steps;
461
+ const said = item.call?.data.starts;
462
+ const named = typeof said === "string" ? said : steps.map(firstOf).find(Boolean)?.data.subagent;
463
+ const name = typeof named === "string" ? named.trim().slice(0, MAX_SUBAGENT_NAME) : "";
464
+ const started = Date.parse(first.at);
465
+ const answered = item.result === undefined ? Number.NaN : Date.parse(item.result.at);
466
+ const cut = item.endedAt === undefined ? Number.NaN : Date.parse(item.endedAt);
467
+ const state: SubAgentState =
468
+ item.result !== undefined
469
+ ? item.result.data.error === true
470
+ ? "failed"
471
+ : "done"
472
+ : item.endedAt !== undefined || refusedOf(item) || !input.live
473
+ ? "ended"
474
+ : "running";
475
+ const until =
476
+ state === "running"
477
+ ? input.now
478
+ : item.result !== undefined
479
+ ? answered
480
+ : item.endedAt !== undefined
481
+ ? cut
482
+ : Math.max(started, ...steps.flatMap(momentsOf));
483
+ const seconds = Math.floor((until - started) / 1000);
484
+ return {
485
+ n: first.n,
486
+ name,
487
+ startedAt: first.at,
488
+ state,
489
+ seconds: Number.isFinite(seconds) && seconds > 0 ? seconds : 0,
490
+ calls: steps.filter((step) => step.type === "tool" && step.call !== undefined).length,
491
+ at: state === "running" ? atOf(steps) : undefined,
492
+ };
493
+ }
494
+
495
+ /** The sub-agents among things and under them, in the order they were started. */
496
+ function subAgentsIn(
497
+ items: readonly TalkItem[],
498
+ input: { readonly now: number; readonly live: boolean },
499
+ ): SubAgent[] {
500
+ return items.flatMap((item) => {
501
+ const one = subAgentOf(item, input);
502
+ return one === undefined || item.type !== "tool"
503
+ ? []
504
+ : [one, ...subAgentsIn(item.steps ?? [], input)];
505
+ });
506
+ }
507
+
508
+ /**
509
+ * The sub-agents at work in the turn under way, read off a session's events alone, in the order
510
+ * they were started: those a call of this turn started that was not answered yet. None where the
511
+ * session has no event, or its last turn is over.
512
+ */
513
+ export function atWorkOf(events: readonly RestTranscriptEvent[], now: number): readonly SubAgent[] {
514
+ let from = 0;
515
+ for (let at = events.length - 1; at >= 0; at -= 1) {
516
+ const event = events[at];
517
+ if (event !== undefined && parentOf(event) === undefined && endsTurn(event)) {
518
+ from = at + 1;
519
+ break;
520
+ }
521
+ }
522
+ return subAgentsIn(talkOf(events.slice(from)), { now, live: true }).filter(
523
+ (one) => one.state === "running",
524
+ );
525
+ }
526
+
275
527
  /**
276
528
  * Whether a turn is under way, and what the agent is at, read off a session's events alone:
277
529
  * the record says where a turn ends (`turn: "completed"` on a status) and where the session
278
530
  * does, so whatever follows the last of those is a turn that is not done. Nothing where the
279
- * session has no event yet, or its last turn is over.
531
+ * session has no event yet, or its last turn is over. What a sub-agent does says nothing of
532
+ * what the agent itself is at, which is the call that started it: its events are passed over.
280
533
  */
281
534
  export function workingOf(events: readonly RestTranscriptEvent[]): Working | undefined {
282
535
  /** The calls that were answered, by the id the product gave them. */
283
536
  const answered = new Set<string>();
284
537
  for (let at = events.length - 1; at >= 0; at -= 1) {
285
538
  const event = events[at];
286
- if (event === undefined || event.sealed !== null) {
539
+ if (event === undefined || event.sealed !== null || parentOf(event) !== undefined) {
287
540
  continue;
288
541
  }
289
542
  if (event.kind === "status") {
@@ -439,6 +692,21 @@ function firstLine(text: string, most = 160): string {
439
692
  return line.length > most ? `${line.slice(0, most)}…` : line;
440
693
  }
441
694
 
695
+ /**
696
+ * The first line of what was said, for a row that shows one: without the marks its Markdown
697
+ * begins a heading, a quotation or an item of a list with, and those it sets code and weight
698
+ * off by, which a line alone would show bare.
699
+ */
700
+ export function saidLine(text: string): string {
701
+ const line = text.split("\n").find((one) => one.trim().length > 0) ?? "";
702
+ return firstLine(
703
+ line
704
+ .replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d{1,9}[.)]\s+)/, "")
705
+ .replaceAll("**", "")
706
+ .replaceAll("`", ""),
707
+ );
708
+ }
709
+
442
710
  /** A fact of an event as a word, or nothing where it is none. */
443
711
  const word = (value: unknown): string | undefined =>
444
712
  typeof value === "string" && value.length > 0 ? value : undefined;
@@ -453,6 +721,48 @@ export function wordOf(words: Readonly<Record<string, string>>, name: string): s
453
721
  return Object.hasOwn(words, name) ? (words[name] ?? name) : name;
454
722
  }
455
723
 
724
+ /** A length of time as a clock says it, from whole seconds: `0:07`, `12:40`, `1:02:05`. */
725
+ export function clockOf(seconds: number): string {
726
+ const whole = Number.isFinite(seconds) && seconds > 0 ? Math.floor(seconds) : 0;
727
+ const two = (value: number): string => String(value).padStart(2, "0");
728
+ const hours = Math.floor(whole / 3600);
729
+ const minutes = Math.floor((whole % 3600) / 60);
730
+ return hours > 0
731
+ ? `${hours}:${two(minutes)}:${two(whole % 60)}`
732
+ : `${minutes}:${two(whole % 60)}`;
733
+ }
734
+
735
+ /**
736
+ * How long something has run since a moment, as a clock that ticks by itself: the page counts
737
+ * the seconds, and the record is not read again for them.
738
+ */
739
+ function RunningFor(props: { readonly since: string }) {
740
+ const [now, setNow] = useState(() => Date.now());
741
+ useEffect(() => {
742
+ const timer = setInterval(() => setNow(Date.now()), 1000);
743
+ return () => clearInterval(timer);
744
+ }, []);
745
+ return <>{clockOf((now - Date.parse(props.since)) / 1000)}</>;
746
+ }
747
+
748
+ /** What an agent or a sub-agent is at, in the page's words: a thought, a tool by its name, or the work between. */
749
+ function workingWord(
750
+ words: {
751
+ readonly thinking: string;
752
+ readonly working: string;
753
+ readonly tool: (name: string) => string;
754
+ },
755
+ working: Working | undefined,
756
+ ): string {
757
+ if (working === undefined) {
758
+ return words.working;
759
+ }
760
+ if (working.at === "tool") {
761
+ return working.tool === undefined ? words.working : words.tool(working.tool);
762
+ }
763
+ return words[working.at];
764
+ }
765
+
456
766
  /**
457
767
  * What every line of a conversation is handed, the same from one render of the view to the
458
768
  * next, so that a line is drawn again only when what it shows changed.
@@ -484,17 +794,39 @@ export interface TalkLineProps {
484
794
  readonly reading: number | undefined;
485
795
  /** The day it is: a moment of today is said by its hour alone, so a new day draws the lines again. */
486
796
  readonly today: string;
797
+ /**
798
+ * When the line before this one was: a line of the same day says its hour alone, and the day
799
+ * is said once, on the first line of it. The first line is read against today.
800
+ */
801
+ readonly after: string | undefined;
802
+ /**
803
+ * What the sub-agent the line's call started did, a line each, for a call that started one
804
+ * (ADR-0141): drawn inside the line, each again only when it changed.
805
+ */
806
+ readonly steps?: readonly TalkStep[] | undefined;
807
+ /**
808
+ * For a call that started a sub-agent: whether the session is one whose agent is at work, so
809
+ * that a sub-agent the record does not end is running. Said on no other line.
810
+ */
811
+ readonly live?: boolean | undefined;
812
+ /** Whether the line stands under the sub-agent that made it: whose it is, is then not said again. */
813
+ readonly inside?: boolean | undefined;
487
814
  }
488
815
 
816
+ /** A line of a conversation with the number it is told apart by. */
817
+ export type TalkStep = TalkLineProps & { readonly key: number };
818
+
489
819
  /** Whether two things of a session are the same events: a thing is made anew each time the events are read through. */
490
820
  function sameItem(a: TalkItem, b: TalkItem): boolean {
491
821
  if (a.type === "tool" || b.type === "tool") {
822
+ // What a sub-agent did is compared as the lines it is drawn in, and not here.
492
823
  return (
493
824
  a.type === "tool" &&
494
825
  b.type === "tool" &&
495
826
  a.call === b.call &&
496
827
  a.result === b.result &&
497
- a.permission === b.permission
828
+ a.permission === b.permission &&
829
+ a.endedAt === b.endedAt
498
830
  );
499
831
  }
500
832
  return a.type === b.type && a.event === b.event;
@@ -525,6 +857,23 @@ function sameFiles(
525
857
  );
526
858
  }
527
859
 
860
+ /** Whether the lines of two sub-agents would be drawn the same: as many, each the same line. */
861
+ function sameSteps(
862
+ a: readonly TalkStep[] | undefined,
863
+ b: readonly TalkStep[] | undefined,
864
+ ): boolean {
865
+ if (a === undefined || b === undefined) {
866
+ return a === b;
867
+ }
868
+ return (
869
+ a.length === b.length &&
870
+ a.every((line, index) => {
871
+ const other = b[index];
872
+ return other !== undefined && line.key === other.key && sameLine(line, other);
873
+ })
874
+ );
875
+ }
876
+
528
877
  /** Whether a line would be drawn the same: then it is not drawn again. */
529
878
  export function sameLine(a: TalkLineProps, b: TalkLineProps): boolean {
530
879
  return (
@@ -536,7 +885,11 @@ export function sameLine(a: TalkLineProps, b: TalkLineProps): boolean {
536
885
  a.whole === b.whole &&
537
886
  a.wholeAnswer === b.wholeAnswer &&
538
887
  a.reading === b.reading &&
539
- a.today === b.today
888
+ a.today === b.today &&
889
+ a.after === b.after &&
890
+ a.live === b.live &&
891
+ a.inside === b.inside &&
892
+ sameSteps(a.steps, b.steps)
540
893
  );
541
894
  }
542
895
 
@@ -560,7 +913,8 @@ export function turnStarts(events: readonly RestTranscriptEvent[]): ReadonlyMap<
560
913
  /**
561
914
  * What each line of a conversation is given, in order, with the number it is told apart by:
562
915
  * its own events, and of everything the view holds only what the line itself shows, so that a
563
- * line's props say the same until the line would be drawn otherwise.
916
+ * line's props say the same until the line would be drawn otherwise. A call that started a
917
+ * sub-agent is given the lines of what that sub-agent did, made the same way.
564
918
  */
565
919
  export function talkLinesOf(input: {
566
920
  readonly items: readonly TalkItem[];
@@ -574,36 +928,56 @@ export function talkLinesOf(input: {
574
928
  /** The event whose whole text is being read, by its number. */
575
929
  readonly reading: number | undefined;
576
930
  readonly today: string;
577
- }): readonly (TalkLineProps & { readonly key: number })[] {
931
+ /** Whether the session is one whose agent is at work: left out, it is not. */
932
+ readonly live?: boolean | undefined;
933
+ }): readonly TalkStep[] {
578
934
  const { whole, of, reading } = input;
579
- return input.items.flatMap((one) => {
580
- const main = one.type === "tool" ? one.call : one.event;
581
- const answer = one.type === "tool" ? one.result : undefined;
582
- const first = one.type === "tool" ? (main ?? one.permission ?? answer) : one.event;
583
- if (first === undefined) {
584
- return [];
585
- }
586
- const signal = one.type === "told" ? one.event.data.signal : undefined;
587
- return [
588
- {
589
- key: first.n,
590
- one,
591
- hands: input.hands,
592
- // The account's picture stands beside what it said, and nowhere else: what a
593
- // sub-agent said is a step, with no picture, and is not drawn again for one.
594
- agent: one.type === "said" && subagentOf(one.event) === undefined ? input.agent : undefined,
595
- began: one.type === "tool" ? undefined : input.began.get(one.event.n),
596
- files: typeof signal === "number" ? input.signalFiles?.(signal) : undefined,
597
- whole: main === undefined ? undefined : wholeOf(whole, of, main.n),
598
- wholeAnswer: answer === undefined ? undefined : wholeOf(whole, of, answer.n),
599
- reading:
600
- reading !== undefined && (reading === main?.n || reading === answer?.n)
601
- ? reading
602
- : undefined,
603
- today: input.today,
604
- },
605
- ];
606
- });
935
+ const linesOf = (
936
+ items: readonly TalkItem[],
937
+ inside: boolean,
938
+ from: string | undefined,
939
+ ): TalkStep[] => {
940
+ let before = from;
941
+ return items.flatMap((one) => {
942
+ const main = one.type === "tool" ? one.call : one.event;
943
+ const answer = one.type === "tool" ? one.result : undefined;
944
+ const first = firstOf(one);
945
+ if (first === undefined) {
946
+ return [];
947
+ }
948
+ const signal = one.type === "told" ? one.event.data.signal : undefined;
949
+ const after = before;
950
+ before = first.at;
951
+ const steps =
952
+ one.type === "tool" && one.steps !== undefined
953
+ ? { steps: linesOf(one.steps, true, first.at), live: input.live === true }
954
+ : {};
955
+ return [
956
+ {
957
+ key: first.n,
958
+ one,
959
+ hands: input.hands,
960
+ // The account's picture stands beside what it said, and nowhere else: what a
961
+ // sub-agent said is a step, with no picture, and is not drawn again for one.
962
+ agent:
963
+ one.type === "said" && subagentOf(one.event) === undefined ? input.agent : undefined,
964
+ began: one.type === "tool" ? undefined : input.began.get(one.event.n),
965
+ files: typeof signal === "number" ? input.signalFiles?.(signal) : undefined,
966
+ whole: main === undefined ? undefined : wholeOf(whole, of, main.n),
967
+ wholeAnswer: answer === undefined ? undefined : wholeOf(whole, of, answer.n),
968
+ reading:
969
+ reading !== undefined && (reading === main?.n || reading === answer?.n)
970
+ ? reading
971
+ : undefined,
972
+ today: input.today,
973
+ after,
974
+ ...steps,
975
+ ...(inside ? { inside: true } : {}),
976
+ },
977
+ ];
978
+ });
979
+ };
980
+ return linesOf(input.items, false, undefined);
607
981
  }
608
982
 
609
983
  /**
@@ -611,22 +985,34 @@ export function talkLinesOf(input: {
611
985
  * whole or what it is handed changed: a session of thousands of events draws one line for an
612
986
  * event that arrives, not all of them.
613
987
  */
614
- const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
988
+ const TalkLine: NamedExoticComponent<TalkLineProps> = memo(function Line(
989
+ props: TalkLineProps,
990
+ ): ReactNode {
615
991
  const all = useWords();
616
992
  const words = all.agents.page.live;
617
993
  const { one, hands } = props;
618
994
  const kinds: Readonly<Record<string, string>> = words.kinds;
619
- /** The words of an event, whole where they were read whole, with the way to read the rest. */
995
+ /**
996
+ * The words of an event, whole where they were read whole, with the way to read the rest: as
997
+ * text that keeps its spaces and its lines, or, for what the agent said (`said`), as Markdown
998
+ * rendered to elements, with no picture fetched (ADR-0141).
999
+ */
620
1000
  const text = (
621
1001
  event: RestTranscriptEvent,
622
1002
  className: string,
623
1003
  read: string | undefined,
1004
+ said = false,
624
1005
  ): ReactNode => {
625
1006
  const shown = read ?? event.text;
626
1007
  const readWhole = hands.readWhole;
627
1008
  return (
628
1009
  <>
629
- {shown.length > 0 && <pre className={className}>{shown}</pre>}
1010
+ {shown.length > 0 &&
1011
+ (said ? (
1012
+ <Markdown source={shown} picturesAsLinks />
1013
+ ) : (
1014
+ <pre className={className}>{shown}</pre>
1015
+ ))}
630
1016
  {event.whole !== null && read === undefined && (
631
1017
  <p className="sc-talk-cut">
632
1018
  {words.cutAt(formatBytes(event.whole))}{" "}
@@ -663,7 +1049,9 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
663
1049
  ))}
664
1050
  </ul>
665
1051
  );
666
- const when = (event: RestTranscriptEvent): ReactNode => <Time iso={event.at} precision="clock" />;
1052
+ const when = (event: RestTranscriptEvent): ReactNode => (
1053
+ <Time iso={event.at} precision="clock" against={props.after} />
1054
+ );
667
1055
  if (one.type === "tool") {
668
1056
  const first = one.call ?? one.permission ?? one.result;
669
1057
  if (first === undefined) {
@@ -675,8 +1063,82 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
675
1063
  const refused = answer !== undefined && answer !== "allowed";
676
1064
  const line = firstLine(one.call?.text ?? one.permission?.text ?? one.result?.text ?? "");
677
1065
  // Whose the call is, where a sub-agent made it: read off the line's own events, as
678
- // everything a line shows is, so that it is drawn again only when they are others.
679
- const sub = subagentOf(first);
1066
+ // everything a line shows is, so that it is drawn again only when they are others. Under
1067
+ // the sub-agent that made it, it is not said again.
1068
+ const sub = props.inside === true ? undefined : subagentOf(first);
1069
+ // A call that started a sub-agent is that sub-agent's row: what it is called, how much it
1070
+ // did and how it stands; opened, what it was started with, what it did, a line each, and
1071
+ // what it answered.
1072
+ const started = subAgentOf(one, { now: 0, live: props.live === true });
1073
+ if (started !== undefined) {
1074
+ const steps = props.steps ?? [];
1075
+ const calls = words.agent.calls(started.calls);
1076
+ // What it is called: by the call, by its events, or as the tool that started it is.
1077
+ const called = started.name.length === 0 ? (name ?? kinds.tool_call) : started.name;
1078
+ return (
1079
+ <li
1080
+ className={cx(
1081
+ "sc-talk-item",
1082
+ "sc-talk-step",
1083
+ "sc-talk-tool",
1084
+ (started.state === "failed" || refused) && "sc-talk-tool-failed",
1085
+ )}
1086
+ data-n={first.n}
1087
+ >
1088
+ <details className="sc-talk-tool-fold">
1089
+ <summary className="sc-talk-tool-head sc-talk-agent-head">
1090
+ <span className="sc-talk-who sc-talk-agent-name" title={called}>
1091
+ {called}
1092
+ </span>
1093
+ {sub !== undefined && <Badge>{words.subagent(sub)}</Badge>}
1094
+ {refused ? (
1095
+ <Badge tone="warning">{words.toolRefused}</Badge>
1096
+ ) : started.state === "running" ? (
1097
+ <Badge tone="success" kind="state" live>
1098
+ {words.agent.states.running}
1099
+ </Badge>
1100
+ ) : started.state === "failed" ? (
1101
+ <Badge tone="danger">{words.agent.states.failed}</Badge>
1102
+ ) : (
1103
+ <Badge>{words.agent.states[started.state]}</Badge>
1104
+ )}
1105
+ {when(first)}
1106
+ <span className="sc-muted sc-talk-agent-facts">
1107
+ <span className="sc-talk-kind">{words.agent.label}</span>
1108
+ {started.state === "running" ? (
1109
+ <>
1110
+ {workingWord(words.working, started.at)} · {calls} ·{" "}
1111
+ <RunningFor since={started.startedAt} />
1112
+ </>
1113
+ ) : (
1114
+ `${calls} · ${clockOf(started.seconds)}`
1115
+ )}
1116
+ </span>
1117
+ </summary>
1118
+ <div className="sc-talk-tool-body">
1119
+ {one.permission !== undefined && (
1120
+ <p className="sc-talk-note-line">
1121
+ {kinds.permission}
1122
+ {answer === undefined ? "" : ` · ${wordOf(words.answers, answer)}`}
1123
+ {one.permission.text.length > 0 && ` · ${one.permission.text}`}
1124
+ </p>
1125
+ )}
1126
+ {one.call !== undefined && text(one.call, "sc-talk-code", props.whole)}
1127
+ {steps.length > 0 && (
1128
+ <ol className="sc-talk sc-talk-steps" aria-label={words.agent.steps}>
1129
+ {steps.map(({ key, ...step }) => (
1130
+ <TalkLine key={key} {...step} />
1131
+ ))}
1132
+ </ol>
1133
+ )}
1134
+ {one.result !== undefined &&
1135
+ text(one.result, "sc-talk-code sc-talk-code-answer", props.wholeAnswer)}
1136
+ </div>
1137
+ </details>
1138
+ {pictures(one.result)}
1139
+ </li>
1140
+ );
1141
+ }
680
1142
  return (
681
1143
  <li
682
1144
  className={cx(
@@ -807,19 +1269,19 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
807
1269
  if (one.type === "said") {
808
1270
  const sub = subagentOf(event);
809
1271
  // What a sub-agent said is a step of the work, and not the agent's word to whoever reads:
810
- // folded as a thought is, under the sub-agent's name.
1272
+ // folded as a thought is, under the sub-agent's name where it stands apart from its row.
811
1273
  if (sub !== undefined) {
812
1274
  return (
813
1275
  <li className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
814
1276
  <details className="sc-talk-tool-fold">
815
1277
  <summary className="sc-talk-tool-head">
816
1278
  <span className="sc-talk-kind">{kinds.assistant}</span>
817
- <span className="sc-talk-tool-line">{firstLine(event.text)}</span>
818
- <Badge>{words.subagent(sub)}</Badge>
1279
+ <span className="sc-talk-tool-line">{saidLine(event.text)}</span>
1280
+ {props.inside !== true && <Badge>{words.subagent(sub)}</Badge>}
819
1281
  {when(event)}
820
1282
  </summary>
821
1283
  <div className="sc-talk-tool-body">
822
- {text(event, "sc-talk-text", props.whole)}
1284
+ {text(event, "sc-talk-text", props.whole, true)}
823
1285
  {pictures(event)}
824
1286
  </div>
825
1287
  </details>
@@ -830,7 +1292,7 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
830
1292
  <li className="sc-talk-item sc-talk-said" data-n={event.n}>
831
1293
  {props.agent !== undefined && <Avatar person={props.agent} size="sm" />}
832
1294
  <div className="sc-talk-prose">
833
- {text(event, "sc-talk-text", props.whole)}
1295
+ {text(event, "sc-talk-text", props.whole, true)}
834
1296
  {pictures(event)}
835
1297
  </div>
836
1298
  {when(event)}
@@ -838,7 +1300,7 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
838
1300
  );
839
1301
  }
840
1302
  if (one.type === "thought") {
841
- const sub = subagentOf(event);
1303
+ const sub = props.inside === true ? undefined : subagentOf(event);
842
1304
  return (
843
1305
  <li className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
844
1306
  <details className="sc-talk-tool-fold">
@@ -871,14 +1333,16 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
871
1333
  }
872
1334
  // A wake, a status, an error, and whatever a newer runner calls otherwise: a note between.
873
1335
  // What the note's own words say already, how a session ended, is not said twice as a fact.
874
- // The id of the call that started a sub-agent is for joining, and says nothing to a reader.
1336
+ // The id of the call that started a sub-agent is for joining, and says nothing to a reader;
1337
+ // whose a note is, is not said again under the sub-agent that made it.
875
1338
  const facts = Object.entries(event.data).filter(
876
1339
  ([name, fact]) =>
877
1340
  fact !== null &&
878
1341
  name !== "signal" &&
879
1342
  name !== "kind" &&
880
1343
  name !== "ended" &&
881
- name !== "parent",
1344
+ name !== "parent" &&
1345
+ !(name === "subagent" && props.inside === true),
882
1346
  );
883
1347
  const lines = event.text.split("\n").filter((line) => line.trim().length > 0);
884
1348
  return (
@@ -906,10 +1370,11 @@ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
906
1370
  * A session as a conversation: what the agent was told at the right, as whoever said it wrote
907
1371
  * it, with the files that came with it; what the agent said at the left, beside its picture; its
908
1372
  * thoughts folded; a tool's call and what it answered as one row that opens, the steps of a turn
909
- * close together; a wake, a status and an error as notes between, and a line where a turn
910
- * ended, with how long it took. A picture opens large over the page. Everything an agent's
911
- * product printed is text, never markup. Each line is drawn once and again only when it
912
- * changed, however long the session is.
1373
+ * close together; a sub-agent as one row that opens on what it did; a wake, a status and an
1374
+ * error as notes between, and a line where a turn ended, with how long it took. A picture opens
1375
+ * large over the page. What the agent said is Markdown rendered to elements; everything else its
1376
+ * product printed is text, and nothing of either is ever HTML (ADR-0141). Each line is drawn
1377
+ * once and again only when it changed, however long the session is.
913
1378
  */
914
1379
  export function TranscriptView(props: TranscriptViewProps) {
915
1380
  const words = useWords().agents.page.live;
@@ -989,6 +1454,7 @@ export function TranscriptView(props: TranscriptViewProps) {
989
1454
  of,
990
1455
  reading: reading !== undefined && reading.of === of ? reading.n : undefined,
991
1456
  today: today(),
1457
+ live: props.live,
992
1458
  });
993
1459
  return (
994
1460
  <>
@@ -1103,33 +1569,56 @@ export function TalkWaiting(props: TalkWaitingProps) {
1103
1569
 
1104
1570
  /**
1105
1571
  * The sign that the agent is at work while a turn is under way: its picture, three dots, and
1106
- * what it is at, a thought, a tool by its name, or the work between. A row of the
1107
- * conversation's list; nothing where no turn is under way.
1572
+ * what it is at, a thought, a tool by its name, or the work between. Where sub-agents run, it
1573
+ * says how many, with each under it: its name, what it is at, how many tools it called and how
1574
+ * long it has run, which the page counts by itself (ADR-0141). A row of the conversation's list;
1575
+ * nothing where no turn is under way.
1108
1576
  */
1109
1577
  export function TalkWorking(props: {
1110
1578
  readonly working: Working | undefined;
1111
1579
  readonly agent?: RestPerson | undefined;
1580
+ /** The sub-agents at work in the turn under way: `atWorkOf` says which. */
1581
+ readonly agents?: readonly SubAgent[] | undefined;
1112
1582
  }) {
1113
- const words = useWords().agents.page.live.working;
1583
+ const live = useWords().agents.page.live;
1584
+ const words = live.working;
1114
1585
  const { working } = props;
1115
1586
  if (working === undefined) {
1116
1587
  return null;
1117
1588
  }
1589
+ const agents = props.agents ?? [];
1118
1590
  return (
1119
- <li className="sc-talk-item sc-talk-working" role="status">
1591
+ <li
1592
+ className={cx(
1593
+ "sc-talk-item",
1594
+ "sc-talk-working",
1595
+ agents.length > 0 && "sc-talk-working-agents",
1596
+ )}
1597
+ role="status"
1598
+ >
1120
1599
  {props.agent !== undefined && <Avatar person={props.agent} size="sm" />}
1121
1600
  <span className="sc-talk-dots" aria-hidden="true">
1122
1601
  <span />
1123
1602
  <span />
1124
1603
  <span />
1125
1604
  </span>
1126
- <span>
1127
- {working.at === "tool"
1128
- ? working.tool === undefined
1129
- ? words.working
1130
- : words.tool(working.tool)
1131
- : words[working.at]}
1132
- </span>
1605
+ <span>{agents.length > 0 ? words.agents(agents.length) : workingWord(words, working)}</span>
1606
+ {agents.length > 0 && (
1607
+ // A clock that ticks is not read out at every second.
1608
+ <ul className="sc-talk-agents" aria-live="off">
1609
+ {agents.map((one) => (
1610
+ <li key={one.n} className="sc-talk-agents-row">
1611
+ <span className="sc-talk-who sc-talk-agent-name">
1612
+ {one.name.length === 0 ? live.agent.label : one.name}
1613
+ </span>
1614
+ <span className="sc-talk-agents-facts">
1615
+ {workingWord(words, one.at)} · {live.agent.calls(one.calls)} ·{" "}
1616
+ <RunningFor since={one.startedAt} />
1617
+ </span>
1618
+ </li>
1619
+ ))}
1620
+ </ul>
1621
+ )}
1133
1622
  </li>
1134
1623
  );
1135
1624
  }
@@ -1828,6 +2317,34 @@ export function AgentRunnerFacts(props: { readonly runner: RestAgentRunner | nul
1828
2317
  ],
1829
2318
  ] as [string, ReactNode][])),
1830
2319
  [words.signals, words.delivered(runner.delivered, runner.latest)],
2320
+ // The wake sources its runner keeps beside the console's own, as it last said (ADR-0144):
2321
+ // each by its module's name, with how it stands and why where it does not listen.
2322
+ ...(runner.sources === undefined || runner.sources.length === 0
2323
+ ? []
2324
+ : ([
2325
+ [
2326
+ words.sources,
2327
+ <span key="sources" className="sc-agent-product">
2328
+ {runner.sources.map((source) => (
2329
+ <span key={source.name} className="sc-agent-product">
2330
+ {source.name}
2331
+ <Badge
2332
+ tone={
2333
+ source.state === "connected"
2334
+ ? "success"
2335
+ : source.state === "failing"
2336
+ ? "danger"
2337
+ : "warning"
2338
+ }
2339
+ >
2340
+ {wordOf(words.sourceStates, source.state)}
2341
+ </Badge>
2342
+ {source.why !== undefined && <span className="sc-muted">{source.why}</span>}
2343
+ </span>
2344
+ ))}
2345
+ </span>,
2346
+ ],
2347
+ ] as [string, ReactNode][])),
1831
2348
  ];
1832
2349
  return (
1833
2350
  <dl className="sc-person-facts sc-agent-runner-facts">