@bigmistqke/whiteboard 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +628 -2
- package/bin/whiteboard.ts +488 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/whiteboard.js +542 -0
- package/dist/client/runtime.js +544 -0
- package/dist/define.js +7 -0
- package/dist/plugins/callout/README.md +13 -0
- package/dist/plugins/callout/index.js +27 -0
- package/dist/plugins/callout/style.css +12 -0
- package/dist/plugins/chat/README.md +46 -0
- package/dist/plugins/chat/client.js +3 -0
- package/dist/plugins/chat/index.js +47 -0
- package/dist/plugins/chat/style.css +24 -0
- package/dist/plugins/claude-code/index.js +120 -0
- package/dist/plugins/code/README.md +42 -0
- package/dist/plugins/code/diff.js +65 -0
- package/dist/plugins/code/index.js +77 -0
- package/dist/plugins/code/style.css +29 -0
- package/dist/plugins/comments/client.js +10 -0
- package/dist/plugins/comments/index.js +54 -0
- package/dist/plugins/comments/style.css +40 -0
- package/dist/plugins/details/README.md +17 -0
- package/dist/plugins/details/index.js +17 -0
- package/dist/plugins/details/style.css +3 -0
- package/dist/plugins/forge/README.md +12 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +111 -0
- package/dist/plugins/form/index.js +102 -0
- package/dist/plugins/form/style.css +41 -0
- package/dist/plugins/gallery/README.md +30 -0
- package/dist/plugins/gallery/client.js +1 -0
- package/dist/plugins/gallery/index.js +74 -0
- package/dist/plugins/gallery/style.css +27 -0
- package/dist/plugins/grid/README.md +33 -0
- package/dist/plugins/grid/index.js +33 -0
- package/dist/plugins/grid/style.css +25 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/client.js +1 -0
- package/dist/plugins/iframe/index.js +40 -0
- package/dist/plugins/iframe/style.css +29 -0
- package/dist/plugins/index.js +30 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +35 -0
- package/dist/plugins/mermaid/style.css +16 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +17 -0
- package/dist/plugins/terminal/client.js +41 -0
- package/dist/plugins/terminal/host.js +332 -0
- package/dist/plugins/terminal/index.js +171 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +57 -0
- package/dist/plugins/terminal/style.css +357 -0
- package/dist/solid/index.js +36 -0
- package/dist/src/auth.js +54 -0
- package/dist/src/client/page/base.css +295 -0
- package/dist/src/client/page/main.js +1228 -0
- package/dist/src/config.js +76 -0
- package/dist/src/events.js +183 -0
- package/dist/src/html.js +34 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/load.js +77 -0
- package/dist/src/loader.js +126 -0
- package/dist/src/package.js +33 -0
- package/dist/src/pages/blocks.js +50 -0
- package/dist/src/pages/index.js +15 -0
- package/dist/src/pages/markdown.js +410 -0
- package/dist/src/pages/render.js +311 -0
- package/dist/src/plugins.js +238 -0
- package/dist/src/running.js +24 -0
- package/dist/src/serve.js +71 -0
- package/dist/src/server.js +725 -0
- package/dist/src/status.js +71 -0
- package/package.json +131 -4
- package/plugins/callout/README.md +13 -0
- package/plugins/callout/index.ts +25 -0
- package/plugins/callout/style.css +12 -0
- package/plugins/chat/README.md +46 -0
- package/plugins/chat/autosize.ts +101 -0
- package/plugins/chat/client.tsx +93 -0
- package/plugins/chat/index.ts +61 -0
- package/plugins/chat/style.css +24 -0
- package/plugins/claude-code/index.ts +136 -0
- package/plugins/code/README.md +42 -0
- package/plugins/code/diff.ts +64 -0
- package/plugins/code/index.ts +94 -0
- package/plugins/code/style.css +29 -0
- package/plugins/comments/client.ts +492 -0
- package/plugins/comments/index.ts +54 -0
- package/plugins/comments/style.css +40 -0
- package/plugins/details/README.md +17 -0
- package/plugins/details/index.ts +21 -0
- package/plugins/details/style.css +3 -0
- package/plugins/forge/README.md +12 -0
- package/plugins/forge/index.ts +71 -0
- package/plugins/form/README.md +111 -0
- package/plugins/form/index.ts +104 -0
- package/plugins/form/style.css +41 -0
- package/plugins/gallery/README.md +30 -0
- package/plugins/gallery/client.tsx +64 -0
- package/plugins/gallery/index.ts +67 -0
- package/plugins/gallery/style.css +27 -0
- package/plugins/grid/README.md +33 -0
- package/plugins/grid/index.ts +36 -0
- package/plugins/grid/style.css +25 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/client.ts +46 -0
- package/plugins/iframe/index.ts +54 -0
- package/plugins/iframe/style.css +29 -0
- package/plugins/index.ts +21 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +40 -0
- package/plugins/mermaid/style.css +16 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +27 -0
- package/plugins/terminal/client.ts +317 -0
- package/plugins/terminal/host.ts +326 -0
- package/plugins/terminal/index.ts +138 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/server.ts +215 -0
- package/plugins/terminal/sizes.ts +60 -0
- package/plugins/terminal/style.css +71 -0
- package/skills/whiteboard/SKILL.md +302 -0
- package/solid/index.tsx +59 -0
- package/src/auth.ts +66 -0
- package/src/client/forms.ts +185 -0
- package/src/client/markdown.ts +36 -0
- package/src/client/page/base.css +295 -0
- package/src/client/page/elsewhere.ts +70 -0
- package/src/client/page/fresh.ts +205 -0
- package/src/client/page/live.ts +30 -0
- package/src/client/page/main.ts +272 -0
- package/src/client/page/orphans.ts +46 -0
- package/src/client/page/sort.ts +38 -0
- package/src/client/page/theme.ts +32 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +182 -0
- package/src/client/read.ts +73 -0
- package/src/client/runtime.ts +183 -0
- package/src/client/toast.ts +25 -0
- package/src/config.ts +96 -0
- package/src/define.ts +612 -0
- package/src/events.ts +218 -0
- package/src/html.ts +40 -0
- package/src/icons.ts +8 -0
- package/src/load.ts +89 -0
- package/src/loader.ts +112 -0
- package/src/package.ts +39 -0
- package/src/pages/blocks.ts +70 -0
- package/src/pages/index.ts +42 -0
- package/src/pages/markdown.ts +364 -0
- package/src/pages/render.ts +233 -0
- package/src/plugins.ts +197 -0
- package/src/running.ts +22 -0
- package/src/serve.ts +52 -0
- package/src/server.ts +667 -0
- package/src/status.ts +113 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// What the terminal's routes do, forwarded to its host: the sessions (the drawer's tabs), starting
|
|
2
|
+
// one, its keystrokes and size, following its output, closing it, stopping them all.
|
|
3
|
+
//
|
|
4
|
+
// The sessions run in a process of their own (host.js), which this starts the first time a session
|
|
5
|
+
// starts and reaches over a Unix socket. So they outlive the page server: a restarted server
|
|
6
|
+
// connects to the same host and finds them as they were. Each open drawer gets its own connection to
|
|
7
|
+
// the host, which sends it the whole screen of its tab first and then follows the output.
|
|
8
|
+
//
|
|
9
|
+
// A session is the user's shell. A tab started with a program runs it in the shell, and when it
|
|
10
|
+
// exits the shell takes over in the same tab (`$SHELL -c '"$@"; exec "$0" -l' $SHELL <program>`),
|
|
11
|
+
// so leaving the program leaves a prompt, not a dead tab.
|
|
12
|
+
//
|
|
13
|
+
// No whiteboard in it: give it the folder the session runs in and a folder for its socket and log.
|
|
14
|
+
// It doesn't check who asks; whoever mounts it must (it runs code).
|
|
15
|
+
import fs from 'node:fs'
|
|
16
|
+
import net from 'node:net'
|
|
17
|
+
import os from 'node:os'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import crypto from 'node:crypto'
|
|
20
|
+
import { spawn } from 'node:child_process'
|
|
21
|
+
import { createRequire } from 'node:module'
|
|
22
|
+
import { fileURLToPath } from 'node:url'
|
|
23
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
24
|
+
|
|
25
|
+
/** A session, as a tab. */
|
|
26
|
+
export interface Session {
|
|
27
|
+
id: string
|
|
28
|
+
label: string
|
|
29
|
+
running: boolean
|
|
30
|
+
exited: number | null
|
|
31
|
+
started: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The tabs, and whether the terminal can run (node-pty is installed). */
|
|
35
|
+
export interface Sessions {
|
|
36
|
+
available: boolean
|
|
37
|
+
sessions: Session[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface StartOptions {
|
|
41
|
+
/** the session to start in; a new tab without one */
|
|
42
|
+
id?: string
|
|
43
|
+
/** a program to run in the shell, with its arguments; the shell alone without one */
|
|
44
|
+
program?: string[]
|
|
45
|
+
/** start again in `id`, running what it ran before, even when it still runs */
|
|
46
|
+
restart?: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A reply from the host: one JSON object, its fields by request (see host.ts). */
|
|
50
|
+
type Reply = Record<string, any>
|
|
51
|
+
|
|
52
|
+
const require = createRequire(import.meta.url)
|
|
53
|
+
const HOST = fileURLToPath(new URL(`./host${path.extname(fileURLToPath(import.meta.url))}`, import.meta.url))
|
|
54
|
+
|
|
55
|
+
const hasPty = () => { try { require.resolve('node-pty'); return true } catch { return false } }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Where the host listens: `host.sock` in the terminal's folder, or, when that path is too long for
|
|
59
|
+
* a Unix socket (about 100 bytes), a name in /tmp made from it.
|
|
60
|
+
*/
|
|
61
|
+
export function hostSocket(home: string): string {
|
|
62
|
+
const own = path.join(home, 'host.sock')
|
|
63
|
+
return Buffer.byteLength(own) < 100 ? own : path.join('/tmp', `wb-term-${crypto.createHash('sha1').update(home).digest('hex').slice(0, 12)}.sock`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `dir` the folder the sessions run in, `home` where the socket and log go */
|
|
67
|
+
export function createTerminal({ dir, home }: { dir: string; home: string }) {
|
|
68
|
+
const own = hostSocket(home)
|
|
69
|
+
const log = path.join(home, 'host.log')
|
|
70
|
+
|
|
71
|
+
// ---- the host -------------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
/** A connection to the host, or null when none runs. */
|
|
74
|
+
function connect(): Promise<net.Socket | null> {
|
|
75
|
+
return new Promise(resolve => {
|
|
76
|
+
const conn = net.connect(own)
|
|
77
|
+
conn.once('connect', () => resolve(conn))
|
|
78
|
+
conn.once('error', () => resolve(null))
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Send one request; its one reply, or null when no host runs. */
|
|
83
|
+
async function ask(req: Record<string, unknown>, timeout = 2000): Promise<Reply | null> {
|
|
84
|
+
const conn = await connect()
|
|
85
|
+
if (!conn) return null
|
|
86
|
+
return new Promise(resolve => {
|
|
87
|
+
let buf = ''
|
|
88
|
+
const done = (value: Reply | null) => { clearTimeout(timer); conn.destroy(); resolve(value) }
|
|
89
|
+
const timer = setTimeout(() => done(null), timeout)
|
|
90
|
+
conn.setEncoding('utf8')
|
|
91
|
+
conn.on('data', (c: string) => { buf += c; const nl = buf.indexOf('\n'); if (nl >= 0) { try { done(JSON.parse(buf.slice(0, nl))) } catch { done(null) } } })
|
|
92
|
+
conn.on('error', () => done(null))
|
|
93
|
+
conn.on('end', () => done(null))
|
|
94
|
+
conn.write(JSON.stringify(req) + '\n')
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Start the host (detached: it outlives this server) and wait until it answers. */
|
|
99
|
+
async function startHost(): Promise<boolean> {
|
|
100
|
+
const out = fs.openSync(log, 'a')
|
|
101
|
+
const child = spawn(process.execPath, [HOST, dir, own], { cwd: dir, detached: true, stdio: ['ignore', out, out], env: process.env })
|
|
102
|
+
child.unref()
|
|
103
|
+
fs.closeSync(out)
|
|
104
|
+
for (let i = 0; i < 40; i++) {
|
|
105
|
+
await new Promise(r => setTimeout(r, 100))
|
|
106
|
+
if (await ask({ t: 'list' }, 500)) return true
|
|
107
|
+
}
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const shell = process.env.SHELL || '/bin/sh'
|
|
112
|
+
|
|
113
|
+
/** The sessions, as tabs: `{ id, label, running, exited, started }` each. */
|
|
114
|
+
async function sessions(): Promise<Sessions> {
|
|
115
|
+
const reply = await ask({ t: 'list' })
|
|
116
|
+
return { available: hasPty(), sessions: reply?.sessions ?? [] }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The screens as HTML rows by session id, for a page's first render. */
|
|
120
|
+
async function screens(list: Session[]): Promise<Record<string, string>> {
|
|
121
|
+
const out: Record<string, string> = {}
|
|
122
|
+
await Promise.all(list.map(async s => { out[s.id] = (await ask({ t: 'html', id: s.id }, 300))?.html ?? '' }))
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ---- what the routes do --------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
const failure = (message: string, status = 500) => Object.assign(new Error(message), { status })
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Start a tab: the shell, or `program` in it (a new tab without `id`). In a running session it
|
|
132
|
+
* reports it (`already`) unless `restart`; restarting without a program runs what it ran before.
|
|
133
|
+
*/
|
|
134
|
+
async function start({ id, program = [], restart = false }: StartOptions = {}) {
|
|
135
|
+
if (!hasPty()) throw failure('the terminal needs node-pty: npm install node-pty')
|
|
136
|
+
const request = program.length
|
|
137
|
+
? { t: 'start', id, command: shell, args: ['-c', '"$@"; exec "$0" -l', shell, ...program], label: path.basename(program[0]!), restart }
|
|
138
|
+
: restart && id != null
|
|
139
|
+
? { t: 'start', id, restart }
|
|
140
|
+
: { t: 'start', id, command: shell, args: ['-l'], label: path.basename(shell), restart }
|
|
141
|
+
let reply = await ask(request)
|
|
142
|
+
if (!reply) {
|
|
143
|
+
if (!(await startHost())) throw failure(`the terminal's host did not start; see ${log}`)
|
|
144
|
+
reply = await ask(request)
|
|
145
|
+
}
|
|
146
|
+
if (!reply || reply.error) throw failure(reply?.error ?? 'no answer from the terminal host')
|
|
147
|
+
return { available: true, session: reply.session ?? '1', already: !!reply.already }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const input = async (id: string, data: string) => { await ask({ t: 'input', id, d: data }) }
|
|
151
|
+
/** The size that fits drawer `viewer`; `active`: the reader is using that drawer now (see host.ts, Sizes). */
|
|
152
|
+
const resize = async (id: string, viewer: string, cols: number, rows: number, active = false) => { await ask({ t: 'resize', id, viewer, cols, rows, active }) }
|
|
153
|
+
|
|
154
|
+
/** End one session and drop its tab. */
|
|
155
|
+
async function close(id: string) {
|
|
156
|
+
await ask({ t: 'close', id })
|
|
157
|
+
return { ok: true }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Follow a session as server-sent events on `res`: `sessions` (the tabs) and `screen` first, then
|
|
162
|
+
* `data`, `exit` and `sessions` as they come.
|
|
163
|
+
*/
|
|
164
|
+
async function stream(req: IncomingMessage, res: ServerResponse, id: string | undefined, viewer?: string) {
|
|
165
|
+
res.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-store', connection: 'keep-alive' })
|
|
166
|
+
res.write(': terminal\n\n')
|
|
167
|
+
const ping = setInterval(() => res.write(': ping\n\n'), 25000)
|
|
168
|
+
const conn = await connect()
|
|
169
|
+
if (!conn) {
|
|
170
|
+
// no host runs yet: say so, and have the browser ask again shortly, so that a tab started
|
|
171
|
+
// meanwhile (from the command line, say) shows up
|
|
172
|
+
clearInterval(ping)
|
|
173
|
+
res.end('retry: 2000\nevent: none\ndata: {}\n\n')
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
// the host's messages, one per line, as server-sent events of the same name
|
|
177
|
+
let buf = ''
|
|
178
|
+
conn.setEncoding('utf8')
|
|
179
|
+
conn.on('data', (chunk: string) => {
|
|
180
|
+
buf += chunk
|
|
181
|
+
let nl
|
|
182
|
+
while ((nl = buf.indexOf('\n')) >= 0) {
|
|
183
|
+
const line = buf.slice(0, nl)
|
|
184
|
+
buf = buf.slice(nl + 1)
|
|
185
|
+
try {
|
|
186
|
+
const { t, ...data } = JSON.parse(line)
|
|
187
|
+
res.write(`event: ${t}\ndata: ${JSON.stringify(data)}\n\n`)
|
|
188
|
+
} catch { /* not a message */ }
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
// the host went away (stopped, or its program ended and it left): the page shows it as stopped
|
|
192
|
+
conn.on('close', () => { if (!res.writableEnded) res.write('event: exit\ndata: {"code":null}\n\n') })
|
|
193
|
+
conn.on('error', () => {})
|
|
194
|
+
req.on('close', () => { clearInterval(ping); conn.destroy() })
|
|
195
|
+
conn.write(JSON.stringify({ t: 'attach', id, viewer }) + '\n')
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** End the session and its host. */
|
|
199
|
+
async function stop() {
|
|
200
|
+
return { stopped: !!(await ask({ t: 'stop' })) }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Show the page at `path` (a path on this server) in the browser tab whose drawer the reader used
|
|
205
|
+
* last: for session `id`, or without one, of all sessions.
|
|
206
|
+
*/
|
|
207
|
+
async function open(id: string | undefined, path: string) {
|
|
208
|
+
if (!path.startsWith('/') || path.startsWith('//')) throw failure('open takes a path on this server, like /plan', 400)
|
|
209
|
+
const reply = await ask({ t: 'open', id, path })
|
|
210
|
+
if (!reply) throw failure('no terminal host runs', 404)
|
|
211
|
+
return { shown: Number(reply.shown ?? 0) }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { sessions, screens, start, input, resize, close, open, stream, stop }
|
|
215
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Whose size a session has. A session has one size, and several drawers (browser windows) can show
|
|
2
|
+
// it at once. It takes the size of the drawer the reader used last, its active viewer: the one that
|
|
3
|
+
// last reported being used (opening it, focus, a keystroke), else the first to report a size. The
|
|
4
|
+
// others show it at that size. When the active drawer goes, the session passes to the drawer used
|
|
5
|
+
// most recently of those left: after a moment, since a page switch reconnects the same window under
|
|
6
|
+
// a new viewer, which claims it again.
|
|
7
|
+
//
|
|
8
|
+
// No terminal in here: host.ts applies what these return.
|
|
9
|
+
|
|
10
|
+
export interface Sizes {
|
|
11
|
+
cols: number
|
|
12
|
+
rows: number
|
|
13
|
+
/** the drawers showing the session, by viewer id: the size that fits each, and when each was last used */
|
|
14
|
+
viewers: Map<string, { cols: number; rows: number; used: number }>
|
|
15
|
+
/** the viewer whose size the session has */
|
|
16
|
+
active: string | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A drawer reports the size that fits it; `used`: the reader uses it now. Returns the size the
|
|
21
|
+
* session should have: its own when the drawer is (now) the active one, else the session's as it is.
|
|
22
|
+
*/
|
|
23
|
+
export function report(s: Sizes, viewer: string, cols: number, rows: number, used: boolean, now = Date.now()): { cols: number; rows: number } {
|
|
24
|
+
const known = s.viewers.get(viewer)
|
|
25
|
+
s.viewers.set(viewer, { cols, rows, used: used ? now : known?.used ?? 0 })
|
|
26
|
+
if (used || !s.active || !s.viewers.has(s.active)) s.active = viewer
|
|
27
|
+
return s.active === viewer ? { cols, rows } : { cols: s.cols, rows: s.rows }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A drawer stopped showing the session. True when it was the active one: call `handOver` after a moment. */
|
|
31
|
+
export function leave(s: Sizes, viewer: string): boolean {
|
|
32
|
+
s.viewers.delete(viewer)
|
|
33
|
+
return s.active === viewer
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* After the active drawer `viewer` left: the drawer used most recently of those left becomes the
|
|
38
|
+
* active one. Returns the size the session should take, or null to leave it as it is (another drawer
|
|
39
|
+
* claimed the session in the meantime, or none is left).
|
|
40
|
+
*/
|
|
41
|
+
export function handOver(s: Sizes, viewer: string): { cols: number; rows: number } | null {
|
|
42
|
+
if (s.active !== viewer || s.viewers.has(viewer)) return null
|
|
43
|
+
const next = [...s.viewers].sort((a, b) => b[1].used - a[1].used)[0]
|
|
44
|
+
s.active = next?.[0] ?? null
|
|
45
|
+
return next ? { cols: next[1].cols, rows: next[1].rows } : null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Of several sessions, the one whose active drawer the reader used last: where "the browser the
|
|
50
|
+
* reader is in" is, for a program that doesn't know its own tab. Undefined when no drawer is active.
|
|
51
|
+
*/
|
|
52
|
+
export function lastUsed<S extends Sizes>(sessions: S[]): S | undefined {
|
|
53
|
+
let best: S | undefined
|
|
54
|
+
let at = -1
|
|
55
|
+
for (const s of sessions) {
|
|
56
|
+
const viewer = s.active ? s.viewers.get(s.active) : undefined
|
|
57
|
+
if (viewer && viewer.used > at) { best = s; at = viewer.used }
|
|
58
|
+
}
|
|
59
|
+
return best
|
|
60
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* The terminal drawer (see terminal.ts). Pages morph into each other on navigation, and the drawer is
|
|
2
|
+
named, so it keeps its place and size while the page around it changes. */
|
|
3
|
+
@view-transition { navigation: auto; }
|
|
4
|
+
|
|
5
|
+
/* How much of the window the drawer takes at the bottom, for the page to keep clear: its content
|
|
6
|
+
scrolls to above it, and its own fixed elements sit above it (the page's buttons at the bottom).
|
|
7
|
+
Registered as a length so that it computes to pixels a script can read. */
|
|
8
|
+
@property --wb-inset-bottom { syntax: '<length>'; inherits: true; initial-value: 0px; }
|
|
9
|
+
|
|
10
|
+
:root { --wb-term-h: 320px; --wb-term-bar: 34px; }
|
|
11
|
+
:root:has(body > #wb-terminal) { --wb-inset-bottom: var(--wb-term-bar); }
|
|
12
|
+
:root:has(body > #wb-terminal[data-state=open]) { --wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h)); }
|
|
13
|
+
|
|
14
|
+
#wb-terminal {
|
|
15
|
+
view-transition-name: wb-terminal;
|
|
16
|
+
position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
|
|
17
|
+
display: flex; flex-direction: column;
|
|
18
|
+
background: #0f1115; color: #d7dae0;
|
|
19
|
+
border-top: 1px solid #2a2f3a;
|
|
20
|
+
box-shadow: 0 -6px 24px rgb(0 0 0 / .18);
|
|
21
|
+
font: 500 12px/1 ui-sans-serif, system-ui, sans-serif;
|
|
22
|
+
}
|
|
23
|
+
body:has(> #wb-terminal) { padding-bottom: var(--wb-inset-bottom); }
|
|
24
|
+
|
|
25
|
+
.wb-term-grip { position: absolute; left: 0; right: 0; top: -4px; height: 8px; cursor: ns-resize; touch-action: none; }
|
|
26
|
+
.wb-term-bar { height: var(--wb-term-bar); display: flex; align-items: center; gap: 12px; padding: 0 10px 0 6px; flex: none; }
|
|
27
|
+
.wb-term-bar button {
|
|
28
|
+
font: inherit; color: inherit; background: transparent; border: 1px solid transparent; border-radius: 5px;
|
|
29
|
+
padding: 5px 8px; cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
.wb-term-bar button:hover { background: #1c2029; border-color: #2a2f3a; }
|
|
32
|
+
.wb-term-toggle { display: inline-flex; align-items: center; gap: 7px; letter-spacing: .04em; text-transform: uppercase; }
|
|
33
|
+
/* points up while closed (it opens upward), down while open */
|
|
34
|
+
.wb-term-chevron { width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; rotate: 45deg; translate: 0 -2px; transition: rotate .2s, translate .2s; }
|
|
35
|
+
#wb-terminal[data-state=collapsed] .wb-term-chevron { rotate: -135deg; translate: 0 2px; }
|
|
36
|
+
.wb-term-status { color: #8b93a3; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
37
|
+
.wb-term-actions { display: flex; gap: 4px; }
|
|
38
|
+
|
|
39
|
+
/* the tabs: one per session, the current one lit */
|
|
40
|
+
/* the bar: the toggle, what the current tab says (status, actions), then the tabs and "+" at the right */
|
|
41
|
+
.wb-term-tabs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
|
|
42
|
+
.wb-term-bar .wb-term-add { flex: none; }
|
|
43
|
+
.wb-term-tab { display: inline-flex; align-items: center; flex: none; border-radius: 5px; }
|
|
44
|
+
.wb-term-bar .wb-term-tab button { padding: 5px 4px 5px 8px; }
|
|
45
|
+
.wb-term-bar .wb-term-tab .wb-term-tab-close { padding: 5px 7px 5px 3px; opacity: .45; }
|
|
46
|
+
.wb-term-bar .wb-term-tab .wb-term-tab-close:hover { opacity: 1; background: transparent; border-color: transparent; }
|
|
47
|
+
.wb-term-bar .wb-term-tab button:hover { background: transparent; border-color: transparent; }
|
|
48
|
+
.wb-term-tab:hover { background: #1c2029; }
|
|
49
|
+
.wb-term-tab.wb-current { background: #232836; color: #fff; }
|
|
50
|
+
.wb-term-tab[data-exited] { color: #8b93a3; }
|
|
51
|
+
.wb-term-bar .wb-term-add { padding: 3px 8px; font-size: 15px; line-height: 1; color: #8b93a3; }
|
|
52
|
+
.wb-term-bar .wb-term-add:hover { color: #d7dae0; }
|
|
53
|
+
|
|
54
|
+
/* content-box: the fit addon reads this height as the room for rows, so the padding must not be in it */
|
|
55
|
+
.wb-term-screen { height: calc(var(--wb-term-h) - 10px); padding: 4px 0 6px 10px; box-sizing: content-box; overflow: hidden; }
|
|
56
|
+
/* the screen as the server wrote it into the page, over the terminal until that has drawn it */
|
|
57
|
+
.wb-term-screen { position: relative; }
|
|
58
|
+
.wb-term-placeholder {
|
|
59
|
+
position: absolute; inset: 4px 0 6px 10px; z-index: 1; overflow: hidden; background: #0f1115;
|
|
60
|
+
font: 13px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; color: #d7dae0;
|
|
61
|
+
}
|
|
62
|
+
.wb-term-placeholder > div { height: 1.2em; }
|
|
63
|
+
/* the server writes every tab's screen; the current tab's shows */
|
|
64
|
+
.wb-term-placeholder:not(.wb-current) { display: none; }
|
|
65
|
+
#wb-terminal[data-state=collapsed] .wb-term-screen { height: 0; padding: 0; visibility: hidden; }
|
|
66
|
+
|
|
67
|
+
::view-transition-group(wb-terminal) { animation-duration: .22s; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
|
|
68
|
+
/* opening and closing: the pictures keep their scale and stay anchored at the bar, so the text
|
|
69
|
+
doesn't stretch while the drawer grows */
|
|
70
|
+
::view-transition-old(wb-terminal), ::view-transition-new(wb-terminal) { height: 100%; object-fit: none; object-position: top; }
|
|
71
|
+
@media (prefers-reduced-motion: reduce) { ::view-transition-group(*) { animation: none !important; } }
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: whiteboard
|
|
3
|
+
description: Show the user a live HTML page written in markdown, and get answers back through forms on it. Use when an explanation, plan, comparison, status overview or set of open questions would read better as a page than as terminal text; when the user has to re-ask about something explained earlier (put it on a page they can keep open); when work is long-running and the user needs an overview of what is pending, running and done; or when you need decisions from the user that you can wait on while they read.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# whiteboard
|
|
7
|
+
|
|
8
|
+
Pages are markdown files. In a repository set up for whiteboard they live in
|
|
9
|
+
`.whiteboard/pages/` and are served by the project's own server, at a port
|
|
10
|
+
`whiteboard show` prints. The user keeps them open in a browser; every save
|
|
11
|
+
of the file updates the open page in place, and the blocks that changed are
|
|
12
|
+
marked until the user has seen them. Forms on a page write the user's answers
|
|
13
|
+
to an ndjson log you can wait on.
|
|
14
|
+
|
|
15
|
+
The commands below are written as `whiteboard …`. When that is not on the
|
|
16
|
+
PATH, the project has it installed locally: run them as `npx whiteboard …`.
|
|
17
|
+
|
|
18
|
+
## Writing a page
|
|
19
|
+
|
|
20
|
+
1. Run `whiteboard docs` once per session and read it: it is how pages are
|
|
21
|
+
written in this project: the syntax of every block its plugins bring, and
|
|
22
|
+
what their events mean. Do not rely on memory for block syntax; the set
|
|
23
|
+
differs per project. If it says there is no
|
|
24
|
+
project, ask the user before running `whiteboard init`: it adds a folder
|
|
25
|
+
to their repository.
|
|
26
|
+
2. Run `whiteboard new <topic>` (subfolders are fine: `task/plan`). It
|
|
27
|
+
creates an empty page with a name no other page has, `<topic>` or else
|
|
28
|
+
`<topic>-2` and so on, and prints its path. That file is yours: other
|
|
29
|
+
agents may be writing pages in the same project, so never write a page you
|
|
30
|
+
did not get from `whiteboard new`, and never pick a page name yourself.
|
|
31
|
+
3. Write the page into that file.
|
|
32
|
+
4. Run `whiteboard show <file>`: it starts the server if needed and prints the
|
|
33
|
+
URL. Give the user the URL the first time; after that, just keep editing
|
|
34
|
+
the file — the open page follows.
|
|
35
|
+
|
|
36
|
+
Files that already exist in the repository render too: `whiteboard show
|
|
37
|
+
README.md` (any path in the project) gives a URL that renders that file, and
|
|
38
|
+
relative links in it lead to the other files they name (unless the config
|
|
39
|
+
sets `files: false`, as a project in the home folder does). Link to existing
|
|
40
|
+
documents and code from your pages with relative paths instead of copying
|
|
41
|
+
them.
|
|
42
|
+
|
|
43
|
+
Write for a reader who comes back later:
|
|
44
|
+
|
|
45
|
+
- Lead with the state of things; put depth in `:::details[…]` blocks so the
|
|
46
|
+
page stays scannable.
|
|
47
|
+
- Update your page rather than starting a new one for the same topic; changed
|
|
48
|
+
blocks are highlighted for the user, unchanged ones stay quiet.
|
|
49
|
+
- Put the things you need from the user in forms, one form per decision, each
|
|
50
|
+
with a distinct name (no colon: those are reserved for event types like
|
|
51
|
+
`chat:message`). A form is markdown with its inputs inline (see the
|
|
52
|
+
form plugin's docs). When the options need explaining, explain them in
|
|
53
|
+
the form, each option with its meaning right under it, not in a section
|
|
54
|
+
above it: the user decides where they read. Keep `:::details` for real
|
|
55
|
+
depth, not for the options.
|
|
56
|
+
- A send is a choice, and only that. Questions and remarks about a form go
|
|
57
|
+
in the chat under it (`chat:message` events, see the chat plugin's docs):
|
|
58
|
+
answer them there, and never read a chat message, or a note sent along
|
|
59
|
+
with a submit, as a choice. Don't add a notes field to a decision form for
|
|
60
|
+
questions; its chat is for that.
|
|
61
|
+
- For talk that isn't about a question, put a chat on the page:
|
|
62
|
+
`:::chat{name=…}`, at the end or in a section. It is the same chat as
|
|
63
|
+
under a form, without the question.
|
|
64
|
+
- When a question changes, rework it inside its form and keep the form's
|
|
65
|
+
name. The chat belongs to the form by name: replace or rename the form and
|
|
66
|
+
its chat moves to the end of the page, away from the question.
|
|
67
|
+
- Don't number headings yourself (`### 1. Naming`): the page
|
|
68
|
+
numbers section headings already, so yours would show twice. Refer to a
|
|
69
|
+
section by its name.
|
|
70
|
+
- When you only repeat back what the user answered, or update a status line
|
|
71
|
+
or timestamp, put it in `:::quiet` (if the project's docs list it): changed
|
|
72
|
+
blocks are marked for the user, and an echo of their own answer is not
|
|
73
|
+
news. Anything they need to read (a question back, a different reading of
|
|
74
|
+
their answer, a new explanation) stays outside it.
|
|
75
|
+
|
|
76
|
+
Plain markdown, GFM tables, `<details>` and a raw `<form name="…">` work
|
|
77
|
+
without any block. An unknown `:::name` block still renders its content, so
|
|
78
|
+
a typo never breaks the page.
|
|
79
|
+
|
|
80
|
+
**Nesting containers:** the outer fence needs more colons than anything
|
|
81
|
+
inside it, `::::grid` around `:::details`. A `:::` closes the first open
|
|
82
|
+
container whose fence is no longer than its own, so with equal colons the
|
|
83
|
+
inner close ends the outer block too. This also counts lines of colons inside
|
|
84
|
+
a code block within a container: a code example containing `::::` needs a
|
|
85
|
+
container of at least five.
|
|
86
|
+
|
|
87
|
+
## Showing the page beside the conversation
|
|
88
|
+
|
|
89
|
+
Open the page in a browser next to your pane instead of only printing the URL.
|
|
90
|
+
The user then reads the page and talks to you side by side. Do this the first
|
|
91
|
+
time you show a page in a session, or when the user asks to see one. Which
|
|
92
|
+
browser depends on where you run: in whiteboard's own terminal drawer, the
|
|
93
|
+
page around it; in cmux, its own browser pane; in herdr, terminal-browser.
|
|
94
|
+
|
|
95
|
+
### In whiteboard's terminal drawer
|
|
96
|
+
|
|
97
|
+
When you run in a tab of the terminal drawer at the bottom of the user's
|
|
98
|
+
whiteboard pages (`WHITEBOARD_TERMINAL` is set, or the user says so), the
|
|
99
|
+
browser is right there:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
whiteboard terminal open <file> # the browser tab the user is in goes to that page; the drawer comes along
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
It works without `WHITEBOARD_TERMINAL` too (a sandbox may filter it out):
|
|
106
|
+
then it uses the drawer the user used last.
|
|
107
|
+
|
|
108
|
+
It replaces the page the user is looking at, so open a page when they asked
|
|
109
|
+
to see it or when you just wrote it for them, not while they read another.
|
|
110
|
+
|
|
111
|
+
**One browser pane, a tab per page.** The first page opens a browser pane to
|
|
112
|
+
the right of yours; every later page opens as a new tab in that same pane, not
|
|
113
|
+
in another pane or workspace. Later edits to a page show up in its tab by
|
|
114
|
+
themselves, so open each page once.
|
|
115
|
+
|
|
116
|
+
### In cmux
|
|
117
|
+
|
|
118
|
+
When `CMUX_WORKSPACE_ID` is set, you run in cmux, and its browser pane is a
|
|
119
|
+
native web view beside your terminal. The `cmux` command works from a sandbox,
|
|
120
|
+
so run it directly.
|
|
121
|
+
|
|
122
|
+
Find out whether your workspace has a browser pane already:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
cmux tree # this workspace's panes, their surfaces (tabs) with [browser], title and URL
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- **No browser pane yet:** `cmux browser open <url>` opens one in a split to
|
|
129
|
+
the right, without taking focus. It prints `surface=surface:N pane=pane:M`.
|
|
130
|
+
- **A browser pane already:** add the page as a tab in it, without taking
|
|
131
|
+
focus from the user's terminal:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
cmux new-surface --type browser --pane pane:M --url <url> --focus false
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Not `cmux browser … tab new`: that moves keyboard focus into the browser,
|
|
138
|
+
away from the conversation.
|
|
139
|
+
|
|
140
|
+
- Each tab's title in `cmux tree` is the page's title: one starting with `(!n)`
|
|
141
|
+
has n forms waiting for the user.
|
|
142
|
+
- `cmux browser --surface surface:N eval '…'` (or `snapshot`, `get text`,
|
|
143
|
+
`click <css>`, `screenshot --out <file>`) works in the user's open tab, so
|
|
144
|
+
you can check how a page actually renders instead of asking. `cmux help
|
|
145
|
+
browser` lists the commands.
|
|
146
|
+
|
|
147
|
+
### In herdr
|
|
148
|
+
|
|
149
|
+
When you run inside herdr (`HERDR_ENV=1`, and `HERDR_PANE_ID` names your pane)
|
|
150
|
+
and `terminal-browser` is on the PATH, it is the browser:
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
terminal-browser new-tab <url>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
With no browser in your herdr tab yet, this opens one in a split to the right;
|
|
157
|
+
with one, it adds a tab to it. When there are several, it asks for one:
|
|
158
|
+
`terminal-browser ls` lists them with their key, and
|
|
159
|
+
`terminal-browser new-tab --browser <key> <url>` picks it.
|
|
160
|
+
|
|
161
|
+
**From a sandbox.** `terminal-browser` may be blocked inside your sandbox
|
|
162
|
+
("Operation not permitted"). herdr starts panes outside it, so run the command
|
|
163
|
+
in a short-lived pane and read what it printed:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
herdr pane split --current --direction down --cwd "$PWD" # JSON; the new id is result.pane.pane_id
|
|
167
|
+
herdr pane run <id> 'terminal-browser new-tab <url> 2>&1; echo DONE_$((40+2))'
|
|
168
|
+
herdr pane wait-output <id> --match DONE_42 # the marker is computed, so the echoed command doesn't match it
|
|
169
|
+
herdr pane read <id> --source recent-unwrapped --format text
|
|
170
|
+
herdr pane close <id>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- `terminal-browser ls` shows each browser's tabs and their titles: a title
|
|
174
|
+
starting with `(!n)` has n forms waiting for the user.
|
|
175
|
+
- `terminal-browser action -- snapshot` (or `eval "…"`, `click @e14`) works
|
|
176
|
+
in the user's open browser, so you can check how a page actually renders
|
|
177
|
+
instead of asking. `terminal-browser action --help` has the selectors.
|
|
178
|
+
- `herdr pane read` returns no text for a pane showing the browser itself,
|
|
179
|
+
since it draws with graphics.
|
|
180
|
+
|
|
181
|
+
## Getting answers
|
|
182
|
+
|
|
183
|
+
Each submit of a named form appends one line to the project's
|
|
184
|
+
`.whiteboard/events.ndjson`:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{"id":"…","ts":"2026-…","page":"plan","type":"deploy-review","action":"Approve","data":{"notes":"…"}}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Pass your page's file path as `--page`, so you only hear about your own
|
|
191
|
+
page (`--page plan` also works, and includes the pages below `plan/`).
|
|
192
|
+
|
|
193
|
+
- `whiteboard wait --page <file> --type <name>` prints the next answer to that
|
|
194
|
+
form and exits (`--timeout <s>` exits 2 on timeout). It first hands out
|
|
195
|
+
answers it has not handed out before, also ones given before you started
|
|
196
|
+
waiting, so you never miss one and never get one twice. Run it in the
|
|
197
|
+
background and keep working; you are notified when it exits.
|
|
198
|
+
- **A page with several forms: one `wait` per answer.** Run
|
|
199
|
+
`whiteboard wait --page <file>` (no `--type`: any answer on the page) in
|
|
200
|
+
the background. It exits on the next answer, and that exit notifies you.
|
|
201
|
+
Act on the answer, then run the wait again for as long as the page still
|
|
202
|
+
has forms without an answer. When all are answered, stop: nothing keeps
|
|
203
|
+
running. When you add a question later, start a wait again. An answer
|
|
204
|
+
given between two waits is not lost: the next wait hands it out first.
|
|
205
|
+
Background commands have no time limit, unlike a monitor tool, which
|
|
206
|
+
expires. Do not use `wait --count <n>`: it returns only after all n
|
|
207
|
+
answers, so the first ones go unread until the last arrives.
|
|
208
|
+
- `whiteboard watch --page <file>` is `wait` that never exits: it prints
|
|
209
|
+
every answer on the page once, also those given while no watch ran. Use it
|
|
210
|
+
only with something that reports each printed line as it comes (a
|
|
211
|
+
monitor), and restart it when that expires.
|
|
212
|
+
- Without `--page`, `wait` and `watch` are the project's fallback: they hand
|
|
213
|
+
out only what no other wait or watch would take, on any page (also
|
|
214
|
+
answers left from sessions that ended). One runs per project; a second
|
|
215
|
+
exits 1. Use it only when asked to look after the whole board; for your
|
|
216
|
+
own pages, always pass `--page`.
|
|
217
|
+
- `whiteboard events --page <file> [--type <name>] [--last 1]` lists what was
|
|
218
|
+
submitted so far, for when you need the history rather than the next
|
|
219
|
+
answer. With `--follow` it then prints each new event as it comes, without
|
|
220
|
+
picking anything up; `whiteboard pick <event id>` marks one picked up
|
|
221
|
+
yourself. Use these only for something `wait` doesn't do, such as picking
|
|
222
|
+
an answer up after you acted on it.
|
|
223
|
+
|
|
224
|
+
The page shows the user what waits for them: every question without an
|
|
225
|
+
answer is marked "waiting for you", and so is a message from you they
|
|
226
|
+
haven't read (a reply in a comment thread, a chat message). A button goes
|
|
227
|
+
from one to the next, and the tab title and the header count them. Whether
|
|
228
|
+
your wait runs doesn't change that, so answers given while none runs wait in
|
|
229
|
+
the log for you. So:
|
|
230
|
+
|
|
231
|
+
- An answer counts as picked up once your `wait` or `watch` hands it to you;
|
|
232
|
+
the form then folds into one line quoting it, as decided. Answers no wait
|
|
233
|
+
has handed out show as waiting for you to pick them up. Waiting on a
|
|
234
|
+
decided form by name (`--type`) asks the user again: it is open again.
|
|
235
|
+
- Keep a `wait` or `watch` running for as long as you want answers, and only
|
|
236
|
+
then. Don't poll `whiteboard events` in a loop instead: it picks nothing
|
|
237
|
+
up, so the user's answers never show as received, and the hooks and
|
|
238
|
+
`whiteboard status` keep reporting them. When an answer arrives while no
|
|
239
|
+
wait runs, the user is told nobody is listening right now.
|
|
240
|
+
- When you need the user to read something before you go on, put a form with
|
|
241
|
+
just a button in it (`:button[Read it]`) and wait for it. Then
|
|
242
|
+
everything you wait for is a form the page can point to.
|
|
243
|
+
|
|
244
|
+
### Status and hooks
|
|
245
|
+
|
|
246
|
+
`whiteboard status` lists, per page, the questions waiting for the user (no
|
|
247
|
+
answer yet, or a wait asks for a new one), the answers no agent picked up,
|
|
248
|
+
and who is listening, with the `wait` command
|
|
249
|
+
that picks them up. Pages are claimed by the session that ran
|
|
250
|
+
`whiteboard new` for them, and `status` marks yours. Run it when you resume
|
|
251
|
+
work, or when you're unsure what is still open.
|
|
252
|
+
|
|
253
|
+
A project can have Claude Code hooks for this: the Claude Code plugin in
|
|
254
|
+
its config, and `whiteboard claude-code install`. None of them ever blocks:
|
|
255
|
+
|
|
256
|
+
- when your turn ends with something on your pages nobody listens for, the
|
|
257
|
+
user sees a one-line warning;
|
|
258
|
+
- when the user sends a message, answers on your pages that no wait picked
|
|
259
|
+
up come with it, and count as picked up from then on;
|
|
260
|
+
- a new session starts with the same, plus what is open on other sessions'
|
|
261
|
+
pages (not handed over: those answers stay for whoever waits on them).
|
|
262
|
+
|
|
263
|
+
So when a message arrives with answers from the hook, act on them as on
|
|
264
|
+
answers from a wait, and start a wait when it says nobody listens.
|
|
265
|
+
|
|
266
|
+
The user can also select text on a page and comment on it, or comment on
|
|
267
|
+
lines of a code block: a `wait` or `watch` on the whole page hands you those
|
|
268
|
+
as `comments:new` events. `whiteboard docs` says how to reply (by editing the
|
|
269
|
+
page, or in the thread with `whiteboard append`).
|
|
270
|
+
|
|
271
|
+
After acting on an answer, update the page to say what you did with it.
|
|
272
|
+
|
|
273
|
+
## Putting changes up for review
|
|
274
|
+
|
|
275
|
+
To have the user review code you changed, write the diff into a page, one
|
|
276
|
+
file at a time: each file's diff in a `diff` fence, inside a chat named
|
|
277
|
+
after the file. The fence shows the file's name, where each part starts
|
|
278
|
+
and line numbers, and leaves out the headers only tools read. Its lines are coloured, the user can comment on any of them
|
|
279
|
+
(each comment's `at` says which file and line: `src/a.ts:12`, or
|
|
280
|
+
`src/a.ts (old):9` for a removed line), and the chat under it is for the
|
|
281
|
+
file as a whole. End with a form for the verdict.
|
|
282
|
+
|
|
283
|
+
```sh
|
|
284
|
+
git add -N . # new files show in the diff too
|
|
285
|
+
{ printf '# Review: <what changed>\n\n<why, in a few lines>\n\n'
|
|
286
|
+
git diff HEAD --name-only | while read -r f; do
|
|
287
|
+
printf ':::chat{name="%s"}\n````diff\n' "$f"
|
|
288
|
+
git diff HEAD -- "$f"
|
|
289
|
+
printf '````\n:::\n\n'
|
|
290
|
+
done
|
|
291
|
+
printf ':::form{name=review}\n:textarea[Anything else]{name=note}\n\n:button[Approve] :button[Request changes]\n:::\n'
|
|
292
|
+
} > .whiteboard/pages/review.md
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Then `whiteboard wait --page review`: it hands you the line comments
|
|
296
|
+
(`comments:new`), the messages about a file (`chat:message`, with the file
|
|
297
|
+
as `chat`) and the verdict. For a comment or message, change the code or
|
|
298
|
+
reply in its thread; after changing code, write the page again the same
|
|
299
|
+
way, so each diff shows what the file is now (comments whose lines are gone
|
|
300
|
+
stay open, marked as no longer on the page; a file's chat stays with its
|
|
301
|
+
name). Add a line of explanation above a file's fence where it helps. Use
|
|
302
|
+
four backticks for the fence, since a diff can hold three.
|