@bigmistqke/whiteboard 0.4.0 → 0.6.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 +177 -26
- package/bin/whiteboard.ts +331 -16
- package/dist/bin/whiteboard.js +268 -17
- package/dist/client/runtime.js +66 -23
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +64 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +28 -0
- package/dist/plugins/badge/index.js +24 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/public/style.css +7 -2
- package/dist/plugins/code/README.md +4 -2
- package/dist/plugins/code/diff.js +12 -2
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/grid/README.md +12 -12
- package/dist/plugins/grid/index.js +7 -19
- package/dist/plugins/grid/public/style.css +4 -33
- package/dist/plugins/iframe/README.md +7 -7
- package/dist/plugins/iframe/index.js +11 -11
- package/dist/plugins/iframe/public/style.css +15 -0
- package/dist/plugins/index.js +11 -3
- package/dist/plugins/lightbox/README.md +22 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +60 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +8 -2
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +10 -4
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +6 -4
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +74 -20
- package/dist/src/entries.js +211 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +12 -3
- package/dist/src/package.js +23 -1
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +87 -33
- package/dist/src/pages/render.js +157 -28
- package/dist/src/pages/window.js +17 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +264 -23
- package/package.json +3 -2
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +28 -0
- package/plugins/badge/index.ts +35 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/public/style.css +7 -2
- package/plugins/code/README.md +4 -2
- package/plugins/code/diff.ts +14 -2
- package/plugins/code/index.ts +3 -1
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/grid/README.md +12 -12
- package/plugins/grid/index.ts +11 -26
- package/plugins/grid/public/style.css +4 -33
- package/plugins/iframe/README.md +7 -7
- package/plugins/iframe/index.ts +15 -15
- package/plugins/iframe/public/style.css +15 -0
- package/plugins/index.ts +10 -2
- package/plugins/lightbox/README.md +22 -0
- package/plugins/lightbox/client.ts +99 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +75 -0
- package/plugins/steps/index.ts +84 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +16 -7
- package/plugins/terminal/host.ts +12 -6
- package/plugins/terminal/sizes.ts +3 -1
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +47 -6
- package/plugins/toc/index.ts +19 -6
- package/plugins/toc/public/style.css +10 -4
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +18 -10
- package/src/auth.ts +8 -5
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +2 -1
- package/src/client/markdown.ts +2 -1
- package/src/client/page/base.css +61 -1
- package/src/client/page/elsewhere.ts +72 -16
- package/src/client/page/fresh.ts +2 -1
- package/src/client/page/main.ts +18 -6
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +62 -25
- package/src/define.ts +126 -19
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +14 -3
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +6 -4
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +181 -28
- package/src/pages/window.ts +23 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +332 -26
- package/dist/plugins/gallery/README.md +0 -30
- package/dist/plugins/gallery/index.js +0 -75
- package/dist/plugins/gallery/public/client.js +0 -1
- package/dist/plugins/gallery/public/style.css +0 -90
- package/plugins/gallery/README.md +0 -30
- package/plugins/gallery/client.tsx +0 -70
- package/plugins/gallery/index.ts +0 -89
- package/plugins/gallery/public/style.css +0 -90
package/dist/bin/whiteboard.js
CHANGED
|
@@ -4,8 +4,9 @@ import { CLAIM, appendEvent, editEvent, follow, forAgent, handOut, matches, pick
|
|
|
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";
|
|
7
|
-
import { packagePath } from "../src/package.js";
|
|
8
|
-
import { runningServer } from "../src/running.js";
|
|
7
|
+
import { PACKAGE_DIR, VERSION, compareVersions, packagePath } from "../src/package.js";
|
|
8
|
+
import { recordedSharedPort, runningServer, sharedServer } from "../src/running.js";
|
|
9
|
+
import { machineDir, machineServerFile, matchesEntries, readMachineConfig, serverPaths, stateDir } from "../src/entries.js";
|
|
9
10
|
import { statusLines, takenByOther, whose } from "../src/status.js";
|
|
10
11
|
import fs from "node:fs";
|
|
11
12
|
import os from "node:os";
|
|
@@ -30,6 +31,8 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
30
31
|
whiteboard url <page|file> the same: print the page URL
|
|
31
32
|
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
32
33
|
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
34
|
+
whiteboard build [globs…] [--out <dir>] [--skip <a,b>] pages as a static site: plain HTML, links
|
|
35
|
+
relative, without forms, chats, comments and drafts (the config's build)
|
|
33
36
|
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
34
37
|
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
35
38
|
a form's name or any text on it (opening details around it)
|
|
@@ -41,18 +44,27 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
41
44
|
whiteboard append --page <p> --type <t> [--data <json>] add an event to a page's log (e.g. a reply)
|
|
42
45
|
whiteboard pick <event id> record an event as picked up, as wait does when it hands one out
|
|
43
46
|
whiteboard status [--page <p>] per page: questions without an answer, answers no agent picked up, who listens
|
|
44
|
-
whiteboard serve run this project's server in the foreground
|
|
47
|
+
whiteboard serve run this project's server in the foreground; for a project of the
|
|
48
|
+
machine's entries, or outside any project, the shared server
|
|
45
49
|
whiteboard skill [dir] print where the agent skill is, or link it into a skills folder
|
|
50
|
+
whiteboard paths [--write|--read] the folders the shared server needs, ':' between them, for a sandbox
|
|
51
|
+
wrapper to grant: --write the entries' folders and its state, --read
|
|
52
|
+
the machine config and whiteboard itself
|
|
46
53
|
|
|
47
54
|
filters: --page <page|file> (includes pages below it) --type <type>
|
|
48
55
|
wait: --timeout <seconds> (exit 2 on timeout) --count <n> (default 1)
|
|
49
56
|
wait, watch without --page: the fallback, taking only what no other wait or watch would, on any
|
|
50
|
-
page, also once they stop; one per project (a second exits 1)
|
|
57
|
+
page, also once they stop; one per project (a second exits 1), or, in a project of the
|
|
58
|
+
machine's entries, one for the whole entry, each event with its project and url
|
|
51
59
|
events: --since <iso time or event id> --last <n>
|
|
52
60
|
|
|
53
61
|
Every command works on the project of the current folder: the nearest folder upward with a
|
|
54
62
|
.whiteboard/ folder. A project needs no config: .whiteboard/config.ts only says what differs from
|
|
55
63
|
the defaults (markdown with the built-in plugins). Each project runs its own server; its port is in .whiteboard/server.json.
|
|
64
|
+
A project the machine config's entries include (${machineDir()}/config.json) is served by the one shared
|
|
65
|
+
server instead, under its path (/<entry>/<folder>), with an index of every entry at /. It is started
|
|
66
|
+
outside the agents' sandboxes (\`whiteboard serve\` outside any project, or a login service), and
|
|
67
|
+
\`serve\` takes an older one over; commands never start it. A wait without a server waits for one.
|
|
56
68
|
A page appends events {id, ts, page, type, action, data} to .whiteboard/events.ndjson;
|
|
57
69
|
which types it sends is up to its plugins (\`whiteboard docs\` says). The project's plugins
|
|
58
70
|
can add commands of their own; \`whiteboard help\` in a project lists them.`;
|
|
@@ -74,10 +86,14 @@ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? {
|
|
|
74
86
|
last: { type: "string" },
|
|
75
87
|
follow: { type: "boolean" },
|
|
76
88
|
id: { type: "string" },
|
|
89
|
+
out: { type: "string" },
|
|
90
|
+
skip: { type: "string" },
|
|
77
91
|
help: {
|
|
78
92
|
type: "boolean",
|
|
79
93
|
short: "h"
|
|
80
|
-
}
|
|
94
|
+
},
|
|
95
|
+
write: { type: "boolean" },
|
|
96
|
+
read: { type: "boolean" }
|
|
81
97
|
}
|
|
82
98
|
});
|
|
83
99
|
const project = project$1(findProjectDir());
|
|
@@ -92,12 +108,45 @@ const filter = () => ({
|
|
|
92
108
|
page: opts.page ? pageId(needProject(), opts.page) : void 0,
|
|
93
109
|
type: opts.type
|
|
94
110
|
});
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Is this project one of the machine's entries (see src/entries.ts)? Then the shared server serves
|
|
113
|
+
* it, under its path, and no server of its own runs. A project outside every include runs its own.
|
|
114
|
+
*/
|
|
115
|
+
function isShared(proj) {
|
|
116
|
+
const config = readMachineConfig();
|
|
117
|
+
return !!config && !!matchesEntries(config, proj.dir);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The running server of this project: the URL it is served at (`http://localhost:4777`, or
|
|
121
|
+
* `http://localhost:4777/rg/develop` under the shared server), or null.
|
|
122
|
+
*/
|
|
123
|
+
async function running(proj) {
|
|
124
|
+
if (!isShared(proj)) return runningServer(proj);
|
|
125
|
+
const file = machineServerFile();
|
|
126
|
+
const shared = await sharedServer(file);
|
|
127
|
+
if (!shared) return null;
|
|
128
|
+
const mine = shared.projects.find((p) => p.dir === proj.dir) ?? (await sharedServer(file, { rescan: true }))?.projects.find((p) => p.dir === proj.dir);
|
|
129
|
+
return mine ? `${shared.origin}${mine.base}` : null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* This project's server, started in the background when it is not running. Under the shared server
|
|
133
|
+
* nothing is started: it is started outside every agent's sandbox (a login service, or `whiteboard
|
|
134
|
+
* serve` in a terminal), since it serves every project of the entries and runs their plugins; a
|
|
135
|
+
* command inside one sandbox would start it boxed in there. Only `show` and a plugin's command that
|
|
136
|
+
* asks for the server get here. @returns the URL it serves the project at
|
|
137
|
+
*/
|
|
98
138
|
async function ensureServer() {
|
|
99
139
|
const proj = needProject();
|
|
140
|
+
const shared = isShared(proj);
|
|
100
141
|
const base = await running(proj);
|
|
142
|
+
if (shared) {
|
|
143
|
+
const server = await sharedServer(machineServerFile());
|
|
144
|
+
if (base) {
|
|
145
|
+
if (server && compareVersions(VERSION, server.version) > 0) console.error(`whiteboard: the shared server runs ${server.version}, this is ${VERSION}; restart it to upgrade (\`whiteboard serve\` takes it over)`);
|
|
146
|
+
return base;
|
|
147
|
+
}
|
|
148
|
+
throw new Error(server ? `the shared server at ${server.origin} does not serve ${proj.dir}; is it in an include of ${machineDir()}/config.json?` : `the shared server is not running. It is started outside the agents' sandboxes: as a login service, or with \`whiteboard serve\` in a terminal, outside any project`);
|
|
149
|
+
}
|
|
101
150
|
if (base) return base;
|
|
102
151
|
const lock = path.join(proj.wb, "server.lock");
|
|
103
152
|
const claim = () => {
|
|
@@ -147,12 +196,59 @@ async function ensureServer() {
|
|
|
147
196
|
}
|
|
148
197
|
throw new Error(`server did not start; see ${proj.logFile}`);
|
|
149
198
|
}
|
|
199
|
+
/** This project's running server, or an error saying how to start one. */
|
|
200
|
+
async function needServer() {
|
|
201
|
+
const proj = needProject();
|
|
202
|
+
const base = await running(proj);
|
|
203
|
+
if (base) return base;
|
|
204
|
+
if (isShared(proj)) {
|
|
205
|
+
const port = recordedSharedPort(machineServerFile());
|
|
206
|
+
throw new Error(port ? `the shared server recorded on port ${port} did not answer, or does not serve ${proj.dir}` : "the shared server is not running. It is started outside the agents' sandboxes: as a login service, or with `whiteboard serve` in a terminal, outside any project");
|
|
207
|
+
}
|
|
208
|
+
throw new Error("no server runs for this project; `whiteboard show <page>` starts it");
|
|
209
|
+
}
|
|
210
|
+
/** Is there a page (a markdown file) in this folder or below it? */
|
|
211
|
+
function hasPages(dir) {
|
|
212
|
+
let entries;
|
|
213
|
+
try {
|
|
214
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
215
|
+
} catch {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
return entries.some((e) => e.isDirectory() ? !e.name.startsWith(".") && hasPages(path.join(dir, e.name)) : e.name.endsWith(".md"));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Ask the project's server. Without one running, a server made for this one question answers it,
|
|
222
|
+
* in this process, on no port: a command that only asks (status, docs, the hooks on every prompt)
|
|
223
|
+
* never starts one. It has no listeners, as no server runs to hold them.
|
|
224
|
+
*/
|
|
150
225
|
async function api(route) {
|
|
151
|
-
const
|
|
226
|
+
const base = await running(needProject());
|
|
227
|
+
const res = base ? await fetch(`${base}${route}`) : await askInProcess(route);
|
|
152
228
|
const body = await res.json();
|
|
153
229
|
if (!res.ok) throw new Error(body.error ?? res.statusText);
|
|
154
230
|
return body;
|
|
155
231
|
}
|
|
232
|
+
async function askInProcess(route) {
|
|
233
|
+
if (route.startsWith("/api/status") && !hasPages(needProject().pagesDir)) return Response.json([]);
|
|
234
|
+
const { createServer } = await import("../src/server.js");
|
|
235
|
+
const server = createServer(needProject());
|
|
236
|
+
const listener = http.createServer((req, res) => void server.handle(req, res));
|
|
237
|
+
await new Promise((r) => listener.listen(0, "127.0.0.1", r));
|
|
238
|
+
try {
|
|
239
|
+
const { port } = listener.address();
|
|
240
|
+
const res = await fetch(`http://127.0.0.1:${port}${route}`);
|
|
241
|
+
const text = await res.text();
|
|
242
|
+
return new Response(text, {
|
|
243
|
+
status: res.status,
|
|
244
|
+
headers: res.headers
|
|
245
|
+
});
|
|
246
|
+
} finally {
|
|
247
|
+
server.close();
|
|
248
|
+
listener.closeAllConnections();
|
|
249
|
+
listener.close();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
156
252
|
/**
|
|
157
253
|
* Tell the project's server that an agent is waiting, for as long as this command runs: pages show
|
|
158
254
|
* what is waited for. Holds one connection open, the listener; reconnects when the server restarts.
|
|
@@ -167,7 +263,7 @@ function listen(f, command, fallback = false) {
|
|
|
167
263
|
const connect = async () => {
|
|
168
264
|
let base;
|
|
169
265
|
try {
|
|
170
|
-
base = await
|
|
266
|
+
base = await needServer();
|
|
171
267
|
} catch {
|
|
172
268
|
return setTimeout(connect, 2e3).unref();
|
|
173
269
|
}
|
|
@@ -203,11 +299,11 @@ function listen(f, command, fallback = false) {
|
|
|
203
299
|
* Who else listens, kept current: the fallback leaves to them what they would take. Calls
|
|
204
300
|
* `changed` after each change (the server's live channel says when).
|
|
205
301
|
*/
|
|
206
|
-
async function otherListeners(changed) {
|
|
302
|
+
async function otherListeners(changed, server = needServer) {
|
|
207
303
|
let list = [];
|
|
208
304
|
const load = async () => {
|
|
209
305
|
try {
|
|
210
|
-
list = await (await fetch(`${await
|
|
306
|
+
list = await (await fetch(`${await server()}/api/listeners`)).json();
|
|
211
307
|
} catch {}
|
|
212
308
|
changed();
|
|
213
309
|
};
|
|
@@ -221,7 +317,7 @@ async function otherListeners(changed) {
|
|
|
221
317
|
};
|
|
222
318
|
let base;
|
|
223
319
|
try {
|
|
224
|
-
base = await
|
|
320
|
+
base = await server();
|
|
225
321
|
} catch {
|
|
226
322
|
return retry();
|
|
227
323
|
}
|
|
@@ -280,8 +376,11 @@ const relFile = (file) => path.relative(process.cwd(), file) || file;
|
|
|
280
376
|
* The project's config, as the command line needs it: for its plugins (their commands, the
|
|
281
377
|
* session, which events reach an agent), so without the pages. Loaded once per command.
|
|
282
378
|
*/
|
|
283
|
-
|
|
284
|
-
const projectConfig = (proj) =>
|
|
379
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
380
|
+
const projectConfig = (proj) => {
|
|
381
|
+
if (!loaded.has(proj.dir)) loaded.set(proj.dir, createConfigLoader(proj, { pages: false }).config());
|
|
382
|
+
return loaded.get(proj.dir);
|
|
383
|
+
};
|
|
285
384
|
/**
|
|
286
385
|
* The agent session this command runs in, as the project's plugins know it (Claude Code's
|
|
287
386
|
* plugin reads it from the environment): the first one that names one. Null without any.
|
|
@@ -313,7 +412,17 @@ async function status() {
|
|
|
313
412
|
}
|
|
314
413
|
switch (cmd) {
|
|
315
414
|
case "serve": {
|
|
415
|
+
if (!project && readMachineConfig()) {
|
|
416
|
+
const { startShared } = await import("../src/serve.js");
|
|
417
|
+
await startShared();
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
316
420
|
const proj = needProject();
|
|
421
|
+
if (isShared(proj)) {
|
|
422
|
+
const { startShared } = await import("../src/serve.js");
|
|
423
|
+
await startShared();
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
317
426
|
const base = await running(proj);
|
|
318
427
|
if (base) {
|
|
319
428
|
console.error(`whiteboard: ${proj.name} is already served at ${base}`);
|
|
@@ -323,6 +432,23 @@ switch (cmd) {
|
|
|
323
432
|
await start(proj);
|
|
324
433
|
break;
|
|
325
434
|
}
|
|
435
|
+
case "build": {
|
|
436
|
+
const proj = needProject();
|
|
437
|
+
const { createServer } = await import("../src/server.js");
|
|
438
|
+
const server = createServer(proj);
|
|
439
|
+
try {
|
|
440
|
+
const result = await server.build({
|
|
441
|
+
pages: positionals.length ? positionals : void 0,
|
|
442
|
+
out: opts.out,
|
|
443
|
+
skip: opts.skip != null ? opts.skip.split(",").map((s) => s.trim()).filter(Boolean) : void 0
|
|
444
|
+
});
|
|
445
|
+
for (const w of result.warnings) console.error(`whiteboard build: ${w}`);
|
|
446
|
+
console.log(`built ${result.pages.length} page${result.pages.length === 1 ? "" : "s"} into ${path.relative(process.cwd(), result.out) || "."}`);
|
|
447
|
+
} finally {
|
|
448
|
+
server.close();
|
|
449
|
+
}
|
|
450
|
+
process.exit(0);
|
|
451
|
+
}
|
|
326
452
|
case "init":
|
|
327
453
|
init(positionals[0]);
|
|
328
454
|
break;
|
|
@@ -361,7 +487,7 @@ switch (cmd) {
|
|
|
361
487
|
case "show":
|
|
362
488
|
case "url": {
|
|
363
489
|
if (cmd === "show" && !positionals[0]) throw new Error("usage: whiteboard show <page|file>");
|
|
364
|
-
const base = await ensureServer();
|
|
490
|
+
const base = cmd === "show" ? await ensureServer() : await needServer();
|
|
365
491
|
console.log(`${base}/${pageId(project, positionals[0] ?? "")}`);
|
|
366
492
|
break;
|
|
367
493
|
}
|
|
@@ -417,7 +543,7 @@ switch (cmd) {
|
|
|
417
543
|
if (!target || !to) throw new Error("usage: whiteboard scroll <page|file> <heading, form name or text>");
|
|
418
544
|
const proj = needProject();
|
|
419
545
|
const id = pageId(proj, target);
|
|
420
|
-
const base = await
|
|
546
|
+
const base = await needServer();
|
|
421
547
|
const rendered = await (await fetch(`${base}/api/render?page=${encodeURIComponent(id)}`)).json().catch(() => null);
|
|
422
548
|
const text = (rendered?.html ?? "").replace(/<[^>]+>/g, " ").replace(/&[a-z#0-9]+;/gi, " ").replace(/\s+/g, " ").toLowerCase();
|
|
423
549
|
const named = new RegExp(`<form[^>]*\\bname="${to.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"`).test(rendered?.html ?? "");
|
|
@@ -506,6 +632,11 @@ switch (cmd) {
|
|
|
506
632
|
case "watch": {
|
|
507
633
|
const proj = needProject();
|
|
508
634
|
const f = filter();
|
|
635
|
+
const entry = !f.page && isShared(proj) ? matchesEntries(readMachineConfig(), proj.dir) : null;
|
|
636
|
+
if (entry) {
|
|
637
|
+
await entryFallback(entry, f, cmd);
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
509
640
|
const { handedOut } = await projectConfig(proj);
|
|
510
641
|
const fallback = !f.page;
|
|
511
642
|
let recheck = () => {};
|
|
@@ -561,6 +692,20 @@ switch (cmd) {
|
|
|
561
692
|
case "status":
|
|
562
693
|
await status();
|
|
563
694
|
break;
|
|
695
|
+
case "paths": {
|
|
696
|
+
const config = readMachineConfig();
|
|
697
|
+
if (!config) throw new Error(`no machine config: ${machineDir()}/config.json`);
|
|
698
|
+
const paths = serverPaths(config, { packageDir: PACKAGE_DIR });
|
|
699
|
+
try {
|
|
700
|
+
fs.mkdirSync(stateDir(), { recursive: true });
|
|
701
|
+
} catch {}
|
|
702
|
+
const write = paths.write.filter((d) => fs.existsSync(d));
|
|
703
|
+
const read = paths.read.filter((d) => fs.existsSync(d));
|
|
704
|
+
if (opts.write) console.log(write.join(":"));
|
|
705
|
+
else if (opts.read) console.log(read.join(":"));
|
|
706
|
+
else console.log(`write: ${write.join(":")}\nread: ${read.join(":")}`);
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
564
709
|
case "skill": {
|
|
565
710
|
const source = packagePath("skills", "whiteboard");
|
|
566
711
|
if (!positionals[0]) {
|
|
@@ -629,6 +774,112 @@ switch (cmd) {
|
|
|
629
774
|
if (!asked) process.exit(1);
|
|
630
775
|
}
|
|
631
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* The fallback of a whole entry: what no other wait or watch in any of its projects would take, on
|
|
779
|
+
* any page, also once they stop, from each project's own log, each event with the project it is
|
|
780
|
+
* from (`project`, its folder) and its page's `url`. One per entry: the shared server holds it, and
|
|
781
|
+
* refuses a second (exit 1). Without a shared server running it waits for one, as any wait does: who
|
|
782
|
+
* else listens is the server's to say. Projects that appear meanwhile are followed too.
|
|
783
|
+
*/
|
|
784
|
+
async function entryFallback(entry, f, command) {
|
|
785
|
+
const file = machineServerFile();
|
|
786
|
+
const count = command === "wait" ? Number(opts.count ?? 1) : Infinity;
|
|
787
|
+
const done = new AbortController();
|
|
788
|
+
let total = 0;
|
|
789
|
+
done.signal.addEventListener("abort", () => setImmediate(() => process.exit(0)));
|
|
790
|
+
if (opts.timeout && command === "wait") setTimeout(() => {
|
|
791
|
+
console.error("timeout");
|
|
792
|
+
process.exit(2);
|
|
793
|
+
}, Number(opts.timeout) * 1e3);
|
|
794
|
+
await new Promise((registered) => {
|
|
795
|
+
const connect = async () => {
|
|
796
|
+
const shared = await sharedServer(file);
|
|
797
|
+
if (!shared) return setTimeout(connect, 2e3).unref();
|
|
798
|
+
const q = new URLSearchParams({
|
|
799
|
+
entry,
|
|
800
|
+
command,
|
|
801
|
+
...f.type ? { type: f.type } : {}
|
|
802
|
+
});
|
|
803
|
+
let again = false;
|
|
804
|
+
const retry = (ms) => {
|
|
805
|
+
if (!again) {
|
|
806
|
+
again = true;
|
|
807
|
+
setTimeout(connect, ms).unref();
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
const req = http.get(`${shared.origin}/api/listen?${q}`, (res) => {
|
|
811
|
+
if (res.statusCode === 409) {
|
|
812
|
+
let body = "";
|
|
813
|
+
res.on("data", (d) => body += d);
|
|
814
|
+
res.on("end", () => {
|
|
815
|
+
console.error(`whiteboard: ${JSON.parse(body || "{}").error ?? "another agent is the fallback"}. Add --page to wait on a page of your own.`);
|
|
816
|
+
process.exit(1);
|
|
817
|
+
});
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
res.resume();
|
|
821
|
+
registered();
|
|
822
|
+
res.on("close", () => retry(1e3));
|
|
823
|
+
});
|
|
824
|
+
req.on("error", () => retry(2e3));
|
|
825
|
+
req.on("socket", (socket) => socket.unref());
|
|
826
|
+
};
|
|
827
|
+
connect();
|
|
828
|
+
});
|
|
829
|
+
const following = /* @__PURE__ */ new Map();
|
|
830
|
+
async function start(p, origin) {
|
|
831
|
+
const proj = project$1(p.dir);
|
|
832
|
+
if (!proj) return;
|
|
833
|
+
const stop = new AbortController();
|
|
834
|
+
following.set(p.dir, stop);
|
|
835
|
+
const { handedOut } = await projectConfig(proj);
|
|
836
|
+
let recheck = () => {};
|
|
837
|
+
const at = async () => {
|
|
838
|
+
const shared = await sharedServer(file);
|
|
839
|
+
const now = shared?.projects.find((x) => x.dir === p.dir);
|
|
840
|
+
if (!shared || !now) throw new Error("not served");
|
|
841
|
+
return `${shared.origin}${now.base}`;
|
|
842
|
+
};
|
|
843
|
+
const others = await otherListeners(() => recheck(), at);
|
|
844
|
+
const held = /* @__PURE__ */ new Set();
|
|
845
|
+
const skip = (e) => {
|
|
846
|
+
if (!held.has(e.id)) {
|
|
847
|
+
held.add(e.id);
|
|
848
|
+
setTimeout(() => recheck(), 500).unref();
|
|
849
|
+
return true;
|
|
850
|
+
}
|
|
851
|
+
return takenByOther(others(), e);
|
|
852
|
+
};
|
|
853
|
+
const page = (id) => id.split("/").map(encodeURIComponent).join("/");
|
|
854
|
+
await handOut(proj.eventsFile, { type: f.type }, (e) => {
|
|
855
|
+
console.log(JSON.stringify({
|
|
856
|
+
...e,
|
|
857
|
+
project: p.dir,
|
|
858
|
+
url: `${origin}${p.base}/${page(e.page)}`
|
|
859
|
+
}));
|
|
860
|
+
if (++total >= count) done.abort();
|
|
861
|
+
}, {
|
|
862
|
+
forAgent: forAgent(handedOut),
|
|
863
|
+
signal: AbortSignal.any([stop.signal, done.signal]),
|
|
864
|
+
skip,
|
|
865
|
+
recheck: (again) => {
|
|
866
|
+
recheck = again;
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
const sync = async () => {
|
|
871
|
+
const shared = await sharedServer(file);
|
|
872
|
+
if (!shared) return;
|
|
873
|
+
const mine = shared.projects.filter((p) => p.entry === entry);
|
|
874
|
+
for (const p of mine) if (!following.has(p.dir)) start(p, shared.origin);
|
|
875
|
+
for (const [dir, stop] of following) if (!mine.some((p) => p.dir === dir)) {
|
|
876
|
+
stop.abort();
|
|
877
|
+
following.delete(dir);
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
await sync();
|
|
881
|
+
setInterval(sync, 2e3);
|
|
882
|
+
}
|
|
632
883
|
/** The commands the project's plugins add: `whiteboard <plugin> [sub]`. */
|
|
633
884
|
async function projectCommands(proj) {
|
|
634
885
|
const { plugins, errors } = await projectConfig(proj);
|
package/dist/client/runtime.js
CHANGED
|
@@ -93,6 +93,17 @@ function reactive(get) {
|
|
|
93
93
|
};
|
|
94
94
|
return value;
|
|
95
95
|
}
|
|
96
|
+
const base = (() => {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(document.getElementById("wb-page")?.textContent ?? "{}");
|
|
99
|
+
} catch {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
})().base ?? "";
|
|
103
|
+
/** A path of the project's server (`/api/events`) as this page requests it. */
|
|
104
|
+
const url = (path) => base + path;
|
|
105
|
+
/** A localStorage key, kept apart from other projects' on the same origin. */
|
|
106
|
+
const storageKey = (key) => base ? `${base}|${key}` : key;
|
|
96
107
|
// src/client/forms.ts
|
|
97
108
|
let root$1;
|
|
98
109
|
let api$1;
|
|
@@ -157,7 +168,7 @@ function onOtherInput(e) {
|
|
|
157
168
|
if (text.value.trim()) option.checked = true;
|
|
158
169
|
else if (option.type === "checkbox") option.checked = false;
|
|
159
170
|
}
|
|
160
|
-
const draftKey = (form) => `wb-draft:${page$1}:${form.getAttribute("name")}
|
|
171
|
+
const draftKey = (form) => storageKey(`wb-draft:${page$1}:${form.getAttribute("name")}`);
|
|
161
172
|
function saveDraft(e) {
|
|
162
173
|
const form = e.target?.closest?.("form");
|
|
163
174
|
if (!form || !managed(form) || !root$1.contains(form) || keepsOwnFields(form)) return;
|
|
@@ -415,7 +426,7 @@ async function flush() {
|
|
|
415
426
|
const batch = queue;
|
|
416
427
|
queue = [];
|
|
417
428
|
try {
|
|
418
|
-
const res = await fetch("/api/markdown", {
|
|
429
|
+
const res = await fetch(url("/api/markdown"), {
|
|
419
430
|
method: "POST",
|
|
420
431
|
headers: { "content-type": "application/json" },
|
|
421
432
|
body: JSON.stringify({ texts: batch.map((b) => b.text) })
|
|
@@ -487,6 +498,8 @@ const handoff = JSON.parse(document.getElementById("wb-page").textContent);
|
|
|
487
498
|
const root = document.getElementById("wb-root");
|
|
488
499
|
const page = handoff.id;
|
|
489
500
|
const isDir = handoff.kind === "pages" || handoff.kind === "folder";
|
|
501
|
+
const live = handoff.live !== false;
|
|
502
|
+
const moduleUrl = (path) => new URL(path, document.baseURI).href;
|
|
490
503
|
let events = [];
|
|
491
504
|
const eventsValue = reactive(() => events);
|
|
492
505
|
const unread = reactive(unread$1);
|
|
@@ -498,10 +511,12 @@ function setEvents(next) {
|
|
|
498
511
|
messagesChanged();
|
|
499
512
|
}
|
|
500
513
|
async function loadEvents() {
|
|
501
|
-
|
|
514
|
+
if (!live) return;
|
|
515
|
+
setEvents((await (await fetch(url(`/api/events?page=${encodeURIComponent(page)}`))).json()).filter((e) => e.page === page));
|
|
502
516
|
}
|
|
503
517
|
async function append(type, data = {}, action = null) {
|
|
504
|
-
|
|
518
|
+
if (!live) throw new Error("a built page is a file: there is no log to append to");
|
|
519
|
+
const res = await fetch(url("/api/events"), {
|
|
505
520
|
method: "POST",
|
|
506
521
|
headers: { "content-type": "application/json" },
|
|
507
522
|
body: JSON.stringify({
|
|
@@ -519,7 +534,8 @@ async function append(type, data = {}, action = null) {
|
|
|
519
534
|
let listeners = [];
|
|
520
535
|
const listenersValue = reactive(() => listeners);
|
|
521
536
|
async function loadListeners() {
|
|
522
|
-
|
|
537
|
+
if (!live) return;
|
|
538
|
+
listeners = await (await fetch(url(`/api/listeners?page=${encodeURIComponent(page)}`))).json();
|
|
523
539
|
listenersValue.notify();
|
|
524
540
|
}
|
|
525
541
|
const renderedListeners = /* @__PURE__ */ new Set();
|
|
@@ -528,11 +544,12 @@ let baseTitle = document.title;
|
|
|
528
544
|
const badges = /* @__PURE__ */ new Map();
|
|
529
545
|
let badgeCount = 0;
|
|
530
546
|
function writeTitle() {
|
|
531
|
-
const list = [...badges.values()].
|
|
547
|
+
const list = [...badges.values()].toSorted((a, b) => a.order - b.order || a.since - b.since);
|
|
532
548
|
document.title = `${list.map((b) => `(${b.text}) `).join("")}${baseTitle}`;
|
|
533
549
|
}
|
|
534
550
|
const api = {
|
|
535
551
|
page,
|
|
552
|
+
url,
|
|
536
553
|
events: eventsValue,
|
|
537
554
|
last: (type) => events.findLast((e) => e.type === type),
|
|
538
555
|
pickedUp: (id) => !!events.find((e) => e.id === id)?.pickedUp,
|
|
@@ -586,8 +603,10 @@ let nextFrontmatter = frontmatter;
|
|
|
586
603
|
const dataValue = reactive(() => data);
|
|
587
604
|
const frontmatterValue = reactive(() => frontmatter);
|
|
588
605
|
const handle = {
|
|
606
|
+
settings: reactive(() => void 0),
|
|
589
607
|
id: page,
|
|
590
608
|
kind: handoff.kind,
|
|
609
|
+
live,
|
|
591
610
|
data: dataValue,
|
|
592
611
|
frontmatter: frontmatterValue,
|
|
593
612
|
onChange(fn) {
|
|
@@ -595,18 +614,18 @@ const handle = {
|
|
|
595
614
|
return () => changeListeners.delete(fn);
|
|
596
615
|
},
|
|
597
616
|
render: async () => {
|
|
598
|
-
const next = await getJson(`/api/render?page=${encodeURIComponent(page)}`);
|
|
617
|
+
const next = await getJson(url(`/api/render?page=${encodeURIComponent(page)}`));
|
|
599
618
|
nextData = next.data ?? null;
|
|
600
619
|
nextFrontmatter = next.frontmatter ?? {};
|
|
601
620
|
return next;
|
|
602
621
|
},
|
|
603
|
-
stored: () => getJson(`/api/page?page=${encodeURIComponent(page)}`)
|
|
622
|
+
stored: () => getJson(url(`/api/page?page=${encodeURIComponent(page)}`))
|
|
604
623
|
};
|
|
605
624
|
/** Did the page change since it was rendered here (its file's time, or it came to be)? Then say so. */
|
|
606
625
|
async function caughtUp() {
|
|
607
626
|
let now;
|
|
608
627
|
try {
|
|
609
|
-
now = (await getJson(`/api/render?page=${encodeURIComponent(page)}`)).mtime ?? null;
|
|
628
|
+
now = (await getJson(url(`/api/render?page=${encodeURIComponent(page)}`))).mtime ?? null;
|
|
610
629
|
} catch {
|
|
611
630
|
now = null;
|
|
612
631
|
}
|
|
@@ -618,7 +637,7 @@ if (!handoff.client) handle.onChange(async () => {
|
|
|
618
637
|
api.rendered();
|
|
619
638
|
});
|
|
620
639
|
function connect() {
|
|
621
|
-
const es = new EventSource(`/api/watch?page=${encodeURIComponent(page)}${isDir ? "&dir" : ""}`);
|
|
640
|
+
const es = new EventSource(url(`/api/watch?page=${encodeURIComponent(page)}${isDir ? "&dir" : ""}`));
|
|
622
641
|
es.onopen = () => {
|
|
623
642
|
document.documentElement.dataset.wbLive = "";
|
|
624
643
|
loadListeners();
|
|
@@ -636,7 +655,7 @@ function connect() {
|
|
|
636
655
|
es.addEventListener("reload", () => {
|
|
637
656
|
const go = async () => {
|
|
638
657
|
try {
|
|
639
|
-
if ((await fetch("/api/health", { cache: "no-store" })).ok) return location.reload();
|
|
658
|
+
if ((await fetch(url("/api/health"), { cache: "no-store" })).ok) return location.reload();
|
|
640
659
|
} catch {}
|
|
641
660
|
setTimeout(go, 500);
|
|
642
661
|
};
|
|
@@ -657,29 +676,53 @@ function connect() {
|
|
|
657
676
|
}
|
|
658
677
|
await Promise.all([loadEvents(), loadListeners()]);
|
|
659
678
|
if (handoff.client) try {
|
|
660
|
-
const mount = (await import(handoff.client)).default;
|
|
679
|
+
const mount = (await import(moduleUrl(handoff.client))).default;
|
|
661
680
|
await mount(root, handle, api);
|
|
662
681
|
} catch (err) {
|
|
663
682
|
console.error("page:", err);
|
|
664
683
|
root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">the page failed to start: ${err.message}</pre>`));
|
|
665
684
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
685
|
+
if (live) {
|
|
686
|
+
trackForms(root, page, api);
|
|
687
|
+
trackReading({
|
|
688
|
+
messages: handoff.messages ?? [],
|
|
689
|
+
events: () => events,
|
|
690
|
+
send: (ids) => {
|
|
691
|
+
append(READ, { ids }).catch((err) => console.error("marking read:", err));
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* A plugin's page handle: the page's, with its own settings, the page's frontmatter under `plugins:`
|
|
697
|
+
* by its name, heard of only when they changed.
|
|
698
|
+
*/
|
|
699
|
+
function handleFor(name) {
|
|
700
|
+
const own = () => {
|
|
701
|
+
const plugins = frontmatter.plugins;
|
|
702
|
+
return plugins && typeof plugins === "object" ? plugins[name] : void 0;
|
|
703
|
+
};
|
|
704
|
+
const settings = reactive(own);
|
|
705
|
+
let last = JSON.stringify(own() ?? null);
|
|
706
|
+
frontmatterValue.on(() => {
|
|
707
|
+
const now = JSON.stringify(own() ?? null);
|
|
708
|
+
if (now === last) return;
|
|
709
|
+
last = now;
|
|
710
|
+
settings.notify();
|
|
711
|
+
});
|
|
712
|
+
return {
|
|
713
|
+
...handle,
|
|
714
|
+
settings
|
|
715
|
+
};
|
|
716
|
+
}
|
|
674
717
|
await Promise.all((handoff.plugins ?? []).map(async (ext) => {
|
|
675
718
|
try {
|
|
676
|
-
const mount = (await import(ext.client)).default;
|
|
719
|
+
const mount = (await import(moduleUrl(ext.client))).default;
|
|
677
720
|
if (typeof mount !== "function") throw new Error("the client module must export a mount(root, page, api) function as default");
|
|
678
|
-
await mount(root,
|
|
721
|
+
await mount(root, handleFor(ext.name), api);
|
|
679
722
|
} catch (err) {
|
|
680
723
|
console.error(`plugin ${ext.name}:`, err);
|
|
681
724
|
root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">
|
|
682
725
|
plugin "${ext.name}" failed in the browser: ${err.message}</pre>`));
|
|
683
726
|
}
|
|
684
727
|
}));
|
|
685
|
-
connect();
|
|
728
|
+
if (live) connect();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
What a program printed, as its terminal showed it: an `ansi` fence holds the
|
|
2
|
+
output with its escape codes, and the page draws it dark, in its colours, as a
|
|
3
|
+
terminal does. It goes through a terminal emulator on the server, so colours
|
|
4
|
+
(16, 256 and true colour, foreground and background), bold, dim and underline
|
|
5
|
+
show, and a progress line that a carriage return writes over shows as it
|
|
6
|
+
ended. It is plain HTML: nothing runs on the page, and `whiteboard build` keeps
|
|
7
|
+
it. Wide output scrolls sideways (a line wraps at 240 columns, as a terminal
|
|
8
|
+
that wide would).
|
|
9
|
+
|
|
10
|
+
````markdown
|
|
11
|
+
```ansi
|
|
12
|
+
\e[32m✔\e[0m parses a page
|
|
13
|
+
\e[31m✖\e[0m renders a diff \e[2m(12ms)\e[0m
|
|
14
|
+
```
|
|
15
|
+
````
|
|
16
|
+
|
|
17
|
+
```ansi
|
|
18
|
+
\e[32m✔\e[0m parses a page
|
|
19
|
+
\e[31m✖\e[0m renders a diff \e[2m(12ms)\e[0m
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The escape byte itself works, and so does any way of writing it out: `\e`,
|
|
23
|
+
`\x1b`, `\033`, `\u001b` or `^[`. A carriage return has to be the byte itself,
|
|
24
|
+
as a program prints it: `\r` written out stays as written, since it is as
|
|
25
|
+
likely a path (`C:\repo`). To capture a command's colours, have it colour
|
|
26
|
+
output that isn't a terminal (`--color=always`, `FORCE_COLOR=1`) and paste
|
|
27
|
+
what it printed.
|
|
28
|
+
|
|
29
|
+
`title` puts it in a window with that label, whose button fills the browser
|
|
30
|
+
window with it:
|
|
31
|
+
|
|
32
|
+
````markdown
|
|
33
|
+
```ansi {title="npm test"}
|
|
34
|
+
…
|
|
35
|
+
```
|
|
36
|
+
````
|