@bigmistqke/workpad 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -9
- package/bin/workpad.ts +187 -37
- package/dist/bin/workpad.js +156 -32
- package/dist/client/runtime.js +141 -18
- package/dist/plugins/chat/README.md +7 -3
- package/dist/plugins/chat/index.js +1 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +10 -0
- package/dist/plugins/claude/channel.js +22 -4
- package/dist/plugins/comments/README.md +2 -1
- package/dist/plugins/comments/index.js +2 -0
- package/dist/plugins/comments/public/client.js +6 -5
- package/dist/plugins/comments/public/style.css +9 -0
- package/dist/plugins/form/README.md +1 -1
- package/dist/plugins/index.js +3 -1
- package/dist/plugins/opencode/channel.js +1 -0
- package/dist/plugins/progress/README.md +41 -0
- package/dist/plugins/progress/index.js +117 -0
- package/dist/plugins/progress/public/client.js +1 -0
- package/dist/plugins/progress/public/style.css +85 -0
- package/dist/plugins/progress/state.js +210 -0
- package/dist/solid/index.js +3 -1
- package/dist/src/agents.js +7 -3
- package/dist/src/anchors.js +25 -1
- package/dist/src/build.js +1 -1
- package/dist/src/client/page/base.css +48 -2
- package/dist/src/client/page/main.js +58 -30
- package/dist/src/document.js +6 -4
- package/dist/src/events.js +19 -9
- package/dist/src/help.js +43 -8
- package/dist/src/hub.js +14 -1
- package/dist/src/loader.js +7 -2
- package/dist/src/migrate.js +1 -1
- package/dist/src/pages/board.js +1 -1
- package/dist/src/pages/markdown.js +3 -3
- package/dist/src/pages/render.js +16 -0
- package/dist/src/server.js +25 -12
- package/dist/src/set.js +99 -0
- package/dist/src/status.js +47 -8
- package/package.json +6 -1
- package/plugins/README.md +3 -1
- package/plugins/chat/README.md +7 -3
- package/plugins/chat/client.tsx +20 -3
- package/plugins/chat/index.ts +1 -0
- package/plugins/chat/public/style.css +10 -0
- package/plugins/claude/channel.ts +19 -5
- package/plugins/comments/README.md +2 -1
- package/plugins/comments/client.ts +19 -0
- package/plugins/comments/index.ts +7 -1
- package/plugins/comments/public/style.css +9 -0
- package/plugins/form/README.md +1 -1
- package/plugins/index.ts +2 -0
- package/plugins/opencode/channel.ts +2 -1
- package/plugins/progress/README.md +41 -0
- package/plugins/progress/client.ts +172 -0
- package/plugins/progress/index.ts +166 -0
- package/plugins/progress/public/style.css +85 -0
- package/plugins/progress/state.ts +278 -0
- package/skills/workpad/SKILL.md +126 -15
- package/solid/index.tsx +6 -2
- package/src/agents.ts +17 -2
- package/src/anchors.ts +32 -0
- package/src/build.ts +1 -1
- package/src/client/delivery.ts +49 -0
- package/src/client/forms.ts +18 -11
- package/src/client/page/base.css +48 -2
- package/src/client/page/waiting.ts +45 -25
- package/src/client/read.ts +9 -5
- package/src/client/runtime.ts +7 -3
- package/src/client/toast.ts +27 -3
- package/src/define.ts +92 -8
- package/src/document.ts +19 -5
- package/src/events.ts +26 -6
- package/src/help.ts +42 -7
- package/src/hub.ts +9 -0
- package/src/loader.ts +14 -4
- package/src/migrate.ts +1 -1
- package/src/pages/board.ts +3 -1
- package/src/pages/markdown.ts +4 -4
- package/src/pages/render.ts +19 -1
- package/src/server.ts +43 -13
- package/src/set.ts +118 -0
- package/src/status.ts +100 -13
package/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.0",
|
|
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
|
}
|
|
@@ -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
|
|
@@ -231,6 +231,8 @@ function draw() {
|
|
|
231
231
|
badge.toggleAttribute('data-unread', unread)
|
|
232
232
|
badge.title = unread ? 'the agent replied: unread' : lastFromAgent(t) ? 'the agent replied' : 'comment'
|
|
233
233
|
badge.textContent = String(1 + t.replies.length)
|
|
234
|
+
// the reader's comment or reply no agent received for long: the page counts it and goes here
|
|
235
|
+
if (late(t)) badge.dataset.wpDelivery = 'late'
|
|
234
236
|
const rect = t.range?.getClientRects()[0]
|
|
235
237
|
// a passage that is gone from the page: its badge stays where the passage was (at the top, if
|
|
236
238
|
// nothing of there is left), still open until closed
|
|
@@ -307,15 +309,29 @@ function refreshComments() {
|
|
|
307
309
|
// messages as markdown, rendered by the server, by their text
|
|
308
310
|
const rendered = new Map<string, string>()
|
|
309
311
|
|
|
312
|
+
/** Does a thread hold a message of the reader's no agent received for long (api.delivery)? */
|
|
313
|
+
const late = (t: Thread) => [t.comment, ...t.replies].some(e => api.delivery().get(e.id)?.state === 'late')
|
|
314
|
+
|
|
310
315
|
function renderPopover() {
|
|
311
316
|
const t = threads.find(x => x.id === openThread)
|
|
312
317
|
if (!t) return
|
|
313
318
|
const who = (e: WpEvent) => (e.from === 'cli' ? 'agent' : 'you')
|
|
319
|
+
// Where the reader's messages went, said quietly under the one it is about: their latest, while
|
|
320
|
+
// the agent hasn't replied after it (a reply says it all), and any no agent received for long
|
|
321
|
+
const all = [t.comment, ...t.replies]
|
|
322
|
+
const lastAgent = all.findLastIndex(e => e.from === 'cli')
|
|
323
|
+
const lastOwn = all.findLastIndex(e => e.from !== 'cli' && !e.sending)
|
|
324
|
+
const deliveryOf = (e: WpEvent) => {
|
|
325
|
+
const i = all.indexOf(e)
|
|
326
|
+
const d = e.from !== 'cli' && !e.sending ? api.delivery().get(e.id) : undefined
|
|
327
|
+
return d && (d.state === 'late' || (i === lastOwn && i > lastAgent)) ? d : undefined
|
|
328
|
+
}
|
|
314
329
|
// the quote and every message are text from the reader or the agent: `html` escapes them
|
|
315
330
|
// a message is markdown: as rendered, once the server has (api.markdown), as plain text till then
|
|
316
331
|
const message = (e: WpEvent) => {
|
|
317
332
|
const text = String(e.data.text ?? '')
|
|
318
333
|
const md = rendered.get(text)
|
|
334
|
+
const d = deliveryOf(e)
|
|
319
335
|
// shown at once, not yet confirmed by the server
|
|
320
336
|
return html`<div
|
|
321
337
|
class="wp-thread-message"
|
|
@@ -325,6 +341,7 @@ function renderPopover() {
|
|
|
325
341
|
>
|
|
326
342
|
<span class="wp-thread-who">${who(e)}</span>
|
|
327
343
|
<div class="wp-thread-text" ${md != null ? raw(' data-md') : ''}>${md != null ? raw(md) : text}</div>
|
|
344
|
+
${d && html`<span class="wp-thread-delivery" role="status" data-wp-delivery="${d.state}">${d.text}</span>`}
|
|
328
345
|
</div>`
|
|
329
346
|
}
|
|
330
347
|
// the reply being typed: its text, and its focus and caret, which a redraw would take
|
|
@@ -714,6 +731,8 @@ const mount: PluginMount = (el: HTMLElement, handle: PageHandle, core: Api) => {
|
|
|
714
731
|
})
|
|
715
732
|
|
|
716
733
|
api.events.on(refreshComments)
|
|
734
|
+
// where the reader's messages went: who received them, one turned late
|
|
735
|
+
api.delivery.on(refreshComments)
|
|
717
736
|
api.onRendered(refreshComments)
|
|
718
737
|
new ResizeObserver(() => draw()).observe(root)
|
|
719
738
|
addEventListener('resize', () => draw())
|
|
@@ -16,10 +16,16 @@ export default function comments(): Plugin {
|
|
|
16
16
|
events: {
|
|
17
17
|
'comments:new': {
|
|
18
18
|
handOut: true,
|
|
19
|
+
requires: ['text'],
|
|
19
20
|
description:
|
|
20
21
|
"a comment on a passage or lines of code: `{ quote, before, after, block, at?, text }`; its id is the thread's",
|
|
21
22
|
},
|
|
22
|
-
'comments:reply': {
|
|
23
|
+
'comments:reply': {
|
|
24
|
+
handOut: true,
|
|
25
|
+
forReader: true,
|
|
26
|
+
requires: ['replyTo', 'text'],
|
|
27
|
+
description: 'a reply in a thread: `{ replyTo, text }`',
|
|
28
|
+
},
|
|
23
29
|
'comments:resolve': { description: 'the reader closed a thread: `{ replyTo }`' },
|
|
24
30
|
},
|
|
25
31
|
public: builtinPublic('comments'),
|
|
@@ -103,6 +103,15 @@
|
|
|
103
103
|
.wp-thread-message[data-from='agent'] .wp-thread-who {
|
|
104
104
|
color: var(--accent, #1d5bbf);
|
|
105
105
|
}
|
|
106
|
+
/* where the reader's message went (api.delivery), quietly under it; not received for long: the warning colour */
|
|
107
|
+
.wp-thread-delivery {
|
|
108
|
+
font-size: var(--ui-tiny);
|
|
109
|
+
color: var(--muted, #696e76);
|
|
110
|
+
}
|
|
111
|
+
.wp-thread-delivery[data-wp-delivery='late'] {
|
|
112
|
+
color: var(--warn, #6b4fc0);
|
|
113
|
+
font-weight: var(--weight-strong);
|
|
114
|
+
}
|
|
106
115
|
.wp-thread-text {
|
|
107
116
|
white-space: pre-wrap;
|
|
108
117
|
overflow-wrap: anywhere;
|
package/plugins/form/README.md
CHANGED
|
@@ -117,7 +117,7 @@ but send nothing.
|
|
|
117
117
|
answering it: under every form is a chat (see the chat plugin), named
|
|
118
118
|
after the form, whose messages are never a submit, so talking about a choice
|
|
119
119
|
never makes it. Answer there with `workpad append --type chat:message
|
|
120
|
-
--data '{"chat":"<form name>"
|
|
120
|
+
--data '{"chat":"<form name>"}' --text-file -` (the text on standard input), and don't add a free-text field
|
|
121
121
|
for questions to a decision form. A form that asks nothing to talk about (a
|
|
122
122
|
lone button that starts something) can leave its chat out:
|
|
123
123
|
`:::form{name=start chat=false}`.
|
package/plugins/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import badge from './badge/index.ts'
|
|
|
23
23
|
import ansi from './ansi/index.ts'
|
|
24
24
|
import timeline from './timeline/index.ts'
|
|
25
25
|
import toc from './toc/index.ts'
|
|
26
|
+
import progress from './progress/index.ts'
|
|
26
27
|
|
|
27
28
|
export function builtins(): Plugin[] {
|
|
28
29
|
return [
|
|
@@ -45,5 +46,6 @@ export function builtins(): Plugin[] {
|
|
|
45
46
|
ansi(),
|
|
46
47
|
timeline(),
|
|
47
48
|
toc(),
|
|
49
|
+
progress(),
|
|
48
50
|
]
|
|
49
51
|
}
|
|
@@ -103,7 +103,8 @@ export async function channel(ctx: CommandContext) {
|
|
|
103
103
|
// a page taken on through the channel: what is new, not the past someone already received
|
|
104
104
|
const since = channelSince(read(ctx.eventsFile).events, agent, page) ?? undefined
|
|
105
105
|
void ctx
|
|
106
|
-
|
|
106
|
+
// what it wrote in its session, when WORKPAD_AGENT names it, is its own too
|
|
107
|
+
.handOut({ page, exact: true }, push, { mark: false, agent, aliases: new Set([session]), skipReceivedBefore: since })
|
|
107
108
|
.catch(err => problem('handing out failed', { page, err: String(err) }))
|
|
108
109
|
}
|
|
109
110
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
How far a long piece of work is, live, where the reader would ask: a
|
|
2
|
+
`:progress{id=…}` inline on a page, moved by the agent doing the work with
|
|
3
|
+
`workpad progress`. Moving it appends an event to the page's log and leaves
|
|
4
|
+
the page as it is, so it never fights another writer, and a job can move a
|
|
5
|
+
progress on a page that isn't its own.
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
## The probe
|
|
9
|
+
|
|
10
|
+
Captures 3 and 4 :progress{id=probe}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
workpad progress goldens probe 287/1413 "captures 3 and 4" --eta 20m
|
|
15
|
+
workpad progress goldens probe "building the stack" # no count
|
|
16
|
+
workpad progress goldens probe 1413/1413 "all 287 checked" # n = total: done
|
|
17
|
+
workpad progress goldens probe done "all 287 checked"
|
|
18
|
+
workpad progress goldens probe failed "Docker ran out of disk"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
On the page it shows a small bar and the count, the note, the time left
|
|
22
|
+
(`--eta`, else from the rate so far) and how long ago it moved; without a
|
|
23
|
+
count a pulsing dot; `done` and `failed` with when; "waiting to start"
|
|
24
|
+
before its first update. The corner has a card for it while it runs, and
|
|
25
|
+
one that stays once it ended until the reader has clicked to it; a click
|
|
26
|
+
goes to the marker. `workpad status` lists the running ones, and the
|
|
27
|
+
shared server's overview shows each page's on its card.
|
|
28
|
+
|
|
29
|
+
Ids are per page, letters, digits, `-` and `_`. Several on a page are one
|
|
30
|
+
per piece of work.
|
|
31
|
+
|
|
32
|
+
**Stale:** a running progress past its ETA, or without an update for 15
|
|
33
|
+
minutes, greys. The server then nudges the agent that last moved it, once,
|
|
34
|
+
and again at most every 15 minutes while it stays stale: a `progress:stale`
|
|
35
|
+
event, handed out like an answer (a channel pushes it, `workpad listen
|
|
36
|
+
--wait` returns with it, the turn-end check mentions it). Moving the
|
|
37
|
+
progress, or marking it done or failed, answers it. So move it while the
|
|
38
|
+
work runs, and end it when the work ends, failed too.
|
|
39
|
+
|
|
40
|
+
The times are the plugin's options, in milliseconds, in the config:
|
|
41
|
+
`progress({ staleAfter, nudgeEvery, checkEvery })`.
|