@skillcdn/console 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/README.md +68 -11
  2. package/SKILLCDN.md +3 -3
  3. package/dist/agent-page.d.ts.map +1 -1
  4. package/dist/agent-page.js +3 -2
  5. package/dist/agent-page.js.map +1 -1
  6. package/dist/api.d.ts +7 -6
  7. package/dist/api.d.ts.map +1 -1
  8. package/dist/api.js +6 -5
  9. package/dist/api.js.map +1 -1
  10. package/dist/charts.d.ts +103 -0
  11. package/dist/charts.d.ts.map +1 -0
  12. package/dist/charts.js +182 -0
  13. package/dist/charts.js.map +1 -0
  14. package/dist/cli/cli.d.ts +26 -2
  15. package/dist/cli/cli.d.ts.map +1 -1
  16. package/dist/cli/cli.js +1304 -383
  17. package/dist/cli/cli.js.map +1 -1
  18. package/dist/cli/command-words.d.ts +20 -0
  19. package/dist/cli/command-words.d.ts.map +1 -0
  20. package/dist/cli/command-words.js +51 -0
  21. package/dist/cli/command-words.js.map +1 -0
  22. package/dist/cli/credentials.d.ts +54 -5
  23. package/dist/cli/credentials.d.ts.map +1 -1
  24. package/dist/cli/credentials.js +126 -20
  25. package/dist/cli/credentials.js.map +1 -1
  26. package/dist/cli/directory.d.ts +19 -4
  27. package/dist/cli/directory.d.ts.map +1 -1
  28. package/dist/cli/directory.js +16 -8
  29. package/dist/cli/directory.js.map +1 -1
  30. package/dist/cli/format.d.ts +65 -8
  31. package/dist/cli/format.d.ts.map +1 -1
  32. package/dist/cli/format.js +242 -37
  33. package/dist/cli/format.js.map +1 -1
  34. package/dist/cli/help.d.ts +13 -4
  35. package/dist/cli/help.d.ts.map +1 -1
  36. package/dist/cli/help.js +92 -54
  37. package/dist/cli/help.js.map +1 -1
  38. package/dist/cli/main.js +76 -2
  39. package/dist/cli/main.js.map +1 -1
  40. package/dist/cli/pack.d.ts +69 -60
  41. package/dist/cli/pack.d.ts.map +1 -1
  42. package/dist/cli/pack.js +241 -270
  43. package/dist/cli/pack.js.map +1 -1
  44. package/dist/cli/plugin-check.d.ts +42 -0
  45. package/dist/cli/plugin-check.d.ts.map +1 -1
  46. package/dist/cli/plugin-check.js +221 -36
  47. package/dist/cli/plugin-check.js.map +1 -1
  48. package/dist/cli/plugin-cli.d.ts +6 -1
  49. package/dist/cli/plugin-cli.d.ts.map +1 -1
  50. package/dist/cli/plugin-cli.js +21 -4
  51. package/dist/cli/plugin-cli.js.map +1 -1
  52. package/dist/cli/plugin-main.js +1 -0
  53. package/dist/cli/plugin-main.js.map +1 -1
  54. package/dist/cli/serve.d.ts +33 -1
  55. package/dist/cli/serve.d.ts.map +1 -1
  56. package/dist/cli/serve.js +252 -3
  57. package/dist/cli/serve.js.map +1 -1
  58. package/dist/client.d.ts +48 -9
  59. package/dist/client.d.ts.map +1 -1
  60. package/dist/client.js +72 -80
  61. package/dist/client.js.map +1 -1
  62. package/dist/components/agent-page.d.ts +64 -1
  63. package/dist/components/agent-page.d.ts.map +1 -1
  64. package/dist/components/agent-page.js +244 -96
  65. package/dist/components/agent-page.js.map +1 -1
  66. package/dist/components/charts.d.ts +157 -0
  67. package/dist/components/charts.d.ts.map +1 -0
  68. package/dist/components/charts.js +182 -0
  69. package/dist/components/charts.js.map +1 -0
  70. package/dist/components/desk-records.d.ts +102 -0
  71. package/dist/components/desk-records.d.ts.map +1 -0
  72. package/dist/components/desk-records.js +221 -0
  73. package/dist/components/desk-records.js.map +1 -0
  74. package/dist/components/desk.d.ts +85 -0
  75. package/dist/components/desk.d.ts.map +1 -0
  76. package/dist/components/desk.js +135 -0
  77. package/dist/components/desk.js.map +1 -0
  78. package/dist/components/event-feed.d.ts.map +1 -1
  79. package/dist/components/event-feed.js +4 -1
  80. package/dist/components/event-feed.js.map +1 -1
  81. package/dist/components/home.d.ts.map +1 -1
  82. package/dist/components/home.js +4 -2
  83. package/dist/components/home.js.map +1 -1
  84. package/dist/components/plugin-settings.d.ts.map +1 -1
  85. package/dist/components/plugin-settings.js +54 -3
  86. package/dist/components/plugin-settings.js.map +1 -1
  87. package/dist/components/projects.d.ts.map +1 -1
  88. package/dist/components/projects.js +27 -7
  89. package/dist/components/projects.js.map +1 -1
  90. package/dist/components/rules.d.ts +8 -10
  91. package/dist/components/rules.d.ts.map +1 -1
  92. package/dist/components/rules.js +35 -13
  93. package/dist/components/rules.js.map +1 -1
  94. package/dist/components/setup.d.ts +9 -3
  95. package/dist/components/setup.d.ts.map +1 -1
  96. package/dist/components/setup.js +10 -4
  97. package/dist/components/setup.js.map +1 -1
  98. package/dist/console.css +677 -7
  99. package/dist/console.d.ts +5 -0
  100. package/dist/console.d.ts.map +1 -1
  101. package/dist/console.js +14 -8
  102. package/dist/console.js.map +1 -1
  103. package/dist/data.d.ts.map +1 -1
  104. package/dist/data.js +32 -33
  105. package/dist/data.js.map +1 -1
  106. package/dist/desk-page.d.ts +38 -0
  107. package/dist/desk-page.d.ts.map +1 -0
  108. package/dist/desk-page.js +184 -0
  109. package/dist/desk-page.js.map +1 -0
  110. package/dist/desk-records-page.d.ts +18 -0
  111. package/dist/desk-records-page.d.ts.map +1 -0
  112. package/dist/desk-records-page.js +130 -0
  113. package/dist/desk-records-page.js.map +1 -0
  114. package/dist/desk-records.d.ts +247 -0
  115. package/dist/desk-records.d.ts.map +1 -0
  116. package/dist/desk-records.js +543 -0
  117. package/dist/desk-records.js.map +1 -0
  118. package/dist/desk.d.ts +122 -0
  119. package/dist/desk.d.ts.map +1 -0
  120. package/dist/desk.js +211 -0
  121. package/dist/desk.js.map +1 -0
  122. package/dist/feed-stream.d.ts +39 -0
  123. package/dist/feed-stream.d.ts.map +1 -0
  124. package/dist/feed-stream.js +117 -0
  125. package/dist/feed-stream.js.map +1 -0
  126. package/dist/home-tiles.d.ts +10 -3
  127. package/dist/home-tiles.d.ts.map +1 -1
  128. package/dist/home-tiles.js +54 -31
  129. package/dist/home-tiles.js.map +1 -1
  130. package/dist/i18n/en.d.ts +180 -5
  131. package/dist/i18n/en.d.ts.map +1 -1
  132. package/dist/i18n/en.js +184 -7
  133. package/dist/i18n/en.js.map +1 -1
  134. package/dist/i18n/ko.d.ts.map +1 -1
  135. package/dist/i18n/ko.js +169 -6
  136. package/dist/i18n/ko.js.map +1 -1
  137. package/dist/index.d.ts +8 -0
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +8 -0
  140. package/dist/index.js.map +1 -1
  141. package/dist/limits.d.ts +11 -0
  142. package/dist/limits.d.ts.map +1 -1
  143. package/dist/limits.js +11 -0
  144. package/dist/limits.js.map +1 -1
  145. package/dist/onboarding.d.ts +6 -0
  146. package/dist/onboarding.d.ts.map +1 -1
  147. package/dist/onboarding.js +3 -3
  148. package/dist/onboarding.js.map +1 -1
  149. package/dist/plugin/context.d.ts +42 -11
  150. package/dist/plugin/context.d.ts.map +1 -1
  151. package/dist/plugin/limits.d.ts +2 -0
  152. package/dist/plugin/limits.d.ts.map +1 -1
  153. package/dist/plugin/limits.js +2 -0
  154. package/dist/plugin/limits.js.map +1 -1
  155. package/dist/plugin/manifest.d.ts +13 -0
  156. package/dist/plugin/manifest.d.ts.map +1 -1
  157. package/dist/plugin/manifest.js +30 -3
  158. package/dist/plugin/manifest.js.map +1 -1
  159. package/dist/plugin/rest-schemas.d.ts +55 -0
  160. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  161. package/dist/plugin/rest-schemas.js +37 -0
  162. package/dist/plugin/rest-schemas.js.map +1 -1
  163. package/dist/plugin/sandbox.d.ts.map +1 -1
  164. package/dist/plugin/sandbox.js +4 -1
  165. package/dist/plugin/sandbox.js.map +1 -1
  166. package/dist/plugin/testing.d.ts +6 -2
  167. package/dist/plugin/testing.d.ts.map +1 -1
  168. package/dist/plugin/testing.js +52 -10
  169. package/dist/plugin/testing.js.map +1 -1
  170. package/dist/plugin.d.ts +1 -1
  171. package/dist/plugin.d.ts.map +1 -1
  172. package/dist/plugin.js +1 -1
  173. package/dist/plugin.js.map +1 -1
  174. package/dist/records.d.ts +283 -0
  175. package/dist/records.d.ts.map +1 -0
  176. package/dist/records.js +543 -0
  177. package/dist/records.js.map +1 -0
  178. package/dist/routes.d.ts +3 -1
  179. package/dist/routes.d.ts.map +1 -1
  180. package/dist/routes.js +3 -1
  181. package/dist/routes.js.map +1 -1
  182. package/dist/rules.d.ts +30 -11
  183. package/dist/rules.d.ts.map +1 -1
  184. package/dist/rules.js +98 -45
  185. package/dist/rules.js.map +1 -1
  186. package/dist/runner/acp.d.ts +1 -1
  187. package/dist/runner/acp.d.ts.map +1 -1
  188. package/dist/runner/acp.js +31 -20
  189. package/dist/runner/acp.js.map +1 -1
  190. package/dist/runner/claude.d.ts +1 -1
  191. package/dist/runner/claude.d.ts.map +1 -1
  192. package/dist/runner/claude.js +85 -15
  193. package/dist/runner/claude.js.map +1 -1
  194. package/dist/runner/codex.d.ts +1 -1
  195. package/dist/runner/codex.d.ts.map +1 -1
  196. package/dist/runner/codex.js +19 -16
  197. package/dist/runner/codex.js.map +1 -1
  198. package/dist/runner/desk.d.ts +43 -2
  199. package/dist/runner/desk.d.ts.map +1 -1
  200. package/dist/runner/desk.js +166 -10
  201. package/dist/runner/desk.js.map +1 -1
  202. package/dist/runner/process.d.ts.map +1 -1
  203. package/dist/runner/process.js +11 -4
  204. package/dist/runner/process.js.map +1 -1
  205. package/dist/runner/redact.d.ts +39 -4
  206. package/dist/runner/redact.d.ts.map +1 -1
  207. package/dist/runner/redact.js +81 -5
  208. package/dist/runner/redact.js.map +1 -1
  209. package/dist/runner/runner.d.ts +15 -1
  210. package/dist/runner/runner.d.ts.map +1 -1
  211. package/dist/runner/runner.js +231 -33
  212. package/dist/runner/runner.js.map +1 -1
  213. package/dist/runner/task-scheduler.d.ts +20 -0
  214. package/dist/runner/task-scheduler.d.ts.map +1 -1
  215. package/dist/runner/task-scheduler.js +34 -4
  216. package/dist/runner/task-scheduler.js.map +1 -1
  217. package/dist/runner/types.d.ts +36 -1
  218. package/dist/runner/types.d.ts.map +1 -1
  219. package/dist/runner/types.js +17 -0
  220. package/dist/runner/types.js.map +1 -1
  221. package/dist/runner.d.ts +6 -6
  222. package/dist/runner.d.ts.map +1 -1
  223. package/dist/runner.js +5 -5
  224. package/dist/runner.js.map +1 -1
  225. package/dist/schemas.d.ts +509 -5
  226. package/dist/schemas.d.ts.map +1 -1
  227. package/dist/schemas.js +76 -16
  228. package/dist/schemas.js.map +1 -1
  229. package/dist/services.d.ts +22 -5
  230. package/dist/services.d.ts.map +1 -1
  231. package/dist/services.js +35 -15
  232. package/dist/services.js.map +1 -1
  233. package/dist/setup-guide.d.ts +3 -1
  234. package/dist/setup-guide.d.ts.map +1 -1
  235. package/dist/setup-guide.js +7 -4
  236. package/dist/setup-guide.js.map +1 -1
  237. package/dist/vocabulary.d.ts +14 -3
  238. package/dist/vocabulary.d.ts.map +1 -1
  239. package/dist/vocabulary.js +13 -3
  240. package/dist/vocabulary.js.map +1 -1
  241. package/docs/specs/cli.md +64 -38
  242. package/docs/specs/plugins.md +27 -20
  243. package/docs/specs/records.md +113 -0
  244. package/docs/specs/rest.md +20 -13
  245. package/docs/specs/runner.md +23 -17
  246. package/package.json +7 -2
  247. package/skills/building-a-console/SKILL.md +4 -4
  248. package/skills/building-a-plugin/SKILL.md +6 -6
  249. package/skills/deploying-a-console/SKILL.md +4 -4
  250. package/skills/deploying-a-console/references/resources.md +41 -4
  251. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  252. package/skills/keeping-a-desk/SKILL.md +133 -0
  253. package/skills/keeping-a-desk/collections.md +96 -0
  254. package/skills/planning-the-board/SKILL.md +14 -18
  255. package/skills/planning-the-board/references/a-task.md +2 -2
  256. package/skills/planning-the-board/references/project-rules.md +13 -14
  257. package/skills/planning-the-board/references/setting-up.md +15 -13
  258. package/skills/running-an-agent/SKILL.md +10 -9
  259. package/skills/working-the-board/SKILL.md +62 -44
  260. package/skills/working-the-board/references/terms.md +9 -5
  261. package/skills/working-the-board/references/the-pack.md +12 -10
  262. package/skills/working-the-board/references/the-sentence.md +2 -2
  263. package/src/agent-page.tsx +3 -1
  264. package/src/api.ts +77 -2
  265. package/src/charts.ts +250 -0
  266. package/src/cli/cli.ts +1698 -476
  267. package/src/cli/command-words.ts +56 -0
  268. package/src/cli/credentials.ts +181 -20
  269. package/src/cli/directory.ts +28 -10
  270. package/src/cli/format.ts +301 -46
  271. package/src/cli/help.ts +102 -54
  272. package/src/cli/main.ts +72 -2
  273. package/src/cli/pack.ts +333 -372
  274. package/src/cli/plugin-check.ts +275 -34
  275. package/src/cli/plugin-cli.ts +28 -4
  276. package/src/cli/plugin-main.ts +1 -0
  277. package/src/cli/serve.ts +295 -2
  278. package/src/client.ts +192 -177
  279. package/src/components/agent-page.tsx +489 -243
  280. package/src/components/charts.tsx +680 -0
  281. package/src/components/desk-records.tsx +724 -0
  282. package/src/components/desk.tsx +471 -0
  283. package/src/components/event-feed.tsx +5 -1
  284. package/src/components/home.tsx +12 -0
  285. package/src/components/plugin-settings.tsx +171 -12
  286. package/src/components/projects.tsx +29 -12
  287. package/src/components/rules.tsx +94 -34
  288. package/src/components/setup.tsx +18 -3
  289. package/src/console.tsx +17 -9
  290. package/src/data.ts +37 -34
  291. package/src/desk-page.tsx +332 -0
  292. package/src/desk-records-page.tsx +256 -0
  293. package/src/desk-records.ts +808 -0
  294. package/src/desk.ts +329 -0
  295. package/src/feed-stream.ts +144 -0
  296. package/src/home-tiles.ts +55 -35
  297. package/src/i18n/en.ts +196 -9
  298. package/src/i18n/ko.ts +178 -8
  299. package/src/index.ts +118 -0
  300. package/src/limits.ts +11 -0
  301. package/src/onboarding.ts +12 -4
  302. package/src/plugin/context.ts +55 -12
  303. package/src/plugin/limits.ts +2 -0
  304. package/src/plugin/manifest.ts +38 -2
  305. package/src/plugin/rest-schemas.ts +41 -0
  306. package/src/plugin/sandbox.ts +4 -1
  307. package/src/plugin/testing.ts +63 -12
  308. package/src/plugin.ts +2 -0
  309. package/src/records.ts +702 -0
  310. package/src/routes.ts +3 -1
  311. package/src/rules.ts +108 -47
  312. package/src/runner/acp.ts +47 -29
  313. package/src/runner/claude.ts +113 -23
  314. package/src/runner/codex.ts +35 -25
  315. package/src/runner/desk.ts +198 -12
  316. package/src/runner/process.ts +11 -4
  317. package/src/runner/redact.ts +92 -6
  318. package/src/runner/runner.ts +275 -34
  319. package/src/runner/task-scheduler.ts +36 -4
  320. package/src/runner/types.ts +47 -1
  321. package/src/runner.ts +27 -2
  322. package/src/schemas.ts +83 -15
  323. package/src/services.ts +49 -14
  324. package/src/setup-guide.ts +6 -2
  325. package/src/styles/README.md +11 -1
  326. package/src/styles/console.css +9 -0
  327. package/src/styles/pages/desk.css +126 -0
  328. package/src/styles/pages/documents.css +5 -0
  329. package/src/styles/parts/bars.css +80 -0
  330. package/src/styles/parts/chart.css +173 -0
  331. package/src/styles/parts/figures.css +65 -0
  332. package/src/styles/parts/legend.css +48 -0
  333. package/src/styles/parts/series.css +32 -0
  334. package/src/styles/parts/share.css +25 -0
  335. package/src/styles/parts/spark.css +23 -0
  336. package/src/styles/parts/stat.css +69 -0
  337. package/src/styles/tokens.css +13 -7
  338. package/src/vocabulary.ts +16 -3
  339. package/template/desk-web/README.md +8 -0
  340. package/template/desk-web/index.html +13 -0
  341. package/template/desk-web/package.json +25 -0
  342. package/template/desk-web/src/main.tsx +24 -0
  343. package/template/desk-web/src/page.tsx +51 -0
  344. package/template/desk-web/tsconfig.json +16 -0
  345. package/template/desk-web/vite.config.ts +15 -0
