@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,49 @@
1
+ // The built-in plugins: what every project has, before its config's `plugins` (which add to them,
2
+ // and replace one of the same name: `code({ themes })` for the default `code`). The terminal and the
3
+ // Claude Code plugin are not among them: they run code, or are about one agent, so a project adds
4
+ // them itself. The table of contents is, but shows only on a page that asks for it, unless the
5
+ // config replaces it with `toc({ always: true })`.
6
+ import type { Plugin } from '../src/define.ts'
7
+ import alert from './alert/index.ts'
8
+ import chat from './chat/index.ts'
9
+ import code from './code/index.ts'
10
+ import comments from './comments/index.ts'
11
+ import details from './details/index.ts'
12
+ import forge from './forge/index.ts'
13
+ import form from './form/index.ts'
14
+ import grid from './grid/index.ts'
15
+ import iframe from './iframe/index.ts'
16
+ import mermaid from './mermaid/index.ts'
17
+ import quiet from './quiet/index.ts'
18
+ import windows from './window/index.ts'
19
+ import tabs from './tabs/index.ts'
20
+ import draft from './draft/index.ts'
21
+ import lightbox from './lightbox/index.ts'
22
+ import badge from './badge/index.ts'
23
+ import ansi from './ansi/index.ts'
24
+ import timeline from './timeline/index.ts'
25
+ import toc from './toc/index.ts'
26
+
27
+ export function builtins(): Plugin[] {
28
+ return [
29
+ alert(),
30
+ chat(),
31
+ code(),
32
+ comments(),
33
+ details(),
34
+ forge(),
35
+ form(),
36
+ grid(),
37
+ iframe(),
38
+ mermaid(),
39
+ quiet(),
40
+ windows(),
41
+ tabs(),
42
+ draft(),
43
+ lightbox(),
44
+ badge(),
45
+ ansi(),
46
+ timeline(),
47
+ toc(),
48
+ ]
49
+ }
@@ -0,0 +1,24 @@
1
+ Composed around a container, the pictures in it open large on a click: ← →
2
+ (or ‹ ›) step through the container's pictures and videos, Esc or a click
3
+ beside it closes. A picture that is a link keeps going to its link, and a
4
+ video is not opened by a click (that plays it), but takes part in the
5
+ stepping.
6
+
7
+ ```markdown
8
+ ::::grid{min=200px compose=lightbox}
9
+ :::item[Dunes]
10
+ ::image{src="dunes.jpg" alt="Dunes at dusk"}
11
+ Option A: warm, quiet.
12
+ :::
13
+
14
+ :::item[Coast]
15
+ ::image{src="coast.jpg"}
16
+ Option B: more contrast.
17
+ :::
18
+ ::::
19
+ ```
20
+
21
+ That is a gallery: a grid, and a lightbox around it. It goes around any
22
+ container (a window, tabs, a list of pictures), and with other parts:
23
+ `compose=lightbox,window`. A picture's caption in the lightbox is its alt
24
+ text (an `::image`'s label).
@@ -0,0 +1,109 @@
1
+ // The lightbox in the browser (index.ts): a click on a picture inside a container marked
2
+ // `data-lightbox` opens it large, over the page, with the container's other pictures and videos to
3
+ // step through (‹ ›, ← →); Esc or a click beside it closes it. It lives outside the page's content,
4
+ // so the page's updates leave it as it is.
5
+ import type { PluginMount } from '../../src/define'
6
+
7
+ const icon = (d: string) =>
8
+ `<svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`
9
+ const PREV = icon('M10 3.5 5.5 8l4.5 4.5')
10
+ const NEXT = icon('M6 3.5 10.5 8 6 12.5')
11
+ const CLOSE = icon('M4 4l8 8M12 4l-8 8')
12
+
13
+ /** What the lightbox shows of a container: its pictures and videos, in order; not a picture that is a link. */
14
+ const mediaIn = (scope: Element) =>
15
+ [...scope.querySelectorAll<HTMLImageElement | HTMLVideoElement>('img, video')].filter(
16
+ m => !m.closest('a, .wp-window-bar, .wp-lightbox'),
17
+ )
18
+
19
+ let overlay: HTMLElement | null = null
20
+ let items: (HTMLImageElement | HTMLVideoElement)[] = []
21
+ let at = 0
22
+
23
+ function show() {
24
+ if (!overlay) return
25
+ const item = items[at]!
26
+ const stage = overlay.querySelector('.wp-lightbox-stage')!
27
+ let shown: HTMLElement
28
+ if (item instanceof HTMLVideoElement) {
29
+ const video = item.cloneNode(true) as HTMLVideoElement
30
+ video.controls = true
31
+ video.removeAttribute('autoplay')
32
+ shown = video
33
+ } else {
34
+ const img = document.createElement('img')
35
+ img.src = item.currentSrc || item.src
36
+ img.alt = item.alt
37
+ shown = img
38
+ }
39
+ stage.replaceChildren(shown)
40
+ overlay.querySelector('.wp-lightbox-caption')!.textContent =
41
+ (item instanceof HTMLImageElement ? item.alt : item.getAttribute('aria-label')) ?? ''
42
+ for (const button of overlay.querySelectorAll<HTMLElement>('.wp-lightbox-prev, .wp-lightbox-next'))
43
+ button.hidden = items.length < 2
44
+ }
45
+
46
+ function open(scope: Element, picture: HTMLImageElement) {
47
+ items = mediaIn(scope)
48
+ at = Math.max(0, items.indexOf(picture))
49
+ overlay?.remove()
50
+ overlay = document.createElement('div')
51
+ overlay.className = 'wp-lightbox'
52
+ overlay.setAttribute('role', 'dialog')
53
+ overlay.setAttribute('aria-modal', 'true')
54
+ overlay.innerHTML = `<div class="wp-lightbox-stage"></div><div class="wp-lightbox-caption"></div>
55
+ <button type="button" class="wp-lightbox-prev" aria-label="Previous">${PREV}</button>
56
+ <button type="button" class="wp-lightbox-next" aria-label="Next">${NEXT}</button>
57
+ <button type="button" class="wp-lightbox-close" aria-label="Close">${CLOSE}</button>`
58
+ overlay.addEventListener('click', e => {
59
+ const target = e.target as Element
60
+ if (target.closest('.wp-lightbox-prev')) step(-1)
61
+ else if (target.closest('.wp-lightbox-next')) step(1)
62
+ else if (target.closest('.wp-lightbox-close') || target === overlay || target.matches('.wp-lightbox-stage')) close()
63
+ })
64
+ place?.append(overlay)
65
+ show()
66
+ }
67
+
68
+ function step(by: number) {
69
+ if (items.length < 2) return
70
+ at = (at + by + items.length) % items.length
71
+ show()
72
+ }
73
+
74
+ function close() {
75
+ overlay?.remove()
76
+ overlay = null
77
+ }
78
+
79
+ /** Where an open lightbox goes: this plugin's element in the overlay slot. */
80
+ let place: HTMLElement | null = null
81
+
82
+ let listening = false
83
+ const mount: PluginMount = (_root, _page, api) => {
84
+ api.slot('overlay', el => {
85
+ place = el
86
+ return () => {
87
+ close()
88
+ place = null
89
+ }
90
+ })
91
+ if (listening) return
92
+ listening = true
93
+ document.addEventListener('click', e => {
94
+ const picture = (e.target as Element).closest?.('img')
95
+ const scope = picture?.closest('[data-lightbox]')
96
+ if (!picture || !scope || !place || picture.closest('a, .wp-lightbox')) return
97
+ e.preventDefault()
98
+ open(scope, picture)
99
+ })
100
+ document.addEventListener('keydown', e => {
101
+ if (!overlay) return
102
+ if (e.key === 'Escape') close()
103
+ else if (e.key === 'ArrowLeft') step(-1)
104
+ else if (e.key === 'ArrowRight') step(1)
105
+ else return
106
+ e.preventDefault()
107
+ })
108
+ }
109
+ export default mount
@@ -0,0 +1,25 @@
1
+ // The lightbox: composed around a container (`:::grid{compose=lightbox}`), it makes the pictures in
2
+ // it open large on a click, and ← → step through the container's pictures and videos. The pictures
3
+ // themselves know nothing of it: outside one, a picture is just a picture. It marks the container
4
+ // (its outer element gets `data-lightbox`) rather than wrapping it, so the page lays the container
5
+ // out as before (a wide grid stays wide); the browser module (client.ts) does the rest.
6
+ import fs from 'node:fs'
7
+ import { definePlugin, html, raw, type Plugin } from '@bigmistqke/workpad'
8
+ import { builtinPublic } from '../../src/package.ts'
9
+
10
+ /** The container's HTML with its outer element marked; around it, when it starts with no element. */
11
+ export function mark(children: string): string {
12
+ const marked = children.replace(/^(\s*<[a-zA-Z][\w-]*)(?=[\s>/])/, '$1 data-lightbox')
13
+ return marked !== children ? marked : String(html`<div data-lightbox>${raw(children)}</div>`)
14
+ }
15
+
16
+ export default function lightbox(): Plugin {
17
+ return definePlugin({
18
+ name: 'lightbox',
19
+ public: builtinPublic('lightbox'),
20
+ style: 'style.css',
21
+ compose: ({ children }) => mark(String(children)),
22
+ setup: () => ({ client: 'client.js' }),
23
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
24
+ })
25
+ }
@@ -0,0 +1,66 @@
1
+ /* The lightbox (index.ts, client.ts): pictures in a container composed with it open on a click */
2
+ [data-lightbox] img:not(a img) {
3
+ cursor: zoom-in;
4
+ }
5
+ /* over the page: the picture or video as large as fits, its caption under it */
6
+ .wp-lightbox {
7
+ position: fixed;
8
+ inset: 0;
9
+ z-index: var(--layer-top);
10
+ background: rgb(0 0 0 / 0.86);
11
+ display: grid;
12
+ place-items: center;
13
+ grid-template-rows: 1fr auto;
14
+ padding: var(--space-3xl) var(--space-2xl);
15
+ }
16
+ .wp-lightbox-stage {
17
+ display: grid;
18
+ place-items: center;
19
+ min-height: 0;
20
+ width: 100%;
21
+ height: 100%;
22
+ }
23
+ .wp-lightbox-stage > :is(img, video) {
24
+ max-width: 100%;
25
+ max-height: calc(100vh - 110px);
26
+ object-fit: contain;
27
+ border-radius: var(--radius-sm);
28
+ }
29
+ .wp-lightbox-caption {
30
+ color: #eee;
31
+ text-align: center;
32
+ padding-top: var(--space-lg);
33
+ }
34
+ .wp-lightbox button {
35
+ position: absolute;
36
+ display: grid;
37
+ place-items: center;
38
+ background: rgb(255 255 255 / 0.12);
39
+ color: #fff;
40
+ border: 0;
41
+ width: 44px;
42
+ height: 44px;
43
+ border-radius: 50%;
44
+ padding: 0;
45
+ cursor: pointer;
46
+ }
47
+ .wp-lightbox button:hover {
48
+ background: rgb(255 255 255 / 0.22);
49
+ }
50
+ .wp-lightbox-prev {
51
+ left: 12px;
52
+ top: 50%;
53
+ translate: 0 -50%;
54
+ }
55
+ .wp-lightbox-next {
56
+ right: 12px;
57
+ top: 50%;
58
+ translate: 0 -50%;
59
+ }
60
+ .wp-lightbox button[hidden] {
61
+ display: none;
62
+ }
63
+ .wp-lightbox-close {
64
+ right: 12px;
65
+ top: 12px;
66
+ }
@@ -0,0 +1,21 @@
1
+ A [Mermaid](https://mermaid.js.org) diagram from a fence: flowcharts,
2
+ sequence, state, class, ER, gantt, pie and the other Mermaid types. Rendered
3
+ to SVG on the server by [Pele](https://pele.run), so no script runs on the
4
+ page; colours follow the page theme. A syntax error shows the line and
5
+ column in place of the diagram.
6
+
7
+ ````markdown
8
+ ```mermaid
9
+ flowchart LR
10
+ agent[agent writes .md] --> page[page in browser]
11
+ page -- form submit --> log[(events.ndjson)]
12
+ log -- workpad listen --> agent
13
+ ```
14
+ ````
15
+
16
+ ```mermaid
17
+ flowchart LR
18
+ agent[agent writes .md] --> page[page in browser]
19
+ page -- form submit --> log[(events.ndjson)]
20
+ log -- workpad listen --> agent
21
+ ```
@@ -0,0 +1,46 @@
1
+ import fs from 'node:fs'
2
+ import { definePlugin, type Plugin } from '@bigmistqke/workpad'
3
+ // Mermaid diagrams rendered to SVG on the server with Pele (https://pele.run): no JavaScript on
4
+ // the page, and colours come from CSS variables, so diagrams follow the light/dark theme.
5
+ import crypto from 'node:crypto'
6
+ import type * as Pele from 'pele'
7
+ import { html, raw, type FenceContext } from '@bigmistqke/workpad'
8
+ import { builtinPublic } from '../../src/package.ts'
9
+
10
+ // loaded the first time a page has a diagram, not with the plugin: the command line loads plugins too
11
+ let pele: typeof Pele | undefined
12
+
13
+ const FONT = 'ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
14
+
15
+ export async function render(ctx: FenceContext) {
16
+ pele ??= await import('pele')
17
+ // ids derive from the source, so an unchanged diagram renders the same markup every time
18
+ const idPrefix = `wpm-${crypto.createHash('sha1').update(ctx.text).digest('hex').slice(0, 8)}-`
19
+ try {
20
+ const { svg } = pele.render(ctx.text, { idPrefix, fontFamily: FONT, responsive: true })
21
+ // the SVG is Pele's markup
22
+ return html`<figure class="wp-diagram wp-figure">${raw(svg)}</figure>`
23
+ } catch (err) {
24
+ if (!(err instanceof pele.PeleError)) throw err
25
+ const where = err.line ? ` (line ${err.line}${err.column ? `, column ${err.column}` : ''})` : ''
26
+ const snippet = err.snippet ? `\n\n${err.snippet}` : ''
27
+ return html`<pre class="wp-error">mermaid: ${err.message}${where}${snippet}</pre>`
28
+ }
29
+ }
30
+
31
+ export default function mermaid(): Plugin {
32
+ return definePlugin({
33
+ name: 'mermaid',
34
+ public: builtinPublic('mermaid'),
35
+ blocks: {
36
+ mermaid: {
37
+ menu: { group: 'show', summary: 'a diagram: flowchart, sequence, state' },
38
+ attrs: [],
39
+ fence: true,
40
+ html: render,
41
+ style: 'style.css',
42
+ },
43
+ },
44
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
45
+ })
46
+ }
@@ -0,0 +1,21 @@
1
+ /* Pele reads its colours from --pele-* variables; map them onto the page's tokens so diagrams
2
+ follow the theme without being re-rendered. */
3
+ .wp-diagram {
4
+ margin: var(--gap-block) 0;
5
+ overflow-x: auto;
6
+ text-align: center;
7
+ --pele-bg: transparent;
8
+ --pele-fg: var(--text);
9
+ --pele-muted: var(--muted);
10
+ --pele-line: var(--muted);
11
+ --pele-surface: var(--surface);
12
+ --pele-surface-alt: var(--code-bg);
13
+ --pele-border: var(--border);
14
+ --pele-accent: var(--accent);
15
+ --pele-font: var(--sans);
16
+ --pele-radius: 6px;
17
+ }
18
+ .wp-diagram svg {
19
+ max-width: 100%;
20
+ height: auto;
21
+ }
@@ -0,0 +1,48 @@
1
+ # opencode
2
+
3
+ The opencode plugin brings your answers to an
4
+ [opencode](https://opencode.ai) session without the agent having to wait
5
+ for them, and sends a turn that ends with something left on its pages on
6
+ once:
7
+
8
+ ```ts
9
+ import opencode from '@bigmistqke/workpad/opencode'
10
+
11
+ export default defineConfig({
12
+ plugins: [opencode()],
13
+ })
14
+ ```
15
+
16
+ `workpad opencode install` writes the plugin opencode loads,
17
+ `.opencode/plugins/workpad.js` (`uninstall` removes it again). It runs
18
+ the project's own copy of workpad when it depends on one, so it can be
19
+ committed. opencode loads it when it starts in the project, with no flag:
20
+
21
+ - each command the agent runs is told its session (`OPENCODE_SESSION_ID`),
22
+ so `workpad new` subscribes it to the page, and `workpad status` marks
23
+ its pages;
24
+ - once the agent has run `workpad agent ping` and confirmed the pong that
25
+ comes in (`workpad agent ping <code>`), your answers on its pages come into
26
+ the session as a message as soon as it is idle, and count as received
27
+ once they are in; no `listen` needs to run for the agent, and
28
+ `workpad listen --channel` makes more pages its own;
29
+ - when a turn ends with something left on its pages, it goes on once, told
30
+ what to do about it; a turn the plugin already sent on ends, and you see
31
+ what is open (the Claude Code plugin's check does the same).
32
+
33
+ Problems (a hand-out that failed, say) are written to
34
+ `.workpad/opencode/channel.log`.
35
+
36
+ ## How it works
37
+
38
+ opencode loads plugins into its own process, so the file `install` writes
39
+ holds no workpad of its own: it runs the project's. Its `shell.env` hook
40
+ sets the session; one `workpad opencode channel` per opencode process
41
+ answers each session's `workpad agent ping` with a pong, and once that is
42
+ confirmed listens on the session's pages, as a `listen` does, and says each
43
+ answer. The plugin sends these into their session once it is idle, with
44
+ the agent and model you last used there. At a turn's end it has the
45
+ channel look for the session's new pages at once and runs `workpad
46
+ opencode hook stop`, which says the same as the Claude Code plugin's. The
47
+ messages the plugin sends start with `[workpad]`, so
48
+ they are told apart from yours.
@@ -0,0 +1,112 @@
1
+ // The channel of an opencode process, `workpad opencode channel`: the plugin opencode loads
2
+ // (shim.ts) starts it, and tells it on its standard input which sessions to follow, one JSON line
3
+ // each (again: look for their new pages now, as at a turn's end):
4
+ //
5
+ // {"follow":"ses_…"}
6
+ //
7
+ // For each, it is a channel of the core's (`ctx.channel`): `workpad agent ping` in the session makes
8
+ // it say a pong, which the plugin brings into the session; once the agent confirmed it, the
9
+ // channel listens on the session's pages (those it is subscribed to, also later
10
+ // ones), as a `listen` does, and says each answer there. On its standard output, one JSON line each:
11
+ //
12
+ // {"session":"ses_…","pong":true,"text":"workpad: pong. …"}
13
+ // {"session":"ses_…","id":"mwv…","page":"plan","type":"q","text":"plan: form q: \"Pears\" (id mwv…; …)"}
14
+ //
15
+ // It hands the answers out without marking them: the plugin brings them in once their session is
16
+ // idle, and then says
17
+ //
18
+ // {"session":"ses_…","received":["mwv…"]}
19
+ //
20
+ // and the channel marks them received by that session. Problems (a hand-out that failed) go to
21
+ // `.workpad/opencode/channel.log`.
22
+ import fs from 'node:fs'
23
+ import path from 'node:path'
24
+ import readline from 'node:readline'
25
+ import type { CommandContext, WpEvent } from '../../src/define.ts'
26
+ import { channelSince, read, receive, receivedBy } from '../../src/events.ts'
27
+ import { answerLine, identity, pong } from '../../src/agents.ts'
28
+
29
+ export async function channel(ctx: CommandContext) {
30
+ const problem = (what: string, data?: unknown) => {
31
+ fs.mkdirSync(ctx.dataDir, { recursive: true })
32
+ fs.appendFileSync(
33
+ path.join(ctx.dataDir, 'channel.log'),
34
+ `${new Date().toISOString()} ${what}${data === undefined ? '' : ' ' + JSON.stringify(data)}\n`,
35
+ )
36
+ }
37
+ const say = (msg: object) => process.stdout.write(JSON.stringify(msg) + '\n')
38
+
39
+ /** the sessions followed: whether each confirmed a pong */
40
+ const sessions = new Map<string, boolean>()
41
+ const hold = (session: string) => {
42
+ sessions.set(session, false)
43
+ ctx.channel(identity(session)!, {
44
+ onPing: code => say({ session, pong: true, text: pong(code) }),
45
+ onConfirmed: () => {
46
+ sessions.set(session, true)
47
+ void round()
48
+ },
49
+ })
50
+ }
51
+ // each page followed on its own, so another session's answers are never handed out here
52
+ const followed = new Set<string>()
53
+ const follow = async () => {
54
+ // who each confirmed session is on the boards, and the session to bring its pages' answers to
55
+ const who = new Map<string, string>()
56
+ for (const [session, confirmed] of sessions) if (confirmed) who.set(identity(session)!, session)
57
+ if (!who.size) return
58
+ for (const p of await ctx.status()) {
59
+ const agent = p.subscribers.find(s => who.has(s))
60
+ if (!agent || followed.has(p.page)) continue
61
+ const page = p.page
62
+ const session = who.get(agent)!
63
+ followed.add(page)
64
+ await ctx.listen(page, { agent })
65
+ const push = (e: WpEvent, again: boolean) =>
66
+ say({
67
+ session,
68
+ id: e.id,
69
+ page: e.page,
70
+ type: e.type,
71
+ text: answerLine(e, again),
72
+ })
73
+ // a page taken on through the channel: what is new, not the past someone already received
74
+ const since = channelSince(read(ctx.eventsFile).events, agent, page) ?? undefined
75
+ void ctx
76
+ .handOut({ page, exact: true }, push, { mark: false, agent, skipReceivedBefore: since })
77
+ .catch(err => problem('handing out failed', { page, err: String(err) }))
78
+ }
79
+ }
80
+
81
+ /** The plugin brought these answers into their session. */
82
+ const received = (ids: string[], session: string) => {
83
+ const agent = identity(session)
84
+ const { events } = read(ctx.eventsFile)
85
+ const had = receivedBy(events, agent)
86
+ for (const id of ids) {
87
+ const e = events.find(x => x.id === id)
88
+ if (e && !had.has(id)) receive(ctx.eventsFile, e, agent)
89
+ }
90
+ }
91
+
92
+ const round = () => follow().catch(err => problem('finding the sessions’ pages failed', String(err)))
93
+ const rl = readline.createInterface({ input: process.stdin })
94
+ rl.on('line', line => {
95
+ let msg: { follow?: unknown; received?: unknown; session?: unknown }
96
+ try {
97
+ msg = JSON.parse(line)
98
+ } catch {
99
+ return
100
+ }
101
+ if (typeof msg.follow === 'string') {
102
+ if (!sessions.has(msg.follow)) hold(msg.follow)
103
+ void round()
104
+ }
105
+ if (Array.isArray(msg.received) && typeof msg.session === 'string') received(msg.received.map(String), msg.session)
106
+ })
107
+ // opencode ended
108
+ rl.on('close', () => process.exit(0))
109
+
110
+ setInterval(() => void round(), 5000)
111
+ await new Promise(() => {})
112
+ }
@@ -0,0 +1,91 @@
1
+ // opencode, as a workpad plugin: an agent session is subscribed to the pages it makes,
2
+ // the reader's answers on them are brought into it, and a turn that ends with something left on
3
+ // them goes on once. In a config:
4
+ //
5
+ // import opencode from '@bigmistqke/workpad/opencode'
6
+ // export default defineConfig({ plugins: [opencode()] })
7
+ //
8
+ // `workpad opencode install` writes the plugin opencode loads, `.opencode/plugins/workpad.js`
9
+ // (shim.ts), and `uninstall` removes it. It runs this plugin's commands:
10
+ // - `channel`: one for the opencode process, which answers each session's `workpad agent ping` with a
11
+ // pong, and once the agent confirmed it says each answer on the session's pages (channel.ts);
12
+ // - `hook stop` (a turn ends): what is left on the session's pages, as JSON, for the plugin to send
13
+ // the session on once with, or show the reader.
14
+ //
15
+ // The plugin opencode loads puts the session in the environment of each command the agent runs,
16
+ // and of the hooks: `OPENCODE_SESSION_ID`, the session the core records when `workpad new`
17
+ // subscribes it to a page.
18
+ import fs from 'node:fs'
19
+ import path from 'node:path'
20
+ import type { Plugin } from '../../src/define.ts'
21
+ import { identity, stopReminder, workpadCommand } from '../../src/agents.ts'
22
+ import { channel } from './channel.ts'
23
+ import { shimSource } from './shim.ts'
24
+
25
+ const session = () => process.env.OPENCODE_SESSION_ID || null
26
+
27
+ export default function opencode(): Plugin {
28
+ return {
29
+ name: 'opencode',
30
+ session,
31
+ commands: {
32
+ hook: {
33
+ description:
34
+ "what the opencode plugin runs when a turn ends: what is left on the session's pages (JSON, nothing when nothing is)",
35
+ args: 'stop',
36
+ async run(ctx) {
37
+ if (ctx.positionals[0] !== 'stop') throw new Error('usage: workpad opencode hook stop')
38
+ // a hook that fails must not get in the way of the session it runs in: say why, and exit cleanly
39
+ try {
40
+ const left = await stopReminder(ctx, identity(session()))
41
+ if (left) console.log(JSON.stringify(left))
42
+ } catch (err) {
43
+ console.error(`workpad opencode hook stop: ${(err as Error).message}`)
44
+ }
45
+ },
46
+ },
47
+ channel: {
48
+ description:
49
+ "what the opencode plugin starts once per opencode process: says each answer on the pages of the sessions it is told to follow, marks those brought in received",
50
+ run: channel,
51
+ },
52
+ install: {
53
+ description: 'write the plugin opencode loads for this project: .opencode/plugins/workpad.js',
54
+ run: ctx => install(ctx.project.dir),
55
+ },
56
+ uninstall: {
57
+ description: 'remove the plugin opencode loads for this project again',
58
+ run: ctx => uninstall(ctx.project.dir),
59
+ },
60
+ },
61
+ }
62
+ }
63
+
64
+ const shimFile = (dir: string) => path.join(dir, '.opencode', 'plugins', 'workpad.js')
65
+ /** The first line of the file this plugin writes, so it removes only its own. */
66
+ const OURS = '// Installed by `workpad opencode install`'
67
+
68
+ function install(dir: string) {
69
+ const file = shimFile(dir)
70
+ const source = shimSource(workpadCommand(dir))
71
+ if (fs.existsSync(file)) {
72
+ const now = fs.readFileSync(file, 'utf8')
73
+ if (!now.startsWith(OURS)) throw new Error(`${file} is not workpad's; move it out of the way first`)
74
+ if (now === source) return console.log(`opencode plugin already installed: ${file}`)
75
+ }
76
+ fs.mkdirSync(path.dirname(file), { recursive: true })
77
+ fs.writeFileSync(`${file}.tmp`, source)
78
+ fs.renameSync(`${file}.tmp`, file)
79
+ console.log(`opencode plugin written to ${file}; opencode loads it when it starts in this project`)
80
+ }
81
+
82
+ function uninstall(dir: string) {
83
+ const file = shimFile(dir)
84
+ if (!fs.existsSync(file) || !fs.readFileSync(file, 'utf8').startsWith(OURS))
85
+ return console.log(`no workpad opencode plugin at ${file}`)
86
+ fs.rmSync(file)
87
+ // the folders it made, when nothing else is in them
88
+ for (const d of [path.dirname(file), path.dirname(path.dirname(file))])
89
+ if (fs.readdirSync(d).length === 0) fs.rmdirSync(d)
90
+ console.log(`opencode plugin removed from ${file}`)
91
+ }