@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.
Files changed (109) hide show
  1. package/README.md +18 -9
  2. package/bin/workpad.ts +412 -58
  3. package/dist/bin/workpad.js +336 -46
  4. package/dist/client/runtime.js +141 -18
  5. package/dist/plugins/badge/README.md +59 -10
  6. package/dist/plugins/badge/index.js +130 -8
  7. package/dist/plugins/badge/public/style.css +132 -12
  8. package/dist/plugins/chat/README.md +7 -3
  9. package/dist/plugins/chat/index.js +8 -1
  10. package/dist/plugins/chat/public/client.js +2 -2
  11. package/dist/plugins/chat/public/style.css +10 -0
  12. package/dist/plugins/claude/README.md +13 -5
  13. package/dist/plugins/claude/channel.js +47 -6
  14. package/dist/plugins/claude/doctor.js +43 -47
  15. package/dist/plugins/claude/index.js +24 -8
  16. package/dist/plugins/claude/session.js +46 -1
  17. package/dist/plugins/comments/README.md +2 -1
  18. package/dist/plugins/comments/index.js +2 -0
  19. package/dist/plugins/comments/public/client.js +6 -5
  20. package/dist/plugins/comments/public/style.css +9 -0
  21. package/dist/plugins/form/README.md +1 -1
  22. package/dist/plugins/index.js +3 -1
  23. package/dist/plugins/opencode/channel.js +43 -7
  24. package/dist/plugins/opencode/index.js +2 -0
  25. package/dist/plugins/progress/README.md +41 -0
  26. package/dist/plugins/progress/index.js +117 -0
  27. package/dist/plugins/progress/public/client.js +1 -0
  28. package/dist/plugins/progress/public/style.css +85 -0
  29. package/dist/plugins/progress/state.js +210 -0
  30. package/dist/solid/index.js +3 -1
  31. package/dist/src/agents.js +13 -4
  32. package/dist/src/anchors.js +25 -1
  33. package/dist/src/build.js +1 -1
  34. package/dist/src/client/page/base.css +48 -2
  35. package/dist/src/client/page/main.js +58 -30
  36. package/dist/src/document.js +6 -4
  37. package/dist/src/events.js +22 -11
  38. package/dist/src/help.js +59 -12
  39. package/dist/src/hub.js +69 -3
  40. package/dist/src/listen.js +36 -4
  41. package/dist/src/listeners.js +14 -4
  42. package/dist/src/loader.js +7 -2
  43. package/dist/src/migrate.js +1 -1
  44. package/dist/src/pages/board.js +9 -4
  45. package/dist/src/pages/index.js +2 -4
  46. package/dist/src/pages/markdown.js +50 -19
  47. package/dist/src/pages/render.js +17 -1
  48. package/dist/src/server.js +94 -18
  49. package/dist/src/set.js +99 -0
  50. package/dist/src/state.js +2 -1
  51. package/dist/src/status.js +57 -9
  52. package/dist/src/turns.js +41 -0
  53. package/package.json +11 -1
  54. package/plugins/README.md +3 -1
  55. package/plugins/badge/README.md +59 -10
  56. package/plugins/badge/index.ts +141 -8
  57. package/plugins/badge/public/style.css +132 -12
  58. package/plugins/chat/README.md +7 -3
  59. package/plugins/chat/client.tsx +20 -3
  60. package/plugins/chat/index.ts +10 -1
  61. package/plugins/chat/public/style.css +10 -0
  62. package/plugins/claude/README.md +13 -5
  63. package/plugins/claude/channel.ts +45 -7
  64. package/plugins/claude/doctor.ts +58 -39
  65. package/plugins/claude/index.ts +30 -8
  66. package/plugins/claude/session.ts +32 -0
  67. package/plugins/comments/README.md +2 -1
  68. package/plugins/comments/client.ts +19 -0
  69. package/plugins/comments/index.ts +7 -1
  70. package/plugins/comments/public/style.css +9 -0
  71. package/plugins/form/README.md +1 -1
  72. package/plugins/index.ts +2 -0
  73. package/plugins/opencode/channel.ts +44 -8
  74. package/plugins/opencode/index.ts +4 -0
  75. package/plugins/progress/README.md +41 -0
  76. package/plugins/progress/client.ts +172 -0
  77. package/plugins/progress/index.ts +166 -0
  78. package/plugins/progress/public/style.css +85 -0
  79. package/plugins/progress/state.ts +278 -0
  80. package/skills/workpad/SKILL.md +149 -18
  81. package/solid/index.tsx +6 -2
  82. package/src/agents.ts +24 -2
  83. package/src/anchors.ts +32 -0
  84. package/src/build.ts +1 -1
  85. package/src/client/delivery.ts +49 -0
  86. package/src/client/forms.ts +18 -11
  87. package/src/client/page/base.css +48 -2
  88. package/src/client/page/waiting.ts +45 -25
  89. package/src/client/read.ts +9 -5
  90. package/src/client/runtime.ts +7 -3
  91. package/src/client/toast.ts +27 -3
  92. package/src/define.ts +120 -9
  93. package/src/document.ts +19 -5
  94. package/src/events.ts +47 -6
  95. package/src/help.ts +58 -11
  96. package/src/hub.ts +80 -2
  97. package/src/listen.ts +47 -4
  98. package/src/listeners.ts +22 -1
  99. package/src/loader.ts +14 -4
  100. package/src/migrate.ts +1 -1
  101. package/src/pages/board.ts +12 -3
  102. package/src/pages/index.ts +8 -10
  103. package/src/pages/markdown.ts +59 -12
  104. package/src/pages/render.ts +20 -2
  105. package/src/server.ts +127 -19
  106. package/src/set.ts +118 -0
  107. package/src/state.ts +3 -0
  108. package/src/status.ts +115 -14
  109. package/src/turns.ts +56 -0
