@bigmistqke/whiteboard 0.3.1 → 0.5.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 (174) hide show
  1. package/README.md +119 -18
  2. package/bin/whiteboard.ts +300 -71
  3. package/dist/bin/whiteboard.js +21 -0
  4. package/dist/client/runtime.js +132 -54
  5. package/dist/define.js +21 -2
  6. package/dist/plugins/callout/index.js +3 -1
  7. package/dist/plugins/callout/public/style.css +30 -0
  8. package/dist/plugins/chat/index.js +7 -4
  9. package/dist/plugins/chat/{client.js → public/client.js} +1 -1
  10. package/dist/plugins/chat/public/style.css +98 -0
  11. package/dist/plugins/code/index.js +3 -1
  12. package/dist/plugins/code/public/style.css +68 -0
  13. package/dist/plugins/comments/index.js +4 -5
  14. package/dist/plugins/comments/public/client.js +19 -0
  15. package/dist/plugins/comments/public/style.css +185 -0
  16. package/dist/plugins/details/index.js +7 -2
  17. package/dist/plugins/details/public/style.css +7 -0
  18. package/dist/plugins/draft/README.md +14 -0
  19. package/dist/plugins/draft/index.js +21 -0
  20. package/dist/plugins/draft/public/style.css +21 -0
  21. package/dist/plugins/form/index.js +37 -8
  22. package/dist/plugins/form/public/style.css +126 -0
  23. package/dist/plugins/gallery/index.js +4 -3
  24. package/dist/plugins/gallery/public/client.js +1 -0
  25. package/dist/plugins/gallery/public/style.css +90 -0
  26. package/dist/plugins/grid/index.js +9 -3
  27. package/dist/plugins/grid/public/style.css +71 -0
  28. package/dist/plugins/iframe/index.js +13 -14
  29. package/dist/plugins/iframe/public/style.css +13 -0
  30. package/dist/plugins/index.js +7 -1
  31. package/dist/plugins/mermaid/index.js +3 -1
  32. package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
  33. package/dist/plugins/steps/README.md +42 -0
  34. package/dist/plugins/steps/index.js +99 -0
  35. package/dist/plugins/steps/public/client.js +1 -0
  36. package/dist/plugins/steps/public/style.css +77 -0
  37. package/dist/plugins/terminal/host.js +9 -3
  38. package/dist/plugins/terminal/index.js +10 -9
  39. package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
  40. package/dist/plugins/terminal/sizes.js +2 -1
  41. package/dist/plugins/toc/README.md +21 -3
  42. package/dist/plugins/toc/index.js +12 -5
  43. package/dist/plugins/toc/public/client.js +1 -0
  44. package/dist/plugins/toc/public/style.css +99 -0
  45. package/dist/plugins/window/README.md +29 -0
  46. package/dist/plugins/window/index.js +64 -0
  47. package/dist/solid/index.js +14 -11
  48. package/dist/src/auth.js +2 -1
  49. package/dist/src/client/page/base.css +1078 -199
  50. package/dist/src/client/page/main.js +188 -39
  51. package/dist/src/loader.js +14 -3
  52. package/dist/src/package.js +3 -6
  53. package/dist/src/pages/blocks.js +8 -13
  54. package/dist/src/pages/markdown.js +1 -1
  55. package/dist/src/pages/render.js +106 -20
  56. package/dist/src/pages/window.js +31 -0
  57. package/dist/src/public.js +24 -0
  58. package/dist/src/server.js +251 -23
  59. package/package.json +5 -2
  60. package/plugins/callout/index.ts +3 -1
  61. package/plugins/callout/public/style.css +30 -0
  62. package/plugins/chat/autosize.ts +43 -9
  63. package/plugins/chat/client.tsx +22 -5
  64. package/plugins/chat/index.ts +22 -8
  65. package/plugins/chat/public/style.css +98 -0
  66. package/plugins/claude-code/index.ts +49 -14
  67. package/plugins/code/diff.ts +28 -8
  68. package/plugins/code/index.ts +33 -21
  69. package/plugins/code/public/style.css +68 -0
  70. package/plugins/comments/client.ts +139 -71
  71. package/plugins/comments/index.ts +9 -7
  72. package/plugins/comments/public/style.css +185 -0
  73. package/plugins/details/index.ts +7 -2
  74. package/plugins/details/public/style.css +7 -0
  75. package/plugins/draft/README.md +14 -0
  76. package/plugins/draft/index.ts +23 -0
  77. package/plugins/draft/public/style.css +21 -0
  78. package/plugins/forge/index.ts +16 -3
  79. package/plugins/form/index.ts +75 -27
  80. package/plugins/form/public/style.css +126 -0
  81. package/plugins/gallery/client.tsx +9 -3
  82. package/plugins/gallery/index.ts +31 -9
  83. package/plugins/gallery/public/style.css +90 -0
  84. package/plugins/grid/index.ts +19 -5
  85. package/plugins/grid/public/style.css +71 -0
  86. package/plugins/iframe/index.ts +20 -23
  87. package/plugins/iframe/public/style.css +13 -0
  88. package/plugins/index.ts +20 -1
  89. package/plugins/mermaid/index.ts +7 -3
  90. package/plugins/mermaid/{style.css → public/style.css} +7 -2
  91. package/plugins/steps/README.md +42 -0
  92. package/plugins/steps/client.ts +66 -0
  93. package/plugins/steps/index.ts +127 -0
  94. package/plugins/steps/public/style.css +77 -0
  95. package/plugins/terminal/client.ts +105 -48
  96. package/plugins/terminal/host.ts +143 -35
  97. package/plugins/terminal/index.ts +84 -25
  98. package/plugins/terminal/public/style.css +225 -0
  99. package/plugins/terminal/server.ts +64 -13
  100. package/plugins/terminal/sizes.ts +16 -4
  101. package/plugins/toc/README.md +21 -3
  102. package/plugins/toc/client.ts +90 -30
  103. package/plugins/toc/index.ts +26 -10
  104. package/plugins/toc/public/style.css +99 -0
  105. package/plugins/window/README.md +29 -0
  106. package/plugins/window/index.ts +85 -0
  107. package/skills/whiteboard/SKILL.md +3 -1
  108. package/solid/index.tsx +24 -9
  109. package/src/auth.ts +28 -9
  110. package/src/client/forms.ts +74 -28
  111. package/src/client/markdown.ts +15 -4
  112. package/src/client/page/base.css +1078 -199
  113. package/src/client/page/elsewhere.ts +32 -15
  114. package/src/client/page/fresh.ts +91 -23
  115. package/src/client/page/hold.ts +11 -2
  116. package/src/client/page/live.ts +10 -6
  117. package/src/client/page/main.ts +124 -42
  118. package/src/client/page/orphans.ts +25 -10
  119. package/src/client/page/sort.ts +14 -4
  120. package/src/client/page/sticky.ts +11 -3
  121. package/src/client/page/theme.ts +11 -7
  122. package/src/client/page/waiting.ts +141 -34
  123. package/src/client/page/window.ts +40 -0
  124. package/src/client/reactive.ts +19 -0
  125. package/src/client/read.ts +17 -10
  126. package/src/client/runtime.ts +170 -40
  127. package/src/client/scroll.ts +14 -4
  128. package/src/client/toast.ts +19 -5
  129. package/src/config.ts +20 -5
  130. package/src/define.ts +119 -31
  131. package/src/events.ts +111 -24
  132. package/src/html.ts +6 -2
  133. package/src/icons.ts +4 -2
  134. package/src/load.ts +10 -2
  135. package/src/loader.ts +81 -12
  136. package/src/package.ts +9 -8
  137. package/src/pages/blocks.ts +20 -14
  138. package/src/pages/index.ts +2 -2
  139. package/src/pages/markdown.ts +113 -34
  140. package/src/pages/render.ts +233 -41
  141. package/src/pages/window.ts +78 -0
  142. package/src/plugins.ts +90 -24
  143. package/src/public.ts +39 -0
  144. package/src/running.ts +8 -2
  145. package/src/serve.ts +29 -7
  146. package/src/server.ts +591 -110
  147. package/src/status.ts +15 -9
  148. package/dist/plugins/callout/style.css +0 -12
  149. package/dist/plugins/chat/style.css +0 -24
  150. package/dist/plugins/code/style.css +0 -29
  151. package/dist/plugins/comments/client.js +0 -10
  152. package/dist/plugins/comments/style.css +0 -40
  153. package/dist/plugins/details/style.css +0 -3
  154. package/dist/plugins/form/style.css +0 -44
  155. package/dist/plugins/gallery/client.js +0 -1
  156. package/dist/plugins/gallery/style.css +0 -27
  157. package/dist/plugins/grid/style.css +0 -25
  158. package/dist/plugins/iframe/client.js +0 -1
  159. package/dist/plugins/iframe/style.css +0 -29
  160. package/dist/plugins/toc/client.js +0 -1
  161. package/dist/plugins/toc/style.css +0 -19
  162. package/plugins/callout/style.css +0 -12
  163. package/plugins/chat/style.css +0 -24
  164. package/plugins/code/style.css +0 -29
  165. package/plugins/comments/style.css +0 -40
  166. package/plugins/details/style.css +0 -3
  167. package/plugins/form/style.css +0 -44
  168. package/plugins/gallery/style.css +0 -27
  169. package/plugins/grid/style.css +0 -25
  170. package/plugins/iframe/client.ts +0 -46
  171. package/plugins/iframe/style.css +0 -29
  172. package/plugins/terminal/style.css +0 -71
  173. package/plugins/toc/style.css +0 -19
  174. /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigmistqke/whiteboard",
