@skillcdn/console 0.4.7 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (599) hide show
  1. package/README.md +74 -14
  2. package/SKILLCDN.md +5 -3
  3. package/dist/agent-page.d.ts +44 -0
  4. package/dist/agent-page.d.ts.map +1 -0
  5. package/dist/agent-page.js +415 -0
  6. package/dist/agent-page.js.map +1 -0
  7. package/dist/agent-stream.d.ts +52 -0
  8. package/dist/agent-stream.d.ts.map +1 -0
  9. package/dist/agent-stream.js +155 -0
  10. package/dist/agent-stream.js.map +1 -0
  11. package/dist/api.d.ts +12 -6
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +11 -5
  14. package/dist/api.js.map +1 -1
  15. package/dist/avatar.d.ts +137 -0
  16. package/dist/avatar.d.ts.map +1 -0
  17. package/dist/avatar.js +1216 -0
  18. package/dist/avatar.js.map +1 -0
  19. package/dist/charts.d.ts +103 -0
  20. package/dist/charts.d.ts.map +1 -0
  21. package/dist/charts.js +182 -0
  22. package/dist/charts.js.map +1 -0
  23. package/dist/cli/cli.d.ts +39 -1
  24. package/dist/cli/cli.d.ts.map +1 -1
  25. package/dist/cli/cli.js +2424 -296
  26. package/dist/cli/cli.js.map +1 -1
  27. package/dist/cli/command-words.d.ts +20 -0
  28. package/dist/cli/command-words.d.ts.map +1 -0
  29. package/dist/cli/command-words.js +51 -0
  30. package/dist/cli/command-words.js.map +1 -0
  31. package/dist/cli/credentials.d.ts +59 -5
  32. package/dist/cli/credentials.d.ts.map +1 -1
  33. package/dist/cli/credentials.js +128 -16
  34. package/dist/cli/credentials.js.map +1 -1
  35. package/dist/cli/directory.d.ts +19 -4
  36. package/dist/cli/directory.d.ts.map +1 -1
  37. package/dist/cli/directory.js +16 -8
  38. package/dist/cli/directory.js.map +1 -1
  39. package/dist/cli/format.d.ts +91 -8
  40. package/dist/cli/format.d.ts.map +1 -1
  41. package/dist/cli/format.js +386 -57
  42. package/dist/cli/format.js.map +1 -1
  43. package/dist/cli/help.d.ts +13 -4
  44. package/dist/cli/help.d.ts.map +1 -1
  45. package/dist/cli/help.js +202 -62
  46. package/dist/cli/help.js.map +1 -1
  47. package/dist/cli/main.js +94 -0
  48. package/dist/cli/main.js.map +1 -1
  49. package/dist/cli/pack.d.ts +69 -36
  50. package/dist/cli/pack.d.ts.map +1 -1
  51. package/dist/cli/pack.js +241 -188
  52. package/dist/cli/pack.js.map +1 -1
  53. package/dist/cli/plugin-check.d.ts +42 -0
  54. package/dist/cli/plugin-check.d.ts.map +1 -1
  55. package/dist/cli/plugin-check.js +221 -36
  56. package/dist/cli/plugin-check.js.map +1 -1
  57. package/dist/cli/plugin-cli.d.ts +6 -1
  58. package/dist/cli/plugin-cli.d.ts.map +1 -1
  59. package/dist/cli/plugin-cli.js +21 -4
  60. package/dist/cli/plugin-cli.js.map +1 -1
  61. package/dist/cli/plugin-main.js +1 -0
  62. package/dist/cli/plugin-main.js.map +1 -1
  63. package/dist/cli/runner-host.d.ts +36 -0
  64. package/dist/cli/runner-host.d.ts.map +1 -0
  65. package/dist/cli/runner-host.js +154 -0
  66. package/dist/cli/runner-host.js.map +1 -0
  67. package/dist/cli/serve.d.ts +33 -1
  68. package/dist/cli/serve.d.ts.map +1 -1
  69. package/dist/cli/serve.js +275 -6
  70. package/dist/cli/serve.js.map +1 -1
  71. package/dist/cli/setup-machine.d.ts +36 -0
  72. package/dist/cli/setup-machine.d.ts.map +1 -0
  73. package/dist/cli/setup-machine.js +109 -0
  74. package/dist/cli/setup-machine.js.map +1 -0
  75. package/dist/client.d.ts +189 -10
  76. package/dist/client.d.ts.map +1 -1
  77. package/dist/client.js +192 -57
  78. package/dist/client.js.map +1 -1
  79. package/dist/compat.d.ts +1 -1
  80. package/dist/compat.js +2 -2
  81. package/dist/components/agent-page.d.ts +384 -0
  82. package/dist/components/agent-page.d.ts.map +1 -0
  83. package/dist/components/agent-page.js +985 -0
  84. package/dist/components/agent-page.js.map +1 -0
  85. package/dist/components/agents.d.ts +102 -0
  86. package/dist/components/agents.d.ts.map +1 -0
  87. package/dist/components/agents.js +246 -0
  88. package/dist/components/agents.js.map +1 -0
  89. package/dist/components/calendar.d.ts +17 -17
  90. package/dist/components/calendar.d.ts.map +1 -1
  91. package/dist/components/calendar.js +7 -2
  92. package/dist/components/calendar.js.map +1 -1
  93. package/dist/components/charts.d.ts +157 -0
  94. package/dist/components/charts.d.ts.map +1 -0
  95. package/dist/components/charts.js +182 -0
  96. package/dist/components/charts.js.map +1 -0
  97. package/dist/components/comments.d.ts +2 -0
  98. package/dist/components/comments.d.ts.map +1 -1
  99. package/dist/components/comments.js +1 -1
  100. package/dist/components/comments.js.map +1 -1
  101. package/dist/components/connect.d.ts.map +1 -1
  102. package/dist/components/connect.js +7 -2
  103. package/dist/components/connect.js.map +1 -1
  104. package/dist/components/decision-form.d.ts +21 -0
  105. package/dist/components/decision-form.d.ts.map +1 -1
  106. package/dist/components/decision-form.js +20 -6
  107. package/dist/components/decision-form.js.map +1 -1
  108. package/dist/components/decision-list.d.ts +24 -0
  109. package/dist/components/decision-list.d.ts.map +1 -1
  110. package/dist/components/decision-list.js +54 -5
  111. package/dist/components/decision-list.js.map +1 -1
  112. package/dist/components/desk-records.d.ts +102 -0
  113. package/dist/components/desk-records.d.ts.map +1 -0
  114. package/dist/components/desk-records.js +221 -0
  115. package/dist/components/desk-records.js.map +1 -0
  116. package/dist/components/desk.d.ts +85 -0
  117. package/dist/components/desk.d.ts.map +1 -0
  118. package/dist/components/desk.js +135 -0
  119. package/dist/components/desk.js.map +1 -0
  120. package/dist/components/event-feed.d.ts.map +1 -1
  121. package/dist/components/event-feed.js +26 -1
  122. package/dist/components/event-feed.js.map +1 -1
  123. package/dist/components/home.d.ts +12 -1
  124. package/dist/components/home.d.ts.map +1 -1
  125. package/dist/components/home.js +175 -16
  126. package/dist/components/home.js.map +1 -1
  127. package/dist/components/my-decisions.d.ts +5 -0
  128. package/dist/components/my-decisions.d.ts.map +1 -1
  129. package/dist/components/my-decisions.js +3 -3
  130. package/dist/components/my-decisions.js.map +1 -1
  131. package/dist/components/people.d.ts +17 -0
  132. package/dist/components/people.d.ts.map +1 -1
  133. package/dist/components/people.js +55 -19
  134. package/dist/components/people.js.map +1 -1
  135. package/dist/components/picker.d.ts +2 -0
  136. package/dist/components/picker.d.ts.map +1 -1
  137. package/dist/components/picker.js +1 -1
  138. package/dist/components/picker.js.map +1 -1
  139. package/dist/components/pictures.d.ts +38 -10
  140. package/dist/components/pictures.d.ts.map +1 -1
  141. package/dist/components/pictures.js +195 -40
  142. package/dist/components/pictures.js.map +1 -1
  143. package/dist/components/plugin-events.d.ts +29 -0
  144. package/dist/components/plugin-events.d.ts.map +1 -0
  145. package/dist/components/plugin-events.js +139 -0
  146. package/dist/components/plugin-events.js.map +1 -0
  147. package/dist/components/plugin-frame.d.ts.map +1 -1
  148. package/dist/components/plugin-frame.js +14 -37
  149. package/dist/components/plugin-frame.js.map +1 -1
  150. package/dist/components/plugin-settings.d.ts.map +1 -1
  151. package/dist/components/plugin-settings.js +58 -7
  152. package/dist/components/plugin-settings.js.map +1 -1
  153. package/dist/components/projects.d.ts.map +1 -1
  154. package/dist/components/projects.js +30 -10
  155. package/dist/components/projects.js.map +1 -1
  156. package/dist/components/rules.d.ts +8 -10
  157. package/dist/components/rules.d.ts.map +1 -1
  158. package/dist/components/rules.js +36 -14
  159. package/dist/components/rules.js.map +1 -1
  160. package/dist/components/sessions.d.ts.map +1 -1
  161. package/dist/components/sessions.js +8 -4
  162. package/dist/components/sessions.js.map +1 -1
  163. package/dist/components/setup.d.ts +59 -0
  164. package/dist/components/setup.d.ts.map +1 -0
  165. package/dist/components/setup.js +93 -0
  166. package/dist/components/setup.js.map +1 -0
  167. package/dist/components/sign-in.js +1 -1
  168. package/dist/components/sign-in.js.map +1 -1
  169. package/dist/components/task-form.d.ts.map +1 -1
  170. package/dist/components/task-form.js +2 -2
  171. package/dist/components/task-form.js.map +1 -1
  172. package/dist/components/task-list.d.ts +7 -6
  173. package/dist/components/task-list.d.ts.map +1 -1
  174. package/dist/components/task-list.js.map +1 -1
  175. package/dist/components/task-view.d.ts +3 -0
  176. package/dist/components/task-view.d.ts.map +1 -1
  177. package/dist/components/task-view.js +1 -1
  178. package/dist/components/task-view.js.map +1 -1
  179. package/dist/components/ui.d.ts +78 -8
  180. package/dist/components/ui.d.ts.map +1 -1
  181. package/dist/components/ui.js +88 -9
  182. package/dist/components/ui.js.map +1 -1
  183. package/dist/components/work.d.ts +5 -5
  184. package/dist/components/work.d.ts.map +1 -1
  185. package/dist/components/work.js.map +1 -1
  186. package/dist/components/workspace.d.ts +17 -0
  187. package/dist/components/workspace.d.ts.map +1 -1
  188. package/dist/components/workspace.js +129 -2
  189. package/dist/components/workspace.js.map +1 -1
  190. package/dist/connect-page.d.ts.map +1 -1
  191. package/dist/connect-page.js +5 -2
  192. package/dist/connect-page.js.map +1 -1
  193. package/dist/console.css +7551 -4580
  194. package/dist/console.d.ts +20 -0
  195. package/dist/console.d.ts.map +1 -1
  196. package/dist/console.js +331 -57
  197. package/dist/console.js.map +1 -1
  198. package/dist/data.d.ts +22 -1
  199. package/dist/data.d.ts.map +1 -1
  200. package/dist/data.js +62 -34
  201. package/dist/data.js.map +1 -1
  202. package/dist/desk-page.d.ts +38 -0
  203. package/dist/desk-page.d.ts.map +1 -0
  204. package/dist/desk-page.js +184 -0
  205. package/dist/desk-page.js.map +1 -0
  206. package/dist/desk-records-page.d.ts +18 -0
  207. package/dist/desk-records-page.d.ts.map +1 -0
  208. package/dist/desk-records-page.js +130 -0
  209. package/dist/desk-records-page.js.map +1 -0
  210. package/dist/desk-records.d.ts +247 -0
  211. package/dist/desk-records.d.ts.map +1 -0
  212. package/dist/desk-records.js +543 -0
  213. package/dist/desk-records.js.map +1 -0
  214. package/dist/desk.d.ts +122 -0
  215. package/dist/desk.d.ts.map +1 -0
  216. package/dist/desk.js +211 -0
  217. package/dist/desk.js.map +1 -0
  218. package/dist/feed-stream.d.ts +39 -0
  219. package/dist/feed-stream.d.ts.map +1 -0
  220. package/dist/feed-stream.js +117 -0
  221. package/dist/feed-stream.js.map +1 -0
  222. package/dist/glances.d.ts +39 -0
  223. package/dist/glances.d.ts.map +1 -0
  224. package/dist/glances.js +94 -0
  225. package/dist/glances.js.map +1 -0
  226. package/dist/home-tiles.d.ts +69 -5
  227. package/dist/home-tiles.d.ts.map +1 -1
  228. package/dist/home-tiles.js +347 -9
  229. package/dist/home-tiles.js.map +1 -1
  230. package/dist/i18n/en.d.ts +773 -3
  231. package/dist/i18n/en.d.ts.map +1 -1
  232. package/dist/i18n/en.js +770 -9
  233. package/dist/i18n/en.js.map +1 -1
  234. package/dist/i18n/ko.d.ts.map +1 -1
  235. package/dist/i18n/ko.js +736 -9
  236. package/dist/i18n/ko.js.map +1 -1
  237. package/dist/index.d.ts +19 -7
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +17 -5
  240. package/dist/index.js.map +1 -1
  241. package/dist/limits.d.ts +67 -0
  242. package/dist/limits.d.ts.map +1 -1
  243. package/dist/limits.js +67 -0
  244. package/dist/limits.js.map +1 -1
  245. package/dist/onboarding.d.ts +21 -0
  246. package/dist/onboarding.d.ts.map +1 -0
  247. package/dist/onboarding.js +43 -0
  248. package/dist/onboarding.js.map +1 -0
  249. package/dist/persona.d.ts +34 -0
  250. package/dist/persona.d.ts.map +1 -0
  251. package/dist/persona.js +71 -0
  252. package/dist/persona.js.map +1 -0
  253. package/dist/plugin/context.d.ts +42 -11
  254. package/dist/plugin/context.d.ts.map +1 -1
  255. package/dist/plugin/limits.d.ts +2 -0
  256. package/dist/plugin/limits.d.ts.map +1 -1
  257. package/dist/plugin/limits.js +2 -0
  258. package/dist/plugin/limits.js.map +1 -1
  259. package/dist/plugin/manifest.d.ts +13 -0
  260. package/dist/plugin/manifest.d.ts.map +1 -1
  261. package/dist/plugin/manifest.js +34 -4
  262. package/dist/plugin/manifest.js.map +1 -1
  263. package/dist/plugin/rest-schemas.d.ts +56 -0
  264. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  265. package/dist/plugin/rest-schemas.js +42 -0
  266. package/dist/plugin/rest-schemas.js.map +1 -1
  267. package/dist/plugin/sandbox.d.ts.map +1 -1
  268. package/dist/plugin/sandbox.js +4 -1
  269. package/dist/plugin/sandbox.js.map +1 -1
  270. package/dist/plugin/testing.d.ts +6 -2
  271. package/dist/plugin/testing.d.ts.map +1 -1
  272. package/dist/plugin/testing.js +52 -10
  273. package/dist/plugin/testing.js.map +1 -1
  274. package/dist/plugin.d.ts +1 -1
  275. package/dist/plugin.d.ts.map +1 -1
  276. package/dist/plugin.js +1 -1
  277. package/dist/plugin.js.map +1 -1
  278. package/dist/records.d.ts +283 -0
  279. package/dist/records.d.ts.map +1 -0
  280. package/dist/records.js +543 -0
  281. package/dist/records.js.map +1 -0
  282. package/dist/router.d.ts +50 -3
  283. package/dist/router.d.ts.map +1 -1
  284. package/dist/router.js +78 -7
  285. package/dist/router.js.map +1 -1
  286. package/dist/routes.d.ts +12 -2
  287. package/dist/routes.d.ts.map +1 -1
  288. package/dist/routes.js +14 -1
  289. package/dist/routes.js.map +1 -1
  290. package/dist/rules.d.ts +30 -11
  291. package/dist/rules.d.ts.map +1 -1
  292. package/dist/rules.js +99 -42
  293. package/dist/rules.js.map +1 -1
  294. package/dist/runner/acp.d.ts +20 -0
  295. package/dist/runner/acp.d.ts.map +1 -0
  296. package/dist/runner/acp.js +1132 -0
  297. package/dist/runner/acp.js.map +1 -0
  298. package/dist/runner/claude.d.ts +13 -0
  299. package/dist/runner/claude.d.ts.map +1 -0
  300. package/dist/runner/claude.js +615 -0
  301. package/dist/runner/claude.js.map +1 -0
  302. package/dist/runner/codex.d.ts +19 -0
  303. package/dist/runner/codex.d.ts.map +1 -0
  304. package/dist/runner/codex.js +597 -0
  305. package/dist/runner/codex.js.map +1 -0
  306. package/dist/runner/config.d.ts +35 -0
  307. package/dist/runner/config.d.ts.map +1 -0
  308. package/dist/runner/config.js +74 -0
  309. package/dist/runner/config.js.map +1 -0
  310. package/dist/runner/desk.d.ts +81 -0
  311. package/dist/runner/desk.d.ts.map +1 -0
  312. package/dist/runner/desk.js +303 -0
  313. package/dist/runner/desk.js.map +1 -0
  314. package/dist/runner/launchd.d.ts +7 -0
  315. package/dist/runner/launchd.d.ts.map +1 -0
  316. package/dist/runner/launchd.js +78 -0
  317. package/dist/runner/launchd.js.map +1 -0
  318. package/dist/runner/message.d.ts +66 -0
  319. package/dist/runner/message.d.ts.map +1 -0
  320. package/dist/runner/message.js +181 -0
  321. package/dist/runner/message.js.map +1 -0
  322. package/dist/runner/modules.d.ts +13 -0
  323. package/dist/runner/modules.d.ts.map +1 -0
  324. package/dist/runner/modules.js +30 -0
  325. package/dist/runner/modules.js.map +1 -0
  326. package/dist/runner/process.d.ts +7 -0
  327. package/dist/runner/process.d.ts.map +1 -0
  328. package/dist/runner/process.js +65 -0
  329. package/dist/runner/process.js.map +1 -0
  330. package/dist/runner/redact.d.ts +48 -0
  331. package/dist/runner/redact.d.ts.map +1 -0
  332. package/dist/runner/redact.js +214 -0
  333. package/dist/runner/redact.js.map +1 -0
  334. package/dist/runner/registry.d.ts +37 -0
  335. package/dist/runner/registry.d.ts.map +1 -0
  336. package/dist/runner/registry.js +26 -0
  337. package/dist/runner/registry.js.map +1 -0
  338. package/dist/runner/runner.d.ts +130 -0
  339. package/dist/runner/runner.d.ts.map +1 -0
  340. package/dist/runner/runner.js +1551 -0
  341. package/dist/runner/runner.js.map +1 -0
  342. package/dist/runner/slack.d.ts +16 -0
  343. package/dist/runner/slack.d.ts.map +1 -0
  344. package/dist/runner/slack.js +157 -0
  345. package/dist/runner/slack.js.map +1 -0
  346. package/dist/runner/systemd-user.d.ts +7 -0
  347. package/dist/runner/systemd-user.d.ts.map +1 -0
  348. package/dist/runner/systemd-user.js +93 -0
  349. package/dist/runner/systemd-user.js.map +1 -0
  350. package/dist/runner/task-scheduler.d.ts +38 -0
  351. package/dist/runner/task-scheduler.d.ts.map +1 -0
  352. package/dist/runner/task-scheduler.js +216 -0
  353. package/dist/runner/task-scheduler.js.map +1 -0
  354. package/dist/runner/types.d.ts +315 -0
  355. package/dist/runner/types.d.ts.map +1 -0
  356. package/dist/runner/types.js +24 -0
  357. package/dist/runner/types.js.map +1 -0
  358. package/dist/runner.d.ts +18 -0
  359. package/dist/runner.d.ts.map +1 -0
  360. package/dist/runner.js +20 -0
  361. package/dist/runner.js.map +1 -0
  362. package/dist/schemas.d.ts +6082 -1295
  363. package/dist/schemas.d.ts.map +1 -1
  364. package/dist/schemas.js +930 -31
  365. package/dist/schemas.js.map +1 -1
  366. package/dist/services.d.ts +110 -0
  367. package/dist/services.d.ts.map +1 -0
  368. package/dist/services.js +305 -0
  369. package/dist/services.js.map +1 -0
  370. package/dist/setup-guide.d.ts +64 -0
  371. package/dist/setup-guide.d.ts.map +1 -0
  372. package/dist/setup-guide.js +256 -0
  373. package/dist/setup-guide.js.map +1 -0
  374. package/dist/setup-page.d.ts +6 -0
  375. package/dist/setup-page.d.ts.map +1 -0
  376. package/dist/setup-page.js +29 -0
  377. package/dist/setup-page.js.map +1 -0
  378. package/dist/sse.d.ts +15 -0
  379. package/dist/sse.d.ts.map +1 -0
  380. package/dist/sse.js +73 -0
  381. package/dist/sse.js.map +1 -0
  382. package/dist/tab-title.d.ts +6 -0
  383. package/dist/tab-title.d.ts.map +1 -0
  384. package/dist/tab-title.js +22 -0
  385. package/dist/tab-title.js.map +1 -0
  386. package/dist/tokens.d.ts.map +1 -1
  387. package/dist/tokens.js +3 -0
  388. package/dist/tokens.js.map +1 -1
  389. package/dist/use-action.d.ts +5 -2
  390. package/dist/use-action.d.ts.map +1 -1
  391. package/dist/use-action.js +6 -1
  392. package/dist/use-action.js.map +1 -1
  393. package/dist/vocabulary.d.ts +84 -4
  394. package/dist/vocabulary.d.ts.map +1 -1
  395. package/dist/vocabulary.js +115 -3
  396. package/dist/vocabulary.js.map +1 -1
  397. package/docs/specs/cli.md +147 -41
  398. package/docs/specs/plugins.md +37 -27
  399. package/docs/specs/records.md +113 -0
  400. package/docs/specs/rest.md +155 -20
  401. package/docs/specs/runner.md +347 -0
  402. package/package.json +12 -3
  403. package/skills/building-a-console/SKILL.md +4 -4
  404. package/skills/building-a-console/references/configuring.md +1 -0
  405. package/skills/building-a-plugin/SKILL.md +7 -7
  406. package/skills/deploying-a-console/SKILL.md +4 -4
  407. package/skills/deploying-a-console/references/resources.md +48 -8
  408. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  409. package/skills/keeping-a-desk/SKILL.md +133 -0
  410. package/skills/keeping-a-desk/collections.md +96 -0
  411. package/skills/planning-the-board/SKILL.md +14 -18
  412. package/skills/planning-the-board/references/a-task.md +2 -2
  413. package/skills/planning-the-board/references/project-rules.md +13 -14
  414. package/skills/planning-the-board/references/setting-up.md +22 -9
  415. package/skills/running-an-agent/SKILL.md +107 -0
  416. package/skills/running-an-agent/references/slack-app.md +61 -0
  417. package/skills/working-the-board/SKILL.md +66 -39
  418. package/skills/working-the-board/references/terms.md +9 -5
  419. package/skills/working-the-board/references/the-pack.md +14 -9
  420. package/skills/working-the-board/references/the-sentence.md +2 -2
  421. package/src/agent-page.tsx +1039 -0
  422. package/src/agent-stream.ts +199 -0
  423. package/src/api.ts +317 -2
  424. package/src/avatar.ts +1506 -0
  425. package/src/charts.ts +250 -0
  426. package/src/cli/cli.ts +3210 -503
  427. package/src/cli/command-words.ts +56 -0
  428. package/src/cli/credentials.ts +188 -16
  429. package/src/cli/directory.ts +28 -10
  430. package/src/cli/format.ts +470 -67
  431. package/src/cli/help.ts +233 -61
  432. package/src/cli/main.ts +89 -0
  433. package/src/cli/pack.ts +332 -263
  434. package/src/cli/plugin-check.ts +275 -34
  435. package/src/cli/plugin-cli.ts +28 -4
  436. package/src/cli/plugin-main.ts +1 -0
  437. package/src/cli/runner-host.ts +188 -0
  438. package/src/cli/serve.ts +320 -5
  439. package/src/cli/setup-machine.ts +153 -0
  440. package/src/client.ts +711 -126
  441. package/src/compat.ts +2 -2
  442. package/src/components/agent-page.tsx +1946 -0
  443. package/src/components/agents.tsx +638 -0
  444. package/src/components/calendar.tsx +74 -53
  445. package/src/components/charts.tsx +680 -0
  446. package/src/components/comments.tsx +3 -0
  447. package/src/components/connect.tsx +37 -2
  448. package/src/components/decision-form.tsx +89 -51
  449. package/src/components/decision-list.tsx +140 -4
  450. package/src/components/desk-records.tsx +724 -0
  451. package/src/components/desk.tsx +471 -0
  452. package/src/components/event-feed.tsx +30 -1
  453. package/src/components/home.tsx +353 -12
  454. package/src/components/my-decisions.tsx +8 -2
  455. package/src/components/people.tsx +300 -203
  456. package/src/components/picker.tsx +3 -1
  457. package/src/components/pictures.tsx +256 -44
  458. package/src/components/plugin-events.ts +159 -0
  459. package/src/components/plugin-frame.tsx +14 -38
  460. package/src/components/plugin-settings.tsx +178 -22
  461. package/src/components/projects.tsx +33 -15
  462. package/src/components/rules.tsx +96 -36
  463. package/src/components/sessions.tsx +7 -4
  464. package/src/components/setup.tsx +252 -0
  465. package/src/components/sign-in.tsx +1 -1
  466. package/src/components/task-form.tsx +11 -2
  467. package/src/components/task-list.tsx +7 -6
  468. package/src/components/task-view.tsx +4 -0
  469. package/src/components/ui.tsx +169 -25
  470. package/src/components/work.tsx +9 -9
  471. package/src/components/workspace.tsx +345 -4
  472. package/src/connect-page.tsx +15 -2
  473. package/src/console.tsx +657 -83
  474. package/src/data.ts +109 -43
  475. package/src/desk-page.tsx +332 -0
  476. package/src/desk-records-page.tsx +256 -0
  477. package/src/desk-records.ts +808 -0
  478. package/src/desk.ts +329 -0
  479. package/src/feed-stream.ts +144 -0
  480. package/src/glances.ts +132 -0
  481. package/src/home-tiles.ts +411 -9
  482. package/src/i18n/en.ts +828 -10
  483. package/src/i18n/ko.ts +792 -10
  484. package/src/index.ts +172 -3
  485. package/src/limits.ts +67 -0
  486. package/src/onboarding.ts +84 -0
  487. package/src/persona.ts +100 -0
  488. package/src/plugin/context.ts +55 -12
  489. package/src/plugin/limits.ts +2 -0
  490. package/src/plugin/manifest.ts +42 -3
  491. package/src/plugin/rest-schemas.ts +46 -0
  492. package/src/plugin/sandbox.ts +4 -1
  493. package/src/plugin/testing.ts +63 -12
  494. package/src/plugin.ts +2 -0
  495. package/src/records.ts +702 -0
  496. package/src/router.ts +120 -10
  497. package/src/routes.ts +17 -1
  498. package/src/rules.ts +109 -44
  499. package/src/runner/acp.ts +1267 -0
  500. package/src/runner/claude.ts +695 -0
  501. package/src/runner/codex.ts +691 -0
  502. package/src/runner/config.ts +97 -0
  503. package/src/runner/desk.ts +377 -0
  504. package/src/runner/launchd.ts +86 -0
  505. package/src/runner/message.ts +232 -0
  506. package/src/runner/modules.ts +30 -0
  507. package/src/runner/process.ts +72 -0
  508. package/src/runner/redact.ts +242 -0
  509. package/src/runner/registry.ts +67 -0
  510. package/src/runner/runner.ts +1879 -0
  511. package/src/runner/slack.ts +180 -0
  512. package/src/runner/systemd-user.ts +103 -0
  513. package/src/runner/task-scheduler.ts +236 -0
  514. package/src/runner/types.ts +334 -0
  515. package/src/runner.ts +110 -0
  516. package/src/schemas.ts +1183 -30
  517. package/src/services.ts +424 -0
  518. package/src/setup-guide.ts +336 -0
  519. package/src/setup-page.tsx +46 -0
  520. package/src/sse.ts +84 -0
  521. package/src/styles/README.md +111 -0
  522. package/src/styles/base.css +130 -0
  523. package/src/styles/console.css +85 -7095
  524. package/src/styles/drawn-by-pages.json +256 -0
  525. package/src/styles/pages/agents.css +1195 -0
  526. package/src/styles/pages/board.css +380 -0
  527. package/src/styles/pages/calendar.css +214 -0
  528. package/src/styles/pages/connect.css +182 -0
  529. package/src/styles/pages/decisions.css +370 -0
  530. package/src/styles/pages/desk.css +126 -0
  531. package/src/styles/pages/documents.css +273 -0
  532. package/src/styles/pages/feed.css +118 -0
  533. package/src/styles/pages/home.css +718 -0
  534. package/src/styles/pages/people.css +90 -0
  535. package/src/styles/pages/plugins.css +212 -0
  536. package/src/styles/pages/roadmap.css +377 -0
  537. package/src/styles/pages/settings.css +171 -0
  538. package/src/styles/pages/shell.css +208 -0
  539. package/src/styles/pages/sign-in.css +178 -0
  540. package/src/styles/pages/task.css +108 -0
  541. package/src/styles/pages/thread.css +331 -0
  542. package/src/styles/pages/work.css +68 -0
  543. package/src/styles/parts/avatar.css +82 -0
  544. package/src/styles/parts/badge.css +227 -0
  545. package/src/styles/parts/bars.css +80 -0
  546. package/src/styles/parts/button.css +99 -0
  547. package/src/styles/parts/calendar.css +547 -0
  548. package/src/styles/parts/callout.css +41 -0
  549. package/src/styles/parts/category.css +8 -0
  550. package/src/styles/parts/chart.css +173 -0
  551. package/src/styles/parts/chip.css +90 -0
  552. package/src/styles/parts/code.css +48 -0
  553. package/src/styles/parts/count.css +27 -0
  554. package/src/styles/parts/crumbs.css +61 -0
  555. package/src/styles/parts/detail.css +110 -0
  556. package/src/styles/parts/empty.css +21 -0
  557. package/src/styles/parts/eyebrow.css +9 -0
  558. package/src/styles/parts/facts.css +147 -0
  559. package/src/styles/parts/figures.css +65 -0
  560. package/src/styles/parts/files.css +38 -0
  561. package/src/styles/parts/filters.css +42 -0
  562. package/src/styles/parts/form.css +109 -0
  563. package/src/styles/parts/frame.css +45 -0
  564. package/src/styles/parts/input.css +243 -0
  565. package/src/styles/parts/legend.css +48 -0
  566. package/src/styles/parts/links.css +37 -0
  567. package/src/styles/parts/mark.css +79 -0
  568. package/src/styles/parts/menu.css +147 -0
  569. package/src/styles/parts/page.css +174 -0
  570. package/src/styles/parts/pager.css +19 -0
  571. package/src/styles/parts/panel.css +33 -0
  572. package/src/styles/parts/person.css +257 -0
  573. package/src/styles/parts/picker.css +185 -0
  574. package/src/styles/parts/progress.css +25 -0
  575. package/src/styles/parts/prose.css +128 -0
  576. package/src/styles/parts/rows.css +63 -0
  577. package/src/styles/parts/series.css +32 -0
  578. package/src/styles/parts/settings.css +101 -0
  579. package/src/styles/parts/share.css +25 -0
  580. package/src/styles/parts/spark.css +23 -0
  581. package/src/styles/parts/spinner.css +29 -0
  582. package/src/styles/parts/stat.css +69 -0
  583. package/src/styles/parts/steps.css +68 -0
  584. package/src/styles/parts/tabs.css +175 -0
  585. package/src/styles/parts/text.css +61 -0
  586. package/src/styles/parts/toggle.css +71 -0
  587. package/src/styles/parts/workers.css +37 -0
  588. package/src/styles/tokens.css +295 -0
  589. package/src/tab-title.ts +25 -0
  590. package/src/tokens.ts +3 -0
  591. package/src/use-action.ts +7 -2
  592. package/src/vocabulary.ts +151 -3
  593. package/template/desk-web/README.md +8 -0
  594. package/template/desk-web/index.html +13 -0
  595. package/template/desk-web/package.json +25 -0
  596. package/template/desk-web/src/main.tsx +24 -0
  597. package/template/desk-web/src/page.tsx +51 -0
  598. package/template/desk-web/tsconfig.json +16 -0
  599. package/template/desk-web/vite.config.ts +15 -0
