@bigmistqke/workpad 0.19.0 → 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 +187 -37
- package/dist/bin/workpad.js +156 -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/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/events.js +19 -9
- package/dist/src/help.js +43 -8
- package/dist/src/hub.js +14 -1
- package/dist/src/loader.js +7 -2
- 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 +25 -12
- 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/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/events.ts +26 -6
- package/src/help.ts +42 -7
- package/src/hub.ts +9 -0
- package/src/loader.ts +14 -4
- 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 +43 -13
- 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/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/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() */
|
|
@@ -256,6 +258,12 @@ export function createHub({
|
|
|
256
258
|
} catch (err) {
|
|
257
259
|
return { ...at, pages: [], active: 0, error: (err as Error).message }
|
|
258
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) })
|
|
259
267
|
const pages = statuses
|
|
260
268
|
.map((p): IndexPage => ({
|
|
261
269
|
page: p.page,
|
|
@@ -266,6 +274,7 @@ export function createHub({
|
|
|
266
274
|
open: p.open,
|
|
267
275
|
unread: p.unread.length,
|
|
268
276
|
unreceived: p.unreceived.length,
|
|
277
|
+
progress: runs.get(p.page) ?? null,
|
|
269
278
|
}))
|
|
270
279
|
.toSorted((a, b) => b.updated - a.updated)
|
|
271
280
|
return { ...at, pages, active: pages[0]?.updated ?? 0 }
|
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
|
@@ -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
|
}
|
package/src/server.ts
CHANGED
|
@@ -32,7 +32,6 @@ import {
|
|
|
32
32
|
follow,
|
|
33
33
|
handle as handleEvent,
|
|
34
34
|
matches,
|
|
35
|
-
receivedIds,
|
|
36
35
|
handledIds,
|
|
37
36
|
forAgent,
|
|
38
37
|
namesOf,
|
|
@@ -63,7 +62,17 @@ import { describeRoutes, dispatch, pluginCommands, mountRoutes, usage } from './
|
|
|
63
62
|
import { createAuth, sameSite } from './auth.ts'
|
|
64
63
|
import { accept, refuse } from './ws.ts'
|
|
65
64
|
import { FROM_SOURCE, PACKAGE_DIR, VERSION } from './package.ts'
|
|
66
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
SCROLL,
|
|
67
|
+
agentLabel,
|
|
68
|
+
agentMessagesIn,
|
|
69
|
+
awaiting,
|
|
70
|
+
isAgentMessage,
|
|
71
|
+
projectStatus,
|
|
72
|
+
receivers,
|
|
73
|
+
refusal,
|
|
74
|
+
type ProjectStatus,
|
|
75
|
+
} from './status.ts'
|
|
67
76
|
import { formsIn, messageForms } from './pages/markdown.ts'
|
|
68
77
|
import { fileFilter, type FileFilter } from './files.ts'
|
|
69
78
|
import { titleOf } from './pages/render.ts'
|
|
@@ -106,6 +115,9 @@ const MIME: Record<string, string> = {
|
|
|
106
115
|
'.csv': 'text/csv; charset=utf-8',
|
|
107
116
|
'.html': 'text/html; charset=utf-8',
|
|
108
117
|
}
|
|
118
|
+
/** How many of the browser's latest events the server knows by id, to answer a retried send with the first. */
|
|
119
|
+
const APPENDED_KEPT = 1000
|
|
120
|
+
|
|
109
121
|
// files in .workpad/ that are the server's own bookkeeping, not content
|
|
110
122
|
const OWN_FILES = new Set(['events.ndjson', 'server.json', 'server.log', 'server.lock', 'token'])
|
|
111
123
|
|
|
@@ -263,7 +275,8 @@ export function createServer(
|
|
|
263
275
|
const notices = [...rendered.notices]
|
|
264
276
|
const parts = await pluginParts(await pluginHooks(), req, {
|
|
265
277
|
asset,
|
|
266
|
-
messages:
|
|
278
|
+
messages: Object.fromEntries((await config()).forReader),
|
|
279
|
+
handedOut: [...(await config()).handedOut],
|
|
267
280
|
failed: message => {
|
|
268
281
|
console.error(message)
|
|
269
282
|
notices.push(message)
|
|
@@ -466,7 +479,7 @@ export function createServer(
|
|
|
466
479
|
events,
|
|
467
480
|
listeners: listenersFor,
|
|
468
481
|
forAgent: forAgent(handedOut),
|
|
469
|
-
forReader
|
|
482
|
+
forReader,
|
|
470
483
|
})
|
|
471
484
|
}
|
|
472
485
|
|
|
@@ -799,8 +812,17 @@ export function createServer(
|
|
|
799
812
|
}
|
|
800
813
|
|
|
801
814
|
const clients = new Set<WatchClient>()
|
|
802
|
-
/**
|
|
803
|
-
|
|
815
|
+
/**
|
|
816
|
+
* what the browser appended lately, by id: a send it retries is answered with what it got. From
|
|
817
|
+
* the log at the start, so a retry that comes after a restart (the first try got in, its answer
|
|
818
|
+
* didn't get out) is no second answer either.
|
|
819
|
+
*/
|
|
820
|
+
const appended = new Map<string, WpEvent>(
|
|
821
|
+
readEvents(project.eventsFile)
|
|
822
|
+
.filter(e => !e.from)
|
|
823
|
+
.slice(-APPENDED_KEPT)
|
|
824
|
+
.map(e => [e.id, e]),
|
|
825
|
+
)
|
|
804
826
|
function notify(client: WatchClient, kind: string) {
|
|
805
827
|
client.pending ??= new Set()
|
|
806
828
|
if (client.pending.size === 0)
|
|
@@ -1134,9 +1156,12 @@ export function createServer(
|
|
|
1134
1156
|
// the browser sends it again when it heard nothing back: appended once, the same answer twice
|
|
1135
1157
|
const again = isEventId(body.id) ? appended.get(body.id) : undefined
|
|
1136
1158
|
if (again) return sendJson(res, 200, again)
|
|
1159
|
+
// an event without the data its type requires shows nowhere (a chat message with no text)
|
|
1160
|
+
const refused = refusal(body.type, body.data, (await config()).requires)
|
|
1161
|
+
if (refused) return sendJson(res, 400, { error: refused })
|
|
1137
1162
|
const event = appendEvent(project.eventsFile, body)
|
|
1138
1163
|
appended.set(event.id, event)
|
|
1139
|
-
if (appended.size >
|
|
1164
|
+
if (appended.size > APPENDED_KEPT) appended.delete(appended.keys().next().value!)
|
|
1140
1165
|
return sendJson(res, 200, event)
|
|
1141
1166
|
}
|
|
1142
1167
|
// an agent shows the reader a place on a page: every tab with it open scrolls there
|
|
@@ -1264,7 +1289,7 @@ export function createServer(
|
|
|
1264
1289
|
if (p === '/api/events') {
|
|
1265
1290
|
const all = after(readEvents(project.eventsFile), q.since)
|
|
1266
1291
|
// what became of each: received by a wait, handled by the agent (status.ts)
|
|
1267
|
-
const received =
|
|
1292
|
+
const received = receivers(all)
|
|
1268
1293
|
const handled = handledIds(all)
|
|
1269
1294
|
return sendJson(
|
|
1270
1295
|
res,
|
|
@@ -1272,11 +1297,16 @@ export function createServer(
|
|
|
1272
1297
|
all
|
|
1273
1298
|
// `type` and `kind` may be several, comma-separated (state.ts); `page` and `exact` as ever
|
|
1274
1299
|
.filter(e => matches(e, { ...q, type: null }) && matchesQuery(e, q))
|
|
1275
|
-
.map(e =>
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1300
|
+
.map(e => {
|
|
1301
|
+
const by = received.get(e.id)
|
|
1302
|
+
return {
|
|
1303
|
+
...e,
|
|
1304
|
+
...(received.has(e.id) && { received: true }),
|
|
1305
|
+
// who, as the page says it ("received by …")
|
|
1306
|
+
...(by && { receivedBy: agentLabel(by, names) }),
|
|
1307
|
+
...(handled.has(e.id) && { handled: true }),
|
|
1308
|
+
}
|
|
1309
|
+
}),
|
|
1280
1310
|
)
|
|
1281
1311
|
}
|
|
1282
1312
|
if (p === '/api/docs') return sendJson(res, 200, await docs())
|