@@ -0,0 +1,85 @@
1
+ /* A progress, inline where it is written (client.ts draws it): a small bar and the count while it
2
+ runs, or a word with a dot (running without a count, done, failed); the note; and its time, muted.
3
+ Its state is data-wp-progress (waiting, running, done, failed); data-wp-stale greys it. */
4
+ .wp-progress {
5
+ font-size: 0.9em;
6
+ }
7
+ .wp-progress-body {
8
+ display: inline-flex;
9
+ flex-wrap: wrap;
10
+ align-items: center;
11
+ gap: 2px var(--space-md, 8px);
12
+ vertical-align: baseline;
13
+ font-family: var(--sans);
14
+ }
15
+ .wp-progress[data-wp-progress='waiting'] .wp-progress-note {
16
+ color: var(--muted);
17
+ font-style: italic;
18
+ }
19
+ .wp-progress-bar {
20
+ position: relative;
21
+ display: inline-block;
22
+ width: 64px;
23
+ height: 5px;
24
+ border-radius: 3px;
25
+ overflow: hidden;
26
+ background: color-mix(in srgb, var(--muted) 28%, transparent);
27
+ }
28
+ .wp-progress-bar > span {
29
+ position: absolute;
30
+ inset: 0 auto 0 0;
31
+ border-radius: inherit;
32
+ background: var(--accent);
33
+ }
34
+ .wp-progress-count {
35
+ font-variant-numeric: tabular-nums;
36
+ font-weight: var(--weight-strong, 600);
37
+ }
38
+ .wp-progress-when {
39
+ color: var(--muted);
40
+ font-size: 0.92em;
41
+ }
42
+ /* the word, with its dot: blue and pulsing while it runs, green done, red failed */
43
+ .wp-progress-state {
44
+ display: inline-flex;
45
+ align-items: center;
46
+ gap: var(--space-sm, 6px);
47
+ color: var(--muted);
48
+ font: 500 var(--ui-tiny, 0.7rem) / 1 var(--sans);
49
+ }
50
+ .wp-progress-state::before {
51
+ content: '';
52
+ width: 7px;
53
+ height: 7px;
54
+ border-radius: 50%;
55
+ background: var(--wp-progress-dot, var(--muted));
56
+ }
57
+ .wp-progress[data-wp-progress='running'] {
58
+ --wp-progress-dot: var(--accent);
59
+ }
60
+ .wp-progress[data-wp-progress='done'] {
61
+ --wp-progress-dot: var(--ok);
62
+ }
63
+ .wp-progress[data-wp-progress='failed'] {
64
+ --wp-progress-dot: var(--bad);
65
+ }
66
+ @keyframes wp-progress-pulse {
67
+ 50% {
68
+ opacity: 0.35;
69
+ }
70
+ }
71
+ .wp-progress[data-wp-progress='running']:not([data-wp-stale]) .wp-progress-state::before {
72
+ animation: wp-progress-pulse 1.6s ease-in-out infinite;
73
+ }
74
+ @media (prefers-reduced-motion: reduce) {
75
+ .wp-progress-state::before {
76
+ animation: none !important;
77
+ }
78
+ }
79
+ /* stale: greyed, its time saying how long without an update */
80
+ .wp-progress[data-wp-stale] .wp-progress-body {
81
+ opacity: 0.55;
82
+ }
83
+ .wp-progress[data-wp-stale] .wp-progress-bar > span {
84
+ background: var(--muted);
85
+ }
@@ -0,0 +1,210 @@
1
+ // plugins/progress/state.ts
2
+ /** The event `workpad progress` appends: `{ id, n, total, note, eta, state }`. */
3
+ const UPDATE = "progress:update";
4
+ /**
5
+ * The server's nudge to the agent that last moved a stale progress: `{ id, to, nudge, since, at }`,
6
+ * `at` when it was due (the clock the server goes by, which a test sets).
7
+ */
8
+ const STALE = "progress:stale";
9
+ /** Who the server's nudges say they are by (their `by`): no agent, so every agent is handed them. */
10
+ const NUDGER = "workpad";
11
+ const MINUTE = 6e4;
12
+ /** A running progress with no update this long is stale. */
13
+ const STALE_AFTER = 15 * MINUTE;
14
+ /** A stale progress is nudged again at most this often. */
15
+ const NUDGE_EVERY = 15 * MINUTE;
16
+ /** A key for a progress across pages: its page and id. */
17
+ const keyOf = (page, id) => `${page}\n${id}`;
18
+ /** An id as written in `:progress{id=…}` and on the command line: letters, digits, `-` and `_`. */
19
+ const isProgressId = (id) => /^[A-Za-z0-9_-]+$/.test(id);
20
+ /** `287/1413` (spaces and thousands separators allowed): the count and the total, or null. */
21
+ function parseCount(s) {
22
+ const m = /^\s*([\d,_]+)\s*\/\s*([\d,_]+)\s*$/.exec(s);
23
+ if (!m) return null;
24
+ const n = Number(m[1].replace(/[,_]/g, ""));
25
+ const total = Number(m[2].replace(/[,_]/g, ""));
26
+ if (!Number.isFinite(n) || !Number.isFinite(total) || total <= 0 || n < 0) return null;
27
+ return {
28
+ n,
29
+ total
30
+ };
31
+ }
32
+ /** `20m`, `90s`, `1h30m`, `2h`; a bare number is minutes. Seconds, or null when it isn't one. */
33
+ function parseDuration(s) {
34
+ const t = s.trim().toLowerCase();
35
+ if (/^\d+(\.\d+)?$/.test(t)) return Math.round(Number(t) * 60);
36
+ const re = /(\d+(?:\.\d+)?)\s*(h|hr|hours?|m|min|mins|minutes?|s|sec|secs|seconds?)/gy;
37
+ let total = 0;
38
+ let at = 0;
39
+ let m;
40
+ while (m = re.exec(t)) {
41
+ const unit = m[2][0];
42
+ total += Number(m[1]) * (unit === "h" ? 3600 : unit === "m" ? 60 : 1);
43
+ at = re.lastIndex;
44
+ while (t[at] === " ") at++;
45
+ re.lastIndex = at;
46
+ }
47
+ return at === t.length && at > 0 ? Math.round(total) : null;
48
+ }
49
+ /** What `workpad progress <page> <id> …` says, after the page and id: the update's data, or why not. */
50
+ function parseArgs(args, eta) {
51
+ const [first, ...rest] = args;
52
+ if (first === void 0) throw new Error("say how far: `<n>/<total> \"<note>\"`, `\"<note>\"`, `done \"<note>\"` or `failed \"<note>\"`");
53
+ let n = null;
54
+ let total = null;
55
+ let state = "running";
56
+ let words = args;
57
+ const count = parseCount(first);
58
+ if (count) {
59
+ ({n, total} = count);
60
+ if (n > total) throw new Error(`${first}: the count is past its total`);
61
+ words = rest;
62
+ if (n === total) state = "done";
63
+ } else if (first === "done" || first === "failed") {
64
+ state = first;
65
+ words = rest;
66
+ }
67
+ let seconds = null;
68
+ if (eta != null && eta !== "") {
69
+ seconds = parseDuration(eta);
70
+ if (seconds == null) throw new Error(`--eta ${eta}: a time such as 20m, 90s or 1h30m`);
71
+ }
72
+ return {
73
+ n,
74
+ total,
75
+ note: words.join(" ").trim(),
76
+ state,
77
+ eta: state === "running" ? seconds : null
78
+ };
79
+ }
80
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
81
+ /**
82
+ * Every progress in the log, by page and id (keyOf), each as its latest update says, with its run's
83
+ * start. `events` in the log's order.
84
+ */
85
+ function progressOf(events) {
86
+ const out = /* @__PURE__ */ new Map();
87
+ for (const e of events) {
88
+ if (e.type !== "progress:update" || e.from !== "cli") continue;
89
+ const d = e.data ?? {};
90
+ const id = typeof d.id === "string" ? d.id : "";
91
+ if (!id) continue;
92
+ const key = keyOf(e.page, id);
93
+ const before = out.get(key);
94
+ const state = d.state === "done" || d.state === "failed" ? d.state : "running";
95
+ const n = num(d.n);
96
+ const total = num(d.total);
97
+ const fresh = !before || before.state !== "running";
98
+ const started = fresh ? e.ts : before.started;
99
+ const first = fresh ? null : before.first;
100
+ out.set(key, {
101
+ page: e.page,
102
+ id,
103
+ n,
104
+ total,
105
+ note: typeof d.note === "string" ? d.note : "",
106
+ state,
107
+ eta: num(d.eta),
108
+ ts: e.ts,
109
+ started,
110
+ first: first ?? (n != null ? {
111
+ n,
112
+ ts: e.ts
113
+ } : null),
114
+ by: e.by ?? null,
115
+ event: e.id
116
+ });
117
+ }
118
+ return out;
119
+ }
120
+ /** The running ones of every page, the latest moved first. */
121
+ const running = (events) => [...progressOf(events).values()].filter((p) => p.state === "running").sort((a, b) => b.ts.localeCompare(a.ts));
122
+ /**
123
+ * Milliseconds left, as the agent said (`--eta`), else as the rate since the run's first count
124
+ * says; null when neither can tell. Below zero: past it.
125
+ */
126
+ function timeLeft(p, now) {
127
+ if (p.state !== "running") return null;
128
+ const at = Date.parse(p.ts);
129
+ if (p.eta != null) return at + p.eta * 1e3 - now;
130
+ if (p.n == null || p.total == null || !p.first || p.n <= p.first.n) return null;
131
+ const rate = (p.n - p.first.n) / (at - Date.parse(p.first.ts));
132
+ if (!(rate > 0)) return null;
133
+ return at + (p.total - p.n) / rate - now;
134
+ }
135
+ /** Is it stale at `now`: running, and past the ETA it was given, or without an update for `after`? */
136
+ function isStale(p, now, after = STALE_AFTER) {
137
+ if (p.state !== "running") return false;
138
+ if (now - Date.parse(p.ts) >= after) return true;
139
+ return p.eta != null && Date.parse(p.ts) + p.eta * 1e3 < now;
140
+ }
141
+ /** `1,413` */
142
+ const thousands = (n) => n.toLocaleString("en-US");
143
+ /** `287 / 1,413`, or '' without a count. */
144
+ const countText = (p) => p.n != null && p.total != null ? `${thousands(p.n)} / ${thousands(p.total)}` : "";
145
+ /** A span of time in a few words: `40 s`, `2 min`, `1 h 20 min`. */
146
+ function span(ms) {
147
+ const s = Math.max(0, Math.round(ms / 1e3));
148
+ if (s < 60) return `${s} s`;
149
+ const min = Math.round(s / 60);
150
+ if (min < 60) return `${min} min`;
151
+ const h = Math.floor(min / 60);
152
+ const rest = min % 60;
153
+ return rest ? `${h} h ${rest} min` : `${h} h`;
154
+ }
155
+ /** `just now`, `40 s ago`, `2 min ago`. */
156
+ const ago = (ms) => ms < 1e4 ? "just now" : `${span(ms)} ago`;
157
+ /** `~20 min left`, or '' when it can't tell or is past it. */
158
+ function leftText(p, now) {
159
+ const left = timeLeft(p, now);
160
+ return left == null || left <= 0 ? "" : `~${span(left)} left`;
161
+ }
162
+ /** The line a progress is in words: `probe 287 / 1,413 · captures 3 and 4 · ~20 min left · 2 min ago`. */
163
+ function line(p, now) {
164
+ const parts = [[p.id, countText(p)].filter(Boolean).join(" ")];
165
+ if (p.state !== "running") parts.push(p.state);
166
+ if (p.note) parts.push(p.note);
167
+ if (isStale(p, now)) parts.push(`no update for ${span(now - Date.parse(p.ts))}`);
168
+ else {
169
+ const left = leftText(p, now);
170
+ if (left) parts.push(left);
171
+ parts.push(ago(now - Date.parse(p.ts)));
172
+ }
173
+ return parts.join(" · ");
174
+ }
175
+ /** The nudge for a stale progress, in words: what is stale, and what to run. */
176
+ function nudgeText(p, now) {
177
+ const how = [countText(p), p.note].filter(Boolean).join(", ");
178
+ return `${p.id} has had no update for ${span(now - Date.parse(p.ts))}${how ? ` (${how})` : ""}${isStale(p, now) && p.eta != null && now - Date.parse(p.ts) < 9e5 ? ", past its ETA" : ""} → workpad progress ${p.page} ${p.id} …, or done/failed`;
179
+ }
180
+ /**
181
+ * The nudges due at `now`: one for each stale progress that has had none since it last moved, or
182
+ * whose latest is `every` old. The log is the only record, so a server that restarts keeps count.
183
+ */
184
+ function nudgesDue(events, now, { staleAfter = STALE_AFTER, every = NUDGE_EVERY } = {}) {
185
+ const last = /* @__PURE__ */ new Map();
186
+ for (const e of events) if (e.type === "progress:stale" && e.by === "workpad" && typeof e.data?.id === "string") last.set(keyOf(e.page, e.data.id), Date.parse(typeof e.data.at === "string" ? e.data.at : e.ts));
187
+ const out = [];
188
+ for (const p of progressOf(events).values()) {
189
+ if (!isStale(p, now, staleAfter)) continue;
190
+ const before = last.get(keyOf(p.page, p.id));
191
+ if (before != null && before >= Date.parse(p.ts) && now - before < every) continue;
192
+ out.push({
193
+ page: p.page,
194
+ type: STALE,
195
+ data: {
196
+ id: p.id,
197
+ to: p.by,
198
+ nudge: nudgeText(p, now),
199
+ since: p.ts,
200
+ at: new Date(now).toISOString()
201
+ }
202
+ });
203
+ }
204
+ return out;
205
+ }
206
+ /** The nudges for `page` and `id` no agent marked handled: `workpad progress` handles them by moving it. */
207
+ function openNudges(events, page, id, handled) {
208
+ return events.filter((e) => e.type === "progress:stale" && e.page === page && e.data?.id === id && !handled.has(e.id));
209
+ }
210
+ export { MINUTE, NUDGER, NUDGE_EVERY, STALE, STALE_AFTER, UPDATE, ago, countText, isProgressId, isStale, keyOf, leftText, line, nudgeText, nudgesDue, openNudges, parseArgs, parseCount, parseDuration, progressOf, running, span, thousands, timeLeft };
@@ -2,7 +2,7 @@ import { createComponent, render } from "@solidjs/web";
2
2
  import { createContext, createSignal, onSettled, useContext } from "solid-js";