@@ -2,15 +2,19 @@ import { randomUUID } from "node:crypto";
2
2
  import { MAX_FILE_BYTES } from "../limits.js";
3
3
  import { TRANSCRIPT_PICTURE_TYPES } from "../vocabulary.js";
4
4
  import type { DriverHost } from "./registry.js";
5
- import type {
6
- Child,
7
- Driver,
8
- DriverEvent,
9
- DriverMessage,
10
- DriverSession,
11
- Fact,
12
- Picture,
13
- StartOptions,
5
+ import {
6
+ type Child,
7
+ type Cut,
8
+ type Driver,
9
+ type DriverEvent,
10
+ type DriverMessage,
11
+ type DriverSession,
12
+ errorsShown,
13
+ type Fact,
14
+ type Picture,
15
+ plainCut,
16
+ plainCutEnd,
17
+ type StartOptions,
14
18
  } from "./types.js";
15
19
 
16
20
  // The `claude` driver (docs/specs/runner.md): the Claude Code binary, unmodified, over its
@@ -65,7 +69,7 @@ function lineOf(line: string): Json | undefined {
65
69
  }
66
70
 
67
71
  /** A tool's input as a person reads it: the command of a shell, the path of a file, or the input whole and bounded. */
68
- function inputOf(input: unknown): string {
72
+ function inputOf(input: unknown, cut: Cut): string {
69
73
  if (isObject(input)) {
70
74
  const line = textOf(input.command) ?? textOf(input.file_path) ?? textOf(input.path);
71
75
  if (line !== undefined && Object.keys(input).length <= 3) {
@@ -78,7 +82,38 @@ function inputOf(input: unknown): string {
78
82
  } catch {
79
83
  whole = "";
80
84
  }
81
- return whole.length > MAX_INPUT_LENGTH ? `${whole.slice(0, MAX_INPUT_LENGTH)}…` : whole;
85
+ return cut(whole, MAX_INPUT_LENGTH);
86
+ }
87
+
88
+ /** The most characters of what a sub-agent is called that an event carries. */
89
+ const MAX_SUBAGENT_LENGTH = 80;
90
+ /** How many calls that started a sub-agent are remembered by their ids: the oldest is let go past it. */
91
+ const MAX_SUBAGENTS = 500;
92
+ /** The product's tools that start a sub-agent, as it has called them: one whose input names a kind of sub-agent is one too. */
93
+ const SUBAGENT_TOOLS: ReadonlySet<string> = new Set(["Agent", "Task"]);
94
+
95
+ /** A word of a call's input, trimmed, or nothing where it holds none. */
96
+ const wordOf = (input: unknown, name: string): string | undefined => {
97
+ const word = isObject(input) ? textOf(input[name])?.trim() : undefined;
98
+ return word === undefined || word.length === 0 ? undefined : word;
99
+ };
100
+
101
+ /**
102
+ * What a call that starts a sub-agent calls it: the kind of sub-agent its input names and what
103
+ * its input says it is for, the kind first (`Explore: Read src/ of acme/web`), so that two of
104
+ * one kind at once are told apart; the one of the two the input names alone; the tool where
105
+ * it names neither; nothing for a call that starts none. Within the bound, mark and all, cut
106
+ * after the secrets are out of it, as everything a driver shows a part of is.
107
+ */
108
+ function subagentOf(tool: string, input: unknown, cut: Cut): string | undefined {
109
+ const kind = wordOf(input, "subagent_type");
110
+ if (kind === undefined && !SUBAGENT_TOOLS.has(tool)) {
111
+ return undefined;
112
+ }
113
+ const about = wordOf(input, "description");
114
+ const name =
115
+ kind !== undefined && about !== undefined ? `${kind}: ${about}` : (kind ?? about ?? tool);
116
+ return cut(name, MAX_SUBAGENT_LENGTH - 1);
82
117
  }
83
118
 
84
119
  /** The pictures and the text of what a tool returned: a string, or blocks of text and pictures. */
@@ -124,7 +159,7 @@ function resultOf(
124
159
  }
125
160
 
126
161
  /** What a denial says of the tool it denied. */
127
- function denialOf(denial: unknown): DriverEvent | undefined {
162
+ function denialOf(denial: unknown, cut: Cut): DriverEvent | undefined {
128
163
  if (!isObject(denial)) {
129
164
  return undefined;
130
165
  }
@@ -137,7 +172,7 @@ function denialOf(denial: unknown): DriverEvent | undefined {
137
172
  return {
138
173
  type: "event",
139
174
  kind: "permission",
140
- text: `Denied, with nobody at the terminal to ask: ${tool} ${inputOf(denial.tool_input)}`.trim(),
175
+ text: `Denied, with nobody at the terminal to ask: ${tool} ${inputOf(denial.tool_input, cut)}`.trim(),
141
176
  data,
142
177
  };
143
178
  }
@@ -159,6 +194,25 @@ interface Read {
159
194
  acknowledges: boolean;
160
195
  /** The tool calls of the turn it said were denied, which the turn's result says again. */
161
196
  readonly denied: Set<string>;
197
+ /** The calls that started a sub-agent, by their ids, with what each calls it. */
198
+ readonly subagents: Map<string, string>;
199
+ /** What cuts a text to what is shown of it. */
200
+ readonly cut: Cut;
201
+ }
202
+
203
+ /**
204
+ * Whose a line of the product is, as facts of its events (ADR-0131): a line a sub-agent wrote
205
+ * names the call that started that sub-agent, by the id the product gave the call, as the
206
+ * product's documentation has it (`parent_tool_use_id`), and what that call called it, where
207
+ * the call was read. Nothing for a line of the session's own.
208
+ */
209
+ function whoseOf(line: Json, state: Read): Record<string, Fact> {
210
+ const parent = textOf(line.parent_tool_use_id);
211
+ if (parent === undefined || parent.length === 0) {
212
+ return {};
213
+ }
214
+ const subagent = state.subagents.get(parent);
215
+ return subagent === undefined ? { parent } : { parent, subagent };
162
216
  }
163
217
 
164
218
  /** The product's permission modes, as its documentation and its own help name them. */
@@ -262,7 +316,7 @@ function eventsOf(line: Json, state: Read): DriverEvent[] {
262
316
  });
263
317
  } else if (line.subtype === "permission_denied") {
264
318
  // Said when it happens, and again in the turn's result, which is then not said twice.
265
- const denied = denialOf(line);
319
+ const denied = denialOf(line, state.cut);
266
320
  if (denied !== undefined) {
267
321
  events.push(denied);
268
322
  const id = textOf(line.tool_use_id);
@@ -274,21 +328,40 @@ function eventsOf(line: Json, state: Read): DriverEvent[] {
274
328
  return events;
275
329
  }
276
330
  case "assistant": {
331
+ const whose = whoseOf(line, state);
332
+ // A fact is said only where there is one: a line of the session's own carries none.
333
+ const said = Object.keys(whose).length === 0 ? {} : { data: whose };
277
334
  for (const block of blocks) {
278
335
  if (!isObject(block)) {
279
336
  continue;
280
337
  }
281
338
  if (block.type === "text" && typeof block.text === "string") {
282
- events.push({ type: "event", kind: "assistant", text: block.text });
339
+ events.push({ type: "event", kind: "assistant", text: block.text, ...said });
283
340
  } else if (block.type === "thinking" && typeof block.thinking === "string") {
284
- events.push({ type: "event", kind: "thinking", text: block.thinking });
341
+ // A thought the product sends with no words, its signature alone, is no event: it
342
+ // would show nothing, and count against what an hour of a session takes.
343
+ if (block.thinking.trim().length > 0) {
344
+ events.push({ type: "event", kind: "thinking", text: block.thinking, ...said });
345
+ }
285
346
  } else if (block.type === "tool_use") {
286
347
  const tool = textOf(block.name) ?? "a tool";
348
+ const id = textOf(block.id);
349
+ const subagent = subagentOf(tool, block.input, state.cut);
350
+ if (id !== undefined && subagent !== undefined) {
351
+ // What the sub-agent this call starts does names the call: remembered by its id.
352
+ if (state.subagents.size >= MAX_SUBAGENTS) {
353
+ const oldest = state.subagents.keys().next().value;
354
+ if (oldest !== undefined) {
355
+ state.subagents.delete(oldest);
356
+ }
357
+ }
358
+ state.subagents.set(id, subagent);
359
+ }
287
360
  events.push({
288
361
  type: "event",
289
362
  kind: "tool_call",
290
- text: inputOf(block.input),
291
- data: { tool, id: textOf(block.id) ?? null },
363
+ text: inputOf(block.input, state.cut),
364
+ data: { tool, id: id ?? null, ...whose },
292
365
  });
293
366
  }
294
367
  }
@@ -305,7 +378,8 @@ function eventsOf(line: Json, state: Read): DriverEvent[] {
305
378
  }
306
379
  return events;
307
380
  }
308
- // What came back from a tool is recorded here.
381
+ // What came back from a tool is recorded here, a sub-agent's tool as the session's own.
382
+ const whose = whoseOf(line, state);
309
383
  for (const block of blocks) {
310
384
  if (!isObject(block) || block.type !== "tool_result") {
311
385
  continue;
@@ -316,7 +390,11 @@ function eventsOf(line: Json, state: Read): DriverEvent[] {
316
390
  type: "event",
317
391
  kind: "tool_result",
318
392
  text: result.text,
319
- data: { id: textOf(block.tool_use_id) ?? null, error: block.is_error === true },
393
+ data: {
394
+ id: textOf(block.tool_use_id) ?? null,
395
+ error: block.is_error === true,
396
+ ...whose,
397
+ },
320
398
  pictures: result.pictures,
321
399
  });
322
400
  }
@@ -324,7 +402,7 @@ function eventsOf(line: Json, state: Read): DriverEvent[] {
324
402
  }
325
403
  case "result": {
326
404
  for (const denial of Array.isArray(line.permission_denials) ? line.permission_denials : []) {
327
- const denied = denialOf(denial);
405
+ const denied = denialOf(denial, state.cut);
328
406
  const id = isObject(denial) ? textOf(denial.tool_use_id) : undefined;
329
407
  if (denied !== undefined && (id === undefined || !state.denied.has(id))) {
330
408
  events.push(denied);
@@ -448,7 +526,13 @@ const wait = (ms: number): Promise<"timeout"> =>
448
526
  setTimeout(() => resolve("timeout"), ms).unref?.();
449
527
  });
450
528
 
451
- function sessionOf(child: Child, asked: string, uuid: () => string): DriverSession {
529
+ function sessionOf(
530
+ child: Child,
531
+ asked: string,
532
+ uuid: () => string,
533
+ cut: Cut,
534
+ cutEnd: Cut,
535
+ ): DriverSession {
452
536
  let stopping = false;
453
537
  const state: Read = {
454
538
  began: false,
@@ -459,6 +543,8 @@ function sessionOf(child: Child, asked: string, uuid: () => string): DriverSessi
459
543
  waiting: new Set(),
460
544
  denied: new Set(),
461
545
  acknowledges: false,
546
+ subagents: new Map(),
547
+ cut,
462
548
  };
463
549
 
464
550
  async function* events(): AsyncGenerator<DriverEvent> {
@@ -478,10 +564,12 @@ function sessionOf(child: Child, asked: string, uuid: () => string): DriverSessi
478
564
  const clean = stopping || (exit.code === 0 && exit.signal === null && exit.error === undefined);
479
565
  if (!clean && !waits) {
480
566
  const said = child.errors().trim();
567
+ // Its end, cut after the secrets are out, so that none stands at the cut.
568
+ const shown = errorsShown(said, cutEnd);
481
569
  const text =
482
570
  exit.error !== undefined
483
571
  ? `The product could not be started: ${exit.error}`
484
- : `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`}.${said.length === 0 ? "" : `\n${said}`}`;
572
+ : `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`}.${shown.length === 0 ? "" : `\n${shown}`}`;
485
573
  yield { type: "event", kind: "error", text };
486
574
  yield {
487
575
  type: "cannot_go_on",
@@ -599,6 +687,8 @@ export function createClaudeDriver(host: DriverHost): Driver {
599
687
  host.spawn(command, claudeArguments(options), { cwd: options.cwd, env: options.env }),
600
688
  claudeMode(options.permissions),
601
689
  uuid,
690
+ options.cut ?? plainCut,
691
+ options.cutEnd ?? plainCutEnd,
602
692
  );
603
693
  },
604
694
  };
@@ -1,12 +1,16 @@
1
1
  import type { DriverHost } from "./registry.js";
2
- import type {
3
- Child,
4
- Driver,
5
- DriverEvent,
6
- DriverMessage,
7
- DriverSession,
8
- Fact,
9
- StartOptions,
2
+ import {
3
+ type Child,
4
+ type Cut,
5
+ type Driver,
6
+ type DriverEvent,
7
+ type DriverMessage,
8
+ type DriverSession,
9
+ errorsShown,
10
+ type Fact,
11
+ plainCut,
12
+ plainCutEnd,
13
+ type StartOptions,
10
14
  } from "./types.js";
11
15
 
12
16
  // The `codex` driver (docs/specs/runner.md): the Codex binary, unmodified, run with nobody at
@@ -151,16 +155,13 @@ function lineOf(line: string): Json | undefined {
151
155
  }
152
156
  }
153
157
 
154
- const bounded = (text: string): string =>
155
- text.length > MAX_INPUT_LENGTH ? `${text.slice(0, MAX_INPUT_LENGTH)}…` : text;
156
-
157
158
  /** Anything as a line of text a person reads, bounded. */
158
- function shown(value: unknown): string {
159
+ function shown(value: unknown, cut: Cut): string {
159
160
  if (typeof value === "string") {
160
- return bounded(value);
161
+ return cut(value, MAX_INPUT_LENGTH);
161
162
  }
162
163
  try {
163
- return bounded(JSON.stringify(value) ?? "");
164
+ return cut(JSON.stringify(value) ?? "", MAX_INPUT_LENGTH);
164
165
  } catch {
165
166
  return "";
166
167
  }
@@ -201,6 +202,8 @@ interface Read {
201
202
  turned: boolean;
202
203
  /** How many messages the turn under way was started with. */
203
204
  messages: number;
205
+ /** What cuts a text to what is shown of it. */
206
+ readonly cut: Cut;
204
207
  }
205
208
 
206
209
  /** What a turn runs with, as the session's first event and the heartbeat say it. */
@@ -211,19 +214,23 @@ interface Runs {
211
214
  }
212
215
 
213
216
  /** A tool call of the product, by the kind of item it writes for one: its name and its input as a line. */
214
- function callOf(item: Json): { readonly tool: string; readonly text: string } | undefined {
217
+ function callOf(
218
+ item: Json,
219
+ cut: Cut,
220
+ ): { readonly tool: string; readonly text: string } | undefined {
215
221
  switch (item.type) {
216
222
  case "command_execution":
217
- return { tool: "command_execution", text: shown(item.command ?? "") };
223
+ return { tool: "command_execution", text: shown(item.command ?? "", cut) };
218
224
  case "file_change": {
219
225
  const changes = Array.isArray(item.changes) ? item.changes : [];
220
226
  return {
221
227
  tool: "file_change",
222
- text: bounded(
228
+ text: cut(
223
229
  changes
224
230
  .filter(isObject)
225
231
  .map((change) => `${textOf(change.kind) ?? "change"} ${textOf(change.path) ?? ""}`)
226
232
  .join("\n"),
233
+ MAX_INPUT_LENGTH,
227
234
  ),
228
235
  };
229
236
  }
@@ -231,17 +238,17 @@ function callOf(item: Json): { readonly tool: string; readonly text: string } |
231
238
  case "mcp_tool_call":
232
239
  return {
233
240
  tool: `${textOf(item.server) ?? "mcp"}.${textOf(item.tool) ?? "tool"}`,
234
- text: item.arguments === undefined ? "" : shown(item.arguments),
241
+ text: item.arguments === undefined ? "" : shown(item.arguments, cut),
235
242
  };
236
243
  case "web_search":
237
- return { tool: "web_search", text: shown(item.query ?? "") };
244
+ return { tool: "web_search", text: shown(item.query ?? "", cut) };
238
245
  default:
239
246
  return undefined;
240
247
  }
241
248
  }
242
249
 
243
250
  /** What came back from a tool call, where the product says: a command's output, or what a tool answered. */
244
- function resultOf(item: Json): string {
251
+ function resultOf(item: Json, cut: Cut): string {
245
252
  if (item.type === "command_execution") {
246
253
  return textOf(item.aggregated_output) ?? "";
247
254
  }
@@ -249,7 +256,7 @@ function resultOf(item: Json): string {
249
256
  if (isObject(item.error) && typeof item.error.message === "string") {
250
257
  return item.error.message;
251
258
  }
252
- return item.result === undefined || item.result === null ? "" : shown(item.result);
259
+ return item.result === undefined || item.result === null ? "" : shown(item.result, cut);
253
260
  }
254
261
  return "";
255
262
  }
@@ -284,7 +291,7 @@ function eventsOf(line: Json, read: Read, runs: Runs): DriverEvent[] {
284
291
  return events;
285
292
  }
286
293
  case "item.started": {
287
- const call = item === undefined ? undefined : callOf(item);
294
+ const call = item === undefined ? undefined : callOf(item, read.cut);
288
295
  const id = textOf(item?.id);
289
296
  if (call !== undefined) {
290
297
  events.push({
@@ -313,7 +320,7 @@ function eventsOf(line: Json, read: Read, runs: Runs): DriverEvent[] {
313
320
  // A word of warning inside a turn: the turn goes on.
314
321
  events.push({ type: "event", kind: "error", text: errorOf(item.message) });
315
322
  } else {
316
- const call = callOf(item);
323
+ const call = callOf(item, read.cut);
317
324
  if (call === undefined) {
318
325
  return events;
319
326
  }
@@ -340,7 +347,7 @@ function eventsOf(line: Json, read: Read, runs: Runs): DriverEvent[] {
340
347
  events.push({
341
348
  type: "event",
342
349
  kind: "tool_result",
343
- text: resultOf(item),
350
+ text: resultOf(item, read.cut),
344
351
  data,
345
352
  pictures: [],
346
353
  });
@@ -434,6 +441,7 @@ function sessionOf(
434
441
  failed: undefined,
435
442
  turned: false,
436
443
  messages: 0,
444
+ cut: options.cut ?? plainCut,
437
445
  };
438
446
  const mode = codexMode(options.permissions);
439
447
  let conversation = word(options.resume);
@@ -521,10 +529,12 @@ function sessionOf(
521
529
  } else if (!read.completed) {
522
530
  const errors = child.errors().trim();
523
531
  if (read.failed === undefined) {
532
+ // Its end, cut after the secrets are out, so that none stands at the cut.
533
+ const shown = errorsShown(errors, options.cutEnd ?? plainCutEnd);
524
534
  emit({
525
535
  type: "event",
526
536
  kind: "error",
527
- text: `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`} before the turn did.${errors.length === 0 ? "" : `\n${errors}`}`,
537
+ text: `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`} before the turn did.${shown.length === 0 ? "" : `\n${shown}`}`,
528
538
  });
529
539
  }
530
540
  if (SIGN_IN.test(`${read.failed ?? ""}\n${errors}`)) {