@bigmistqke/workpad 0.0.0-stage → 0.18.0

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 (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +781 -2
  3. package/bin/workpad.ts +1509 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/workpad.js +1190 -0
  6. package/dist/client/runtime.js +1194 -0
  7. package/dist/define.js +27 -0
  8. package/dist/plugins/alert/README.md +18 -0
  9. package/dist/plugins/alert/index.js +40 -0
  10. package/dist/plugins/alert/public/style.css +40 -0
  11. package/dist/plugins/ansi/README.md +36 -0
  12. package/dist/plugins/ansi/index.js +63 -0
  13. package/dist/plugins/ansi/public/style.css +28 -0
  14. package/dist/plugins/badge/README.md +32 -0
  15. package/dist/plugins/badge/index.js +28 -0
  16. package/dist/plugins/badge/public/style.css +30 -0
  17. package/dist/plugins/chat/README.md +81 -0
  18. package/dist/plugins/chat/index.js +96 -0
  19. package/dist/plugins/chat/public/client.js +3 -0
  20. package/dist/plugins/chat/public/style.css +143 -0
  21. package/dist/plugins/claude/README.md +116 -0
  22. package/dist/plugins/claude/channel.js +130 -0
  23. package/dist/plugins/claude/doctor.js +316 -0
  24. package/dist/plugins/claude/index.js +199 -0
  25. package/dist/plugins/claude/session.js +68 -0
  26. package/dist/plugins/code/README.md +54 -0
  27. package/dist/plugins/code/diff.js +75 -0
  28. package/dist/plugins/code/index.js +105 -0
  29. package/dist/plugins/code/public/client.js +1 -0
  30. package/dist/plugins/code/public/style.css +99 -0
  31. package/dist/plugins/comments/README.md +30 -0
  32. package/dist/plugins/comments/index.js +39 -0
  33. package/dist/plugins/comments/public/client.js +24 -0
  34. package/dist/plugins/comments/public/style.css +224 -0
  35. package/dist/plugins/details/README.md +24 -0
  36. package/dist/plugins/details/index.js +28 -0
  37. package/dist/plugins/details/public/style.css +7 -0
  38. package/dist/plugins/draft/README.md +14 -0
  39. package/dist/plugins/draft/index.js +27 -0
  40. package/dist/plugins/draft/public/style.css +21 -0
  41. package/dist/plugins/forge/README.md +22 -0
  42. package/dist/plugins/forge/index.js +83 -0
  43. package/dist/plugins/form/README.md +126 -0
  44. package/dist/plugins/form/index.js +179 -0
  45. package/dist/plugins/form/public/style.css +172 -0
  46. package/dist/plugins/grid/README.md +45 -0
  47. package/dist/plugins/grid/index.js +35 -0
  48. package/dist/plugins/grid/public/style.css +98 -0
  49. package/dist/plugins/iframe/README.md +18 -0
  50. package/dist/plugins/iframe/index.js +49 -0
  51. package/dist/plugins/iframe/public/style.css +28 -0
  52. package/dist/plugins/index.js +44 -0
  53. package/dist/plugins/lightbox/README.md +24 -0
  54. package/dist/plugins/lightbox/index.js +20 -0
  55. package/dist/plugins/lightbox/public/client.js +4 -0
  56. package/dist/plugins/lightbox/public/style.css +66 -0
  57. package/dist/plugins/mermaid/README.md +21 -0
  58. package/dist/plugins/mermaid/index.js +42 -0
  59. package/dist/plugins/mermaid/public/style.css +21 -0
  60. package/dist/plugins/opencode/README.md +48 -0
  61. package/dist/plugins/opencode/channel.js +92 -0
  62. package/dist/plugins/opencode/index.js +64 -0
  63. package/dist/plugins/opencode/shim.js +150 -0
  64. package/dist/plugins/quiet/README.md +26 -0
  65. package/dist/plugins/quiet/index.js +23 -0
  66. package/dist/plugins/tabs/README.md +44 -0
  67. package/dist/plugins/tabs/index.js +75 -0
  68. package/dist/plugins/tabs/public/client.js +1 -0
  69. package/dist/plugins/tabs/public/style.css +98 -0
  70. package/dist/plugins/terminal/README.md +63 -0
  71. package/dist/plugins/terminal/host.js +338 -0
  72. package/dist/plugins/terminal/index.js +170 -0
  73. package/dist/plugins/terminal/modes.js +32 -0
  74. package/dist/plugins/terminal/public/client.js +41 -0
  75. package/dist/plugins/terminal/public/style.css +511 -0
  76. package/dist/plugins/terminal/server.js +256 -0
  77. package/dist/plugins/terminal/sizes.js +58 -0
  78. package/dist/plugins/timeline/README.md +48 -0
  79. package/dist/plugins/timeline/index.js +83 -0
  80. package/dist/plugins/timeline/public/style.css +138 -0
  81. package/dist/plugins/toc/README.md +40 -0
  82. package/dist/plugins/toc/index.js +29 -0
  83. package/dist/plugins/toc/public/client.js +1 -0
  84. package/dist/plugins/toc/public/style.css +117 -0
  85. package/dist/plugins/window/README.md +51 -0
  86. package/dist/plugins/window/index.js +91 -0
  87. package/dist/solid/index.js +41 -0
  88. package/dist/src/agents.js +81 -0
  89. package/dist/src/anchors.js +52 -0
  90. package/dist/src/api.js +282 -0
  91. package/dist/src/archive.js +49 -0
  92. package/dist/src/auth.js +67 -0
  93. package/dist/src/build.js +159 -0
  94. package/dist/src/client/page/base.css +1762 -0
  95. package/dist/src/client/page/main.js +2098 -0
  96. package/dist/src/config.js +76 -0
  97. package/dist/src/document.js +93 -0
  98. package/dist/src/entries.js +264 -0
  99. package/dist/src/events.js +322 -0
  100. package/dist/src/files.js +47 -0
  101. package/dist/src/formstate.js +65 -0
  102. package/dist/src/help.js +211 -0
  103. package/dist/src/html.js +34 -0
  104. package/dist/src/hub.js +341 -0
  105. package/dist/src/icons.js +6 -0
  106. package/dist/src/listen.js +132 -0
  107. package/dist/src/listeners.js +64 -0
  108. package/dist/src/load.js +81 -0
  109. package/dist/src/loader.js +179 -0
  110. package/dist/src/migrate.js +314 -0
  111. package/dist/src/package.js +52 -0
  112. package/dist/src/pages/blocks.js +67 -0
  113. package/dist/src/pages/board.js +59 -0
  114. package/dist/src/pages/index.js +27 -0
  115. package/dist/src/pages/markdown.js +863 -0
  116. package/dist/src/pages/render.js +665 -0
  117. package/dist/src/pages/window.js +29 -0
  118. package/dist/src/plugins.js +283 -0
  119. package/dist/src/public.js +24 -0
  120. package/dist/src/rename.js +130 -0
  121. package/dist/src/running.js +146 -0
  122. package/dist/src/serve.js +188 -0
  123. package/dist/src/server.js +1105 -0
  124. package/dist/src/site.js +179 -0
  125. package/dist/src/state.js +155 -0
  126. package/dist/src/status.js +323 -0
  127. package/dist/src/thread.js +68 -0
  128. package/dist/src/watchdog.js +38 -0
  129. package/dist/src/ws.js +128 -0
  130. package/package.json +154 -4
  131. package/plugins/README.md +304 -0
  132. package/plugins/alert/README.md +18 -0
  133. package/plugins/alert/index.ts +50 -0
  134. package/plugins/alert/public/style.css +40 -0
  135. package/plugins/ansi/README.md +36 -0
  136. package/plugins/ansi/index.ts +95 -0
  137. package/plugins/ansi/public/style.css +28 -0
  138. package/plugins/badge/README.md +32 -0
  139. package/plugins/badge/index.ts +36 -0
  140. package/plugins/badge/public/style.css +30 -0
  141. package/plugins/chat/README.md +81 -0
  142. package/plugins/chat/autosize.ts +139 -0
  143. package/plugins/chat/client.tsx +187 -0
  144. package/plugins/chat/index.ts +146 -0
  145. package/plugins/chat/public/style.css +143 -0
  146. package/plugins/claude/README.md +116 -0
  147. package/plugins/claude/channel.ts +136 -0
  148. package/plugins/claude/doctor.ts +274 -0
  149. package/plugins/claude/index.ts +248 -0
  150. package/plugins/claude/session.ts +70 -0
  151. package/plugins/code/README.md +54 -0
  152. package/plugins/code/client.ts +73 -0
  153. package/plugins/code/diff.ts +96 -0
  154. package/plugins/code/index.ts +136 -0
  155. package/plugins/code/public/style.css +99 -0
  156. package/plugins/comments/README.md +30 -0
  157. package/plugins/comments/client.ts +723 -0
  158. package/plugins/comments/index.ts +48 -0
  159. package/plugins/comments/public/style.css +224 -0
  160. package/plugins/details/README.md +24 -0
  161. package/plugins/details/index.ts +30 -0
  162. package/plugins/details/public/style.css +7 -0
  163. package/plugins/draft/README.md +14 -0
  164. package/plugins/draft/index.ts +23 -0
  165. package/plugins/draft/public/style.css +21 -0
  166. package/plugins/forge/README.md +22 -0
  167. package/plugins/forge/index.ts +84 -0
  168. package/plugins/form/README.md +126 -0
  169. package/plugins/form/index.ts +199 -0
  170. package/plugins/form/public/style.css +172 -0
  171. package/plugins/grid/README.md +45 -0
  172. package/plugins/grid/index.ts +41 -0
  173. package/plugins/grid/public/style.css +98 -0
  174. package/plugins/iframe/README.md +18 -0
  175. package/plugins/iframe/index.ts +53 -0
  176. package/plugins/iframe/public/style.css +28 -0
  177. package/plugins/index.ts +49 -0
  178. package/plugins/lightbox/README.md +24 -0
  179. package/plugins/lightbox/client.ts +109 -0
  180. package/plugins/lightbox/index.ts +25 -0
  181. package/plugins/lightbox/public/style.css +66 -0
  182. package/plugins/mermaid/README.md +21 -0
  183. package/plugins/mermaid/index.ts +46 -0
  184. package/plugins/mermaid/public/style.css +21 -0
  185. package/plugins/opencode/README.md +48 -0
  186. package/plugins/opencode/channel.ts +112 -0
  187. package/plugins/opencode/index.ts +91 -0
  188. package/plugins/opencode/shim.ts +166 -0
  189. package/plugins/quiet/README.md +26 -0
  190. package/plugins/quiet/index.ts +28 -0
  191. package/plugins/tabs/README.md +44 -0
  192. package/plugins/tabs/client.ts +96 -0
  193. package/plugins/tabs/index.ts +103 -0
  194. package/plugins/tabs/public/style.css +98 -0
  195. package/plugins/terminal/README.md +63 -0
  196. package/plugins/terminal/client.ts +391 -0
  197. package/plugins/terminal/host.ts +434 -0
  198. package/plugins/terminal/index.ts +199 -0
  199. package/plugins/terminal/modes.ts +30 -0
  200. package/plugins/terminal/public/style.css +225 -0
  201. package/plugins/terminal/server.ts +266 -0
  202. package/plugins/terminal/sizes.ts +72 -0
  203. package/plugins/timeline/README.md +48 -0
  204. package/plugins/timeline/index.ts +82 -0
  205. package/plugins/timeline/public/style.css +138 -0
  206. package/plugins/toc/README.md +40 -0
  207. package/plugins/toc/client.ts +236 -0
  208. package/plugins/toc/index.ts +55 -0
  209. package/plugins/toc/public/style.css +117 -0
  210. package/plugins/window/README.md +51 -0
  211. package/plugins/window/index.ts +92 -0
  212. package/skills/workpad/SKILL.md +588 -0
  213. package/solid/index.tsx +80 -0
  214. package/src/agents.ts +133 -0
  215. package/src/anchors.ts +85 -0
  216. package/src/api.ts +444 -0
  217. package/src/archive.ts +75 -0
  218. package/src/auth.ts +99 -0
  219. package/src/build.ts +213 -0
  220. package/src/client/base.ts +19 -0
  221. package/src/client/forms.ts +420 -0
  222. package/src/client/markdown.ts +147 -0
  223. package/src/client/page/base.css +1762 -0
  224. package/src/client/page/board.ts +137 -0
  225. package/src/client/page/elsewhere.ts +153 -0
  226. package/src/client/page/fresh.ts +343 -0
  227. package/src/client/page/heading-link.ts +32 -0
  228. package/src/client/page/live.ts +134 -0
  229. package/src/client/page/main.ts +398 -0
  230. package/src/client/page/orphans.ts +64 -0
  231. package/src/client/page/place.ts +260 -0
  232. package/src/client/page/sort.ts +49 -0
  233. package/src/client/page/sticky.ts +58 -0
  234. package/src/client/page/theme.ts +36 -0
  235. package/src/client/page/view.ts +9 -0
  236. package/src/client/page/waiting.ts +278 -0
  237. package/src/client/page/window.ts +40 -0
  238. package/src/client/reactive.ts +19 -0
  239. package/src/client/read.ts +111 -0
  240. package/src/client/runtime.ts +499 -0
  241. package/src/client/scroll.ts +90 -0
  242. package/src/client/toast.ts +99 -0
  243. package/src/config.ts +111 -0
  244. package/src/define.ts +997 -0
  245. package/src/document.ts +191 -0
  246. package/src/entries.ts +352 -0
  247. package/src/events.ts +463 -0
  248. package/src/files.ts +74 -0
  249. package/src/formstate.ts +72 -0
  250. package/src/help.ts +238 -0
  251. package/src/html.ts +44 -0
  252. package/src/hub.ts +426 -0
  253. package/src/icons.ts +18 -0
  254. package/src/listen.ts +171 -0
  255. package/src/listeners.ts +89 -0
  256. package/src/load.ts +113 -0
  257. package/src/loader.ts +227 -0
  258. package/src/migrate.ts +352 -0
  259. package/src/package.ts +62 -0
  260. package/src/pages/blocks.ts +106 -0
  261. package/src/pages/board.ts +89 -0
  262. package/src/pages/index.ts +79 -0
  263. package/src/pages/markdown.ts +976 -0
  264. package/src/pages/render.ts +748 -0
  265. package/src/pages/window.ts +69 -0
  266. package/src/plugins.ts +319 -0
  267. package/src/public.ts +39 -0
  268. package/src/rename.ts +147 -0
  269. package/src/running.ts +171 -0
  270. package/src/serve.ts +221 -0
  271. package/src/server.ts +1385 -0
  272. package/src/site.ts +170 -0
  273. package/src/state.ts +327 -0
  274. package/src/status.ts +466 -0
  275. package/src/thread.ts +98 -0
  276. package/src/watchdog.ts +53 -0
  277. package/src/ws.ts +155 -0
@@ -0,0 +1,304 @@
1
+ # Writing a plugin
2
+
3
+ How to extend workpad. The plugins in this folder are the built-in ones,
4
+ and the best examples. Each one has a `README.md` that says what it does and
5
+ how to use it; for those that add to pages it is what `workpad docs` tells
6
+ an agent writing them. This file is for writing a plugin of your own.
7
+
8
+ Everything that extends workpad is a plugin: syntax for pages,
9
+ behaviour on every page, commands, events. A plugin is an object with a
10
+ name, and everything it adds lives under that name, so two plugins can't
11
+ collide: its block `:::name`, its events `name:…`, its command
12
+ `workpad name`, its routes `/api/name/…` and its data folder
13
+ `.workpad/name/`. Local plugins go in `.workpad/plugins/`.
14
+
15
+ ## A block: a checklist the reader ticks
16
+
17
+ A block is syntax: `:::name` around content, `::name` on a line, `:name`
18
+ inside a line, or a code fence of that name. It renders on the server, and
19
+ with a `client` it is mounted in the browser too.
20
+
21
+ ```ts
22
+ // .workpad/plugins/checklist/index.ts
23
+ import { definePlugin, html, type DirectiveContext } from '@bigmistqke/workpad'
24
+
25
+ const toText = (node: any): string => node.value ?? (node.children ?? []).map(toText).join('')
26
+
27
+ export default function checklist() {
28
+ return definePlugin({
29
+ name: 'checklist',
30
+ blocks: {
31
+ checklist: {
32
+ // what the browser part gets: the block's list items as text
33
+ props: ctx => {
34
+ const c = ctx as DirectiveContext // a block (`:::checklist`), not a code fence
35
+ return {
36
+ name: c.attrs.name ?? 'checklist',
37
+ items: (c.children as any[]).filter(n => n.type === 'list')
38
+ .flatMap(list => list.children.map((item: any) => toText(item))),
39
+ }
40
+ },
41
+ // shown until the client mounts, then replaced
42
+ html: () => html`<ul class="checklist"></ul>`,
43
+ client: 'client.js', // in its public/ folder
44
+ },
45
+ },
46
+ // its events, and whether a `wait` on the page hands them out (a tick is information: no)
47
+ events: { 'checklist:tick': { description: '`{ checklist, item, checked }`' } },
48
+ // for `workpad docs`, under a `# Plugin: checklist` heading the core adds
49
+ docs: () => 'A list the reader ticks:\n\n :::checklist{name=launch}\n - Write the changelog\n :::\n',
50
+ })
51
+ }
52
+ ```
53
+
54
+ ```js
55
+ // .workpad/plugins/checklist/public/client.js: its public/ folder is served, nothing else of it
56
+ export default function mount(el, { name, items }, api) {
57
+ const ticked = () => {
58
+ const state = new Map()
59
+ for (const e of api.events()) if (e.type === 'checklist:tick' && e.data.checklist === name) state.set(e.data.item, e.data.checked)
60
+ return state
61
+ }
62
+ const draw = () => {
63
+ const state = ticked()
64
+ el.replaceChildren(...items.map(item => {
65
+ const box = Object.assign(document.createElement('input'), { type: 'checkbox', checked: !!state.get(item) })
66
+ box.addEventListener('change', () => api.append('checklist:tick', { checklist: name, item, checked: box.checked }))
67
+ const label = document.createElement('label')
68
+ label.append(box, ' ', item)
69
+ return label
70
+ }))
71
+ }
72
+ draw()
73
+ // the page's events, also the ones it appends itself, come back here
74
+ return api.events.on(draw)
75
+ }
76
+ ```
77
+
78
+ ```ts
79
+ // .workpad/config.ts
80
+ import { defineConfig } from '@bigmistqke/workpad'
81
+ import checklist from './plugins/checklist/index.ts'
82
+
83
+ export default defineConfig({ plugins: [checklist()] })
84
+ ```
85
+
86
+ An agent can wait for a tick by asking for it: `workpad wait --page
87
+ <file> --type checklist:tick`.
88
+
89
+ ## Behaviour on every page: votes
90
+
91
+ A plugin can also put something on every page, and add commands:
92
+
93
+ ```ts
94
+ // .workpad/plugins/votes/index.ts
95
+ import { definePlugin } from '@bigmistqke/workpad'
96
+ import { read } from '@bigmistqke/workpad/log'
97
+
98
+ export default function votes() {
99
+ return definePlugin({
100
+ name: 'votes',
101
+ events: { 'votes:up': { description: 'the reader voted the page up' } },
102
+ commands: {
103
+ '': {
104
+ description: 'print the votes per page',
105
+ run(ctx) {
106
+ const counts = new Map<string, number>()
107
+ for (const e of read(ctx.eventsFile).events) if (e.type === 'votes:up') counts.set(e.page, (counts.get(e.page) ?? 0) + 1)
108
+ for (const [page, n] of counts) console.log(`${page}: ${n}`)
109
+ },
110
+ },
111
+ },
112
+ docs: () => 'The reader can vote a page up: a `votes:up` event. `workpad votes` counts them.',
113
+ // from setup: what the running server adds (routes, what it puts in its slots, the browser module)
114
+ setup: () => ({ client: 'client.js' }),
115
+ })
116
+ }
117
+ ```
118
+
119
+ ```js
120
+ // .workpad/plugins/votes/public/client.js
121
+ export default function mount(root, page, api) {
122
+ const button = document.createElement('button')
123
+ const draw = () => { button.textContent = `👍 ${api.events().filter(e => e.type === 'votes:up').length}` }
124
+ button.addEventListener('click', () => api.append('votes:up'))
125
+ api.slot('corner', el => { // its own element in the page's corner, for floating buttons
126
+ el.append(button)
127
+ return () => button.remove()
128
+ })
129
+ api.events.on(draw)
130
+ draw()
131
+ }
132
+ ```
133
+
134
+ ## What a plugin can have
135
+
136
+ - **`blocks`**, by name. A block has `html(ctx)` (the server's HTML; `ctx`
137
+ has the block's attributes, label, content as mdast nodes, `toHtml`,
138
+ `items()` (its `:::item[Title]` containers, as a grid's cards and tabs
139
+ are), `fileUrl(src)` for the address of a file beside the page, and
140
+ more), `props(ctx)` (JSON for its client), `client` (a
141
+ browser module, mounted per block), `style` (linked on pages that use it),
142
+ `fence: true` to also take the code fences of its name (```` ```mermaid ````),
143
+ `fence: 'any'` for the block that takes every code fence nobody else
144
+ claims, and `open(ctx)`: what it shows on its own, for a window around it.
145
+ Block names are unique across a project's plugins.
146
+ - **`compose(ctx)`**: itself around any block that names the plugin in its
147
+ `compose` attribute, that block's HTML as `ctx.children` (see below).
148
+ - **`events`**, by type (`<plugin>:<what>`): a description each, and
149
+ `handOut: true` for those an agent should get unasked, like a chat
150
+ message. `workpad docs` lists them.
151
+ - **`style`**: a stylesheet on every page.
152
+ - **`docs`**: markdown for agents: how to write its blocks, what its events
153
+ mean, how to answer.
154
+ - **`commands`**: `workpad <name>` and `workpad <name> <sub>`, with
155
+ declared options that the core parses and checks. A command gets the
156
+ project, its event log (`ctx.eventsFile`, for
157
+ `@bigmistqke/workpad/log`), its token and server, what is open on each
158
+ page (`ctx.status`), handing out (`ctx.handOut`, what `wait` does), and
159
+ the project's state as data through its server (`ctx.wp`, the client of
160
+ `@bigmistqke/workpad/api`: forms, chats, agents, a live stream, hold
161
+ and release). A config can declare commands of its own the same way,
162
+ without a plugin (`commands` in the config). `live: true` on a command is
163
+ reserved for a feature to come (a page's inline scripts calling it).
164
+ - **`session()`**: the agent session a command runs in, for a plugin that
165
+ knows how its agent says so.
166
+ - **`setup(ctx)`**, which runs once per loaded config on the server and
167
+ returns:
168
+ - `routes`, by method and path (`'POST /start'` is mounted at
169
+ `/api/<name>/start`), each with what it does, whether it needs the
170
+ project's token (`auth`), and the types of its body and query; the core
171
+ checks all of that before the route's code runs;
172
+ - `slots`, markup for its element in the page's slots, there on the first
173
+ render (see below), and `head` for `<head>`;
174
+ - `client`, a module on every page, run once per page load.
175
+
176
+ **A plugin puts what it adds to the page in slots**, places the core owns:
177
+ `header` (the header bar, before the theme button), `aside` (a panel beside
178
+ the text), `bottom` (a drawer the page makes room for), `overlay` (over the
179
+ page) and `corner` (floating buttons and toasts). Each plugin has its own
180
+ element in each. Its `slots(req)` can render markup into them on the server,
181
+ so it is there on the first paint; its browser module mounts on its element
182
+ with `api.slot('bottom', el => unmount)`, handed to it whether the server
183
+ filled it or not, and what the mount returns runs when the element is taken
184
+ away. A plugin never looks the element up, and its markup names no
185
+ addresses: it names its files (`client`, `style`) and the core makes them.
186
+
187
+ ```ts
188
+ // server: the drawer, there on the first render
189
+ setup: () => ({
190
+ client: 'client.js',
191
+ slots: () => ({ bottom: html`<aside class="drawer">…</aside>` }),
192
+ }),
193
+
194
+ // browser (client.js): mounts on it
195
+ export default (root, page, api) =>
196
+ api.slot('bottom', el => {
197
+ const drawer = open(el.firstElementChild)
198
+ return () => drawer.close()
199
+ })
200
+ ```
201
+
202
+ **A plugin can compose itself around other blocks.** With `compose`, a
203
+ block whose `compose` attribute names the plugin is put in what it returns,
204
+ the block's HTML as `children`, as a component gets what it wraps. The
205
+ window plugin is one: `::image{src compose=window}`, ```` ```mermaid {compose=window} ````
206
+ and `:::grid{compose=window}` all go in a window, and none of those blocks
207
+ knows of windows. A block says what it shows on its own with `open` (an
208
+ image's file), which a window's ↗ opens. Several named compose in the order
209
+ written, the first innermost: `compose=lightbox,window`. A name no plugin
210
+ composes is said in place.
211
+
212
+ ```ts
213
+ definePlugin({
214
+ name: 'window',
215
+ compose: ({ children, label, open }) => windowFrame({ label, open, body: children }),
216
+ })
217
+ ```
218
+
219
+ **A plugin's browser files live in its `public/` folder**, and only that
220
+ folder is served: its client modules, styles, images and fonts, never its
221
+ server code or the project's files beside it. `client` and `style` (a
222
+ plugin's and a block's) name files in it: `'client.js'`. `definePlugin` puts
223
+ it next to the module that calls it (`plugins/checklist/public/` for
224
+ `plugins/checklist/index.ts`); say another with `public: new URL('./assets/',
225
+ import.meta.url)`; a plain object plugin, or one written in the config, has
226
+ `.workpad/public/`. A file named outside it is a config error. Browser
227
+ code is JavaScript or TypeScript: a `.ts` file is served with its types
228
+ stripped (Node's type stripping, as for server code: types only, so no
229
+ `enum` or `namespace`, and imports name their `.ts` files). JSX still needs
230
+ building first. A block's `client` gets
231
+ `mount(element, props, api)` and may return a cleanup, run when the block
232
+ is replaced on a live update; it replaces the server's HTML when it mounts.
233
+ A page module (`setup`'s `client`) gets `mount(root, page, api)`. Both get
234
+ the page's `api`: its `events` and `append` (which comes back through
235
+ `events.on`), the `listeners`, `forms` and `unread` messages, `onRendered`
236
+ (after a live update, to put back what it adds), the page's `frontmatter`
237
+ on the page handle (YAML, as parsed) and the plugin's own `settings` in it
238
+ (under `plugins:` by its name: `plugins: { toc: true }` is `true` for toc), `slot()` for its elements in the page's slots, `toast()` for a label in
239
+ the corner that says what is going on and goes there (one that hides after a
240
+ few seconds, or one that stays with a count), `badge()` for counts in the
241
+ tab title, `blocks(markdown)` for workpad's own blocks inside what it draws
242
+ itself (HTML the server renders as on the page, whose blocks mount once it is
243
+ in the page's content: `::chat{name=…}` gives a thread under each of its own
244
+ notes), the `theme`, and `url(path)`: the address of one of the
245
+ project's server routes as this page requests it (`api.url('/api/votes/count')`).
246
+ Ask for the plugin's routes through it rather than writing `/api/…`: under a
247
+ shared server a project is served below a path (`/rg/develop`). Every value
248
+ that changes is called for what it
249
+ is now and has `.on(fn)` for each change: `api.events()`,
250
+ `api.events.on(draw)`, `page.frontmatter.on(…)`. Files beside a browser module that are browser
251
+ assets (scripts, styles, images, fonts) are served too.
252
+
253
+ Something that covers the bottom of the window says how much in
254
+ `--wp-inset-bottom`, and the page keeps clear of it. A plugin can't be
255
+ named like a built-in command or a folder of the core.
256
+
257
+ ## Looking like the rest of the page
258
+
259
+ A block that draws its own interface looks like workpad when it leaves
260
+ the page's styles alone:
261
+
262
+ - **Plain elements are styled already.** `button`, `input`, `textarea` and
263
+ `select` get the page's look (font, padding, border, focus ring, light
264
+ and dark) from the base stylesheet. Use them bare: a block that sets their
265
+ background, border or font looks home-made next to the forms around it.
266
+ The same goes for `kbd`, `code`, tables and lists in markdown it renders.
267
+ - **Colours and sizes are variables on `:root`:** `--text`, `--muted`,
268
+ `--bg`, `--surface`, `--tint` (a subtle fill), `--border`, `--accent` (and
269
+ `--accent-text` on it), `--ok`, `--warn`, `--bad`, `--wp-sending` (what
270
+ is on its way), the type sizes `--text-size` and `--ui-tiny`, the spacing
271
+ steps `--space-xs` … `--space-2xl`, and `--radius-sm`. Each one is right
272
+ in both themes, so a block needs no dark mode of its own. A canvas reads
273
+ them with `getComputedStyle`, and draws again when `api.theme` changes.
274
+ - **Don't build what workpad has.** A thread of messages is a chat:
275
+ `::chat{name=…}` in the block's markdown, or through `api.blocks()` for
276
+ things the reader makes in the browser (a note under each of them). It
277
+ brings drafts, sending, unread marks and the agent's replies as small
278
+ pages; one of the block's own has none of that.
279
+
280
+ ## Keys and files
281
+
282
+ - **Keys.** The page has its own keys, and space scrolls it. A block that
283
+ takes keys (play, switch) listens on its own element, made focusable
284
+ (`tabIndex = 0`) and focused when the reader clicks in it, never on
285
+ `window`; and it leaves keys alone while the target is a text field.
286
+ Give each key a visible button too, so nothing depends on focus.
287
+ - **Files.** A file in the repository is served at `/-/<path>` as it is,
288
+ any type (an image, a WAV, a PDF): `ctx.fileUrl(src)` gives its address
289
+ from a path relative to the page, and a link in the block's markdown is
290
+ rewritten to it already. Files the repository ignores in git are served
291
+ too; the config's `files` setting is what leaves things out.
292
+
293
+ ## Patterns in the built-in plugins
294
+
295
+ | want | look at |
296
+ | --- | --- |
297
+ | a block with a browser part | `checklist` above; `tabs/` |
298
+ | a block around other blocks (`compose`) | `window/`, `lightbox/` |
299
+ | markup there on the first paint, a drawer the page makes room for (`bottom`) | `terminal/` |
300
+ | a button in the header bar and a panel beside the text (`header`, `aside`) | `toc/` |
301
+ | things over the page, placed in document coordinates (`overlay`) | `comments/` |
302
+ | a browser module that works on every page's content | `code/` (measures code blocks), `lightbox/` |
303
+ | events an agent gets, answered in place | `chat/`, `comments/` |
304
+ | commands and routes | `terminal/` (both), `claude/`, `opencode/` (commands) |
@@ -0,0 +1,18 @@
1
+ A highlighted box, written the way GitHub, Obsidian and most markdown tools
2
+ already write it: a quote that starts with its type. A title can follow the
3
+ type (as in Obsidian); without one, the box is named after its type.
4
+
5
+ ```markdown
6
+ > [!WARNING] Heads up
7
+ > Solid 2 is a release candidate; APIs can still move.
8
+ ```
9
+
10
+ > [!WARNING] Heads up
11
+ > Solid 2 is a release candidate; APIs can still move.
12
+
13
+ The types: GitHub's `NOTE`, `TIP`, `IMPORTANT`, `WARNING` and `CAUTION`, and
14
+ Obsidian's `SUCCESS`, `DANGER` and `QUESTION`, in any case (`[!tip]`). Any
15
+ other type is a quote like any other, as on GitHub.
16
+
17
+ The quote's lines are any markdown: a list, code, a diagram, other blocks,
18
+ each line behind `> `.
@@ -0,0 +1,50 @@
1
+ // Alerts: a highlighted box, written as markdown tools already write it, a quote that starts with its
2
+ // type (GitHub's alerts; Obsidian's title after the type):
3
+ //
4
+ // > [!WARNING] Heads up
5
+ // > Solid 2 is a release candidate; APIs can still move.
6
+ //
7
+ // GitHub's five types and Obsidian's success, danger and question. Another type is a quote like any
8
+ // other, as GitHub shows it. The core hands such quotes to this block (Block.alert).
9
+ import fs from 'node:fs'
10
+ import { definePlugin, html, raw, type DirectiveContext, type Plugin } from '@bigmistqke/workpad'
11
+ import { builtinPublic } from '../../src/package.ts'
12
+
13
+ /** The types, and what a box without a title of its own is called. */
14
+ const TYPES: Record<string, string> = {
15
+ note: 'Note',
16
+ tip: 'Tip',
17
+ important: 'Important',
18
+ warning: 'Warning',
19
+ caution: 'Caution',
20
+ success: 'Success',
21
+ danger: 'Danger',
22
+ question: 'Question',
23
+ }
24
+
25
+ export async function render(ctx: DirectiveContext) {
26
+ const type = String(ctx.attrs.type ?? '')
27
+ const content = raw(await ctx.toHtml(ctx.children))
28
+ // not one of them: the quote as written, [!TYPE] and all
29
+ if (!TYPES[type])
30
+ return html`<blockquote><p>[!${type.toUpperCase()}]${ctx.label ? html` ${raw(ctx.label)}` : ''}</p>${content}</blockquote>`
31
+ const title = ctx.label ? raw(ctx.label) : TYPES[type]
32
+ return html`<aside class="wp-alert" data-type="${type}"><div class="wp-alert-title">${title}</div>${content}</aside>`
33
+ }
34
+
35
+ export default function alert(): Plugin {
36
+ return definePlugin({
37
+ name: 'alert',
38
+ public: builtinPublic('alert'),
39
+ blocks: {
40
+ alert: {
41
+ menu: { group: 'mark', summary: 'a box that stands out: > [!NOTE], [!TIP], [!WARNING]' },
42
+ attrs: ['type'],
43
+ alert: true,
44
+ html: render,
45
+ style: 'style.css',
46
+ },
47
+ },
48
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
49
+ })
50
+ }
@@ -0,0 +1,40 @@
1
+ /* an alert (index.ts): a coloured rule and a light tint, set in the body face */
2
+ .wp-alert {
3
+ --c: var(--info);
4
+ margin: var(--gap-block) 0;
5
+ padding: 1em 1.3em;
6
+ border-left: 3px solid var(--c);
7
+ background: color-mix(in srgb, var(--c) var(--tint-faint), var(--bg));
8
+ border-radius: 0 var(--radius) var(--radius) 0;
9
+ }
10
+ /* alerts in a row read as a group */
11
+ .wp-alert:has(+ .wp-alert) {
12
+ margin-bottom: var(--gap-group);
13
+ }
14
+ .wp-alert + .wp-alert {
15
+ margin-top: var(--gap-group);
16
+ }
17
+ .wp-alert > :first-child {
18
+ margin-top: 0;
19
+ }
20
+ .wp-alert > :last-child {
21
+ margin-bottom: 0;
22
+ }
23
+ .wp-alert-title {
24
+ font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
25
+ color: var(--c);
26
+ margin-bottom: var(--gap-attach);
27
+ letter-spacing: 0.01em;
28
+ }
29
+ .wp-alert:is([data-type='tip'], [data-type='success']) {
30
+ --c: var(--ok);
31
+ }
32
+ .wp-alert[data-type='important'] {
33
+ --c: var(--accent);
34
+ }
35
+ .wp-alert:is([data-type='warning'], [data-type='question']) {
36
+ --c: var(--warn);
37
+ }
38
+ .wp-alert:is([data-type='caution'], [data-type='danger']) {
39
+ --c: var(--bad);
40
+ }
@@ -0,0 +1,36 @@
1
+ What a program printed, as its terminal showed it: an `ansi` fence holds the
2
+ output with its escape codes, and the page draws it dark, in its colours, as a
3
+ terminal does. It goes through a terminal emulator on the server, so colours
4
+ (16, 256 and true colour, foreground and background), bold, dim and underline
5
+ show, and a progress line that a carriage return writes over shows as it
6
+ ended. It is plain HTML: nothing runs on the page, and `workpad build` keeps
7
+ it. Wide output scrolls sideways (a line wraps at 240 columns, as a terminal
8
+ that wide would).
9
+
10
+ ````markdown
11
+ ```ansi
12
+ \e[32m✔\e[0m parses a page
13
+ \e[31m✖\e[0m renders a diff \e[2m(12ms)\e[0m
14
+ ```
15
+ ````
16
+
17
+ ```ansi
18
+ \e[32m✔\e[0m parses a page
19
+ \e[31m✖\e[0m renders a diff \e[2m(12ms)\e[0m
20
+ ```
21
+
22
+ The escape byte itself works, and so does any way of writing it out: `\e`,
23
+ `\x1b`, `\033`, `\u001b` or `^[`. A carriage return has to be the byte itself,
24
+ as a program prints it: `\r` written out stays as written, since it is as
25
+ likely a path (`C:\repo`). To capture a command's colours, have it colour
26
+ output that isn't a terminal (`--color=always`, `FORCE_COLOR=1`) and paste
27
+ what it printed.
28
+
29
+ In a window, as any block: `compose=window`, with `title` its label; its
30
+ button fills the browser window with it:
31
+
32
+ ````markdown
33
+ ```ansi {compose=window title="npm test"}
34
+ …
35
+ ```
36
+ ````
@@ -0,0 +1,95 @@
1
+ // Terminal output in a page: an `ansi` fence holds what a program printed, escape codes and all, and
2
+ // the page shows it as the terminal did. The text goes through a headless terminal (xterm's, the
3
+ // one the terminal plugin keeps its screens in), so what a terminal does with it is what shows:
4
+ // colours (16, 256 and true colour), bold, a progress line `\r` writes over, the cursor moving.
5
+ // Rendered on the server to plain HTML, so nothing runs on the page and a built site has it too.
6
+ import fs from 'node:fs'
7
+ import { definePlugin, html, raw, type FenceContext, type Plugin } from '@bigmistqke/workpad'
8
+ import xtermHeadless from '@xterm/headless'
9
+ import xtermSerialize from '@xterm/addon-serialize'
10
+ import { builtinPublic } from '../../src/package.ts'
11
+
12
+ // CommonJS packages: their exports are the default's
13
+ const { Terminal } = xtermHeadless
14
+ const { SerializeAddon } = xtermSerialize
15
+
16
+ /** The widest a line is laid out before it wraps, as a terminal would. */
17
+ const MAX_COLS = 240
18
+ const ESC = '\x1b'
19
+
20
+ /**
21
+ * Escapes written out as text count as escapes: an agent writing a page often can't put the ESC
22
+ * byte itself in a file, so `\e[31m`, `\x1b[31m`, `\033[31m`, `\u001b[31m` and `^[[31m` are one.
23
+ */
24
+ export const unescape = (text: string): string => text.replace(/\\e(?=\[)|\\x1b|\\033|\\u001b|\^\[(?=\[)/gi, ESC)
25
+
26
+ /** How wide a line shows: its characters, without its escape sequences. */
27
+ const shown = (line: string) =>
28
+ [
29
+ ...line
30
+ .replace(/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g, '')
31
+ .split('\r')
32
+ .at(-1)!,
33
+ ].length
34
+
35
+ /**
36
+ * What the text shows in a terminal as wide as its widest line (up to MAX_COLS), as HTML rows: the
37
+ * serializer's spans, colours inline, text escaped; trailing blank space and blank rows left out.
38
+ */
39
+ export async function toHtml(text: string): Promise<string> {
40
+ const input = unescape(text).replace(/\r?\n$/, '')
41
+ const lines = input.split(/\r?\n/)
42
+ const cols = Math.min(MAX_COLS, Math.max(20, ...lines.map(shown)))
43
+ const term = new Terminal({
44
+ cols,
45
+ rows: Math.max(1, lines.length),
46
+ scrollback: 100_000,
47
+ allowProposedApi: true,
48
+ convertEol: true,
49
+ })
50
+ const serializer = new SerializeAddon()
51
+ term.loadAddon(serializer)
52
+ await new Promise<void>(resolve => term.write(input, resolve))
53
+ const out = serializer.serializeAsHTML({ includeGlobalBackground: false })
54
+ term.dispose()
55
+ // the rows, without the wrapper that sets the serializer's own colours and font
56
+ const body = /<pre><div style='[^']*'>([\s\S]*)<\/div><\/pre>/.exec(out)?.[1] ?? ''
57
+ const rows = [...body.matchAll(/<div>([\s\S]*?)<\/div>/g)].map(m =>
58
+ // a row's padding to the terminal's width is no part of the output
59
+ m[1]!
60
+ .replace(/<span><\/span>/g, '')
61
+ .replace(/<span> +<\/span>$/, '')
62
+ .replace(/(<span>[^<]*?) +(<\/span>)$/, '$1$2'),
63
+ )
64
+ while (
65
+ rows.length &&
66
+ !rows
67
+ .at(-1)!
68
+ .replace(/<[^>]+>/g, '')
69
+ .trim()
70
+ )
71
+ rows.pop()
72
+ return rows.map(r => `<span class="wp-ansi-row">${r}</span>`).join('\n')
73
+ }
74
+
75
+ export async function render(ctx: FenceContext) {
76
+ // a window around it, as around any block, is `compose=window` (with `title=` its label)
77
+ return html`<pre class="wp-ansi"><code>${raw(await toHtml(ctx.text))}</code></pre>`
78
+ }
79
+
80
+ export default function ansi(): Plugin {
81
+ return definePlugin({
82
+ name: 'ansi',
83
+ public: builtinPublic('ansi'),
84
+ blocks: {
85
+ ansi: {
86
+ menu: { group: 'show', summary: 'a program\'s output, in its colours' },
87
+ attrs: [],
88
+ fence: true,
89
+ html: render,
90
+ style: 'style.css',
91
+ },
92
+ },
93
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
94
+ })
95
+ }
@@ -0,0 +1,28 @@
1
+ /* Terminal output: dark as a terminal in either theme, since the colours in it are a terminal's
2
+ palette, written inline. Wide output scrolls sideways rather than wrapping. */
3
+ .wp-ansi {
4
+ margin: var(--gap-block) 0;
5
+ padding: 12px 16px;
6
+ overflow-x: auto;
7
+ background: #0f1115;
8
+ color: #d7dae0;
9
+ border-radius: var(--radius, 6px);
10
+ font: 0.82rem/1.45 var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
11
+ white-space: pre;
12
+ tab-size: 8;
13
+ }
14
+ .wp-ansi code {
15
+ font: inherit;
16
+ background: none;
17
+ padding: 0;
18
+ color: inherit;
19
+ }
20
+ /* in a window (title=, or compose=window) the terminal fills it, the frame its edge */
21
+ .wp-window-body:has(> .wp-ansi:only-child) {
22
+ padding: 0;
23
+ background: #0f1115;
24
+ }
25
+ .wp-window-body > .wp-ansi {
26
+ margin: 0;
27
+ border-radius: 0;
28
+ }
@@ -0,0 +1,32 @@
1
+ A status as a coloured dot and a word, inline wherever text goes: in a
2
+ heading, a table cell, a list item, a sentence. `done ok yes good` are
3
+ green, `active new info` blue, `open todo maybe warning` amber,
4
+ `blocked no bad error` red; any other word is grey.
5
+
6
+ ```markdown
7
+ ### Parser :badge[done]
8
+
9
+ | step | state |
10
+ | --- | --- |
11
+ | parse | :badge[done] |
12
+ | render | :badge[active] |
13
+ | docs | :badge[todo] |
14
+
15
+ The release is :badge[blocked] on review.
16
+ ```
17
+
18
+ A badge that ends a heading sits at its right edge: a page's heading, a grid
19
+ card's, a timeline step's. A block of your own can have the same for a title
20
+ that isn't a heading, with a `data-wp-title` attribute on it. A badge is not
21
+ in a heading's anchor, nor in an item's: `### Parser :badge[done]` is
22
+ `#parser`, so a link to it holds while the badge changes.
23
+
24
+ ### Parser :badge[done]
25
+
26
+ | step | state |
27
+ | --- | --- |
28
+ | parse | :badge[done] |
29
+ | render | :badge[active] |
30
+ | docs | :badge[todo] |
31
+
32
+ The release is :badge[blocked] on review.
@@ -0,0 +1,36 @@
1
+ import fs from 'node:fs'
2
+ import { definePlugin, type Plugin } from '@bigmistqke/workpad'
3
+ // Static block: no component, so no JavaScript on the page.
4
+ import { html, raw, type DirectiveContext } from '@bigmistqke/workpad'
5
+ import { builtinPublic } from '../../src/package.ts'
6
+
7
+ /** The word a badge's colour is chosen by: its text, lowercased, runs of other characters a `-`. */
8
+ export const tone = (s: string) =>
9
+ s
10
+ .toLowerCase()
11
+ .trim()
12
+ .replace(/[^a-z0-9]+/g, '-')
13
+ .replace(/^-|-$/g, '')
14
+
15
+ /** `:badge[done]`: a coloured dot and a word, inline wherever text goes. */
16
+ export function render(ctx: DirectiveContext) {
17
+ const text = ctx.labelText?.trim()
18
+ if (!text) return html``
19
+ // the label is HTML already; its plain text picks the colour
20
+ return html`<span class="wp-badge" data-badge="${tone(text)}">${raw(ctx.label ?? '')}</span>`
21
+ }
22
+
23
+ export default function badge(): Plugin {
24
+ return definePlugin({
25
+ name: 'badge',
26
+ public: builtinPublic('badge'),
27
+ blocks: {
28
+ badge: {
29
+ menu: { group: 'mark', summary: 'a status in a word: done, todo, waiting' },
30
+ html: render,
31
+ style: 'style.css',
32
+ },
33
+ },
34
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
35
+ })
36
+ }
@@ -0,0 +1,30 @@
1
+ /* a coloured dot and a word, not a pill */
2
+ .wp-badge {
3
+ --c: var(--muted);
4
+ display: inline-flex;
5
+ align-items: center;
6
+ gap: var(--space-sm);
7
+ font: 500 var(--ui-tiny)/1 var(--sans);
8
+ color: var(--muted);
9
+ white-space: nowrap;
10
+ vertical-align: 0.1em;
11
+ }
12
+ .wp-badge::before {
13
+ content: '';
14
+ width: 7px;
15
+ height: 7px;
16
+ border-radius: 50%;
17
+ background: var(--c);
18
+ }
19
+ .wp-badge:is([data-badge='done'], [data-badge='ok'], [data-badge='yes'], [data-badge='good']) {
20
+ --c: var(--ok);
21
+ }
22
+ .wp-badge:is([data-badge='active'], [data-badge='new'], [data-badge='info']) {
23
+ --c: var(--info);
24
+ }
25
+ .wp-badge:is([data-badge='open'], [data-badge='todo'], [data-badge='maybe'], [data-badge='warning']) {
26
+ --c: var(--warn);
27
+ }
28
+ .wp-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
29
+ --c: var(--bad);
30
+ }