@@ -0,0 +1,188 @@
1
+ import { randomInt } from "node:crypto";
2
+ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { type as osType, release, userInfo } from "node:os";
4
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
5
+ import process from "node:process";
6
+ import { createSpawn } from "../runner/process.js";
7
+ import { KEEPER_VARIABLE, type Spawn, type WakeSocket } from "../runner/types.js";
8
+
9
+ // What `console runner` needs of the machine it runs on (ADR-0085): the desk it was started in,
10
+ // processes to start, a few files of its own there, and the word to stop. The command takes it
11
+ // as it takes everything else, so that the tests hand it one that touches nothing.
12
+
13
+ export interface RunnerHost {
14
+ /** The desk: the directory the runner was started in. */
15
+ readonly cwd: string;
16
+ readonly spawn: Spawn;
17
+ /** The operating system as it calls itself, and the OS account the runner runs in. */
18
+ readonly os: string;
19
+ readonly user: string;
20
+ /** A file under the desk, as text; nothing where there is none. */
21
+ readText(path: string): Promise<string | undefined>;
22
+ /** Writes a file under the desk for its owner alone, its folders made on the way: a text, or bytes as they are. */
23
+ writePrivate(path: string, value: string | Uint8Array): Promise<void>;
24
+ /** Removes a file under the desk; one that is not there is removed already. */
25
+ remove(path: string): Promise<void>;
26
+ /** Opens a socket for a wake source: the messages of text it carries, until it closes. */
27
+ socket(url: string): WakeSocket;
28
+ /**
29
+ * Resolves when the process is asked to stop, or when the process that keeps the runner
30
+ * running is gone, where the runner was told which that is. Asked for by the command that runs
31
+ * a runner, and by no other: listening for the word to stop is what keeps a process from
32
+ * stopping by itself.
33
+ */
34
+ untilStopped(): Promise<void>;
35
+ readonly random: () => number;
36
+ }
37
+
38
+ /** How often a runner that was told which process keeps it looks whether that one is still there. */
39
+ const KEEPER_PAUSE_MS = 2000;
40
+
41
+ /** The process a runner was told keeps it, by its number; nothing where none is named, or what is named is no number. */
42
+ function keeperOf(named: string | undefined): number | undefined {
43
+ if (named === undefined || !/^[1-9]\d{0,9}$/.test(named)) {
44
+ return undefined;
45
+ }
46
+ return Number(named);
47
+ }
48
+
49
+ /** Whether a process is still there: one that may not be asked about is. */
50
+ function alive(pid: number): boolean {
51
+ try {
52
+ process.kill(pid, 0);
53
+ return true;
54
+ } catch (error) {
55
+ return error instanceof Error && "code" in error && error.code === "EPERM";
56
+ }
57
+ }
58
+
59
+ /**
60
+ * The runner's host on this machine, in `cwd`, with `env` as what a product's process begins
61
+ * from, and where a keeper names itself (`CONSOLE_RUNNER_KEEPER`).
62
+ */
63
+ export function createRunnerHost(
64
+ cwd: string,
65
+ env: Readonly<Record<string, string | undefined>>,
66
+ options: { readonly keeperPauseMs?: number | undefined } = {},
67
+ ): RunnerHost {
68
+ /** A path under the desk, or an error: nothing the runner reads or writes is anywhere else. */
69
+ const under = (path: string): string => {
70
+ const full = resolve(cwd, path);
71
+ const away = relative(cwd, full);
72
+ if (away.length === 0 || away.startsWith("..") || isAbsolute(away)) {
73
+ throw new Error("a file of the runner's is under its desk");
74
+ }
75
+ return full;
76
+ };
77
+ let user = "";
78
+ try {
79
+ user = userInfo().username;
80
+ } catch {
81
+ user = "";
82
+ }
83
+ return {
84
+ cwd,
85
+ spawn: createSpawn(env),
86
+ os: `${osType()} ${release()}`,
87
+ user: user.length === 0 ? "unknown" : user,
88
+ async readText(path) {
89
+ try {
90
+ return await readFile(under(path), "utf8");
91
+ } catch (error) {
92
+ if (
93
+ typeof error === "object" &&
94
+ error !== null &&
95
+ "code" in error &&
96
+ error.code === "ENOENT"
97
+ ) {
98
+ return undefined;
99
+ }
100
+ throw error;
101
+ }
102
+ },
103
+ async writePrivate(path, value) {
104
+ const full = under(path);
105
+ await mkdir(dirname(full), { recursive: true });
106
+ await writeFile(full, value, { mode: 0o600 });
107
+ // A file that was there keeps the mode it had: say it again.
108
+ await chmod(full, 0o600);
109
+ },
110
+ async remove(path) {
111
+ await rm(under(path), { force: true });
112
+ },
113
+ socket(url) {
114
+ const socket = new WebSocket(url);
115
+ const waiting: string[] = [];
116
+ let closed = false;
117
+ let wake: (() => void) | undefined;
118
+ const turn = (): void => {
119
+ wake?.();
120
+ wake = undefined;
121
+ };
122
+ socket.addEventListener("message", (event) => {
123
+ if (typeof event.data === "string") {
124
+ waiting.push(event.data);
125
+ turn();
126
+ }
127
+ });
128
+ const end = (): void => {
129
+ closed = true;
130
+ turn();
131
+ };
132
+ socket.addEventListener("close", end);
133
+ socket.addEventListener("error", end);
134
+ return {
135
+ messages: (async function* () {
136
+ for (;;) {
137
+ const next = waiting.shift();
138
+ if (next !== undefined) {
139
+ yield next;
140
+ } else if (closed) {
141
+ return;
142
+ } else {
143
+ await new Promise<void>((resolve) => {
144
+ wake = resolve;
145
+ });
146
+ }
147
+ }
148
+ })(),
149
+ send(text) {
150
+ if (socket.readyState === WebSocket.OPEN) {
151
+ socket.send(text);
152
+ }
153
+ },
154
+ close() {
155
+ end();
156
+ try {
157
+ socket.close();
158
+ } catch {
159
+ // Closed already, or never opened: there is nothing to close.
160
+ }
161
+ },
162
+ };
163
+ },
164
+ untilStopped: () =>
165
+ new Promise<void>((done) => {
166
+ process.once("SIGINT", () => done());
167
+ process.once("SIGTERM", () => done());
168
+ // A system that ends what keeps the runner running may leave the runner itself: told
169
+ // which process that is, the runner looks for it, and stops when it is gone.
170
+ const keeper = keeperOf(env[KEEPER_VARIABLE]);
171
+ if (keeper !== undefined) {
172
+ const timer = setInterval(() => {
173
+ if (!alive(keeper)) {
174
+ clearInterval(timer);
175
+ done();
176
+ }
177
+ }, options.keeperPauseMs ?? KEEPER_PAUSE_MS);
178
+ timer.unref();
179
+ }
180
+ }),
181
+ // A session's mark is made of these: not to be guessed from outside the machine.
182
+ random: () => randomInt(0, 2 ** 31) / 2 ** 31,
183
+ };
184
+ }
185
+
186
+ /** Where a session's files and the runner's own are kept under the desk: ignored by its repository. */
187
+ export const WORK_DIR = "work";
188
+ export const workPath = (path: string): string => join(WORK_DIR, path);
package/src/cli/serve.ts CHANGED
@@ -1,14 +1,20 @@
1
+ import { createReadStream } from "node:fs";
2
+ import { readFile, realpath, stat } from "node:fs/promises";
1
3
  import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
