@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
package/src/define.ts
ADDED
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
// The contract between the core, a project's config and its plugins.
|
|
2
|
+
//
|
|
3
|
+
// import { defineConfig, definePlugin, html } from '@bigmistqke/whiteboard'
|
|
4
|
+
//
|
|
5
|
+
// The core stores pages as markdown, renders them, keeps the event log and runs the live channel
|
|
6
|
+
// between them and a browser. Everything else is a plugin: the syntax pages are written in (blocks),
|
|
7
|
+
// behaviour on every page, commands, routes. defineConfig and definePlugin only return their
|
|
8
|
+
// argument; they exist for types.
|
|
9
|
+
import type { Html } from './html.ts'
|
|
10
|
+
|
|
11
|
+
// HTML from a template literal, escaped by default: for a block, a plugin's `shell`
|
|
12
|
+
export { html, raw, escape, Html } from './html.ts'
|
|
13
|
+
|
|
14
|
+
// ---- config ------------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
export interface Config {
|
|
17
|
+
/** shown in page titles and the overview (default: the folder name) */
|
|
18
|
+
name?: string
|
|
19
|
+
/**
|
|
20
|
+
* Serve the project's other files at /-/<path> and watch them for changes (default: true).
|
|
21
|
+
* Set it to false for a project whose folder is not a repository, such as your home folder:
|
|
22
|
+
* then only `.whiteboard/` is served and watched.
|
|
23
|
+
*/
|
|
24
|
+
files?: boolean
|
|
25
|
+
/**
|
|
26
|
+
* Plugins, added to the built-in ones (form, chat, code, comments and the rest); one with a
|
|
27
|
+
* built-in's name replaces it (`code({ themes })`). Such as the terminal drawer
|
|
28
|
+
* (`@bigmistqke/whiteboard/terminal`).
|
|
29
|
+
*/
|
|
30
|
+
plugins?: Plugin[]
|
|
31
|
+
/** a stylesheet linked on every page, after the built-in ones: the project's own look */
|
|
32
|
+
style?: URL | string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const defineConfig = (config: Config): Config => config
|
|
36
|
+
|
|
37
|
+
// ---- plugins --------------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What extends whiteboard: syntax (blocks), behaviour on every page, and commands. `setup` runs
|
|
41
|
+
* once per loaded config, on the server, and returns what the plugin adds to it. Everything is
|
|
42
|
+
* optional but the name.
|
|
43
|
+
*
|
|
44
|
+
* What a plugin adds lives under its name, so two plugins can't collide:
|
|
45
|
+
* - its routes are mounted at `/api/<name>/…`,
|
|
46
|
+
* - its commands are `whiteboard <name>` and `whiteboard <name> <sub>`,
|
|
47
|
+
* - its files go in `.whiteboard/<name>/`, which ignores itself in git and reloads nothing.
|
|
48
|
+
* The core checks a route's token and arguments before its code runs, and lists routes and commands
|
|
49
|
+
* in `whiteboard help` and `whiteboard docs`.
|
|
50
|
+
*/
|
|
51
|
+
export interface Plugin {
|
|
52
|
+
/** letters, digits, - and _; not a folder of the core (`pages`, and `plugins` for local plugins) nor a built-in command */
|
|
53
|
+
name: string
|
|
54
|
+
/**
|
|
55
|
+
* Syntax: the blocks it adds to pages, by name: `:::name`, `::name`, `:name` and ```` ```name ````
|
|
56
|
+
* go to the block of that name. Block names are unique across a project's plugins.
|
|
57
|
+
*/
|
|
58
|
+
blocks?: Record<string, Block<any>>
|
|
59
|
+
/** a stylesheet linked on every page (for blocks, their own `style` links it only where they're used) */
|
|
60
|
+
style?: URL | string
|
|
61
|
+
/**
|
|
62
|
+
* Text that links somewhere, as written in plain text (`#12` → an issue): the core turns each
|
|
63
|
+
* match into a link when it renders a page, but not inside code, links or inline directives.
|
|
64
|
+
* Called once per project folder (`dir`), so it can read the project (its git remote, say).
|
|
65
|
+
*/
|
|
66
|
+
links?(ctx: { dir: string }): TextLink[]
|
|
67
|
+
/**
|
|
68
|
+
* The event types it writes to the log, named `<plugin name>:<what>`, and who they're for.
|
|
69
|
+
* `whiteboard docs` lists them. Only those with `handOut: true` reach an agent unasked: a `wait`
|
|
70
|
+
* or `watch` on a page hands them out, `whiteboard status` counts them, and the hooks deliver them.
|
|
71
|
+
* Others stay in the log, for `whiteboard events` or a `wait --type` that asks for them by name.
|
|
72
|
+
*/
|
|
73
|
+
events?: Record<string, EventSpec>
|
|
74
|
+
setup?(ctx: PluginContext): PluginHooks | Promise<PluginHooks>
|
|
75
|
+
/** by subcommand: `''` is `whiteboard <name>` itself, `stop` is `whiteboard <name> stop` */
|
|
76
|
+
commands?: Record<string, Command>
|
|
77
|
+
/**
|
|
78
|
+
* Markdown for whoever writes pages here, printed by `whiteboard docs` after how pages are written,
|
|
79
|
+
* under a heading the core adds (`# Plugin: <name>`), so start below it (`##`):
|
|
80
|
+
* what the plugin sends to the page's log, and how to answer it (comments say how to reply)
|
|
81
|
+
*/
|
|
82
|
+
docs?(): string | Promise<string>
|
|
83
|
+
/**
|
|
84
|
+
* The agent session the command line runs in, for a plugin that knows how its agent says so
|
|
85
|
+
* (Claude Code's reads `CLAUDE_CODE_SESSION_ID`); null when it doesn't run in one. `whiteboard
|
|
86
|
+
* new` claims the page it makes for this session, and `whiteboard status` marks the session's
|
|
87
|
+
* pages. The first plugin that names a session wins.
|
|
88
|
+
*/
|
|
89
|
+
session?(): string | null | undefined | Promise<string | null | undefined>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const definePlugin = (plugin: Plugin): Plugin => plugin
|
|
93
|
+
|
|
94
|
+
/** A pattern in a page's text that links somewhere (Plugin.links). */
|
|
95
|
+
export interface TextLink {
|
|
96
|
+
/** what to find; matched against each run of plain text */
|
|
97
|
+
pattern: RegExp
|
|
98
|
+
/** where a match links to; null leaves it as text */
|
|
99
|
+
href(match: RegExpExecArray): string | null
|
|
100
|
+
/** what the link says on hover */
|
|
101
|
+
title?(match: RegExpExecArray): string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** One of a plugin's event types. */
|
|
105
|
+
export interface EventSpec {
|
|
106
|
+
/** what it is, and its `data`: for `whiteboard docs` */
|
|
107
|
+
description?: string
|
|
108
|
+
/** hand it to an agent unasked, like a form's answer (a message for the agent); default false */
|
|
109
|
+
handOut?: boolean
|
|
110
|
+
/**
|
|
111
|
+
* one from the agent is a message for the reader (a reply in a thread, a chat message): it waits
|
|
112
|
+
* for them until read, which the page records once its element (marked `data-wb-message` with the
|
|
113
|
+
* event's id) has been in view; default false
|
|
114
|
+
*/
|
|
115
|
+
forReader?: boolean
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface Project {
|
|
119
|
+
name: string
|
|
120
|
+
/** the project folder */
|
|
121
|
+
dir: string
|
|
122
|
+
/** its .whiteboard folder */
|
|
123
|
+
wb: string
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface PluginContext {
|
|
127
|
+
project: Project
|
|
128
|
+
/** the plugin's own folder, `.whiteboard/<name>/` (made, and ignored in git) */
|
|
129
|
+
dataDir: string
|
|
130
|
+
/** whether a request carries the project's token: for a check of its own, beyond a route's `auth` */
|
|
131
|
+
authorized(req: import('node:http').IncomingMessage): boolean
|
|
132
|
+
/** the URL that serves a file of the plugin (its browser module, a stylesheet) */
|
|
133
|
+
asset(file: URL | string): string
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The type of a body or query field, or a command option: `string`, `number`, `boolean` or
|
|
138
|
+
* `string[]`, with `?` when it may be left out.
|
|
139
|
+
*/
|
|
140
|
+
export type FieldType = 'string' | 'number' | 'boolean' | 'string[]' | 'string?' | 'number?' | 'boolean?' | 'string[]?'
|
|
141
|
+
|
|
142
|
+
export interface PluginHooks {
|
|
143
|
+
/** by method and path, `'POST /start'`: mounted at `/api/<name>/start` */
|
|
144
|
+
routes?: Record<string, Route>
|
|
145
|
+
/**
|
|
146
|
+
* Markup for the page shell, outside the page's root: `head` at the end of <head>, `body` at
|
|
147
|
+
* the end of <body>. Called for every page; null adds nothing. The body is there for the first
|
|
148
|
+
* render, so an element in it can take part in the view transition between two pages.
|
|
149
|
+
*
|
|
150
|
+
* Something that covers an edge of the window (a drawer at the bottom) says how much of it, as a
|
|
151
|
+
* length in `--wb-inset-bottom` on :root, registered with `@property` so that it computes to
|
|
152
|
+
* pixels. The page keeps its own fixed elements clear of it and counts what is behind it as out
|
|
153
|
+
* of view.
|
|
154
|
+
*/
|
|
155
|
+
shell?(req: import('node:http').IncomingMessage): { head?: string | Html; body?: string | Html } | null | Promise<{ head?: string | Html; body?: string | Html } | null>
|
|
156
|
+
/**
|
|
157
|
+
* A browser module whose default export is an `PluginMount`: on every page, the core imports
|
|
158
|
+
* it once the page has mounted, and hands it the page and its api. For
|
|
159
|
+
* behaviour on the page's own content (its forms, say); markup of the plugin's own can come
|
|
160
|
+
* from `shell` instead. Serve it with `ctx.asset`.
|
|
161
|
+
*/
|
|
162
|
+
client?: URL | string
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface Route {
|
|
166
|
+
description: string
|
|
167
|
+
/** needs the project's token: for anything that runs code. The core refuses a request without it */
|
|
168
|
+
auth?: boolean
|
|
169
|
+
/** the JSON body's fields; any other field is refused */
|
|
170
|
+
body?: Record<string, FieldType>
|
|
171
|
+
/** the query's fields */
|
|
172
|
+
query?: Record<string, FieldType>
|
|
173
|
+
/** writes to `res` itself, for as long as it likes (server-sent events): `run` gets `res`, its result is ignored */
|
|
174
|
+
stream?: boolean
|
|
175
|
+
/**
|
|
176
|
+
* What the route does. Its result is sent as JSON (`{ ok: true }` for none); an error it throws is
|
|
177
|
+
* sent as `{ error }` with the error's `status` (default 500).
|
|
178
|
+
*/
|
|
179
|
+
run(request: RouteRequest): unknown | Promise<unknown>
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface RouteRequest {
|
|
183
|
+
body: Record<string, unknown>
|
|
184
|
+
query: Record<string, unknown>
|
|
185
|
+
req: import('node:http').IncomingMessage
|
|
186
|
+
/** only for a stream route */
|
|
187
|
+
res?: import('node:http').ServerResponse
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** `whiteboard <plugin> [sub] …` */
|
|
191
|
+
export interface Command {
|
|
192
|
+
description: string
|
|
193
|
+
/** the positional arguments, for the help: `[page]` */
|
|
194
|
+
args?: string
|
|
195
|
+
/** `--name`: its type, what it means, and for the help a word for its value (`value: 'id'` shows as `--name <id>`) */
|
|
196
|
+
options?: Record<string, { type: FieldType; description?: string; value?: string; short?: string }>
|
|
197
|
+
/** takes arguments after `--`, passed on untouched (`ctx.rest`); for the help, what they are */
|
|
198
|
+
rest?: string
|
|
199
|
+
run(ctx: CommandContext): void | Promise<void>
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface CommandContext {
|
|
203
|
+
/** the options, parsed and checked by their declaration */
|
|
204
|
+
options: Record<string, unknown>
|
|
205
|
+
positionals: string[]
|
|
206
|
+
/** what followed `--`, untouched (only for a command that declares `rest`) */
|
|
207
|
+
rest: string[]
|
|
208
|
+
project: Project
|
|
209
|
+
/** the project's event log, for `@bigmistqke/whiteboard/log` (`read(ctx.eventsFile)`, …) */
|
|
210
|
+
eventsFile: string
|
|
211
|
+
/** the plugin's own folder, `.whiteboard/<name>/` */
|
|
212
|
+
dataDir: string
|
|
213
|
+
/** the project's token, for the requests the command sends (header `x-whiteboard-token`) */
|
|
214
|
+
token: string
|
|
215
|
+
/** the base URL of the project's server, started when it isn't running */
|
|
216
|
+
server(): Promise<string>
|
|
217
|
+
/** the path of a page or file of the project, as the server serves it: `/plan` */
|
|
218
|
+
pagePath(page?: string): string
|
|
219
|
+
/** a link that gives a browser the project's token, then goes to `path` */
|
|
220
|
+
authLink(path: string): Promise<string>
|
|
221
|
+
/** what is open on each page (or on `page` and the pages below it), as `whiteboard status` reports it */
|
|
222
|
+
status(page?: string): Promise<PageStatus[]>
|
|
223
|
+
/**
|
|
224
|
+
* Hand the reader's events on `page` (and below it, unless `exact`) or of `type` to `onEvent`, as `whiteboard
|
|
225
|
+
* wait` does: each once, also those from before, never an agent's own, and each counted as picked
|
|
226
|
+
* up from then on. With `follow: false` only those nobody picked up yet. Resolves with how many.
|
|
227
|
+
* For the log's other primitives, import `@bigmistqke/whiteboard/log`.
|
|
228
|
+
*/
|
|
229
|
+
handOut(
|
|
230
|
+
filter: { page?: string | null; type?: string | null; exact?: boolean },
|
|
231
|
+
onEvent: (event: WbEvent) => void,
|
|
232
|
+
options?: { count?: number; follow?: boolean; signal?: AbortSignal },
|
|
233
|
+
): Promise<number>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** What is open on one page. */
|
|
237
|
+
export interface PageStatus {
|
|
238
|
+
page: string
|
|
239
|
+
/** what the reader knows it by: its first heading, else its name */
|
|
240
|
+
title: string
|
|
241
|
+
/** the page's file */
|
|
242
|
+
file: string
|
|
243
|
+
/** the session that claimed the page with `whiteboard new`, if one did */
|
|
244
|
+
owner: string | null
|
|
245
|
+
/** the event types the page waits on the reader for: its named forms */
|
|
246
|
+
asks: string[]
|
|
247
|
+
/** where each of them stands, as the page shows it: open, pending or decided */
|
|
248
|
+
questions: { name: string; state: FormState }[]
|
|
249
|
+
/** those waiting for the reader: no answer yet, or a running wait asks for a new one */
|
|
250
|
+
open: string[]
|
|
251
|
+
/** the open ones no running wait or watch (but the fallback) takes */
|
|
252
|
+
unheard: string[]
|
|
253
|
+
/** the agent's messages on the page the reader hasn't read (see EventSpec.forReader) */
|
|
254
|
+
unread: WbEvent[]
|
|
255
|
+
/** the reader's events on the page that no wait, watch or hook handed out */
|
|
256
|
+
unpicked: WbEvent[]
|
|
257
|
+
/** the running waits and watches that cover the page */
|
|
258
|
+
listeners: Listener[]
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ---- pages ---------------------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
export interface Rendered {
|
|
264
|
+
/** the page's HTML: a string, or built with `html` (the core turns it into a string once) */
|
|
265
|
+
html: string | Html
|
|
266
|
+
title?: string
|
|
267
|
+
/** extra markup for <head>: stylesheets, meta */
|
|
268
|
+
head?: string | Html
|
|
269
|
+
/** JSON handed to the client with the HTML, e.g. what to mount where */
|
|
270
|
+
data?: unknown
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** A render as the browser gets it: the core has turned its HTML into strings. */
|
|
274
|
+
export interface RenderedPage extends Rendered {
|
|
275
|
+
html: string
|
|
276
|
+
head?: string
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A page as the core stores it: what is in the file, read as is. */
|
|
280
|
+
export type StoredPage = PageSource | FileSource | FolderSource | PagesSource
|
|
281
|
+
|
|
282
|
+
interface StoredBase {
|
|
283
|
+
/** "plan", "task/plan", "-/docs/guide.md" for a repository file, "" for the overview */
|
|
284
|
+
id: string
|
|
285
|
+
/** absolute path on disk */
|
|
286
|
+
file: string
|
|
287
|
+
/** last modified, ms */
|
|
288
|
+
mtime: number | null
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** A page: a markdown file in .whiteboard/pages/, or one in the repository. */
|
|
292
|
+
export interface PageSource extends StoredBase {
|
|
293
|
+
kind: 'page'
|
|
294
|
+
source: string
|
|
295
|
+
/** `source` without its frontmatter: the page's content */
|
|
296
|
+
body: string
|
|
297
|
+
/** the frontmatter's fields, when the file starts with one (`source` keeps it) */
|
|
298
|
+
frontmatter: Record<string, string>
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Any other text file in the repository. */
|
|
302
|
+
export interface FileSource extends StoredBase {
|
|
303
|
+
kind: 'file'
|
|
304
|
+
source: string
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** A folder in the repository. */
|
|
308
|
+
export interface FolderSource extends StoredBase {
|
|
309
|
+
kind: 'folder'
|
|
310
|
+
entries: { name: string; dir: boolean }[]
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** The overview, or a folder of pages without an index.md. */
|
|
314
|
+
export interface PagesSource extends StoredBase {
|
|
315
|
+
kind: 'pages'
|
|
316
|
+
/** `awaiting`: how many things on the page wait for the reader: open questions, unread messages */
|
|
317
|
+
pages: { id: string; file: string; mtime: number; lastEvent: string | null; awaiting: number }[]
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** What the core offers the pages on the server: how files are served and linked. */
|
|
321
|
+
export interface RenderContext {
|
|
322
|
+
project: { name: string; dir: string; files: boolean }
|
|
323
|
+
/**
|
|
324
|
+
* The URL the browser loads a file from: a client module, a stylesheet, an image next to a
|
|
325
|
+
* block. Files are served only once asked for, and are watched from then on:
|
|
326
|
+
* a stylesheet reloads in place, a browser module reloads the page.
|
|
327
|
+
*/
|
|
328
|
+
asset(file: string | URL): string
|
|
329
|
+
/**
|
|
330
|
+
* The URL that shows a file or folder on disk (also `file.md` for `file`), or null when it does
|
|
331
|
+
* not exist or nothing serves it. For relative links: resolve them from the page's folder first.
|
|
332
|
+
*/
|
|
333
|
+
urlFor(file: string): string | null
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The default export of a plugin's browser module (from `setup`): the page's root, the page, and its
|
|
338
|
+
* api. It runs once per page load, and is never unmounted: going to another page loads a new one.
|
|
339
|
+
*/
|
|
340
|
+
export type PluginMount = (root: HTMLElement, page: PageHandle, api: Api) => void | Promise<void>
|
|
341
|
+
|
|
342
|
+
/** The page, in the browser. */
|
|
343
|
+
export interface PageHandle {
|
|
344
|
+
id: string
|
|
345
|
+
kind: StoredPage['kind']
|
|
346
|
+
/** what the server render returned with the HTML now in the root */
|
|
347
|
+
data: unknown
|
|
348
|
+
/** called when the stored page changed; returns an unsubscribe */
|
|
349
|
+
onChange(fn: () => void): () => void
|
|
350
|
+
/** the server render, afresh */
|
|
351
|
+
render(): Promise<RenderedPage>
|
|
352
|
+
/** the page as stored, afresh */
|
|
353
|
+
stored(): Promise<StoredPage>
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// ---- events ------------------------------------------------------------------------------------
|
|
357
|
+
|
|
358
|
+
export interface WbEvent {
|
|
359
|
+
id: string
|
|
360
|
+
ts: string
|
|
361
|
+
page: string
|
|
362
|
+
/** what kind of event: for a submitted form, the form's name */
|
|
363
|
+
type: string
|
|
364
|
+
/** the button that submitted a form; null for other events */
|
|
365
|
+
action: string | null
|
|
366
|
+
data: Record<string, unknown>
|
|
367
|
+
/** 'cli' for events the command line appended (`whiteboard append`), such as an agent's reply */
|
|
368
|
+
from?: 'cli'
|
|
369
|
+
/** in the browser: an agent has picked this event up (`whiteboard wait` or `watch` handed it out) */
|
|
370
|
+
pickedUp?: true
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* An agent waiting for answers right now: a running `whiteboard wait` or `watch`. `page` is its
|
|
375
|
+
* page filter ("" for every page; a page also covers the pages below it), `type` the event type it
|
|
376
|
+
* waits for, null for any.
|
|
377
|
+
*/
|
|
378
|
+
export interface Listener {
|
|
379
|
+
page: string
|
|
380
|
+
type: string | null
|
|
381
|
+
command: 'wait' | 'watch'
|
|
382
|
+
/**
|
|
383
|
+
* a `wait` or `watch` without `--page`: it takes only what no other listener would, and asks no
|
|
384
|
+
* question again. At most one runs per project.
|
|
385
|
+
*/
|
|
386
|
+
fallback?: boolean
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** How a toast looks and acts: `warn` for something that may need the reader, how long it stays. */
|
|
390
|
+
export interface ToastOptions {
|
|
391
|
+
kind?: 'info' | 'warn'
|
|
392
|
+
/** milliseconds before it goes, 7000 by default; 0: it stays until closed through its `Toast` */
|
|
393
|
+
ms?: number
|
|
394
|
+
/** what a click on it does, besides closing it (a toast that stays, stays) */
|
|
395
|
+
onClick?: () => void
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** A toast on the screen: close it, or change what it says (a count that goes down). */
|
|
399
|
+
export interface Toast {
|
|
400
|
+
close(): void
|
|
401
|
+
update(text: string): void
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** What the core gives the page and every plugin in the browser. Framework-free: getters and subscriptions. */
|
|
405
|
+
export interface Api {
|
|
406
|
+
/** this page's id */
|
|
407
|
+
page: string
|
|
408
|
+
/** every event recorded for this page, oldest first */
|
|
409
|
+
events(): WbEvent[]
|
|
410
|
+
/** called with the new list whenever it changes; returns an unsubscribe */
|
|
411
|
+
onEvents(fn: (events: WbEvent[]) => void): () => void
|
|
412
|
+
/** the latest event of a type, e.g. the last submit of a form */
|
|
413
|
+
last(type: string): WbEvent | undefined
|
|
414
|
+
/** record an event for this page: it lands in the log, where the agent reads it */
|
|
415
|
+
append(type: string, data?: Record<string, unknown>, action?: string | null): Promise<WbEvent>
|
|
416
|
+
/** has an agent picked this event up (a `wait` or `watch` handed it out)? */
|
|
417
|
+
pickedUp(id: string): boolean
|
|
418
|
+
/**
|
|
419
|
+
* The agent's messages on this page the reader hasn't read, oldest first (see
|
|
420
|
+
* EventSpec.forReader). An element marked `data-wb-message="<event id>"` reads its message once
|
|
421
|
+
* it has been in view; `markRead` does so for messages read otherwise (a thread closed).
|
|
422
|
+
*/
|
|
423
|
+
unread(): WbEvent[]
|
|
424
|
+
markRead(ids: string[]): void
|
|
425
|
+
/**
|
|
426
|
+
* A message's markdown (a comment, a chat message) as HTML, rendered by the server like a page:
|
|
427
|
+
* code fences highlighted, text links (`#12`), but raw HTML as text and no directives. Cached.
|
|
428
|
+
*/
|
|
429
|
+
markdown(text: string): Promise<string>
|
|
430
|
+
/** the agents waiting for answers on this page right now */
|
|
431
|
+
listeners(): Listener[]
|
|
432
|
+
onListeners(fn: (listeners: Listener[]) => void): () => void
|
|
433
|
+
/**
|
|
434
|
+
* Say that the page's content changed in place: the page module calls it after each patch on an update
|
|
435
|
+
* (it morphs it) calls this after each patch, so that plugins working on the content
|
|
436
|
+
* can put back what they add to it.
|
|
437
|
+
*/
|
|
438
|
+
rendered(): void
|
|
439
|
+
/** called after each `rendered()`; returns an unsubscribe */
|
|
440
|
+
onRendered(fn: () => void): () => void
|
|
441
|
+
/**
|
|
442
|
+
* The page's corner: a column at the bottom right, above whatever covers the bottom of the
|
|
443
|
+
* window (`--wb-inset-bottom`), for floating buttons. The page and the plugins each add
|
|
444
|
+
* their own; the core draws nothing in it.
|
|
445
|
+
*/
|
|
446
|
+
corner(): HTMLElement
|
|
447
|
+
/**
|
|
448
|
+
* A count in the tab title, under `key`: `(text)` in front of the page's title; null removes it.
|
|
449
|
+
* Lower `order` comes first (default 0), so what waits for the reader can lead.
|
|
450
|
+
*/
|
|
451
|
+
badge(key: string, text: string | null, order?: number): void
|
|
452
|
+
/** the page's own title, behind the badges */
|
|
453
|
+
title(title: string): void
|
|
454
|
+
/**
|
|
455
|
+
* A short message at the bottom of the window, for what the reader should know when it happens,
|
|
456
|
+
* wherever they are scrolled: an answer nobody listens for, a reply in a thread. It goes after a
|
|
457
|
+
* few seconds, or on a click, which runs `onClick` first (go to what it is about); with `ms: 0`
|
|
458
|
+
* it stays until closed through what this returns.
|
|
459
|
+
*/
|
|
460
|
+
toast(text: string, options?: ToastOptions): Toast
|
|
461
|
+
/**
|
|
462
|
+
* The page's named forms and where each stands. The core looks after every `<form name>` without
|
|
463
|
+
* an `action`: it sends a submit as an event, keeps drafts, puts the last answer back, and marks
|
|
464
|
+
* each form with its state (`data-wb-open`, `-pending`, `-decided`). How that
|
|
465
|
+
* looks is the page's styles'; this is for drawing more than the attributes allow (a summary, a count)
|
|
466
|
+
*/
|
|
467
|
+
forms(): FormStatus[]
|
|
468
|
+
/** called after the forms were marked again: the log, the listeners or the page changed */
|
|
469
|
+
onForms(fn: (forms: FormStatus[]) => void): () => void
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Where a named form stands:
|
|
474
|
+
* - waiting: an agent is listening and wants its answer
|
|
475
|
+
* - unheard: no answer, and no agent is listening
|
|
476
|
+
* - pending: answered, but no agent has picked the answer up yet
|
|
477
|
+
* - decided: an agent picked up its latest answer
|
|
478
|
+
*/
|
|
479
|
+
export type FormState = 'open' | 'pending' | 'decided'
|
|
480
|
+
|
|
481
|
+
export interface FormStatus {
|
|
482
|
+
form: HTMLFormElement
|
|
483
|
+
/** the form's name: the type of its answers */
|
|
484
|
+
name: string
|
|
485
|
+
state: FormState
|
|
486
|
+
/** its latest answer */
|
|
487
|
+
last: WbEvent | undefined
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ---- blocks ------------------------------------------------------------------------------------
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* A block handles the directives with its name (its key in a plugin's `blocks`): `:::name`,
|
|
494
|
+
* `::name` and `:name`; and, when it says so (`fence`), the code fences of that language,
|
|
495
|
+
* ```` ```name ````. Server functions run while the page renders; `client` runs in the browser.
|
|
496
|
+
*
|
|
497
|
+
* File references are URLs relative to the plugin's module, so they work wherever it is installed:
|
|
498
|
+
* client: new URL('./client.js', import.meta.url)
|
|
499
|
+
*/
|
|
500
|
+
export interface Block<Props = unknown> {
|
|
501
|
+
/**
|
|
502
|
+
* Which code fences it renders. `true`: those of its name (```` ```mermaid ````). `'any'`: those
|
|
503
|
+
* too, and every fence no block claims by name, and the code view of repository files: the block
|
|
504
|
+
* for code in general, such as a syntax highlighter (when several set it, the last plugin's wins).
|
|
505
|
+
* Without it, a fence of its name is code like any other: ```` ```text ```` is no text field.
|
|
506
|
+
*/
|
|
507
|
+
fence?: boolean | 'any'
|
|
508
|
+
/** props for the client; JSON-serialisable. Without it a client gets the defaults (see DirectiveProps / FenceProps). */
|
|
509
|
+
props?(ctx: ServerContext): Props | Promise<Props>
|
|
510
|
+
/**
|
|
511
|
+
* HTML for the block, as a string or built with `html`. Without `client` this is the whole
|
|
512
|
+
* output; with it, what shows until it mounts.
|
|
513
|
+
*/
|
|
514
|
+
html?(ctx: ServerContext): string | Html | null | Promise<string | Html | null>
|
|
515
|
+
/** a browser module whose default export is a `Mount` */
|
|
516
|
+
client?: URL | string
|
|
517
|
+
/** a stylesheet linked on every page that uses the block */
|
|
518
|
+
style?: URL | string
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** A block with typed props, for one written apart from its plugin. */
|
|
522
|
+
export const defineBlock = <Props = unknown>(block: Block<Props>): Block<Props> => block
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Default export of a block's `client` module: mounted once per block, again with new props when
|
|
526
|
+
* the block changes. Return a cleanup, or nothing: it runs when the block is replaced or removed.
|
|
527
|
+
*/
|
|
528
|
+
export type Mount<Props = unknown> = (
|
|
529
|
+
element: HTMLElement,
|
|
530
|
+
props: Props,
|
|
531
|
+
api: ClientApi,
|
|
532
|
+
) => void | (() => void) | Promise<void | (() => void)>
|
|
533
|
+
|
|
534
|
+
// ---- server context ----------------------------------------------------------------------------
|
|
535
|
+
|
|
536
|
+
export interface Section {
|
|
537
|
+
/** heading content as HTML (no <h*> wrapper), null when the block has no headings */
|
|
538
|
+
title: string | null
|
|
539
|
+
/** heading as plain text */
|
|
540
|
+
text: string | null
|
|
541
|
+
html: string
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
interface BaseContext {
|
|
545
|
+
/** page id, e.g. "plan", or "-/docs/guide.md" for a repository file */
|
|
546
|
+
page: string
|
|
547
|
+
/** absolute path of the markdown file, and its folder (resolve files next to the page with it) */
|
|
548
|
+
file: string
|
|
549
|
+
dir: string
|
|
550
|
+
name: string
|
|
551
|
+
attrs: Record<string, string>
|
|
552
|
+
parseAttrs(s: string): Record<string, string>
|
|
553
|
+
/** render mdast nodes to HTML; nested directives and fences go through their blocks */
|
|
554
|
+
toHtml(nodes: unknown[]): Promise<string>
|
|
555
|
+
toString(node: unknown): string
|
|
556
|
+
/** render a markdown string to HTML (blocks included) */
|
|
557
|
+
markdown(src: string): Promise<string>
|
|
558
|
+
/** like markdown(), without the wrapping <p> for a single paragraph */
|
|
559
|
+
inline(src: string): Promise<string>
|
|
560
|
+
/** what a client gets when the block has no props() */
|
|
561
|
+
defaults(): Promise<Record<string, unknown>>
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** `:::name[label]{attrs}` … `:::`, `::name[label]{attrs}`, `:name[label]{attrs}` */
|
|
565
|
+
export interface DirectiveContext extends BaseContext {
|
|
566
|
+
kind: 'containerDirective' | 'leafDirective' | 'textDirective'
|
|
567
|
+
/** label as HTML / plain text, null without one */
|
|
568
|
+
label: string | null
|
|
569
|
+
labelText: string | null
|
|
570
|
+
/** the block's content as mdast nodes */
|
|
571
|
+
children: unknown[]
|
|
572
|
+
/** split the content at its shallowest headings, or at blank lines when it has none */
|
|
573
|
+
sections(): Promise<{ intro: string; sections: Section[] }>
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** ```name attrs */
|
|
577
|
+
export interface FenceContext extends BaseContext {
|
|
578
|
+
kind: 'fence'
|
|
579
|
+
text: string
|
|
580
|
+
/** the fence's language (its first word); for a fence claimed by name it equals `name`, null when there is none */
|
|
581
|
+
lang: string | null
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export type ServerContext = DirectiveContext | FenceContext
|
|
585
|
+
|
|
586
|
+
/** Default props of a directive without props(). */
|
|
587
|
+
export interface DirectiveProps {
|
|
588
|
+
name: string
|
|
589
|
+
attrs: Record<string, string>
|
|
590
|
+
label: string | null
|
|
591
|
+
html: string
|
|
592
|
+
intro: string
|
|
593
|
+
sections: Section[]
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** Default props of a fence without props(). */
|
|
597
|
+
export interface FenceProps {
|
|
598
|
+
name: string
|
|
599
|
+
attrs: Record<string, string>
|
|
600
|
+
text: string
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// ---- client api --------------------------------------------------------------------------------
|
|
604
|
+
|
|
605
|
+
export type Theme = 'light' | 'dark'
|
|
606
|
+
|
|
607
|
+
/** Passed to every Mount: the core's api, and the page's theme. */
|
|
608
|
+
export interface ClientApi extends Api {
|
|
609
|
+
/** the theme in effect (the reader's choice, else the system's) */
|
|
610
|
+
theme(): Theme
|
|
611
|
+
onTheme(fn: (theme: Theme) => void): () => void
|
|
612
|
+
}
|