@bigmistqke/whiteboard 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +628 -2
  3. package/bin/whiteboard.ts +488 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/whiteboard.js +542 -0
  6. package/dist/client/runtime.js +544 -0
  7. package/dist/define.js +7 -0
  8. package/dist/plugins/callout/README.md +13 -0
  9. package/dist/plugins/callout/index.js +27 -0
  10. package/dist/plugins/callout/style.css +12 -0
  11. package/dist/plugins/chat/README.md +46 -0
  12. package/dist/plugins/chat/client.js +3 -0
  13. package/dist/plugins/chat/index.js +47 -0
  14. package/dist/plugins/chat/style.css +24 -0
  15. package/dist/plugins/claude-code/index.js +120 -0
  16. package/dist/plugins/code/README.md +42 -0
  17. package/dist/plugins/code/diff.js +65 -0
  18. package/dist/plugins/code/index.js +77 -0
  19. package/dist/plugins/code/style.css +29 -0
  20. package/dist/plugins/comments/client.js +10 -0
  21. package/dist/plugins/comments/index.js +54 -0
  22. package/dist/plugins/comments/style.css +40 -0
  23. package/dist/plugins/details/README.md +17 -0
  24. package/dist/plugins/details/index.js +17 -0
  25. package/dist/plugins/details/style.css +3 -0
  26. package/dist/plugins/forge/README.md +12 -0
  27. package/dist/plugins/forge/index.js +83 -0
  28. package/dist/plugins/form/README.md +111 -0
  29. package/dist/plugins/form/index.js +102 -0
  30. package/dist/plugins/form/style.css +41 -0
  31. package/dist/plugins/gallery/README.md +30 -0
  32. package/dist/plugins/gallery/client.js +1 -0
  33. package/dist/plugins/gallery/index.js +74 -0
  34. package/dist/plugins/gallery/style.css +27 -0
  35. package/dist/plugins/grid/README.md +33 -0
  36. package/dist/plugins/grid/index.js +33 -0
  37. package/dist/plugins/grid/style.css +25 -0
  38. package/dist/plugins/iframe/README.md +18 -0
  39. package/dist/plugins/iframe/client.js +1 -0
  40. package/dist/plugins/iframe/index.js +40 -0
  41. package/dist/plugins/iframe/style.css +29 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/mermaid/README.md +21 -0
  44. package/dist/plugins/mermaid/index.js +35 -0
  45. package/dist/plugins/mermaid/style.css +16 -0
  46. package/dist/plugins/quiet/README.md +26 -0
  47. package/dist/plugins/quiet/index.js +17 -0
  48. package/dist/plugins/terminal/client.js +41 -0
  49. package/dist/plugins/terminal/host.js +332 -0
  50. package/dist/plugins/terminal/index.js +171 -0
  51. package/dist/plugins/terminal/modes.js +32 -0
  52. package/dist/plugins/terminal/server.js +256 -0
  53. package/dist/plugins/terminal/sizes.js +57 -0
  54. package/dist/plugins/terminal/style.css +357 -0
  55. package/dist/solid/index.js +36 -0
  56. package/dist/src/auth.js +54 -0
  57. package/dist/src/client/page/base.css +295 -0
  58. package/dist/src/client/page/main.js +1228 -0
  59. package/dist/src/config.js +76 -0
  60. package/dist/src/events.js +183 -0
  61. package/dist/src/html.js +34 -0
  62. package/dist/src/icons.js +6 -0
  63. package/dist/src/load.js +77 -0
  64. package/dist/src/loader.js +126 -0
  65. package/dist/src/package.js +33 -0
  66. package/dist/src/pages/blocks.js +50 -0
  67. package/dist/src/pages/index.js +15 -0
  68. package/dist/src/pages/markdown.js +410 -0
  69. package/dist/src/pages/render.js +311 -0
  70. package/dist/src/plugins.js +238 -0
  71. package/dist/src/running.js +24 -0
  72. package/dist/src/serve.js +71 -0
  73. package/dist/src/server.js +725 -0
  74. package/dist/src/status.js +71 -0
  75. package/package.json +131 -4
  76. package/plugins/callout/README.md +13 -0
  77. package/plugins/callout/index.ts +25 -0
  78. package/plugins/callout/style.css +12 -0
  79. package/plugins/chat/README.md +46 -0
  80. package/plugins/chat/autosize.ts +101 -0
  81. package/plugins/chat/client.tsx +93 -0
  82. package/plugins/chat/index.ts +61 -0
  83. package/plugins/chat/style.css +24 -0
  84. package/plugins/claude-code/index.ts +136 -0
  85. package/plugins/code/README.md +42 -0
  86. package/plugins/code/diff.ts +64 -0
  87. package/plugins/code/index.ts +94 -0
  88. package/plugins/code/style.css +29 -0
  89. package/plugins/comments/client.ts +492 -0
  90. package/plugins/comments/index.ts +54 -0
  91. package/plugins/comments/style.css +40 -0
  92. package/plugins/details/README.md +17 -0
  93. package/plugins/details/index.ts +21 -0
  94. package/plugins/details/style.css +3 -0
  95. package/plugins/forge/README.md +12 -0
  96. package/plugins/forge/index.ts +71 -0
  97. package/plugins/form/README.md +111 -0
  98. package/plugins/form/index.ts +104 -0
  99. package/plugins/form/style.css +41 -0
  100. package/plugins/gallery/README.md +30 -0
  101. package/plugins/gallery/client.tsx +64 -0
  102. package/plugins/gallery/index.ts +67 -0
  103. package/plugins/gallery/style.css +27 -0
  104. package/plugins/grid/README.md +33 -0
  105. package/plugins/grid/index.ts +36 -0
  106. package/plugins/grid/style.css +25 -0
  107. package/plugins/iframe/README.md +18 -0
  108. package/plugins/iframe/client.ts +46 -0
  109. package/plugins/iframe/index.ts +54 -0
  110. package/plugins/iframe/style.css +29 -0
  111. package/plugins/index.ts +21 -0
  112. package/plugins/mermaid/README.md +21 -0
  113. package/plugins/mermaid/index.ts +40 -0
  114. package/plugins/mermaid/style.css +16 -0
  115. package/plugins/quiet/README.md +26 -0
  116. package/plugins/quiet/index.ts +27 -0
  117. package/plugins/terminal/client.ts +317 -0
  118. package/plugins/terminal/host.ts +326 -0
  119. package/plugins/terminal/index.ts +138 -0
  120. package/plugins/terminal/modes.ts +30 -0
  121. package/plugins/terminal/server.ts +215 -0
  122. package/plugins/terminal/sizes.ts +60 -0
  123. package/plugins/terminal/style.css +71 -0
  124. package/skills/whiteboard/SKILL.md +302 -0
  125. package/solid/index.tsx +59 -0
  126. package/src/auth.ts +66 -0
  127. package/src/client/forms.ts +185 -0
  128. package/src/client/markdown.ts +36 -0
  129. package/src/client/page/base.css +295 -0
  130. package/src/client/page/elsewhere.ts +70 -0
  131. package/src/client/page/fresh.ts +205 -0
  132. package/src/client/page/live.ts +30 -0
  133. package/src/client/page/main.ts +272 -0
  134. package/src/client/page/orphans.ts +46 -0
  135. package/src/client/page/sort.ts +38 -0
  136. package/src/client/page/theme.ts +32 -0
  137. package/src/client/page/view.ts +9 -0
  138. package/src/client/page/waiting.ts +182 -0
  139. package/src/client/read.ts +73 -0
  140. package/src/client/runtime.ts +183 -0
  141. package/src/client/toast.ts +25 -0
  142. package/src/config.ts +96 -0
  143. package/src/define.ts +612 -0
  144. package/src/events.ts +218 -0
  145. package/src/html.ts +40 -0
  146. package/src/icons.ts +8 -0
  147. package/src/load.ts +89 -0
  148. package/src/loader.ts +112 -0
  149. package/src/package.ts +39 -0
  150. package/src/pages/blocks.ts +70 -0
  151. package/src/pages/index.ts +42 -0
  152. package/src/pages/markdown.ts +364 -0
  153. package/src/pages/render.ts +233 -0
  154. package/src/plugins.ts +197 -0
  155. package/src/running.ts +22 -0
  156. package/src/serve.ts +52 -0
  157. package/src/server.ts +667 -0
  158. package/src/status.ts +113 -0
