@bigmistqke/workpad 0.18.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -9
- package/bin/workpad.ts +412 -58
- package/dist/bin/workpad.js +336 -46
- package/dist/client/runtime.js +141 -18
- package/dist/plugins/badge/README.md +59 -10
- package/dist/plugins/badge/index.js +130 -8
- package/dist/plugins/badge/public/style.css +132 -12
- package/dist/plugins/chat/README.md +7 -3
- package/dist/plugins/chat/index.js +8 -1
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +10 -0
- package/dist/plugins/claude/README.md +13 -5
- package/dist/plugins/claude/channel.js +47 -6
- package/dist/plugins/claude/doctor.js +43 -47
- package/dist/plugins/claude/index.js +24 -8
- package/dist/plugins/claude/session.js +46 -1
- 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 +43 -7
- package/dist/plugins/opencode/index.js +2 -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 +13 -4
- 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 +22 -11
- package/dist/src/help.js +59 -12
- package/dist/src/hub.js +69 -3
- package/dist/src/listen.js +36 -4
- package/dist/src/listeners.js +14 -4
- package/dist/src/loader.js +7 -2
- package/dist/src/migrate.js +1 -1
- package/dist/src/pages/board.js +9 -4
- package/dist/src/pages/index.js +2 -4
- package/dist/src/pages/markdown.js +50 -19
- package/dist/src/pages/render.js +17 -1
- package/dist/src/server.js +94 -18
- package/dist/src/set.js +99 -0
- package/dist/src/state.js +2 -1
- package/dist/src/status.js +57 -9
- package/dist/src/turns.js +41 -0
- package/package.json +11 -1
- package/plugins/README.md +3 -1
- package/plugins/badge/README.md +59 -10
- package/plugins/badge/index.ts +141 -8
- package/plugins/badge/public/style.css +132 -12
- package/plugins/chat/README.md +7 -3
- package/plugins/chat/client.tsx +20 -3
- package/plugins/chat/index.ts +10 -1
- package/plugins/chat/public/style.css +10 -0
- package/plugins/claude/README.md +13 -5
- package/plugins/claude/channel.ts +45 -7
- package/plugins/claude/doctor.ts +58 -39
- package/plugins/claude/index.ts +30 -8
- package/plugins/claude/session.ts +32 -0
- 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 +44 -8
- package/plugins/opencode/index.ts +4 -0
- 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 +149 -18
- package/solid/index.tsx +6 -2
- package/src/agents.ts +24 -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 +120 -9
- package/src/document.ts +19 -5
- package/src/events.ts +47 -6
- package/src/help.ts +58 -11
- package/src/hub.ts +80 -2
- package/src/listen.ts +47 -4
- package/src/listeners.ts +22 -1
- package/src/loader.ts +14 -4
- package/src/migrate.ts +1 -1
- package/src/pages/board.ts +12 -3
- package/src/pages/index.ts +8 -10
- package/src/pages/markdown.ts +59 -12
- package/src/pages/render.ts +20 -2
- package/src/server.ts +127 -19
- package/src/set.ts +118 -0
- package/src/state.ts +3 -0
- package/src/status.ts +115 -14
- package/src/turns.ts +56 -0
|
@@ -3,6 +3,7 @@ import { read, receivedBy } from "../../src/events.js";
|
|
|
3
3
|
import { channel } from "./channel.js";
|
|
4
4
|
import { doctor } from "./doctor.js";
|
|
5
5
|
import { recordSession } from "./session.js";
|
|
6
|
+
import { recordTurn } from "../../src/turns.js";
|
|
6
7
|
import fs from "node:fs";
|
|
7
8
|
import path from "node:path";
|
|
8
9
|
// plugins/claude/index.ts
|
|
@@ -37,26 +38,40 @@ function claude() {
|
|
|
37
38
|
run: channel
|
|
38
39
|
},
|
|
39
40
|
doctor: {
|
|
40
|
-
description: "check what the channel needs, a line each with what to do: the .mcp.json entry and its command, the server approved and disabled in no settings file, the session started with the channels flag
|
|
41
|
+
description: "check what the channel needs, a line each with what to do: the .mcp.json entry and its command, the server approved and disabled in no settings file (both where Claude Code runs, named beside the pages' project when it is another folder), the session started with the channels flag, the server up at the project's version, a channel for this session, its ping confirmed",
|
|
41
42
|
run: doctor
|
|
42
43
|
},
|
|
43
44
|
install: {
|
|
44
|
-
description: "add the channel to
|
|
45
|
+
description: "add the channel to the .mcp.json and its hooks to the .claude/settings.json of the folder Claude Code runs in: this project's, or --claude-dir",
|
|
46
|
+
options: { "claude-dir": CLAUDE_DIR },
|
|
45
47
|
run: (ctx) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const dir = claudeDir(ctx);
|
|
49
|
+
installChannel(dir);
|
|
50
|
+
installHooks(dir);
|
|
48
51
|
}
|
|
49
52
|
},
|
|
50
53
|
uninstall: {
|
|
51
|
-
description: "take the channel and its hooks out of this project's
|
|
54
|
+
description: "take the channel and its hooks out of the settings again (this project's, or --claude-dir's); other hooks, servers and settings stay",
|
|
55
|
+
options: { "claude-dir": CLAUDE_DIR },
|
|
52
56
|
run: (ctx) => {
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
const dir = claudeDir(ctx);
|
|
58
|
+
uninstallChannel(dir);
|
|
59
|
+
uninstallHooks(dir);
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
};
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The folder Claude Code runs in, when it isn't the pages' project: a session a wrapper hands
|
|
67
|
+
* another folder's pages reads .mcp.json and its settings from its own folder.
|
|
68
|
+
*/
|
|
69
|
+
const CLAUDE_DIR = {
|
|
70
|
+
type: "string?",
|
|
71
|
+
value: "folder",
|
|
72
|
+
description: "the folder Claude Code runs in, when not this project's (`workpad claude doctor` names it)"
|
|
73
|
+
};
|
|
74
|
+
const claudeDir = (ctx) => path.resolve(ctx.options["claude-dir"] ?? ctx.project.dir);
|
|
60
75
|
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
61
76
|
function hookInput() {
|
|
62
77
|
if (process.stdin.isTTY) return {};
|
|
@@ -69,9 +84,10 @@ function hookInput() {
|
|
|
69
84
|
async function hook(ctx, mode) {
|
|
70
85
|
const input = hookInput();
|
|
71
86
|
if (input.session_id) recordSession(ctx.dataDir, input.session_id);
|
|
72
|
-
if (mode === "session") return;
|
|
87
|
+
if (mode === "session") return recordTurn(ctx.project.wp, identity(input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null), false);
|
|
73
88
|
const agent = identity(input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null);
|
|
74
89
|
const left = await stopReminder(ctx, agent, inFlight(ctx, agent, input.transcript_path));
|
|
90
|
+
if (!left || input.stop_hook_active) recordTurn(ctx.project.wp, agent, true);
|
|
75
91
|
if (!left) return;
|
|
76
92
|
if (input.stop_hook_active) return void console.log(JSON.stringify({ systemMessage: left.shown }));
|
|
77
93
|
console.log(JSON.stringify({ hookSpecificOutput: {
|
|
@@ -37,6 +37,51 @@ function claudeProcess() {
|
|
|
37
37
|
const at = started.status === 0 ? Date.parse(started.stdout.trim()) : NaN;
|
|
38
38
|
return Number.isNaN(at) ? String(pid) : `${pid}-${at / 1e3}`;
|
|
39
39
|
}
|
|
40
|
+
/** The folder a process runs in (with lsof), or null when it can't be read. */
|
|
41
|
+
function processCwd(pid) {
|
|
42
|
+
const lsof = spawnSync("lsof", [
|
|
43
|
+
"-a",
|
|
44
|
+
"-p",
|
|
45
|
+
String(pid),
|
|
46
|
+
"-d",
|
|
47
|
+
"cwd",
|
|
48
|
+
"-Fn"
|
|
49
|
+
], { encoding: "utf8" });
|
|
50
|
+
if (lsof.status !== 0) return null;
|
|
51
|
+
return lsof.stdout.split("\n").find((l) => l.startsWith("n"))?.slice(1) || null;
|
|
52
|
+
}
|
|
53
|
+
/** A folder as the file system names it, symbolic links resolved (as given when it isn't there). */
|
|
54
|
+
function real(dir) {
|
|
55
|
+
try {
|
|
56
|
+
return fs.realpathSync(dir);
|
|
57
|
+
} catch {
|
|
58
|
+
return path.resolve(dir);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The folder Claude Code runs in, where it reads .mcp.json and its project settings: not always the
|
|
63
|
+
* pages' project (a wrapper can hand a session another folder's pages). CLAUDE_PROJECT_DIR when set
|
|
64
|
+
* (Claude Code gives it to hooks and MCP servers, not to an agent's commands); else the folder of
|
|
65
|
+
* the claude process this one runs under (found with ps, else by the CLAUDE_PID Claude Code gives an
|
|
66
|
+
* agent's commands); else, outside a session, `fallback`. With how it was found, for the doctor
|
|
67
|
+
* (null: no session was found, and it is `fallback`).
|
|
68
|
+
*/
|
|
69
|
+
function claudeFolder(fallback, env = process.env) {
|
|
70
|
+
if (env.CLAUDE_PROJECT_DIR) return {
|
|
71
|
+
dir: real(env.CLAUDE_PROJECT_DIR),
|
|
72
|
+
from: "CLAUDE_PROJECT_DIR"
|
|
73
|
+
};
|
|
74
|
+
const pid = claudePid() ?? (Number(env.CLAUDE_PID) || null);
|
|
75
|
+
const cwd = pid ? processCwd(pid) : null;
|
|
76
|
+
if (cwd) return {
|
|
77
|
+
dir: real(cwd),
|
|
78
|
+
from: `the folder claude (pid ${pid}) runs in`
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
dir: real(fallback),
|
|
82
|
+
from: null
|
|
83
|
+
};
|
|
84
|
+
}
|
|
40
85
|
const sessionsDir = (dataDir) => path.join(dataDir, "sessions");
|
|
41
86
|
/** The conversation a hook says this claude process is on; records of processes that ended go. */
|
|
42
87
|
function recordSession(dataDir, session) {
|
|
@@ -65,4 +110,4 @@ function alive(pid) {
|
|
|
65
110
|
return err.code === "EPERM";
|
|
66
111
|
}
|
|
67
112
|
}
|
|
68
|
-
export { claudePid, claudeProcess, recordSession, recordedSession };
|
|
113
|
+
export { claudeFolder, claudePid, claudeProcess, real, recordSession, recordedSession };
|
|
@@ -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
|
|
@@ -10,11 +10,13 @@ function comments() {
|
|
|
10
10
|
events: {
|
|
11
11
|
"comments:new": {
|
|
12
12
|
handOut: true,
|
|
13
|
+
requires: ["text"],
|
|
13
14
|
description: "a comment on a passage or lines of code: `{ quote, before, after, block, at?, text }`; its id is the thread's"
|
|
14
15
|
},
|
|
15
16
|
"comments:reply": {
|
|
16
17
|
handOut: true,
|
|
17
18
|
forReader: true,
|
|
19
|
+
requires: ["replyTo", "text"],
|
|
18
20
|
description: "a reply in a thread: `{ replyTo, text }`"
|
|
19
21
|
},
|
|
20
22
|
"comments:resolve": { description: "the reader closed a thread: `{ replyTo }`" }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=class{value;constructor(e){this.value=e}toString(){return this.value}};const t={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},n=e=>String(e).replace(/[&<>"']/g,e=>t[e]),r=t=>new e(String(t??``));function i(t){return t==null||t===!1?``:t instanceof e?t.value:Array.isArray(t)?t.map(i).join(``):n(t)}function a(t,...n){let r=t[0];for(let e=0;e<n.length;e++)r+=i(n[e])+t[e+1];return new e(r)}const o=`comments:new`,s=`comments:reply`,c=`comments:resolve`;let l,u,d,f=[],p=null;const m=document.createElement(`div`);m.className=`wp-comments`;const h=document.createElement(`button`);h.type=`button`,h.className=`wp-comment-start`,h.textContent=`Comment`,h.hidden=!0;const g=document.createElement(`div`);g.className=`wp-thread`,g.hidden=!0;const _=document.createElement(`section`);_.className=`wp-orphan-comments`,_.hidden=!0;let v=``;function y(){let e=[],t=``,n=document.createTreeWalker(d,NodeFilter.SHOW_TEXT,{acceptNode:e=>e.parentElement?.closest(`script, style, textarea`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let r=n.nextNode();r;r=n.nextNode())e.push({node:r,start:t.length}),t+=r.data;return{text:t,nodes:e}}function b(e,t,n){for(let r=0;r<e.nodes.length;r++){let{node:i,start:a}=e.nodes[r],o=a+i.data.length;if(t<o||n&&t===o||r===e.nodes.length-1)return{node:i,offset:Math.min(Math.max(t-a,0),i.data.length)}}return null}function x(e,t){let n=(t,n)=>{if(t.nodeType===Node.TEXT_NODE){let r=e.nodes.find(e=>e.node===t);return r?r.start+n:null}let r=document.createRange();r.setStart(d,0),r.setEnd(t,n);let i=0;for(let{node:t,start:n}of e.nodes)r.intersectsNode(t)&&(i=n+t.data.length);return i},r=n(t.startContainer,t.startOffset),i=n(t.endContainer,t.endOffset);return r==null||i==null?null:{start:r,end:i}}function S(e,t){let n=String(t.quote??``);if(!n)return null;let r=String(t.before??``),i=String(t.after??``),a=-1,o=-1;for(let t=e.text.indexOf(n);t>=0;t=e.text.indexOf(n,t+1)){let s=e.text.slice(Math.max(0,t-r.length),t),c=e.text.slice(t+n.length,t+n.length+i.length),l=0;for(;l<s.length&&s[s.length-1-l]===r[r.length-1-l];)l++;let u=0;for(;u<c.length&&c[u]===i[u];)u++;l+u>o&&(a=t,o=l+u)}if(a<0)return null;let s=b(e,a,!1),c=b(e,a+n.length,!0);if(!s||!c)return null;let l=document.createRange();return l.setStart(s.node,s.offset),l.setEnd(c.node,c.offset),l}function C(e,t){let n=(t,n,r)=>{let i=b(e,t,!1),a=b(e,n,!0);if(!i||!a)return null;let o=document.createRange();o.setStart(i.node,i.offset),o.setEnd(a.node,a.offset);let s=o.getClientRects(),c=r?s[s.length-1]:s[0];return c?c.top:null},r=String(t.before??``).trim(),i=String(t.after??``).trim();if(r.length>=8){let t=e.text.indexOf(r);if(t>=0&&e.text.indexOf(r,t+1)<0){let e=n(t,t+r.length,!0);if(e!=null)return e}}if(i.length>=8){let t=e.text.indexOf(i);if(t>=0&&e.text.indexOf(i,t+1)<0){let e=n(t,t+i.length,!1);if(e!=null)return e}}let a=typeof t.block==`number`&&t.block>=0?d.children[t.block]:null;return a?a.getBoundingClientRect().top:null}function w(){let e=u.events(),t=new Set(e.filter(e=>e.type===c).map(e=>String(e.data.replyTo))),n=y();return e.filter(e=>e.type===o&&!t.has(e.id)).map(t=>({id:t.id,comment:t,replies:e.filter(e=>e.type===s&&e.data.replyTo===t.id),range:S(n,t.data),index:n}))}const T=e=>e.replies.at(-1)?.from===`cli`;function E(){let e=CSS.highlights,t=window.Highlight;if(e&&t){e.set(`wp-comment`,new t(...f.filter(e=>e.range&&e.id!==p).map(e=>e.range)));let n=f.find(e=>e.id===p)?.range;n?e.set(`wp-comment-active`,new t(n)):e.delete(`wp-comment-active`)}let n=/* @__PURE__ */ new Map;for(let e of f)e.range?.getClientRects().length||n.set(e.id,e.index?C(e.index,e.comment.data):null);D(f.filter(e=>n.has(e.id)&&n.get(e.id)==null));let r=d.getBoundingClientRect(),i=new Set(u.unread().map(e=>e.id)),a=/* @__PURE__ */ new Map;m.replaceChildren(...f.map(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`wp-comment-badge`,t.dataset.thread=e.id,t.toggleAttribute(`data-agent`,T(e)),t.dataset.wpHolds=e.replies.map(e=>e.id).join(` `);let o=e.replies.some(e=>i.has(e.id));t.toggleAttribute(`data-unread`,o),t.title=o?`the agent replied: unread`:T(e)?`the agent replied`:`comment`,t.textContent=String(1+e.replies.length);let s=e.range?.getClientRects()[0],c,l=_.querySelector(`[data-row="${CSS.escape(e.id)}"]`);if(s)c=s.top+scrollY;else if(l)c=l.getBoundingClientRect().top+scrollY;else{let t=Math.round(n.get(e.id)??r.top),i=a.get(t)??0;a.set(t,i+1),c=t+i*30+scrollY}let u=Math.min(r.right+8+scrollX,document.documentElement.clientWidth-36+scrollX);return t.style.top=`${c}px`,t.style.left=`${u}px`,s||(t.dataset.detached=``),t})),p&&
|
|
1
|
+
var e=class{value;constructor(e){this.value=e}toString(){return this.value}};const t={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},n=e=>String(e).replace(/[&<>"']/g,e=>t[e]),r=t=>new e(String(t??``));function i(t){return t==null||t===!1?``:t instanceof e?t.value:Array.isArray(t)?t.map(i).join(``):n(t)}function a(t,...n){let r=t[0];for(let e=0;e<n.length;e++)r+=i(n[e])+t[e+1];return new e(r)}const o=`comments:new`,s=`comments:reply`,c=`comments:resolve`;let l,u,d,f=[],p=null;const m=document.createElement(`div`);m.className=`wp-comments`;const h=document.createElement(`button`);h.type=`button`,h.className=`wp-comment-start`,h.textContent=`Comment`,h.hidden=!0;const g=document.createElement(`div`);g.className=`wp-thread`,g.hidden=!0;const _=document.createElement(`section`);_.className=`wp-orphan-comments`,_.hidden=!0;let v=``;function y(){let e=[],t=``,n=document.createTreeWalker(d,NodeFilter.SHOW_TEXT,{acceptNode:e=>e.parentElement?.closest(`script, style, textarea`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let r=n.nextNode();r;r=n.nextNode())e.push({node:r,start:t.length}),t+=r.data;return{text:t,nodes:e}}function b(e,t,n){for(let r=0;r<e.nodes.length;r++){let{node:i,start:a}=e.nodes[r],o=a+i.data.length;if(t<o||n&&t===o||r===e.nodes.length-1)return{node:i,offset:Math.min(Math.max(t-a,0),i.data.length)}}return null}function x(e,t){let n=(t,n)=>{if(t.nodeType===Node.TEXT_NODE){let r=e.nodes.find(e=>e.node===t);return r?r.start+n:null}let r=document.createRange();r.setStart(d,0),r.setEnd(t,n);let i=0;for(let{node:t,start:n}of e.nodes)r.intersectsNode(t)&&(i=n+t.data.length);return i},r=n(t.startContainer,t.startOffset),i=n(t.endContainer,t.endOffset);return r==null||i==null?null:{start:r,end:i}}function S(e,t){let n=String(t.quote??``);if(!n)return null;let r=String(t.before??``),i=String(t.after??``),a=-1,o=-1;for(let t=e.text.indexOf(n);t>=0;t=e.text.indexOf(n,t+1)){let s=e.text.slice(Math.max(0,t-r.length),t),c=e.text.slice(t+n.length,t+n.length+i.length),l=0;for(;l<s.length&&s[s.length-1-l]===r[r.length-1-l];)l++;let u=0;for(;u<c.length&&c[u]===i[u];)u++;l+u>o&&(a=t,o=l+u)}if(a<0)return null;let s=b(e,a,!1),c=b(e,a+n.length,!0);if(!s||!c)return null;let l=document.createRange();return l.setStart(s.node,s.offset),l.setEnd(c.node,c.offset),l}function C(e,t){let n=(t,n,r)=>{let i=b(e,t,!1),a=b(e,n,!0);if(!i||!a)return null;let o=document.createRange();o.setStart(i.node,i.offset),o.setEnd(a.node,a.offset);let s=o.getClientRects(),c=r?s[s.length-1]:s[0];return c?c.top:null},r=String(t.before??``).trim(),i=String(t.after??``).trim();if(r.length>=8){let t=e.text.indexOf(r);if(t>=0&&e.text.indexOf(r,t+1)<0){let e=n(t,t+r.length,!0);if(e!=null)return e}}if(i.length>=8){let t=e.text.indexOf(i);if(t>=0&&e.text.indexOf(i,t+1)<0){let e=n(t,t+i.length,!1);if(e!=null)return e}}let a=typeof t.block==`number`&&t.block>=0?d.children[t.block]:null;return a?a.getBoundingClientRect().top:null}function w(){let e=u.events(),t=new Set(e.filter(e=>e.type===c).map(e=>String(e.data.replyTo))),n=y();return e.filter(e=>e.type===o&&!t.has(e.id)).map(t=>({id:t.id,comment:t,replies:e.filter(e=>e.type===s&&e.data.replyTo===t.id),range:S(n,t.data),index:n}))}const T=e=>e.replies.at(-1)?.from===`cli`;function E(){let e=CSS.highlights,t=window.Highlight;if(e&&t){e.set(`wp-comment`,new t(...f.filter(e=>e.range&&e.id!==p).map(e=>e.range)));let n=f.find(e=>e.id===p)?.range;n?e.set(`wp-comment-active`,new t(n)):e.delete(`wp-comment-active`)}let n=/* @__PURE__ */ new Map;for(let e of f)e.range?.getClientRects().length||n.set(e.id,e.index?C(e.index,e.comment.data):null);D(f.filter(e=>n.has(e.id)&&n.get(e.id)==null));let r=d.getBoundingClientRect(),i=new Set(u.unread().map(e=>e.id)),a=/* @__PURE__ */ new Map;m.replaceChildren(...f.map(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`wp-comment-badge`,t.dataset.thread=e.id,t.toggleAttribute(`data-agent`,T(e)),t.dataset.wpHolds=e.replies.map(e=>e.id).join(` `);let o=e.replies.some(e=>i.has(e.id));t.toggleAttribute(`data-unread`,o),t.title=o?`the agent replied: unread`:T(e)?`the agent replied`:`comment`,t.textContent=String(1+e.replies.length),j(e)&&(t.dataset.wpDelivery=`late`);let s=e.range?.getClientRects()[0],c,l=_.querySelector(`[data-row="${CSS.escape(e.id)}"]`);if(s)c=s.top+scrollY;else if(l)c=l.getBoundingClientRect().top+scrollY;else{let t=Math.round(n.get(e.id)??r.top),i=a.get(t)??0;a.set(t,i+1),c=t+i*30+scrollY}let u=Math.min(r.right+8+scrollX,document.documentElement.clientWidth-36+scrollX);return t.style.top=`${c}px`,t.style.left=`${u}px`,s||(t.dataset.detached=``),t})),p&&N()}function D(e){_.isConnected&&_.previousElementSibling===d||d.after(_);let t=e.map(e=>e.id).join(` `);if(t===v)return;v=t,_.hidden=!e.length;let n=document.createElement(`p`);n.className=`wp-orphan-comments-title`,n.textContent=`${e.length} comment${e.length===1?``:`s`} on text no longer on this page`;let r=e.map(e=>{let t=document.createElement(`blockquote`);return t.className=`wp-thread-quote`,t.dataset.row=t.dataset.thread=e.id,t.textContent=String(e.comment.data.quote??``),t});_.replaceChildren(...e.length?[n,...r]:[])}function O(e){let t=g.querySelector(`textarea`),n=!!t&&document.activeElement===t,r=n?t.getBoundingClientRect().top:0;e();let i=g.querySelector(`textarea`);if(!n||!i||document.activeElement!==i)return;let a=i.getBoundingClientRect().top-r;Math.abs(a)>=1&&scrollBy(0,a)}function k(){l&&(d=l.querySelector(`main`)??l,O(()=>{f=w(),p&&!f.some(e=>e.id===p)?F():p&&M(),E()}))}const A=/* @__PURE__ */ new Map,j=e=>[e.comment,...e.replies].some(e=>u.delivery().get(e.id)?.state===`late`);function M(){let e=f.find(e=>e.id===p);if(!e)return;let t=e=>e.from===`cli`?`agent`:`you`,n=[e.comment,...e.replies],i=n.findLastIndex(e=>e.from===`cli`),o=n.findLastIndex(e=>e.from!==`cli`&&!e.sending),s=e=>{let t=n.indexOf(e),r=e.from!==`cli`&&!e.sending?u.delivery().get(e.id):void 0;return r&&(r.state===`late`||t===o&&t>i)?r:void 0},c=e=>{let n=String(e.data.text??``),i=A.get(n),o=s(e);return a`<div
|
|
2
2
|
class="wp-thread-message"
|
|
3
3
|
data-from="${t(e)}"
|
|
4
4
|
data-wp-message="${e.id}"
|
|
@@ -6,19 +6,20 @@ var e=class{value;constructor(e){this.value=e}toString(){return this.value}};con
|
|
|
6
6
|
>
|
|
7
7
|
<span class="wp-thread-who">${t(e)}</span>
|
|
8
8
|
<div class="wp-thread-text" ${i==null?``:r(` data-md`)}>${i==null?n:r(i)}</div>
|
|
9
|
-
|
|
9
|
+
${o&&a`<span class="wp-thread-delivery" role="status" data-wp-delivery="${o.state}">${o.text}</span>`}
|
|
10
|
+
</div>`},l=g.querySelector(`textarea`),d=l?.value??``,m=!!l&&document.activeElement===l,h=l?[l.selectionStart,l.selectionEnd]:null;g.innerHTML=String(a` <blockquote class="wp-thread-quote">${e.comment.data.quote??``}</blockquote>
|
|
10
11
|
${e.comment.data.at&&a`<p class="wp-thread-at">${e.comment.data.at}</p>`}
|
|
11
12
|
${!e.range&&a`<p class="wp-thread-detached">This passage is no longer on the page.</p>`}
|
|
12
|
-
${[e.comment,...e.replies].map(
|
|
13
|
+
${[e.comment,...e.replies].map(c)}
|
|
13
14
|
<form class="wp-thread-reply">
|
|
14
15
|
<textarea rows="2" placeholder="Reply (Shift+Enter for a new line)"></textarea>
|
|
15
16
|
<div class="wp-thread-actions">
|
|
16
17
|
<button type="submit" class="wp-comment-button wp-comment-primary">Reply</button
|
|
17
18
|
><button type="button" class="wp-comment-button" data-close>Close thread</button>
|
|
18
19
|
</div>
|
|
19
|
-
</form>`);let
|
|
20
|
+
</form>`);let _=g.querySelector(`textarea`);_.value=d,m&&(_.focus({preventScroll:!0}),h&&_.setSelectionRange(h[0],h[1]));for(let t of[e.comment,...e.replies]){let e=String(t.data.text??``);A.has(e)||u.markdown(e).then(n=>{A.set(e,n);let r=g.querySelector(`[data-wp-message="${CSS.escape(t.id)}"] .wp-thread-text`);r&&!r.hasAttribute(`data-md`)&&O(()=>{r.innerHTML=n,r.setAttribute(`data-md`,``)})},e=>console.error(`comments:`,e))}}function N(){let e=m.querySelector(`[data-thread="${p}"]`);if(!e)return;let t=parseFloat(e.style.top)+28,n=Math.min(360,document.documentElement.clientWidth-32),r=Math.max(16+scrollX,Math.min(parseFloat(e.style.left)+28-n,document.documentElement.clientWidth-n-16+scrollX));g.style.top=`${t}px`,g.style.left=`${r}px`,g.style.width=`${n}px`}function P(e){p=e,g.hidden=!1,g.querySelector(`textarea`)?.replaceWith(document.createElement(`textarea`)),M(),E(),g.querySelector(`textarea`)?.focus({preventScroll:!0})}function F(){p=null,g.hidden=!0,E()}let I=null;function L(){d=l.querySelector(`main`)??l;let e=getSelection();if(!e||e.isCollapsed||!e.rangeCount){h.matches(`:focus`)||(h.hidden=!0);return}let t=e.getRangeAt(0),n=e=>d.contains(e)&&!(e instanceof Element?e:e.parentElement)?.closest(`form, input, textarea, select, button`);!n(t.startContainer)||!n(t.endContainer)?h.hidden=!0:h.hidden=!R(t)}function R(e){let t=e.toString().trim();if(!t)return!1;let n=y(),r=x(n,e);if(!r)return!1;let i=n.text.indexOf(t,r.start),a=i>=0&&i<=r.end?i:r.start,o=e.startContainer instanceof Element?e.startContainer:e.startContainer.parentElement;for(;o&&o.parentElement!==d;)o=o.parentElement;I={quote:t,before:n.text.slice(Math.max(0,a-32),a),after:n.text.slice(a+t.length,a+t.length+32),block:o?[...d.children].indexOf(o):-1};let s=[...d.querySelectorAll(`[data-wp-at]`)].filter(t=>e.intersectsNode(t)&&t.textContent).map(e=>e.dataset.wpAt);s.length&&(I.at=s.length>1&&s.at(-1)!==s[0]?`${s[0]} – ${s.at(-1)}`:s[0]);let c=e.getClientRects(),l=c[c.length-1]??e.getBoundingClientRect();return h.style.top=`${l.bottom+scrollY+6}px`,h.style.left=`${Math.min(l.right+scrollX-40,document.documentElement.clientWidth-110+scrollX)}px`,!0}const z=document.createElement(`button`);z.type=`button`,z.className=`wp-line-comment`,z.textContent=`+`,z.title=`Comment on this line (drag for several)`,z.hidden=!0;let B=null,V=null;const H=e=>{let t=e instanceof Element?e.closest(`pre .line`):null;return t&&d.contains(t)&&!t.closest(`form`)?t:null};function U(e,t){let[n,r]=e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING?[t,e]:[e,t],i=document.createRange();return i.setStart(n,0),i.setEnd(r,r.childNodes.length),i}function W(e){B=e;let t=e.getBoundingClientRect(),n=e.closest(`pre`).getBoundingClientRect();z.style.top=`${t.top+scrollY+t.height/2-10}px`,z.style.left=`${Math.max(scrollX+2,n.left+scrollX-24)}px`,z.hidden=!1}function G(e){if(V){let t=V.pre.getBoundingClientRect(),n=V.from.getBoundingClientRect().left+4,r=H(document.elementFromPoint(n,Math.min(Math.max(e.clientY,t.top+1),t.bottom-1)));if(r&&V.pre.contains(r)&&r!==V.to){V.to=r;let e=CSS.highlights,t=window.Highlight;e&&t&&e.set(`wp-comment-active`,new t(U(V.from,V.to)))}return}if(e.target===z)return;let t=H(e.target);if(t)return W(t);if(z.hidden||!B)return;let n=B.closest(`pre`),r=n.getBoundingClientRect(),i=z.getBoundingClientRect(),a=e.clientX>=i.left-4&&e.clientX<=r.right&&e.clientY>=r.top&&e.clientY<=r.bottom,o=a?H(document.elementFromPoint(B.getBoundingClientRect().left+4,e.clientY)):null;o&&n.contains(o)?W(o):a&&e.clientY>=i.top-4&&e.clientY<=i.bottom+4||(z.hidden=!0,B=null)}const K=document.createElement(`form`);K.className=`wp-thread wp-comment-new`,K.hidden=!0,K.innerHTML=String(a`<blockquote class="wp-thread-quote"></blockquote>
|
|
20
21
|
<textarea rows="3" placeholder="Your comment (Shift+Enter for a new line)"></textarea>
|
|
21
22
|
<div class="wp-thread-actions">
|
|
22
23
|
<button type="submit" class="wp-comment-button wp-comment-primary">Comment</button
|
|
23
24
|
><button type="button" class="wp-comment-button" data-cancel>Cancel</button>
|
|
24
|
-
</div>`);function
|
|
25
|
+
</div>`);function q(){if(!I)return;K.querySelector(`blockquote`).textContent=I.at?`${I.at}\n${I.quote}`:I.quote,K.style.top=h.style.top;let e=Math.min(360,document.documentElement.clientWidth-32);K.style.width=`${e}px`,K.style.left=`${Math.max(16+scrollX,Math.min(parseFloat(h.style.left),document.documentElement.clientWidth-e-16+scrollX))}px`,K.hidden=!1,h.hidden=!0,K.querySelector(`textarea`).focus({preventScroll:!0})}const J=(e,t,n)=>{if(t.kind!==`page`&&t.kind!==`file`)return;l=e,d=l.querySelector(`main`)??l,u=n,n.slot(`overlay`,e=>(e.append(m,h,z,g,K),()=>{for(let e of[m,h,z,g,K])e.remove()})),document.addEventListener(`mousemove`,G),document.documentElement.addEventListener(`mouseleave`,()=>{V||(z.hidden=!0,B=null)}),z.addEventListener(`mousedown`,e=>{if(!B||e.button!==0)return;e.preventDefault();let t=CSS.highlights,n=window.Highlight;t&&n&&t.set(`wp-comment-active`,new n(U(B,B))),V={pre:B.closest(`pre`),from:B,to:B}}),document.addEventListener(`mouseup`,()=>{if(!V)return;let{from:e,to:t}=V;V=null,z.hidden=!0,R(U(e,t))?q():E()});let r=0;document.addEventListener(`selectionchange`,()=>{clearTimeout(r),r=window.setTimeout(L,150)}),h.addEventListener(`mousedown`,e=>e.preventDefault()),h.addEventListener(`click`,q);for(let e of[K,g])e.addEventListener(`keydown`,e=>{let t=e.target;t.tagName!==`TEXTAREA`||e.key!==`Enter`||e.shiftKey||e.isComposing||(e.preventDefault(),t.closest(`form`)?.requestSubmit())});K.addEventListener(`submit`,async e=>{e.preventDefault();let t=K.querySelector(`textarea`).value.trim();if(!t||!I)return;let n=I,r=u.append(o,{...n,text:t}),i=u.events().findLast(e=>e.type===o&&e.sending&&e.data.text===t);K.querySelector(`textarea`).value=``,K.hidden=!0,I=null,getSelection()?.removeAllRanges(),k(),i&&P(i.id);try{await r}catch(e){if(console.error(`comments:`,e),!K.hidden)return;I=n,K.querySelector(`textarea`).value=t,K.hidden=!1,u.toast(`Couldn't send the comment`,{kind:`alert`,name:`comment-failed`,details:`It's back in the box: send it again.`})}}),K.querySelector(`[data-cancel]`).addEventListener(`click`,()=>{K.hidden=!0,I=null}),_.addEventListener(`click`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&(p===t?F():P(t))}),m.addEventListener(`click`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&(p===t?F():P(t))}),g.addEventListener(`submit`,async e=>{e.preventDefault();let t=g.querySelector(`textarea`),n=t.value.trim();if(!n||!p)return;let r=p;t.value=``;let i=u.append(s,{replyTo:r,text:n});k();try{await i}catch(e){console.error(`comments:`,e);let t=g.querySelector(`textarea`);p===r&&t&&!t.value.trim()&&(t.value=n),u.toast(`Couldn't send the reply`,{kind:`alert`,name:`comment-failed`,details:`It's back in the box: send it again.`})}}),g.addEventListener(`click`,async e=>{if(!e.target.closest(`[data-close]`)||!p)return;let t=p;F(),u.markRead(f.find(e=>e.id===t)?.replies.map(e=>e.id)??[]);let n=u.append(c,{replyTo:t});k(),n.catch(e=>{console.error(`comments:`,e),u.toast(`Couldn't close the thread`,{kind:`alert`,name:`comment-failed`,details:`It's open again.`})})}),m.addEventListener(`wp-reveal`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&p!==t&&P(t)}),document.addEventListener(`dblclick`,e=>{let t=e.target;!p||g.contains(t)||m.contains(t)||F()}),document.addEventListener(`keydown`,e=>{e.key===`Escape`&&(K.hidden?p&&F():(K.hidden=!0,I=null))}),u.events.on(k),u.delivery.on(k),u.onRendered(k),new ResizeObserver(()=>E()).observe(l),addEventListener(`resize`,()=>E()),k()};export{J as default};
|
|
@@ -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;
|
|
@@ -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/dist/plugins/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import badge from "./badge/index.js";
|
|
|
17
17
|
import ansi from "./ansi/index.js";
|
|
18
18
|
import timeline from "./timeline/index.js";
|
|
19
19
|
import toc from "./toc/index.js";
|
|
20
|
+
import progress from "./progress/index.js";
|
|
20
21
|
// plugins/index.ts
|
|
21
22
|
function builtins() {
|
|
22
23
|
return [
|
|
@@ -38,7 +39,8 @@ function builtins() {
|
|
|
38
39
|
badge(),
|
|
39
40
|
ansi(),
|
|
40
41
|
timeline(),
|
|
41
|
-
toc()
|
|
42
|
+
toc(),
|
|
43
|
+
progress()
|
|
42
44
|
];
|
|
43
45
|
}
|
|
44
46
|
export { builtins };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { channelSince } from "../../src/status.js";
|
|
2
1
|
import { read, receive, receivedBy } from "../../src/events.js";
|
|
3
|
-
import {
|
|
2
|
+
import { channelSince, takesUnfollowed } from "../../src/status.js";
|
|
3
|
+
import { answerLine, identity, pong, unfollowedLine } from "../../src/agents.js";
|
|
4
|
+
import { project } from "../../src/config.js";
|
|
5
|
+
import { recordTurn } from "../../src/turns.js";
|
|
4
6
|
import fs from "node:fs";
|
|
5
7
|
import path from "node:path";
|
|
6
8
|
import readline from "node:readline";
|
|
@@ -15,6 +17,7 @@ async function channel(ctx) {
|
|
|
15
17
|
const sessions = /* @__PURE__ */ new Map();
|
|
16
18
|
const hold = (session) => {
|
|
17
19
|
sessions.set(session, false);
|
|
20
|
+
recordTurn(ctx.project.wp, identity(session), false);
|
|
18
21
|
ctx.channel(identity(session), {
|
|
19
22
|
onPing: (code) => say({
|
|
20
23
|
session,
|
|
@@ -28,10 +31,38 @@ async function channel(ctx) {
|
|
|
28
31
|
});
|
|
29
32
|
};
|
|
30
33
|
const followed = /* @__PURE__ */ new Set();
|
|
34
|
+
const unfollowed = /* @__PURE__ */ new Map();
|
|
35
|
+
const logOf = /* @__PURE__ */ new Map();
|
|
36
|
+
const takeUnfollowed = (agent, session) => {
|
|
37
|
+
if (!takesUnfollowed(read(ctx.eventsFile).events, agent)) {
|
|
38
|
+
unfollowed.get(session)?.abort();
|
|
39
|
+
unfollowed.delete(session);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (unfollowed.has(session)) return;
|
|
43
|
+
const stop = new AbortController();
|
|
44
|
+
unfollowed.set(session, stop);
|
|
45
|
+
ctx.unfollowed((e, again, from) => {
|
|
46
|
+
const log = from ? project(from.project)?.eventsFile : null;
|
|
47
|
+
if (log) logOf.set(e.id, log);
|
|
48
|
+
say({
|
|
49
|
+
session,
|
|
50
|
+
id: e.id,
|
|
51
|
+
page: e.page,
|
|
52
|
+
type: e.type,
|
|
53
|
+
text: unfollowedLine(e, again, from)
|
|
54
|
+
});
|
|
55
|
+
}, {
|
|
56
|
+
agent,
|
|
57
|
+
mark: false,
|
|
58
|
+
signal: stop.signal
|
|
59
|
+
}).catch((err) => problem("taking the unfollowed pages failed", String(err)));
|
|
60
|
+
};
|
|
31
61
|
const follow = async () => {
|
|
32
62
|
const who = /* @__PURE__ */ new Map();
|
|
33
63
|
for (const [session, confirmed] of sessions) if (confirmed) who.set(identity(session), session);
|
|
34
64
|
if (!who.size) return;
|
|
65
|
+
for (const [agent, session] of who) takeUnfollowed(agent, session);
|
|
35
66
|
for (const p of await ctx.status()) {
|
|
36
67
|
const agent = p.subscribers.find((s) => who.has(s));
|
|
37
68
|
if (!agent || followed.has(p.page)) continue;
|
|
@@ -53,6 +84,7 @@ async function channel(ctx) {
|
|
|
53
84
|
}, push, {
|
|
54
85
|
mark: false,
|
|
55
86
|
agent,
|
|
87
|
+
aliases: /* @__PURE__ */ new Set([session]),
|
|
56
88
|
skipReceivedBefore: since
|
|
57
89
|
}).catch((err) => problem("handing out failed", {
|
|
58
90
|
page,
|
|
@@ -63,11 +95,15 @@ async function channel(ctx) {
|
|
|
63
95
|
/** The plugin brought these answers into their session. */
|
|
64
96
|
const received = (ids, session) => {
|
|
65
97
|
const agent = identity(session);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
98
|
+
for (const log of new Set(ids.map((id) => logOf.get(id) ?? ctx.eventsFile))) {
|
|
99
|
+
const { events } = read(log);
|
|
100
|
+
const had = receivedBy(events, agent);
|
|
101
|
+
for (const id of ids) {
|
|
102
|
+
if ((logOf.get(id) ?? ctx.eventsFile) !== log) continue;
|
|
103
|
+
const e = events.find((x) => x.id === id);
|
|
104
|
+
if (e && !had.has(id)) receive(log, e, agent);
|
|
105
|
+
logOf.delete(id);
|
|
106
|
+
}
|
|
71
107
|
}
|
|
72
108
|
};
|
|
73
109
|
const round = () => follow().catch((err) => problem("finding the sessions’ pages failed", String(err)));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { identity, stopReminder, workpadCommand } from "../../src/agents.js";
|
|
2
|
+
import { recordTurn } from "../../src/turns.js";
|
|
2
3
|
import { channel } from "./channel.js";
|
|
3
4
|
import { shimSource } from "./shim.js";
|
|
4
5
|
import fs from "node:fs";
|
|
@@ -16,6 +17,7 @@ function opencode() {
|
|
|
16
17
|
async run(ctx) {
|
|
17
18
|
if (ctx.positionals[0] !== "stop") throw new Error("usage: workpad opencode hook stop");
|
|
18
19
|
try {
|
|
20
|
+
recordTurn(ctx.project.wp, identity(session()), true);
|
|
19
21
|
const left = await stopReminder(ctx, identity(session()));
|
|
20
22
|
if (left) console.log(JSON.stringify(left));
|
|
21
23
|
} catch (err) {
|
|
@@ -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 })`.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import { NUDGER, STALE, UPDATE, isProgressId, keyOf, line, nudgesDue, openNudges, parseArgs, progressOf } from "./state.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { anchorTaken, definePlugin, html } from "@bigmistqke/workpad";
|
|
6
|
+
import { appendEvent, handle, handledIds, read } from "@bigmistqke/workpad/log";
|
|
7
|
+
// plugins/progress/index.ts
|
|
8
|
+
/** `:progress{id=probe}`: the marker, drawn by the page's client from the log; "waiting to start" until then. */
|
|
9
|
+
function render(ctx) {
|
|
10
|
+
const id = ctx.attrs.id ?? "";
|
|
11
|
+
if (!id) {
|
|
12
|
+
ctx.problem("`:progress` needs an id, which `workpad progress` moves it by: `:progress{id=probe}`");
|
|
13
|
+
return html``;
|
|
14
|
+
}
|
|
15
|
+
if (!isProgressId(id)) ctx.problem(`\`:progress{id=${id}}\`: an id is letters, digits, - and _`);
|
|
16
|
+
const anchor = ctx.anchor("progress", id);
|
|
17
|
+
return html`<span class="wp-progress" data-progress="${id}" ${anchor ? html` id="${anchor}"` : ""}
|
|
18
|
+
>${!anchor ? anchorTaken("progress", id) : ""}<span class="wp-progress-body" data-wp-quiet
|
|
19
|
+
><span class="wp-progress-note">waiting to start</span></span
|
|
20
|
+
></span
|
|
21
|
+
>`;
|
|
22
|
+
}
|
|
23
|
+
const watches = /* @__PURE__ */ new Map();
|
|
24
|
+
/** Append the nudges due at `now` to the log in `file`; returns them. */
|
|
25
|
+
function nudgeStale(file, now, options = {}) {
|
|
26
|
+
return nudgesDue(read(file).events, now, {
|
|
27
|
+
staleAfter: options.staleAfter ?? 9e5,
|
|
28
|
+
every: options.nudgeEvery ?? 9e5
|
|
29
|
+
}).map((n) => appendEvent(file, n, "cli", NUDGER));
|
|
30
|
+
}
|
|
31
|
+
/** Whether page `page` is there to show a progress: a page of `.workpad/pages/`, or a file of the repository. */
|
|
32
|
+
function pageExists(wp, dir, page) {
|
|
33
|
+
if (page.startsWith("-/")) return fs.existsSync(path.join(dir, page.slice(2)));
|
|
34
|
+
const pages = path.join(wp, "pages");
|
|
35
|
+
return fs.existsSync(path.join(pages, `${page}.md`)) || fs.existsSync(path.join(pages, page, "index.md"));
|
|
36
|
+
}
|
|
37
|
+
/** The page's source, when it has one to look in for its marker. */
|
|
38
|
+
function sourceOf(wp, page) {
|
|
39
|
+
const pages = path.join(wp, "pages");
|
|
40
|
+
for (const file of [path.join(pages, `${page}.md`), path.join(pages, page, "index.md")]) try {
|
|
41
|
+
return fs.readFileSync(file, "utf8");
|
|
42
|
+
} catch {}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function progress(options = {}) {
|
|
46
|
+
const now = options.now ?? Date.now;
|
|
47
|
+
return definePlugin({
|
|
48
|
+
name: "progress",
|
|
49
|
+
public: builtinPublic("progress"),
|
|
50
|
+
blocks: { progress: {
|
|
51
|
+
menu: {
|
|
52
|
+
group: "mark",
|
|
53
|
+
summary: "how far a long piece of work is, moved live by `workpad progress`"
|
|
54
|
+
},
|
|
55
|
+
attrs: ["id"],
|
|
56
|
+
style: "style.css",
|
|
57
|
+
html: (ctx) => render(ctx)
|
|
58
|
+
} },
|
|
59
|
+
events: {
|
|
60
|
+
[UPDATE]: { description: "a progress moved (`workpad progress`): `{ id, n, total, note, eta, state }`, `n` and `total` null without a count, `eta` seconds from it, `state` running, done or failed" },
|
|
61
|
+
[STALE]: {
|
|
62
|
+
handOut: true,
|
|
63
|
+
description: "the server nudges the agent that last moved a progress gone stale: `{ id, to, nudge, since, at }`, `to` that agent, `nudge` what to run. Moving the progress handles it"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
setup(ctx) {
|
|
67
|
+
const file = path.join(ctx.project.wp, "events.ndjson");
|
|
68
|
+
clearInterval(watches.get(file));
|
|
69
|
+
const timer = setInterval(() => {
|
|
70
|
+
try {
|
|
71
|
+
nudgeStale(file, now(), options);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error("progress: looking for stale progress failed:", err);
|
|
74
|
+
}
|
|
75
|
+
}, options.checkEvery ?? 6e4);
|
|
76
|
+
timer.unref();
|
|
77
|
+
watches.set(file, timer);
|
|
78
|
+
return {
|
|
79
|
+
client: "client.js",
|
|
80
|
+
slots: () => options.staleAfter != null ? { head: html`<meta name="wp-progress" data-stale-after="${String(options.staleAfter)}" />` } : null
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
commands: { "": {
|
|
84
|
+
description: "move a `:progress{id=…}` on a page: how far (`287/1413`), a note, and `--eta`; or `done`, `failed`. Appends an event; the page is left as it is",
|
|
85
|
+
args: "<page|file> <id> [<n>/<total> | done | failed] \"<note>\"",
|
|
86
|
+
options: { eta: {
|
|
87
|
+
type: "string?",
|
|
88
|
+
value: "time",
|
|
89
|
+
description: "the time left: 20m, 90s, 1h30m"
|
|
90
|
+
} },
|
|
91
|
+
run(ctx) {
|
|
92
|
+
const [target, id, ...rest] = ctx.positionals;
|
|
93
|
+
if (!target || !id || !rest.length) throw new Error("usage: workpad progress <page> <id> <n>/<total> \"<note>\" [--eta 20m], or <page> <id> \"<note>\", <page> <id> done|failed \"<note>\"");
|
|
94
|
+
if (!isProgressId(id)) throw new Error(`progress id ${JSON.stringify(id)}: letters, digits, - and _`);
|
|
95
|
+
const page = ctx.page(target);
|
|
96
|
+
if (!pageExists(ctx.project.wp, ctx.project.dir, page)) throw new Error(`no page ${page}`);
|
|
97
|
+
const data = parseArgs(rest, ctx.options.eta ?? null);
|
|
98
|
+
const before = read(ctx.eventsFile).events;
|
|
99
|
+
const event = appendEvent(ctx.eventsFile, {
|
|
100
|
+
page,
|
|
101
|
+
type: UPDATE,
|
|
102
|
+
data: {
|
|
103
|
+
id,
|
|
104
|
+
...data
|
|
105
|
+
}
|
|
106
|
+
}, "cli", ctx.agent);
|
|
107
|
+
for (const e of openNudges(before, page, id, handledIds(before))) handle(ctx.eventsFile, e, ctx.agent);
|
|
108
|
+
const p = progressOf([...before, event]).get(keyOf(page, id));
|
|
109
|
+
console.log(`${page}: ${line(p, Date.parse(event.ts))}`);
|
|
110
|
+
const source = sourceOf(ctx.project.wp, page);
|
|
111
|
+
if (source != null && !new RegExp(`:progress\\{[^}]*\\bid=["']?${id}(?![\\w-])`).test(source)) console.error(`workpad: ${page} has no :progress{id=${id}}: put one where it should show (the corner shows it all the same)`);
|
|
112
|
+
}
|
|
113
|
+
} },
|
|
114
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export { progress as default, nudgeStale };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e,t)=>`${e}\n${t}`,t=e=>typeof e==`number`&&Number.isFinite(e)?e:null;function n(n){let r=/* @__PURE__ */ new Map;for(let i of n){if(i.type!==`progress:update`||i.from!==`cli`)continue;let n=i.data??{},a=typeof n.id==`string`?n.id:``;if(!a)continue;let o=e(i.page,a),s=r.get(o),c=n.state===`done`||n.state===`failed`?n.state:`running`,l=t(n.n),u=t(n.total),d=!s||s.state!==`running`,f=d?i.ts:s.started,p=d?null:s.first;r.set(o,{page:i.page,id:a,n:l,total:u,note:typeof n.note==`string`?n.note:``,state:c,eta:t(n.eta),ts:i.ts,started:f,first:p??(l==null?null:{n:l,ts:i.ts}),by:i.by??null,event:i.id})}return r}const r=(e,t)=>[...n(e.filter(e=>e.page===t)).values()];function i(e,t){if(e.state!==`running`)return null;let n=Date.parse(e.ts);if(e.eta!=null)return n+e.eta*1e3-t;if(e.n==null||e.total==null||!e.first||e.n<=e.first.n)return null;let r=(e.n-e.first.n)/(n-Date.parse(e.first.ts));return r>0?n+(e.total-e.n)/r-t:null}function a(e,t,n=9e5){return e.state===`running`?t-Date.parse(e.ts)>=n||e.eta!=null&&Date.parse(e.ts)+e.eta*1e3<t:!1}const o=e=>e.toLocaleString(`en-US`),s=e=>e.n!=null&&e.total!=null?`${o(e.n)} / ${o(e.total)}`:``;function c(e){let t=Math.max(0,Math.round(e/1e3));if(t<60)return`${t} s`;let n=Math.round(t/60);if(n<60)return`${n} min`;let r=Math.floor(n/60),i=n%60;return i?`${r} h ${i} min`:`${r} h`}const l=e=>e<1e4?`just now`:`${c(e)} ago`;function u(e,t){let n=i(e,t);return n==null||n<=0?``:`~${c(n)} left`}function d(e,t,n){let r=document.createElement(e);return r.className=t,n!=null&&(r.textContent=n),r}const f=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}),p=e=>e.n!=null&&e.total?e.n/e.total:null,m={running:`running`,done:`done`,failed:`failed`};function h(e,t,n,r){let i=e.querySelector(`:scope > .wp-progress-body`);if(!i)return;if(!t){e.dataset.wpProgress=`waiting`,e.removeAttribute(`data-wp-stale`),i.replaceChildren(d(`span`,`wp-progress-note`,`waiting to start`));return}let o=a(t,n,r);e.dataset.wpProgress=t.state,e.toggleAttribute(`data-wp-stale`,o);let h=[],g=p(t);if(t.state===`running`&&g!=null){let e=d(`span`,`wp-progress-bar`),n=d(`span`,``);n.style.width=`${Math.round(g*1e3)/10}%`,e.append(n),e.setAttribute(`role`,`progressbar`),e.setAttribute(`aria-valuemin`,`0`),e.setAttribute(`aria-valuemax`,String(t.total)),e.setAttribute(`aria-valuenow`,String(t.n)),h.push(e,d(`span`,`wp-progress-count`,s(t)))}else h.push(d(`span`,`wp-progress-state`,m[t.state]));t.note&&h.push(d(`span`,`wp-progress-note`,t.note));let _=[];if(t.state!==`running`)_.push(f(t.ts));else if(o)_.push(`no update for ${c(n-Date.parse(t.ts))}`);else{let e=u(t,n);e&&_.push(e),_.push(l(n-Date.parse(t.ts)))}h.push(d(`span`,`wp-progress-when`,_.join(` · `))),i.replaceChildren(...h),e.title=`${t.id}: ${t.state}${t.by?`, moved by ${t.by}`:``}`}function g(e,t,n){let r=e.state===`running`?s(e)||e.note:e.note||m[e.state],i=`${e.state===`done`?`✓ `:e.state===`failed`?`✗ `:``}${e.id}${r?` · ${r}`:``}`;return e.state===`running`?{text:i,meta:a(e,t,n)?`no update ${c(t-Date.parse(e.ts))}`:u(e,t)||l(t-Date.parse(e.ts)),bar:{value:p(e),tone:`accent`}}:{text:i,meta:l(t-Date.parse(e.ts)),bar:{value:1,tone:e.state===`done`?`good`:`bad`}}}const _=(e,t,n)=>{if(!t.live)return;let i=Number(document.querySelector(`meta[name=wp-progress]`)?.dataset.staleAfter)||9e5,a=`wp-progress-seen:${location.pathname}`,o=/* @__PURE__ */ new Set;try{o=new Set(JSON.parse(localStorage.getItem(a)??`[]`))}catch{}let s=e=>{o.add(e);try{localStorage.setItem(a,JSON.stringify([...o].slice(-200)))}catch{}},c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=t=>[...e.querySelectorAll(`.wp-progress[data-progress]`)].filter(e=>e.dataset.progress===t);function f(e){let t=l.get(e);t&&t.state!==`running`&&(s(t.event),c.get(e)?.close(),c.delete(e));let n=d(e);if(!n.length)return;let r=((u.get(e)??-1)+1)%n.length;u.set(e,r);let i=n[r];i.scrollIntoView({block:`center`,behavior:`smooth`}),i.classList.remove(`wp-flash`),i.offsetWidth,i.classList.add(`wp-flash`)}function p(){let t=Date.now(),a=r(n.events(),n.page),s=new Map(a.map(e=>[e.id,e]));for(let n of e.querySelectorAll(`.wp-progress[data-progress]`))h(n,s.get(n.dataset.progress),t,i);for(let e of a){let r=e.state===`running`||!o.has(e.event),a=c.get(e.id);if(!r){a?.close(),c.delete(e.id);continue}l.set(e.id,e);let{text:s,meta:u,bar:d}=g(e,t,i);a?a.update(s,{meta:u??null,bar:d??null}):(a=n.toast(s,{kind:`quiet`,ms:0,name:`progress-${e.id}`,order:-3,meta:u,bar:d,onClick:()=>f(e.id)}),c.set(e.id,a))}for(let[e,t]of c)s.has(e)||(t.close(),c.delete(e))}p(),n.events.on(p),n.onRendered(p),setInterval(p,1e4)};export{_ as default};
|