3
- "version": "0.3.1",
3
+ "version": "0.5.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
  },
@@ -105,7 +106,8 @@
105
106
  "remark-parse": "^11.0.0",
106
107
  "remark-rehype": "^11.1.2",
107
108
  "shiki": "^4.6.0",
108
- "unified": "^11.0.5"
109
+ "unified": "^11.0.5",
110
+ "yaml": "^2.9.1"
109
111
  },
110
112
  "peerDependencies": {
111
113
  "@solidjs/web": "^2.0.0-rc.21",
@@ -128,6 +130,7 @@
128
130
  "bumpp": "^12.3.0",
129
131
  "morphdom": "^2.7.7",
130
132
  "playwright": "^1.60.0",
133
+ "prettier": "^3.10.1",
131
134
  "rolldown": "^1.2.19",
132
135
  "solid-js": "^2.0.0-rc.21",
133
136
  "typescript": "^7.0.2"
@@ -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: new URL('./style.css', import.meta.url),
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
+ }
@@ -17,21 +17,50 @@ export interface AutosizeOptions {
17
17
  }
18
18
 
19
19
  const SIZING_STYLE = [
20
- 'border-bottom-width', 'border-left-width', 'border-right-width', 'border-top-width', 'box-sizing',
21
- 'font-family', 'font-size', 'font-style', 'font-weight', 'letter-spacing', 'line-height',
22
- 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'tab-size', 'text-indent',
23
- 'text-rendering', 'text-transform', 'width', 'word-break',
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', 'max-height': 'none', 'min-width': '0', 'max-width': 'none', height: '0',
30
- visibility: 'hidden', overflow: 'hidden',
31
- position: 'absolute', 'z-index': '-1000', top: '0', right: '0',
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 { style: Record<string, string>; padding: number; border: number }
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(sizing, node.value || node.placeholder || 'x', options.minRows ?? 1, options.maxRows ?? Infinity)
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')
@@ -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 { id: string; from: 'you' | 'agent'; text: string }
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(own.map(e => e.data.replaces).filter(Boolean).map(String))
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 = props.form && e.data.replyTo ? events.find(x => x.id === e.data.replyTo && x.type === props.form) : undefined
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 => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { e.preventDefault(); post() } }}
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}>{props.form ? 'Ask' : 'Send'}</button>
91
+ <button type="button" onClick={post}>
92
+ {props.form ? 'Ask' : 'Send'}
93
+ </button>
77
94
  </div>
