@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
package/src/desk.ts ADDED
@@ -0,0 +1,329 @@
1
+ import type { RestRunBrief, RestTaskBrief, RestWorkBrief, RunStatus, TaskState } from "./api.js";
2
+ import type { ProjectClient } from "./client.js";
3
+ import { addDays, dayOf, weekOf } from "./dates.js";
4
+
5
+ // The board's side of a desk's page (ADR-0116): what a member's own console shows of their own
6
+ // work on the board, across the projects they may see. Three views: what stands now, the
7
+ // figures, and the archive. Each is read from the console when it is looked at, a project at a
8
+ // time through the routes there are, and what one visit reads is bounded here. This module is
9
+ // the reading and the counting, with no React in it; the views are `components/desk.tsx` and
10
+ // the page that composes them, with the desk's records before them, is `desk-page.tsx`.
11
+
12
+ /** How many of a person's projects one visit reads: the rest are named as not read. */
13
+ export const DESK_PROJECTS = 12;
14
+ /** How many tasks of a listing a project gives one visit at once. */
15
+ export const DESK_TASKS = 100;
16
+ /** How many runs a project gives one visit at once: a run carries its reports, so fewer. */
17
+ export const DESK_RUNS = 30;
18
+ /** How many weeks the figures count back, this week among them. */
19
+ export const DESK_WEEKS = 8;
20
+ /** How many words a search of the archive takes; the rest are dropped. */
21
+ export const DESK_WORDS = 8;
22
+
23
+ /** A project as a row names it: what the plate says of one, which a project's own answer carries too. */
24
+ export type DeskProject = RestWorkBrief["tasks"][number]["project"];
25
+
26
+ /** A task of the person's with the project it is in. */
27
+ export interface DeskTask {
28
+ readonly project: DeskProject;
29
+ readonly task: RestTaskBrief;
30
+ }
31
+
32
+ /** A run of the person's with the project it is in and, where the visit read its task, the task's title. */
33
+ export interface DeskRun {
34
+ readonly project: DeskProject;
35
+ /** The run without its reports, which a desk never shows: what a listing in the brief form answers. */
36
+ readonly run: RestRunBrief;
37
+ readonly title: string | undefined;
38
+ }
39
+
40
+ /** The states of open work, in the order a desk shows them: what is at hand first. */
41
+ export const DESK_STATES = [
42
+ "in_progress",
43
+ "in_review",
44
+ "ready",
45
+ "idea",
46
+ ] as const satisfies readonly TaskState[];
47
+
48
+ /** The open tasks by state, in the desk's order, each group in the order the tasks came (the sooner due first). */
49
+ export function standingOf(tasks: readonly DeskTask[]): readonly {
50
+ readonly state: (typeof DESK_STATES)[number];
51
+ readonly tasks: readonly DeskTask[];
52
+ }[] {
53
+ return DESK_STATES.map((state) => ({
54
+ state,
55
+ tasks: tasks.filter((item) => item.task.state === state),
56
+ }));
57
+ }
58
+
59
+ /** How a run can have ended. */
60
+ export const DESK_ENDINGS = [
61
+ "finished",
62
+ "failed",
63
+ "abandoned",
64
+ ] as const satisfies readonly RunStatus[];
65
+ export type DeskEnding = (typeof DESK_ENDINGS)[number];
66
+
67
+ /** One week of the figures: its first and last day, and how many tasks were done in it. */
68
+ export interface DeskWeek {
69
+ readonly start: string;
70
+ readonly end: string;
71
+ readonly done: number;
72
+ }
73
+
74
+ /** A category as a task carries it. */
75
+ export type DeskCategory = NonNullable<RestTaskBrief["category"]>;
76
+
77
+ export interface DeskFigures {
78
+ /** The weeks counted, the oldest first; the last is the week of `today`. */
79
+ readonly weeks: readonly DeskWeek[];
80
+ /** The tasks done within those weeks, in all. */
81
+ readonly done: number;
82
+ /** The runs that ended within those weeks, by how they ended. */
83
+ readonly runs: Readonly<Record<DeskEnding, number>>;
84
+ /** The same by project, the most done first; a project with neither is left out. */
85
+ readonly byProject: readonly {
86
+ readonly project: DeskProject;
87
+ readonly done: number;
88
+ readonly runs: number;
89
+ }[];
90
+ /** The tasks done by category, the most first; those sorted into none last, under `null`. */
91
+ readonly byCategory: readonly { readonly category: DeskCategory | null; readonly done: number }[];
92
+ }
93
+
94
+ /**
95
+ * The figures of a stretch of weeks, counted from what a visit read: the tasks by the day they
96
+ * were done, the runs by the day they ended, both as the browser's clock has the day. A task
97
+ * that is not done, or a run still open, counts nowhere.
98
+ */
99
+ export function figuresOf(input: {
100
+ readonly tasks: readonly DeskTask[];
101
+ readonly runs: readonly DeskRun[];
102
+ readonly today: string;
103
+ /** The weekday a week begins on: 1 for Monday, 7 for Sunday. */
104
+ readonly firstDay?: number | undefined;
105
+ readonly weeks?: number | undefined;
106
+ }): DeskFigures {
107
+ const count = Math.max(1, input.weeks ?? DESK_WEEKS);
108
+ const thisWeek = weekOf(input.today, input.firstDay ?? 1);
109
+ const last = thisWeek[0] ?? input.today;
110
+ const weeks = Array.from({ length: count }, (_, index) => {
111
+ const start = addDays(last, (index - (count - 1)) * 7);
112
+ return { start, end: addDays(start, 6), done: 0 };
113
+ });
114
+ const from = weeks[0]?.start ?? input.today;
115
+ const until = weeks.at(-1)?.end ?? input.today;
116
+ const within = (instant: string | null): string | undefined => {
117
+ if (instant === null) {
118
+ return undefined;
119
+ }
120
+ const date = new Date(instant);
121
+ if (Number.isNaN(date.getTime())) {
122
+ return undefined;
123
+ }
124
+ const day = dayOf(date);
125
+ return day >= from && day <= until ? day : undefined;
126
+ };
127
+ const projects = new Map<string, { project: DeskProject; done: number; runs: number }>();
128
+ const projectOf = (project: DeskProject) => {
129
+ const found = projects.get(project.key) ?? { project, done: 0, runs: 0 };
130
+ projects.set(project.key, found);
131
+ return found;
132
+ };
133
+ const categories = new Map<string, { category: DeskCategory | null; done: number }>();
134
+ let done = 0;
135
+ const seen = new Set<string>();
136
+ for (const { project, task } of input.tasks) {
137
+ const day = task.state === "done" ? within(task.doneAt) : undefined;
138
+ if (day === undefined || seen.has(task.id)) {
139
+ continue;
140
+ }
141
+ seen.add(task.id);
142
+ const week = weeks.find((candidate) => day >= candidate.start && day <= candidate.end);
143
+ if (week !== undefined) {
144
+ week.done += 1;
145
+ }
146
+ done += 1;
147
+ projectOf(project).done += 1;
148
+ const key = task.category?.key ?? "";
149
+ const category = categories.get(key) ?? { category: task.category, done: 0 };
150
+ category.done += 1;
151
+ categories.set(key, category);
152
+ }
153
+ const runs: Record<DeskEnding, number> = { finished: 0, failed: 0, abandoned: 0 };
154
+ for (const { project, run } of input.runs) {
155
+ const ending = DESK_ENDINGS.find((candidate) => candidate === run.status);
156
+ if (ending === undefined || within(run.endedAt) === undefined || seen.has(run.id)) {
157
+ continue;
158
+ }
159
+ seen.add(run.id);
160
+ runs[ending] += 1;
161
+ projectOf(project).runs += 1;
162
+ }
163
+ return {
164
+ weeks,
165
+ done,
166
+ runs,
167
+ byProject: [...projects.values()].sort(
168
+ (a, b) => b.done - a.done || b.runs - a.runs || a.project.name.localeCompare(b.project.name),
169
+ ),
170
+ byCategory: [...categories.values()].sort(
171
+ (a, b) =>
172
+ Number(a.category === null) - Number(b.category === null) ||
173
+ b.done - a.done ||
174
+ (a.category?.name ?? "").localeCompare(b.category?.name ?? ""),
175
+ ),
176
+ };
177
+ }
178
+
179
+ /** The words of a search, as they are looked for: lowercased, without what is between them, `DESK_WORDS` at most. */
180
+ export function wordsOf(query: string): readonly string[] {
181
+ return query
182
+ .toLowerCase()
183
+ .split(/\s+/)
184
+ .filter((word) => word.length > 0)
185
+ .slice(0, DESK_WORDS);
186
+ }
187
+
188
+ /** Whether a run is found by every word: in its task's title or number, or in what it said at its end. */
189
+ export function runHolds(run: DeskRun, words: readonly string[]): boolean {
190
+ if (words.length === 0) {
191
+ return true;
192
+ }
193
+ const text =
194
+ `#${run.run.taskNumber} ${run.title ?? ""} ${run.run.summary ?? ""} ${run.run.agent}`.toLowerCase();
195
+ return words.every((word) => text.includes(word));
196
+ }
197
+
198
+ /** When a task was closed, as the archive orders it: put away, else done, else last changed. */
199
+ function closedAt(task: RestTaskBrief): string {
200
+ return task.archivedAt ?? task.doneAt ?? task.updatedAt;
201
+ }
202
+
203
+ /**
204
+ * What a desk reads of the console: a project at a time, its tasks and its runs, each in the
205
+ * brief form, without the bodies and the reports a desk does not show.
206
+ */
207
+ export interface DeskReader {
208
+ project(key: string): Pick<ProjectClient, "taskBriefs" | "runBriefs">;
209
+ }
210
+
211
+ /** A page of a person's closed work: what one visit read, and whether the console has more. */
212
+ export interface DeskHistory {
213
+ /** The tasks the person worked on that are done, dropped or put away, the last closed first. */
214
+ readonly tasks: readonly DeskTask[];
215
+ /** The person's runs that ended, the last ended first. */
216
+ readonly runs: readonly DeskRun[];
217
+ /** Whether a project has more of either than this page read. */
218
+ readonly more: boolean;
219
+ /** How many projects were read, and how many the person may see. */
220
+ readonly read: number;
221
+ readonly of: number;
222
+ }
223
+
224
+ /**
225
+ * A page of the person's closed work, across their projects: from each of the first
226
+ * `DESK_PROJECTS`, the closed tasks they worked on that are on the board, those put away, and
227
+ * the runs that ended, of which theirs are kept. Three requests a project, each bounded;
228
+ * `words` narrows the tasks at the console and the runs here; `page` is which page of each.
229
+ */
230
+ export async function readHistory(
231
+ reader: DeskReader,
232
+ input: {
233
+ readonly projects: readonly DeskProject[];
234
+ readonly personId: string;
235
+ readonly words?: string | undefined;
236
+ readonly page?: number | undefined;
237
+ },
238
+ signal?: AbortSignal,
239
+ ): Promise<DeskHistory> {
240
+ const projects = input.projects.slice(0, DESK_PROJECTS);
241
+ const page = Math.max(0, input.page ?? 0);
242
+ const words = wordsOf(input.words ?? "");
243
+ const q = words.length === 0 ? undefined : words.join(" ");
244
+ const read = await Promise.all(
245
+ projects.map(async (project) => {
246
+ const client = reader.project(project.key);
247
+ const filter = {
248
+ worker: input.personId,
249
+ q,
250
+ limit: DESK_TASKS,
251
+ offset: page * DESK_TASKS,
252
+ };
253
+ const [closed, away, ended] = await Promise.all([
254
+ client.taskBriefs({ ...filter, open: false }, signal),
255
+ client.taskBriefs({ ...filter, archived: true }, signal),
256
+ client.runBriefs({ open: false, limit: DESK_RUNS, offset: page * DESK_RUNS }, signal),
257
+ ]);
258
+ const tasks = [...closed.items, ...away.items];
259
+ const titles = new Map(tasks.map((task) => [task.id, task.title]));
260
+ return {
261
+ tasks: tasks.map((task) => ({ project, task })),
262
+ runs: ended.items
263
+ .filter((run) => run.person.id === input.personId)
264
+ .map((run) => ({ project, run, title: titles.get(run.taskId) }))
265
+ .filter((run) => runHolds(run, words)),
266
+ more: closed.more || away.more || ended.more,
267
+ };
268
+ }),
269
+ );
270
+ return {
271
+ tasks: read
272
+ .flatMap((one) => one.tasks)
273
+ .sort((a, b) => closedAt(b.task).localeCompare(closedAt(a.task))),
274
+ runs: read
275
+ .flatMap((one) => one.runs)
276
+ .sort((a, b) => (b.run.endedAt ?? "").localeCompare(a.run.endedAt ?? "")),
277
+ more: read.some((one) => one.more),
278
+ read: projects.length,
279
+ of: input.projects.length,
280
+ };
281
+ }
282
+
283
+ /** Two pages of a person's closed work as one: the later after the earlier, nothing twice, ordered anew. */
284
+ export function withHistory(earlier: DeskHistory, later: DeskHistory): DeskHistory {
285
+ const tasks = new Map(
286
+ [...earlier.tasks, ...later.tasks].map((item) => [item.task.id, item] as const),
287
+ );
288
+ const runs = new Map(
289
+ [...earlier.runs, ...later.runs].map((item) => [item.run.id, item] as const),
290
+ );
291
+ return {
292
+ tasks: [...tasks.values()].sort((a, b) => closedAt(b.task).localeCompare(closedAt(a.task))),
293
+ runs: [...runs.values()].sort((a, b) =>
294
+ (b.run.endedAt ?? "").localeCompare(a.run.endedAt ?? ""),
295
+ ),
296
+ more: later.more,
297
+ read: later.read,
298
+ of: later.of,
299
+ };
300
+ }
301
+
302
+ /**
303
+ * The person's runs that are open, in the projects where a task on their plate says one is:
304
+ * one request a project, `DESK_PROJECTS` at most, each run with its task's title from the plate.
305
+ */
306
+ export async function readOpenRuns(
307
+ reader: DeskReader,
308
+ input: { readonly tasks: readonly DeskTask[]; readonly personId: string },
309
+ signal?: AbortSignal,
310
+ ): Promise<readonly DeskRun[]> {
311
+ const projects = new Map<string, DeskProject>();
312
+ for (const { project, task } of input.tasks) {
313
+ if (task.openRuns > 0 && !projects.has(project.key)) {
314
+ projects.set(project.key, project);
315
+ }
316
+ }
317
+ const titles = new Map(input.tasks.map(({ task }) => [task.id, task.title]));
318
+ const read = await Promise.all(
319
+ [...projects.values()].slice(0, DESK_PROJECTS).map(async (project) => {
320
+ const open = await reader
321
+ .project(project.key)
322
+ .runBriefs({ open: true, limit: DESK_RUNS }, signal);
323
+ return open.items
324
+ .filter((run) => run.person.id === input.personId)
325
+ .map((run) => ({ project, run, title: titles.get(run.taskId) }));
326
+ }),
327
+ );
328
+ return read.flat().sort((a, b) => b.run.lastHeardAt.localeCompare(a.run.lastHeardAt));
329
+ }
@@ -0,0 +1,144 @@
1
+ import { STREAM_RETRY_MOST_MS, STREAM_RETRY_MS, type StreamSource } from "./agent-stream.js";
2
+ import { ApiError, EVENT_KINDS, type RestEvent, restEventSchema } from "./api.js";
3
+
4
+ // How a project's page follows its board: the feed is read as it stands, and what happens
5
+ // after arrives by a stream, numbered, which the console begins after the event it is told. A
6
+ // browser opens a stream again by itself after it was cut, and gives it up for good once it is
7
+ // answered something that is no stream, a gateway's error while the console restarts say. The
8
+ // stream is then opened again here, after the last event read, so that a board a person keeps
9
+ // open does not stand still for good without a word; the console sends what happened while it
10
+ // was away. As an agent's conversation is followed (`agent-stream.ts`). No React here: the
11
+ // page hands in what it does with what arrives, and a test drives it with a stream of its own.
12
+
13
+ /** `EventSource.CLOSED`: the browser gave the stream up and opens it no more. */
14
+ const CLOSED = 2;
15
+
16
+ /** How long a read of the feed waits before it asks again, where the console could not say where the feed stands. */
17
+ export const FEED_UNSETTLED_RETRY_MS = 1_000;
18
+ /** How many times such a read asks before it gives the refusal to whoever asked. */
19
+ export const FEED_UNSETTLED_TRIES = 10;
20
+
21
+ /**
22
+ * A read of the feed, asked again while the console answers that it cannot be read yet
23
+ * (`feed.unsettled`, a 503): a process of the console that has not seen the feed settle since
24
+ * it began, while a change is still under way, cannot say where the feed stands, and says so in
25
+ * place of an empty page. An empty page would be a board on which nothing ever happened, and the
26
+ * page's stream would go on from the beginning and be sent the whole history. It is over within a
27
+ * moment: the change ends, or another process answers. Any other refusal is whoever asked's at
28
+ * once, and so is this one after `FEED_UNSETTLED_TRIES`.
29
+ */
30
+ export async function whileFeedSettles<T>(
31
+ read: () => Promise<T>,
32
+ options: {
33
+ readonly signal?: AbortSignal | undefined;
34
+ /** How a wait is made: a timer where left out. */
35
+ readonly sleep?: ((milliseconds: number) => Promise<void>) | undefined;
36
+ } = {},
37
+ ): Promise<T> {
38
+ const sleep =
39
+ options.sleep ??
40
+ ((milliseconds: number) => new Promise<void>((resolve) => setTimeout(resolve, milliseconds)));
41
+ for (let asked = 1; ; asked += 1) {
42
+ try {
43
+ return await read();
44
+ } catch (failure) {
45
+ const unsettled = failure instanceof ApiError && failure.code === "feed.unsettled";
46
+ if (!unsettled || asked >= FEED_UNSETTLED_TRIES || options.signal?.aborted === true) {
47
+ throw failure;
48
+ }
49
+ }
50
+ await sleep(FEED_UNSETTLED_RETRY_MS);
51
+ }
52
+ }
53
+
54
+ export interface FollowFeedOptions {
55
+ /** Where the stream is, for what happens after an event's number. */
56
+ readonly url: (after: number) => string;
57
+ /** The number of the last event read: the stream begins after it. */
58
+ readonly after: number;
59
+ /** An event not handed over before, in the order they were numbered. */
60
+ readonly onEvent: (event: RestEvent) => void;
61
+ /** Whether the stream is open, said each time it opens and each time it is lost. */
62
+ readonly onLive: (live: boolean) => void;
63
+ /** What opens a stream: the browser's `EventSource` where left out, and no stream where there is none. */
64
+ readonly EventSource?: (new (url: string) => StreamSource) | undefined;
65
+ }
66
+
67
+ /**
68
+ * Follows a project's feed until the function it answers is called: opens the stream after the
69
+ * last event read, and opens it again from there whenever the browser gave it up, a few seconds
70
+ * later and further apart while the console does not answer.
71
+ */
72
+ export function followFeed(options: FollowFeedOptions): () => void {
73
+ const Source =
74
+ options.EventSource ??
75
+ (typeof EventSource === "undefined"
76
+ ? undefined
77
+ : (EventSource as unknown as new (
78
+ url: string,
79
+ ) => StreamSource));
80
+ if (Source === undefined) {
81
+ return () => undefined;
82
+ }
83
+ let stopped = false;
84
+ let last = options.after;
85
+ let source: StreamSource | undefined;
86
+ let retry: ReturnType<typeof setTimeout> | undefined;
87
+ let wait = STREAM_RETRY_MS;
88
+
89
+ const arrived = (message: { readonly data: unknown }): void => {
90
+ let parsed: ReturnType<typeof restEventSchema.safeParse>;
91
+ try {
92
+ parsed = restEventSchema.safeParse(JSON.parse(String(message.data)));
93
+ } catch {
94
+ // What does not read as an event is left out.
95
+ return;
96
+ }
97
+ if (!parsed.success || parsed.data.id <= last) {
98
+ return;
99
+ }
100
+ last = parsed.data.id;
101
+ options.onEvent(parsed.data);
102
+ };
103
+ const open = (): void => {
104
+ const stream = new Source(options.url(last));
105
+ source = stream;
106
+ stream.onopen = () => {
107
+ if (stopped || source !== stream) {
108
+ return;
109
+ }
110
+ wait = STREAM_RETRY_MS;
111
+ options.onLive(true);
112
+ };
113
+ stream.onerror = () => {
114
+ if (stopped || source !== stream) {
115
+ return;
116
+ }
117
+ options.onLive(false);
118
+ if (stream.readyState !== CLOSED) {
119
+ // The browser is opening it again by itself, and says where it was.
120
+ return;
121
+ }
122
+ // The browser opens it no more: it is opened again here, after the last event read.
123
+ stream.close();
124
+ source = undefined;
125
+ retry = setTimeout(() => {
126
+ retry = undefined;
127
+ if (!stopped) {
128
+ open();
129
+ }
130
+ }, wait);
131
+ wait = Math.min(wait * 2, STREAM_RETRY_MOST_MS);
132
+ };
133
+ for (const kind of EVENT_KINDS) {
134
+ stream.addEventListener(kind, arrived);
135
+ }
136
+ };
137
+ open();
138
+ return () => {
139
+ stopped = true;
140
+ clearTimeout(retry);
141
+ source?.close();
142
+ source = undefined;
143
+ };
144
+ }
package/src/home-tiles.ts CHANGED
@@ -442,24 +442,12 @@ export function arranged(
442
442
  const hidden = new Set(home?.hidden ?? []);
443
443
  const { entries, placed: keepsPlaces } = keptAt(home, columns);
444
444
  if (nobodyArranged(home)) {
445
- // Arranging starts from the page as it was composed, each widget on the cells nearest it, the
446
- // projects one to a cell from the corner of theirs, in their order.
447
- const boxes = composed(tiles, home, columns);
448
- const projects = boxes.filter(({ tile }) => tile.kind === "project");
449
- const left = Math.round(Math.min(...projects.map((box) => box.x)));
450
- const top = Math.round(Math.min(...projects.map((box) => box.y)));
451
- const across = Math.max(
452
- 1,
453
- Math.round(Math.max(...projects.map((box) => box.x + box.w))) - left,
454
- );
445
+ // Arranging starts from the page as it was composed, each tile on the cells nearest it: a
446
+ // project on the very cell it stood on (ADR-0108), a lead alone on its own (ADR-0110).
455
447
  const taken = new Set<number>();
456
- return boxes.map(({ tile, size, x, y }) => {
448
+ return composed(tiles, home, columns).map(({ tile, size, x, y }) => {
457
449
  const shape = footprintOf(size, columns);
458
- const nth = projects.findIndex((box) => box.tile.id === tile.id);
459
- const near =
460
- nth < 0
461
- ? { x: Math.round(x), y: Math.round(y) }
462
- : { x: left + (nth % across), y: top + Math.floor(nth / across) };
450
+ const near = { x: Math.round(x), y: Math.round(y) };
463
451
  const place = fits(taken, near, shape, columns)
464
452
  ? near
465
453
  : nearestRoom(taken, shape, near, columns);
@@ -529,6 +517,14 @@ export function nobodyArranged(home: RestHome | null | undefined): boolean {
529
517
  return home === null || home === undefined || Object.keys(home.layouts).length === 0;
530
518
  }
531
519
 
520
+ /** The page put back as composed: no width arranged, nothing taken off (ADR-0109). */
521
+ export const COMPOSED_HOME: RestHome = { hidden: [], layouts: {} };
522
+
523
+ /** Whether the page stands as composed, nothing taken off: nothing for putting it back to undo. */
524
+ export function standsComposed(home: RestHome | null | undefined): boolean {
525
+ return nobodyArranged(home) && (home?.hidden.length ?? 0) === 0;
526
+ }
527
+
532
528
  /**
533
529
  * A tile of the composed page: where it stands and how far it reaches, in cells, which need not
534
530
  * be whole, and the size its frame is told, the one of its own nearest that shape.
@@ -575,9 +571,12 @@ function nearestSize(tile: HomeTile, w: number, h: number, columns: number): Hom
575
571
  /**
576
572
  * The page of someone who has arranged nothing, composed (ADR-0082): the first widget leads,
577
573
  * half the page wide, and beside it stand the next two widgets and the projects, the column as
578
- * high as the lead; on a grid of six columns or fewer they stand one under the other. The projects
579
- * are icons in rows of as many as are alike, each row as wide as its column, so that no row ends
580
- * short; the other widgets stand below, two to a row. Every edge meets another or the page's.
574
+ * high as the lead; on a grid of six columns or fewer they stand one under the other. With nothing
575
+ * beside it, the lead stands at a size it comes in, and the projects follow it in the columns it
576
+ * leaves (ADR-0110). The projects are icons, one to a cell, in rows as long as their column has
577
+ * cells, so that a project is never drawn in a shape it does not come in and the page is the one
578
+ * arranging starts from (ADR-0108); the last row may end short. The other widgets stand below, two
579
+ * to a row.
581
580
  */
582
581
  export function composed(
583
582
  tiles: readonly HomeTile[],
@@ -597,21 +596,31 @@ export function composed(
597
596
  /** The rows the projects take in a column so wide: as many to a row as a cell each allows. */
598
597
  const projectRows = (width: number) =>
599
598
  projects.length === 0 ? 0 : Math.ceil(projects.length / Math.max(1, Math.floor(width)));
600
- /** The projects in rows from a place, as many in each as alike, each row filling the width. */
599
+ /** The projects in rows from a place, one to a cell, each row as long as the width has cells. */
601
600
  const putProjects = (x: number, y: number, width: number): number => {
602
- const rows = projectRows(width);
603
- let next = 0;
604
- for (let row = 0; row < rows; row += 1) {
605
- const count = Math.floor(projects.length / rows) + (row < projects.length % rows ? 1 : 0);
606
- for (let at = 0; at < count; at += 1) {
607
- const tile = projects[next];
608
- if (tile !== undefined) {
609
- put(tile, x + (at * width) / count, y + row, width / count, 1);
610
- }
611
- next += 1;
601
+ const across = Math.max(1, Math.floor(width));
602
+ projects.forEach((tile, nth) => {
603
+ put(tile, x + (nth % across), y + Math.floor(nth / across), 1, 1);
604
+ });
605
+ return projectRows(width);
606
+ };
607
+ /**
608
+ * The projects beside a tile in the page's corner, so wide and so high: one to a cell in the
609
+ * columns it leaves, no lower than it reaches, then across the page below it. The row after them.
610
+ */
611
+ const putProjectsBeside = (w: number, h: number): number => {
612
+ const across = columns - w;
613
+ const beside = Math.min(projects.length, across * h);
614
+ projects.forEach((tile, nth) => {
615
+ const below = nth - beside;
616
+ if (below < 0) {
617
+ put(tile, w + (nth % across), Math.floor(nth / across), 1, 1);
618
+ } else {
619
+ put(tile, below % columns, h + Math.floor(below / columns), 1, 1);
612
620
  }
613
- }
614
- return rows;
621
+ });
622
+ const left = projects.length - beside;
623
+ return h + Math.ceil(left / columns);
615
624
  };
616
625
  /** Widgets two to a row across the page, one alone as wide as the page. */
617
626
  const putInPairs = (list: readonly HomeTile[], from: number): number => {
@@ -655,12 +664,23 @@ export function composed(
655
664
  }
656
665
  y = putInPairs([...others.slice(MOST_BESIDE), ...bottom], y);
657
666
  } else {
667
+ let projectsPut = false;
658
668
  if (lead !== undefined) {
659
- put(lead, 0, 0, columns, LEAD_ROWS);
660
- y = LEAD_ROWS;
669
+ // Nothing beside it, the lead is drawn at the size it is told, on that size's cells, and
670
+ // never stretched to the page's width and four rows (ADR-0110).
671
+ const size = nearestSize(lead, columns, LEAD_ROWS, columns);
672
+ const shape = footprintOf(size, columns);
673
+ boxes.push({ tile: lead, size, x: 0, y: 0, ...shape });
674
+ y = shape.h;
675
+ if (shape.w < columns && projects.length > 0) {
676
+ y = putProjectsBeside(shape.w, shape.h);
677
+ projectsPut = true;
678
+ }
661
679
  }
662
680
  y = putInPairs(others, y);
663
- y += putProjects(0, y, columns);
681
+ if (!projectsPut) {
682
+ y += putProjects(0, y, columns);
683
+ }
664
684
  putInPairs(bottom, y);
665
685
  }
666
686
  return boxes;