@@ -0,0 +1,59 @@
1
+ // Solid 2 adapter for whiteboard template clients.
2
+ //
3
+ // // client.tsx
4
+ // import { solid, useWhiteboard } from '@bigmistqke/whiteboard/solid'
5
+ // function Chart(props) { const wb = useWhiteboard(); … }
6
+ // export default solid(Chart)
7
+ //
8
+ // The engine only knows mount(element, props, api); this turns a component into one and exposes
9
+ // the api's events and theme as signals through context.
10
+ import { createContext, createSignal, onSettled, useContext, type Component } from 'solid-js'
11
+ import { render } from '@solidjs/web'
12
+ import type { ClientApi, Mount, Theme, WbEvent } from '@bigmistqke/whiteboard'
13
+
14
+ export interface Whiteboard {
15
+ /** this page's id */
16
+ page: string
17
+ /** every event recorded for this page. Reactive. */
18
+ events(): WbEvent[]
19
+ /** the latest event of a type, e.g. the last submit of a form. Reactive. */
20
+ last(type: string): WbEvent | undefined
21
+ /** record an event for this page */
22
+ append: ClientApi['append']
23
+ /** the theme in effect. Reactive. */
24
+ theme(): Theme
25
+ /** a message's markdown as HTML, rendered by the server (see Api.markdown) */
26
+ markdown: ClientApi['markdown']
27
+ }
28
+
29
+ const WhiteboardContext = createContext<Whiteboard>()
30
+
31
+ /** The page's events and theme, as signals. Use inside a component passed to solid(). */
32
+ export const useWhiteboard = (): Whiteboard => useContext(WhiteboardContext)
33
+
34
+ /** Turn a Solid component into a template client: `export default solid(MyComponent)`. */
35
+ export function solid<Props extends object>(Component: Component<Props>): Mount<Props> {
36
+ return (element: HTMLElement, props: Props, api: ClientApi) =>
37
+ render(() => {
38
+ const [events, setEvents] = createSignal<WbEvent[]>(api.events())
39
+ const [theme, setTheme] = createSignal<Theme>(api.theme())
40
+ onSettled(() => {
41
+ const offEvents = api.onEvents(list => setEvents(() => list))
42
+ const offTheme = api.onTheme(setTheme)
43
+ return () => { offEvents(); offTheme() }
44
+ })
45
+ const value: Whiteboard = {
46
+ page: api.page,
47
+ events,
48
+ last: type => events().findLast(e => e.type === type),
49
+ append: api.append,
50
+ theme,
51
+ markdown: api.markdown,
52
+ }
53
+ return (
54
+ <WhiteboardContext value={value}>
55
+ <Component {...props} />
56
+ </WhiteboardContext>
57
+ )
58
+ }, element)
59
+ }
package/src/auth.ts ADDED
@@ -0,0 +1,66 @@
1
+ // The project's token: what a browser or command needs for anything that runs code, such as an
2
+ // plugin that starts a process. Pages and events don't need it.
3
+ //
4
+ // /_/auth?token=…&to=/page sets the token as a cookie in this browser, then goes to `to`
5
+ //
6
+ // The token is made on first use and kept in `.whiteboard/token`, readable by its owner only. The
7
+ // command line sends it as a header; a browser gets it once through the link above (a command
8
+ // prints it). The cookie is HttpOnly and SameSite=Lax, and a request from another site is refused
9
+ // even with it, so a website open in the same browser can't use it. One kind is let through: opening
10
+ // a page as the tab's document, as a link from another app or a reload of such a tab does. Then the
11
+ // page shows what needs the token (the terminal drawer) to the reader alone: the site that sent them
12
+ // there can't read it, and the page's own requests come from its own origin.
13
+ //
14
+ // The cookie is Lax, not Strict, for that same case: a browser sends no Strict cookie on a
15
+ // navigation from outside, and a reload of that tab doesn't either, so such a tab never had the
16
+ // drawer until a link inside the page was followed.
17
+ import fs from 'node:fs'
18
+ import path from 'node:path'
19
+ import crypto from 'node:crypto'
20
+ import type { IncomingMessage, ServerResponse } from 'node:http'
21
+
22
+ const COOKIE = 'wb-token'
23
+
24
+ /** The project's token, made on first use. */
25
+ export function projectToken(wb: string): string {
26
+ const file = path.join(wb, 'token')
27
+ try { return fs.readFileSync(file, 'utf8').trim() } catch {}
28
+ const token = crypto.randomBytes(24).toString('base64url')
29
+ fs.writeFileSync(file, token + '\n', { mode: 0o600 })
30
+ return token
31
+ }
32
+
33
+ export function createAuth(wb: string) {
34
+ const token = projectToken(wb)
35
+ const same = (a: unknown, b: string): boolean => typeof a === 'string' && a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b))
36
+ const cookies = (req: IncomingMessage): Record<string, string | undefined> =>
37
+ Object.fromEntries((req.headers.cookie ?? '').split(';').map(c => c.trim().split('=')).filter(([k]) => k))
38
+
39
+ /** Has this request the token, from this origin? */
40
+ function authorized(req: IncomingMessage): boolean {
41
+ const jar = cookies(req)
42
+ const has = same(jar[COOKIE], token) || same(req.headers['x-whiteboard-token'], token)
43
+ if (!has) return false
44
+ const origin = req.headers.origin
45
+ if (origin && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) return false
46
+ const site = req.headers['sec-fetch-site']
47
+ if (site && site !== 'same-origin' && site !== 'none' && !opensPage(req)) return false
48
+ return true
49
+ }
50
+
51
+ /** Opening a page as the tab's document: no frame, no fetch, and not an API route. */
52
+ const opensPage = (req: IncomingMessage) => req.method === 'GET' && req.headers['sec-fetch-mode'] === 'navigate'
53
+ && req.headers['sec-fetch-dest'] === 'document' && !(req.url ?? '').startsWith('/api/')
54
+
55
+ /** The /_/auth route; false for any other path. */
56
+ function handle(req: IncomingMessage, res: ServerResponse, p: string, q: Record<string, unknown>): boolean {
57
+ if (p !== '/_/auth') return false
58
+ if (!same(q.token, token)) { res.writeHead(403, { 'content-type': 'text/plain' }); res.end('wrong token'); return true }
59
+ const to = typeof q.to === 'string' && q.to.startsWith('/') && !q.to.startsWith('//') ? q.to : '/'
60
+ res.writeHead(302, { 'set-cookie': `${COOKIE}=${token}; Path=/; HttpOnly; SameSite=Lax; Max-Age=31536000`, location: to })
61
+ res.end()
62
+ return true
63
+ }
64
+
65
+ return { authorized, handle, token }
66
+ }
@@ -0,0 +1,185 @@
1
+ // Named forms: whiteboard's one interaction primitive, in the browser. A `<form name>` without an
2
+ // `action` (one with an action submits normally) is a question; submitting it appends an event
3
+ // whose type is the form's name, the button its `action` and the fields its `data`. This holds on
4
+ // every page.
5
+ //
6
+ // What the core does with such a form, without drawing anything:
7
+ // - sends a submit as an event, and says how that went: `data-wb-state` is sending, sent or failed;
8
+ // - keeps what the reader typed until it is sent (localStorage, per page and form), across
9
+ // re-renders and reloads;
10
+ // - puts the last answer back into the form, and its button in `data-wb-sent`;
11
+ // - marks where the form stands, from the log and the listeners, with one of these attributes:
12
+ // data-wb-open no answer yet, or the agent asks again (a wait asks for it by name after
13
+ // its answer was picked up)
14
+ // data-wb-pending answered, but no agent has picked the answer up yet
15
+ // data-wb-decided an agent picked up its latest answer; data-wb-outcome quotes it in one line
16
+ // and, for a few seconds after a send went through, `data-wb-just-sent`, to confirm it
17
+ //
18
+ // How that looks is the page's: it styles the attributes, and can follow `api.onForms`. A form
19
+ // marked `data-wb-self` (or inside an element that is) keeps its own fields: no drafts and no last
20
+ // answer are written into it, for a block's component that shows them itself.
21
+ import type { Api, FormState, FormStatus } from '../define'
22
+ import { STATES, isQuestionName, questionState } from '../status.ts'
23
+
24
+ type Data = Record<string, unknown>
25
+
26
+ let root: HTMLElement
27
+ let api: Api
28
+ let page = ''
29
+ const listeners = new Set<(forms: FormStatus[]) => void>()
30
+
31
+ /** The forms the core looks after: named (a name without a colon: see isQuestionName), without an action. */
32
+ const managed = (form: HTMLFormElement) => isQuestionName(form.getAttribute('name') ?? '') && !form.hasAttribute('action')
33
+ const forms = () => [...root.querySelectorAll('form')].filter(managed)
34
+ const keepsOwnFields = (form: HTMLFormElement) => !!form.closest('[data-wb-self]')
35
+
36
+ // ---- reading and writing a form ----------------------------------------------------------------
37
+
38
+ function readForm(form: HTMLFormElement): Data {
39
+ const data: Data = {}
40
+ const elements = [...form.elements] as HTMLInputElement[]
41
+ const boxes: Record<string, number> = {}
42
+ for (const el of elements) if (el.name && el.type === 'checkbox') boxes[el.name] = (boxes[el.name] ?? 0) + 1
43
+ for (const el of elements) {
44
+ if (!el.name || el.type === 'submit' || el.type === 'button' || el.type === 'reset' || el.type === 'file') continue
45
+ if (el.type === 'checkbox') {
46
+ if (boxes[el.name] > 1) { const list = (data[el.name] ??= []) as string[]; if (el.checked) list.push(el.value) }
47
+ else data[el.name] = el.checked
48
+ } else if (el.type === 'radio') {
49
+ if (el.checked) data[el.name] = el.value
50
+ else data[el.name] ??= null
51
+ } else if ((el as unknown) instanceof HTMLSelectElement && (el as unknown as HTMLSelectElement).multiple) {
52
+ data[el.name] = [...(el as unknown as HTMLSelectElement).selectedOptions].map(o => o.value)
53
+ } else data[el.name] = el.value
54
+ }
55
+ return data
56
+ }
57
+
58
+ function writeForm(form: HTMLFormElement, data: Data) {
59
+ for (const el of [...form.elements] as HTMLInputElement[]) {
60
+ if (!el.name || !(el.name in data) || ['submit', 'button', 'hidden', 'file'].includes(el.type)) continue
61
+ const v = data[el.name]
62
+ if (el.type === 'checkbox') el.checked = Array.isArray(v) ? v.includes(el.value) : !!v
63
+ else if (el.type === 'radio') el.checked = v === el.value
64
+ else el.value = v == null ? '' : String(v)
65
+ }
66
+ }
67
+
68
+ // ---- drafts ------------------------------------------------------------------------------------
69
+
70
+ const draftKey = (form: HTMLFormElement) => `wb-draft:${page}:${form.getAttribute('name')}`
71
+
72
+ function saveDraft(e: Event) {
73
+ const form = (e.target as Element | null)?.closest?.('form')
74
+ if (!form || !managed(form) || !root.contains(form) || keepsOwnFields(form)) return
75
+ try { localStorage.setItem(draftKey(form), JSON.stringify(readForm(form))) } catch { /* storage unavailable */ }
76
+ }
77
+
78
+ /** Unsent drafts back into their forms; a form being typed in is left alone. */
79
+ function restoreDrafts() {
80
+ for (const form of forms()) {
81
+ if (keepsOwnFields(form) || form.contains(document.activeElement)) continue
82
+ let draft: Data | null = null
83
+ try { draft = JSON.parse(localStorage.getItem(draftKey(form)) ?? 'null') } catch { /* storage unavailable */ }
84
+ if (draft) writeForm(form, draft)
85
+ }
86
+ }
87
+
88
+ const dropDraft = (form: HTMLFormElement) => { try { localStorage.removeItem(draftKey(form)) } catch { /* storage unavailable */ } }
89
+
90
+ /** Each form's last answer: its button in data-wb-sent, and with `prefill` its fields. */
91
+ function restoreLast(prefill: boolean) {
92
+ for (const form of forms()) {
93
+ const last = api.last(form.getAttribute('name')!)
94
+ if (!last) continue
95
+ form.dataset.wbSent = last.action ?? ''
96
+ if (prefill && !keepsOwnFields(form)) writeForm(form, last.data)
97
+ }
98
+ }
99
+
100
+ async function onSubmit(e: SubmitEvent) {
101
+ const form = e.target as HTMLFormElement
102
+ if (!managed(form) || !root.contains(form)) return
103
+ e.preventDefault()
104
+ const button = e.submitter as HTMLButtonElement | null
105
+ const action = button ? button.value || button.textContent?.trim() || null : null
106
+ form.dataset.wbState = 'sending'
107
+ try {
108
+ await api.append(form.getAttribute('name')!, readForm(form), action)
109
+ dropDraft(form)
110
+ form.dataset.wbState = 'sent'
111
+ form.dataset.wbSent = action ?? ''
112
+ // for the page to confirm the send: set for a few seconds after it, also once the form
113
+ // folds because an agent picked the answer up at once
114
+ form.toggleAttribute('data-wb-just-sent', true)
115
+ clearTimeout(justSent.get(form))
116
+ justSent.set(form, setTimeout(() => form.removeAttribute('data-wb-just-sent'), 3000))
117
+ } catch (err) {
118
+ form.dataset.wbState = 'failed'
119
+ console.error(err)
120
+ }
121
+ }
122
+
123
+ // ---- where each form stands --------------------------------------------------------------------
124
+
125
+ const ATTR: Record<FormState, string> = { open: 'data-wb-open', pending: 'data-wb-pending', decided: 'data-wb-decided' }
126
+
127
+ /** One line quoting an answer: what was chosen, then what was written. */
128
+ function outcome(data: Data, action: string | null) {
129
+ const chosen: string[] = [], written: string[] = []
130
+ for (const v of Object.values(data)) {
131
+ if (v == null || v === '' || v === false) continue
132
+ if (Array.isArray(v)) { if (v.length) chosen.push(v.join(', ')) }
133
+ else if (v === true) continue
134
+ else if (String(v).length > 60 || String(v).includes('\n')) written.push(String(v))
135
+ else chosen.push(String(v))
136
+ }
137
+ if (action && !['Send', 'Submit'].includes(action)) chosen.unshift(action)
138
+ return [chosen.join(' · ') || 'sent', ...written.map(w => `“${w.length > 240 ? w.slice(0, 240) + '…' : w}”`)].join('\n')
139
+ }
140
+
141
+ let current: FormStatus[] = []
142
+ const justSent = new WeakMap<HTMLFormElement, ReturnType<typeof setTimeout>>()
143
+
144
+ /** Mark every form from the log and the listeners, then tell whoever follows. */
145
+ function mark() {
146
+ const listening = api.listeners()
147
+ current = forms().map(form => {
148
+ const name = form.getAttribute('name')!
149
+ const { state, last } = questionState(name, api.events(), listening, api.pickedUp)
150
+ for (const st of STATES) form.toggleAttribute(ATTR[st], st === state)
151
+ if (state === 'decided') form.dataset.wbOutcome = outcome(last!.data, last!.action)
152
+ else delete form.dataset.wbOutcome
153
+ return { form, name, state, last }
154
+ })
155
+ for (const fn of listeners) fn(current)
156
+ }
157
+
158
+ /** After the page re-rendered: answers, drafts and marks back on its forms. */
159
+ function refresh() {
160
+ restoreLast(false)
161
+ restoreDrafts()
162
+ mark()
163
+ }
164
+
165
+ /** Look after the page's named forms; called once the page has mounted. */
166
+ export function trackForms(el: HTMLElement, pageId: string, core: Api) {
167
+ root = el
168
+ page = pageId
169
+ api = core
170
+ document.addEventListener('input', saveDraft)
171
+ document.addEventListener('change', saveDraft)
172
+ document.addEventListener('submit', onSubmit)
173
+ api.onRendered(refresh)
174
+ api.onListeners(mark)
175
+ api.onEvents(() => { restoreLast(false); mark() })
176
+ restoreLast(true)
177
+ restoreDrafts()
178
+ mark()
179
+ }
180
+
181
+ /** For the api: every named form and where it stands, and following that. */
182
+ export const formsApi = {
183
+ forms: (): FormStatus[] => current,
184
+ onForms(fn: (forms: FormStatus[]) => void) { listeners.add(fn); return () => { listeners.delete(fn) } },
185
+ }
@@ -0,0 +1,36 @@
1
+ // Messages written in markdown (comments, chat messages), as HTML: rendered on the server like a
2
+ // page (code fences highlighted, `#12` linked), without raw HTML or directives (api.markdown). The
3
+ // texts asked for at once go in one request; each text is rendered once, then cached. A
4
+ // stylesheet a message needs (the code block's) is linked once it is first used.
5
+
6
+ const cache = new Map<string, Promise<string>>()
7
+ let queue: { text: string; resolve: (html: string) => void; reject: (err: unknown) => void }[] = []
8
+
9
+ async function flush() {
10
+ const batch = queue
11
+ queue = []
12
+ try {
13
+ const res = await fetch('/api/markdown', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ texts: batch.map(b => b.text) }) })
14
+ if (!res.ok) throw new Error(await res.text())
15
+ const { html, styles } = await res.json() as { html: string[]; styles: string[] }
16
+ for (const href of styles) {
17
+ if (![...document.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet]')].some(l => new URL(l.href).pathname === new URL(href, location.href).pathname))
18
+ document.head.insertAdjacentHTML('beforeend', `<link rel="stylesheet" href="${href.replace(/"/g, '&quot;')}">`)
19
+ }
20
+ batch.forEach((b, i) => b.resolve(html[i] ?? ''))
21
+ } catch (err) {
22
+ for (const b of batch) { cache.delete(b.text); b.reject(err) }
23
+ }
24
+ }
25
+
26
+ export function markdown(text: string): Promise<string> {
27
+ let got = cache.get(text)
28
+ if (!got) {
29
+ got = new Promise((resolve, reject) => {
30
+ if (!queue.length) queueMicrotask(flush)
31
+ queue.push({ text, resolve, reject })
32
+ })
33
+ cache.set(text, got)
34
+ }
35
+ return got
36
+ }
@@ -0,0 +1,295 @@
1
+ /* Base page style: an article, set for reading. Blocks bring their own style.css;
2
+ <root>/style.css is loaded after this file to override anything here.
3
+
4
+ Theme: follows the system unless <html data-theme="light|dark"> is set (the nav toggle). */
5
+ :root {
6
+ --bg: #fdfdfc; --surface: #ffffff; --text: #1b1c1e; --muted: #696e76; --border: #e3e5e9;
7
+ --accent: #1d5bbf; --accent-text: #ffffff; --code-bg: #f2f3f5; --tint: #f6f7f9;
8
+ --ok: #1a7a49; --warn: #6b4fc0; --bad: #c4352b; --info: #1d5bbf;
9
+ --radius: 8px; --shadow: none;
10
+ --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
11
+ --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
12
+ --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
13
+ --measure: 680px;
14
+ --wide: 1040px;
15
+ --figure: 920px;
16
+ color-scheme: light;
17
+ }
18
+ @media (prefers-color-scheme: dark) {
19
+ :root:not([data-theme="light"]) {
20
+ --bg: #131417; --surface: #191a1e; --text: #e4e5e7; --muted: #979ca5; --border: #2b2e34;
21
+ --accent: #82aaff; --accent-text: #0d1220; --code-bg: #1e2026; --tint: #1a1c21;
22
+ --ok: #57c48c; --warn: #b4a0ff; --bad: #ff6f66; --info: #82aaff;
23
+ color-scheme: dark;
24
+ }
25
+ }
26
+ :root[data-theme="dark"] {
27
+ --bg: #131417; --surface: #191a1e; --text: #e4e5e7; --muted: #979ca5; --border: #2b2e34;
28
+ --accent: #82aaff; --accent-text: #0d1220; --code-bg: #1e2026; --tint: #1a1c21;
29
+ --ok: #57c48c; --warn: #b4a0ff; --bad: #ff6f66; --info: #82aaff;
30
+ color-scheme: dark;
31
+ }
32
+
33
+ * { box-sizing: border-box; }
34
+ html { -webkit-text-size-adjust: 100%; }
35
+ body {
36
+ margin: 0; background: var(--bg); color: var(--text);
37
+ font: 19px/1.72 var(--serif);
38
+ font-kerning: normal; font-variant-numeric: oldstyle-nums proportional-nums;
39
+ text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
40
+ }
41
+ /* The column: headings sit on its left edge, everything else is indented by --indent, and section
42
+ numbers hang in the margin left of the headings. */
43
+ main { --indent: 34px; max-width: calc(var(--measure) + var(--indent) + 32px); margin: 0 auto; padding: 120px 16px 220px; }
44
+ main > :first-child { margin-top: 0; }
45
+ #wb-main > :not(h1, h2, h3, h4, h5, h6, hr, .wb-wide, .wb-island:has(.wb-wide), figure, .wb-figure, p:has(> img:only-child), p:has(> a:only-child > img:only-child)) { margin-left: var(--indent); }
46
+ #wb-main > :is(h1, h2, h3, h4) + * { margin-top: 0; }
47
+
48
+ /* text */
49
+ a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
50
+ a:hover { text-decoration-color: currentColor; }
51
+ h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
52
+ h1 { font-size: 2.9rem; line-height: 1.08; margin: 0 0 1.1em; letter-spacing: -0.022em; }
53
+ h2 { font-size: 1.62rem; margin: 4.6em 0 1.5em; }
54
+ h3 { font-size: 1.2rem; margin: 3.4em 0 1.2em; }
55
+ #wb-main > h3 { font-style: italic; } /* section headings only; card titles stay upright */
56
+ h4 { font: 600 .74rem/1.4 var(--sans); text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 3em 0 1.1em; }
57
+ p, ul, ol, blockquote, pre, table { margin: 0 0 2.2em; }
58
+ p { margin-bottom: 2.4em; }
59
+ p { text-wrap: pretty; hyphens: auto; }
60
+ ul, ol { padding-left: 1.4em; }
61
+ li::marker { color: var(--muted); }
62
+ li + li { margin-top: .8em; }
63
+ li > p { margin-bottom: .8em; }
64
+ strong { font-weight: 650; }
65
+ img, video { max-width: 100%; height: auto; border-radius: 4px; }
66
+ figure { margin: 3.6em 0; }
67
+ figcaption { font: italic .9rem/1.5 var(--serif); color: var(--muted); margin-top: .7em; }
68
+ code { font: .82em/1.5 var(--mono); background: var(--code-bg); padding: .12em .35em; border-radius: 4px; }
69
+ pre { margin: 3em 0; background: var(--code-bg); padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; font-size: .92rem; line-height: 1.55; }
70
+ pre code { background: none; padding: 0; font-size: .82rem; }
71
+ table { margin: 3em 0; border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font: .88rem/1.5 var(--sans); }
72
+ th, td { border-bottom: 1px solid var(--border); padding: 7px 12px 7px 0; text-align: left; vertical-align: top; }
73
+ th { font-weight: 600; color: var(--muted); }
74
+ li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.4em; }
75
+ li > input[type=checkbox] { margin-right: 8px; }
76
+
77
+ /* standfirst: the paragraph right under the title introduces the piece */
78
+ #wb-main > h1 + p {
79
+ font-size: 1.24em; line-height: 1.5; color: color-mix(in srgb, var(--text) 72%, var(--bg));
80
+ margin-bottom: 3.6em; padding-bottom: 2.6em; border-bottom: 1px solid var(--border);
81
+ }
82
+ /* pull quote */
83
+ blockquote {
84
+ margin: 3.4em 0; padding: 0 0 0 1em; border-left: 2px solid var(--text);
85
+ font-size: 1.24em; line-height: 1.45; font-style: italic; color: var(--text);
86
+ }
87
+ blockquote > :last-child { margin-bottom: 0; }
88
+ /* a section break: an asterism instead of a rule */
89
+ hr { border: 0; margin: 4.6em 0; text-align: center; height: auto; }
90
+ hr::after { content: "⁂"; font-size: 1.1em; color: var(--muted); letter-spacing: .3em; }
91
+
92
+ /* section numbers hanging in the margin: 1, 1.1, 1.1.1, in italic oldstyle figures. Only the
93
+ page's own headings (direct children of main), so headings inside cards stay unnumbered. The
94
+ number is an inline-block pulled into the margin, so it shares the heading's baseline. */
95
+ #wb-main { counter-reset: h2; }
96
+ #wb-main > h2 { counter-increment: h2; counter-reset: h3; }
97
+ #wb-main > h3 { counter-increment: h3; counter-reset: h4; }
98
+ #wb-main > h4 { counter-increment: h4; }
99
+ #wb-main > :is(h2, h3, h4)::before {
100
+ display: inline-block; box-sizing: content-box; width: 64px; margin-left: -86px; margin-right: 22px; text-align: right;
101
+ font-family: var(--serif); font-style: italic; font-weight: 400; font-variant-numeric: oldstyle-nums tabular-nums;
102
+ color: var(--muted); letter-spacing: 0; text-transform: none; white-space: nowrap;
103
+ }
104
+ #wb-main > h2::before { content: counter(h2); font-size: .82em; }
105
+ #wb-main > h3::before { content: counter(h2) "." counter(h3); font-size: .88em; }
106
+ #wb-main > h4::before { content: counter(h2) "." counter(h3) "." counter(h4); font-size: 1.3em; }
107
+ /* no margin to hang them in: set the number in front of the heading, and indent less */
108
+ @media (max-width: 860px) {
109
+ main { --indent: 0px; }
110
+ #wb-main > :is(h2, h3, h4)::before { width: auto; margin-left: 0; margin-right: .6em; text-align: left; }
111
+ }
112
+
113
+ /* a <details>: a quiet, collapsible section rather than a box */
114
+ details { margin: 3.2em 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
115
+ details + details { margin-top: -3.2em; border-top: 0; }
116
+ details > summary {
117
+ cursor: pointer; list-style: none; padding: .95em 0; font: 500 .95rem/1.4 var(--sans); color: var(--text);
118
+ display: flex; gap: .6em; align-items: baseline;
119
+ }
120
+ details > summary::-webkit-details-marker { display: none; }
121
+ details > summary::before { content: "+"; font: 400 1.1em/1 var(--mono); color: var(--muted); width: .8em; flex: none; }
122
+ details[open] > summary::before { content: "−"; }
123
+ details > summary:hover { color: var(--accent); }
124
+ details > :not(summary) { margin-left: 1.4em; }
125
+ details[open] > :last-child { margin-bottom: 2em; }
126
+
127
+ /* figures: an image alone in its paragraph, an HTML <figure>, or anything with .wb-figure (blocks
128
+ opt in) may run wider than the text, up to --figure, centred on the column. Images keep their
129
+ natural size within that. */
130
+ #wb-main > :is(figure, .wb-figure, p:has(> img:only-child), p:has(> a:only-child > img:only-child)) {
131
+ width: min(var(--figure), 100vw - 32px); position: relative; left: 50%; transform: translateX(-50%);
132
+ margin-left: 0; margin-right: 0; text-align: center;
133
+ }
134
+ #wb-main > p:has(> img:only-child), #wb-main > p:has(> a:only-child > img:only-child) { margin-top: 3.6em; margin-bottom: 3.6em; }
135
+ #wb-main > :is(figure, .wb-figure) figcaption { text-align: center; }
136
+
137
+ /* blocks that may run wider than the text column (blocks opt in with .wb-wide) */
138
+ /* positioned with left + transform, not margins, so a block's own margin rules can't undo it */
139
+ .wb-wide { width: min(var(--wide), 100vw - 32px); position: relative; left: 50%; transform: translateX(-50%); }
140
+
141
+ /* frame */
142
+ .wb-nav {
143
+ position: sticky; top: 0; z-index: 5; display: flex; gap: 14px; align-items: center; justify-content: space-between;
144
+ padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
145
+ font: .8rem/1.4 var(--sans); color: var(--muted);
146
+ }
147
+ .wb-nav > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
148
+ .wb-nav a { color: var(--muted); text-decoration: none; }
149
+ .wb-nav a:hover { color: var(--text); }
150
+ /* live.ts: a ring while not connected, grey while live with no agent listening, green with one */
151
+ .wb-live { width: 8px; height: 8px; box-sizing: border-box; border-radius: 50%; border: 1.5px solid var(--muted); background: none; flex: none; }
152
+ [data-wb-live] .wb-live { border-color: var(--muted); background: var(--muted); }
153
+ [data-wb-live] .wb-live[data-agent] { border-color: var(--ok); background: var(--ok); }
154
+ .wb-theme {
155
+ font: inherit; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 99px;
156
+ height: 24px; box-sizing: border-box; padding: 0 7px; cursor: pointer; display: inline-flex; align-items: center; flex: none;
157
+ }
158
+ .wb-theme:hover { color: var(--text); border-color: var(--muted); }
159
+ /* what waits for the reader on other pages (elsewhere.ts): a menu of them */
160
+ .wb-elsewhere { position: relative; flex: none; }
161
+ .wb-elsewhere[hidden], .wb-elsewhere-list[hidden] { display: none; }
162
+ .wb-awaiting {
163
+ font: inherit; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
164
+ border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 99px; height: 24px; box-sizing: border-box; padding: 0 9px; cursor: pointer;
165
+ display: inline-flex; align-items: center; gap: 5px;
166
+ }
167
+ .wb-awaiting svg { flex: none; }
168
+ .wb-index .wb-awaiting { vertical-align: 1px; margin-left: 4px; font: 600 .8rem/1.4 var(--sans); text-decoration: none; }
169
+ .wb-awaiting:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
170
+ .wb-elsewhere-list {
171
+ position: absolute; right: 0; top: calc(100% + 6px); margin: 0; padding: 4px; list-style: none; min-width: 200px; max-width: min(360px, 100vw - 32px);
172
+ background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / .16);
173
+ }
174
+ .wb-nav .wb-elsewhere-list a { display: block; padding: 6px 10px; border-radius: 5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
175
+ .wb-nav .wb-elsewhere-list a:hover, .wb-nav .wb-elsewhere-list a:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); }
176
+ .wb-meta { color: var(--muted); font: .8rem/1.5 var(--sans); }
177
+ .wb-index { padding: 0; }
178
+ .wb-index li { list-style: none; padding: 12px 0; border-bottom: 1px solid var(--border); }
179
+ .wb-index .wb-meta { display: block; }
180
+ .wb-error { color: var(--bad); background: color-mix(in srgb, var(--bad) 7%, var(--bg)); white-space: pre-wrap; font: .8rem/1.5 var(--mono); }
181
+ .wb-unknown > .wb-label { color: var(--muted); }
182
+ .wb-island { display: block; }
183
+ span.wb-island { display: inline; }
184
+
185
+ /* plain named forms: the only engine-level interaction */
186
+ input:not([type=checkbox], [type=radio], [type=range]), textarea, select {
187
+ font: .95rem/1.45 var(--sans); color: inherit; background: var(--surface); border: 1px solid var(--border);
188
+ border-radius: 6px; padding: 8px 10px; max-width: 100%;
189
+ }
190
+ input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
191
+ input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
192
+ button {
193
+ font: 500 .85rem/1.3 var(--sans); padding: 7px 14px; border-radius: 6px; cursor: pointer;
194
+ border: 1px solid var(--border); background: var(--surface); color: var(--text);
195
+ }
196
+ button:hover { border-color: var(--muted); }
197
+
198
+ /* new content since the reader last saw the page */
199
+ #wb-main > * { scroll-margin-top: 72px; }
200
+ .wb-new { position: relative; }
201
+ .wb-new::after {
202
+ content: ""; position: absolute; left: -14px; top: 3px; bottom: 3px; width: 3px; border-radius: 2px;
203
+ background: var(--bad); transition: opacity 1.2s ease;
204
+ }
205
+ .wb-wide.wb-new::after { left: -10px; }
206
+ .wb-new.wb-new-seen::after { opacity: 0; transition-delay: 1s; }
207
+ .wb-fresh button { display: inline-flex; align-items: center; gap: 8px; }
208
+ .wb-fresh-close { display: inline-block; margin-right: -4px; padding: 0 4px; border-left: 1px solid rgb(255 255 255 / .35); opacity: .75; }
209
+ .wb-fresh-close:hover { opacity: 1; }
210
+ .wb-fresh { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
211
+
212
+ form.wb-form[data-wb-folded] { padding: 1em 0; gap: 0; }
213
+ /* named forms: the core marks where each stands (data-wb-open, -pending, -decided); this is how that looks */
214
+ form[data-wb-state=sending] { opacity: .7; }
215
+ /* sending: the form's buttons can't send twice */
216
+ form[data-wb-state=sending] button { pointer-events: none; cursor: progress; }
217
+ /* just sent: a short green flash, and a line saying what happened, for a few seconds */
218
+ @keyframes wb-sent { from { background-color: color-mix(in srgb, var(--ok) 22%, transparent); } to { background-color: transparent; } }
219
+ form[data-wb-just-sent] { animation: wb-sent 1.4s ease-out; }
220
+ form.wb-form[data-wb-state=failed]::before { content: "couldn't send it: try again"; display: block; margin-bottom: 8px; color: var(--bad); font: 600 .75rem/1.4 var(--sans); }
221
+ form[data-wb-sent]:not(.wb-form)::after { content: "✓ sent " attr(data-wb-sent); display: block; margin-top: 6px; color: var(--ok); font: .8rem var(--sans); }
222
+ form[data-wb-state=failed]:not(.wb-form)::after { content: "failed to send"; color: var(--bad); }
223
+
224
+ /* the button in the page's corner that goes to the next thing waiting for the reader */
225
+ .wb-waiting-next { background: var(--accent); color: var(--accent-text); border-color: var(--accent); border-radius: 99px; font-size: .8rem; }
226
+ .wb-waiting-next[hidden] { display: none; }
227
+
228
+ /* a question the reader hasn't answered, or one the agent asks again */
229
+ form[data-wb-open] { outline: 2px solid var(--accent); outline-offset: 10px; border-radius: 2px; }
230
+ form[data-wb-open]::before { content: "waiting for you"; display: block; margin-bottom: 8px; color: var(--accent); font: 600 .75rem/1.4 var(--sans); letter-spacing: .04em; text-transform: uppercase; }
231
+ form[data-wb-pending]::before { content: "sent · waiting for the agent to pick it up"; display: block; margin-bottom: 8px; color: var(--muted); font: .75rem/1.4 var(--sans); }
232
+ form[data-wb-pending][data-wb-just-sent]::before { content: "✓ sent · waiting for the agent to pick it up"; color: var(--ok); font-weight: 600; }
233
+
234
+ /* decided: the agent picked up the latest answer; the form folds into one line quoting it */
235
+ form[data-wb-folded] { cursor: pointer; }
236
+ form[data-wb-folded] > :not([data-block=chat-thread]) { display: none !important; }
237
+ /* the question's chat stays with it, under the answer and the line that reopens it */
238
+ form[data-wb-folded] > [data-block=chat-thread] { order: 1; margin-top: 14px; cursor: auto; }
239
+ form[data-wb-folded]::before { content: "✓ " attr(data-wb-outcome); display: block; white-space: pre-line; color: var(--text); font: .95rem/1.5 var(--sans); }
240
+ form[data-wb-folded]::after { content: "decided · click to change the answer"; display: block; margin-top: 4px; color: var(--muted); font: .75rem/1.4 var(--sans); }
241
+ form[data-wb-folded][data-wb-just-sent]::after { content: "✓ sent · the agent has it"; color: var(--ok); font-weight: 600; }
242
+ form[data-wb-folded]:hover::after { color: var(--accent); }
243
+
244
+ /* the line above the page: what waits for the reader, what nobody listens for, what is answered */
245
+ .wb-summary[hidden] { display: none; }
246
+ .wb-summary button { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); }
247
+ .wb-summary button:hover { color: var(--text); }
248
+ .wb-summary button:is([data-state=open], [data-state=messages]) { color: var(--accent); font-weight: 600; }
249
+ .wb-summary { max-width: calc(var(--measure) + var(--indent, 34px) + 32px); margin: 0 auto; padding: 96px 16px 0; box-sizing: border-box; color: var(--muted); font: .8rem/1.5 var(--sans); }
250
+ /* the summary takes the space above the title that the page would otherwise start with */
251
+ .wb-summary:not([hidden]) + main { padding-top: 20px; }
252
+ .wb-fresh[hidden], .wb-fresh button[hidden] { display: none; }
253
+ .wb-fresh button { background: var(--bad); color: #fff; border-color: var(--bad); border-radius: 99px; font-size: .8rem; }
254
+
255
+ @media (max-width: 600px) {
256
+ body { font-size: 18px; }
257
+ main { padding-top: 32px; }
258
+ h1 { font-size: 2.2rem; }
259
+ .wb-new::after { left: -9px; }
260
+ }
261
+
262
+ /* repository views: folder listings and code */
263
+ .wb-files { padding: 0; font: .92rem/1.5 var(--mono); }
264
+ .wb-files li { list-style: none; margin: 0; padding: 5px 0; border-bottom: 1px solid var(--border); }
265
+ .wb-files li + li { margin-top: 0; }
266
+ .wb-files a { text-decoration: none; }
267
+ .wb-code-title { font: 500 1.1rem/1.4 var(--mono); letter-spacing: 0; }
268
+ .wb-code.wb-wide { margin-top: 0; }
269
+
270
+ .wb-code > pre { margin-top: 0; }
271
+
272
+ /* the overview's list of the project's documents */
273
+ .wb-documents { margin-top: 2.5em; }
274
+ .wb-documents h2 { font-size: 1.1rem; margin: 0; }
275
+ /* a list's heading with its sort control at the right (sort.ts) */
276
+ .wb-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: .4em; }
277
+ .wb-sort { font: .8rem/1.4 var(--sans); color: var(--muted); display: inline-flex; align-items: baseline; gap: 6px; }
278
+ .wb-sort select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; }
279
+
280
+ /* threads whose form is no longer on the page (orphans.ts): read-only, after the content */
281
+ .wb-orphans { --indent: 34px; max-width: calc(var(--measure) + var(--indent) + 32px); margin: 0 auto; padding: 0 16px 220px; box-sizing: border-box; font: .92rem/1.45 var(--sans); }
282
+ .wb-orphans > * { margin-left: var(--indent); }
283
+ .wb-orphans > h2 { margin-left: 0; padding-top: 2em; }
284
+ /* the page's own bottom space moves below the list */
285
+ main:has(+ .wb-orphans:not([hidden])) { padding-bottom: 0; }
286
+ @media (max-width: 860px) { .wb-orphans { --indent: 0px; } }
287
+ .wb-orphans[hidden] { display: none; }
288
+ .wb-orphans h2 { font-size: 1rem; margin: 0 0 .8em; color: var(--muted); }
289
+ .wb-orphans h3 { font: 600 .8rem/1.4 var(--mono, monospace); margin: 1.2em 0 .5em; }
290
+ .wb-orphan { display: flex; flex-direction: column; gap: 8px; }
291
+ .wb-orphan-message { display: flex; flex-direction: column; gap: 2px; max-width: 85%; align-self: flex-start; }
292
+ .wb-orphan-message[data-from=you] { align-self: flex-end; align-items: flex-end; }
293
+ .wb-orphan-who { font: 600 .68rem/1.3 var(--sans); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
294
+ .wb-orphan-message[data-from=agent] .wb-orphan-who { color: var(--accent); }
295
+ .wb-orphan-text { white-space: pre-wrap; padding: 6px 10px; border-radius: 12px; background: var(--tint, var(--surface)); border: 1px solid var(--border); }