@skillcdn/console 0.5.0 → 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 (490) hide show
  1. package/README.md +87 -12
  2. package/SKILLCDN.md +3 -3
  3. package/dist/agent-page.d.ts.map +1 -1
  4. package/dist/agent-page.js +7 -6
  5. package/dist/agent-page.js.map +1 -1
  6. package/dist/api.d.ts +9 -7
  7. package/dist/api.d.ts.map +1 -1
  8. package/dist/api.js +8 -6
  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 +58 -2
  15. package/dist/cli/cli.d.ts.map +1 -1
  16. package/dist/cli/cli.js +1742 -472
  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 +70 -9
  31. package/dist/cli/format.d.ts.map +1 -1
  32. package/dist/cli/format.js +267 -40
  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 +101 -58
  37. package/dist/cli/help.js.map +1 -1
  38. package/dist/cli/machine-check.d.ts +36 -0
  39. package/dist/cli/machine-check.d.ts.map +1 -0
  40. package/dist/cli/machine-check.js +151 -0
  41. package/dist/cli/machine-check.js.map +1 -0
  42. package/dist/cli/main.js +76 -2
  43. package/dist/cli/main.js.map +1 -1
  44. package/dist/cli/pack.d.ts +69 -60
  45. package/dist/cli/pack.d.ts.map +1 -1
  46. package/dist/cli/pack.js +241 -270
  47. package/dist/cli/pack.js.map +1 -1
  48. package/dist/cli/plugin-check.d.ts +42 -0
  49. package/dist/cli/plugin-check.d.ts.map +1 -1
  50. package/dist/cli/plugin-check.js +221 -36
  51. package/dist/cli/plugin-check.js.map +1 -1
  52. package/dist/cli/plugin-cli.d.ts +6 -1
  53. package/dist/cli/plugin-cli.d.ts.map +1 -1
  54. package/dist/cli/plugin-cli.js +21 -4
  55. package/dist/cli/plugin-cli.js.map +1 -1
  56. package/dist/cli/plugin-main.js +1 -0
  57. package/dist/cli/plugin-main.js.map +1 -1
  58. package/dist/cli/runner-host.d.ts +7 -0
  59. package/dist/cli/runner-host.d.ts.map +1 -1
  60. package/dist/cli/runner-host.js +2 -0
  61. package/dist/cli/runner-host.js.map +1 -1
  62. package/dist/cli/secret-notes.d.ts +8 -0
  63. package/dist/cli/secret-notes.d.ts.map +1 -0
  64. package/dist/cli/secret-notes.js +48 -0
  65. package/dist/cli/secret-notes.js.map +1 -0
  66. package/dist/cli/serve.d.ts +33 -1
  67. package/dist/cli/serve.d.ts.map +1 -1
  68. package/dist/cli/serve.js +252 -3
  69. package/dist/cli/serve.js.map +1 -1
  70. package/dist/client.d.ts +54 -9
  71. package/dist/client.d.ts.map +1 -1
  72. package/dist/client.js +77 -80
  73. package/dist/client.js.map +1 -1
  74. package/dist/components/agent-page.d.ts +164 -8
  75. package/dist/components/agent-page.d.ts.map +1 -1
  76. package/dist/components/agent-page.js +588 -151
  77. package/dist/components/agent-page.js.map +1 -1
  78. package/dist/components/agents.d.ts.map +1 -1
  79. package/dist/components/agents.js +1 -1
  80. package/dist/components/agents.js.map +1 -1
  81. package/dist/components/board.d.ts.map +1 -1
  82. package/dist/components/board.js +3 -2
  83. package/dist/components/board.js.map +1 -1
  84. package/dist/components/categories.js +1 -1
  85. package/dist/components/categories.js.map +1 -1
  86. package/dist/components/charts.d.ts +157 -0
  87. package/dist/components/charts.d.ts.map +1 -0
  88. package/dist/components/charts.js +182 -0
  89. package/dist/components/charts.js.map +1 -0
  90. package/dist/components/decision-list.d.ts.map +1 -1
  91. package/dist/components/decision-list.js +1 -1
  92. package/dist/components/decision-list.js.map +1 -1
  93. package/dist/components/desk-records.d.ts +102 -0
  94. package/dist/components/desk-records.d.ts.map +1 -0
  95. package/dist/components/desk-records.js +221 -0
  96. package/dist/components/desk-records.js.map +1 -0
  97. package/dist/components/desk.d.ts +85 -0
  98. package/dist/components/desk.d.ts.map +1 -0
  99. package/dist/components/desk.js +135 -0
  100. package/dist/components/desk.js.map +1 -0
  101. package/dist/components/event-feed.d.ts.map +1 -1
  102. package/dist/components/event-feed.js +7 -3
  103. package/dist/components/event-feed.js.map +1 -1
  104. package/dist/components/goals.d.ts +2 -0
  105. package/dist/components/goals.d.ts.map +1 -1
  106. package/dist/components/goals.js +1 -1
  107. package/dist/components/goals.js.map +1 -1
  108. package/dist/components/home.d.ts.map +1 -1
  109. package/dist/components/home.js +14 -6
  110. package/dist/components/home.js.map +1 -1
  111. package/dist/components/icon.d.ts +31 -0
  112. package/dist/components/icon.d.ts.map +1 -0
  113. package/dist/components/icon.js +169 -0
  114. package/dist/components/icon.js.map +1 -0
  115. package/dist/components/markdown.d.ts +6 -0
  116. package/dist/components/markdown.d.ts.map +1 -1
  117. package/dist/components/markdown.js +10 -2
  118. package/dist/components/markdown.js.map +1 -1
  119. package/dist/components/people.js +1 -1
  120. package/dist/components/people.js.map +1 -1
  121. package/dist/components/plugin-frame.d.ts.map +1 -1
  122. package/dist/components/plugin-frame.js +7 -0
  123. package/dist/components/plugin-frame.js.map +1 -1
  124. package/dist/components/plugin-settings.d.ts.map +1 -1
  125. package/dist/components/plugin-settings.js +54 -3
  126. package/dist/components/plugin-settings.js.map +1 -1
  127. package/dist/components/projects.d.ts +17 -4
  128. package/dist/components/projects.d.ts.map +1 -1
  129. package/dist/components/projects.js +51 -12
  130. package/dist/components/projects.js.map +1 -1
  131. package/dist/components/rules.d.ts +8 -10
  132. package/dist/components/rules.d.ts.map +1 -1
  133. package/dist/components/rules.js +35 -13
  134. package/dist/components/rules.js.map +1 -1
  135. package/dist/components/sessions.d.ts.map +1 -1
  136. package/dist/components/sessions.js +3 -2
  137. package/dist/components/sessions.js.map +1 -1
  138. package/dist/components/setup.d.ts +9 -3
  139. package/dist/components/setup.d.ts.map +1 -1
  140. package/dist/components/setup.js +12 -6
  141. package/dist/components/setup.js.map +1 -1
  142. package/dist/components/shell.d.ts.map +1 -1
  143. package/dist/components/shell.js +3 -2
  144. package/dist/components/shell.js.map +1 -1
  145. package/dist/components/tokens.js +1 -1
  146. package/dist/components/tokens.js.map +1 -1
  147. package/dist/components/ui.d.ts +5 -2
  148. package/dist/components/ui.d.ts.map +1 -1
  149. package/dist/components/ui.js +10 -7
  150. package/dist/components/ui.js.map +1 -1
  151. package/dist/connect-page.js +1 -1
  152. package/dist/connect-page.js.map +1 -1
  153. package/dist/console.css +1172 -106
  154. package/dist/console.d.ts +5 -0
  155. package/dist/console.d.ts.map +1 -1
  156. package/dist/console.js +52 -39
  157. package/dist/console.js.map +1 -1
  158. package/dist/data.d.ts.map +1 -1
  159. package/dist/data.js +32 -33
  160. package/dist/data.js.map +1 -1
  161. package/dist/desk-page.d.ts +38 -0
  162. package/dist/desk-page.d.ts.map +1 -0
  163. package/dist/desk-page.js +184 -0
  164. package/dist/desk-page.js.map +1 -0
  165. package/dist/desk-records-page.d.ts +18 -0
  166. package/dist/desk-records-page.d.ts.map +1 -0
  167. package/dist/desk-records-page.js +130 -0
  168. package/dist/desk-records-page.js.map +1 -0
  169. package/dist/desk-records.d.ts +247 -0
  170. package/dist/desk-records.d.ts.map +1 -0
  171. package/dist/desk-records.js +543 -0
  172. package/dist/desk-records.js.map +1 -0
  173. package/dist/desk.d.ts +122 -0
  174. package/dist/desk.d.ts.map +1 -0
  175. package/dist/desk.js +211 -0
  176. package/dist/desk.js.map +1 -0
  177. package/dist/feed-stream.d.ts +39 -0
  178. package/dist/feed-stream.d.ts.map +1 -0
  179. package/dist/feed-stream.js +117 -0
  180. package/dist/feed-stream.js.map +1 -0
  181. package/dist/home-tiles.d.ts +19 -3
  182. package/dist/home-tiles.d.ts.map +1 -1
  183. package/dist/home-tiles.js +147 -42
  184. package/dist/home-tiles.js.map +1 -1
  185. package/dist/i18n/en.d.ts +228 -6
  186. package/dist/i18n/en.d.ts.map +1 -1
  187. package/dist/i18n/en.js +309 -9
  188. package/dist/i18n/en.js.map +1 -1
  189. package/dist/i18n/ko.d.ts.map +1 -1
  190. package/dist/i18n/ko.js +366 -85
  191. package/dist/i18n/ko.js.map +1 -1
  192. package/dist/i18n/particles.d.ts +7 -0
  193. package/dist/i18n/particles.d.ts.map +1 -0
  194. package/dist/i18n/particles.js +72 -0
  195. package/dist/i18n/particles.js.map +1 -0
  196. package/dist/icons/glyphs.d.ts +605 -0
  197. package/dist/icons/glyphs.d.ts.map +1 -0
  198. package/dist/icons/glyphs.js +104 -0
  199. package/dist/icons/glyphs.js.map +1 -0
  200. package/dist/icons/index.d.ts +59 -0
  201. package/dist/icons/index.d.ts.map +1 -0
  202. package/dist/icons/index.js +157 -0
  203. package/dist/icons/index.js.map +1 -0
  204. package/dist/index.d.ts +9 -0
  205. package/dist/index.d.ts.map +1 -1
  206. package/dist/index.js +9 -0
  207. package/dist/index.js.map +1 -1
  208. package/dist/limits.d.ts +20 -0
  209. package/dist/limits.d.ts.map +1 -1
  210. package/dist/limits.js +20 -0
  211. package/dist/limits.js.map +1 -1
  212. package/dist/marks.d.ts +9 -0
  213. package/dist/marks.d.ts.map +1 -1
  214. package/dist/marks.js +9 -0
  215. package/dist/marks.js.map +1 -1
  216. package/dist/onboarding.d.ts +6 -0
  217. package/dist/onboarding.d.ts.map +1 -1
  218. package/dist/onboarding.js +5 -5
  219. package/dist/onboarding.js.map +1 -1
  220. package/dist/plugin/context.d.ts +42 -11
  221. package/dist/plugin/context.d.ts.map +1 -1
  222. package/dist/plugin/limits.d.ts +2 -0
  223. package/dist/plugin/limits.d.ts.map +1 -1
  224. package/dist/plugin/limits.js +2 -0
  225. package/dist/plugin/limits.js.map +1 -1
  226. package/dist/plugin/manifest.d.ts +13 -0
  227. package/dist/plugin/manifest.d.ts.map +1 -1
  228. package/dist/plugin/manifest.js +30 -3
  229. package/dist/plugin/manifest.js.map +1 -1
  230. package/dist/plugin/rest-schemas.d.ts +55 -0
  231. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  232. package/dist/plugin/rest-schemas.js +37 -0
  233. package/dist/plugin/rest-schemas.js.map +1 -1
  234. package/dist/plugin/sandbox.d.ts.map +1 -1
  235. package/dist/plugin/sandbox.js +4 -1
  236. package/dist/plugin/sandbox.js.map +1 -1
  237. package/dist/plugin/testing.d.ts +6 -2
  238. package/dist/plugin/testing.d.ts.map +1 -1
  239. package/dist/plugin/testing.js +52 -10
  240. package/dist/plugin/testing.js.map +1 -1
  241. package/dist/plugin/web.d.ts +3 -0
  242. package/dist/plugin/web.d.ts.map +1 -1
  243. package/dist/plugin/web.js +5 -1
  244. package/dist/plugin/web.js.map +1 -1
  245. package/dist/plugin.d.ts +1 -1
  246. package/dist/plugin.d.ts.map +1 -1
  247. package/dist/plugin.js +1 -1
  248. package/dist/plugin.js.map +1 -1
  249. package/dist/records.d.ts +283 -0
  250. package/dist/records.d.ts.map +1 -0
  251. package/dist/records.js +543 -0
  252. package/dist/records.js.map +1 -0
  253. package/dist/routes.d.ts +3 -1
  254. package/dist/routes.d.ts.map +1 -1
  255. package/dist/routes.js +3 -1
  256. package/dist/routes.js.map +1 -1
  257. package/dist/rules.d.ts +30 -11
  258. package/dist/rules.d.ts.map +1 -1
  259. package/dist/rules.js +98 -45
  260. package/dist/rules.js.map +1 -1
  261. package/dist/runner/acp.d.ts +1 -1
  262. package/dist/runner/acp.d.ts.map +1 -1
  263. package/dist/runner/acp.js +32 -21
  264. package/dist/runner/acp.js.map +1 -1
  265. package/dist/runner/awake.d.ts +35 -0
  266. package/dist/runner/awake.d.ts.map +1 -0
  267. package/dist/runner/awake.js +95 -0
  268. package/dist/runner/awake.js.map +1 -0
  269. package/dist/runner/claude.d.ts +1 -1
  270. package/dist/runner/claude.d.ts.map +1 -1
  271. package/dist/runner/claude.js +100 -18
  272. package/dist/runner/claude.js.map +1 -1
  273. package/dist/runner/codex.d.ts +1 -1
  274. package/dist/runner/codex.d.ts.map +1 -1
  275. package/dist/runner/codex.js +20 -17
  276. package/dist/runner/codex.js.map +1 -1
  277. package/dist/runner/config.d.ts +5 -0
  278. package/dist/runner/config.d.ts.map +1 -1
  279. package/dist/runner/config.js +9 -0
  280. package/dist/runner/config.js.map +1 -1
  281. package/dist/runner/desk.d.ts +43 -2
  282. package/dist/runner/desk.d.ts.map +1 -1
  283. package/dist/runner/desk.js +168 -13
  284. package/dist/runner/desk.js.map +1 -1
  285. package/dist/runner/process.d.ts.map +1 -1
  286. package/dist/runner/process.js +11 -4
  287. package/dist/runner/process.js.map +1 -1
  288. package/dist/runner/redact.d.ts +39 -4
  289. package/dist/runner/redact.d.ts.map +1 -1
  290. package/dist/runner/redact.js +81 -5
  291. package/dist/runner/redact.js.map +1 -1
  292. package/dist/runner/runner.d.ts +28 -3
  293. package/dist/runner/runner.d.ts.map +1 -1
  294. package/dist/runner/runner.js +371 -54
  295. package/dist/runner/runner.js.map +1 -1
  296. package/dist/runner/slack.d.ts.map +1 -1
  297. package/dist/runner/slack.js +10 -4
  298. package/dist/runner/slack.js.map +1 -1
  299. package/dist/runner/task-scheduler.d.ts +20 -0
  300. package/dist/runner/task-scheduler.d.ts.map +1 -1
  301. package/dist/runner/task-scheduler.js +34 -4
  302. package/dist/runner/task-scheduler.js.map +1 -1
  303. package/dist/runner/types.d.ts +51 -1
  304. package/dist/runner/types.d.ts.map +1 -1
  305. package/dist/runner/types.js +26 -0
  306. package/dist/runner/types.js.map +1 -1
  307. package/dist/runner.d.ts +6 -6
  308. package/dist/runner.d.ts.map +1 -1
  309. package/dist/runner.js +5 -5
  310. package/dist/runner.js.map +1 -1
  311. package/dist/schemas.d.ts +603 -6
  312. package/dist/schemas.d.ts.map +1 -1
  313. package/dist/schemas.js +156 -20
  314. package/dist/schemas.js.map +1 -1
  315. package/dist/services.d.ts +22 -5
  316. package/dist/services.d.ts.map +1 -1
  317. package/dist/services.js +41 -17
  318. package/dist/services.js.map +1 -1
  319. package/dist/setup-guide.d.ts +17 -4
  320. package/dist/setup-guide.d.ts.map +1 -1
  321. package/dist/setup-guide.js +48 -41
  322. package/dist/setup-guide.js.map +1 -1
  323. package/dist/tokens.d.ts.map +1 -1
  324. package/dist/tokens.js +5 -1
  325. package/dist/tokens.js.map +1 -1
  326. package/dist/vocabulary.d.ts +21 -3
  327. package/dist/vocabulary.d.ts.map +1 -1
  328. package/dist/vocabulary.js +19 -3
  329. package/dist/vocabulary.js.map +1 -1
  330. package/docs/specs/cli.md +73 -44
  331. package/docs/specs/plugins.md +40 -22
  332. package/docs/specs/records.md +113 -0
  333. package/docs/specs/rest.md +30 -21
  334. package/docs/specs/runner.md +46 -22
  335. package/package.json +11 -2
  336. package/skills/building-a-console/SKILL.md +4 -4
  337. package/skills/building-a-plugin/SKILL.md +6 -6
  338. package/skills/deploying-a-console/SKILL.md +4 -4
  339. package/skills/deploying-a-console/references/resources.md +41 -4
  340. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  341. package/skills/keeping-a-desk/SKILL.md +133 -0
  342. package/skills/keeping-a-desk/collections.md +96 -0
  343. package/skills/planning-the-board/SKILL.md +14 -18
  344. package/skills/planning-the-board/references/a-task.md +2 -2
  345. package/skills/planning-the-board/references/project-rules.md +13 -14
  346. package/skills/planning-the-board/references/setting-up.md +15 -13
  347. package/skills/running-an-agent/SKILL.md +47 -56
  348. package/skills/working-the-board/SKILL.md +63 -44
  349. package/skills/working-the-board/references/terms.md +9 -5
  350. package/skills/working-the-board/references/the-pack.md +12 -10
  351. package/skills/working-the-board/references/the-sentence.md +2 -2
  352. package/src/agent-page.tsx +16 -2
  353. package/src/api.ts +109 -3
  354. package/src/charts.ts +250 -0
  355. package/src/cli/cli.ts +2226 -580
  356. package/src/cli/command-words.ts +56 -0
  357. package/src/cli/credentials.ts +181 -20
  358. package/src/cli/directory.ts +28 -10
  359. package/src/cli/format.ts +332 -49
  360. package/src/cli/help.ts +113 -57
  361. package/src/cli/machine-check.ts +223 -0
  362. package/src/cli/main.ts +72 -2
  363. package/src/cli/pack.ts +333 -372
  364. package/src/cli/plugin-check.ts +275 -34
  365. package/src/cli/plugin-cli.ts +28 -4
  366. package/src/cli/plugin-main.ts +1 -0
  367. package/src/cli/runner-host.ts +8 -0
  368. package/src/cli/secret-notes.ts +63 -0
  369. package/src/cli/serve.ts +295 -2
  370. package/src/client.ts +215 -177
  371. package/src/components/agent-page.tsx +1044 -281
  372. package/src/components/agents.tsx +9 -5
  373. package/src/components/board.tsx +3 -15
  374. package/src/components/categories.tsx +2 -2
  375. package/src/components/charts.tsx +680 -0
  376. package/src/components/decision-list.tsx +11 -7
  377. package/src/components/desk-records.tsx +724 -0
  378. package/src/components/desk.tsx +471 -0
  379. package/src/components/event-feed.tsx +12 -3
  380. package/src/components/goals.tsx +33 -25
  381. package/src/components/home.tsx +42 -6
  382. package/src/components/icon.tsx +337 -0
  383. package/src/components/markdown.tsx +22 -2
  384. package/src/components/people.tsx +1 -1
  385. package/src/components/plugin-frame.tsx +7 -0
  386. package/src/components/plugin-settings.tsx +171 -12
  387. package/src/components/projects.tsx +68 -17
  388. package/src/components/rules.tsx +94 -34
  389. package/src/components/sessions.tsx +2 -13
  390. package/src/components/setup.tsx +20 -5
  391. package/src/components/shell.tsx +3 -20
  392. package/src/components/tokens.tsx +1 -1
  393. package/src/components/ui.tsx +16 -8
  394. package/src/connect-page.tsx +1 -1
  395. package/src/console.tsx +104 -62
  396. package/src/data.ts +37 -34
  397. package/src/desk-page.tsx +332 -0
  398. package/src/desk-records-page.tsx +256 -0
  399. package/src/desk-records.ts +808 -0
  400. package/src/desk.ts +329 -0
  401. package/src/feed-stream.ts +144 -0
  402. package/src/home-tiles.ts +170 -46
  403. package/src/i18n/en.ts +323 -11
  404. package/src/i18n/ko.ts +378 -87
  405. package/src/i18n/particles.ts +79 -0
  406. package/src/icons/glyphs.ts +112 -0
  407. package/src/icons/index.ts +195 -0
  408. package/src/index.ts +125 -0
  409. package/src/limits.ts +20 -0
  410. package/src/marks.ts +12 -0
  411. package/src/onboarding.ts +14 -6
  412. package/src/plugin/context.ts +55 -12
  413. package/src/plugin/limits.ts +2 -0
  414. package/src/plugin/manifest.ts +38 -2
  415. package/src/plugin/rest-schemas.ts +41 -0
  416. package/src/plugin/sandbox.ts +4 -1
  417. package/src/plugin/testing.ts +63 -12
  418. package/src/plugin/web.ts +9 -2
  419. package/src/plugin.ts +2 -0
  420. package/src/records.ts +702 -0
  421. package/src/routes.ts +3 -1
  422. package/src/rules.ts +108 -47
  423. package/src/runner/acp.ts +49 -30
  424. package/src/runner/awake.ts +135 -0
  425. package/src/runner/claude.ts +131 -26
  426. package/src/runner/codex.ts +37 -26
  427. package/src/runner/config.ts +9 -0
  428. package/src/runner/desk.ts +200 -15
  429. package/src/runner/process.ts +11 -4
  430. package/src/runner/redact.ts +92 -6
  431. package/src/runner/runner.ts +457 -56
  432. package/src/runner/slack.ts +10 -4
  433. package/src/runner/task-scheduler.ts +36 -4
  434. package/src/runner/types.ts +67 -1
  435. package/src/runner.ts +27 -2
  436. package/src/schemas.ts +177 -18
  437. package/src/services.ts +55 -16
  438. package/src/setup-guide.ts +49 -40
  439. package/src/styles/README.md +16 -5
  440. package/src/styles/base.css +17 -0
  441. package/src/styles/console.css +10 -0
  442. package/src/styles/drawn-by-pages.json +1 -1
  443. package/src/styles/pages/agents.css +103 -1
  444. package/src/styles/pages/board.css +0 -10
  445. package/src/styles/pages/calendar.css +1 -1
  446. package/src/styles/pages/connect.css +0 -10
  447. package/src/styles/pages/decisions.css +3 -1
  448. package/src/styles/pages/desk.css +126 -0
  449. package/src/styles/pages/documents.css +5 -0
  450. package/src/styles/pages/feed.css +5 -2
  451. package/src/styles/pages/home.css +5 -0
  452. package/src/styles/pages/roadmap.css +2 -2
  453. package/src/styles/pages/settings.css +11 -0
  454. package/src/styles/pages/task.css +0 -20
  455. package/src/styles/pages/thread.css +1 -1
  456. package/src/styles/parts/bars.css +80 -0
  457. package/src/styles/parts/calendar.css +1 -1
  458. package/src/styles/parts/callout.css +1 -0
  459. package/src/styles/parts/chart.css +173 -0
  460. package/src/styles/parts/detail.css +22 -0
  461. package/src/styles/parts/empty.css +2 -0
  462. package/src/styles/parts/eyebrow.css +1 -1
  463. package/src/styles/parts/facts.css +1 -1
  464. package/src/styles/parts/figures.css +65 -0
  465. package/src/styles/parts/form.css +2 -1
  466. package/src/styles/parts/icon.css +191 -0
  467. package/src/styles/parts/input.css +14 -4
  468. package/src/styles/parts/legend.css +48 -0
  469. package/src/styles/parts/mark.css +36 -0
  470. package/src/styles/parts/menu.css +1 -7
  471. package/src/styles/parts/page.css +1 -1
  472. package/src/styles/parts/panel.css +10 -0
  473. package/src/styles/parts/person.css +5 -2
  474. package/src/styles/parts/progress.css +5 -2
  475. package/src/styles/parts/rows.css +1 -0
  476. package/src/styles/parts/series.css +32 -0
  477. package/src/styles/parts/settings.css +5 -0
  478. package/src/styles/parts/share.css +25 -0
  479. package/src/styles/parts/spark.css +23 -0
  480. package/src/styles/parts/stat.css +69 -0
  481. package/src/styles/tokens.css +31 -10
  482. package/src/tokens.ts +5 -1
  483. package/src/vocabulary.ts +25 -3
  484. package/template/desk-web/README.md +8 -0
  485. package/template/desk-web/index.html +13 -0
  486. package/template/desk-web/package.json +25 -0
  487. package/template/desk-web/src/main.tsx +24 -0
  488. package/template/desk-web/src/page.tsx +51 -0
  489. package/template/desk-web/tsconfig.json +16 -0
  490. package/template/desk-web/vite.config.ts +15 -0
package/src/cli/cli.ts CHANGED
@@ -1,6 +1,21 @@
1
- import { basename, extname } from "node:path";
1
+ import { basename, extname, isAbsolute } from "node:path";
2
2
  import { parseArgs } from "node:util";
3
3
  import { deflateSync } from "node:zlib";
4
+ import {
5
+ PackError,
6
+ type PackRead,
7
+ ReadMisuse,
8
+ type ReadOutput,
9
+ readNumber,
10
+ readPack,
11
+ wroteLine,
12
+ } from "@skillcdn/cli";
13
+ import {
14
+ BROWSE_MAX_LIMIT,
15
+ FIND_MAX_LIMIT,
16
+ READ_FILE_MAX_LIMIT,
17
+ type ToolWords,
18
+ } from "@skillcdn/core";
4
19
  import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
