@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
package/src/status.ts ADDED
@@ -0,0 +1,113 @@
1
+ // What waits for the reader on a page, and how to say what is open on it: one definition for the
2
+ // server (`whiteboard status`, the hooks, the header and overview) and the page in the browser
3
+ // alike. No Node in it, so the browser runtime uses the same module.
4
+ //
5
+ // What waits for the reader is their to-do, not whether an agent's process runs: a question they
6
+ // haven't answered, and a message from the agent they haven't read.
7
+ //
8
+ // A question is a named form; its answers are the reader's events of its name. It stands:
9
+ // open no answer yet, or the agent asks again: a wait or watch asks for it by name after its
10
+ // answer was picked up
11
+ // pending answered, but no agent has picked the answer up yet
12
+ // decided an agent picked up its latest answer
13
+ // Whether an agent listens is told apart where it helps when something goes wrong: the toast after
14
+ // a submit, and `whiteboard status` (`unheard`: open, and no wait or watch takes it).
15
+ //
16
+ // A message is an agent's event of a type a plugin declares `forReader` (a reply in a comment
17
+ // thread, a chat message). It is unread until a `whiteboard:read` event from the reader names it,
18
+ // which the page appends once the message has been in view; one the agent replaced (`replaces`)
19
+ // no longer counts.
20
+ import type { FormState, Listener, PageStatus, WbEvent } from './define.ts'
21
+
22
+ /**
23
+ * Can this be a question's name, the type of its answers? Not with a colon: types with one belong
24
+ * to whiteboard (`whiteboard:picked`) or a plugin (`comments:reply`, `chat:message`),
25
+ * named after its owner, so a form's answers never mix with their events.
26
+ */
27
+ export const isQuestionName = (name: string): boolean => !!name && !name.includes(':')
28
+
29
+ /** The states, in the order a reader should see them: what waits on them first. */
30
+ export const STATES: FormState[] = ['open', 'pending', 'decided']
31
+
32
+ /**
33
+ * Was this event written by the reader (a form submit, a comment), not by an agent? Agents write
34
+ * through the command line, which marks its events `from: 'cli'`: an agent's reply, a claim, a pick.
35
+ */
36
+ export const fromReader = (event: WbEvent): boolean => event.from !== 'cli'
37
+
38
+ /** Does a listener's page filter cover `page`? An empty filter covers every page. */
39
+ export const covers = (l: Listener, page: string): boolean => !l.page || page === l.page || page.startsWith(l.page + '/')
40
+
41
+ /**
42
+ * Would a listener other than the fallback take this event, by its page and type? What the
43
+ * fallback leaves to it.
44
+ */
45
+ export const takenByOther = (listeners: Listener[], event: WbEvent): boolean =>
46
+ listeners.some(l => !l.fallback && covers(l, event.page) && (l.type === null || l.type === event.type))
47
+
48
+ /**
49
+ * Where the question `name` stands. `events` are the page's, `listeners` the running waits and
50
+ * watches that cover the page (only one asking for it by name counts: it asks again),
51
+ * `pickedUp` whether an event was handed to an agent. `last` is its latest answer: the reader's
52
+ * latest event of its name.
53
+ */
54
+ export function questionState(
55
+ name: string,
56
+ events: WbEvent[],
57
+ listeners: Listener[],
58
+ pickedUp: (id: string) => boolean,
59
+ ): { state: FormState; last: WbEvent | undefined } {
60
+ const last = events.findLast(e => e.type === name && fromReader(e))
61
+ const askedAgain = listeners.some(l => !l.fallback && l.type === name)
62
+ const state: FormState =
63
+ !last ? 'open'
64
+ : !pickedUp(last.id) ? 'pending'
65
+ : askedAgain ? 'open'
66
+ : 'decided'
67
+ return { state, last }
68
+ }
69
+
70
+ /** Does a wait or watch take the answer to question `name`? Not: it is unheard. */
71
+ export const heard = (name: string, listeners: Listener[]): boolean =>
72
+ listeners.some(l => !l.fallback && (l.type === null || l.type === name))
73
+
74
+ /** The type of the event the page appends once messages were in view: `{ ids }`. */
75
+ export const READ = 'whiteboard:read'
76
+
77
+ /**
78
+ * The agent's messages on a page the reader hasn't read: events from the agent of a type
79
+ * `isMessage` says is for the reader, not named by a `whiteboard:read` from the reader, and not
80
+ * replaced by a later one (`replaces`).
81
+ */
82
+ export function unreadMessages(events: WbEvent[], isMessage: (type: string) => boolean): WbEvent[] {
83
+ const read = new Set<string>()
84
+ const replaced = new Set<string>()
85
+ for (const e of events) {
86
+ if (e.type === READ && fromReader(e)) for (const id of (e.data?.ids as unknown[] | undefined) ?? []) read.add(String(id))
87
+ if (e.data?.replaces) replaced.add(String(e.data.replaces))
88
+ }
89
+ return events.filter(e => !fromReader(e) && isMessage(e.type) && !read.has(e.id) && !replaced.has(e.id))
90
+ }
91
+
92
+ /** How many things on a page wait for the reader: its open questions and unread messages. */
93
+ export const awaiting = (p: Pick<PageStatus, 'open' | 'unread'>): number => p.open.length + p.unread.length
94
+
95
+ /**
96
+ * What is open on a page, one short line each; the command that picks it up comes last, once.
97
+ * `file` is how to name the page's file to the reader (relative to where they are). Without
98
+ * `waiting`, the questions an agent is already waiting on are left out.
99
+ */
100
+ export function statusLines(p: PageStatus, file: string, { waiting = true } = {}): string[] {
101
+ const lines: string[] = []
102
+ if (p.unpicked.length) lines.push(`${p.unpicked.length} answer${p.unpicked.length > 1 ? 's' : ''} no agent picked up (${[...new Set(p.unpicked.map(e => e.type))].join(', ')})`)
103
+ const fallback = p.listeners.some(l => l.fallback)
104
+ if (p.unheard.length) lines.push(fallback ? `no agent waits for ${p.unheard.join(', ')}; the fallback picks the answers up` : `nobody listens for ${p.unheard.join(', ')}`)
105
+ if (lines.length && !(fallback && !p.unpicked.length)) lines.push(`→ whiteboard wait --page ${file}`)
106
+ const listened = p.open.filter(t => !p.unheard.includes(t))
107
+ if (waiting && listened.length) lines.push(`waiting for the reader: ${listened.join(', ')}`)
108
+ return lines
109
+ }
110
+
111
+ /** Whose a page is, said to `session`: yours, another session's, or nobody's. */
112
+ export const whose = (p: PageStatus, session: string | null): string =>
113
+ p.owner && p.owner === session ? 'yours' : p.owner ? `session ${p.owner.slice(0, 8)}` : 'no session'