@bigmistqke/whiteboard 0.6.1 → 0.8.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 +23 -216
- package/bin/whiteboard.ts +82 -239
- package/dist/bin/whiteboard.js +70 -200
- package/dist/client/runtime.js +297 -61
- package/dist/plugins/badge/README.md +3 -1
- package/dist/plugins/badge/public/style.css +17 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +19 -6
- package/dist/plugins/code/README.md +10 -0
- package/dist/plugins/code/index.js +31 -22
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +33 -2
- package/dist/plugins/comments/public/client.js +7 -2
- package/dist/plugins/comments/public/style.css +4 -0
- package/dist/plugins/form/public/style.css +2 -0
- package/dist/plugins/grid/public/style.css +0 -5
- package/dist/plugins/iframe/index.js +2 -2
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/lightbox/public/client.js +1 -1
- package/dist/plugins/terminal/index.js +7 -9
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/public/style.css +3 -3
- package/dist/plugins/timeline/README.md +40 -0
- package/dist/plugins/timeline/index.js +82 -0
- package/dist/plugins/timeline/public/style.css +118 -0
- package/dist/plugins/toc/README.md +13 -13
- package/dist/plugins/toc/index.js +6 -4
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +19 -2
- package/dist/plugins/window/index.js +4 -4
- package/dist/solid/index.js +2 -1
- package/dist/src/auth.js +7 -3
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +74 -35
- package/dist/src/client/page/main.js +16 -5
- package/dist/src/document.js +93 -0
- package/dist/src/events.js +7 -15
- package/dist/src/hub.js +90 -53
- package/dist/src/listen.js +100 -0
- package/dist/src/listeners.js +67 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +23 -11
- package/dist/src/pages/render.js +13 -8
- package/dist/src/serve.js +2 -0
- package/dist/src/server.js +204 -514
- package/dist/src/site.js +173 -0
- package/dist/src/status.js +63 -1
- package/dist/src/ws.js +128 -0
- package/package.json +1 -1
- package/plugins/README.md +258 -0
- package/plugins/badge/README.md +3 -1
- package/plugins/badge/public/style.css +17 -0
- package/plugins/chat/client.tsx +34 -6
- package/plugins/chat/public/style.css +19 -6
- package/plugins/code/README.md +10 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/index.ts +38 -26
- package/plugins/code/public/style.css +33 -2
- package/plugins/comments/client.ts +56 -6
- package/plugins/comments/public/style.css +4 -0
- package/plugins/form/public/style.css +2 -0
- package/plugins/grid/public/style.css +0 -5
- package/plugins/iframe/index.ts +2 -2
- package/plugins/index.ts +6 -1
- package/plugins/lightbox/client.ts +13 -3
- package/plugins/terminal/client.ts +10 -2
- package/plugins/terminal/index.ts +8 -6
- package/plugins/terminal/public/style.css +3 -3
- package/plugins/timeline/README.md +40 -0
- package/plugins/timeline/index.ts +92 -0
- package/plugins/timeline/public/style.css +118 -0
- package/plugins/toc/README.md +13 -13
- package/plugins/toc/client.ts +58 -32
- package/plugins/toc/index.ts +13 -13
- package/plugins/toc/public/style.css +19 -2
- package/plugins/window/index.ts +4 -4
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +3 -0
- package/src/auth.ts +7 -2
- package/src/build.ts +213 -0
- package/src/client/forms.ts +102 -5
- package/src/client/page/base.css +74 -35
- package/src/client/page/elsewhere.ts +14 -4
- package/src/client/page/waiting.ts +10 -5
- package/src/client/read.ts +16 -3
- package/src/client/runtime.ts +219 -52
- package/src/client/toast.ts +36 -6
- package/src/define.ts +44 -18
- package/src/document.ts +191 -0
- package/src/events.ts +18 -17
- package/src/hub.ts +102 -56
- package/src/listen.ts +125 -0
- package/src/listeners.ts +95 -0
- package/src/pages/index.ts +1 -1
- package/src/pages/markdown.ts +29 -18
- package/src/pages/render.ts +13 -8
- package/src/serve.ts +2 -0
- package/src/server.ts +223 -611
- package/src/site.ts +165 -0
- package/src/status.ts +100 -0
- package/src/ws.ts +155 -0
package/dist/bin/whiteboard.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { configFileIn, findProjectDir, pageId, project as project$1 } from "../src/config.js";
|
|
3
|
-
import {
|
|
3
|
+
import { appendEvent, editEvent, follow, forAgent, handOut, matches, pick, prune, read, readEvents } from "../src/events.js";
|
|
4
4
|
import { BUILTIN_COMMANDS, createConfigLoader, pluginDir } from "../src/loader.js";
|
|
5
5
|
import { parseCommandArgs, pluginCommands, usage } from "../src/plugins.js";
|
|
6
6
|
import { projectToken } from "../src/auth.js";
|
|
7
7
|
import { PACKAGE_DIR, VERSION, compareVersions, packagePath } from "../src/package.js";
|
|
8
8
|
import { recordedSharedPort, runningServer, sharedServer } from "../src/running.js";
|
|
9
9
|
import { machineDir, machineServerFile, matchesEntries, readMachineConfig, serverPaths, stateDir } from "../src/entries.js";
|
|
10
|
-
import {
|
|
10
|
+
import { CLAIM, pickedUp, statusLines, whose } from "../src/status.js";
|
|
11
|
+
import { fallback, listen } from "../src/listen.js";
|
|
11
12
|
import fs from "node:fs";
|
|
12
13
|
import os from "node:os";
|
|
13
14
|
import path from "node:path";
|
|
@@ -249,99 +250,6 @@ async function askInProcess(route) {
|
|
|
249
250
|
listener.close();
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Tell the project's server that an agent is waiting, for as long as this command runs: pages show
|
|
254
|
-
* what is waited for. Holds one connection open, the listener; reconnects when the server restarts.
|
|
255
|
-
* Reading the log does not depend on it, so answers are never missed when the server is away.
|
|
256
|
-
*/
|
|
257
|
-
/**
|
|
258
|
-
* Tell the server who is listening, for as long as the command runs (again after a restart). The
|
|
259
|
-
* fallback is refused when another one runs: it exits, saying so. Resolves once the server took it.
|
|
260
|
-
*/
|
|
261
|
-
function listen(f, command, fallback = false) {
|
|
262
|
-
return new Promise((registered) => {
|
|
263
|
-
const connect = async () => {
|
|
264
|
-
let base;
|
|
265
|
-
try {
|
|
266
|
-
base = await needServer();
|
|
267
|
-
} catch {
|
|
268
|
-
return setTimeout(connect, 2e3).unref();
|
|
269
|
-
}
|
|
270
|
-
const q = new URLSearchParams({
|
|
271
|
-
command,
|
|
272
|
-
...f.page ? { page: f.page } : {},
|
|
273
|
-
...f.type ? { type: f.type } : {},
|
|
274
|
-
...fallback ? { fallback: "" } : {}
|
|
275
|
-
});
|
|
276
|
-
let again = false;
|
|
277
|
-
const retry = (ms) => {
|
|
278
|
-
if (!again) {
|
|
279
|
-
again = true;
|
|
280
|
-
setTimeout(connect, ms).unref();
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
const req = http.get(`${base}/api/listen?${q}`, (res) => {
|
|
284
|
-
if (res.statusCode === 409) {
|
|
285
|
-
console.error("whiteboard: another agent already takes what no other listener does (a wait or watch without --page; one per project). Add --page to wait on a page of your own.");
|
|
286
|
-
process.exit(1);
|
|
287
|
-
}
|
|
288
|
-
res.resume();
|
|
289
|
-
registered();
|
|
290
|
-
res.on("close", () => retry(1e3));
|
|
291
|
-
});
|
|
292
|
-
req.on("error", () => retry(2e3));
|
|
293
|
-
req.on("socket", (socket) => socket.unref());
|
|
294
|
-
};
|
|
295
|
-
connect();
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Who else listens, kept current: the fallback leaves to them what they would take. Calls
|
|
300
|
-
* `changed` after each change (the server's live channel says when).
|
|
301
|
-
*/
|
|
302
|
-
async function otherListeners(changed, server = needServer) {
|
|
303
|
-
let list = [];
|
|
304
|
-
const load = async () => {
|
|
305
|
-
try {
|
|
306
|
-
list = await (await fetch(`${await server()}/api/listeners`)).json();
|
|
307
|
-
} catch {}
|
|
308
|
-
changed();
|
|
309
|
-
};
|
|
310
|
-
const follow = async () => {
|
|
311
|
-
let again = false;
|
|
312
|
-
const retry = () => {
|
|
313
|
-
if (!again) {
|
|
314
|
-
again = true;
|
|
315
|
-
setTimeout(follow, 1e3).unref();
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
let base;
|
|
319
|
-
try {
|
|
320
|
-
base = await server();
|
|
321
|
-
} catch {
|
|
322
|
-
return retry();
|
|
323
|
-
}
|
|
324
|
-
const req = http.get(`${base}/api/watch?dir`, (res) => {
|
|
325
|
-
let buf = "";
|
|
326
|
-
res.setEncoding("utf8");
|
|
327
|
-
res.on("data", (chunk) => {
|
|
328
|
-
buf += chunk;
|
|
329
|
-
if (buf.includes("event: listeners")) {
|
|
330
|
-
buf = "";
|
|
331
|
-
load();
|
|
332
|
-
}
|
|
333
|
-
if (buf.length > 4096) buf = buf.slice(-64);
|
|
334
|
-
});
|
|
335
|
-
res.on("close", retry);
|
|
336
|
-
load();
|
|
337
|
-
});
|
|
338
|
-
req.on("error", retry);
|
|
339
|
-
req.on("socket", (socket) => socket.unref());
|
|
340
|
-
};
|
|
341
|
-
await load();
|
|
342
|
-
follow();
|
|
343
|
-
return () => list;
|
|
344
|
-
}
|
|
345
253
|
function init(name) {
|
|
346
254
|
const dir = process.cwd();
|
|
347
255
|
const wb = path.join(dir, ".whiteboard");
|
|
@@ -560,7 +468,7 @@ switch (cmd) {
|
|
|
560
468
|
})
|
|
561
469
|
})).json();
|
|
562
470
|
if (!tabs) {
|
|
563
|
-
console.error(`whiteboard: no
|
|
471
|
+
console.error(`whiteboard: no tab of ${id} is connected now; one that is open scrolls there once it is back (a background tab connects again when it is shown). \`whiteboard show ${target}\` prints its URL`);
|
|
564
472
|
process.exit(1);
|
|
565
473
|
}
|
|
566
474
|
console.log(`scrolled ${tabs} tab${tabs > 1 ? "s" : ""} of ${id} to ${JSON.stringify(to)}`);
|
|
@@ -638,39 +546,54 @@ switch (cmd) {
|
|
|
638
546
|
break;
|
|
639
547
|
}
|
|
640
548
|
const { handedOut } = await projectConfig(proj);
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
return true;
|
|
650
|
-
}
|
|
651
|
-
return takenByOther(others(), e);
|
|
549
|
+
const query = {
|
|
550
|
+
command: cmd,
|
|
551
|
+
...f.page ? { page: f.page } : {},
|
|
552
|
+
...f.type ? { type: f.type } : {}
|
|
553
|
+
};
|
|
554
|
+
const refused = (reason) => {
|
|
555
|
+
console.error(`whiteboard: ${reason}: another agent already takes what no other listener does (a wait or watch without --page; one per project). Add --page to wait on a page of your own.`);
|
|
556
|
+
process.exit(1);
|
|
652
557
|
};
|
|
653
|
-
|
|
558
|
+
const at = () => needServer().catch(() => null);
|
|
559
|
+
const options = {
|
|
654
560
|
count: cmd === "wait" ? Number(opts.count ?? 1) : Infinity,
|
|
655
|
-
forAgent: forAgent(handedOut)
|
|
656
|
-
|
|
657
|
-
skip,
|
|
658
|
-
recheck: (again) => {
|
|
659
|
-
recheck = again;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}).then(async () => {
|
|
663
|
-
if (cmd === "wait" && !fallback) try {
|
|
664
|
-
const pages = await api(`/api/status?page=${encodeURIComponent(f.page)}`);
|
|
665
|
-
for (const p of pages) if (p.open.length) console.error(`whiteboard: still unanswered on ${p.page}: ${p.open.join(", ")} → run \`whiteboard wait --page ${relFile(p.file)}\` again, in the background, once you've acted on this`);
|
|
666
|
-
} catch {}
|
|
667
|
-
process.exit(0);
|
|
668
|
-
});
|
|
669
|
-
if (!fallback) listen(f, cmd);
|
|
561
|
+
forAgent: forAgent(handedOut)
|
|
562
|
+
};
|
|
670
563
|
if (opts.timeout && cmd === "wait") setTimeout(() => {
|
|
671
564
|
console.error("timeout");
|
|
672
565
|
process.exit(2);
|
|
673
566
|
}, Number(opts.timeout) * 1e3);
|
|
567
|
+
if (!f.page) {
|
|
568
|
+
const update = fallback((_, handing) => {
|
|
569
|
+
handOut(proj.eventsFile, f, (e) => console.log(JSON.stringify(e)), {
|
|
570
|
+
...options,
|
|
571
|
+
...handing
|
|
572
|
+
}).then(() => process.exit(0));
|
|
573
|
+
});
|
|
574
|
+
await listen({
|
|
575
|
+
at,
|
|
576
|
+
query: {
|
|
577
|
+
...query,
|
|
578
|
+
fallback: ""
|
|
579
|
+
},
|
|
580
|
+
onSnapshot: update,
|
|
581
|
+
onRefused: refused
|
|
582
|
+
});
|
|
583
|
+
} else {
|
|
584
|
+
await listen({
|
|
585
|
+
at,
|
|
586
|
+
query,
|
|
587
|
+
onRefused: refused
|
|
588
|
+
}, { orNone: true });
|
|
589
|
+
handOut(proj.eventsFile, f, (e) => console.log(JSON.stringify(e)), options).then(async () => {
|
|
590
|
+
if (cmd === "wait") try {
|
|
591
|
+
const pages = await api(`/api/status?page=${encodeURIComponent(f.page)}`);
|
|
592
|
+
for (const p of pages) if (p.open.length) console.error(`whiteboard: still unanswered on ${p.page}: ${p.open.join(", ")} → run \`whiteboard wait --page ${relFile(p.file)}\` again, in the background, once you've acted on this`);
|
|
593
|
+
} catch {}
|
|
594
|
+
process.exit(0);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
674
597
|
break;
|
|
675
598
|
}
|
|
676
599
|
case "append": {
|
|
@@ -791,67 +714,12 @@ async function entryFallback(entry, f, command) {
|
|
|
791
714
|
console.error("timeout");
|
|
792
715
|
process.exit(2);
|
|
793
716
|
}, Number(opts.timeout) * 1e3);
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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) {
|
|
717
|
+
let origin = "";
|
|
718
|
+
const page = (id) => id.split("/").map(encodeURIComponent).join("/");
|
|
719
|
+
const update = fallback((p, handing) => {
|
|
831
720
|
const proj = project$1(p.dir);
|
|
832
721
|
if (!proj) return;
|
|
833
|
-
|
|
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) => {
|
|
722
|
+
projectConfig(proj).then(({ handedOut }) => handOut(proj.eventsFile, { type: f.type }, (e) => {
|
|
855
723
|
console.log(JSON.stringify({
|
|
856
724
|
...e,
|
|
857
725
|
project: p.dir,
|
|
@@ -860,25 +728,27 @@ async function entryFallback(entry, f, command) {
|
|
|
860
728
|
if (++total >= count) done.abort();
|
|
861
729
|
}, {
|
|
862
730
|
forAgent: forAgent(handedOut),
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
731
|
+
...handing,
|
|
732
|
+
signal: AbortSignal.any([handing.signal, done.signal])
|
|
733
|
+
}));
|
|
734
|
+
});
|
|
735
|
+
await listen({
|
|
736
|
+
at: async () => {
|
|
737
|
+
origin = (await sharedServer(file))?.origin ?? "";
|
|
738
|
+
return origin || null;
|
|
739
|
+
},
|
|
740
|
+
query: {
|
|
741
|
+
entry,
|
|
742
|
+
command,
|
|
743
|
+
...f.type ? { type: f.type } : {}
|
|
744
|
+
},
|
|
745
|
+
onSnapshot: update,
|
|
746
|
+
onRefused: (reason) => {
|
|
747
|
+
console.error(`whiteboard: ${reason}. Add --page to wait on a page of your own.`);
|
|
748
|
+
process.exit(1);
|
|
878
749
|
}
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
setInterval(sync, 2e3);
|
|
750
|
+
});
|
|
751
|
+
setInterval(() => {}, 1 << 30);
|
|
882
752
|
}
|
|
883
753
|
/** The commands the project's plugins add: `whiteboard <plugin> [sub]`. */
|
|
884
754
|
async function projectCommands(proj) {
|