@bigmistqke/whiteboard 0.3.1 → 0.5.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.
- package/README.md +119 -18
- package/bin/whiteboard.ts +300 -71
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +132 -54
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +7 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +12 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +99 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/auth.js +2 -1
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +188 -39
- package/dist/src/loader.js +14 -3
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +106 -20
- package/dist/src/pages/window.js +31 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +251 -23
- package/package.json +5 -2
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +33 -21
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +20 -1
- package/plugins/mermaid/index.ts +7 -3
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +143 -35
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +16 -4
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +90 -30
- package/plugins/toc/index.ts +26 -10
- package/plugins/toc/public/style.css +99 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +28 -9
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +124 -42
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +170 -40
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +119 -31
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +81 -12
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/index.ts +2 -2
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +233 -41
- package/src/pages/window.ts +78 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +591 -110
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
package/bin/whiteboard.ts
CHANGED
|
@@ -7,7 +7,21 @@ import http from 'node:http'
|
|
|
7
7
|
import { parseArgs } from 'node:util'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
9
|
import { pageId, findProjectDir, project as projectAt, configFileIn, type Project } from '../src/config.ts'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
appendEvent,
|
|
12
|
+
read,
|
|
13
|
+
readEvents,
|
|
14
|
+
follow,
|
|
15
|
+
matches,
|
|
16
|
+
pickedUp,
|
|
17
|
+
pick,
|
|
18
|
+
prune,
|
|
19
|
+
editEvent,
|
|
20
|
+
handOut,
|
|
21
|
+
CLAIM,
|
|
22
|
+
type EventFilter,
|
|
23
|
+
forAgent,
|
|
24
|
+
} from '../src/events.ts'
|
|
11
25
|
import { BUILTIN_COMMANDS, createConfigLoader, pluginDir } from '../src/loader.ts'
|
|
12
26
|
import { pluginCommands, parseCommandArgs, usage } from '../src/plugins.ts'
|
|
13
27
|
import { projectToken } from '../src/auth.ts'
|
|
@@ -33,6 +47,8 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
33
47
|
whiteboard url <page|file> the same: print the page URL
|
|
34
48
|
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
35
49
|
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
50
|
+
whiteboard build [globs…] [--out <dir>] [--skip <a,b>] pages as a static site: plain HTML, links
|
|
51
|
+
relative, without forms, chats, comments and drafts (the config's build)
|
|
36
52
|
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
37
53
|
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
38
54
|
a form's name or any text on it (opening details around it)
|
|
@@ -64,14 +80,27 @@ const [first, ...rest] = process.argv.slice(2)
|
|
|
64
80
|
// `whiteboard --help` and `-h`, where a command goes, ask for the help as `whiteboard help` does
|
|
65
81
|
const cmd = first === '--help' || first === '-h' ? 'help' : first
|
|
66
82
|
// a plugin's command parses its own arguments
|
|
67
|
-
const { values: opts, positionals } =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
83
|
+
const { values: opts, positionals } =
|
|
84
|
+
cmd && !BUILTIN_COMMANDS.has(cmd)
|
|
85
|
+
? { values: {}, positionals: [] }
|
|
86
|
+
: parseArgs({
|
|
87
|
+
args: rest,
|
|
88
|
+
allowPositionals: true,
|
|
89
|
+
options: {
|
|
90
|
+
page: { type: 'string' },
|
|
91
|
+
type: { type: 'string' },
|
|
92
|
+
data: { type: 'string' },
|
|
93
|
+
timeout: { type: 'string' },
|
|
94
|
+
count: { type: 'string' },
|
|
95
|
+
since: { type: 'string' },
|
|
96
|
+
last: { type: 'string' },
|
|
97
|
+
follow: { type: 'boolean' },
|
|
98
|
+
id: { type: 'string' },
|
|
99
|
+
out: { type: 'string' },
|
|
100
|
+
skip: { type: 'string' },
|
|
101
|
+
help: { type: 'boolean', short: 'h' },
|
|
102
|
+
},
|
|
103
|
+
})
|
|
75
104
|
|
|
76
105
|
const project = projectAt(findProjectDir())
|
|
77
106
|
|
|
@@ -98,7 +127,10 @@ async function ensureServer(): Promise<string> {
|
|
|
98
127
|
// is left over, and taken over. (Should two servers still start, the server lets one survive.)
|
|
99
128
|
const lock = path.join(proj.wb, 'server.lock')
|
|
100
129
|
const claim = () => {
|
|
101
|
-
try {
|
|
130
|
+
try {
|
|
131
|
+
fs.writeFileSync(lock, String(process.pid), { flag: 'wx' })
|
|
132
|
+
return true
|
|
133
|
+
} catch (err) {
|
|
102
134
|
if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err
|
|
103
135
|
return false
|
|
104
136
|
}
|
|
@@ -110,16 +142,31 @@ async function ensureServer(): Promise<string> {
|
|
|
110
142
|
let stale = false
|
|
111
143
|
try {
|
|
112
144
|
const owner = Number(fs.readFileSync(lock, 'utf8'))
|
|
113
|
-
try {
|
|
114
|
-
|
|
145
|
+
try {
|
|
146
|
+
process.kill(owner, 0)
|
|
147
|
+
} catch (err) {
|
|
148
|
+
stale = (err as NodeJS.ErrnoException).code === 'ESRCH'
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
/* removed meanwhile */
|
|
152
|
+
}
|
|
115
153
|
if (stale) {
|
|
116
|
-
try {
|
|
154
|
+
try {
|
|
155
|
+
fs.unlinkSync(lock)
|
|
156
|
+
} catch {
|
|
157
|
+
/* another command removed it first */
|
|
158
|
+
}
|
|
117
159
|
mine = claim()
|
|
118
160
|
}
|
|
119
161
|
}
|
|
120
162
|
if (mine) {
|
|
121
163
|
const log = fs.openSync(proj.logFile, 'a')
|
|
122
|
-
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'serve'], {
|
|
164
|
+
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'serve'], {
|
|
165
|
+
cwd: proj.dir,
|
|
166
|
+
detached: true,
|
|
167
|
+
stdio: ['ignore', log, log],
|
|
168
|
+
env: process.env,
|
|
169
|
+
})
|
|
123
170
|
child.unref()
|
|
124
171
|
}
|
|
125
172
|
for (let i = 0; i < 75; i++) {
|
|
@@ -150,13 +197,29 @@ function listen(f: EventFilter, command: 'wait' | 'watch', fallback = false): Pr
|
|
|
150
197
|
return new Promise(registered => {
|
|
151
198
|
const connect = async () => {
|
|
152
199
|
let base
|
|
153
|
-
try {
|
|
154
|
-
|
|
200
|
+
try {
|
|
201
|
+
base = await ensureServer()
|
|
202
|
+
} catch {
|
|
203
|
+
return setTimeout(connect, 2000).unref()
|
|
204
|
+
}
|
|
205
|
+
const q = new URLSearchParams({
|
|
206
|
+
command,
|
|
207
|
+
...(f.page ? { page: f.page } : {}),
|
|
208
|
+
...(f.type ? { type: f.type } : {}),
|
|
209
|
+
...(fallback ? { fallback: '' } : {}),
|
|
210
|
+
})
|
|
155
211
|
let again = false
|
|
156
|
-
const retry = (ms: number) => {
|
|
212
|
+
const retry = (ms: number) => {
|
|
213
|
+
if (!again) {
|
|
214
|
+
again = true
|
|
215
|
+
setTimeout(connect, ms).unref()
|
|
216
|
+
}
|
|
217
|
+
}
|
|
157
218
|
const req = http.get(`${base}/api/listen?${q}`, res => {
|
|
158
219
|
if (res.statusCode === 409) {
|
|
159
|
-
console.error(
|
|
220
|
+
console.error(
|
|
221
|
+
'whiteboard: another agent already takes what no other listener does (a wait or watch without --page; one per project). Add --page to wait on a page of your own.',
|
|
222
|
+
)
|
|
160
223
|
process.exit(1)
|
|
161
224
|
}
|
|
162
225
|
res.resume()
|
|
@@ -178,20 +241,36 @@ function listen(f: EventFilter, command: 'wait' | 'watch', fallback = false): Pr
|
|
|
178
241
|
async function otherListeners(changed: () => void): Promise<() => Listener[]> {
|
|
179
242
|
let list: Listener[] = []
|
|
180
243
|
const load = async () => {
|
|
181
|
-
try {
|
|
244
|
+
try {
|
|
245
|
+
list = (await (await fetch(`${await ensureServer()}/api/listeners`)).json()) as Listener[]
|
|
246
|
+
} catch {
|
|
247
|
+
/* the server restarts */
|
|
248
|
+
}
|
|
182
249
|
changed()
|
|
183
250
|
}
|
|
184
251
|
const follow = async () => {
|
|
185
252
|
let again = false
|
|
186
|
-
const retry = () => {
|
|
253
|
+
const retry = () => {
|
|
254
|
+
if (!again) {
|
|
255
|
+
again = true
|
|
256
|
+
setTimeout(follow, 1000).unref()
|
|
257
|
+
}
|
|
258
|
+
}
|
|
187
259
|
let base
|
|
188
|
-
try {
|
|
260
|
+
try {
|
|
261
|
+
base = await ensureServer()
|
|
262
|
+
} catch {
|
|
263
|
+
return retry()
|
|
264
|
+
}
|
|
189
265
|
const req = http.get(`${base}/api/watch?dir`, res => {
|
|
190
266
|
let buf = ''
|
|
191
267
|
res.setEncoding('utf8')
|
|
192
268
|
res.on('data', (chunk: string) => {
|
|
193
269
|
buf += chunk
|
|
194
|
-
if (buf.includes('event: listeners')) {
|
|
270
|
+
if (buf.includes('event: listeners')) {
|
|
271
|
+
buf = ''
|
|
272
|
+
load()
|
|
273
|
+
}
|
|
195
274
|
if (buf.length > 4096) buf = buf.slice(-64)
|
|
196
275
|
})
|
|
197
276
|
res.on('close', retry)
|
|
@@ -219,12 +298,18 @@ function init(name: string | undefined) {
|
|
|
219
298
|
const named = name && name !== path.basename(dir)
|
|
220
299
|
fs.mkdirSync(path.join(wb, 'pages'), { recursive: true })
|
|
221
300
|
// a config only for what differs from the defaults
|
|
222
|
-
if (named || home)
|
|
301
|
+
if (named || home)
|
|
302
|
+
fs.writeFileSync(
|
|
303
|
+
path.join(wb, 'config.ts'),
|
|
304
|
+
`import { defineConfig } from '@bigmistqke/whiteboard'
|
|
223
305
|
|
|
224
306
|
export default defineConfig({
|
|
225
307
|
${named ? ` name: '${name}',\n` : ''}${home ? ' // only .whiteboard/ is served: this folder is not a repository\n files: false,\n' : ''}})
|
|
226
|
-
|
|
227
|
-
|
|
308
|
+
`,
|
|
309
|
+
)
|
|
310
|
+
fs.writeFileSync(
|
|
311
|
+
path.join(wb, '.gitignore'),
|
|
312
|
+
`# pages are working documents; remove this line to keep them in git
|
|
228
313
|
pages/
|
|
229
314
|
# events from the pages (and which ones an agent picked up), and the running server's port and output
|
|
230
315
|
events.ndjson
|
|
@@ -233,7 +318,8 @@ server.log
|
|
|
233
318
|
server.lock
|
|
234
319
|
# the secret for anything that runs code (a plugin like the terminal)
|
|
235
320
|
token
|
|
236
|
-
|
|
321
|
+
`,
|
|
322
|
+
)
|
|
237
323
|
console.log(`project: ${wb}
|
|
238
324
|
pages: ${path.join(wb, 'pages')} (gitignored); \`whiteboard show <page>\` starts the server
|
|
239
325
|
config: ${configFileIn(wb) ?? `none: the defaults (markdown with the built-in plugins); add ${path.join(wb, 'config.ts')} to change them`}`)
|
|
@@ -260,11 +346,12 @@ async function currentSession(proj: Project): Promise<string | null> {
|
|
|
260
346
|
const session = typeof e.session === 'function' ? await e.session() : null
|
|
261
347
|
if (session) return String(session)
|
|
262
348
|
}
|
|
263
|
-
} catch (err) {
|
|
349
|
+
} catch (err) {
|
|
350
|
+
console.error(`whiteboard: which session runs this: ${(err as Error).message}`)
|
|
351
|
+
}
|
|
264
352
|
return null
|
|
265
353
|
}
|
|
266
354
|
|
|
267
|
-
|
|
268
355
|
async function status() {
|
|
269
356
|
const proj = needProject()
|
|
270
357
|
const [pages, session]: [PageStatus[], string | null] = await Promise.all([
|
|
@@ -272,8 +359,12 @@ async function status() {
|
|
|
272
359
|
currentSession(proj),
|
|
273
360
|
])
|
|
274
361
|
const busy = pages.filter(p => p.unpicked.length || p.open.length)
|
|
275
|
-
if (pages.some(p => p.listeners.some(l => l.fallback)))
|
|
276
|
-
|
|
362
|
+
if (pages.some(p => p.listeners.some(l => l.fallback)))
|
|
363
|
+
console.log('a fallback listens: it takes what no other wait or watch would\n')
|
|
364
|
+
if (!busy.length) {
|
|
365
|
+
console.log('nothing open: every question is answered, and every answer picked up')
|
|
366
|
+
return
|
|
367
|
+
}
|
|
277
368
|
for (const p of busy) {
|
|
278
369
|
console.log(`${p.page} (${whose(p, session)})`)
|
|
279
370
|
for (const l of statusLines(p, relFile(p.file))) console.log(` ${l}`)
|
|
@@ -284,11 +375,42 @@ switch (cmd) {
|
|
|
284
375
|
case 'serve': {
|
|
285
376
|
const proj = needProject()
|
|
286
377
|
const base = await running(proj)
|
|
287
|
-
if (base) {
|
|
378
|
+
if (base) {
|
|
379
|
+
console.error(`whiteboard: ${proj.name} is already served at ${base}`)
|
|
380
|
+
process.exit(1)
|
|
381
|
+
}
|
|
382
|
+
// the server only for the commands that run one: every other command (the hooks' among them,
|
|
383
|
+
// on every prompt) starts without it, a good part of its start-up time
|
|
288
384
|
const { start } = await import('../src/serve.ts')
|
|
289
385
|
await start(proj)
|
|
290
386
|
break
|
|
291
387
|
}
|
|
388
|
+
case 'build': {
|
|
389
|
+
// pages rendered once, as a static site: the config's `build`, with what is given here over it
|
|
390
|
+
const proj = needProject()
|
|
391
|
+
const { createServer } = await import('../src/server.ts') // as for serve: only when needed
|
|
392
|
+
const server = createServer(proj)
|
|
393
|
+
try {
|
|
394
|
+
const result = await server.build({
|
|
395
|
+
pages: positionals.length ? positionals : undefined,
|
|
396
|
+
out: opts.out,
|
|
397
|
+
skip:
|
|
398
|
+
opts.skip != null
|
|
399
|
+
? opts.skip
|
|
400
|
+
.split(',')
|
|
401
|
+
.map(s => s.trim())
|
|
402
|
+
.filter(Boolean)
|
|
403
|
+
: undefined,
|
|
404
|
+
})
|
|
405
|
+
for (const w of result.warnings) console.error(`whiteboard build: ${w}`)
|
|
406
|
+
console.log(
|
|
407
|
+
`built ${result.pages.length} page${result.pages.length === 1 ? '' : 's'} into ${path.relative(process.cwd(), result.out) || '.'}`,
|
|
408
|
+
)
|
|
409
|
+
} finally {
|
|
410
|
+
server.close()
|
|
411
|
+
}
|
|
412
|
+
process.exit(0)
|
|
413
|
+
}
|
|
292
414
|
case 'init': {
|
|
293
415
|
init(positionals[0])
|
|
294
416
|
break
|
|
@@ -302,7 +424,10 @@ switch (cmd) {
|
|
|
302
424
|
case 'new': {
|
|
303
425
|
// claim a page: the exclusive create fails when the file exists, so two agents asking at once
|
|
304
426
|
// never get the same page; the second gets name-2
|
|
305
|
-
const name = (positionals[0] ?? '')
|
|
427
|
+
const name = (positionals[0] ?? '')
|
|
428
|
+
.replace(/\\/g, '/')
|
|
429
|
+
.replace(/\.md$/, '')
|
|
430
|
+
.replace(/^\/+|\/+$/g, '')
|
|
306
431
|
if (!name || name.split('/').some(part => !part || part === '.' || part === '..' || part === '-' || part === '_'))
|
|
307
432
|
throw new Error('usage: whiteboard new <name> (a page name like plan or task/plan)')
|
|
308
433
|
const proj = needProject()
|
|
@@ -341,21 +466,36 @@ switch (cmd) {
|
|
|
341
466
|
if (!target) throw new Error('usage: whiteboard close <page|file>')
|
|
342
467
|
const proj = needProject()
|
|
343
468
|
const id = pageId(proj, target)
|
|
344
|
-
if (id.startsWith('-/'))
|
|
469
|
+
if (id.startsWith('-/'))
|
|
470
|
+
throw new Error(
|
|
471
|
+
`${target} is a file of the repository, not a page: close is for the pages in ${relFile(proj.pagesDir)}`,
|
|
472
|
+
)
|
|
345
473
|
const file = path.join(proj.pagesDir, `${id}.md`)
|
|
346
474
|
const exists = fs.existsSync(file)
|
|
347
475
|
// an agent still waiting on it would wait on nothing
|
|
348
476
|
const base = await running(proj)
|
|
349
477
|
if (base) {
|
|
350
478
|
try {
|
|
351
|
-
const listening = (
|
|
352
|
-
|
|
353
|
-
|
|
479
|
+
const listening = (
|
|
480
|
+
(await (await fetch(`${base}/api/listeners?page=${encodeURIComponent(id)}`)).json()) as Listener[]
|
|
481
|
+
).filter(l => !l.fallback && l.page === id)
|
|
482
|
+
if (listening.length)
|
|
483
|
+
console.error(
|
|
484
|
+
`whiteboard: ${listening.length} wait or watch still listens on ${id}; stop it, it will hear nothing more`,
|
|
485
|
+
)
|
|
486
|
+
} catch {
|
|
487
|
+
/* the server is going: nothing to say */
|
|
488
|
+
}
|
|
354
489
|
}
|
|
355
490
|
if (exists) fs.rmSync(file)
|
|
356
491
|
const removed = prune(proj.eventsFile, id)
|
|
357
|
-
if (!exists && !removed) {
|
|
358
|
-
|
|
492
|
+
if (!exists && !removed) {
|
|
493
|
+
console.error(`whiteboard: there is no page ${id}, nor events of it`)
|
|
494
|
+
process.exit(1)
|
|
495
|
+
}
|
|
496
|
+
console.log(
|
|
497
|
+
`closed ${id}: ${exists ? 'removed its file' : 'it had no file'}, and ${removed} event${removed === 1 ? '' : 's'} from the log`,
|
|
498
|
+
)
|
|
359
499
|
break
|
|
360
500
|
}
|
|
361
501
|
case 'prune': {
|
|
@@ -365,18 +505,29 @@ switch (cmd) {
|
|
|
365
505
|
if (!target) throw new Error('usage: whiteboard prune <page|file> [--type <type>] [--id <event id>]')
|
|
366
506
|
const proj = needProject()
|
|
367
507
|
const id = pageId(proj, target)
|
|
368
|
-
const removed = prune(
|
|
508
|
+
const removed = prune(
|
|
509
|
+
proj.eventsFile,
|
|
510
|
+
id,
|
|
511
|
+
e => (!opts.type || e.type === opts.type) && (!opts.id || e.id === opts.id),
|
|
512
|
+
)
|
|
369
513
|
const which = [opts.type && `of type ${opts.type}`, opts.id && `with id ${opts.id}`].filter(Boolean).join(', ')
|
|
370
|
-
console.log(
|
|
514
|
+
console.log(
|
|
515
|
+
`pruned ${removed} event${removed === 1 ? '' : 's'} of ${id}${which ? ` (${which})` : ''} from the log; the page stays`,
|
|
516
|
+
)
|
|
371
517
|
break
|
|
372
518
|
}
|
|
373
519
|
case 'edit': {
|
|
374
520
|
// an agent's own event, changed in place: --data is merged into its data
|
|
375
521
|
const eventId = positionals[0]
|
|
376
|
-
if (!eventId || !opts.data)
|
|
522
|
+
if (!eventId || !opts.data)
|
|
523
|
+
throw new Error("usage: whiteboard edit <event id> --data <json> (merged into the event's data)")
|
|
377
524
|
const proj = needProject()
|
|
378
525
|
let data: Record<string, unknown>
|
|
379
|
-
try {
|
|
526
|
+
try {
|
|
527
|
+
data = JSON.parse(opts.data)
|
|
528
|
+
} catch {
|
|
529
|
+
throw new Error('--data must be a JSON object')
|
|
530
|
+
}
|
|
380
531
|
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('--data must be a JSON object')
|
|
381
532
|
console.log(JSON.stringify(editEvent(proj.eventsFile, eventId, data)))
|
|
382
533
|
break
|
|
@@ -390,15 +541,31 @@ switch (cmd) {
|
|
|
390
541
|
const id = pageId(proj, target)
|
|
391
542
|
const base = await ensureServer()
|
|
392
543
|
// what the page shows, to say now when nothing on it matches
|
|
393
|
-
const rendered =
|
|
394
|
-
|
|
395
|
-
|
|
544
|
+
const rendered = (await (
|
|
545
|
+
await fetch(`${base}/api/render?page=${encodeURIComponent(id)}`)
|
|
546
|
+
)
|
|
547
|
+
.json()
|
|
548
|
+
.catch(() => null)) as { html?: string; data?: unknown } | null
|
|
549
|
+
const text = (rendered?.html ?? '')
|
|
550
|
+
.replace(/<[^>]+>/g, ' ')
|
|
551
|
+
.replace(/&[a-z#0-9]+;/gi, ' ')
|
|
552
|
+
.replace(/\s+/g, ' ')
|
|
553
|
+
.toLowerCase()
|
|
554
|
+
const named = new RegExp(`<form[^>]*\\bname="${to.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"`).test(
|
|
555
|
+
rendered?.html ?? '',
|
|
556
|
+
)
|
|
396
557
|
if (rendered && !named && !text.includes(to.replace(/\s+/g, ' ').toLowerCase())) {
|
|
397
|
-
console.error(
|
|
558
|
+
console.error(
|
|
559
|
+
`whiteboard: nothing on ${id} matches ${JSON.stringify(to)} (a heading's text, a form's name, or text on the page)`,
|
|
560
|
+
)
|
|
398
561
|
process.exit(1)
|
|
399
562
|
}
|
|
400
|
-
const res = await fetch(`${base}/api/scroll`, {
|
|
401
|
-
|
|
563
|
+
const res = await fetch(`${base}/api/scroll`, {
|
|
564
|
+
method: 'POST',
|
|
565
|
+
headers: { 'content-type': 'application/json' },
|
|
566
|
+
body: JSON.stringify({ page: id, to }),
|
|
567
|
+
})
|
|
568
|
+
const { tabs } = (await res.json()) as { tabs: number }
|
|
402
569
|
if (!tabs) {
|
|
403
570
|
console.error(`whiteboard: no browser has ${id} open; \`whiteboard show ${target}\` prints its URL`)
|
|
404
571
|
process.exit(1)
|
|
@@ -415,21 +582,37 @@ switch (cmd) {
|
|
|
415
582
|
const names = (info.plugins ?? []).map((x: { name: string }) => x.name)
|
|
416
583
|
if (only && !names.includes(only)) throw new Error(`no plugin named "${only}" here: ${names.join(', ')}`)
|
|
417
584
|
const shown = (x: { name: string }) => !only || x.name === only
|
|
418
|
-
if (!only)
|
|
585
|
+
if (!only)
|
|
586
|
+
console.log(
|
|
587
|
+
info.pages ? `${info.pages.trim()}\n` : 'The config failed to load, so pages show as their raw text.\n',
|
|
588
|
+
)
|
|
419
589
|
for (const e of (info.plugins ?? []).filter(shown)) {
|
|
420
590
|
console.log(`<!-- plugin: ${e.name} -->\n# Plugin: ${e.name}\n`)
|
|
421
591
|
if (e.error) console.log(`It failed to load: ${e.error}\n`)
|
|
422
592
|
if (e.docs) console.log(`${e.docs.trim()}\n`)
|
|
423
593
|
if (e.events?.length) {
|
|
424
|
-
console.log(
|
|
425
|
-
|
|
594
|
+
console.log(
|
|
595
|
+
'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',
|
|
596
|
+
)
|
|
597
|
+
for (const v of e.events)
|
|
598
|
+
console.log(`- \`${v.type}\`${v.handOut ? ' (handed out)' : ''}${v.description ? `: ${v.description}` : ''}`)
|
|
426
599
|
console.log()
|
|
427
600
|
}
|
|
428
|
-
for (const c of e.commands)
|
|
429
|
-
|
|
601
|
+
for (const c of e.commands)
|
|
602
|
+
console.log(`- \`whiteboard ${[c.name, c.usage].filter(Boolean).join(' ')}\`: ${c.description}`)
|
|
603
|
+
if (e.routes.length)
|
|
604
|
+
console.log(`\nRoutes (\`auth\`: needs the project's token, header \`x-whiteboard-token\`):\n`)
|
|
430
605
|
for (const r of e.routes) {
|
|
431
|
-
const takes = [
|
|
432
|
-
|
|
606
|
+
const takes = [
|
|
607
|
+
r.body && `body ${JSON.stringify(r.body)}`,
|
|
608
|
+
r.query && `query ${JSON.stringify(r.query)}`,
|
|
609
|
+
r.stream && 'server-sent events',
|
|
610
|
+
]
|
|
611
|
+
.filter(Boolean)
|
|
612
|
+
.join(', ')
|
|
613
|
+
console.log(
|
|
614
|
+
`- \`${r.method} ${r.path}\`${r.auth ? ' (auth)' : ''}: ${r.description}${takes ? ` (${takes})` : ''}`,
|
|
615
|
+
)
|
|
433
616
|
}
|
|
434
617
|
console.log()
|
|
435
618
|
}
|
|
@@ -448,7 +631,10 @@ switch (cmd) {
|
|
|
448
631
|
}
|
|
449
632
|
if (opts.last) list = list.slice(-Number(opts.last))
|
|
450
633
|
for (const e of list) console.log(JSON.stringify(e))
|
|
451
|
-
if (opts.follow)
|
|
634
|
+
if (opts.follow)
|
|
635
|
+
follow(log, end, e => {
|
|
636
|
+
if (matches(e, f)) console.log(JSON.stringify(e))
|
|
637
|
+
})
|
|
452
638
|
break
|
|
453
639
|
}
|
|
454
640
|
case 'pick': {
|
|
@@ -459,7 +645,10 @@ switch (cmd) {
|
|
|
459
645
|
const events = readEvents(proj.eventsFile)
|
|
460
646
|
const event = events.find(e => e.id === id)
|
|
461
647
|
if (!event) throw new Error(`no event ${id} in ${proj.eventsFile}`)
|
|
462
|
-
if (pickedUp(events).has(id)) {
|
|
648
|
+
if (pickedUp(events).has(id)) {
|
|
649
|
+
console.error(`whiteboard: ${id} was picked up already`)
|
|
650
|
+
break
|
|
651
|
+
}
|
|
463
652
|
console.log(JSON.stringify(pick(proj.eventsFile, event)))
|
|
464
653
|
break
|
|
465
654
|
}
|
|
@@ -480,38 +669,67 @@ switch (cmd) {
|
|
|
480
669
|
// it holds each event briefly before deciding: by then that wait took it, or the copy knows.
|
|
481
670
|
const held = new Set<string>()
|
|
482
671
|
const skip = (e: WbEvent) => {
|
|
483
|
-
if (!held.has(e.id)) {
|
|
672
|
+
if (!held.has(e.id)) {
|
|
673
|
+
held.add(e.id)
|
|
674
|
+
setTimeout(() => recheck(), 500).unref()
|
|
675
|
+
return true
|
|
676
|
+
}
|
|
484
677
|
return takenByOther(others!(), e)
|
|
485
678
|
}
|
|
486
679
|
handOut(proj.eventsFile, f, e => console.log(JSON.stringify(e)), {
|
|
487
680
|
count: cmd === 'wait' ? Number(opts.count ?? 1) : Infinity,
|
|
488
681
|
forAgent: forAgent(handedOut),
|
|
489
|
-
...(others && {
|
|
682
|
+
...(others && {
|
|
683
|
+
skip,
|
|
684
|
+
recheck: again => {
|
|
685
|
+
recheck = again
|
|
686
|
+
},
|
|
687
|
+
}),
|
|
490
688
|
}).then(async () => {
|
|
491
689
|
// a wait on a page ends with an answer, and the agent acts on it; what is still unanswered
|
|
492
690
|
// there needs the next wait, which is easily forgotten: say so, right with the answer
|
|
493
691
|
if (cmd === 'wait' && !fallback) {
|
|
494
692
|
try {
|
|
495
|
-
const pages = await api(`/api/status?page=${encodeURIComponent(f.page!)}`) as PageStatus[]
|
|
496
|
-
for (const p of pages)
|
|
497
|
-
|
|
693
|
+
const pages = (await api(`/api/status?page=${encodeURIComponent(f.page!)}`)) as PageStatus[]
|
|
694
|
+
for (const p of pages)
|
|
695
|
+
if (p.open.length)
|
|
696
|
+
console.error(
|
|
697
|
+
`whiteboard: still unanswered on ${p.page}: ${p.open.join(', ')} → run \`whiteboard wait --page ${relFile(p.file)}\` again, in the background, once you've acted on this`,
|
|
698
|
+
)
|
|
699
|
+
} catch {
|
|
700
|
+
/* no status: the answer is what matters */
|
|
701
|
+
}
|
|
498
702
|
}
|
|
499
703
|
process.exit(0)
|
|
500
704
|
})
|
|
501
705
|
if (!fallback) listen(f, cmd)
|
|
502
|
-
if (opts.timeout && cmd === 'wait')
|
|
706
|
+
if (opts.timeout && cmd === 'wait')
|
|
707
|
+
setTimeout(
|
|
708
|
+
() => {
|
|
709
|
+
console.error('timeout')
|
|
710
|
+
process.exit(2)
|
|
711
|
+
},
|
|
712
|
+
Number(opts.timeout) * 1000,
|
|
713
|
+
)
|
|
503
714
|
break
|
|
504
715
|
}
|
|
505
716
|
case 'append': {
|
|
506
717
|
// the agent's side of the log: anything a page's plugins understand, such as a reply to a
|
|
507
718
|
// comment. Waits skip what is appended here, so an agent does not hear its own events.
|
|
508
719
|
const proj = needProject()
|
|
509
|
-
if (!opts.page || !opts.type)
|
|
720
|
+
if (!opts.page || !opts.type)
|
|
721
|
+
throw new Error("usage: whiteboard append --page <page|file> --type <type> [--data '<json>']")
|
|
510
722
|
let data = {}
|
|
511
723
|
if (opts.data) {
|
|
512
|
-
try {
|
|
724
|
+
try {
|
|
725
|
+
data = JSON.parse(opts.data)
|
|
726
|
+
} catch {
|
|
727
|
+
throw new Error('--data must be JSON, e.g. \'{"text":"…"}\'')
|
|
728
|
+
}
|
|
513
729
|
}
|
|
514
|
-
console.log(
|
|
730
|
+
console.log(
|
|
731
|
+
JSON.stringify(appendEvent(proj.eventsFile, { page: pageId(proj, opts.page), type: opts.type, data }, 'cli')),
|
|
732
|
+
)
|
|
515
733
|
break
|
|
516
734
|
}
|
|
517
735
|
case 'status':
|
|
@@ -520,10 +738,15 @@ switch (cmd) {
|
|
|
520
738
|
case 'skill': {
|
|
521
739
|
// the agent skill ships in this package; link it into whatever folder an agent reads skills from
|
|
522
740
|
const source = packagePath('skills', 'whiteboard')
|
|
523
|
-
if (!positionals[0]) {
|
|
741
|
+
if (!positionals[0]) {
|
|
742
|
+
console.log(source)
|
|
743
|
+
break
|
|
744
|
+
}
|
|
524
745
|
const target = path.join(path.resolve(positionals[0].replace(/^~(?=$|\/)/, os.homedir())), 'whiteboard')
|
|
525
746
|
let existing = null
|
|
526
|
-
try {
|
|
747
|
+
try {
|
|
748
|
+
existing = fs.lstatSync(target)
|
|
749
|
+
} catch {}
|
|
527
750
|
if (existing) {
|
|
528
751
|
if (existing.isSymbolicLink() && path.resolve(path.dirname(target), fs.readlinkSync(target)) === source) {
|
|
529
752
|
console.log(`already linked: ${target} -> ${source}`)
|
|
@@ -556,8 +779,13 @@ switch (cmd) {
|
|
|
556
779
|
server: ensureServer,
|
|
557
780
|
pagePath: page => `/${pageId(project, page ?? '')}`,
|
|
558
781
|
status: async page => api(`/api/status${page ? `?page=${encodeURIComponent(pageId(project, page))}` : ''}`),
|
|
559
|
-
handOut: async (filter, onEvent, options) =>
|
|
560
|
-
|
|
782
|
+
handOut: async (filter, onEvent, options) =>
|
|
783
|
+
handOut(project.eventsFile, { ...filter, page: filter.page ? pageId(project, filter.page) : null }, onEvent, {
|
|
784
|
+
...options,
|
|
785
|
+
forAgent: forAgent((await projectConfig(project)).handedOut),
|
|
786
|
+
}),
|
|
787
|
+
authLink: async to =>
|
|
788
|
+
`${await ensureServer()}/_/auth?token=${encodeURIComponent(projectToken(project.wb))}&to=${encodeURIComponent(to)}`,
|
|
561
789
|
})
|
|
562
790
|
break
|
|
563
791
|
}
|
|
@@ -567,7 +795,8 @@ switch (cmd) {
|
|
|
567
795
|
print(HELP)
|
|
568
796
|
if (commands.length) {
|
|
569
797
|
print(`\nfrom this project's plugins:\n`)
|
|
570
|
-
for (const c of commands)
|
|
798
|
+
for (const c of commands)
|
|
799
|
+
print(` whiteboard ${[c.name, usage(c.command)].filter(Boolean).join(' ')}\n ${c.command.description}`)
|
|
571
800
|
}
|
|
572
801
|
if (mine.length) console.error(`\nwhiteboard: ${cmd} has no command ${JSON.stringify(rest[0] ?? '')}`)
|
|
573
802
|
if (!asked) process.exit(1)
|
package/dist/bin/whiteboard.js
CHANGED
|
@@ -30,6 +30,8 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
30
30
|
whiteboard url <page|file> the same: print the page URL
|
|
31
31
|
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
32
32
|
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
33
|
+
whiteboard build [globs…] [--out <dir>] [--skip <a,b>] pages as a static site: plain HTML, links
|
|
34
|
+
relative, without forms, chats, comments and drafts (the config's build)
|
|
33
35
|
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
34
36
|
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
35
37
|
a form's name or any text on it (opening details around it)
|
|
@@ -74,6 +76,8 @@ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? {
|
|
|
74
76
|
last: { type: "string" },
|
|
75
77
|
follow: { type: "boolean" },
|
|
76
78
|
id: { type: "string" },
|
|
79
|
+
out: { type: "string" },
|
|
80
|
+
skip: { type: "string" },
|
|
77
81
|
help: {
|
|
78
82
|
type: "boolean",
|
|
79
83
|
short: "h"
|
|
@@ -323,6 +327,23 @@ switch (cmd) {
|
|
|
323
327
|
await start(proj);
|
|
324
328
|
break;
|
|
325
329
|
}
|
|
330
|
+
case "build": {
|
|
331
|
+
const proj = needProject();
|
|
332
|
+
const { createServer } = await import("../src/server.js");
|
|
333
|
+
const server = createServer(proj);
|
|
334
|
+
try {
|
|
335
|
+
const result = await server.build({
|
|
336
|
+
pages: positionals.length ? positionals : void 0,
|
|
337
|
+
out: opts.out,
|
|
338
|
+
skip: opts.skip != null ? opts.skip.split(",").map((s) => s.trim()).filter(Boolean) : void 0
|
|
339
|
+
});
|
|
340
|
+
for (const w of result.warnings) console.error(`whiteboard build: ${w}`);
|
|
341
|
+
console.log(`built ${result.pages.length} page${result.pages.length === 1 ? "" : "s"} into ${path.relative(process.cwd(), result.out) || "."}`);
|
|
342
|
+
} finally {
|
|
343
|
+
server.close();
|
|
344
|
+
}
|
|
345
|
+
process.exit(0);
|
|
346
|
+
}
|
|
326
347
|
case "init":
|
|
327
348
|
init(positionals[0]);
|
|
328
349
|
break;
|