@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/dist/src/server.js
CHANGED
|
@@ -8,7 +8,7 @@ import { describeRoutes, dispatch, mountRoutes, pluginCommands, usage } from "./
|
|
|
8
8
|
import { createAuth, sameSite } from "./auth.js";
|
|
9
9
|
import { accept, refuse } from "./ws.js";
|
|
10
10
|
import { FROM_SOURCE, PACKAGE_DIR, VERSION } from "./package.js";
|
|
11
|
-
import { SCROLL, SUBSCRIBE, agentMessagesIn, awaiting, handledIds, isAgentMessage, namesOf, projectStatus,
|
|
11
|
+
import { SCROLL, SUBSCRIBE, agentLabel, agentMessagesIn, awaiting, handledIds, isAgentMessage, namesOf, projectStatus, receivers, refusal, subscriptions } from "./status.js";
|
|
12
12
|
import { formsIn, messageForms } from "./pages/markdown.js";
|
|
13
13
|
import { fileFilter } from "./files.js";
|
|
14
14
|
import { titleOf } from "./pages/render.js";
|
|
@@ -22,6 +22,13 @@ import fs from "node:fs";
|
|
|
22
22
|
import path from "node:path";
|
|
23
23
|
import crypto from "node:crypto";
|
|
24
24
|
// src/server.ts
|
|
25
|
+
/**
|
|
26
|
+
* Watch a project's files folder by folder (each that can hold something shown, at any depth), not
|
|
27
|
+
* a recursive watch per top-level folder: where a recursive watch costs a watch per folder below
|
|
28
|
+
* it, whatever it holds (Linux's inotify). `$WORKPAD_WATCH`: `folders` or `recursive`, else by
|
|
29
|
+
* platform. See setFiles.
|
|
30
|
+
*/
|
|
31
|
+
const WATCH_BY_FOLDER = process.env.WORKPAD_WATCH ? process.env.WORKPAD_WATCH === "folders" : process.platform !== "darwin" && process.platform !== "win32";
|
|
25
32
|
const ENGINE_DIR = PACKAGE_DIR;
|
|
26
33
|
const MIME = {
|
|
27
34
|
".css": "text/css",
|
|
@@ -45,6 +52,8 @@ const MIME = {
|
|
|
45
52
|
".csv": "text/csv; charset=utf-8",
|
|
46
53
|
".html": "text/html; charset=utf-8"
|
|
47
54
|
};
|
|
55
|
+
/** How many of the browser's latest events the server knows by id, to answer a retried send with the first. */
|
|
56
|
+
const APPENDED_KEPT = 1e3;
|
|
48
57
|
const OWN_FILES = /* @__PURE__ */ new Set([
|
|
49
58
|
"events.ndjson",
|
|
50
59
|
"server.json",
|
|
@@ -61,7 +70,7 @@ const API_LISTS = [
|
|
|
61
70
|
"subscriptions",
|
|
62
71
|
"agents"
|
|
63
72
|
];
|
|
64
|
-
function createServer(project, { base = "", entry, label, name, files: filesOption, filesDefault, overview, onChange, origins = () => [] } = {}) {
|
|
73
|
+
function createServer(project, { base = "", entry, label, name, files: filesOption, filesDefault, watchByFolder = WATCH_BY_FOLDER, overview, onChange, origins = () => [] } = {}) {
|
|
65
74
|
const projectName = () => name ?? project.name;
|
|
66
75
|
const loader = createConfigLoader(project, { files: filesDefault });
|
|
67
76
|
const auth = createAuth(project.wp, base, origins);
|
|
@@ -118,7 +127,8 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
118
127
|
const notices = [...rendered.notices];
|
|
119
128
|
const parts = await pluginParts(await pluginHooks(), req, {
|
|
120
129
|
asset,
|
|
121
|
-
messages:
|
|
130
|
+
messages: Object.fromEntries((await config()).forReader),
|
|
131
|
+
handedOut: [...(await config()).handedOut],
|
|
122
132
|
failed: (message) => {
|
|
123
133
|
console.error(message);
|
|
124
134
|
notices.push(message);
|
|
@@ -289,7 +299,7 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
289
299
|
events,
|
|
290
300
|
listeners: listenersFor,
|
|
291
301
|
forAgent: forAgent(handedOut),
|
|
292
|
-
forReader
|
|
302
|
+
forReader
|
|
293
303
|
});
|
|
294
304
|
}
|
|
295
305
|
/** Per page, below `only` when given: what `workpad status` and the hooks report (see snapshot). */
|
|
@@ -586,8 +596,12 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
586
596
|
};
|
|
587
597
|
}
|
|
588
598
|
const clients = /* @__PURE__ */ new Set();
|
|
589
|
-
/**
|
|
590
|
-
|
|
599
|
+
/**
|
|
600
|
+
* what the browser appended lately, by id: a send it retries is answered with what it got. From
|
|
601
|
+
* the log at the start, so a retry that comes after a restart (the first try got in, its answer
|
|
602
|
+
* didn't get out) is no second answer either.
|
|
603
|
+
*/
|
|
604
|
+
const appended = new Map(readEvents(project.eventsFile).filter((e) => !e.from).slice(-1e3).map((e) => [e.id, e]));
|
|
591
605
|
function notify(client, kind) {
|
|
592
606
|
client.pending ??= /* @__PURE__ */ new Set();
|
|
593
607
|
if (client.pending.size === 0) setTimeout(() => {
|
|
@@ -638,15 +652,24 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
638
652
|
let FILES = null;
|
|
639
653
|
let FILTER = fileFilter();
|
|
640
654
|
let projectWatchers = /* @__PURE__ */ new Map();
|
|
655
|
+
let watchRound = 0;
|
|
641
656
|
function setFiles(files, filter = fileFilter()) {
|
|
642
657
|
if (files === FILES && filter.key === FILTER.key) return;
|
|
643
658
|
FILES = files;
|
|
644
659
|
FILTER = filter;
|
|
660
|
+
const round = ++watchRound;
|
|
645
661
|
for (const w of projectWatchers.values()) {
|
|
646
662
|
w.close();
|
|
647
663
|
watchers.delete(w);
|
|
648
664
|
}
|
|
649
665
|
projectWatchers = /* @__PURE__ */ new Map();
|
|
666
|
+
const drop = (key) => {
|
|
667
|
+
for (const [k, w] of projectWatchers) if (k === key || k.startsWith(key + "/")) {
|
|
668
|
+
w.close();
|
|
669
|
+
watchers.delete(w);
|
|
670
|
+
projectWatchers.delete(k);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
650
673
|
const add = (key, dir, recursive, prefix) => {
|
|
651
674
|
try {
|
|
652
675
|
const w = fs.watch(dir, { recursive }, (evt, filename) => {
|
|
@@ -654,32 +677,41 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
654
677
|
const name = filename.toString().replace(/\\/g, "/");
|
|
655
678
|
fileChanged(prefix + name);
|
|
656
679
|
if (!recursive && evt === "rename") {
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
watchers.delete(old);
|
|
661
|
-
projectWatchers.delete(name);
|
|
662
|
-
}
|
|
663
|
-
watchFolder(name);
|
|
680
|
+
const child = prefix + name;
|
|
681
|
+
drop(child);
|
|
682
|
+
watchFolder(child);
|
|
664
683
|
}
|
|
665
684
|
});
|
|
666
|
-
w.on("error", () =>
|
|
667
|
-
w.close();
|
|
668
|
-
watchers.delete(w);
|
|
669
|
-
projectWatchers.delete(key);
|
|
670
|
-
});
|
|
685
|
+
w.on("error", () => drop(key));
|
|
671
686
|
projectWatchers.set(key, w);
|
|
672
687
|
watchers.add(w);
|
|
673
688
|
} catch {}
|
|
674
689
|
};
|
|
675
|
-
const
|
|
676
|
-
if (projectWatchers.has(name) || name.includes("/") || name !== ".workpad" && !FILTER.mayHold(name)) return;
|
|
677
|
-
const dir = path.join(project.dir, name);
|
|
678
|
-
let isDir = false;
|
|
690
|
+
const isDir = (dir) => {
|
|
679
691
|
try {
|
|
680
|
-
|
|
681
|
-
} catch {
|
|
682
|
-
|
|
692
|
+
return fs.statSync(dir).isDirectory();
|
|
693
|
+
} catch {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
const watchFolder = (rel) => {
|
|
698
|
+
if (round !== watchRound || projectWatchers.has(rel)) return;
|
|
699
|
+
if (rel !== ".workpad" && !FILTER.mayHold(rel)) return;
|
|
700
|
+
if (!!rel.includes("/") && !watchByFolder) return;
|
|
701
|
+
const dir = path.join(project.dir, rel);
|
|
702
|
+
if (!isDir(dir)) return;
|
|
703
|
+
if (rel === ".workpad" || !watchByFolder) return add(rel, dir, true, rel + "/");
|
|
704
|
+
add(rel, dir, false, rel + "/");
|
|
705
|
+
walk(rel);
|
|
706
|
+
};
|
|
707
|
+
const walk = async (rel) => {
|
|
708
|
+
let ents;
|
|
709
|
+
try {
|
|
710
|
+
ents = await fs.promises.readdir(path.join(project.dir, rel), { withFileTypes: true });
|
|
711
|
+
} catch {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
for (const ent of ents) if (ent.isDirectory()) watchFolder(rel ? `${rel}/${ent.name}` : ent.name);
|
|
683
715
|
};
|
|
684
716
|
if (!files) return add(".workpad", project.wp, true, ".workpad/");
|
|
685
717
|
add("", project.dir, false, "");
|
|
@@ -847,9 +879,11 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
847
879
|
if (!body.type) return sendJson(res, 400, { error: "event type required" });
|
|
848
880
|
const again = isEventId(body.id) ? appended.get(body.id) : void 0;
|
|
849
881
|
if (again) return sendJson(res, 200, again);
|
|
882
|
+
const refused = refusal(body.type, body.data, (await config()).requires);
|
|
883
|
+
if (refused) return sendJson(res, 400, { error: refused });
|
|
850
884
|
const event = appendEvent(project.eventsFile, body);
|
|
851
885
|
appended.set(event.id, event);
|
|
852
|
-
if (appended.size >
|
|
886
|
+
if (appended.size > APPENDED_KEPT) appended.delete(appended.keys().next().value);
|
|
853
887
|
return sendJson(res, 200, event);
|
|
854
888
|
}
|
|
855
889
|
if (p === "/api/scroll" && req.method === "POST") {
|
|
@@ -963,16 +997,20 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
963
997
|
}
|
|
964
998
|
if (p === "/api/events") {
|
|
965
999
|
const all = after(readEvents(project.eventsFile), q.since);
|
|
966
|
-
const received =
|
|
1000
|
+
const received = receivers(all);
|
|
967
1001
|
const handled = handledIds(all);
|
|
968
1002
|
return sendJson(res, 200, all.filter((e) => matches(e, {
|
|
969
1003
|
...q,
|
|
970
1004
|
type: null
|
|
971
|
-
}) && matchesQuery(e, q)).map((e) =>
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1005
|
+
}) && matchesQuery(e, q)).map((e) => {
|
|
1006
|
+
const by = received.get(e.id);
|
|
1007
|
+
return {
|
|
1008
|
+
...e,
|
|
1009
|
+
...received.has(e.id) && { received: true },
|
|
1010
|
+
...by && { receivedBy: agentLabel(by, names) },
|
|
1011
|
+
...handled.has(e.id) && { handled: true }
|
|
1012
|
+
};
|
|
1013
|
+
}));
|
|
976
1014
|
}
|
|
977
1015
|
if (p === "/api/docs") return sendJson(res, 200, await docs());
|
|
978
1016
|
if (p === "/api/status") return sendJson(res, 200, await status(q.page || null));
|
package/dist/src/set.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { parseMarkdown, slug, titleWords } from "./pages/markdown.js";
|
|
2
|
+
import { hashOf, slugText } from "./anchors.js";
|
|
3
|
+
import { edit } from "./migrate.js";
|
|
4
|
+
import { toString } from "mdast-util-to-string";
|
|
5
|
+
// src/set.ts
|
|
6
|
+
const start = (n) => n.position.start.offset;
|
|
7
|
+
const end = (n) => n.position.end.offset;
|
|
8
|
+
/** Directives that are named even without a name: a form or chat without one is `form`, `chat`. */
|
|
9
|
+
const NAMED_BY_TYPE = /* @__PURE__ */ new Set(["form", "chat"]);
|
|
10
|
+
/**
|
|
11
|
+
* The blocks of a page's source, in source order, named as the page's anchors name them: headings
|
|
12
|
+
* (numbered on a repeat, as the page does), and container or leaf directives with a name (its
|
|
13
|
+
* `name` or `id`), a label (its slug), or of a type named by itself (a form or chat without a name).
|
|
14
|
+
* A repeat of a directive's id is numbered (`details:why-1`), as a details' is on the page.
|
|
15
|
+
*/
|
|
16
|
+
function blocksOf(source) {
|
|
17
|
+
const tree = parseMarkdown(source);
|
|
18
|
+
const out = [];
|
|
19
|
+
const headings = /* @__PURE__ */ new Map();
|
|
20
|
+
const taken = /* @__PURE__ */ new Map();
|
|
21
|
+
const walk = (parent) => {
|
|
22
|
+
const kids = parent.children ?? [];
|
|
23
|
+
kids.forEach((node, i) => {
|
|
24
|
+
if (node.type === "heading" && node.position) {
|
|
25
|
+
const id = slug(titleWords(node.children ?? [], () => true), headings);
|
|
26
|
+
let last = node;
|
|
27
|
+
for (const next of kids.slice(i + 1)) {
|
|
28
|
+
if (next.type === "heading" && next.depth <= node.depth) break;
|
|
29
|
+
last = next;
|
|
30
|
+
}
|
|
31
|
+
if (id && !id.startsWith("wp-")) out.push({
|
|
32
|
+
id,
|
|
33
|
+
kind: "heading",
|
|
34
|
+
from: start(node),
|
|
35
|
+
to: end(last)
|
|
36
|
+
});
|
|
37
|
+
} else if ((node.type === "containerDirective" || node.type === "leafDirective") && node.position) {
|
|
38
|
+
const attrs = node.attributes ?? {};
|
|
39
|
+
const label = node.type === "containerDirective" && node.children?.[0]?.data?.directiveLabel ? node.children[0] : null;
|
|
40
|
+
const labelText = label ? slugText(node.name === "details" ? toString(label) : titleWords(label.children ?? [], () => true)) : "";
|
|
41
|
+
const name = attrs.name || attrs.id || (NAMED_BY_TYPE.has(node.name) ? node.name : labelText);
|
|
42
|
+
if (name) {
|
|
43
|
+
const base = `${node.name}:${name}`;
|
|
44
|
+
let id = base;
|
|
45
|
+
if (taken.has(base)) {
|
|
46
|
+
let n = taken.get(base);
|
|
47
|
+
do
|
|
48
|
+
id = `${base}-${++n}`;
|
|
49
|
+
while (taken.has(id));
|
|
50
|
+
taken.set(base, n);
|
|
51
|
+
}
|
|
52
|
+
taken.set(id, 0);
|
|
53
|
+
out.push({
|
|
54
|
+
id,
|
|
55
|
+
kind: node.name,
|
|
56
|
+
from: start(node),
|
|
57
|
+
to: end(node)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
walk(node);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
walk(tree);
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** `name` as a link writes it, or as typed: `#form:logger`, `form:logger`, `form%3Alogger`. */
|
|
68
|
+
function normalize(name) {
|
|
69
|
+
let id = name.trim().replace(/^#/, "");
|
|
70
|
+
try {
|
|
71
|
+
id = decodeURIComponent(id);
|
|
72
|
+
} catch {}
|
|
73
|
+
return id;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The block `name` names: its anchor (`form:logger`, `open-questions`), or a block's bare name
|
|
77
|
+
* (`logger` for `form:logger`) when only one block has it. Throws, listing the page's blocks, when
|
|
78
|
+
* none does, or when the bare name fits several.
|
|
79
|
+
*/
|
|
80
|
+
function findBlock(source, name) {
|
|
81
|
+
const blocks = blocksOf(source);
|
|
82
|
+
const id = normalize(name);
|
|
83
|
+
const exact = name.trim().startsWith("#");
|
|
84
|
+
const fits = blocks.filter((b) => b.id === id || !exact && b.id === `${b.kind}:${id}`);
|
|
85
|
+
if (fits.length === 1) return fits[0];
|
|
86
|
+
const list = (bs) => bs.map((b) => ` ${hashOf(b.id)} ${b.kind}`).join("\n");
|
|
87
|
+
if (fits.length > 1) throw new Error(`${id} fits ${fits.length} blocks; name one by its anchor, with its #:\n${list(fits)}`);
|
|
88
|
+
throw new Error(`no block ${hashOf(id)} on the page${blocks.length ? `; it has:\n${list(blocks)}` : ", nor any other with a name"}`);
|
|
89
|
+
}
|
|
90
|
+
/** `source` with the block `name` names replaced by `markdown` (its trailing blank lines left off). */
|
|
91
|
+
function setBlock(source, name, markdown) {
|
|
92
|
+
const block = findBlock(source, name);
|
|
93
|
+
return edit(source, [{
|
|
94
|
+
from: block.from,
|
|
95
|
+
to: block.to,
|
|
96
|
+
text: markdown.replace(/\s+$/, "")
|
|
97
|
+
}]);
|
|
98
|
+
}
|
|
99
|
+
export { blocksOf, findBlock, setBlock };
|
package/dist/src/status.js
CHANGED
|
@@ -75,20 +75,45 @@ const READ = "workpad:read";
|
|
|
75
75
|
*/
|
|
76
76
|
const SCROLL = "workpad:scroll";
|
|
77
77
|
/**
|
|
78
|
-
* The
|
|
79
|
-
*
|
|
80
|
-
* replaced by a later one (`replaces`), and, given the page's `chats`, not in a chat (`data.chat`)
|
|
81
|
-
* that is no longer among them.
|
|
78
|
+
* The fields of an event's `data` its type requires (EventSpec.requires) that it lacks: each must
|
|
79
|
+
* be a non-empty string.
|
|
82
80
|
*/
|
|
83
|
-
|
|
81
|
+
const missingData = (data, requires) => requires.filter((field) => {
|
|
82
|
+
const value = data?.[field];
|
|
83
|
+
return typeof value !== "string" || !value.trim();
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Why an event of `type` with this `data` can't go in the log, given the types that require data
|
|
87
|
+
* fields: what it lacks, and the shape it needs; null when nothing is missing.
|
|
88
|
+
*/
|
|
89
|
+
function refusal(type, data, requires) {
|
|
90
|
+
const fields = requires.get(type) ?? [];
|
|
91
|
+
const missing = missingData(data, fields);
|
|
92
|
+
if (!missing.length) return null;
|
|
93
|
+
const list = (names) => names.join(names.length > 2 ? ", " : " and ").replace(/, (?=[^,]*$)/, " and ");
|
|
94
|
+
const shape = JSON.stringify(Object.fromEntries(fields.map((f) => [f, "…"])));
|
|
95
|
+
return `a ${type} needs ${list(fields)} in its data, each a non-empty string; ${list(missing)} ${missing.length > 1 ? "are" : "is"} missing or empty. Its data: ${shape}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The agent's messages on a page the reader hasn't read: events from the agent of a type in
|
|
99
|
+
* `messages` (the types for the reader, each with the `data` fields it requires), not named by a
|
|
100
|
+
* `workpad:read` from the reader, not replaced by a later one (`replaces`), with the data their
|
|
101
|
+
* type requires (one without it shows nowhere on the page, so it waits for nobody), and, given the
|
|
102
|
+
* page's `chats`, not in a chat (`data.chat`) that is no longer among them.
|
|
103
|
+
*/
|
|
104
|
+
function unreadMessages(events, messages, chats) {
|
|
84
105
|
const read = /* @__PURE__ */ new Set();
|
|
85
106
|
const replaced = /* @__PURE__ */ new Set();
|
|
86
107
|
for (const e of events) {
|
|
87
108
|
if (e.type === "workpad:read" && fromReader(e)) for (const id of e.data?.ids ?? []) read.add(String(id));
|
|
88
109
|
if (e.data?.replaces) replaced.add(String(e.data.replaces));
|
|
89
110
|
}
|
|
111
|
+
const shown = (e) => {
|
|
112
|
+
const requires = messages.get(e.type);
|
|
113
|
+
return !!requires && !missingData(e.data, requires).length;
|
|
114
|
+
};
|
|
90
115
|
const offPage = (e) => !!chats && typeof e.data?.chat === "string" && !chats.has(e.data.chat);
|
|
91
|
-
return events.filter((e) => !fromReader(e) &&
|
|
116
|
+
return events.filter((e) => !fromReader(e) && shown(e) && !read.has(e.id) && !replaced.has(e.id) && !offPage(e));
|
|
92
117
|
}
|
|
93
118
|
/** How many things on a page wait for the reader: its open questions and unread messages. */
|
|
94
119
|
const awaiting = (p) => p.open.length + p.unread.length;
|
|
@@ -149,6 +174,20 @@ function namesOf(events) {
|
|
|
149
174
|
for (const e of events) if (e.type === "workpad:name" && e.from === "cli" && e.by && typeof e.data?.name === "string") names.set(e.by, e.data.name);
|
|
150
175
|
return names;
|
|
151
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Who received each answer first, by its id: the `by` of the first RECEIVED naming it (null when
|
|
179
|
+
* the command line knew no one). Only the command line's marks count.
|
|
180
|
+
*/
|
|
181
|
+
function receivers(events) {
|
|
182
|
+
const by = /* @__PURE__ */ new Map();
|
|
183
|
+
for (const e of events) if (e.type === "workpad:received" && !fromReader(e)) {
|
|
184
|
+
const id = String(e.data?.event);
|
|
185
|
+
if (!by.has(id)) by.set(id, e.by ?? null);
|
|
186
|
+
}
|
|
187
|
+
return by;
|
|
188
|
+
}
|
|
189
|
+
/** An agent as a page names it: the name it gave itself (`names`), else its id, a long one (a session's) cut short. */
|
|
190
|
+
const agentLabel = (id, names = /* @__PURE__ */ new Map()) => names.get(id) ?? (id.length > 16 ? id.slice(0, 8) : id);
|
|
152
191
|
/** The ids of the answers a wait or watch printed. Only the command line's marks count. */
|
|
153
192
|
function receivedIds(events) {
|
|
154
193
|
return new Set(events.filter((e) => e.type === "workpad:received" && !fromReader(e)).map((e) => String(e.data?.event)));
|
|
@@ -315,7 +354,7 @@ function statusLines(p, file, { waiting = true } = {}) {
|
|
|
315
354
|
* Who is subscribed to a page, said to `me`: `you` among them, the others by the name they gave
|
|
316
355
|
* themselves (`names`), else their id, a long one (a session's) cut short.
|
|
317
356
|
*/
|
|
318
|
-
const whose = (p, me, names = /* @__PURE__ */ new Map()) => p.subscribers.length ? p.subscribers.map((s) => s === me ? "you" :
|
|
357
|
+
const whose = (p, me, names = /* @__PURE__ */ new Map()) => p.subscribers.length ? p.subscribers.map((s) => s === me ? "you" : agentLabel(s, names)).join(", ") : "no one subscribed";
|
|
319
358
|
/** The type of a chat message: `{ chat, text }` (the chat plugin's; the core shows the agent's as small pages). */
|
|
320
359
|
const CHAT_MESSAGE = "chat:message";
|
|
321
360
|
/** Is this a chat message of the agent's, which shows as a small page (forms and all)? */
|
|
@@ -329,4 +368,4 @@ function agentMessagesIn(events, page, chat) {
|
|
|
329
368
|
const replaced = new Set(own.map((e) => e.data.replaces).filter(Boolean).map(String));
|
|
330
369
|
return own.filter((e) => !replaced.has(e.id));
|
|
331
370
|
}
|
|
332
|
-
export { CHAT_MESSAGE, HANDLED, HOLD, NAME, READ, RECEIVED, RELEASE, SCROLL, SETTLE, SUBSCRIBE, UNSUBSCRIBE, agentMessagesIn, awaiting, awaitingReply, channelSince, covers, fromReader, handledIds, heard, holdOf, isAgentMessage, isQuestionName, namesOf, projectStatus, questionState, receivedIds, settleNested, statusLines, subscriptions, takesUnfollowed, unreadMessages, whose };
|
|
371
|
+
export { CHAT_MESSAGE, HANDLED, HOLD, NAME, READ, RECEIVED, RELEASE, SCROLL, SETTLE, SUBSCRIBE, UNSUBSCRIBE, agentLabel, agentMessagesIn, awaiting, awaitingReply, channelSince, covers, fromReader, handledIds, heard, holdOf, isAgentMessage, isQuestionName, missingData, namesOf, projectStatus, questionState, receivedIds, receivers, refusal, settleNested, statusLines, subscriptions, takesUnfollowed, unreadMessages, whose };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigmistqke/workpad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "A workpad for you and your agent: it writes markdown pages you read live in the browser, you answer through forms it waits on",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -89,6 +89,11 @@
|
|
|
89
89
|
"source": "./plugins/badge/index.ts",
|
|
90
90
|
"types": "./plugins/badge/index.ts",
|
|
91
91
|
"default": "./dist/plugins/badge/index.js"
|
|
92
|
+
},
|
|
93
|
+
"./progress": {
|
|
94
|
+
"source": "./plugins/progress/index.ts",
|
|
95
|
+
"types": "./plugins/progress/index.ts",
|
|
96
|
+
"default": "./dist/plugins/progress/index.js"
|
|
92
97
|
}
|
|
93
98
|
},
|
|
94
99
|
"files": [
|
package/plugins/README.md
CHANGED
|
@@ -147,7 +147,9 @@ export default function mount(root, page, api) {
|
|
|
147
147
|
`compose` attribute, that block's HTML as `ctx.children` (see below).
|
|
148
148
|
- **`events`**, by type (`<plugin>:<what>`): a description each, and
|
|
149
149
|
`handOut: true` for those an agent should get unasked, like a chat
|
|
150
|
-
message
|
|
150
|
+
message, and `requires: ['chat', 'text']` for the `data` fields one can't
|
|
151
|
+
be without (each a non-empty string): `workpad append` and the API refuse
|
|
152
|
+
an event that lacks one. `workpad docs` lists them.
|
|
151
153
|
- **`style`**: a stylesheet on every page.
|
|
152
154
|
- **`docs`**: markdown for agents: how to write its blocks, what its events
|
|
153
155
|
mean, how to answer.
|
package/plugins/chat/README.md
CHANGED
|
@@ -19,7 +19,7 @@ its answers are events of that type, and a link to it is
|
|
|
19
19
|
chat. A form on the page can't have a `/` in its name.
|
|
20
20
|
|
|
21
21
|
To rework a message (an option more, a typo), edit it in place:
|
|
22
|
-
`workpad edit <its id> --
|
|
22
|
+
`workpad edit <its id> --text-file -` with the new text on standard input. It updates in the reader's
|
|
23
23
|
tab, marked new until they've seen it, and a form in it that keeps its name
|
|
24
24
|
keeps its answers.
|
|
25
25
|
|
|
@@ -41,10 +41,14 @@ message `#message:<its event id>`; a folded form's chat opens for it.
|
|
|
41
41
|
|
|
42
42
|
A message is a `chat:message` event, `{ "chat": "<name>", "text": "…" }`,
|
|
43
43
|
never an answer: under a form it never makes a choice (only the reader can,
|
|
44
|
-
with a message of yours marked `answer`, below). Answer in the same chat
|
|
44
|
+
with a message of yours marked `answer`, below). Answer in the same chat, the
|
|
45
|
+
text from standard input (a quoted heredoc: no shell quoting in the markdown)
|
|
46
|
+
or a file (`--text-file reply.md`):
|
|
45
47
|
|
|
46
48
|
```sh
|
|
47
|
-
workpad append --page <file> --type chat:message --data '{"chat":"<name>"
|
|
49
|
+
workpad append --page <file> --type chat:message --data '{"chat":"<name>"}' --text-file - <<'EOF'
|
|
50
|
+
your answer, in markdown
|
|
51
|
+
EOF
|
|
48
52
|
```
|
|
49
53
|
|
|
50
54
|
Two more fields, both optional:
|
package/plugins/chat/client.tsx
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// is a `chat:message` event, never an answer, so talking about a form's choice never makes it. But
|
|
4
4
|
// under a form, an agent's message marked `answer` has a button that answers the form with its
|
|
5
5
|
// text, for an answer the two settled on in the chat that is none of the form's options.
|
|
6
|
-
import { createEffect, createMemo, For, Loading } from 'solid-js'
|
|
6
|
+
import { createEffect, createMemo, For, Loading, Show } from 'solid-js'
|
|
7
7
|
import { solid, useWorkpad } from '@bigmistqke/workpad/solid'
|
|
8
8
|
import type { ChatProps } from './index'
|
|
9
|
-
import type { WpEvent } from '@bigmistqke/workpad'
|
|
9
|
+
import type { Delivery, WpEvent } from '@bigmistqke/workpad'
|
|
10
10
|
import { autosize } from './autosize'
|
|
11
11
|
|
|
12
12
|
/** A message in a chat: the chat block's own event type. */
|
|
@@ -20,6 +20,8 @@ interface Message {
|
|
|
20
20
|
sending?: boolean
|
|
21
21
|
/** the agent's message as it is in the log: it shows as a small page (Api.message) */
|
|
22
22
|
event?: WpEvent
|
|
23
|
+
/** the reader's message: where it went, said under it (see `messages`) */
|
|
24
|
+
delivery?: Delivery
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -63,7 +65,15 @@ function Chat(props: ChatProps) {
|
|
|
63
65
|
event: e.from === 'cli' ? e : undefined,
|
|
64
66
|
})
|
|
65
67
|
}
|
|
66
|
-
|
|
68
|
+
// Where the reader's messages went, said quietly under the one it is about: their latest, while
|
|
69
|
+
// the agent hasn't answered after it (an answer says it all), and any no agent received for long
|
|
70
|
+
const delivery = wp.delivery()
|
|
71
|
+
const lastAgent = out.findLastIndex(m => m.from === 'agent')
|
|
72
|
+
const lastOwn = out.findLastIndex(m => m.from === 'you' && !m.sending)
|
|
73
|
+
return out.map((m, i) => {
|
|
74
|
+
const d = m.from === 'you' && !m.sending ? delivery.get(m.id) : undefined
|
|
75
|
+
return d && (d.state === 'late' || (i === lastOwn && i > lastAgent)) ? { ...m, delivery: d } : m
|
|
76
|
+
})
|
|
67
77
|
})
|
|
68
78
|
let box: HTMLTextAreaElement | undefined
|
|
69
79
|
// what the reader is typing, kept until it is sent: a reload, the page's tab sent elsewhere or the
|
|
@@ -135,6 +145,13 @@ function Chat(props: ChatProps) {
|
|
|
135
145
|
>
|
|
136
146
|
<span class="wp-chat-who">{m().from}</span>
|
|
137
147
|
<Bubble text={m().text} event={m().event} />
|
|
148
|
+
<Show when={m().delivery}>
|
|
149
|
+
{d => (
|
|
150
|
+
<span class="wp-chat-delivery" role="status" data-wp-delivery={d().state}>
|
|
151
|
+
{d().text}
|
|
152
|
+
</span>
|
|
153
|
+
)}
|
|
154
|
+
</Show>
|
|
138
155
|
</div>
|
|
139
156
|
)}
|
|
140
157
|
</For>
|
package/plugins/chat/index.ts
CHANGED
|
@@ -100,6 +100,7 @@ export default function chatPlugin({ page: pageChat = true }: ChatOptions = {}):
|
|
|
100
100
|
'chat:message': {
|
|
101
101
|
handOut: true,
|
|
102
102
|
forReader: true,
|
|
103
|
+
requires: ['chat', 'text'],
|
|
103
104
|
description: 'a message in a chat: `{ chat, text }`, and `replaces` or `replyTo` (see below)',
|
|
104
105
|
},
|
|
105
106
|
},
|
|
@@ -69,6 +69,16 @@
|
|
|
69
69
|
.wp-chat-message[data-from='agent'] .wp-chat-who {
|
|
70
70
|
color: var(--accent);
|
|
71
71
|
}
|
|
72
|
+
/* where the reader's message went (api.delivery), quietly under it; not received for long: the warning colour */
|
|
73
|
+
.wp-chat-delivery {
|
|
74
|
+
padding: 0 var(--space-xs);
|
|
75
|
+
font: var(--ui-tiny)/1.3 var(--sans);
|
|
76
|
+
color: var(--muted);
|
|
77
|
+
}
|
|
78
|
+
.wp-chat-delivery[data-wp-delivery='late'] {
|
|
79
|
+
color: var(--warn);
|
|
80
|
+
font-weight: var(--weight-strong);
|
|
81
|
+
}
|
|
72
82
|
.wp-chat-bubble {
|
|
73
83
|
max-width: 100%;
|
|
74
84
|
min-width: 0;
|
|
@@ -45,9 +45,14 @@ export async function channel(ctx: CommandContext) {
|
|
|
45
45
|
const claude = claudeProcess()
|
|
46
46
|
const started = process.env.CLAUDE_CODE_SESSION_ID || null
|
|
47
47
|
let session: string | null = null
|
|
48
|
+
// every id the process's conversation went by: the sessions before a resume or a clear, and the
|
|
49
|
+
// session beside WORKPAD_AGENT. What any of them wrote is the agent's own, never pushed to it
|
|
50
|
+
const selves = new Set<string>()
|
|
48
51
|
/** The conversation now, and a line in the log when it changed after start (a resume). */
|
|
49
52
|
const current = () => {
|
|
50
|
-
const
|
|
53
|
+
const raw = recordedSession(ctx.dataDir, claude) ?? started
|
|
54
|
+
const now = identity(raw)
|
|
55
|
+
for (const id of [raw, now]) if (id) selves.add(id)
|
|
51
56
|
if (now !== session) {
|
|
52
57
|
if (!now) problem('no CLAUDE_CODE_SESSION_ID: no pages to follow')
|
|
53
58
|
else if (now !== started || session) problem('following another session than at start', { started, now })
|
|
@@ -80,8 +85,11 @@ export async function channel(ctx: CommandContext) {
|
|
|
80
85
|
})
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
// Each page followed on its own, so another session's answers are never handed out here
|
|
88
|
+
// Each page followed on its own, so another session's answers are never handed out here; as the
|
|
89
|
+
// session it is followed for, until that moves on (a resume, a clear): then its pages are let go,
|
|
90
|
+
// and the new session's followed as its own
|
|
84
91
|
const followed = new Set<string>()
|
|
92
|
+
let followedFor: { session: string; stop: AbortController } | null = null
|
|
85
93
|
// the pages no one follows, when the session took them on (`workpad listen --unfollowed --channel`)
|
|
86
94
|
let unfollowed: { session: string; stop: AbortController } | null = null
|
|
87
95
|
const takeUnfollowed = (session: string) => {
|
|
@@ -110,17 +118,23 @@ export async function channel(ctx: CommandContext) {
|
|
|
110
118
|
hold(session)
|
|
111
119
|
if (!confirmed || !session) return
|
|
112
120
|
takeUnfollowed(session)
|
|
121
|
+
if (followedFor?.session !== session) {
|
|
122
|
+
followedFor?.stop.abort()
|
|
123
|
+
followed.clear()
|
|
124
|
+
followedFor = { session, stop: new AbortController() }
|
|
125
|
+
}
|
|
126
|
+
const { signal } = followedFor.stop
|
|
113
127
|
const pages = (await ctx.status()).filter(p => p.subscribers.includes(session)).map(p => p.page)
|
|
114
128
|
for (const page of pages) {
|
|
115
|
-
if (followed.has(page)) continue
|
|
129
|
+
if (followed.has(page) || signal.aborted) continue
|
|
116
130
|
followed.add(page)
|
|
117
|
-
await ctx.listen(page, { agent: session })
|
|
131
|
+
await ctx.listen(page, { agent: session, signal })
|
|
118
132
|
// received as it is sent: the agent confirmed that what this sends reaches it
|
|
119
133
|
const push = (e: WpEvent, again: boolean) => notify(answerLine(e, again), { page: e.page, id: e.id, type: e.type })
|
|
120
134
|
// a page taken on through the channel: what is new, not the past someone already received
|
|
121
135
|
const since = channelSince(read(ctx.eventsFile).events, session, page) ?? undefined
|
|
122
136
|
void ctx
|
|
123
|
-
.handOut({ page, exact: true }, push, { agent: session, skipReceivedBefore: since })
|
|
137
|
+
.handOut({ page, exact: true }, push, { agent: session, aliases: selves, skipReceivedBefore: since, signal })
|
|
124
138
|
.catch(err => problem('handing out failed', { page, err: String(err) }))
|
|
125
139
|
}
|
|
126
140
|
}
|
package/plugins/claude/doctor.ts
CHANGED
|
@@ -40,9 +40,15 @@ function readJson(file: string): { value: any; why?: string } | null {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* `$VAR`, `${VAR}` and `${VAR:-default}` in a command, its args or env as Claude Code expands them
|
|
45
|
+
* (the default when VAR is unset or empty); CLAUDE_PROJECT_DIR is the project.
|
|
46
|
+
*/
|
|
44
47
|
export function expand(s: string, env: Record<string, string | undefined>): string {
|
|
45
|
-
return s.replace(/\$\{(\w+)
|
|
48
|
+
return s.replace(/\$\{(\w+)(?::-([^}]*))?\}|\$(\w+)/g, (_, a, fallback, b) => {
|
|
49
|
+
const value = env[a ?? b]
|
|
50
|
+
return fallback !== undefined && !value ? fallback : (value ?? '')
|
|
51
|
+
})
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
/** Start the channel's command, ask it to initialize, and stop it: whether it answered, or why not. */
|
|
@@ -177,7 +183,9 @@ export async function channelChecks(
|
|
|
177
183
|
else if (mcp.value === undefined) lines.push({ mark: 'fail', text: `${mcpFile}: ${mcp.why}`, fix: 'fix the file' })
|
|
178
184
|
else if (!entry?.command) lines.push({ mark: 'fail', text: `${mcpFile} has no "${SERVER}" server`, fix: install })
|
|
179
185
|
else {
|
|
180
|
-
const
|
|
186
|
+
const base = { ...process.env, CLAUDE_PROJECT_DIR: dir }
|
|
187
|
+
const own = Object.entries((entry.env ?? {}) as Record<string, string>).map(([k, v]) => [k, expand(String(v), base)])
|
|
188
|
+
const env = { ...base, ...Object.fromEntries(own) }
|
|
181
189
|
const command = expand(entry.command, env)
|
|
182
190
|
const args = ((entry.args ?? []) as string[]).map(a => expand(a, env))
|
|
183
191
|
const why = await probe(command, args, dir, env)
|
|
@@ -21,7 +21,8 @@ page until the reader closes it. Answer a comment the way it asks:
|
|
|
21
21
|
- **It asks for a change:** edit the page. The thread stays, so say what you
|
|
22
22
|
changed in a reply if it is not obvious.
|
|
23
23
|
- **It asks a question:** reply in the thread:
|
|
24
|
-
`workpad append --page <file> --type comments:reply --data '{"replyTo":"<comment id>"
|
|
24
|
+
`workpad append --page <file> --type comments:reply --data '{"replyTo":"<comment id>"}' --text-file -`,
|
|
25
|
+
the reply's markdown on standard input
|
|
25
26
|
|
|
26
27
|
Your replies show as the agent's, and your own `listen` skips what you
|
|
27
28
|
append, so you don't hear your own replies. Comments and replies are
|