@bigmistqke/whiteboard 0.1.0 → 0.2.1

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 (73) hide show
  1. package/README.md +31 -12
  2. package/bin/whiteboard.ts +74 -17
  3. package/dist/bin/whiteboard.js +93 -22
  4. package/dist/client/runtime.js +164 -11
  5. package/dist/plugins/chat/README.md +2 -1
  6. package/dist/plugins/chat/client.js +2 -2
  7. package/dist/plugins/chat/index.js +1 -0
  8. package/dist/plugins/chat/style.css +7 -0
  9. package/dist/plugins/code/diff.js +1 -0
  10. package/dist/plugins/comments/client.js +6 -6
  11. package/dist/plugins/comments/index.js +4 -1
  12. package/dist/plugins/comments/style.css +8 -0
  13. package/dist/plugins/forge/README.md +12 -0
  14. package/dist/plugins/forge/index.js +83 -0
  15. package/dist/plugins/gallery/client.js +1 -1
  16. package/dist/plugins/iframe/README.md +18 -0
  17. package/dist/plugins/iframe/client.js +1 -0
  18. package/dist/plugins/iframe/index.js +40 -0
  19. package/dist/plugins/iframe/style.css +29 -0
  20. package/dist/plugins/index.js +4 -0
  21. package/dist/plugins/mermaid/index.js +1 -0
  22. package/dist/solid/index.js +2 -1
  23. package/dist/src/client/page/base.css +33 -12
  24. package/dist/src/client/page/main.js +250 -26
  25. package/dist/src/events.js +24 -3
  26. package/dist/src/icons.js +6 -0
  27. package/dist/src/loader.js +12 -6
  28. package/dist/src/pages/blocks.js +1 -0
  29. package/dist/src/pages/index.js +3 -2
  30. package/dist/src/pages/markdown.js +107 -4
  31. package/dist/src/pages/render.js +63 -9
  32. package/dist/src/server.js +37 -12
  33. package/dist/src/status.js +38 -10
  34. package/package.json +1 -1
  35. package/plugins/chat/README.md +2 -1
  36. package/plugins/chat/client.tsx +15 -3
  37. package/plugins/chat/index.ts +1 -1
  38. package/plugins/chat/style.css +7 -0
  39. package/plugins/code/diff.ts +7 -1
  40. package/plugins/comments/client.ts +50 -6
  41. package/plugins/comments/index.ts +4 -2
  42. package/plugins/comments/style.css +8 -0
  43. package/plugins/forge/README.md +12 -0
  44. package/plugins/forge/index.ts +71 -0
  45. package/plugins/iframe/README.md +18 -0
  46. package/plugins/iframe/client.ts +46 -0
  47. package/plugins/iframe/index.ts +54 -0
  48. package/plugins/iframe/style.css +29 -0
  49. package/plugins/index.ts +3 -1
  50. package/plugins/mermaid/index.ts +1 -0
  51. package/skills/whiteboard/SKILL.md +17 -7
  52. package/solid/index.tsx +3 -0
  53. package/src/client/forms.ts +5 -6
  54. package/src/client/markdown.ts +36 -0
  55. package/src/client/page/base.css +33 -12
  56. package/src/client/page/elsewhere.ts +70 -0
  57. package/src/client/page/live.ts +30 -0
  58. package/src/client/page/main.ts +31 -6
  59. package/src/client/page/sort.ts +38 -0
  60. package/src/client/page/waiting.ts +102 -29
  61. package/src/client/read.ts +73 -0
  62. package/src/client/runtime.ts +13 -0
  63. package/src/client/toast.ts +25 -0
  64. package/src/define.ts +79 -13
  65. package/src/events.ts +27 -3
  66. package/src/icons.ts +8 -0
  67. package/src/loader.ts +7 -4
  68. package/src/pages/blocks.ts +3 -0
  69. package/src/pages/index.ts +8 -2
  70. package/src/pages/markdown.ts +92 -4
  71. package/src/pages/render.ts +49 -12
  72. package/src/server.ts +35 -12
  73. package/src/status.ts +64 -20
