@bigmistqke/workpad 0.0.0-stage → 0.18.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 (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +781 -2
  3. package/bin/workpad.ts +1526 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/workpad.js +1202 -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 +2121 -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 +213 -0
  103. package/dist/src/html.js +34 -0
  104. package/dist/src/hub.js +348 -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 +761 -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 +592 -0
  213. package/solid/index.tsx +80 -0
  214. package/src/agents.ts +134 -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 +166 -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 +240 -0
  251. package/src/html.ts +44 -0
  252. package/src/hub.ts +435 -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 +845 -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
package/src/ws.ts ADDED
@@ -0,0 +1,155 @@
1
+ // A WebSocket that only the server talks on: the page's live channel (/api/live). Not a server-sent
2
+ // event stream because a browser keeps at most six HTTP/1.1 connections to one origin, and every
3
+ // workpad tab is on the same one (the shared server): six open tabs, each holding its stream,
4
+ // left no connection for a seventh tab to load, nor for a form's answer to be sent. WebSockets don't
5
+ // count towards that limit.
6
+ //
7
+ // Enough of RFC 6455 for that: the handshake, text frames out, and of what comes in, close and ping
8
+ // (answered); anything else from the browser is read and dropped. A ping goes out every 25 s, so a
9
+ // connection that went away without closing is found and let go.
10
+ import crypto from 'node:crypto'
11
+ import type { IncomingMessage } from 'node:http'
12
+ import type { Duplex } from 'node:stream'
13
+
14
+ const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
15
+ const PING_EVERY = 25_000
16
+
17
+ export interface Socket {
18
+ /** send one text message; nothing once closed */
19
+ send(text: string): void
20
+ /** close it: a close frame, then the connection ends */
21
+ close(): void
22
+ /** called once, when it closed (either side, or the connection broke) */
23
+ onClose(fn: () => void): void
24
+ }
25
+
26
+ /** Is this request asking to become a WebSocket? */
27
+ export const isUpgrade = (req: IncomingMessage) =>
28
+ (req.headers.upgrade ?? '').toLowerCase() === 'websocket' && !!req.headers['sec-websocket-key']
29
+
30
+ /** Answer the handshake and give the socket; null (and the connection refused) if it isn't one. */
31
+ export function accept(req: IncomingMessage, conn: Duplex): Socket | null {
32
+ const key = req.headers['sec-websocket-key']
33
+ if (!isUpgrade(req) || typeof key !== 'string' || req.headers['sec-websocket-version'] !== '13') {
34
+ refuse(conn, 400, 'Bad Request')
35
+ return null
36
+ }
37
+ const hash = crypto
38
+ .createHash('sha1')
39
+ .update(key + GUID)
40
+ .digest('base64')
41
+ conn.write(
42
+ 'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n' +
43
+ `Sec-WebSocket-Accept: ${hash}\r\n\r\n`,
44
+ )
45
+ if ('setNoDelay' in conn && typeof conn.setNoDelay === 'function') conn.setNoDelay(true)
46
+
47
+ let open = true
48
+ const closers: (() => void)[] = []
49
+ const ended = () => {
50
+ if (!open) return
51
+ open = false
52
+ clearInterval(ping)
53
+ for (const fn of closers.splice(0)) fn()
54
+ }
55
+ const write = (opcode: number, payload: Buffer) => {
56
+ if (!open || conn.destroyed) return
57
+ conn.write(Buffer.concat([header(opcode, payload.length), payload]))
58
+ }
59
+ let alive = true
60
+ const ping = setInterval(() => {
61
+ // no pong since the last ping: it went away without closing
62
+ if (!alive) return void conn.destroy()
63
+ alive = false
64
+ write(0x9, Buffer.alloc(0))
65
+ }, PING_EVERY)
66
+ ping.unref?.()
67
+
68
+ let buf = Buffer.alloc(0)
69
+ conn.on('data', (chunk: Buffer) => {
70
+ buf = Buffer.concat([buf, chunk])
71
+ for (;;) {
72
+ const frame = parse(buf)
73
+ if (!frame) break
74
+ buf = buf.subarray(frame.size)
75
+ alive = true
76
+ if (frame.opcode === 0x8) {
77
+ write(0x8, frame.payload.subarray(0, 2))
78
+ ended()
79
+ conn.end()
80
+ return
81
+ }
82
+ if (frame.opcode === 0x9) write(0xa, frame.payload)
83
+ // a browser has nothing to say on this channel: text, binary and pongs are dropped
84
+ }
85
+ // a frame that claims to be huge: not a browser of ours
86
+ if (buf.length > 1 << 20) conn.destroy()
87
+ })
88
+ conn.on('close', ended)
89
+ conn.on('error', () => conn.destroy())
90
+
91
+ return {
92
+ send: text => write(0x1, Buffer.from(text, 'utf8')),
93
+ close() {
94
+ if (!open) return
95
+ write(0x8, Buffer.from([0x03, 0xe8])) // 1000: normal closure
96
+ ended()
97
+ conn.end()
98
+ // a peer that never closes its side
99
+ setTimeout(() => conn.destroy(), 1000).unref?.()
100
+ },
101
+ onClose(fn) {
102
+ if (open) closers.push(fn)
103
+ else fn()
104
+ },
105
+ }
106
+ }
107
+
108
+ /** Turn an upgrade down with a plain HTTP response. */
109
+ export function refuse(conn: Duplex, status: number, text: string) {
110
+ if (conn.destroyed) return
111
+ conn.end(`HTTP/1.1 ${status} ${text}\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`)
112
+ }
113
+
114
+ /** A frame's header, unmasked as the server sends them, FIN set. */
115
+ function header(opcode: number, length: number): Buffer {
116
+ if (length < 126) return Buffer.from([0x80 | opcode, length])
117
+ if (length < 1 << 16) {
118
+ const h = Buffer.alloc(4)
119
+ h[0] = 0x80 | opcode
120
+ h[1] = 126
121
+ h.writeUInt16BE(length, 2)
122
+ return h
123
+ }
124
+ const h = Buffer.alloc(10)
125
+ h[0] = 0x80 | opcode
126
+ h[1] = 127
127
+ h.writeBigUInt64BE(BigInt(length), 2)
128
+ return h
129
+ }
130
+
131
+ /** One whole frame at the start of `buf` (unmasked), or null while it hasn't all arrived. */
132
+ function parse(buf: Buffer): { opcode: number; payload: Buffer; size: number } | null {
133
+ if (buf.length < 2) return null
134
+ const opcode = buf[0]! & 0x0f
135
+ const masked = (buf[1]! & 0x80) !== 0
136
+ let length = buf[1]! & 0x7f
137
+ let at = 2
138
+ if (length === 126) {
139
+ if (buf.length < 4) return null
140
+ length = buf.readUInt16BE(2)
141
+ at = 4
142
+ } else if (length === 127) {
143
+ if (buf.length < 10) return null
144
+ const big = buf.readBigUInt64BE(2)
145
+ if (big > BigInt(1 << 20)) return { opcode: 0x8, payload: Buffer.alloc(0), size: buf.length }
146
+ length = Number(big)
147
+ at = 10
148
+ }
149
+ const mask = masked ? buf.subarray(at, at + 4) : null
150
+ if (masked) at += 4
151
+ if (buf.length < at + length) return null
152
+ const payload = Buffer.from(buf.subarray(at, at + length))
153
+ if (mask) for (let i = 0; i < payload.length; i++) payload[i] = payload[i]! ^ mask[i % 4]!
154
+ return { opcode, payload, size: at + length }
155
+ }