3
3
  // solid/index.tsx
4
4
  const WorkpadContext = createContext();
5
- /** The page's events, theme, listeners, forms and unread messages, as signals. Use inside a component passed to solid(). */
5
+ /** The page's events, theme, listeners, forms, unread messages and deliveries, as signals. Use inside a component passed to solid(). */
6
6
  const useWorkpad = () => useContext(WorkpadContext);
7
7
  /** Turn a Solid component into a template client: `export default solid(MyComponent)`. */
8
8
  function solid(Component) {
@@ -17,6 +17,7 @@ function solid(Component) {
17
17
  const listeners = signal(api.listeners);
18
18
  const forms = signal(api.forms);
19
19
  const unread = signal(api.unread);
20
+ const delivery = signal(api.delivery);
20
21
  const value = {
21
22
  page: api.page,
22
23
  events,
@@ -26,6 +27,7 @@ function solid(Component) {
26
27
  listeners,
27
28
  forms,
28
29
  unread,
30
+ delivery,
29
31
  markdown: api.markdown,
30
32
  message: api.message,
31
33
  toast: api.toast
@@ -1,5 +1,6 @@
1
1
  import { fromReader, statusLines } from "./status.js";
2
2
  import { read } from "./events.js";
3
+ import { isStale, line, running } from "../plugins/progress/state.js";
3
4
  import fs from "node:fs";
4
5
  import path from "node:path";
5
6
  import { spawnSync } from "node:child_process";
@@ -33,9 +34,11 @@ async function stopReminder(ctx, session, inFlight = /* @__PURE__ */ new Set())
33
34
  awaitingReply: p.awaitingReply.filter((chat) => !inFlight.has(lastFromReader.get(chat) ?? ""))
34
35
  };
35
36
  }).filter((p) => p.unheard.length || p.unreceived.length || p.unhandled.length || p.awaitingReply.length);
36
- if (!loose.length) return null;
37
+ const now = Date.now();
38
+ const stale = running(read(ctx.eventsFile).events).filter((p) => p.by === session && isStale(p, now));
39
+ if (!loose.length && !stale.length) return null;
37
40
  const said = (p) => openOn(p, { waiting: false }).filter((l) => !l.startsWith("→")).join("; ");
38
- const shown = `workpad: ${loose.map((p) => `${p.page}: ${said(p)}`).join(" · ")}`;
41
+ const shown = `workpad: ${[...loose.map((p) => `${p.page}: ${said(p)}`), ...stale.map((p) => `${p.page}: ${line(p, now)}`)].join(" · ")}`;
39
42
  const toWait = loose.filter((p) => p.unheard.length || p.unreceived.length);
40
43
  return {
41
44
  reason: loose.map((p) => {
@@ -44,7 +47,7 @@ async function stopReminder(ctx, session, inFlight = /* @__PURE__ */ new Set())
44
47
  if (p.unhandled.length) todo.push(`act on the answers you were given and reply in their chat, or \`workpad handled ${p.unhandled.map((e) => e.id).join(" ")}\``);
45
48
  if (p.awaitingReply.length) todo.push(`reply in the chat${p.awaitingReply.length > 1 ? "s" : ""} ${p.awaitingReply.join(", ")}`);
46
49
  return `On your workpad page ${p.page}: ${said(p)}.${todo.length ? ` Before ending your turn: ${todo.join("; ")}.` : ""}`;
47
- }).concat(toWait.length > 1 ? [`Before ending your turn, ${PING} run one listen for these pages in the background: \`${waitOn(toWait)}\`.`] : []).join("\n"),
50
+ }).concat(toWait.length > 1 ? [`Before ending your turn, ${PING} run one listen for these pages in the background: \`${waitOn(toWait)}\`.`] : []).concat(stale.map((p) => `Your progress ${p.id} on workpad page ${p.page} is stale (${line(p, now)}): move it (\`workpad progress ${p.page} ${p.id} <n>/<total> "<note>"\`), or end it with \`done\` or \`failed\`.`)).join("\n"),
48
51
  shown