package/src/status.ts CHANGED
@@ -1,14 +1,22 @@
1
- // Where a page's questions stand, and how to say what is open on it: one definition for the server
2
- // (`whiteboard status`, the hooks) and the page in the browser alike. No Node in it, so the browser
3
- // runtime uses the same module.
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.
4
7
  //
5
8
  // A question is a named form; its answers are the reader's events of its name. It stands:
6
- // waiting an agent is listening and wants its answer: a wait or watch asks for it by name (also
7
- // when it was answered before: the agent wants a new answer), or takes any answer and
8
- // it has none
9
- // unheard no answer, and no agent is listening
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
10
11
  // pending answered, but no agent has picked the answer up yet
11
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.
12
20
  import type { FormState, Listener, PageStatus, WbEvent } from './define.ts'
13
21
 
14
22
  /**
@@ -19,7 +27,7 @@ import type { FormState, Listener, PageStatus, WbEvent } from './define.ts'
19
27
  export const isQuestionName = (name: string): boolean => !!name && !name.includes(':')
20
28
 
21
29
  /** The states, in the order a reader should see them: what waits on them first. */
22
- export const STATES: FormState[] = ['waiting', 'unheard', 'pending', 'decided']
30
+ export const STATES: FormState[] = ['open', 'pending', 'decided']
23
31
 
24
32
  /**
25
33
  * Was this event written by the reader (a form submit, a comment), not by an agent? Agents write
@@ -27,10 +35,21 @@ export const STATES: FormState[] = ['waiting', 'unheard', 'pending', 'decided']
27
35
  */
28
36
  export const fromReader = (event: WbEvent): boolean => event.from !== 'cli'
29
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
+
30
48
  /**
31
49
  * Where the question `name` stands. `events` are the page's, `listeners` the running waits and
32
- * watches that cover the page, `pickedUp` whether an event was handed to an agent. `last` is its
33
- * latest answer: the reader's latest event of its name.
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.
34
53
  */
35
54
  export function questionState(
36
55
  name: string,
@@ -39,16 +58,40 @@ export function questionState(
39
58
  pickedUp: (id: string) => boolean,
40
59
  ): { state: FormState; last: WbEvent | undefined } {
41
60
  const last = events.findLast(e => e.type === name && fromReader(e))
42
- const asked = listeners.some(l => l.type === name)
43
- const any = listeners.some(l => l.type === null)
61
+ const askedAgain = listeners.some(l => !l.fallback && l.type === name)
44
62
  const state: FormState =
45
- asked || (any && !last) ? 'waiting'
46
- : !last ? 'unheard'
47
- : pickedUp(last.id) ? 'decided'
48
- : 'pending'
63
+ !last ? 'open'
64
+ : !pickedUp(last.id) ? 'pending'
65
+ : askedAgain ? 'open'
66
+ : 'decided'
49
67
  return { state, last }
50
68
  }
51
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
+
52
95
  /**
53
96
  * What is open on a page, one short line each; the command that picks it up comes last, once.
54
97
  * `file` is how to name the page's file to the reader (relative to where they are). Without
@@ -57,10 +100,11 @@ export function questionState(
57
100
  export function statusLines(p: PageStatus, file: string, { waiting = true } = {}): string[] {
58
101
  const lines: string[] = []
59
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(', ')})`)
60
- if (p.unheard.length) lines.push(`nobody listens for ${p.unheard.join(', ')}`)
61
- if (lines.length) lines.push(`→ whiteboard wait --page ${file}`)
62
- const heard = p.open.filter(t => !p.unheard.includes(t))
63
- if (waiting && heard.length) lines.push(`waiting for the reader: ${heard.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(', ')}`)
64
108
  return lines
65
109
  }
66
110