5
20
  import {
6
21
  ApiError,
@@ -8,6 +23,7 @@ import {
8
23
  createClient,
9
24
  type FetchLike,
10
25
  type FileUpload,
26
+ type PackClient,
11
27
  type PluginClient,
12
28
  type ProjectClient,
13
29
  } from "../client.js";
@@ -24,22 +40,41 @@ import {
24
40
  } from "../compat.js";
25
41
  import { normalizeConnectCode } from "../connect.js";
26
42
  import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
43
+ import { ICON_NAMES, type IconName, isIconName } from "../icons/index.js";
27
44
  import {
28
45
  DEFAULT_PAGE_LIMIT,
46
+ EVENTS_PAGE_LIMIT,
29
47
  LIST_LIMIT,
30
48
  MAX_DECIDERS,
31
49
  MAX_OPTIONS,
50
+ MAX_OWN_WAKE_DAYS,
32
51
  MAX_RUNNER_LINE_LENGTH,
33
52
  MAX_SIGNALS_PAGE_LIMIT,
34
53
  MIN_OPTIONS,
54
+ OWN_WAKE_KEY,
35
55
  } from "../limits.js";
56
+ import { onboardingTitle } from "../onboarding.js";
36
57
  import { capabilityWords } from "../plugin/capabilities.js";
37
58
  import { PLUGIN_LIST_LIMIT } from "../plugin/limits.js";
59
+ import { checkRecords, RECORDS_DIR, RECORDS_INDEX_FILE, type RecordsFiles } from "../records.js";
60
+ import { agentHref, decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
38
61
  import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
39
62
  import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
40
- import { deskFiles, deskServicesOf } from "../runner/desk.js";
63
+ import {
64
+ DESK_FOLDER,
65
+ deskFiles,
66
+ deskServicesOf,
67
+ deskWebTitleOf,
68
+ personDeskFiles,
69
+ } from "../runner/desk.js";
41
70
  import { ownRunnerModules } from "../runner/modules.js";
42
- import { createRunner, GIT_TOKEN_SECRET, type RunnerState } from "../runner/runner.js";
71
+ import {
72
+ createRunner,
73
+ GIT_TOKEN_SECRET,
74
+ type Runner,
75
+ type RunnerEnd,
76
+ type RunnerState,
77
+ } from "../runner/runner.js";
43
78
  import type { ServiceCommand } from "../runner/types.js";
44
79
  import {
45
80
  hostOfLogin,
@@ -54,12 +89,10 @@ import {
54
89
  type RestPluginEnableInput,
55
90
  type RestPluginGrantInput,
56
91
  type RestPluginInvocation,
57
- type RestSkillBrowse,
58
- type RestSkillCode,
59
- type RestSkillFile,
60
- type RestSkillLoad,
61
- type RestSkillRows,
62
- type RestSkills,
92
+ type RestRules,
93
+ type RestRun,
94
+ type RestRunBrief,
95
+ type RestTask,
63
96
  type RestTaskPatch,
64
97
  } from "../schemas.js";
65
98
  import { agentLoginOf, deskRemoteOf } from "../services.js";
@@ -89,18 +122,31 @@ import {
89
122
  WEEK_STARTS,
90
123
  } from "../vocabulary.js";
91
124
  import { loadWebRoot, type WebRoot, WebRootError } from "../web.js";
125
+ import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
92
126
  import {
93
127
  type CredentialStore,
94
128
  type Credentials,
95
129
  CredentialsError,
96
130
  EMPTY_CREDENTIALS,
131
+ fitsFile,
132
+ keepsNothing,
133
+ lasts,
97
134
  loginsAt,
135
+ type PendingConnection,
136
+ pendingAt,
98
137
  type Resolution,
99
138
  resolveLogin,
100
139
  withLogin,
101
140
  withoutLogin,
141
+ withoutPending,
142
+ withPending,
102
143
  } from "./credentials.js";
103
- import { type DirectorySettings, type DirectoryStore, THE_SENTENCE } from "./directory.js";
144
+ import {
145
+ DIRECTORY_FILE,
146
+ type DirectorySettings,
147
+ type DirectoryStore,
148
+ THE_SENTENCE,
149
+ } from "./directory.js";
104
150
  import {
105
151
  calledOf,
106
152
  deciderLogins,
@@ -120,10 +166,12 @@ import {
120
166
  formatMemberLine,
121
167
  formatMore,
122
168
  formatOptions,
169
+ formatOwnWakeLine,
123
170
  formatPersonLine,
124
171
  formatPersonWork,
125
172
  formatPlugin,
126
173
  formatPluginAsks,
174
+ formatPluginEvents,
127
175
  formatPluginGrantLine,
128
176
  formatPluginHelp,
129
177
  formatPluginRecord,
@@ -134,6 +182,8 @@ import {
134
182
  formatProject,
135
183
  formatProjectLine,
136
184
  formatRules,
185
+ formatRulesChanged,
186
+ formatRulesLeftOut,
137
187
  formatRun,
138
188
  formatRunLine,
139
189
  formatSecretLine,
@@ -147,36 +197,36 @@ import {
147
197
  formatWorkspace,
148
198
  localized,
149
199
  moment,
200
+ pageLine,
201
+ rulesMark,
150
202
  setMomentZone,
151
203
  } from "./format.js";
152
204
  import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
153
205
  import { describeInstall, type Install, updateCommandFor } from "./install.js";
206
+ import { awakeWords, heldAwake, lookAtMachine, type MachineLook } from "./machine-check.js";
154
207
  import type { NoticeStore } from "./notices.js";
155
208
  import {
156
- bodyOfFile,
157
- bodyOfFolder,
158
- bodyOfSkill,
159
- csvOfRows,
160
- dataRefusal,
161
- describeCode,
162
- describeRows,
163
- formatSkillBrowse,
164
- formatSkillFile,
165
- formatSkillFind,
166
- formatSkillLoad,
209
+ type ConsolePack,
210
+ consolePack,
167
211
  formatSkills,
168
- joinCode,
169
- joinFile,
170
- joinFolder,
171
- joinRows,
172
- joinSkill,
173
- type PackSummary,
212
+ holdsNothing,
213
+ ORGANIZATION_PACK_LINE,
214
+ type PackOwner,
215
+ PackRefusal,
216
+ packWords,
217
+ refusalWords,
174
218
  skillPathIn,
175
- summaryOf,
176
- textOfCode,
177
219
  } from "./pack.js";
178
220
  import { type RunnerHost, workPath } from "./runner-host.js";
179
- import { createServeHandler, DEFAULT_SERVE_PORT, type Listen } from "./serve.js";
221
+ import { secretNotes } from "./secret-notes.js";
222
+ import {
223
+ createServeHandler,
224
+ DEFAULT_SERVE_PORT,
225
+ type Listen,
226
+ loadRecordsRoot,
227
+ type RecordsRoot,
228
+ RecordsRootError,
229
+ } from "./serve.js";
180
230
  import type { Ran, SetupMachine } from "./setup-machine.js";
181
231
 
182
232
  // The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
@@ -192,7 +242,7 @@ export const EXIT = {
192
242
  failed: 1,
193
243
  /** The command was not understood. */
194
244
  usage: 2,
195
- /** The decision still waits for a person. */
245
+ /** What was waited for still waits for a person: a decision's answer, or a connection's approval. */
196
246
  waiting: 3,
197
247
  /** The command and the console do not go together (ADR-0025): stderr says which to update, and how. */
198
248
  incompatible: 4,
@@ -209,6 +259,12 @@ const WAIT_PAUSE_MS = 500;
209
259
  const DEFAULT_ASK_WAIT_SECONDS = 60;
210
260
  /** The longest wait a person may ask for: a day. */
211
261
  const MAX_WAIT_SECONDS = 86_400;
262
+ /**
263
+ * How long `login` waits for the approval of a connection a call before it began, where no
264
+ * terminal shows its words as they are printed (ADR-0129): within the two minutes an agent's
265
+ * host gives a command before it cuts it off.
266
+ */
267
+ const DEFAULT_LOGIN_WAIT_SECONDS = 90;
212
268
 
213
269
  export interface CliIo {
214
270
  readonly env: Readonly<Record<string, string | undefined>>;
@@ -225,6 +281,14 @@ export interface CliIo {
225
281
  readonly readSecret?: ((prompt: string) => Promise<string>) | undefined;
226
282
  /** The name of the machine, for the agent to say where it runs; nothing when unknown. */
227
283
  readonly hostname?: string | undefined;
284
+ /** The machine's own time zone, for a moment printed before the workspace's is known. */
285
+ readonly timeZone?: string | undefined;
286
+ /**
287
+ * Whether a terminal shows the command's words as they are printed. Where none does, whoever
288
+ * runs the command sees them when it ends, so `login` says its code and ends, and waits for
289
+ * the approval in the next call (ADR-0129). Left out, one is taken to be there.
290
+ */
291
+ readonly terminal?: boolean | undefined;
228
292
  /** A file named with `--file`, as text. */
229
293
  readonly readFile: (path: string) => Promise<string>;
230
294
  /** A file handed in, as bytes. */
@@ -262,8 +326,22 @@ export interface CliIo {
262
326
  readonly listen?: Listen | undefined;
263
327
  /** What `runner` needs of the machine (ADR-0085); left out, the command cannot run one. */
264
328
  readonly runner?: RunnerHost | undefined;
265
- /** What `agent setup` needs of the machine (ADR-0088); left out, the command sets none up. */
329
+ /** What `agent setup` needs of the machine (ADR-0088), and `desk` of its files; left out, the command sets none up and writes no desk. */
266
330
  readonly machine?: SetupMachine | undefined;
331
+ /**
332
+ * The shell of a desk's pages as the package carries it (ADR-0115), `template/desk-web`
333
+ * beside `dist/`: its files as text, by their path in it with forward slashes; nothing where
334
+ * the package carries none. Left out, `desk --web` has no shell to write.
335
+ */
336
+ readonly deskWebTemplate?: (() => Promise<ReadonlyMap<string, string> | undefined>) | undefined;
337
+ /**
338
+ * The records of a desk on this machine (ADR-0117), for `desk check`: the desk's directory in
339
+ * full, and the files of its `records/` as the format's check reads them. Left out, the
340
+ * command checks none.
341
+ */
342
+ readonly recordsAt?:
343
+ | ((directory: string) => { readonly directory: string; readonly files: RecordsFiles })
344
+ | undefined;
267
345
  }
268
346
 
269
347
  /** The command stops with an exit code and a word on stderr. */
@@ -344,6 +422,101 @@ interface Session {
344
422
  project(): Promise<ProjectClient>;
345
423
  /** The key of that project, or nothing when none is named. */
346
424
  projectKey(): Promise<string | undefined>;
425
+ /** The key with what named it, for `whoami` to say (ADR-0112); nothing when none is named. */
426
+ projectNamed(): { readonly key: string; readonly source: ProjectSource } | undefined;
427
+ }
428
+
429
+ /**
430
+ * What named the project a command works in, in the order they win: the flag, the environment,
431
+ * the directory's file, with the directory that holds it where the store says.
432
+ */
433
+ type ProjectSource =
434
+ | { readonly kind: "flag" }
435
+ | { readonly kind: "environment" }
436
+ | { readonly kind: "directory"; readonly directory: string | undefined };
437
+
438
+ /**
439
+ * What is said of a project the console does not have, or does not show the member: the key,
440
+ * the console and what named the key, then the two things a person can do about it, each
441
+ * something to ask for or to do. An agent that reads only "not found" guesses at causes; one of
442
+ * these two is always the one. `login` is the member's, where the command knows it. Both are
443
+ * said as what is done and by whom, never as a command to whoever reads: an agent told to do
444
+ * as it saw fit took "bind this directory anew" for its own step, bound the checkout to another
445
+ * project and went on with no task. Which key is right is the repository's agreement's to say,
446
+ * or the person's.
447
+ */
448
+ function unseenProjectWords(
449
+ url: string,
450
+ named: { readonly key: string; readonly source: ProjectSource },
451
+ login: string | undefined,
452
+ ): string {
453
+ const right =
454
+ "the right one, the key the repository's agreement names or the one the person says";
455
+ const mend =
456
+ named.source.kind === "directory"
457
+ ? `the directory is bound to ${right}, with console use <key>`
458
+ : named.source.kind === "environment"
459
+ ? `CONSOLE_PROJECT is set to ${right}, or unset`
460
+ : `--project is given ${right}`;
461
+ return [
462
+ `project.not_found: ${url} has no project ${named.key}, or it is not yours to see. The key is named by ${sourceWords(named.source)}.`,
463
+ `Where the project is there and you are not in it, one of its owners lists you: console member add ${login ?? "<your login>"} --project ${named.key}. Where the key is wrong, ${mend}; console projects lists the projects you may work in at this console.`,
464
+ ].join("\n");
465
+ }
466
+
467
+ /**
468
+ * The console's refusal of the project a directory or the environment names, with the words
469
+ * above: still the refusal it was, for the code that reads one (a decision is looked for
470
+ * elsewhere when its project is not found), and said in full where the command ends on it.
471
+ */
472
+ class UnseenProject extends ApiError {
473
+ readonly words: string;
474
+
475
+ constructor(refusal: ApiError, words: string) {
476
+ super(refusal.status, refusal.code, refusal.message);
477
+ this.name = "UnseenProject";
478
+ this.words = words;
479
+ }
480
+ }
481
+
482
+ /**
483
+ * A project's client whose refusals as `project.not_found` carry `words`: every command that
484
+ * works in the directory's project goes through one, so that the refusal names the key, the
485
+ * console and what named it wherever it is met, and no command says it for itself.
486
+ */
487
+ function namingUnseen(project: ProjectClient, words: () => string): ProjectClient {
488
+ return new Proxy(project, {
489
+ get(target, property, receiver) {
490
+ const member: unknown = Reflect.get(target, property, receiver);
491
+ if (typeof member !== "function") {
492
+ return member;
493
+ }
494
+ return (...args: unknown[]): unknown => {
495
+ const result: unknown = Reflect.apply(member, target, args);
496
+ return result instanceof Promise
497
+ ? result.catch((error: unknown) => {
498
+ throw error instanceof ApiError && error.code === "project.not_found"
499
+ ? new UnseenProject(error, words())
500
+ : error;
501
+ })
502
+ : result;
503
+ };
504
+ },
505
+ });
506
+ }
507
+
508
+ /** Where a project's key came from, as `whoami` and its refusal say it. */
509
+ function sourceWords(source: ProjectSource): string {
510
+ switch (source.kind) {
511
+ case "flag":
512
+ return "--project";
513
+ case "environment":
514
+ return "CONSOLE_PROJECT";
515
+ case "directory":
516
+ return source.directory === undefined
517
+ ? DIRECTORY_FILE
518
+ : `${DIRECTORY_FILE} in ${source.directory}`;
519
+ }
347
520
  }
348
521
 
349
522
  const NO_PROJECT =
@@ -363,6 +536,21 @@ async function loadCredentials(io: CliIo): Promise<Credentials | undefined> {
363
536
  }
364
537
  }
365
538
 
539
+ /**
540
+ * What is about to be kept, where the credentials file would read it back; else the command
541
+ * stops, and nothing is written. What a console answered comes to rest in that file, and
542
+ * anything at an address may answer to nobody: kept beyond the file's own bounds, it would have
543
+ * every later command stop on a file it cannot read, at every console.
544
+ */
545
+ function fitting(next: Credentials, url: string): Credentials {
546
+ if (!fitsFile(next)) {
547
+ throw failed(
548
+ `${url} answered what the command cannot keep: a code, a token or a name beyond the bounds a console's have. Nothing was kept. Check that the address is the console's, and sign in again.`,
549
+ );
550
+ }
551
+ return next;
552
+ }
553
+
366
554
  /** The console a directory is bound to, as an origin, when it names one. */
367
555
  function directoryOrigin(settings: DirectorySettings | undefined): string | undefined {
368
556
  if (settings?.url === undefined) {
@@ -427,8 +615,19 @@ async function open(io: CliIo, values: Values): Promise<Session> {
427
615
  : undefined,
428
616
  );
429
617
  const client = clientOf(io, url, token);
430
- const projectKey = async () =>
431
- text(values, "project") ?? io.env.CONSOLE_PROJECT ?? directory?.project;
618
+ const projectNamed = (): ReturnType<Session["projectNamed"]> => {
619
+ const flagged = text(values, "project");
620
+ if (flagged !== undefined) {
621
+ return { key: flagged, source: { kind: "flag" } };
622
+ }
623
+ if (io.env.CONSOLE_PROJECT !== undefined) {
624
+ return { key: io.env.CONSOLE_PROJECT, source: { kind: "environment" } };
625
+ }
626
+ return directory === undefined
627
+ ? undefined
628
+ : { key: directory.project, source: { kind: "directory", directory: directory.directory } };
629
+ };
630
+ const projectKey = async () => projectNamed()?.key;
432
631
  return {
433
632
  client,
434
633
  url,
@@ -438,12 +637,19 @@ async function open(io: CliIo, values: Values): Promise<Session> {
438
637
  credentials,
439
638
  json: on(values, "json"),
440
639
  projectKey,
640
+ projectNamed,
441
641
  async project() {
442
- const key = await projectKey();
443
- if (key === undefined) {
642
+ const named = projectNamed();
643
+ if (named === undefined) {
444
644
  throw failed(NO_PROJECT);
445
645
  }
446
- return client.project(key);
646
+ // A key typed on the command is in front of whoever typed it; one the directory or the
647
+ // environment named is not, and is said with the refusal.
648
+ return named.source.kind === "flag"
649
+ ? client.project(named.key)
650
+ : namingUnseen(client.project(named.key), () =>
651
+ unseenProjectWords(url, named, resolved.account),
652
+ );
447
653
  },
448
654
  };
449
655
  }
@@ -454,17 +660,38 @@ function answer(io: CliIo, session: Session, value: unknown, words: () => string
454
660
  }
455
661
 
456
662
  /** The run a command on a run means: the one named, else the one open run of this token in the project. */
457
- async function currentRun(project: ProjectClient, values: Values): Promise<string> {
663
+ async function currentRun(
664
+ session: Session,
665
+ project: ProjectClient,
666
+ values: Values,
667
+ ): Promise<string> {
458
668
  const given = text(values, "run");
459
669
  if (given !== undefined) {
460
670
  return given;
461
671
  }
462
- const { items } = await project.runs({ open: true, mine: true });
672
+ // The brief form: a command on a run asks which run is open every time, and needs no report
673
+ // of it, where a long run has many.
674
+ const { items } = await project.runBriefs({ open: true, mine: true });
463
675
  const [only] = items;
464
676
  if (only !== undefined && items.length === 1) {
465
677
  return only.id;
466
678
  }
467
679
  if (items.length === 0) {
680
+ // A run is its person's, and `mine` is this token's: a run begun through another of the
681
+ // person's agents, or before the command was signed in again, is open all the same, and
682
+ // goes on by its id. It is named before any word of taking, since taking its task again
683
+ // would end it, a run that waits for a decision included.
684
+ const theirs = await openRunsOfThePerson(session, project);
685
+ if (theirs.length > 0) {
686
+ const one = theirs.length === 1;
687
+ throw failed(
688
+ [
689
+ `run.none: no run begun through this agent is open in this project; ${theirs.length} of yours begun through another agent, or before a new sign-in, ${one ? "is" : "are"} open:`,
690
+ ...theirs.map((run) => ` ${formatRunLine(run)}`),
691
+ `Go on with ${one ? "it" : "one of them"}: add --run <id> to the command. A run is its person's, whichever of their agents began it; taking its task again would end it and begin another.`,
692
+ ].join("\n"),
693
+ );
694
+ }
468
695
  throw failed(
469
696
  "run.none: no run of yours is open in this project. Take a task first: console take <number>; or name a run: --run <id>",
470
697
  );
@@ -474,6 +701,30 @@ async function currentRun(project: ProjectClient, values: Values): Promise<strin
474
701
  );
475
702
  }
476
703
 
704
+ /**
705
+ * The open runs of the project that are for the person the command acts as, whichever of their
706
+ * agents began them: what a command on a run looks through when none was begun with its own
707
+ * token. A courtesy before a refusal: where the console does not answer it, there are none.
708
+ */
709
+ async function openRunsOfThePerson(
710
+ session: Session,
711
+ project: ProjectClient,
712
+ ): Promise<readonly RestRunBrief[]> {
713
+ try {
714
+ const [me, open] = await Promise.all([
715
+ session.client.me(),
716
+ project.runBriefs({ open: true, limit: LIST_LIMIT }),
717
+ ]);
718
+ const person = me.person;
719
+ return person === null ? [] : open.items.filter((run) => run.person.id === person.id);
720
+ } catch (error) {
721
+ if (error instanceof ApiError) {
722
+ return [];
723
+ }
724
+ throw error;
725
+ }
726
+ }
727
+
477
728
  /** A Markdown body: from `--file`, from standard input for `-`, or as given. */
478
729
  async function bodyOf(
479
730
  io: CliIo,
@@ -736,6 +987,8 @@ async function settle(
736
987
  decision: RestDecision,
737
988
  seconds: number,
738
989
  shown = false,
990
+ /** What is said where the decision still waits, in place of how an attended agent waits on. */
991
+ waiting?: string,
739
992
  ): Promise<number> {
740
993
  const outcome =
741
994
  decision.answer === null && seconds > 0
@@ -746,11 +999,46 @@ async function settle(
746
999
  io.stdout(`${JSON.stringify(outcome, null, 2)}\n`);
747
1000
  }
748
1001
  } else {
749
- io.stdout(`${outcome.answer === null ? stillWaiting(outcome.id) : formatAnswer(outcome)}\n`);
1002
+ io.stdout(
1003
+ `${outcome.answer === null ? (waiting ?? stillWaiting(outcome.id)) : formatAnswer(outcome)}\n`,
1004
+ );
750
1005
  }
751
1006
  return outcome.answer === null ? EXIT.waiting : EXIT.ok;
752
1007
  }
753
1008
 
1009
+ /**
1010
+ * Whether the command is signed in as the account itself (ADR-0084), which is how an agent
1011
+ * account's own command is: what the login kept says, and nothing the environment's pair does.
1012
+ */
1013
+ function signedInAsItself(session: Session): boolean {
1014
+ return (
1015
+ session.via === "login" &&
1016
+ session.credentials?.logins.find(
1017
+ (kept) => kept.url === session.url && kept.account === session.account,
1018
+ )?.self === true
1019
+ );
1020
+ }
1021
+
1022
+ /**
1023
+ * The address of a task's page at the console the command talks to: the console's origin and
1024
+ * the path the pages route a task by (ADR-0010), made here and asked of no console. An agent
1025
+ * that tells a person of a task links this, and not the console's front page; nothing where
1026
+ * the command works in no project.
1027
+ */
1028
+ async function taskPage(session: Session, number: number): Promise<string | undefined> {
1029
+ const key = await session.projectKey();
1030
+ return key === undefined ? undefined : `${session.url}${taskHref(key, number)}`;
1031
+ }
1032
+
1033
+ /**
1034
+ * The address of a decision's page: in the project the command reached it in, else the
1035
+ * decision's own (ADR-0068), which whoever it reaches may open, in that project or not.
1036
+ */
1037
+ async function decisionPage(session: Session, id: string, atItsAddress = false): Promise<string> {
1038
+ const key = atItsAddress ? undefined : await session.projectKey();
1039
+ return `${session.url}${key === undefined ? myDecisionHref(id) : decisionHref(key, id)}`;
1040
+ }
1041
+
754
1042
  type Command = (args: readonly string[], io: CliIo) => Promise<number>;
755
1043
 
756
1044
  /**
@@ -792,12 +1080,6 @@ async function keep(
792
1080
  );
793
1081
  }
794
1082
  const credentials = (await loadCredentials(io)) ?? EMPTY_CREDENTIALS;
795
- const replaced = loginsAt(credentials, url).find((login) => login.account === person.login);
796
- if (replaced !== undefined && replaced.token !== token) {
797
- await clientOf(io, url, replaced.token)
798
- .giveUpToken()
799
- .catch(() => undefined);
800
- }
801
1083
  const next = withLogin(
802
1084
  credentials,
803
1085
  {
@@ -809,14 +1091,34 @@ async function keep(
809
1091
  ...(self ? { self: true } : {}),
810
1092
  timeZone: me.workspace.timeZone ?? undefined,
811
1093
  },
1094
+ io.now(),
812
1095
  { default: asDefault },
813
1096
  );
814
- const kept = await io.store.save(next);
1097
+ // A login kept at a console ends the connection that waited there (ADR-0129): its secret
1098
+ // is spent, and is kept no longer. Asked whether it can be kept before the token it replaces
1099
+ // is given up, so that none is given up for one that never was.
1100
+ const keeping = fitting(withoutPending(next, url, io.now()), url);
1101
+ const replaced = loginsAt(credentials, url).find((login) => login.account === person.login);
1102
+ if (replaced !== undefined && replaced.token !== token) {
1103
+ await clientOf(io, url, replaced.token)
1104
+ .giveUpToken()
1105
+ .catch(() => undefined);
1106
+ }
1107
+ const kept = await io.store.save(keeping);
815
1108
  const standing = next.default === url ? ", the default console here" : "";
1109
+ // Last, what holds where, never a next step: the line once said to bind this directory
1110
+ // next, and a folder that is no checkout of a project's repository, a desk or a home
1111
+ // directory, was bound to a project because it said so.
1112
+ const binding =
1113
+ "Only a project's checkout is bound to it: console use <key> (console projects lists them).";
1114
+ // Where it is kept: the file, for a person at a terminal. Where no terminal shows the words,
1115
+ // an agent reads them, and the path of the one file it must never open is not handed to it.
1116
+ const where =
1117
+ io.terminal === false ? "on this machine by the command, and never shown" : `in ${kept}`;
816
1118
  say(
817
1119
  self
818
- ? `Signed in to ${me.workspace.name} at ${url} as ${whoOf(person)}, the account itself${standing}: what this command does, ${person.login} does, and no agent is named beside it. The session is kept while it is used; its secret is kept in ${kept}.\nNext, say which project this directory works in: console use <key> (console projects lists them).\n`
819
- : `${agent === undefined ? "Signed in" : `Connected as "${agent}"`} to ${me.workspace.name} at ${url} as ${whoOf(person)}${standing}. The token is kept in ${kept}.\nNext, say which project this directory works in: console use <key> (console projects lists them).\n`,
1120
+ ? `Signed in to ${me.workspace.name} at ${url} as ${whoOf(person)}, the account itself${standing}: what this command does, ${person.login} does, and no agent is named beside it. The session is kept while it is used; its secret is kept ${where}.\n${binding}\n`
1121
+ : `${agent === undefined ? "Signed in" : `Connected as "${agent}"`} to ${me.workspace.name} at ${url} as ${whoOf(person)}${standing}. The token is kept ${where}.\n${binding}\n`,
820
1122
  );
821
1123
  return EXIT.ok;
822
1124
  }
@@ -829,6 +1131,7 @@ const login: Command = async (args, io) => {
829
1131
  agent: { type: "string" },
830
1132
  self: { type: "boolean" },
831
1133
  default: { type: "boolean" },
1134
+ wait: { type: "string" },
832
1135
  },
833
1136
  false,
834
1137
  );
@@ -849,39 +1152,167 @@ const login: Command = async (args, io) => {
849
1152
  // A connection (ADR-0011): a code a person approves on the console's own pages, and the token
850
1153
  // handed over here once, never shown.
851
1154
  const client = clientOf(io, url);
852
- // "<agent> on <machine>": the pages say the agent and keep the machine for a hover.
853
- const agent = text(values, "agent") ?? agentOf(io.env) ?? "An agent";
854
1155
  // With --self the command asks to be the account itself (ADR-0084): whoever approves says
855
1156
  // "this is me", and what is handed over is a session of the command's, in place of a token.
856
1157
  const self = on(values, "self");
857
- const begun = await client.connect({
858
- agent: io.hostname === undefined ? agent : `${agent} on ${io.hostname}`,
859
- ...(self ? { as: "self" as const } : {}),
860
- });
861
- io.stdout(
1158
+ // Where no terminal shows the command's words as they are printed, whoever runs it sees them
1159
+ // when it ends: an agent's host held the address and the code back until its own limit, two
1160
+ // minutes on, while a person waited for them. There the call that begins a connection says
1161
+ // them and ends, and the next call waits for the approval (ADR-0129).
1162
+ const attended = io.terminal !== false;
1163
+ const wait = text(values, "wait");
1164
+ const waitGiven = wait === undefined ? undefined : secondsOf(wait, 0);
1165
+ // The end of the wait is a moment as any other the command prints (ADR-0035): in the
1166
+ // workspace's time zone where a login at this console kept it, which is one zone whoever
1167
+ // signed in; on a first sign-in, when none is known yet, in the machine's own, since an agent
1168
+ // relays the moment to a person; as the API gave it where the machine says none.
1169
+ setMomentZone(credentials?.logins.find((login) => login.url === url)?.timeZone ?? io.timeZone);
1170
+ const again = `console login --url ${url}${self ? " --self" : ""}`;
1171
+ /** Whom the code is shown to, and what they do with it. */
1172
+ const asked = (page: string, code: string): string =>
862
1173
  self
863
- ? `To sign this command in as an account itself, open ${begun.url} signed in as that account, check that the page shows the code ${begun.code}, and say that it is you.\nWaiting for that, until ${begun.expiresAt}.\n`
864
- : `To connect this agent, a person opens ${begun.url} signed in, checks that the page shows the code ${begun.code}, names the agent and approves.\nWaiting for that, until ${begun.expiresAt}.\n`,
865
- );
1174
+ ? `To sign this command in as an account itself, open ${page} signed in as that account, check that the page shows the code ${code}, and say that it is you.`
1175
+ : `To connect this agent, a person opens ${page} signed in, checks that the page shows the code ${code}, names the agent and approves.`;
1176
+ /** Forgets the connection kept for this console, and any whose code ran out; writes nothing where none was kept. */
1177
+ const forget = async (): Promise<void> => {
1178
+ const kept = await loadCredentials(io);
1179
+ if (kept === undefined || (kept.pending ?? []).length === 0) {
1180
+ return;
1181
+ }
1182
+ const next = withoutPending(kept, url, io.now());
1183
+ if (keepsNothing(next)) {
1184
+ await io.store.clear();
1185
+ } else {
1186
+ await io.store.save(next);
1187
+ }
1188
+ };
1189
+
1190
+ // A connection a call before this one began at this console, of the kind this call asks for:
1191
+ // it is gone on with, and no new code is made while its code lasts.
1192
+ let waiting = pendingAt(credentials, url);
1193
+ if (waiting !== undefined && ((waiting.self === true) !== self || !lasts(waiting, io.now()))) {
1194
+ const ranOut = !lasts(waiting, io.now());
1195
+ await forget();
1196
+ if (ranOut) {
1197
+ io.stdout(`The code ${waiting.code} ran out before a person approved it. A new one:\n`);
1198
+ }
1199
+ waiting = undefined;
1200
+ }
866
1201
  for (;;) {
867
- await io.sleep(begun.interval * 1000);
868
- let claim: RestClaim;
869
- try {
870
- claim = await client.claimConnection(begun.secret);
871
- } catch (error) {
872
- if (error instanceof ApiError && error.code === "connect.not_found") {
873
- throw failed(
874
- "The connection was not approved in time, or the person said it was not theirs. Run console login again for a new code.",
1202
+ const resumed = waiting !== undefined;
1203
+ if (waiting === undefined) {
1204
+ // "<agent> on <machine>": the pages say the agent and keep the machine for a hover.
1205
+ const agent = text(values, "agent") ?? agentOf(io.env) ?? "An agent";
1206
+ const begun = await client.connect({
1207
+ agent: io.hostname === undefined ? agent : `${agent} on ${io.hostname}`,
1208
+ ...(self ? { as: "self" as const } : {}),
1209
+ });
1210
+ waiting = {
1211
+ url,
1212
+ secret: begun.secret,
1213
+ code: begun.code,
1214
+ page: begun.url,
1215
+ expiresAt: begun.expiresAt,
1216
+ interval: begun.interval,
1217
+ ...(self ? { self: true } : {}),
1218
+ ...(asDefault ? { default: true } : {}),
1219
+ };
1220
+ // Kept only where this call may end before the approval: at a terminal, with no wait
1221
+ // said, the secret stays in the process as it always did.
1222
+ if (!attended || waitGiven !== undefined) {
1223
+ await io.store.save(
1224
+ fitting(
1225
+ withPending((await loadCredentials(io)) ?? EMPTY_CREDENTIALS, waiting, io.now()),
1226
+ url,
1227
+ ),
875
1228
  );
876
1229
  }
877
- throw error;
878
1230
  }
879
- if (claim.status === "connected") {
880
- return keep(io, url, claim.secret, claim.token.name, asDefault);
1231
+ const pending: PendingConnection = waiting;
1232
+ const until = moment(pending.expiresAt);
1233
+ const end = Date.parse(pending.expiresAt);
1234
+ const seconds =
1235
+ waitGiven ?? (attended ? MAX_WAIT_SECONDS : resumed ? DEFAULT_LOGIN_WAIT_SECONDS : 0);
1236
+ // A call that begins a connection and waits for nothing says what a person does and ends:
1237
+ // the words reach whoever ran it now, and the next call waits. A call that goes on with a
1238
+ // connection says nothing before its wait where no terminal would show it.
1239
+ const told = !resumed && seconds === 0;
1240
+ if (!resumed || attended) {
1241
+ // The telling is a sentence of its own, before the one that names the command: read in
1242
+ // one sentence, an agent ran the command first and told its person after. And the wait
1243
+ // of the next call is said apart from the code's end, which an agent took for how long
1244
+ // that call waits, and gave it half an hour. At a terminal, told not to wait, the next
1245
+ // call there waits while the code lasts, and says so.
1246
+ const next = attended
1247
+ ? `it waits for the approval while the code lasts, until ${until}`
1248
+ : `it waits for the approval up to ${DEFAULT_LOGIN_WAIT_SECONDS} seconds a call, and the code lasts until ${until}`;
1249
+ io.stdout(
1250
+ told
1251
+ ? `${asked(pending.page, pending.code)}\n${self ? "Have that done now" : "Tell the person that address and that code now, in a message of its own"}, before you run the command again.\nThen run ${again} again: ${next}.\n`
1252
+ : `${asked(pending.page, pending.code)}\nWaiting for that, until ${until}.\n`,
1253
+ );
881
1254
  }
882
- if (claim.status === "signed_in") {
883
- return keep(io, url, claim.secret, undefined, asDefault, true);
1255
+ if (told) {
1256
+ return EXIT.ok;
884
1257
  }
1258
+ // Where the call may end before the approval, it waits no longer than it was given, and no
1259
+ // longer than the code lasts; at a terminal with no wait said, until the console says how
1260
+ // the connection ended, as before.
1261
+ const bounded = waitGiven !== undefined || !attended;
1262
+ const deadline = Math.min(
1263
+ io.now() + seconds * 1000,
1264
+ Number.isFinite(end) ? end : Number.POSITIVE_INFINITY,
1265
+ );
1266
+ // A connection gone on with is claimed at once, since its person may have approved between
1267
+ // the two calls; one begun now, after the breath the console asked for, as before.
1268
+ let first = resumed;
1269
+ let gone = false;
1270
+ for (;;) {
1271
+ if (!first) {
1272
+ if (bounded && io.now() + pending.interval * 1000 > deadline) {
1273
+ break;
1274
+ }
1275
+ await io.sleep(pending.interval * 1000);
1276
+ }
1277
+ first = false;
1278
+ let claim: RestClaim;
1279
+ try {
1280
+ claim = await client.claimConnection(pending.secret);
1281
+ } catch (error) {
1282
+ if (error instanceof ApiError && error.code === "connect.not_found") {
1283
+ gone = true;
1284
+ break;
1285
+ }
1286
+ throw error;
1287
+ }
1288
+ if (claim.status === "connected") {
1289
+ return keep(io, url, claim.secret, claim.token.name, asDefault || pending.default === true);
1290
+ }
1291
+ if (claim.status === "signed_in") {
1292
+ return keep(io, url, claim.secret, undefined, asDefault || pending.default === true, true);
1293
+ }
1294
+ }
1295
+ if (gone) {
1296
+ await forget();
1297
+ if (!resumed) {
1298
+ throw failed(
1299
+ "The connection was not approved in time, or the person said it was not theirs. Run console login again for a new code.",
1300
+ );
1301
+ }
1302
+ // A connection kept from a call before, which the console no longer knows: its code ran
1303
+ // out there, or a person said it was not theirs. It is forgotten, and a new one begun.
1304
+ io.stdout(
1305
+ `The code ${pending.code} is good no longer: it ran out, or a person said the connection was not theirs. A new one:\n`,
1306
+ );
1307
+ waiting = undefined;
1308
+ continue;
1309
+ }
1310
+ // The wait this call was given is over and the code still lasts: the connection stays kept,
1311
+ // and the same command goes on waiting for it.
1312
+ io.stdout(
1313
+ `${self ? "Not signed in yet" : "Not approved yet"}. ${asked(pending.page, pending.code)}\nKeep waiting with: ${again}, as often as needed until ${until}.\n`,
1314
+ );
1315
+ return EXIT.waiting;
885
1316
  }
886
1317
  };
887
1318
 
@@ -895,7 +1326,14 @@ const logout: Command = async (args, io) => {
895
1326
  }
896
1327
  };
897
1328
  if (credentials === undefined || credentials.logins.length === 0) {
898
- io.stdout("Not signed in here: nothing to forget.\n");
1329
+ // Nobody is signed in; a connection that waited for a person is forgotten all the same
1330
+ // (ADR-0129), with its secret.
1331
+ if (credentials !== undefined && (credentials.pending ?? []).length > 0) {
1332
+ await io.store.clear();
1333
+ io.stdout("Not signed in here; the connection that waited for a person is forgotten.\n");
1334
+ } else {
1335
+ io.stdout("Not signed in here: nothing to forget.\n");
1336
+ }
899
1337
  envNote();
900
1338
  return EXIT.ok;
901
1339
  }
@@ -919,8 +1357,19 @@ const logout: Command = async (args, io) => {
919
1357
  const chosen = account === undefined ? at : at.filter((login) => login.account === account);
920
1358
  const [login] = chosen;
921
1359
  if (login === undefined) {
1360
+ const whom = account === undefined ? "" : ` as ${account}`;
1361
+ // Nobody to sign out there; a connection that waits for a person at that console is
1362
+ // forgotten all the same (ADR-0129): signing out of a console leaves no secret of it here.
1363
+ if (pendingAt(credentials, url) !== undefined) {
1364
+ await io.store.save(withoutPending(credentials, url, io.now()));
1365
+ io.stdout(
1366
+ `Nobody is signed in here at ${url}${whom}; the connection that waited for a person there is forgotten.\n`,
1367
+ );
1368
+ envNote();
1369
+ return EXIT.ok;
1370
+ }
922
1371
  throw failed(
923
- `Nobody is signed in here at ${url}${account === undefined ? "" : ` as ${account}`}: nothing to forget. console logins lists the consoles signed in.`,
1372
+ `Nobody is signed in here at ${url}${whom}: nothing to forget. console logins lists the consoles signed in.`,
924
1373
  );
925
1374
  }
926
1375
  if (chosen.length > 1) {
@@ -945,8 +1394,14 @@ const logout: Command = async (args, io) => {
945
1394
  outcome = "left";
946
1395
  }
947
1396
  }
948
- const next = withoutLogin(credentials, url, login.account);
949
- if (next.logins.length === 0) {
1397
+ // A connection that waited at this console goes with its login (ADR-0129), as does any
1398
+ // whose code ran out: signing out leaves no secret of the console here.
1399
+ const next = withoutPending(
1400
+ withoutLogin(credentials, url, io.now(), login.account),
1401
+ url,
1402
+ io.now(),
1403
+ );
1404
+ if (keepsNothing(next)) {
950
1405
  await io.store.clear();
951
1406
  } else {
952
1407
  await io.store.save(next);
@@ -976,24 +1431,49 @@ const logins: Command = async (args, io) => {
976
1431
  since: login.since ?? null,
977
1432
  default: credentials?.default === login.url,
978
1433
  }));
1434
+ // The connections that wait for a person while their codes last (ADR-0129): the console, the
1435
+ // code and its end, never the secret; one whose code ran out is not shown.
1436
+ const waiting = (credentials?.pending ?? [])
1437
+ .filter((pending) => lasts(pending, io.now()))
1438
+ .map((pending) => ({
1439
+ url: pending.url,
1440
+ code: pending.code,
1441
+ expiresAt: pending.expiresAt,
1442
+ self: pending.self === true,
1443
+ }));
979
1444
  if (on(values, "json")) {
980
1445
  io.stdout(
981
- `${JSON.stringify({ default: credentials?.default ?? null, logins: kept }, null, 2)}\n`,
1446
+ `${JSON.stringify(
1447
+ {
1448
+ default: credentials?.default ?? null,
1449
+ logins: kept,
1450
+ ...(waiting.length === 0 ? {} : { waiting }),
1451
+ },
1452
+ null,
1453
+ 2,
1454
+ )}\n`,
982
1455
  );
983
1456
  return EXIT.ok;
984
1457
  }
1458
+ const lines = [
1459
+ ...kept.map(
1460
+ (login) =>
1461
+ `${login.url} ${login.account ?? "(account unknown)"}${login.agent === null ? "" : ` ${login.agent}`}${login.self ? " as the account itself" : ""}${login.since === null ? "" : ` since ${login.since.slice(0, 10)}`}${login.default ? " (default)" : ""}`,
1462
+ ),
1463
+ ];
1464
+ for (const pending of waiting) {
1465
+ // The code's end as login printed it: in the zone a login at that console kept, else the machine's.
1466
+ setMomentZone(
1467
+ credentials?.logins.find((login) => login.url === pending.url)?.timeZone ?? io.timeZone,
1468
+ );
1469
+ lines.push(
1470
+ `${pending.url} waits for a person to approve the code ${pending.code}, until ${moment(pending.expiresAt)}: console login --url ${pending.url}${pending.self ? " --self" : ""}`,
1471
+ );
1472
+ }
985
1473
  if (kept.length === 0) {
986
- io.stdout("Not signed in anywhere here: console login --url <the console's origin>\n");
987
- return EXIT.ok;
1474
+ lines.unshift("Not signed in anywhere here: console login --url <the console's origin>");
988
1475
  }
989
- io.stdout(
990
- `${kept
991
- .map(
992
- (login) =>
993
- `${login.url} ${login.account ?? "(account unknown)"}${login.agent === null ? "" : ` ${login.agent}`}${login.self ? " as the account itself" : ""}${login.since === null ? "" : ` since ${login.since.slice(0, 10)}`}${login.default ? " (default)" : ""}`,
994
- )
995
- .join("\n")}\n`,
996
- );
1476
+ io.stdout(`${lines.join("\n")}\n`);
997
1477
  return EXIT.ok;
998
1478
  };
999
1479
 
@@ -1023,7 +1503,10 @@ async function rememberZone(io: CliIo, session: Session, zone: string | undefine
1023
1503
  if (kept === undefined || kept.timeZone === zone) {
1024
1504
  return;
1025
1505
  }
1026
- await io.store.save(withLogin(session.credentials, { ...kept, timeZone: zone }));
1506
+ // Kept anew, and so without a connection whose code ran out (ADR-0129).
1507
+ await io.store.save(
1508
+ fitting(withLogin(session.credentials, { ...kept, timeZone: zone }, io.now()), session.url),
1509
+ );
1027
1510
  }
1028
1511
 
1029
1512
  const whoami: Command = async (args, io) => {
@@ -1035,7 +1518,29 @@ const whoami: Command = async (args, io) => {
1035
1518
  throw failed("The console does not know this token. Sign in again: console login");
1036
1519
  }
1037
1520
  await rememberZone(io, session, me.workspace.timeZone ?? undefined);
1038
- const key = await session.projectKey();
1521
+ // The project the directory names is asked of the console (ADR-0112): a key repeated from a
1522
+ // file says nothing of whether this console has the project, or shows it to this member, and
1523
+ // an agreement has its agents check the binding with this command before the first one on
1524
+ // the board. Where the key came from is said either way, since that is where it is mended.
1525
+ const named = session.projectNamed();
1526
+ const key = named?.key;
1527
+ let projectName: string | undefined;
1528
+ if (named !== undefined) {
1529
+ try {
1530
+ projectName = (await session.client.project(named.key).get()).name;
1531
+ } catch (error) {
1532
+ if (!(error instanceof ApiError && error.code === "project.not_found")) {
1533
+ throw error;
1534
+ }
1535
+ }
1536
+ }
1537
+ const missing = named !== undefined && projectName === undefined;
1538
+ const projectWords =
1539
+ named === undefined
1540
+ ? "; no project named here"
1541
+ : projectName === undefined
1542
+ ? `; project ${named.key}, named by ${sourceWords(named.source)}, which this console does not have or does not show you`
1543
+ : `; project ${named.key} (${projectName}), named by ${sourceWords(named.source)}`;
1039
1544
  const command = parseVersion(io.version);
1040
1545
  const server = parseVersion(me.console?.version);
1041
1546
  const verdict =
@@ -1058,16 +1563,23 @@ const whoami: Command = async (args, io) => {
1058
1563
  ...me,
1059
1564
  console: me.console ?? null,
1060
1565
  project: key ?? null,
1566
+ projectName: projectName ?? null,
1567
+ projectSource: named?.source ?? null,
1061
1568
  command: { version: io.version ?? null, install: io.install ?? null },
1062
1569
  },
1063
1570
  () =>
1064
1571
  [
1065
- `${whoOf(person)} at ${me.workspace.name}, ${session.url}${key === undefined ? "; no project named here" : `; project ${key}`}${me.session?.kind === "command" ? "; signed in as the account itself" : ""}`,
1066
- // The pack's rules send an agent here first; from here the rules and the skill are the next
1067
- // steps. In a directory that names no project too: an agent account's desk names none,
1068
- // the command's help sends an agent here for where the skill is, and the workspace has
1069
- // rules whatever the project.
1070
- `What this organization asks of agents: console rules. How the board is worked: the skill working-the-board, shipped with this command${io.skillsDir === undefined ? " (console skills says where it is)." : `: ${ownSkillPath(io.skillsDir)}`}`,
1572
+ `${whoOf(person)} at ${me.workspace.name}, ${session.url}${projectWords}${me.session?.kind === "command" ? "; signed in as the account itself" : ""}`,
1573
+ // The sentence of a checkout's agreement sends an agent here first and says that this
1574
+ // answer says how: so it says what is read before the first task, the rules and the
1575
+ // skill, and that one command's flags are read from that command's help, since an agent
1576
+ // that has the skill was reading the whole help beside it. In a directory that names
1577
+ // no project too: an agent account's desk names none, the command's help sends an
1578
+ // agent here for where the skill is, and the workspace has rules whatever the project.
1579
+ // The skill's path stands last, with nothing after it, to be copied as it is.
1580
+ io.skillsDir === undefined
1581
+ ? "Before the first task, read console rules and the skill working-the-board (console skills says where it is); for one command's flags, console help <command>."
1582
+ : `Before the first task, read console rules and the skill working-the-board; for one command's flags, console help <command>. The skill: ${ownSkillPath(io.skillsDir)}`,
1071
1583
  `This command is ${io.version ?? "of a version it does not know"}${io.install === undefined ? "" : `, ${describeInstall(io.install)}`}; ${consoleWords}.`,
1072
1584
  ...(verdict === "behind"
1073
1585
  ? [`A newer command exists. Update it: ${updateWords(io, me.console?.version)}`]
@@ -1078,6 +1590,11 @@ const whoami: Command = async (args, io) => {
1078
1590
  : []),
1079
1591
  ].join("\n"),
1080
1592
  );
1593
+ if (missing && named !== undefined) {
1594
+ // Who and where are said above, which is what mends it; the command still ends as refused,
1595
+ // so that a check of the binding never passes on a key alone.
1596
+ throw failed(unseenProjectWords(session.url, named, person.login));
1597
+ }
1081
1598
  return EXIT.ok;
1082
1599
  };
1083
1600
 
@@ -1101,26 +1618,23 @@ const use: Command = async (args, io) => {
1101
1618
  );
1102
1619
  const session = await open(io, values);
1103
1620
  const project = await session.client.project(key).get();
1104
- // The directory names the console where that is not the default login here, or when asked,
1105
- // and the account where the console has several, or when asked; never a token.
1106
- const credentials = session.credentials ?? EMPTY_CREDENTIALS;
1107
- const pinUrl =
1108
- text(values, "url") !== undefined ||
1109
- (session.via === "login" && credentials.default !== session.url);
1621
+ // The directory names the console every time (ADR-0112): what is the default login on this
1622
+ // machine is another console's on the next, and a file that said only the project would
1623
+ // follow it there. The account only when asked, or where the directory named it before, so
1624
+ // that a file to be committed never carries somebody's account unasked; never a token.
1625
+ const before = await io.directory.load();
1110
1626
  const pinAccount =
1111
- text(values, "account") !== undefined ||
1112
- (session.via === "login" && loginsAt(credentials, session.url).length > 1);
1627
+ session.account !== undefined &&
1628
+ (text(values, "account") !== undefined || before?.account === session.account);
1113
1629
  const kept = await io.directory.save({
1114
1630
  project: project.key,
1115
- ...(pinUrl ? { url: session.url } : {}),
1116
- ...(pinAccount && session.account !== undefined ? { account: session.account } : {}),
1631
+ url: session.url,
1632
+ ...(pinAccount ? { account: session.account } : {}),
1117
1633
  });
1118
- const bound = pinUrl
1119
- ? ` at ${session.url}${pinAccount && session.account !== undefined ? ` as ${session.account}` : ""}`
1120
- : "";
1634
+ const bound = ` at ${session.url}${pinAccount ? ` as ${session.account}` : ""}`;
1121
1635
  answer(io, session, project, () =>
1122
1636
  [
1123
- `Working in ${project.name} (${project.key})${bound} from this directory on: kept in ${kept}, which is meant to be committed in a private repository and left out of a public one. What its people ask of agents: console rules.`,
1637
+ `Working in ${project.name} (${project.key})${bound} from this directory on: kept in ${kept}, which names the project and the console, never a token, and is meant to be committed in a private repository and left out of a public one. What its people ask of agents: console rules.`,
1124
1638
  // Nothing sends an agent to the console until the checkout says so; the sentence is the
1125
1639
  // skill's (references/the-sentence.md), printed here as `skillcdn use` prints its own.
1126
1640
  "Then put this sentence into the checkout's agreement (AGENTS.md, or CLAUDE.md where that is the file agents read), as it is, so that every agent working here is sent to the console:",
@@ -1194,7 +1708,7 @@ const tasks: Command = async (args, io) => {
1194
1708
  if (search === "") {
1195
1709
  throw misuse("Say what to search for: console tasks --search <words>");
1196
1710
  }
1197
- const found = await project.tasks({
1711
+ const filter = {
1198
1712
  ...(state === undefined ? {} : { state }),
1199
1713
  ...(on(values, "open") || due === "overdue" ? { open: true } : {}),
1200
1714
  ...(worker === undefined ? {} : { worker }),
@@ -1205,10 +1719,22 @@ const tasks: Command = async (args, io) => {
1205
1719
  ...(search === undefined ? {} : { q: search }),
1206
1720
  ...(on(values, "archived") ? { archived: true } : {}),
1207
1721
  ...page,
1208
- });
1722
+ };
1723
+ // A line a task and no body: the listing is asked for in the brief form, without the bodies,
1724
+ // which weigh more than the rest of a page together. --json is the console's own answer, whole.
1725
+ const found = session.json ? await project.tasks(filter) : await project.taskBriefs(filter);
1726
+ // A search that finds nothing says how it looked: every word must be in a title, so three
1727
+ // words find nothing where one of them finds the task, and an agent that read "No tasks."
1728
+ // wrote the same work a second time.
1729
+ const none =
1730
+ search === undefined
1731
+ ? "No tasks."
1732
+ : /\s/.test(search.trim())
1733
+ ? `No tasks: no title holds every word of "${search.trim()}". Fewer words find more: one word of the thing's name, in the language the board is written in.`
1734
+ : `No tasks: no title holds "${search.trim()}".`;
1209
1735
  answer(io, session, found, () =>
1210
1736
  found.items.length === 0
1211
- ? "No tasks."
1737
+ ? none
1212
1738
  : found.items.map(formatTaskLine).join("\n") +
1213
1739
  formatMore(found.more, page.limit, page.offset),
1214
1740
  );
@@ -1241,157 +1767,192 @@ const categories: Command = async (args, io) => {
1241
1767
  return EXIT.ok;
1242
1768
  };
1243
1769
 
1244
- /** How many pages of a skill, of a file or of a folder the command follows before it stops: far above what one holds. */
1245
- const MAX_SKILL_PAGES = 64;
1246
- /** How many results a search answers at most: what the deployment allows on one page. */
1247
- const MAX_FIND_LIMIT = 25;
1248
- /** How many rows, and how many code blocks, one page of a read as data is asked to end after: the most the console takes. */
1249
- const DATA_PAGE_ROWS = 5000;
1250
- const DATA_PAGE_BLOCKS = 500;
1251
-
1252
- /** The pack of the project as the console lists it, and what its reads are rendered at; none when the pack did not answer. */
1253
- async function packOf(
1254
- reader: PackReader,
1255
- ): Promise<{ readonly listing: RestSkills; readonly summary: PackSummary | undefined }> {
1256
- const listing = await reader.skills();
1257
- return { listing, summary: summaryOf(listing) };
1258
- }
1259
-
1260
- /** What reads a pack: a project's client, or a plugin's, whose skills are a pack of their own. */
1261
- type PackReader = Pick<
1262
- ProjectClient,
1263
- "skills" | "skill" | "skillFile" | "skillBrowse" | "skillFind" | "skillRows" | "skillCode"
1264
- >;
1770
+ /** What reads a pack: a project's client, a plugin's, whose skills are a pack of their own, or the console's for the organization's. */
1771
+ type PackReader = PackClient;
1265
1772
 
1266
1773
  const SKILLS_OPTIONS: OptionSpec = {
1267
1774
  search: { type: "string" },
1775
+ path: { type: "string" },
1268
1776
  limit: { type: "string" },
1269
1777
  cursor: { type: "string" },
1270
1778
  rows: { type: "boolean" },
1271
1779
  code: { type: "boolean" },
1272
1780
  heading: { type: "string" },
1781
+ format: { type: "string" },
1782
+ grep: { type: "string" },
1273
1783
  out: { type: "string" },
1274
1784
  };
1275
1785
 
1786
+ /**
1787
+ * A read the pack refused, as the command ends on it (ADR-0118): the words on standard error
1788
+ * and the exit of a refusal, as the skillcdn command ends one, where the pack's answer was once
1789
+ * printed as if it were the read. `--json` still prints what the console answered, which says
1790
+ * the status. Thrown by the caller, so that nothing follows it.
1791
+ */
1792
+ function refusedRead(
1793
+ io: CliIo,
1794
+ session: Session,
1795
+ owner: PackOwner,
1796
+ answered: unknown,
1797
+ words: string,
1798
+ ): CliExit {
1799
+ if (session.json) {
1800
+ io.stdout(`${JSON.stringify(answered, null, 2)}\n`);
1801
+ }
1802
+ return failed(owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words}` : words);
1803
+ }
1804
+
1805
+ /** A whole number a flag carries, within its bounds; nothing when it is not given. */
1806
+ function countOf(
1807
+ given: string | undefined,
1808
+ name: string,
1809
+ bounds: { readonly least: number; readonly most?: number },
1810
+ ): number | undefined {
1811
+ if (given === undefined) {
1812
+ return undefined;
1813
+ }
1814
+ const count = /^\d{1,9}$/.test(given) ? Number(given) : Number.NaN;
1815
+ if (
1816
+ Number.isNaN(count) ||
1817
+ count < bounds.least ||
1818
+ (bounds.most !== undefined && count > bounds.most)
1819
+ ) {
1820
+ throw misuse(
1821
+ `--${name} takes an integer ${bounds.most === undefined ? `from ${bounds.least}` : `between ${bounds.least} and ${bounds.most}`}: ${given}`,
1822
+ );
1823
+ }
1824
+ return count;
1825
+ }
1826
+
1827
+ /**
1828
+ * A number a read of a pack takes, checked as the skillcdn command checks it and said in its
1829
+ * words, before anything is asked of the console.
1830
+ */
1831
+ function checkedNumber(given: string | undefined, name: string, most: number): void {
1832
+ try {
1833
+ readNumber(given, name, most);
1834
+ } catch (error) {
1835
+ throw error instanceof ReadMisuse ? misuse(error.message) : error;
1836
+ }
1837
+ }
1838
+
1839
+ /**
1840
+ * The flags that say where a pack is read, as they were given, for the command that reads the
1841
+ * next part of a skill (ADR-0124): it is asked as this part was.
1842
+ */
1843
+ function whereGiven(values: Readonly<Record<string, unknown>>): readonly string[] {
1844
+ return ["project", "url", "account"].flatMap((name) => {
1845
+ const value = values[name];
1846
+ return typeof value === "string" ? [`--${name}`, value] : [];
1847
+ });
1848
+ }
1849
+
1850
+ /**
1851
+ * One read of a pack as the skillcdn command makes it (ADR-0124): `readPack` of @skillcdn/cli
1852
+ * over the pack made of the console's answers, in the words of the command the pack is read
1853
+ * with. What the pack refused ends the command as refused (ADR-0118): of one read, in the
1854
+ * pack's own code and words, as that command prints them; of the pack as a whole, in the
1855
+ * console's. A read not asked right is a command not understood. With `data`, nothing is
1856
+ * printed for a refusal even with `--json`: what a program takes is never one.
1857
+ */
1858
+ async function readThrough(
1859
+ io: CliIo,
1860
+ session: Session,
1861
+ owner: PackOwner,
1862
+ pack: ConsolePack,
1863
+ read: PackRead,
1864
+ options: {
1865
+ readonly words: ToolWords;
1866
+ readonly nextPart?: ((cursor: string) => string) | undefined;
1867
+ readonly data?: boolean | undefined;
1868
+ },
1869
+ ): Promise<ReadOutput> {
1870
+ try {
1871
+ return await readPack(pack, read, {
1872
+ words: options.words,
1873
+ json: session.json,
1874
+ nextPart: options.nextPart,
1875
+ });
1876
+ } catch (error) {
1877
+ if (error instanceof ReadMisuse) {
1878
+ throw misuse(error.message);
1879
+ }
1880
+ const refusal =
1881
+ error instanceof PackRefusal
1882
+ ? { answer: error.answer, words: refusalWords(error.what, error.answer, owner) }
1883
+ : error instanceof PackError
1884
+ ? { answer: pack.answered(), words: `${error.code}: ${error.message}` }
1885
+ : undefined;
1886
+ if (refusal === undefined) {
1887
+ throw error;
1888
+ }
1889
+ throw options.data === true || refusal.answer === undefined
1890
+ ? failed(refusal.words)
1891
+ : refusedRead(io, session, owner, refusal.answer, refusal.words);
1892
+ }
1893
+ }
1894
+
1895
+ /**
1896
+ * What `--json` prints for a read: the console's answer, with the pack's own in it as the
1897
+ * skillcdn command's `--json` prints it, the pages of a skill or of a read of data joined.
1898
+ */
1899
+ function jsonOfRead(session: Session, pack: ConsolePack, output: ReadOutput): unknown {
1900
+ return session.json ? { ...pack.answered(), read: JSON.parse(output.text) } : undefined;
1901
+ }
1902
+
1276
1903
  /**
1277
1904
  * The tables, or the code blocks, of a document or of every document under a folder, as data
1278
- * (ADR-0100): every page the console answers, joined, and printed as one CSV or as the blocks
1279
- * as written, or written to a file with `--out`. What a program takes is never a refusal: a
1280
- * read the pack refused fails with why, and so does one that did not reach its end.
1905
+ * (ADR-0100): read and printed as the skillcdn command prints them, one CSV or an array of rows,
1906
+ * the blocks as written, or written to a file with `--out`. What a program takes is never a
1907
+ * refusal: a read the pack refused fails with why.
1281
1908
  */
1282
1909
  async function readData(
1283
1910
  io: CliIo,
1284
1911
  session: Session,
1285
- reader: PackReader,
1912
+ pack: ConsolePack,
1286
1913
  asked: {
1287
- readonly what: "rows" | "code";
1288
- readonly path: string | undefined;
1289
- readonly heading: string | undefined;
1914
+ readonly read: Extract<PackRead, { readonly read: "rows" | "code" }>;
1290
1915
  readonly out: string | undefined;
1916
+ readonly owner: PackOwner;
1917
+ readonly words: ToolWords;
1291
1918
  },
1292
1919
  ): Promise<number> {
1293
- const where = asked.path ?? "the pack";
1294
- /** The answer written to a file, or printed: what was read in a line when a file was written. */
1295
- const give = async (
1296
- body: unknown,
1297
- words: string,
1298
- summary: string,
1299
- name: string,
1300
- ): Promise<number> => {
1301
- const printed = session.json ? `${JSON.stringify(body, null, 2)}\n` : words;
1302
- if (asked.out === undefined) {
1303
- io.stdout(printed);
1304
- return EXIT.ok;
1305
- }
1306
- let saved: string;
1307
- try {
1308
- saved = await io.writeBytes(asked.out, new TextEncoder().encode(printed), name);
1309
- } catch {
1310
- throw failed(`The file could not be written at ${asked.out}.`);
1311
- }
1312
- answer(io, session, { path: saved, summary }, () => `Saved ${summary} at ${saved}`);
1313
- return EXIT.ok;
1314
- };
1315
- if (asked.what === "rows") {
1316
- const pages: RestSkillRows[] = [];
1317
- let next: string | undefined;
1318
- for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1319
- const page = await reader.skillRows({
1320
- path: asked.path,
1321
- heading: asked.heading,
1322
- cursor: next,
1323
- limit: DATA_PAGE_ROWS,
1324
- });
1325
- const refusal = dataRefusal("tables", page);
1326
- if (refusal !== undefined) {
1327
- throw failed(refusal);
1328
- }
1329
- pages.push(page);
1330
- next = page.read?.status === "ready" ? (page.read.nextCursor ?? undefined) : undefined;
1331
- if (next === undefined) {
1332
- break;
1333
- }
1334
- }
1335
- const whole = joinRows(pages);
1336
- const last = pages[pages.length - 1];
1337
- if (whole === undefined || last === undefined) {
1338
- throw failed("The tables could not be read.");
1339
- }
1340
- if (next !== undefined) {
1341
- throw failed(
1342
- `The tables under ${where} are more than the command reads at once (${describeRows(whole)} so far): name a folder or a file under it.`,
1343
- );
1344
- }
1345
- if (whole.tables.length === 0 && !session.json) {
1346
- io.stdout(
1347
- `No tables in ${where}${asked.heading === undefined ? "" : " under that heading"}.\n`,
1348
- );
1349
- return EXIT.ok;
1350
- }
1351
- return give({ ...last, read: whole }, csvOfRows(whole), describeRows(whole), "rows.csv");
1352
- }
1353
- const pages: RestSkillCode[] = [];
1354
- let next: string | undefined;
1355
- for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1356
- const page = await reader.skillCode({
1357
- path: asked.path,
1358
- heading: asked.heading,
1359
- cursor: next,
1360
- limit: DATA_PAGE_BLOCKS,
1361
- });
1362
- const refusal = dataRefusal("code blocks", page);
1363
- if (refusal !== undefined) {
1364
- throw failed(refusal);
1365
- }
1366
- pages.push(page);
1367
- next = page.read?.status === "ready" ? (page.read.nextCursor ?? undefined) : undefined;
1368
- if (next === undefined) {
1369
- break;
1370
- }
1371
- }
1372
- const whole = joinCode(pages);
1373
- const last = pages[pages.length - 1];
1374
- if (whole === undefined || last === undefined) {
1375
- throw failed("The code blocks could not be read.");
1376
- }
1377
- if (next !== undefined) {
1378
- throw failed(
1379
- `The code blocks under ${where} are more than the command reads at once (${describeCode(whole)} so far): name a folder or a file under it.`,
1920
+ const { read } = asked;
1921
+ const output = await readThrough(io, session, asked.owner, pack, read, {
1922
+ words: asked.words,
1923
+ data: true,
1924
+ });
1925
+ // Nothing is printed for nothing, which a program takes as it is; a line beside it says so.
1926
+ if (holdsNothing(output.holds) && asked.out === undefined && !session.json) {
1927
+ io.stderr(
1928
+ `No ${read.read === "rows" ? "tables" : "code blocks"} in ${read.path ?? "the pack"}${read.heading === undefined ? "" : " under that heading"}.\n`,
1380
1929
  );
1381
1930
  }
1382
- if (whole.blocks.length === 0 && !session.json) {
1383
- io.stdout(
1384
- `No code blocks in ${where}${asked.heading === undefined ? "" : " under that heading"}.\n`,
1385
- );
1931
+ const made = session.json
1932
+ ? JSON.stringify(jsonOfRead(session, pack, output), null, 2)
1933
+ : output.text;
1934
+ const whole = made.endsWith("\n") || made.length === 0 ? made : `${made}\n`;
1935
+ if (asked.out === undefined) {
1936
+ io.stdout(whole);
1386
1937
  return EXIT.ok;
1387
1938
  }
1388
- return give({ ...last, read: whole }, textOfCode(whole), describeCode(whole), "code.txt");
1939
+ const name =
1940
+ read.read === "code" ? "code.txt" : read.format === "json" ? "rows.json" : "rows.csv";
1941
+ let saved: string;
1942
+ try {
1943
+ saved = await io.writeBytes(asked.out, new TextEncoder().encode(whole), name);
1944
+ } catch {
1945
+ throw failed(`The file could not be written at ${asked.out}.`);
1946
+ }
1947
+ io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
1948
+ return EXIT.ok;
1389
1949
  }
1390
1950
 
1391
1951
  const SKILL_OPTIONS: OptionSpec = {
1392
1952
  file: { type: "string" },
1393
1953
  offset: { type: "string" },
1394
1954
  limit: { type: "string" },
1955
+ cursor: { type: "string" },
1395
1956
  };
1396
1957
 
1397
1958
  /** The line `console skills` ends with: where the plugins' own skills are. */
@@ -1399,8 +1960,10 @@ const PLUGIN_SKILLS_LINE =
1399
1960
  "The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
1400
1961
 
1401
1962
  /**
1402
- * The pack as the words say: whole, a folder of it, a file's outline, or what words find; for
1403
- * the project's pack as `console skills`, and for a plugin's as `console plugin <key> skills`.
1963
+ * The pack as the words say: whole, a page of a folder or of a file's outline, or what words
1964
+ * find; for the project's pack as `console skills`, and for a plugin's as
1965
+ * `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
1966
+ * (ADR-0124).
1404
1967
  */
1405
1968
  async function readSkills(
1406
1969
  io: CliIo,
@@ -1415,26 +1978,42 @@ async function readSkills(
1415
1978
  readonly own?: string | undefined;
1416
1979
  /** A line after the listing whole. */
1417
1980
  readonly afterwards?: string | undefined;
1981
+ /** Whose pack it is: the organization's where no project is named (ADR-0113), else a project's. */
1982
+ readonly owner?: PackOwner | undefined;
1418
1983
  },
1419
1984
  ): Promise<number> {
1985
+ const owner = extras.owner ?? "project";
1986
+ const say = (value: unknown, words: () => string): void =>
1987
+ answerPack(io, session, owner, value, words);
1988
+ // The reads by the names of this pack's own commands: a plugin's are not the project's.
1989
+ const skillCommand = extras.command.replace(/skills$/, "skill");
1990
+ const toolWords = packWords(extras.command, skillCommand);
1991
+ // How a skill is loaded, said after a listing and after what a search found: the pack's own
1992
+ // words there name how a section is read, and a skill read as a file comes without its rules.
1993
+ const loading = `A skill is loaded, its rules first, with ${skillCommand} <the path of its SKILL.md>, a long one in parts; --file reads a file of the pack as it is, without the rules.`;
1420
1994
  if (positionals.length > 1) {
1421
1995
  throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
1422
1996
  }
1423
1997
  // The root of the pack is the mounted folder, which the deployment reads as no path at all.
1424
1998
  const given = positionals[0];
1425
- const folder = given === undefined || given === "/" || given === "." ? undefined : given;
1426
1999
  const words = text(values, "search");
2000
+ const within = text(values, "path");
1427
2001
  const limit = text(values, "limit");
1428
2002
  const cursor = text(values, "cursor");
1429
2003
  const rows = on(values, "rows");
1430
2004
  const code = on(values, "code");
1431
2005
  const heading = text(values, "heading");
1432
2006
  const out = text(values, "out");
2007
+ const format = text(values, "format");
2008
+ const grep = text(values, "grep");
1433
2009
  const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
1434
2010
  if (rows && code) {
1435
2011
  throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
1436
2012
  }
1437
- if ((rows || code) && (words !== undefined || limit !== undefined || cursor !== undefined)) {
2013
+ if (
2014
+ (rows || code) &&
2015
+ (words !== undefined || within !== undefined || limit !== undefined || cursor !== undefined)
2016
+ ) {
1438
2017
  throw misuse(
1439
2018
  `--rows and --code read a folder or a file whole, and go without --search: ${dataUsage}`,
1440
2019
  );
@@ -1442,32 +2021,77 @@ async function readSkills(
1442
2021
  if (!rows && !code && (heading !== undefined || out !== undefined)) {
1443
2022
  throw misuse(`--heading and --out go with --rows or --code: ${dataUsage}`);
1444
2023
  }
1445
- if (words === undefined && (limit !== undefined || cursor !== undefined)) {
2024
+ if (format !== undefined && !rows) {
1446
2025
  throw misuse(
1447
- `--limit and --cursor go with --search: ${extras.command} --search <words> [--limit <n>] [--cursor <cursor>]`,
2026
+ `--format goes with --rows: ${extras.command} --rows [<folder|file>] [--format csv|json]`,
1448
2027
  );
1449
2028
  }
1450
- const atMost = limit === undefined ? undefined : Number(limit);
1451
- if (
1452
- atMost !== undefined &&
1453
- (!Number.isInteger(atMost) || atMost < 1 || atMost > MAX_FIND_LIMIT)
1454
- ) {
1455
- throw misuse(`Not a number of results, 1 to ${MAX_FIND_LIMIT}: ${limit}`);
2029
+ if (grep !== undefined && !code) {
2030
+ throw misuse(
2031
+ `--grep goes with --code: ${extras.command} --code [<folder|file>] [--grep <pattern>]`,
2032
+ );
1456
2033
  }
1457
- // As data: the read answers for itself how the pack stands, and fails where it does not.
2034
+ // The folder a search keeps to is said once: after the words, or with --path as the
2035
+ // skillcdn command takes it.
2036
+ if (within !== undefined && words === undefined) {
2037
+ throw misuse(
2038
+ `--path goes with --search; a folder is read with ${extras.command} <folder>: ${extras.command} --search <words> [--path <folder>]`,
2039
+ );
2040
+ }
2041
+ if (within !== undefined && given !== undefined) {
2042
+ throw misuse(
2043
+ `Say the folder once: after the words, or with --path: ${extras.command} --search <words> [<folder>]`,
2044
+ );
2045
+ }
2046
+ const named = given ?? within;
2047
+ const folder = named === undefined || named === "/" || named === "." ? undefined : named;
2048
+ if (words === undefined && given === undefined && (limit !== undefined || cursor !== undefined)) {
2049
+ throw misuse(
2050
+ `--limit and --cursor go with a folder or with --search: ${extras.command} <folder> [--limit <n>] [--cursor <cursor>]`,
2051
+ );
2052
+ }
2053
+ // A page of what words find, or of what a folder holds: the bounds of each, as the pack has them.
2054
+ checkedNumber(limit, "limit", words === undefined ? BROWSE_MAX_LIMIT : FIND_MAX_LIMIT);
2055
+ const listing = await reader.skills();
2056
+ // With --json the console's own addresses stay in a document's outline; in words, the
2057
+ // commands that read its tables and its code blocks.
2058
+ const pack = consolePack(reader, listing, {
2059
+ url: session.url,
2060
+ dataCommand: session.json ? undefined : extras.command,
2061
+ });
2062
+ // As data: a read the pack refused fails with why, and nothing is printed.
1458
2063
  if (rows || code) {
1459
- return readData(io, session, reader, {
1460
- what: rows ? "rows" : "code",
1461
- path: folder,
1462
- heading,
2064
+ if (pack === undefined) {
2065
+ throw failed(refusalWords(rows ? "tables" : "code blocks", listing, owner));
2066
+ }
2067
+ return readData(io, session, pack, {
2068
+ read: rows
2069
+ ? { read: "rows", path: folder, heading, format }
2070
+ : { read: "code", path: folder, heading, grep },
1463
2071
  out,
2072
+ owner,
2073
+ words: toolWords,
1464
2074
  });
1465
2075
  }
1466
- const { listing, summary } = await packOf(reader);
1467
- // The pack as it stands; or why it does not answer, which a folder or a search would meet too.
1468
- if (summary === undefined || (words === undefined && given === undefined)) {
1469
- answer(io, session, listing, () =>
1470
- [formatSkills(listing, extras.own), extras.afterwards]
2076
+ // A pack that does not answer: said as that, which a folder or a search would meet too.
2077
+ if (pack === undefined) {
2078
+ throw refusedRead(
2079
+ io,
2080
+ session,
2081
+ owner,
2082
+ listing,
2083
+ [formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
2084
+ .filter((part): part is string => part !== undefined)
2085
+ .join("\n"),
2086
+ );
2087
+ }
2088
+ if (words === undefined && given === undefined) {
2089
+ // --json is the console's listing as it answered it; the words are the pack's own, read once more from that answer.
2090
+ const told = session.json
2091
+ ? undefined
2092
+ : await readThrough(io, session, owner, pack, { read: "skills" }, { words: toolWords });
2093
+ say(listing, () =>
2094
+ [formatSkills(listing, told?.text, extras.own, owner, toolWords), loading, extras.afterwards]
1471
2095
  .filter((part): part is string => part !== undefined)
1472
2096
  .join("\n"),
1473
2097
  );
@@ -1475,75 +2099,99 @@ async function readSkills(
1475
2099
  }
1476
2100
  if (words !== undefined) {
1477
2101
  // One page of what the words find; more is said, and asked for with --cursor.
1478
- const found = await reader.skillFind(words, { path: folder, limit: atMost, cursor });
1479
- answer(io, session, found, () => formatSkillFind(found, summary));
2102
+ const found = await readThrough(
2103
+ io,
2104
+ session,
2105
+ owner,
2106
+ pack,
2107
+ { read: "find", words, path: folder, cursor, limit },
2108
+ { words: toolWords },
2109
+ );
2110
+ say(jsonOfRead(session, pack, found), () => `${found.text}\n${loading}`);
1480
2111
  return EXIT.ok;
1481
2112
  }
1482
- // The folder whole: its pages until the end, as the pack lists them.
1483
- const pages: RestSkillBrowse[] = [];
1484
- let next: string | undefined;
1485
- let last: RestSkillBrowse | undefined;
1486
- for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1487
- last = await reader.skillBrowse({ path: folder, cursor: next });
1488
- if (last.read?.status !== "ready") {
1489
- break;
1490
- }
1491
- pages.push(last);
1492
- next = last.read.nextCursor ?? undefined;
1493
- if (next === undefined) {
1494
- break;
2113
+ // One page of the folder, or of a file's outline, as the skillcdn command browses: a page
2114
+ // that ends before the folder does names the cursor that continues it.
2115
+ const browsed = await readThrough(
2116
+ io,
2117
+ session,
2118
+ owner,
2119
+ pack,
2120
+ { read: "browse", path: folder, cursor, limit },
2121
+ { words: toolWords },
2122
+ );
2123
+ say(jsonOfRead(session, pack, browsed), () => browsed.text);
2124
+ return EXIT.ok;
2125
+ }
2126
+
2127
+ /**
2128
+ * The pack a command reads (ADR-0113): the project's where one is named; else the
2129
+ * organization's, which a desk and a folder a repository is about to be made in read, since
2130
+ * neither names a project and the skill that sets one up is in that pack.
2131
+ */
2132
+ async function packNamed(
2133
+ session: Session,
2134
+ ): Promise<{ readonly reader: PackReader; readonly owner: PackOwner }> {
2135
+ return (await session.projectKey()) === undefined
2136
+ ? { reader: session.client.organizationPack(), owner: "organization" }
2137
+ : { reader: await session.project(), owner: "project" };
2138
+ }
2139
+
2140
+ /**
2141
+ * A read of the organization's pack at a console from before ADR-0113, which has no such
2142
+ * routes and answers that nothing is at the path: said as what it is, with what still reads a
2143
+ * pack there, where the console's own words would read as a missing skill.
2144
+ */
2145
+ async function readingPack(owner: PackOwner, read: () => Promise<number>): Promise<number> {
2146
+ try {
2147
+ return await read();
2148
+ } catch (error) {
2149
+ if (owner === "organization" && error instanceof ApiError && error.code === "not_found") {
2150
+ throw failed(
2151
+ `This console does not read the organization's pack where no project is named: it is older than the command. ${NO_PROJECT}`,
2152
+ );
1495
2153
  }
2154
+ throw error;
1496
2155
  }
1497
- if (last === undefined) {
1498
- throw failed("The folder could not be read.");
1499
- }
1500
- const browsed = last;
1501
- const whole = joinFolder(pages, summary);
1502
- answer(io, session, { ...browsed, read: whole === undefined ? null : bodyOfFolder(whole) }, () =>
1503
- formatSkillBrowse(browsed, whole, extras.command),
2156
+ }
2157
+
2158
+ /**
2159
+ * Prints a read of a pack: as `answer` does, and, where the pack is the organization's, under
2160
+ * the line that says so. `--json` stays what the console answered.
2161
+ */
2162
+ function answerPack(
2163
+ io: CliIo,
2164
+ session: Session,
2165
+ owner: PackOwner,
2166
+ value: unknown,
2167
+ words: () => string,
2168
+ ): void {
2169
+ answer(io, session, value, () =>
2170
+ owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words()}` : words(),
1504
2171
  );
1505
- return EXIT.ok;
1506
2172
  }
1507
2173
 
1508
2174
  const skills: Command = async (args, io) => {
1509
2175
  const { values, positionals } = parse(args, SKILLS_OPTIONS);
1510
2176
  const session = await open(io, values);
1511
- const project = await session.project();
1512
- return readSkills(io, session, project, values, positionals, {
1513
- command: "console skills",
1514
- own: io.skillsDir,
1515
- afterwards: PLUGIN_SKILLS_LINE,
1516
- });
2177
+ const { reader, owner } = await packNamed(session);
2178
+ return readingPack(owner, () =>
2179
+ readSkills(io, session, reader, values, positionals, {
2180
+ command: "console skills",
2181
+ own: io.skillsDir,
2182
+ afterwards: PLUGIN_SKILLS_LINE,
2183
+ owner,
2184
+ }),
2185
+ );
1517
2186
  };
1518
2187
 
1519
- /** The most characters one read of a file asks for: what the console's API allows on one page. */
1520
- const MAX_FILE_LIMIT = 100_000;
1521
-
1522
- /** A count given as a flag, within its bounds, or nothing; anything else is not understood. */
1523
- function countOf(
1524
- given: string | undefined,
1525
- name: string,
1526
- bounds: { readonly least: number; readonly most?: number },
1527
- ): number | undefined {
1528
- if (given === undefined) {
1529
- return undefined;
1530
- }
1531
- const count = Number(given);
1532
- if (
1533
- !Number.isInteger(count) ||
1534
- count < bounds.least ||
1535
- (bounds.most !== undefined && count > bounds.most)
1536
- ) {
1537
- const range =
1538
- bounds.most === undefined ? `${bounds.least} or more` : `${bounds.least} to ${bounds.most}`;
1539
- throw misuse(`Not a number for --${name}, ${range}: ${given}`);
1540
- }
1541
- return count;
1542
- }
1543
-
1544
2188
  /**
1545
- * One skill of the pack whole, a file of it, or one page of a file; for the project's pack as
1546
- * `console skill`, and for a plugin's as `console plugin <key> skill`.
2189
+ * One skill of the pack, or a page of a file of it; for the project's pack as `console skill`,
2190
+ * and for a plugin's as `console plugin <key> skill`. Each as the skillcdn command reads it,
2191
+ * through its own reads (ADR-0124): a skill whole where a host shows it whole, else in parts,
2192
+ * each ending with the command that reads the next; a file a page at a time. `again` is what
2193
+ * that command says after the cursor, its words: where the pack is read, as it was said for this
2194
+ * part.
1547
2195
  */
1548
2196
  async function readSkill(
1549
2197
  io: CliIo,
@@ -1552,8 +2200,14 @@ async function readSkill(
1552
2200
  values: Values,
1553
2201
  positionals: readonly string[],
1554
2202
  command: string,
2203
+ owner: PackOwner = "project",
2204
+ again: readonly string[] = [],
1555
2205
  ): Promise<number> {
2206
+ const say = (value: unknown, words: () => string): void =>
2207
+ answerPack(io, session, owner, value, words);
2208
+ const toolWords = packWords(`${command}s`, command);
1556
2209
  const file = text(values, "file");
2210
+ const cursor = text(values, "cursor");
1557
2211
  // A file is read by its own path from the repository's root; a skill's path beside it would be
1558
2212
  // ignored, which reads as if it mattered, so the two together are not understood.
1559
2213
  if (file !== undefined && positionals.length > 0) {
@@ -1561,7 +2215,7 @@ async function readSkill(
1561
2215
  `Say one: ${command} <path of its SKILL.md> for a skill, or ${command} --file <path> for a file of the pack.`,
1562
2216
  );
1563
2217
  }
1564
- // A section is a page of a file read as asked (SkillCDN 0.4): the flags mean nothing without one.
2218
+ // A page of a file is asked for by where it begins and how long it is: the flags mean nothing without one.
1565
2219
  if (
1566
2220
  file === undefined &&
1567
2221
  (text(values, "offset") !== undefined || text(values, "limit") !== undefined)
@@ -1570,90 +2224,92 @@ async function readSkill(
1570
2224
  `--offset and --limit go with --file: ${command} --file <path> [--offset <n>] [--limit <n>]`,
1571
2225
  );
1572
2226
  }
1573
- const offset = countOf(text(values, "offset"), "offset", { least: 0 });
1574
- const limit = countOf(text(values, "limit"), "limit", { least: 1, most: MAX_FILE_LIMIT });
1575
- const { listing, summary } = await packOf(reader);
1576
- if (summary === undefined) {
1577
- answer(io, session, listing, () => formatSkills(listing, io.skillsDir));
1578
- return EXIT.ok;
2227
+ // The next part of a skill is asked for by the cursor its part ended with; a file reads on from an offset.
2228
+ if (file !== undefined && cursor !== undefined) {
2229
+ throw misuse(
2230
+ `--cursor reads the next part of a skill; a file reads on from --offset: ${command} --file <path> [--offset <n>] [--limit <n>]`,
2231
+ );
1579
2232
  }
1580
- if (file !== undefined && (offset !== undefined || limit !== undefined)) {
1581
- // One page as asked, the section a search or an outline named; the result says where the
1582
- // file continues, and asks for nothing.
1583
- const page = await reader.skillFile(file, { offset, limit });
1584
- const section = page.read === null ? undefined : joinFile([page], summary, limit);
1585
- answer(io, session, { ...page, read: section === undefined ? null : bodyOfFile(section) }, () =>
1586
- formatSkillFile(page, section),
2233
+ checkedNumber(text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
2234
+ checkedNumber(text(values, "limit"), "limit", READ_FILE_MAX_LIMIT);
2235
+ const listing = await reader.skills();
2236
+ const pack = consolePack(reader, listing, { url: session.url });
2237
+ if (pack === undefined) {
2238
+ throw refusedRead(
2239
+ io,
2240
+ session,
2241
+ owner,
2242
+ listing,
2243
+ formatSkills(listing, undefined, io.skillsDir, owner, toolWords),
1587
2244
  );
1588
- return EXIT.ok;
1589
2245
  }
1590
2246
  if (file !== undefined) {
1591
- // The file whole, page after page, as the console reads it from the pack.
1592
- const pages: RestSkillFile[] = [];
1593
- let offset: number | undefined;
1594
- let last: RestSkillFile | undefined;
1595
- for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1596
- last = await reader.skillFile(file, offset === undefined ? {} : { offset });
1597
- if (last.read === null) {
1598
- break;
1599
- }
1600
- pages.push(last);
1601
- if (last.read.kind !== "file" || last.read.nextOffset === null) {
1602
- break;
1603
- }
1604
- offset = last.read.nextOffset;
1605
- }
1606
- if (last === undefined) {
1607
- throw failed("The file could not be read.");
1608
- }
1609
- const fileRead = last;
1610
- const whole = joinFile(pages, summary);
1611
- answer(io, session, { ...fileRead, read: whole === undefined ? null : bodyOfFile(whole) }, () =>
1612
- formatSkillFile(fileRead, whole),
2247
+ // A page of the file, as the skillcdn command reads one: from --offset, as long as a host
2248
+ // shows whole where --limit says nothing, and where the next begins when the file goes on.
2249
+ const page = await readThrough(
2250
+ io,
2251
+ session,
2252
+ owner,
2253
+ pack,
2254
+ { read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") },
2255
+ { words: toolWords },
1613
2256
  );
2257
+ say(jsonOfRead(session, pack, page), () => page.text);
1614
2258
  return EXIT.ok;
1615
2259
  }
1616
- const wanted = skillPathIn(
1617
- theOne(
1618
- positionals,
1619
- `Say which skill: ${command} <path of its SKILL.md>, or ${command} --file <path> for a file of the pack`,
1620
- ),
1621
- listing.address,
2260
+ const given = theOne(
2261
+ positionals,
2262
+ `Say which skill: ${command} <path of its SKILL.md>, or ${command} --file <path> for a file of the pack`,
1622
2263
  );
2264
+ const wanted = skillPathIn(given, listing.address);
1623
2265
  if ("error" in wanted) {
1624
2266
  throw misuse(wanted.error);
1625
2267
  }
1626
- // The skill whole: its pages until complete, the rules first, as load_skill lays them out.
1627
- const pages: RestSkillLoad[] = [];
1628
- let cursor: string | undefined;
1629
- let last: RestSkillLoad | undefined;
1630
- for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1631
- last = await reader.skill(wanted.path, cursor);
1632
- if (last.read?.status !== "ready") {
1633
- break;
1634
- }
1635
- pages.push(last);
1636
- cursor = last.read.skill.nextCursor ?? undefined;
1637
- if (last.read.skill.complete === true || cursor === undefined) {
1638
- break;
1639
- }
1640
- }
1641
- if (last === undefined) {
1642
- throw failed("The skill could not be read.");
1643
- }
1644
- const loaded = last;
1645
- const whole = joinSkill(pages, summary);
1646
- answer(io, session, { ...loaded, read: whole === undefined ? null : bodyOfSkill(whole) }, () =>
1647
- formatSkillLoad(loaded, whole),
2268
+ // The skill, its rules first, as load_skill lays them out: whole, or the part that begins at
2269
+ // the cursor, ending with the command that reads the next, asked as this one was.
2270
+ let continues = false;
2271
+ const loaded = await readThrough(
2272
+ io,
2273
+ session,
2274
+ owner,
2275
+ pack,
2276
+ { read: "skill", path: wanted.path, cursor },
2277
+ {
2278
+ words: toolWords,
2279
+ // Spelled so that bash and PowerShell run it as it is; where a word has no such spelling,
2280
+ // the command that was run is run again, with the cursor, and the line says why.
2281
+ nextPart: (next) => {
2282
+ continues = true;
2283
+ return (
2284
+ commandLine(command, [given, "--cursor", next, ...again]) ??
2285
+ `the command you ran, with --cursor ${commandWord(next) ?? JSON.stringify(next)} in place of any it had, each word quoted for your shell. ${NO_LINE_TO_RUN}`
2286
+ );
2287
+ },
2288
+ },
2289
+ );
2290
+ // A part that is not the last ends with the console's own words after the library's line: a
2291
+ // fresh agent read one part of four, saw that the skill continued, and planned from that part,
2292
+ // since "before using it" did not read as now to a session that meant only to plan.
2293
+ say(jsonOfRead(session, pack, loaded), () =>
2294
+ continues ? `${loaded.text}\n${PART_ENDS_HERE}` : loaded.text,
1648
2295
  );
1649
2296
  return EXIT.ok;
1650
2297
  }
1651
2298
 
2299
+ /**
2300
+ * What a part of a skill ends with where another follows: that the instructions stop here,
2301
+ * what the rest holds, and that the command above is run now.
2302
+ */
2303
+ const PART_ENDS_HERE =
2304
+ "This part stops in the middle of the skill: its later steps, its checkpoints and its rules are in the parts that follow, and nothing above is complete without them. Run that command now, before a plan, an answer or any other step, and each next one, until a part ends without these lines.";
2305
+
1652
2306
  const skill: Command = async (args, io) => {
1653
2307
  const { values, positionals } = parse(args, SKILL_OPTIONS);
1654
2308
  const session = await open(io, values);
1655
- const project = await session.project();
1656
- return readSkill(io, session, project, values, positionals, "console skill");
2309
+ const { reader, owner } = await packNamed(session);
2310
+ return readingPack(owner, () =>
2311
+ readSkill(io, session, reader, values, positionals, "console skill", owner, whereGiven(values)),
2312
+ );
1657
2313
  };
1658
2314
 
1659
2315
  // ---- The plugins (docs/specs/plugins.md, "The command") ----
@@ -1729,7 +2385,7 @@ function splitWords(
1729
2385
  }
1730
2386
 
1731
2387
  const PLUGIN_USAGE =
1732
- "console plugin <key> [help [<command>] | <command> [args] | records <collection> | skills | skill <path> | enable | disable | settings | secret <name> | grant <role> | revoke <id>]. console plugins lists the plugins.";
2388
+ "console plugin <key> [help [<command>] | <command> [args] | records <collection> | events [--kind <kind>] | skills | skill <path> | enable | disable | settings | secret <name> [--key <key>] | grant <role> | revoke <id>]. console plugins lists the plugins.";
1733
2389
 
1734
2390
  const plugin: Command = async (args, io) => {
1735
2391
  const { values, words } = splitWords(args, PLUGIN_GLOBAL_FLAGS);
@@ -1765,6 +2421,8 @@ const plugin: Command = async (args, io) => {
1765
2421
  }
1766
2422
  case "records":
1767
2423
  return pluginRecords(io, session, client, rest, text(values, "project"));
2424
+ case "events":
2425
+ return pluginEvents(io, session, client, rest);
1768
2426
  case "skills": {
1769
2427
  const parsed = parse(rest, SKILLS_OPTIONS);
1770
2428
  return readSkills(io, session, client, parsed.values, parsed.positionals, {
@@ -1780,6 +2438,8 @@ const plugin: Command = async (args, io) => {
1780
2438
  parsed.values,
1781
2439
  parsed.positionals,
1782
2440
  `console plugin ${key} skill`,
2441
+ "project",
2442
+ whereGiven(values),
1783
2443
  );
1784
2444
  }
1785
2445
  case "enable":
@@ -1932,6 +2592,53 @@ function whereValueOf(word: string): unknown {
1932
2592
  }
1933
2593
 
1934
2594
  /** The records of a collection one may read, a page of them; or one record, or its versions. */
2595
+ /**
2596
+ * A plugin's events, newest first (ADR-0128): what it did and what went wrong in it, as far as
2597
+ * the caller may read it, which the console decides (every event for an administrator; for
2598
+ * anyone else those of the projects they may see, their own commands and the console's word of
2599
+ * the plugin); the failures alone with `--kind plugin.failed`, whether or not it has a board
2600
+ * project. A console before 0.5.1 takes no kind and answers every one: the page is narrowed
2601
+ * here, and that is said, since a page narrowed after it was read may hold fewer than were
2602
+ * asked for.
2603
+ */
2604
+ async function pluginEvents(
2605
+ io: CliIo,
2606
+ session: Session,
2607
+ client: PluginClient,
2608
+ rest: readonly string[],
2609
+ ): Promise<number> {
2610
+ const usage = `console plugin ${client.key} events [--kind <kind>] [--limit <n>] [--offset <n>]`;
2611
+ const { values, positionals } = parse(rest, { kind: { type: "string" }, ...PAGE_OPTIONS });
2612
+ if (positionals.length > 0) {
2613
+ throw misuse(`Events take no word but their flags: ${usage}`);
2614
+ }
2615
+ const kind = text(values, "kind");
2616
+ if (kind !== undefined && !/^[a-z_]{1,40}\.[a-z_]{1,40}$/.test(kind)) {
2617
+ throw misuse(
2618
+ `Not a kind of event: ${kind}. A kind is two words with a dot between, as plugin.failed or plugin.command: ${usage}`,
2619
+ );
2620
+ }
2621
+ const limit = countOf(text(values, "limit"), "limit", { least: 1, most: EVENTS_PAGE_LIMIT });
2622
+ const offset = countOf(text(values, "offset"), "offset", { least: 0, most: 1_000_000 });
2623
+ const asked = { kind, limit: limit ?? DEFAULT_PAGE_LIMIT, offset: offset ?? 0 };
2624
+ const read = await client.events(asked);
2625
+ const items = kind === undefined ? read.items : read.items.filter((one) => one.kind === kind);
2626
+ const narrowedHere = items.length !== read.items.length;
2627
+ const page = { items, more: read.more };
2628
+ answer(
2629
+ io,
2630
+ session,
2631
+ page,
2632
+ () =>
2633
+ `${formatPluginEvents(client.key, page, asked)}${
2634
+ narrowedHere
2635
+ ? `\nThis console is older than 0.5.1 and does not narrow events by kind: of the ${read.items.length} newest read, the ${kind} ones are shown. Read further back with --offset.`
2636
+ : ""
2637
+ }`,
2638
+ );
2639
+ return EXIT.ok;
2640
+ }
2641
+
1935
2642
  async function pluginRecords(
1936
2643
  io: CliIo,
1937
2644
  session: Session,
@@ -2249,31 +2956,38 @@ async function pluginSecret(
2249
2956
  client: PluginClient,
2250
2957
  rest: readonly string[],
2251
2958
  ): Promise<number> {
2252
- const { values, positionals } = parse(rest, { remove: { type: "boolean" } });
2959
+ const { values, positionals } = parse(rest, {
2960
+ remove: { type: "boolean" },
2961
+ key: { type: "string" },
2962
+ });
2253
2963
  const name = theOne(
2254
2964
  positionals,
2255
- `Say which secret: console plugin ${client.key} secret <name> [--remove]; the value is typed at the prompt, unseen, or piped in.`,
2965
+ `Say which secret: console plugin ${client.key} secret <name> [--key <key>] [--remove]; the value is typed at the prompt, unseen, or piped in.`,
2256
2966
  );
2967
+ // A secret kept per key (ADR-0111) is set and removed one key at a time.
2968
+ const key = text(values, "key");
2969
+ const which = key === undefined ? `the secret ${name}` : `the secret ${name} under ${key}`;
2970
+ const data = key === undefined ? { name } : { name, key };
2257
2971
  if (on(values, "remove")) {
2258
- await client.removeSecret(name);
2259
- answer(io, session, { name, set: false }, () => `Removed the secret ${name} of ${client.key}.`);
2972
+ await client.removeSecret(name, key);
2973
+ answer(io, session, { ...data, set: false }, () => `Removed ${which} of ${client.key}.`);
2260
2974
  return EXIT.ok;
2261
2975
  }
2262
2976
  const value = await secretGiven(
2263
2977
  io,
2264
- `Secret ${name} of ${client.key} (typed unseen; Enter ends it): `,
2978
+ `Secret ${name}${key === undefined ? "" : ` under ${key}`} of ${client.key} (typed unseen; Enter ends it): `,
2265
2979
  );
2266
2980
  if (value.length === 0) {
2267
2981
  throw misuse(
2268
- `Type the value at the prompt, or redirect a file into it: console plugin ${client.key} secret ${name} < file. Never give it on the command line or through echo, which a shell keeps; the console seals it and shows it never.`,
2982
+ `Type the value at the prompt, or redirect a file into it: console plugin ${client.key} secret ${name}${key === undefined ? "" : ` --key ${key}`} < file. Never give it on the command line or through echo, which a shell keeps; the console seals it and shows it never.`,
2269
2983
  );
2270
2984
  }
2271
- await client.setSecret(name, value);
2985
+ await client.setSecret(name, value, key);
2272
2986
  answer(
2273
2987
  io,
2274
2988
  session,
2275
- { name, set: true },
2276
- () => `Set the secret ${name} of ${client.key}: sealed, and shown by nothing from now on.`,
2989
+ { ...data, set: true },
2990
+ () => `Set ${which} of ${client.key}: sealed, and shown by nothing from now on.`,
2277
2991
  );
2278
2992
  return EXIT.ok;
2279
2993
  }
@@ -2345,8 +3059,9 @@ function versionOf(given: string | undefined): number | undefined {
2345
3059
  return version;
2346
3060
  }
2347
3061
 
2348
- // The rules of the board (ADR-0023): read before a task is taken, written by an owner for the
2349
- // project and by an administrator for the workspace, through the same page the console keeps.
3062
+ // The rules of the board (ADR-0023, ADR-0120): the console's, which always hold, with what the
3063
+ // organization and the project add to them; read before a task is taken, and added to by an
3064
+ // owner for the project and by an administrator for the organization, on the page each keeps.
2350
3065
  const rules: Command = async (args, io) => {
2351
3066
  const [verb, ...rest] = args;
2352
3067
  if (verb === "write") {
@@ -2364,7 +3079,7 @@ const rules: Command = async (args, io) => {
2364
3079
  const body = none ? undefined : await bodyOf(io, values, given);
2365
3080
  if (!none && body === undefined) {
2366
3081
  throw misuse(
2367
- "Say what the rules are to say: --body <markdown>, --file <path>, - to read standard input, or none to put the written rules away.",
3082
+ "Say what is added to the rules: --body <markdown>, --file <path>, - to read standard input, or none to put what was added away.",
2368
3083
  );
2369
3084
  }
2370
3085
  const baseVersion = versionOf(text(values, "base"));
@@ -2376,18 +3091,28 @@ const rules: Command = async (args, io) => {
2376
3091
  io,
2377
3092
  session,
2378
3093
  put,
2379
- () => "The organization's rules are put away: the console's own hold.",
3094
+ () => "What this organization adds to the rules is put away: the console's stand alone.",
2380
3095
  );
2381
3096
  return EXIT.ok;
2382
3097
  }
3098
+ // A console of before 0.5.1 keeps what is written here as the organization's whole rules,
3099
+ // in the place of its own (ADR-0120): what is added would be all that holds there. Its
3100
+ // answer tells, since it says the workspace's rules whole and no parts, and it is asked
3101
+ // before anything is written.
3102
+ const held = await session.client.rules();
3103
+ if (held.own === undefined) {
3104
+ throw failed(
3105
+ "This console is older than 0.5.1 and keeps the organization's rules whole: what is written here would replace the console's rules, not add to them. Update the console first.",
3106
+ );
3107
+ }
2383
3108
  const written = await session.client.writeRules({
2384
3109
  body: body ?? "",
2385
3110
  ...(baseVersion === undefined ? {} : { baseVersion }),
2386
3111
  });
2387
3112
  answer(io, session, written, () =>
2388
3113
  written.page === null
2389
- ? "Nothing written: these are the console's own rules as they stand, and they hold already."
2390
- : `Wrote the workspace's rules, version ${written.page.version}.`,
3114
+ ? "Nothing written: that adds nothing to the console's rules, which hold as they stand."
3115
+ : `Wrote what this organization adds to the rules, version ${written.page.version}.`,
2391
3116
  );
2392
3117
  return EXIT.ok;
2393
3118
  }
@@ -2395,12 +3120,22 @@ const rules: Command = async (args, io) => {
2395
3120
  if (none) {
2396
3121
  try {
2397
3122
  const put = await project.archiveDocument(RULES_PATH);
2398
- answer(io, session, put, () => "This project's rules are put away: it adds none now.");
3123
+ answer(
3124
+ io,
3125
+ session,
3126
+ put,
3127
+ () => "What this project adds to the rules is put away: it adds nothing now.",
3128
+ );
2399
3129
  } catch (error) {
2400
3130
  if (!(error instanceof ApiError) || error.code !== "document.not_found") {
2401
3131
  throw error;
2402
3132
  }
2403
- answer(io, session, null, () => "This project has no rules of its own to put away.");
3133
+ answer(
3134
+ io,
3135
+ session,
3136
+ null,
3137
+ () => "This project adds nothing to the rules: nothing to put away.",
3138
+ );
2404
3139
  }
2405
3140
  return EXIT.ok;
2406
3141
  }
@@ -2409,14 +3144,19 @@ const rules: Command = async (args, io) => {
2409
3144
  body: body ?? "",
2410
3145
  ...(baseVersion === undefined ? {} : { baseVersion }),
2411
3146
  });
2412
- answer(io, session, written, () => `Wrote this project's rules, version ${written.version}.`);
3147
+ answer(
3148
+ io,
3149
+ session,
3150
+ written,
3151
+ () => `Wrote what this project adds to the rules, version ${written.version}.`,
3152
+ );
2413
3153
  return EXIT.ok;
2414
3154
  }
2415
3155
  const { values } = parse(args, {}, false);
2416
3156
  const session = await open(io, values);
2417
3157
  const key = await session.projectKey();
2418
3158
  const [found, me] = await Promise.all([
2419
- key === undefined ? session.client.rules() : session.client.project(key).rules(),
3159
+ key === undefined ? session.client.rules() : (await session.project()).rules(),
2420
3160
  session.client.me(),
2421
3161
  ]);
2422
3162
  const read =
@@ -2427,19 +3167,27 @@ const rules: Command = async (args, io) => {
2427
3167
  ...(found.plugins === undefined ? {} : { plugins: found.plugins }),
2428
3168
  }
2429
3169
  : forPerson(found, readingLanguage(me));
2430
- answer(io, session, read, () => formatRules(read, readingLanguage(me)));
3170
+ // The mark of what is printed goes with --json too, for a program that takes a task next.
3171
+ answer(io, session, { ...read, mark: rulesMark(read, readingLanguage(me)) }, () =>
3172
+ formatRules(read, readingLanguage(me)),
3173
+ );
2431
3174
  return EXIT.ok;
2432
3175
  };
2433
3176
 
2434
3177
  /**
2435
3178
  * The rules as they read for the person whose token the command holds: `{language}` filled
2436
- * with the language they read in, or with the task's while they have none.
3179
+ * with the language they read in, or with the task's while they have none; in the whole and,
3180
+ * where the console says them apart (ADR-0120), in the console's own and in what is added.
2437
3181
  */
2438
- function forPerson<T extends { readonly body: string | null }>(
2439
- half: T,
2440
- language: string | null,
2441
- ): T {
2442
- return half.body === null ? half : { ...half, body: fillRules(half.body, language) };
3182
+ function forPerson(half: RestRules, language: string | null): RestRules {
3183
+ return {
3184
+ ...half,
3185
+ ...(half.body === null ? {} : { body: fillRules(half.body, language) }),
3186
+ ...(half.own === undefined ? {} : { own: fillRules(half.own, language) }),
3187
+ ...(half.added == null
3188
+ ? {}
3189
+ : { added: { ...half.added, body: fillRules(half.added.body, language) } }),
3190
+ };
2443
3191
  }
2444
3192
 
2445
3193
  /** The flags that set a task's fields, shared by writing one and changing one. */
@@ -2520,8 +3268,28 @@ const newTask: Command = async (args, io) => {
2520
3268
  ...TASK_FIELDS,
2521
3269
  body: { type: "string" },
2522
3270
  file: { type: "string" },
3271
+ take: { type: "boolean" },
3272
+ agent: { type: "string" },
3273
+ rules: { type: "string" },
2523
3274
  });
2524
3275
  const title = theOne(positionals, 'Say the title: console task new "<title>"');
3276
+ // Written and taken in one command (--take): work given in chat is both at once, and a
3277
+ // session that sends its commands together cannot read the number between two of them,
3278
+ // on a board where another agent may have written a task in the meantime.
3279
+ const taken = on(values, "take");
3280
+ if (!taken && (text(values, "rules") !== undefined || text(values, "agent") !== undefined)) {
3281
+ throw misuse(
3282
+ '--rules and --agent go with --take, which takes the task as it is written: console task new "<title>" --take [--rules <mark>] [--agent <name>]',
3283
+ );
3284
+ }
3285
+ // Refused before anything is written: a task that is done or dropped is not taken, and
3286
+ // written first it would stand on the board as the half of a command that failed.
3287
+ const said = stateOf(text(values, "state"));
3288
+ if (taken && (said === "done" || said === "dropped")) {
3289
+ throw misuse(
3290
+ `A task written as ${said} is not taken. Leave --state out, for ready; or leave --take out.`,
3291
+ );
3292
+ }
2525
3293
  const body = await bodyOf(io, values, text(values, "body"));
2526
3294
  const session = await open(io, values);
2527
3295
  const project = await session.project();
@@ -2529,14 +3297,46 @@ const newTask: Command = async (args, io) => {
2529
3297
  const made = await project.createTask({
2530
3298
  title,
2531
3299
  ...(body === undefined ? {} : { body }),
3300
+ // An idea is not taken: what is written to be taken is ready, where no state is said.
3301
+ ...(taken && said === undefined ? { state: "ready" as const } : {}),
2532
3302
  ...fields,
2533
3303
  });
2534
- answer(
2535
- io,
2536
- session,
2537
- made,
2538
- () => `Task #${made.number} written: ${made.title}\ntask id: ${made.id}`,
2539
- );
3304
+ const written = `Task #${made.number} written: ${made.title}\ntask id: ${made.id}`;
3305
+ if (!taken) {
3306
+ // With the address of its page, for a person told of the task; a task taken at once says
3307
+ // it in the task's own lines below, once.
3308
+ const page = await taskPage(session, made.number);
3309
+ answer(io, session, made, () =>
3310
+ page === undefined ? written : `${written}\n${pageLine(page)}`,
3311
+ );
3312
+ return EXIT.ok;
3313
+ }
3314
+ // The number first, before the take is asked for: whatever becomes of the take, the task is
3315
+ // on the board, and the session must know it by its number so as not to write it twice.
3316
+ if (!session.json) {
3317
+ io.stdout(`${written}\n`);
3318
+ }
3319
+ let run: RestRun | undefined;
3320
+ let took: Taking;
3321
+ try {
3322
+ run = await runOn(project, made, values);
3323
+ took = await taking(session, project, made, made.id, run, values);
3324
+ } catch (error) {
3325
+ // Said before the console's own words for what failed, which follow as on any command:
3326
+ // which half stands, by the task's number, so that nothing is written or taken twice.
3327
+ if (session.json) {
3328
+ io.stdout(
3329
+ `${JSON.stringify({ written: made, ...(run === undefined ? {} : { run }) }, null, 2)}\n`,
3330
+ );
3331
+ }
3332
+ io.stderr(
3333
+ run === undefined
3334
+ ? `Task #${made.number} is written and was not taken: it stands on the board as written. Take it with console take ${made.number}, and do not write it again. What the take ended on:\n`
3335
+ : `Task #${made.number} is written and taken, run ${run.id}, and what a take prints of it was not read. Do not write it or take it again: console task ${made.number} shows the task, console rules the rules. What the reading ended on:\n`,
3336
+ );
3337
+ throw error;
3338
+ }
3339
+ answer(io, session, { written: made, ...took.value }, took.words);
2540
3340
  return EXIT.ok;
2541
3341
  };
2542
3342
 
@@ -2567,7 +3367,8 @@ const editTask: Command = async (args, io) => {
2567
3367
  }
2568
3368
  const found = await project.task(ref);
2569
3369
  const changed = await project.updateTask(found.id, patch);
2570
- answer(io, session, changed, () => formatTask(changed));
3370
+ const page = await taskPage(session, changed.number);
3371
+ answer(io, session, changed, () => formatTask(changed, undefined, undefined, undefined, page));
2571
3372
  return EXIT.ok;
2572
3373
  };
2573
3374
 
@@ -2630,14 +3431,17 @@ const task: Command = async (args, io) => {
2630
3431
  const found = await project.task(ref);
2631
3432
  const [decisions, runs, comments] = await Promise.all([
2632
3433
  project.decisions({ task: found.id }),
2633
- project.runs({ task: found.id }),
3434
+ // The runs are a line each, with their reports counted: the brief form, unless --json asks
3435
+ // for the console's own answer.
3436
+ session.json ? project.runs({ task: found.id }) : project.runBriefs({ task: found.id }),
2634
3437
  project.comments(found.id),
2635
3438
  ]);
3439
+ const page = await taskPage(session, found.number);
2636
3440
  answer(
2637
3441
  io,
2638
3442
  session,
2639
3443
  { task: found, decisions: decisions.items, runs: runs.items, comments: comments.items },
2640
- () => formatTask(found, decisions.items, runs.items, comments.items),
3444
+ () => formatTask(found, decisions.items, runs.items, comments.items, page),
2641
3445
  );
2642
3446
  return EXIT.ok;
2643
3447
  };
@@ -2740,17 +3544,40 @@ const file: Command = async (args, io) => {
2740
3544
  return EXIT.ok;
2741
3545
  };
2742
3546
 
2743
- const take: Command = async (args, io) => {
2744
- const { values, positionals } = parse(args, { agent: { type: "string" } });
2745
- const ref = theOne(positionals, "Say which task: console take <number|id>");
2746
- const session = await open(io, values);
2747
- const project = await session.project();
2748
- const found = await project.task(ref);
3547
+ /** What a take answers: the value `--json` prints, and the words otherwise. */
3548
+ interface Taking {
3549
+ value: {
3550
+ run: RestRun;
3551
+ task: RestTask;
3552
+ comments: readonly unknown[];
3553
+ rules: Record<string, unknown>;
3554
+ };
3555
+ words: () => string;
3556
+ }
3557
+
3558
+ /** Begins a run on a task, as the agent `--agent` names where it is said: the take itself. */
3559
+ function runOn(project: ProjectClient, found: RestTask, values: Values): Promise<RestRun> {
2749
3560
  const agent = text(values, "agent");
2750
- const run = await project.startRun({
3561
+ return project.startRun({
2751
3562
  taskId: found.id,
2752
3563
  ...(agent === undefined ? {} : { agent }),
2753
3564
  });
3565
+ }
3566
+
3567
+ /**
3568
+ * What a take answers, once its run began: the task as it stands taken, its comments and the
3569
+ * rules under their mark, or left out by it (`--rules`, ADR-0119). `take` takes a task that
3570
+ * was read by what the person said, `task new --take` the one it has just written; `ref` is
3571
+ * what the task is read again by, now that it is taken.
3572
+ */
3573
+ async function taking(
3574
+ session: Session,
3575
+ project: ProjectClient,
3576
+ found: RestTask,
3577
+ ref: string,
3578
+ run: RestRun,
3579
+ values: Values,
3580
+ ): Promise<Taking> {
2754
3581
  // The rules come with the run, as they read for the person: everything from here acts
2755
3582
  // within them (ADR-0023); the task is read again, as it stands now that it is taken.
2756
3583
  const [ruling, me, taken, comments, openRuns] = await Promise.all([
@@ -2758,7 +3585,7 @@ const take: Command = async (args, io) => {
2758
3585
  session.client.me(),
2759
3586
  project.task(ref),
2760
3587
  project.comments(found.id),
2761
- project.runs({ open: true, mine: true }),
3588
+ project.runBriefs({ open: true, mine: true }),
2762
3589
  ]);
2763
3590
  // Taking a task with a run open on it ends that run (ADR-0020): said when it happened.
2764
3591
  const tookOver =
@@ -2777,21 +3604,51 @@ const take: Command = async (args, io) => {
2777
3604
  project: forPerson(ruling.project, readingLanguage(me)),
2778
3605
  ...(ruling.plugins === undefined ? {} : { plugins: ruling.plugins }),
2779
3606
  };
2780
- answer(io, session, { run, task: taken, comments: comments.items, rules }, () =>
2781
- [
2782
- `Run ${run.id} began on #${found.number} ${found.title}, as "${run.agent}" for ${calledOf(run.person)}. The task is in progress and theirs.${tookOver}${elsewhere}`,
2783
- // The ids on a line of their own, each named: a run's and a task's begin alike, and a
2784
- // task has a number for people as well.
2785
- `run id: ${run.id} task id: ${found.id} (task #${found.number})`,
2786
- "",
2787
- formatTask(taken, undefined, undefined, comments.items),
2788
- "",
2789
- formatRules(rules, readingLanguage(me)),
2790
- "",
2791
- 'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
2792
- 'Ask when a person must decide: console ask "<question>" --option "..." --option "...". A word for the task\'s people that is not a report: console comment <number> "<markdown>". End with: console finish --summary "<what was done, what is left>".',
2793
- ].join("\n"),
2794
- );
3607
+ // A take gives the rules, whole, unless the session says the mark they have (ADR-0119): a
3608
+ // mark is known only from having been shown them, so a session that never was, a fresh one
3609
+ // or a subagent, gets them whatever it does. A mark that is not theirs, since they changed
3610
+ // or it is of another project's, gets them whole again, and is told so first. The line that
3611
+ // answers a mark stands directly after the run's ids, before the task: a take is cut at its
3612
+ // head by a session that holds the rules, and a rule that changed is what such a cut must
3613
+ // not lose. Without a mark nothing is said there, and the rules follow the task as before.
3614
+ const language = readingLanguage(me);
3615
+ const mark = rulesMark(rules, language);
3616
+ const held = text(values, "rules")?.trim().toLowerCase();
3617
+ const answered =
3618
+ held === undefined ? [] : [held === mark ? formatRulesLeftOut(mark) : formatRulesChanged(held)];
3619
+ const ruled = held === mark ? [] : [formatRules(rules, language), ""];
3620
+ const page = await taskPage(session, taken.number);
3621
+ return {
3622
+ value: { run, task: taken, comments: comments.items, rules: { ...rules, mark } },
3623
+ words: () =>
3624
+ [
3625
+ `Run ${run.id} began on #${found.number} ${found.title}, as "${run.agent}" for ${calledOf(run.person)}. The task is in progress and theirs.${tookOver}${elsewhere}`,
3626
+ // The ids on a line of their own, each named: a run's and a task's begin alike, and a
3627
+ // task has a number for people as well.
3628
+ `run id: ${run.id} task id: ${found.id} (task #${found.number})`,
3629
+ ...answered,
3630
+ "",
3631
+ formatTask(taken, undefined, undefined, comments.items, page),
3632
+ "",
3633
+ ...ruled,
3634
+ 'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
3635
+ 'Ask when a person must decide: console ask "<question>" --option "..." --option "...". A word for the task\'s people that is not a report: console comment <number> "<markdown>". End with: console finish --summary "<what was done, what is left>".',
3636
+ ].join("\n"),
3637
+ };
3638
+ }
3639
+
3640
+ const take: Command = async (args, io) => {
3641
+ const { values, positionals } = parse(args, {
3642
+ agent: { type: "string" },
3643
+ rules: { type: "string" },
3644
+ });
3645
+ const ref = theOne(positionals, "Say which task: console take <number|id> [--rules <mark>]");
3646
+ const session = await open(io, values);
3647
+ const project = await session.project();
3648
+ const found = await project.task(ref);
3649
+ const run = await runOn(project, found, values);
3650
+ const took = await taking(session, project, found, ref, run, values);
3651
+ answer(io, session, took.value, took.words);
2795
3652
  return EXIT.ok;
2796
3653
  };
2797
3654
 
@@ -2811,7 +3668,7 @@ const report: Command = async (args, io) => {
2811
3668
  }
2812
3669
  const session = await open(io, values);
2813
3670
  const project = await session.project();
2814
- const runId = await currentRun(project, values);
3671
+ const runId = await currentRun(session, project, values);
2815
3672
  const run = await project.report(runId, { body });
2816
3673
  answer(
2817
3674
  io,
@@ -2857,7 +3714,7 @@ const handIn: Command = async (args, io) => {
2857
3714
  const label = text(values, "label");
2858
3715
  const session = await open(io, values);
2859
3716
  const project = await session.project();
2860
- const runId = await currentRun(project, values);
3717
+ const runId = await currentRun(session, project, values);
2861
3718
  // A URL is handed in as a link, and the console says whether it takes it; anything else
2862
3719
  // names a file on this machine.
2863
3720
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(what)) {
@@ -2928,7 +3785,7 @@ const ask: Command = async (args, io) => {
2928
3785
  const files = await attachmentsOf(io, texts(values, "attach"));
2929
3786
  const session = await open(io, values);
2930
3787
  const project = await session.project();
2931
- const runId = await currentRun(project, values);
3788
+ const runId = await currentRun(session, project, values);
2932
3789
  // Whom the decision is for (ADR-0042, ADR-0057): the person the agent works for, unless --to
2933
3790
  // names others of the project, each once; several, and any of them may answer.
2934
3791
  const deciderIds: string[] = [];
@@ -2954,13 +3811,28 @@ const ask: Command = async (args, io) => {
2954
3811
  );
2955
3812
  const withFiles =
2956
3813
  files.length === 0 ? "" : `, with ${files.length} file${files.length === 1 ? "" : "s"}`;
2957
- // The id is printed before any waiting, so that a wait cut short loses nothing.
3814
+ // The id is printed before any waiting, so that a wait cut short loses nothing; and the
3815
+ // address of its page, which is what a person told of the decision is given to open.
2958
3816
  io.stdout(
2959
3817
  session.json
2960
3818
  ? `${JSON.stringify(raised, null, 2)}\n`
2961
- : `Decision ${raised.id} raised on run ${runId}${withFiles}; the run waits for ${deciderLogins(raised)}.\ndecision id: ${raised.id}\n${formatOptions(raised)}\n`,
3819
+ : `Decision ${raised.id} raised on run ${runId}${withFiles}; the run waits for ${deciderLogins(raised)}.\ndecision id: ${raised.id}\n${pageLine(await decisionPage(session, raised.id))}\n${formatOptions(raised)}\n`,
2962
3820
  );
2963
- return settle(io, session, project, raised, seconds, true);
3821
+ // An agent account is attended by nobody, and the answer wakes it (ADR-0085): it waits at no
3822
+ // terminal unless it asked to, and is told to go on with other work, where an attended
3823
+ // agent is told how to keep waiting. A wait it asked for that runs out ends in the same
3824
+ // words: waiting on is not what it is told to do then either.
3825
+ const wakes =
3826
+ raised.raisedBy.kind === "agent"
3827
+ ? `The answer wakes you: go on with other work meanwhile, and with this run when it comes (--run ${runId}). The run stays open while the decision waits.`
3828
+ : undefined;
3829
+ if (wakes !== undefined && text(values, "wait") === undefined) {
3830
+ if (!session.json) {
3831
+ io.stdout(`${wakes}\n`);
3832
+ }
3833
+ return EXIT.waiting;
3834
+ }
3835
+ return settle(io, session, project, raised, seconds, true, wakes);
2964
3836
  };
2965
3837
 
2966
3838
  /**
@@ -2992,7 +3864,8 @@ const answering: Command = async (args, io) => {
2992
3864
  ...(own === undefined ? { option } : { own }),
2993
3865
  ...(note === undefined ? {} : { note }),
2994
3866
  });
2995
- answer(io, session, answered, () => formatDecision(answered, { atItsAddress }));
3867
+ const page = await decisionPage(session, answered.id, atItsAddress);
3868
+ answer(io, session, answered, () => formatDecision(answered, { atItsAddress, page }));
2996
3869
  return EXIT.ok;
2997
3870
  };
2998
3871
 
@@ -3046,6 +3919,27 @@ async function reachDecision(
3046
3919
  }
3047
3920
  }
3048
3921
 
3922
+ /**
3923
+ * The project a write on a decision goes to: the one the command works in; where none is named,
3924
+ * the decision's own, as the console says it of the decision wherever it is (ADR-0068). A desk
3925
+ * names no project, and the wake that brings an answer names the decision alone: what followed
3926
+ * is written from there as the decision was read from there. With a project named nothing is
3927
+ * looked up, and the console answers for that project as before.
3928
+ */
3929
+ async function projectOfDecision(session: Session, id: string): Promise<ProjectClient> {
3930
+ if ((await session.projectKey()) !== undefined) {
3931
+ return session.project();
3932
+ }
3933
+ try {
3934
+ return session.client.project((await session.client.decision(id)).project.key);
3935
+ } catch (error) {
3936
+ if (error instanceof ApiError && error.status === 404) {
3937
+ throw new ApiError(404, "decision.not_found", "The decision was not found.");
3938
+ }
3939
+ throw error;
3940
+ }
3941
+ }
3942
+
3049
3943
  /** Writes an answer on a decision as the command reaches it (ADR-0068): in the project, else wherever it is. */
3050
3944
  async function answerReached(
3051
3945
  session: Session,
@@ -3101,7 +3995,7 @@ const decision: Command = async (args, io) => {
3101
3995
  if (tos.length > 0) {
3102
3996
  // Whom a decision that waits is for, said anew (ADR-0096): the people named take the place
3103
3997
  // of those it was for, each once in the order named.
3104
- const project = await session.project();
3998
+ const project = await projectOfDecision(session, id);
3105
3999
  const deciderIds: string[] = [];
3106
4000
  for (const to of tos) {
3107
4001
  const named = await personIdOf(session, to);
@@ -3110,22 +4004,34 @@ const decision: Command = async (args, io) => {
3110
4004
  }
3111
4005
  }
3112
4006
  const addressed = await project.addressDecision(id, deciderIds);
3113
- answer(io, session, addressed, () => formatDecision(addressed));
4007
+ const page = await decisionPage(session, addressed.id);
4008
+ answer(io, session, addressed, () => formatDecision(addressed, { page }));
3114
4009
  return EXIT.ok;
3115
4010
  }
3116
4011
  if (outcome !== undefined) {
3117
4012
  // What followed the decision: the record grows, and is printed as it stands.
3118
- const project = await session.project();
4013
+ const project = await projectOfDecision(session, id);
3119
4014
  const grown = await project.updateDecision(id, { outcome });
3120
- answer(io, session, grown, () => formatDecision(grown));
4015
+ const page = await decisionPage(session, grown.id);
4016
+ answer(io, session, grown, () => formatDecision(grown, { page }));
3121
4017
  return EXIT.ok;
3122
4018
  }
3123
4019
  const { decision: found, waiter, atItsAddress } = await reachDecision(session, id);
3124
4020
  if (seconds === 0) {
3125
- answer(io, session, found, () => formatDecision(found, { atItsAddress }));
4021
+ const page = await decisionPage(session, found.id, atItsAddress);
4022
+ answer(io, session, found, () => formatDecision(found, { atItsAddress, page }));
3126
4023
  return EXIT.ok;
3127
4024
  }
3128
- return settle(io, session, waiter, found, seconds);
4025
+ // An agent account is attended by nobody, and the answer to a decision it raised wakes it
4026
+ // (ADR-0085): a wait of its own that runs out ends in the account's words, as ask's does, and
4027
+ // not in how an attended agent waits on. Whether the command is the account is what the
4028
+ // login kept says (`login --self`), since the decision alone does not: a person's agent may
4029
+ // wait for a decision an account raised, and is told how to keep waiting.
4030
+ const wakes =
4031
+ signedInAsItself(session) && found.raisedBy.login === session.account
4032
+ ? `Decision ${found.id} still waits for a person. The answer wakes you: go on with other work meanwhile, and with its run when it comes${found.run === null ? "" : ` (--run ${found.run.id})`}. The run stays open while the decision waits.`
4033
+ : undefined;
4034
+ return settle(io, session, waiter, found, seconds, false, wakes);
3129
4035
  };
3130
4036
 
3131
4037
  const docs: Command = async (args, io) => {
@@ -3139,8 +4045,10 @@ const docs: Command = async (args, io) => {
3139
4045
  const search = text(values, "search");
3140
4046
  const session = await open(io, values);
3141
4047
  const project = await session.project();
4048
+ // A folder is taken as the listing prints it, `guides/`, and as it is named, `guides`.
4049
+ const folder = positionals[0]?.replace(/\/+$/, "");
3142
4050
  const found = await project.documents({
3143
- ...(positionals[0] === undefined ? {} : { folder: positionals[0] }),
4051
+ ...(folder === undefined || folder === "" ? {} : { folder }),
3144
4052
  ...(search === undefined ? {} : { q: search }),
3145
4053
  ...(on(values, "archived") ? { archived: true } : {}),
3146
4054
  });
@@ -3219,12 +4127,15 @@ const write: Command = async (args, io) => {
3219
4127
  body,
3220
4128
  ...(baseVersion === undefined ? {} : { baseVersion }),
3221
4129
  });
4130
+ // The page's address, as a task's and a decision's: what an agent tells a person and hands in.
4131
+ const key = await session.projectKey();
4132
+ const page = key === undefined ? undefined : `${session.url}${docHref(key, written.path)}`;
3222
4133
  answer(
3223
4134
  io,
3224
4135
  session,
3225
4136
  written,
3226
4137
  () =>
3227
- `Wrote ${written.path} (${written.title}), version ${written.version}${written.links.length === 0 ? "" : `; refers to ${written.links.map((link) => link.path).join(", ")}`}`,
4138
+ `Wrote ${written.path} (${written.title}), version ${written.version}${written.links.length === 0 ? "" : `; refers to ${written.links.map((link) => link.path).join(", ")}`}${page === undefined ? "" : `\n${pageLine(page)}`}`,
3228
4139
  );
3229
4140
  return EXIT.ok;
3230
4141
  };
@@ -3402,7 +4313,9 @@ const goal: Command = async (args, io) => {
3402
4313
  const session = await open(io, values);
3403
4314
  const project = await session.project();
3404
4315
  const found = await project.goal(id);
3405
- const towards = await project.tasks({ goal: found.id });
4316
+ const towards = session.json
4317
+ ? await project.tasks({ goal: found.id })
4318
+ : await project.taskBriefs({ goal: found.id });
3406
4319
  answer(io, session, { goal: found, tasks: towards.items }, () =>
3407
4320
  formatGoal(found, towards.items),
3408
4321
  );
@@ -3450,6 +4363,37 @@ const decisions: Command = async (args, io) => {
3450
4363
  return EXIT.ok;
3451
4364
  };
3452
4365
 
4366
+ /**
4367
+ * Says how a run ended, and where that left its task (ADR-0114). The console places the task,
4368
+ * and where is not the command's to know: a finished run leaves it at work where another run is
4369
+ * open on it, and a run that failed or was given up does that too, and on a console of before
4370
+ * 0.5.1 always, or where a person moved it meanwhile. So the task is read once the run is over, and its state said as it stands. On
4371
+ * `--json` the answer is the run as the console gave it, and nothing more is asked.
4372
+ */
4373
+ async function sayEnded(
4374
+ io: CliIo,
4375
+ session: Session,
4376
+ project: ProjectClient,
4377
+ run: RestRun,
4378
+ status: "finished" | "failed" | "abandoned",
4379
+ ): Promise<void> {
4380
+ let words = "";
4381
+ if (!session.json) {
4382
+ try {
4383
+ const task = await project.task(run.taskId);
4384
+ words = `Run ${run.id} ${status}; task #${task.number} is ${task.state} now.`;
4385
+ } catch (error) {
4386
+ // Said before the console's own words for what failed, which follow as on any command:
4387
+ // the run is over whatever became of the reading, and is not to be ended again.
4388
+ io.stderr(
4389
+ `Run ${run.id} ${status}, and where that left task #${run.taskNumber} was not read. The run is over: do not end it again. console task ${run.taskNumber} shows the task. What the reading ended on:\n`,
4390
+ );
4391
+ throw error;
4392
+ }
4393
+ }
4394
+ answer(io, session, run, () => words);
4395
+ }
4396
+
3453
4397
  const ending =
3454
4398
  (status: "finished" | "failed"): Command =>
3455
4399
  async (args, io) => {
@@ -3461,16 +4405,12 @@ const ending =
3461
4405
  const summary = await bodyOf(io, values, text(values, "summary"));
3462
4406
  const session = await open(io, values);
3463
4407
  const project = await session.project();
3464
- const runId = await currentRun(project, values);
4408
+ const runId = await currentRun(session, project, values);
3465
4409
  const run = await project.endRun(runId, {
3466
4410
  status,
3467
4411
  ...(summary === undefined ? {} : { summary }),
3468
4412
  });
3469
- answer(io, session, run, () =>
3470
- status === "finished"
3471
- ? `Run ${run.id} finished; the task is up for review.`
3472
- : `Run ${run.id} failed; the task stays as it is.`,
3473
- );
4413
+ await sayEnded(io, session, project, run, status);
3474
4414
  return EXIT.ok;
3475
4415
  };
3476
4416
 
@@ -3486,12 +4426,12 @@ const abandon: Command = async (args, io) => {
3486
4426
  const summary = await bodyOf(io, values, text(values, "summary"));
3487
4427
  const session = await open(io, values);
3488
4428
  const project = await session.project();
3489
- const runId = positionals[0] ?? (await currentRun(project, values));
4429
+ const runId = positionals[0] ?? (await currentRun(session, project, values));
3490
4430
  const run = await project.endRun(runId, {
3491
4431
  status: "abandoned",
3492
4432
  ...(summary === undefined ? {} : { summary }),
3493
4433
  });
3494
- answer(io, session, run, () => `Run ${run.id} abandoned; the task stays as it is.`);
4434
+ await sayEnded(io, session, project, run, "abandoned");
3495
4435
  return EXIT.ok;
3496
4436
  };
3497
4437
 
@@ -3511,20 +4451,49 @@ const runs: Command = async (args, io) => {
3511
4451
  const project = await session.project();
3512
4452
  const ref = text(values, "task");
3513
4453
  const taskId = ref === undefined ? undefined : (await project.task(ref)).id;
3514
- const found = await project.runs({
4454
+ const mine = on(values, "mine");
4455
+ const filter = {
3515
4456
  ...(taskId === undefined ? {} : { task: taskId }),
3516
4457
  ...(on(values, "open") ? { open: true } : {}),
3517
- ...(on(values, "mine") ? { mine: true } : {}),
4458
+ ...(mine ? { mine: true } : {}),
3518
4459
  ...page,
4460
+ };
4461
+ const [found, agent] = await Promise.all([
4462
+ // A line a run, its reports counted: the brief form, unless --json asks for the console's own.
4463
+ session.json ? project.runs(filter) : project.runBriefs(filter),
4464
+ // With a token, --mine is the runs begun with that token, one agent's, and a person may
4465
+ // have more: an empty listing would read as if they had none, so whose these are is said.
4466
+ mine && !session.json ? tokenNameOf(session) : undefined,
4467
+ ]);
4468
+ const others =
4469
+ "A run of yours begun through another agent, or before a new sign-in, is listed without --mine, where each line says whom it is for and through which agent.";
4470
+ answer(io, session, found, () => {
4471
+ if (found.items.length === 0) {
4472
+ return agent === undefined
4473
+ ? "No runs."
4474
+ : `No runs begun through this agent (${agent}). ${others}`;
4475
+ }
4476
+ const listed =
4477
+ found.items.map(formatRunLine).join("\n") + formatMore(found.more, page.limit, page.offset);
4478
+ return agent === undefined
4479
+ ? listed
4480
+ : `${listed}\nThese are the runs begun through this agent (${agent}). ${others}`;
3519
4481
  });
3520
- answer(io, session, found, () =>
3521
- found.items.length === 0
3522
- ? "No runs."
3523
- : found.items.map(formatRunLine).join("\n") + formatMore(found.more, page.limit, page.offset),
3524
- );
3525
4482
  return EXIT.ok;
3526
4483
  };
3527
4484
 
4485
+ /** What the token the command acts with is called, or nothing where it acts on a session or cannot be asked. */
4486
+ async function tokenNameOf(session: Session): Promise<string | undefined> {
4487
+ try {
4488
+ return (await session.client.me()).agent ?? undefined;
4489
+ } catch (error) {
4490
+ if (error instanceof ApiError) {
4491
+ return undefined;
4492
+ }
4493
+ throw error;
4494
+ }
4495
+ }
4496
+
3528
4497
  const run: Command = async (args, io) => {
3529
4498
  const { values, positionals } = parse(args, {});
3530
4499
  const id = theOne(positionals, "Say which run: console run <id>");
@@ -3549,12 +4518,16 @@ function portOf(value: string | undefined): number {
3549
4518
 
3550
4519
  /**
3551
4520
  * A console of the person's own, served from this machine (ADR-0014): the build's pages here,
3552
- * and everything under /api/ carried to the console with the token, which the pages never see.
4521
+ * and everything under /api/ carried to the console with the token, which the pages never see;
4522
+ * and, with --records, what a desk keeps under /records/ (ADR-0117), for the desk's pages.
3553
4523
  */
3554
4524
  const serve: Command = async (args, io) => {
3555
- const { values, positionals } = parse(args, { port: { type: "string" } });
4525
+ const { values, positionals } = parse(args, {
4526
+ port: { type: "string" },
4527
+ records: { type: "string" },
4528
+ });
3556
4529
  if (positionals.length > 1) {
3557
- throw misuse("Say at most one directory: console serve [<dir>] [--port <n>]");
4530
+ throw misuse("Say at most one directory: console serve [<dir>] [--port <n>] [--records <dir>]");
3558
4531
  }
3559
4532
  const [dir] = positionals;
3560
4533
  const port = portOf(text(values, "port"));
@@ -3581,6 +4554,24 @@ const serve: Command = async (args, io) => {
3581
4554
  throw error;
3582
4555
  }
3583
4556
  }
4557
+ const kept = text(values, "records");
4558
+ let records: RecordsRoot | undefined;
4559
+ if (kept !== undefined) {
4560
+ try {
4561
+ records = await loadRecordsRoot(kept);
4562
+ } catch (error) {
4563
+ if (error instanceof RecordsRootError) {
4564
+ throw failed(
4565
+ `No records to serve: ${error.message}. Name the records/ of a desk: console serve <dir> --records <desk>/records`,
4566
+ );
4567
+ }
4568
+ throw error;
4569
+ }
4570
+ }
4571
+ // Whether the records are there is asked before anything listens: the line says what the
4572
+ // command found when it began. Asked after, a directory made in the moment between, by a
4573
+ // session that began keeping something as the pages came up, read as there all along.
4574
+ const recordsThere = records === undefined ? false : await records.there();
3584
4575
  const listening = await listen(
3585
4576
  (bound) =>
3586
4577
  createServeHandler({
@@ -3589,13 +4580,22 @@ const serve: Command = async (args, io) => {
3589
4580
  fetch: io.fetch,
3590
4581
  port: bound,
3591
4582
  web,
4583
+ records,
3592
4584
  }),
3593
4585
  port,
3594
4586
  );
4587
+ // A desk has its records/ once it keeps something (ADR-0122): until then the line says that
4588
+ // nothing is kept there, and that what comes to be is served with no restart.
4589
+ const served =
4590
+ kept === undefined || records === undefined
4591
+ ? ""
4592
+ : recordsThere
4593
+ ? ` The records in ${kept} are at ${listening.url}records/, read as they are when they are asked for.`
4594
+ : ` Nothing is kept in ${kept} yet: what comes to be kept there is at ${listening.url}records/ from then on, with no restart.`;
3595
4595
  io.stdout(
3596
4596
  web === undefined
3597
- ? `Serving the API of ${me.workspace.name} (${session.url}) at ${listening.url}api/ as ${person.login}, for a development server to send its /api/ requests to. Stop with Ctrl+C.\n`
3598
- : `Serving ${dir} at ${listening.url} as ${person.login}: the pages are there, and everything under /api/ goes to ${me.workspace.name} (${session.url}) with your token, which the pages never see. Stop with Ctrl+C.\n`,
4597
+ ? `Serving the API of ${me.workspace.name} (${session.url}) at ${listening.url}api/ as ${person.login}, for a development server to send its /api/ requests to.${served} Stop with Ctrl+C.\n`
4598
+ : `Serving ${dir} at ${listening.url} as ${person.login}: the pages are there, and everything under /api/ goes to ${me.workspace.name} (${session.url}) with your token, which the pages never see.${served} Stop with Ctrl+C.\n`,
3599
4599
  );
3600
4600
  await listening.closed;
3601
4601
  return EXIT.ok;
@@ -3646,6 +4646,52 @@ const machineLine = (text: string): string => {
3646
4646
  return line.length === 0 ? "unknown" : line;
3647
4647
  };
3648
4648
 
4649
+ /**
4650
+ * Keeps a runner going across its `runner.json` (ADR-0144): a runner that ended for its file is
4651
+ * followed by another, begun with the file as it is now, in this process. Where the file stopped
4652
+ * reading in between, the agent having written it again in the turn that was under way, the next
4653
+ * runner begins with the file as it last read, so that there is always one: it then says what is
4654
+ * wrong with the file to the agent, whose session it is the only way to. Answers how the last
4655
+ * runner ended, once one ended for anything else or whoever runs the command asked it to stop.
4656
+ */
4657
+ export async function keepRunning<Config>(input: {
4658
+ readonly first: Config;
4659
+ /** The desk's file as it stands now, or what is wrong with it in a few words. */
4660
+ readonly read: () => Promise<
4661
+ | { readonly ok: true; readonly config: Config }
4662
+ | { readonly ok: false; readonly problem: string }
4663
+ >;
4664
+ readonly start: (config: Config) => Pick<Runner, "run" | "stop">;
4665
+ /** Resolves when whoever runs the command asks it to stop. */
4666
+ readonly stopped: Promise<void>;
4667
+ readonly say: (line: string) => void;
4668
+ }): Promise<RunnerEnd> {
4669
+ let good = input.first;
4670
+ let running = input.start(good);
4671
+ let asked = false;
4672
+ void input.stopped.then(() => {
4673
+ asked = true;
4674
+ running.stop();
4675
+ });
4676
+ for (;;) {
4677
+ const how = await running.run();
4678
+ if (how !== "changed" || asked) {
4679
+ return how;
4680
+ }
4681
+ const next = await input.read();
4682
+ if (next.ok) {
4683
+ good = next.config;
4684
+ } else {
4685
+ input.say(`${next.problem}: the runner starts again with the runner.json it last read`);
4686
+ }
4687
+ running = input.start(good);
4688
+ // Asked to stop while the file was read: the runner just begun ends at once.
4689
+ if (asked) {
4690
+ running.stop();
4691
+ }
4692
+ }
4693
+ }
4694
+
3649
4695
  // The runner of an agent account (ADR-0085, docs/specs/runner.md): started in the account's
3650
4696
  // desk, on the command signed in as the account itself. It keeps the agent's session going,
3651
4697
  // feeds it what the console sends and reports what it does, until it is stopped.
@@ -3668,29 +4714,36 @@ const runner: Command = async (args, io) => {
3668
4714
  "A runner is an agent account's own, on the command signed in as the account itself: console login --self, approved in a browser signed in as the account.",
3669
4715
  );
3670
4716
  }
3671
- const written = await host.readText("runner.json");
3672
- const read =
3673
- written === undefined
3674
- ? { ok: true as const, config: DEFAULT_RUNNER_CONFIG }
3675
- : parseRunnerConfig(written);
3676
- if (!read.ok) {
3677
- throw failed(
3678
- `${read.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`,
3679
- );
3680
- }
3681
4717
  const modules = ownRunnerModules({ user: host.user });
3682
- const driverOf = modules.drivers.get(read.config.driver);
3683
- if (driverOf === undefined) {
3684
- throw failed(
3685
- `runner.json names the driver ${read.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}.`,
3686
- );
3687
- }
3688
- const unknown = read.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
3689
- if (unknown !== undefined) {
3690
- throw failed(
3691
- `runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}.`,
3692
- );
3693
- }
4718
+ /**
4719
+ * The desk's runner.json as it stands: its text, what it says, and the driver it names; or
4720
+ * what is wrong with it in a few words. No file is the defaults.
4721
+ */
4722
+ const readConfig = async () => {
4723
+ const written = await host.readText("runner.json");
4724
+ const parsed =
4725
+ written === undefined
4726
+ ? { ok: true as const, config: DEFAULT_RUNNER_CONFIG }
4727
+ : parseRunnerConfig(written);
4728
+ if (!parsed.ok) {
4729
+ return { ok: false as const, problem: parsed.problem };
4730
+ }
4731
+ const driverOf = modules.drivers.get(parsed.config.driver);
4732
+ if (driverOf === undefined) {
4733
+ return {
4734
+ ok: false as const,
4735
+ problem: `runner.json names the driver ${parsed.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}`,
4736
+ };
4737
+ }
4738
+ const unknown = parsed.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
4739
+ if (unknown !== undefined) {
4740
+ return {
4741
+ ok: false as const,
4742
+ problem: `runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}`,
4743
+ };
4744
+ }
4745
+ return { ok: true as const, config: parsed.config, driverOf, text: written ?? "" };
4746
+ };
3694
4747
  // A header says the hour and the minute in the workspace's zone, or the machine's where it has none.
3695
4748
  const zone = me.workspace.timeZone ?? undefined;
3696
4749
  let clock: Intl.DateTimeFormat;
@@ -3709,73 +4762,109 @@ const runner: Command = async (args, io) => {
3709
4762
  });
3710
4763
  }
3711
4764
  const statePath = workPath("runner-state.json");
3712
- const running = createRunner({
3713
- client: session.client,
3714
- driver: driverOf({
3715
- spawn: host.spawn,
3716
- cwd: host.cwd,
3717
- command: read.config.product?.command,
3718
- args: read.config.product?.args,
3719
- version: io.version,
3720
- }),
3721
- config: read.config,
3722
- cwd: host.cwd,
3723
- machine: {
3724
- name: machineLine(io.hostname ?? ""),
3725
- os: machineLine(host.os),
3726
- user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
3727
- },
3728
- version: io.version ?? "0.0.0",
3729
- // A runner whose own version is not known has nothing to hold the package's against.
3730
- installed: io.version === undefined ? undefined : io.installedVersion,
3731
- // What installs the console's version here, the way this command was installed.
3732
- updateCommand: () => updateWords(io, io.consoleVersion?.()),
3733
- now: io.now,
3734
- random: host.random,
3735
- time: (iso) => clock.format(new Date(iso)),
3736
- files: {
3737
- write: (path, text) => host.writePrivate(workPath(path), text),
3738
- remove: (path) => host.remove(workPath(path)),
3739
- },
3740
- state: {
3741
- load: async () => runnerStateOf(await host.readText(statePath)),
3742
- save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
3743
- },
3744
- log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
3745
- // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
3746
- // A step that reaches the git host is handed the account's token for it, as the clone of
3747
- // the desk was: answered from the environment of that one command, and only to the host
3748
- // the workspace keeps its desks at.
3749
- git: async (args, handed) => {
3750
- const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
3751
- const child = host.spawn("git", args, {
4765
+ const person = me.person;
4766
+ /** A runner for the desk's runner.json as it is read now: begun again whenever the file changed (ADR-0144). */
4767
+ const runnerOf = (read: Extract<Awaited<ReturnType<typeof readConfig>>, { ok: true }>) => {
4768
+ const { driverOf } = read;
4769
+ return createRunner({
4770
+ client: session.client,
4771
+ driver: driverOf({
4772
+ spawn: host.spawn,
3752
4773
  cwd: host.cwd,
3753
- env:
3754
- handed?.token === undefined || origin === undefined
3755
- ? { GIT_TERMINAL_PROMPT: "0" }
3756
- : gitTokenEnv(handed.token, origin),
3757
- });
3758
- child.end();
3759
- for await (const _ of child.lines) {
3760
- // Nothing of what git prints is kept.
3761
- }
3762
- return (await child.exited).code;
3763
- },
3764
- // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
3765
- wakes: {
3766
- sources: read.config.wake.flatMap((name) => {
3767
- const source = modules.wakeSources.get(name);
3768
- return source === undefined || source.run === undefined ? [] : [source];
4774
+ command: read.config.product?.command,
4775
+ args: read.config.product?.args,
4776
+ version: io.version,
3769
4777
  }),
3770
- fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
3771
- socket: (url) => host.socket(url),
3772
- },
3773
- });
4778
+ config: read.config,
4779
+ reconfigured: async () => {
4780
+ const now = await readConfig();
4781
+ return !now.ok ? { problem: now.problem } : now.text === read.text ? "same" : "changed";
4782
+ },
4783
+ cwd: host.cwd,
4784
+ machine: {
4785
+ name: machineLine(io.hostname ?? ""),
4786
+ os: machineLine(host.os),
4787
+ user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
4788
+ },
4789
+ version: io.version ?? "0.0.0",
4790
+ // A runner whose own version is not known has nothing to hold the package's against.
4791
+ installed: io.version === undefined ? undefined : io.installedVersion,
4792
+ // What installs the console's version here, the way this command was installed.
4793
+ updateCommand: () => updateWords(io, io.consoleVersion?.()),
4794
+ now: io.now,
4795
+ random: host.random,
4796
+ time: (iso) => clock.format(new Date(iso)),
4797
+ files: {
4798
+ write: (path, text) => host.writePrivate(workPath(path), text),
4799
+ remove: (path) => host.remove(workPath(path)),
4800
+ },
4801
+ state: {
4802
+ load: async () => runnerStateOf(await host.readText(statePath)),
4803
+ save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
4804
+ },
4805
+ log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
4806
+ // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
4807
+ // A step that reaches the git host is handed the account's token for it, as the clone of
4808
+ // the desk was: answered from the environment of that one command, and only to the host
4809
+ // the workspace keeps its desks at.
4810
+ git: async (args, handed) => {
4811
+ const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
4812
+ const child = host.spawn("git", args, {
4813
+ cwd: host.cwd,
4814
+ env:
4815
+ handed?.token === undefined || origin === undefined
4816
+ ? { GIT_TERMINAL_PROMPT: "0" }
4817
+ : gitTokenEnv(handed.token, origin),
4818
+ });
4819
+ child.end();
4820
+ for await (const _ of child.lines) {
4821
+ // Nothing of what git prints is kept.
4822
+ }
4823
+ return (await child.exited).code;
4824
+ },
4825
+ // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
4826
+ wakes: {
4827
+ sources: read.config.wake.flatMap((name) => {
4828
+ const source = modules.wakeSources.get(name);
4829
+ return source === undefined || source.run === undefined ? [] : [source];
4830
+ }),
4831
+ fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
4832
+ socket: (url) => host.socket(url),
4833
+ },
4834
+ });
4835
+ };
4836
+ const first = await readConfig();
4837
+ if (!first.ok) {
4838
+ throw failed(
4839
+ `${first.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`,
4840
+ );
4841
+ }
3774
4842
  io.stdout(
3775
- `The runner of @${me.person.handle ?? me.person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`,
4843
+ `The runner of @${person.handle ?? person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`,
3776
4844
  );
3777
- void host.untilStopped().then(() => running.stop());
3778
- if ((await running.run()) === "updated") {
4845
+ // The machine is held awake while the runner runs, where the system has a way that needs no
4846
+ // administrator (ADR-0140): said in the runner's own lines, either way.
4847
+ const said = (line: string): void => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`);
4848
+ void host
4849
+ .keepAwake?.()
4850
+ .then((awake) =>
4851
+ said(
4852
+ "by" in awake
4853
+ ? `the machine is kept from sleeping while the runner runs (${awake.by})`
4854
+ : `the machine is not kept from sleeping by the runner (${awake.problem}): set it never to sleep when idle`,
4855
+ ),
4856
+ );
4857
+ const how = await keepRunning({
4858
+ first,
4859
+ read: async () => {
4860
+ const next = await readConfig();
4861
+ return next.ok ? { ok: true, config: next } : next;
4862
+ },
4863
+ start: runnerOf,
4864
+ stopped: host.untilStopped(),
4865
+ say: said,
4866
+ });
4867
+ if (how === "updated") {
3779
4868
  // The service that keeps a runner starts it again whenever it ends; one started by hand is
3780
4869
  // started again by hand.
3781
4870
  io.stdout(
@@ -3917,8 +5006,13 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
3917
5006
  formatAgentLine(made),
3918
5007
  made.person.invited === true
3919
5008
  ? host === "gh"
3920
- ? // A login at a git host goes to whoever registers it, and the console lets that one in.
3921
- `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: that account has to be the organization's own at the git host already, since until its first sign-in binds it here the console lets in whoever holds that login.`
5009
+ ? // A login at a git host goes to whoever registers it: what the first sign-in is held
5010
+ // to is said (ADR-0126), and by a console older than the answer, the login alone.
5011
+ made.firstSignIn === "account"
5012
+ ? `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: confirmed at the git host, so that account alone is let in as it, whatever it is called by then.`
5013
+ : made.firstSignIn === "member"
5014
+ ? `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: not confirmed, since the organization at the git host has no member called so, or could not be asked. It is let in once it is a member there, and nobody else is under that login.`
5015
+ : `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: ${made.firstSignIn === "login" ? "not confirmed, since this console reads no organization at the git host. That" : "that"} account has to be the organization's own at the git host already, since until its first sign-in binds it here the console lets in whoever holds that login.`
3922
5016
  : `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: that account is made at the provider before its machine is set up, and its first sign-in with it binds it here.`
3923
5017
  : `${made.person.login} is an agent account from now on, with everything it did.`,
3924
5018
  ...(made.onboarding === null || made.onboarding === undefined
@@ -3954,6 +5048,15 @@ async function secretValue(io: CliIo, values: Values, prompt: string): Promise<s
3954
5048
  return value;
3955
5049
  }
3956
5050
 
5051
+ /**
5052
+ * The kind of git host the workspace names, where it names one: what a token for git is held to
5053
+ * the shape of. Asked for the secret that is one alone, since no other is held to a host's shape.
5054
+ */
5055
+ const gitHostFor = async (client: ConsoleClient, name: string): Promise<string | undefined> =>
5056
+ name === GIT_TOKEN_SECRET
5057
+ ? ((await client.me().catch(() => undefined))?.workspace.services?.git?.kind ?? undefined)
5058
+ : undefined;
5059
+
3957
5060
  const SECRET_FLAGS: OptionSpec = {
3958
5061
  set: { type: "boolean" },
3959
5062
  remove: { type: "boolean" },
@@ -3991,11 +5094,13 @@ const secret: Command = async (args, io) => {
3991
5094
  if (on(values, "set")) {
3992
5095
  const expiresOn = expiryOf(io, values);
3993
5096
  const value = await secretValue(io, values, `Value of ${name} (typed unseen; Enter ends it): `);
5097
+ const host = await gitHostFor(session.client, name);
3994
5098
  const kept = await session.client.setSecret(name, {
3995
5099
  value,
3996
5100
  ...(expiresOn === undefined ? {} : { expiresOn }),
3997
5101
  });
3998
- answer(io, session, kept, () => `Kept: ${formatSecretLine(kept)}`);
5102
+ const notes = secretNotes(name, value, host);
5103
+ answer(io, session, kept, () => [`Kept: ${formatSecretLine(kept)}`, ...notes].join("\n"));
3999
5104
  return EXIT.ok;
4000
5105
  }
4001
5106
  // The value alone, for whatever reads it next; the reading is on the account's record.
@@ -4010,7 +5115,22 @@ const agentSecrets = async (args: readonly string[], io: CliIo): Promise<number>
4010
5115
  const { values, positionals } = parse(args, {});
4011
5116
  const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle>"));
4012
5117
  const session = await open(io, values);
4013
- const found = await session.client.agentSecrets(handle);
5118
+ let found: Awaited<ReturnType<ConsoleClient["agentSecrets"]>>;
5119
+ try {
5120
+ found = await session.client.agentSecrets(handle);
5121
+ } catch (error) {
5122
+ // An account that asks for its own secrets by the supervisor's command is told which
5123
+ // command is its own, where the console's refusal says only whose this one is.
5124
+ if (error instanceof ApiError && error.code === "auth.forbidden") {
5125
+ const me = await session.client.me().catch(() => undefined);
5126
+ if (me?.person?.kind === "agent" && me.person.handle === handle) {
5127
+ throw failed(
5128
+ `auth.forbidden: console agent secrets is a supervisor's command, and you are @${handle} yourself. Your own store is read with console secrets, and one secret of it with console secret <name>.`,
5129
+ );
5130
+ }
5131
+ }
5132
+ throw error;
5133
+ }
4014
5134
  answer(io, session, found, () =>
4015
5135
  found.items.length === 0
4016
5136
  ? `@${handle} keeps no secret yet.`
@@ -4043,15 +5163,151 @@ const agentSecret = async (args: readonly string[], io: CliIo): Promise<number>
4043
5163
  values,
4044
5164
  `Value of ${name} for @${handle} (typed unseen; Enter ends it): `,
4045
5165
  );
5166
+ const host = await gitHostFor(session.client, name);
4046
5167
  const kept = await session.client.seedAgentSecret(handle, name, {
4047
5168
  value,
4048
5169
  ...(expiresOn === undefined ? {} : { expiresOn }),
4049
5170
  });
4050
- answer(
4051
- io,
4052
- session,
4053
- kept,
4054
- () => `Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`,
5171
+ const notes = secretNotes(name, value, host);
5172
+ answer(io, session, kept, () =>
5173
+ [`Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`, ...notes].join(
5174
+ "\n",
5175
+ ),
5176
+ );
5177
+ return EXIT.ok;
5178
+ };
5179
+
5180
+ const OWN_WAKE_FLAGS: OptionSpec = {
5181
+ file: { type: "string" },
5182
+ in: { type: "string" },
5183
+ at: { type: "string" },
5184
+ key: { type: "string" },
5185
+ cancel: { type: "boolean" },
5186
+ };
5187
+
5188
+ const OWN_WAKE_USAGE =
5189
+ 'Say when, or nothing for now: console agent wake me ["<words>"] [--in <minutes> | --at <HH:MM>] [--key <name>] | agent wake me --cancel [--key <name>]';
5190
+
5191
+ /** The hour and the minute it is in a time zone, as minutes of its day; in the machine's own where the zone names none. */
5192
+ function minutesOfDayIn(zone: string | undefined, now: Date): number {
5193
+ let parts: Intl.DateTimeFormatPart[];
5194
+ try {
5195
+ parts = new Intl.DateTimeFormat("en-GB", {
5196
+ hour: "2-digit",
5197
+ minute: "2-digit",
5198
+ hourCycle: "h23",
5199
+ ...(zone === undefined ? {} : { timeZone: zone }),
5200
+ }).formatToParts(now);
5201
+ } catch {
5202
+ parts = new Intl.DateTimeFormat("en-GB", {
5203
+ hour: "2-digit",
5204
+ minute: "2-digit",
5205
+ hourCycle: "h23",
5206
+ }).formatToParts(now);
5207
+ }
5208
+ const of = (type: string): number =>
5209
+ Number(parts.find((part) => part.type === type)?.value ?? "0");
5210
+ return of("hour") * 60 + of("minute");
5211
+ }
5212
+
5213
+ /**
5214
+ * When a wake for later is raised, as the flags say it: so many minutes from now, or the next
5215
+ * time the workspace's clock says an hour and a minute; nothing where neither flag is given.
5216
+ */
5217
+ export function ownWakeMoment(
5218
+ given: { readonly in?: string | undefined; readonly at?: string | undefined },
5219
+ zone: string | undefined,
5220
+ now: Date,
5221
+ ): Date | undefined {
5222
+ if (given.in !== undefined && given.at !== undefined) {
5223
+ throw misuse(OWN_WAKE_USAGE);
5224
+ }
5225
+ if (given.in !== undefined) {
5226
+ const minutes = Number(given.in);
5227
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > MAX_OWN_WAKE_DAYS * 24 * 60) {
5228
+ throw misuse(
5229
+ `Not a number of minutes, from 1 to ${MAX_OWN_WAKE_DAYS * 24 * 60}: ${given.in}`,
5230
+ );
5231
+ }
5232
+ return new Date(now.getTime() + minutes * 60_000);
5233
+ }
5234
+ if (given.at !== undefined) {
5235
+ const clock = /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/.exec(given.at);
5236
+ if (clock === null) {
5237
+ throw misuse(`Not an hour and a minute, as 14:30: ${given.at}`);
5238
+ }
5239
+ const wanted = Number(clock[1]) * 60 + Number(clock[2]);
5240
+ // The next time the clock says so: later today, or tomorrow where that hour has passed.
5241
+ const day = 24 * 60;
5242
+ const ahead = (wanted - minutesOfDayIn(zone, now) + day) % day || day;
5243
+ const at = new Date(now.getTime() + ahead * 60_000);
5244
+ at.setSeconds(0, 0);
5245
+ // Where the zone's clock is put forward or back before then, the moment is off by that
5246
+ // much: moved by what the clock says there, once, where the clock then says the hour asked
5247
+ // for and the moment is still to come. An hour the clock skips that night is no hour of
5248
+ // that day: the moment stays the one counted, just past it.
5249
+ const off = ((wanted - minutesOfDayIn(zone, at) + day + day / 2) % day) - day / 2;
5250
+ const moved = new Date(at.getTime() + off * 60_000);
5251
+ return off !== 0 && moved.getTime() > now.getTime() && minutesOfDayIn(zone, moved) === wanted
5252
+ ? moved
5253
+ : at;
5254
+ }
5255
+ return undefined;
5256
+ }
5257
+
5258
+ // A wake an agent account raises for itself (ADR-0145), by its own command: now, for whoever
5259
+ // prepared its machine or signed something in there to say so and for the agent to go on; or
5260
+ // kept for a moment to come, for an agent that has something to look at again.
5261
+ const ownWake = async (args: readonly string[], io: CliIo): Promise<number> => {
5262
+ const { values, positionals } = parse(args, OWN_WAKE_FLAGS);
5263
+ const [, words, ...rest] = positionals;
5264
+ if (rest.length > 0) {
5265
+ throw misuse(OWN_WAKE_USAGE);
5266
+ }
5267
+ const key = text(values, "key");
5268
+ if (key !== undefined && !/^[a-z0-9][a-z0-9-]{0,39}$/.test(key)) {
5269
+ throw misuse(
5270
+ `Not a name for a wake, which is up to 40 lowercase letters, digits and hyphens: ${key}`,
5271
+ );
5272
+ }
5273
+ const session = await open(io, values);
5274
+ /** A console of before knows no such route: said as what it is. */
5275
+ const asked = async <T>(ask: () => Promise<T>): Promise<T> => {
5276
+ try {
5277
+ return await ask();
5278
+ } catch (error) {
5279
+ if (error instanceof ApiError && error.status === 404 && error.code === "not_found") {
5280
+ throw failed(
5281
+ "This console does not take an account's own wake yet: it does from 0.5.2 on.",
5282
+ );
5283
+ }
5284
+ throw error;
5285
+ }
5286
+ };
5287
+ if (on(values, "cancel")) {
5288
+ const named = key ?? OWN_WAKE_KEY;
5289
+ await asked(() => session.client.cancelOwnWake(named));
5290
+ answer(io, session, { cancelled: named }, () => `The wake ${named} is taken away.`);
5291
+ return EXIT.ok;
5292
+ }
5293
+ const said = ((await bodyOf(io, values, words)) ?? "").trim();
5294
+ const me = await session.client.me();
5295
+ const at = ownWakeMoment(
5296
+ { in: text(values, "in"), at: text(values, "at") },
5297
+ me.workspace.timeZone ?? undefined,
5298
+ new Date(io.now()),
5299
+ );
5300
+ const raised = await asked(() =>
5301
+ session.client.raiseOwnWake({
5302
+ ...(said.length === 0 ? {} : { text: said }),
5303
+ ...(at === undefined ? {} : { at: at.toISOString() }),
5304
+ ...(key === undefined ? {} : { key }),
5305
+ }),
5306
+ );
5307
+ answer(io, session, raised, () =>
5308
+ raised.kept === null
5309
+ ? `Raised, as signal #${raised.signal?.number ?? "?"} of your record: your runner takes it as it takes any wake.`
5310
+ : `Kept: ${formatOwnWakeLine(raised.kept)}\nTake it away: console agent wake me --cancel${raised.kept.key === OWN_WAKE_KEY ? "" : ` --key ${raised.kept.key}`}. A second under the same name takes its place.`,
4055
5311
  );
4056
5312
  return EXIT.ok;
4057
5313
  };
@@ -4075,6 +5331,19 @@ const agentSignal = async (
4075
5331
  args: readonly string[],
4076
5332
  io: CliIo,
4077
5333
  ): Promise<number> => {
5334
+ // An account's own wake is another command under the same word: console agent wake me,
5335
+ // wherever `me` stands among its flags.
5336
+ if (kind === "wake") {
5337
+ let whom: string | undefined;
5338
+ try {
5339
+ whom = parse(args, OWN_WAKE_FLAGS).positionals[0];
5340
+ } catch {
5341
+ whom = undefined;
5342
+ }
5343
+ if (whom === "me") {
5344
+ return ownWake(args, io);
5345
+ }
5346
+ }
4078
5347
  const { values, positionals } = parse(args, { file: { type: "string" } });
4079
5348
  const [given, words, ...rest] = positionals;
4080
5349
  const needs = WORDED_SIGNALS[kind]?.needs === true;
@@ -4156,11 +5425,21 @@ const agentSignals = async (args: readonly string[], io: CliIo): Promise<number>
4156
5425
  ...(limit === undefined ? {} : { limit: Number(limit) }),
4157
5426
  ...(before === undefined ? {} : { before: Number(before) }),
4158
5427
  });
4159
- answer(io, session, found, () =>
4160
- found.items.length === 0
5428
+ // What the account keeps for later (ADR-0145) stands over the record's first page: it is no
5429
+ // signal yet. A console of before keeps none, and says nothing of it.
5430
+ const kept =
5431
+ before === undefined
5432
+ ? await session.client
5433
+ .ownWakes(handle)
5434
+ .then((wakes) => wakes.items)
5435
+ .catch(() => [])
5436
+ : [];
5437
+ answer(io, session, kept.length === 0 ? found : { ...found, kept }, () =>
5438
+ found.items.length === 0 && kept.length === 0
4161
5439
  ? "No signal yet."
4162
5440
  : [
4163
- ...found.items.map(formatSignalLine),
5441
+ ...kept.map(formatOwnWakeLine),
5442
+ ...found.items.map((signal) => formatSignalLine(signal, found.delivered)),
4164
5443
  ...(found.more
4165
5444
  ? [
4166
5445
  `More before: console agent signals ${handle} --before ${found.items.at(-1)?.number}`,
@@ -4221,6 +5500,8 @@ const SETUP_FLAGS: OptionSpec = {
4221
5500
  refresh: { type: "boolean" },
4222
5501
  "new-desk": { type: "boolean" },
4223
5502
  "no-service": { type: "boolean" },
5503
+ driver: { type: "string" },
5504
+ "no-browser": { type: "boolean" },
4224
5505
  };
4225
5506
 
4226
5507
  type Me = Awaited<ReturnType<ConsoleClient["me"]>>;
@@ -4320,6 +5601,8 @@ async function settleDesk(
4320
5601
  workspace: Me["workspace"],
4321
5602
  url: string,
4322
5603
  values: Values,
5604
+ /** What a look at the machine found, for a setup that looked: the driver and the browser a new desk names. */
5605
+ look?: Pick<MachineLook, "driver" | "browser"> | undefined,
4323
5606
  ): Promise<string> {
4324
5607
  const desk = await deskOf(machine, values);
4325
5608
  const handle = person.handle ?? "";
@@ -4351,6 +5634,7 @@ async function settleDesk(
4351
5634
  );
4352
5635
  }
4353
5636
  io.stdout(`The desk is cloned from ${remote} into ${desk}.\n`);
5637
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
4354
5638
  return desk;
4355
5639
  }
4356
5640
  const written: string[] = [];
@@ -4358,6 +5642,15 @@ async function settleDesk(
4358
5642
  agent: { name: person.name ?? handle, handle, title: person.title ?? null },
4359
5643
  console: { url, workspace: workspace.name },
4360
5644
  services: deskServicesOf(workspace, handle),
5645
+ // The product found on the machine, and its browser: what the runner starts with.
5646
+ runner:
5647
+ look === undefined
5648
+ ? undefined
5649
+ : {
5650
+ ...DEFAULT_RUNNER_CONFIG,
5651
+ ...(look.driver === undefined ? {} : { driver: look.driver }),
5652
+ ...(look.browser === undefined ? {} : { browser: look.browser }),
5653
+ },
4361
5654
  })) {
4362
5655
  const file = machine.path(desk, path);
4363
5656
  if (!(await machine.exists(file))) {
@@ -4366,11 +5659,61 @@ async function settleDesk(
4366
5659
  }
4367
5660
  }
4368
5661
  io.stdout(
4369
- `A new desk is written at ${desk} (${written.join(", ")}). It is the agent's from now on: to edit, to make a repository of, and to push to its git host.\n`,
5662
+ `A new desk is written at ${desk} (${written.join(", ")}). It is the agent's from now on: to edit and to push to its git host.\n`,
4370
5663
  );
5664
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
4371
5665
  return desk;
4372
5666
  }
4373
5667
 
5668
+ /**
5669
+ * The desk's own git settings (ADR-0140): a repository where it is none yet, and for the host
5670
+ * the workspace keeps its desks at, a credential helper that reads the account's token from its
5671
+ * store when git asks, in place of whatever the machine has configured. The agent then pushes
5672
+ * with nothing typed, and no copy of the token is left in a keychain or a file. Nothing where
5673
+ * the workspace names no git host, the command does not know how it was started, or git is not
5674
+ * there; what did not succeed is said and the setup goes on.
5675
+ */
5676
+ async function settleDeskGit(
5677
+ io: CliIo,
5678
+ machine: SetupMachine,
5679
+ desk: string,
5680
+ url: string,
5681
+ login: string,
5682
+ remote: string | undefined,
5683
+ ): Promise<void> {
5684
+ const origin = gitOriginOf(remote);
5685
+ if (origin === undefined || machine.self === undefined) {
5686
+ return;
5687
+ }
5688
+ const git = (args: readonly string[]): Promise<Ran> => machine.run("git", ["-C", desk, ...args]);
5689
+ if (!(await machine.exists(machine.path(desk, ".git")))) {
5690
+ if ((await git(["init", "--quiet"])).code !== 0) {
5691
+ return;
5692
+ }
5693
+ }
5694
+ // The helper as git's own shell runs it: every word in single quotes, a path with its
5695
+ // slashes forward, which that shell takes on every system.
5696
+ const word = (text: string): string => `'${text.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`;
5697
+ const read = [...machine.self, "secret", GIT_TOKEN_SECRET, "--url", url, "--account", login]
5698
+ .map(word)
5699
+ .join(" ");
5700
+ const helper = `!f() { test "$1" = get && printf 'username=x-access-token\\npassword=%s\\n' "$(${read})"; }; f`;
5701
+ const key = `credential.${origin}.helper`;
5702
+ const kept = await git(["config", "--local", "--get-all", key]);
5703
+ if (kept.code === 0 && kept.out.includes(GIT_TOKEN_SECRET)) {
5704
+ return;
5705
+ }
5706
+ // An empty helper first: whatever the machine has configured for that host is left out.
5707
+ const cleared = await git(["config", "--local", "--replace-all", key, ""]);
5708
+ const added =
5709
+ cleared.code === 0 ? await git(["config", "--local", "--add", key, helper]) : cleared;
5710
+ io.stdout(
5711
+ added.code === 0
5712
+ ? `The desk's git reads the account's ${GIT_TOKEN_SECRET} from its store when ${origin} asks: nothing is typed, and no copy is kept elsewhere.\n`
5713
+ : `The desk's git was not set to read the account's token from its store (${lastWords(added)}); the agent hands it to git itself.\n`,
5714
+ );
5715
+ }
5716
+
4374
5717
  /**
4375
5718
  * The service that keeps the runner running (ADR-0085), by the module of this platform: its
4376
5719
  * files written and, for a first setup, its commands run; answers where the runner's own lines
@@ -4505,8 +5848,12 @@ async function signInAsAccount(
4505
5848
  URL.canParse(begun.url) && new URL(begun.url).origin === url
4506
5849
  ? await machine.open(begun.url)
4507
5850
  : false;
5851
+ // The end of the wait is a moment as any other the command prints (ADR-0035), as a login's
5852
+ // is: in the workspace's time zone where a login at this console kept it, as the API gave it
5853
+ // where none has.
5854
+ setMomentZone(credentials.logins.find((kept) => kept.url === url)?.timeZone);
4508
5855
  io.stdout(
4509
- `${opened ? `The page is opened in this machine's browser: ${begun.url}` : `Open ${begun.url} in this machine's browser`}. Sign in there as ${login}, check that the page shows the code ${begun.code}, and say that it is you. On a machine without a screen, open the address in any browser that is signed in as the account.\nWaiting for that, until ${begun.expiresAt}.\n`,
5856
+ `${opened ? `The page is opened in this machine's browser: ${begun.url}` : `Open ${begun.url} in this machine's browser`}. Sign in there as ${login}, check that the page shows the code ${begun.code}, and say that it is you. On a machine without a screen, open the address in any browser that is signed in as the account.\nWaiting for that, until ${moment(begun.expiresAt)}.\n`,
4510
5857
  );
4511
5858
  let secret: string;
4512
5859
  for (;;) {
@@ -4549,7 +5896,7 @@ async function awaitRunner(
4549
5896
  handle: string,
4550
5897
  heardBefore: string | null,
4551
5898
  log: string,
4552
- ): Promise<void> {
5899
+ ): Promise<boolean> {
4553
5900
  for (let tries = 0; tries < RUNNER_HEARD_TRIES; tries += 1) {
4554
5901
  await io.sleep(RUNNER_HEARD_PAUSE_MS);
4555
5902
  const found = await client.agent(handle).catch(() => undefined);
@@ -4557,14 +5904,59 @@ async function awaitRunner(
4557
5904
  const said = found?.runner?.machine ?? null;
4558
5905
  if (heard !== null && heard !== heardBefore && said !== null) {
4559
5906
  io.stdout(
4560
- `The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine, and its page shows it.\n`,
5907
+ `The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine.\n`,
4561
5908
  );
4562
- return;
5909
+ return true;
4563
5910
  }
4564
5911
  }
4565
5912
  io.stdout(
4566
- `The runner is not heard from yet. Its own lines are in ${log}; the account's page says when it is.\n`,
5913
+ `The runner is not heard from yet. Its own lines are in ${log}: read them, since they say what it lacks; the account's page says when it is heard from.\n`,
4567
5914
  );
5915
+ return false;
5916
+ }
5917
+
5918
+ /** How often, and how many times, a setup looks whether the agent's first session has begun. */
5919
+ const FIRST_SESSION_PAUSE_MS = 2000;
5920
+ const FIRST_SESSION_TRIES = 30;
5921
+
5922
+ /**
5923
+ * What a setup ends with (ADR-0140): whether the agent's first session has begun, where to
5924
+ * watch it, and that the machine's part ends here, since everything after is the agent's own.
5925
+ */
5926
+ async function handOver(
5927
+ io: CliIo,
5928
+ machine: SetupMachine,
5929
+ client: ConsoleClient,
5930
+ url: string,
5931
+ handle: string,
5932
+ /** Where the runner's own lines are. */
5933
+ log: string,
5934
+ ): Promise<void> {
5935
+ let began = false;
5936
+ for (let tries = 0; tries < FIRST_SESSION_TRIES && !began; tries += 1) {
5937
+ const found = await client.agent(handle).catch(() => undefined);
5938
+ began = (found?.runner?.session ?? null) !== null;
5939
+ if (!began) {
5940
+ await io.sleep(FIRST_SESSION_PAUSE_MS);
5941
+ }
5942
+ }
5943
+ const plate = await client.work().catch(() => undefined);
5944
+ const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
5945
+ const lines = [
5946
+ began
5947
+ ? `@${handle}'s session has begun: the agent is at work.`
5948
+ : `No session has begun yet: one begins when something wakes @${handle}.`,
5949
+ `Watch it: ${url}${agentHref(handle)}`,
5950
+ ...(first === undefined
5951
+ ? []
5952
+ : [
5953
+ `Its first task: #${first.task.number} "${first.task.title}" in ${first.project.key}, ${url}${taskHref(first.project.key, first.task.number)}`,
5954
+ ]),
5955
+ `That is the machine prepared: stop here. What comes next, its sign-ins, its tokens, its desk's repository, its profile and its messenger, is @${handle}'s own, done in its own session: do none of it for it.`,
5956
+ `What you change on this machine afterwards, say to it: console agent wake me "<what changed>"`,
5957
+ awakeWords(machine.platform, await heldAwake(machine), log),
5958
+ ];
5959
+ io.stdout(`${lines.join("\n")}\n`);
4568
5960
  }
4569
5961
 
4570
5962
  // Derives a machine again (ADR-0088): by the account's own command, in its desk, when the
@@ -4659,13 +6051,33 @@ const agentSetup = async (args: readonly string[], io: CliIo): Promise<number> =
4659
6051
  io.stdout(
4660
6052
  `\nSetting this machine up for @${handle}, in the OS account ${machine.user}${io.hostname === undefined ? "" : ` on ${io.hostname}`}.\n`,
4661
6053
  );
6054
+ // The machine first (ADR-0140): everything that is missing is said at once, before anyone is
6055
+ // asked to sign in, and nothing is set up on a machine the runner could not work on.
6056
+ const driver = text(values, "driver");
6057
+ if (
6058
+ driver !== undefined &&
6059
+ ownRunnerModules({ user: machine.user }).drivers.get(driver) === undefined
6060
+ ) {
6061
+ throw misuse(
6062
+ `Not a driver this command has: ${driver}. It has: ${ownRunnerModules({ user: machine.user }).drivers.names().join(", ")}.`,
6063
+ );
6064
+ }
6065
+ const look = await lookAtMachine(machine, { driver, browser: !on(values, "no-browser") });
6066
+ if (look.missing.length > 0) {
6067
+ throw failed(
6068
+ `This machine lacks what the setup needs. Install each yourself, without asking, and run the line again:\n${look.missing.map((line) => `- ${line}`).join("\n")}`,
6069
+ );
6070
+ }
6071
+ io.stdout(
6072
+ `The machine has what the setup needs: git${look.product === undefined ? "" : `, ${look.product}`}${look.browser === undefined ? "" : ", Google Chrome"}.\n${look.notes.map((line) => `${line}\n`).join("")}`,
6073
+ );
4662
6074
  const client = await signInAsAccount(io, machine, url, setup);
4663
6075
  const me = await client.me();
4664
6076
  if (me.person === null) {
4665
6077
  throw failed("The console does not know this sign-in any more. Run the line again.");
4666
6078
  }
4667
6079
  const heardBefore = (await client.agent(handle).catch(() => undefined))?.state?.heardAt ?? null;
4668
- const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values);
6080
+ const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values, look);
4669
6081
  if (on(values, "no-service")) {
4670
6082
  io.stdout(
4671
6083
  `No service is written, as asked. Start the runner yourself and keep it running: ${runnerByHand(desk, url, me.person.login, machine.platform)}\n`,
@@ -4673,9 +6085,219 @@ const agentSetup = async (args: readonly string[], io: CliIo): Promise<number> =
4673
6085
  return EXIT.ok;
4674
6086
  }
4675
6087
  const log = await settleService(io, machine, desk, url, me.person.login, "load");
4676
- if (log !== undefined) {
4677
- await awaitRunner(io, client, handle, heardBefore, log);
6088
+ if (log !== undefined && (await awaitRunner(io, client, handle, heardBefore, log))) {
6089
+ await handOver(io, machine, client, url, handle, log);
6090
+ }
6091
+ return EXIT.ok;
6092
+ };
6093
+
6094
+ const DESK_USAGE = "Say at most one directory: console desk [<directory>] [--web]";
6095
+
6096
+ /**
6097
+ * What is next in a new desk, in order, as a person says it to their agent there (ADR-0115,
6098
+ * ADR-0122): first the desk is set up as a repository, by the skill for that in the
6099
+ * organization's pack; then the person is asked what they want to keep and to see, and the
6100
+ * desk is shaped to it, by the skill the command ships, named with its place.
6101
+ */
6102
+ function deskNext(web: boolean, skillsDir: string | undefined): [string, string] {
6103
+ return [
6104
+ `Set this desk up as a repository of mine${web ? " and bring its pages up" : ""}, with the skill for it in the organization's pack where it has one: console skills --search "desk setup" --limit 5`,
6105
+ `Ask me what I want to keep and to see here, and shape the desk to it, as the skill keeping-a-desk says, shipped with the console command${skillsDir === undefined ? " (console skills says where it is)" : `: ${ownSkillPath(skillsDir, "keeping-a-desk")}`}`,
6106
+ ];
6107
+ }
6108
+
6109
+ /** The files of the shell of a desk's pages as they are written: the two words the template leaves filled in. */
6110
+ function deskWebFiles(
6111
+ template: ReadonlyMap<string, string>,
6112
+ version: string,
6113
+ title: string,
6114
+ ): [string, string][] {
6115
+ return [...template]
6116
+ .filter(([path]) => !path.split("/").some((part) => part === ".." || part.length === 0))
6117
+ .map(([path, body]) => [
6118
+ path,
6119
+ body.replaceAll("__VERSION__", version).replaceAll("__TITLE__", title),
6120
+ ]);
6121
+ }
6122
+
6123
+ /** A count with its word, the word in the plural where the count is not one. */
6124
+ const counted = (count: number, one: string, many = `${one}s`): string =>
6125
+ `${count} ${count === 1 ? one : many}`;
6126
+
6127
+ // The check of a desk's records (ADR-0117): every file under `records/` read as the format's
6128
+ // schemas read it, and each problem said with its file. It asks nothing of the console and
6129
+ // needs no sign-in: an agent that wrote a record runs it before it commits, and nobody needs
6130
+ // a page to know that the records are right.
6131
+ const deskCheck = async (args: readonly string[], io: CliIo): Promise<number> => {
6132
+ const { values, positionals } = parse(args, {});
6133
+ if (positionals.length > 1) {
6134
+ throw misuse("Say at most one directory: console desk check [<directory>]");
6135
+ }
6136
+ const at = io.recordsAt?.(positionals[0] ?? ".");
6137
+ if (at === undefined) {
6138
+ throw failed("A desk's records cannot be read from here.");
6139
+ }
6140
+ const found = await checkRecords(at.files);
6141
+ if (on(values, "json")) {
6142
+ io.stdout(`${JSON.stringify({ directory: at.directory, ...found }, null, 2)}\n`);
6143
+ } else if (!found.found) {
6144
+ io.stdout(
6145
+ `No collection is kept in ${at.directory}: ${RECORDS_DIR}/${RECORDS_INDEX_FILE} is not there. What else is under ${RECORDS_DIR}/ is the desk's own shape, and not this check's to read. Where a collection is wanted, the skill keeping-a-desk says how one is kept (collections.md).\n`,
6146
+ );
6147
+ } else {
6148
+ const kept = found.collections.map(
6149
+ (one) =>
6150
+ ` ${one.key}: ${counted(one.items, "item")}, ${counted(one.uses, "use")}, ${counted(one.metricRows, "row of figures", "rows of figures")}`,
6151
+ );
6152
+ io.stdout(
6153
+ [
6154
+ ...found.problems.map((one) => `${one.file}: ${one.problem}`),
6155
+ ...found.notes.map((one) => `note: ${one.file}: ${one.problem}`),
6156
+ ...(found.problems.length === 0
6157
+ ? [
6158
+ `The records in ${at.directory} read right: ${counted(found.collections.length, "collection")}.`,
6159
+ ]
6160
+ : found.collections.length === 0
6161
+ ? []
6162
+ : ["What reads:"]),
6163
+ ...kept,
6164
+ "",
6165
+ ].join("\n"),
6166
+ );
6167
+ }
6168
+ if (found.problems.length > 0) {
6169
+ throw failed(
6170
+ `${counted(found.problems.length, "problem")} in the records of ${at.directory}. Mend the files and run this again.`,
6171
+ );
6172
+ }
6173
+ return EXIT.ok;
6174
+ };
6175
+
6176
+ // A person's desk (ADR-0115): its files, the least (ADR-0122), each only where no file of that
6177
+ // name is there, in `desk` here, as an agent account's is called, or the directory named; with
6178
+ // --web, the shell of the desk's pages in `web/`, where that holds nothing yet. The command
6179
+ // writes and stops, and its last lines say what is next, in order, for an agent to go on with:
6180
+ // making the desk a repository is a skill's, of the organization's pack, and shaping it to what
6181
+ // the person asks to keep and to see is the skill keeping-a-desk's, which the command ships.
6182
+ // An agent account's desk is setup's: for one, the command writes the shell alone, with --web,
6183
+ // into the desk it names.
6184
+ const desk: Command = async (args, io) => {
6185
+ if (args[0] === "check") {
6186
+ return deskCheck(args.slice(1), io);
6187
+ }
6188
+ const { values, positionals } = parse(args, { web: { type: "boolean" } });
6189
+ if (positionals.length > 1) {
6190
+ throw misuse(DESK_USAGE);
6191
+ }
6192
+ const session = await open(io, values);
6193
+ const me = await session.client.me();
6194
+ const person = me.person;
6195
+ if (person === null) {
6196
+ throw failed("The console does not know this token. Sign in again: console login");
6197
+ }
6198
+ // An agent account's desk is setup's, and none of its own files is written here (ADR-0115).
6199
+ // The shell of its pages is the one thing this command writes for it, into the desk it names
6200
+ // (ADR-0122): a desk's pages are its member's, whichever kind of member that is.
6201
+ const ofAgent = person.kind === "agent";
6202
+ if (ofAgent && !on(values, "web")) {
6203
+ throw failed(
6204
+ `${whoOf(person)} is an agent account: its desk is settled by console agent setup, on its own machine, and nothing is written here. In that desk, console agent setup --refresh derives it again, and console desk . --web writes the shell of its pages.`,
6205
+ );
6206
+ }
6207
+ const machine = io.machine;
6208
+ if (machine === undefined) {
6209
+ throw failed("A desk cannot be written from here.");
6210
+ }
6211
+ const [named] = positionals;
6212
+ // A desk made under a directory that works in a project would work in it too, and every
6213
+ // checkout under its work/ with it: what the folder above says, a desk must not inherit.
6214
+ const above = named === undefined || !isAbsolute(named) ? await io.directory.load() : undefined;
6215
+ if (above !== undefined) {
6216
+ throw failed(
6217
+ `This directory works in the project ${above.project} (${DIRECTORY_FILE} here or in a directory above), and a desk made inside it would work there too. A desk is bound to no project: make it elsewhere, console desk <directory>.`,
6218
+ );
6219
+ }
6220
+ const dir = machine.path(named ?? DESK_FOLDER);
6221
+ if (ofAgent && !(await machine.exists(machine.path(dir, "AGENTS.md")))) {
6222
+ throw failed(
6223
+ `${dir} holds no AGENTS.md, so it is no desk, and nothing is written. An agent account's desk is settled by console agent setup; in it: console desk . --web`,
6224
+ );
6225
+ }
6226
+ const input = {
6227
+ person: { name: person.name ?? person.login, login: person.login },
6228
+ console: { url: session.url, workspace: me.workspace.name },
6229
+ // The language to write to them in (A-F6): theirs, else the workspace's, else none is said.
6230
+ language: readingLanguage(me) ?? undefined,
6231
+ };
6232
+ // The shell of the pages is settled before anything is written, so that a command that cannot
6233
+ // write it writes nothing.
6234
+ const webDir = machine.path(dir, "web");
6235
+ const webKept = on(values, "web") && (await machine.holds(webDir));
6236
+ let shell: [string, string][] | undefined;
6237
+ if (on(values, "web") && !webKept) {
6238
+ const template = await io.deskWebTemplate?.();
6239
+ if (template === undefined || template.size === 0) {
6240
+ throw failed(
6241
+ `This command's package carries no shell of a desk's pages (template/desk-web): nothing is written.${ofAgent ? "" : " Without --web, the desk alone is written."}`,
6242
+ );
6243
+ }
6244
+ if (io.version === undefined) {
6245
+ throw failed(
6246
+ `This command does not know its version, so it cannot say which package the desk's pages are built on: nothing is written.${ofAgent ? "" : " Without --web, the desk alone is written."}`,
6247
+ );
6248
+ }
6249
+ shell = deskWebFiles(template, io.version, deskWebTitleOf(input.person));
6250
+ }
6251
+ const written: string[] = [];
6252
+ const kept: string[] = [];
6253
+ for (const [path, body] of ofAgent ? [] : personDeskFiles(input)) {
6254
+ const file = machine.path(dir, path);
6255
+ if (await machine.exists(file)) {
6256
+ kept.push(path);
6257
+ } else {
6258
+ await machine.write(file, body, 0o644);
6259
+ written.push(path);
6260
+ }
4678
6261
  }
6262
+ const lines = ofAgent
6263
+ ? []
6264
+ : [
6265
+ written.length === 0
6266
+ ? `The desk at ${dir} is there already, and is left as it is.`
6267
+ : kept.length === 0
6268
+ ? `A new desk is written at ${dir} (${written.join(", ")}), for ${person.login}. It is yours from now on: to edit, and to make a repository of.`
6269
+ : `The desk at ${dir} gains ${written.join(", ")}; ${kept.join(", ")} ${kept.length === 1 ? "was there and is left as it is" : "were there and are left as they are"}.`,
6270
+ ];
6271
+ const shellNames = (shell ?? []).map(([path]) => path);
6272
+ for (const [path, body] of shell ?? []) {
6273
+ await machine.write(machine.path(webDir, ...path.split("/")), body, 0o644);
6274
+ }
6275
+ if (shell !== undefined) {
6276
+ lines.push(
6277
+ `The shell of its pages is written in ${webDir} (${shellNames.join(", ")}), on @skillcdn/console ${io.version}: one empty page of your own until you say what you want to see, served from this machine by console serve once it is built${shellNames.includes("README.md") ? "; its README.md says how" : ""}.`,
6278
+ );
6279
+ } else if (webKept) {
6280
+ lines.push(`${webDir} holds something already, and is left as it is.`);
6281
+ }
6282
+ const web = on(values, "web")
6283
+ ? { directory: webDir, written: shellNames, version: shell === undefined ? null : io.version }
6284
+ : null;
6285
+ // An agent account that asked for the shell is shaping its desk already: nothing is next.
6286
+ // So is a person who asked for the shell in a desk that was there: the two lines printed
6287
+ // again sent a fresh agent back to the repository's setup in the middle of building a page.
6288
+ const shaping = ofAgent || (web !== null && written.length === 0);
6289
+ const next: string[] = shaping ? [] : deskNext(web !== null, io.skillsDir);
6290
+ answer(io, session, { directory: dir, written, kept, web, next }, () =>
6291
+ (next.length === 0
6292
+ ? lines
6293
+ : [
6294
+ ...lines,
6295
+ "Next, in that folder, say these to your agent in order; an agent that ran this command goes on with them there:",
6296
+ "",
6297
+ ...next.map((line, index) => `${index + 1}. ${line}`),
6298
+ ]
6299
+ ).join("\n"),
6300
+ );
4679
6301
  return EXIT.ok;
4680
6302
  };
4681
6303
 
@@ -5103,8 +6725,25 @@ const PROJECT_FIELDS: OptionSpec = {
5103
6725
  skills: { type: "string" },
5104
6726
  color: { type: "string" },
5105
6727
  symbol: { type: "string" },
6728
+ glyph: { type: "string" },
5106
6729
  };
5107
6730
 
6731
+ /** An icon of the pack as a flag names it, `null` for `none`; a name that is none of the pack's is answered with the pack's names. */
6732
+ function glyphOrNoneOf(value: string | undefined): IconName | null | undefined {
6733
+ if (value === undefined) {
6734
+ return undefined;
6735
+ }
6736
+ if (value === "none") {
6737
+ return null;
6738
+ }
6739
+ if (!isIconName(value)) {
6740
+ throw misuse(
6741
+ `No icon of the pack is called ${value}. The pack's icons: ${ICON_NAMES.join(", ")}; none takes the icon away.`,
6742
+ );
6743
+ }
6744
+ return value;
6745
+ }
6746
+
5108
6747
  /** What the flags say of a project; `none` clears what may be cleared. */
5109
6748
  async function projectFieldsOf(io: CliIo, values: Values) {
5110
6749
  const description = await bodyOf(io, values, text(values, "description"));
@@ -5112,6 +6751,7 @@ async function projectFieldsOf(io: CliIo, values: Values) {
5112
6751
  const skills = orNone(text(values, "skills"));
5113
6752
  const color = colorOrNoneOf(text(values, "color"));
5114
6753
  const symbol = orNone(text(values, "symbol"));
6754
+ const glyph = glyphOrNoneOf(text(values, "glyph"));
5115
6755
  return {
5116
6756
  ...(description === undefined
5117
6757
  ? {}
@@ -5120,6 +6760,7 @@ async function projectFieldsOf(io: CliIo, values: Values) {
5120
6760
  ...(skills === undefined ? {} : { skillsAddress: skills }),
5121
6761
  ...(color === undefined ? {} : { color }),
5122
6762
  ...(symbol === undefined ? {} : { symbol }),
6763
+ ...(glyph === undefined ? {} : { glyph }),
5123
6764
  };
5124
6765
  }
5125
6766
 
@@ -5152,7 +6793,7 @@ const editProject: Command = async (args, io) => {
5152
6793
  const patch = { ...(name === undefined ? {} : { name }), ...(await projectFieldsOf(io, values)) };
5153
6794
  if (Object.keys(patch).length === 0) {
5154
6795
  throw misuse(
5155
- "Say what to change: --name, --description, --visibility, --skills, --color or --symbol; none clears the description, the skills address, the colour or the symbol.",
6796
+ "Say what to change: --name, --description, --visibility, --skills, --color, --symbol or --glyph; none clears the description, the skills address, the colour, the symbol or the icon.",
5156
6797
  );
5157
6798
  }
5158
6799
  const session = await open(io, values);
@@ -5488,6 +7129,7 @@ const COMMANDS: Readonly<Record<string, Command>> = {
5488
7129
  whoami,
5489
7130
  serve,
5490
7131
  runner,
7132
+ desk,
5491
7133
  projects,
5492
7134
  use,
5493
7135
  work,
@@ -5542,7 +7184,7 @@ function help(io: CliIo, name: string | undefined): number {
5542
7184
  io.stdout(usage(io.version, io.skillsDir));
5543
7185
  return EXIT.ok;
5544
7186
  }
5545
- const found = helpFor(name);
7187
+ const found = helpFor(name, io.skillsDir);
5546
7188
  if (found === undefined) {
5547
7189
  throw misuse(`Not a command: ${name}. The commands: ${Object.keys(COMMAND_HELP).join(", ")}`);
5548
7190
  }
@@ -5788,6 +7430,10 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<number
5788
7430
  io.stderr(`${error.message}\n`);
5789
7431
  return error.exit;
5790
7432
  }
7433
+ if (error instanceof UnseenProject) {
7434
+ io.stderr(`${error.words}\n`);
7435
+ return EXIT.failed;
7436
+ }
5791
7437
  if (error instanceof ApiError) {
5792
7438
  io.stderr(`${error.code}: ${error.message}\n${hintFor(error, io, seen)}`);
5793
7439
  return error.code === "client.outdated" ||