@bigmistqke/whiteboard 0.2.1 → 0.3.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 +16 -10
- package/bin/whiteboard.ts +98 -4
- package/dist/bin/whiteboard.js +99 -3
- package/dist/client/runtime.js +118 -24
- package/dist/plugins/claude-code/index.js +14 -3
- package/dist/plugins/comments/client.js +3 -3
- package/dist/plugins/details/README.md +3 -1
- package/dist/plugins/form/README.md +6 -4
- package/dist/plugins/form/index.js +9 -1
- package/dist/plugins/form/style.css +3 -0
- package/dist/plugins/toc/README.md +10 -0
- package/dist/plugins/toc/client.js +1 -0
- package/dist/plugins/toc/index.js +17 -0
- package/dist/plugins/toc/style.css +19 -0
- package/dist/src/client/page/base.css +26 -22
- package/dist/src/client/page/main.js +227 -52
- package/dist/src/events.js +127 -9
- package/dist/src/loader.js +4 -0
- package/dist/src/server.js +25 -17
- package/package.json +6 -1
- package/plugins/claude-code/index.ts +16 -7
- package/plugins/comments/client.ts +30 -7
- package/plugins/details/README.md +3 -1
- package/plugins/form/README.md +6 -4
- package/plugins/form/index.ts +9 -1
- package/plugins/form/style.css +3 -0
- package/plugins/toc/README.md +10 -0
- package/plugins/toc/client.ts +130 -0
- package/plugins/toc/index.ts +25 -0
- package/plugins/toc/style.css +19 -0
- package/skills/whiteboard/SKILL.md +41 -9
- package/src/client/forms.ts +32 -1
- package/src/client/page/base.css +26 -22
- package/src/client/page/fresh.ts +18 -23
- package/src/client/page/hold.ts +37 -0
- package/src/client/page/main.ts +81 -6
- package/src/client/page/sticky.ts +45 -0
- package/src/client/page/waiting.ts +30 -27
- package/src/client/runtime.ts +8 -2
- package/src/client/scroll.ts +44 -0
- package/src/client/toast.ts +51 -21
- package/src/define.ts +17 -8
- package/src/events.ts +95 -7
- package/src/loader.ts +1 -1
- package/src/server.ts +28 -7
package/README.md
CHANGED
|
@@ -247,11 +247,11 @@ export default defineConfig({
|
|
|
247
247
|
With it, `whiteboard new` claims the page it makes for the Claude Code
|
|
248
248
|
session that ran it, and `whiteboard status` marks that session's pages.
|
|
249
249
|
`whiteboard claude-code install` adds three hooks to the project's
|
|
250
|
-
`.claude/settings.json
|
|
251
|
-
them ever blocks:
|
|
250
|
+
`.claude/settings.json`:
|
|
252
251
|
|
|
253
252
|
- when a turn ends with something on the session's pages nobody listens for,
|
|
254
|
-
|
|
253
|
+
the turn goes on once, telling the agent to start its wait (agents forget);
|
|
254
|
+
a turn the hook already continued ends, and you see what is open;
|
|
255
255
|
- when you send a message, answers on the session's pages that no wait
|
|
256
256
|
picked up come with it, and count as picked up from then on;
|
|
257
257
|
- a new session starts with the same, plus what is open on other sessions'
|
|
@@ -269,6 +269,10 @@ upward with a `.whiteboard/` folder.
|
|
|
269
269
|
| `whiteboard new <name>` | create a page under a name no other page has (`name`, else `name-2`, …), print its path |
|
|
270
270
|
| `whiteboard show <page\|file>` | start the server if needed, print the page's URL |
|
|
271
271
|
| `whiteboard url <page\|file>` | the same |
|
|
272
|
+
| `whiteboard close <page>` | a page that did its job: remove its file, and all its events from the log |
|
|
273
|
+
| `whiteboard prune <page> [--type <t>] [--id <id>]` | remove a page's events from the log (all, one type, or one), keep the page |
|
|
274
|
+
| `whiteboard edit <event id> --data <json>` | change an agent's own event in place: merged into its data, its id kept |
|
|
275
|
+
| `whiteboard scroll <page\|file> <where>` | scroll the tabs that have the page open to a heading's text, a form's name or any text on it; exits 1 when nothing matches or no tab has it open |
|
|
272
276
|
| `whiteboard docs [name]` | print how to write pages in this project: the blocks, then each plugin's docs; with a name, only that plugin's |
|
|
273
277
|
| `whiteboard events [filters] [--follow]` | print recorded events; with `--follow`, then each new one as it comes, marking nothing |
|
|
274
278
|
| `whiteboard wait [filters]` | print the next matching event not handed out before, waiting for it if needed; without `--page`, only what no other wait or watch would take (the fallback, one per project) |
|
|
@@ -311,7 +315,8 @@ The built-in plugins are callout, chat, code, comments, details, forge,
|
|
|
311
315
|
form, gallery, grid, iframe, mermaid and quiet: every project has them, and
|
|
312
316
|
`whiteboard docs` shows how to write each. A config's `plugins` add to them,
|
|
313
317
|
and one with a built-in's name replaces it. The terminal and the Claude Code
|
|
314
|
-
plugin are opt-in, since they run code or are about one agent
|
|
318
|
+
plugin are opt-in, since they run code or are about one agent, and so is the
|
|
319
|
+
table of contents (`toc`), which takes the margin beside every page.
|
|
315
320
|
|
|
316
321
|
Named forms need nothing in the config: the core sends a submit of any
|
|
317
322
|
`<form name>` as an event, on any page.
|
|
@@ -483,9 +488,10 @@ is replaced on a live update; it replaces the server's HTML when it mounts.
|
|
|
483
488
|
A page module (`setup`'s `client`) gets `mount(root, page, api)`. Both get
|
|
484
489
|
the page's `api`: its events and `append` (which comes back through
|
|
485
490
|
`onEvents`), the listeners, `onRendered` (after a live update, to put back
|
|
486
|
-
what it adds), `corner()` for floating buttons, `toast()` for a
|
|
487
|
-
|
|
488
|
-
|
|
491
|
+
what it adds), `corner()` for floating buttons, `toast()` for a label in
|
|
492
|
+
the corner that says what is going on and goes there (one that hides after a
|
|
493
|
+
few seconds, or one that stays with a count), `badge()` for counts in the
|
|
494
|
+
tab title, and the theme. Files beside a browser module that are browser
|
|
489
495
|
assets (scripts, styles, images, fonts) are served too.
|
|
490
496
|
|
|
491
497
|
Something that covers the bottom of the window says how much in
|
|
@@ -535,9 +541,9 @@ Not started.
|
|
|
535
541
|
recorded in the log, so it holds in every browser. An answered form waits
|
|
536
542
|
for the agent until it picks the answer up, then it is decided and folds
|
|
537
543
|
to one line quoting the answer, with its chat still under it; a click
|
|
538
|
-
opens it again. A line above the page counts all this,
|
|
539
|
-
|
|
540
|
-
and the tab title gets a `(!n)` prefix. An answer sent while no agent
|
|
544
|
+
opens it again. A line above the page counts all this, the corner's
|
|
545
|
+
toasts go to the next question ("→ unanswered (n)") and the next
|
|
546
|
+
unread message ("→ unread (n)"), and the tab title gets a `(!n)` prefix. An answer sent while no agent
|
|
541
547
|
listens says so in a toast; it stays in the log for the next agent that
|
|
542
548
|
checks.
|
|
543
549
|
- **Whether an agent listens.** The dot at the end of the header is green
|
package/bin/whiteboard.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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 { appendEvent, read, readEvents, follow, matches, pickedUp, pick, handOut, CLAIM, type EventFilter, forAgent } from '../src/events.ts'
|
|
10
|
+
import { appendEvent, read, readEvents, follow, matches, pickedUp, pick, prune, editEvent, handOut, CLAIM, type EventFilter, forAgent } from '../src/events.ts'
|
|
11
11
|
import { BUILTIN_COMMANDS, createConfigLoader, pluginDir } from '../src/loader.ts'
|
|
12
12
|
import { pluginCommands, parseCommandArgs, usage } from '../src/plugins.ts'
|
|
13
13
|
import { projectToken } from '../src/auth.ts'
|
|
@@ -31,6 +31,11 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
31
31
|
whiteboard new <name> create a page under a name no other page has (name, name-2, …), print its path
|
|
32
32
|
whiteboard show <page|file> start this project's server if needed, print the page URL
|
|
33
33
|
whiteboard url <page|file> the same: print the page URL
|
|
34
|
+
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
35
|
+
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
36
|
+
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
37
|
+
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
38
|
+
a form's name or any text on it (opening details around it)
|
|
34
39
|
whiteboard docs [plugin] how to write pages here: markdown, and each plugin's blocks — read before writing one;
|
|
35
40
|
with a plugin's name, only its docs
|
|
36
41
|
whiteboard events [filters] print recorded events as ndjson; --follow: then each new one as it comes
|
|
@@ -64,7 +69,7 @@ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? { valu
|
|
|
64
69
|
allowPositionals: true,
|
|
65
70
|
options: {
|
|
66
71
|
page: { type: 'string' }, type: { type: 'string' }, data: { type: 'string' }, timeout: { type: 'string' }, count: { type: 'string' },
|
|
67
|
-
since: { type: 'string' }, last: { type: 'string' }, follow: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
|
|
72
|
+
since: { type: 'string' }, last: { type: 'string' }, follow: { type: 'boolean' }, id: { type: 'string' }, help: { type: 'boolean', short: 'h' },
|
|
68
73
|
},
|
|
69
74
|
})
|
|
70
75
|
|
|
@@ -329,6 +334,78 @@ switch (cmd) {
|
|
|
329
334
|
console.log(`${base}/${pageId(project, positionals[0] ?? '')}`)
|
|
330
335
|
break
|
|
331
336
|
}
|
|
337
|
+
case 'close': {
|
|
338
|
+
// a page that has done its job: its file goes, and its events leave the log (answers, chats,
|
|
339
|
+
// comments, what was read and picked up), so neither the page nor its history lingers
|
|
340
|
+
const target = positionals[0]
|
|
341
|
+
if (!target) throw new Error('usage: whiteboard close <page|file>')
|
|
342
|
+
const proj = needProject()
|
|
343
|
+
const id = pageId(proj, target)
|
|
344
|
+
if (id.startsWith('-/')) throw new Error(`${target} is a file of the repository, not a page: close is for the pages in ${relFile(proj.pagesDir)}`)
|
|
345
|
+
const file = path.join(proj.pagesDir, `${id}.md`)
|
|
346
|
+
const exists = fs.existsSync(file)
|
|
347
|
+
// an agent still waiting on it would wait on nothing
|
|
348
|
+
const base = await running(proj)
|
|
349
|
+
if (base) {
|
|
350
|
+
try {
|
|
351
|
+
const listening = (await (await fetch(`${base}/api/listeners?page=${encodeURIComponent(id)}`)).json() as Listener[]).filter(l => !l.fallback && l.page === id)
|
|
352
|
+
if (listening.length) console.error(`whiteboard: ${listening.length} wait or watch still listens on ${id}; stop it, it will hear nothing more`)
|
|
353
|
+
} catch { /* the server is going: nothing to say */ }
|
|
354
|
+
}
|
|
355
|
+
if (exists) fs.rmSync(file)
|
|
356
|
+
const removed = prune(proj.eventsFile, id)
|
|
357
|
+
if (!exists && !removed) { console.error(`whiteboard: there is no page ${id}, nor events of it`); process.exit(1) }
|
|
358
|
+
console.log(`closed ${id}: ${exists ? 'removed its file' : 'it had no file'}, and ${removed} event${removed === 1 ? '' : 's'} from the log`)
|
|
359
|
+
break
|
|
360
|
+
}
|
|
361
|
+
case 'prune': {
|
|
362
|
+
// a page's events, gone from the log, the page kept: all of them (it starts over), or one type,
|
|
363
|
+
// or one event
|
|
364
|
+
const target = positionals[0]
|
|
365
|
+
if (!target) throw new Error('usage: whiteboard prune <page|file> [--type <type>] [--id <event id>]')
|
|
366
|
+
const proj = needProject()
|
|
367
|
+
const id = pageId(proj, target)
|
|
368
|
+
const removed = prune(proj.eventsFile, id, e => (!opts.type || e.type === opts.type) && (!opts.id || e.id === opts.id))
|
|
369
|
+
const which = [opts.type && `of type ${opts.type}`, opts.id && `with id ${opts.id}`].filter(Boolean).join(', ')
|
|
370
|
+
console.log(`pruned ${removed} event${removed === 1 ? '' : 's'} of ${id}${which ? ` (${which})` : ''} from the log; the page stays`)
|
|
371
|
+
break
|
|
372
|
+
}
|
|
373
|
+
case 'edit': {
|
|
374
|
+
// an agent's own event, changed in place: --data is merged into its data
|
|
375
|
+
const eventId = positionals[0]
|
|
376
|
+
if (!eventId || !opts.data) throw new Error('usage: whiteboard edit <event id> --data <json> (merged into the event\'s data)')
|
|
377
|
+
const proj = needProject()
|
|
378
|
+
let data: Record<string, unknown>
|
|
379
|
+
try { data = JSON.parse(opts.data) } catch { throw new Error('--data must be a JSON object') }
|
|
380
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('--data must be a JSON object')
|
|
381
|
+
console.log(JSON.stringify(editEvent(proj.eventsFile, eventId, data)))
|
|
382
|
+
break
|
|
383
|
+
}
|
|
384
|
+
case 'scroll': {
|
|
385
|
+
// show the reader a place on a page they have open: every tab with it scrolls there
|
|
386
|
+
const [target, ...where] = positionals
|
|
387
|
+
const to = where.join(' ').trim()
|
|
388
|
+
if (!target || !to) throw new Error('usage: whiteboard scroll <page|file> <heading, form name or text>')
|
|
389
|
+
const proj = needProject()
|
|
390
|
+
const id = pageId(proj, target)
|
|
391
|
+
const base = await ensureServer()
|
|
392
|
+
// what the page shows, to say now when nothing on it matches
|
|
393
|
+
const rendered = await (await fetch(`${base}/api/render?page=${encodeURIComponent(id)}`)).json().catch(() => null) as { html?: string; data?: unknown } | null
|
|
394
|
+
const text = (rendered?.html ?? '').replace(/<[^>]+>/g, ' ').replace(/&[a-z#0-9]+;/gi, ' ').replace(/\s+/g, ' ').toLowerCase()
|
|
395
|
+
const named = new RegExp(`<form[^>]*\\bname="${to.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"`).test(rendered?.html ?? '')
|
|
396
|
+
if (rendered && !named && !text.includes(to.replace(/\s+/g, ' ').toLowerCase())) {
|
|
397
|
+
console.error(`whiteboard: nothing on ${id} matches ${JSON.stringify(to)} (a heading's text, a form's name, or text on the page)`)
|
|
398
|
+
process.exit(1)
|
|
399
|
+
}
|
|
400
|
+
const res = await fetch(`${base}/api/scroll`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ page: id, to }) })
|
|
401
|
+
const { tabs } = await res.json() as { tabs: number }
|
|
402
|
+
if (!tabs) {
|
|
403
|
+
console.error(`whiteboard: no browser has ${id} open; \`whiteboard show ${target}\` prints its URL`)
|
|
404
|
+
process.exit(1)
|
|
405
|
+
}
|
|
406
|
+
console.log(`scrolled ${tabs} tab${tabs > 1 ? 's' : ''} of ${id} to ${JSON.stringify(to)}`)
|
|
407
|
+
break
|
|
408
|
+
}
|
|
332
409
|
case 'docs': {
|
|
333
410
|
// how pages are written and which plugin brings which block, then each plugin's docs (the
|
|
334
411
|
// syntax of its blocks, its events, its commands); `whiteboard docs <plugin>` prints only that one
|
|
@@ -399,11 +476,28 @@ switch (cmd) {
|
|
|
399
476
|
const fallback = !f.page
|
|
400
477
|
let recheck = () => {}
|
|
401
478
|
const others = fallback ? (await listen(f, cmd, true), await otherListeners(() => recheck())) : null
|
|
479
|
+
// The fallback's copy of who else listens can lag a moment behind a wait that just started, so
|
|
480
|
+
// it holds each event briefly before deciding: by then that wait took it, or the copy knows.
|
|
481
|
+
const held = new Set<string>()
|
|
482
|
+
const skip = (e: WbEvent) => {
|
|
483
|
+
if (!held.has(e.id)) { held.add(e.id); setTimeout(() => recheck(), 500).unref(); return true }
|
|
484
|
+
return takenByOther(others!(), e)
|
|
485
|
+
}
|
|
402
486
|
handOut(proj.eventsFile, f, e => console.log(JSON.stringify(e)), {
|
|
403
487
|
count: cmd === 'wait' ? Number(opts.count ?? 1) : Infinity,
|
|
404
488
|
forAgent: forAgent(handedOut),
|
|
405
|
-
...(others && { skip
|
|
406
|
-
}).then(() =>
|
|
489
|
+
...(others && { skip, recheck: again => { recheck = again } }),
|
|
490
|
+
}).then(async () => {
|
|
491
|
+
// a wait on a page ends with an answer, and the agent acts on it; what is still unanswered
|
|
492
|
+
// there needs the next wait, which is easily forgotten: say so, right with the answer
|
|
493
|
+
if (cmd === 'wait' && !fallback) {
|
|
494
|
+
try {
|
|
495
|
+
const pages = await api(`/api/status?page=${encodeURIComponent(f.page!)}`) as PageStatus[]
|
|
496
|
+
for (const p of pages) if (p.open.length) console.error(`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`)
|
|
497
|
+
} catch { /* no status: the answer is what matters */ }
|
|
498
|
+
}
|
|
499
|
+
process.exit(0)
|
|
500
|
+
})
|
|
407
501
|
if (!fallback) listen(f, cmd)
|
|
408
502
|
if (opts.timeout && cmd === 'wait') setTimeout(() => { console.error('timeout'); process.exit(2) }, Number(opts.timeout) * 1000)
|
|
409
503
|
break
|
package/dist/bin/whiteboard.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { configFileIn, findProjectDir, pageId, project as project$1 } from "../src/config.js";
|
|
3
|
-
import { CLAIM, appendEvent, follow, forAgent, handOut, matches, pick, pickedUp, read, readEvents } from "../src/events.js";
|
|
3
|
+
import { CLAIM, appendEvent, editEvent, follow, forAgent, handOut, matches, pick, pickedUp, prune, read, readEvents } from "../src/events.js";
|
|
4
4
|
import { BUILTIN_COMMANDS, createConfigLoader, pluginDir } from "../src/loader.js";
|
|
5
5
|
import { parseCommandArgs, pluginCommands, usage } from "../src/plugins.js";
|
|
6
6
|
import { projectToken } from "../src/auth.js";
|
|
@@ -28,6 +28,11 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
28
28
|
whiteboard new <name> create a page under a name no other page has (name, name-2, …), print its path
|
|
29
29
|
whiteboard show <page|file> start this project's server if needed, print the page URL
|
|
30
30
|
whiteboard url <page|file> the same: print the page URL
|
|
31
|
+
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
32
|
+
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
33
|
+
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
34
|
+
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
35
|
+
a form's name or any text on it (opening details around it)
|
|
31
36
|
whiteboard docs [plugin] how to write pages here: markdown, and each plugin's blocks — read before writing one;
|
|
32
37
|
with a plugin's name, only its docs
|
|
33
38
|
whiteboard events [filters] print recorded events as ndjson; --follow: then each new one as it comes
|
|
@@ -68,6 +73,7 @@ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? {
|
|
|
68
73
|
since: { type: "string" },
|
|
69
74
|
last: { type: "string" },
|
|
70
75
|
follow: { type: "boolean" },
|
|
76
|
+
id: { type: "string" },
|
|
71
77
|
help: {
|
|
72
78
|
type: "boolean",
|
|
73
79
|
short: "h"
|
|
@@ -359,6 +365,81 @@ switch (cmd) {
|
|
|
359
365
|
console.log(`${base}/${pageId(project, positionals[0] ?? "")}`);
|
|
360
366
|
break;
|
|
361
367
|
}
|
|
368
|
+
case "close": {
|
|
369
|
+
const target = positionals[0];
|
|
370
|
+
if (!target) throw new Error("usage: whiteboard close <page|file>");
|
|
371
|
+
const proj = needProject();
|
|
372
|
+
const id = pageId(proj, target);
|
|
373
|
+
if (id.startsWith("-/")) throw new Error(`${target} is a file of the repository, not a page: close is for the pages in ${relFile(proj.pagesDir)}`);
|
|
374
|
+
const file = path.join(proj.pagesDir, `${id}.md`);
|
|
375
|
+
const exists = fs.existsSync(file);
|
|
376
|
+
const base = await running(proj);
|
|
377
|
+
if (base) try {
|
|
378
|
+
const listening = (await (await fetch(`${base}/api/listeners?page=${encodeURIComponent(id)}`)).json()).filter((l) => !l.fallback && l.page === id);
|
|
379
|
+
if (listening.length) console.error(`whiteboard: ${listening.length} wait or watch still listens on ${id}; stop it, it will hear nothing more`);
|
|
380
|
+
} catch {}
|
|
381
|
+
if (exists) fs.rmSync(file);
|
|
382
|
+
const removed = prune(proj.eventsFile, id);
|
|
383
|
+
if (!exists && !removed) {
|
|
384
|
+
console.error(`whiteboard: there is no page ${id}, nor events of it`);
|
|
385
|
+
process.exit(1);
|
|
386
|
+
}
|
|
387
|
+
console.log(`closed ${id}: ${exists ? "removed its file" : "it had no file"}, and ${removed} event${removed === 1 ? "" : "s"} from the log`);
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case "prune": {
|
|
391
|
+
const target = positionals[0];
|
|
392
|
+
if (!target) throw new Error("usage: whiteboard prune <page|file> [--type <type>] [--id <event id>]");
|
|
393
|
+
const proj = needProject();
|
|
394
|
+
const id = pageId(proj, target);
|
|
395
|
+
const removed = prune(proj.eventsFile, id, (e) => (!opts.type || e.type === opts.type) && (!opts.id || e.id === opts.id));
|
|
396
|
+
const which = [opts.type && `of type ${opts.type}`, opts.id && `with id ${opts.id}`].filter(Boolean).join(", ");
|
|
397
|
+
console.log(`pruned ${removed} event${removed === 1 ? "" : "s"} of ${id}${which ? ` (${which})` : ""} from the log; the page stays`);
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "edit": {
|
|
401
|
+
const eventId = positionals[0];
|
|
402
|
+
if (!eventId || !opts.data) throw new Error("usage: whiteboard edit <event id> --data <json> (merged into the event's data)");
|
|
403
|
+
const proj = needProject();
|
|
404
|
+
let data;
|
|
405
|
+
try {
|
|
406
|
+
data = JSON.parse(opts.data);
|
|
407
|
+
} catch {
|
|
408
|
+
throw new Error("--data must be a JSON object");
|
|
409
|
+
}
|
|
410
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("--data must be a JSON object");
|
|
411
|
+
console.log(JSON.stringify(editEvent(proj.eventsFile, eventId, data)));
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case "scroll": {
|
|
415
|
+
const [target, ...where] = positionals;
|
|
416
|
+
const to = where.join(" ").trim();
|
|
417
|
+
if (!target || !to) throw new Error("usage: whiteboard scroll <page|file> <heading, form name or text>");
|
|
418
|
+
const proj = needProject();
|
|
419
|
+
const id = pageId(proj, target);
|
|
420
|
+
const base = await ensureServer();
|
|
421
|
+
const rendered = await (await fetch(`${base}/api/render?page=${encodeURIComponent(id)}`)).json().catch(() => null);
|
|
422
|
+
const text = (rendered?.html ?? "").replace(/<[^>]+>/g, " ").replace(/&[a-z#0-9]+;/gi, " ").replace(/\s+/g, " ").toLowerCase();
|
|
423
|
+
const named = new RegExp(`<form[^>]*\\bname="${to.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"`).test(rendered?.html ?? "");
|
|
424
|
+
if (rendered && !named && !text.includes(to.replace(/\s+/g, " ").toLowerCase())) {
|
|
425
|
+
console.error(`whiteboard: nothing on ${id} matches ${JSON.stringify(to)} (a heading's text, a form's name, or text on the page)`);
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
428
|
+
const { tabs } = await (await fetch(`${base}/api/scroll`, {
|
|
429
|
+
method: "POST",
|
|
430
|
+
headers: { "content-type": "application/json" },
|
|
431
|
+
body: JSON.stringify({
|
|
432
|
+
page: id,
|
|
433
|
+
to
|
|
434
|
+
})
|
|
435
|
+
})).json();
|
|
436
|
+
if (!tabs) {
|
|
437
|
+
console.error(`whiteboard: no browser has ${id} open; \`whiteboard show ${target}\` prints its URL`);
|
|
438
|
+
process.exit(1);
|
|
439
|
+
}
|
|
440
|
+
console.log(`scrolled ${tabs} tab${tabs > 1 ? "s" : ""} of ${id} to ${JSON.stringify(to)}`);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
362
443
|
case "docs": {
|
|
363
444
|
const info = await api("/api/docs");
|
|
364
445
|
for (const e of info.errors) console.error(`config error: ${e}`);
|
|
@@ -429,16 +510,31 @@ switch (cmd) {
|
|
|
429
510
|
const fallback = !f.page;
|
|
430
511
|
let recheck = () => {};
|
|
431
512
|
const others = fallback ? (await listen(f, cmd, true), await otherListeners(() => recheck())) : null;
|
|
513
|
+
const held = /* @__PURE__ */ new Set();
|
|
514
|
+
const skip = (e) => {
|
|
515
|
+
if (!held.has(e.id)) {
|
|
516
|
+
held.add(e.id);
|
|
517
|
+
setTimeout(() => recheck(), 500).unref();
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
return takenByOther(others(), e);
|
|
521
|
+
};
|
|
432
522
|
handOut(proj.eventsFile, f, (e) => console.log(JSON.stringify(e)), {
|
|
433
523
|
count: cmd === "wait" ? Number(opts.count ?? 1) : Infinity,
|
|
434
524
|
forAgent: forAgent(handedOut),
|
|
435
525
|
...others && {
|
|
436
|
-
skip
|
|
526
|
+
skip,
|
|
437
527
|
recheck: (again) => {
|
|
438
528
|
recheck = again;
|
|
439
529
|
}
|
|
440
530
|
}
|
|
441
|
-
}).then(() =>
|
|
531
|
+
}).then(async () => {
|
|
532
|
+
if (cmd === "wait" && !fallback) try {
|
|
533
|
+
const pages = await api(`/api/status?page=${encodeURIComponent(f.page)}`);
|
|
534
|
+
for (const p of pages) if (p.open.length) console.error(`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`);
|
|
535
|
+
} catch {}
|
|
536
|
+
process.exit(0);
|
|
537
|
+
});
|
|
442
538
|
if (!fallback) listen(f, cmd);
|
|
443
539
|
if (opts.timeout && cmd === "wait") setTimeout(() => {
|
|
444
540
|
console.error("timeout");
|
package/dist/client/runtime.js
CHANGED
|
@@ -86,6 +86,8 @@ const listeners$1 = /* @__PURE__ */ new Set();
|
|
|
86
86
|
const managed = (form) => isQuestionName(form.getAttribute("name") ?? "") && !form.hasAttribute("action");
|
|
87
87
|
const forms = () => [...root$1.querySelectorAll("form")].filter(managed);
|
|
88
88
|
const keepsOwnFields = (form) => !!form.closest("[data-wb-self]");
|
|
89
|
+
const otherText = (option) => option.closest("label")?.querySelector("[data-wb-other-text]") ?? null;
|
|
90
|
+
const isOther = (el) => el instanceof HTMLInputElement && el.hasAttribute("data-wb-other");
|
|
89
91
|
function readForm(form) {
|
|
90
92
|
const data = {};
|
|
91
93
|
const elements = [...form.elements];
|
|
@@ -93,6 +95,7 @@ function readForm(form) {
|
|
|
93
95
|
for (const el of elements) if (el.name && el.type === "checkbox") boxes[el.name] = (boxes[el.name] ?? 0) + 1;
|
|
94
96
|
for (const el of elements) {
|
|
95
97
|
if (!el.name || el.type === "submit" || el.type === "button" || el.type === "reset" || el.type === "file") continue;
|
|
98
|
+
if (isOther(el)) el.value = otherText(el)?.value.trim() ?? "";
|
|
96
99
|
if (el.type === "checkbox") {
|
|
97
100
|
if (boxes[el.name] > 1) {
|
|
98
101
|
const list = data[el.name] ??= [];
|
|
@@ -107,7 +110,9 @@ function readForm(form) {
|
|
|
107
110
|
return data;
|
|
108
111
|
}
|
|
109
112
|
function writeForm(form, data) {
|
|
110
|
-
|
|
113
|
+
const elements = [...form.elements];
|
|
114
|
+
const listed = (name) => elements.filter((e) => e.name === name && !isOther(e) && (e.type === "radio" || e.type === "checkbox")).map((e) => e.value);
|
|
115
|
+
for (const el of elements) {
|
|
111
116
|
if (!el.name || !(el.name in data) || [
|
|
112
117
|
"submit",
|
|
113
118
|
"button",
|
|
@@ -115,11 +120,28 @@ function writeForm(form, data) {
|
|
|
115
120
|
"file"
|
|
116
121
|
].includes(el.type)) continue;
|
|
117
122
|
const v = data[el.name];
|
|
123
|
+
if (isOther(el)) {
|
|
124
|
+
const own = listed(el.name);
|
|
125
|
+
const rest = (Array.isArray(v) ? v : [v]).filter((x) => typeof x === "string" && x !== "" && !own.includes(x));
|
|
126
|
+
el.checked = rest.length > 0;
|
|
127
|
+
const text = otherText(el);
|
|
128
|
+
if (text && text !== document.activeElement) text.value = rest.join(", ");
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
118
131
|
if (el.type === "checkbox") el.checked = Array.isArray(v) ? v.includes(el.value) : !!v;
|
|
119
132
|
else if (el.type === "radio") el.checked = v === el.value;
|
|
120
133
|
else el.value = v == null ? "" : String(v);
|
|
121
134
|
}
|
|
122
135
|
}
|
|
136
|
+
/** Typing in an other-option's box picks it (and an empty box, for a checkbox, unpicks it). */
|
|
137
|
+
function onOtherInput(e) {
|
|
138
|
+
const text = e.target;
|
|
139
|
+
if (!text.matches?.("[data-wb-other-text]")) return;
|
|
140
|
+
const option = text.closest("label")?.querySelector("[data-wb-other]");
|
|
141
|
+
if (!option) return;
|
|
142
|
+
if (text.value.trim()) option.checked = true;
|
|
143
|
+
else if (option.type === "checkbox") option.checked = false;
|
|
144
|
+
}
|
|
123
145
|
const draftKey = (form) => `wb-draft:${page$1}:${form.getAttribute("name")}`;
|
|
124
146
|
function saveDraft(e) {
|
|
125
147
|
const form = e.target?.closest?.("form");
|
|
@@ -223,6 +245,7 @@ function trackForms(el, pageId, core) {
|
|
|
223
245
|
root$1 = el;
|
|
224
246
|
page$1 = pageId;
|
|
225
247
|
api$1 = core;
|
|
248
|
+
document.addEventListener("input", onOtherInput);
|
|
226
249
|
document.addEventListener("input", saveDraft);
|
|
227
250
|
document.addEventListener("change", saveDraft);
|
|
228
251
|
document.addEventListener("submit", onSubmit);
|
|
@@ -247,29 +270,60 @@ const formsApi = {
|
|
|
247
270
|
}
|
|
248
271
|
};
|
|
249
272
|
// src/client/toast.ts
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
box
|
|
253
|
-
box.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
273
|
+
let box = null;
|
|
274
|
+
function place(corner) {
|
|
275
|
+
if (box?.isConnected) return box;
|
|
276
|
+
box = document.createElement("div");
|
|
277
|
+
box.className = "wb-toasts";
|
|
278
|
+
box.setAttribute("role", "status");
|
|
279
|
+
box.setAttribute("aria-live", "polite");
|
|
280
|
+
corner.append(box);
|
|
281
|
+
return box;
|
|
282
|
+
}
|
|
283
|
+
function createToast(corner) {
|
|
284
|
+
return function toast(text, { kind = "info", ms = 7e3, onClick, onDismiss, name, order = 0 } = {}) {
|
|
285
|
+
const el = document.createElement("button");
|
|
286
|
+
el.type = "button";
|
|
287
|
+
el.className = "wb-toast";
|
|
288
|
+
el.dataset.kind = kind;
|
|
289
|
+
if (name) el.dataset.toast = name;
|
|
290
|
+
el.style.order = String(order);
|
|
291
|
+
const label = document.createElement("span");
|
|
292
|
+
label.className = "wb-toast-text";
|
|
293
|
+
label.textContent = text;
|
|
294
|
+
el.append(label);
|
|
295
|
+
if (onDismiss) {
|
|
296
|
+
const x = document.createElement("span");
|
|
297
|
+
x.className = "wb-toast-dismiss";
|
|
298
|
+
x.textContent = "✕";
|
|
299
|
+
x.title = x.ariaLabel = "Dismiss";
|
|
300
|
+
el.append(x);
|
|
272
301
|
}
|
|
302
|
+
const close = () => el.remove();
|
|
303
|
+
el.addEventListener("click", (e) => {
|
|
304
|
+
if (onDismiss && e.target.closest(".wb-toast-dismiss")) {
|
|
305
|
+
close();
|
|
306
|
+
onDismiss();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (ms) close();
|
|
310
|
+
onClick?.();
|
|
311
|
+
});
|
|
312
|
+
if (ms) setTimeout(close, ms);
|
|
313
|
+
place(corner()).append(el);
|
|
314
|
+
return {
|
|
315
|
+
close,
|
|
316
|
+
update: (next) => {
|
|
317
|
+
label.textContent = next;
|
|
318
|
+
},
|
|
319
|
+
hide: () => {
|
|
320
|
+
el.hidden = true;
|
|
321
|
+
},
|
|
322
|
+
show: () => {
|
|
323
|
+
if (!el.isConnected) place(corner()).append(el);
|
|
324
|
+
el.hidden = false;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
273
327
|
};
|
|
274
328
|
}
|
|
275
329
|
// src/client/read.ts
|
|
@@ -372,6 +426,42 @@ function markdown(text) {
|
|
|
372
426
|
}
|
|
373
427
|
return got;
|
|
374
428
|
}
|
|
429
|
+
// src/client/scroll.ts
|
|
430
|
+
const norm = (s) => s.replace(/\s+/g, " ").trim().toLowerCase();
|
|
431
|
+
function findTarget(root, where) {
|
|
432
|
+
const want = norm(where);
|
|
433
|
+
const headings = [...root.querySelectorAll("h1, h2, h3, h4, h5, h6, summary")];
|
|
434
|
+
const heading = headings.find((h) => norm(h.textContent ?? "") === want) ?? headings.find((h) => norm(h.textContent ?? "").includes(want));
|
|
435
|
+
if (heading) return heading;
|
|
436
|
+
const byName = [...root.querySelectorAll("form[name]")].find((f) => f.getAttribute("name") === where.trim());
|
|
437
|
+
if (byName) return byName;
|
|
438
|
+
const byId = root.querySelector(`#${CSS.escape(where.trim())}`);
|
|
439
|
+
if (byId) return byId;
|
|
440
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
441
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) if (norm(n.textContent ?? "").includes(want) && n.parentElement && !n.parentElement.closest("script, style")) return n.parentElement;
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
function scrollToTarget(root, where) {
|
|
445
|
+
const target = findTarget(root, where);
|
|
446
|
+
if (!target) return false;
|
|
447
|
+
for (let d = (target.tagName === "SUMMARY" ? target.parentElement?.parentElement : target)?.closest("details"); d; d = d.parentElement?.closest("details")) d.open = true;
|
|
448
|
+
requestAnimationFrame(() => {
|
|
449
|
+
let offset = (document.querySelector(".wb-nav")?.getBoundingClientRect().height ?? 0) + 12;
|
|
450
|
+
for (let d = target.parentElement?.closest("details"); d; d = d.parentElement?.closest("details")) {
|
|
451
|
+
const summary = d.querySelector(":scope > summary");
|
|
452
|
+
if (summary && summary !== target) offset += summary.getBoundingClientRect().height;
|
|
453
|
+
}
|
|
454
|
+
scrollTo({
|
|
455
|
+
top: Math.max(0, scrollY + target.getBoundingClientRect().top - offset),
|
|
456
|
+
behavior: "smooth"
|
|
457
|
+
});
|
|
458
|
+
target.classList.remove("wb-flash");
|
|
459
|
+
target.offsetWidth;
|
|
460
|
+
target.classList.add("wb-flash");
|
|
461
|
+
setTimeout(() => target.classList.remove("wb-flash"), 2e3);
|
|
462
|
+
});
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
375
465
|
// src/client/runtime.ts
|
|
376
466
|
const handoff = JSON.parse(document.getElementById("wb-page").textContent);
|
|
377
467
|
const root = document.getElementById("wb-root");
|
|
@@ -458,7 +548,7 @@ const api = {
|
|
|
458
548
|
baseTitle = title;
|
|
459
549
|
writeTitle();
|
|
460
550
|
},
|
|
461
|
-
toast,
|
|
551
|
+
toast: createToast(() => corner),
|
|
462
552
|
...formsApi
|
|
463
553
|
};
|
|
464
554
|
const changeListeners = /* @__PURE__ */ new Set();
|
|
@@ -506,6 +596,10 @@ function connect() {
|
|
|
506
596
|
};
|
|
507
597
|
go();
|
|
508
598
|
});
|
|
599
|
+
es.addEventListener("scroll", (e) => {
|
|
600
|
+
const { to } = JSON.parse(e.data);
|
|
601
|
+
if (!scrollToTarget(root, to)) console.warn(`whiteboard scroll: nothing on the page matches ${JSON.stringify(to)}`);
|
|
602
|
+
});
|
|
509
603
|
es.addEventListener("style", () => {
|
|
510
604
|
for (const link of document.querySelectorAll("link[rel=stylesheet]")) {
|
|
511
605
|
const url = new URL(link.href);
|
|
@@ -18,7 +18,7 @@ function claudeCode() {
|
|
|
18
18
|
session: () => process.env.CLAUDE_CODE_SESSION_ID || null,
|
|
19
19
|
commands: {
|
|
20
20
|
hook: {
|
|
21
|
-
description: "what Claude Code runs on an event (stop, prompt or session): report what is open on the session's pages;
|
|
21
|
+
description: "what Claude Code runs on an event (stop, prompt or session): report what is open on the session's pages; a stop with questions nobody listens for continues the turn once, to start a wait",
|
|
22
22
|
args: "<stop|prompt|session>",
|
|
23
23
|
async run(ctx) {
|
|
24
24
|
const mode = ctx.positionals[0];
|
|
@@ -48,7 +48,8 @@ function hookInput() {
|
|
|
48
48
|
}
|
|
49
49
|
const relFile = (file) => path.relative(process.cwd(), file) || file;
|
|
50
50
|
async function hook(ctx, mode) {
|
|
51
|
-
const
|
|
51
|
+
const input = hookInput();
|
|
52
|
+
const session = input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null;
|
|
52
53
|
const busy = (await ctx.status()).filter((p) => p.unpicked.length || p.open.length);
|
|
53
54
|
const mine = busy.filter((p) => session && p.owner === session);
|
|
54
55
|
if (mode === "stop") {
|
|
@@ -58,7 +59,17 @@ async function hook(ctx, mode) {
|
|
|
58
59
|
const l = openOn(p, { waiting: false });
|
|
59
60
|
return `${l.slice(0, -1).join("; ")} ${l.at(-1)}`;
|
|
60
61
|
};
|
|
61
|
-
|
|
62
|
+
const shown = `whiteboard: ${loose.map((p) => `${p.page}: ${said(p)}`).join(" · ")}`;
|
|
63
|
+
if (input.stop_hook_active) {
|
|
64
|
+
console.log(JSON.stringify({ systemMessage: shown }));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const reason = loose.map((p) => `On your whiteboard page ${p.page}: ${openOn(p, { waiting: false }).slice(0, -1).join("; ")}. Run \`whiteboard wait --page ${relFile(p.file)}\` in the background before ending your turn.`).join("\n");
|
|
68
|
+
console.log(JSON.stringify({
|
|
69
|
+
decision: "block",
|
|
70
|
+
reason,
|
|
71
|
+
systemMessage: shown
|
|
72
|
+
}));
|
|
62
73
|
return;
|
|
63
74
|
}
|
|
64
75
|
const out = [];
|