@bigmistqke/whiteboard 0.0.0-stage → 0.1.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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +609 -2
  3. package/bin/whiteboard.ts +431 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/whiteboard.js +471 -0
  6. package/dist/client/runtime.js +391 -0
  7. package/dist/define.js +7 -0
  8. package/dist/plugins/callout/README.md +13 -0
  9. package/dist/plugins/callout/index.js +27 -0
  10. package/dist/plugins/callout/style.css +12 -0
  11. package/dist/plugins/chat/README.md +45 -0
  12. package/dist/plugins/chat/client.js +3 -0
  13. package/dist/plugins/chat/index.js +46 -0
  14. package/dist/plugins/chat/style.css +17 -0
  15. package/dist/plugins/claude-code/index.js +120 -0
  16. package/dist/plugins/code/README.md +42 -0
  17. package/dist/plugins/code/diff.js +64 -0
  18. package/dist/plugins/code/index.js +77 -0
  19. package/dist/plugins/code/style.css +29 -0
  20. package/dist/plugins/comments/client.js +10 -0
  21. package/dist/plugins/comments/index.js +51 -0
  22. package/dist/plugins/comments/style.css +32 -0
  23. package/dist/plugins/details/README.md +17 -0
  24. package/dist/plugins/details/index.js +17 -0
  25. package/dist/plugins/details/style.css +3 -0
  26. package/dist/plugins/form/README.md +111 -0
  27. package/dist/plugins/form/index.js +102 -0
  28. package/dist/plugins/form/style.css +41 -0
  29. package/dist/plugins/gallery/README.md +30 -0
  30. package/dist/plugins/gallery/client.js +1 -0
  31. package/dist/plugins/gallery/index.js +74 -0
  32. package/dist/plugins/gallery/style.css +27 -0
  33. package/dist/plugins/grid/README.md +33 -0
  34. package/dist/plugins/grid/index.js +33 -0
  35. package/dist/plugins/grid/style.css +25 -0
  36. package/dist/plugins/index.js +26 -0
  37. package/dist/plugins/mermaid/README.md +21 -0
  38. package/dist/plugins/mermaid/index.js +34 -0
  39. package/dist/plugins/mermaid/style.css +16 -0
  40. package/dist/plugins/quiet/README.md +26 -0
  41. package/dist/plugins/quiet/index.js +17 -0
  42. package/dist/plugins/terminal/client.js +41 -0
  43. package/dist/plugins/terminal/host.js +332 -0
  44. package/dist/plugins/terminal/index.js +171 -0
  45. package/dist/plugins/terminal/modes.js +32 -0
  46. package/dist/plugins/terminal/server.js +256 -0
  47. package/dist/plugins/terminal/sizes.js +57 -0
  48. package/dist/plugins/terminal/style.css +357 -0
  49. package/dist/solid/index.js +35 -0
  50. package/dist/src/auth.js +54 -0
  51. package/dist/src/client/page/base.css +274 -0
  52. package/dist/src/client/page/main.js +1004 -0
  53. package/dist/src/config.js +76 -0
  54. package/dist/src/events.js +162 -0
  55. package/dist/src/html.js +34 -0
  56. package/dist/src/load.js +77 -0
  57. package/dist/src/loader.js +120 -0
  58. package/dist/src/package.js +33 -0
  59. package/dist/src/pages/blocks.js +49 -0
  60. package/dist/src/pages/index.js +14 -0
  61. package/dist/src/pages/markdown.js +307 -0
  62. package/dist/src/pages/render.js +257 -0
  63. package/dist/src/plugins.js +238 -0
  64. package/dist/src/running.js +24 -0
  65. package/dist/src/serve.js +71 -0
  66. package/dist/src/server.js +700 -0
  67. package/dist/src/status.js +43 -0
  68. package/package.json +131 -4
  69. package/plugins/callout/README.md +13 -0
  70. package/plugins/callout/index.ts +25 -0
  71. package/plugins/callout/style.css +12 -0
  72. package/plugins/chat/README.md +45 -0
  73. package/plugins/chat/autosize.ts +101 -0
  74. package/plugins/chat/client.tsx +81 -0
  75. package/plugins/chat/index.ts +61 -0
  76. package/plugins/chat/style.css +17 -0
  77. package/plugins/claude-code/index.ts +136 -0
  78. package/plugins/code/README.md +42 -0
  79. package/plugins/code/diff.ts +58 -0
  80. package/plugins/code/index.ts +94 -0
  81. package/plugins/code/style.css +29 -0
  82. package/plugins/comments/client.ts +448 -0
  83. package/plugins/comments/index.ts +52 -0
  84. package/plugins/comments/style.css +32 -0
  85. package/plugins/details/README.md +17 -0
  86. package/plugins/details/index.ts +21 -0
  87. package/plugins/details/style.css +3 -0
  88. package/plugins/form/README.md +111 -0
  89. package/plugins/form/index.ts +104 -0
  90. package/plugins/form/style.css +41 -0
  91. package/plugins/gallery/README.md +30 -0
  92. package/plugins/gallery/client.tsx +64 -0
  93. package/plugins/gallery/index.ts +67 -0
  94. package/plugins/gallery/style.css +27 -0
  95. package/plugins/grid/README.md +33 -0
  96. package/plugins/grid/index.ts +36 -0
  97. package/plugins/grid/style.css +25 -0
  98. package/plugins/index.ts +19 -0
  99. package/plugins/mermaid/README.md +21 -0
  100. package/plugins/mermaid/index.ts +39 -0
  101. package/plugins/mermaid/style.css +16 -0
  102. package/plugins/quiet/README.md +26 -0
  103. package/plugins/quiet/index.ts +27 -0
  104. package/plugins/terminal/client.ts +317 -0
  105. package/plugins/terminal/host.ts +326 -0
  106. package/plugins/terminal/index.ts +138 -0
  107. package/plugins/terminal/modes.ts +30 -0
  108. package/plugins/terminal/server.ts +215 -0
  109. package/plugins/terminal/sizes.ts +60 -0
  110. package/plugins/terminal/style.css +71 -0
  111. package/skills/whiteboard/SKILL.md +292 -0
  112. package/solid/index.tsx +56 -0
  113. package/src/auth.ts +66 -0
  114. package/src/client/forms.ts +186 -0
  115. package/src/client/page/base.css +274 -0
  116. package/src/client/page/fresh.ts +205 -0
  117. package/src/client/page/main.ts +249 -0
  118. package/src/client/page/orphans.ts +46 -0
  119. package/src/client/page/theme.ts +32 -0
  120. package/src/client/page/view.ts +9 -0
  121. package/src/client/page/waiting.ts +109 -0
  122. package/src/client/runtime.ts +170 -0
  123. package/src/config.ts +96 -0
  124. package/src/define.ts +546 -0
  125. package/src/events.ts +194 -0
  126. package/src/html.ts +40 -0
  127. package/src/load.ts +89 -0
  128. package/src/loader.ts +109 -0
  129. package/src/package.ts +39 -0
  130. package/src/pages/blocks.ts +67 -0
  131. package/src/pages/index.ts +36 -0
  132. package/src/pages/markdown.ts +276 -0
  133. package/src/pages/render.ts +196 -0
  134. package/src/plugins.ts +197 -0
  135. package/src/running.ts +22 -0
  136. package/src/serve.ts +52 -0
  137. package/src/server.ts +644 -0
  138. package/src/status.ts +69 -0
