@bigmistqke/workpad 0.18.1 → 0.20.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.
- package/README.md +18 -9
- package/bin/workpad.ts +412 -58
- package/dist/bin/workpad.js +336 -46
- package/dist/client/runtime.js +141 -18
- package/dist/plugins/badge/README.md +59 -10
- package/dist/plugins/badge/index.js +130 -8
- package/dist/plugins/badge/public/style.css +132 -12
- package/dist/plugins/chat/README.md +7 -3
- package/dist/plugins/chat/index.js +8 -1
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +10 -0
- package/dist/plugins/claude/README.md +13 -5
- package/dist/plugins/claude/channel.js +47 -6
- package/dist/plugins/claude/doctor.js +43 -47
- package/dist/plugins/claude/index.js +24 -8
- package/dist/plugins/claude/session.js +46 -1
- package/dist/plugins/comments/README.md +2 -1
- package/dist/plugins/comments/index.js +2 -0
- package/dist/plugins/comments/public/client.js +6 -5
- package/dist/plugins/comments/public/style.css +9 -0
- package/dist/plugins/form/README.md +1 -1
- package/dist/plugins/index.js +3 -1
- package/dist/plugins/opencode/channel.js +43 -7
- package/dist/plugins/opencode/index.js +2 -0
- package/dist/plugins/progress/README.md +41 -0
- package/dist/plugins/progress/index.js +117 -0
- package/dist/plugins/progress/public/client.js +1 -0
- package/dist/plugins/progress/public/style.css +85 -0
- package/dist/plugins/progress/state.js +210 -0
- package/dist/solid/index.js +3 -1
- package/dist/src/agents.js +13 -4
- package/dist/src/anchors.js +25 -1
- package/dist/src/build.js +1 -1
- package/dist/src/client/page/base.css +48 -2
- package/dist/src/client/page/main.js +58 -30
- package/dist/src/document.js +6 -4
- package/dist/src/events.js +22 -11
- package/dist/src/help.js +59 -12
- package/dist/src/hub.js +69 -3
- package/dist/src/listen.js +36 -4
- package/dist/src/listeners.js +14 -4
- package/dist/src/loader.js +7 -2
- package/dist/src/migrate.js +1 -1
- package/dist/src/pages/board.js +9 -4
- package/dist/src/pages/index.js +2 -4
- package/dist/src/pages/markdown.js +50 -19
- package/dist/src/pages/render.js +17 -1
- package/dist/src/server.js +94 -18
- package/dist/src/set.js +99 -0
- package/dist/src/state.js +2 -1
- package/dist/src/status.js +57 -9
- package/dist/src/turns.js +41 -0
- package/package.json +11 -1
- package/plugins/README.md +3 -1
- package/plugins/badge/README.md +59 -10
- package/plugins/badge/index.ts +141 -8
- package/plugins/badge/public/style.css +132 -12
- package/plugins/chat/README.md +7 -3
- package/plugins/chat/client.tsx +20 -3
- package/plugins/chat/index.ts +10 -1
- package/plugins/chat/public/style.css +10 -0
- package/plugins/claude/README.md +13 -5
- package/plugins/claude/channel.ts +45 -7
- package/plugins/claude/doctor.ts +58 -39
- package/plugins/claude/index.ts +30 -8
- package/plugins/claude/session.ts +32 -0
- package/plugins/comments/README.md +2 -1
- package/plugins/comments/client.ts +19 -0
- package/plugins/comments/index.ts +7 -1
- package/plugins/comments/public/style.css +9 -0
- package/plugins/form/README.md +1 -1
- package/plugins/index.ts +2 -0
- package/plugins/opencode/channel.ts +44 -8
- package/plugins/opencode/index.ts +4 -0
- package/plugins/progress/README.md +41 -0
- package/plugins/progress/client.ts +172 -0
- package/plugins/progress/index.ts +166 -0
- package/plugins/progress/public/style.css +85 -0
- package/plugins/progress/state.ts +278 -0
- package/skills/workpad/SKILL.md +149 -18
- package/solid/index.tsx +6 -2
- package/src/agents.ts +24 -2
- package/src/anchors.ts +32 -0
- package/src/build.ts +1 -1
- package/src/client/delivery.ts +49 -0
- package/src/client/forms.ts +18 -11
- package/src/client/page/base.css +48 -2
- package/src/client/page/waiting.ts +45 -25
- package/src/client/read.ts +9 -5
- package/src/client/runtime.ts +7 -3
- package/src/client/toast.ts +27 -3
- package/src/define.ts +120 -9
- package/src/document.ts +19 -5
- package/src/events.ts +47 -6
- package/src/help.ts +58 -11
- package/src/hub.ts +80 -2
- package/src/listen.ts +47 -4
- package/src/listeners.ts +22 -1
- package/src/loader.ts +14 -4
- package/src/migrate.ts +1 -1
- package/src/pages/board.ts +12 -3
- package/src/pages/index.ts +8 -10
- package/src/pages/markdown.ts +59 -12
- package/src/pages/render.ts +20 -2
- package/src/server.ts +127 -19
- package/src/set.ts +118 -0
- package/src/state.ts +3 -0
- package/src/status.ts +115 -14
- package/src/turns.ts +56 -0
package/src/hub.ts
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
// a listen over a whole entry, for as long as the connection is open: held on
|
|
20
20
|
// every page of its projects, also those that appear meanwhile; its stream is
|
|
21
21
|
// told the entry's projects (listeners.ts). Any number run
|
|
22
|
+
// /api/listen?unfollowed[&entry=<name>][&agent=<who>]
|
|
23
|
+
// a listen on the pages no one follows, across every project (or one entry's):
|
|
24
|
+
// held on each, and told them (`event: pages`) as they change (listeners.ts)
|
|
22
25
|
//
|
|
23
26
|
// A project's server is made when the project is found and closed when it goes, so a project
|
|
24
27
|
// appears and disappears without a restart. Each keeps its own state, config and log, as it would
|
|
@@ -35,6 +38,8 @@ import { API_LISTS, createServer, type ApiList, type WorkpadServer } from './ser
|
|
|
35
38
|
import type { LiveEvent } from './state.ts'
|
|
36
39
|
import type { IndexPage, IndexProject, Listener, PageStatus } from './define.ts'
|
|
37
40
|
import { holdStream, listenerOf } from './listeners.ts'
|
|
41
|
+
import { readEvents } from './events.ts'
|
|
42
|
+
import { isStale, running } from '../plugins/progress/state.ts'
|
|
38
43
|
|
|
39
44
|
export interface HubOptions {
|
|
40
45
|
/** the machine folder (its config.json), which the server only reads; default machineDir() */
|
|
@@ -89,6 +94,32 @@ export function createHub({
|
|
|
89
94
|
tell: () => void
|
|
90
95
|
}
|
|
91
96
|
const entryListens = new Set<EntryListen>()
|
|
97
|
+
|
|
98
|
+
// the listens on the pages no one follows (`workpad listen --unfollowed`): each project holds
|
|
99
|
+
// one for it, and says which of its pages those are; its stream is told them all together
|
|
100
|
+
interface UnfollowedListen {
|
|
101
|
+
entry: string | null
|
|
102
|
+
listener: Listener
|
|
103
|
+
held: Map<Served, () => void>
|
|
104
|
+
pages: Map<Served, string[]>
|
|
105
|
+
tell: () => void
|
|
106
|
+
}
|
|
107
|
+
const unfollowedListens = new Set<UnfollowedListen>()
|
|
108
|
+
function takeOn(s: Served, ul: UnfollowedListen) {
|
|
109
|
+
if (ul.held.has(s) || (ul.entry && s.entry !== ul.entry)) return
|
|
110
|
+
ul.held.set(
|
|
111
|
+
s,
|
|
112
|
+
s.server.unfollowed(ul.listener, pages => {
|
|
113
|
+
ul.pages.set(s, pages)
|
|
114
|
+
ul.tell()
|
|
115
|
+
}),
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
function letGo(s: Served, ul: UnfollowedListen) {
|
|
119
|
+
ul.held.get(s)?.()
|
|
120
|
+
ul.held.delete(s)
|
|
121
|
+
if (ul.pages.delete(s)) ul.tell()
|
|
122
|
+
}
|
|
92
123
|
/** An entry listen held on one of its projects, so the project's pages say it listens. */
|
|
93
124
|
function hold(s: Served, el: EntryListen) {
|
|
94
125
|
if (!el.held.has(s)) el.held.set(s, s.server.addListener(el.listener))
|
|
@@ -124,6 +155,7 @@ export function createHub({
|
|
|
124
155
|
for (const [key, s] of served)
|
|
125
156
|
if (!wanted.has(key)) {
|
|
126
157
|
for (const el of entryListens) release(s, el)
|
|
158
|
+
for (const ul of unfollowedListens) letGo(s, ul)
|
|
127
159
|
s.server.close()
|
|
128
160
|
served.delete(key)
|
|
129
161
|
console.log(`workpad: ${s.base} is gone (${s.dir})`)
|
|
@@ -143,6 +175,7 @@ export function createHub({
|
|
|
143
175
|
const s: Served = { ...p, project, server }
|
|
144
176
|
served.set(key, s)
|
|
145
177
|
for (const el of entryListens) if (el.entry === p.entry) hold(s, el)
|
|
178
|
+
for (const ul of unfollowedListens) takeOn(s, ul)
|
|
146
179
|
console.log(`workpad: ${p.base} → ${p.dir}`)
|
|
147
180
|
}
|
|
148
181
|
// an entry listen follows its projects coming and going
|
|
@@ -225,18 +258,26 @@ export function createHub({
|
|
|
225
258
|
} catch (err) {
|
|
226
259
|
return { ...at, pages: [], active: 0, error: (err as Error).message }
|
|
227
260
|
}
|
|
261
|
+
// each page's running progress, the one moved last (plugins/progress): its line on the card
|
|
262
|
+
const now = Date.now()
|
|
263
|
+
const runs = new Map<string, IndexPage['progress']>()
|
|
264
|
+
for (const r of running(readEvents(s.project.eventsFile)))
|
|
265
|
+
if (!runs.has(r.page))
|
|
266
|
+
runs.set(r.page, { id: r.id, note: r.note, n: r.n, total: r.total, ts: r.ts, stale: isStale(r, now) })
|
|
228
267
|
const pages = statuses
|
|
229
268
|
.map((p): IndexPage => ({
|
|
230
269
|
page: p.page,
|
|
231
270
|
title: p.title,
|
|
232
271
|
url: `${s.base}/${p.page.split('/').map(encodeURIComponent).join('/')}`,
|
|
233
272
|
mtime: mtimeOf(p.file),
|
|
273
|
+
updated: Math.max(mtimeOf(p.file), p.updated ? Date.parse(p.updated) : 0),
|
|
234
274
|
open: p.open,
|
|
235
275
|
unread: p.unread.length,
|
|
236
276
|
unreceived: p.unreceived.length,
|
|
277
|
+
progress: runs.get(p.page) ?? null,
|
|
237
278
|
}))
|
|
238
|
-
.toSorted((a, b) => b.
|
|
239
|
-
return { ...at, pages, active: pages[0]?.
|
|
279
|
+
.toSorted((a, b) => b.updated - a.updated)
|
|
280
|
+
return { ...at, pages, active: pages[0]?.updated ?? 0 }
|
|
240
281
|
}
|
|
241
282
|
const index = () => Promise.all([...served.values()].map(indexOf))
|
|
242
283
|
|
|
@@ -292,6 +333,7 @@ export function createHub({
|
|
|
292
333
|
setImmediate(() => onShutdown?.())
|
|
293
334
|
return
|
|
294
335
|
}
|
|
336
|
+
if (p === '/api/listen' && url.searchParams.has('unfollowed')) return listenUnfollowed(req, res, url.searchParams)
|
|
295
337
|
if (p === '/api/listen' && url.searchParams.has('entry')) return listenEntry(req, res, url.searchParams)
|
|
296
338
|
// the API across every project: each project's list, put together
|
|
297
339
|
const what = /^\/api\/(\w+)$/.exec(p)?.[1]
|
|
@@ -380,6 +422,42 @@ export function createHub({
|
|
|
380
422
|
}
|
|
381
423
|
const closers = new Set<() => void>()
|
|
382
424
|
|
|
425
|
+
/**
|
|
426
|
+
* A listen on the pages no one follows (`workpad listen --unfollowed`), across every project or
|
|
427
|
+
* one entry's: each project holds it on those of its pages (WorkpadServer.unfollowed), and its
|
|
428
|
+
* stream is told them all, once for several changes.
|
|
429
|
+
*/
|
|
430
|
+
function listenUnfollowed(req: IncomingMessage, res: ServerResponse, q: URLSearchParams) {
|
|
431
|
+
let telling = false
|
|
432
|
+
const ul: UnfollowedListen = {
|
|
433
|
+
entry: q.get('entry'),
|
|
434
|
+
listener: listenerOf(q),
|
|
435
|
+
held: new Map(),
|
|
436
|
+
pages: new Map(),
|
|
437
|
+
tell: () => {
|
|
438
|
+
if (telling) return
|
|
439
|
+
telling = true
|
|
440
|
+
setImmediate(() => {
|
|
441
|
+
telling = false
|
|
442
|
+
const projects = [...ul.pages]
|
|
443
|
+
.filter(([, pages]) => pages.length)
|
|
444
|
+
.map(([s, pages]) => ({ dir: s.dir, base: s.base, pages }))
|
|
445
|
+
stream.send('pages', { projects })
|
|
446
|
+
})
|
|
447
|
+
},
|
|
448
|
+
}
|
|
449
|
+
const stream = holdStream(req, res, () => {
|
|
450
|
+
closers.delete(stream.end)
|
|
451
|
+
unfollowedListens.delete(ul)
|
|
452
|
+
for (const s of [...ul.held.keys()]) letGo(s, ul)
|
|
453
|
+
})
|
|
454
|
+
closers.add(stream.end)
|
|
455
|
+
unfollowedListens.add(ul)
|
|
456
|
+
for (const s of served.values()) takeOn(s, ul)
|
|
457
|
+
// told at once, also with no project to take on
|
|
458
|
+
ul.tell()
|
|
459
|
+
}
|
|
460
|
+
|
|
383
461
|
/** /api/stream across every project: as a project's, each event with its project. */
|
|
384
462
|
function streamAll(req: IncomingMessage, res: ServerResponse, query: Record<string, string>) {
|
|
385
463
|
res.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-store', connection: 'keep-alive' })
|
package/src/listen.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// and the listen hands out from each project's log.
|
|
6
6
|
import http from 'node:http'
|
|
7
7
|
import https from 'node:https'
|
|
8
|
-
import type { Followed, Snapshot } from './listeners.ts'
|
|
8
|
+
import type { Followed, Snapshot, Unfollowed } from './listeners.ts'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A held GET to the server, over http or https as its address says: a server reached at an https
|
|
@@ -22,6 +22,10 @@ export interface ListenOptions {
|
|
|
22
22
|
query: Record<string, string>
|
|
23
23
|
/** a listen over a whole entry: the projects it covers, at once and on every change */
|
|
24
24
|
onSnapshot?: (snapshot: Snapshot) => void
|
|
25
|
+
/** a listen on the unfollowed pages (`unfollowed` in the query): which they are, at once and on every change */
|
|
26
|
+
onPages?: (unfollowed: Unfollowed) => void
|
|
27
|
+
/** let go of the server, and don't connect again */
|
|
28
|
+
signal?: AbortSignal
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
/**
|
|
@@ -29,15 +33,22 @@ export interface ListenOptions {
|
|
|
29
33
|
* Resolves once the server holds it; with `orNone`, also after a first try that found no server
|
|
30
34
|
* running (a listen reads the log all the same, and registers once one appears).
|
|
31
35
|
*/
|
|
32
|
-
export function listen(
|
|
36
|
+
export function listen(
|
|
37
|
+
{ at, query, onSnapshot, onPages, signal }: ListenOptions,
|
|
38
|
+
{ orNone = false } = {},
|
|
39
|
+
): Promise<void> {
|
|
33
40
|
return new Promise(settled => {
|
|
41
|
+
let current: http.ClientRequest | null = null
|
|
42
|
+
signal?.addEventListener('abort', () => current?.destroy())
|
|
34
43
|
const connect = async () => {
|
|
44
|
+
if (signal?.aborted) return settled()
|
|
35
45
|
let base: string | null = null
|
|
36
46
|
try {
|
|
37
47
|
base = await at()
|
|
38
48
|
} catch {
|
|
39
49
|
/* none runs */
|
|
40
50
|
}
|
|
51
|
+
if (signal?.aborted) return settled()
|
|
41
52
|
if (!base) {
|
|
42
53
|
if (orNone) settled()
|
|
43
54
|
return setTimeout(connect, 2000).unref()
|
|
@@ -49,7 +60,7 @@ export function listen({ at, query, onSnapshot }: ListenOptions, { orNone = fals
|
|
|
49
60
|
setTimeout(connect, ms).unref()
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
|
-
const req = get(`${base}/api/listen?${new URLSearchParams(query)}`, res => {
|
|
63
|
+
const req = (current = get(`${base}/api/listen?${new URLSearchParams(query)}`, res => {
|
|
53
64
|
res.setEncoding('utf8')
|
|
54
65
|
settled()
|
|
55
66
|
// held: the connection alone does not keep the command running. Not before: until the
|
|
@@ -66,10 +77,11 @@ export function listen({ at, query, onSnapshot }: ListenOptions, { orNone = fals
|
|
|
66
77
|
const event = /^event: (.*)$/m.exec(block)?.[1]
|
|
67
78
|
const data = /^data: (.*)$/m.exec(block)?.[1]
|
|
68
79
|
if (event === 'projects' && data && onSnapshot) onSnapshot(JSON.parse(data) as Snapshot)
|
|
80
|
+
if (event === 'pages' && data && onPages) onPages(JSON.parse(data) as Unfollowed)
|
|
69
81
|
}
|
|
70
82
|
})
|
|
71
83
|
res.on('close', () => retry(1000))
|
|
72
|
-
})
|
|
84
|
+
}))
|
|
73
85
|
req.on('error', () => retry(2000))
|
|
74
86
|
}
|
|
75
87
|
void connect()
|
|
@@ -98,6 +110,37 @@ export function everyProject(start: (project: Followed, signal: AbortSignal) =>
|
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
|
|
113
|
+
/** A page of a project a listen on the unfollowed pages takes. */
|
|
114
|
+
export interface PageOf extends Followed {
|
|
115
|
+
page: string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A listen on the unfollowed pages: `start` is called once for each page as it joins, to hand out
|
|
120
|
+
* from its project's log; a page that drops out (someone follows it now) is stopped (`signal`).
|
|
121
|
+
* @returns what takes each list of pages the server sends
|
|
122
|
+
*/
|
|
123
|
+
export function everyPage(start: (page: PageOf, signal: AbortSignal) => void): (unfollowed: Unfollowed) => void {
|
|
124
|
+
const taken = new Map<string, AbortController>()
|
|
125
|
+
return ({ projects }) => {
|
|
126
|
+
const now = new Set<string>()
|
|
127
|
+
for (const p of projects)
|
|
128
|
+
for (const page of p.pages) {
|
|
129
|
+
const key = `${p.dir}\n${page}`
|
|
130
|
+
now.add(key)
|
|
131
|
+
if (taken.has(key)) continue
|
|
132
|
+
const stop = new AbortController()
|
|
133
|
+
taken.set(key, stop)
|
|
134
|
+
start({ dir: p.dir, base: p.base, page }, stop.signal)
|
|
135
|
+
}
|
|
136
|
+
for (const [key, stop] of taken)
|
|
137
|
+
if (!now.has(key)) {
|
|
138
|
+
stop.abort()
|
|
139
|
+
taken.delete(key)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
101
144
|
/** What a channel's line does with what the server sends it (`CommandContext.channel`). */
|
|
102
145
|
export interface ChannelHandlers {
|
|
103
146
|
/** `workpad agent ping` in the session: push the pong, with this code, into it */
|
package/src/listeners.ts
CHANGED
|
@@ -26,7 +26,9 @@ export function createRegistry(): Registry {
|
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
28
28
|
list: (page = null) =>
|
|
29
|
-
[...listeners]
|
|
29
|
+
[...listeners]
|
|
30
|
+
.filter(l => page == null || covers(l, page))
|
|
31
|
+
.map(({ page, type, agent, unfollowed }) => ({ page, type, agent, ...(unfollowed && { unfollowed }) })),
|
|
30
32
|
add(l) {
|
|
31
33
|
listeners.add(l)
|
|
32
34
|
changed()
|
|
@@ -59,8 +61,27 @@ export const listenerOf = (q: URLSearchParams): Listener => ({
|
|
|
59
61
|
page: q.get('page') || '',
|
|
60
62
|
type: q.get('type') || null,
|
|
61
63
|
agent: q.get('agent') || null,
|
|
64
|
+
...(q.has('unfollowed') && { unfollowed: true as const }),
|
|
62
65
|
})
|
|
63
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Does `l` follow `page`: is someone there to take whatever comes on it? A listener covering the
|
|
69
|
+
* page, for every type: a running listen on it (or above it, or on every page), and a confirmed
|
|
70
|
+
* channel, which holds one on each page of its session's. A listen for one form only (`--type`)
|
|
71
|
+
* leaves the rest to no one, and a listen on the unfollowed pages follows nothing itself. A
|
|
72
|
+
* subscriber listening nowhere (gone, between turns, or a channel never confirmed) is no listener.
|
|
73
|
+
*/
|
|
74
|
+
export const follows = (l: Listener, page: string): boolean => !l.unfollowed && !l.type && covers(l, page)
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What a listen on the unfollowed pages (`workpad listen --unfollowed`) is told (`event: pages`), at
|
|
78
|
+
* once and whenever it changes: per project, the pages no one follows now; a project with none is
|
|
79
|
+
* left out.
|
|
80
|
+
*/
|
|
81
|
+
export interface Unfollowed {
|
|
82
|
+
projects: (Followed & { pages: string[] })[]
|
|
83
|
+
}
|
|
84
|
+
|
|
64
85
|
/**
|
|
65
86
|
* Hold a /api/listen connection open as an event stream (with a ping, so nothing between closes it
|
|
66
87
|
* as idle). `send` writes an event on it; `onEnd` runs once, when the agent goes or `end` is called.
|
package/src/loader.ts
CHANGED
|
@@ -20,8 +20,13 @@ export interface LoadedConfig {
|
|
|
20
20
|
plugins: Plugin[]
|
|
21
21
|
/** the plugins' event types declared `handOut: true`: those that reach an agent unasked */
|
|
22
22
|
handedOut: Set<string>
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* the plugins' event types declared `forReader: true`: from the agent, a message for the reader;
|
|
25
|
+
* each with the `data` fields it requires
|
|
26
|
+
*/
|
|
27
|
+
forReader: Map<string, string[]>
|
|
28
|
+
/** the plugins' event types that require `data` fields (EventSpec.requires), with those fields */
|
|
29
|
+
requires: Map<string, string[]>
|
|
25
30
|
/** each plugin's public folder, by name: the one place its browser files are served from */
|
|
26
31
|
publicDirs: Map<string, string>
|
|
27
32
|
/** whether it serves the project's own files, and which (src/files.ts) */
|
|
@@ -50,6 +55,7 @@ export const BUILTIN_COMMANDS = new Set([
|
|
|
50
55
|
'release',
|
|
51
56
|
'url',
|
|
52
57
|
'anchors',
|
|
58
|
+
'set',
|
|
53
59
|
'docs',
|
|
54
60
|
'events',
|
|
55
61
|
'listen',
|
|
@@ -178,11 +184,14 @@ export function createConfigLoader(
|
|
|
178
184
|
.map(([type]) => type),
|
|
179
185
|
),
|
|
180
186
|
)
|
|
187
|
+
const specs = plugins.flatMap(p => Object.entries(p.events ?? {}))
|
|
188
|
+
const requires = new Map(specs.flatMap(([type, spec]) => (spec?.requires?.length ? [[type, spec.requires] as const] : [])))
|
|
181
189
|
return {
|
|
182
190
|
pages,
|
|
183
191
|
plugins,
|
|
184
192
|
handedOut: declared('handOut'),
|
|
185
|
-
forReader: declared('forReader'),
|
|
193
|
+
forReader: new Map([...declared('forReader')].map(type => [type, requires.get(type) ?? []])),
|
|
194
|
+
requires,
|
|
186
195
|
publicDirs,
|
|
187
196
|
files: config?.files == null ? filesDefault : config.files !== false,
|
|
188
197
|
fileFilter: fileFilter(config?.files),
|
|
@@ -204,7 +213,8 @@ export function createConfigLoader(
|
|
|
204
213
|
pages: null,
|
|
205
214
|
plugins: [],
|
|
206
215
|
handedOut: new Set<string>(),
|
|
207
|
-
forReader: new
|
|
216
|
+
forReader: new Map<string, string[]>(),
|
|
217
|
+
requires: new Map<string, string[]>(),
|
|
208
218
|
publicDirs: new Map<string, string>(),
|
|
209
219
|
files: false,
|
|
210
220
|
fileFilter: fileFilter(),
|
package/src/migrate.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface Edit {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** `source` with the edits made (they don't overlap). */
|
|
40
|
-
function edit(source: string, edits: Edit[]): string {
|
|
40
|
+
export function edit(source: string, edits: Edit[]): string {
|
|
41
41
|
let out = source
|
|
42
42
|
for (const e of [...edits].sort((a, b) => b.from - a.from)) out = out.slice(0, e.from) + e.text + out.slice(e.to)
|
|
43
43
|
return out
|
package/src/pages/board.ts
CHANGED
|
@@ -23,6 +23,13 @@ export const waitingOn = (p: IndexPage): Waiting => ({
|
|
|
23
23
|
|
|
24
24
|
export const total = (w: Waiting): number => w.open + w.unread + w.unreceived
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* How much a card needs the reader: something waiting on it first, then the newest update (its file,
|
|
28
|
+
* or an agent's message or question on it) first.
|
|
29
|
+
*/
|
|
30
|
+
export const byAttention = (a: Card, b: Card): number =>
|
|
31
|
+
Number(total(b.waiting) > 0) - Number(total(a.waiting) > 0) || b.page.updated - a.page.updated
|
|
32
|
+
|
|
26
33
|
/** A page on the board, with the project it is in. */
|
|
27
34
|
export interface Card<P extends IndexProject = IndexProject> {
|
|
28
35
|
page: IndexPage
|
|
@@ -48,10 +55,12 @@ export function byState<P extends IndexProject>(
|
|
|
48
55
|
for (const project of projects)
|
|
49
56
|
for (const page of project.pages) {
|
|
50
57
|
const card = { page, project, waiting: waitingOn(page) }
|
|
51
|
-
|
|
58
|
+
// a page with work running on it is active, however long ago it last changed
|
|
59
|
+
const column =
|
|
60
|
+
total(card.waiting) > 0 ? 'waiting' : page.progress || now - page.updated <= activeFor ? 'active' : 'quiet'
|
|
52
61
|
columns[column].push(card)
|
|
53
62
|
}
|
|
54
|
-
for (const cards of [columns.waiting, columns.active, columns.quiet]) cards.sort(
|
|
63
|
+
for (const cards of [columns.waiting, columns.active, columns.quiet]) cards.sort(byAttention)
|
|
55
64
|
return columns
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -70,7 +79,7 @@ export function byProject<P extends IndexProject>(projects: readonly P[]): Proje
|
|
|
70
79
|
.map(project => {
|
|
71
80
|
const cards = project.pages
|
|
72
81
|
.map(page => ({ page, project, waiting: waitingOn(page) }))
|
|
73
|
-
.sort(
|
|
82
|
+
.sort(byAttention)
|
|
74
83
|
const waiting = cards.reduce(
|
|
75
84
|
(sum, c) => ({
|
|
76
85
|
open: sum.open + c.waiting.open,
|
package/src/pages/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// loaded config (see loader.ts); the server renders with it.
|
|
4
4
|
import { resolveBlocks, type BlockEntry } from './blocks.ts'
|
|
5
5
|
import { createAgentMessageRender, createBlocksRender, createDocs, createMessageRender, createRender } from './render.ts'
|
|
6
|
-
import {
|
|
6
|
+
import { pageAsks, type Island, type PageAsks } from './markdown.ts'
|
|
7
7
|
import type { PageSource, RenderContext, Rendered, StoredPage } from '../define.ts'
|
|
8
8
|
import type { Plugin, TextLink } from '../define.ts'
|
|
9
9
|
|
|
@@ -28,12 +28,12 @@ export interface Pages {
|
|
|
28
28
|
render(page: StoredPage, ctx: RenderContext): Promise<Rendered>
|
|
29
29
|
/** how pages are written, and which blocks the plugins bring: what `workpad docs` prints first */
|
|
30
30
|
docs(ctx: RenderContext): string
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
/**
|
|
32
|
+
* What a page asks, with what the plugins add at its end: its questions (its named forms, whose
|
|
33
|
+
* answers are events of their name), its chats (one under every form, and the chat blocks) and
|
|
34
|
+
* what each of its `:::form`s asks (its question, options and buttons). One parse for all three.
|
|
35
|
+
*/
|
|
36
|
+
asks(page: PageSource): PageAsks
|
|
37
37
|
/** a message's markdown (a comment, a chat message) as HTML, and the stylesheets it needs */
|
|
38
38
|
message(text: string, ctx: RenderContext): Promise<{ html: string; styles: string[] }>
|
|
39
39
|
/**
|
|
@@ -72,8 +72,6 @@ export function createPages(options: PagesOptions): Pages {
|
|
|
72
72
|
agentMessage: createAgentMessageRender(blocks, options.links ?? [], options.composers),
|
|
73
73
|
blocks: createBlocksRender(blocks, options.links ?? [], options.composers),
|
|
74
74
|
docs: createDocs(blocks),
|
|
75
|
-
|
|
76
|
-
chats: page => chatNames(ended(page).body),
|
|
77
|
-
forms: page => formDetails(ended(page).body),
|
|
75
|
+
asks: page => pageAsks(ended(page).body),
|
|
78
76
|
}
|
|
79
77
|
}
|
package/src/pages/markdown.ts
CHANGED
|
@@ -14,7 +14,7 @@ import remarkRehype from 'remark-rehype'
|
|
|
14
14
|
import rehypeStringify from 'rehype-stringify'
|
|
15
15
|
import { toString } from 'mdast-util-to-string'
|
|
16
16
|
import { html, raw, type Html } from '../html.ts'
|
|
17
|
-
import { anchorsOf, slugText } from '../anchors.ts'
|
|
17
|
+
import { anchorsOf, nearest, slugText } from '../anchors.ts'
|
|
18
18
|
import { agentMessagesIn, isQuestionName } from '../status.ts'
|
|
19
19
|
import type { ResolvedBlock } from './blocks.ts'
|
|
20
20
|
import type { Plugin, TextLink, WpEvent } from '../define.ts'
|
|
@@ -316,7 +316,11 @@ export function titleWords(nodes: MdNode[], resolve: (name: string) => unknown):
|
|
|
316
316
|
* code block doesn't count.
|
|
317
317
|
*/
|
|
318
318
|
export function formNames(source: string) {
|
|
319
|
-
|
|
319
|
+
return formNamesIn(parseMarkdown(String(source ?? '')))
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** formNames of a source parsed already. */
|
|
323
|
+
function formNamesIn(tree: MdNode) {
|
|
320
324
|
const names: string[] = []
|
|
321
325
|
const walk = (node: MdNode) => {
|
|
322
326
|
if (node.type === 'containerDirective' && node.name === 'form') {
|
|
@@ -338,10 +342,10 @@ export function formNames(source: string) {
|
|
|
338
342
|
|
|
339
343
|
/**
|
|
340
344
|
* The `:::form`s in a source by the name they are written with, null for one without; in order, and
|
|
341
|
-
* not those shown in a code fence. For a message's forms, which are named in their chat.
|
|
345
|
+
* not those shown in a code fence. For a message's forms, which are named in their chat. Kept: a
|
|
346
|
+
* status asks it of every agent message in every chat, and a message's text never changes.
|
|
342
347
|
*/
|
|
343
|
-
export
|
|
344
|
-
const text = String(source ?? '')
|
|
348
|
+
export const formsIn = byText(5000, (text): readonly { readonly name: string | null; readonly markdown: string }[] => {
|
|
345
349
|
const out: { name: string | null; markdown: string }[] = []
|
|
346
350
|
const walk = (node: MdNode) => {
|
|
347
351
|
if (node.type === 'containerDirective' && node.name === 'form') {
|
|
@@ -356,7 +360,7 @@ export function formsIn(source: string): { name: string | null; markdown: string
|
|
|
356
360
|
}
|
|
357
361
|
walk(parseMarkdown(text))
|
|
358
362
|
return out
|
|
359
|
-
}
|
|
363
|
+
})
|
|
360
364
|
|
|
361
365
|
/** One option of a form's question, as written: `:radio[Label]{name=field value=… recommended other}`. */
|
|
362
366
|
export interface FormOption {
|
|
@@ -429,15 +433,53 @@ function describeForm(node: MdNode): FormDetail {
|
|
|
429
433
|
|
|
430
434
|
/** What each `:::form` in a source asks, in order (not those shown in a code fence). */
|
|
431
435
|
export function formDetails(source: string): FormDetail[] {
|
|
436
|
+
return formDetailsIn(parseMarkdown(String(source ?? '')))
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** formDetails of a source parsed already. */
|
|
440
|
+
function formDetailsIn(tree: MdNode): FormDetail[] {
|
|
432
441
|
const out: FormDetail[] = []
|
|
433
442
|
const walk = (node: MdNode) => {
|
|
434
443
|
if (node.type === 'containerDirective' && node.name === 'form') out.push(describeForm(node))
|
|
435
444
|
for (const child of node.children ?? []) walk(child)
|
|
436
445
|
}
|
|
437
|
-
walk(
|
|
446
|
+
walk(tree)
|
|
438
447
|
return out
|
|
439
448
|
}
|
|
440
449
|
|
|
450
|
+
/** What a page asks: its questions (formNames), its chats (chatNames), what each form asks (formDetails). */
|
|
451
|
+
export interface PageAsks {
|
|
452
|
+
questions: string[]
|
|
453
|
+
chats: string[]
|
|
454
|
+
forms: FormDetail[]
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* A page's questions, chats and forms, from one parse of its source. The same source is asked again
|
|
459
|
+
* after the config reloads, which a change to a plugin does: its answer is kept.
|
|
460
|
+
*/
|
|
461
|
+
export const pageAsks = byText(1000, (source): Readonly<PageAsks> => {
|
|
462
|
+
const tree = parseMarkdown(source)
|
|
463
|
+
return { questions: formNamesIn(tree), chats: chatNamesIn(tree), forms: formDetailsIn(tree) }
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* `fn` with its answers kept by the text it was asked about, the oldest dropped past `limit`: for
|
|
468
|
+
* what is read from a parse, asked again and again of the same pages and messages. What it answers
|
|
469
|
+
* is shared, never to be changed.
|
|
470
|
+
*/
|
|
471
|
+
function byText<T>(limit: number, fn: (text: string) => T): (source: string) => T {
|
|
472
|
+
const kept = new Map<string, T>()
|
|
473
|
+
return source => {
|
|
474
|
+
const text = String(source ?? '')
|
|
475
|
+
if (kept.has(text)) return kept.get(text)!
|
|
476
|
+
const value = fn(text)
|
|
477
|
+
if (kept.size >= limit) kept.delete(kept.keys().next().value!)
|
|
478
|
+
kept.set(text, value)
|
|
479
|
+
return value
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
441
483
|
/**
|
|
442
484
|
* The forms in the agent's messages in `chats` (a page's chats, chatNames), by their names there:
|
|
443
485
|
* `<chat>/<name>`, an unnamed one numbered in its chat (Api.message). They are questions of the
|
|
@@ -473,8 +515,12 @@ export function chatForms(
|
|
|
473
515
|
* on the page.
|
|
474
516
|
*/
|
|
475
517
|
export function chatNames(source: string) {
|
|
476
|
-
|
|
477
|
-
|
|
518
|
+
return chatNamesIn(parseMarkdown(String(source ?? '')))
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** chatNames of a source parsed already. */
|
|
522
|
+
function chatNamesIn(tree: MdNode) {
|
|
523
|
+
const names: string[] = formNamesIn(tree)
|
|
478
524
|
// a form without its chat (`chat=false`): no chat of that name
|
|
479
525
|
const without = new Set<string>()
|
|
480
526
|
const walk = (node: MdNode) => {
|
|
@@ -808,6 +854,7 @@ plugin "${name}" failed to compose around block "${block.name}": ${(err as Error
|
|
|
808
854
|
fileUrl,
|
|
809
855
|
anchor,
|
|
810
856
|
chat: inChat,
|
|
857
|
+
problem,
|
|
811
858
|
}
|
|
812
859
|
|
|
813
860
|
/**
|
|
@@ -958,7 +1005,7 @@ plugin "${name}" failed to compose around block "${block.name}": ${(err as Error
|
|
|
958
1005
|
const out = stringify(tree.children ?? [])
|
|
959
1006
|
// a link to a place on this page that isn't there; a chat message's (#message:) are drawn later
|
|
960
1007
|
if (links.length) {
|
|
961
|
-
const ids =
|
|
1008
|
+
const ids = anchorsOf(String(out)).map(a => a.id)
|
|
962
1009
|
for (const url of links) {
|
|
963
1010
|
let id = url.slice(1)
|
|
964
1011
|
try {
|
|
@@ -966,8 +1013,8 @@ plugin "${name}" failed to compose around block "${block.name}": ${(err as Error
|
|
|
966
1013
|
} catch {
|
|
967
1014
|
/* as written */
|
|
968
1015
|
}
|
|
969
|
-
if (id && !id.startsWith('message:') && !ids.
|
|
970
|
-
problem(`a link to \`${url}\`, which this page doesn't have
|
|
1016
|
+
if (id && !id.startsWith('message:') && !ids.includes(id))
|
|
1017
|
+
problem(`a link to \`${url}\`, which this page doesn't have${nearest(id, ids)}`)
|
|
971
1018
|
}
|
|
972
1019
|
}
|
|
973
1020
|
// blocks of one plugin can share a stylesheet (the form and its fields): linked once
|
package/src/pages/render.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { promisify } from 'node:util'
|
|
|
13
13
|
import { renderMarkdown, type Island, type MdNode } from './markdown.ts'
|
|
14
14
|
import { html, raw, type Html } from '../html.ts'
|
|
15
15
|
import { INBOX_ICON, awaitingLabel } from '../icons.ts'
|
|
16
|
-
import type { BlockGroup, Plugin, RenderContext, Rendered, StoredPage, TextLink } from '../define.ts'
|
|
16
|
+
import type { BlockGroup, IndexPage, Plugin, RenderContext, Rendered, StoredPage, TextLink } from '../define.ts'
|
|
17
17
|
import type { ResolvedBlock, ResolvedBlocks } from './blocks.ts'
|
|
18
18
|
import { ACTIVE_FOR, byProject, byState, total, withoutPages, type Card, type ProjectColumn, type Waiting } from './board.ts'
|
|
19
19
|
|
|
@@ -412,13 +412,31 @@ function counts(w: Waiting, href: string | null) {
|
|
|
412
412
|
>`
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
/** A page's running progress on its card: a small bar (or a dot, without a count), its id, count and note. */
|
|
416
|
+
function progressLine(p: NonNullable<IndexPage['progress']>) {
|
|
417
|
+
const count =
|
|
418
|
+
p.n != null && p.total != null ? `${p.n.toLocaleString('en-US')} / ${p.total.toLocaleString('en-US')}` : ''
|
|
419
|
+
const width = p.n != null && p.total ? `${Math.round((p.n / p.total) * 1000) / 10}%` : null
|
|
420
|
+
return html`<span
|
|
421
|
+
class="wp-board-progress"
|
|
422
|
+
${p.stale ? html` data-stale` : ''}
|
|
423
|
+
title="${p.id}: running${p.stale ? ', no update for a while' : ''}"
|
|
424
|
+
>${
|
|
425
|
+
width != null
|
|
426
|
+
? html`<span class="wp-board-progress-bar"><span style="width:${width}"></span></span>`
|
|
427
|
+
: html`<span class="wp-board-progress-dot"></span>`
|
|
428
|
+
}<span class="wp-board-progress-text">${[p.id, count, p.note].filter(Boolean).join(' · ')}</span></span
|
|
429
|
+
>`
|
|
430
|
+
}
|
|
431
|
+
|
|
415
432
|
/** A page on the board: its title, what waits on it, and (in a column of states) its project. */
|
|
416
433
|
function card(c: Card<BoardProject>, withProject: boolean) {
|
|
417
434
|
return html`<li class="wp-board-card${total(c.waiting) > 0 ? ' wp-board-waits' : ''}">
|
|
418
435
|
<a class="wp-board-title" href="${c.page.url}">${c.page.title}</a>
|
|
419
436
|
${counts(c.waiting, `${c.page.url}#wp-waiting`)}
|
|
420
437
|
${withProject && html`<span class="wp-board-project">${c.project.label}</span>`}
|
|
421
|
-
|
|
438
|
+
${c.page.progress && progressLine(c.page.progress)}
|
|
439
|
+
<span class="wp-meta wp-board-when">updated ${time(c.page.updated)}</span>
|
|
422
440
|
</li>`
|
|
423
441
|
}
|
|
424
442
|
|