78
95
  </div>
79
96
  )
@@ -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 { builtFile } from '../../src/package.ts'
10
+ import { builtinPublic } from '../../src/package.ts'
11
11
  import { isQuestionName } from '../../src/status.ts'
12
12
 
13
- const style = new URL('./style.css', import.meta.url)
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 { chat: string; form: string | null; choices: string[] }
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: builtFile(import.meta.url, 'client.js'),
34
+ client: 'client.js',
31
35
  }
32
36
 
33
37
  const quote = (s: string) => s.replace(/"/g, '&quot;')
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(`::chat-thread{chat="${quote(chat)}"${form ? ` form="${quote(chat)}" choices="${form.choices.join(' ')}"` : ''}}`)
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)) throw new Error(`chat name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
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}">${raw(body)}${raw(await chatThread(c, name))}</section>`
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': { handOut: true, forReader: true, description: 'a message in a chat: `{ chat, text }`, and `replaces` or `replyTo` (see below)' },
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: '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',
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)) throw new Error(`usage: whiteboard claude-code hook <${Object.keys(MODES).join('|')}>`)
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 { await hook(ctx, mode) } catch (err) { console.error(`whiteboard claude-code hook ${mode}: ${(err as Error).message}`) }
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: 'add the hooks to this project\'s .claude/settings.json',
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 { return JSON.parse(fs.readFileSync(0, 'utf8') || '{}') } catch { return {} }
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) => { const l = openOn(p, { waiting: false }); return `${l.slice(0, -1).join('; ')} ${l.at(-1)}` }
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) { console.log(JSON.stringify({ systemMessage: shown })); return }
88
- const reason = loose.map(p => `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.`).join('\n')
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(`Answers on your page ${p.page} (${relFile(p.file)}) that no wait picked up; they count as picked up now:`)
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) out.push(`Nobody listens for ${p.unheard.join(', ')} on your page ${p.page}: run \`whiteboard wait --page ${relFile(p.file)}\` in the background.`)
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('Other pages in this whiteboard project with something open (not this session\'s; their answers stay for whoever waits on them):')
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 { settings = JSON.parse(fs.readFileSync(file, 'utf8')) } catch { throw new Error(`${file} is not valid JSON; fix it first`) }
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) { console.log(`hooks already installed: ${file}`); return }
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)
@@ -17,20 +17,33 @@ export interface DiffLineInfo {
17
17
  label?: string
18
18
  }
