@bigmistqke/workpad 0.19.0 → 0.20.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 +29 -16
- package/bin/workpad.ts +193 -37
- package/dist/bin/workpad.js +161 -32
- package/dist/client/runtime.js +141 -18
- package/dist/plugins/chat/README.md +7 -3
- package/dist/plugins/chat/index.js +1 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +10 -0
- package/dist/plugins/claude/channel.js +22 -4
- package/dist/plugins/claude/doctor.js +15 -5
- 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 +1 -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 +7 -3
- 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/entries.js +6 -2
- package/dist/src/events.js +19 -9
- package/dist/src/files.js +26 -3
- package/dist/src/help.js +43 -8
- package/dist/src/hub.js +20 -4
- package/dist/src/loader.js +11 -6
- package/dist/src/migrate.js +1 -1
- package/dist/src/pages/board.js +1 -1
- package/dist/src/pages/markdown.js +3 -3
- package/dist/src/pages/render.js +16 -0
- package/dist/src/server.js +70 -32
- package/dist/src/set.js +99 -0
- package/dist/src/status.js +47 -8
- package/package.json +6 -1
- package/plugins/README.md +3 -1
- package/plugins/chat/README.md +7 -3
- package/plugins/chat/client.tsx +20 -3
- package/plugins/chat/index.ts +1 -0
- package/plugins/chat/public/style.css +10 -0
- package/plugins/claude/channel.ts +19 -5
- package/plugins/claude/doctor.ts +11 -3
- 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 +2 -1
- 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 +126 -15
- package/solid/index.tsx +6 -2
- package/src/agents.ts +17 -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 +92 -8
- package/src/document.ts +19 -5
- package/src/entries.ts +18 -7
- package/src/events.ts +26 -6
- package/src/files.ts +28 -2
- package/src/help.ts +42 -7
- package/src/hub.ts +25 -8
- package/src/loader.ts +20 -10
- package/src/migrate.ts +1 -1
- package/src/pages/board.ts +3 -1
- package/src/pages/markdown.ts +4 -4
- package/src/pages/render.ts +19 -1
- package/src/server.ts +114 -42
- package/src/set.ts +118 -0
- package/src/status.ts +100 -13
package/src/document.ts
CHANGED
|
@@ -43,8 +43,10 @@ export interface PageParts {
|
|
|
43
43
|
slots: { [K in Exclude<SlotName, 'header'>]: Slotted[] }
|
|
44
44
|
/** their browser modules, which the runtime imports after the page's */
|
|
45
45
|
clients: { name: string; client: string }[]
|
|
46
|
-
/** the event types that, from the agent, are messages for the reader (EventSpec.forReader) */
|
|
47
|
-
messages: string[]
|
|
46
|
+
/** the event types that, from the agent, are messages for the reader (EventSpec.forReader), each with the `data` fields it requires */
|
|
47
|
+
messages: Record<string, string[]>
|
|
48
|
+
/** the plugins' event types that, from the reader, go to an agent (EventSpec.handOut) */
|
|
49
|
+
handedOut: string[]
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -58,11 +60,14 @@ export async function pluginParts(
|
|
|
58
60
|
{
|
|
59
61
|
asset,
|
|
60
62
|
messages,
|
|
63
|
+
handedOut = [],
|
|
61
64
|
leaveOut = new Set(),
|
|
62
65
|
failed,
|
|
63
66
|
}: {
|
|
64
67
|
asset(ref: string | URL): string
|
|
65
|
-
messages: string[]
|
|
68
|
+
messages: Record<string, string[]>
|
|
69
|
+
/** none on a built page: nothing it sends goes anywhere */
|
|
70
|
+
handedOut?: string[]
|
|
66
71
|
leaveOut?: ReadonlySet<string>
|
|
67
72
|
failed(message: string): void
|
|
68
73
|
},
|
|
@@ -95,6 +100,7 @@ export async function pluginParts(
|
|
|
95
100
|
},
|
|
96
101
|
clients: working.filter(h => h.client).map(h => ({ name: h.name, client: asset(h.client!) })),
|
|
97
102
|
messages,
|
|
103
|
+
handedOut,
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
|
|
@@ -123,7 +129,14 @@ const DOCK_STYLE =
|
|
|
123
129
|
'.wp-toast-dismiss{margin-right:-4px;padding:0 4px;border-left:1px solid rgb(255 255 255/.35);opacity:.75}.wp-toast-dismiss:hover{opacity:1}' +
|
|
124
130
|
// a toast's details (ToastOptions.details): a ▸ on its line, unfolding them under it
|
|
125
131
|
'.wp-toast{max-width:min(24rem,calc(100vw - 32px));text-align:left}.wp-toast-more{margin:0 -4px 0 -2px;padding:0 4px;opacity:.75}.wp-toast-more:hover{opacity:1}' +
|
|
126
|
-
'.wp-toast[data-open]{flex-wrap:wrap;border-radius:12px}.wp-toast-details{flex-basis:100%;padding:2px 0 3px;font-weight:400;cursor:text}.wp-toast-details[hidden]{display:none}'
|
|
132
|
+
'.wp-toast[data-open]{flex-wrap:wrap;border-radius:12px}.wp-toast-details{flex-basis:100%;padding:2px 0 3px;font-weight:400;cursor:text}.wp-toast-details[hidden]{display:none}' +
|
|
133
|
+
// a quiet toast (kind quiet): a card in the page's colours, its time at the right, a thin bar under
|
|
134
|
+
'.wp-toast[data-kind=quiet]{display:grid;grid-template-columns:1fr auto;align-items:baseline;gap:4px 12px;width:230px;max-width:calc(100vw - 32px);padding:8px 12px 9px;border-radius:10px;background:var(--surface,#fff);color:var(--text,#1b1c1e);border:1px solid var(--border,#e3e5e9);box-shadow:0 4px 16px rgb(0 0 0/.14);font-weight:500}' +
|
|
135
|
+
'.wp-toast-meta{color:var(--muted,#696e76);font-weight:400;white-space:nowrap;text-align:right}.wp-toast[data-kind=quiet]:not(:has(.wp-toast-meta)) .wp-toast-text{grid-column:1/-1}' +
|
|
136
|
+
'.wp-toast-bar{grid-column:1/-1;position:relative;height:3px;margin-top:3px;border-radius:2px;overflow:hidden;background:color-mix(in srgb,var(--muted,#696e76) 28%,transparent)}' +
|
|
137
|
+
'.wp-toast-bar span{position:absolute;inset:0 auto 0 0;width:var(--wp-toast-bar,0%);border-radius:inherit;background:var(--accent,#1d5bbf)}.wp-toast-bar[data-tone=good] span{background:var(--ok,#1a7a49)}.wp-toast-bar[data-tone=bad] span{background:var(--bad,#c4352b)}' +
|
|
138
|
+
'@keyframes wp-toast-stripe{from{left:-30%}to{left:100%}}.wp-toast-bar[data-indeterminate] span{width:30%;animation:wp-toast-stripe 1.6s ease-in-out infinite}' +
|
|
139
|
+
'@media (prefers-reduced-motion:reduce){.wp-toast-bar[data-indeterminate] span{animation:none;left:0;width:100%;opacity:.5}}'
|
|
127
140
|
|
|
128
141
|
/** How a page is put out: by the server (live) or by a build (a file with no server behind it). */
|
|
129
142
|
export interface Output {
|
|
@@ -161,6 +174,7 @@ export function pageDocument(
|
|
|
161
174
|
frontmatter: frontmatterOf(page),
|
|
162
175
|
plugins: parts.clients,
|
|
163
176
|
messages: parts.messages,
|
|
177
|
+
handedOut: parts.handedOut,
|
|
164
178
|
...(o.stamps && { stamps: o.stamps }),
|
|
165
179
|
}
|
|
166
180
|
// the page's head and html are HTML already; the handoff is JSON made safe for a script tag
|
|
@@ -172,7 +186,7 @@ export function pageDocument(
|
|
|
172
186
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
173
187
|
<title>${out.title || page.id || o.title}</title>
|
|
174
188
|
<style>
|
|
175
|
-
${DOCK_STYLE}
|
|
189
|
+
${raw(DOCK_STYLE)}
|
|
176
190
|
</style>
|
|
177
191
|
${raw(String(out.head ?? ''))}${parts.head}
|
|
178
192
|
</head>
|
package/src/entries.ts
CHANGED
|
@@ -14,16 +14,18 @@
|
|
|
14
14
|
import fs from 'node:fs'
|
|
15
15
|
import os from 'node:os'
|
|
16
16
|
import path from 'node:path'
|
|
17
|
+
import type { FilesConfig } from './files.ts'
|
|
17
18
|
|
|
18
19
|
/** One entry of the machine config: which folders are its projects. */
|
|
19
20
|
export interface EntryConfig {
|
|
20
21
|
include: string[]
|
|
21
22
|
exclude?: string[]
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
* false
|
|
24
|
+
* which of their own files its projects serve and watch, when a project's config doesn't say, as
|
|
25
|
+
* a project's config has it: false none (only `.workpad/` is watched), `{ include, exclude }`
|
|
26
|
+
* some (default: true, all but node_modules and .git)
|
|
25
27
|
*/
|
|
26
|
-
files?: boolean
|
|
28
|
+
files?: boolean | FilesConfig
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/** The machine config: the shared server's port and its entries. */
|
|
@@ -49,7 +51,7 @@ export interface EntryProject {
|
|
|
49
51
|
/** the URL path it is served under, without a trailing slash: /<entry>/<path> */
|
|
50
52
|
base: string
|
|
51
53
|
/** its entry's `files`, when the entry sets it */
|
|
52
|
-
files?: boolean
|
|
54
|
+
files?: boolean | FilesConfig
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -130,12 +132,21 @@ export function readMachineConfig(dir = machineDir()): MachineConfig | null {
|
|
|
130
132
|
throw new Error(`${file}: entries.${name}.${what} must be a list of globs`)
|
|
131
133
|
return v
|
|
132
134
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
const files = e?.files
|
|
136
|
+
if (files != null && typeof files !== 'boolean' && (typeof files !== 'object' || Array.isArray(files)))
|
|
137
|
+
throw new Error(`${file}: entries.${name}.files must be true, false or { "include": [...], "exclude": [...] }`)
|
|
135
138
|
entries[name] = {
|
|
136
139
|
include: list(e?.include, 'include'),
|
|
137
140
|
exclude: list(e?.exclude, 'exclude'),
|
|
138
|
-
...(
|
|
141
|
+
...(files != null && {
|
|
142
|
+
files:
|
|
143
|
+
typeof files === 'boolean'
|
|
144
|
+
? files
|
|
145
|
+
: {
|
|
146
|
+
...(files.include != null && { include: list(files.include, 'files.include') }),
|
|
147
|
+
...(files.exclude != null && { exclude: list(files.exclude, 'files.exclude') }),
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
139
150
|
}
|
|
140
151
|
}
|
|
141
152
|
const port = raw.port == null ? undefined : Number(raw.port)
|
package/src/events.ts
CHANGED
|
@@ -70,13 +70,16 @@ export const isEventId = (id: unknown): id is string =>
|
|
|
70
70
|
/**
|
|
71
71
|
* Append one event; `action` is the button that submitted a form, null for anything else. `from`
|
|
72
72
|
* is set only for events the command line writes ('cli'), so that waits skip them and pages can
|
|
73
|
-
* tell them apart; what the browser appends has none.
|
|
73
|
+
* tell them apart; what the browser appends has none. `by` is who wrote it; `session`, the agent
|
|
74
|
+
* session it was written in, when that is another id than `by` (`WORKPAD_AGENT` named the writer):
|
|
75
|
+
* a channel that knows the agent by its session still knows the event for its own.
|
|
74
76
|
*/
|
|
75
77
|
export function appendEvent(
|
|
76
78
|
file: string,
|
|
77
79
|
input: EventInput,
|
|
78
80
|
from: 'cli' | null = null,
|
|
79
81
|
by: string | null = null,
|
|
82
|
+
session: string | null = null,
|
|
80
83
|
): WpEvent {
|
|
81
84
|
const event: WpEvent = {
|
|
82
85
|
id: isEventId(input.id) ? input.id : `${Date.now().toString(36)}-${crypto.randomBytes(3).toString('hex')}`,
|
|
@@ -87,6 +90,7 @@ export function appendEvent(
|
|
|
87
90
|
data: input.data ?? {},
|
|
88
91
|
...(from ? { from } : {}),
|
|
89
92
|
...(by ? { by } : {}),
|
|
93
|
+
...(session && session !== by ? { session } : {}),
|
|
90
94
|
}
|
|
91
95
|
fs.appendFileSync(file, JSON.stringify(event) + '\n')
|
|
92
96
|
return event
|
|
@@ -363,6 +367,13 @@ export interface HandOutOptions {
|
|
|
363
367
|
* handed to it, other agents' are; its received marks say it; `again` is what it received before.
|
|
364
368
|
*/
|
|
365
369
|
agent?: string | null
|
|
370
|
+
/**
|
|
371
|
+
* The other ids `agent` goes by, read as each event comes (a channel adds to it): the sessions
|
|
372
|
+
* its conversation had before (a resume, a clear), the session beside its `WORKPAD_AGENT`. An
|
|
373
|
+
* event any of them wrote (`by`, or the `session` it was written in) is its own too, and what
|
|
374
|
+
* they received it received before.
|
|
375
|
+
*/
|
|
376
|
+
aliases?: ReadonlySet<string>
|
|
366
377
|
/**
|
|
367
378
|
* Mark each as received once handed out (default true). Without, the receiver marks it itself
|
|
368
379
|
* once it has it (a channel: once its message is in the session).
|
|
@@ -388,9 +399,12 @@ export interface HandOutOptions {
|
|
|
388
399
|
|
|
389
400
|
/**
|
|
390
401
|
* Hand the events that match `filter` to `onEvent`, for agent `agent`: the reader's, and other
|
|
391
|
-
* agents' (an agent's event says who wrote it, `by`; one that doesn't is handed to no one)
|
|
392
|
-
*
|
|
393
|
-
*
|
|
402
|
+
* agents' (an agent's event says who wrote it, `by`; one that doesn't is handed to no one), never
|
|
403
|
+
* its own (written by `agent` or one of its `aliases`). Each is marked received by `agent` once
|
|
404
|
+
* handed out. First the backlog: what is not handled, also from before this started; of the
|
|
405
|
+
* reader's, those `agent` received before come again, saying so (`again`), until handled; another
|
|
406
|
+
* agent's message it received before doesn't: a message is news once, and an agent's message is
|
|
407
|
+
* never handled by a reply, so it would come back at every start. Then, with `follow`, every new one as
|
|
394
408
|
* it comes. The backlog and the following split the log at one line boundary, so no event falls
|
|
395
409
|
* between them. Any number hand out from one log at once: each gets every event. Of the plugins'
|
|
396
410
|
* events only those for an agent (`forAgent`), unless the filter asks for a type by name.
|
|
@@ -413,6 +427,7 @@ export function handOut(
|
|
|
413
427
|
batch = false,
|
|
414
428
|
mark = true,
|
|
415
429
|
agent = null,
|
|
430
|
+
aliases = new Set<string>(),
|
|
416
431
|
skipReceivedBefore,
|
|
417
432
|
readerOnly = false,
|
|
418
433
|
notReceivedByOthers = false,
|
|
@@ -426,7 +441,9 @@ export function handOut(
|
|
|
426
441
|
resolve(got)
|
|
427
442
|
}
|
|
428
443
|
// whose events: the reader's, and another agent's that says who it is
|
|
429
|
-
const
|
|
444
|
+
const me = (id: string | undefined) => !!id && (id === agent || aliases.has(id))
|
|
445
|
+
const own = (e: WpEvent) => me(e.by) || me(e.session)
|
|
446
|
+
const fromOthers = (e: WpEvent) => fromReader(e) || (!readerOnly && !!e.by && !own(e))
|
|
430
447
|
// of those, the ones for an agent, unless the filter names a type
|
|
431
448
|
const wanted = (e: WpEvent) => fromOthers(e) && matches(e, filter) && (!!filter.type || isForAgent(e.type))
|
|
432
449
|
// what this identity received before, by id: handed out again, it says so
|
|
@@ -442,10 +459,11 @@ export function handOut(
|
|
|
442
459
|
const { events, end } = read(file)
|
|
443
460
|
const handled = handledIds(events)
|
|
444
461
|
before = receivedBy(events, agent)
|
|
462
|
+
for (const alias of aliases) for (const id of receivedBy(events, alias)) before.add(id)
|
|
445
463
|
const others = notReceivedByOthers
|
|
446
464
|
? new Set(
|
|
447
465
|
events
|
|
448
|
-
.filter(e => e.type === RECEIVED && !fromReader(e) && (e.by ?? null) !== agent)
|
|
466
|
+
.filter(e => e.type === RECEIVED && !fromReader(e) && !me(e.by) && (e.by ?? null) !== agent)
|
|
449
467
|
.map(e => String(e.data?.event)),
|
|
450
468
|
)
|
|
451
469
|
: new Set<string>()
|
|
@@ -455,6 +473,8 @@ export function handOut(
|
|
|
455
473
|
for (const e of events) {
|
|
456
474
|
if (skipping && e.id === skipReceivedBefore) skipping = false
|
|
457
475
|
if (skipping && !fromReader(e) && receivedAny.has(e.id)) continue
|
|
476
|
+
// another agent's message this agent had already: not again
|
|
477
|
+
if (!fromReader(e) && before.has(e.id)) continue
|
|
458
478
|
if (wanted(e) && !handled.has(e.id) && !others.has(e.id) && !hand(e)) return finish()
|
|
459
479
|
}
|
|
460
480
|
// a batch: what there was, if anything; else it goes on for the first to come
|
package/src/files.ts
CHANGED
|
@@ -26,7 +26,32 @@ export interface FileFilter {
|
|
|
26
26
|
mayHold(rel: string): boolean
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Does `rel` match `g`? As `path.posix.matchesGlob`, but a `**` takes in folders whose name starts
|
|
31
|
+
* with a dot as well: matchesGlob's doesn't, so `**\/node_modules` left out nothing under `.claude/`,
|
|
32
|
+
* and an install in a worktree kept there reached the watcher as thousands of changes. Segment by
|
|
33
|
+
* segment: `**` stands for any number of folders, every other segment is matched by matchesGlob.
|
|
34
|
+
*/
|
|
35
|
+
export function glob(rel: string, g: string): boolean {
|
|
36
|
+
const parts = g.split('/')
|
|
37
|
+
const segs = rel.split('/')
|
|
38
|
+
const seen = new Set<string>()
|
|
39
|
+
const at = (i: number, j: number): boolean => {
|
|
40
|
+
if (i === parts.length) return j === segs.length
|
|
41
|
+
const key = `${i},${j}`
|
|
42
|
+
if (seen.has(key)) return false
|
|
43
|
+
seen.add(key)
|
|
44
|
+
if (parts[i] === '**') {
|
|
45
|
+
for (let k = j; k <= segs.length; k++) if (at(i + 1, k)) return true
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
return j < segs.length && path.posix.matchesGlob(segs[j]!, parts[i]!) && at(i + 1, j + 1)
|
|
49
|
+
}
|
|
50
|
+
return at(0, 0)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// the always-excluded by folder name: checked first, it settles most of a burst cheaply
|
|
54
|
+
const ALWAYS_NAMES = new Set(ALWAYS_EXCLUDED.map(g => g.slice('**/'.length)))
|
|
30
55
|
|
|
31
56
|
/** The path and each folder above it: `a/b/c` → `a/b/c`, `a/b`, `a`. */
|
|
32
57
|
function* upward(rel: string) {
|
|
@@ -57,7 +82,8 @@ export function fileFilter(files?: boolean | FilesConfig): FileFilter {
|
|
|
57
82
|
const exclude = [...ALWAYS_EXCLUDED, ...(config.exclude ?? [])]
|
|
58
83
|
const include = config.include?.length ? config.include : null
|
|
59
84
|
// left out: it, or a folder it is in, matches an exclude
|
|
60
|
-
const excluded = (rel: string) =>
|
|
85
|
+
const excluded = (rel: string) =>
|
|
86
|
+
rel.split('/').some(s => ALWAYS_NAMES.has(s)) || [...upward(rel)].some(p => exclude.some(g => glob(p, g)))
|
|
61
87
|
// taken in: it, or a folder it is in, matches an include
|
|
62
88
|
const included = (rel: string) => !include || [...upward(rel)].some(p => include.some(g => glob(p, g)))
|
|
63
89
|
return {
|
package/src/help.ts
CHANGED
|
@@ -66,10 +66,10 @@ opencode()). Alone, it says your id and your name.
|
|
|
66
66
|
"The link leaves out the server's address (`/rg/jobs/x/decisions#form:logger`), so it works however the board is opened; --full prints the whole URL, for outside a board. The page can be another project's: name its file. An anchor the page doesn't have exits 1, listing those it has.",
|
|
67
67
|
},
|
|
68
68
|
settle: {
|
|
69
|
-
usage: '<page|file> <form>… | --all',
|
|
69
|
+
usage: '<page|file> <form>… | --all | <form> --replace-with <file|->',
|
|
70
70
|
summary: 'settle questions answered elsewhere (a chat, the design moving on): no longer unanswered',
|
|
71
71
|
details:
|
|
72
|
-
"A form a chat settled, or the design moved past, would otherwise stay \"unanswered\" for good: in `workpad status`, the page's counter, the turn-end check. Settled, it counts as answered elsewhere. With `--all`, every open (or held) question on the page; without forms or `--all` it settles nothing and says which are open. A form with an answer in is left as it is. If the reader answers a settled form after all, it is open again. Say what settled it in its chat first, so the reader sees why.",
|
|
72
|
+
"A form a chat settled, or the design moved past, would otherwise stay \"unanswered\" for good: in `workpad status`, the page's counter, the turn-end check. Settled, it counts as answered elsewhere. With `--all`, every open (or held) question on the page; without forms or `--all` it settles nothing and says which are open. A form with an answer in is left as it is. If the reader answers a settled form after all, it is open again. Say what settled it in its chat first, so the reader sees why.\n\n --replace-with <file|-> also replace the form on the page with this markdown (a file, or - for\n standard input), such as a line saying what was decided: one form, named.\n The form is found as `workpad set` finds it; one the page lacks settles\n nothing. Its chat goes to the page's folded list of chats no longer on it\n (`workpad chat prune` removes it).\n\n workpad settle plan logger --replace-with - <<'EOF'\n **Decided:** pino, for its speed.\n EOF",
|
|
73
73
|
},
|
|
74
74
|
hold: {
|
|
75
75
|
usage: '<page|file> <form>… "<reason>"',
|
|
@@ -83,9 +83,9 @@ opencode()). Alone, it says your id and your name.
|
|
|
83
83
|
},
|
|
84
84
|
check: {
|
|
85
85
|
usage: '[<page|file>…]',
|
|
86
|
-
summary: "what is wrong on pages, as they render: a block nobody brings, an input outside its form, a block's error",
|
|
86
|
+
summary: "what is wrong on pages, as they render: a block nobody brings, an input outside its form, a block's error, a broken link",
|
|
87
87
|
details:
|
|
88
|
-
"Every page of the project, or those named. Per page, one line for each problem: a config or frontmatter that doesn't parse, a block that reports an error (a diagram that doesn't parse, a form's name used twice), a block nobody brings (`:::tabz`), a form's input or button outside any form (a block inside the form one colon short), an attribute a block doesn't read, a link to an anchor the page
|
|
88
|
+
"Every page of the project, or those named. Per page, one line for each problem: a config or frontmatter that doesn't parse, a block that reports an error (a diagram that doesn't parse, a form's name used twice), a block nobody brings (`:::tabz`), a form's input or button outside any form (a block inside the form one colon short), an attribute a block doesn't read, a link to an anchor that isn't there: on the same page (`#form:logger`, which the page shows above it too) or on another page of the project (`decisions.md#form:logger`), with the nearest anchors it does have; a link to a page that doesn't exist. Links to other projects and sites aren't checked. Exits 1 when there is any. Run it after writing a page.",
|
|
89
89
|
},
|
|
90
90
|
anchors: {
|
|
91
91
|
usage: '<page|file>',
|
|
@@ -93,6 +93,31 @@ opencode()). Alone, it says your id and your name.
|
|
|
93
93
|
details:
|
|
94
94
|
"Headings by their slug (`#open-questions`), and `#<type>:<name>` for the rest: `#form:logger`, `#chat:notes`, `#tab:intro`, `#details:why`. A chat message is `#message:<event id>`, not listed. The page can be another project's: name its file.",
|
|
95
95
|
},
|
|
96
|
+
set: {
|
|
97
|
+
usage: '<page|file> <anchor|form> --file <file|->',
|
|
98
|
+
summary: "replace one block of a page by its name: a form, a heading's section, a chat or other named block",
|
|
99
|
+
details: `The markdown comes from a file, or with - from standard input (a heredoc with a quoted
|
|
100
|
+
delimiter: nothing in it passes through the shell's quoting). The block is found by parsing the
|
|
101
|
+
page, as a link names it (\`workpad anchors\`):
|
|
102
|
+
|
|
103
|
+
#form:logger the :::form{name=logger} container
|
|
104
|
+
#open-questions a heading's section: the heading and what follows, up to the next heading
|
|
105
|
+
of the same or a higher level (a deeper one is inside it)
|
|
106
|
+
#chat:notes a :::chat{name=notes}; any block with a name: #<type>:<name>, or with a
|
|
107
|
+
label: #details:why-not-mdx, #item:parser
|
|
108
|
+
logger a bare name: the block whose anchor it is, or whose name it is (form:logger);
|
|
109
|
+
when it fits two (a heading and a form), name it by its anchor, with its #
|
|
110
|
+
|
|
111
|
+
Everything else on the page stays as it was, byte for byte; a form in a code fence is never touched.
|
|
112
|
+
A name the page doesn't have exits 1, listing the blocks it has. To settle a form and put what was
|
|
113
|
+
decided in its place in one step: workpad settle <page> <form> --replace-with <file|->.
|
|
114
|
+
|
|
115
|
+
workpad set plan '#open-questions' --file - <<'EOF'
|
|
116
|
+
## Open questions
|
|
117
|
+
|
|
118
|
+
None left.
|
|
119
|
+
EOF`,
|
|
120
|
+
},
|
|
96
121
|
migrate: {
|
|
97
122
|
usage: '[<folder|file>…] [--write]',
|
|
98
123
|
summary: "after updating workpad: rewrite pages written in an older syntax in the current one",
|
|
@@ -131,9 +156,11 @@ One chat's messages: workpad chat prune <page|file> <chat>.`,
|
|
|
131
156
|
--skip <a,b> plugins or blocks to leave out (default: form, chat, comments, draft)`,
|
|
132
157
|
},
|
|
133
158
|
edit: {
|
|
134
|
-
usage: '<event id> --data <json>',
|
|
159
|
+
usage: '<event id> --data <json> | --file <file|-> | --text-file <file|->',
|
|
135
160
|
summary: "change an agent's own event in place (merged into its data)",
|
|
136
|
-
details:
|
|
161
|
+
details: `Keeps its id, so what refers to it still does. What the reader sent can't be edited.
|
|
162
|
+
The data is taken as append takes it: --data, --file (JSON from a file, or - for standard input),
|
|
163
|
+
--text-file (markdown as its text).`,
|
|
137
164
|
},
|
|
138
165
|
scroll: {
|
|
139
166
|
usage: '<page|file> <where>',
|
|
@@ -192,8 +219,16 @@ follower goes, as do new pages. What it hands out counts as received by you. Wit
|
|
|
192
219
|
confirmed channel takes these pages on (none becomes yours) and it exits.`,
|
|
193
220
|
},
|
|
194
221
|
append: {
|
|
195
|
-
usage: '--page <p> --type <t> [--data <json>]',
|
|
222
|
+
usage: '--page <p> --type <t> [--data <json> | --file <file|->] [--text-file <file|->]',
|
|
196
223
|
summary: "add an event to a page's log, as the agent (a reply, a chat message)",
|
|
224
|
+
details: ` --data <json> its data, as JSON on the command line: for short data without markdown
|
|
225
|
+
--file <file|-> its data, as JSON from a file, or - for standard input
|
|
226
|
+
--text-file <file|-> markdown from a file, or - for standard input, as the data's "text" (with
|
|
227
|
+
--data or --file for the rest): a chat reply, without shell quoting
|
|
228
|
+
|
|
229
|
+
workpad append --page plan --type chat:message --data '{"chat":"page"}' --text-file - <<'EOF'
|
|
230
|
+
It's **done**: see [the logger question](#form:logger).
|
|
231
|
+
EOF`,
|
|
197
232
|
},
|
|
198
233
|
handled: {
|
|
199
234
|
usage: '<event id> [<event id>…]',
|
package/src/hub.ts
CHANGED
|
@@ -38,6 +38,8 @@ import { API_LISTS, createServer, type ApiList, type WorkpadServer } from './ser
|
|
|
38
38
|
import type { LiveEvent } from './state.ts'
|
|
39
39
|
import type { IndexPage, IndexProject, Listener, PageStatus } from './define.ts'
|
|
40
40
|
import { holdStream, listenerOf } from './listeners.ts'
|
|
41
|
+
import { readEvents } from './events.ts'
|
|
42
|
+
import { isStale, running } from '../plugins/progress/state.ts'
|
|
41
43
|
|
|
42
44
|
export interface HubOptions {
|
|
43
45
|
/** the machine folder (its config.json), which the server only reads; default machineDir() */
|
|
@@ -149,7 +151,7 @@ export function createHub({
|
|
|
149
151
|
// projects come and go: the overview lists them
|
|
150
152
|
setImmediate(() => touch())
|
|
151
153
|
// a project whose entry's files changed is made again with it
|
|
152
|
-
const wanted = new Map(projects.map(p => [`${p.base}\n${p.dir}\n${p.files ??
|
|
154
|
+
const wanted = new Map(projects.map(p => [`${p.base}\n${p.dir}\n${JSON.stringify(p.files ?? null)}`, p]))
|
|
153
155
|
for (const [key, s] of served)
|
|
154
156
|
if (!wanted.has(key)) {
|
|
155
157
|
for (const el of entryListens) release(s, el)
|
|
@@ -208,14 +210,22 @@ export function createHub({
|
|
|
208
210
|
// the projects that changed since: each other project's open pages are told, for their menu of
|
|
209
211
|
// what waits elsewhere (pushed, so no page has to ask every project now and then)
|
|
210
212
|
const changes = new Set<string>()
|
|
213
|
+
// told 150 ms after the first change, then at most once a second: a burst of changes (an install
|
|
214
|
+
// writing into a shown folder) re-renders the overview's clients once a second, not at each pause
|
|
215
|
+
let toldAt = 0
|
|
211
216
|
const touch = () => {
|
|
212
|
-
|
|
213
|
-
touching = setTimeout(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
if (touching) return
|
|
218
|
+
touching = setTimeout(
|
|
219
|
+
() => {
|
|
220
|
+
touching = undefined
|
|
221
|
+
toldAt = Date.now()
|
|
222
|
+
root.touch()
|
|
223
|
+
const from = [...changes]
|
|
224
|
+
changes.clear()
|
|
225
|
+
for (const s of served.values()) if (from.some(b => b !== s.base)) s.server.elsewhere()
|
|
226
|
+
},
|
|
227
|
+
Math.max(150, toldAt + 1000 - Date.now()),
|
|
228
|
+
)
|
|
219
229
|
}
|
|
220
230
|
const changed = (base: string) => {
|
|
221
231
|
changes.add(base)
|
|
@@ -256,6 +266,12 @@ export function createHub({
|
|
|
256
266
|
} catch (err) {
|
|
257
267
|
return { ...at, pages: [], active: 0, error: (err as Error).message }
|
|
258
268
|
}
|
|
269
|
+
// each page's running progress, the one moved last (plugins/progress): its line on the card
|
|
270
|
+
const now = Date.now()
|
|
271
|
+
const runs = new Map<string, IndexPage['progress']>()
|
|
272
|
+
for (const r of running(readEvents(s.project.eventsFile)))
|
|
273
|
+
if (!runs.has(r.page))
|
|
274
|
+
runs.set(r.page, { id: r.id, note: r.note, n: r.n, total: r.total, ts: r.ts, stale: isStale(r, now) })
|
|
259
275
|
const pages = statuses
|
|
260
276
|
.map((p): IndexPage => ({
|
|
261
277
|
page: p.page,
|
|
@@ -266,6 +282,7 @@ export function createHub({
|
|
|
266
282
|
open: p.open,
|
|
267
283
|
unread: p.unread.length,
|
|
268
284
|
unreceived: p.unreceived.length,
|
|
285
|
+
progress: runs.get(p.page) ?? null,
|
|
269
286
|
}))
|
|
270
287
|
.toSorted((a, b) => b.updated - a.updated)
|
|
271
288
|
return { ...at, pages, active: pages[0]?.updated ?? 0 }
|
package/src/loader.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// the pages (how markdown is rendered with their blocks).
|
|
5
5
|
import fs from 'node:fs'
|
|
6
6
|
import path from 'node:path'
|
|
7
|
-
import { fileFilter, type FileFilter } from './files.ts'
|
|
7
|
+
import { fileFilter, type FileFilter, type FilesConfig } from './files.ts'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
9
|
import { importFresh, importOwn } from './load.ts'
|
|
10
10
|
import { createPages, type Pages } from './pages/index.ts'
|
|
@@ -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',
|
|
@@ -120,12 +126,12 @@ function checkPlugin(e: Plugin, where: string | null) {
|
|
|
120
126
|
const RETRY_FAILED_MS = 5000
|
|
121
127
|
|
|
122
128
|
/**
|
|
123
|
-
* `files`:
|
|
124
|
-
* entry can say
|
|
129
|
+
* `files`: which of its own files the project serves when its config doesn't say (a machine config's
|
|
130
|
+
* entry can say it for all of its projects; see EntryConfig).
|
|
125
131
|
*/
|
|
126
132
|
export function createConfigLoader(
|
|
127
133
|
proj: Project,
|
|
128
|
-
{ pages: withPages = true, files: filesDefault = true }: { pages?: boolean; files?: boolean } = {},
|
|
134
|
+
{ pages: withPages = true, files: filesDefault = true }: { pages?: boolean; files?: boolean | FilesConfig } = {},
|
|
129
135
|
) {
|
|
130
136
|
let cached: Promise<LoadedConfig> | null = null
|
|
131
137
|
let failedAt: number | null = null
|
|
@@ -178,14 +184,17 @@ 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
|
-
files: config?.files
|
|
188
|
-
fileFilter: fileFilter(config?.files),
|
|
196
|
+
files: (config?.files ?? filesDefault) !== false,
|
|
197
|
+
fileFilter: fileFilter(config?.files ?? filesDefault),
|
|
189
198
|
build: config?.build ?? {},
|
|
190
199
|
commands: configCommands(config?.commands, { taken: RESERVED, plugins: plugins.map(p => p.name), where: configFile }),
|
|
191
200
|
}
|
|
@@ -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
|
@@ -55,7 +55,9 @@ export function byState<P extends IndexProject>(
|
|
|
55
55
|
for (const project of projects)
|
|
56
56
|
for (const page of project.pages) {
|
|
57
57
|
const card = { page, project, waiting: waitingOn(page) }
|
|
58
|
-
|
|
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'
|
|
59
61
|
columns[column].push(card)
|
|
60
62
|
}
|
|
61
63
|
for (const cards of [columns.waiting, columns.active, columns.quiet]) cards.sort(byAttention)
|
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'
|
|
@@ -1005,7 +1005,7 @@ plugin "${name}" failed to compose around block "${block.name}": ${(err as Error
|
|
|
1005
1005
|
const out = stringify(tree.children ?? [])
|
|
1006
1006
|
// a link to a place on this page that isn't there; a chat message's (#message:) are drawn later
|
|
1007
1007
|
if (links.length) {
|
|
1008
|
-
const ids =
|
|
1008
|
+
const ids = anchorsOf(String(out)).map(a => a.id)
|
|
1009
1009
|
for (const url of links) {
|
|
1010
1010
|
let id = url.slice(1)
|
|
1011
1011
|
try {
|
|
@@ -1013,8 +1013,8 @@ plugin "${name}" failed to compose around block "${block.name}": ${(err as Error
|
|
|
1013
1013
|
} catch {
|
|
1014
1014
|
/* as written */
|
|
1015
1015
|
}
|
|
1016
|
-
if (id && !id.startsWith('message:') && !ids.
|
|
1017
|
-
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)}`)
|
|
1018
1018
|
}
|
|
1019
1019
|
}
|
|
1020
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,12 +412,30 @@ 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>`}
|
|
438
|
+
${c.page.progress && progressLine(c.page.progress)}
|
|
421
439
|
<span class="wp-meta wp-board-when">updated ${time(c.page.updated)}</span>
|
|
422
440
|
</li>`
|
|
423
441
|
}
|