4
+ import { basename, extname, join, sep } from "node:path";
2
5
  import { Readable } from "node:stream";
3
6
  import { pipeline } from "node:stream/promises";
4
7
  import type { ReadableStream as NodeReadableStream } from "node:stream/web";
5
8
  import type { FetchLike } from "../client.js";
9
+ import { isLfsPointer, MAX_LFS_POINTER_BYTES } from "../records.js";
6
10
  import type { WebRoot } from "../web.js";
7
11
 
8
12
  // A console of a person's own, served from their machine (ADR-0014): the files of a build, and
9
13
  // everything under /api/ carried to the organization's console with the token the command
10
14
  // keeps. The page and the API share one origin on the loopback, so the page needs no token and
11
15
  // the organization's console no allowance: it sees a token's requests, as it sees the command's.
16
+ // Beside them, where the command is told of one, the records of a desk under /records/
17
+ // (ADR-0117): the files a desk keeps of what its member made, for the desk's pages to show.
12
18
 
13
19
  /** Where the command listens when nothing is said: next to the api role's 11199 and the dev UI's 11198. */
14
20
  export const DEFAULT_SERVE_PORT = 11197;
@@ -26,6 +32,8 @@ export interface ServeOptions {
26
32
  readonly port: number;
27
33
  /** The build to serve, or none: then only the API is here, for a development server to send it to. */
28
34
  readonly web?: WebRoot | undefined;
35
+ /** The records of a desk to serve under `/records/`, or none: then nothing is there. */
36
+ readonly records?: RecordsRoot | undefined;
29
37
  }
