@bigmistqke/whiteboard 0.3.0 → 0.4.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 +67 -17
- package/bin/whiteboard.ts +268 -71
- package/dist/client/runtime.js +88 -41
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +3 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/toc/README.md +12 -0
- package/dist/plugins/toc/index.js +9 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +93 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +174 -32
- package/dist/src/loader.js +7 -2
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +73 -13
- package/dist/src/pages/window.js +30 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +37 -15
- package/package.json +3 -1
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +30 -20
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +16 -1
- package/plugins/mermaid/index.ts +3 -1
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +131 -29
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +13 -3
- package/plugins/toc/README.md +12 -0
- package/plugins/toc/client.ts +58 -29
- package/plugins/toc/index.ts +22 -5
- package/plugins/toc/public/style.css +93 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +25 -7
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +106 -34
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +130 -35
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +67 -23
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +75 -11
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +198 -37
- package/src/pages/window.ts +71 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +351 -108
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
package/dist/src/server.js
CHANGED
|
@@ -6,7 +6,9 @@ import { createAuth } from "./auth.js";
|
|
|
6
6
|
import { FROM_SOURCE, PACKAGE_DIR } from "./package.js";
|
|
7
7
|
import { awaiting, covers, fromReader, heard, questionState, unreadMessages } from "./status.js";
|
|
8
8
|
import { titleOf } from "./pages/render.js";
|
|
9
|
+
import { inPublic } from "./public.js";
|
|
9
10
|
import _taggedTemplateLiteral from "../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js";
|
|
11
|
+
import { stripTypeScriptTypes } from "node:module";
|
|
10
12
|
import fs from "node:fs";
|
|
11
13
|
import path from "node:path";
|
|
12
14
|
// src/server.ts
|
|
@@ -66,6 +68,8 @@ function createServer(project) {
|
|
|
66
68
|
try {
|
|
67
69
|
pluginDirs.add(e.name);
|
|
68
70
|
const dataDir = pluginDir(project.wb, e.name);
|
|
71
|
+
const dir = c.publicDirs.get(e.name);
|
|
72
|
+
const own = (ref) => asset(inPublic(dir, ref, `plugin ${e.name}`));
|
|
69
73
|
const hooks = await e.setup?.({
|
|
70
74
|
project: {
|
|
71
75
|
name: project.name,
|
|
@@ -74,11 +78,13 @@ function createServer(project) {
|
|
|
74
78
|
},
|
|
75
79
|
dataDir,
|
|
76
80
|
authorized: auth.authorized,
|
|
77
|
-
asset
|
|
81
|
+
asset: own
|
|
78
82
|
}) ?? {};
|
|
83
|
+
const client = hooks.client != null ? inPublic(dir, hooks.client, `plugin ${e.name}: client`) : void 0;
|
|
79
84
|
return {
|
|
80
85
|
name: e.name,
|
|
81
86
|
...hooks,
|
|
87
|
+
client,
|
|
82
88
|
table: mountRoutes(e.name, hooks.routes),
|
|
83
89
|
plugin: e
|
|
84
90
|
};
|
|
@@ -131,12 +137,15 @@ function createServer(project) {
|
|
|
131
137
|
async function config() {
|
|
132
138
|
const c = await loader.config();
|
|
133
139
|
setFiles(c.files);
|
|
140
|
+
publicDirs = [...c.publicDirs.values()];
|
|
134
141
|
return c;
|
|
135
142
|
}
|
|
136
143
|
const assets = /* @__PURE__ */ new Set();
|
|
137
144
|
const assetDirs = /* @__PURE__ */ new Set();
|
|
138
|
-
const
|
|
139
|
-
const
|
|
145
|
+
const TYPESCRIPT = /\.m?ts$/i;
|
|
146
|
+
const typeScriptModule = (file) => stripTypeScriptTypes(fs.readFileSync(file, "utf8"));
|
|
147
|
+
let publicDirs = [];
|
|
148
|
+
const servable = (file) => assets.has(file) || publicDirs.some((dir) => within(file, dir) && file !== dir);
|
|
140
149
|
function asset(ref) {
|
|
141
150
|
const file = toPath(ref);
|
|
142
151
|
if (!assets.has(file)) {
|
|
@@ -288,7 +297,9 @@ function createServer(project) {
|
|
|
288
297
|
}
|
|
289
298
|
/** A config that failed to load: the page as stored, as text, under the error. */
|
|
290
299
|
function rawRender(page) {
|
|
291
|
-
const list = (items) => html`<ul
|
|
300
|
+
const list = (items) => html`<ul>
|
|
301
|
+
${items.map(([href, text]) => html`<li><a href="${href}">${text}</a></li>`)}
|
|
302
|
+
</ul>`;
|
|
292
303
|
if (page.kind === "pages") return { html: list(page.pages.map((p) => [`/${p.id}`, p.id])) };
|
|
293
304
|
if (page.kind === "folder") return { html: list(page.entries.map((e) => [encodeURIComponent(e.name) + (e.dir ? "/" : ""), e.name + (e.dir ? "/" : "")])) };
|
|
294
305
|
return { html: html`<pre>${page.source}</pre>` };
|
|
@@ -302,6 +313,8 @@ function createServer(project) {
|
|
|
302
313
|
asset,
|
|
303
314
|
urlFor
|
|
304
315
|
});
|
|
316
|
+
/** A stored page's frontmatter, for the browser (PageHandle.frontmatter): a markdown page's, else none. */
|
|
317
|
+
const frontmatterOf = (page) => page.kind === "page" ? page.frontmatter : {};
|
|
305
318
|
/** Render a stored page as markdown, with the plugins' blocks, and anything the reader should be told. */
|
|
306
319
|
async function render(page) {
|
|
307
320
|
const { pages, errors } = await config();
|
|
@@ -398,7 +411,7 @@ function createServer(project) {
|
|
|
398
411
|
};
|
|
399
412
|
}
|
|
400
413
|
const json = (s) => JSON.stringify(s).replace(/</g, "\\u003c");
|
|
401
|
-
const DOCK_STYLE = "#wb-dock{position:fixed;right:16px;bottom:calc(16px + var(--wb-inset-bottom,0px));z-index:
|
|
414
|
+
const DOCK_STYLE = "#wb-dock{position:fixed;right:16px;bottom:calc(16px + var(--wb-inset-bottom,0px));z-index:30;display:flex;flex-direction:column;align-items:flex-end;gap:6px}#wb-dock:empty{display:none}.wb-toasts{display:flex;flex-direction:column;align-items:flex-end;gap:6px}.wb-toasts:empty{display:none}.wb-toast{display:inline-flex;align-items:center;gap:8px;cursor:pointer;padding:5px 12px;border-radius:99px;font:600 .8rem/1.4 var(--sans,system-ui,sans-serif);background:var(--accent,#1d5bbf);color:var(--accent-text,#fff);border:1px solid transparent;box-shadow:0 2px 10px rgb(0 0 0/.18)}.wb-toast[hidden]{display:none}.wb-toast[data-kind=warn]{background:var(--warn,#6b4fc0)}.wb-toast[data-kind=alert]{background:var(--bad,#c4352b);color:#fff}@keyframes wb-flash{from{outline-color:var(--accent,#1d5bbf)}to{outline-color:transparent}}.wb-flash{outline:3px solid transparent;outline-offset:6px;border-radius:4px;animation:wb-flash 2s ease-out}.wb-toast-dismiss{margin-right:-4px;padding:0 4px;border-left:1px solid rgb(255 255 255/.35);opacity:.75}.wb-toast-dismiss:hover{opacity:1}";
|
|
402
415
|
/** `extras`: what plugins add to <head> and <body> (see shellExtras). */
|
|
403
416
|
function shell(page, { page: rendered, out, notices }, extras = {
|
|
404
417
|
head: [],
|
|
@@ -410,21 +423,22 @@ function createServer(project) {
|
|
|
410
423
|
kind: page.kind,
|
|
411
424
|
client: rendered ? asset(PAGE_CLIENT) : null,
|
|
412
425
|
data: out.data ?? null,
|
|
426
|
+
frontmatter: frontmatterOf(page),
|
|
413
427
|
plugins: extras.clients,
|
|
414
428
|
messages: extras.messages ?? []
|
|
415
429
|
};
|
|
416
430
|
return String(html(_templateObject || (_templateObject = _taggedTemplateLiteral([
|
|
417
|
-
"<!doctype html
|
|
418
|
-
"</title>\n<style
|
|
419
|
-
"</style>\n",
|
|
431
|
+
"<!doctype html>\n <html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" />\n <title>",
|
|
432
|
+
"</title>\n <style>\n ",
|
|
433
|
+
"\n </style>\n ",
|
|
420
434
|
"",
|
|
421
|
-
"</head>\n<body data-page=\"",
|
|
435
|
+
"\n </head>\n <body data-page=\"",
|
|
422
436
|
"\" data-kind=\"",
|
|
423
|
-
"\">\n",
|
|
424
|
-
"\n<div id=\"wb-root\">",
|
|
425
|
-
"</div>\n<div id=\"wb-dock\"></div>\n<script type=\"application/json\" id=\"wb-page\"
|
|
426
|
-
"<\/script>\n<script type=\"module\" src=\"/_/runtime.js\"><\/script
|
|
427
|
-
"</body
|
|
437
|
+
"\">\n ",
|
|
438
|
+
"\n <div id=\"wb-root\">",
|
|
439
|
+
"</div>\n <div id=\"wb-dock\"></div>\n <script type=\"application/json\" id=\"wb-page\">\n ",
|
|
440
|
+
"\n <\/script>\n <script type=\"module\" src=\"/_/runtime.js\"><\/script>\n ",
|
|
441
|
+
"\n </body>\n </html>"
|
|
428
442
|
])), out.title || page.id || project.name, DOCK_STYLE, raw(out.head ?? ""), extras.head, page.id, page.kind, notices.map((n) => html`<pre class="wb-error" role="alert">${n}</pre>`), raw(String(out.html)), raw(json(handoff)), extras.body));
|
|
429
443
|
}
|
|
430
444
|
/** A listener as the server holds it. */
|
|
@@ -571,8 +585,15 @@ function createServer(project) {
|
|
|
571
585
|
if (owner) return sendJson(res, 404, { error: `plugin ${owner.name} has no route ${req.method} ${p}` });
|
|
572
586
|
}
|
|
573
587
|
if (p.startsWith("/_/file/")) {
|
|
588
|
+
await config();
|
|
574
589
|
const file = path.resolve(p.slice(7));
|
|
575
590
|
if (!servable(file) || !fs.existsSync(file) || !fs.statSync(file).isFile()) return send(res, 404, "not found", "text/plain");
|
|
591
|
+
asset(file);
|
|
592
|
+
if (TYPESCRIPT.test(file)) try {
|
|
593
|
+
return send(res, 200, typeScriptModule(file), "text/javascript; charset=utf-8");
|
|
594
|
+
} catch (err) {
|
|
595
|
+
return send(res, 200, `throw new SyntaxError(${JSON.stringify(`${path.basename(file)}: ${err.message}`)})`, "text/javascript; charset=utf-8");
|
|
596
|
+
}
|
|
576
597
|
return sendFile(res, file);
|
|
577
598
|
}
|
|
578
599
|
if (p === "/api/health") return sendJson(res, 200, {
|
|
@@ -661,7 +682,8 @@ function createServer(project) {
|
|
|
661
682
|
return sendJson(res, 200, {
|
|
662
683
|
...out,
|
|
663
684
|
notices,
|
|
664
|
-
mtime: r.page.mtime
|
|
685
|
+
mtime: r.page.mtime,
|
|
686
|
+
frontmatter: frontmatterOf(r.page)
|
|
665
687
|
});
|
|
666
688
|
}
|
|
667
689
|
if (p === "/api/watch") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigmistqke/whiteboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A whiteboard for you and your agent: it writes markdown pages you read live in the browser, you answer through forms it waits on",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
"release": "npm run check && npm test && bumpp --commit 'Release v%s' && npm publish --access public",
|
|
89
89
|
"start": "node bin/whiteboard.ts serve",
|
|
90
90
|
"check": "tsc -p tsconfig.json",
|
|
91
|
+
"format": "prettier --write .",
|
|
91
92
|
"test": "node --test --test-force-exit 'src/**/*.test.ts' 'plugins/**/*.test.ts'",
|
|
92
93
|
"test:browser": "node --test --test-force-exit --test-concurrency=1 'test/browser/*.test.ts'"
|
|
93
94
|
},
|
|
@@ -128,6 +129,7 @@
|
|
|
128
129
|
"bumpp": "^12.3.0",
|
|
129
130
|
"morphdom": "^2.7.7",
|
|
130
131
|
"playwright": "^1.60.0",
|
|
132
|
+
"prettier": "^3.10.1",
|
|
131
133
|
"rolldown": "^1.2.19",
|
|
132
134
|
"solid-js": "^2.0.0-rc.21",
|
|
133
135
|
"typescript": "^7.0.2"
|
package/plugins/callout/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
3
3
|
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
4
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
4
5
|
|
|
5
6
|
const TYPES = new Set(['note', 'tip', 'success', 'warning', 'danger', 'question'])
|
|
6
7
|
|
|
@@ -14,10 +15,11 @@ export async function render(ctx: DirectiveContext) {
|
|
|
14
15
|
export default function callout(): Plugin {
|
|
15
16
|
return definePlugin({
|
|
16
17
|
name: 'callout',
|
|
18
|
+
public: builtinPublic('callout'),
|
|
17
19
|
blocks: {
|
|
18
20
|
callout: {
|
|
19
21
|
html: render,
|
|
20
|
-
style:
|
|
22
|
+
style: 'style.css',
|
|
21
23
|
},
|
|
22
24
|
},
|
|
23
25
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* a margin note: a coloured rule and a light tint, set in the body face */
|
|
2
|
+
.wb-callout {
|
|
3
|
+
--c: var(--info);
|
|
4
|
+
margin: calc(var(--rhythm) * 3) 0;
|
|
5
|
+
padding: 1em 1.3em;
|
|
6
|
+
border-left: 3px solid var(--c);
|
|
7
|
+
background: color-mix(in srgb, var(--c) var(--tint-faint), var(--bg));
|
|
8
|
+
border-radius: 0 var(--radius) var(--radius) 0;
|
|
9
|
+
}
|
|
10
|
+
.wb-callout > :first-child {
|
|
11
|
+
margin-top: 0;
|
|
12
|
+
}
|
|
13
|
+
.wb-callout > :last-child {
|
|
14
|
+
margin-bottom: 0;
|
|
15
|
+
}
|
|
16
|
+
.wb-callout-title {
|
|
17
|
+
font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
|
|
18
|
+
color: var(--c);
|
|
19
|
+
margin-bottom: 0.5em;
|
|
20
|
+
letter-spacing: 0.01em;
|
|
21
|
+
}
|
|
22
|
+
.wb-callout:is([data-type='tip'], [data-type='success']) {
|
|
23
|
+
--c: var(--ok);
|
|
24
|
+
}
|
|
25
|
+
.wb-callout:is([data-type='warning'], [data-type='question']) {
|
|
26
|
+
--c: var(--warn);
|
|
27
|
+
}
|
|
28
|
+
.wb-callout[data-type='danger'] {
|
|
29
|
+
--c: var(--bad);
|
|
30
|
+
}
|
package/plugins/chat/autosize.ts
CHANGED
|
@@ -17,21 +17,50 @@ export interface AutosizeOptions {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const SIZING_STYLE = [
|
|
20
|
-
'border-bottom-width',
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
20
|
+
'border-bottom-width',
|
|
21
|
+
'border-left-width',
|
|
22
|
+
'border-right-width',
|
|
23
|
+
'border-top-width',
|
|
24
|
+
'box-sizing',
|
|
25
|
+
'font-family',
|
|
26
|
+
'font-size',
|
|
27
|
+
'font-style',
|
|
28
|
+
'font-weight',
|
|
29
|
+
'letter-spacing',
|
|
30
|
+
'line-height',
|
|
31
|
+
'padding-bottom',
|
|
32
|
+
'padding-left',
|
|
33
|
+
'padding-right',
|
|
34
|
+
'padding-top',
|
|
35
|
+
'tab-size',
|
|
36
|
+
'text-indent',
|
|
37
|
+
'text-rendering',
|
|
38
|
+
'text-transform',
|
|
39
|
+
'width',
|
|
40
|
+
'word-break',
|
|
24
41
|
] as const
|
|
25
42
|
|
|
26
43
|
// forced on the measuring textarea, over anything a page's stylesheet gives textareas (a page's
|
|
27
44
|
// `max-width: 100%` resolves against the body here, and would squeeze it to nothing)
|
|
28
45
|
const HIDDEN_STYLE: Record<string, string> = {
|
|
29
|
-
'min-height': '0',
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
'min-height': '0',
|
|
47
|
+
'max-height': 'none',
|
|
48
|
+
'min-width': '0',
|
|
49
|
+
'max-width': 'none',
|
|
50
|
+
height: '0',
|
|
51
|
+
visibility: 'hidden',
|
|
52
|
+
overflow: 'hidden',
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
'z-index': '-1000',
|
|
55
|
+
top: '0',
|
|
56
|
+
right: '0',
|
|
32
57
|
}
|
|
33
58
|
|
|
34
|
-
interface Sizing {
|
|
59
|
+
interface Sizing {
|
|
60
|
+
style: Record<string, string>
|
|
61
|
+
padding: number
|
|
62
|
+
border: number
|
|
63
|
+
}
|
|
35
64
|
|
|
36
65
|
function sizingOf(node: HTMLElement): Sizing | null {
|
|
37
66
|
const computed = getComputedStyle(node)
|
|
@@ -77,7 +106,12 @@ export function autosize(options: AutosizeOptions = {}) {
|
|
|
77
106
|
if (!node) return
|
|
78
107
|
const sizing = sizingOf(node)
|
|
79
108
|
if (!sizing) return
|
|
80
|
-
const height = heightFor(
|
|
109
|
+
const height = heightFor(
|
|
110
|
+
sizing,
|
|
111
|
+
node.value || node.placeholder || 'x',
|
|
112
|
+
options.minRows ?? 1,
|
|
113
|
+
options.maxRows ?? Infinity,
|
|
114
|
+
)
|
|
81
115
|
if (height === last) return
|
|
82
116
|
last = height
|
|
83
117
|
node.style.setProperty('height', `${height}px`, 'important')
|
package/plugins/chat/client.tsx
CHANGED
|
@@ -10,7 +10,11 @@ import { autosize } from './autosize'
|
|
|
10
10
|
/** A message in a chat: the chat block's own event type. */
|
|
11
11
|
const MESSAGE = 'chat:message'
|
|
12
12
|
|
|
13
|
-
interface Message {
|
|
13
|
+
interface Message {
|
|
14
|
+
id: string
|
|
15
|
+
from: 'you' | 'agent'
|
|
16
|
+
text: string
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* What the reader wrote in a submit of a form: every text in it that is not one of the form's
|
|
@@ -32,11 +36,17 @@ function Chat(props: ChatProps) {
|
|
|
32
36
|
const messages = createMemo((): Message[] => {
|
|
33
37
|
const events = wb.events()
|
|
34
38
|
const own = events.filter(e => e.type === MESSAGE && e.data.chat === props.chat)
|
|
35
|
-
const replaced = new Set(
|
|
39
|
+
const replaced = new Set(
|
|
40
|
+
own
|
|
41
|
+
.map(e => e.data.replaces)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.map(String),
|
|
44
|
+
)
|
|
36
45
|
const out: Message[] = []
|
|
37
46
|
for (const e of own) {
|
|
38
47
|
if (replaced.has(e.id)) continue
|
|
39
|
-
const to =
|
|
48
|
+
const to =
|
|
49
|
+
props.form && e.data.replyTo ? events.find(x => x.id === e.data.replyTo && x.type === props.form) : undefined
|
|
40
50
|
const asked = to ? written(to, props.choices) : ''
|
|
41
51
|
if (to && asked && !out.some(m => m.id === to.id)) out.push({ id: to.id, from: 'you', text: asked })
|
|
42
52
|
out.push({ id: e.id, from: e.from === 'cli' ? 'agent' : 'you', text: String(e.data.text ?? '') })
|
|
@@ -71,9 +81,16 @@ function Chat(props: ChatProps) {
|
|
|
71
81
|
rows={1}
|
|
72
82
|
placeholder={props.form ? "Ask about this question (doesn't choose anything)" : 'Write a message'}
|
|
73
83
|
// Enter sends, Shift+Enter starts a new line; not while an input method is composing
|
|
74
|
-
onKeyDown={e => {
|
|
84
|
+
onKeyDown={e => {
|
|
85
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
|
|
86
|
+
e.preventDefault()
|
|
87
|
+
post()
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
75
90
|
/>
|
|
76
|
-
<button type="button" onClick={post}>
|
|
91
|
+
<button type="button" onClick={post}>
|
|
92
|
+
{props.form ? 'Ask' : 'Send'}
|
|
93
|
+
</button>
|
|
77
94
|
</div>
|
|
78
95
|
</div>
|
|
79
96
|
)
|
package/plugins/chat/index.ts
CHANGED
|
@@ -7,16 +7,20 @@
|
|
|
7
7
|
import fs from 'node:fs'
|
|
8
8
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
9
9
|
import { html, raw, type Block, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
10
|
-
import {
|
|
10
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
11
11
|
import { isQuestionName } from '../../src/status.ts'
|
|
12
12
|
|
|
13
|
-
const style =
|
|
13
|
+
const style = 'style.css'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* What the chat needs to know. `form`: the form it sits under, if any, with the names of its choices,
|
|
17
17
|
* whose values are never a remark (a message can answer text the reader typed into a submit).
|
|
18
18
|
*/
|
|
19
|
-
export interface ChatProps {
|
|
19
|
+
export interface ChatProps {
|
|
20
|
+
chat: string
|
|
21
|
+
form: string | null
|
|
22
|
+
choices: string[]
|
|
23
|
+
}
|
|
20
24
|
|
|
21
25
|
/** The chat itself: a client island, so the server renders nothing for it. */
|
|
22
26
|
const thread: Block<ChatProps> = {
|
|
@@ -27,14 +31,16 @@ const thread: Block<ChatProps> = {
|
|
|
27
31
|
choices: ((ctx as DirectiveContext).attrs.choices ?? '').split(' ').filter(Boolean),
|
|
28
32
|
}),
|
|
29
33
|
html: () => '',
|
|
30
|
-
client:
|
|
34
|
+
client: 'client.js',
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
const quote = (s: string) => s.replace(/"/g, '"')
|
|
34
38
|
|
|
35
39
|
/** The chat thread for `chat`, as markup: for the chat block, and for the form plugin under a form. */
|
|
36
40
|
export const chatThread = (c: DirectiveContext, chat: string, form?: { choices: string[] }) =>
|
|
37
|
-
c.markdown(
|
|
41
|
+
c.markdown(
|
|
42
|
+
`::chat-thread{chat="${quote(chat)}"${form ? ` form="${quote(chat)}" choices="${form.choices.join(' ')}"` : ''}}`,
|
|
43
|
+
)
|
|
38
44
|
|
|
39
45
|
/** `:::chat{name=…}`: a chat on its own, after whatever the block says above it. */
|
|
40
46
|
const chat: Block = {
|
|
@@ -43,18 +49,26 @@ const chat: Block = {
|
|
|
43
49
|
const c = ctx as DirectiveContext
|
|
44
50
|
const name = c.attrs.name || c.attrs.id || 'chat'
|
|
45
51
|
// a chat's name shares the forms' names: a colon marks events, never a chat
|
|
46
|
-
if (!isQuestionName(name))
|
|
52
|
+
if (!isQuestionName(name))
|
|
53
|
+
throw new Error(`chat name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
|
|
47
54
|
const body = c.children.length ? await c.toHtml(c.children) : ''
|
|
48
|
-
return html`<section class="wb-chat-block" data-chat="${name}"
|
|
55
|
+
return html`<section class="wb-chat-block" data-chat="${name}">
|
|
56
|
+
${raw(body)}${raw(await chatThread(c, name))}
|
|
57
|
+
</section>`
|
|
49
58
|
},
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
export default function chatPlugin(): Plugin {
|
|
53
62
|
return definePlugin({
|
|
54
63
|
name: 'chat',
|
|
64
|
+
public: builtinPublic('chat'),
|
|
55
65
|
blocks: { chat, 'chat-thread': thread },
|
|
56
66
|
events: {
|
|
57
|
-
'chat:message': {
|
|
67
|
+
'chat:message': {
|
|
68
|
+
handOut: true,
|
|
69
|
+
forReader: true,
|
|
70
|
+
description: 'a message in a chat: `{ chat, text }`, and `replaces` or `replyTo` (see below)',
|
|
71
|
+
},
|
|
58
72
|
},
|
|
59
73
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
60
74
|
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* A chat: the reader's messages on the right, the agent's on the left; never part of an answer. */
|
|
2
|
+
.wb-chat {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: var(--space-lg);
|
|
6
|
+
font: var(--ui-text)/var(--ui-line-height) var(--sans);
|
|
7
|
+
}
|
|
8
|
+
/* under a form: set off from the question by a dashed rule */
|
|
9
|
+
.wb-chat[data-under-form] {
|
|
10
|
+
margin-top: var(--space-xs);
|
|
11
|
+
padding-top: var(--space-xl);
|
|
12
|
+
border-top: var(--hairline) dashed var(--border);
|
|
13
|
+
}
|
|
14
|
+
.wb-chat-message {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: var(--space-2xs);
|
|
18
|
+
max-width: 85%;
|
|
19
|
+
align-self: flex-start;
|
|
20
|
+
align-items: flex-start;
|
|
21
|
+
}
|
|
22
|
+
.wb-chat-message[data-from='you'] {
|
|
23
|
+
align-self: flex-end;
|
|
24
|
+
align-items: flex-end;
|
|
25
|
+
}
|
|
26
|
+
.wb-chat-who {
|
|
27
|
+
font: var(--weight-strong) var(--ui-tiny)/1.3 var(--sans);
|
|
28
|
+
letter-spacing: var(--caps-spacing);
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
color: var(--muted);
|
|
31
|
+
padding: 0 var(--space-xs);
|
|
32
|
+
}
|
|
33
|
+
.wb-chat-message[data-from='agent'] .wb-chat-who {
|
|
34
|
+
color: var(--accent);
|
|
35
|
+
}
|
|
36
|
+
.wb-chat-bubble {
|
|
37
|
+
white-space: pre-wrap;
|
|
38
|
+
padding: var(--space-md) var(--space-xl);
|
|
39
|
+
border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
|
|
40
|
+
background: var(--tint);
|
|
41
|
+
border: var(--hairline) solid var(--border);
|
|
42
|
+
}
|
|
43
|
+
/* rendered from markdown: its paragraphs and code carry the spacing */
|
|
44
|
+
.wb-chat-bubble[data-md] {
|
|
45
|
+
white-space: normal;
|
|
46
|
+
overflow-wrap: anywhere;
|
|
47
|
+
}
|
|
48
|
+
.wb-chat-bubble[data-md] > :first-child {
|
|
49
|
+
margin-top: 0;
|
|
50
|
+
}
|
|
51
|
+
.wb-chat-bubble[data-md] > :last-child {
|
|
52
|
+
margin-bottom: 0;
|
|
53
|
+
}
|
|
54
|
+
.wb-chat-bubble[data-md] :is(p, ul, ol, pre, blockquote) {
|
|
55
|
+
margin: 0 0 0.5em;
|
|
56
|
+
}
|
|
57
|
+
.wb-chat-bubble[data-md] pre {
|
|
58
|
+
font-size: var(--ui-small);
|
|
59
|
+
padding: var(--space-md) var(--space-lg);
|
|
60
|
+
border-radius: var(--radius-sm);
|
|
61
|
+
overflow-x: auto;
|
|
62
|
+
max-width: 100%;
|
|
63
|
+
}
|
|
64
|
+
.wb-chat-message[data-from='you'] .wb-chat-bubble[data-md] a {
|
|
65
|
+
color: inherit;
|
|
66
|
+
}
|
|
67
|
+
.wb-chat-message[data-from='you'] .wb-chat-bubble {
|
|
68
|
+
border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
|
|
69
|
+
background: var(--accent);
|
|
70
|
+
border-color: var(--accent);
|
|
71
|
+
color: var(--accent-text);
|
|
72
|
+
}
|
|
73
|
+
.wb-chat-new {
|
|
74
|
+
display: flex;
|
|
75
|
+
gap: var(--space-md);
|
|
76
|
+
align-items: flex-start;
|
|
77
|
+
}
|
|
78
|
+
.wb-chat-new textarea {
|
|
79
|
+
flex: 1;
|
|
80
|
+
resize: none;
|
|
81
|
+
font: inherit;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* :::chat on its own: set off from the article like a form, hairlines above and below */
|
|
85
|
+
.wb-chat-block {
|
|
86
|
+
margin: calc(var(--rhythm) * 3) 0;
|
|
87
|
+
padding: 1.6em 0 1.7em;
|
|
88
|
+
border-top: var(--hairline) solid var(--border);
|
|
89
|
+
border-bottom: var(--hairline) solid var(--border);
|
|
90
|
+
display: grid;
|
|
91
|
+
gap: var(--space-2xl);
|
|
92
|
+
}
|
|
93
|
+
.wb-chat-block > :first-child {
|
|
94
|
+
margin-top: 0;
|
|
95
|
+
}
|
|
96
|
+
.wb-chat-block > :is(p, ul, ol) {
|
|
97
|
+
margin: 0;
|
|
98
|
+
}
|
|
@@ -44,17 +44,23 @@ export default function claudeCode(): Plugin {
|
|
|
44
44
|
session: () => process.env.CLAUDE_CODE_SESSION_ID || null,
|
|
45
45
|
commands: {
|
|
46
46
|
hook: {
|
|
47
|
-
description:
|
|
47
|
+
description:
|
|
48
|
+
"what Claude Code runs on an event (stop, prompt or session): report what is open on the session's pages; a stop with questions nobody listens for continues the turn once, to start a wait",
|
|
48
49
|
args: '<stop|prompt|session>',
|
|
49
50
|
async run(ctx) {
|
|
50
51
|
const mode = ctx.positionals[0] as Mode
|
|
51
|
-
if (!mode || !(mode in MODES))
|
|
52
|
+
if (!mode || !(mode in MODES))
|
|
53
|
+
throw new Error(`usage: whiteboard claude-code hook <${Object.keys(MODES).join('|')}>`)
|
|
52
54
|
// a hook that fails must not get in the way of the session it runs in: say why, and exit cleanly
|
|
53
|
-
try {
|
|
55
|
+
try {
|
|
56
|
+
await hook(ctx, mode)
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error(`whiteboard claude-code hook ${mode}: ${(err as Error).message}`)
|
|
59
|
+
}
|
|
54
60
|
},
|
|
55
61
|
},
|
|
56
62
|
install: {
|
|
57
|
-
description:
|
|
63
|
+
description: "add the hooks to this project's .claude/settings.json",
|
|
58
64
|
run: ctx => install(ctx.project.dir),
|
|
59
65
|
},
|
|
60
66
|
},
|
|
@@ -64,7 +70,11 @@ export default function claudeCode(): Plugin {
|
|
|
64
70
|
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
65
71
|
function hookInput(): { session_id?: string; stop_hook_active?: boolean } {
|
|
66
72
|
if (process.stdin.isTTY) return {}
|
|
67
|
-
try {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(fs.readFileSync(0, 'utf8') || '{}')
|
|
75
|
+
} catch {
|
|
76
|
+
return {}
|
|
77
|
+
}
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
const relFile = (file: string) => path.relative(process.cwd(), file) || file
|
|
@@ -82,10 +92,21 @@ async function hook(ctx: CommandContext, mode: Mode) {
|
|
|
82
92
|
// one ends, with what is open shown to the reader instead.
|
|
83
93
|
const loose = mine.filter(p => p.unheard.length || p.unpicked.length)
|
|
84
94
|
if (!loose.length) return
|
|
85
|
-
const said = (p: PageStatus) => {
|
|
95
|
+
const said = (p: PageStatus) => {
|
|
96
|
+
const l = openOn(p, { waiting: false })
|
|
97
|
+
return `${l.slice(0, -1).join('; ')} ${l.at(-1)}`
|
|
98
|
+
}
|
|
86
99
|
const shown = `whiteboard: ${loose.map(p => `${p.page}: ${said(p)}`).join(' · ')}`
|
|
87
|
-
if (input.stop_hook_active) {
|
|
88
|
-
|
|
100
|
+
if (input.stop_hook_active) {
|
|
101
|
+
console.log(JSON.stringify({ systemMessage: shown }))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
const reason = loose
|
|
105
|
+
.map(
|
|
106
|
+
p =>
|
|
107
|
+
`On your whiteboard page ${p.page}: ${openOn(p, { waiting: false }).slice(0, -1).join('; ')}. Run \`whiteboard wait --page ${relFile(p.file)}\` in the background before ending your turn.`,
|
|
108
|
+
)
|
|
109
|
+
.join('\n')
|
|
89
110
|
console.log(JSON.stringify({ decision: 'block', reason, systemMessage: shown }))
|
|
90
111
|
return
|
|
91
112
|
}
|
|
@@ -98,16 +119,23 @@ async function hook(ctx: CommandContext, mode: Mode) {
|
|
|
98
119
|
const handed: WbEvent[] = []
|
|
99
120
|
await ctx.handOut({ page: p.page, exact: true }, e => handed.push(e), { follow: false })
|
|
100
121
|
if (handed.length) {
|
|
101
|
-
out.push(
|
|
122
|
+
out.push(
|
|
123
|
+
`Answers on your page ${p.page} (${relFile(p.file)}) that no wait picked up; they count as picked up now:`,
|
|
124
|
+
)
|
|
102
125
|
for (const e of handed) out.push(JSON.stringify(e))
|
|
103
126
|
}
|
|
104
|
-
if (p.unheard.length)
|
|
127
|
+
if (p.unheard.length)
|
|
128
|
+
out.push(
|
|
129
|
+
`Nobody listens for ${p.unheard.join(', ')} on your page ${p.page}: run \`whiteboard wait --page ${relFile(p.file)}\` in the background.`,
|
|
130
|
+
)
|
|
105
131
|
}
|
|
106
132
|
if (mode === 'session') {
|
|
107
133
|
// a new session may carry on work another one started: say what is open elsewhere, without handing it over
|
|
108
134
|
const others = busy.filter(p => !mine.includes(p))
|
|
109
135
|
if (others.length) {
|
|
110
|
-
out.push(
|
|
136
|
+
out.push(
|
|
137
|
+
"Other pages in this whiteboard project with something open (not this session's; their answers stay for whoever waits on them):",
|
|
138
|
+
)
|
|
111
139
|
for (const p of others) out.push(`- ${p.page} (${whose(p, session)}): ${openOn(p).join(' ')}`)
|
|
112
140
|
}
|
|
113
141
|
}
|
|
@@ -119,13 +147,17 @@ function install(dir: string) {
|
|
|
119
147
|
const file = path.join(dir, '.claude', 'settings.json')
|
|
120
148
|
let settings: Settings = {}
|
|
121
149
|
if (fs.existsSync(file)) {
|
|
122
|
-
try {
|
|
150
|
+
try {
|
|
151
|
+
settings = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
152
|
+
} catch {
|
|
153
|
+
throw new Error(`${file} is not valid JSON; fix it first`)
|
|
154
|
+
}
|
|
123
155
|
}
|
|
124
156
|
// the hooks run outside any project folder's node_modules/.bin, so name the command that works here
|
|
125
157
|
const onPath = spawnSync('sh', ['-c', 'command -v whiteboard'], { encoding: 'utf8' }).status === 0
|
|
126
158
|
const bin = onPath ? 'whiteboard' : 'npx whiteboard'
|
|
127
159
|
const changed: string[] = []
|
|
128
|
-
const hooks = settings.hooks ??= {}
|
|
160
|
+
const hooks = (settings.hooks ??= {})
|
|
129
161
|
for (const [mode, event] of Object.entries(MODES)) {
|
|
130
162
|
const command = `${bin} claude-code hook ${mode}`
|
|
131
163
|
const groups = hooks[event] ?? []
|
|
@@ -137,7 +169,10 @@ function install(dir: string) {
|
|
|
137
169
|
hooks[event] = [...kept, { hooks: [{ type: 'command', command }] }]
|
|
138
170
|
changed.push(event)
|
|
139
171
|
}
|
|
140
|
-
if (!changed.length) {
|
|
172
|
+
if (!changed.length) {
|
|
173
|
+
console.log(`hooks already installed: ${file}`)
|
|
174
|
+
return
|
|
175
|
+
}
|
|
141
176
|
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
142
177
|
fs.writeFileSync(`${file}.tmp`, JSON.stringify(settings, null, 2) + '\n')
|
|
143
178
|
fs.renameSync(`${file}.tmp`, file)
|