@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
@@ -0,0 +1,64 @@
1
+ import { identity, stopReminder, workpadCommand } from "../../src/agents.js";
2
+ import { channel } from "./channel.js";
3
+ import { shimSource } from "./shim.js";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ // plugins/opencode/index.ts
7
+ const session = () => process.env.OPENCODE_SESSION_ID || null;
8
+ function opencode() {
9
+ return {
10
+ name: "opencode",
11
+ session,
12
+ commands: {
13
+ hook: {
14
+ description: "what the opencode plugin runs when a turn ends: what is left on the session's pages (JSON, nothing when nothing is)",
15
+ args: "stop",
16
+ async run(ctx) {
17
+ if (ctx.positionals[0] !== "stop") throw new Error("usage: workpad opencode hook stop");
18
+ try {
19
+ const left = await stopReminder(ctx, identity(session()));
20
+ if (left) console.log(JSON.stringify(left));
21
+ } catch (err) {
22
+ console.error(`workpad opencode hook stop: ${err.message}`);
23
+ }
24
+ }
25
+ },
26
+ channel: {
27
+ description: "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",
28
+ run: channel
29
+ },
30
+ install: {
31
+ description: "write the plugin opencode loads for this project: .opencode/plugins/workpad.js",
32
+ run: (ctx) => install(ctx.project.dir)
33
+ },
34
+ uninstall: {
35
+ description: "remove the plugin opencode loads for this project again",
36
+ run: (ctx) => uninstall(ctx.project.dir)
37
+ }
38
+ }
39
+ };
40
+ }
41
+ const shimFile = (dir) => path.join(dir, ".opencode", "plugins", "workpad.js");
42
+ /** The first line of the file this plugin writes, so it removes only its own. */
43
+ const OURS = "// Installed by `workpad opencode install`";
44
+ function install(dir) {
45
+ const file = shimFile(dir);
46
+ const source = shimSource(workpadCommand(dir));
47
+ if (fs.existsSync(file)) {
48
+ const now = fs.readFileSync(file, "utf8");
49
+ if (!now.startsWith(OURS)) throw new Error(`${file} is not workpad's; move it out of the way first`);
50
+ if (now === source) return console.log(`opencode plugin already installed: ${file}`);
51
+ }
52
+ fs.mkdirSync(path.dirname(file), { recursive: true });
53
+ fs.writeFileSync(`${file}.tmp`, source);
54
+ fs.renameSync(`${file}.tmp`, file);
55
+ console.log(`opencode plugin written to ${file}; opencode loads it when it starts in this project`);
56
+ }
57
+ function uninstall(dir) {
58
+ const file = shimFile(dir);
59
+ if (!fs.existsSync(file) || !fs.readFileSync(file, "utf8").startsWith(OURS)) return console.log(`no workpad opencode plugin at ${file}`);
60
+ fs.rmSync(file);
61
+ for (const d of [path.dirname(file), path.dirname(path.dirname(file))]) if (fs.readdirSync(d).length === 0) fs.rmdirSync(d);
62
+ console.log(`opencode plugin removed from ${file}`);
63
+ }
64
+ export { opencode as default };
@@ -0,0 +1,150 @@
1
+ import { ANSWERS_NOTE } from "../../src/agents.js";
2
+ // plugins/opencode/shim.ts
3
+ /** The plugin's source, running workpad as `command` (`['npx', '@bigmistqke/workpad']`). */
4
+ const shimSource = (command) => `// Installed by \`workpad opencode install\`, which writes it again; \`workpad opencode uninstall\` removes it.
5
+ // It brings the reader's answers on this opencode session's workpad pages into it, and sends a
6
+ // turn that ends with something left on them on once. See the opencode plugin of @bigmistqke/workpad.
7
+ import { spawn } from 'node:child_process'
8
+ import readline from 'node:readline'
9
+
10
+ const WORKPAD = ${JSON.stringify(command)}
11
+ const MARK = '[workpad]'
12
+ const ANSWERS_NOTE = ${JSON.stringify(ANSWERS_NOTE)}
13
+
14
+ export const Workpad = async ({ client, directory }) => {
15
+ const env = session => ({ ...process.env, ...(session ? { OPENCODE_SESSION_ID: session } : {}) })
16
+
17
+ /** Run a workpad opencode command for a session: what it printed ('' when it failed). */
18
+ const run = (args, session) =>
19
+ new Promise(resolve => {
20
+ const child = spawn(WORKPAD[0], [...WORKPAD.slice(1), 'opencode', ...args], {
21
+ cwd: directory,
22
+ env: env(session),
23
+ stdio: ['ignore', 'pipe', 'ignore'],
24
+ })
25
+ let out = ''
26
+ child.stdout.on('data', d => (out += d))
27
+ child.on('error', () => resolve(''))
28
+ child.on('close', code => resolve(code === 0 ? out.trim() : ''))
29
+ })
30
+
31
+ const known = new Set() // sessions the channel follows
32
+ const busy = new Set() // sessions in a turn
33
+ const sentOn = new Set() // sessions a reminder sent on, until the reader writes again
34
+ const last = new Map() // the agent and model the reader last used, per session
35
+ const held = new Map() // answers waiting for their session to be idle
36
+
37
+ // the channel: one for this process, started on the first session there is
38
+ let channel = null
39
+ const tell = msg => channel?.stdin.write(JSON.stringify(msg) + '\\n')
40
+ const follow = session => {
41
+ if (!session || known.has(session)) return
42
+ known.add(session)
43
+ if (!channel) {
44
+ channel = spawn(WORKPAD[0], [...WORKPAD.slice(1), 'opencode', 'channel'], {
45
+ cwd: directory,
46
+ env: env(),
47
+ stdio: ['pipe', 'pipe', 'ignore'],
48
+ })
49
+ channel.on('error', () => (channel = null))
50
+ readline.createInterface({ input: channel.stdout }).on('line', line => {
51
+ let answer
52
+ try {
53
+ answer = JSON.parse(line)
54
+ } catch {
55
+ return
56
+ }
57
+ if (!answer.session) return
58
+ held.set(answer.session, [...(held.get(answer.session) ?? []), answer])
59
+ if (!busy.has(answer.session)) void bring(answer.session)
60
+ })
61
+ for (const s of known) tell({ follow: s })
62
+ return
63
+ }
64
+ tell({ follow: session })
65
+ }
66
+
67
+ /** Send the session a message of the plugin's own; whether it went in. */
68
+ const send = async (session, text) => {
69
+ const { agent, model } = last.get(session) ?? {}
70
+ try {
71
+ const r = await client.session.promptAsync({
72
+ path: { id: session },
73
+ body: { ...(agent ? { agent } : {}), ...(model ? { model } : {}), parts: [{ type: 'text', text: MARK + ' ' + text }] },
74
+ })
75
+ return !r?.error
76
+ } catch {
77
+ return false
78
+ }
79
+ }
80
+
81
+ /** The answers held for an idle session, as one message; whether there were any. */
82
+ const bring = async session => {
83
+ const answers = held.get(session)
84
+ if (!answers?.length) return false
85
+ held.delete(session)
86
+ busy.add(session)
87
+ const pongs = answers.filter(a => a.pong)
88
+ const real = answers.filter(a => !a.pong)
89
+ const text = [
90
+ ...pongs.map(a => a.text),
91
+ ...(real.length
92
+ ? ['The reader answered on your workpad pages (received already):', ...real.map(a => '- ' + a.text), ANSWERS_NOTE]
93
+ : []),
94
+ ].join('\\n')
95
+ if (await send(session, text)) {
96
+ if (real.length) tell({ session, received: real.map(a => a.id) })
97
+ } else held.set(session, [...answers, ...(held.get(session) ?? [])])
98
+ return true
99
+ }
100
+
101
+ const toast = message =>
102
+ client.tui?.showToast?.({ body: { message, variant: 'info' } }).catch?.(() => {})
103
+
104
+ return {
105
+ 'shell.env': async (input, output) => {
106
+ if (!input.sessionID) return
107
+ output.env.OPENCODE_SESSION_ID = input.sessionID
108
+ busy.add(input.sessionID)
109
+ follow(input.sessionID)
110
+ },
111
+
112
+ 'chat.message': async (input, output) => {
113
+ const session = input.sessionID
114
+ if (input.agent || input.model) last.set(session, { agent: input.agent, model: input.model })
115
+ busy.add(session)
116
+ if (output.parts.some(p => p.type === 'text' && p.text?.startsWith(MARK))) return
117
+ sentOn.delete(session)
118
+ follow(session)
119
+ },
120
+
121
+ event: async ({ event }) => {
122
+ const session = event.properties?.sessionID
123
+ if (!session) return
124
+ // a turn ends: opencode says so twice (session.status idle, session.idle), once is acted on
125
+ const idle =
126
+ event.type === 'session.idle' || (event.type === 'session.status' && event.properties.status?.type === 'idle')
127
+ if (event.type === 'session.status' && !idle) return void busy.add(session)
128
+ if (!idle || !busy.has(session)) return
129
+ busy.delete(session)
130
+ if (!known.has(session)) return
131
+ // pages it made this turn: the channel looks for them now, not at its next round
132
+ tell({ follow: session })
133
+ if (await bring(session)) return
134
+ const left = await run(['hook', 'stop'], session)
135
+ if (!left || busy.has(session)) return
136
+ let said
137
+ try {
138
+ said = JSON.parse(left)
139
+ } catch {
140
+ return
141
+ }
142
+ if (sentOn.has(session)) return void toast(said.shown)
143
+ sentOn.add(session)
144
+ busy.add(session)
145
+ if (!(await send(session, said.reason))) busy.delete(session)
146
+ },
147
+ }
148
+ }
149
+ `;
150
+ export { shimSource };
@@ -0,0 +1,26 @@
1
+ Content that is never marked as new. Changed blocks get a red bar until the
2
+ reader has seen them; what is inside `quiet` does not count as a change. Use
3
+ it for what changes without being news to the reader: repeating back what
4
+ they answered, a status line, a timestamp. Anything with substance (an
5
+ explanation, a question back, a different reading of their answer) belongs
6
+ outside it, so it is marked.
7
+
8
+ A whole block, a line, or a few words:
9
+
10
+ ```markdown
11
+ :::quiet
12
+ Decided: **this week**, as you answered.
13
+ :::
14
+
15
+ ::quiet[Last checked 12:04]
16
+
17
+ The build is green :quiet[(as of 12:04)].
18
+ ```
19
+
20
+ Inside a larger block, such as a card, only the quiet part is ignored: other
21
+ changes in the block still mark it. Hand-written HTML can do the same with a
22
+ `data-wp-quiet` attribute.
23
+
24
+ :::quiet
25
+ This block is quiet: editing it never marks it as new.
26
+ :::
@@ -0,0 +1,23 @@
1
+ import fs from "node:fs";
2
+ import { definePlugin, html, raw } from "@bigmistqke/workpad";
3
+ // plugins/quiet/index.ts
4
+ async function render(ctx) {
5
+ const label = ctx.label && raw(ctx.label);
6
+ if (ctx.kind === "textDirective") return html`<span data-wp-quiet>${label}</span>`;
7
+ if (ctx.kind === "leafDirective") return html`<div data-wp-quiet>${label && html`<p>${label}</p>`}</div>`;
8
+ return html`<div data-wp-quiet>${raw(await ctx.toHtml(ctx.children))}</div>`;
9
+ }
10
+ function quiet() {
11
+ return definePlugin({
12
+ name: "quiet",
13
+ blocks: { quiet: {
14
+ menu: {
15
+ group: "mark",
16
+ summary: "not news: an echo of an answer, a timestamp"
17
+ },
18
+ html: render
19
+ } },
20
+ docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
21
+ });
22
+ }
23
+ export { quiet as default, render };
@@ -0,0 +1,44 @@
1
+ One pane, its items as tabs, one showing at a time: an A/B, versions of a
2
+ design, the parts of an answer, a before and an after. It is a window, so ⤢
3
+ fills the browser window with it.
4
+
5
+ Each item is an `:::item[Title]` container, its label the tab's label;
6
+ without a label it is untitled, and its tab is its number. Inside an item,
7
+ headings of any level are its content. The tabs take one colon more than
8
+ their items: `::::tabs` around `:::item`. A `:::form[Title]` or a
9
+ `:::details[Title]` directly in it is an item as it is, its label the tab.
10
+ A row of tabs too long for the header scrolls sideways; ‹ › step through
11
+ the items, and so do ← and → when the block has the focus (a click in it)
12
+ or fills the window.
13
+
14
+ The items are laid over each other, so the pane is as tall as the tallest
15
+ and switching doesn't move the page. Which item shows stays when the page
16
+ updates, even when an item is added before it.
17
+
18
+ A link to an item, `#tab:<its title as a slug>` (`#tab:switch-the-reads`;
19
+ a badge or a `:when` in the title is not in it), or `#tab:<its number>` for an
20
+ untitled one, shows that item.
21
+
22
+ Attributes: `wide`, `height`.
23
+
24
+ ```markdown
25
+ ::::tabs[Two headers]
26
+ :::item[A]
27
+ The label on the left, the buttons on the right.
28
+ :::
29
+
30
+ :::item[B]
31
+ Everything centred.
32
+ :::
33
+ ::::
34
+ ```
35
+
36
+ ::::tabs[Two headers]
37
+ :::item[A]
38
+ The label on the left, the buttons on the right.
39
+ :::
40
+
41
+ :::item[B]
42
+ Everything centred.
43
+ :::
44
+ ::::
@@ -0,0 +1,75 @@
1
+ import { builtinPublic } from "../../src/package.js";
2
+ import fs from "node:fs";
3
+ import { definePlugin, html, raw, slugText, windowFrame } from "@bigmistqke/workpad";
4
+ // plugins/tabs/index.ts
5
+ /** A height in px (a bare number) or a CSS length; else none. */
6
+ const height = (value) => value && /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value) ? value : void 0;
7
+ const svg = (d) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`);
8
+ const PREV = svg("M10 3.5 5.5 8l4.5 4.5");
9
+ const NEXT = svg("M6 3.5 10.5 8 6 12.5");
10
+ async function render(ctx) {
11
+ const items = await ctx.items();
12
+ const ids = items.map((item, i) => ctx.anchor("tab", item.text ? slugText(item.text) : String(i + 1), { numbered: true }));
13
+ const tabs = items.map((item, i) => html`<button
14
+ type="button"
15
+ role="tab"
16
+ class="wp-tabs-tab"
17
+ ${ids[i] ? html`id="wp-${ids[i]}" aria-controls="${ids[i]}"` : ""}
18
+ aria-selected="${i === 0 ? "true" : "false"}"
19
+ tabindex="${i === 0 ? "0" : "-1"}"
20
+ data-tabs="${String(i)}"
21
+ >
22
+ ${item.title ? raw(item.title) : String(i + 1)}
23
+ </button>`);
24
+ const controls = html`<span class="wp-tabs-nav">
25
+ <button
26
+ type="button"
27
+ class="wp-window-button wp-tabs-prev"
28
+ data-tabs="prev"
29
+ title="Previous (←)"
30
+ aria-label="Previous"
31
+ >
32
+ ${PREV}
33
+ </button>
34
+ <span class="wp-tabs-list" role="tablist" ${ctx.label ? html`aria-label="${ctx.label}"` : ""}>${tabs}</span>
35
+ <button type="button" class="wp-window-button wp-tabs-next" data-tabs="next" title="Next (→)" aria-label="Next">
36
+ ${NEXT}
37
+ </button>
38
+ </span>`;
39
+ const body = html`<div class="wp-tabs" tabindex="0">
40
+ ${items.map((item, i) => html`<section
41
+ class="wp-tabs-item"
42
+ role="tabpanel"
43
+ data-key="${item.key}"
44
+ ${ids[i] ? html`id="${ids[i]}" aria-labelledby="wp-${ids[i]}"` : ""}
45
+ >
46
+ ${raw(item.html)}
47
+ </section>`)}
48
+ </div>`;
49
+ return windowFrame({
50
+ label: ctx.label,
51
+ className: "wp-tabs-window",
52
+ controls,
53
+ wide: "wide" in ctx.attrs,
54
+ height: height(ctx.attrs.height),
55
+ body
56
+ });
57
+ }
58
+ function tabs() {
59
+ return definePlugin({
60
+ name: "tabs",
61
+ public: builtinPublic("tabs"),
62
+ style: "style.css",
63
+ setup: () => ({ client: "client.js" }),
64
+ blocks: { tabs: {
65
+ attrs: ["wide", "height"],
66
+ html: render,
67
+ menu: {
68
+ group: "arrange",
69
+ summary: "one at a time: versions, A/B, per harness"
70
+ }
71
+ } },
72
+ docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
73
+ });
74
+ }
75
+ export { tabs as default, render };
@@ -0,0 +1 @@
1
+ const e=()=>[...document.querySelectorAll(`#wp-main .wp-tabs-window`)],t=e=>[...e.querySelectorAll(`:scope > .wp-window-body > .wp-tabs > .wp-tabs-item`)],n=e=>[...e.querySelectorAll(`:scope > .wp-window-bar .wp-tabs-tab`)],r=/* @__PURE__ */ new Map;function i(e,n){let i=r.get(n);if(!i)return 0;let a=i.key?t(e).findIndex(e=>e.dataset.key===i.key):-1;return a>=0?a:i.index}function a(e,i,a,o=!1){let s=t(e),c=Math.max(s.length,1);a=Math.min(Math.max(a,0),c-1),r.set(i,{key:s[a]?.dataset.key??null,index:a}),e.setAttribute(`data-wp-tab`,String(a)),s.forEach((e,t)=>e.toggleAttribute(`data-wp-current`,t===a));let l=n(e);l.forEach((e,t)=>{e.setAttribute(`aria-selected`,String(t===a)),e.tabIndex=t===a?0:-1});let u=l[a],d=u?.parentElement;u&&d&&(u.offsetLeft<d.scrollLeft?d.scrollLeft=u.offsetLeft:u.offsetLeft+u.offsetWidth>d.scrollLeft+d.clientWidth&&(d.scrollLeft=u.offsetLeft+u.offsetWidth-d.clientWidth)),o&&l[a]?.focus(),e.toggleAttribute(`data-wp-first`,a===0),e.toggleAttribute(`data-wp-last`,a===c-1)}const o=()=>e().forEach((e,t)=>a(e,t,i(e,t)));function s(t,n,r=!1){let o=e().indexOf(t);if(o<0)return;let s=i(t,o);a(t,o,n===`prev`?s-1:n===`next`?s+1:n,r)}const c=e=>!!e?.closest?.(`input, textarea, select, [contenteditable]:not([contenteditable="false"])`);let l=!1;const u=(e,n,r)=>{o(),r.onRendered(o),l||(l=!0,document.addEventListener(`click`,e=>{let t=e.target.closest?.(`[data-tabs]`),n=t?.closest(`.wp-tabs-window`);if(!t||!n)return;let r=t.dataset.tabs;s(n,r===`prev`||r===`next`?r:Number(r))}),document.addEventListener(`wp-reveal`,e=>{let n=e.target.closest?.(`.wp-tabs-item`),r=n?.closest(`.wp-tabs-window`);n&&r&&s(r,t(r).indexOf(n))}),document.addEventListener(`keydown`,e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target;if(c(t))return;let n=t.closest?.(`.wp-tabs-window`)??document.querySelector(`#wp-main .wp-tabs-window[data-wp-maximized]`);n&&(e.preventDefault(),s(n,e.key===`ArrowLeft`?`prev`:`next`,t.matches?.(`[role=tab]`)))}))};export{u as default};
@@ -0,0 +1,98 @@
1
+ /* Tabs (index.ts): the items over each other in one grid cell, so the pane is as tall as the
2
+ tallest; one shows. Before the browser marks one (data-wp-tab), the first. */
3
+ .wp-tabs {
4
+ display: grid;
5
+ outline: none;
6
+ }
7
+ .wp-tabs:focus-visible {
8
+ box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
9
+ }
10
+ .wp-tabs > .wp-tabs-item {
11
+ grid-area: 1 / 1;
12
+ min-width: 0;
13
+ }
14
+ .wp-tabs > .wp-tabs-item > :first-child {
15
+ margin-top: 0;
16
+ }
17
+ .wp-tabs > .wp-tabs-item > :last-child {
18
+ margin-bottom: 0;
19
+ }
20
+ .wp-tabs-window:not([data-wp-tab]) > .wp-window-body > .wp-tabs > .wp-tabs-item:not(:first-child),
21
+ .wp-tabs-window[data-wp-tab] > .wp-window-body > .wp-tabs > .wp-tabs-item:not([data-wp-current]) {
22
+ visibility: hidden;
23
+ }
24
+
25
+ /* the header: ‹ A B C › ; the tabs share the bar with the label, and a row too long scrolls
26
+ sideways between ‹ and ›, its scrollbar hidden (the arrows and ← → step through it) */
27
+ .wp-tabs-nav {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: var(--space-2xs);
31
+ flex: 0 1 auto;
32
+ min-width: 0;
33
+ }
34
+ .wp-tabs-list {
35
+ /* positioned: its tabs' offsetLeft is measured from it (client.ts scrolls the one showing in) */
36
+ position: relative;
37
+ display: flex;
38
+ gap: var(--space-2xs);
39
+ min-width: 0;
40
+ overflow-x: auto;
41
+ scrollbar-width: none;
42
+ }
43
+ .wp-tabs-list::-webkit-scrollbar {
44
+ display: none;
45
+ }
46
+ .wp-tabs-tab {
47
+ flex: none;
48
+ font: var(--ui-tiny) / 1 var(--sans);
49
+ font-variant-numeric: tabular-nums;
50
+ color: var(--muted);
51
+ background: none;
52
+ border: var(--hairline) solid transparent;
53
+ border-radius: var(--radius-pill);
54
+ padding: var(--space-xs) var(--space-md);
55
+ cursor: pointer;
56
+ white-space: nowrap;
57
+ }
58
+ .wp-tabs-tab > * {
59
+ margin: 0;
60
+ }
61
+ .wp-tabs-tab:hover {
62
+ color: var(--text);
63
+ background: color-mix(in srgb, var(--text) var(--tint-faint), transparent);
64
+ }
65
+ .wp-tabs-tab:focus-visible {
66
+ outline: 2px solid color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
67
+ outline-offset: -2px;
68
+ }
69
+ .wp-tabs-tab[aria-selected='true'] {
70
+ color: var(--accent);
71
+ border-color: color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
72
+ background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
73
+ }
74
+ .wp-tabs-window:not([data-wp-tab]) > .wp-window-bar .wp-tabs-prev,
75
+ .wp-tabs-window[data-wp-first] > .wp-window-bar .wp-tabs-prev,
76
+ .wp-tabs-window[data-wp-last] > .wp-window-bar .wp-tabs-next {
77
+ opacity: 0.35;
78
+ pointer-events: none;
79
+ }
80
+
81
+ /* a badge ending a tab's label: after it, on its line (the renderer puts it first, for a title's
82
+ float, base.css: a tab is one line, never wrapping) */
83
+ .wp-tabs-tab:has(> .wp-title-end) {
84
+ display: inline-flex;
85
+ align-items: center;
86
+ gap: var(--space-xs);
87
+ }
88
+ .wp-tabs-tab > .wp-title-end {
89
+ float: none;
90
+ order: 1;
91
+ height: auto;
92
+ margin: 0;
93
+ }
94
+
95
+ /* a form that is an item: its tab is its title, not shown again over it */
96
+ .wp-tabs-item > form.wp-form > .wp-form-title {
97
+ display: none;
98
+ }
@@ -0,0 +1,63 @@
1
+ # A terminal on every page
2
+
3
+ The terminal is a plugin: add it to the config.
4
+
5
+ ```ts
6
+ import terminal from '@bigmistqke/workpad/terminal'
7
+
8
+ export default defineConfig({
9
+ plugins: [terminal()],
10
+ })
11
+ ```
12
+
13
+ `workpad terminal` prints a link that unlocks a terminal drawer at the
14
+ bottom of every page of the project, in that browser. Collapsed it's a bar;
15
+ open, it shows a terminal with tabs. Each tab is a session in a
16
+ pseudo-terminal, in a small host process of its own that the server starts.
17
+ So the sessions outlive the browser tab (switching pages, reloading or
18
+ opening a second browser tab shows the same ones) and the server: a
19
+ restarted server finds them where they were. The browser morphs the drawer
20
+ from one page into the next (a view transition across the page load), and
21
+ the server writes the current screens into each page, so it never shows
22
+ empty. Ctrl+\` opens and closes it.
23
+
24
+ Several browser windows can show the same tab. A tab has one size, the
25
+ size of the window you used last (opened the drawer, clicked or typed in
26
+ it); the others show it at that size, with a margin or cut off at the right,
27
+ until you use them.
28
+
29
+ Every tab is your shell. The tabs sit at the bar's right, "+" at its end
30
+ opens one, and "×" closes a tab and ends what runs in it. A tab started with
31
+ a program runs it inside your shell, and the shell takes over when it exits:
32
+ leaving `claude` leaves a prompt in the same tab, not a dead one. A tab whose
33
+ shell exited offers to start it again, as it was.
34
+
35
+ ```sh
36
+ workpad terminal [page] # the link that opens the drawer in this browser
37
+ workpad terminal --new # a new tab with the shell
38
+ workpad terminal -- <program> … # run a program in a new tab: -- claude --resume <id>
39
+ workpad terminal open <page> # show a page where the drawer you used last is
40
+ workpad terminal stop # end every tab and their host
41
+ ```
42
+
43
+ An agent can show you a page: `workpad terminal open <page>` takes the
44
+ browser tab whose drawer you used last to that page, and the drawer comes
45
+ along. A program in a tab knows which tab it runs in (`WORKPAD_TERMINAL`)
46
+ and opens it where that tab's drawer is; without it, where you were last.
47
+
48
+ The terminal runs code, so it needs the project's token: `.workpad/token`,
49
+ made on first use and gitignored. The link (`/_/auth`) sets it as a cookie
50
+ that is only sent from the project's own pages, and requests from another
51
+ origin are refused. Any plugin can ask the core whether a request has it.
52
+
53
+ It needs `node-pty`, an optional dependency; without it the drawer says what
54
+ to install. The host listens on `.workpad/terminal/host.sock`, readable
55
+ by its owner only, and leaves ten minutes after the last tab's program ended.
56
+
57
+ The token keeps other websites out, not agents: it is in the project, and so
58
+ is the config the server runs. **workpad runs with the rights of whoever
59
+ started its server, and adds none**, so start the server where your agents
60
+ run. If they run in a sandbox, start it from inside that sandbox (an agent
61
+ running `workpad show` does); the terminal and everything else it starts
62
+ are then boxed in the same way. A server started outside the sandbox lets an
63
+ agent reach past it, through the terminal or simply by editing `config.ts`.