@@ -0,0 +1,431 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+ import { spawn } from 'node:child_process'
6
+ import http from 'node:http'
7
+ import { parseArgs } from 'node:util'
8
+ import { fileURLToPath } from 'node:url'
9
+ import { pageId, findProjectDir, project as projectAt, configFileIn, type Project } from '../src/config.ts'
10
+ import { appendEvent, read, readEvents, follow, matches, pickedUp, pick, handOut, CLAIM, type EventFilter, forAgent } from '../src/events.ts'
11
+ import { BUILTIN_COMMANDS, createConfigLoader, pluginDir } from '../src/loader.ts'
12
+ import { pluginCommands, parseCommandArgs, usage } from '../src/plugins.ts'
13
+ import { projectToken } from '../src/auth.ts'
14
+ import { packagePath } from '../src/package.ts'
15
+ import { runningServer } from '../src/running.ts'
16
+ import { statusLines, whose } from '../src/status.ts'
17
+ import type { PageStatus, WbEvent } from '../src/define.ts'
18
+
19
+ // a failing command prints its message, not a stack trace
20
+ const fail = (err: unknown) => {
21
+ console.error(`whiteboard: ${(err as Error)?.message ?? err}`)
22
+ process.exit(1)
23
+ }
24
+ process.on('uncaughtException', fail)
25
+ process.on('unhandledRejection', fail)
26
+
27
+ const HELP = `whiteboard — markdown pages in the browser, what the reader does on them as events in an ndjson log
28
+
29
+ whiteboard init [name] make this folder a project: .whiteboard/pages/
30
+ whiteboard root print where pages go (this project's .whiteboard/pages)
31
+ whiteboard new <name> create a page under a name no other page has (name, name-2, …), print its path
32
+ whiteboard show <page|file> start this project's server if needed, print the page URL
33
+ whiteboard url <page|file> the same: print the page URL
34
+ whiteboard docs [plugin] how to write pages here: markdown, and each plugin's blocks — read before writing one;
35
+ with a plugin's name, only its docs
36
+ whiteboard events [filters] print recorded events as ndjson; --follow: then each new one as it comes
37
+ whiteboard wait [filters] block until the next matching event, print it, exit
38
+ whiteboard watch [filters] like wait, but never exits: print each matching event once
39
+ whiteboard append --page <p> --type <t> [--data <json>] add an event to a page's log (e.g. a reply)
40
+ whiteboard pick <event id> record an event as picked up, as wait does when it hands one out
41
+ whiteboard status [--page <p>] per page: questions without an answer, answers no agent picked up, who listens
42
+ whiteboard serve run this project's server in the foreground
43
+ whiteboard skill [dir] print where the agent skill is, or link it into a skills folder
44
+
45
+ filters: --page <page|file> (includes pages below it) --type <type>
46
+ wait: --timeout <seconds> (exit 2 on timeout) --count <n> (default 1)
47
+ events: --since <iso time or event id> --last <n>
48
+
49
+ Every command works on the project of the current folder: the nearest folder upward with a
50
+ .whiteboard/ folder. A project needs no config: .whiteboard/config.ts only says what differs from
51
+ the defaults (markdown with the built-in plugins). Each project runs its own server; its port is in .whiteboard/server.json.
52
+ A page appends events {id, ts, page, type, action, data} to .whiteboard/events.ndjson;
53
+ which types it sends is up to its plugins (\`whiteboard docs\` says). The project's plugins
54
+ can add commands of their own; \`whiteboard help\` in a project lists them.`
55
+
56
+ const [first, ...rest] = process.argv.slice(2)
57
+ // `whiteboard --help` and `-h`, where a command goes, ask for the help as `whiteboard help` does
58
+ const cmd = first === '--help' || first === '-h' ? 'help' : first
59
+ // a plugin's command parses its own arguments
60
+ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? { values: {}, positionals: [] } : parseArgs({
61
+ args: rest,
62
+ allowPositionals: true,
63
+ options: {
64
+ page: { type: 'string' }, type: { type: 'string' }, data: { type: 'string' }, timeout: { type: 'string' }, count: { type: 'string' },
65
+ since: { type: 'string' }, last: { type: 'string' }, follow: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
66
+ },
67
+ })
68
+
69
+ const project = projectAt(findProjectDir())
70
+
71
+ /** The current project, or exit with how to make one. */
72
+ function needProject(): Project {
73
+ if (project) return project
74
+ console.error(`whiteboard: not inside a project (no .whiteboard/ folder in ${process.cwd()} or above it).
75
+ Run \`whiteboard init\` in the folder that should become one.`)
76
+ process.exit(1)
77
+ }
78
+
79
+ const filter = (): EventFilter => ({ page: opts.page ? pageId(needProject(), opts.page) : undefined, type: opts.type })
80
+
81
+ /** The running server of this project: its base URL, or null. */
82
+ const running = (proj: Project) => runningServer(proj)
83
+
84
+ /** This project's server, started in the background when it is not running. @returns its base URL */
85
+ async function ensureServer(): Promise<string> {
86
+ const proj = needProject()
87
+ const base = await running(proj)
88
+ if (base) return base
89
+ // Several commands may get here at once (an agent starting three watches, say): the one that
90
+ // creates the lock file starts the server, the others wait for it. A lock whose command is gone
91
+ // is left over, and taken over. (Should two servers still start, the server lets one survive.)
92
+ const lock = path.join(proj.wb, 'server.lock')
93
+ const claim = () => {
94
+ try { fs.writeFileSync(lock, String(process.pid), { flag: 'wx' }); return true } catch (err) {
95
+ if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err
96
+ return false
97
+ }
98
+ }
99
+ let mine = claim()
100
+ if (!mine) {
101
+ // taking a stale lock over must be exclusive too: remove it, then claim it again, so that of
102
+ // several commands finding it at once only one starts a server
103
+ let stale = false
104
+ try {
105
+ const owner = Number(fs.readFileSync(lock, 'utf8'))
106
+ try { process.kill(owner, 0) } catch (err) { stale = (err as NodeJS.ErrnoException).code === 'ESRCH' }
107
+ } catch { /* removed meanwhile */ }
108
+ if (stale) {
109
+ try { fs.unlinkSync(lock) } catch { /* another command removed it first */ }
110
+ mine = claim()
111
+ }
112
+ }
113
+ if (mine) {
114
+ const log = fs.openSync(proj.logFile, 'a')
115
+ const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'serve'], { cwd: proj.dir, detached: true, stdio: ['ignore', log, log], env: process.env })
116
+ child.unref()
117
+ }
118
+ for (let i = 0; i < 75; i++) {
119
+ await new Promise(r => setTimeout(r, 200))
120
+ const base = await running(proj)
121
+ if (base) return base
122
+ }
123
+ throw new Error(`server did not start; see ${proj.logFile}`)
124
+ }
125
+
126
+ async function api(route: string): Promise<any> {
127
+ const res = await fetch(`${await ensureServer()}${route}`)
128
+ const body = await res.json()
129
+ if (!res.ok) throw new Error(body.error ?? res.statusText)
130
+ return body
131
+ }
132
+
133
+ /**
134
+ * Tell the project's server that an agent is waiting, for as long as this command runs: pages show
135
+ * what is waited for. Holds one connection open, the listener; reconnects when the server restarts.
136
+ * Reading the log does not depend on it, so answers are never missed when the server is away.
137
+ */
138
+ function listen(f: EventFilter, command: 'wait' | 'watch') {
139
+ const connect = async () => {
140
+ let base
141
+ try { base = await ensureServer() } catch { return setTimeout(connect, 2000).unref() }
142
+ const q = new URLSearchParams({ command, ...(f.page ? { page: f.page } : {}), ...(f.type ? { type: f.type } : {}) })
143
+ let again = false
144
+ const retry = (ms: number) => { if (!again) { again = true; setTimeout(connect, ms).unref() } }
145
+ const req = http.get(`${base}/api/listen?${q}`, res => {
146
+ res.resume()
147
+ res.on('close', () => retry(1000))
148
+ })
149
+ req.on('error', () => retry(2000))
150
+ // the connection alone does not keep the command running
151
+ req.on('socket', socket => socket.unref())
152
+ }
153
+ connect()
154
+ }
155
+
156
+ function init(name: string | undefined) {
157
+ const dir = process.cwd()
158
+ const wb = path.join(dir, '.whiteboard')
159
+ if (fs.existsSync(wb)) {
160
+ console.log(`already a project: ${wb}`)
161
+ return
162
+ }
163
+ // the home folder is no repository: serving and watching all of it would be slow and expose everything
164
+ const home = dir === os.homedir()
165
+ // a name other than the folder's
166
+ const named = name && name !== path.basename(dir)
167
+ fs.mkdirSync(path.join(wb, 'pages'), { recursive: true })
168
+ // a config only for what differs from the defaults
169
+ if (named || home) fs.writeFileSync(path.join(wb, 'config.ts'), `import { defineConfig } from '@bigmistqke/whiteboard'
170
+
171
+ export default defineConfig({
172
+ ${named ? ` name: '${name}',\n` : ''}${home ? ' // only .whiteboard/ is served: this folder is not a repository\n files: false,\n' : ''}})
173
+ `)
174
+ fs.writeFileSync(path.join(wb, '.gitignore'), `# pages are working documents; remove this line to keep them in git
175
+ pages/
176
+ # events from the pages (and which ones an agent picked up), and the running server's port and output
177
+ events.ndjson
178
+ server.json
179
+ server.log
180
+ server.lock
181
+ # the secret for anything that runs code (a plugin like the terminal)
182
+ token
183
+ `)
184
+ console.log(`project: ${wb}
185
+ pages: ${path.join(wb, 'pages')} (gitignored); \`whiteboard show <page>\` starts the server
186
+ config: ${configFileIn(wb) ?? `none: the defaults (markdown with the built-in plugins); add ${path.join(wb, 'config.ts')} to change them`}`)
187
+ }
188
+
189
+ // ---- status ------------------------------------------------------------------------------------
190
+
191
+ const relFile = (file: string) => path.relative(process.cwd(), file) || file
192
+
193
+ /**
194
+ * The project's config, as the command line needs it: for its plugins (their commands, the
195
+ * session, which events reach an agent), so without the pages. Loaded once per command.
196
+ */
197
+ let loaded: ReturnType<ReturnType<typeof createConfigLoader>['config']> | null = null
198
+ const projectConfig = (proj: Project) => (loaded ??= createConfigLoader(proj, { pages: false }).config())
199
+
200
+ /**
201
+ * The agent session this command runs in, as the project's plugins know it (Claude Code's
202
+ * plugin reads it from the environment): the first one that names one. Null without any.
203
+ */
204
+ async function currentSession(proj: Project): Promise<string | null> {
205
+ try {
206
+ for (const e of (await projectConfig(proj)).plugins) {
207
+ const session = typeof e.session === 'function' ? await e.session() : null
208
+ if (session) return String(session)
209
+ }
210
+ } catch (err) { console.error(`whiteboard: which session runs this: ${(err as Error).message}`) }
211
+ return null
212
+ }
213
+
214
+
215
+ async function status() {
216
+ const proj = needProject()
217
+ const [pages, session]: [PageStatus[], string | null] = await Promise.all([
218
+ api(`/api/status${opts.page ? `?page=${encodeURIComponent(pageId(proj, opts.page))}` : ''}`),
219
+ currentSession(proj),
220
+ ])
221
+ const busy = pages.filter(p => p.unpicked.length || p.open.length)
222
+ if (!busy.length) { console.log('nothing open: every question is answered, and every answer picked up'); return }
223
+ for (const p of busy) {
224
+ console.log(`${p.page} (${whose(p, session)})`)
225
+ for (const l of statusLines(p, relFile(p.file))) console.log(` ${l}`)
226
+ }
227
+ }
228
+
229
+ switch (cmd) {
230
+ case 'serve': {
231
+ const proj = needProject()
232
+ const base = await running(proj)
233
+ if (base) { console.error(`whiteboard: ${proj.name} is already served at ${base}`); process.exit(1) }
234
+ const { start } = await import('../src/serve.ts')
235
+ await start(proj)
236
+ break
237
+ }
238
+ case 'init': {
239
+ init(positionals[0])
240
+ break
241
+ }
242
+ case 'root': {
243
+ const dir = needProject().pagesDir
244
+ fs.mkdirSync(dir, { recursive: true })
245
+ console.log(dir)
246
+ break
247
+ }
248
+ case 'new': {
249
+ // claim a page: the exclusive create fails when the file exists, so two agents asking at once
250
+ // never get the same page; the second gets name-2
251
+ const name = (positionals[0] ?? '').replace(/\\/g, '/').replace(/\.md$/, '').replace(/^\/+|\/+$/g, '')
252
+ if (!name || name.split('/').some(part => !part || part === '.' || part === '..' || part === '-' || part === '_'))
253
+ throw new Error('usage: whiteboard new <name> (a page name like plan or task/plan)')
254
+ const proj = needProject()
255
+ // a name with submits in the log stays taken after its page is deleted, so a new page never
256
+ // receives the answers of an old one
257
+ const answered = new Set(readEvents(proj.eventsFile).map(e => e.page))
258
+ for (let n = 1; ; n++) {
259
+ const id = n === 1 ? name : `${name}-${n}`
260
+ if (answered.has(id)) continue
261
+ const file = path.join(proj.pagesDir, `${id}.md`)
262
+ fs.mkdirSync(path.dirname(file), { recursive: true })
263
+ try {
264
+ fs.writeFileSync(file, '', { flag: 'wx' })
265
+ // the session that made the page: what is open on it is reported to that session
266
+ const session = await currentSession(proj)
267
+ if (session) appendEvent(proj.eventsFile, { page: id, type: CLAIM, data: { session } }, 'cli')
268
+ console.log(file)
269
+ break
270
+ } catch (err) {
271
+ if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err
272
+ }
273
+ }
274
+ break
275
+ }
276
+ case 'show':
277
+ case 'url': {
278
+ if (cmd === 'show' && !positionals[0]) throw new Error('usage: whiteboard show <page|file>')
279
+ const base = await ensureServer()
280
+ console.log(`${base}/${pageId(project, positionals[0] ?? '')}`)
281
+ break
282
+ }
283
+ case 'docs': {
284
+ // how pages are written and which plugin brings which block, then each plugin's docs (the
285
+ // syntax of its blocks, its events, its commands); `whiteboard docs <plugin>` prints only that one
286
+ const info = await api('/api/docs')
287
+ for (const e of info.errors) console.error(`config error: ${e}`)
288
+ const only = positionals[0]
289
+ const names = (info.plugins ?? []).map((x: { name: string }) => x.name)
290
+ if (only && !names.includes(only)) throw new Error(`no plugin named "${only}" here: ${names.join(', ')}`)
291
+ const shown = (x: { name: string }) => !only || x.name === only
292
+ if (!only) console.log(info.pages ? `${info.pages.trim()}\n` : 'The config failed to load, so pages show as their raw text.\n')
293
+ for (const e of (info.plugins ?? []).filter(shown)) {
294
+ console.log(`<!-- plugin: ${e.name} -->\n# Plugin: ${e.name}\n`)
295
+ if (e.error) console.log(`It failed to load: ${e.error}\n`)
296
+ if (e.docs) console.log(`${e.docs.trim()}\n`)
297
+ if (e.events?.length) {
298
+ console.log('Events it writes (handed out: a `wait` or `watch` on the page gets them, and `status` counts them; the others only when asked for by type):\n')
299
+ for (const v of e.events) console.log(`- \`${v.type}\`${v.handOut ? ' (handed out)' : ''}${v.description ? `: ${v.description}` : ''}`)
300
+ console.log()
301
+ }
302
+ for (const c of e.commands) console.log(`- \`whiteboard ${[c.name, c.usage].filter(Boolean).join(' ')}\`: ${c.description}`)
303
+ if (e.routes.length) console.log(`\nRoutes (\`auth\`: needs the project's token, header \`x-whiteboard-token\`):\n`)
304
+ for (const r of e.routes) {
305
+ const takes = [r.body && `body ${JSON.stringify(r.body)}`, r.query && `query ${JSON.stringify(r.query)}`, r.stream && 'server-sent events'].filter(Boolean).join(', ')
306
+ console.log(`- \`${r.method} ${r.path}\`${r.auth ? ' (auth)' : ''}: ${r.description}${takes ? ` (${takes})` : ''}`)
307
+ }
308
+ console.log()
309
+ }
310
+ break
311
+ }
312
+ case 'events': {
313
+ // the log as it is: every matching event, also the agent's own, and nothing marked as picked up
314
+ const f = filter()
315
+ const log = needProject().eventsFile
316
+ const { events, end } = read(log)
317
+ let list = events.filter(e => matches(e, f))
318
+ if (opts.since) {
319
+ const i = list.findIndex(e => e.id === opts.since)
320
+ const since = opts.since
321
+ list = i >= 0 ? list.slice(i + 1) : list.filter(e => e.ts > since)
322
+ }
323
+ if (opts.last) list = list.slice(-Number(opts.last))
324
+ for (const e of list) console.log(JSON.stringify(e))
325
+ if (opts.follow) follow(log, end, e => { if (matches(e, f)) console.log(JSON.stringify(e)) })
326
+ break
327
+ }
328
+ case 'pick': {
329
+ // what a wait does when it hands an event out, for a script that hands out events itself
330
+ const proj = needProject()
331
+ const id = positionals[0]
332
+ if (!id) throw new Error('usage: whiteboard pick <event id>')
333
+ const events = readEvents(proj.eventsFile)
334
+ const event = events.find(e => e.id === id)
335
+ if (!event) throw new Error(`no event ${id} in ${proj.eventsFile}`)
336
+ if (pickedUp(events).has(id)) { console.error(`whiteboard: ${id} was picked up already`); break }
337
+ console.log(JSON.stringify(pick(proj.eventsFile, event)))
338
+ break
339
+ }
340
+ case 'wait':
341
+ case 'watch': {
342
+ // Each answer once, also one given before the command started, never the agent's own; of the
343
+ // plugins' events, those they declare for an agent (see handOut). `wait` stops after --count
344
+ // events (default 1); `watch` never does.
345
+ const proj = needProject()
346
+ const f = filter()
347
+ const { handedOut } = await projectConfig(proj)
348
+ handOut(proj.eventsFile, f, e => console.log(JSON.stringify(e)), { count: cmd === 'wait' ? Number(opts.count ?? 1) : Infinity, forAgent: forAgent(handedOut) })
349
+ .then(() => process.exit(0))
350
+ listen(f, cmd)
351
+ if (opts.timeout && cmd === 'wait') setTimeout(() => { console.error('timeout'); process.exit(2) }, Number(opts.timeout) * 1000)
352
+ break
353
+ }
354
+ case 'append': {
355
+ // the agent's side of the log: anything a page's plugins understand, such as a reply to a
356
+ // comment. Waits skip what is appended here, so an agent does not hear its own events.
357
+ const proj = needProject()
358
+ if (!opts.page || !opts.type) throw new Error("usage: whiteboard append --page <page|file> --type <type> [--data '<json>']")
359
+ let data = {}
360
+ if (opts.data) {
361
+ try { data = JSON.parse(opts.data) } catch { throw new Error('--data must be JSON, e.g. \'{"text":"…"}\'') }
362
+ }
363
+ console.log(JSON.stringify(appendEvent(proj.eventsFile, { page: pageId(proj, opts.page), type: opts.type, data }, 'cli')))
364
+ break
365
+ }
366
+ case 'status':
367
+ await status()
368
+ break
369
+ case 'skill': {
370
+ // the agent skill ships in this package; link it into whatever folder an agent reads skills from
371
+ const source = packagePath('skills', 'whiteboard')
372
+ if (!positionals[0]) { console.log(source); break }
373
+ const target = path.join(path.resolve(positionals[0].replace(/^~(?=$|\/)/, os.homedir())), 'whiteboard')
374
+ let existing = null
375
+ try { existing = fs.lstatSync(target) } catch {}
376
+ if (existing) {
377
+ if (existing.isSymbolicLink() && path.resolve(path.dirname(target), fs.readlinkSync(target)) === source) {
378
+ console.log(`already linked: ${target} -> ${source}`)
379
+ break
380
+ }
381
+ console.error(`whiteboard: ${target} already exists; remove it first to link the skill there`)
382
+ process.exit(1)
383
+ }
384
+ fs.mkdirSync(path.dirname(target), { recursive: true })
385
+ fs.symlinkSync(source, target)
386
+ console.log(`linked: ${target} -> ${source}`)
387
+ break
388
+ }
389
+ default: {
390
+ // `whiteboard <plugin> [sub] …`: a command of one of the project's plugins
391
+ const commands = project ? await projectCommands(project) : []
392
+ const mine = commands.filter(c => c.plugin === cmd)
393
+ const found = mine.find(c => c.sub && c.sub === rest[0]) ?? mine.find(c => !c.sub)
394
+ if (found && project) {
395
+ const args = found.sub ? rest.slice(1) : rest
396
+ const { options, positionals, rest: after } = parseCommandArgs(found.command, args, found.name)
397
+ await found.command.run({
398
+ options,
399
+ positionals,
400
+ rest: after,
401
+ project: { name: project.name, dir: project.dir, wb: project.wb },
402
+ eventsFile: project.eventsFile,
403
+ dataDir: pluginDir(project.wb, found.plugin),
404
+ token: projectToken(project.wb),
405
+ server: ensureServer,
406
+ pagePath: page => `/${pageId(project, page ?? '')}`,
407
+ status: async page => api(`/api/status${page ? `?page=${encodeURIComponent(pageId(project, page))}` : ''}`),
408
+ handOut: async (filter, onEvent, options) => handOut(project.eventsFile, { ...filter, page: filter.page ? pageId(project, filter.page) : null }, onEvent, { ...options, forAgent: forAgent((await projectConfig(project)).handedOut) }),
409
+ authLink: async to => `${await ensureServer()}/_/auth?token=${encodeURIComponent(projectToken(project.wb))}&to=${encodeURIComponent(to)}`,
410
+ })
411
+ break
412
+ }
413
+ // asked for, the help goes to standard output; after a command it doesn't know, to standard error
414
+ const asked = !cmd || cmd === 'help' || opts.help
415
+ const print = asked ? console.log : console.error
416
+ print(HELP)
417
+ if (commands.length) {
418
+ print(`\nfrom this project's plugins:\n`)
419
+ for (const c of commands) print(` whiteboard ${[c.name, usage(c.command)].filter(Boolean).join(' ')}\n ${c.command.description}`)
420
+ }
421
+ if (mine.length) console.error(`\nwhiteboard: ${cmd} has no command ${JSON.stringify(rest[0] ?? '')}`)
422
+ if (!asked) process.exit(1)
423
+ }
424
+ }
425
+
426
+ /** The commands the project's plugins add: `whiteboard <plugin> [sub]`. */
427
+ async function projectCommands(proj: Project) {
428
+ const { plugins, errors } = await projectConfig(proj)
429
+ for (const e of errors) console.error(`whiteboard: config error: ${(e as Error).message}`)
430
+ return plugins.flatMap(pluginCommands)
431
+ }
@@ -0,0 +1,5 @@
1
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js
2
+ function _taggedTemplateLiteral(e, t) {
3
+ return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
4
+ }
5
+ export { _taggedTemplateLiteral as default };