@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.
- package/README.md +31 -12
- package/bin/whiteboard.ts +74 -17
- package/dist/bin/whiteboard.js +93 -22
- package/dist/client/runtime.js +164 -11
- package/dist/plugins/chat/README.md +2 -1
- package/dist/plugins/chat/client.js +2 -2
- package/dist/plugins/chat/index.js +1 -0
- package/dist/plugins/chat/style.css +7 -0
- package/dist/plugins/code/diff.js +1 -0
- package/dist/plugins/comments/client.js +6 -6
- package/dist/plugins/comments/index.js +4 -1
- package/dist/plugins/comments/style.css +8 -0
- package/dist/plugins/forge/README.md +12 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/gallery/client.js +1 -1
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/client.js +1 -0
- package/dist/plugins/iframe/index.js +40 -0
- package/dist/plugins/iframe/style.css +29 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/mermaid/index.js +1 -0
- package/dist/solid/index.js +2 -1
- package/dist/src/client/page/base.css +33 -12
- package/dist/src/client/page/main.js +250 -26
- package/dist/src/events.js +24 -3
- package/dist/src/icons.js +6 -0
- package/dist/src/loader.js +12 -6
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +3 -2
- package/dist/src/pages/markdown.js +107 -4
- package/dist/src/pages/render.js +63 -9
- package/dist/src/server.js +37 -12
- package/dist/src/status.js +38 -10
- package/package.json +1 -1
- package/plugins/chat/README.md +2 -1
- package/plugins/chat/client.tsx +15 -3
- package/plugins/chat/index.ts +1 -1
- package/plugins/chat/style.css +7 -0
- package/plugins/code/diff.ts +7 -1
- package/plugins/comments/client.ts +50 -6
- package/plugins/comments/index.ts +4 -2
- package/plugins/comments/style.css +8 -0
- package/plugins/forge/README.md +12 -0
- package/plugins/forge/index.ts +71 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/client.ts +46 -0
- package/plugins/iframe/index.ts +54 -0
- package/plugins/iframe/style.css +29 -0
- package/plugins/index.ts +3 -1
- package/plugins/mermaid/index.ts +1 -0
- package/skills/whiteboard/SKILL.md +17 -7
- package/solid/index.tsx +3 -0
- package/src/client/forms.ts +5 -6
- package/src/client/markdown.ts +36 -0
- package/src/client/page/base.css +33 -12
- package/src/client/page/elsewhere.ts +70 -0
- package/src/client/page/live.ts +30 -0
- package/src/client/page/main.ts +31 -6
- package/src/client/page/sort.ts +38 -0
- package/src/client/page/waiting.ts +102 -29
- package/src/client/read.ts +73 -0
- package/src/client/runtime.ts +13 -0
- package/src/client/toast.ts +25 -0
- package/src/define.ts +79 -13
- package/src/events.ts +27 -3
- package/src/icons.ts +8 -0
- package/src/loader.ts +7 -4
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +8 -2
- package/src/pages/markdown.ts +92 -4
- package/src/pages/render.ts +49 -12
- package/src/server.ts +35 -12
- package/src/status.ts +64 -20
package/src/status.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
//
|
|
2
|
-
// (`whiteboard status`, the hooks
|
|
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
|
-
//
|
|
7
|
-
//
|
|
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[] = ['
|
|
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
|
|
33
|
-
* latest answer: the reader's
|
|
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
|
|
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
|
-
|
|
46
|
-
: !last ? '
|
|
47
|
-
:
|
|
48
|
-
: '
|
|
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
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|