30
38
 
31
39
  export type ServeHandler = (request: Request) => Promise<Response>;
@@ -44,9 +52,10 @@ const HOP_BY_HOP: ReadonlySet<string> = new Set([
44
52
  ]);
45
53
 
46
54
  /**
47
- * What of the browser's request does not go to the console: the loopback's host, anything of a
48
- * session (the token is the credential), what names the page's origin (a token's request needs
49
- * none), and the encodings the browser takes, since what comes back is passed on decoded.
55
+ * What of the browser's request does not go to the console as it came: the loopback's host,
56
+ * anything of a session (the token is the credential), what names the page (a token's request
57
+ * needs none, but for the referrer's origin, below), and the encodings the browser takes, since
58
+ * what comes back is passed on decoded.
50
59
  */
51
60
  const NOT_FORWARDED: ReadonlySet<string> = new Set([
52
61
  "host",
@@ -64,6 +73,23 @@ const NOT_ANSWERED: ReadonlySet<string> = new Set([
64
73
  "content-length",
65
74
  ]);
66
75
 
76
+ /** An origin on this machine: the loopback by any of its names, on any port. */
77
+ const LOOPBACK_ORIGIN = /^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
78
+
79
+ /**
80
+ * The origin of the page a request comes from, when that page is on this machine (ADR-0083): the
81
+ * console reads it to know which page may embed a plugin's frame, and allows the loopback's.
82
+ * Nothing else of the referrer travels, its path least of all, nor a page anywhere else.
83
+ */
84
+ function loopbackReferrer(request: Request): string | undefined {
85
+ const referer = request.headers.get("referer");
86
+ if (referer === null || !URL.canParse(referer)) {
87
+ return undefined;
88
+ }
89
+ const { origin } = new URL(referer);
90
+ return LOOPBACK_ORIGIN.test(origin) ? `${origin}/` : undefined;
91
+ }
92
+
67
93
  const json = (status: number, code: string, message: string): Response =>
68
94
  new Response(JSON.stringify({ error: { code, message } }), {
69
95
  status,
@@ -92,11 +118,28 @@ function fromOwnPage(request: Request, origin: string): boolean {
92
118
  return from === null || from === origin;
93
119
  }
94
120
 
121
+ /**
122
+ * The files a plugin's frame is made of (docs/specs/plugins.md, "The frame"): a file of a
123
+ * plugin's bundle at its version, and the console's stylesheet and faces for frames. The
124
+ * console answers them to anyone, with no session, and marks them for any origin to read: a
125
+ * frame is sandboxed, its origin opaque, so that what it asks of the address its document was
126
+ * read from reaches the browser as another site's request. The path as the browser's address
127
+ * holds it, dot segments resolved: a plugin's key, `web`, a version, and a file under it.
128
+ */
129
+ const FRAME_FILE =
130
+ /^\/api\/v1\/(?:plugin-runtime\/[^/]|plugins\/[a-z][a-z0-9-]{1,31}\/web\/[^/]+\/[^/])/;
131
+
132
+ /** Whether a request reads a file of a plugin's frame: a `GET` of such a path, and nothing else. */
133
+ const readsFrameFile = (request: Request, url: URL): boolean =>
134
+ request.method === "GET" && FRAME_FILE.test(url.pathname);
135
+
95
136
  async function forward(
96
137
  request: Request,
97
138
  url: URL,
98
139
  upstream: string,
99
140
  options: ServeOptions,
141
+ /** Whether the request is carried with the person's token: not what the console answers to anyone. */
142
+ asPerson = true,
100
143
  ): Promise<Response> {
101
144
  const headers = new Headers();
102
145
  request.headers.forEach((value, name) => {
@@ -104,8 +147,14 @@ async function forward(
104
147
  headers.set(name, value);
105
148
  }
106
149
  });
107
- headers.set("authorization", `Bearer ${options.token}`);
150
+ if (asPerson) {
151
+ headers.set("authorization", `Bearer ${options.token}`);
152
+ }
108
153
  headers.set("accept-encoding", "identity");
154
+ const referrer = loopbackReferrer(request);
155
+ if (referrer !== undefined) {
156
+ headers.set("referer", referrer);
157
+ }
109
158
  const withBody = request.method !== "GET" && request.method !== "HEAD";
110
159
  let answer: Response;
111
160
  try {
@@ -130,9 +179,251 @@ async function forward(
130
179
  return new Response(answer.body, { status: answer.status, headers: out });
131
180
  }
132
181
 
182
+ /** What a desk's records are served under, beside the build and the API (ADR-0117). */
183
+ export const RECORDS_PREFIX = "/records";
184
+
185
+ /**
186
+ * What a page shows in place, by its extension: the records' own JSON, a picture, a video, a
187
+ * sound and a PDF, each under its own content type. An SVG is not among them: a picture that
188
+ * may carry a script is answered as a picture and as a download at once, under a policy that
189
+ * runs nothing, so that a page shows it and nothing opens it as a document of the pages'
190
+ * origin. Anything else is handed over as a download.
191
+ */
192
+ const SHOWN_IN_PLACE: Readonly<Record<string, string>> = {
193
+ ".json": "application/json; charset=utf-8",
194
+ ".png": "image/png",
195
+ ".jpg": "image/jpeg",
196
+ ".jpeg": "image/jpeg",
197
+ ".webp": "image/webp",
198
+ ".gif": "image/gif",
199
+ ".avif": "image/avif",
200
+ ".mp4": "video/mp4",
201
+ ".m4v": "video/mp4",
202
+ ".webm": "video/webm",
203
+ ".mov": "video/quicktime",
204
+ ".ogv": "video/ogg",
205
+ ".mp3": "audio/mpeg",
206
+ ".m4a": "audio/mp4",
207
+ ".aac": "audio/aac",
208
+ ".wav": "audio/wav",
209
+ ".ogg": "audio/ogg",
210
+ ".oga": "audio/ogg",
211
+ ".flac": "audio/flac",
212
+ ".pdf": "application/pdf",
213
+ };
214
+
215
+ export class RecordsRootError extends Error {
216
+ constructor(message: string, options?: { readonly cause?: unknown }) {
217
+ super(message, options);
218
+ this.name = "RecordsRootError";
219
+ }
220
+ }
221
+
222
+ export interface RecordsRoot {
223
+ /** Whether the directory is there now: a desk keeps nothing until its member asks (ADR-0122). */
224
+ there(): Promise<boolean>;
225
+ /** The file a request under `/records/` asks for, or the refusal that says why not. */
226
+ respond(request: Request): Promise<Response>;
227
+ }
228
+
229
+ /** A file's name as a download is called by it, in the one spelling every browser reads. */
230
+ function downloadAs(name: string): string {
231
+ const spelled = encodeURIComponent(name).replace(
232
+ /['()*]/g,
233
+ (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`,
234
+ );
235
+ return `attachment; filename*=UTF-8''${spelled}`;
236
+ }
237
+
238
+ /**
239
+ * The part of a file a request asks for: one range of bytes, as a player asks for a video from
240
+ * where it is looked at. Nothing for a request that names none, several, or another unit, which
241
+ * is answered with the whole file; `null` for a range the file does not have.
242
+ */
243
+ function rangeOf(
244
+ header: string | null,
245
+ size: number,
246
+ ): { readonly start: number; readonly end: number } | undefined | null {
247
+ const found = header === null ? null : /^bytes=(\d*)-(\d*)$/.exec(header.trim());
248
+ if (found === null) {
249
+ return undefined;
250
+ }
251
+ const [, from = "", to = ""] = found;
252
+ if (from === "") {
253
+ // The last bytes of the file, as many as are asked for.
254
+ const length = Number(to);
255
+ if (to === "") {
256
+ return undefined;
257
+ }
258
+ return length === 0 || size === 0 ? null : { start: Math.max(0, size - length), end: size - 1 };
259
+ }
260
+ const start = Number(from);
261
+ if (start >= size) {
262
+ return null;
263
+ }
264
+ const end = to === "" ? size - 1 : Math.min(Number(to), size - 1);
265
+ return end < start ? undefined : { start, end };
266
+ }
267
+
268
+ /**
269
+ * The records of a desk, served to the desk's pages (ADR-0117): every file read when it is
270
+ * asked for, so that a record an agent just wrote is what the page shows, and never kept by the
271
+ * browser. `GET` alone. A path names a file under the directory and nothing else: no part of it
272
+ * is empty, `.` or `..`, begins with a full stop, ends with one or with a space, or holds what
273
+ * a file system reads as more than a name; a link that leads out of the directory leads
274
+ * nowhere; a folder is not listed. A file that is a git LFS pointer is refused by name, since
275
+ * what would be shown is not the file.
276
+ *
277
+ * A directory that is not there yet is no error (ADR-0122): a desk has its `records/` once it
278
+ * keeps something, and its pages are served before that. Such a directory holds nothing, and
279
+ * is looked for again at each request, so that the first thing kept is served with no restart.
280
+ * What is there and is no directory is refused before anything is served.
281
+ */
282
+ export async function loadRecordsRoot(directory: string): Promise<RecordsRoot> {
283
+ /** The directory as it is now, links followed; nothing where it is not there yet. */
284
+ const rootNow = async (): Promise<string | undefined> => {
285
+ let root: string;
286
+ try {
287
+ root = await realpath(directory);
288
+ } catch (error) {
289
+ if (
290
+ typeof error === "object" &&
291
+ error !== null &&
292
+ "code" in error &&
293
+ error.code === "ENOENT"
294
+ ) {
295
+ return undefined;
296
+ }
297
+ throw new RecordsRootError(`${directory} cannot be read`, { cause: error });
298
+ }
299
+ if (!(await stat(root)).isDirectory()) {
300
+ throw new RecordsRootError(`${directory} is there and is not a directory`);
301
+ }
302
+ return root;
303
+ };
304
+ // Said before anything is served: a file where the records are to be is a mistake to say now.
305
+ await rootNow();
306
+ /** The directory at the moment of a request: nothing where it is not one then, whatever it was. */
307
+ const rootThen = (): Promise<string | undefined> => rootNow().catch(() => undefined);
308
+ const headers = {
309
+ "cache-control": "no-store",
310
+ "x-content-type-options": "nosniff",
311
+ "cross-origin-resource-policy": "same-origin",
312
+ };
313
+ const notFound = (): Response =>
314
+ json(404, "records.not_found", "No file of the records is at this path.");
315
+
316
+ const fileAt = async (root: string, pathname: string): Promise<string | undefined> => {
317
+ const parts: string[] = [];
318
+ for (const raw of pathname.slice(RECORDS_PREFIX.length + 1).split("/")) {
319
+ let part: string;
320
+ try {
321
+ part = decodeURIComponent(raw);
322
+ } catch {
323
+ return undefined;
324
+ }
325
+ if (
326
+ part.length === 0 ||
327
+ part.startsWith(".") ||
328
+ part.endsWith(".") ||
329
+ part.trim() !== part ||
330
+ /[\\/:*?"<>|]/.test(part) ||
331
+ [...part].some((character) => (character.codePointAt(0) ?? 0) < 0x20)
332
+ ) {
333
+ return undefined;
334
+ }
335
+ parts.push(part);
336
+ }
337
+ try {
338
+ // Where the path leads, links followed: a file inside the directory, or nothing.
339
+ const file = await realpath(join(root, ...parts));
340
+ return file.startsWith(`${root}${sep}`) ? file : undefined;
341
+ } catch {
342
+ return undefined;
343
+ }
344
+ };
345
+
346
+ const respond = async (request: Request): Promise<Response> => {
347
+ if (request.method !== "GET") {
348
+ const refused = json(405, "records.read_only", "The records are read here, and only read.");
349
+ refused.headers.set("allow", "GET");
350
+ return refused;
351
+ }
352
+ const { pathname } = new URL(request.url);
353
+ const root = await rootThen();
354
+ const file =
355
+ root !== undefined && pathname.startsWith(`${RECORDS_PREFIX}/`)
356
+ ? await fileAt(root, pathname)
357
+ : undefined;
358
+ if (file === undefined) {
359
+ return notFound();
360
+ }
361
+ let size: number;
362
+ try {
363
+ const info = await stat(file);
364
+ if (!info.isFile()) {
365
+ return notFound();
366
+ }
367
+ size = info.size;
368
+ } catch {
369
+ return notFound();
370
+ }
371
+ if (size <= MAX_LFS_POINTER_BYTES && isLfsPointer(await readFile(file, "utf8"))) {
372
+ return json(
373
+ 409,
374
+ "records.not_fetched",
375
+ "This file is a git LFS pointer: the file itself was not fetched on this machine. git lfs pull in the desk fetches it.",
376
+ );
377
+ }
378
+ const kind = extname(file).toLowerCase();
379
+ const shown = SHOWN_IN_PLACE[kind];
380
+ const said: Record<string, string> = {
381
+ ...headers,
382
+ "accept-ranges": "bytes",
383
+ ...(shown !== undefined
384
+ ? { "content-type": shown }
385
+ : kind === ".svg"
386
+ ? {
387
+ "content-type": "image/svg+xml",
388
+ "content-disposition": downloadAs(basename(file)),
389
+ "content-security-policy": "sandbox",
390
+ }
391
+ : {
392
+ "content-type": "application/octet-stream",
393
+ "content-disposition": downloadAs(basename(file)),
394
+ }),
395
+ };
396
+ const range = rangeOf(request.headers.get("range"), size);
397
+ if (range === null) {
398
+ return new Response(null, {
399
+ status: 416,
400
+ headers: { ...headers, "content-range": `bytes */${size}` },
401
+ });
402
+ }
403
+ if (size === 0) {
404
+ return new Response(null, { status: 200, headers: { ...said, "content-length": "0" } });
405
+ }
406
+ const { start, end } = range ?? { start: 0, end: size - 1 };
407
+ return new Response(
408
+ Readable.toWeb(createReadStream(file, { start, end })) as unknown as ReadableStream,
409
+ {
410
+ status: range === undefined ? 200 : 206,
411
+ headers: {
412
+ ...said,
413
+ "content-length": String(end - start + 1),
414
+ ...(range === undefined ? {} : { "content-range": `bytes ${start}-${end}/${size}` }),
415
+ },
416
+ },
417
+ );
418
+ };
419
+ return { there: async () => (await rootThen()) !== undefined, respond };
420
+ }
421
+
133
422
  /**
134
423
  * What the command answers: the API carried to the console with the token, for the page's own
135
- * requests; the build's files and its page for everything else, when there is a build; and
424
+ * requests; the files of a plugin's frame carried with none, for whatever page asks, since a
425
+ * frame's origin is no page's; a desk's records under `/records/`, for the same pages and no
426
+ * other site's; the build's files and its page for everything else, when there is a build; and
136
427
  * nothing to a request whose host is not this loopback, which is a page elsewhere whose name
137
428
  * was made to resolve here.
138
429
  */
@@ -149,6 +440,12 @@ export function createServeHandler(options: ServeOptions): ServeHandler {
149
440
  return plain(421, "This address is not the console's.");
150
441
  }
151
442
  if (url.pathname === "/api" || url.pathname.startsWith("/api/")) {
443
+ // A file of a plugin's frame is read whatever page asks, the frame itself first, and
444
+ // never with the person's token: it is public at the console, so that no other site's
445
+ // page reaches anything of the person's through it.
446
+ if (readsFrameFile(request, url)) {
447
+ return forward(request, url, upstream, options, false);
448
+ }
152
449
  if (!fromOwnPage(request, `http://${url.host}`)) {
153
450
  return json(
154
451
  403,
@@ -158,6 +455,24 @@ export function createServeHandler(options: ServeOptions): ServeHandler {
158
455
  }
159
456
  return forward(request, url, upstream, options);
160
457
  }
458
+ // A desk's records, or the word that none are served: never the build's page, which a
459
+ // page that asked for a file would take for one.
460
+ if (url.pathname === RECORDS_PREFIX || url.pathname.startsWith(`${RECORDS_PREFIX}/`)) {
461
+ if (!fromOwnPage(request, `http://${url.host}`)) {
462
+ return json(
463
+ 403,
464
+ "auth.forbidden_origin",
465
+ "This request must come from the console's own pages.",
466
+ );
467
+ }
468
+ return options.records === undefined
469
+ ? json(
470
+ 404,
471
+ "records.not_served",
472
+ "No records are served here. console serve --records <dir> serves a desk's.",
473
+ )
474
+ : options.records.respond(request);
475
+ }
161
476
  if (options.web !== undefined) {
162
477
  const answer = await options.web.respond(request);
163
478
  if (answer !== undefined) {