@bigmistqke/workpad 0.0.0-stage → 0.18.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/LICENSE +21 -0
- package/README.md +781 -2
- package/bin/workpad.ts +1509 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1190 -0
- package/dist/client/runtime.js +1194 -0
- package/dist/define.js +27 -0
- package/dist/plugins/alert/README.md +18 -0
- package/dist/plugins/alert/index.js +40 -0
- package/dist/plugins/alert/public/style.css +40 -0
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +63 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +32 -0
- package/dist/plugins/badge/index.js +28 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/README.md +81 -0
- package/dist/plugins/chat/index.js +96 -0
- package/dist/plugins/chat/public/client.js +3 -0
- package/dist/plugins/chat/public/style.css +143 -0
- package/dist/plugins/claude/README.md +116 -0
- package/dist/plugins/claude/channel.js +130 -0
- package/dist/plugins/claude/doctor.js +316 -0
- package/dist/plugins/claude/index.js +199 -0
- package/dist/plugins/claude/session.js +68 -0
- package/dist/plugins/code/README.md +54 -0
- package/dist/plugins/code/diff.js +75 -0
- package/dist/plugins/code/index.js +105 -0
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +99 -0
- package/dist/plugins/comments/README.md +30 -0
- package/dist/plugins/comments/index.js +39 -0
- package/dist/plugins/comments/public/client.js +24 -0
- package/dist/plugins/comments/public/style.css +224 -0
- package/dist/plugins/details/README.md +24 -0
- package/dist/plugins/details/index.js +28 -0
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +27 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/forge/README.md +22 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +126 -0
- package/dist/plugins/form/index.js +179 -0
- package/dist/plugins/form/public/style.css +172 -0
- package/dist/plugins/grid/README.md +45 -0
- package/dist/plugins/grid/index.js +35 -0
- package/dist/plugins/grid/public/style.css +98 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/index.js +49 -0
- package/dist/plugins/iframe/public/style.css +28 -0
- package/dist/plugins/index.js +44 -0
- package/dist/plugins/lightbox/README.md +24 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +42 -0
- package/dist/plugins/mermaid/public/style.css +21 -0
- package/dist/plugins/opencode/README.md +48 -0
- package/dist/plugins/opencode/channel.js +92 -0
- package/dist/plugins/opencode/index.js +64 -0
- package/dist/plugins/opencode/shim.js +150 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +23 -0
- package/dist/plugins/tabs/README.md +44 -0
- package/dist/plugins/tabs/index.js +75 -0
- package/dist/plugins/tabs/public/client.js +1 -0
- package/dist/plugins/tabs/public/style.css +98 -0
- package/dist/plugins/terminal/README.md +63 -0
- package/dist/plugins/terminal/host.js +338 -0
- package/dist/plugins/terminal/index.js +170 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/public/client.js +41 -0
- package/dist/plugins/terminal/public/style.css +511 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +58 -0
- package/dist/plugins/timeline/README.md +48 -0
- package/dist/plugins/timeline/index.js +83 -0
- package/dist/plugins/timeline/public/style.css +138 -0
- package/dist/plugins/toc/README.md +40 -0
- package/dist/plugins/toc/index.js +29 -0
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +117 -0
- package/dist/plugins/window/README.md +51 -0
- package/dist/plugins/window/index.js +91 -0
- package/dist/solid/index.js +41 -0
- package/dist/src/agents.js +81 -0
- package/dist/src/anchors.js +52 -0
- package/dist/src/api.js +282 -0
- package/dist/src/archive.js +49 -0
- package/dist/src/auth.js +67 -0
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +1762 -0
- package/dist/src/client/page/main.js +2098 -0
- package/dist/src/config.js +76 -0
- package/dist/src/document.js +93 -0
- package/dist/src/entries.js +264 -0
- package/dist/src/events.js +322 -0
- package/dist/src/files.js +47 -0
- package/dist/src/formstate.js +65 -0
- package/dist/src/help.js +211 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +341 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/listen.js +132 -0
- package/dist/src/listeners.js +64 -0
- package/dist/src/load.js +81 -0
- package/dist/src/loader.js +179 -0
- package/dist/src/migrate.js +314 -0
- package/dist/src/package.js +52 -0
- package/dist/src/pages/blocks.js +67 -0
- package/dist/src/pages/board.js +59 -0
- package/dist/src/pages/index.js +27 -0
- package/dist/src/pages/markdown.js +863 -0
- package/dist/src/pages/render.js +665 -0
- package/dist/src/pages/window.js +29 -0
- package/dist/src/plugins.js +283 -0
- package/dist/src/public.js +24 -0
- package/dist/src/rename.js +130 -0
- package/dist/src/running.js +146 -0
- package/dist/src/serve.js +188 -0
- package/dist/src/server.js +1105 -0
- package/dist/src/site.js +179 -0
- package/dist/src/state.js +155 -0
- package/dist/src/status.js +323 -0
- package/dist/src/thread.js +68 -0
- package/dist/src/watchdog.js +38 -0
- package/dist/src/ws.js +128 -0
- package/package.json +154 -4
- package/plugins/README.md +304 -0
- package/plugins/alert/README.md +18 -0
- package/plugins/alert/index.ts +50 -0
- package/plugins/alert/public/style.css +40 -0
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +32 -0
- package/plugins/badge/index.ts +36 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/README.md +81 -0
- package/plugins/chat/autosize.ts +139 -0
- package/plugins/chat/client.tsx +187 -0
- package/plugins/chat/index.ts +146 -0
- package/plugins/chat/public/style.css +143 -0
- package/plugins/claude/README.md +116 -0
- package/plugins/claude/channel.ts +136 -0
- package/plugins/claude/doctor.ts +274 -0
- package/plugins/claude/index.ts +248 -0
- package/plugins/claude/session.ts +70 -0
- package/plugins/code/README.md +54 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/diff.ts +96 -0
- package/plugins/code/index.ts +136 -0
- package/plugins/code/public/style.css +99 -0
- package/plugins/comments/README.md +30 -0
- package/plugins/comments/client.ts +723 -0
- package/plugins/comments/index.ts +48 -0
- package/plugins/comments/public/style.css +224 -0
- package/plugins/details/README.md +24 -0
- package/plugins/details/index.ts +30 -0
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/README.md +22 -0
- package/plugins/forge/index.ts +84 -0
- package/plugins/form/README.md +126 -0
- package/plugins/form/index.ts +199 -0
- package/plugins/form/public/style.css +172 -0
- package/plugins/grid/README.md +45 -0
- package/plugins/grid/index.ts +41 -0
- package/plugins/grid/public/style.css +98 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/index.ts +53 -0
- package/plugins/iframe/public/style.css +28 -0
- package/plugins/index.ts +49 -0
- package/plugins/lightbox/README.md +24 -0
- package/plugins/lightbox/client.ts +109 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +46 -0
- package/plugins/mermaid/public/style.css +21 -0
- package/plugins/opencode/README.md +48 -0
- package/plugins/opencode/channel.ts +112 -0
- package/plugins/opencode/index.ts +91 -0
- package/plugins/opencode/shim.ts +166 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +28 -0
- package/plugins/tabs/README.md +44 -0
- package/plugins/tabs/client.ts +96 -0
- package/plugins/tabs/index.ts +103 -0
- package/plugins/tabs/public/style.css +98 -0
- package/plugins/terminal/README.md +63 -0
- package/plugins/terminal/client.ts +391 -0
- package/plugins/terminal/host.ts +434 -0
- package/plugins/terminal/index.ts +199 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +266 -0
- package/plugins/terminal/sizes.ts +72 -0
- package/plugins/timeline/README.md +48 -0
- package/plugins/timeline/index.ts +82 -0
- package/plugins/timeline/public/style.css +138 -0
- package/plugins/toc/README.md +40 -0
- package/plugins/toc/client.ts +236 -0
- package/plugins/toc/index.ts +55 -0
- package/plugins/toc/public/style.css +117 -0
- package/plugins/window/README.md +51 -0
- package/plugins/window/index.ts +92 -0
- package/skills/workpad/SKILL.md +588 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +133 -0
- package/src/anchors.ts +85 -0
- package/src/api.ts +444 -0
- package/src/archive.ts +75 -0
- package/src/auth.ts +99 -0
- package/src/build.ts +213 -0
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +420 -0
- package/src/client/markdown.ts +147 -0
- package/src/client/page/base.css +1762 -0
- package/src/client/page/board.ts +137 -0
- package/src/client/page/elsewhere.ts +153 -0
- package/src/client/page/fresh.ts +343 -0
- package/src/client/page/heading-link.ts +32 -0
- package/src/client/page/live.ts +134 -0
- package/src/client/page/main.ts +398 -0
- package/src/client/page/orphans.ts +64 -0
- package/src/client/page/place.ts +260 -0
- package/src/client/page/sort.ts +49 -0
- package/src/client/page/sticky.ts +58 -0
- package/src/client/page/theme.ts +36 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +278 -0
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +111 -0
- package/src/client/runtime.ts +499 -0
- package/src/client/scroll.ts +90 -0
- package/src/client/toast.ts +99 -0
- package/src/config.ts +111 -0
- package/src/define.ts +997 -0
- package/src/document.ts +191 -0
- package/src/entries.ts +352 -0
- package/src/events.ts +463 -0
- package/src/files.ts +74 -0
- package/src/formstate.ts +72 -0
- package/src/help.ts +238 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +426 -0
- package/src/icons.ts +18 -0
- package/src/listen.ts +171 -0
- package/src/listeners.ts +89 -0
- package/src/load.ts +113 -0
- package/src/loader.ts +227 -0
- package/src/migrate.ts +352 -0
- package/src/package.ts +62 -0
- package/src/pages/blocks.ts +106 -0
- package/src/pages/board.ts +89 -0
- package/src/pages/index.ts +79 -0
- package/src/pages/markdown.ts +976 -0
- package/src/pages/render.ts +748 -0
- package/src/pages/window.ts +69 -0
- package/src/plugins.ts +319 -0
- package/src/public.ts +39 -0
- package/src/rename.ts +147 -0
- package/src/running.ts +171 -0
- package/src/serve.ts +221 -0
- package/src/server.ts +1385 -0
- package/src/site.ts +170 -0
- package/src/state.ts +327 -0
- package/src/status.ts +466 -0
- package/src/thread.ts +98 -0
- package/src/watchdog.ts +53 -0
- package/src/ws.ts +155 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { HANDLED, NAME, RECEIVED, SUBSCRIBE, UNSUBSCRIBE, channelSince, fromReader, handledIds, namesOf, receivedIds, subscriptions } from "./status.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
// src/events.ts
|
|
5
|
+
/** An event id as the log has them: the time in base 36, a dash, random hex. */
|
|
6
|
+
const isEventId = (id) => typeof id === "string" && /^[0-9a-z]{6,12}-[0-9a-f]{6,32}$/.test(id);
|
|
7
|
+
/**
|
|
8
|
+
* Append one event; `action` is the button that submitted a form, null for anything else. `from`
|
|
9
|
+
* is set only for events the command line writes ('cli'), so that waits skip them and pages can
|
|
10
|
+
* tell them apart; what the browser appends has none.
|
|
11
|
+
*/
|
|
12
|
+
function appendEvent(file, input, from = null, by = null) {
|
|
13
|
+
const event = {
|
|
14
|
+
id: isEventId(input.id) ? input.id : `${Date.now().toString(36)}-${crypto.randomBytes(3).toString("hex")}`,
|
|
15
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16
|
+
page: String(input.page ?? ""),
|
|
17
|
+
type: String(input.type ?? ""),
|
|
18
|
+
action: input.action ?? null,
|
|
19
|
+
data: input.data ?? {},
|
|
20
|
+
...from ? { from } : {},
|
|
21
|
+
...by ? { by } : {}
|
|
22
|
+
};
|
|
23
|
+
fs.appendFileSync(file, JSON.stringify(event) + "\n");
|
|
24
|
+
return event;
|
|
25
|
+
}
|
|
26
|
+
function parseLines(text) {
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const line of text.split("\n")) {
|
|
29
|
+
if (!line.trim()) continue;
|
|
30
|
+
let event;
|
|
31
|
+
try {
|
|
32
|
+
event = JSON.parse(line);
|
|
33
|
+
} catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
out.push(event);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function readEvents(file) {
|
|
41
|
+
return read(file).events;
|
|
42
|
+
}
|
|
43
|
+
const RENAMED = {
|
|
44
|
+
"workpad:taken": RECEIVED,
|
|
45
|
+
"workpad:picked": HANDLED
|
|
46
|
+
};
|
|
47
|
+
const OLD_MARKS = Object.keys(RENAMED).map((type) => Buffer.from(`"type":"${type}"`));
|
|
48
|
+
function convert(file) {
|
|
49
|
+
rewrite(file, (e) => RENAMED[e.type] ? {
|
|
50
|
+
...e,
|
|
51
|
+
type: RENAMED[e.type]
|
|
52
|
+
} : e);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The events in the log, and the byte offset they end at: after its last whole line. A line still
|
|
56
|
+
* being written is left out, and following from `end` gets it whole, so reading and then following
|
|
57
|
+
* from `end` never loses or splits an event.
|
|
58
|
+
*/
|
|
59
|
+
function read(file) {
|
|
60
|
+
let buf;
|
|
61
|
+
try {
|
|
62
|
+
buf = fs.readFileSync(file);
|
|
63
|
+
} catch {
|
|
64
|
+
return {
|
|
65
|
+
events: [],
|
|
66
|
+
end: 0
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (OLD_MARKS.some((m) => buf.includes(m))) {
|
|
70
|
+
convert(file);
|
|
71
|
+
try {
|
|
72
|
+
buf = fs.readFileSync(file);
|
|
73
|
+
} catch {
|
|
74
|
+
return {
|
|
75
|
+
events: [],
|
|
76
|
+
end: 0
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const end = buf.lastIndexOf(10) + 1;
|
|
81
|
+
return {
|
|
82
|
+
events: parseLines(buf.subarray(0, end).toString("utf8")),
|
|
83
|
+
end
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Call `onEvent` for each event appended to the log from byte `from` on (a line boundary, such as
|
|
88
|
+
* `read`'s `end`), in order, as whole lines arrive. Checks every `interval` ms (default 200).
|
|
89
|
+
* Returns a function that stops it.
|
|
90
|
+
*
|
|
91
|
+
* The log can be rewritten under it (`prune`: a page closed, its events gone): a new file, or a
|
|
92
|
+
* shorter one. Then it reads the log again and goes on after the last event it had passed on (by
|
|
93
|
+
* time, and by id among those of the same time), so nothing is passed on twice.
|
|
94
|
+
*/
|
|
95
|
+
function follow(file, from, onEvent, { interval = 200 } = {}) {
|
|
96
|
+
let offset = from;
|
|
97
|
+
let partial = "";
|
|
98
|
+
let inode = null;
|
|
99
|
+
try {
|
|
100
|
+
inode = fs.statSync(file).ino;
|
|
101
|
+
} catch {}
|
|
102
|
+
let lastTs = "";
|
|
103
|
+
let atLastTs = /* @__PURE__ */ new Set();
|
|
104
|
+
if (from > 0) {
|
|
105
|
+
let before = [];
|
|
106
|
+
try {
|
|
107
|
+
before = parseLines(fs.readFileSync(file).subarray(0, from).toString("utf8"));
|
|
108
|
+
} catch {}
|
|
109
|
+
for (const e of before) {
|
|
110
|
+
if (e.ts > lastTs) {
|
|
111
|
+
lastTs = e.ts;
|
|
112
|
+
atLastTs = /* @__PURE__ */ new Set();
|
|
113
|
+
}
|
|
114
|
+
if (e.ts === lastTs) atLastTs.add(e.id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const pass = (e) => {
|
|
118
|
+
if (e.ts > lastTs) {
|
|
119
|
+
lastTs = e.ts;
|
|
120
|
+
atLastTs = /* @__PURE__ */ new Set();
|
|
121
|
+
}
|
|
122
|
+
atLastTs.add(e.id);
|
|
123
|
+
onEvent(e);
|
|
124
|
+
};
|
|
125
|
+
const poll = () => {
|
|
126
|
+
let stat;
|
|
127
|
+
try {
|
|
128
|
+
stat = fs.statSync(file);
|
|
129
|
+
} catch {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (inode != null && stat.ino !== inode || stat.size < offset) {
|
|
133
|
+
inode = stat.ino;
|
|
134
|
+
const { events, end } = read(file);
|
|
135
|
+
offset = end;
|
|
136
|
+
partial = "";
|
|
137
|
+
for (const e of events) if (e.ts > lastTs || e.ts === lastTs && !atLastTs.has(e.id)) pass(e);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
inode = stat.ino;
|
|
141
|
+
if (stat.size === offset) return;
|
|
142
|
+
const fd = fs.openSync(file, "r");
|
|
143
|
+
const buf = Buffer.alloc(stat.size - offset);
|
|
144
|
+
fs.readSync(fd, buf, 0, buf.length, offset);
|
|
145
|
+
fs.closeSync(fd);
|
|
146
|
+
offset = stat.size;
|
|
147
|
+
const text = partial + buf.toString("utf8");
|
|
148
|
+
const cut = text.lastIndexOf("\n");
|
|
149
|
+
partial = text.slice(cut + 1);
|
|
150
|
+
for (const e of parseLines(text.slice(0, cut + 1))) pass(e);
|
|
151
|
+
};
|
|
152
|
+
const timer = setInterval(poll, interval);
|
|
153
|
+
return () => clearInterval(timer);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Rewrite the log, event by event: `change` returns the event to keep (as it is, or changed) or
|
|
157
|
+
* null to drop it. The log is written anew and put in place in one rename; when an event was
|
|
158
|
+
* appended while it was being written, it starts over, so none is lost. A follow running across it
|
|
159
|
+
* reads it again and goes on after the last event it passed on (see follow). Lines that aren't
|
|
160
|
+
* events are kept as they are. Returns how many were dropped and changed.
|
|
161
|
+
*/
|
|
162
|
+
function rewrite(file, change) {
|
|
163
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
164
|
+
let buf;
|
|
165
|
+
try {
|
|
166
|
+
buf = fs.readFileSync(file);
|
|
167
|
+
} catch {
|
|
168
|
+
return {
|
|
169
|
+
removed: 0,
|
|
170
|
+
changed: 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const keep = [];
|
|
174
|
+
let removed = 0, changed = 0;
|
|
175
|
+
for (const line of buf.toString("utf8").split("\n")) {
|
|
176
|
+
if (!line.trim()) continue;
|
|
177
|
+
let ev = null;
|
|
178
|
+
try {
|
|
179
|
+
ev = JSON.parse(line);
|
|
180
|
+
} catch {}
|
|
181
|
+
if (!ev) {
|
|
182
|
+
keep.push(line);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const next = change(ev);
|
|
186
|
+
if (!next) {
|
|
187
|
+
removed++;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const text = JSON.stringify(next);
|
|
191
|
+
if (text !== JSON.stringify(ev)) changed++;
|
|
192
|
+
keep.push(next === ev ? line : text);
|
|
193
|
+
}
|
|
194
|
+
if (!removed && !changed) return {
|
|
195
|
+
removed,
|
|
196
|
+
changed
|
|
197
|
+
};
|
|
198
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
199
|
+
fs.writeFileSync(tmp, keep.length ? keep.join("\n") + "\n" : "");
|
|
200
|
+
if (fs.statSync(file).size !== buf.length) {
|
|
201
|
+
fs.rmSync(tmp, { force: true });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
fs.renameSync(tmp, file);
|
|
205
|
+
return {
|
|
206
|
+
removed,
|
|
207
|
+
changed
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
throw new Error("the log kept changing while it was being rewritten; try again");
|
|
211
|
+
}
|
|
212
|
+
/** Remove a page's events from the log (`workpad archive` and `destroy`, `workpad prune`): those of exactly
|
|
213
|
+
* that page, and of them only those `which` says (all by default). Returns how many. */
|
|
214
|
+
function prune(file, page, which = () => true) {
|
|
215
|
+
return rewrite(file, (e) => e.page === page && which(e) ? null : e).removed;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Change an agent's event in place (`workpad edit`): `data` is merged into its data; its id, time
|
|
219
|
+
* and everything else stay, so what refers to it (a reply, a mark, a read) still does. Only an
|
|
220
|
+
* agent's own events (`from: cli`): what the reader sent stays as they sent it. Returns the event
|
|
221
|
+
* as it is now.
|
|
222
|
+
*/
|
|
223
|
+
function editEvent(file, id, data) {
|
|
224
|
+
const found = readEvents(file).find((e) => e.id === id);
|
|
225
|
+
if (!found) throw new Error(`no event ${id} in the log`);
|
|
226
|
+
if (fromReader(found)) throw new Error(`event ${id} is the reader's (${found.type}): what the reader sent stays as they sent it; an agent edits only its own`);
|
|
227
|
+
let edited = null;
|
|
228
|
+
rewrite(file, (e) => e.id === id ? edited = {
|
|
229
|
+
...e,
|
|
230
|
+
data: {
|
|
231
|
+
...e.data,
|
|
232
|
+
...data
|
|
233
|
+
}
|
|
234
|
+
} : e);
|
|
235
|
+
return edited ?? found;
|
|
236
|
+
}
|
|
237
|
+
/** `page` matches the page itself and every page below it, unless `exact`. */
|
|
238
|
+
const onPage = (event, page, exact) => event.page === page || !exact && event.page.startsWith(page + "/");
|
|
239
|
+
function matches(event, { page, pages, type, exact } = {}) {
|
|
240
|
+
if (page && !onPage(event, page, exact)) return false;
|
|
241
|
+
if (pages && !pages.some((p) => onPage(event, p, exact))) return false;
|
|
242
|
+
if (type && event.type !== type) return false;
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
/** Record that an agent (`by`, when it is known) received `event`. */
|
|
246
|
+
function receive(file, event, by = null) {
|
|
247
|
+
return appendEvent(file, {
|
|
248
|
+
page: event.page,
|
|
249
|
+
type: RECEIVED,
|
|
250
|
+
data: { event: event.id }
|
|
251
|
+
}, "cli", by);
|
|
252
|
+
}
|
|
253
|
+
/** Record that an agent (`by`) handled `event` (`workpad handled`): it is no longer handed out. */
|
|
254
|
+
function handle(file, event, by = null) {
|
|
255
|
+
return appendEvent(file, {
|
|
256
|
+
page: event.page,
|
|
257
|
+
type: HANDLED,
|
|
258
|
+
data: { event: event.id }
|
|
259
|
+
}, "cli", by);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Which event types reach an agent unasked: a form's answers (types without a colon) always, and of
|
|
263
|
+
* the plugins' events (`<plugin>:<what>`) those declared `handOut: true`, given in `handedOut`.
|
|
264
|
+
*/
|
|
265
|
+
const forAgent = (handedOut = /* @__PURE__ */ new Set()) => (type) => !type.includes(":") || handedOut.has(type);
|
|
266
|
+
/**
|
|
267
|
+
* Hand the events that match `filter` to `onEvent`, for agent `agent`: the reader's, and other
|
|
268
|
+
* agents' (an agent's event says who wrote it, `by`; one that doesn't is handed to no one). Each is
|
|
269
|
+
* marked received by `agent` once handed out. First the backlog: what is not handled, also from before
|
|
270
|
+
* this started, those `agent` received before saying so (`again`). Then, with `follow`, every new one as
|
|
271
|
+
* it comes. The backlog and the following split the log at one line boundary, so no event falls
|
|
272
|
+
* between them. Any number hand out from one log at once: each gets every event. Of the plugins'
|
|
273
|
+
* events only those for an agent (`forAgent`), unless the filter asks for a type by name.
|
|
274
|
+
*
|
|
275
|
+
* Resolves with how many were handed out: once `count` is reached, after the backlog without
|
|
276
|
+
* `follow`, or when `signal` aborts.
|
|
277
|
+
*/
|
|
278
|
+
function handOut(file, filter, onEvent, options = {}) {
|
|
279
|
+
const { count = Infinity, follow: following = true, interval, signal, forAgent: isForAgent = forAgent(), batch = false, mark = true, agent = null, skipReceivedBefore } = options;
|
|
280
|
+
return new Promise((resolve) => {
|
|
281
|
+
let got = 0;
|
|
282
|
+
let stop = () => {};
|
|
283
|
+
const finish = () => {
|
|
284
|
+
stop();
|
|
285
|
+
signal?.removeEventListener("abort", finish);
|
|
286
|
+
resolve(got);
|
|
287
|
+
};
|
|
288
|
+
const fromOthers = (e) => fromReader(e) || !!e.by && e.by !== agent;
|
|
289
|
+
const wanted = (e) => fromOthers(e) && matches(e, filter) && (!!filter.type || isForAgent(e.type));
|
|
290
|
+
let before = /* @__PURE__ */ new Set();
|
|
291
|
+
const hand = (e) => {
|
|
292
|
+
onEvent(e, before.has(e.id));
|
|
293
|
+
if (mark) receive(file, e, agent);
|
|
294
|
+
return ++got < count && !signal?.aborted;
|
|
295
|
+
};
|
|
296
|
+
if (count <= 0 || signal?.aborted) return finish();
|
|
297
|
+
const { events, end } = read(file);
|
|
298
|
+
const handled = handledIds(events);
|
|
299
|
+
before = receivedBy(events, agent);
|
|
300
|
+
let skipping = !!skipReceivedBefore;
|
|
301
|
+
const receivedAny = skipping ? receivedIds(events) : /* @__PURE__ */ new Set();
|
|
302
|
+
for (const e of events) {
|
|
303
|
+
if (skipping && e.id === skipReceivedBefore) skipping = false;
|
|
304
|
+
if (skipping && !fromReader(e) && receivedAny.has(e.id)) continue;
|
|
305
|
+
if (wanted(e) && !handled.has(e.id) && !hand(e)) return finish();
|
|
306
|
+
}
|
|
307
|
+
if (batch && got) return finish();
|
|
308
|
+
if (!following) return finish();
|
|
309
|
+
signal?.addEventListener("abort", finish);
|
|
310
|
+
stop = follow(file, end, (e) => {
|
|
311
|
+
if (got < count && wanted(e) && !hand(e)) return finish();
|
|
312
|
+
if (batch && got) queueMicrotask(finish);
|
|
313
|
+
}, { interval });
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** The ids of the events `agent` received (null: an unnamed process, whose marks say no one). */
|
|
317
|
+
function receivedBy(events, agent) {
|
|
318
|
+
const ids = /* @__PURE__ */ new Set();
|
|
319
|
+
for (const e of events) if (e.type === "workpad:received" && e.from === "cli" && (e.by ?? null) === agent && typeof e.data?.event === "string") ids.add(e.data.event);
|
|
320
|
+
return ids;
|
|
321
|
+
}
|
|
322
|
+
export { HANDLED, NAME, RECEIVED, SUBSCRIBE, UNSUBSCRIBE, appendEvent, channelSince, editEvent, follow, forAgent, fromReader, handOut, handle, handledIds, isEventId, matches, namesOf, parseLines, prune, read, readEvents, receive, receivedBy, receivedIds, rewrite, subscriptions };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/files.ts
|
|
3
|
+
/** Left out always: what a repository keeps for its tools. */
|
|
4
|
+
const ALWAYS_EXCLUDED = ["**/node_modules", "**/.git"];
|
|
5
|
+
const glob = (rel, g) => path.posix.matchesGlob(rel, g);
|
|
6
|
+
/** The path and each folder above it: `a/b/c` → `a/b/c`, `a/b`, `a`. */
|
|
7
|
+
function* upward(rel) {
|
|
8
|
+
for (let p = rel; p && p !== "."; p = path.posix.dirname(p)) yield p;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Can a match of `g` be inside the folder `rel`? Segment by segment, up to the glob's first `**`
|
|
12
|
+
* (which can stand for any folders): `docs/*.md` reaches into `docs`, `*.md` into no folder at all.
|
|
13
|
+
*/
|
|
14
|
+
function reachesInto(g, rel) {
|
|
15
|
+
const parts = g.split("/");
|
|
16
|
+
const dirs = rel.split("/");
|
|
17
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
18
|
+
const part = parts[i];
|
|
19
|
+
if (part === void 0) return false;
|
|
20
|
+
if (part === "**") return true;
|
|
21
|
+
if (i === parts.length - 1) return false;
|
|
22
|
+
if (!path.posix.matchesGlob(dirs[i], part)) return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/** The filter for a project's `files` setting (anything but an object: everything but the always-excluded). */
|
|
27
|
+
function fileFilter(files) {
|
|
28
|
+
const config = typeof files === "object" && files ? files : {};
|
|
29
|
+
const exclude = [...ALWAYS_EXCLUDED, ...config.exclude ?? []];
|
|
30
|
+
const include = config.include?.length ? config.include : null;
|
|
31
|
+
const excluded = (rel) => [...upward(rel)].some((p) => exclude.some((g) => glob(p, g)));
|
|
32
|
+
const included = (rel) => !include || [...upward(rel)].some((p) => include.some((g) => glob(p, g)));
|
|
33
|
+
return {
|
|
34
|
+
key: JSON.stringify({
|
|
35
|
+
include,
|
|
36
|
+
exclude
|
|
37
|
+
}),
|
|
38
|
+
shows: (rel) => !!rel && !excluded(rel) && included(rel),
|
|
39
|
+
mayHold: (rel) => {
|
|
40
|
+
if (!rel) return true;
|
|
41
|
+
if (excluded(rel)) return false;
|
|
42
|
+
if (!include || included(rel)) return true;
|
|
43
|
+
return include.some((g) => reachesInto(g, rel));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { ALWAYS_EXCLUDED, fileFilter };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { appendEvent } from "./events.js";
|
|
2
|
+
import { HOLD, RELEASE, SETTLE } from "./status.js";
|
|
3
|
+
// src/formstate.ts
|
|
4
|
+
/** A refusal: what was asked can't be done as asked. `status` is for the API's answer. */
|
|
5
|
+
var FormStateError = class extends Error {
|
|
6
|
+
status = 400;
|
|
7
|
+
};
|
|
8
|
+
/** Are these questions of the page? Else a refusal that says which are. */
|
|
9
|
+
function check(p, names) {
|
|
10
|
+
if (!names.length) throw new FormStateError(`name the forms: the questions on ${p.page} are ${p.asks.join(", ") || "none"}`);
|
|
11
|
+
for (const name of names) if (!p.asks.includes(name)) throw new FormStateError(`no form ${name} on ${p.page}: its questions are ${p.asks.join(", ") || "none"}`);
|
|
12
|
+
}
|
|
13
|
+
const stateOf = (p, name) => p.questions.find((q) => q.name === name)?.state;
|
|
14
|
+
/**
|
|
15
|
+
* Settle questions (`workpad settle`): those named, or every open and held one (`all`). Only what
|
|
16
|
+
* waits for the reader, or is held, settles: an answer in stays the agent's to see to.
|
|
17
|
+
*/
|
|
18
|
+
function settleForms(file, p, named, by) {
|
|
19
|
+
const unsettled = (name) => p.open.includes(name) || p.held.some((h) => h.name === name);
|
|
20
|
+
if (named !== "all") check(p, named);
|
|
21
|
+
const forms = named === "all" ? [...p.open, ...p.held.map((h) => h.name)] : named.filter(unsettled);
|
|
22
|
+
const skipped = named === "all" ? [] : named.filter((n) => !unsettled(n)).map((name) => ({
|
|
23
|
+
name,
|
|
24
|
+
state: stateOf(p, name) ?? ""
|
|
25
|
+
}));
|
|
26
|
+
return {
|
|
27
|
+
event: forms.length ? appendEvent(file, {
|
|
28
|
+
page: p.page,
|
|
29
|
+
type: SETTLE,
|
|
30
|
+
data: { forms }
|
|
31
|
+
}, "cli", by) : null,
|
|
32
|
+
forms,
|
|
33
|
+
skipped
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Hold questions, with a reason (`workpad hold`): those that wait for the reader (or are held
|
|
38
|
+
* already: the new reason replaces the old). Until released, or answered after all, each is held.
|
|
39
|
+
*/
|
|
40
|
+
function holdForms(file, p, names, reason, by) {
|
|
41
|
+
check(p, names);
|
|
42
|
+
if (!reason.trim()) throw new FormStateError("say why it is held: what it waits for (\"waits for !2145\")");
|
|
43
|
+
const answered = names.filter((n) => !p.open.includes(n) && !p.held.some((h) => h.name === n));
|
|
44
|
+
if (answered.length) throw new FormStateError(`only a question that waits for the reader is held: ${answered.map((n) => `${n} is ${stateOf(p, n)}`).join(", ")}`);
|
|
45
|
+
return appendEvent(file, {
|
|
46
|
+
page: p.page,
|
|
47
|
+
type: HOLD,
|
|
48
|
+
data: {
|
|
49
|
+
forms: names,
|
|
50
|
+
reason: reason.trim()
|
|
51
|
+
}
|
|
52
|
+
}, "cli", by);
|
|
53
|
+
}
|
|
54
|
+
/** Release held questions (`workpad release`): open again, or as their answers say. */
|
|
55
|
+
function releaseForms(file, p, names, by) {
|
|
56
|
+
check(p, names);
|
|
57
|
+
const free = names.filter((n) => !p.held.some((h) => h.name === n));
|
|
58
|
+
if (free.length) throw new FormStateError(`${free.join(", ")} ${free.length > 1 ? "aren't" : "isn't"} held on ${p.page}${p.held.length ? `: held are ${p.held.map((h) => h.name).join(", ")}` : ""}`);
|
|
59
|
+
return appendEvent(file, {
|
|
60
|
+
page: p.page,
|
|
61
|
+
type: RELEASE,
|
|
62
|
+
data: { forms: names }
|
|
63
|
+
}, "cli", by);
|
|
64
|
+
}
|
|
65
|
+
export { FormStateError, holdForms, releaseForms, settleForms };
|
package/dist/src/help.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { MIGRATIONS } from "./migrate.js";
|
|
2
|
+
// src/help.ts
|
|
3
|
+
const FILTERS = ` --page <page|file> only that page and the pages below it
|
|
4
|
+
--type <type> only events of that type (a form's name, chat:message, comments:new…)`;
|
|
5
|
+
const COMMAND_HELP = {
|
|
6
|
+
init: {
|
|
7
|
+
usage: "[name]",
|
|
8
|
+
summary: "make this folder a project: .workpad/pages/",
|
|
9
|
+
details: "Writes a config only for what differs from the defaults (a name; files: false in the home folder)."
|
|
10
|
+
},
|
|
11
|
+
root: {
|
|
12
|
+
usage: "",
|
|
13
|
+
summary: "print where pages go (this project's .workpad/pages)"
|
|
14
|
+
},
|
|
15
|
+
new: {
|
|
16
|
+
usage: "<name>",
|
|
17
|
+
summary: "create a page under a name no other page has (name, name-2, …), print its path",
|
|
18
|
+
details: "Subfolders are fine (task/plan). Whoever runs it (--agent, WORKPAD_AGENT, a plugin's session) is subscribed to the page."
|
|
19
|
+
},
|
|
20
|
+
agent: {
|
|
21
|
+
usage: "[name <name> | name --clear | list | unsubscribe <agent> [--page <p>…] | ping [<code>]]",
|
|
22
|
+
summary: "who you are on the boards: your id and name; name yourself, see who else is around, check a channel reaches you",
|
|
23
|
+
details: `Your id is --agent, else WORKPAD_AGENT, else the session an agent plugin names (claude(),
|
|
24
|
+
opencode()). Alone, it says your id and your name.
|
|
25
|
+
|
|
26
|
+
name <name> the name you show as (the list on a page's dot, status), one per agent: a new
|
|
27
|
+
one takes the old one's place; --clear drops it. Kept on no page, so deleting a
|
|
28
|
+
page keeps it
|
|
29
|
+
list everyone on this board: their name and id, what each is subscribed to, what
|
|
30
|
+
each listens on now; subscribed and not listening is said
|
|
31
|
+
unsubscribe <agent> take an agent (its id or name) off the pages named with --page, else off all
|
|
32
|
+
of them: one that is gone (a relay that stopped) stays a subscriber otherwise
|
|
33
|
+
ping [<code>] does what a plugin pushes reach you? It pings your channel, which pushes a pong
|
|
34
|
+
into the session, the way answers will, with the code to confirm with. Once
|
|
35
|
+
confirmed, the channel listens on your pages, and the answers it brings count
|
|
36
|
+
as received. No channel (exit 1), or no pong: nothing brings answers here, so
|
|
37
|
+
listen for them.`
|
|
38
|
+
},
|
|
39
|
+
show: {
|
|
40
|
+
usage: "<page|file> [<anchor>]",
|
|
41
|
+
summary: "start this project's server if needed, print the page's URL",
|
|
42
|
+
details: "Any file of the project renders too (README.md). Under a shared server that isn't running, says so and starts nothing. With an anchor (`form:logger`, a heading's slug: see `workpad anchors`), the URL opens the page there; one the page doesn't have exits 1."
|
|
43
|
+
},
|
|
44
|
+
url: {
|
|
45
|
+
usage: "<page|file> [<anchor>] [--full]",
|
|
46
|
+
summary: "a link to a page, or to a place on it, for a message or a page: from the server root",
|
|
47
|
+
details: "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."
|
|
48
|
+
},
|
|
49
|
+
settle: {
|
|
50
|
+
usage: "<page|file> <form>… | --all",
|
|
51
|
+
summary: "settle questions answered elsewhere (a chat, the design moving on): no longer unanswered",
|
|
52
|
+
details: "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."
|
|
53
|
+
},
|
|
54
|
+
hold: {
|
|
55
|
+
usage: "<page|file> <form>… \"<reason>\"",
|
|
56
|
+
summary: "hold questions that wait on something else (\"waits for !2145\"): not waiting for the reader, not settled",
|
|
57
|
+
details: "A held form shows on the page with its reason, and counts nowhere as waiting for the reader: not in `workpad status`, the page's counter, the turn-end check or the overview's waiting column. It isn't settled either: `workpad release` opens it again. Only a question that waits for the reader is held (one held already takes the new reason). If the reader answers it after all, the answer counts and the hold ends."
|
|
58
|
+
},
|
|
59
|
+
release: {
|
|
60
|
+
usage: "<page|file> <form>…",
|
|
61
|
+
summary: "release held questions: they wait for the reader again"
|
|
62
|
+
},
|
|
63
|
+
check: {
|
|
64
|
+
usage: "[<page|file>…]",
|
|
65
|
+
summary: "what is wrong on pages, as they render: a block nobody brings, an input outside its form, a block's error",
|
|
66
|
+
details: "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 doesn't have. The page shows the same above it. Exits 1 when there is any. Run it after writing a page."
|
|
67
|
+
},
|
|
68
|
+
anchors: {
|
|
69
|
+
usage: "<page|file>",
|
|
70
|
+
summary: "what a page can be linked to: each #anchor, what it is and what it says",
|
|
71
|
+
details: "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."
|
|
72
|
+
},
|
|
73
|
+
migrate: {
|
|
74
|
+
usage: "[<folder|file>…] [--write]",
|
|
75
|
+
summary: "after updating workpad: rewrite pages written in an older syntax in the current one",
|
|
76
|
+
details: `Without --write, a dry run: each page that would change, and what would. --write rewrites them
|
|
77
|
+
in place. Without paths, this project's pages (.workpad/pages); a folder is searched for .md files.
|
|
78
|
+
Code fences and inline code are left as they are, and a page already in the current syntax doesn't
|
|
79
|
+
change: running it again changes nothing. A dry run that finds pages to change exits 1 (for CI);
|
|
80
|
+
otherwise it exits 0.
|
|
81
|
+
|
|
82
|
+
${MIGRATIONS.map((m) => ` ${m.name.padEnd(20)} ${m.description}`).join("\n")}`
|
|
83
|
+
},
|
|
84
|
+
archive: {
|
|
85
|
+
usage: "<page|file>",
|
|
86
|
+
summary: "a page that did its job: it leaves the pages and its events the log, kept as markdown with what was answered on it",
|
|
87
|
+
details: "The file goes to .workpad/archive/<page>-<date>.md: the page, then each form's answers with when they came, its chats, its comments. It reads without a server, and moves with the project's folder."
|
|
88
|
+
},
|
|
89
|
+
destroy: {
|
|
90
|
+
usage: "<page|file>",
|
|
91
|
+
summary: "a throwaway page: remove its file, and its events from the log; nothing is kept"
|
|
92
|
+
},
|
|
93
|
+
prune: {
|
|
94
|
+
usage: "<page|file> [--type <type>] [--id <event id>]",
|
|
95
|
+
summary: "remove a page's events from the log, keep the page",
|
|
96
|
+
details: ` --type <type> only the events of that type
|
|
97
|
+
--id <event id> only that event
|
|
98
|
+
|
|
99
|
+
Without either, all of the page's events: its questions are open again.
|
|
100
|
+
One chat's messages: workpad chat prune <page|file> <chat>.`
|
|
101
|
+
},
|
|
102
|
+
build: {
|
|
103
|
+
usage: "[globs…] [--out <dir>] [--skip <a,b>]",
|
|
104
|
+
summary: "pages as a static site: plain HTML, links relative",
|
|
105
|
+
details: ` --out <dir> where to write it (default: the config's build.out)
|
|
106
|
+
--skip <a,b> plugins or blocks to leave out (default: form, chat, comments, draft)`
|
|
107
|
+
},
|
|
108
|
+
edit: {
|
|
109
|
+
usage: "<event id> --data <json>",
|
|
110
|
+
summary: "change an agent's own event in place (merged into its data)",
|
|
111
|
+
details: "Keeps its id, so what refers to it still does. What the reader sent can't be edited."
|
|
112
|
+
},
|
|
113
|
+
scroll: {
|
|
114
|
+
usage: "<page|file> <where>",
|
|
115
|
+
summary: "scroll the tabs that have the page open to a heading's text, a form's name or any text",
|
|
116
|
+
details: "Opens details around it and lights it up. Exits 1 when nothing matches or no tab of the page is connected."
|
|
117
|
+
},
|
|
118
|
+
docs: {
|
|
119
|
+
usage: "[<block|plugin> | --all]",
|
|
120
|
+
summary: "how to write pages here: markdown, and a line per block by what it is for; read it before writing one",
|
|
121
|
+
details: "Without arguments, the menu: how pages are written, and each block's line under what an agent wants to do (ask, show, arrange, mark). With a block's name, the docs of the plugin that brings it (`workpad docs tabs`); a plugin's name works too. With `--all`, every plugin's docs."
|
|
122
|
+
},
|
|
123
|
+
events: {
|
|
124
|
+
usage: "[--page <p>] [--type <t>] [--since <time|id>] [--last <n>] [--follow]",
|
|
125
|
+
summary: "print recorded events as ndjson; marks nothing received",
|
|
126
|
+
details: `${FILTERS}
|
|
127
|
+
--since <time|id> only those after an ISO time or an event id
|
|
128
|
+
--last <n> only the last n
|
|
129
|
+
--follow then print each new one as it comes`
|
|
130
|
+
},
|
|
131
|
+
listen: {
|
|
132
|
+
usage: "[--page <p>…] [--type <t>] [--wait [--timeout <s>] | --channel] [--agent <who>]",
|
|
133
|
+
summary: "print what you haven't handled on the pages (the reader's answers, other agents' messages) and each as it comes; --wait stops at the first, --channel hands over to your channel",
|
|
134
|
+
details: `${FILTERS}
|
|
135
|
+
--page again several pages in one listen: it listens on each, and takes what comes on any
|
|
136
|
+
--wait stop once it printed: all there are, or with none, the first to come
|
|
137
|
+
--timeout <seconds> with --wait: exit 2 when nothing came
|
|
138
|
+
--channel make the pages yours and exit: your session's channel brings their answers
|
|
139
|
+
--agent <who> who listens (else WORKPAD_AGENT, else the session an agent plugin names)
|
|
140
|
+
|
|
141
|
+
It prints, one line each, everything on the page you haven't handled, also from before it started,
|
|
142
|
+
then each new one as it comes, and runs on: run it in the background. To get the next answer and
|
|
143
|
+
your turn back, --wait. In a session whose channel is confirmed (workpad agent ping), --channel
|
|
144
|
+
makes the pages yours (without --page, every page, also those made later) and exits: the channel
|
|
145
|
+
brings the reader's answers waiting there and what comes; other agents' messages from before that
|
|
146
|
+
someone already received are skipped, and it says how many (listen --wait hands them out). Each
|
|
147
|
+
counts as received by you. One you
|
|
148
|
+
received before and still haven't handled comes again, with "again": true. You handle one by
|
|
149
|
+
replying in its chat (or to it), or with workpad handled <id>. Then it lists what is left:
|
|
150
|
+
answers to handle, chats waiting for your reply, questions still unanswered.
|
|
151
|
+
|
|
152
|
+
Any number listen on a page, and each hears everything there but its own events: agents can talk
|
|
153
|
+
to each other in the same chats. Without --page it listens on every page (in a project of the
|
|
154
|
+
machine's entries, every page of the entry).`
|
|
155
|
+
},
|
|
156
|
+
append: {
|
|
157
|
+
usage: "--page <p> --type <t> [--data <json>]",
|
|
158
|
+
summary: "add an event to a page's log, as the agent (a reply, a chat message)"
|
|
159
|
+
},
|
|
160
|
+
handled: {
|
|
161
|
+
usage: "<event id> [<event id>…]",
|
|
162
|
+
summary: "you are done with these answers: handled, so no listen hands them out again and nothing reminds you of them",
|
|
163
|
+
details: "Replying in an answer's chat (or to it) handles it too."
|
|
164
|
+
},
|
|
165
|
+
thread: {
|
|
166
|
+
usage: "<event id>",
|
|
167
|
+
summary: "an answer or chat message with its question: the form as written, the chosen options marked, its answers and its chat",
|
|
168
|
+
details: "For acting on an answer you were handed (a listen, the channel) without piecing the question together from the page and the log. Reads the page and the log: no server needed."
|
|
169
|
+
},
|
|
170
|
+
status: {
|
|
171
|
+
usage: "[--page <p>]",
|
|
172
|
+
summary: "per page: questions without an answer, answers not received or not handled, chats waiting for a reply, who listens"
|
|
173
|
+
},
|
|
174
|
+
serve: {
|
|
175
|
+
usage: "",
|
|
176
|
+
summary: "run this project's server in the foreground; outside a project or for one of the machine's entries, the shared server"
|
|
177
|
+
},
|
|
178
|
+
skill: {
|
|
179
|
+
usage: "[dir]",
|
|
180
|
+
summary: "print where the agent skill is, or link it into a skills folder"
|
|
181
|
+
},
|
|
182
|
+
paths: {
|
|
183
|
+
usage: "[--write|--read]",
|
|
184
|
+
summary: "the folders the shared server needs, for a sandbox wrapper to grant",
|
|
185
|
+
details: ` --write the entries' folders and the server's state
|
|
186
|
+
--read the machine config and workpad itself`
|
|
187
|
+
},
|
|
188
|
+
help: {
|
|
189
|
+
usage: "[command]",
|
|
190
|
+
summary: "this overview; with a command, its help (as <command> --help)"
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/** `workpad <name> --help`: its usage, what it does, and its options. */
|
|
194
|
+
function commandHelp(name) {
|
|
195
|
+
const h = COMMAND_HELP[name];
|
|
196
|
+
if (!h) throw new Error(`no command ${name}`);
|
|
197
|
+
return [
|
|
198
|
+
`usage: workpad ${[name, h.usage].filter(Boolean).join(" ")}`,
|
|
199
|
+
"",
|
|
200
|
+
h.summary,
|
|
201
|
+
h.details ? `\n${h.details}` : ""
|
|
202
|
+
].join("\n").trimEnd();
|
|
203
|
+
}
|
|
204
|
+
/** The overview's list of commands, one line each. */
|
|
205
|
+
function commandList() {
|
|
206
|
+
return Object.entries(COMMAND_HELP).map(([name, h]) => {
|
|
207
|
+
const head = ` workpad ${[name, h.usage].filter(Boolean).join(" ")}`;
|
|
208
|
+
return head.length < 36 ? `${head.padEnd(36)} ${h.summary}` : `${head}\n${" ".repeat(37)}${h.summary}`;
|
|
209
|
+
}).join("\n");
|
|
210
|
+
}
|
|
211
|
+
export { COMMAND_HELP, commandHelp, commandList };
|
package/dist/src/html.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/html.ts
|
|
2
|
+
/** A piece of HTML that is not escaped again. `String(piece)` is its markup. */
|
|
3
|
+
var Html = class {
|
|
4
|
+
value;
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
}
|
|
8
|
+
toString() {
|
|
9
|
+
return this.value;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const ESCAPE = {
|
|
13
|
+
"&": "&",
|
|
14
|
+
"<": "<",
|
|
15
|
+
">": ">",
|
|
16
|
+
"\"": """,
|
|
17
|
+
"'": "'"
|
|
18
|
+
};
|
|
19
|
+
/** Text → HTML that shows it as text. */
|
|
20
|
+
const escape = (value) => String(value).replace(/[&<>"']/g, (c) => ESCAPE[c]);
|
|
21
|
+
/** Markup to use as it is: only for HTML that is safe already, never for text from outside. */
|
|
22
|
+
const raw = (value) => new Html(String(value ?? ""));
|
|
23
|
+
function part(value) {
|
|
24
|
+
if (value == null || value === false) return "";
|
|
25
|
+
if (value instanceof Html) return value.value;
|
|
26
|
+
if (Array.isArray(value)) return value.map(part).join("");
|
|
27
|
+
return escape(value);
|
|
28
|
+
}
|
|
29
|
+
function html(strings, ...values) {
|
|
30
|
+
let out = strings[0];
|
|
31
|
+
for (let i = 0; i < values.length; i++) out += part(values[i]) + strings[i + 1];
|
|
32
|
+
return new Html(out);
|
|
33
|
+
}
|
|
34
|
+
export { Html, escape, html, raw };
|