49
52
  };
50
53
  }
@@ -52,6 +55,7 @@ async function stopReminder(ctx, session, inFlight = /* @__PURE__ */ new Set())
52
55
  function describe(e) {
53
56
  const d = e.data ?? {};
54
57
  if (e.type === "chat:message") return `chat ${d.chat}: "${d.text}"`;
58
+ if (typeof d.nudge === "string") return d.nudge;
55
59
  if (e.type === "comments:new") return `comment on "${d.quote ?? d.at ?? ""}": "${d.text}"`;
56
60
  const fields = Object.entries(d).filter(([, v]) => v !== "" && v != null && !(Array.isArray(v) && !v.length));
57
61
  const said = fields.map(([k, v]) => fields.length === 1 ? JSON.stringify(v) : `${k}: ${JSON.stringify(v)}`);
@@ -76,6 +80,11 @@ const NPX = ["npx", "@bigmistqke/workpad"];
76
80
  const pong = (code) => `workpad: pong. Answers on your workpad pages will reach you like this message did, and count as received once they do: no \`workpad listen\` needs to run for them (\`workpad listen --channel\` makes more pages yours). Run \`workpad agent ping ${code}\` to confirm.`;
77
81
  /** An answer a channel pushes into its session, in one line: the page, what the reader did, how to see its question. */
78
82
  const answerLine = (e, again = false) => `${e.page}: ${describe(e)}${again ? " (received before, not handled yet)" : ""} (id ${e.id}; \`workpad thread ${e.id}\` shows it with its question)`;
83
+ /**
84
+ * An answer a channel brings from a page no one follows (`workpad listen --unfollowed --channel`):
85
+ * as answerLine, and under the shared server, the project it is in, where its commands run.
86
+ */
87
+ const unfollowedLine = (e, again, from) => `${answerLine(e, again)}, on a page no one follows${from ? `, in ${from.project} (${from.url}): run its workpad commands there` : ""}`;
79
88
  /** What to do about answers a channel brought: the same for every agent. */
80
89
  const ANSWERS_NOTE = "Act on each as on an answer from `workpad listen`. Then handle it with one of: a reply in its chat (`workpad append`), when you have something to say; else `workpad handled <id>`. Nothing more is needed.";
81
- export { ANSWERS_NOTE, answerLine, describe, identity, pong, stopReminder, workpadCommand };
90
+ export { ANSWERS_NOTE, answerLine, describe, identity, pong, stopReminder, unfollowedLine, workpadCommand };
@@ -49,4 +49,28 @@ function anchorsOf(html) {
49
49
  }
50
50
  /** A hash as a link writes it: escaped where it must be, the colon and slash of an id left readable. */
51
51
  const hashOf = (id) => "#" + encodeURIComponent(id).replace(/%3A/gi, ":").replace(/%2F/gi, "/");
52
- export { anchorTaken, anchorsOf, hashOf, slugText };
52
+ /** How many single-character edits turn `a` into `b`. */
53
+ function distance(a, b) {
54
+ let row = Array.from({ length: b.length + 1 }, (_, j) => j);
55
+ for (let i = 1; i <= a.length; i++) {
56
+ const next = [i];
57
+ for (let j = 1; j <= b.length; j++) next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
58
+ row = next;
59
+ }
60
+ return row[b.length];
61
+ }
62
+ /**
63
+ * Of a page's anchors, the `n` whose ids are nearest `id` by name, nearest first: what a link to a
64
+ * missing anchor most likely meant. One of its own kind (`form:` for `form:…`) comes before one of
65
+ * another at the same distance.
66
+ */
67
+ function closest(id, ids, n = 3) {
68
+ const kind = id.includes(":") ? id.slice(0, id.indexOf(":") + 1) : "";
69
+ return ids.map((other) => ({
70
+ other,
71
+ d: distance(id, other) - (kind && other.startsWith(kind) ? .5 : 0)
72
+ })).sort((a, b) => a.d - b.d).slice(0, n).map((c) => c.other);
73
+ }
74
+ /** For a message about a missing anchor: `; nearest: #a, #b` of those a page has, or how to list them. */
75
+ const nearest = (id, ids) => ids.length ? `; nearest: ${closest(id, ids).map(hashOf).join(", ")} (\`workpad anchors\` lists all)` : "; it has no anchors";
76
+ export { anchorTaken, anchorsOf, closest, hashOf, nearest, slugText };
package/dist/src/build.js CHANGED
@@ -131,7 +131,7 @@ async function build({ project, config, hooks: setUp, files: served }, options =
131
131
  };
132
132
  const parts = await pluginParts(hooks, null, {
133
133
  asset: assetHere,
134
- messages: [],
134
+ messages: {},
135
135
  leaveOut: skip,
136
136
  failed: (message) => warnings.push(`${path.relative(project.dir, file)}: ${message}`)
137
137
  });
@@ -949,8 +949,8 @@ form button[data-wp-send='failed'] {
949
949
  form[data-wp-just-sent] {
950
950
  animation: wp-sent 1.4s ease-out;
951
951
  }
952
- /* what a sent answer came to, beside the form's last send button (forms.ts): waiting for the agent
953
- (muted), couldn't send (red) */
952
+ /* what a sent answer came to, beside the form's last send button (forms.ts): where it went (muted),
953
+ not received for long (the warning colour), couldn't send (red) */
954
954
  .wp-form-status {
955
955
  margin-left: var(--space-md);
956
956
  color: var(--muted);
@@ -960,6 +960,10 @@ form[data-wp-just-sent] {
960
960
  color: var(--bad);
961
961
  font-weight: var(--weight-strong);
962
962
  }
963
+ .wp-form-status[data-kind='warn'] {
964
+ color: var(--warn);
965
+ font-weight: var(--weight-strong);
966
+ }
963
967
 
964
968
  /* a question the reader hasn't answered, or one the agent asks again: ringed, without a label of
965
969
  its own (one laid into the form landed on its content in some layouts; the corner counts them).
@@ -1329,6 +1333,48 @@ input.wp-board-search::placeholder {
1329
1333
  font: var(--ui-small)/var(--ui-line-height) var(--sans);
1330
1334
  color: color-mix(in srgb, var(--text) 72%, var(--muted));
1331
1335
  }
1336
+ /* a running progress on the page (plugins/progress): a small bar and its line */
1337
+ .wp-board-card > .wp-board-progress {
1338
+ flex: 1 1 100%;
1339
+ display: flex;
1340
+ align-items: center;
1341
+ gap: var(--space-sm);
1342
+ min-width: 0;
1343
+ font: var(--ui-small)/var(--ui-line-height) var(--sans);
1344
+ }
1345
+ .wp-board-progress[data-stale] {
1346
+ opacity: 0.55;
1347
+ }
1348
+ .wp-board-progress-text {
1349
+ min-width: 0;
1350
+ overflow: hidden;
1351
+ text-overflow: ellipsis;
1352
+ white-space: nowrap;
1353
+ }
1354
+ .wp-board-progress-bar {
1355
+ position: relative;
1356
+ flex: none;
1357
+ width: 48px;
1358
+ height: 4px;
1359
+ border-radius: 2px;
1360
+ overflow: hidden;
1361
+ background: color-mix(in srgb, var(--muted) 28%, transparent);
1362
+ }
1363
+ .wp-board-progress-bar > span {
1364
+ position: absolute;
1365
+ inset: 0 auto 0 0;
1366
+ background: var(--accent);
1367
+ }
1368
+ .wp-board-progress[data-stale] .wp-board-progress-bar > span {
1369
+ background: var(--muted);
1370
+ }
1371
+ .wp-board-progress-dot {
1372
+ flex: none;
1373
+ width: 7px;
1374
+ height: 7px;
1375
+ border-radius: 50%;
1376
+ background: var(--accent);
1377
+ }
1332
1378
  .wp-board-card > .wp-board-when {
1333
1379
  color: color-mix(in srgb, var(--muted) 72%, var(--surface));
1334
1380
  margin-top: calc(var(--space-xs) * -1);
@@ -801,25 +801,44 @@ function setThemePreference(pref) {
801
801
  }
802
802
  // src/status.ts
803
803
  /**
804
+ * Can this be a question's name, the type of its answers? Not with a colon: types with one belong
805
+ * to workpad (`workpad:handled`) or a plugin (`comments:reply`, `chat:message`),
806
+ * named after its owner, so a form's answers never mix with their events.
807
+ */
808
+ const isQuestionName = (name) => !!name && !name.includes(":");
809
+ /**
804
810
  * Was this event written by the reader (a form submit, a comment), not by an agent? Agents write
805
811
  * through the command line, which marks its events `from: 'cli'`: an agent's reply, a claim, a mark.
806
812
  */
807
813
  const fromReader = (event) => event.from !== "cli";
808
814
  /**
809
- * The agent's messages on a page the reader hasn't read: events from the agent of a type
810
- * `isMessage` says is for the reader, not named by a `workpad:read` from the reader, not
811
- * replaced by a later one (`replaces`), and, given the page's `chats`, not in a chat (`data.chat`)
812
- * that is no longer among them.
815
+ * The fields of an event's `data` its type requires (EventSpec.requires) that it lacks: each must
816
+ * be a non-empty string.
817
+ */
818
+ const missingData = (data, requires) => requires.filter((field) => {
819
+ const value = data?.[field];
820
+ return typeof value !== "string" || !value.trim();
821
+ });
822
+ /**
823
+ * The agent's messages on a page the reader hasn't read: events from the agent of a type in
824
+ * `messages` (the types for the reader, each with the `data` fields it requires), not named by a
825
+ * `workpad:read` from the reader, not replaced by a later one (`replaces`), with the data their
826
+ * type requires (one without it shows nowhere on the page, so it waits for nobody), and, given the
827
+ * page's `chats`, not in a chat (`data.chat`) that is no longer among them.
813
828
  */
814
- function unreadMessages(events, isMessage, chats) {
829
+ function unreadMessages(events, messages, chats) {
815
830
  const read = /* @__PURE__ */ new Set();
816
831
  const replaced = /* @__PURE__ */ new Set();
817
832
  for (const e of events) {
818
833
  if (e.type === "workpad:read" && fromReader(e)) for (const id of e.data?.ids ?? []) read.add(String(id));
819
834
  if (e.data?.replaces) replaced.add(String(e.data.replaces));
820
835
  }
836
+ const shown = (e) => {
837
+ const requires = messages.get(e.type);
838
+ return !!requires && !missingData(e.data, requires).length;
839
+ };
821
840
  const offPage = (e) => !!chats && typeof e.data?.chat === "string" && !chats.has(e.data.chat);
822
- return events.filter((e) => !fromReader(e) && isMessage(e.type) && !read.has(e.id) && !replaced.has(e.id) && !offPage(e));
841
+ return events.filter((e) => !fromReader(e) && shown(e) && !read.has(e.id) && !replaced.has(e.id) && !offPage(e));
823
842
  }
824
843
  /** How many things on a page wait for the reader: its open questions and unread messages. */
825
844
  const awaiting = (p) => p.open.length + p.unread.length;
@@ -985,6 +1004,7 @@ function targets(kind = "all") {
985
1004
  }
986
1005
  let waitingToast;
987
1006
  let unreadToast;
1007
+ let lateToast;
988
1008
  let toastTimer = 0;
989
1009
  let unreadShown = false;
990
1010
  let dismissed = null;
@@ -1004,7 +1024,8 @@ function card(form, name, last, state) {
1004
1024
  const choices = el.querySelector(".wp-folded-choices");
1005
1025
  choices.replaceChildren(...list.map((c) => Object.assign(document.createElement("li"), { textContent: c })));
1006
1026
  choices.hidden = !list.length;
1007
- el.querySelector(".wp-folded-change").textContent = state === "received" ? "received · change" : "decided · change";
1027
+ const received = api$1.delivery().get(last.id)?.text ?? "received";
1028
+ el.querySelector(".wp-folded-change").textContent = `${state === "received" ? received : "decided"} · change`;
1008
1029
  const text = el.querySelector(".wp-folded-text");
1009
1030
  text.textContent = written.join("\n\n");
1010
1031
  text.hidden = !written.length;
@@ -1042,6 +1063,11 @@ function show(list = forms) {
1042
1063
  waitingToast.show();
1043
1064
  } else waitingToast.hide();
1044
1065
  api$1.badge("waiting", n ? `!${n}` : null, -1);
1066
+ const late = lateAnswers().length;
1067
+ if (late) {
1068
+ lateToast.update(`→ not received (${late})`);
1069
+ lateToast.show();
1070
+ } else lateToast.hide();
1045
1071
  clearTimeout(toastTimer);
1046
1072
  const ids = api$1.unread().map((e) => e.id);
1047
1073
  if (dismissed && (!unread || ids.some((id) => !dismissed.has(id)))) dismissed = null;
@@ -1065,6 +1091,19 @@ function show(list = forms) {
1065
1091
  });
1066
1092
  }
1067
1093
  }
1094
+ /**
1095
+ * The reader's answers no agent received for long (late): each of a form only its latest (an older
1096
+ * answer was overtaken by it), every chat message and comment.
1097
+ */
1098
+ function lateAnswers() {
1099
+ const delivery = api$1.delivery();
1100
+ return api$1.events().filter((e) => delivery.get(e.id)?.state === "late" && (!isQuestionName(e.type) || api$1.last(e.type)?.id === e.id));
1101
+ }
1102
+ /** Where the late answers are on the page, top to bottom: a form's line goes to its form. */
1103
+ function lateTargets() {
1104
+ const top = (el) => el.getBoundingClientRect().top;
1105
+ return [...new Set([...document.querySelectorAll("[data-wp-delivery=late]")].filter((el) => el.getClientRects().length).map((el) => el.closest("form") ?? el))].sort((a, b) => top(a) - top(b));
1106
+ }
1068
1107
  let arriving = location.hash === WAITING_HASH;
1069
1108
  setTimeout(() => {
1070
1109
  arriving = false;
@@ -1077,7 +1116,7 @@ function next(list) {
1077
1116
  return list.find((f) => f.getBoundingClientRect().top > viewBottom() / 2) ?? list[0];
1078
1117
  }
1079
1118
  function jump(what) {
1080
- const target = next(what === "messages" ? targets("messages") : inState("open"));
1119
+ const target = next(what === "messages" ? targets("messages") : what === "late" ? lateTargets() : inState("open"));
1081
1120
  if (target) jumpTo(target);
1082
1121
  }
1083
1122
  function jumpTo(target) {
@@ -1111,8 +1150,16 @@ function trackWaiting(root, core) {
1111
1150
  unreadShown = false;
1112
1151
  }
1113
1152
  });
1153
+ lateToast = api$1.toast("", {
1154
+ ms: 0,
1155
+ kind: "warn",
1156
+ name: "not-received",
1157
+ order: -1,
1158
+ onClick: () => jump("late")
1159
+ });
1114
1160
  waitingToast.hide();
1115
1161
  unreadToast.hide();
1162
+ lateToast.hide();
1116
1163
  main$2.addEventListener("click", (e) => {
1117
1164
  const target = e.target;
1118
1165
  const form = target.closest("form[data-wp-folded]");
@@ -1142,27 +1189,8 @@ function trackWaiting(root, core) {
1142
1189
  });
1143
1190
  api$1.forms.on(show);
1144
1191
  api$1.events.on(() => show());
1192
+ api$1.delivery.on(() => show());
1145
1193
  show(api$1.forms());
1146
- document.addEventListener("submit", (e) => {
1147
- const form = e.target;
1148
- const name = form.getAttribute("name");
1149
- if (!name || !main$2.contains(form) || !forms.some((f) => f.form === form)) return;
1150
- if (api$1.listeners().some((l) => l.type === name || l.type === null)) return;
1151
- const sent = new MutationObserver(() => {
1152
- if (form.dataset.wpState === "sending") return;
1153
- sent.disconnect();
1154
- if (form.dataset.wpState !== "sent") return;
1155
- api$1.toast("Sent · nobody listening", {
1156
- kind: "warn",
1157
- name: "sent",
1158
- details: "Your answer stays in the log until someone listens on this page."
1159
- });
1160
- });
1161
- sent.observe(form, {
1162
- attributes: true,
1163
- attributeFilter: ["data-wp-state"]
1164
- });
1165
- }, { capture: true });
1166
1194
  }
1167
1195
  // src/client/page/live.ts
1168
1196
  /** A button that copies an agent's id, a check for a moment once it did. */
@@ -1743,11 +1771,11 @@ function trackHeadingLinks(main) {
1743
1771
  });
1744
1772
  }
1745
1773
  // src/client/read.ts
1746
- let isMessage$1 = () => false;
1774
+ let messages = /* @__PURE__ */ new Map();
1747
1775
  let getEvents = () => [];
1748
1776
  let chats = () => null;
1749
1777
  const sending = /* @__PURE__ */ new Set();
1750
- const unread = () => unreadMessages(getEvents(), isMessage$1, chats()).filter((e) => !sending.has(e.id));
1778
+ const unread = () => unreadMessages(getEvents(), messages, chats()).filter((e) => !sending.has(e.id));
1751
1779
  /**
1752
1780
  * The chats the page's content shows, by name: the one under every form and each chat block; null
1753
1781
  * while there is no page content (a folder, raw text), when every chat's messages count.