19
19
 
20
- const unprefix = (p: string) => p.replace(/\t.*$/, '').replace(/^"|"$/g, '').replace(/^[ab]\//, '')
20
+ const unprefix = (p: string) =>
21
+ p
22
+ .replace(/\t.*$/, '')
23
+ .replace(/^"|"$/g, '')
24
+ .replace(/^[ab]\//, '')
21
25
 
22
26
  export function diffLines(text: string): DiffLineInfo[] {
23
27
  // a snippet without hunks or file headers (only +, - and unchanged lines, as people paste them):
24
28
  // every line is one of those, without numbers, as no header says where it is
25
29
  if (!/^(@@ -\d|diff --git )/m.test(text)) {
26
- return text.split('\n').map((line): DiffLineInfo => ({ kind: line[0] === '+' ? 'add' : line[0] === '-' ? 'del' : 'context' }))
30
+ return text
31
+ .split('\n')
32
+ .map((line): DiffLineInfo => ({ kind: line[0] === '+' ? 'add' : line[0] === '-' ? 'del' : 'context' }))
27
33
  }
28
- let file = '', oldFile = '', oldN = 0, newN = 0, inHunk = false
29
- let status = '', renamedFrom = ''
34
+ let file = '',
35
+ oldFile = '',
36
+ oldN = 0,
37
+ newN = 0,
38
+ inHunk = false
39
+ let status = '',
40
+ renamedFrom = ''
30
41
  return text.split('\n').map((line): DiffLineInfo => {
31
42
  const at = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line)
32
43
  if (at) {
33
- oldN = Number(at[1]); newN = Number(at[2]); inHunk = true
44
+ oldN = Number(at[1])
45
+ newN = Number(at[2])
46
+ inHunk = true
34
47
  // only a mark that lines were skipped: the numbers are in the gutter, and the text git adds
35
48
  // after them is a guess at the enclosing line, often just the one before
36
49
  return { kind: 'hunk', label: '' }
@@ -43,13 +56,20 @@ export function diffLines(text: string): DiffLineInfo[] {
43
56
  }
44
57
  if (sign === '+') return { kind: 'add', ...where('new', newN++) }
45
58
  if (sign === '-') return { kind: 'del', ...where('old', oldN++) }
46
- if (sign === ' ') { oldN++; return { kind: 'context', ...where('new', newN++) } }
59
+ if (sign === ' ') {
60
+ oldN++
61
+ return { kind: 'context', ...where('new', newN++) }
62
+ }
47
63
  // "" belongs to the hunk; anything else ends it
48
64
  if (sign === '\\') return { kind: 'meta' }
49
65
  inHunk = false
50
66
  }
51
- if (line.startsWith('diff --git ')) { file = ''; oldFile = ''; status = ''; renamedFrom = '' }
52
- else if (line.startsWith('new file mode')) status = 'new'
67
+ if (line.startsWith('diff --git ')) {
68
+ file = ''
69
+ oldFile = ''
70
+ status = ''
71
+ renamedFrom = ''
72
+ } else if (line.startsWith('new file mode')) status = 'new'
53
73
  else if (line.startsWith('deleted file mode')) status = 'deleted'
54
74
  else if (line.startsWith('rename from ')) renamedFrom = line.slice('rename from '.length)
55
75
  else if (line.startsWith('--- ')) oldFile = line === '--- /dev/null' ? '' : unprefix(line.slice(4))
@@ -17,9 +17,11 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
17
17
  // of the text) and where it is (`data-wb-at="file:line"`), which comments on the line record.
18
18
  // shiki loads the first time a page has code, not with the plugin: the command line loads the
19
19
  // built-in plugins too, for their declarations
20
+ import type * as Shiki from 'shiki'
20
21
  import type { BundledTheme, Highlighter } from 'shiki'
21
22
  import type { FenceContext } from '@bigmistqke/whiteboard'
22
23
  import { diffLines } from './diff.ts'
24
+ import { builtinPublic } from '../../src/package.ts'
23
25
 
24
26
  export interface Options {
25
27
  /** Shiki theme names for each page theme (default: GitHub light and dark) */
@@ -40,7 +42,8 @@ export default function code(options: Options = {}): Plugin {
40
42
  const themes = options.themes ?? DEFAULT_THEMES
41
43
  const colorReplacements = options.colorReplacements ?? (options.themes ? {} : DEFAULT_REPLACEMENTS)
42
44
  let highlighter: Promise<Highlighter> | undefined
43
- let shiki: typeof import('shiki') | undefined
45
+ // loaded the first time a page has code, not with the plugin: the command line loads plugins too
46
+ let shiki: typeof Shiki | undefined
44
47
  const loaded = new Set<string>()
45
48
 
46
49
  /** Highlight `code` as `lang`; an unknown or missing language renders as plain text. */
@@ -57,36 +60,45 @@ export default function code(options: Options = {}): Plugin {
57
60
  } else language = 'text'
58
61
  const diff = language === 'diff' ? diffLines(code) : null
59
62
  return h.codeToHtml(code, {
60
- lang: language, themes, defaultColor: false, colorReplacements,
61
- transformers: diff ? [{
62
- line(node, n) {
63
- const info = diff[n - 1]
64
- if (!info) return
65
- node.properties['data-diff'] = info.kind
66
- if (info.n != null) node.properties['data-n'] = String(info.n)
67
- if (info.at) node.properties['data-wb-at'] = info.at
68
- // a file's headers read as its name; a hunk's header as nothing but the gutter's `⋯`
69
- if (info.label != null) node.children = [{ type: 'text', value: info.label }]
70
- },
71
- // the headers nobody reads go, with the line break after each
72
- code(node) {
73
- node.children = node.children.filter((child, i, all) => {
74
- const isMeta = (c: typeof child | undefined) => c?.type === 'element' && c.properties['data-diff'] === 'meta'
75
- return !isMeta(child) && !(child.type === 'text' && isMeta(all[i - 1]))
76
- })
77
- },
78
- }] : [],
63
+ lang: language,
64
+ themes,
65
+ defaultColor: false,
66
+ colorReplacements,
67
+ transformers: diff
68
+ ? [
69
+ {
70
+ line(node, n) {
71
+ const info = diff[n - 1]
72
+ if (!info) return
73
+ node.properties['data-diff'] = info.kind
74
+ if (info.n != null) node.properties['data-n'] = String(info.n)
75
+ if (info.at) node.properties['data-wb-at'] = info.at
76
+ // a file's headers read as its name; a hunk's header as nothing but the gutter's `⋯`
77
+ if (info.label != null) node.children = [{ type: 'text', value: info.label }]
78
+ },
79
+ // the headers nobody reads go, with the line break after each
80
+ code(node) {
81
+ node.children = node.children.filter((child, i, all) => {
82
+ const isMeta = (c: typeof child | undefined) =>
83
+ c?.type === 'element' && c.properties['data-diff'] === 'meta'
84
+ return !isMeta(child) && !(child.type === 'text' && isMeta(all[i - 1]))
85
+ })
86
+ },
87
+ },
88
+ ]
89
+ : [],
79
90
  })
80
91
  }
81
92
 
82
93
  return definePlugin({
83
94
  name: 'code',
95
+ public: builtinPublic('code'),
84
96
  blocks: {
85
97
  code: {
86
98
  // every code fence no other block claims by name, and the code view of repository files
87
99
  fence: 'any',
88
100
  html: ctx => highlight((ctx as FenceContext).text, (ctx as FenceContext).lang),
89
- style: new URL('./style.css', import.meta.url),
101
+ style: 'style.css',
90
102
  },
91
103
  },
92
104
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),